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 #ifndef _SV_FIELD_HXX 25 #define _SV_FIELD_HXX 26 27 #include <vcl/dllapi.h> 28 #include <tools/link.hxx> 29 #include <tools/date.hxx> 30 #include <tools/time.hxx> 31 #include <vcl/spinfld.hxx> 32 #include <vcl/combobox.hxx> 33 #include <tools/fldunit.hxx> 34 35 namespace com { namespace sun { namespace star { namespace lang { struct Locale; } } } } 36 37 class CalendarWrapper; 38 class LocaleDataWrapper; 39 40 // ----------------- 41 // - FormatterBase - 42 // ----------------- 43 44 class VCL_DLLPUBLIC FormatterBase 45 { 46 private: 47 Edit* mpField; 48 LocaleDataWrapper* mpLocaleDataWrapper; 49 Link maErrorLink; 50 sal_Bool mbReformat; 51 sal_Bool mbStrictFormat; 52 sal_Bool mbEmptyFieldValue; 53 sal_Bool mbEmptyFieldValueEnabled; 54 sal_Bool mbDefaultLocale; 55 56 protected: 57 SAL_DLLPRIVATE void ImplSetText( const XubString& rText, Selection* pNewSel = NULL ); ImplGetEmptyFieldValue() const58 SAL_DLLPRIVATE sal_Bool ImplGetEmptyFieldValue() const { return mbEmptyFieldValue; } 59 60 void SetFieldText( const XubString& rText, sal_Bool bKeepSelection ); SetEmptyFieldValueData(sal_Bool bValue)61 void SetEmptyFieldValueData( sal_Bool bValue ) { mbEmptyFieldValue = bValue; } 62 63 SAL_DLLPRIVATE LocaleDataWrapper& ImplGetLocaleDataWrapper() const; IsDefaultLocale() const64 sal_Bool IsDefaultLocale() const { return mbDefaultLocale; } 65 66 public: 67 explicit FormatterBase( Edit* pField = NULL ); 68 virtual ~FormatterBase(); 69 70 const LocaleDataWrapper& GetLocaleDataWrapper() const; 71 SetField(Edit * pField)72 void SetField( Edit* pField ) { mpField = pField; } GetField() const73 Edit* GetField() const { return mpField; } 74 MustBeReformatted() const75 sal_Bool MustBeReformatted() const { return mbReformat; } MarkToBeReformatted(sal_Bool b)76 void MarkToBeReformatted( sal_Bool b ) { mbReformat = b; } 77 78 void SetStrictFormat( sal_Bool bStrict ); IsStrictFormat() const79 sal_Bool IsStrictFormat() const { return mbStrictFormat; } 80 81 virtual void Reformat(); 82 virtual void ReformatAll(); 83 84 virtual void SetLocale( const ::com::sun::star::lang::Locale& rLocale ); 85 const ::com::sun::star::lang::Locale& GetLocale() const; 86 87 const AllSettings& GetFieldSettings() const; 88 SetErrorHdl(const Link & rLink)89 void SetErrorHdl( const Link& rLink ) { maErrorLink = rLink; } GetErrorHdl() const90 const Link& GetErrorHdl() const { return maErrorLink; } 91 92 void SetEmptyFieldValue(); 93 sal_Bool IsEmptyFieldValue() const; 94 EnableEmptyFieldValue(sal_Bool bEnable)95 void EnableEmptyFieldValue( sal_Bool bEnable ) { mbEmptyFieldValueEnabled = bEnable; } IsEmptyFieldValueEnabled() const96 sal_Bool IsEmptyFieldValueEnabled() const { return mbEmptyFieldValueEnabled; } 97 }; 98 99 100 // -------------------- 101 // - PatternFormatter - 102 // -------------------- 103 104 #define PATTERN_FORMAT_EMPTYLITERALS ((sal_uInt16)0x0001) 105 106 class VCL_DLLPUBLIC PatternFormatter : public FormatterBase 107 { 108 private: 109 ByteString maEditMask; 110 XubString maFieldString; 111 XubString maLiteralMask; 112 sal_uInt16 mnFormatFlags; 113 sal_Bool mbSameMask; 114 sal_Bool mbInPattKeyInput; 115 116 protected: 117 PatternFormatter(); 118 119 SAL_DLLPRIVATE void ImplLoadRes( const ResId& rResId ); 120 SAL_DLLPRIVATE void ImplSetMask( const ByteString& rEditMask, const XubString& rLiteralMask ); ImplIsSameMask() const121 SAL_DLLPRIVATE sal_Bool ImplIsSameMask() const { return mbSameMask; } ImplGetInPattKeyInput()122 SAL_DLLPRIVATE sal_Bool& ImplGetInPattKeyInput() { return mbInPattKeyInput; } 123 124 public: 125 ~PatternFormatter(); 126 127 virtual void Reformat(); 128 129 void SetMask( const ByteString& rEditMask, 130 const XubString& rLiteralMask ); GetEditMask() const131 const ByteString& GetEditMask() const { return maEditMask; } GetLiteralMask() const132 const XubString& GetLiteralMask() const { return maLiteralMask; } 133 SetFormatFlags(sal_uInt16 nFlags)134 void SetFormatFlags( sal_uInt16 nFlags ) { mnFormatFlags = nFlags; } GetFormatFlags() const135 sal_uInt16 GetFormatFlags() const { return mnFormatFlags; } 136 137 void SetString( const XubString& rStr ); 138 XubString GetString() const; IsStringModified() const139 sal_Bool IsStringModified() const { return !(GetString().Equals( maFieldString )); } 140 141 void SelectFixedFont(); 142 }; 143 144 // -------------------- 145 // - NumericFormatter - 146 // -------------------- 147 148 class VCL_DLLPUBLIC NumericFormatter : public FormatterBase 149 { 150 private: 151 SAL_DLLPRIVATE void ImplInit(); 152 153 protected: 154 sal_Int64 mnFieldValue; 155 sal_Int64 mnLastValue; 156 sal_Int64 mnMin; 157 sal_Int64 mnMax; 158 sal_Int64 mnCorrectedValue; 159 sal_uInt16 mnType; 160 sal_uInt16 mnDecimalDigits; 161 sal_Bool mbThousandSep; 162 sal_Bool mbShowTrailingZeros; 163 164 // the members below are used in all derivatives of NumericFormatter 165 // not in NumericFormatter itself. 166 sal_Int64 mnSpinSize; 167 sal_Int64 mnFirst; 168 sal_Int64 mnLast; 169 170 protected: 171 NumericFormatter(); 172 173 virtual XubString CreateFieldText( sal_Int64 nValue ) const; 174 175 void FieldUp(); 176 void FieldDown(); 177 void FieldFirst(); 178 void FieldLast(); 179 180 SAL_DLLPRIVATE void ImplLoadRes( const ResId& rResId ); 181 SAL_DLLPRIVATE sal_Bool ImplNumericReformat( const XubString& rStr, double& rValue, XubString& rOutStr ); 182 SAL_DLLPRIVATE void ImplNewFieldValue( sal_Int64 nNewValue ); 183 SAL_DLLPRIVATE void ImplSetUserValue( sal_Int64 nNewValue, Selection* pNewSelection = NULL ); 184 185 public: 186 ~NumericFormatter(); 187 188 virtual void Reformat(); 189 190 void SetMin( sal_Int64 nNewMin ); GetMin() const191 sal_Int64 GetMin() const { return mnMin; } 192 void SetMax( sal_Int64 nNewMax ); GetMax() const193 sal_Int64 GetMax() const { return mnMax; } 194 SetFirst(sal_Int64 nNewFirst)195 void SetFirst( sal_Int64 nNewFirst ) { mnFirst = nNewFirst; } GetFirst() const196 sal_Int64 GetFirst() const { return mnFirst; } SetLast(sal_Int64 nNewLast)197 void SetLast( sal_Int64 nNewLast ) { mnLast = nNewLast; } GetLast() const198 sal_Int64 GetLast() const { return mnLast; } SetSpinSize(sal_Int64 nNewSize)199 void SetSpinSize( sal_Int64 nNewSize ) { mnSpinSize = nNewSize; } GetSpinSize() const200 sal_Int64 GetSpinSize() const { return mnSpinSize; } 201 202 void SetDecimalDigits( sal_uInt16 nDigits ); 203 sal_uInt16 GetDecimalDigits() const; 204 205 void SetUseThousandSep( sal_Bool b ); IsUseThousandSep() const206 sal_Bool IsUseThousandSep() const { return mbThousandSep; } 207 208 void SetShowTrailingZeros( sal_Bool bShowTrailingZeros ); IsShowTrailingZeros() const209 sal_Bool IsShowTrailingZeros() const { return mbShowTrailingZeros; } 210 211 212 void SetUserValue( sal_Int64 nNewValue ); 213 virtual void SetValue( sal_Int64 nNewValue ); 214 virtual sal_Int64 GetValue() const; 215 sal_Bool IsValueModified() const; GetCorrectedValue() const216 sal_Int64 GetCorrectedValue() const { return mnCorrectedValue; } 217 218 Fraction ConvertToFraction( sal_Int64 nValue ); 219 sal_Int64 ConvertToLong( const Fraction& rValue ); 220 sal_Int64 Normalize( sal_Int64 nValue ) const; 221 sal_Int64 Denormalize( sal_Int64 nValue ) const; 222 }; 223 224 // ------------------- 225 // - MetricFormatter - 226 // ------------------- 227 228 class VCL_DLLPUBLIC MetricFormatter : public NumericFormatter 229 { 230 private: 231 SAL_DLLPRIVATE void ImplInit(); 232 233 protected: 234 XubString maCustomUnitText; 235 XubString maCurUnitText; 236 sal_Int64 mnBaseValue; 237 FieldUnit meUnit; 238 Link maCustomConvertLink; 239 240 protected: 241 MetricFormatter(); 242 243 virtual XubString CreateFieldText( sal_Int64 nValue ) const; 244 245 SAL_DLLPRIVATE void ImplLoadRes( const ResId& rResId ); 246 SAL_DLLPRIVATE sal_Bool ImplMetricReformat( const XubString& rStr, double& rValue, XubString& rOutStr ); 247 248 public: 249 ~MetricFormatter(); 250 251 virtual void CustomConvert() = 0; 252 virtual void Reformat(); 253 254 void SetUnit( FieldUnit meUnit ); GetUnit() const255 FieldUnit GetUnit() const { return meUnit; } 256 void SetCustomUnitText( const XubString& rStr ); GetCustomUnitText() const257 const XubString& GetCustomUnitText() const { return maCustomUnitText; } GetCurUnitText() const258 const XubString& GetCurUnitText() const { return maCurUnitText; } 259 260 using NumericFormatter::SetMax; 261 void SetMax( sal_Int64 nNewMax, FieldUnit eInUnit ); 262 using NumericFormatter::GetMax; 263 sal_Int64 GetMax( FieldUnit eOutUnit ) const; 264 using NumericFormatter::SetMin; 265 void SetMin( sal_Int64 nNewMin, FieldUnit eInUnit ); 266 using NumericFormatter::GetMin; 267 sal_Int64 GetMin( FieldUnit eOutUnit ) const; 268 void SetBaseValue( sal_Int64 nNewBase, FieldUnit eInUnit = FUNIT_NONE ); 269 sal_Int64 GetBaseValue( FieldUnit eOutUnit = FUNIT_NONE ) const; 270 271 virtual void SetValue( sal_Int64 nNewValue, FieldUnit eInUnit ); 272 virtual void SetValue( sal_Int64 nValue ); 273 using NumericFormatter::SetUserValue; 274 void SetUserValue( sal_Int64 nNewValue, FieldUnit eInUnit ); 275 virtual sal_Int64 GetValue( FieldUnit eOutUnit ) const; 276 virtual sal_Int64 GetValue() const; 277 using NumericFormatter::GetCorrectedValue; 278 sal_Int64 GetCorrectedValue( FieldUnit eOutUnit ) const; 279 SetCustomConvertHdl(const Link & rLink)280 void SetCustomConvertHdl( const Link& rLink ) { maCustomConvertLink = rLink; } GetCustomConvertHdl() const281 const Link& GetCustomConvertHdl() const { return maCustomConvertLink; } 282 }; 283 284 285 // --------------------- 286 // - CurrencyFormatter - 287 // --------------------- 288 289 class VCL_DLLPUBLIC CurrencyFormatter : public NumericFormatter 290 { 291 private: 292 String maCurrencySymbol; 293 294 SAL_DLLPRIVATE void ImplInit(); 295 296 protected: 297 CurrencyFormatter(); 298 virtual XubString CreateFieldText( sal_Int64 nValue ) const; 299 SAL_DLLPRIVATE sal_Bool ImplCurrencyReformat( const XubString& rStr, XubString& rOutStr ); 300 301 public: 302 ~CurrencyFormatter(); 303 304 virtual void Reformat(); 305 306 void SetCurrencySymbol( const String& rStr ); 307 String GetCurrencySymbol() const; 308 309 virtual void SetValue( sal_Int64 nNewValue ); 310 virtual sal_Int64 GetValue() const; 311 }; 312 313 314 // ----------------- 315 // - DateFormatter - 316 // ----------------- 317 318 class VCL_DLLPUBLIC DateFormatter : public FormatterBase 319 { 320 private: 321 CalendarWrapper* mpCalendarWrapper; 322 Date maFieldDate; 323 Date maLastDate; 324 Date maMin; 325 Date maMax; 326 Date maCorrectedDate; 327 sal_Bool mbLongFormat; 328 sal_Bool mbEmptyDate; 329 sal_Bool mbShowDateCentury; 330 sal_uInt16 mnDateFormat; 331 sal_uLong mnExtDateFormat; 332 sal_Bool mbEnforceValidValue; 333 334 SAL_DLLPRIVATE void ImplInit(); 335 336 protected: 337 DateFormatter(); 338 339 SAL_DLLPRIVATE void ImplLoadRes( const ResId& rResId ); ImplGetFieldDate() const340 SAL_DLLPRIVATE const Date& ImplGetFieldDate() const { return maFieldDate; } 341 SAL_DLLPRIVATE sal_Bool ImplDateReformat( const XubString& rStr, XubString& rOutStr, 342 const AllSettings& rSettings ); 343 SAL_DLLPRIVATE void ImplSetUserDate( const Date& rNewDate, 344 Selection* pNewSelection = NULL ); 345 SAL_DLLPRIVATE XubString ImplGetDateAsText( const Date& rDate, 346 const AllSettings& rSettings ) const; 347 SAL_DLLPRIVATE void ImplNewFieldValue( const Date& rDate ); 348 CalendarWrapper& GetCalendarWrapper() const; 349 350 SAL_DLLPRIVATE sal_Bool ImplAllowMalformedInput() const; 351 352 public: 353 ~DateFormatter(); 354 355 virtual void Reformat(); 356 virtual void ReformatAll(); 357 358 virtual void SetLocale( const ::com::sun::star::lang::Locale& rLocale ); 359 360 361 void SetExtDateFormat( ExtDateFieldFormat eFormat ); 362 ExtDateFieldFormat GetExtDateFormat( sal_Bool bResolveSystemFormat = sal_False ) const; 363 364 void SetMin( const Date& rNewMin ); GetMin() const365 const Date& GetMin() const { return maMin; } 366 367 void SetMax( const Date& rNewMax ); GetMax() const368 const Date& GetMax() const { return maMax; } 369 370 371 // -------------------------------------------------------------- 372 // MT: Remove these methods too, ExtDateFormat should be enough! 373 // What should happen if using DDMMYYYY, but ShowCentury=sal_False? 374 // -------------------------------------------------------------- 375 void SetLongFormat( sal_Bool bLong ); IsLongFormat() const376 sal_Bool IsLongFormat() const { return mbLongFormat; } 377 void SetShowDateCentury( sal_Bool bShowCentury ); IsShowDateCentury() const378 sal_Bool IsShowDateCentury() const { return mbShowDateCentury; } 379 // -------------------------------------------------------------- 380 381 void SetDate( const Date& rNewDate ); 382 void SetUserDate( const Date& rNewDate ); 383 Date GetDate() const; 384 Date GetRealDate() const; 385 sal_Bool IsDateModified() const; 386 void SetEmptyDate(); 387 sal_Bool IsEmptyDate() const; GetCorrectedDate() const388 Date GetCorrectedDate() const { return maCorrectedDate; } 389 ResetLastDate()390 void ResetLastDate() { maLastDate = Date( 0, 0, 0 ); } 391 392 static void ExpandCentury( Date& rDate ); 393 static void ExpandCentury( Date& rDate, sal_uInt16 nTwoDigitYearStart ); 394 GetInvalidDate()395 static Date GetInvalidDate() { return Date( 0, 0, 0 ); } 396 397 /** enables or disables the enforcement of valid values 398 399 If this is set to <TRUE/> (which is the default), then GetDate will always return a valid 400 date, no matter whether the current text can really be interpreted as date. (Note: this 401 is the compatible behaviour). 402 403 If this is set to <FALSE/>, the GetDate will return GetInvalidDate, in case the current text 404 cannot be interpreted as date. 405 406 In addition, if this is set to <FALSE/>, the text in the field will <em>not</em> be corrected 407 when the control loses the focus - instead, the invalid input will be preserved. 408 */ EnforceValidValue(sal_Bool _bEnforce)409 void EnforceValidValue( sal_Bool _bEnforce ) { mbEnforceValidValue = _bEnforce; } IsEnforceValidValue() const410 inline sal_Bool IsEnforceValidValue( ) const { return mbEnforceValidValue; } 411 }; 412 413 414 // ----------------- 415 // - TimeFormatter - 416 // ----------------- 417 418 class VCL_DLLPUBLIC TimeFormatter : public FormatterBase 419 { 420 private: 421 Time maLastTime; 422 Time maMin; 423 Time maMax; 424 Time maCorrectedTime; 425 TimeFieldFormat meFormat; 426 sal_uInt16 mnTimeFormat; 427 sal_Bool mbDuration; 428 sal_Bool mbEmptyTime; 429 sal_Bool mbEnforceValidValue; 430 431 SAL_DLLPRIVATE void ImplInit(); 432 433 protected: 434 Time maFieldTime; 435 436 TimeFormatter(); 437 438 SAL_DLLPRIVATE void ImplLoadRes( const ResId& rResId ); 439 SAL_DLLPRIVATE sal_Bool ImplTimeReformat( const XubString& rStr, XubString& rOutStr ); 440 SAL_DLLPRIVATE void ImplNewFieldValue( const Time& rTime ); 441 SAL_DLLPRIVATE void ImplSetUserTime( const Time& rNewTime, Selection* pNewSelection = NULL ); 442 SAL_DLLPRIVATE sal_Bool ImplAllowMalformedInput() const; 443 444 public: 445 446 enum TimeFormat { 447 HOUR_12, 448 HOUR_24 449 }; 450 451 ~TimeFormatter(); 452 453 virtual void Reformat(); 454 virtual void ReformatAll(); 455 456 void SetMin( const Time& rNewMin ); GetMin() const457 const Time& GetMin() const { return maMin; } 458 void SetMax( const Time& rNewMax ); GetMax() const459 const Time& GetMax() const { return maMax; } 460 461 void SetTimeFormat( TimeFormat eNewFormat ); 462 TimeFormat GetTimeFormat() const; 463 464 void SetFormat( TimeFieldFormat eNewFormat ); GetFormat() const465 TimeFieldFormat GetFormat() const { return meFormat; } 466 467 void SetDuration( sal_Bool mbDuration ); IsDuration() const468 sal_Bool IsDuration() const { return mbDuration; } 469 470 void SetTime( const Time& rNewTime ); 471 void SetUserTime( const Time& rNewTime ); 472 Time GetTime() const; 473 Time GetRealTime() const; 474 sal_Bool IsTimeModified() const; SetEmptyTime()475 void SetEmptyTime() { FormatterBase::SetEmptyFieldValue(); } IsEmptyTime() const476 sal_Bool IsEmptyTime() const { return FormatterBase::IsEmptyFieldValue(); } GetCorrectedTime() const477 Time GetCorrectedTime() const { return maCorrectedTime; } 478 GetInvalidTime()479 static Time GetInvalidTime() { return Time( 99, 99, 99 ); } 480 481 /** enables or disables the enforcement of valid values 482 483 If this is set to <TRUE/> (which is the default), then GetTime will always return a valid 484 time, no matter whether the current text can really be interpreted as time. (Note: this 485 is the compatible behaviour). 486 487 If this is set to <FALSE/>, the GetTime will return GetInvalidTime, in case the current text 488 cannot be interpreted as time. 489 490 In addition, if this is set to <FALSE/>, the text in the field will <em>not</em> be corrected 491 when the control loses the focus - instead, the invalid input will be preserved. 492 */ EnforceValidValue(sal_Bool _bEnforce)493 void EnforceValidValue( sal_Bool _bEnforce ) { mbEnforceValidValue = _bEnforce; } IsEnforceValidValue() const494 inline sal_Bool IsEnforceValidValue( ) const { return mbEnforceValidValue; } 495 }; 496 497 498 // ---------------- 499 // - PatternField - 500 // ---------------- 501 502 class VCL_DLLPUBLIC PatternField : public SpinField, public PatternFormatter 503 { 504 public: 505 explicit PatternField( Window* pParent, WinBits nWinStyle ); 506 explicit PatternField( Window* pParent, const ResId& ); 507 virtual ~PatternField(); 508 509 virtual long PreNotify( NotifyEvent& rNEvt ); 510 virtual long Notify( NotifyEvent& rNEvt ); 511 virtual void Modify(); 512 }; 513 514 515 // ---------------- 516 // - NumericField - 517 // ---------------- 518 519 class VCL_DLLPUBLIC NumericField : public SpinField, public NumericFormatter 520 { 521 protected: 522 SAL_DLLPRIVATE void ImplLoadRes( const ResId& rResId ); 523 524 public: 525 explicit NumericField( Window* pParent, WinBits nWinStyle ); 526 explicit NumericField( Window* pParent, const ResId& ); 527 virtual ~NumericField(); 528 529 virtual long PreNotify( NotifyEvent& rNEvt ); 530 virtual long Notify( NotifyEvent& rNEvt ); 531 virtual void DataChanged( const DataChangedEvent& rDCEvt ); 532 533 virtual void Modify(); 534 535 virtual void Up(); 536 virtual void Down(); 537 virtual void First(); 538 virtual void Last(); 539 }; 540 541 542 // ---------------- 543 // - MetricField - 544 // ---------------- 545 546 class VCL_DLLPUBLIC MetricField : public SpinField, public MetricFormatter 547 { 548 protected: 549 SAL_DLLPRIVATE void ImplLoadRes( const ResId& rResId ); 550 551 public: 552 explicit MetricField( Window* pParent, WinBits nWinStyle ); 553 explicit MetricField( Window* pParent, const ResId& ); 554 virtual ~MetricField(); 555 556 virtual long PreNotify( NotifyEvent& rNEvt ); 557 virtual long Notify( NotifyEvent& rNEvt ); 558 virtual void DataChanged( const DataChangedEvent& rDCEvt ); 559 560 virtual void Modify(); 561 562 virtual void Up(); 563 virtual void Down(); 564 virtual void First(); 565 virtual void Last(); 566 virtual void CustomConvert(); 567 568 void SetFirst( sal_Int64 nNewFirst, FieldUnit eInUnit ); SetFirst(sal_Int64 first)569 inline void SetFirst(sal_Int64 first) { SetFirst(first, FUNIT_NONE); } 570 sal_Int64 GetFirst( FieldUnit eOutUnit ) const; GetFirst() const571 inline sal_Int64 GetFirst() const { return GetFirst(FUNIT_NONE); } 572 void SetLast( sal_Int64 nNewLast, FieldUnit eInUnit ); SetLast(sal_Int64 last)573 inline void SetLast(sal_Int64 last) { SetLast(last, FUNIT_NONE); } 574 sal_Int64 GetLast( FieldUnit eOutUnit ) const; GetLast() const575 inline sal_Int64 GetLast() const { return GetLast(FUNIT_NONE); } 576 577 static void SetDefaultUnit( FieldUnit eDefaultUnit ); 578 static FieldUnit GetDefaultUnit(); 579 static sal_Int64 ConvertValue( sal_Int64 nValue, sal_Int64 mnBaseValue, sal_uInt16 nDecDigits, 580 FieldUnit eInUnit, FieldUnit eOutUnit ); 581 static sal_Int64 ConvertValue( sal_Int64 nValue, sal_uInt16 nDecDigits, 582 FieldUnit eInUnit, MapUnit eOutUnit ); 583 static sal_Int64 ConvertValue( sal_Int64 nValue, sal_uInt16 nDecDigits, 584 MapUnit eInUnit, FieldUnit eOutUnit ); 585 586 // for backwards compatibility 587 // caution: conversion to double loses precision 588 static double ConvertDoubleValue( double nValue, sal_Int64 mnBaseValue, sal_uInt16 nDecDigits, 589 FieldUnit eInUnit, FieldUnit eOutUnit ); 590 static double ConvertDoubleValue( double nValue, sal_uInt16 nDecDigits, 591 FieldUnit eInUnit, MapUnit eOutUnit ); 592 static double ConvertDoubleValue( double nValue, sal_uInt16 nDecDigits, 593 MapUnit eInUnit, FieldUnit eOutUnit ); 594 595 // for backwards compatibility 596 // caution: conversion to double loses precision ConvertDoubleValue(sal_Int64 nValue,sal_Int64 nBaseValue,sal_uInt16 nDecDigits,FieldUnit eInUnit,FieldUnit eOutUnit)597 static double ConvertDoubleValue( sal_Int64 nValue, sal_Int64 nBaseValue, sal_uInt16 nDecDigits, 598 FieldUnit eInUnit, FieldUnit eOutUnit ) 599 { return ConvertDoubleValue( static_cast<double>(nValue), nBaseValue, nDecDigits, eInUnit, eOutUnit ); } ConvertDoubleValue(sal_Int64 nValue,sal_uInt16 nDecDigits,FieldUnit eInUnit,MapUnit eOutUnit)600 static double ConvertDoubleValue( sal_Int64 nValue, sal_uInt16 nDecDigits, 601 FieldUnit eInUnit, MapUnit eOutUnit ) 602 { return ConvertDoubleValue( static_cast<double>(nValue), nDecDigits, eInUnit, eOutUnit ); } ConvertDoubleValue(sal_Int64 nValue,sal_uInt16 nDecDigits,MapUnit eInUnit,FieldUnit eOutUnit)603 static double ConvertDoubleValue( sal_Int64 nValue, sal_uInt16 nDecDigits, 604 MapUnit eInUnit, FieldUnit eOutUnit ) 605 { return ConvertDoubleValue( static_cast<double>(nValue), nDecDigits, eInUnit, eOutUnit ); } 606 }; 607 608 609 // ----------------- 610 // - CurrencyField - 611 // ----------------- 612 613 class VCL_DLLPUBLIC CurrencyField : public SpinField, public CurrencyFormatter 614 { 615 protected: 616 SAL_DLLPRIVATE void ImplLoadRes( const ResId& rResId ); 617 618 public: 619 explicit CurrencyField( Window* pParent, WinBits nWinStyle ); 620 explicit CurrencyField( Window* pParent, const ResId& ); 621 virtual ~CurrencyField(); 622 623 virtual long PreNotify( NotifyEvent& rNEvt ); 624 virtual long Notify( NotifyEvent& rNEvt ); 625 virtual void DataChanged( const DataChangedEvent& rDCEvt ); 626 627 virtual void Modify(); 628 629 virtual void Up(); 630 virtual void Down(); 631 virtual void First(); 632 virtual void Last(); 633 }; 634 635 636 // ------------- 637 // - DateField - 638 // ------------- 639 640 class VCL_DLLPUBLIC DateField : public SpinField, public DateFormatter 641 { 642 private: 643 Date maFirst; 644 Date maLast; 645 646 protected: 647 SAL_DLLPRIVATE void ImplDateSpinArea( sal_Bool bUp ); 648 SAL_DLLPRIVATE void ImplLoadRes( const ResId& rResId ); 649 650 public: 651 explicit DateField( Window* pParent, WinBits nWinStyle ); 652 explicit DateField( Window* pParent, const ResId& ); 653 virtual ~DateField(); 654 655 virtual long PreNotify( NotifyEvent& rNEvt ); 656 virtual long Notify( NotifyEvent& rNEvt ); 657 virtual void DataChanged( const DataChangedEvent& rDCEvt ); 658 659 virtual void Modify(); 660 661 virtual void Up(); 662 virtual void Down(); 663 virtual void First(); 664 virtual void Last(); 665 SetFirst(const Date & rNewFirst)666 void SetFirst( const Date& rNewFirst ) { maFirst = rNewFirst; } GetFirst() const667 Date GetFirst() const { return maFirst; } SetLast(const Date & rNewLast)668 void SetLast( const Date& rNewLast ) { maLast = rNewLast; } GetLast() const669 Date GetLast() const { return maLast; } 670 }; 671 672 // ------------- 673 // - TimeField - 674 // ------------- 675 676 class VCL_DLLPUBLIC TimeField : public SpinField, public TimeFormatter 677 { 678 private: 679 Time maFirst; 680 Time maLast; 681 682 protected: 683 SAL_DLLPRIVATE void ImplTimeSpinArea( sal_Bool bUp ); 684 SAL_DLLPRIVATE void ImplLoadRes( const ResId& rResId ); 685 686 public: 687 explicit TimeField( Window* pParent, WinBits nWinStyle ); 688 explicit TimeField( Window* pParent, const ResId& ); 689 virtual ~TimeField(); 690 691 virtual long PreNotify( NotifyEvent& rNEvt ); 692 virtual long Notify( NotifyEvent& rNEvt ); 693 virtual void DataChanged( const DataChangedEvent& rDCEvt ); 694 695 virtual void Modify(); 696 697 virtual void Up(); 698 virtual void Down(); 699 virtual void First(); 700 virtual void Last(); 701 SetFirst(const Time & rNewFirst)702 void SetFirst( const Time& rNewFirst ) { maFirst = rNewFirst; } GetFirst() const703 Time GetFirst() const { return maFirst; } SetLast(const Time & rNewLast)704 void SetLast( const Time& rNewLast ) { maLast = rNewLast; } GetLast() const705 Time GetLast() const { return maLast; } 706 707 void SetExtFormat( ExtTimeFieldFormat eFormat ); 708 }; 709 710 711 // -------------- 712 // - PatternBox - 713 // -------------- 714 715 class VCL_DLLPUBLIC PatternBox : public ComboBox, public PatternFormatter 716 { 717 public: 718 explicit PatternBox( Window* pParent, WinBits nWinStyle ); 719 explicit PatternBox( Window* pParent, const ResId& ); 720 virtual ~PatternBox(); 721 722 virtual long PreNotify( NotifyEvent& rNEvt ); 723 virtual long Notify( NotifyEvent& rNEvt ); 724 725 virtual void Modify(); 726 727 virtual void ReformatAll(); 728 729 void InsertString( const XubString& rStr, 730 sal_uInt16 nPos = COMBOBOX_APPEND ); 731 void RemoveString( const XubString& rStr ); 732 using PatternFormatter::GetString; 733 XubString GetString( sal_uInt16 nPos ) const; 734 sal_uInt16 GetStringPos( const XubString& rStr ) const; 735 }; 736 737 738 // -------------- 739 // - NumericBox - 740 // -------------- 741 742 class VCL_DLLPUBLIC NumericBox : public ComboBox, public NumericFormatter 743 { 744 public: 745 explicit NumericBox( Window* pParent, WinBits nWinStyle ); 746 explicit NumericBox( Window* pParent, const ResId& ); 747 virtual ~NumericBox(); 748 749 virtual long PreNotify( NotifyEvent& rNEvt ); 750 virtual long Notify( NotifyEvent& rNEvt ); 751 virtual void DataChanged( const DataChangedEvent& rDCEvt ); 752 753 virtual void Modify(); 754 755 virtual void ReformatAll(); 756 757 void InsertValue( sal_Int64 nValue, sal_uInt16 nPos = COMBOBOX_APPEND ); 758 void RemoveValue( sal_Int64 nValue ); 759 using NumericFormatter::GetValue; 760 sal_Int64 GetValue( sal_uInt16 nPos ) const; 761 sal_uInt16 GetValuePos( sal_Int64 nPos ) const; 762 }; 763 764 765 // ------------- 766 // - MetricBox - 767 // ------------- 768 769 class VCL_DLLPUBLIC MetricBox : public ComboBox, public MetricFormatter 770 { 771 public: 772 explicit MetricBox( Window* pParent, WinBits nWinStyle ); 773 explicit MetricBox( Window* pParent, const ResId& ); 774 virtual ~MetricBox(); 775 776 virtual long PreNotify( NotifyEvent& rNEvt ); 777 virtual long Notify( NotifyEvent& rNEvt ); 778 virtual void DataChanged( const DataChangedEvent& rDCEvt ); 779 780 virtual void Modify(); 781 782 virtual void CustomConvert(); 783 virtual void ReformatAll(); 784 785 void InsertValue( sal_Int64 nValue, FieldUnit eInUnit = FUNIT_NONE, 786 sal_uInt16 nPos = COMBOBOX_APPEND ); 787 void RemoveValue( sal_Int64 nValue, FieldUnit eInUnit = FUNIT_NONE ); 788 sal_Int64 GetValue( sal_uInt16 nPos, FieldUnit eOutUnit = FUNIT_NONE ) const; 789 sal_uInt16 GetValuePos( sal_Int64 nValue, 790 FieldUnit eInUnit = FUNIT_NONE ) const; 791 792 // Needed, because GetValue() with nPos hide these functions 793 virtual sal_Int64 GetValue( FieldUnit eOutUnit ) const; 794 virtual sal_Int64 GetValue() const; 795 }; 796 797 798 // --------------- 799 // - CurrencyBox - 800 // --------------- 801 802 class VCL_DLLPUBLIC CurrencyBox : public ComboBox, public CurrencyFormatter 803 { 804 public: 805 explicit CurrencyBox( Window* pParent, WinBits nWinStyle ); 806 explicit CurrencyBox( Window* pParent, const ResId& ); 807 virtual ~CurrencyBox(); 808 809 virtual long PreNotify( NotifyEvent& rNEvt ); 810 virtual long Notify( NotifyEvent& rNEvt ); 811 virtual void DataChanged( const DataChangedEvent& rDCEvt ); 812 813 virtual void Modify(); 814 815 virtual void ReformatAll(); 816 817 void InsertValue( sal_Int64 nValue, sal_uInt16 nPos = COMBOBOX_APPEND ); 818 void RemoveValue( sal_Int64 nValue ); 819 sal_Int64 GetValue( sal_uInt16 nPos ) const; 820 sal_uInt16 GetValuePos( sal_Int64 nValue ) const; 821 822 // Needed, because GetValue() with nPos hide this function 823 virtual sal_Int64 GetValue() const; 824 }; 825 826 827 // ----------- 828 // - DateBox - 829 // ----------- 830 831 class VCL_DLLPUBLIC DateBox : public ComboBox, public DateFormatter 832 { 833 public: 834 explicit DateBox( Window* pParent, WinBits nWinStyle ); 835 explicit DateBox( Window* pParent, const ResId& ); 836 virtual ~DateBox(); 837 838 virtual long PreNotify( NotifyEvent& rNEvt ); 839 virtual long Notify( NotifyEvent& rNEvt ); 840 virtual void DataChanged( const DataChangedEvent& rDCEvt ); 841 842 virtual void Modify(); 843 844 virtual void ReformatAll(); 845 846 void InsertDate( const Date& rDate, sal_uInt16 nPos = COMBOBOX_APPEND ); 847 void RemoveDate( const Date& rDate ); 848 using DateFormatter::GetDate; 849 Date GetDate( sal_uInt16 nPos ) const; 850 sal_uInt16 GetDatePos( const Date& rDate ) const; 851 }; 852 853 854 // ----------- 855 // - TimeBox - 856 // ----------- 857 858 class VCL_DLLPUBLIC TimeBox : public ComboBox, public TimeFormatter 859 { 860 public: 861 explicit TimeBox( Window* pParent, WinBits nWinStyle ); 862 explicit TimeBox( Window* pParent, const ResId& ); 863 virtual ~TimeBox(); 864 865 virtual long PreNotify( NotifyEvent& rNEvt ); 866 virtual long Notify( NotifyEvent& rNEvt ); 867 virtual void DataChanged( const DataChangedEvent& rDCEvt ); 868 869 virtual void Modify(); 870 871 virtual void ReformatAll(); 872 873 void InsertTime( const Time& rTime, sal_uInt16 nPos = COMBOBOX_APPEND ); 874 void RemoveTime( const Time& rTime ); 875 using TimeFormatter::GetTime; 876 Time GetTime( sal_uInt16 nPos ) const; 877 sal_uInt16 GetTimePos( const Time& rTime ) const; 878 }; 879 880 #endif // _SV_FIELD_HXX 881