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>
23 #include "headless/svpframe.hxx"
24 #include "headless/svpinst.hxx"
25 #include "headless/svpgdi.hxx"
27 #include <basegfx/vector/b2ivector.hxx>
33 SvpSalFrame
* SvpSalFrame::s_pFocusFrame
= nullptr;
36 #define SvpSalGraphics AquaSalGraphics
39 SvpSalFrame::SvpSalFrame( SvpSalInstance
* pInstance
,
41 SalFrameStyleFlags nSalFrameStyle
) :
42 m_pInstance( pInstance
),
43 m_pParent( static_cast<SvpSalFrame
*>(pParent
) ),
44 m_nStyle( nSalFrameStyle
),
47 m_pSurface( nullptr ),
54 // SAL_DEBUG("SvpSalFrame::SvpSalFrame: " << this);
55 // fast and easy cross-platform wiping of the data
56 memset( static_cast<void *>(&m_aSystemChildData
), 0, sizeof( SystemEnvData
) );
57 m_aSystemChildData
.nSize
= sizeof( SystemEnvData
);
63 m_aSystemChildData
.pSalFrame
= this;
64 m_aSystemChildData
.nDepth
= 24;
68 m_pParent
->m_aChildren
.push_back( this );
71 m_pInstance
->registerFrame( this );
73 SetPosSize( 0, 0, 800, 600, SAL_FRAME_POSSIZE_WIDTH
| SAL_FRAME_POSSIZE_HEIGHT
);
76 SvpSalFrame::~SvpSalFrame()
79 m_pInstance
->deregisterFrame( this );
81 std::list
<SvpSalFrame
*> Children
= m_aChildren
;
82 for( std::list
<SvpSalFrame
*>::iterator it
= Children
.begin();
83 it
!= Children
.end(); ++it
)
84 (*it
)->SetParent( m_pParent
);
86 m_pParent
->m_aChildren
.remove( this );
88 if( s_pFocusFrame
== this )
90 // SAL_DEBUG("SvpSalFrame::~SvpSalFrame: losing focus: " << this);
91 s_pFocusFrame
= nullptr;
92 // call directly here, else an event for a destroyed frame would be dispatched
93 CallCallback( SalEvent::LoseFocus
, nullptr );
94 // if the handler has not set a new focus frame
95 // pass focus to another frame, preferably a document style window
96 if( s_pFocusFrame
== nullptr )
98 const std::list
< SalFrame
* >& rFrames( m_pInstance
->getFrames() );
99 for( std::list
< SalFrame
* >::const_iterator it
= rFrames
.begin(); it
!= rFrames
.end(); ++it
)
101 SvpSalFrame
* pFrame
= const_cast<SvpSalFrame
*>(static_cast<const SvpSalFrame
*>(*it
));
102 if( pFrame
->m_bVisible
&&
103 pFrame
->m_pParent
== nullptr &&
104 (pFrame
->m_nStyle
& (SalFrameStyleFlags::MOVEABLE
|
105 SalFrameStyleFlags::SIZEABLE
|
106 SalFrameStyleFlags::CLOSEABLE
) )
117 cairo_surface_destroy(m_pSurface
);
121 void SvpSalFrame::GetFocus()
123 if( s_pFocusFrame
== this )
126 if( (m_nStyle
& (SalFrameStyleFlags::OWNERDRAWDECORATION
| SalFrameStyleFlags::FLOAT
)) == SalFrameStyleFlags::NONE
)
129 s_pFocusFrame
->LoseFocus();
130 // SAL_DEBUG("SvpSalFrame::GetFocus(): " << this);
131 s_pFocusFrame
= this;
132 m_pInstance
->PostEvent( this, nullptr, SalEvent::GetFocus
);
136 void SvpSalFrame::LoseFocus()
138 if( s_pFocusFrame
== this )
140 // SAL_DEBUG("SvpSalFrame::LoseFocus: " << this);
141 m_pInstance
->PostEvent( this, nullptr, SalEvent::LoseFocus
);
142 s_pFocusFrame
= nullptr;
146 SalGraphics
* SvpSalFrame::AcquireGraphics()
148 SvpSalGraphics
* pGraphics
= new SvpSalGraphics();
150 pGraphics
->setSurface(m_pSurface
, basegfx::B2IVector(maGeometry
.nWidth
, maGeometry
.nHeight
));
152 m_aGraphics
.push_back( pGraphics
);
156 void SvpSalFrame::ReleaseGraphics( SalGraphics
* pGraphics
)
158 SvpSalGraphics
* pSvpGraphics
= dynamic_cast<SvpSalGraphics
*>(pGraphics
);
159 m_aGraphics
.remove( pSvpGraphics
);
163 bool SvpSalFrame::PostEvent(ImplSVEvent
* pData
)
165 m_pInstance
->PostEvent( this, pData
, SalEvent::UserEvent
);
169 void SvpSalFrame::PostPaint() const
173 SalPaintEvent
aPEvt(0, 0, maGeometry
.nWidth
, maGeometry
.nHeight
);
174 aPEvt
.mbImmediateUpdate
= false;
175 CallCallback( SalEvent::Paint
, &aPEvt
);
179 void SvpSalFrame::SetTitle( const OUString
& )
183 void SvpSalFrame::SetIcon( sal_uInt16
)
187 void SvpSalFrame::SetMenu( SalMenu
* )
191 void SvpSalFrame::DrawMenuBar()
195 void SvpSalFrame::SetExtendedFrameStyle( SalExtStyle
)
199 void SvpSalFrame::Show( bool bVisible
, bool bNoActivate
)
201 if( bVisible
&& ! m_bVisible
)
203 // SAL_DEBUG("SvpSalFrame::Show: showing: " << this);
205 m_pInstance
->PostEvent( this, nullptr, SalEvent::Resize
);
209 else if( ! bVisible
&& m_bVisible
)
211 // SAL_DEBUG("SvpSalFrame::Show: hiding: " << this);
213 m_pInstance
->PostEvent( this, nullptr, SalEvent::Resize
);
218 // SAL_DEBUG("SvpSalFrame::Show: nothing: " << this);
222 void SvpSalFrame::SetMinClientSize( long nWidth
, long nHeight
)
224 m_nMinWidth
= nWidth
;
225 m_nMinHeight
= nHeight
;
228 void SvpSalFrame::SetMaxClientSize( long nWidth
, long nHeight
)
230 m_nMaxWidth
= nWidth
;
231 m_nMaxHeight
= nHeight
;
234 void SvpSalFrame::SetPosSize( long nX
, long nY
, long nWidth
, long nHeight
, sal_uInt16 nFlags
)
236 if( (nFlags
& SAL_FRAME_POSSIZE_X
) != 0 )
238 if( (nFlags
& SAL_FRAME_POSSIZE_Y
) != 0 )
240 if( (nFlags
& SAL_FRAME_POSSIZE_WIDTH
) != 0 )
242 maGeometry
.nWidth
= nWidth
;
243 if( m_nMaxWidth
> 0 && maGeometry
.nWidth
> (unsigned int)m_nMaxWidth
)
244 maGeometry
.nWidth
= m_nMaxWidth
;
245 if( m_nMinWidth
> 0 && maGeometry
.nWidth
< (unsigned int)m_nMinWidth
)
246 maGeometry
.nWidth
= m_nMinWidth
;
248 if( (nFlags
& SAL_FRAME_POSSIZE_HEIGHT
) != 0 )
250 maGeometry
.nHeight
= nHeight
;
251 if( m_nMaxHeight
> 0 && maGeometry
.nHeight
> (unsigned int)m_nMaxHeight
)
252 maGeometry
.nHeight
= m_nMaxHeight
;
253 if( m_nMinHeight
> 0 && maGeometry
.nHeight
< (unsigned int)m_nMinHeight
)
254 maGeometry
.nHeight
= m_nMinHeight
;
257 basegfx::B2IVector
aFrameSize( maGeometry
.nWidth
, maGeometry
.nHeight
);
258 if (!m_pSurface
|| cairo_image_surface_get_width(m_pSurface
) != aFrameSize
.getX() ||
259 cairo_image_surface_get_height(m_pSurface
) != aFrameSize
.getY() )
261 if( aFrameSize
.getX() == 0 )
262 aFrameSize
.setX( 1 );
263 if( aFrameSize
.getY() == 0 )
264 aFrameSize
.setY( 1 );
267 cairo_surface_destroy(m_pSurface
);
269 // Creating backing surfaces for invisible windows costs a big chunk of RAM.
270 if (Application::IsHeadlessModeEnabled())
271 aFrameSize
= basegfx::B2IVector( 1, 1 );
273 m_pSurface
= cairo_image_surface_create(CAIRO_FORMAT_ARGB32
,
277 // update device in existing graphics
278 for( std::list
< SvpSalGraphics
* >::iterator it
= m_aGraphics
.begin();
279 it
!= m_aGraphics
.end(); ++it
)
281 (*it
)->setSurface(m_pSurface
, aFrameSize
);
285 m_pInstance
->PostEvent( this, nullptr, SalEvent::Resize
);
289 void SvpSalFrame::GetClientSize( long& rWidth
, long& rHeight
)
291 rWidth
= maGeometry
.nWidth
;
292 rHeight
= maGeometry
.nHeight
;
295 void SvpSalFrame::GetWorkArea( tools::Rectangle
& rRect
)
297 rRect
= tools::Rectangle( Point( 0, 0 ),
298 Size( VIRTUAL_DESKTOP_WIDTH
, VIRTUAL_DESKTOP_HEIGHT
) );
301 SalFrame
* SvpSalFrame::GetParent() const
306 #define FRAMESTATE_MASK_GEOMETRY \
307 (WindowStateMask::X | WindowStateMask::Y | \
308 WindowStateMask::Width | WindowStateMask::Height)
310 void SvpSalFrame::SetWindowState( const SalFrameState
*pState
)
312 if (pState
== nullptr)
315 // Request for position or size change
316 if (pState
->mnMask
& FRAMESTATE_MASK_GEOMETRY
)
318 long nX
= maGeometry
.nX
;
319 long nY
= maGeometry
.nY
;
320 long nWidth
= maGeometry
.nWidth
;
321 long nHeight
= maGeometry
.nHeight
;
323 // change requested properties
324 if (pState
->mnMask
& WindowStateMask::X
)
326 if (pState
->mnMask
& WindowStateMask::Y
)
328 if (pState
->mnMask
& WindowStateMask::Width
)
329 nWidth
= pState
->mnWidth
;
330 if (pState
->mnMask
& WindowStateMask::Height
)
331 nHeight
= pState
->mnHeight
;
333 SetPosSize( nX
, nY
, nWidth
, nHeight
,
334 SAL_FRAME_POSSIZE_X
| SAL_FRAME_POSSIZE_Y
|
335 SAL_FRAME_POSSIZE_WIDTH
| SAL_FRAME_POSSIZE_HEIGHT
);
339 bool SvpSalFrame::GetWindowState( SalFrameState
* pState
)
341 pState
->mnState
= WindowStateState::Normal
;
342 pState
->mnX
= maGeometry
.nX
;
343 pState
->mnY
= maGeometry
.nY
;
344 pState
->mnWidth
= maGeometry
.nWidth
;
345 pState
->mnHeight
= maGeometry
.nHeight
;
346 pState
->mnMask
= FRAMESTATE_MASK_GEOMETRY
| WindowStateMask::State
;
351 void SvpSalFrame::ShowFullScreen( bool, sal_Int32
)
353 SetPosSize( 0, 0, VIRTUAL_DESKTOP_WIDTH
, VIRTUAL_DESKTOP_HEIGHT
,
354 SAL_FRAME_POSSIZE_WIDTH
| SAL_FRAME_POSSIZE_HEIGHT
);
357 void SvpSalFrame::StartPresentation( bool )
361 void SvpSalFrame::SetAlwaysOnTop( bool )
365 void SvpSalFrame::ToTop( SalFrameToTop
)
370 void SvpSalFrame::SetPointer( PointerStyle
)
374 void SvpSalFrame::CaptureMouse( bool )
378 void SvpSalFrame::SetPointerPos( long, long )
382 void SvpSalFrame::Flush()
386 void SvpSalFrame::SetInputContext( SalInputContext
* )
390 void SvpSalFrame::EndExtTextInput( EndExtTextInputFlags
)
394 OUString
SvpSalFrame::GetKeyName( sal_uInt16
)
399 bool SvpSalFrame::MapUnicodeToKeyCode( sal_Unicode
, LanguageType
, vcl::KeyCode
& )
404 LanguageType
SvpSalFrame::GetInputLanguage()
406 return LANGUAGE_DONTKNOW
;
409 void SvpSalFrame::UpdateSettings( AllSettings
& )
413 void SvpSalFrame::Beep()
417 const SystemEnvData
* SvpSalFrame::GetSystemData() const
419 return &m_aSystemChildData
;
422 SalFrame::SalPointerState
SvpSalFrame::GetPointerState()
424 SalPointerState aState
;
429 KeyIndicatorState
SvpSalFrame::GetIndicatorState()
431 return KeyIndicatorState::NONE
;
434 void SvpSalFrame::SimulateKeyPress( sal_uInt16
/*nKeyCode*/ )
438 void SvpSalFrame::SetParent( SalFrame
* pNewParent
)
441 m_pParent
->m_aChildren
.remove( this );
442 m_pParent
= static_cast<SvpSalFrame
*>(pNewParent
);
445 bool SvpSalFrame::SetPluginParent( SystemParentData
* )
450 void SvpSalFrame::ResetClipRegion()
454 void SvpSalFrame::BeginSetClipRegion( sal_uLong
)
458 void SvpSalFrame::UnionClipRegion( long, long, long, long )
462 void SvpSalFrame::EndSetClipRegion()
466 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */