xref: /trunk/main/sc/source/ui/dbgui/dpgroupdlg.cxx (revision a479921a)
1b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5b3f79822SAndrew Rist  * distributed with this work for additional information
6b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10b3f79822SAndrew Rist  *
11b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12b3f79822SAndrew Rist  *
13b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17b3f79822SAndrew Rist  * specific language governing permissions and limitations
18b3f79822SAndrew Rist  * under the License.
19b3f79822SAndrew Rist  *
20b3f79822SAndrew Rist  *************************************************************/
21b3f79822SAndrew Rist 
22b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25*b77af630Sdamjan #include "precompiled_scui.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "dpgroupdlg.hxx"
30cdf0e10cSrcweir #ifndef SC_DPGROUPDLG_HRC
31cdf0e10cSrcweir #include "dpgroupdlg.hrc"
32cdf0e10cSrcweir #endif
3358ae0c86SAriel Constenla-Haile 
34cdf0e10cSrcweir #include "scresid.hxx"
35cdf0e10cSrcweir #ifndef SC_SC_HRC
36cdf0e10cSrcweir #include "sc.hrc"
37cdf0e10cSrcweir #endif
3858ae0c86SAriel Constenla-Haile 
3958ae0c86SAriel Constenla-Haile #include "globstr.hrc"
4058ae0c86SAriel Constenla-Haile 
41cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotFieldGroupBy.hpp>
42cdf0e10cSrcweir 
43cdf0e10cSrcweir // ============================================================================
44cdf0e10cSrcweir 
45cdf0e10cSrcweir namespace {
46cdf0e10cSrcweir 
47cdf0e10cSrcweir /** Date part flags in order of the list box entries. */
48cdf0e10cSrcweir static const sal_Int32 spnDateParts[] =
49cdf0e10cSrcweir {
50cdf0e10cSrcweir     com::sun::star::sheet::DataPilotFieldGroupBy::SECONDS,
51cdf0e10cSrcweir     com::sun::star::sheet::DataPilotFieldGroupBy::MINUTES,
52cdf0e10cSrcweir     com::sun::star::sheet::DataPilotFieldGroupBy::HOURS,
53cdf0e10cSrcweir     com::sun::star::sheet::DataPilotFieldGroupBy::DAYS,
54cdf0e10cSrcweir     com::sun::star::sheet::DataPilotFieldGroupBy::MONTHS,
55cdf0e10cSrcweir     com::sun::star::sheet::DataPilotFieldGroupBy::QUARTERS,
56cdf0e10cSrcweir     com::sun::star::sheet::DataPilotFieldGroupBy::YEARS
57cdf0e10cSrcweir };
58cdf0e10cSrcweir 
5958ae0c86SAriel Constenla-Haile static const sal_uInt16 nDatePartResIds[] =
6058ae0c86SAriel Constenla-Haile {
6158ae0c86SAriel Constenla-Haile     STR_DPFIELD_GROUP_BY_SECONDS,
6258ae0c86SAriel Constenla-Haile     STR_DPFIELD_GROUP_BY_MINUTES,
6358ae0c86SAriel Constenla-Haile     STR_DPFIELD_GROUP_BY_HOURS,
6458ae0c86SAriel Constenla-Haile     STR_DPFIELD_GROUP_BY_DAYS,
6558ae0c86SAriel Constenla-Haile     STR_DPFIELD_GROUP_BY_MONTHS,
6658ae0c86SAriel Constenla-Haile     STR_DPFIELD_GROUP_BY_QUARTERS,
6758ae0c86SAriel Constenla-Haile     STR_DPFIELD_GROUP_BY_YEARS
6858ae0c86SAriel Constenla-Haile };
6958ae0c86SAriel Constenla-Haile 
70cdf0e10cSrcweir } // namespace
71cdf0e10cSrcweir 
72cdf0e10cSrcweir // ============================================================================
73cdf0e10cSrcweir 
ScDPGroupEditHelper(RadioButton & rRbAuto,RadioButton & rRbMan,Edit & rEdValue)74cdf0e10cSrcweir ScDPGroupEditHelper::ScDPGroupEditHelper( RadioButton& rRbAuto, RadioButton& rRbMan, Edit& rEdValue ) :
75cdf0e10cSrcweir     mrRbAuto( rRbAuto ),
76cdf0e10cSrcweir     mrRbMan( rRbMan ),
77cdf0e10cSrcweir     mrEdValue( rEdValue )
78cdf0e10cSrcweir {
79cdf0e10cSrcweir     mrRbAuto.SetClickHdl( LINK( this, ScDPGroupEditHelper, ClickHdl ) );
80cdf0e10cSrcweir     mrRbMan.SetClickHdl( LINK( this, ScDPGroupEditHelper, ClickHdl ) );
81cdf0e10cSrcweir }
82cdf0e10cSrcweir 
IsAuto() const83cdf0e10cSrcweir bool ScDPGroupEditHelper::IsAuto() const
84cdf0e10cSrcweir {
85cdf0e10cSrcweir     return mrRbAuto.IsChecked();
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
GetValue() const88cdf0e10cSrcweir double ScDPGroupEditHelper::GetValue() const
89cdf0e10cSrcweir {
90cdf0e10cSrcweir     double fValue;
91cdf0e10cSrcweir     if( !ImplGetValue( fValue ) )
92cdf0e10cSrcweir         fValue = 0.0;
93cdf0e10cSrcweir     return fValue;
94cdf0e10cSrcweir }
95cdf0e10cSrcweir 
SetValue(bool bAuto,double fValue)96cdf0e10cSrcweir void ScDPGroupEditHelper::SetValue( bool bAuto, double fValue )
97cdf0e10cSrcweir {
98cdf0e10cSrcweir     if( bAuto )
99cdf0e10cSrcweir     {
100cdf0e10cSrcweir         mrRbAuto.Check();
101cdf0e10cSrcweir         ClickHdl( &mrRbAuto );
102cdf0e10cSrcweir     }
103cdf0e10cSrcweir     else
104cdf0e10cSrcweir     {
105cdf0e10cSrcweir         mrRbMan.Check();
106cdf0e10cSrcweir         ClickHdl( &mrRbMan );
107cdf0e10cSrcweir     }
108cdf0e10cSrcweir     ImplSetValue( fValue );
109cdf0e10cSrcweir }
110cdf0e10cSrcweir 
IMPL_LINK(ScDPGroupEditHelper,ClickHdl,RadioButton *,pButton)111cdf0e10cSrcweir IMPL_LINK( ScDPGroupEditHelper, ClickHdl, RadioButton*, pButton )
112cdf0e10cSrcweir {
113cdf0e10cSrcweir     if( pButton == &mrRbAuto )
114cdf0e10cSrcweir     {
115cdf0e10cSrcweir         // disable edit field on clicking "automatic" radio button
116cdf0e10cSrcweir         mrEdValue.Disable();
117cdf0e10cSrcweir     }
118cdf0e10cSrcweir     else if( pButton == &mrRbMan )
119cdf0e10cSrcweir     {
120cdf0e10cSrcweir         // enable and set focus to edit field on clicking "manual" radio button
121cdf0e10cSrcweir         mrEdValue.Enable();
122cdf0e10cSrcweir         mrEdValue.GrabFocus();
123cdf0e10cSrcweir     }
124cdf0e10cSrcweir     return 0;
125cdf0e10cSrcweir }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir // ----------------------------------------------------------------------------
128cdf0e10cSrcweir 
ScDPNumGroupEditHelper(RadioButton & rRbAuto,RadioButton & rRbMan,ScDoubleField & rEdValue)129cdf0e10cSrcweir ScDPNumGroupEditHelper::ScDPNumGroupEditHelper(
130cdf0e10cSrcweir         RadioButton& rRbAuto, RadioButton& rRbMan, ScDoubleField& rEdValue ) :
131cdf0e10cSrcweir     ScDPGroupEditHelper( rRbAuto, rRbMan, rEdValue ),
132cdf0e10cSrcweir     mrEdValue( rEdValue )
133cdf0e10cSrcweir {
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
ImplGetValue(double & rfValue) const136cdf0e10cSrcweir bool ScDPNumGroupEditHelper::ImplGetValue( double& rfValue ) const
137cdf0e10cSrcweir {
138cdf0e10cSrcweir     return mrEdValue.GetValue( rfValue );
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
ImplSetValue(double fValue)141cdf0e10cSrcweir void ScDPNumGroupEditHelper::ImplSetValue( double fValue )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir     mrEdValue.SetValue( fValue );
144cdf0e10cSrcweir }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir // ----------------------------------------------------------------------------
147cdf0e10cSrcweir 
ScDPDateGroupEditHelper(RadioButton & rRbAuto,RadioButton & rRbMan,DateField & rEdValue,const Date & rNullDate)148cdf0e10cSrcweir ScDPDateGroupEditHelper::ScDPDateGroupEditHelper(
149cdf0e10cSrcweir         RadioButton& rRbAuto, RadioButton& rRbMan, DateField& rEdValue, const Date& rNullDate ) :
150cdf0e10cSrcweir     ScDPGroupEditHelper( rRbAuto, rRbMan, rEdValue ),
151cdf0e10cSrcweir     mrEdValue( rEdValue ),
152cdf0e10cSrcweir     maNullDate( rNullDate )
153cdf0e10cSrcweir {
154cdf0e10cSrcweir }
155cdf0e10cSrcweir 
ImplGetValue(double & rfValue) const156cdf0e10cSrcweir bool ScDPDateGroupEditHelper::ImplGetValue( double& rfValue ) const
157cdf0e10cSrcweir {
158cdf0e10cSrcweir     rfValue = mrEdValue.GetDate() - maNullDate;
159cdf0e10cSrcweir     return true;
160cdf0e10cSrcweir }
161cdf0e10cSrcweir 
ImplSetValue(double fValue)162cdf0e10cSrcweir void ScDPDateGroupEditHelper::ImplSetValue( double fValue )
163cdf0e10cSrcweir {
164cdf0e10cSrcweir     Date aDate( maNullDate );
165cdf0e10cSrcweir     aDate += static_cast< sal_Int32 >( fValue );
166cdf0e10cSrcweir     mrEdValue.SetDate( aDate );
167cdf0e10cSrcweir }
168cdf0e10cSrcweir 
169cdf0e10cSrcweir // ============================================================================
170cdf0e10cSrcweir // ============================================================================
171cdf0e10cSrcweir 
ScDPNumGroupDlg(Window * pParent,const ScDPNumGroupInfo & rInfo)172cdf0e10cSrcweir ScDPNumGroupDlg::ScDPNumGroupDlg( Window* pParent, const ScDPNumGroupInfo& rInfo ) :
173cdf0e10cSrcweir     ModalDialog     ( pParent, ScResId( RID_SCDLG_DPNUMGROUP ) ),
174cdf0e10cSrcweir     maFlStart       ( this, ScResId( FL_START ) ),
175cdf0e10cSrcweir     maRbAutoStart   ( this, ScResId( RB_AUTOSTART ) ),
176cdf0e10cSrcweir     maRbManStart    ( this, ScResId( RB_MANSTART ) ),
177cdf0e10cSrcweir     maEdStart       ( this, ScResId( ED_START ) ),
178cdf0e10cSrcweir     maFlEnd         ( this, ScResId( FL_END ) ),
179cdf0e10cSrcweir     maRbAutoEnd     ( this, ScResId( RB_AUTOEND ) ),
180cdf0e10cSrcweir     maRbManEnd      ( this, ScResId( RB_MANEND ) ),
181cdf0e10cSrcweir     maEdEnd         ( this, ScResId( ED_END ) ),
182cdf0e10cSrcweir     maFlBy          ( this, ScResId( FL_BY ) ),
183cdf0e10cSrcweir     maEdBy          ( this, ScResId( ED_BY ) ),
184cdf0e10cSrcweir     maBtnOk         ( this, ScResId( BTN_OK ) ),
185cdf0e10cSrcweir     maBtnCancel     ( this, ScResId( BTN_CANCEL ) ),
186cdf0e10cSrcweir     maBtnHelp       ( this, ScResId( BTN_HELP ) ),
187cdf0e10cSrcweir     maStartHelper   ( maRbAutoStart, maRbManStart, maEdStart ),
188cdf0e10cSrcweir     maEndHelper     ( maRbAutoEnd, maRbManEnd, maEdEnd )
189cdf0e10cSrcweir {
190cdf0e10cSrcweir     FreeResource();
191cdf0e10cSrcweir 
192cdf0e10cSrcweir     maStartHelper.SetValue( rInfo.AutoStart, rInfo.Start );
193cdf0e10cSrcweir     maEndHelper.SetValue( rInfo.AutoEnd, rInfo.End );
194cdf0e10cSrcweir     maEdBy.SetValue( (rInfo.Step <= 0.0) ? 1.0 : rInfo.Step );
195cdf0e10cSrcweir 
196cdf0e10cSrcweir     /*  Set the initial focus, currently it is somewhere after calling all the radio
197cdf0e10cSrcweir         button click handlers. Now the first enabled editable control is focused. */
198cdf0e10cSrcweir     if( maEdStart.IsEnabled() )
199cdf0e10cSrcweir         maEdStart.GrabFocus();
200cdf0e10cSrcweir     else if( maEdEnd.IsEnabled() )
201cdf0e10cSrcweir         maEdEnd.GrabFocus();
202cdf0e10cSrcweir     else
203cdf0e10cSrcweir         maEdBy.GrabFocus();
204cdf0e10cSrcweir }
205cdf0e10cSrcweir 
GetGroupInfo() const206cdf0e10cSrcweir ScDPNumGroupInfo ScDPNumGroupDlg::GetGroupInfo() const
207cdf0e10cSrcweir {
208cdf0e10cSrcweir     ScDPNumGroupInfo aInfo;
209cdf0e10cSrcweir     aInfo.Enable = sal_True;
210cdf0e10cSrcweir     aInfo.DateValues = sal_False;
211cdf0e10cSrcweir     aInfo.AutoStart = maStartHelper.IsAuto();
212cdf0e10cSrcweir     aInfo.AutoEnd = maEndHelper.IsAuto();
213cdf0e10cSrcweir 
214cdf0e10cSrcweir     // get values and silently auto-correct them, if they are not valid
215cdf0e10cSrcweir     // TODO: error messages in OK event?
216cdf0e10cSrcweir     aInfo.Start = maStartHelper.GetValue();
217cdf0e10cSrcweir     aInfo.End = maEndHelper.GetValue();
218cdf0e10cSrcweir     if( !maEdBy.GetValue( aInfo.Step ) || (aInfo.Step <= 0.0) )
219cdf0e10cSrcweir         aInfo.Step = 1.0;
220cdf0e10cSrcweir     if( aInfo.End <= aInfo.Start )
221cdf0e10cSrcweir         aInfo.End = aInfo.Start + aInfo.Step;
222cdf0e10cSrcweir 
223cdf0e10cSrcweir     return aInfo;
224cdf0e10cSrcweir }
225cdf0e10cSrcweir 
226cdf0e10cSrcweir // ============================================================================
227cdf0e10cSrcweir 
ScDPDateGroupDlg(Window * pParent,const ScDPNumGroupInfo & rInfo,sal_Int32 nDatePart,const Date & rNullDate)228cdf0e10cSrcweir ScDPDateGroupDlg::ScDPDateGroupDlg( Window* pParent,
229cdf0e10cSrcweir         const ScDPNumGroupInfo& rInfo, sal_Int32 nDatePart, const Date& rNullDate ) :
230cdf0e10cSrcweir     ModalDialog     ( pParent, ScResId( RID_SCDLG_DPDATEGROUP ) ),
231cdf0e10cSrcweir     maFlStart       ( this, ScResId( FL_START ) ),
232cdf0e10cSrcweir     maRbAutoStart   ( this, ScResId( RB_AUTOSTART ) ),
233cdf0e10cSrcweir     maRbManStart    ( this, ScResId( RB_MANSTART ) ),
234cdf0e10cSrcweir     maEdStart       ( this, ScResId( ED_START ) ),
235cdf0e10cSrcweir     maFlEnd         ( this, ScResId( FL_END ) ),
236cdf0e10cSrcweir     maRbAutoEnd     ( this, ScResId( RB_AUTOEND ) ),
237cdf0e10cSrcweir     maRbManEnd      ( this, ScResId( RB_MANEND ) ),
238cdf0e10cSrcweir     maEdEnd         ( this, ScResId( ED_END ) ),
239cdf0e10cSrcweir     maFlBy          ( this, ScResId( FL_BY ) ),
240cdf0e10cSrcweir     maRbNumDays     ( this, ScResId( RB_NUMDAYS ) ),
241cdf0e10cSrcweir     maRbUnits       ( this, ScResId( RB_UNITS ) ),
242cdf0e10cSrcweir     maEdNumDays     ( this, ScResId( ED_NUMDAYS ) ),
243cdf0e10cSrcweir     maLbUnits       ( this, ScResId( LB_UNITS ) ),
244cdf0e10cSrcweir     maBtnOk         ( this, ScResId( BTN_OK ) ),
245cdf0e10cSrcweir     maBtnCancel     ( this, ScResId( BTN_CANCEL ) ),
246cdf0e10cSrcweir     maBtnHelp       ( this, ScResId( BTN_HELP ) ),
247cdf0e10cSrcweir     maStartHelper   ( maRbAutoStart, maRbManStart, maEdStart, rNullDate ),
248cdf0e10cSrcweir     maEndHelper     ( maRbAutoEnd, maRbManEnd, maEdEnd, rNullDate )
249cdf0e10cSrcweir {
25058ae0c86SAriel Constenla-Haile     FreeResource();
25158ae0c86SAriel Constenla-Haile 
252cdf0e10cSrcweir     maLbUnits.SetHelpId( HID_SC_DPDATEGROUP_LB );
253cdf0e10cSrcweir 
25458ae0c86SAriel Constenla-Haile     static const size_t nCount = sizeof( nDatePartResIds ) / sizeof( nDatePartResIds[0] );
25558ae0c86SAriel Constenla-Haile     for( size_t nIdx = 0 ; nIdx < nCount; ++nIdx )
25658ae0c86SAriel Constenla-Haile         maLbUnits.InsertEntry( ScGlobal::GetRscString( nDatePartResIds[nIdx] ) );
257cdf0e10cSrcweir 
258cdf0e10cSrcweir     maEdStart.SetShowDateCentury( sal_True );
259cdf0e10cSrcweir     maEdEnd.SetShowDateCentury( sal_True );
260cdf0e10cSrcweir 
261cdf0e10cSrcweir     maStartHelper.SetValue( rInfo.AutoStart, rInfo.Start );
262cdf0e10cSrcweir     maEndHelper.SetValue( rInfo.AutoEnd, rInfo.End );
263cdf0e10cSrcweir 
264cdf0e10cSrcweir     if( nDatePart == 0 )
265cdf0e10cSrcweir         nDatePart = com::sun::star::sheet::DataPilotFieldGroupBy::MONTHS;
26658ae0c86SAriel Constenla-Haile     for( size_t nIdx = 0; nIdx < nCount; ++nIdx )
267cdf0e10cSrcweir         maLbUnits.CheckEntryPos( static_cast< sal_uInt16 >( nIdx ), (nDatePart & spnDateParts[ nIdx ]) != 0 );
268cdf0e10cSrcweir 
269cdf0e10cSrcweir     if( rInfo.DateValues )
270cdf0e10cSrcweir     {
271cdf0e10cSrcweir         maRbNumDays.Check();
272cdf0e10cSrcweir         ClickHdl( &maRbNumDays );
273cdf0e10cSrcweir 
274cdf0e10cSrcweir         double fNumDays = rInfo.Step;
275cdf0e10cSrcweir         if( fNumDays < 1.0 )
276cdf0e10cSrcweir             fNumDays = 1.0;
277cdf0e10cSrcweir         else if( fNumDays > 32767.0 )
278cdf0e10cSrcweir             fNumDays = 32767.0;
279cdf0e10cSrcweir         maEdNumDays.SetValue( static_cast< long >( fNumDays ) );
280cdf0e10cSrcweir     }
281cdf0e10cSrcweir     else
282cdf0e10cSrcweir     {
283cdf0e10cSrcweir         maRbUnits.Check();
284cdf0e10cSrcweir         ClickHdl( &maRbUnits );
285cdf0e10cSrcweir     }
286cdf0e10cSrcweir 
287cdf0e10cSrcweir     /*  Set the initial focus, currently it is somewhere after calling all the radio
288cdf0e10cSrcweir         button click handlers. Now the first enabled editable control is focused. */
289cdf0e10cSrcweir     if( maEdStart.IsEnabled() )
290cdf0e10cSrcweir         maEdStart.GrabFocus();
291cdf0e10cSrcweir     else if( maEdEnd.IsEnabled() )
292cdf0e10cSrcweir         maEdEnd.GrabFocus();
293cdf0e10cSrcweir     else if( maEdNumDays.IsEnabled() )
294cdf0e10cSrcweir         maEdNumDays.GrabFocus();
295cdf0e10cSrcweir     else if( maLbUnits.IsEnabled() )
296cdf0e10cSrcweir         maLbUnits.GrabFocus();
297cdf0e10cSrcweir 
298cdf0e10cSrcweir     maRbNumDays.SetClickHdl( LINK( this, ScDPDateGroupDlg, ClickHdl ) );
299cdf0e10cSrcweir     maRbUnits.SetClickHdl( LINK( this, ScDPDateGroupDlg, ClickHdl ) );
300cdf0e10cSrcweir     maLbUnits.SetCheckButtonHdl( LINK( this, ScDPDateGroupDlg, CheckHdl ) );
301cdf0e10cSrcweir }
302cdf0e10cSrcweir 
GetGroupInfo() const303cdf0e10cSrcweir ScDPNumGroupInfo ScDPDateGroupDlg::GetGroupInfo() const
304cdf0e10cSrcweir {
305cdf0e10cSrcweir     ScDPNumGroupInfo aInfo;
306cdf0e10cSrcweir     aInfo.Enable = sal_True;
307cdf0e10cSrcweir     aInfo.DateValues = maRbNumDays.IsChecked();
308cdf0e10cSrcweir     aInfo.AutoStart = maStartHelper.IsAuto();
309cdf0e10cSrcweir     aInfo.AutoEnd = maEndHelper.IsAuto();
310cdf0e10cSrcweir 
311cdf0e10cSrcweir     // get values and silently auto-correct them, if they are not valid
312cdf0e10cSrcweir     // TODO: error messages in OK event?
313cdf0e10cSrcweir     aInfo.Start = maStartHelper.GetValue();
314cdf0e10cSrcweir     aInfo.End = maEndHelper.GetValue();
315cdf0e10cSrcweir     sal_Int64 nNumDays = maEdNumDays.GetValue();
316cdf0e10cSrcweir     aInfo.Step = static_cast<double>( aInfo.DateValues ? nNumDays : 0L );
317cdf0e10cSrcweir     if( aInfo.End <= aInfo.Start )
318cdf0e10cSrcweir         aInfo.End = aInfo.Start + nNumDays;
319cdf0e10cSrcweir 
320cdf0e10cSrcweir     return aInfo;
321cdf0e10cSrcweir }
322cdf0e10cSrcweir 
GetDatePart() const323cdf0e10cSrcweir sal_Int32 ScDPDateGroupDlg::GetDatePart() const
324cdf0e10cSrcweir {
325cdf0e10cSrcweir     // return DAYS for special "number of days" mode
326cdf0e10cSrcweir     if( maRbNumDays.IsChecked() )
327cdf0e10cSrcweir         return com::sun::star::sheet::DataPilotFieldGroupBy::DAYS;
328cdf0e10cSrcweir 
329cdf0e10cSrcweir     // return listbox contents for "units" mode
330cdf0e10cSrcweir     sal_Int32 nDatePart = 0;
331cdf0e10cSrcweir     for( sal_uLong nIdx = 0, nCount = maLbUnits.GetEntryCount(); nIdx < nCount; ++nIdx )
332cdf0e10cSrcweir         if( maLbUnits.IsChecked( static_cast< sal_uInt16 >( nIdx ) ) )
333cdf0e10cSrcweir             nDatePart |= spnDateParts[ nIdx ];
334cdf0e10cSrcweir     return nDatePart;
335cdf0e10cSrcweir }
336cdf0e10cSrcweir 
IMPL_LINK(ScDPDateGroupDlg,ClickHdl,RadioButton *,pButton)337cdf0e10cSrcweir IMPL_LINK( ScDPDateGroupDlg, ClickHdl, RadioButton*, pButton )
338cdf0e10cSrcweir {
339cdf0e10cSrcweir     if( pButton == &maRbNumDays )
340cdf0e10cSrcweir     {
341cdf0e10cSrcweir         maLbUnits.Disable();
342cdf0e10cSrcweir         // enable and set focus to edit field on clicking "num of days" radio button
343cdf0e10cSrcweir         maEdNumDays.Enable();
344cdf0e10cSrcweir         maEdNumDays.GrabFocus();
345cdf0e10cSrcweir         maBtnOk.Enable();
346cdf0e10cSrcweir     }
347cdf0e10cSrcweir     else if( pButton == &maRbUnits )
348cdf0e10cSrcweir     {
349cdf0e10cSrcweir         maEdNumDays.Disable();
350cdf0e10cSrcweir         // enable and set focus to listbox on clicking "units" radio button
351cdf0e10cSrcweir         maLbUnits.Enable();
352cdf0e10cSrcweir         maLbUnits.GrabFocus();
353cdf0e10cSrcweir         // disable OK button if no date part selected
354cdf0e10cSrcweir         CheckHdl( &maLbUnits );
355cdf0e10cSrcweir     }
356cdf0e10cSrcweir     return 0;
357cdf0e10cSrcweir }
358cdf0e10cSrcweir 
IMPL_LINK(ScDPDateGroupDlg,CheckHdl,SvxCheckListBox *,pListBox)359cdf0e10cSrcweir IMPL_LINK( ScDPDateGroupDlg, CheckHdl, SvxCheckListBox*, pListBox )
360cdf0e10cSrcweir {
361cdf0e10cSrcweir     // enable/disable OK button on modifying check list box
362cdf0e10cSrcweir     if( pListBox == &maLbUnits )
363cdf0e10cSrcweir         maBtnOk.Enable( maLbUnits.GetCheckedEntryCount() > 0 );
364cdf0e10cSrcweir     return 0;
365cdf0e10cSrcweir }
366cdf0e10cSrcweir 
367cdf0e10cSrcweir // ============================================================================
368cdf0e10cSrcweir 
369