Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / headless / svpframe.cxx
blobe1218d7ab3e6ad0ca1536c888b381fdb3c77a221
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/svpforlokit.hxx>
22 #include <vcl/syswin.hxx>
24 #include "headless/svpframe.hxx"
25 #include "headless/svpinst.hxx"
26 #include "headless/svpgdi.hxx"
28 #include <basebmp/bitmapdevice.hxx>
29 #include <basebmp/scanlineformats.hxx>
30 #include <basegfx/vector/b2ivector.hxx>
32 using namespace basebmp;
33 using namespace basegfx;
35 SvpSalFrame* SvpSalFrame::s_pFocusFrame = NULL;
37 #ifdef IOS
38 #define SvpSalGraphics AquaSalGraphics
39 #endif
41 #ifndef IOS
43 namespace {
44 /// Decouple SalFrame lifetime from damagetracker lifetime
45 struct DamageTracker : public basebmp::IBitmapDeviceDamageTracker
47 virtual ~DamageTracker() {}
48 virtual void damaged( const basegfx::B2IBox& ) const SAL_OVERRIDE {}
52 void SvpSalFrame::enableDamageTracker( bool bOn )
54 if( m_bDamageTracking == bOn )
55 return;
56 if( m_aFrame.get() )
58 if( m_bDamageTracking )
59 m_aFrame->setDamageTracker( basebmp::IBitmapDeviceDamageTrackerSharedPtr() );
60 else
61 m_aFrame->setDamageTracker(
62 basebmp::IBitmapDeviceDamageTrackerSharedPtr( new DamageTracker ) );
64 m_bDamageTracking = bOn;
67 #endif
69 SvpSalFrame::SvpSalFrame( SvpSalInstance* pInstance,
70 SalFrame* pParent,
71 sal_uLong nSalFrameStyle,
72 bool bTopDown,
73 basebmp::Format nScanlineFormat,
74 SystemParentData* ) :
75 m_pInstance( pInstance ),
76 m_pParent( static_cast<SvpSalFrame*>(pParent) ),
77 m_nStyle( nSalFrameStyle ),
78 m_bVisible( false ),
79 m_bTopDown( bTopDown ),
80 #ifndef IOS
81 m_bDamageTracking( false ),
82 #endif
83 m_nScanlineFormat( nScanlineFormat ),
84 m_nMinWidth( 0 ),
85 m_nMinHeight( 0 ),
86 m_nMaxWidth( 0 ),
87 m_nMaxHeight( 0 )
89 // SAL_DEBUG("SvpSalFrame::SvpSalFrame: " << this);
90 // fast and easy cross-platform wiping of the data
91 memset( (void *)&m_aSystemChildData, 0, sizeof( SystemEnvData ) );
92 m_aSystemChildData.nSize = sizeof( SystemEnvData );
93 #ifdef IOS
94 // Nothing
95 #elif defined ANDROID
96 // Nothing
97 #else
98 m_aSystemChildData.pSalFrame = this;
99 m_aSystemChildData.nDepth = 24;
100 #endif
102 if( m_pParent )
103 m_pParent->m_aChildren.push_back( this );
105 if( m_pInstance )
106 m_pInstance->registerFrame( this );
108 SetPosSize( 0, 0, 800, 600, SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT );
111 SvpSalFrame::~SvpSalFrame()
113 if( m_pInstance )
114 m_pInstance->deregisterFrame( this );
116 std::list<SvpSalFrame*> Children = m_aChildren;
117 for( std::list<SvpSalFrame*>::iterator it = Children.begin();
118 it != Children.end(); ++it )
119 (*it)->SetParent( m_pParent );
120 if( m_pParent )
121 m_pParent->m_aChildren.remove( this );
123 if( s_pFocusFrame == this )
125 // SAL_DEBUG("SvpSalFrame::~SvpSalFrame: losing focus: " << this);
126 s_pFocusFrame = NULL;
127 // call directly here, else an event for a destroyed frame would be dispatched
128 CallCallback( SALEVENT_LOSEFOCUS, NULL );
129 // if the handler has not set a new focus frame
130 // pass focus to another frame, preferably a document style window
131 if( s_pFocusFrame == NULL )
133 const std::list< SalFrame* >& rFrames( m_pInstance->getFrames() );
134 for( std::list< SalFrame* >::const_iterator it = rFrames.begin(); it != rFrames.end(); ++it )
136 SvpSalFrame* pFrame = const_cast<SvpSalFrame*>(static_cast<const SvpSalFrame*>(*it));
137 if( pFrame->m_bVisible &&
138 pFrame->m_pParent == NULL &&
139 (pFrame->m_nStyle & (SAL_FRAME_STYLE_MOVEABLE |
140 SAL_FRAME_STYLE_SIZEABLE |
141 SAL_FRAME_STYLE_CLOSEABLE) ) != 0
144 pFrame->GetFocus();
145 break;
152 void SvpSalFrame::GetFocus()
154 if( s_pFocusFrame == this )
155 return;
157 if( (m_nStyle & (SAL_FRAME_STYLE_OWNERDRAWDECORATION | SAL_FRAME_STYLE_FLOAT)) == 0 )
159 if( s_pFocusFrame )
160 s_pFocusFrame->LoseFocus();
161 // SAL_DEBUG("SvpSalFrame::GetFocus(): " << this);
162 s_pFocusFrame = this;
163 m_pInstance->PostEvent( this, NULL, SALEVENT_GETFOCUS );
167 void SvpSalFrame::LoseFocus()
169 if( s_pFocusFrame == this )
171 // SAL_DEBUG("SvpSalFrame::LoseFocus: " << this);
172 m_pInstance->PostEvent( this, NULL, SALEVENT_LOSEFOCUS );
173 s_pFocusFrame = NULL;
177 SalGraphics* SvpSalFrame::AcquireGraphics()
179 SvpSalGraphics* pGraphics = new SvpSalGraphics();
180 #ifndef IOS
181 pGraphics->setDevice( m_aFrame );
182 #endif
183 m_aGraphics.push_back( pGraphics );
184 return pGraphics;
187 void SvpSalFrame::ReleaseGraphics( SalGraphics* pGraphics )
189 SvpSalGraphics* pSvpGraphics = dynamic_cast<SvpSalGraphics*>(pGraphics);
190 m_aGraphics.remove( pSvpGraphics );
191 delete pSvpGraphics;
194 bool SvpSalFrame::PostEvent( void* pData )
196 m_pInstance->PostEvent( this, pData, SALEVENT_USEREVENT );
197 return true;
200 void SvpSalFrame::PostPaint(bool bImmediate) const
202 if( m_bVisible )
204 SalPaintEvent aPEvt(0, 0, maGeometry.nWidth, maGeometry.nHeight);
205 aPEvt.mbImmediateUpdate = bImmediate;
206 CallCallback( SALEVENT_PAINT, &aPEvt );
210 void SvpSalFrame::SetTitle( const OUString& )
214 void SvpSalFrame::SetIcon( sal_uInt16 )
218 void SvpSalFrame::SetMenu( SalMenu* )
222 void SvpSalFrame::DrawMenuBar()
226 void SvpSalFrame::SetExtendedFrameStyle( SalExtStyle )
230 void SvpSalFrame::Show( bool bVisible, bool bNoActivate )
232 if( bVisible && ! m_bVisible )
234 // SAL_DEBUG("SvpSalFrame::Show: showing: " << this);
235 m_bVisible = true;
236 m_pInstance->PostEvent( this, NULL, SALEVENT_RESIZE );
237 if( ! bNoActivate )
238 GetFocus();
240 else if( ! bVisible && m_bVisible )
242 // SAL_DEBUG("SvpSalFrame::Show: hiding: " << this);
243 m_bVisible = false;
244 m_pInstance->PostEvent( this, NULL, SALEVENT_RESIZE );
245 LoseFocus();
247 else
249 // SAL_DEBUG("SvpSalFrame::Show: nothihg: " << this);
253 void SvpSalFrame::SetMinClientSize( long nWidth, long nHeight )
255 m_nMinWidth = nWidth;
256 m_nMinHeight = nHeight;
259 void SvpSalFrame::SetMaxClientSize( long nWidth, long nHeight )
261 m_nMaxWidth = nWidth;
262 m_nMaxHeight = nHeight;
265 void SvpSalFrame::SetPosSize( long nX, long nY, long nWidth, long nHeight, sal_uInt16 nFlags )
267 if( (nFlags & SAL_FRAME_POSSIZE_X) != 0 )
268 maGeometry.nX = nX;
269 if( (nFlags & SAL_FRAME_POSSIZE_Y) != 0 )
270 maGeometry.nY = nY;
271 if( (nFlags & SAL_FRAME_POSSIZE_WIDTH) != 0 )
273 maGeometry.nWidth = nWidth;
274 if( m_nMaxWidth > 0 && maGeometry.nWidth > (unsigned int)m_nMaxWidth )
275 maGeometry.nWidth = m_nMaxWidth;
276 if( m_nMinWidth > 0 && maGeometry.nWidth < (unsigned int)m_nMinWidth )
277 maGeometry.nWidth = m_nMinWidth;
279 if( (nFlags & SAL_FRAME_POSSIZE_HEIGHT) != 0 )
281 maGeometry.nHeight = nHeight;
282 if( m_nMaxHeight > 0 && maGeometry.nHeight > (unsigned int)m_nMaxHeight )
283 maGeometry.nHeight = m_nMaxHeight;
284 if( m_nMinHeight > 0 && maGeometry.nHeight < (unsigned int)m_nMinHeight )
285 maGeometry.nHeight = m_nMinHeight;
287 #ifndef IOS
288 B2IVector aFrameSize( maGeometry.nWidth, maGeometry.nHeight );
289 if( ! m_aFrame.get() || m_aFrame->getSize() != aFrameSize )
291 if( aFrameSize.getX() == 0 )
292 aFrameSize.setX( 1 );
293 if( aFrameSize.getY() == 0 )
294 aFrameSize.setY( 1 );
295 sal_Int32 nStride = basebmp::getBitmapDeviceStrideForWidth(m_nScanlineFormat, aFrameSize.getX());
296 m_aFrame = createBitmapDevice( aFrameSize, m_bTopDown, m_nScanlineFormat, nStride );
297 if (m_bDamageTracking)
298 m_aFrame->setDamageTracker(
299 basebmp::IBitmapDeviceDamageTrackerSharedPtr( new DamageTracker ) );
300 // update device in existing graphics
301 for( std::list< SvpSalGraphics* >::iterator it = m_aGraphics.begin();
302 it != m_aGraphics.end(); ++it )
304 (*it)->setDevice( m_aFrame );
307 if( m_bVisible )
308 m_pInstance->PostEvent( this, NULL, SALEVENT_RESIZE );
309 #endif
312 void SvpSalFrame::GetClientSize( long& rWidth, long& rHeight )
314 if( m_bVisible )
316 rWidth = maGeometry.nWidth;
317 rHeight = maGeometry.nHeight;
319 else
320 rWidth = rHeight = 0;
323 void SvpSalFrame::GetWorkArea( Rectangle& rRect )
325 rRect = Rectangle( Point( 0, 0 ),
326 Size( VIRTUAL_DESKTOP_WIDTH, VIRTUAL_DESKTOP_HEIGHT ) );
329 SalFrame* SvpSalFrame::GetParent() const
331 return m_pParent;
334 #define _FRAMESTATE_MASK_GEOMETRY \
335 (WINDOWSTATE_MASK_X | WINDOWSTATE_MASK_Y | \
336 WINDOWSTATE_MASK_WIDTH | WINDOWSTATE_MASK_HEIGHT)
338 void SvpSalFrame::SetWindowState( const SalFrameState *pState )
340 if (pState == NULL)
341 return;
343 // Request for position or size change
344 if (pState->mnMask & _FRAMESTATE_MASK_GEOMETRY)
346 long nX = maGeometry.nX;
347 long nY = maGeometry.nY;
348 long nWidth = maGeometry.nWidth;
349 long nHeight = maGeometry.nHeight;
351 // change requested properties
352 if (pState->mnMask & WINDOWSTATE_MASK_X)
353 nX = pState->mnX;
354 if (pState->mnMask & WINDOWSTATE_MASK_Y)
355 nY = pState->mnY;
356 if (pState->mnMask & WINDOWSTATE_MASK_WIDTH)
357 nWidth = pState->mnWidth;
358 if (pState->mnMask & WINDOWSTATE_MASK_HEIGHT)
359 nHeight = pState->mnHeight;
361 SetPosSize( nX, nY, nWidth, nHeight,
362 SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y |
363 SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT );
367 bool SvpSalFrame::GetWindowState( SalFrameState* pState )
369 pState->mnState = WINDOWSTATE_STATE_NORMAL;
370 pState->mnX = maGeometry.nX;
371 pState->mnY = maGeometry.nY;
372 pState->mnWidth = maGeometry.nWidth;
373 pState->mnHeight = maGeometry.nHeight;
374 pState->mnMask = _FRAMESTATE_MASK_GEOMETRY | WINDOWSTATE_MASK_STATE;
376 return true;
379 void SvpSalFrame::ShowFullScreen( bool, sal_Int32 )
381 SetPosSize( 0, 0, VIRTUAL_DESKTOP_WIDTH, VIRTUAL_DESKTOP_HEIGHT,
382 SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT );
385 void SvpSalFrame::StartPresentation( bool )
389 void SvpSalFrame::SetAlwaysOnTop( bool )
393 void SvpSalFrame::ToTop( sal_uInt16 )
395 GetFocus();
398 void SvpSalFrame::SetPointer( PointerStyle )
402 void SvpSalFrame::CaptureMouse( bool )
406 void SvpSalFrame::SetPointerPos( long, long )
410 void SvpSalFrame::Flush()
414 void SvpSalFrame::Sync()
418 void SvpSalFrame::SetInputContext( SalInputContext* )
422 void SvpSalFrame::EndExtTextInput( sal_uInt16 )
426 OUString SvpSalFrame::GetKeyName( sal_uInt16 )
428 return OUString();
431 bool SvpSalFrame::MapUnicodeToKeyCode( sal_Unicode, LanguageType, vcl::KeyCode& )
433 return false;
436 LanguageType SvpSalFrame::GetInputLanguage()
438 return LANGUAGE_DONTKNOW;
441 void SvpSalFrame::UpdateSettings( AllSettings& )
445 void SvpSalFrame::Beep()
449 const SystemEnvData* SvpSalFrame::GetSystemData() const
451 return &m_aSystemChildData;
454 SalFrame::SalPointerState SvpSalFrame::GetPointerState()
456 SalPointerState aState;
457 aState.mnState = 0;
458 return aState;
461 KeyIndicatorState SvpSalFrame::GetIndicatorState()
463 return KeyIndicatorState::NONE;
466 void SvpSalFrame::SimulateKeyPress( sal_uInt16 /*nKeyCode*/ )
470 void SvpSalFrame::SetParent( SalFrame* pNewParent )
472 if( m_pParent )
473 m_pParent->m_aChildren.remove( this );
474 m_pParent = static_cast<SvpSalFrame*>(pNewParent);
477 bool SvpSalFrame::SetPluginParent( SystemParentData* )
479 return true;
482 void SvpSalFrame::ResetClipRegion()
486 void SvpSalFrame::BeginSetClipRegion( sal_uLong )
490 void SvpSalFrame::UnionClipRegion( long, long, long, long )
494 void SvpSalFrame::EndSetClipRegion()
498 SalFrame* GetSvpFocusFrameForLibreOfficeKit()
500 return SvpSalFrame::GetFocusFrame();
503 vcl::Window* GetSalFrameWindowForLibreOfficeKit(SalFrame *pSF)
505 return pSF->GetWindow();
508 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */