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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
|
/* -*- 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/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifdef SC_DLLIMPLEMENTATION
#undef SC_DLLIMPLEMENTATION
#endif
#include <dpgroupdlg.hxx>
#include <globstr.hrc>
#include <scresid.hxx>
#include <editfield.hxx>
#include <com/sun/star/sheet/DataPilotFieldGroupBy.hpp>
#include <svtools/ctrlbox.hxx>
namespace {
/** Date part flags in order of the list box entries. */
static const sal_Int32 spnDateParts[] =
{
css::sheet::DataPilotFieldGroupBy::SECONDS,
css::sheet::DataPilotFieldGroupBy::MINUTES,
css::sheet::DataPilotFieldGroupBy::HOURS,
css::sheet::DataPilotFieldGroupBy::DAYS,
css::sheet::DataPilotFieldGroupBy::MONTHS,
css::sheet::DataPilotFieldGroupBy::QUARTERS,
css::sheet::DataPilotFieldGroupBy::YEARS
};
static const char* aDatePartResIds[] =
{
STR_DPFIELD_GROUP_BY_SECONDS,
STR_DPFIELD_GROUP_BY_MINUTES,
STR_DPFIELD_GROUP_BY_HOURS,
STR_DPFIELD_GROUP_BY_DAYS,
STR_DPFIELD_GROUP_BY_MONTHS,
STR_DPFIELD_GROUP_BY_QUARTERS,
STR_DPFIELD_GROUP_BY_YEARS
};
} // namespace
ScDPGroupEditHelper::ScDPGroupEditHelper(weld::RadioButton& rRbAuto, weld::RadioButton& rRbMan, weld::Widget& rEdValue)
: mrRbAuto(rRbAuto)
, mrRbMan(rRbMan)
, mrEdValue(rEdValue)
{
mrRbAuto.connect_clicked( LINK( this, ScDPGroupEditHelper, ClickHdl ) );
mrRbMan.connect_clicked( LINK( this, ScDPGroupEditHelper, ClickHdl ) );
}
bool ScDPGroupEditHelper::IsAuto() const
{
return mrRbAuto.get_active();
}
double ScDPGroupEditHelper::GetValue() const
{
double fValue;
if( !ImplGetValue( fValue ) )
fValue = 0.0;
return fValue;
}
void ScDPGroupEditHelper::SetValue( bool bAuto, double fValue )
{
if( bAuto )
{
mrRbAuto.set_active(true);
ClickHdl(mrRbAuto);
}
else
{
mrRbMan.set_active(true);
ClickHdl(mrRbMan);
}
ImplSetValue( fValue );
}
IMPL_LINK(ScDPGroupEditHelper, ClickHdl, weld::Button&, rButton, void)
{
if (&rButton == &mrRbAuto)
{
// disable edit field on clicking "automatic" radio button
mrEdValue.set_sensitive(false);
}
else if (&rButton == &mrRbMan)
{
// enable and set focus to edit field on clicking "manual" radio button
mrEdValue.set_sensitive(true);
mrEdValue.grab_focus();
}
}
ScDPNumGroupEditHelper::ScDPNumGroupEditHelper(weld::RadioButton& rRbAuto,
weld::RadioButton& rRbMan, ScDoubleField& rEdValue)
: ScDPGroupEditHelper(rRbAuto, rRbMan, rEdValue.get_widget())
, mrEdValue(rEdValue)
{
}
bool ScDPNumGroupEditHelper::ImplGetValue( double& rfValue ) const
{
return mrEdValue.GetValue(rfValue);
}
void ScDPNumGroupEditHelper::ImplSetValue( double fValue )
{
mrEdValue.SetValue(fValue);
}
ScDPDateGroupEditHelper::ScDPDateGroupEditHelper(weld::RadioButton& rRbAuto, weld::RadioButton& rRbMan,
SvtCalendarBox& rEdValue, const Date& rNullDate)
: ScDPGroupEditHelper(rRbAuto, rRbMan, rEdValue.get_button())
, mrEdValue(rEdValue)
, maNullDate(rNullDate)
{
}
bool ScDPDateGroupEditHelper::ImplGetValue( double& rfValue ) const
{
rfValue = mrEdValue.get_date() - maNullDate;
return true;
}
void ScDPDateGroupEditHelper::ImplSetValue( double fValue )
{
Date aDate( maNullDate );
aDate.AddDays( fValue );
mrEdValue.set_date( aDate );
}
ScDPNumGroupDlg::ScDPNumGroupDlg(weld::Window* pParent, const ScDPNumGroupInfo& rInfo)
: GenericDialogController(pParent, "modules/scalc/ui/groupbynumber.ui", "PivotTableGroupByNumber")
, mxRbAutoStart(m_xBuilder->weld_radio_button("auto_start"))
, mxRbManStart(m_xBuilder->weld_radio_button("manual_start"))
, mxEdStart(new ScDoubleField(m_xBuilder->weld_entry("edit_start")))
, mxRbAutoEnd(m_xBuilder->weld_radio_button("auto_end"))
, mxRbManEnd(m_xBuilder->weld_radio_button("manual_end"))
, mxEdEnd(new ScDoubleField(m_xBuilder->weld_entry("edit_end")))
, mxEdBy(new ScDoubleField(m_xBuilder->weld_entry("edit_by")))
, maStartHelper(*mxRbAutoStart, *mxRbManStart, *mxEdStart)
, maEndHelper(*mxRbAutoEnd, *mxRbManEnd, *mxEdEnd)
{
maStartHelper.SetValue( rInfo.mbAutoStart, rInfo.mfStart );
maEndHelper.SetValue( rInfo.mbAutoEnd, rInfo.mfEnd );
mxEdBy->SetValue( (rInfo.mfStep <= 0.0) ? 1.0 : rInfo.mfStep );
/* Set the initial focus, currently it is somewhere after calling all the radio
button click handlers. Now the first enabled editable control is focused. */
if (mxEdStart->get_sensitive())
mxEdStart->grab_focus();
else if (mxEdEnd->get_sensitive())
mxEdEnd->grab_focus();
else
mxEdBy->grab_focus();
}
ScDPNumGroupDlg::~ScDPNumGroupDlg()
{
}
ScDPNumGroupInfo ScDPNumGroupDlg::GetGroupInfo() const
{
ScDPNumGroupInfo aInfo;
aInfo.mbEnable = true;
aInfo.mbDateValues = false;
aInfo.mbAutoStart = maStartHelper.IsAuto();
aInfo.mbAutoEnd = maEndHelper.IsAuto();
// get values and silently auto-correct them, if they are not valid
// TODO: error messages in OK event?
aInfo.mfStart = maStartHelper.GetValue();
aInfo.mfEnd = maEndHelper.GetValue();
if( !mxEdBy->GetValue( aInfo.mfStep ) || (aInfo.mfStep <= 0.0) )
aInfo.mfStep = 1.0;
if( aInfo.mfEnd <= aInfo.mfStart )
aInfo.mfEnd = aInfo.mfStart + aInfo.mfStep;
return aInfo;
}
ScDPDateGroupDlg::ScDPDateGroupDlg(weld::Window* pParent,
const ScDPNumGroupInfo& rInfo, sal_Int32 nDatePart, const Date& rNullDate)
: GenericDialogController(pParent, "modules/scalc/ui/groupbydate.ui", "PivotTableGroupByDate")
, mxRbAutoStart(m_xBuilder->weld_radio_button("auto_start"))
, mxRbManStart(m_xBuilder->weld_radio_button("manual_start"))
, mxEdStart(new SvtCalendarBox(m_xBuilder->weld_menu_button("start_date")))
, mxRbAutoEnd(m_xBuilder->weld_radio_button("auto_end"))
, mxRbManEnd(m_xBuilder->weld_radio_button("manual_end"))
, mxEdEnd(new SvtCalendarBox(m_xBuilder->weld_menu_button("end_date")))
, mxRbNumDays(m_xBuilder->weld_radio_button("days"))
, mxRbUnits(m_xBuilder->weld_radio_button("intervals"))
, mxEdNumDays(m_xBuilder->weld_spin_button("days_value"))
, mxLbUnits(m_xBuilder->weld_tree_view("interval_list"))
, mxBtnOk(m_xBuilder->weld_button("ok"))
, maStartHelper(*mxRbAutoStart, *mxRbManStart, *mxEdStart, rNullDate)
, maEndHelper(*mxRbAutoEnd, *mxRbManEnd, *mxEdEnd, rNullDate)
{
maStartHelper.SetValue( rInfo.mbAutoStart, rInfo.mfStart );
maEndHelper.SetValue( rInfo.mbAutoEnd, rInfo.mfEnd );
std::vector<int> aWidths;
aWidths.push_back(mxLbUnits->get_checkbox_column_width());
mxLbUnits->set_column_fixed_widths(aWidths);
if( nDatePart == 0 )
nDatePart = css::sheet::DataPilotFieldGroupBy::MONTHS;
for (size_t nIdx = 0; nIdx < SAL_N_ELEMENTS(aDatePartResIds); ++nIdx)
{
mxLbUnits->append();
mxLbUnits->set_toggle(nIdx, (nDatePart & spnDateParts[ nIdx ]) ? TRISTATE_TRUE : TRISTATE_FALSE, 0);
mxLbUnits->set_text(nIdx, ScResId(aDatePartResIds[nIdx]), 1);
}
if( rInfo.mbDateValues )
{
mxRbNumDays->set_active(true);
ClickHdl(*mxRbNumDays );
double fNumDays = rInfo.mfStep;
if( fNumDays < 1.0 )
fNumDays = 1.0;
else if( fNumDays > 32767.0 )
fNumDays = 32767.0;
mxEdNumDays->set_value(fNumDays);
}
else
{
mxRbUnits->set_active(true);
ClickHdl(*mxRbUnits);
}
/* Set the initial focus, currently it is somewhere after calling all the radio
button click handlers. Now the first enabled editable control is focused. */
if( mxEdStart->get_sensitive() )
mxEdStart->grab_focus();
else if( mxEdEnd->get_sensitive() )
mxEdEnd->grab_focus();
else if( mxEdNumDays->get_sensitive() )
mxEdNumDays->grab_focus();
else if( mxLbUnits->get_sensitive() )
mxLbUnits->grab_focus();
mxRbNumDays->connect_clicked( LINK( this, ScDPDateGroupDlg, ClickHdl ) );
mxRbUnits->connect_clicked( LINK( this, ScDPDateGroupDlg, ClickHdl ) );
mxLbUnits->connect_toggled( LINK( this, ScDPDateGroupDlg, CheckHdl ) );
}
ScDPDateGroupDlg::~ScDPDateGroupDlg()
{
}
ScDPNumGroupInfo ScDPDateGroupDlg::GetGroupInfo() const
{
ScDPNumGroupInfo aInfo;
aInfo.mbEnable = true;
aInfo.mbDateValues = mxRbNumDays->get_active();
aInfo.mbAutoStart = maStartHelper.IsAuto();
aInfo.mbAutoEnd = maEndHelper.IsAuto();
// get values and silently auto-correct them, if they are not valid
// TODO: error messages in OK event?
aInfo.mfStart = maStartHelper.GetValue();
aInfo.mfEnd = maEndHelper.GetValue();
sal_Int64 nNumDays = mxEdNumDays->get_value();
aInfo.mfStep = static_cast<double>( aInfo.mbDateValues ? nNumDays : 0L );
if( aInfo.mfEnd <= aInfo.mfStart )
aInfo.mfEnd = aInfo.mfStart + nNumDays;
return aInfo;
}
sal_Int32 ScDPDateGroupDlg::GetDatePart() const
{
// return DAYS for special "number of days" mode
if( mxRbNumDays->get_active() )
return css::sheet::DataPilotFieldGroupBy::DAYS;
// return listbox contents for "units" mode
sal_Int32 nDatePart = 0;
for (int nIdx = 0, nCount = mxLbUnits->n_children(); nIdx < nCount; ++nIdx )
if (mxLbUnits->get_toggle(nIdx, 0) == TRISTATE_TRUE)
nDatePart |= spnDateParts[ nIdx ];
return nDatePart;
}
IMPL_LINK(ScDPDateGroupDlg, ClickHdl, weld::Button&, rButton, void)
{
if (&rButton == mxRbNumDays.get())
{
mxLbUnits->set_sensitive(false);
// enable and set focus to edit field on clicking "num of days" radio button
mxEdNumDays->set_sensitive(true);
mxEdNumDays->grab_focus();
mxBtnOk->set_sensitive(true);
}
else if (&rButton == mxRbUnits.get())
{
mxEdNumDays->set_sensitive(false);
// enable and set focus to listbox on clicking "units" radio button
mxLbUnits->set_sensitive(true);
mxLbUnits->grab_focus();
// disable OK button if no date part selected
CheckHdl(row_col(0, 0));
}
}
namespace
{
bool HasCheckedEntryCount(const weld::TreeView& rView)
{
for (int i = 0; i < rView.n_children(); ++i)
{
if (rView.get_toggle(i, 0) == TRISTATE_TRUE)
return true;
}
return false;
}
}
IMPL_LINK_NOARG(ScDPDateGroupDlg, CheckHdl, const row_col&, void)
{
// enable/disable OK button on modifying check list box
mxBtnOk->set_sensitive(HasCheckedEntryCount(*mxLbUnits));
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|