Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <string.h>
30 : : #include "headless/svpframe.hxx"
31 : : #include "headless/svpinst.hxx"
32 : : #include "headless/svpgdi.hxx"
33 : :
34 : : #include <basebmp/bitmapdevice.hxx>
35 : : #include <basebmp/scanlineformats.hxx>
36 : : #include <basegfx/vector/b2ivector.hxx>
37 : :
38 : : using namespace basebmp;
39 : : using namespace basegfx;
40 : :
41 : : SvpSalFrame* SvpSalFrame::s_pFocusFrame = NULL;
42 : :
43 : : namespace {
44 : : /// Decouple SalFrame lifetime from damagetracker lifetime
45 : : struct DamageTracker : public basebmp::IBitmapDeviceDamageTracker
46 : : {
47 : 0 : DamageTracker( SvpSalFrame& rFrame ) : m_rFrame( rFrame ) {}
48 [ # # ]: 0 : virtual ~DamageTracker() {}
49 : 0 : virtual void damaged( const basegfx::B2IBox& rDamageRect ) const
50 : : {
51 : 0 : m_rFrame.damaged( rDamageRect );
52 : 0 : }
53 : : SvpSalFrame& m_rFrame;
54 : : };
55 : : }
56 : :
57 : 0 : void SvpSalFrame::enableDamageTracker( bool bOn )
58 : : {
59 [ # # ]: 0 : if( m_bDamageTracking == bOn )
60 : 0 : return;
61 [ # # ]: 0 : if( m_aFrame.get() )
62 : : {
63 [ # # ]: 0 : if( m_bDamageTracking )
64 [ # # ]: 0 : m_aFrame->setDamageTracker( basebmp::IBitmapDeviceDamageTrackerSharedPtr() );
65 : : else
66 : : m_aFrame->setDamageTracker(
67 [ # # ]: 0 : basebmp::IBitmapDeviceDamageTrackerSharedPtr( new DamageTracker( *this ) ) );
68 : : }
69 : 0 : m_bDamageTracking = bOn;
70 : : }
71 : :
72 : 5988 : SvpSalFrame::SvpSalFrame( SvpSalInstance* pInstance,
73 : : SalFrame* pParent,
74 : : sal_uLong nSalFrameStyle,
75 : : bool bTopDown,
76 : : sal_Int32 nScanlineFormat,
77 : : SystemParentData* ) :
78 : : m_pInstance( pInstance ),
79 : : m_pParent( static_cast<SvpSalFrame*>(pParent) ),
80 : : m_nStyle( nSalFrameStyle ),
81 : : m_bVisible( false ),
82 : : m_bDamageTracking( false ),
83 : : m_bTopDown( bTopDown ),
84 : : m_nScanlineFormat( nScanlineFormat ),
85 : : m_nMinWidth( 0 ),
86 : : m_nMinHeight( 0 ),
87 : : m_nMaxWidth( 0 ),
88 [ + - ][ + - ]: 5988 : m_nMaxHeight( 0 )
[ + - ][ + - ]
89 : : {
90 : : // fast and easy cross-platform wiping of the data
91 : 5988 : memset( (void *)&m_aSystemChildData, 0, sizeof( SystemChildData ) );
92 : 5988 : m_aSystemChildData.nSize = sizeof( SystemChildData );
93 : : #if defined( UNX ) // FIXME: prolly redundant
94 : 5988 : m_aSystemChildData.pSalFrame = this;
95 : : #if defined(ANDROID) || defined(IOS)
96 : : // We want 32-bit RGBA bitmaps
97 : : m_aSystemChildData.nDepth = 32;
98 : : #else
99 : 5988 : m_aSystemChildData.nDepth = 24;
100 : : #endif
101 : : #endif
102 : :
103 [ + + ]: 5988 : if( m_pParent )
104 [ + - ]: 3858 : m_pParent->m_aChildren.push_back( this );
105 : :
106 [ + - ]: 5988 : if( m_pInstance )
107 [ + - ]: 5988 : m_pInstance->registerFrame( this );
108 : :
109 [ + - ]: 5988 : SetPosSize( 0, 0, 800, 600, SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT );
110 : 5988 : }
111 : :
112 [ + - ][ + - ]: 5802 : SvpSalFrame::~SvpSalFrame()
113 : : {
114 [ + - ]: 5802 : if( m_pInstance )
115 [ + - ]: 5802 : m_pInstance->deregisterFrame( this );
116 : :
117 [ + - ]: 5802 : std::list<SvpSalFrame*> Children = m_aChildren;
118 [ - + ]: 11604 : for( std::list<SvpSalFrame*>::iterator it = Children.begin();
119 : 5802 : it != Children.end(); ++it )
120 [ # # ]: 0 : (*it)->SetParent( m_pParent );
121 [ + + ]: 5802 : if( m_pParent )
122 [ + - ]: 3854 : m_pParent->m_aChildren.remove( this );
123 : :
124 [ + + ]: 5802 : if( s_pFocusFrame == this )
125 : : {
126 : 42 : s_pFocusFrame = NULL;
127 : : // call directly here, else an event for a destroyed frame would be dispatched
128 [ + - ]: 42 : 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 [ + - ]: 42 : if( s_pFocusFrame == NULL )
132 : : {
133 : 42 : const std::list< SalFrame* >& rFrames( m_pInstance->getFrames() );
134 [ + - ][ + - ]: 120 : for( std::list< SalFrame* >::const_iterator it = rFrames.begin(); it != rFrames.end(); ++it )
[ + + ]
135 : : {
136 [ + - ]: 78 : SvpSalFrame* pFrame = const_cast<SvpSalFrame*>(static_cast<const SvpSalFrame*>(*it));
137 [ + + ][ + - ]: 78 : 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
142 : : )
143 : : {
144 [ + - ]: 36 : pFrame->GetFocus();
145 : 36 : break;
146 : : }
147 : : }
148 : : }
149 : 5802 : }
150 [ - + ]: 11604 : }
151 : :
152 : 5415 : void SvpSalFrame::GetFocus()
153 : : {
154 [ + - ]: 5415 : if( (m_nStyle & (SAL_FRAME_STYLE_OWNERDRAWDECORATION | SAL_FRAME_STYLE_FLOAT)) == 0 )
155 : : {
156 [ + + ]: 5415 : if( s_pFocusFrame )
157 : 3766 : s_pFocusFrame->LoseFocus();
158 : 5415 : s_pFocusFrame = this;
159 : 5415 : m_pInstance->PostEvent( this, NULL, SALEVENT_GETFOCUS );
160 : : }
161 : 5415 : }
162 : :
163 : 5500 : void SvpSalFrame::LoseFocus()
164 : : {
165 [ + + ]: 5500 : if( s_pFocusFrame == this )
166 : : {
167 : 5369 : m_pInstance->PostEvent( this, NULL, SALEVENT_LOSEFOCUS );
168 : 5369 : s_pFocusFrame = NULL;
169 : : }
170 : 5500 : }
171 : :
172 : 131808 : SalGraphics* SvpSalFrame::GetGraphics()
173 : : {
174 [ + - ][ + - ]: 131808 : SvpSalGraphics* pGraphics = new SvpSalGraphics();
175 [ + - ]: 131808 : pGraphics->setDevice( m_aFrame );
176 [ + - ]: 131808 : m_aGraphics.push_back( pGraphics );
177 : 131808 : return pGraphics;
178 : : }
179 : :
180 : 128497 : void SvpSalFrame::ReleaseGraphics( SalGraphics* pGraphics )
181 : : {
182 [ - + ]: 128497 : SvpSalGraphics* pSvpGraphics = dynamic_cast<SvpSalGraphics*>(pGraphics);
183 [ + - ]: 128497 : m_aGraphics.remove( pSvpGraphics );
184 [ + - ][ + - ]: 128497 : delete pSvpGraphics;
185 : 128497 : }
186 : :
187 : 27256 : sal_Bool SvpSalFrame::PostEvent( void* pData )
188 : : {
189 : 27256 : m_pInstance->PostEvent( this, pData, SALEVENT_USEREVENT );
190 : 27256 : return sal_True;
191 : : }
192 : :
193 : 1695 : void SvpSalFrame::PostPaint(bool bImmediate) const
194 : : {
195 [ + + ]: 1695 : if( m_bVisible )
196 : : {
197 : 1618 : SalPaintEvent aPEvt(0, 0, maGeometry.nWidth, maGeometry.nHeight);
198 : 1618 : aPEvt.mbImmediateUpdate = bImmediate;
199 [ + - ]: 1618 : CallCallback( SALEVENT_PAINT, &aPEvt );
200 : : }
201 : 1695 : }
202 : :
203 : 5434 : void SvpSalFrame::SetTitle( const rtl::OUString& )
204 : : {
205 : 5434 : }
206 : :
207 : 1777 : void SvpSalFrame::SetIcon( sal_uInt16 )
208 : : {
209 : 1777 : }
210 : :
211 : 0 : void SvpSalFrame::SetMenu( SalMenu* )
212 : : {
213 : 0 : }
214 : :
215 : 0 : void SvpSalFrame::DrawMenuBar()
216 : : {
217 : 0 : }
218 : :
219 : 3548 : void SvpSalFrame::SetExtendedFrameStyle( SalExtStyle )
220 : : {
221 : 3548 : }
222 : :
223 : 3559 : void SvpSalFrame::Show( sal_Bool bVisible, sal_Bool bNoActivate )
224 : : {
225 [ + + ][ + - ]: 3559 : if( bVisible && ! m_bVisible )
226 : : {
227 : 1825 : m_bVisible = true;
228 : 1825 : m_pInstance->PostEvent( this, NULL, SALEVENT_RESIZE );
229 [ + + ]: 3558 : if( ! bNoActivate )
230 : 1733 : GetFocus();
231 : : }
232 [ + - ][ + - ]: 1734 : else if( ! bVisible && m_bVisible )
233 : : {
234 : 1734 : m_bVisible = false;
235 : 1734 : m_pInstance->PostEvent( this, NULL, SALEVENT_RESIZE );
236 : 1734 : LoseFocus();
237 : : }
238 : 3559 : }
239 : :
240 : 0 : void SvpSalFrame::Enable( sal_Bool )
241 : : {
242 : 0 : }
243 : :
244 : 0 : void SvpSalFrame::SetMinClientSize( long nWidth, long nHeight )
245 : : {
246 : 0 : m_nMinWidth = nWidth;
247 : 0 : m_nMinHeight = nHeight;
248 : 0 : }
249 : :
250 : 0 : void SvpSalFrame::SetMaxClientSize( long nWidth, long nHeight )
251 : : {
252 : 0 : m_nMaxWidth = nWidth;
253 : 0 : m_nMaxHeight = nHeight;
254 : 0 : }
255 : :
256 : 12864 : void SvpSalFrame::SetPosSize( long nX, long nY, long nWidth, long nHeight, sal_uInt16 nFlags )
257 : : {
258 [ + + ]: 12864 : if( (nFlags & SAL_FRAME_POSSIZE_X) != 0 )
259 : 1783 : maGeometry.nX = nX;
260 [ + + ]: 12864 : if( (nFlags & SAL_FRAME_POSSIZE_Y) != 0 )
261 : 1783 : maGeometry.nY = nY;
262 [ + + ]: 12864 : if( (nFlags & SAL_FRAME_POSSIZE_WIDTH) != 0 )
263 : : {
264 : 12834 : maGeometry.nWidth = nWidth;
265 [ - + ][ # # ]: 12834 : if( m_nMaxWidth > 0 && maGeometry.nWidth > (unsigned int)m_nMaxWidth )
266 : 0 : maGeometry.nWidth = m_nMaxWidth;
267 [ - + ][ # # ]: 12834 : if( m_nMinWidth > 0 && maGeometry.nWidth < (unsigned int)m_nMinWidth )
268 : 0 : maGeometry.nWidth = m_nMinWidth;
269 : : }
270 [ + + ]: 12864 : if( (nFlags & SAL_FRAME_POSSIZE_HEIGHT) != 0 )
271 : : {
272 : 12834 : maGeometry.nHeight = nHeight;
273 [ - + ][ # # ]: 12834 : if( m_nMaxHeight > 0 && maGeometry.nHeight > (unsigned int)m_nMaxHeight )
274 : 0 : maGeometry.nHeight = m_nMaxHeight;
275 [ - + ][ # # ]: 12834 : if( m_nMinHeight > 0 && maGeometry.nHeight < (unsigned int)m_nMinHeight )
276 : 0 : maGeometry.nHeight = m_nMinHeight;
277 : : }
278 : 12864 : B2IVector aFrameSize( maGeometry.nWidth, maGeometry.nHeight );
279 [ + - ][ + + ]: 12864 : if( ! m_aFrame.get() || m_aFrame->getSize() != aFrameSize )
[ + + ]
[ + + # # ]
[ + + ]
280 : : {
281 [ + + ]: 10287 : if( aFrameSize.getX() == 0 )
282 : 38 : aFrameSize.setX( 1 );
283 [ + + ]: 10287 : if( aFrameSize.getY() == 0 )
284 : 38 : aFrameSize.setY( 1 );
285 [ + - ][ + - ]: 10287 : m_aFrame = createBitmapDevice( aFrameSize, m_bTopDown, m_nScanlineFormat );
[ + - ]
286 [ - + ]: 10287 : if (m_bDamageTracking)
287 : : m_aFrame->setDamageTracker(
288 [ # # ][ # # ]: 0 : basebmp::IBitmapDeviceDamageTrackerSharedPtr( new DamageTracker( *this ) ) );
[ # # ][ # # ]
289 : : // update device in existing graphics
290 [ + + ]: 81028 : for( std::list< SvpSalGraphics* >::iterator it = m_aGraphics.begin();
291 : 40514 : it != m_aGraphics.end(); ++it )
292 [ + - ]: 30227 : (*it)->setDevice( m_aFrame );
293 : : }
294 [ + + ]: 12864 : if( m_bVisible )
295 [ + - ]: 12864 : m_pInstance->PostEvent( this, NULL, SALEVENT_RESIZE );
296 : 12864 : }
297 : :
298 : 3701 : void SvpSalFrame::GetClientSize( long& rWidth, long& rHeight )
299 : : {
300 [ + + ]: 3701 : if( m_bVisible )
301 : : {
302 : 1711 : rWidth = maGeometry.nWidth;
303 : 1711 : rHeight = maGeometry.nHeight;
304 : : }
305 : : else
306 : 1990 : rWidth = rHeight = 0;
307 : 3701 : }
308 : :
309 : 11876 : void SvpSalFrame::GetWorkArea( Rectangle& rRect )
310 : : {
311 : : rRect = Rectangle( Point( 0, 0 ),
312 [ + - ]: 11876 : Size( VIRTUAL_DESKTOP_WIDTH, VIRTUAL_DESKTOP_HEIGHT ) );
313 : 11876 : }
314 : :
315 : 49764 : SalFrame* SvpSalFrame::GetParent() const
316 : : {
317 : 49764 : return m_pParent;
318 : : }
319 : :
320 : : #define _FRAMESTATE_MASK_GEOMETRY \
321 : : (SAL_FRAMESTATE_MASK_X | SAL_FRAMESTATE_MASK_Y | \
322 : : SAL_FRAMESTATE_MASK_WIDTH | SAL_FRAMESTATE_MASK_HEIGHT)
323 : :
324 : 1871 : void SvpSalFrame::SetWindowState( const SalFrameState *pState )
325 : : {
326 [ - + ]: 1871 : if (pState == NULL)
327 : 1871 : return;
328 : :
329 : : // Request for position or size change
330 [ + + ]: 1871 : if (pState->mnMask & _FRAMESTATE_MASK_GEOMETRY)
331 : : {
332 : 1743 : long nX = maGeometry.nX;
333 : 1743 : long nY = maGeometry.nY;
334 : 1743 : long nWidth = maGeometry.nWidth;
335 : 1743 : long nHeight = maGeometry.nHeight;
336 : :
337 : : // change requested properties
338 [ + - ]: 1743 : if (pState->mnMask & SAL_FRAMESTATE_MASK_X)
339 : 1743 : nX = pState->mnX;
340 [ + - ]: 1743 : if (pState->mnMask & SAL_FRAMESTATE_MASK_Y)
341 : 1743 : nY = pState->mnY;
342 [ + + ]: 1743 : if (pState->mnMask & SAL_FRAMESTATE_MASK_WIDTH)
343 : 1683 : nWidth = pState->mnWidth;
344 [ + + ]: 1743 : if (pState->mnMask & SAL_FRAMESTATE_MASK_HEIGHT)
345 : 1683 : nHeight = pState->mnHeight;
346 : :
347 : : SetPosSize( nX, nY, nWidth, nHeight,
348 : : SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y |
349 : 1743 : SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT );
350 : : }
351 : : }
352 : :
353 : 6755 : sal_Bool SvpSalFrame::GetWindowState( SalFrameState* pState )
354 : : {
355 : 6755 : pState->mnState = SAL_FRAMESTATE_NORMAL;
356 : 6755 : pState->mnX = maGeometry.nX;
357 : 6755 : pState->mnY = maGeometry.nY;
358 : 6755 : pState->mnWidth = maGeometry.nWidth;
359 : 6755 : pState->mnHeight = maGeometry.nHeight;
360 : 6755 : pState->mnMask = _FRAMESTATE_MASK_GEOMETRY | SAL_FRAMESTATE_MASK_STATE;
361 : :
362 : 6755 : return sal_True;
363 : : }
364 : :
365 : 0 : void SvpSalFrame::ShowFullScreen( sal_Bool, sal_Int32 )
366 : : {
367 : : SetPosSize( 0, 0, VIRTUAL_DESKTOP_WIDTH, VIRTUAL_DESKTOP_HEIGHT,
368 : 0 : SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT );
369 : 0 : }
370 : :
371 : 0 : void SvpSalFrame::StartPresentation( sal_Bool )
372 : : {
373 : 0 : }
374 : :
375 : 0 : void SvpSalFrame::SetAlwaysOnTop( sal_Bool )
376 : : {
377 : 0 : }
378 : :
379 : 3646 : void SvpSalFrame::ToTop( sal_uInt16 )
380 : : {
381 : 3646 : GetFocus();
382 : 3646 : }
383 : :
384 : 0 : void SvpSalFrame::SetPointer( PointerStyle )
385 : : {
386 : 0 : }
387 : :
388 : 0 : void SvpSalFrame::CaptureMouse( sal_Bool )
389 : : {
390 : 0 : }
391 : :
392 : 0 : void SvpSalFrame::SetPointerPos( long, long )
393 : : {
394 : 0 : }
395 : :
396 : 27209 : void SvpSalFrame::Flush()
397 : : {
398 : 27209 : }
399 : :
400 : 0 : void SvpSalFrame::Sync()
401 : : {
402 : 0 : }
403 : :
404 : 3326 : void SvpSalFrame::SetInputContext( SalInputContext* )
405 : : {
406 : 3326 : }
407 : :
408 : 0 : void SvpSalFrame::EndExtTextInput( sal_uInt16 )
409 : : {
410 : 0 : }
411 : :
412 : 46025 : rtl::OUString SvpSalFrame::GetKeyName( sal_uInt16 )
413 : : {
414 : 46025 : return rtl::OUString();
415 : : }
416 : :
417 : 0 : sal_Bool SvpSalFrame::MapUnicodeToKeyCode( sal_Unicode, LanguageType, KeyCode& )
418 : : {
419 : 0 : return sal_False;
420 : : }
421 : :
422 : 3427 : LanguageType SvpSalFrame::GetInputLanguage()
423 : : {
424 : 3427 : return LANGUAGE_DONTKNOW;
425 : : }
426 : :
427 : 367 : void SvpSalFrame::UpdateSettings( AllSettings& )
428 : : {
429 : 367 : }
430 : :
431 : 3371 : const SystemEnvData* SvpSalFrame::GetSystemData() const
432 : : {
433 : 3371 : return &m_aSystemChildData;
434 : : }
435 : :
436 : 477 : SalFrame::SalPointerState SvpSalFrame::GetPointerState()
437 : : {
438 : 477 : SalPointerState aState;
439 : 477 : aState.mnState = 0;
440 : 477 : return aState;
441 : : }
442 : :
443 : 0 : SalFrame::SalIndicatorState SvpSalFrame::GetIndicatorState()
444 : : {
445 : : SalIndicatorState aState;
446 : 0 : aState.mnState = 0;
447 : 0 : return aState;
448 : : }
449 : :
450 : 0 : void SvpSalFrame::SimulateKeyPress( sal_uInt16 /*nKeyCode*/ )
451 : : {
452 : 0 : }
453 : :
454 : 4195 : void SvpSalFrame::SetParent( SalFrame* pNewParent )
455 : : {
456 [ + - ]: 4195 : if( m_pParent )
457 [ + - ]: 4195 : m_pParent->m_aChildren.remove( this );
458 : 4195 : m_pParent = static_cast<SvpSalFrame*>(pNewParent);
459 : 4195 : }
460 : :
461 : 0 : bool SvpSalFrame::SetPluginParent( SystemParentData* )
462 : : {
463 : 0 : return true;
464 : : }
465 : :
466 : 0 : void SvpSalFrame::SetBackgroundBitmap( SalBitmap* )
467 : : {
468 : 0 : }
469 : :
470 : 0 : void SvpSalFrame::ResetClipRegion()
471 : : {
472 : 0 : }
473 : :
474 : 0 : void SvpSalFrame::BeginSetClipRegion( sal_uLong )
475 : : {
476 : 0 : }
477 : :
478 : 0 : void SvpSalFrame::UnionClipRegion( long, long, long, long )
479 : : {
480 : 0 : }
481 : :
482 : 0 : void SvpSalFrame::EndSetClipRegion()
483 : : {
484 : 0 : }
485 : :
486 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|