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