1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #ifndef SFX_SIDEBAR_CONTROLLER_HXX
23 #define SFX_SIDEBAR_CONTROLLER_HXX
24 
25 #include "AsynchronousCall.hxx"
26 #include "Context.hxx"
27 #include "FocusManager.hxx"
28 #include "Panel.hxx"
29 #include "ResourceManager.hxx"
30 #include "TabBar.hxx"
31 
32 #include <vcl/menu.hxx>
33 
34 #include <com/sun/star/awt/XWindowPeer.hpp>
35 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
36 #include <com/sun/star/frame/XDispatch.hpp>
37 #include <com/sun/star/ui/XContextChangeEventListener.hpp>
38 #include <com/sun/star/ui/XUIElement.hpp>
39 #include <com/sun/star/ui/XSidebar.hpp>
40 
41 #include <boost/noncopyable.hpp>
42 #include <boost/optional.hpp>
43 #include <cppuhelper/compbase4.hxx>
44 #include <cppuhelper/basemutex.hxx>
45 
46 namespace css = ::com::sun::star;
47 namespace cssu = ::com::sun::star::uno;
48 
49 
50 namespace
51 {
52     typedef ::cppu::WeakComponentImplHelper4 <
53         css::ui::XContextChangeEventListener,
54         css::beans::XPropertyChangeListener,
55         css::ui::XSidebar,
56         css::frame::XStatusListener
57         > SidebarControllerInterfaceBase;
58 }
59 
60 class SfxSplitWindow;
61 class FixedBitmap;
62 
63 namespace sfx2 { namespace sidebar {
64 
65 class ContentPanelDescriptor;
66 class Deck;
67 class DeckDescriptor;
68 class SidebarDockingWindow;
69 class TabBar;
70 class TabBarConfiguration;
71 
72 class SidebarController
73     : private ::boost::noncopyable,
74       private ::cppu::BaseMutex,
75       public SidebarControllerInterfaceBase
76 {
77 public:
78     SidebarController(
79         SidebarDockingWindow* pParentWindow,
80         const cssu::Reference<css::frame::XFrame>& rxFrame);
81     virtual ~SidebarController (void);
82 
83     // ui::XContextChangeEventListener
84     virtual void SAL_CALL notifyContextChangeEvent (const css::ui::ContextChangeEventObject& rEvent)
85         throw(cssu::RuntimeException);
86 
87     // XEventListener
88     virtual void SAL_CALL disposing (const css::lang::EventObject& rEventObject)
89         throw(cssu::RuntimeException);
90 
91     // beans::XPropertyChangeListener
92     virtual void SAL_CALL propertyChange (const css::beans::PropertyChangeEvent& rEvent)
93         throw(cssu::RuntimeException);
94 
95     // frame::XStatusListener
96     virtual void SAL_CALL statusChanged (const css::frame::FeatureStateEvent& rEvent)
97         throw(cssu::RuntimeException);
98 
99     // ui::XSidebar
100     virtual void SAL_CALL requestLayout (void)
101         throw(cssu::RuntimeException);
102 
103     void NotifyResize (void);
104 
105     void SwitchToDeck (
106         const ::rtl::OUString& rsDeckId);
107     void OpenThenSwitchToDeck (
108         const ::rtl::OUString& rsDeckId);
109 
110     /** Show only the tab bar, not the deck.
111     */
112     void RequestCloseDeck (void);
113 
114     /** Open the deck area and restore the parent window to its old width.
115     */
116     void RequestOpenDeck (void);
117 
118     FocusManager& GetFocusManager (void);
119 
120 private:
121     ::boost::scoped_ptr<Deck> mpCurrentDeck;
122     SidebarDockingWindow* mpParentWindow;
123     ::boost::scoped_ptr<TabBar> mpTabBar;
124     cssu::Reference<css::frame::XFrame> mxFrame;
125     Context maCurrentContext;
126     Context maRequestedContext;
127     ::rtl::OUString msCurrentDeckId;
128     ::rtl::OUString msCurrentDeckTitle;
129     AsynchronousCall maPropertyChangeForwarder;
130     AsynchronousCall maContextChangeUpdate;
131 
132     /** Two flags control whether the deck is displayed or if only the
133         tab bar remains visible.
134         The mbIsDeckOpen flag stores the current state while
135         mbIsDeckRequestedOpen stores how this state should be.  User
136         actions like clicking on the deck closer affect the
137         mbIsDeckRequestedOpen.  Normally both flags have the same
138         value.  A document being read-only can prevent the deck from opening.
139     */
140     ::boost::optional<bool> mbIsDeckRequestedOpen;
141     ::boost::optional<bool> mbIsDeckOpen;
142     bool mbCanDeckBeOpened;
143 
144     /** Before the deck is closed the sidebar width is saved into this variable,
145         so that it can be restored when the deck is reopended.
146     */
147     sal_Int32 mnSavedSidebarWidth;
148     FocusManager maFocusManager;
149     cssu::Reference<css::frame::XDispatch> mxReadOnlyModeDispatch;
150     bool mbIsDocumentReadOnly;
151     SfxSplitWindow* mpSplitWindow;
152     /** When the user moves the splitter then we remember the
153         width at that time.
154     */
155     sal_Int32 mnWidthOnSplitterButtonDown;
156     /** Control that is temporarily used as replacement for the deck
157         to indicate that when the current mouse drag operation ends, the
158         sidebar will only show the tab bar.
159     */
160     ::boost::scoped_ptr<Window> mpCloseIndicator;
161 
162     DECL_LINK(WindowEventHandler, VclWindowEvent*);
163     /** Make maRequestedContext the current context.
164     */
165     void UpdateConfigurations (void);
166 
167     bool ArePanelSetsEqual (
168         const SharedPanelContainer& rCurrentPanels,
169         const ResourceManager::PanelContextDescriptorContainer& rRequestedPanels);
170     cssu::Reference<css::ui::XUIElement> CreateUIElement (
171         const cssu::Reference<css::awt::XWindowPeer>& rxWindow,
172         const ::rtl::OUString& rsImplementationURL,
173         const bool bWantsCanvas,
174         const Context& rContext);
175     SharedPanel CreatePanel (
176         const ::rtl::OUString& rsPanelId,
177         ::Window* pParentWindow,
178         const bool bIsInitiallyExpanded,
179         const Context& rContext);
180     void SwitchToDeck (
181         const DeckDescriptor& rDeckDescriptor,
182         const Context& rContext);
183     void ShowPopupMenu (
184         const Rectangle& rButtonBox,
185         const ::std::vector<TabBar::DeckMenuData>& rDeckSelectionData,
186         const ::std::vector<TabBar::DeckMenuData>& rDeckShowData) const;
187     void ShowDetailMenu (const ::rtl::OUString& rsMenuCommand) const;
188     ::boost::shared_ptr<PopupMenu> CreatePopupMenu (
189         const ::std::vector<TabBar::DeckMenuData>& rDeckSelectionData,
190         const ::std::vector<TabBar::DeckMenuData>& rDeckShowData) const;
191     DECL_LINK(OnMenuItemSelected, Menu*);
192     void BroadcastPropertyChange (void);
193 
194     /** The close of the deck changes the width of the child window.
195         That is only possible if there is no other docking window docked above or below the sidebar.
196         Return whether the width of the child window can be modified.
197     */
198     bool CanModifyChildWindowWidth (void);
199 
200     /** Set the child window container to a new width.
201         Return the old width.
202     */
203     sal_Int32 SetChildWindowWidth (const sal_Int32 nNewWidth);
204 
205     /** Update the icons displayed in the title bars of the deck and
206         the panels.  This is called once when a deck is created and
207         every time when a data change event is processed.
208     */
209     void UpdateTitleBarIcons (void);
210 
211     void UpdateDeckOpenState (void);
212     void RestrictWidth (void);
213     SfxSplitWindow* GetSplitWindow (void);
214     void ProcessNewWidth (const sal_Int32 nNewWidth);
215     void UpdateCloseIndicator (const bool bIsIndicatorVisible);
216 
217     /** Typically called when a panel is focused via keyboard.
218         Tries to scroll the deck up or down to make the given panel
219         completely visible.
220     */
221     void ShowPanel (const Panel& rPanel);
222 
223     Context GetCurrentContext (void) const;
224 
225     virtual void SAL_CALL disposing (void);
226 };
227 
228 
229 } } // end of namespace sfx2::sidebar
230 
231 #endif
232