xref: /aoo42x/main/vcl/source/window/wrkwin.cxx (revision 9f62ea84)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_vcl.hxx"
26 
27 #include <tools/debug.hxx>
28 #include <tools/rc.h>
29 
30 #include <vcl/svapp.hxx>
31 #include <vcl/wrkwin.hxx>
32 // declare system types in sysdata.hxx
33 #include <svsys.h>
34 #include <vcl/sysdata.hxx>
35 #include <com/sun/star/lang/XComponent.hpp>
36 #include <com/sun/star/rendering/XCanvas.hpp>
37 
38 #include <svdata.hxx>
39 #include <salframe.hxx>
40 #include <brdwin.hxx>
41 #include <window.h>
42 
43 // =======================================================================
44 
45 #define WORKWIN_WINDOWSTATE_FULLSCREEN          ((sal_uLong)0x00010000)
46 #define WORKWIN_WINDOWSTATE_ALL                 ((sal_uLong)0x00FF0000)
47 
48 // =======================================================================
49 
50 void WorkWindow::ImplInitWorkWindowData()
51 {
52     mnIcon                  = 0; // Should be removed in the next top level update - now in SystemWindow
53 
54     mnPresentationFlags     = 0;
55     mbPresentationMode      = sal_False;
56     mbPresentationVisible   = sal_False;
57     mbPresentationFull      = sal_False;
58     mbFullScreenMode        = sal_False;
59 }
60 
61 // -----------------------------------------------------------------------
62 
63 void WorkWindow::ImplInit( Window* pParent, WinBits nStyle, SystemParentData* pSystemParentData )
64 {
65     sal_uInt16 nFrameStyle = BORDERWINDOW_STYLE_FRAME;
66     if ( nStyle & WB_APP )
67         nFrameStyle |= BORDERWINDOW_STYLE_APP;
68 
69     ImplBorderWindow* pBorderWin = new ImplBorderWindow( pParent, pSystemParentData, nStyle, nFrameStyle );
70     Window::ImplInit( pBorderWin, nStyle & (WB_3DLOOK | WB_CLIPCHILDREN | WB_DIALOGCONTROL | WB_SYSTEMFLOATWIN), NULL );
71     pBorderWin->mpWindowImpl->mpClientWindow = this;
72     pBorderWin->GetBorder( mpWindowImpl->mnLeftBorder, mpWindowImpl->mnTopBorder, mpWindowImpl->mnRightBorder, mpWindowImpl->mnBottomBorder );
73     mpWindowImpl->mpBorderWindow  = pBorderWin;
74 //        mpWindowImpl->mpRealParent    = pParent; // !!! Muesste eigentlich gesetzt werden, aber wegen Fehlern mit dem MenuBar erstmal nicht gesetzt !!!
75 
76     if ( nStyle & WB_APP )
77     {
78         ImplSVData* pSVData = ImplGetSVData();
79         DBG_ASSERT( !pSVData->maWinData.mpAppWin, "WorkWindow::WorkWindow(): More than one window with style WB_APP" );
80         pSVData->maWinData.mpAppWin = this;
81     }
82 
83     SetActivateMode( ACTIVATE_MODE_GRABFOCUS );
84 }
85 
86 // -----------------------------------------------------------------------
87 
88 void WorkWindow::ImplInit( Window* pParent, WinBits nStyle, const ::com::sun::star::uno::Any& aSystemWorkWindowToken )
89 {
90     if( aSystemWorkWindowToken.hasValue() )
91     {
92         ::com::sun::star::uno::Sequence< sal_Int8 > aSeq;
93         aSystemWorkWindowToken >>= aSeq;
94         SystemParentData* pData = (SystemParentData*)aSeq.getArray();
95         DBG_ASSERT( aSeq.getLength() == sizeof( SystemParentData ) && pData->nSize == sizeof( SystemParentData ), "WorkWindow::WorkWindow( Window*, const Any&, WinBits ) called with invalid Any" );
96         // init with style 0 as does WorkWindow::WorkWindow( SystemParentData* );
97         ImplInit( pParent, 0, pData );
98     }
99     else
100         ImplInit( pParent, nStyle, NULL );
101 }
102 
103 // -----------------------------------------------------------------------
104 
105 WorkWindow::WorkWindow( WindowType nType ) :
106     SystemWindow( nType )
107 {
108     ImplInitWorkWindowData();
109 }
110 
111 // -----------------------------------------------------------------------
112 
113 WorkWindow::WorkWindow( Window* pParent, WinBits nStyle ) :
114     SystemWindow( WINDOW_WORKWINDOW )
115 {
116     ImplInitWorkWindowData();
117     ImplInit( pParent, nStyle, NULL );
118 }
119 
120 // -----------------------------------------------------------------------
121 
122 WorkWindow::WorkWindow( Window* pParent, const ResId& rResId ) :
123     SystemWindow( WINDOW_WORKWINDOW )
124 {
125     ImplInitWorkWindowData();
126     rResId.SetRT( RSC_WORKWIN );
127     WinBits nStyle = ImplInitRes( rResId );
128     ImplInit( pParent, nStyle );
129     ImplLoadRes( rResId );
130 }
131 
132 // -----------------------------------------------------------------------
133 
134 WorkWindow::WorkWindow( Window* pParent, const ::com::sun::star::uno::Any& aSystemWorkWindowToken, WinBits nStyle ) :
135     SystemWindow( WINDOW_WORKWINDOW )
136 {
137     ImplInitWorkWindowData();
138     mbSysChild = sal_True;
139     ImplInit( pParent, nStyle, aSystemWorkWindowToken );
140 }
141 
142 // -----------------------------------------------------------------------
143 
144 WorkWindow::WorkWindow( SystemParentData* pParent ) :
145     SystemWindow( WINDOW_WORKWINDOW )
146 {
147     ImplInitWorkWindowData();
148     mbSysChild = sal_True;
149     ImplInit( NULL, 0, pParent );
150 }
151 
152 // -----------------------------------------------------------------------
153 
154 void WorkWindow::ImplLoadRes( const ResId& rResId )
155 {
156     SystemWindow::ImplLoadRes( rResId );
157 
158     ReadLongRes();
159     if ( !(rResId.GetWinBits() & WB_HIDE) && (RSC_WORKWIN == rResId.GetRT()) )
160         Show();
161 }
162 
163 // -----------------------------------------------------------------------
164 
165 WorkWindow::~WorkWindow()
166 {
167     ImplSVData* pSVData = ImplGetSVData();
168     if ( pSVData->maWinData.mpAppWin == this )
169     {
170         pSVData->maWinData.mpAppWin = NULL;
171         Application::Quit();
172     }
173 }
174 
175 // -----------------------------------------------------------------------
176 
177 void WorkWindow::ShowFullScreenMode( sal_Bool bFullScreenMode, sal_Int32 nDisplay )
178 {
179     if ( !mbFullScreenMode == !bFullScreenMode )
180         return;
181 
182     if( (nDisplay < -1)
183     || (nDisplay >= static_cast<sal_Int32>(Application::GetScreenCount()) ) )
184     {
185         nDisplay = GetScreenNumber();
186     }
187 
188     mbFullScreenMode = bFullScreenMode != 0;
189     if ( !mbSysChild )
190     {
191         // Dispose of the canvas implementation, which might rely on
192         // screen-specific system data.
193         com::sun::star::uno::Reference< com::sun::star::rendering::XCanvas > xCanvas( mpWindowImpl->mxCanvas );
194         if( xCanvas.is() )
195         {
196             com::sun::star::uno::Reference< com::sun::star::lang::XComponent >
197                 xCanvasComponent( xCanvas,
198                                   com::sun::star::uno::UNO_QUERY );
199             if( xCanvasComponent.is() )
200                 xCanvasComponent->dispose();
201         }
202 
203         mpWindowImpl->mpFrameWindow->mpWindowImpl->mbWaitSystemResize = sal_True;
204         ImplGetFrame()->ShowFullScreen( bFullScreenMode, nDisplay );
205     }
206 }
207 
208 // -----------------------------------------------------------------------
209 
210 void WorkWindow::StartPresentationMode( sal_Bool bPresentation, sal_uInt16 nFlags, sal_Int32 nDisplay )
211 {
212     if ( !bPresentation == !mbPresentationMode )
213         return;
214 
215     if ( bPresentation )
216     {
217         mbPresentationMode      = sal_True;
218         mbPresentationVisible   = IsVisible();
219         mbPresentationFull      = mbFullScreenMode;
220         mnPresentationFlags     = nFlags;
221 
222         if ( !(mnPresentationFlags & PRESENTATION_NOFULLSCREEN) )
223             ShowFullScreenMode( sal_True, nDisplay );
224         if ( !mbSysChild )
225         {
226             if ( mnPresentationFlags & PRESENTATION_HIDEALLAPPS )
227                 mpWindowImpl->mpFrame->SetAlwaysOnTop( sal_True );
228             if ( !(mnPresentationFlags & PRESENTATION_NOAUTOSHOW) )
229                 ToTop();
230             mpWindowImpl->mpFrame->StartPresentation( sal_True );
231         }
232 
233         if ( !(mnPresentationFlags & PRESENTATION_NOAUTOSHOW) )
234             Show();
235     }
236     else
237     {
238         Show( mbPresentationVisible );
239         if ( !mbSysChild )
240         {
241             mpWindowImpl->mpFrame->StartPresentation( sal_False );
242             if ( mnPresentationFlags & PRESENTATION_HIDEALLAPPS )
243                 mpWindowImpl->mpFrame->SetAlwaysOnTop( sal_False );
244         }
245         ShowFullScreenMode( mbPresentationFull, nDisplay );
246 
247         mbPresentationMode      = sal_False;
248         mbPresentationVisible   = sal_False;
249         mbPresentationFull      = sal_False;
250         mnPresentationFlags     = 0;
251     }
252 }
253 
254 // -----------------------------------------------------------------------
255 
256 sal_Bool WorkWindow::IsMinimized() const
257 {
258     //return mpWindowImpl->mpFrameData->mbMinimized;
259 	SalFrameState aState;
260 	mpWindowImpl->mpFrame->GetWindowState(&aState);
261 	return (( aState.mnState & SAL_FRAMESTATE_MINIMIZED ) != 0);
262 }
263 
264 // -----------------------------------------------------------------------
265 
266 sal_Bool WorkWindow::SetPluginParent( SystemParentData* pParent )
267 {
268     DBG_ASSERT( ! mbPresentationMode && ! mbFullScreenMode, "SetPluginParent in fullscreen or presentation mode !" );
269 
270     bool bWasDnd = Window::ImplStopDnd();
271 
272     sal_Bool bShown = IsVisible();
273     Show( sal_False );
274     sal_Bool bRet = mpWindowImpl->mpFrame->SetPluginParent( pParent );
275     Show( bShown );
276 
277     if( bWasDnd )
278         Window::ImplStartDnd();
279 
280     return bRet;
281 }
282 
283 void WorkWindow::ImplSetFrameState( sal_uLong aFrameState )
284 {
285     SalFrameState   aState;
286     aState.mnMask   = SAL_FRAMESTATE_MASK_STATE;
287     aState.mnState  = aFrameState;
288     mpWindowImpl->mpFrame->SetWindowState( &aState );
289 }
290 
291 
292 void WorkWindow::Minimize()
293 {
294     ImplSetFrameState( SAL_FRAMESTATE_MINIMIZED );
295 }
296 
297 void WorkWindow::Restore()
298 {
299     ImplSetFrameState( SAL_FRAMESTATE_NORMAL );
300 }
301 
302 sal_Bool WorkWindow::Close()
303 {
304     sal_Bool bCanClose = SystemWindow::Close();
305 
306     // Ist es das Applikationsfenster, dann beende die Applikation
307     if ( bCanClose && ( ImplGetSVData()->maWinData.mpAppWin == this ) )
308         GetpApp()->Quit();
309 
310     return bCanClose;
311 }
312 
313 void WorkWindow::Maximize( sal_Bool bMaximize )
314 {
315     ImplSetFrameState( bMaximize ? SAL_FRAMESTATE_MAXIMIZED : SAL_FRAMESTATE_NORMAL );
316 }
317 
318 sal_Bool WorkWindow::IsMaximized() const
319 {
320     sal_Bool bRet = sal_False;
321 
322     SalFrameState aState;
323     if( mpWindowImpl->mpFrame->GetWindowState( &aState ) )
324     {
325         if( aState.mnState & (SAL_FRAMESTATE_MAXIMIZED			|
326                               SAL_FRAMESTATE_MAXIMIZED_HORZ		|
327                               SAL_FRAMESTATE_MAXIMIZED_VERT ) )
328             bRet = sal_True;
329     }
330     return bRet;
331 }
332