Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / vcl / headless / svpframe.cxx
blob724220ad60a9a32fe35ca7006eb788a58c5fbc0e
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 <string.h>
22 #include <comphelper/lok.hxx>
23 #include <vcl/syswin.hxx>
25 #include <headless/svpframe.hxx>
26 #include <headless/svpinst.hxx>
27 #include <headless/svpgdi.hxx>
29 #include <basegfx/vector/b2ivector.hxx>
31 #ifndef IOS
32 #include <cairo.h>
33 #endif
35 SvpSalFrame* SvpSalFrame::s_pFocusFrame = nullptr;
37 #ifdef IOS
38 #define SvpSalGraphics AquaSalGraphics
39 #endif
41 SvpSalFrame::SvpSalFrame( SvpSalInstance* pInstance,
42 SalFrame* pParent,
43 SalFrameStyleFlags nSalFrameStyle ) :
44 m_pInstance( pInstance ),
45 m_pParent( static_cast<SvpSalFrame*>(pParent) ),
46 m_nStyle( nSalFrameStyle ),
47 m_bVisible( false ),
48 #ifndef IOS
49 m_pSurface( nullptr ),
50 #endif
51 m_nMinWidth( 0 ),
52 m_nMinHeight( 0 ),
53 m_nMaxWidth( 0 ),
54 m_nMaxHeight( 0 )
56 // SAL_DEBUG("SvpSalFrame::SvpSalFrame: " << this);
57 // fast and easy cross-platform wiping of the data
58 memset( static_cast<void *>(&m_aSystemChildData), 0, sizeof( SystemEnvData ) );
59 m_aSystemChildData.nSize = sizeof( SystemEnvData );
60 #ifdef IOS
61 // Nothing
62 #elif defined ANDROID
63 // Nothing
64 #else
65 m_aSystemChildData.pSalFrame = this;
66 #endif
68 if( m_pParent )
69 m_pParent->m_aChildren.push_back( this );
71 if( m_pInstance )
72 m_pInstance->registerFrame( this );
74 SetPosSize( 0, 0, 800, 600, SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT );
77 SvpSalFrame::~SvpSalFrame()
79 if( m_pInstance )
80 m_pInstance->deregisterFrame( this );
82 std::list<SvpSalFrame*> Children = m_aChildren;
83 for( std::list<SvpSalFrame*>::iterator it = Children.begin();
84 it != Children.end(); ++it )
85 (*it)->SetParent( m_pParent );
86 if( m_pParent )
87 m_pParent->m_aChildren.remove( this );
89 if( s_pFocusFrame == this )
91 // SAL_DEBUG("SvpSalFrame::~SvpSalFrame: losing focus: " << this);
92 s_pFocusFrame = nullptr;
93 // call directly here, else an event for a destroyed frame would be dispatched
94 CallCallback( SalEvent::LoseFocus, nullptr );
95 // if the handler has not set a new focus frame
96 // pass focus to another frame, preferably a document style window
97 if( s_pFocusFrame == nullptr )
99 for (auto pSalFrame : m_pInstance->getFrames() )
101 SvpSalFrame* pFrame = static_cast<SvpSalFrame*>( pSalFrame );
102 if( pFrame->m_bVisible &&
103 pFrame->m_pParent == nullptr &&
104 (pFrame->m_nStyle & (SalFrameStyleFlags::MOVEABLE |
105 SalFrameStyleFlags::SIZEABLE |
106 SalFrameStyleFlags::CLOSEABLE) )
109 pFrame->GetFocus();
110 break;
115 #ifndef IOS
116 if (m_pSurface)
117 cairo_surface_destroy(m_pSurface);
118 #endif
121 void SvpSalFrame::GetFocus()
123 if( s_pFocusFrame == this )
124 return;
126 if( (m_nStyle & (SalFrameStyleFlags::OWNERDRAWDECORATION | SalFrameStyleFlags::FLOAT)) == SalFrameStyleFlags::NONE )
128 if( s_pFocusFrame )
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();
149 #ifndef IOS
150 pGraphics->setSurface(m_pSurface, basegfx::B2IVector(maGeometry.nWidth, maGeometry.nHeight));
151 #endif
152 m_aGraphics.push_back( pGraphics );
153 return pGraphics;
156 void SvpSalFrame::ReleaseGraphics( SalGraphics* pGraphics )
158 SvpSalGraphics* pSvpGraphics = dynamic_cast<SvpSalGraphics*>(pGraphics);
159 m_aGraphics.erase(std::remove(m_aGraphics.begin(), m_aGraphics.end(), pSvpGraphics), m_aGraphics.end());
160 delete pSvpGraphics;
163 bool SvpSalFrame::PostEvent(ImplSVEvent* pData)
165 m_pInstance->PostEvent( this, pData, SalEvent::UserEvent );
166 return true;
169 void SvpSalFrame::PostPaint() const
171 if( m_bVisible )
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);
204 m_bVisible = true;
205 m_pInstance->PostEvent( this, nullptr, SalEvent::Resize );
206 if( ! bNoActivate )
207 GetFocus();
209 else if( ! bVisible && m_bVisible )
211 // SAL_DEBUG("SvpSalFrame::Show: hiding: " << this);
212 m_bVisible = false;
213 m_pInstance->PostEvent( this, nullptr, SalEvent::Resize );
214 LoseFocus();
216 else
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 )
237 maGeometry.nX = nX;
238 if( (nFlags & SAL_FRAME_POSSIZE_Y) != 0 )
239 maGeometry.nY = nY;
240 if( (nFlags & SAL_FRAME_POSSIZE_WIDTH) != 0 )
242 maGeometry.nWidth = nWidth;
243 if( m_nMaxWidth > 0 && maGeometry.nWidth > static_cast<unsigned int>(m_nMaxWidth) )
244 maGeometry.nWidth = m_nMaxWidth;
245 if( m_nMinWidth > 0 && maGeometry.nWidth < static_cast<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 > static_cast<unsigned int>(m_nMaxHeight) )
252 maGeometry.nHeight = m_nMaxHeight;
253 if( m_nMinHeight > 0 && maGeometry.nHeight < static_cast<unsigned int>(m_nMinHeight) )
254 maGeometry.nHeight = m_nMinHeight;
256 #ifndef IOS
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 );
266 if (m_pSurface)
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,
274 aFrameSize.getX(),
275 aFrameSize.getY());
277 // update device in existing graphics
278 for (auto const& graphic : m_aGraphics)
280 graphic->setSurface(m_pSurface, aFrameSize);
283 if( m_bVisible )
284 m_pInstance->PostEvent( this, nullptr, SalEvent::Resize );
285 #endif
288 void SvpSalFrame::GetClientSize( long& rWidth, long& rHeight )
290 rWidth = maGeometry.nWidth;
291 rHeight = maGeometry.nHeight;
294 void SvpSalFrame::GetWorkArea( tools::Rectangle& rRect )
296 rRect = tools::Rectangle( Point( 0, 0 ),
297 Size( VIRTUAL_DESKTOP_WIDTH, VIRTUAL_DESKTOP_HEIGHT ) );
300 SalFrame* SvpSalFrame::GetParent() const
302 return m_pParent;
305 #define FRAMESTATE_MASK_GEOMETRY \
306 (WindowStateMask::X | WindowStateMask::Y | \
307 WindowStateMask::Width | WindowStateMask::Height)
309 void SvpSalFrame::SetWindowState( const SalFrameState *pState )
311 if (pState == nullptr)
312 return;
314 // Request for position or size change
315 if (pState->mnMask & FRAMESTATE_MASK_GEOMETRY)
317 long nX = maGeometry.nX;
318 long nY = maGeometry.nY;
319 long nWidth = maGeometry.nWidth;
320 long nHeight = maGeometry.nHeight;
322 // change requested properties
323 if (pState->mnMask & WindowStateMask::X)
324 nX = pState->mnX;
325 if (pState->mnMask & WindowStateMask::Y)
326 nY = pState->mnY;
327 if (pState->mnMask & WindowStateMask::Width)
328 nWidth = pState->mnWidth;
329 if (pState->mnMask & WindowStateMask::Height)
330 nHeight = pState->mnHeight;
332 SetPosSize( nX, nY, nWidth, nHeight,
333 SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y |
334 SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT );
338 bool SvpSalFrame::GetWindowState( SalFrameState* pState )
340 pState->mnState = WindowStateState::Normal;
341 pState->mnX = maGeometry.nX;
342 pState->mnY = maGeometry.nY;
343 pState->mnWidth = maGeometry.nWidth;
344 pState->mnHeight = maGeometry.nHeight;
345 pState->mnMask = FRAMESTATE_MASK_GEOMETRY | WindowStateMask::State;
347 return true;
350 void SvpSalFrame::ShowFullScreen( bool, sal_Int32 )
352 SetPosSize( 0, 0, VIRTUAL_DESKTOP_WIDTH, VIRTUAL_DESKTOP_HEIGHT,
353 SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT );
356 void SvpSalFrame::StartPresentation( bool )
360 void SvpSalFrame::SetAlwaysOnTop( bool )
364 void SvpSalFrame::ToTop( SalFrameToTop )
366 GetFocus();
369 void SvpSalFrame::SetPointer( PointerStyle )
373 void SvpSalFrame::CaptureMouse( bool )
377 void SvpSalFrame::SetPointerPos( long, long )
381 void SvpSalFrame::Flush()
385 void SvpSalFrame::SetInputContext( SalInputContext* )
389 void SvpSalFrame::EndExtTextInput( EndExtTextInputFlags )
393 OUString SvpSalFrame::GetKeyName( sal_uInt16 )
395 return OUString();
398 bool SvpSalFrame::MapUnicodeToKeyCode( sal_Unicode, LanguageType, vcl::KeyCode& )
400 return false;
403 LanguageType SvpSalFrame::GetInputLanguage()
405 return LANGUAGE_DONTKNOW;
408 void SvpSalFrame::UpdateSettings( AllSettings& rSettings )
410 StyleSettings aStyleSettings = rSettings.GetStyleSettings();
412 Color aBackgroundColor( 0xef, 0xef, 0xef );
413 aStyleSettings.BatchSetBackgrounds( aBackgroundColor, false );
414 aStyleSettings.SetMenuColor( aBackgroundColor );
415 aStyleSettings.SetMenuBarColor( aBackgroundColor );
417 if (comphelper::LibreOfficeKit::isActive()) // TODO: remove this.
419 vcl::Font aStdFont( FAMILY_SWISS, Size( 0, 14 ) );
420 aStdFont.SetCharSet( osl_getThreadTextEncoding() );
421 aStdFont.SetWeight( WEIGHT_NORMAL );
422 aStdFont.SetFamilyName( "Liberation Sans" );
423 aStyleSettings.BatchSetFonts( aStdFont, aStdFont );
425 aStdFont.SetFontSize(Size(0, 12));
426 aStyleSettings.SetMenuFont(aStdFont);
429 rSettings.SetStyleSettings( aStyleSettings );
432 void SvpSalFrame::Beep()
436 const SystemEnvData* SvpSalFrame::GetSystemData() const
438 return &m_aSystemChildData;
441 SalFrame::SalPointerState SvpSalFrame::GetPointerState()
443 SalPointerState aState;
444 aState.mnState = 0;
445 return aState;
448 KeyIndicatorState SvpSalFrame::GetIndicatorState()
450 return KeyIndicatorState::NONE;
453 void SvpSalFrame::SimulateKeyPress( sal_uInt16 /*nKeyCode*/ )
457 void SvpSalFrame::SetParent( SalFrame* pNewParent )
459 if( m_pParent )
460 m_pParent->m_aChildren.remove( this );
461 m_pParent = static_cast<SvpSalFrame*>(pNewParent);
464 bool SvpSalFrame::SetPluginParent( SystemParentData* )
466 return true;
469 void SvpSalFrame::ResetClipRegion()
473 void SvpSalFrame::BeginSetClipRegion( sal_uLong )
477 void SvpSalFrame::UnionClipRegion( long, long, long, long )
481 void SvpSalFrame::EndSetClipRegion()
485 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */