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 "ResourceManager.hxx"
26 #include "AsynchronousCall.hxx"
27 #include "TabBar.hxx"
28 #include "Context.hxx"
29 #include "Panel.hxx"
30 
31 #include <vcl/menu.hxx>
32 
33 #include <com/sun/star/awt/XWindowPeer.hpp>
34 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
35 #include <com/sun/star/ui/XContextChangeEventListener.hpp>
36 #include <com/sun/star/ui/XUIElement.hpp>
37 #include <com/sun/star/ui/XSidebar.hpp>
38 
39 #include <boost/noncopyable.hpp>
40 #include <cppuhelper/compbase3.hxx>
41 #include <cppuhelper/basemutex.hxx>
42 
43 namespace css = ::com::sun::star;
44 namespace cssu = ::com::sun::star::uno;
45 
46 
47 namespace
48 {
49     typedef ::cppu::WeakComponentImplHelper3 <
50         css::ui::XContextChangeEventListener,
51         css::beans::XPropertyChangeListener,
52         css::ui::XSidebar
53         > SidebarControllerInterfaceBase;
54 }
55 
56 namespace sfx2 { namespace sidebar {
57 
58 class ContentPanelDescriptor;
59 class Deck;
60 class DeckDescriptor;
61 class SidebarDockingWindow;
62 class TabBar;
63 class TabBarConfiguration;
64 
65 class SidebarController
66     : private ::boost::noncopyable,
67       private ::cppu::BaseMutex,
68       public SidebarControllerInterfaceBase
69 {
70 public:
71     SidebarController(
72         SidebarDockingWindow* pParentWindow,
73         const cssu::Reference<css::frame::XFrame>& rxFrame);
74     virtual ~SidebarController (void);
75 
76     // ui::XContextChangeEventListener
77     virtual void SAL_CALL notifyContextChangeEvent (const css::ui::ContextChangeEventObject& rEvent)
78         throw(cssu::RuntimeException);
79 
80     // XEventListener
81     virtual void SAL_CALL disposing (const css::lang::EventObject& rEventObject)
82         throw(cssu::RuntimeException);
83 
84     // beans::XPropertyChangeListener
85     virtual void SAL_CALL propertyChange (const css::beans::PropertyChangeEvent& rEvent)
86         throw(cssu::RuntimeException);
87 
88     // ui::XSidebar
89     virtual void SAL_CALL requestLayout (void)
90         throw(cssu::RuntimeException);
91 
92     void NotifyResize (void);
93 
94     void SwitchToDeck (
95         const ::rtl::OUString& rsDeckId);
96 
97     /** Show only the tab bar, not the deck.
98     */
99     void CloseDeck (void);
100 
101     /** Open the deck area and restore the parent window to its old width.
102     */
103     void OpenDeck (void);
104 
105 private:
106     ::boost::scoped_ptr<Deck> mpCurrentDeck;
107     SidebarDockingWindow* mpParentWindow;
108     ::boost::scoped_ptr<TabBar> mpTabBar;
109     cssu::Reference<css::frame::XFrame> mxFrame;
110     Context maCurrentContext;
111     ::rtl::OUString msCurrentDeckId;
112     AsynchronousCall maPropertyChangeForwarder;
113     bool mbIsDeckClosed;
114     /** Before the deck is closed the sidebar width is saved into this variable,
115         so that it can be restored when the deck is reopended.
116     */
117     sal_Int32 mnSavedSidebarWidth;
118 
119     DECL_LINK(WindowEventHandler, VclWindowEvent*);
120     void UpdateConfigurations (const Context& rContext);
121     bool ArePanelSetsEqual (
122         const SharedPanelContainer& rCurrentPanels,
123         const ResourceManager::PanelContextDescriptorContainer& rRequestedPanels);
124     cssu::Reference<css::ui::XUIElement> CreateUIElement (
125         const cssu::Reference<css::awt::XWindowPeer>& rxWindow,
126         const ::rtl::OUString& rsImplementationURL);
127     SharedPanel CreatePanel (
128         const ::rtl::OUString& rsPanelId,
129         ::Window* pParentWindow,
130         const ::rtl::OUString& rsMenuCommand);
131     void SwitchToDeck (
132         const DeckDescriptor& rDeckDescriptor,
133         const Context& rContext);
134     void ShowPopupMenu (
135         const Rectangle& rButtonBox,
136         const ::std::vector<TabBar::DeckMenuData>& rDeckSelectionData,
137         const ::std::vector<TabBar::DeckMenuData>& rDeckShowData) const;
138     void ShowDetailMenu (const ::rtl::OUString& rsMenuCommand) const;
139     ::boost::shared_ptr<PopupMenu> CreatePopupMenu (
140         const ::std::vector<TabBar::DeckMenuData>& rDeckSelectionData,
141         const ::std::vector<TabBar::DeckMenuData>& rDeckShowData) const;
142     DECL_LINK(OnMenuItemSelected, Menu*);
143     void BroadcastPropertyChange (void);
144 
145     /** The close of the deck changes the width of the child window.
146         That is only possible if there is no other docking window docked above or below the sidebar.
147         Return whether the width of the child window can be modified.
148     */
149     bool CanModifyChildWindowWidth (void) const;
150 
151     /** Set the child window container to a new width.
152         Return the old width.
153     */
154     sal_Int32 SetChildWindowWidth (const sal_Int32 nNewWidth);
155 
156     void RestrictWidth (void);
157 
158     virtual void SAL_CALL disposing (void);
159 };
160 
161 
162 } } // end of namespace sfx2::sidebar
163 
164 #endif
165