1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
*/
#include <sfx2/dispatch.hxx>
#include <svl/zforlist.hxx>
#include <svl/undo.hxx>
#include "formulacell.hxx"
#include "rangelst.hxx"
#include "scitems.hxx"
#include "docsh.hxx"
#include "document.hxx"
#include "uiitems.hxx"
#include "reffact.hxx"
#include "scresid.hxx"
#include "docfunc.hxx"
#include "strload.hxx"
#include "StatisticsInputOutputDialog.hxx"
ScRangeList ScStatisticsInputOutputDialog::MakeColumnRangeList(SCTAB aTab, ScAddress aStart, ScAddress aEnd)
{
ScRangeList aRangeList;
for (SCCOL inCol = aStart.Col(); inCol <= aEnd.Col(); inCol++)
{
ScRange aColumnRange (
ScAddress(inCol, aStart.Row(), aTab),
ScAddress(inCol, aEnd.Row(), aTab) );
aRangeList.Append(aColumnRange);
}
return aRangeList;
}
ScRangeList ScStatisticsInputOutputDialog::MakeRowRangeList(SCTAB aTab, ScAddress aStart, ScAddress aEnd)
{
ScRangeList aRangeList;
for (SCROW inRow = aStart.Row(); inRow <= aEnd.Row(); inRow++)
{
ScRange aRowRange (
ScAddress(aStart.Col(), inRow, aTab),
ScAddress(aEnd.Col(), inRow, aTab) );
aRangeList.Append(aRowRange);
}
return aRangeList;
}
ScStatisticsInputOutputDialog::ScStatisticsInputOutputDialog(
SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
vcl::Window* pParent, ScViewData* pViewData, const OUString& rID, const OUString& rUIXMLDescription ) :
ScAnyRefDlg ( pSfxBindings, pChildWindow, pParent, rID, rUIXMLDescription ),
mViewData ( pViewData ),
mDocument ( pViewData->GetDocument() ),
mInputRange ( ScAddress::INITIALIZE_INVALID ),
mAddressDetails ( mDocument->GetAddressConvention(), 0, 0 ),
mOutputAddress ( ScAddress::INITIALIZE_INVALID ),
mGroupedBy ( BY_COLUMN ),
mpActiveEdit ( NULL ),
mCurrentAddress ( pViewData->GetCurX(), pViewData->GetCurY(), pViewData->GetTabNo() ),
mDialogLostFocus( false )
{
get(mpInputRangeLabel, "input-range-label");
get(mpInputRangeEdit, "input-range-edit");
get(mpInputRangeButton, "input-range-button");
mpInputRangeEdit->SetReferences(this, mpInputRangeLabel);
mpInputRangeButton->SetReferences(this, mpInputRangeEdit);
get(mpOutputRangeLabel, "output-range-label");
get(mpOutputRangeEdit, "output-range-edit");
get(mpOutputRangeButton, "output-range-button");
mpOutputRangeEdit->SetReferences(this, mpOutputRangeLabel);
mpOutputRangeButton->SetReferences(this, mpOutputRangeEdit);
get(mpButtonOk, "ok");
get(mpGroupByColumnsRadio, "groupedby-columns-radio");
get(mpGroupByRowsRadio, "groupedby-rows-radio");
Init();
GetRangeFromSelection();
}
ScStatisticsInputOutputDialog::~ScStatisticsInputOutputDialog()
{
disposeOnce();
}
void ScStatisticsInputOutputDialog::dispose()
{
mpInputRangeLabel.clear();
mpInputRangeEdit.clear();
mpInputRangeButton.clear();
mpOutputRangeLabel.clear();
mpOutputRangeEdit.clear();
mpOutputRangeButton.clear();
mpGroupByColumnsRadio.clear();
mpGroupByRowsRadio.clear();
mpButtonOk.clear();
mpActiveEdit.clear();
ScAnyRefDlg::dispose();
}
void ScStatisticsInputOutputDialog::Init()
{
mpButtonOk->SetClickHdl( LINK( this, ScStatisticsInputOutputDialog, OkClicked ) );
mpButtonOk->Enable(false);
Link<> aLink = LINK( this, ScStatisticsInputOutputDialog, GetFocusHandler );
mpInputRangeEdit->SetGetFocusHdl( aLink );
mpInputRangeButton->SetGetFocusHdl( aLink );
mpOutputRangeEdit->SetGetFocusHdl( aLink );
mpOutputRangeButton->SetGetFocusHdl( aLink );
aLink = LINK( this, ScStatisticsInputOutputDialog, LoseFocusHandler );
mpInputRangeEdit->SetLoseFocusHdl( aLink );
mpInputRangeButton->SetLoseFocusHdl( aLink );
mpOutputRangeEdit->SetLoseFocusHdl( aLink );
mpOutputRangeButton->SetLoseFocusHdl( aLink );
aLink = LINK( this, ScStatisticsInputOutputDialog, RefInputModifyHandler);
mpInputRangeEdit->SetModifyHdl( aLink);
mpOutputRangeEdit->SetModifyHdl( aLink);
mpOutputRangeEdit->GrabFocus();
mpGroupByColumnsRadio->SetToggleHdl( LINK( this, ScStatisticsInputOutputDialog, GroupByChanged ) );
mpGroupByRowsRadio->SetToggleHdl( LINK( this, ScStatisticsInputOutputDialog, GroupByChanged ) );
mpGroupByColumnsRadio->Check();
mpGroupByRowsRadio->Check(false);
}
void ScStatisticsInputOutputDialog::GetRangeFromSelection()
{
mViewData->GetSimpleArea(mInputRange);
OUString aCurrentString(mInputRange.Format(SCR_ABS_3D, mDocument, mAddressDetails));
mpInputRangeEdit->SetText(aCurrentString);
}
void ScStatisticsInputOutputDialog::SetActive()
{
if ( mDialogLostFocus )
{
mDialogLostFocus = false;
if( mpActiveEdit )
mpActiveEdit->GrabFocus();
}
else
{
GrabFocus();
}
RefInputDone();
}
void ScStatisticsInputOutputDialog::SetReference( const ScRange& rReferenceRange, ScDocument* pDocument )
{
if ( mpActiveEdit )
{
if ( rReferenceRange.aStart != rReferenceRange.aEnd )
RefInputStart( mpActiveEdit );
OUString aReferenceString;
if ( mpActiveEdit == mpInputRangeEdit )
{
mInputRange = rReferenceRange;
aReferenceString = mInputRange.Format(SCR_ABS_3D, pDocument, mAddressDetails);
mpInputRangeEdit->SetRefString( aReferenceString );
}
else if ( mpActiveEdit == mpOutputRangeEdit )
{
mOutputAddress = rReferenceRange.aStart;
sal_uInt16 nFormat = ( mOutputAddress.Tab() == mCurrentAddress.Tab() ) ? SCA_ABS : SCA_ABS_3D;
aReferenceString = mOutputAddress.Format(nFormat, pDocument, pDocument->GetAddressConvention());
mpOutputRangeEdit->SetRefString( aReferenceString );
}
}
// Enable OK if both, input range and output address are set.
if (mInputRange.IsValid() && mOutputAddress.IsValid())
mpButtonOk->Enable();
else
mpButtonOk->Disable();
}
IMPL_LINK_NOARG_TYPED( ScStatisticsInputOutputDialog, OkClicked, Button*, void )
{
CalculateInputAndWriteToOutput();
Close();
}
IMPL_LINK( ScStatisticsInputOutputDialog, GetFocusHandler, Control*, pCtrl )
{
mpActiveEdit = NULL;
if( (pCtrl == static_cast<Control*>(mpInputRangeEdit)) || (pCtrl == static_cast<Control*>(mpInputRangeButton)) )
mpActiveEdit = mpInputRangeEdit;
else if( (pCtrl == static_cast<Control*>(mpOutputRangeEdit)) || (pCtrl == static_cast<Control*>(mpOutputRangeButton)) )
mpActiveEdit = mpOutputRangeEdit;
if( mpActiveEdit )
mpActiveEdit->SetSelection( Selection( 0, SELECTION_MAX ) );
return 0;
}
IMPL_LINK_NOARG( ScStatisticsInputOutputDialog, LoseFocusHandler )
{
mDialogLostFocus = !IsActive();
return 0;
}
IMPL_LINK_NOARG( ScStatisticsInputOutputDialog, GroupByChanged )
{
if (mpGroupByColumnsRadio->IsChecked())
mGroupedBy = BY_COLUMN;
else if (mpGroupByRowsRadio->IsChecked())
mGroupedBy = BY_ROW;
return 0;
}
IMPL_LINK_NOARG( ScStatisticsInputOutputDialog, RefInputModifyHandler )
{
if ( mpActiveEdit )
{
if ( mpActiveEdit == mpInputRangeEdit )
{
ScRangeList aRangeList;
bool bValid = ParseWithNames( aRangeList, mpInputRangeEdit->GetText(), mDocument);
const ScRange* pRange = (bValid && aRangeList.size() == 1) ? aRangeList[0] : nullptr;
if (pRange)
{
mInputRange = *pRange;
// Highlight the resulting range.
mpInputRangeEdit->StartUpdateData();
}
else
{
mInputRange = ScRange( ScAddress::INITIALIZE_INVALID);
}
}
else if ( mpActiveEdit == mpOutputRangeEdit )
{
ScRangeList aRangeList;
bool bValid = ParseWithNames( aRangeList, mpOutputRangeEdit->GetText(), mDocument);
const ScRange* pRange = (bValid && aRangeList.size() == 1) ? aRangeList[0] : nullptr;
if (pRange)
{
mOutputAddress = pRange->aStart;
// Crop output range to top left address for Edit field.
if (pRange->aStart != pRange->aEnd)
{
sal_uInt16 nFormat = ( mOutputAddress.Tab() == mCurrentAddress.Tab() ) ? SCA_ABS : SCA_ABS_3D;
OUString aReferenceString = mOutputAddress.Format(nFormat, mDocument, mDocument->GetAddressConvention());
mpOutputRangeEdit->SetRefString( aReferenceString );
}
// Highlight the resulting range.
mpOutputRangeEdit->StartUpdateData();
}
else
{
mOutputAddress = ScAddress( ScAddress::INITIALIZE_INVALID);
}
}
}
// Enable OK if both, input range and output address are set.
if (mInputRange.IsValid() && mOutputAddress.IsValid())
mpButtonOk->Enable();
else
mpButtonOk->Disable();
return 0;
}
void ScStatisticsInputOutputDialog::CalculateInputAndWriteToOutput()
{
OUString aUndo(SC_STRLOAD(RID_STATISTICS_DLGS, GetUndoNameId()));
ScDocShell* pDocShell = mViewData->GetDocShell();
svl::IUndoManager* pUndoManager = pDocShell->GetUndoManager();
pUndoManager->EnterListAction( aUndo, aUndo );
ScRange aOutputRange = ApplyOutput(pDocShell);
pUndoManager->LeaveListAction();
pDocShell->PostPaint( aOutputRange, PAINT_GRID );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|