Update ooo320-m1
[ooovba.git] / sc / source / ui / miscdlgs / filldlg.cxx
blobc30b9a86532e67d3e5158cd1656a5c2c8f4c85e7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: filldlg.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #undef SC_DLLIMPLEMENTATION
38 //----------------------------------------------------------------------------
40 #include <svtools/zforlist.hxx>
41 #include <vcl/msgbox.hxx>
42 #include <limits.h>
44 #include "scresid.hxx"
45 #include "document.hxx"
46 #include "miscdlgs.hrc"
48 #define _FILLDLG_CXX
49 #include "filldlg.hxx"
50 #undef _FILLDLG_CXX
54 //============================================================================
55 // class ScFillSeriesDlg
57 //----------------------------------------------------------------------------
59 ScFillSeriesDlg::ScFillSeriesDlg( Window* pParent,
60 ScDocument& rDocument,
61 FillDir eFillDir,
62 FillCmd eFillCmd,
63 FillDateCmd eFillDateCmd,
64 String aStartStr,
65 double fStep,
66 double fMax,
67 USHORT nPossDir )
69 : ModalDialog ( pParent, ScResId( RID_SCDLG_FILLSERIES ) ),
71 aFlDirection ( this, ScResId( FL_DIRECTION ) ),
72 aBtnDown ( this, ScResId( BTN_BOTTOM ) ),
73 aBtnRight ( this, ScResId( BTN_RIGHT ) ),
74 aBtnUp ( this, ScResId( BTN_TOP ) ),
75 aBtnLeft ( this, ScResId( BTN_LEFT ) ),
76 aFlSep1 ( this, ScResId( FL_SEP1 ) ),
77 aFlType ( this, ScResId( FL_TYPE ) ),
78 aBtnArithmetic ( this, ScResId( BTN_ARITHMETIC ) ),
79 aBtnGeometric ( this, ScResId( BTN_GEOMETRIC ) ),
80 aBtnDate ( this, ScResId( BTN_DATE ) ),
81 aBtnAutoFill ( this, ScResId( BTN_AUTOFILL ) ),
82 aFlSep2 ( this, ScResId( FL_SEP2 ) ),
83 aFlTimeUnit ( this, ScResId( FL_TIME_UNIT ) ),
84 aBtnDay ( this, ScResId( BTN_DAY ) ),
85 aBtnDayOfWeek ( this, ScResId( BTN_DAY_OF_WEEK ) ),
86 aBtnMonth ( this, ScResId( BTN_MONTH ) ),
87 aBtnYear ( this, ScResId( BTN_YEAR ) ),
89 aFtStartVal ( this, ScResId( FT_START_VALUE ) ),
90 aEdStartVal ( this, ScResId( ED_START_VALUES ) ),
91 aStartStrVal ( aStartStr),
92 aFtEndVal ( this, ScResId( FT_END_VALUE ) ),
93 aEdEndVal ( this, ScResId( ED_END_VALUES ) ),
94 aFtIncrement ( this, ScResId( FT_INCREMENT ) ),
95 aEdIncrement ( this, ScResId( ED_INCREMENT ) ),
97 aBtnOk ( this, ScResId( BTN_OK ) ),
98 aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
99 aBtnHelp ( this, ScResId( BTN_HELP ) ),
100 errMsgInvalidVal( ScResId( STR_VALERR ) ),
101 rDoc ( rDocument ),
102 theFillDir ( eFillDir ),
103 theFillCmd ( eFillCmd ),
104 theFillDateCmd ( eFillDateCmd ),
105 fIncrement ( fStep ),
106 fEndVal ( fMax )
108 Init( nPossDir );
109 FreeResource();
113 //----------------------------------------------------------------------------
115 __EXPORT ScFillSeriesDlg::~ScFillSeriesDlg()
119 //----------------------------------------------------------------------------
121 void ScFillSeriesDlg::SetEdStartValEnabled(BOOL bFlag)
123 bStartValFlag=bFlag;
124 if(bFlag)
126 aFtStartVal.Enable();
127 aEdStartVal.Enable();
129 else
131 aFtStartVal.Disable();
132 aEdStartVal.Disable();
136 //----------------------------------------------------------------------------
138 void ScFillSeriesDlg::Init( USHORT nPossDir )
140 aBtnOk.SetClickHdl ( LINK( this, ScFillSeriesDlg, OKHdl ) );
141 aBtnArithmetic.SetClickHdl ( LINK( this, ScFillSeriesDlg, DisableHdl ) );
142 aBtnGeometric.SetClickHdl ( LINK( this, ScFillSeriesDlg, DisableHdl ) );
143 aBtnDate.SetClickHdl ( LINK( this, ScFillSeriesDlg, DisableHdl ) );
144 aBtnAutoFill.SetClickHdl ( LINK( this, ScFillSeriesDlg, DisableHdl ) );
146 if( nPossDir == FDS_OPT_NONE )
148 aBtnLeft.Disable();
149 aBtnRight.Disable();
150 aBtnDown.Disable();
151 aBtnUp.Disable();
154 if( nPossDir == FDS_OPT_HORZ )
156 aBtnDown.Disable();
157 aBtnUp.Disable();
160 if( nPossDir == FDS_OPT_VERT )
162 aBtnLeft.Disable();
163 aBtnRight.Disable();
166 switch ( theFillDir )
168 case FILL_TO_LEFT: aBtnLeft.Check(); break;
169 case FILL_TO_RIGHT: aBtnRight.Check(); break;
170 case FILL_TO_BOTTOM: aBtnDown.Check(); break;
171 case FILL_TO_TOP: aBtnUp.Check(); break;
172 default:
173 break;
176 switch ( theFillCmd )
178 case FILL_LINEAR:
179 aBtnArithmetic.Check();
180 DisableHdl( &aBtnArithmetic );
181 break;
182 case FILL_GROWTH:
183 aBtnGeometric.Check();
184 DisableHdl( &aBtnGeometric );
185 break;
186 case FILL_DATE:
187 aBtnDate.Check();
188 DisableHdl( &aBtnDate );
189 break;
190 case FILL_AUTO:
191 aBtnAutoFill.Check();
192 DisableHdl( &aBtnAutoFill );
193 break;
194 default:
195 break;
198 switch ( theFillDateCmd )
200 case FILL_DAY: aBtnDay.Check(); break;
201 case FILL_WEEKDAY: aBtnDayOfWeek.Check(); break;
202 case FILL_MONTH: aBtnMonth.Check(); break;
203 case FILL_YEAR: aBtnYear.Check(); break;
204 default:
205 break;
208 fStartVal = MAXDOUBLE;
210 String aStartTxt;
211 if ( fStartVal != MAXDOUBLE )
212 rDoc.GetFormatTable()->GetInputLineString( fStartVal, 0, aStartTxt );
213 aEdStartVal.SetText( aStartTxt );
216 aEdStartVal.SetText( aStartStrVal);
218 String aIncrTxt;
219 rDoc.GetFormatTable()->GetInputLineString( fIncrement, 0, aIncrTxt );
220 aEdIncrement.SetText( aIncrTxt );
222 String aEndTxt;
223 if ( fEndVal != MAXDOUBLE )
224 rDoc.GetFormatTable()->GetInputLineString( fEndVal, 0, aEndTxt );
225 aEdEndVal.SetText( aEndTxt );
227 bStartValFlag=FALSE;
229 aFlSep1.SetStyle( aFlSep1.GetStyle() | WB_VERT );
230 aFlSep2.SetStyle( aFlSep2.GetStyle() | WB_VERT );
234 //----------------------------------------------------------------------------
236 BOOL __EXPORT ScFillSeriesDlg::CheckStartVal()
238 BOOL bValOk = FALSE;
239 sal_uInt32 nKey = 0;
240 String aStr( aEdStartVal.GetText() );
242 if ( aStr.Len() == 0 || aBtnAutoFill.IsChecked())
244 fStartVal = MAXDOUBLE;
245 bValOk = TRUE;
247 else
248 bValOk = rDoc.GetFormatTable()->IsNumberFormat( aStr, nKey, fStartVal );
250 return bValOk;
254 //----------------------------------------------------------------------------
256 BOOL __EXPORT ScFillSeriesDlg::CheckIncrementVal()
258 sal_uInt32 nKey = 0;
259 String aStr( aEdIncrement.GetText() );
261 return rDoc.GetFormatTable()->IsNumberFormat( aStr, nKey, fIncrement );
265 //----------------------------------------------------------------------------
267 BOOL __EXPORT ScFillSeriesDlg::CheckEndVal()
269 BOOL bValOk = FALSE;
270 sal_uInt32 nKey = 0;
271 String aStr( aEdEndVal.GetText() );
273 if ( aStr.Len() == 0 )
275 fEndVal = (fIncrement < 0) ? -MAXDOUBLE : MAXDOUBLE;
276 bValOk = TRUE;
278 else
279 bValOk = rDoc.GetFormatTable()->IsNumberFormat( aStr, nKey, fEndVal );
281 return bValOk;
285 //----------------------------------------------------------------------------
286 // Handler:
287 //----------------------------------------------------------------------------
289 IMPL_LINK( ScFillSeriesDlg, DisableHdl, Button *, pBtn )
291 if ( pBtn == &aBtnDate )
293 aBtnDay.Enable();
294 aBtnDayOfWeek.Enable();
295 aBtnMonth.Enable();
296 aBtnYear.Enable();
297 aFlTimeUnit.Enable();
299 else
301 aBtnDay.Disable();
302 aBtnDayOfWeek.Disable();
303 aBtnMonth.Disable();
304 aBtnYear.Disable();
305 aFlTimeUnit.Disable();
308 if ( pBtn != &aBtnAutoFill )
310 aFtIncrement.Enable();
311 aEdIncrement.Enable();
312 aFtEndVal.Enable();
313 aEdEndVal.Enable();
315 else
317 aFtIncrement.Disable();
318 aEdIncrement.Disable();
319 aFtEndVal.Disable();
320 aEdEndVal.Disable();
322 return 0;
326 //----------------------------------------------------------------------------
328 IMPL_LINK( ScFillSeriesDlg, OKHdl, void *, EMPTYARG )
330 if ( aBtnLeft.IsChecked() ) theFillDir = FILL_TO_LEFT;
331 else if ( aBtnRight.IsChecked() ) theFillDir = FILL_TO_RIGHT;
332 else if ( aBtnDown.IsChecked() ) theFillDir = FILL_TO_BOTTOM;
333 else if ( aBtnUp.IsChecked() ) theFillDir = FILL_TO_TOP;
335 if ( aBtnArithmetic.IsChecked() ) theFillCmd = FILL_LINEAR;
336 else if ( aBtnGeometric.IsChecked() ) theFillCmd = FILL_GROWTH;
337 else if ( aBtnDate.IsChecked() ) theFillCmd = FILL_DATE;
338 else if ( aBtnAutoFill.IsChecked() ) theFillCmd = FILL_AUTO;
340 if ( aBtnDay.IsChecked() ) theFillDateCmd = FILL_DAY;
341 else if ( aBtnDayOfWeek.IsChecked() ) theFillDateCmd = FILL_WEEKDAY;
342 else if ( aBtnMonth.IsChecked() ) theFillDateCmd = FILL_MONTH;
343 else if ( aBtnYear.IsChecked() ) theFillDateCmd = FILL_YEAR;
345 BOOL bAllOk = TRUE;
346 Edit* pEdWrong = NULL;
347 if ( !CheckStartVal() )
349 bAllOk = FALSE;
350 pEdWrong = &aEdStartVal;
352 else if ( !CheckIncrementVal() )
354 bAllOk = FALSE;
355 pEdWrong = &aEdIncrement;
357 else if ( !CheckEndVal() )
359 bAllOk = FALSE;
360 pEdWrong = &aEdEndVal;
362 if ( bAllOk )
363 EndDialog( RET_OK );
364 else
366 ErrorBox( this,
367 WinBits( WB_OK | WB_DEF_OK ),
368 errMsgInvalidVal
369 ).Execute();
370 pEdWrong->GrabFocus();
373 return 0;