1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef __FRAMEWORK_PATTERN_WINDOW_HXX_
29 #define __FRAMEWORK_PATTERN_WINDOW_HXX_
30 
31 //_______________________________________________
32 // own includes
33 
34 #include <general.h>
35 
36 //_______________________________________________
37 // interface includes
38 #include <com/sun/star/awt/XWindow.hpp>
39 #include <com/sun/star/awt/XTopWindow.hpp>
40 
41 //_______________________________________________
42 // other includes
43 
44 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
45 #include <toolkit/unohlp.hxx>
46 #endif
47 #include <vcl/window.hxx>
48 #include <vcl/syswin.hxx>
49 #include <vcl/wrkwin.hxx>
50 #include <vcl/svapp.hxx>
51 #include <vos/mutex.hxx>
52 #include <rtl/ustring.hxx>
53 
54 //_______________________________________________
55 // namespaces
56 
57 #ifndef css
58 namespace css = ::com::sun::star;
59 #endif
60 
61 namespace framework{
62 
63 //_______________________________________________
64 // definitions
65 
66 class WindowHelper
67 {
68     public:
69 
70 //-----------------------------------------------
71 static ::rtl::OUString getWindowState(const css::uno::Reference< css::awt::XWindow >& xWindow)
72 {
73     if (!xWindow.is())
74         return ::rtl::OUString();
75 
76     // SOLAR SAFE -> ----------------------------
77     ::vos::OClearableGuard aSolarGuard(Application::GetSolarMutex());
78 
79     ByteString sWindowState;
80     Window*    pWindow     = VCLUnoHelper::GetWindow(xWindow);
81     // check for system window is neccessary to guarantee correct pointer cast!
82     if (pWindow!=NULL && pWindow->IsSystemWindow())
83 	{
84 		sal_uLong nMask  = WINDOWSTATE_MASK_ALL;
85               nMask &= ~(WINDOWSTATE_MASK_MINIMIZED);
86         sWindowState = ((SystemWindow*)pWindow)->GetWindowState(nMask);
87 	}
88 
89     aSolarGuard.clear();
90     // <- SOLAR SAFE ----------------------------
91 
92     return B2U_ENC(sWindowState,RTL_TEXTENCODING_UTF8);
93 }
94 
95 //-----------------------------------------------
96 static void setWindowState(const css::uno::Reference< css::awt::XWindow >& xWindow     ,
97                            const ::rtl::OUString&                          sWindowState)
98 {
99     if (
100         (!xWindow.is()            ) ||
101         (!sWindowState.getLength())
102        )
103         return;
104 
105     // SOLAR SAFE -> ----------------------------
106     ::vos::OClearableGuard aSolarGuard(Application::GetSolarMutex());
107 
108     Window* pWindow = VCLUnoHelper::GetWindow(xWindow);
109     // check for system window is neccessary to guarantee correct pointer cast!
110     if (
111         (pWindow                  ) &&
112         (pWindow->IsSystemWindow()) &&
113         (
114             // dont overwrite a might existing minimized mode!
115             (pWindow->GetType() != WINDOW_WORKWINDOW) ||
116             (!((WorkWindow*)pWindow)->IsMinimized() )
117         )
118        )
119     {
120         ((SystemWindow*)pWindow)->SetWindowState(U2B_ENC(sWindowState,RTL_TEXTENCODING_UTF8));
121     }
122 
123     aSolarGuard.clear();
124     // <- SOLAR SAFE ----------------------------
125 }
126 
127 //-----------------------------------------------
128 static ::sal_Bool isTopWindow(const css::uno::Reference< css::awt::XWindow >& xWindow)
129 {
130     // even child frame containing top level windows (e.g. query designer of database) will be closed
131     css::uno::Reference< css::awt::XTopWindow > xTopWindowCheck(xWindow, css::uno::UNO_QUERY);
132     if (xTopWindowCheck.is())
133     {
134         // Note: Toolkit interface XTopWindow sometimes is used by real VCL-child-windows also .-)
135         // Be sure that these window is realy a "top system window".
136         // Attention ! Checking Window->GetParent() isnt the right approach here.
137         // Because sometimes VCL create "implicit border windows" as parents even we created
138         // a simple XWindow using the toolkit only .-(
139         ::vos::OGuard aSolarLock(&Application::GetSolarMutex());
140         Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
141         if (
142             (pWindow				  ) &&
143             (pWindow->IsSystemWindow())
144            )
145             return sal_True;
146     }
147 
148     return sal_False;
149 }
150 
151 };
152 
153 } // namespace framework
154 
155 #endif // __FRAMEWORK_PATTERN_WINDOW_HXX_
156