1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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"
37 #include <vcl/salframe.hxx>
38 #include <tools/debug.hxx>
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
);
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();
148 ImplInit( pParent
, nStyle
, aSystemWorkWindowToken
);
151 // -----------------------------------------------------------------------
153 WorkWindow::WorkWindow( SystemParentData
* pParent
) :
154 SystemWindow( WINDOW_WORKWINDOW
)
156 ImplInitWorkWindowData();
158 ImplInit( NULL
, 0, pParent
);
161 // -----------------------------------------------------------------------
163 void WorkWindow::ImplLoadRes( const ResId
& rResId
)
165 SystemWindow::ImplLoadRes( rResId
);
168 if ( !(rResId
.GetWinBits() & WB_HIDE
) && (RSC_WORKWIN
== rResId
.GetRT()) )
172 // -----------------------------------------------------------------------
174 WorkWindow::~WorkWindow()
176 ImplSVData
* pSVData
= ImplGetSVData();
177 if ( pSVData
->maWinData
.mpAppWin
== this )
179 pSVData
->maWinData
.mpAppWin
= NULL
;
184 // -----------------------------------------------------------------------
186 void WorkWindow::ShowFullScreenMode( BOOL bFullScreenMode
, sal_Int32 nDisplay
)
188 if ( !mbFullScreenMode
== !bFullScreenMode
)
192 || (nDisplay
>= static_cast<sal_Int32
>(Application::GetScreenCount()) ) )
194 nDisplay
= GetScreenNumber();
197 mbFullScreenMode
= bFullScreenMode
!= 0;
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
);
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
)
226 mbPresentationMode
= TRUE
;
227 mbPresentationVisible
= IsVisible();
228 mbPresentationFull
= mbFullScreenMode
;
229 mnPresentationFlags
= nFlags
;
231 if ( !(mnPresentationFlags
& PRESENTATION_NOFULLSCREEN
) )
232 ShowFullScreenMode( TRUE
, nDisplay
);
235 if ( mnPresentationFlags
& PRESENTATION_HIDEALLAPPS
)
236 mpWindowImpl
->mpFrame
->SetAlwaysOnTop( TRUE
);
237 if ( !(mnPresentationFlags
& PRESENTATION_NOAUTOSHOW
) )
239 mpWindowImpl
->mpFrame
->StartPresentation( TRUE
);
242 if ( !(mnPresentationFlags
& PRESENTATION_NOAUTOSHOW
) )
247 Show( mbPresentationVisible
);
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();
283 BOOL bRet
= mpWindowImpl
->mpFrame
->SetPluginParent( pParent
);
287 Window::ImplStartDnd();
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 ) )
322 void WorkWindow::Maximize( BOOL bMaximize
)
324 ImplSetFrameState( bMaximize
? SAL_FRAMESTATE_MAXIMIZED
: SAL_FRAMESTATE_NORMAL
);
327 BOOL
WorkWindow::IsMaximized()
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
) )