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 <o3tl/safeint.hxx>
23 #include <sal/config.h>
24 #include <sal/log.hxx>
26 #include <vcl/layout.hxx>
27 #include <vcl/mnemonic.hxx>
28 #include <vcl/settings.hxx>
29 #include <vcl/svapp.hxx>
30 #include <vcl/menu.hxx>
31 #include <vcl/event.hxx>
32 #include <vcl/syswin.hxx>
33 #include <vcl/taskpanelist.hxx>
34 #include <vcl/tabctrl.hxx>
35 #include <vcl/tabpage.hxx>
36 #include <vcl/virdev.hxx>
38 #include <rtl/ustrbuf.hxx>
39 #include <o3tl/string_view.hxx>
42 #include <salframe.hxx>
47 using namespace ::com::sun::star::uno
;
48 using namespace ::com::sun::star::lang
;
50 class SystemWindow::ImplData
55 std::unique_ptr
<TaskPaneList
>
58 OUString maRepresentedURL
;
59 Link
<SystemWindow
&,void> maCloseHdl
;
62 SystemWindow::ImplData::ImplData()
64 mpTaskPaneList
= nullptr;
65 maMaxOutSize
= Size( SHRT_MAX
, SHRT_MAX
);
68 SystemWindow::SystemWindow(WindowType nType
, const char* pIdleDebugName
)
73 , mbIsCalculatingInitialLayoutSize(false)
74 , mbInitialLayoutSizeCalculated(false)
75 , mbPaintComplete(false)
76 , mnMenuBarMode(MenuBarMode::Normal
)
78 , mpImplData(new ImplData
)
79 , maLayoutIdle( pIdleDebugName
)
80 , mbIsDeferredInit(false)
82 mpWindowImpl
->mbSysWin
= true;
83 mpWindowImpl
->mnActivateMode
= ActivateModeFlags::GrabFocus
;
85 //To-Do, reuse maResizeTimer
86 maLayoutIdle
.SetPriority(TaskPriority::RESIZE
);
87 maLayoutIdle
.SetInvokeHandler( LINK( this, SystemWindow
, ImplHandleLayoutTimerHdl
) );
90 void SystemWindow::loadUI(vcl::Window
* pParent
, const OUString
& rID
, const OUString
& rUIXMLDescription
,
91 const css::uno::Reference
<css::frame::XFrame
> &rFrame
)
93 mbIsDeferredInit
= true;
94 mpDialogParent
= pParent
; //should be unset in doDeferredInit
95 m_pUIBuilder
.reset( new VclBuilder(this, AllSettings::GetUIRootDir(), rUIXMLDescription
, rID
, rFrame
) );
98 SystemWindow::~SystemWindow()
103 void SystemWindow::dispose()
108 // Hack to make sure code called from base ~Window does not interpret this
109 // as a SystemWindow (which it no longer is by then):
110 mpWindowImpl
->mbSysWin
= false;
112 mpDialogParent
.clear();
117 static void ImplHandleControlAccelerator( const vcl::Window
* pWindow
, bool bShow
)
119 Control
*pControl
= dynamic_cast<Control
*>(pWindow
->ImplGetWindow());
120 if (pControl
&& pControl
->GetText().indexOf('~') != -1)
122 pControl
->SetShowAccelerator( bShow
);
123 pControl
->Invalidate(InvalidateFlags::Update
);
129 void processChildren(const vcl::Window
*pParent
, bool bShowAccel
)
131 // go through its children
132 vcl::Window
* pChild
= firstLogicalChildOfParent(pParent
);
135 if (pChild
->GetType() == WindowType::TABCONTROL
)
137 // find currently shown tab page
138 TabControl
* pTabControl
= static_cast<TabControl
*>(pChild
);
139 TabPage
* pTabPage
= pTabControl
->GetTabPage( pTabControl
->GetCurPageId() );
140 processChildren(pTabPage
, bShowAccel
);
142 else if (pChild
->GetType() == WindowType::TABPAGE
)
144 // bare tabpage without tabcontrol parent (options dialog)
145 processChildren(pChild
, bShowAccel
);
147 else if ((pChild
->GetStyle() & (WB_DIALOGCONTROL
| WB_NODIALOGCONTROL
)) == WB_DIALOGCONTROL
)
149 // special controls that manage their children outside of widget layout
150 processChildren(pChild
, bShowAccel
);
154 ImplHandleControlAccelerator(pChild
, bShowAccel
);
156 pChild
= nextLogicalChildOfParent(pParent
, pChild
);
163 bool ToggleMnemonicsOnHierarchy(const CommandEvent
& rCEvent
, const vcl::Window
*pWindow
)
165 if (rCEvent
.GetCommand() == CommandEventId::ModKeyChange
&& ImplGetSVData()->maNWFData
.mbAutoAccel
)
167 const CommandModKeyData
*pCData
= rCEvent
.GetModKeyData();
168 const bool bShowAccel
= pCData
&& pCData
->IsMod2() && pCData
->IsDown();
169 processChildren(pWindow
, bShowAccel
);
176 bool SystemWindow::EventNotify( NotifyEvent
& rNEvt
)
178 if (rNEvt
.GetType() == NotifyEventType::COMMAND
)
179 ToggleMnemonicsOnHierarchy(*rNEvt
.GetCommandEvent(), this);
181 // capture KeyEvents for menu handling
182 if (rNEvt
.GetType() == NotifyEventType::KEYINPUT
)
184 MenuBar
* pMBar
= mpMenuBar
;
185 if ( !pMBar
&& ( GetType() == WindowType::FLOATINGWINDOW
) )
187 vcl::Window
* pWin
= ImplGetFrameWindow()->ImplGetWindow();
188 if( pWin
&& pWin
->IsSystemWindow() )
189 pMBar
= static_cast<SystemWindow
*>(pWin
)->GetMenuBar();
191 if (pMBar
&& pMBar
->ImplHandleKeyEvent(*rNEvt
.GetKeyEvent()))
195 return Window::EventNotify( rNEvt
);
198 bool SystemWindow::PreNotify( NotifyEvent
& rNEvt
)
200 // capture KeyEvents for taskpane cycling
201 if ( rNEvt
.GetType() == NotifyEventType::KEYINPUT
)
203 if( rNEvt
.GetKeyEvent()->GetKeyCode().GetCode() == KEY_F6
&&
204 rNEvt
.GetKeyEvent()->GetKeyCode().IsMod1() &&
205 !rNEvt
.GetKeyEvent()->GetKeyCode().IsShift() )
207 // Ctrl-F6 goes directly to the document
208 GrabFocusToDocument();
213 TaskPaneList
*pTList
= mpImplData
->mpTaskPaneList
.get();
214 if( !pTList
&& ( GetType() == WindowType::FLOATINGWINDOW
) )
216 vcl::Window
* pWin
= ImplGetFrameWindow()->ImplGetWindow();
217 if( pWin
&& pWin
->IsSystemWindow() )
218 pTList
= static_cast<SystemWindow
*>(pWin
)->mpImplData
->mpTaskPaneList
.get();
222 // search topmost system window which is the one to handle dialog/toolbar cycling
223 SystemWindow
*pSysWin
= this;
224 vcl::Window
*pWin
= this;
227 pWin
= pWin
->GetParent();
228 if( pWin
&& pWin
->IsSystemWindow() )
229 pSysWin
= static_cast<SystemWindow
*>(pWin
);
231 pTList
= pSysWin
->mpImplData
->mpTaskPaneList
.get();
233 if( pTList
&& pTList
->HandleKeyEvent( *rNEvt
.GetKeyEvent() ) )
237 return Window::PreNotify( rNEvt
);
240 TaskPaneList
* SystemWindow::GetTaskPaneList()
244 if( mpImplData
->mpTaskPaneList
)
245 return mpImplData
->mpTaskPaneList
.get();
248 mpImplData
->mpTaskPaneList
.reset( new TaskPaneList
);
249 MenuBar
* pMBar
= mpMenuBar
;
250 if ( !pMBar
&& ( GetType() == WindowType::FLOATINGWINDOW
) )
252 vcl::Window
* pWin
= ImplGetFrameWindow()->ImplGetWindow();
253 if ( pWin
&& pWin
->IsSystemWindow() )
254 pMBar
= static_cast<SystemWindow
*>(pWin
)->GetMenuBar();
257 mpImplData
->mpTaskPaneList
->AddWindow( pMBar
->ImplGetWindow() );
258 return mpImplData
->mpTaskPaneList
.get();
262 bool SystemWindow::Close()
264 VclPtr
<vcl::Window
> xWindow
= this;
265 CallEventListeners( VclEventId::WindowClose
);
266 if ( xWindow
->isDisposed() )
269 if ( mpWindowImpl
->mxWindowPeer
.is() && IsCreatedWithToolkit() )
272 // Is Window not closeable, ignore close
273 vcl::Window
* pBorderWin
= ImplGetBorderWindow();
276 nStyle
= pBorderWin
->GetStyle();
279 if ( !(nStyle
& WB_CLOSEABLE
) )
287 void SystemWindow::TitleButtonClick( TitleButton
)
291 void SystemWindow::Resizing( Size
& )
295 void SystemWindow::SetRepresentedURL( const OUString
& i_rURL
)
297 bool bChanged
= (i_rURL
!= mpImplData
->maRepresentedURL
);
298 mpImplData
->maRepresentedURL
= i_rURL
;
299 if ( !mbSysChild
&& bChanged
)
301 const vcl::Window
* pWindow
= this;
302 while ( pWindow
->mpWindowImpl
->mpBorderWindow
)
303 pWindow
= pWindow
->mpWindowImpl
->mpBorderWindow
;
305 if ( pWindow
->mpWindowImpl
->mbFrame
)
306 pWindow
->mpWindowImpl
->mpFrame
->SetRepresentedURL( i_rURL
);
310 void SystemWindow::SetIcon( sal_uInt16 nIcon
)
312 if ( mnIcon
== nIcon
)
319 const vcl::Window
* pWindow
= this;
320 while ( pWindow
->mpWindowImpl
->mpBorderWindow
)
321 pWindow
= pWindow
->mpWindowImpl
->mpBorderWindow
;
323 if ( pWindow
->mpWindowImpl
->mbFrame
)
324 pWindow
->mpWindowImpl
->mpFrame
->SetIcon( nIcon
);
328 void SystemWindow::ShowTitleButton( TitleButton nButton
, bool bVisible
)
330 if ( nButton
== TitleButton::Docking
)
332 if ( mbDockBtn
!= bVisible
)
334 mbDockBtn
= bVisible
;
335 if ( mpWindowImpl
->mpBorderWindow
)
336 static_cast<ImplBorderWindow
*>(mpWindowImpl
->mpBorderWindow
.get())->SetDockButton( bVisible
);
339 else if ( nButton
== TitleButton::Hide
)
341 if ( mbHideBtn
!= bVisible
)
343 mbHideBtn
= bVisible
;
344 if ( mpWindowImpl
->mpBorderWindow
)
345 static_cast<ImplBorderWindow
*>(mpWindowImpl
->mpBorderWindow
.get())->SetHideButton( bVisible
);
348 else if ( nButton
== TitleButton::Menu
)
350 if ( mpWindowImpl
->mpBorderWindow
)
351 static_cast<ImplBorderWindow
*>(mpWindowImpl
->mpBorderWindow
.get())->SetMenuButton( bVisible
);
357 bool SystemWindow::IsTitleButtonVisible( TitleButton nButton
) const
359 if ( nButton
== TitleButton::Docking
)
361 else /* if ( nButton == TitleButton::Hide ) */
365 void SystemWindow::SetMinOutputSizePixel( const Size
& rSize
)
367 maMinOutSize
= rSize
;
368 if ( mpWindowImpl
->mpBorderWindow
)
370 static_cast<ImplBorderWindow
*>(mpWindowImpl
->mpBorderWindow
.get())->SetMinOutputSize( rSize
.Width(), rSize
.Height() );
371 if ( mpWindowImpl
->mpBorderWindow
->mpWindowImpl
->mbFrame
)
372 mpWindowImpl
->mpBorderWindow
->mpWindowImpl
->mpFrame
->SetMinClientSize( rSize
.Width(), rSize
.Height() );
374 else if ( mpWindowImpl
->mbFrame
)
375 mpWindowImpl
->mpFrame
->SetMinClientSize( rSize
.Width(), rSize
.Height() );
378 void SystemWindow::SetMaxOutputSizePixel( const Size
& rSize
)
381 if( aSize
.Width() > SHRT_MAX
|| aSize
.Width() <= 0 )
382 aSize
.setWidth( SHRT_MAX
);
383 if( aSize
.Height() > SHRT_MAX
|| aSize
.Height() <= 0 )
384 aSize
.setHeight( SHRT_MAX
);
386 mpImplData
->maMaxOutSize
= aSize
;
387 if ( mpWindowImpl
->mpBorderWindow
)
389 static_cast<ImplBorderWindow
*>(mpWindowImpl
->mpBorderWindow
.get())->SetMaxOutputSize( aSize
.Width(), aSize
.Height() );
390 if ( mpWindowImpl
->mpBorderWindow
->mpWindowImpl
->mbFrame
)
391 mpWindowImpl
->mpBorderWindow
->mpWindowImpl
->mpFrame
->SetMaxClientSize( aSize
.Width(), aSize
.Height() );
393 else if ( mpWindowImpl
->mbFrame
)
394 mpWindowImpl
->mpFrame
->SetMaxClientSize( aSize
.Width(), aSize
.Height() );
397 const Size
& SystemWindow::GetMaxOutputSizePixel() const
399 return mpImplData
->maMaxOutSize
;
402 vcl::WindowData::WindowData(std::u16string_view rStr
)
404 vcl::WindowData
& rData
= *this;
405 vcl::WindowDataMask nValidMask
= vcl::WindowDataMask::NONE
;
406 sal_Int32 nIndex
= 0;
408 std::u16string_view aTokenStr
= o3tl::getToken(rStr
, 0, ',', nIndex
);
409 if (!aTokenStr
.empty())
411 rData
.setX(o3tl::toInt32(aTokenStr
));
412 if (rData
.x() > -16384 && rData
.x() < 16384)
413 nValidMask
|= vcl::WindowDataMask::X
;
419 aTokenStr
= o3tl::getToken(rStr
, 0, ',', nIndex
);
420 if (!aTokenStr
.empty())
422 rData
.setY(o3tl::toInt32(aTokenStr
));
423 if (rData
.y() > -16384 && rData
.y() < 16384)
424 nValidMask
|= vcl::WindowDataMask::Y
;
430 aTokenStr
= o3tl::getToken(rStr
, 0, ',', nIndex
);
431 if (!aTokenStr
.empty())
433 sal_Int32 nWidth
= o3tl::toInt32(aTokenStr
);
436 rData
.setWidth(nWidth
);
438 if (rData
.width() > 0 && rData
.width() < 16384)
439 nValidMask
|= vcl::WindowDataMask::Width
;
445 aTokenStr
= o3tl::getToken(rStr
, 0, ';', nIndex
);
446 if (!aTokenStr
.empty())
448 sal_Int32 nHeight
= o3tl::toInt32(aTokenStr
);
451 rData
.setHeight(nHeight
);
453 if (rData
.height() > 0 && rData
.height() < 16384)
454 nValidMask
|= vcl::WindowDataMask::Height
;
460 aTokenStr
= o3tl::getToken(rStr
, 0, ';', nIndex
);
461 if (!aTokenStr
.empty())
463 // #94144# allow Minimize again, should be masked out when read from configuration
464 // 91625 - ignore Minimize
465 vcl::WindowState nState
= static_cast<vcl::WindowState
>(o3tl::toInt32(aTokenStr
));
466 //nState &= ~vcl::WindowState::Minimized;
467 rData
.setState(nState
);
468 nValidMask
|= vcl::WindowDataMask::State
;
471 rData
.setState(vcl::WindowState::NONE
);
473 // read maximized pos/size
474 aTokenStr
= o3tl::getToken(rStr
, 0, ',', nIndex
);
475 if (!aTokenStr
.empty())
477 rData
.SetMaximizedX(o3tl::toInt32(aTokenStr
));
478 if (rData
.GetMaximizedX() > -16384 && rData
.GetMaximizedX() < 16384)
479 nValidMask
|= vcl::WindowDataMask::MaximizedX
;
481 rData
.SetMaximizedX(0);
484 rData
.SetMaximizedX(0);
485 aTokenStr
= o3tl::getToken(rStr
, 0, ',', nIndex
);
486 if (!aTokenStr
.empty())
488 rData
.SetMaximizedY(o3tl::toInt32(aTokenStr
));
489 if (rData
.GetMaximizedY() > -16384 && rData
.GetMaximizedY() < 16384)
490 nValidMask
|= vcl::WindowDataMask::MaximizedY
;
492 rData
.SetMaximizedY(0);
495 rData
.SetMaximizedY(0);
496 aTokenStr
= o3tl::getToken(rStr
, 0, ',', nIndex
);
497 if (!aTokenStr
.empty())
499 rData
.SetMaximizedWidth(o3tl::toInt32(aTokenStr
));
500 if (rData
.GetMaximizedWidth() > 0 && rData
.GetMaximizedWidth() < 16384)
501 nValidMask
|= vcl::WindowDataMask::MaximizedWidth
;
503 rData
.SetMaximizedWidth(0);
506 rData
.SetMaximizedWidth(0);
507 aTokenStr
= o3tl::getToken(rStr
, 0, ';', nIndex
);
508 if (!aTokenStr
.empty())
510 rData
.SetMaximizedHeight(o3tl::toInt32(aTokenStr
));
511 if (rData
.GetMaximizedHeight() > 0 && rData
.GetMaximizedHeight() < 16384)
512 nValidMask
|= vcl::WindowDataMask::MaximizedHeight
;
514 rData
.SetMaximizedHeight(0);
517 rData
.SetMaximizedHeight(0);
520 rData
.setMask(nValidMask
);
523 OUString
vcl::WindowData::toStr() const
525 const vcl::WindowDataMask nValidMask
= mask();
526 if ( nValidMask
== vcl::WindowDataMask::NONE
)
529 OUStringBuffer
rStrBuf(64);
531 tools::Rectangle aRect
= posSize();
533 if (nValidMask
& vcl::WindowDataMask::X
)
534 rStrBuf
.append(static_cast<sal_Int32
>(aRect
.Left()));
536 if (nValidMask
& vcl::WindowDataMask::Y
)
537 rStrBuf
.append(static_cast<sal_Int32
>(aRect
.Top()));
539 if (nValidMask
& vcl::WindowDataMask::Width
)
540 rStrBuf
.append(static_cast<sal_Int32
>(aRect
.GetWidth()));
542 if (nValidMask
& vcl::WindowDataMask::Height
)
543 rStrBuf
.append(static_cast<sal_Int32
>(aRect
.GetHeight()));
544 rStrBuf
.append( ';' );
545 if (nValidMask
& vcl::WindowDataMask::State
)
547 // #94144# allow Minimize again, should be masked out when read from configuration
548 // 91625 - ignore Minimize
549 rStrBuf
.append(static_cast<sal_Int32
>(state()));
552 if (nValidMask
& vcl::WindowDataMask::MaximizedX
)
553 rStrBuf
.append(static_cast<sal_Int32
>(GetMaximizedX()));
555 if (nValidMask
& vcl::WindowDataMask::MaximizedY
)
556 rStrBuf
.append(static_cast<sal_Int32
>(GetMaximizedY()));
557 rStrBuf
.append( ',' );
558 if (nValidMask
& vcl::WindowDataMask::MaximizedWidth
)
559 rStrBuf
.append(static_cast<sal_Int32
>(GetMaximizedWidth()));
561 if (nValidMask
& vcl::WindowDataMask::MaximizedHeight
)
562 rStrBuf
.append(static_cast<sal_Int32
>(GetMaximizedHeight()));
565 return rStrBuf
.makeStringAndClear();
568 void SystemWindow::ImplMoveToScreen( tools::Long
& io_rX
, tools::Long
& io_rY
, tools::Long i_nWidth
, tools::Long i_nHeight
, vcl::Window
const * i_pConfigureWin
)
570 tools::Rectangle aScreenRect
;
571 if( !Application::IsUnifiedDisplay() )
572 aScreenRect
= Application::GetScreenPosSizePixel( GetScreenNumber() );
575 aScreenRect
= Application::GetScreenPosSizePixel( 0 );
576 for( unsigned int i
= 1; i
< Application::GetScreenCount(); i
++ )
577 aScreenRect
.Union( Application::GetScreenPosSizePixel( i
) );
579 // unfortunately most of the time width and height are not really known
587 if( io_rX
+ i_nWidth
< aScreenRect
.Left() )
590 io_rX
= aScreenRect
.Left();
592 // check right border
593 if( io_rX
> aScreenRect
.Right() - i_nWidth
)
596 io_rX
= aScreenRect
.Right() - i_nWidth
;
599 if( io_rY
+ i_nHeight
< aScreenRect
.Top() )
602 io_rY
= aScreenRect
.Top();
604 // check bottom border
605 if( io_rY
> aScreenRect
.Bottom() - i_nHeight
)
608 io_rY
= aScreenRect
.Bottom() - i_nHeight
;
610 vcl::Window
* pParent
= i_pConfigureWin
->GetParent();
611 if( bMove
&& pParent
)
613 // calculate absolute screen pos here, since that is what is contained in WindowData
614 Point
aParentAbsPos( pParent
->OutputToAbsoluteScreenPixel( Point(0,0) ) );
615 Size
aParentSizePixel( pParent
->GetOutputSizePixel() );
616 Point
aPos( (aParentSizePixel
.Width() - i_nWidth
) / 2,
617 (aParentSizePixel
.Height() - i_nHeight
) / 2 );
618 io_rX
= aParentAbsPos
.X() + aPos
.X();
619 io_rY
= aParentAbsPos
.Y() + aPos
.Y();
623 void SystemWindow::SetWindowState(const vcl::WindowData
& rData
)
625 const vcl::WindowDataMask nValidMask
= rData
.mask();
626 if ( nValidMask
== vcl::WindowDataMask::NONE
)
632 vcl::Window
* pWindow
= this;
633 while ( pWindow
->mpWindowImpl
->mpBorderWindow
)
634 pWindow
= pWindow
->mpWindowImpl
->mpBorderWindow
;
636 if ( pWindow
->mpWindowImpl
->mbFrame
)
638 const vcl::WindowState nState
= rData
.state();
639 vcl::WindowData aState
= rData
;
641 if (rData
.mask() & vcl::WindowDataMask::Size
)
643 // #i43799# adjust window state sizes if a minimal output size was set
644 // otherwise the frame and the client might get different sizes
645 if (maMinOutSize
.Width() > static_cast<tools::Long
>(aState
.width()))
646 aState
.setWidth(maMinOutSize
.Width());
647 if (maMinOutSize
.Height() > static_cast<tools::Long
>(aState
.width()))
648 aState
.setHeight(maMinOutSize
.Height());
651 // #94144# allow Minimize again, should be masked out when read from configuration
652 // 91625 - ignore Minimize
653 //nState &= ~(WindowState::Minimized);
654 aState
.rState() &= vcl::WindowState::SystemMask
;
656 // normalize window positions onto screen
657 tools::Long nX
= aState
.x(), nY
= aState
.y();
658 ImplMoveToScreen(nX
, nY
, aState
.width(), aState
.height(), pWindow
);
659 aState
.setPos({ nX
, nY
});
660 nX
= aState
.GetMaximizedX();
661 nY
= aState
.GetMaximizedY();
662 ImplMoveToScreen(nX
, nY
, aState
.GetMaximizedWidth(), aState
.GetMaximizedHeight(), pWindow
);
663 aState
.SetMaximizedX(nX
);
664 aState
.SetMaximizedY(nY
);
666 // #96568# avoid having multiple frames at the same screen location
667 // do the check only if not maximized
668 if( !((rData
.mask() & vcl::WindowDataMask::State
) && (nState
& vcl::WindowState::Maximized
)) )
669 if (rData
.mask() & vcl::WindowDataMask::PosSize
)
671 tools::Rectangle aDesktop
= GetDesktopRectPixel();
672 ImplSVData
*pSVData
= ImplGetSVData();
673 vcl::Window
*pWin
= pSVData
->maFrameData
.mpFirstFrame
;
674 bool bWrapped
= false;
677 if( !pWin
->ImplIsRealParentPath( this ) && ( pWin
!= this ) &&
678 pWin
->ImplGetWindow()->IsTopWindow() && pWin
->mpWindowImpl
->mbReallyVisible
)
680 SalFrameGeometry g
= pWin
->mpWindowImpl
->mpFrame
->GetGeometry();
681 if( std::abs(g
.x()-aState
.x()) < 2 && std::abs(g
.y()-aState
.y()) < 5 )
683 tools::Long displacement
= g
.topDecoration() ? g
.topDecoration() : 20;
684 if( static_cast<tools::Long
>(aState
.x() + displacement
+ aState
.width() + g
.rightDecoration()) > aDesktop
.Right() ||
685 static_cast<tools::Long
>(aState
.y() + displacement
+ aState
.height() + g
.bottomDecoration()) > aDesktop
.Bottom() )
687 // displacing would leave screen
688 aState
.setX(g
.leftDecoration() ? g
.leftDecoration() : 10); // should result in (0,0)
689 aState
.setY(displacement
);
691 static_cast<tools::Long
>(aState
.x() + displacement
+ aState
.width() + g
.rightDecoration()) > aDesktop
.Right() ||
692 static_cast<tools::Long
>(aState
.y() + displacement
+ aState
.height() + g
.bottomDecoration()) > aDesktop
.Bottom() )
693 break; // further displacement not possible -> break
694 // avoid endless testing
698 aState
.move(displacement
, displacement
);
699 pWin
= pSVData
->maFrameData
.mpFirstFrame
; // check new pos again
702 pWin
= pWin
->mpWindowImpl
->mpFrameData
->mpNextFrame
;
706 mpWindowImpl
->mpFrame
->SetWindowState( &aState
);
708 // do a synchronous resize for layout reasons
709 // but use rData only when the window is not to be maximized (#i38089#)
710 // otherwise we have no useful size information
711 if( (rData
.mask() & vcl::WindowDataMask::State
) && (nState
& vcl::WindowState::Maximized
) )
713 // query maximized size from frame
714 SalFrameGeometry aGeometry
= mpWindowImpl
->mpFrame
->GetGeometry();
716 // but use it only if it is different from the restore size (rData)
717 // as currently only on windows the exact size of a maximized window
718 // can be computed without actually showing the window
719 if (aGeometry
.width() != rData
.width() || aGeometry
.height() != rData
.height())
720 ImplHandleResize(pWindow
, aGeometry
.width(), aGeometry
.height());
723 if (rData
.mask() & vcl::WindowDataMask::Size
)
724 ImplHandleResize(pWindow
, aState
.width(), aState
.height()); // #i43799# use aState and not rData, see above
728 PosSizeFlags nPosSize
= PosSizeFlags::NONE
;
729 if ( nValidMask
& vcl::WindowDataMask::X
)
730 nPosSize
|= PosSizeFlags::X
;
731 if ( nValidMask
& vcl::WindowDataMask::Y
)
732 nPosSize
|= PosSizeFlags::Y
;
733 if ( nValidMask
& vcl::WindowDataMask::Width
)
734 nPosSize
|= PosSizeFlags::Width
;
735 if ( nValidMask
& vcl::WindowDataMask::Height
)
736 nPosSize
|= PosSizeFlags::Height
;
738 tools::Long nX
= rData
.x();
739 tools::Long nY
= rData
.y();
740 tools::Long nWidth
= rData
.width();
741 tools::Long nHeight
= rData
.height();
742 const SalFrameGeometry
& rGeom
= pWindow
->mpWindowImpl
->mpFrame
->GetGeometry();
745 if( nX
+ nWidth
> static_cast<tools::Long
>(rGeom
.width()) )
746 nX
= rGeom
.width() - nWidth
;
749 if( nY
+ nHeight
> static_cast<tools::Long
>(rGeom
.height()) )
750 nY
= rGeom
.height() - nHeight
;
751 setPosSizePixel( nX
, nY
, nWidth
, nHeight
, nPosSize
);
754 // tdf#146648 if an explicit size state was set, then use it as the preferred
756 if (nValidMask
& vcl::WindowDataMask::Size
)
757 mbInitialLayoutSizeCalculated
= true;
760 void SystemWindow::GetWindowState(vcl::WindowData
& rData
) const
762 vcl::WindowDataMask nValidMask
= rData
.mask();
763 if ( nValidMask
== vcl::WindowDataMask::NONE
)
768 rData
.setMask( vcl::WindowDataMask::NONE
);
772 const vcl::Window
* pWindow
= this;
773 while ( pWindow
->mpWindowImpl
->mpBorderWindow
)
774 pWindow
= pWindow
->mpWindowImpl
->mpBorderWindow
;
776 if ( pWindow
->mpWindowImpl
->mbFrame
)
778 vcl::WindowData aState
;
779 if ( mpWindowImpl
->mpFrame
->GetWindowState( &aState
) )
781 // Limit mask only to what we've received, the rest is not set.
782 nValidMask
&= aState
.mask();
783 rData
.setMask( nValidMask
);
784 if ( nValidMask
& vcl::WindowDataMask::X
)
785 rData
.setX( aState
.x() );
786 if ( nValidMask
& vcl::WindowDataMask::Y
)
787 rData
.setY( aState
.y() );
788 if ( nValidMask
& vcl::WindowDataMask::Width
)
789 rData
.setWidth( aState
.width() );
790 if ( nValidMask
& vcl::WindowDataMask::Height
)
791 rData
.setHeight( aState
.height() );
792 if ( nValidMask
& vcl::WindowDataMask::MaximizedX
)
793 rData
.SetMaximizedX( aState
.GetMaximizedX() );
794 if ( nValidMask
& vcl::WindowDataMask::MaximizedY
)
795 rData
.SetMaximizedY( aState
.GetMaximizedY() );
796 if ( nValidMask
& vcl::WindowDataMask::MaximizedWidth
)
797 rData
.SetMaximizedWidth( aState
.GetMaximizedWidth() );
798 if ( nValidMask
& vcl::WindowDataMask::MaximizedHeight
)
799 rData
.SetMaximizedHeight( aState
.GetMaximizedHeight() );
800 if ( nValidMask
& vcl::WindowDataMask::State
)
802 // #94144# allow Minimize again, should be masked out when read from configuration
803 // 91625 - ignore Minimize
804 if (!(nValidMask
& vcl::WindowDataMask::Minimized
))
805 aState
.rState() &= ~vcl::WindowState::Minimized
;
806 rData
.setState(aState
.state());
808 rData
.setMask( nValidMask
);
811 rData
.setMask(vcl::WindowDataMask::NONE
);
815 Point aPos
= GetPosPixel();
816 Size aSize
= GetSizePixel();
817 vcl::WindowState nState
= vcl::WindowState::NONE
;
819 nValidMask
&= vcl::WindowDataMask::PosSizeState
;
820 rData
.setMask( nValidMask
);
821 if (nValidMask
& vcl::WindowDataMask::X
)
822 rData
.setX(aPos
.X());
823 if (nValidMask
& vcl::WindowDataMask::Y
)
824 rData
.setY(aPos
.Y());
825 if (nValidMask
& vcl::WindowDataMask::Width
)
826 rData
.setWidth(aSize
.Width());
827 if (nValidMask
& vcl::WindowDataMask::Height
)
828 rData
.setHeight(aSize
.Height());
829 if (nValidMask
& vcl::WindowDataMask::State
)
830 rData
.setState(nState
);
834 void SystemWindow::SetWindowState(std::u16string_view rStr
)
838 SetWindowState(vcl::WindowData(rStr
));
841 OUString
SystemWindow::GetWindowState(vcl::WindowDataMask nMask
) const
843 vcl::WindowData aData
;
844 aData
.setMask(nMask
);
845 GetWindowState(aData
);
846 return aData
.toStr();
849 void SystemWindow::SetMenuBar(MenuBar
* pMenuBar
)
851 if ( mpMenuBar
== pMenuBar
)
854 MenuBar
* pOldMenuBar
= mpMenuBar
;
855 vcl::Window
* pOldWindow
= nullptr;
856 VclPtr
<vcl::Window
> pNewWindow
;
857 mpMenuBar
= pMenuBar
;
859 if ( mpWindowImpl
->mpBorderWindow
&& (mpWindowImpl
->mpBorderWindow
->GetType() == WindowType::BORDERWINDOW
) )
862 pOldWindow
= pOldMenuBar
->ImplGetWindow();
864 pOldWindow
= nullptr;
867 CallEventListeners( VclEventId::WindowMenubarRemoved
, static_cast<void*>(pOldMenuBar
) );
868 pOldWindow
->SetAccessible( css::uno::Reference
< css::accessibility::XAccessible
>() );
872 SAL_WARN_IF( pMenuBar
->pWindow
, "vcl", "SystemWindow::SetMenuBar() - MenuBars can only set in one SystemWindow at time" );
874 pNewWindow
= MenuBar::ImplCreate(mpWindowImpl
->mpBorderWindow
, pOldWindow
, pMenuBar
);
875 static_cast<ImplBorderWindow
*>(mpWindowImpl
->mpBorderWindow
.get())->SetMenuBarWindow(pNewWindow
);
877 CallEventListeners( VclEventId::WindowMenubarAdded
, static_cast<void*>(pMenuBar
) );
880 static_cast<ImplBorderWindow
*>(mpWindowImpl
->mpBorderWindow
.get())->SetMenuBarWindow( nullptr );
884 bool bDelete
= (pMenuBar
== nullptr);
885 if( bDelete
&& pOldWindow
)
887 if( mpImplData
->mpTaskPaneList
)
888 mpImplData
->mpTaskPaneList
->RemoveWindow( pOldWindow
);
890 MenuBar::ImplDestroy( pOldMenuBar
, bDelete
);
892 pOldWindow
= nullptr; // will be deleted in MenuBar::ImplDestroy,
899 pNewWindow
= pMenuBar
->ImplGetWindow();
901 pOldWindow
= pOldMenuBar
->ImplGetWindow();
904 // update taskpane list to make menubar accessible
905 if( mpImplData
->mpTaskPaneList
)
908 mpImplData
->mpTaskPaneList
->RemoveWindow( pOldWindow
);
910 mpImplData
->mpTaskPaneList
->AddWindow( pNewWindow
);
914 void SystemWindow::SetNotebookBar(const OUString
& rUIXMLDescription
,
915 const css::uno::Reference
<css::frame::XFrame
>& rFrame
,
916 const NotebookBarAddonsItem
& aNotebookBarAddonsItem
,
917 bool bReloadNotebookbar
)
919 if (rUIXMLDescription
!= maNotebookBarUIFile
|| bReloadNotebookbar
)
921 static_cast<ImplBorderWindow
*>(mpWindowImpl
->mpBorderWindow
.get())
922 ->SetNotebookBar(rUIXMLDescription
, rFrame
, aNotebookBarAddonsItem
);
923 maNotebookBarUIFile
= rUIXMLDescription
;
925 GetNotebookBar()->SetSystemWindow(this);
929 void SystemWindow::CloseNotebookBar()
931 static_cast<ImplBorderWindow
*>(mpWindowImpl
->mpBorderWindow
.get())->CloseNotebookBar();
932 maNotebookBarUIFile
.clear();
935 VclPtr
<NotebookBar
> const & SystemWindow::GetNotebookBar() const
937 return static_cast<ImplBorderWindow
*>(mpWindowImpl
->mpBorderWindow
.get())->GetNotebookBar();
940 void SystemWindow::SetMenuBarMode( MenuBarMode nMode
)
942 if ( mnMenuBarMode
!= nMode
)
944 mnMenuBarMode
= nMode
;
945 if ( mpWindowImpl
->mpBorderWindow
&& (mpWindowImpl
->mpBorderWindow
->GetType() == WindowType::BORDERWINDOW
) )
947 if ( nMode
== MenuBarMode::Hide
)
948 static_cast<ImplBorderWindow
*>(mpWindowImpl
->mpBorderWindow
.get())->SetMenuBarMode( true );
950 static_cast<ImplBorderWindow
*>(mpWindowImpl
->mpBorderWindow
.get())->SetMenuBarMode( false );
955 bool SystemWindow::ImplIsInTaskPaneList( vcl::Window
* pWin
)
957 if( mpImplData
&& mpImplData
->mpTaskPaneList
)
958 return mpImplData
->mpTaskPaneList
->IsInList( pWin
);
962 unsigned int SystemWindow::GetScreenNumber() const
964 return mpWindowImpl
->mpFrame
->maGeometry
.screen();
967 void SystemWindow::SetScreenNumber(unsigned int nDisplayScreen
)
969 mpWindowImpl
->mpFrame
->SetScreenNumber( nDisplayScreen
);
972 void SystemWindow::SetApplicationID(const OUString
&rApplicationID
)
974 mpWindowImpl
->mpFrame
->SetApplicationID( rApplicationID
);
977 void SystemWindow::SetCloseHdl(const Link
<SystemWindow
&,void>& rLink
)
979 mpImplData
->maCloseHdl
= rLink
;
982 const Link
<SystemWindow
&,void>& SystemWindow::GetCloseHdl() const
984 return mpImplData
->maCloseHdl
;
987 void SystemWindow::queue_resize(StateChangedType
/*eReason*/)
989 if (!isLayoutEnabled())
991 if (isCalculatingInitialLayoutSize())
993 InvalidateSizeCache();
994 if (hasPendingLayout())
996 maLayoutIdle
.Start();
999 void SystemWindow::Resize()
1004 bool SystemWindow::isLayoutEnabled() const
1006 //pre dtor called, and single child is a container => we're layout enabled
1007 return mpImplData
&& ::isLayoutEnabled(this);
1010 Size
SystemWindow::GetOptimalSize() const
1012 if (!isLayoutEnabled())
1013 return Window::GetOptimalSize();
1015 Window
*pBox
= GetWindow(GetWindowType::FirstChild
);
1016 // tdf#141318 Do the same as SystemWindow::setOptimalLayoutSize in case we're called before initial layout
1017 const_cast<SystemWindow
*>(this)->settingOptimalLayoutSize(pBox
);
1018 Size aSize
= VclContainer::getLayoutRequisition(*pBox
);
1020 sal_Int32 nBorderWidth
= get_border_width();
1022 aSize
.AdjustHeight(2 * nBorderWidth
);
1023 aSize
.AdjustWidth(2 * nBorderWidth
);
1025 return Window::CalcWindowSize(aSize
);
1028 void SystemWindow::setPosSizeOnContainee(Size aSize
, Window
&rBox
)
1030 sal_Int32 nBorderWidth
= get_border_width();
1032 aSize
.AdjustWidth( -(2 * nBorderWidth
) );
1033 aSize
.AdjustHeight( -(2 * nBorderWidth
) );
1035 Point
aPos(nBorderWidth
, nBorderWidth
);
1036 VclContainer::setLayoutAllocation(rBox
, aPos
, CalcOutputSize(aSize
));
1039 IMPL_LINK_NOARG( SystemWindow
, ImplHandleLayoutTimerHdl
, Timer
*, void )
1041 Window
*pBox
= GetWindow(GetWindowType::FirstChild
);
1042 if (!isLayoutEnabled())
1044 SAL_WARN_IF(pBox
, "vcl.layout", "SystemWindow has become non-layout because extra children have been added directly to it.");
1048 setPosSizeOnContainee(GetSizePixel(), *pBox
);
1051 void SystemWindow::SetText(const OUString
& rStr
)
1053 setDeferredProperties();
1054 Window::SetText(rStr
);
1057 OUString
SystemWindow::GetText() const
1059 const_cast<SystemWindow
*>(this)->setDeferredProperties();
1060 return Window::GetText();
1063 void SystemWindow::settingOptimalLayoutSize(Window
* /*pBox*/)
1067 void SystemWindow::setOptimalLayoutSize(bool bAllowWindowShrink
)
1069 maLayoutIdle
.Stop();
1071 //resize SystemWindow to fit requisition on initial show
1072 Window
*pBox
= GetWindow(GetWindowType::FirstChild
);
1074 settingOptimalLayoutSize(pBox
);
1076 Size aSize
= get_preferred_size();
1078 Size
aMax(bestmaxFrameSizeForScreenSize(GetDesktopRectPixel().GetSize()));
1080 aSize
.setWidth( std::min(aMax
.Width(), aSize
.Width()) );
1081 aSize
.setHeight( std::min(aMax
.Height(), aSize
.Height()) );
1083 SetMinOutputSizePixel(aSize
);
1085 if (!bAllowWindowShrink
)
1087 Size aCurrentSize
= GetSizePixel();
1088 aSize
.setWidth(std::max(aSize
.Width(), aCurrentSize
.Width()));
1089 aSize
.setHeight(std::max(aSize
.Height(), aCurrentSize
.Height()));
1092 SetSizePixel(aSize
);
1093 setPosSizeOnContainee(aSize
, *pBox
);
1096 void SystemWindow::DoInitialLayout()
1098 if (GetSettings().GetStyleSettings().GetAutoMnemonic())
1099 GenerateAutoMnemonicsOnHierarchy(this);
1101 if (isLayoutEnabled())
1103 mbIsCalculatingInitialLayoutSize
= true;
1104 setDeferredProperties();
1105 setOptimalLayoutSize(!mbInitialLayoutSizeCalculated
);
1106 mbInitialLayoutSizeCalculated
= true;
1107 mbIsCalculatingInitialLayoutSize
= false;
1111 void SystemWindow::doDeferredInit(WinBits
/*nBits*/)
1113 SAL_WARN("vcl.layout", "SystemWindow in layout without doDeferredInit impl");
1116 VclPtr
<VirtualDevice
> SystemWindow::createScreenshot()
1118 // same prerequisites as in Execute()
1119 setDeferredProperties();
1120 ImplAdjustNWFSizes();
1125 Size
aSize(GetOutputSizePixel());
1127 VclPtr
<VirtualDevice
> xOutput(VclPtr
<VirtualDevice
>::Create(DeviceFormat::WITHOUT_ALPHA
));
1128 xOutput
->SetOutputSizePixel(aSize
);
1131 xOutput
->DrawOutDev(aPos
, aSize
, aPos
, aSize
, *GetOutDev());
1136 void SystemWindow::PrePaint(vcl::RenderContext
& rRenderContext
)
1138 Window::PrePaint(rRenderContext
);
1139 mbPaintComplete
= false;
1142 void SystemWindow::PostPaint(vcl::RenderContext
& rRenderContext
)
1144 Window::PostPaint(rRenderContext
);
1145 mbPaintComplete
= true;
1148 void SystemWindow::ensureRepaint()
1152 mbPaintComplete
= false;
1154 while (!mbPaintComplete
&& !Application::IsQuit())
1156 Application::Yield();
1160 void SystemWindow::CollectMenuBarMnemonics(MnemonicGenerator
& rMnemonicGenerator
) const
1162 if (MenuBar
* pMenu
= GetMenuBar())
1164 sal_uInt16 nMenuItems
= pMenu
->GetItemCount();
1165 for ( sal_uInt16 i
= 0; i
< nMenuItems
; ++i
)
1166 rMnemonicGenerator
.RegisterMnemonic( pMenu
->GetItemText( pMenu
->GetItemId( i
) ) );
1170 int SystemWindow::GetMenuBarHeight() const
1172 if (MenuBar
* pMenuBar
= GetMenuBar())
1173 return pMenuBar
->GetMenuBarHeight();
1177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */