LCOV - code coverage report
Current view: top level - chart2/source/controller/dialogs - tp_RangeChooser.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 213 0.5 %
Date: 2015-06-13 12:38:46 Functions: 2 24 8.3 %
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 "tp_RangeChooser.hxx"
      21             : #include "Strings.hrc"
      22             : #include "ResId.hxx"
      23             : #include "macros.hxx"
      24             : #include "DataSourceHelper.hxx"
      25             : #include "DiagramHelper.hxx"
      26             : #include "ChartTypeTemplateProvider.hxx"
      27             : #include "DialogModel.hxx"
      28             : #include "RangeSelectionHelper.hxx"
      29             : #include <com/sun/star/awt/XTopWindow.hpp>
      30             : #include <com/sun/star/embed/EmbedStates.hpp>
      31             : #include <com/sun/star/embed/XComponentSupplier.hpp>
      32             : #include <svtools/miscopt.hxx>
      33             : 
      34             : namespace
      35             : {
      36           0 :     void lcl_ShowChooserButton(
      37             :         PushButton& rChooserButton,
      38             :         bool bShow)
      39             :     {
      40           0 :         if( rChooserButton.IsVisible() != bShow )
      41             :         {
      42           0 :             rChooserButton.Show( bShow );
      43             :         }
      44           0 :     }
      45             : 
      46           0 :     void lcl_enableRangeChoosing( bool bEnable, Dialog * pDialog )
      47             :     {
      48           0 :         if( pDialog )
      49             :         {
      50           0 :             pDialog->Show( !bEnable );
      51           0 :             pDialog->SetModalInputMode( !bEnable );
      52             :         }
      53           0 :     }
      54             : 
      55             : } // anonymous namespace
      56             : 
      57             : namespace chart
      58             : {
      59             : using namespace ::com::sun::star;
      60             : using namespace ::com::sun::star::chart2;
      61             : 
      62             : using ::com::sun::star::uno::Reference;
      63             : using ::com::sun::star::uno::Sequence;
      64             : 
      65           0 : RangeChooserTabPage::RangeChooserTabPage( vcl::Window* pParent
      66             :         , DialogModel & rDialogModel
      67             :         , ChartTypeTemplateProvider* pTemplateProvider
      68             :         , Dialog * pParentDialog
      69             :         , bool bHideDescription /* = false */ )
      70             :         : OWizardPage( pParent
      71             :         ,"tp_RangeChooser"
      72             :         ,"modules/schart/ui/tp_RangeChooser.ui")
      73             :         , m_nChangingControlCalls(0)
      74             :         , m_bIsDirty(false)
      75             :         , m_xDataProvider( 0 )
      76             :         , m_aLastValidRangeString()
      77             :         , m_xCurrentChartTypeTemplate(0)
      78             :         , m_pTemplateProvider(pTemplateProvider)
      79             :         , m_rDialogModel( rDialogModel )
      80             :         , m_pParentDialog( pParentDialog )
      81           0 :         , m_pTabPageNotifiable( dynamic_cast< TabPageNotifiable * >( pParentDialog ))
      82             : {
      83           0 :     get(m_pFT_Caption, "FT_CAPTION_FOR_WIZARD");
      84           0 :     get(m_pFT_Range, "FT_RANGE");
      85           0 :     get(m_pED_Range, "ED_RANGE");
      86           0 :     get(m_pIB_Range, "IB_RANGE");
      87           0 :     get(m_pRB_Rows, "RB_DATAROWS");
      88           0 :     get(m_pRB_Columns, "RB_DATACOLS");
      89           0 :     get(m_pCB_FirstRowAsLabel, "CB_FIRST_ROW_ASLABELS");
      90           0 :     get(m_pCB_FirstColumnAsLabel, "CB_FIRST_COLUMN_ASLABELS");
      91           0 :     get(m_pFTTitle, "STR_PAGE_DATA_RANGE");// OH:remove later with dialog title
      92           0 :     get(m_pFL_TimeBased, "separator1");
      93           0 :     get(m_pCB_TimeBased, "CB_TIME_BASED");
      94           0 :     get(m_pFT_TimeStart, "label1");
      95           0 :     get(m_pEd_TimeStart, "ED_TIME_BASED_START");
      96           0 :     get(m_pFT_TimeEnd, "label2");
      97           0 :     get(m_pEd_TimeEnd, "ED_TIME_BASED_END");
      98             : 
      99           0 :     m_pFT_Caption->Show(!bHideDescription);
     100             : 
     101           0 :     this->SetText( m_pFTTitle->GetText());// OH:remove later with dialog
     102             : 
     103             :     // set defaults as long as DetectArguments does not work
     104           0 :     m_pRB_Columns->Check();
     105           0 :     m_pCB_FirstColumnAsLabel->Check();
     106           0 :     m_pCB_FirstRowAsLabel->Check();
     107             : 
     108             :     // BM: Note, that the range selection is not available, if there is no view.
     109             :     // This happens for charts having their own embedded spreadsheet.  If you
     110             :     // force to get the range selection here, this would mean when entering this
     111             :     // page the calc view would be created in this case.  So, I enable the
     112             :     // button here, and in the worst case nothing happens when it is pressed.
     113             :     // Not nice, but I see no better solution for the moment.
     114           0 :     m_pIB_Range->SetClickHdl( LINK( this, RangeChooserTabPage, ChooseRangeHdl ));
     115             : 
     116             :     // #i75179# enable setting the background to a different color
     117           0 :     m_pED_Range->SetStyle( m_pED_Range->GetStyle() | WB_FORCECTRLBACKGROUND );
     118             : 
     119           0 :     m_pED_Range->SetUpdateDataHdl( LINK( this, RangeChooserTabPage, ControlChangedHdl ));
     120           0 :     m_pED_Range->SetModifyHdl( LINK( this, RangeChooserTabPage, ControlEditedHdl ));
     121           0 :     m_pRB_Rows->SetToggleHdl( LINK( this, RangeChooserTabPage, ControlChangedHdl ) );
     122           0 :     m_pCB_FirstRowAsLabel->SetToggleHdl( LINK( this, RangeChooserTabPage, ControlChangedHdl ) );
     123           0 :     m_pCB_FirstColumnAsLabel->SetToggleHdl( LINK( this, RangeChooserTabPage, ControlChangedHdl ) );
     124           0 :     m_pCB_TimeBased->SetToggleHdl( LINK( this, RangeChooserTabPage, ControlChangedHdl ) );
     125           0 :     m_pEd_TimeStart->SetModifyHdl( LINK( this, RangeChooserTabPage, ControlChangedHdl ) );
     126           0 :     m_pEd_TimeEnd->SetModifyHdl( LINK( this, RangeChooserTabPage, ControlChangedHdl ) );
     127             : 
     128           0 :     SvtMiscOptions aOpts;
     129           0 :     if ( !aOpts.IsExperimentalMode() )
     130             :     {
     131           0 :         m_pFL_TimeBased->Hide();
     132           0 :         m_pCB_TimeBased->Hide();
     133           0 :         m_pFT_TimeStart->Hide();
     134           0 :         m_pEd_TimeStart->Hide();
     135           0 :         m_pFT_TimeEnd->Hide();
     136           0 :         m_pEd_TimeEnd->Hide();
     137           0 :     }
     138           0 : }
     139             : 
     140           0 : RangeChooserTabPage::~RangeChooserTabPage()
     141             : {
     142           0 :     disposeOnce();
     143           0 : }
     144             : 
     145           0 : void RangeChooserTabPage::dispose()
     146             : {
     147           0 :     m_pFT_Caption.clear();
     148           0 :     m_pFT_Range.clear();
     149           0 :     m_pED_Range.clear();
     150           0 :     m_pIB_Range.clear();
     151           0 :     m_pRB_Rows.clear();
     152           0 :     m_pRB_Columns.clear();
     153           0 :     m_pCB_FirstRowAsLabel.clear();
     154           0 :     m_pCB_FirstColumnAsLabel.clear();
     155           0 :     m_pFTTitle.clear();
     156           0 :     m_pFL_TimeBased.clear();
     157           0 :     m_pCB_TimeBased.clear();
     158           0 :     m_pFT_TimeStart.clear();
     159           0 :     m_pEd_TimeStart.clear();
     160           0 :     m_pFT_TimeEnd.clear();
     161           0 :     m_pEd_TimeEnd.clear();
     162           0 :     m_pParentDialog.clear();
     163           0 :     OWizardPage::dispose();
     164           0 : }
     165             : 
     166             : 
     167           0 : void RangeChooserTabPage::ActivatePage()
     168             : {
     169           0 :     OWizardPage::ActivatePage();
     170           0 :     initControlsFromModel();
     171           0 : }
     172             : 
     173           0 : void RangeChooserTabPage::initControlsFromModel()
     174             : {
     175           0 :     m_nChangingControlCalls++;
     176             : 
     177           0 :     if(m_pTemplateProvider)
     178           0 :         m_xCurrentChartTypeTemplate = m_pTemplateProvider->getCurrentTemplate();
     179             : 
     180           0 :     bool bUseColumns = ! m_pRB_Rows->IsChecked();
     181           0 :     bool bFirstCellAsLabel = bUseColumns ? m_pCB_FirstRowAsLabel->IsChecked() : m_pCB_FirstColumnAsLabel->IsChecked();
     182           0 :     bool bHasCategories = bUseColumns ? m_pCB_FirstColumnAsLabel->IsChecked() : m_pCB_FirstRowAsLabel->IsChecked();
     183             : 
     184           0 :     bool bIsValid = m_rDialogModel.allArgumentsForRectRangeDetected();
     185           0 :     if( bIsValid )
     186           0 :         m_rDialogModel.detectArguments(m_aLastValidRangeString, bUseColumns, bFirstCellAsLabel, bHasCategories );
     187             :     else
     188           0 :         m_aLastValidRangeString.clear();
     189             : 
     190           0 :     m_pED_Range->SetText( m_aLastValidRangeString );
     191             : 
     192           0 :     m_pRB_Rows->Check( !bUseColumns );
     193           0 :     m_pRB_Columns->Check(  bUseColumns );
     194             : 
     195           0 :     m_pCB_FirstRowAsLabel->Check( m_pRB_Rows->IsChecked()?bHasCategories:bFirstCellAsLabel  );
     196           0 :     m_pCB_FirstColumnAsLabel->Check( m_pRB_Columns->IsChecked()?bHasCategories:bFirstCellAsLabel  );
     197             : 
     198           0 :     isValid();
     199             : 
     200           0 :     m_nChangingControlCalls--;
     201           0 : }
     202             : 
     203           0 : void RangeChooserTabPage::DeactivatePage()
     204             : {
     205           0 :     commitPage();
     206           0 :     svt::OWizardPage::DeactivatePage();
     207           0 : }
     208             : 
     209           0 : void RangeChooserTabPage::commitPage()
     210             : {
     211           0 :     commitPage(::svt::WizardTypes::eFinish);
     212           0 : }
     213             : 
     214           0 : bool RangeChooserTabPage::commitPage( ::svt::WizardTypes::CommitPageReason /*eReason*/ )
     215             : {
     216             :     //ranges may have been edited in the meanwhile (dirty is true in that case here)
     217           0 :     if( isValid() )
     218             :     {
     219           0 :         changeDialogModelAccordingToControls();
     220           0 :         return true; // return false if this page should not be left
     221             :     }
     222             :     else
     223           0 :         return false;
     224             : }
     225             : 
     226           0 : void RangeChooserTabPage::changeDialogModelAccordingToControls()
     227             : {
     228           0 :     if(m_nChangingControlCalls>0)
     229           0 :         return;
     230             : 
     231           0 :     if( !m_xCurrentChartTypeTemplate.is() )
     232             :     {
     233           0 :         if(m_pTemplateProvider)
     234           0 :             m_xCurrentChartTypeTemplate.set( m_pTemplateProvider->getCurrentTemplate());
     235           0 :         if( !m_xCurrentChartTypeTemplate.is())
     236             :         {
     237             :             OSL_FAIL( "Need a template to change data source" );
     238           0 :             return;
     239             :         }
     240             :     }
     241             : 
     242           0 :     if( m_bIsDirty )
     243             :     {
     244           0 :         bool bFirstCellAsLabel = ( m_pCB_FirstColumnAsLabel->IsChecked() && !m_pRB_Columns->IsChecked() )
     245           0 :             || ( m_pCB_FirstRowAsLabel->IsChecked()    && !m_pRB_Rows->IsChecked() );
     246           0 :         bool bHasCategories = ( m_pCB_FirstColumnAsLabel->IsChecked() && m_pRB_Columns->IsChecked() )
     247           0 :             || ( m_pCB_FirstRowAsLabel->IsChecked()    && m_pRB_Rows->IsChecked() );
     248           0 :         bool bTimeBased = m_pCB_TimeBased->IsChecked();
     249             : 
     250             :         Sequence< beans::PropertyValue > aArguments(
     251             :             DataSourceHelper::createArguments(
     252           0 :                 m_pRB_Columns->IsChecked(), bFirstCellAsLabel, bHasCategories ) );
     253             : 
     254           0 :         if(bTimeBased)
     255             :         {
     256           0 :             aArguments.realloc( aArguments.getLength() + 1 );
     257           0 :             aArguments[aArguments.getLength() - 1] =
     258             :                 beans::PropertyValue( "TimeBased", -1, uno::makeAny(bTimeBased),
     259           0 :                         beans::PropertyState_DIRECT_VALUE );
     260             :         }
     261             : 
     262             :         // only if range is valid
     263           0 :         if( m_aLastValidRangeString.equals(m_pED_Range->GetText()))
     264             :         {
     265           0 :             m_rDialogModel.setTemplate( m_xCurrentChartTypeTemplate );
     266           0 :             aArguments.realloc( aArguments.getLength() + 1 );
     267           0 :             aArguments[aArguments.getLength() - 1] =
     268             :                 beans::PropertyValue( "CellRangeRepresentation" , -1,
     269             :                                       uno::makeAny( m_aLastValidRangeString ),
     270           0 :                                       beans::PropertyState_DIRECT_VALUE );
     271           0 :             m_rDialogModel.setData( aArguments );
     272           0 :             m_bIsDirty = false;
     273             : 
     274           0 :             if(bTimeBased)
     275             :             {
     276           0 :                 sal_Int32 nStart = m_pEd_TimeStart->GetText().toInt32();
     277           0 :                 sal_Int32 nEnd = m_pEd_TimeEnd->GetText().toInt32();
     278           0 :                 m_rDialogModel.setTimeBasedRange(true, nStart, nEnd);
     279             :             }
     280           0 :         }
     281             : 
     282             :         //@todo warn user that the selected range is not valid
     283             :         //@todo better: disable OK-Button if range is invalid
     284             :     }
     285             : }
     286             : 
     287           0 : bool RangeChooserTabPage::isValid()
     288             : {
     289           0 :     OUString aRange( m_pED_Range->GetText());
     290           0 :     bool bFirstCellAsLabel = ( m_pCB_FirstColumnAsLabel->IsChecked() && !m_pRB_Columns->IsChecked() )
     291           0 :         || ( m_pCB_FirstRowAsLabel->IsChecked()    && !m_pRB_Rows->IsChecked() );
     292           0 :     bool bHasCategories = ( m_pCB_FirstColumnAsLabel->IsChecked() && m_pRB_Columns->IsChecked() )
     293           0 :         || ( m_pCB_FirstRowAsLabel->IsChecked()    && m_pRB_Rows->IsChecked() );
     294           0 :     bool bIsValid = ( aRange.isEmpty() ) ||
     295             :         m_rDialogModel.getRangeSelectionHelper()->verifyArguments(
     296             :             DataSourceHelper::createArguments(
     297           0 :                 aRange, Sequence< sal_Int32 >(), m_pRB_Columns->IsChecked(), bFirstCellAsLabel, bHasCategories ));
     298             : 
     299           0 :     if( bIsValid )
     300             :     {
     301           0 :         m_pED_Range->SetControlForeground();
     302           0 :         m_pED_Range->SetControlBackground();
     303           0 :         if( m_pTabPageNotifiable )
     304           0 :             m_pTabPageNotifiable->setValidPage( this );
     305           0 :         m_aLastValidRangeString = aRange;
     306             :     }
     307             :     else
     308             :     {
     309           0 :         m_pED_Range->SetControlBackground( RANGE_SELECTION_INVALID_RANGE_BACKGROUND_COLOR );
     310           0 :         m_pED_Range->SetControlForeground( RANGE_SELECTION_INVALID_RANGE_FOREGROUND_COLOR );
     311           0 :         if( m_pTabPageNotifiable )
     312           0 :             m_pTabPageNotifiable->setInvalidPage( this );
     313             :     }
     314             : 
     315             :     // enable/disable controls
     316             :     // #i79531# if the range is valid but an action of one of these buttons
     317             :     // would render it invalid, the button should be disabled
     318           0 :     if( bIsValid )
     319             :     {
     320           0 :         bool bDataInColumns = m_pRB_Columns->IsChecked();
     321             :         bool bIsSwappedRangeValid = m_rDialogModel.getRangeSelectionHelper()->verifyArguments(
     322             :             DataSourceHelper::createArguments(
     323           0 :                 aRange, Sequence< sal_Int32 >(), ! bDataInColumns, bHasCategories, bFirstCellAsLabel ));
     324           0 :         m_pRB_Rows->Enable( bIsSwappedRangeValid );
     325           0 :         m_pRB_Columns->Enable( bIsSwappedRangeValid );
     326             : 
     327           0 :         m_pCB_FirstRowAsLabel->Enable(
     328             :             m_rDialogModel.getRangeSelectionHelper()->verifyArguments(
     329             :                 DataSourceHelper::createArguments(
     330           0 :                     aRange, Sequence< sal_Int32 >(), m_pRB_Columns->IsChecked(),
     331           0 :                     bDataInColumns ? ! bFirstCellAsLabel : bFirstCellAsLabel,
     332           0 :                     bDataInColumns ? bHasCategories : ! bHasCategories )));
     333           0 :         m_pCB_FirstColumnAsLabel->Enable(
     334             :             m_rDialogModel.getRangeSelectionHelper()->verifyArguments(
     335             :                 DataSourceHelper::createArguments(
     336           0 :                     aRange, Sequence< sal_Int32 >(), m_pRB_Columns->IsChecked(),
     337           0 :                     bDataInColumns ? bFirstCellAsLabel : ! bFirstCellAsLabel,
     338           0 :                     bDataInColumns ? ! bHasCategories : bHasCategories )));
     339             :     }
     340             :     else
     341             :     {
     342           0 :         m_pRB_Rows->Enable( bIsValid );
     343           0 :         m_pRB_Columns->Enable( bIsValid );
     344           0 :         m_pCB_FirstRowAsLabel->Enable( bIsValid );
     345           0 :         m_pCB_FirstColumnAsLabel->Enable( bIsValid );
     346             :     }
     347             : 
     348           0 :     bool bShowIB = m_rDialogModel.getRangeSelectionHelper()->hasRangeSelection();
     349           0 :     lcl_ShowChooserButton( *m_pIB_Range, bShowIB );
     350             : 
     351           0 :     return bIsValid;
     352             : }
     353             : 
     354           0 : IMPL_LINK_NOARG(RangeChooserTabPage, ControlEditedHdl)
     355             : {
     356           0 :     setDirty();
     357           0 :     isValid();
     358           0 :     return 0;
     359             : }
     360             : 
     361           0 : IMPL_LINK_NOARG(RangeChooserTabPage, ControlChangedHdl)
     362             : {
     363           0 :     setDirty();
     364           0 :     if( isValid())
     365           0 :         changeDialogModelAccordingToControls();
     366           0 :     return 0;
     367             : }
     368             : 
     369           0 : IMPL_LINK_NOARG(RangeChooserTabPage, ChooseRangeHdl)
     370             : {
     371           0 :     OUString aRange = m_pED_Range->GetText();
     372             :     // using assignment for broken gcc 3.3
     373           0 :     OUString aTitle = m_pFTTitle->GetText();
     374             : 
     375           0 :     lcl_enableRangeChoosing( true, m_pParentDialog );
     376           0 :     m_rDialogModel.getRangeSelectionHelper()->chooseRange( aRange, aTitle, *this );
     377             : 
     378           0 :     return 0;
     379             : }
     380             : 
     381           0 : void RangeChooserTabPage::listeningFinished( const OUString & rNewRange )
     382             : {
     383             :     //user has selected a new range
     384             : 
     385           0 :     OUString aRange( rNewRange );
     386             : 
     387           0 :     m_rDialogModel.startControllerLockTimer();
     388             : 
     389             :     // stop listening
     390           0 :     m_rDialogModel.getRangeSelectionHelper()->stopRangeListening();
     391             : 
     392             :     //update dialog state
     393           0 :     ToTop();
     394           0 :     GrabFocus();
     395           0 :     m_pED_Range->SetText( aRange );
     396           0 :     m_pED_Range->GrabFocus();
     397             : 
     398           0 :     setDirty();
     399           0 :     if( isValid())
     400           0 :         changeDialogModelAccordingToControls();
     401             : 
     402           0 :     lcl_enableRangeChoosing( false, m_pParentDialog );
     403           0 : }
     404           0 : void RangeChooserTabPage::disposingRangeSelection()
     405             : {
     406           0 :     m_rDialogModel.getRangeSelectionHelper()->stopRangeListening( false );
     407           0 : }
     408             : 
     409           0 : void RangeChooserTabPage::setDirty()
     410             : {
     411           0 :     if( m_nChangingControlCalls == 0 )
     412           0 :         m_bIsDirty = true;
     413           0 : }
     414             : 
     415          57 : } //namespace chart
     416             : 
     417             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11