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 #include "svpframe.hxx" 29 #include "svpinst.hxx" 30 #include "svpgdi.hxx" 31 32 #include <basebmp/scanlineformats.hxx> 33 #include <basegfx/vector/b2ivector.hxx> 34 35 using namespace basebmp; 36 using namespace basegfx; 37 38 SvpSalFrame* SvpSalFrame::s_pFocusFrame = NULL; 39 40 SvpSalFrame::SvpSalFrame( SvpSalInstance* pInstance, 41 SalFrame* pParent, 42 sal_uLong nSalFrameStyle, 43 SystemParentData* ) : 44 m_pInstance( pInstance ), 45 m_pParent( static_cast<SvpSalFrame*>(pParent) ), 46 m_nStyle( nSalFrameStyle ), 47 m_bVisible( false ), 48 m_nMinWidth( 0 ), 49 m_nMinHeight( 0 ), 50 m_nMaxWidth( 0 ), 51 m_nMaxHeight( 0 ) 52 { 53 m_aSystemChildData.nSize = sizeof( SystemChildData ); 54 m_aSystemChildData.pDisplay = NULL; 55 m_aSystemChildData.aWindow = 0; 56 m_aSystemChildData.pSalFrame = this; 57 m_aSystemChildData.pWidget = NULL; 58 m_aSystemChildData.pVisual = NULL; 59 m_aSystemChildData.nDepth = 24; 60 m_aSystemChildData.aColormap = 0; 61 m_aSystemChildData.pAppContext = NULL; 62 m_aSystemChildData.aShellWindow = 0; 63 m_aSystemChildData.pShellWidget = NULL; 64 65 if( m_pParent ) 66 m_pParent->m_aChildren.push_back( this ); 67 68 if( m_pInstance ) 69 m_pInstance->registerFrame( this ); 70 71 SetPosSize( 0, 0, 800, 600, SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT ); 72 } 73 74 SvpSalFrame::~SvpSalFrame() 75 { 76 if( m_pInstance ) 77 m_pInstance->deregisterFrame( this ); 78 79 std::list<SvpSalFrame*> Children = m_aChildren; 80 for( std::list<SvpSalFrame*>::iterator it = Children.begin(); 81 it != Children.end(); ++it ) 82 (*it)->SetParent( m_pParent ); 83 if( m_pParent ) 84 m_pParent->m_aChildren.remove( this ); 85 86 if( s_pFocusFrame == this ) 87 { 88 s_pFocusFrame = NULL; 89 // call directly here, else an event for a destroyed frame would be dispatched 90 CallCallback( SALEVENT_LOSEFOCUS, NULL ); 91 // if the handler has not set a new focus frame 92 // pass focus to another frame, preferably a document style window 93 if( s_pFocusFrame == NULL ) 94 { 95 const std::list< SalFrame* >& rFrames( m_pInstance->getFrames() ); 96 for( std::list< SalFrame* >::const_iterator it = rFrames.begin(); it != rFrames.end(); ++it ) 97 { 98 SvpSalFrame* pFrame = const_cast<SvpSalFrame*>(static_cast<const SvpSalFrame*>(*it)); 99 if( pFrame->m_bVisible && 100 pFrame->m_pParent == NULL && 101 (pFrame->m_nStyle & (SAL_FRAME_STYLE_MOVEABLE | 102 SAL_FRAME_STYLE_SIZEABLE | 103 SAL_FRAME_STYLE_CLOSEABLE) ) != 0 104 ) 105 { 106 pFrame->GetFocus(); 107 break; 108 } 109 } 110 } 111 } 112 } 113 114 void SvpSalFrame::GetFocus() 115 { 116 if( (m_nStyle & (SAL_FRAME_STYLE_OWNERDRAWDECORATION | SAL_FRAME_STYLE_FLOAT)) == 0 ) 117 { 118 if( s_pFocusFrame ) 119 s_pFocusFrame->LoseFocus(); 120 s_pFocusFrame = this; 121 m_pInstance->PostEvent( this, NULL, SALEVENT_GETFOCUS ); 122 } 123 } 124 125 void SvpSalFrame::LoseFocus() 126 { 127 if( s_pFocusFrame == this ) 128 { 129 m_pInstance->PostEvent( this, NULL, SALEVENT_LOSEFOCUS ); 130 s_pFocusFrame = NULL; 131 } 132 } 133 134 SalGraphics* SvpSalFrame::GetGraphics() 135 { 136 SvpSalGraphics* pGraphics = new SvpSalGraphics(); 137 pGraphics->setDevice( m_aFrame ); 138 m_aGraphics.push_back( pGraphics ); 139 return pGraphics; 140 } 141 142 void SvpSalFrame::ReleaseGraphics( SalGraphics* pGraphics ) 143 { 144 SvpSalGraphics* pSvpGraphics = dynamic_cast<SvpSalGraphics*>(pGraphics); 145 m_aGraphics.remove( pSvpGraphics ); 146 delete pSvpGraphics; 147 } 148 149 sal_Bool SvpSalFrame::PostEvent( void* pData ) 150 { 151 m_pInstance->PostEvent( this, pData, SALEVENT_USEREVENT ); 152 return sal_True; 153 } 154 155 void SvpSalFrame::PostPaint() const 156 { 157 if( m_bVisible ) 158 { 159 SalPaintEvent aPEvt(0, 0, maGeometry.nWidth, maGeometry.nHeight); 160 CallCallback( SALEVENT_PAINT, &aPEvt ); 161 } 162 } 163 164 void SvpSalFrame::SetTitle( const XubString& ) 165 { 166 } 167 168 void SvpSalFrame::SetIcon( sal_uInt16 ) 169 { 170 } 171 172 void SvpSalFrame::SetMenu( SalMenu* ) 173 { 174 } 175 176 void SvpSalFrame::DrawMenuBar() 177 { 178 } 179 180 void SvpSalFrame::SetExtendedFrameStyle( SalExtStyle ) 181 { 182 } 183 184 void SvpSalFrame::Show( sal_Bool bVisible, sal_Bool bNoActivate ) 185 { 186 if( bVisible && ! m_bVisible ) 187 { 188 m_bVisible = true; 189 m_pInstance->PostEvent( this, NULL, SALEVENT_RESIZE ); 190 if( ! bNoActivate ) 191 GetFocus(); 192 } 193 else if( ! bVisible && m_bVisible ) 194 { 195 m_bVisible = false; 196 m_pInstance->PostEvent( this, NULL, SALEVENT_RESIZE ); 197 LoseFocus(); 198 } 199 } 200 201 void SvpSalFrame::Enable( sal_Bool ) 202 { 203 } 204 205 void SvpSalFrame::SetMinClientSize( long nWidth, long nHeight ) 206 { 207 m_nMinWidth = nWidth; 208 m_nMinHeight = nHeight; 209 } 210 211 void SvpSalFrame::SetMaxClientSize( long nWidth, long nHeight ) 212 { 213 m_nMaxWidth = nWidth; 214 m_nMaxHeight = nHeight; 215 } 216 217 void SvpSalFrame::SetPosSize( long nX, long nY, long nWidth, long nHeight, sal_uInt16 nFlags ) 218 { 219 if( (nFlags & SAL_FRAME_POSSIZE_X) != 0 ) 220 maGeometry.nX = nX; 221 if( (nFlags & SAL_FRAME_POSSIZE_Y) != 0 ) 222 maGeometry.nY = nY; 223 if( (nFlags & SAL_FRAME_POSSIZE_WIDTH) != 0 ) 224 { 225 maGeometry.nWidth = nWidth; 226 if( m_nMaxWidth > 0 && maGeometry.nWidth > (unsigned int)m_nMaxWidth ) 227 maGeometry.nWidth = m_nMaxWidth; 228 if( m_nMinWidth > 0 && maGeometry.nWidth < (unsigned int)m_nMinWidth ) 229 maGeometry.nWidth = m_nMinWidth; 230 } 231 if( (nFlags & SAL_FRAME_POSSIZE_HEIGHT) != 0 ) 232 { 233 maGeometry.nHeight = nHeight; 234 if( m_nMaxHeight > 0 && maGeometry.nHeight > (unsigned int)m_nMaxHeight ) 235 maGeometry.nHeight = m_nMaxHeight; 236 if( m_nMinHeight > 0 && maGeometry.nHeight < (unsigned int)m_nMinHeight ) 237 maGeometry.nHeight = m_nMinHeight; 238 } 239 B2IVector aFrameSize( maGeometry.nWidth, maGeometry.nHeight ); 240 if( ! m_aFrame.get() || m_aFrame->getSize() != aFrameSize ) 241 { 242 if( aFrameSize.getX() == 0 ) 243 aFrameSize.setX( 1 ); 244 if( aFrameSize.getY() == 0 ) 245 aFrameSize.setY( 1 ); 246 m_aFrame = createBitmapDevice( aFrameSize, false, SVP_DEFAULT_BITMAP_FORMAT ); 247 // update device in existing graphics 248 for( std::list< SvpSalGraphics* >::iterator it = m_aGraphics.begin(); 249 it != m_aGraphics.end(); ++it ) 250 (*it)->setDevice( m_aFrame ); 251 } 252 if( m_bVisible ) 253 m_pInstance->PostEvent( this, NULL, SALEVENT_RESIZE ); 254 } 255 256 void SvpSalFrame::GetClientSize( long& rWidth, long& rHeight ) 257 { 258 if( m_bVisible ) 259 { 260 rWidth = maGeometry.nWidth; 261 rHeight = maGeometry.nHeight; 262 } 263 else 264 rWidth = rHeight = 0; 265 } 266 267 void SvpSalFrame::GetWorkArea( Rectangle& rRect ) 268 { 269 rRect = Rectangle( Point( 0, 0 ), 270 Size( VIRTUAL_DESKTOP_WIDTH, VIRTUAL_DESKTOP_HEIGHT ) ); 271 } 272 273 SalFrame* SvpSalFrame::GetParent() const 274 { 275 return m_pParent; 276 } 277 278 #define _FRAMESTATE_MASK_GEOMETRY \ 279 (SAL_FRAMESTATE_MASK_X | SAL_FRAMESTATE_MASK_Y | \ 280 SAL_FRAMESTATE_MASK_WIDTH | SAL_FRAMESTATE_MASK_HEIGHT) 281 #define _FRAMESTATE_MASK_MAXIMIZED_GEOMETRY \ 282 (SAL_FRAMESTATE_MASK_MAXIMIZED_X | SAL_FRAMESTATE_MASK_MAXIMIZED_Y | \ 283 SAL_FRAMESTATE_MASK_MAXIMIZED_WIDTH | SAL_FRAMESTATE_MASK_MAXIMIZED_HEIGHT) 284 285 void SvpSalFrame::SetWindowState( const SalFrameState *pState ) 286 { 287 if (pState == NULL) 288 return; 289 290 // Request for position or size change 291 if (pState->mnMask & _FRAMESTATE_MASK_GEOMETRY) 292 { 293 long nX = maGeometry.nX; 294 long nY = maGeometry.nY; 295 long nWidth = maGeometry.nWidth; 296 long nHeight = maGeometry.nHeight; 297 298 // change requested properties 299 if (pState->mnMask & SAL_FRAMESTATE_MASK_X) 300 nX = pState->mnX; 301 if (pState->mnMask & SAL_FRAMESTATE_MASK_Y) 302 nY = pState->mnY; 303 if (pState->mnMask & SAL_FRAMESTATE_MASK_WIDTH) 304 nWidth = pState->mnWidth; 305 if (pState->mnMask & SAL_FRAMESTATE_MASK_HEIGHT) 306 nHeight = pState->mnHeight; 307 308 SetPosSize( nX, nY, nWidth, nHeight, 309 SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y | 310 SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT ); 311 } 312 } 313 314 sal_Bool SvpSalFrame::GetWindowState( SalFrameState* pState ) 315 { 316 pState->mnState = SAL_FRAMESTATE_NORMAL; 317 pState->mnX = maGeometry.nX; 318 pState->mnY = maGeometry.nY; 319 pState->mnWidth = maGeometry.nWidth; 320 pState->mnHeight = maGeometry.nHeight; 321 pState->mnMask = _FRAMESTATE_MASK_GEOMETRY | SAL_FRAMESTATE_MASK_STATE; 322 323 return sal_True; 324 } 325 326 void SvpSalFrame::ShowFullScreen( sal_Bool, sal_Int32 ) 327 { 328 SetPosSize( 0, 0, VIRTUAL_DESKTOP_WIDTH, VIRTUAL_DESKTOP_HEIGHT, 329 SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT ); 330 } 331 332 void SvpSalFrame::StartPresentation( sal_Bool ) 333 { 334 } 335 336 void SvpSalFrame::SetAlwaysOnTop( sal_Bool ) 337 { 338 } 339 340 void SvpSalFrame::ToTop( sal_uInt16 ) 341 { 342 GetFocus(); 343 } 344 345 void SvpSalFrame::SetPointer( PointerStyle ) 346 { 347 } 348 349 void SvpSalFrame::CaptureMouse( sal_Bool ) 350 { 351 } 352 353 void SvpSalFrame::SetPointerPos( long, long ) 354 { 355 } 356 357 void SvpSalFrame::Flush() 358 { 359 } 360 361 void SvpSalFrame::Sync() 362 { 363 } 364 365 void SvpSalFrame::SetInputContext( SalInputContext* ) 366 { 367 } 368 369 void SvpSalFrame::EndExtTextInput( sal_uInt16 ) 370 { 371 } 372 373 String SvpSalFrame::GetKeyName( sal_uInt16 ) 374 { 375 return String(); 376 } 377 378 String SvpSalFrame::GetSymbolKeyName( const XubString&, sal_uInt16 ) 379 { 380 return String(); 381 } 382 383 sal_Bool SvpSalFrame::MapUnicodeToKeyCode( sal_Unicode, LanguageType, KeyCode& ) 384 { 385 return sal_False; 386 } 387 388 LanguageType SvpSalFrame::GetInputLanguage() 389 { 390 return LANGUAGE_DONTKNOW; 391 } 392 393 SalBitmap* SvpSalFrame::SnapShot() 394 { 395 return NULL; 396 } 397 398 void SvpSalFrame::UpdateSettings( AllSettings& ) 399 { 400 } 401 402 void SvpSalFrame::Beep( SoundType ) 403 { 404 } 405 406 const SystemEnvData* SvpSalFrame::GetSystemData() const 407 { 408 return &m_aSystemChildData; 409 } 410 411 SalFrame::SalPointerState SvpSalFrame::GetPointerState() 412 { 413 SalPointerState aState; 414 aState.mnState = 0; 415 return aState; 416 } 417 418 void SvpSalFrame::SetParent( SalFrame* pNewParent ) 419 { 420 if( m_pParent ) 421 m_pParent->m_aChildren.remove( this ); 422 m_pParent = static_cast<SvpSalFrame*>(pNewParent); 423 } 424 425 bool SvpSalFrame::SetPluginParent( SystemParentData* ) 426 { 427 return true; 428 } 429 430 void SvpSalFrame::SetBackgroundBitmap( SalBitmap* ) 431 { 432 } 433 434 void SvpSalFrame::ResetClipRegion() 435 { 436 } 437 438 void SvpSalFrame::BeginSetClipRegion( sal_uLong ) 439 { 440 } 441 442 void SvpSalFrame::UnionClipRegion( long, long, long, long ) 443 { 444 } 445 446 void SvpSalFrame::EndSetClipRegion() 447 { 448 } 449 450