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