1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
11 #include <sfx2/dispatch.hxx>
12 #include <svl/zforlist.hxx>
13 #include <svl/undo.hxx>
15 #include "formulacell.hxx"
16 #include "rangelst.hxx"
17 #include "scitems.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"
26 #include "StatisticsInputOutputDialog.hxx"
28 ScRangeList
ScStatisticsInputOutputDialog::MakeColumnRangeList(SCTAB aTab
, ScAddress aStart
, ScAddress aEnd
)
30 ScRangeList aRangeList
;
31 for (SCCOL inCol
= aStart
.Col(); inCol
<= aEnd
.Col(); inCol
++)
33 ScRange
aColumnRange (
34 ScAddress(inCol
, aStart
.Row(), aTab
),
35 ScAddress(inCol
, aEnd
.Row(), aTab
) );
37 aRangeList
.Append(aColumnRange
);
42 ScRangeList
ScStatisticsInputOutputDialog::MakeRowRangeList(SCTAB aTab
, ScAddress aStart
, ScAddress aEnd
)
44 ScRangeList aRangeList
;
45 for (SCROW inRow
= aStart
.Row(); inRow
<= aEnd
.Row(); inRow
++)
48 ScAddress(aStart
.Col(), inRow
, aTab
),
49 ScAddress(aEnd
.Col(), inRow
, aTab
) );
51 aRangeList
.Append(aRowRange
);
56 ScStatisticsInputOutputDialog::ScStatisticsInputOutputDialog(
57 SfxBindings
* pSfxBindings
, SfxChildWindow
* pChildWindow
,
58 Window
* pParent
, ScViewData
* pViewData
, const OString
& rID
, const OUString
& rUIXMLDescription
) :
59 ScAnyRefDlg ( pSfxBindings
, pChildWindow
, pParent
, rID
, rUIXMLDescription
),
60 mViewData ( pViewData
),
61 mDocument ( pViewData
->GetDocument() ),
62 mAddressDetails ( mDocument
->GetAddressConvention(), 0, 0 ),
63 mGroupedBy ( BY_COLUMN
),
64 mpActiveEdit ( NULL
),
65 mCurrentAddress ( pViewData
->GetCurX(), pViewData
->GetCurY(), pViewData
->GetTabNo() ),
66 mDialogLostFocus( false )
68 get(mpInputRangeLabel
, "input-range-label");
69 get(mpInputRangeEdit
, "input-range-edit");
70 get(mpInputRangeButton
, "input-range-button");
71 mpInputRangeEdit
->SetReferences(this, mpInputRangeLabel
);
72 mpInputRangeButton
->SetReferences(this, mpInputRangeEdit
);
74 get(mpOutputRangeLabel
, "output-range-label");
75 get(mpOutputRangeEdit
, "output-range-edit");
76 get(mpOutputRangeButton
, "output-range-button");
77 mpOutputRangeEdit
->SetReferences(this, mpOutputRangeLabel
);
78 mpOutputRangeButton
->SetReferences(this, mpOutputRangeEdit
);
80 get(mpButtonOk
, "ok");
82 get(mpGroupByColumnsRadio
, "groupedby-columns-radio");
83 get(mpGroupByRowsRadio
, "groupedby-rows-radio");
86 GetRangeFromSelection();
89 ScStatisticsInputOutputDialog::~ScStatisticsInputOutputDialog()
92 void ScStatisticsInputOutputDialog::Init()
94 mpButtonOk
->SetClickHdl( LINK( this, ScStatisticsInputOutputDialog
, OkClicked
) );
95 mpButtonOk
->Enable(false);
97 Link aLink
= LINK( this, ScStatisticsInputOutputDialog
, GetFocusHandler
);
98 mpInputRangeEdit
->SetGetFocusHdl( aLink
);
99 mpInputRangeButton
->SetGetFocusHdl( aLink
);
100 mpOutputRangeEdit
->SetGetFocusHdl( aLink
);
101 mpOutputRangeButton
->SetGetFocusHdl( aLink
);
103 aLink
= LINK( this, ScStatisticsInputOutputDialog
, LoseFocusHandler
);
104 mpInputRangeEdit
->SetLoseFocusHdl( aLink
);
105 mpInputRangeButton
->SetLoseFocusHdl( aLink
);
106 mpOutputRangeEdit
->SetLoseFocusHdl( aLink
);
107 mpOutputRangeButton
->SetLoseFocusHdl( aLink
);
109 mpOutputRangeEdit
->GrabFocus();
111 mpGroupByColumnsRadio
->SetToggleHdl( LINK( this, ScStatisticsInputOutputDialog
, GroupByChanged
) );
112 mpGroupByRowsRadio
->SetToggleHdl( LINK( this, ScStatisticsInputOutputDialog
, GroupByChanged
) );
114 mpGroupByColumnsRadio
->Check(true);
115 mpGroupByRowsRadio
->Check(false);
118 void ScStatisticsInputOutputDialog::GetRangeFromSelection()
120 mViewData
->GetSimpleArea(mInputRange
);
121 OUString
aCurrentString(mInputRange
.Format(SCR_ABS_3D
, mDocument
, mAddressDetails
));
122 mpInputRangeEdit
->SetText(aCurrentString
);
125 void ScStatisticsInputOutputDialog::SetActive()
127 if ( mDialogLostFocus
)
129 mDialogLostFocus
= false;
131 mpActiveEdit
->GrabFocus();
140 void ScStatisticsInputOutputDialog::SetReference( const ScRange
& rReferenceRange
, ScDocument
* pDocument
)
144 if ( rReferenceRange
.aStart
!= rReferenceRange
.aEnd
)
145 RefInputStart( mpActiveEdit
);
147 OUString aReferenceString
;
149 if ( mpActiveEdit
== mpInputRangeEdit
)
151 mInputRange
= rReferenceRange
;
152 aReferenceString
= mInputRange
.Format(SCR_ABS_3D
, pDocument
, mAddressDetails
);
153 mpInputRangeEdit
->SetRefString( aReferenceString
);
155 else if ( mpActiveEdit
== mpOutputRangeEdit
)
157 mOutputAddress
= rReferenceRange
.aStart
;
159 sal_uInt16 nFormat
= ( mOutputAddress
.Tab() == mCurrentAddress
.Tab() ) ? SCA_ABS
: SCA_ABS_3D
;
160 aReferenceString
= mOutputAddress
.Format(nFormat
, pDocument
, pDocument
->GetAddressConvention());
161 mpOutputRangeEdit
->SetRefString( aReferenceString
);
163 // Enable OK, Cancel if output range is set
164 mpButtonOk
->Enable(!mpOutputRangeEdit
->GetText().isEmpty());
169 IMPL_LINK( ScStatisticsInputOutputDialog
, OkClicked
, PushButton
*, /*pButton*/ )
171 CalculateInputAndWriteToOutput();
176 IMPL_LINK( ScStatisticsInputOutputDialog
, GetFocusHandler
, Control
*, pCtrl
)
180 if( (pCtrl
== (Control
*) mpInputRangeEdit
) || (pCtrl
== (Control
*) mpInputRangeButton
) )
181 mpActiveEdit
= mpInputRangeEdit
;
182 else if( (pCtrl
== (Control
*) mpOutputRangeEdit
) || (pCtrl
== (Control
*) mpOutputRangeButton
) )
183 mpActiveEdit
= mpOutputRangeEdit
;
186 mpActiveEdit
->SetSelection( Selection( 0, SELECTION_MAX
) );
191 IMPL_LINK_NOARG( ScStatisticsInputOutputDialog
, LoseFocusHandler
)
193 mDialogLostFocus
= !IsActive();
197 IMPL_LINK_NOARG( ScStatisticsInputOutputDialog
, GroupByChanged
)
199 if (mpGroupByColumnsRadio
->IsChecked())
200 mGroupedBy
= BY_COLUMN
;
201 else if (mpGroupByRowsRadio
->IsChecked())
207 void ScStatisticsInputOutputDialog::CalculateInputAndWriteToOutput()
209 OUString
aUndo(SC_STRLOAD(RID_STATISTICS_DLGS
, GetUndoNameId()));
210 ScDocShell
* pDocShell
= mViewData
->GetDocShell();
211 svl::IUndoManager
* pUndoManager
= pDocShell
->GetUndoManager();
212 pUndoManager
->EnterListAction( aUndo
, aUndo
);
214 ScRange aOutputRange
= ApplyOutput(pDocShell
);
216 pUndoManager
->LeaveListAction();
217 pDocShell
->PostPaint( aOutputRange
, PAINT_GRID
);
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */