fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / vcl / headless / svpframe.cxx
blob18c84f3ef9e5f7274e78d8a70e0e8575699d593f
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 "vcl/syswin.hxx"
22 #include "headless/svpframe.hxx"
23 #include "headless/svpinst.hxx"
24 #include "headless/svpgdi.hxx"
26 #include <basebmp/bitmapdevice.hxx>
27 #include <basebmp/scanlineformats.hxx>
28 #include <basegfx/vector/b2ivector.hxx>
30 using namespace basebmp;
31 using namespace basegfx;
33 SvpSalFrame* SvpSalFrame::s_pFocusFrame = NULL;
35 namespace {
36 /// Decouple SalFrame lifetime from damagetracker lifetime
37 struct DamageTracker : public basebmp::IBitmapDeviceDamageTracker
39 DamageTracker( SvpSalFrame& rFrame ) : m_rFrame( rFrame ) {}
40 virtual ~DamageTracker() {}
41 virtual void damaged( const basegfx::B2IBox& rDamageRect ) const
43 m_rFrame.damaged( rDamageRect );
45 SvpSalFrame& m_rFrame;
49 void SvpSalFrame::enableDamageTracker( bool bOn )
51 if( m_bDamageTracking == bOn )
52 return;
53 if( m_aFrame.get() )
55 if( m_bDamageTracking )
56 m_aFrame->setDamageTracker( basebmp::IBitmapDeviceDamageTrackerSharedPtr() );
57 else
58 m_aFrame->setDamageTracker(
59 basebmp::IBitmapDeviceDamageTrackerSharedPtr( new DamageTracker( *this ) ) );
61 m_bDamageTracking = bOn;
64 SvpSalFrame::SvpSalFrame( SvpSalInstance* pInstance,
65 SalFrame* pParent,
66 sal_uLong nSalFrameStyle,
67 bool bTopDown,
68 sal_Int32 nScanlineFormat,
69 SystemParentData* ) :
70 m_pInstance( pInstance ),
71 m_pParent( static_cast<SvpSalFrame*>(pParent) ),
72 m_nStyle( nSalFrameStyle ),
73 m_bVisible( false ),
74 m_bDamageTracking( false ),
75 m_bTopDown( bTopDown ),
76 m_nScanlineFormat( nScanlineFormat ),
77 m_nMinWidth( 0 ),
78 m_nMinHeight( 0 ),
79 m_nMaxWidth( 0 ),
80 m_nMaxHeight( 0 )
82 // fast and easy cross-platform wiping of the data
83 memset( (void *)&m_aSystemChildData, 0, sizeof( SystemChildData ) );
84 m_aSystemChildData.nSize = sizeof( SystemChildData );
85 #ifdef IOS
86 // Nothing
87 #elif defined ANDROID
88 // Nothing
89 #else
90 m_aSystemChildData.pSalFrame = this;
91 m_aSystemChildData.nDepth = 24;
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 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 (WINDOWSTATE_MASK_X | WINDOWSTATE_MASK_Y | \
313 WINDOWSTATE_MASK_WIDTH | WINDOWSTATE_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 & WINDOWSTATE_MASK_X)
330 nX = pState->mnX;
331 if (pState->mnMask & WINDOWSTATE_MASK_Y)
332 nY = pState->mnY;
333 if (pState->mnMask & WINDOWSTATE_MASK_WIDTH)
334 nWidth = pState->mnWidth;
335 if (pState->mnMask & WINDOWSTATE_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 = WINDOWSTATE_STATE_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 | WINDOWSTATE_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 OUString SvpSalFrame::GetKeyName( sal_uInt16 )
405 return 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 void SvpSalFrame::Beep()
426 const SystemEnvData* SvpSalFrame::GetSystemData() const
428 return &m_aSystemChildData;
431 SalFrame::SalPointerState SvpSalFrame::GetPointerState()
433 SalPointerState aState;
434 aState.mnState = 0;
435 return aState;
438 SalFrame::SalIndicatorState SvpSalFrame::GetIndicatorState()
440 SalIndicatorState aState;
441 aState.mnState = 0;
442 return aState;
445 void SvpSalFrame::SimulateKeyPress( sal_uInt16 /*nKeyCode*/ )
449 void SvpSalFrame::SetParent( SalFrame* pNewParent )
451 if( m_pParent )
452 m_pParent->m_aChildren.remove( this );
453 m_pParent = static_cast<SvpSalFrame*>(pNewParent);
456 bool SvpSalFrame::SetPluginParent( SystemParentData* )
458 return true;
461 void SvpSalFrame::ResetClipRegion()
465 void SvpSalFrame::BeginSetClipRegion( sal_uLong )
469 void SvpSalFrame::UnionClipRegion( long, long, long, long )
473 void SvpSalFrame::EndSetClipRegion()
477 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */