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