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 INCLUDED_FRAMEWORK_SOURCE_LAYOUTMANAGER_TOOLBARLAYOUTMANAGER_HXX
21 : #define INCLUDED_FRAMEWORK_SOURCE_LAYOUTMANAGER_TOOLBARLAYOUTMANAGER_HXX
22 :
23 : /** Attention: stl headers must(!) be included at first. Otherwise it can make trouble
24 : with solaris headers ...
25 : */
26 : #include <vector>
27 :
28 : #include <macros/generic.hxx>
29 : #include <macros/xinterface.hxx>
30 : #include <macros/xtypeprovider.hxx>
31 : #include <macros/xserviceinfo.hxx>
32 : #include <stdtypes.h>
33 : #include <properties.h>
34 : #include <uiconfiguration/globalsettings.hxx>
35 : #include <framework/addonsoptions.hxx>
36 : #include <uielement/uielement.hxx>
37 : #include <helper/ilayoutnotifications.hxx>
38 :
39 : #include <com/sun/star/lang/XServiceInfo.hpp>
40 : #include <com/sun/star/lang/XTypeProvider.hpp>
41 : #include <com/sun/star/frame/XLayoutManager.hpp>
42 : #include <com/sun/star/ui/XUIConfigurationManager.hpp>
43 : #include <com/sun/star/ui/XUIConfiguration.hpp>
44 : #include <com/sun/star/frame/XModuleManager.hpp>
45 : #include <com/sun/star/frame/XFrameActionListener.hpp>
46 : #include <com/sun/star/awt/XWindowListener.hpp>
47 : #include <com/sun/star/util/XURLTransformer.hpp>
48 : #include <com/sun/star/ui/XUIElementFactory.hpp>
49 : #include <com/sun/star/ui/DockingArea.hpp>
50 : #include <com/sun/star/awt/XToolkit2.hpp>
51 : #include <com/sun/star/awt/XTopWindow2.hpp>
52 : #include <com/sun/star/awt/XWindow2.hpp>
53 : #include <com/sun/star/awt/XDockableWindow.hpp>
54 : #include <com/sun/star/awt/XDockableWindowListener.hpp>
55 :
56 : #include <cppuhelper/implbase3.hxx>
57 :
58 : namespace framework
59 : {
60 :
61 : class ToolbarLayoutManager : public ::cppu::WeakImplHelper3< ::com::sun::star::awt::XDockableWindowListener,
62 : ::com::sun::star::ui::XUIConfigurationListener,
63 : ::com::sun::star::awt::XWindowListener >
64 : {
65 : public:
66 : enum { DOCKINGAREAS_COUNT = 4 };
67 :
68 : enum PreviewFrameDetection
69 : {
70 : PREVIEWFRAME_UNKNOWN,
71 : PREVIEWFRAME_NO,
72 : PREVIEWFRAME_YES
73 : };
74 :
75 : ToolbarLayoutManager( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
76 : const ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIElementFactory >& xUIElementFactory,
77 : ILayoutNotifications* pParentLayouter );
78 : virtual ~ToolbarLayoutManager();
79 :
80 : void reset();
81 : void attach( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame,
82 : const ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIConfigurationManager >& xModuleCfgMgr,
83 : const ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIConfigurationManager >& xDocCfgMgr,
84 : const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& xPersistentWindowState );
85 :
86 : void setParentWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >& xParentWindow );
87 : void setDockingAreaOffsets(const ::Rectangle& rOffsets);
88 :
89 : void resetDockingArea();
90 :
91 : ::com::sun::star::awt::Rectangle getDockingArea();
92 : void setDockingArea( const ::com::sun::star::awt::Rectangle& rDockingArea );
93 :
94 : bool isPreviewFrame();
95 :
96 : // layouting
97 21616 : bool isLayoutDirty() { return m_bLayoutDirty;}
98 : void doLayout(const ::Size& aContainerSize);
99 :
100 : // creation/destruction
101 : void createStaticToolbars();
102 : void destroyToolbars();
103 :
104 : bool requestToolbar( const OUString& rResourceURL );
105 : bool createToolbar( const OUString& rResourceURL );
106 : bool destroyToolbar( const OUString& rResourceURL );
107 :
108 : // visibility
109 : bool showToolbar( const OUString& rResourceURL );
110 : bool hideToolbar( const OUString& rResourceURL );
111 :
112 : void refreshToolbarsVisibility( bool bAutomaticToolbars );
113 : void setFloatingToolbarsVisibility( bool bVisible );
114 : void setVisible(bool bVisible);
115 : bool isVisible() { return m_bVisible; }
116 :
117 : // docking and further functions
118 : bool dockToolbar( const OUString& rResourceURL, ::com::sun::star::ui::DockingArea eDockingArea, const ::com::sun::star::awt::Point& aPos );
119 : bool dockAllToolbars();
120 : bool floatToolbar( const OUString& rResoureURL );
121 : bool lockToolbar( const OUString& rResourceURL );
122 : bool unlockToolbar( const OUString& rResourceURL );
123 : void setToolbarPos( const OUString& rResourceURL, const ::com::sun::star::awt::Point& aPos );
124 : void setToolbarSize( const OUString& rResourceURL, const ::com::sun::star::awt::Size& aSize );
125 : void setToolbarPosSize( const OUString& rResourceURL, const ::com::sun::star::awt::Point& aPos, const ::com::sun::star::awt::Size& aSize );
126 : bool isToolbarVisible( const OUString& rResourceURL );
127 : bool isToolbarFloating( const OUString& rResourceURL );
128 : bool isToolbarDocked( const OUString& rResourceURL );
129 : bool isToolbarLocked( const OUString& rResourceURL );
130 : ::com::sun::star::awt::Point getToolbarPos( const OUString& rResourceURL );
131 : ::com::sun::star::awt::Size getToolbarSize( const OUString& rResourceURL );
132 : ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIElement > getToolbar( const OUString& aName );
133 : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIElement > > getToolbars();
134 :
135 : // child window notifications
136 : long childWindowEvent( VclSimpleEvent* pEvent );
137 :
138 : // XInterface
139 :
140 : virtual void SAL_CALL acquire() throw() SAL_OVERRIDE;
141 : virtual void SAL_CALL release() throw() SAL_OVERRIDE;
142 : virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
143 :
144 : // XEventListener
145 : virtual void SAL_CALL disposing( const css::lang::EventObject& aEvent ) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
146 :
147 : // XWindowListener
148 : virtual void SAL_CALL windowResized( const css::awt::WindowEvent& aEvent ) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
149 : virtual void SAL_CALL windowMoved( const css::awt::WindowEvent& aEvent ) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
150 : virtual void SAL_CALL windowShown( const css::lang::EventObject& aEvent ) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
151 : virtual void SAL_CALL windowHidden( const css::lang::EventObject& aEvent ) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
152 :
153 : // XDockableWindowListener
154 : virtual void SAL_CALL startDocking( const ::com::sun::star::awt::DockingEvent& e ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
155 : virtual ::com::sun::star::awt::DockingData SAL_CALL docking( const ::com::sun::star::awt::DockingEvent& e ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
156 : virtual void SAL_CALL endDocking( const ::com::sun::star::awt::EndDockingEvent& e ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
157 : virtual sal_Bool SAL_CALL prepareToggleFloatingMode( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
158 : virtual void SAL_CALL toggleFloatingMode( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
159 : virtual void SAL_CALL closed( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
160 : virtual void SAL_CALL endPopupMode( const ::com::sun::star::awt::EndPopupModeEvent& e ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
161 :
162 : // XUIConfigurationListener
163 : virtual void SAL_CALL elementInserted( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
164 : virtual void SAL_CALL elementRemoved( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
165 : virtual void SAL_CALL elementReplaced( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
166 :
167 : private:
168 : enum DockingOperation
169 : {
170 : DOCKOP_BEFORE_COLROW,
171 : DOCKOP_ON_COLROW,
172 : DOCKOP_AFTER_COLROW
173 : };
174 :
175 : typedef std::vector< UIElement > UIElementVector;
176 43116 : struct SingleRowColumnWindowData
177 : {
178 11574 : SingleRowColumnWindowData()
179 : : nVarSize(0)
180 : , nStaticSize(0)
181 : , nSpace(0)
182 11574 : , nRowColumn(0)
183 11574 : {}
184 :
185 : std::vector< OUString > aUIElementNames;
186 : std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > > aRowColumnWindows;
187 : std::vector< ::com::sun::star::awt::Rectangle > aRowColumnWindowSizes;
188 : std::vector< sal_Int32 > aRowColumnSpace;
189 : ::com::sun::star::awt::Rectangle aRowColumnRect;
190 : sal_Int32 nVarSize;
191 : sal_Int32 nStaticSize;
192 : sal_Int32 nSpace;
193 : sal_Int32 nRowColumn;
194 : };
195 :
196 : // internal helper methods
197 :
198 : bool implts_isParentWindowVisible() const;
199 : ::Rectangle implts_calcDockingArea();
200 : void implts_sortUIElements();
201 : void implts_reparentToolbars();
202 : OUString implts_generateGenericAddonToolbarTitle( sal_Int32 nNumber ) const;
203 : void implts_setElementData( UIElement& rUIElement, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDockableWindow >& rDockWindow );
204 : void implts_destroyDockingAreaWindows();
205 :
206 : // layout methods
207 :
208 : void implts_setDockingAreaWindowSizes( const ::com::sun::star::awt::Rectangle& rBorderSpace );
209 : ::com::sun::star::awt::Point implts_findNextCascadeFloatingPos();
210 : void implts_renumberRowColumnData( ::com::sun::star::ui::DockingArea eDockingArea, DockingOperation eDockingOperation, const UIElement& rUIElement );
211 : void implts_calcWindowPosSizeOnSingleRowColumn( sal_Int32 nDockingArea,
212 : sal_Int32 nOffset,
213 : SingleRowColumnWindowData& rRowColumnWindowData,
214 : const ::Size& rContainerSize );
215 : void implts_setLayoutDirty();
216 : void implts_setLayoutInProgress( bool bInProgress = true );
217 : bool implts_isLayoutInProgress() const { return m_bLayoutInProgress; }
218 :
219 : // lookup/container methods
220 :
221 : UIElement implts_findToolbar( const OUString& aName );
222 : UIElement implts_findToolbar( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xToolbar );
223 : UIElement& impl_findToolbar( const OUString& aName );
224 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > implts_getXWindow( const OUString& aName );
225 : vcl::Window* implts_getWindow( const OUString& aName );
226 : bool implts_insertToolbar( const UIElement& rUIElement );
227 : void implts_setToolbar( const UIElement& rUIElement );
228 : ::Size implts_getTopBottomDockingAreaSizes();
229 : void implts_getUIElementVectorCopy( UIElementVector& rCopy );
230 :
231 : // internal docking methods
232 :
233 : ::Rectangle implts_calcHotZoneRect( const ::Rectangle& rRect, sal_Int32 nHotZoneOffset );
234 : void implts_calcDockingPosSize( UIElement& aUIElement, DockingOperation& eDockOperation, ::Rectangle& rTrackingRect, const Point& rMousePos );
235 : DockingOperation implts_determineDockingOperation( ::com::sun::star::ui::DockingArea DockingArea, const ::Rectangle& rRowColRect, const Point& rMousePos );
236 : ::Rectangle implts_getWindowRectFromRowColumn( ::com::sun::star::ui::DockingArea DockingArea, const SingleRowColumnWindowData& rRowColumnWindowData, const ::Point& rMousePos, const OUString& rExcludeElementName );
237 : ::Rectangle implts_determineFrontDockingRect( ::com::sun::star::ui::DockingArea eDockingArea,
238 : sal_Int32 nRowCol,
239 : const ::Rectangle& rDockedElementRect,
240 : const OUString& rMovedElementName,
241 : const ::Rectangle& rMovedElementRect );
242 : ::Rectangle implts_calcTrackingAndElementRect( ::com::sun::star::ui::DockingArea eDockingArea,
243 : sal_Int32 nRowCol,
244 : UIElement& rUIElement,
245 : const ::Rectangle& rTrackingRect,
246 : const ::Rectangle& rRowColumnRect,
247 : const ::Size& rContainerWinSize );
248 :
249 : void implts_getDockingAreaElementInfos( ::com::sun::star::ui::DockingArea DockingArea, std::vector< SingleRowColumnWindowData >& rRowColumnsWindowData );
250 : void implts_getDockingAreaElementInfoOnSingleRowCol( ::com::sun::star::ui::DockingArea, sal_Int32 nRowCol, SingleRowColumnWindowData& rRowColumnWindowData );
251 : void implts_findNextDockingPos( ::com::sun::star::ui::DockingArea DockingArea, const ::Size& aUIElementSize, ::com::sun::star::awt::Point& rVirtualPos, ::Point& rPixelPos );
252 : void implts_setTrackingRect( ::com::sun::star::ui::DockingArea eDockingArea, const ::Point& rMousePos, ::Rectangle& rTrackingRect );
253 :
254 : // creation methods
255 :
256 : void implts_createAddonsToolBars();
257 : void implts_createCustomToolBars();
258 : void implts_createNonContextSensitiveToolBars();
259 : void implts_createCustomToolBars( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >& aCustomTbxSeq );
260 : void implts_createCustomToolBar( const OUString& aTbxResName, const OUString& aTitle );
261 : void implts_setToolbarCreation( bool bStart = true );
262 : bool implts_isToolbarCreationActive();
263 :
264 : // persistence methods
265 :
266 : bool implts_readWindowStateData( const OUString& aName, UIElement& rElementData );
267 : void implts_writeWindowStateData( const UIElement& rElementData );
268 :
269 : // members
270 :
271 : css::uno::Reference< css::uno::XComponentContext > m_xContext;
272 : css::uno::Reference< css::frame::XFrame > m_xFrame;
273 : css::uno::Reference< css::awt::XWindow2 > m_xContainerWindow;
274 : css::uno::Reference< css::awt::XWindow > m_xDockAreaWindows[DOCKINGAREAS_COUNT];
275 : css::uno::Reference< ::com::sun::star::ui::XUIElementFactory > m_xUIElementFactoryManager;
276 : css::uno::Reference< ::com::sun::star::ui::XUIConfigurationManager > m_xModuleCfgMgr;
277 : css::uno::Reference< ::com::sun::star::ui::XUIConfigurationManager > m_xDocCfgMgr;
278 : css::uno::Reference< ::com::sun::star::container::XNameAccess > m_xPersistentWindowState;
279 : ILayoutNotifications* m_pParentLayouter;
280 :
281 : UIElementVector m_aUIElements;
282 : UIElement m_aDockUIElement;
283 : Point m_aStartDockMousePos;
284 : Rectangle m_aDockingArea;
285 : Rectangle m_aDockingAreaOffsets;
286 : DockingOperation m_eDockOperation;
287 : PreviewFrameDetection m_ePreviewDetection;
288 :
289 : AddonsOptions* m_pAddonOptions;
290 : GlobalSettings* m_pGlobalSettings;
291 :
292 : bool m_bComponentAttached;
293 : bool m_bLayoutDirty;
294 : bool m_bStoreWindowState;
295 : bool m_bGlobalSettings;
296 : bool m_bDockingInProgress;
297 : bool m_bVisible;
298 : bool m_bLayoutInProgress;
299 : bool m_bToolbarCreation;
300 : };
301 :
302 : } // namespace framework
303 :
304 : #endif // INCLUDED_FRAMEWORK_SOURCE_LAYOUTMANAGER_TOOLBARLAYOUTMANAGER_HXX
305 :
306 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|