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