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 <o3tl/safeint.hxx>
22 #include <vcl/syswin.hxx>
23 #include <sal/log.hxx>
25 #include <headless/svpframe.hxx>
26 #include <headless/svpinst.hxx>
28 #include <headless/svpgdi.hxx>
32 #include <basegfx/vector/b2ivector.hxx>
38 SvpSalFrame
* SvpSalFrame::s_pFocusFrame
= nullptr;
41 #define SvpSalGraphics AquaSalGraphics
44 SvpSalFrame::SvpSalFrame( SvpSalInstance
* pInstance
,
46 SalFrameStyleFlags nSalFrameStyle
) :
47 m_pInstance( pInstance
),
48 m_pParent( static_cast<SvpSalFrame
*>(pParent
) ),
49 m_nStyle( nSalFrameStyle
),
52 m_pSurface( nullptr ),
64 m_aSystemChildData
.pSalFrame
= this;
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::vector
<SvpSalFrame
*> Children
= m_aChildren
;
82 for( auto& rChild
: Children
)
83 rChild
->SetParent( m_pParent
);
85 m_pParent
->m_aChildren
.erase(std::remove(m_pParent
->m_aChildren
.begin(), m_pParent
->m_aChildren
.end(), this), m_pParent
->m_aChildren
.end());
87 if( s_pFocusFrame
== this )
89 s_pFocusFrame
= nullptr;
90 // call directly here, else an event for a destroyed frame would be dispatched
91 CallCallback( SalEvent::LoseFocus
, nullptr );
92 // if the handler has not set a new focus frame
93 // pass focus to another frame, preferably a document style window
94 if( s_pFocusFrame
== nullptr )
96 for (auto pSalFrame
: m_pInstance
->getFrames() )
98 SvpSalFrame
* pFrame
= static_cast<SvpSalFrame
*>( pSalFrame
);
99 if( pFrame
->m_bVisible
&&
100 pFrame
->m_pParent
== nullptr &&
101 (pFrame
->m_nStyle
& (SalFrameStyleFlags::MOVEABLE
|
102 SalFrameStyleFlags::SIZEABLE
|
103 SalFrameStyleFlags::CLOSEABLE
) )
114 cairo_surface_destroy(m_pSurface
);
118 void SvpSalFrame::GetFocus()
120 if (m_nStyle
== SalFrameStyleFlags::NONE
)
122 if( s_pFocusFrame
== this )
124 // FIXME: return if !m_bVisible
125 // That's IMHO why CppunitTest_sd_tiledrendering crashes non-headless
127 if( (m_nStyle
& (SalFrameStyleFlags::OWNERDRAWDECORATION
| SalFrameStyleFlags::FLOAT
)) == SalFrameStyleFlags::NONE
)
130 s_pFocusFrame
->LoseFocus();
131 s_pFocusFrame
= this;
132 m_pInstance
->PostEvent( this, nullptr, SalEvent::GetFocus
);
136 void SvpSalFrame::LoseFocus()
138 if( s_pFocusFrame
== this )
140 m_pInstance
->PostEvent( this, nullptr, SalEvent::LoseFocus
);
141 s_pFocusFrame
= nullptr;
145 basegfx::B2IVector
SvpSalFrame::GetSurfaceFrameSize() const
147 basegfx::B2IVector
aFrameSize( maGeometry
.width(), maGeometry
.height() );
148 if( aFrameSize
.getX() == 0 )
149 aFrameSize
.setX( 1 );
150 if( aFrameSize
.getY() == 0 )
151 aFrameSize
.setY( 1 );
152 // Creating backing surfaces for invisible windows costs a big chunk of RAM.
153 if (Application::IsHeadlessModeEnabled())
154 aFrameSize
= basegfx::B2IVector( 1, 1 );
158 SalGraphics
* SvpSalFrame::AcquireGraphics()
160 SvpSalGraphics
* pGraphics
= new SvpSalGraphics();
162 pGraphics
->setSurface(m_pSurface
, GetSurfaceFrameSize());
164 m_aGraphics
.push_back( pGraphics
);
168 void SvpSalFrame::ReleaseGraphics( SalGraphics
* pGraphics
)
170 SvpSalGraphics
* pSvpGraphics
= dynamic_cast<SvpSalGraphics
*>(pGraphics
);
171 m_aGraphics
.erase(std::remove(m_aGraphics
.begin(), m_aGraphics
.end(), pSvpGraphics
), m_aGraphics
.end());
175 bool SvpSalFrame::PostEvent(std::unique_ptr
<ImplSVEvent
> pData
)
177 m_pInstance
->PostEvent( this, pData
.release(), SalEvent::UserEvent
);
181 void SvpSalFrame::PostPaint() const
185 SalPaintEvent
aPEvt(0, 0, maGeometry
.width(), maGeometry
.height());
186 aPEvt
.mbImmediateUpdate
= false;
187 CallCallback( SalEvent::Paint
, &aPEvt
);
191 void SvpSalFrame::SetTitle(const OUString
& sTitle
)
196 void SvpSalFrame::SetIcon( sal_uInt16
)
200 void SvpSalFrame::SetMenu( SalMenu
* )
204 void SvpSalFrame::SetExtendedFrameStyle( SalExtStyle
)
208 void SvpSalFrame::Show( bool bVisible
, bool bNoActivate
)
210 if (m_nStyle
== SalFrameStyleFlags::NONE
)
212 if (bVisible
== m_bVisible
)
214 if (m_bVisible
&& !bNoActivate
)
222 m_pInstance
->PostEvent( this, nullptr, SalEvent::Resize
);
233 void SvpSalFrame::SetMinClientSize( tools::Long nWidth
, tools::Long nHeight
)
235 m_nMinWidth
= nWidth
;
236 m_nMinHeight
= nHeight
;
239 void SvpSalFrame::SetMaxClientSize( tools::Long nWidth
, tools::Long nHeight
)
241 m_nMaxWidth
= nWidth
;
242 m_nMaxHeight
= nHeight
;
245 void SvpSalFrame::SetPosSize( tools::Long nX
, tools::Long nY
, tools::Long nWidth
, tools::Long nHeight
, sal_uInt16 nFlags
)
247 if( (nFlags
& SAL_FRAME_POSSIZE_X
) != 0 )
249 if( (nFlags
& SAL_FRAME_POSSIZE_Y
) != 0 )
251 if( (nFlags
& SAL_FRAME_POSSIZE_WIDTH
) != 0 )
253 maGeometry
.setWidth(nWidth
);
254 if (m_nMaxWidth
> 0 && maGeometry
.width() > m_nMaxWidth
)
255 maGeometry
.setWidth(m_nMaxWidth
);
256 if (m_nMinWidth
> 0 && maGeometry
.width() < m_nMinWidth
)
257 maGeometry
.setWidth(m_nMinWidth
);
259 if( (nFlags
& SAL_FRAME_POSSIZE_HEIGHT
) != 0 )
261 maGeometry
.setHeight(nHeight
);
262 if (m_nMaxHeight
> 0 && maGeometry
.height() > m_nMaxHeight
)
263 maGeometry
.setHeight(m_nMaxHeight
);
264 if (m_nMinHeight
> 0 && maGeometry
.height() < m_nMinHeight
)
265 maGeometry
.setHeight(m_nMinHeight
);
268 basegfx::B2IVector aFrameSize
= GetSurfaceFrameSize();
269 if (!m_pSurface
|| cairo_image_surface_get_width(m_pSurface
) != aFrameSize
.getX() ||
270 cairo_image_surface_get_height(m_pSurface
) != aFrameSize
.getY() )
273 cairo_surface_destroy(m_pSurface
);
275 m_pSurface
= cairo_image_surface_create(CAIRO_FORMAT_ARGB32
,
279 // update device in existing graphics
280 for (auto const& graphic
: m_aGraphics
)
282 graphic
->setSurface(m_pSurface
, aFrameSize
);
286 m_pInstance
->PostEvent( this, nullptr, SalEvent::Resize
);
290 void SvpSalFrame::GetClientSize( tools::Long
& rWidth
, tools::Long
& rHeight
)
292 rWidth
= maGeometry
.width();
293 rHeight
= maGeometry
.height();
296 void SvpSalFrame::GetWorkArea( tools::Rectangle
& rRect
)
298 rRect
= tools::Rectangle( Point( 0, 0 ),
299 Size( VIRTUAL_DESKTOP_WIDTH
, VIRTUAL_DESKTOP_HEIGHT
) );
302 SalFrame
* SvpSalFrame::GetParent() const
307 void SvpSalFrame::SetWindowState(const vcl::WindowData
*pState
)
309 if (pState
== nullptr)
312 // Request for position or size change
313 if (!(pState
->mask() & vcl::WindowDataMask::PosSize
))
316 tools::Long nX
= maGeometry
.x();
317 tools::Long nY
= maGeometry
.y();
318 tools::Long nWidth
= maGeometry
.width();
319 tools::Long nHeight
= maGeometry
.height();
321 // change requested properties
322 if (pState
->mask() & vcl::WindowDataMask::X
)
324 if (pState
->mask() & vcl::WindowDataMask::Y
)
326 if (pState
->mask() & vcl::WindowDataMask::Width
)
327 nWidth
= pState
->width();
328 if (pState
->mask() & vcl::WindowDataMask::Height
)
329 nHeight
= pState
->height();
331 SetPosSize( nX
, nY
, nWidth
, nHeight
,
332 SAL_FRAME_POSSIZE_X
| SAL_FRAME_POSSIZE_Y
|
333 SAL_FRAME_POSSIZE_WIDTH
| SAL_FRAME_POSSIZE_HEIGHT
);
336 bool SvpSalFrame::GetWindowState(vcl::WindowData
* pState
)
338 pState
->setPosSize(maGeometry
.posSize());
339 pState
->setState(vcl::WindowState::Normal
);
340 pState
->setMask(vcl::WindowDataMask::PosSizeState
);
344 void SvpSalFrame::ShowFullScreen( bool, sal_Int32
)
346 SetPosSize( 0, 0, VIRTUAL_DESKTOP_WIDTH
, VIRTUAL_DESKTOP_HEIGHT
,
347 SAL_FRAME_POSSIZE_WIDTH
| SAL_FRAME_POSSIZE_HEIGHT
);
350 void SvpSalFrame::StartPresentation( bool )
354 void SvpSalFrame::SetAlwaysOnTop( bool )
358 void SvpSalFrame::ToTop(SalFrameToTop nFlags
)
360 if (m_nStyle
== SalFrameStyleFlags::NONE
)
362 if (nFlags
& SalFrameToTop::RestoreWhenMin
)
368 void SvpSalFrame::SetPointer( PointerStyle
)
372 void SvpSalFrame::CaptureMouse( bool )
376 void SvpSalFrame::SetPointerPos( tools::Long
, tools::Long
)
380 void SvpSalFrame::Flush()
384 void SvpSalFrame::SetInputContext( SalInputContext
* )
388 void SvpSalFrame::EndExtTextInput( EndExtTextInputFlags
)
392 OUString
SvpSalFrame::GetKeyName( sal_uInt16
)
397 bool SvpSalFrame::MapUnicodeToKeyCode( sal_Unicode
, LanguageType
, vcl::KeyCode
& )
402 LanguageType
SvpSalFrame::GetInputLanguage()
404 return LANGUAGE_DONTKNOW
;
407 void SvpSalFrame::UpdateSettings( AllSettings
& rSettings
)
409 StyleSettings aStyleSettings
= rSettings
.GetStyleSettings();
411 Color
aBackgroundColor( 0xef, 0xef, 0xef );
412 aStyleSettings
.BatchSetBackgrounds( aBackgroundColor
, false );
413 aStyleSettings
.SetMenuColor( aBackgroundColor
);
414 aStyleSettings
.SetMenuBarColor( aBackgroundColor
);
416 if (comphelper::LibreOfficeKit::isActive()) // TODO: remove this.
418 vcl::Font
aStdFont( FAMILY_SWISS
, Size( 0, 14 ) );
419 aStdFont
.SetCharSet( osl_getThreadTextEncoding() );
420 aStdFont
.SetWeight( WEIGHT_NORMAL
);
421 aStdFont
.SetFamilyName( "Liberation Sans" );
422 aStyleSettings
.BatchSetFonts( aStdFont
, aStdFont
);
424 aStdFont
.SetFontSize(Size(0, 12));
425 aStyleSettings
.SetMenuFont(aStdFont
);
427 SvpSalGraphics
* pGraphics
= m_aGraphics
.empty() ? nullptr : m_aGraphics
.back();
428 bool bFreeGraphics
= false;
431 pGraphics
= dynamic_cast<SvpSalGraphics
*>(AcquireGraphics());
434 SAL_WARN("vcl.gtk3", "Could not get graphics - unable to update settings");
437 bFreeGraphics
= true;
439 rSettings
.SetStyleSettings(aStyleSettings
);
440 #ifndef IOS // For now...
441 pGraphics
->UpdateSettings(rSettings
);
444 ReleaseGraphics(pGraphics
);
447 rSettings
.SetStyleSettings(aStyleSettings
);
450 void SvpSalFrame::Beep()
454 const SystemEnvData
* SvpSalFrame::GetSystemData() const
456 return &m_aSystemChildData
;
459 SalFrame::SalPointerState
SvpSalFrame::GetPointerState()
461 SalPointerState aState
;
466 KeyIndicatorState
SvpSalFrame::GetIndicatorState()
468 return KeyIndicatorState::NONE
;
471 void SvpSalFrame::SimulateKeyPress( sal_uInt16
/*nKeyCode*/ )
475 void SvpSalFrame::SetParent( SalFrame
* pNewParent
)
478 m_pParent
->m_aChildren
.erase(std::remove(m_pParent
->m_aChildren
.begin(), m_pParent
->m_aChildren
.end(), this), m_pParent
->m_aChildren
.end());
479 m_pParent
= static_cast<SvpSalFrame
*>(pNewParent
);
482 void SvpSalFrame::SetPluginParent( SystemParentData
* )
486 void SvpSalFrame::ResetClipRegion()
490 void SvpSalFrame::BeginSetClipRegion( sal_uInt32
)
494 void SvpSalFrame::UnionClipRegion( tools::Long
, tools::Long
, tools::Long
, tools::Long
)
498 void SvpSalFrame::EndSetClipRegion()
502 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */