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