122de8995SAndre Fischer /**************************************************************
222de8995SAndre Fischer  *
322de8995SAndre Fischer  * Licensed to the Apache Software Foundation (ASF) under one
422de8995SAndre Fischer  * or more contributor license agreements.  See the NOTICE file
522de8995SAndre Fischer  * distributed with this work for additional information
622de8995SAndre Fischer  * regarding copyright ownership.  The ASF licenses this file
722de8995SAndre Fischer  * to you under the Apache License, Version 2.0 (the
822de8995SAndre Fischer  * "License"); you may not use this file except in compliance
922de8995SAndre Fischer  * with the License.  You may obtain a copy of the License at
1022de8995SAndre Fischer  *
1122de8995SAndre Fischer  *   http://www.apache.org/licenses/LICENSE-2.0
1222de8995SAndre Fischer  *
1322de8995SAndre Fischer  * Unless required by applicable law or agreed to in writing,
1422de8995SAndre Fischer  * software distributed under the License is distributed on an
1522de8995SAndre Fischer  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1622de8995SAndre Fischer  * KIND, either express or implied.  See the License for the
1722de8995SAndre Fischer  * specific language governing permissions and limitations
1822de8995SAndre Fischer  * under the License.
1922de8995SAndre Fischer  *
2022de8995SAndre Fischer  *************************************************************/
2122de8995SAndre Fischer 
2222de8995SAndre Fischer #ifndef SFX_SIDEBAR_CONTROLLER_HXX
2322de8995SAndre Fischer #define SFX_SIDEBAR_CONTROLLER_HXX
2422de8995SAndre Fischer 
2595a18594SAndre Fischer #include "AsynchronousCall.hxx"
267a32b0c8SAndre Fischer #include "Context.hxx"
2765908a7eSAndre Fischer #include "FocusManager.hxx"
28f120fe41SAndre Fischer #include "Panel.hxx"
2965908a7eSAndre Fischer #include "ResourceManager.hxx"
3065908a7eSAndre Fischer #include "TabBar.hxx"
3195a18594SAndre Fischer 
3295a18594SAndre Fischer #include <vcl/menu.hxx>
3322de8995SAndre Fischer 
34b9e67834SAndre Fischer #include <com/sun/star/awt/XWindowPeer.hpp>
35b9e67834SAndre Fischer #include <com/sun/star/beans/XPropertyChangeListener.hpp>
3613e1c3b4SAndre Fischer #include <com/sun/star/frame/XDispatch.hpp>
3722de8995SAndre Fischer #include <com/sun/star/ui/XContextChangeEventListener.hpp>
3895a18594SAndre Fischer #include <com/sun/star/ui/XUIElement.hpp>
397a32b0c8SAndre Fischer #include <com/sun/star/ui/XSidebar.hpp>
4095a18594SAndre Fischer 
4122de8995SAndre Fischer #include <boost/noncopyable.hpp>
4213e1c3b4SAndre Fischer #include <boost/optional.hpp>
4313e1c3b4SAndre Fischer #include <cppuhelper/compbase4.hxx>
4422de8995SAndre Fischer #include <cppuhelper/basemutex.hxx>
4522de8995SAndre Fischer 
4622de8995SAndre Fischer namespace css = ::com::sun::star;
4722de8995SAndre Fischer namespace cssu = ::com::sun::star::uno;
4822de8995SAndre Fischer 
497a32b0c8SAndre Fischer 
5022de8995SAndre Fischer namespace
5122de8995SAndre Fischer {
5213e1c3b4SAndre Fischer     typedef ::cppu::WeakComponentImplHelper4 <
53b9e67834SAndre Fischer         css::ui::XContextChangeEventListener,
547a32b0c8SAndre Fischer         css::beans::XPropertyChangeListener,
5513e1c3b4SAndre Fischer         css::ui::XSidebar,
5613e1c3b4SAndre Fischer         css::frame::XStatusListener
5722de8995SAndre Fischer         > SidebarControllerInterfaceBase;
5822de8995SAndre Fischer }
5922de8995SAndre Fischer 
6013e1c3b4SAndre Fischer class SfxSplitWindow;
6113e1c3b4SAndre Fischer class FixedBitmap;
6213e1c3b4SAndre Fischer 
63ff12d537SAndre Fischer namespace sfx2 { namespace sidebar {
6422de8995SAndre Fischer 
6595a18594SAndre Fischer class ContentPanelDescriptor;
6695a18594SAndre Fischer class Deck;
6795a18594SAndre Fischer class DeckDescriptor;
687a32b0c8SAndre Fischer class SidebarDockingWindow;
6922de8995SAndre Fischer class TabBar;
70ff12d537SAndre Fischer class TabBarConfiguration;
7122de8995SAndre Fischer 
7222de8995SAndre Fischer class SidebarController
7322de8995SAndre Fischer     : private ::boost::noncopyable,
7422de8995SAndre Fischer       private ::cppu::BaseMutex,
7522de8995SAndre Fischer       public SidebarControllerInterfaceBase
7622de8995SAndre Fischer {
7722de8995SAndre Fischer public:
7822de8995SAndre Fischer     SidebarController(
797a32b0c8SAndre Fischer         SidebarDockingWindow* pParentWindow,
8022de8995SAndre Fischer         const cssu::Reference<css::frame::XFrame>& rxFrame);
8122de8995SAndre Fischer     virtual ~SidebarController (void);
8222de8995SAndre Fischer 
83b9e67834SAndre Fischer     // ui::XContextChangeEventListener
8422de8995SAndre Fischer     virtual void SAL_CALL notifyContextChangeEvent (const css::ui::ContextChangeEventObject& rEvent)
8522de8995SAndre Fischer         throw(cssu::RuntimeException);
8622de8995SAndre Fischer 
87b9e67834SAndre Fischer     // XEventListener
8822de8995SAndre Fischer     virtual void SAL_CALL disposing (const css::lang::EventObject& rEventObject)
8922de8995SAndre Fischer         throw(cssu::RuntimeException);
9022de8995SAndre Fischer 
91b9e67834SAndre Fischer     // beans::XPropertyChangeListener
92b9e67834SAndre Fischer     virtual void SAL_CALL propertyChange (const css::beans::PropertyChangeEvent& rEvent)
93b9e67834SAndre Fischer         throw(cssu::RuntimeException);
947a32b0c8SAndre Fischer 
9513e1c3b4SAndre Fischer     // frame::XStatusListener
9613e1c3b4SAndre Fischer     virtual void SAL_CALL statusChanged (const css::frame::FeatureStateEvent& rEvent)
9713e1c3b4SAndre Fischer         throw(cssu::RuntimeException);
9813e1c3b4SAndre Fischer 
997a32b0c8SAndre Fischer     // ui::XSidebar
1007a32b0c8SAndre Fischer     virtual void SAL_CALL requestLayout (void)
1017a32b0c8SAndre Fischer         throw(cssu::RuntimeException);
102b9e67834SAndre Fischer 
10322de8995SAndre Fischer     void NotifyResize (void);
10422de8995SAndre Fischer 
105*a5297dafSAndre Fischer     /** In some situations it is necessary to force an update of the
106*a5297dafSAndre Fischer         current deck and its panels.  One reason is a change of the
107*a5297dafSAndre Fischer         view scale.  Some panels can handle this only when
108*a5297dafSAndre Fischer         constructed.  In this case we have to a context change and
109*a5297dafSAndre Fischer         also force that all panels are destroyed and created new.
110*a5297dafSAndre Fischer     */
111*a5297dafSAndre Fischer     const static sal_Int32 SwitchFlag_NoForce = 0x00;
112*a5297dafSAndre Fischer     const static sal_Int32 SwitchFlag_ForceSwitch = 0x01;
113*a5297dafSAndre Fischer     const static sal_Int32 SwitchFlag_ForceNewDeck = 0x02;
114*a5297dafSAndre Fischer     const static sal_Int32 SwitchFlag_ForceNewPanels = 0x02;
115*a5297dafSAndre Fischer 
116ff12d537SAndre Fischer     void SwitchToDeck (
11795a18594SAndre Fischer         const ::rtl::OUString& rsDeckId);
11813e1c3b4SAndre Fischer     void OpenThenSwitchToDeck (
11913e1c3b4SAndre Fischer         const ::rtl::OUString& rsDeckId);
120ff12d537SAndre Fischer 
1217a32b0c8SAndre Fischer     /** Show only the tab bar, not the deck.
1227a32b0c8SAndre Fischer     */
12313e1c3b4SAndre Fischer     void RequestCloseDeck (void);
1247a32b0c8SAndre Fischer 
1257a32b0c8SAndre Fischer     /** Open the deck area and restore the parent window to its old width.
1267a32b0c8SAndre Fischer     */
12713e1c3b4SAndre Fischer     void RequestOpenDeck (void);
1287a32b0c8SAndre Fischer 
12965908a7eSAndre Fischer     FocusManager& GetFocusManager (void);
1307e429a12SAndre Fischer 
13122de8995SAndre Fischer private:
132f120fe41SAndre Fischer     ::boost::scoped_ptr<Deck> mpCurrentDeck;
1337a32b0c8SAndre Fischer     SidebarDockingWindow* mpParentWindow;
1347a32b0c8SAndre Fischer     ::boost::scoped_ptr<TabBar> mpTabBar;
13522de8995SAndre Fischer     cssu::Reference<css::frame::XFrame> mxFrame;
1367a32b0c8SAndre Fischer     Context maCurrentContext;
137239cbbc0SAndre Fischer     Context maRequestedContext;
138*a5297dafSAndre Fischer     /// Use a combination of SwitchFlag_* as value.
139*a5297dafSAndre Fischer     sal_Int32 mnRequestedForceFlags;
14095a18594SAndre Fischer     ::rtl::OUString msCurrentDeckId;
14154eaaa32SAndre Fischer     ::rtl::OUString msCurrentDeckTitle;
14295a18594SAndre Fischer     AsynchronousCall maPropertyChangeForwarder;
143239cbbc0SAndre Fischer     AsynchronousCall maContextChangeUpdate;
14413e1c3b4SAndre Fischer 
14513e1c3b4SAndre Fischer     /** Two flags control whether the deck is displayed or if only the
14613e1c3b4SAndre Fischer         tab bar remains visible.
14713e1c3b4SAndre Fischer         The mbIsDeckOpen flag stores the current state while
14813e1c3b4SAndre Fischer         mbIsDeckRequestedOpen stores how this state should be.  User
14913e1c3b4SAndre Fischer         actions like clicking on the deck closer affect the
15013e1c3b4SAndre Fischer         mbIsDeckRequestedOpen.  Normally both flags have the same
15113e1c3b4SAndre Fischer         value.  A document being read-only can prevent the deck from opening.
15213e1c3b4SAndre Fischer     */
15313e1c3b4SAndre Fischer     ::boost::optional<bool> mbIsDeckRequestedOpen;
15413e1c3b4SAndre Fischer     ::boost::optional<bool> mbIsDeckOpen;
15513e1c3b4SAndre Fischer     bool mbCanDeckBeOpened;
15613e1c3b4SAndre Fischer 
1577a32b0c8SAndre Fischer     /** Before the deck is closed the sidebar width is saved into this variable,
1587a32b0c8SAndre Fischer         so that it can be restored when the deck is reopended.
1597a32b0c8SAndre Fischer     */
1607a32b0c8SAndre Fischer     sal_Int32 mnSavedSidebarWidth;
16165908a7eSAndre Fischer     FocusManager maFocusManager;
16213e1c3b4SAndre Fischer     cssu::Reference<css::frame::XDispatch> mxReadOnlyModeDispatch;
16313e1c3b4SAndre Fischer     bool mbIsDocumentReadOnly;
16413e1c3b4SAndre Fischer     SfxSplitWindow* mpSplitWindow;
16513e1c3b4SAndre Fischer     /** When the user moves the splitter then we remember the
16613e1c3b4SAndre Fischer         width at that time.
16713e1c3b4SAndre Fischer     */
16813e1c3b4SAndre Fischer     sal_Int32 mnWidthOnSplitterButtonDown;
16913e1c3b4SAndre Fischer     /** Control that is temporarily used as replacement for the deck
17013e1c3b4SAndre Fischer         to indicate that when the current mouse drag operation ends, the
17113e1c3b4SAndre Fischer         sidebar will only show the tab bar.
17213e1c3b4SAndre Fischer     */
17313e1c3b4SAndre Fischer     ::boost::scoped_ptr<Window> mpCloseIndicator;
17413e1c3b4SAndre Fischer 
17522de8995SAndre Fischer     DECL_LINK(WindowEventHandler, VclWindowEvent*);
176239cbbc0SAndre Fischer     /** Make maRequestedContext the current context.
177239cbbc0SAndre Fischer     */
178239cbbc0SAndre Fischer     void UpdateConfigurations (void);
179309fba80SAndre Fischer 
180ff12d537SAndre Fischer     cssu::Reference<css::ui::XUIElement> CreateUIElement (
181ff12d537SAndre Fischer         const cssu::Reference<css::awt::XWindowPeer>& rxWindow,
18222f77e9eSAndre Fischer         const ::rtl::OUString& rsImplementationURL,
183ae13266dSAndre Fischer         const bool bWantsCanvas,
184ae13266dSAndre Fischer         const Context& rContext);
185f120fe41SAndre Fischer     SharedPanel CreatePanel (
18695a18594SAndre Fischer         const ::rtl::OUString& rsPanelId,
1877e429a12SAndre Fischer         ::Window* pParentWindow,
188ae13266dSAndre Fischer         const bool bIsInitiallyExpanded,
189ae13266dSAndre Fischer         const Context& rContext);
190ff12d537SAndre Fischer     void SwitchToDeck (
191ff12d537SAndre Fischer         const DeckDescriptor& rDeckDescriptor,
1927a32b0c8SAndre Fischer         const Context& rContext);
19395a18594SAndre Fischer     void ShowPopupMenu (
19495a18594SAndre Fischer         const Rectangle& rButtonBox,
195be6d8c25SAndre Fischer         const ::std::vector<TabBar::DeckMenuData>& rMenuData) const;
196f120fe41SAndre Fischer     void ShowDetailMenu (const ::rtl::OUString& rsMenuCommand) const;
19795a18594SAndre Fischer     ::boost::shared_ptr<PopupMenu> CreatePopupMenu (
198be6d8c25SAndre Fischer         const ::std::vector<TabBar::DeckMenuData>& rMenuData) const;
199ff12d537SAndre Fischer     DECL_LINK(OnMenuItemSelected, Menu*);
20095a18594SAndre Fischer     void BroadcastPropertyChange (void);
20122de8995SAndre Fischer 
2027a32b0c8SAndre Fischer     /** The close of the deck changes the width of the child window.
2037a32b0c8SAndre Fischer         That is only possible if there is no other docking window docked above or below the sidebar.
2047a32b0c8SAndre Fischer         Return whether the width of the child window can be modified.
2057a32b0c8SAndre Fischer     */
20613e1c3b4SAndre Fischer     bool CanModifyChildWindowWidth (void);
2077a32b0c8SAndre Fischer 
2087a32b0c8SAndre Fischer     /** Set the child window container to a new width.
2097a32b0c8SAndre Fischer         Return the old width.
2107a32b0c8SAndre Fischer     */
2117a32b0c8SAndre Fischer     sal_Int32 SetChildWindowWidth (const sal_Int32 nNewWidth);
2127a32b0c8SAndre Fischer 
2134e21436dSAndre Fischer     /** Update the icons displayed in the title bars of the deck and
2144e21436dSAndre Fischer         the panels.  This is called once when a deck is created and
2154e21436dSAndre Fischer         every time when a data change event is processed.
2164e21436dSAndre Fischer     */
2174e21436dSAndre Fischer     void UpdateTitleBarIcons (void);
21813e1c3b4SAndre Fischer 
21913e1c3b4SAndre Fischer     void UpdateDeckOpenState (void);
22013e1c3b4SAndre Fischer     void RestrictWidth (void);
22113e1c3b4SAndre Fischer     SfxSplitWindow* GetSplitWindow (void);
22213e1c3b4SAndre Fischer     void ProcessNewWidth (const sal_Int32 nNewWidth);
22313e1c3b4SAndre Fischer     void UpdateCloseIndicator (const bool bIsIndicatorVisible);
22452d13b84SAndre Fischer 
22552d13b84SAndre Fischer     /** Typically called when a panel is focused via keyboard.
22652d13b84SAndre Fischer         Tries to scroll the deck up or down to make the given panel
22752d13b84SAndre Fischer         completely visible.
22852d13b84SAndre Fischer     */
22952d13b84SAndre Fischer     void ShowPanel (const Panel& rPanel);
2307e429a12SAndre Fischer 
2317e429a12SAndre Fischer     Context GetCurrentContext (void) const;
2327e429a12SAndre Fischer 
23322de8995SAndre Fischer     virtual void SAL_CALL disposing (void);
23422de8995SAndre Fischer };
23522de8995SAndre Fischer 
23622de8995SAndre Fischer 
237ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar
23822de8995SAndre Fischer 
23922de8995SAndre Fischer #endif
240