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