1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: filldlg.cxx,v $
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>
44 #include "scresid.hxx"
45 #include "document.hxx"
46 #include "miscdlgs.hrc"
49 #include "filldlg.hxx"
54 //============================================================================
55 // class ScFillSeriesDlg
57 //----------------------------------------------------------------------------
59 ScFillSeriesDlg::ScFillSeriesDlg( Window
* pParent
,
60 ScDocument
& rDocument
,
63 FillDateCmd eFillDateCmd
,
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
) ),
102 theFillDir ( eFillDir
),
103 theFillCmd ( eFillCmd
),
104 theFillDateCmd ( eFillDateCmd
),
105 fIncrement ( fStep
),
113 //----------------------------------------------------------------------------
115 __EXPORT
ScFillSeriesDlg::~ScFillSeriesDlg()
119 //----------------------------------------------------------------------------
121 void ScFillSeriesDlg::SetEdStartValEnabled(BOOL bFlag
)
126 aFtStartVal
.Enable();
127 aEdStartVal
.Enable();
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
)
154 if( nPossDir
== FDS_OPT_HORZ
)
160 if( nPossDir
== FDS_OPT_VERT
)
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;
176 switch ( theFillCmd
)
179 aBtnArithmetic
.Check();
180 DisableHdl( &aBtnArithmetic
);
183 aBtnGeometric
.Check();
184 DisableHdl( &aBtnGeometric
);
188 DisableHdl( &aBtnDate
);
191 aBtnAutoFill
.Check();
192 DisableHdl( &aBtnAutoFill
);
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;
208 fStartVal
= MAXDOUBLE
;
211 if ( fStartVal != MAXDOUBLE )
212 rDoc.GetFormatTable()->GetInputLineString( fStartVal, 0, aStartTxt );
213 aEdStartVal.SetText( aStartTxt );
216 aEdStartVal
.SetText( aStartStrVal
);
219 rDoc
.GetFormatTable()->GetInputLineString( fIncrement
, 0, aIncrTxt
);
220 aEdIncrement
.SetText( aIncrTxt
);
223 if ( fEndVal
!= MAXDOUBLE
)
224 rDoc
.GetFormatTable()->GetInputLineString( fEndVal
, 0, aEndTxt
);
225 aEdEndVal
.SetText( aEndTxt
);
229 aFlSep1
.SetStyle( aFlSep1
.GetStyle() | WB_VERT
);
230 aFlSep2
.SetStyle( aFlSep2
.GetStyle() | WB_VERT
);
234 //----------------------------------------------------------------------------
236 BOOL __EXPORT
ScFillSeriesDlg::CheckStartVal()
240 String
aStr( aEdStartVal
.GetText() );
242 if ( aStr
.Len() == 0 || aBtnAutoFill
.IsChecked())
244 fStartVal
= MAXDOUBLE
;
248 bValOk
= rDoc
.GetFormatTable()->IsNumberFormat( aStr
, nKey
, fStartVal
);
254 //----------------------------------------------------------------------------
256 BOOL __EXPORT
ScFillSeriesDlg::CheckIncrementVal()
259 String
aStr( aEdIncrement
.GetText() );
261 return rDoc
.GetFormatTable()->IsNumberFormat( aStr
, nKey
, fIncrement
);
265 //----------------------------------------------------------------------------
267 BOOL __EXPORT
ScFillSeriesDlg::CheckEndVal()
271 String
aStr( aEdEndVal
.GetText() );
273 if ( aStr
.Len() == 0 )
275 fEndVal
= (fIncrement
< 0) ? -MAXDOUBLE
: MAXDOUBLE
;
279 bValOk
= rDoc
.GetFormatTable()->IsNumberFormat( aStr
, nKey
, fEndVal
);
285 //----------------------------------------------------------------------------
287 //----------------------------------------------------------------------------
289 IMPL_LINK( ScFillSeriesDlg
, DisableHdl
, Button
*, pBtn
)
291 if ( pBtn
== &aBtnDate
)
294 aBtnDayOfWeek
.Enable();
297 aFlTimeUnit
.Enable();
302 aBtnDayOfWeek
.Disable();
305 aFlTimeUnit
.Disable();
308 if ( pBtn
!= &aBtnAutoFill
)
310 aFtIncrement
.Enable();
311 aEdIncrement
.Enable();
317 aFtIncrement
.Disable();
318 aEdIncrement
.Disable();
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
;
346 Edit
* pEdWrong
= NULL
;
347 if ( !CheckStartVal() )
350 pEdWrong
= &aEdStartVal
;
352 else if ( !CheckIncrementVal() )
355 pEdWrong
= &aEdIncrement
;
357 else if ( !CheckEndVal() )
360 pEdWrong
= &aEdEndVal
;
367 WinBits( WB_OK
| WB_DEF_OK
),
370 pEdWrong
->GrabFocus();