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 
105ff12d537SAndre Fischer     void SwitchToDeck (
10695a18594SAndre Fischer         const ::rtl::OUString& rsDeckId);
10713e1c3b4SAndre Fischer     void OpenThenSwitchToDeck (
10813e1c3b4SAndre Fischer         const ::rtl::OUString& rsDeckId);
109ff12d537SAndre Fischer 
1107a32b0c8SAndre Fischer     /** Show only the tab bar, not the deck.
1117a32b0c8SAndre Fischer     */
11213e1c3b4SAndre Fischer     void RequestCloseDeck (void);
1137a32b0c8SAndre Fischer 
1147a32b0c8SAndre Fischer     /** Open the deck area and restore the parent window to its old width.
1157a32b0c8SAndre Fischer     */
11613e1c3b4SAndre Fischer     void RequestOpenDeck (void);
1177a32b0c8SAndre Fischer 
11865908a7eSAndre Fischer     FocusManager& GetFocusManager (void);
1197e429a12SAndre Fischer 
12022de8995SAndre Fischer private:
121f120fe41SAndre Fischer     ::boost::scoped_ptr<Deck> mpCurrentDeck;
1227a32b0c8SAndre Fischer     SidebarDockingWindow* mpParentWindow;
1237a32b0c8SAndre Fischer     ::boost::scoped_ptr<TabBar> mpTabBar;
12422de8995SAndre Fischer     cssu::Reference<css::frame::XFrame> mxFrame;
1257a32b0c8SAndre Fischer     Context maCurrentContext;
126239cbbc0SAndre Fischer     Context maRequestedContext;
12795a18594SAndre Fischer     ::rtl::OUString msCurrentDeckId;
12854eaaa32SAndre Fischer     ::rtl::OUString msCurrentDeckTitle;
12995a18594SAndre Fischer     AsynchronousCall maPropertyChangeForwarder;
130239cbbc0SAndre Fischer     AsynchronousCall maContextChangeUpdate;
13113e1c3b4SAndre Fischer 
13213e1c3b4SAndre Fischer     /** Two flags control whether the deck is displayed or if only the
13313e1c3b4SAndre Fischer         tab bar remains visible.
13413e1c3b4SAndre Fischer         The mbIsDeckOpen flag stores the current state while
13513e1c3b4SAndre Fischer         mbIsDeckRequestedOpen stores how this state should be.  User
13613e1c3b4SAndre Fischer         actions like clicking on the deck closer affect the
13713e1c3b4SAndre Fischer         mbIsDeckRequestedOpen.  Normally both flags have the same
13813e1c3b4SAndre Fischer         value.  A document being read-only can prevent the deck from opening.
13913e1c3b4SAndre Fischer     */
14013e1c3b4SAndre Fischer     ::boost::optional<bool> mbIsDeckRequestedOpen;
14113e1c3b4SAndre Fischer     ::boost::optional<bool> mbIsDeckOpen;
14213e1c3b4SAndre Fischer     bool mbCanDeckBeOpened;
14313e1c3b4SAndre Fischer 
1447a32b0c8SAndre Fischer     /** Before the deck is closed the sidebar width is saved into this variable,
1457a32b0c8SAndre Fischer         so that it can be restored when the deck is reopended.
1467a32b0c8SAndre Fischer     */
1477a32b0c8SAndre Fischer     sal_Int32 mnSavedSidebarWidth;
14865908a7eSAndre Fischer     FocusManager maFocusManager;
14913e1c3b4SAndre Fischer     cssu::Reference<css::frame::XDispatch> mxReadOnlyModeDispatch;
15013e1c3b4SAndre Fischer     bool mbIsDocumentReadOnly;
15113e1c3b4SAndre Fischer     SfxSplitWindow* mpSplitWindow;
15213e1c3b4SAndre Fischer     /** When the user moves the splitter then we remember the
15313e1c3b4SAndre Fischer         width at that time.
15413e1c3b4SAndre Fischer     */
15513e1c3b4SAndre Fischer     sal_Int32 mnWidthOnSplitterButtonDown;
15613e1c3b4SAndre Fischer     /** Control that is temporarily used as replacement for the deck
15713e1c3b4SAndre Fischer         to indicate that when the current mouse drag operation ends, the
15813e1c3b4SAndre Fischer         sidebar will only show the tab bar.
15913e1c3b4SAndre Fischer     */
16013e1c3b4SAndre Fischer     ::boost::scoped_ptr<Window> mpCloseIndicator;
16113e1c3b4SAndre Fischer 
16222de8995SAndre Fischer     DECL_LINK(WindowEventHandler, VclWindowEvent*);
163239cbbc0SAndre Fischer     /** Make maRequestedContext the current context.
164239cbbc0SAndre Fischer     */
165239cbbc0SAndre Fischer     void UpdateConfigurations (void);
166309fba80SAndre Fischer 
16702c50d82SAndre Fischer     bool ArePanelSetsEqual (
168f120fe41SAndre Fischer         const SharedPanelContainer& rCurrentPanels,
169f120fe41SAndre Fischer         const ResourceManager::PanelContextDescriptorContainer& rRequestedPanels);
170ff12d537SAndre Fischer     cssu::Reference<css::ui::XUIElement> CreateUIElement (
171ff12d537SAndre Fischer         const cssu::Reference<css::awt::XWindowPeer>& rxWindow,
17222f77e9eSAndre Fischer         const ::rtl::OUString& rsImplementationURL,
173ae13266dSAndre Fischer         const bool bWantsCanvas,
174ae13266dSAndre Fischer         const Context& rContext);
175f120fe41SAndre Fischer     SharedPanel CreatePanel (
17695a18594SAndre Fischer         const ::rtl::OUString& rsPanelId,
1777e429a12SAndre Fischer         ::Window* pParentWindow,
178ae13266dSAndre Fischer         const bool bIsInitiallyExpanded,
179ae13266dSAndre Fischer         const Context& rContext);
180ff12d537SAndre Fischer     void SwitchToDeck (
181ff12d537SAndre Fischer         const DeckDescriptor& rDeckDescriptor,
1827a32b0c8SAndre Fischer         const Context& rContext);
18395a18594SAndre Fischer     void ShowPopupMenu (
18495a18594SAndre Fischer         const Rectangle& rButtonBox,
185*be6d8c25SAndre Fischer         const ::std::vector<TabBar::DeckMenuData>& rMenuData) const;
186f120fe41SAndre Fischer     void ShowDetailMenu (const ::rtl::OUString& rsMenuCommand) const;
18795a18594SAndre Fischer     ::boost::shared_ptr<PopupMenu> CreatePopupMenu (
188*be6d8c25SAndre Fischer         const ::std::vector<TabBar::DeckMenuData>& rMenuData) const;
189ff12d537SAndre Fischer     DECL_LINK(OnMenuItemSelected, Menu*);
19095a18594SAndre Fischer     void BroadcastPropertyChange (void);
19122de8995SAndre Fischer 
1927a32b0c8SAndre Fischer     /** The close of the deck changes the width of the child window.
1937a32b0c8SAndre Fischer         That is only possible if there is no other docking window docked above or below the sidebar.
1947a32b0c8SAndre Fischer         Return whether the width of the child window can be modified.
1957a32b0c8SAndre Fischer     */
19613e1c3b4SAndre Fischer     bool CanModifyChildWindowWidth (void);
1977a32b0c8SAndre Fischer 
1987a32b0c8SAndre Fischer     /** Set the child window container to a new width.
1997a32b0c8SAndre Fischer         Return the old width.
2007a32b0c8SAndre Fischer     */
2017a32b0c8SAndre Fischer     sal_Int32 SetChildWindowWidth (const sal_Int32 nNewWidth);
2027a32b0c8SAndre Fischer 
2034e21436dSAndre Fischer     /** Update the icons displayed in the title bars of the deck and
2044e21436dSAndre Fischer         the panels.  This is called once when a deck is created and
2054e21436dSAndre Fischer         every time when a data change event is processed.
2064e21436dSAndre Fischer     */
2074e21436dSAndre Fischer     void UpdateTitleBarIcons (void);
20813e1c3b4SAndre Fischer 
20913e1c3b4SAndre Fischer     void UpdateDeckOpenState (void);
21013e1c3b4SAndre Fischer     void RestrictWidth (void);
21113e1c3b4SAndre Fischer     SfxSplitWindow* GetSplitWindow (void);
21213e1c3b4SAndre Fischer     void ProcessNewWidth (const sal_Int32 nNewWidth);
21313e1c3b4SAndre Fischer     void UpdateCloseIndicator (const bool bIsIndicatorVisible);
21452d13b84SAndre Fischer 
21552d13b84SAndre Fischer     /** Typically called when a panel is focused via keyboard.
21652d13b84SAndre Fischer         Tries to scroll the deck up or down to make the given panel
21752d13b84SAndre Fischer         completely visible.
21852d13b84SAndre Fischer     */
21952d13b84SAndre Fischer     void ShowPanel (const Panel& rPanel);
2207e429a12SAndre Fischer 
2217e429a12SAndre Fischer     Context GetCurrentContext (void) const;
2227e429a12SAndre Fischer 
22322de8995SAndre Fischer     virtual void SAL_CALL disposing (void);
22422de8995SAndre Fischer };
22522de8995SAndre Fischer 
22622de8995SAndre Fischer 
227ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar
22822de8995SAndre Fischer 
22922de8995SAndre Fischer #endif
230