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