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>
45*3091fa8aSAndre Fischer #include <cppuhelper/weakref.hxx>
46*3091fa8aSAndre Fischer #include <comphelper/stl_types.hxx>
47*3091fa8aSAndre Fischer 
4822de8995SAndre Fischer 
4922de8995SAndre Fischer namespace css = ::com::sun::star;
5022de8995SAndre Fischer namespace cssu = ::com::sun::star::uno;
5122de8995SAndre Fischer 
527a32b0c8SAndre Fischer 
5322de8995SAndre Fischer namespace
5422de8995SAndre Fischer {
5513e1c3b4SAndre Fischer     typedef ::cppu::WeakComponentImplHelper4 <
56b9e67834SAndre Fischer         css::ui::XContextChangeEventListener,
577a32b0c8SAndre Fischer         css::beans::XPropertyChangeListener,
5813e1c3b4SAndre Fischer         css::ui::XSidebar,
5913e1c3b4SAndre Fischer         css::frame::XStatusListener
6022de8995SAndre Fischer         > SidebarControllerInterfaceBase;
6122de8995SAndre Fischer }
6222de8995SAndre Fischer 
6313e1c3b4SAndre Fischer class SfxSplitWindow;
6413e1c3b4SAndre Fischer class FixedBitmap;
6513e1c3b4SAndre Fischer 
66ff12d537SAndre Fischer namespace sfx2 { namespace sidebar {
6722de8995SAndre Fischer 
6895a18594SAndre Fischer class ContentPanelDescriptor;
6995a18594SAndre Fischer class Deck;
7095a18594SAndre Fischer class DeckDescriptor;
717a32b0c8SAndre Fischer class SidebarDockingWindow;
7222de8995SAndre Fischer class TabBar;
73ff12d537SAndre Fischer class TabBarConfiguration;
7422de8995SAndre Fischer 
7522de8995SAndre Fischer class SidebarController
7622de8995SAndre Fischer     : private ::boost::noncopyable,
7722de8995SAndre Fischer       private ::cppu::BaseMutex,
7822de8995SAndre Fischer       public SidebarControllerInterfaceBase
7922de8995SAndre Fischer {
8022de8995SAndre Fischer public:
8122de8995SAndre Fischer     SidebarController(
827a32b0c8SAndre Fischer         SidebarDockingWindow* pParentWindow,
8322de8995SAndre Fischer         const cssu::Reference<css::frame::XFrame>& rxFrame);
8422de8995SAndre Fischer     virtual ~SidebarController (void);
8522de8995SAndre Fischer 
86*3091fa8aSAndre Fischer     /** Return the SidebarController object that is associated with
87*3091fa8aSAndre Fischer         the given XFrame.
88*3091fa8aSAndre Fischer         @return
89*3091fa8aSAndre Fischer             When there is no SidebarController object for the given
90*3091fa8aSAndre Fischer             XFrame then <NULL/> is returned.
91*3091fa8aSAndre Fischer     */
92*3091fa8aSAndre Fischer     static SidebarController* GetSidebarControllerForFrame (
93*3091fa8aSAndre Fischer         const cssu::Reference<css::frame::XFrame>& rxFrame);
94*3091fa8aSAndre Fischer 
95b9e67834SAndre Fischer     // ui::XContextChangeEventListener
9622de8995SAndre Fischer     virtual void SAL_CALL notifyContextChangeEvent (const css::ui::ContextChangeEventObject& rEvent)
9722de8995SAndre Fischer         throw(cssu::RuntimeException);
9822de8995SAndre Fischer 
99b9e67834SAndre Fischer     // XEventListener
10022de8995SAndre Fischer     virtual void SAL_CALL disposing (const css::lang::EventObject& rEventObject)
10122de8995SAndre Fischer         throw(cssu::RuntimeException);
10222de8995SAndre Fischer 
103b9e67834SAndre Fischer     // beans::XPropertyChangeListener
104b9e67834SAndre Fischer     virtual void SAL_CALL propertyChange (const css::beans::PropertyChangeEvent& rEvent)
105b9e67834SAndre Fischer         throw(cssu::RuntimeException);
1067a32b0c8SAndre Fischer 
10713e1c3b4SAndre Fischer     // frame::XStatusListener
10813e1c3b4SAndre Fischer     virtual void SAL_CALL statusChanged (const css::frame::FeatureStateEvent& rEvent)
10913e1c3b4SAndre Fischer         throw(cssu::RuntimeException);
11013e1c3b4SAndre Fischer 
1117a32b0c8SAndre Fischer     // ui::XSidebar
1127a32b0c8SAndre Fischer     virtual void SAL_CALL requestLayout (void)
1137a32b0c8SAndre Fischer         throw(cssu::RuntimeException);
114b9e67834SAndre Fischer 
11522de8995SAndre Fischer     void NotifyResize (void);
11622de8995SAndre Fischer 
117a5297dafSAndre Fischer     /** In some situations it is necessary to force an update of the
118a5297dafSAndre Fischer         current deck and its panels.  One reason is a change of the
119a5297dafSAndre Fischer         view scale.  Some panels can handle this only when
120a5297dafSAndre Fischer         constructed.  In this case we have to a context change and
121a5297dafSAndre Fischer         also force that all panels are destroyed and created new.
122a5297dafSAndre Fischer     */
123a5297dafSAndre Fischer     const static sal_Int32 SwitchFlag_NoForce = 0x00;
124a5297dafSAndre Fischer     const static sal_Int32 SwitchFlag_ForceSwitch = 0x01;
125a5297dafSAndre Fischer     const static sal_Int32 SwitchFlag_ForceNewDeck = 0x02;
126a5297dafSAndre Fischer     const static sal_Int32 SwitchFlag_ForceNewPanels = 0x02;
127a5297dafSAndre Fischer 
128*3091fa8aSAndre Fischer     void RequestSwitchToDeck (
12995a18594SAndre Fischer         const ::rtl::OUString& rsDeckId);
13013e1c3b4SAndre Fischer     void OpenThenSwitchToDeck (
13113e1c3b4SAndre Fischer         const ::rtl::OUString& rsDeckId);
132ff12d537SAndre Fischer 
1337a32b0c8SAndre Fischer     /** Show only the tab bar, not the deck.
1347a32b0c8SAndre Fischer     */
13513e1c3b4SAndre Fischer     void RequestCloseDeck (void);
1367a32b0c8SAndre Fischer 
1377a32b0c8SAndre Fischer     /** Open the deck area and restore the parent window to its old width.
1387a32b0c8SAndre Fischer     */
13913e1c3b4SAndre Fischer     void RequestOpenDeck (void);
1407a32b0c8SAndre Fischer 
14165908a7eSAndre Fischer     FocusManager& GetFocusManager (void);
1427e429a12SAndre Fischer 
14322de8995SAndre Fischer private:
144*3091fa8aSAndre Fischer     typedef ::std::map<
145*3091fa8aSAndre Fischer         const cssu::Reference<css::frame::XFrame>,
146*3091fa8aSAndre Fischer         cssu::WeakReference<SidebarController>
147*3091fa8aSAndre Fischer     > SidebarControllerContainer;
148*3091fa8aSAndre Fischer     static SidebarControllerContainer maSidebarControllerContainer;
149*3091fa8aSAndre Fischer 
150f120fe41SAndre Fischer     ::boost::scoped_ptr<Deck> mpCurrentDeck;
1517a32b0c8SAndre Fischer     SidebarDockingWindow* mpParentWindow;
1527a32b0c8SAndre Fischer     ::boost::scoped_ptr<TabBar> mpTabBar;
15322de8995SAndre Fischer     cssu::Reference<css::frame::XFrame> mxFrame;
1547a32b0c8SAndre Fischer     Context maCurrentContext;
155239cbbc0SAndre Fischer     Context maRequestedContext;
156a5297dafSAndre Fischer     /// Use a combination of SwitchFlag_* as value.
157a5297dafSAndre Fischer     sal_Int32 mnRequestedForceFlags;
15895a18594SAndre Fischer     ::rtl::OUString msCurrentDeckId;
15954eaaa32SAndre Fischer     ::rtl::OUString msCurrentDeckTitle;
16095a18594SAndre Fischer     AsynchronousCall maPropertyChangeForwarder;
161239cbbc0SAndre Fischer     AsynchronousCall maContextChangeUpdate;
162*3091fa8aSAndre Fischer     AsynchronousCall maAsynchronousDeckSwitch;
16313e1c3b4SAndre Fischer 
16413e1c3b4SAndre Fischer     /** Two flags control whether the deck is displayed or if only the
16513e1c3b4SAndre Fischer         tab bar remains visible.
16613e1c3b4SAndre Fischer         The mbIsDeckOpen flag stores the current state while
16713e1c3b4SAndre Fischer         mbIsDeckRequestedOpen stores how this state should be.  User
16813e1c3b4SAndre Fischer         actions like clicking on the deck closer affect the
16913e1c3b4SAndre Fischer         mbIsDeckRequestedOpen.  Normally both flags have the same
17013e1c3b4SAndre Fischer         value.  A document being read-only can prevent the deck from opening.
17113e1c3b4SAndre Fischer     */
17213e1c3b4SAndre Fischer     ::boost::optional<bool> mbIsDeckRequestedOpen;
17313e1c3b4SAndre Fischer     ::boost::optional<bool> mbIsDeckOpen;
17413e1c3b4SAndre Fischer     bool mbCanDeckBeOpened;
17513e1c3b4SAndre Fischer 
1767a32b0c8SAndre Fischer     /** Before the deck is closed the sidebar width is saved into this variable,
1777a32b0c8SAndre Fischer         so that it can be restored when the deck is reopended.
1787a32b0c8SAndre Fischer     */
1797a32b0c8SAndre Fischer     sal_Int32 mnSavedSidebarWidth;
18065908a7eSAndre Fischer     FocusManager maFocusManager;
18113e1c3b4SAndre Fischer     cssu::Reference<css::frame::XDispatch> mxReadOnlyModeDispatch;
18213e1c3b4SAndre Fischer     bool mbIsDocumentReadOnly;
18313e1c3b4SAndre Fischer     SfxSplitWindow* mpSplitWindow;
18413e1c3b4SAndre Fischer     /** When the user moves the splitter then we remember the
18513e1c3b4SAndre Fischer         width at that time.
18613e1c3b4SAndre Fischer     */
18713e1c3b4SAndre Fischer     sal_Int32 mnWidthOnSplitterButtonDown;
18813e1c3b4SAndre Fischer     /** Control that is temporarily used as replacement for the deck
18913e1c3b4SAndre Fischer         to indicate that when the current mouse drag operation ends, the
19013e1c3b4SAndre Fischer         sidebar will only show the tab bar.
19113e1c3b4SAndre Fischer     */
19213e1c3b4SAndre Fischer     ::boost::scoped_ptr<Window> mpCloseIndicator;
19313e1c3b4SAndre Fischer 
19422de8995SAndre Fischer     DECL_LINK(WindowEventHandler, VclWindowEvent*);
195239cbbc0SAndre Fischer     /** Make maRequestedContext the current context.
196239cbbc0SAndre Fischer     */
197239cbbc0SAndre Fischer     void UpdateConfigurations (void);
198309fba80SAndre Fischer 
199ff12d537SAndre Fischer     cssu::Reference<css::ui::XUIElement> CreateUIElement (
200ff12d537SAndre Fischer         const cssu::Reference<css::awt::XWindowPeer>& rxWindow,
20122f77e9eSAndre Fischer         const ::rtl::OUString& rsImplementationURL,
202ae13266dSAndre Fischer         const bool bWantsCanvas,
203ae13266dSAndre Fischer         const Context& rContext);
204f120fe41SAndre Fischer     SharedPanel CreatePanel (
20595a18594SAndre Fischer         const ::rtl::OUString& rsPanelId,
2067e429a12SAndre Fischer         ::Window* pParentWindow,
207ae13266dSAndre Fischer         const bool bIsInitiallyExpanded,
208ae13266dSAndre Fischer         const Context& rContext);
209*3091fa8aSAndre Fischer     void SwitchToDeck (
210*3091fa8aSAndre Fischer         const ::rtl::OUString& rsDeckId);
211ff12d537SAndre Fischer     void SwitchToDeck (
212ff12d537SAndre Fischer         const DeckDescriptor& rDeckDescriptor,
2137a32b0c8SAndre Fischer         const Context& rContext);
21495a18594SAndre Fischer     void ShowPopupMenu (
21595a18594SAndre Fischer         const Rectangle& rButtonBox,
216be6d8c25SAndre Fischer         const ::std::vector<TabBar::DeckMenuData>& rMenuData) const;
217f120fe41SAndre Fischer     void ShowDetailMenu (const ::rtl::OUString& rsMenuCommand) const;
21895a18594SAndre Fischer     ::boost::shared_ptr<PopupMenu> CreatePopupMenu (
219be6d8c25SAndre Fischer         const ::std::vector<TabBar::DeckMenuData>& rMenuData) const;
220ff12d537SAndre Fischer     DECL_LINK(OnMenuItemSelected, Menu*);
22195a18594SAndre Fischer     void BroadcastPropertyChange (void);
22222de8995SAndre Fischer 
2237a32b0c8SAndre Fischer     /** The close of the deck changes the width of the child window.
2247a32b0c8SAndre Fischer         That is only possible if there is no other docking window docked above or below the sidebar.
2257a32b0c8SAndre Fischer         Return whether the width of the child window can be modified.
2267a32b0c8SAndre Fischer     */
22713e1c3b4SAndre Fischer     bool CanModifyChildWindowWidth (void);
2287a32b0c8SAndre Fischer 
2297a32b0c8SAndre Fischer     /** Set the child window container to a new width.
2307a32b0c8SAndre Fischer         Return the old width.
2317a32b0c8SAndre Fischer     */
2327a32b0c8SAndre Fischer     sal_Int32 SetChildWindowWidth (const sal_Int32 nNewWidth);
2337a32b0c8SAndre Fischer 
2344e21436dSAndre Fischer     /** Update the icons displayed in the title bars of the deck and
2354e21436dSAndre Fischer         the panels.  This is called once when a deck is created and
2364e21436dSAndre Fischer         every time when a data change event is processed.
2374e21436dSAndre Fischer     */
2384e21436dSAndre Fischer     void UpdateTitleBarIcons (void);
23913e1c3b4SAndre Fischer 
24013e1c3b4SAndre Fischer     void UpdateDeckOpenState (void);
24113e1c3b4SAndre Fischer     void RestrictWidth (void);
24213e1c3b4SAndre Fischer     SfxSplitWindow* GetSplitWindow (void);
24313e1c3b4SAndre Fischer     void ProcessNewWidth (const sal_Int32 nNewWidth);
24413e1c3b4SAndre Fischer     void UpdateCloseIndicator (const bool bIsIndicatorVisible);
24552d13b84SAndre Fischer 
24652d13b84SAndre Fischer     /** Typically called when a panel is focused via keyboard.
24752d13b84SAndre Fischer         Tries to scroll the deck up or down to make the given panel
24852d13b84SAndre Fischer         completely visible.
24952d13b84SAndre Fischer     */
25052d13b84SAndre Fischer     void ShowPanel (const Panel& rPanel);
2517e429a12SAndre Fischer 
2527e429a12SAndre Fischer     Context GetCurrentContext (void) const;
2537e429a12SAndre Fischer 
25422de8995SAndre Fischer     virtual void SAL_CALL disposing (void);
25522de8995SAndre Fischer };
25622de8995SAndre Fischer 
25722de8995SAndre Fischer 
258ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar
25922de8995SAndre Fischer 
26022de8995SAndre Fischer #endif
261