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. Otherwhise 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 initalization 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 221 //--------------------------------------------------------------------------------------------------------- 222 // layout methods 223 //--------------------------------------------------------------------------------------------------------- 224 void implts_setDockingAreaWindowSizes( const ::com::sun::star::awt::Rectangle& rBorderSpace ); 225 ::Point implts_findNextCascadeFloatingPos(); 226 void implts_renumberRowColumnData( ::com::sun::star::ui::DockingArea eDockingArea, DockingOperation eDockingOperation, const UIElement& rUIElement ); 227 void implts_calcWindowPosSizeOnSingleRowColumn( sal_Int32 nDockingArea, 228 sal_Int32 nOffset, 229 SingleRowColumnWindowData& rRowColumnWindowData, 230 const ::Size& rContainerSize ); 231 void implts_setLayoutDirty(); 232 void implts_setLayoutInProgress( bool bInProgress = true ); 233 bool implts_isLayoutInProgress() const { return m_bLayoutInProgress; } 234 235 //--------------------------------------------------------------------------------------------------------- 236 // lookup/container methods 237 //--------------------------------------------------------------------------------------------------------- 238 UIElement implts_findToolbar( const rtl::OUString& aName ); 239 UIElement implts_findToolbar( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xToolbar ); 240 UIElement& impl_findToolbar( const rtl::OUString& aName ); 241 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > implts_getXWindow( const ::rtl::OUString& aName ); 242 Window* implts_getWindow( const ::rtl::OUString& aName ); 243 bool implts_insertToolbar( const UIElement& rUIElement ); 244 void implts_setToolbar( const UIElement& rUIElement ); 245 ::Size implts_getTopBottomDockingAreaSizes(); 246 void implts_getUIElementVectorCopy( UIElementVector& rCopy ); 247 248 //--------------------------------------------------------------------------------------------------------- 249 // internal docking methods 250 //--------------------------------------------------------------------------------------------------------- 251 ::Rectangle implts_calcHotZoneRect( const ::Rectangle& rRect, sal_Int32 nHotZoneOffset ); 252 void implts_calcDockingPosSize( UIElement& aUIElement, DockingOperation& eDockOperation, ::Rectangle& rTrackingRect, const Point& rMousePos ); 253 DockingOperation implts_determineDockingOperation( ::com::sun::star::ui::DockingArea DockingArea, const ::Rectangle& rRowColRect, const Point& rMousePos ); 254 ::Rectangle implts_getWindowRectFromRowColumn( ::com::sun::star::ui::DockingArea DockingArea, const SingleRowColumnWindowData& rRowColumnWindowData, const ::Point& rMousePos, const rtl::OUString& rExcludeElementName ); 255 ::Rectangle implts_determineFrontDockingRect( ::com::sun::star::ui::DockingArea eDockingArea, 256 sal_Int32 nRowCol, 257 const ::Rectangle& rDockedElementRect, 258 const ::rtl::OUString& rMovedElementName, 259 const ::Rectangle& rMovedElementRect ); 260 ::Rectangle implts_calcTrackingAndElementRect( ::com::sun::star::ui::DockingArea eDockingArea, 261 sal_Int32 nRowCol, 262 UIElement& rUIElement, 263 const ::Rectangle& rTrackingRect, 264 const ::Rectangle& rRowColumnRect, 265 const ::Size& rContainerWinSize ); 266 267 void implts_getDockingAreaElementInfos( ::com::sun::star::ui::DockingArea DockingArea, std::vector< SingleRowColumnWindowData >& rRowColumnsWindowData ); 268 void implts_getDockingAreaElementInfoOnSingleRowCol( ::com::sun::star::ui::DockingArea, sal_Int32 nRowCol, SingleRowColumnWindowData& rRowColumnWindowData ); 269 void implts_findNextDockingPos( ::com::sun::star::ui::DockingArea DockingArea, const ::Size& aUIElementSize, ::Point& rVirtualPos, ::Point& rPixelPos ); 270 void implts_setTrackingRect( ::com::sun::star::ui::DockingArea eDockingArea, const ::Point& rMousePos, ::Rectangle& rTrackingRect ); 271 272 //--------------------------------------------------------------------------------------------------------- 273 // creation methods 274 //--------------------------------------------------------------------------------------------------------- 275 void implts_createAddonsToolBars(); 276 void implts_createCustomToolBars(); 277 void implts_createNonContextSensitiveToolBars(); 278 void implts_createCustomToolBars( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >& aCustomTbxSeq ); 279 void implts_createCustomToolBar( const rtl::OUString& aTbxResName, const rtl::OUString& aTitle ); 280 void implts_createToolBar( const ::rtl::OUString& aName, bool& bNotify, ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIElement >& rUIElement ); 281 css::uno::Reference< css::ui::XUIElement > implts_createElement( const ::rtl::OUString& aName ); 282 void implts_setToolbarCreation( bool bStart = true ); 283 bool implts_isToolbarCreationActive(); 284 285 //--------------------------------------------------------------------------------------------------------- 286 // persistence methods 287 //--------------------------------------------------------------------------------------------------------- 288 sal_Bool implts_readWindowStateData( const rtl::OUString& aName, UIElement& rElementData ); 289 void implts_writeWindowStateData( const UIElement& rElementData ); 290 void implts_writeNewWindowStateData( const rtl::OUString aName, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& xWindow ); 291 292 //--------------------------------------------------------------------------------------------------------- 293 // members 294 //--------------------------------------------------------------------------------------------------------- 295 css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR; 296 css::uno::Reference< css::frame::XFrame > m_xFrame; 297 css::uno::Reference< css::awt::XWindow2 > m_xContainerWindow; 298 css::uno::Reference< css::awt::XWindow > m_xDockAreaWindows[DOCKINGAREAS_COUNT]; 299 css::uno::Reference< ::com::sun::star::ui::XUIElementFactory > m_xUIElementFactoryManager; 300 css::uno::Reference< ::com::sun::star::ui::XUIConfigurationManager > m_xModuleCfgMgr; 301 css::uno::Reference< ::com::sun::star::ui::XUIConfigurationManager > m_xDocCfgMgr; 302 css::uno::Reference< ::com::sun::star::awt::XToolkit > m_xToolkit; 303 css::uno::Reference< ::com::sun::star::container::XNameAccess > m_xPersistentWindowState; 304 ILayoutNotifications* m_pParentLayouter; 305 306 UIElementVector m_aUIElements; 307 UIElement m_aDockUIElement; 308 Point m_aStartDockMousePos; 309 Rectangle m_aDockingArea; 310 Rectangle m_aDockingAreaOffsets; 311 DockingOperation m_eDockOperation; 312 313 AddonsOptions* m_pAddonOptions; 314 GlobalSettings* m_pGlobalSettings; 315 316 bool m_bComponentAttached; 317 bool m_bMustLayout; 318 bool m_bLayoutDirty; 319 bool m_bStoreWindowState; 320 bool m_bGlobalSettings; 321 bool m_bDockingInProgress; 322 bool m_bVisible; 323 bool m_bLayoutInProgress; 324 bool m_bToolbarCreation; 325 326 ::rtl::OUString m_aFullAddonTbxPrefix; 327 ::rtl::OUString m_aCustomTbxPrefix; 328 ::rtl::OUString m_aCustomizeCmd; 329 ::rtl::OUString m_aToolbarTypeString; 330 ::rtl::OUString m_aModuleIdentifier; 331 }; 332 333 } // namespace framework 334 335 #endif // __FRAMEWORK_LAYOUTMANAGER_TOOLBARLAYOUTMANAGER_HXX_ 336 337 /* vim: set noet sw=4 ts=4: */ 338