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