fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / dbgui / dpgroupdlg.cxx
blob7bbb0fd809854d027e99e82560377460f9ee7619
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 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifdef SC_DLLIMPLEMENTATION
21 #undef SC_DLLIMPLEMENTATION
22 #endif
24 #include "dpgroupdlg.hxx"
25 #include "scresid.hxx"
26 #include "sc.hrc"
27 #include "globstr.hrc"
29 #include <com/sun/star/sheet/DataPilotFieldGroupBy.hpp>
31 namespace {
33 /** Date part flags in order of the list box entries. */
34 static const sal_Int32 spnDateParts[] =
36 com::sun::star::sheet::DataPilotFieldGroupBy::SECONDS,
37 com::sun::star::sheet::DataPilotFieldGroupBy::MINUTES,
38 com::sun::star::sheet::DataPilotFieldGroupBy::HOURS,
39 com::sun::star::sheet::DataPilotFieldGroupBy::DAYS,
40 com::sun::star::sheet::DataPilotFieldGroupBy::MONTHS,
41 com::sun::star::sheet::DataPilotFieldGroupBy::QUARTERS,
42 com::sun::star::sheet::DataPilotFieldGroupBy::YEARS
45 static const sal_uInt16 nDatePartResIds[] =
47 STR_DPFIELD_GROUP_BY_SECONDS,
48 STR_DPFIELD_GROUP_BY_MINUTES,
49 STR_DPFIELD_GROUP_BY_HOURS,
50 STR_DPFIELD_GROUP_BY_DAYS,
51 STR_DPFIELD_GROUP_BY_MONTHS,
52 STR_DPFIELD_GROUP_BY_QUARTERS,
53 STR_DPFIELD_GROUP_BY_YEARS
56 } // namespace
58 ScDPGroupEditHelper::ScDPGroupEditHelper( RadioButton* pRbAuto, RadioButton* pRbMan, Edit* pEdValue ) :
59 mpRbAuto( pRbAuto ),
60 mpRbMan( pRbMan ),
61 mpEdValue( pEdValue )
63 mpRbAuto->SetClickHdl( LINK( this, ScDPGroupEditHelper, ClickHdl ) );
64 mpRbMan->SetClickHdl( LINK( this, ScDPGroupEditHelper, ClickHdl ) );
67 bool ScDPGroupEditHelper::IsAuto() const
69 return mpRbAuto->IsChecked();
72 double ScDPGroupEditHelper::GetValue() const
74 double fValue;
75 if( !ImplGetValue( fValue ) )
76 fValue = 0.0;
77 return fValue;
80 void ScDPGroupEditHelper::SetValue( bool bAuto, double fValue )
82 if( bAuto )
84 mpRbAuto->Check();
85 ClickHdl( mpRbAuto );
87 else
89 mpRbMan->Check();
90 ClickHdl( mpRbMan );
92 ImplSetValue( fValue );
95 IMPL_LINK( ScDPGroupEditHelper, ClickHdl, RadioButton*, pButton )
97 if( pButton == mpRbAuto )
99 // disable edit field on clicking "automatic" radio button
100 mpEdValue->Disable();
102 else if( pButton == mpRbMan )
104 // enable and set focus to edit field on clicking "manual" radio button
105 mpEdValue->Enable();
106 mpEdValue->GrabFocus();
108 return 0;
111 ScDPNumGroupEditHelper::ScDPNumGroupEditHelper(
112 RadioButton* pRbAuto, RadioButton* pRbMan, ScDoubleField* pEdValue ) :
113 ScDPGroupEditHelper( pRbAuto, pRbMan, pEdValue ),
114 mpEdValue( pEdValue )
118 bool ScDPNumGroupEditHelper::ImplGetValue( double& rfValue ) const
120 return mpEdValue->GetValue( rfValue );
123 void ScDPNumGroupEditHelper::ImplSetValue( double fValue )
125 mpEdValue->SetValue( fValue );
128 ScDPDateGroupEditHelper::ScDPDateGroupEditHelper(
129 RadioButton* pRbAuto, RadioButton* pRbMan, DateField* pEdValue, const Date& rNullDate ) :
130 ScDPGroupEditHelper( pRbAuto, pRbMan, pEdValue ),
131 mpEdValue( pEdValue ),
132 maNullDate( rNullDate )
136 bool ScDPDateGroupEditHelper::ImplGetValue( double& rfValue ) const
138 rfValue = mpEdValue->GetDate() - maNullDate;
139 return true;
142 void ScDPDateGroupEditHelper::ImplSetValue( double fValue )
144 Date aDate( maNullDate );
145 aDate += static_cast< sal_Int32 >( fValue );
146 mpEdValue->SetDate( aDate );
149 ScDPNumGroupDlg::ScDPNumGroupDlg( vcl::Window* pParent, const ScDPNumGroupInfo& rInfo ) :
150 ModalDialog ( pParent, "PivotTableGroupByNumber", "modules/scalc/ui/groupbynumber.ui" ),
151 mpRbAutoStart ( get<RadioButton>("auto_start") ),
152 mpRbManStart ( get<RadioButton>("manual_start") ),
153 mpEdStart ( get<ScDoubleField> ("edit_start") ),
154 mpRbAutoEnd ( get<RadioButton> ( "auto_end" ) ),
155 mpRbManEnd ( get<RadioButton> ("manual_end") ),
156 mpEdEnd ( get<ScDoubleField>( "edit_end") ),
157 mpEdBy ( get<ScDoubleField> ("edit_by") ),
158 maStartHelper ( mpRbAutoStart, mpRbManStart, mpEdStart ),
159 maEndHelper ( mpRbAutoEnd, mpRbManEnd, mpEdEnd )
162 maStartHelper.SetValue( rInfo.mbAutoStart, rInfo.mfStart );
163 maEndHelper.SetValue( rInfo.mbAutoEnd, rInfo.mfEnd );
164 mpEdBy->SetValue( (rInfo.mfStep <= 0.0) ? 1.0 : rInfo.mfStep );
166 /* Set the initial focus, currently it is somewhere after calling all the radio
167 button click handlers. Now the first enabled editable control is focused. */
168 if( mpEdStart->IsEnabled() )
169 mpEdStart->GrabFocus();
170 else if( mpEdEnd->IsEnabled() )
171 mpEdEnd->GrabFocus();
172 else
173 mpEdBy->GrabFocus();
176 ScDPNumGroupDlg::~ScDPNumGroupDlg()
178 disposeOnce();
181 void ScDPNumGroupDlg::dispose()
183 mpRbAutoStart.clear();
184 mpRbManStart.clear();
185 mpEdStart.clear();
186 mpRbAutoEnd.clear();
187 mpRbManEnd.clear();
188 mpEdEnd.clear();
189 mpEdBy.clear();
190 ModalDialog::dispose();
194 ScDPNumGroupInfo ScDPNumGroupDlg::GetGroupInfo() const
196 ScDPNumGroupInfo aInfo;
197 aInfo.mbEnable = true;
198 aInfo.mbDateValues = false;
199 aInfo.mbAutoStart = maStartHelper.IsAuto();
200 aInfo.mbAutoEnd = maEndHelper.IsAuto();
202 // get values and silently auto-correct them, if they are not valid
203 // TODO: error messages in OK event?
204 aInfo.mfStart = maStartHelper.GetValue();
205 aInfo.mfEnd = maEndHelper.GetValue();
206 if( !mpEdBy->GetValue( aInfo.mfStep ) || (aInfo.mfStep <= 0.0) )
207 aInfo.mfStep = 1.0;
208 if( aInfo.mfEnd <= aInfo.mfStart )
209 aInfo.mfEnd = aInfo.mfStart + aInfo.mfStep;
211 return aInfo;
214 ScDPDateGroupDlg::ScDPDateGroupDlg( vcl::Window* pParent,
215 const ScDPNumGroupInfo& rInfo, sal_Int32 nDatePart, const Date& rNullDate ) :
216 ModalDialog( pParent, "PivotTableGroupByDate", "modules/scalc/ui/groupbydate.ui" ),
217 mpRbAutoStart ( get<RadioButton>("auto_start") ),
218 mpRbManStart ( get<RadioButton>("manual_start") ),
219 mpEdStart ( get<DateField>("start_date") ),
220 mpRbAutoEnd ( get<RadioButton>("auto_end") ),
221 mpRbManEnd ( get<RadioButton>("manual_end") ),
222 mpEdEnd ( get<DateField>("end_date") ),
223 mpRbNumDays ( get<RadioButton>("days") ),
224 mpRbUnits ( get<RadioButton>("intervals") ),
225 mpEdNumDays ( get<NumericField>("days_value") ),
226 mpLbUnits ( get<SvxCheckListBox>("interval_list") ),
227 mpBtnOk ( get<OKButton>("ok") ),
228 maStartHelper ( mpRbAutoStart, mpRbManStart, mpEdStart, rNullDate ),
229 maEndHelper ( mpRbAutoEnd, mpRbManEnd, mpEdEnd, rNullDate )
231 static const size_t nCount = sizeof( nDatePartResIds ) / sizeof( nDatePartResIds[0] );
232 for( size_t nIdx = 0 ; nIdx < nCount; ++nIdx )
233 mpLbUnits->InsertEntry( ScGlobal::GetRscString( nDatePartResIds[nIdx] ) );
235 mpEdStart->SetShowDateCentury( true );
236 mpEdEnd->SetShowDateCentury( true );
238 maStartHelper.SetValue( rInfo.mbAutoStart, rInfo.mfStart );
239 maEndHelper.SetValue( rInfo.mbAutoEnd, rInfo.mfEnd );
241 if( nDatePart == 0 )
242 nDatePart = com::sun::star::sheet::DataPilotFieldGroupBy::MONTHS;
243 for( size_t nIdx = 0; nIdx < nCount; ++nIdx )
244 mpLbUnits->CheckEntryPos( static_cast< sal_uInt16 >( nIdx ), (nDatePart & spnDateParts[ nIdx ]) != 0 );
246 if( rInfo.mbDateValues )
248 mpRbNumDays->Check();
249 ClickHdl( mpRbNumDays );
251 double fNumDays = rInfo.mfStep;
252 if( fNumDays < 1.0 )
253 fNumDays = 1.0;
254 else if( fNumDays > 32767.0 )
255 fNumDays = 32767.0;
256 mpEdNumDays->SetValue( static_cast< long >( fNumDays ) );
258 else
260 mpRbUnits->Check();
261 ClickHdl( mpRbUnits );
264 /* Set the initial focus, currently it is somewhere after calling all the radio
265 button click handlers. Now the first enabled editable control is focused. */
266 if( mpEdStart->IsEnabled() )
267 mpEdStart->GrabFocus();
268 else if( mpEdEnd->IsEnabled() )
269 mpEdEnd->GrabFocus();
270 else if( mpEdNumDays->IsEnabled() )
271 mpEdNumDays->GrabFocus();
272 else if( mpLbUnits->IsEnabled() )
273 mpLbUnits->GrabFocus();
275 mpRbNumDays->SetClickHdl( LINK( this, ScDPDateGroupDlg, ClickHdl ) );
276 mpRbUnits->SetClickHdl( LINK( this, ScDPDateGroupDlg, ClickHdl ) );
277 mpLbUnits->SetCheckButtonHdl( LINK( this, ScDPDateGroupDlg, CheckHdl ) );
280 ScDPDateGroupDlg::~ScDPDateGroupDlg()
282 disposeOnce();
285 void ScDPDateGroupDlg::dispose()
287 mpRbAutoStart.clear();
288 mpRbManStart.clear();
289 mpEdStart.clear();
290 mpRbAutoEnd.clear();
291 mpRbManEnd.clear();
292 mpEdEnd.clear();
293 mpRbNumDays.clear();
294 mpRbUnits.clear();
295 mpEdNumDays.clear();
296 mpLbUnits.clear();
297 mpBtnOk.clear();
298 ModalDialog::dispose();
301 ScDPNumGroupInfo ScDPDateGroupDlg::GetGroupInfo() const
303 ScDPNumGroupInfo aInfo;
304 aInfo.mbEnable = true;
305 aInfo.mbDateValues = mpRbNumDays->IsChecked();
306 aInfo.mbAutoStart = maStartHelper.IsAuto();
307 aInfo.mbAutoEnd = maEndHelper.IsAuto();
309 // get values and silently auto-correct them, if they are not valid
310 // TODO: error messages in OK event?
311 aInfo.mfStart = maStartHelper.GetValue();
312 aInfo.mfEnd = maEndHelper.GetValue();
313 sal_Int64 nNumDays = mpEdNumDays->GetValue();
314 aInfo.mfStep = static_cast<double>( aInfo.mbDateValues ? nNumDays : 0L );
315 if( aInfo.mfEnd <= aInfo.mfStart )
316 aInfo.mfEnd = aInfo.mfStart + nNumDays;
318 return aInfo;
321 sal_Int32 ScDPDateGroupDlg::GetDatePart() const
323 // return DAYS for special "number of days" mode
324 if( mpRbNumDays->IsChecked() )
325 return com::sun::star::sheet::DataPilotFieldGroupBy::DAYS;
327 // return listbox contents for "units" mode
328 sal_Int32 nDatePart = 0;
329 for( sal_uLong nIdx = 0, nCount = mpLbUnits->GetEntryCount(); nIdx < nCount; ++nIdx )
330 if( mpLbUnits->IsChecked( static_cast< sal_uInt16 >( nIdx ) ) )
331 nDatePart |= spnDateParts[ nIdx ];
332 return nDatePart;
335 IMPL_LINK( ScDPDateGroupDlg, ClickHdl, RadioButton*, pButton )
337 if( pButton == mpRbNumDays )
339 mpLbUnits->Disable();
340 // enable and set focus to edit field on clicking "num of days" radio button
341 mpEdNumDays->Enable();
342 mpEdNumDays->GrabFocus();
343 mpBtnOk->Enable();
345 else if( pButton == mpRbUnits )
347 mpEdNumDays->Disable();
348 // enable and set focus to listbox on clicking "units" radio button
349 mpLbUnits->Enable();
350 mpLbUnits->GrabFocus();
351 // disable OK button if no date part selected
352 CheckHdl( mpLbUnits );
354 return 0;
357 IMPL_LINK( ScDPDateGroupDlg, CheckHdl, SvxCheckListBox*, pListBox )
359 // enable/disable OK button on modifying check list box
360 if( pListBox == mpLbUnits )
361 mpBtnOk->Enable( mpLbUnits->GetCheckedEntryCount() > 0 );
362 return 0;
365 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */