16d739b60SAndrew Rist /**************************************************************
26d739b60SAndrew Rist  *
36d739b60SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
46d739b60SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
56d739b60SAndrew Rist  * distributed with this work for additional information
66d739b60SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
76d739b60SAndrew Rist  * to you under the Apache License, Version 2.0 (the
86d739b60SAndrew Rist  * "License"); you may not use this file except in compliance
96d739b60SAndrew Rist  * with the License.  You may obtain a copy of the License at
106d739b60SAndrew Rist  *
116d739b60SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
126d739b60SAndrew Rist  *
136d739b60SAndrew Rist  * Unless required by applicable law or agreed to in writing,
146d739b60SAndrew Rist  * software distributed under the License is distributed on an
156d739b60SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
166d739b60SAndrew Rist  * KIND, either express or implied.  See the License for the
176d739b60SAndrew Rist  * specific language governing permissions and limitations
186d739b60SAndrew Rist  * under the License.
196d739b60SAndrew Rist  *
206d739b60SAndrew Rist  *************************************************************/
216d739b60SAndrew Rist 
226d739b60SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_framework.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // my own includes
28cdf0e10cSrcweir #include <toolbarlayoutmanager.hxx>
29cdf0e10cSrcweir #include <helpers.hxx>
30cdf0e10cSrcweir #include <services.h>
31cdf0e10cSrcweir #include <classes/resource.hrc>
32cdf0e10cSrcweir #include <classes/fwkresid.hxx>
33cdf0e10cSrcweir #include <uiconfiguration/windowstateconfiguration.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir // interface includes
36cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp>
37cdf0e10cSrcweir #include <com/sun/star/ui/UIElementType.hpp>
38cdf0e10cSrcweir #include <com/sun/star/container/XNameReplace.hpp>
39cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
40cdf0e10cSrcweir #include <com/sun/star/ui/XUIElementSettings.hpp>
41cdf0e10cSrcweir #include <com/sun/star/ui/XUIFunctionListener.hpp>
42cdf0e10cSrcweir 
43cdf0e10cSrcweir // other includes
44cdf0e10cSrcweir #include <unotools/cmdoptions.hxx>
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 
100726169348SAriel Constenla-Haile                 ::rtl::OUString aAddonUIName = m_pAddonOptions->GetAddonsToolbarUIName( i );
1008*bb0b5665SAriel Constenla-Haile                 const bool bAddonUIName = aAddonUIName.getLength();
1009*bb0b5665SAriel Constenla-Haile                 ::rtl::OUString aAddonTitle = bAddonUIName ?
101026169348SAriel Constenla-Haile                     aAddonUIName : implts_generateGenericAddonToolbarTitle( i+1 );
1011cdf0e10cSrcweir 
1012cdf0e10cSrcweir                 if ( aElement.m_aName.getLength() > 0 )
1013cdf0e10cSrcweir                 {
1014cdf0e10cSrcweir                     // Reuse a local entry so we are able to use the latest
1015cdf0e10cSrcweir                     // UI changes for this document.
1016cdf0e10cSrcweir                     implts_setElementData( aElement, xDockWindow );
1017cdf0e10cSrcweir                     aElement.m_xUIElement = xUIElement;
1018*bb0b5665SAriel Constenla-Haile                     if ( aElement.m_aUIName.getLength() == 0 && !bAddonUIName)
1019cdf0e10cSrcweir                     {
102026169348SAriel Constenla-Haile                         aElement.m_aUIName = aAddonTitle;
1021cdf0e10cSrcweir                         implts_writeWindowStateData( aElement );
1022cdf0e10cSrcweir                     }
1023cdf0e10cSrcweir                 }
1024cdf0e10cSrcweir                 else
1025cdf0e10cSrcweir                 {
1026cdf0e10cSrcweir                     // Create new UI element and try to read its state data
1027cdf0e10cSrcweir                     UIElement aNewToolbar( aAddonToolBarName, aElementType, xUIElement );
1028cdf0e10cSrcweir                     aNewToolbar.m_bFloating = true;
1029cdf0e10cSrcweir                     implts_readWindowStateData( aAddonToolBarName, aNewToolbar );
1030cdf0e10cSrcweir                     implts_setElementData( aNewToolbar, xDockWindow );
1031*bb0b5665SAriel Constenla-Haile                     if ( aNewToolbar.m_aUIName.getLength() == 0 && !bAddonUIName)
1032cdf0e10cSrcweir                     {
103326169348SAriel Constenla-Haile                         aNewToolbar.m_aUIName = aAddonTitle;
1034cdf0e10cSrcweir                         implts_writeWindowStateData( aNewToolbar );
1035cdf0e10cSrcweir                     }
1036cdf0e10cSrcweir                     implts_insertToolbar( aNewToolbar );
1037cdf0e10cSrcweir                 }
1038cdf0e10cSrcweir 
1039cdf0e10cSrcweir                 uno::Reference< awt::XWindow > xWindow( xDockWindow, uno::UNO_QUERY );
1040cdf0e10cSrcweir                 if ( xWindow.is() )
1041cdf0e10cSrcweir                 {
1042cdf0e10cSrcweir                     // Set generic title for add-on toolbar
1043cdf0e10cSrcweir                     vos::OGuard aGuard( Application::GetSolarMutex() );
1044cdf0e10cSrcweir                     Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
1045cdf0e10cSrcweir                     if ( pWindow->GetText().Len() == 0 )
104626169348SAriel Constenla-Haile                         pWindow->SetText( aAddonTitle );
1047cdf0e10cSrcweir                     if ( pWindow->GetType() == WINDOW_TOOLBOX )
1048cdf0e10cSrcweir                     {
1049cdf0e10cSrcweir                         ToolBox* pToolbar = (ToolBox *)pWindow;
1050cdf0e10cSrcweir                         pToolbar->SetMenuType();
1051cdf0e10cSrcweir                     }
1052cdf0e10cSrcweir                 }
1053cdf0e10cSrcweir             }
1054cdf0e10cSrcweir         }
1055cdf0e10cSrcweir         catch ( container::NoSuchElementException& ) {}
1056cdf0e10cSrcweir         catch ( lang::IllegalArgumentException& ) {}
1057cdf0e10cSrcweir     }
1058cdf0e10cSrcweir }
1059cdf0e10cSrcweir 
1060cdf0e10cSrcweir void ToolbarLayoutManager::implts_createCustomToolBars()
1061cdf0e10cSrcweir {
1062cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
1063cdf0e10cSrcweir     if ( !m_bComponentAttached )
1064cdf0e10cSrcweir         return;
1065cdf0e10cSrcweir 
1066cdf0e10cSrcweir     uno::Reference< ui::XUIElementFactory > xUIElementFactory( m_xUIElementFactoryManager );
1067cdf0e10cSrcweir     uno::Reference< frame::XFrame > xFrame( m_xFrame );
1068cdf0e10cSrcweir     uno::Reference< frame::XModel > xModel;
1069cdf0e10cSrcweir     uno::Reference< ui::XUIConfigurationManager > xModuleCfgMgr( m_xModuleCfgMgr, uno::UNO_QUERY );
1070cdf0e10cSrcweir     uno::Reference< ui::XUIConfigurationManager > xDocCfgMgr( m_xDocCfgMgr, uno::UNO_QUERY );
1071cdf0e10cSrcweir     aReadLock.unlock();
1072cdf0e10cSrcweir 
1073cdf0e10cSrcweir     if ( xFrame.is() )
1074cdf0e10cSrcweir     {
1075cdf0e10cSrcweir         xModel = impl_getModelFromFrame( xFrame );
1076cdf0e10cSrcweir         if ( implts_isPreviewModel( xModel ))
1077cdf0e10cSrcweir             return; // no custom toolbars for preview frame!
1078cdf0e10cSrcweir 
1079cdf0e10cSrcweir         uno::Sequence< uno::Sequence< beans::PropertyValue > > aTbxSeq;
1080cdf0e10cSrcweir         if ( xDocCfgMgr.is() )
1081cdf0e10cSrcweir         {
1082cdf0e10cSrcweir             aTbxSeq = xDocCfgMgr->getUIElementsInfo( ui::UIElementType::TOOLBAR );
1083cdf0e10cSrcweir             implts_createCustomToolBars( aTbxSeq ); // first create all document based toolbars
1084cdf0e10cSrcweir         }
1085cdf0e10cSrcweir         if ( xModuleCfgMgr.is() )
1086cdf0e10cSrcweir         {
1087cdf0e10cSrcweir             aTbxSeq = xModuleCfgMgr->getUIElementsInfo( ui::UIElementType::TOOLBAR );
1088cdf0e10cSrcweir             implts_createCustomToolBars( aTbxSeq ); // second create module based toolbars
1089cdf0e10cSrcweir         }
1090cdf0e10cSrcweir     }
1091cdf0e10cSrcweir }
1092cdf0e10cSrcweir 
1093cdf0e10cSrcweir void ToolbarLayoutManager::implts_createNonContextSensitiveToolBars()
1094cdf0e10cSrcweir {
1095cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
1096cdf0e10cSrcweir 
1097cdf0e10cSrcweir     if ( !m_xPersistentWindowState.is() || !m_xFrame.is() || !m_bComponentAttached )
1098cdf0e10cSrcweir         return;
1099cdf0e10cSrcweir 
1100cdf0e10cSrcweir     uno::Reference< frame::XFrame >          xFrame( m_xFrame );
1101cdf0e10cSrcweir     uno::Reference< ui::XUIElementFactory >  xUIElementFactory( m_xUIElementFactoryManager );
1102cdf0e10cSrcweir     uno::Reference< container::XNameAccess > xPersistentWindowState( m_xPersistentWindowState );
1103cdf0e10cSrcweir     aReadLock.unlock();
1104cdf0e10cSrcweir 
1105cdf0e10cSrcweir     if ( implts_isPreviewModel( impl_getModelFromFrame( xFrame )))
1106cdf0e10cSrcweir         return;
1107cdf0e10cSrcweir 
1108cdf0e10cSrcweir     std::vector< rtl::OUString > aMakeVisibleToolbars;
1109cdf0e10cSrcweir 
1110cdf0e10cSrcweir     try
1111cdf0e10cSrcweir     {
1112cdf0e10cSrcweir         uno::Sequence< ::rtl::OUString > aToolbarNames = xPersistentWindowState->getElementNames();
1113cdf0e10cSrcweir 
1114cdf0e10cSrcweir         if ( aToolbarNames.getLength() > 0 )
1115cdf0e10cSrcweir         {
1116cdf0e10cSrcweir             ::rtl::OUString aElementType;
1117cdf0e10cSrcweir             ::rtl::OUString aElementName;
1118cdf0e10cSrcweir             ::rtl::OUString aName;
1119cdf0e10cSrcweir 
1120cdf0e10cSrcweir             uno::Reference< ui::XUIElement > xUIElement;
1121cdf0e10cSrcweir             aMakeVisibleToolbars.reserve(aToolbarNames.getLength());
1122cdf0e10cSrcweir 
1123cdf0e10cSrcweir             /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1124cdf0e10cSrcweir             WriteGuard aWriteLock( m_aLock );
1125cdf0e10cSrcweir 
1126cdf0e10cSrcweir             const rtl::OUString* pTbNames = aToolbarNames.getConstArray();
1127cdf0e10cSrcweir             for ( sal_Int32 i = 0; i < aToolbarNames.getLength(); i++ )
1128cdf0e10cSrcweir             {
1129cdf0e10cSrcweir                 aName = pTbNames[i];
1130cdf0e10cSrcweir                 parseResourceURL( aName, aElementType, aElementName );
1131cdf0e10cSrcweir 
1132cdf0e10cSrcweir                 // Check that we only create:
1133cdf0e10cSrcweir                 // - Toolbars (the statusbar is also member of the persistent window state)
1134cdf0e10cSrcweir                 // - Not custom toolbars, there are created with their own method (implts_createCustomToolbars)
1135cdf0e10cSrcweir                 if ( aElementType.equalsIgnoreAsciiCaseAscii( "toolbar" ) && aElementName.indexOf( m_aCustomTbxPrefix ) == -1 )
1136cdf0e10cSrcweir                 {
1137cdf0e10cSrcweir                     UIElement aNewToolbar = implts_findToolbar( aName );
1138cdf0e10cSrcweir                     bool bFound = ( aNewToolbar.m_aName == aName );
1139cdf0e10cSrcweir                     if ( !bFound )
1140cdf0e10cSrcweir                         implts_readWindowStateData( aName, aNewToolbar );
1141cdf0e10cSrcweir 
1142cdf0e10cSrcweir                     if ( aNewToolbar.m_bVisible && !aNewToolbar.m_bContextSensitive )
1143cdf0e10cSrcweir                     {
1144cdf0e10cSrcweir                         if ( !bFound )
1145cdf0e10cSrcweir                             implts_insertToolbar( aNewToolbar );
1146cdf0e10cSrcweir                         aMakeVisibleToolbars.push_back( aName );
1147cdf0e10cSrcweir                     }
1148cdf0e10cSrcweir                 }
1149cdf0e10cSrcweir             }
1150cdf0e10cSrcweir             /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1151cdf0e10cSrcweir         }
1152cdf0e10cSrcweir     }
1153cdf0e10cSrcweir     catch ( uno::RuntimeException& ) { throw; }
1154cdf0e10cSrcweir     catch ( uno::Exception& ) {}
1155cdf0e10cSrcweir 
1156cdf0e10cSrcweir     if ( !aMakeVisibleToolbars.empty() )
1157cdf0e10cSrcweir         ::std::for_each( aMakeVisibleToolbars.begin(), aMakeVisibleToolbars.end(),::boost::bind( &ToolbarLayoutManager::requestToolbar, this,_1 ));
1158cdf0e10cSrcweir }
1159cdf0e10cSrcweir 
1160cdf0e10cSrcweir void ToolbarLayoutManager::implts_createCustomToolBars( const uno::Sequence< uno::Sequence< beans::PropertyValue > >& aTbxSeqSeq )
1161cdf0e10cSrcweir {
1162cdf0e10cSrcweir     const uno::Sequence< beans::PropertyValue >* pTbxSeq = aTbxSeqSeq.getConstArray();
1163cdf0e10cSrcweir     for ( sal_Int32 i = 0; i < aTbxSeqSeq.getLength(); i++ )
1164cdf0e10cSrcweir     {
1165cdf0e10cSrcweir         const uno::Sequence< beans::PropertyValue >& rTbxSeq = pTbxSeq[i];
1166cdf0e10cSrcweir         ::rtl::OUString aTbxResName;
1167cdf0e10cSrcweir         ::rtl::OUString aTbxTitle;
1168cdf0e10cSrcweir         for ( sal_Int32 j = 0; j < rTbxSeq.getLength(); j++ )
1169cdf0e10cSrcweir         {
1170cdf0e10cSrcweir             if ( rTbxSeq[j].Name.equalsAscii( "ResourceURL" ))
1171cdf0e10cSrcweir                 rTbxSeq[j].Value >>= aTbxResName;
1172cdf0e10cSrcweir             else if ( rTbxSeq[j].Name.equalsAscii( "UIName" ))
1173cdf0e10cSrcweir                 rTbxSeq[j].Value >>= aTbxTitle;
1174cdf0e10cSrcweir         }
1175cdf0e10cSrcweir 
1176cdf0e10cSrcweir         // Only create custom toolbars. Their name have to start with "custom_"!
1177cdf0e10cSrcweir         if ( aTbxResName.getLength() > 0 && aTbxResName.indexOf( m_aCustomTbxPrefix ) != -1 )
1178cdf0e10cSrcweir             implts_createCustomToolBar( aTbxResName, aTbxTitle );
1179cdf0e10cSrcweir     }
1180cdf0e10cSrcweir }
1181cdf0e10cSrcweir 
1182cdf0e10cSrcweir void ToolbarLayoutManager::implts_createCustomToolBar( const rtl::OUString& aTbxResName, const rtl::OUString& aTitle )
1183cdf0e10cSrcweir {
1184cdf0e10cSrcweir     if ( aTbxResName.getLength() > 0 )
1185cdf0e10cSrcweir     {
1186cdf0e10cSrcweir         bool bNotify( false );
1187cdf0e10cSrcweir         uno::Reference< ui::XUIElement > xUIElement;
1188cdf0e10cSrcweir         implts_createToolBar( aTbxResName, bNotify, xUIElement );
1189cdf0e10cSrcweir 
1190cdf0e10cSrcweir         if ( aTitle && xUIElement.is() )
1191cdf0e10cSrcweir         {
1192cdf0e10cSrcweir             vos::OGuard aGuard( Application::GetSolarMutex() );
1193cdf0e10cSrcweir 
1194cdf0e10cSrcweir             Window* pWindow = getWindowFromXUIElement( xUIElement );
1195cdf0e10cSrcweir             if ( pWindow  )
1196cdf0e10cSrcweir                 pWindow->SetText( aTitle );
1197cdf0e10cSrcweir         }
1198cdf0e10cSrcweir     }
1199cdf0e10cSrcweir }
1200cdf0e10cSrcweir 
1201cdf0e10cSrcweir void ToolbarLayoutManager::implts_reparentToolbars()
1202cdf0e10cSrcweir {
1203cdf0e10cSrcweir     WriteGuard aWriteLock( m_aLock );
1204cdf0e10cSrcweir     UIElementVector aUIElementVector = m_aUIElements;
1205cdf0e10cSrcweir     Window* pContainerWindow  = VCLUnoHelper::GetWindow( m_xContainerWindow );
1206cdf0e10cSrcweir     Window* pTopDockWindow    = VCLUnoHelper::GetWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_TOP] );
1207cdf0e10cSrcweir     Window* pBottomDockWindow = VCLUnoHelper::GetWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_BOTTOM] );
1208cdf0e10cSrcweir     Window* pLeftDockWindow   = VCLUnoHelper::GetWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_LEFT] );
1209cdf0e10cSrcweir     Window* pRightDockWindow  = VCLUnoHelper::GetWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_RIGHT] );
1210cdf0e10cSrcweir     aWriteLock.unlock();
1211cdf0e10cSrcweir 
1212cdf0e10cSrcweir     vos::OGuard aGuard( Application::GetSolarMutex() );
1213cdf0e10cSrcweir     if ( pContainerWindow )
1214cdf0e10cSrcweir     {
1215cdf0e10cSrcweir         UIElementVector::iterator pIter;
1216cdf0e10cSrcweir         for ( pIter = aUIElementVector.begin(); pIter != aUIElementVector.end(); pIter++ )
1217cdf0e10cSrcweir         {
1218cdf0e10cSrcweir             uno::Reference< ui::XUIElement > xUIElement( pIter->m_xUIElement );
1219cdf0e10cSrcweir             if ( xUIElement.is() )
1220cdf0e10cSrcweir             {
1221cdf0e10cSrcweir                 uno::Reference< awt::XWindow > xWindow;
1222cdf0e10cSrcweir                 try
1223cdf0e10cSrcweir                 {
1224cdf0e10cSrcweir                     // We have to retreive the window reference with try/catch as it is
1225cdf0e10cSrcweir                     // possible that all elements have been disposed!
1226cdf0e10cSrcweir                     xWindow = uno::Reference< awt::XWindow >( xUIElement->getRealInterface(), uno::UNO_QUERY );
1227cdf0e10cSrcweir                 }
1228cdf0e10cSrcweir                 catch ( uno::RuntimeException& ) { throw; }
1229cdf0e10cSrcweir                 catch ( uno::Exception& ) {}
1230cdf0e10cSrcweir 
1231cdf0e10cSrcweir                 Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
1232cdf0e10cSrcweir                 if ( pWindow )
1233cdf0e10cSrcweir                 {
1234cdf0e10cSrcweir                     // Reparent our child windows acording to their current state.
1235cdf0e10cSrcweir                     if ( pIter->m_bFloating )
1236cdf0e10cSrcweir                         pWindow->SetParent( pContainerWindow );
1237cdf0e10cSrcweir                     else
1238cdf0e10cSrcweir                     {
1239cdf0e10cSrcweir                         if ( pIter->m_aDockedData.m_nDockedArea == ui::DockingArea_DOCKINGAREA_TOP )
1240cdf0e10cSrcweir                             pWindow->SetParent( pTopDockWindow );
1241cdf0e10cSrcweir                         else if ( pIter->m_aDockedData.m_nDockedArea == ui::DockingArea_DOCKINGAREA_BOTTOM )
1242cdf0e10cSrcweir                             pWindow->SetParent( pBottomDockWindow );
1243cdf0e10cSrcweir                         else if ( pIter->m_aDockedData.m_nDockedArea == ui::DockingArea_DOCKINGAREA_LEFT )
1244cdf0e10cSrcweir                             pWindow->SetParent( pLeftDockWindow );
1245cdf0e10cSrcweir                         else
1246cdf0e10cSrcweir                             pWindow->SetParent( pRightDockWindow );
1247cdf0e10cSrcweir                     }
1248cdf0e10cSrcweir                 }
1249cdf0e10cSrcweir             }
1250cdf0e10cSrcweir         }
1251cdf0e10cSrcweir     }
1252cdf0e10cSrcweir }
1253cdf0e10cSrcweir 
1254cdf0e10cSrcweir void ToolbarLayoutManager::implts_setToolbarCreation( bool bStart )
1255cdf0e10cSrcweir {
1256cdf0e10cSrcweir     WriteGuard aWriteLock( m_aLock );
1257cdf0e10cSrcweir     m_bToolbarCreation = bStart;
1258cdf0e10cSrcweir }
1259cdf0e10cSrcweir 
1260cdf0e10cSrcweir bool ToolbarLayoutManager::implts_isToolbarCreationActive()
1261cdf0e10cSrcweir {
1262cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
1263cdf0e10cSrcweir     return m_bToolbarCreation;
1264cdf0e10cSrcweir }
1265cdf0e10cSrcweir 
1266cdf0e10cSrcweir void ToolbarLayoutManager::implts_createToolBar( const ::rtl::OUString& aName, bool& bNotify, uno::Reference< ui::XUIElement >& rUIElement )
1267cdf0e10cSrcweir {
1268cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
1269cdf0e10cSrcweir     uno::Reference< frame::XFrame > xFrame( m_xFrame );
1270cdf0e10cSrcweir     uno::Reference< awt::XWindow2 > xContainerWindow( m_xContainerWindow );
1271cdf0e10cSrcweir     aReadLock.unlock();
1272cdf0e10cSrcweir 
1273cdf0e10cSrcweir     bNotify = false;
1274cdf0e10cSrcweir 
1275cdf0e10cSrcweir     if ( !xFrame.is() || !xContainerWindow.is() )
1276cdf0e10cSrcweir         return;
1277cdf0e10cSrcweir 
1278cdf0e10cSrcweir     UIElement aToolbarElement = implts_findToolbar( aName );
1279cdf0e10cSrcweir     if ( !aToolbarElement.m_xUIElement.is()  )
1280cdf0e10cSrcweir     {
1281cdf0e10cSrcweir         uno::Reference< ui::XUIElement > xUIElement = implts_createElement( aName );
1282cdf0e10cSrcweir 
1283cdf0e10cSrcweir         bool bVisible( false );
1284cdf0e10cSrcweir         bool bFloating( false );
1285cdf0e10cSrcweir         if ( xUIElement.is() )
1286cdf0e10cSrcweir         {
1287cdf0e10cSrcweir             rUIElement = xUIElement;
1288cdf0e10cSrcweir 
1289cdf0e10cSrcweir             uno::Reference< awt::XWindow > xWindow( xUIElement->getRealInterface(), uno::UNO_QUERY );
1290cdf0e10cSrcweir             uno::Reference< awt::XDockableWindow > xDockWindow( xWindow, uno::UNO_QUERY );
1291cdf0e10cSrcweir             if ( xDockWindow.is() && xWindow.is() )
1292cdf0e10cSrcweir             {
1293cdf0e10cSrcweir                 try
1294cdf0e10cSrcweir                 {
1295cdf0e10cSrcweir                     xDockWindow->addDockableWindowListener( uno::Reference< awt::XDockableWindowListener >(
1296cdf0e10cSrcweir                         static_cast< OWeakObject * >( this ), uno::UNO_QUERY ));
1297cdf0e10cSrcweir                     xWindow->addWindowListener( uno::Reference< awt::XWindowListener >(
1298cdf0e10cSrcweir                         static_cast< OWeakObject * >( this ), uno::UNO_QUERY ));
1299cdf0e10cSrcweir                     xDockWindow->enableDocking( sal_True );
1300cdf0e10cSrcweir                 }
1301cdf0e10cSrcweir                 catch ( uno::Exception& ) {}
1302cdf0e10cSrcweir             }
1303cdf0e10cSrcweir 
1304cdf0e10cSrcweir             /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1305cdf0e10cSrcweir             WriteGuard aWriteLock( m_aLock );
1306cdf0e10cSrcweir 
1307cdf0e10cSrcweir             UIElement& rElement = impl_findToolbar( aName );
1308cdf0e10cSrcweir             if ( rElement.m_aName.getLength() > 0 )
1309cdf0e10cSrcweir             {
1310cdf0e10cSrcweir                 // Reuse a local entry so we are able to use the latest
1311cdf0e10cSrcweir                 // UI changes for this document.
1312cdf0e10cSrcweir                 implts_setElementData( rElement, xDockWindow );
1313cdf0e10cSrcweir                 rElement.m_xUIElement = xUIElement;
1314cdf0e10cSrcweir                 bVisible = rElement.m_bVisible;
1315cdf0e10cSrcweir                 bFloating = rElement.m_bFloating;
1316cdf0e10cSrcweir             }
1317cdf0e10cSrcweir             else
1318cdf0e10cSrcweir             {
1319cdf0e10cSrcweir                 // Create new UI element and try to read its state data
1320cdf0e10cSrcweir                 UIElement aNewToolbar( aName, m_aToolbarTypeString, xUIElement );
1321cdf0e10cSrcweir                 implts_readWindowStateData( aName, aNewToolbar );
1322cdf0e10cSrcweir                 implts_setElementData( aNewToolbar, xDockWindow );
1323cdf0e10cSrcweir                 implts_insertToolbar( aNewToolbar );
1324cdf0e10cSrcweir                 bVisible = aNewToolbar.m_bVisible;
1325cdf0e10cSrcweir                 bFloating = rElement.m_bFloating;
1326cdf0e10cSrcweir             }
1327cdf0e10cSrcweir             aWriteLock.unlock();
1328cdf0e10cSrcweir             /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1329cdf0e10cSrcweir 
1330cdf0e10cSrcweir             // set toolbar menu style according to customize command state
1331cdf0e10cSrcweir             SvtCommandOptions aCmdOptions;
1332cdf0e10cSrcweir 
1333cdf0e10cSrcweir             vos::OGuard aGuard( Application::GetSolarMutex() );
1334cdf0e10cSrcweir             Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
1335cdf0e10cSrcweir             if ( pWindow && pWindow->GetType() == WINDOW_TOOLBOX )
1336cdf0e10cSrcweir             {
1337cdf0e10cSrcweir                 ToolBox* pToolbar = (ToolBox *)pWindow;
1338cdf0e10cSrcweir                 sal_uInt16 nMenuType = pToolbar->GetMenuType();
1339cdf0e10cSrcweir                 if ( aCmdOptions.Lookup( SvtCommandOptions::CMDOPTION_DISABLED, m_aCustomizeCmd ))
1340cdf0e10cSrcweir                     pToolbar->SetMenuType( nMenuType & ~TOOLBOX_MENUTYPE_CUSTOMIZE );
1341cdf0e10cSrcweir                 else
1342cdf0e10cSrcweir                     pToolbar->SetMenuType( nMenuType | TOOLBOX_MENUTYPE_CUSTOMIZE );
1343cdf0e10cSrcweir             }
1344cdf0e10cSrcweir             bNotify = true;
1345cdf0e10cSrcweir 
1346cdf0e10cSrcweir             implts_sortUIElements();
1347cdf0e10cSrcweir 
1348cdf0e10cSrcweir             if ( bVisible && !bFloating )
1349cdf0e10cSrcweir                 implts_setLayoutDirty();
1350cdf0e10cSrcweir         }
1351cdf0e10cSrcweir     }
1352cdf0e10cSrcweir }
1353cdf0e10cSrcweir 
1354cdf0e10cSrcweir uno::Reference< ui::XUIElement > ToolbarLayoutManager::implts_createElement( const ::rtl::OUString& aName )
1355cdf0e10cSrcweir {
1356cdf0e10cSrcweir     uno::Reference< ui::XUIElement > xUIElement;
1357cdf0e10cSrcweir 
1358cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
1359cdf0e10cSrcweir     uno::Sequence< beans::PropertyValue > aPropSeq( 2 );
1360cdf0e10cSrcweir     aPropSeq[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
1361cdf0e10cSrcweir     aPropSeq[0].Value <<= m_xFrame;
1362cdf0e10cSrcweir     aPropSeq[1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Persistent" ));
1363cdf0e10cSrcweir     aPropSeq[1].Value <<= true;
1364cdf0e10cSrcweir     uno::Reference< ui::XUIElementFactory > xUIElementFactory( m_xUIElementFactoryManager );
1365cdf0e10cSrcweir     aReadLock.unlock();
1366cdf0e10cSrcweir 
1367cdf0e10cSrcweir     implts_setToolbarCreation( true );
1368cdf0e10cSrcweir     try
1369cdf0e10cSrcweir     {
1370cdf0e10cSrcweir         if ( xUIElementFactory.is() )
1371cdf0e10cSrcweir             xUIElement = xUIElementFactory->createUIElement( aName, aPropSeq );
1372cdf0e10cSrcweir     }
1373cdf0e10cSrcweir     catch ( container::NoSuchElementException& ) {}
1374cdf0e10cSrcweir     catch ( lang::IllegalArgumentException& ) {}
1375cdf0e10cSrcweir     implts_setToolbarCreation( false );
1376cdf0e10cSrcweir 
1377cdf0e10cSrcweir     return xUIElement;
1378cdf0e10cSrcweir }
1379cdf0e10cSrcweir 
1380cdf0e10cSrcweir void ToolbarLayoutManager::implts_setElementData( UIElement& rElement, const uno::Reference< awt::XDockableWindow >& rDockWindow )
1381cdf0e10cSrcweir {
1382cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
1383cdf0e10cSrcweir     bool bShowElement( rElement.m_bVisible && !rElement.m_bMasterHide && implts_isParentWindowVisible() );
1384cdf0e10cSrcweir     aReadLock.unlock();
1385cdf0e10cSrcweir 
1386cdf0e10cSrcweir     uno::Reference< awt::XDockableWindow > xDockWindow( rDockWindow );
1387cdf0e10cSrcweir     uno::Reference< awt::XWindow2 >        xWindow( xDockWindow, uno::UNO_QUERY );
1388cdf0e10cSrcweir 
1389cdf0e10cSrcweir     Window*  pWindow( 0 );
1390cdf0e10cSrcweir     ToolBox* pToolBox( 0 );
1391cdf0e10cSrcweir 
1392cdf0e10cSrcweir     if ( xDockWindow.is() && xWindow.is() )
1393cdf0e10cSrcweir     {
1394cdf0e10cSrcweir         {
1395cdf0e10cSrcweir             vos::OGuard aGuard( Application::GetSolarMutex() );
1396cdf0e10cSrcweir             pWindow = VCLUnoHelper::GetWindow( xWindow );
1397cdf0e10cSrcweir             if ( pWindow )
1398cdf0e10cSrcweir             {
1399cdf0e10cSrcweir                 String aText = pWindow->GetText();
1400cdf0e10cSrcweir                 if ( aText.Len() == 0 )
1401cdf0e10cSrcweir                     pWindow->SetText( rElement.m_aUIName );
1402cdf0e10cSrcweir                 if ( rElement.m_bNoClose )
1403cdf0e10cSrcweir                     pWindow->SetStyle( pWindow->GetStyle() & ~WB_CLOSEABLE );
1404cdf0e10cSrcweir                 if ( pWindow->GetType() == WINDOW_TOOLBOX )
1405cdf0e10cSrcweir                     pToolBox = (ToolBox *)pWindow;
1406cdf0e10cSrcweir             }
1407cdf0e10cSrcweir             if ( pToolBox )
1408cdf0e10cSrcweir             {
1409cdf0e10cSrcweir                 if (( rElement.m_nStyle < 0 ) || ( rElement.m_nStyle > BUTTON_SYMBOLTEXT ))
1410cdf0e10cSrcweir                     rElement.m_nStyle = BUTTON_SYMBOL;
1411cdf0e10cSrcweir                 pToolBox->SetButtonType( (ButtonType)rElement.m_nStyle );
1412cdf0e10cSrcweir                 if ( rElement.m_bNoClose )
1413cdf0e10cSrcweir                     pToolBox->SetFloatStyle( pToolBox->GetFloatStyle() & ~WB_CLOSEABLE );
1414cdf0e10cSrcweir             }
1415cdf0e10cSrcweir         }
1416cdf0e10cSrcweir 
1417cdf0e10cSrcweir         if ( rElement.m_bFloating )
1418cdf0e10cSrcweir         {
1419cdf0e10cSrcweir             if ( pWindow )
1420cdf0e10cSrcweir             {
1421cdf0e10cSrcweir                 vos::OGuard aGuard( Application::GetSolarMutex() );
1422cdf0e10cSrcweir                 String aText = pWindow->GetText();
1423cdf0e10cSrcweir                 if ( aText.Len() == 0 )
1424cdf0e10cSrcweir                     pWindow->SetText( rElement.m_aUIName );
1425cdf0e10cSrcweir             }
1426cdf0e10cSrcweir 
1427cdf0e10cSrcweir             ::Point  aPos( rElement.m_aFloatingData.m_aPos.X(),
1428cdf0e10cSrcweir                            rElement.m_aFloatingData.m_aPos.Y() );
1429cdf0e10cSrcweir             bool bWriteData( false );
1430cdf0e10cSrcweir             bool bUndefPos = hasDefaultPosValue( rElement.m_aFloatingData.m_aPos );
1431cdf0e10cSrcweir             bool bSetSize = ( rElement.m_aFloatingData.m_aSize.Width() != 0 &&
1432cdf0e10cSrcweir                               rElement.m_aFloatingData.m_aSize.Height() != 0 );
1433cdf0e10cSrcweir             xDockWindow->setFloatingMode( sal_True );
1434cdf0e10cSrcweir             if ( bUndefPos )
1435cdf0e10cSrcweir             {
1436cdf0e10cSrcweir                 aPos = implts_findNextCascadeFloatingPos();
1437cdf0e10cSrcweir                 rElement.m_aFloatingData.m_aPos = aPos; // set new cascaded position
1438cdf0e10cSrcweir                 bWriteData = true;
1439cdf0e10cSrcweir             }
1440cdf0e10cSrcweir 
1441cdf0e10cSrcweir             if( bSetSize )
1442cdf0e10cSrcweir                 xWindow->setOutputSize( AWTSize( rElement.m_aFloatingData.m_aSize ) );
1443cdf0e10cSrcweir             else
1444cdf0e10cSrcweir             {
1445cdf0e10cSrcweir                 if( pToolBox )
1446cdf0e10cSrcweir                 {
1447cdf0e10cSrcweir                     // set an optimal initial floating size
1448cdf0e10cSrcweir                     vos::OGuard aGuard( Application::GetSolarMutex() );
1449cdf0e10cSrcweir                     ::Size aSize( pToolBox->CalcFloatingWindowSizePixel() );
1450cdf0e10cSrcweir                     pToolBox->SetOutputSizePixel( aSize );
1451cdf0e10cSrcweir                 }
1452cdf0e10cSrcweir             }
1453cdf0e10cSrcweir 
1454cdf0e10cSrcweir             // #i60882# IMPORTANT: Set position after size as it is
1455cdf0e10cSrcweir             // possible that we position some part of the toolbar
1456cdf0e10cSrcweir             // outside of the desktop. A default constructed toolbar
1457cdf0e10cSrcweir             // always has one line. Now VCL automatically
1458cdf0e10cSrcweir             // position the toolbar back into the desktop. Therefore
1459cdf0e10cSrcweir             // we resize the toolbar with the new (wrong) position.
1460cdf0e10cSrcweir             // To fix this problem we have to set the size BEFORE the
1461cdf0e10cSrcweir             // position.
1462cdf0e10cSrcweir             xWindow->setPosSize( aPos.X(), aPos.Y(), 0, 0, awt::PosSize::POS );
1463cdf0e10cSrcweir 
1464cdf0e10cSrcweir             if ( bWriteData )
1465cdf0e10cSrcweir                 implts_writeWindowStateData( rElement );
1466cdf0e10cSrcweir             if ( bShowElement && pWindow )
1467cdf0e10cSrcweir             {
1468cdf0e10cSrcweir                 vos::OGuard aGuard( Application::GetSolarMutex() );
1469cdf0e10cSrcweir                 pWindow->Show( sal_True, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE );
1470cdf0e10cSrcweir             }
1471cdf0e10cSrcweir         }
1472cdf0e10cSrcweir         else
1473cdf0e10cSrcweir         {
1474cdf0e10cSrcweir             bool    bSetSize( false );
1475cdf0e10cSrcweir             ::Point aDockPos;
1476cdf0e10cSrcweir             ::Point aPixelPos;
1477cdf0e10cSrcweir             ::Size  aSize;
1478cdf0e10cSrcweir 
1479cdf0e10cSrcweir             if ( pToolBox )
1480cdf0e10cSrcweir             {
1481cdf0e10cSrcweir                 vos::OGuard aGuard( Application::GetSolarMutex() );
1482cdf0e10cSrcweir                 pToolBox->SetAlign( ImplConvertAlignment(rElement.m_aDockedData.m_nDockedArea )  );
1483cdf0e10cSrcweir                 pToolBox->SetLineCount( 1 );
1484cdf0e10cSrcweir                 xDockWindow->setFloatingMode( sal_False );
1485cdf0e10cSrcweir                 if ( rElement.m_aDockedData.m_bLocked )
1486cdf0e10cSrcweir                     xDockWindow->lock();
1487cdf0e10cSrcweir                 aSize = pToolBox->CalcWindowSizePixel();
1488cdf0e10cSrcweir                 bSetSize = true;
1489cdf0e10cSrcweir 
1490cdf0e10cSrcweir                 if ( isDefaultPos( rElement.m_aDockedData.m_aPos ))
1491cdf0e10cSrcweir                 {
1492cdf0e10cSrcweir                     implts_findNextDockingPos( (ui::DockingArea)rElement.m_aDockedData.m_nDockedArea, aSize, aDockPos, aPixelPos );
1493cdf0e10cSrcweir                     rElement.m_aDockedData.m_aPos = aDockPos;
1494cdf0e10cSrcweir                 }
1495cdf0e10cSrcweir             }
1496cdf0e10cSrcweir 
1497cdf0e10cSrcweir             xWindow->setPosSize( aPixelPos.X(), aPixelPos.Y(), 0, 0, awt::PosSize::POS );
1498cdf0e10cSrcweir             if( bSetSize )
1499cdf0e10cSrcweir                 xWindow->setOutputSize( AWTSize( aSize) );
1500cdf0e10cSrcweir 
1501cdf0e10cSrcweir             if ( pWindow )
1502cdf0e10cSrcweir             {
1503cdf0e10cSrcweir                 vos::OGuard aGuard( Application::GetSolarMutex() );
1504cdf0e10cSrcweir                 if ( !bShowElement )
1505cdf0e10cSrcweir                     pWindow->Hide();
1506cdf0e10cSrcweir             }
1507cdf0e10cSrcweir         }
1508cdf0e10cSrcweir     }
1509cdf0e10cSrcweir }
1510cdf0e10cSrcweir 
1511cdf0e10cSrcweir void ToolbarLayoutManager::implts_destroyDockingAreaWindows()
1512cdf0e10cSrcweir {
1513cdf0e10cSrcweir     WriteGuard aWriteLock( m_aLock );
1514cdf0e10cSrcweir     uno::Reference< awt::XWindow > xTopDockingWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_TOP] );
1515cdf0e10cSrcweir     uno::Reference< awt::XWindow > xLeftDockingWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_LEFT] );
1516cdf0e10cSrcweir     uno::Reference< awt::XWindow > xRightDockingWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_RIGHT] );
1517cdf0e10cSrcweir     uno::Reference< awt::XWindow > xBottomDockingWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_BOTTOM] );
1518cdf0e10cSrcweir     m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_TOP].clear();
1519cdf0e10cSrcweir     m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_LEFT].clear();
1520cdf0e10cSrcweir     m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_RIGHT].clear();
1521cdf0e10cSrcweir     m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_BOTTOM].clear();
1522cdf0e10cSrcweir     aWriteLock.unlock();
1523cdf0e10cSrcweir 
1524cdf0e10cSrcweir     // destroy windows
1525cdf0e10cSrcweir     xTopDockingWindow->dispose();
1526cdf0e10cSrcweir     xLeftDockingWindow->dispose();
1527cdf0e10cSrcweir     xRightDockingWindow->dispose();
1528cdf0e10cSrcweir     xBottomDockingWindow->dispose();
1529cdf0e10cSrcweir }
1530cdf0e10cSrcweir 
1531cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------
1532cdf0e10cSrcweir // persistence methods
1533cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------
1534cdf0e10cSrcweir 
1535cdf0e10cSrcweir sal_Bool ToolbarLayoutManager::implts_readWindowStateData( const rtl::OUString& aName, UIElement& rElementData )
1536cdf0e10cSrcweir {
1537cdf0e10cSrcweir     WriteGuard aWriteLock( m_aLock );
1538cdf0e10cSrcweir     uno::Reference< container::XNameAccess > xPersistentWindowState( m_xPersistentWindowState );
1539cdf0e10cSrcweir     bool bGetSettingsState( false );
1540cdf0e10cSrcweir     aWriteLock.unlock();
1541cdf0e10cSrcweir 
1542cdf0e10cSrcweir     if ( xPersistentWindowState.is() )
1543cdf0e10cSrcweir     {
1544cdf0e10cSrcweir         aWriteLock.lock();
1545cdf0e10cSrcweir         bool bGlobalSettings( m_bGlobalSettings );
1546cdf0e10cSrcweir         GlobalSettings* pGlobalSettings( 0 );
1547cdf0e10cSrcweir         if ( m_pGlobalSettings == 0 )
1548cdf0e10cSrcweir         {
1549cdf0e10cSrcweir             m_pGlobalSettings = new GlobalSettings( m_xSMGR );
1550cdf0e10cSrcweir             bGetSettingsState = true;
1551cdf0e10cSrcweir         }
1552cdf0e10cSrcweir         pGlobalSettings = m_pGlobalSettings;
1553cdf0e10cSrcweir         aWriteLock.unlock();
1554cdf0e10cSrcweir 
1555cdf0e10cSrcweir         try
1556cdf0e10cSrcweir         {
1557cdf0e10cSrcweir             uno::Sequence< beans::PropertyValue > aWindowState;
1558cdf0e10cSrcweir             if ( xPersistentWindowState->getByName( aName ) >>= aWindowState )
1559cdf0e10cSrcweir             {
1560cdf0e10cSrcweir                 sal_Bool bValue( sal_False );
1561cdf0e10cSrcweir                 for ( sal_Int32 n = 0; n < aWindowState.getLength(); n++ )
1562cdf0e10cSrcweir                 {
1563cdf0e10cSrcweir                     if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_DOCKED ))
1564cdf0e10cSrcweir                     {
1565cdf0e10cSrcweir                         if ( aWindowState[n].Value >>= bValue )
1566cdf0e10cSrcweir                             rElementData.m_bFloating = !bValue;
1567cdf0e10cSrcweir                     }
1568cdf0e10cSrcweir                     else if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_VISIBLE ))
1569cdf0e10cSrcweir                     {
1570cdf0e10cSrcweir                         if ( aWindowState[n].Value >>= bValue )
1571cdf0e10cSrcweir                             rElementData.m_bVisible = bValue;
1572cdf0e10cSrcweir                     }
1573cdf0e10cSrcweir                     else if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_DOCKINGAREA ))
1574cdf0e10cSrcweir                     {
1575cdf0e10cSrcweir                         ui::DockingArea eDockingArea;
1576cdf0e10cSrcweir                         if ( aWindowState[n].Value >>= eDockingArea )
1577cdf0e10cSrcweir                             rElementData.m_aDockedData.m_nDockedArea = sal_Int16( eDockingArea );
1578cdf0e10cSrcweir                     }
1579cdf0e10cSrcweir                     else if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_DOCKPOS ))
1580cdf0e10cSrcweir                     {
1581cdf0e10cSrcweir                         awt::Point aPoint;
1582cdf0e10cSrcweir                         if ( aWindowState[n].Value >>= aPoint )
1583cdf0e10cSrcweir                         {
1584cdf0e10cSrcweir                             rElementData.m_aDockedData.m_aPos.X() = aPoint.X;
1585cdf0e10cSrcweir                             rElementData.m_aDockedData.m_aPos.Y() = aPoint.Y;
1586cdf0e10cSrcweir                         }
1587cdf0e10cSrcweir                     }
1588cdf0e10cSrcweir                     else if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_POS ))
1589cdf0e10cSrcweir                     {
1590cdf0e10cSrcweir                         awt::Point aPoint;
1591cdf0e10cSrcweir                         if ( aWindowState[n].Value >>= aPoint )
1592cdf0e10cSrcweir                         {
1593cdf0e10cSrcweir                             rElementData.m_aFloatingData.m_aPos.X() = aPoint.X;
1594cdf0e10cSrcweir                             rElementData.m_aFloatingData.m_aPos.Y() = aPoint.Y;
1595cdf0e10cSrcweir                         }
1596cdf0e10cSrcweir                     }
1597cdf0e10cSrcweir                     else if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_SIZE ))
1598cdf0e10cSrcweir                     {
1599cdf0e10cSrcweir                         awt::Size aSize;
1600cdf0e10cSrcweir                         if ( aWindowState[n].Value >>= aSize )
1601cdf0e10cSrcweir                         {
1602cdf0e10cSrcweir                             rElementData.m_aFloatingData.m_aSize.Width() = aSize.Width;
1603cdf0e10cSrcweir                             rElementData.m_aFloatingData.m_aSize.Height() = aSize.Height;
1604cdf0e10cSrcweir                         }
1605cdf0e10cSrcweir                     }
1606cdf0e10cSrcweir                     else if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_UINAME ))
1607cdf0e10cSrcweir                         aWindowState[n].Value >>= rElementData.m_aUIName;
1608cdf0e10cSrcweir                     else if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_STYLE ))
1609cdf0e10cSrcweir                     {
1610cdf0e10cSrcweir                         sal_Int32 nStyle = 0;
1611cdf0e10cSrcweir                         if ( aWindowState[n].Value >>= nStyle )
1612cdf0e10cSrcweir                             rElementData.m_nStyle = sal_Int16( nStyle );
1613cdf0e10cSrcweir                     }
1614cdf0e10cSrcweir                     else if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_LOCKED ))
1615cdf0e10cSrcweir                     {
1616cdf0e10cSrcweir                         if ( aWindowState[n].Value >>= bValue )
1617cdf0e10cSrcweir                             rElementData.m_aDockedData.m_bLocked = bValue;
1618cdf0e10cSrcweir                     }
1619cdf0e10cSrcweir                     else if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_CONTEXT ))
1620cdf0e10cSrcweir                     {
1621cdf0e10cSrcweir                         if ( aWindowState[n].Value >>= bValue )
1622cdf0e10cSrcweir                             rElementData.m_bContextSensitive = bValue;
1623cdf0e10cSrcweir                     }
1624cdf0e10cSrcweir                     else if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_NOCLOSE ))
1625cdf0e10cSrcweir                     {
1626cdf0e10cSrcweir                         if ( aWindowState[n].Value >>= bValue )
1627cdf0e10cSrcweir                             rElementData.m_bNoClose = bValue;
1628cdf0e10cSrcweir                     }
1629cdf0e10cSrcweir                     else if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_CONTEXTACTIVE ))
1630cdf0e10cSrcweir                     {
1631cdf0e10cSrcweir                         if ( aWindowState[n].Value >>= bValue )
1632cdf0e10cSrcweir                             rElementData.m_bContextActive = bValue;
1633cdf0e10cSrcweir                     }
1634cdf0e10cSrcweir                     else if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_SOFTCLOSE ))
1635cdf0e10cSrcweir                     {
1636cdf0e10cSrcweir                         if ( aWindowState[n].Value >>= bValue )
1637cdf0e10cSrcweir                             rElementData.m_bSoftClose = bValue;
1638cdf0e10cSrcweir                     }
1639cdf0e10cSrcweir                 }
1640cdf0e10cSrcweir             }
1641cdf0e10cSrcweir 
1642cdf0e10cSrcweir             // oversteer values with global settings
1643cdf0e10cSrcweir             if ( pGlobalSettings && ( bGetSettingsState || bGlobalSettings ))
1644cdf0e10cSrcweir             {
1645cdf0e10cSrcweir                 if ( pGlobalSettings->HasStatesInfo( GlobalSettings::UIELEMENT_TYPE_TOOLBAR ))
1646cdf0e10cSrcweir                 {
1647cdf0e10cSrcweir                     WriteGuard aWriteLock2( m_aLock );
1648cdf0e10cSrcweir                     m_bGlobalSettings = true;
1649cdf0e10cSrcweir                     aWriteLock2.unlock();
1650cdf0e10cSrcweir 
1651cdf0e10cSrcweir                     uno::Any aValue;
1652cdf0e10cSrcweir                     sal_Bool bValue = sal_Bool();
1653cdf0e10cSrcweir                     if ( pGlobalSettings->GetStateInfo( GlobalSettings::UIELEMENT_TYPE_TOOLBAR,
1654cdf0e10cSrcweir                                                         GlobalSettings::STATEINFO_LOCKED,
1655cdf0e10cSrcweir                                                         aValue ))
1656cdf0e10cSrcweir                         aValue >>= rElementData.m_aDockedData.m_bLocked;
1657cdf0e10cSrcweir                     if ( pGlobalSettings->GetStateInfo( GlobalSettings::UIELEMENT_TYPE_TOOLBAR,
1658cdf0e10cSrcweir                                                         GlobalSettings::STATEINFO_DOCKED,
1659cdf0e10cSrcweir                                                         aValue ))
1660cdf0e10cSrcweir                     {
1661cdf0e10cSrcweir                         if ( aValue >>= bValue )
1662cdf0e10cSrcweir                             rElementData.m_bFloating = !bValue;
1663cdf0e10cSrcweir                     }
1664cdf0e10cSrcweir                 }
1665cdf0e10cSrcweir             }
1666cdf0e10cSrcweir 
1667cdf0e10cSrcweir             return sal_True;
1668cdf0e10cSrcweir         }
1669cdf0e10cSrcweir         catch ( container::NoSuchElementException& ) {}
1670cdf0e10cSrcweir     }
1671cdf0e10cSrcweir 
1672cdf0e10cSrcweir     return sal_False;
1673cdf0e10cSrcweir }
1674cdf0e10cSrcweir 
1675cdf0e10cSrcweir void ToolbarLayoutManager::implts_writeWindowStateData( const UIElement& rElementData )
1676cdf0e10cSrcweir {
1677cdf0e10cSrcweir     WriteGuard aWriteLock( m_aLock );
1678cdf0e10cSrcweir     uno::Reference< container::XNameAccess > xPersistentWindowState( m_xPersistentWindowState );
1679cdf0e10cSrcweir     m_bStoreWindowState = true; // set flag to determine that we triggered the notification
1680cdf0e10cSrcweir     aWriteLock.unlock();
1681cdf0e10cSrcweir 
1682cdf0e10cSrcweir     bool bPersistent( sal_False );
1683cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xPropSet( rElementData.m_xUIElement, uno::UNO_QUERY );
1684cdf0e10cSrcweir     if ( xPropSet.is() )
1685cdf0e10cSrcweir     {
1686cdf0e10cSrcweir         try
1687cdf0e10cSrcweir         {
1688cdf0e10cSrcweir             // Check persistent flag of the user interface element
1689cdf0e10cSrcweir             xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Persistent" ))) >>= bPersistent;
1690cdf0e10cSrcweir         }
1691cdf0e10cSrcweir         catch ( beans::UnknownPropertyException )
1692cdf0e10cSrcweir         {
1693cdf0e10cSrcweir             bPersistent = true; // Non-configurable elements should at least store their dimension/position
1694cdf0e10cSrcweir         }
1695cdf0e10cSrcweir         catch ( lang::WrappedTargetException ) {}
1696cdf0e10cSrcweir     }
1697cdf0e10cSrcweir 
1698cdf0e10cSrcweir     if ( bPersistent && xPersistentWindowState.is() )
1699cdf0e10cSrcweir     {
1700cdf0e10cSrcweir         try
1701cdf0e10cSrcweir         {
170226169348SAriel Constenla-Haile             uno::Sequence< beans::PropertyValue > aWindowState( 9 );
1703cdf0e10cSrcweir 
1704cdf0e10cSrcweir             aWindowState[0].Name  = ::rtl::OUString::createFromAscii( WINDOWSTATE_PROPERTY_DOCKED );
1705cdf0e10cSrcweir             aWindowState[0].Value = ::uno::makeAny( sal_Bool( !rElementData.m_bFloating ));
1706cdf0e10cSrcweir             aWindowState[1].Name  = ::rtl::OUString::createFromAscii( WINDOWSTATE_PROPERTY_VISIBLE );
1707cdf0e10cSrcweir             aWindowState[1].Value = uno::makeAny( sal_Bool( rElementData.m_bVisible ));
1708cdf0e10cSrcweir             aWindowState[2].Name  = ::rtl::OUString::createFromAscii( WINDOWSTATE_PROPERTY_DOCKINGAREA );
1709cdf0e10cSrcweir             aWindowState[2].Value = uno::makeAny( static_cast< ui::DockingArea >( rElementData.m_aDockedData.m_nDockedArea ) );
1710cdf0e10cSrcweir 
1711cdf0e10cSrcweir             awt::Point aPos;
1712cdf0e10cSrcweir             aPos.X = rElementData.m_aDockedData.m_aPos.X();
1713cdf0e10cSrcweir             aPos.Y = rElementData.m_aDockedData.m_aPos.Y();
1714cdf0e10cSrcweir             aWindowState[3].Name  = ::rtl::OUString::createFromAscii( WINDOWSTATE_PROPERTY_DOCKPOS );
1715cdf0e10cSrcweir             aWindowState[3].Value <<= aPos;
1716cdf0e10cSrcweir 
1717cdf0e10cSrcweir             aPos.X = rElementData.m_aFloatingData.m_aPos.X();
1718cdf0e10cSrcweir             aPos.Y = rElementData.m_aFloatingData.m_aPos.Y();
1719cdf0e10cSrcweir             aWindowState[4].Name  = ::rtl::OUString::createFromAscii( WINDOWSTATE_PROPERTY_POS );
1720cdf0e10cSrcweir             aWindowState[4].Value <<= aPos;
1721cdf0e10cSrcweir 
1722cdf0e10cSrcweir             awt::Size aSize;
1723cdf0e10cSrcweir             aSize.Width  = rElementData.m_aFloatingData.m_aSize.Width();
1724cdf0e10cSrcweir             aSize.Height = rElementData.m_aFloatingData.m_aSize.Height();
1725cdf0e10cSrcweir             aWindowState[5].Name  = ::rtl::OUString::createFromAscii( WINDOWSTATE_PROPERTY_SIZE );
1726cdf0e10cSrcweir             aWindowState[5].Value <<= aSize;
1727cdf0e10cSrcweir             aWindowState[6].Name  = ::rtl::OUString::createFromAscii( WINDOWSTATE_PROPERTY_UINAME );
1728cdf0e10cSrcweir             aWindowState[6].Value = uno::makeAny( rElementData.m_aUIName );
1729cdf0e10cSrcweir             aWindowState[7].Name  = ::rtl::OUString::createFromAscii( WINDOWSTATE_PROPERTY_LOCKED );
1730cdf0e10cSrcweir             aWindowState[7].Value = uno::makeAny( rElementData.m_aDockedData.m_bLocked );
173126169348SAriel Constenla-Haile             aWindowState[8].Name  = ::rtl::OUString::createFromAscii( WINDOWSTATE_PROPERTY_STYLE );
173226169348SAriel Constenla-Haile             aWindowState[8].Value = uno::makeAny( rElementData.m_nStyle );
1733cdf0e10cSrcweir 
1734cdf0e10cSrcweir             ::rtl::OUString aName = rElementData.m_aName;
1735cdf0e10cSrcweir             if ( xPersistentWindowState->hasByName( aName ))
1736cdf0e10cSrcweir             {
1737cdf0e10cSrcweir                 uno::Reference< container::XNameReplace > xReplace( xPersistentWindowState, uno::UNO_QUERY );
1738cdf0e10cSrcweir                 xReplace->replaceByName( aName, uno::makeAny( aWindowState ));
1739cdf0e10cSrcweir             }
1740cdf0e10cSrcweir             else
1741cdf0e10cSrcweir             {
1742cdf0e10cSrcweir                 uno::Reference< container::XNameContainer > xInsert( xPersistentWindowState, uno::UNO_QUERY );
1743cdf0e10cSrcweir                 xInsert->insertByName( aName, uno::makeAny( aWindowState ));
1744cdf0e10cSrcweir             }
1745cdf0e10cSrcweir         }
1746cdf0e10cSrcweir         catch ( uno::Exception& ) {}
1747cdf0e10cSrcweir     }
1748cdf0e10cSrcweir 
1749cdf0e10cSrcweir     // Reset flag
1750cdf0e10cSrcweir     aWriteLock.lock();
1751cdf0e10cSrcweir     m_bStoreWindowState = false;
1752cdf0e10cSrcweir     aWriteLock.unlock();
1753cdf0e10cSrcweir }
1754cdf0e10cSrcweir 
1755cdf0e10cSrcweir void ToolbarLayoutManager::implts_writeNewWindowStateData( const rtl::OUString aName, const uno::Reference< awt::XWindow >& xWindow )
1756cdf0e10cSrcweir {
1757cdf0e10cSrcweir     bool bVisible( false );
1758cdf0e10cSrcweir     bool bFloating( true );
1759cdf0e10cSrcweir     awt::Rectangle aPos;
1760cdf0e10cSrcweir     awt::Size      aSize;
1761cdf0e10cSrcweir 
1762cdf0e10cSrcweir     if ( xWindow.is() )
1763cdf0e10cSrcweir     {
1764cdf0e10cSrcweir         uno::Reference< awt::XDockableWindow > xDockWindow( xWindow, uno::UNO_QUERY );
1765cdf0e10cSrcweir         if ( xDockWindow.is() )
1766cdf0e10cSrcweir             bFloating = xDockWindow->isFloating();
1767cdf0e10cSrcweir 
1768cdf0e10cSrcweir         uno::Reference< awt::XWindow2 > xWindow2( xWindow, uno::UNO_QUERY );
1769cdf0e10cSrcweir         if( xWindow2.is() )
1770cdf0e10cSrcweir         {
1771cdf0e10cSrcweir             aPos     = xWindow2->getPosSize();
1772cdf0e10cSrcweir             aSize    = xWindow2->getOutputSize();   // always use output size for consistency
1773cdf0e10cSrcweir             bVisible = xWindow2->isVisible();
1774cdf0e10cSrcweir         }
1775cdf0e10cSrcweir 
1776cdf0e10cSrcweir         WriteGuard aWriteLock( m_aLock );
1777cdf0e10cSrcweir         UIElement& rUIElement = impl_findToolbar( aName );
1778cdf0e10cSrcweir         if ( rUIElement.m_xUIElement.is() )
1779cdf0e10cSrcweir         {
1780cdf0e10cSrcweir             rUIElement.m_bVisible   = bVisible;
1781cdf0e10cSrcweir             rUIElement.m_bFloating  = bFloating;
1782cdf0e10cSrcweir             if ( bFloating )
1783cdf0e10cSrcweir             {
1784cdf0e10cSrcweir                 rUIElement.m_aFloatingData.m_aPos  = ::Point( aPos.X, aPos.Y );
1785cdf0e10cSrcweir                 rUIElement.m_aFloatingData.m_aSize = ::Size( aSize.Width, aSize.Height );
1786cdf0e10cSrcweir             }
1787cdf0e10cSrcweir         }
1788cdf0e10cSrcweir         implts_writeWindowStateData( rUIElement );
1789cdf0e10cSrcweir         aWriteLock.unlock();
1790cdf0e10cSrcweir     }
1791cdf0e10cSrcweir }
1792cdf0e10cSrcweir 
1793cdf0e10cSrcweir /******************************************************************************
1794cdf0e10cSrcweir                         LOOKUP PART FOR TOOLBARS
1795cdf0e10cSrcweir ******************************************************************************/
1796cdf0e10cSrcweir 
1797cdf0e10cSrcweir UIElement& ToolbarLayoutManager::impl_findToolbar( const rtl::OUString& aName )
1798cdf0e10cSrcweir {
1799cdf0e10cSrcweir     static UIElement aEmptyElement;
1800cdf0e10cSrcweir     UIElementVector::iterator pIter;
1801cdf0e10cSrcweir 
1802cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
1803cdf0e10cSrcweir     for ( pIter = m_aUIElements.begin(); pIter != m_aUIElements.end(); pIter++ )
1804cdf0e10cSrcweir     {
1805cdf0e10cSrcweir         if ( pIter->m_aName == aName )
1806cdf0e10cSrcweir             return *pIter;
1807cdf0e10cSrcweir     }
1808cdf0e10cSrcweir 
1809cdf0e10cSrcweir     return aEmptyElement;
1810cdf0e10cSrcweir }
1811cdf0e10cSrcweir 
1812cdf0e10cSrcweir UIElement ToolbarLayoutManager::implts_findToolbar( const rtl::OUString& aName )
1813cdf0e10cSrcweir {
1814cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
1815cdf0e10cSrcweir     UIElement aElement = impl_findToolbar( aName );
1816cdf0e10cSrcweir     aReadLock.unlock();
1817cdf0e10cSrcweir 
1818cdf0e10cSrcweir     return aElement;
1819cdf0e10cSrcweir }
1820cdf0e10cSrcweir 
1821cdf0e10cSrcweir UIElement ToolbarLayoutManager::implts_findToolbar( const uno::Reference< uno::XInterface >& xToolbar )
1822cdf0e10cSrcweir {
1823cdf0e10cSrcweir     UIElement                       aToolbar;
1824cdf0e10cSrcweir     UIElementVector::const_iterator pIter;
1825cdf0e10cSrcweir 
1826cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
1827cdf0e10cSrcweir     for ( pIter = m_aUIElements.begin(); pIter != m_aUIElements.end(); pIter++ )
1828cdf0e10cSrcweir     {
1829cdf0e10cSrcweir         if ( pIter->m_xUIElement.is() )
1830cdf0e10cSrcweir         {
1831cdf0e10cSrcweir             uno::Reference< uno::XInterface > xIfac( pIter->m_xUIElement->getRealInterface(), uno::UNO_QUERY );
1832cdf0e10cSrcweir             if ( xIfac == xToolbar )
1833cdf0e10cSrcweir             {
1834cdf0e10cSrcweir                 aToolbar = *pIter;
1835cdf0e10cSrcweir                 break;
1836cdf0e10cSrcweir             }
1837cdf0e10cSrcweir         }
1838cdf0e10cSrcweir     }
1839cdf0e10cSrcweir 
1840cdf0e10cSrcweir     return aToolbar;
1841cdf0e10cSrcweir }
1842cdf0e10cSrcweir 
1843cdf0e10cSrcweir uno::Reference< awt::XWindow > ToolbarLayoutManager::implts_getXWindow( const ::rtl::OUString& aName )
1844cdf0e10cSrcweir {
1845cdf0e10cSrcweir     UIElementVector::iterator pIter;
1846cdf0e10cSrcweir     uno::Reference< awt::XWindow > xWindow;
1847cdf0e10cSrcweir 
1848cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
1849cdf0e10cSrcweir     for ( pIter = m_aUIElements.begin(); pIter != m_aUIElements.end(); pIter++ )
1850cdf0e10cSrcweir     {
1851cdf0e10cSrcweir         if ( pIter->m_aName == aName && pIter->m_xUIElement.is() )
1852cdf0e10cSrcweir         {
1853cdf0e10cSrcweir              xWindow = uno::Reference< awt::XWindow >( pIter->m_xUIElement->getRealInterface(), uno::UNO_QUERY );
1854cdf0e10cSrcweir              break;
1855cdf0e10cSrcweir         }
1856cdf0e10cSrcweir     }
1857cdf0e10cSrcweir 
1858cdf0e10cSrcweir     return xWindow;
1859cdf0e10cSrcweir }
1860cdf0e10cSrcweir 
1861cdf0e10cSrcweir Window* ToolbarLayoutManager::implts_getWindow( const ::rtl::OUString& aName )
1862cdf0e10cSrcweir {
1863cdf0e10cSrcweir     uno::Reference< awt::XWindow > xWindow = implts_getXWindow( aName );
1864cdf0e10cSrcweir     Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
1865cdf0e10cSrcweir 
1866cdf0e10cSrcweir     return pWindow;
1867cdf0e10cSrcweir }
1868cdf0e10cSrcweir 
1869cdf0e10cSrcweir bool ToolbarLayoutManager::implts_insertToolbar( const UIElement& rUIElement )
1870cdf0e10cSrcweir {
1871cdf0e10cSrcweir     UIElement aTempData;
1872cdf0e10cSrcweir     bool      bFound( false );
1873cdf0e10cSrcweir     bool      bResult( false );
1874cdf0e10cSrcweir 
1875cdf0e10cSrcweir     aTempData = implts_findToolbar( rUIElement.m_aName );
1876cdf0e10cSrcweir     if ( aTempData.m_aName == rUIElement.m_aName )
1877cdf0e10cSrcweir         bFound = true;
1878cdf0e10cSrcweir 
1879cdf0e10cSrcweir     if ( !bFound )
1880cdf0e10cSrcweir     {
1881cdf0e10cSrcweir         WriteGuard aWriteLock( m_aLock );
1882cdf0e10cSrcweir         m_aUIElements.push_back( rUIElement );
1883cdf0e10cSrcweir         bResult = true;
1884cdf0e10cSrcweir     }
1885cdf0e10cSrcweir 
1886cdf0e10cSrcweir     return bResult;
1887cdf0e10cSrcweir }
1888cdf0e10cSrcweir 
1889cdf0e10cSrcweir void ToolbarLayoutManager::implts_setToolbar( const UIElement& rUIElement )
1890cdf0e10cSrcweir {
1891cdf0e10cSrcweir     WriteGuard aWriteLock( m_aLock );
1892cdf0e10cSrcweir     UIElement& rData = impl_findToolbar( rUIElement.m_aName );
1893cdf0e10cSrcweir     if ( rData.m_aName == rUIElement.m_aName )
1894cdf0e10cSrcweir         rData = rUIElement;
1895cdf0e10cSrcweir     else
1896cdf0e10cSrcweir         m_aUIElements.push_back( rUIElement );
1897cdf0e10cSrcweir }
1898cdf0e10cSrcweir 
1899cdf0e10cSrcweir /******************************************************************************
1900cdf0e10cSrcweir                         LAYOUT CODE PART FOR TOOLBARS
1901cdf0e10cSrcweir ******************************************************************************/
1902cdf0e10cSrcweir 
1903cdf0e10cSrcweir ::Point ToolbarLayoutManager::implts_findNextCascadeFloatingPos()
1904cdf0e10cSrcweir {
1905cdf0e10cSrcweir     const sal_Int32 nHotZoneX       = 50;
1906cdf0e10cSrcweir     const sal_Int32 nHotZoneY       = 50;
1907cdf0e10cSrcweir     const sal_Int32 nCascadeIndentX = 15;
1908cdf0e10cSrcweir     const sal_Int32 nCascadeIndentY = 15;
1909cdf0e10cSrcweir 
1910cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
1911cdf0e10cSrcweir     uno::Reference< awt::XWindow2 > xContainerWindow( m_xContainerWindow );
1912cdf0e10cSrcweir     uno::Reference< awt::XWindow > xTopDockingWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_TOP] );
1913cdf0e10cSrcweir     uno::Reference< awt::XWindow > xLeftDockingWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_LEFT] );
1914cdf0e10cSrcweir     aReadLock.unlock();
1915cdf0e10cSrcweir 
1916cdf0e10cSrcweir     ::Point aStartPos( nCascadeIndentX, nCascadeIndentY );
1917cdf0e10cSrcweir     ::Point aCurrPos( aStartPos );
1918cdf0e10cSrcweir     awt::Rectangle aRect;
1919cdf0e10cSrcweir 
1920cdf0e10cSrcweir     Window* pContainerWindow( 0 );
1921cdf0e10cSrcweir     if ( xContainerWindow.is() )
1922cdf0e10cSrcweir     {
1923cdf0e10cSrcweir         vos::OGuard aGuard( Application::GetSolarMutex() );
1924cdf0e10cSrcweir         pContainerWindow = VCLUnoHelper::GetWindow( xContainerWindow );
1925cdf0e10cSrcweir         if ( pContainerWindow )
1926cdf0e10cSrcweir             aStartPos = pContainerWindow->OutputToScreenPixel( aStartPos );
1927cdf0e10cSrcweir     }
1928cdf0e10cSrcweir 
1929cdf0e10cSrcweir     // Determine size of top and left docking area
1930cdf0e10cSrcweir     awt::Rectangle aTopRect( xTopDockingWindow->getPosSize() );
1931cdf0e10cSrcweir     awt::Rectangle aLeftRect( xLeftDockingWindow->getPosSize() );
1932cdf0e10cSrcweir 
1933cdf0e10cSrcweir     aStartPos.X() += aLeftRect.Width + nCascadeIndentX;
1934cdf0e10cSrcweir     aStartPos.Y() += aTopRect.Height + nCascadeIndentY;
1935cdf0e10cSrcweir     aCurrPos = aStartPos;
1936cdf0e10cSrcweir 
1937cdf0e10cSrcweir     // Try to find a cascaded position for the new floating window
1938cdf0e10cSrcweir     UIElementVector::const_iterator pIter;
1939cdf0e10cSrcweir     for ( pIter = m_aUIElements.begin(); pIter != m_aUIElements.end(); pIter++ )
1940cdf0e10cSrcweir     {
1941cdf0e10cSrcweir         if ( pIter->m_xUIElement.is() )
1942cdf0e10cSrcweir         {
1943cdf0e10cSrcweir             uno::Reference< awt::XDockableWindow > xDockWindow( pIter->m_xUIElement->getRealInterface(), uno::UNO_QUERY );
1944cdf0e10cSrcweir             uno::Reference< awt::XWindow > xWindow( xDockWindow, uno::UNO_QUERY );
1945cdf0e10cSrcweir             if ( xDockWindow.is() && xDockWindow->isFloating() )
1946cdf0e10cSrcweir             {
1947cdf0e10cSrcweir                 vos::OGuard aGuard( Application::GetSolarMutex() );
1948cdf0e10cSrcweir                 Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
1949cdf0e10cSrcweir                 if ( pWindow && pWindow->IsVisible() )
1950cdf0e10cSrcweir                 {
1951cdf0e10cSrcweir                     awt::Rectangle aFloatRect = xWindow->getPosSize();
1952cdf0e10cSrcweir                     if ((( aFloatRect.X - nHotZoneX ) <= aCurrPos.X() ) &&
1953cdf0e10cSrcweir                         ( aFloatRect.X >= aCurrPos.X() ) &&
1954cdf0e10cSrcweir                         (( aFloatRect.Y - nHotZoneY ) <= aCurrPos.Y() ) &&
1955cdf0e10cSrcweir                         ( aFloatRect.Y >= aCurrPos.Y() ))
1956cdf0e10cSrcweir                     {
1957cdf0e10cSrcweir                         aCurrPos.X() = aFloatRect.X + nCascadeIndentX;
1958cdf0e10cSrcweir                         aCurrPos.Y() = aFloatRect.Y + nCascadeIndentY;
1959cdf0e10cSrcweir                     }
1960cdf0e10cSrcweir                 }
1961cdf0e10cSrcweir             }
1962cdf0e10cSrcweir         }
1963cdf0e10cSrcweir     }
1964cdf0e10cSrcweir 
1965cdf0e10cSrcweir     return aCurrPos;
1966cdf0e10cSrcweir }
1967cdf0e10cSrcweir 
1968cdf0e10cSrcweir void ToolbarLayoutManager::implts_sortUIElements()
1969cdf0e10cSrcweir {
1970cdf0e10cSrcweir     WriteGuard aWriteLock( m_aLock );
1971cdf0e10cSrcweir     UIElementVector::iterator pIterStart = m_aUIElements.begin();
1972cdf0e10cSrcweir     UIElementVector::iterator pIterEnd   = m_aUIElements.end();
1973cdf0e10cSrcweir 
1974cdf0e10cSrcweir     std::stable_sort( pIterStart, pIterEnd ); // first created element should first
1975cdf0e10cSrcweir 
1976cdf0e10cSrcweir     // We have to reset our temporary flags.
1977cdf0e10cSrcweir     UIElementVector::iterator pIter;
1978cdf0e10cSrcweir     for ( pIter = m_aUIElements.begin(); pIter != m_aUIElements.end(); pIter++ )
1979cdf0e10cSrcweir         pIter->m_bUserActive = sal_False;
1980cdf0e10cSrcweir     aWriteLock.unlock();
1981cdf0e10cSrcweir }
1982cdf0e10cSrcweir 
1983cdf0e10cSrcweir void ToolbarLayoutManager::implts_getUIElementVectorCopy( UIElementVector& rCopy )
1984cdf0e10cSrcweir {
1985cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
1986cdf0e10cSrcweir     rCopy = m_aUIElements;
1987cdf0e10cSrcweir }
1988cdf0e10cSrcweir 
1989cdf0e10cSrcweir ::Size ToolbarLayoutManager::implts_getTopBottomDockingAreaSizes()
1990cdf0e10cSrcweir {
1991cdf0e10cSrcweir     ::Size                         aSize;
1992cdf0e10cSrcweir     uno::Reference< awt::XWindow > xTopDockingAreaWindow;
1993cdf0e10cSrcweir     uno::Reference< awt::XWindow > xBottomDockingAreaWindow;
1994cdf0e10cSrcweir 
1995cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
1996cdf0e10cSrcweir     xTopDockingAreaWindow    = m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_TOP];
1997cdf0e10cSrcweir     xBottomDockingAreaWindow = m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_BOTTOM];
1998cdf0e10cSrcweir     aReadLock.unlock();
1999cdf0e10cSrcweir 
2000cdf0e10cSrcweir     if ( xTopDockingAreaWindow.is() )
2001cdf0e10cSrcweir         aSize.Width() = xTopDockingAreaWindow->getPosSize().Height;
2002cdf0e10cSrcweir     if ( xBottomDockingAreaWindow.is() )
2003cdf0e10cSrcweir         aSize.Height() = xBottomDockingAreaWindow->getPosSize().Height;
2004cdf0e10cSrcweir 
2005cdf0e10cSrcweir     return aSize;
2006cdf0e10cSrcweir }
2007cdf0e10cSrcweir 
2008cdf0e10cSrcweir void ToolbarLayoutManager::implts_getDockingAreaElementInfos( ui::DockingArea eDockingArea, std::vector< SingleRowColumnWindowData >& rRowColumnsWindowData )
2009cdf0e10cSrcweir {
2010cdf0e10cSrcweir     std::vector< UIElement > aWindowVector;
2011cdf0e10cSrcweir 
2012cdf0e10cSrcweir     if (( eDockingArea < ui::DockingArea_DOCKINGAREA_TOP ) || ( eDockingArea > ui::DockingArea_DOCKINGAREA_RIGHT ))
2013cdf0e10cSrcweir         eDockingArea = ui::DockingArea_DOCKINGAREA_TOP;
2014cdf0e10cSrcweir 
2015cdf0e10cSrcweir     uno::Reference< awt::XWindow > xDockAreaWindow;
2016cdf0e10cSrcweir 
2017cdf0e10cSrcweir     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
2018cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
2019cdf0e10cSrcweir     aWindowVector.reserve(m_aUIElements.size());
2020cdf0e10cSrcweir     xDockAreaWindow = m_xDockAreaWindows[eDockingArea];
2021cdf0e10cSrcweir     UIElementVector::iterator   pIter;
2022cdf0e10cSrcweir     for ( pIter = m_aUIElements.begin(); pIter != m_aUIElements.end(); pIter++ )
2023cdf0e10cSrcweir     {
2024cdf0e10cSrcweir         if ( pIter->m_aDockedData.m_nDockedArea == eDockingArea && pIter->m_bVisible && !pIter->m_bFloating )
2025cdf0e10cSrcweir         {
2026cdf0e10cSrcweir             uno::Reference< ui::XUIElement > xUIElement( pIter->m_xUIElement );
2027cdf0e10cSrcweir             if ( xUIElement.is() )
2028cdf0e10cSrcweir             {
2029cdf0e10cSrcweir                 uno::Reference< awt::XWindow > xWindow( xUIElement->getRealInterface(), uno::UNO_QUERY );
2030cdf0e10cSrcweir                 uno::Reference< awt::XDockableWindow > xDockWindow( xWindow, uno::UNO_QUERY );
2031cdf0e10cSrcweir                 if ( xDockWindow.is() )
2032cdf0e10cSrcweir                 {
2033cdf0e10cSrcweir                     // docked windows
2034cdf0e10cSrcweir                     aWindowVector.push_back( *pIter );
2035cdf0e10cSrcweir                 }
2036cdf0e10cSrcweir             }
2037cdf0e10cSrcweir         }
2038cdf0e10cSrcweir     }
2039cdf0e10cSrcweir     aReadLock.unlock();
2040cdf0e10cSrcweir     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
2041cdf0e10cSrcweir 
2042cdf0e10cSrcweir     rRowColumnsWindowData.clear();
2043cdf0e10cSrcweir 
2044cdf0e10cSrcweir     // Collect data from windows that are on the same row/column
2045cdf0e10cSrcweir     sal_Int32 j;
2046cdf0e10cSrcweir     sal_Int32 nIndex( 0 );
2047cdf0e10cSrcweir     sal_Int32 nLastPos( 0 );
2048cdf0e10cSrcweir     sal_Int32 nCurrPos( -1 );
2049cdf0e10cSrcweir     sal_Int32 nLastRowColPixelPos( 0 );
2050cdf0e10cSrcweir     awt::Rectangle aDockAreaRect;
2051cdf0e10cSrcweir 
2052cdf0e10cSrcweir     if ( xDockAreaWindow.is() )
2053cdf0e10cSrcweir         aDockAreaRect = xDockAreaWindow->getPosSize();
2054cdf0e10cSrcweir 
2055cdf0e10cSrcweir     if ( eDockingArea == ui::DockingArea_DOCKINGAREA_TOP )
2056cdf0e10cSrcweir         nLastRowColPixelPos = 0;
2057cdf0e10cSrcweir     else if ( eDockingArea == ui::DockingArea_DOCKINGAREA_BOTTOM )
2058cdf0e10cSrcweir         nLastRowColPixelPos = aDockAreaRect.Height;
2059cdf0e10cSrcweir     else if ( eDockingArea == ui::DockingArea_DOCKINGAREA_LEFT )
2060cdf0e10cSrcweir         nLastRowColPixelPos = 0;
2061cdf0e10cSrcweir     else
2062cdf0e10cSrcweir         nLastRowColPixelPos = aDockAreaRect.Width;
2063cdf0e10cSrcweir 
2064cdf0e10cSrcweir     const sal_uInt32 nCount = aWindowVector.size();
2065cdf0e10cSrcweir     for ( j = 0; j < sal_Int32( nCount); j++ )
2066cdf0e10cSrcweir     {
2067cdf0e10cSrcweir         const UIElement& rElement = aWindowVector[j];
2068cdf0e10cSrcweir         uno::Reference< awt::XWindow > xWindow;
2069cdf0e10cSrcweir         uno::Reference< ui::XUIElement > xUIElement( rElement.m_xUIElement );
2070cdf0e10cSrcweir         awt::Rectangle aPosSize;
2071cdf0e10cSrcweir 
2072cdf0e10cSrcweir         if ( !lcl_checkUIElement(xUIElement,aPosSize,xWindow) )
2073cdf0e10cSrcweir             continue;
2074cdf0e10cSrcweir         if ( isHorizontalDockingArea( eDockingArea ))
2075cdf0e10cSrcweir         {
2076cdf0e10cSrcweir             if ( nCurrPos == -1 )
2077cdf0e10cSrcweir             {
2078cdf0e10cSrcweir                 nCurrPos = rElement.m_aDockedData.m_aPos.Y();
2079cdf0e10cSrcweir                 nLastPos = 0;
2080cdf0e10cSrcweir 
2081cdf0e10cSrcweir                 SingleRowColumnWindowData aRowColumnWindowData;
2082cdf0e10cSrcweir                 aRowColumnWindowData.nRowColumn = nCurrPos;
2083cdf0e10cSrcweir                 rRowColumnsWindowData.push_back( aRowColumnWindowData );
2084cdf0e10cSrcweir             }
2085cdf0e10cSrcweir 
2086cdf0e10cSrcweir             sal_Int32 nSpace( 0 );
2087cdf0e10cSrcweir             if ( rElement.m_aDockedData.m_aPos.Y() != nCurrPos )
2088cdf0e10cSrcweir             {
2089cdf0e10cSrcweir                 if ( eDockingArea == ui::DockingArea_DOCKINGAREA_TOP )
2090cdf0e10cSrcweir                     nLastRowColPixelPos += rRowColumnsWindowData[nIndex].nStaticSize;
2091cdf0e10cSrcweir                 else
2092cdf0e10cSrcweir                     nLastRowColPixelPos -= rRowColumnsWindowData[nIndex].nStaticSize;
2093cdf0e10cSrcweir                 ++nIndex;
2094cdf0e10cSrcweir                 nLastPos = 0;
2095cdf0e10cSrcweir                 nCurrPos = rElement.m_aDockedData.m_aPos.Y();
2096cdf0e10cSrcweir                 SingleRowColumnWindowData aRowColumnWindowData;
2097cdf0e10cSrcweir                 aRowColumnWindowData.nRowColumn = nCurrPos;
2098cdf0e10cSrcweir                 rRowColumnsWindowData.push_back( aRowColumnWindowData );
2099cdf0e10cSrcweir             }
2100cdf0e10cSrcweir 
2101cdf0e10cSrcweir             // Calc space before an element and store it
2102cdf0e10cSrcweir             nSpace = ( rElement.m_aDockedData.m_aPos.X() - nLastPos );
2103cdf0e10cSrcweir             if ( rElement.m_aDockedData.m_aPos.X() >= nLastPos )
2104cdf0e10cSrcweir             {
2105cdf0e10cSrcweir                 rRowColumnsWindowData[nIndex].nSpace += nSpace;
2106cdf0e10cSrcweir                 nLastPos = rElement.m_aDockedData.m_aPos.X() + aPosSize.Width;
2107cdf0e10cSrcweir             }
2108cdf0e10cSrcweir             else
2109cdf0e10cSrcweir             {
2110cdf0e10cSrcweir                 nSpace = 0;
2111cdf0e10cSrcweir                 nLastPos += aPosSize.Width;
2112cdf0e10cSrcweir             }
2113cdf0e10cSrcweir             rRowColumnsWindowData[nIndex].aRowColumnSpace.push_back( nSpace );
2114cdf0e10cSrcweir 
2115cdf0e10cSrcweir             rRowColumnsWindowData[nIndex].aRowColumnWindows.push_back( xWindow );
2116cdf0e10cSrcweir             rRowColumnsWindowData[nIndex].aUIElementNames.push_back( rElement.m_aName );
2117cdf0e10cSrcweir             rRowColumnsWindowData[nIndex].aRowColumnWindowSizes.push_back(
2118cdf0e10cSrcweir                 awt::Rectangle( rElement.m_aDockedData.m_aPos.X(),
2119cdf0e10cSrcweir                                 rElement.m_aDockedData.m_aPos.Y(),
2120cdf0e10cSrcweir                                 aPosSize.Width,
2121cdf0e10cSrcweir                                 aPosSize.Height ));
2122cdf0e10cSrcweir             if ( rRowColumnsWindowData[nIndex].nStaticSize < aPosSize.Height )
2123cdf0e10cSrcweir                 rRowColumnsWindowData[nIndex].nStaticSize = aPosSize.Height;
2124cdf0e10cSrcweir             if ( eDockingArea == ui::DockingArea_DOCKINGAREA_TOP )
2125cdf0e10cSrcweir                 rRowColumnsWindowData[nIndex].aRowColumnRect = awt::Rectangle( 0, nLastRowColPixelPos,
2126cdf0e10cSrcweir                                                                                aDockAreaRect.Width, aPosSize.Height );
2127cdf0e10cSrcweir             else
2128cdf0e10cSrcweir                 rRowColumnsWindowData[nIndex].aRowColumnRect = awt::Rectangle( 0, ( nLastRowColPixelPos - aPosSize.Height ),
2129cdf0e10cSrcweir                                                                                aDockAreaRect.Width, aPosSize.Height );
2130cdf0e10cSrcweir             rRowColumnsWindowData[nIndex].nVarSize += aPosSize.Width + nSpace;
2131cdf0e10cSrcweir         }
2132cdf0e10cSrcweir         else
2133cdf0e10cSrcweir         {
2134cdf0e10cSrcweir             if ( nCurrPos == -1 )
2135cdf0e10cSrcweir             {
2136cdf0e10cSrcweir                 nCurrPos = rElement.m_aDockedData.m_aPos.X();
2137cdf0e10cSrcweir                 nLastPos = 0;
2138cdf0e10cSrcweir 
2139cdf0e10cSrcweir                 SingleRowColumnWindowData aRowColumnWindowData;
2140cdf0e10cSrcweir                 aRowColumnWindowData.nRowColumn = nCurrPos;
2141cdf0e10cSrcweir                 rRowColumnsWindowData.push_back( aRowColumnWindowData );
2142cdf0e10cSrcweir             }
2143cdf0e10cSrcweir 
2144cdf0e10cSrcweir             sal_Int32 nSpace( 0 );
2145cdf0e10cSrcweir             if ( rElement.m_aDockedData.m_aPos.X() != nCurrPos )
2146cdf0e10cSrcweir             {
2147cdf0e10cSrcweir                 if ( eDockingArea == ui::DockingArea_DOCKINGAREA_LEFT )
2148cdf0e10cSrcweir                     nLastRowColPixelPos += rRowColumnsWindowData[nIndex].nStaticSize;
2149cdf0e10cSrcweir                 else
2150cdf0e10cSrcweir                     nLastRowColPixelPos -= rRowColumnsWindowData[nIndex].nStaticSize;
2151cdf0e10cSrcweir                 ++nIndex;
2152cdf0e10cSrcweir                 nLastPos = 0;
2153cdf0e10cSrcweir                 nCurrPos = rElement.m_aDockedData.m_aPos.X();
2154cdf0e10cSrcweir                 SingleRowColumnWindowData aRowColumnWindowData;
2155cdf0e10cSrcweir                 aRowColumnWindowData.nRowColumn = nCurrPos;
2156cdf0e10cSrcweir                 rRowColumnsWindowData.push_back( aRowColumnWindowData );
2157cdf0e10cSrcweir             }
2158cdf0e10cSrcweir 
2159cdf0e10cSrcweir             // Calc space before an element and store it
2160cdf0e10cSrcweir             nSpace = ( rElement.m_aDockedData.m_aPos.Y() - nLastPos );
2161cdf0e10cSrcweir             if ( rElement.m_aDockedData.m_aPos.Y() > nLastPos )
2162cdf0e10cSrcweir             {
2163cdf0e10cSrcweir                 rRowColumnsWindowData[nIndex].nSpace += nSpace;
2164cdf0e10cSrcweir                 nLastPos = rElement.m_aDockedData.m_aPos.Y() + aPosSize.Height;
2165cdf0e10cSrcweir             }
2166cdf0e10cSrcweir             else
2167cdf0e10cSrcweir             {
2168cdf0e10cSrcweir                 nSpace = 0;
2169cdf0e10cSrcweir                 nLastPos += aPosSize.Height;
2170cdf0e10cSrcweir             }
2171cdf0e10cSrcweir             rRowColumnsWindowData[nIndex].aRowColumnSpace.push_back( nSpace );
2172cdf0e10cSrcweir 
2173cdf0e10cSrcweir             rRowColumnsWindowData[nIndex].aRowColumnWindows.push_back( xWindow );
2174cdf0e10cSrcweir             rRowColumnsWindowData[nIndex].aUIElementNames.push_back( rElement.m_aName );
2175cdf0e10cSrcweir             rRowColumnsWindowData[nIndex].aRowColumnWindowSizes.push_back(
2176cdf0e10cSrcweir                 awt::Rectangle( rElement.m_aDockedData.m_aPos.X(),
2177cdf0e10cSrcweir                                 rElement.m_aDockedData.m_aPos.Y(),
2178cdf0e10cSrcweir                                 aPosSize.Width,
2179cdf0e10cSrcweir                                 aPosSize.Height ));
2180cdf0e10cSrcweir             if ( rRowColumnsWindowData[nIndex].nStaticSize < aPosSize.Width )
2181cdf0e10cSrcweir                 rRowColumnsWindowData[nIndex].nStaticSize = aPosSize.Width;
2182cdf0e10cSrcweir             if ( eDockingArea == ui::DockingArea_DOCKINGAREA_LEFT )
2183cdf0e10cSrcweir                 rRowColumnsWindowData[nIndex].aRowColumnRect = awt::Rectangle( nLastRowColPixelPos, 0,
2184cdf0e10cSrcweir                                                                                aPosSize.Width, aDockAreaRect.Height );
2185cdf0e10cSrcweir             else
2186cdf0e10cSrcweir                 rRowColumnsWindowData[nIndex].aRowColumnRect = awt::Rectangle( ( nLastRowColPixelPos - aPosSize.Width ), 0,
2187cdf0e10cSrcweir                                                                                  aPosSize.Width, aDockAreaRect.Height );
2188cdf0e10cSrcweir             rRowColumnsWindowData[nIndex].nVarSize += aPosSize.Height + nSpace;
2189cdf0e10cSrcweir         }
2190cdf0e10cSrcweir     }
2191cdf0e10cSrcweir }
2192cdf0e10cSrcweir 
2193cdf0e10cSrcweir void ToolbarLayoutManager::implts_getDockingAreaElementInfoOnSingleRowCol( ui::DockingArea eDockingArea, sal_Int32 nRowCol, SingleRowColumnWindowData& rRowColumnWindowData )
2194cdf0e10cSrcweir {
2195cdf0e10cSrcweir     std::vector< UIElement > aWindowVector;
2196cdf0e10cSrcweir 
2197cdf0e10cSrcweir     if (( eDockingArea < ui::DockingArea_DOCKINGAREA_TOP ) || ( eDockingArea > ui::DockingArea_DOCKINGAREA_RIGHT ))
2198cdf0e10cSrcweir         eDockingArea = ui::DockingArea_DOCKINGAREA_TOP;
2199cdf0e10cSrcweir 
2200cdf0e10cSrcweir     bool bHorzDockArea = isHorizontalDockingArea( eDockingArea );
2201cdf0e10cSrcweir 
2202cdf0e10cSrcweir     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
2203cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
2204cdf0e10cSrcweir     UIElementVector::iterator   pIter;
2205cdf0e10cSrcweir     UIElementVector::iterator   pEnd = m_aUIElements.end();
2206cdf0e10cSrcweir     for ( pIter = m_aUIElements.begin(); pIter != pEnd; pIter++ )
2207cdf0e10cSrcweir     {
2208cdf0e10cSrcweir         if ( pIter->m_aDockedData.m_nDockedArea == eDockingArea )
2209cdf0e10cSrcweir         {
2210cdf0e10cSrcweir             bool bSameRowCol = bHorzDockArea ? ( pIter->m_aDockedData.m_aPos.Y() == nRowCol ) : ( pIter->m_aDockedData.m_aPos.X() == nRowCol );
2211cdf0e10cSrcweir             uno::Reference< ui::XUIElement > xUIElement( pIter->m_xUIElement );
2212cdf0e10cSrcweir 
2213cdf0e10cSrcweir             if ( bSameRowCol && xUIElement.is() )
2214cdf0e10cSrcweir             {
2215cdf0e10cSrcweir                 uno::Reference< awt::XWindow > xWindow( xUIElement->getRealInterface(), uno::UNO_QUERY );
2216cdf0e10cSrcweir                 if ( xWindow.is() )
2217cdf0e10cSrcweir                 {
2218cdf0e10cSrcweir                     vos::OGuard aGuard( Application::GetSolarMutex() );
2219cdf0e10cSrcweir                     Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
2220cdf0e10cSrcweir                     uno::Reference< awt::XDockableWindow > xDockWindow( xWindow, uno::UNO_QUERY );
2221cdf0e10cSrcweir                     if ( pWindow && pIter->m_bVisible && xDockWindow.is() && !pIter->m_bFloating )
2222cdf0e10cSrcweir                         aWindowVector.push_back( *pIter ); // docked windows
2223cdf0e10cSrcweir                 }
2224cdf0e10cSrcweir             }
2225cdf0e10cSrcweir         }
2226cdf0e10cSrcweir     }
2227cdf0e10cSrcweir     aReadLock.unlock();
2228cdf0e10cSrcweir     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
2229cdf0e10cSrcweir 
2230cdf0e10cSrcweir     // Initialize structure
2231cdf0e10cSrcweir     rRowColumnWindowData.aUIElementNames.clear();
2232cdf0e10cSrcweir     rRowColumnWindowData.aRowColumnWindows.clear();
2233cdf0e10cSrcweir     rRowColumnWindowData.aRowColumnWindowSizes.clear();
2234cdf0e10cSrcweir     rRowColumnWindowData.aRowColumnSpace.clear();
2235cdf0e10cSrcweir     rRowColumnWindowData.nVarSize = 0;
2236cdf0e10cSrcweir     rRowColumnWindowData.nStaticSize = 0;
2237cdf0e10cSrcweir     rRowColumnWindowData.nSpace = 0;
2238cdf0e10cSrcweir     rRowColumnWindowData.nRowColumn = nRowCol;
2239cdf0e10cSrcweir 
2240cdf0e10cSrcweir     // Collect data from windows that are on the same row/column
2241cdf0e10cSrcweir     sal_Int32 j;
2242cdf0e10cSrcweir     sal_Int32 nLastPos( 0 );
2243cdf0e10cSrcweir 
2244cdf0e10cSrcweir     const sal_uInt32 nCount = aWindowVector.size();
2245cdf0e10cSrcweir     for ( j = 0; j < sal_Int32( nCount); j++ )
2246cdf0e10cSrcweir     {
2247cdf0e10cSrcweir         const UIElement& rElement = aWindowVector[j];
2248cdf0e10cSrcweir         uno::Reference< awt::XWindow > xWindow;
2249cdf0e10cSrcweir         uno::Reference< ui::XUIElement > xUIElement( rElement.m_xUIElement );
2250cdf0e10cSrcweir         awt::Rectangle aPosSize;
2251cdf0e10cSrcweir         if ( !lcl_checkUIElement(xUIElement,aPosSize,xWindow) )
2252cdf0e10cSrcweir             continue;
2253cdf0e10cSrcweir 
2254cdf0e10cSrcweir         sal_Int32 nSpace;
2255cdf0e10cSrcweir         if ( isHorizontalDockingArea( eDockingArea ))
2256cdf0e10cSrcweir         {
2257cdf0e10cSrcweir             nSpace = ( rElement.m_aDockedData.m_aPos.X() - nLastPos );
2258cdf0e10cSrcweir 
2259cdf0e10cSrcweir             // Calc space before an element and store it
2260cdf0e10cSrcweir             if ( rElement.m_aDockedData.m_aPos.X() > nLastPos )
2261cdf0e10cSrcweir                 rRowColumnWindowData.nSpace += nSpace;
2262cdf0e10cSrcweir             else
2263cdf0e10cSrcweir                 nSpace = 0;
2264cdf0e10cSrcweir 
2265cdf0e10cSrcweir             nLastPos = rElement.m_aDockedData.m_aPos.X() + aPosSize.Width;
2266cdf0e10cSrcweir 
2267cdf0e10cSrcweir 
2268cdf0e10cSrcweir             rRowColumnWindowData.aRowColumnWindowSizes.push_back(
2269cdf0e10cSrcweir                 awt::Rectangle( rElement.m_aDockedData.m_aPos.X(), rElement.m_aDockedData.m_aPos.Y(),
2270cdf0e10cSrcweir                                 aPosSize.Width, aPosSize.Height ));
2271cdf0e10cSrcweir             if ( rRowColumnWindowData.nStaticSize < aPosSize.Height )
2272cdf0e10cSrcweir                 rRowColumnWindowData.nStaticSize = aPosSize.Height;
2273cdf0e10cSrcweir             rRowColumnWindowData.nVarSize += aPosSize.Width;
2274cdf0e10cSrcweir         }
2275cdf0e10cSrcweir         else
2276cdf0e10cSrcweir         {
2277cdf0e10cSrcweir             // Calc space before an element and store it
2278cdf0e10cSrcweir             nSpace = ( rElement.m_aDockedData.m_aPos.Y() - nLastPos );
2279cdf0e10cSrcweir             if ( rElement.m_aDockedData.m_aPos.Y() > nLastPos )
2280cdf0e10cSrcweir                 rRowColumnWindowData.nSpace += nSpace;
2281cdf0e10cSrcweir             else
2282cdf0e10cSrcweir                 nSpace = 0;
2283cdf0e10cSrcweir 
2284cdf0e10cSrcweir             nLastPos = rElement.m_aDockedData.m_aPos.Y() + aPosSize.Height;
2285cdf0e10cSrcweir 
2286cdf0e10cSrcweir             rRowColumnWindowData.aRowColumnWindowSizes.push_back(
2287cdf0e10cSrcweir                 awt::Rectangle( rElement.m_aDockedData.m_aPos.X(), rElement.m_aDockedData.m_aPos.Y(),
2288cdf0e10cSrcweir                                 aPosSize.Width, aPosSize.Height ));
2289cdf0e10cSrcweir             if ( rRowColumnWindowData.nStaticSize < aPosSize.Width )
2290cdf0e10cSrcweir                 rRowColumnWindowData.nStaticSize = aPosSize.Width;
2291cdf0e10cSrcweir             rRowColumnWindowData.nVarSize += aPosSize.Height;
2292cdf0e10cSrcweir         }
2293cdf0e10cSrcweir 
2294cdf0e10cSrcweir         rRowColumnWindowData.aUIElementNames.push_back( rElement.m_aName );
2295cdf0e10cSrcweir         rRowColumnWindowData.aRowColumnWindows.push_back( xWindow );
2296cdf0e10cSrcweir         rRowColumnWindowData.aRowColumnSpace.push_back( nSpace );
2297cdf0e10cSrcweir         rRowColumnWindowData.nVarSize += nSpace;
2298cdf0e10cSrcweir     }
2299cdf0e10cSrcweir }
2300cdf0e10cSrcweir 
2301cdf0e10cSrcweir ::Rectangle ToolbarLayoutManager::implts_getWindowRectFromRowColumn(
2302cdf0e10cSrcweir     ui::DockingArea DockingArea,
2303cdf0e10cSrcweir     const SingleRowColumnWindowData& rRowColumnWindowData,
2304cdf0e10cSrcweir     const ::Point& rMousePos,
2305cdf0e10cSrcweir     const rtl::OUString& rExcludeElementName )
2306cdf0e10cSrcweir {
2307cdf0e10cSrcweir     ::Rectangle aWinRect;
2308cdf0e10cSrcweir 
2309cdf0e10cSrcweir     if (( DockingArea < ui::DockingArea_DOCKINGAREA_TOP ) || ( DockingArea > ui::DockingArea_DOCKINGAREA_RIGHT ))
2310cdf0e10cSrcweir         DockingArea = ui::DockingArea_DOCKINGAREA_TOP;
2311cdf0e10cSrcweir 
2312cdf0e10cSrcweir     if ( rRowColumnWindowData.aRowColumnWindows.empty() )
2313cdf0e10cSrcweir         return aWinRect;
2314cdf0e10cSrcweir     else
2315cdf0e10cSrcweir     {
2316cdf0e10cSrcweir         ReadGuard aReadLock( m_aLock );
2317cdf0e10cSrcweir         Window* pContainerWindow( VCLUnoHelper::GetWindow( m_xContainerWindow ));
2318cdf0e10cSrcweir         Window* pDockingAreaWindow( VCLUnoHelper::GetWindow( m_xDockAreaWindows[DockingArea] ));
2319cdf0e10cSrcweir         aReadLock.unlock();
2320cdf0e10cSrcweir 
2321cdf0e10cSrcweir         // Calc correct position of the column/row rectangle to be able to compare it with mouse pos/tracking rect
2322cdf0e10cSrcweir         vos::OGuard aGuard( Application::GetSolarMutex() );
2323cdf0e10cSrcweir 
2324cdf0e10cSrcweir         // Retrieve output size from container Window
2325cdf0e10cSrcweir         if ( pDockingAreaWindow && pContainerWindow )
2326cdf0e10cSrcweir         {
2327cdf0e10cSrcweir             const sal_uInt32 nCount = rRowColumnWindowData.aRowColumnWindows.size();
2328cdf0e10cSrcweir             for ( sal_uInt32 i = 0; i < nCount; i++ )
2329cdf0e10cSrcweir             {
2330cdf0e10cSrcweir                 awt::Rectangle aWindowRect = rRowColumnWindowData.aRowColumnWindows[i]->getPosSize();
2331cdf0e10cSrcweir                 ::Rectangle aRect( aWindowRect.X, aWindowRect.Y, aWindowRect.X+aWindowRect.Width, aWindowRect.Y+aWindowRect.Height );
2332cdf0e10cSrcweir                 aRect.SetPos( pContainerWindow->ScreenToOutputPixel( pDockingAreaWindow->OutputToScreenPixel( aRect.TopLeft() )));
2333cdf0e10cSrcweir                 if ( aRect.IsInside( rMousePos ))
2334cdf0e10cSrcweir                 {
2335cdf0e10cSrcweir                     // Check if we have found the excluded element. If yes, we have to provide an empty rectangle.
2336cdf0e10cSrcweir                     // We prevent that a toolbar cannot be moved when the mouse pointer is inside its own rectangle!
2337cdf0e10cSrcweir                     if ( rExcludeElementName != rRowColumnWindowData.aUIElementNames[i] )
2338cdf0e10cSrcweir                         return aRect;
2339cdf0e10cSrcweir                     else
2340cdf0e10cSrcweir                         break;
2341cdf0e10cSrcweir                 }
2342cdf0e10cSrcweir             }
2343cdf0e10cSrcweir         }
2344cdf0e10cSrcweir     }
2345cdf0e10cSrcweir 
2346cdf0e10cSrcweir     return aWinRect;
2347cdf0e10cSrcweir }
2348cdf0e10cSrcweir 
2349cdf0e10cSrcweir ::Rectangle ToolbarLayoutManager::implts_determineFrontDockingRect(
2350cdf0e10cSrcweir     ui::DockingArea        eDockingArea,
2351cdf0e10cSrcweir     sal_Int32              nRowCol,
2352cdf0e10cSrcweir     const ::Rectangle&     rDockedElementRect,
2353cdf0e10cSrcweir     const ::rtl::OUString& rMovedElementName,
2354cdf0e10cSrcweir     const ::Rectangle&     rMovedElementRect )
2355cdf0e10cSrcweir {
2356cdf0e10cSrcweir     SingleRowColumnWindowData aRowColumnWindowData;
2357cdf0e10cSrcweir 
2358cdf0e10cSrcweir     sal_Bool bHorzDockArea( isHorizontalDockingArea( eDockingArea ));
2359cdf0e10cSrcweir     implts_getDockingAreaElementInfoOnSingleRowCol( eDockingArea, nRowCol, aRowColumnWindowData );
2360cdf0e10cSrcweir     if ( aRowColumnWindowData.aRowColumnWindows.empty() )
2361cdf0e10cSrcweir         return rMovedElementRect;
2362cdf0e10cSrcweir     else
2363cdf0e10cSrcweir     {
2364cdf0e10cSrcweir         sal_Int32 nSpace( 0 );
2365cdf0e10cSrcweir         ::Rectangle aFrontDockingRect( rMovedElementRect );
2366cdf0e10cSrcweir         const sal_uInt32 nCount = aRowColumnWindowData.aRowColumnWindows.size();
2367cdf0e10cSrcweir         for ( sal_uInt32 i = 0; i < nCount; i++ )
2368cdf0e10cSrcweir         {
2369cdf0e10cSrcweir             if ( bHorzDockArea )
2370cdf0e10cSrcweir             {
2371cdf0e10cSrcweir                 if ( aRowColumnWindowData.aRowColumnWindowSizes[i].X >= rDockedElementRect.Left() )
2372cdf0e10cSrcweir                 {
2373cdf0e10cSrcweir                     nSpace += aRowColumnWindowData.aRowColumnSpace[i];
2374cdf0e10cSrcweir                     break;
2375cdf0e10cSrcweir                 }
2376cdf0e10cSrcweir                 else if ( aRowColumnWindowData.aUIElementNames[i] == rMovedElementName )
2377cdf0e10cSrcweir                     nSpace += aRowColumnWindowData.aRowColumnWindowSizes[i].Width +
2378cdf0e10cSrcweir                               aRowColumnWindowData.aRowColumnSpace[i];
2379cdf0e10cSrcweir                 else
2380cdf0e10cSrcweir                     nSpace = 0;
2381cdf0e10cSrcweir             }
2382cdf0e10cSrcweir             else
2383cdf0e10cSrcweir             {
2384cdf0e10cSrcweir                 if ( aRowColumnWindowData.aRowColumnWindowSizes[i].Y >= rDockedElementRect.Top() )
2385cdf0e10cSrcweir                 {
2386cdf0e10cSrcweir                     nSpace += aRowColumnWindowData.aRowColumnSpace[i];
2387cdf0e10cSrcweir                     break;
2388cdf0e10cSrcweir                 }
2389cdf0e10cSrcweir                 else if ( aRowColumnWindowData.aUIElementNames[i] == rMovedElementName )
2390cdf0e10cSrcweir                     nSpace += aRowColumnWindowData.aRowColumnWindowSizes[i].Height +
2391cdf0e10cSrcweir                               aRowColumnWindowData.aRowColumnSpace[i];
2392cdf0e10cSrcweir                 else
2393cdf0e10cSrcweir                     nSpace = 0;
2394cdf0e10cSrcweir             }
2395cdf0e10cSrcweir         }
2396cdf0e10cSrcweir 
2397cdf0e10cSrcweir         if ( nSpace > 0 )
2398cdf0e10cSrcweir         {
2399cdf0e10cSrcweir             sal_Int32 nMove = std::min( nSpace, static_cast<sal_Int32>(aFrontDockingRect.getWidth()) );
2400cdf0e10cSrcweir             if ( bHorzDockArea )
2401cdf0e10cSrcweir                 aFrontDockingRect.Move( -nMove, 0 );
2402cdf0e10cSrcweir             else
2403cdf0e10cSrcweir                 aFrontDockingRect.Move( 0, -nMove );
2404cdf0e10cSrcweir         }
2405cdf0e10cSrcweir 
2406cdf0e10cSrcweir         return aFrontDockingRect;
2407cdf0e10cSrcweir     }
2408cdf0e10cSrcweir }
2409cdf0e10cSrcweir 
2410cdf0e10cSrcweir void ToolbarLayoutManager::implts_findNextDockingPos( ui::DockingArea DockingArea, const ::Size& aUIElementSize, ::Point& rVirtualPos, ::Point& rPixelPos )
2411cdf0e10cSrcweir {
2412cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
2413cdf0e10cSrcweir     uno::Reference< awt::XWindow > xDockingWindow( m_xDockAreaWindows[DockingArea] );
2414cdf0e10cSrcweir     ::Size                         aDockingWinSize;
2415cdf0e10cSrcweir     Window*                        pDockingWindow( 0 );
2416cdf0e10cSrcweir     aReadLock.unlock();
2417cdf0e10cSrcweir 
2418cdf0e10cSrcweir     if (( DockingArea < ui::DockingArea_DOCKINGAREA_TOP ) || ( DockingArea > ui::DockingArea_DOCKINGAREA_RIGHT ))
2419cdf0e10cSrcweir         DockingArea = ui::DockingArea_DOCKINGAREA_TOP;
2420cdf0e10cSrcweir 
2421cdf0e10cSrcweir     {
2422cdf0e10cSrcweir         // Retrieve output size from container Window
2423cdf0e10cSrcweir         vos::OGuard aGuard( Application::GetSolarMutex() );
2424cdf0e10cSrcweir         pDockingWindow  = VCLUnoHelper::GetWindow( xDockingWindow );
2425cdf0e10cSrcweir         if ( pDockingWindow )
2426cdf0e10cSrcweir             aDockingWinSize = pDockingWindow->GetOutputSizePixel();
2427cdf0e10cSrcweir     }
2428cdf0e10cSrcweir 
2429cdf0e10cSrcweir     sal_Int32 nFreeRowColPixelPos( 0 );
2430cdf0e10cSrcweir     sal_Int32 nMaxSpace( 0 );
2431cdf0e10cSrcweir     sal_Int32 nNeededSpace( 0 );
2432cdf0e10cSrcweir     sal_Int32 nTopDockingAreaSize( 0 );
2433cdf0e10cSrcweir 
2434cdf0e10cSrcweir     if ( isHorizontalDockingArea( DockingArea ))
2435cdf0e10cSrcweir     {
2436cdf0e10cSrcweir         nMaxSpace    = aDockingWinSize.Width();
2437cdf0e10cSrcweir         nNeededSpace = aUIElementSize.Width();
2438cdf0e10cSrcweir     }
2439cdf0e10cSrcweir     else
2440cdf0e10cSrcweir     {
2441cdf0e10cSrcweir         nMaxSpace           = aDockingWinSize.Height();
2442cdf0e10cSrcweir         nNeededSpace        = aUIElementSize.Height();
2443cdf0e10cSrcweir         nTopDockingAreaSize = implts_getTopBottomDockingAreaSizes().Width();
2444cdf0e10cSrcweir     }
2445cdf0e10cSrcweir 
2446cdf0e10cSrcweir     std::vector< SingleRowColumnWindowData > aRowColumnsWindowData;
2447cdf0e10cSrcweir 
2448cdf0e10cSrcweir     implts_getDockingAreaElementInfos( DockingArea, aRowColumnsWindowData );
2449cdf0e10cSrcweir     sal_Int32 nPixelPos( 0 );
2450cdf0e10cSrcweir     const sal_uInt32 nCount = aRowColumnsWindowData.size();
2451cdf0e10cSrcweir     for ( sal_uInt32 i = 0; i < nCount; i++ )
2452cdf0e10cSrcweir     {
2453cdf0e10cSrcweir         SingleRowColumnWindowData& rRowColumnWindowData = aRowColumnsWindowData[i];
2454cdf0e10cSrcweir 
2455cdf0e10cSrcweir         if (( DockingArea == ui::DockingArea_DOCKINGAREA_BOTTOM ) ||
2456cdf0e10cSrcweir             ( DockingArea == ui::DockingArea_DOCKINGAREA_RIGHT  ))
2457cdf0e10cSrcweir             nPixelPos += rRowColumnWindowData.nStaticSize;
2458cdf0e10cSrcweir 
2459cdf0e10cSrcweir         if ((( nMaxSpace - rRowColumnWindowData.nVarSize ) >= nNeededSpace ) ||
2460cdf0e10cSrcweir             ( rRowColumnWindowData.nSpace >= nNeededSpace ))
2461cdf0e10cSrcweir         {
2462cdf0e10cSrcweir             // Check current row where we can find the needed space
2463cdf0e10cSrcweir             sal_Int32 nCurrPos( 0 );
2464cdf0e10cSrcweir             const sal_uInt32 nWindowSizesCount = rRowColumnWindowData.aRowColumnWindowSizes.size();
2465cdf0e10cSrcweir             for ( sal_uInt32 j = 0; j < nWindowSizesCount; j++ )
2466cdf0e10cSrcweir             {
2467cdf0e10cSrcweir                 awt::Rectangle rRect  = rRowColumnWindowData.aRowColumnWindowSizes[j];
2468cdf0e10cSrcweir                 sal_Int32&     rSpace = rRowColumnWindowData.aRowColumnSpace[j];
2469cdf0e10cSrcweir                 if ( isHorizontalDockingArea( DockingArea ))
2470cdf0e10cSrcweir                 {
2471cdf0e10cSrcweir                     if ( rSpace >= nNeededSpace )
2472cdf0e10cSrcweir                     {
2473cdf0e10cSrcweir                         rVirtualPos = ::Point( nCurrPos, rRowColumnWindowData.nRowColumn );
2474cdf0e10cSrcweir                         if ( DockingArea == ui::DockingArea_DOCKINGAREA_TOP )
2475cdf0e10cSrcweir                             rPixelPos   = ::Point( nCurrPos, nPixelPos );
2476cdf0e10cSrcweir                         else
2477cdf0e10cSrcweir                             rPixelPos   = ::Point( nCurrPos, aDockingWinSize.Height() - nPixelPos );
2478cdf0e10cSrcweir                         return;
2479cdf0e10cSrcweir                     }
2480cdf0e10cSrcweir                     nCurrPos = rRect.X + rRect.Width;
2481cdf0e10cSrcweir                 }
2482cdf0e10cSrcweir                 else
2483cdf0e10cSrcweir                 {
2484cdf0e10cSrcweir                     if ( rSpace >= nNeededSpace )
2485cdf0e10cSrcweir                     {
2486cdf0e10cSrcweir                         rVirtualPos = ::Point( rRowColumnWindowData.nRowColumn, nCurrPos );
2487cdf0e10cSrcweir                         if ( DockingArea == ui::DockingArea_DOCKINGAREA_LEFT )
2488cdf0e10cSrcweir                             rPixelPos   = ::Point( nPixelPos, nTopDockingAreaSize + nCurrPos );
2489cdf0e10cSrcweir                         else
2490cdf0e10cSrcweir                             rPixelPos   = ::Point( aDockingWinSize.Width() - nPixelPos , nTopDockingAreaSize + nCurrPos );
2491cdf0e10cSrcweir                         return;
2492cdf0e10cSrcweir                     }
2493cdf0e10cSrcweir                     nCurrPos = rRect.Y + rRect.Height;
2494cdf0e10cSrcweir                 }
2495cdf0e10cSrcweir             }
2496cdf0e10cSrcweir 
2497cdf0e10cSrcweir             if (( nCurrPos + nNeededSpace ) <= nMaxSpace )
2498cdf0e10cSrcweir             {
2499cdf0e10cSrcweir                 if ( isHorizontalDockingArea( DockingArea ))
2500cdf0e10cSrcweir                 {
2501cdf0e10cSrcweir                     rVirtualPos = ::Point( nCurrPos, rRowColumnWindowData.nRowColumn );
2502cdf0e10cSrcweir                     if ( DockingArea == ui::DockingArea_DOCKINGAREA_TOP )
2503cdf0e10cSrcweir                         rPixelPos   = ::Point( nCurrPos, nPixelPos );
2504cdf0e10cSrcweir                     else
2505cdf0e10cSrcweir                         rPixelPos   = ::Point( nCurrPos, aDockingWinSize.Height() - nPixelPos );
2506cdf0e10cSrcweir                     return;
2507cdf0e10cSrcweir                 }
2508cdf0e10cSrcweir                 else
2509cdf0e10cSrcweir                 {
2510cdf0e10cSrcweir                     rVirtualPos = ::Point( rRowColumnWindowData.nRowColumn, nCurrPos );
2511cdf0e10cSrcweir                     if ( DockingArea == ui::DockingArea_DOCKINGAREA_LEFT )
2512cdf0e10cSrcweir                         rPixelPos   = ::Point( nPixelPos, nTopDockingAreaSize + nCurrPos );
2513cdf0e10cSrcweir                     else
2514cdf0e10cSrcweir                         rPixelPos   = ::Point( aDockingWinSize.Width() - nPixelPos , nTopDockingAreaSize + nCurrPos );
2515cdf0e10cSrcweir                     return;
2516cdf0e10cSrcweir                 }
2517cdf0e10cSrcweir             }
2518cdf0e10cSrcweir         }
2519cdf0e10cSrcweir 
2520cdf0e10cSrcweir         if (( DockingArea == ui::DockingArea_DOCKINGAREA_TOP ) || ( DockingArea == ui::DockingArea_DOCKINGAREA_LEFT  ))
2521cdf0e10cSrcweir             nPixelPos += rRowColumnWindowData.nStaticSize;
2522cdf0e10cSrcweir     }
2523cdf0e10cSrcweir 
2524cdf0e10cSrcweir     sal_Int32 nNextFreeRowCol( 0 );
2525cdf0e10cSrcweir     sal_Int32 nRowColumnsCount = aRowColumnsWindowData.size();
2526cdf0e10cSrcweir     if ( nRowColumnsCount > 0 )
2527cdf0e10cSrcweir         nNextFreeRowCol = aRowColumnsWindowData[nRowColumnsCount-1].nRowColumn+1;
2528cdf0e10cSrcweir     else
2529cdf0e10cSrcweir         nNextFreeRowCol = 0;
2530cdf0e10cSrcweir 
2531cdf0e10cSrcweir     if ( nNextFreeRowCol == 0 )
2532cdf0e10cSrcweir     {
2533cdf0e10cSrcweir         if ( DockingArea == ui::DockingArea_DOCKINGAREA_BOTTOM )
2534cdf0e10cSrcweir             nFreeRowColPixelPos = aDockingWinSize.Height() - aUIElementSize.Height();
2535cdf0e10cSrcweir         else if ( DockingArea == ui::DockingArea_DOCKINGAREA_RIGHT  )
2536cdf0e10cSrcweir             nFreeRowColPixelPos = aDockingWinSize.Width() - aUIElementSize.Width();
2537cdf0e10cSrcweir     }
2538cdf0e10cSrcweir 
2539cdf0e10cSrcweir     if ( isHorizontalDockingArea( DockingArea ))
2540cdf0e10cSrcweir     {
2541cdf0e10cSrcweir         rVirtualPos = ::Point( 0, nNextFreeRowCol );
2542cdf0e10cSrcweir         if ( DockingArea == ui::DockingArea_DOCKINGAREA_TOP )
2543cdf0e10cSrcweir             rPixelPos = ::Point( 0, nFreeRowColPixelPos );
2544cdf0e10cSrcweir         else
2545cdf0e10cSrcweir             rPixelPos = ::Point( 0, aDockingWinSize.Height() - nFreeRowColPixelPos );
2546cdf0e10cSrcweir     }
2547cdf0e10cSrcweir     else
2548cdf0e10cSrcweir     {
2549cdf0e10cSrcweir         rVirtualPos = ::Point( nNextFreeRowCol, 0 );
2550cdf0e10cSrcweir         rPixelPos   = ::Point( aDockingWinSize.Width() - nFreeRowColPixelPos, 0 );
2551cdf0e10cSrcweir     }
2552cdf0e10cSrcweir }
2553cdf0e10cSrcweir 
2554cdf0e10cSrcweir void ToolbarLayoutManager::implts_calcWindowPosSizeOnSingleRowColumn(
2555cdf0e10cSrcweir     sal_Int32 nDockingArea,
2556cdf0e10cSrcweir     sal_Int32 nOffset,
2557cdf0e10cSrcweir     SingleRowColumnWindowData& rRowColumnWindowData,
2558cdf0e10cSrcweir     const ::Size& rContainerSize )
2559cdf0e10cSrcweir {
2560cdf0e10cSrcweir     sal_Int32 nDiff(0);
2561cdf0e10cSrcweir     sal_Int32 nRCSpace( rRowColumnWindowData.nSpace );
2562cdf0e10cSrcweir     sal_Int32 nTopDockingAreaSize(0);
2563cdf0e10cSrcweir     sal_Int32 nBottomDockingAreaSize(0);
2564cdf0e10cSrcweir     sal_Int32 nContainerClientSize(0);
2565cdf0e10cSrcweir 
2566cdf0e10cSrcweir     if ( rRowColumnWindowData.aRowColumnWindows.empty() )
2567cdf0e10cSrcweir         return;
2568cdf0e10cSrcweir 
2569cdf0e10cSrcweir     if ( isHorizontalDockingArea( nDockingArea ))
2570cdf0e10cSrcweir     {
2571cdf0e10cSrcweir         nContainerClientSize = rContainerSize.Width();
2572cdf0e10cSrcweir         nDiff = nContainerClientSize - rRowColumnWindowData.nVarSize;
2573cdf0e10cSrcweir     }
2574cdf0e10cSrcweir     else
2575cdf0e10cSrcweir     {
2576cdf0e10cSrcweir         nTopDockingAreaSize    = implts_getTopBottomDockingAreaSizes().Width();
2577cdf0e10cSrcweir         nBottomDockingAreaSize = implts_getTopBottomDockingAreaSizes().Height();
2578cdf0e10cSrcweir         nContainerClientSize   = ( rContainerSize.Height() - nTopDockingAreaSize - nBottomDockingAreaSize );
2579cdf0e10cSrcweir         nDiff = nContainerClientSize - rRowColumnWindowData.nVarSize;
2580cdf0e10cSrcweir     }
2581cdf0e10cSrcweir 
2582cdf0e10cSrcweir     const sal_uInt32 nCount = rRowColumnWindowData.aRowColumnWindowSizes.size();
2583cdf0e10cSrcweir     if (( nDiff < 0 ) && ( nRCSpace > 0 ))
2584cdf0e10cSrcweir     {
2585cdf0e10cSrcweir         // First we try to reduce the size of blank space before/behind docked windows
2586cdf0e10cSrcweir         sal_Int32 i = nCount - 1;
2587cdf0e10cSrcweir         while ( i >= 0 )
2588cdf0e10cSrcweir         {
2589cdf0e10cSrcweir             sal_Int32 nSpace = rRowColumnWindowData.aRowColumnSpace[i];
2590cdf0e10cSrcweir             if ( nSpace >= -nDiff )
2591cdf0e10cSrcweir             {
2592cdf0e10cSrcweir                 if ( isHorizontalDockingArea( nDockingArea ))
2593cdf0e10cSrcweir                 {
2594cdf0e10cSrcweir                     // Try to move this and all user elements behind with the calculated difference
2595cdf0e10cSrcweir                     for ( sal_uInt32 j = i; j < nCount ; j++ )
2596cdf0e10cSrcweir                         rRowColumnWindowData.aRowColumnWindowSizes[j].X += nDiff;
2597cdf0e10cSrcweir                 }
2598cdf0e10cSrcweir                 else
2599cdf0e10cSrcweir                 {
2600cdf0e10cSrcweir                     // Try to move this and all user elements behind with the calculated difference
2601cdf0e10cSrcweir                     for ( sal_uInt32 j = i; j < nCount ; j++ )
2602cdf0e10cSrcweir                         rRowColumnWindowData.aRowColumnWindowSizes[j].Y += nDiff;
2603cdf0e10cSrcweir                 }
2604cdf0e10cSrcweir                 nDiff = 0;
2605cdf0e10cSrcweir 
2606cdf0e10cSrcweir                 break;
2607cdf0e10cSrcweir             }
2608cdf0e10cSrcweir             else if ( nSpace > 0 )
2609cdf0e10cSrcweir             {
2610cdf0e10cSrcweir                 if ( isHorizontalDockingArea( nDockingArea ))
2611cdf0e10cSrcweir                 {
2612cdf0e10cSrcweir                     // Try to move this and all user elements behind with the calculated difference
2613cdf0e10cSrcweir                     for ( sal_uInt32 j = i; j < nCount; j++ )
2614cdf0e10cSrcweir                         rRowColumnWindowData.aRowColumnWindowSizes[j].X -= nSpace;
2615cdf0e10cSrcweir                 }
2616cdf0e10cSrcweir                 else
2617cdf0e10cSrcweir                 {
2618cdf0e10cSrcweir                     // Try to move this and all user elements behind with the calculated difference
2619cdf0e10cSrcweir                     for ( sal_uInt32 j = i; j < nCount; j++ )
2620cdf0e10cSrcweir                         rRowColumnWindowData.aRowColumnWindowSizes[j].Y -= nSpace;
2621cdf0e10cSrcweir                 }
2622cdf0e10cSrcweir                 nDiff += nSpace;
2623cdf0e10cSrcweir             }
2624cdf0e10cSrcweir             --i;
2625cdf0e10cSrcweir         }
2626cdf0e10cSrcweir     }
2627cdf0e10cSrcweir 
2628cdf0e10cSrcweir     // Check if we have to reduce further
2629cdf0e10cSrcweir     if ( nDiff < 0 )
2630cdf0e10cSrcweir     {
2631cdf0e10cSrcweir         // Now we have to reduce the size of certain docked windows
2632cdf0e10cSrcweir         sal_Int32 i = sal_Int32( nCount - 1 );
2633cdf0e10cSrcweir         while ( i >= 0 )
2634cdf0e10cSrcweir         {
2635cdf0e10cSrcweir             awt::Rectangle& rWinRect = rRowColumnWindowData.aRowColumnWindowSizes[i];
2636cdf0e10cSrcweir             ::Size          aMinSize;
2637cdf0e10cSrcweir 
2638cdf0e10cSrcweir             vos::OGuard aGuard( Application::GetSolarMutex() );
2639cdf0e10cSrcweir             {
2640cdf0e10cSrcweir                 uno::Reference< awt::XWindow > xWindow = rRowColumnWindowData.aRowColumnWindows[i];
2641cdf0e10cSrcweir                 Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
2642cdf0e10cSrcweir                 if ( pWindow && pWindow->GetType() == WINDOW_TOOLBOX )
2643cdf0e10cSrcweir                     aMinSize = ((ToolBox *)pWindow)->CalcMinimumWindowSizePixel();
2644cdf0e10cSrcweir             }
2645cdf0e10cSrcweir 
2646cdf0e10cSrcweir             if (( aMinSize.Width() > 0 ) && ( aMinSize.Height() > 0 ))
2647cdf0e10cSrcweir             {
2648cdf0e10cSrcweir                 if ( isHorizontalDockingArea( nDockingArea ))
2649cdf0e10cSrcweir                 {
2650cdf0e10cSrcweir                     sal_Int32 nMaxReducation = ( rWinRect.Width - aMinSize.Width() );
2651cdf0e10cSrcweir                     if ( nMaxReducation >= -nDiff )
2652cdf0e10cSrcweir                     {
2653cdf0e10cSrcweir                         rWinRect.Width = rWinRect.Width + nDiff;
2654cdf0e10cSrcweir                         nDiff = 0;
2655cdf0e10cSrcweir                     }
2656cdf0e10cSrcweir                     else
2657cdf0e10cSrcweir                     {
2658cdf0e10cSrcweir                         rWinRect.Width = aMinSize.Width();
2659cdf0e10cSrcweir                         nDiff += nMaxReducation;
2660cdf0e10cSrcweir                     }
2661cdf0e10cSrcweir 
2662cdf0e10cSrcweir                     // Try to move this and all user elements behind with the calculated difference
2663cdf0e10cSrcweir                     for ( sal_uInt32 j = i; j < nCount; j++ )
2664cdf0e10cSrcweir                         rRowColumnWindowData.aRowColumnWindowSizes[j].X += nDiff;
2665cdf0e10cSrcweir                 }
2666cdf0e10cSrcweir                 else
2667cdf0e10cSrcweir                 {
2668cdf0e10cSrcweir                     sal_Int32 nMaxReducation = ( rWinRect.Height - aMinSize.Height() );
2669cdf0e10cSrcweir                     if ( nMaxReducation >= -nDiff )
2670cdf0e10cSrcweir                     {
2671cdf0e10cSrcweir                         rWinRect.Height = rWinRect.Height + nDiff;
2672cdf0e10cSrcweir                         nDiff = 0;
2673cdf0e10cSrcweir                     }
2674cdf0e10cSrcweir                     else
2675cdf0e10cSrcweir                     {
2676cdf0e10cSrcweir                         rWinRect.Height = aMinSize.Height();
2677cdf0e10cSrcweir                         nDiff += nMaxReducation;
2678cdf0e10cSrcweir                     }
2679cdf0e10cSrcweir 
2680cdf0e10cSrcweir                     // Try to move this and all user elements behind with the calculated difference
2681cdf0e10cSrcweir                     for ( sal_uInt32 j = i; j < nCount; j++ )
2682cdf0e10cSrcweir                         rRowColumnWindowData.aRowColumnWindowSizes[j].Y += nDiff;
2683cdf0e10cSrcweir                 }
2684cdf0e10cSrcweir             }
2685cdf0e10cSrcweir 
2686cdf0e10cSrcweir             if ( nDiff >= 0 )
2687cdf0e10cSrcweir                 break;
2688cdf0e10cSrcweir 
2689cdf0e10cSrcweir             --i;
2690cdf0e10cSrcweir         }
2691cdf0e10cSrcweir     }
2692cdf0e10cSrcweir 
2693cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
2694cdf0e10cSrcweir     Window* pDockAreaWindow = VCLUnoHelper::GetWindow( m_xDockAreaWindows[nDockingArea] );
2695cdf0e10cSrcweir     aReadLock.unlock();
2696cdf0e10cSrcweir 
2697cdf0e10cSrcweir     sal_Int32 nCurrPos( 0 );
2698cdf0e10cSrcweir 
2699cdf0e10cSrcweir     vos::OGuard aGuard( Application::GetSolarMutex() );
2700cdf0e10cSrcweir     for ( sal_uInt32 i = 0; i < nCount; i++ )
2701cdf0e10cSrcweir     {
2702cdf0e10cSrcweir         uno::Reference< awt::XWindow > xWindow = rRowColumnWindowData.aRowColumnWindows[i];
2703cdf0e10cSrcweir         Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
2704cdf0e10cSrcweir         Window* pOldParentWindow = pWindow->GetParent();
2705cdf0e10cSrcweir 
2706cdf0e10cSrcweir         if ( pDockAreaWindow != pOldParentWindow )
2707cdf0e10cSrcweir             pWindow->SetParent( pDockAreaWindow );
2708cdf0e10cSrcweir 
2709cdf0e10cSrcweir         awt::Rectangle aWinRect = rRowColumnWindowData.aRowColumnWindowSizes[i];
2710cdf0e10cSrcweir         if ( isHorizontalDockingArea( nDockingArea ))
2711cdf0e10cSrcweir         {
2712cdf0e10cSrcweir             if ( aWinRect.X < nCurrPos )
2713cdf0e10cSrcweir                 aWinRect.X = nCurrPos;
2714cdf0e10cSrcweir             pWindow->SetPosSizePixel( ::Point( aWinRect.X, nOffset ), ::Size( aWinRect.Width, rRowColumnWindowData.nStaticSize ));
2715cdf0e10cSrcweir             pWindow->Show( sal_True, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE );
2716cdf0e10cSrcweir             nCurrPos += ( aWinRect.X - nCurrPos ) + aWinRect.Width;
2717cdf0e10cSrcweir         }
2718cdf0e10cSrcweir         else
2719cdf0e10cSrcweir         {
2720cdf0e10cSrcweir             if ( aWinRect.Y < nCurrPos )
2721cdf0e10cSrcweir                 aWinRect.Y = nCurrPos;
2722cdf0e10cSrcweir             pWindow->SetPosSizePixel( ::Point( nOffset, aWinRect.Y ), ::Size( rRowColumnWindowData.nStaticSize, aWinRect.Height ));
2723cdf0e10cSrcweir             pWindow->Show( sal_True, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE );
2724cdf0e10cSrcweir             nCurrPos += ( aWinRect.Y - nCurrPos ) + aWinRect.Height;
2725cdf0e10cSrcweir         }
2726cdf0e10cSrcweir     }
2727cdf0e10cSrcweir }
2728cdf0e10cSrcweir 
2729cdf0e10cSrcweir void ToolbarLayoutManager::implts_setLayoutDirty()
2730cdf0e10cSrcweir {
2731cdf0e10cSrcweir     WriteGuard aWriteLock( m_aLock );
2732cdf0e10cSrcweir     m_bLayoutDirty = true;
2733cdf0e10cSrcweir }
2734cdf0e10cSrcweir 
2735cdf0e10cSrcweir void ToolbarLayoutManager::implts_setLayoutInProgress( bool bInProgress )
2736cdf0e10cSrcweir {
2737cdf0e10cSrcweir     WriteGuard aWriteLock( m_aLock );
2738cdf0e10cSrcweir     m_bLayoutInProgress = bInProgress;
2739cdf0e10cSrcweir }
2740cdf0e10cSrcweir 
2741cdf0e10cSrcweir ::Rectangle ToolbarLayoutManager::implts_calcHotZoneRect( const ::Rectangle& rRect, sal_Int32 nHotZoneOffset )
2742cdf0e10cSrcweir {
2743cdf0e10cSrcweir     ::Rectangle aRect( rRect );
2744cdf0e10cSrcweir 
2745cdf0e10cSrcweir     aRect.Left() -= nHotZoneOffset;
2746cdf0e10cSrcweir     aRect.Top() -= nHotZoneOffset;
2747cdf0e10cSrcweir     aRect.Right() += nHotZoneOffset;
2748cdf0e10cSrcweir     aRect.Bottom() += nHotZoneOffset;
2749cdf0e10cSrcweir 
2750cdf0e10cSrcweir     return aRect;
2751cdf0e10cSrcweir }
2752cdf0e10cSrcweir 
2753cdf0e10cSrcweir void ToolbarLayoutManager::implts_calcDockingPosSize(
2754cdf0e10cSrcweir     UIElement&          rUIElement,
2755cdf0e10cSrcweir     DockingOperation&   rDockingOperation,
2756cdf0e10cSrcweir     ::Rectangle&        rTrackingRect,
2757cdf0e10cSrcweir     const Point&        rMousePos )
2758cdf0e10cSrcweir {
2759cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
2760cdf0e10cSrcweir     uno::Reference< awt::XWindow2 > xContainerWindow( m_xContainerWindow );
2761cdf0e10cSrcweir     ::Size                          aContainerWinSize;
2762cdf0e10cSrcweir     Window*                         pContainerWindow( 0 );
2763cdf0e10cSrcweir     ::Rectangle                     aDockingAreaOffsets( m_aDockingAreaOffsets );
2764cdf0e10cSrcweir     aReadLock.unlock();
2765cdf0e10cSrcweir 
2766cdf0e10cSrcweir     if ( !rUIElement.m_xUIElement.is() )
2767cdf0e10cSrcweir     {
2768cdf0e10cSrcweir         rTrackingRect = ::Rectangle();
2769cdf0e10cSrcweir         return;
2770cdf0e10cSrcweir     }
2771cdf0e10cSrcweir 
2772cdf0e10cSrcweir     {
2773cdf0e10cSrcweir         // Retrieve output size from container Window
2774cdf0e10cSrcweir         vos::OGuard aGuard( Application::GetSolarMutex() );
2775cdf0e10cSrcweir         pContainerWindow  = VCLUnoHelper::GetWindow( xContainerWindow );
2776cdf0e10cSrcweir         aContainerWinSize = pContainerWindow->GetOutputSizePixel();
2777cdf0e10cSrcweir     }
2778cdf0e10cSrcweir 
2779cdf0e10cSrcweir     Window*                        pDockWindow( 0 );
2780cdf0e10cSrcweir     Window*                        pDockingAreaWindow( 0 );
2781cdf0e10cSrcweir     ToolBox*                       pToolBox( 0 );
2782cdf0e10cSrcweir     uno::Reference< awt::XWindow > xWindow( rUIElement.m_xUIElement->getRealInterface(), uno::UNO_QUERY );
2783cdf0e10cSrcweir     uno::Reference< awt::XWindow > xDockingAreaWindow;
2784cdf0e10cSrcweir     ::Rectangle                    aTrackingRect( rTrackingRect );
2785cdf0e10cSrcweir     ui::DockingArea                eDockedArea( (ui::DockingArea)rUIElement.m_aDockedData.m_nDockedArea );
2786cdf0e10cSrcweir     sal_Int32                      nTopDockingAreaSize( implts_getTopBottomDockingAreaSizes().Width() );
2787cdf0e10cSrcweir     sal_Int32                      nBottomDockingAreaSize( implts_getTopBottomDockingAreaSizes().Height() );
2788cdf0e10cSrcweir     bool                           bHorizontalDockArea(( eDockedArea == ui::DockingArea_DOCKINGAREA_TOP ) ||
2789cdf0e10cSrcweir                                                        ( eDockedArea == ui::DockingArea_DOCKINGAREA_BOTTOM ));
2790cdf0e10cSrcweir     sal_Int32                      nMaxLeftRightDockAreaSize = aContainerWinSize.Height() -
2791cdf0e10cSrcweir                                                                nTopDockingAreaSize -
2792cdf0e10cSrcweir                                                                nBottomDockingAreaSize -
2793cdf0e10cSrcweir                                                                aDockingAreaOffsets.Top() -
2794cdf0e10cSrcweir                                                                aDockingAreaOffsets.Bottom();
2795cdf0e10cSrcweir     ::Rectangle                    aDockingAreaRect;
2796cdf0e10cSrcweir 
2797cdf0e10cSrcweir     aReadLock.lock();
2798cdf0e10cSrcweir     xDockingAreaWindow = m_xDockAreaWindows[eDockedArea];
2799cdf0e10cSrcweir     aReadLock.unlock();
2800cdf0e10cSrcweir 
2801cdf0e10cSrcweir     {
2802cdf0e10cSrcweir         vos::OGuard aGuard( Application::GetSolarMutex() );
2803cdf0e10cSrcweir         pDockingAreaWindow = VCLUnoHelper::GetWindow( xDockingAreaWindow );
2804cdf0e10cSrcweir         pDockWindow        = VCLUnoHelper::GetWindow( xWindow );
2805cdf0e10cSrcweir         if ( pDockWindow && pDockWindow->GetType() == WINDOW_TOOLBOX )
2806cdf0e10cSrcweir             pToolBox = (ToolBox *)pDockWindow;
2807cdf0e10cSrcweir 
2808cdf0e10cSrcweir         aDockingAreaRect = ::Rectangle( pDockingAreaWindow->GetPosPixel(), pDockingAreaWindow->GetSizePixel() );
2809cdf0e10cSrcweir         if ( pToolBox )
2810cdf0e10cSrcweir         {
2811cdf0e10cSrcweir             // docked toolbars always have one line
2812cdf0e10cSrcweir             ::Size aSize = pToolBox->CalcWindowSizePixel( 1, ImplConvertAlignment( sal_Int16( eDockedArea )) );
2813cdf0e10cSrcweir             aTrackingRect.SetSize( ::Size( aSize.Width(), aSize.Height() ));
2814cdf0e10cSrcweir         }
2815cdf0e10cSrcweir     }
2816cdf0e10cSrcweir 
2817cdf0e10cSrcweir     // default docking operation, dock on the given row/column
2818cdf0e10cSrcweir     bool                                     bOpOutsideOfDockingArea( !aDockingAreaRect.IsInside( rMousePos ));
2819cdf0e10cSrcweir     std::vector< SingleRowColumnWindowData > aRowColumnsWindowData;
2820cdf0e10cSrcweir 
2821cdf0e10cSrcweir     rDockingOperation = DOCKOP_ON_COLROW;
2822cdf0e10cSrcweir     implts_getDockingAreaElementInfos( eDockedArea, aRowColumnsWindowData );
2823cdf0e10cSrcweir 
2824cdf0e10cSrcweir     // determine current first row/column and last row/column
2825cdf0e10cSrcweir     sal_Int32 nMaxRowCol( -1 );
2826cdf0e10cSrcweir     sal_Int32 nMinRowCol( SAL_MAX_INT32 );
2827cdf0e10cSrcweir     const sal_uInt32 nCount = aRowColumnsWindowData.size();
2828cdf0e10cSrcweir     for ( sal_uInt32 i = 0; i < nCount; i++ )
2829cdf0e10cSrcweir     {
2830cdf0e10cSrcweir         if ( aRowColumnsWindowData[i].nRowColumn > nMaxRowCol )
2831cdf0e10cSrcweir             nMaxRowCol = aRowColumnsWindowData[i].nRowColumn;
2832cdf0e10cSrcweir         if ( aRowColumnsWindowData[i].nRowColumn < nMinRowCol )
2833cdf0e10cSrcweir             nMinRowCol = aRowColumnsWindowData[i].nRowColumn;
2834cdf0e10cSrcweir     }
2835cdf0e10cSrcweir 
2836cdf0e10cSrcweir     if ( !bOpOutsideOfDockingArea )
2837cdf0e10cSrcweir     {
2838cdf0e10cSrcweir         // docking inside our docking area
2839cdf0e10cSrcweir         sal_Int32   nIndex( -1 );
2840cdf0e10cSrcweir         sal_Int32   nRowCol( -1 );
2841cdf0e10cSrcweir         ::Rectangle aWindowRect;
2842cdf0e10cSrcweir         ::Rectangle aRowColumnRect;
2843cdf0e10cSrcweir 
2844cdf0e10cSrcweir         const sal_uInt32 nWindowDataCount = aRowColumnsWindowData.size();
2845cdf0e10cSrcweir         for ( sal_uInt32 i = 0; i < nWindowDataCount; i++ )
2846cdf0e10cSrcweir         {
2847cdf0e10cSrcweir             ::Rectangle aRect( aRowColumnsWindowData[i].aRowColumnRect.X,
2848cdf0e10cSrcweir                                aRowColumnsWindowData[i].aRowColumnRect.Y,
2849cdf0e10cSrcweir                                aRowColumnsWindowData[i].aRowColumnRect.X + aRowColumnsWindowData[i].aRowColumnRect.Width,
2850cdf0e10cSrcweir                                aRowColumnsWindowData[i].aRowColumnRect.Y + aRowColumnsWindowData[i].aRowColumnRect.Height );
2851cdf0e10cSrcweir 
2852cdf0e10cSrcweir             {
2853cdf0e10cSrcweir                 // Calc correct position of the column/row rectangle to be able to compare it with mouse pos/tracking rect
2854cdf0e10cSrcweir                 vos::OGuard aGuard( Application::GetSolarMutex() );
2855cdf0e10cSrcweir                 aRect.SetPos( pContainerWindow->ScreenToOutputPixel( pDockingAreaWindow->OutputToScreenPixel( aRect.TopLeft() )));
2856cdf0e10cSrcweir             }
2857cdf0e10cSrcweir 
2858cdf0e10cSrcweir             bool bIsInsideRowCol( aRect.IsInside( rMousePos ) );
2859cdf0e10cSrcweir             if ( bIsInsideRowCol )
2860cdf0e10cSrcweir             {
2861cdf0e10cSrcweir                 nIndex            = i;
2862cdf0e10cSrcweir                 nRowCol           = aRowColumnsWindowData[i].nRowColumn;
2863cdf0e10cSrcweir                 rDockingOperation = implts_determineDockingOperation( eDockedArea, aRect, rMousePos );
2864cdf0e10cSrcweir                 aWindowRect       = implts_getWindowRectFromRowColumn( eDockedArea, aRowColumnsWindowData[i], rMousePos, rUIElement.m_aName );
2865cdf0e10cSrcweir                 aRowColumnRect    = aRect;
2866cdf0e10cSrcweir                 break;
2867cdf0e10cSrcweir             }
2868cdf0e10cSrcweir         }
2869cdf0e10cSrcweir 
2870cdf0e10cSrcweir         OSL_ENSURE( ( nIndex >= 0 ) && ( nRowCol >= 0 ), "Impossible case - no row/column found but mouse pointer is inside our docking area" );
2871cdf0e10cSrcweir         if (( nIndex >= 0 ) && ( nRowCol >= 0 ))
2872cdf0e10cSrcweir         {
2873cdf0e10cSrcweir             if ( rDockingOperation == DOCKOP_ON_COLROW )
2874cdf0e10cSrcweir             {
2875cdf0e10cSrcweir                 if ( !aWindowRect.IsEmpty())
2876cdf0e10cSrcweir                 {
2877cdf0e10cSrcweir                     // Tracking rect is on a row/column and mouse is over a docked toolbar.
2878cdf0e10cSrcweir                     // Determine if the tracking rect must be located before/after the docked toolbar.
2879cdf0e10cSrcweir 
2880cdf0e10cSrcweir                     ::Rectangle aUIElementRect( aWindowRect );
2881cdf0e10cSrcweir                     sal_Int32   nMiddle( bHorizontalDockArea ? ( aWindowRect.Left() + aWindowRect.getWidth() / 2 ) :
2882cdf0e10cSrcweir                                                                ( aWindowRect.Top() + aWindowRect.getHeight() / 2 ));
2883cdf0e10cSrcweir                     sal_Bool    bInsertBefore( bHorizontalDockArea ? ( rMousePos.X() < nMiddle ) : ( rMousePos.Y() < nMiddle ));
2884cdf0e10cSrcweir                     if ( bInsertBefore )
2885cdf0e10cSrcweir                     {
2886cdf0e10cSrcweir                         if ( bHorizontalDockArea )
2887cdf0e10cSrcweir                         {
2888cdf0e10cSrcweir                             sal_Int32 nSize = ::std::max( sal_Int32( 0 ), std::min( sal_Int32( aContainerWinSize.Width() -  aWindowRect.Left() ),
2889cdf0e10cSrcweir                                                                                     sal_Int32( aTrackingRect.getWidth() )));
2890cdf0e10cSrcweir                             if ( nSize == 0 )
2891cdf0e10cSrcweir                                 nSize = aWindowRect.getWidth();
2892cdf0e10cSrcweir 
2893cdf0e10cSrcweir                             aUIElementRect.SetSize( ::Size( nSize, aWindowRect.getHeight() ));
2894cdf0e10cSrcweir                             aWindowRect = implts_determineFrontDockingRect( eDockedArea, nRowCol, aWindowRect,rUIElement.m_aName, aUIElementRect );
2895cdf0e10cSrcweir 
2896cdf0e10cSrcweir                             // Set virtual position
2897cdf0e10cSrcweir                             rUIElement.m_aDockedData.m_aPos.X() = aWindowRect.Left();
2898cdf0e10cSrcweir                             rUIElement.m_aDockedData.m_aPos.Y() = nRowCol;
2899cdf0e10cSrcweir                         }
2900cdf0e10cSrcweir                         else
2901cdf0e10cSrcweir                         {
2902cdf0e10cSrcweir                             sal_Int32 nSize = ::std::max( sal_Int32( 0 ), std::min( sal_Int32(
2903cdf0e10cSrcweir                                                     nTopDockingAreaSize + nMaxLeftRightDockAreaSize - aWindowRect.Top() ),
2904cdf0e10cSrcweir                                                     sal_Int32( aTrackingRect.getHeight() )));
2905cdf0e10cSrcweir                             if ( nSize == 0 )
2906cdf0e10cSrcweir                                 nSize = aWindowRect.getHeight();
2907cdf0e10cSrcweir 
2908cdf0e10cSrcweir                             aUIElementRect.SetSize( ::Size( aWindowRect.getWidth(), nSize ));
2909cdf0e10cSrcweir                             aWindowRect = implts_determineFrontDockingRect( eDockedArea, nRowCol, aWindowRect, rUIElement.m_aName, aUIElementRect );
2910cdf0e10cSrcweir 
2911cdf0e10cSrcweir                             // Set virtual position
2912cdf0e10cSrcweir                             sal_Int32 nPosY = pDockingAreaWindow->ScreenToOutputPixel(
2913cdf0e10cSrcweir                                                 pContainerWindow->OutputToScreenPixel( aWindowRect.TopLeft() )).Y();
2914cdf0e10cSrcweir                             rUIElement.m_aDockedData.m_aPos.X() = nRowCol;
2915cdf0e10cSrcweir                             rUIElement.m_aDockedData.m_aPos.Y() = nPosY;
2916cdf0e10cSrcweir                         }
2917cdf0e10cSrcweir 
2918cdf0e10cSrcweir                         rTrackingRect = aWindowRect;
2919cdf0e10cSrcweir                         return;
2920cdf0e10cSrcweir                     }
2921cdf0e10cSrcweir                     else
2922cdf0e10cSrcweir                     {
2923cdf0e10cSrcweir                         if ( bHorizontalDockArea )
2924cdf0e10cSrcweir                         {
2925cdf0e10cSrcweir                             sal_Int32 nSize = ::std::max( sal_Int32( 0 ), std::min( sal_Int32(( aContainerWinSize.Width() ) - aWindowRect.Right() ),
2926cdf0e10cSrcweir                                                                                     sal_Int32( aTrackingRect.getWidth() )));
2927cdf0e10cSrcweir                             if ( nSize == 0 )
2928cdf0e10cSrcweir                             {
2929cdf0e10cSrcweir                                 aUIElementRect.SetPos( ::Point( aContainerWinSize.Width() - aTrackingRect.getWidth(), aWindowRect.Top() ));
2930cdf0e10cSrcweir                                 aUIElementRect.SetSize( ::Size( aTrackingRect.getWidth(), aWindowRect.getHeight() ));
2931cdf0e10cSrcweir                                 rUIElement.m_aDockedData.m_aPos.X() = aUIElementRect.Left();
2932cdf0e10cSrcweir                             }
2933cdf0e10cSrcweir                             else
2934cdf0e10cSrcweir                             {
2935cdf0e10cSrcweir                                 aUIElementRect.SetPos( ::Point( aWindowRect.Right(), aWindowRect.Top() ));
2936cdf0e10cSrcweir                                 aUIElementRect.SetSize( ::Size( nSize, aWindowRect.getHeight() ));
2937cdf0e10cSrcweir                                 rUIElement.m_aDockedData.m_aPos.X() = aWindowRect.Right();
2938cdf0e10cSrcweir                             }
2939cdf0e10cSrcweir 
2940cdf0e10cSrcweir                             // Set virtual position
2941cdf0e10cSrcweir                             rUIElement.m_aDockedData.m_aPos.Y() = nRowCol;
2942cdf0e10cSrcweir                         }
2943cdf0e10cSrcweir                         else
2944cdf0e10cSrcweir                         {
2945cdf0e10cSrcweir                             sal_Int32 nSize = ::std::max( sal_Int32( 0 ), std::min( sal_Int32( nTopDockingAreaSize + nMaxLeftRightDockAreaSize - aWindowRect.Bottom() ),
2946cdf0e10cSrcweir                                                                                     sal_Int32( aTrackingRect.getHeight() )));
2947cdf0e10cSrcweir                             aUIElementRect.SetPos( ::Point( aWindowRect.Left(), aWindowRect.Bottom() ));
2948cdf0e10cSrcweir                             aUIElementRect.SetSize( ::Size( aWindowRect.getWidth(), nSize ));
2949cdf0e10cSrcweir 
2950cdf0e10cSrcweir                             // Set virtual position
2951cdf0e10cSrcweir                             sal_Int32 nPosY( 0 );
2952cdf0e10cSrcweir                             {
2953cdf0e10cSrcweir                                 vos::OGuard aGuard( Application::GetSolarMutex() );
2954cdf0e10cSrcweir                                 nPosY = pDockingAreaWindow->ScreenToOutputPixel(
2955cdf0e10cSrcweir                                                     pContainerWindow->OutputToScreenPixel( aWindowRect.BottomRight() )).Y();
2956cdf0e10cSrcweir                             }
2957cdf0e10cSrcweir                             rUIElement.m_aDockedData.m_aPos.X() = nRowCol;
2958cdf0e10cSrcweir                             rUIElement.m_aDockedData.m_aPos.Y() = nPosY;
2959cdf0e10cSrcweir                         }
2960cdf0e10cSrcweir 
2961cdf0e10cSrcweir                         rTrackingRect = aUIElementRect;
2962cdf0e10cSrcweir                         return;
2963cdf0e10cSrcweir                     }
2964cdf0e10cSrcweir                 }
2965cdf0e10cSrcweir                 else
2966cdf0e10cSrcweir                 {
2967cdf0e10cSrcweir                     implts_setTrackingRect( eDockedArea, rMousePos, aTrackingRect );
2968cdf0e10cSrcweir                     rTrackingRect = implts_calcTrackingAndElementRect(
2969cdf0e10cSrcweir                                         eDockedArea, nRowCol, rUIElement,
2970cdf0e10cSrcweir                                         aTrackingRect, aRowColumnRect, aContainerWinSize );
2971cdf0e10cSrcweir                     return;
2972cdf0e10cSrcweir                 }
2973cdf0e10cSrcweir             }
2974cdf0e10cSrcweir             else
2975cdf0e10cSrcweir             {
2976cdf0e10cSrcweir                 if ((( nRowCol == nMinRowCol ) && ( rDockingOperation == DOCKOP_BEFORE_COLROW )) ||
2977cdf0e10cSrcweir                     (( nRowCol == nMaxRowCol ) && ( rDockingOperation == DOCKOP_AFTER_COLROW  )))
2978cdf0e10cSrcweir                     bOpOutsideOfDockingArea = true;
2979cdf0e10cSrcweir                 else
2980cdf0e10cSrcweir                 {
2981cdf0e10cSrcweir                     // handle docking before/after a row
2982cdf0e10cSrcweir                     implts_setTrackingRect( eDockedArea, rMousePos, aTrackingRect );
2983cdf0e10cSrcweir                     rTrackingRect = implts_calcTrackingAndElementRect(
2984cdf0e10cSrcweir                                         eDockedArea, nRowCol, rUIElement,
2985cdf0e10cSrcweir                                         aTrackingRect, aRowColumnRect, aContainerWinSize );
2986cdf0e10cSrcweir 
2987cdf0e10cSrcweir                     sal_Int32 nOffsetX( 0 );
2988cdf0e10cSrcweir                     sal_Int32 nOffsetY( 0 );
2989cdf0e10cSrcweir                     if ( bHorizontalDockArea )
2990cdf0e10cSrcweir                         nOffsetY = sal_Int32( floor( aRowColumnRect.getHeight() / 2 + 0.5 ));
2991cdf0e10cSrcweir                     else
2992cdf0e10cSrcweir                         nOffsetX = sal_Int32( floor( aRowColumnRect.getWidth() / 2 + 0.5 ));
2993cdf0e10cSrcweir 
2994cdf0e10cSrcweir                     if ( rDockingOperation == DOCKOP_BEFORE_COLROW )
2995cdf0e10cSrcweir                     {
2996cdf0e10cSrcweir                         if (( eDockedArea == ui::DockingArea_DOCKINGAREA_TOP ) || ( eDockedArea == ui::DockingArea_DOCKINGAREA_LEFT ))
2997cdf0e10cSrcweir                         {
2998cdf0e10cSrcweir                             // Docking before/after means move track rectangle half column/row.
2999cdf0e10cSrcweir                             // As left and top are ordered 0...n instead of right and bottom
3000cdf0e10cSrcweir                             // which uses n...0, we have to use negative values for top/left.
3001cdf0e10cSrcweir                             nOffsetX *= -1;
3002cdf0e10cSrcweir                             nOffsetY *= -1;
3003cdf0e10cSrcweir                         }
3004cdf0e10cSrcweir                     }
3005cdf0e10cSrcweir                     else
3006cdf0e10cSrcweir                     {
3007cdf0e10cSrcweir                         if (( eDockedArea == ui::DockingArea_DOCKINGAREA_BOTTOM ) || ( eDockedArea == ui::DockingArea_DOCKINGAREA_RIGHT ))
3008cdf0e10cSrcweir                         {
3009cdf0e10cSrcweir                             // Docking before/after means move track rectangle half column/row.
3010cdf0e10cSrcweir                             // As left and top are ordered 0...n instead of right and bottom
3011cdf0e10cSrcweir                             // which uses n...0, we have to use negative values for top/left.
3012cdf0e10cSrcweir                             nOffsetX *= -1;
3013cdf0e10cSrcweir                             nOffsetY *= -1;
3014cdf0e10cSrcweir                         }
3015cdf0e10cSrcweir                         nRowCol++;
3016cdf0e10cSrcweir                     }
3017cdf0e10cSrcweir 
3018cdf0e10cSrcweir                     if ( bHorizontalDockArea )
3019cdf0e10cSrcweir                         rUIElement.m_aDockedData.m_aPos.Y() = nRowCol;
3020cdf0e10cSrcweir                     else
3021cdf0e10cSrcweir                         rUIElement.m_aDockedData.m_aPos.X() = nRowCol;
3022cdf0e10cSrcweir 
3023cdf0e10cSrcweir                     rTrackingRect.Move( nOffsetX, nOffsetY );
3024cdf0e10cSrcweir                     rTrackingRect.SetSize( aTrackingRect.GetSize() );
3025cdf0e10cSrcweir                 }
3026cdf0e10cSrcweir             }
3027cdf0e10cSrcweir         }
3028cdf0e10cSrcweir     }
3029cdf0e10cSrcweir 
3030cdf0e10cSrcweir     // Docking outside of our docking window area =>
3031cdf0e10cSrcweir     // Users want to dock before/after first/last docked element or to an empty docking area
3032cdf0e10cSrcweir     if ( bOpOutsideOfDockingArea )
3033cdf0e10cSrcweir     {
3034cdf0e10cSrcweir         // set correct size for docking
3035cdf0e10cSrcweir         implts_setTrackingRect( eDockedArea, rMousePos, aTrackingRect );
3036cdf0e10cSrcweir         rTrackingRect = aTrackingRect;
3037cdf0e10cSrcweir 
3038cdf0e10cSrcweir         if ( bHorizontalDockArea )
3039cdf0e10cSrcweir         {
3040cdf0e10cSrcweir             sal_Int32 nPosX( std::max( sal_Int32( rTrackingRect.Left()), sal_Int32( 0 )));
3041cdf0e10cSrcweir             if (( nPosX + rTrackingRect.getWidth()) > aContainerWinSize.Width() )
3042cdf0e10cSrcweir                 nPosX = std::min( nPosX,
3043cdf0e10cSrcweir                                 std::max( sal_Int32( aContainerWinSize.Width() - rTrackingRect.getWidth() ),
3044cdf0e10cSrcweir                                           sal_Int32( 0 )));
3045cdf0e10cSrcweir 
3046cdf0e10cSrcweir             sal_Int32 nSize = std::min( aContainerWinSize.Width(), rTrackingRect.getWidth() );
3047cdf0e10cSrcweir             sal_Int32 nDockHeight = std::max( static_cast<sal_Int32>(aDockingAreaRect.getHeight()), sal_Int32( 0 ));
3048cdf0e10cSrcweir             if ( nDockHeight == 0 )
3049cdf0e10cSrcweir             {
3050cdf0e10cSrcweir                 sal_Int32 nPosY( std::max( aDockingAreaRect.Top(), aDockingAreaRect.Bottom() ));
3051cdf0e10cSrcweir                 if ( eDockedArea == ui::DockingArea_DOCKINGAREA_BOTTOM )
3052cdf0e10cSrcweir                     nPosY -= rTrackingRect.getHeight();
3053cdf0e10cSrcweir                 rTrackingRect.SetPos( Point( nPosX, nPosY ));
3054cdf0e10cSrcweir                 rUIElement.m_aDockedData.m_aPos.Y() = 0;
3055cdf0e10cSrcweir             }
3056cdf0e10cSrcweir             else if ( rMousePos.Y() < ( aDockingAreaRect.Top() + ( nDockHeight / 2 )))
3057cdf0e10cSrcweir             {
3058cdf0e10cSrcweir                 rTrackingRect.SetPos( Point( nPosX, aDockingAreaRect.Top() - rTrackingRect.getHeight() ));
3059cdf0e10cSrcweir                 if ( eDockedArea == ui::DockingArea_DOCKINGAREA_TOP )
3060cdf0e10cSrcweir                     rUIElement.m_aDockedData.m_aPos.Y() = 0;
3061cdf0e10cSrcweir                 else
3062cdf0e10cSrcweir                     rUIElement.m_aDockedData.m_aPos.Y() = ( nMaxRowCol >= 0 ) ? nMaxRowCol+1 : 0;
3063cdf0e10cSrcweir                 rDockingOperation = DOCKOP_BEFORE_COLROW;
3064cdf0e10cSrcweir             }
3065cdf0e10cSrcweir             else
3066cdf0e10cSrcweir             {
3067cdf0e10cSrcweir                 rTrackingRect.SetPos( Point( nPosX, aDockingAreaRect.Bottom() ));
3068cdf0e10cSrcweir                 if ( eDockedArea == ui::DockingArea_DOCKINGAREA_TOP )
3069cdf0e10cSrcweir                     rUIElement.m_aDockedData.m_aPos.Y() = ( nMaxRowCol >= 0 ) ? nMaxRowCol+1 : 0;
3070cdf0e10cSrcweir                 else
3071cdf0e10cSrcweir                     rUIElement.m_aDockedData.m_aPos.Y() = 0;
3072cdf0e10cSrcweir                 rDockingOperation = DOCKOP_AFTER_COLROW;
3073cdf0e10cSrcweir             }
3074cdf0e10cSrcweir             rTrackingRect.setWidth( nSize );
3075cdf0e10cSrcweir 
3076cdf0e10cSrcweir             {
3077cdf0e10cSrcweir                 vos::OGuard aGuard( Application::GetSolarMutex() );
3078cdf0e10cSrcweir                 nPosX = pDockingAreaWindow->ScreenToOutputPixel(
3079cdf0e10cSrcweir                                     pContainerWindow->OutputToScreenPixel( rTrackingRect.TopLeft() )).X();
3080cdf0e10cSrcweir             }
3081cdf0e10cSrcweir             rUIElement.m_aDockedData.m_aPos.X() = nPosX;
3082cdf0e10cSrcweir         }
3083cdf0e10cSrcweir         else
3084cdf0e10cSrcweir         {
3085cdf0e10cSrcweir             sal_Int32 nMaxDockingAreaHeight = std::max( sal_Int32( 0 ), sal_Int32( nMaxLeftRightDockAreaSize ));
3086cdf0e10cSrcweir             sal_Int32 nPosY( std::max( sal_Int32( aTrackingRect.Top()), sal_Int32( nTopDockingAreaSize )));
3087cdf0e10cSrcweir             if (( nPosY + aTrackingRect.getHeight()) > ( nTopDockingAreaSize + nMaxDockingAreaHeight ))
3088cdf0e10cSrcweir                 nPosY = std::min( nPosY,
3089cdf0e10cSrcweir                                 std::max( sal_Int32( nTopDockingAreaSize + ( nMaxDockingAreaHeight - aTrackingRect.getHeight() )),
3090cdf0e10cSrcweir                                         sal_Int32( nTopDockingAreaSize )));
3091cdf0e10cSrcweir 
3092cdf0e10cSrcweir             sal_Int32 nSize = std::min( nMaxDockingAreaHeight, static_cast<sal_Int32>(aTrackingRect.getHeight()) );
3093cdf0e10cSrcweir             sal_Int32 nDockWidth = std::max( static_cast<sal_Int32>(aDockingAreaRect.getWidth()), sal_Int32( 0 ));
3094cdf0e10cSrcweir             if ( nDockWidth == 0 )
3095cdf0e10cSrcweir             {
3096cdf0e10cSrcweir                 sal_Int32 nPosX( std::max( aDockingAreaRect.Left(), aDockingAreaRect.Right() ));
3097cdf0e10cSrcweir                 if ( eDockedArea == ui::DockingArea_DOCKINGAREA_RIGHT )
3098cdf0e10cSrcweir                     nPosX -= rTrackingRect.getWidth();
3099cdf0e10cSrcweir                 rTrackingRect.SetPos( Point( nPosX, nPosY ));
3100cdf0e10cSrcweir                 rUIElement.m_aDockedData.m_aPos.X() = 0;
3101cdf0e10cSrcweir             }
3102cdf0e10cSrcweir             else if ( rMousePos.X() < ( aDockingAreaRect.Left() + ( nDockWidth / 2 )))
3103cdf0e10cSrcweir             {
3104cdf0e10cSrcweir                 rTrackingRect.SetPos( Point( aDockingAreaRect.Left() - rTrackingRect.getWidth(), nPosY ));
3105cdf0e10cSrcweir                 if ( eDockedArea == ui::DockingArea_DOCKINGAREA_LEFT )
3106cdf0e10cSrcweir                     rUIElement.m_aDockedData.m_aPos.X() = 0;
3107cdf0e10cSrcweir                 else
3108cdf0e10cSrcweir                     rUIElement.m_aDockedData.m_aPos.X() = ( nMaxRowCol >= 0 ) ? nMaxRowCol+1 : 0;
3109cdf0e10cSrcweir                 rDockingOperation = DOCKOP_BEFORE_COLROW;
3110cdf0e10cSrcweir             }
3111cdf0e10cSrcweir             else
3112cdf0e10cSrcweir             {
3113cdf0e10cSrcweir                 rTrackingRect.SetPos( Point( aDockingAreaRect.Right(), nPosY ));
3114cdf0e10cSrcweir                 if ( eDockedArea == ui::DockingArea_DOCKINGAREA_LEFT )
3115cdf0e10cSrcweir                     rUIElement.m_aDockedData.m_aPos.X() = ( nMaxRowCol >= 0 ) ? nMaxRowCol+1 : 0;
3116cdf0e10cSrcweir                 else
3117cdf0e10cSrcweir                     rUIElement.m_aDockedData.m_aPos.X() = 0;
3118cdf0e10cSrcweir                 rDockingOperation = DOCKOP_AFTER_COLROW;
3119cdf0e10cSrcweir             }
3120cdf0e10cSrcweir             rTrackingRect.setHeight( nSize );
3121cdf0e10cSrcweir 
3122cdf0e10cSrcweir             {
3123cdf0e10cSrcweir                 vos::OGuard aGuard( Application::GetSolarMutex() );
3124cdf0e10cSrcweir                 nPosY = pDockingAreaWindow->ScreenToOutputPixel(
3125cdf0e10cSrcweir                                     pContainerWindow->OutputToScreenPixel( rTrackingRect.TopLeft() )).Y();
3126cdf0e10cSrcweir             }
3127cdf0e10cSrcweir             rUIElement.m_aDockedData.m_aPos.Y() = nPosY;
3128cdf0e10cSrcweir         }
3129cdf0e10cSrcweir     }
3130cdf0e10cSrcweir }
3131cdf0e10cSrcweir 
3132cdf0e10cSrcweir framework::ToolbarLayoutManager::DockingOperation ToolbarLayoutManager::implts_determineDockingOperation(
3133cdf0e10cSrcweir     ui::DockingArea    DockingArea,
3134cdf0e10cSrcweir     const ::Rectangle& rRowColRect,
3135cdf0e10cSrcweir     const Point&       rMousePos )
3136cdf0e10cSrcweir {
3137cdf0e10cSrcweir     const sal_Int32 nHorzVerticalRegionSize        = 6;
3138cdf0e10cSrcweir     const sal_Int32 nHorzVerticalMoveRegion        = 4;
3139cdf0e10cSrcweir 
3140cdf0e10cSrcweir     if ( rRowColRect.IsInside( rMousePos ))
3141cdf0e10cSrcweir     {
3142cdf0e10cSrcweir         if ( isHorizontalDockingArea( DockingArea ))
3143cdf0e10cSrcweir         {
3144cdf0e10cSrcweir             sal_Int32 nRegion = rRowColRect.getHeight() / nHorzVerticalRegionSize;
3145cdf0e10cSrcweir             sal_Int32 nPosY   = rRowColRect.Top() + nRegion;
3146cdf0e10cSrcweir 
3147cdf0e10cSrcweir             if ( rMousePos.Y() < nPosY )
3148cdf0e10cSrcweir                 return ( DockingArea == ui::DockingArea_DOCKINGAREA_TOP ) ? DOCKOP_BEFORE_COLROW : DOCKOP_AFTER_COLROW;
3149cdf0e10cSrcweir             else if ( rMousePos.Y() < ( nPosY + nRegion*nHorzVerticalMoveRegion ))
3150cdf0e10cSrcweir                 return DOCKOP_ON_COLROW;
3151cdf0e10cSrcweir             else
3152cdf0e10cSrcweir                 return ( DockingArea == ui::DockingArea_DOCKINGAREA_TOP ) ? DOCKOP_AFTER_COLROW : DOCKOP_BEFORE_COLROW;
3153cdf0e10cSrcweir         }
3154cdf0e10cSrcweir         else
3155cdf0e10cSrcweir         {
3156cdf0e10cSrcweir             sal_Int32 nRegion = rRowColRect.getWidth() / nHorzVerticalRegionSize;
3157cdf0e10cSrcweir             sal_Int32 nPosX   = rRowColRect.Left() + nRegion;
3158cdf0e10cSrcweir 
3159cdf0e10cSrcweir             if ( rMousePos.X() < nPosX )
3160cdf0e10cSrcweir                 return ( DockingArea == ui::DockingArea_DOCKINGAREA_LEFT ) ? DOCKOP_BEFORE_COLROW : DOCKOP_AFTER_COLROW;
3161cdf0e10cSrcweir             else if ( rMousePos.X() < ( nPosX + nRegion*nHorzVerticalMoveRegion ))
3162cdf0e10cSrcweir                 return DOCKOP_ON_COLROW;
3163cdf0e10cSrcweir             else
3164cdf0e10cSrcweir                 return ( DockingArea == ui::DockingArea_DOCKINGAREA_LEFT ) ? DOCKOP_AFTER_COLROW : DOCKOP_BEFORE_COLROW;
3165cdf0e10cSrcweir         }
3166cdf0e10cSrcweir     }
3167cdf0e10cSrcweir     else
3168cdf0e10cSrcweir         return DOCKOP_ON_COLROW;
3169cdf0e10cSrcweir }
3170cdf0e10cSrcweir 
3171cdf0e10cSrcweir ::Rectangle ToolbarLayoutManager::implts_calcTrackingAndElementRect(
3172cdf0e10cSrcweir     ui::DockingArea eDockingArea,
3173cdf0e10cSrcweir     sal_Int32 nRowCol,
3174cdf0e10cSrcweir     UIElement& rUIElement,
3175cdf0e10cSrcweir     const ::Rectangle& rTrackingRect,
3176cdf0e10cSrcweir     const ::Rectangle& rRowColumnRect,
3177cdf0e10cSrcweir     const ::Size& rContainerWinSize )
3178cdf0e10cSrcweir {
3179cdf0e10cSrcweir     ReadGuard aReadGuard( m_aLock );
3180cdf0e10cSrcweir     ::Rectangle aDockingAreaOffsets( m_aDockingAreaOffsets );
3181cdf0e10cSrcweir     aReadGuard.unlock();
3182cdf0e10cSrcweir 
3183cdf0e10cSrcweir     bool      bHorizontalDockArea( isHorizontalDockingArea( eDockingArea ));
3184cdf0e10cSrcweir     sal_Int32 nTopDockingAreaSize( implts_getTopBottomDockingAreaSizes().Width() );
3185cdf0e10cSrcweir     sal_Int32 nBottomDockingAreaSize( implts_getTopBottomDockingAreaSizes().Height() );
3186cdf0e10cSrcweir 
3187cdf0e10cSrcweir     sal_Int32 nMaxLeftRightDockAreaSize = rContainerWinSize.Height() -
3188cdf0e10cSrcweir                                           nTopDockingAreaSize -
3189cdf0e10cSrcweir                                           nBottomDockingAreaSize -
3190cdf0e10cSrcweir                                           aDockingAreaOffsets.Top() -
3191cdf0e10cSrcweir                                           aDockingAreaOffsets.Bottom();
3192cdf0e10cSrcweir 
3193cdf0e10cSrcweir     ::Rectangle aTrackingRect( rTrackingRect );
3194cdf0e10cSrcweir     if ( bHorizontalDockArea )
3195cdf0e10cSrcweir     {
3196cdf0e10cSrcweir         sal_Int32 nPosX( std::max( sal_Int32( rTrackingRect.Left()), sal_Int32( 0 )));
3197cdf0e10cSrcweir         if (( nPosX + rTrackingRect.getWidth()) > rContainerWinSize.Width() )
3198cdf0e10cSrcweir             nPosX = std::min( nPosX,
3199cdf0e10cSrcweir                                 std::max( sal_Int32( rContainerWinSize.Width() - rTrackingRect.getWidth() ),
3200cdf0e10cSrcweir                                           sal_Int32( 0 )));
3201cdf0e10cSrcweir 
3202cdf0e10cSrcweir         sal_Int32 nSize = std::min( rContainerWinSize.Width(), rTrackingRect.getWidth() );
3203cdf0e10cSrcweir 
3204cdf0e10cSrcweir         aTrackingRect.SetPos( ::Point( nPosX, rRowColumnRect.Top() ));
3205cdf0e10cSrcweir         aTrackingRect.setWidth( nSize );
3206cdf0e10cSrcweir         aTrackingRect.setHeight( rRowColumnRect.getHeight() );
3207cdf0e10cSrcweir 
3208cdf0e10cSrcweir         // Set virtual position
3209cdf0e10cSrcweir         rUIElement.m_aDockedData.m_aPos.X() = nPosX;
3210cdf0e10cSrcweir         rUIElement.m_aDockedData.m_aPos.Y() = nRowCol;
3211cdf0e10cSrcweir     }
3212cdf0e10cSrcweir     else
3213cdf0e10cSrcweir     {
3214cdf0e10cSrcweir         sal_Int32 nMaxDockingAreaHeight = std::max( sal_Int32( 0 ),
3215cdf0e10cSrcweir                                                     sal_Int32( nMaxLeftRightDockAreaSize ));
3216cdf0e10cSrcweir 
3217cdf0e10cSrcweir         sal_Int32 nPosY( std::max( sal_Int32( aTrackingRect.Top()), sal_Int32( nTopDockingAreaSize )));
3218cdf0e10cSrcweir         if (( nPosY + aTrackingRect.getHeight()) > ( nTopDockingAreaSize + nMaxDockingAreaHeight ))
3219cdf0e10cSrcweir             nPosY = std::min( nPosY,
3220cdf0e10cSrcweir                                 std::max( sal_Int32( nTopDockingAreaSize + ( nMaxDockingAreaHeight - aTrackingRect.getHeight() )),
3221cdf0e10cSrcweir                                         sal_Int32( nTopDockingAreaSize )));
3222cdf0e10cSrcweir 
3223cdf0e10cSrcweir         sal_Int32 nSize = std::min( nMaxDockingAreaHeight, static_cast<sal_Int32>(aTrackingRect.getHeight()) );
3224cdf0e10cSrcweir 
3225cdf0e10cSrcweir         aTrackingRect.SetPos( ::Point( rRowColumnRect.Left(), nPosY ));
3226cdf0e10cSrcweir         aTrackingRect.setWidth( rRowColumnRect.getWidth() );
3227cdf0e10cSrcweir         aTrackingRect.setHeight( nSize );
3228cdf0e10cSrcweir 
3229cdf0e10cSrcweir         aReadGuard.lock();
3230cdf0e10cSrcweir         uno::Reference< awt::XWindow  > xDockingAreaWindow( m_xDockAreaWindows[eDockingArea] );
3231cdf0e10cSrcweir         uno::Reference< awt::XWindow2 > xContainerWindow( m_xContainerWindow );
3232cdf0e10cSrcweir         aReadGuard.unlock();
3233cdf0e10cSrcweir 
3234cdf0e10cSrcweir         sal_Int32 nDockPosY( 0 );
3235cdf0e10cSrcweir         Window* pDockingAreaWindow( 0 );
3236cdf0e10cSrcweir         Window* pContainerWindow( 0 );
3237cdf0e10cSrcweir         {
3238cdf0e10cSrcweir             vos::OGuard aGuard( Application::GetSolarMutex() );
3239cdf0e10cSrcweir             pDockingAreaWindow = VCLUnoHelper::GetWindow( xDockingAreaWindow );
3240cdf0e10cSrcweir             pContainerWindow = VCLUnoHelper::GetWindow( xContainerWindow );
3241cdf0e10cSrcweir             nDockPosY = pDockingAreaWindow->ScreenToOutputPixel( pContainerWindow->OutputToScreenPixel( ::Point( 0, nPosY ))).Y();
3242cdf0e10cSrcweir         }
3243cdf0e10cSrcweir 
3244cdf0e10cSrcweir         // Set virtual position
3245cdf0e10cSrcweir         rUIElement.m_aDockedData.m_aPos.X() = nRowCol;
3246cdf0e10cSrcweir         rUIElement.m_aDockedData.m_aPos.Y() = nDockPosY;
3247cdf0e10cSrcweir     }
3248cdf0e10cSrcweir 
3249cdf0e10cSrcweir     return aTrackingRect;
3250cdf0e10cSrcweir }
3251cdf0e10cSrcweir 
3252cdf0e10cSrcweir void ToolbarLayoutManager::implts_setTrackingRect( ui::DockingArea eDockingArea, const ::Point& rMousePos, ::Rectangle& rTrackingRect )
3253cdf0e10cSrcweir {
3254cdf0e10cSrcweir     ::Point aPoint( rTrackingRect.TopLeft());
3255cdf0e10cSrcweir     if ( isHorizontalDockingArea( eDockingArea ))
3256cdf0e10cSrcweir         aPoint.X() = rMousePos.X();
3257cdf0e10cSrcweir     else
3258cdf0e10cSrcweir         aPoint.Y() = rMousePos.Y();
3259cdf0e10cSrcweir     rTrackingRect.SetPos( aPoint );
3260cdf0e10cSrcweir }
3261cdf0e10cSrcweir 
3262cdf0e10cSrcweir void ToolbarLayoutManager::implts_renumberRowColumnData(
3263cdf0e10cSrcweir     ui::DockingArea eDockingArea,
3264cdf0e10cSrcweir     DockingOperation /*eDockingOperation*/,
3265cdf0e10cSrcweir     const UIElement& rUIElement )
3266cdf0e10cSrcweir {
3267cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
3268cdf0e10cSrcweir     uno::Reference< container::XNameAccess > xPersistentWindowState( m_xPersistentWindowState );
3269cdf0e10cSrcweir     aReadLock.unlock();
3270cdf0e10cSrcweir 
3271cdf0e10cSrcweir     bool bHorzDockingArea( isHorizontalDockingArea( eDockingArea ));
3272cdf0e10cSrcweir     sal_Int32 nRowCol( bHorzDockingArea ? rUIElement.m_aDockedData.m_aPos.Y() : rUIElement.m_aDockedData.m_aPos.X() );
3273cdf0e10cSrcweir 
3274cdf0e10cSrcweir     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
3275cdf0e10cSrcweir     WriteGuard aWriteLock( m_aLock );
3276cdf0e10cSrcweir     UIElementVector::iterator pIter;
3277cdf0e10cSrcweir     for ( pIter = m_aUIElements.begin(); pIter != m_aUIElements.end(); pIter++ )
3278cdf0e10cSrcweir     {
3279cdf0e10cSrcweir         if (( pIter->m_aDockedData.m_nDockedArea == sal_Int16( eDockingArea )) && ( pIter->m_aName != rUIElement.m_aName ))
3280cdf0e10cSrcweir         {
3281cdf0e10cSrcweir             // Don't change toolbars without a valid docking position!
3282cdf0e10cSrcweir             if ( isDefaultPos( pIter->m_aDockedData.m_aPos ))
3283cdf0e10cSrcweir                 continue;
3284cdf0e10cSrcweir 
3285cdf0e10cSrcweir             sal_Int32 nWindowRowCol = ( bHorzDockingArea ) ? pIter->m_aDockedData.m_aPos.Y() : pIter->m_aDockedData.m_aPos.X();
3286cdf0e10cSrcweir             if ( nWindowRowCol >= nRowCol )
3287cdf0e10cSrcweir             {
3288cdf0e10cSrcweir                 if ( bHorzDockingArea )
3289cdf0e10cSrcweir                     pIter->m_aDockedData.m_aPos.Y() += 1;
3290cdf0e10cSrcweir                 else
3291cdf0e10cSrcweir                     pIter->m_aDockedData.m_aPos.X() += 1;
3292cdf0e10cSrcweir             }
3293cdf0e10cSrcweir         }
3294cdf0e10cSrcweir     }
3295cdf0e10cSrcweir     aWriteLock.unlock();
3296cdf0e10cSrcweir     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
3297cdf0e10cSrcweir 
3298cdf0e10cSrcweir     // We have to change the persistent window state part
3299cdf0e10cSrcweir     if ( xPersistentWindowState.is() )
3300cdf0e10cSrcweir     {
3301cdf0e10cSrcweir         try
3302cdf0e10cSrcweir         {
3303cdf0e10cSrcweir             uno::Sequence< ::rtl::OUString > aWindowElements = xPersistentWindowState->getElementNames();
3304cdf0e10cSrcweir             for ( sal_Int32 i = 0; i < aWindowElements.getLength(); i++ )
3305cdf0e10cSrcweir             {
3306cdf0e10cSrcweir                 if ( rUIElement.m_aName != aWindowElements[i] )
3307cdf0e10cSrcweir                 {
3308cdf0e10cSrcweir                     try
3309cdf0e10cSrcweir                     {
3310cdf0e10cSrcweir                         uno::Sequence< beans::PropertyValue > aPropValueSeq;
3311cdf0e10cSrcweir                         awt::Point                            aDockedPos;
3312cdf0e10cSrcweir                         ui::DockingArea                       nDockedArea( ui::DockingArea_DOCKINGAREA_DEFAULT );
3313cdf0e10cSrcweir 
3314cdf0e10cSrcweir                         xPersistentWindowState->getByName( aWindowElements[i] ) >>= aPropValueSeq;
3315cdf0e10cSrcweir                         for ( sal_Int32 j = 0; j < aPropValueSeq.getLength(); j++ )
3316cdf0e10cSrcweir                         {
3317cdf0e10cSrcweir                             if ( aPropValueSeq[j].Name.equalsAscii( WINDOWSTATE_PROPERTY_DOCKINGAREA ))
3318cdf0e10cSrcweir                                 aPropValueSeq[j].Value >>= nDockedArea;
3319cdf0e10cSrcweir                             else if ( aPropValueSeq[j].Name.equalsAscii( WINDOWSTATE_PROPERTY_DOCKPOS ))
3320cdf0e10cSrcweir                                 aPropValueSeq[j].Value >>= aDockedPos;
3321cdf0e10cSrcweir                         }
3322cdf0e10cSrcweir 
3323cdf0e10cSrcweir                         // Don't change toolbars without a valid docking position!
3324cdf0e10cSrcweir                         if ( isDefaultPos( aDockedPos ))
3325cdf0e10cSrcweir                             continue;
3326cdf0e10cSrcweir 
3327cdf0e10cSrcweir                         sal_Int32 nWindowRowCol = ( bHorzDockingArea ) ? aDockedPos.Y : aDockedPos.X;
3328cdf0e10cSrcweir                         if (( nDockedArea == eDockingArea ) && ( nWindowRowCol >= nRowCol ))
3329cdf0e10cSrcweir                         {
3330cdf0e10cSrcweir                             if ( bHorzDockingArea )
3331cdf0e10cSrcweir                                 aDockedPos.Y += 1;
3332cdf0e10cSrcweir                             else
3333cdf0e10cSrcweir                                 aDockedPos.X += 1;
3334cdf0e10cSrcweir 
3335cdf0e10cSrcweir                             uno::Reference< container::XNameReplace > xReplace( xPersistentWindowState, uno::UNO_QUERY );
3336cdf0e10cSrcweir                             xReplace->replaceByName( aWindowElements[i], makeAny( aPropValueSeq ));
3337cdf0e10cSrcweir                         }
3338cdf0e10cSrcweir                     }
3339cdf0e10cSrcweir                     catch ( uno::Exception& ) {}
3340cdf0e10cSrcweir                 }
3341cdf0e10cSrcweir             }
3342cdf0e10cSrcweir         }
3343cdf0e10cSrcweir         catch ( uno::Exception& ) {}
3344cdf0e10cSrcweir     }
3345cdf0e10cSrcweir }
3346cdf0e10cSrcweir 
3347cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------
3348cdf0e10cSrcweir //  XWindowListener
3349cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------
3350cdf0e10cSrcweir void SAL_CALL ToolbarLayoutManager::windowResized( const awt::WindowEvent& aEvent )
3351cdf0e10cSrcweir throw( uno::RuntimeException )
3352cdf0e10cSrcweir {
3353cdf0e10cSrcweir     WriteGuard aWriteLock( m_aLock );
3354cdf0e10cSrcweir     bool bLocked( m_bDockingInProgress );
3355cdf0e10cSrcweir     bool bLayoutInProgress( m_bLayoutInProgress );
3356cdf0e10cSrcweir     aWriteLock.unlock();
3357cdf0e10cSrcweir 
3358cdf0e10cSrcweir     // Do not do anything if we are in the middle of a docking process. This would interfere all other
3359cdf0e10cSrcweir     // operations. We will store the new position and size in the docking handlers.
3360cdf0e10cSrcweir     // Do not do anything if we are in the middle of our layouting process. We will adapt the position
3361cdf0e10cSrcweir     // and size of the user interface elements.
3362cdf0e10cSrcweir     if ( !bLocked && !bLayoutInProgress )
3363cdf0e10cSrcweir     {
3364cdf0e10cSrcweir         bool                           bNotify( false );
3365cdf0e10cSrcweir         uno::Reference< awt::XWindow > xWindow( aEvent.Source, uno::UNO_QUERY );
3366cdf0e10cSrcweir 
3367cdf0e10cSrcweir         UIElement aUIElement = implts_findToolbar( aEvent.Source );
3368cdf0e10cSrcweir         if ( aUIElement.m_xUIElement.is() )
3369cdf0e10cSrcweir         {
3370cdf0e10cSrcweir             if ( aUIElement.m_bFloating )
3371cdf0e10cSrcweir             {
3372cdf0e10cSrcweir                 uno::Reference< awt::XWindow2 > xWindow2( xWindow, uno::UNO_QUERY );
3373cdf0e10cSrcweir 
3374cdf0e10cSrcweir                 if( xWindow2.is() )
3375cdf0e10cSrcweir                 {
3376cdf0e10cSrcweir                     awt::Rectangle aPos     = xWindow2->getPosSize();
3377cdf0e10cSrcweir                     awt::Size      aSize    = xWindow2->getOutputSize();   // always use output size for consistency
3378cdf0e10cSrcweir                     bool           bVisible = xWindow2->isVisible();
3379cdf0e10cSrcweir 
3380cdf0e10cSrcweir                     // update element data
3381cdf0e10cSrcweir                     aUIElement.m_aFloatingData.m_aPos  = ::Point( aPos.X, aPos.Y );
3382cdf0e10cSrcweir                     aUIElement.m_aFloatingData.m_aSize = ::Size( aSize.Width, aSize.Height );
3383cdf0e10cSrcweir                     aUIElement.m_bVisible              = bVisible;
3384cdf0e10cSrcweir                 }
3385cdf0e10cSrcweir 
3386cdf0e10cSrcweir                 implts_writeWindowStateData( aUIElement );
3387cdf0e10cSrcweir             }
3388cdf0e10cSrcweir             else
3389cdf0e10cSrcweir             {
3390cdf0e10cSrcweir                 implts_setLayoutDirty();
3391cdf0e10cSrcweir                 bNotify = true;
3392cdf0e10cSrcweir             }
3393cdf0e10cSrcweir         }
3394cdf0e10cSrcweir 
3395cdf0e10cSrcweir         if ( bNotify )
3396cdf0e10cSrcweir             m_pParentLayouter->requestLayout( ILayoutNotifications::HINT_TOOLBARSPACE_HAS_CHANGED );
3397cdf0e10cSrcweir     }
3398cdf0e10cSrcweir }
3399cdf0e10cSrcweir 
3400cdf0e10cSrcweir void SAL_CALL ToolbarLayoutManager::windowMoved( const awt::WindowEvent& /*aEvent*/ )
3401cdf0e10cSrcweir throw( uno::RuntimeException )
3402cdf0e10cSrcweir {
3403cdf0e10cSrcweir }
3404cdf0e10cSrcweir 
3405cdf0e10cSrcweir void SAL_CALL ToolbarLayoutManager::windowShown( const lang::EventObject& /*aEvent*/ )
3406cdf0e10cSrcweir throw( uno::RuntimeException )
3407cdf0e10cSrcweir {
3408cdf0e10cSrcweir }
3409cdf0e10cSrcweir 
3410cdf0e10cSrcweir void SAL_CALL ToolbarLayoutManager::windowHidden( const lang::EventObject& /*aEvent*/ )
3411cdf0e10cSrcweir throw( uno::RuntimeException )
3412cdf0e10cSrcweir {
3413cdf0e10cSrcweir }
3414cdf0e10cSrcweir 
3415cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------
3416cdf0e10cSrcweir //  XDockableWindowListener
3417cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------
3418cdf0e10cSrcweir void SAL_CALL ToolbarLayoutManager::startDocking( const awt::DockingEvent& e )
3419cdf0e10cSrcweir throw (uno::RuntimeException)
3420cdf0e10cSrcweir {
3421cdf0e10cSrcweir     bool bWinFound( false );
3422cdf0e10cSrcweir 
3423cdf0e10cSrcweir     ReadGuard aReadGuard( m_aLock );
3424cdf0e10cSrcweir     uno::Reference< awt::XWindow2 > xContainerWindow( m_xContainerWindow );
3425cdf0e10cSrcweir     uno::Reference< awt::XWindow2 > xWindow( e.Source, uno::UNO_QUERY );
3426cdf0e10cSrcweir     aReadGuard.unlock();
3427cdf0e10cSrcweir 
3428cdf0e10cSrcweir     Window* pContainerWindow( 0 );
3429cdf0e10cSrcweir     Window* pWindow( 0 );
3430cdf0e10cSrcweir     ::Point aMousePos;
3431cdf0e10cSrcweir     {
3432cdf0e10cSrcweir         vos::OGuard aGuard( Application::GetSolarMutex() );
3433cdf0e10cSrcweir         pContainerWindow = VCLUnoHelper::GetWindow( xContainerWindow );
3434cdf0e10cSrcweir         aMousePos = pContainerWindow->ScreenToOutputPixel( ::Point( e.MousePos.X, e.MousePos.Y ));
3435cdf0e10cSrcweir     }
3436cdf0e10cSrcweir 
3437cdf0e10cSrcweir     UIElement aUIElement = implts_findToolbar( e.Source );
3438cdf0e10cSrcweir 
3439cdf0e10cSrcweir     if ( aUIElement.m_xUIElement.is() && xWindow.is() )
3440cdf0e10cSrcweir     {
3441cdf0e10cSrcweir         awt::Rectangle aRect;
3442cdf0e10cSrcweir 
3443cdf0e10cSrcweir         bWinFound = true;
3444cdf0e10cSrcweir         uno::Reference< awt::XDockableWindow > xDockWindow( xWindow, uno::UNO_QUERY );
3445cdf0e10cSrcweir         if ( xDockWindow->isFloating() )
3446cdf0e10cSrcweir         {
3447cdf0e10cSrcweir             awt::Rectangle aPos  = xWindow->getPosSize();
3448cdf0e10cSrcweir             awt::Size      aSize = xWindow->getOutputSize();
3449cdf0e10cSrcweir 
3450cdf0e10cSrcweir             aUIElement.m_aFloatingData.m_aPos  = ::Point( aPos.X, aPos.Y );
3451cdf0e10cSrcweir             aUIElement.m_aFloatingData.m_aSize = ::Size( aSize.Width, aSize.Height );
3452cdf0e10cSrcweir 
3453cdf0e10cSrcweir             vos::OGuard aGuard( Application::GetSolarMutex() );
3454cdf0e10cSrcweir             pWindow = VCLUnoHelper::GetWindow( xWindow );
3455cdf0e10cSrcweir             if ( pWindow && pWindow->GetType() == WINDOW_TOOLBOX )
3456cdf0e10cSrcweir             {
3457cdf0e10cSrcweir                 ToolBox* pToolBox = (ToolBox *)pWindow;
3458cdf0e10cSrcweir                 aUIElement.m_aFloatingData.m_nLines        = pToolBox->GetFloatingLines();
3459cdf0e10cSrcweir                 aUIElement.m_aFloatingData.m_bIsHorizontal = isToolboxHorizontalAligned( pToolBox );
3460cdf0e10cSrcweir             }
3461cdf0e10cSrcweir         }
3462cdf0e10cSrcweir     }
3463cdf0e10cSrcweir 
3464cdf0e10cSrcweir     WriteGuard aWriteLock( m_aLock );
3465cdf0e10cSrcweir     m_bDockingInProgress = bWinFound;
3466cdf0e10cSrcweir     m_aDockUIElement = aUIElement;
3467cdf0e10cSrcweir     m_aDockUIElement.m_bUserActive = true;
3468cdf0e10cSrcweir     m_aStartDockMousePos = aMousePos;
3469cdf0e10cSrcweir     aWriteLock.unlock();
3470cdf0e10cSrcweir }
3471cdf0e10cSrcweir 
3472cdf0e10cSrcweir awt::DockingData SAL_CALL ToolbarLayoutManager::docking( const awt::DockingEvent& e )
3473cdf0e10cSrcweir throw (uno::RuntimeException)
3474cdf0e10cSrcweir {
3475cdf0e10cSrcweir     const sal_Int32 MAGNETIC_DISTANCE_UNDOCK = 25;
3476cdf0e10cSrcweir     const sal_Int32 MAGNETIC_DISTANCE_DOCK   = 20;
3477cdf0e10cSrcweir 
3478cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
3479cdf0e10cSrcweir     awt::DockingData                       aDockingData;
3480cdf0e10cSrcweir     uno::Reference< awt::XDockableWindow > xDockWindow( e.Source, uno::UNO_QUERY );
3481cdf0e10cSrcweir     uno::Reference< awt::XWindow >         xWindow( e.Source, uno::UNO_QUERY );
3482cdf0e10cSrcweir     uno::Reference< awt::XWindow >         xTopDockingWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_TOP] );
3483cdf0e10cSrcweir     uno::Reference< awt::XWindow >         xLeftDockingWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_LEFT] );
3484cdf0e10cSrcweir     uno::Reference< awt::XWindow >         xRightDockingWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_RIGHT] );
3485cdf0e10cSrcweir     uno::Reference< awt::XWindow >         xBottomDockingWindow( m_xDockAreaWindows[ui::DockingArea_DOCKINGAREA_BOTTOM] );
3486cdf0e10cSrcweir     uno::Reference< awt::XWindow2 >        xContainerWindow( m_xContainerWindow );
3487cdf0e10cSrcweir     UIElement                              aUIDockingElement( m_aDockUIElement );
3488cdf0e10cSrcweir     DockingOperation                       eDockingOperation( DOCKOP_ON_COLROW );
3489cdf0e10cSrcweir     bool                                   bDockingInProgress( m_bDockingInProgress );
3490cdf0e10cSrcweir     aReadLock.unlock();
3491cdf0e10cSrcweir 
3492cdf0e10cSrcweir     if ( bDockingInProgress )
3493cdf0e10cSrcweir         aDockingData.TrackingRectangle = e.TrackingRectangle;
3494cdf0e10cSrcweir 
3495cdf0e10cSrcweir     if ( bDockingInProgress && xDockWindow.is() && xWindow.is() )
3496cdf0e10cSrcweir     {
3497cdf0e10cSrcweir         try
3498cdf0e10cSrcweir         {
3499cdf0e10cSrcweir             vos::OGuard aGuard( Application::GetSolarMutex() );
3500cdf0e10cSrcweir 
3501cdf0e10cSrcweir             sal_Int16 eDockingArea( -1 ); // none
3502cdf0e10cSrcweir             sal_Int32 nMagneticZone( aUIDockingElement.m_bFloating ? MAGNETIC_DISTANCE_DOCK : MAGNETIC_DISTANCE_UNDOCK );
3503cdf0e10cSrcweir             awt::Rectangle aNewTrackingRect;
3504cdf0e10cSrcweir             ::Rectangle aTrackingRect( e.TrackingRectangle.X, e.TrackingRectangle.Y,
3505cdf0e10cSrcweir                                        ( e.TrackingRectangle.X + e.TrackingRectangle.Width ),
3506cdf0e10cSrcweir                                        ( e.TrackingRectangle.Y + e.TrackingRectangle.Height ));
3507cdf0e10cSrcweir 
3508cdf0e10cSrcweir             awt::Rectangle aTmpRect = xTopDockingWindow->getPosSize();
3509cdf0e10cSrcweir             ::Rectangle aTopDockRect( aTmpRect.X, aTmpRect.Y, aTmpRect.Width, aTmpRect.Height );
3510cdf0e10cSrcweir             ::Rectangle aHotZoneTopDockRect( implts_calcHotZoneRect( aTopDockRect, nMagneticZone ));
3511cdf0e10cSrcweir 
3512cdf0e10cSrcweir             aTmpRect = xBottomDockingWindow->getPosSize();
3513cdf0e10cSrcweir             ::Rectangle aBottomDockRect( aTmpRect.X, aTmpRect.Y, ( aTmpRect.X + aTmpRect.Width), ( aTmpRect.Y + aTmpRect.Height ));
3514cdf0e10cSrcweir             ::Rectangle aHotZoneBottomDockRect( implts_calcHotZoneRect( aBottomDockRect, nMagneticZone ));
3515cdf0e10cSrcweir 
3516cdf0e10cSrcweir             aTmpRect = xLeftDockingWindow->getPosSize();
3517cdf0e10cSrcweir             ::Rectangle aLeftDockRect( aTmpRect.X, aTmpRect.Y, ( aTmpRect.X + aTmpRect.Width ), ( aTmpRect.Y + aTmpRect.Height ));
3518cdf0e10cSrcweir             ::Rectangle aHotZoneLeftDockRect( implts_calcHotZoneRect( aLeftDockRect, nMagneticZone ));
3519cdf0e10cSrcweir 
3520cdf0e10cSrcweir             aTmpRect = xRightDockingWindow->getPosSize();
3521cdf0e10cSrcweir             ::Rectangle aRightDockRect( aTmpRect.X, aTmpRect.Y, ( aTmpRect.X + aTmpRect.Width ), ( aTmpRect.Y + aTmpRect.Height ));
3522cdf0e10cSrcweir             ::Rectangle aHotZoneRightDockRect( implts_calcHotZoneRect( aRightDockRect, nMagneticZone ));
3523cdf0e10cSrcweir 
3524cdf0e10cSrcweir             Window* pContainerWindow( VCLUnoHelper::GetWindow( xContainerWindow ) );
3525cdf0e10cSrcweir             Window* pDockingAreaWindow( 0 );
3526cdf0e10cSrcweir             ::Point aMousePos( pContainerWindow->ScreenToOutputPixel( ::Point( e.MousePos.X, e.MousePos.Y )));
3527cdf0e10cSrcweir 
3528cdf0e10cSrcweir             if ( aHotZoneTopDockRect.IsInside( aMousePos ))
3529cdf0e10cSrcweir                 eDockingArea = ui::DockingArea_DOCKINGAREA_TOP;
3530cdf0e10cSrcweir             else if ( aHotZoneBottomDockRect.IsInside( aMousePos ))
3531cdf0e10cSrcweir                 eDockingArea = ui::DockingArea_DOCKINGAREA_BOTTOM;
3532cdf0e10cSrcweir             else if ( aHotZoneLeftDockRect.IsInside( aMousePos ))
3533cdf0e10cSrcweir                 eDockingArea = ui::DockingArea_DOCKINGAREA_LEFT;
3534cdf0e10cSrcweir             else if ( aHotZoneRightDockRect.IsInside( aMousePos ))
3535cdf0e10cSrcweir                 eDockingArea = ui::DockingArea_DOCKINGAREA_RIGHT;
3536cdf0e10cSrcweir 
3537cdf0e10cSrcweir             // Higher priority for movements inside the real docking area
3538cdf0e10cSrcweir             if ( aTopDockRect.IsInside( aMousePos ))
3539cdf0e10cSrcweir                 eDockingArea = ui::DockingArea_DOCKINGAREA_TOP;
3540cdf0e10cSrcweir             else if ( aBottomDockRect.IsInside( aMousePos ))
3541cdf0e10cSrcweir                 eDockingArea = ui::DockingArea_DOCKINGAREA_BOTTOM;
3542cdf0e10cSrcweir             else if ( aLeftDockRect.IsInside( aMousePos ))
3543cdf0e10cSrcweir                 eDockingArea = ui::DockingArea_DOCKINGAREA_LEFT;
3544cdf0e10cSrcweir             else if ( aRightDockRect.IsInside( aMousePos ))
3545cdf0e10cSrcweir                 eDockingArea = ui::DockingArea_DOCKINGAREA_RIGHT;
3546cdf0e10cSrcweir 
3547cdf0e10cSrcweir             // Determine if we have a toolbar and set alignment according to the docking area!
3548cdf0e10cSrcweir             Window*  pWindow = VCLUnoHelper::GetWindow( xWindow );
3549cdf0e10cSrcweir             ToolBox* pToolBox = 0;
3550cdf0e10cSrcweir             if ( pWindow && pWindow->GetType() == WINDOW_TOOLBOX )
3551cdf0e10cSrcweir                 pToolBox = (ToolBox *)pWindow;
3552cdf0e10cSrcweir 
3553cdf0e10cSrcweir             if ( eDockingArea != -1 )
3554cdf0e10cSrcweir             {
3555cdf0e10cSrcweir                 if ( eDockingArea == ui::DockingArea_DOCKINGAREA_TOP )
3556cdf0e10cSrcweir                 {
3557cdf0e10cSrcweir                     aUIDockingElement.m_aDockedData.m_nDockedArea = ui::DockingArea_DOCKINGAREA_TOP;
3558cdf0e10cSrcweir                     aUIDockingElement.m_bFloating = false;
3559cdf0e10cSrcweir                     pDockingAreaWindow = VCLUnoHelper::GetWindow( xTopDockingWindow );
3560cdf0e10cSrcweir                 }
3561cdf0e10cSrcweir                 else if ( eDockingArea == ui::DockingArea_DOCKINGAREA_BOTTOM )
3562cdf0e10cSrcweir                 {
3563cdf0e10cSrcweir                     aUIDockingElement.m_aDockedData.m_nDockedArea = ui::DockingArea_DOCKINGAREA_BOTTOM;
3564cdf0e10cSrcweir                     aUIDockingElement.m_bFloating = false;
3565cdf0e10cSrcweir                     pDockingAreaWindow = VCLUnoHelper::GetWindow( xBottomDockingWindow );
3566cdf0e10cSrcweir                 }
3567cdf0e10cSrcweir                 else if ( eDockingArea == ui::DockingArea_DOCKINGAREA_LEFT )
3568cdf0e10cSrcweir                 {
3569cdf0e10cSrcweir                     aUIDockingElement.m_aDockedData.m_nDockedArea = ui::DockingArea_DOCKINGAREA_LEFT;
3570cdf0e10cSrcweir                     aUIDockingElement.m_bFloating = false;
3571cdf0e10cSrcweir                     pDockingAreaWindow = VCLUnoHelper::GetWindow( xLeftDockingWindow );
3572cdf0e10cSrcweir                 }
3573cdf0e10cSrcweir                 else if ( eDockingArea == ui::DockingArea_DOCKINGAREA_RIGHT )
3574cdf0e10cSrcweir                 {
3575cdf0e10cSrcweir                     aUIDockingElement.m_aDockedData.m_nDockedArea = ui::DockingArea_DOCKINGAREA_RIGHT;
3576cdf0e10cSrcweir                     aUIDockingElement.m_bFloating = false;
3577cdf0e10cSrcweir                     pDockingAreaWindow = VCLUnoHelper::GetWindow( xRightDockingWindow );
3578cdf0e10cSrcweir                 }
3579cdf0e10cSrcweir 
3580cdf0e10cSrcweir                 ::Point aOutputPos = pContainerWindow->ScreenToOutputPixel( aTrackingRect.TopLeft() );
3581cdf0e10cSrcweir                 aTrackingRect.SetPos( aOutputPos );
3582cdf0e10cSrcweir 
3583cdf0e10cSrcweir                 ::Rectangle aNewDockingRect( aTrackingRect );
3584cdf0e10cSrcweir                 implts_calcDockingPosSize( aUIDockingElement, eDockingOperation, aNewDockingRect, aMousePos );
3585cdf0e10cSrcweir 
3586cdf0e10cSrcweir                 ::Point aScreenPos = pContainerWindow->OutputToScreenPixel( aNewDockingRect.TopLeft() );
3587cdf0e10cSrcweir                 aNewTrackingRect = awt::Rectangle( aScreenPos.X(), aScreenPos.Y(),
3588cdf0e10cSrcweir                                                    aNewDockingRect.getWidth(), aNewDockingRect.getHeight() );
3589cdf0e10cSrcweir                 aDockingData.TrackingRectangle = aNewTrackingRect;
3590cdf0e10cSrcweir             }
3591cdf0e10cSrcweir             else if ( pToolBox && bDockingInProgress )
3592cdf0e10cSrcweir             {
3593cdf0e10cSrcweir                 bool bIsHorizontal = isToolboxHorizontalAligned( pToolBox );
3594cdf0e10cSrcweir                 ::Size aFloatSize  = aUIDockingElement.m_aFloatingData.m_aSize;
3595cdf0e10cSrcweir                 if ( aFloatSize.Width() > 0 && aFloatSize.Height() > 0 )
3596cdf0e10cSrcweir                 {
3597cdf0e10cSrcweir                     aUIDockingElement.m_aFloatingData.m_aPos = pContainerWindow->ScreenToOutputPixel(
3598cdf0e10cSrcweir                                                                 ::Point( e.MousePos.X, e.MousePos.Y ));
3599cdf0e10cSrcweir                     aDockingData.TrackingRectangle.Height = aFloatSize.Height();
3600cdf0e10cSrcweir                     aDockingData.TrackingRectangle.Width  = aFloatSize.Width();
3601cdf0e10cSrcweir                 }
3602cdf0e10cSrcweir                 else
3603cdf0e10cSrcweir                 {
3604cdf0e10cSrcweir                     aFloatSize = pToolBox->CalcWindowSizePixel();
3605cdf0e10cSrcweir                     if ( !bIsHorizontal )
3606cdf0e10cSrcweir                     {
3607cdf0e10cSrcweir                         // Floating toolbars are always horizontal aligned! We have to swap
3608cdf0e10cSrcweir                         // width/height if we have a vertical aligned toolbar.
3609cdf0e10cSrcweir                         sal_Int32 nTemp = aFloatSize.Height();
3610cdf0e10cSrcweir                         aFloatSize.Height() = aFloatSize.Width();
3611cdf0e10cSrcweir                         aFloatSize.Width()  = nTemp;
3612cdf0e10cSrcweir                     }
3613cdf0e10cSrcweir 
3614cdf0e10cSrcweir                     aDockingData.TrackingRectangle.Height = aFloatSize.Height();
3615cdf0e10cSrcweir                     aDockingData.TrackingRectangle.Width  = aFloatSize.Width();
3616cdf0e10cSrcweir 
3617cdf0e10cSrcweir                     // For the first time we don't have any data about the floating size of a toolbar.
3618cdf0e10cSrcweir                     // We calculate it and store it for later use.
3619cdf0e10cSrcweir                     aUIDockingElement.m_aFloatingData.m_aPos = pContainerWindow->ScreenToOutputPixel(::Point( e.MousePos.X, e.MousePos.Y ));
3620cdf0e10cSrcweir                     aUIDockingElement.m_aFloatingData.m_aSize         = aFloatSize;
3621cdf0e10cSrcweir                     aUIDockingElement.m_aFloatingData.m_nLines        = pToolBox->GetFloatingLines();
3622cdf0e10cSrcweir                     aUIDockingElement.m_aFloatingData.m_bIsHorizontal = isToolboxHorizontalAligned( pToolBox );
3623cdf0e10cSrcweir                 }
3624cdf0e10cSrcweir                 aDockingData.TrackingRectangle.X = e.MousePos.X;
3625cdf0e10cSrcweir                 aDockingData.TrackingRectangle.Y = e.MousePos.Y;
3626cdf0e10cSrcweir             }
3627cdf0e10cSrcweir 
3628cdf0e10cSrcweir             aDockingData.bFloating = ( eDockingArea == -1 );
3629cdf0e10cSrcweir 
3630cdf0e10cSrcweir             // Write current data to the member docking progress data
3631cdf0e10cSrcweir             WriteGuard aWriteLock( m_aLock );
3632cdf0e10cSrcweir             m_aDockUIElement.m_bFloating = aDockingData.bFloating;
3633cdf0e10cSrcweir             if ( !aDockingData.bFloating )
3634cdf0e10cSrcweir             {
3635cdf0e10cSrcweir                 m_aDockUIElement.m_aDockedData = aUIDockingElement.m_aDockedData;
3636cdf0e10cSrcweir                 m_eDockOperation               = eDockingOperation;
3637cdf0e10cSrcweir             }
3638cdf0e10cSrcweir             else
3639cdf0e10cSrcweir                 m_aDockUIElement.m_aFloatingData = aUIDockingElement.m_aFloatingData;
3640cdf0e10cSrcweir             aWriteLock.unlock();
3641cdf0e10cSrcweir         }
3642cdf0e10cSrcweir         catch ( uno::Exception& ) {}
3643cdf0e10cSrcweir     }
3644cdf0e10cSrcweir 
3645cdf0e10cSrcweir     return aDockingData;
3646cdf0e10cSrcweir }
3647cdf0e10cSrcweir 
3648cdf0e10cSrcweir void SAL_CALL ToolbarLayoutManager::endDocking( const awt::EndDockingEvent& e )
3649cdf0e10cSrcweir throw (uno::RuntimeException)
3650cdf0e10cSrcweir {
3651cdf0e10cSrcweir     bool bDockingInProgress( false );
3652cdf0e10cSrcweir     bool bStartDockFloated( false );
3653cdf0e10cSrcweir     bool bFloating( false );
3654cdf0e10cSrcweir     UIElement aUIDockingElement;
3655cdf0e10cSrcweir 
3656cdf0e10cSrcweir     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
3657cdf0e10cSrcweir     WriteGuard aWriteLock( m_aLock );
3658cdf0e10cSrcweir     bDockingInProgress = m_bDockingInProgress;
3659cdf0e10cSrcweir     aUIDockingElement  = m_aDockUIElement;
3660cdf0e10cSrcweir     bFloating          = aUIDockingElement.m_bFloating;
3661cdf0e10cSrcweir 
3662cdf0e10cSrcweir     UIElement& rUIElement = impl_findToolbar( aUIDockingElement.m_aName );
3663cdf0e10cSrcweir     if ( rUIElement.m_aName == aUIDockingElement.m_aName )
3664cdf0e10cSrcweir     {
3665cdf0e10cSrcweir         if ( aUIDockingElement.m_bFloating )
3666cdf0e10cSrcweir         {
3667cdf0e10cSrcweir             // Write last position into position data
3668cdf0e10cSrcweir             uno::Reference< awt::XWindow > xWindow( aUIDockingElement.m_xUIElement->getRealInterface(), uno::UNO_QUERY );
3669cdf0e10cSrcweir             rUIElement.m_aFloatingData = aUIDockingElement.m_aFloatingData;
3670cdf0e10cSrcweir             awt::Rectangle aTmpRect = xWindow->getPosSize();
3671cdf0e10cSrcweir             rUIElement.m_aFloatingData.m_aPos = ::Point( aTmpRect.X, aTmpRect.Y );
3672cdf0e10cSrcweir             // make changes also for our local data as we use it to make data persistent
3673cdf0e10cSrcweir             aUIDockingElement.m_aFloatingData = rUIElement.m_aFloatingData;
3674cdf0e10cSrcweir         }
3675cdf0e10cSrcweir         else
3676cdf0e10cSrcweir         {
3677cdf0e10cSrcweir             rUIElement.m_aDockedData = aUIDockingElement.m_aDockedData;
3678cdf0e10cSrcweir             rUIElement.m_aFloatingData.m_aSize = aUIDockingElement.m_aFloatingData.m_aSize;
3679cdf0e10cSrcweir 
3680cdf0e10cSrcweir             if ( m_eDockOperation != DOCKOP_ON_COLROW )
3681cdf0e10cSrcweir             {
3682cdf0e10cSrcweir                 // we have to renumber our row/column data to insert a new row/column
3683cdf0e10cSrcweir                 implts_renumberRowColumnData((ui::DockingArea)aUIDockingElement.m_aDockedData.m_nDockedArea, m_eDockOperation, aUIDockingElement );
3684cdf0e10cSrcweir             }
3685cdf0e10cSrcweir         }
3686cdf0e10cSrcweir 
3687cdf0e10cSrcweir         bStartDockFloated        = rUIElement.m_bFloating;
3688cdf0e10cSrcweir         rUIElement.m_bFloating   = m_aDockUIElement.m_bFloating;
3689cdf0e10cSrcweir         rUIElement.m_bUserActive = true;
3690cdf0e10cSrcweir     }
3691cdf0e10cSrcweir 
3692cdf0e10cSrcweir     // reset member for next docking operation
3693cdf0e10cSrcweir     m_aDockUIElement.m_xUIElement.clear();
3694cdf0e10cSrcweir     m_eDockOperation = DOCKOP_ON_COLROW;
3695cdf0e10cSrcweir     aWriteLock.unlock();
3696cdf0e10cSrcweir     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
3697cdf0e10cSrcweir 
3698cdf0e10cSrcweir     implts_writeWindowStateData( aUIDockingElement );
3699cdf0e10cSrcweir 
3700cdf0e10cSrcweir     if ( bDockingInProgress )
3701cdf0e10cSrcweir     {
3702cdf0e10cSrcweir         vos::OGuard aGuard( Application::GetSolarMutex() );
3703cdf0e10cSrcweir         Window*  pWindow = VCLUnoHelper::GetWindow( uno::Reference< awt::XWindow >( e.Source, uno::UNO_QUERY ));
3704cdf0e10cSrcweir         ToolBox* pToolBox = 0;
3705cdf0e10cSrcweir         if ( pWindow && pWindow->GetType() == WINDOW_TOOLBOX )
3706cdf0e10cSrcweir             pToolBox = (ToolBox *)pWindow;
3707cdf0e10cSrcweir 
3708cdf0e10cSrcweir         if ( pToolBox )
3709cdf0e10cSrcweir         {
3710cdf0e10cSrcweir             if( e.bFloating )
3711cdf0e10cSrcweir             {
3712cdf0e10cSrcweir                 if ( aUIDockingElement.m_aFloatingData.m_bIsHorizontal )
3713cdf0e10cSrcweir                     pToolBox->SetAlign( WINDOWALIGN_TOP );
3714cdf0e10cSrcweir                 else
3715cdf0e10cSrcweir                     pToolBox->SetAlign( WINDOWALIGN_LEFT );
3716cdf0e10cSrcweir             }
3717cdf0e10cSrcweir             else
3718cdf0e10cSrcweir             {
3719cdf0e10cSrcweir                 ::Size aSize;
3720cdf0e10cSrcweir 
3721cdf0e10cSrcweir                 pToolBox->SetAlign( ImplConvertAlignment( aUIDockingElement.m_aDockedData.m_nDockedArea) );
3722cdf0e10cSrcweir 
3723cdf0e10cSrcweir                 // Docked toolbars have always one line
3724cdf0e10cSrcweir                 aSize = pToolBox->CalcWindowSizePixel( 1 );
3725cdf0e10cSrcweir 
3726cdf0e10cSrcweir                 // Lock layouting updates as our listener would be called due to SetSizePixel
3727cdf0e10cSrcweir                 pToolBox->SetOutputSizePixel( aSize );
3728cdf0e10cSrcweir             }
3729cdf0e10cSrcweir         }
3730cdf0e10cSrcweir     }
3731cdf0e10cSrcweir 
3732cdf0e10cSrcweir     implts_sortUIElements();
3733cdf0e10cSrcweir 
3734cdf0e10cSrcweir     aWriteLock.lock();
3735cdf0e10cSrcweir     m_bDockingInProgress = sal_False;
3736cdf0e10cSrcweir     m_bLayoutDirty       = !bStartDockFloated || !bFloating;
3737cdf0e10cSrcweir     bool bNotify         = m_bLayoutDirty;
3738cdf0e10cSrcweir     aWriteLock.unlock();
3739cdf0e10cSrcweir 
3740cdf0e10cSrcweir     if ( bNotify )
3741cdf0e10cSrcweir         m_pParentLayouter->requestLayout( ILayoutNotifications::HINT_TOOLBARSPACE_HAS_CHANGED );
3742cdf0e10cSrcweir }
3743cdf0e10cSrcweir 
3744cdf0e10cSrcweir sal_Bool SAL_CALL ToolbarLayoutManager::prepareToggleFloatingMode( const lang::EventObject& e )
3745cdf0e10cSrcweir throw (uno::RuntimeException)
3746cdf0e10cSrcweir {
3747cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
3748cdf0e10cSrcweir     bool bDockingInProgress = m_bDockingInProgress;
3749cdf0e10cSrcweir     aReadLock.unlock();
3750cdf0e10cSrcweir 
3751cdf0e10cSrcweir     UIElement aUIDockingElement = implts_findToolbar( e.Source );
3752cdf0e10cSrcweir     bool      bWinFound( aUIDockingElement.m_aName.getLength() > 0 );
3753cdf0e10cSrcweir     uno::Reference< awt::XWindow > xWindow( e.Source, uno::UNO_QUERY );
3754cdf0e10cSrcweir 
3755cdf0e10cSrcweir     if ( bWinFound && xWindow.is() )
3756cdf0e10cSrcweir     {
3757cdf0e10cSrcweir         if ( !bDockingInProgress )
3758cdf0e10cSrcweir         {
3759cdf0e10cSrcweir             awt::Rectangle aRect;
3760cdf0e10cSrcweir             uno::Reference< awt::XDockableWindow > xDockWindow( xWindow, uno::UNO_QUERY );
3761cdf0e10cSrcweir             if ( xDockWindow->isFloating() )
3762cdf0e10cSrcweir             {
3763cdf0e10cSrcweir                 {
3764cdf0e10cSrcweir                     vos::OGuard aGuard( Application::GetSolarMutex() );
3765cdf0e10cSrcweir                     Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
3766cdf0e10cSrcweir                     if ( pWindow && pWindow->GetType() == WINDOW_TOOLBOX )
3767cdf0e10cSrcweir                     {
3768cdf0e10cSrcweir                         ToolBox* pToolBox = static_cast< ToolBox *>( pWindow );
3769cdf0e10cSrcweir                         aUIDockingElement.m_aFloatingData.m_aPos          = pToolBox->GetPosPixel();
3770cdf0e10cSrcweir                         aUIDockingElement.m_aFloatingData.m_aSize         = pToolBox->GetOutputSizePixel();
3771cdf0e10cSrcweir                         aUIDockingElement.m_aFloatingData.m_nLines        = pToolBox->GetFloatingLines();
3772cdf0e10cSrcweir                         aUIDockingElement.m_aFloatingData.m_bIsHorizontal = isToolboxHorizontalAligned( pToolBox );
3773cdf0e10cSrcweir                     }
3774cdf0e10cSrcweir                 }
3775cdf0e10cSrcweir 
3776cdf0e10cSrcweir                 UIElement aUIElement = implts_findToolbar( aUIDockingElement.m_aName );
3777cdf0e10cSrcweir                 if ( aUIElement.m_aName == aUIDockingElement.m_aName )
3778cdf0e10cSrcweir                     implts_setToolbar( aUIDockingElement );
3779cdf0e10cSrcweir             }
3780cdf0e10cSrcweir         }
3781cdf0e10cSrcweir     }
3782cdf0e10cSrcweir 
3783cdf0e10cSrcweir     return sal_True;
3784cdf0e10cSrcweir }
3785cdf0e10cSrcweir 
3786cdf0e10cSrcweir void SAL_CALL ToolbarLayoutManager::toggleFloatingMode( const lang::EventObject& e )
3787cdf0e10cSrcweir throw (uno::RuntimeException)
3788cdf0e10cSrcweir {
3789cdf0e10cSrcweir     UIElement aUIDockingElement;
3790cdf0e10cSrcweir 
3791cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
3792cdf0e10cSrcweir     bool bDockingInProgress( m_bDockingInProgress );
3793cdf0e10cSrcweir     if ( bDockingInProgress )
3794cdf0e10cSrcweir         aUIDockingElement = m_aDockUIElement;
3795cdf0e10cSrcweir     aReadLock.unlock();
3796cdf0e10cSrcweir 
3797cdf0e10cSrcweir     Window*  pWindow( 0 );
3798cdf0e10cSrcweir     ToolBox* pToolBox( 0 );
3799cdf0e10cSrcweir     uno::Reference< awt::XWindow2 > xWindow;
3800cdf0e10cSrcweir 
3801cdf0e10cSrcweir     {
3802cdf0e10cSrcweir         vos::OGuard aGuard( Application::GetSolarMutex() );
3803cdf0e10cSrcweir         xWindow = uno::Reference< awt::XWindow2 >( e.Source, uno::UNO_QUERY );
3804cdf0e10cSrcweir         pWindow = VCLUnoHelper::GetWindow( xWindow );
3805cdf0e10cSrcweir 
3806cdf0e10cSrcweir         if ( pWindow && pWindow->GetType() == WINDOW_TOOLBOX )
3807cdf0e10cSrcweir             pToolBox = (ToolBox *)pWindow;
3808cdf0e10cSrcweir     }
3809cdf0e10cSrcweir 
3810cdf0e10cSrcweir     if ( !bDockingInProgress )
3811cdf0e10cSrcweir     {
3812cdf0e10cSrcweir         aUIDockingElement = implts_findToolbar( e.Source );
3813cdf0e10cSrcweir         bool bWinFound = ( aUIDockingElement.m_aName.getLength() > 0 );
3814cdf0e10cSrcweir 
3815cdf0e10cSrcweir         if ( bWinFound && xWindow.is() )
3816cdf0e10cSrcweir         {
3817cdf0e10cSrcweir             aUIDockingElement.m_bFloating   = !aUIDockingElement.m_bFloating;
3818cdf0e10cSrcweir             aUIDockingElement.m_bUserActive = true;
3819cdf0e10cSrcweir 
3820cdf0e10cSrcweir             implts_setLayoutInProgress( true );
3821cdf0e10cSrcweir             if ( aUIDockingElement.m_bFloating )
3822cdf0e10cSrcweir             {
3823cdf0e10cSrcweir                 vos::OGuard aGuard( Application::GetSolarMutex() );
3824cdf0e10cSrcweir                 if ( pToolBox )
3825cdf0e10cSrcweir                 {
3826cdf0e10cSrcweir                     pToolBox->SetLineCount( aUIDockingElement.m_aFloatingData.m_nLines );
3827cdf0e10cSrcweir                     if ( aUIDockingElement.m_aFloatingData.m_bIsHorizontal )
3828cdf0e10cSrcweir                         pToolBox->SetAlign( WINDOWALIGN_TOP );
3829cdf0e10cSrcweir                     else
3830cdf0e10cSrcweir                         pToolBox->SetAlign( WINDOWALIGN_LEFT );
3831cdf0e10cSrcweir                 }
3832cdf0e10cSrcweir 
3833cdf0e10cSrcweir                 bool bUndefPos = hasDefaultPosValue( aUIDockingElement.m_aFloatingData.m_aPos );
3834cdf0e10cSrcweir                 bool bSetSize = !hasEmptySize( aUIDockingElement.m_aFloatingData.m_aSize );
3835cdf0e10cSrcweir 
3836cdf0e10cSrcweir                 if ( bUndefPos )
3837cdf0e10cSrcweir                     aUIDockingElement.m_aFloatingData.m_aPos = implts_findNextCascadeFloatingPos();
3838cdf0e10cSrcweir 
3839cdf0e10cSrcweir                 if ( !bSetSize )
3840cdf0e10cSrcweir                 {
3841cdf0e10cSrcweir                     if ( pToolBox )
3842cdf0e10cSrcweir                         aUIDockingElement.m_aFloatingData.m_aSize = pToolBox->CalcFloatingWindowSizePixel();
3843cdf0e10cSrcweir                     else
3844cdf0e10cSrcweir                         aUIDockingElement.m_aFloatingData.m_aSize = pWindow->GetOutputSizePixel();
3845cdf0e10cSrcweir                 }
3846cdf0e10cSrcweir 
3847cdf0e10cSrcweir                 xWindow->setPosSize( aUIDockingElement.m_aFloatingData.m_aPos.X(),
3848cdf0e10cSrcweir                                      aUIDockingElement.m_aFloatingData.m_aPos.Y(),
3849cdf0e10cSrcweir                                      0, 0, awt::PosSize::POS );
3850cdf0e10cSrcweir                 xWindow->setOutputSize( AWTSize( aUIDockingElement.m_aFloatingData.m_aSize ) );
3851cdf0e10cSrcweir             }
3852cdf0e10cSrcweir             else
3853cdf0e10cSrcweir             {
3854cdf0e10cSrcweir                 if ( isDefaultPos( aUIDockingElement.m_aDockedData.m_aPos ))
3855cdf0e10cSrcweir                 {
3856cdf0e10cSrcweir                     // Docking on its default position without a preset position -
3857cdf0e10cSrcweir                     // we have to find a good place for it.
3858cdf0e10cSrcweir                     ::Point aPixelPos;
3859cdf0e10cSrcweir                     ::Point aDockPos;
3860cdf0e10cSrcweir                     ::Size  aSize;
3861cdf0e10cSrcweir 
3862cdf0e10cSrcweir                     {
3863cdf0e10cSrcweir                         vos::OGuard aGuard( Application::GetSolarMutex() );
3864cdf0e10cSrcweir                         if ( pToolBox )
3865cdf0e10cSrcweir                             aSize = pToolBox->CalcWindowSizePixel( 1, ImplConvertAlignment( aUIDockingElement.m_aDockedData.m_nDockedArea ) );
3866cdf0e10cSrcweir                         else
3867cdf0e10cSrcweir                             aSize = pWindow->GetSizePixel();
3868cdf0e10cSrcweir                     }
3869cdf0e10cSrcweir 
3870cdf0e10cSrcweir                     implts_findNextDockingPos((ui::DockingArea)aUIDockingElement.m_aDockedData.m_nDockedArea, aSize, aDockPos, aPixelPos );
3871cdf0e10cSrcweir                     aUIDockingElement.m_aDockedData.m_aPos = aDockPos;
3872cdf0e10cSrcweir                 }
3873cdf0e10cSrcweir 
3874cdf0e10cSrcweir                 vos::OGuard aGuard( Application::GetSolarMutex() );
3875cdf0e10cSrcweir                 if ( pToolBox )
3876cdf0e10cSrcweir                 {
3877cdf0e10cSrcweir                     pToolBox->SetAlign( ImplConvertAlignment( aUIDockingElement.m_aDockedData.m_nDockedArea) );
3878cdf0e10cSrcweir                     ::Size aSize = pToolBox->CalcWindowSizePixel( 1 );
3879cdf0e10cSrcweir                     awt::Rectangle aRect = xWindow->getPosSize();
3880cdf0e10cSrcweir                     xWindow->setPosSize( aRect.X, aRect.Y, 0, 0, awt::PosSize::POS );
3881cdf0e10cSrcweir                     xWindow->setOutputSize( AWTSize( aSize ) );
3882cdf0e10cSrcweir                 }
3883cdf0e10cSrcweir             }
3884cdf0e10cSrcweir 
3885cdf0e10cSrcweir             implts_setLayoutInProgress( false );
3886cdf0e10cSrcweir             implts_setToolbar( aUIDockingElement );
3887cdf0e10cSrcweir             implts_writeWindowStateData( aUIDockingElement );
3888cdf0e10cSrcweir             implts_sortUIElements();
3889cdf0e10cSrcweir             implts_setLayoutDirty();
3890cdf0e10cSrcweir 
3891cdf0e10cSrcweir             aReadLock.lock();
3892cdf0e10cSrcweir             ILayoutNotifications* pParentLayouter( m_pParentLayouter );
3893cdf0e10cSrcweir             aReadLock.unlock();
3894cdf0e10cSrcweir 
3895cdf0e10cSrcweir             if ( pParentLayouter )
3896cdf0e10cSrcweir                 pParentLayouter->requestLayout( ILayoutNotifications::HINT_TOOLBARSPACE_HAS_CHANGED );
3897cdf0e10cSrcweir         }
3898cdf0e10cSrcweir     }
3899cdf0e10cSrcweir     else
3900cdf0e10cSrcweir     {
3901cdf0e10cSrcweir         vos::OGuard aGuard( Application::GetSolarMutex() );
3902cdf0e10cSrcweir         if ( pToolBox )
3903cdf0e10cSrcweir         {
3904cdf0e10cSrcweir             if ( aUIDockingElement.m_bFloating )
3905cdf0e10cSrcweir             {
3906cdf0e10cSrcweir                 if ( aUIDockingElement.m_aFloatingData.m_bIsHorizontal )
3907cdf0e10cSrcweir                     pToolBox->SetAlign( WINDOWALIGN_TOP );
3908cdf0e10cSrcweir                 else
3909cdf0e10cSrcweir                     pToolBox->SetAlign( WINDOWALIGN_LEFT );
3910cdf0e10cSrcweir             }
3911cdf0e10cSrcweir             else
3912cdf0e10cSrcweir                 pToolBox->SetAlign( ImplConvertAlignment( aUIDockingElement.m_aDockedData.m_nDockedArea) );
3913cdf0e10cSrcweir         }
3914cdf0e10cSrcweir     }
3915cdf0e10cSrcweir }
3916cdf0e10cSrcweir 
3917cdf0e10cSrcweir void SAL_CALL ToolbarLayoutManager::closed( const lang::EventObject& e )
3918cdf0e10cSrcweir throw (uno::RuntimeException)
3919cdf0e10cSrcweir {
3920cdf0e10cSrcweir     rtl::OUString aName;
3921cdf0e10cSrcweir     UIElement     aUIElement;
3922cdf0e10cSrcweir     UIElementVector::iterator pIter;
3923cdf0e10cSrcweir 
3924cdf0e10cSrcweir     WriteGuard aWriteLock( m_aLock );
3925cdf0e10cSrcweir     for ( pIter = m_aUIElements.begin(); pIter != m_aUIElements.end(); pIter++ )
3926cdf0e10cSrcweir     {
3927cdf0e10cSrcweir         uno::Reference< ui::XUIElement > xUIElement( pIter->m_xUIElement );
3928cdf0e10cSrcweir         if ( xUIElement.is() )
3929cdf0e10cSrcweir         {
3930cdf0e10cSrcweir             uno::Reference< uno::XInterface > xIfac( xUIElement->getRealInterface(), uno::UNO_QUERY );
3931cdf0e10cSrcweir             if ( xIfac == e.Source )
3932cdf0e10cSrcweir             {
3933cdf0e10cSrcweir                 aName = pIter->m_aName;
3934cdf0e10cSrcweir 
3935cdf0e10cSrcweir                 // user closes a toolbar =>
3936cdf0e10cSrcweir                 // context sensitive toolbar: only destroy toolbar and store state.
3937cdf0e10cSrcweir                 // context sensitive toolbar: make it invisible, store state and destroy it.
3938cdf0e10cSrcweir                 if ( !pIter->m_bContextSensitive )
3939cdf0e10cSrcweir                     pIter->m_bVisible = sal_False;
3940cdf0e10cSrcweir 
3941cdf0e10cSrcweir                 aUIElement = *pIter;
3942cdf0e10cSrcweir                 break;
3943cdf0e10cSrcweir             }
3944cdf0e10cSrcweir         }
3945cdf0e10cSrcweir     }
3946cdf0e10cSrcweir     aWriteLock.unlock();
3947cdf0e10cSrcweir 
3948cdf0e10cSrcweir     // destroy element
3949cdf0e10cSrcweir     if ( aName.getLength() > 0 )
3950cdf0e10cSrcweir     {
3951cdf0e10cSrcweir         implts_writeWindowStateData( aUIElement );
3952cdf0e10cSrcweir         destroyToolbar( aName );
3953cdf0e10cSrcweir     }
3954cdf0e10cSrcweir }
3955cdf0e10cSrcweir 
3956cdf0e10cSrcweir void SAL_CALL ToolbarLayoutManager::endPopupMode( const awt::EndPopupModeEvent& /*e*/ )
3957cdf0e10cSrcweir throw (uno::RuntimeException)
3958cdf0e10cSrcweir {
3959cdf0e10cSrcweir }
3960cdf0e10cSrcweir 
3961cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------
3962cdf0e10cSrcweir //  XUIConfigurationListener
3963cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------
3964cdf0e10cSrcweir void SAL_CALL ToolbarLayoutManager::elementInserted( const ui::ConfigurationEvent& rEvent )
3965cdf0e10cSrcweir throw (uno::RuntimeException)
3966cdf0e10cSrcweir {
3967cdf0e10cSrcweir     UIElement aUIElement = implts_findToolbar( rEvent.ResourceURL );
3968cdf0e10cSrcweir 
3969cdf0e10cSrcweir     uno::Reference< ui::XUIElementSettings > xElementSettings( aUIElement.m_xUIElement, uno::UNO_QUERY );
3970cdf0e10cSrcweir     if ( xElementSettings.is() )
3971cdf0e10cSrcweir     {
3972cdf0e10cSrcweir         ::rtl::OUString aConfigSourcePropName( RTL_CONSTASCII_USTRINGPARAM( "ConfigurationSource" ));
3973cdf0e10cSrcweir         uno::Reference< beans::XPropertySet > xPropSet( xElementSettings, uno::UNO_QUERY );
3974cdf0e10cSrcweir         if ( xPropSet.is() )
3975cdf0e10cSrcweir         {
3976cdf0e10cSrcweir             if ( rEvent.Source == uno::Reference< uno::XInterface >( m_xDocCfgMgr, uno::UNO_QUERY ))
3977cdf0e10cSrcweir                 xPropSet->setPropertyValue( aConfigSourcePropName, makeAny( m_xDocCfgMgr ));
3978cdf0e10cSrcweir         }
3979cdf0e10cSrcweir         xElementSettings->updateSettings();
3980cdf0e10cSrcweir     }
3981cdf0e10cSrcweir     else
3982cdf0e10cSrcweir     {
3983cdf0e10cSrcweir         ::rtl::OUString aElementType;
3984cdf0e10cSrcweir         ::rtl::OUString aElementName;
3985cdf0e10cSrcweir         parseResourceURL( rEvent.ResourceURL, aElementType, aElementName );
3986cdf0e10cSrcweir         if ( aElementName.indexOf( m_aCustomTbxPrefix ) != -1 )
3987cdf0e10cSrcweir         {
3988cdf0e10cSrcweir             // custom toolbar must be directly created, shown and layouted!
3989cdf0e10cSrcweir             createToolbar( rEvent.ResourceURL );
3990cdf0e10cSrcweir             uno::Reference< ui::XUIElement > xUIElement = getToolbar( rEvent.ResourceURL );
3991cdf0e10cSrcweir             if ( xUIElement.is() )
3992cdf0e10cSrcweir             {
3993cdf0e10cSrcweir                 ::rtl::OUString                               aUIName;
3994cdf0e10cSrcweir                 uno::Reference< ui::XUIConfigurationManager > xCfgMgr;
3995cdf0e10cSrcweir                 uno::Reference< beans::XPropertySet >         xPropSet;
3996cdf0e10cSrcweir 
3997cdf0e10cSrcweir                 try
3998cdf0e10cSrcweir                 {
3999cdf0e10cSrcweir                     xCfgMgr  = uno::Reference< ui::XUIConfigurationManager >( rEvent.Source, uno::UNO_QUERY );
4000cdf0e10cSrcweir                     xPropSet = uno::Reference< beans::XPropertySet >( xCfgMgr->getSettings( rEvent.ResourceURL, sal_False ), uno::UNO_QUERY );
4001cdf0e10cSrcweir 
4002cdf0e10cSrcweir                     if ( xPropSet.is() )
4003cdf0e10cSrcweir                         xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UIName" ))) >>= aUIName;
4004cdf0e10cSrcweir                 }
4005cdf0e10cSrcweir                 catch ( container::NoSuchElementException& ) {}
4006cdf0e10cSrcweir                 catch ( beans::UnknownPropertyException& ) {}
4007cdf0e10cSrcweir                 catch ( lang::WrappedTargetException& ) {}
4008cdf0e10cSrcweir 
4009cdf0e10cSrcweir                 {
4010cdf0e10cSrcweir                     vos::OGuard aGuard( Application::GetSolarMutex() );
4011cdf0e10cSrcweir                     Window* pWindow = getWindowFromXUIElement( xUIElement );
4012cdf0e10cSrcweir                     if ( pWindow  )
4013cdf0e10cSrcweir                         pWindow->SetText( aUIName );
4014cdf0e10cSrcweir                 }
4015cdf0e10cSrcweir 
4016cdf0e10cSrcweir                 showToolbar( rEvent.ResourceURL );
4017cdf0e10cSrcweir             }
4018cdf0e10cSrcweir         }
4019cdf0e10cSrcweir     }
4020cdf0e10cSrcweir }
4021cdf0e10cSrcweir 
4022cdf0e10cSrcweir void SAL_CALL ToolbarLayoutManager::elementRemoved( const ui::ConfigurationEvent& rEvent )
4023cdf0e10cSrcweir throw (uno::RuntimeException)
4024cdf0e10cSrcweir {
4025cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
4026cdf0e10cSrcweir     uno::Reference< awt::XWindow > xContainerWindow( m_xContainerWindow, uno::UNO_QUERY );
4027cdf0e10cSrcweir     uno::Reference< ui::XUIConfigurationManager > xModuleCfgMgr( m_xModuleCfgMgr );
4028cdf0e10cSrcweir     uno::Reference< ui::XUIConfigurationManager > xDocCfgMgr( m_xDocCfgMgr );
4029cdf0e10cSrcweir     aReadLock.unlock();
4030cdf0e10cSrcweir 
4031cdf0e10cSrcweir     UIElement aUIElement = implts_findToolbar( rEvent.ResourceURL );
4032cdf0e10cSrcweir     uno::Reference< ui::XUIElementSettings > xElementSettings( aUIElement.m_xUIElement, uno::UNO_QUERY );
4033cdf0e10cSrcweir     if ( xElementSettings.is() )
4034cdf0e10cSrcweir     {
4035cdf0e10cSrcweir         bool                                  bNoSettings( false );
4036cdf0e10cSrcweir         ::rtl::OUString                       aConfigSourcePropName( RTL_CONSTASCII_USTRINGPARAM( "ConfigurationSource" ));
4037cdf0e10cSrcweir         uno::Reference< uno::XInterface >     xElementCfgMgr;
4038cdf0e10cSrcweir         uno::Reference< beans::XPropertySet > xPropSet( xElementSettings, uno::UNO_QUERY );
4039cdf0e10cSrcweir 
4040cdf0e10cSrcweir         if ( xPropSet.is() )
4041cdf0e10cSrcweir             xPropSet->getPropertyValue( aConfigSourcePropName ) >>= xElementCfgMgr;
4042cdf0e10cSrcweir 
4043cdf0e10cSrcweir         if ( !xElementCfgMgr.is() )
4044cdf0e10cSrcweir             return;
4045cdf0e10cSrcweir 
4046cdf0e10cSrcweir         // Check if the same UI configuration manager has changed => check further
4047cdf0e10cSrcweir         if ( rEvent.Source == xElementCfgMgr )
4048cdf0e10cSrcweir         {
4049cdf0e10cSrcweir             // Same UI configuration manager where our element has its settings
4050cdf0e10cSrcweir             if ( rEvent.Source == uno::Reference< uno::XInterface >( xDocCfgMgr, uno::UNO_QUERY ))
4051cdf0e10cSrcweir             {
4052cdf0e10cSrcweir                 // document settings removed
4053cdf0e10cSrcweir                 if ( xModuleCfgMgr->hasSettings( rEvent.ResourceURL ))
4054cdf0e10cSrcweir                 {
4055cdf0e10cSrcweir                     xPropSet->setPropertyValue( aConfigSourcePropName, makeAny( xModuleCfgMgr ));
4056cdf0e10cSrcweir                     xElementSettings->updateSettings();
4057cdf0e10cSrcweir                     return;
4058cdf0e10cSrcweir                 }
4059cdf0e10cSrcweir             }
4060cdf0e10cSrcweir 
4061cdf0e10cSrcweir             bNoSettings = true;
4062cdf0e10cSrcweir         }
4063cdf0e10cSrcweir 
4064cdf0e10cSrcweir         // No settings anymore, element must be destroyed
4065cdf0e10cSrcweir         if ( xContainerWindow.is() && bNoSettings )
4066cdf0e10cSrcweir             destroyToolbar( rEvent.ResourceURL );
4067cdf0e10cSrcweir     }
4068cdf0e10cSrcweir }
4069cdf0e10cSrcweir 
4070cdf0e10cSrcweir void SAL_CALL ToolbarLayoutManager::elementReplaced( const ui::ConfigurationEvent& rEvent )
4071cdf0e10cSrcweir throw (uno::RuntimeException)
4072cdf0e10cSrcweir {
4073cdf0e10cSrcweir     UIElement aUIElement = implts_findToolbar( rEvent.ResourceURL );
4074cdf0e10cSrcweir 
4075cdf0e10cSrcweir     uno::Reference< ui::XUIElementSettings > xElementSettings( aUIElement.m_xUIElement, uno::UNO_QUERY );
4076cdf0e10cSrcweir     if ( xElementSettings.is() )
4077cdf0e10cSrcweir     {
4078cdf0e10cSrcweir         ::rtl::OUString                       aConfigSourcePropName( RTL_CONSTASCII_USTRINGPARAM( "ConfigurationSource" ));
4079cdf0e10cSrcweir         uno::Reference< uno::XInterface >     xElementCfgMgr;
4080cdf0e10cSrcweir         uno::Reference< beans::XPropertySet > xPropSet( xElementSettings, uno::UNO_QUERY );
4081cdf0e10cSrcweir 
4082cdf0e10cSrcweir         if ( xPropSet.is() )
4083cdf0e10cSrcweir             xPropSet->getPropertyValue( aConfigSourcePropName ) >>= xElementCfgMgr;
4084cdf0e10cSrcweir 
4085cdf0e10cSrcweir         if ( !xElementCfgMgr.is() )
4086cdf0e10cSrcweir             return;
4087cdf0e10cSrcweir 
4088cdf0e10cSrcweir         // Check if the same UI configuration manager has changed => update settings
4089cdf0e10cSrcweir         if ( rEvent.Source == xElementCfgMgr )
4090cdf0e10cSrcweir         {
4091cdf0e10cSrcweir             xElementSettings->updateSettings();
4092cdf0e10cSrcweir 
4093cdf0e10cSrcweir             WriteGuard aWriteLock( m_aLock );
4094cdf0e10cSrcweir             bool bNotify = !aUIElement.m_bFloating;
4095cdf0e10cSrcweir             m_bLayoutDirty = bNotify;
4096cdf0e10cSrcweir             ILayoutNotifications* pParentLayouter( m_pParentLayouter );
4097cdf0e10cSrcweir             aWriteLock.unlock();
4098cdf0e10cSrcweir 
4099cdf0e10cSrcweir             if ( bNotify && pParentLayouter )
4100cdf0e10cSrcweir                 pParentLayouter->requestLayout( ILayoutNotifications::HINT_TOOLBARSPACE_HAS_CHANGED );
4101cdf0e10cSrcweir         }
4102cdf0e10cSrcweir     }
4103cdf0e10cSrcweir }
4104cdf0e10cSrcweir 
4105cdf0e10cSrcweir uno::Reference< ui::XUIElement > ToolbarLayoutManager::getToolbar( const ::rtl::OUString& aName )
4106cdf0e10cSrcweir {
4107cdf0e10cSrcweir     return implts_findToolbar( aName ).m_xUIElement;
4108cdf0e10cSrcweir }
4109cdf0e10cSrcweir 
4110cdf0e10cSrcweir uno::Sequence< uno::Reference< ui::XUIElement > > ToolbarLayoutManager::getToolbars()
4111cdf0e10cSrcweir {
4112cdf0e10cSrcweir     uno::Sequence< uno::Reference< ui::XUIElement > > aSeq;
4113cdf0e10cSrcweir 
4114cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
4115cdf0e10cSrcweir     if ( m_aUIElements.size() > 0 )
4116cdf0e10cSrcweir     {
4117cdf0e10cSrcweir         sal_uInt32 nCount(0);
4118cdf0e10cSrcweir         UIElementVector::iterator pIter;
4119cdf0e10cSrcweir         for ( pIter = m_aUIElements.begin(); pIter != m_aUIElements.end(); pIter++ )
4120cdf0e10cSrcweir         {
4121cdf0e10cSrcweir             if ( pIter->m_xUIElement.is() )
4122cdf0e10cSrcweir             {
4123cdf0e10cSrcweir                 ++nCount;
4124cdf0e10cSrcweir                 aSeq.realloc( nCount );
4125cdf0e10cSrcweir                 aSeq[nCount-1] = pIter->m_xUIElement;
4126cdf0e10cSrcweir             }
4127cdf0e10cSrcweir         }
4128cdf0e10cSrcweir     }
4129cdf0e10cSrcweir 
4130cdf0e10cSrcweir     return aSeq;
4131cdf0e10cSrcweir }
4132cdf0e10cSrcweir 
4133cdf0e10cSrcweir bool ToolbarLayoutManager::floatToolbar( const ::rtl::OUString& rResourceURL )
4134cdf0e10cSrcweir {
4135cdf0e10cSrcweir     UIElement aUIElement = implts_findToolbar( rResourceURL );
4136cdf0e10cSrcweir     if ( aUIElement.m_xUIElement.is() )
4137cdf0e10cSrcweir     {
4138cdf0e10cSrcweir         try
4139cdf0e10cSrcweir         {
4140cdf0e10cSrcweir             uno::Reference< awt::XDockableWindow > xDockWindow( aUIElement.m_xUIElement->getRealInterface(), uno::UNO_QUERY );
4141cdf0e10cSrcweir             if ( xDockWindow.is() && !xDockWindow->isFloating() )
4142cdf0e10cSrcweir             {
4143cdf0e10cSrcweir                 aUIElement.m_bFloating = true;
4144cdf0e10cSrcweir                 implts_writeWindowStateData( aUIElement );
4145cdf0e10cSrcweir                 xDockWindow->setFloatingMode( true );
4146cdf0e10cSrcweir 
4147cdf0e10cSrcweir                 implts_setLayoutDirty();
4148cdf0e10cSrcweir                 implts_setToolbar( aUIElement );
4149cdf0e10cSrcweir                 return true;
4150cdf0e10cSrcweir             }
4151cdf0e10cSrcweir         }
4152cdf0e10cSrcweir         catch ( lang::DisposedException& ) {}
4153cdf0e10cSrcweir     }
4154cdf0e10cSrcweir 
4155cdf0e10cSrcweir     return false;
4156cdf0e10cSrcweir }
4157cdf0e10cSrcweir 
4158cdf0e10cSrcweir bool ToolbarLayoutManager::lockToolbar( const ::rtl::OUString& rResourceURL )
4159cdf0e10cSrcweir {
4160cdf0e10cSrcweir     UIElement aUIElement = implts_findToolbar( rResourceURL );
4161cdf0e10cSrcweir     if ( aUIElement.m_xUIElement.is() )
4162cdf0e10cSrcweir     {
4163cdf0e10cSrcweir         try
4164cdf0e10cSrcweir         {
4165cdf0e10cSrcweir             uno::Reference< awt::XDockableWindow > xDockWindow( aUIElement.m_xUIElement->getRealInterface(), uno::UNO_QUERY );
4166cdf0e10cSrcweir             if ( xDockWindow.is() && !xDockWindow->isFloating() && !xDockWindow->isLocked() )
4167cdf0e10cSrcweir             {
4168cdf0e10cSrcweir                 aUIElement.m_aDockedData.m_bLocked = true;
4169cdf0e10cSrcweir                 implts_writeWindowStateData( aUIElement );
4170cdf0e10cSrcweir                 xDockWindow->lock();
4171cdf0e10cSrcweir 
4172cdf0e10cSrcweir                 implts_setLayoutDirty();
4173cdf0e10cSrcweir                 implts_setToolbar( aUIElement );
4174cdf0e10cSrcweir                 return true;
4175cdf0e10cSrcweir             }
4176cdf0e10cSrcweir         }
4177cdf0e10cSrcweir         catch ( lang::DisposedException& ) {}
4178cdf0e10cSrcweir     }
4179cdf0e10cSrcweir 
4180cdf0e10cSrcweir     return false;
4181cdf0e10cSrcweir }
4182cdf0e10cSrcweir 
4183cdf0e10cSrcweir bool ToolbarLayoutManager::unlockToolbar( const ::rtl::OUString& rResourceURL )
4184cdf0e10cSrcweir {
4185cdf0e10cSrcweir     UIElement aUIElement = implts_findToolbar( rResourceURL );
4186cdf0e10cSrcweir     if ( aUIElement.m_xUIElement.is() )
4187cdf0e10cSrcweir     {
4188cdf0e10cSrcweir         try
4189cdf0e10cSrcweir         {
4190cdf0e10cSrcweir             uno::Reference< awt::XDockableWindow > xDockWindow( aUIElement.m_xUIElement->getRealInterface(), uno::UNO_QUERY );
4191cdf0e10cSrcweir             if ( xDockWindow.is() && !xDockWindow->isFloating() && xDockWindow->isLocked() )
4192cdf0e10cSrcweir             {
4193cdf0e10cSrcweir                 aUIElement.m_aDockedData.m_bLocked = false;
4194cdf0e10cSrcweir                 implts_writeWindowStateData( aUIElement );
4195cdf0e10cSrcweir                 xDockWindow->unlock();
4196cdf0e10cSrcweir 
4197cdf0e10cSrcweir                 implts_setLayoutDirty();
4198cdf0e10cSrcweir                 implts_setToolbar( aUIElement );
4199cdf0e10cSrcweir                 return true;
4200cdf0e10cSrcweir             }
4201cdf0e10cSrcweir         }
4202cdf0e10cSrcweir         catch ( lang::DisposedException& ) {}
4203cdf0e10cSrcweir     }
4204cdf0e10cSrcweir 
4205cdf0e10cSrcweir     return false;
4206cdf0e10cSrcweir }
4207cdf0e10cSrcweir 
4208cdf0e10cSrcweir bool ToolbarLayoutManager::isToolbarVisible( const ::rtl::OUString& rResourceURL )
4209cdf0e10cSrcweir {
4210cdf0e10cSrcweir     uno::Reference< awt::XWindow2 > xWindow2( implts_getXWindow( rResourceURL ), uno::UNO_QUERY );
4211cdf0e10cSrcweir     return ( xWindow2.is() && xWindow2->isVisible() );
4212cdf0e10cSrcweir }
4213cdf0e10cSrcweir 
4214cdf0e10cSrcweir bool ToolbarLayoutManager::isToolbarFloating( const ::rtl::OUString& rResourceURL )
4215cdf0e10cSrcweir {
4216cdf0e10cSrcweir     uno::Reference< awt::XDockableWindow > xDockWindow( implts_getXWindow( rResourceURL ), uno::UNO_QUERY );
4217cdf0e10cSrcweir     return ( xDockWindow.is() && xDockWindow->isFloating() );
4218cdf0e10cSrcweir }
4219cdf0e10cSrcweir 
4220cdf0e10cSrcweir bool ToolbarLayoutManager::isToolbarDocked( const ::rtl::OUString& rResourceURL )
4221cdf0e10cSrcweir {
4222cdf0e10cSrcweir     return !isToolbarFloating( rResourceURL );
4223cdf0e10cSrcweir }
4224cdf0e10cSrcweir 
4225cdf0e10cSrcweir bool ToolbarLayoutManager::isToolbarLocked( const ::rtl::OUString& rResourceURL )
4226cdf0e10cSrcweir {
4227cdf0e10cSrcweir     uno::Reference< awt::XDockableWindow > xDockWindow( implts_getXWindow( rResourceURL ), uno::UNO_QUERY );
4228cdf0e10cSrcweir     return ( xDockWindow.is() && xDockWindow->isLocked() );
4229cdf0e10cSrcweir }
4230cdf0e10cSrcweir 
4231cdf0e10cSrcweir awt::Size ToolbarLayoutManager::getToolbarSize( const ::rtl::OUString& rResourceURL )
4232cdf0e10cSrcweir {
4233cdf0e10cSrcweir     Window* pWindow = implts_getWindow( rResourceURL );
4234cdf0e10cSrcweir 
4235cdf0e10cSrcweir     vos::OGuard aGuard( Application::GetSolarMutex() );
4236cdf0e10cSrcweir     if ( pWindow )
4237cdf0e10cSrcweir     {
4238cdf0e10cSrcweir         ::Size    aSize = pWindow->GetSizePixel();
4239cdf0e10cSrcweir         awt::Size aWinSize;
4240cdf0e10cSrcweir         aWinSize.Width  = aSize.Width();
4241cdf0e10cSrcweir         aWinSize.Height = aSize.Height();
4242cdf0e10cSrcweir         return aWinSize;
4243cdf0e10cSrcweir     }
4244cdf0e10cSrcweir 
4245cdf0e10cSrcweir     return awt::Size();
4246cdf0e10cSrcweir }
4247cdf0e10cSrcweir 
4248cdf0e10cSrcweir awt::Point ToolbarLayoutManager::getToolbarPos( const ::rtl::OUString& rResourceURL )
4249cdf0e10cSrcweir {
4250cdf0e10cSrcweir     awt::Point aPos;
4251cdf0e10cSrcweir     UIElement  aUIElement = implts_findToolbar( rResourceURL );
4252cdf0e10cSrcweir 
4253cdf0e10cSrcweir     uno::Reference< awt::XWindow > xWindow( implts_getXWindow( rResourceURL ));
4254cdf0e10cSrcweir     if ( xWindow.is() )
4255cdf0e10cSrcweir     {
4256cdf0e10cSrcweir         if ( aUIElement.m_bFloating )
4257cdf0e10cSrcweir         {
4258cdf0e10cSrcweir             awt::Rectangle aRect = xWindow->getPosSize();
4259cdf0e10cSrcweir             aPos.X = aRect.X;
4260cdf0e10cSrcweir             aPos.Y = aRect.Y;
4261cdf0e10cSrcweir         }
4262cdf0e10cSrcweir         else
4263cdf0e10cSrcweir         {
4264cdf0e10cSrcweir             ::Point aVirtualPos = aUIElement.m_aDockedData.m_aPos;
4265cdf0e10cSrcweir             aPos.X = aVirtualPos.X();
4266cdf0e10cSrcweir             aPos.Y = aVirtualPos.Y();
4267cdf0e10cSrcweir         }
4268cdf0e10cSrcweir     }
4269cdf0e10cSrcweir 
4270cdf0e10cSrcweir     return aPos;
4271cdf0e10cSrcweir }
4272cdf0e10cSrcweir 
4273cdf0e10cSrcweir void ToolbarLayoutManager::setToolbarSize( const ::rtl::OUString& rResourceURL, const awt::Size& aSize )
4274cdf0e10cSrcweir {
4275cdf0e10cSrcweir   uno::Reference< awt::XWindow2 > xWindow( implts_getXWindow( rResourceURL ), uno::UNO_QUERY );
4276cdf0e10cSrcweir     uno::Reference< awt::XDockableWindow > xDockWindow( xWindow, uno::UNO_QUERY );
4277cdf0e10cSrcweir     UIElement aUIElement = implts_findToolbar( rResourceURL );
4278cdf0e10cSrcweir 
4279cdf0e10cSrcweir     if ( xWindow.is() && xDockWindow.is() && xDockWindow->isFloating() )
4280cdf0e10cSrcweir     {
4281cdf0e10cSrcweir         xWindow->setOutputSize( aSize );
4282cdf0e10cSrcweir         aUIElement.m_aFloatingData.m_aSize = ::Size( aSize.Width, aSize.Height );
4283cdf0e10cSrcweir         implts_setToolbar( aUIElement );
4284cdf0e10cSrcweir         implts_writeWindowStateData( aUIElement );
4285cdf0e10cSrcweir         implts_sortUIElements();
4286cdf0e10cSrcweir     }
4287cdf0e10cSrcweir }
4288cdf0e10cSrcweir 
4289cdf0e10cSrcweir void ToolbarLayoutManager::setToolbarPos( const ::rtl::OUString& rResourceURL, const awt::Point& aPos )
4290cdf0e10cSrcweir {
4291cdf0e10cSrcweir     uno::Reference< awt::XWindow > xWindow( implts_getXWindow( rResourceURL ));
4292cdf0e10cSrcweir     uno::Reference< awt::XDockableWindow > xDockWindow( xWindow, uno::UNO_QUERY );
4293cdf0e10cSrcweir     UIElement aUIElement = implts_findToolbar( rResourceURL );
4294cdf0e10cSrcweir 
4295cdf0e10cSrcweir     if ( xWindow.is() && xDockWindow.is() && xDockWindow->isFloating() )
4296cdf0e10cSrcweir     {
4297cdf0e10cSrcweir         xWindow->setPosSize( aPos.X, aPos.Y, 0, 0, awt::PosSize::POS );
4298cdf0e10cSrcweir         aUIElement.m_aFloatingData.m_aPos = ::Point( aPos.X, aPos.Y );
4299cdf0e10cSrcweir         implts_setToolbar( aUIElement );
4300cdf0e10cSrcweir         implts_writeWindowStateData( aUIElement );
4301cdf0e10cSrcweir         implts_sortUIElements();
4302cdf0e10cSrcweir     }
4303cdf0e10cSrcweir }
4304cdf0e10cSrcweir 
4305cdf0e10cSrcweir void ToolbarLayoutManager::setToolbarPosSize( const ::rtl::OUString& rResourceURL, const awt::Point& aPos, const awt::Size& aSize )
4306cdf0e10cSrcweir {
4307cdf0e10cSrcweir     setToolbarPos( rResourceURL, aPos );
4308cdf0e10cSrcweir     setToolbarSize( rResourceURL, aSize );
4309cdf0e10cSrcweir }
4310cdf0e10cSrcweir 
4311cdf0e10cSrcweir } // namespace framework
4312