Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / vcl / headless / svpframe.cxx
blob0d4e4660f19758aa48182a8f62dc9dbcffa0979d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <string.h>
21 #include "headless/svpframe.hxx"
22 #include "headless/svpinst.hxx"
23 #include "headless/svpgdi.hxx"
25 #include <basebmp/bitmapdevice.hxx>
26 #include <basebmp/scanlineformats.hxx>
27 #include <basegfx/vector/b2ivector.hxx>
29 using namespace basebmp;
30 using namespace basegfx;
32 SvpSalFrame* SvpSalFrame::s_pFocusFrame = NULL;
34 namespace {
35 /// Decouple SalFrame lifetime from damagetracker lifetime
36 struct DamageTracker : public basebmp::IBitmapDeviceDamageTracker
38 DamageTracker( SvpSalFrame& rFrame ) : m_rFrame( rFrame ) {}
39 virtual ~DamageTracker() {}
40 virtual void damaged( const basegfx::B2IBox& rDamageRect ) const
42 m_rFrame.damaged( rDamageRect );
44 SvpSalFrame& m_rFrame;
48 void SvpSalFrame::enableDamageTracker( bool bOn )
50 if( m_bDamageTracking == bOn )
51 return;
52 if( m_aFrame.get() )
54 if( m_bDamageTracking )
55 m_aFrame->setDamageTracker( basebmp::IBitmapDeviceDamageTrackerSharedPtr() );
56 else
57 m_aFrame->setDamageTracker(
58 basebmp::IBitmapDeviceDamageTrackerSharedPtr( new DamageTracker( *this ) ) );
60 m_bDamageTracking = bOn;
63 SvpSalFrame::SvpSalFrame( SvpSalInstance* pInstance,
64 SalFrame* pParent,
65 sal_uLong nSalFrameStyle,
66 bool bTopDown,
67 sal_Int32 nScanlineFormat,
68 SystemParentData* ) :
69 m_pInstance( pInstance ),
70 m_pParent( static_cast<SvpSalFrame*>(pParent) ),
71 m_nStyle( nSalFrameStyle ),
72 m_bVisible( false ),
73 m_bDamageTracking( false ),
74 m_bTopDown( bTopDown ),
75 m_nScanlineFormat( nScanlineFormat ),
76 m_nMinWidth( 0 ),
77 m_nMinHeight( 0 ),
78 m_nMaxWidth( 0 ),
79 m_nMaxHeight( 0 )
81 // fast and easy cross-platform wiping of the data
82 memset( (void *)&m_aSystemChildData, 0, sizeof( SystemChildData ) );
83 m_aSystemChildData.nSize = sizeof( SystemChildData );
84 #if defined( UNX ) // FIXME: prolly redundant
85 m_aSystemChildData.pSalFrame = this;
86 #if defined(ANDROID) || defined(IOS)
87 // We want 32-bit RGBA bitmaps
88 m_aSystemChildData.nDepth = 32;
89 #else
90 m_aSystemChildData.nDepth = 24;
91 #endif
92 #endif
94 if( m_pParent )
95 m_pParent->m_aChildren.push_back( this );
97 if( m_pInstance )
98 m_pInstance->registerFrame( this );
100 SetPosSize( 0, 0, 800, 600, SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT );
103 SvpSalFrame::~SvpSalFrame()
105 if( m_pInstance )
106 m_pInstance->deregisterFrame( this );
108 std::list<SvpSalFrame*> Children = m_aChildren;
109 for( std::list<SvpSalFrame*>::iterator it = Children.begin();
110 it != Children.end(); ++it )
111 (*it)->SetParent( m_pParent );
112 if( m_pParent )
113 m_pParent->m_aChildren.remove( this );
115 if( s_pFocusFrame == this )
117 s_pFocusFrame = NULL;
118 // call directly here, else an event for a destroyed frame would be dispatched
119 CallCallback( SALEVENT_LOSEFOCUS, NULL );
120 // if the handler has not set a new focus frame
121 // pass focus to another frame, preferably a document style window
122 if( s_pFocusFrame == NULL )
124 const std::list< SalFrame* >& rFrames( m_pInstance->getFrames() );
125 for( std::list< SalFrame* >::const_iterator it = rFrames.begin(); it != rFrames.end(); ++it )
127 SvpSalFrame* pFrame = const_cast<SvpSalFrame*>(static_cast<const SvpSalFrame*>(*it));
128 if( pFrame->m_bVisible &&
129 pFrame->m_pParent == NULL &&
130 (pFrame->m_nStyle & (SAL_FRAME_STYLE_MOVEABLE |
131 SAL_FRAME_STYLE_SIZEABLE |
132 SAL_FRAME_STYLE_CLOSEABLE) ) != 0
135 pFrame->GetFocus();
136 break;
143 void SvpSalFrame::GetFocus()
145 if( (m_nStyle & (SAL_FRAME_STYLE_OWNERDRAWDECORATION | SAL_FRAME_STYLE_FLOAT)) == 0 )
147 if( s_pFocusFrame )
148 s_pFocusFrame->LoseFocus();
149 s_pFocusFrame = this;
150 m_pInstance->PostEvent( this, NULL, SALEVENT_GETFOCUS );
154 void SvpSalFrame::LoseFocus()
156 if( s_pFocusFrame == this )
158 m_pInstance->PostEvent( this, NULL, SALEVENT_LOSEFOCUS );
159 s_pFocusFrame = NULL;
163 SalGraphics* SvpSalFrame::GetGraphics()
165 SvpSalGraphics* pGraphics = new SvpSalGraphics();
166 pGraphics->setDevice( m_aFrame );
167 m_aGraphics.push_back( pGraphics );
168 return pGraphics;
171 void SvpSalFrame::ReleaseGraphics( SalGraphics* pGraphics )
173 SvpSalGraphics* pSvpGraphics = dynamic_cast<SvpSalGraphics*>(pGraphics);
174 m_aGraphics.remove( pSvpGraphics );
175 delete pSvpGraphics;
178 sal_Bool SvpSalFrame::PostEvent( void* pData )
180 m_pInstance->PostEvent( this, pData, SALEVENT_USEREVENT );
181 return sal_True;
184 void SvpSalFrame::PostPaint(bool bImmediate) const
186 if( m_bVisible )
188 SalPaintEvent aPEvt(0, 0, maGeometry.nWidth, maGeometry.nHeight);
189 aPEvt.mbImmediateUpdate = bImmediate;
190 CallCallback( SALEVENT_PAINT, &aPEvt );
194 void SvpSalFrame::SetTitle( const rtl::OUString& )
198 void SvpSalFrame::SetIcon( sal_uInt16 )
202 void SvpSalFrame::SetMenu( SalMenu* )
206 void SvpSalFrame::DrawMenuBar()
210 void SvpSalFrame::SetExtendedFrameStyle( SalExtStyle )
214 void SvpSalFrame::Show( sal_Bool bVisible, sal_Bool bNoActivate )
216 if( bVisible && ! m_bVisible )
218 m_bVisible = true;
219 m_pInstance->PostEvent( this, NULL, SALEVENT_RESIZE );
220 if( ! bNoActivate )
221 GetFocus();
223 else if( ! bVisible && m_bVisible )
225 m_bVisible = false;
226 m_pInstance->PostEvent( this, NULL, SALEVENT_RESIZE );
227 LoseFocus();
231 void SvpSalFrame::Enable( sal_Bool )
235 void SvpSalFrame::SetMinClientSize( long nWidth, long nHeight )
237 m_nMinWidth = nWidth;
238 m_nMinHeight = nHeight;
241 void SvpSalFrame::SetMaxClientSize( long nWidth, long nHeight )
243 m_nMaxWidth = nWidth;
244 m_nMaxHeight = nHeight;
247 void SvpSalFrame::SetPosSize( long nX, long nY, long nWidth, long nHeight, sal_uInt16 nFlags )
249 if( (nFlags & SAL_FRAME_POSSIZE_X) != 0 )
250 maGeometry.nX = nX;
251 if( (nFlags & SAL_FRAME_POSSIZE_Y) != 0 )
252 maGeometry.nY = nY;
253 if( (nFlags & SAL_FRAME_POSSIZE_WIDTH) != 0 )
255 maGeometry.nWidth = nWidth;
256 if( m_nMaxWidth > 0 && maGeometry.nWidth > (unsigned int)m_nMaxWidth )
257 maGeometry.nWidth = m_nMaxWidth;
258 if( m_nMinWidth > 0 && maGeometry.nWidth < (unsigned int)m_nMinWidth )
259 maGeometry.nWidth = m_nMinWidth;
261 if( (nFlags & SAL_FRAME_POSSIZE_HEIGHT) != 0 )
263 maGeometry.nHeight = nHeight;
264 if( m_nMaxHeight > 0 && maGeometry.nHeight > (unsigned int)m_nMaxHeight )
265 maGeometry.nHeight = m_nMaxHeight;
266 if( m_nMinHeight > 0 && maGeometry.nHeight < (unsigned int)m_nMinHeight )
267 maGeometry.nHeight = m_nMinHeight;
269 B2IVector aFrameSize( maGeometry.nWidth, maGeometry.nHeight );
270 if( ! m_aFrame.get() || m_aFrame->getSize() != aFrameSize )
272 if( aFrameSize.getX() == 0 )
273 aFrameSize.setX( 1 );
274 if( aFrameSize.getY() == 0 )
275 aFrameSize.setY( 1 );
276 m_aFrame = createBitmapDevice( aFrameSize, m_bTopDown, m_nScanlineFormat );
277 if (m_bDamageTracking)
278 m_aFrame->setDamageTracker(
279 basebmp::IBitmapDeviceDamageTrackerSharedPtr( new DamageTracker( *this ) ) );
280 // update device in existing graphics
281 for( std::list< SvpSalGraphics* >::iterator it = m_aGraphics.begin();
282 it != m_aGraphics.end(); ++it )
283 (*it)->setDevice( m_aFrame );
285 if( m_bVisible )
286 m_pInstance->PostEvent( this, NULL, SALEVENT_RESIZE );
289 void SvpSalFrame::GetClientSize( long& rWidth, long& rHeight )
291 if( m_bVisible )
293 rWidth = maGeometry.nWidth;
294 rHeight = maGeometry.nHeight;
296 else
297 rWidth = rHeight = 0;
300 void SvpSalFrame::GetWorkArea( Rectangle& rRect )
302 rRect = Rectangle( Point( 0, 0 ),
303 Size( VIRTUAL_DESKTOP_WIDTH, VIRTUAL_DESKTOP_HEIGHT ) );
306 SalFrame* SvpSalFrame::GetParent() const
308 return m_pParent;
311 #define _FRAMESTATE_MASK_GEOMETRY \
312 (SAL_FRAMESTATE_MASK_X | SAL_FRAMESTATE_MASK_Y | \
313 SAL_FRAMESTATE_MASK_WIDTH | SAL_FRAMESTATE_MASK_HEIGHT)
315 void SvpSalFrame::SetWindowState( const SalFrameState *pState )
317 if (pState == NULL)
318 return;
320 // Request for position or size change
321 if (pState->mnMask & _FRAMESTATE_MASK_GEOMETRY)
323 long nX = maGeometry.nX;
324 long nY = maGeometry.nY;
325 long nWidth = maGeometry.nWidth;
326 long nHeight = maGeometry.nHeight;
328 // change requested properties
329 if (pState->mnMask & SAL_FRAMESTATE_MASK_X)
330 nX = pState->mnX;
331 if (pState->mnMask & SAL_FRAMESTATE_MASK_Y)
332 nY = pState->mnY;
333 if (pState->mnMask & SAL_FRAMESTATE_MASK_WIDTH)
334 nWidth = pState->mnWidth;
335 if (pState->mnMask & SAL_FRAMESTATE_MASK_HEIGHT)
336 nHeight = pState->mnHeight;
338 SetPosSize( nX, nY, nWidth, nHeight,
339 SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y |
340 SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT );
344 sal_Bool SvpSalFrame::GetWindowState( SalFrameState* pState )
346 pState->mnState = SAL_FRAMESTATE_NORMAL;
347 pState->mnX = maGeometry.nX;
348 pState->mnY = maGeometry.nY;
349 pState->mnWidth = maGeometry.nWidth;
350 pState->mnHeight = maGeometry.nHeight;
351 pState->mnMask = _FRAMESTATE_MASK_GEOMETRY | SAL_FRAMESTATE_MASK_STATE;
353 return sal_True;
356 void SvpSalFrame::ShowFullScreen( sal_Bool, sal_Int32 )
358 SetPosSize( 0, 0, VIRTUAL_DESKTOP_WIDTH, VIRTUAL_DESKTOP_HEIGHT,
359 SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT );
362 void SvpSalFrame::StartPresentation( sal_Bool )
366 void SvpSalFrame::SetAlwaysOnTop( sal_Bool )
370 void SvpSalFrame::ToTop( sal_uInt16 )
372 GetFocus();
375 void SvpSalFrame::SetPointer( PointerStyle )
379 void SvpSalFrame::CaptureMouse( sal_Bool )
383 void SvpSalFrame::SetPointerPos( long, long )
387 void SvpSalFrame::Flush()
391 void SvpSalFrame::Sync()
395 void SvpSalFrame::SetInputContext( SalInputContext* )
399 void SvpSalFrame::EndExtTextInput( sal_uInt16 )
403 rtl::OUString SvpSalFrame::GetKeyName( sal_uInt16 )
405 return rtl::OUString();
408 sal_Bool SvpSalFrame::MapUnicodeToKeyCode( sal_Unicode, LanguageType, KeyCode& )
410 return sal_False;
413 LanguageType SvpSalFrame::GetInputLanguage()
415 return LANGUAGE_DONTKNOW;
418 void SvpSalFrame::UpdateSettings( AllSettings& )
422 const SystemEnvData* SvpSalFrame::GetSystemData() const
424 return &m_aSystemChildData;
427 SalFrame::SalPointerState SvpSalFrame::GetPointerState()
429 SalPointerState aState;
430 aState.mnState = 0;
431 return aState;
434 SalFrame::SalIndicatorState SvpSalFrame::GetIndicatorState()
436 SalIndicatorState aState;
437 aState.mnState = 0;
438 return aState;
441 void SvpSalFrame::SimulateKeyPress( sal_uInt16 /*nKeyCode*/ )
445 void SvpSalFrame::SetParent( SalFrame* pNewParent )
447 if( m_pParent )
448 m_pParent->m_aChildren.remove( this );
449 m_pParent = static_cast<SvpSalFrame*>(pNewParent);
452 bool SvpSalFrame::SetPluginParent( SystemParentData* )
454 return true;
457 void SvpSalFrame::ResetClipRegion()
461 void SvpSalFrame::BeginSetClipRegion( sal_uLong )
465 void SvpSalFrame::UnionClipRegion( long, long, long, long )
469 void SvpSalFrame::EndSetClipRegion()
473 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */