LCOV - code coverage report
Current view: top level - sc/source/ui/StatisticsDialogs - StatisticsInputOutputDialog.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 1 127 0.8 %
Date: 2014-04-11 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             :  */
      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 "StatisticsInputOutputDialog.hxx"
      28             : 
      29           0 : ScRangeList ScStatisticsInputOutputDialog::MakeColumnRangeList(SCTAB aTab, ScAddress aStart, ScAddress aEnd)
      30             : {
      31           0 :     ScRangeList aRangeList;
      32           0 :     for (SCCOL inCol = aStart.Col(); inCol <= aEnd.Col(); inCol++)
      33             :     {
      34             :         ScRange aColumnRange (
      35             :             ScAddress(inCol, aStart.Row(), aTab),
      36           0 :             ScAddress(inCol, aEnd.Row(),   aTab) );
      37             : 
      38           0 :         aRangeList.Append(aColumnRange);
      39             :     }
      40           0 :     return aRangeList;
      41             : }
      42             : 
      43           0 : ScRangeList ScStatisticsInputOutputDialog::MakeRowRangeList(SCTAB aTab, ScAddress aStart, ScAddress aEnd)
      44             : {
      45           0 :     ScRangeList aRangeList;
      46           0 :     for (SCROW inRow = aStart.Row(); inRow <= aEnd.Row(); inRow++)
      47             :     {
      48             :         ScRange aRowRange (
      49           0 :             ScAddress(aStart.Col(), inRow, aTab),
      50           0 :             ScAddress(aEnd.Col(),   inRow, aTab) );
      51             : 
      52           0 :         aRangeList.Append(aRowRange);
      53             :     }
      54           0 :     return aRangeList;
      55             : }
      56             : 
      57           0 : ScStatisticsInputOutputDialog::ScStatisticsInputOutputDialog(
      58             :                     SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
      59             :                     Window* pParent, ScViewData* pViewData, const OString& rID, const OUString& rUIXMLDescription ) :
      60             :     ScAnyRefDlg     ( pSfxBindings, pChildWindow, pParent, rID, rUIXMLDescription ),
      61             :     mViewData       ( pViewData ),
      62           0 :     mDocument       ( pViewData->GetDocument() ),
      63             :     mAddressDetails ( mDocument->GetAddressConvention(), 0, 0 ),
      64             :     mGroupedBy      ( BY_COLUMN ),
      65           0 :     mCurrentAddress ( pViewData->GetCurX(), pViewData->GetCurY(), pViewData->GetTabNo() ),
      66           0 :     mDialogLostFocus( false )
      67             : {
      68           0 :     get(mpInputRangeLabel,  "input-range-label");
      69           0 :     get(mpInputRangeEdit,   "input-range-edit");
      70           0 :     get(mpInputRangeButton, "input-range-button");
      71           0 :     mpInputRangeEdit->SetReferences(this, mpInputRangeLabel);
      72           0 :     mpInputRangeButton->SetReferences(this, mpInputRangeEdit);
      73             : 
      74           0 :     get(mpOutputRangeLabel,  "output-range-label");
      75           0 :     get(mpOutputRangeEdit,   "output-range-edit");
      76           0 :     get(mpOutputRangeButton, "output-range-button");
      77           0 :     mpOutputRangeEdit->SetReferences(this, mpOutputRangeLabel);
      78           0 :     mpOutputRangeButton->SetReferences(this, mpOutputRangeEdit);
      79             : 
      80           0 :     get(mpButtonOk,     "ok");
      81           0 :     get(mpButtonApply,  "apply");
      82           0 :     get(mpButtonClose,  "close");
      83             : 
      84           0 :     get(mpGroupByColumnsRadio,   "groupedby-columns-radio");
      85           0 :     get(mpGroupByRowsRadio,      "groupedby-rows-radio");
      86             : 
      87           0 :     Init();
      88           0 :     GetRangeFromSelection();
      89           0 : }
      90             : 
      91           0 : ScStatisticsInputOutputDialog::~ScStatisticsInputOutputDialog()
      92           0 : {}
      93             : 
      94           0 : void ScStatisticsInputOutputDialog::Init()
      95             : {
      96           0 :     mpButtonOk->SetClickHdl( LINK( this, ScStatisticsInputOutputDialog, OkClicked ) );
      97           0 :     mpButtonClose->SetClickHdl( LINK( this, ScStatisticsInputOutputDialog, CloseClicked ) );
      98           0 :     mpButtonApply->SetClickHdl( LINK( this, ScStatisticsInputOutputDialog, ApplyClicked ) );
      99           0 :     mpButtonOk->Enable(false);
     100           0 :     mpButtonApply->Enable(false);
     101             : 
     102           0 :     Link aLink = LINK( this, ScStatisticsInputOutputDialog, GetFocusHandler );
     103           0 :     mpInputRangeEdit->SetGetFocusHdl( aLink );
     104           0 :     mpInputRangeButton->SetGetFocusHdl( aLink );
     105           0 :     mpOutputRangeEdit->SetGetFocusHdl( aLink );
     106           0 :     mpOutputRangeButton->SetGetFocusHdl( aLink );
     107             : 
     108           0 :     aLink = LINK( this, ScStatisticsInputOutputDialog, LoseFocusHandler );
     109           0 :     mpInputRangeEdit->SetLoseFocusHdl( aLink );
     110           0 :     mpInputRangeButton->SetLoseFocusHdl( aLink );
     111           0 :     mpOutputRangeEdit->SetLoseFocusHdl( aLink );
     112           0 :     mpOutputRangeButton->SetLoseFocusHdl( aLink );
     113             : 
     114           0 :     mpOutputRangeEdit->GrabFocus();
     115             : 
     116           0 :     mpGroupByColumnsRadio->SetToggleHdl( LINK( this, ScStatisticsInputOutputDialog, GroupByChanged ) );
     117           0 :     mpGroupByRowsRadio->SetToggleHdl( LINK( this, ScStatisticsInputOutputDialog, GroupByChanged ) );
     118             : 
     119           0 :     mpGroupByColumnsRadio->Check(true);
     120           0 :     mpGroupByRowsRadio->Check(false);
     121           0 : }
     122             : 
     123           0 : void ScStatisticsInputOutputDialog::GetRangeFromSelection()
     124             : {
     125           0 :     mViewData->GetSimpleArea(mInputRange);
     126           0 :     OUString aCurrentString(mInputRange.Format(SCR_ABS_3D, mDocument, mAddressDetails));
     127           0 :     mpInputRangeEdit->SetText(aCurrentString);
     128           0 : }
     129             : 
     130           0 : void ScStatisticsInputOutputDialog::SetActive()
     131             : {
     132           0 :     if ( mDialogLostFocus )
     133             :     {
     134           0 :         mDialogLostFocus = false;
     135           0 :         if( mpActiveEdit )
     136           0 :             mpActiveEdit->GrabFocus();
     137             :     }
     138             :     else
     139             :     {
     140           0 :         GrabFocus();
     141             :     }
     142           0 :     RefInputDone();
     143           0 : }
     144             : 
     145           0 : void ScStatisticsInputOutputDialog::SetReference( const ScRange& rReferenceRange, ScDocument* pDocument )
     146             : {
     147           0 :     if ( mpActiveEdit )
     148             :     {
     149           0 :         if ( rReferenceRange.aStart != rReferenceRange.aEnd )
     150           0 :             RefInputStart( mpActiveEdit );
     151             : 
     152           0 :         OUString aReferenceString;
     153             : 
     154           0 :         if ( mpActiveEdit == mpInputRangeEdit )
     155             :         {
     156           0 :             mInputRange = rReferenceRange;
     157           0 :             aReferenceString = mInputRange.Format(SCR_ABS_3D, pDocument, mAddressDetails);
     158           0 :             mpInputRangeEdit->SetRefString( aReferenceString );
     159             :         }
     160           0 :         else if ( mpActiveEdit == mpOutputRangeEdit )
     161             :         {
     162           0 :             mOutputAddress = rReferenceRange.aStart;
     163             : 
     164           0 :             sal_uInt16 nFormat = ( mOutputAddress.Tab() == mCurrentAddress.Tab() ) ? SCA_ABS : SCA_ABS_3D;
     165           0 :             aReferenceString = mOutputAddress.Format(nFormat, pDocument, pDocument->GetAddressConvention());
     166           0 :             mpOutputRangeEdit->SetRefString( aReferenceString );
     167             : 
     168             :             // Enable OK, Cancel if output range is set
     169           0 :             mpButtonOk->Enable(!mpOutputRangeEdit->GetText().isEmpty());
     170           0 :             mpButtonApply->Enable(!mpOutputRangeEdit->GetText().isEmpty());
     171           0 :         }
     172             :     }
     173           0 : }
     174             : 
     175           0 : IMPL_LINK( ScStatisticsInputOutputDialog, OkClicked, PushButton*, /*pButton*/ )
     176             : {
     177           0 :     ApplyClicked(NULL);
     178           0 :     CloseClicked(NULL);
     179           0 :     return 0;
     180             : }
     181             : 
     182             : 
     183           0 : IMPL_LINK( ScStatisticsInputOutputDialog, ApplyClicked, PushButton*, /*pButton*/ )
     184             : {
     185           0 :     CalculateInputAndWriteToOutput();
     186           0 :     return 0;
     187             : }
     188             : 
     189           0 : IMPL_LINK( ScStatisticsInputOutputDialog, CloseClicked, PushButton*, /*pButton*/ )
     190             : {
     191           0 :     Close();
     192           0 :     return 0;
     193             : }
     194             : 
     195           0 : IMPL_LINK( ScStatisticsInputOutputDialog, GetFocusHandler, Control*, pCtrl )
     196             : {
     197           0 :     mpActiveEdit = NULL;
     198             : 
     199           0 :     if(      (pCtrl == (Control*) mpInputRangeEdit)  || (pCtrl == (Control*) mpInputRangeButton) )
     200           0 :         mpActiveEdit = mpInputRangeEdit;
     201           0 :     else if( (pCtrl == (Control*) mpOutputRangeEdit) || (pCtrl == (Control*) mpOutputRangeButton) )
     202           0 :         mpActiveEdit = mpOutputRangeEdit;
     203             : 
     204           0 :     if( mpActiveEdit )
     205           0 :         mpActiveEdit->SetSelection( Selection( 0, SELECTION_MAX ) );
     206             : 
     207           0 :     return 0;
     208             : }
     209             : 
     210           0 : IMPL_LINK_NOARG( ScStatisticsInputOutputDialog, LoseFocusHandler )
     211             : {
     212           0 :     mDialogLostFocus = !IsActive();
     213           0 :     return 0;
     214             : }
     215             : 
     216           0 : IMPL_LINK_NOARG( ScStatisticsInputOutputDialog, GroupByChanged )
     217             : {
     218           0 :     if (mpGroupByColumnsRadio->IsChecked())
     219           0 :         mGroupedBy = BY_COLUMN;
     220           0 :     else if (mpGroupByRowsRadio->IsChecked())
     221           0 :         mGroupedBy = BY_ROW;
     222             : 
     223           0 :     return 0;
     224             : }
     225             : 
     226           0 : void ScStatisticsInputOutputDialog::CalculateInputAndWriteToOutput()
     227             : {
     228           0 :     OUString aUndo(SC_STRLOAD(RID_STATISTICS_DLGS, GetUndoNameId()));
     229           0 :     ScDocShell* pDocShell = mViewData->GetDocShell();
     230           0 :     svl::IUndoManager* pUndoManager = pDocShell->GetUndoManager();
     231           0 :     pUndoManager->EnterListAction( aUndo, aUndo );
     232             : 
     233           0 :     ScRange aOutputRange = ApplyOutput(pDocShell);
     234             : 
     235           0 :     pUndoManager->LeaveListAction();
     236           0 :     pDocShell->PostPaint( aOutputRange, PAINT_GRID );
     237         102 : }
     238             : 
     239             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10