xref: /trunk/main/sfx2/inc/sfx2/taskpane.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3  *
4  * Copyright 2000, 2010 Oracle and/or its affiliates.
5  *
6  * OpenOffice.org - a multi-platform office productivity suite
7  *
8  * This file is part of OpenOffice.org.
9  *
10  * OpenOffice.org is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License version 3
12  * only, as published by the Free Software Foundation.
13  *
14  * OpenOffice.org is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Lesser General Public License version 3 for more details
18  * (a copy is included in the LICENSE file that accompanied this code).
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * version 3 along with OpenOffice.org.  If not, see
22  * <http://www.openoffice.org/license.html>
23  * for a copy of the LGPLv3 License.
24  *
25  ************************************************************************/
26 
27 #ifndef SFX_TASKPANE_HXX
28 #define SFX_TASKPANE_HXX
29 
30 #include "sfx2/dllapi.h"
31 #include "sfx2/childwin.hxx"
32 #include "sfx2/titledockwin.hxx"
33 
34 #include <svtools/toolpanel/tabalignment.hxx>
35 #include <svtools/toolpanel/tabitemcontent.hxx>
36 
37 #include <boost/scoped_ptr.hpp>
38 #include <boost/optional.hpp>
39 
40 namespace svt
41 {
42     class ToolPanelDeck;
43 }
44 
45 //......................................................................................................................
46 namespace sfx2
47 {
48 //......................................................................................................................
49 
50     //==================================================================================================================
51     //= ITaskPaneToolPanelAccess
52     //==================================================================================================================
53     class SAL_NO_VTABLE ITaskPaneToolPanelAccess
54     {
55     public:
56         virtual void ActivateToolPanel( const ::rtl::OUString& i_rPanelURL ) = 0;
57     };
58 
59     //==================================================================================================================
60     //= TaskPaneWrapper
61     //==================================================================================================================
62     class SFX2_DLLPUBLIC TaskPaneWrapper    :public SfxChildWindow
63                                             ,public ITaskPaneToolPanelAccess
64     {
65     public:
66         TaskPaneWrapper(
67             Window* i_pParent,
68             sal_uInt16 i_nId,
69             SfxBindings* i_pBindings,
70             SfxChildWinInfo* i_pInfo
71         );
72 
73         SFX_DECL_CHILDWINDOW( TaskPaneWrapper );
74 
75         // ITaskPaneToolPanelAccess
76         virtual void ActivateToolPanel( const ::rtl::OUString& i_rPanelURL );
77     };
78 
79     //==================================================================================================================
80     //= IToolPanelCompare
81     //==================================================================================================================
82     class SFX2_DLLPUBLIC SAL_NO_VTABLE IToolPanelCompare
83     {
84     public:
85         /** compares to tool panel URLs
86             @return
87                 <ul>
88                 <li>-1 if the tool panel described by i_rLHS should precede the one described by i_rRHS</li>
89                 <li>0 if the two panels have no particular relative order</li>
90                 <li>1 if the tool panel described by i_rLHS should succeed the one described by i_rRHS</li>
91 
92         */
93         virtual short compareToolPanelsURLs(
94                         const ::rtl::OUString& i_rLHS,
95                         const ::rtl::OUString& i_rRHS
96                     ) const = 0;
97     };
98 
99     //==================================================================================================================
100     //= ModuleTaskPane
101     //==================================================================================================================
102     class ModuleTaskPane_Impl;
103     /** SFX-less version of a module dependent task pane, filled with tool panels as specified in the respective
104         module's configuration
105     */
106     class SFX2_DLLPUBLIC ModuleTaskPane : public Window
107     {
108     public:
109         /** creates a new instance
110             @param i_rParentWindow
111                 the parent window
112             @param i_rDocumentFrame
113                 the frame to which the task pane belongs. Will be passed to any custom tool panels created
114                 via an XUIElementFactory. Also, it is used to determine the module which the task pane is
115                 responsible for, thus controlling which tool panels are actually available.
116         */
117         ModuleTaskPane(
118             Window& i_rParentWindow,
119             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& i_rDocumentFrame
120         );
121         /** creates a new instance
122             @param i_rParentWindow
123                 the parent window
124             @param i_rDocumentFrame
125                 the frame to which the task pane belongs. Will be passed to any custom tool panels created
126                 via an XUIElementFactory. Also, it is used to determine the module which the task pane is
127                 responsible for, thus controlling which tool panels are actually available.
128             @param i_rCompare
129                 a comparator for tool panel URLs, which allows controlling the order in which the panels are
130                 added to the tool panel deck.
131         */
132         ModuleTaskPane(
133             Window& i_rParentWindow,
134             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& i_rDocumentFrame,
135             const IToolPanelCompare& i_rCompare
136         );
137         ~ModuleTaskPane();
138 
139         /** determines whether a given module has any registered tool panels
140         */
141         static bool ModuleHasToolPanels( const ::rtl::OUString& i_rModuleIdentifier );
142         /** determines whether a given module has any registered tool panels
143         */
144         static bool ModuleHasToolPanels( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& i_rDocumentFrame );
145 
146         /** provides access to the Window aspect of the PanelDeck
147 
148             Be careful with this method. For instance, you're not allowed to insert arbitrary IToolPanel implementations
149             into the deck, as the ModuleTaskPane has certain assumptions about the panel implementations. However,
150             you're allowed to remove and re-insert panels, which have originally been created by the ModuleTaskPane
151             itself.
152         */
153               ::svt::ToolPanelDeck& GetPanelDeck();
154         const ::svt::ToolPanelDeck& GetPanelDeck() const;
155 
156         /** returns the position of the panel with the given resource URL
157         */
158         ::boost::optional< size_t >
159                     GetPanelPos( const ::rtl::OUString& i_rResourceURL );
160 
161         /** returns the resource URL of the panel at the specified position
162         */
163         ::rtl::OUString
164                     GetPanelResourceURL( const size_t i_nPanelPos ) const;
165 
166         /// sets the "classical" layout of the tool panel deck, using drawers
167         void    SetDrawersLayout();
168         /// sets the new layout of the tool panel deck, using tabs
169         void    SetTabsLayout( const ::svt::TabAlignment i_eTabAlignment, const ::svt::TabItemContent i_eTabContent );
170 
171     protected:
172         // Window overridables
173         virtual void Resize();
174         virtual void GetFocus();
175 
176     private:
177         ::boost::scoped_ptr< ModuleTaskPane_Impl >  m_pImpl;
178     };
179 
180     //==================================================================================================================
181     //= TaskPaneController
182     //==================================================================================================================
183     class TaskPaneController_Impl;
184     /** is a helper class for connecting a ModuleTaskPane and a TitledDockingWindow, for clients of the ModuleTaskPane
185         which do not use the TaskPaneDockingWindow
186 
187         The controller will add a drop down menu to the docking window which contains one item for each panel in the
188         panel deck, and allows toggling their visibility.
189     */
190     class SFX2_DLLPUBLIC TaskPaneController
191     {
192     public:
193         TaskPaneController(
194             ModuleTaskPane& i_rTaskPane,
195             TitledDockingWindow& i_rDockingWindow
196         );
197         ~TaskPaneController();
198 
199         /** sets the default title to be used for the TitledDockingWindow
200 
201             When the controller switches the docking window to "tabbed" mode, then the title of the docking window
202             will contain the name of the currently active panel (since this name isn't to be seen elsewhere).
203             When the controller switches the docking window to "drawer" mode, then the title of the docking window
204             contains the default title as given here (since in this mode, the names of the panels are shown in
205             the drawers).
206         */
207         void    SetDefaultTitle( const String& i_rTitle );
208 
209         /// activates the panel with the given URL
210         void    ActivateToolPanel( const ::rtl::OUString& i_rPanelURL );
211 
212     private:
213         ::boost::scoped_ptr< TaskPaneController_Impl >  m_pImpl;
214     };
215 
216     //==================================================================================================================
217     //= TaskPaneDockingWindow
218     //==================================================================================================================
219     class TaskPaneDockingWindow :public TitledDockingWindow
220                                 ,public ITaskPaneToolPanelAccess
221     {
222     public:
223         TaskPaneDockingWindow( SfxBindings* i_pBindings, TaskPaneWrapper& i_rWrapper,
224             Window* i_pParent, WinBits i_nBits );
225 
226         // ITaskPaneToolPanelAccess
227         virtual void    ActivateToolPanel( const ::rtl::OUString& i_rPanelURL );
228 
229     protected:
230         // Window overridables
231         virtual void        GetFocus();
232 
233         // TitledDockingWindow overridables
234         virtual void onLayoutDone();
235 
236     private:
237         ModuleTaskPane      m_aTaskPane;
238         TaskPaneController  m_aPaneController;
239     };
240 
241 //......................................................................................................................
242 } // namespace sfx2
243 //......................................................................................................................
244 
245 #endif // SFX_TASKPANE_HXX
246