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

Generated by: LCOV version 1.11