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