LCOV - code coverage report
Current view: top level - svtools/source/toolpanel - drawerlayouter.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 75 122 61.5 %
Date: 2012-08-25 Functions: 15 20 75.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 63 209 30.1 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       4                 :            :  *
       5                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       6                 :            :  *
       7                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       8                 :            :  *
       9                 :            :  * This file is part of OpenOffice.org.
      10                 :            :  *
      11                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      12                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      13                 :            :  * only, as published by the Free Software Foundation.
      14                 :            :  *
      15                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      16                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      17                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      18                 :            :  * GNU Lesser General Public License version 3 for more details
      19                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      20                 :            :  *
      21                 :            :  * You should have received a copy of the GNU Lesser General Public License
      22                 :            :  * version 3 along with OpenOffice.org.  If not, see
      23                 :            :  * <http://www.openoffice.org/license.html>
      24                 :            :  * for a copy of the LGPLv3 License.
      25                 :            :  *
      26                 :            : ************************************************************************/
      27                 :            : 
      28                 :            : 
      29                 :            : #include "svtools/toolpanel/drawerlayouter.hxx"
      30                 :            : #include "toolpaneldrawer.hxx"
      31                 :            : 
      32                 :            : #include <com/sun/star/accessibility/XAccessible.hpp>
      33                 :            : 
      34                 :            : #include <comphelper/accimplaccess.hxx>
      35                 :            : #include <tools/diagnose_ex.h>
      36                 :            : 
      37                 :            : //......................................................................................................................
      38                 :            : namespace svt
      39                 :            : {
      40                 :            : //......................................................................................................................
      41                 :            : 
      42                 :            :     /** === begin UNO using === **/
      43                 :            :     using ::com::sun::star::uno::Reference;
      44                 :            :     using ::com::sun::star::accessibility::XAccessible;
      45                 :            :     /** === end UNO using === **/
      46                 :            : 
      47                 :            :     //==================================================================================================================
      48                 :            :     //= DrawerDeckLayouter
      49                 :            :     //==================================================================================================================
      50                 :            :     //------------------------------------------------------------------------------------------------------------------
      51                 :         26 :     DrawerDeckLayouter::DrawerDeckLayouter( ::Window& i_rParentWindow, IToolPanelDeck& i_rPanels )
      52                 :            :         :m_rParentWindow( i_rParentWindow )
      53                 :            :         ,m_rPanelDeck( i_rPanels )
      54                 :            :         ,m_aDrawers()
      55 [ +  - ][ +  - ]:         26 :         ,m_aLastKnownActivePanel()
      56                 :            :     {
      57         [ +  - ]:         26 :         m_rPanelDeck.AddListener( *this );
      58                 :            : 
      59                 :            :         // simulate PanelInserted events for the panels which are already there
      60 [ +  - ][ -  + ]:         26 :         for ( size_t i=0; i<m_rPanelDeck.GetPanelCount(); ++i )
      61 [ #  # ][ #  # ]:          0 :             PanelInserted( m_rPanelDeck.GetPanel( i ), i );
                 [ #  # ]
      62                 :         26 :     }
      63                 :            : 
      64                 :            :     //------------------------------------------------------------------------------------------------------------------
      65         [ +  - ]:         26 :     DrawerDeckLayouter::~DrawerDeckLayouter()
      66                 :            :     {
      67         [ -  + ]:         52 :     }
      68                 :            : 
      69                 :            :     //------------------------------------------------------------------------------------------------------------------
      70                 :        208 :     IMPLEMENT_IREFERENCE( DrawerDeckLayouter )
      71                 :            : 
      72                 :            :     //------------------------------------------------------------------------------------------------------------------
      73                 :        244 :     Rectangle DrawerDeckLayouter::Layout( const Rectangle& i_rDeckPlayground )
      74                 :            :     {
      75         [ +  - ]:        244 :         const size_t nPanelCount( m_rPanelDeck.GetPanelCount() );
      76         [ +  + ]:        244 :         if ( nPanelCount == 0 )
      77                 :         52 :             return i_rDeckPlayground;
      78                 :            : 
      79         [ +  - ]:        192 :         const int nWidth( i_rDeckPlayground.GetWidth() );
      80         [ +  - ]:        192 :         ::boost::optional< size_t > aActivePanel( m_rPanelDeck.GetActivePanel() );
      81 [ +  - ][ +  + ]:        192 :         if ( !aActivePanel )
      82         [ +  - ]:        149 :             aActivePanel = m_aLastKnownActivePanel;
      83                 :            : 
      84                 :            :         // arrange the title bars which are *above* the active panel (or *all* if there is no active panel), plus
      85                 :            :         // the title bar of the active panel itself
      86                 :        192 :         Point aUpperDrawerPos( i_rDeckPlayground.TopLeft() );
      87 [ +  + ][ +  - ]:        192 :         const size_t nUpperBound = !!aActivePanel ? *aActivePanel : nPanelCount - 1;
                 [ +  - ]
      88         [ +  + ]:        785 :         for ( size_t i=0; i<=nUpperBound; ++i )
      89                 :            :         {
      90         [ +  - ]:        593 :             long nDrawerHeight = m_aDrawers[i]->GetPreferredHeightPixel();
      91                 :        593 :             m_aDrawers[i]->SetPosSizePixel(
      92         [ +  - ]:        593 :                 aUpperDrawerPos, Size( nWidth, nDrawerHeight ) );
      93                 :        593 :             aUpperDrawerPos.Move( 0, nDrawerHeight );
      94                 :            :         }
      95                 :            : 
      96                 :            :         // arrange title bars which are below the active panel (or *none* if there is no active panel)
      97         [ +  - ]:        192 :         Point aLowerDrawerPos( i_rDeckPlayground.BottomLeft() );
      98         [ +  + ]:        299 :         for ( size_t j = nPanelCount - 1; j > nUpperBound; --j )
      99                 :            :         {
     100         [ +  - ]:        107 :             long nDrawerHeight = m_aDrawers[j]->GetPreferredHeightPixel();
     101                 :        107 :             m_aDrawers[j]->SetPosSizePixel(
     102                 :        107 :                 Point( aLowerDrawerPos.X(), aLowerDrawerPos.Y() - nDrawerHeight + 1 ),
     103                 :            :                 Size( nWidth, nDrawerHeight )
     104         [ +  - ]:        214 :             );
     105                 :        107 :             aLowerDrawerPos.Move( 0, -nDrawerHeight );
     106                 :            :         }
     107                 :            : 
     108                 :            :         // fincally calculate the rectangle for the active panel
     109                 :            :         return Rectangle(
     110                 :            :             aUpperDrawerPos,
     111                 :        192 :             Size( nWidth, aLowerDrawerPos.Y() - aUpperDrawerPos.Y() + 1 )
     112 [ +  - ][ +  - ]:        244 :         );
     113                 :            :     }
     114                 :            : 
     115                 :            :     //------------------------------------------------------------------------------------------------------------------
     116                 :         52 :     void DrawerDeckLayouter::Destroy()
     117                 :            :     {
     118         [ +  + ]:        182 :         while ( !m_aDrawers.empty() )
     119                 :        130 :             impl_removeDrawer( 0 );
     120                 :         52 :         m_rPanelDeck.RemoveListener( *this );
     121                 :         52 :     }
     122                 :            : 
     123                 :            :     //------------------------------------------------------------------------------------------------------------------
     124                 :          0 :     void DrawerDeckLayouter::SetFocusToPanelSelector()
     125                 :            :     {
     126         [ #  # ]:          0 :         const size_t nPanelCount( m_rPanelDeck.GetPanelCount() );
     127         [ #  # ]:          0 :         if ( !nPanelCount )
     128                 :            :             // nothing to focus
     129                 :            :             return;
     130         [ #  # ]:          0 :         ::boost::optional< size_t > aActivePanel( m_rPanelDeck.GetActivePanel() );
     131 [ #  # ][ #  # ]:          0 :         if ( !aActivePanel )
     132         [ #  # ]:          0 :             aActivePanel = 0;
     133 [ #  # ][ #  # ]:          0 :         ENSURE_OR_RETURN_VOID( *aActivePanel < m_aDrawers.size(), "DrawerDeckLayouter::SetFocusToPanelSelector: invalid active panel, or inconsistent drawers!" );
     134 [ #  # ][ #  # ]:          0 :         m_aDrawers[ *aActivePanel ]->GrabFocus();
         [ #  # ][ #  # ]
     135                 :            :     }
     136                 :            : 
     137                 :            :     //------------------------------------------------------------------------------------------------------------------
     138                 :          0 :     size_t DrawerDeckLayouter::GetAccessibleChildCount() const
     139                 :            :     {
     140                 :          0 :         return m_aDrawers.size();
     141                 :            :     }
     142                 :            : 
     143                 :            :     //------------------------------------------------------------------------------------------------------------------
     144                 :          0 :     Reference< XAccessible > DrawerDeckLayouter::GetAccessibleChild( const size_t i_nChildIndex, const Reference< XAccessible >& i_rParentAccessible )
     145                 :            :     {
     146 [ #  # ][ #  # ]:          0 :         ENSURE_OR_RETURN( i_nChildIndex < m_aDrawers.size(), "illegal index", NULL );
     147                 :            : 
     148         [ #  # ]:          0 :         const PToolPanelDrawer pDrawer( m_aDrawers[ i_nChildIndex ] );
     149                 :            : 
     150         [ #  # ]:          0 :         Reference< XAccessible > xItemAccessible = pDrawer->GetAccessible( sal_False );
     151         [ #  # ]:          0 :         if ( !xItemAccessible.is() )
     152                 :            :         {
     153 [ #  # ][ #  # ]:          0 :             xItemAccessible = pDrawer->GetAccessible( sal_True );
     154 [ #  # ][ #  # ]:          0 :             ENSURE_OR_RETURN( xItemAccessible.is(), "illegal accessible provided by the drawer implementation!", NULL );
     155 [ #  # ][ #  # ]:          0 :             OSL_VERIFY( ::comphelper::OAccessibleImplementationAccess::setAccessibleParent( xItemAccessible->getAccessibleContext(),
                 [ #  # ]
     156                 :            :                 i_rParentAccessible ) );
     157                 :            :         }
     158                 :            : 
     159         [ #  # ]:          0 :         return xItemAccessible;
     160                 :            :     }
     161                 :            : 
     162                 :            :     //------------------------------------------------------------------------------------------------------------------
     163                 :        130 :     void DrawerDeckLayouter::PanelInserted( const PToolPanel& i_pPanel, const size_t i_nPosition )
     164                 :            :     {
     165                 :            :         OSL_PRECOND( i_nPosition <= m_aDrawers.size(), "DrawerDeckLayouter::PanelInserted: inconsistency!" );
     166                 :            : 
     167 [ +  - ][ +  - ]:        130 :         PToolPanelDrawer pDrawer( new ToolPanelDrawer( m_rParentWindow, i_pPanel->GetDisplayName() ) );
         [ +  - ][ +  - ]
     168 [ +  - ][ +  - ]:        130 :         pDrawer->SetHelpId( i_pPanel->GetHelpID() );
     169                 :            :         // proper Z-Order
     170         [ +  + ]:        130 :         if ( i_nPosition == 0 )
     171                 :            :         {
     172         [ +  - ]:         78 :             pDrawer->SetZOrder( NULL, WINDOW_ZORDER_FIRST );
     173                 :            :         }
     174                 :            :         else
     175                 :            :         {
     176         [ +  - ]:         52 :             const PToolPanelDrawer pFirstDrawer( m_aDrawers[ i_nPosition - 1 ] );
     177 [ +  - ][ +  - ]:         52 :             pDrawer->SetZOrder( pFirstDrawer.get(), WINDOW_ZORDER_BEHIND );
     178                 :            :         }
     179                 :            : 
     180         [ +  - ]:        130 :         pDrawer->Show();
     181 [ +  - ][ +  - ]:        130 :         pDrawer->AddEventListener( LINK( this, DrawerDeckLayouter, OnWindowEvent ) );
     182 [ +  - ][ +  - ]:        130 :         m_aDrawers.insert( m_aDrawers.begin() + i_nPosition, pDrawer );
     183 [ +  - ][ +  - ]:        130 :         impl_triggerRearrange();
     184                 :        130 :     }
     185                 :            : 
     186                 :            :     //------------------------------------------------------------------------------------------------------------------
     187                 :          0 :     void DrawerDeckLayouter::PanelRemoved( const size_t i_nPosition )
     188                 :            :     {
     189                 :          0 :         impl_removeDrawer( i_nPosition );
     190                 :          0 :         impl_triggerRearrange();
     191                 :          0 :     }
     192                 :            : 
     193                 :            :     //------------------------------------------------------------------------------------------------------------------
     194                 :        162 :     void DrawerDeckLayouter::impl_triggerRearrange() const
     195                 :            :     {
     196                 :            :         // this is somewhat hacky, it assumes that the parent of our panels is a tool panel deck, which, in its
     197                 :            :         // Resize implementation, rearrances all elements.
     198                 :        162 :         m_rParentWindow.Resize();
     199                 :        162 :     }
     200                 :            : 
     201                 :            :     //------------------------------------------------------------------------------------------------------------------
     202                 :         32 :     void DrawerDeckLayouter::ActivePanelChanged( const ::boost::optional< size_t >& i_rOldActive, const ::boost::optional< size_t >& i_rNewActive )
     203                 :            :     {
     204         [ +  + ]:         32 :         if ( !!i_rOldActive )
     205                 :            :         {
     206                 :            :             OSL_ENSURE( *i_rOldActive < m_aDrawers.size(), "DrawerDeckLayouter::ActivePanelChanged: illegal old index!" );
     207                 :          6 :             m_aDrawers[ *i_rOldActive ]->SetExpanded( false );
     208                 :            :         }
     209                 :            : 
     210         [ +  - ]:         32 :         if ( !!i_rNewActive )
     211                 :            :         {
     212                 :            :             OSL_ENSURE( *i_rNewActive < m_aDrawers.size(), "DrawerDeckLayouter::ActivePanelChanged: illegal new index!" );
     213                 :         32 :             m_aDrawers[ *i_rNewActive ]->SetExpanded( true );
     214                 :            :         }
     215                 :            : 
     216                 :         32 :         impl_triggerRearrange();
     217                 :         32 :     }
     218                 :            : 
     219                 :            :     //------------------------------------------------------------------------------------------------------------------
     220                 :         26 :     void DrawerDeckLayouter::LayouterChanged( const PDeckLayouter& i_rNewLayouter )
     221                 :            :     {
     222                 :            :         // not interested in
     223                 :            :         (void)i_rNewLayouter;
     224                 :         26 :     }
     225                 :            : 
     226                 :            :     //------------------------------------------------------------------------------------------------------------------
     227                 :          0 :     size_t DrawerDeckLayouter::impl_getPanelPositionFromWindow( const Window* i_pDrawerWindow ) const
     228                 :            :     {
     229 [ #  # ][ #  # ]:          0 :         for (   ::std::vector< PToolPanelDrawer >::const_iterator drawerPos = m_aDrawers.begin();
     230                 :          0 :                 drawerPos != m_aDrawers.end();
     231                 :            :                 ++drawerPos
     232                 :            :             )
     233                 :            :         {
     234         [ #  # ]:          0 :             if ( drawerPos->get() == i_pDrawerWindow )
     235         [ #  # ]:          0 :                 return drawerPos - m_aDrawers.begin();
     236                 :            :         }
     237                 :          0 :         return m_aDrawers.size();
     238                 :            :     }
     239                 :            : 
     240                 :            :     //------------------------------------------------------------------------------------------------------------------
     241                 :        130 :     void DrawerDeckLayouter::impl_removeDrawer( const size_t i_nPosition )
     242                 :            :     {
     243                 :            :         OSL_PRECOND( i_nPosition < m_aDrawers.size(), "DrawerDeckLayouter::impl_removeDrawer: invalid panel position!" );
     244         [ +  - ]:        130 :         m_aDrawers[ i_nPosition ]->RemoveEventListener( LINK( this, DrawerDeckLayouter, OnWindowEvent ) );
     245                 :            :         OSL_ENSURE( m_aDrawers[ i_nPosition ].unique(), "DrawerDeckLayouter::impl_removeDrawer: somebody else is still holding a reference!" );
     246 [ +  - ][ +  - ]:        130 :         m_aDrawers.erase( m_aDrawers.begin() + i_nPosition );
     247                 :        130 :     }
     248                 :            : 
     249                 :            :     //------------------------------------------------------------------------------------------------------------------
     250                 :       1347 :     IMPL_LINK( DrawerDeckLayouter, OnWindowEvent, VclSimpleEvent*, i_pEvent )
     251                 :            :     {
     252 [ +  - ][ +  - ]:       1347 :         const VclWindowEvent* pWindowEvent = PTR_CAST( VclWindowEvent, i_pEvent );
     253         [ -  + ]:       1347 :         ENSURE_OR_RETURN( pWindowEvent, "no WindowEvent", 0L );
     254                 :            : 
     255                 :       1347 :         bool bActivatePanel = false;
     256      [ -  -  + ]:       1347 :         switch ( pWindowEvent->GetId() )
     257                 :            :         {
     258                 :            :             case VCLEVENT_WINDOW_MOUSEBUTTONUP:
     259                 :            :             {
     260                 :          0 :                 const MouseEvent* pMouseEvent = static_cast< const MouseEvent* >( pWindowEvent->GetData() );
     261         [ #  # ]:          0 :                 ENSURE_OR_RETURN( pMouseEvent, "no mouse event with MouseButtonUp", 0L );
     262         [ #  # ]:          0 :                 if ( pMouseEvent->GetButtons() == MOUSE_LEFT )
     263                 :            :                 {
     264                 :          0 :                     bActivatePanel = true;
     265                 :            :                 }
     266                 :            :             }
     267                 :          0 :             break;
     268                 :            :             case VCLEVENT_WINDOW_KEYINPUT:
     269                 :            :             {
     270                 :          0 :                 const KeyEvent* pKeyEvent = static_cast< const KeyEvent* >( pWindowEvent->GetData() );
     271         [ #  # ]:          0 :                 ENSURE_OR_RETURN( pKeyEvent, "no key event with KeyInput", 0L );
     272                 :          0 :                 const KeyCode& rKeyCode( pKeyEvent->GetKeyCode() );
     273 [ #  # ][ #  # ]:          0 :                 if ( ( rKeyCode.GetModifier() == 0 ) && ( rKeyCode.GetCode() == KEY_RETURN ) )
                 [ #  # ]
     274                 :            :                 {
     275                 :          0 :                     bActivatePanel = true;
     276                 :            :                 }
     277                 :            :             }
     278                 :          0 :             break;
     279                 :            :         }
     280         [ -  + ]:       1347 :         if ( bActivatePanel )
     281                 :            :         {
     282         [ #  # ]:          0 :             const size_t nPanelPos = impl_getPanelPositionFromWindow( pWindowEvent->GetWindow() );
     283 [ #  # ][ #  # ]:          0 :             if ( nPanelPos != m_rPanelDeck.GetActivePanel() )
         [ #  # ][ #  # ]
     284                 :            :             {
     285 [ #  # ][ #  # ]:          0 :                 m_rPanelDeck.ActivatePanel( nPanelPos );
                 [ #  # ]
     286                 :            :             }
     287                 :            :             else
     288                 :            :             {
     289         [ #  # ]:          0 :                 PToolPanel pPanel( m_rPanelDeck.GetPanel( nPanelPos ) );
     290 [ #  # ][ #  # ]:          0 :                 pPanel->GrabFocus();
     291                 :            :             }
     292                 :          0 :             return 1L;
     293                 :            :         }
     294                 :       1347 :         return 0L;
     295                 :            :     }
     296                 :            : 
     297                 :            :     //------------------------------------------------------------------------------------------------------------------
     298                 :         26 :     void DrawerDeckLayouter::Dying()
     299                 :            :     {
     300                 :         26 :         Destroy();
     301                 :         26 :     }
     302                 :            : 
     303                 :            : //......................................................................................................................
     304                 :            : } // namespace svt
     305                 :            : //......................................................................................................................
     306                 :            : 
     307                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10