merge the formfield patch from ooo-build
[ooovba.git] / vcl / source / window / wrkwin.cxx
blobfc4ae00e6f227f5b5c0a5ccceb4e1f3407686b77
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: wrkwin.cxx,v $
10 * $Revision: 1.21.138.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
34 #ifndef _SV_SVSYS_HXX
35 #include <svsys.h>
36 #endif
37 #include <vcl/salframe.hxx>
38 #include <tools/debug.hxx>
40 #ifndef _SV_RC_H
41 #include <tools/rc.h>
42 #endif
43 #include <vcl/svdata.hxx>
44 #include <vcl/svapp.hxx>
45 #include <vcl/brdwin.hxx>
46 #include <vcl/window.h>
47 #include <vcl/wrkwin.hxx>
48 #include <vcl/sysdata.hxx>
49 #include <com/sun/star/lang/XComponent.hpp>
50 #include <com/sun/star/rendering/XCanvas.hpp>
52 // =======================================================================
54 #define WORKWIN_WINDOWSTATE_FULLSCREEN ((ULONG)0x00010000)
55 #define WORKWIN_WINDOWSTATE_ALL ((ULONG)0x00FF0000)
57 // =======================================================================
59 void WorkWindow::ImplInitWorkWindowData()
61 mnIcon = 0; // Should be removed in the next top level update - now in SystemWindow
63 mnPresentationFlags = 0;
64 mbPresentationMode = FALSE;
65 mbPresentationVisible = FALSE;
66 mbPresentationFull = FALSE;
67 mbFullScreenMode = FALSE;
70 // -----------------------------------------------------------------------
72 void WorkWindow::ImplInit( Window* pParent, WinBits nStyle, SystemParentData* pSystemParentData )
74 USHORT nFrameStyle = BORDERWINDOW_STYLE_FRAME;
75 if ( nStyle & WB_APP )
76 nFrameStyle |= BORDERWINDOW_STYLE_APP;
78 ImplBorderWindow* pBorderWin = new ImplBorderWindow( pParent, pSystemParentData, nStyle, nFrameStyle );
79 Window::ImplInit( pBorderWin, nStyle & (WB_3DLOOK | WB_CLIPCHILDREN | WB_DIALOGCONTROL | WB_SYSTEMFLOATWIN), NULL );
80 pBorderWin->mpWindowImpl->mpClientWindow = this;
81 pBorderWin->GetBorder( mpWindowImpl->mnLeftBorder, mpWindowImpl->mnTopBorder, mpWindowImpl->mnRightBorder, mpWindowImpl->mnBottomBorder );
82 mpWindowImpl->mpBorderWindow = pBorderWin;
83 // mpWindowImpl->mpRealParent = pParent; // !!! Muesste eigentlich gesetzt werden, aber wegen Fehlern mit dem MenuBar erstmal nicht gesetzt !!!
85 if ( nStyle & WB_APP )
87 ImplSVData* pSVData = ImplGetSVData();
88 DBG_ASSERT( !pSVData->maWinData.mpAppWin, "WorkWindow::WorkWindow(): More than one window with style WB_APP" );
89 pSVData->maWinData.mpAppWin = this;
92 SetActivateMode( ACTIVATE_MODE_GRABFOCUS );
95 // -----------------------------------------------------------------------
97 void WorkWindow::ImplInit( Window* pParent, WinBits nStyle, const ::com::sun::star::uno::Any& aSystemWorkWindowToken )
99 if( aSystemWorkWindowToken.hasValue() )
101 ::com::sun::star::uno::Sequence< sal_Int8 > aSeq;
102 aSystemWorkWindowToken >>= aSeq;
103 SystemParentData* pData = (SystemParentData*)aSeq.getArray();
104 DBG_ASSERT( aSeq.getLength() == sizeof( SystemParentData ) && pData->nSize == sizeof( SystemParentData ), "WorkWindow::WorkWindow( Window*, const Any&, WinBits ) called with invalid Any" );
105 // init with style 0 as does WorkWindow::WorkWindow( SystemParentData* );
106 ImplInit( pParent, 0, pData );
108 else
109 ImplInit( pParent, nStyle, NULL );
112 // -----------------------------------------------------------------------
114 WorkWindow::WorkWindow( WindowType nType ) :
115 SystemWindow( nType )
117 ImplInitWorkWindowData();
120 // -----------------------------------------------------------------------
122 WorkWindow::WorkWindow( Window* pParent, WinBits nStyle ) :
123 SystemWindow( WINDOW_WORKWINDOW )
125 ImplInitWorkWindowData();
126 ImplInit( pParent, nStyle, NULL );
129 // -----------------------------------------------------------------------
131 WorkWindow::WorkWindow( Window* pParent, const ResId& rResId ) :
132 SystemWindow( WINDOW_WORKWINDOW )
134 ImplInitWorkWindowData();
135 rResId.SetRT( RSC_WORKWIN );
136 WinBits nStyle = ImplInitRes( rResId );
137 ImplInit( pParent, nStyle );
138 ImplLoadRes( rResId );
141 // -----------------------------------------------------------------------
143 WorkWindow::WorkWindow( Window* pParent, const ::com::sun::star::uno::Any& aSystemWorkWindowToken, WinBits nStyle ) :
144 SystemWindow( WINDOW_WORKWINDOW )
146 ImplInitWorkWindowData();
147 mbSysChild = TRUE;
148 ImplInit( pParent, nStyle, aSystemWorkWindowToken );
151 // -----------------------------------------------------------------------
153 WorkWindow::WorkWindow( SystemParentData* pParent ) :
154 SystemWindow( WINDOW_WORKWINDOW )
156 ImplInitWorkWindowData();
157 mbSysChild = TRUE;
158 ImplInit( NULL, 0, pParent );
161 // -----------------------------------------------------------------------
163 void WorkWindow::ImplLoadRes( const ResId& rResId )
165 SystemWindow::ImplLoadRes( rResId );
167 ReadLongRes();
168 if ( !(rResId.GetWinBits() & WB_HIDE) && (RSC_WORKWIN == rResId.GetRT()) )
169 Show();
172 // -----------------------------------------------------------------------
174 WorkWindow::~WorkWindow()
176 ImplSVData* pSVData = ImplGetSVData();
177 if ( pSVData->maWinData.mpAppWin == this )
179 pSVData->maWinData.mpAppWin = NULL;
180 Application::Quit();
184 // -----------------------------------------------------------------------
186 void WorkWindow::ShowFullScreenMode( BOOL bFullScreenMode, sal_Int32 nDisplay )
188 if ( !mbFullScreenMode == !bFullScreenMode )
189 return;
191 if( (nDisplay < 0)
192 || (nDisplay >= static_cast<sal_Int32>(Application::GetScreenCount()) ) )
194 nDisplay = GetScreenNumber();
197 mbFullScreenMode = bFullScreenMode != 0;
198 if ( !mbSysChild )
200 // Dispose of the canvas implementation, which might rely on
201 // screen-specific system data.
202 com::sun::star::uno::Reference< com::sun::star::rendering::XCanvas > xCanvas( mpWindowImpl->mxCanvas );
203 if( xCanvas.is() )
205 com::sun::star::uno::Reference< com::sun::star::lang::XComponent >
206 xCanvasComponent( xCanvas,
207 com::sun::star::uno::UNO_QUERY );
208 if( xCanvasComponent.is() )
209 xCanvasComponent->dispose();
212 mpWindowImpl->mpFrameWindow->mpWindowImpl->mbWaitSystemResize = TRUE;
213 ImplGetFrame()->ShowFullScreen( bFullScreenMode, nDisplay );
217 // -----------------------------------------------------------------------
219 void WorkWindow::StartPresentationMode( BOOL bPresentation, USHORT nFlags, sal_Int32 nDisplay )
221 if ( !bPresentation == !mbPresentationMode )
222 return;
224 if ( bPresentation )
226 mbPresentationMode = TRUE;
227 mbPresentationVisible = IsVisible();
228 mbPresentationFull = mbFullScreenMode;
229 mnPresentationFlags = nFlags;
231 if ( !(mnPresentationFlags & PRESENTATION_NOFULLSCREEN) )
232 ShowFullScreenMode( TRUE, nDisplay );
233 if ( !mbSysChild )
235 if ( mnPresentationFlags & PRESENTATION_HIDEALLAPPS )
236 mpWindowImpl->mpFrame->SetAlwaysOnTop( TRUE );
237 if ( !(mnPresentationFlags & PRESENTATION_NOAUTOSHOW) )
238 ToTop();
239 mpWindowImpl->mpFrame->StartPresentation( TRUE );
242 if ( !(mnPresentationFlags & PRESENTATION_NOAUTOSHOW) )
243 Show();
245 else
247 Show( mbPresentationVisible );
248 if ( !mbSysChild )
250 mpWindowImpl->mpFrame->StartPresentation( FALSE );
251 if ( mnPresentationFlags & PRESENTATION_HIDEALLAPPS )
252 mpWindowImpl->mpFrame->SetAlwaysOnTop( FALSE );
254 ShowFullScreenMode( mbPresentationFull, nDisplay );
256 mbPresentationMode = FALSE;
257 mbPresentationVisible = FALSE;
258 mbPresentationFull = FALSE;
259 mnPresentationFlags = 0;
263 // -----------------------------------------------------------------------
265 BOOL WorkWindow::IsMinimized() const
267 //return mpWindowImpl->mpFrameData->mbMinimized;
268 SalFrameState aState;
269 mpWindowImpl->mpFrame->GetWindowState(&aState);
270 return (( aState.mnState & SAL_FRAMESTATE_MINIMIZED ) != 0);
273 // -----------------------------------------------------------------------
275 BOOL WorkWindow::SetPluginParent( SystemParentData* pParent )
277 DBG_ASSERT( ! mbPresentationMode && ! mbFullScreenMode, "SetPluginParent in fullscreen or presentation mode !" );
279 bool bWasDnd = Window::ImplStopDnd();
281 BOOL bShown = IsVisible();
282 Show( FALSE );
283 BOOL bRet = mpWindowImpl->mpFrame->SetPluginParent( pParent );
284 Show( bShown );
286 if( bWasDnd )
287 Window::ImplStartDnd();
289 return bRet;
292 void WorkWindow::ImplSetFrameState( ULONG aFrameState )
294 SalFrameState aState;
295 aState.mnMask = SAL_FRAMESTATE_MASK_STATE;
296 aState.mnState = aFrameState;
297 mpWindowImpl->mpFrame->SetWindowState( &aState );
301 void WorkWindow::Minimize()
303 ImplSetFrameState( SAL_FRAMESTATE_MINIMIZED );
306 void WorkWindow::Restore()
308 ImplSetFrameState( SAL_FRAMESTATE_NORMAL );
311 BOOL WorkWindow::Close()
313 BOOL bCanClose = SystemWindow::Close();
315 // Ist es das Applikationsfenster, dann beende die Applikation
316 if ( bCanClose && ( ImplGetSVData()->maWinData.mpAppWin == this ) )
317 GetpApp()->Quit();
319 return bCanClose;
322 void WorkWindow::Maximize( BOOL bMaximize )
324 ImplSetFrameState( bMaximize ? SAL_FRAMESTATE_MAXIMIZED : SAL_FRAMESTATE_NORMAL );
327 BOOL WorkWindow::IsMaximized()
329 BOOL bRet = FALSE;
331 SalFrameState aState;
332 if( mpWindowImpl->mpFrame->GetWindowState( &aState ) )
334 if( aState.mnState & (SAL_FRAMESTATE_MAXIMIZED |
335 SAL_FRAMESTATE_MAXIMIZED_HORZ |
336 SAL_FRAMESTATE_MAXIMIZED_VERT ) )
337 bRet = TRUE;
339 return bRet;