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