Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #undef SC_DLLIMPLEMENTATION
31 : :
32 : :
33 : :
34 : : //----------------------------------------------------------------------------
35 : :
36 : : #include <svl/zforlist.hxx>
37 : : #include <vcl/msgbox.hxx>
38 : : #include <limits.h>
39 : :
40 : : #include "scresid.hxx"
41 : : #include "document.hxx"
42 : : #include "miscdlgs.hrc"
43 : :
44 : : #define _FILLDLG_CXX
45 : : #include "filldlg.hxx"
46 : : #undef _FILLDLG_CXX
47 : :
48 : :
49 : :
50 : : //============================================================================
51 : : // class ScFillSeriesDlg
52 : :
53 : : //----------------------------------------------------------------------------
54 : :
55 : 0 : ScFillSeriesDlg::ScFillSeriesDlg( Window* pParent,
56 : : ScDocument& rDocument,
57 : : FillDir eFillDir,
58 : : FillCmd eFillCmd,
59 : : FillDateCmd eFillDateCmd,
60 : : const rtl::OUString& aStartStr,
61 : : double fStep,
62 : : double fMax,
63 : : sal_uInt16 nPossDir )
64 : :
65 : : : ModalDialog ( pParent, ScResId( RID_SCDLG_FILLSERIES ) ),
66 : :
67 : : aFtStartVal ( this, ScResId( FT_START_VALUE ) ),
68 : : aEdStartVal ( this, ScResId( ED_START_VALUES ) ),
69 : : aStartStrVal ( aStartStr),
70 : :
71 : : aFtEndVal ( this, ScResId( FT_END_VALUE ) ),
72 : : aEdEndVal ( this, ScResId( ED_END_VALUES ) ),
73 : :
74 : : aFtIncrement ( this, ScResId( FT_INCREMENT ) ),
75 : : aEdIncrement ( this, ScResId( ED_INCREMENT ) ),
76 : :
77 : : aFlDirection ( this, ScResId( FL_DIRECTION ) ),
78 : : aBtnDown ( this, ScResId( BTN_BOTTOM ) ),
79 : : aBtnRight ( this, ScResId( BTN_RIGHT ) ),
80 : : aBtnUp ( this, ScResId( BTN_TOP ) ),
81 : : aBtnLeft ( this, ScResId( BTN_LEFT ) ),
82 : : aFlSep1 ( this, ScResId( FL_SEP1 ) ),
83 : : aFlType ( this, ScResId( FL_TYPE ) ),
84 : : aBtnArithmetic ( this, ScResId( BTN_ARITHMETIC ) ),
85 : : aBtnGeometric ( this, ScResId( BTN_GEOMETRIC ) ),
86 : : aBtnDate ( this, ScResId( BTN_DATE ) ),
87 : : aBtnAutoFill ( this, ScResId( BTN_AUTOFILL ) ),
88 : : aFlSep2 ( this, ScResId( FL_SEP2 ) ),
89 : : aFlTimeUnit ( this, ScResId( FL_TIME_UNIT ) ),
90 : : aBtnDay ( this, ScResId( BTN_DAY ) ),
91 : : aBtnDayOfWeek ( this, ScResId( BTN_DAY_OF_WEEK ) ),
92 : : aBtnMonth ( this, ScResId( BTN_MONTH ) ),
93 : : aBtnYear ( this, ScResId( BTN_YEAR ) ),
94 : :
95 : : aBtnOk ( this, ScResId( BTN_OK ) ),
96 : : aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
97 : : aBtnHelp ( this, ScResId( BTN_HELP ) ),
98 : : aErrMsgInvalidVal( SC_RESSTR(STR_VALERR) ),
99 : : rDoc ( rDocument ),
100 : : theFillDir ( eFillDir ),
101 : : theFillCmd ( eFillCmd ),
102 : : theFillDateCmd ( eFillDateCmd ),
103 : : fIncrement ( fStep ),
104 : 0 : fEndVal ( fMax )
105 : : {
106 : 0 : Init( nPossDir );
107 : 0 : FreeResource();
108 : 0 : }
109 : :
110 : :
111 : : //----------------------------------------------------------------------------
112 : :
113 : 0 : ScFillSeriesDlg::~ScFillSeriesDlg()
114 : : {
115 : 0 : }
116 : :
117 : : //----------------------------------------------------------------------------
118 : :
119 : 0 : void ScFillSeriesDlg::SetEdStartValEnabled(bool bFlag)
120 : : {
121 : 0 : bStartValFlag=bFlag;
122 : 0 : if(bFlag)
123 : : {
124 : 0 : aFtStartVal.Enable();
125 : 0 : aEdStartVal.Enable();
126 : : }
127 : : else
128 : : {
129 : 0 : aFtStartVal.Disable();
130 : 0 : aEdStartVal.Disable();
131 : : }
132 : 0 : }
133 : :
134 : : //----------------------------------------------------------------------------
135 : :
136 : 0 : void ScFillSeriesDlg::Init( sal_uInt16 nPossDir )
137 : : {
138 : 0 : aBtnOk.SetClickHdl ( LINK( this, ScFillSeriesDlg, OKHdl ) );
139 : 0 : aBtnArithmetic.SetClickHdl ( LINK( this, ScFillSeriesDlg, DisableHdl ) );
140 : 0 : aBtnGeometric.SetClickHdl ( LINK( this, ScFillSeriesDlg, DisableHdl ) );
141 : 0 : aBtnDate.SetClickHdl ( LINK( this, ScFillSeriesDlg, DisableHdl ) );
142 : 0 : aBtnAutoFill.SetClickHdl ( LINK( this, ScFillSeriesDlg, DisableHdl ) );
143 : :
144 : 0 : if( nPossDir == FDS_OPT_NONE )
145 : : {
146 : 0 : aBtnLeft.Disable();
147 : 0 : aBtnRight.Disable();
148 : 0 : aBtnDown.Disable();
149 : 0 : aBtnUp.Disable();
150 : : }
151 : :
152 : 0 : if( nPossDir == FDS_OPT_HORZ )
153 : : {
154 : 0 : aBtnDown.Disable();
155 : 0 : aBtnUp.Disable();
156 : : }
157 : :
158 : 0 : if( nPossDir == FDS_OPT_VERT )
159 : : {
160 : 0 : aBtnLeft.Disable();
161 : 0 : aBtnRight.Disable();
162 : : }
163 : :
164 : 0 : switch ( theFillDir )
165 : : {
166 : 0 : case FILL_TO_LEFT: aBtnLeft.Check(); break;
167 : 0 : case FILL_TO_RIGHT: aBtnRight.Check(); break;
168 : 0 : case FILL_TO_BOTTOM: aBtnDown.Check(); break;
169 : 0 : case FILL_TO_TOP: aBtnUp.Check(); break;
170 : : default:
171 : 0 : break;
172 : : }
173 : :
174 : 0 : switch ( theFillCmd )
175 : : {
176 : : case FILL_LINEAR:
177 : 0 : aBtnArithmetic.Check();
178 : 0 : DisableHdl( &aBtnArithmetic );
179 : 0 : break;
180 : : case FILL_GROWTH:
181 : 0 : aBtnGeometric.Check();
182 : 0 : DisableHdl( &aBtnGeometric );
183 : 0 : break;
184 : : case FILL_DATE:
185 : 0 : aBtnDate.Check();
186 : 0 : DisableHdl( &aBtnDate );
187 : 0 : break;
188 : : case FILL_AUTO:
189 : 0 : aBtnAutoFill.Check();
190 : 0 : DisableHdl( &aBtnAutoFill );
191 : 0 : break;
192 : : default:
193 : 0 : break;
194 : : }
195 : :
196 : 0 : switch ( theFillDateCmd )
197 : : {
198 : 0 : case FILL_DAY: aBtnDay.Check(); break;
199 : 0 : case FILL_WEEKDAY: aBtnDayOfWeek.Check(); break;
200 : 0 : case FILL_MONTH: aBtnMonth.Check(); break;
201 : 0 : case FILL_YEAR: aBtnYear.Check(); break;
202 : : default:
203 : 0 : break;
204 : : }
205 : :
206 : 0 : fStartVal = MAXDOUBLE;
207 : :
208 : 0 : aEdStartVal.SetText( aStartStrVal);
209 : :
210 : 0 : String aIncrTxt;
211 : 0 : rDoc.GetFormatTable()->GetInputLineString( fIncrement, 0, aIncrTxt );
212 : 0 : aEdIncrement.SetText( aIncrTxt );
213 : :
214 : 0 : String aEndTxt;
215 : 0 : if ( fEndVal != MAXDOUBLE )
216 : 0 : rDoc.GetFormatTable()->GetInputLineString( fEndVal, 0, aEndTxt );
217 : 0 : aEdEndVal.SetText( aEndTxt );
218 : :
219 : 0 : bStartValFlag = false;
220 : :
221 : 0 : aFlSep1.SetStyle( aFlSep1.GetStyle() | WB_VERT );
222 : 0 : aFlSep2.SetStyle( aFlSep2.GetStyle() | WB_VERT );
223 : 0 : }
224 : :
225 : :
226 : : //----------------------------------------------------------------------------
227 : :
228 : 0 : bool ScFillSeriesDlg::CheckStartVal()
229 : : {
230 : 0 : bool bValOk = false;
231 : 0 : rtl::OUString aStr = aEdStartVal.GetText();
232 : :
233 : 0 : if ( aStr.isEmpty() || aBtnAutoFill.IsChecked())
234 : : {
235 : 0 : fStartVal = MAXDOUBLE;
236 : 0 : bValOk = true;
237 : : }
238 : : else
239 : : {
240 : 0 : sal_uInt32 nKey = 0;
241 : 0 : bValOk = rDoc.GetFormatTable()->IsNumberFormat( aStr, nKey, fStartVal );
242 : : }
243 : 0 : return bValOk;
244 : : }
245 : :
246 : :
247 : : //----------------------------------------------------------------------------
248 : :
249 : 0 : bool ScFillSeriesDlg::CheckIncrementVal()
250 : : {
251 : 0 : sal_uInt32 nKey = 0;
252 : 0 : rtl::OUString aStr = aEdIncrement.GetText();
253 : :
254 : 0 : return rDoc.GetFormatTable()->IsNumberFormat( aStr, nKey, fIncrement );
255 : : }
256 : :
257 : :
258 : : //----------------------------------------------------------------------------
259 : :
260 : 0 : bool ScFillSeriesDlg::CheckEndVal()
261 : : {
262 : 0 : bool bValOk = false;
263 : 0 : rtl::OUString aStr = aEdEndVal.GetText();
264 : :
265 : 0 : if (aStr.isEmpty())
266 : : {
267 : 0 : fEndVal = (fIncrement < 0) ? -MAXDOUBLE : MAXDOUBLE;
268 : 0 : bValOk = true;
269 : : }
270 : : else
271 : : {
272 : 0 : sal_uInt32 nKey = 0;
273 : 0 : bValOk = rDoc.GetFormatTable()->IsNumberFormat( aStr, nKey, fEndVal );
274 : : }
275 : 0 : return bValOk;
276 : : }
277 : :
278 : :
279 : : //----------------------------------------------------------------------------
280 : : // Handler:
281 : : //----------------------------------------------------------------------------
282 : :
283 : 0 : IMPL_LINK( ScFillSeriesDlg, DisableHdl, Button *, pBtn )
284 : : {
285 : 0 : if ( pBtn == &aBtnDate )
286 : : {
287 : 0 : aBtnDay.Enable();
288 : 0 : aBtnDayOfWeek.Enable();
289 : 0 : aBtnMonth.Enable();
290 : 0 : aBtnYear.Enable();
291 : 0 : aFlTimeUnit.Enable();
292 : : }
293 : : else
294 : : {
295 : 0 : aBtnDay.Disable();
296 : 0 : aBtnDayOfWeek.Disable();
297 : 0 : aBtnMonth.Disable();
298 : 0 : aBtnYear.Disable();
299 : 0 : aFlTimeUnit.Disable();
300 : : }
301 : :
302 : 0 : if ( pBtn != &aBtnAutoFill )
303 : : {
304 : 0 : aFtIncrement.Enable();
305 : 0 : aEdIncrement.Enable();
306 : 0 : aFtEndVal.Enable();
307 : 0 : aEdEndVal.Enable();
308 : : }
309 : : else
310 : : {
311 : 0 : aFtIncrement.Disable();
312 : 0 : aEdIncrement.Disable();
313 : 0 : aFtEndVal.Disable();
314 : 0 : aEdEndVal.Disable();
315 : : }
316 : 0 : return 0;
317 : : }
318 : :
319 : :
320 : : //----------------------------------------------------------------------------
321 : :
322 : 0 : IMPL_LINK_NOARG(ScFillSeriesDlg, OKHdl)
323 : : {
324 : 0 : if ( aBtnLeft.IsChecked() ) theFillDir = FILL_TO_LEFT;
325 : 0 : else if ( aBtnRight.IsChecked() ) theFillDir = FILL_TO_RIGHT;
326 : 0 : else if ( aBtnDown.IsChecked() ) theFillDir = FILL_TO_BOTTOM;
327 : 0 : else if ( aBtnUp.IsChecked() ) theFillDir = FILL_TO_TOP;
328 : :
329 : 0 : if ( aBtnArithmetic.IsChecked() ) theFillCmd = FILL_LINEAR;
330 : 0 : else if ( aBtnGeometric.IsChecked() ) theFillCmd = FILL_GROWTH;
331 : 0 : else if ( aBtnDate.IsChecked() ) theFillCmd = FILL_DATE;
332 : 0 : else if ( aBtnAutoFill.IsChecked() ) theFillCmd = FILL_AUTO;
333 : :
334 : 0 : if ( aBtnDay.IsChecked() ) theFillDateCmd = FILL_DAY;
335 : 0 : else if ( aBtnDayOfWeek.IsChecked() ) theFillDateCmd = FILL_WEEKDAY;
336 : 0 : else if ( aBtnMonth.IsChecked() ) theFillDateCmd = FILL_MONTH;
337 : 0 : else if ( aBtnYear.IsChecked() ) theFillDateCmd = FILL_YEAR;
338 : :
339 : 0 : sal_Bool bAllOk = true;
340 : 0 : Edit* pEdWrong = NULL;
341 : 0 : if ( !CheckStartVal() )
342 : : {
343 : 0 : bAllOk = false;
344 : 0 : pEdWrong = &aEdStartVal;
345 : : }
346 : 0 : else if ( !CheckIncrementVal() )
347 : : {
348 : 0 : bAllOk = false;
349 : 0 : pEdWrong = &aEdIncrement;
350 : : }
351 : 0 : else if ( !CheckEndVal() )
352 : : {
353 : 0 : bAllOk = false;
354 : 0 : pEdWrong = &aEdEndVal;
355 : : }
356 : 0 : if ( bAllOk )
357 : 0 : EndDialog( RET_OK );
358 : : else
359 : : {
360 : : ErrorBox( this,
361 : : WinBits( WB_OK | WB_DEF_OK ),
362 : : aErrMsgInvalidVal
363 : 0 : ).Execute();
364 : 0 : pEdWrong->GrabFocus();
365 : : }
366 : :
367 : 0 : return 0;
368 : : }
369 : :
370 : :
371 : :
372 : :
373 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|