merged tag ooo/OOO330_m14
[LibreOffice.git] / framework / source / inc / pattern / window.hxx
blob619ce140d49179a6640bffc5fe915653374364b2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 #ifndef __FRAMEWORK_PATTERN_WINDOW_HXX_
29 #define __FRAMEWORK_PATTERN_WINDOW_HXX_
31 //_______________________________________________
32 // own includes
34 #include <general.h>
36 //_______________________________________________
37 // interface includes
38 #include <com/sun/star/awt/XWindow.hpp>
39 #include <com/sun/star/awt/XTopWindow.hpp>
41 //_______________________________________________
42 // other includes
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>
54 //_______________________________________________
55 // namespaces
57 #ifndef css
58 namespace css = ::com::sun::star;
59 #endif
61 namespace framework{
63 //_______________________________________________
64 // definitions
66 class WindowHelper
68 public:
70 //-----------------------------------------------
71 static ::rtl::OUString getWindowState(const css::uno::Reference< css::awt::XWindow >& xWindow)
73 if (!xWindow.is())
74 return ::rtl::OUString();
76 // SOLAR SAFE -> ----------------------------
77 ::vos::OClearableGuard aSolarGuard(Application::GetSolarMutex());
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())
84 ULONG nMask = WINDOWSTATE_MASK_ALL;
85 nMask &= ~(WINDOWSTATE_MASK_MINIMIZED);
86 sWindowState = ((SystemWindow*)pWindow)->GetWindowState(nMask);
89 aSolarGuard.clear();
90 // <- SOLAR SAFE ----------------------------
92 return B2U_ENC(sWindowState,RTL_TEXTENCODING_UTF8);
95 //-----------------------------------------------
96 static void setWindowState(const css::uno::Reference< css::awt::XWindow >& xWindow ,
97 const ::rtl::OUString& sWindowState)
99 if (
100 (!xWindow.is() ) ||
101 (!sWindowState.getLength())
103 return;
105 // SOLAR SAFE -> ----------------------------
106 ::vos::OClearableGuard aSolarGuard(Application::GetSolarMutex());
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()) &&
114 // dont overwrite a might existing minimized mode!
115 (pWindow->GetType() != WINDOW_WORKWINDOW) ||
116 (!((WorkWindow*)pWindow)->IsMinimized() )
120 ((SystemWindow*)pWindow)->SetWindowState(U2B_ENC(sWindowState,RTL_TEXTENCODING_UTF8));
123 aSolarGuard.clear();
124 // <- SOLAR SAFE ----------------------------
127 //-----------------------------------------------
128 static ::sal_Bool isTopWindow(const css::uno::Reference< css::awt::XWindow >& xWindow)
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())
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())
145 return sal_True;
148 return sal_False;
153 } // namespace framework
155 #endif // __FRAMEWORK_PATTERN_WINDOW_HXX_