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 .
22 #include <comphelper/lok.hxx>
23 #include <vcl/syswin.hxx>
24 #include <sal/log.hxx>
26 #include <headless/svpframe.hxx>
27 #include <headless/svpinst.hxx>
29 #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 ),
59 // SAL_DEBUG("SvpSalFrame::SvpSalFrame: " << this);
60 // fast and easy cross-platform wiping of the data
61 memset( static_cast<void *>(&m_aSystemChildData
), 0, sizeof( SystemEnvData
) );
62 m_aSystemChildData
.nSize
= sizeof( SystemEnvData
);
68 m_aSystemChildData
.pSalFrame
= this;
72 m_pParent
->m_aChildren
.push_back( this );
75 m_pInstance
->registerFrame( this );
77 SetPosSize( 0, 0, 800, 600, SAL_FRAME_POSSIZE_WIDTH
| SAL_FRAME_POSSIZE_HEIGHT
);
80 SvpSalFrame::~SvpSalFrame()
83 m_pInstance
->deregisterFrame( this );
85 std::list
<SvpSalFrame
*> Children
= m_aChildren
;
86 for( auto& rChild
: Children
)
87 rChild
->SetParent( m_pParent
);
89 m_pParent
->m_aChildren
.remove( this );
91 if( s_pFocusFrame
== this )
93 // SAL_DEBUG("SvpSalFrame::~SvpSalFrame: losing focus: " << this);
94 s_pFocusFrame
= nullptr;
95 // call directly here, else an event for a destroyed frame would be dispatched
96 CallCallback( SalEvent::LoseFocus
, nullptr );
97 // if the handler has not set a new focus frame
98 // pass focus to another frame, preferably a document style window
99 if( s_pFocusFrame
== nullptr )
101 for (auto pSalFrame
: m_pInstance
->getFrames() )
103 SvpSalFrame
* pFrame
= static_cast<SvpSalFrame
*>( pSalFrame
);
104 if( pFrame
->m_bVisible
&&
105 pFrame
->m_pParent
== nullptr &&
106 (pFrame
->m_nStyle
& (SalFrameStyleFlags::MOVEABLE
|
107 SalFrameStyleFlags::SIZEABLE
|
108 SalFrameStyleFlags::CLOSEABLE
) )
119 cairo_surface_destroy(m_pSurface
);
123 void SvpSalFrame::GetFocus()
125 if( s_pFocusFrame
== this )
128 if( (m_nStyle
& (SalFrameStyleFlags::OWNERDRAWDECORATION
| SalFrameStyleFlags::FLOAT
)) == SalFrameStyleFlags::NONE
)
131 s_pFocusFrame
->LoseFocus();
132 // SAL_DEBUG("SvpSalFrame::GetFocus(): " << this);
133 s_pFocusFrame
= this;
134 m_pInstance
->PostEvent( this, nullptr, SalEvent::GetFocus
);
138 void SvpSalFrame::LoseFocus()
140 if( s_pFocusFrame
== this )
142 // SAL_DEBUG("SvpSalFrame::LoseFocus: " << this);
143 m_pInstance
->PostEvent( this, nullptr, SalEvent::LoseFocus
);
144 s_pFocusFrame
= nullptr;
148 SalGraphics
* SvpSalFrame::AcquireGraphics()
150 SvpSalGraphics
* pGraphics
= new SvpSalGraphics();
152 pGraphics
->setSurface(m_pSurface
, basegfx::B2IVector(maGeometry
.nWidth
, maGeometry
.nHeight
));
154 m_aGraphics
.push_back( pGraphics
);
158 void SvpSalFrame::ReleaseGraphics( SalGraphics
* pGraphics
)
160 SvpSalGraphics
* pSvpGraphics
= dynamic_cast<SvpSalGraphics
*>(pGraphics
);
161 m_aGraphics
.erase(std::remove(m_aGraphics
.begin(), m_aGraphics
.end(), pSvpGraphics
), m_aGraphics
.end());
165 bool SvpSalFrame::PostEvent(std::unique_ptr
<ImplSVEvent
> pData
)
167 m_pInstance
->PostEvent( this, pData
.release(), SalEvent::UserEvent
);
171 void SvpSalFrame::PostPaint() const
175 SalPaintEvent
aPEvt(0, 0, maGeometry
.nWidth
, maGeometry
.nHeight
);
176 aPEvt
.mbImmediateUpdate
= false;
177 CallCallback( SalEvent::Paint
, &aPEvt
);
181 void SvpSalFrame::SetTitle( const OUString
& )
185 void SvpSalFrame::SetIcon( sal_uInt16
)
189 void SvpSalFrame::SetMenu( SalMenu
* )
193 void SvpSalFrame::DrawMenuBar()
197 void SvpSalFrame::SetExtendedFrameStyle( SalExtStyle
)
201 void SvpSalFrame::Show( bool bVisible
, bool bNoActivate
)
203 if( bVisible
&& ! m_bVisible
)
205 // SAL_DEBUG("SvpSalFrame::Show: showing: " << this);
207 m_pInstance
->PostEvent( this, nullptr, SalEvent::Resize
);
211 else if( ! bVisible
&& m_bVisible
)
213 // SAL_DEBUG("SvpSalFrame::Show: hiding: " << this);
215 m_pInstance
->PostEvent( this, nullptr, SalEvent::Resize
);
220 // SAL_DEBUG("SvpSalFrame::Show: nothing: " << this);
224 void SvpSalFrame::SetMinClientSize( long nWidth
, long nHeight
)
226 m_nMinWidth
= nWidth
;
227 m_nMinHeight
= nHeight
;
230 void SvpSalFrame::SetMaxClientSize( long nWidth
, long nHeight
)
232 m_nMaxWidth
= nWidth
;
233 m_nMaxHeight
= nHeight
;
236 void SvpSalFrame::SetPosSize( long nX
, long nY
, long nWidth
, long nHeight
, sal_uInt16 nFlags
)
238 if( (nFlags
& SAL_FRAME_POSSIZE_X
) != 0 )
240 if( (nFlags
& SAL_FRAME_POSSIZE_Y
) != 0 )
242 if( (nFlags
& SAL_FRAME_POSSIZE_WIDTH
) != 0 )
244 maGeometry
.nWidth
= nWidth
;
245 if( m_nMaxWidth
> 0 && maGeometry
.nWidth
> static_cast<unsigned int>(m_nMaxWidth
) )
246 maGeometry
.nWidth
= m_nMaxWidth
;
247 if( m_nMinWidth
> 0 && maGeometry
.nWidth
< static_cast<unsigned int>(m_nMinWidth
) )
248 maGeometry
.nWidth
= m_nMinWidth
;
250 if( (nFlags
& SAL_FRAME_POSSIZE_HEIGHT
) != 0 )
252 maGeometry
.nHeight
= nHeight
;
253 if( m_nMaxHeight
> 0 && maGeometry
.nHeight
> static_cast<unsigned int>(m_nMaxHeight
) )
254 maGeometry
.nHeight
= m_nMaxHeight
;
255 if( m_nMinHeight
> 0 && maGeometry
.nHeight
< static_cast<unsigned int>(m_nMinHeight
) )
256 maGeometry
.nHeight
= m_nMinHeight
;
259 basegfx::B2IVector
aFrameSize( maGeometry
.nWidth
, maGeometry
.nHeight
);
260 if (!m_pSurface
|| cairo_image_surface_get_width(m_pSurface
) != aFrameSize
.getX() ||
261 cairo_image_surface_get_height(m_pSurface
) != aFrameSize
.getY() )
263 if( aFrameSize
.getX() == 0 )
264 aFrameSize
.setX( 1 );
265 if( aFrameSize
.getY() == 0 )
266 aFrameSize
.setY( 1 );
269 cairo_surface_destroy(m_pSurface
);
271 // Creating backing surfaces for invisible windows costs a big chunk of RAM.
272 if (Application::IsHeadlessModeEnabled())
273 aFrameSize
= basegfx::B2IVector( 1, 1 );
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( long& rWidth
, long& rHeight
)
292 rWidth
= maGeometry
.nWidth
;
293 rHeight
= maGeometry
.nHeight
;
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 static constexpr auto FRAMESTATE_MASK_GEOMETRY
=
308 WindowStateMask::X
| WindowStateMask::Y
|
309 WindowStateMask::Width
| WindowStateMask::Height
;
311 void SvpSalFrame::SetWindowState( const SalFrameState
*pState
)
313 if (pState
== nullptr)
316 // Request for position or size change
317 if (pState
->mnMask
& FRAMESTATE_MASK_GEOMETRY
)
319 long nX
= maGeometry
.nX
;
320 long nY
= maGeometry
.nY
;
321 long nWidth
= maGeometry
.nWidth
;
322 long nHeight
= maGeometry
.nHeight
;
324 // change requested properties
325 if (pState
->mnMask
& WindowStateMask::X
)
327 if (pState
->mnMask
& WindowStateMask::Y
)
329 if (pState
->mnMask
& WindowStateMask::Width
)
330 nWidth
= pState
->mnWidth
;
331 if (pState
->mnMask
& WindowStateMask::Height
)
332 nHeight
= pState
->mnHeight
;
334 SetPosSize( nX
, nY
, nWidth
, nHeight
,
335 SAL_FRAME_POSSIZE_X
| SAL_FRAME_POSSIZE_Y
|
336 SAL_FRAME_POSSIZE_WIDTH
| SAL_FRAME_POSSIZE_HEIGHT
);
340 bool SvpSalFrame::GetWindowState( SalFrameState
* pState
)
342 pState
->mnState
= WindowStateState::Normal
;
343 pState
->mnX
= maGeometry
.nX
;
344 pState
->mnY
= maGeometry
.nY
;
345 pState
->mnWidth
= maGeometry
.nWidth
;
346 pState
->mnHeight
= maGeometry
.nHeight
;
347 pState
->mnMask
= FRAMESTATE_MASK_GEOMETRY
| WindowStateMask::State
;
352 void SvpSalFrame::ShowFullScreen( bool, sal_Int32
)
354 SetPosSize( 0, 0, VIRTUAL_DESKTOP_WIDTH
, VIRTUAL_DESKTOP_HEIGHT
,
355 SAL_FRAME_POSSIZE_WIDTH
| SAL_FRAME_POSSIZE_HEIGHT
);
358 void SvpSalFrame::StartPresentation( bool )
362 void SvpSalFrame::SetAlwaysOnTop( bool )
366 void SvpSalFrame::ToTop( SalFrameToTop
)
371 void SvpSalFrame::SetPointer( PointerStyle
)
375 void SvpSalFrame::CaptureMouse( bool )
379 void SvpSalFrame::SetPointerPos( long, long )
383 void SvpSalFrame::Flush()
387 void SvpSalFrame::SetInputContext( SalInputContext
* )
391 void SvpSalFrame::EndExtTextInput( EndExtTextInputFlags
)
395 OUString
SvpSalFrame::GetKeyName( sal_uInt16
)
400 bool SvpSalFrame::MapUnicodeToKeyCode( sal_Unicode
, LanguageType
, vcl::KeyCode
& )
405 LanguageType
SvpSalFrame::GetInputLanguage()
407 return LANGUAGE_DONTKNOW
;
410 void SvpSalFrame::UpdateSettings( AllSettings
& rSettings
)
412 StyleSettings aStyleSettings
= rSettings
.GetStyleSettings();
414 Color
aBackgroundColor( 0xef, 0xef, 0xef );
415 aStyleSettings
.BatchSetBackgrounds( aBackgroundColor
, false );
416 aStyleSettings
.SetMenuColor( aBackgroundColor
);
417 aStyleSettings
.SetMenuBarColor( aBackgroundColor
);
419 if (comphelper::LibreOfficeKit::isActive()) // TODO: remove this.
421 vcl::Font
aStdFont( FAMILY_SWISS
, Size( 0, 14 ) );
422 aStdFont
.SetCharSet( osl_getThreadTextEncoding() );
423 aStdFont
.SetWeight( WEIGHT_NORMAL
);
424 aStdFont
.SetFamilyName( "Liberation Sans" );
425 aStyleSettings
.BatchSetFonts( aStdFont
, aStdFont
);
427 aStdFont
.SetFontSize(Size(0, 12));
428 aStyleSettings
.SetMenuFont(aStdFont
);
430 SvpSalGraphics
* pGraphics
= m_aGraphics
.back();
431 bool bFreeGraphics
= false;
434 pGraphics
= dynamic_cast<SvpSalGraphics
*>(AcquireGraphics());
437 SAL_WARN("vcl.gtk3", "Could not get graphics - unable to update settings");
440 bFreeGraphics
= true;
442 rSettings
.SetStyleSettings(aStyleSettings
);
443 #ifndef IOS // For now...
444 pGraphics
->updateSettings(rSettings
);
447 ReleaseGraphics(pGraphics
);
450 rSettings
.SetStyleSettings(aStyleSettings
);
453 void SvpSalFrame::Beep()
457 const SystemEnvData
* SvpSalFrame::GetSystemData() const
459 return &m_aSystemChildData
;
462 SalFrame::SalPointerState
SvpSalFrame::GetPointerState()
464 SalPointerState aState
;
469 KeyIndicatorState
SvpSalFrame::GetIndicatorState()
471 return KeyIndicatorState::NONE
;
474 void SvpSalFrame::SimulateKeyPress( sal_uInt16
/*nKeyCode*/ )
478 void SvpSalFrame::SetParent( SalFrame
* pNewParent
)
481 m_pParent
->m_aChildren
.remove( this );
482 m_pParent
= static_cast<SvpSalFrame
*>(pNewParent
);
485 bool SvpSalFrame::SetPluginParent( SystemParentData
* )
490 void SvpSalFrame::ResetClipRegion()
494 void SvpSalFrame::BeginSetClipRegion( sal_uInt32
)
498 void SvpSalFrame::UnionClipRegion( long, long, long, long )
502 void SvpSalFrame::EndSetClipRegion()
506 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */