xref: /aoo41x/main/vcl/source/window/wrkwin.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_vcl.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <tools/debug.hxx>
32*cdf0e10cSrcweir #include <tools/rc.h>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include <vcl/svapp.hxx>
35*cdf0e10cSrcweir #include <vcl/wrkwin.hxx>
36*cdf0e10cSrcweir // declare system types in sysdata.hxx
37*cdf0e10cSrcweir #include <svsys.h>
38*cdf0e10cSrcweir #include <vcl/sysdata.hxx>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include <svdata.hxx>
41*cdf0e10cSrcweir #include <salframe.hxx>
42*cdf0e10cSrcweir #include <brdwin.hxx>
43*cdf0e10cSrcweir #include <window.h>
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir // =======================================================================
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir #define WORKWIN_WINDOWSTATE_FULLSCREEN          ((sal_uLong)0x00010000)
48*cdf0e10cSrcweir #define WORKWIN_WINDOWSTATE_ALL                 ((sal_uLong)0x00FF0000)
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir // =======================================================================
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir void WorkWindow::ImplInitWorkWindowData()
53*cdf0e10cSrcweir {
54*cdf0e10cSrcweir     mnIcon                  = 0; // Should be removed in the next top level update - now in SystemWindow
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir     mnPresentationFlags     = 0;
57*cdf0e10cSrcweir     mbPresentationMode      = sal_False;
58*cdf0e10cSrcweir     mbPresentationVisible   = sal_False;
59*cdf0e10cSrcweir     mbPresentationFull      = sal_False;
60*cdf0e10cSrcweir     mbFullScreenMode        = sal_False;
61*cdf0e10cSrcweir }
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir // -----------------------------------------------------------------------
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir void WorkWindow::ImplInit( Window* pParent, WinBits nStyle, SystemParentData* pSystemParentData )
66*cdf0e10cSrcweir {
67*cdf0e10cSrcweir     sal_uInt16 nFrameStyle = BORDERWINDOW_STYLE_FRAME;
68*cdf0e10cSrcweir     if ( nStyle & WB_APP )
69*cdf0e10cSrcweir         nFrameStyle |= BORDERWINDOW_STYLE_APP;
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir     ImplBorderWindow* pBorderWin = new ImplBorderWindow( pParent, pSystemParentData, nStyle, nFrameStyle );
72*cdf0e10cSrcweir     Window::ImplInit( pBorderWin, nStyle & (WB_3DLOOK | WB_CLIPCHILDREN | WB_DIALOGCONTROL | WB_SYSTEMFLOATWIN), NULL );
73*cdf0e10cSrcweir     pBorderWin->mpWindowImpl->mpClientWindow = this;
74*cdf0e10cSrcweir     pBorderWin->GetBorder( mpWindowImpl->mnLeftBorder, mpWindowImpl->mnTopBorder, mpWindowImpl->mnRightBorder, mpWindowImpl->mnBottomBorder );
75*cdf0e10cSrcweir     mpWindowImpl->mpBorderWindow  = pBorderWin;
76*cdf0e10cSrcweir //        mpWindowImpl->mpRealParent    = pParent; // !!! Muesste eigentlich gesetzt werden, aber wegen Fehlern mit dem MenuBar erstmal nicht gesetzt !!!
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir     if ( nStyle & WB_APP )
79*cdf0e10cSrcweir     {
80*cdf0e10cSrcweir         ImplSVData* pSVData = ImplGetSVData();
81*cdf0e10cSrcweir         DBG_ASSERT( !pSVData->maWinData.mpAppWin, "WorkWindow::WorkWindow(): More than one window with style WB_APP" );
82*cdf0e10cSrcweir         pSVData->maWinData.mpAppWin = this;
83*cdf0e10cSrcweir     }
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir     SetActivateMode( ACTIVATE_MODE_GRABFOCUS );
86*cdf0e10cSrcweir }
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir // -----------------------------------------------------------------------
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir void WorkWindow::ImplInit( Window* pParent, WinBits nStyle, const ::com::sun::star::uno::Any& aSystemWorkWindowToken )
91*cdf0e10cSrcweir {
92*cdf0e10cSrcweir     if( aSystemWorkWindowToken.hasValue() )
93*cdf0e10cSrcweir     {
94*cdf0e10cSrcweir         ::com::sun::star::uno::Sequence< sal_Int8 > aSeq;
95*cdf0e10cSrcweir         aSystemWorkWindowToken >>= aSeq;
96*cdf0e10cSrcweir         SystemParentData* pData = (SystemParentData*)aSeq.getArray();
97*cdf0e10cSrcweir         DBG_ASSERT( aSeq.getLength() == sizeof( SystemParentData ) && pData->nSize == sizeof( SystemParentData ), "WorkWindow::WorkWindow( Window*, const Any&, WinBits ) called with invalid Any" );
98*cdf0e10cSrcweir         // init with style 0 as does WorkWindow::WorkWindow( SystemParentData* );
99*cdf0e10cSrcweir         ImplInit( pParent, 0, pData );
100*cdf0e10cSrcweir     }
101*cdf0e10cSrcweir     else
102*cdf0e10cSrcweir         ImplInit( pParent, nStyle, NULL );
103*cdf0e10cSrcweir }
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir // -----------------------------------------------------------------------
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir WorkWindow::WorkWindow( WindowType nType ) :
108*cdf0e10cSrcweir     SystemWindow( nType )
109*cdf0e10cSrcweir {
110*cdf0e10cSrcweir     ImplInitWorkWindowData();
111*cdf0e10cSrcweir }
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir // -----------------------------------------------------------------------
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir WorkWindow::WorkWindow( Window* pParent, WinBits nStyle ) :
116*cdf0e10cSrcweir     SystemWindow( WINDOW_WORKWINDOW )
117*cdf0e10cSrcweir {
118*cdf0e10cSrcweir     ImplInitWorkWindowData();
119*cdf0e10cSrcweir     ImplInit( pParent, nStyle, NULL );
120*cdf0e10cSrcweir }
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir // -----------------------------------------------------------------------
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir WorkWindow::WorkWindow( Window* pParent, const ResId& rResId ) :
125*cdf0e10cSrcweir     SystemWindow( WINDOW_WORKWINDOW )
126*cdf0e10cSrcweir {
127*cdf0e10cSrcweir     ImplInitWorkWindowData();
128*cdf0e10cSrcweir     rResId.SetRT( RSC_WORKWIN );
129*cdf0e10cSrcweir     WinBits nStyle = ImplInitRes( rResId );
130*cdf0e10cSrcweir     ImplInit( pParent, nStyle );
131*cdf0e10cSrcweir     ImplLoadRes( rResId );
132*cdf0e10cSrcweir }
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir // -----------------------------------------------------------------------
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir WorkWindow::WorkWindow( Window* pParent, const ::com::sun::star::uno::Any& aSystemWorkWindowToken, WinBits nStyle ) :
137*cdf0e10cSrcweir     SystemWindow( WINDOW_WORKWINDOW )
138*cdf0e10cSrcweir {
139*cdf0e10cSrcweir     ImplInitWorkWindowData();
140*cdf0e10cSrcweir     mbSysChild = sal_True;
141*cdf0e10cSrcweir     ImplInit( pParent, nStyle, aSystemWorkWindowToken );
142*cdf0e10cSrcweir }
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir // -----------------------------------------------------------------------
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir WorkWindow::WorkWindow( SystemParentData* pParent ) :
147*cdf0e10cSrcweir     SystemWindow( WINDOW_WORKWINDOW )
148*cdf0e10cSrcweir {
149*cdf0e10cSrcweir     ImplInitWorkWindowData();
150*cdf0e10cSrcweir     mbSysChild = sal_True;
151*cdf0e10cSrcweir     ImplInit( NULL, 0, pParent );
152*cdf0e10cSrcweir }
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir // -----------------------------------------------------------------------
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir void WorkWindow::ImplLoadRes( const ResId& rResId )
157*cdf0e10cSrcweir {
158*cdf0e10cSrcweir     SystemWindow::ImplLoadRes( rResId );
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir     ReadLongRes();
161*cdf0e10cSrcweir     if ( !(rResId.GetWinBits() & WB_HIDE) && (RSC_WORKWIN == rResId.GetRT()) )
162*cdf0e10cSrcweir         Show();
163*cdf0e10cSrcweir }
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir // -----------------------------------------------------------------------
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir WorkWindow::~WorkWindow()
168*cdf0e10cSrcweir {
169*cdf0e10cSrcweir     ImplSVData* pSVData = ImplGetSVData();
170*cdf0e10cSrcweir     if ( pSVData->maWinData.mpAppWin == this )
171*cdf0e10cSrcweir     {
172*cdf0e10cSrcweir         pSVData->maWinData.mpAppWin = NULL;
173*cdf0e10cSrcweir         Application::Quit();
174*cdf0e10cSrcweir     }
175*cdf0e10cSrcweir }
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir // -----------------------------------------------------------------------
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir void WorkWindow::ShowFullScreenMode( sal_Bool bFullScreenMode, sal_Int32 nDisplay )
180*cdf0e10cSrcweir {
181*cdf0e10cSrcweir     if ( !mbFullScreenMode == !bFullScreenMode )
182*cdf0e10cSrcweir         return;
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir     if( (nDisplay < -1)
185*cdf0e10cSrcweir     || (nDisplay >= static_cast<sal_Int32>(Application::GetScreenCount()) ) )
186*cdf0e10cSrcweir     {
187*cdf0e10cSrcweir         nDisplay = GetScreenNumber();
188*cdf0e10cSrcweir     }
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir     mbFullScreenMode = bFullScreenMode != 0;
191*cdf0e10cSrcweir     if ( !mbSysChild )
192*cdf0e10cSrcweir     {
193*cdf0e10cSrcweir         mpWindowImpl->mpFrameWindow->mpWindowImpl->mbWaitSystemResize = sal_True;
194*cdf0e10cSrcweir         ImplGetFrame()->ShowFullScreen( bFullScreenMode, nDisplay );
195*cdf0e10cSrcweir     }
196*cdf0e10cSrcweir }
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir // -----------------------------------------------------------------------
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir void WorkWindow::StartPresentationMode( sal_Bool bPresentation, sal_uInt16 nFlags, sal_Int32 nDisplay )
201*cdf0e10cSrcweir {
202*cdf0e10cSrcweir     if ( !bPresentation == !mbPresentationMode )
203*cdf0e10cSrcweir         return;
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir     if ( bPresentation )
206*cdf0e10cSrcweir     {
207*cdf0e10cSrcweir         mbPresentationMode      = sal_True;
208*cdf0e10cSrcweir         mbPresentationVisible   = IsVisible();
209*cdf0e10cSrcweir         mbPresentationFull      = mbFullScreenMode;
210*cdf0e10cSrcweir         mnPresentationFlags     = nFlags;
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir         if ( !(mnPresentationFlags & PRESENTATION_NOFULLSCREEN) )
213*cdf0e10cSrcweir             ShowFullScreenMode( sal_True, nDisplay );
214*cdf0e10cSrcweir         if ( !mbSysChild )
215*cdf0e10cSrcweir         {
216*cdf0e10cSrcweir             if ( mnPresentationFlags & PRESENTATION_HIDEALLAPPS )
217*cdf0e10cSrcweir                 mpWindowImpl->mpFrame->SetAlwaysOnTop( sal_True );
218*cdf0e10cSrcweir             if ( !(mnPresentationFlags & PRESENTATION_NOAUTOSHOW) )
219*cdf0e10cSrcweir                 ToTop();
220*cdf0e10cSrcweir             mpWindowImpl->mpFrame->StartPresentation( sal_True );
221*cdf0e10cSrcweir         }
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir         if ( !(mnPresentationFlags & PRESENTATION_NOAUTOSHOW) )
224*cdf0e10cSrcweir             Show();
225*cdf0e10cSrcweir     }
226*cdf0e10cSrcweir     else
227*cdf0e10cSrcweir     {
228*cdf0e10cSrcweir         Show( mbPresentationVisible );
229*cdf0e10cSrcweir         if ( !mbSysChild )
230*cdf0e10cSrcweir         {
231*cdf0e10cSrcweir             mpWindowImpl->mpFrame->StartPresentation( sal_False );
232*cdf0e10cSrcweir             if ( mnPresentationFlags & PRESENTATION_HIDEALLAPPS )
233*cdf0e10cSrcweir                 mpWindowImpl->mpFrame->SetAlwaysOnTop( sal_False );
234*cdf0e10cSrcweir         }
235*cdf0e10cSrcweir         ShowFullScreenMode( mbPresentationFull, nDisplay );
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir         mbPresentationMode      = sal_False;
238*cdf0e10cSrcweir         mbPresentationVisible   = sal_False;
239*cdf0e10cSrcweir         mbPresentationFull      = sal_False;
240*cdf0e10cSrcweir         mnPresentationFlags     = 0;
241*cdf0e10cSrcweir     }
242*cdf0e10cSrcweir }
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir // -----------------------------------------------------------------------
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir sal_Bool WorkWindow::IsMinimized() const
247*cdf0e10cSrcweir {
248*cdf0e10cSrcweir     //return mpWindowImpl->mpFrameData->mbMinimized;
249*cdf0e10cSrcweir 	SalFrameState aState;
250*cdf0e10cSrcweir 	mpWindowImpl->mpFrame->GetWindowState(&aState);
251*cdf0e10cSrcweir 	return (( aState.mnState & SAL_FRAMESTATE_MINIMIZED ) != 0);
252*cdf0e10cSrcweir }
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir // -----------------------------------------------------------------------
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir sal_Bool WorkWindow::SetPluginParent( SystemParentData* pParent )
257*cdf0e10cSrcweir {
258*cdf0e10cSrcweir     DBG_ASSERT( ! mbPresentationMode && ! mbFullScreenMode, "SetPluginParent in fullscreen or presentation mode !" );
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir     bool bWasDnd = Window::ImplStopDnd();
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir     sal_Bool bShown = IsVisible();
263*cdf0e10cSrcweir     Show( sal_False );
264*cdf0e10cSrcweir     sal_Bool bRet = mpWindowImpl->mpFrame->SetPluginParent( pParent );
265*cdf0e10cSrcweir     Show( bShown );
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir     if( bWasDnd )
268*cdf0e10cSrcweir         Window::ImplStartDnd();
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir     return bRet;
271*cdf0e10cSrcweir }
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir void WorkWindow::ImplSetFrameState( sal_uLong aFrameState )
274*cdf0e10cSrcweir {
275*cdf0e10cSrcweir     SalFrameState   aState;
276*cdf0e10cSrcweir     aState.mnMask   = SAL_FRAMESTATE_MASK_STATE;
277*cdf0e10cSrcweir     aState.mnState  = aFrameState;
278*cdf0e10cSrcweir     mpWindowImpl->mpFrame->SetWindowState( &aState );
279*cdf0e10cSrcweir }
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir void WorkWindow::Minimize()
283*cdf0e10cSrcweir {
284*cdf0e10cSrcweir     ImplSetFrameState( SAL_FRAMESTATE_MINIMIZED );
285*cdf0e10cSrcweir }
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir void WorkWindow::Restore()
288*cdf0e10cSrcweir {
289*cdf0e10cSrcweir     ImplSetFrameState( SAL_FRAMESTATE_NORMAL );
290*cdf0e10cSrcweir }
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir sal_Bool WorkWindow::Close()
293*cdf0e10cSrcweir {
294*cdf0e10cSrcweir     sal_Bool bCanClose = SystemWindow::Close();
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir     // Ist es das Applikationsfenster, dann beende die Applikation
297*cdf0e10cSrcweir     if ( bCanClose && ( ImplGetSVData()->maWinData.mpAppWin == this ) )
298*cdf0e10cSrcweir         GetpApp()->Quit();
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir     return bCanClose;
301*cdf0e10cSrcweir }
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir void WorkWindow::Maximize( sal_Bool bMaximize )
304*cdf0e10cSrcweir {
305*cdf0e10cSrcweir     ImplSetFrameState( bMaximize ? SAL_FRAMESTATE_MAXIMIZED : SAL_FRAMESTATE_NORMAL );
306*cdf0e10cSrcweir }
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir sal_Bool WorkWindow::IsMaximized() const
309*cdf0e10cSrcweir {
310*cdf0e10cSrcweir     sal_Bool bRet = sal_False;
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir     SalFrameState aState;
313*cdf0e10cSrcweir     if( mpWindowImpl->mpFrame->GetWindowState( &aState ) )
314*cdf0e10cSrcweir     {
315*cdf0e10cSrcweir         if( aState.mnState & (SAL_FRAMESTATE_MAXIMIZED			|
316*cdf0e10cSrcweir                               SAL_FRAMESTATE_MAXIMIZED_HORZ		|
317*cdf0e10cSrcweir                               SAL_FRAMESTATE_MAXIMIZED_VERT ) )
318*cdf0e10cSrcweir             bRet = sal_True;
319*cdf0e10cSrcweir     }
320*cdf0e10cSrcweir     return bRet;
321*cdf0e10cSrcweir }
322