LCOV - code coverage report
Current view: top level - svtools/source/toolpanel - toolpanelcollection.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 58 0.0 %
Date: 2014-04-14 Functions: 0 13 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include "toolpanelcollection.hxx"
      22             : #include "paneldecklisteners.hxx"
      23             : 
      24             : #include <tools/diagnose_ex.h>
      25             : 
      26             : #include <vector>
      27             : 
      28             : 
      29             : namespace svt
      30             : {
      31             : 
      32             : 
      33             : 
      34             :     //= ToolPanelCollection_Data
      35             : 
      36           0 :     struct ToolPanelCollection_Data
      37             :     {
      38             :         ::std::vector< PToolPanel >                 aPanels;
      39             :         ::boost::optional< size_t >                 aActivePanel;
      40             :         PanelDeckListeners                          aListeners;
      41             :     };
      42             : 
      43             : 
      44             :     //= ToolPanelCollection
      45             : 
      46             : 
      47           0 :     ToolPanelCollection::ToolPanelCollection()
      48           0 :         :m_pData( new ToolPanelCollection_Data )
      49             :     {
      50           0 :     }
      51             : 
      52             : 
      53           0 :     ToolPanelCollection::~ToolPanelCollection()
      54             :     {
      55           0 :         m_pData->aListeners.Dying();
      56           0 :     }
      57             : 
      58             : 
      59           0 :     size_t ToolPanelCollection::GetPanelCount() const
      60             :     {
      61           0 :         return m_pData->aPanels.size();
      62             :     }
      63             : 
      64             : 
      65           0 :     ::boost::optional< size_t > ToolPanelCollection::GetActivePanel() const
      66             :     {
      67           0 :         return m_pData->aActivePanel;
      68             :     }
      69             : 
      70             : 
      71           0 :     void ToolPanelCollection::ActivatePanel( const ::boost::optional< size_t >& i_rPanel )
      72             :     {
      73           0 :         if ( !!i_rPanel )
      74             :         {
      75             :             OSL_ENSURE( *i_rPanel < GetPanelCount(), "ToolPanelCollection::ActivatePanel: illegal panel no.!" );
      76           0 :             if ( *i_rPanel >= GetPanelCount() )
      77           0 :                 return;
      78             :         }
      79             : 
      80           0 :         if ( m_pData->aActivePanel == i_rPanel )
      81           0 :             return;
      82             : 
      83           0 :         const ::boost::optional< size_t > aOldPanel( m_pData->aActivePanel );
      84           0 :         m_pData->aActivePanel = i_rPanel;
      85             : 
      86             :         // notify listeners
      87           0 :         m_pData->aListeners.ActivePanelChanged( aOldPanel, m_pData->aActivePanel );
      88             :     }
      89             : 
      90             : 
      91           0 :     PToolPanel ToolPanelCollection::GetPanel( const size_t i_nPos ) const
      92             :     {
      93             :         OSL_ENSURE( i_nPos < m_pData->aPanels.size(), "ToolPanelCollection::GetPanel: illegal position!" );
      94           0 :         if ( i_nPos >= m_pData->aPanels.size() )
      95           0 :             return PToolPanel();
      96           0 :         return m_pData->aPanels[ i_nPos ];
      97             :     }
      98             : 
      99             : 
     100           0 :     size_t ToolPanelCollection::InsertPanel( const PToolPanel& i_pPanel, const size_t i_nPosition )
     101             :     {
     102             :         OSL_ENSURE( i_pPanel.get(), "ToolPanelCollection::InsertPanel: illegal panel!" );
     103           0 :         if ( !i_pPanel.get() )
     104           0 :             return 0;
     105             : 
     106             :         // insert
     107           0 :         const size_t position = i_nPosition < m_pData->aPanels.size() ? i_nPosition : m_pData->aPanels.size();
     108           0 :         m_pData->aPanels.insert( m_pData->aPanels.begin() + position, i_pPanel );
     109             : 
     110             :         // update active panel
     111           0 :         if ( !!m_pData->aActivePanel )
     112             :         {
     113           0 :             if ( i_nPosition <= *m_pData->aActivePanel )
     114           0 :                 ++*m_pData->aActivePanel;
     115             :         }
     116             : 
     117             :         // notifications
     118           0 :         m_pData->aListeners.PanelInserted( i_pPanel, i_nPosition );
     119             : 
     120           0 :         return position;
     121             :     }
     122             : 
     123             : 
     124           0 :     PToolPanel ToolPanelCollection::RemovePanel( const size_t i_nPosition )
     125             :     {
     126             :         OSL_ENSURE( i_nPosition < m_pData->aPanels.size(), "ToolPanelCollection::RemovePanel: illegal position!" );
     127           0 :         if ( i_nPosition >= m_pData->aPanels.size() )
     128           0 :             return NULL;
     129             : 
     130             :         // if the active panel is going to be removed, activate another one (before the actual removal)
     131           0 :         if ( m_pData->aActivePanel == i_nPosition )
     132             :         {
     133           0 :             const ::boost::optional< size_t > aOldActive( m_pData->aActivePanel );
     134             : 
     135           0 :             if ( i_nPosition + 1 < GetPanelCount() )
     136             :             {
     137           0 :                 ++*m_pData->aActivePanel;
     138             :             }
     139           0 :             else if ( i_nPosition > 0 )
     140             :             {
     141           0 :                 --*m_pData->aActivePanel;
     142             :             }
     143             :             else
     144             :             {
     145           0 :                 m_pData->aActivePanel.reset();
     146             :             }
     147             : 
     148           0 :             m_pData->aListeners.ActivePanelChanged( aOldActive, m_pData->aActivePanel );
     149             :         }
     150             : 
     151             :         // remember the removed panel for the aller
     152           0 :         PToolPanel pRemovedPanel( m_pData->aPanels[ i_nPosition ] );
     153             : 
     154             :         // actually remove
     155           0 :         m_pData->aPanels.erase( m_pData->aPanels.begin() + i_nPosition );
     156             : 
     157           0 :         if ( !!m_pData->aActivePanel )
     158             :         {
     159           0 :             if ( i_nPosition < *m_pData->aActivePanel )
     160             :             {
     161           0 :                 --*m_pData->aActivePanel;
     162             :             }
     163             :         }
     164             : 
     165             :         // notify removed panel
     166           0 :         m_pData->aListeners.PanelRemoved( i_nPosition );
     167             : 
     168           0 :         return pRemovedPanel;
     169             :     }
     170             : 
     171             : 
     172           0 :     void ToolPanelCollection::AddListener( IToolPanelDeckListener& i_rListener )
     173             :     {
     174           0 :         m_pData->aListeners.AddListener( i_rListener );
     175           0 :     }
     176             : 
     177             : 
     178           0 :     void ToolPanelCollection::RemoveListener( IToolPanelDeckListener& i_rListener )
     179             :     {
     180           0 :         m_pData->aListeners.RemoveListener( i_rListener );
     181           0 :     }
     182             : 
     183             : 
     184             : } // namespace svt
     185             : 
     186             : 
     187             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10