tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sfx2 / source / appl / workwin.cxx
blob0140c4b39c46cc2e103f4ed43e09a42bbad08fe6
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 <config_features.h>
21 #include <config_feature_desktop.h>
22 #include <comphelper/configuration.hxx>
23 #include <comphelper/lok.hxx>
24 #include <comphelper/processfactory.hxx>
25 #include <osl/diagnose.h>
26 #include <sal/log.hxx>
27 #include <sfx2/docfile.hxx>
28 #include <sfx2/objface.hxx>
29 #include <sfx2/objsh.hxx>
30 #include <sfx2/app.hxx>
31 #include <workwin.hxx>
32 #include <sfx2/viewfrm.hxx>
33 #include <sfx2/module.hxx>
34 #include <sfx2/dispatch.hxx>
35 #include <sfx2/dockwin.hxx>
36 #include <sfx2/viewsh.hxx>
37 #include <splitwin.hxx>
38 #include <sfx2/sfxsids.hrc>
39 #include <sfx2/toolbarids.hxx>
40 #include <vcl/taskpanelist.hxx>
41 #include <vcl/svapp.hxx>
42 #include <svl/eitem.hxx>
43 #include <tools/svborder.hxx>
44 #include <tools/debug.hxx>
45 #include <unotools/configmgr.hxx>
46 #include <unotools/moduleoptions.hxx>
47 #include <com/sun/star/ui/XUIElement.hpp>
48 #include <com/sun/star/frame/LayoutManagerEvents.hpp>
49 #include <com/sun/star/frame/ModuleManager.hpp>
50 #include <com/sun/star/frame/XLayoutManager.hpp>
51 #include <com/sun/star/frame/XLayoutManagerEventBroadcaster.hpp>
52 #include <com/sun/star/beans/XPropertySet.hpp>
53 #include <com/sun/star/lang/DisposedException.hpp>
54 #include <type_traits>
55 #include <unordered_map>
56 #include <sfx2/notebookbar/SfxNotebookBar.hxx>
58 using namespace ::com::sun::star;
59 using namespace ::com::sun::star::uno;
61 namespace {
63 struct ResIdToResName
65 ToolbarId eId;
66 OUString pName;
71 constexpr ResIdToResName pToolBarResToName[] =
73 { ToolbarId::FullScreenToolbox, u"fullscreenbar"_ustr },
74 { ToolbarId::EnvToolbox, u"standardbar"_ustr, },
75 { ToolbarId::SvxTbx_Form_Navigation, u"formsnavigationbar"_ustr },
76 { ToolbarId::SvxTbx_Form_Filter, u"formsfilterbar"_ustr },
77 { ToolbarId::SvxTbx_Text_Control_Attributes, u"formtextobjectbar"_ustr },
78 { ToolbarId::SvxTbx_Controls, u"formcontrols"_ustr },
79 { ToolbarId::SvxTbx_FormDesign, u"formdesign"_ustr },
80 { ToolbarId::Math_Toolbox, u"toolbar"_ustr }, //math
81 { ToolbarId::Text_Toolbox_Sc, u"textobjectbar"_ustr }, //calc
82 { ToolbarId::Draw_Objectbar, u"drawobjectbar"_ustr },
83 { ToolbarId::Graphic_Objectbar, u"graphicobjectbar"_ustr },
84 { ToolbarId::Objectbar_Format, u"formatobjectbar"_ustr },
85 { ToolbarId::Objectbar_Preview, u"previewbar"_ustr },
86 { ToolbarId::Objectbar_Tools, u"toolbar"_ustr }, //calc
87 { ToolbarId::Bezier_Toolbox_Sd, u"bezierobjectbar"_ustr }, //draw/impress
88 { ToolbarId::Gluepoints_Toolbox, u"gluepointsobjectbar"_ustr },
89 { ToolbarId::Draw_Graf_Toolbox, u"graphicobjectbar"_ustr },
90 { ToolbarId::Draw_Obj_Toolbox, u"drawingobjectbar"_ustr }, //impress
91 { ToolbarId::Draw_Text_Toolbox_Sd, u"textobjectbar"_ustr }, //impress
92 { ToolbarId::Draw_Toolbox_Sd, u"toolbar"_ustr }, //impress
93 { ToolbarId::Draw_Options_Toolbox, u"optionsbar"_ustr },
94 { ToolbarId::Draw_CommonTask_Toolbox, u"commontaskbar"_ustr },
95 { ToolbarId::Graphic_Obj_Toolbox, u"drawingobjectbar"_ustr }, //draw
96 { ToolbarId::Outline_Toolbox, u"outlinetoolbar"_ustr }, //impress
97 { ToolbarId::Slide_Toolbox, u"slideviewtoolbar"_ustr },
98 { ToolbarId::Slide_Obj_Toolbox, u"slideviewobjectbar"_ustr },
99 { ToolbarId::Bezier_Toolbox_Sw, u"bezierobjectbar"_ustr },
100 { ToolbarId::Draw_Toolbox_Sw, u"drawingobjectbar"_ustr },
101 { ToolbarId::Draw_Text_Toolbox_Sw, u"drawtextobjectbar"_ustr },
102 { ToolbarId::Frame_Toolbox, u"frameobjectbar"_ustr },
103 { ToolbarId::Grafik_Toolbox, u"graphicobjectbar"_ustr },
104 { ToolbarId::Num_Toolbox, u"numobjectbar"_ustr },
105 { ToolbarId::Ole_Toolbox, u"oleobjectbar"_ustr },
106 { ToolbarId::Table_Toolbox, u"tableobjectbar"_ustr },
107 { ToolbarId::Text_Toolbox_Sw, u"textobjectbar"_ustr },
108 { ToolbarId::PView_Toolbox, u"previewobjectbar"_ustr }, //writer
109 { ToolbarId::Webtools_Toolbox, u"toolbar"_ustr }, //web
110 { ToolbarId::Webtext_Toolbox, u"textobjectbar"_ustr },
111 { ToolbarId::Tools_Toolbox, u"toolbar"_ustr }, //writer
112 { ToolbarId::Webframe_Toolbox, u"frameobjectbar"_ustr }, //web
113 { ToolbarId::Webgraphic_Toolbox, u"graphicobjectbar"_ustr },
114 { ToolbarId::Webole_Toolbox, u"oleobjectbar"_ustr },
115 { ToolbarId::Basicide_Objectbar, u"macrobar"_ustr },
116 { ToolbarId::Svx_Fontwork_Bar, u"fontworkobjectbar"_ustr }, //global
117 { ToolbarId::Svx_Extrusion_Bar, u"extrusionobjectbar"_ustr },
118 { ToolbarId::FormLayer_Toolbox, u"formsobjectbar"_ustr },
119 { ToolbarId::Module_Toolbox, u"viewerbar"_ustr }, //writer (plugin)
120 { ToolbarId::Objectbar_App, u"viewerbar"_ustr }, //calc (plugin)
121 { ToolbarId::Draw_Viewer_Toolbox, u"viewerbar"_ustr }, //impress(plugin)
122 { ToolbarId::Draw_Media_Toolbox, u"mediaobjectbar"_ustr }, //draw/impress
123 { ToolbarId::Media_Objectbar, u"mediaobjectbar"_ustr }, //calc
124 { ToolbarId::Media_Toolbox, u"mediaobjectbar"_ustr }, //writer
125 { ToolbarId::None, u""_ustr }
128 // Sort the Children according their alignment
129 // The order corresponds to the enum SfxChildAlignment (->CHILDWIN.HXX).
131 constexpr OUString g_aLayoutManagerPropName = u"LayoutManager"_ustr;
133 // Help to make changes to the alignment compatible!
134 LayoutManagerListener::LayoutManagerListener(
135 SfxWorkWindow* pWrkWin ) :
136 m_bHasFrame( false ),
137 m_pWrkWin( pWrkWin )
141 LayoutManagerListener::~LayoutManagerListener()
145 void LayoutManagerListener::setFrame( const css::uno::Reference< css::frame::XFrame >& xFrame )
147 SolarMutexGuard aGuard;
148 if ( !m_pWrkWin || m_bHasFrame )
149 return;
151 m_xFrame = xFrame;
152 m_bHasFrame = true;
154 if ( !xFrame.is() )
155 return;
157 css::uno::Reference< css::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
158 css::uno::Reference< css::frame::XLayoutManagerEventBroadcaster > xLayoutManager;
159 if ( !xPropSet.is() )
160 return;
164 Any aValue = xPropSet->getPropertyValue( g_aLayoutManagerPropName );
165 aValue >>= xLayoutManager;
167 if ( xLayoutManager.is() )
168 xLayoutManager->addLayoutManagerEventListener(
169 css::uno::Reference< css::frame::XLayoutManagerListener >(this) );
171 xPropSet.set( xLayoutManager, UNO_QUERY );
172 if ( xPropSet.is() )
174 aValue = xPropSet->getPropertyValue( u"LockCount"_ustr );
175 aValue >>= m_pWrkWin->m_nLock;
178 catch ( css::lang::DisposedException& )
181 catch ( const css::uno::RuntimeException& )
183 throw;
185 catch ( css::uno::Exception& )
191 // XComponent
193 void SAL_CALL LayoutManagerListener::addEventListener(
194 const css::uno::Reference< css::lang::XEventListener >& )
196 // do nothing, only internal class
199 void SAL_CALL LayoutManagerListener::removeEventListener(
200 const css::uno::Reference< css::lang::XEventListener >& )
202 // do nothing, only internal class
205 void SAL_CALL LayoutManagerListener::dispose()
207 SolarMutexGuard aGuard;
209 // reset member
210 m_pWrkWin = nullptr;
212 css::uno::Reference< css::frame::XFrame > xFrame( m_xFrame.get(), css::uno::UNO_QUERY );
213 if ( !xFrame.is() )
214 return;
216 m_xFrame.clear();
217 m_bHasFrame = false;
219 css::uno::Reference< css::beans::XPropertySet > xPropSet( xFrame, css::uno::UNO_QUERY );
220 css::uno::Reference< css::frame::XLayoutManagerEventBroadcaster > xLayoutManager;
221 if ( !xPropSet.is() )
222 return;
226 css::uno::Any aValue = xPropSet->getPropertyValue( g_aLayoutManagerPropName );
227 aValue >>= xLayoutManager;
229 // remove as listener from layout manager
230 if ( xLayoutManager.is() )
231 xLayoutManager->removeLayoutManagerEventListener(
232 css::uno::Reference< css::frame::XLayoutManagerListener >(this) );
234 catch ( css::lang::DisposedException& )
237 catch ( const css::uno::RuntimeException& )
239 throw;
241 catch ( css::uno::Exception& )
247 // XEventListener
249 void SAL_CALL LayoutManagerListener::disposing(
250 const css::lang::EventObject& )
252 SolarMutexGuard aGuard;
253 m_pWrkWin = nullptr;
254 m_bHasFrame = false;
255 m_xFrame.clear();
259 // XLayoutManagerEventListener
261 void SAL_CALL LayoutManagerListener::layoutEvent(
262 const css::lang::EventObject&,
263 ::sal_Int16 eLayoutEvent,
264 const css::uno::Any& )
266 SolarMutexGuard aGuard;
267 if ( !m_pWrkWin )
268 return;
270 if ( eLayoutEvent == css::frame::LayoutManagerEvents::VISIBLE )
272 m_pWrkWin->MakeVisible_Impl( true );
273 m_pWrkWin->ShowChildren_Impl();
274 m_pWrkWin->ArrangeChildren_Impl();
276 else if ( eLayoutEvent == css::frame::LayoutManagerEvents::INVISIBLE )
278 m_pWrkWin->MakeVisible_Impl( false );
279 m_pWrkWin->HideChildren_Impl();
280 m_pWrkWin->ArrangeChildren_Impl();
282 else if ( eLayoutEvent == css::frame::LayoutManagerEvents::LOCK )
284 m_pWrkWin->Lock_Impl( true );
286 else if ( eLayoutEvent == css::frame::LayoutManagerEvents::UNLOCK )
288 m_pWrkWin->Lock_Impl( false );
292 namespace
294 struct ToolbarIdHash
296 size_t operator()(ToolbarId t) const
298 typedef std::underlying_type<ToolbarId>::type underlying_type;
299 return std::hash<underlying_type>()(static_cast<underlying_type>(t));
303 class FilledToolBarResIdToResourceURLMap
305 private:
306 typedef std::unordered_map<ToolbarId, OUString, ToolbarIdHash> ToolBarResIdToResourceURLMap;
307 ToolBarResIdToResourceURLMap m_aResIdToResourceURLMap;
308 public:
309 FilledToolBarResIdToResourceURLMap()
311 sal_Int32 nIndex( 0 );
312 while (pToolBarResToName[nIndex].eId != ToolbarId::None)
314 OUString aResourceURL( pToolBarResToName[nIndex].pName );
315 m_aResIdToResourceURLMap.emplace(pToolBarResToName[nIndex].eId, aResourceURL);
316 ++nIndex;
320 OUString findURL(ToolbarId eId) const
322 ToolBarResIdToResourceURLMap::const_iterator aIter = m_aResIdToResourceURLMap.find(eId);
323 if ( aIter != m_aResIdToResourceURLMap.end() )
324 return aIter->second;
325 return OUString();
330 static OUString GetResourceURLFromToolbarId(ToolbarId eId)
332 static FilledToolBarResIdToResourceURLMap theFilledToolBarResIdToResourceURLMap;
333 return theFilledToolBarResIdToResourceURLMap.findURL(eId);
336 static sal_uInt16 TbxMatch( sal_uInt16 nPos )
338 switch ( nPos )
340 case SFX_OBJECTBAR_APPLICATION :
341 return 0;
342 case SFX_OBJECTBAR_OPTIONS:
343 return 1;
344 case SFX_OBJECTBAR_MACRO:
345 return 2;
346 case SFX_OBJECTBAR_OBJECT:
347 return 3;
348 case SFX_OBJECTBAR_TOOLS:
349 return 4;
350 case SFX_OBJECTBAR_FULLSCREEN:
351 case SFX_OBJECTBAR_COMMONTASK:
352 case SFX_OBJECTBAR_RECORDING:
353 return nPos+1;
354 default:
355 return nPos;
359 static sal_uInt16 ChildAlignValue(SfxChildAlignment eAlign)
361 sal_uInt16 ret = 17;
363 switch (eAlign)
365 case SfxChildAlignment::HIGHESTTOP:
366 ret = 1;
367 break;
368 case SfxChildAlignment::LOWESTBOTTOM:
369 ret = 2;
370 break;
371 case SfxChildAlignment::FIRSTLEFT:
372 ret = 3;
373 break;
374 case SfxChildAlignment::LASTRIGHT:
375 ret = 4;
376 break;
377 case SfxChildAlignment::LEFT:
378 ret = 5;
379 break;
380 case SfxChildAlignment::RIGHT:
381 ret = 6;
382 break;
383 case SfxChildAlignment::FIRSTRIGHT:
384 ret = 7;
385 break;
386 case SfxChildAlignment::LASTLEFT:
387 ret = 8;
388 break;
389 case SfxChildAlignment::TOP:
390 ret = 9;
391 break;
392 case SfxChildAlignment::BOTTOM:
393 ret = 10;
394 break;
395 case SfxChildAlignment::TOOLBOXTOP:
396 ret = 11;
397 break;
398 case SfxChildAlignment::TOOLBOXBOTTOM:
399 ret = 12;
400 break;
401 case SfxChildAlignment::LOWESTTOP:
402 ret = 13;
403 break;
404 case SfxChildAlignment::HIGHESTBOTTOM:
405 ret = 14;
406 break;
407 case SfxChildAlignment::TOOLBOXLEFT:
408 ret = 15;
409 break;
410 case SfxChildAlignment::TOOLBOXRIGHT:
411 ret = 16;
412 break;
413 case SfxChildAlignment::NOALIGNMENT:
414 break; // -Wall not handled...
417 return ret;
420 void SfxWorkWindow::Sort_Impl()
422 aSortedList.clear();
423 for (size_t i = 0; i < aChildren.size(); ++i)
425 SfxChild_Impl *pCli = aChildren[i].get();
426 if (pCli)
428 decltype(aSortedList)::size_type k;
429 for (k=0; k<aSortedList.size(); k++)
430 if (ChildAlignValue( aChildren[aSortedList[k]]->eAlign ) >
431 ChildAlignValue(pCli->eAlign))
432 break;
433 aSortedList.insert( aSortedList.begin() + k, i );
437 bSorted = true;
440 constexpr OUString g_aStatusBarResName( u"private:resource/statusbar/statusbar"_ustr );
441 constexpr OUString g_aTbxTypeName( u"private:resource/toolbar/"_ustr );
442 constexpr OUString g_aProgressBarResName( u"private:resource/progressbar/progressbar"_ustr );
444 // constructor for workwin of a Frame
446 SfxWorkWindow::SfxWorkWindow( vcl::Window *pWin, SfxFrame *pFrm, SfxFrame* pMaster ) :
447 pBindings(&pFrm->GetCurrentViewFrame()->GetBindings()),
448 pWorkWin (pWin),
449 pActiveChild( nullptr ),
450 nUpdateMode(SfxVisibilityFlags::Standard),
451 nChildren( 0 ),
452 nOrigMode( SfxVisibilityFlags::Invisible ),
453 bSorted( true ),
454 bDockingAllowed(true),
455 bInternalDockingAllowed(true),
456 bAllChildrenVisible(true),
457 #if !defined(ANDROID) || HAVE_FEATURE_ANDROID_LOK
458 bIsFullScreen( false ),
459 #else // Fennec-based Android Viewer
460 bIsFullScreen( true ),
461 #endif
462 #if HAVE_FEATURE_DESKTOP
463 bShowStatusBar( true ),
464 #else
465 bShowStatusBar( sal_False ),
466 #endif
467 m_nLock( 0 ),
468 pMasterFrame( pMaster ),
469 pFrame( pFrm )
471 DBG_ASSERT (pBindings, "No Bindings!");
473 pBindings->SetWorkWindow_Impl( std::unique_ptr<SfxWorkWindow>(this) );
475 // For the ObjectBars an integral place in the Childlist is reserved,
476 // so that they always come in a defined order.
477 for (int i=0; i<SFX_OBJECTBAR_MAX; ++i)
478 aChildren.push_back( nullptr );
480 // create and initialize layout manager listener
481 Reference< css::frame::XFrame > xFrame = GetFrameInterface();
482 m_xLayoutManagerListener = new LayoutManagerListener( this );
483 m_xLayoutManagerListener->setFrame( xFrame );
485 SfxShell* pConfigShell = pFrm->GetCurrentViewFrame();
486 if ( pConfigShell && pConfigShell->GetObjectShell() )
488 bShowStatusBar = ( !pConfigShell->GetObjectShell()->IsInPlaceActive() );
489 bDockingAllowed = true;
490 bInternalDockingAllowed = true;
493 // The required split windows (one for each side) can be created
494 for ( sal_uInt16 n=0; n<SFX_SPLITWINDOWS_MAX; n++ )
496 // The SplitWindows excludes direct ChildWindows of the WorkWindows
497 // and receives the docked window.
499 SfxChildAlignment eAlign =
500 ( n == SFX_SPLITWINDOWS_LEFT ? SfxChildAlignment::LEFT :
501 n == SFX_SPLITWINDOWS_RIGHT ? SfxChildAlignment::RIGHT :
502 n == SFX_SPLITWINDOWS_TOP ? SfxChildAlignment::TOP :
503 SfxChildAlignment::BOTTOM );
504 pSplit[n] = VclPtr<SfxSplitWindow>::Create(pWorkWin, eAlign, this, true );
507 nOrigMode = SfxVisibilityFlags::Standard;
508 nUpdateMode = SfxVisibilityFlags::Standard;
512 // Destructor
514 SfxWorkWindow::~SfxWorkWindow()
517 // Delete SplitWindows
518 for (VclPtr<SfxSplitWindow> & p : pSplit)
520 if (p->GetWindowCount())
521 ReleaseChild_Impl(*p);
522 p.disposeAndClear();
525 // Delete help structure for Child-Windows
526 DBG_ASSERT( aChildren.empty(), "dangling children" );
528 if ( m_xLayoutManagerListener.is() )
529 m_xLayoutManagerListener->dispose();
532 void SfxWorkWindow::Lock_Impl( bool bLock )
534 if ( bLock )
535 m_nLock++;
536 else
537 --m_nLock;
538 if ( m_nLock<0 )
540 OSL_FAIL("Lock count underflow!");
541 assert(m_nLock >= 0);
542 m_nLock = 0;
545 if ( !m_nLock )
546 ArrangeChildren_Impl();
550 // Helper method to release the child lists. Should the destructor not be
551 // called after this, instead work continues, then space for the object bars
552 // and split windows has to be reserved in the same way as in the constructor
553 // of SfxWorkWindow.
555 void SfxWorkWindow::DeleteControllers_Impl()
558 // Lock SplitWindows (which means suppressing the Resize-Reaction of the
559 // DockingWindows)
560 for (size_t n=0; n<SFX_SPLITWINDOWS_MAX; n++ )
562 VclPtr<SfxSplitWindow> const &p = pSplit[n];
563 if (p->GetWindowCount())
564 p->Lock();
567 // Delete Child-Windows
568 while(!aChildWins.empty())
570 std::unique_ptr<SfxChildWin_Impl> pCW = std::move(*aChildWins.begin());
571 aChildWins.erase(aChildWins.begin());
572 SfxChildWindow *pChild = pCW->pWin;
573 if (pChild)
575 if (comphelper::LibreOfficeKit::isActive())
577 vcl::Window* pWindow = pChild->GetWindow();
578 if (pWindow)
580 pWindow->ReleaseLOKNotifier();
583 pChild->Hide();
585 // If the child window is a direct child window and not in a
586 // SplitWindow, cancel it at the workwindow.
587 // After TH a cancellation on the SplitWindow is not necessary
588 // since this window is also destroyed (see below).
589 if (pCW->pCli)
591 if (pChild->GetController())
592 ReleaseChild_Impl(*pChild->GetController());
593 else
594 ReleaseChild_Impl(*pChild->GetWindow());
597 pCW->pWin = nullptr;
598 pWorkWin->GetSystemWindow()->GetTaskPaneList()->RemoveWindow( pChild->GetWindow() );
599 pChild->Destroy();
602 // ATTENTION: The array itself is cleared after this loop!!
603 // Therefore we have to set every array entry to zero as it could be
604 // accessed by calling pChild->Destroy().
605 // Window::NotifyAllChildren() calls SfxWorkWindow::DataChanged_Impl for
606 // 8-bit displays (WM_QUERYPALETTECHANGED message due to focus change)!!
609 Reference< css::frame::XFrame > xFrame = GetFrameInterface();
610 Reference< css::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
611 Reference< css::frame::XLayoutManager > xLayoutManager;
612 if ( xPropSet.is() )
616 Any aValue = xPropSet->getPropertyValue( g_aLayoutManagerPropName );
617 aValue >>= xLayoutManager;
619 catch ( Exception& )
624 if ( xLayoutManager.is() )
626 xLayoutManager->reset();
628 // Delete StatusBar
629 ResetStatusBar_Impl();
631 // Delete ObjectBars (this is done last, so that aChildren does not
632 // receive dead Pointers)
633 for (SfxObjectBar_Impl & i : aObjBarList)
635 // Not every position must be occupied
636 ToolbarId eId = i.eId;
637 if (eId != ToolbarId::None)
638 i.eId = ToolbarId::None;
642 // ObjectBars are all released at once, since they occupy a
643 // fixed contiguous area in the array pChild
644 aChildren.clear();
645 bSorted = false;
647 nChildren = 0;
651 // for placing the child window.
653 void SfxWorkWindow::ArrangeChildren_Impl( bool bForce )
655 if ( pFrame->IsClosing_Impl() || ( m_nLock && !bForce ))
656 return;
658 SfxInPlaceClient *pClient = nullptr;
659 SfxViewFrame *pF = pFrame->GetCurrentViewFrame();
660 if ( pF && pF->GetViewShell() )
661 pClient = pF->GetViewShell()->GetIPClient();
663 if ( pClient )
664 return;
666 aClientArea = GetTopRect_Impl();
667 if ( aClientArea.IsEmpty() )
668 return;
670 SvBorder aBorder;
671 if ( nChildren && IsVisible_Impl() )
672 aBorder = Arrange_Impl();
673 // If the current application document contains an IPClient, then the
674 // object through SetTopToolFramePixel has to be assigned the available
675 // space. The object will then point to its UITools and sets the app border
676 // (-> SfxInPlaceEnv_Impl:: ArrangeChildren_Impl ()). Otherwise the
677 // app border is set here directly to possibly overwrite the Border that
678 // was set by an object from another document. The object does not set
679 // the SetAppBorder when it removes its UI tools so that no-dithering
680 // ObjectBar arises.
681 // (->SfxInPlaceEnv_Impl::ArrangeChildren_Impl())
683 pMasterFrame->SetToolSpaceBorderPixel_Impl( aBorder );
685 ArrangeAutoHideWindows( nullptr );
688 void SfxWorkWindow::FlushPendingChildSizes()
690 // tdf#116865, if any windows are being resized, i.e. their
691 // resize timer is active, then calling GetSizePixel on
692 // them forces the timer to fire and sets the final
693 // size to which they are getting resized towards.
694 for (size_t i = 0; i < aChildren.size(); ++i)
696 SfxChild_Impl *pCli = aChildren[i].get();
697 if (!pCli || !pCli->pWin)
698 continue;
699 (void)pCli->pWin->GetSizePixel();
703 SvBorder SfxWorkWindow::Arrange_Impl()
705 /* [Description]
707 This method organizes all visible child windows so that the docked window
708 sorted in order from the outside to the inside are placed after one
709 another. If a visible window does not fit anymore into the free
710 ClientArea, it is set to "not visible".
713 //tdf#116865 trigger pending sizing timers now so we arrange
714 //with the final size of the client area.
716 //Otherwise calling GetSizePixel in the following loop will trigger the
717 //timers, causing reentry into Arrange_Impl again where the inner
718 //Arrange_Impl arranges with the final size, and then returns to this outer
719 //Arrange_Impl which would rearrange with the old client area size
720 FlushPendingChildSizes();
721 aClientArea = GetTopRect_Impl();
722 aUpperClientArea = aClientArea;
724 SvBorder aBorder;
725 if ( !nChildren )
726 return aBorder;
728 if (!bSorted)
729 Sort_Impl();
731 Point aPos;
732 Size aSize;
733 tools::Rectangle aTmp( aClientArea );
735 for (sal_uInt16 n : aSortedList)
737 SfxChild_Impl* pCli = aChildren[n].get();
738 if ( !pCli->pWin )
739 continue;
741 // First, we assume that there is room for the window.
742 pCli->nVisible |= SfxChildVisibility::FITS_IN;
744 // Skip invisible windows
745 if (pCli->nVisible != SfxChildVisibility::VISIBLE)
746 continue;
748 if ( pCli->bResize )
749 aSize = pCli->aSize;
750 else
751 aSize = pCli->pWin->GetSizePixel();
753 SvBorder aTemp = aBorder;
754 bool bAllowHiding = true;
755 switch ( pCli->eAlign )
757 case SfxChildAlignment::HIGHESTTOP:
758 case SfxChildAlignment::TOP:
759 case SfxChildAlignment::TOOLBOXTOP:
760 case SfxChildAlignment::LOWESTTOP:
761 aSize.setWidth( aTmp.GetWidth() );
762 if ( pCli->pWin->GetType() == WindowType::SPLITWINDOW )
763 aSize = static_cast<SplitWindow *>(pCli->pWin.get())->CalcLayoutSizePixel( aSize );
764 bAllowHiding = false;
765 aBorder.Top() += aSize.Height();
766 aPos = aTmp.TopLeft();
767 aTmp.AdjustTop(aSize.Height() );
768 if ( pCli->eAlign == SfxChildAlignment::HIGHESTTOP )
769 aUpperClientArea.AdjustTop(aSize.Height() );
770 break;
772 case SfxChildAlignment::LOWESTBOTTOM:
773 case SfxChildAlignment::BOTTOM:
774 case SfxChildAlignment::TOOLBOXBOTTOM:
775 case SfxChildAlignment::HIGHESTBOTTOM:
776 aSize.setWidth( aTmp.GetWidth() );
777 if ( pCli->pWin->GetType() == WindowType::SPLITWINDOW )
778 aSize = static_cast<SplitWindow *>(pCli->pWin.get())->CalcLayoutSizePixel( aSize );
779 aBorder.Bottom() += aSize.Height();
780 aPos = aTmp.BottomLeft();
781 aPos.AdjustY( -(aSize.Height()-1) );
782 aTmp.AdjustBottom( -(aSize.Height()) );
783 if ( pCli->eAlign == SfxChildAlignment::LOWESTBOTTOM )
784 aUpperClientArea.AdjustBottom( -(aSize.Height()) );
785 break;
787 case SfxChildAlignment::FIRSTLEFT:
788 case SfxChildAlignment::LEFT:
789 case SfxChildAlignment::LASTLEFT:
790 case SfxChildAlignment::TOOLBOXLEFT:
791 aSize.setHeight( aTmp.GetHeight() );
792 if ( pCli->pWin->GetType() == WindowType::SPLITWINDOW )
793 aSize = static_cast<SplitWindow *>(pCli->pWin.get())->CalcLayoutSizePixel( aSize );
794 bAllowHiding = false;
795 aBorder.Left() += aSize.Width();
796 aPos = aTmp.TopLeft();
797 aTmp.AdjustLeft(aSize.Width() );
798 if ( pCli->eAlign != SfxChildAlignment::TOOLBOXLEFT )
799 aUpperClientArea.AdjustLeft(aSize.Width() );
800 break;
802 case SfxChildAlignment::FIRSTRIGHT:
803 case SfxChildAlignment::RIGHT:
804 case SfxChildAlignment::LASTRIGHT:
805 case SfxChildAlignment::TOOLBOXRIGHT:
806 aSize.setHeight( aTmp.GetHeight() );
807 if ( pCli->pWin->GetType() == WindowType::SPLITWINDOW )
808 aSize = static_cast<SplitWindow *>(pCli->pWin.get())->CalcLayoutSizePixel( aSize );
809 aBorder.Right() += aSize.Width();
810 aPos = aTmp.TopRight();
811 aPos.AdjustX( -(aSize.Width()-1) );
812 aTmp.AdjustRight( -(aSize.Width()) );
813 if ( pCli->eAlign != SfxChildAlignment::TOOLBOXRIGHT )
814 aUpperClientArea.AdjustRight( -(aSize.Width()) );
815 break;
817 default:
818 pCli->aSize = pCli->pWin->GetSizePixel();
819 pCli->bResize = false;
820 continue;
823 pCli->pWin->SetPosSizePixel( aPos, aSize );
824 pCli->bResize = false;
825 pCli->aSize = aSize;
826 if( bAllowHiding && !RequestTopToolSpacePixel_Impl( aBorder ) )
828 pCli->nVisible ^= SfxChildVisibility::FITS_IN;
829 aBorder = aTemp;
833 if ( aClientArea.GetWidth() >= aBorder.Left() + aBorder.Right() )
835 aClientArea.AdjustLeft(aBorder.Left() );
836 aClientArea.AdjustRight( -(aBorder.Right()) );
838 else
840 aBorder.Left() = aClientArea.Left();
841 aBorder.Right() = aClientArea.Right();
842 aClientArea.SetRight( aTmp.Left() );
843 aClientArea.SetLeft( aTmp.Left() );
846 if ( aClientArea.GetHeight() >= aBorder.Top() + aBorder.Bottom() )
848 aClientArea.AdjustTop(aBorder.Top() );
849 aClientArea.AdjustBottom( -(aBorder.Bottom()) );
851 else
853 aBorder.Top() = aClientArea.Top();
854 aBorder.Bottom() = aClientArea.Bottom();
855 aClientArea.SetTop(aTmp.Top());
856 aClientArea.SetBottom(aTmp.Top());
859 return IsDockingAllowed() ? aBorder : SvBorder();
862 bool SfxWorkWindow::PrepareClose_Impl()
864 for (const std::unique_ptr<SfxChildWin_Impl> &pCW : aChildWins)
866 SfxChildWindow *pChild = pCW->pWin;
867 if ( pChild && !pChild->QueryClose() )
868 return false;
871 return true;
874 SfxChild_Impl* SfxWorkWindow::RegisterChild_Impl( vcl::Window& rWindow,
875 SfxChildAlignment eAlign )
877 DBG_ASSERT( aChildren.size() < 255, "too many children" );
878 DBG_ASSERT( SfxChildAlignValid(eAlign), "invalid align" );
879 DBG_ASSERT( !FindChild_Impl(&rWindow), "child registered more than once" );
882 if ( rWindow.GetParent() != pWorkWin )
883 rWindow.SetParent( pWorkWin );
885 auto pChild = std::make_unique<SfxChild_Impl>(rWindow, rWindow.GetSizePixel(),
886 eAlign, rWindow.IsVisible());
888 aChildren.push_back(std::move(pChild));
889 bSorted = false;
890 nChildren++;
891 return aChildren.back().get();
894 SfxChild_Impl* SfxWorkWindow::RegisterChild_Impl(std::shared_ptr<SfxDialogController>& rController,
895 SfxChildAlignment eAlign )
897 DBG_ASSERT( aChildren.size() < 255, "too many children" );
898 DBG_ASSERT( SfxChildAlignValid(eAlign), "invalid align" );
900 auto pChild = std::make_unique<SfxChild_Impl>(rController, eAlign);
902 aChildren.push_back(std::move(pChild));
903 bSorted = false;
904 nChildren++;
905 return aChildren.back().get();
908 void SfxWorkWindow::ReleaseChild_Impl( vcl::Window& rWindow )
911 SfxChild_Impl *pChild = nullptr;
912 decltype(aChildren)::size_type nPos;
913 for ( nPos = 0; nPos < aChildren.size(); ++nPos )
915 pChild = aChildren[nPos].get();
916 if ( pChild && pChild->pWin == &rWindow )
918 bSorted = false;
919 nChildren--;
920 aChildren.erase(aChildren.begin() + nPos);
921 return;
924 OSL_FAIL( "releasing unregistered child" );
927 void SfxWorkWindow::ReleaseChild_Impl(const SfxDialogController& rController)
930 SfxChild_Impl *pChild = nullptr;
931 decltype(aChildren)::size_type nPos;
932 for ( nPos = 0; nPos < aChildren.size(); ++nPos )
934 pChild = aChildren[nPos].get();
935 if (pChild && pChild->xController.get() == &rController)
937 bSorted = false;
938 nChildren--;
939 aChildren.erase(aChildren.begin() + nPos);
940 return;
943 OSL_FAIL( "releasing unregistered child" );
946 SfxChild_Impl* SfxWorkWindow::FindChild_Impl( const vcl::Window* rWindow ) const
949 sal_uInt16 nCount = aChildren.size();
950 for ( sal_uInt16 nPos = 0; nPos < nCount; ++nPos )
952 SfxChild_Impl *pChild = aChildren[nPos].get();
953 if ( pChild && pChild->pWin == rWindow )
954 return pChild;
957 return nullptr;
960 void SfxWorkWindow::ShowChildren_Impl()
962 bool bInvisible = ( !IsVisible_Impl() || ( !pWorkWin->IsReallyVisible() && !pWorkWin->IsReallyShown() ));
964 for (std::unique_ptr<SfxChild_Impl>& pCli : aChildren)
966 if (!pCli)
967 continue;
968 SfxChildWin_Impl* pCW = nullptr;
969 if (pCli->pWin || pCli->xController)
971 // We have to find the SfxChildWin_Impl to retrieve the
972 // SFX_CHILDWIN flags that can influence visibility.
973 for (const std::unique_ptr<SfxChildWin_Impl>& pCWin : aChildWins)
975 SfxChild_Impl* pChild = pCWin->pCli;
976 if ( pChild == pCli.get() )
978 pCW = pCWin.get();
979 break;
983 bool bVisible( !bInvisible );
984 if ( pCW )
986 // Check flag SFX_CHILDWIN_NEVERHIDE that forces us to show
987 // the child window even in situations where no child window is
988 // visible.
989 SfxChildWindowFlags nFlags = pCW->aInfo.nFlags;
990 bVisible = !bInvisible || ( nFlags & SfxChildWindowFlags::NEVERHIDE );
993 if ( SfxChildVisibility::VISIBLE == (pCli->nVisible & SfxChildVisibility::VISIBLE) && bVisible )
995 if (pCli->xController)
997 if (!pCli->xController->getDialog()->get_visible())
999 auto xController = pCli->xController;
1000 weld::DialogController::runAsync(xController,
1001 [=](sal_Int32 nResult){
1002 if (nResult == nCloseResponseToJustHide)
1003 return;
1004 xController->Close();
1008 else
1010 ShowFlags nFlags = pCli->bSetFocus ? ShowFlags::NONE : ShowFlags::NoFocusChange | ShowFlags::NoActivate;
1011 pCli->pWin->Show(true, nFlags);
1013 pCli->bSetFocus = false;
1015 else
1017 if (pCli->xController)
1019 if (pCli->xController->getDialog()->get_visible())
1020 pCli->xController->response(RET_CLOSE);
1022 else
1023 pCli->pWin->Hide();
1030 void SfxWorkWindow::HideChildren_Impl()
1032 for ( sal_uInt16 nPos = aChildren.size(); nPos > 0; --nPos )
1034 SfxChild_Impl *pChild = aChildren[nPos-1].get();
1035 if (!pChild)
1036 continue;
1037 if (pChild->xController)
1038 pChild->xController->response(RET_CLOSE);
1039 else if (pChild->pWin)
1040 pChild->pWin->Hide();
1044 void SfxWorkWindow::ResetObjectBars_Impl()
1046 for ( auto & n: aObjBarList )
1047 n.bDestroy = true;
1049 for ( auto & n: aChildWins )
1050 n->nId = 0;
1053 void SfxWorkWindow::SetObjectBar_Impl(sal_uInt16 nPos, SfxVisibilityFlags nFlags, ToolbarId eId)
1055 DBG_ASSERT( nPos < SFX_OBJECTBAR_MAX, "object bar position overflow" );
1057 SfxObjectBar_Impl aObjBar;
1058 aObjBar.eId = eId;
1059 aObjBar.nMode = nFlags;
1061 for (SfxObjectBar_Impl & rBar : aObjBarList)
1063 if ( rBar.eId == aObjBar.eId )
1065 rBar = aObjBar;
1066 return;
1070 aObjBarList.push_back( aObjBar );
1073 bool SfxWorkWindow::IsVisible_Impl( SfxVisibilityFlags nMode ) const
1075 switch( nUpdateMode )
1077 case SfxVisibilityFlags::Standard:
1078 return true;
1079 case SfxVisibilityFlags::Invisible:
1080 return false;
1081 case SfxVisibilityFlags::Client:
1082 case SfxVisibilityFlags::Server:
1083 return bool(nMode & nUpdateMode);
1084 default:
1085 return (nMode & nOrigMode ) ||
1086 nOrigMode == SfxVisibilityFlags::Standard;
1090 void SfxWorkWindow::UpdateObjectBars_Impl()
1092 if ( pFrame->IsClosing_Impl() )
1093 return;
1095 UpdateObjectBars_Impl2();
1098 ArrangeChildren_Impl( false );
1100 ShowChildren_Impl();
1103 ShowChildren_Impl();
1106 Reference< css::task::XStatusIndicator > SfxWorkWindow::GetStatusIndicator()
1108 Reference< css::beans::XPropertySet > xPropSet( GetFrameInterface(), UNO_QUERY );
1109 Reference< css::frame::XLayoutManager > xLayoutManager;
1110 Reference< css::task::XStatusIndicator > xStatusIndicator;
1112 if ( xPropSet.is() )
1114 Any aValue = xPropSet->getPropertyValue( g_aLayoutManagerPropName );
1115 aValue >>= xLayoutManager;
1116 if ( xLayoutManager.is() )
1118 xLayoutManager->createElement( g_aProgressBarResName );
1119 xLayoutManager->showElement( g_aProgressBarResName );
1121 Reference< css::ui::XUIElement > xProgressBar =
1122 xLayoutManager->getElement( g_aProgressBarResName );
1123 if ( xProgressBar.is() )
1125 xStatusIndicator.set( xProgressBar->getRealInterface(), UNO_QUERY );
1130 return xStatusIndicator;
1134 bool SfxWorkWindow::IsPluginMode( SfxObjectShell const * pObjShell )
1136 if ( pObjShell && pObjShell->GetMedium() )
1138 const SfxBoolItem* pViewOnlyItem = pObjShell->GetMedium()->GetItemSet().GetItem(SID_VIEWONLY, false);
1139 if ( pViewOnlyItem && pViewOnlyItem->GetValue() )
1140 return true;
1143 return false;
1147 css::uno::Reference< css::frame::XFrame > SfxWorkWindow::GetFrameInterface()
1149 css::uno::Reference< css::frame::XFrame > xFrame;
1151 SfxDispatcher* pDispatcher( GetBindings().GetDispatcher() );
1152 if ( pDispatcher )
1154 SfxViewFrame* pViewFrame = pDispatcher->GetFrame();
1155 if ( pViewFrame )
1156 xFrame = pViewFrame->GetFrame().GetFrameInterface();
1159 return xFrame;
1163 void SfxWorkWindow::UpdateObjectBars_Impl2()
1165 if (comphelper::IsFuzzing())
1166 return;
1168 // Lock SplitWindows (which means suppressing the Resize-Reaction of the
1169 // DockingWindows)
1170 for ( sal_uInt16 n=0; n<SFX_SPLITWINDOWS_MAX; n++ )
1172 VclPtr<SfxSplitWindow> const & p = pSplit[n];
1173 if (p->GetWindowCount())
1174 p->Lock();
1177 Reference< css::beans::XPropertySet > xPropSet( GetFrameInterface(), UNO_QUERY );
1178 Reference< css::frame::XLayoutManager > xLayoutManager;
1180 if ( xPropSet.is() )
1182 Any aValue = xPropSet->getPropertyValue( g_aLayoutManagerPropName );
1183 aValue >>= xLayoutManager;
1186 if ( !xLayoutManager.is() )
1187 return;
1189 bool bPluginMode( false );
1190 SfxDispatcher* pDispatcher( GetBindings().GetDispatcher() );
1192 if ( pDispatcher )
1194 SfxViewFrame* pViewFrame = pDispatcher->GetFrame();
1195 if ( pViewFrame )
1196 bPluginMode = IsPluginMode( pViewFrame->GetObjectShell() );
1199 // Iterate over all Toolboxes
1200 xLayoutManager->lock();
1201 const bool bForceDestroyToolbars =
1202 comphelper::LibreOfficeKit::isActive() ? false : sfx2::SfxNotebookBar::IsActive(true);
1203 for ( auto const & n: aObjBarList )
1205 ToolbarId eId = n.eId;
1206 bool bDestroy = n.bDestroy;
1208 // Determine the valid mode for the ToolBox
1209 SfxVisibilityFlags nTbxMode = n.nMode;
1210 bool bFullScreenTbx( nTbxMode & SfxVisibilityFlags::FullScreen );
1211 nTbxMode &= ~SfxVisibilityFlags::FullScreen;
1212 nTbxMode &= ~SfxVisibilityFlags::Viewer;
1214 // Is a ToolBox required in this context ?
1215 bool bModesMatching = (nUpdateMode != SfxVisibilityFlags::Invisible) && ((nTbxMode & nUpdateMode) == nUpdateMode);
1216 if ( bDestroy || bForceDestroyToolbars)
1218 OUString aTbxId = g_aTbxTypeName + GetResourceURLFromToolbarId(eId);
1219 xLayoutManager->destroyElement( aTbxId );
1221 else if ( eId != ToolbarId::None && ( ( bModesMatching && !bIsFullScreen ) ||
1222 ( bIsFullScreen && bFullScreenTbx ) ) )
1224 OUString aTbxId = g_aTbxTypeName + GetResourceURLFromToolbarId(eId);
1225 if ( !IsDockingAllowed() && !xLayoutManager->isElementFloating( aTbxId ))
1226 xLayoutManager->destroyElement( aTbxId );
1227 else
1229 xLayoutManager->requestElement( aTbxId );
1230 if ( bPluginMode )
1231 xLayoutManager->lockWindow( aTbxId );
1234 else if ( eId != ToolbarId::None )
1236 // Delete the Toolbox at this Position if possible
1237 OUString aTbxId = g_aTbxTypeName + GetResourceURLFromToolbarId(eId);
1238 xLayoutManager->destroyElement( aTbxId );
1242 UpdateStatusBar_Impl();
1244 // unlocking automatically forces Layout
1245 xLayoutManager->unlock();
1247 UpdateChildWindows_Impl();
1249 // Unlock the SplitWindows again
1250 for ( sal_uInt16 n=0; n<SFX_SPLITWINDOWS_MAX; n++ )
1252 VclPtr<SfxSplitWindow> const & p = pSplit[n];
1253 if (p->GetWindowCount())
1254 p->Lock(false);
1258 void SfxWorkWindow::UpdateChildWindows_Impl()
1260 // tdf#100870, tdf#101320: don't use range-based for loop when
1261 // container is modified
1262 for ( size_t n=0; n<aChildWins.size(); n++ )
1264 // any current or in the context available Childwindows
1265 SfxChildWin_Impl *pCW = aChildWins[n].get();
1266 SfxChildWindow *pChildWin = pCW->pWin;
1267 bool bCreate = false;
1268 if ( pCW->nId && (pCW->aInfo.nFlags & SfxChildWindowFlags::ALWAYSAVAILABLE || IsVisible_Impl( pCW->nVisibility ) ) )
1270 // In the context is an appropriate ChildWindow allowed;
1271 // it is also turned on?
1272 if ( pChildWin == nullptr && pCW->bCreate )
1274 // Internal docking is only used for embedding into another
1275 // container. We force the floating state of all floatable
1276 // child windows.
1277 if ( !bInternalDockingAllowed )
1279 // Special case for all non-floatable child windows. We have
1280 // to prevent the creation here!
1281 bCreate = !( pCW->aInfo.nFlags & SfxChildWindowFlags::FORCEDOCK );
1283 else if ( !IsDockingAllowed() || bIsFullScreen ) // || !bInternalDocking )
1285 // In Presentation mode or FullScreen only FloatingWindows
1286 SfxChildAlignment eAlign;
1287 if ( pCW->aInfo.GetExtraData_Impl( &eAlign ) )
1288 bCreate = ( eAlign == SfxChildAlignment::NOALIGNMENT );
1290 else
1291 bCreate = true;
1293 if (pCW->aInfo.nFlags & SfxChildWindowFlags::NEVERCLONE)
1294 pCW->bCreate = bCreate = false; // Don't create and remember that we haven't created.
1296 // Currently, no window here, but it is enabled; windows
1297 // Create window and if possible theContext
1298 if ( bCreate )
1299 CreateChildWin_Impl( pCW, false );
1301 if ( !bAllChildrenVisible && pCW->pCli )
1302 pCW->pCli->nVisible &= ~SfxChildVisibility::ACTIVE;
1304 else if ( pChildWin )
1306 // Window already exists, it should also be visible?
1307 if ( ( !bIsFullScreen || pChildWin->GetAlignment() == SfxChildAlignment::NOALIGNMENT ) && bAllChildrenVisible )
1309 // Update Mode is compatible; definitely enable it
1310 bCreate = true;
1311 if ( pCW->pCli )
1313 // The window is a direct Child
1314 if ((IsDockingAllowed() && bInternalDockingAllowed)
1315 || pCW->pCli->eAlign == SfxChildAlignment::NOALIGNMENT)
1316 pCW->pCli->nVisible |= SfxChildVisibility::NOT_HIDDEN;
1318 else
1320 if ( pCW->bCreate && IsDockingAllowed() && bInternalDockingAllowed )
1321 // The window ia within a SplitWindow
1322 static_cast<SfxDockingWindow*>(pChildWin->GetWindow())->Reappear_Impl();
1328 if ( pChildWin && !bCreate )
1330 if ( !pChildWin->QueryClose() || pChildWin->IsHideNotDelete() || Application::IsUICaptured() )
1332 if ( pCW->pCli )
1334 if ( pCW->pCli->nVisible & SfxChildVisibility::NOT_HIDDEN )
1335 pCW->pCli->nVisible ^= SfxChildVisibility::NOT_HIDDEN;
1337 else
1338 static_cast<SfxDockingWindow*>(pChildWin->GetWindow())->Disappear_Impl();
1340 else
1341 RemoveChildWin_Impl( pCW );
1346 void SfxWorkWindow::CreateChildWin_Impl( SfxChildWin_Impl *pCW, bool bSetFocus )
1348 pCW->aInfo.bVisible = true;
1350 SfxChildWindow *pChildWin = SfxChildWindow::CreateChildWindow( pCW->nId, pWorkWin, &GetBindings(), pCW->aInfo).release();
1351 if (!pChildWin)
1352 return;
1354 if ( bSetFocus )
1355 bSetFocus = pChildWin->WantsFocus();
1356 pChildWin->SetWorkWindow_Impl( this );
1358 // At least the extra string is changed during the evaluation,
1359 // also get it anewed
1360 SfxChildWinInfo aInfo = pChildWin->GetInfo();
1361 pCW->aInfo.aExtraString = aInfo.aExtraString;
1362 pCW->aInfo.bVisible = aInfo.bVisible;
1363 pCW->aInfo.nFlags |= aInfo.nFlags;
1365 // The creation was successful
1366 GetBindings().Invalidate(pCW->nId);
1368 sal_uInt16 nPos = pChildWin->GetPosition();
1369 if (nPos != CHILDWIN_NOPOS)
1371 DBG_ASSERT(nPos < SFX_OBJECTBAR_MAX, "Illegal objectbar position!");
1372 if ( aChildren[TbxMatch(nPos)] )// &&
1374 // ChildWindow replaces ObjectBar
1375 aChildren[TbxMatch(nPos)]->nVisible ^= SfxChildVisibility::NOT_HIDDEN;
1379 // make childwin keyboard accessible
1380 pWorkWin->GetSystemWindow()->GetTaskPaneList()->AddWindow( pChildWin->GetWindow() );
1382 pCW->pWin = pChildWin;
1384 if ( pChildWin->GetAlignment() == SfxChildAlignment::NOALIGNMENT || pChildWin->GetWindow()->GetParent() == pWorkWin)
1386 // The window is not docked or docked outside of one split windows
1387 // and must therefore be registered explicitly as a Child
1388 if (pChildWin->GetController())
1389 pCW->pCli = RegisterChild_Impl(pChildWin->GetController(), pChildWin->GetAlignment());
1390 else
1391 pCW->pCli = RegisterChild_Impl(*(pChildWin->GetWindow()), pChildWin->GetAlignment());
1392 pCW->pCli->nVisible = SfxChildVisibility::VISIBLE;
1393 if ( pChildWin->GetAlignment() != SfxChildAlignment::NOALIGNMENT && bIsFullScreen )
1394 pCW->pCli->nVisible ^= SfxChildVisibility::ACTIVE;
1395 pCW->pCli->bSetFocus = bSetFocus;
1397 else
1399 // A docked window which parent is not a WorkingWindow, must lie
1400 // in a SplitWindow and thus not be explicitly registered.
1401 // This happens already in the initialization of SfxDockingWindows!
1404 // Save the information in the INI file
1405 SaveStatus_Impl(pChildWin, pCW->aInfo);
1408 void SfxWorkWindow::RemoveChildWin_Impl( SfxChildWin_Impl *pCW )
1410 sal_uInt16 nId = pCW->nSaveId;
1411 SfxChildWindow *pChildWin = pCW->pWin;
1413 // Save the information in the INI file
1414 SfxChildWindowFlags nFlags = pCW->aInfo.nFlags;
1415 pCW->aInfo = pChildWin->GetInfo();
1416 pCW->aInfo.nFlags |= nFlags;
1417 SaveStatus_Impl(pChildWin, pCW->aInfo);
1419 pChildWin->Hide();
1421 if ( pCW->pCli )
1423 // Child window is a direct child window and must therefore unregister
1424 // itself from the WorkWindow
1425 pCW->pCli = nullptr;
1426 if (pChildWin->GetController())
1427 ReleaseChild_Impl(*pChildWin->GetController());
1428 else
1429 ReleaseChild_Impl(*pChildWin->GetWindow());
1431 else
1433 // ChildWindow is within a SplitWindow and unregister itself in
1434 // the destructor.
1437 pWorkWin->GetSystemWindow()->GetTaskPaneList()->RemoveWindow( pChildWin->GetWindow() );
1438 pCW->pWin = nullptr;
1439 pChildWin->Destroy();
1441 GetBindings().Invalidate( nId );
1444 void SfxWorkWindow::ResetStatusBar_Impl()
1446 aStatBar.eId = StatusBarId::None;
1449 void SfxWorkWindow::SetStatusBar_Impl(StatusBarId eId)
1451 if (eId != StatusBarId::None && bShowStatusBar && IsVisible_Impl())
1452 aStatBar.eId = eId;
1455 void SfxWorkWindow::UpdateStatusBar_Impl()
1457 Reference< css::beans::XPropertySet > xPropSet( GetFrameInterface(), UNO_QUERY );
1458 Reference< css::frame::XLayoutManager > xLayoutManager;
1460 Any aValue = xPropSet->getPropertyValue( g_aLayoutManagerPropName );
1461 aValue >>= xLayoutManager;
1463 // No status bar, if no ID is required or when in FullScreenView or
1464 // if disabled
1465 if (aStatBar.eId != StatusBarId::None && IsDockingAllowed() && bInternalDockingAllowed && bShowStatusBar &&
1466 !bIsFullScreen)
1468 // Id has changed, thus create a suitable Statusbarmanager, this takes
1469 // over the current status bar;
1470 if ( xLayoutManager.is() )
1471 xLayoutManager->requestElement( g_aStatusBarResName );
1473 else
1475 // Destroy the current StatusBar
1476 // The Manager only creates the Status bar, does not destroy it.
1477 if ( xLayoutManager.is() )
1478 xLayoutManager->destroyElement( g_aStatusBarResName );
1482 void SfxWorkWindow::MakeVisible_Impl( bool bVis )
1484 if ( bVis )
1485 nOrigMode = SfxVisibilityFlags::Standard;
1486 else
1487 nOrigMode = SfxVisibilityFlags::Invisible;
1489 if ( nOrigMode != nUpdateMode)
1490 nUpdateMode = nOrigMode;
1493 bool SfxWorkWindow::IsVisible_Impl() const
1495 return nOrigMode != SfxVisibilityFlags::Invisible;
1499 void SfxWorkWindow::HidePopups_Impl(bool bHide, sal_uInt16 nId )
1501 if (comphelper::LibreOfficeKit::isActive() && bHide)
1502 return;
1504 for (const std::unique_ptr<SfxChildWin_Impl>& i : aChildWins)
1506 SfxChildWindow *pCW = i->pWin;
1507 if (pCW && pCW->GetAlignment() == SfxChildAlignment::NOALIGNMENT && pCW->GetType() != nId)
1509 vcl::Window *pWin = pCW->GetWindow();
1510 SfxChild_Impl *pChild = FindChild_Impl(pWin);
1511 if (!pChild)
1513 SAL_WARN("sfx.appl", "missing SfxChild_Impl child!");
1514 continue;
1516 if (bHide)
1518 pChild->nVisible &= ~SfxChildVisibility::ACTIVE;
1519 pCW->Hide();
1521 else if ( !comphelper::LibreOfficeKit::isActive() ||
1522 SfxChildVisibility::ACTIVE != (pChild->nVisible & SfxChildVisibility::ACTIVE) )
1524 pChild->nVisible |= SfxChildVisibility::ACTIVE;
1525 if ( SfxChildVisibility::VISIBLE == (pChild->nVisible & SfxChildVisibility::VISIBLE) )
1526 pCW->Show( ShowFlags::NoFocusChange | ShowFlags::NoActivate );
1533 void SfxWorkWindow::ConfigChild_Impl(SfxChildIdentifier eChild,
1534 SfxDockingConfig eConfig, sal_uInt16 nId)
1536 SfxDockingWindow* pDockWin=nullptr;
1537 sal_uInt16 nPos = USHRT_MAX;
1538 vcl::Window *pWin=nullptr;
1539 SfxChildWin_Impl *pCW = nullptr;
1541 // configure direct childwindow
1542 for (const std::unique_ptr<SfxChildWin_Impl>& i : aChildWins)
1544 pCW = i.get();
1545 SfxChildWindow *pChild = pCW->pWin;
1546 if ( pChild && (pChild->GetType() == nId ))
1548 if (SfxDockingWindow* pSfxDockingWindow = dynamic_cast<SfxDockingWindow*>(pChild->GetWindow()))
1550 // it's a DockingWindow
1551 pDockWin = pSfxDockingWindow;
1553 else
1555 // FloatingWindow or ModelessDialog
1556 pWin = pChild->GetWindow();
1558 break;
1562 if ( pDockWin )
1564 if ( eChild == SfxChildIdentifier::DOCKINGWINDOW || pDockWin->GetAlignment() == SfxChildAlignment::NOALIGNMENT )
1566 if ( eChild == SfxChildIdentifier::SPLITWINDOW && eConfig == SfxDockingConfig::TOGGLEFLOATMODE)
1568 // DockingWindow was dragged out of a SplitWindow
1569 pCW->pCli = RegisterChild_Impl(*pDockWin, pDockWin->GetAlignment());
1570 pCW->pCli->nVisible = SfxChildVisibility::VISIBLE;
1573 pWin = pDockWin;
1575 else
1577 SfxSplitWindow *pSplitWin = GetSplitWindow_Impl(pDockWin->GetAlignment());
1579 // configure DockingWindow inside a SplitWindow
1580 if ( eConfig == SfxDockingConfig::TOGGLEFLOATMODE)
1582 // DockingWindow was dragged into a SplitWindow
1583 pCW->pCli = nullptr;
1584 ReleaseChild_Impl(*pDockWin);
1587 pWin = pSplitWin->GetSplitWindow();
1588 if ( pSplitWin->GetWindowCount() == 1 )
1589 static_cast<SplitWindow*>(pWin)->Show( true, ShowFlags::NoFocusChange | ShowFlags::NoActivate );
1593 DBG_ASSERT( pCW, "Unknown window!" );
1595 if ( !bSorted )
1596 // windows may have been registered and released without an update until now
1597 Sort_Impl();
1599 decltype(aSortedList)::size_type n;
1600 for ( n=0; n<aSortedList.size(); ++n )
1602 SfxChild_Impl *pChild = aChildren[aSortedList[n]].get();
1603 if ( pChild && pChild->pWin == pWin )
1604 break;
1607 if ( n < aSortedList.size() )
1608 // sometimes called while toggling float mode
1609 nPos = aSortedList[n];
1611 switch ( eConfig )
1613 case SfxDockingConfig::SETDOCKINGRECTS :
1615 if (nPos == USHRT_MAX || !pDockWin)
1616 return;
1618 tools::Rectangle aOuterRect( GetTopRect_Impl() );
1619 aOuterRect.SetPos( pWorkWin->OutputToScreenPixel( aOuterRect.TopLeft() ));
1620 tools::Rectangle aInnerRect( aOuterRect );
1622 // The current affected window is included in the calculation of
1623 // the inner rectangle!
1624 for (sal_uInt16 i : aSortedList)
1626 SfxChild_Impl* pCli = aChildren[i].get();
1628 if ( pCli && pCli->nVisible == SfxChildVisibility::VISIBLE && pCli->pWin )
1630 switch ( pCli->eAlign )
1632 case SfxChildAlignment::TOP:
1633 // Object-Toolboxes come always last
1634 aInnerRect.AdjustTop(pCli->aSize.Height() );
1635 break;
1637 case SfxChildAlignment::HIGHESTTOP:
1638 // Always performed first
1639 aInnerRect.AdjustTop(pCli->aSize.Height() );
1640 break;
1642 case SfxChildAlignment::LOWESTTOP:
1643 // Is only counted if it is the current window
1644 if ( i == nPos )
1645 aInnerRect.AdjustTop(pCli->aSize.Height() );
1646 break;
1648 case SfxChildAlignment::BOTTOM:
1649 // Object-Toolboxes come always last
1650 aInnerRect.AdjustBottom( -(pCli->aSize.Height()) );
1651 break;
1653 case SfxChildAlignment::LOWESTBOTTOM:
1654 // Always performed first
1655 aInnerRect.AdjustBottom( -(pCli->aSize.Height()) );
1656 break;
1658 case SfxChildAlignment::HIGHESTBOTTOM:
1659 // Is only counted if it is the current window
1660 if ( i == nPos )
1661 aInnerRect.AdjustBottom( -(pCli->aSize.Height()) );
1662 break;
1664 case SfxChildAlignment::LEFT:
1665 // Toolboxes come always last
1666 aInnerRect.AdjustLeft(pCli->aSize.Width() );
1667 break;
1669 case SfxChildAlignment::FIRSTLEFT:
1670 // Always performed first
1671 aInnerRect.AdjustLeft(pCli->aSize.Width() );
1672 break;
1674 case SfxChildAlignment::LASTLEFT:
1675 // Is only counted if it is the current window
1676 if (i == nPos)
1677 aInnerRect.AdjustLeft(pCli->aSize.Width() );
1678 break;
1680 case SfxChildAlignment::RIGHT:
1681 // Toolboxes come always last
1682 aInnerRect.AdjustRight( -(pCli->aSize.Width()) );
1683 break;
1685 case SfxChildAlignment::FIRSTRIGHT:
1686 // Is only counted if it is the current window
1687 if (i == nPos)
1688 aInnerRect.AdjustRight( -(pCli->aSize.Width()) );
1689 break;
1691 case SfxChildAlignment::LASTRIGHT:
1692 // Always performed first
1693 aInnerRect.AdjustRight( -(pCli->aSize.Width()) );
1694 break;
1696 default:
1697 break;
1702 pDockWin->SetDockingRects(aOuterRect, aInnerRect);
1703 break;
1706 case SfxDockingConfig::ALIGNDOCKINGWINDOW :
1707 case SfxDockingConfig::TOGGLEFLOATMODE:
1709 if ( nPos == USHRT_MAX && !pCW )
1710 return;
1712 SfxChildAlignment eAlign = SfxChildAlignment::NOALIGNMENT;
1713 SfxChild_Impl *pCli = ( nPos != USHRT_MAX ) ? aChildren[nPos].get() : nullptr;
1714 if ( pCli && pDockWin )
1716 eAlign = pDockWin->GetAlignment();
1717 if ( eChild == SfxChildIdentifier::DOCKINGWINDOW || eAlign == SfxChildAlignment::NOALIGNMENT)
1719 // configuration inside the SplitWindow, no change for the SplitWindows' configuration
1720 pCli->bResize = true;
1721 pCli->aSize = pDockWin->GetSizePixel();
1725 if ( pCli )
1727 if( pCli->eAlign != eAlign )
1729 bSorted = false;
1730 pCli->eAlign = eAlign;
1733 ArrangeChildren_Impl();
1734 ShowChildren_Impl();
1737 if ( pCW && pCW->pWin )
1739 // store changed configuration
1740 SfxChildWindowFlags nFlags = pCW->aInfo.nFlags;
1741 pCW->aInfo = pCW->pWin->GetInfo();
1742 pCW->aInfo.nFlags |= nFlags;
1743 SaveStatus_Impl( pCW->pWin, pCW->aInfo);
1746 break;
1751 namespace
1753 template <sal_uInt16 SfxChildWin_Impl::*Member>
1754 SfxChildWin_Impl* Get_Impl(const std::vector<std::unique_ptr<SfxChildWin_Impl>>& rChildWins,
1755 sal_uInt16 nId)
1757 for (auto& pChildWin : rChildWins)
1758 if (pChildWin.get()->*Member == nId)
1759 return pChildWin.get();
1760 return nullptr;
1762 auto Get_ById = Get_Impl<&SfxChildWin_Impl::nId>;
1763 auto Get_BySaveId = Get_Impl<&SfxChildWin_Impl::nSaveId>;
1766 void SfxWorkWindow::SetChildWindowVisible_Impl( sal_uInt32 lId, bool bEnabled, SfxVisibilityFlags nMode )
1768 sal_uInt16 nId = static_cast<sal_uInt16>( lId & 0xFFFF );
1770 SfxChildWin_Impl* pCW = Get_BySaveId(aChildWins, nId);
1772 if ( !pCW )
1774 // If new, then initialize, add this here depending on the flag or
1775 // the Parent
1776 pCW = new SfxChildWin_Impl( lId );
1777 pCW->nId = nId;
1778 InitializeChild_Impl( pCW );
1779 aChildWins.push_back( std::unique_ptr<SfxChildWin_Impl>(pCW) );
1782 pCW->nId = nId;
1783 pCW->nVisibility = nMode;
1784 pCW->bEnable = bEnabled;
1788 // The on/off status of a ChildWindow is switched
1790 void SfxWorkWindow::ToggleChildWindow_Impl(sal_uInt16 nId, bool bSetFocus)
1792 if (SfxChildWin_Impl* pCW = Get_ById(aChildWins, nId))
1794 // The Window is already known
1795 SfxChildWindow *pChild = pCW->pWin;
1797 bool bCreationAllowed( true );
1798 if ( !bInternalDockingAllowed )
1800 // Special case for all non-floatable child windows. We have
1801 // to prevent the creation here!
1802 bCreationAllowed = !( pCW->aInfo.nFlags & SfxChildWindowFlags::FORCEDOCK );
1805 if ( bCreationAllowed )
1807 if ( pCW->bCreate )
1809 if ( pChild )
1811 if ( pChild->QueryClose() )
1813 pCW->bCreate = false;
1814 // The Window should be switched off
1815 pChild->SetVisible_Impl( false );
1816 RemoveChildWin_Impl( pCW );
1819 else
1821 // no actual Window exists, yet => just remember the "switched off" state
1822 pCW->bCreate = false;
1825 else
1827 pCW->bCreate = true;
1828 if ( pChild )
1830 ShowChildWindow_Impl( nId, true, bSetFocus );
1832 else
1834 // create actual Window
1835 CreateChildWin_Impl( pCW, bSetFocus );
1836 if ( !pCW->pWin )
1837 // no success
1838 pCW->bCreate = false;
1843 ArrangeChildren_Impl();
1844 ShowChildren_Impl();
1846 if ( pCW->bCreate && bCreationAllowed )
1848 if ( !pCW->pCli )
1850 SfxDockingWindow *pDock =
1851 static_cast<SfxDockingWindow*>( pCW->pWin->GetWindow() );
1852 if ( pDock->IsAutoHide_Impl() )
1853 pDock->AutoShow_Impl();
1857 return;
1860 #ifdef DBG_UTIL
1861 if (Get_BySaveId(aChildWins, nId))
1863 OSL_FAIL("The ChildWindow is not in context!");
1865 else
1867 OSL_FAIL("The ChildWindow is not registered!");
1869 #endif
1873 bool SfxWorkWindow::HasChildWindow_Impl(sal_uInt16 nId)
1875 if (const SfxChildWin_Impl* pCW = Get_BySaveId(aChildWins, nId))
1876 return ( pCW->pWin && pCW->bCreate );
1878 return false;
1881 bool SfxWorkWindow::IsFloating( sal_uInt16 nId )
1883 SfxChildWin_Impl* pCW = Get_BySaveId(aChildWins, nId);
1885 if ( !pCW )
1887 // If new, then initialize, add this here depending on the flag or
1888 // the Parent
1889 pCW = new SfxChildWin_Impl( nId );
1890 pCW->bEnable = false;
1891 pCW->nId = 0;
1892 pCW->nVisibility = SfxVisibilityFlags::Invisible;
1893 InitializeChild_Impl( pCW );
1894 aChildWins.push_back( std::unique_ptr<SfxChildWin_Impl>(pCW) );
1897 SfxChildAlignment eAlign;
1898 if ( pCW->aInfo.GetExtraData_Impl( &eAlign ) )
1899 return( eAlign == SfxChildAlignment::NOALIGNMENT );
1900 else
1901 return true;
1905 bool SfxWorkWindow::KnowsChildWindow_Impl(sal_uInt16 nId)
1907 if (SfxChildWin_Impl* pCW = Get_BySaveId(aChildWins, nId))
1909 if ( !(pCW->aInfo.nFlags & SfxChildWindowFlags::ALWAYSAVAILABLE) && !IsVisible_Impl( pCW->nVisibility ) )
1910 return false;
1911 return pCW->bEnable;
1913 else
1914 return false;
1918 void SfxWorkWindow::SetChildWindow_Impl(sal_uInt16 nId, bool bOn, bool bSetFocus)
1920 SfxChildWin_Impl* pCW = Get_BySaveId(aChildWins, nId);
1922 if ( !pCW )
1924 // If new, then initialize, add this here depending on the flag or
1925 // the Parent
1926 pCW = new SfxChildWin_Impl( nId );
1927 InitializeChild_Impl( pCW );
1928 aChildWins.push_back( std::unique_ptr<SfxChildWin_Impl>(pCW) );
1931 if ( pCW->bCreate != bOn )
1932 ToggleChildWindow_Impl(nId,bSetFocus);
1936 void SfxWorkWindow::ShowChildWindow_Impl(sal_uInt16 nId, bool bVisible, bool bSetFocus)
1938 if (SfxChildWin_Impl* pCW = Get_ById(aChildWins, nId))
1940 SfxChildWindow *pChildWin = pCW->pWin;
1941 if ( pChildWin )
1943 if ( bVisible )
1945 if ( pCW->pCli )
1947 pCW->pCli->bSetFocus = bSetFocus;
1948 pCW->pCli->nVisible = SfxChildVisibility::VISIBLE;
1949 pChildWin->Show( bSetFocus && pChildWin->WantsFocus() ? ShowFlags::NONE : ShowFlags::NoFocusChange | ShowFlags::NoActivate );
1951 else
1952 static_cast<SfxDockingWindow*>(pChildWin->GetWindow())->Reappear_Impl();
1955 else
1957 if ( pCW->pCli )
1959 pCW->pCli->nVisible = SfxChildVisibility::VISIBLE ^ SfxChildVisibility::NOT_HIDDEN;
1960 pCW->pWin->Hide();
1962 else
1963 static_cast<SfxDockingWindow*>(pChildWin->GetWindow())->Disappear_Impl();
1967 ArrangeChildren_Impl();
1968 ShowChildren_Impl();
1970 else if ( bVisible )
1972 SetChildWindow_Impl( nId, true, bSetFocus );
1973 pChildWin = pCW->pWin;
1976 if ( pChildWin )
1978 pChildWin->SetVisible_Impl( bVisible );
1979 SfxChildWindowFlags nFlags = pCW->aInfo.nFlags;
1980 pCW->aInfo = pChildWin->GetInfo();
1981 pCW->aInfo.nFlags |= nFlags;
1982 if ( !pCW->bCreate )
1983 SaveStatus_Impl( pChildWin, pCW->aInfo );
1986 return;
1989 #ifdef DBG_UTIL
1990 if (Get_BySaveId(aChildWins, nId))
1992 OSL_FAIL("The ChildWindow is not in context!");
1994 else
1996 OSL_FAIL("The ChildWindow is not registered");
1998 #endif
2002 SfxChildWindow* SfxWorkWindow::GetChildWindow_Impl(sal_uInt16 nId)
2004 if (SfxChildWin_Impl* pCW = Get_BySaveId(aChildWins, nId))
2005 return pCW->pWin;
2006 return nullptr;
2010 void SfxWorkWindow::ResetChildWindows_Impl()
2012 for (std::unique_ptr<SfxChildWin_Impl>& pChildWin : aChildWins)
2014 pChildWin->nId = 0;
2015 pChildWin->bEnable = false;
2019 // returns the size of the area (client area) of the
2020 // parent windows, in which the ChildWindow can be fitted.
2022 tools::Rectangle SfxWorkWindow::GetTopRect_Impl() const
2024 return pMasterFrame->GetTopOuterRectPixel_Impl();
2028 // Virtual method to find out if there is room for a ChildWindow in the
2029 // client area of the parent.
2031 bool SfxWorkWindow::RequestTopToolSpacePixel_Impl( SvBorder aBorder )
2033 return !(!IsDockingAllowed() ||
2034 aClientArea.GetWidth() < aBorder.Left() + aBorder.Right() ||
2035 aClientArea.GetHeight() < aBorder.Top() + aBorder.Bottom());
2038 void SfxWorkWindow::SaveStatus_Impl(SfxChildWindow *pChild, const SfxChildWinInfo &rInfo)
2040 // The Status of the Presentation mode is not saved
2041 if ( IsDockingAllowed() && bInternalDockingAllowed )
2042 pChild->SaveStatus(rInfo);
2045 void SfxWorkWindow::InitializeChild_Impl(SfxChildWin_Impl *pCW)
2047 SfxDispatcher *pDisp = pBindings->GetDispatcher_Impl();
2048 SfxViewFrame *pViewFrame = pDisp ? pDisp->GetFrame() :nullptr;
2049 SfxModule *pMod = pViewFrame ? SfxModule::GetActiveModule(pViewFrame) :nullptr;
2051 OUString sModule;
2052 if (pViewFrame)
2056 uno::Reference< frame::XModuleManager2 > xModuleManager(
2057 frame::ModuleManager::create(::comphelper::getProcessComponentContext()));
2058 sModule = xModuleManager->identify(pViewFrame->GetFrame().GetFrameInterface());
2059 SvtModuleOptions::EFactory eFac = SvtModuleOptions::ClassifyFactoryByServiceName(sModule);
2060 sModule = SvtModuleOptions::GetFactoryShortName(eFac);
2062 catch (...)
2067 SfxChildWinFactory* pFact=nullptr;
2068 SfxApplication *pApp = SfxGetpApp();
2070 pFact = pApp->GetChildWinFactoryById(pCW->nSaveId);
2071 if ( pFact )
2073 pCW->aInfo = pFact->aInfo;
2074 pCW->aInfo.aModule = sModule;
2075 SfxChildWindow::InitializeChildWinFactory_Impl(
2076 pCW->nSaveId, pCW->aInfo);
2077 pCW->bCreate = pCW->aInfo.bVisible;
2078 SfxChildWindowFlags nFlags = pFact->aInfo.nFlags;
2079 if ( nFlags & SfxChildWindowFlags::TASK )
2080 pCW->aInfo.nFlags |= SfxChildWindowFlags::TASK;
2081 if ( nFlags & SfxChildWindowFlags::CANTGETFOCUS )
2082 pCW->aInfo.nFlags |= SfxChildWindowFlags::CANTGETFOCUS;
2083 if ( nFlags & SfxChildWindowFlags::FORCEDOCK )
2084 pCW->aInfo.nFlags |= SfxChildWindowFlags::FORCEDOCK;
2085 pFact->aInfo = pCW->aInfo;
2086 return;
2090 if ( !pMod )
2091 return;
2093 pFact = pMod->GetChildWinFactoryById(pCW->nSaveId);
2094 if ( !pFact )
2095 return;
2097 pCW->aInfo = pFact->aInfo;
2098 pCW->aInfo.aModule = sModule;
2099 SfxChildWindow::InitializeChildWinFactory_Impl(
2100 pCW->nSaveId, pCW->aInfo);
2101 pCW->bCreate = pCW->aInfo.bVisible;
2102 SfxChildWindowFlags nFlags = pFact->aInfo.nFlags;
2103 if ( nFlags & SfxChildWindowFlags::TASK )
2104 pCW->aInfo.nFlags |= SfxChildWindowFlags::TASK;
2105 if ( nFlags & SfxChildWindowFlags::CANTGETFOCUS )
2106 pCW->aInfo.nFlags |= SfxChildWindowFlags::CANTGETFOCUS;
2107 if ( nFlags & SfxChildWindowFlags::FORCEDOCK )
2108 pCW->aInfo.nFlags |= SfxChildWindowFlags::FORCEDOCK;
2109 if ( nFlags & SfxChildWindowFlags::ALWAYSAVAILABLE )
2110 pCW->aInfo.nFlags |= SfxChildWindowFlags::ALWAYSAVAILABLE;
2111 pFact->aInfo = pCW->aInfo;
2114 SfxSplitWindow* SfxWorkWindow::GetSplitWindow_Impl( SfxChildAlignment eAlign )
2116 switch ( eAlign )
2118 case SfxChildAlignment::TOP:
2119 return pSplit[2];
2121 case SfxChildAlignment::BOTTOM:
2122 return pSplit[3];
2124 case SfxChildAlignment::LEFT:
2125 return pSplit[0];
2127 case SfxChildAlignment::RIGHT:
2128 return pSplit[1];
2130 default:
2131 return nullptr;
2135 void SfxWorkWindow::MakeChildrenVisible_Impl( bool bVis )
2137 bAllChildrenVisible = bVis;
2138 if ( bVis )
2140 if ( !bSorted )
2141 Sort_Impl();
2142 for (sal_uInt16 n : aSortedList)
2144 SfxChild_Impl* pCli = aChildren[n].get();
2145 if ( (pCli->eAlign == SfxChildAlignment::NOALIGNMENT) || (IsDockingAllowed() && bInternalDockingAllowed) )
2146 pCli->nVisible |= SfxChildVisibility::ACTIVE;
2149 else
2151 if ( !bSorted )
2152 Sort_Impl();
2153 for (sal_uInt16 n : aSortedList)
2155 SfxChild_Impl* pCli = aChildren[n].get();
2156 pCli->nVisible &= ~SfxChildVisibility::ACTIVE;
2161 bool SfxWorkWindow::IsAutoHideMode( const SfxSplitWindow *pSplitWin )
2163 for (const VclPtr<SfxSplitWindow> & pWin : pSplit)
2165 if ( pWin.get() != pSplitWin && pWin->IsAutoHide( true ) )
2166 return true;
2168 return false;
2172 void SfxWorkWindow::EndAutoShow_Impl( Point aPos )
2174 for (VclPtr<SfxSplitWindow> & p : pSplit)
2176 if ( p && p->IsAutoHide(false) )
2178 Point aLocalPos = p->ScreenToOutputPixel( aPos );
2179 tools::Rectangle aRect( Point(), p->GetSizePixel() );
2180 if ( !aRect.Contains( aLocalPos ) )
2181 p->FadeOut();
2186 void SfxWorkWindow::ArrangeAutoHideWindows( SfxSplitWindow *pActSplitWin )
2188 if ( m_nLock )
2189 return;
2191 tools::Rectangle aArea( aUpperClientArea );
2192 for ( sal_uInt16 n=0; n<SFX_SPLITWINDOWS_MAX; n++ )
2194 // Either dummy window or window in the auto-show-mode are processed
2195 // (not pinned, FadeIn).
2196 // Only the abandoned window may be invisible, because perhaps its
2197 // size is just being calculated before it is displayed.
2198 VclPtr<SfxSplitWindow> const & pSplitWin = pSplit[n];
2199 bool bDummyWindow = !pSplitWin->IsFadeIn();
2200 vcl::Window *pDummy = pSplitWin->GetSplitWindow();
2201 vcl::Window *pWin = bDummyWindow ? pDummy : pSplitWin;
2202 if ( (pSplitWin->IsPinned() && !bDummyWindow) || (!pWin->IsVisible() && pActSplitWin != pSplitWin) )
2203 continue;
2205 // Width and position of the dummy window as a starting point
2206 Size aSize = pDummy->GetSizePixel();
2207 Point aPos = pDummy->GetPosPixel();
2209 switch ( n )
2211 case 0 :
2213 // Left SplitWindow
2214 // Get the width of the Window yourself, if no DummyWindow
2215 if ( !bDummyWindow )
2216 aSize.setWidth( pSplitWin->GetSizePixel().Width() );
2218 // If a Window is visible to the left, then the free region
2219 // starts to the right from it, for example at the Client area
2220 tools::Long nLeft = aPos.X() + aSize.Width();
2221 if ( nLeft > aArea.Left() )
2222 aArea.SetLeft( nLeft );
2223 break;
2225 case 1 :
2227 // Right SplitWindow
2228 // Position to correct the difference of the widths
2229 aPos.AdjustX(aSize.Width() );
2231 // Get the width of the Window yourself, if no DummyWindow
2232 if ( !bDummyWindow )
2233 aSize.setWidth( pSplitWin->GetSizePixel().Width() );
2235 aPos.AdjustX( -(aSize.Width()) );
2237 // If already a window is opened at the left side, then the
2238 // right is not allowed to overlap this one.
2239 if ( aPos.X() < aArea.Left() )
2241 aPos.setX( aArea.Left() );
2242 aSize.setWidth( aArea.GetWidth() );
2245 // If a Window is visible to the right, then the free region
2246 // starts to the left from it, for example at the Client area
2247 tools::Long nRight = aPos.X();
2248 if ( !aArea.IsWidthEmpty() && nRight < aArea.Right() )
2249 aArea.SetRight( nRight );
2250 break;
2252 case 2 :
2254 // Top SplitWindow
2255 // Get the height of the Window yourself, if no DummyWindow
2256 if ( !bDummyWindow )
2257 aSize.setHeight( pSplitWin->GetSizePixel().Height() );
2260 // Adjust width with regard to if a Window is already open
2261 // to the left or right
2262 aPos.setX( aArea.Left() );
2263 aSize.setWidth( aArea.GetWidth() );
2265 // If a Window is visible at the top, then the free region
2266 // starts beneath it, for example at the Client area
2267 tools::Long nTop = aPos.Y() + aSize.Height();
2268 if ( nTop > aArea.Top() )
2269 aArea.SetTop( nTop );
2270 break;
2272 case 3 :
2274 // The bottom SplitWindow
2275 // Position to correct the difference of the heights
2276 aPos.AdjustY(aSize.Height() );
2278 // Get the height of the Window yourself, if no DummyWindow
2279 if ( !bDummyWindow )
2280 aSize.setHeight( pSplitWin->GetSizePixel().Height() );
2282 aPos.AdjustY( -(aSize.Height()) );
2284 // Adjust width with regard to if a Window is already open
2285 // to the left or right.
2286 aPos.setX( aArea.Left() );
2287 aSize.setWidth( aArea.GetWidth() );
2289 // If already a window is opened at the top, then the
2290 // bottom one is not allowed to overlap this one.
2291 if ( aPos.Y() < aArea.Top() )
2293 aPos.setY( aArea.Top() );
2294 aSize.setHeight( aArea.GetHeight() );
2297 break;
2301 if ( !bDummyWindow )
2302 // the FadeIn-Window is a Floating window, which coordinates are
2303 // set in Screen coordinates.
2304 pSplitWin->SetPosSizePixel( pWorkWin->OutputToScreenPixel(aPos), aSize );
2305 else
2306 // the docked DummyWindow
2307 pDummy->SetPosSizePixel( aPos, aSize );
2311 tools::Rectangle SfxWorkWindow::GetFreeArea( bool bAutoHide ) const
2313 if ( bAutoHide )
2315 tools::Rectangle aArea( aClientArea );
2316 for ( sal_uInt16 n=0; n<SFX_SPLITWINDOWS_MAX; n++ )
2318 if ( pSplit[n]->IsPinned() || !pSplit[n]->IsVisible() )
2319 continue;
2321 Size aSize = pSplit[n]->GetSizePixel();
2322 switch ( n )
2324 case 0 :
2325 aArea.AdjustLeft(aSize.Width() );
2326 break;
2327 case 1 :
2328 aArea.AdjustRight( -(aSize.Width()) );
2329 break;
2330 case 2 :
2331 aArea.AdjustTop(aSize.Height() );
2332 break;
2333 case 3 :
2334 aArea.AdjustBottom( -(aSize.Height()) );
2335 break;
2339 return aArea;
2341 else
2342 return aClientArea;
2345 void SfxWorkWindow::SetActiveChild_Impl( vcl::Window *pChild )
2347 pActiveChild = pChild;
2350 void SfxWorkWindow::DataChanged_Impl()
2352 ArrangeChildren_Impl();
2355 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */