bump product version to 7.6.3.2-android
[LibreOffice.git] / vcl / headless / svpframe.cxx
blob5c6a713572d24d1710c956ece3ac0c4e0cade2c1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
27 #ifndef IOS
28 #include <headless/svpgdi.hxx>
29 #endif
30 #include <salsys.hxx>
32 #include <basegfx/vector/b2ivector.hxx>
34 #ifndef IOS
35 #include <cairo.h>
36 #endif
38 SvpSalFrame* SvpSalFrame::s_pFocusFrame = nullptr;
40 #ifdef IOS
41 #define SvpSalGraphics AquaSalGraphics
42 #endif
44 SvpSalFrame::SvpSalFrame( SvpSalInstance* pInstance,
45 SalFrame* pParent,
46 SalFrameStyleFlags nSalFrameStyle ) :
47 m_pInstance( pInstance ),
48 m_pParent( static_cast<SvpSalFrame*>(pParent) ),
49 m_nStyle( nSalFrameStyle ),
50 m_bVisible( false ),
51 #ifndef IOS
52 m_pSurface( nullptr ),
53 #endif
54 m_nMinWidth( 0 ),
55 m_nMinHeight( 0 ),
56 m_nMaxWidth( 0 ),
57 m_nMaxHeight( 0 )
59 #ifdef IOS
60 // Nothing
61 #elif defined ANDROID
62 // Nothing
63 #else
64 m_aSystemChildData.pSalFrame = this;
65 #endif
67 if( m_pParent )
68 m_pParent->m_aChildren.push_back( this );
70 if( m_pInstance )
71 m_pInstance->registerFrame( this );
73 SetPosSize( 0, 0, 800, 600, SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT );
76 SvpSalFrame::~SvpSalFrame()
78 if( m_pInstance )
79 m_pInstance->deregisterFrame( this );
81 std::vector<SvpSalFrame*> Children = m_aChildren;
82 for( auto& rChild : Children )
83 rChild->SetParent( m_pParent );
84 if( 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) )
106 pFrame->GetFocus();
107 break;
112 #ifndef IOS
113 if (m_pSurface)
114 cairo_surface_destroy(m_pSurface);
115 #endif
118 void SvpSalFrame::GetFocus()
120 if (m_nStyle == SalFrameStyleFlags::NONE)
121 return;
122 if( s_pFocusFrame == this )
123 return;
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 )
129 if( s_pFocusFrame )
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 );
155 return aFrameSize;
158 SalGraphics* SvpSalFrame::AcquireGraphics()
160 SvpSalGraphics* pGraphics = new SvpSalGraphics();
161 #ifndef IOS
162 pGraphics->setSurface(m_pSurface, GetSurfaceFrameSize());
163 #endif
164 m_aGraphics.push_back( pGraphics );
165 return 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());
172 delete pSvpGraphics;
175 bool SvpSalFrame::PostEvent(std::unique_ptr<ImplSVEvent> pData)
177 m_pInstance->PostEvent( this, pData.release(), SalEvent::UserEvent );
178 return true;
181 void SvpSalFrame::PostPaint() const
183 if( m_bVisible )
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)
193 m_sTitle = 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)
211 return;
212 if (bVisible == m_bVisible)
214 if (m_bVisible && !bNoActivate)
215 GetFocus();
216 return;
219 if (bVisible)
221 m_bVisible = true;
222 m_pInstance->PostEvent( this, nullptr, SalEvent::Resize );
223 if( ! bNoActivate )
224 GetFocus();
226 else
228 m_bVisible = false;
229 LoseFocus();
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 )
248 maGeometry.setX(nX);
249 if( (nFlags & SAL_FRAME_POSSIZE_Y) != 0 )
250 maGeometry.setY(nY);
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);
267 #ifndef IOS
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() )
272 if (m_pSurface)
273 cairo_surface_destroy(m_pSurface);
275 m_pSurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
276 aFrameSize.getX(),
277 aFrameSize.getY());
279 // update device in existing graphics
280 for (auto const& graphic : m_aGraphics)
282 graphic->setSurface(m_pSurface, aFrameSize);
285 if( m_bVisible )
286 m_pInstance->PostEvent( this, nullptr, SalEvent::Resize );
287 #endif
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
304 return m_pParent;
307 void SvpSalFrame::SetWindowState(const vcl::WindowData *pState)
309 if (pState == nullptr)
310 return;
312 // Request for position or size change
313 if (!(pState->mask() & vcl::WindowDataMask::PosSize))
314 return;
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)
323 nX = pState->x();
324 if (pState->mask() & vcl::WindowDataMask::Y)
325 nY = pState->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);
341 return true;
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)
361 return;
362 if (nFlags & SalFrameToTop::RestoreWhenMin)
363 Show(true, false);
364 else
365 GetFocus();
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 )
394 return OUString();
397 bool SvpSalFrame::MapUnicodeToKeyCode( sal_Unicode, LanguageType, vcl::KeyCode& )
399 return false;
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;
429 if (!pGraphics)
431 pGraphics = dynamic_cast<SvpSalGraphics*>(AcquireGraphics());
432 if (!pGraphics)
434 SAL_WARN("vcl.gtk3", "Could not get graphics - unable to update settings");
435 return;
437 bFreeGraphics = true;
439 rSettings.SetStyleSettings(aStyleSettings);
440 #ifndef IOS // For now...
441 pGraphics->UpdateSettings(rSettings);
442 #endif
443 if (bFreeGraphics)
444 ReleaseGraphics(pGraphics);
446 else
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;
462 aState.mnState = 0;
463 return aState;
466 KeyIndicatorState SvpSalFrame::GetIndicatorState()
468 return KeyIndicatorState::NONE;
471 void SvpSalFrame::SimulateKeyPress( sal_uInt16 /*nKeyCode*/ )
475 void SvpSalFrame::SetParent( SalFrame* pNewParent )
477 if( m_pParent )
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: */