xref: /aoo41x/main/sd/source/ui/sidebar/LayoutMenu.hxx (revision 02c50d82)
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 SD_SIDEBAR_LAYOUT_MENU_HXX
23 #define SD_SIDEBAR_LAYOUT_MENU_HXX
24 
25 #include "IDisposable.hxx"
26 #include "ISidebarReceiver.hxx"
27 #include <sfx2/sidebar/ILayoutableWindow.hxx>
28 
29 #include "glob.hxx"
30 #include "pres.hxx"
31 
32 #include <vcl/ctrl.hxx>
33 #include <svtools/valueset.hxx>
34 #include <svtools/transfer.hxx>
35 #include <sfx2/shell.hxx>
36 
37 #include <com/sun/star/frame/XStatusListener.hpp>
38 #include <com/sun/star/ui/XSidebar.hpp>
39 
40 
41 class SfxModule;
42 
43 namespace css = ::com::sun::star;
44 namespace cssu = ::com::sun::star::uno;
45 
46 namespace sd {
47 class DrawDocShell;
48 class PaneManagerEvent;
49 class ViewShellBase;
50 }
51 
52 
53 namespace sd { namespace tools {
54 class EventMultiplexerEvent;
55 } }
56 
57 
58 namespace sd { namespace sidebar {
59 
60 class ControlFactory;
61 class SidebarViewShell;
62 class SidebarShellManager;
63 
64 
65 class LayoutMenu
66     : public ValueSet,
67       public DragSourceHelper,
68       public DropTargetHelper,
69       public sfx2::sidebar::ILayoutableWindow
70 {
71 public:
72     /** Create a new layout menu.  Depending on the given flag it
73         displays its own scroll bar or lets a surrounding window
74         handle that.
75         @param i_pParent
76             the parent node in the control tree
77         @param i_rPanelViewShell
78             the view shell of the task pane.
79     */
80     LayoutMenu (
81         ::Window* pParent,
82         ViewShellBase& rViewShellBase,
83         const cssu::Reference<css::ui::XSidebar>& rxSidebar);
84     virtual ~LayoutMenu (void);
85 
86     virtual void Dispose (void);
87 
88     /** Return a numerical value representing the currently selected
89         layout.
90     */
91     AutoLayout GetSelectedAutoLayout (void);
92 
93     Size GetPreferredSize (void);
94     sal_Int32 GetPreferredWidth (sal_Int32 nHeight);
95     sal_Int32 GetMinimumWidth (void);
96 
97     // From ILayoutableWindow
98     virtual css::ui::LayoutSize GetHeightForWidth (const sal_Int32 nWidth);
99 
100     // From ::Window
101 	virtual void Paint (const Rectangle& rRect);
102     virtual void Resize (void);
103 
104     /** Show a context menu when the right mouse button is pressed.
105     */
106     virtual void MouseButtonDown (const MouseEvent& rEvent);
107 
108     /** The LayoutMenu does not support some main views.  In this case the
109         LayoutMenu is disabled.  This state is updated in this method.
110         @param eMode
111             On some occasions the edit mode is being switched when this
112             method is called can not (yet) be reliably detected.  Luckily,
113             in these cases the new value is provided by some broadcaster.
114             On other occasions the edit mode is not modified and is also not
115             provided.  Therefore the Unknown value.
116     */
117     enum MasterMode { MM_NORMAL, MM_MASTER, MM_UNKNOWN };
118     void UpdateEnabledState (const MasterMode eMode);
119 
120     /** Call this method when the set of displayed layouts is not up-to-date
121         anymore.  It will re-assemple this set according to the current
122         settings.
123     */
124     void InvalidateContent (void);
125 
126 	// DragSourceHelper
127 	virtual void StartDrag (sal_Int8 nAction, const Point& rPosPixel);
128 
129 	// DropTargetHelper
130 	virtual sal_Int8 AcceptDrop (const AcceptDropEvent& rEvent);
131 	virtual sal_Int8 ExecuteDrop (const ExecuteDropEvent& rEvent);
132 
133     /** The context menu is requested over this Command() method.
134     */
135 	virtual void Command (const CommandEvent& rEvent);
136 
137     /** Call Fill() when switching to or from high contrast mode so that the
138         correct set of icons is displayed.
139     */
140     virtual void DataChanged (const DataChangedEvent& rEvent);
141 
142 	using Window::GetWindow;
143 	using ValueSet::StartDrag;
144 
145 private:
146     ViewShellBase& mrBase;
147 
148     /** Do we use our own scroll bar or is viewport handling done by
149         our parent?
150     */
151     bool mbUseOwnScrollBar;
152 
153     /** If we are asked for the preferred window size, then use this
154         many columns for the calculation.
155     */
156     const int mnPreferredColumnCount;
157     cssu::Reference<css::frame::XStatusListener> mxListener;
158     bool mbSelectionUpdatePending;
159     bool mbIsMainViewChangePending;
160     cssu::Reference<css::ui::XSidebar> mxSidebar;
161     bool mbIsDisposed;
162 
163     /** Calculate the number of displayed rows.  This depends on the given
164         item size, the given number of columns, and the size of the
165         control.  Note that this is not the number of rows managed by the
166         valueset.  This number may be larger.  In that case a vertical
167         scroll bar is displayed.
168     */
169     int CalculateRowCount (const Size& rItemSize, int nColumnCount);
170 
171     /** Fill the value set with the layouts that are applicable to the
172         current main view shell.
173     */
174     void Fill (void);
175 
176     /** Remove all items from the value set.
177     */
178     void Clear (void);
179 
180     /** Assign the given layout to all selected slides of a slide sorter.
181         If no slide sorter is active then this call is ignored.  The slide
182         sorter in the center pane is preferred if the choice exists.
183     */
184     void AssignLayoutToSelectedSlides (AutoLayout aLayout);
185 
186     /** Insert a new page with the given layout.  The page is inserted via
187         the main view shell, i.e. its SID_INSERTPAGE slot is called.  It it
188         does not support this slot then inserting a new page does not take
189         place.  The new page is inserted after the currently active one (the
190         one returned by ViewShell::GetActualPage().)
191     */
192     void InsertPageWithLayout (AutoLayout aLayout);
193 
194     /** Create a request structure that can be used with the SID_INSERTPAGE
195         and SID_MODIFYPAGE slots.  The parameters are set so that the given
196         layout is assigned to the current page of the main view shell.
197         @param nSlotId
198             Supported slots are SID_INSERTPAGE and SID_MODIFYPAGE.
199         @param aLayout
200             Layout of the page to insert or to assign.
201     */
202     SfxRequest CreateRequest (
203         sal_uInt16 nSlotId,
204         AutoLayout aLayout);
205 
206     /** Select the layout that is used by the current page.
207     */
208     void UpdateSelection (void);
209 
210     // internal ctor
211     void    implConstruct( DrawDocShell& rDocumentShell );
212 
213     /** When clicked then set the current page of the view in the center pane.
214     */
215     DECL_LINK(ClickHandler, ValueSet*);
216     DECL_LINK(RightClickHandler, MouseEvent*);
217     DECL_LINK(StateChangeHandler, ::rtl::OUString*);
218     DECL_LINK(EventMultiplexerListener, ::sd::tools::EventMultiplexerEvent*);
219     DECL_LINK(WindowEventHandler, VclWindowEvent*);
220     DECL_LINK(OnMenuItemSelected, Menu*);
221 };
222 
223 } } // end of namespace ::sd::toolpanel
224 
225 #endif
226