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     bool ArePanelSetsEqual (
167         const SharedPanelContainer& rCurrentPanels,
168         const ResourceManager::PanelContextDescriptorContainer& rRequestedPanels);
169     cssu::Reference<css::ui::XUIElement> CreateUIElement (
170         const cssu::Reference<css::awt::XWindowPeer>& rxWindow,
171         const ::rtl::OUString& rsImplementationURL,
172         const bool bWantsCanvas);
173     SharedPanel CreatePanel (
174         const ::rtl::OUString& rsPanelId,
175         ::Window* pParentWindow );
176     void SwitchToDeck (
177         const DeckDescriptor& rDeckDescriptor,
178         const Context& rContext);
179     void ShowPopupMenu (
180         const Rectangle& rButtonBox,
181         const ::std::vector<TabBar::DeckMenuData>& rDeckSelectionData,
182         const ::std::vector<TabBar::DeckMenuData>& rDeckShowData) const;
183     void ShowDetailMenu (const ::rtl::OUString& rsMenuCommand) const;
184     css::util::URL GetURL (const ::rtl::OUString& rsCommand) const;
185     cssu::Reference<css::frame::XDispatch> GetDispatch (const css::util::URL& rURL) const;
186     ::boost::shared_ptr<PopupMenu> CreatePopupMenu (
187         const ::std::vector<TabBar::DeckMenuData>& rDeckSelectionData,
188         const ::std::vector<TabBar::DeckMenuData>& rDeckShowData) const;
189     DECL_LINK(OnMenuItemSelected, Menu*);
190     void BroadcastPropertyChange (void);
191 
192     /** The close of the deck changes the width of the child window.
193         That is only possible if there is no other docking window docked above or below the sidebar.
194         Return whether the width of the child window can be modified.
195     */
196     bool CanModifyChildWindowWidth (void);
197 
198     /** Set the child window container to a new width.
199         Return the old width.
200     */
201     sal_Int32 SetChildWindowWidth (const sal_Int32 nNewWidth);
202 
203     /** Update the icons displayed in the title bars of the deck and
204         the panels.  This is called once when a deck is created and
205         every time when a data change event is processed.
206     */
207     void UpdateTitleBarIcons (void);
208 
209     void UpdateDeckOpenState (void);
210     void RestrictWidth (void);
211     SfxSplitWindow* GetSplitWindow (void);
212     void ProcessNewWidth (const sal_Int32 nNewWidth);
213     void UpdateCloseIndicator (const bool bIsIndicatorVisible);
214 
215     virtual void SAL_CALL disposing (void);
216 };
217 
218 
219 } } // end of namespace sfx2::sidebar
220 
221 #endif
222