16d739b60SAndrew Rist /************************************************************** 26d739b60SAndrew Rist * 36d739b60SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 46d739b60SAndrew Rist * or more contributor license agreements. See the NOTICE file 56d739b60SAndrew Rist * distributed with this work for additional information 66d739b60SAndrew Rist * regarding copyright ownership. The ASF licenses this file 76d739b60SAndrew Rist * to you under the Apache License, Version 2.0 (the 86d739b60SAndrew Rist * "License"); you may not use this file except in compliance 96d739b60SAndrew Rist * with the License. You may obtain a copy of the License at 106d739b60SAndrew Rist * 116d739b60SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 126d739b60SAndrew Rist * 136d739b60SAndrew Rist * Unless required by applicable law or agreed to in writing, 146d739b60SAndrew Rist * software distributed under the License is distributed on an 156d739b60SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 166d739b60SAndrew Rist * KIND, either express or implied. See the License for the 176d739b60SAndrew Rist * specific language governing permissions and limitations 186d739b60SAndrew Rist * under the License. 196d739b60SAndrew Rist * 206d739b60SAndrew Rist *************************************************************/ 216d739b60SAndrew Rist 226d739b60SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_framework.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir // my own includes 28cdf0e10cSrcweir #include <toolbarlayoutmanager.hxx> 29cdf0e10cSrcweir #include <helpers.hxx> 30cdf0e10cSrcweir #include <services.h> 31cdf0e10cSrcweir #include <classes/resource.hrc> 32cdf0e10cSrcweir #include <classes/fwkresid.hxx> 33cdf0e10cSrcweir #include <uiconfiguration/windowstateconfiguration.hxx> 34cdf0e10cSrcweir 35cdf0e10cSrcweir // interface includes 36cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp> 37cdf0e10cSrcweir #include <com/sun/star/ui/UIElementType.hpp> 38cdf0e10cSrcweir #include <com/sun/star/container/XNameReplace.hpp> 39cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 40cdf0e10cSrcweir #include <com/sun/star/ui/XUIElementSettings.hpp> 41cdf0e10cSrcweir #include <com/sun/star/ui/XUIFunctionListener.hpp> 42cdf0e10cSrcweir 43cdf0e10cSrcweir // other includes 44cdf0e10cSrcweir #include <unotools/cmdoptions.hxx> 45*b63233d8Sdamjan #include <toolkit/helper/vclunohelper.hxx> 46cdf0e10cSrcweir #include <toolkit/helper/convert.hxx> 47cdf0e10cSrcweir #include <toolkit/awt/vclxwindow.hxx> 48cdf0e10cSrcweir #include <vcl/i18nhelp.hxx> 49cdf0e10cSrcweir #include <vcl/dockingarea.hxx> 50cdf0e10cSrcweir #include <boost/bind.hpp> 51cdf0e10cSrcweir 52cdf0e10cSrcweir using namespace ::com::sun::star; 53cdf0e10cSrcweir 54cdf0e10cSrcweir namespace framework 55cdf0e10cSrcweir { 56cdf0e10cSrcweir 57cdf0e10cSrcweir ToolbarLayoutManager::ToolbarLayoutManager( 58cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& xSMGR, 59cdf0e10cSrcweir const uno::Reference< ui::XUIElementFactory >& xUIElementFactory, 60cdf0e10cSrcweir ILayoutNotifications* pParentLayouter ) 61cdf0e10cSrcweir : ThreadHelpBase( &Application::GetSolarMutex() ), 62cdf0e10cSrcweir m_xSMGR( xSMGR ), 63cdf0e10cSrcweir m_xUIElementFactoryManager( xUIElementFactory ), 64cdf0e10cSrcweir m_pParentLayouter( pParentLayouter ), 65cdf0e10cSrcweir m_eDockOperation( DOCKOP_ON_COLROW ), 66cdf0e10cSrcweir m_pAddonOptions( 0 ), 67cdf0e10cSrcweir m_pGlobalSettings( 0 ), 68cdf0e10cSrcweir m_bComponentAttached( false ), 69cdf0e10cSrcweir m_bMustLayout( false ), 70cdf0e10cSrcweir m_bLayoutDirty( false ), 71cdf0e10cSrcweir m_bStoreWindowState( false ), 72cdf0e10cSrcweir m_bGlobalSettings( false ), 73cdf0e10cSrcweir m_bDockingInProgress( false ), 74cdf0e10cSrcweir m_bVisible( true ), 75cdf0e10cSrcweir m_bLayoutInProgress( false ), 76cdf0e10cSrcweir m_bToolbarCreation( false ), 77cdf0e10cSrcweir m_aFullAddonTbxPrefix( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/addon_" )), 78cdf0e10cSrcweir m_aCustomTbxPrefix( RTL_CONSTASCII_USTRINGPARAM( "custom_" )), 79cdf0e10cSrcweir m_aCustomizeCmd( RTL_CONSTASCII_USTRINGPARAM( "ConfigureDialog" )), 80cdf0e10cSrcweir m_aToolbarTypeString( RTL_CONSTASCII_USTRINGPARAM( UIRESOURCETYPE_TOOLBAR )) 81cdf0e10cSrcweir { 82cdf0e10cSrcweir // initialize rectangles to zero values 83cdf0e10cSrcweir setZeroRectangle( m_aDockingAreaOffsets ); 84cdf0e10cSrcweir setZeroRectangle( m_aDockingArea ); 85cdf0e10cSrcweir 86cdf0e10cSrcweir // create toolkit object 87cdf0e10cSrcweir m_xToolkit = uno::Reference< awt::XToolkit >( m_xSMGR->createInstance( SERVICENAME_VCLTOOLKIT ), uno::UNO_QUERY ); 88cdf0e10cSrcweir } 89cdf0e10cSrcweir 90cdf0e10cSrcweir ToolbarLayoutManager::~ToolbarLayoutManager() 91cdf0e10cSrcweir { 92cdf0e10cSrcweir } 93cdf0e10cSrcweir 94cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 95cdf0e10cSrcweir // XInterface 96cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 97cdf0e10cSrcweir void SAL_CALL ToolbarLayoutManager::acquire() throw() 98cdf0e10cSrcweir { 99cdf0e10cSrcweir OWeakObject::acquire(); 100cdf0e10cSrcweir } 101cdf0e10cSrcweir 102cdf0e10cSrcweir void SAL_CALL ToolbarLayoutManager::release() throw() 103cdf0e10cSrcweir { 104cdf0e10cSrcweir OWeakObject::release(); 105cdf0e10cSrcweir } 106cdf0e10cSrcweir 107cdf0e10cSrcweir uno::Any SAL_CALL ToolbarLayoutManager::queryInterface( const uno::Type & rType ) throw( uno::RuntimeException ) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir uno::Any a = ::cppu::queryInterface( rType, 110cdf0e10cSrcweir SAL_STATIC_CAST( awt::XDockableWindowListener*, this ), 111cdf0e10cSrcweir SAL_STATIC_CAST( ui::XUIConfigurationListener*, this ), 112cdf0e10cSrcweir SAL_STATIC_CAST( awt::XWindowListener*, this )); 113cdf0e10cSrcweir 114cdf0e10cSrcweir if ( a.hasValue() ) 115cdf0e10cSrcweir return a; 116cdf0e10cSrcweir 117cdf0e10cSrcweir return OWeakObject::queryInterface( rType ); 118cdf0e10cSrcweir } 119cdf0e10cSrcweir 120cdf0e10cSrcweir void SAL_CALL ToolbarLayoutManager::disposing( const lang::EventObject& aEvent ) throw( uno::RuntimeException ) 121cdf0e10cSrcweir { 122cdf0e10cSrcweir if ( aEvent.Source == m_xFrame ) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir // Reset all internal references 125cdf0e10cSrcweir reset(); 126cdf0e10cSrcweir implts_destroyDockingAreaWindows(); 127cdf0e10cSrcweir } 128cdf0e10cSrcweir } 129cdf0e10cSrcweir 130cdf0e10cSrcweir awt::Rectangle ToolbarLayoutManager::getDockingArea() 131cdf0e10cSrcweir { 132cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 133cdf0e10cSrcweir Rectangle aNewDockingArea( m_aDockingArea ); 134cdf0e10cSrcweir aWriteLock.unlock(); 135cdf0e10cSrcweir 136cdf0e10cSrcweir if ( isLayoutDirty() ) 137cdf0e10cSrcweir aNewDockingArea = implts_calcDockingArea(); 138cdf0e10cSrcweir 139cdf0e10cSrcweir aWriteLock.lock(); 140cdf0e10cSrcweir m_aDockingArea = aNewDockingArea; 141cdf0e10cSrcweir aWriteLock.unlock(); 142cdf0e10cSrcweir 143cdf0e10cSrcweir return putRectangleValueToAWT(aNewDockingArea); 144cdf0e10cSrcweir } 145cdf0e10cSrcweir 146cdf0e10cSrcweir void ToolbarLayoutManager::setDockingArea( const awt::Rectangle& rDockingArea ) 147cdf0e10cSrcweir { 148cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 149cdf0e10cSrcweir m_aDockingArea = putAWTToRectangle( rDockingArea ); 150cdf0e10cSrcweir m_bLayoutDirty = true; 151cdf0e10cSrcweir aWriteLock.unlock(); 152cdf0e10cSrcweir } 153cdf0e10cSrcweir 154cdf0e10cSrcweir void ToolbarLayoutManager::implts_setDockingAreaWindowSizes( const awt::Rectangle& rBorderSpace ) 155cdf0e10cSrcweir { 156cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 157cdf0e10cSrcweir Rectangle aDockOffsets = m_aDockingAreaOffsets; 158cdf0e10cSrcweir uno::Reference< awt::XWindow2 > xContainerWindow( m_xContainerWindow ); 159cdf0e10cSrcweir uno::Reference< awt::XWindow > xTopDockAreaWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_TOP] ); 160cdf0e10cSrcweir uno::Reference< awt::XWindow > xBottomDockAreaWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_BOTTOM] ); 161cdf0e10cSrcweir uno::Reference< awt::XWindow > xLeftDockAreaWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_LEFT] ); 162cdf0e10cSrcweir uno::Reference< awt::XWindow > xRightDockAreaWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_RIGHT] ); 163cdf0e10cSrcweir aReadLock.unlock(); 164cdf0e10cSrcweir 165cdf0e10cSrcweir uno::Reference< awt::XDevice > xDevice( xContainerWindow, uno::UNO_QUERY ); 166cdf0e10cSrcweir 167cdf0e10cSrcweir // Convert relativ size to output size. 168cdf0e10cSrcweir awt::Rectangle aRectangle = xContainerWindow->getPosSize(); 169cdf0e10cSrcweir awt::DeviceInfo aInfo = xDevice->getInfo(); 170cdf0e10cSrcweir awt::Size aContainerClientSize = awt::Size( aRectangle.Width - aInfo.LeftInset - aInfo.RightInset , 171cdf0e10cSrcweir aRectangle.Height - aInfo.TopInset - aInfo.BottomInset ); 172cdf0e10cSrcweir long aStatusBarHeight = aDockOffsets.GetHeight(); 173cdf0e10cSrcweir 174cdf0e10cSrcweir sal_Int32 nLeftRightDockingAreaHeight( aContainerClientSize.Height ); 175cdf0e10cSrcweir if ( rBorderSpace.Y >= 0 ) 176cdf0e10cSrcweir { 177cdf0e10cSrcweir // Top docking area window 178cdf0e10cSrcweir xTopDockAreaWindow->setPosSize( 0, 0, aContainerClientSize.Width, rBorderSpace.Y, awt::PosSize::POSSIZE ); 179cdf0e10cSrcweir xTopDockAreaWindow->setVisible( sal_True ); 180cdf0e10cSrcweir nLeftRightDockingAreaHeight -= rBorderSpace.Y; 181cdf0e10cSrcweir } 182cdf0e10cSrcweir 183cdf0e10cSrcweir if ( rBorderSpace.Height >= 0 ) 184cdf0e10cSrcweir { 185cdf0e10cSrcweir // Bottom docking area window 186cdf0e10cSrcweir sal_Int32 nBottomPos = std::max( sal_Int32( aContainerClientSize.Height - rBorderSpace.Height - aStatusBarHeight ), sal_Int32( 0 )); 187cdf0e10cSrcweir sal_Int32 nHeight = ( nBottomPos == 0 ) ? 0 : rBorderSpace.Height; 188cdf0e10cSrcweir 189cdf0e10cSrcweir xBottomDockAreaWindow->setPosSize( 0, nBottomPos, aContainerClientSize.Width, nHeight, awt::PosSize::POSSIZE ); 190cdf0e10cSrcweir xBottomDockAreaWindow->setVisible( sal_True ); 191cdf0e10cSrcweir nLeftRightDockingAreaHeight -= nHeight; 192cdf0e10cSrcweir } 193cdf0e10cSrcweir 194cdf0e10cSrcweir nLeftRightDockingAreaHeight -= aStatusBarHeight; 195cdf0e10cSrcweir if ( rBorderSpace.X >= 0 || nLeftRightDockingAreaHeight > 0 ) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir // Left docking area window 198cdf0e10cSrcweir // We also have to change our right docking area window if the top or bottom area has changed. They have a higher priority! 199cdf0e10cSrcweir sal_Int32 nHeight = std::max( sal_Int32( 0 ), sal_Int32( nLeftRightDockingAreaHeight )); 200cdf0e10cSrcweir 201cdf0e10cSrcweir xLeftDockAreaWindow->setPosSize( 0, rBorderSpace.Y, rBorderSpace.X, nHeight, awt::PosSize::POSSIZE ); 202cdf0e10cSrcweir xLeftDockAreaWindow->setVisible( sal_True ); 203cdf0e10cSrcweir } 204cdf0e10cSrcweir if ( rBorderSpace.Width >= 0 || nLeftRightDockingAreaHeight > 0 ) 205cdf0e10cSrcweir { 206cdf0e10cSrcweir // Right docking area window 207cdf0e10cSrcweir // We also have to change our right docking area window if the top or bottom area has changed. They have a higher priority! 208cdf0e10cSrcweir sal_Int32 nLeftPos = std::max( sal_Int32( 0 ), sal_Int32( aContainerClientSize.Width - rBorderSpace.Width )); 209cdf0e10cSrcweir sal_Int32 nHeight = std::max( sal_Int32( 0 ), sal_Int32( nLeftRightDockingAreaHeight )); 210cdf0e10cSrcweir sal_Int32 nWidth = ( nLeftPos == 0 ) ? 0 : rBorderSpace.Width; 211cdf0e10cSrcweir 212cdf0e10cSrcweir xRightDockAreaWindow->setPosSize( nLeftPos, rBorderSpace.Y, nWidth, nHeight, awt::PosSize::POSSIZE ); 213cdf0e10cSrcweir xRightDockAreaWindow->setVisible( sal_True ); 214cdf0e10cSrcweir } 215cdf0e10cSrcweir } 216cdf0e10cSrcweir 217cdf0e10cSrcweir bool ToolbarLayoutManager::isLayoutDirty() 218cdf0e10cSrcweir { 219cdf0e10cSrcweir return m_bLayoutDirty; 220cdf0e10cSrcweir } 221cdf0e10cSrcweir 222cdf0e10cSrcweir void ToolbarLayoutManager::doLayout(const ::Size& aContainerSize) 223cdf0e10cSrcweir { 224cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 225cdf0e10cSrcweir bool bLayoutInProgress( m_bLayoutInProgress ); 226cdf0e10cSrcweir m_bLayoutInProgress = true; 227cdf0e10cSrcweir awt::Rectangle aDockingArea = putRectangleValueToAWT( m_aDockingArea ); 228cdf0e10cSrcweir aWriteLock.unlock(); 229cdf0e10cSrcweir 230cdf0e10cSrcweir if ( bLayoutInProgress ) 231cdf0e10cSrcweir return; 232cdf0e10cSrcweir 233cdf0e10cSrcweir // Retrieve row/column dependent data from all docked user-interface elements 234cdf0e10cSrcweir for ( sal_Int32 i = 0; i < DOCKINGAREAS_COUNT; i++ ) 235cdf0e10cSrcweir { 236cdf0e10cSrcweir bool bReverse( isReverseOrderDockingArea( i )); 237cdf0e10cSrcweir std::vector< SingleRowColumnWindowData > aRowColumnsWindowData; 238cdf0e10cSrcweir 239cdf0e10cSrcweir implts_getDockingAreaElementInfos( (ui::DockingArea)i, aRowColumnsWindowData ); 240cdf0e10cSrcweir 241cdf0e10cSrcweir sal_Int32 nOffset( 0 ); 242cdf0e10cSrcweir const sal_uInt32 nCount = aRowColumnsWindowData.size(); 243cdf0e10cSrcweir for ( sal_uInt32 j = 0; j < nCount; ++j ) 244cdf0e10cSrcweir { 245cdf0e10cSrcweir sal_uInt32 nIndex = bReverse ? nCount-j-1 : j; 246cdf0e10cSrcweir implts_calcWindowPosSizeOnSingleRowColumn( i, nOffset, aRowColumnsWindowData[nIndex], aContainerSize ); 247cdf0e10cSrcweir nOffset += aRowColumnsWindowData[j].nStaticSize; 248cdf0e10cSrcweir } 249cdf0e10cSrcweir } 250cdf0e10cSrcweir 251cdf0e10cSrcweir implts_setDockingAreaWindowSizes( aDockingArea ); 252cdf0e10cSrcweir 253cdf0e10cSrcweir aWriteLock.lock(); 254cdf0e10cSrcweir m_bLayoutDirty = false; 255cdf0e10cSrcweir m_bLayoutInProgress = false; 256cdf0e10cSrcweir aWriteLock.unlock(); 257cdf0e10cSrcweir } 258cdf0e10cSrcweir 259cdf0e10cSrcweir bool ToolbarLayoutManager::implts_isParentWindowVisible() const 260cdf0e10cSrcweir { 261cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 26244e86b95SOliver-Rainer Wittmann bool bVisible( false ); 263cdf0e10cSrcweir if ( m_xContainerWindow.is() ) 264cdf0e10cSrcweir bVisible = m_xContainerWindow->isVisible(); 265cdf0e10cSrcweir 266cdf0e10cSrcweir return bVisible; 267cdf0e10cSrcweir } 268cdf0e10cSrcweir 26944e86b95SOliver-Rainer Wittmann namespace 270cdf0e10cSrcweir { 27144e86b95SOliver-Rainer Wittmann void insertDockingAreaSize( 27244e86b95SOliver-Rainer Wittmann const UIElement& rUIElement, 27344e86b95SOliver-Rainer Wittmann const awt::Rectangle& rUIElementPosSize, 27444e86b95SOliver-Rainer Wittmann std::vector< sal_Int32 >& rDockingAreaData ) 27544e86b95SOliver-Rainer Wittmann { 27644e86b95SOliver-Rainer Wittmann sal_Int32 nAreaPos = 0; 27744e86b95SOliver-Rainer Wittmann sal_Int32 nSize = 0; 27844e86b95SOliver-Rainer Wittmann if ( isHorizontalDockingArea( rUIElement.m_aDockedData.m_nDockedArea ) ) 27944e86b95SOliver-Rainer Wittmann { 28044e86b95SOliver-Rainer Wittmann nAreaPos = rUIElement.m_aDockedData.m_aPos.Y(); 28144e86b95SOliver-Rainer Wittmann nSize = rUIElementPosSize.Height; 28244e86b95SOliver-Rainer Wittmann } 28344e86b95SOliver-Rainer Wittmann else 28444e86b95SOliver-Rainer Wittmann { 28544e86b95SOliver-Rainer Wittmann nAreaPos = rUIElement.m_aDockedData.m_aPos.X(); 28644e86b95SOliver-Rainer Wittmann nSize = rUIElementPosSize.Width; 28744e86b95SOliver-Rainer Wittmann } 288cdf0e10cSrcweir 28944e86b95SOliver-Rainer Wittmann const sal_uInt32 nIndexPos = nAreaPos >= 0 ? static_cast< sal_uInt32 >(nAreaPos) : 0; 29044e86b95SOliver-Rainer Wittmann if ( rDockingAreaData.size() < nIndexPos + 1 ) 29144e86b95SOliver-Rainer Wittmann { 29244e86b95SOliver-Rainer Wittmann rDockingAreaData.resize( nIndexPos + 1, 0 ); 29344e86b95SOliver-Rainer Wittmann } 294cdf0e10cSrcweir 29544e86b95SOliver-Rainer Wittmann if ( rDockingAreaData[nIndexPos] < nSize ) 29644e86b95SOliver-Rainer Wittmann { 29744e86b95SOliver-Rainer Wittmann rDockingAreaData[nIndexPos] = nSize; 29844e86b95SOliver-Rainer Wittmann } 29944e86b95SOliver-Rainer Wittmann } 300cdf0e10cSrcweir 301cdf0e10cSrcweir 30244e86b95SOliver-Rainer Wittmann sal_Int32 calcDockingAreaSize( const std::vector< sal_Int32 >& rDockingAreaData ) 303cdf0e10cSrcweir { 30444e86b95SOliver-Rainer Wittmann sal_Int32 nDockingAreaSize = 0; 30544e86b95SOliver-Rainer Wittmann 30644e86b95SOliver-Rainer Wittmann std::vector< sal_Int32 >::const_iterator iDockingAreaDataEnd = rDockingAreaData.end(); 30744e86b95SOliver-Rainer Wittmann for ( std::vector< sal_Int32 >::const_iterator iDockingAreaData = rDockingAreaData.begin(); 30844e86b95SOliver-Rainer Wittmann iDockingAreaData != iDockingAreaDataEnd; 30944e86b95SOliver-Rainer Wittmann ++iDockingAreaData ) 310cdf0e10cSrcweir { 31144e86b95SOliver-Rainer Wittmann nDockingAreaSize += *(iDockingAreaData); 31244e86b95SOliver-Rainer Wittmann } 31344e86b95SOliver-Rainer Wittmann 31444e86b95SOliver-Rainer Wittmann return nDockingAreaSize; 31544e86b95SOliver-Rainer Wittmann } 31644e86b95SOliver-Rainer Wittmann } 317cdf0e10cSrcweir 318cdf0e10cSrcweir 31944e86b95SOliver-Rainer Wittmann Rectangle ToolbarLayoutManager::implts_calcDockingArea() 32044e86b95SOliver-Rainer Wittmann { 32144e86b95SOliver-Rainer Wittmann Rectangle aBorderSpace( 0, 0, 0, 0 ); 32244e86b95SOliver-Rainer Wittmann 32344e86b95SOliver-Rainer Wittmann // For each docking area one container of UIElement sizes. 32444e86b95SOliver-Rainer Wittmann std::vector< std::vector< sal_Int32 > >aDockingAreaSizeDatas( DOCKINGAREAS_COUNT ); 32544e86b95SOliver-Rainer Wittmann 32644e86b95SOliver-Rainer Wittmann { 32744e86b95SOliver-Rainer Wittmann ReadGuard aReadLock( m_aLock ); 32844e86b95SOliver-Rainer Wittmann vos::OGuard aGuard( Application::GetSolarMutex() ); 32944e86b95SOliver-Rainer Wittmann 33044e86b95SOliver-Rainer Wittmann // Iterate over the UIElements and collect corresponding docking area data 33144e86b95SOliver-Rainer Wittmann // for non-floating and visible ones separated for the each docking area. 33244e86b95SOliver-Rainer Wittmann // Note: For each docking area row resp. column only the size of largest UIElement is collected. 33344e86b95SOliver-Rainer Wittmann for ( UIElementVector::const_iterator pConstIter = m_aUIElements.begin(); pConstIter != m_aUIElements.end(); ++pConstIter ) 33444e86b95SOliver-Rainer Wittmann { 335ffdd8a15SOliver-Rainer Wittmann if ( !pConstIter->m_bVisible 336ffdd8a15SOliver-Rainer Wittmann || pConstIter->m_bMasterHide ) 337ffdd8a15SOliver-Rainer Wittmann { 338ffdd8a15SOliver-Rainer Wittmann continue; 339ffdd8a15SOliver-Rainer Wittmann } 340ffdd8a15SOliver-Rainer Wittmann 34144e86b95SOliver-Rainer Wittmann uno::Reference< ui::XUIElement > xUIElement( pConstIter->m_xUIElement, uno::UNO_QUERY ); 34244e86b95SOliver-Rainer Wittmann if ( xUIElement.is() ) 34344e86b95SOliver-Rainer Wittmann { 34444e86b95SOliver-Rainer Wittmann uno::Reference< awt::XWindow > xWindow( xUIElement->getRealInterface(), uno::UNO_QUERY ); 34544e86b95SOliver-Rainer Wittmann uno::Reference< awt::XDockableWindow > xDockWindow( xWindow, uno::UNO_QUERY ); 34644e86b95SOliver-Rainer Wittmann if ( xWindow.is() && xDockWindow.is() ) 34744e86b95SOliver-Rainer Wittmann { 34844e86b95SOliver-Rainer Wittmann Window* pWindow = VCLUnoHelper::GetWindow( xWindow ); 349ffdd8a15SOliver-Rainer Wittmann if ( pWindow != NULL 350ffdd8a15SOliver-Rainer Wittmann && !xDockWindow->isFloating() ) 351cdf0e10cSrcweir { 35244e86b95SOliver-Rainer Wittmann const awt::Rectangle aPosSize = xWindow->getPosSize(); 35344e86b95SOliver-Rainer Wittmann insertDockingAreaSize( 35444e86b95SOliver-Rainer Wittmann *(pConstIter), 35544e86b95SOliver-Rainer Wittmann aPosSize, 35644e86b95SOliver-Rainer Wittmann aDockingAreaSizeDatas[pConstIter->m_aDockedData.m_nDockedArea] ); 357cdf0e10cSrcweir } 358cdf0e10cSrcweir } 359cdf0e10cSrcweir } 360cdf0e10cSrcweir } 361cdf0e10cSrcweir 36244e86b95SOliver-Rainer Wittmann aReadLock.unlock(); 363cdf0e10cSrcweir } 364cdf0e10cSrcweir 36544e86b95SOliver-Rainer Wittmann aBorderSpace.Top() = calcDockingAreaSize( aDockingAreaSizeDatas[ui::DockingArea_DOCKINGAREA_TOP] ); 36644e86b95SOliver-Rainer Wittmann aBorderSpace.Bottom() = calcDockingAreaSize( aDockingAreaSizeDatas[ui::DockingArea_DOCKINGAREA_BOTTOM] ); 36744e86b95SOliver-Rainer Wittmann aBorderSpace.Left() = calcDockingAreaSize( aDockingAreaSizeDatas[ui::DockingArea_DOCKINGAREA_LEFT] ); 36844e86b95SOliver-Rainer Wittmann aBorderSpace.Right() = calcDockingAreaSize( aDockingAreaSizeDatas[ui::DockingArea_DOCKINGAREA_RIGHT] ); 36944e86b95SOliver-Rainer Wittmann 370cdf0e10cSrcweir return aBorderSpace; 371cdf0e10cSrcweir } 372cdf0e10cSrcweir 373cdf0e10cSrcweir void ToolbarLayoutManager::reset() 374cdf0e10cSrcweir { 375cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 376cdf0e10cSrcweir uno::Reference< ui::XUIConfigurationManager > xModuleCfgMgr( m_xModuleCfgMgr ); 377cdf0e10cSrcweir uno::Reference< ui::XUIConfigurationManager > xDocCfgMgr( m_xDocCfgMgr ); 378cdf0e10cSrcweir m_xModuleCfgMgr.clear(); 379cdf0e10cSrcweir m_xDocCfgMgr.clear(); 380cdf0e10cSrcweir m_bComponentAttached = false; 381cdf0e10cSrcweir aWriteLock.unlock(); 382cdf0e10cSrcweir 383cdf0e10cSrcweir destroyToolbars(); 384cdf0e10cSrcweir resetDockingArea(); 385cdf0e10cSrcweir } 386cdf0e10cSrcweir 387cdf0e10cSrcweir void ToolbarLayoutManager::attach( 388cdf0e10cSrcweir const uno::Reference< frame::XFrame >& xFrame, 389cdf0e10cSrcweir const uno::Reference< ui::XUIConfigurationManager >& xModuleCfgMgr, 390cdf0e10cSrcweir const uno::Reference< ui::XUIConfigurationManager >& xDocCfgMgr, 391cdf0e10cSrcweir const uno::Reference< container::XNameAccess >& xPersistentWindowState ) 392cdf0e10cSrcweir { 393cdf0e10cSrcweir // reset toolbar manager if we lose our current frame 394cdf0e10cSrcweir if ( m_xFrame.is() && m_xFrame != xFrame ) 395cdf0e10cSrcweir reset(); 396cdf0e10cSrcweir 397cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 398cdf0e10cSrcweir m_xFrame = xFrame; 399cdf0e10cSrcweir m_xModuleCfgMgr = xModuleCfgMgr; 400cdf0e10cSrcweir m_xDocCfgMgr = xDocCfgMgr; 401cdf0e10cSrcweir m_xPersistentWindowState = xPersistentWindowState; 402cdf0e10cSrcweir m_bComponentAttached = true; 403cdf0e10cSrcweir } 404cdf0e10cSrcweir 405cdf0e10cSrcweir void ToolbarLayoutManager::createStaticToolbars() 406cdf0e10cSrcweir { 407cdf0e10cSrcweir resetDockingArea(); 408cdf0e10cSrcweir implts_createCustomToolBars(); 409cdf0e10cSrcweir implts_createAddonsToolBars(); 410cdf0e10cSrcweir implts_createNonContextSensitiveToolBars(); 411cdf0e10cSrcweir implts_sortUIElements(); 412cdf0e10cSrcweir } 413cdf0e10cSrcweir 414cdf0e10cSrcweir bool ToolbarLayoutManager::requestToolbar( const ::rtl::OUString& rResourceURL ) 415cdf0e10cSrcweir { 416cdf0e10cSrcweir bool bNotify( false ); 417cdf0e10cSrcweir bool bMustCallCreate( false ); 418cdf0e10cSrcweir uno::Reference< ui::XUIElement > xUIElement; 419cdf0e10cSrcweir 420cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 421cdf0e10cSrcweir uno::Reference< frame::XFrame > xFrame( m_xFrame ); 422cdf0e10cSrcweir aReadLock.unlock(); 423cdf0e10cSrcweir 424cdf0e10cSrcweir uno::Reference< frame::XModel > xModel( impl_getModelFromFrame( xFrame )); 425cdf0e10cSrcweir if ( implts_isPreviewModel( xModel )) 426cdf0e10cSrcweir return false; // no toolbars for preview frame! 427cdf0e10cSrcweir 428cdf0e10cSrcweir UIElement aRequestedToolbar = impl_findToolbar( rResourceURL ); 429cdf0e10cSrcweir if ( aRequestedToolbar.m_aName != rResourceURL ) 430cdf0e10cSrcweir { 431cdf0e10cSrcweir bMustCallCreate = true; 432cdf0e10cSrcweir aRequestedToolbar.m_aName = rResourceURL; 433cdf0e10cSrcweir aRequestedToolbar.m_aType = m_aToolbarTypeString; 434cdf0e10cSrcweir aRequestedToolbar.m_xUIElement = xUIElement; 435cdf0e10cSrcweir implts_readWindowStateData( rResourceURL, aRequestedToolbar ); 436cdf0e10cSrcweir } 437cdf0e10cSrcweir 438cdf0e10cSrcweir xUIElement = aRequestedToolbar.m_xUIElement; 439cdf0e10cSrcweir if ( !xUIElement.is() ) 440cdf0e10cSrcweir bMustCallCreate = true; 441cdf0e10cSrcweir 442cdf0e10cSrcweir bool bCreateOrShowToolbar( aRequestedToolbar.m_bVisible & !aRequestedToolbar.m_bMasterHide ); 443cdf0e10cSrcweir uno::Reference< awt::XWindow2 > xContainerWindow( m_xContainerWindow, uno::UNO_QUERY ); 444cdf0e10cSrcweir if ( xContainerWindow.is() && aRequestedToolbar.m_bFloating ) 445cdf0e10cSrcweir bCreateOrShowToolbar &= bool( xContainerWindow->isActive()); 446cdf0e10cSrcweir 447cdf0e10cSrcweir if ( bCreateOrShowToolbar ) 448cdf0e10cSrcweir bNotify = ( bMustCallCreate ) ? createToolbar( rResourceURL ) : showToolbar( rResourceURL ); 449cdf0e10cSrcweir 450cdf0e10cSrcweir return bNotify; 451cdf0e10cSrcweir } 452cdf0e10cSrcweir 453cdf0e10cSrcweir bool ToolbarLayoutManager::createToolbar( const ::rtl::OUString& rResourceURL ) 454cdf0e10cSrcweir { 455cdf0e10cSrcweir bool bNotify( false ); 456cdf0e10cSrcweir uno::Reference< ui::XUIElement > xUITempElement; 457cdf0e10cSrcweir 458cdf0e10cSrcweir implts_createToolBar( rResourceURL, bNotify, xUITempElement ); 459cdf0e10cSrcweir return bNotify; 460cdf0e10cSrcweir } 461cdf0e10cSrcweir 462cdf0e10cSrcweir bool ToolbarLayoutManager::destroyToolbar( const ::rtl::OUString& rResourceURL ) 463cdf0e10cSrcweir { 464cdf0e10cSrcweir const rtl::OUString aAddonTbResourceName( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/addon_" )); 465cdf0e10cSrcweir 466cdf0e10cSrcweir UIElementVector::iterator pIter; 467cdf0e10cSrcweir uno::Reference< lang::XComponent > xComponent; 468cdf0e10cSrcweir 469cdf0e10cSrcweir bool bNotify( false ); 470cdf0e10cSrcweir bool bMustBeSorted( false ); 471cdf0e10cSrcweir bool bMustLayouted( false ); 472cdf0e10cSrcweir bool bMustBeDestroyed( rResourceURL.indexOf( aAddonTbResourceName ) != 0 ); 473cdf0e10cSrcweir 474cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 475cdf0e10cSrcweir for ( pIter = m_aUIElements.begin(); pIter != m_aUIElements.end(); pIter++ ) 476cdf0e10cSrcweir { 477cdf0e10cSrcweir if ( pIter->m_aName == rResourceURL ) 478cdf0e10cSrcweir { 479cdf0e10cSrcweir xComponent.set( pIter->m_xUIElement, uno::UNO_QUERY ); 480cdf0e10cSrcweir if ( bMustBeDestroyed ) 481cdf0e10cSrcweir pIter->m_xUIElement.clear(); 482cdf0e10cSrcweir else 483cdf0e10cSrcweir pIter->m_bVisible = false; 484cdf0e10cSrcweir break; 485cdf0e10cSrcweir } 486cdf0e10cSrcweir } 487cdf0e10cSrcweir aWriteLock.unlock(); 488cdf0e10cSrcweir 489cdf0e10cSrcweir uno::Reference< ui::XUIElement > xUIElement( xComponent, uno::UNO_QUERY ); 490cdf0e10cSrcweir if ( xUIElement.is() ) 491cdf0e10cSrcweir { 492cdf0e10cSrcweir uno::Reference< awt::XWindow > xWindow( xUIElement->getRealInterface(), uno::UNO_QUERY ); 493cdf0e10cSrcweir uno::Reference< awt::XDockableWindow > xDockWindow( xWindow, uno::UNO_QUERY ); 494cdf0e10cSrcweir 495cdf0e10cSrcweir if ( bMustBeDestroyed ) 496cdf0e10cSrcweir { 497cdf0e10cSrcweir try 498cdf0e10cSrcweir { 499cdf0e10cSrcweir if ( xWindow.is() ) 500cdf0e10cSrcweir xWindow->removeWindowListener( uno::Reference< awt::XWindowListener >( 501cdf0e10cSrcweir static_cast< OWeakObject * >( this ), uno::UNO_QUERY )); 502cdf0e10cSrcweir } 503cdf0e10cSrcweir catch( uno::Exception& ) {} 504cdf0e10cSrcweir 505cdf0e10cSrcweir try 506cdf0e10cSrcweir { 507cdf0e10cSrcweir if ( xDockWindow.is() ) 508cdf0e10cSrcweir xDockWindow->removeDockableWindowListener( uno::Reference< awt::XDockableWindowListener >( 509cdf0e10cSrcweir static_cast< OWeakObject * >( this ), uno::UNO_QUERY )); 510cdf0e10cSrcweir } 511cdf0e10cSrcweir catch ( uno::Exception& ) {} 512cdf0e10cSrcweir } 513cdf0e10cSrcweir else 514cdf0e10cSrcweir { 515cdf0e10cSrcweir if ( xWindow.is() ) 516cdf0e10cSrcweir xWindow->setVisible( sal_False ); 517cdf0e10cSrcweir bNotify = true; 518cdf0e10cSrcweir } 519cdf0e10cSrcweir 520cdf0e10cSrcweir if ( !xDockWindow->isFloating() ) 521cdf0e10cSrcweir bMustLayouted = true; 522cdf0e10cSrcweir bMustBeSorted = true; 523cdf0e10cSrcweir } 524cdf0e10cSrcweir 525cdf0e10cSrcweir if ( bMustBeDestroyed ) 526cdf0e10cSrcweir { 527cdf0e10cSrcweir if ( xComponent.is() ) 528cdf0e10cSrcweir xComponent->dispose(); 529cdf0e10cSrcweir bNotify = true; 530cdf0e10cSrcweir } 531cdf0e10cSrcweir 532cdf0e10cSrcweir if ( bMustLayouted ) 533cdf0e10cSrcweir implts_setLayoutDirty(); 534cdf0e10cSrcweir 535cdf0e10cSrcweir if ( bMustBeSorted ) 536cdf0e10cSrcweir implts_sortUIElements(); 537cdf0e10cSrcweir 538cdf0e10cSrcweir return bNotify; 539cdf0e10cSrcweir } 540cdf0e10cSrcweir 541cdf0e10cSrcweir void ToolbarLayoutManager::destroyToolbars() 542cdf0e10cSrcweir { 543cdf0e10cSrcweir UIElementVector aUIElementVector; 544cdf0e10cSrcweir implts_getUIElementVectorCopy( aUIElementVector ); 545cdf0e10cSrcweir 546cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 547cdf0e10cSrcweir m_aUIElements.clear(); 548cdf0e10cSrcweir m_bLayoutDirty = true; 549cdf0e10cSrcweir aWriteLock.unlock(); 550cdf0e10cSrcweir 551cdf0e10cSrcweir UIElementVector::iterator pIter; 552cdf0e10cSrcweir for ( pIter = aUIElementVector.begin(); pIter != aUIElementVector.end(); pIter++ ) 553cdf0e10cSrcweir { 554cdf0e10cSrcweir uno::Reference< lang::XComponent > xComponent( pIter->m_xUIElement, uno::UNO_QUERY ); 555cdf0e10cSrcweir if ( xComponent.is() ) 556cdf0e10cSrcweir xComponent->dispose(); 557cdf0e10cSrcweir } 558cdf0e10cSrcweir } 559cdf0e10cSrcweir 56044e86b95SOliver-Rainer Wittmann bool ToolbarLayoutManager::implts_setToolbarVisibility( 56144e86b95SOliver-Rainer Wittmann bool bVisible, 56244e86b95SOliver-Rainer Wittmann UIElement aUIElement ) 563cdf0e10cSrcweir { 56444e86b95SOliver-Rainer Wittmann bool bRet = false; 56544e86b95SOliver-Rainer Wittmann 566cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 567cdf0e10cSrcweir Window* pWindow = getWindowFromXUIElement( aUIElement.m_xUIElement ); 568cdf0e10cSrcweir if ( pWindow ) 569cdf0e10cSrcweir { 57044e86b95SOliver-Rainer Wittmann if ( bVisible ) 57144e86b95SOliver-Rainer Wittmann { 57244e86b95SOliver-Rainer Wittmann pWindow->Show( sal_True, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE ); 57344e86b95SOliver-Rainer Wittmann } 57444e86b95SOliver-Rainer Wittmann else 57544e86b95SOliver-Rainer Wittmann { 57644e86b95SOliver-Rainer Wittmann pWindow->Show( sal_False ); 57744e86b95SOliver-Rainer Wittmann } 578cdf0e10cSrcweir if ( !aUIElement.m_bFloating ) 57944e86b95SOliver-Rainer Wittmann { 580cdf0e10cSrcweir implts_setLayoutDirty(); 58144e86b95SOliver-Rainer Wittmann } 58244e86b95SOliver-Rainer Wittmann 58344e86b95SOliver-Rainer Wittmann bRet = true; 584cdf0e10cSrcweir } 58544e86b95SOliver-Rainer Wittmann 58644e86b95SOliver-Rainer Wittmann return bRet; 587cdf0e10cSrcweir } 588cdf0e10cSrcweir 58944e86b95SOliver-Rainer Wittmann bool ToolbarLayoutManager::showToolbar( const ::rtl::OUString& rResourceURL ) 590cdf0e10cSrcweir { 591cdf0e10cSrcweir UIElement aUIElement = implts_findToolbar( rResourceURL ); 59244e86b95SOliver-Rainer Wittmann const bool bRet = implts_setToolbarVisibility( true, aUIElement ); 593ffdd8a15SOliver-Rainer Wittmann aUIElement.m_bVisible = true; 594ffdd8a15SOliver-Rainer Wittmann implts_writeWindowStateData( aUIElement ); 595ffdd8a15SOliver-Rainer Wittmann implts_setToolbar( aUIElement ); 59644e86b95SOliver-Rainer Wittmann implts_sortUIElements(); 59744e86b95SOliver-Rainer Wittmann return bRet; 59844e86b95SOliver-Rainer Wittmann } 599cdf0e10cSrcweir 60044e86b95SOliver-Rainer Wittmann bool ToolbarLayoutManager::hideToolbar( const ::rtl::OUString& rResourceURL ) 60144e86b95SOliver-Rainer Wittmann { 60244e86b95SOliver-Rainer Wittmann UIElement aUIElement = implts_findToolbar( rResourceURL ); 60344e86b95SOliver-Rainer Wittmann const bool bRet = implts_setToolbarVisibility( false, aUIElement ); 604ffdd8a15SOliver-Rainer Wittmann aUIElement.m_bVisible = false; 605ffdd8a15SOliver-Rainer Wittmann implts_writeWindowStateData( aUIElement ); 606ffdd8a15SOliver-Rainer Wittmann implts_setToolbar( aUIElement ); 60744e86b95SOliver-Rainer Wittmann implts_sortUIElements(); 60844e86b95SOliver-Rainer Wittmann return bRet; 609cdf0e10cSrcweir } 610cdf0e10cSrcweir 611cdf0e10cSrcweir void ToolbarLayoutManager::refreshToolbarsVisibility( bool bAutomaticToolbars ) 612cdf0e10cSrcweir { 61344e86b95SOliver-Rainer Wittmann if ( !bAutomaticToolbars ) 61444e86b95SOliver-Rainer Wittmann return; 615cdf0e10cSrcweir 616cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 61744e86b95SOliver-Rainer Wittmann if ( !m_bVisible ) 618cdf0e10cSrcweir return; 61944e86b95SOliver-Rainer Wittmann aReadLock.unlock(); 620cdf0e10cSrcweir 62144e86b95SOliver-Rainer Wittmann UIElementVector aUIElementVector; 622cdf0e10cSrcweir implts_getUIElementVectorCopy( aUIElementVector ); 62344e86b95SOliver-Rainer Wittmann 624cdf0e10cSrcweir UIElement aUIElement; 625cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 626cdf0e10cSrcweir UIElementVector::iterator pIter; 627cdf0e10cSrcweir for ( pIter = aUIElementVector.begin(); pIter != aUIElementVector.end(); pIter++ ) 628cdf0e10cSrcweir { 629cdf0e10cSrcweir if ( implts_readWindowStateData( pIter->m_aName, aUIElement ) && 630cdf0e10cSrcweir ( pIter->m_bVisible != aUIElement.m_bVisible ) && !pIter->m_bMasterHide ) 631cdf0e10cSrcweir { 632cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 633cdf0e10cSrcweir UIElement& rUIElement = impl_findToolbar( pIter->m_aName ); 634cdf0e10cSrcweir if ( rUIElement.m_aName == pIter->m_aName ) 635cdf0e10cSrcweir { 636cdf0e10cSrcweir rUIElement.m_bVisible = aUIElement.m_bVisible; 637cdf0e10cSrcweir implts_setLayoutDirty(); 638cdf0e10cSrcweir } 639cdf0e10cSrcweir } 640cdf0e10cSrcweir } 641cdf0e10cSrcweir } 642cdf0e10cSrcweir 643cdf0e10cSrcweir void ToolbarLayoutManager::setFloatingToolbarsVisibility( bool bVisible ) 644cdf0e10cSrcweir { 645cdf0e10cSrcweir UIElementVector aUIElementVector; 646cdf0e10cSrcweir implts_getUIElementVectorCopy( aUIElementVector ); 647cdf0e10cSrcweir 648cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 649cdf0e10cSrcweir UIElementVector::iterator pIter; 650cdf0e10cSrcweir for ( pIter = aUIElementVector.begin(); pIter != aUIElementVector.end(); pIter++ ) 651cdf0e10cSrcweir { 652cdf0e10cSrcweir Window* pWindow = getWindowFromXUIElement( pIter->m_xUIElement ); 653cdf0e10cSrcweir if ( pWindow && pIter->m_bFloating ) 654cdf0e10cSrcweir { 655cdf0e10cSrcweir if ( bVisible ) 656ffdd8a15SOliver-Rainer Wittmann { 657cdf0e10cSrcweir if ( pIter->m_bVisible && !pIter->m_bMasterHide ) 658cdf0e10cSrcweir pWindow->Show( sal_True, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE ); 659cdf0e10cSrcweir } 660cdf0e10cSrcweir else 661cdf0e10cSrcweir pWindow->Show( sal_False ); 662ffdd8a15SOliver-Rainer Wittmann } 663cdf0e10cSrcweir } 664cdf0e10cSrcweir } 665cdf0e10cSrcweir 666cdf0e10cSrcweir void ToolbarLayoutManager::setVisible( bool bVisible ) 667cdf0e10cSrcweir { 668cdf0e10cSrcweir UIElementVector aUIElementVector; 669cdf0e10cSrcweir implts_getUIElementVectorCopy( aUIElementVector ); 67044e86b95SOliver-Rainer Wittmann 671cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 672cdf0e10cSrcweir UIElementVector::iterator pIter; 673cdf0e10cSrcweir for ( pIter = aUIElementVector.begin(); pIter != aUIElementVector.end(); pIter++ ) 674cdf0e10cSrcweir { 67544e86b95SOliver-Rainer Wittmann implts_setToolbarVisibility( bVisible, *pIter ); 676ffdd8a15SOliver-Rainer Wittmann pIter->m_bMasterHide = !bVisible; 677ffdd8a15SOliver-Rainer Wittmann implts_setToolbar( *pIter ); 678cdf0e10cSrcweir } 67944e86b95SOliver-Rainer Wittmann 68044e86b95SOliver-Rainer Wittmann implts_sortUIElements(); 68144e86b95SOliver-Rainer Wittmann 682cdf0e10cSrcweir if ( !bVisible ) 683cdf0e10cSrcweir resetDockingArea(); 684cdf0e10cSrcweir } 685cdf0e10cSrcweir 686cdf0e10cSrcweir bool ToolbarLayoutManager::dockToolbar( const ::rtl::OUString& rResourceURL, ui::DockingArea eDockingArea, const awt::Point& aPos ) 687cdf0e10cSrcweir { 688cdf0e10cSrcweir UIElement aUIElement = implts_findToolbar( rResourceURL ); 689cdf0e10cSrcweir 690cdf0e10cSrcweir if ( aUIElement.m_xUIElement.is() ) 691cdf0e10cSrcweir { 692cdf0e10cSrcweir try 693cdf0e10cSrcweir { 694cdf0e10cSrcweir uno::Reference< awt::XWindow > xWindow( aUIElement.m_xUIElement->getRealInterface(), uno::UNO_QUERY ); 695cdf0e10cSrcweir uno::Reference< awt::XDockableWindow > xDockWindow( xWindow, uno::UNO_QUERY ); 696cdf0e10cSrcweir if ( xDockWindow.is() ) 697cdf0e10cSrcweir { 698cdf0e10cSrcweir if ( eDockingArea != ui::DockingArea_DOCKINGAREA_DEFAULT ) 699cdf0e10cSrcweir aUIElement.m_aDockedData.m_nDockedArea = sal_Int16( eDockingArea ); 700cdf0e10cSrcweir 701cdf0e10cSrcweir if ( !isDefaultPos( aPos )) 702cdf0e10cSrcweir aUIElement.m_aDockedData.m_aPos = ::Point( aPos.X, aPos.Y ); 703cdf0e10cSrcweir 704cdf0e10cSrcweir if ( !xDockWindow->isFloating() ) 705cdf0e10cSrcweir { 706cdf0e10cSrcweir Window* pWindow( 0 ); 707cdf0e10cSrcweir ToolBox* pToolBox( 0 ); 708cdf0e10cSrcweir 709cdf0e10cSrcweir { 710cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 711cdf0e10cSrcweir pWindow = VCLUnoHelper::GetWindow( xWindow ); 712cdf0e10cSrcweir if ( pWindow && pWindow->GetType() == WINDOW_TOOLBOX ) 713cdf0e10cSrcweir { 714cdf0e10cSrcweir pToolBox = (ToolBox *)pWindow; 715cdf0e10cSrcweir 716cdf0e10cSrcweir // We have to set the alignment of the toolbox. It's possible that the toolbox is moved from a 717cdf0e10cSrcweir // horizontal to a vertical docking area! 718cdf0e10cSrcweir pToolBox->SetAlign( ImplConvertAlignment( aUIElement.m_aDockedData.m_nDockedArea )); 719cdf0e10cSrcweir } 720cdf0e10cSrcweir } 721cdf0e10cSrcweir 722cdf0e10cSrcweir if ( hasDefaultPosValue( aUIElement.m_aDockedData.m_aPos )) 723cdf0e10cSrcweir { 724cdf0e10cSrcweir // Docking on its default position without a preset position - 725cdf0e10cSrcweir // we have to find a good place for it. 726cdf0e10cSrcweir ::Size aSize; 727cdf0e10cSrcweir 728cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 729cdf0e10cSrcweir { 730cdf0e10cSrcweir if ( pToolBox ) 731cdf0e10cSrcweir aSize = pToolBox->CalcWindowSizePixel( 1, ImplConvertAlignment( aUIElement.m_aDockedData.m_nDockedArea ) ); 732cdf0e10cSrcweir else 733cdf0e10cSrcweir aSize = pWindow->GetSizePixel(); 734cdf0e10cSrcweir } 735cdf0e10cSrcweir 736cdf0e10cSrcweir ::Point aPixelPos; 737cdf0e10cSrcweir ::Point aDockPos; 738cdf0e10cSrcweir implts_findNextDockingPos((ui::DockingArea)aUIElement.m_aDockedData.m_nDockedArea, aSize, aDockPos, aPixelPos ); 739cdf0e10cSrcweir aUIElement.m_aDockedData.m_aPos = aDockPos; 740cdf0e10cSrcweir } 741cdf0e10cSrcweir } 742cdf0e10cSrcweir 743cdf0e10cSrcweir implts_setToolbar( aUIElement ); 744cdf0e10cSrcweir 745cdf0e10cSrcweir if ( xDockWindow->isFloating() ) 746cdf0e10cSrcweir { 747cdf0e10cSrcweir // ATTENTION: This will call toggleFloatingMode() via notifications which 748cdf0e10cSrcweir // sets the floating member of the UIElement correctly! 749cdf0e10cSrcweir xDockWindow->setFloatingMode( sal_False ); 750cdf0e10cSrcweir } 751cdf0e10cSrcweir else 752cdf0e10cSrcweir { 753cdf0e10cSrcweir implts_writeWindowStateData( aUIElement ); 754cdf0e10cSrcweir implts_sortUIElements(); 755cdf0e10cSrcweir 756cdf0e10cSrcweir if ( aUIElement.m_bVisible ) 757cdf0e10cSrcweir implts_setLayoutDirty(); 758cdf0e10cSrcweir } 759cdf0e10cSrcweir return true; 760cdf0e10cSrcweir } 761cdf0e10cSrcweir } 762cdf0e10cSrcweir catch ( lang::DisposedException& ) {} 763cdf0e10cSrcweir } 764cdf0e10cSrcweir 765cdf0e10cSrcweir return false; 766cdf0e10cSrcweir } 767cdf0e10cSrcweir 768cdf0e10cSrcweir bool ToolbarLayoutManager::dockAllToolbars() 769cdf0e10cSrcweir { 770cdf0e10cSrcweir std::vector< ::rtl::OUString > aToolBarNameVector; 771cdf0e10cSrcweir 772cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 773cdf0e10cSrcweir UIElementVector::iterator pIter; 774cdf0e10cSrcweir for ( pIter = m_aUIElements.begin(); pIter != m_aUIElements.end(); pIter++ ) 775cdf0e10cSrcweir { 776ffdd8a15SOliver-Rainer Wittmann if ( pIter->m_aType.equalsAscii( "toolbar" ) 777ffdd8a15SOliver-Rainer Wittmann && pIter->m_xUIElement.is() 778ffdd8a15SOliver-Rainer Wittmann && pIter->m_bFloating 779ffdd8a15SOliver-Rainer Wittmann && pIter->m_bVisible 780ffdd8a15SOliver-Rainer Wittmann && !pIter->m_bMasterHide ) 781ffdd8a15SOliver-Rainer Wittmann { 782cdf0e10cSrcweir aToolBarNameVector.push_back( pIter->m_aName ); 783ffdd8a15SOliver-Rainer Wittmann } 784cdf0e10cSrcweir } 785cdf0e10cSrcweir aReadLock.unlock(); 786cdf0e10cSrcweir 787cdf0e10cSrcweir bool bResult(true); 788cdf0e10cSrcweir const sal_uInt32 nCount = aToolBarNameVector.size(); 789cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < nCount; ++i ) 790cdf0e10cSrcweir { 791cdf0e10cSrcweir awt::Point aPoint; 792cdf0e10cSrcweir aPoint.X = aPoint.Y = SAL_MAX_INT32; 793cdf0e10cSrcweir bResult &= dockToolbar( aToolBarNameVector[i], ui::DockingArea_DOCKINGAREA_DEFAULT, aPoint ); 794cdf0e10cSrcweir } 795cdf0e10cSrcweir 796cdf0e10cSrcweir return bResult; 797cdf0e10cSrcweir } 798cdf0e10cSrcweir 799cdf0e10cSrcweir long ToolbarLayoutManager::childWindowEvent( VclSimpleEvent* pEvent ) 800cdf0e10cSrcweir { 801cdf0e10cSrcweir // To enable toolbar controllers to change their image when a sub-toolbar function 802cdf0e10cSrcweir // is activated, we need this mechanism. We have NO connection between these toolbars 803cdf0e10cSrcweir // anymore! 804cdf0e10cSrcweir if ( pEvent && pEvent->ISA( VclWindowEvent )) 805cdf0e10cSrcweir { 806cdf0e10cSrcweir if ( pEvent->GetId() == VCLEVENT_TOOLBOX_SELECT ) 807cdf0e10cSrcweir { 808cdf0e10cSrcweir ::rtl::OUString aToolbarName; 809cdf0e10cSrcweir ::rtl::OUString aCommand; 810cdf0e10cSrcweir ToolBox* pToolBox = getToolboxPtr( ((VclWindowEvent*)pEvent)->GetWindow() ); 811cdf0e10cSrcweir 812cdf0e10cSrcweir if ( pToolBox ) 813cdf0e10cSrcweir { 814cdf0e10cSrcweir aToolbarName = retrieveToolbarNameFromHelpURL( pToolBox ); 815cdf0e10cSrcweir sal_uInt16 nId = pToolBox->GetCurItemId(); 816cdf0e10cSrcweir if ( nId > 0 ) 817cdf0e10cSrcweir aCommand = pToolBox->GetItemCommand( nId ); 818cdf0e10cSrcweir } 819cdf0e10cSrcweir 820cdf0e10cSrcweir if (( aToolbarName.getLength() > 0 ) && ( aCommand.getLength() > 0 )) 821cdf0e10cSrcweir { 822cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 823cdf0e10cSrcweir ::std::vector< uno::Reference< ui::XUIFunctionListener > > aListenerArray; 824cdf0e10cSrcweir UIElementVector::iterator pIter; 825cdf0e10cSrcweir 826cdf0e10cSrcweir for ( pIter = m_aUIElements.begin(); pIter != m_aUIElements.end(); pIter++ ) 827cdf0e10cSrcweir { 828cdf0e10cSrcweir if ( pIter->m_xUIElement.is() ) 829cdf0e10cSrcweir { 830cdf0e10cSrcweir uno::Reference< ui::XUIFunctionListener > xListener( pIter->m_xUIElement, uno::UNO_QUERY ); 831cdf0e10cSrcweir if ( xListener.is() ) 832cdf0e10cSrcweir aListenerArray.push_back( xListener ); 833cdf0e10cSrcweir } 834cdf0e10cSrcweir } 835cdf0e10cSrcweir aReadLock.unlock(); 836cdf0e10cSrcweir 837cdf0e10cSrcweir const sal_uInt32 nCount = aListenerArray.size(); 838cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < nCount; ++i ) 839cdf0e10cSrcweir { 840cdf0e10cSrcweir try { aListenerArray[i]->functionExecute( aToolbarName, aCommand ); } 841cdf0e10cSrcweir catch ( uno::RuntimeException& ) { throw; } 842cdf0e10cSrcweir catch ( uno::Exception& ) {} 843cdf0e10cSrcweir } 844cdf0e10cSrcweir } 845cdf0e10cSrcweir } 846cdf0e10cSrcweir else if ( pEvent->GetId() == VCLEVENT_TOOLBOX_FORMATCHANGED ) 847cdf0e10cSrcweir { 848cdf0e10cSrcweir if ( !implts_isToolbarCreationActive() ) 849cdf0e10cSrcweir { 850cdf0e10cSrcweir ToolBox* pToolBox = getToolboxPtr( ((VclWindowEvent*)pEvent)->GetWindow() ); 851cdf0e10cSrcweir if ( pToolBox ) 852cdf0e10cSrcweir { 853cdf0e10cSrcweir ::rtl::OUString aToolbarName = retrieveToolbarNameFromHelpURL( pToolBox ); 854cdf0e10cSrcweir if ( aToolbarName.getLength() > 0 ) 855cdf0e10cSrcweir { 856cdf0e10cSrcweir ::rtl::OUStringBuffer aBuf(100); 857cdf0e10cSrcweir aBuf.appendAscii( "private:resource/toolbar/" ); 858cdf0e10cSrcweir aBuf.append( aToolbarName ); 859cdf0e10cSrcweir 860cdf0e10cSrcweir UIElement aToolbar = implts_findToolbar( aBuf.makeStringAndClear() ); 861cdf0e10cSrcweir if ( aToolbar.m_xUIElement.is() && !aToolbar.m_bFloating ) 862cdf0e10cSrcweir { 863cdf0e10cSrcweir implts_setLayoutDirty(); 864cdf0e10cSrcweir m_pParentLayouter->requestLayout( ILayoutNotifications::HINT_TOOLBARSPACE_HAS_CHANGED ); 865cdf0e10cSrcweir } 866cdf0e10cSrcweir } 867cdf0e10cSrcweir } 868cdf0e10cSrcweir } 869cdf0e10cSrcweir } 870cdf0e10cSrcweir } 871cdf0e10cSrcweir 872cdf0e10cSrcweir return 1; 873cdf0e10cSrcweir } 874cdf0e10cSrcweir 875cdf0e10cSrcweir void ToolbarLayoutManager::resetDockingArea() 876cdf0e10cSrcweir { 877cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 878cdf0e10cSrcweir uno::Reference< awt::XWindow > xTopDockingWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_TOP] ); 879cdf0e10cSrcweir uno::Reference< awt::XWindow > xLeftDockingWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_LEFT] ); 880cdf0e10cSrcweir uno::Reference< awt::XWindow > xRightDockingWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_RIGHT] ); 881cdf0e10cSrcweir uno::Reference< awt::XWindow > xBottomDockingWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_BOTTOM] ); 882cdf0e10cSrcweir aReadLock.unlock(); 883cdf0e10cSrcweir 884cdf0e10cSrcweir if ( xTopDockingWindow.is() ) 885cdf0e10cSrcweir xTopDockingWindow->setPosSize( 0, 0, 0, 0, awt::PosSize::POSSIZE ); 886cdf0e10cSrcweir if ( xLeftDockingWindow.is() ) 887cdf0e10cSrcweir xLeftDockingWindow->setPosSize( 0, 0, 0, 0, awt::PosSize::POSSIZE ); 888cdf0e10cSrcweir if ( xRightDockingWindow.is() ) 889cdf0e10cSrcweir xRightDockingWindow->setPosSize( 0, 0, 0, 0, awt::PosSize::POSSIZE ); 890cdf0e10cSrcweir if ( xBottomDockingWindow.is() ) 891cdf0e10cSrcweir xBottomDockingWindow->setPosSize( 0, 0, 0, 0, awt::PosSize::POSSIZE ); 892cdf0e10cSrcweir } 893cdf0e10cSrcweir 894cdf0e10cSrcweir void ToolbarLayoutManager::setParentWindow( 895cdf0e10cSrcweir const uno::Reference< awt::XWindowPeer >& xParentWindow ) 896cdf0e10cSrcweir { 897cdf0e10cSrcweir static const char DOCKINGAREASTRING[] = "dockingarea"; 898cdf0e10cSrcweir 899cdf0e10cSrcweir uno::Reference< awt::XWindow > xTopDockWindow = uno::Reference< awt::XWindow >( createToolkitWindow( m_xSMGR, xParentWindow, DOCKINGAREASTRING ), uno::UNO_QUERY ); 900cdf0e10cSrcweir uno::Reference< awt::XWindow > xLeftDockWindow = uno::Reference< awt::XWindow >( createToolkitWindow( m_xSMGR, xParentWindow, DOCKINGAREASTRING ), uno::UNO_QUERY ); 901cdf0e10cSrcweir uno::Reference< awt::XWindow > xRightDockWindow = uno::Reference< awt::XWindow >( createToolkitWindow( m_xSMGR, xParentWindow, DOCKINGAREASTRING ), uno::UNO_QUERY ); 902cdf0e10cSrcweir uno::Reference< awt::XWindow > xBottomDockWindow = uno::Reference< awt::XWindow >( createToolkitWindow( m_xSMGR, xParentWindow, DOCKINGAREASTRING ), uno::UNO_QUERY ); 903cdf0e10cSrcweir 904cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 905cdf0e10cSrcweir m_xContainerWindow = uno::Reference< awt::XWindow2 >( xParentWindow, uno::UNO_QUERY ); 906cdf0e10cSrcweir m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_TOP] = xTopDockWindow; 907cdf0e10cSrcweir m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_LEFT] = xLeftDockWindow; 908cdf0e10cSrcweir m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_RIGHT] = xRightDockWindow; 909cdf0e10cSrcweir m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_BOTTOM] = xBottomDockWindow; 910cdf0e10cSrcweir aWriteLock.unlock(); 911cdf0e10cSrcweir 912cdf0e10cSrcweir if ( xParentWindow.is() ) 913cdf0e10cSrcweir { 914cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 915cdf0e10cSrcweir ::DockingAreaWindow* pWindow = dynamic_cast< ::DockingAreaWindow* >(VCLUnoHelper::GetWindow( xTopDockWindow ) ); 916cdf0e10cSrcweir if( pWindow ) pWindow->SetAlign( WINDOWALIGN_TOP ); 917cdf0e10cSrcweir pWindow = dynamic_cast< ::DockingAreaWindow* >(VCLUnoHelper::GetWindow( xBottomDockWindow ) ); 918cdf0e10cSrcweir if( pWindow ) pWindow->SetAlign( WINDOWALIGN_BOTTOM ); 919cdf0e10cSrcweir pWindow = dynamic_cast< ::DockingAreaWindow* >(VCLUnoHelper::GetWindow( xLeftDockWindow ) ); 920cdf0e10cSrcweir if( pWindow ) pWindow->SetAlign( WINDOWALIGN_LEFT ); 921cdf0e10cSrcweir pWindow = dynamic_cast< ::DockingAreaWindow* >(VCLUnoHelper::GetWindow( xRightDockWindow ) ); 922cdf0e10cSrcweir if( pWindow ) pWindow->SetAlign( WINDOWALIGN_RIGHT ); 923cdf0e10cSrcweir implts_reparentToolbars(); 924cdf0e10cSrcweir } 925cdf0e10cSrcweir else 926cdf0e10cSrcweir { 927cdf0e10cSrcweir destroyToolbars(); 928cdf0e10cSrcweir resetDockingArea(); 929cdf0e10cSrcweir } 930cdf0e10cSrcweir } 931cdf0e10cSrcweir 932cdf0e10cSrcweir void ToolbarLayoutManager::setDockingAreaOffsets( const ::Rectangle aOffsets ) 933cdf0e10cSrcweir { 934cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 935cdf0e10cSrcweir m_aDockingAreaOffsets = aOffsets; 936cdf0e10cSrcweir m_bLayoutDirty = true; 937cdf0e10cSrcweir } 938cdf0e10cSrcweir 939cdf0e10cSrcweir rtl::OUString ToolbarLayoutManager::implts_generateGenericAddonToolbarTitle( sal_Int32 nNumber ) const 940cdf0e10cSrcweir { 941cdf0e10cSrcweir String aAddonGenericTitle; 942cdf0e10cSrcweir 943cdf0e10cSrcweir aAddonGenericTitle = String( FwkResId( STR_TOOLBAR_TITLE_ADDON )); 944cdf0e10cSrcweir const vcl::I18nHelper& rI18nHelper = Application::GetSettings().GetUILocaleI18nHelper(); 945cdf0e10cSrcweir 946cdf0e10cSrcweir String aNumStr = rI18nHelper.GetNum( nNumber, 0, sal_False, sal_False ); 947cdf0e10cSrcweir aAddonGenericTitle.SearchAndReplaceAscii( "%num%", aNumStr ); 948cdf0e10cSrcweir 949cdf0e10cSrcweir return rtl::OUString( aAddonGenericTitle ); 950cdf0e10cSrcweir } 951cdf0e10cSrcweir 952cdf0e10cSrcweir void ToolbarLayoutManager::implts_createAddonsToolBars() 953cdf0e10cSrcweir { 954cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 955cdf0e10cSrcweir if ( !m_pAddonOptions ) 956cdf0e10cSrcweir m_pAddonOptions = new AddonsOptions; 957cdf0e10cSrcweir 958cdf0e10cSrcweir uno::Reference< ui::XUIElementFactory > xUIElementFactory( m_xUIElementFactoryManager ); 959cdf0e10cSrcweir uno::Reference< frame::XFrame > xFrame( m_xFrame ); 960cdf0e10cSrcweir aWriteLock.unlock(); 961cdf0e10cSrcweir 962cdf0e10cSrcweir uno::Reference< frame::XModel > xModel( impl_getModelFromFrame( xFrame )); 963cdf0e10cSrcweir if ( implts_isPreviewModel( xModel )) 964cdf0e10cSrcweir return; // no addon toolbars for preview frame! 965cdf0e10cSrcweir 966cdf0e10cSrcweir UIElementVector aUIElementVector; 967cdf0e10cSrcweir uno::Sequence< uno::Sequence< beans::PropertyValue > > aAddonToolBarData; 968cdf0e10cSrcweir uno::Reference< ui::XUIElement > xUIElement; 969cdf0e10cSrcweir 970cdf0e10cSrcweir sal_uInt32 nCount = m_pAddonOptions->GetAddonsToolBarCount(); 971cdf0e10cSrcweir ::rtl::OUString aAddonsToolBarStaticName( m_aFullAddonTbxPrefix ); 972cdf0e10cSrcweir ::rtl::OUString aElementType( RTL_CONSTASCII_USTRINGPARAM( "toolbar" )); 973cdf0e10cSrcweir 974cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aPropSeq( 2 ); 975cdf0e10cSrcweir aPropSeq[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" )); 976cdf0e10cSrcweir aPropSeq[0].Value <<= xFrame; 977cdf0e10cSrcweir aPropSeq[1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ConfigurationData" )); 978cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < nCount; i++ ) 979cdf0e10cSrcweir { 980cdf0e10cSrcweir ::rtl::OUString aAddonToolBarName( aAddonsToolBarStaticName + m_pAddonOptions->GetAddonsToolbarResourceName(i) ); 981cdf0e10cSrcweir aAddonToolBarData = m_pAddonOptions->GetAddonsToolBarPart( i ); 982cdf0e10cSrcweir aPropSeq[1].Value <<= aAddonToolBarData; 983cdf0e10cSrcweir 984cdf0e10cSrcweir UIElement aElement = implts_findToolbar( aAddonToolBarName ); 985cdf0e10cSrcweir 986cdf0e10cSrcweir // #i79828 987cdf0e10cSrcweir // It's now possible that we are called more than once. Be sure to not create 988cdf0e10cSrcweir // add-on toolbars more than once! 989cdf0e10cSrcweir if ( aElement.m_xUIElement.is() ) 990cdf0e10cSrcweir continue; 991cdf0e10cSrcweir 992cdf0e10cSrcweir try 993cdf0e10cSrcweir { 994cdf0e10cSrcweir xUIElement = xUIElementFactory->createUIElement( aAddonToolBarName, aPropSeq ); 995cdf0e10cSrcweir if ( xUIElement.is() ) 996cdf0e10cSrcweir { 997cdf0e10cSrcweir uno::Reference< awt::XDockableWindow > xDockWindow( xUIElement->getRealInterface(), uno::UNO_QUERY ); 998cdf0e10cSrcweir if ( xDockWindow.is() ) 999cdf0e10cSrcweir { 1000cdf0e10cSrcweir try 1001cdf0e10cSrcweir { 1002cdf0e10cSrcweir xDockWindow->addDockableWindowListener( uno::Reference< awt::XDockableWindowListener >( static_cast< OWeakObject * >( this ), uno::UNO_QUERY )); 1003cdf0e10cSrcweir xDockWindow->enableDocking( sal_True ); 1004cdf0e10cSrcweir uno::Reference< awt::XWindow > xWindow( xDockWindow, uno::UNO_QUERY ); 1005cdf0e10cSrcweir if ( xWindow.is() ) 1006cdf0e10cSrcweir xWindow->addWindowListener( uno::Reference< awt::XWindowListener >( static_cast< OWeakObject * >( this ), uno::UNO_QUERY )); 1007cdf0e10cSrcweir } 1008cdf0e10cSrcweir catch ( uno::Exception& ) {} 1009cdf0e10cSrcweir } 1010cdf0e10cSrcweir 101126169348SAriel Constenla-Haile ::rtl::OUString aAddonUIName = m_pAddonOptions->GetAddonsToolbarUIName( i ); 1012bb0b5665SAriel Constenla-Haile const bool bAddonUIName = aAddonUIName.getLength(); 1013bb0b5665SAriel Constenla-Haile ::rtl::OUString aAddonTitle = bAddonUIName ? 101426169348SAriel Constenla-Haile aAddonUIName : implts_generateGenericAddonToolbarTitle( i+1 ); 1015cdf0e10cSrcweir 1016cdf0e10cSrcweir if ( aElement.m_aName.getLength() > 0 ) 1017cdf0e10cSrcweir { 1018cdf0e10cSrcweir // Reuse a local entry so we are able to use the latest 1019cdf0e10cSrcweir // UI changes for this document. 1020cdf0e10cSrcweir implts_setElementData( aElement, xDockWindow ); 1021cdf0e10cSrcweir aElement.m_xUIElement = xUIElement; 1022bb0b5665SAriel Constenla-Haile if ( aElement.m_aUIName.getLength() == 0 && !bAddonUIName) 1023cdf0e10cSrcweir { 102426169348SAriel Constenla-Haile aElement.m_aUIName = aAddonTitle; 1025cdf0e10cSrcweir implts_writeWindowStateData( aElement ); 1026cdf0e10cSrcweir } 1027cdf0e10cSrcweir } 1028cdf0e10cSrcweir else 1029cdf0e10cSrcweir { 1030cdf0e10cSrcweir // Create new UI element and try to read its state data 1031cdf0e10cSrcweir UIElement aNewToolbar( aAddonToolBarName, aElementType, xUIElement ); 1032cdf0e10cSrcweir aNewToolbar.m_bFloating = true; 1033cdf0e10cSrcweir implts_readWindowStateData( aAddonToolBarName, aNewToolbar ); 1034cdf0e10cSrcweir implts_setElementData( aNewToolbar, xDockWindow ); 1035bb0b5665SAriel Constenla-Haile if ( aNewToolbar.m_aUIName.getLength() == 0 && !bAddonUIName) 1036cdf0e10cSrcweir { 103726169348SAriel Constenla-Haile aNewToolbar.m_aUIName = aAddonTitle; 1038cdf0e10cSrcweir implts_writeWindowStateData( aNewToolbar ); 1039cdf0e10cSrcweir } 1040cdf0e10cSrcweir implts_insertToolbar( aNewToolbar ); 1041cdf0e10cSrcweir } 1042cdf0e10cSrcweir 1043cdf0e10cSrcweir uno::Reference< awt::XWindow > xWindow( xDockWindow, uno::UNO_QUERY ); 1044cdf0e10cSrcweir if ( xWindow.is() ) 1045cdf0e10cSrcweir { 1046cdf0e10cSrcweir // Set generic title for add-on toolbar 1047cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 1048cdf0e10cSrcweir Window* pWindow = VCLUnoHelper::GetWindow( xWindow ); 1049cdf0e10cSrcweir if ( pWindow->GetText().Len() == 0 ) 105026169348SAriel Constenla-Haile pWindow->SetText( aAddonTitle ); 1051cdf0e10cSrcweir if ( pWindow->GetType() == WINDOW_TOOLBOX ) 1052cdf0e10cSrcweir { 1053cdf0e10cSrcweir ToolBox* pToolbar = (ToolBox *)pWindow; 1054cdf0e10cSrcweir pToolbar->SetMenuType(); 1055cdf0e10cSrcweir } 1056cdf0e10cSrcweir } 1057cdf0e10cSrcweir } 1058cdf0e10cSrcweir } 1059cdf0e10cSrcweir catch ( container::NoSuchElementException& ) {} 1060cdf0e10cSrcweir catch ( lang::IllegalArgumentException& ) {} 1061cdf0e10cSrcweir } 1062cdf0e10cSrcweir } 1063cdf0e10cSrcweir 1064cdf0e10cSrcweir void ToolbarLayoutManager::implts_createCustomToolBars() 1065cdf0e10cSrcweir { 1066cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 1067cdf0e10cSrcweir if ( !m_bComponentAttached ) 1068cdf0e10cSrcweir return; 1069cdf0e10cSrcweir 1070cdf0e10cSrcweir uno::Reference< ui::XUIElementFactory > xUIElementFactory( m_xUIElementFactoryManager ); 1071cdf0e10cSrcweir uno::Reference< frame::XFrame > xFrame( m_xFrame ); 1072cdf0e10cSrcweir uno::Reference< frame::XModel > xModel; 1073cdf0e10cSrcweir uno::Reference< ui::XUIConfigurationManager > xModuleCfgMgr( m_xModuleCfgMgr, uno::UNO_QUERY ); 1074cdf0e10cSrcweir uno::Reference< ui::XUIConfigurationManager > xDocCfgMgr( m_xDocCfgMgr, uno::UNO_QUERY ); 1075cdf0e10cSrcweir aReadLock.unlock(); 1076cdf0e10cSrcweir 1077cdf0e10cSrcweir if ( xFrame.is() ) 1078cdf0e10cSrcweir { 1079cdf0e10cSrcweir xModel = impl_getModelFromFrame( xFrame ); 1080cdf0e10cSrcweir if ( implts_isPreviewModel( xModel )) 1081cdf0e10cSrcweir return; // no custom toolbars for preview frame! 1082cdf0e10cSrcweir 1083cdf0e10cSrcweir uno::Sequence< uno::Sequence< beans::PropertyValue > > aTbxSeq; 1084cdf0e10cSrcweir if ( xDocCfgMgr.is() ) 1085cdf0e10cSrcweir { 1086cdf0e10cSrcweir aTbxSeq = xDocCfgMgr->getUIElementsInfo( ui::UIElementType::TOOLBAR ); 1087cdf0e10cSrcweir implts_createCustomToolBars( aTbxSeq ); // first create all document based toolbars 1088cdf0e10cSrcweir } 1089cdf0e10cSrcweir if ( xModuleCfgMgr.is() ) 1090cdf0e10cSrcweir { 1091cdf0e10cSrcweir aTbxSeq = xModuleCfgMgr->getUIElementsInfo( ui::UIElementType::TOOLBAR ); 1092cdf0e10cSrcweir implts_createCustomToolBars( aTbxSeq ); // second create module based toolbars 1093cdf0e10cSrcweir } 1094cdf0e10cSrcweir } 1095cdf0e10cSrcweir } 1096cdf0e10cSrcweir 1097cdf0e10cSrcweir void ToolbarLayoutManager::implts_createNonContextSensitiveToolBars() 1098cdf0e10cSrcweir { 1099cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 1100cdf0e10cSrcweir 1101cdf0e10cSrcweir if ( !m_xPersistentWindowState.is() || !m_xFrame.is() || !m_bComponentAttached ) 1102cdf0e10cSrcweir return; 1103cdf0e10cSrcweir 1104cdf0e10cSrcweir uno::Reference< frame::XFrame > xFrame( m_xFrame ); 1105cdf0e10cSrcweir uno::Reference< ui::XUIElementFactory > xUIElementFactory( m_xUIElementFactoryManager ); 1106cdf0e10cSrcweir uno::Reference< container::XNameAccess > xPersistentWindowState( m_xPersistentWindowState ); 1107cdf0e10cSrcweir aReadLock.unlock(); 1108cdf0e10cSrcweir 1109cdf0e10cSrcweir if ( implts_isPreviewModel( impl_getModelFromFrame( xFrame ))) 1110cdf0e10cSrcweir return; 1111cdf0e10cSrcweir 1112cdf0e10cSrcweir std::vector< rtl::OUString > aMakeVisibleToolbars; 1113cdf0e10cSrcweir 1114cdf0e10cSrcweir try 1115cdf0e10cSrcweir { 1116cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aToolbarNames = xPersistentWindowState->getElementNames(); 1117cdf0e10cSrcweir 1118cdf0e10cSrcweir if ( aToolbarNames.getLength() > 0 ) 1119cdf0e10cSrcweir { 1120cdf0e10cSrcweir ::rtl::OUString aElementType; 1121cdf0e10cSrcweir ::rtl::OUString aElementName; 1122cdf0e10cSrcweir ::rtl::OUString aName; 1123cdf0e10cSrcweir 1124cdf0e10cSrcweir uno::Reference< ui::XUIElement > xUIElement; 1125cdf0e10cSrcweir aMakeVisibleToolbars.reserve(aToolbarNames.getLength()); 1126cdf0e10cSrcweir 1127cdf0e10cSrcweir /* SAFE AREA ----------------------------------------------------------------------------------------------- */ 1128cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 1129cdf0e10cSrcweir 1130cdf0e10cSrcweir const rtl::OUString* pTbNames = aToolbarNames.getConstArray(); 1131cdf0e10cSrcweir for ( sal_Int32 i = 0; i < aToolbarNames.getLength(); i++ ) 1132cdf0e10cSrcweir { 1133cdf0e10cSrcweir aName = pTbNames[i]; 1134cdf0e10cSrcweir parseResourceURL( aName, aElementType, aElementName ); 1135cdf0e10cSrcweir 1136cdf0e10cSrcweir // Check that we only create: 1137cdf0e10cSrcweir // - Toolbars (the statusbar is also member of the persistent window state) 1138cdf0e10cSrcweir // - Not custom toolbars, there are created with their own method (implts_createCustomToolbars) 1139cdf0e10cSrcweir if ( aElementType.equalsIgnoreAsciiCaseAscii( "toolbar" ) && aElementName.indexOf( m_aCustomTbxPrefix ) == -1 ) 1140cdf0e10cSrcweir { 1141cdf0e10cSrcweir UIElement aNewToolbar = implts_findToolbar( aName ); 1142cdf0e10cSrcweir bool bFound = ( aNewToolbar.m_aName == aName ); 1143cdf0e10cSrcweir if ( !bFound ) 1144cdf0e10cSrcweir implts_readWindowStateData( aName, aNewToolbar ); 1145cdf0e10cSrcweir 1146cdf0e10cSrcweir if ( aNewToolbar.m_bVisible && !aNewToolbar.m_bContextSensitive ) 1147cdf0e10cSrcweir { 1148cdf0e10cSrcweir if ( !bFound ) 1149cdf0e10cSrcweir implts_insertToolbar( aNewToolbar ); 1150cdf0e10cSrcweir aMakeVisibleToolbars.push_back( aName ); 1151cdf0e10cSrcweir } 1152cdf0e10cSrcweir } 1153cdf0e10cSrcweir } 1154cdf0e10cSrcweir /* SAFE AREA ----------------------------------------------------------------------------------------------- */ 1155cdf0e10cSrcweir } 1156cdf0e10cSrcweir } 1157cdf0e10cSrcweir catch ( uno::RuntimeException& ) { throw; } 1158cdf0e10cSrcweir catch ( uno::Exception& ) {} 1159cdf0e10cSrcweir 1160cdf0e10cSrcweir if ( !aMakeVisibleToolbars.empty() ) 1161cdf0e10cSrcweir ::std::for_each( aMakeVisibleToolbars.begin(), aMakeVisibleToolbars.end(),::boost::bind( &ToolbarLayoutManager::requestToolbar, this,_1 )); 1162cdf0e10cSrcweir } 1163cdf0e10cSrcweir 1164cdf0e10cSrcweir void ToolbarLayoutManager::implts_createCustomToolBars( const uno::Sequence< uno::Sequence< beans::PropertyValue > >& aTbxSeqSeq ) 1165cdf0e10cSrcweir { 1166cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >* pTbxSeq = aTbxSeqSeq.getConstArray(); 1167cdf0e10cSrcweir for ( sal_Int32 i = 0; i < aTbxSeqSeq.getLength(); i++ ) 1168cdf0e10cSrcweir { 1169cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& rTbxSeq = pTbxSeq[i]; 1170cdf0e10cSrcweir ::rtl::OUString aTbxResName; 1171cdf0e10cSrcweir ::rtl::OUString aTbxTitle; 1172cdf0e10cSrcweir for ( sal_Int32 j = 0; j < rTbxSeq.getLength(); j++ ) 1173cdf0e10cSrcweir { 1174cdf0e10cSrcweir if ( rTbxSeq[j].Name.equalsAscii( "ResourceURL" )) 1175cdf0e10cSrcweir rTbxSeq[j].Value >>= aTbxResName; 1176cdf0e10cSrcweir else if ( rTbxSeq[j].Name.equalsAscii( "UIName" )) 1177cdf0e10cSrcweir rTbxSeq[j].Value >>= aTbxTitle; 1178cdf0e10cSrcweir } 1179cdf0e10cSrcweir 1180cdf0e10cSrcweir // Only create custom toolbars. Their name have to start with "custom_"! 1181cdf0e10cSrcweir if ( aTbxResName.getLength() > 0 && aTbxResName.indexOf( m_aCustomTbxPrefix ) != -1 ) 1182cdf0e10cSrcweir implts_createCustomToolBar( aTbxResName, aTbxTitle ); 1183cdf0e10cSrcweir } 1184cdf0e10cSrcweir } 1185cdf0e10cSrcweir 1186cdf0e10cSrcweir void ToolbarLayoutManager::implts_createCustomToolBar( const rtl::OUString& aTbxResName, const rtl::OUString& aTitle ) 1187cdf0e10cSrcweir { 1188cdf0e10cSrcweir if ( aTbxResName.getLength() > 0 ) 1189cdf0e10cSrcweir { 1190cdf0e10cSrcweir bool bNotify( false ); 1191cdf0e10cSrcweir uno::Reference< ui::XUIElement > xUIElement; 1192cdf0e10cSrcweir implts_createToolBar( aTbxResName, bNotify, xUIElement ); 1193cdf0e10cSrcweir 119424c56ab9SHerbert Dürr if ( !aTitle.isEmpty() && xUIElement.is() ) 1195cdf0e10cSrcweir { 1196cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 1197cdf0e10cSrcweir 1198cdf0e10cSrcweir Window* pWindow = getWindowFromXUIElement( xUIElement ); 1199cdf0e10cSrcweir if ( pWindow ) 1200cdf0e10cSrcweir pWindow->SetText( aTitle ); 1201cdf0e10cSrcweir } 1202cdf0e10cSrcweir } 1203cdf0e10cSrcweir } 1204cdf0e10cSrcweir 1205cdf0e10cSrcweir void ToolbarLayoutManager::implts_reparentToolbars() 1206cdf0e10cSrcweir { 1207cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 1208cdf0e10cSrcweir UIElementVector aUIElementVector = m_aUIElements; 1209cdf0e10cSrcweir Window* pContainerWindow = VCLUnoHelper::GetWindow( m_xContainerWindow ); 1210cdf0e10cSrcweir Window* pTopDockWindow = VCLUnoHelper::GetWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_TOP] ); 1211cdf0e10cSrcweir Window* pBottomDockWindow = VCLUnoHelper::GetWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_BOTTOM] ); 1212cdf0e10cSrcweir Window* pLeftDockWindow = VCLUnoHelper::GetWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_LEFT] ); 1213cdf0e10cSrcweir Window* pRightDockWindow = VCLUnoHelper::GetWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_RIGHT] ); 1214cdf0e10cSrcweir aWriteLock.unlock(); 1215cdf0e10cSrcweir 1216cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 1217cdf0e10cSrcweir if ( pContainerWindow ) 1218cdf0e10cSrcweir { 1219cdf0e10cSrcweir UIElementVector::iterator pIter; 1220cdf0e10cSrcweir for ( pIter = aUIElementVector.begin(); pIter != aUIElementVector.end(); pIter++ ) 1221cdf0e10cSrcweir { 1222cdf0e10cSrcweir uno::Reference< ui::XUIElement > xUIElement( pIter->m_xUIElement ); 1223cdf0e10cSrcweir if ( xUIElement.is() ) 1224cdf0e10cSrcweir { 1225cdf0e10cSrcweir uno::Reference< awt::XWindow > xWindow; 1226cdf0e10cSrcweir try 1227cdf0e10cSrcweir { 122807a3d7f1SPedro Giffuni // We have to retrieve the window reference with try/catch as it is 1229cdf0e10cSrcweir // possible that all elements have been disposed! 1230cdf0e10cSrcweir xWindow = uno::Reference< awt::XWindow >( xUIElement->getRealInterface(), uno::UNO_QUERY ); 1231cdf0e10cSrcweir } 1232cdf0e10cSrcweir catch ( uno::RuntimeException& ) { throw; } 1233cdf0e10cSrcweir catch ( uno::Exception& ) {} 1234cdf0e10cSrcweir 1235cdf0e10cSrcweir Window* pWindow = VCLUnoHelper::GetWindow( xWindow ); 1236cdf0e10cSrcweir if ( pWindow ) 1237cdf0e10cSrcweir { 123807a3d7f1SPedro Giffuni // Reparent our child windows according to their current state. 1239cdf0e10cSrcweir if ( pIter->m_bFloating ) 1240cdf0e10cSrcweir pWindow->SetParent( pContainerWindow ); 1241cdf0e10cSrcweir else 1242cdf0e10cSrcweir { 1243cdf0e10cSrcweir if ( pIter->m_aDockedData.m_nDockedArea == ui::DockingArea_DOCKINGAREA_TOP ) 1244cdf0e10cSrcweir pWindow->SetParent( pTopDockWindow ); 1245cdf0e10cSrcweir else if ( pIter->m_aDockedData.m_nDockedArea == ui::DockingArea_DOCKINGAREA_BOTTOM ) 1246cdf0e10cSrcweir pWindow->SetParent( pBottomDockWindow ); 1247cdf0e10cSrcweir else if ( pIter->m_aDockedData.m_nDockedArea == ui::DockingArea_DOCKINGAREA_LEFT ) 1248cdf0e10cSrcweir pWindow->SetParent( pLeftDockWindow ); 1249cdf0e10cSrcweir else 1250cdf0e10cSrcweir pWindow->SetParent( pRightDockWindow ); 1251cdf0e10cSrcweir } 1252cdf0e10cSrcweir } 1253cdf0e10cSrcweir } 1254cdf0e10cSrcweir } 1255cdf0e10cSrcweir } 1256cdf0e10cSrcweir } 1257cdf0e10cSrcweir 1258cdf0e10cSrcweir void ToolbarLayoutManager::implts_setToolbarCreation( bool bStart ) 1259cdf0e10cSrcweir { 1260cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 1261cdf0e10cSrcweir m_bToolbarCreation = bStart; 1262cdf0e10cSrcweir } 1263cdf0e10cSrcweir 1264cdf0e10cSrcweir bool ToolbarLayoutManager::implts_isToolbarCreationActive() 1265cdf0e10cSrcweir { 1266cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 1267cdf0e10cSrcweir return m_bToolbarCreation; 1268cdf0e10cSrcweir } 1269cdf0e10cSrcweir 1270cdf0e10cSrcweir void ToolbarLayoutManager::implts_createToolBar( const ::rtl::OUString& aName, bool& bNotify, uno::Reference< ui::XUIElement >& rUIElement ) 1271cdf0e10cSrcweir { 1272cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 1273cdf0e10cSrcweir uno::Reference< frame::XFrame > xFrame( m_xFrame ); 1274cdf0e10cSrcweir uno::Reference< awt::XWindow2 > xContainerWindow( m_xContainerWindow ); 1275cdf0e10cSrcweir aReadLock.unlock(); 1276cdf0e10cSrcweir 1277cdf0e10cSrcweir bNotify = false; 1278cdf0e10cSrcweir 1279cdf0e10cSrcweir if ( !xFrame.is() || !xContainerWindow.is() ) 1280cdf0e10cSrcweir return; 1281cdf0e10cSrcweir 1282cdf0e10cSrcweir UIElement aToolbarElement = implts_findToolbar( aName ); 1283cdf0e10cSrcweir if ( !aToolbarElement.m_xUIElement.is() ) 1284cdf0e10cSrcweir { 1285cdf0e10cSrcweir uno::Reference< ui::XUIElement > xUIElement = implts_createElement( aName ); 1286cdf0e10cSrcweir 1287cdf0e10cSrcweir bool bVisible( false ); 1288cdf0e10cSrcweir bool bFloating( false ); 1289cdf0e10cSrcweir if ( xUIElement.is() ) 1290cdf0e10cSrcweir { 1291cdf0e10cSrcweir rUIElement = xUIElement; 1292cdf0e10cSrcweir 1293cdf0e10cSrcweir uno::Reference< awt::XWindow > xWindow( xUIElement->getRealInterface(), uno::UNO_QUERY ); 1294cdf0e10cSrcweir uno::Reference< awt::XDockableWindow > xDockWindow( xWindow, uno::UNO_QUERY ); 1295cdf0e10cSrcweir if ( xDockWindow.is() && xWindow.is() ) 1296cdf0e10cSrcweir { 1297cdf0e10cSrcweir try 1298cdf0e10cSrcweir { 1299cdf0e10cSrcweir xDockWindow->addDockableWindowListener( uno::Reference< awt::XDockableWindowListener >( 1300cdf0e10cSrcweir static_cast< OWeakObject * >( this ), uno::UNO_QUERY )); 1301cdf0e10cSrcweir xWindow->addWindowListener( uno::Reference< awt::XWindowListener >( 1302cdf0e10cSrcweir static_cast< OWeakObject * >( this ), uno::UNO_QUERY )); 1303cdf0e10cSrcweir xDockWindow->enableDocking( sal_True ); 1304cdf0e10cSrcweir } 1305cdf0e10cSrcweir catch ( uno::Exception& ) {} 1306cdf0e10cSrcweir } 1307cdf0e10cSrcweir 1308cdf0e10cSrcweir /* SAFE AREA ----------------------------------------------------------------------------------------------- */ 1309cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 1310cdf0e10cSrcweir 1311cdf0e10cSrcweir UIElement& rElement = impl_findToolbar( aName ); 1312cdf0e10cSrcweir if ( rElement.m_aName.getLength() > 0 ) 1313cdf0e10cSrcweir { 1314cdf0e10cSrcweir // Reuse a local entry so we are able to use the latest 1315cdf0e10cSrcweir // UI changes for this document. 1316cdf0e10cSrcweir implts_setElementData( rElement, xDockWindow ); 1317cdf0e10cSrcweir rElement.m_xUIElement = xUIElement; 1318cdf0e10cSrcweir bVisible = rElement.m_bVisible; 1319cdf0e10cSrcweir bFloating = rElement.m_bFloating; 1320cdf0e10cSrcweir } 1321cdf0e10cSrcweir else 1322cdf0e10cSrcweir { 1323cdf0e10cSrcweir // Create new UI element and try to read its state data 1324cdf0e10cSrcweir UIElement aNewToolbar( aName, m_aToolbarTypeString, xUIElement ); 1325cdf0e10cSrcweir implts_readWindowStateData( aName, aNewToolbar ); 1326cdf0e10cSrcweir implts_setElementData( aNewToolbar, xDockWindow ); 1327cdf0e10cSrcweir implts_insertToolbar( aNewToolbar ); 1328cdf0e10cSrcweir bVisible = aNewToolbar.m_bVisible; 1329cdf0e10cSrcweir bFloating = rElement.m_bFloating; 1330cdf0e10cSrcweir } 1331cdf0e10cSrcweir aWriteLock.unlock(); 1332cdf0e10cSrcweir /* SAFE AREA ----------------------------------------------------------------------------------------------- */ 1333cdf0e10cSrcweir 1334cdf0e10cSrcweir // set toolbar menu style according to customize command state 1335cdf0e10cSrcweir SvtCommandOptions aCmdOptions; 1336cdf0e10cSrcweir 1337cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 1338cdf0e10cSrcweir Window* pWindow = VCLUnoHelper::GetWindow( xWindow ); 1339cdf0e10cSrcweir if ( pWindow && pWindow->GetType() == WINDOW_TOOLBOX ) 1340cdf0e10cSrcweir { 1341cdf0e10cSrcweir ToolBox* pToolbar = (ToolBox *)pWindow; 1342cdf0e10cSrcweir sal_uInt16 nMenuType = pToolbar->GetMenuType(); 1343cdf0e10cSrcweir if ( aCmdOptions.Lookup( SvtCommandOptions::CMDOPTION_DISABLED, m_aCustomizeCmd )) 1344cdf0e10cSrcweir pToolbar->SetMenuType( nMenuType & ~TOOLBOX_MENUTYPE_CUSTOMIZE ); 1345cdf0e10cSrcweir else 1346cdf0e10cSrcweir pToolbar->SetMenuType( nMenuType | TOOLBOX_MENUTYPE_CUSTOMIZE ); 1347cdf0e10cSrcweir } 1348cdf0e10cSrcweir bNotify = true; 1349cdf0e10cSrcweir 1350cdf0e10cSrcweir implts_sortUIElements(); 1351cdf0e10cSrcweir 1352cdf0e10cSrcweir if ( bVisible && !bFloating ) 1353cdf0e10cSrcweir implts_setLayoutDirty(); 1354cdf0e10cSrcweir } 1355cdf0e10cSrcweir } 1356cdf0e10cSrcweir } 1357cdf0e10cSrcweir 1358cdf0e10cSrcweir uno::Reference< ui::XUIElement > ToolbarLayoutManager::implts_createElement( const ::rtl::OUString& aName ) 1359cdf0e10cSrcweir { 1360cdf0e10cSrcweir uno::Reference< ui::XUIElement > xUIElement; 1361cdf0e10cSrcweir 1362cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 1363cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aPropSeq( 2 ); 1364cdf0e10cSrcweir aPropSeq[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" )); 1365cdf0e10cSrcweir aPropSeq[0].Value <<= m_xFrame; 1366cdf0e10cSrcweir aPropSeq[1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Persistent" )); 1367cdf0e10cSrcweir aPropSeq[1].Value <<= true; 1368cdf0e10cSrcweir uno::Reference< ui::XUIElementFactory > xUIElementFactory( m_xUIElementFactoryManager ); 1369cdf0e10cSrcweir aReadLock.unlock(); 1370cdf0e10cSrcweir 1371cdf0e10cSrcweir implts_setToolbarCreation( true ); 1372cdf0e10cSrcweir try 1373cdf0e10cSrcweir { 1374cdf0e10cSrcweir if ( xUIElementFactory.is() ) 1375cdf0e10cSrcweir xUIElement = xUIElementFactory->createUIElement( aName, aPropSeq ); 1376cdf0e10cSrcweir } 1377cdf0e10cSrcweir catch ( container::NoSuchElementException& ) {} 1378cdf0e10cSrcweir catch ( lang::IllegalArgumentException& ) {} 1379cdf0e10cSrcweir implts_setToolbarCreation( false ); 1380cdf0e10cSrcweir 1381cdf0e10cSrcweir return xUIElement; 1382cdf0e10cSrcweir } 1383cdf0e10cSrcweir 1384cdf0e10cSrcweir void ToolbarLayoutManager::implts_setElementData( UIElement& rElement, const uno::Reference< awt::XDockableWindow >& rDockWindow ) 1385cdf0e10cSrcweir { 1386cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 1387ffdd8a15SOliver-Rainer Wittmann const bool bShowElement( rElement.m_bVisible && !rElement.m_bMasterHide && implts_isParentWindowVisible() ); 1388cdf0e10cSrcweir aReadLock.unlock(); 1389cdf0e10cSrcweir 1390cdf0e10cSrcweir uno::Reference< awt::XDockableWindow > xDockWindow( rDockWindow ); 1391cdf0e10cSrcweir uno::Reference< awt::XWindow2 > xWindow( xDockWindow, uno::UNO_QUERY ); 1392cdf0e10cSrcweir 1393cdf0e10cSrcweir Window* pWindow( 0 ); 1394cdf0e10cSrcweir ToolBox* pToolBox( 0 ); 1395cdf0e10cSrcweir 1396cdf0e10cSrcweir if ( xDockWindow.is() && xWindow.is() ) 1397cdf0e10cSrcweir { 1398cdf0e10cSrcweir { 1399cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 1400cdf0e10cSrcweir pWindow = VCLUnoHelper::GetWindow( xWindow ); 1401cdf0e10cSrcweir if ( pWindow ) 1402cdf0e10cSrcweir { 1403cdf0e10cSrcweir String aText = pWindow->GetText(); 1404cdf0e10cSrcweir if ( aText.Len() == 0 ) 1405cdf0e10cSrcweir pWindow->SetText( rElement.m_aUIName ); 1406cdf0e10cSrcweir if ( rElement.m_bNoClose ) 1407cdf0e10cSrcweir pWindow->SetStyle( pWindow->GetStyle() & ~WB_CLOSEABLE ); 1408cdf0e10cSrcweir if ( pWindow->GetType() == WINDOW_TOOLBOX ) 1409cdf0e10cSrcweir pToolBox = (ToolBox *)pWindow; 1410cdf0e10cSrcweir } 1411cdf0e10cSrcweir if ( pToolBox ) 1412cdf0e10cSrcweir { 1413cdf0e10cSrcweir if (( rElement.m_nStyle < 0 ) || ( rElement.m_nStyle > BUTTON_SYMBOLTEXT )) 1414cdf0e10cSrcweir rElement.m_nStyle = BUTTON_SYMBOL; 1415cdf0e10cSrcweir pToolBox->SetButtonType( (ButtonType)rElement.m_nStyle ); 1416cdf0e10cSrcweir if ( rElement.m_bNoClose ) 1417cdf0e10cSrcweir pToolBox->SetFloatStyle( pToolBox->GetFloatStyle() & ~WB_CLOSEABLE ); 1418cdf0e10cSrcweir } 1419cdf0e10cSrcweir } 1420cdf0e10cSrcweir 1421cdf0e10cSrcweir if ( rElement.m_bFloating ) 1422cdf0e10cSrcweir { 1423cdf0e10cSrcweir if ( pWindow ) 1424cdf0e10cSrcweir { 1425cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 1426cdf0e10cSrcweir String aText = pWindow->GetText(); 1427cdf0e10cSrcweir if ( aText.Len() == 0 ) 1428cdf0e10cSrcweir pWindow->SetText( rElement.m_aUIName ); 1429cdf0e10cSrcweir } 1430cdf0e10cSrcweir 1431cdf0e10cSrcweir ::Point aPos( rElement.m_aFloatingData.m_aPos.X(), 1432cdf0e10cSrcweir rElement.m_aFloatingData.m_aPos.Y() ); 1433cdf0e10cSrcweir bool bWriteData( false ); 1434cdf0e10cSrcweir bool bUndefPos = hasDefaultPosValue( rElement.m_aFloatingData.m_aPos ); 1435cdf0e10cSrcweir bool bSetSize = ( rElement.m_aFloatingData.m_aSize.Width() != 0 && 1436cdf0e10cSrcweir rElement.m_aFloatingData.m_aSize.Height() != 0 ); 1437cdf0e10cSrcweir xDockWindow->setFloatingMode( sal_True ); 1438cdf0e10cSrcweir if ( bUndefPos ) 1439cdf0e10cSrcweir { 1440cdf0e10cSrcweir aPos = implts_findNextCascadeFloatingPos(); 1441cdf0e10cSrcweir rElement.m_aFloatingData.m_aPos = aPos; // set new cascaded position 1442cdf0e10cSrcweir bWriteData = true; 1443cdf0e10cSrcweir } 1444cdf0e10cSrcweir 1445cdf0e10cSrcweir if( bSetSize ) 1446cdf0e10cSrcweir xWindow->setOutputSize( AWTSize( rElement.m_aFloatingData.m_aSize ) ); 1447cdf0e10cSrcweir else 1448cdf0e10cSrcweir { 1449cdf0e10cSrcweir if( pToolBox ) 1450cdf0e10cSrcweir { 1451cdf0e10cSrcweir // set an optimal initial floating size 1452cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 1453cdf0e10cSrcweir ::Size aSize( pToolBox->CalcFloatingWindowSizePixel() ); 1454cdf0e10cSrcweir pToolBox->SetOutputSizePixel( aSize ); 1455cdf0e10cSrcweir } 1456cdf0e10cSrcweir } 1457cdf0e10cSrcweir 1458cdf0e10cSrcweir // #i60882# IMPORTANT: Set position after size as it is 1459cdf0e10cSrcweir // possible that we position some part of the toolbar 1460cdf0e10cSrcweir // outside of the desktop. A default constructed toolbar 1461cdf0e10cSrcweir // always has one line. Now VCL automatically 1462cdf0e10cSrcweir // position the toolbar back into the desktop. Therefore 1463cdf0e10cSrcweir // we resize the toolbar with the new (wrong) position. 1464cdf0e10cSrcweir // To fix this problem we have to set the size BEFORE the 1465cdf0e10cSrcweir // position. 1466cdf0e10cSrcweir xWindow->setPosSize( aPos.X(), aPos.Y(), 0, 0, awt::PosSize::POS ); 1467cdf0e10cSrcweir 1468cdf0e10cSrcweir if ( bWriteData ) 1469cdf0e10cSrcweir implts_writeWindowStateData( rElement ); 1470cdf0e10cSrcweir if ( bShowElement && pWindow ) 1471cdf0e10cSrcweir { 1472cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 1473cdf0e10cSrcweir pWindow->Show( sal_True, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE ); 1474cdf0e10cSrcweir } 1475cdf0e10cSrcweir } 1476cdf0e10cSrcweir else 1477cdf0e10cSrcweir { 1478cdf0e10cSrcweir bool bSetSize( false ); 1479cdf0e10cSrcweir ::Point aDockPos; 1480cdf0e10cSrcweir ::Point aPixelPos; 1481cdf0e10cSrcweir ::Size aSize; 1482cdf0e10cSrcweir 1483cdf0e10cSrcweir if ( pToolBox ) 1484cdf0e10cSrcweir { 1485cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 1486cdf0e10cSrcweir pToolBox->SetAlign( ImplConvertAlignment(rElement.m_aDockedData.m_nDockedArea ) ); 1487cdf0e10cSrcweir pToolBox->SetLineCount( 1 ); 1488cdf0e10cSrcweir xDockWindow->setFloatingMode( sal_False ); 1489cdf0e10cSrcweir if ( rElement.m_aDockedData.m_bLocked ) 1490cdf0e10cSrcweir xDockWindow->lock(); 1491cdf0e10cSrcweir aSize = pToolBox->CalcWindowSizePixel(); 1492cdf0e10cSrcweir bSetSize = true; 1493cdf0e10cSrcweir 1494cdf0e10cSrcweir if ( isDefaultPos( rElement.m_aDockedData.m_aPos )) 1495cdf0e10cSrcweir { 1496cdf0e10cSrcweir implts_findNextDockingPos( (ui::DockingArea)rElement.m_aDockedData.m_nDockedArea, aSize, aDockPos, aPixelPos ); 1497cdf0e10cSrcweir rElement.m_aDockedData.m_aPos = aDockPos; 1498cdf0e10cSrcweir } 1499cdf0e10cSrcweir } 1500cdf0e10cSrcweir 1501cdf0e10cSrcweir xWindow->setPosSize( aPixelPos.X(), aPixelPos.Y(), 0, 0, awt::PosSize::POS ); 1502cdf0e10cSrcweir if( bSetSize ) 1503cdf0e10cSrcweir xWindow->setOutputSize( AWTSize( aSize) ); 1504cdf0e10cSrcweir 1505cdf0e10cSrcweir if ( pWindow ) 1506cdf0e10cSrcweir { 1507cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 1508cdf0e10cSrcweir if ( !bShowElement ) 1509cdf0e10cSrcweir pWindow->Hide(); 1510cdf0e10cSrcweir } 1511cdf0e10cSrcweir } 1512cdf0e10cSrcweir } 1513cdf0e10cSrcweir } 1514cdf0e10cSrcweir 1515cdf0e10cSrcweir void ToolbarLayoutManager::implts_destroyDockingAreaWindows() 1516cdf0e10cSrcweir { 1517cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 1518cdf0e10cSrcweir uno::Reference< awt::XWindow > xTopDockingWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_TOP] ); 1519cdf0e10cSrcweir uno::Reference< awt::XWindow > xLeftDockingWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_LEFT] ); 1520cdf0e10cSrcweir uno::Reference< awt::XWindow > xRightDockingWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_RIGHT] ); 1521cdf0e10cSrcweir uno::Reference< awt::XWindow > xBottomDockingWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_BOTTOM] ); 1522cdf0e10cSrcweir m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_TOP].clear(); 1523cdf0e10cSrcweir m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_LEFT].clear(); 1524cdf0e10cSrcweir m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_RIGHT].clear(); 1525cdf0e10cSrcweir m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_BOTTOM].clear(); 1526cdf0e10cSrcweir aWriteLock.unlock(); 1527cdf0e10cSrcweir 1528cdf0e10cSrcweir // destroy windows 1529cdf0e10cSrcweir xTopDockingWindow->dispose(); 1530cdf0e10cSrcweir xLeftDockingWindow->dispose(); 1531cdf0e10cSrcweir xRightDockingWindow->dispose(); 1532cdf0e10cSrcweir xBottomDockingWindow->dispose(); 1533cdf0e10cSrcweir } 1534cdf0e10cSrcweir 1535cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 1536cdf0e10cSrcweir // persistence methods 1537cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 1538cdf0e10cSrcweir 1539cdf0e10cSrcweir sal_Bool ToolbarLayoutManager::implts_readWindowStateData( const rtl::OUString& aName, UIElement& rElementData ) 1540cdf0e10cSrcweir { 1541cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 1542cdf0e10cSrcweir uno::Reference< container::XNameAccess > xPersistentWindowState( m_xPersistentWindowState ); 1543cdf0e10cSrcweir bool bGetSettingsState( false ); 1544cdf0e10cSrcweir aWriteLock.unlock(); 1545cdf0e10cSrcweir 1546cdf0e10cSrcweir if ( xPersistentWindowState.is() ) 1547cdf0e10cSrcweir { 1548cdf0e10cSrcweir aWriteLock.lock(); 1549cdf0e10cSrcweir bool bGlobalSettings( m_bGlobalSettings ); 1550cdf0e10cSrcweir GlobalSettings* pGlobalSettings( 0 ); 1551cdf0e10cSrcweir if ( m_pGlobalSettings == 0 ) 1552cdf0e10cSrcweir { 1553cdf0e10cSrcweir m_pGlobalSettings = new GlobalSettings( m_xSMGR ); 1554cdf0e10cSrcweir bGetSettingsState = true; 1555cdf0e10cSrcweir } 1556cdf0e10cSrcweir pGlobalSettings = m_pGlobalSettings; 1557cdf0e10cSrcweir aWriteLock.unlock(); 1558cdf0e10cSrcweir 1559cdf0e10cSrcweir try 1560cdf0e10cSrcweir { 1561cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aWindowState; 1562cdf0e10cSrcweir if ( xPersistentWindowState->getByName( aName ) >>= aWindowState ) 1563cdf0e10cSrcweir { 1564cdf0e10cSrcweir sal_Bool bValue( sal_False ); 1565cdf0e10cSrcweir for ( sal_Int32 n = 0; n < aWindowState.getLength(); n++ ) 1566cdf0e10cSrcweir { 1567cdf0e10cSrcweir if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_DOCKED )) 1568cdf0e10cSrcweir { 1569cdf0e10cSrcweir if ( aWindowState[n].Value >>= bValue ) 1570cdf0e10cSrcweir rElementData.m_bFloating = !bValue; 1571cdf0e10cSrcweir } 1572cdf0e10cSrcweir else if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_VISIBLE )) 1573cdf0e10cSrcweir { 1574cdf0e10cSrcweir if ( aWindowState[n].Value >>= bValue ) 1575cdf0e10cSrcweir rElementData.m_bVisible = bValue; 1576cdf0e10cSrcweir } 1577cdf0e10cSrcweir else if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_DOCKINGAREA )) 1578cdf0e10cSrcweir { 1579cdf0e10cSrcweir ui::DockingArea eDockingArea; 1580cdf0e10cSrcweir if ( aWindowState[n].Value >>= eDockingArea ) 1581cdf0e10cSrcweir rElementData.m_aDockedData.m_nDockedArea = sal_Int16( eDockingArea ); 1582cdf0e10cSrcweir } 1583cdf0e10cSrcweir else if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_DOCKPOS )) 1584cdf0e10cSrcweir { 1585cdf0e10cSrcweir awt::Point aPoint; 1586cdf0e10cSrcweir if ( aWindowState[n].Value >>= aPoint ) 1587cdf0e10cSrcweir { 1588cdf0e10cSrcweir rElementData.m_aDockedData.m_aPos.X() = aPoint.X; 1589cdf0e10cSrcweir rElementData.m_aDockedData.m_aPos.Y() = aPoint.Y; 1590cdf0e10cSrcweir } 1591cdf0e10cSrcweir } 1592cdf0e10cSrcweir else if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_POS )) 1593cdf0e10cSrcweir { 1594cdf0e10cSrcweir awt::Point aPoint; 1595cdf0e10cSrcweir if ( aWindowState[n].Value >>= aPoint ) 1596cdf0e10cSrcweir { 1597cdf0e10cSrcweir rElementData.m_aFloatingData.m_aPos.X() = aPoint.X; 1598cdf0e10cSrcweir rElementData.m_aFloatingData.m_aPos.Y() = aPoint.Y; 1599cdf0e10cSrcweir } 1600cdf0e10cSrcweir } 1601cdf0e10cSrcweir else if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_SIZE )) 1602cdf0e10cSrcweir { 1603cdf0e10cSrcweir awt::Size aSize; 1604cdf0e10cSrcweir if ( aWindowState[n].Value >>= aSize ) 1605cdf0e10cSrcweir { 1606cdf0e10cSrcweir rElementData.m_aFloatingData.m_aSize.Width() = aSize.Width; 1607cdf0e10cSrcweir rElementData.m_aFloatingData.m_aSize.Height() = aSize.Height; 1608cdf0e10cSrcweir } 1609cdf0e10cSrcweir } 1610cdf0e10cSrcweir else if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_UINAME )) 1611cdf0e10cSrcweir aWindowState[n].Value >>= rElementData.m_aUIName; 1612cdf0e10cSrcweir else if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_STYLE )) 1613cdf0e10cSrcweir { 1614cdf0e10cSrcweir sal_Int32 nStyle = 0; 1615cdf0e10cSrcweir if ( aWindowState[n].Value >>= nStyle ) 1616cdf0e10cSrcweir rElementData.m_nStyle = sal_Int16( nStyle ); 1617cdf0e10cSrcweir } 1618cdf0e10cSrcweir else if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_LOCKED )) 1619cdf0e10cSrcweir { 1620cdf0e10cSrcweir if ( aWindowState[n].Value >>= bValue ) 1621cdf0e10cSrcweir rElementData.m_aDockedData.m_bLocked = bValue; 1622cdf0e10cSrcweir } 1623cdf0e10cSrcweir else if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_CONTEXT )) 1624cdf0e10cSrcweir { 1625cdf0e10cSrcweir if ( aWindowState[n].Value >>= bValue ) 1626cdf0e10cSrcweir rElementData.m_bContextSensitive = bValue; 1627cdf0e10cSrcweir } 1628cdf0e10cSrcweir else if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_NOCLOSE )) 1629cdf0e10cSrcweir { 1630cdf0e10cSrcweir if ( aWindowState[n].Value >>= bValue ) 1631cdf0e10cSrcweir rElementData.m_bNoClose = bValue; 1632cdf0e10cSrcweir } 1633cdf0e10cSrcweir else if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_CONTEXTACTIVE )) 1634cdf0e10cSrcweir { 1635cdf0e10cSrcweir if ( aWindowState[n].Value >>= bValue ) 1636cdf0e10cSrcweir rElementData.m_bContextActive = bValue; 1637cdf0e10cSrcweir } 1638cdf0e10cSrcweir else if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_SOFTCLOSE )) 1639cdf0e10cSrcweir { 1640cdf0e10cSrcweir if ( aWindowState[n].Value >>= bValue ) 1641cdf0e10cSrcweir rElementData.m_bSoftClose = bValue; 1642cdf0e10cSrcweir } 1643cdf0e10cSrcweir } 1644cdf0e10cSrcweir } 1645cdf0e10cSrcweir 1646cdf0e10cSrcweir // oversteer values with global settings 1647cdf0e10cSrcweir if ( pGlobalSettings && ( bGetSettingsState || bGlobalSettings )) 1648cdf0e10cSrcweir { 1649cdf0e10cSrcweir if ( pGlobalSettings->HasStatesInfo( GlobalSettings::UIELEMENT_TYPE_TOOLBAR )) 1650cdf0e10cSrcweir { 1651cdf0e10cSrcweir WriteGuard aWriteLock2( m_aLock ); 1652cdf0e10cSrcweir m_bGlobalSettings = true; 1653cdf0e10cSrcweir aWriteLock2.unlock(); 1654cdf0e10cSrcweir 1655cdf0e10cSrcweir uno::Any aValue; 1656cdf0e10cSrcweir sal_Bool bValue = sal_Bool(); 1657cdf0e10cSrcweir if ( pGlobalSettings->GetStateInfo( GlobalSettings::UIELEMENT_TYPE_TOOLBAR, 1658cdf0e10cSrcweir GlobalSettings::STATEINFO_LOCKED, 1659cdf0e10cSrcweir aValue )) 1660cdf0e10cSrcweir aValue >>= rElementData.m_aDockedData.m_bLocked; 1661cdf0e10cSrcweir if ( pGlobalSettings->GetStateInfo( GlobalSettings::UIELEMENT_TYPE_TOOLBAR, 1662cdf0e10cSrcweir GlobalSettings::STATEINFO_DOCKED, 1663cdf0e10cSrcweir aValue )) 1664cdf0e10cSrcweir { 1665cdf0e10cSrcweir if ( aValue >>= bValue ) 1666cdf0e10cSrcweir rElementData.m_bFloating = !bValue; 1667cdf0e10cSrcweir } 1668cdf0e10cSrcweir } 1669cdf0e10cSrcweir } 1670cdf0e10cSrcweir 1671cdf0e10cSrcweir return sal_True; 1672cdf0e10cSrcweir } 1673cdf0e10cSrcweir catch ( container::NoSuchElementException& ) {} 1674cdf0e10cSrcweir } 1675cdf0e10cSrcweir 1676cdf0e10cSrcweir return sal_False; 1677cdf0e10cSrcweir } 1678cdf0e10cSrcweir 1679cdf0e10cSrcweir void ToolbarLayoutManager::implts_writeWindowStateData( const UIElement& rElementData ) 1680cdf0e10cSrcweir { 1681cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 1682cdf0e10cSrcweir uno::Reference< container::XNameAccess > xPersistentWindowState( m_xPersistentWindowState ); 1683cdf0e10cSrcweir m_bStoreWindowState = true; // set flag to determine that we triggered the notification 1684cdf0e10cSrcweir aWriteLock.unlock(); 1685cdf0e10cSrcweir 1686cdf0e10cSrcweir bool bPersistent( sal_False ); 1687cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xPropSet( rElementData.m_xUIElement, uno::UNO_QUERY ); 1688cdf0e10cSrcweir if ( xPropSet.is() ) 1689cdf0e10cSrcweir { 1690cdf0e10cSrcweir try 1691cdf0e10cSrcweir { 1692cdf0e10cSrcweir // Check persistent flag of the user interface element 1693cdf0e10cSrcweir xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Persistent" ))) >>= bPersistent; 1694cdf0e10cSrcweir } 1695cdf0e10cSrcweir catch ( beans::UnknownPropertyException ) 1696cdf0e10cSrcweir { 1697cdf0e10cSrcweir bPersistent = true; // Non-configurable elements should at least store their dimension/position 1698cdf0e10cSrcweir } 1699cdf0e10cSrcweir catch ( lang::WrappedTargetException ) {} 1700cdf0e10cSrcweir } 1701cdf0e10cSrcweir 1702cdf0e10cSrcweir if ( bPersistent && xPersistentWindowState.is() ) 1703cdf0e10cSrcweir { 1704cdf0e10cSrcweir try 1705cdf0e10cSrcweir { 170626169348SAriel Constenla-Haile uno::Sequence< beans::PropertyValue > aWindowState( 9 ); 1707cdf0e10cSrcweir 1708cdf0e10cSrcweir aWindowState[0].Name = ::rtl::OUString::createFromAscii( WINDOWSTATE_PROPERTY_DOCKED ); 1709cdf0e10cSrcweir aWindowState[0].Value = ::uno::makeAny( sal_Bool( !rElementData.m_bFloating )); 1710cdf0e10cSrcweir aWindowState[1].Name = ::rtl::OUString::createFromAscii( WINDOWSTATE_PROPERTY_VISIBLE ); 1711cdf0e10cSrcweir aWindowState[1].Value = uno::makeAny( sal_Bool( rElementData.m_bVisible )); 1712cdf0e10cSrcweir aWindowState[2].Name = ::rtl::OUString::createFromAscii( WINDOWSTATE_PROPERTY_DOCKINGAREA ); 1713cdf0e10cSrcweir aWindowState[2].Value = uno::makeAny( static_cast< ui::DockingArea >( rElementData.m_aDockedData.m_nDockedArea ) ); 1714cdf0e10cSrcweir 1715cdf0e10cSrcweir awt::Point aPos; 1716cdf0e10cSrcweir aPos.X = rElementData.m_aDockedData.m_aPos.X(); 1717cdf0e10cSrcweir aPos.Y = rElementData.m_aDockedData.m_aPos.Y(); 1718cdf0e10cSrcweir aWindowState[3].Name = ::rtl::OUString::createFromAscii( WINDOWSTATE_PROPERTY_DOCKPOS ); 1719cdf0e10cSrcweir aWindowState[3].Value <<= aPos; 1720cdf0e10cSrcweir 1721cdf0e10cSrcweir aPos.X = rElementData.m_aFloatingData.m_aPos.X(); 1722cdf0e10cSrcweir aPos.Y = rElementData.m_aFloatingData.m_aPos.Y(); 1723cdf0e10cSrcweir aWindowState[4].Name = ::rtl::OUString::createFromAscii( WINDOWSTATE_PROPERTY_POS ); 1724cdf0e10cSrcweir aWindowState[4].Value <<= aPos; 1725cdf0e10cSrcweir 1726cdf0e10cSrcweir awt::Size aSize; 1727cdf0e10cSrcweir aSize.Width = rElementData.m_aFloatingData.m_aSize.Width(); 1728cdf0e10cSrcweir aSize.Height = rElementData.m_aFloatingData.m_aSize.Height(); 1729cdf0e10cSrcweir aWindowState[5].Name = ::rtl::OUString::createFromAscii( WINDOWSTATE_PROPERTY_SIZE ); 1730cdf0e10cSrcweir aWindowState[5].Value <<= aSize; 1731cdf0e10cSrcweir aWindowState[6].Name = ::rtl::OUString::createFromAscii( WINDOWSTATE_PROPERTY_UINAME ); 1732cdf0e10cSrcweir aWindowState[6].Value = uno::makeAny( rElementData.m_aUIName ); 1733cdf0e10cSrcweir aWindowState[7].Name = ::rtl::OUString::createFromAscii( WINDOWSTATE_PROPERTY_LOCKED ); 1734cdf0e10cSrcweir aWindowState[7].Value = uno::makeAny( rElementData.m_aDockedData.m_bLocked ); 173526169348SAriel Constenla-Haile aWindowState[8].Name = ::rtl::OUString::createFromAscii( WINDOWSTATE_PROPERTY_STYLE ); 173626169348SAriel Constenla-Haile aWindowState[8].Value = uno::makeAny( rElementData.m_nStyle ); 1737cdf0e10cSrcweir 1738cdf0e10cSrcweir ::rtl::OUString aName = rElementData.m_aName; 1739cdf0e10cSrcweir if ( xPersistentWindowState->hasByName( aName )) 1740cdf0e10cSrcweir { 1741cdf0e10cSrcweir uno::Reference< container::XNameReplace > xReplace( xPersistentWindowState, uno::UNO_QUERY ); 1742cdf0e10cSrcweir xReplace->replaceByName( aName, uno::makeAny( aWindowState )); 1743cdf0e10cSrcweir } 1744cdf0e10cSrcweir else 1745cdf0e10cSrcweir { 1746cdf0e10cSrcweir uno::Reference< container::XNameContainer > xInsert( xPersistentWindowState, uno::UNO_QUERY ); 1747cdf0e10cSrcweir xInsert->insertByName( aName, uno::makeAny( aWindowState )); 1748cdf0e10cSrcweir } 1749cdf0e10cSrcweir } 1750cdf0e10cSrcweir catch ( uno::Exception& ) {} 1751cdf0e10cSrcweir } 1752cdf0e10cSrcweir 1753cdf0e10cSrcweir // Reset flag 1754cdf0e10cSrcweir aWriteLock.lock(); 1755cdf0e10cSrcweir m_bStoreWindowState = false; 1756cdf0e10cSrcweir aWriteLock.unlock(); 1757cdf0e10cSrcweir } 1758cdf0e10cSrcweir 1759cdf0e10cSrcweir void ToolbarLayoutManager::implts_writeNewWindowStateData( const rtl::OUString aName, const uno::Reference< awt::XWindow >& xWindow ) 1760cdf0e10cSrcweir { 1761cdf0e10cSrcweir bool bVisible( false ); 1762cdf0e10cSrcweir bool bFloating( true ); 1763cdf0e10cSrcweir awt::Rectangle aPos; 1764cdf0e10cSrcweir awt::Size aSize; 1765cdf0e10cSrcweir 1766cdf0e10cSrcweir if ( xWindow.is() ) 1767cdf0e10cSrcweir { 1768cdf0e10cSrcweir uno::Reference< awt::XDockableWindow > xDockWindow( xWindow, uno::UNO_QUERY ); 1769cdf0e10cSrcweir if ( xDockWindow.is() ) 1770cdf0e10cSrcweir bFloating = xDockWindow->isFloating(); 1771cdf0e10cSrcweir 1772cdf0e10cSrcweir uno::Reference< awt::XWindow2 > xWindow2( xWindow, uno::UNO_QUERY ); 1773cdf0e10cSrcweir if( xWindow2.is() ) 1774cdf0e10cSrcweir { 1775cdf0e10cSrcweir aPos = xWindow2->getPosSize(); 1776cdf0e10cSrcweir aSize = xWindow2->getOutputSize(); // always use output size for consistency 1777cdf0e10cSrcweir bVisible = xWindow2->isVisible(); 1778cdf0e10cSrcweir } 1779cdf0e10cSrcweir 1780cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 1781cdf0e10cSrcweir UIElement& rUIElement = impl_findToolbar( aName ); 1782cdf0e10cSrcweir if ( rUIElement.m_xUIElement.is() ) 1783cdf0e10cSrcweir { 1784cdf0e10cSrcweir rUIElement.m_bVisible = bVisible; 1785cdf0e10cSrcweir rUIElement.m_bFloating = bFloating; 1786cdf0e10cSrcweir if ( bFloating ) 1787cdf0e10cSrcweir { 1788cdf0e10cSrcweir rUIElement.m_aFloatingData.m_aPos = ::Point( aPos.X, aPos.Y ); 1789cdf0e10cSrcweir rUIElement.m_aFloatingData.m_aSize = ::Size( aSize.Width, aSize.Height ); 1790cdf0e10cSrcweir } 1791cdf0e10cSrcweir } 1792cdf0e10cSrcweir implts_writeWindowStateData( rUIElement ); 1793cdf0e10cSrcweir aWriteLock.unlock(); 1794cdf0e10cSrcweir } 1795cdf0e10cSrcweir } 1796cdf0e10cSrcweir 1797cdf0e10cSrcweir /****************************************************************************** 1798cdf0e10cSrcweir LOOKUP PART FOR TOOLBARS 1799cdf0e10cSrcweir ******************************************************************************/ 1800cdf0e10cSrcweir 1801cdf0e10cSrcweir UIElement& ToolbarLayoutManager::impl_findToolbar( const rtl::OUString& aName ) 1802cdf0e10cSrcweir { 1803cdf0e10cSrcweir static UIElement aEmptyElement; 1804cdf0e10cSrcweir UIElementVector::iterator pIter; 1805cdf0e10cSrcweir 1806cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 1807cdf0e10cSrcweir for ( pIter = m_aUIElements.begin(); pIter != m_aUIElements.end(); pIter++ ) 1808cdf0e10cSrcweir { 1809cdf0e10cSrcweir if ( pIter->m_aName == aName ) 1810cdf0e10cSrcweir return *pIter; 1811cdf0e10cSrcweir } 1812cdf0e10cSrcweir 1813cdf0e10cSrcweir return aEmptyElement; 1814cdf0e10cSrcweir } 1815cdf0e10cSrcweir 1816cdf0e10cSrcweir UIElement ToolbarLayoutManager::implts_findToolbar( const rtl::OUString& aName ) 1817cdf0e10cSrcweir { 1818cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 1819cdf0e10cSrcweir UIElement aElement = impl_findToolbar( aName ); 1820cdf0e10cSrcweir aReadLock.unlock(); 1821cdf0e10cSrcweir 1822cdf0e10cSrcweir return aElement; 1823cdf0e10cSrcweir } 1824cdf0e10cSrcweir 1825cdf0e10cSrcweir UIElement ToolbarLayoutManager::implts_findToolbar( const uno::Reference< uno::XInterface >& xToolbar ) 1826cdf0e10cSrcweir { 1827cdf0e10cSrcweir UIElement aToolbar; 1828cdf0e10cSrcweir UIElementVector::const_iterator pIter; 1829cdf0e10cSrcweir 1830cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 1831cdf0e10cSrcweir for ( pIter = m_aUIElements.begin(); pIter != m_aUIElements.end(); pIter++ ) 1832cdf0e10cSrcweir { 1833cdf0e10cSrcweir if ( pIter->m_xUIElement.is() ) 1834cdf0e10cSrcweir { 1835cdf0e10cSrcweir uno::Reference< uno::XInterface > xIfac( pIter->m_xUIElement->getRealInterface(), uno::UNO_QUERY ); 1836cdf0e10cSrcweir if ( xIfac == xToolbar ) 1837cdf0e10cSrcweir { 1838cdf0e10cSrcweir aToolbar = *pIter; 1839cdf0e10cSrcweir break; 1840cdf0e10cSrcweir } 1841cdf0e10cSrcweir } 1842cdf0e10cSrcweir } 1843cdf0e10cSrcweir 1844cdf0e10cSrcweir return aToolbar; 1845cdf0e10cSrcweir } 1846cdf0e10cSrcweir 1847cdf0e10cSrcweir uno::Reference< awt::XWindow > ToolbarLayoutManager::implts_getXWindow( const ::rtl::OUString& aName ) 1848cdf0e10cSrcweir { 1849cdf0e10cSrcweir UIElementVector::iterator pIter; 1850cdf0e10cSrcweir uno::Reference< awt::XWindow > xWindow; 1851cdf0e10cSrcweir 1852cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 1853cdf0e10cSrcweir for ( pIter = m_aUIElements.begin(); pIter != m_aUIElements.end(); pIter++ ) 1854cdf0e10cSrcweir { 1855cdf0e10cSrcweir if ( pIter->m_aName == aName && pIter->m_xUIElement.is() ) 1856cdf0e10cSrcweir { 1857cdf0e10cSrcweir xWindow = uno::Reference< awt::XWindow >( pIter->m_xUIElement->getRealInterface(), uno::UNO_QUERY ); 1858cdf0e10cSrcweir break; 1859cdf0e10cSrcweir } 1860cdf0e10cSrcweir } 1861cdf0e10cSrcweir 1862cdf0e10cSrcweir return xWindow; 1863cdf0e10cSrcweir } 1864cdf0e10cSrcweir 1865cdf0e10cSrcweir Window* ToolbarLayoutManager::implts_getWindow( const ::rtl::OUString& aName ) 1866cdf0e10cSrcweir { 1867cdf0e10cSrcweir uno::Reference< awt::XWindow > xWindow = implts_getXWindow( aName ); 1868cdf0e10cSrcweir Window* pWindow = VCLUnoHelper::GetWindow( xWindow ); 1869cdf0e10cSrcweir 1870cdf0e10cSrcweir return pWindow; 1871cdf0e10cSrcweir } 1872cdf0e10cSrcweir 1873cdf0e10cSrcweir bool ToolbarLayoutManager::implts_insertToolbar( const UIElement& rUIElement ) 1874cdf0e10cSrcweir { 1875cdf0e10cSrcweir UIElement aTempData; 1876cdf0e10cSrcweir bool bFound( false ); 1877cdf0e10cSrcweir bool bResult( false ); 1878cdf0e10cSrcweir 1879cdf0e10cSrcweir aTempData = implts_findToolbar( rUIElement.m_aName ); 1880cdf0e10cSrcweir if ( aTempData.m_aName == rUIElement.m_aName ) 1881cdf0e10cSrcweir bFound = true; 1882cdf0e10cSrcweir 1883cdf0e10cSrcweir if ( !bFound ) 1884cdf0e10cSrcweir { 1885cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 1886cdf0e10cSrcweir m_aUIElements.push_back( rUIElement ); 1887cdf0e10cSrcweir bResult = true; 1888cdf0e10cSrcweir } 1889cdf0e10cSrcweir 1890cdf0e10cSrcweir return bResult; 1891cdf0e10cSrcweir } 1892cdf0e10cSrcweir 1893cdf0e10cSrcweir void ToolbarLayoutManager::implts_setToolbar( const UIElement& rUIElement ) 1894cdf0e10cSrcweir { 1895cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 1896cdf0e10cSrcweir UIElement& rData = impl_findToolbar( rUIElement.m_aName ); 1897cdf0e10cSrcweir if ( rData.m_aName == rUIElement.m_aName ) 1898cdf0e10cSrcweir rData = rUIElement; 1899cdf0e10cSrcweir else 1900cdf0e10cSrcweir m_aUIElements.push_back( rUIElement ); 1901cdf0e10cSrcweir } 1902cdf0e10cSrcweir 1903cdf0e10cSrcweir /****************************************************************************** 1904cdf0e10cSrcweir LAYOUT CODE PART FOR TOOLBARS 1905cdf0e10cSrcweir ******************************************************************************/ 1906cdf0e10cSrcweir 1907cdf0e10cSrcweir ::Point ToolbarLayoutManager::implts_findNextCascadeFloatingPos() 1908cdf0e10cSrcweir { 1909cdf0e10cSrcweir const sal_Int32 nHotZoneX = 50; 1910cdf0e10cSrcweir const sal_Int32 nHotZoneY = 50; 1911cdf0e10cSrcweir const sal_Int32 nCascadeIndentX = 15; 1912cdf0e10cSrcweir const sal_Int32 nCascadeIndentY = 15; 1913cdf0e10cSrcweir 1914cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 1915cdf0e10cSrcweir uno::Reference< awt::XWindow2 > xContainerWindow( m_xContainerWindow ); 1916cdf0e10cSrcweir uno::Reference< awt::XWindow > xTopDockingWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_TOP] ); 1917cdf0e10cSrcweir uno::Reference< awt::XWindow > xLeftDockingWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_LEFT] ); 1918cdf0e10cSrcweir aReadLock.unlock(); 1919cdf0e10cSrcweir 1920cdf0e10cSrcweir ::Point aStartPos( nCascadeIndentX, nCascadeIndentY ); 1921cdf0e10cSrcweir ::Point aCurrPos( aStartPos ); 1922cdf0e10cSrcweir awt::Rectangle aRect; 1923cdf0e10cSrcweir 1924cdf0e10cSrcweir Window* pContainerWindow( 0 ); 1925cdf0e10cSrcweir if ( xContainerWindow.is() ) 1926cdf0e10cSrcweir { 1927cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 1928cdf0e10cSrcweir pContainerWindow = VCLUnoHelper::GetWindow( xContainerWindow ); 1929cdf0e10cSrcweir if ( pContainerWindow ) 1930cdf0e10cSrcweir aStartPos = pContainerWindow->OutputToScreenPixel( aStartPos ); 1931cdf0e10cSrcweir } 1932cdf0e10cSrcweir 1933cdf0e10cSrcweir // Determine size of top and left docking area 1934cdf0e10cSrcweir awt::Rectangle aTopRect( xTopDockingWindow->getPosSize() ); 1935cdf0e10cSrcweir awt::Rectangle aLeftRect( xLeftDockingWindow->getPosSize() ); 1936cdf0e10cSrcweir 1937cdf0e10cSrcweir aStartPos.X() += aLeftRect.Width + nCascadeIndentX; 1938cdf0e10cSrcweir aStartPos.Y() += aTopRect.Height + nCascadeIndentY; 1939cdf0e10cSrcweir aCurrPos = aStartPos; 1940cdf0e10cSrcweir 1941cdf0e10cSrcweir // Try to find a cascaded position for the new floating window 1942cdf0e10cSrcweir UIElementVector::const_iterator pIter; 1943cdf0e10cSrcweir for ( pIter = m_aUIElements.begin(); pIter != m_aUIElements.end(); pIter++ ) 1944cdf0e10cSrcweir { 1945cdf0e10cSrcweir if ( pIter->m_xUIElement.is() ) 1946cdf0e10cSrcweir { 1947cdf0e10cSrcweir uno::Reference< awt::XDockableWindow > xDockWindow( pIter->m_xUIElement->getRealInterface(), uno::UNO_QUERY ); 1948cdf0e10cSrcweir uno::Reference< awt::XWindow > xWindow( xDockWindow, uno::UNO_QUERY ); 1949cdf0e10cSrcweir if ( xDockWindow.is() && xDockWindow->isFloating() ) 1950cdf0e10cSrcweir { 1951cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 1952cdf0e10cSrcweir Window* pWindow = VCLUnoHelper::GetWindow( xWindow ); 1953cdf0e10cSrcweir if ( pWindow && pWindow->IsVisible() ) 1954cdf0e10cSrcweir { 1955cdf0e10cSrcweir awt::Rectangle aFloatRect = xWindow->getPosSize(); 1956cdf0e10cSrcweir if ((( aFloatRect.X - nHotZoneX ) <= aCurrPos.X() ) && 1957cdf0e10cSrcweir ( aFloatRect.X >= aCurrPos.X() ) && 1958cdf0e10cSrcweir (( aFloatRect.Y - nHotZoneY ) <= aCurrPos.Y() ) && 1959cdf0e10cSrcweir ( aFloatRect.Y >= aCurrPos.Y() )) 1960cdf0e10cSrcweir { 1961cdf0e10cSrcweir aCurrPos.X() = aFloatRect.X + nCascadeIndentX; 1962cdf0e10cSrcweir aCurrPos.Y() = aFloatRect.Y + nCascadeIndentY; 1963cdf0e10cSrcweir } 1964cdf0e10cSrcweir } 1965cdf0e10cSrcweir } 1966cdf0e10cSrcweir } 1967cdf0e10cSrcweir } 1968cdf0e10cSrcweir 1969cdf0e10cSrcweir return aCurrPos; 1970cdf0e10cSrcweir } 1971cdf0e10cSrcweir 1972cdf0e10cSrcweir void ToolbarLayoutManager::implts_sortUIElements() 1973cdf0e10cSrcweir { 1974cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 1975cdf0e10cSrcweir UIElementVector::iterator pIterStart = m_aUIElements.begin(); 1976cdf0e10cSrcweir UIElementVector::iterator pIterEnd = m_aUIElements.end(); 1977cdf0e10cSrcweir 1978cdf0e10cSrcweir std::stable_sort( pIterStart, pIterEnd ); // first created element should first 1979cdf0e10cSrcweir 1980cdf0e10cSrcweir // We have to reset our temporary flags. 1981cdf0e10cSrcweir UIElementVector::iterator pIter; 1982cdf0e10cSrcweir for ( pIter = m_aUIElements.begin(); pIter != m_aUIElements.end(); pIter++ ) 1983cdf0e10cSrcweir pIter->m_bUserActive = sal_False; 1984cdf0e10cSrcweir aWriteLock.unlock(); 1985cdf0e10cSrcweir } 1986cdf0e10cSrcweir 1987cdf0e10cSrcweir void ToolbarLayoutManager::implts_getUIElementVectorCopy( UIElementVector& rCopy ) 1988cdf0e10cSrcweir { 1989cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 1990cdf0e10cSrcweir rCopy = m_aUIElements; 1991cdf0e10cSrcweir } 1992cdf0e10cSrcweir 1993cdf0e10cSrcweir ::Size ToolbarLayoutManager::implts_getTopBottomDockingAreaSizes() 1994cdf0e10cSrcweir { 1995cdf0e10cSrcweir ::Size aSize; 1996cdf0e10cSrcweir uno::Reference< awt::XWindow > xTopDockingAreaWindow; 1997cdf0e10cSrcweir uno::Reference< awt::XWindow > xBottomDockingAreaWindow; 1998cdf0e10cSrcweir 1999cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 2000cdf0e10cSrcweir xTopDockingAreaWindow = m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_TOP]; 2001cdf0e10cSrcweir xBottomDockingAreaWindow = m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_BOTTOM]; 2002cdf0e10cSrcweir aReadLock.unlock(); 2003cdf0e10cSrcweir 2004cdf0e10cSrcweir if ( xTopDockingAreaWindow.is() ) 2005cdf0e10cSrcweir aSize.Width() = xTopDockingAreaWindow->getPosSize().Height; 2006cdf0e10cSrcweir if ( xBottomDockingAreaWindow.is() ) 2007cdf0e10cSrcweir aSize.Height() = xBottomDockingAreaWindow->getPosSize().Height; 2008cdf0e10cSrcweir 2009cdf0e10cSrcweir return aSize; 2010cdf0e10cSrcweir } 2011cdf0e10cSrcweir 2012cdf0e10cSrcweir void ToolbarLayoutManager::implts_getDockingAreaElementInfos( ui::DockingArea eDockingArea, std::vector< SingleRowColumnWindowData >& rRowColumnsWindowData ) 2013cdf0e10cSrcweir { 2014cdf0e10cSrcweir std::vector< UIElement > aWindowVector; 2015cdf0e10cSrcweir 2016cdf0e10cSrcweir if (( eDockingArea < ui::DockingArea_DOCKINGAREA_TOP ) || ( eDockingArea > ui::DockingArea_DOCKINGAREA_RIGHT )) 2017cdf0e10cSrcweir eDockingArea = ui::DockingArea_DOCKINGAREA_TOP; 2018cdf0e10cSrcweir 2019cdf0e10cSrcweir uno::Reference< awt::XWindow > xDockAreaWindow; 2020cdf0e10cSrcweir 2021cdf0e10cSrcweir /* SAFE AREA ----------------------------------------------------------------------------------------------- */ 2022cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 2023cdf0e10cSrcweir aWindowVector.reserve(m_aUIElements.size()); 2024cdf0e10cSrcweir xDockAreaWindow = m_xDockAreaWindows[eDockingArea]; 2025cdf0e10cSrcweir UIElementVector::iterator pIter; 2026cdf0e10cSrcweir for ( pIter = m_aUIElements.begin(); pIter != m_aUIElements.end(); pIter++ ) 2027cdf0e10cSrcweir { 2028ffdd8a15SOliver-Rainer Wittmann if ( pIter->m_aDockedData.m_nDockedArea == eDockingArea 2029ffdd8a15SOliver-Rainer Wittmann && pIter->m_bVisible 2030ffdd8a15SOliver-Rainer Wittmann && !pIter->m_bMasterHide 2031ffdd8a15SOliver-Rainer Wittmann && !pIter->m_bFloating ) 2032cdf0e10cSrcweir { 2033cdf0e10cSrcweir uno::Reference< ui::XUIElement > xUIElement( pIter->m_xUIElement ); 2034cdf0e10cSrcweir if ( xUIElement.is() ) 2035cdf0e10cSrcweir { 2036cdf0e10cSrcweir uno::Reference< awt::XWindow > xWindow( xUIElement->getRealInterface(), uno::UNO_QUERY ); 2037cdf0e10cSrcweir uno::Reference< awt::XDockableWindow > xDockWindow( xWindow, uno::UNO_QUERY ); 2038cdf0e10cSrcweir if ( xDockWindow.is() ) 2039cdf0e10cSrcweir { 2040cdf0e10cSrcweir // docked windows 2041cdf0e10cSrcweir aWindowVector.push_back( *pIter ); 2042cdf0e10cSrcweir } 2043cdf0e10cSrcweir } 2044cdf0e10cSrcweir } 2045cdf0e10cSrcweir } 2046cdf0e10cSrcweir aReadLock.unlock(); 2047cdf0e10cSrcweir /* SAFE AREA ----------------------------------------------------------------------------------------------- */ 2048cdf0e10cSrcweir 2049cdf0e10cSrcweir rRowColumnsWindowData.clear(); 2050cdf0e10cSrcweir 2051cdf0e10cSrcweir // Collect data from windows that are on the same row/column 2052cdf0e10cSrcweir sal_Int32 j; 2053cdf0e10cSrcweir sal_Int32 nIndex( 0 ); 2054cdf0e10cSrcweir sal_Int32 nLastPos( 0 ); 2055cdf0e10cSrcweir sal_Int32 nCurrPos( -1 ); 2056cdf0e10cSrcweir sal_Int32 nLastRowColPixelPos( 0 ); 2057cdf0e10cSrcweir awt::Rectangle aDockAreaRect; 2058cdf0e10cSrcweir 2059cdf0e10cSrcweir if ( xDockAreaWindow.is() ) 2060cdf0e10cSrcweir aDockAreaRect = xDockAreaWindow->getPosSize(); 2061cdf0e10cSrcweir 2062cdf0e10cSrcweir if ( eDockingArea == ui::DockingArea_DOCKINGAREA_TOP ) 2063cdf0e10cSrcweir nLastRowColPixelPos = 0; 2064cdf0e10cSrcweir else if ( eDockingArea == ui::DockingArea_DOCKINGAREA_BOTTOM ) 2065cdf0e10cSrcweir nLastRowColPixelPos = aDockAreaRect.Height; 2066cdf0e10cSrcweir else if ( eDockingArea == ui::DockingArea_DOCKINGAREA_LEFT ) 2067cdf0e10cSrcweir nLastRowColPixelPos = 0; 2068cdf0e10cSrcweir else 2069cdf0e10cSrcweir nLastRowColPixelPos = aDockAreaRect.Width; 2070cdf0e10cSrcweir 2071cdf0e10cSrcweir const sal_uInt32 nCount = aWindowVector.size(); 2072cdf0e10cSrcweir for ( j = 0; j < sal_Int32( nCount); j++ ) 2073cdf0e10cSrcweir { 2074cdf0e10cSrcweir const UIElement& rElement = aWindowVector[j]; 2075cdf0e10cSrcweir uno::Reference< awt::XWindow > xWindow; 2076cdf0e10cSrcweir uno::Reference< ui::XUIElement > xUIElement( rElement.m_xUIElement ); 2077cdf0e10cSrcweir awt::Rectangle aPosSize; 2078cdf0e10cSrcweir 2079cdf0e10cSrcweir if ( !lcl_checkUIElement(xUIElement,aPosSize,xWindow) ) 2080cdf0e10cSrcweir continue; 2081cdf0e10cSrcweir if ( isHorizontalDockingArea( eDockingArea )) 2082cdf0e10cSrcweir { 2083cdf0e10cSrcweir if ( nCurrPos == -1 ) 2084cdf0e10cSrcweir { 2085cdf0e10cSrcweir nCurrPos = rElement.m_aDockedData.m_aPos.Y(); 2086cdf0e10cSrcweir nLastPos = 0; 2087cdf0e10cSrcweir 2088cdf0e10cSrcweir SingleRowColumnWindowData aRowColumnWindowData; 2089cdf0e10cSrcweir aRowColumnWindowData.nRowColumn = nCurrPos; 2090cdf0e10cSrcweir rRowColumnsWindowData.push_back( aRowColumnWindowData ); 2091cdf0e10cSrcweir } 2092cdf0e10cSrcweir 2093cdf0e10cSrcweir sal_Int32 nSpace( 0 ); 2094cdf0e10cSrcweir if ( rElement.m_aDockedData.m_aPos.Y() != nCurrPos ) 2095cdf0e10cSrcweir { 2096cdf0e10cSrcweir if ( eDockingArea == ui::DockingArea_DOCKINGAREA_TOP ) 2097cdf0e10cSrcweir nLastRowColPixelPos += rRowColumnsWindowData[nIndex].nStaticSize; 2098cdf0e10cSrcweir else 2099cdf0e10cSrcweir nLastRowColPixelPos -= rRowColumnsWindowData[nIndex].nStaticSize; 2100cdf0e10cSrcweir ++nIndex; 2101cdf0e10cSrcweir nLastPos = 0; 2102cdf0e10cSrcweir nCurrPos = rElement.m_aDockedData.m_aPos.Y(); 2103cdf0e10cSrcweir SingleRowColumnWindowData aRowColumnWindowData; 2104cdf0e10cSrcweir aRowColumnWindowData.nRowColumn = nCurrPos; 2105cdf0e10cSrcweir rRowColumnsWindowData.push_back( aRowColumnWindowData ); 2106cdf0e10cSrcweir } 2107cdf0e10cSrcweir 2108cdf0e10cSrcweir // Calc space before an element and store it 2109cdf0e10cSrcweir nSpace = ( rElement.m_aDockedData.m_aPos.X() - nLastPos ); 2110cdf0e10cSrcweir if ( rElement.m_aDockedData.m_aPos.X() >= nLastPos ) 2111cdf0e10cSrcweir { 2112cdf0e10cSrcweir rRowColumnsWindowData[nIndex].nSpace += nSpace; 2113cdf0e10cSrcweir nLastPos = rElement.m_aDockedData.m_aPos.X() + aPosSize.Width; 2114cdf0e10cSrcweir } 2115cdf0e10cSrcweir else 2116cdf0e10cSrcweir { 2117cdf0e10cSrcweir nSpace = 0; 2118cdf0e10cSrcweir nLastPos += aPosSize.Width; 2119cdf0e10cSrcweir } 2120cdf0e10cSrcweir rRowColumnsWindowData[nIndex].aRowColumnSpace.push_back( nSpace ); 2121cdf0e10cSrcweir 2122cdf0e10cSrcweir rRowColumnsWindowData[nIndex].aRowColumnWindows.push_back( xWindow ); 2123cdf0e10cSrcweir rRowColumnsWindowData[nIndex].aUIElementNames.push_back( rElement.m_aName ); 2124cdf0e10cSrcweir rRowColumnsWindowData[nIndex].aRowColumnWindowSizes.push_back( 2125cdf0e10cSrcweir awt::Rectangle( rElement.m_aDockedData.m_aPos.X(), 2126cdf0e10cSrcweir rElement.m_aDockedData.m_aPos.Y(), 2127cdf0e10cSrcweir aPosSize.Width, 2128cdf0e10cSrcweir aPosSize.Height )); 2129cdf0e10cSrcweir if ( rRowColumnsWindowData[nIndex].nStaticSize < aPosSize.Height ) 2130cdf0e10cSrcweir rRowColumnsWindowData[nIndex].nStaticSize = aPosSize.Height; 2131cdf0e10cSrcweir if ( eDockingArea == ui::DockingArea_DOCKINGAREA_TOP ) 2132cdf0e10cSrcweir rRowColumnsWindowData[nIndex].aRowColumnRect = awt::Rectangle( 0, nLastRowColPixelPos, 2133cdf0e10cSrcweir aDockAreaRect.Width, aPosSize.Height ); 2134cdf0e10cSrcweir else 2135cdf0e10cSrcweir rRowColumnsWindowData[nIndex].aRowColumnRect = awt::Rectangle( 0, ( nLastRowColPixelPos - aPosSize.Height ), 2136cdf0e10cSrcweir aDockAreaRect.Width, aPosSize.Height ); 2137cdf0e10cSrcweir rRowColumnsWindowData[nIndex].nVarSize += aPosSize.Width + nSpace; 2138cdf0e10cSrcweir } 2139cdf0e10cSrcweir else 2140cdf0e10cSrcweir { 2141cdf0e10cSrcweir if ( nCurrPos == -1 ) 2142cdf0e10cSrcweir { 2143cdf0e10cSrcweir nCurrPos = rElement.m_aDockedData.m_aPos.X(); 2144cdf0e10cSrcweir nLastPos = 0; 2145cdf0e10cSrcweir 2146cdf0e10cSrcweir SingleRowColumnWindowData aRowColumnWindowData; 2147cdf0e10cSrcweir aRowColumnWindowData.nRowColumn = nCurrPos; 2148cdf0e10cSrcweir rRowColumnsWindowData.push_back( aRowColumnWindowData ); 2149cdf0e10cSrcweir } 2150cdf0e10cSrcweir 2151cdf0e10cSrcweir sal_Int32 nSpace( 0 ); 2152cdf0e10cSrcweir if ( rElement.m_aDockedData.m_aPos.X() != nCurrPos ) 2153cdf0e10cSrcweir { 2154cdf0e10cSrcweir if ( eDockingArea == ui::DockingArea_DOCKINGAREA_LEFT ) 2155cdf0e10cSrcweir nLastRowColPixelPos += rRowColumnsWindowData[nIndex].nStaticSize; 2156cdf0e10cSrcweir else 2157cdf0e10cSrcweir nLastRowColPixelPos -= rRowColumnsWindowData[nIndex].nStaticSize; 2158cdf0e10cSrcweir ++nIndex; 2159cdf0e10cSrcweir nLastPos = 0; 2160cdf0e10cSrcweir nCurrPos = rElement.m_aDockedData.m_aPos.X(); 2161cdf0e10cSrcweir SingleRowColumnWindowData aRowColumnWindowData; 2162cdf0e10cSrcweir aRowColumnWindowData.nRowColumn = nCurrPos; 2163cdf0e10cSrcweir rRowColumnsWindowData.push_back( aRowColumnWindowData ); 2164cdf0e10cSrcweir } 2165cdf0e10cSrcweir 2166cdf0e10cSrcweir // Calc space before an element and store it 2167cdf0e10cSrcweir nSpace = ( rElement.m_aDockedData.m_aPos.Y() - nLastPos ); 2168cdf0e10cSrcweir if ( rElement.m_aDockedData.m_aPos.Y() > nLastPos ) 2169cdf0e10cSrcweir { 2170cdf0e10cSrcweir rRowColumnsWindowData[nIndex].nSpace += nSpace; 2171cdf0e10cSrcweir nLastPos = rElement.m_aDockedData.m_aPos.Y() + aPosSize.Height; 2172cdf0e10cSrcweir } 2173cdf0e10cSrcweir else 2174cdf0e10cSrcweir { 2175cdf0e10cSrcweir nSpace = 0; 2176cdf0e10cSrcweir nLastPos += aPosSize.Height; 2177cdf0e10cSrcweir } 2178cdf0e10cSrcweir rRowColumnsWindowData[nIndex].aRowColumnSpace.push_back( nSpace ); 2179cdf0e10cSrcweir 2180cdf0e10cSrcweir rRowColumnsWindowData[nIndex].aRowColumnWindows.push_back( xWindow ); 2181cdf0e10cSrcweir rRowColumnsWindowData[nIndex].aUIElementNames.push_back( rElement.m_aName ); 2182cdf0e10cSrcweir rRowColumnsWindowData[nIndex].aRowColumnWindowSizes.push_back( 2183cdf0e10cSrcweir awt::Rectangle( rElement.m_aDockedData.m_aPos.X(), 2184cdf0e10cSrcweir rElement.m_aDockedData.m_aPos.Y(), 2185cdf0e10cSrcweir aPosSize.Width, 2186cdf0e10cSrcweir aPosSize.Height )); 2187cdf0e10cSrcweir if ( rRowColumnsWindowData[nIndex].nStaticSize < aPosSize.Width ) 2188cdf0e10cSrcweir rRowColumnsWindowData[nIndex].nStaticSize = aPosSize.Width; 2189cdf0e10cSrcweir if ( eDockingArea == ui::DockingArea_DOCKINGAREA_LEFT ) 2190cdf0e10cSrcweir rRowColumnsWindowData[nIndex].aRowColumnRect = awt::Rectangle( nLastRowColPixelPos, 0, 2191cdf0e10cSrcweir aPosSize.Width, aDockAreaRect.Height ); 2192cdf0e10cSrcweir else 2193cdf0e10cSrcweir rRowColumnsWindowData[nIndex].aRowColumnRect = awt::Rectangle( ( nLastRowColPixelPos - aPosSize.Width ), 0, 2194cdf0e10cSrcweir aPosSize.Width, aDockAreaRect.Height ); 2195cdf0e10cSrcweir rRowColumnsWindowData[nIndex].nVarSize += aPosSize.Height + nSpace; 2196cdf0e10cSrcweir } 2197cdf0e10cSrcweir } 2198cdf0e10cSrcweir } 2199cdf0e10cSrcweir 2200cdf0e10cSrcweir void ToolbarLayoutManager::implts_getDockingAreaElementInfoOnSingleRowCol( ui::DockingArea eDockingArea, sal_Int32 nRowCol, SingleRowColumnWindowData& rRowColumnWindowData ) 2201cdf0e10cSrcweir { 2202cdf0e10cSrcweir std::vector< UIElement > aWindowVector; 2203cdf0e10cSrcweir 2204cdf0e10cSrcweir if (( eDockingArea < ui::DockingArea_DOCKINGAREA_TOP ) || ( eDockingArea > ui::DockingArea_DOCKINGAREA_RIGHT )) 2205cdf0e10cSrcweir eDockingArea = ui::DockingArea_DOCKINGAREA_TOP; 2206cdf0e10cSrcweir 2207cdf0e10cSrcweir bool bHorzDockArea = isHorizontalDockingArea( eDockingArea ); 2208cdf0e10cSrcweir 2209cdf0e10cSrcweir /* SAFE AREA ----------------------------------------------------------------------------------------------- */ 2210cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 2211cdf0e10cSrcweir UIElementVector::iterator pIter; 2212cdf0e10cSrcweir UIElementVector::iterator pEnd = m_aUIElements.end(); 2213cdf0e10cSrcweir for ( pIter = m_aUIElements.begin(); pIter != pEnd; pIter++ ) 2214cdf0e10cSrcweir { 2215ffdd8a15SOliver-Rainer Wittmann if ( pIter->m_aDockedData.m_nDockedArea == eDockingArea 2216ffdd8a15SOliver-Rainer Wittmann && pIter->m_bVisible 2217ffdd8a15SOliver-Rainer Wittmann && !pIter->m_bMasterHide 2218ffdd8a15SOliver-Rainer Wittmann && !pIter->m_bFloating ) 2219cdf0e10cSrcweir { 2220cdf0e10cSrcweir bool bSameRowCol = bHorzDockArea ? ( pIter->m_aDockedData.m_aPos.Y() == nRowCol ) : ( pIter->m_aDockedData.m_aPos.X() == nRowCol ); 2221cdf0e10cSrcweir uno::Reference< ui::XUIElement > xUIElement( pIter->m_xUIElement ); 2222cdf0e10cSrcweir 2223cdf0e10cSrcweir if ( bSameRowCol && xUIElement.is() ) 2224cdf0e10cSrcweir { 2225cdf0e10cSrcweir uno::Reference< awt::XWindow > xWindow( xUIElement->getRealInterface(), uno::UNO_QUERY ); 2226cdf0e10cSrcweir if ( xWindow.is() ) 2227cdf0e10cSrcweir { 2228cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 2229cdf0e10cSrcweir Window* pWindow = VCLUnoHelper::GetWindow( xWindow ); 2230cdf0e10cSrcweir uno::Reference< awt::XDockableWindow > xDockWindow( xWindow, uno::UNO_QUERY ); 2231ffdd8a15SOliver-Rainer Wittmann if ( pWindow != NULL 2232ffdd8a15SOliver-Rainer Wittmann && xDockWindow.is() ) 2233ffdd8a15SOliver-Rainer Wittmann { 2234cdf0e10cSrcweir aWindowVector.push_back( *pIter ); // docked windows 2235ffdd8a15SOliver-Rainer Wittmann } 2236cdf0e10cSrcweir } 2237cdf0e10cSrcweir } 2238cdf0e10cSrcweir } 2239cdf0e10cSrcweir } 2240cdf0e10cSrcweir aReadLock.unlock(); 2241cdf0e10cSrcweir /* SAFE AREA ----------------------------------------------------------------------------------------------- */ 2242cdf0e10cSrcweir 2243cdf0e10cSrcweir // Initialize structure 2244cdf0e10cSrcweir rRowColumnWindowData.aUIElementNames.clear(); 2245cdf0e10cSrcweir rRowColumnWindowData.aRowColumnWindows.clear(); 2246cdf0e10cSrcweir rRowColumnWindowData.aRowColumnWindowSizes.clear(); 2247cdf0e10cSrcweir rRowColumnWindowData.aRowColumnSpace.clear(); 2248cdf0e10cSrcweir rRowColumnWindowData.nVarSize = 0; 2249cdf0e10cSrcweir rRowColumnWindowData.nStaticSize = 0; 2250cdf0e10cSrcweir rRowColumnWindowData.nSpace = 0; 2251cdf0e10cSrcweir rRowColumnWindowData.nRowColumn = nRowCol; 2252cdf0e10cSrcweir 2253cdf0e10cSrcweir // Collect data from windows that are on the same row/column 2254cdf0e10cSrcweir sal_Int32 j; 2255cdf0e10cSrcweir sal_Int32 nLastPos( 0 ); 2256cdf0e10cSrcweir 2257cdf0e10cSrcweir const sal_uInt32 nCount = aWindowVector.size(); 2258cdf0e10cSrcweir for ( j = 0; j < sal_Int32( nCount); j++ ) 2259cdf0e10cSrcweir { 2260cdf0e10cSrcweir const UIElement& rElement = aWindowVector[j]; 2261cdf0e10cSrcweir uno::Reference< awt::XWindow > xWindow; 2262cdf0e10cSrcweir uno::Reference< ui::XUIElement > xUIElement( rElement.m_xUIElement ); 2263cdf0e10cSrcweir awt::Rectangle aPosSize; 2264cdf0e10cSrcweir if ( !lcl_checkUIElement(xUIElement,aPosSize,xWindow) ) 2265cdf0e10cSrcweir continue; 2266cdf0e10cSrcweir 2267cdf0e10cSrcweir sal_Int32 nSpace; 2268cdf0e10cSrcweir if ( isHorizontalDockingArea( eDockingArea )) 2269cdf0e10cSrcweir { 2270cdf0e10cSrcweir nSpace = ( rElement.m_aDockedData.m_aPos.X() - nLastPos ); 2271cdf0e10cSrcweir 2272cdf0e10cSrcweir // Calc space before an element and store it 2273cdf0e10cSrcweir if ( rElement.m_aDockedData.m_aPos.X() > nLastPos ) 2274cdf0e10cSrcweir rRowColumnWindowData.nSpace += nSpace; 2275cdf0e10cSrcweir else 2276cdf0e10cSrcweir nSpace = 0; 2277cdf0e10cSrcweir 2278cdf0e10cSrcweir nLastPos = rElement.m_aDockedData.m_aPos.X() + aPosSize.Width; 2279cdf0e10cSrcweir 2280cdf0e10cSrcweir 2281cdf0e10cSrcweir rRowColumnWindowData.aRowColumnWindowSizes.push_back( 2282cdf0e10cSrcweir awt::Rectangle( rElement.m_aDockedData.m_aPos.X(), rElement.m_aDockedData.m_aPos.Y(), 2283cdf0e10cSrcweir aPosSize.Width, aPosSize.Height )); 2284cdf0e10cSrcweir if ( rRowColumnWindowData.nStaticSize < aPosSize.Height ) 2285cdf0e10cSrcweir rRowColumnWindowData.nStaticSize = aPosSize.Height; 2286cdf0e10cSrcweir rRowColumnWindowData.nVarSize += aPosSize.Width; 2287cdf0e10cSrcweir } 2288cdf0e10cSrcweir else 2289cdf0e10cSrcweir { 2290cdf0e10cSrcweir // Calc space before an element and store it 2291cdf0e10cSrcweir nSpace = ( rElement.m_aDockedData.m_aPos.Y() - nLastPos ); 2292cdf0e10cSrcweir if ( rElement.m_aDockedData.m_aPos.Y() > nLastPos ) 2293cdf0e10cSrcweir rRowColumnWindowData.nSpace += nSpace; 2294cdf0e10cSrcweir else 2295cdf0e10cSrcweir nSpace = 0; 2296cdf0e10cSrcweir 2297cdf0e10cSrcweir nLastPos = rElement.m_aDockedData.m_aPos.Y() + aPosSize.Height; 2298cdf0e10cSrcweir 2299cdf0e10cSrcweir rRowColumnWindowData.aRowColumnWindowSizes.push_back( 2300cdf0e10cSrcweir awt::Rectangle( rElement.m_aDockedData.m_aPos.X(), rElement.m_aDockedData.m_aPos.Y(), 2301cdf0e10cSrcweir aPosSize.Width, aPosSize.Height )); 2302cdf0e10cSrcweir if ( rRowColumnWindowData.nStaticSize < aPosSize.Width ) 2303cdf0e10cSrcweir rRowColumnWindowData.nStaticSize = aPosSize.Width; 2304cdf0e10cSrcweir rRowColumnWindowData.nVarSize += aPosSize.Height; 2305cdf0e10cSrcweir } 2306cdf0e10cSrcweir 2307cdf0e10cSrcweir rRowColumnWindowData.aUIElementNames.push_back( rElement.m_aName ); 2308cdf0e10cSrcweir rRowColumnWindowData.aRowColumnWindows.push_back( xWindow ); 2309cdf0e10cSrcweir rRowColumnWindowData.aRowColumnSpace.push_back( nSpace ); 2310cdf0e10cSrcweir rRowColumnWindowData.nVarSize += nSpace; 2311cdf0e10cSrcweir } 2312cdf0e10cSrcweir } 2313cdf0e10cSrcweir 2314cdf0e10cSrcweir ::Rectangle ToolbarLayoutManager::implts_getWindowRectFromRowColumn( 2315cdf0e10cSrcweir ui::DockingArea DockingArea, 2316cdf0e10cSrcweir const SingleRowColumnWindowData& rRowColumnWindowData, 2317cdf0e10cSrcweir const ::Point& rMousePos, 2318cdf0e10cSrcweir const rtl::OUString& rExcludeElementName ) 2319cdf0e10cSrcweir { 2320cdf0e10cSrcweir ::Rectangle aWinRect; 2321cdf0e10cSrcweir 2322cdf0e10cSrcweir if (( DockingArea < ui::DockingArea_DOCKINGAREA_TOP ) || ( DockingArea > ui::DockingArea_DOCKINGAREA_RIGHT )) 2323cdf0e10cSrcweir DockingArea = ui::DockingArea_DOCKINGAREA_TOP; 2324cdf0e10cSrcweir 2325cdf0e10cSrcweir if ( rRowColumnWindowData.aRowColumnWindows.empty() ) 2326cdf0e10cSrcweir return aWinRect; 2327cdf0e10cSrcweir else 2328cdf0e10cSrcweir { 2329cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 2330cdf0e10cSrcweir Window* pContainerWindow( VCLUnoHelper::GetWindow( m_xContainerWindow )); 2331cdf0e10cSrcweir Window* pDockingAreaWindow( VCLUnoHelper::GetWindow( m_xDockAreaWindows[DockingArea] )); 2332cdf0e10cSrcweir aReadLock.unlock(); 2333cdf0e10cSrcweir 2334cdf0e10cSrcweir // Calc correct position of the column/row rectangle to be able to compare it with mouse pos/tracking rect 2335cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 2336cdf0e10cSrcweir 2337cdf0e10cSrcweir // Retrieve output size from container Window 2338cdf0e10cSrcweir if ( pDockingAreaWindow && pContainerWindow ) 2339cdf0e10cSrcweir { 2340cdf0e10cSrcweir const sal_uInt32 nCount = rRowColumnWindowData.aRowColumnWindows.size(); 2341cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < nCount; i++ ) 2342cdf0e10cSrcweir { 2343cdf0e10cSrcweir awt::Rectangle aWindowRect = rRowColumnWindowData.aRowColumnWindows[i]->getPosSize(); 2344cdf0e10cSrcweir ::Rectangle aRect( aWindowRect.X, aWindowRect.Y, aWindowRect.X+aWindowRect.Width, aWindowRect.Y+aWindowRect.Height ); 2345cdf0e10cSrcweir aRect.SetPos( pContainerWindow->ScreenToOutputPixel( pDockingAreaWindow->OutputToScreenPixel( aRect.TopLeft() ))); 2346cdf0e10cSrcweir if ( aRect.IsInside( rMousePos )) 2347cdf0e10cSrcweir { 2348cdf0e10cSrcweir // Check if we have found the excluded element. If yes, we have to provide an empty rectangle. 2349cdf0e10cSrcweir // We prevent that a toolbar cannot be moved when the mouse pointer is inside its own rectangle! 2350cdf0e10cSrcweir if ( rExcludeElementName != rRowColumnWindowData.aUIElementNames[i] ) 2351cdf0e10cSrcweir return aRect; 2352cdf0e10cSrcweir else 2353cdf0e10cSrcweir break; 2354cdf0e10cSrcweir } 2355cdf0e10cSrcweir } 2356cdf0e10cSrcweir } 2357cdf0e10cSrcweir } 2358cdf0e10cSrcweir 2359cdf0e10cSrcweir return aWinRect; 2360cdf0e10cSrcweir } 2361cdf0e10cSrcweir 2362cdf0e10cSrcweir ::Rectangle ToolbarLayoutManager::implts_determineFrontDockingRect( 2363cdf0e10cSrcweir ui::DockingArea eDockingArea, 2364cdf0e10cSrcweir sal_Int32 nRowCol, 2365cdf0e10cSrcweir const ::Rectangle& rDockedElementRect, 2366cdf0e10cSrcweir const ::rtl::OUString& rMovedElementName, 2367cdf0e10cSrcweir const ::Rectangle& rMovedElementRect ) 2368cdf0e10cSrcweir { 2369cdf0e10cSrcweir SingleRowColumnWindowData aRowColumnWindowData; 2370cdf0e10cSrcweir 2371cdf0e10cSrcweir sal_Bool bHorzDockArea( isHorizontalDockingArea( eDockingArea )); 2372cdf0e10cSrcweir implts_getDockingAreaElementInfoOnSingleRowCol( eDockingArea, nRowCol, aRowColumnWindowData ); 2373cdf0e10cSrcweir if ( aRowColumnWindowData.aRowColumnWindows.empty() ) 2374cdf0e10cSrcweir return rMovedElementRect; 2375cdf0e10cSrcweir else 2376cdf0e10cSrcweir { 2377cdf0e10cSrcweir sal_Int32 nSpace( 0 ); 2378cdf0e10cSrcweir ::Rectangle aFrontDockingRect( rMovedElementRect ); 2379cdf0e10cSrcweir const sal_uInt32 nCount = aRowColumnWindowData.aRowColumnWindows.size(); 2380cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < nCount; i++ ) 2381cdf0e10cSrcweir { 2382cdf0e10cSrcweir if ( bHorzDockArea ) 2383cdf0e10cSrcweir { 2384cdf0e10cSrcweir if ( aRowColumnWindowData.aRowColumnWindowSizes[i].X >= rDockedElementRect.Left() ) 2385cdf0e10cSrcweir { 2386cdf0e10cSrcweir nSpace += aRowColumnWindowData.aRowColumnSpace[i]; 2387cdf0e10cSrcweir break; 2388cdf0e10cSrcweir } 2389cdf0e10cSrcweir else if ( aRowColumnWindowData.aUIElementNames[i] == rMovedElementName ) 2390cdf0e10cSrcweir nSpace += aRowColumnWindowData.aRowColumnWindowSizes[i].Width + 2391cdf0e10cSrcweir aRowColumnWindowData.aRowColumnSpace[i]; 2392cdf0e10cSrcweir else 2393cdf0e10cSrcweir nSpace = 0; 2394cdf0e10cSrcweir } 2395cdf0e10cSrcweir else 2396cdf0e10cSrcweir { 2397cdf0e10cSrcweir if ( aRowColumnWindowData.aRowColumnWindowSizes[i].Y >= rDockedElementRect.Top() ) 2398cdf0e10cSrcweir { 2399cdf0e10cSrcweir nSpace += aRowColumnWindowData.aRowColumnSpace[i]; 2400cdf0e10cSrcweir break; 2401cdf0e10cSrcweir } 2402cdf0e10cSrcweir else if ( aRowColumnWindowData.aUIElementNames[i] == rMovedElementName ) 2403cdf0e10cSrcweir nSpace += aRowColumnWindowData.aRowColumnWindowSizes[i].Height + 2404cdf0e10cSrcweir aRowColumnWindowData.aRowColumnSpace[i]; 2405cdf0e10cSrcweir else 2406cdf0e10cSrcweir nSpace = 0; 2407cdf0e10cSrcweir } 2408cdf0e10cSrcweir } 2409cdf0e10cSrcweir 2410cdf0e10cSrcweir if ( nSpace > 0 ) 2411cdf0e10cSrcweir { 2412cdf0e10cSrcweir sal_Int32 nMove = std::min( nSpace, static_cast<sal_Int32>(aFrontDockingRect.getWidth()) ); 2413cdf0e10cSrcweir if ( bHorzDockArea ) 2414cdf0e10cSrcweir aFrontDockingRect.Move( -nMove, 0 ); 2415cdf0e10cSrcweir else 2416cdf0e10cSrcweir aFrontDockingRect.Move( 0, -nMove ); 2417cdf0e10cSrcweir } 2418cdf0e10cSrcweir 2419cdf0e10cSrcweir return aFrontDockingRect; 2420cdf0e10cSrcweir } 2421cdf0e10cSrcweir } 2422cdf0e10cSrcweir 2423cdf0e10cSrcweir void ToolbarLayoutManager::implts_findNextDockingPos( ui::DockingArea DockingArea, const ::Size& aUIElementSize, ::Point& rVirtualPos, ::Point& rPixelPos ) 2424cdf0e10cSrcweir { 2425cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 2426cdf0e10cSrcweir uno::Reference< awt::XWindow > xDockingWindow( m_xDockAreaWindows[DockingArea] ); 2427cdf0e10cSrcweir ::Size aDockingWinSize; 2428cdf0e10cSrcweir Window* pDockingWindow( 0 ); 2429cdf0e10cSrcweir aReadLock.unlock(); 2430cdf0e10cSrcweir 2431cdf0e10cSrcweir if (( DockingArea < ui::DockingArea_DOCKINGAREA_TOP ) || ( DockingArea > ui::DockingArea_DOCKINGAREA_RIGHT )) 2432cdf0e10cSrcweir DockingArea = ui::DockingArea_DOCKINGAREA_TOP; 2433cdf0e10cSrcweir 2434cdf0e10cSrcweir { 2435cdf0e10cSrcweir // Retrieve output size from container Window 2436cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 2437cdf0e10cSrcweir pDockingWindow = VCLUnoHelper::GetWindow( xDockingWindow ); 2438cdf0e10cSrcweir if ( pDockingWindow ) 2439cdf0e10cSrcweir aDockingWinSize = pDockingWindow->GetOutputSizePixel(); 2440cdf0e10cSrcweir } 2441cdf0e10cSrcweir 2442cdf0e10cSrcweir sal_Int32 nFreeRowColPixelPos( 0 ); 2443cdf0e10cSrcweir sal_Int32 nMaxSpace( 0 ); 2444cdf0e10cSrcweir sal_Int32 nNeededSpace( 0 ); 2445cdf0e10cSrcweir sal_Int32 nTopDockingAreaSize( 0 ); 2446cdf0e10cSrcweir 2447cdf0e10cSrcweir if ( isHorizontalDockingArea( DockingArea )) 2448cdf0e10cSrcweir { 2449cdf0e10cSrcweir nMaxSpace = aDockingWinSize.Width(); 2450cdf0e10cSrcweir nNeededSpace = aUIElementSize.Width(); 2451cdf0e10cSrcweir } 2452cdf0e10cSrcweir else 2453cdf0e10cSrcweir { 2454cdf0e10cSrcweir nMaxSpace = aDockingWinSize.Height(); 2455cdf0e10cSrcweir nNeededSpace = aUIElementSize.Height(); 2456cdf0e10cSrcweir nTopDockingAreaSize = implts_getTopBottomDockingAreaSizes().Width(); 2457cdf0e10cSrcweir } 2458cdf0e10cSrcweir 2459cdf0e10cSrcweir std::vector< SingleRowColumnWindowData > aRowColumnsWindowData; 2460cdf0e10cSrcweir 2461cdf0e10cSrcweir implts_getDockingAreaElementInfos( DockingArea, aRowColumnsWindowData ); 2462cdf0e10cSrcweir sal_Int32 nPixelPos( 0 ); 2463cdf0e10cSrcweir const sal_uInt32 nCount = aRowColumnsWindowData.size(); 2464cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < nCount; i++ ) 2465cdf0e10cSrcweir { 2466cdf0e10cSrcweir SingleRowColumnWindowData& rRowColumnWindowData = aRowColumnsWindowData[i]; 2467cdf0e10cSrcweir 2468cdf0e10cSrcweir if (( DockingArea == ui::DockingArea_DOCKINGAREA_BOTTOM ) || 2469cdf0e10cSrcweir ( DockingArea == ui::DockingArea_DOCKINGAREA_RIGHT )) 2470cdf0e10cSrcweir nPixelPos += rRowColumnWindowData.nStaticSize; 2471cdf0e10cSrcweir 2472cdf0e10cSrcweir if ((( nMaxSpace - rRowColumnWindowData.nVarSize ) >= nNeededSpace ) || 2473cdf0e10cSrcweir ( rRowColumnWindowData.nSpace >= nNeededSpace )) 2474cdf0e10cSrcweir { 2475cdf0e10cSrcweir // Check current row where we can find the needed space 2476cdf0e10cSrcweir sal_Int32 nCurrPos( 0 ); 2477cdf0e10cSrcweir const sal_uInt32 nWindowSizesCount = rRowColumnWindowData.aRowColumnWindowSizes.size(); 2478cdf0e10cSrcweir for ( sal_uInt32 j = 0; j < nWindowSizesCount; j++ ) 2479cdf0e10cSrcweir { 2480cdf0e10cSrcweir awt::Rectangle rRect = rRowColumnWindowData.aRowColumnWindowSizes[j]; 2481cdf0e10cSrcweir sal_Int32& rSpace = rRowColumnWindowData.aRowColumnSpace[j]; 2482cdf0e10cSrcweir if ( isHorizontalDockingArea( DockingArea )) 2483cdf0e10cSrcweir { 2484cdf0e10cSrcweir if ( rSpace >= nNeededSpace ) 2485cdf0e10cSrcweir { 2486cdf0e10cSrcweir rVirtualPos = ::Point( nCurrPos, rRowColumnWindowData.nRowColumn ); 2487cdf0e10cSrcweir if ( DockingArea == ui::DockingArea_DOCKINGAREA_TOP ) 2488cdf0e10cSrcweir rPixelPos = ::Point( nCurrPos, nPixelPos ); 2489cdf0e10cSrcweir else 2490cdf0e10cSrcweir rPixelPos = ::Point( nCurrPos, aDockingWinSize.Height() - nPixelPos ); 2491cdf0e10cSrcweir return; 2492cdf0e10cSrcweir } 2493cdf0e10cSrcweir nCurrPos = rRect.X + rRect.Width; 2494cdf0e10cSrcweir } 2495cdf0e10cSrcweir else 2496cdf0e10cSrcweir { 2497cdf0e10cSrcweir if ( rSpace >= nNeededSpace ) 2498cdf0e10cSrcweir { 2499cdf0e10cSrcweir rVirtualPos = ::Point( rRowColumnWindowData.nRowColumn, nCurrPos ); 2500cdf0e10cSrcweir if ( DockingArea == ui::DockingArea_DOCKINGAREA_LEFT ) 2501cdf0e10cSrcweir rPixelPos = ::Point( nPixelPos, nTopDockingAreaSize + nCurrPos ); 2502cdf0e10cSrcweir else 2503cdf0e10cSrcweir rPixelPos = ::Point( aDockingWinSize.Width() - nPixelPos , nTopDockingAreaSize + nCurrPos ); 2504cdf0e10cSrcweir return; 2505cdf0e10cSrcweir } 2506cdf0e10cSrcweir nCurrPos = rRect.Y + rRect.Height; 2507cdf0e10cSrcweir } 2508cdf0e10cSrcweir } 2509cdf0e10cSrcweir 2510cdf0e10cSrcweir if (( nCurrPos + nNeededSpace ) <= nMaxSpace ) 2511cdf0e10cSrcweir { 2512cdf0e10cSrcweir if ( isHorizontalDockingArea( DockingArea )) 2513cdf0e10cSrcweir { 2514cdf0e10cSrcweir rVirtualPos = ::Point( nCurrPos, rRowColumnWindowData.nRowColumn ); 2515cdf0e10cSrcweir if ( DockingArea == ui::DockingArea_DOCKINGAREA_TOP ) 2516cdf0e10cSrcweir rPixelPos = ::Point( nCurrPos, nPixelPos ); 2517cdf0e10cSrcweir else 2518cdf0e10cSrcweir rPixelPos = ::Point( nCurrPos, aDockingWinSize.Height() - nPixelPos ); 2519cdf0e10cSrcweir return; 2520cdf0e10cSrcweir } 2521cdf0e10cSrcweir else 2522cdf0e10cSrcweir { 2523cdf0e10cSrcweir rVirtualPos = ::Point( rRowColumnWindowData.nRowColumn, nCurrPos ); 2524cdf0e10cSrcweir if ( DockingArea == ui::DockingArea_DOCKINGAREA_LEFT ) 2525cdf0e10cSrcweir rPixelPos = ::Point( nPixelPos, nTopDockingAreaSize + nCurrPos ); 2526cdf0e10cSrcweir else 2527cdf0e10cSrcweir rPixelPos = ::Point( aDockingWinSize.Width() - nPixelPos , nTopDockingAreaSize + nCurrPos ); 2528cdf0e10cSrcweir return; 2529cdf0e10cSrcweir } 2530cdf0e10cSrcweir } 2531cdf0e10cSrcweir } 2532cdf0e10cSrcweir 2533cdf0e10cSrcweir if (( DockingArea == ui::DockingArea_DOCKINGAREA_TOP ) || ( DockingArea == ui::DockingArea_DOCKINGAREA_LEFT )) 2534cdf0e10cSrcweir nPixelPos += rRowColumnWindowData.nStaticSize; 2535cdf0e10cSrcweir } 2536cdf0e10cSrcweir 2537cdf0e10cSrcweir sal_Int32 nNextFreeRowCol( 0 ); 2538cdf0e10cSrcweir sal_Int32 nRowColumnsCount = aRowColumnsWindowData.size(); 2539cdf0e10cSrcweir if ( nRowColumnsCount > 0 ) 2540cdf0e10cSrcweir nNextFreeRowCol = aRowColumnsWindowData[nRowColumnsCount-1].nRowColumn+1; 2541cdf0e10cSrcweir else 2542cdf0e10cSrcweir nNextFreeRowCol = 0; 2543cdf0e10cSrcweir 2544cdf0e10cSrcweir if ( nNextFreeRowCol == 0 ) 2545cdf0e10cSrcweir { 2546cdf0e10cSrcweir if ( DockingArea == ui::DockingArea_DOCKINGAREA_BOTTOM ) 2547cdf0e10cSrcweir nFreeRowColPixelPos = aDockingWinSize.Height() - aUIElementSize.Height(); 2548cdf0e10cSrcweir else if ( DockingArea == ui::DockingArea_DOCKINGAREA_RIGHT ) 2549cdf0e10cSrcweir nFreeRowColPixelPos = aDockingWinSize.Width() - aUIElementSize.Width(); 2550cdf0e10cSrcweir } 2551cdf0e10cSrcweir 2552cdf0e10cSrcweir if ( isHorizontalDockingArea( DockingArea )) 2553cdf0e10cSrcweir { 2554cdf0e10cSrcweir rVirtualPos = ::Point( 0, nNextFreeRowCol ); 2555cdf0e10cSrcweir if ( DockingArea == ui::DockingArea_DOCKINGAREA_TOP ) 2556cdf0e10cSrcweir rPixelPos = ::Point( 0, nFreeRowColPixelPos ); 2557cdf0e10cSrcweir else 2558cdf0e10cSrcweir rPixelPos = ::Point( 0, aDockingWinSize.Height() - nFreeRowColPixelPos ); 2559cdf0e10cSrcweir } 2560cdf0e10cSrcweir else 2561cdf0e10cSrcweir { 2562cdf0e10cSrcweir rVirtualPos = ::Point( nNextFreeRowCol, 0 ); 2563cdf0e10cSrcweir rPixelPos = ::Point( aDockingWinSize.Width() - nFreeRowColPixelPos, 0 ); 2564cdf0e10cSrcweir } 2565cdf0e10cSrcweir } 2566cdf0e10cSrcweir 2567cdf0e10cSrcweir void ToolbarLayoutManager::implts_calcWindowPosSizeOnSingleRowColumn( 2568cdf0e10cSrcweir sal_Int32 nDockingArea, 2569cdf0e10cSrcweir sal_Int32 nOffset, 2570cdf0e10cSrcweir SingleRowColumnWindowData& rRowColumnWindowData, 2571cdf0e10cSrcweir const ::Size& rContainerSize ) 2572cdf0e10cSrcweir { 2573cdf0e10cSrcweir sal_Int32 nDiff(0); 2574cdf0e10cSrcweir sal_Int32 nRCSpace( rRowColumnWindowData.nSpace ); 2575cdf0e10cSrcweir sal_Int32 nTopDockingAreaSize(0); 2576cdf0e10cSrcweir sal_Int32 nBottomDockingAreaSize(0); 2577cdf0e10cSrcweir sal_Int32 nContainerClientSize(0); 2578cdf0e10cSrcweir 2579cdf0e10cSrcweir if ( rRowColumnWindowData.aRowColumnWindows.empty() ) 2580cdf0e10cSrcweir return; 2581cdf0e10cSrcweir 2582cdf0e10cSrcweir if ( isHorizontalDockingArea( nDockingArea )) 2583cdf0e10cSrcweir { 2584cdf0e10cSrcweir nContainerClientSize = rContainerSize.Width(); 2585cdf0e10cSrcweir nDiff = nContainerClientSize - rRowColumnWindowData.nVarSize; 2586cdf0e10cSrcweir } 2587cdf0e10cSrcweir else 2588cdf0e10cSrcweir { 2589cdf0e10cSrcweir nTopDockingAreaSize = implts_getTopBottomDockingAreaSizes().Width(); 2590cdf0e10cSrcweir nBottomDockingAreaSize = implts_getTopBottomDockingAreaSizes().Height(); 2591cdf0e10cSrcweir nContainerClientSize = ( rContainerSize.Height() - nTopDockingAreaSize - nBottomDockingAreaSize ); 2592cdf0e10cSrcweir nDiff = nContainerClientSize - rRowColumnWindowData.nVarSize; 2593cdf0e10cSrcweir } 2594cdf0e10cSrcweir 2595cdf0e10cSrcweir const sal_uInt32 nCount = rRowColumnWindowData.aRowColumnWindowSizes.size(); 2596cdf0e10cSrcweir if (( nDiff < 0 ) && ( nRCSpace > 0 )) 2597cdf0e10cSrcweir { 2598cdf0e10cSrcweir // First we try to reduce the size of blank space before/behind docked windows 2599cdf0e10cSrcweir sal_Int32 i = nCount - 1; 2600cdf0e10cSrcweir while ( i >= 0 ) 2601cdf0e10cSrcweir { 2602cdf0e10cSrcweir sal_Int32 nSpace = rRowColumnWindowData.aRowColumnSpace[i]; 2603cdf0e10cSrcweir if ( nSpace >= -nDiff ) 2604cdf0e10cSrcweir { 2605cdf0e10cSrcweir if ( isHorizontalDockingArea( nDockingArea )) 2606cdf0e10cSrcweir { 2607cdf0e10cSrcweir // Try to move this and all user elements behind with the calculated difference 2608cdf0e10cSrcweir for ( sal_uInt32 j = i; j < nCount ; j++ ) 2609cdf0e10cSrcweir rRowColumnWindowData.aRowColumnWindowSizes[j].X += nDiff; 2610cdf0e10cSrcweir } 2611cdf0e10cSrcweir else 2612cdf0e10cSrcweir { 2613cdf0e10cSrcweir // Try to move this and all user elements behind with the calculated difference 2614cdf0e10cSrcweir for ( sal_uInt32 j = i; j < nCount ; j++ ) 2615cdf0e10cSrcweir rRowColumnWindowData.aRowColumnWindowSizes[j].Y += nDiff; 2616cdf0e10cSrcweir } 2617cdf0e10cSrcweir nDiff = 0; 2618cdf0e10cSrcweir 2619cdf0e10cSrcweir break; 2620cdf0e10cSrcweir } 2621cdf0e10cSrcweir else if ( nSpace > 0 ) 2622cdf0e10cSrcweir { 2623cdf0e10cSrcweir if ( isHorizontalDockingArea( nDockingArea )) 2624cdf0e10cSrcweir { 2625cdf0e10cSrcweir // Try to move this and all user elements behind with the calculated difference 2626cdf0e10cSrcweir for ( sal_uInt32 j = i; j < nCount; j++ ) 2627cdf0e10cSrcweir rRowColumnWindowData.aRowColumnWindowSizes[j].X -= nSpace; 2628cdf0e10cSrcweir } 2629cdf0e10cSrcweir else 2630cdf0e10cSrcweir { 2631cdf0e10cSrcweir // Try to move this and all user elements behind with the calculated difference 2632cdf0e10cSrcweir for ( sal_uInt32 j = i; j < nCount; j++ ) 2633cdf0e10cSrcweir rRowColumnWindowData.aRowColumnWindowSizes[j].Y -= nSpace; 2634cdf0e10cSrcweir } 2635cdf0e10cSrcweir nDiff += nSpace; 2636cdf0e10cSrcweir } 2637cdf0e10cSrcweir --i; 2638cdf0e10cSrcweir } 2639cdf0e10cSrcweir } 2640cdf0e10cSrcweir 2641cdf0e10cSrcweir // Check if we have to reduce further 2642cdf0e10cSrcweir if ( nDiff < 0 ) 2643cdf0e10cSrcweir { 2644cdf0e10cSrcweir // Now we have to reduce the size of certain docked windows 2645cdf0e10cSrcweir sal_Int32 i = sal_Int32( nCount - 1 ); 2646cdf0e10cSrcweir while ( i >= 0 ) 2647cdf0e10cSrcweir { 2648cdf0e10cSrcweir awt::Rectangle& rWinRect = rRowColumnWindowData.aRowColumnWindowSizes[i]; 2649cdf0e10cSrcweir ::Size aMinSize; 2650cdf0e10cSrcweir 2651cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 2652cdf0e10cSrcweir { 2653cdf0e10cSrcweir uno::Reference< awt::XWindow > xWindow = rRowColumnWindowData.aRowColumnWindows[i]; 2654cdf0e10cSrcweir Window* pWindow = VCLUnoHelper::GetWindow( xWindow ); 2655cdf0e10cSrcweir if ( pWindow && pWindow->GetType() == WINDOW_TOOLBOX ) 2656cdf0e10cSrcweir aMinSize = ((ToolBox *)pWindow)->CalcMinimumWindowSizePixel(); 2657cdf0e10cSrcweir } 2658cdf0e10cSrcweir 2659cdf0e10cSrcweir if (( aMinSize.Width() > 0 ) && ( aMinSize.Height() > 0 )) 2660cdf0e10cSrcweir { 2661cdf0e10cSrcweir if ( isHorizontalDockingArea( nDockingArea )) 2662cdf0e10cSrcweir { 2663cdf0e10cSrcweir sal_Int32 nMaxReducation = ( rWinRect.Width - aMinSize.Width() ); 2664cdf0e10cSrcweir if ( nMaxReducation >= -nDiff ) 2665cdf0e10cSrcweir { 2666cdf0e10cSrcweir rWinRect.Width = rWinRect.Width + nDiff; 2667cdf0e10cSrcweir nDiff = 0; 2668cdf0e10cSrcweir } 2669cdf0e10cSrcweir else 2670cdf0e10cSrcweir { 2671cdf0e10cSrcweir rWinRect.Width = aMinSize.Width(); 2672cdf0e10cSrcweir nDiff += nMaxReducation; 2673cdf0e10cSrcweir } 2674cdf0e10cSrcweir 2675cdf0e10cSrcweir // Try to move this and all user elements behind with the calculated difference 2676cdf0e10cSrcweir for ( sal_uInt32 j = i; j < nCount; j++ ) 2677cdf0e10cSrcweir rRowColumnWindowData.aRowColumnWindowSizes[j].X += nDiff; 2678cdf0e10cSrcweir } 2679cdf0e10cSrcweir else 2680cdf0e10cSrcweir { 2681cdf0e10cSrcweir sal_Int32 nMaxReducation = ( rWinRect.Height - aMinSize.Height() ); 2682cdf0e10cSrcweir if ( nMaxReducation >= -nDiff ) 2683cdf0e10cSrcweir { 2684cdf0e10cSrcweir rWinRect.Height = rWinRect.Height + nDiff; 2685cdf0e10cSrcweir nDiff = 0; 2686cdf0e10cSrcweir } 2687cdf0e10cSrcweir else 2688cdf0e10cSrcweir { 2689cdf0e10cSrcweir rWinRect.Height = aMinSize.Height(); 2690cdf0e10cSrcweir nDiff += nMaxReducation; 2691cdf0e10cSrcweir } 2692cdf0e10cSrcweir 2693cdf0e10cSrcweir // Try to move this and all user elements behind with the calculated difference 2694cdf0e10cSrcweir for ( sal_uInt32 j = i; j < nCount; j++ ) 2695cdf0e10cSrcweir rRowColumnWindowData.aRowColumnWindowSizes[j].Y += nDiff; 2696cdf0e10cSrcweir } 2697cdf0e10cSrcweir } 2698cdf0e10cSrcweir 2699cdf0e10cSrcweir if ( nDiff >= 0 ) 2700cdf0e10cSrcweir break; 2701cdf0e10cSrcweir 2702cdf0e10cSrcweir --i; 2703cdf0e10cSrcweir } 2704cdf0e10cSrcweir } 2705cdf0e10cSrcweir 2706cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 2707cdf0e10cSrcweir Window* pDockAreaWindow = VCLUnoHelper::GetWindow( m_xDockAreaWindows[nDockingArea] ); 2708cdf0e10cSrcweir aReadLock.unlock(); 2709cdf0e10cSrcweir 2710cdf0e10cSrcweir sal_Int32 nCurrPos( 0 ); 2711cdf0e10cSrcweir 2712cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 2713cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < nCount; i++ ) 2714cdf0e10cSrcweir { 2715cdf0e10cSrcweir uno::Reference< awt::XWindow > xWindow = rRowColumnWindowData.aRowColumnWindows[i]; 2716cdf0e10cSrcweir Window* pWindow = VCLUnoHelper::GetWindow( xWindow ); 2717cdf0e10cSrcweir Window* pOldParentWindow = pWindow->GetParent(); 2718cdf0e10cSrcweir 2719cdf0e10cSrcweir if ( pDockAreaWindow != pOldParentWindow ) 2720cdf0e10cSrcweir pWindow->SetParent( pDockAreaWindow ); 2721cdf0e10cSrcweir 2722cdf0e10cSrcweir awt::Rectangle aWinRect = rRowColumnWindowData.aRowColumnWindowSizes[i]; 2723cdf0e10cSrcweir if ( isHorizontalDockingArea( nDockingArea )) 2724cdf0e10cSrcweir { 2725cdf0e10cSrcweir if ( aWinRect.X < nCurrPos ) 2726cdf0e10cSrcweir aWinRect.X = nCurrPos; 2727cdf0e10cSrcweir pWindow->SetPosSizePixel( ::Point( aWinRect.X, nOffset ), ::Size( aWinRect.Width, rRowColumnWindowData.nStaticSize )); 2728cdf0e10cSrcweir pWindow->Show( sal_True, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE ); 2729cdf0e10cSrcweir nCurrPos += ( aWinRect.X - nCurrPos ) + aWinRect.Width; 2730cdf0e10cSrcweir } 2731cdf0e10cSrcweir else 2732cdf0e10cSrcweir { 2733cdf0e10cSrcweir if ( aWinRect.Y < nCurrPos ) 2734cdf0e10cSrcweir aWinRect.Y = nCurrPos; 2735cdf0e10cSrcweir pWindow->SetPosSizePixel( ::Point( nOffset, aWinRect.Y ), ::Size( rRowColumnWindowData.nStaticSize, aWinRect.Height )); 2736cdf0e10cSrcweir pWindow->Show( sal_True, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE ); 2737cdf0e10cSrcweir nCurrPos += ( aWinRect.Y - nCurrPos ) + aWinRect.Height; 2738cdf0e10cSrcweir } 2739cdf0e10cSrcweir } 2740cdf0e10cSrcweir } 2741cdf0e10cSrcweir 2742cdf0e10cSrcweir void ToolbarLayoutManager::implts_setLayoutDirty() 2743cdf0e10cSrcweir { 2744cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 2745cdf0e10cSrcweir m_bLayoutDirty = true; 2746cdf0e10cSrcweir } 2747cdf0e10cSrcweir 2748cdf0e10cSrcweir void ToolbarLayoutManager::implts_setLayoutInProgress( bool bInProgress ) 2749cdf0e10cSrcweir { 2750cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 2751cdf0e10cSrcweir m_bLayoutInProgress = bInProgress; 2752cdf0e10cSrcweir } 2753cdf0e10cSrcweir 2754cdf0e10cSrcweir ::Rectangle ToolbarLayoutManager::implts_calcHotZoneRect( const ::Rectangle& rRect, sal_Int32 nHotZoneOffset ) 2755cdf0e10cSrcweir { 2756cdf0e10cSrcweir ::Rectangle aRect( rRect ); 2757cdf0e10cSrcweir 2758cdf0e10cSrcweir aRect.Left() -= nHotZoneOffset; 2759cdf0e10cSrcweir aRect.Top() -= nHotZoneOffset; 2760cdf0e10cSrcweir aRect.Right() += nHotZoneOffset; 2761cdf0e10cSrcweir aRect.Bottom() += nHotZoneOffset; 2762cdf0e10cSrcweir 2763cdf0e10cSrcweir return aRect; 2764cdf0e10cSrcweir } 2765cdf0e10cSrcweir 2766cdf0e10cSrcweir void ToolbarLayoutManager::implts_calcDockingPosSize( 2767cdf0e10cSrcweir UIElement& rUIElement, 2768cdf0e10cSrcweir DockingOperation& rDockingOperation, 2769cdf0e10cSrcweir ::Rectangle& rTrackingRect, 2770cdf0e10cSrcweir const Point& rMousePos ) 2771cdf0e10cSrcweir { 2772cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 2773cdf0e10cSrcweir uno::Reference< awt::XWindow2 > xContainerWindow( m_xContainerWindow ); 2774cdf0e10cSrcweir ::Size aContainerWinSize; 2775cdf0e10cSrcweir Window* pContainerWindow( 0 ); 2776cdf0e10cSrcweir ::Rectangle aDockingAreaOffsets( m_aDockingAreaOffsets ); 2777cdf0e10cSrcweir aReadLock.unlock(); 2778cdf0e10cSrcweir 2779cdf0e10cSrcweir if ( !rUIElement.m_xUIElement.is() ) 2780cdf0e10cSrcweir { 2781cdf0e10cSrcweir rTrackingRect = ::Rectangle(); 2782cdf0e10cSrcweir return; 2783cdf0e10cSrcweir } 2784cdf0e10cSrcweir 2785cdf0e10cSrcweir { 2786cdf0e10cSrcweir // Retrieve output size from container Window 2787cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 2788cdf0e10cSrcweir pContainerWindow = VCLUnoHelper::GetWindow( xContainerWindow ); 2789cdf0e10cSrcweir aContainerWinSize = pContainerWindow->GetOutputSizePixel(); 2790cdf0e10cSrcweir } 2791cdf0e10cSrcweir 2792cdf0e10cSrcweir Window* pDockWindow( 0 ); 2793cdf0e10cSrcweir Window* pDockingAreaWindow( 0 ); 2794cdf0e10cSrcweir ToolBox* pToolBox( 0 ); 2795cdf0e10cSrcweir uno::Reference< awt::XWindow > xWindow( rUIElement.m_xUIElement->getRealInterface(), uno::UNO_QUERY ); 2796cdf0e10cSrcweir uno::Reference< awt::XWindow > xDockingAreaWindow; 2797cdf0e10cSrcweir ::Rectangle aTrackingRect( rTrackingRect ); 2798cdf0e10cSrcweir ui::DockingArea eDockedArea( (ui::DockingArea)rUIElement.m_aDockedData.m_nDockedArea ); 2799cdf0e10cSrcweir sal_Int32 nTopDockingAreaSize( implts_getTopBottomDockingAreaSizes().Width() ); 2800cdf0e10cSrcweir sal_Int32 nBottomDockingAreaSize( implts_getTopBottomDockingAreaSizes().Height() ); 2801cdf0e10cSrcweir bool bHorizontalDockArea(( eDockedArea == ui::DockingArea_DOCKINGAREA_TOP ) || 2802cdf0e10cSrcweir ( eDockedArea == ui::DockingArea_DOCKINGAREA_BOTTOM )); 2803cdf0e10cSrcweir sal_Int32 nMaxLeftRightDockAreaSize = aContainerWinSize.Height() - 2804cdf0e10cSrcweir nTopDockingAreaSize - 2805cdf0e10cSrcweir nBottomDockingAreaSize - 2806cdf0e10cSrcweir aDockingAreaOffsets.Top() - 2807cdf0e10cSrcweir aDockingAreaOffsets.Bottom(); 2808cdf0e10cSrcweir ::Rectangle aDockingAreaRect; 2809cdf0e10cSrcweir 2810cdf0e10cSrcweir aReadLock.lock(); 2811cdf0e10cSrcweir xDockingAreaWindow = m_xDockAreaWindows[eDockedArea]; 2812cdf0e10cSrcweir aReadLock.unlock(); 2813cdf0e10cSrcweir 2814cdf0e10cSrcweir { 2815cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 2816cdf0e10cSrcweir pDockingAreaWindow = VCLUnoHelper::GetWindow( xDockingAreaWindow ); 2817cdf0e10cSrcweir pDockWindow = VCLUnoHelper::GetWindow( xWindow ); 2818cdf0e10cSrcweir if ( pDockWindow && pDockWindow->GetType() == WINDOW_TOOLBOX ) 2819cdf0e10cSrcweir pToolBox = (ToolBox *)pDockWindow; 2820cdf0e10cSrcweir 2821cdf0e10cSrcweir aDockingAreaRect = ::Rectangle( pDockingAreaWindow->GetPosPixel(), pDockingAreaWindow->GetSizePixel() ); 2822cdf0e10cSrcweir if ( pToolBox ) 2823cdf0e10cSrcweir { 2824cdf0e10cSrcweir // docked toolbars always have one line 2825cdf0e10cSrcweir ::Size aSize = pToolBox->CalcWindowSizePixel( 1, ImplConvertAlignment( sal_Int16( eDockedArea )) ); 2826cdf0e10cSrcweir aTrackingRect.SetSize( ::Size( aSize.Width(), aSize.Height() )); 2827cdf0e10cSrcweir } 2828cdf0e10cSrcweir } 2829cdf0e10cSrcweir 2830cdf0e10cSrcweir // default docking operation, dock on the given row/column 2831cdf0e10cSrcweir bool bOpOutsideOfDockingArea( !aDockingAreaRect.IsInside( rMousePos )); 2832cdf0e10cSrcweir std::vector< SingleRowColumnWindowData > aRowColumnsWindowData; 2833cdf0e10cSrcweir 2834cdf0e10cSrcweir rDockingOperation = DOCKOP_ON_COLROW; 2835cdf0e10cSrcweir implts_getDockingAreaElementInfos( eDockedArea, aRowColumnsWindowData ); 2836cdf0e10cSrcweir 2837cdf0e10cSrcweir // determine current first row/column and last row/column 2838cdf0e10cSrcweir sal_Int32 nMaxRowCol( -1 ); 2839cdf0e10cSrcweir sal_Int32 nMinRowCol( SAL_MAX_INT32 ); 2840cdf0e10cSrcweir const sal_uInt32 nCount = aRowColumnsWindowData.size(); 2841cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < nCount; i++ ) 2842cdf0e10cSrcweir { 2843cdf0e10cSrcweir if ( aRowColumnsWindowData[i].nRowColumn > nMaxRowCol ) 2844cdf0e10cSrcweir nMaxRowCol = aRowColumnsWindowData[i].nRowColumn; 2845cdf0e10cSrcweir if ( aRowColumnsWindowData[i].nRowColumn < nMinRowCol ) 2846cdf0e10cSrcweir nMinRowCol = aRowColumnsWindowData[i].nRowColumn; 2847cdf0e10cSrcweir } 2848cdf0e10cSrcweir 2849cdf0e10cSrcweir if ( !bOpOutsideOfDockingArea ) 2850cdf0e10cSrcweir { 2851cdf0e10cSrcweir // docking inside our docking area 2852cdf0e10cSrcweir sal_Int32 nIndex( -1 ); 2853cdf0e10cSrcweir sal_Int32 nRowCol( -1 ); 2854cdf0e10cSrcweir ::Rectangle aWindowRect; 2855cdf0e10cSrcweir ::Rectangle aRowColumnRect; 2856cdf0e10cSrcweir 2857cdf0e10cSrcweir const sal_uInt32 nWindowDataCount = aRowColumnsWindowData.size(); 2858cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < nWindowDataCount; i++ ) 2859cdf0e10cSrcweir { 2860cdf0e10cSrcweir ::Rectangle aRect( aRowColumnsWindowData[i].aRowColumnRect.X, 2861cdf0e10cSrcweir aRowColumnsWindowData[i].aRowColumnRect.Y, 2862cdf0e10cSrcweir aRowColumnsWindowData[i].aRowColumnRect.X + aRowColumnsWindowData[i].aRowColumnRect.Width, 2863cdf0e10cSrcweir aRowColumnsWindowData[i].aRowColumnRect.Y + aRowColumnsWindowData[i].aRowColumnRect.Height ); 2864cdf0e10cSrcweir 2865cdf0e10cSrcweir { 2866cdf0e10cSrcweir // Calc correct position of the column/row rectangle to be able to compare it with mouse pos/tracking rect 2867cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 2868cdf0e10cSrcweir aRect.SetPos( pContainerWindow->ScreenToOutputPixel( pDockingAreaWindow->OutputToScreenPixel( aRect.TopLeft() ))); 2869cdf0e10cSrcweir } 2870cdf0e10cSrcweir 2871cdf0e10cSrcweir bool bIsInsideRowCol( aRect.IsInside( rMousePos ) ); 2872cdf0e10cSrcweir if ( bIsInsideRowCol ) 2873cdf0e10cSrcweir { 2874cdf0e10cSrcweir nIndex = i; 2875cdf0e10cSrcweir nRowCol = aRowColumnsWindowData[i].nRowColumn; 2876cdf0e10cSrcweir rDockingOperation = implts_determineDockingOperation( eDockedArea, aRect, rMousePos ); 2877cdf0e10cSrcweir aWindowRect = implts_getWindowRectFromRowColumn( eDockedArea, aRowColumnsWindowData[i], rMousePos, rUIElement.m_aName ); 2878cdf0e10cSrcweir aRowColumnRect = aRect; 2879cdf0e10cSrcweir break; 2880cdf0e10cSrcweir } 2881cdf0e10cSrcweir } 2882cdf0e10cSrcweir 2883cdf0e10cSrcweir OSL_ENSURE( ( nIndex >= 0 ) && ( nRowCol >= 0 ), "Impossible case - no row/column found but mouse pointer is inside our docking area" ); 2884cdf0e10cSrcweir if (( nIndex >= 0 ) && ( nRowCol >= 0 )) 2885cdf0e10cSrcweir { 2886cdf0e10cSrcweir if ( rDockingOperation == DOCKOP_ON_COLROW ) 2887cdf0e10cSrcweir { 2888cdf0e10cSrcweir if ( !aWindowRect.IsEmpty()) 2889cdf0e10cSrcweir { 2890cdf0e10cSrcweir // Tracking rect is on a row/column and mouse is over a docked toolbar. 2891cdf0e10cSrcweir // Determine if the tracking rect must be located before/after the docked toolbar. 2892cdf0e10cSrcweir 2893cdf0e10cSrcweir ::Rectangle aUIElementRect( aWindowRect ); 2894cdf0e10cSrcweir sal_Int32 nMiddle( bHorizontalDockArea ? ( aWindowRect.Left() + aWindowRect.getWidth() / 2 ) : 2895cdf0e10cSrcweir ( aWindowRect.Top() + aWindowRect.getHeight() / 2 )); 2896cdf0e10cSrcweir sal_Bool bInsertBefore( bHorizontalDockArea ? ( rMousePos.X() < nMiddle ) : ( rMousePos.Y() < nMiddle )); 2897cdf0e10cSrcweir if ( bInsertBefore ) 2898cdf0e10cSrcweir { 2899cdf0e10cSrcweir if ( bHorizontalDockArea ) 2900cdf0e10cSrcweir { 2901cdf0e10cSrcweir sal_Int32 nSize = ::std::max( sal_Int32( 0 ), std::min( sal_Int32( aContainerWinSize.Width() - aWindowRect.Left() ), 2902cdf0e10cSrcweir sal_Int32( aTrackingRect.getWidth() ))); 2903cdf0e10cSrcweir if ( nSize == 0 ) 2904cdf0e10cSrcweir nSize = aWindowRect.getWidth(); 2905cdf0e10cSrcweir 2906cdf0e10cSrcweir aUIElementRect.SetSize( ::Size( nSize, aWindowRect.getHeight() )); 2907cdf0e10cSrcweir aWindowRect = implts_determineFrontDockingRect( eDockedArea, nRowCol, aWindowRect,rUIElement.m_aName, aUIElementRect ); 2908cdf0e10cSrcweir 2909cdf0e10cSrcweir // Set virtual position 2910cdf0e10cSrcweir rUIElement.m_aDockedData.m_aPos.X() = aWindowRect.Left(); 2911cdf0e10cSrcweir rUIElement.m_aDockedData.m_aPos.Y() = nRowCol; 2912cdf0e10cSrcweir } 2913cdf0e10cSrcweir else 2914cdf0e10cSrcweir { 2915cdf0e10cSrcweir sal_Int32 nSize = ::std::max( sal_Int32( 0 ), std::min( sal_Int32( 2916cdf0e10cSrcweir nTopDockingAreaSize + nMaxLeftRightDockAreaSize - aWindowRect.Top() ), 2917cdf0e10cSrcweir sal_Int32( aTrackingRect.getHeight() ))); 2918cdf0e10cSrcweir if ( nSize == 0 ) 2919cdf0e10cSrcweir nSize = aWindowRect.getHeight(); 2920cdf0e10cSrcweir 2921cdf0e10cSrcweir aUIElementRect.SetSize( ::Size( aWindowRect.getWidth(), nSize )); 2922cdf0e10cSrcweir aWindowRect = implts_determineFrontDockingRect( eDockedArea, nRowCol, aWindowRect, rUIElement.m_aName, aUIElementRect ); 2923cdf0e10cSrcweir 2924cdf0e10cSrcweir // Set virtual position 2925cdf0e10cSrcweir sal_Int32 nPosY = pDockingAreaWindow->ScreenToOutputPixel( 2926cdf0e10cSrcweir pContainerWindow->OutputToScreenPixel( aWindowRect.TopLeft() )).Y(); 2927cdf0e10cSrcweir rUIElement.m_aDockedData.m_aPos.X() = nRowCol; 2928cdf0e10cSrcweir rUIElement.m_aDockedData.m_aPos.Y() = nPosY; 2929cdf0e10cSrcweir } 2930cdf0e10cSrcweir 2931cdf0e10cSrcweir rTrackingRect = aWindowRect; 2932cdf0e10cSrcweir return; 2933cdf0e10cSrcweir } 2934cdf0e10cSrcweir else 2935cdf0e10cSrcweir { 2936cdf0e10cSrcweir if ( bHorizontalDockArea ) 2937cdf0e10cSrcweir { 2938cdf0e10cSrcweir sal_Int32 nSize = ::std::max( sal_Int32( 0 ), std::min( sal_Int32(( aContainerWinSize.Width() ) - aWindowRect.Right() ), 2939cdf0e10cSrcweir sal_Int32( aTrackingRect.getWidth() ))); 2940cdf0e10cSrcweir if ( nSize == 0 ) 2941cdf0e10cSrcweir { 2942cdf0e10cSrcweir aUIElementRect.SetPos( ::Point( aContainerWinSize.Width() - aTrackingRect.getWidth(), aWindowRect.Top() )); 2943cdf0e10cSrcweir aUIElementRect.SetSize( ::Size( aTrackingRect.getWidth(), aWindowRect.getHeight() )); 2944cdf0e10cSrcweir rUIElement.m_aDockedData.m_aPos.X() = aUIElementRect.Left(); 2945cdf0e10cSrcweir } 2946cdf0e10cSrcweir else 2947cdf0e10cSrcweir { 2948cdf0e10cSrcweir aUIElementRect.SetPos( ::Point( aWindowRect.Right(), aWindowRect.Top() )); 2949cdf0e10cSrcweir aUIElementRect.SetSize( ::Size( nSize, aWindowRect.getHeight() )); 2950cdf0e10cSrcweir rUIElement.m_aDockedData.m_aPos.X() = aWindowRect.Right(); 2951cdf0e10cSrcweir } 2952cdf0e10cSrcweir 2953cdf0e10cSrcweir // Set virtual position 2954cdf0e10cSrcweir rUIElement.m_aDockedData.m_aPos.Y() = nRowCol; 2955cdf0e10cSrcweir } 2956cdf0e10cSrcweir else 2957cdf0e10cSrcweir { 2958cdf0e10cSrcweir sal_Int32 nSize = ::std::max( sal_Int32( 0 ), std::min( sal_Int32( nTopDockingAreaSize + nMaxLeftRightDockAreaSize - aWindowRect.Bottom() ), 2959cdf0e10cSrcweir sal_Int32( aTrackingRect.getHeight() ))); 2960cdf0e10cSrcweir aUIElementRect.SetPos( ::Point( aWindowRect.Left(), aWindowRect.Bottom() )); 2961cdf0e10cSrcweir aUIElementRect.SetSize( ::Size( aWindowRect.getWidth(), nSize )); 2962cdf0e10cSrcweir 2963cdf0e10cSrcweir // Set virtual position 2964cdf0e10cSrcweir sal_Int32 nPosY( 0 ); 2965cdf0e10cSrcweir { 2966cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 2967cdf0e10cSrcweir nPosY = pDockingAreaWindow->ScreenToOutputPixel( 2968cdf0e10cSrcweir pContainerWindow->OutputToScreenPixel( aWindowRect.BottomRight() )).Y(); 2969cdf0e10cSrcweir } 2970cdf0e10cSrcweir rUIElement.m_aDockedData.m_aPos.X() = nRowCol; 2971cdf0e10cSrcweir rUIElement.m_aDockedData.m_aPos.Y() = nPosY; 2972cdf0e10cSrcweir } 2973cdf0e10cSrcweir 2974cdf0e10cSrcweir rTrackingRect = aUIElementRect; 2975cdf0e10cSrcweir return; 2976cdf0e10cSrcweir } 2977cdf0e10cSrcweir } 2978cdf0e10cSrcweir else 2979cdf0e10cSrcweir { 2980cdf0e10cSrcweir implts_setTrackingRect( eDockedArea, rMousePos, aTrackingRect ); 2981cdf0e10cSrcweir rTrackingRect = implts_calcTrackingAndElementRect( 2982cdf0e10cSrcweir eDockedArea, nRowCol, rUIElement, 2983cdf0e10cSrcweir aTrackingRect, aRowColumnRect, aContainerWinSize ); 2984cdf0e10cSrcweir return; 2985cdf0e10cSrcweir } 2986cdf0e10cSrcweir } 2987cdf0e10cSrcweir else 2988cdf0e10cSrcweir { 2989cdf0e10cSrcweir if ((( nRowCol == nMinRowCol ) && ( rDockingOperation == DOCKOP_BEFORE_COLROW )) || 2990cdf0e10cSrcweir (( nRowCol == nMaxRowCol ) && ( rDockingOperation == DOCKOP_AFTER_COLROW ))) 2991cdf0e10cSrcweir bOpOutsideOfDockingArea = true; 2992cdf0e10cSrcweir else 2993cdf0e10cSrcweir { 2994cdf0e10cSrcweir // handle docking before/after a row 2995cdf0e10cSrcweir implts_setTrackingRect( eDockedArea, rMousePos, aTrackingRect ); 2996cdf0e10cSrcweir rTrackingRect = implts_calcTrackingAndElementRect( 2997cdf0e10cSrcweir eDockedArea, nRowCol, rUIElement, 2998cdf0e10cSrcweir aTrackingRect, aRowColumnRect, aContainerWinSize ); 2999cdf0e10cSrcweir 3000cdf0e10cSrcweir sal_Int32 nOffsetX( 0 ); 3001cdf0e10cSrcweir sal_Int32 nOffsetY( 0 ); 3002cdf0e10cSrcweir if ( bHorizontalDockArea ) 3003cdf0e10cSrcweir nOffsetY = sal_Int32( floor( aRowColumnRect.getHeight() / 2 + 0.5 )); 3004cdf0e10cSrcweir else 3005cdf0e10cSrcweir nOffsetX = sal_Int32( floor( aRowColumnRect.getWidth() / 2 + 0.5 )); 3006cdf0e10cSrcweir 3007cdf0e10cSrcweir if ( rDockingOperation == DOCKOP_BEFORE_COLROW ) 3008cdf0e10cSrcweir { 3009cdf0e10cSrcweir if (( eDockedArea == ui::DockingArea_DOCKINGAREA_TOP ) || ( eDockedArea == ui::DockingArea_DOCKINGAREA_LEFT )) 3010cdf0e10cSrcweir { 3011cdf0e10cSrcweir // Docking before/after means move track rectangle half column/row. 3012cdf0e10cSrcweir // As left and top are ordered 0...n instead of right and bottom 3013cdf0e10cSrcweir // which uses n...0, we have to use negative values for top/left. 3014cdf0e10cSrcweir nOffsetX *= -1; 3015cdf0e10cSrcweir nOffsetY *= -1; 3016cdf0e10cSrcweir } 3017cdf0e10cSrcweir } 3018cdf0e10cSrcweir else 3019cdf0e10cSrcweir { 3020cdf0e10cSrcweir if (( eDockedArea == ui::DockingArea_DOCKINGAREA_BOTTOM ) || ( eDockedArea == ui::DockingArea_DOCKINGAREA_RIGHT )) 3021cdf0e10cSrcweir { 3022cdf0e10cSrcweir // Docking before/after means move track rectangle half column/row. 3023cdf0e10cSrcweir // As left and top are ordered 0...n instead of right and bottom 3024cdf0e10cSrcweir // which uses n...0, we have to use negative values for top/left. 3025cdf0e10cSrcweir nOffsetX *= -1; 3026cdf0e10cSrcweir nOffsetY *= -1; 3027cdf0e10cSrcweir } 3028cdf0e10cSrcweir nRowCol++; 3029cdf0e10cSrcweir } 3030cdf0e10cSrcweir 3031cdf0e10cSrcweir if ( bHorizontalDockArea ) 3032cdf0e10cSrcweir rUIElement.m_aDockedData.m_aPos.Y() = nRowCol; 3033cdf0e10cSrcweir else 3034cdf0e10cSrcweir rUIElement.m_aDockedData.m_aPos.X() = nRowCol; 3035cdf0e10cSrcweir 3036cdf0e10cSrcweir rTrackingRect.Move( nOffsetX, nOffsetY ); 3037cdf0e10cSrcweir rTrackingRect.SetSize( aTrackingRect.GetSize() ); 3038cdf0e10cSrcweir } 3039cdf0e10cSrcweir } 3040cdf0e10cSrcweir } 3041cdf0e10cSrcweir } 3042cdf0e10cSrcweir 3043cdf0e10cSrcweir // Docking outside of our docking window area => 3044cdf0e10cSrcweir // Users want to dock before/after first/last docked element or to an empty docking area 3045cdf0e10cSrcweir if ( bOpOutsideOfDockingArea ) 3046cdf0e10cSrcweir { 3047cdf0e10cSrcweir // set correct size for docking 3048cdf0e10cSrcweir implts_setTrackingRect( eDockedArea, rMousePos, aTrackingRect ); 3049cdf0e10cSrcweir rTrackingRect = aTrackingRect; 3050cdf0e10cSrcweir 3051cdf0e10cSrcweir if ( bHorizontalDockArea ) 3052cdf0e10cSrcweir { 3053cdf0e10cSrcweir sal_Int32 nPosX( std::max( sal_Int32( rTrackingRect.Left()), sal_Int32( 0 ))); 3054cdf0e10cSrcweir if (( nPosX + rTrackingRect.getWidth()) > aContainerWinSize.Width() ) 3055cdf0e10cSrcweir nPosX = std::min( nPosX, 3056cdf0e10cSrcweir std::max( sal_Int32( aContainerWinSize.Width() - rTrackingRect.getWidth() ), 3057cdf0e10cSrcweir sal_Int32( 0 ))); 3058cdf0e10cSrcweir 3059cdf0e10cSrcweir sal_Int32 nSize = std::min( aContainerWinSize.Width(), rTrackingRect.getWidth() ); 3060cdf0e10cSrcweir sal_Int32 nDockHeight = std::max( static_cast<sal_Int32>(aDockingAreaRect.getHeight()), sal_Int32( 0 )); 3061cdf0e10cSrcweir if ( nDockHeight == 0 ) 3062cdf0e10cSrcweir { 3063cdf0e10cSrcweir sal_Int32 nPosY( std::max( aDockingAreaRect.Top(), aDockingAreaRect.Bottom() )); 3064cdf0e10cSrcweir if ( eDockedArea == ui::DockingArea_DOCKINGAREA_BOTTOM ) 3065cdf0e10cSrcweir nPosY -= rTrackingRect.getHeight(); 3066cdf0e10cSrcweir rTrackingRect.SetPos( Point( nPosX, nPosY )); 3067cdf0e10cSrcweir rUIElement.m_aDockedData.m_aPos.Y() = 0; 3068cdf0e10cSrcweir } 3069cdf0e10cSrcweir else if ( rMousePos.Y() < ( aDockingAreaRect.Top() + ( nDockHeight / 2 ))) 3070cdf0e10cSrcweir { 3071cdf0e10cSrcweir rTrackingRect.SetPos( Point( nPosX, aDockingAreaRect.Top() - rTrackingRect.getHeight() )); 3072cdf0e10cSrcweir if ( eDockedArea == ui::DockingArea_DOCKINGAREA_TOP ) 3073cdf0e10cSrcweir rUIElement.m_aDockedData.m_aPos.Y() = 0; 3074cdf0e10cSrcweir else 3075cdf0e10cSrcweir rUIElement.m_aDockedData.m_aPos.Y() = ( nMaxRowCol >= 0 ) ? nMaxRowCol+1 : 0; 3076cdf0e10cSrcweir rDockingOperation = DOCKOP_BEFORE_COLROW; 3077cdf0e10cSrcweir } 3078cdf0e10cSrcweir else 3079cdf0e10cSrcweir { 3080cdf0e10cSrcweir rTrackingRect.SetPos( Point( nPosX, aDockingAreaRect.Bottom() )); 3081cdf0e10cSrcweir if ( eDockedArea == ui::DockingArea_DOCKINGAREA_TOP ) 3082cdf0e10cSrcweir rUIElement.m_aDockedData.m_aPos.Y() = ( nMaxRowCol >= 0 ) ? nMaxRowCol+1 : 0; 3083cdf0e10cSrcweir else 3084cdf0e10cSrcweir rUIElement.m_aDockedData.m_aPos.Y() = 0; 3085cdf0e10cSrcweir rDockingOperation = DOCKOP_AFTER_COLROW; 3086cdf0e10cSrcweir } 3087cdf0e10cSrcweir rTrackingRect.setWidth( nSize ); 3088cdf0e10cSrcweir 3089cdf0e10cSrcweir { 3090cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 3091cdf0e10cSrcweir nPosX = pDockingAreaWindow->ScreenToOutputPixel( 3092cdf0e10cSrcweir pContainerWindow->OutputToScreenPixel( rTrackingRect.TopLeft() )).X(); 3093cdf0e10cSrcweir } 3094cdf0e10cSrcweir rUIElement.m_aDockedData.m_aPos.X() = nPosX; 3095cdf0e10cSrcweir } 3096cdf0e10cSrcweir else 3097cdf0e10cSrcweir { 3098cdf0e10cSrcweir sal_Int32 nMaxDockingAreaHeight = std::max( sal_Int32( 0 ), sal_Int32( nMaxLeftRightDockAreaSize )); 3099cdf0e10cSrcweir sal_Int32 nPosY( std::max( sal_Int32( aTrackingRect.Top()), sal_Int32( nTopDockingAreaSize ))); 3100cdf0e10cSrcweir if (( nPosY + aTrackingRect.getHeight()) > ( nTopDockingAreaSize + nMaxDockingAreaHeight )) 3101cdf0e10cSrcweir nPosY = std::min( nPosY, 3102cdf0e10cSrcweir std::max( sal_Int32( nTopDockingAreaSize + ( nMaxDockingAreaHeight - aTrackingRect.getHeight() )), 3103cdf0e10cSrcweir sal_Int32( nTopDockingAreaSize ))); 3104cdf0e10cSrcweir 3105cdf0e10cSrcweir sal_Int32 nSize = std::min( nMaxDockingAreaHeight, static_cast<sal_Int32>(aTrackingRect.getHeight()) ); 3106cdf0e10cSrcweir sal_Int32 nDockWidth = std::max( static_cast<sal_Int32>(aDockingAreaRect.getWidth()), sal_Int32( 0 )); 3107cdf0e10cSrcweir if ( nDockWidth == 0 ) 3108cdf0e10cSrcweir { 3109cdf0e10cSrcweir sal_Int32 nPosX( std::max( aDockingAreaRect.Left(), aDockingAreaRect.Right() )); 3110cdf0e10cSrcweir if ( eDockedArea == ui::DockingArea_DOCKINGAREA_RIGHT ) 3111cdf0e10cSrcweir nPosX -= rTrackingRect.getWidth(); 3112cdf0e10cSrcweir rTrackingRect.SetPos( Point( nPosX, nPosY )); 3113cdf0e10cSrcweir rUIElement.m_aDockedData.m_aPos.X() = 0; 3114cdf0e10cSrcweir } 3115cdf0e10cSrcweir else if ( rMousePos.X() < ( aDockingAreaRect.Left() + ( nDockWidth / 2 ))) 3116cdf0e10cSrcweir { 3117cdf0e10cSrcweir rTrackingRect.SetPos( Point( aDockingAreaRect.Left() - rTrackingRect.getWidth(), nPosY )); 3118cdf0e10cSrcweir if ( eDockedArea == ui::DockingArea_DOCKINGAREA_LEFT ) 3119cdf0e10cSrcweir rUIElement.m_aDockedData.m_aPos.X() = 0; 3120cdf0e10cSrcweir else 3121cdf0e10cSrcweir rUIElement.m_aDockedData.m_aPos.X() = ( nMaxRowCol >= 0 ) ? nMaxRowCol+1 : 0; 3122cdf0e10cSrcweir rDockingOperation = DOCKOP_BEFORE_COLROW; 3123cdf0e10cSrcweir } 3124cdf0e10cSrcweir else 3125cdf0e10cSrcweir { 3126cdf0e10cSrcweir rTrackingRect.SetPos( Point( aDockingAreaRect.Right(), nPosY )); 3127cdf0e10cSrcweir if ( eDockedArea == ui::DockingArea_DOCKINGAREA_LEFT ) 3128cdf0e10cSrcweir rUIElement.m_aDockedData.m_aPos.X() = ( nMaxRowCol >= 0 ) ? nMaxRowCol+1 : 0; 3129cdf0e10cSrcweir else 3130cdf0e10cSrcweir rUIElement.m_aDockedData.m_aPos.X() = 0; 3131cdf0e10cSrcweir rDockingOperation = DOCKOP_AFTER_COLROW; 3132cdf0e10cSrcweir } 3133cdf0e10cSrcweir rTrackingRect.setHeight( nSize ); 3134cdf0e10cSrcweir 3135cdf0e10cSrcweir { 3136cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 3137cdf0e10cSrcweir nPosY = pDockingAreaWindow->ScreenToOutputPixel( 3138cdf0e10cSrcweir pContainerWindow->OutputToScreenPixel( rTrackingRect.TopLeft() )).Y(); 3139cdf0e10cSrcweir } 3140cdf0e10cSrcweir rUIElement.m_aDockedData.m_aPos.Y() = nPosY; 3141cdf0e10cSrcweir } 3142cdf0e10cSrcweir } 3143cdf0e10cSrcweir } 3144cdf0e10cSrcweir 3145cdf0e10cSrcweir framework::ToolbarLayoutManager::DockingOperation ToolbarLayoutManager::implts_determineDockingOperation( 3146cdf0e10cSrcweir ui::DockingArea DockingArea, 3147cdf0e10cSrcweir const ::Rectangle& rRowColRect, 3148cdf0e10cSrcweir const Point& rMousePos ) 3149cdf0e10cSrcweir { 3150cdf0e10cSrcweir const sal_Int32 nHorzVerticalRegionSize = 6; 3151cdf0e10cSrcweir const sal_Int32 nHorzVerticalMoveRegion = 4; 3152cdf0e10cSrcweir 3153cdf0e10cSrcweir if ( rRowColRect.IsInside( rMousePos )) 3154cdf0e10cSrcweir { 3155cdf0e10cSrcweir if ( isHorizontalDockingArea( DockingArea )) 3156cdf0e10cSrcweir { 3157cdf0e10cSrcweir sal_Int32 nRegion = rRowColRect.getHeight() / nHorzVerticalRegionSize; 3158cdf0e10cSrcweir sal_Int32 nPosY = rRowColRect.Top() + nRegion; 3159cdf0e10cSrcweir 3160cdf0e10cSrcweir if ( rMousePos.Y() < nPosY ) 3161cdf0e10cSrcweir return ( DockingArea == ui::DockingArea_DOCKINGAREA_TOP ) ? DOCKOP_BEFORE_COLROW : DOCKOP_AFTER_COLROW; 3162cdf0e10cSrcweir else if ( rMousePos.Y() < ( nPosY + nRegion*nHorzVerticalMoveRegion )) 3163cdf0e10cSrcweir return DOCKOP_ON_COLROW; 3164cdf0e10cSrcweir else 3165cdf0e10cSrcweir return ( DockingArea == ui::DockingArea_DOCKINGAREA_TOP ) ? DOCKOP_AFTER_COLROW : DOCKOP_BEFORE_COLROW; 3166cdf0e10cSrcweir } 3167cdf0e10cSrcweir else 3168cdf0e10cSrcweir { 3169cdf0e10cSrcweir sal_Int32 nRegion = rRowColRect.getWidth() / nHorzVerticalRegionSize; 3170cdf0e10cSrcweir sal_Int32 nPosX = rRowColRect.Left() + nRegion; 3171cdf0e10cSrcweir 3172cdf0e10cSrcweir if ( rMousePos.X() < nPosX ) 3173cdf0e10cSrcweir return ( DockingArea == ui::DockingArea_DOCKINGAREA_LEFT ) ? DOCKOP_BEFORE_COLROW : DOCKOP_AFTER_COLROW; 3174cdf0e10cSrcweir else if ( rMousePos.X() < ( nPosX + nRegion*nHorzVerticalMoveRegion )) 3175cdf0e10cSrcweir return DOCKOP_ON_COLROW; 3176cdf0e10cSrcweir else 3177cdf0e10cSrcweir return ( DockingArea == ui::DockingArea_DOCKINGAREA_LEFT ) ? DOCKOP_AFTER_COLROW : DOCKOP_BEFORE_COLROW; 3178cdf0e10cSrcweir } 3179cdf0e10cSrcweir } 3180cdf0e10cSrcweir else 3181cdf0e10cSrcweir return DOCKOP_ON_COLROW; 3182cdf0e10cSrcweir } 3183cdf0e10cSrcweir 3184cdf0e10cSrcweir ::Rectangle ToolbarLayoutManager::implts_calcTrackingAndElementRect( 3185cdf0e10cSrcweir ui::DockingArea eDockingArea, 3186cdf0e10cSrcweir sal_Int32 nRowCol, 3187cdf0e10cSrcweir UIElement& rUIElement, 3188cdf0e10cSrcweir const ::Rectangle& rTrackingRect, 3189cdf0e10cSrcweir const ::Rectangle& rRowColumnRect, 3190cdf0e10cSrcweir const ::Size& rContainerWinSize ) 3191cdf0e10cSrcweir { 3192cdf0e10cSrcweir ReadGuard aReadGuard( m_aLock ); 3193cdf0e10cSrcweir ::Rectangle aDockingAreaOffsets( m_aDockingAreaOffsets ); 3194cdf0e10cSrcweir aReadGuard.unlock(); 3195cdf0e10cSrcweir 3196cdf0e10cSrcweir bool bHorizontalDockArea( isHorizontalDockingArea( eDockingArea )); 3197cdf0e10cSrcweir sal_Int32 nTopDockingAreaSize( implts_getTopBottomDockingAreaSizes().Width() ); 3198cdf0e10cSrcweir sal_Int32 nBottomDockingAreaSize( implts_getTopBottomDockingAreaSizes().Height() ); 3199cdf0e10cSrcweir 3200cdf0e10cSrcweir sal_Int32 nMaxLeftRightDockAreaSize = rContainerWinSize.Height() - 3201cdf0e10cSrcweir nTopDockingAreaSize - 3202cdf0e10cSrcweir nBottomDockingAreaSize - 3203cdf0e10cSrcweir aDockingAreaOffsets.Top() - 3204cdf0e10cSrcweir aDockingAreaOffsets.Bottom(); 3205cdf0e10cSrcweir 3206cdf0e10cSrcweir ::Rectangle aTrackingRect( rTrackingRect ); 3207cdf0e10cSrcweir if ( bHorizontalDockArea ) 3208cdf0e10cSrcweir { 3209cdf0e10cSrcweir sal_Int32 nPosX( std::max( sal_Int32( rTrackingRect.Left()), sal_Int32( 0 ))); 3210cdf0e10cSrcweir if (( nPosX + rTrackingRect.getWidth()) > rContainerWinSize.Width() ) 3211cdf0e10cSrcweir nPosX = std::min( nPosX, 3212cdf0e10cSrcweir std::max( sal_Int32( rContainerWinSize.Width() - rTrackingRect.getWidth() ), 3213cdf0e10cSrcweir sal_Int32( 0 ))); 3214cdf0e10cSrcweir 3215cdf0e10cSrcweir sal_Int32 nSize = std::min( rContainerWinSize.Width(), rTrackingRect.getWidth() ); 3216cdf0e10cSrcweir 3217cdf0e10cSrcweir aTrackingRect.SetPos( ::Point( nPosX, rRowColumnRect.Top() )); 3218cdf0e10cSrcweir aTrackingRect.setWidth( nSize ); 3219cdf0e10cSrcweir aTrackingRect.setHeight( rRowColumnRect.getHeight() ); 3220cdf0e10cSrcweir 3221cdf0e10cSrcweir // Set virtual position 3222cdf0e10cSrcweir rUIElement.m_aDockedData.m_aPos.X() = nPosX; 3223cdf0e10cSrcweir rUIElement.m_aDockedData.m_aPos.Y() = nRowCol; 3224cdf0e10cSrcweir } 3225cdf0e10cSrcweir else 3226cdf0e10cSrcweir { 3227cdf0e10cSrcweir sal_Int32 nMaxDockingAreaHeight = std::max( sal_Int32( 0 ), 3228cdf0e10cSrcweir sal_Int32( nMaxLeftRightDockAreaSize )); 3229cdf0e10cSrcweir 3230cdf0e10cSrcweir sal_Int32 nPosY( std::max( sal_Int32( aTrackingRect.Top()), sal_Int32( nTopDockingAreaSize ))); 3231cdf0e10cSrcweir if (( nPosY + aTrackingRect.getHeight()) > ( nTopDockingAreaSize + nMaxDockingAreaHeight )) 3232cdf0e10cSrcweir nPosY = std::min( nPosY, 3233cdf0e10cSrcweir std::max( sal_Int32( nTopDockingAreaSize + ( nMaxDockingAreaHeight - aTrackingRect.getHeight() )), 3234cdf0e10cSrcweir sal_Int32( nTopDockingAreaSize ))); 3235cdf0e10cSrcweir 3236cdf0e10cSrcweir sal_Int32 nSize = std::min( nMaxDockingAreaHeight, static_cast<sal_Int32>(aTrackingRect.getHeight()) ); 3237cdf0e10cSrcweir 3238cdf0e10cSrcweir aTrackingRect.SetPos( ::Point( rRowColumnRect.Left(), nPosY )); 3239cdf0e10cSrcweir aTrackingRect.setWidth( rRowColumnRect.getWidth() ); 3240cdf0e10cSrcweir aTrackingRect.setHeight( nSize ); 3241cdf0e10cSrcweir 3242cdf0e10cSrcweir aReadGuard.lock(); 3243cdf0e10cSrcweir uno::Reference< awt::XWindow > xDockingAreaWindow( m_xDockAreaWindows[eDockingArea] ); 3244cdf0e10cSrcweir uno::Reference< awt::XWindow2 > xContainerWindow( m_xContainerWindow ); 3245cdf0e10cSrcweir aReadGuard.unlock(); 3246cdf0e10cSrcweir 3247cdf0e10cSrcweir sal_Int32 nDockPosY( 0 ); 3248cdf0e10cSrcweir Window* pDockingAreaWindow( 0 ); 3249cdf0e10cSrcweir Window* pContainerWindow( 0 ); 3250cdf0e10cSrcweir { 3251cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 3252cdf0e10cSrcweir pDockingAreaWindow = VCLUnoHelper::GetWindow( xDockingAreaWindow ); 3253cdf0e10cSrcweir pContainerWindow = VCLUnoHelper::GetWindow( xContainerWindow ); 3254cdf0e10cSrcweir nDockPosY = pDockingAreaWindow->ScreenToOutputPixel( pContainerWindow->OutputToScreenPixel( ::Point( 0, nPosY ))).Y(); 3255cdf0e10cSrcweir } 3256cdf0e10cSrcweir 3257cdf0e10cSrcweir // Set virtual position 3258cdf0e10cSrcweir rUIElement.m_aDockedData.m_aPos.X() = nRowCol; 3259cdf0e10cSrcweir rUIElement.m_aDockedData.m_aPos.Y() = nDockPosY; 3260cdf0e10cSrcweir } 3261cdf0e10cSrcweir 3262cdf0e10cSrcweir return aTrackingRect; 3263cdf0e10cSrcweir } 3264cdf0e10cSrcweir 3265cdf0e10cSrcweir void ToolbarLayoutManager::implts_setTrackingRect( ui::DockingArea eDockingArea, const ::Point& rMousePos, ::Rectangle& rTrackingRect ) 3266cdf0e10cSrcweir { 3267cdf0e10cSrcweir ::Point aPoint( rTrackingRect.TopLeft()); 3268cdf0e10cSrcweir if ( isHorizontalDockingArea( eDockingArea )) 3269cdf0e10cSrcweir aPoint.X() = rMousePos.X(); 3270cdf0e10cSrcweir else 3271cdf0e10cSrcweir aPoint.Y() = rMousePos.Y(); 3272cdf0e10cSrcweir rTrackingRect.SetPos( aPoint ); 3273cdf0e10cSrcweir } 3274cdf0e10cSrcweir 3275cdf0e10cSrcweir void ToolbarLayoutManager::implts_renumberRowColumnData( 3276cdf0e10cSrcweir ui::DockingArea eDockingArea, 3277cdf0e10cSrcweir DockingOperation /*eDockingOperation*/, 3278cdf0e10cSrcweir const UIElement& rUIElement ) 3279cdf0e10cSrcweir { 3280cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 3281cdf0e10cSrcweir uno::Reference< container::XNameAccess > xPersistentWindowState( m_xPersistentWindowState ); 3282cdf0e10cSrcweir aReadLock.unlock(); 3283cdf0e10cSrcweir 3284cdf0e10cSrcweir bool bHorzDockingArea( isHorizontalDockingArea( eDockingArea )); 3285cdf0e10cSrcweir sal_Int32 nRowCol( bHorzDockingArea ? rUIElement.m_aDockedData.m_aPos.Y() : rUIElement.m_aDockedData.m_aPos.X() ); 3286cdf0e10cSrcweir 3287cdf0e10cSrcweir /* SAFE AREA ----------------------------------------------------------------------------------------------- */ 3288cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 3289cdf0e10cSrcweir UIElementVector::iterator pIter; 3290cdf0e10cSrcweir for ( pIter = m_aUIElements.begin(); pIter != m_aUIElements.end(); pIter++ ) 3291cdf0e10cSrcweir { 3292cdf0e10cSrcweir if (( pIter->m_aDockedData.m_nDockedArea == sal_Int16( eDockingArea )) && ( pIter->m_aName != rUIElement.m_aName )) 3293cdf0e10cSrcweir { 3294cdf0e10cSrcweir // Don't change toolbars without a valid docking position! 3295cdf0e10cSrcweir if ( isDefaultPos( pIter->m_aDockedData.m_aPos )) 3296cdf0e10cSrcweir continue; 3297cdf0e10cSrcweir 3298cdf0e10cSrcweir sal_Int32 nWindowRowCol = ( bHorzDockingArea ) ? pIter->m_aDockedData.m_aPos.Y() : pIter->m_aDockedData.m_aPos.X(); 3299cdf0e10cSrcweir if ( nWindowRowCol >= nRowCol ) 3300cdf0e10cSrcweir { 3301cdf0e10cSrcweir if ( bHorzDockingArea ) 3302cdf0e10cSrcweir pIter->m_aDockedData.m_aPos.Y() += 1; 3303cdf0e10cSrcweir else 3304cdf0e10cSrcweir pIter->m_aDockedData.m_aPos.X() += 1; 3305cdf0e10cSrcweir } 3306cdf0e10cSrcweir } 3307cdf0e10cSrcweir } 3308cdf0e10cSrcweir aWriteLock.unlock(); 3309cdf0e10cSrcweir /* SAFE AREA ----------------------------------------------------------------------------------------------- */ 3310cdf0e10cSrcweir 3311cdf0e10cSrcweir // We have to change the persistent window state part 3312cdf0e10cSrcweir if ( xPersistentWindowState.is() ) 3313cdf0e10cSrcweir { 3314cdf0e10cSrcweir try 3315cdf0e10cSrcweir { 3316cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aWindowElements = xPersistentWindowState->getElementNames(); 3317cdf0e10cSrcweir for ( sal_Int32 i = 0; i < aWindowElements.getLength(); i++ ) 3318cdf0e10cSrcweir { 3319cdf0e10cSrcweir if ( rUIElement.m_aName != aWindowElements[i] ) 3320cdf0e10cSrcweir { 3321cdf0e10cSrcweir try 3322cdf0e10cSrcweir { 3323cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aPropValueSeq; 3324cdf0e10cSrcweir awt::Point aDockedPos; 3325cdf0e10cSrcweir ui::DockingArea nDockedArea( ui::DockingArea_DOCKINGAREA_DEFAULT ); 3326cdf0e10cSrcweir 3327cdf0e10cSrcweir xPersistentWindowState->getByName( aWindowElements[i] ) >>= aPropValueSeq; 3328cdf0e10cSrcweir for ( sal_Int32 j = 0; j < aPropValueSeq.getLength(); j++ ) 3329cdf0e10cSrcweir { 3330cdf0e10cSrcweir if ( aPropValueSeq[j].Name.equalsAscii( WINDOWSTATE_PROPERTY_DOCKINGAREA )) 3331cdf0e10cSrcweir aPropValueSeq[j].Value >>= nDockedArea; 3332cdf0e10cSrcweir else if ( aPropValueSeq[j].Name.equalsAscii( WINDOWSTATE_PROPERTY_DOCKPOS )) 3333cdf0e10cSrcweir aPropValueSeq[j].Value >>= aDockedPos; 3334cdf0e10cSrcweir } 3335cdf0e10cSrcweir 3336cdf0e10cSrcweir // Don't change toolbars without a valid docking position! 3337cdf0e10cSrcweir if ( isDefaultPos( aDockedPos )) 3338cdf0e10cSrcweir continue; 3339cdf0e10cSrcweir 3340cdf0e10cSrcweir sal_Int32 nWindowRowCol = ( bHorzDockingArea ) ? aDockedPos.Y : aDockedPos.X; 3341cdf0e10cSrcweir if (( nDockedArea == eDockingArea ) && ( nWindowRowCol >= nRowCol )) 3342cdf0e10cSrcweir { 3343cdf0e10cSrcweir if ( bHorzDockingArea ) 3344cdf0e10cSrcweir aDockedPos.Y += 1; 3345cdf0e10cSrcweir else 3346cdf0e10cSrcweir aDockedPos.X += 1; 3347cdf0e10cSrcweir 3348cdf0e10cSrcweir uno::Reference< container::XNameReplace > xReplace( xPersistentWindowState, uno::UNO_QUERY ); 3349cdf0e10cSrcweir xReplace->replaceByName( aWindowElements[i], makeAny( aPropValueSeq )); 3350cdf0e10cSrcweir } 3351cdf0e10cSrcweir } 3352cdf0e10cSrcweir catch ( uno::Exception& ) {} 3353cdf0e10cSrcweir } 3354cdf0e10cSrcweir } 3355cdf0e10cSrcweir } 3356cdf0e10cSrcweir catch ( uno::Exception& ) {} 3357cdf0e10cSrcweir } 3358cdf0e10cSrcweir } 3359cdf0e10cSrcweir 3360cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 3361cdf0e10cSrcweir // XWindowListener 3362cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 3363cdf0e10cSrcweir void SAL_CALL ToolbarLayoutManager::windowResized( const awt::WindowEvent& aEvent ) 3364cdf0e10cSrcweir throw( uno::RuntimeException ) 3365cdf0e10cSrcweir { 3366cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 3367cdf0e10cSrcweir bool bLocked( m_bDockingInProgress ); 3368cdf0e10cSrcweir bool bLayoutInProgress( m_bLayoutInProgress ); 3369cdf0e10cSrcweir aWriteLock.unlock(); 3370cdf0e10cSrcweir 3371cdf0e10cSrcweir // Do not do anything if we are in the middle of a docking process. This would interfere all other 3372cdf0e10cSrcweir // operations. We will store the new position and size in the docking handlers. 3373cdf0e10cSrcweir // Do not do anything if we are in the middle of our layouting process. We will adapt the position 3374cdf0e10cSrcweir // and size of the user interface elements. 3375cdf0e10cSrcweir if ( !bLocked && !bLayoutInProgress ) 3376cdf0e10cSrcweir { 3377cdf0e10cSrcweir bool bNotify( false ); 3378cdf0e10cSrcweir uno::Reference< awt::XWindow > xWindow( aEvent.Source, uno::UNO_QUERY ); 3379cdf0e10cSrcweir 3380cdf0e10cSrcweir UIElement aUIElement = implts_findToolbar( aEvent.Source ); 3381cdf0e10cSrcweir if ( aUIElement.m_xUIElement.is() ) 3382cdf0e10cSrcweir { 3383cdf0e10cSrcweir if ( aUIElement.m_bFloating ) 3384cdf0e10cSrcweir { 3385cdf0e10cSrcweir uno::Reference< awt::XWindow2 > xWindow2( xWindow, uno::UNO_QUERY ); 3386cdf0e10cSrcweir 3387cdf0e10cSrcweir if( xWindow2.is() ) 3388cdf0e10cSrcweir { 3389cdf0e10cSrcweir awt::Rectangle aPos = xWindow2->getPosSize(); 3390cdf0e10cSrcweir awt::Size aSize = xWindow2->getOutputSize(); // always use output size for consistency 3391cdf0e10cSrcweir bool bVisible = xWindow2->isVisible(); 3392cdf0e10cSrcweir 3393cdf0e10cSrcweir // update element data 3394cdf0e10cSrcweir aUIElement.m_aFloatingData.m_aPos = ::Point( aPos.X, aPos.Y ); 3395cdf0e10cSrcweir aUIElement.m_aFloatingData.m_aSize = ::Size( aSize.Width, aSize.Height ); 3396cdf0e10cSrcweir aUIElement.m_bVisible = bVisible; 3397cdf0e10cSrcweir } 3398cdf0e10cSrcweir 3399cdf0e10cSrcweir implts_writeWindowStateData( aUIElement ); 3400cdf0e10cSrcweir } 3401cdf0e10cSrcweir else 3402cdf0e10cSrcweir { 3403cdf0e10cSrcweir implts_setLayoutDirty(); 3404cdf0e10cSrcweir bNotify = true; 3405cdf0e10cSrcweir } 3406cdf0e10cSrcweir } 3407cdf0e10cSrcweir 3408cdf0e10cSrcweir if ( bNotify ) 3409cdf0e10cSrcweir m_pParentLayouter->requestLayout( ILayoutNotifications::HINT_TOOLBARSPACE_HAS_CHANGED ); 3410cdf0e10cSrcweir } 3411cdf0e10cSrcweir } 3412cdf0e10cSrcweir 3413cdf0e10cSrcweir void SAL_CALL ToolbarLayoutManager::windowMoved( const awt::WindowEvent& /*aEvent*/ ) 3414cdf0e10cSrcweir throw( uno::RuntimeException ) 3415cdf0e10cSrcweir { 3416cdf0e10cSrcweir } 3417cdf0e10cSrcweir 3418cdf0e10cSrcweir void SAL_CALL ToolbarLayoutManager::windowShown( const lang::EventObject& /*aEvent*/ ) 3419cdf0e10cSrcweir throw( uno::RuntimeException ) 3420cdf0e10cSrcweir { 3421cdf0e10cSrcweir } 3422cdf0e10cSrcweir 3423cdf0e10cSrcweir void SAL_CALL ToolbarLayoutManager::windowHidden( const lang::EventObject& /*aEvent*/ ) 3424cdf0e10cSrcweir throw( uno::RuntimeException ) 3425cdf0e10cSrcweir { 3426cdf0e10cSrcweir } 3427cdf0e10cSrcweir 3428cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 3429cdf0e10cSrcweir // XDockableWindowListener 3430cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 3431cdf0e10cSrcweir void SAL_CALL ToolbarLayoutManager::startDocking( const awt::DockingEvent& e ) 3432cdf0e10cSrcweir throw (uno::RuntimeException) 3433cdf0e10cSrcweir { 3434cdf0e10cSrcweir bool bWinFound( false ); 3435cdf0e10cSrcweir 3436cdf0e10cSrcweir ReadGuard aReadGuard( m_aLock ); 3437cdf0e10cSrcweir uno::Reference< awt::XWindow2 > xContainerWindow( m_xContainerWindow ); 3438cdf0e10cSrcweir uno::Reference< awt::XWindow2 > xWindow( e.Source, uno::UNO_QUERY ); 3439cdf0e10cSrcweir aReadGuard.unlock(); 3440cdf0e10cSrcweir 3441cdf0e10cSrcweir Window* pContainerWindow( 0 ); 3442cdf0e10cSrcweir Window* pWindow( 0 ); 3443cdf0e10cSrcweir ::Point aMousePos; 3444cdf0e10cSrcweir { 3445cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 3446cdf0e10cSrcweir pContainerWindow = VCLUnoHelper::GetWindow( xContainerWindow ); 3447cdf0e10cSrcweir aMousePos = pContainerWindow->ScreenToOutputPixel( ::Point( e.MousePos.X, e.MousePos.Y )); 3448cdf0e10cSrcweir } 3449cdf0e10cSrcweir 3450cdf0e10cSrcweir UIElement aUIElement = implts_findToolbar( e.Source ); 3451cdf0e10cSrcweir 3452cdf0e10cSrcweir if ( aUIElement.m_xUIElement.is() && xWindow.is() ) 3453cdf0e10cSrcweir { 3454cdf0e10cSrcweir awt::Rectangle aRect; 3455cdf0e10cSrcweir 3456cdf0e10cSrcweir bWinFound = true; 3457cdf0e10cSrcweir uno::Reference< awt::XDockableWindow > xDockWindow( xWindow, uno::UNO_QUERY ); 3458cdf0e10cSrcweir if ( xDockWindow->isFloating() ) 3459cdf0e10cSrcweir { 3460cdf0e10cSrcweir awt::Rectangle aPos = xWindow->getPosSize(); 3461cdf0e10cSrcweir awt::Size aSize = xWindow->getOutputSize(); 3462cdf0e10cSrcweir 3463cdf0e10cSrcweir aUIElement.m_aFloatingData.m_aPos = ::Point( aPos.X, aPos.Y ); 3464cdf0e10cSrcweir aUIElement.m_aFloatingData.m_aSize = ::Size( aSize.Width, aSize.Height ); 3465cdf0e10cSrcweir 3466cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 3467cdf0e10cSrcweir pWindow = VCLUnoHelper::GetWindow( xWindow ); 3468cdf0e10cSrcweir if ( pWindow && pWindow->GetType() == WINDOW_TOOLBOX ) 3469cdf0e10cSrcweir { 3470cdf0e10cSrcweir ToolBox* pToolBox = (ToolBox *)pWindow; 3471cdf0e10cSrcweir aUIElement.m_aFloatingData.m_nLines = pToolBox->GetFloatingLines(); 3472cdf0e10cSrcweir aUIElement.m_aFloatingData.m_bIsHorizontal = isToolboxHorizontalAligned( pToolBox ); 3473cdf0e10cSrcweir } 3474cdf0e10cSrcweir } 3475cdf0e10cSrcweir } 3476cdf0e10cSrcweir 3477cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 3478cdf0e10cSrcweir m_bDockingInProgress = bWinFound; 3479cdf0e10cSrcweir m_aDockUIElement = aUIElement; 3480cdf0e10cSrcweir m_aDockUIElement.m_bUserActive = true; 3481cdf0e10cSrcweir m_aStartDockMousePos = aMousePos; 3482cdf0e10cSrcweir aWriteLock.unlock(); 3483cdf0e10cSrcweir } 3484cdf0e10cSrcweir 3485cdf0e10cSrcweir awt::DockingData SAL_CALL ToolbarLayoutManager::docking( const awt::DockingEvent& e ) 3486cdf0e10cSrcweir throw (uno::RuntimeException) 3487cdf0e10cSrcweir { 3488cdf0e10cSrcweir const sal_Int32 MAGNETIC_DISTANCE_UNDOCK = 25; 3489cdf0e10cSrcweir const sal_Int32 MAGNETIC_DISTANCE_DOCK = 20; 3490cdf0e10cSrcweir 3491cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 3492cdf0e10cSrcweir awt::DockingData aDockingData; 3493cdf0e10cSrcweir uno::Reference< awt::XDockableWindow > xDockWindow( e.Source, uno::UNO_QUERY ); 3494cdf0e10cSrcweir uno::Reference< awt::XWindow > xWindow( e.Source, uno::UNO_QUERY ); 3495cdf0e10cSrcweir uno::Reference< awt::XWindow > xTopDockingWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_TOP] ); 3496cdf0e10cSrcweir uno::Reference< awt::XWindow > xLeftDockingWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_LEFT] ); 3497cdf0e10cSrcweir uno::Reference< awt::XWindow > xRightDockingWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_RIGHT] ); 3498cdf0e10cSrcweir uno::Reference< awt::XWindow > xBottomDockingWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_BOTTOM] ); 3499cdf0e10cSrcweir uno::Reference< awt::XWindow2 > xContainerWindow( m_xContainerWindow ); 3500cdf0e10cSrcweir UIElement aUIDockingElement( m_aDockUIElement ); 3501cdf0e10cSrcweir DockingOperation eDockingOperation( DOCKOP_ON_COLROW ); 3502cdf0e10cSrcweir bool bDockingInProgress( m_bDockingInProgress ); 3503cdf0e10cSrcweir aReadLock.unlock(); 3504cdf0e10cSrcweir 3505cdf0e10cSrcweir if ( bDockingInProgress ) 3506cdf0e10cSrcweir aDockingData.TrackingRectangle = e.TrackingRectangle; 3507cdf0e10cSrcweir 3508cdf0e10cSrcweir if ( bDockingInProgress && xDockWindow.is() && xWindow.is() ) 3509cdf0e10cSrcweir { 3510cdf0e10cSrcweir try 3511cdf0e10cSrcweir { 3512cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 3513cdf0e10cSrcweir 3514cdf0e10cSrcweir sal_Int16 eDockingArea( -1 ); // none 3515cdf0e10cSrcweir sal_Int32 nMagneticZone( aUIDockingElement.m_bFloating ? MAGNETIC_DISTANCE_DOCK : MAGNETIC_DISTANCE_UNDOCK ); 3516cdf0e10cSrcweir awt::Rectangle aNewTrackingRect; 3517cdf0e10cSrcweir ::Rectangle aTrackingRect( e.TrackingRectangle.X, e.TrackingRectangle.Y, 3518cdf0e10cSrcweir ( e.TrackingRectangle.X + e.TrackingRectangle.Width ), 3519cdf0e10cSrcweir ( e.TrackingRectangle.Y + e.TrackingRectangle.Height )); 3520cdf0e10cSrcweir 3521cdf0e10cSrcweir awt::Rectangle aTmpRect = xTopDockingWindow->getPosSize(); 3522cdf0e10cSrcweir ::Rectangle aTopDockRect( aTmpRect.X, aTmpRect.Y, aTmpRect.Width, aTmpRect.Height ); 3523cdf0e10cSrcweir ::Rectangle aHotZoneTopDockRect( implts_calcHotZoneRect( aTopDockRect, nMagneticZone )); 3524cdf0e10cSrcweir 3525cdf0e10cSrcweir aTmpRect = xBottomDockingWindow->getPosSize(); 3526cdf0e10cSrcweir ::Rectangle aBottomDockRect( aTmpRect.X, aTmpRect.Y, ( aTmpRect.X + aTmpRect.Width), ( aTmpRect.Y + aTmpRect.Height )); 3527cdf0e10cSrcweir ::Rectangle aHotZoneBottomDockRect( implts_calcHotZoneRect( aBottomDockRect, nMagneticZone )); 3528cdf0e10cSrcweir 3529cdf0e10cSrcweir aTmpRect = xLeftDockingWindow->getPosSize(); 3530cdf0e10cSrcweir ::Rectangle aLeftDockRect( aTmpRect.X, aTmpRect.Y, ( aTmpRect.X + aTmpRect.Width ), ( aTmpRect.Y + aTmpRect.Height )); 3531cdf0e10cSrcweir ::Rectangle aHotZoneLeftDockRect( implts_calcHotZoneRect( aLeftDockRect, nMagneticZone )); 3532cdf0e10cSrcweir 3533cdf0e10cSrcweir aTmpRect = xRightDockingWindow->getPosSize(); 3534cdf0e10cSrcweir ::Rectangle aRightDockRect( aTmpRect.X, aTmpRect.Y, ( aTmpRect.X + aTmpRect.Width ), ( aTmpRect.Y + aTmpRect.Height )); 3535cdf0e10cSrcweir ::Rectangle aHotZoneRightDockRect( implts_calcHotZoneRect( aRightDockRect, nMagneticZone )); 3536cdf0e10cSrcweir 3537cdf0e10cSrcweir Window* pContainerWindow( VCLUnoHelper::GetWindow( xContainerWindow ) ); 3538cdf0e10cSrcweir Window* pDockingAreaWindow( 0 ); 3539cdf0e10cSrcweir ::Point aMousePos( pContainerWindow->ScreenToOutputPixel( ::Point( e.MousePos.X, e.MousePos.Y ))); 3540cdf0e10cSrcweir 3541cdf0e10cSrcweir if ( aHotZoneTopDockRect.IsInside( aMousePos )) 3542cdf0e10cSrcweir eDockingArea = ui::DockingArea_DOCKINGAREA_TOP; 3543cdf0e10cSrcweir else if ( aHotZoneBottomDockRect.IsInside( aMousePos )) 3544cdf0e10cSrcweir eDockingArea = ui::DockingArea_DOCKINGAREA_BOTTOM; 3545cdf0e10cSrcweir else if ( aHotZoneLeftDockRect.IsInside( aMousePos )) 3546cdf0e10cSrcweir eDockingArea = ui::DockingArea_DOCKINGAREA_LEFT; 3547cdf0e10cSrcweir else if ( aHotZoneRightDockRect.IsInside( aMousePos )) 3548cdf0e10cSrcweir eDockingArea = ui::DockingArea_DOCKINGAREA_RIGHT; 3549cdf0e10cSrcweir 3550cdf0e10cSrcweir // Higher priority for movements inside the real docking area 3551cdf0e10cSrcweir if ( aTopDockRect.IsInside( aMousePos )) 3552cdf0e10cSrcweir eDockingArea = ui::DockingArea_DOCKINGAREA_TOP; 3553cdf0e10cSrcweir else if ( aBottomDockRect.IsInside( aMousePos )) 3554cdf0e10cSrcweir eDockingArea = ui::DockingArea_DOCKINGAREA_BOTTOM; 3555cdf0e10cSrcweir else if ( aLeftDockRect.IsInside( aMousePos )) 3556cdf0e10cSrcweir eDockingArea = ui::DockingArea_DOCKINGAREA_LEFT; 3557cdf0e10cSrcweir else if ( aRightDockRect.IsInside( aMousePos )) 3558cdf0e10cSrcweir eDockingArea = ui::DockingArea_DOCKINGAREA_RIGHT; 3559cdf0e10cSrcweir 3560cdf0e10cSrcweir // Determine if we have a toolbar and set alignment according to the docking area! 3561cdf0e10cSrcweir Window* pWindow = VCLUnoHelper::GetWindow( xWindow ); 3562cdf0e10cSrcweir ToolBox* pToolBox = 0; 3563cdf0e10cSrcweir if ( pWindow && pWindow->GetType() == WINDOW_TOOLBOX ) 3564cdf0e10cSrcweir pToolBox = (ToolBox *)pWindow; 3565cdf0e10cSrcweir 3566cdf0e10cSrcweir if ( eDockingArea != -1 ) 3567cdf0e10cSrcweir { 3568cdf0e10cSrcweir if ( eDockingArea == ui::DockingArea_DOCKINGAREA_TOP ) 3569cdf0e10cSrcweir { 3570cdf0e10cSrcweir aUIDockingElement.m_aDockedData.m_nDockedArea = ui::DockingArea_DOCKINGAREA_TOP; 3571cdf0e10cSrcweir aUIDockingElement.m_bFloating = false; 3572cdf0e10cSrcweir pDockingAreaWindow = VCLUnoHelper::GetWindow( xTopDockingWindow ); 3573cdf0e10cSrcweir } 3574cdf0e10cSrcweir else if ( eDockingArea == ui::DockingArea_DOCKINGAREA_BOTTOM ) 3575cdf0e10cSrcweir { 3576cdf0e10cSrcweir aUIDockingElement.m_aDockedData.m_nDockedArea = ui::DockingArea_DOCKINGAREA_BOTTOM; 3577cdf0e10cSrcweir aUIDockingElement.m_bFloating = false; 3578cdf0e10cSrcweir pDockingAreaWindow = VCLUnoHelper::GetWindow( xBottomDockingWindow ); 3579cdf0e10cSrcweir } 3580cdf0e10cSrcweir else if ( eDockingArea == ui::DockingArea_DOCKINGAREA_LEFT ) 3581cdf0e10cSrcweir { 3582cdf0e10cSrcweir aUIDockingElement.m_aDockedData.m_nDockedArea = ui::DockingArea_DOCKINGAREA_LEFT; 3583cdf0e10cSrcweir aUIDockingElement.m_bFloating = false; 3584cdf0e10cSrcweir pDockingAreaWindow = VCLUnoHelper::GetWindow( xLeftDockingWindow ); 3585cdf0e10cSrcweir } 3586cdf0e10cSrcweir else if ( eDockingArea == ui::DockingArea_DOCKINGAREA_RIGHT ) 3587cdf0e10cSrcweir { 3588cdf0e10cSrcweir aUIDockingElement.m_aDockedData.m_nDockedArea = ui::DockingArea_DOCKINGAREA_RIGHT; 3589cdf0e10cSrcweir aUIDockingElement.m_bFloating = false; 3590cdf0e10cSrcweir pDockingAreaWindow = VCLUnoHelper::GetWindow( xRightDockingWindow ); 3591cdf0e10cSrcweir } 3592cdf0e10cSrcweir 3593cdf0e10cSrcweir ::Point aOutputPos = pContainerWindow->ScreenToOutputPixel( aTrackingRect.TopLeft() ); 3594cdf0e10cSrcweir aTrackingRect.SetPos( aOutputPos ); 3595cdf0e10cSrcweir 3596cdf0e10cSrcweir ::Rectangle aNewDockingRect( aTrackingRect ); 3597cdf0e10cSrcweir implts_calcDockingPosSize( aUIDockingElement, eDockingOperation, aNewDockingRect, aMousePos ); 3598cdf0e10cSrcweir 3599cdf0e10cSrcweir ::Point aScreenPos = pContainerWindow->OutputToScreenPixel( aNewDockingRect.TopLeft() ); 3600cdf0e10cSrcweir aNewTrackingRect = awt::Rectangle( aScreenPos.X(), aScreenPos.Y(), 3601cdf0e10cSrcweir aNewDockingRect.getWidth(), aNewDockingRect.getHeight() ); 3602cdf0e10cSrcweir aDockingData.TrackingRectangle = aNewTrackingRect; 3603cdf0e10cSrcweir } 3604cdf0e10cSrcweir else if ( pToolBox && bDockingInProgress ) 3605cdf0e10cSrcweir { 3606cdf0e10cSrcweir bool bIsHorizontal = isToolboxHorizontalAligned( pToolBox ); 3607cdf0e10cSrcweir ::Size aFloatSize = aUIDockingElement.m_aFloatingData.m_aSize; 3608cdf0e10cSrcweir if ( aFloatSize.Width() > 0 && aFloatSize.Height() > 0 ) 3609cdf0e10cSrcweir { 3610cdf0e10cSrcweir aUIDockingElement.m_aFloatingData.m_aPos = pContainerWindow->ScreenToOutputPixel( 3611cdf0e10cSrcweir ::Point( e.MousePos.X, e.MousePos.Y )); 3612cdf0e10cSrcweir aDockingData.TrackingRectangle.Height = aFloatSize.Height(); 3613cdf0e10cSrcweir aDockingData.TrackingRectangle.Width = aFloatSize.Width(); 3614cdf0e10cSrcweir } 3615cdf0e10cSrcweir else 3616cdf0e10cSrcweir { 3617cdf0e10cSrcweir aFloatSize = pToolBox->CalcWindowSizePixel(); 3618cdf0e10cSrcweir if ( !bIsHorizontal ) 3619cdf0e10cSrcweir { 3620cdf0e10cSrcweir // Floating toolbars are always horizontal aligned! We have to swap 3621cdf0e10cSrcweir // width/height if we have a vertical aligned toolbar. 3622cdf0e10cSrcweir sal_Int32 nTemp = aFloatSize.Height(); 3623cdf0e10cSrcweir aFloatSize.Height() = aFloatSize.Width(); 3624cdf0e10cSrcweir aFloatSize.Width() = nTemp; 3625cdf0e10cSrcweir } 3626cdf0e10cSrcweir 3627cdf0e10cSrcweir aDockingData.TrackingRectangle.Height = aFloatSize.Height(); 3628cdf0e10cSrcweir aDockingData.TrackingRectangle.Width = aFloatSize.Width(); 3629cdf0e10cSrcweir 3630cdf0e10cSrcweir // For the first time we don't have any data about the floating size of a toolbar. 3631cdf0e10cSrcweir // We calculate it and store it for later use. 3632cdf0e10cSrcweir aUIDockingElement.m_aFloatingData.m_aPos = pContainerWindow->ScreenToOutputPixel(::Point( e.MousePos.X, e.MousePos.Y )); 3633cdf0e10cSrcweir aUIDockingElement.m_aFloatingData.m_aSize = aFloatSize; 3634cdf0e10cSrcweir aUIDockingElement.m_aFloatingData.m_nLines = pToolBox->GetFloatingLines(); 3635cdf0e10cSrcweir aUIDockingElement.m_aFloatingData.m_bIsHorizontal = isToolboxHorizontalAligned( pToolBox ); 3636cdf0e10cSrcweir } 3637cdf0e10cSrcweir aDockingData.TrackingRectangle.X = e.MousePos.X; 3638cdf0e10cSrcweir aDockingData.TrackingRectangle.Y = e.MousePos.Y; 3639cdf0e10cSrcweir } 3640cdf0e10cSrcweir 3641cdf0e10cSrcweir aDockingData.bFloating = ( eDockingArea == -1 ); 3642cdf0e10cSrcweir 3643cdf0e10cSrcweir // Write current data to the member docking progress data 3644cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 3645cdf0e10cSrcweir m_aDockUIElement.m_bFloating = aDockingData.bFloating; 3646cdf0e10cSrcweir if ( !aDockingData.bFloating ) 3647cdf0e10cSrcweir { 3648cdf0e10cSrcweir m_aDockUIElement.m_aDockedData = aUIDockingElement.m_aDockedData; 3649cdf0e10cSrcweir m_eDockOperation = eDockingOperation; 3650cdf0e10cSrcweir } 3651cdf0e10cSrcweir else 3652cdf0e10cSrcweir m_aDockUIElement.m_aFloatingData = aUIDockingElement.m_aFloatingData; 3653cdf0e10cSrcweir aWriteLock.unlock(); 3654cdf0e10cSrcweir } 3655cdf0e10cSrcweir catch ( uno::Exception& ) {} 3656cdf0e10cSrcweir } 3657cdf0e10cSrcweir 3658cdf0e10cSrcweir return aDockingData; 3659cdf0e10cSrcweir } 3660cdf0e10cSrcweir 3661cdf0e10cSrcweir void SAL_CALL ToolbarLayoutManager::endDocking( const awt::EndDockingEvent& e ) 3662cdf0e10cSrcweir throw (uno::RuntimeException) 3663cdf0e10cSrcweir { 3664cdf0e10cSrcweir bool bDockingInProgress( false ); 3665cdf0e10cSrcweir bool bStartDockFloated( false ); 3666cdf0e10cSrcweir bool bFloating( false ); 3667cdf0e10cSrcweir UIElement aUIDockingElement; 3668cdf0e10cSrcweir 3669cdf0e10cSrcweir /* SAFE AREA ----------------------------------------------------------------------------------------------- */ 3670cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 3671cdf0e10cSrcweir bDockingInProgress = m_bDockingInProgress; 3672cdf0e10cSrcweir aUIDockingElement = m_aDockUIElement; 3673cdf0e10cSrcweir bFloating = aUIDockingElement.m_bFloating; 3674cdf0e10cSrcweir 3675cdf0e10cSrcweir UIElement& rUIElement = impl_findToolbar( aUIDockingElement.m_aName ); 3676cdf0e10cSrcweir if ( rUIElement.m_aName == aUIDockingElement.m_aName ) 3677cdf0e10cSrcweir { 3678cdf0e10cSrcweir if ( aUIDockingElement.m_bFloating ) 3679cdf0e10cSrcweir { 3680cdf0e10cSrcweir // Write last position into position data 3681cdf0e10cSrcweir uno::Reference< awt::XWindow > xWindow( aUIDockingElement.m_xUIElement->getRealInterface(), uno::UNO_QUERY ); 3682cdf0e10cSrcweir rUIElement.m_aFloatingData = aUIDockingElement.m_aFloatingData; 3683cdf0e10cSrcweir awt::Rectangle aTmpRect = xWindow->getPosSize(); 3684cdf0e10cSrcweir rUIElement.m_aFloatingData.m_aPos = ::Point( aTmpRect.X, aTmpRect.Y ); 3685cdf0e10cSrcweir // make changes also for our local data as we use it to make data persistent 3686cdf0e10cSrcweir aUIDockingElement.m_aFloatingData = rUIElement.m_aFloatingData; 3687cdf0e10cSrcweir } 3688cdf0e10cSrcweir else 3689cdf0e10cSrcweir { 3690cdf0e10cSrcweir rUIElement.m_aDockedData = aUIDockingElement.m_aDockedData; 3691cdf0e10cSrcweir rUIElement.m_aFloatingData.m_aSize = aUIDockingElement.m_aFloatingData.m_aSize; 3692cdf0e10cSrcweir 3693cdf0e10cSrcweir if ( m_eDockOperation != DOCKOP_ON_COLROW ) 3694cdf0e10cSrcweir { 3695cdf0e10cSrcweir // we have to renumber our row/column data to insert a new row/column 3696cdf0e10cSrcweir implts_renumberRowColumnData((ui::DockingArea)aUIDockingElement.m_aDockedData.m_nDockedArea, m_eDockOperation, aUIDockingElement ); 3697cdf0e10cSrcweir } 3698cdf0e10cSrcweir } 3699cdf0e10cSrcweir 3700cdf0e10cSrcweir bStartDockFloated = rUIElement.m_bFloating; 3701cdf0e10cSrcweir rUIElement.m_bFloating = m_aDockUIElement.m_bFloating; 3702cdf0e10cSrcweir rUIElement.m_bUserActive = true; 3703cdf0e10cSrcweir } 3704cdf0e10cSrcweir 3705cdf0e10cSrcweir // reset member for next docking operation 3706cdf0e10cSrcweir m_aDockUIElement.m_xUIElement.clear(); 3707cdf0e10cSrcweir m_eDockOperation = DOCKOP_ON_COLROW; 3708cdf0e10cSrcweir aWriteLock.unlock(); 3709cdf0e10cSrcweir /* SAFE AREA ----------------------------------------------------------------------------------------------- */ 3710cdf0e10cSrcweir 3711cdf0e10cSrcweir implts_writeWindowStateData( aUIDockingElement ); 3712cdf0e10cSrcweir 3713cdf0e10cSrcweir if ( bDockingInProgress ) 3714cdf0e10cSrcweir { 3715cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 3716cdf0e10cSrcweir Window* pWindow = VCLUnoHelper::GetWindow( uno::Reference< awt::XWindow >( e.Source, uno::UNO_QUERY )); 3717cdf0e10cSrcweir ToolBox* pToolBox = 0; 3718cdf0e10cSrcweir if ( pWindow && pWindow->GetType() == WINDOW_TOOLBOX ) 3719cdf0e10cSrcweir pToolBox = (ToolBox *)pWindow; 3720cdf0e10cSrcweir 3721cdf0e10cSrcweir if ( pToolBox ) 3722cdf0e10cSrcweir { 3723cdf0e10cSrcweir if( e.bFloating ) 3724cdf0e10cSrcweir { 3725cdf0e10cSrcweir if ( aUIDockingElement.m_aFloatingData.m_bIsHorizontal ) 3726cdf0e10cSrcweir pToolBox->SetAlign( WINDOWALIGN_TOP ); 3727cdf0e10cSrcweir else 3728cdf0e10cSrcweir pToolBox->SetAlign( WINDOWALIGN_LEFT ); 3729cdf0e10cSrcweir } 3730cdf0e10cSrcweir else 3731cdf0e10cSrcweir { 3732cdf0e10cSrcweir ::Size aSize; 3733cdf0e10cSrcweir 3734cdf0e10cSrcweir pToolBox->SetAlign( ImplConvertAlignment( aUIDockingElement.m_aDockedData.m_nDockedArea) ); 3735cdf0e10cSrcweir 3736cdf0e10cSrcweir // Docked toolbars have always one line 3737cdf0e10cSrcweir aSize = pToolBox->CalcWindowSizePixel( 1 ); 3738cdf0e10cSrcweir 3739cdf0e10cSrcweir // Lock layouting updates as our listener would be called due to SetSizePixel 3740cdf0e10cSrcweir pToolBox->SetOutputSizePixel( aSize ); 3741cdf0e10cSrcweir } 3742cdf0e10cSrcweir } 3743cdf0e10cSrcweir } 3744cdf0e10cSrcweir 3745cdf0e10cSrcweir implts_sortUIElements(); 3746cdf0e10cSrcweir 3747cdf0e10cSrcweir aWriteLock.lock(); 3748cdf0e10cSrcweir m_bDockingInProgress = sal_False; 3749cdf0e10cSrcweir m_bLayoutDirty = !bStartDockFloated || !bFloating; 3750cdf0e10cSrcweir bool bNotify = m_bLayoutDirty; 3751cdf0e10cSrcweir aWriteLock.unlock(); 3752cdf0e10cSrcweir 3753cdf0e10cSrcweir if ( bNotify ) 3754cdf0e10cSrcweir m_pParentLayouter->requestLayout( ILayoutNotifications::HINT_TOOLBARSPACE_HAS_CHANGED ); 3755cdf0e10cSrcweir } 3756cdf0e10cSrcweir 3757cdf0e10cSrcweir sal_Bool SAL_CALL ToolbarLayoutManager::prepareToggleFloatingMode( const lang::EventObject& e ) 3758cdf0e10cSrcweir throw (uno::RuntimeException) 3759cdf0e10cSrcweir { 3760cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 3761cdf0e10cSrcweir bool bDockingInProgress = m_bDockingInProgress; 3762cdf0e10cSrcweir aReadLock.unlock(); 3763cdf0e10cSrcweir 3764cdf0e10cSrcweir UIElement aUIDockingElement = implts_findToolbar( e.Source ); 3765cdf0e10cSrcweir bool bWinFound( aUIDockingElement.m_aName.getLength() > 0 ); 3766cdf0e10cSrcweir uno::Reference< awt::XWindow > xWindow( e.Source, uno::UNO_QUERY ); 3767cdf0e10cSrcweir 3768cdf0e10cSrcweir if ( bWinFound && xWindow.is() ) 3769cdf0e10cSrcweir { 3770cdf0e10cSrcweir if ( !bDockingInProgress ) 3771cdf0e10cSrcweir { 3772cdf0e10cSrcweir awt::Rectangle aRect; 3773cdf0e10cSrcweir uno::Reference< awt::XDockableWindow > xDockWindow( xWindow, uno::UNO_QUERY ); 3774cdf0e10cSrcweir if ( xDockWindow->isFloating() ) 3775cdf0e10cSrcweir { 3776cdf0e10cSrcweir { 3777cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 3778cdf0e10cSrcweir Window* pWindow = VCLUnoHelper::GetWindow( xWindow ); 3779cdf0e10cSrcweir if ( pWindow && pWindow->GetType() == WINDOW_TOOLBOX ) 3780cdf0e10cSrcweir { 3781cdf0e10cSrcweir ToolBox* pToolBox = static_cast< ToolBox *>( pWindow ); 3782cdf0e10cSrcweir aUIDockingElement.m_aFloatingData.m_aPos = pToolBox->GetPosPixel(); 3783cdf0e10cSrcweir aUIDockingElement.m_aFloatingData.m_aSize = pToolBox->GetOutputSizePixel(); 3784cdf0e10cSrcweir aUIDockingElement.m_aFloatingData.m_nLines = pToolBox->GetFloatingLines(); 3785cdf0e10cSrcweir aUIDockingElement.m_aFloatingData.m_bIsHorizontal = isToolboxHorizontalAligned( pToolBox ); 3786cdf0e10cSrcweir } 3787cdf0e10cSrcweir } 3788cdf0e10cSrcweir 3789cdf0e10cSrcweir UIElement aUIElement = implts_findToolbar( aUIDockingElement.m_aName ); 3790cdf0e10cSrcweir if ( aUIElement.m_aName == aUIDockingElement.m_aName ) 3791cdf0e10cSrcweir implts_setToolbar( aUIDockingElement ); 3792cdf0e10cSrcweir } 3793cdf0e10cSrcweir } 3794cdf0e10cSrcweir } 3795cdf0e10cSrcweir 3796cdf0e10cSrcweir return sal_True; 3797cdf0e10cSrcweir } 3798cdf0e10cSrcweir 3799cdf0e10cSrcweir void SAL_CALL ToolbarLayoutManager::toggleFloatingMode( const lang::EventObject& e ) 3800cdf0e10cSrcweir throw (uno::RuntimeException) 3801cdf0e10cSrcweir { 3802cdf0e10cSrcweir UIElement aUIDockingElement; 3803cdf0e10cSrcweir 3804cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 3805cdf0e10cSrcweir bool bDockingInProgress( m_bDockingInProgress ); 3806cdf0e10cSrcweir if ( bDockingInProgress ) 3807cdf0e10cSrcweir aUIDockingElement = m_aDockUIElement; 3808cdf0e10cSrcweir aReadLock.unlock(); 3809cdf0e10cSrcweir 3810cdf0e10cSrcweir Window* pWindow( 0 ); 3811cdf0e10cSrcweir ToolBox* pToolBox( 0 ); 3812cdf0e10cSrcweir uno::Reference< awt::XWindow2 > xWindow; 3813cdf0e10cSrcweir 3814cdf0e10cSrcweir { 3815cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 3816cdf0e10cSrcweir xWindow = uno::Reference< awt::XWindow2 >( e.Source, uno::UNO_QUERY ); 3817cdf0e10cSrcweir pWindow = VCLUnoHelper::GetWindow( xWindow ); 3818cdf0e10cSrcweir 3819cdf0e10cSrcweir if ( pWindow && pWindow->GetType() == WINDOW_TOOLBOX ) 3820cdf0e10cSrcweir pToolBox = (ToolBox *)pWindow; 3821cdf0e10cSrcweir } 3822cdf0e10cSrcweir 3823cdf0e10cSrcweir if ( !bDockingInProgress ) 3824cdf0e10cSrcweir { 3825cdf0e10cSrcweir aUIDockingElement = implts_findToolbar( e.Source ); 3826cdf0e10cSrcweir bool bWinFound = ( aUIDockingElement.m_aName.getLength() > 0 ); 3827cdf0e10cSrcweir 3828cdf0e10cSrcweir if ( bWinFound && xWindow.is() ) 3829cdf0e10cSrcweir { 3830cdf0e10cSrcweir aUIDockingElement.m_bFloating = !aUIDockingElement.m_bFloating; 3831cdf0e10cSrcweir aUIDockingElement.m_bUserActive = true; 3832cdf0e10cSrcweir 3833cdf0e10cSrcweir implts_setLayoutInProgress( true ); 3834cdf0e10cSrcweir if ( aUIDockingElement.m_bFloating ) 3835cdf0e10cSrcweir { 3836cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 3837cdf0e10cSrcweir if ( pToolBox ) 3838cdf0e10cSrcweir { 3839cdf0e10cSrcweir pToolBox->SetLineCount( aUIDockingElement.m_aFloatingData.m_nLines ); 3840cdf0e10cSrcweir if ( aUIDockingElement.m_aFloatingData.m_bIsHorizontal ) 3841cdf0e10cSrcweir pToolBox->SetAlign( WINDOWALIGN_TOP ); 3842cdf0e10cSrcweir else 3843cdf0e10cSrcweir pToolBox->SetAlign( WINDOWALIGN_LEFT ); 3844cdf0e10cSrcweir } 3845cdf0e10cSrcweir 3846cdf0e10cSrcweir bool bUndefPos = hasDefaultPosValue( aUIDockingElement.m_aFloatingData.m_aPos ); 3847cdf0e10cSrcweir bool bSetSize = !hasEmptySize( aUIDockingElement.m_aFloatingData.m_aSize ); 3848cdf0e10cSrcweir 3849cdf0e10cSrcweir if ( bUndefPos ) 3850cdf0e10cSrcweir aUIDockingElement.m_aFloatingData.m_aPos = implts_findNextCascadeFloatingPos(); 3851cdf0e10cSrcweir 3852cdf0e10cSrcweir if ( !bSetSize ) 3853cdf0e10cSrcweir { 3854cdf0e10cSrcweir if ( pToolBox ) 3855cdf0e10cSrcweir aUIDockingElement.m_aFloatingData.m_aSize = pToolBox->CalcFloatingWindowSizePixel(); 3856cdf0e10cSrcweir else 3857cdf0e10cSrcweir aUIDockingElement.m_aFloatingData.m_aSize = pWindow->GetOutputSizePixel(); 3858cdf0e10cSrcweir } 3859cdf0e10cSrcweir 3860cdf0e10cSrcweir xWindow->setPosSize( aUIDockingElement.m_aFloatingData.m_aPos.X(), 3861cdf0e10cSrcweir aUIDockingElement.m_aFloatingData.m_aPos.Y(), 3862cdf0e10cSrcweir 0, 0, awt::PosSize::POS ); 3863cdf0e10cSrcweir xWindow->setOutputSize( AWTSize( aUIDockingElement.m_aFloatingData.m_aSize ) ); 3864cdf0e10cSrcweir } 3865cdf0e10cSrcweir else 3866cdf0e10cSrcweir { 3867cdf0e10cSrcweir if ( isDefaultPos( aUIDockingElement.m_aDockedData.m_aPos )) 3868cdf0e10cSrcweir { 3869cdf0e10cSrcweir // Docking on its default position without a preset position - 3870cdf0e10cSrcweir // we have to find a good place for it. 3871cdf0e10cSrcweir ::Point aPixelPos; 3872cdf0e10cSrcweir ::Point aDockPos; 3873cdf0e10cSrcweir ::Size aSize; 3874cdf0e10cSrcweir 3875cdf0e10cSrcweir { 3876cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 3877cdf0e10cSrcweir if ( pToolBox ) 3878cdf0e10cSrcweir aSize = pToolBox->CalcWindowSizePixel( 1, ImplConvertAlignment( aUIDockingElement.m_aDockedData.m_nDockedArea ) ); 3879cdf0e10cSrcweir else 3880cdf0e10cSrcweir aSize = pWindow->GetSizePixel(); 3881cdf0e10cSrcweir } 3882cdf0e10cSrcweir 3883cdf0e10cSrcweir implts_findNextDockingPos((ui::DockingArea)aUIDockingElement.m_aDockedData.m_nDockedArea, aSize, aDockPos, aPixelPos ); 3884cdf0e10cSrcweir aUIDockingElement.m_aDockedData.m_aPos = aDockPos; 3885cdf0e10cSrcweir } 3886cdf0e10cSrcweir 3887cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 3888cdf0e10cSrcweir if ( pToolBox ) 3889cdf0e10cSrcweir { 3890cdf0e10cSrcweir pToolBox->SetAlign( ImplConvertAlignment( aUIDockingElement.m_aDockedData.m_nDockedArea) ); 3891cdf0e10cSrcweir ::Size aSize = pToolBox->CalcWindowSizePixel( 1 ); 3892cdf0e10cSrcweir awt::Rectangle aRect = xWindow->getPosSize(); 3893cdf0e10cSrcweir xWindow->setPosSize( aRect.X, aRect.Y, 0, 0, awt::PosSize::POS ); 3894cdf0e10cSrcweir xWindow->setOutputSize( AWTSize( aSize ) ); 3895cdf0e10cSrcweir } 3896cdf0e10cSrcweir } 3897cdf0e10cSrcweir 3898cdf0e10cSrcweir implts_setLayoutInProgress( false ); 3899cdf0e10cSrcweir implts_setToolbar( aUIDockingElement ); 3900cdf0e10cSrcweir implts_writeWindowStateData( aUIDockingElement ); 3901cdf0e10cSrcweir implts_sortUIElements(); 3902cdf0e10cSrcweir implts_setLayoutDirty(); 3903cdf0e10cSrcweir 3904cdf0e10cSrcweir aReadLock.lock(); 3905cdf0e10cSrcweir ILayoutNotifications* pParentLayouter( m_pParentLayouter ); 3906cdf0e10cSrcweir aReadLock.unlock(); 3907cdf0e10cSrcweir 3908cdf0e10cSrcweir if ( pParentLayouter ) 3909cdf0e10cSrcweir pParentLayouter->requestLayout( ILayoutNotifications::HINT_TOOLBARSPACE_HAS_CHANGED ); 3910cdf0e10cSrcweir } 3911cdf0e10cSrcweir } 3912cdf0e10cSrcweir else 3913cdf0e10cSrcweir { 3914cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 3915cdf0e10cSrcweir if ( pToolBox ) 3916cdf0e10cSrcweir { 3917cdf0e10cSrcweir if ( aUIDockingElement.m_bFloating ) 3918cdf0e10cSrcweir { 3919cdf0e10cSrcweir if ( aUIDockingElement.m_aFloatingData.m_bIsHorizontal ) 3920cdf0e10cSrcweir pToolBox->SetAlign( WINDOWALIGN_TOP ); 3921cdf0e10cSrcweir else 3922cdf0e10cSrcweir pToolBox->SetAlign( WINDOWALIGN_LEFT ); 3923cdf0e10cSrcweir } 3924cdf0e10cSrcweir else 3925cdf0e10cSrcweir pToolBox->SetAlign( ImplConvertAlignment( aUIDockingElement.m_aDockedData.m_nDockedArea) ); 3926cdf0e10cSrcweir } 3927cdf0e10cSrcweir } 3928cdf0e10cSrcweir } 3929cdf0e10cSrcweir 3930cdf0e10cSrcweir void SAL_CALL ToolbarLayoutManager::closed( const lang::EventObject& e ) 3931cdf0e10cSrcweir throw (uno::RuntimeException) 3932cdf0e10cSrcweir { 3933cdf0e10cSrcweir rtl::OUString aName; 3934cdf0e10cSrcweir UIElement aUIElement; 3935cdf0e10cSrcweir UIElementVector::iterator pIter; 3936cdf0e10cSrcweir 3937cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 3938cdf0e10cSrcweir for ( pIter = m_aUIElements.begin(); pIter != m_aUIElements.end(); pIter++ ) 3939cdf0e10cSrcweir { 3940cdf0e10cSrcweir uno::Reference< ui::XUIElement > xUIElement( pIter->m_xUIElement ); 3941cdf0e10cSrcweir if ( xUIElement.is() ) 3942cdf0e10cSrcweir { 3943cdf0e10cSrcweir uno::Reference< uno::XInterface > xIfac( xUIElement->getRealInterface(), uno::UNO_QUERY ); 3944cdf0e10cSrcweir if ( xIfac == e.Source ) 3945cdf0e10cSrcweir { 3946cdf0e10cSrcweir aName = pIter->m_aName; 3947cdf0e10cSrcweir 3948cdf0e10cSrcweir // user closes a toolbar => 3949cdf0e10cSrcweir // context sensitive toolbar: only destroy toolbar and store state. 3950cdf0e10cSrcweir // context sensitive toolbar: make it invisible, store state and destroy it. 3951cdf0e10cSrcweir if ( !pIter->m_bContextSensitive ) 3952cdf0e10cSrcweir pIter->m_bVisible = sal_False; 3953cdf0e10cSrcweir 3954cdf0e10cSrcweir aUIElement = *pIter; 3955cdf0e10cSrcweir break; 3956cdf0e10cSrcweir } 3957cdf0e10cSrcweir } 3958cdf0e10cSrcweir } 3959cdf0e10cSrcweir aWriteLock.unlock(); 3960cdf0e10cSrcweir 3961cdf0e10cSrcweir // destroy element 3962cdf0e10cSrcweir if ( aName.getLength() > 0 ) 3963cdf0e10cSrcweir { 3964cdf0e10cSrcweir implts_writeWindowStateData( aUIElement ); 3965cdf0e10cSrcweir destroyToolbar( aName ); 3966cdf0e10cSrcweir } 3967cdf0e10cSrcweir } 3968cdf0e10cSrcweir 3969cdf0e10cSrcweir void SAL_CALL ToolbarLayoutManager::endPopupMode( const awt::EndPopupModeEvent& /*e*/ ) 3970cdf0e10cSrcweir throw (uno::RuntimeException) 3971cdf0e10cSrcweir { 3972cdf0e10cSrcweir } 3973cdf0e10cSrcweir 3974cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 3975cdf0e10cSrcweir // XUIConfigurationListener 3976cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 3977cdf0e10cSrcweir void SAL_CALL ToolbarLayoutManager::elementInserted( const ui::ConfigurationEvent& rEvent ) 3978cdf0e10cSrcweir throw (uno::RuntimeException) 3979cdf0e10cSrcweir { 3980cdf0e10cSrcweir UIElement aUIElement = implts_findToolbar( rEvent.ResourceURL ); 3981cdf0e10cSrcweir 3982cdf0e10cSrcweir uno::Reference< ui::XUIElementSettings > xElementSettings( aUIElement.m_xUIElement, uno::UNO_QUERY ); 3983cdf0e10cSrcweir if ( xElementSettings.is() ) 3984cdf0e10cSrcweir { 3985cdf0e10cSrcweir ::rtl::OUString aConfigSourcePropName( RTL_CONSTASCII_USTRINGPARAM( "ConfigurationSource" )); 3986cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xPropSet( xElementSettings, uno::UNO_QUERY ); 3987cdf0e10cSrcweir if ( xPropSet.is() ) 3988cdf0e10cSrcweir { 3989cdf0e10cSrcweir if ( rEvent.Source == uno::Reference< uno::XInterface >( m_xDocCfgMgr, uno::UNO_QUERY )) 3990cdf0e10cSrcweir xPropSet->setPropertyValue( aConfigSourcePropName, makeAny( m_xDocCfgMgr )); 3991cdf0e10cSrcweir } 3992cdf0e10cSrcweir xElementSettings->updateSettings(); 3993cdf0e10cSrcweir } 3994cdf0e10cSrcweir else 3995cdf0e10cSrcweir { 3996cdf0e10cSrcweir ::rtl::OUString aElementType; 3997cdf0e10cSrcweir ::rtl::OUString aElementName; 3998cdf0e10cSrcweir parseResourceURL( rEvent.ResourceURL, aElementType, aElementName ); 3999cdf0e10cSrcweir if ( aElementName.indexOf( m_aCustomTbxPrefix ) != -1 ) 4000cdf0e10cSrcweir { 4001cdf0e10cSrcweir // custom toolbar must be directly created, shown and layouted! 4002cdf0e10cSrcweir createToolbar( rEvent.ResourceURL ); 4003cdf0e10cSrcweir uno::Reference< ui::XUIElement > xUIElement = getToolbar( rEvent.ResourceURL ); 4004cdf0e10cSrcweir if ( xUIElement.is() ) 4005cdf0e10cSrcweir { 4006cdf0e10cSrcweir ::rtl::OUString aUIName; 4007cdf0e10cSrcweir uno::Reference< ui::XUIConfigurationManager > xCfgMgr; 4008cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xPropSet; 4009cdf0e10cSrcweir 4010cdf0e10cSrcweir try 4011cdf0e10cSrcweir { 4012cdf0e10cSrcweir xCfgMgr = uno::Reference< ui::XUIConfigurationManager >( rEvent.Source, uno::UNO_QUERY ); 4013cdf0e10cSrcweir xPropSet = uno::Reference< beans::XPropertySet >( xCfgMgr->getSettings( rEvent.ResourceURL, sal_False ), uno::UNO_QUERY ); 4014cdf0e10cSrcweir 4015cdf0e10cSrcweir if ( xPropSet.is() ) 4016cdf0e10cSrcweir xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UIName" ))) >>= aUIName; 4017cdf0e10cSrcweir } 4018cdf0e10cSrcweir catch ( container::NoSuchElementException& ) {} 4019cdf0e10cSrcweir catch ( beans::UnknownPropertyException& ) {} 4020cdf0e10cSrcweir catch ( lang::WrappedTargetException& ) {} 4021cdf0e10cSrcweir 4022cdf0e10cSrcweir { 4023cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 4024cdf0e10cSrcweir Window* pWindow = getWindowFromXUIElement( xUIElement ); 4025cdf0e10cSrcweir if ( pWindow ) 4026cdf0e10cSrcweir pWindow->SetText( aUIName ); 4027cdf0e10cSrcweir } 4028cdf0e10cSrcweir 4029cdf0e10cSrcweir showToolbar( rEvent.ResourceURL ); 4030cdf0e10cSrcweir } 4031cdf0e10cSrcweir } 4032cdf0e10cSrcweir } 4033cdf0e10cSrcweir } 4034cdf0e10cSrcweir 4035cdf0e10cSrcweir void SAL_CALL ToolbarLayoutManager::elementRemoved( const ui::ConfigurationEvent& rEvent ) 4036cdf0e10cSrcweir throw (uno::RuntimeException) 4037cdf0e10cSrcweir { 4038cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 4039cdf0e10cSrcweir uno::Reference< awt::XWindow > xContainerWindow( m_xContainerWindow, uno::UNO_QUERY ); 4040cdf0e10cSrcweir uno::Reference< ui::XUIConfigurationManager > xModuleCfgMgr( m_xModuleCfgMgr ); 4041cdf0e10cSrcweir uno::Reference< ui::XUIConfigurationManager > xDocCfgMgr( m_xDocCfgMgr ); 4042cdf0e10cSrcweir aReadLock.unlock(); 4043cdf0e10cSrcweir 4044cdf0e10cSrcweir UIElement aUIElement = implts_findToolbar( rEvent.ResourceURL ); 4045cdf0e10cSrcweir uno::Reference< ui::XUIElementSettings > xElementSettings( aUIElement.m_xUIElement, uno::UNO_QUERY ); 4046cdf0e10cSrcweir if ( xElementSettings.is() ) 4047cdf0e10cSrcweir { 4048cdf0e10cSrcweir bool bNoSettings( false ); 4049cdf0e10cSrcweir ::rtl::OUString aConfigSourcePropName( RTL_CONSTASCII_USTRINGPARAM( "ConfigurationSource" )); 4050cdf0e10cSrcweir uno::Reference< uno::XInterface > xElementCfgMgr; 4051cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xPropSet( xElementSettings, uno::UNO_QUERY ); 4052cdf0e10cSrcweir 4053cdf0e10cSrcweir if ( xPropSet.is() ) 4054cdf0e10cSrcweir xPropSet->getPropertyValue( aConfigSourcePropName ) >>= xElementCfgMgr; 4055cdf0e10cSrcweir 4056cdf0e10cSrcweir if ( !xElementCfgMgr.is() ) 4057cdf0e10cSrcweir return; 4058cdf0e10cSrcweir 4059cdf0e10cSrcweir // Check if the same UI configuration manager has changed => check further 4060cdf0e10cSrcweir if ( rEvent.Source == xElementCfgMgr ) 4061cdf0e10cSrcweir { 4062cdf0e10cSrcweir // Same UI configuration manager where our element has its settings 4063cdf0e10cSrcweir if ( rEvent.Source == uno::Reference< uno::XInterface >( xDocCfgMgr, uno::UNO_QUERY )) 4064cdf0e10cSrcweir { 4065cdf0e10cSrcweir // document settings removed 4066cdf0e10cSrcweir if ( xModuleCfgMgr->hasSettings( rEvent.ResourceURL )) 4067cdf0e10cSrcweir { 4068cdf0e10cSrcweir xPropSet->setPropertyValue( aConfigSourcePropName, makeAny( xModuleCfgMgr )); 4069cdf0e10cSrcweir xElementSettings->updateSettings(); 4070cdf0e10cSrcweir return; 4071cdf0e10cSrcweir } 4072cdf0e10cSrcweir } 4073cdf0e10cSrcweir 4074cdf0e10cSrcweir bNoSettings = true; 4075cdf0e10cSrcweir } 4076cdf0e10cSrcweir 4077cdf0e10cSrcweir // No settings anymore, element must be destroyed 4078cdf0e10cSrcweir if ( xContainerWindow.is() && bNoSettings ) 4079cdf0e10cSrcweir destroyToolbar( rEvent.ResourceURL ); 4080cdf0e10cSrcweir } 4081cdf0e10cSrcweir } 4082cdf0e10cSrcweir 4083cdf0e10cSrcweir void SAL_CALL ToolbarLayoutManager::elementReplaced( const ui::ConfigurationEvent& rEvent ) 4084cdf0e10cSrcweir throw (uno::RuntimeException) 4085cdf0e10cSrcweir { 4086cdf0e10cSrcweir UIElement aUIElement = implts_findToolbar( rEvent.ResourceURL ); 4087cdf0e10cSrcweir 4088cdf0e10cSrcweir uno::Reference< ui::XUIElementSettings > xElementSettings( aUIElement.m_xUIElement, uno::UNO_QUERY ); 4089cdf0e10cSrcweir if ( xElementSettings.is() ) 4090cdf0e10cSrcweir { 4091cdf0e10cSrcweir ::rtl::OUString aConfigSourcePropName( RTL_CONSTASCII_USTRINGPARAM( "ConfigurationSource" )); 4092cdf0e10cSrcweir uno::Reference< uno::XInterface > xElementCfgMgr; 4093cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xPropSet( xElementSettings, uno::UNO_QUERY ); 4094cdf0e10cSrcweir 4095cdf0e10cSrcweir if ( xPropSet.is() ) 4096cdf0e10cSrcweir xPropSet->getPropertyValue( aConfigSourcePropName ) >>= xElementCfgMgr; 4097cdf0e10cSrcweir 4098cdf0e10cSrcweir if ( !xElementCfgMgr.is() ) 4099cdf0e10cSrcweir return; 4100cdf0e10cSrcweir 4101cdf0e10cSrcweir // Check if the same UI configuration manager has changed => update settings 4102cdf0e10cSrcweir if ( rEvent.Source == xElementCfgMgr ) 4103cdf0e10cSrcweir { 4104cdf0e10cSrcweir xElementSettings->updateSettings(); 4105cdf0e10cSrcweir 4106cdf0e10cSrcweir WriteGuard aWriteLock( m_aLock ); 4107cdf0e10cSrcweir bool bNotify = !aUIElement.m_bFloating; 4108cdf0e10cSrcweir m_bLayoutDirty = bNotify; 4109cdf0e10cSrcweir ILayoutNotifications* pParentLayouter( m_pParentLayouter ); 4110cdf0e10cSrcweir aWriteLock.unlock(); 4111cdf0e10cSrcweir 4112cdf0e10cSrcweir if ( bNotify && pParentLayouter ) 4113cdf0e10cSrcweir pParentLayouter->requestLayout( ILayoutNotifications::HINT_TOOLBARSPACE_HAS_CHANGED ); 4114cdf0e10cSrcweir } 4115cdf0e10cSrcweir } 4116cdf0e10cSrcweir } 4117cdf0e10cSrcweir 4118cdf0e10cSrcweir uno::Reference< ui::XUIElement > ToolbarLayoutManager::getToolbar( const ::rtl::OUString& aName ) 4119cdf0e10cSrcweir { 4120cdf0e10cSrcweir return implts_findToolbar( aName ).m_xUIElement; 4121cdf0e10cSrcweir } 4122cdf0e10cSrcweir 4123cdf0e10cSrcweir uno::Sequence< uno::Reference< ui::XUIElement > > ToolbarLayoutManager::getToolbars() 4124cdf0e10cSrcweir { 4125cdf0e10cSrcweir uno::Sequence< uno::Reference< ui::XUIElement > > aSeq; 4126cdf0e10cSrcweir 4127cdf0e10cSrcweir ReadGuard aReadLock( m_aLock ); 4128cdf0e10cSrcweir if ( m_aUIElements.size() > 0 ) 4129cdf0e10cSrcweir { 4130cdf0e10cSrcweir sal_uInt32 nCount(0); 4131cdf0e10cSrcweir UIElementVector::iterator pIter; 4132cdf0e10cSrcweir for ( pIter = m_aUIElements.begin(); pIter != m_aUIElements.end(); pIter++ ) 4133cdf0e10cSrcweir { 4134cdf0e10cSrcweir if ( pIter->m_xUIElement.is() ) 4135cdf0e10cSrcweir { 4136cdf0e10cSrcweir ++nCount; 4137cdf0e10cSrcweir aSeq.realloc( nCount ); 4138cdf0e10cSrcweir aSeq[nCount-1] = pIter->m_xUIElement; 4139cdf0e10cSrcweir } 4140cdf0e10cSrcweir } 4141cdf0e10cSrcweir } 4142cdf0e10cSrcweir 4143cdf0e10cSrcweir return aSeq; 4144cdf0e10cSrcweir } 4145cdf0e10cSrcweir 4146cdf0e10cSrcweir bool ToolbarLayoutManager::floatToolbar( const ::rtl::OUString& rResourceURL ) 4147cdf0e10cSrcweir { 4148cdf0e10cSrcweir UIElement aUIElement = implts_findToolbar( rResourceURL ); 4149cdf0e10cSrcweir if ( aUIElement.m_xUIElement.is() ) 4150cdf0e10cSrcweir { 4151cdf0e10cSrcweir try 4152cdf0e10cSrcweir { 4153cdf0e10cSrcweir uno::Reference< awt::XDockableWindow > xDockWindow( aUIElement.m_xUIElement->getRealInterface(), uno::UNO_QUERY ); 4154cdf0e10cSrcweir if ( xDockWindow.is() && !xDockWindow->isFloating() ) 4155cdf0e10cSrcweir { 4156cdf0e10cSrcweir aUIElement.m_bFloating = true; 4157cdf0e10cSrcweir implts_writeWindowStateData( aUIElement ); 4158cdf0e10cSrcweir xDockWindow->setFloatingMode( true ); 4159cdf0e10cSrcweir 4160cdf0e10cSrcweir implts_setLayoutDirty(); 4161cdf0e10cSrcweir implts_setToolbar( aUIElement ); 4162cdf0e10cSrcweir return true; 4163cdf0e10cSrcweir } 4164cdf0e10cSrcweir } 4165cdf0e10cSrcweir catch ( lang::DisposedException& ) {} 4166cdf0e10cSrcweir } 4167cdf0e10cSrcweir 4168cdf0e10cSrcweir return false; 4169cdf0e10cSrcweir } 4170cdf0e10cSrcweir 4171cdf0e10cSrcweir bool ToolbarLayoutManager::lockToolbar( const ::rtl::OUString& rResourceURL ) 4172cdf0e10cSrcweir { 4173cdf0e10cSrcweir UIElement aUIElement = implts_findToolbar( rResourceURL ); 4174cdf0e10cSrcweir if ( aUIElement.m_xUIElement.is() ) 4175cdf0e10cSrcweir { 4176cdf0e10cSrcweir try 4177cdf0e10cSrcweir { 4178cdf0e10cSrcweir uno::Reference< awt::XDockableWindow > xDockWindow( aUIElement.m_xUIElement->getRealInterface(), uno::UNO_QUERY ); 4179cdf0e10cSrcweir if ( xDockWindow.is() && !xDockWindow->isFloating() && !xDockWindow->isLocked() ) 4180cdf0e10cSrcweir { 4181cdf0e10cSrcweir aUIElement.m_aDockedData.m_bLocked = true; 4182cdf0e10cSrcweir implts_writeWindowStateData( aUIElement ); 4183cdf0e10cSrcweir xDockWindow->lock(); 4184cdf0e10cSrcweir 4185cdf0e10cSrcweir implts_setLayoutDirty(); 4186cdf0e10cSrcweir implts_setToolbar( aUIElement ); 4187cdf0e10cSrcweir return true; 4188cdf0e10cSrcweir } 4189cdf0e10cSrcweir } 4190cdf0e10cSrcweir catch ( lang::DisposedException& ) {} 4191cdf0e10cSrcweir } 4192cdf0e10cSrcweir 4193cdf0e10cSrcweir return false; 4194cdf0e10cSrcweir } 4195cdf0e10cSrcweir 4196cdf0e10cSrcweir bool ToolbarLayoutManager::unlockToolbar( const ::rtl::OUString& rResourceURL ) 4197cdf0e10cSrcweir { 4198cdf0e10cSrcweir UIElement aUIElement = implts_findToolbar( rResourceURL ); 4199cdf0e10cSrcweir if ( aUIElement.m_xUIElement.is() ) 4200cdf0e10cSrcweir { 4201cdf0e10cSrcweir try 4202cdf0e10cSrcweir { 4203cdf0e10cSrcweir uno::Reference< awt::XDockableWindow > xDockWindow( aUIElement.m_xUIElement->getRealInterface(), uno::UNO_QUERY ); 4204cdf0e10cSrcweir if ( xDockWindow.is() && !xDockWindow->isFloating() && xDockWindow->isLocked() ) 4205cdf0e10cSrcweir { 4206cdf0e10cSrcweir aUIElement.m_aDockedData.m_bLocked = false; 4207cdf0e10cSrcweir implts_writeWindowStateData( aUIElement ); 4208cdf0e10cSrcweir xDockWindow->unlock(); 4209cdf0e10cSrcweir 4210cdf0e10cSrcweir implts_setLayoutDirty(); 4211cdf0e10cSrcweir implts_setToolbar( aUIElement ); 4212cdf0e10cSrcweir return true; 4213cdf0e10cSrcweir } 4214cdf0e10cSrcweir } 4215cdf0e10cSrcweir catch ( lang::DisposedException& ) {} 4216cdf0e10cSrcweir } 4217cdf0e10cSrcweir 4218cdf0e10cSrcweir return false; 4219cdf0e10cSrcweir } 4220cdf0e10cSrcweir 4221cdf0e10cSrcweir bool ToolbarLayoutManager::isToolbarVisible( const ::rtl::OUString& rResourceURL ) 4222cdf0e10cSrcweir { 4223cdf0e10cSrcweir uno::Reference< awt::XWindow2 > xWindow2( implts_getXWindow( rResourceURL ), uno::UNO_QUERY ); 4224cdf0e10cSrcweir return ( xWindow2.is() && xWindow2->isVisible() ); 4225cdf0e10cSrcweir } 4226cdf0e10cSrcweir 4227cdf0e10cSrcweir bool ToolbarLayoutManager::isToolbarFloating( const ::rtl::OUString& rResourceURL ) 4228cdf0e10cSrcweir { 4229cdf0e10cSrcweir uno::Reference< awt::XDockableWindow > xDockWindow( implts_getXWindow( rResourceURL ), uno::UNO_QUERY ); 4230cdf0e10cSrcweir return ( xDockWindow.is() && xDockWindow->isFloating() ); 4231cdf0e10cSrcweir } 4232cdf0e10cSrcweir 4233cdf0e10cSrcweir bool ToolbarLayoutManager::isToolbarDocked( const ::rtl::OUString& rResourceURL ) 4234cdf0e10cSrcweir { 4235cdf0e10cSrcweir return !isToolbarFloating( rResourceURL ); 4236cdf0e10cSrcweir } 4237cdf0e10cSrcweir 4238cdf0e10cSrcweir bool ToolbarLayoutManager::isToolbarLocked( const ::rtl::OUString& rResourceURL ) 4239cdf0e10cSrcweir { 4240cdf0e10cSrcweir uno::Reference< awt::XDockableWindow > xDockWindow( implts_getXWindow( rResourceURL ), uno::UNO_QUERY ); 4241cdf0e10cSrcweir return ( xDockWindow.is() && xDockWindow->isLocked() ); 4242cdf0e10cSrcweir } 4243cdf0e10cSrcweir 4244cdf0e10cSrcweir awt::Size ToolbarLayoutManager::getToolbarSize( const ::rtl::OUString& rResourceURL ) 4245cdf0e10cSrcweir { 4246cdf0e10cSrcweir Window* pWindow = implts_getWindow( rResourceURL ); 4247cdf0e10cSrcweir 4248cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 4249cdf0e10cSrcweir if ( pWindow ) 4250cdf0e10cSrcweir { 4251cdf0e10cSrcweir ::Size aSize = pWindow->GetSizePixel(); 4252cdf0e10cSrcweir awt::Size aWinSize; 4253cdf0e10cSrcweir aWinSize.Width = aSize.Width(); 4254cdf0e10cSrcweir aWinSize.Height = aSize.Height(); 4255cdf0e10cSrcweir return aWinSize; 4256cdf0e10cSrcweir } 4257cdf0e10cSrcweir 4258cdf0e10cSrcweir return awt::Size(); 4259cdf0e10cSrcweir } 4260cdf0e10cSrcweir 4261cdf0e10cSrcweir awt::Point ToolbarLayoutManager::getToolbarPos( const ::rtl::OUString& rResourceURL ) 4262cdf0e10cSrcweir { 4263cdf0e10cSrcweir awt::Point aPos; 4264cdf0e10cSrcweir UIElement aUIElement = implts_findToolbar( rResourceURL ); 4265cdf0e10cSrcweir 4266cdf0e10cSrcweir uno::Reference< awt::XWindow > xWindow( implts_getXWindow( rResourceURL )); 4267cdf0e10cSrcweir if ( xWindow.is() ) 4268cdf0e10cSrcweir { 4269cdf0e10cSrcweir if ( aUIElement.m_bFloating ) 4270cdf0e10cSrcweir { 4271cdf0e10cSrcweir awt::Rectangle aRect = xWindow->getPosSize(); 4272cdf0e10cSrcweir aPos.X = aRect.X; 4273cdf0e10cSrcweir aPos.Y = aRect.Y; 4274cdf0e10cSrcweir } 4275cdf0e10cSrcweir else 4276cdf0e10cSrcweir { 4277cdf0e10cSrcweir ::Point aVirtualPos = aUIElement.m_aDockedData.m_aPos; 4278cdf0e10cSrcweir aPos.X = aVirtualPos.X(); 4279cdf0e10cSrcweir aPos.Y = aVirtualPos.Y(); 4280cdf0e10cSrcweir } 4281cdf0e10cSrcweir } 4282cdf0e10cSrcweir 4283cdf0e10cSrcweir return aPos; 4284cdf0e10cSrcweir } 4285cdf0e10cSrcweir 4286cdf0e10cSrcweir void ToolbarLayoutManager::setToolbarSize( const ::rtl::OUString& rResourceURL, const awt::Size& aSize ) 4287cdf0e10cSrcweir { 4288cdf0e10cSrcweir uno::Reference< awt::XWindow2 > xWindow( implts_getXWindow( rResourceURL ), uno::UNO_QUERY ); 4289cdf0e10cSrcweir uno::Reference< awt::XDockableWindow > xDockWindow( xWindow, uno::UNO_QUERY ); 4290cdf0e10cSrcweir UIElement aUIElement = implts_findToolbar( rResourceURL ); 4291cdf0e10cSrcweir 4292cdf0e10cSrcweir if ( xWindow.is() && xDockWindow.is() && xDockWindow->isFloating() ) 4293cdf0e10cSrcweir { 4294cdf0e10cSrcweir xWindow->setOutputSize( aSize ); 4295cdf0e10cSrcweir aUIElement.m_aFloatingData.m_aSize = ::Size( aSize.Width, aSize.Height ); 4296cdf0e10cSrcweir implts_setToolbar( aUIElement ); 4297cdf0e10cSrcweir implts_writeWindowStateData( aUIElement ); 4298cdf0e10cSrcweir implts_sortUIElements(); 4299cdf0e10cSrcweir } 4300cdf0e10cSrcweir } 4301cdf0e10cSrcweir 4302cdf0e10cSrcweir void ToolbarLayoutManager::setToolbarPos( const ::rtl::OUString& rResourceURL, const awt::Point& aPos ) 4303cdf0e10cSrcweir { 4304cdf0e10cSrcweir uno::Reference< awt::XWindow > xWindow( implts_getXWindow( rResourceURL )); 4305cdf0e10cSrcweir uno::Reference< awt::XDockableWindow > xDockWindow( xWindow, uno::UNO_QUERY ); 4306cdf0e10cSrcweir UIElement aUIElement = implts_findToolbar( rResourceURL ); 4307cdf0e10cSrcweir 4308cdf0e10cSrcweir if ( xWindow.is() && xDockWindow.is() && xDockWindow->isFloating() ) 4309cdf0e10cSrcweir { 4310cdf0e10cSrcweir xWindow->setPosSize( aPos.X, aPos.Y, 0, 0, awt::PosSize::POS ); 4311cdf0e10cSrcweir aUIElement.m_aFloatingData.m_aPos = ::Point( aPos.X, aPos.Y ); 4312cdf0e10cSrcweir implts_setToolbar( aUIElement ); 4313cdf0e10cSrcweir implts_writeWindowStateData( aUIElement ); 4314cdf0e10cSrcweir implts_sortUIElements(); 4315cdf0e10cSrcweir } 4316cdf0e10cSrcweir } 4317cdf0e10cSrcweir 4318cdf0e10cSrcweir void ToolbarLayoutManager::setToolbarPosSize( const ::rtl::OUString& rResourceURL, const awt::Point& aPos, const awt::Size& aSize ) 4319cdf0e10cSrcweir { 4320cdf0e10cSrcweir setToolbarPos( rResourceURL, aPos ); 4321cdf0e10cSrcweir setToolbarSize( rResourceURL, aSize ); 4322cdf0e10cSrcweir } 4323cdf0e10cSrcweir 4324cdf0e10cSrcweir } // namespace framework 4325