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