LCOV - code coverage report
Current view: top level - sc/source/ui/StatisticsDialogs - StatisticsTwoVariableDialog.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 133 0.8 %
Date: 2014-11-03 Functions: 2 18 11.1 %
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 OString& 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           0 : {}
      69             : 
      70           0 : void ScStatisticsTwoVariableDialog::Init()
      71             : {
      72           0 :     mpButtonOk->SetClickHdl( LINK( this, ScStatisticsTwoVariableDialog, OkClicked ) );
      73           0 :     mpButtonOk->Enable(false);
      74             : 
      75           0 :     Link aLink = LINK( this, ScStatisticsTwoVariableDialog, GetFocusHandler );
      76           0 :     mpVariable1RangeEdit->SetGetFocusHdl( aLink );
      77           0 :     mpVariable1RangeButton->SetGetFocusHdl( aLink );
      78           0 :     mpVariable2RangeEdit->SetGetFocusHdl( aLink );
      79           0 :     mpVariable2RangeButton->SetGetFocusHdl( aLink );
      80           0 :     mpOutputRangeEdit->SetGetFocusHdl( aLink );
      81           0 :     mpOutputRangeButton->SetGetFocusHdl( aLink );
      82             : 
      83           0 :     aLink = LINK( this, ScStatisticsTwoVariableDialog, LoseFocusHandler );
      84           0 :     mpVariable1RangeEdit->SetLoseFocusHdl( aLink );
      85           0 :     mpVariable1RangeButton->SetLoseFocusHdl( aLink );
      86           0 :     mpVariable2RangeEdit->SetLoseFocusHdl( aLink );
      87           0 :     mpVariable2RangeButton->SetLoseFocusHdl( aLink );
      88           0 :     mpOutputRangeEdit->SetLoseFocusHdl( aLink );
      89           0 :     mpOutputRangeButton->SetLoseFocusHdl( aLink );
      90             : 
      91           0 :     mpOutputRangeEdit->GrabFocus();
      92             : 
      93           0 :     mpGroupByColumnsRadio->SetToggleHdl( LINK( this, ScStatisticsTwoVariableDialog, GroupByChanged ) );
      94           0 :     mpGroupByRowsRadio->SetToggleHdl( LINK( this, ScStatisticsTwoVariableDialog, GroupByChanged ) );
      95             : 
      96           0 :     mpGroupByColumnsRadio->Check(true);
      97           0 :     mpGroupByRowsRadio->Check(false);
      98           0 : }
      99             : 
     100           0 : void ScStatisticsTwoVariableDialog::GetRangeFromSelection()
     101             : {
     102           0 :     OUString aCurrentString;
     103             : 
     104           0 :     ScRange aCurrentRange;
     105           0 :     mViewData->GetSimpleArea(aCurrentRange);
     106             : 
     107           0 :     if (aCurrentRange.aEnd.Col() - aCurrentRange.aStart.Col() == 1)
     108             :     {
     109           0 :         mVariable1Range = aCurrentRange;
     110           0 :         mVariable1Range.aEnd.SetCol(mVariable1Range.aStart.Col());
     111           0 :         aCurrentString = mVariable1Range.Format(SCR_ABS_3D, mDocument, mAddressDetails);
     112           0 :         mpVariable1RangeEdit->SetText(aCurrentString);
     113             : 
     114           0 :         mVariable2Range = aCurrentRange;
     115           0 :         mVariable2Range.aStart.SetCol(mVariable2Range.aEnd.Col());
     116           0 :         aCurrentString = mVariable2Range.Format(SCR_ABS_3D, mDocument, mAddressDetails);
     117           0 :         mpVariable2RangeEdit->SetText(aCurrentString);
     118             :     }
     119             :     else
     120             :     {
     121           0 :         mVariable1Range = aCurrentRange;
     122           0 :         aCurrentString = mVariable1Range.Format(SCR_ABS_3D, mDocument, mAddressDetails);
     123           0 :         mpVariable1RangeEdit->SetText(aCurrentString);
     124           0 :     }
     125           0 : }
     126             : 
     127           0 : void ScStatisticsTwoVariableDialog::SetActive()
     128             : {
     129           0 :     if ( mDialogLostFocus )
     130             :     {
     131           0 :         mDialogLostFocus = false;
     132           0 :         if( mpActiveEdit )
     133           0 :             mpActiveEdit->GrabFocus();
     134             :     }
     135             :     else
     136             :     {
     137           0 :         GrabFocus();
     138             :     }
     139           0 :     RefInputDone();
     140           0 : }
     141             : 
     142           0 : void ScStatisticsTwoVariableDialog::SetReference( const ScRange& rReferenceRange, ScDocument* pDocument )
     143             : {
     144           0 :     if ( mpActiveEdit != NULL )
     145             :     {
     146           0 :         if ( rReferenceRange.aStart != rReferenceRange.aEnd )
     147           0 :             RefInputStart( mpActiveEdit );
     148             : 
     149           0 :         OUString aReferenceString;
     150             : 
     151           0 :         if ( mpActiveEdit == mpVariable1RangeEdit )
     152             :         {
     153           0 :             mVariable1Range = rReferenceRange;
     154           0 :             aReferenceString = mVariable1Range.Format(SCR_ABS_3D, pDocument, mAddressDetails);
     155           0 :             mpVariable1RangeEdit->SetRefString(aReferenceString);
     156             :         }
     157           0 :         else if ( mpActiveEdit == mpVariable2RangeEdit )
     158             :         {
     159           0 :             mVariable2Range = rReferenceRange;
     160           0 :             aReferenceString = mVariable2Range.Format(SCR_ABS_3D, pDocument, mAddressDetails);
     161           0 :             mpVariable2RangeEdit->SetRefString(aReferenceString);
     162             :         }
     163           0 :         else if ( mpActiveEdit == mpOutputRangeEdit )
     164             :         {
     165           0 :             mOutputAddress = rReferenceRange.aStart;
     166             : 
     167           0 :             sal_uInt16 nFormat = ( mOutputAddress.Tab() == mCurrentAddress.Tab() ) ? SCA_ABS : SCA_ABS_3D;
     168           0 :             aReferenceString = mOutputAddress.Format(nFormat, pDocument, pDocument->GetAddressConvention());
     169           0 :             mpOutputRangeEdit->SetRefString( aReferenceString );
     170             : 
     171             :             // Enable OK, Cancel if output range is set
     172           0 :             mpButtonOk->Enable(!mpOutputRangeEdit->GetText().isEmpty());
     173           0 :         }
     174             :     }
     175           0 : }
     176             : 
     177           0 : IMPL_LINK( ScStatisticsTwoVariableDialog, OkClicked, PushButton*, /*pButton*/ )
     178             : {
     179           0 :     CalculateInputAndWriteToOutput();
     180           0 :     Close();
     181           0 :     return 0;
     182             : }
     183             : 
     184           0 : IMPL_LINK( ScStatisticsTwoVariableDialog, GetFocusHandler, Control*, pCtrl )
     185             : {
     186           0 :     mpActiveEdit = NULL;
     187           0 :     if(      pCtrl == mpVariable1RangeEdit
     188           0 :           || pCtrl == mpVariable1RangeButton )
     189             :     {
     190           0 :         mpActiveEdit = mpVariable1RangeEdit;
     191             :     }
     192           0 :     else if( pCtrl == mpVariable2RangeEdit
     193           0 :           || pCtrl == mpVariable2RangeButton )
     194             :     {
     195           0 :         mpActiveEdit = mpVariable2RangeEdit;
     196             :     }
     197           0 :     else if( pCtrl == mpOutputRangeEdit
     198           0 :           || pCtrl == mpOutputRangeButton )
     199             :     {
     200           0 :         mpActiveEdit = mpOutputRangeEdit;
     201             :     }
     202             : 
     203           0 :     if( mpActiveEdit )
     204           0 :         mpActiveEdit->SetSelection( Selection( 0, SELECTION_MAX ) );
     205             : 
     206           0 :     return 0;
     207             : }
     208             : 
     209           0 : IMPL_LINK_NOARG( ScStatisticsTwoVariableDialog, LoseFocusHandler )
     210             : {
     211           0 :     mDialogLostFocus = !IsActive();
     212           0 :     return 0;
     213             : }
     214             : 
     215           0 : IMPL_LINK_NOARG( ScStatisticsTwoVariableDialog, GroupByChanged )
     216             : {
     217           0 :     if (mpGroupByColumnsRadio->IsChecked())
     218           0 :         mGroupedBy = BY_COLUMN;
     219           0 :     else if (mpGroupByRowsRadio->IsChecked())
     220           0 :         mGroupedBy = BY_ROW;
     221             : 
     222           0 :     return 0;
     223             : }
     224             : 
     225           0 : void ScStatisticsTwoVariableDialog::CalculateInputAndWriteToOutput()
     226             : {
     227           0 :     OUString aUndo(SC_STRLOAD(RID_STATISTICS_DLGS, GetUndoNameId()));
     228           0 :     ScDocShell* pDocShell = mViewData->GetDocShell();
     229           0 :     svl::IUndoManager* pUndoManager = pDocShell->GetUndoManager();
     230           0 :     pUndoManager->EnterListAction( aUndo, aUndo );
     231             : 
     232           0 :     ScRange aOutputRange = ApplyOutput(pDocShell);
     233             : 
     234           0 :     pUndoManager->LeaveListAction();
     235           0 :     pDocShell->PostPaint( aOutputRange, PAINT_GRID );
     236         228 : }
     237             : 
     238             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10