1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*b3f79822SAndrew Rist * distributed with this work for additional information
6*b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist * KIND, either express or implied. See the License for the
17*b3f79822SAndrew Rist * specific language governing permissions and limitations
18*b3f79822SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*b3f79822SAndrew Rist *************************************************************/
21*b3f79822SAndrew Rist
22*b3f79822SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #undef SC_DLLIMPLEMENTATION
28cdf0e10cSrcweir
29cdf0e10cSrcweir
30cdf0e10cSrcweir
31cdf0e10cSrcweir //----------------------------------------------------------------------------
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include <svl/zforlist.hxx>
34cdf0e10cSrcweir #include <vcl/msgbox.hxx>
35cdf0e10cSrcweir #include <limits.h>
36cdf0e10cSrcweir
37cdf0e10cSrcweir #include "scresid.hxx"
38cdf0e10cSrcweir #include "document.hxx"
39cdf0e10cSrcweir #include "miscdlgs.hrc"
40cdf0e10cSrcweir
41cdf0e10cSrcweir #define _FILLDLG_CXX
42cdf0e10cSrcweir #include "filldlg.hxx"
43cdf0e10cSrcweir #undef _FILLDLG_CXX
44cdf0e10cSrcweir
45cdf0e10cSrcweir
46cdf0e10cSrcweir
47cdf0e10cSrcweir //============================================================================
48cdf0e10cSrcweir // class ScFillSeriesDlg
49cdf0e10cSrcweir
50cdf0e10cSrcweir //----------------------------------------------------------------------------
51cdf0e10cSrcweir
ScFillSeriesDlg(Window * pParent,ScDocument & rDocument,FillDir eFillDir,FillCmd eFillCmd,FillDateCmd eFillDateCmd,String aStartStr,double fStep,double fMax,sal_uInt16 nPossDir)52cdf0e10cSrcweir ScFillSeriesDlg::ScFillSeriesDlg( Window* pParent,
53cdf0e10cSrcweir ScDocument& rDocument,
54cdf0e10cSrcweir FillDir eFillDir,
55cdf0e10cSrcweir FillCmd eFillCmd,
56cdf0e10cSrcweir FillDateCmd eFillDateCmd,
57cdf0e10cSrcweir String aStartStr,
58cdf0e10cSrcweir double fStep,
59cdf0e10cSrcweir double fMax,
60cdf0e10cSrcweir sal_uInt16 nPossDir )
61cdf0e10cSrcweir
62cdf0e10cSrcweir : ModalDialog ( pParent, ScResId( RID_SCDLG_FILLSERIES ) ),
63cdf0e10cSrcweir
64cdf0e10cSrcweir aFtStartVal ( this, ScResId( FT_START_VALUE ) ),
65cdf0e10cSrcweir aEdStartVal ( this, ScResId( ED_START_VALUES ) ),
66cdf0e10cSrcweir aStartStrVal ( aStartStr),
67cdf0e10cSrcweir
68cdf0e10cSrcweir aFtEndVal ( this, ScResId( FT_END_VALUE ) ),
69cdf0e10cSrcweir aEdEndVal ( this, ScResId( ED_END_VALUES ) ),
70cdf0e10cSrcweir
71cdf0e10cSrcweir aFtIncrement ( this, ScResId( FT_INCREMENT ) ),
72cdf0e10cSrcweir aEdIncrement ( this, ScResId( ED_INCREMENT ) ),
73cdf0e10cSrcweir
74cdf0e10cSrcweir aFlDirection ( this, ScResId( FL_DIRECTION ) ),
75cdf0e10cSrcweir aBtnDown ( this, ScResId( BTN_BOTTOM ) ),
76cdf0e10cSrcweir aBtnRight ( this, ScResId( BTN_RIGHT ) ),
77cdf0e10cSrcweir aBtnUp ( this, ScResId( BTN_TOP ) ),
78cdf0e10cSrcweir aBtnLeft ( this, ScResId( BTN_LEFT ) ),
79cdf0e10cSrcweir aFlSep1 ( this, ScResId( FL_SEP1 ) ),
80cdf0e10cSrcweir aFlType ( this, ScResId( FL_TYPE ) ),
81cdf0e10cSrcweir aBtnArithmetic ( this, ScResId( BTN_ARITHMETIC ) ),
82cdf0e10cSrcweir aBtnGeometric ( this, ScResId( BTN_GEOMETRIC ) ),
83cdf0e10cSrcweir aBtnDate ( this, ScResId( BTN_DATE ) ),
84cdf0e10cSrcweir aBtnAutoFill ( this, ScResId( BTN_AUTOFILL ) ),
85cdf0e10cSrcweir aFlSep2 ( this, ScResId( FL_SEP2 ) ),
86cdf0e10cSrcweir aFlTimeUnit ( this, ScResId( FL_TIME_UNIT ) ),
87cdf0e10cSrcweir aBtnDay ( this, ScResId( BTN_DAY ) ),
88cdf0e10cSrcweir aBtnDayOfWeek ( this, ScResId( BTN_DAY_OF_WEEK ) ),
89cdf0e10cSrcweir aBtnMonth ( this, ScResId( BTN_MONTH ) ),
90cdf0e10cSrcweir aBtnYear ( this, ScResId( BTN_YEAR ) ),
91cdf0e10cSrcweir
92cdf0e10cSrcweir aBtnOk ( this, ScResId( BTN_OK ) ),
93cdf0e10cSrcweir aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
94cdf0e10cSrcweir aBtnHelp ( this, ScResId( BTN_HELP ) ),
95cdf0e10cSrcweir errMsgInvalidVal( ScResId( STR_VALERR ) ),
96cdf0e10cSrcweir rDoc ( rDocument ),
97cdf0e10cSrcweir theFillDir ( eFillDir ),
98cdf0e10cSrcweir theFillCmd ( eFillCmd ),
99cdf0e10cSrcweir theFillDateCmd ( eFillDateCmd ),
100cdf0e10cSrcweir fIncrement ( fStep ),
101cdf0e10cSrcweir fEndVal ( fMax )
102cdf0e10cSrcweir {
103cdf0e10cSrcweir Init( nPossDir );
104cdf0e10cSrcweir FreeResource();
105cdf0e10cSrcweir }
106cdf0e10cSrcweir
107cdf0e10cSrcweir
108cdf0e10cSrcweir //----------------------------------------------------------------------------
109cdf0e10cSrcweir
~ScFillSeriesDlg()110cdf0e10cSrcweir __EXPORT ScFillSeriesDlg::~ScFillSeriesDlg()
111cdf0e10cSrcweir {
112cdf0e10cSrcweir }
113cdf0e10cSrcweir
114cdf0e10cSrcweir //----------------------------------------------------------------------------
115cdf0e10cSrcweir
SetEdStartValEnabled(sal_Bool bFlag)116cdf0e10cSrcweir void ScFillSeriesDlg::SetEdStartValEnabled(sal_Bool bFlag)
117cdf0e10cSrcweir {
118cdf0e10cSrcweir bStartValFlag=bFlag;
119cdf0e10cSrcweir if(bFlag)
120cdf0e10cSrcweir {
121cdf0e10cSrcweir aFtStartVal.Enable();
122cdf0e10cSrcweir aEdStartVal.Enable();
123cdf0e10cSrcweir }
124cdf0e10cSrcweir else
125cdf0e10cSrcweir {
126cdf0e10cSrcweir aFtStartVal.Disable();
127cdf0e10cSrcweir aEdStartVal.Disable();
128cdf0e10cSrcweir }
129cdf0e10cSrcweir }
130cdf0e10cSrcweir
131cdf0e10cSrcweir //----------------------------------------------------------------------------
132cdf0e10cSrcweir
Init(sal_uInt16 nPossDir)133cdf0e10cSrcweir void ScFillSeriesDlg::Init( sal_uInt16 nPossDir )
134cdf0e10cSrcweir {
135cdf0e10cSrcweir aBtnOk.SetClickHdl ( LINK( this, ScFillSeriesDlg, OKHdl ) );
136cdf0e10cSrcweir aBtnArithmetic.SetClickHdl ( LINK( this, ScFillSeriesDlg, DisableHdl ) );
137cdf0e10cSrcweir aBtnGeometric.SetClickHdl ( LINK( this, ScFillSeriesDlg, DisableHdl ) );
138cdf0e10cSrcweir aBtnDate.SetClickHdl ( LINK( this, ScFillSeriesDlg, DisableHdl ) );
139cdf0e10cSrcweir aBtnAutoFill.SetClickHdl ( LINK( this, ScFillSeriesDlg, DisableHdl ) );
140cdf0e10cSrcweir
141cdf0e10cSrcweir if( nPossDir == FDS_OPT_NONE )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir aBtnLeft.Disable();
144cdf0e10cSrcweir aBtnRight.Disable();
145cdf0e10cSrcweir aBtnDown.Disable();
146cdf0e10cSrcweir aBtnUp.Disable();
147cdf0e10cSrcweir }
148cdf0e10cSrcweir
149cdf0e10cSrcweir if( nPossDir == FDS_OPT_HORZ )
150cdf0e10cSrcweir {
151cdf0e10cSrcweir aBtnDown.Disable();
152cdf0e10cSrcweir aBtnUp.Disable();
153cdf0e10cSrcweir }
154cdf0e10cSrcweir
155cdf0e10cSrcweir if( nPossDir == FDS_OPT_VERT )
156cdf0e10cSrcweir {
157cdf0e10cSrcweir aBtnLeft.Disable();
158cdf0e10cSrcweir aBtnRight.Disable();
159cdf0e10cSrcweir }
160cdf0e10cSrcweir
161cdf0e10cSrcweir switch ( theFillDir )
162cdf0e10cSrcweir {
163cdf0e10cSrcweir case FILL_TO_LEFT: aBtnLeft.Check(); break;
164cdf0e10cSrcweir case FILL_TO_RIGHT: aBtnRight.Check(); break;
165cdf0e10cSrcweir case FILL_TO_BOTTOM: aBtnDown.Check(); break;
166cdf0e10cSrcweir case FILL_TO_TOP: aBtnUp.Check(); break;
167cdf0e10cSrcweir default:
168cdf0e10cSrcweir break;
169cdf0e10cSrcweir }
170cdf0e10cSrcweir
171cdf0e10cSrcweir switch ( theFillCmd )
172cdf0e10cSrcweir {
173cdf0e10cSrcweir case FILL_LINEAR:
174cdf0e10cSrcweir aBtnArithmetic.Check();
175cdf0e10cSrcweir DisableHdl( &aBtnArithmetic );
176cdf0e10cSrcweir break;
177cdf0e10cSrcweir case FILL_GROWTH:
178cdf0e10cSrcweir aBtnGeometric.Check();
179cdf0e10cSrcweir DisableHdl( &aBtnGeometric );
180cdf0e10cSrcweir break;
181cdf0e10cSrcweir case FILL_DATE:
182cdf0e10cSrcweir aBtnDate.Check();
183cdf0e10cSrcweir DisableHdl( &aBtnDate );
184cdf0e10cSrcweir break;
185cdf0e10cSrcweir case FILL_AUTO:
186cdf0e10cSrcweir aBtnAutoFill.Check();
187cdf0e10cSrcweir DisableHdl( &aBtnAutoFill );
188cdf0e10cSrcweir break;
189cdf0e10cSrcweir default:
190cdf0e10cSrcweir break;
191cdf0e10cSrcweir }
192cdf0e10cSrcweir
193cdf0e10cSrcweir switch ( theFillDateCmd )
194cdf0e10cSrcweir {
195cdf0e10cSrcweir case FILL_DAY: aBtnDay.Check(); break;
196cdf0e10cSrcweir case FILL_WEEKDAY: aBtnDayOfWeek.Check(); break;
197cdf0e10cSrcweir case FILL_MONTH: aBtnMonth.Check(); break;
198cdf0e10cSrcweir case FILL_YEAR: aBtnYear.Check(); break;
199cdf0e10cSrcweir default:
200cdf0e10cSrcweir break;
201cdf0e10cSrcweir }
202cdf0e10cSrcweir
203cdf0e10cSrcweir fStartVal = MAXDOUBLE;
204cdf0e10cSrcweir /*
205cdf0e10cSrcweir String aStartTxt;
206cdf0e10cSrcweir if ( fStartVal != MAXDOUBLE )
207cdf0e10cSrcweir rDoc.GetFormatTable()->GetInputLineString( fStartVal, 0, aStartTxt );
208cdf0e10cSrcweir aEdStartVal.SetText( aStartTxt );
209cdf0e10cSrcweir */
210cdf0e10cSrcweir
211cdf0e10cSrcweir aEdStartVal.SetText( aStartStrVal);
212cdf0e10cSrcweir
213cdf0e10cSrcweir String aIncrTxt;
214cdf0e10cSrcweir rDoc.GetFormatTable()->GetInputLineString( fIncrement, 0, aIncrTxt );
215cdf0e10cSrcweir aEdIncrement.SetText( aIncrTxt );
216cdf0e10cSrcweir
217cdf0e10cSrcweir String aEndTxt;
218cdf0e10cSrcweir if ( fEndVal != MAXDOUBLE )
219cdf0e10cSrcweir rDoc.GetFormatTable()->GetInputLineString( fEndVal, 0, aEndTxt );
220cdf0e10cSrcweir aEdEndVal.SetText( aEndTxt );
221cdf0e10cSrcweir
222cdf0e10cSrcweir bStartValFlag=sal_False;
223cdf0e10cSrcweir
224cdf0e10cSrcweir aFlSep1.SetStyle( aFlSep1.GetStyle() | WB_VERT );
225cdf0e10cSrcweir aFlSep2.SetStyle( aFlSep2.GetStyle() | WB_VERT );
226cdf0e10cSrcweir }
227cdf0e10cSrcweir
228cdf0e10cSrcweir
229cdf0e10cSrcweir //----------------------------------------------------------------------------
230cdf0e10cSrcweir
CheckStartVal()231cdf0e10cSrcweir sal_Bool __EXPORT ScFillSeriesDlg::CheckStartVal()
232cdf0e10cSrcweir {
233cdf0e10cSrcweir sal_Bool bValOk = sal_False;
234cdf0e10cSrcweir sal_uInt32 nKey = 0;
235cdf0e10cSrcweir String aStr( aEdStartVal.GetText() );
236cdf0e10cSrcweir
237cdf0e10cSrcweir if ( aStr.Len() == 0 || aBtnAutoFill.IsChecked())
238cdf0e10cSrcweir {
239cdf0e10cSrcweir fStartVal = MAXDOUBLE;
240cdf0e10cSrcweir bValOk = sal_True;
241cdf0e10cSrcweir }
242cdf0e10cSrcweir else
243cdf0e10cSrcweir bValOk = rDoc.GetFormatTable()->IsNumberFormat( aStr, nKey, fStartVal );
244cdf0e10cSrcweir
245cdf0e10cSrcweir return bValOk;
246cdf0e10cSrcweir }
247cdf0e10cSrcweir
248cdf0e10cSrcweir
249cdf0e10cSrcweir //----------------------------------------------------------------------------
250cdf0e10cSrcweir
CheckIncrementVal()251cdf0e10cSrcweir sal_Bool __EXPORT ScFillSeriesDlg::CheckIncrementVal()
252cdf0e10cSrcweir {
253cdf0e10cSrcweir sal_uInt32 nKey = 0;
254cdf0e10cSrcweir String aStr( aEdIncrement.GetText() );
255cdf0e10cSrcweir
256cdf0e10cSrcweir return rDoc.GetFormatTable()->IsNumberFormat( aStr, nKey, fIncrement );
257cdf0e10cSrcweir }
258cdf0e10cSrcweir
259cdf0e10cSrcweir
260cdf0e10cSrcweir //----------------------------------------------------------------------------
261cdf0e10cSrcweir
CheckEndVal()262cdf0e10cSrcweir sal_Bool __EXPORT ScFillSeriesDlg::CheckEndVal()
263cdf0e10cSrcweir {
264cdf0e10cSrcweir sal_Bool bValOk = sal_False;
265cdf0e10cSrcweir sal_uInt32 nKey = 0;
266cdf0e10cSrcweir String aStr( aEdEndVal.GetText() );
267cdf0e10cSrcweir
268cdf0e10cSrcweir if ( aStr.Len() == 0 )
269cdf0e10cSrcweir {
270cdf0e10cSrcweir fEndVal = (fIncrement < 0) ? -MAXDOUBLE : MAXDOUBLE;
271cdf0e10cSrcweir bValOk = sal_True;
272cdf0e10cSrcweir }
273cdf0e10cSrcweir else
274cdf0e10cSrcweir bValOk = rDoc.GetFormatTable()->IsNumberFormat( aStr, nKey, fEndVal );
275cdf0e10cSrcweir
276cdf0e10cSrcweir return bValOk;
277cdf0e10cSrcweir }
278cdf0e10cSrcweir
279cdf0e10cSrcweir
280cdf0e10cSrcweir //----------------------------------------------------------------------------
281cdf0e10cSrcweir // Handler:
282cdf0e10cSrcweir //----------------------------------------------------------------------------
283cdf0e10cSrcweir
IMPL_LINK(ScFillSeriesDlg,DisableHdl,Button *,pBtn)284cdf0e10cSrcweir IMPL_LINK( ScFillSeriesDlg, DisableHdl, Button *, pBtn )
285cdf0e10cSrcweir {
286cdf0e10cSrcweir if ( pBtn == &aBtnDate )
287cdf0e10cSrcweir {
288cdf0e10cSrcweir aBtnDay.Enable();
289cdf0e10cSrcweir aBtnDayOfWeek.Enable();
290cdf0e10cSrcweir aBtnMonth.Enable();
291cdf0e10cSrcweir aBtnYear.Enable();
292cdf0e10cSrcweir aFlTimeUnit.Enable();
293cdf0e10cSrcweir }
294cdf0e10cSrcweir else
295cdf0e10cSrcweir {
296cdf0e10cSrcweir aBtnDay.Disable();
297cdf0e10cSrcweir aBtnDayOfWeek.Disable();
298cdf0e10cSrcweir aBtnMonth.Disable();
299cdf0e10cSrcweir aBtnYear.Disable();
300cdf0e10cSrcweir aFlTimeUnit.Disable();
301cdf0e10cSrcweir }
302cdf0e10cSrcweir
303cdf0e10cSrcweir if ( pBtn != &aBtnAutoFill )
304cdf0e10cSrcweir {
305cdf0e10cSrcweir aFtIncrement.Enable();
306cdf0e10cSrcweir aEdIncrement.Enable();
307cdf0e10cSrcweir aFtEndVal.Enable();
308cdf0e10cSrcweir aEdEndVal.Enable();
309cdf0e10cSrcweir }
310cdf0e10cSrcweir else
311cdf0e10cSrcweir {
312cdf0e10cSrcweir aFtIncrement.Disable();
313cdf0e10cSrcweir aEdIncrement.Disable();
314cdf0e10cSrcweir aFtEndVal.Disable();
315cdf0e10cSrcweir aEdEndVal.Disable();
316cdf0e10cSrcweir }
317cdf0e10cSrcweir return 0;
318cdf0e10cSrcweir }
319cdf0e10cSrcweir
320cdf0e10cSrcweir
321cdf0e10cSrcweir //----------------------------------------------------------------------------
322cdf0e10cSrcweir
IMPL_LINK(ScFillSeriesDlg,OKHdl,void *,EMPTYARG)323cdf0e10cSrcweir IMPL_LINK( ScFillSeriesDlg, OKHdl, void *, EMPTYARG )
324cdf0e10cSrcweir {
325cdf0e10cSrcweir if ( aBtnLeft.IsChecked() ) theFillDir = FILL_TO_LEFT;
326cdf0e10cSrcweir else if ( aBtnRight.IsChecked() ) theFillDir = FILL_TO_RIGHT;
327cdf0e10cSrcweir else if ( aBtnDown.IsChecked() ) theFillDir = FILL_TO_BOTTOM;
328cdf0e10cSrcweir else if ( aBtnUp.IsChecked() ) theFillDir = FILL_TO_TOP;
329cdf0e10cSrcweir
330cdf0e10cSrcweir if ( aBtnArithmetic.IsChecked() ) theFillCmd = FILL_LINEAR;
331cdf0e10cSrcweir else if ( aBtnGeometric.IsChecked() ) theFillCmd = FILL_GROWTH;
332cdf0e10cSrcweir else if ( aBtnDate.IsChecked() ) theFillCmd = FILL_DATE;
333cdf0e10cSrcweir else if ( aBtnAutoFill.IsChecked() ) theFillCmd = FILL_AUTO;
334cdf0e10cSrcweir
335cdf0e10cSrcweir if ( aBtnDay.IsChecked() ) theFillDateCmd = FILL_DAY;
336cdf0e10cSrcweir else if ( aBtnDayOfWeek.IsChecked() ) theFillDateCmd = FILL_WEEKDAY;
337cdf0e10cSrcweir else if ( aBtnMonth.IsChecked() ) theFillDateCmd = FILL_MONTH;
338cdf0e10cSrcweir else if ( aBtnYear.IsChecked() ) theFillDateCmd = FILL_YEAR;
339cdf0e10cSrcweir
340cdf0e10cSrcweir sal_Bool bAllOk = sal_True;
341cdf0e10cSrcweir Edit* pEdWrong = NULL;
342cdf0e10cSrcweir if ( !CheckStartVal() )
343cdf0e10cSrcweir {
344cdf0e10cSrcweir bAllOk = sal_False;
345cdf0e10cSrcweir pEdWrong = &aEdStartVal;
346cdf0e10cSrcweir }
347cdf0e10cSrcweir else if ( !CheckIncrementVal() )
348cdf0e10cSrcweir {
349cdf0e10cSrcweir bAllOk = sal_False;
350cdf0e10cSrcweir pEdWrong = &aEdIncrement;
351cdf0e10cSrcweir }
352cdf0e10cSrcweir else if ( !CheckEndVal() )
353cdf0e10cSrcweir {
354cdf0e10cSrcweir bAllOk = sal_False;
355cdf0e10cSrcweir pEdWrong = &aEdEndVal;
356cdf0e10cSrcweir }
357cdf0e10cSrcweir if ( bAllOk )
358cdf0e10cSrcweir EndDialog( RET_OK );
359cdf0e10cSrcweir else
360cdf0e10cSrcweir {
361cdf0e10cSrcweir ErrorBox( this,
362cdf0e10cSrcweir WinBits( WB_OK | WB_DEF_OK ),
363cdf0e10cSrcweir errMsgInvalidVal
364cdf0e10cSrcweir ).Execute();
365cdf0e10cSrcweir pEdWrong->GrabFocus();
366cdf0e10cSrcweir }
367cdf0e10cSrcweir
368cdf0e10cSrcweir return 0;
369cdf0e10cSrcweir }
370cdf0e10cSrcweir
371cdf0e10cSrcweir
372cdf0e10cSrcweir
373cdf0e10cSrcweir
374