fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / StatisticsDialogs / StatisticsInputOutputDialog.cxx
blob377a0e579ae8645b5d71e078f9e0aa9a79150530
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 */
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"
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"
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);
39 return aRangeList;
42 ScRangeList ScStatisticsInputOutputDialog::MakeRowRangeList(SCTAB aTab, ScAddress aStart, ScAddress aEnd)
44 ScRangeList aRangeList;
45 for (SCROW inRow = aStart.Row(); inRow <= aEnd.Row(); inRow++)
47 ScRange aRowRange (
48 ScAddress(aStart.Col(), inRow, aTab),
49 ScAddress(aEnd.Col(), inRow, aTab) );
51 aRangeList.Append(aRowRange);
53 return aRangeList;
56 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 mDocument ( pViewData->GetDocument() ),
62 mInputRange ( ScAddress::INITIALIZE_INVALID ),
63 mAddressDetails ( mDocument->GetAddressConvention(), 0, 0 ),
64 mOutputAddress ( ScAddress::INITIALIZE_INVALID ),
65 mGroupedBy ( BY_COLUMN ),
66 mpActiveEdit ( NULL ),
67 mCurrentAddress ( pViewData->GetCurX(), pViewData->GetCurY(), pViewData->GetTabNo() ),
68 mDialogLostFocus( false )
70 get(mpInputRangeLabel, "input-range-label");
71 get(mpInputRangeEdit, "input-range-edit");
72 get(mpInputRangeButton, "input-range-button");
73 mpInputRangeEdit->SetReferences(this, mpInputRangeLabel);
74 mpInputRangeButton->SetReferences(this, mpInputRangeEdit);
76 get(mpOutputRangeLabel, "output-range-label");
77 get(mpOutputRangeEdit, "output-range-edit");
78 get(mpOutputRangeButton, "output-range-button");
79 mpOutputRangeEdit->SetReferences(this, mpOutputRangeLabel);
80 mpOutputRangeButton->SetReferences(this, mpOutputRangeEdit);
82 get(mpButtonOk, "ok");
84 get(mpGroupByColumnsRadio, "groupedby-columns-radio");
85 get(mpGroupByRowsRadio, "groupedby-rows-radio");
87 Init();
88 GetRangeFromSelection();
91 ScStatisticsInputOutputDialog::~ScStatisticsInputOutputDialog()
93 disposeOnce();
96 void ScStatisticsInputOutputDialog::dispose()
98 mpInputRangeLabel.clear();
99 mpInputRangeEdit.clear();
100 mpInputRangeButton.clear();
101 mpOutputRangeLabel.clear();
102 mpOutputRangeEdit.clear();
103 mpOutputRangeButton.clear();
104 mpGroupByColumnsRadio.clear();
105 mpGroupByRowsRadio.clear();
106 mpButtonOk.clear();
107 mpActiveEdit.clear();
108 ScAnyRefDlg::dispose();
111 void ScStatisticsInputOutputDialog::Init()
113 mpButtonOk->SetClickHdl( LINK( this, ScStatisticsInputOutputDialog, OkClicked ) );
114 mpButtonOk->Enable(false);
116 Link<> aLink = LINK( this, ScStatisticsInputOutputDialog, GetFocusHandler );
117 mpInputRangeEdit->SetGetFocusHdl( aLink );
118 mpInputRangeButton->SetGetFocusHdl( aLink );
119 mpOutputRangeEdit->SetGetFocusHdl( aLink );
120 mpOutputRangeButton->SetGetFocusHdl( aLink );
122 aLink = LINK( this, ScStatisticsInputOutputDialog, LoseFocusHandler );
123 mpInputRangeEdit->SetLoseFocusHdl( aLink );
124 mpInputRangeButton->SetLoseFocusHdl( aLink );
125 mpOutputRangeEdit->SetLoseFocusHdl( aLink );
126 mpOutputRangeButton->SetLoseFocusHdl( aLink );
128 aLink = LINK( this, ScStatisticsInputOutputDialog, RefInputModifyHandler);
129 mpInputRangeEdit->SetModifyHdl( aLink);
130 mpOutputRangeEdit->SetModifyHdl( aLink);
132 mpOutputRangeEdit->GrabFocus();
134 mpGroupByColumnsRadio->SetToggleHdl( LINK( this, ScStatisticsInputOutputDialog, GroupByChanged ) );
135 mpGroupByRowsRadio->SetToggleHdl( LINK( this, ScStatisticsInputOutputDialog, GroupByChanged ) );
137 mpGroupByColumnsRadio->Check(true);
138 mpGroupByRowsRadio->Check(false);
141 void ScStatisticsInputOutputDialog::GetRangeFromSelection()
143 mViewData->GetSimpleArea(mInputRange);
144 OUString aCurrentString(mInputRange.Format(SCR_ABS_3D, mDocument, mAddressDetails));
145 mpInputRangeEdit->SetText(aCurrentString);
148 void ScStatisticsInputOutputDialog::SetActive()
150 if ( mDialogLostFocus )
152 mDialogLostFocus = false;
153 if( mpActiveEdit )
154 mpActiveEdit->GrabFocus();
156 else
158 GrabFocus();
160 RefInputDone();
163 void ScStatisticsInputOutputDialog::SetReference( const ScRange& rReferenceRange, ScDocument* pDocument )
165 if ( mpActiveEdit )
167 if ( rReferenceRange.aStart != rReferenceRange.aEnd )
168 RefInputStart( mpActiveEdit );
170 OUString aReferenceString;
172 if ( mpActiveEdit == mpInputRangeEdit )
174 mInputRange = rReferenceRange;
175 aReferenceString = mInputRange.Format(SCR_ABS_3D, pDocument, mAddressDetails);
176 mpInputRangeEdit->SetRefString( aReferenceString );
178 else if ( mpActiveEdit == mpOutputRangeEdit )
180 mOutputAddress = rReferenceRange.aStart;
182 sal_uInt16 nFormat = ( mOutputAddress.Tab() == mCurrentAddress.Tab() ) ? SCA_ABS : SCA_ABS_3D;
183 aReferenceString = mOutputAddress.Format(nFormat, pDocument, pDocument->GetAddressConvention());
184 mpOutputRangeEdit->SetRefString( aReferenceString );
188 // Enable OK if both, input range and output address are set.
189 if (mInputRange.IsValid() && mOutputAddress.IsValid())
190 mpButtonOk->Enable();
191 else
192 mpButtonOk->Disable();
195 IMPL_LINK( ScStatisticsInputOutputDialog, OkClicked, PushButton*, /*pButton*/ )
197 CalculateInputAndWriteToOutput();
198 Close();
199 return 0;
202 IMPL_LINK( ScStatisticsInputOutputDialog, GetFocusHandler, Control*, pCtrl )
204 mpActiveEdit = NULL;
206 if( (pCtrl == (Control*) mpInputRangeEdit) || (pCtrl == (Control*) mpInputRangeButton) )
207 mpActiveEdit = mpInputRangeEdit;
208 else if( (pCtrl == (Control*) mpOutputRangeEdit) || (pCtrl == (Control*) mpOutputRangeButton) )
209 mpActiveEdit = mpOutputRangeEdit;
211 if( mpActiveEdit )
212 mpActiveEdit->SetSelection( Selection( 0, SELECTION_MAX ) );
214 return 0;
217 IMPL_LINK_NOARG( ScStatisticsInputOutputDialog, LoseFocusHandler )
219 mDialogLostFocus = !IsActive();
220 return 0;
223 IMPL_LINK_NOARG( ScStatisticsInputOutputDialog, GroupByChanged )
225 if (mpGroupByColumnsRadio->IsChecked())
226 mGroupedBy = BY_COLUMN;
227 else if (mpGroupByRowsRadio->IsChecked())
228 mGroupedBy = BY_ROW;
230 return 0;
233 IMPL_LINK_NOARG( ScStatisticsInputOutputDialog, RefInputModifyHandler )
235 if ( mpActiveEdit )
237 if ( mpActiveEdit == mpInputRangeEdit )
239 ScRangeList aRangeList;
240 bool bValid = ParseWithNames( aRangeList, mpInputRangeEdit->GetText(), mDocument);
241 const ScRange* pRange = (bValid && aRangeList.size() == 1) ? aRangeList[0] : nullptr;
242 if (pRange)
244 mInputRange = *pRange;
245 // Highlight the resulting range.
246 mpInputRangeEdit->StartUpdateData();
248 else
250 mInputRange = ScRange( ScAddress::INITIALIZE_INVALID);
253 else if ( mpActiveEdit == mpOutputRangeEdit )
255 ScRangeList aRangeList;
256 bool bValid = ParseWithNames( aRangeList, mpOutputRangeEdit->GetText(), mDocument);
257 const ScRange* pRange = (bValid && aRangeList.size() == 1) ? aRangeList[0] : nullptr;
258 if (pRange)
260 mOutputAddress = pRange->aStart;
262 // Crop output range to top left address for Edit field.
263 if (pRange->aStart != pRange->aEnd)
265 sal_uInt16 nFormat = ( mOutputAddress.Tab() == mCurrentAddress.Tab() ) ? SCA_ABS : SCA_ABS_3D;
266 OUString aReferenceString = mOutputAddress.Format(nFormat, mDocument, mDocument->GetAddressConvention());
267 mpOutputRangeEdit->SetRefString( aReferenceString );
270 // Highlight the resulting range.
271 mpOutputRangeEdit->StartUpdateData();
273 else
275 mOutputAddress = ScAddress( ScAddress::INITIALIZE_INVALID);
280 // Enable OK if both, input range and output address are set.
281 if (mInputRange.IsValid() && mOutputAddress.IsValid())
282 mpButtonOk->Enable();
283 else
284 mpButtonOk->Disable();
286 return 0;
289 void ScStatisticsInputOutputDialog::CalculateInputAndWriteToOutput()
291 OUString aUndo(SC_STRLOAD(RID_STATISTICS_DLGS, GetUndoNameId()));
292 ScDocShell* pDocShell = mViewData->GetDocShell();
293 svl::IUndoManager* pUndoManager = pDocShell->GetUndoManager();
294 pUndoManager->EnterListAction( aUndo, aUndo );
296 ScRange aOutputRange = ApplyOutput(pDocShell);
298 pUndoManager->LeaveListAction();
299 pDocShell->PostPaint( aOutputRange, PAINT_GRID );
302 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */