Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2008 by Sun Microsystems, Inc.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef __FRAMEWORK_LAYOUTMANAGER_TOOLBARLAYOUTMANAGER_HXX_
30 : : #define __FRAMEWORK_LAYOUTMANAGER_TOOLBARLAYOUTMANAGER_HXX_
31 : :
32 : : /** Attention: stl headers must(!) be included at first. Otherwhise it can make trouble
33 : : with solaris headers ...
34 : : */
35 : : #include <memory>
36 : : #include <vector>
37 : :
38 : : #include <threadhelp/threadhelpbase.hxx>
39 : : #include <threadhelp/resetableguard.hxx>
40 : : #include <threadhelp/writeguard.hxx>
41 : : #include <threadhelp/readguard.hxx>
42 : : #include <macros/generic.hxx>
43 : : #include <macros/xinterface.hxx>
44 : : #include <macros/xtypeprovider.hxx>
45 : : #include <macros/xserviceinfo.hxx>
46 : : #include <stdtypes.h>
47 : : #include <properties.h>
48 : : #include <stdtypes.h>
49 : : #include <uiconfiguration/globalsettings.hxx>
50 : : #include <uiconfiguration/windowstateconfiguration.hxx>
51 : : #include <framework/addonsoptions.hxx>
52 : : #include <uielement/uielement.hxx>
53 : : #include <helper/ilayoutnotifications.hxx>
54 : :
55 : : #include <com/sun/star/lang/XServiceInfo.hpp>
56 : : #include <com/sun/star/lang/XTypeProvider.hpp>
57 : : #include <com/sun/star/frame/XLayoutManager.hpp>
58 : : #include <com/sun/star/ui/XUIConfigurationManager.hpp>
59 : : #include <com/sun/star/ui/XUIConfiguration.hpp>
60 : : #include <com/sun/star/frame/XModuleManager.hpp>
61 : : #include <com/sun/star/frame/XFrameActionListener.hpp>
62 : : #include <com/sun/star/awt/XWindowListener.hpp>
63 : : #include <com/sun/star/util/XURLTransformer.hpp>
64 : : #include <com/sun/star/ui/XUIElementFactory.hpp>
65 : : #include <com/sun/star/ui/DockingArea.hpp>
66 : : #include <com/sun/star/awt/XTopWindow2.hpp>
67 : : #include <com/sun/star/awt/XWindow2.hpp>
68 : : #include <com/sun/star/awt/XDockableWindow.hpp>
69 : : #include <com/sun/star/awt/XDockableWindowListener.hpp>
70 : :
71 : : #include <cppuhelper/implbase3.hxx>
72 : :
73 : :
74 : : namespace framework
75 : : {
76 : :
77 : : class ToolbarLayoutManager : public ::cppu::WeakImplHelper3< ::com::sun::star::awt::XDockableWindowListener,
78 : : ::com::sun::star::ui::XUIConfigurationListener,
79 : : ::com::sun::star::awt::XWindowListener >,
80 : : private ThreadHelpBase // Struct for right initalization of mutex member! Must be first of baseclasses.
81 : : {
82 : : public:
83 : : enum { DOCKINGAREAS_COUNT = 4 };
84 : :
85 : : enum PreviewFrameDetection
86 : : {
87 : : PREVIEWFRAME_UNKNOWN,
88 : : PREVIEWFRAME_NO,
89 : : PREVIEWFRAME_YES
90 : : };
91 : :
92 : : ToolbarLayoutManager( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xSMGR,
93 : : const ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIElementFactory >& xUIElementFactory,
94 : : ILayoutNotifications* pParentLayouter );
95 : : virtual ~ToolbarLayoutManager();
96 : :
97 : : void reset();
98 : : void attach( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame,
99 : : const ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIConfigurationManager >& xModuleCfgMgr,
100 : : const ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIConfigurationManager >& xDocCfgMgr,
101 : : const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& xPersistentWindowState );
102 : :
103 : : void setParentWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >& xParentWindow );
104 : : void setDockingAreaOffsets( const ::Rectangle aOffsets );
105 : :
106 : : void resetDockingArea();
107 : :
108 : : ::com::sun::star::awt::Rectangle getDockingArea();
109 : : void setDockingArea( const ::com::sun::star::awt::Rectangle& rDockingArea );
110 : :
111 : : bool isPreviewFrame();
112 : :
113 : : // layouting
114 : : bool isLayoutDirty();
115 : : void doLayout(const ::Size& aContainerSize);
116 : :
117 : : // creation/destruction
118 : : void createStaticToolbars();
119 : : void destroyToolbars();
120 : :
121 : : bool requestToolbar( const ::rtl::OUString& rResourceURL );
122 : : bool createToolbar( const ::rtl::OUString& rResourceURL );
123 : : bool destroyToolbar( const ::rtl::OUString& rResourceURL );
124 : :
125 : : // visibility
126 : : bool showToolbar( const ::rtl::OUString& rResourceURL );
127 : : bool hideToolbar( const ::rtl::OUString& rResourceURL );
128 : :
129 : : void refreshToolbarsVisibility( bool bAutomaticToolbars );
130 : : void setFloatingToolbarsVisibility( bool bVisible );
131 : : void setVisible(bool bVisible);
132 : : bool isVisible() { return m_bVisible; }
133 : :
134 : : // docking and further functions
135 : : bool dockToolbar( const ::rtl::OUString& rResourceURL, ::com::sun::star::ui::DockingArea eDockingArea, const ::com::sun::star::awt::Point& aPos );
136 : : bool dockAllToolbars();
137 : : bool floatToolbar( const ::rtl::OUString& rResoureURL );
138 : : bool lockToolbar( const ::rtl::OUString& rResourceURL );
139 : : bool unlockToolbar( const ::rtl::OUString& rResourceURL );
140 : : void setToolbarPos( const ::rtl::OUString& rResourceURL, const ::com::sun::star::awt::Point& aPos );
141 : : void setToolbarSize( const ::rtl::OUString& rResourceURL, const ::com::sun::star::awt::Size& aSize );
142 : : void setToolbarPosSize( const ::rtl::OUString& rResourceURL, const ::com::sun::star::awt::Point& aPos, const ::com::sun::star::awt::Size& aSize );
143 : : bool isToolbarVisible( const ::rtl::OUString& rResourceURL );
144 : : bool isToolbarFloating( const ::rtl::OUString& rResourceURL );
145 : : bool isToolbarDocked( const ::rtl::OUString& rResourceURL );
146 : : bool isToolbarLocked( const ::rtl::OUString& rResourceURL );
147 : : ::com::sun::star::awt::Point getToolbarPos( const ::rtl::OUString& rResourceURL );
148 : : ::com::sun::star::awt::Size getToolbarSize( const ::rtl::OUString& rResourceURL );
149 : : ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIElement > getToolbar( const ::rtl::OUString& aName );
150 : : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIElement > > getToolbars();
151 : :
152 : : // child window notifications
153 : : long childWindowEvent( VclSimpleEvent* pEvent );
154 : :
155 : : //---------------------------------------------------------------------------------------------------------
156 : : // XInterface
157 : : //---------------------------------------------------------------------------------------------------------
158 : : virtual void SAL_CALL acquire() throw();
159 : : virtual void SAL_CALL release() throw();
160 : : virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw( ::com::sun::star::uno::RuntimeException );
161 : :
162 : : //---------------------------------------------------------------------------------------------------------
163 : : // XEventListener
164 : : //---------------------------------------------------------------------------------------------------------
165 : : virtual void SAL_CALL disposing( const css::lang::EventObject& aEvent ) throw( css::uno::RuntimeException );
166 : :
167 : : //---------------------------------------------------------------------------------------------------------
168 : : // XWindowListener
169 : : //---------------------------------------------------------------------------------------------------------
170 : : virtual void SAL_CALL windowResized( const css::awt::WindowEvent& aEvent ) throw( css::uno::RuntimeException );
171 : : virtual void SAL_CALL windowMoved( const css::awt::WindowEvent& aEvent ) throw( css::uno::RuntimeException );
172 : : virtual void SAL_CALL windowShown( const css::lang::EventObject& aEvent ) throw( css::uno::RuntimeException );
173 : : virtual void SAL_CALL windowHidden( const css::lang::EventObject& aEvent ) throw( css::uno::RuntimeException );
174 : :
175 : : //---------------------------------------------------------------------------------------------------------
176 : : // XDockableWindowListener
177 : : //---------------------------------------------------------------------------------------------------------
178 : : virtual void SAL_CALL startDocking( const ::com::sun::star::awt::DockingEvent& e ) throw (::com::sun::star::uno::RuntimeException);
179 : : virtual ::com::sun::star::awt::DockingData SAL_CALL docking( const ::com::sun::star::awt::DockingEvent& e ) throw (::com::sun::star::uno::RuntimeException);
180 : : virtual void SAL_CALL endDocking( const ::com::sun::star::awt::EndDockingEvent& e ) throw (::com::sun::star::uno::RuntimeException);
181 : : virtual sal_Bool SAL_CALL prepareToggleFloatingMode( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException);
182 : : virtual void SAL_CALL toggleFloatingMode( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException);
183 : : virtual void SAL_CALL closed( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException);
184 : : virtual void SAL_CALL endPopupMode( const ::com::sun::star::awt::EndPopupModeEvent& e ) throw (::com::sun::star::uno::RuntimeException);
185 : :
186 : : //---------------------------------------------------------------------------------------------------------
187 : : // XUIConfigurationListener
188 : : //---------------------------------------------------------------------------------------------------------
189 : : virtual void SAL_CALL elementInserted( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
190 : : virtual void SAL_CALL elementRemoved( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
191 : : virtual void SAL_CALL elementReplaced( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
192 : :
193 : : private:
194 : : enum DockingOperation
195 : : {
196 : : DOCKOP_BEFORE_COLROW,
197 : : DOCKOP_ON_COLROW,
198 : : DOCKOP_AFTER_COLROW
199 : : };
200 : :
201 : : typedef std::vector< UIElement > UIElementVector;
202 [ + - ][ + - ]: 33001 : struct SingleRowColumnWindowData
[ + - ]
203 : : {
204 [ + - ][ + - ]: 8537 : SingleRowColumnWindowData() : nVarSize( 0 ), nStaticSize( 0 ), nSpace( 0 ) {}
[ + - ]
205 : :
206 : : std::vector< rtl::OUString > aUIElementNames;
207 : : std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > > aRowColumnWindows;
208 : : std::vector< ::com::sun::star::awt::Rectangle > aRowColumnWindowSizes;
209 : : std::vector< sal_Int32 > aRowColumnSpace;
210 : : ::com::sun::star::awt::Rectangle aRowColumnRect;
211 : : sal_Int32 nVarSize;
212 : : sal_Int32 nStaticSize;
213 : : sal_Int32 nSpace;
214 : : sal_Int32 nRowColumn;
215 : : };
216 : :
217 : : //---------------------------------------------------------------------------------------------------------
218 : : // internal helper methods
219 : : //---------------------------------------------------------------------------------------------------------
220 : : bool implts_isParentWindowVisible() const;
221 : : ::Rectangle implts_calcDockingArea();
222 : : void implts_sortUIElements();
223 : : void implts_reparentToolbars();
224 : : rtl::OUString implts_generateGenericAddonToolbarTitle( sal_Int32 nNumber ) const;
225 : : void implts_setElementData( UIElement& rUIElement, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDockableWindow >& rDockWindow );
226 : : void implts_destroyDockingAreaWindows();
227 : :
228 : : //---------------------------------------------------------------------------------------------------------
229 : : // layout methods
230 : : //---------------------------------------------------------------------------------------------------------
231 : : void implts_setDockingAreaWindowSizes( const ::com::sun::star::awt::Rectangle& rBorderSpace );
232 : : ::com::sun::star::awt::Point implts_findNextCascadeFloatingPos();
233 : : void implts_renumberRowColumnData( ::com::sun::star::ui::DockingArea eDockingArea, DockingOperation eDockingOperation, const UIElement& rUIElement );
234 : : void implts_calcWindowPosSizeOnSingleRowColumn( sal_Int32 nDockingArea,
235 : : sal_Int32 nOffset,
236 : : SingleRowColumnWindowData& rRowColumnWindowData,
237 : : const ::Size& rContainerSize );
238 : : void implts_setLayoutDirty();
239 : : void implts_setLayoutInProgress( bool bInProgress = true );
240 : : bool implts_isLayoutInProgress() const { return m_bLayoutInProgress; }
241 : :
242 : : //---------------------------------------------------------------------------------------------------------
243 : : // lookup/container methods
244 : : //---------------------------------------------------------------------------------------------------------
245 : : UIElement implts_findToolbar( const rtl::OUString& aName );
246 : : UIElement implts_findToolbar( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xToolbar );
247 : : UIElement& impl_findToolbar( const rtl::OUString& aName );
248 : : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > implts_getXWindow( const ::rtl::OUString& aName );
249 : : Window* implts_getWindow( const ::rtl::OUString& aName );
250 : : bool implts_insertToolbar( const UIElement& rUIElement );
251 : : void implts_setToolbar( const UIElement& rUIElement );
252 : : ::Size implts_getTopBottomDockingAreaSizes();
253 : : void implts_getUIElementVectorCopy( UIElementVector& rCopy );
254 : :
255 : : //---------------------------------------------------------------------------------------------------------
256 : : // internal docking methods
257 : : //---------------------------------------------------------------------------------------------------------
258 : : ::Rectangle implts_calcHotZoneRect( const ::Rectangle& rRect, sal_Int32 nHotZoneOffset );
259 : : void implts_calcDockingPosSize( UIElement& aUIElement, DockingOperation& eDockOperation, ::Rectangle& rTrackingRect, const Point& rMousePos );
260 : : DockingOperation implts_determineDockingOperation( ::com::sun::star::ui::DockingArea DockingArea, const ::Rectangle& rRowColRect, const Point& rMousePos );
261 : : ::Rectangle implts_getWindowRectFromRowColumn( ::com::sun::star::ui::DockingArea DockingArea, const SingleRowColumnWindowData& rRowColumnWindowData, const ::Point& rMousePos, const rtl::OUString& rExcludeElementName );
262 : : ::Rectangle implts_determineFrontDockingRect( ::com::sun::star::ui::DockingArea eDockingArea,
263 : : sal_Int32 nRowCol,
264 : : const ::Rectangle& rDockedElementRect,
265 : : const ::rtl::OUString& rMovedElementName,
266 : : const ::Rectangle& rMovedElementRect );
267 : : ::Rectangle implts_calcTrackingAndElementRect( ::com::sun::star::ui::DockingArea eDockingArea,
268 : : sal_Int32 nRowCol,
269 : : UIElement& rUIElement,
270 : : const ::Rectangle& rTrackingRect,
271 : : const ::Rectangle& rRowColumnRect,
272 : : const ::Size& rContainerWinSize );
273 : :
274 : : void implts_getDockingAreaElementInfos( ::com::sun::star::ui::DockingArea DockingArea, std::vector< SingleRowColumnWindowData >& rRowColumnsWindowData );
275 : : void implts_getDockingAreaElementInfoOnSingleRowCol( ::com::sun::star::ui::DockingArea, sal_Int32 nRowCol, SingleRowColumnWindowData& rRowColumnWindowData );
276 : : void implts_findNextDockingPos( ::com::sun::star::ui::DockingArea DockingArea, const ::Size& aUIElementSize, ::com::sun::star::awt::Point& rVirtualPos, ::Point& rPixelPos );
277 : : void implts_setTrackingRect( ::com::sun::star::ui::DockingArea eDockingArea, const ::Point& rMousePos, ::Rectangle& rTrackingRect );
278 : :
279 : : //---------------------------------------------------------------------------------------------------------
280 : : // creation methods
281 : : //---------------------------------------------------------------------------------------------------------
282 : : void implts_createAddonsToolBars();
283 : : void implts_createCustomToolBars();
284 : : void implts_createNonContextSensitiveToolBars();
285 : : void implts_createCustomToolBars( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >& aCustomTbxSeq );
286 : : void implts_createCustomToolBar( const rtl::OUString& aTbxResName, const rtl::OUString& aTitle );
287 : : void implts_createToolBar( const ::rtl::OUString& aName, bool& bNotify, ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIElement >& rUIElement );
288 : : css::uno::Reference< css::ui::XUIElement > implts_createElement( const ::rtl::OUString& aName );
289 : : void implts_setToolbarCreation( bool bStart = true );
290 : : bool implts_isToolbarCreationActive();
291 : :
292 : : //---------------------------------------------------------------------------------------------------------
293 : : // persistence methods
294 : : //---------------------------------------------------------------------------------------------------------
295 : : sal_Bool implts_readWindowStateData( const rtl::OUString& aName, UIElement& rElementData );
296 : : void implts_writeWindowStateData( const UIElement& rElementData );
297 : :
298 : : //---------------------------------------------------------------------------------------------------------
299 : : // members
300 : : //---------------------------------------------------------------------------------------------------------
301 : : css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR;
302 : : css::uno::Reference< css::frame::XFrame > m_xFrame;
303 : : css::uno::Reference< css::awt::XWindow2 > m_xContainerWindow;
304 : : css::uno::Reference< css::awt::XWindow > m_xDockAreaWindows[DOCKINGAREAS_COUNT];
305 : : css::uno::Reference< ::com::sun::star::ui::XUIElementFactory > m_xUIElementFactoryManager;
306 : : css::uno::Reference< ::com::sun::star::ui::XUIConfigurationManager > m_xModuleCfgMgr;
307 : : css::uno::Reference< ::com::sun::star::ui::XUIConfigurationManager > m_xDocCfgMgr;
308 : : css::uno::Reference< ::com::sun::star::awt::XToolkit > m_xToolkit;
309 : : css::uno::Reference< ::com::sun::star::container::XNameAccess > m_xPersistentWindowState;
310 : : ILayoutNotifications* m_pParentLayouter;
311 : :
312 : : UIElementVector m_aUIElements;
313 : : UIElement m_aDockUIElement;
314 : : Point m_aStartDockMousePos;
315 : : Rectangle m_aDockingArea;
316 : : Rectangle m_aDockingAreaOffsets;
317 : : DockingOperation m_eDockOperation;
318 : : PreviewFrameDetection m_ePreviewDetection;
319 : :
320 : : std::auto_ptr< AddonsOptions > m_pAddonOptions;
321 : : std::auto_ptr< GlobalSettings > m_pGlobalSettings;
322 : :
323 : : bool m_bComponentAttached;
324 : : bool m_bLayoutDirty;
325 : : bool m_bStoreWindowState;
326 : : bool m_bGlobalSettings;
327 : : bool m_bDockingInProgress;
328 : : bool m_bVisible;
329 : : bool m_bLayoutInProgress;
330 : : bool m_bToolbarCreation;
331 : :
332 : : ::rtl::OUString m_aFullAddonTbxPrefix;
333 : : ::rtl::OUString m_aCustomTbxPrefix;
334 : : ::rtl::OUString m_aCustomizeCmd;
335 : : ::rtl::OUString m_aToolbarTypeString;
336 : : ::rtl::OUString m_aModuleIdentifier;
337 : : };
338 : :
339 : : } // namespace framework
340 : :
341 : : #endif // __FRAMEWORK_LAYOUTMANAGER_TOOLBARLAYOUTMANAGER_HXX_
342 : :
343 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|