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