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 /** In some situations it is necessary to force an update of the 106 current deck and its panels. One reason is a change of the 107 view scale. Some panels can handle this only when 108 constructed. In this case we have to a context change and 109 also force that all panels are destroyed and created new. 110 */ 111 const static sal_Int32 SwitchFlag_NoForce = 0x00; 112 const static sal_Int32 SwitchFlag_ForceSwitch = 0x01; 113 const static sal_Int32 SwitchFlag_ForceNewDeck = 0x02; 114 const static sal_Int32 SwitchFlag_ForceNewPanels = 0x02; 115 116 void SwitchToDeck ( 117 const ::rtl::OUString& rsDeckId); 118 void OpenThenSwitchToDeck ( 119 const ::rtl::OUString& rsDeckId); 120 121 /** Show only the tab bar, not the deck. 122 */ 123 void RequestCloseDeck (void); 124 125 /** Open the deck area and restore the parent window to its old width. 126 */ 127 void RequestOpenDeck (void); 128 129 FocusManager& GetFocusManager (void); 130 131 private: 132 ::boost::scoped_ptr<Deck> mpCurrentDeck; 133 SidebarDockingWindow* mpParentWindow; 134 ::boost::scoped_ptr<TabBar> mpTabBar; 135 cssu::Reference<css::frame::XFrame> mxFrame; 136 Context maCurrentContext; 137 Context maRequestedContext; 138 /// Use a combination of SwitchFlag_* as value. 139 sal_Int32 mnRequestedForceFlags; 140 ::rtl::OUString msCurrentDeckId; 141 ::rtl::OUString msCurrentDeckTitle; 142 AsynchronousCall maPropertyChangeForwarder; 143 AsynchronousCall maContextChangeUpdate; 144 145 /** Two flags control whether the deck is displayed or if only the 146 tab bar remains visible. 147 The mbIsDeckOpen flag stores the current state while 148 mbIsDeckRequestedOpen stores how this state should be. User 149 actions like clicking on the deck closer affect the 150 mbIsDeckRequestedOpen. Normally both flags have the same 151 value. A document being read-only can prevent the deck from opening. 152 */ 153 ::boost::optional<bool> mbIsDeckRequestedOpen; 154 ::boost::optional<bool> mbIsDeckOpen; 155 bool mbCanDeckBeOpened; 156 157 /** Before the deck is closed the sidebar width is saved into this variable, 158 so that it can be restored when the deck is reopended. 159 */ 160 sal_Int32 mnSavedSidebarWidth; 161 FocusManager maFocusManager; 162 cssu::Reference<css::frame::XDispatch> mxReadOnlyModeDispatch; 163 bool mbIsDocumentReadOnly; 164 SfxSplitWindow* mpSplitWindow; 165 /** When the user moves the splitter then we remember the 166 width at that time. 167 */ 168 sal_Int32 mnWidthOnSplitterButtonDown; 169 /** Control that is temporarily used as replacement for the deck 170 to indicate that when the current mouse drag operation ends, the 171 sidebar will only show the tab bar. 172 */ 173 ::boost::scoped_ptr<Window> mpCloseIndicator; 174 175 DECL_LINK(WindowEventHandler, VclWindowEvent*); 176 /** Make maRequestedContext the current context. 177 */ 178 void UpdateConfigurations (void); 179 180 cssu::Reference<css::ui::XUIElement> CreateUIElement ( 181 const cssu::Reference<css::awt::XWindowPeer>& rxWindow, 182 const ::rtl::OUString& rsImplementationURL, 183 const bool bWantsCanvas, 184 const Context& rContext); 185 SharedPanel CreatePanel ( 186 const ::rtl::OUString& rsPanelId, 187 ::Window* pParentWindow, 188 const bool bIsInitiallyExpanded, 189 const Context& rContext); 190 void SwitchToDeck ( 191 const DeckDescriptor& rDeckDescriptor, 192 const Context& rContext); 193 void ShowPopupMenu ( 194 const Rectangle& rButtonBox, 195 const ::std::vector<TabBar::DeckMenuData>& rMenuData) const; 196 void ShowDetailMenu (const ::rtl::OUString& rsMenuCommand) const; 197 ::boost::shared_ptr<PopupMenu> CreatePopupMenu ( 198 const ::std::vector<TabBar::DeckMenuData>& rMenuData) const; 199 DECL_LINK(OnMenuItemSelected, Menu*); 200 void BroadcastPropertyChange (void); 201 202 /** The close of the deck changes the width of the child window. 203 That is only possible if there is no other docking window docked above or below the sidebar. 204 Return whether the width of the child window can be modified. 205 */ 206 bool CanModifyChildWindowWidth (void); 207 208 /** Set the child window container to a new width. 209 Return the old width. 210 */ 211 sal_Int32 SetChildWindowWidth (const sal_Int32 nNewWidth); 212 213 /** Update the icons displayed in the title bars of the deck and 214 the panels. This is called once when a deck is created and 215 every time when a data change event is processed. 216 */ 217 void UpdateTitleBarIcons (void); 218 219 void UpdateDeckOpenState (void); 220 void RestrictWidth (void); 221 SfxSplitWindow* GetSplitWindow (void); 222 void ProcessNewWidth (const sal_Int32 nNewWidth); 223 void UpdateCloseIndicator (const bool bIsIndicatorVisible); 224 225 /** Typically called when a panel is focused via keyboard. 226 Tries to scroll the deck up or down to make the given panel 227 completely visible. 228 */ 229 void ShowPanel (const Panel& rPanel); 230 231 Context GetCurrentContext (void) const; 232 233 virtual void SAL_CALL disposing (void); 234 }; 235 236 237 } } // end of namespace sfx2::sidebar 238 239 #endif 240