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

Generated by: LCOV version 1.10