LCOV - code coverage report
Current view: top level - sc/source/ui/StatisticsDialogs - StatisticsTwoVariableDialog.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 150 0.7 %
Date: 2015-06-13 12:38:46 Functions: 2 19 10.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             :  */
      10             : 
      11             : #include <sfx2/dispatch.hxx>
      12             : #include <svl/zforlist.hxx>
      13             : #include <svl/undo.hxx>
      14             : 
      15             : #include "formulacell.hxx"
      16             : #include "rangelst.hxx"
      17             : #include "scitems.hxx"
      18             : #include "docsh.hxx"
      19             : #include "document.hxx"
      20             : #include "uiitems.hxx"
      21             : #include "reffact.hxx"
      22             : #include "scresid.hxx"
      23             : #include "docfunc.hxx"
      24             : #include "strload.hxx"
      25             : 
      26             : #include "StatisticsTwoVariableDialog.hxx"
      27             : 
      28           0 : ScStatisticsTwoVariableDialog::ScStatisticsTwoVariableDialog(
      29             :                     SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
      30             :                     vcl::Window* pParent, ScViewData* pViewData, const OUString& rID, const OUString& rUIXMLDescription ) :
      31             :     ScAnyRefDlg     ( pSfxBindings, pChildWindow, pParent, rID, rUIXMLDescription ),
      32             :     mViewData       ( pViewData ),
      33           0 :     mDocument       ( pViewData->GetDocument() ),
      34             :     mAddressDetails ( mDocument->GetAddressConvention(), 0, 0 ),
      35             :     mGroupedBy      ( BY_COLUMN ),
      36             :     mpActiveEdit    ( NULL ),
      37           0 :     mCurrentAddress ( pViewData->GetCurX(), pViewData->GetCurY(), pViewData->GetTabNo() ),
      38           0 :     mDialogLostFocus( false )
      39             : {
      40           0 :     get(mpVariable1RangeLabel,  "variable1-range-label");
      41           0 :     get(mpVariable1RangeEdit,   "variable1-range-edit");
      42           0 :     get(mpVariable1RangeButton, "variable1-range-button");
      43           0 :     mpVariable1RangeEdit->SetReferences(this, mpVariable1RangeLabel);
      44           0 :     mpVariable1RangeButton->SetReferences(this, mpVariable1RangeEdit);
      45             : 
      46           0 :     get(mpVariable2RangeLabel,  "variable2-range-label");
      47           0 :     get(mpVariable2RangeEdit,   "variable2-range-edit");
      48           0 :     get(mpVariable2RangeButton, "variable2-range-button");
      49           0 :     mpVariable2RangeEdit->SetReferences(this, mpVariable2RangeLabel);
      50           0 :     mpVariable2RangeButton->SetReferences(this, mpVariable2RangeEdit);
      51             : 
      52           0 :     get(mpOutputRangeLabel,  "output-range-label");
      53           0 :     get(mpOutputRangeEdit,   "output-range-edit");
      54           0 :     get(mpOutputRangeButton, "output-range-button");
      55           0 :     mpOutputRangeEdit->SetReferences(this, mpOutputRangeLabel);
      56           0 :     mpOutputRangeButton->SetReferences(this, mpOutputRangeEdit);
      57             : 
      58           0 :     get(mpButtonOk,     "ok");
      59             : 
      60           0 :     get(mpGroupByColumnsRadio,   "groupedby-columns-radio");
      61           0 :     get(mpGroupByRowsRadio,      "groupedby-rows-radio");
      62             : 
      63           0 :     Init();
      64           0 :     GetRangeFromSelection();
      65           0 : }
      66             : 
      67           0 : ScStatisticsTwoVariableDialog::~ScStatisticsTwoVariableDialog()
      68             : {
      69           0 :     disposeOnce();
      70           0 : }
      71             : 
      72           0 : void ScStatisticsTwoVariableDialog::dispose()
      73             : {
      74           0 :     mpVariable1RangeLabel.clear();
      75           0 :     mpVariable1RangeEdit.clear();
      76           0 :     mpVariable1RangeButton.clear();
      77           0 :     mpVariable2RangeLabel.clear();
      78           0 :     mpVariable2RangeEdit.clear();
      79           0 :     mpVariable2RangeButton.clear();
      80           0 :     mpOutputRangeLabel.clear();
      81           0 :     mpOutputRangeEdit.clear();
      82           0 :     mpOutputRangeButton.clear();
      83           0 :     mpButtonOk.clear();
      84           0 :     mpGroupByColumnsRadio.clear();
      85           0 :     mpGroupByRowsRadio.clear();
      86           0 :     mpActiveEdit.clear();
      87           0 :     ScAnyRefDlg::dispose();
      88           0 : }
      89             : 
      90           0 : void ScStatisticsTwoVariableDialog::Init()
      91             : {
      92           0 :     mpButtonOk->SetClickHdl( LINK( this, ScStatisticsTwoVariableDialog, OkClicked ) );
      93           0 :     mpButtonOk->Enable(false);
      94             : 
      95           0 :     Link<> aLink = LINK( this, ScStatisticsTwoVariableDialog, GetFocusHandler );
      96           0 :     mpVariable1RangeEdit->SetGetFocusHdl( aLink );
      97           0 :     mpVariable1RangeButton->SetGetFocusHdl( aLink );
      98           0 :     mpVariable2RangeEdit->SetGetFocusHdl( aLink );
      99           0 :     mpVariable2RangeButton->SetGetFocusHdl( aLink );
     100           0 :     mpOutputRangeEdit->SetGetFocusHdl( aLink );
     101           0 :     mpOutputRangeButton->SetGetFocusHdl( aLink );
     102             : 
     103           0 :     aLink = LINK( this, ScStatisticsTwoVariableDialog, LoseFocusHandler );
     104           0 :     mpVariable1RangeEdit->SetLoseFocusHdl( aLink );
     105           0 :     mpVariable1RangeButton->SetLoseFocusHdl( aLink );
     106           0 :     mpVariable2RangeEdit->SetLoseFocusHdl( aLink );
     107           0 :     mpVariable2RangeButton->SetLoseFocusHdl( aLink );
     108           0 :     mpOutputRangeEdit->SetLoseFocusHdl( aLink );
     109           0 :     mpOutputRangeButton->SetLoseFocusHdl( aLink );
     110             : 
     111           0 :     mpOutputRangeEdit->GrabFocus();
     112             : 
     113           0 :     mpGroupByColumnsRadio->SetToggleHdl( LINK( this, ScStatisticsTwoVariableDialog, GroupByChanged ) );
     114           0 :     mpGroupByRowsRadio->SetToggleHdl( LINK( this, ScStatisticsTwoVariableDialog, GroupByChanged ) );
     115             : 
     116           0 :     mpGroupByColumnsRadio->Check(true);
     117           0 :     mpGroupByRowsRadio->Check(false);
     118           0 : }
     119             : 
     120           0 : void ScStatisticsTwoVariableDialog::GetRangeFromSelection()
     121             : {
     122           0 :     OUString aCurrentString;
     123             : 
     124           0 :     ScRange aCurrentRange;
     125           0 :     mViewData->GetSimpleArea(aCurrentRange);
     126             : 
     127           0 :     if (aCurrentRange.aEnd.Col() - aCurrentRange.aStart.Col() == 1)
     128             :     {
     129           0 :         mVariable1Range = aCurrentRange;
     130           0 :         mVariable1Range.aEnd.SetCol(mVariable1Range.aStart.Col());
     131           0 :         aCurrentString = mVariable1Range.Format(SCR_ABS_3D, mDocument, mAddressDetails);
     132           0 :         mpVariable1RangeEdit->SetText(aCurrentString);
     133             : 
     134           0 :         mVariable2Range = aCurrentRange;
     135           0 :         mVariable2Range.aStart.SetCol(mVariable2Range.aEnd.Col());
     136           0 :         aCurrentString = mVariable2Range.Format(SCR_ABS_3D, mDocument, mAddressDetails);
     137           0 :         mpVariable2RangeEdit->SetText(aCurrentString);
     138             :     }
     139             :     else
     140             :     {
     141           0 :         mVariable1Range = aCurrentRange;
     142           0 :         aCurrentString = mVariable1Range.Format(SCR_ABS_3D, mDocument, mAddressDetails);
     143           0 :         mpVariable1RangeEdit->SetText(aCurrentString);
     144           0 :     }
     145           0 : }
     146             : 
     147           0 : void ScStatisticsTwoVariableDialog::SetActive()
     148             : {
     149           0 :     if ( mDialogLostFocus )
     150             :     {
     151           0 :         mDialogLostFocus = false;
     152           0 :         if( mpActiveEdit )
     153           0 :             mpActiveEdit->GrabFocus();
     154             :     }
     155             :     else
     156             :     {
     157           0 :         GrabFocus();
     158             :     }
     159           0 :     RefInputDone();
     160           0 : }
     161             : 
     162           0 : void ScStatisticsTwoVariableDialog::SetReference( const ScRange& rReferenceRange, ScDocument* pDocument )
     163             : {
     164           0 :     if ( mpActiveEdit != nullptr )
     165             :     {
     166           0 :         if ( rReferenceRange.aStart != rReferenceRange.aEnd )
     167           0 :             RefInputStart( mpActiveEdit );
     168             : 
     169           0 :         OUString aReferenceString;
     170             : 
     171           0 :         if ( mpActiveEdit == mpVariable1RangeEdit )
     172             :         {
     173           0 :             mVariable1Range = rReferenceRange;
     174           0 :             aReferenceString = mVariable1Range.Format(SCR_ABS_3D, pDocument, mAddressDetails);
     175           0 :             mpVariable1RangeEdit->SetRefString(aReferenceString);
     176             :         }
     177           0 :         else if ( mpActiveEdit == mpVariable2RangeEdit )
     178             :         {
     179           0 :             mVariable2Range = rReferenceRange;
     180           0 :             aReferenceString = mVariable2Range.Format(SCR_ABS_3D, pDocument, mAddressDetails);
     181           0 :             mpVariable2RangeEdit->SetRefString(aReferenceString);
     182             :         }
     183           0 :         else if ( mpActiveEdit == mpOutputRangeEdit )
     184             :         {
     185           0 :             mOutputAddress = rReferenceRange.aStart;
     186             : 
     187           0 :             sal_uInt16 nFormat = ( mOutputAddress.Tab() == mCurrentAddress.Tab() ) ? SCA_ABS : SCA_ABS_3D;
     188           0 :             aReferenceString = mOutputAddress.Format(nFormat, pDocument, pDocument->GetAddressConvention());
     189           0 :             mpOutputRangeEdit->SetRefString( aReferenceString );
     190             : 
     191             :             // Enable OK, Cancel if output range is set
     192           0 :             mpButtonOk->Enable(!mpOutputRangeEdit->GetText().isEmpty());
     193           0 :         }
     194             :     }
     195           0 : }
     196             : 
     197           0 : IMPL_LINK( ScStatisticsTwoVariableDialog, OkClicked, PushButton*, /*pButton*/ )
     198             : {
     199           0 :     CalculateInputAndWriteToOutput();
     200           0 :     Close();
     201           0 :     return 0;
     202             : }
     203             : 
     204           0 : IMPL_LINK( ScStatisticsTwoVariableDialog, GetFocusHandler, Control*, pCtrl )
     205             : {
     206           0 :     mpActiveEdit = NULL;
     207           0 :     if(      pCtrl == mpVariable1RangeEdit
     208           0 :           || pCtrl == mpVariable1RangeButton )
     209             :     {
     210           0 :         mpActiveEdit = mpVariable1RangeEdit;
     211             :     }
     212           0 :     else if( pCtrl == mpVariable2RangeEdit
     213           0 :           || pCtrl == mpVariable2RangeButton )
     214             :     {
     215           0 :         mpActiveEdit = mpVariable2RangeEdit;
     216             :     }
     217           0 :     else if( pCtrl == mpOutputRangeEdit
     218           0 :           || pCtrl == mpOutputRangeButton )
     219             :     {
     220           0 :         mpActiveEdit = mpOutputRangeEdit;
     221             :     }
     222             : 
     223           0 :     if( mpActiveEdit )
     224           0 :         mpActiveEdit->SetSelection( Selection( 0, SELECTION_MAX ) );
     225             : 
     226           0 :     return 0;
     227             : }
     228             : 
     229           0 : IMPL_LINK_NOARG( ScStatisticsTwoVariableDialog, LoseFocusHandler )
     230             : {
     231           0 :     mDialogLostFocus = !IsActive();
     232           0 :     return 0;
     233             : }
     234             : 
     235           0 : IMPL_LINK_NOARG( ScStatisticsTwoVariableDialog, GroupByChanged )
     236             : {
     237           0 :     if (mpGroupByColumnsRadio->IsChecked())
     238           0 :         mGroupedBy = BY_COLUMN;
     239           0 :     else if (mpGroupByRowsRadio->IsChecked())
     240           0 :         mGroupedBy = BY_ROW;
     241             : 
     242           0 :     return 0;
     243             : }
     244             : 
     245           0 : void ScStatisticsTwoVariableDialog::CalculateInputAndWriteToOutput()
     246             : {
     247           0 :     OUString aUndo(SC_STRLOAD(RID_STATISTICS_DLGS, GetUndoNameId()));
     248           0 :     ScDocShell* pDocShell = mViewData->GetDocShell();
     249           0 :     svl::IUndoManager* pUndoManager = pDocShell->GetUndoManager();
     250           0 :     pUndoManager->EnterListAction( aUndo, aUndo );
     251             : 
     252           0 :     ScRange aOutputRange = ApplyOutput(pDocShell);
     253             : 
     254           0 :     pUndoManager->LeaveListAction();
     255           0 :     pDocShell->PostPaint( aOutputRange, PAINT_GRID );
     256         156 : }
     257             : 
     258             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11