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