LCOV - code coverage report
Current view: top level - chart2/source/controller/main - ElementSelector.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 110 171 64.3 %
Date: 2012-08-25 Functions: 19 26 73.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 102 337 30.3 %

           Branch data     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 "ElementSelector.hxx"
      22                 :            : #include "macros.hxx"
      23                 :            : #include "ObjectNameProvider.hxx"
      24                 :            : #include "ObjectHierarchy.hxx"
      25                 :            : #include "servicenames.hxx"
      26                 :            : #include <chartview/ExplicitValueProvider.hxx>
      27                 :            : #include "DrawViewWrapper.hxx"
      28                 :            : #include "ResId.hxx"
      29                 :            : #include "Strings.hrc"
      30                 :            : 
      31                 :            : #include <toolkit/helper/vclunohelper.hxx>
      32                 :            : #include <osl/mutex.hxx>
      33                 :            : #include <vcl/svapp.hxx>
      34                 :            : 
      35                 :            : #include <com/sun/star/chart2/XChartDocument.hpp>
      36                 :            : #include <com/sun/star/frame/XControlNotificationListener.hpp>
      37                 :            : #include <com/sun/star/util/XURLTransformer.hpp>
      38                 :            : #include <com/sun/star/view/XSelectionSupplier.hpp>
      39                 :            : 
      40                 :            : namespace chart
      41                 :            : {
      42                 :            : 
      43                 :            : using namespace com::sun::star;
      44                 :            : using namespace com::sun::star::uno;
      45                 :            : using ::com::sun::star::uno::Any;
      46                 :            : using ::com::sun::star::uno::Reference;
      47                 :            : using ::com::sun::star::uno::Sequence;
      48                 :            : 
      49                 :            : namespace
      50                 :            : {
      51                 :         16 : static const ::rtl::OUString lcl_aServiceName(
      52                 :            :     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart.ElementSelectorToolbarController" ));
      53                 :            : }
      54                 :            : 
      55                 :            : //------------------------------------------------------------------------------
      56                 :            : 
      57                 :         34 : SelectorListBox::SelectorListBox( Window* pParent, WinBits nStyle )
      58                 :            :     : ListBox( pParent, nStyle )
      59 [ +  - ][ +  - ]:         34 :     , m_bReleaseFocus( true )
      60                 :            : {
      61                 :         34 : }
      62                 :            : 
      63         [ +  - ]:         34 : SelectorListBox::~SelectorListBox()
      64                 :            : {
      65         [ -  + ]:         68 : }
      66                 :            : 
      67                 :      23605 : void lcl_addObjectsToList( const ObjectHierarchy& rHierarchy, const ObjectHierarchy::tOID & rParent, std::vector< ListBoxEntryData >& rEntries
      68                 :            :                           , const sal_Int32 nHierarchyDepth, const Reference< chart2::XChartDocument >& xChartDoc )
      69                 :            : {
      70         [ +  - ]:      23605 :     ObjectHierarchy::tChildContainer aChildren( rHierarchy.getChildren(rParent) );
      71         [ +  - ]:      23605 :     ObjectHierarchy::tChildContainer::const_iterator aIt( aChildren.begin());
      72 [ +  - ][ +  + ]:      44939 :     while( aIt != aChildren.end() )
      73                 :            :     {
      74 [ +  - ][ +  - ]:      21334 :         ObjectHierarchy::tOID aOID = *aIt;
      75         [ +  - ]:      21334 :         ::rtl::OUString aCID = aOID.getObjectCID();
      76         [ +  - ]:      21334 :         ListBoxEntryData aEntry;
      77         [ +  - ]:      21334 :         aEntry.OID = aOID;
      78         [ +  - ]:      21334 :         aEntry.UIName += ObjectNameProvider::getNameForCID( aCID, xChartDoc );
      79                 :      21334 :         aEntry.nHierarchyDepth = nHierarchyDepth;
      80         [ +  - ]:      21334 :         rEntries.push_back(aEntry);
      81         [ +  - ]:      21334 :         lcl_addObjectsToList( rHierarchy, aOID, rEntries, nHierarchyDepth+1, xChartDoc );
      82         [ +  - ]:      21334 :         ++aIt;
      83 [ +  - ][ +  - ]:      44939 :     }
      84                 :      23605 : }
      85                 :            : 
      86                 :       2271 : void SelectorListBox::SetChartController( const Reference< frame::XController >& xChartController )
      87                 :            : {
      88                 :       2271 :     m_xChartController = xChartController;
      89                 :       2271 : }
      90                 :            : 
      91                 :       2271 : void SelectorListBox::UpdateChartElementsListAndSelection()
      92                 :            : {
      93         [ +  - ]:       2271 :     Clear();
      94                 :       2271 :     m_aEntries.clear();
      95                 :            : 
      96         [ +  - ]:       2271 :     Reference< frame::XController > xChartController( m_xChartController );
      97         [ +  - ]:       2271 :     if( xChartController.is() )
      98                 :            :     {
      99         [ +  - ]:       2271 :         Reference< view::XSelectionSupplier > xSelectionSupplier( xChartController, uno::UNO_QUERY);
     100         [ +  - ]:       2271 :         ObjectHierarchy::tOID aSelectedOID;
     101                 :       2271 :         rtl::OUString aSelectedCID;
     102         [ +  - ]:       2271 :         if( xSelectionSupplier.is() )
     103                 :            :         {
     104 [ +  - ][ +  - ]:       2271 :             aSelectedOID = ObjectIdentifier( xSelectionSupplier->getSelection() );
         [ +  - ][ +  - ]
                 [ +  - ]
     105         [ +  - ]:       2271 :             aSelectedCID = aSelectedOID.getObjectCID();
     106                 :            :         }
     107                 :            : 
     108 [ +  - ][ +  - ]:       2271 :         Reference< chart2::XChartDocument > xChartDoc( xChartController->getModel(), uno::UNO_QUERY );
                 [ +  - ]
     109         [ +  - ]:       2271 :         ObjectType eType( aSelectedOID.getObjectType() );
     110                 :       2271 :         bool bAddSelectionToList = false;
     111 [ +  - ][ +  - ]:       2271 :         if ( eType == OBJECTTYPE_DATA_POINT || eType == OBJECTTYPE_DATA_LABEL || eType == OBJECTTYPE_SHAPE )
                 [ -  + ]
     112                 :          0 :             bAddSelectionToList = true;
     113                 :            : 
     114                 :       2271 :         Reference< uno::XInterface > xChartView;
     115 [ +  - ][ +  - ]:       2271 :         Reference< lang::XMultiServiceFactory > xFact( xChartController->getModel(), uno::UNO_QUERY );
                 [ +  - ]
     116         [ +  - ]:       2271 :         if( xFact.is() )
     117 [ +  - ][ +  - ]:       2271 :             xChartView = xFact->createInstance( CHART_VIEW_SERVICE_NAME );
         [ +  - ][ +  - ]
     118                 :       2271 :         ExplicitValueProvider* pExplicitValueProvider = 0;//ExplicitValueProvider::getExplicitValueProvider(xChartView); dies erzeugt alle sichtbaren datenpinkte, das ist zu viel
     119         [ +  - ]:       2271 :         ObjectHierarchy aHierarchy( xChartDoc, pExplicitValueProvider, true /*bFlattenDiagram*/, true /*bOrderingForElementSelector*/ );
     120 [ +  - ][ +  - ]:       2271 :         lcl_addObjectsToList( aHierarchy, aHierarchy.getRootNodeOID(), m_aEntries, 0, xChartDoc );
                 [ +  - ]
     121                 :            : 
     122                 :       2271 :         std::vector< ListBoxEntryData >::iterator aIt( m_aEntries.begin() );
     123         [ -  + ]:       2271 :         if( bAddSelectionToList )
     124                 :            :         {
     125 [ #  # ][ #  # ]:          0 :             if ( aSelectedOID.isAutoGeneratedObject() )
     126                 :            :             {
     127 [ #  # ][ #  # ]:          0 :                 rtl::OUString aSeriesCID = ObjectIdentifier::createClassifiedIdentifierForParticle( ObjectIdentifier::getSeriesParticleFromCID( aSelectedCID ) );
     128 [ #  # ][ #  # ]:          0 :                 for( aIt = m_aEntries.begin(); aIt != m_aEntries.end(); ++aIt )
     129                 :            :                 {
     130 [ #  # ][ #  # ]:          0 :                     if( aIt->OID.getObjectCID().match( aSeriesCID ) )
     131                 :            :                     {
     132         [ #  # ]:          0 :                         ListBoxEntryData aEntry;
     133         [ #  # ]:          0 :                         aEntry.UIName = ObjectNameProvider::getNameForCID( aSelectedCID, xChartDoc );
     134         [ #  # ]:          0 :                         aEntry.OID = aSelectedOID;
     135                 :          0 :                         ++aIt;
     136 [ #  # ][ #  # ]:          0 :                         if( aIt != m_aEntries.end() )
     137         [ #  # ]:          0 :                             m_aEntries.insert(aIt, aEntry);
     138                 :            :                         else
     139         [ #  # ]:          0 :                             m_aEntries.push_back( aEntry );
     140         [ #  # ]:          0 :                         break;
     141                 :            :                     }
     142                 :          0 :                 }
     143                 :            :             }
     144 [ #  # ][ #  # ]:          0 :             else if ( aSelectedOID.isAdditionalShape() )
     145                 :            :             {
     146         [ #  # ]:          0 :                 ListBoxEntryData aEntry;
     147 [ #  # ][ #  # ]:          0 :                 SdrObject* pSelectedObj = DrawViewWrapper::getSdrObject( aSelectedOID.getAdditionalShape() );
     148 [ #  # ][ #  # ]:          0 :                 rtl::OUString aName = pSelectedObj ? pSelectedObj->GetName() : rtl::OUString();
     149 [ #  # ][ #  # ]:          0 :                 aEntry.UIName = ( aName.isEmpty() ?  ::rtl::OUString( String( SchResId( STR_OBJECT_SHAPE ) ) ) : aName );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
     150         [ #  # ]:          0 :                 aEntry.OID = aSelectedOID;
     151 [ #  # ][ #  # ]:          0 :                 m_aEntries.push_back( aEntry );
     152                 :            :             }
     153                 :            :         }
     154                 :            : 
     155                 :       2271 :         sal_uInt16 nEntryPosToSelect = 0; bool bSelectionFound = false;
     156                 :       2271 :         aIt = m_aEntries.begin();
     157 [ +  - ][ +  + ]:      23605 :         for( sal_uInt16 nN=0; aIt != m_aEntries.end(); ++aIt, ++nN )
     158                 :            :         {
     159 [ +  - ][ +  - ]:      21334 :             InsertEntry( aIt->UIName );
                 [ +  - ]
     160 [ +  + ][ +  - ]:      21334 :             if ( !bSelectionFound && aSelectedOID == aIt->OID )
         [ +  - ][ +  + ]
     161                 :            :             {
     162                 :       2271 :                 nEntryPosToSelect = nN;
     163                 :       2271 :                 bSelectionFound = true;
     164                 :            :             }
     165                 :            :         }
     166                 :            : 
     167         [ +  - ]:       2271 :         if( bSelectionFound )
     168         [ +  - ]:       2271 :             SelectEntryPos(nEntryPosToSelect);
     169                 :            : 
     170         [ +  - ]:       2271 :         sal_uInt16 nEntryCount = GetEntryCount();
     171         [ -  + ]:       2271 :         if( nEntryCount > 100 )
     172                 :          0 :             nEntryCount = 100;
     173 [ +  - ][ +  - ]:       2271 :         SetDropDownLineCount( nEntryCount );
                 [ +  - ]
     174                 :            :     }
     175         [ +  - ]:       2271 :     SaveValue();//remind current selection pos
     176                 :       2271 : }
     177                 :            : 
     178                 :          0 : void SelectorListBox::ReleaseFocus_Impl()
     179                 :            : {
     180         [ #  # ]:          0 :     if ( !m_bReleaseFocus )
     181                 :            :     {
     182                 :          0 :         m_bReleaseFocus = true;
     183                 :          0 :         return;
     184                 :            :     }
     185                 :            : 
     186         [ #  # ]:          0 :     Reference< frame::XController > xController( m_xChartController );
     187 [ #  # ][ #  # ]:          0 :     Reference< frame::XFrame > xFrame( xController->getFrame() );
     188 [ #  # ][ #  # ]:          0 :     if ( xFrame.is() && xFrame->getContainerWindow().is() )
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
     189 [ #  # ][ #  # ]:          0 :         xFrame->getContainerWindow()->setFocus();
         [ #  # ][ #  # ]
     190                 :            : }
     191                 :            : 
     192                 :          0 : void SelectorListBox::Select()
     193                 :            : {
     194                 :          0 :     ListBox::Select();
     195                 :            : 
     196         [ #  # ]:          0 :     if ( !IsTravelSelect() )
     197                 :            :     {
     198                 :          0 :         sal_uInt16 nPos = GetSelectEntryPos();
     199         [ #  # ]:          0 :         if( nPos < m_aEntries.size() )
     200                 :            :         {
     201         [ #  # ]:          0 :             ObjectHierarchy::tOID aOID = m_aEntries[nPos].OID;
     202 [ #  # ][ #  # ]:          0 :             Reference< view::XSelectionSupplier > xSelectionSupplier( m_xChartController.get(), uno::UNO_QUERY );
     203         [ #  # ]:          0 :             if( xSelectionSupplier.is() )
     204 [ #  # ][ #  # ]:          0 :                 xSelectionSupplier->select( aOID.getAny() );
         [ #  # ][ #  # ]
     205                 :            :         }
     206                 :          0 :         ReleaseFocus_Impl();
     207                 :            :     }
     208                 :          0 : }
     209                 :            : 
     210                 :          0 : long SelectorListBox::Notify( NotifyEvent& rNEvt )
     211                 :            : {
     212                 :          0 :     long nHandled = 0;
     213                 :            : 
     214         [ #  # ]:          0 :     if ( rNEvt.GetType() == EVENT_KEYINPUT )
     215                 :            :     {
     216                 :          0 :         sal_uInt16 nCode = rNEvt.GetKeyEvent()->GetKeyCode().GetCode();
     217                 :            : 
     218      [ #  #  # ]:          0 :         switch ( nCode )
     219                 :            :         {
     220                 :            :             case KEY_RETURN:
     221                 :            :             case KEY_TAB:
     222                 :            :             {
     223         [ #  # ]:          0 :                 if ( KEY_TAB == nCode )
     224                 :          0 :                     m_bReleaseFocus = false;
     225                 :            :                 else
     226                 :          0 :                     nHandled = 1;
     227                 :          0 :                 Select();
     228                 :          0 :                 break;
     229                 :            :             }
     230                 :            : 
     231                 :            :             case KEY_ESCAPE:
     232                 :          0 :                 SelectEntryPos( GetSavedValue() ); //restore saved selection
     233                 :          0 :                 ReleaseFocus_Impl();
     234                 :          0 :                 break;
     235                 :            :         }
     236                 :            :     }
     237         [ #  # ]:          0 :     else if ( EVENT_LOSEFOCUS == rNEvt.GetType() )
     238                 :            :     {
     239         [ #  # ]:          0 :         if ( !HasFocus() )
     240                 :          0 :             SelectEntryPos( GetSavedValue() );
     241                 :            :     }
     242                 :            : 
     243         [ #  # ]:          0 :     return nHandled ? nHandled : ListBox::Notify( rNEvt );
     244                 :            : }
     245                 :            : 
     246                 :          0 : Reference< ::com::sun::star::accessibility::XAccessible > SelectorListBox::CreateAccessible()
     247                 :            : {
     248                 :          0 :     UpdateChartElementsListAndSelection();
     249                 :          0 :     return ListBox::CreateAccessible();
     250                 :            : }
     251                 :            : 
     252                 :            : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     253 [ #  # ][ #  # ]:         32 : APPHELPER_XSERVICEINFO_IMPL( ElementSelectorToolbarController, lcl_aServiceName );
         [ #  # ][ #  # ]
                 [ #  # ]
     254                 :            : 
     255                 :            : //------------------------------------------------------------------------------
     256                 :          4 : Sequence< ::rtl::OUString > ElementSelectorToolbarController::getSupportedServiceNames_Static()
     257                 :            : {
     258                 :          4 :     Sequence< ::rtl::OUString > aServices(1);
     259 [ +  - ][ +  - ]:          4 :     aServices[ 0 ] = C2U( "com.sun.star.frame.ToolbarController" );
     260                 :          4 :     return aServices;
     261                 :            : }
     262                 :            : // -----------------------------------------------------------------------------
     263                 :         34 : ElementSelectorToolbarController::ElementSelectorToolbarController( const uno::Reference< uno::XComponentContext > & xContext )
     264                 :         34 :     : m_xCC( xContext )
     265                 :            : {
     266                 :         34 : }
     267                 :            : // -----------------------------------------------------------------------------
     268         [ +  - ]:         34 : ElementSelectorToolbarController::~ElementSelectorToolbarController()
     269                 :            : {
     270         [ -  + ]:         68 : }
     271                 :            : // -----------------------------------------------------------------------------
     272                 :            : // XInterface
     273                 :       2611 : Any SAL_CALL ElementSelectorToolbarController::queryInterface( const Type& _rType ) throw (RuntimeException)
     274                 :            : {
     275                 :       2611 :     Any aReturn = ToolboxController::queryInterface(_rType);
     276         [ +  + ]:       2611 :     if (!aReturn.hasValue())
     277         [ +  - ]:         34 :         aReturn = ElementSelectorToolbarController_BASE::queryInterface(_rType);
     278                 :       2611 :     return aReturn;
     279                 :            : }
     280                 :            : // -----------------------------------------------------------------------------
     281                 :       7663 : void SAL_CALL ElementSelectorToolbarController::acquire() throw ()
     282                 :            : {
     283                 :       7663 :     ToolboxController::acquire();
     284                 :       7663 : }
     285                 :            : // -----------------------------------------------------------------------------
     286                 :       7663 : void SAL_CALL ElementSelectorToolbarController::release() throw ()
     287                 :            : {
     288                 :       7663 :     ToolboxController::release();
     289                 :       7663 : }
     290                 :            : // -----------------------------------------------------------------------------
     291                 :         34 : void SAL_CALL ElementSelectorToolbarController::initialize( const Sequence< Any >& rArguments ) throw (Exception, RuntimeException)
     292                 :            : {
     293                 :         34 :     ToolboxController::initialize(rArguments);
     294                 :         34 : }
     295                 :            : // -----------------------------------------------------------------------------
     296                 :       2271 : void SAL_CALL ElementSelectorToolbarController::statusChanged( const frame::FeatureStateEvent& rEvent ) throw ( RuntimeException )
     297                 :            : {
     298         [ +  - ]:       2271 :     if( m_apSelectorListBox.get() )
     299                 :            :     {
     300         [ +  - ]:       2271 :         SolarMutexGuard aSolarMutexGuard;
     301         [ +  - ]:       2271 :         if ( rEvent.FeatureURL.Path == "ChartElementSelector" )
     302                 :            :         {
     303                 :       2271 :             Reference< frame::XController > xChartController;
     304         [ +  - ]:       2271 :             rEvent.State >>= xChartController;
     305         [ +  - ]:       2271 :             m_apSelectorListBox->SetChartController( xChartController );
     306         [ +  - ]:       2271 :             m_apSelectorListBox->UpdateChartElementsListAndSelection();
     307         [ +  - ]:       2271 :         }
     308                 :            :     }
     309                 :       2271 : }
     310                 :            : // -----------------------------------------------------------------------------
     311                 :         34 : uno::Reference< awt::XWindow > SAL_CALL ElementSelectorToolbarController::createItemWindow( const uno::Reference< awt::XWindow >& xParent )
     312                 :            :         throw (uno::RuntimeException)
     313                 :            : {
     314                 :         34 :     uno::Reference< awt::XWindow > xItemWindow;
     315         [ +  - ]:         34 :     if( !m_apSelectorListBox.get() )
     316                 :            :     {
     317         [ +  - ]:         34 :         Window* pParent = VCLUnoHelper::GetWindow( xParent );
     318         [ +  - ]:         34 :         if( pParent )
     319                 :            :         {
     320 [ +  - ][ +  - ]:         34 :             m_apSelectorListBox = ::std::auto_ptr< SelectorListBox >( new SelectorListBox( pParent, WB_DROPDOWN|WB_AUTOHSCROLL|WB_BORDER ) );
                 [ +  - ]
     321                 :         34 :             ::Size aLogicalSize( 95, 160 );
     322 [ +  - ][ +  - ]:         34 :             ::Size aPixelSize = m_apSelectorListBox->LogicToPixel( aLogicalSize, MAP_APPFONT );
                 [ +  - ]
     323         [ +  - ]:         34 :             m_apSelectorListBox->SetSizePixel( aPixelSize );
     324         [ +  - ]:         34 :             m_apSelectorListBox->SetDropDownLineCount( 5 );
     325                 :            :         }
     326                 :            :     }
     327         [ +  - ]:         34 :     if( m_apSelectorListBox.get() )
     328 [ +  - ][ +  - ]:         34 :         xItemWindow = VCLUnoHelper::GetInterface( m_apSelectorListBox.get() );
     329                 :         34 :     return xItemWindow;
     330                 :            : }
     331                 :            : 
     332                 :            : //..........................................................................
     333 [ +  - ][ +  - ]:         48 : } // chart2
     334                 :            : //..........................................................................
     335                 :            : 
     336                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10