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

Generated by: LCOV version 1.10