openoffice-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From o..@apache.org
Subject svn commit: r1575876 - in /openoffice/trunk/main/framework/source/layoutmanager: toolbarlayoutmanager.cxx toolbarlayoutmanager.hxx
Date Mon, 10 Mar 2014 09:37:03 GMT
Author: orw
Date: Mon Mar 10 09:37:02 2014
New Revision: 1575876

URL: http://svn.apache.org/r1575876
Log:
124355: Toolbarmanager: correct show/hide of toolbars; correct calculation of docking area
sizes


Modified:
    openoffice/trunk/main/framework/source/layoutmanager/toolbarlayoutmanager.cxx
    openoffice/trunk/main/framework/source/layoutmanager/toolbarlayoutmanager.hxx

Modified: openoffice/trunk/main/framework/source/layoutmanager/toolbarlayoutmanager.cxx
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/framework/source/layoutmanager/toolbarlayoutmanager.cxx?rev=1575876&r1=1575875&r2=1575876&view=diff
==============================================================================
--- openoffice/trunk/main/framework/source/layoutmanager/toolbarlayoutmanager.cxx (original)
+++ openoffice/trunk/main/framework/source/layoutmanager/toolbarlayoutmanager.cxx Mon Mar
10 09:37:02 2014
@@ -259,110 +259,107 @@ void ToolbarLayoutManager::doLayout(cons
 bool ToolbarLayoutManager::implts_isParentWindowVisible() const
 {
     ReadGuard aReadLock( m_aLock );
-    bool bVisible( false );    
+    bool bVisible( false );
     if ( m_xContainerWindow.is() )
         bVisible = m_xContainerWindow->isVisible();
 
     return bVisible;
 }
 
-Rectangle ToolbarLayoutManager::implts_calcDockingArea()
+namespace
 {
-    ReadGuard aReadLock( m_aLock );
-    UIElementVector aWindowVector( m_aUIElements );
-    aReadLock.unlock();
+    void insertDockingAreaSize(
+        const UIElement& rUIElement,
+        const awt::Rectangle& rUIElementPosSize,
+        std::vector< sal_Int32 >& rDockingAreaData )
+    {
+        sal_Int32 nAreaPos = 0;
+        sal_Int32 nSize = 0;
+        if ( isHorizontalDockingArea( rUIElement.m_aDockedData.m_nDockedArea ) )
+        {
+            nAreaPos = rUIElement.m_aDockedData.m_aPos.Y();
+            nSize = rUIElementPosSize.Height;
+        }
+        else
+        {
+            nAreaPos = rUIElement.m_aDockedData.m_aPos.X();
+            nSize = rUIElementPosSize.Width;
+        }
 
-    Rectangle                aBorderSpace;
-    sal_Int32                nCurrRowColumn( 0 );
-    sal_Int32                nCurrPos( 0 );
-    sal_Int32                nCurrDockingArea( ui::DockingArea_DOCKINGAREA_TOP );
-    std::vector< sal_Int32 > aRowColumnSizes[DOCKINGAREAS_COUNT];
-    UIElementVector::const_iterator pConstIter;
+        const sal_uInt32 nIndexPos = nAreaPos >= 0 ? static_cast< sal_uInt32 >(nAreaPos)
: 0;
+        if ( rDockingAreaData.size() < nIndexPos + 1 )
+        {
+            rDockingAreaData.resize( nIndexPos + 1, 0 );
+        }
 
-    // initialize rectangle with zero values!
-    aBorderSpace.setWidth(0);
-    aBorderSpace.setHeight(0);
+        if ( rDockingAreaData[nIndexPos] < nSize )
+        {
+            rDockingAreaData[nIndexPos] = nSize;
+        }
+    }
 
-    aRowColumnSizes[nCurrDockingArea].clear();
-    aRowColumnSizes[nCurrDockingArea].push_back( 0 );
 
-    for ( pConstIter = aWindowVector.begin(); pConstIter != aWindowVector.end(); pConstIter++
)
+    sal_Int32 calcDockingAreaSize( const std::vector< sal_Int32 >& rDockingAreaData
)
     {
-        uno::Reference< ui::XUIElement > xUIElement( pConstIter->m_xUIElement, uno::UNO_QUERY
);
-        if ( xUIElement.is() )
+        sal_Int32 nDockingAreaSize = 0;
+
+        std::vector< sal_Int32 >::const_iterator iDockingAreaDataEnd = rDockingAreaData.end();
+        for ( std::vector< sal_Int32 >::const_iterator iDockingAreaData = rDockingAreaData.begin();
+              iDockingAreaData != iDockingAreaDataEnd;
+              ++iDockingAreaData )
         {
-            uno::Reference< awt::XWindow > xWindow( xUIElement->getRealInterface(),
uno::UNO_QUERY );
-            uno::Reference< awt::XDockableWindow > xDockWindow( xWindow, uno::UNO_QUERY
);
-            if ( xWindow.is() && xDockWindow.is() )
-            {
-                vos::OGuard aGuard( Application::GetSolarMutex() );
+                nDockingAreaSize += *(iDockingAreaData);
+        }
 
-                Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
-                if ( pWindow && !xDockWindow->isFloating() && pConstIter->m_bVisible
)
-                {
-                    awt::Rectangle aPosSize = xWindow->getPosSize();
-                    if ( pConstIter->m_aDockedData.m_nDockedArea != nCurrDockingArea )
-                    {
-                        nCurrDockingArea = pConstIter->m_aDockedData.m_nDockedArea;
-                        nCurrRowColumn   = 0;
-                        nCurrPos         = 0;
-                        aRowColumnSizes[nCurrDockingArea].clear();
-                        aRowColumnSizes[nCurrDockingArea].push_back( 0 );
-                    }
+        return nDockingAreaSize;
+    }
+}
 
-                    if ( pConstIter->m_aDockedData.m_nDockedArea == nCurrDockingArea )
-                    {
-                        if ( isHorizontalDockingArea( pConstIter->m_aDockedData.m_nDockedArea
))
-                        {
-                            if ( pConstIter->m_aDockedData.m_aPos.Y() > nCurrPos )
-                            {
-                                ++nCurrRowColumn;
-                                nCurrPos = pConstIter->m_aDockedData.m_aPos.Y();
-                                aRowColumnSizes[nCurrDockingArea].push_back( 0 );
-                            }
 
-                            if ( aPosSize.Height > aRowColumnSizes[nCurrDockingArea][nCurrRowColumn]
)
-                                aRowColumnSizes[nCurrDockingArea][nCurrRowColumn] = aPosSize.Height;
-                        }
-                        else
-                        {
-                            if ( pConstIter->m_aDockedData.m_aPos.X() > nCurrPos )
-                            {
-                                ++nCurrRowColumn;
-                                nCurrPos = pConstIter->m_aDockedData.m_aPos.X();
-                                aRowColumnSizes[nCurrDockingArea].push_back( 0 );
-                            }
+Rectangle ToolbarLayoutManager::implts_calcDockingArea()
+{
+    Rectangle aBorderSpace( 0, 0, 0, 0 );
 
-                            if ( aPosSize.Width > aRowColumnSizes[nCurrDockingArea][nCurrRowColumn]
)
-                                aRowColumnSizes[nCurrDockingArea][nCurrRowColumn] = aPosSize.Width;
-                        }
+    // For each docking area one container of UIElement sizes.
+    std::vector< std::vector< sal_Int32 > >aDockingAreaSizeDatas( DOCKINGAREAS_COUNT
);
+
+    {
+        ReadGuard aReadLock( m_aLock );
+        vos::OGuard aGuard( Application::GetSolarMutex() );
+
+        // Iterate over the UIElements and collect corresponding docking area data
+        // for non-floating and visible ones separated for the each docking area.
+        // Note: For each docking area row resp. column only the size of largest UIElement
is collected.
+        for ( UIElementVector::const_iterator pConstIter = m_aUIElements.begin(); pConstIter
!= m_aUIElements.end(); ++pConstIter )
+        {
+            uno::Reference< ui::XUIElement > xUIElement( pConstIter->m_xUIElement,
uno::UNO_QUERY );
+            if ( xUIElement.is() )
+            {
+                uno::Reference< awt::XWindow > xWindow( xUIElement->getRealInterface(),
uno::UNO_QUERY );
+                uno::Reference< awt::XDockableWindow > xDockWindow( xWindow, uno::UNO_QUERY
);
+                if ( xWindow.is() && xDockWindow.is() )
+                {
+                    Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
+                    if ( pWindow && !xDockWindow->isFloating() && pConstIter->m_bVisible
)
+                    {
+                        const awt::Rectangle aPosSize = xWindow->getPosSize();
+                        insertDockingAreaSize(
+                            *(pConstIter),
+                            aPosSize,
+                            aDockingAreaSizeDatas[pConstIter->m_aDockedData.m_nDockedArea]
);
                     }
                 }
             }
         }
-    }
 
-    // Sum up max heights from every row/column
-    if ( !aWindowVector.empty() )
-    {
-        for ( sal_Int32 i = 0; i <= ui::DockingArea_DOCKINGAREA_RIGHT; i++ )
-        {
-            sal_Int32 nSize( 0 );
-            const sal_uInt32 nCount = aRowColumnSizes[i].size();
-            for ( sal_uInt32 j = 0; j < nCount; j++ )
-                nSize += aRowColumnSizes[i][j];
-
-            if ( i == ui::DockingArea_DOCKINGAREA_TOP )
-                aBorderSpace.Top() = nSize;
-            else if ( i == ui::DockingArea_DOCKINGAREA_BOTTOM )
-                aBorderSpace.Bottom() = nSize;
-            else if ( i == ui::DockingArea_DOCKINGAREA_LEFT )
-                aBorderSpace.Left() = nSize;
-            else
-                aBorderSpace.Right() = nSize;
-        }
+        aReadLock.unlock();
     }
 
+    aBorderSpace.Top() = calcDockingAreaSize( aDockingAreaSizeDatas[ui::DockingArea_DOCKINGAREA_TOP]
);
+    aBorderSpace.Bottom() = calcDockingAreaSize( aDockingAreaSizeDatas[ui::DockingArea_DOCKINGAREA_BOTTOM]
);
+    aBorderSpace.Left() = calcDockingAreaSize( aDockingAreaSizeDatas[ui::DockingArea_DOCKINGAREA_LEFT]
);
+    aBorderSpace.Right() = calcDockingAreaSize( aDockingAreaSizeDatas[ui::DockingArea_DOCKINGAREA_RIGHT]
);
+
     return aBorderSpace;
 }
 
@@ -553,62 +550,67 @@ void ToolbarLayoutManager::destroyToolba
     }
 }
 
-bool ToolbarLayoutManager::showToolbar( const ::rtl::OUString& rResourceURL )
+bool ToolbarLayoutManager::implts_setToolbarVisibility(
+    bool bVisible,
+    UIElement aUIElement )
 {
-    UIElement aUIElement = implts_findToolbar( rResourceURL );
-    
+    bool bRet = false;
+
     vos::OGuard aGuard( Application::GetSolarMutex() );
     Window* pWindow = getWindowFromXUIElement( aUIElement.m_xUIElement );
     if ( pWindow )
     {
+        if ( bVisible )
+        {
+            pWindow->Show( sal_True, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE );
+        }
+        else
+        {
+            pWindow->Show( sal_False );
+        }
         if ( !aUIElement.m_bFloating )
+        {
             implts_setLayoutDirty();
-        else
-            pWindow->Show( sal_True, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE );
-        
-        aUIElement.m_bVisible = true;
+        }
+        aUIElement.m_bVisible = bVisible;
         implts_writeWindowStateData( aUIElement );
         implts_setToolbar( aUIElement );
-        return true;
+
+        bRet = true;
     }
-    
-    return false;
+
+    return bRet;
 }
 
-bool ToolbarLayoutManager::hideToolbar( const ::rtl::OUString& rResourceURL )
+bool ToolbarLayoutManager::showToolbar( const ::rtl::OUString& rResourceURL )
 {
     UIElement aUIElement = implts_findToolbar( rResourceURL );
+    const bool bRet = implts_setToolbarVisibility( true, aUIElement );
+    implts_sortUIElements();
+    return bRet;
+}
 
-    vos::OGuard aGuard( Application::GetSolarMutex() );
-    Window* pWindow = getWindowFromXUIElement( aUIElement.m_xUIElement );
-    if ( pWindow )
-    {
-        pWindow->Show( sal_False );
-        if ( !aUIElement.m_bFloating )
-            implts_setLayoutDirty();
-        
-        aUIElement.m_bVisible = false;
-        implts_writeWindowStateData( aUIElement );
-        implts_setToolbar( aUIElement );
-        return true;
-    }
-
-    return false;
+bool ToolbarLayoutManager::hideToolbar( const ::rtl::OUString& rResourceURL )
+{
+    UIElement aUIElement = implts_findToolbar( rResourceURL );
+    const bool bRet = implts_setToolbarVisibility( false, aUIElement );
+    implts_sortUIElements();
+    return bRet;
 }
 
 void ToolbarLayoutManager::refreshToolbarsVisibility( bool bAutomaticToolbars )
 {
-    UIElementVector aUIElementVector;
+    if ( !bAutomaticToolbars )
+        return;
 
     ReadGuard aReadLock( m_aLock );
-    bool bVisible( m_bVisible );
-    aReadLock.unlock();
-
-    if ( !bVisible || !bAutomaticToolbars )
+    if ( !m_bVisible )
         return;
+    aReadLock.unlock();
 
+    UIElementVector aUIElementVector;
     implts_getUIElementVectorCopy( aUIElementVector );
-    
+
     UIElement aUIElement;
     vos::OGuard aGuard( Application::GetSolarMutex() );
     UIElementVector::iterator pIter;
@@ -655,28 +657,17 @@ void ToolbarLayoutManager::setVisible( b
 {
     UIElementVector aUIElementVector;
     implts_getUIElementVectorCopy( aUIElementVector );
-    
+
     vos::OGuard aGuard( Application::GetSolarMutex() );
     UIElementVector::iterator pIter;
     for ( pIter = aUIElementVector.begin(); pIter != aUIElementVector.end(); pIter++ )
     {
         pIter->m_bMasterHide = !bVisible;
-        Window* pWindow = getWindowFromXUIElement( pIter->m_xUIElement );
-        if ( pWindow )
-        {
-            bool bSetVisible( pIter->m_bVisible & bVisible );
-            if ( !bSetVisible )
-                pWindow->Hide();
-            else
-            {
-                if ( pIter->m_bFloating )
-                    pWindow->Show(true, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE );
-                else
-                    implts_setLayoutDirty();
-            }
-        }
+        implts_setToolbarVisibility( bVisible, *pIter );
     }
-        
+
+    implts_sortUIElements();
+
     if ( !bVisible )
         resetDockingArea();
 }

Modified: openoffice/trunk/main/framework/source/layoutmanager/toolbarlayoutmanager.hxx
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/framework/source/layoutmanager/toolbarlayoutmanager.hxx?rev=1575876&r1=1575875&r2=1575876&view=diff
==============================================================================
--- openoffice/trunk/main/framework/source/layoutmanager/toolbarlayoutmanager.hxx (original)
+++ openoffice/trunk/main/framework/source/layoutmanager/toolbarlayoutmanager.hxx Mon Mar
10 09:37:02 2014
@@ -219,6 +219,7 @@ class ToolbarLayoutManager : public ::cp
         rtl::OUString    implts_generateGenericAddonToolbarTitle( sal_Int32 nNumber ) const;
         void             implts_setElementData( UIElement& rUIElement, const ::com::sun::star::uno::Reference<
::com::sun::star::awt::XDockableWindow >& rDockWindow );
         void             implts_destroyDockingAreaWindows();
+        bool             implts_setToolbarVisibility( bool bVisible, UIElement aUIElement
);
 
         //---------------------------------------------------------------------------------------------------------
         // layout methods
@@ -233,7 +234,7 @@ class ToolbarLayoutManager : public ::cp
         void             implts_setLayoutDirty();
         void             implts_setLayoutInProgress( bool bInProgress = true );
         bool             implts_isLayoutInProgress() const { return m_bLayoutInProgress;
}
-        
+
         //---------------------------------------------------------------------------------------------------------
         // lookup/container methods
         //---------------------------------------------------------------------------------------------------------
@@ -246,7 +247,7 @@ class ToolbarLayoutManager : public ::cp
         void             implts_setToolbar( const UIElement& rUIElement );
         ::Size           implts_getTopBottomDockingAreaSizes();
         void             implts_getUIElementVectorCopy( UIElementVector& rCopy );
-        
+
         //---------------------------------------------------------------------------------------------------------
         // internal docking methods
         //---------------------------------------------------------------------------------------------------------
@@ -265,12 +266,12 @@ class ToolbarLayoutManager : public ::cp
                                                             const ::Rectangle& rTrackingRect,
                                                             const ::Rectangle& rRowColumnRect,
                                                             const ::Size& rContainerWinSize
);
-        
+
         void             implts_getDockingAreaElementInfos( ::com::sun::star::ui::DockingArea
DockingArea, std::vector< SingleRowColumnWindowData >& rRowColumnsWindowData );
         void             implts_getDockingAreaElementInfoOnSingleRowCol( ::com::sun::star::ui::DockingArea,
sal_Int32 nRowCol, SingleRowColumnWindowData& rRowColumnWindowData );
         void             implts_findNextDockingPos( ::com::sun::star::ui::DockingArea DockingArea,
const ::Size& aUIElementSize, ::Point& rVirtualPos, ::Point& rPixelPos );
         void             implts_setTrackingRect( ::com::sun::star::ui::DockingArea eDockingArea,
const ::Point& rMousePos, ::Rectangle& rTrackingRect );
-        
+
         //---------------------------------------------------------------------------------------------------------
         // creation methods
         //---------------------------------------------------------------------------------------------------------
@@ -283,14 +284,14 @@ class ToolbarLayoutManager : public ::cp
         css::uno::Reference< css::ui::XUIElement > implts_createElement( const ::rtl::OUString&
aName );
         void             implts_setToolbarCreation( bool bStart = true );
         bool             implts_isToolbarCreationActive();
-        
+
         //---------------------------------------------------------------------------------------------------------
         // persistence methods
         //---------------------------------------------------------------------------------------------------------
         sal_Bool         implts_readWindowStateData( const rtl::OUString& aName, UIElement&
rElementData );
         void             implts_writeWindowStateData( const UIElement& rElementData );
         void             implts_writeNewWindowStateData( const rtl::OUString aName, const
::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& xWindow );
-        
+
         //---------------------------------------------------------------------------------------------------------
         // members
         //---------------------------------------------------------------------------------------------------------



Mime
View raw message