LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/controller/main - ElementSelector.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 3 171 1.8 %
Date: 2012-12-27 Functions: 3 26 11.5 %
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           1 : static const ::rtl::OUString lcl_aServiceName(
      52             :     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart.ElementSelectorToolbarController" ));
      53             : }
      54             : 
      55             : //------------------------------------------------------------------------------
      56             : 
      57           0 : SelectorListBox::SelectorListBox( Window* pParent, WinBits nStyle )
      58             :     : ListBox( pParent, nStyle )
      59           0 :     , m_bReleaseFocus( true )
      60             : {
      61           0 : }
      62             : 
      63           0 : SelectorListBox::~SelectorListBox()
      64             : {
      65           0 : }
      66             : 
      67           0 : 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           0 :     ObjectHierarchy::tChildContainer aChildren( rHierarchy.getChildren(rParent) );
      71           0 :     ObjectHierarchy::tChildContainer::const_iterator aIt( aChildren.begin());
      72           0 :     while( aIt != aChildren.end() )
      73             :     {
      74           0 :         ObjectHierarchy::tOID aOID = *aIt;
      75           0 :         ::rtl::OUString aCID = aOID.getObjectCID();
      76           0 :         ListBoxEntryData aEntry;
      77           0 :         aEntry.OID = aOID;
      78           0 :         aEntry.UIName += ObjectNameProvider::getNameForCID( aCID, xChartDoc );
      79           0 :         aEntry.nHierarchyDepth = nHierarchyDepth;
      80           0 :         rEntries.push_back(aEntry);
      81           0 :         lcl_addObjectsToList( rHierarchy, aOID, rEntries, nHierarchyDepth+1, xChartDoc );
      82           0 :         ++aIt;
      83           0 :     }
      84           0 : }
      85             : 
      86           0 : void SelectorListBox::SetChartController( const Reference< frame::XController >& xChartController )
      87             : {
      88           0 :     m_xChartController = xChartController;
      89           0 : }
      90             : 
      91           0 : void SelectorListBox::UpdateChartElementsListAndSelection()
      92             : {
      93           0 :     Clear();
      94           0 :     m_aEntries.clear();
      95             : 
      96           0 :     Reference< frame::XController > xChartController( m_xChartController );
      97           0 :     if( xChartController.is() )
      98             :     {
      99           0 :         Reference< view::XSelectionSupplier > xSelectionSupplier( xChartController, uno::UNO_QUERY);
     100           0 :         ObjectHierarchy::tOID aSelectedOID;
     101           0 :         rtl::OUString aSelectedCID;
     102           0 :         if( xSelectionSupplier.is() )
     103             :         {
     104           0 :             aSelectedOID = ObjectIdentifier( xSelectionSupplier->getSelection() );
     105           0 :             aSelectedCID = aSelectedOID.getObjectCID();
     106             :         }
     107             : 
     108           0 :         Reference< chart2::XChartDocument > xChartDoc( xChartController->getModel(), uno::UNO_QUERY );
     109           0 :         ObjectType eType( aSelectedOID.getObjectType() );
     110           0 :         bool bAddSelectionToList = false;
     111           0 :         if ( eType == OBJECTTYPE_DATA_POINT || eType == OBJECTTYPE_DATA_LABEL || eType == OBJECTTYPE_SHAPE )
     112           0 :             bAddSelectionToList = true;
     113             : 
     114           0 :         Reference< uno::XInterface > xChartView;
     115           0 :         Reference< lang::XMultiServiceFactory > xFact( xChartController->getModel(), uno::UNO_QUERY );
     116           0 :         if( xFact.is() )
     117           0 :             xChartView = xFact->createInstance( CHART_VIEW_SERVICE_NAME );
     118           0 :         ExplicitValueProvider* pExplicitValueProvider = 0;//ExplicitValueProvider::getExplicitValueProvider(xChartView); dies erzeugt alle sichtbaren datenpinkte, das ist zu viel
     119           0 :         ObjectHierarchy aHierarchy( xChartDoc, pExplicitValueProvider, true /*bFlattenDiagram*/, true /*bOrderingForElementSelector*/ );
     120           0 :         lcl_addObjectsToList( aHierarchy, aHierarchy.getRootNodeOID(), m_aEntries, 0, xChartDoc );
     121             : 
     122           0 :         std::vector< ListBoxEntryData >::iterator aIt( m_aEntries.begin() );
     123           0 :         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           0 :         sal_uInt16 nEntryPosToSelect = 0; bool bSelectionFound = false;
     156           0 :         aIt = m_aEntries.begin();
     157           0 :         for( sal_uInt16 nN=0; aIt != m_aEntries.end(); ++aIt, ++nN )
     158             :         {
     159           0 :             InsertEntry( aIt->UIName );
     160           0 :             if ( !bSelectionFound && aSelectedOID == aIt->OID )
     161             :             {
     162           0 :                 nEntryPosToSelect = nN;
     163           0 :                 bSelectionFound = true;
     164             :             }
     165             :         }
     166             : 
     167           0 :         if( bSelectionFound )
     168           0 :             SelectEntryPos(nEntryPosToSelect);
     169             : 
     170           0 :         sal_uInt16 nEntryCount = GetEntryCount();
     171           0 :         if( nEntryCount > 100 )
     172           0 :             nEntryCount = 100;
     173           0 :         SetDropDownLineCount( nEntryCount );
     174             :     }
     175           0 :     SaveValue();//remind current selection pos
     176           0 : }
     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           1 : APPHELPER_XSERVICEINFO_IMPL( ElementSelectorToolbarController, lcl_aServiceName );
     254             : 
     255             : //------------------------------------------------------------------------------
     256           0 : Sequence< ::rtl::OUString > ElementSelectorToolbarController::getSupportedServiceNames_Static()
     257             : {
     258           0 :     Sequence< ::rtl::OUString > aServices(1);
     259           0 :     aServices[ 0 ] = C2U( "com.sun.star.frame.ToolbarController" );
     260           0 :     return aServices;
     261             : }
     262             : // -----------------------------------------------------------------------------
     263           0 : ElementSelectorToolbarController::ElementSelectorToolbarController( const uno::Reference< uno::XComponentContext > & xContext )
     264           0 :     : m_xCC( xContext )
     265             : {
     266           0 : }
     267             : // -----------------------------------------------------------------------------
     268           0 : ElementSelectorToolbarController::~ElementSelectorToolbarController()
     269             : {
     270           0 : }
     271             : // -----------------------------------------------------------------------------
     272             : // XInterface
     273           0 : Any SAL_CALL ElementSelectorToolbarController::queryInterface( const Type& _rType ) throw (RuntimeException)
     274             : {
     275           0 :     Any aReturn = ToolboxController::queryInterface(_rType);
     276           0 :     if (!aReturn.hasValue())
     277           0 :         aReturn = ElementSelectorToolbarController_BASE::queryInterface(_rType);
     278           0 :     return aReturn;
     279             : }
     280             : // -----------------------------------------------------------------------------
     281           0 : void SAL_CALL ElementSelectorToolbarController::acquire() throw ()
     282             : {
     283           0 :     ToolboxController::acquire();
     284           0 : }
     285             : // -----------------------------------------------------------------------------
     286           0 : void SAL_CALL ElementSelectorToolbarController::release() throw ()
     287             : {
     288           0 :     ToolboxController::release();
     289           0 : }
     290             : // -----------------------------------------------------------------------------
     291           0 : void SAL_CALL ElementSelectorToolbarController::initialize( const Sequence< Any >& rArguments ) throw (Exception, RuntimeException)
     292             : {
     293           0 :     ToolboxController::initialize(rArguments);
     294           0 : }
     295             : // -----------------------------------------------------------------------------
     296           0 : void SAL_CALL ElementSelectorToolbarController::statusChanged( const frame::FeatureStateEvent& rEvent ) throw ( RuntimeException )
     297             : {
     298           0 :     if( m_apSelectorListBox.get() )
     299             :     {
     300           0 :         SolarMutexGuard aSolarMutexGuard;
     301           0 :         if ( rEvent.FeatureURL.Path == "ChartElementSelector" )
     302             :         {
     303           0 :             Reference< frame::XController > xChartController;
     304           0 :             rEvent.State >>= xChartController;
     305           0 :             m_apSelectorListBox->SetChartController( xChartController );
     306           0 :             m_apSelectorListBox->UpdateChartElementsListAndSelection();
     307           0 :         }
     308             :     }
     309           0 : }
     310             : // -----------------------------------------------------------------------------
     311           0 : uno::Reference< awt::XWindow > SAL_CALL ElementSelectorToolbarController::createItemWindow( const uno::Reference< awt::XWindow >& xParent )
     312             :         throw (uno::RuntimeException)
     313             : {
     314           0 :     uno::Reference< awt::XWindow > xItemWindow;
     315           0 :     if( !m_apSelectorListBox.get() )
     316             :     {
     317           0 :         Window* pParent = VCLUnoHelper::GetWindow( xParent );
     318           0 :         if( pParent )
     319             :         {
     320           0 :             m_apSelectorListBox = ::std::auto_ptr< SelectorListBox >( new SelectorListBox( pParent, WB_DROPDOWN|WB_AUTOHSCROLL|WB_BORDER ) );
     321           0 :             ::Size aLogicalSize( 95, 160 );
     322           0 :             ::Size aPixelSize = m_apSelectorListBox->LogicToPixel( aLogicalSize, MAP_APPFONT );
     323           0 :             m_apSelectorListBox->SetSizePixel( aPixelSize );
     324           0 :             m_apSelectorListBox->SetDropDownLineCount( 5 );
     325             :         }
     326             :     }
     327           0 :     if( m_apSelectorListBox.get() )
     328           0 :         xItemWindow = VCLUnoHelper::GetInterface( m_apSelectorListBox.get() );
     329           0 :     return xItemWindow;
     330             : }
     331             : 
     332             : //..........................................................................
     333           3 : } // chart2
     334             : //..........................................................................
     335             : 
     336             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10