Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_FRAMEWORK_SOURCE_INC_PATTERN_WINDOW_HXX
21 : #define INCLUDED_FRAMEWORK_SOURCE_INC_PATTERN_WINDOW_HXX
22 :
23 : #include <general.h>
24 :
25 : #include <com/sun/star/awt/XWindow.hpp>
26 : #include <com/sun/star/awt/XTopWindow.hpp>
27 :
28 : #include <toolkit/helper/vclunohelper.hxx>
29 : #include <vcl/window.hxx>
30 : #include <vcl/syswin.hxx>
31 : #include <vcl/wrkwin.hxx>
32 : #include <vcl/svapp.hxx>
33 : #include <osl/mutex.hxx>
34 : #include <rtl/ustring.hxx>
35 :
36 : // namespaces
37 :
38 : namespace framework{
39 :
40 : class WindowHelper
41 : {
42 : public:
43 :
44 : static OUString getWindowState(const css::uno::Reference< css::awt::XWindow >& xWindow)
45 : {
46 : if (!xWindow.is())
47 : return OUString();
48 :
49 : OString sWindowState;
50 : // SOLAR SAFE -> ----------------------------
51 : {
52 : SolarMutexGuard aSolarGuard;
53 :
54 : vcl::Window* pWindow = VCLUnoHelper::GetWindow(xWindow);
55 : // check for system window is necessary to guarantee correct pointer cast!
56 : if (pWindow!=NULL && pWindow->IsSystemWindow())
57 : {
58 : sal_uLong nMask = WINDOWSTATE_MASK_ALL;
59 : nMask &= ~(WINDOWSTATE_MASK_MINIMIZED);
60 : sWindowState = static_cast<SystemWindow*>(pWindow)->GetWindowState(nMask);
61 : }
62 : }
63 : // <- SOLAR SAFE ----------------------------
64 :
65 : return OStringToOUString(sWindowState,RTL_TEXTENCODING_UTF8);
66 : }
67 :
68 : static void setWindowState(const css::uno::Reference< css::awt::XWindow >& xWindow ,
69 : const OUString& sWindowState)
70 : {
71 : if (
72 : (!xWindow.is() ) ||
73 : (!sWindowState.getLength())
74 : )
75 : return;
76 :
77 : // SOLAR SAFE -> ----------------------------
78 : SolarMutexGuard aSolarGuard;
79 :
80 : vcl::Window* pWindow = VCLUnoHelper::GetWindow(xWindow);
81 : // check for system window is necessary to guarantee correct pointer cast!
82 : if (
83 : (pWindow ) &&
84 : (pWindow->IsSystemWindow()) &&
85 : (
86 : // dont overwrite a might existing minimized mode!
87 : (pWindow->GetType() != WINDOW_WORKWINDOW) ||
88 : (!static_cast<WorkWindow*>(pWindow)->IsMinimized() )
89 : )
90 : )
91 : {
92 : static_cast<SystemWindow*>(pWindow)->SetWindowState(OUStringToOString(sWindowState,RTL_TEXTENCODING_UTF8));
93 : }
94 :
95 : // <- SOLAR SAFE ----------------------------
96 : }
97 :
98 2854 : static bool isTopWindow(const css::uno::Reference< css::awt::XWindow >& xWindow)
99 : {
100 : // even child frame containing top level windows (e.g. query designer of database) will be closed
101 2854 : css::uno::Reference< css::awt::XTopWindow > xTopWindowCheck(xWindow, css::uno::UNO_QUERY);
102 2854 : if (xTopWindowCheck.is())
103 : {
104 : // Note: Toolkit interface XTopWindow sometimes is used by real VCL-child-windows also .-)
105 : // Be sure that these window is really a "top system window".
106 : // Attention ! Checking Window->GetParent() is not the right approach here.
107 : // Because sometimes VCL create "implicit border windows" as parents even we created
108 : // a simple XWindow using the toolkit only .-(
109 2854 : SolarMutexGuard aSolarGuard;
110 2854 : vcl::Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
111 2854 : if (
112 5708 : (pWindow ) &&
113 2854 : (pWindow->IsSystemWindow())
114 : )
115 2850 : return true;
116 : }
117 :
118 4 : return false;
119 : }
120 :
121 : };
122 :
123 : } // namespace framework
124 :
125 : #endif // INCLUDED_FRAMEWORK_SOURCE_INC_PATTERN_WINDOW_HXX
126 :
127 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|