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>
25 #include <headless/svpframe.hxx>
26 #include <headless/svpinst.hxx>
27 #include <headless/svpgdi.hxx>
29 #include <basegfx/vector/b2ivector.hxx>
35 SvpSalFrame
* SvpSalFrame::s_pFocusFrame
= nullptr;
38 #define SvpSalGraphics AquaSalGraphics
41 SvpSalFrame::SvpSalFrame( SvpSalInstance
* pInstance
,
43 SalFrameStyleFlags nSalFrameStyle
) :
44 m_pInstance( pInstance
),
45 m_pParent( static_cast<SvpSalFrame
*>(pParent
) ),
46 m_nStyle( nSalFrameStyle
),
49 m_pSurface( nullptr ),
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
);
65 m_aSystemChildData
.pSalFrame
= this;
69 m_pParent
->m_aChildren
.push_back( this );
72 m_pInstance
->registerFrame( this );
74 SetPosSize( 0, 0, 800, 600, SAL_FRAME_POSSIZE_WIDTH
| SAL_FRAME_POSSIZE_HEIGHT
);
77 SvpSalFrame::~SvpSalFrame()
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
);
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
) )
117 cairo_surface_destroy(m_pSurface
);
121 void SvpSalFrame::GetFocus()
123 if( s_pFocusFrame
== this )
126 if( (m_nStyle
& (SalFrameStyleFlags::OWNERDRAWDECORATION
| SalFrameStyleFlags::FLOAT
)) == SalFrameStyleFlags::NONE
)
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();
150 pGraphics
->setSurface(m_pSurface
, basegfx::B2IVector(maGeometry
.nWidth
, maGeometry
.nHeight
));
152 m_aGraphics
.push_back( 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());
163 bool SvpSalFrame::PostEvent(ImplSVEvent
* pData
)
165 m_pInstance
->PostEvent( this, pData
, SalEvent::UserEvent
);
169 void SvpSalFrame::PostPaint() const
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);
205 m_pInstance
->PostEvent( this, nullptr, SalEvent::Resize
);
209 else if( ! bVisible
&& m_bVisible
)
211 // SAL_DEBUG("SvpSalFrame::Show: hiding: " << this);
213 m_pInstance
->PostEvent( this, nullptr, SalEvent::Resize
);
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 )
238 if( (nFlags
& SAL_FRAME_POSSIZE_Y
) != 0 )
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
;
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 );
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
,
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( 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
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)
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
)
325 if (pState
->mnMask
& WindowStateMask::Y
)
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
;
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
)
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
)
398 bool SvpSalFrame::MapUnicodeToKeyCode( sal_Unicode
, LanguageType
, vcl::KeyCode
& )
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
;
448 KeyIndicatorState
SvpSalFrame::GetIndicatorState()
450 return KeyIndicatorState::NONE
;
453 void SvpSalFrame::SimulateKeyPress( sal_uInt16
/*nKeyCode*/ )
457 void SvpSalFrame::SetParent( SalFrame
* pNewParent
)
460 m_pParent
->m_aChildren
.remove( this );
461 m_pParent
= static_cast<SvpSalFrame
*>(pNewParent
);
464 bool SvpSalFrame::SetPluginParent( SystemParentData
* )
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: */