1f8e07b45SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f8e07b45SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f8e07b45SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f8e07b45SAndrew Rist  * distributed with this work for additional information
6f8e07b45SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f8e07b45SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f8e07b45SAndrew Rist  * "License"); you may not use this file except in compliance
9f8e07b45SAndrew Rist  * with the License.  You may obtain a copy of the License at
10f8e07b45SAndrew Rist  *
11f8e07b45SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12f8e07b45SAndrew Rist  *
13f8e07b45SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f8e07b45SAndrew Rist  * software distributed under the License is distributed on an
15f8e07b45SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f8e07b45SAndrew Rist  * KIND, either express or implied.  See the License for the
17f8e07b45SAndrew Rist  * specific language governing permissions and limitations
18f8e07b45SAndrew Rist  * under the License.
19f8e07b45SAndrew Rist  *
20f8e07b45SAndrew Rist  *************************************************************/
21f8e07b45SAndrew Rist 
22f8e07b45SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef __FRAMEWORK_PATTERN_WINDOW_HXX_
25cdf0e10cSrcweir #define __FRAMEWORK_PATTERN_WINDOW_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir //_______________________________________________
28cdf0e10cSrcweir // own includes
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <general.h>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir //_______________________________________________
33cdf0e10cSrcweir // interface includes
34cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp>
35cdf0e10cSrcweir #include <com/sun/star/awt/XTopWindow.hpp>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir //_______________________________________________
38cdf0e10cSrcweir // other includes
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
41*b63233d8Sdamjan #include <toolkit/helper/vclunohelper.hxx>
42cdf0e10cSrcweir #endif
43cdf0e10cSrcweir #include <vcl/window.hxx>
44cdf0e10cSrcweir #include <vcl/syswin.hxx>
45cdf0e10cSrcweir #include <vcl/wrkwin.hxx>
46cdf0e10cSrcweir #include <vcl/svapp.hxx>
47cdf0e10cSrcweir #include <vos/mutex.hxx>
48cdf0e10cSrcweir #include <rtl/ustring.hxx>
49cdf0e10cSrcweir 
50cdf0e10cSrcweir //_______________________________________________
51cdf0e10cSrcweir // namespaces
52cdf0e10cSrcweir 
53cdf0e10cSrcweir #ifndef css
54cdf0e10cSrcweir namespace css = ::com::sun::star;
55cdf0e10cSrcweir #endif
56cdf0e10cSrcweir 
57cdf0e10cSrcweir namespace framework{
58cdf0e10cSrcweir 
59cdf0e10cSrcweir //_______________________________________________
60cdf0e10cSrcweir // definitions
61cdf0e10cSrcweir 
62cdf0e10cSrcweir class WindowHelper
63cdf0e10cSrcweir {
64cdf0e10cSrcweir     public:
65cdf0e10cSrcweir 
66cdf0e10cSrcweir //-----------------------------------------------
getWindowState(const css::uno::Reference<css::awt::XWindow> & xWindow)67cdf0e10cSrcweir static ::rtl::OUString getWindowState(const css::uno::Reference< css::awt::XWindow >& xWindow)
68cdf0e10cSrcweir {
69cdf0e10cSrcweir     if (!xWindow.is())
70cdf0e10cSrcweir         return ::rtl::OUString();
71cdf0e10cSrcweir 
72cdf0e10cSrcweir     // SOLAR SAFE -> ----------------------------
73cdf0e10cSrcweir     ::vos::OClearableGuard aSolarGuard(Application::GetSolarMutex());
74cdf0e10cSrcweir 
75cdf0e10cSrcweir     ByteString sWindowState;
76cdf0e10cSrcweir     Window*    pWindow     = VCLUnoHelper::GetWindow(xWindow);
7707a3d7f1SPedro Giffuni     // check for system window is necessary to guarantee correct pointer cast!
78cdf0e10cSrcweir     if (pWindow!=NULL && pWindow->IsSystemWindow())
79cdf0e10cSrcweir 	{
80cdf0e10cSrcweir 		sal_uLong nMask  = WINDOWSTATE_MASK_ALL;
81cdf0e10cSrcweir               nMask &= ~(WINDOWSTATE_MASK_MINIMIZED);
82cdf0e10cSrcweir         sWindowState = ((SystemWindow*)pWindow)->GetWindowState(nMask);
83cdf0e10cSrcweir 	}
84cdf0e10cSrcweir 
85cdf0e10cSrcweir     aSolarGuard.clear();
86cdf0e10cSrcweir     // <- SOLAR SAFE ----------------------------
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     return B2U_ENC(sWindowState,RTL_TEXTENCODING_UTF8);
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir //-----------------------------------------------
setWindowState(const css::uno::Reference<css::awt::XWindow> & xWindow,const::rtl::OUString & sWindowState)92cdf0e10cSrcweir static void setWindowState(const css::uno::Reference< css::awt::XWindow >& xWindow     ,
93cdf0e10cSrcweir                            const ::rtl::OUString&                          sWindowState)
94cdf0e10cSrcweir {
95cdf0e10cSrcweir     if (
96cdf0e10cSrcweir         (!xWindow.is()            ) ||
97cdf0e10cSrcweir         (!sWindowState.getLength())
98cdf0e10cSrcweir        )
99cdf0e10cSrcweir         return;
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     // SOLAR SAFE -> ----------------------------
102cdf0e10cSrcweir     ::vos::OClearableGuard aSolarGuard(Application::GetSolarMutex());
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     Window* pWindow = VCLUnoHelper::GetWindow(xWindow);
10507a3d7f1SPedro Giffuni     // check for system window is necessary to guarantee correct pointer cast!
106cdf0e10cSrcweir     if (
107cdf0e10cSrcweir         (pWindow                  ) &&
108cdf0e10cSrcweir         (pWindow->IsSystemWindow()) &&
109cdf0e10cSrcweir         (
110cdf0e10cSrcweir             // dont overwrite a might existing minimized mode!
111cdf0e10cSrcweir             (pWindow->GetType() != WINDOW_WORKWINDOW) ||
112cdf0e10cSrcweir             (!((WorkWindow*)pWindow)->IsMinimized() )
113cdf0e10cSrcweir         )
114cdf0e10cSrcweir        )
115cdf0e10cSrcweir     {
116cdf0e10cSrcweir         ((SystemWindow*)pWindow)->SetWindowState(U2B_ENC(sWindowState,RTL_TEXTENCODING_UTF8));
117cdf0e10cSrcweir     }
118cdf0e10cSrcweir 
119cdf0e10cSrcweir     aSolarGuard.clear();
120cdf0e10cSrcweir     // <- SOLAR SAFE ----------------------------
121cdf0e10cSrcweir }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir //-----------------------------------------------
isTopWindow(const css::uno::Reference<css::awt::XWindow> & xWindow)124cdf0e10cSrcweir static ::sal_Bool isTopWindow(const css::uno::Reference< css::awt::XWindow >& xWindow)
125cdf0e10cSrcweir {
126cdf0e10cSrcweir     // even child frame containing top level windows (e.g. query designer of database) will be closed
127cdf0e10cSrcweir     css::uno::Reference< css::awt::XTopWindow > xTopWindowCheck(xWindow, css::uno::UNO_QUERY);
128cdf0e10cSrcweir     if (xTopWindowCheck.is())
129cdf0e10cSrcweir     {
130cdf0e10cSrcweir         // Note: Toolkit interface XTopWindow sometimes is used by real VCL-child-windows also .-)
13107a3d7f1SPedro Giffuni         // Be sure that these window is really a "top system window".
13207a3d7f1SPedro Giffuni         // Attention ! Checking Window->GetParent() isn't the right approach here.
133cdf0e10cSrcweir         // Because sometimes VCL create "implicit border windows" as parents even we created
134cdf0e10cSrcweir         // a simple XWindow using the toolkit only .-(
135cdf0e10cSrcweir         ::vos::OGuard aSolarLock(&Application::GetSolarMutex());
136cdf0e10cSrcweir         Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
137cdf0e10cSrcweir         if (
138cdf0e10cSrcweir             (pWindow				  ) &&
139cdf0e10cSrcweir             (pWindow->IsSystemWindow())
140cdf0e10cSrcweir            )
141cdf0e10cSrcweir             return sal_True;
142cdf0e10cSrcweir     }
143cdf0e10cSrcweir 
144cdf0e10cSrcweir     return sal_False;
145cdf0e10cSrcweir }
146cdf0e10cSrcweir 
147cdf0e10cSrcweir };
148cdf0e10cSrcweir 
149cdf0e10cSrcweir } // namespace framework
150cdf0e10cSrcweir 
151cdf0e10cSrcweir #endif // __FRAMEWORK_PATTERN_WINDOW_HXX_
152