LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/controller/dialogs - dlg_DataSource.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 81 0.0 %
Date: 2012-12-17 Functions: 0 16 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 "dlg_DataSource.hxx"
      22             : #include "dlg_DataSource.hrc"
      23             : #include "Strings.hrc"
      24             : #include "ResId.hxx"
      25             : #include "ChartTypeTemplateProvider.hxx"
      26             : #include "DiagramHelper.hxx"
      27             : #include "DialogModel.hxx"
      28             : #include "HelpIds.hrc"
      29             : 
      30             : #include "tp_RangeChooser.hxx"
      31             : #include "tp_DataSource.hxx"
      32             : 
      33             : // for RET_OK
      34             : #include <vcl/msgbox.hxx>
      35             : 
      36             : using namespace ::com::sun::star;
      37             : using namespace ::com::sun::star::chart2;
      38             : using namespace ::chart;
      39             : 
      40             : using ::com::sun::star::uno::Reference;
      41             : using ::com::sun::star::uno::Sequence;
      42             : using ::rtl::OUString;
      43             : 
      44             : // --------------------------------------------------------------------------------
      45             : 
      46             : 
      47             : namespace chart
      48             : {
      49             : 
      50             : // ----------------------------------------
      51             : 
      52             : class DocumentChartTypeTemplateProvider : public ChartTypeTemplateProvider
      53             : {
      54             : public:
      55             :     DocumentChartTypeTemplateProvider(
      56             :         const Reference< chart2::XChartDocument > & xDoc );
      57             :     virtual ~DocumentChartTypeTemplateProvider();
      58             : 
      59             :     // ____ ChartTypeTemplateProvider ____
      60             :     virtual Reference< chart2::XChartTypeTemplate > getCurrentTemplate() const;
      61             : 
      62             : private:
      63             :     Reference< chart2::XChartTypeTemplate > m_xTemplate;
      64             : };
      65             : 
      66           0 : DocumentChartTypeTemplateProvider::DocumentChartTypeTemplateProvider(
      67           0 :     const Reference< chart2::XChartDocument > & xDoc )
      68             : {
      69           0 :     if( xDoc.is())
      70             :     {
      71           0 :         Reference< chart2::XDiagram > xDia( xDoc->getFirstDiagram());
      72           0 :         if( xDia.is())
      73             :         {
      74             :             DiagramHelper::tTemplateWithServiceName aResult(
      75             :                 DiagramHelper::getTemplateForDiagram(
      76             :                     xDia,
      77             :                     Reference< lang::XMultiServiceFactory >(
      78           0 :                         xDoc->getChartTypeManager(), uno::UNO_QUERY ) ));
      79           0 :             m_xTemplate.set( aResult.first );
      80           0 :         }
      81             :     }
      82           0 : }
      83             : 
      84           0 : DocumentChartTypeTemplateProvider::~DocumentChartTypeTemplateProvider()
      85           0 : {}
      86             : 
      87           0 : Reference< chart2::XChartTypeTemplate > DocumentChartTypeTemplateProvider::getCurrentTemplate() const
      88             : {
      89           0 :     return m_xTemplate;
      90             : }
      91             : 
      92             : // ----------------------------------------
      93             : 
      94             : class DataSourceTabControl : public TabControl
      95             : {
      96             : public:
      97             :     DataSourceTabControl( Window* pParent, const ResId& rResId );
      98             :     ~DataSourceTabControl();
      99             : 
     100             :     virtual long DeactivatePage();
     101             : 
     102             :     void DisableTabToggling();
     103             :     void EnableTabToggling();
     104             : 
     105             : private:
     106             :     bool m_bTogglingEnabled;
     107             : };
     108             : 
     109           0 : DataSourceTabControl::DataSourceTabControl( Window* pParent, const ResId& rResId ) :
     110             :         TabControl( pParent, rResId ),
     111           0 :         m_bTogglingEnabled( true )
     112           0 : {}
     113             : 
     114           0 : DataSourceTabControl::~DataSourceTabControl()
     115           0 : {}
     116             : 
     117             : // Note that the result is long, but is intended to be a bool
     118           0 : long DataSourceTabControl::DeactivatePage()
     119             : {
     120           0 :     bool bCanDeactivate( TabControl::DeactivatePage() != 0 );
     121             : 
     122           0 :     bCanDeactivate = (bCanDeactivate && m_bTogglingEnabled);
     123             : 
     124           0 :     return (bCanDeactivate ? 1 : 0 );
     125             : }
     126             : 
     127           0 : void DataSourceTabControl::DisableTabToggling()
     128             : {
     129           0 :     m_bTogglingEnabled = false;
     130           0 : }
     131             : 
     132           0 : void DataSourceTabControl::EnableTabToggling()
     133             : {
     134           0 :     m_bTogglingEnabled = true;
     135           0 : }
     136             : 
     137             : // ----------------------------------------
     138             : 
     139             : sal_uInt16 DataSourceDialog::m_nLastPageId = 0;
     140             : 
     141           0 : DataSourceDialog::DataSourceDialog(
     142             :     Window * pParent,
     143             :     const Reference< XChartDocument > & xChartDocument,
     144             :     const Reference< uno::XComponentContext > & xContext ) :
     145             : 
     146             :         TabDialog( pParent, SchResId( DLG_DATA_SOURCE )),
     147             : 
     148             :         m_xChartDocument( xChartDocument ),
     149             :         m_xContext( xContext ),
     150           0 :         m_apDocTemplateProvider( new DocumentChartTypeTemplateProvider( xChartDocument )),
     151           0 :         m_apDialogModel( new DialogModel( xChartDocument, xContext )),
     152             : 
     153           0 :         m_pTabControl( new DataSourceTabControl( this, SchResId( TABCTRL ) )),
     154             :         m_aBtnOK( this, SchResId( BTN_OK ) ),
     155             :         m_aBtnCancel( this, SchResId( BTN_CANCEL ) ),
     156             :         m_aBtnHelp( this, SchResId( BTN_HELP ) ),
     157             : 
     158             :         m_pRangeChooserTabePage(0),
     159             :         m_pDataSourceTabPage(0),
     160             :         m_bRangeChooserTabIsValid( true ),
     161           0 :         m_bDataSourceTabIsValid( true )
     162             : {
     163           0 :     FreeResource();
     164             : 
     165             :     //don't create the tabpages before FreeResource, otherwise the help ids are not matched correctly
     166           0 :     m_pRangeChooserTabePage = new RangeChooserTabPage( m_pTabControl, *(m_apDialogModel.get()),
     167           0 :                                      m_apDocTemplateProvider.get(), this, true /* bHideDescription */ );
     168           0 :     m_pDataSourceTabPage = new DataSourceTabPage( m_pTabControl, *(m_apDialogModel.get()),
     169           0 :                                     m_apDocTemplateProvider.get(), this, true /* bHideDescription */ );
     170             : 
     171           0 :     m_pTabControl->InsertPage( TP_RANGECHOOSER, String( SchResId( STR_PAGE_DATA_RANGE )));
     172           0 :     m_pTabControl->InsertPage( TP_DATA_SOURCE,  String( SchResId( STR_OBJECT_DATASERIES_PLURAL )));
     173             : 
     174           0 :     m_pTabControl->SetTabPage( TP_RANGECHOOSER, m_pRangeChooserTabePage );
     175           0 :     m_pTabControl->SetTabPage( TP_DATA_SOURCE,  m_pDataSourceTabPage );
     176             : 
     177           0 :     m_pTabControl->SelectTabPage( m_nLastPageId );
     178             : 
     179           0 :     SetHelpId( HID_SCH_DLG_RANGES );
     180           0 : }
     181             : 
     182           0 : DataSourceDialog::~DataSourceDialog()
     183             : {
     184           0 :     delete m_pRangeChooserTabePage;
     185           0 :     delete m_pDataSourceTabPage;
     186             : 
     187           0 :     m_nLastPageId = m_pTabControl->GetCurPageId();
     188           0 :     delete m_pTabControl;
     189           0 : }
     190             : 
     191           0 : short DataSourceDialog::Execute()
     192             : {
     193           0 :     short nResult = TabDialog::Execute();
     194           0 :     if( nResult == RET_OK )
     195             :     {
     196           0 :         if( m_pRangeChooserTabePage )
     197           0 :             m_pRangeChooserTabePage->commitPage();
     198           0 :         if( m_pDataSourceTabPage )
     199           0 :             m_pDataSourceTabPage->commitPage();
     200             :     }
     201           0 :     return nResult;
     202             : }
     203             : 
     204           0 : void DataSourceDialog::setInvalidPage( TabPage * pTabPage )
     205             : {
     206           0 :     if( pTabPage == m_pRangeChooserTabePage )
     207           0 :         m_bRangeChooserTabIsValid = false;
     208           0 :     else if( pTabPage == m_pDataSourceTabPage )
     209           0 :         m_bDataSourceTabIsValid = false;
     210             : 
     211           0 :     if( ! (m_bRangeChooserTabIsValid && m_bDataSourceTabIsValid ))
     212             :     {
     213           0 :         m_aBtnOK.Enable( sal_False );
     214             :         OSL_ASSERT( m_pTabControl );
     215             :         // note: there seems to be no suitable mechanism to address pages by
     216             :         // identifier, at least it is unclear what the page identifiers are.
     217             :         // @todo: change the fixed numbers to identifiers
     218           0 :         if( m_bRangeChooserTabIsValid )
     219           0 :             m_pTabControl->SetCurPageId( m_pTabControl->GetPageId( 1 ));
     220           0 :         else if( m_bDataSourceTabIsValid )
     221           0 :             m_pTabControl->SetCurPageId( m_pTabControl->GetPageId( 0 ));
     222           0 :         m_pTabControl->DisableTabToggling();
     223             :     }
     224           0 : }
     225             : 
     226           0 : void DataSourceDialog::setValidPage( TabPage * pTabPage )
     227             : {
     228           0 :     if( pTabPage == m_pRangeChooserTabePage )
     229           0 :         m_bRangeChooserTabIsValid = true;
     230           0 :     else if( pTabPage == m_pDataSourceTabPage )
     231           0 :         m_bDataSourceTabIsValid = true;
     232             : 
     233           0 :     if( m_bRangeChooserTabIsValid && m_bDataSourceTabIsValid )
     234             :     {
     235           0 :         m_aBtnOK.Enable( sal_True );
     236             :         OSL_ASSERT( m_pTabControl );
     237           0 :         m_pTabControl->EnableTabToggling();
     238             :     }
     239           0 : }
     240             : 
     241             : 
     242             : } //  namespace chart
     243             : 
     244             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10