1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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
;
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
)
55 if( m_bDamageTracking
)
56 m_aFrame
->setDamageTracker( basebmp::IBitmapDeviceDamageTrackerSharedPtr() );
58 m_aFrame
->setDamageTracker(
59 basebmp::IBitmapDeviceDamageTrackerSharedPtr( new DamageTracker( *this ) ) );
61 m_bDamageTracking
= bOn
;
64 SvpSalFrame::SvpSalFrame( SvpSalInstance
* pInstance
,
66 sal_uLong nSalFrameStyle
,
68 basebmp::Format nScanlineFormat
,
70 m_pInstance( pInstance
),
71 m_pParent( static_cast<SvpSalFrame
*>(pParent
) ),
72 m_nStyle( nSalFrameStyle
),
74 m_bDamageTracking( false ),
75 m_bTopDown( bTopDown
),
76 m_nScanlineFormat( nScanlineFormat
),
82 // SAL_DEBUG("SvpSalFrame::SvpSalFrame: " << this);
83 // fast and easy cross-platform wiping of the data
84 memset( (void *)&m_aSystemChildData
, 0, sizeof( SystemEnvData
) );
85 m_aSystemChildData
.nSize
= sizeof( SystemEnvData
);
91 m_aSystemChildData
.pSalFrame
= this;
92 m_aSystemChildData
.nDepth
= 24;
96 m_pParent
->m_aChildren
.push_back( this );
99 m_pInstance
->registerFrame( this );
101 SetPosSize( 0, 0, 800, 600, SAL_FRAME_POSSIZE_WIDTH
| SAL_FRAME_POSSIZE_HEIGHT
);
104 SvpSalFrame::~SvpSalFrame()
107 m_pInstance
->deregisterFrame( this );
109 std::list
<SvpSalFrame
*> Children
= m_aChildren
;
110 for( std::list
<SvpSalFrame
*>::iterator it
= Children
.begin();
111 it
!= Children
.end(); ++it
)
112 (*it
)->SetParent( m_pParent
);
114 m_pParent
->m_aChildren
.remove( this );
116 if( s_pFocusFrame
== this )
118 // SAL_DEBUG("SvpSalFrame::~SvpSalFrame: losing focus: " << this);
119 s_pFocusFrame
= NULL
;
120 // call directly here, else an event for a destroyed frame would be dispatched
121 CallCallback( SALEVENT_LOSEFOCUS
, NULL
);
122 // if the handler has not set a new focus frame
123 // pass focus to another frame, preferably a document style window
124 if( s_pFocusFrame
== NULL
)
126 const std::list
< SalFrame
* >& rFrames( m_pInstance
->getFrames() );
127 for( std::list
< SalFrame
* >::const_iterator it
= rFrames
.begin(); it
!= rFrames
.end(); ++it
)
129 SvpSalFrame
* pFrame
= const_cast<SvpSalFrame
*>(static_cast<const SvpSalFrame
*>(*it
));
130 if( pFrame
->m_bVisible
&&
131 pFrame
->m_pParent
== NULL
&&
132 (pFrame
->m_nStyle
& (SAL_FRAME_STYLE_MOVEABLE
|
133 SAL_FRAME_STYLE_SIZEABLE
|
134 SAL_FRAME_STYLE_CLOSEABLE
) ) != 0
145 void SvpSalFrame::GetFocus()
147 if( s_pFocusFrame
== this )
150 if( (m_nStyle
& (SAL_FRAME_STYLE_OWNERDRAWDECORATION
| SAL_FRAME_STYLE_FLOAT
)) == 0 )
153 s_pFocusFrame
->LoseFocus();
154 // SAL_DEBUG("SvpSalFrame::GetFocus(): " << this);
155 s_pFocusFrame
= this;
156 m_pInstance
->PostEvent( this, NULL
, SALEVENT_GETFOCUS
);
160 void SvpSalFrame::LoseFocus()
162 if( s_pFocusFrame
== this )
164 // SAL_DEBUG("SvpSalFrame::LoseFocus: " << this);
165 m_pInstance
->PostEvent( this, NULL
, SALEVENT_LOSEFOCUS
);
166 s_pFocusFrame
= NULL
;
170 SalGraphics
* SvpSalFrame::GetGraphics()
172 SvpSalGraphics
* pGraphics
= new SvpSalGraphics();
173 pGraphics
->setDevice( m_aFrame
);
174 m_aGraphics
.push_back( pGraphics
);
178 void SvpSalFrame::ReleaseGraphics( SalGraphics
* pGraphics
)
180 SvpSalGraphics
* pSvpGraphics
= dynamic_cast<SvpSalGraphics
*>(pGraphics
);
181 m_aGraphics
.remove( pSvpGraphics
);
185 sal_Bool
SvpSalFrame::PostEvent( void* pData
)
187 m_pInstance
->PostEvent( this, pData
, SALEVENT_USEREVENT
);
191 void SvpSalFrame::PostPaint(bool bImmediate
) const
195 SalPaintEvent
aPEvt(0, 0, maGeometry
.nWidth
, maGeometry
.nHeight
);
196 aPEvt
.mbImmediateUpdate
= bImmediate
;
197 CallCallback( SALEVENT_PAINT
, &aPEvt
);
201 void SvpSalFrame::SetTitle( const OUString
& )
205 void SvpSalFrame::SetIcon( sal_uInt16
)
209 void SvpSalFrame::SetMenu( SalMenu
* )
213 void SvpSalFrame::DrawMenuBar()
217 void SvpSalFrame::SetExtendedFrameStyle( SalExtStyle
)
221 void SvpSalFrame::Show( sal_Bool bVisible
, sal_Bool bNoActivate
)
223 if( bVisible
&& ! m_bVisible
)
225 // SAL_DEBUG("SvpSalFrame::Show: showing: " << this);
227 m_pInstance
->PostEvent( this, NULL
, SALEVENT_RESIZE
);
231 else if( ! bVisible
&& m_bVisible
)
233 // SAL_DEBUG("SvpSalFrame::Show: hiding: " << this);
235 m_pInstance
->PostEvent( this, NULL
, SALEVENT_RESIZE
);
240 // SAL_DEBUG("SvpSalFrame::Show: nothihg: " << this);
244 void SvpSalFrame::Enable( sal_Bool
)
248 void SvpSalFrame::SetMinClientSize( long nWidth
, long nHeight
)
250 m_nMinWidth
= nWidth
;
251 m_nMinHeight
= nHeight
;
254 void SvpSalFrame::SetMaxClientSize( long nWidth
, long nHeight
)
256 m_nMaxWidth
= nWidth
;
257 m_nMaxHeight
= nHeight
;
260 void SvpSalFrame::SetPosSize( long nX
, long nY
, long nWidth
, long nHeight
, sal_uInt16 nFlags
)
262 if( (nFlags
& SAL_FRAME_POSSIZE_X
) != 0 )
264 if( (nFlags
& SAL_FRAME_POSSIZE_Y
) != 0 )
266 if( (nFlags
& SAL_FRAME_POSSIZE_WIDTH
) != 0 )
268 maGeometry
.nWidth
= nWidth
;
269 if( m_nMaxWidth
> 0 && maGeometry
.nWidth
> (unsigned int)m_nMaxWidth
)
270 maGeometry
.nWidth
= m_nMaxWidth
;
271 if( m_nMinWidth
> 0 && maGeometry
.nWidth
< (unsigned int)m_nMinWidth
)
272 maGeometry
.nWidth
= m_nMinWidth
;
274 if( (nFlags
& SAL_FRAME_POSSIZE_HEIGHT
) != 0 )
276 maGeometry
.nHeight
= nHeight
;
277 if( m_nMaxHeight
> 0 && maGeometry
.nHeight
> (unsigned int)m_nMaxHeight
)
278 maGeometry
.nHeight
= m_nMaxHeight
;
279 if( m_nMinHeight
> 0 && maGeometry
.nHeight
< (unsigned int)m_nMinHeight
)
280 maGeometry
.nHeight
= m_nMinHeight
;
282 B2IVector
aFrameSize( maGeometry
.nWidth
, maGeometry
.nHeight
);
283 if( ! m_aFrame
.get() || m_aFrame
->getSize() != aFrameSize
)
285 if( aFrameSize
.getX() == 0 )
286 aFrameSize
.setX( 1 );
287 if( aFrameSize
.getY() == 0 )
288 aFrameSize
.setY( 1 );
289 m_aFrame
= createBitmapDevice( aFrameSize
, m_bTopDown
, m_nScanlineFormat
);
290 if (m_bDamageTracking
)
291 m_aFrame
->setDamageTracker(
292 basebmp::IBitmapDeviceDamageTrackerSharedPtr( new DamageTracker( *this ) ) );
293 // update device in existing graphics
294 for( std::list
< SvpSalGraphics
* >::iterator it
= m_aGraphics
.begin();
295 it
!= m_aGraphics
.end(); ++it
)
296 (*it
)->setDevice( m_aFrame
);
299 m_pInstance
->PostEvent( this, NULL
, SALEVENT_RESIZE
);
302 void SvpSalFrame::GetClientSize( long& rWidth
, long& rHeight
)
306 rWidth
= maGeometry
.nWidth
;
307 rHeight
= maGeometry
.nHeight
;
310 rWidth
= rHeight
= 0;
313 void SvpSalFrame::GetWorkArea( Rectangle
& rRect
)
315 rRect
= Rectangle( Point( 0, 0 ),
316 Size( VIRTUAL_DESKTOP_WIDTH
, VIRTUAL_DESKTOP_HEIGHT
) );
319 SalFrame
* SvpSalFrame::GetParent() const
324 #define _FRAMESTATE_MASK_GEOMETRY \
325 (WINDOWSTATE_MASK_X | WINDOWSTATE_MASK_Y | \
326 WINDOWSTATE_MASK_WIDTH | WINDOWSTATE_MASK_HEIGHT)
328 void SvpSalFrame::SetWindowState( const SalFrameState
*pState
)
333 // Request for position or size change
334 if (pState
->mnMask
& _FRAMESTATE_MASK_GEOMETRY
)
336 long nX
= maGeometry
.nX
;
337 long nY
= maGeometry
.nY
;
338 long nWidth
= maGeometry
.nWidth
;
339 long nHeight
= maGeometry
.nHeight
;
341 // change requested properties
342 if (pState
->mnMask
& WINDOWSTATE_MASK_X
)
344 if (pState
->mnMask
& WINDOWSTATE_MASK_Y
)
346 if (pState
->mnMask
& WINDOWSTATE_MASK_WIDTH
)
347 nWidth
= pState
->mnWidth
;
348 if (pState
->mnMask
& WINDOWSTATE_MASK_HEIGHT
)
349 nHeight
= pState
->mnHeight
;
351 SetPosSize( nX
, nY
, nWidth
, nHeight
,
352 SAL_FRAME_POSSIZE_X
| SAL_FRAME_POSSIZE_Y
|
353 SAL_FRAME_POSSIZE_WIDTH
| SAL_FRAME_POSSIZE_HEIGHT
);
357 sal_Bool
SvpSalFrame::GetWindowState( SalFrameState
* pState
)
359 pState
->mnState
= WINDOWSTATE_STATE_NORMAL
;
360 pState
->mnX
= maGeometry
.nX
;
361 pState
->mnY
= maGeometry
.nY
;
362 pState
->mnWidth
= maGeometry
.nWidth
;
363 pState
->mnHeight
= maGeometry
.nHeight
;
364 pState
->mnMask
= _FRAMESTATE_MASK_GEOMETRY
| WINDOWSTATE_MASK_STATE
;
369 void SvpSalFrame::ShowFullScreen( sal_Bool
, sal_Int32
)
371 SetPosSize( 0, 0, VIRTUAL_DESKTOP_WIDTH
, VIRTUAL_DESKTOP_HEIGHT
,
372 SAL_FRAME_POSSIZE_WIDTH
| SAL_FRAME_POSSIZE_HEIGHT
);
375 void SvpSalFrame::StartPresentation( sal_Bool
)
379 void SvpSalFrame::SetAlwaysOnTop( sal_Bool
)
383 void SvpSalFrame::ToTop( sal_uInt16
)
388 void SvpSalFrame::SetPointer( PointerStyle
)
392 void SvpSalFrame::CaptureMouse( sal_Bool
)
396 void SvpSalFrame::SetPointerPos( long, long )
400 void SvpSalFrame::Flush()
404 void SvpSalFrame::Sync()
408 void SvpSalFrame::SetInputContext( SalInputContext
* )
412 void SvpSalFrame::EndExtTextInput( sal_uInt16
)
416 OUString
SvpSalFrame::GetKeyName( sal_uInt16
)
421 sal_Bool
SvpSalFrame::MapUnicodeToKeyCode( sal_Unicode
, LanguageType
, KeyCode
& )
426 LanguageType
SvpSalFrame::GetInputLanguage()
428 return LANGUAGE_DONTKNOW
;
431 void SvpSalFrame::UpdateSettings( AllSettings
& )
435 void SvpSalFrame::Beep()
439 const SystemEnvData
* SvpSalFrame::GetSystemData() const
441 return &m_aSystemChildData
;
444 SalFrame::SalPointerState
SvpSalFrame::GetPointerState()
446 SalPointerState aState
;
451 SalFrame::SalIndicatorState
SvpSalFrame::GetIndicatorState()
453 SalIndicatorState aState
;
458 void SvpSalFrame::SimulateKeyPress( sal_uInt16
/*nKeyCode*/ )
462 void SvpSalFrame::SetParent( SalFrame
* pNewParent
)
465 m_pParent
->m_aChildren
.remove( this );
466 m_pParent
= static_cast<SvpSalFrame
*>(pNewParent
);
469 bool SvpSalFrame::SetPluginParent( SystemParentData
* )
474 void SvpSalFrame::ResetClipRegion()
478 void SvpSalFrame::BeginSetClipRegion( sal_uLong
)
482 void SvpSalFrame::UnionClipRegion( long, long, long, long )
486 void SvpSalFrame::EndSetClipRegion()
490 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */