Bump version to 6.4-15
[LibreOffice.git] / include / sfx2 / sidebar / SidebarController.hxx
blob440ff55b7bfc715a0c8b460080a177f746ac60de
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 .
19 #ifndef INCLUDED_SFX2_SOURCE_SIDEBAR_SIDEBARCONTROLLER_HXX
20 #define INCLUDED_SFX2_SOURCE_SIDEBAR_SIDEBARCONTROLLER_HXX
22 #include <memory>
23 #include <sal/config.h>
25 #include <sfx2/sidebar/AsynchronousCall.hxx>
26 #include <sfx2/sidebar/Context.hxx>
27 #include <sfx2/sidebar/Deck.hxx>
28 #include <sfx2/sidebar/FocusManager.hxx>
29 #include <sfx2/sidebar/ResourceManager.hxx>
30 #include <sfx2/sidebar/TabBar.hxx>
31 #include <sfx2/viewfrm.hxx>
33 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
34 #include <com/sun/star/frame/XStatusListener.hpp>
35 #include <com/sun/star/frame/XFrameActionListener.hpp>
36 #include <com/sun/star/ui/XContextChangeEventListener.hpp>
37 #include <com/sun/star/ui/XSidebar.hpp>
39 #include <boost/optional.hpp>
40 #include <cppuhelper/compbase.hxx>
41 #include <cppuhelper/basemutex.hxx>
43 namespace com::sun::star::awt { class XWindowPeer; }
44 namespace com::sun::star::frame { class XDispatch; }
45 namespace com::sun::star::ui { class XUIElement; }
47 typedef cppu::WeakComponentImplHelper <
48 css::ui::XContextChangeEventListener,
49 css::beans::XPropertyChangeListener,
50 css::ui::XSidebar,
51 css::frame::XStatusListener,
52 css::frame::XFrameActionListener
53 > SidebarControllerInterfaceBase;
55 class SfxSplitWindow;
57 namespace sfx2 { namespace sidebar {
59 class DeckDescriptor;
60 class SidebarDockingWindow;
62 class SFX2_DLLPUBLIC SidebarController
63 : private ::cppu::BaseMutex,
64 public SidebarControllerInterfaceBase
66 public:
67 static rtl::Reference<SidebarController> create(SidebarDockingWindow* pParentWindow,
68 const SfxViewFrame* pViewFrame);
69 virtual ~SidebarController() override;
70 SidebarController(const SidebarController&) = delete;
71 SidebarController& operator=( const SidebarController& ) = delete;
73 /** Return the SidebarController object that is associated with
74 the given XFrame.
75 @return
76 When there is no SidebarController object for the given
77 XFrame then <NULL/> is returned.
79 static SidebarController* GetSidebarControllerForFrame (
80 const css::uno::Reference<css::frame::XFrame>& rxFrame);
82 static void registerSidebarForFrame(SidebarController* pController, const css::uno::Reference<css::frame::XController>& xFrame);
84 static void unregisterSidebarForFrame(SidebarController* pController, const css::uno::Reference<css::frame::XController>& xFrame);
86 // ui::XContextChangeEventListener
87 virtual void SAL_CALL notifyContextChangeEvent (const css::ui::ContextChangeEventObject& rEvent) override;
89 // XEventListener
90 virtual void SAL_CALL disposing (const css::lang::EventObject& rEventObject) override;
92 // beans::XPropertyChangeListener
93 virtual void SAL_CALL propertyChange (const css::beans::PropertyChangeEvent& rEvent) override;
95 // frame::XStatusListener
96 virtual void SAL_CALL statusChanged (const css::frame::FeatureStateEvent& rEvent) override;
98 // frame::XFrameActionListener
99 virtual void SAL_CALL frameAction (const css::frame::FrameActionEvent& rEvent) override;
101 // ui::XSidebar
102 virtual void SAL_CALL requestLayout() override;
104 void NotifyResize();
106 /** In some situations it is necessary to force an update of the
107 current deck and its panels. One reason is a change of the
108 view scale. Some panels can handle this only when
109 constructed. In this case we have to a context change and
110 also force that all panels are destroyed and created new.
112 const static sal_Int32 SwitchFlag_NoForce = 0x00;
113 const static sal_Int32 SwitchFlag_ForceSwitch = 0x01;
114 const static sal_Int32 SwitchFlag_ForceNewDeck = 0x02;
115 const static sal_Int32 SwitchFlag_ForceNewPanels = 0x02;
117 void OpenThenSwitchToDeck(const OUString& rsDeckId);
118 void OpenThenToggleDeck(const OUString& rsDeckId);
120 /** Show only the tab bar, not the deck.
122 void RequestCloseDeck();
124 /** Open the deck area and restore the parent window to its old width.
126 void RequestOpenDeck();
128 /** Returns true when the given deck is the currently visible deck
130 bool IsDeckVisible(const OUString& rsDeckId);
132 bool IsDeckOpen(const sal_Int32 nIndex = -1);
134 FocusManager& GetFocusManager() { return maFocusManager;}
136 ResourceManager* GetResourceManager() { return mpResourceManager.get();}
137 auto& GetCurrentDeckId() const { return msCurrentDeckId; }
139 // std::unique_ptr<ResourceManager> GetResourceManager() { return mpResourceManager;}
141 const Context& GetCurrentContext() const { return maCurrentContext;}
142 bool IsDocumentReadOnly (void) const { return mbIsDocumentReadOnly;}
144 void SwitchToDeck(const OUString& rsDeckId);
145 void SwitchToDefaultDeck();
146 bool WasFloatingDeckClosed() const { return mbFloatingDeckClosed; }
147 void SetFloatingDeckClosed(bool bWasClosed) { mbFloatingDeckClosed = bWasClosed; }
149 void CreateDeck(const OUString& rDeckId);
150 void CreateDeck(const OUString& rDeckId, const Context& rContext, bool bForceCreate = false);
152 ResourceManager::DeckContextDescriptorContainer GetMatchingDecks();
153 ResourceManager::PanelContextDescriptorContainer GetMatchingPanels(const OUString& rDeckId);
155 void notifyDeckTitle(const OUString& targetDeckId);
157 void updateModel(const css::uno::Reference<css::frame::XModel>& xModel);
159 void disposeDecks();
161 void FadeIn();
162 void FadeOut();
164 tools::Rectangle GetDeckDragArea() const;
166 css::uno::Reference<css::frame::XFrame> const & getXFrame() const {return mxFrame;}
168 sal_Int32 getMaximumWidth() const { return mnMaximumSidebarWidth; }
169 void setMaximumWidth(sal_Int32 nMaximumWidth) { mnMaximumSidebarWidth = nMaximumWidth; }
171 void saveDeckState();
173 void SyncUpdate();
175 private:
176 SidebarController(SidebarDockingWindow* pParentWindow, const SfxViewFrame* pViewFrame);
178 VclPtr<Deck> mpCurrentDeck;
179 VclPtr<SidebarDockingWindow> mpParentWindow;
180 const SfxViewFrame* mpViewFrame;
181 css::uno::Reference<css::frame::XFrame> mxFrame;
182 VclPtr<TabBar> mpTabBar;
183 Context maCurrentContext;
184 Context maRequestedContext;
185 css::uno::Reference<css::frame::XController> mxCurrentController;
186 /// Use a combination of SwitchFlag_* as value.
187 sal_Int32 mnRequestedForceFlags;
188 sal_Int32 mnMaximumSidebarWidth;
189 OUString msCurrentDeckId;
190 AsynchronousCall maPropertyChangeForwarder;
191 AsynchronousCall maContextChangeUpdate;
192 AsynchronousCall maAsynchronousDeckSwitch;
194 /** Two flags control whether the deck is displayed or if only the
195 tab bar remains visible.
196 The mbIsDeckOpen flag stores the current state while
197 mbIsDeckRequestedOpen stores how this state should be. User
198 actions like clicking on the deck closer affect the
199 mbIsDeckRequestedOpen. Normally both flags have the same
200 value. A document being read-only can prevent the deck from opening.
202 ::boost::optional<bool> mbIsDeckRequestedOpen;
203 ::boost::optional<bool> mbIsDeckOpen;
205 bool mbFloatingDeckClosed;
207 /** Before the deck is closed the sidebar width is saved into this variable,
208 so that it can be restored when the deck is reopened.
210 sal_Int32 mnSavedSidebarWidth;
211 FocusManager maFocusManager;
212 css::uno::Reference<css::frame::XDispatch> mxReadOnlyModeDispatch;
213 bool mbIsDocumentReadOnly;
214 VclPtr<SfxSplitWindow> mpSplitWindow;
215 /** When the user moves the splitter then we remember the
216 width at that time.
218 sal_Int32 mnWidthOnSplitterButtonDown;
219 /** Control that is temporarily used as replacement for the deck
220 to indicate that when the current mouse drag operation ends, the
221 sidebar will only show the tab bar.
223 VclPtr<vcl::Window> mpCloseIndicator;
225 DECL_LINK(WindowEventHandler, VclWindowEvent&, void);
226 /** Make maRequestedContext the current context.
228 void UpdateConfigurations();
230 css::uno::Reference<css::ui::XUIElement> CreateUIElement (
231 const css::uno::Reference<css::awt::XWindowPeer>& rxWindow,
232 const OUString& rsImplementationURL,
233 const bool bWantsCanvas,
234 const Context& rContext);
236 void CreatePanels(
237 const OUString& rDeckId,
238 const Context& rContext);
239 VclPtr<Panel> CreatePanel (
240 const OUString& rsPanelId,
241 vcl::Window* pParentWindow,
242 const bool bIsInitiallyExpanded,
243 const Context& rContext,
244 const VclPtr<Deck>& pDeck);
246 void SwitchToDeck (
247 const DeckDescriptor& rDeckDescriptor,
248 const Context& rContext);
250 void ShowPopupMenu (
251 const tools::Rectangle& rButtonBox,
252 const ::std::vector<TabBar::DeckMenuData>& rMenuData) const;
253 VclPtr<PopupMenu> CreatePopupMenu (
254 const ::std::vector<TabBar::DeckMenuData>& rMenuData) const;
255 DECL_LINK(OnMenuItemSelected, Menu*, bool);
256 void BroadcastPropertyChange();
258 /** The close of the deck changes the width of the child window.
259 That is only possible if there is no other docking window docked above or below the sidebar.
260 Return whether the width of the child window can be modified.
262 bool CanModifyChildWindowWidth();
264 /** Set the child window container to a new width.
265 Return the old width.
267 sal_Int32 SetChildWindowWidth (const sal_Int32 nNewWidth);
269 /** Update the icons displayed in the title bars of the deck and
270 the panels. This is called once when a deck is created and
271 every time when a data change event is processed.
273 void UpdateTitleBarIcons();
275 void UpdateDeckOpenState();
276 void RestrictWidth (sal_Int32 nWidth);
277 SfxSplitWindow* GetSplitWindow();
278 void ProcessNewWidth (const sal_Int32 nNewWidth);
279 void UpdateCloseIndicator (const bool bIsIndicatorVisible);
281 /** Typically called when a panel is focused via keyboard.
282 Tries to scroll the deck up or down to make the given panel
283 completely visible.
285 void ShowPanel (const Panel& rPanel);
287 virtual void SAL_CALL disposing() override;
289 std::unique_ptr<ResourceManager> mpResourceManager;
293 } } // end of namespace sfx2::sidebar
295 #endif
297 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */