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 .
20 #include <comphelper/lok.hxx>
21 #include <sal/log.hxx>
23 #include <headless/svpframe.hxx>
24 #include <headless/svpinst.hxx>
26 #include <headless/svpgdi.hxx>
30 #include <basegfx/vector/b2ivector.hxx>
36 SvpSalFrame
* SvpSalFrame::s_pFocusFrame
= nullptr;
39 #define SvpSalGraphics AquaSalGraphics
42 SvpSalFrame::SvpSalFrame( SvpSalInstance
* pInstance
,
44 SalFrameStyleFlags nSalFrameStyle
) :
45 m_pInstance( pInstance
),
46 m_pParent( static_cast<SvpSalFrame
*>(pParent
) ),
47 m_nStyle( nSalFrameStyle
),
50 m_pSurface( nullptr ),
62 m_aSystemChildData
.pSalFrame
= this;
66 m_pParent
->m_aChildren
.push_back( this );
69 m_pInstance
->registerFrame( this );
71 SetPosSize( 0, 0, 800, 600, SAL_FRAME_POSSIZE_WIDTH
| SAL_FRAME_POSSIZE_HEIGHT
);
74 SvpSalFrame::~SvpSalFrame()
77 m_pInstance
->deregisterFrame( this );
79 std::vector
<SvpSalFrame
*> Children
= m_aChildren
;
80 for( auto& rChild
: Children
)
81 rChild
->SetParent( m_pParent
);
83 std::erase(m_pParent
->m_aChildren
, this);
85 if( s_pFocusFrame
== this )
87 s_pFocusFrame
= nullptr;
88 // call directly here, else an event for a destroyed frame would be dispatched
89 CallCallback( SalEvent::LoseFocus
, nullptr );
90 // if the handler has not set a new focus frame
91 // pass focus to another frame, preferably a document style window
92 if( s_pFocusFrame
== nullptr )
94 for (auto pSalFrame
: m_pInstance
->getFrames() )
96 SvpSalFrame
* pFrame
= static_cast<SvpSalFrame
*>( pSalFrame
);
97 if( pFrame
->m_bVisible
&&
98 pFrame
->m_pParent
== nullptr &&
99 (pFrame
->m_nStyle
& (SalFrameStyleFlags::MOVEABLE
|
100 SalFrameStyleFlags::SIZEABLE
|
101 SalFrameStyleFlags::CLOSEABLE
) )
112 cairo_surface_destroy(m_pSurface
);
116 void SvpSalFrame::GetFocus()
118 if (m_nStyle
== SalFrameStyleFlags::NONE
)
120 if( s_pFocusFrame
== this )
122 // FIXME: return if !m_bVisible
123 // That's IMHO why CppunitTest_sd_tiledrendering crashes non-headless
125 if( (m_nStyle
& (SalFrameStyleFlags::OWNERDRAWDECORATION
| SalFrameStyleFlags::FLOAT
)) == SalFrameStyleFlags::NONE
)
128 s_pFocusFrame
->LoseFocus();
129 s_pFocusFrame
= this;
130 m_pInstance
->PostEvent( this, nullptr, SalEvent::GetFocus
);
134 void SvpSalFrame::LoseFocus()
136 if( s_pFocusFrame
== this )
138 m_pInstance
->PostEvent( this, nullptr, SalEvent::LoseFocus
);
139 s_pFocusFrame
= nullptr;
143 basegfx::B2IVector
SvpSalFrame::GetSurfaceFrameSize() const
145 basegfx::B2IVector
aFrameSize( maGeometry
.width(), maGeometry
.height() );
146 if( aFrameSize
.getX() == 0 )
147 aFrameSize
.setX( 1 );
148 if( aFrameSize
.getY() == 0 )
149 aFrameSize
.setY( 1 );
150 // Creating backing surfaces for invisible windows costs a big chunk of RAM.
151 if (Application::IsHeadlessModeEnabled())
152 aFrameSize
= basegfx::B2IVector( 1, 1 );
156 SalGraphics
* SvpSalFrame::AcquireGraphics()
158 SvpSalGraphics
* pGraphics
= new SvpSalGraphics();
160 pGraphics
->setSurface(m_pSurface
, GetSurfaceFrameSize());
162 m_aGraphics
.push_back( pGraphics
);
166 void SvpSalFrame::ReleaseGraphics( SalGraphics
* pGraphics
)
168 SvpSalGraphics
* pSvpGraphics
= dynamic_cast<SvpSalGraphics
*>(pGraphics
);
169 std::erase(m_aGraphics
, pSvpGraphics
);
173 bool SvpSalFrame::PostEvent(std::unique_ptr
<ImplSVEvent
> pData
)
175 m_pInstance
->PostEvent( this, pData
.release(), SalEvent::UserEvent
);
179 void SvpSalFrame::PostPaint() const
183 SalPaintEvent
aPEvt(0, 0, maGeometry
.width(), maGeometry
.height());
184 aPEvt
.mbImmediateUpdate
= false;
185 CallCallback( SalEvent::Paint
, &aPEvt
);
189 void SvpSalFrame::SetTitle(const OUString
& sTitle
)
194 void SvpSalFrame::SetIcon( sal_uInt16
)
198 void SvpSalFrame::SetMenu( SalMenu
* )
202 void SvpSalFrame::SetExtendedFrameStyle( SalExtStyle
)
206 void SvpSalFrame::Show( bool bVisible
, bool bNoActivate
)
208 if (m_nStyle
== SalFrameStyleFlags::NONE
)
210 if (bVisible
== m_bVisible
)
212 if (m_bVisible
&& !bNoActivate
)
220 m_pInstance
->PostEvent( this, nullptr, SalEvent::Resize
);
231 void SvpSalFrame::SetMinClientSize( tools::Long nWidth
, tools::Long nHeight
)
233 m_nMinWidth
= nWidth
;
234 m_nMinHeight
= nHeight
;
237 void SvpSalFrame::SetMaxClientSize( tools::Long nWidth
, tools::Long nHeight
)
239 m_nMaxWidth
= nWidth
;
240 m_nMaxHeight
= nHeight
;
243 void SvpSalFrame::SetPosSize( tools::Long nX
, tools::Long nY
, tools::Long nWidth
, tools::Long nHeight
, sal_uInt16 nFlags
)
245 if( (nFlags
& SAL_FRAME_POSSIZE_X
) != 0 )
247 if( (nFlags
& SAL_FRAME_POSSIZE_Y
) != 0 )
249 if( (nFlags
& SAL_FRAME_POSSIZE_WIDTH
) != 0 )
251 maGeometry
.setWidth(nWidth
);
252 if (m_nMaxWidth
> 0 && maGeometry
.width() > m_nMaxWidth
)
253 maGeometry
.setWidth(m_nMaxWidth
);
254 if (m_nMinWidth
> 0 && maGeometry
.width() < m_nMinWidth
)
255 maGeometry
.setWidth(m_nMinWidth
);
257 if( (nFlags
& SAL_FRAME_POSSIZE_HEIGHT
) != 0 )
259 maGeometry
.setHeight(nHeight
);
260 if (m_nMaxHeight
> 0 && maGeometry
.height() > m_nMaxHeight
)
261 maGeometry
.setHeight(m_nMaxHeight
);
262 if (m_nMinHeight
> 0 && maGeometry
.height() < m_nMinHeight
)
263 maGeometry
.setHeight(m_nMinHeight
);
266 basegfx::B2IVector aFrameSize
= GetSurfaceFrameSize();
267 if (!m_pSurface
|| cairo_image_surface_get_width(m_pSurface
) != aFrameSize
.getX() ||
268 cairo_image_surface_get_height(m_pSurface
) != aFrameSize
.getY() )
271 cairo_surface_destroy(m_pSurface
);
273 m_pSurface
= cairo_image_surface_create(CAIRO_FORMAT_ARGB32
,
277 // update device in existing graphics
278 for (auto const& graphic
: m_aGraphics
)
280 graphic
->setSurface(m_pSurface
, aFrameSize
);
284 m_pInstance
->PostEvent( this, nullptr, SalEvent::Resize
);
288 void SvpSalFrame::GetClientSize( tools::Long
& rWidth
, tools::Long
& rHeight
)
290 rWidth
= maGeometry
.width();
291 rHeight
= maGeometry
.height();
294 void SvpSalFrame::GetWorkArea( AbsoluteScreenPixelRectangle
& rRect
)
296 rRect
= AbsoluteScreenPixelRectangle( AbsoluteScreenPixelPoint( 0, 0 ),
297 AbsoluteScreenPixelSize( VIRTUAL_DESKTOP_WIDTH
, VIRTUAL_DESKTOP_HEIGHT
) );
300 SalFrame
* SvpSalFrame::GetParent() const
305 void SvpSalFrame::SetWindowState(const vcl::WindowData
*pState
)
307 if (pState
== nullptr)
310 // Request for position or size change
311 if (!(pState
->mask() & vcl::WindowDataMask::PosSize
))
314 tools::Long nX
= maGeometry
.x();
315 tools::Long nY
= maGeometry
.y();
316 tools::Long nWidth
= maGeometry
.width();
317 tools::Long nHeight
= maGeometry
.height();
319 // change requested properties
320 if (pState
->mask() & vcl::WindowDataMask::X
)
322 if (pState
->mask() & vcl::WindowDataMask::Y
)
324 if (pState
->mask() & vcl::WindowDataMask::Width
)
325 nWidth
= pState
->width();
326 if (pState
->mask() & vcl::WindowDataMask::Height
)
327 nHeight
= pState
->height();
329 SetPosSize( nX
, nY
, nWidth
, nHeight
,
330 SAL_FRAME_POSSIZE_X
| SAL_FRAME_POSSIZE_Y
|
331 SAL_FRAME_POSSIZE_WIDTH
| SAL_FRAME_POSSIZE_HEIGHT
);
334 bool SvpSalFrame::GetWindowState(vcl::WindowData
* pState
)
336 pState
->setPosSize(maGeometry
.posSize());
337 pState
->setState(vcl::WindowState::Normal
);
338 pState
->setMask(vcl::WindowDataMask::PosSizeState
);
342 void SvpSalFrame::ShowFullScreen( bool, sal_Int32
)
344 SetPosSize( 0, 0, VIRTUAL_DESKTOP_WIDTH
, VIRTUAL_DESKTOP_HEIGHT
,
345 SAL_FRAME_POSSIZE_WIDTH
| SAL_FRAME_POSSIZE_HEIGHT
);
348 void SvpSalFrame::StartPresentation( bool )
352 void SvpSalFrame::SetAlwaysOnTop( bool )
356 void SvpSalFrame::ToTop(SalFrameToTop nFlags
)
358 if (m_nStyle
== SalFrameStyleFlags::NONE
)
360 if (nFlags
& SalFrameToTop::RestoreWhenMin
)
366 void SvpSalFrame::SetPointer( PointerStyle
)
370 void SvpSalFrame::CaptureMouse( bool )
374 void SvpSalFrame::SetPointerPos( tools::Long
, tools::Long
)
378 void SvpSalFrame::Flush()
382 void SvpSalFrame::SetInputContext( SalInputContext
* )
386 void SvpSalFrame::EndExtTextInput( EndExtTextInputFlags
)
390 OUString
SvpSalFrame::GetKeyName( sal_uInt16
)
395 bool SvpSalFrame::MapUnicodeToKeyCode( sal_Unicode
, LanguageType
, vcl::KeyCode
& )
400 LanguageType
SvpSalFrame::GetInputLanguage()
402 return LANGUAGE_DONTKNOW
;
405 void SvpSalFrame::UpdateSettings( AllSettings
& rSettings
)
407 StyleSettings aStyleSettings
= rSettings
.GetStyleSettings();
409 Color
aBackgroundColor( 0xef, 0xef, 0xef );
410 aStyleSettings
.BatchSetBackgrounds( aBackgroundColor
, false );
411 aStyleSettings
.SetMenuColor( aBackgroundColor
);
412 aStyleSettings
.SetMenuBarColor( aBackgroundColor
);
414 if (comphelper::LibreOfficeKit::isActive()) // TODO: remove this.
416 vcl::Font
aStdFont( FAMILY_SWISS
, Size( 0, 14 ) );
417 aStdFont
.SetCharSet( osl_getThreadTextEncoding() );
418 aStdFont
.SetWeight( WEIGHT_NORMAL
);
419 aStdFont
.SetFamilyName( u
"Liberation Sans"_ustr
);
420 aStyleSettings
.BatchSetFonts( aStdFont
, aStdFont
);
422 aStdFont
.SetFontSize(Size(0, 12));
423 aStyleSettings
.SetMenuFont(aStdFont
);
425 SvpSalGraphics
* pGraphics
= m_aGraphics
.empty() ? nullptr : m_aGraphics
.back();
426 bool bFreeGraphics
= false;
429 pGraphics
= dynamic_cast<SvpSalGraphics
*>(AcquireGraphics());
432 SAL_WARN("vcl.gtk3", "Could not get graphics - unable to update settings");
435 bFreeGraphics
= true;
437 rSettings
.SetStyleSettings(aStyleSettings
);
438 #ifndef IOS // For now...
439 pGraphics
->UpdateSettings(rSettings
);
442 ReleaseGraphics(pGraphics
);
445 rSettings
.SetStyleSettings(aStyleSettings
);
448 void SvpSalFrame::Beep()
452 const SystemEnvData
& SvpSalFrame::GetSystemData() const
454 return m_aSystemChildData
;
457 SalFrame::SalPointerState
SvpSalFrame::GetPointerState()
459 SalPointerState aState
;
464 KeyIndicatorState
SvpSalFrame::GetIndicatorState()
466 return KeyIndicatorState::NONE
;
469 void SvpSalFrame::SimulateKeyPress( sal_uInt16
/*nKeyCode*/ )
473 void SvpSalFrame::SetParent( SalFrame
* pNewParent
)
476 std::erase(m_pParent
->m_aChildren
, this);
477 m_pParent
= static_cast<SvpSalFrame
*>(pNewParent
);
480 void SvpSalFrame::SetPluginParent( SystemParentData
* )
484 void SvpSalFrame::ResetClipRegion()
488 void SvpSalFrame::BeginSetClipRegion( sal_uInt32
)
492 void SvpSalFrame::UnionClipRegion( tools::Long
, tools::Long
, tools::Long
, tools::Long
)
496 void SvpSalFrame::EndSetClipRegion()
500 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */