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

Generated by: LCOV version 1.10