bump product version to 7.6.3.2-android
[LibreOffice.git] / vcl / source / window / window.cxx
blobf79918fd7f52470ed776955ca7abb3a072cd9d61
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 <sal/config.h>
22 #include <rtl/strbuf.hxx>
23 #include <sal/log.hxx>
25 #include <sal/types.h>
26 #include <comphelper/diagnose_ex.hxx>
27 #include <vcl/salgtype.hxx>
28 #include <vcl/event.hxx>
29 #include <vcl/help.hxx>
30 #include <vcl/cursor.hxx>
31 #include <vcl/svapp.hxx>
32 #include <vcl/transfer.hxx>
33 #include <vcl/vclevent.hxx>
34 #include <vcl/window.hxx>
35 #include <vcl/syswin.hxx>
36 #include <vcl/dockwin.hxx>
37 #include <vcl/wall.hxx>
38 #include <vcl/toolkit/fixed.hxx>
39 #include <vcl/taskpanelist.hxx>
40 #include <vcl/toolkit/unowrap.hxx>
41 #include <vcl/lazydelete.hxx>
42 #include <vcl/virdev.hxx>
43 #include <vcl/settings.hxx>
44 #include <vcl/sysdata.hxx>
45 #include <vcl/ptrstyle.hxx>
46 #include <vcl/IDialogRenderable.hxx>
48 #include <vcl/uitest/uiobject.hxx>
50 #include <ImplOutDevData.hxx>
51 #include <impfontcache.hxx>
52 #include <salframe.hxx>
53 #include <salobj.hxx>
54 #include <salinst.hxx>
55 #include <salgdi.hxx>
56 #include <svdata.hxx>
57 #include <window.h>
58 #include <toolbox.h>
59 #include <brdwin.hxx>
60 #include <helpwin.hxx>
62 #include <com/sun/star/accessibility/AccessibleRelation.hpp>
63 #include <com/sun/star/accessibility/XAccessible.hpp>
64 #include <com/sun/star/accessibility/XAccessibleEditableText.hpp>
65 #include <com/sun/star/awt/XVclWindowPeer.hpp>
66 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
67 #include <com/sun/star/datatransfer/dnd/XDragGestureRecognizer.hpp>
68 #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
69 #include <com/sun/star/rendering/CanvasFactory.hpp>
70 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
71 #include <comphelper/lok.hxx>
72 #include <comphelper/processfactory.hxx>
73 #include <unotools/configmgr.hxx>
74 #include <osl/diagnose.h>
75 #include <tools/debug.hxx>
76 #include <tools/json_writer.hxx>
77 #include <boost/property_tree/ptree.hpp>
79 #include <cassert>
80 #include <typeinfo>
82 #ifdef _WIN32 // see #140456#
83 #include <win/salframe.h>
84 #endif
86 #include "impldockingwrapper.hxx"
88 using namespace ::com::sun::star::uno;
89 using namespace ::com::sun::star::lang;
90 using namespace ::com::sun::star::datatransfer::clipboard;
91 using namespace ::com::sun::star::datatransfer::dnd;
93 namespace vcl {
95 Window::Window( WindowType nType )
96 : mpWindowImpl(new WindowImpl( *this, nType ))
98 // true: this outdev will be mirrored if RTL window layout (UI mirroring) is globally active
99 mpWindowImpl->mxOutDev->mbEnableRTL = AllSettings::GetLayoutRTL();
102 Window::Window( vcl::Window* pParent, WinBits nStyle )
103 : mpWindowImpl(new WindowImpl( *this, WindowType::WINDOW ))
105 // true: this outdev will be mirrored if RTL window layout (UI mirroring) is globally active
106 mpWindowImpl->mxOutDev->mbEnableRTL = AllSettings::GetLayoutRTL();
108 ImplInit( pParent, nStyle, nullptr );
111 #if OSL_DEBUG_LEVEL > 0
112 namespace
114 OString lcl_createWindowInfo(const vcl::Window* pWindow)
116 // skip border windows, they do not carry information that
117 // would help with diagnosing the problem
118 const vcl::Window* pTempWin( pWindow );
119 while ( pTempWin && pTempWin->GetType() == WindowType::BORDERWINDOW ) {
120 pTempWin = pTempWin->GetWindow( GetWindowType::FirstChild );
122 // check if pTempWin is not null, otherwise use the
123 // original address
124 if ( pTempWin ) {
125 pWindow = pTempWin;
128 return OString::Concat(" ") +
129 typeid( *pWindow ).name() +
130 "(" +
131 OUStringToOString(
132 pWindow->GetText(),
133 RTL_TEXTENCODING_UTF8
135 ")";
138 #endif
140 void Window::dispose()
142 assert( mpWindowImpl );
143 assert( !mpWindowImpl->mbInDispose ); // should only be called from disposeOnce()
144 assert( (!mpWindowImpl->mpParent ||
145 mpWindowImpl->mpParent->mpWindowImpl) &&
146 "vcl::Window child should have its parent disposed first" );
148 // remove Key and Mouse events issued by Application::PostKey/MouseEvent
149 Application::RemoveMouseAndKeyEvents( this );
151 // Dispose of the canvas implementation (which, currently, has an
152 // own wrapper window as a child to this one.
153 GetOutDev()->ImplDisposeCanvas();
155 mpWindowImpl->mbInDispose = true;
157 CallEventListeners( VclEventId::ObjectDying );
159 // do not send child events for frames that were registered as native frames
160 if( !ImplIsAccessibleNativeFrame() && mpWindowImpl->mbReallyVisible )
161 if ( ImplIsAccessibleCandidate() && GetAccessibleParentWindow() )
162 GetAccessibleParentWindow()->CallEventListeners( VclEventId::WindowChildDestroyed, this );
164 // remove associated data structures from dockingmanager
165 ImplGetDockingManager()->RemoveWindow( this );
167 // remove ownerdraw decorated windows from list in the top-most frame window
168 if( (GetStyle() & WB_OWNERDRAWDECORATION) && mpWindowImpl->mbFrame )
170 ::std::vector< VclPtr<vcl::Window> >& rList = ImplGetOwnerDrawList();
171 auto p = ::std::find( rList.begin(), rList.end(), VclPtr<vcl::Window>(this) );
172 if( p != rList.end() )
173 rList.erase( p );
176 // shutdown drag and drop
177 Reference < XComponent > xDnDComponent( mpWindowImpl->mxDNDListenerContainer, UNO_QUERY );
179 if( xDnDComponent.is() )
180 xDnDComponent->dispose();
182 if( mpWindowImpl->mbFrame && mpWindowImpl->mpFrameData )
186 // deregister drop target listener
187 if( mpWindowImpl->mpFrameData->mxDropTargetListener.is() )
189 Reference< XDragGestureRecognizer > xDragGestureRecognizer(mpWindowImpl->mpFrameData->mxDragSource, UNO_QUERY);
190 if( xDragGestureRecognizer.is() )
192 xDragGestureRecognizer->removeDragGestureListener(
193 Reference< XDragGestureListener > (mpWindowImpl->mpFrameData->mxDropTargetListener, UNO_QUERY));
196 mpWindowImpl->mpFrameData->mxDropTarget->removeDropTargetListener( mpWindowImpl->mpFrameData->mxDropTargetListener );
197 mpWindowImpl->mpFrameData->mxDropTargetListener.clear();
200 // shutdown drag and drop for this frame window
201 Reference< XComponent > xComponent( mpWindowImpl->mpFrameData->mxDropTarget, UNO_QUERY );
203 // DNDEventDispatcher does not hold a reference of the DropTarget,
204 // so it's ok if it does not support XComponent
205 if( xComponent.is() )
206 xComponent->dispose();
208 catch (const Exception&)
210 // can be safely ignored here.
214 UnoWrapperBase* pWrapper = UnoWrapperBase::GetUnoWrapper( false );
215 if ( pWrapper )
216 pWrapper->WindowDestroyed( this );
218 // MT: Must be called after WindowDestroyed!
219 // Otherwise, if the accessible is a VCLXWindow, it will try to destroy this window again!
220 // But accessibility implementations from applications need this dispose.
221 if ( mpWindowImpl->mxAccessible.is() )
223 Reference< XComponent> xC( mpWindowImpl->mxAccessible, UNO_QUERY );
224 if ( xC.is() )
225 xC->dispose();
228 ImplSVData* pSVData = ImplGetSVData();
230 if ( ImplGetSVHelpData().mpHelpWin && (ImplGetSVHelpData().mpHelpWin->GetParent() == this) )
231 ImplDestroyHelpWindow( true );
233 SAL_WARN_IF(pSVData->mpWinData->mpTrackWin.get() == this, "vcl.window",
234 "Window::~Window(): Window is in TrackingMode");
235 SAL_WARN_IF(IsMouseCaptured(), "vcl.window",
236 "Window::~Window(): Window has the mouse captured");
238 // due to old compatibility
239 if (pSVData->mpWinData->mpTrackWin == this)
240 EndTracking();
241 if (IsMouseCaptured())
242 ReleaseMouse();
244 #if OSL_DEBUG_LEVEL > 0
245 // always perform these tests in debug builds
247 OStringBuffer aErrorStr;
248 bool bError = false;
249 vcl::Window* pTempWin;
251 if ( mpWindowImpl->mpFirstChild )
253 OStringBuffer aTempStr = "Window (" +
254 lcl_createWindowInfo(this) +
255 ") with live children destroyed: ";
256 pTempWin = mpWindowImpl->mpFirstChild;
257 while ( pTempWin )
259 aTempStr.append(lcl_createWindowInfo(pTempWin));
260 pTempWin = pTempWin->mpWindowImpl->mpNext;
262 OSL_FAIL( aTempStr.getStr() );
263 Application::Abort(OStringToOUString(aTempStr, RTL_TEXTENCODING_UTF8));
266 if (mpWindowImpl->mpFrameData != nullptr)
268 pTempWin = mpWindowImpl->mpFrameData->mpFirstOverlap;
269 while ( pTempWin )
271 if ( ImplIsRealParentPath( pTempWin ) )
273 bError = true;
274 aErrorStr.append(lcl_createWindowInfo(pTempWin));
276 pTempWin = pTempWin->mpWindowImpl->mpNextOverlap;
278 if ( bError )
280 OString aTempStr =
281 "Window (" +
282 lcl_createWindowInfo(this) +
283 ") with live SystemWindows destroyed: " +
284 aErrorStr;
285 OSL_FAIL(aTempStr.getStr());
286 Application::Abort(OStringToOUString(aTempStr, RTL_TEXTENCODING_UTF8));
290 bError = false;
291 pTempWin = pSVData->maFrameData.mpFirstFrame;
292 while ( pTempWin )
294 if ( ImplIsRealParentPath( pTempWin ) )
296 bError = true;
297 aErrorStr.append(lcl_createWindowInfo(pTempWin));
299 pTempWin = pTempWin->mpWindowImpl->mpFrameData->mpNextFrame;
301 if ( bError )
303 OString aTempStr = "Window (" +
304 lcl_createWindowInfo(this) +
305 ") with live SystemWindows destroyed: " +
306 aErrorStr;
307 OSL_FAIL( aTempStr.getStr() );
308 Application::Abort(OStringToOUString(aTempStr, RTL_TEXTENCODING_UTF8));
311 if ( mpWindowImpl->mpFirstOverlap )
313 OStringBuffer aTempStr = "Window (" +
314 lcl_createWindowInfo(this) +
315 ") with live SystemWindows destroyed: ";
316 pTempWin = mpWindowImpl->mpFirstOverlap;
317 while ( pTempWin )
319 aTempStr.append(lcl_createWindowInfo(pTempWin));
320 pTempWin = pTempWin->mpWindowImpl->mpNext;
322 OSL_FAIL( aTempStr.getStr() );
323 Application::Abort(OStringToOUString(aTempStr, RTL_TEXTENCODING_UTF8));
326 vcl::Window* pMyParent = GetParent();
327 SystemWindow* pMySysWin = nullptr;
329 while ( pMyParent )
331 if ( pMyParent->IsSystemWindow() )
333 pMySysWin = dynamic_cast<SystemWindow *>(pMyParent);
335 pMyParent = pMyParent->GetParent();
337 if ( pMySysWin && pMySysWin->ImplIsInTaskPaneList( this ) )
339 OString aTempStr = "Window (" +
340 lcl_createWindowInfo(this) +
341 ") still in TaskPanelList!";
342 OSL_FAIL( aTempStr.getStr() );
343 Application::Abort(OStringToOUString(aTempStr, RTL_TEXTENCODING_UTF8));
346 #endif
348 if( mpWindowImpl->mbIsInTaskPaneList )
350 vcl::Window* pMyParent = GetParent();
351 SystemWindow* pMySysWin = nullptr;
353 while ( pMyParent )
355 if ( pMyParent->IsSystemWindow() )
357 pMySysWin = dynamic_cast<SystemWindow *>(pMyParent);
359 pMyParent = pMyParent->GetParent();
361 if ( pMySysWin && pMySysWin->ImplIsInTaskPaneList( this ) )
363 pMySysWin->GetTaskPaneList()->RemoveWindow( this );
365 else
367 SAL_WARN( "vcl", "Window (" << GetText() << ") not found in TaskPanelList");
371 // remove from size-group if necessary
372 remove_from_all_size_groups();
374 // clear mnemonic labels
375 std::vector<VclPtr<FixedText> > aMnemonicLabels(list_mnemonic_labels());
376 for (auto const& mnemonicLabel : aMnemonicLabels)
378 remove_mnemonic_label(mnemonicLabel);
381 // hide window in order to trigger the Paint-Handling
382 Hide();
384 // EndExtTextInputMode
385 if (pSVData->mpWinData->mpExtTextInputWin == this)
387 EndExtTextInput();
388 if (pSVData->mpWinData->mpExtTextInputWin == this)
389 pSVData->mpWinData->mpExtTextInputWin = nullptr;
392 // check if the focus window is our child
393 bool bHasFocusedChild = false;
394 if (pSVData->mpWinData->mpFocusWin && ImplIsRealParentPath(pSVData->mpWinData->mpFocusWin))
396 // #122232#, this must not happen and is an application bug ! but we try some cleanup to hopefully avoid crashes, see below
397 bHasFocusedChild = true;
398 #if OSL_DEBUG_LEVEL > 0
399 OUString aTempStr = "Window (" + GetText() +
400 ") with focused child window destroyed ! THIS WILL LEAD TO CRASHES AND MUST BE FIXED !";
401 SAL_WARN( "vcl", aTempStr );
402 Application::Abort(aTempStr);
403 #endif
406 // if we get focus pass focus to another window
407 vcl::Window* pOverlapWindow = ImplGetFirstOverlapWindow();
408 if (pSVData->mpWinData->mpFocusWin == this
409 || bHasFocusedChild) // #122232#, see above, try some cleanup
411 if ( mpWindowImpl->mbFrame )
413 pSVData->mpWinData->mpFocusWin = nullptr;
414 pOverlapWindow->mpWindowImpl->mpLastFocusWindow = nullptr;
416 else
418 vcl::Window* pParent = GetParent();
419 vcl::Window* pBorderWindow = mpWindowImpl->mpBorderWindow;
420 // when windows overlap, give focus to the parent
421 // of the next FrameWindow
422 if ( pBorderWindow )
424 if ( pBorderWindow->ImplIsOverlapWindow() )
425 pParent = pBorderWindow->mpWindowImpl->mpOverlapWindow;
427 else if ( ImplIsOverlapWindow() )
428 pParent = mpWindowImpl->mpOverlapWindow;
430 if ( pParent && pParent->IsEnabled() && pParent->IsInputEnabled() && ! pParent->IsInModalMode() )
431 pParent->GrabFocus();
432 else
433 mpWindowImpl->mpFrameWindow->GrabFocus();
435 // If the focus was set back to 'this' set it to nothing
436 if (pSVData->mpWinData->mpFocusWin == this)
438 pSVData->mpWinData->mpFocusWin = nullptr;
439 pOverlapWindow->mpWindowImpl->mpLastFocusWindow = nullptr;
444 if ( pOverlapWindow != nullptr &&
445 pOverlapWindow->mpWindowImpl->mpLastFocusWindow == this )
446 pOverlapWindow->mpWindowImpl->mpLastFocusWindow = nullptr;
448 // reset hint for DefModalDialogParent
449 if( pSVData->maFrameData.mpActiveApplicationFrame == this )
450 pSVData->maFrameData.mpActiveApplicationFrame = nullptr;
452 // reset hint of what was the last wheeled window
453 if (pSVData->mpWinData->mpLastWheelWindow == this)
454 pSVData->mpWinData->mpLastWheelWindow = nullptr;
456 // reset marked windows
457 if ( mpWindowImpl->mpFrameData != nullptr )
459 if ( mpWindowImpl->mpFrameData->mpFocusWin == this )
460 mpWindowImpl->mpFrameData->mpFocusWin = nullptr;
461 if ( mpWindowImpl->mpFrameData->mpMouseMoveWin == this )
462 mpWindowImpl->mpFrameData->mpMouseMoveWin = nullptr;
463 if ( mpWindowImpl->mpFrameData->mpMouseDownWin == this )
464 mpWindowImpl->mpFrameData->mpMouseDownWin = nullptr;
467 // reset Deactivate-Window
468 if (pSVData->mpWinData->mpLastDeacWin == this)
469 pSVData->mpWinData->mpLastDeacWin = nullptr;
471 if ( mpWindowImpl->mbFrame && mpWindowImpl->mpFrameData )
473 if ( mpWindowImpl->mpFrameData->mnFocusId )
474 Application::RemoveUserEvent( mpWindowImpl->mpFrameData->mnFocusId );
475 mpWindowImpl->mpFrameData->mnFocusId = nullptr;
476 if ( mpWindowImpl->mpFrameData->mnMouseMoveId )
477 Application::RemoveUserEvent( mpWindowImpl->mpFrameData->mnMouseMoveId );
478 mpWindowImpl->mpFrameData->mnMouseMoveId = nullptr;
481 // release SalGraphics
482 VclPtr<OutputDevice> pOutDev = GetOutDev();
483 pOutDev->ReleaseGraphics();
485 // remove window from the lists
486 ImplRemoveWindow( true );
488 // de-register as "top window child" at our parent, if necessary
489 if ( mpWindowImpl->mbFrame )
491 bool bIsTopWindow
492 = mpWindowImpl->mpWinData && (mpWindowImpl->mpWinData->mnIsTopWindow == 1);
493 if ( mpWindowImpl->mpRealParent && bIsTopWindow )
495 ImplWinData* pParentWinData = mpWindowImpl->mpRealParent->ImplGetWinData();
497 auto myPos = ::std::find( pParentWinData->maTopWindowChildren.begin(),
498 pParentWinData->maTopWindowChildren.end(), VclPtr<vcl::Window>(this) );
499 SAL_WARN_IF( myPos == pParentWinData->maTopWindowChildren.end(), "vcl.window", "Window::~Window: inconsistency in top window chain!" );
500 if ( myPos != pParentWinData->maTopWindowChildren.end() )
501 pParentWinData->maTopWindowChildren.erase( myPos );
505 mpWindowImpl->mpWinData.reset();
507 // remove BorderWindow or Frame window data
508 mpWindowImpl->mpBorderWindow.disposeAndClear();
509 if ( mpWindowImpl->mbFrame )
511 if ( pSVData->maFrameData.mpFirstFrame == this )
512 pSVData->maFrameData.mpFirstFrame = mpWindowImpl->mpFrameData->mpNextFrame;
513 else
515 sal_Int32 nWindows = 0;
516 vcl::Window* pSysWin = pSVData->maFrameData.mpFirstFrame;
517 while ( pSysWin && pSysWin->mpWindowImpl->mpFrameData->mpNextFrame.get() != this )
519 pSysWin = pSysWin->mpWindowImpl->mpFrameData->mpNextFrame;
520 nWindows++;
523 if ( pSysWin )
525 assert (mpWindowImpl->mpFrameData->mpNextFrame.get() != pSysWin);
526 pSysWin->mpWindowImpl->mpFrameData->mpNextFrame = mpWindowImpl->mpFrameData->mpNextFrame;
528 else // if it is not in the list, we can't remove it.
529 SAL_WARN("vcl.window", "Window " << this << " marked as frame window, "
530 "is missing from list of " << nWindows << " frames");
532 if (mpWindowImpl->mpFrame) // otherwise exception during init
534 mpWindowImpl->mpFrame->SetCallback( nullptr, nullptr );
535 pSVData->mpDefInst->DestroyFrame( mpWindowImpl->mpFrame );
537 assert (mpWindowImpl->mpFrameData->mnFocusId == nullptr);
538 assert (mpWindowImpl->mpFrameData->mnMouseMoveId == nullptr);
540 mpWindowImpl->mpFrameData->mpBuffer.disposeAndClear();
541 delete mpWindowImpl->mpFrameData;
542 mpWindowImpl->mpFrameData = nullptr;
545 if (mpWindowImpl->mxWindowPeer)
546 mpWindowImpl->mxWindowPeer->dispose();
548 // should be the last statements
549 mpWindowImpl.reset();
551 pOutDev.disposeAndClear();
552 // just to make loplugin:vclwidgets happy
553 VclReferenceBase::dispose();
556 Window::~Window()
558 disposeOnce();
561 // We will eventually being removing the inheritance of OutputDevice
562 // from Window. It will be replaced with a transient relationship such
563 // that the OutputDevice is only live for the scope of the Paint method.
564 // In the meantime this can help move us towards a Window use an
565 // OutputDevice, not being one.
567 ::OutputDevice const* Window::GetOutDev() const
569 return mpWindowImpl ? mpWindowImpl->mxOutDev.get() : nullptr;
572 ::OutputDevice* Window::GetOutDev()
574 return mpWindowImpl ? mpWindowImpl->mxOutDev.get() : nullptr;
577 Color WindowOutputDevice::GetBackgroundColor() const
579 return mxOwnerWindow->GetDisplayBackground().GetColor();
582 bool WindowOutputDevice::CanEnableNativeWidget() const
584 return mxOwnerWindow->IsNativeWidgetEnabled();
587 } /* namespace vcl */
589 WindowImpl::WindowImpl( vcl::Window& rWindow, WindowType nType )
591 mxOutDev = VclPtr<vcl::WindowOutputDevice>::Create(rWindow);
592 maZoom = Fraction( 1, 1 );
593 mfPartialScrollX = 0.0;
594 mfPartialScrollY = 0.0;
595 maWinRegion = vcl::Region(true);
596 maWinClipRegion = vcl::Region(true);
597 mpWinData = nullptr; // Extra Window Data, that we don't need for all windows
598 mpFrameData = nullptr; // Frame Data
599 mpFrame = nullptr; // Pointer to frame window
600 mpSysObj = nullptr;
601 mpFrameWindow = nullptr; // window to top level parent (same as frame window)
602 mpOverlapWindow = nullptr; // first overlap parent
603 mpBorderWindow = nullptr; // Border-Window
604 mpClientWindow = nullptr; // Client-Window of a FrameWindow
605 mpParent = nullptr; // parent (incl. BorderWindow)
606 mpRealParent = nullptr; // real parent (excl. BorderWindow)
607 mpFirstChild = nullptr; // first child window
608 mpLastChild = nullptr; // last child window
609 mpFirstOverlap = nullptr; // first overlap window (only set in overlap windows)
610 mpLastOverlap = nullptr; // last overlap window (only set in overlap windows)
611 mpPrev = nullptr; // prev window
612 mpNext = nullptr; // next window
613 mpNextOverlap = nullptr; // next overlap window of frame
614 mpLastFocusWindow = nullptr; // window for focus restore
615 mpDlgCtrlDownWindow = nullptr; // window for dialog control
616 mnEventListenersIteratingCount = 0;
617 mnChildEventListenersIteratingCount = 0;
618 mpCursor = nullptr; // cursor
619 maPointer = PointerStyle::Arrow;
620 mpVCLXWindow = nullptr;
621 mpAccessibleInfos = nullptr;
622 maControlForeground = COL_TRANSPARENT; // no foreground set
623 maControlBackground = COL_TRANSPARENT; // no background set
624 mnLeftBorder = 0; // left border
625 mnTopBorder = 0; // top border
626 mnRightBorder = 0; // right border
627 mnBottomBorder = 0; // bottom border
628 mnWidthRequest = -1; // width request
629 mnHeightRequest = -1; // height request
630 mnOptimalWidthCache = -1; // optimal width cache
631 mnOptimalHeightCache = -1; // optimal height cache
632 mnX = 0; // X-Position to Parent
633 mnY = 0; // Y-Position to Parent
634 mnAbsScreenX = 0; // absolute X-position on screen, used for RTL window positioning
635 mpChildClipRegion = nullptr; // Child-Clip-Region when ClipChildren
636 mpPaintRegion = nullptr; // Paint-ClipRegion
637 mnStyle = 0; // style (init in ImplInitWindow)
638 mnPrevStyle = 0; // prevstyle (set in SetStyle)
639 mnExtendedStyle = WindowExtendedStyle::NONE; // extended style (init in ImplInitWindow)
640 mnType = nType; // type
641 mnGetFocusFlags = GetFocusFlags::NONE; // Flags for GetFocus()-Call
642 mnWaitCount = 0; // Wait-Count (>1 == "wait" mouse pointer)
643 mnPaintFlags = ImplPaintFlags::NONE; // Flags for ImplCallPaint
644 mnParentClipMode = ParentClipMode::NONE; // Flags for Parent-ClipChildren-Mode
645 mnActivateMode = ActivateModeFlags::NONE; // Will be converted in System/Overlap-Windows
646 mnDlgCtrlFlags = DialogControlFlags::NONE; // DialogControl-Flags
647 meAlwaysInputMode = AlwaysInputNone; // AlwaysEnableInput not called
648 meHalign = VclAlign::Fill;
649 meValign = VclAlign::Fill;
650 mePackType = VclPackType::Start;
651 mnPadding = 0;
652 mnGridHeight = 1;
653 mnGridLeftAttach = -1;
654 mnGridTopAttach = -1;
655 mnGridWidth = 1;
656 mnBorderWidth = 0;
657 mnMarginLeft = 0;
658 mnMarginRight = 0;
659 mnMarginTop = 0;
660 mnMarginBottom = 0;
661 mbFrame = false; // true: Window is a frame window
662 mbBorderWin = false; // true: Window is a border window
663 mbOverlapWin = false; // true: Window is an overlap window
664 mbSysWin = false; // true: SystemWindow is the base class
665 mbDialog = false; // true: Dialog is the base class
666 mbDockWin = false; // true: DockingWindow is the base class
667 mbFloatWin = false; // true: FloatingWindow is the base class
668 mbPushButton = false; // true: PushButton is the base class
669 mbToolBox = false; // true: ToolBox is the base class
670 mbMenuFloatingWindow = false; // true: MenuFloatingWindow is the base class
671 mbToolbarFloatingWindow = false; // true: ImplPopupFloatWin is the base class, used for subtoolbars
672 mbSplitter = false; // true: Splitter is the base class
673 mbVisible = false; // true: Show( true ) called
674 mbOverlapVisible = false; // true: Hide called for visible window from ImplHideAllOverlapWindow()
675 mbDisabled = false; // true: Enable( false ) called
676 mbInputDisabled = false; // true: EnableInput( false ) called
677 mbNoUpdate = false; // true: SetUpdateMode( false ) called
678 mbNoParentUpdate = false; // true: SetParentUpdateMode( false ) called
679 mbActive = false; // true: Window Active
680 mbReallyVisible = false; // true: this and all parents to an overlapped window are visible
681 mbReallyShown = false; // true: this and all parents to an overlapped window are shown
682 mbInInitShow = false; // true: we are in InitShow
683 mbChildPtrOverwrite = false; // true: PointerStyle overwrites Child-Pointer
684 mbNoPtrVisible = false; // true: ShowPointer( false ) called
685 mbPaintFrame = false; // true: Paint is visible, but not painted
686 mbInPaint = false; // true: Inside PaintHdl
687 mbMouseButtonDown = false; // true: BaseMouseButtonDown called
688 mbMouseButtonUp = false; // true: BaseMouseButtonUp called
689 mbKeyInput = false; // true: BaseKeyInput called
690 mbKeyUp = false; // true: BaseKeyUp called
691 mbCommand = false; // true: BaseCommand called
692 mbDefPos = true; // true: Position is not Set
693 mbDefSize = true; // true: Size is not Set
694 mbCallMove = true; // true: Move must be called by Show
695 mbCallResize = true; // true: Resize must be called by Show
696 mbWaitSystemResize = true; // true: Wait for System-Resize
697 mbInitWinClipRegion = true; // true: Calc Window Clip Region
698 mbInitChildRegion = false; // true: InitChildClipRegion
699 mbWinRegion = false; // true: Window Region
700 mbClipChildren = false; // true: Child-window should be clipped
701 mbClipSiblings = false; // true: Adjacent Child-window should be clipped
702 mbChildTransparent = false; // true: Child-windows are allowed to switch to transparent (incl. Parent-CLIPCHILDREN)
703 mbPaintTransparent = false; // true: Paints should be executed on the Parent
704 mbMouseTransparent = false; // true: Window is transparent for Mouse
705 mbDlgCtrlStart = false; // true: From here on own Dialog-Control
706 mbFocusVisible = false; // true: Focus Visible
707 mbUseNativeFocus = false;
708 mbNativeFocusVisible = false; // true: native Focus Visible
709 mbInShowFocus = false; // prevent recursion
710 mbInHideFocus = false; // prevent recursion
711 mbTrackVisible = false; // true: Tracking Visible
712 mbControlForeground = false; // true: Foreground-Property set
713 mbControlBackground = false; // true: Background-Property set
714 mbAlwaysOnTop = false; // true: always visible for all others windows
715 mbCompoundControl = false; // true: Composite Control => Listener...
716 mbCompoundControlHasFocus = false; // true: Composite Control has focus somewhere
717 mbPaintDisabled = false; // true: Paint should not be executed
718 mbAllResize = false; // true: Also sent ResizeEvents with 0,0
719 mbInDispose = false; // true: We're still in Window::dispose()
720 mbExtTextInput = false; // true: ExtTextInput-Mode is active
721 mbInFocusHdl = false; // true: Within GetFocus-Handler
722 mbCreatedWithToolkit = false;
723 mbSuppressAccessibilityEvents = false; // true: do not send any accessibility events
724 mbDrawSelectionBackground = false; // true: draws transparent window background to indicate (toolbox) selection
725 mbIsInTaskPaneList = false; // true: window was added to the taskpanelist in the topmost system window
726 mnNativeBackground = ControlPart::NONE; // initialize later, depends on type
727 mbHelpTextDynamic = false; // true: append help id in HELP_DEBUG case
728 mbFakeFocusSet = false; // true: pretend as if the window has focus.
729 mbHexpand = false;
730 mbVexpand = false;
731 mbExpand = false;
732 mbFill = true;
733 mbSecondary = false;
734 mbNonHomogeneous = false;
735 static bool bDoubleBuffer = getenv("VCL_DOUBLEBUFFERING_FORCE_ENABLE");
736 mbDoubleBufferingRequested = bDoubleBuffer; // when we are not sure, assume it cannot do double-buffering via RenderContext
737 mpLOKNotifier = nullptr;
738 mnLOKWindowId = 0;
739 mbUseFrameData = false;
742 WindowImpl::~WindowImpl()
744 mpChildClipRegion.reset();
745 mpAccessibleInfos.reset();
748 ImplWinData::ImplWinData() :
749 mnCursorExtWidth(0),
750 mbVertical(false),
751 mnCompositionCharRects(0),
752 mnTrackFlags(ShowTrackFlags::NONE),
753 mnIsTopWindow(sal_uInt16(~0)), // not initialized yet, 0/1 will indicate TopWindow (see IsTopWindow())
754 mbMouseOver(false),
755 mbEnableNativeWidget(false)
759 ImplWinData::~ImplWinData()
761 mpCompositionCharRects.reset();
764 ImplFrameData::ImplFrameData( vcl::Window *pWindow )
765 : maPaintIdle( "vcl::Window maPaintIdle" ),
766 maResizeIdle( "vcl::Window maResizeIdle" )
768 ImplSVData* pSVData = ImplGetSVData();
769 assert (pSVData->maFrameData.mpFirstFrame.get() != pWindow);
770 mpNextFrame = pSVData->maFrameData.mpFirstFrame;
771 pSVData->maFrameData.mpFirstFrame = pWindow;
772 mpFirstOverlap = nullptr;
773 mpFocusWin = nullptr;
774 mpMouseMoveWin = nullptr;
775 mpMouseDownWin = nullptr;
776 mpTrackWin = nullptr;
777 mxFontCollection = pSVData->maGDIData.mxScreenFontList;
778 mxFontCache = pSVData->maGDIData.mxScreenFontCache;
779 mnFocusId = nullptr;
780 mnMouseMoveId = nullptr;
781 mnLastMouseX = -1;
782 mnLastMouseY = -1;
783 mnBeforeLastMouseX = -1;
784 mnBeforeLastMouseY = -1;
785 mnFirstMouseX = -1;
786 mnFirstMouseY = -1;
787 mnLastMouseWinX = -1;
788 mnLastMouseWinY = -1;
789 mnModalMode = 0;
790 mnMouseDownTime = 0;
791 mnClickCount = 0;
792 mnFirstMouseCode = 0;
793 mnMouseCode = 0;
794 mnMouseMode = MouseEventModifiers::NONE;
795 mbHasFocus = false;
796 mbInMouseMove = false;
797 mbMouseIn = false;
798 mbStartDragCalled = false;
799 mbNeedSysWindow = false;
800 mbMinimized = false;
801 mbStartFocusState = false;
802 mbInSysObjFocusHdl = false;
803 mbInSysObjToTopHdl = false;
804 mbSysObjFocus = false;
805 maPaintIdle.SetPriority( TaskPriority::REPAINT );
806 maPaintIdle.SetInvokeHandler( LINK( pWindow, vcl::Window, ImplHandlePaintHdl ) );
807 maResizeIdle.SetPriority( TaskPriority::RESIZE );
808 maResizeIdle.SetInvokeHandler( LINK( pWindow, vcl::Window, ImplHandleResizeTimerHdl ) );
809 mbInternalDragGestureRecognizer = false;
810 mbDragging = false;
811 mbInBufferedPaint = false;
812 mnDPIX = 96;
813 mnDPIY = 96;
814 mnTouchPanPosition = -1;
817 namespace vcl {
819 bool WindowOutputDevice::AcquireGraphics() const
821 DBG_TESTSOLARMUTEX();
823 if (isDisposed())
824 return false;
826 if (mpGraphics)
827 return true;
829 mbInitLineColor = true;
830 mbInitFillColor = true;
831 mbInitFont = true;
832 mbInitTextColor = true;
833 mbInitClipRegion = true;
835 ImplSVData* pSVData = ImplGetSVData();
837 mpGraphics = mxOwnerWindow->mpWindowImpl->mpFrame->AcquireGraphics();
838 // try harder if no wingraphics was available directly
839 if ( !mpGraphics )
841 // find another output device in the same frame
842 vcl::WindowOutputDevice* pReleaseOutDev = pSVData->maGDIData.mpLastWinGraphics.get();
843 while ( pReleaseOutDev )
845 if ( pReleaseOutDev->mxOwnerWindow && pReleaseOutDev->mxOwnerWindow->mpWindowImpl->mpFrame == mxOwnerWindow->mpWindowImpl->mpFrame )
846 break;
847 pReleaseOutDev = static_cast<vcl::WindowOutputDevice*>(pReleaseOutDev->mpPrevGraphics.get());
850 if ( pReleaseOutDev )
852 // steal the wingraphics from the other outdev
853 mpGraphics = pReleaseOutDev->mpGraphics;
854 pReleaseOutDev->ReleaseGraphics( false );
856 else
858 // if needed retry after releasing least recently used wingraphics
859 while ( !mpGraphics )
861 if ( !pSVData->maGDIData.mpLastWinGraphics )
862 break;
863 pSVData->maGDIData.mpLastWinGraphics->ReleaseGraphics();
864 mpGraphics = mxOwnerWindow->mpWindowImpl->mpFrame->AcquireGraphics();
869 if ( mpGraphics )
871 // update global LRU list of wingraphics
872 mpNextGraphics = pSVData->maGDIData.mpFirstWinGraphics.get();
873 pSVData->maGDIData.mpFirstWinGraphics = const_cast<vcl::WindowOutputDevice*>(this);
874 if ( mpNextGraphics )
875 mpNextGraphics->mpPrevGraphics = const_cast<vcl::WindowOutputDevice*>(this);
876 if ( !pSVData->maGDIData.mpLastWinGraphics )
877 pSVData->maGDIData.mpLastWinGraphics = const_cast<vcl::WindowOutputDevice*>(this);
879 mpGraphics->SetXORMode( (RasterOp::Invert == meRasterOp) || (RasterOp::Xor == meRasterOp), RasterOp::Invert == meRasterOp );
880 mpGraphics->setAntiAlias(bool(mnAntialiasing & AntialiasingFlags::Enable));
883 return mpGraphics != nullptr;
886 void WindowOutputDevice::ReleaseGraphics( bool bRelease )
888 DBG_TESTSOLARMUTEX();
890 if ( !mpGraphics )
891 return;
893 // release the fonts of the physically released graphics device
894 if( bRelease )
895 ImplReleaseFonts();
897 ImplSVData* pSVData = ImplGetSVData();
899 vcl::Window* pWindow = mxOwnerWindow.get();
900 if (!pWindow)
901 return;
903 if ( bRelease )
904 pWindow->mpWindowImpl->mpFrame->ReleaseGraphics( mpGraphics );
905 // remove from global LRU list of window graphics
906 if ( mpPrevGraphics )
907 mpPrevGraphics->mpNextGraphics = mpNextGraphics;
908 else
909 pSVData->maGDIData.mpFirstWinGraphics = static_cast<vcl::WindowOutputDevice*>(mpNextGraphics.get());
910 if ( mpNextGraphics )
911 mpNextGraphics->mpPrevGraphics = mpPrevGraphics;
912 else
913 pSVData->maGDIData.mpLastWinGraphics = static_cast<vcl::WindowOutputDevice*>(mpPrevGraphics.get());
915 mpGraphics = nullptr;
916 mpPrevGraphics = nullptr;
917 mpNextGraphics = nullptr;
920 static sal_Int32 CountDPIScaleFactor(sal_Int32 nDPI)
922 #ifndef MACOSX
923 // Setting of HiDPI is unfortunately all only a heuristic; and to add
924 // insult to an injury, the system is constantly lying to us about
925 // the DPI and whatnot
926 // eg. fdo#77059 - set the value from which we do consider the
927 // screen HiDPI to greater than 168
928 if (nDPI > 216) // 96 * 2 + 96 / 4
929 return 250;
930 else if (nDPI > 168) // 96 * 2 - 96 / 4
931 return 200;
932 else if (nDPI > 120) // 96 * 1.5 - 96 / 4
933 return 150;
934 #else
935 (void)nDPI;
936 #endif
938 return 100;
941 void Window::ImplInit( vcl::Window* pParent, WinBits nStyle, SystemParentData* pSystemParentData )
943 SAL_WARN_IF( !mpWindowImpl->mbFrame && !pParent && GetType() != WindowType::FIXEDIMAGE, "vcl.window",
944 "Window::Window(): pParent == NULL" );
946 ImplSVData* pSVData = ImplGetSVData();
947 vcl::Window* pRealParent = pParent;
949 // inherit 3D look
950 if ( !mpWindowImpl->mbOverlapWin && pParent && (pParent->GetStyle() & WB_3DLOOK) )
951 nStyle |= WB_3DLOOK;
953 // create border window if necessary
954 if ( !mpWindowImpl->mbFrame && !mpWindowImpl->mbBorderWin && !mpWindowImpl->mpBorderWindow
955 && (nStyle & (WB_BORDER | WB_SYSTEMCHILDWINDOW) ) )
957 BorderWindowStyle nBorderTypeStyle = BorderWindowStyle::NONE;
958 if( nStyle & WB_SYSTEMCHILDWINDOW )
960 // handle WB_SYSTEMCHILDWINDOW
961 // these should be analogous to a top level frame; meaning they
962 // should have a border window with style BorderWindowStyle::Frame
963 // which controls their size
964 nBorderTypeStyle |= BorderWindowStyle::Frame;
965 nStyle |= WB_BORDER;
967 VclPtrInstance<ImplBorderWindow> pBorderWin( pParent, nStyle & (WB_BORDER | WB_DIALOGCONTROL | WB_NODIALOGCONTROL), nBorderTypeStyle );
968 static_cast<vcl::Window*>(pBorderWin)->mpWindowImpl->mpClientWindow = this;
969 pBorderWin->GetBorder( mpWindowImpl->mnLeftBorder, mpWindowImpl->mnTopBorder, mpWindowImpl->mnRightBorder, mpWindowImpl->mnBottomBorder );
970 mpWindowImpl->mpBorderWindow = pBorderWin;
971 pParent = mpWindowImpl->mpBorderWindow;
973 else if( !mpWindowImpl->mbFrame && ! pParent )
975 mpWindowImpl->mbOverlapWin = true;
976 mpWindowImpl->mbFrame = true;
979 // insert window in list
980 ImplInsertWindow( pParent );
981 mpWindowImpl->mnStyle = nStyle;
983 if( pParent && ! mpWindowImpl->mbFrame )
984 mpWindowImpl->mxOutDev->mbEnableRTL = AllSettings::GetLayoutRTL();
986 // test for frame creation
987 if ( mpWindowImpl->mbFrame )
989 // create frame
990 SalFrameStyleFlags nFrameStyle = SalFrameStyleFlags::NONE;
992 if ( nStyle & WB_MOVEABLE )
993 nFrameStyle |= SalFrameStyleFlags::MOVEABLE;
994 if ( nStyle & WB_SIZEABLE )
995 nFrameStyle |= SalFrameStyleFlags::SIZEABLE;
996 if ( nStyle & WB_CLOSEABLE )
997 nFrameStyle |= SalFrameStyleFlags::CLOSEABLE;
998 if ( nStyle & WB_APP )
999 nFrameStyle |= SalFrameStyleFlags::DEFAULT;
1000 // check for undecorated floating window
1001 if( // 1. floating windows that are not moveable/sizeable (only closeable allowed)
1002 ( !(nFrameStyle & ~SalFrameStyleFlags::CLOSEABLE) &&
1003 ( mpWindowImpl->mbFloatWin || ((GetType() == WindowType::BORDERWINDOW) && static_cast<ImplBorderWindow*>(this)->mbFloatWindow) || (nStyle & WB_SYSTEMFLOATWIN) ) ) ||
1004 // 2. borderwindows of floaters with ownerdraw decoration
1005 ((GetType() == WindowType::BORDERWINDOW) && static_cast<ImplBorderWindow*>(this)->mbFloatWindow && (nStyle & WB_OWNERDRAWDECORATION) ) )
1007 nFrameStyle = SalFrameStyleFlags::FLOAT;
1008 if( nStyle & WB_OWNERDRAWDECORATION )
1009 nFrameStyle |= SalFrameStyleFlags::OWNERDRAWDECORATION | SalFrameStyleFlags::NOSHADOW;
1011 else if( mpWindowImpl->mbFloatWin )
1012 nFrameStyle |= SalFrameStyleFlags::TOOLWINDOW;
1014 if( nStyle & WB_INTROWIN )
1015 nFrameStyle |= SalFrameStyleFlags::INTRO;
1016 if( nStyle & WB_TOOLTIPWIN )
1017 nFrameStyle |= SalFrameStyleFlags::TOOLTIP;
1019 if( nStyle & WB_NOSHADOW )
1020 nFrameStyle |= SalFrameStyleFlags::NOSHADOW;
1022 if( nStyle & WB_SYSTEMCHILDWINDOW )
1023 nFrameStyle |= SalFrameStyleFlags::SYSTEMCHILD;
1025 switch (mpWindowImpl->mnType)
1027 case WindowType::DIALOG:
1028 case WindowType::TABDIALOG:
1029 case WindowType::MODELESSDIALOG:
1030 case WindowType::MESSBOX:
1031 case WindowType::INFOBOX:
1032 case WindowType::WARNINGBOX:
1033 case WindowType::ERRORBOX:
1034 case WindowType::QUERYBOX:
1035 nFrameStyle |= SalFrameStyleFlags::DIALOG;
1036 break;
1037 default:
1038 break;
1041 // tdf#144624 for the DefaultWindow, which is never visible, don't
1042 // create an icon for it so construction of a DefaultWindow cannot
1043 // trigger creation of a VirtualDevice which itself requires a
1044 // DefaultWindow to exist
1045 if( nStyle & WB_DEFAULTWIN )
1046 nFrameStyle |= SalFrameStyleFlags::NOICON;
1048 SalFrame* pParentFrame = nullptr;
1049 if ( pParent )
1050 pParentFrame = pParent->mpWindowImpl->mpFrame;
1051 SalFrame* pFrame;
1052 if ( pSystemParentData )
1053 pFrame = pSVData->mpDefInst->CreateChildFrame( pSystemParentData, nFrameStyle | SalFrameStyleFlags::PLUG );
1054 else
1055 pFrame = pSVData->mpDefInst->CreateFrame( pParentFrame, nFrameStyle );
1056 if ( !pFrame )
1058 // do not abort but throw an exception, may be the current thread terminates anyway (plugin-scenario)
1059 throw RuntimeException(
1060 "Could not create system window!",
1061 Reference< XInterface >() );
1064 pFrame->SetCallback( this, ImplWindowFrameProc );
1066 // set window frame data
1067 mpWindowImpl->mpFrameData = new ImplFrameData( this );
1068 mpWindowImpl->mpFrame = pFrame;
1069 mpWindowImpl->mpFrameWindow = this;
1070 mpWindowImpl->mpOverlapWindow = this;
1072 if (!(nStyle & WB_DEFAULTWIN) && mpWindowImpl->mbDoubleBufferingRequested)
1073 RequestDoubleBuffering(true);
1075 if ( pRealParent && IsTopWindow() )
1077 ImplWinData* pParentWinData = pRealParent->ImplGetWinData();
1078 pParentWinData->maTopWindowChildren.emplace_back(this );
1082 // init data
1083 mpWindowImpl->mpRealParent = pRealParent;
1085 // #99318: make sure fontcache and list is available before call to SetSettings
1086 mpWindowImpl->mxOutDev->mxFontCollection = mpWindowImpl->mpFrameData->mxFontCollection;
1087 mpWindowImpl->mxOutDev->mxFontCache = mpWindowImpl->mpFrameData->mxFontCache;
1089 if ( mpWindowImpl->mbFrame )
1091 if ( pParent )
1093 mpWindowImpl->mpFrameData->mnDPIX = pParent->mpWindowImpl->mpFrameData->mnDPIX;
1094 mpWindowImpl->mpFrameData->mnDPIY = pParent->mpWindowImpl->mpFrameData->mnDPIY;
1096 else
1098 OutputDevice *pOutDev = GetOutDev();
1099 if ( pOutDev->AcquireGraphics() )
1101 mpWindowImpl->mxOutDev->mpGraphics->GetResolution( mpWindowImpl->mpFrameData->mnDPIX, mpWindowImpl->mpFrameData->mnDPIY );
1105 // add ownerdraw decorated frame windows to list in the top-most frame window
1106 // so they can be hidden on lose focus
1107 if( nStyle & WB_OWNERDRAWDECORATION )
1108 ImplGetOwnerDrawList().emplace_back(this );
1110 // delay settings initialization until first "real" frame
1111 // this relies on the IntroWindow not needing any system settings
1112 if ( !pSVData->maAppData.mbSettingsInit &&
1113 ! (nStyle & (WB_INTROWIN|WB_DEFAULTWIN))
1116 // side effect: ImplUpdateGlobalSettings does an ImplGetFrame()->UpdateSettings
1117 ImplUpdateGlobalSettings( *pSVData->maAppData.mxSettings );
1118 mpWindowImpl->mxOutDev->SetSettings( *pSVData->maAppData.mxSettings );
1119 pSVData->maAppData.mbSettingsInit = true;
1122 // If we create a Window with default size, query this
1123 // size directly, because we want resize all Controls to
1124 // the correct size before we display the window
1125 if ( nStyle & (WB_MOVEABLE | WB_SIZEABLE | WB_APP) )
1126 mpWindowImpl->mpFrame->GetClientSize( mpWindowImpl->mxOutDev->mnOutWidth, mpWindowImpl->mxOutDev->mnOutHeight );
1128 else
1130 if ( pParent )
1132 if ( !ImplIsOverlapWindow() )
1134 mpWindowImpl->mbDisabled = pParent->mpWindowImpl->mbDisabled;
1135 mpWindowImpl->mbInputDisabled = pParent->mpWindowImpl->mbInputDisabled;
1136 mpWindowImpl->meAlwaysInputMode = pParent->mpWindowImpl->meAlwaysInputMode;
1139 if (!utl::ConfigManager::IsFuzzing())
1141 // we don't want to call the WindowOutputDevice override of this because
1142 // it calls back into us.
1143 mpWindowImpl->mxOutDev->OutputDevice::SetSettings( pParent->GetSettings() );
1149 // setup the scale factor for HiDPI displays
1150 mpWindowImpl->mxOutDev->mnDPIScalePercentage = CountDPIScaleFactor(mpWindowImpl->mpFrameData->mnDPIY);
1151 mpWindowImpl->mxOutDev->mnDPIX = mpWindowImpl->mpFrameData->mnDPIX;
1152 mpWindowImpl->mxOutDev->mnDPIY = mpWindowImpl->mpFrameData->mnDPIY;
1154 if (!utl::ConfigManager::IsFuzzing())
1156 const StyleSettings& rStyleSettings = mpWindowImpl->mxOutDev->moSettings->GetStyleSettings();
1157 mpWindowImpl->mxOutDev->maFont = rStyleSettings.GetAppFont();
1159 if ( nStyle & WB_3DLOOK )
1161 SetTextColor( rStyleSettings.GetButtonTextColor() );
1162 SetBackground( Wallpaper( rStyleSettings.GetFaceColor() ) );
1164 else
1166 SetTextColor( rStyleSettings.GetWindowTextColor() );
1167 SetBackground( Wallpaper( rStyleSettings.GetWindowColor() ) );
1170 else
1172 mpWindowImpl->mxOutDev->maFont = OutputDevice::GetDefaultFont( DefaultFontType::FIXED, LANGUAGE_ENGLISH_US, GetDefaultFontFlags::NONE );
1175 ImplPointToLogic(*GetOutDev(), mpWindowImpl->mxOutDev->maFont);
1177 (void)ImplUpdatePos();
1179 // calculate app font res (except for the Intro Window or the default window)
1180 if ( mpWindowImpl->mbFrame && !pSVData->maGDIData.mnAppFontX && ! (nStyle & (WB_INTROWIN|WB_DEFAULTWIN)) )
1181 ImplInitAppFontData( this );
1184 void Window::ImplInitAppFontData( vcl::Window const * pWindow )
1186 ImplSVData* pSVData = ImplGetSVData();
1187 tools::Long nTextHeight = pWindow->GetTextHeight();
1188 tools::Long nTextWidth = pWindow->approximate_char_width() * 8;
1189 tools::Long nSymHeight = nTextHeight*4;
1190 // Make the basis wider if the font is too narrow
1191 // such that the dialog looks symmetrical and does not become too narrow.
1192 // Add some extra space when the dialog has the same width,
1193 // as a little more space is better.
1194 if ( nSymHeight > nTextWidth )
1195 nTextWidth = nSymHeight;
1196 else if ( nSymHeight+5 > nTextWidth )
1197 nTextWidth = nSymHeight+5;
1198 pSVData->maGDIData.mnAppFontX = nTextWidth * 10 / 8;
1199 pSVData->maGDIData.mnAppFontY = nTextHeight * 10;
1201 #ifdef MACOSX
1202 // FIXME: this is currently only on macOS, check with other
1203 // platforms
1204 if( pSVData->maNWFData.mbNoFocusRects )
1206 // try to find out whether there is a large correction
1207 // of control sizes, if yes, make app font scalings larger
1208 // so dialog positioning is not completely off
1209 ImplControlValue aControlValue;
1210 tools::Rectangle aCtrlRegion( Point(), Size( nTextWidth < 10 ? 10 : nTextWidth, nTextHeight < 10 ? 10 : nTextHeight ) );
1211 tools::Rectangle aBoundingRgn( aCtrlRegion );
1212 tools::Rectangle aContentRgn( aCtrlRegion );
1213 if( pWindow->GetNativeControlRegion( ControlType::Editbox, ControlPart::Entire, aCtrlRegion,
1214 ControlState::ENABLED, aControlValue,
1215 aBoundingRgn, aContentRgn ) )
1217 // comment: the magical +6 is for the extra border in bordered
1218 // (which is the standard) edit fields
1219 if( aContentRgn.GetHeight() - nTextHeight > (nTextHeight+4)/4 )
1220 pSVData->maGDIData.mnAppFontY = (aContentRgn.GetHeight()-4) * 10;
1223 #endif
1226 ImplWinData* Window::ImplGetWinData() const
1228 if (!mpWindowImpl->mpWinData)
1230 static const char* pNoNWF = getenv( "SAL_NO_NWF" );
1232 const_cast<vcl::Window*>(this)->mpWindowImpl->mpWinData.reset(new ImplWinData);
1233 mpWindowImpl->mpWinData->mbEnableNativeWidget = !(pNoNWF && *pNoNWF); // true: try to draw this control with native theme API
1236 return mpWindowImpl->mpWinData.get();
1240 void WindowOutputDevice::CopyDeviceArea( SalTwoRect& aPosAry, bool bWindowInvalidate )
1242 if (aPosAry.mnSrcWidth == 0 || aPosAry.mnSrcHeight == 0 || aPosAry.mnDestWidth == 0 || aPosAry.mnDestHeight == 0)
1243 return;
1245 if (bWindowInvalidate)
1247 const tools::Rectangle aSrcRect(Point(aPosAry.mnSrcX, aPosAry.mnSrcY),
1248 Size(aPosAry.mnSrcWidth, aPosAry.mnSrcHeight));
1250 mxOwnerWindow->ImplMoveAllInvalidateRegions(aSrcRect,
1251 aPosAry.mnDestX-aPosAry.mnSrcX,
1252 aPosAry.mnDestY-aPosAry.mnSrcY,
1253 false);
1255 mpGraphics->CopyArea(aPosAry.mnDestX, aPosAry.mnDestY,
1256 aPosAry.mnSrcX, aPosAry.mnSrcY,
1257 aPosAry.mnSrcWidth, aPosAry.mnSrcHeight,
1258 *this);
1260 return;
1263 OutputDevice::CopyDeviceArea(aPosAry, bWindowInvalidate);
1266 const OutputDevice* WindowOutputDevice::DrawOutDevDirectCheck(const OutputDevice& rSrcDev) const
1268 const OutputDevice* pSrcDevChecked;
1269 if ( this == &rSrcDev )
1270 pSrcDevChecked = nullptr;
1271 else if (GetOutDevType() != rSrcDev.GetOutDevType())
1272 pSrcDevChecked = &rSrcDev;
1273 else if (mxOwnerWindow->mpWindowImpl->mpFrameWindow == static_cast<const vcl::WindowOutputDevice&>(rSrcDev).mxOwnerWindow->mpWindowImpl->mpFrameWindow)
1274 pSrcDevChecked = nullptr;
1275 else
1276 pSrcDevChecked = &rSrcDev;
1278 return pSrcDevChecked;
1281 void WindowOutputDevice::DrawOutDevDirectProcess( const OutputDevice& rSrcDev, SalTwoRect& rPosAry, SalGraphics* pSrcGraphics )
1283 if (pSrcGraphics)
1284 mpGraphics->CopyBits(rPosAry, *pSrcGraphics, *this, rSrcDev);
1285 else
1286 mpGraphics->CopyBits(rPosAry, *this);
1289 SalGraphics* Window::ImplGetFrameGraphics() const
1291 if ( mpWindowImpl->mpFrameWindow->GetOutDev()->mpGraphics )
1293 mpWindowImpl->mpFrameWindow->GetOutDev()->mbInitClipRegion = true;
1295 else
1297 OutputDevice* pFrameWinOutDev = mpWindowImpl->mpFrameWindow->GetOutDev();
1298 if ( ! pFrameWinOutDev->AcquireGraphics() )
1300 return nullptr;
1303 mpWindowImpl->mpFrameWindow->GetOutDev()->mpGraphics->ResetClipRegion();
1304 return mpWindowImpl->mpFrameWindow->GetOutDev()->mpGraphics;
1307 void Window::ImplSetReallyVisible()
1309 // #i43594# it is possible that INITSHOW was never send, because the visibility state changed between
1310 // ImplCallInitShow() and ImplSetReallyVisible() when called from Show()
1311 // mbReallyShown is a useful indicator
1312 if( !mpWindowImpl->mbReallyShown )
1313 ImplCallInitShow();
1315 bool bBecameReallyVisible = !mpWindowImpl->mbReallyVisible;
1317 GetOutDev()->mbDevOutput = true;
1318 mpWindowImpl->mbReallyVisible = true;
1319 mpWindowImpl->mbReallyShown = true;
1321 // the SHOW/HIDE events serve as indicators to send child creation/destroy events to the access bridge.
1322 // For this, the data member of the event must not be NULL.
1323 // Previously, we did this in Window::Show, but there some events got lost in certain situations. Now
1324 // we're doing it when the visibility really changes
1325 if( bBecameReallyVisible && ImplIsAccessibleCandidate() )
1326 CallEventListeners( VclEventId::WindowShow, this );
1327 // TODO. It's kind of a hack that we're re-using the VclEventId::WindowShow. Normally, we should
1328 // introduce another event which explicitly triggers the Accessibility implementations.
1330 vcl::Window* pWindow = mpWindowImpl->mpFirstOverlap;
1331 while ( pWindow )
1333 if ( pWindow->mpWindowImpl->mbVisible )
1334 pWindow->ImplSetReallyVisible();
1335 pWindow = pWindow->mpWindowImpl->mpNext;
1338 pWindow = mpWindowImpl->mpFirstChild;
1339 while ( pWindow )
1341 if ( pWindow->mpWindowImpl->mbVisible )
1342 pWindow->ImplSetReallyVisible();
1343 pWindow = pWindow->mpWindowImpl->mpNext;
1347 void Window::ImplInitResolutionSettings()
1349 // recalculate AppFont-resolution and DPI-resolution
1350 if (mpWindowImpl->mbFrame)
1352 GetOutDev()->mnDPIX = mpWindowImpl->mpFrameData->mnDPIX;
1353 GetOutDev()->mnDPIY = mpWindowImpl->mpFrameData->mnDPIY;
1355 // setup the scale factor for HiDPI displays
1356 GetOutDev()->mnDPIScalePercentage = CountDPIScaleFactor(mpWindowImpl->mpFrameData->mnDPIY);
1357 const StyleSettings& rStyleSettings = GetOutDev()->moSettings->GetStyleSettings();
1358 SetPointFont(*GetOutDev(), rStyleSettings.GetAppFont());
1360 else if ( mpWindowImpl->mpParent )
1362 GetOutDev()->mnDPIX = mpWindowImpl->mpParent->GetOutDev()->mnDPIX;
1363 GetOutDev()->mnDPIY = mpWindowImpl->mpParent->GetOutDev()->mnDPIY;
1364 GetOutDev()->mnDPIScalePercentage = mpWindowImpl->mpParent->GetOutDev()->mnDPIScalePercentage;
1367 // update the recalculated values for logical units
1368 // and also tools belonging to the values
1369 if (IsMapModeEnabled())
1371 MapMode aMapMode = GetMapMode();
1372 SetMapMode();
1373 SetMapMode( aMapMode );
1377 void Window::ImplPointToLogic(vcl::RenderContext const & rRenderContext, vcl::Font& rFont) const
1379 Size aSize = rFont.GetFontSize();
1381 if (aSize.Width())
1383 aSize.setWidth( aSize.Width() * ( mpWindowImpl->mpFrameData->mnDPIX) );
1384 aSize.AdjustWidth(72 / 2 );
1385 aSize.setWidth( aSize.Width() / 72 );
1387 aSize.setHeight( aSize.Height() * ( mpWindowImpl->mpFrameData->mnDPIY) );
1388 aSize.AdjustHeight(72/2 );
1389 aSize.setHeight( aSize.Height() / 72 );
1391 if (rRenderContext.IsMapModeEnabled())
1392 aSize = rRenderContext.PixelToLogic(aSize);
1394 rFont.SetFontSize(aSize);
1397 void Window::ImplLogicToPoint(vcl::RenderContext const & rRenderContext, vcl::Font& rFont) const
1399 Size aSize = rFont.GetFontSize();
1401 if (rRenderContext.IsMapModeEnabled())
1402 aSize = rRenderContext.LogicToPixel(aSize);
1404 if (aSize.Width())
1406 aSize.setWidth( aSize.Width() * 72 );
1407 aSize.AdjustWidth(mpWindowImpl->mpFrameData->mnDPIX / 2 );
1408 aSize.setWidth( aSize.Width() / ( mpWindowImpl->mpFrameData->mnDPIX) );
1410 aSize.setHeight( aSize.Height() * 72 );
1411 aSize.AdjustHeight(mpWindowImpl->mpFrameData->mnDPIY / 2 );
1412 aSize.setHeight( aSize.Height() / ( mpWindowImpl->mpFrameData->mnDPIY) );
1414 rFont.SetFontSize(aSize);
1417 bool Window::ImplUpdatePos()
1419 bool bSysChild = false;
1421 if ( ImplIsOverlapWindow() )
1423 GetOutDev()->mnOutOffX = mpWindowImpl->mnX;
1424 GetOutDev()->mnOutOffY = mpWindowImpl->mnY;
1426 else
1428 vcl::Window* pParent = ImplGetParent();
1430 GetOutDev()->mnOutOffX = mpWindowImpl->mnX + pParent->GetOutDev()->mnOutOffX;
1431 GetOutDev()->mnOutOffY = mpWindowImpl->mnY + pParent->GetOutDev()->mnOutOffY;
1434 VclPtr< vcl::Window > pChild = mpWindowImpl->mpFirstChild;
1435 while ( pChild )
1437 if ( pChild->ImplUpdatePos() )
1438 bSysChild = true;
1439 pChild = pChild->mpWindowImpl->mpNext;
1442 if ( mpWindowImpl->mpSysObj )
1443 bSysChild = true;
1445 return bSysChild;
1448 void Window::ImplUpdateSysObjPos()
1450 if ( mpWindowImpl->mpSysObj )
1451 mpWindowImpl->mpSysObj->SetPosSize( GetOutDev()->mnOutOffX, GetOutDev()->mnOutOffY, GetOutDev()->mnOutWidth, GetOutDev()->mnOutHeight );
1453 VclPtr< vcl::Window > pChild = mpWindowImpl->mpFirstChild;
1454 while ( pChild )
1456 pChild->ImplUpdateSysObjPos();
1457 pChild = pChild->mpWindowImpl->mpNext;
1461 void Window::ImplPosSizeWindow( tools::Long nX, tools::Long nY,
1462 tools::Long nWidth, tools::Long nHeight, PosSizeFlags nFlags )
1464 bool bNewPos = false;
1465 bool bNewSize = false;
1466 bool bCopyBits = false;
1467 tools::Long nOldOutOffX = GetOutDev()->mnOutOffX;
1468 tools::Long nOldOutOffY = GetOutDev()->mnOutOffY;
1469 tools::Long nOldOutWidth = GetOutDev()->mnOutWidth;
1470 tools::Long nOldOutHeight = GetOutDev()->mnOutHeight;
1471 std::unique_ptr<vcl::Region> pOverlapRegion;
1472 std::unique_ptr<vcl::Region> pOldRegion;
1474 if ( IsReallyVisible() )
1476 tools::Rectangle aOldWinRect( Point( nOldOutOffX, nOldOutOffY ),
1477 Size( nOldOutWidth, nOldOutHeight ) );
1478 pOldRegion.reset( new vcl::Region( aOldWinRect ) );
1479 if ( mpWindowImpl->mbWinRegion )
1480 pOldRegion->Intersect( GetOutDev()->ImplPixelToDevicePixel( mpWindowImpl->maWinRegion ) );
1482 if ( GetOutDev()->mnOutWidth && GetOutDev()->mnOutHeight && !mpWindowImpl->mbPaintTransparent &&
1483 !mpWindowImpl->mbInitWinClipRegion && !mpWindowImpl->maWinClipRegion.IsEmpty() &&
1484 !HasPaintEvent() )
1485 bCopyBits = true;
1488 bool bnXRecycled = false; // avoid duplicate mirroring in RTL case
1489 if ( nFlags & PosSizeFlags::Width )
1491 if(!( nFlags & PosSizeFlags::X ))
1493 nX = mpWindowImpl->mnX;
1494 nFlags |= PosSizeFlags::X;
1495 bnXRecycled = true; // we're using a mnX which was already mirrored in RTL case
1498 if ( nWidth < 0 )
1499 nWidth = 0;
1500 if ( nWidth != GetOutDev()->mnOutWidth )
1502 GetOutDev()->mnOutWidth = nWidth;
1503 bNewSize = true;
1504 bCopyBits = false;
1507 if ( nFlags & PosSizeFlags::Height )
1509 if ( nHeight < 0 )
1510 nHeight = 0;
1511 if ( nHeight != GetOutDev()->mnOutHeight )
1513 GetOutDev()->mnOutHeight = nHeight;
1514 bNewSize = true;
1515 bCopyBits = false;
1519 if ( nFlags & PosSizeFlags::X )
1521 tools::Long nOrgX = nX;
1522 Point aPtDev( Point( nX+GetOutDev()->mnOutOffX, 0 ) );
1523 OutputDevice *pOutDev = GetOutDev();
1524 if( pOutDev->HasMirroredGraphics() )
1526 aPtDev.setX( GetOutDev()->mpGraphics->mirror2( aPtDev.X(), *GetOutDev() ) );
1528 // #106948# always mirror our pos if our parent is not mirroring, even
1529 // if we are also not mirroring
1530 // RTL: check if parent is in different coordinates
1531 if( !bnXRecycled && mpWindowImpl->mpParent && !mpWindowImpl->mpParent->mpWindowImpl->mbFrame && mpWindowImpl->mpParent->GetOutDev()->ImplIsAntiparallel() )
1533 nX = mpWindowImpl->mpParent->GetOutDev()->mnOutWidth - GetOutDev()->mnOutWidth - nX;
1535 /* #i99166# An LTR window in RTL UI that gets sized only would be
1536 expected to not moved its upper left point
1538 if( bnXRecycled )
1540 if( GetOutDev()->ImplIsAntiparallel() )
1542 aPtDev.setX( mpWindowImpl->mnAbsScreenX );
1543 nOrgX = mpWindowImpl->maPos.X();
1547 else if( !bnXRecycled && mpWindowImpl->mpParent && !mpWindowImpl->mpParent->mpWindowImpl->mbFrame && mpWindowImpl->mpParent->GetOutDev()->ImplIsAntiparallel() )
1549 // mirrored window in LTR UI
1550 nX = mpWindowImpl->mpParent->GetOutDev()->mnOutWidth - GetOutDev()->mnOutWidth - nX;
1553 // check maPos as well, as it could have been changed for client windows (ImplCallMove())
1554 if ( mpWindowImpl->mnAbsScreenX != aPtDev.X() || nX != mpWindowImpl->mnX || nOrgX != mpWindowImpl->maPos.X() )
1556 if ( bCopyBits && !pOverlapRegion )
1558 pOverlapRegion.reset( new vcl::Region() );
1559 ImplCalcOverlapRegion( GetOutputRectPixel(),
1560 *pOverlapRegion, false, true );
1562 mpWindowImpl->mnX = nX;
1563 mpWindowImpl->maPos.setX( nOrgX );
1564 mpWindowImpl->mnAbsScreenX = aPtDev.X();
1565 bNewPos = true;
1568 if ( nFlags & PosSizeFlags::Y )
1570 // check maPos as well, as it could have been changed for client windows (ImplCallMove())
1571 if ( nY != mpWindowImpl->mnY || nY != mpWindowImpl->maPos.Y() )
1573 if ( bCopyBits && !pOverlapRegion )
1575 pOverlapRegion.reset( new vcl::Region() );
1576 ImplCalcOverlapRegion( GetOutputRectPixel(),
1577 *pOverlapRegion, false, true );
1579 mpWindowImpl->mnY = nY;
1580 mpWindowImpl->maPos.setY( nY );
1581 bNewPos = true;
1585 if ( !(bNewPos || bNewSize) )
1586 return;
1588 bool bUpdateSysObjPos = false;
1589 if ( bNewPos )
1590 bUpdateSysObjPos = ImplUpdatePos();
1592 // the borderwindow always specifies the position for its client window
1593 if ( mpWindowImpl->mpBorderWindow )
1594 mpWindowImpl->maPos = mpWindowImpl->mpBorderWindow->mpWindowImpl->maPos;
1596 if ( mpWindowImpl->mpClientWindow )
1598 mpWindowImpl->mpClientWindow->ImplPosSizeWindow( mpWindowImpl->mpClientWindow->mpWindowImpl->mnLeftBorder,
1599 mpWindowImpl->mpClientWindow->mpWindowImpl->mnTopBorder,
1600 GetOutDev()->mnOutWidth - mpWindowImpl->mpClientWindow->mpWindowImpl->mnLeftBorder-mpWindowImpl->mpClientWindow->mpWindowImpl->mnRightBorder,
1601 GetOutDev()->mnOutHeight - mpWindowImpl->mpClientWindow->mpWindowImpl->mnTopBorder-mpWindowImpl->mpClientWindow->mpWindowImpl->mnBottomBorder,
1602 PosSizeFlags::X | PosSizeFlags::Y |
1603 PosSizeFlags::Width | PosSizeFlags::Height );
1604 // If we have a client window, then this is the position
1605 // of the Application's floating windows
1606 mpWindowImpl->mpClientWindow->mpWindowImpl->maPos = mpWindowImpl->maPos;
1607 if ( bNewPos )
1609 if ( mpWindowImpl->mpClientWindow->IsVisible() )
1611 mpWindowImpl->mpClientWindow->ImplCallMove();
1613 else
1615 mpWindowImpl->mpClientWindow->mpWindowImpl->mbCallMove = true;
1620 // Move()/Resize() will be called only for Show(), such that
1621 // at least one is called before Show()
1622 if ( IsVisible() )
1624 if ( bNewPos )
1626 ImplCallMove();
1628 if ( bNewSize )
1630 ImplCallResize();
1633 else
1635 if ( bNewPos )
1636 mpWindowImpl->mbCallMove = true;
1637 if ( bNewSize )
1638 mpWindowImpl->mbCallResize = true;
1641 bool bUpdateSysObjClip = false;
1642 if ( IsReallyVisible() )
1644 if ( bNewPos || bNewSize )
1646 // set Clip-Flag
1647 bUpdateSysObjClip = !ImplSetClipFlag( true );
1650 // invalidate window content ?
1651 if ( bNewPos || (GetOutDev()->mnOutWidth > nOldOutWidth) || (GetOutDev()->mnOutHeight > nOldOutHeight) )
1653 if ( bNewPos )
1655 bool bInvalidate = false;
1656 bool bParentPaint = true;
1657 if ( !ImplIsOverlapWindow() )
1658 bParentPaint = mpWindowImpl->mpParent->IsPaintEnabled();
1659 if ( bCopyBits && bParentPaint && !HasPaintEvent() )
1661 vcl::Region aRegion( GetOutputRectPixel() );
1662 if ( mpWindowImpl->mbWinRegion )
1663 aRegion.Intersect( GetOutDev()->ImplPixelToDevicePixel( mpWindowImpl->maWinRegion ) );
1664 ImplClipBoundaries( aRegion, false, true );
1665 if ( !pOverlapRegion->IsEmpty() )
1667 pOverlapRegion->Move( GetOutDev()->mnOutOffX - nOldOutOffX, GetOutDev()->mnOutOffY - nOldOutOffY );
1668 aRegion.Exclude( *pOverlapRegion );
1670 if ( !aRegion.IsEmpty() )
1672 // adapt Paint areas
1673 ImplMoveAllInvalidateRegions( tools::Rectangle( Point( nOldOutOffX, nOldOutOffY ),
1674 Size( nOldOutWidth, nOldOutHeight ) ),
1675 GetOutDev()->mnOutOffX - nOldOutOffX, GetOutDev()->mnOutOffY - nOldOutOffY,
1676 true );
1677 SalGraphics* pGraphics = ImplGetFrameGraphics();
1678 if ( pGraphics )
1681 OutputDevice *pOutDev = GetOutDev();
1682 const bool bSelectClipRegion = pOutDev->SelectClipRegion( aRegion, pGraphics );
1683 if ( bSelectClipRegion )
1685 pGraphics->CopyArea( GetOutDev()->mnOutOffX, GetOutDev()->mnOutOffY,
1686 nOldOutOffX, nOldOutOffY,
1687 nOldOutWidth, nOldOutHeight,
1688 *GetOutDev() );
1690 else
1691 bInvalidate = true;
1693 else
1694 bInvalidate = true;
1695 if ( !bInvalidate )
1697 if ( !pOverlapRegion->IsEmpty() )
1698 ImplInvalidateFrameRegion( pOverlapRegion.get(), InvalidateFlags::Children );
1701 else
1702 bInvalidate = true;
1704 else
1705 bInvalidate = true;
1706 if ( bInvalidate )
1707 ImplInvalidateFrameRegion( nullptr, InvalidateFlags::Children );
1709 else
1711 vcl::Region aRegion( GetOutputRectPixel() );
1712 aRegion.Exclude( *pOldRegion );
1713 if ( mpWindowImpl->mbWinRegion )
1714 aRegion.Intersect( GetOutDev()->ImplPixelToDevicePixel( mpWindowImpl->maWinRegion ) );
1715 ImplClipBoundaries( aRegion, false, true );
1716 if ( !aRegion.IsEmpty() )
1717 ImplInvalidateFrameRegion( &aRegion, InvalidateFlags::Children );
1721 // invalidate Parent or Overlaps
1722 if ( bNewPos ||
1723 (GetOutDev()->mnOutWidth < nOldOutWidth) || (GetOutDev()->mnOutHeight < nOldOutHeight) )
1725 vcl::Region aRegion( *pOldRegion );
1726 if ( !mpWindowImpl->mbPaintTransparent )
1727 ImplExcludeWindowRegion( aRegion );
1728 ImplClipBoundaries( aRegion, false, true );
1729 if ( !aRegion.IsEmpty() && !mpWindowImpl->mpBorderWindow )
1730 ImplInvalidateParentFrameRegion( aRegion );
1734 // adapt system objects
1735 if ( bUpdateSysObjClip )
1736 ImplUpdateSysObjClip();
1737 if ( bUpdateSysObjPos )
1738 ImplUpdateSysObjPos();
1739 if ( bNewSize && mpWindowImpl->mpSysObj )
1740 mpWindowImpl->mpSysObj->SetPosSize( GetOutDev()->mnOutOffX, GetOutDev()->mnOutOffY, GetOutDev()->mnOutWidth, GetOutDev()->mnOutHeight );
1743 void Window::ImplNewInputContext()
1745 ImplSVData* pSVData = ImplGetSVData();
1746 vcl::Window* pFocusWin = pSVData->mpWinData->mpFocusWin;
1747 if ( !pFocusWin || !pFocusWin->mpWindowImpl || pFocusWin->isDisposed() )
1748 return;
1750 // Is InputContext changed?
1751 const InputContext& rInputContext = pFocusWin->GetInputContext();
1752 if ( rInputContext == pFocusWin->mpWindowImpl->mpFrameData->maOldInputContext )
1753 return;
1755 pFocusWin->mpWindowImpl->mpFrameData->maOldInputContext = rInputContext;
1757 SalInputContext aNewContext;
1758 const vcl::Font& rFont = rInputContext.GetFont();
1759 const OUString& rFontName = rFont.GetFamilyName();
1760 rtl::Reference<LogicalFontInstance> pFontInstance;
1761 aNewContext.mpFont = nullptr;
1762 if (!rFontName.isEmpty())
1764 OutputDevice *pFocusWinOutDev = pFocusWin->GetOutDev();
1765 Size aSize = pFocusWinOutDev->ImplLogicToDevicePixel( rFont.GetFontSize() );
1766 if ( !aSize.Height() )
1768 // only set default sizes if the font height in logical
1769 // coordinates equals 0
1770 if ( rFont.GetFontSize().Height() )
1771 aSize.setHeight( 1 );
1772 else
1773 aSize.setHeight( (12*pFocusWin->GetOutDev()->mnDPIY)/72 );
1775 pFontInstance = pFocusWin->GetOutDev()->mxFontCache->GetFontInstance(
1776 pFocusWin->GetOutDev()->mxFontCollection.get(),
1777 rFont, aSize, static_cast<float>(aSize.Height()) );
1778 if ( pFontInstance )
1779 aNewContext.mpFont = pFontInstance;
1781 aNewContext.mnOptions = rInputContext.GetOptions();
1782 pFocusWin->ImplGetFrame()->SetInputContext( &aNewContext );
1785 void Window::SetDumpAsPropertyTreeHdl(const Link<tools::JsonWriter&, void>& rLink)
1787 if (mpWindowImpl) // may be called after dispose
1789 mpWindowImpl->maDumpAsPropertyTreeHdl = rLink;
1793 void Window::SetModalHierarchyHdl(const Link<bool, void>& rLink)
1795 ImplGetFrame()->SetModalHierarchyHdl(rLink);
1798 KeyIndicatorState Window::GetIndicatorState() const
1800 return mpWindowImpl->mpFrame->GetIndicatorState();
1803 void Window::SimulateKeyPress( sal_uInt16 nKeyCode ) const
1805 mpWindowImpl->mpFrame->SimulateKeyPress(nKeyCode);
1808 void Window::KeyInput( const KeyEvent& rKEvt )
1810 KeyCode cod = rKEvt.GetKeyCode ();
1811 bool autoacc = ImplGetSVData()->maNWFData.mbAutoAccel;
1813 // do not respond to accelerators unless Alt or Ctrl is held
1814 if (cod.GetCode () >= 0x200 && cod.GetCode () <= 0x219)
1816 if (autoacc && cod.GetModifier () != KEY_MOD2 && !(cod.GetModifier() & KEY_MOD1))
1817 return;
1820 NotifyEvent aNEvt( NotifyEventType::KEYINPUT, this, &rKEvt );
1821 if ( !CompatNotify( aNEvt ) )
1822 mpWindowImpl->mbKeyInput = true;
1825 void Window::KeyUp( const KeyEvent& rKEvt )
1827 NotifyEvent aNEvt( NotifyEventType::KEYUP, this, &rKEvt );
1828 if ( !CompatNotify( aNEvt ) )
1829 mpWindowImpl->mbKeyUp = true;
1832 void Window::Draw( OutputDevice*, const Point&, SystemTextColorFlags )
1836 void Window::Move() {}
1838 void Window::Resize() {}
1840 void Window::Activate() {}
1842 void Window::Deactivate() {}
1844 void Window::GetFocus()
1846 if ( HasFocus() && mpWindowImpl->mpLastFocusWindow && !(mpWindowImpl->mnDlgCtrlFlags & DialogControlFlags::WantFocus) )
1848 VclPtr<vcl::Window> xWindow(this);
1849 mpWindowImpl->mpLastFocusWindow->GrabFocus();
1850 if( xWindow->isDisposed() )
1851 return;
1854 NotifyEvent aNEvt( NotifyEventType::GETFOCUS, this );
1855 CompatNotify( aNEvt );
1858 void Window::LoseFocus()
1860 NotifyEvent aNEvt( NotifyEventType::LOSEFOCUS, this );
1861 CompatNotify( aNEvt );
1864 void Window::SetHelpHdl(const Link<vcl::Window&, bool>& rLink)
1866 if (mpWindowImpl) // may be called after dispose
1868 mpWindowImpl->maHelpRequestHdl = rLink;
1872 void Window::RequestHelp( const HelpEvent& rHEvt )
1874 // if Balloon-Help is requested, show the balloon
1875 // with help text set
1876 if ( rHEvt.GetMode() & HelpEventMode::BALLOON )
1878 OUString rStr = GetHelpText();
1879 if ( rStr.isEmpty() )
1880 rStr = GetQuickHelpText();
1881 if ( rStr.isEmpty() && ImplGetParent() && !ImplIsOverlapWindow() )
1882 ImplGetParent()->RequestHelp( rHEvt );
1883 else
1885 Point aPos = GetPosPixel();
1886 if ( ImplGetParent() && !ImplIsOverlapWindow() )
1887 aPos = OutputToScreenPixel(Point(0, 0));
1888 tools::Rectangle aRect( aPos, GetSizePixel() );
1890 Help::ShowBalloon( this, rHEvt.GetMousePosPixel(), aRect, rStr );
1893 else if ( rHEvt.GetMode() & HelpEventMode::QUICK )
1895 const OUString& rStr = GetQuickHelpText();
1896 if ( rStr.isEmpty() && ImplGetParent() && !ImplIsOverlapWindow() )
1897 ImplGetParent()->RequestHelp( rHEvt );
1898 else
1900 Point aPos = GetPosPixel();
1901 if ( ImplGetParent() && !ImplIsOverlapWindow() )
1902 aPos = OutputToScreenPixel(Point(0, 0));
1903 tools::Rectangle aRect( aPos, GetSizePixel() );
1904 Help::ShowQuickHelp( this, aRect, rStr, QuickHelpFlags::CtrlText );
1907 else if (!mpWindowImpl->maHelpRequestHdl.IsSet() || mpWindowImpl->maHelpRequestHdl.Call(*this))
1909 OUString aStrHelpId( GetHelpId() );
1910 if ( aStrHelpId.isEmpty() && ImplGetParent() )
1911 ImplGetParent()->RequestHelp( rHEvt );
1912 else
1914 Help* pHelp = Application::GetHelp();
1915 if ( pHelp )
1917 if( !aStrHelpId.isEmpty() )
1918 pHelp->Start( aStrHelpId, this );
1919 else
1920 pHelp->Start( OOO_HELP_INDEX, this );
1926 void Window::Command( const CommandEvent& rCEvt )
1928 CallEventListeners( VclEventId::WindowCommand, const_cast<CommandEvent *>(&rCEvt) );
1930 NotifyEvent aNEvt( NotifyEventType::COMMAND, this, &rCEvt );
1931 if ( !CompatNotify( aNEvt ) )
1932 mpWindowImpl->mbCommand = true;
1935 void Window::Tracking( const TrackingEvent& rTEvt )
1938 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
1939 if( pWrapper )
1940 pWrapper->Tracking( rTEvt );
1943 void Window::StateChanged(StateChangedType eType)
1945 switch (eType)
1947 //stuff that doesn't invalidate the layout
1948 case StateChangedType::ControlForeground:
1949 case StateChangedType::ControlBackground:
1950 case StateChangedType::UpdateMode:
1951 case StateChangedType::ReadOnly:
1952 case StateChangedType::Enable:
1953 case StateChangedType::State:
1954 case StateChangedType::Data:
1955 case StateChangedType::InitShow:
1956 case StateChangedType::ControlFocus:
1957 break;
1958 //stuff that does invalidate the layout
1959 default:
1960 queue_resize(eType);
1961 break;
1965 void Window::SetStyle( WinBits nStyle )
1967 if ( mpWindowImpl && mpWindowImpl->mnStyle != nStyle )
1969 mpWindowImpl->mnPrevStyle = mpWindowImpl->mnStyle;
1970 mpWindowImpl->mnStyle = nStyle;
1971 CompatStateChanged( StateChangedType::Style );
1975 void Window::SetExtendedStyle( WindowExtendedStyle nExtendedStyle )
1978 if ( mpWindowImpl->mnExtendedStyle == nExtendedStyle )
1979 return;
1981 vcl::Window* pWindow = ImplGetBorderWindow();
1982 if( ! pWindow )
1983 pWindow = this;
1984 if( pWindow->mpWindowImpl->mbFrame )
1986 SalExtStyle nExt = 0;
1987 if( nExtendedStyle & WindowExtendedStyle::Document )
1988 nExt |= SAL_FRAME_EXT_STYLE_DOCUMENT;
1989 if( nExtendedStyle & WindowExtendedStyle::DocModified )
1990 nExt |= SAL_FRAME_EXT_STYLE_DOCMODIFIED;
1992 pWindow->ImplGetFrame()->SetExtendedFrameStyle( nExt );
1994 mpWindowImpl->mnExtendedStyle = nExtendedStyle;
1997 void Window::SetBorderStyle( WindowBorderStyle nBorderStyle )
2000 if ( !mpWindowImpl->mpBorderWindow )
2001 return;
2003 if( nBorderStyle == WindowBorderStyle::REMOVEBORDER &&
2004 ! mpWindowImpl->mpBorderWindow->mpWindowImpl->mbFrame &&
2005 mpWindowImpl->mpBorderWindow->mpWindowImpl->mpParent
2008 // this is a little awkward: some controls (e.g. svtools ProgressBar)
2009 // cannot avoid getting constructed with WB_BORDER but want to disable
2010 // borders in case of NWF drawing. So they need a method to remove their border window
2011 VclPtr<vcl::Window> pBorderWin = mpWindowImpl->mpBorderWindow;
2012 // remove us as border window's client
2013 pBorderWin->mpWindowImpl->mpClientWindow = nullptr;
2014 mpWindowImpl->mpBorderWindow = nullptr;
2015 mpWindowImpl->mpRealParent = pBorderWin->mpWindowImpl->mpParent;
2016 // reparent us above the border window
2017 SetParent( pBorderWin->mpWindowImpl->mpParent );
2018 // set us to the position and size of our previous border
2019 Point aBorderPos( pBorderWin->GetPosPixel() );
2020 Size aBorderSize( pBorderWin->GetSizePixel() );
2021 setPosSizePixel( aBorderPos.X(), aBorderPos.Y(), aBorderSize.Width(), aBorderSize.Height() );
2022 // release border window
2023 pBorderWin.disposeAndClear();
2025 // set new style bits
2026 SetStyle( GetStyle() & (~WB_BORDER) );
2028 else
2030 if ( mpWindowImpl->mpBorderWindow->GetType() == WindowType::BORDERWINDOW )
2031 static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->SetBorderStyle( nBorderStyle );
2032 else
2033 mpWindowImpl->mpBorderWindow->SetBorderStyle( nBorderStyle );
2037 WindowBorderStyle Window::GetBorderStyle() const
2040 if ( mpWindowImpl->mpBorderWindow )
2042 if ( mpWindowImpl->mpBorderWindow->GetType() == WindowType::BORDERWINDOW )
2043 return static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->GetBorderStyle();
2044 else
2045 return mpWindowImpl->mpBorderWindow->GetBorderStyle();
2048 return WindowBorderStyle::NONE;
2051 tools::Long Window::CalcTitleWidth() const
2054 if ( mpWindowImpl->mpBorderWindow )
2056 if ( mpWindowImpl->mpBorderWindow->GetType() == WindowType::BORDERWINDOW )
2057 return static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->CalcTitleWidth();
2058 else
2059 return mpWindowImpl->mpBorderWindow->CalcTitleWidth();
2061 else if ( mpWindowImpl->mbFrame && (mpWindowImpl->mnStyle & WB_MOVEABLE) )
2063 // we guess the width for frame windows as we do not know the
2064 // border of external dialogs
2065 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
2066 vcl::Font aFont = GetFont();
2067 const_cast<vcl::Window*>(this)->SetPointFont(const_cast<::OutputDevice&>(*GetOutDev()), rStyleSettings.GetTitleFont());
2068 tools::Long nTitleWidth = GetTextWidth( GetText() );
2069 const_cast<vcl::Window*>(this)->SetFont( aFont );
2070 nTitleWidth += rStyleSettings.GetTitleHeight() * 3;
2071 nTitleWidth += StyleSettings::GetBorderSize() * 2;
2072 nTitleWidth += 10;
2073 return nTitleWidth;
2076 return 0;
2079 void Window::SetInputContext( const InputContext& rInputContext )
2082 mpWindowImpl->maInputContext = rInputContext;
2083 if ( !mpWindowImpl->mbInFocusHdl && HasFocus() )
2084 ImplNewInputContext();
2087 void Window::PostExtTextInputEvent(VclEventId nType, const OUString& rText)
2089 switch (nType)
2091 case VclEventId::ExtTextInput:
2093 std::unique_ptr<ExtTextInputAttr[]> pAttr(new ExtTextInputAttr[rText.getLength()]);
2094 for (int i = 0; i < rText.getLength(); ++i) {
2095 pAttr[i] = ExtTextInputAttr::Underline;
2097 SalExtTextInputEvent aEvent { rText, pAttr.get(), rText.getLength(), EXTTEXTINPUT_CURSOR_OVERWRITE };
2098 ImplWindowFrameProc(this, SalEvent::ExtTextInput, &aEvent);
2100 break;
2101 case VclEventId::EndExtTextInput:
2102 ImplWindowFrameProc(this, SalEvent::EndExtTextInput, nullptr);
2103 break;
2104 default:
2105 assert(false);
2109 void Window::EndExtTextInput()
2111 if ( mpWindowImpl->mbExtTextInput )
2112 ImplGetFrame()->EndExtTextInput( EndExtTextInputFlags::Complete );
2115 void Window::SetCursorRect( const tools::Rectangle* pRect, tools::Long nExtTextInputWidth )
2118 ImplWinData* pWinData = ImplGetWinData();
2119 if ( pWinData->mpCursorRect )
2121 if ( pRect )
2122 pWinData->mpCursorRect = *pRect;
2123 else
2124 pWinData->mpCursorRect.reset();
2126 else
2128 if ( pRect )
2129 pWinData->mpCursorRect = *pRect;
2132 pWinData->mnCursorExtWidth = nExtTextInputWidth;
2136 const tools::Rectangle* Window::GetCursorRect() const
2139 ImplWinData* pWinData = ImplGetWinData();
2140 return pWinData->mpCursorRect ? &*pWinData->mpCursorRect : nullptr;
2143 tools::Long Window::GetCursorExtTextInputWidth() const
2146 ImplWinData* pWinData = ImplGetWinData();
2147 return pWinData->mnCursorExtWidth;
2150 void Window::SetCompositionCharRect( const tools::Rectangle* pRect, tools::Long nCompositionLength, bool bVertical ) {
2152 ImplWinData* pWinData = ImplGetWinData();
2153 pWinData->mpCompositionCharRects.reset();
2154 pWinData->mbVertical = bVertical;
2155 pWinData->mnCompositionCharRects = nCompositionLength;
2156 if ( pRect && (nCompositionLength > 0) )
2158 pWinData->mpCompositionCharRects.reset( new tools::Rectangle[nCompositionLength] );
2159 for (tools::Long i = 0; i < nCompositionLength; ++i)
2160 pWinData->mpCompositionCharRects[i] = pRect[i];
2164 void Window::CollectChildren(::std::vector<vcl::Window *>& rAllChildren )
2166 rAllChildren.push_back( this );
2168 VclPtr< vcl::Window > pChild = mpWindowImpl->mpFirstChild;
2169 while ( pChild )
2171 pChild->CollectChildren( rAllChildren );
2172 pChild = pChild->mpWindowImpl->mpNext;
2176 void Window::SetPointFont(vcl::RenderContext& rRenderContext, const vcl::Font& rFont)
2178 vcl::Font aFont = rFont;
2179 ImplPointToLogic(rRenderContext, aFont);
2180 rRenderContext.SetFont(aFont);
2183 vcl::Font Window::GetPointFont(vcl::RenderContext const & rRenderContext) const
2185 vcl::Font aFont = rRenderContext.GetFont();
2186 ImplLogicToPoint(rRenderContext, aFont);
2187 return aFont;
2190 void Window::Show(bool bVisible, ShowFlags nFlags)
2192 if ( !mpWindowImpl || mpWindowImpl->mbVisible == bVisible )
2193 return;
2195 VclPtr<vcl::Window> xWindow(this);
2197 bool bRealVisibilityChanged = false;
2198 mpWindowImpl->mbVisible = bVisible;
2200 if ( !bVisible )
2202 ImplHideAllOverlaps();
2203 if( !xWindow->mpWindowImpl )
2204 return;
2206 if ( mpWindowImpl->mpBorderWindow )
2208 bool bOldUpdate = mpWindowImpl->mpBorderWindow->mpWindowImpl->mbNoParentUpdate;
2209 if ( mpWindowImpl->mbNoParentUpdate )
2210 mpWindowImpl->mpBorderWindow->mpWindowImpl->mbNoParentUpdate = true;
2211 mpWindowImpl->mpBorderWindow->Show( false, nFlags );
2212 mpWindowImpl->mpBorderWindow->mpWindowImpl->mbNoParentUpdate = bOldUpdate;
2214 else if ( mpWindowImpl->mbFrame )
2216 mpWindowImpl->mbSuppressAccessibilityEvents = true;
2217 mpWindowImpl->mpFrame->Show( false );
2220 CompatStateChanged( StateChangedType::Visible );
2222 if ( mpWindowImpl->mbReallyVisible )
2224 if ( mpWindowImpl->mbInitWinClipRegion )
2225 ImplInitWinClipRegion();
2227 vcl::Region aInvRegion = mpWindowImpl->maWinClipRegion;
2229 if( !xWindow->mpWindowImpl )
2230 return;
2232 bRealVisibilityChanged = mpWindowImpl->mbReallyVisible;
2233 ImplResetReallyVisible();
2234 ImplSetClipFlag();
2236 if ( ImplIsOverlapWindow() && !mpWindowImpl->mbFrame )
2238 // convert focus
2239 if ( !(nFlags & ShowFlags::NoFocusChange) && HasChildPathFocus() )
2241 if ( mpWindowImpl->mpOverlapWindow->IsEnabled() &&
2242 mpWindowImpl->mpOverlapWindow->IsInputEnabled() &&
2243 ! mpWindowImpl->mpOverlapWindow->IsInModalMode()
2245 mpWindowImpl->mpOverlapWindow->GrabFocus();
2249 if ( !mpWindowImpl->mbFrame )
2251 if (mpWindowImpl->mpWinData && mpWindowImpl->mpWinData->mbEnableNativeWidget)
2254 * #i48371# native theming: some themes draw outside the control
2255 * area we tell them to (bad thing, but we cannot do much about it ).
2256 * On hiding these controls they get invalidated with their window rectangle
2257 * which leads to the parts outside the control area being left and not
2258 * invalidated. Workaround: invalidate an area on the parent, too
2260 const int workaround_border = 5;
2261 tools::Rectangle aBounds( aInvRegion.GetBoundRect() );
2262 aBounds.AdjustLeft( -workaround_border );
2263 aBounds.AdjustTop( -workaround_border );
2264 aBounds.AdjustRight(workaround_border );
2265 aBounds.AdjustBottom(workaround_border );
2266 aInvRegion = aBounds;
2268 if ( !mpWindowImpl->mbNoParentUpdate )
2270 if ( !aInvRegion.IsEmpty() )
2271 ImplInvalidateParentFrameRegion( aInvRegion );
2273 ImplGenerateMouseMove();
2277 else
2279 // inherit native widget flag for form controls
2280 // required here, because frames never show up in the child hierarchy - which should be fixed...
2281 // eg, the drop down of a combobox which is a system floating window
2282 if( mpWindowImpl->mbFrame && GetParent() && !GetParent()->isDisposed() &&
2283 GetParent()->IsCompoundControl() &&
2284 GetParent()->IsNativeWidgetEnabled() != IsNativeWidgetEnabled() &&
2285 !(GetStyle() & WB_TOOLTIPWIN) )
2287 EnableNativeWidget( GetParent()->IsNativeWidgetEnabled() );
2290 if ( mpWindowImpl->mbCallMove )
2292 ImplCallMove();
2294 if ( mpWindowImpl->mbCallResize )
2296 ImplCallResize();
2299 CompatStateChanged( StateChangedType::Visible );
2301 vcl::Window* pTestParent;
2302 if ( ImplIsOverlapWindow() )
2303 pTestParent = mpWindowImpl->mpOverlapWindow;
2304 else
2305 pTestParent = ImplGetParent();
2306 if ( mpWindowImpl->mbFrame || pTestParent->mpWindowImpl->mbReallyVisible )
2308 // if a window becomes visible, send all child windows a StateChange,
2309 // such that these can initialise themselves
2310 ImplCallInitShow();
2312 // If it is a SystemWindow it automatically pops up on top of
2313 // all other windows if needed.
2314 if ( ImplIsOverlapWindow() && !(nFlags & ShowFlags::NoActivate) )
2316 ImplStartToTop(( nFlags & ShowFlags::ForegroundTask ) ? ToTopFlags::ForegroundTask : ToTopFlags::NONE );
2317 ImplFocusToTop( ToTopFlags::NONE, false );
2320 // adjust mpWindowImpl->mbReallyVisible
2321 bRealVisibilityChanged = !mpWindowImpl->mbReallyVisible;
2322 ImplSetReallyVisible();
2324 // assure clip rectangles will be recalculated
2325 ImplSetClipFlag();
2327 if ( !mpWindowImpl->mbFrame )
2329 InvalidateFlags nInvalidateFlags = InvalidateFlags::Children;
2330 if( ! IsPaintTransparent() )
2331 nInvalidateFlags |= InvalidateFlags::NoTransparent;
2332 ImplInvalidate( nullptr, nInvalidateFlags );
2333 ImplGenerateMouseMove();
2337 if ( mpWindowImpl->mpBorderWindow )
2338 mpWindowImpl->mpBorderWindow->Show( true, nFlags );
2339 else if ( mpWindowImpl->mbFrame )
2341 // #106431#, hide SplashScreen
2342 ImplSVData* pSVData = ImplGetSVData();
2343 if ( !pSVData->mpIntroWindow )
2345 // The right way would be just to call this (not even in the 'if')
2346 auto pApp = GetpApp();
2347 if ( pApp )
2348 pApp->InitFinished();
2350 else if ( !ImplIsWindowOrChild( pSVData->mpIntroWindow ) )
2352 // ... but the VCL splash is broken, and it needs this
2353 // (for ./soffice .uno:NewDoc)
2354 pSVData->mpIntroWindow->Hide();
2357 //SAL_WARN_IF( mpWindowImpl->mbSuppressAccessibilityEvents, "vcl", "Window::Show() - Frame reactivated");
2358 mpWindowImpl->mbSuppressAccessibilityEvents = false;
2360 mpWindowImpl->mbPaintFrame = true;
2361 if (!Application::IsHeadlessModeEnabled())
2363 bool bNoActivate(nFlags & (ShowFlags::NoActivate|ShowFlags::NoFocusChange));
2364 mpWindowImpl->mpFrame->Show( true, bNoActivate );
2366 if( !xWindow->mpWindowImpl )
2367 return;
2369 // Query the correct size of the window, if we are waiting for
2370 // a system resize
2371 if ( mpWindowImpl->mbWaitSystemResize )
2373 tools::Long nOutWidth;
2374 tools::Long nOutHeight;
2375 mpWindowImpl->mpFrame->GetClientSize( nOutWidth, nOutHeight );
2376 ImplHandleResize( this, nOutWidth, nOutHeight );
2379 if (mpWindowImpl->mpFrameData->mpBuffer && mpWindowImpl->mpFrameData->mpBuffer->GetOutputSizePixel() != GetOutputSizePixel())
2380 // Make sure that the buffer size matches the window size, even if no resize was needed.
2381 mpWindowImpl->mpFrameData->mpBuffer->SetOutputSizePixel(GetOutputSizePixel());
2384 if( !xWindow->mpWindowImpl )
2385 return;
2387 ImplShowAllOverlaps();
2390 if( !xWindow->mpWindowImpl )
2391 return;
2393 // the SHOW/HIDE events also serve as indicators to send child creation/destroy events to the access bridge
2394 // However, the access bridge only uses this event if the data member is not NULL (it's kind of a hack that
2395 // we re-use the SHOW/HIDE events this way, with this particular semantics).
2396 // Since #104887#, the notifications for the access bridge are done in Impl(Set|Reset)ReallyVisible. Here, we
2397 // now only notify with a NULL data pointer, for all other clients except the access bridge.
2398 if ( !bRealVisibilityChanged )
2399 CallEventListeners( mpWindowImpl->mbVisible ? VclEventId::WindowShow : VclEventId::WindowHide );
2400 if( xWindow->isDisposed() )
2401 return;
2405 Size Window::GetSizePixel() const
2407 if (!mpWindowImpl)
2409 SAL_WARN("vcl.layout", "WTF no windowimpl");
2410 return Size(0,0);
2413 // #i43257# trigger pending resize handler to assure correct window sizes
2414 if( mpWindowImpl->mpFrameData->maResizeIdle.IsActive() )
2416 VclPtr<vcl::Window> xWindow( const_cast<Window*>(this) );
2417 mpWindowImpl->mpFrameData->maResizeIdle.Stop();
2418 mpWindowImpl->mpFrameData->maResizeIdle.Invoke( nullptr );
2419 if( xWindow->isDisposed() )
2420 return Size(0,0);
2423 return Size( GetOutDev()->mnOutWidth + mpWindowImpl->mnLeftBorder+mpWindowImpl->mnRightBorder,
2424 GetOutDev()->mnOutHeight + mpWindowImpl->mnTopBorder+mpWindowImpl->mnBottomBorder );
2427 void Window::GetBorder( sal_Int32& rLeftBorder, sal_Int32& rTopBorder,
2428 sal_Int32& rRightBorder, sal_Int32& rBottomBorder ) const
2430 rLeftBorder = mpWindowImpl->mnLeftBorder;
2431 rTopBorder = mpWindowImpl->mnTopBorder;
2432 rRightBorder = mpWindowImpl->mnRightBorder;
2433 rBottomBorder = mpWindowImpl->mnBottomBorder;
2436 void Window::Enable( bool bEnable, bool bChild )
2438 if ( isDisposed() )
2439 return;
2441 if ( !bEnable )
2443 // the tracking mode will be stopped or the capture will be stolen
2444 // when a window is disabled,
2445 if ( IsTracking() )
2446 EndTracking( TrackingEventFlags::Cancel );
2447 if ( IsMouseCaptured() )
2448 ReleaseMouse();
2449 // try to pass focus to the next control
2450 // if the window has focus and is contained in the dialog control
2451 // mpWindowImpl->mbDisabled should only be set after a call of ImplDlgCtrlNextWindow().
2452 // Otherwise ImplDlgCtrlNextWindow() should be used
2453 if ( HasFocus() )
2454 ImplDlgCtrlNextWindow();
2457 if ( mpWindowImpl->mpBorderWindow )
2459 mpWindowImpl->mpBorderWindow->Enable( bEnable, false );
2460 if ( (mpWindowImpl->mpBorderWindow->GetType() == WindowType::BORDERWINDOW) &&
2461 static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->mpMenuBarWindow )
2462 static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->mpMenuBarWindow->Enable( bEnable );
2465 // #i56102# restore app focus win in case the
2466 // window was disabled when the frame focus changed
2467 ImplSVData* pSVData = ImplGetSVData();
2468 if (bEnable && pSVData->mpWinData->mpFocusWin == nullptr
2469 && mpWindowImpl->mpFrameData->mbHasFocus && mpWindowImpl->mpFrameData->mpFocusWin == this)
2470 pSVData->mpWinData->mpFocusWin = this;
2472 if ( mpWindowImpl->mbDisabled != !bEnable )
2474 mpWindowImpl->mbDisabled = !bEnable;
2475 if ( mpWindowImpl->mpSysObj )
2476 mpWindowImpl->mpSysObj->Enable( bEnable && !mpWindowImpl->mbInputDisabled );
2477 CompatStateChanged( StateChangedType::Enable );
2479 CallEventListeners( bEnable ? VclEventId::WindowEnabled : VclEventId::WindowDisabled );
2482 if ( bChild )
2484 VclPtr< vcl::Window > pChild = mpWindowImpl->mpFirstChild;
2485 while ( pChild )
2487 pChild->Enable( bEnable, bChild );
2488 pChild = pChild->mpWindowImpl->mpNext;
2492 if ( IsReallyVisible() )
2493 ImplGenerateMouseMove();
2496 void Window::EnableInput( bool bEnable, bool bChild )
2498 if (!mpWindowImpl)
2499 return;
2501 if ( mpWindowImpl->mpBorderWindow )
2503 mpWindowImpl->mpBorderWindow->EnableInput( bEnable, false );
2504 if ( (mpWindowImpl->mpBorderWindow->GetType() == WindowType::BORDERWINDOW) &&
2505 static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->mpMenuBarWindow )
2506 static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->mpMenuBarWindow->EnableInput( bEnable );
2509 if ( (!bEnable && mpWindowImpl->meAlwaysInputMode != AlwaysInputEnabled) || bEnable )
2511 // automatically stop the tracking mode or steal capture
2512 // if the window is disabled
2513 if ( !bEnable )
2515 if ( IsTracking() )
2516 EndTracking( TrackingEventFlags::Cancel );
2517 if ( IsMouseCaptured() )
2518 ReleaseMouse();
2521 if ( mpWindowImpl->mbInputDisabled != !bEnable )
2523 mpWindowImpl->mbInputDisabled = !bEnable;
2524 if ( mpWindowImpl->mpSysObj )
2525 mpWindowImpl->mpSysObj->Enable( !mpWindowImpl->mbDisabled && bEnable );
2529 // #i56102# restore app focus win in case the
2530 // window was disabled when the frame focus changed
2531 ImplSVData* pSVData = ImplGetSVData();
2532 if (bEnable && pSVData->mpWinData->mpFocusWin == nullptr
2533 && mpWindowImpl->mpFrameData->mbHasFocus && mpWindowImpl->mpFrameData->mpFocusWin == this)
2534 pSVData->mpWinData->mpFocusWin = this;
2536 if ( bChild )
2538 VclPtr< vcl::Window > pChild = mpWindowImpl->mpFirstChild;
2539 while ( pChild )
2541 pChild->EnableInput( bEnable, bChild );
2542 pChild = pChild->mpWindowImpl->mpNext;
2546 if ( IsReallyVisible() )
2547 ImplGenerateMouseMove();
2550 void Window::EnableInput( bool bEnable, const vcl::Window* pExcludeWindow )
2552 if (!mpWindowImpl)
2553 return;
2555 EnableInput( bEnable );
2557 // pExecuteWindow is the first Overlap-Frame --> if this
2558 // shouldn't be the case, then this must be changed in dialog.cxx
2559 if( pExcludeWindow )
2560 pExcludeWindow = pExcludeWindow->ImplGetFirstOverlapWindow();
2561 vcl::Window* pSysWin = mpWindowImpl->mpFrameWindow->mpWindowImpl->mpFrameData->mpFirstOverlap;
2562 while ( pSysWin )
2564 // Is Window in the path from this window
2565 if ( ImplGetFirstOverlapWindow()->ImplIsWindowOrChild( pSysWin, true ) )
2567 // Is Window not in the exclude window path or not the
2568 // exclude window, then change the status
2569 if ( !pExcludeWindow || !pExcludeWindow->ImplIsWindowOrChild( pSysWin, true ) )
2570 pSysWin->EnableInput( bEnable );
2572 pSysWin = pSysWin->mpWindowImpl->mpNextOverlap;
2575 // enable/disable floating system windows as well
2576 vcl::Window* pFrameWin = ImplGetSVData()->maFrameData.mpFirstFrame;
2577 while ( pFrameWin )
2579 if( pFrameWin->ImplIsFloatingWindow() )
2581 // Is Window in the path from this window
2582 if ( ImplGetFirstOverlapWindow()->ImplIsWindowOrChild( pFrameWin, true ) )
2584 // Is Window not in the exclude window path or not the
2585 // exclude window, then change the status
2586 if ( !pExcludeWindow || !pExcludeWindow->ImplIsWindowOrChild( pFrameWin, true ) )
2587 pFrameWin->EnableInput( bEnable );
2590 pFrameWin = pFrameWin->mpWindowImpl->mpFrameData->mpNextFrame;
2593 // the same for ownerdraw floating windows
2594 if( !mpWindowImpl->mbFrame )
2595 return;
2597 ::std::vector< VclPtr<vcl::Window> >& rList = mpWindowImpl->mpFrameData->maOwnerDrawList;
2598 for (auto const& elem : rList)
2600 // Is Window in the path from this window
2601 if ( ImplGetFirstOverlapWindow()->ImplIsWindowOrChild( elem, true ) )
2603 // Is Window not in the exclude window path or not the
2604 // exclude window, then change the status
2605 if ( !pExcludeWindow || !pExcludeWindow->ImplIsWindowOrChild( elem, true ) )
2606 elem->EnableInput( bEnable );
2611 void Window::AlwaysEnableInput( bool bAlways, bool bChild )
2614 if ( mpWindowImpl->mpBorderWindow )
2615 mpWindowImpl->mpBorderWindow->AlwaysEnableInput( bAlways, false );
2617 if( bAlways && mpWindowImpl->meAlwaysInputMode != AlwaysInputEnabled )
2619 mpWindowImpl->meAlwaysInputMode = AlwaysInputEnabled;
2620 EnableInput(true, false);
2622 else if( ! bAlways && mpWindowImpl->meAlwaysInputMode == AlwaysInputEnabled )
2624 mpWindowImpl->meAlwaysInputMode = AlwaysInputNone;
2627 if ( bChild )
2629 VclPtr< vcl::Window > pChild = mpWindowImpl->mpFirstChild;
2630 while ( pChild )
2632 pChild->AlwaysEnableInput( bAlways, bChild );
2633 pChild = pChild->mpWindowImpl->mpNext;
2638 void Window::SetActivateMode( ActivateModeFlags nMode )
2641 if ( mpWindowImpl->mpBorderWindow )
2642 mpWindowImpl->mpBorderWindow->SetActivateMode( nMode );
2644 if ( mpWindowImpl->mnActivateMode == nMode )
2645 return;
2647 mpWindowImpl->mnActivateMode = nMode;
2649 // possibly trigger Deactivate/Activate
2650 if ( mpWindowImpl->mnActivateMode != ActivateModeFlags::NONE )
2652 if ( (mpWindowImpl->mbActive || (GetType() == WindowType::BORDERWINDOW)) &&
2653 !HasChildPathFocus( true ) )
2655 mpWindowImpl->mbActive = false;
2656 Deactivate();
2659 else
2661 if ( !mpWindowImpl->mbActive || (GetType() == WindowType::BORDERWINDOW) )
2663 mpWindowImpl->mbActive = true;
2664 Activate();
2669 void Window::setPosSizePixel( tools::Long nX, tools::Long nY,
2670 tools::Long nWidth, tools::Long nHeight, PosSizeFlags nFlags )
2672 bool bHasValidSize = !mpWindowImpl->mbDefSize;
2674 if ( nFlags & PosSizeFlags::Pos )
2675 mpWindowImpl->mbDefPos = false;
2676 if ( nFlags & PosSizeFlags::Size )
2677 mpWindowImpl->mbDefSize = false;
2679 // The top BorderWindow is the window which is to be positioned
2680 VclPtr<vcl::Window> pWindow = this;
2681 while ( pWindow->mpWindowImpl->mpBorderWindow )
2682 pWindow = pWindow->mpWindowImpl->mpBorderWindow;
2684 if ( pWindow->mpWindowImpl->mbFrame )
2686 // Note: if we're positioning a frame, the coordinates are interpreted
2687 // as being the top-left corner of the window's client area and NOT
2688 // as the position of the border ! (due to limitations of several UNIX window managers)
2689 tools::Long nOldWidth = pWindow->GetOutDev()->mnOutWidth;
2691 if ( !(nFlags & PosSizeFlags::Width) )
2692 nWidth = pWindow->GetOutDev()->mnOutWidth;
2693 if ( !(nFlags & PosSizeFlags::Height) )
2694 nHeight = pWindow->GetOutDev()->mnOutHeight;
2696 sal_uInt16 nSysFlags=0;
2697 VclPtr<vcl::Window> pParent = GetParent();
2698 VclPtr<vcl::Window> pWinParent = pWindow->GetParent();
2700 if( nFlags & PosSizeFlags::Width )
2701 nSysFlags |= SAL_FRAME_POSSIZE_WIDTH;
2702 if( nFlags & PosSizeFlags::Height )
2703 nSysFlags |= SAL_FRAME_POSSIZE_HEIGHT;
2704 if( nFlags & PosSizeFlags::X )
2706 nSysFlags |= SAL_FRAME_POSSIZE_X;
2707 if( pWinParent && (pWindow->GetStyle() & WB_SYSTEMCHILDWINDOW) )
2709 nX += pWinParent->GetOutDev()->mnOutOffX;
2711 if( pParent && pParent->GetOutDev()->ImplIsAntiparallel() )
2713 tools::Rectangle aRect( Point ( nX, nY ), Size( nWidth, nHeight ) );
2714 const OutputDevice *pParentOutDev = pParent->GetOutDev();
2715 if (!comphelper::LibreOfficeKit::isActive())
2716 pParentOutDev->ReMirror( aRect );
2717 nX = aRect.Left();
2720 if( !comphelper::LibreOfficeKit::isActive() &&
2721 !(nFlags & PosSizeFlags::X) && bHasValidSize &&
2722 pWindow->mpWindowImpl->mpFrame->maGeometry.width() )
2724 // RTL: make sure the old right aligned position is not changed
2725 // system windows will always grow to the right
2726 if ( pWinParent )
2728 OutputDevice *pParentOutDev = pWinParent->GetOutDev();
2729 if( pParentOutDev->HasMirroredGraphics() )
2731 const SalFrameGeometry& aSysGeometry = mpWindowImpl->mpFrame->GetUnmirroredGeometry();
2732 const SalFrameGeometry& aParentSysGeometry =
2733 pWinParent->mpWindowImpl->mpFrame->GetUnmirroredGeometry();
2734 tools::Long myWidth = nOldWidth;
2735 if( !myWidth )
2736 myWidth = aSysGeometry.width();
2737 if( !myWidth )
2738 myWidth = nWidth;
2739 nFlags |= PosSizeFlags::X;
2740 nSysFlags |= SAL_FRAME_POSSIZE_X;
2741 nX = aParentSysGeometry.x() - aSysGeometry.leftDecoration() + aParentSysGeometry.width()
2742 - myWidth - 1 - aSysGeometry.x();
2746 if( nFlags & PosSizeFlags::Y )
2748 nSysFlags |= SAL_FRAME_POSSIZE_Y;
2749 if( pWinParent && (pWindow->GetStyle() & WB_SYSTEMCHILDWINDOW) )
2751 nY += pWinParent->GetOutDev()->mnOutOffY;
2755 if( nSysFlags & (SAL_FRAME_POSSIZE_WIDTH|SAL_FRAME_POSSIZE_HEIGHT) )
2757 // check for min/max client size and adjust size accordingly
2758 // otherwise it may happen that the resize event is ignored, i.e. the old size remains
2759 // unchanged but ImplHandleResize() is called with the wrong size
2760 SystemWindow *pSystemWindow = dynamic_cast< SystemWindow* >( pWindow.get() );
2761 if( pSystemWindow )
2763 Size aMinSize = pSystemWindow->GetMinOutputSizePixel();
2764 Size aMaxSize = pSystemWindow->GetMaxOutputSizePixel();
2765 if( nWidth < aMinSize.Width() )
2766 nWidth = aMinSize.Width();
2767 if( nHeight < aMinSize.Height() )
2768 nHeight = aMinSize.Height();
2770 if( nWidth > aMaxSize.Width() )
2771 nWidth = aMaxSize.Width();
2772 if( nHeight > aMaxSize.Height() )
2773 nHeight = aMaxSize.Height();
2777 pWindow->mpWindowImpl->mpFrame->SetPosSize( nX, nY, nWidth, nHeight, nSysFlags );
2779 // Adjust resize with the hack of different client size and frame geometries to fix
2780 // native menu bars. Eventually this should be replaced by proper mnTopBorder usage.
2781 pWindow->mpWindowImpl->mpFrame->GetClientSize(nWidth, nHeight);
2783 // Resize should be called directly. If we haven't
2784 // set the correct size, we get a second resize from
2785 // the system with the correct size. This can be happened
2786 // if the size is too small or too large.
2787 ImplHandleResize( pWindow, nWidth, nHeight );
2789 else
2791 pWindow->ImplPosSizeWindow( nX, nY, nWidth, nHeight, nFlags );
2792 if ( IsReallyVisible() )
2793 ImplGenerateMouseMove();
2797 Point Window::GetPosPixel() const
2799 return mpWindowImpl->maPos;
2802 tools::Rectangle Window::GetDesktopRectPixel() const
2804 tools::Rectangle rRect;
2805 mpWindowImpl->mpFrameWindow->mpWindowImpl->mpFrame->GetWorkArea( rRect );
2806 return rRect;
2809 Point Window::OutputToScreenPixel( const Point& rPos ) const
2811 // relative to top level parent
2812 return Point( rPos.X() + GetOutDev()->mnOutOffX, rPos.Y() + GetOutDev()->mnOutOffY );
2815 Point Window::ScreenToOutputPixel( const Point& rPos ) const
2817 // relative to top level parent
2818 return Point( rPos.X() - GetOutDev()->mnOutOffX, rPos.Y() - GetOutDev()->mnOutOffY );
2821 tools::Long Window::ImplGetUnmirroredOutOffX()
2823 // revert mnOutOffX changes that were potentially made in ImplPosSizeWindow
2824 tools::Long offx = GetOutDev()->mnOutOffX;
2825 OutputDevice *pOutDev = GetOutDev();
2826 if( pOutDev->HasMirroredGraphics() )
2828 if( mpWindowImpl->mpParent && !mpWindowImpl->mpParent->mpWindowImpl->mbFrame && mpWindowImpl->mpParent->GetOutDev()->ImplIsAntiparallel() )
2830 if ( !ImplIsOverlapWindow() )
2831 offx -= mpWindowImpl->mpParent->GetOutDev()->mnOutOffX;
2833 offx = mpWindowImpl->mpParent->GetOutDev()->mnOutWidth - GetOutDev()->mnOutWidth - offx;
2835 if ( !ImplIsOverlapWindow() )
2836 offx += mpWindowImpl->mpParent->GetOutDev()->mnOutOffX;
2840 return offx;
2843 // normalized screen pixel are independent of mirroring
2844 Point Window::OutputToNormalizedScreenPixel( const Point& rPos ) const
2846 // relative to top level parent
2847 tools::Long offx = const_cast<vcl::Window*>(this)->ImplGetUnmirroredOutOffX();
2848 return Point( rPos.X()+offx, rPos.Y() + GetOutDev()->mnOutOffY );
2851 Point Window::NormalizedScreenToOutputPixel( const Point& rPos ) const
2853 // relative to top level parent
2854 tools::Long offx = const_cast<vcl::Window*>(this)->ImplGetUnmirroredOutOffX();
2855 return Point( rPos.X()-offx, rPos.Y() - GetOutDev()->mnOutOffY );
2858 Point Window::OutputToAbsoluteScreenPixel( const Point& rPos ) const
2860 // relative to the screen
2861 Point p = OutputToScreenPixel( rPos );
2862 SalFrameGeometry g = mpWindowImpl->mpFrame->GetGeometry();
2863 p.AdjustX(g.x() );
2864 p.AdjustY(g.y() );
2865 return p;
2868 Point Window::AbsoluteScreenToOutputPixel( const Point& rPos ) const
2870 // relative to the screen
2871 Point p = ScreenToOutputPixel( rPos );
2872 SalFrameGeometry g = mpWindowImpl->mpFrame->GetGeometry();
2873 p.AdjustX( -(g.x()) );
2874 p.AdjustY( -(g.y()) );
2875 return p;
2878 tools::Rectangle Window::ImplOutputToUnmirroredAbsoluteScreenPixel( const tools::Rectangle &rRect ) const
2880 // this method creates unmirrored screen coordinates to be compared with the desktop
2881 // and is used for positioning of RTL popup windows correctly on the screen
2882 SalFrameGeometry g = mpWindowImpl->mpFrame->GetUnmirroredGeometry();
2884 Point p1 = rRect.TopRight();
2885 p1 = OutputToScreenPixel(p1);
2886 p1.setX( g.x()+g.width()-p1.X() );
2887 p1.AdjustY(g.y() );
2889 Point p2 = rRect.BottomLeft();
2890 p2 = OutputToScreenPixel(p2);
2891 p2.setX( g.x()+g.width()-p2.X() );
2892 p2.AdjustY(g.y() );
2894 return tools::Rectangle( p1, p2 );
2897 tools::Rectangle Window::ImplUnmirroredAbsoluteScreenToOutputPixel( const tools::Rectangle &rRect ) const
2899 // undo ImplOutputToUnmirroredAbsoluteScreenPixel
2900 SalFrameGeometry g = mpWindowImpl->mpFrame->GetUnmirroredGeometry();
2902 Point p1 = rRect.TopRight();
2903 p1.AdjustY(-g.y() );
2904 p1.setX( g.x()+g.width()-p1.X() );
2905 p1 = ScreenToOutputPixel(p1);
2907 Point p2 = rRect.BottomLeft();
2908 p2.AdjustY(-g.y());
2909 p2.setX( g.x()+g.width()-p2.X() );
2910 p2 = ScreenToOutputPixel(p2);
2912 return tools::Rectangle( p1, p2 );
2916 tools::Rectangle Window::GetWindowExtentsRelative(const vcl::Window *pRelativeWindow) const
2918 // with decoration
2919 return ImplGetWindowExtentsRelative( pRelativeWindow );
2922 tools::Rectangle Window::ImplGetWindowExtentsRelative(const vcl::Window *pRelativeWindow) const
2924 SalFrameGeometry g = mpWindowImpl->mpFrame->GetGeometry();
2925 // make sure we use the extent of our border window,
2926 // otherwise we miss a few pixels
2927 const vcl::Window *pWin = mpWindowImpl->mpBorderWindow ? mpWindowImpl->mpBorderWindow : this;
2929 Point aPos( pWin->OutputToScreenPixel( Point(0,0) ) );
2930 aPos.AdjustX(g.x() );
2931 aPos.AdjustY(g.y() );
2932 Size aSize ( pWin->GetSizePixel() );
2933 // #104088# do not add decoration to the workwindow to be compatible to java accessibility api
2934 if( mpWindowImpl->mbFrame || (mpWindowImpl->mpBorderWindow && mpWindowImpl->mpBorderWindow->mpWindowImpl->mbFrame && GetType() != WindowType::WORKWINDOW) )
2936 aPos.AdjustX( -sal_Int32(g.leftDecoration()) );
2937 aPos.AdjustY( -sal_Int32(g.topDecoration()) );
2938 aSize.AdjustWidth(g.leftDecoration() + g.rightDecoration() );
2939 aSize.AdjustHeight(g.topDecoration() + g.bottomDecoration() );
2941 if( pRelativeWindow )
2943 // #106399# express coordinates relative to borderwindow
2944 const vcl::Window *pRelWin = pRelativeWindow->mpWindowImpl->mpBorderWindow ? pRelativeWindow->mpWindowImpl->mpBorderWindow.get() : pRelativeWindow;
2945 aPos = pRelWin->AbsoluteScreenToOutputPixel( aPos );
2947 return tools::Rectangle( aPos, aSize );
2950 void Window::Scroll( tools::Long nHorzScroll, tools::Long nVertScroll, ScrollFlags nFlags )
2953 ImplScroll( GetOutputRectPixel(),
2954 nHorzScroll, nVertScroll, nFlags & ~ScrollFlags::Clip );
2957 void Window::Scroll( tools::Long nHorzScroll, tools::Long nVertScroll,
2958 const tools::Rectangle& rRect, ScrollFlags nFlags )
2960 OutputDevice *pOutDev = GetOutDev();
2961 tools::Rectangle aRect = pOutDev->ImplLogicToDevicePixel( rRect );
2962 aRect.Intersection( GetOutputRectPixel() );
2963 if ( !aRect.IsEmpty() )
2964 ImplScroll( aRect, nHorzScroll, nVertScroll, nFlags );
2967 void WindowOutputDevice::Flush()
2969 if (mxOwnerWindow->mpWindowImpl)
2970 mxOwnerWindow->mpWindowImpl->mpFrame->Flush( GetOutputRectPixel() );
2973 void Window::SetUpdateMode( bool bUpdate )
2975 if (mpWindowImpl)
2977 mpWindowImpl->mbNoUpdate = !bUpdate;
2978 CompatStateChanged( StateChangedType::UpdateMode );
2982 void Window::GrabFocus()
2984 ImplGrabFocus( GetFocusFlags::NONE );
2987 bool Window::HasFocus() const
2989 return (this == ImplGetSVData()->mpWinData->mpFocusWin);
2992 void Window::GrabFocusToDocument()
2994 ImplGrabFocusToDocument(GetFocusFlags::NONE);
2997 VclPtr<vcl::Window> Window::GetFocusedWindow() const
2999 if (mpWindowImpl && mpWindowImpl->mpFrameData)
3000 return mpWindowImpl->mpFrameData->mpFocusWin;
3001 else
3002 return VclPtr<vcl::Window>();
3005 void Window::SetFakeFocus( bool bFocus )
3007 ImplGetWindowImpl()->mbFakeFocusSet = bFocus;
3010 bool Window::HasChildPathFocus( bool bSystemWindow ) const
3013 vcl::Window* pFocusWin = ImplGetSVData()->mpWinData->mpFocusWin;
3014 if ( pFocusWin )
3015 return ImplIsWindowOrChild( pFocusWin, bSystemWindow );
3016 return false;
3019 void Window::SetCursor( vcl::Cursor* pCursor )
3022 if ( mpWindowImpl->mpCursor != pCursor )
3024 if ( mpWindowImpl->mpCursor )
3025 mpWindowImpl->mpCursor->ImplHide();
3026 mpWindowImpl->mpCursor = pCursor;
3027 if ( pCursor )
3028 pCursor->ImplShow();
3032 void Window::SetText( const OUString& rStr )
3034 if (!mpWindowImpl || rStr == mpWindowImpl->maText)
3035 return;
3037 OUString oldTitle( mpWindowImpl->maText );
3038 mpWindowImpl->maText = rStr;
3040 if ( mpWindowImpl->mpBorderWindow )
3041 mpWindowImpl->mpBorderWindow->SetText( rStr );
3042 else if ( mpWindowImpl->mbFrame )
3043 mpWindowImpl->mpFrame->SetTitle( rStr );
3045 CallEventListeners( VclEventId::WindowFrameTitleChanged, &oldTitle );
3047 // #107247# needed for accessibility
3048 // The VclEventId::WindowFrameTitleChanged is (mis)used to notify accessible name changes.
3049 // Therefore a window, which is labeled by this window, must also notify an accessible
3050 // name change.
3051 if ( IsReallyVisible() )
3053 vcl::Window* pWindow = GetAccessibleRelationLabelFor();
3054 if ( pWindow && pWindow != this )
3055 pWindow->CallEventListeners( VclEventId::WindowFrameTitleChanged, &oldTitle );
3058 CompatStateChanged( StateChangedType::Text );
3061 OUString Window::GetText() const
3064 return mpWindowImpl->maText;
3067 OUString Window::GetDisplayText() const
3070 return GetText();
3073 const Wallpaper& Window::GetDisplayBackground() const
3075 // FIXME: fix issue 52349, need to fix this really in
3076 // all NWF enabled controls
3077 const ToolBox* pTB = dynamic_cast<const ToolBox*>(this);
3078 if( pTB && IsNativeWidgetEnabled() )
3079 return pTB->ImplGetToolBoxPrivateData()->maDisplayBackground;
3081 if( !IsBackground() )
3083 if( mpWindowImpl->mpParent )
3084 return mpWindowImpl->mpParent->GetDisplayBackground();
3087 const Wallpaper& rBack = GetBackground();
3088 if( ! rBack.IsBitmap() &&
3089 ! rBack.IsGradient() &&
3090 rBack.GetColor()== COL_TRANSPARENT &&
3091 mpWindowImpl->mpParent )
3092 return mpWindowImpl->mpParent->GetDisplayBackground();
3093 return rBack;
3096 const OUString& Window::GetHelpText() const
3098 OUString aStrHelpId( GetHelpId() );
3099 bool bStrHelpId = !aStrHelpId.isEmpty();
3101 if ( !mpWindowImpl->maHelpText.getLength() && bStrHelpId )
3103 if ( !IsDialog() && (mpWindowImpl->mnType != WindowType::TABPAGE) && (mpWindowImpl->mnType != WindowType::FLOATINGWINDOW) )
3105 Help* pHelp = Application::GetHelp();
3106 if ( pHelp )
3108 mpWindowImpl->maHelpText = pHelp->GetHelpText(aStrHelpId, this);
3109 mpWindowImpl->mbHelpTextDynamic = false;
3113 else if( mpWindowImpl->mbHelpTextDynamic && bStrHelpId )
3115 static const char* pEnv = getenv( "HELP_DEBUG" );
3116 if( pEnv && *pEnv )
3118 OUString aTxt = mpWindowImpl->maHelpText + "\n------------------\n" + aStrHelpId;
3119 mpWindowImpl->maHelpText = aTxt;
3121 mpWindowImpl->mbHelpTextDynamic = false;
3124 //Fallback to Window::GetAccessibleDescription without reentry to GetHelpText()
3125 if (mpWindowImpl->maHelpText.isEmpty() && mpWindowImpl->mpAccessibleInfos && mpWindowImpl->mpAccessibleInfos->pAccessibleDescription)
3126 return *mpWindowImpl->mpAccessibleInfos->pAccessibleDescription;
3127 return mpWindowImpl->maHelpText;
3130 void Window::SetWindowPeer( Reference< css::awt::XVclWindowPeer > const & xPeer, VCLXWindow* pVCLXWindow )
3132 if (!mpWindowImpl || mpWindowImpl->mbInDispose)
3133 return;
3135 // be safe against re-entrance: first clear the old ref, then assign the new one
3136 if (mpWindowImpl->mxWindowPeer)
3138 // first, disconnect the peer from ourself, otherwise disposing it, will dispose us
3139 UnoWrapperBase* pWrapper = UnoWrapperBase::GetUnoWrapper();
3140 SAL_WARN_IF( !pWrapper, "vcl.window", "SetComponentInterface: No Wrapper!" );
3141 if ( pWrapper )
3142 pWrapper->SetWindowInterface( nullptr, mpWindowImpl->mxWindowPeer );
3143 mpWindowImpl->mxWindowPeer->dispose();
3144 mpWindowImpl->mxWindowPeer.clear();
3146 mpWindowImpl->mxWindowPeer = xPeer;
3148 mpWindowImpl->mpVCLXWindow = pVCLXWindow;
3151 Reference< css::awt::XVclWindowPeer > Window::GetComponentInterface( bool bCreate )
3153 if ( !mpWindowImpl->mxWindowPeer.is() && bCreate )
3155 UnoWrapperBase* pWrapper = UnoWrapperBase::GetUnoWrapper();
3156 if ( pWrapper )
3157 mpWindowImpl->mxWindowPeer = pWrapper->GetWindowInterface( this );
3159 return mpWindowImpl->mxWindowPeer;
3162 void Window::SetComponentInterface( Reference< css::awt::XVclWindowPeer > const & xIFace )
3164 UnoWrapperBase* pWrapper = UnoWrapperBase::GetUnoWrapper();
3165 SAL_WARN_IF( !pWrapper, "vcl.window", "SetComponentInterface: No Wrapper!" );
3166 if ( pWrapper )
3167 pWrapper->SetWindowInterface( this, xIFace );
3170 typedef std::map<vcl::LOKWindowId, VclPtr<vcl::Window>> LOKWindowsMap;
3172 namespace {
3174 LOKWindowsMap& GetLOKWindowsMap()
3176 // Map to remember the LOKWindowId <-> Window binding.
3177 static LOKWindowsMap s_aLOKWindowsMap;
3179 return s_aLOKWindowsMap;
3184 void Window::SetLOKNotifier(const vcl::ILibreOfficeKitNotifier* pNotifier, bool bParent)
3186 // don't allow setting this twice
3187 assert(mpWindowImpl->mpLOKNotifier == nullptr);
3188 assert(pNotifier);
3189 // never use this in the desktop case
3190 assert(comphelper::LibreOfficeKit::isActive());
3192 if (!bParent)
3194 // Counter to be able to have unique id's for each window.
3195 static vcl::LOKWindowId sLastLOKWindowId = 1;
3197 // assign the LOK window id
3198 assert(mpWindowImpl->mnLOKWindowId == 0);
3199 mpWindowImpl->mnLOKWindowId = sLastLOKWindowId++;
3200 GetLOKWindowsMap().emplace(mpWindowImpl->mnLOKWindowId, this);
3203 mpWindowImpl->mpLOKNotifier = pNotifier;
3206 VclPtr<Window> Window::FindLOKWindow(vcl::LOKWindowId nWindowId)
3208 const auto it = GetLOKWindowsMap().find(nWindowId);
3209 if (it != GetLOKWindowsMap().end())
3210 return it->second;
3212 return VclPtr<Window>();
3215 bool Window::IsLOKWindowsEmpty()
3217 return GetLOKWindowsMap().empty();
3220 void Window::ReleaseLOKNotifier()
3222 // unregister the LOK window binding
3223 if (mpWindowImpl->mnLOKWindowId > 0)
3224 GetLOKWindowsMap().erase(mpWindowImpl->mnLOKWindowId);
3226 mpWindowImpl->mpLOKNotifier = nullptr;
3227 mpWindowImpl->mnLOKWindowId = 0;
3230 ILibreOfficeKitNotifier::~ILibreOfficeKitNotifier()
3232 if (!comphelper::LibreOfficeKit::isActive())
3234 return;
3237 for (auto it = GetLOKWindowsMap().begin(); it != GetLOKWindowsMap().end();)
3239 WindowImpl* pWindowImpl = it->second->ImplGetWindowImpl();
3240 if (pWindowImpl && pWindowImpl->mpLOKNotifier == this)
3242 pWindowImpl->mpLOKNotifier = nullptr;
3243 pWindowImpl->mnLOKWindowId = 0;
3244 it = GetLOKWindowsMap().erase(it);
3245 continue;
3248 ++it;
3252 const vcl::ILibreOfficeKitNotifier* Window::GetLOKNotifier() const
3254 return mpWindowImpl ? mpWindowImpl->mpLOKNotifier : nullptr;
3257 vcl::LOKWindowId Window::GetLOKWindowId() const
3259 return mpWindowImpl ? mpWindowImpl->mnLOKWindowId : 0;
3262 VclPtr<vcl::Window> Window::GetParentWithLOKNotifier()
3264 VclPtr<vcl::Window> pWindow(this);
3266 while (pWindow && !pWindow->GetLOKNotifier())
3267 pWindow = pWindow->GetParent();
3269 return pWindow;
3272 namespace
3275 std::string_view windowTypeName(WindowType nWindowType)
3277 switch (nWindowType)
3279 case WindowType::NONE: return "none";
3280 case WindowType::MESSBOX: return "messagebox";
3281 case WindowType::INFOBOX: return "infobox";
3282 case WindowType::WARNINGBOX: return "warningbox";
3283 case WindowType::ERRORBOX: return "errorbox";
3284 case WindowType::QUERYBOX: return "querybox";
3285 case WindowType::WINDOW: return "window";
3286 case WindowType::WORKWINDOW: return "workwindow";
3287 case WindowType::CONTAINER: return "container";
3288 case WindowType::FLOATINGWINDOW: return "floatingwindow";
3289 case WindowType::DIALOG: return "dialog";
3290 case WindowType::MODELESSDIALOG: return "modelessdialog";
3291 case WindowType::CONTROL: return "control";
3292 case WindowType::PUSHBUTTON: return "pushbutton";
3293 case WindowType::OKBUTTON: return "okbutton";
3294 case WindowType::CANCELBUTTON: return "cancelbutton";
3295 case WindowType::HELPBUTTON: return "helpbutton";
3296 case WindowType::IMAGEBUTTON: return "imagebutton";
3297 case WindowType::MENUBUTTON: return "menubutton";
3298 case WindowType::MOREBUTTON: return "morebutton";
3299 case WindowType::SPINBUTTON: return "spinbutton";
3300 case WindowType::RADIOBUTTON: return "radiobutton";
3301 case WindowType::CHECKBOX: return "checkbox";
3302 case WindowType::TRISTATEBOX: return "tristatebox";
3303 case WindowType::EDIT: return "edit";
3304 case WindowType::MULTILINEEDIT: return "multilineedit";
3305 case WindowType::COMBOBOX: return "combobox";
3306 case WindowType::LISTBOX: return "listbox";
3307 case WindowType::MULTILISTBOX: return "multilistbox";
3308 case WindowType::FIXEDTEXT: return "fixedtext";
3309 case WindowType::FIXEDLINE: return "fixedline";
3310 case WindowType::FIXEDBITMAP: return "fixedbitmap";
3311 case WindowType::FIXEDIMAGE: return "fixedimage";
3312 case WindowType::GROUPBOX: return "groupbox";
3313 case WindowType::SCROLLBAR: return "scrollbar";
3314 case WindowType::SCROLLBARBOX: return "scrollbarbox";
3315 case WindowType::SPLITTER: return "splitter";
3316 case WindowType::SPLITWINDOW: return "splitwindow";
3317 case WindowType::SPINFIELD: return "spinfield";
3318 case WindowType::PATTERNFIELD: return "patternfield";
3319 case WindowType::METRICFIELD: return "metricfield";
3320 case WindowType::FORMATTEDFIELD: return "formattedfield";
3321 case WindowType::CURRENCYFIELD: return "currencyfield";
3322 case WindowType::DATEFIELD: return "datefield";
3323 case WindowType::TIMEFIELD: return "timefield";
3324 case WindowType::PATTERNBOX: return "patternbox";
3325 case WindowType::NUMERICBOX: return "numericbox";
3326 case WindowType::METRICBOX: return "metricbox";
3327 case WindowType::CURRENCYBOX: return "currencybox";
3328 case WindowType::DATEBOX: return "datebox";
3329 case WindowType::TIMEBOX: return "timebox";
3330 case WindowType::LONGCURRENCYBOX: return "longcurrencybox";
3331 case WindowType::SCROLLWINDOW: return "scrollwindow";
3332 case WindowType::TOOLBOX: return "toolbox";
3333 case WindowType::DOCKINGWINDOW: return "dockingwindow";
3334 case WindowType::STATUSBAR: return "statusbar";
3335 case WindowType::TABPAGE: return "tabpage";
3336 case WindowType::TABCONTROL: return "tabcontrol";
3337 case WindowType::TABDIALOG: return "tabdialog";
3338 case WindowType::BORDERWINDOW: return "borderwindow";
3339 case WindowType::BUTTONDIALOG: return "buttondialog";
3340 case WindowType::SYSTEMCHILDWINDOW: return "systemchildwindow";
3341 case WindowType::SLIDER: return "slider";
3342 case WindowType::MENUBARWINDOW: return "menubarwindow";
3343 case WindowType::TREELISTBOX: return "treelistbox";
3344 case WindowType::HELPTEXTWINDOW: return "helptextwindow";
3345 case WindowType::INTROWINDOW: return "introwindow";
3346 case WindowType::LISTBOXWINDOW: return "listboxwindow";
3347 case WindowType::DOCKINGAREA: return "dockingarea";
3348 case WindowType::RULER: return "ruler";
3349 case WindowType::HEADERBAR: return "headerbar";
3350 case WindowType::VERTICALTABCONTROL: return "verticaltabcontrol";
3352 // nothing to do here, but for completeness
3353 case WindowType::TOOLKIT_FRAMEWINDOW: return "toolkit_framewindow";
3354 case WindowType::TOOLKIT_SYSTEMCHILDWINDOW: return "toolkit_systemchildwindow";
3357 return "none";
3362 void Window::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter)
3364 if (!mpWindowImpl)
3365 return;
3367 rJsonWriter.put("id", get_id()); // TODO could be missing - sort out
3368 rJsonWriter.put("type", windowTypeName(GetType()));
3369 rJsonWriter.put("text", GetText());
3370 rJsonWriter.put("enabled", IsEnabled());
3371 if (!IsVisible())
3372 rJsonWriter.put("visible", false);
3374 if (vcl::Window* pChild = mpWindowImpl->mpFirstChild)
3376 auto childrenNode = rJsonWriter.startArray("children");
3377 while (pChild)
3380 auto childNode = rJsonWriter.startStruct();
3381 pChild->DumpAsPropertyTree(rJsonWriter);
3382 sal_Int32 nLeft = pChild->get_grid_left_attach();
3383 sal_Int32 nTop = pChild->get_grid_top_attach();
3384 if (nLeft != -1 && nTop != -1)
3386 rJsonWriter.put("left", nLeft);
3387 rJsonWriter.put("top", nTop);
3390 sal_Int32 nWidth = pChild->get_grid_width();
3391 if (nWidth > 1)
3392 rJsonWriter.put("width", nWidth);
3394 pChild = pChild->mpWindowImpl->mpNext;
3398 vcl::Window* pAccLabelFor = getAccessibleRelationLabelFor();
3399 if (pAccLabelFor)
3400 rJsonWriter.put("labelFor", pAccLabelFor->get_id());
3402 vcl::Window* pAccLabelledBy = GetAccessibleRelationLabeledBy();
3403 if (pAccLabelledBy)
3404 rJsonWriter.put("labelledBy", pAccLabelledBy->get_id());
3406 mpWindowImpl->maDumpAsPropertyTreeHdl.Call(rJsonWriter);
3409 void Window::ImplCallDeactivateListeners( vcl::Window *pNew )
3411 // no deactivation if the newly activated window is my child
3412 if ( !pNew || !ImplIsChild( pNew ) )
3414 VclPtr<vcl::Window> xWindow(this);
3415 CallEventListeners( VclEventId::WindowDeactivate, pNew );
3416 if( !xWindow->mpWindowImpl )
3417 return;
3419 // #100759#, avoid walking the wrong frame's hierarchy
3420 // eg, undocked docking windows (ImplDockFloatWin)
3421 if ( ImplGetParent() && ImplGetParent()->mpWindowImpl &&
3422 mpWindowImpl->mpFrameWindow == ImplGetParent()->mpWindowImpl->mpFrameWindow )
3423 ImplGetParent()->ImplCallDeactivateListeners( pNew );
3427 void Window::ImplCallActivateListeners( vcl::Window *pOld )
3429 // no activation if the old active window is my child
3430 if ( pOld && ImplIsChild( pOld ))
3431 return;
3433 VclPtr<vcl::Window> xWindow(this);
3434 CallEventListeners( VclEventId::WindowActivate, pOld );
3435 if( !xWindow->mpWindowImpl )
3436 return;
3438 if ( ImplGetParent() )
3439 ImplGetParent()->ImplCallActivateListeners( pOld );
3440 else if( (mpWindowImpl->mnStyle & WB_INTROWIN) == 0 )
3442 // top level frame reached: store hint for DefModalDialogParent
3443 ImplGetSVData()->maFrameData.mpActiveApplicationFrame = mpWindowImpl->mpFrameWindow;
3447 void Window::SetClipboard(Reference<XClipboard> const & xClipboard)
3449 if (mpWindowImpl->mpFrameData)
3450 mpWindowImpl->mpFrameData->mxClipboard = xClipboard;
3453 Reference< XClipboard > Window::GetClipboard()
3455 if (!mpWindowImpl->mpFrameData)
3456 return static_cast<XClipboard*>(nullptr);
3457 if (!mpWindowImpl->mpFrameData->mxClipboard.is())
3458 mpWindowImpl->mpFrameData->mxClipboard = GetSystemClipboard();
3459 return mpWindowImpl->mpFrameData->mxClipboard;
3462 void Window::RecordLayoutData( vcl::ControlLayoutData* pLayout, const tools::Rectangle& rRect )
3464 assert(GetOutDev()->mpOutDevData);
3465 GetOutDev()->mpOutDevData->mpRecordLayout = pLayout;
3466 GetOutDev()->mpOutDevData->maRecordRect = rRect;
3467 Paint(*GetOutDev(), rRect);
3468 GetOutDev()->mpOutDevData->mpRecordLayout = nullptr;
3471 void Window::DrawSelectionBackground( const tools::Rectangle& rRect,
3472 sal_uInt16 highlight,
3473 bool bChecked,
3474 bool bDrawBorder
3477 if( rRect.IsEmpty() )
3478 return;
3480 const StyleSettings& rStyles = GetSettings().GetStyleSettings();
3482 // colors used for item highlighting
3483 Color aSelectionBorderCol( rStyles.GetHighlightColor() );
3484 Color aSelectionFillCol( aSelectionBorderCol );
3486 bool bDark = rStyles.GetFaceColor().IsDark();
3487 bool bBright = ( rStyles.GetFaceColor() == COL_WHITE );
3489 int c1 = aSelectionBorderCol.GetLuminance();
3490 int c2 = GetBackgroundColor().GetLuminance();
3492 if( !bDark && !bBright && abs( c2-c1 ) < 75 )
3494 // contrast too low
3495 sal_uInt16 h,s,b;
3496 aSelectionFillCol.RGBtoHSB( h, s, b );
3497 if( b > 50 ) b -= 40;
3498 else b += 40;
3499 aSelectionFillCol = Color::HSBtoRGB( h, s, b );
3500 aSelectionBorderCol = aSelectionFillCol;
3503 tools::Rectangle aRect( rRect );
3504 Color oldFillCol = GetOutDev()->GetFillColor();
3505 Color oldLineCol = GetOutDev()->GetLineColor();
3507 if( bDrawBorder )
3508 GetOutDev()->SetLineColor( bDark ? COL_WHITE : ( bBright ? COL_BLACK : aSelectionBorderCol ) );
3509 else
3510 GetOutDev()->SetLineColor();
3512 sal_uInt16 nPercent = 0;
3513 if( !highlight )
3515 if( bDark )
3516 aSelectionFillCol = COL_BLACK;
3517 else
3518 nPercent = 80; // just checked (light)
3520 else
3522 if( bChecked && highlight == 2 )
3524 if( bDark )
3525 aSelectionFillCol = COL_LIGHTGRAY;
3526 else if ( bBright )
3528 aSelectionFillCol = COL_BLACK;
3529 GetOutDev()->SetLineColor( COL_BLACK );
3530 nPercent = 0;
3532 else
3533 nPercent = 20; // selected, pressed or checked ( very dark )
3535 else if( bChecked || highlight == 1 )
3537 if( bDark )
3538 aSelectionFillCol = COL_GRAY;
3539 else if ( bBright )
3541 aSelectionFillCol = COL_BLACK;
3542 GetOutDev()->SetLineColor( COL_BLACK );
3543 nPercent = 0;
3545 else
3546 nPercent = 35; // selected, pressed or checked ( very dark )
3548 else
3550 if( bDark )
3551 aSelectionFillCol = COL_LIGHTGRAY;
3552 else if ( bBright )
3554 aSelectionFillCol = COL_BLACK;
3555 GetOutDev()->SetLineColor( COL_BLACK );
3556 if( highlight == 3 )
3557 nPercent = 80;
3558 else
3559 nPercent = 0;
3561 else
3562 nPercent = 70; // selected ( dark )
3566 GetOutDev()->SetFillColor( aSelectionFillCol );
3568 if( bDark )
3570 GetOutDev()->DrawRect( aRect );
3572 else
3574 tools::Polygon aPoly( aRect );
3575 tools::PolyPolygon aPolyPoly( aPoly );
3576 GetOutDev()->DrawTransparent( aPolyPoly, nPercent );
3579 GetOutDev()->SetFillColor( oldFillCol );
3580 GetOutDev()->SetLineColor( oldLineCol );
3583 bool Window::IsScrollable() const
3585 // check for scrollbars
3586 VclPtr< vcl::Window > pChild = mpWindowImpl->mpFirstChild;
3587 while( pChild )
3589 if( pChild->GetType() == WindowType::SCROLLBAR )
3590 return true;
3591 else
3592 pChild = pChild->mpWindowImpl->mpNext;
3594 return false;
3597 void Window::ImplMirrorFramePos( Point &pt ) const
3599 pt.setX( mpWindowImpl->mpFrame->maGeometry.width()-1-pt.X() );
3602 // frame based modal counter (dialogs are not modal to the whole application anymore)
3603 bool Window::IsInModalMode() const
3605 return (mpWindowImpl->mpFrameWindow->mpWindowImpl->mpFrameData->mnModalMode != 0);
3608 void Window::IncModalCount()
3610 vcl::Window* pFrameWindow = mpWindowImpl->mpFrameWindow;
3611 vcl::Window* pParent = pFrameWindow;
3612 while( pFrameWindow )
3614 pFrameWindow->mpWindowImpl->mpFrameData->mnModalMode++;
3615 while( pParent && pParent->mpWindowImpl->mpFrameWindow == pFrameWindow )
3617 pParent = pParent->GetParent();
3619 pFrameWindow = pParent ? pParent->mpWindowImpl->mpFrameWindow.get() : nullptr;
3622 void Window::DecModalCount()
3624 vcl::Window* pFrameWindow = mpWindowImpl->mpFrameWindow;
3625 vcl::Window* pParent = pFrameWindow;
3626 while( pFrameWindow )
3628 pFrameWindow->mpWindowImpl->mpFrameData->mnModalMode--;
3629 while( pParent && pParent->mpWindowImpl->mpFrameWindow == pFrameWindow )
3631 pParent = pParent->GetParent();
3633 pFrameWindow = pParent ? pParent->mpWindowImpl->mpFrameWindow.get() : nullptr;
3637 void Window::ImplIsInTaskPaneList( bool mbIsInTaskList )
3639 mpWindowImpl->mbIsInTaskPaneList = mbIsInTaskList;
3642 void Window::ImplNotifyIconifiedState( bool bIconified )
3644 mpWindowImpl->mpFrameWindow->CallEventListeners( bIconified ? VclEventId::WindowMinimize : VclEventId::WindowNormalize );
3645 // #109206# notify client window as well to have toolkit topwindow listeners notified
3646 if( mpWindowImpl->mpFrameWindow->mpWindowImpl->mpClientWindow && mpWindowImpl->mpFrameWindow != mpWindowImpl->mpFrameWindow->mpWindowImpl->mpClientWindow )
3647 mpWindowImpl->mpFrameWindow->mpWindowImpl->mpClientWindow->CallEventListeners( bIconified ? VclEventId::WindowMinimize : VclEventId::WindowNormalize );
3650 bool Window::HasActiveChildFrame() const
3652 bool bRet = false;
3653 vcl::Window *pFrameWin = ImplGetSVData()->maFrameData.mpFirstFrame;
3654 while( pFrameWin )
3656 if( pFrameWin != mpWindowImpl->mpFrameWindow )
3658 bool bDecorated = false;
3659 VclPtr< vcl::Window > pChildFrame = pFrameWin->ImplGetWindow();
3660 // #i15285# unfortunately WB_MOVEABLE is the same as WB_TABSTOP which can
3661 // be removed for ToolBoxes to influence the keyboard accessibility
3662 // thus WB_MOVEABLE is no indicator for decoration anymore
3663 // but FloatingWindows carry this information in their TitleType...
3664 // TODO: avoid duplicate WinBits !!!
3665 if( pChildFrame && pChildFrame->ImplIsFloatingWindow() )
3666 bDecorated = static_cast<FloatingWindow*>(pChildFrame.get())->GetTitleType() != FloatWinTitleType::NONE;
3667 if( bDecorated || (pFrameWin->mpWindowImpl->mnStyle & (WB_MOVEABLE | WB_SIZEABLE) ) )
3668 if( pChildFrame && pChildFrame->IsVisible() && pChildFrame->IsActive() )
3670 if( ImplIsChild( pChildFrame, true ) )
3672 bRet = true;
3673 break;
3677 pFrameWin = pFrameWin->mpWindowImpl->mpFrameData->mpNextFrame;
3679 return bRet;
3682 LanguageType Window::GetInputLanguage() const
3684 return mpWindowImpl->mpFrame->GetInputLanguage();
3687 void Window::EnableNativeWidget( bool bEnable )
3689 static const char* pNoNWF = getenv( "SAL_NO_NWF" );
3690 if( pNoNWF && *pNoNWF )
3691 bEnable = false;
3693 if( bEnable != ImplGetWinData()->mbEnableNativeWidget )
3695 ImplGetWinData()->mbEnableNativeWidget = bEnable;
3697 // send datachanged event to allow for internal changes required for NWF
3698 // like clipmode, transparency, etc.
3699 DataChangedEvent aDCEvt( DataChangedEventType::SETTINGS, &*GetOutDev()->moSettings, AllSettingsFlags::STYLE );
3700 CompatDataChanged( aDCEvt );
3702 // sometimes the borderwindow is queried, so keep it in sync
3703 if( mpWindowImpl->mpBorderWindow )
3704 mpWindowImpl->mpBorderWindow->ImplGetWinData()->mbEnableNativeWidget = bEnable;
3707 // push down, useful for compound controls
3708 VclPtr< vcl::Window > pChild = mpWindowImpl->mpFirstChild;
3709 while( pChild )
3711 pChild->EnableNativeWidget( bEnable );
3712 pChild = pChild->mpWindowImpl->mpNext;
3716 bool Window::IsNativeWidgetEnabled() const
3718 return mpWindowImpl && ImplGetWinData()->mbEnableNativeWidget;
3721 Reference< css::rendering::XCanvas > WindowOutputDevice::ImplGetCanvas( bool bSpriteCanvas ) const
3723 // Feed any with operating system's window handle
3725 // common: first any is VCL pointer to window (for VCL canvas)
3726 Sequence< Any > aArg{
3727 Any(reinterpret_cast<sal_Int64>(this)),
3728 Any(css::awt::Rectangle( mnOutOffX, mnOutOffY, mnOutWidth, mnOutHeight )),
3729 Any(mxOwnerWindow->mpWindowImpl->mbAlwaysOnTop),
3730 Any(Reference< css::awt::XWindow >(
3731 mxOwnerWindow->GetComponentInterface(),
3732 UNO_QUERY )),
3733 GetSystemGfxDataAny()
3736 Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
3738 // Create canvas instance with window handle
3740 static vcl::DeleteUnoReferenceOnDeinit<XMultiComponentFactory> xStaticCanvasFactory(
3741 css::rendering::CanvasFactory::create( xContext ) );
3742 Reference<XMultiComponentFactory> xCanvasFactory(xStaticCanvasFactory.get());
3743 Reference< css::rendering::XCanvas > xCanvas;
3745 if(xCanvasFactory.is())
3747 #ifdef _WIN32
3748 // see #140456# - if we're running on a multiscreen setup,
3749 // request special, multi-screen safe sprite canvas
3750 // implementation (not DX5 canvas, as it cannot cope with
3751 // surfaces spanning multiple displays). Note: canvas
3752 // (without sprite) stays the same)
3753 const sal_uInt32 nDisplay = static_cast< WinSalFrame* >( mxOwnerWindow->mpWindowImpl->mpFrame )->mnDisplay;
3754 if( nDisplay >= Application::GetScreenCount() )
3756 xCanvas.set( xCanvasFactory->createInstanceWithArgumentsAndContext(
3757 bSpriteCanvas ?
3758 OUString( "com.sun.star.rendering.SpriteCanvas.MultiScreen" ) :
3759 OUString( "com.sun.star.rendering.Canvas.MultiScreen" ),
3760 aArg,
3761 xContext ),
3762 UNO_QUERY );
3765 else
3766 #endif
3768 xCanvas.set( xCanvasFactory->createInstanceWithArgumentsAndContext(
3769 bSpriteCanvas ?
3770 OUString( "com.sun.star.rendering.SpriteCanvas" ) :
3771 OUString( "com.sun.star.rendering.Canvas" ),
3772 aArg,
3773 xContext ),
3774 UNO_QUERY );
3779 // no factory??? Empty reference, then.
3780 return xCanvas;
3783 OUString Window::GetSurroundingText() const
3785 return OUString();
3788 Selection Window::GetSurroundingTextSelection() const
3790 return Selection( 0, 0 );
3793 namespace
3795 using namespace com::sun::star;
3797 uno::Reference<accessibility::XAccessibleEditableText> lcl_GetxText(vcl::Window *pFocusWin)
3799 uno::Reference<accessibility::XAccessibleEditableText> xText;
3802 uno::Reference< accessibility::XAccessible > xAccessible( pFocusWin->GetAccessible() );
3803 if (xAccessible.is())
3804 xText = FindFocusedEditableText(xAccessible->getAccessibleContext());
3806 catch(const uno::Exception&)
3808 TOOLS_WARN_EXCEPTION( "vcl.gtk3", "Exception in getting input method surrounding text");
3810 return xText;
3814 // this is a rubbish implementation using a11y, ideally all subclasses implementing
3815 // GetSurroundingText/GetSurroundingTextSelection should implement this and then this
3816 // should be removed in favor of a stub that returns false
3817 bool Window::DeleteSurroundingText(const Selection& rSelection)
3819 uno::Reference<accessibility::XAccessibleEditableText> xText = lcl_GetxText(this);
3820 if (xText.is())
3822 sal_Int32 nPosition = xText->getCaretPosition();
3823 // #i111768# range checking
3824 sal_Int32 nDeletePos = rSelection.Min();
3825 sal_Int32 nDeleteEnd = rSelection.Max();
3826 if (nDeletePos < 0)
3827 nDeletePos = 0;
3828 if (nDeleteEnd < 0)
3829 nDeleteEnd = 0;
3830 if (nDeleteEnd > xText->getCharacterCount())
3831 nDeleteEnd = xText->getCharacterCount();
3833 xText->deleteText(nDeletePos, nDeleteEnd);
3834 //tdf91641 adjust cursor if deleted chars shift it forward (normal case)
3835 if (nDeletePos < nPosition)
3837 if (nDeleteEnd <= nPosition)
3838 nPosition = nPosition - (nDeleteEnd - nDeletePos);
3839 else
3840 nPosition = nDeletePos;
3842 if (xText->getCharacterCount() >= nPosition)
3843 xText->setCaretPosition( nPosition );
3845 return true;
3848 return false;
3851 bool WindowOutputDevice::UsePolyPolygonForComplexGradient()
3853 return meRasterOp != RasterOp::OverPaint;
3856 void Window::ApplySettings(vcl::RenderContext& /*rRenderContext*/)
3860 const SystemEnvData* Window::GetSystemData() const
3863 return mpWindowImpl->mpFrame ? mpWindowImpl->mpFrame->GetSystemData() : nullptr;
3866 bool Window::SupportsDoubleBuffering() const
3868 return mpWindowImpl->mpFrameData->mpBuffer;
3871 void Window::RequestDoubleBuffering(bool bRequest)
3873 if (bRequest)
3875 mpWindowImpl->mpFrameData->mpBuffer = VclPtrInstance<VirtualDevice>();
3876 // Make sure that the buffer size matches the frame size.
3877 mpWindowImpl->mpFrameData->mpBuffer->SetOutputSizePixel(mpWindowImpl->mpFrameWindow->GetOutputSizePixel());
3879 else
3880 mpWindowImpl->mpFrameData->mpBuffer.reset();
3884 * The rationale here is that we moved destructors to
3885 * dispose and this altered a lot of code paths, that
3886 * are better left unchanged for now.
3888 void Window::CompatGetFocus()
3890 if (!mpWindowImpl || mpWindowImpl->mbInDispose)
3891 Window::GetFocus();
3892 else
3893 GetFocus();
3896 void Window::CompatLoseFocus()
3898 if (!mpWindowImpl || mpWindowImpl->mbInDispose)
3899 Window::LoseFocus();
3900 else
3901 LoseFocus();
3904 void Window::CompatStateChanged( StateChangedType nStateChange )
3906 if (!mpWindowImpl || mpWindowImpl->mbInDispose)
3907 Window::StateChanged(nStateChange);
3908 else
3909 StateChanged(nStateChange);
3912 void Window::CompatDataChanged( const DataChangedEvent& rDCEvt )
3914 if (!mpWindowImpl || mpWindowImpl->mbInDispose)
3915 Window::DataChanged(rDCEvt);
3916 else
3917 DataChanged(rDCEvt);
3920 bool Window::CompatPreNotify( NotifyEvent& rNEvt )
3922 if (!mpWindowImpl || mpWindowImpl->mbInDispose)
3923 return Window::PreNotify( rNEvt );
3924 else
3925 return PreNotify( rNEvt );
3928 bool Window::CompatNotify( NotifyEvent& rNEvt )
3930 if (!mpWindowImpl || mpWindowImpl->mbInDispose)
3931 return Window::EventNotify( rNEvt );
3932 else
3933 return EventNotify( rNEvt );
3936 void Window::set_id(const OUString& rID)
3938 mpWindowImpl->maID = rID;
3941 const OUString& Window::get_id() const
3943 static OUString empty;
3944 return mpWindowImpl ? mpWindowImpl->maID : empty;
3947 FactoryFunction Window::GetUITestFactory() const
3949 return WindowUIObject::create;
3952 WindowOutputDevice::WindowOutputDevice(vcl::Window& rOwnerWindow) :
3953 ::OutputDevice(OUTDEV_WINDOW),
3954 mxOwnerWindow(&rOwnerWindow)
3956 assert(mxOwnerWindow);
3959 WindowOutputDevice::~WindowOutputDevice()
3961 disposeOnce();
3964 void WindowOutputDevice::dispose()
3966 assert((!mxOwnerWindow || mxOwnerWindow->isDisposed()) && "This belongs to the associated window and must be disposed after it");
3967 ::OutputDevice::dispose();
3968 // need to do this after OutputDevice::dispose so that the call to WindowOutputDevice::ReleaseGraphics
3969 // can release the graphics properly
3970 mxOwnerWindow.clear();
3973 css::awt::DeviceInfo WindowOutputDevice::GetDeviceInfo() const
3975 css::awt::DeviceInfo aInfo = GetCommonDeviceInfo(mxOwnerWindow->GetSizePixel());
3976 mxOwnerWindow->GetBorder(aInfo.LeftInset, aInfo.TopInset, aInfo.RightInset, aInfo.BottomInset);
3977 return aInfo;
3981 } /* namespace vcl */
3983 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */