Branch libreoffice-5-0-4
[LibreOffice.git] / sfx2 / source / sidebar / SidebarController.hxx
blob5fb8466b1fbc0688715361947dbb7e04ff04c8d7
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 <sal/config.h>
24 #include <map>
26 #include "AsynchronousCall.hxx"
27 #include "Context.hxx"
28 #include "FocusManager.hxx"
29 #include "Panel.hxx"
30 #include "ResourceManager.hxx"
31 #include "TabBar.hxx"
33 #include <vcl/menu.hxx>
35 #include <com/sun/star/awt/XWindowPeer.hpp>
36 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
37 #include <com/sun/star/frame/XDispatch.hpp>
38 #include <com/sun/star/ui/XContextChangeEventListener.hpp>
39 #include <com/sun/star/ui/XUIElement.hpp>
40 #include <com/sun/star/ui/XSidebar.hpp>
42 #include <boost/noncopyable.hpp>
43 #include <boost/optional.hpp>
44 #include <cppuhelper/compbase4.hxx>
45 #include <cppuhelper/basemutex.hxx>
46 #include <cppuhelper/weakref.hxx>
48 namespace
50 typedef ::cppu::WeakComponentImplHelper4 <
51 css::ui::XContextChangeEventListener,
52 css::beans::XPropertyChangeListener,
53 css::ui::XSidebar,
54 css::frame::XStatusListener
55 > SidebarControllerInterfaceBase;
58 class SfxSplitWindow;
59 class FixedBitmap;
61 namespace sfx2 { namespace sidebar {
63 class ContentPanelDescriptor;
64 class Deck;
65 class DeckDescriptor;
66 class SidebarDockingWindow;
67 class TabBar;
68 class TabBarConfiguration;
70 class SidebarController
71 : private ::boost::noncopyable,
72 private ::cppu::BaseMutex,
73 public SidebarControllerInterfaceBase
75 public:
76 SidebarController(
77 SidebarDockingWindow* pParentWindow,
78 const css::uno::Reference<css::frame::XFrame>& rxFrame);
79 virtual ~SidebarController();
81 /** Return the SidebarController object that is associated with
82 the given XFrame.
83 @return
84 When there is no SidebarController object for the given
85 XFrame then <NULL/> is returned.
87 static SidebarController* GetSidebarControllerForFrame (
88 const css::uno::Reference<css::frame::XFrame>& rxFrame);
90 // ui::XContextChangeEventListener
91 virtual void SAL_CALL notifyContextChangeEvent (const css::ui::ContextChangeEventObject& rEvent)
92 throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
94 // XEventListener
95 virtual void SAL_CALL disposing (const css::lang::EventObject& rEventObject)
96 throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
98 // beans::XPropertyChangeListener
99 virtual void SAL_CALL propertyChange (const css::beans::PropertyChangeEvent& rEvent)
100 throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
102 // frame::XStatusListener
103 virtual void SAL_CALL statusChanged (const css::frame::FeatureStateEvent& rEvent)
104 throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
106 // ui::XSidebar
107 virtual void SAL_CALL requestLayout()
108 throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
110 void NotifyResize();
112 /** In some situations it is necessary to force an update of the
113 current deck and its panels. One reason is a change of the
114 view scale. Some panels can handle this only when
115 constructed. In this case we have to a context change and
116 also force that all panels are destroyed and created new.
118 const static sal_Int32 SwitchFlag_NoForce = 0x00;
119 const static sal_Int32 SwitchFlag_ForceSwitch = 0x01;
120 const static sal_Int32 SwitchFlag_ForceNewDeck = 0x02;
121 const static sal_Int32 SwitchFlag_ForceNewPanels = 0x02;
123 void OpenThenSwitchToDeck (
124 const ::rtl::OUString& rsDeckId);
126 /** Show only the tab bar, not the deck.
128 void RequestCloseDeck();
130 /** Open the deck area and restore the parent window to its old width.
132 void RequestOpenDeck();
134 /** Returns true when the given deck is the currently visible deck
136 bool IsDeckVisible (const ::rtl::OUString& rsDeckId);
138 FocusManager& GetFocusManager() { return maFocusManager;}
140 private:
141 typedef ::std::map<
142 const css::uno::Reference<css::frame::XFrame>,
143 css::uno::WeakReference<SidebarController>
144 > SidebarControllerContainer;
145 static SidebarControllerContainer maSidebarControllerContainer;
147 VclPtr<Deck> mpCurrentDeck;
148 VclPtr<SidebarDockingWindow> mpParentWindow;
149 VclPtr<TabBar> mpTabBar;
150 css::uno::Reference<css::frame::XFrame> mxFrame;
151 Context maCurrentContext;
152 Context maRequestedContext;
153 /// Use a combination of SwitchFlag_* as value.
154 sal_Int32 mnRequestedForceFlags;
155 ::rtl::OUString msCurrentDeckId;
156 ::rtl::OUString msCurrentDeckTitle;
157 AsynchronousCall maPropertyChangeForwarder;
158 AsynchronousCall maContextChangeUpdate;
159 AsynchronousCall maAsynchronousDeckSwitch;
161 /** Two flags control whether the deck is displayed or if only the
162 tab bar remains visible.
163 The mbIsDeckOpen flag stores the current state while
164 mbIsDeckRequestedOpen stores how this state should be. User
165 actions like clicking on the deck closer affect the
166 mbIsDeckRequestedOpen. Normally both flags have the same
167 value. A document being read-only can prevent the deck from opening.
169 ::boost::optional<bool> mbIsDeckRequestedOpen;
170 ::boost::optional<bool> mbIsDeckOpen;
171 bool mbCanDeckBeOpened;
173 /** Before the deck is closed the sidebar width is saved into this variable,
174 so that it can be restored when the deck is reopended.
176 sal_Int32 mnSavedSidebarWidth;
177 FocusManager maFocusManager;
178 css::uno::Reference<css::frame::XDispatch> mxReadOnlyModeDispatch;
179 bool mbIsDocumentReadOnly;
180 VclPtr<SfxSplitWindow> mpSplitWindow;
181 /** When the user moves the splitter then we remember the
182 width at that time.
184 sal_Int32 mnWidthOnSplitterButtonDown;
185 /** Control that is temporarily used as replacement for the deck
186 to indicate that when the current mouse drag operation ends, the
187 sidebar will only show the tab bar.
189 VclPtr<vcl::Window> mpCloseIndicator;
191 DECL_LINK(WindowEventHandler, VclWindowEvent*);
192 /** Make maRequestedContext the current context.
194 void UpdateConfigurations();
196 css::uno::Reference<css::ui::XUIElement> CreateUIElement (
197 const css::uno::Reference<css::awt::XWindowPeer>& rxWindow,
198 const ::rtl::OUString& rsImplementationURL,
199 const bool bWantsCanvas,
200 const Context& rContext);
201 VclPtr<Panel> CreatePanel (
202 const ::rtl::OUString& rsPanelId,
203 vcl::Window* pParentWindow,
204 const bool bIsInitiallyExpanded,
205 const Context& rContext);
206 void SwitchToDeck (
207 const ::rtl::OUString& rsDeckId);
208 void SwitchToDeck (
209 const DeckDescriptor& rDeckDescriptor,
210 const Context& rContext);
211 void ShowPopupMenu (
212 const Rectangle& rButtonBox,
213 const ::std::vector<TabBar::DeckMenuData>& rMenuData) const;
214 ::boost::shared_ptr<PopupMenu> CreatePopupMenu (
215 const ::std::vector<TabBar::DeckMenuData>& rMenuData) const;
216 DECL_LINK(OnMenuItemSelected, Menu*);
217 void BroadcastPropertyChange();
219 /** The close of the deck changes the width of the child window.
220 That is only possible if there is no other docking window docked above or below the sidebar.
221 Return whether the width of the child window can be modified.
223 bool CanModifyChildWindowWidth();
225 /** Set the child window container to a new width.
226 Return the old width.
228 sal_Int32 SetChildWindowWidth (const sal_Int32 nNewWidth);
230 /** Update the icons displayed in the title bars of the deck and
231 the panels. This is called once when a deck is created and
232 every time when a data change event is processed.
234 void UpdateTitleBarIcons();
236 void UpdateDeckOpenState();
237 void RestrictWidth (sal_Int32 nWidth);
238 SfxSplitWindow* GetSplitWindow();
239 void ProcessNewWidth (const sal_Int32 nNewWidth);
240 void UpdateCloseIndicator (const bool bIsIndicatorVisible);
242 /** Typically called when a panel is focused via keyboard.
243 Tries to scroll the deck up or down to make the given panel
244 completely visible.
246 void ShowPanel (const Panel& rPanel);
248 Context GetCurrentContext() const { return maCurrentContext;}
250 virtual void SAL_CALL disposing() SAL_OVERRIDE;
253 } } // end of namespace sfx2::sidebar
255 #endif
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */