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