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