19f62ea84SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 39f62ea84SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 49f62ea84SAndrew Rist * or more contributor license agreements. See the NOTICE file 59f62ea84SAndrew Rist * distributed with this work for additional information 69f62ea84SAndrew Rist * regarding copyright ownership. The ASF licenses this file 79f62ea84SAndrew Rist * to you under the Apache License, Version 2.0 (the 89f62ea84SAndrew Rist * "License"); you may not use this file except in compliance 99f62ea84SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 119f62ea84SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 139f62ea84SAndrew Rist * Unless required by applicable law or agreed to in writing, 149f62ea84SAndrew Rist * software distributed under the License is distributed on an 159f62ea84SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 169f62ea84SAndrew Rist * KIND, either express or implied. See the License for the 179f62ea84SAndrew Rist * specific language governing permissions and limitations 189f62ea84SAndrew Rist * under the License. 19cdf0e10cSrcweir * 209f62ea84SAndrew Rist *************************************************************/ 219f62ea84SAndrew Rist 229f62ea84SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_vcl.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #ifndef _BIGINT_HXX 28cdf0e10cSrcweir #define _TOOLS_BIGINT 29cdf0e10cSrcweir #include "tools/bigint.hxx" 30cdf0e10cSrcweir #endif 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include "tools/debug.hxx" 33cdf0e10cSrcweir 34cdf0e10cSrcweir #include "tools/rc.h" 35cdf0e10cSrcweir #include "tools/resary.hxx" 36cdf0e10cSrcweir 37cdf0e10cSrcweir #include "vcl/field.hxx" 38cdf0e10cSrcweir #include "vcl/event.hxx" 39cdf0e10cSrcweir #include "vcl/svapp.hxx" 40cdf0e10cSrcweir #include "vcl/unohelp.hxx" 41cdf0e10cSrcweir 42cdf0e10cSrcweir #include "svids.hrc" 43cdf0e10cSrcweir #include "svdata.hxx" 44cdf0e10cSrcweir 45cdf0e10cSrcweir #include "i18nutil/unicode.hxx" 46cdf0e10cSrcweir 47cdf0e10cSrcweir #include "rtl/math.hxx" 48cdf0e10cSrcweir 49cdf0e10cSrcweir 50cdf0e10cSrcweir #include <unotools/localedatawrapper.hxx> 51cdf0e10cSrcweir 52cdf0e10cSrcweir using namespace ::com::sun::star; 53cdf0e10cSrcweir 54cdf0e10cSrcweir // ----------------------------------------------------------------------- 55cdf0e10cSrcweir 56cdf0e10cSrcweir #define FORMAT_NUMERIC 1 57cdf0e10cSrcweir #define FORMAT_METRIC 2 58cdf0e10cSrcweir #define FORMAT_CURRENCY 3 59cdf0e10cSrcweir 60cdf0e10cSrcweir // ----------------------------------------------------------------------- 61cdf0e10cSrcweir 62cdf0e10cSrcweir static sal_Int64 ImplPower10( sal_uInt16 n ) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir sal_uInt16 i; 65cdf0e10cSrcweir sal_Int64 nValue = 1; 66cdf0e10cSrcweir 67cdf0e10cSrcweir for ( i=0; i < n; i++ ) 68cdf0e10cSrcweir nValue *= 10; 69cdf0e10cSrcweir 70cdf0e10cSrcweir return nValue; 71cdf0e10cSrcweir } 72cdf0e10cSrcweir 73cdf0e10cSrcweir // ----------------------------------------------------------------------- 74cdf0e10cSrcweir 75cdf0e10cSrcweir static sal_Bool ImplNumericProcessKeyInput( Edit*, const KeyEvent& rKEvt, 76cdf0e10cSrcweir sal_Bool bStrictFormat, sal_Bool bThousandSep, 77cdf0e10cSrcweir const LocaleDataWrapper& rLocaleDataWrappper ) 78cdf0e10cSrcweir { 79cdf0e10cSrcweir if ( !bStrictFormat ) 80cdf0e10cSrcweir return sal_False; 81cdf0e10cSrcweir else 82cdf0e10cSrcweir { 83cdf0e10cSrcweir xub_Unicode cChar = rKEvt.GetCharCode(); 84cdf0e10cSrcweir sal_uInt16 nGroup = rKEvt.GetKeyCode().GetGroup(); 85cdf0e10cSrcweir 86cdf0e10cSrcweir if ( (nGroup == KEYGROUP_FKEYS) || (nGroup == KEYGROUP_CURSOR) || 87cdf0e10cSrcweir (nGroup == KEYGROUP_MISC) || 88cdf0e10cSrcweir ((cChar >= '0') && (cChar <= '9')) || 89cdf0e10cSrcweir (cChar == rLocaleDataWrappper.getNumDecimalSep() ) || 90cdf0e10cSrcweir (bThousandSep && (cChar == rLocaleDataWrappper.getNumThousandSep())) || 91cdf0e10cSrcweir (cChar == '-') ) 92cdf0e10cSrcweir return sal_False; 93cdf0e10cSrcweir else 94cdf0e10cSrcweir return sal_True; 95cdf0e10cSrcweir } 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir // ----------------------------------------------------------------------- 99cdf0e10cSrcweir 100cdf0e10cSrcweir static sal_Bool ImplNumericGetValue( const XubString& rStr, double& rValue, 101cdf0e10cSrcweir sal_uInt16 nDecDigits, const LocaleDataWrapper& rLocaleDataWrappper, 102cdf0e10cSrcweir sal_Bool bCurrency = sal_False ) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir XubString aStr = rStr; 105cdf0e10cSrcweir XubString aStr1; 106cdf0e10cSrcweir XubString aStr2; 107cdf0e10cSrcweir sal_Bool bNegative = sal_False; 108cdf0e10cSrcweir xub_StrLen nDecPos; 109cdf0e10cSrcweir xub_StrLen i; 110cdf0e10cSrcweir 111cdf0e10cSrcweir // Reaktion auf leeren String 112cdf0e10cSrcweir if ( !rStr.Len() ) 113cdf0e10cSrcweir return sal_False; 114cdf0e10cSrcweir 115cdf0e10cSrcweir // Fuehrende und nachfolgende Leerzeichen entfernen 116cdf0e10cSrcweir aStr.EraseLeadingAndTrailingChars( ' ' ); 117cdf0e10cSrcweir 118cdf0e10cSrcweir // Position des Dezimalpunktes suchen 119cdf0e10cSrcweir nDecPos = aStr.Search( rLocaleDataWrappper.getNumDecimalSep() ); 120cdf0e10cSrcweir if ( nDecPos != STRING_NOTFOUND ) 121cdf0e10cSrcweir { 122cdf0e10cSrcweir aStr1 = aStr.Copy( 0, nDecPos ); 123cdf0e10cSrcweir aStr2 = aStr.Copy( nDecPos+1 ); 124cdf0e10cSrcweir } 125cdf0e10cSrcweir else 126cdf0e10cSrcweir aStr1 = aStr; 127cdf0e10cSrcweir 128cdf0e10cSrcweir // Negativ ? 129cdf0e10cSrcweir if ( bCurrency ) 130cdf0e10cSrcweir { 131cdf0e10cSrcweir if ( (aStr.GetChar( 0 ) == '(') && (aStr.GetChar( aStr.Len()-1 ) == ')') ) 132cdf0e10cSrcweir bNegative = sal_True; 133cdf0e10cSrcweir if ( !bNegative ) 134cdf0e10cSrcweir { 135cdf0e10cSrcweir for ( i=0; i < aStr.Len(); i++ ) 136cdf0e10cSrcweir { 137cdf0e10cSrcweir if ( (aStr.GetChar( i ) >= '0') && (aStr.GetChar( i ) <= '9') ) 138cdf0e10cSrcweir break; 139cdf0e10cSrcweir else if ( aStr.GetChar( i ) == '-' ) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir bNegative = sal_True; 142cdf0e10cSrcweir break; 143cdf0e10cSrcweir } 144cdf0e10cSrcweir } 145cdf0e10cSrcweir } 146cdf0e10cSrcweir if ( !bNegative && bCurrency && aStr.Len() ) 147cdf0e10cSrcweir { 148cdf0e10cSrcweir sal_uInt16 nFormat = rLocaleDataWrappper.getCurrNegativeFormat(); 149cdf0e10cSrcweir if ( (nFormat == 3) || (nFormat == 6) || 150cdf0e10cSrcweir (nFormat == 7) || (nFormat == 10) ) 151cdf0e10cSrcweir { 152cdf0e10cSrcweir for ( i = (xub_StrLen)(aStr.Len()-1); i > 0; i++ ) 153cdf0e10cSrcweir { 154cdf0e10cSrcweir if ( (aStr.GetChar( i ) >= '0') && (aStr.GetChar( i ) <= '9') ) 155cdf0e10cSrcweir break; 156cdf0e10cSrcweir else if ( aStr.GetChar( i ) == '-' ) 157cdf0e10cSrcweir { 158cdf0e10cSrcweir bNegative = sal_True; 159cdf0e10cSrcweir break; 160cdf0e10cSrcweir } 161cdf0e10cSrcweir } 162cdf0e10cSrcweir } 163cdf0e10cSrcweir } 164cdf0e10cSrcweir } 165cdf0e10cSrcweir else 166cdf0e10cSrcweir { 167cdf0e10cSrcweir if ( aStr1.GetChar( 0 ) == '-' ) 168cdf0e10cSrcweir bNegative = sal_True; 169cdf0e10cSrcweir } 170cdf0e10cSrcweir 171cdf0e10cSrcweir // Alle unerwuenschten Zeichen rauswerfen 172cdf0e10cSrcweir for ( i=0; i < aStr1.Len(); ) 173cdf0e10cSrcweir { 174cdf0e10cSrcweir if ( (aStr1.GetChar( i ) >= '0') && (aStr1.GetChar( i ) <= '9') ) 175cdf0e10cSrcweir i++; 176cdf0e10cSrcweir else 177cdf0e10cSrcweir aStr1.Erase( i, 1 ); 178cdf0e10cSrcweir } 179cdf0e10cSrcweir for ( i=0; i < aStr2.Len(); ) 180cdf0e10cSrcweir { 181cdf0e10cSrcweir if ( (aStr2.GetChar( i ) >= '0') && (aStr2.GetChar( i ) <= '9') ) 182cdf0e10cSrcweir i++; 183cdf0e10cSrcweir else 184cdf0e10cSrcweir aStr2.Erase( i, 1 ); 185cdf0e10cSrcweir } 186cdf0e10cSrcweir 187cdf0e10cSrcweir if ( !aStr1.Len() && !aStr2.Len() ) 188cdf0e10cSrcweir return sal_False; 189cdf0e10cSrcweir 190cdf0e10cSrcweir if ( !aStr1.Len() ) 191cdf0e10cSrcweir aStr1.Insert( '0' ); 192cdf0e10cSrcweir if ( bNegative ) 193cdf0e10cSrcweir aStr1.Insert( '-', 0 ); 194cdf0e10cSrcweir 195cdf0e10cSrcweir // Nachkommateil zurechtstutzen und dabei runden 196cdf0e10cSrcweir sal_Bool bRound = sal_False; 197cdf0e10cSrcweir if ( aStr2.Len() > nDecDigits ) 198cdf0e10cSrcweir { 199cdf0e10cSrcweir if ( aStr2.GetChar( nDecDigits ) >= '5' ) 200cdf0e10cSrcweir bRound = sal_True; 201cdf0e10cSrcweir aStr2.Erase( nDecDigits ); 202cdf0e10cSrcweir } 203cdf0e10cSrcweir if ( aStr2.Len() < nDecDigits ) 204cdf0e10cSrcweir aStr2.Expand( nDecDigits, '0' ); 205cdf0e10cSrcweir 206cdf0e10cSrcweir aStr = aStr1; 207cdf0e10cSrcweir aStr += aStr2; 208cdf0e10cSrcweir 209cdf0e10cSrcweir // Bereichsueberpruefung 210cdf0e10cSrcweir double nValue = aStr.ToDouble(); 211cdf0e10cSrcweir if ( bRound ) 212cdf0e10cSrcweir { 213cdf0e10cSrcweir if ( !bNegative ) 214cdf0e10cSrcweir nValue++; 215cdf0e10cSrcweir else 216cdf0e10cSrcweir nValue--; 217cdf0e10cSrcweir } 218cdf0e10cSrcweir 219cdf0e10cSrcweir rValue = nValue; 220cdf0e10cSrcweir 221cdf0e10cSrcweir return sal_True; 222cdf0e10cSrcweir } 223cdf0e10cSrcweir 224cdf0e10cSrcweir static void ImplUpdateSeparatorString( String& io_rText, 225cdf0e10cSrcweir const String& rOldDecSep, const String& rNewDecSep, 226cdf0e10cSrcweir const String& rOldThSep, const String& rNewThSep ) 227cdf0e10cSrcweir { 228cdf0e10cSrcweir rtl::OUStringBuffer aBuf( io_rText.Len() ); 229cdf0e10cSrcweir xub_StrLen nIndexDec = 0, nIndexTh = 0, nIndex = 0; 230cdf0e10cSrcweir 231cdf0e10cSrcweir const sal_Unicode* pBuffer = io_rText.GetBuffer(); 232cdf0e10cSrcweir while( nIndex != STRING_NOTFOUND ) 233cdf0e10cSrcweir { 234cdf0e10cSrcweir nIndexDec = io_rText.Search( rOldDecSep, nIndex ); 235cdf0e10cSrcweir nIndexTh = io_rText.Search( rOldThSep, nIndex ); 236cdf0e10cSrcweir if( (nIndexTh != STRING_NOTFOUND && nIndexDec != STRING_NOTFOUND && nIndexTh < nIndexDec ) 237cdf0e10cSrcweir || (nIndexTh != STRING_NOTFOUND && nIndexDec == STRING_NOTFOUND) 238cdf0e10cSrcweir ) 239cdf0e10cSrcweir { 240cdf0e10cSrcweir aBuf.append( pBuffer + nIndex, nIndexTh - nIndex ); 241cdf0e10cSrcweir aBuf.append( rNewThSep ); 242cdf0e10cSrcweir nIndex = nIndexTh + rOldThSep.Len(); 243cdf0e10cSrcweir } 244cdf0e10cSrcweir else if( nIndexDec != STRING_NOTFOUND ) 245cdf0e10cSrcweir { 246cdf0e10cSrcweir aBuf.append( pBuffer + nIndex, nIndexDec - nIndex ); 247cdf0e10cSrcweir aBuf.append( rNewDecSep ); 248cdf0e10cSrcweir nIndex = nIndexDec + rOldDecSep.Len(); 249cdf0e10cSrcweir } 250cdf0e10cSrcweir else 251cdf0e10cSrcweir { 252cdf0e10cSrcweir aBuf.append( pBuffer + nIndex ); 253cdf0e10cSrcweir nIndex = STRING_NOTFOUND; 254cdf0e10cSrcweir } 255cdf0e10cSrcweir } 256cdf0e10cSrcweir 257cdf0e10cSrcweir io_rText = aBuf.makeStringAndClear(); 258cdf0e10cSrcweir } 259cdf0e10cSrcweir 260cdf0e10cSrcweir static void ImplUpdateSeparators( const String& rOldDecSep, const String& rNewDecSep, 261cdf0e10cSrcweir const String& rOldThSep, const String& rNewThSep, 262cdf0e10cSrcweir Edit* pEdit ) 263cdf0e10cSrcweir { 264cdf0e10cSrcweir bool bChangeDec = (rOldDecSep != rNewDecSep); 265cdf0e10cSrcweir bool bChangeTh = (rOldThSep != rNewThSep ); 266cdf0e10cSrcweir 267cdf0e10cSrcweir if( bChangeDec || bChangeTh ) 268cdf0e10cSrcweir { 269cdf0e10cSrcweir sal_Bool bUpdateMode = pEdit->IsUpdateMode(); 270cdf0e10cSrcweir pEdit->SetUpdateMode( sal_False ); 271cdf0e10cSrcweir String aText = pEdit->GetText(); 272cdf0e10cSrcweir ImplUpdateSeparatorString( aText, rOldDecSep, rNewDecSep, rOldThSep, rNewThSep ); 273cdf0e10cSrcweir pEdit->SetText( aText ); 274cdf0e10cSrcweir 275cdf0e10cSrcweir ComboBox* pCombo = dynamic_cast<ComboBox*>(pEdit); 276cdf0e10cSrcweir if( pCombo ) 277cdf0e10cSrcweir { 278cdf0e10cSrcweir // update box entries 279cdf0e10cSrcweir sal_uInt16 nEntryCount = pCombo->GetEntryCount(); 280cdf0e10cSrcweir for ( sal_uInt16 i=0; i < nEntryCount; i++ ) 281cdf0e10cSrcweir { 282cdf0e10cSrcweir aText = pCombo->GetEntry( i ); 283cdf0e10cSrcweir void* pEntryData = pCombo->GetEntryData( i ); 284cdf0e10cSrcweir ImplUpdateSeparatorString( aText, rOldDecSep, rNewDecSep, rOldThSep, rNewThSep ); 285cdf0e10cSrcweir pCombo->RemoveEntry( i ); 286cdf0e10cSrcweir pCombo->InsertEntry( aText, i ); 287cdf0e10cSrcweir pCombo->SetEntryData( i, pEntryData ); 288cdf0e10cSrcweir } 289cdf0e10cSrcweir } 290cdf0e10cSrcweir if( bUpdateMode ) 291cdf0e10cSrcweir pEdit->SetUpdateMode( bUpdateMode ); 292cdf0e10cSrcweir } 293cdf0e10cSrcweir } 294cdf0e10cSrcweir 295cdf0e10cSrcweir // ----------------------------------------------------------------------- 296cdf0e10cSrcweir 297cdf0e10cSrcweir FormatterBase::FormatterBase( Edit* pField ) 298cdf0e10cSrcweir { 299cdf0e10cSrcweir mpField = pField; 300cdf0e10cSrcweir mpLocaleDataWrapper = NULL; 301cdf0e10cSrcweir mbReformat = sal_False; 302cdf0e10cSrcweir mbStrictFormat = sal_False; 303cdf0e10cSrcweir mbEmptyFieldValue = sal_False; 304cdf0e10cSrcweir mbEmptyFieldValueEnabled = sal_False; 305cdf0e10cSrcweir mbDefaultLocale = sal_True; 306cdf0e10cSrcweir } 307cdf0e10cSrcweir 308cdf0e10cSrcweir // ----------------------------------------------------------------------- 309cdf0e10cSrcweir 310cdf0e10cSrcweir FormatterBase::~FormatterBase() 311cdf0e10cSrcweir { 312cdf0e10cSrcweir delete mpLocaleDataWrapper; 313cdf0e10cSrcweir } 314cdf0e10cSrcweir 315cdf0e10cSrcweir // ----------------------------------------------------------------------- 316cdf0e10cSrcweir 317cdf0e10cSrcweir LocaleDataWrapper& FormatterBase::ImplGetLocaleDataWrapper() const 318cdf0e10cSrcweir { 319cdf0e10cSrcweir if ( !mpLocaleDataWrapper ) 320cdf0e10cSrcweir { 321cdf0e10cSrcweir ((FormatterBase*)this)->mpLocaleDataWrapper = new LocaleDataWrapper( vcl::unohelper::GetMultiServiceFactory(), GetLocale() ); 322cdf0e10cSrcweir } 323cdf0e10cSrcweir return *mpLocaleDataWrapper; 324cdf0e10cSrcweir } 325cdf0e10cSrcweir 326cdf0e10cSrcweir const LocaleDataWrapper& FormatterBase::GetLocaleDataWrapper() const 327cdf0e10cSrcweir { 328cdf0e10cSrcweir return ImplGetLocaleDataWrapper(); 329cdf0e10cSrcweir } 330cdf0e10cSrcweir 331cdf0e10cSrcweir // ----------------------------------------------------------------------- 332cdf0e10cSrcweir 333cdf0e10cSrcweir void FormatterBase::Reformat() 334cdf0e10cSrcweir { 335cdf0e10cSrcweir } 336cdf0e10cSrcweir 337cdf0e10cSrcweir // ----------------------------------------------------------------------- 338cdf0e10cSrcweir 339cdf0e10cSrcweir void FormatterBase::ReformatAll() 340cdf0e10cSrcweir { 341cdf0e10cSrcweir Reformat(); 342cdf0e10cSrcweir }; 343cdf0e10cSrcweir 344cdf0e10cSrcweir // ----------------------------------------------------------------------- 345cdf0e10cSrcweir 346cdf0e10cSrcweir void FormatterBase::SetStrictFormat( sal_Bool bStrict ) 347cdf0e10cSrcweir { 348cdf0e10cSrcweir if ( bStrict != mbStrictFormat ) 349cdf0e10cSrcweir { 350cdf0e10cSrcweir mbStrictFormat = bStrict; 351cdf0e10cSrcweir if ( mbStrictFormat ) 352cdf0e10cSrcweir ReformatAll(); 353cdf0e10cSrcweir } 354cdf0e10cSrcweir } 355cdf0e10cSrcweir 356cdf0e10cSrcweir // ----------------------------------------------------------------------- 357cdf0e10cSrcweir 358cdf0e10cSrcweir void FormatterBase::SetLocale( const lang::Locale& rLocale ) 359cdf0e10cSrcweir { 360cdf0e10cSrcweir ImplGetLocaleDataWrapper().setLocale( rLocale ); 361cdf0e10cSrcweir mbDefaultLocale = sal_False; 362cdf0e10cSrcweir ReformatAll(); 363cdf0e10cSrcweir } 364cdf0e10cSrcweir 365cdf0e10cSrcweir // ----------------------------------------------------------------------- 366cdf0e10cSrcweir 367cdf0e10cSrcweir const lang::Locale& FormatterBase::GetLocale() const 368cdf0e10cSrcweir { 369cdf0e10cSrcweir if ( !mpLocaleDataWrapper || mbDefaultLocale ) 370cdf0e10cSrcweir { 371cdf0e10cSrcweir if ( mpField ) 372cdf0e10cSrcweir return mpField->GetSettings().GetLocale(); 373cdf0e10cSrcweir else 374cdf0e10cSrcweir return Application::GetSettings().GetLocale(); 375cdf0e10cSrcweir } 376cdf0e10cSrcweir 377cdf0e10cSrcweir return mpLocaleDataWrapper->getLocale(); 378cdf0e10cSrcweir } 379cdf0e10cSrcweir 380cdf0e10cSrcweir // ----------------------------------------------------------------------- 381cdf0e10cSrcweir 382cdf0e10cSrcweir const AllSettings& FormatterBase::GetFieldSettings() const 383cdf0e10cSrcweir { 384cdf0e10cSrcweir if ( mpField ) 385cdf0e10cSrcweir return mpField->GetSettings(); 386cdf0e10cSrcweir else 387cdf0e10cSrcweir return Application::GetSettings(); 388cdf0e10cSrcweir } 389cdf0e10cSrcweir 390cdf0e10cSrcweir // ----------------------------------------------------------------------- 391cdf0e10cSrcweir 392cdf0e10cSrcweir void FormatterBase::SetFieldText( const XubString& rText, sal_Bool bKeepSelection ) 393cdf0e10cSrcweir { 394cdf0e10cSrcweir if ( mpField ) 395cdf0e10cSrcweir { 396cdf0e10cSrcweir Selection aNewSelection( 0xFFFF, 0xFFFF ); 397cdf0e10cSrcweir if ( bKeepSelection ) 398cdf0e10cSrcweir aNewSelection = mpField->GetSelection(); 399cdf0e10cSrcweir 400cdf0e10cSrcweir ImplSetText( rText, &aNewSelection ); 401cdf0e10cSrcweir } 402cdf0e10cSrcweir } 403cdf0e10cSrcweir 404cdf0e10cSrcweir // ----------------------------------------------------------------------- 405cdf0e10cSrcweir 406cdf0e10cSrcweir void FormatterBase::ImplSetText( const XubString& rText, Selection* pNewSelection ) 407cdf0e10cSrcweir { 408cdf0e10cSrcweir if ( mpField ) 409cdf0e10cSrcweir { 410cdf0e10cSrcweir if ( pNewSelection ) 411cdf0e10cSrcweir mpField->SetText( rText, *pNewSelection ); 412cdf0e10cSrcweir else 413cdf0e10cSrcweir { 414cdf0e10cSrcweir Selection aSel = mpField->GetSelection(); 415cdf0e10cSrcweir aSel.Min() = aSel.Max(); 416cdf0e10cSrcweir mpField->SetText( rText, aSel ); 417cdf0e10cSrcweir } 418cdf0e10cSrcweir 419cdf0e10cSrcweir MarkToBeReformatted( sal_False ); 420cdf0e10cSrcweir } 421cdf0e10cSrcweir } 422cdf0e10cSrcweir 423cdf0e10cSrcweir // ----------------------------------------------------------------------- 424cdf0e10cSrcweir 425cdf0e10cSrcweir void FormatterBase::SetEmptyFieldValue() 426cdf0e10cSrcweir { 427cdf0e10cSrcweir if ( mpField ) 428cdf0e10cSrcweir mpField->SetText( ImplGetSVEmptyStr() ); 429cdf0e10cSrcweir mbEmptyFieldValue = sal_True; 430cdf0e10cSrcweir } 431cdf0e10cSrcweir 432cdf0e10cSrcweir // ----------------------------------------------------------------------- 433cdf0e10cSrcweir 434cdf0e10cSrcweir sal_Bool FormatterBase::IsEmptyFieldValue() const 435cdf0e10cSrcweir { 436cdf0e10cSrcweir return (!mpField || !mpField->GetText().Len()); 437cdf0e10cSrcweir } 438cdf0e10cSrcweir 439cdf0e10cSrcweir // ----------------------------------------------------------------------- 440cdf0e10cSrcweir 441cdf0e10cSrcweir sal_Bool NumericFormatter::ImplNumericReformat( const XubString& rStr, double& rValue, 442cdf0e10cSrcweir XubString& rOutStr ) 443cdf0e10cSrcweir { 444cdf0e10cSrcweir if ( !ImplNumericGetValue( rStr, rValue, GetDecimalDigits(), ImplGetLocaleDataWrapper() ) ) 445cdf0e10cSrcweir return sal_True; 446cdf0e10cSrcweir else 447cdf0e10cSrcweir { 448cdf0e10cSrcweir double nTempVal = rValue; 449cdf0e10cSrcweir // caution: precision loss in double cast 450cdf0e10cSrcweir if ( nTempVal > mnMax ) 451cdf0e10cSrcweir nTempVal = (double)mnMax; 452cdf0e10cSrcweir else if ( nTempVal < mnMin ) 453cdf0e10cSrcweir nTempVal = (double)mnMin; 454cdf0e10cSrcweir 455cdf0e10cSrcweir if ( GetErrorHdl().IsSet() && (rValue != nTempVal) ) 456cdf0e10cSrcweir { 457cdf0e10cSrcweir mnCorrectedValue = (sal_Int64)nTempVal; 458cdf0e10cSrcweir if ( !GetErrorHdl().Call( this ) ) 459cdf0e10cSrcweir { 460cdf0e10cSrcweir mnCorrectedValue = 0; 461cdf0e10cSrcweir return sal_False; 462cdf0e10cSrcweir } 463cdf0e10cSrcweir else 464cdf0e10cSrcweir mnCorrectedValue = 0; 465cdf0e10cSrcweir } 466cdf0e10cSrcweir 467cdf0e10cSrcweir rOutStr = CreateFieldText( (sal_Int64)nTempVal ); 468cdf0e10cSrcweir return sal_True; 469cdf0e10cSrcweir } 470cdf0e10cSrcweir } 471cdf0e10cSrcweir 472cdf0e10cSrcweir // ----------------------------------------------------------------------- 473cdf0e10cSrcweir 474cdf0e10cSrcweir void NumericFormatter::ImplInit() 475cdf0e10cSrcweir { 476cdf0e10cSrcweir mnFieldValue = 0; 477cdf0e10cSrcweir mnLastValue = 0; 478cdf0e10cSrcweir mnMin = 0; 479cdf0e10cSrcweir mnMax = 0x7FFFFFFFFFFFFFFFLL; 480*6ac0dc2eSYuri Dario #ifdef OS2 // see i120312 for details. 481*6ac0dc2eSYuri Dario mnMax = 0x00000000FFFFFFFFLL; 482*6ac0dc2eSYuri Dario #endif 483cdf0e10cSrcweir mnCorrectedValue = 0; 484cdf0e10cSrcweir mnDecimalDigits = 2; 485cdf0e10cSrcweir mnType = FORMAT_NUMERIC; 486cdf0e10cSrcweir mbThousandSep = sal_True; 487cdf0e10cSrcweir mbShowTrailingZeros = sal_True; 488cdf0e10cSrcweir 489cdf0e10cSrcweir // for fields 490cdf0e10cSrcweir mnSpinSize = 1; 491cdf0e10cSrcweir mnFirst = mnMin; 492cdf0e10cSrcweir mnLast = mnMax; 493cdf0e10cSrcweir 494cdf0e10cSrcweir SetDecimalDigits( 0 ); 495cdf0e10cSrcweir } 496cdf0e10cSrcweir 497cdf0e10cSrcweir // ----------------------------------------------------------------------- 498cdf0e10cSrcweir 499cdf0e10cSrcweir NumericFormatter::NumericFormatter() 500cdf0e10cSrcweir { 501cdf0e10cSrcweir ImplInit(); 502cdf0e10cSrcweir } 503cdf0e10cSrcweir 504cdf0e10cSrcweir // ----------------------------------------------------------------------- 505cdf0e10cSrcweir 506cdf0e10cSrcweir void NumericFormatter::ImplLoadRes( const ResId& rResId ) 507cdf0e10cSrcweir { 508cdf0e10cSrcweir ResMgr* pMgr = rResId.GetResMgr(); 509cdf0e10cSrcweir 510cdf0e10cSrcweir if( pMgr ) 511cdf0e10cSrcweir { 512cdf0e10cSrcweir sal_uLong nMask = pMgr->ReadLong(); 513cdf0e10cSrcweir 514cdf0e10cSrcweir if ( NUMERICFORMATTER_MIN & nMask ) 515cdf0e10cSrcweir mnMin = pMgr->ReadLong(); 516cdf0e10cSrcweir 517cdf0e10cSrcweir if ( NUMERICFORMATTER_MAX & nMask ) 518cdf0e10cSrcweir mnMax = pMgr->ReadLong(); 519cdf0e10cSrcweir 520cdf0e10cSrcweir if ( NUMERICFORMATTER_STRICTFORMAT & nMask ) 521cdf0e10cSrcweir SetStrictFormat( (sal_Bool)pMgr->ReadShort() ); 522cdf0e10cSrcweir 523cdf0e10cSrcweir if ( NUMERICFORMATTER_DECIMALDIGITS & nMask ) 524cdf0e10cSrcweir SetDecimalDigits( pMgr->ReadShort() ); 525cdf0e10cSrcweir 526cdf0e10cSrcweir if ( NUMERICFORMATTER_VALUE & nMask ) 527cdf0e10cSrcweir { 528cdf0e10cSrcweir mnFieldValue = pMgr->ReadLong(); 529cdf0e10cSrcweir if ( mnFieldValue > mnMax ) 530cdf0e10cSrcweir mnFieldValue = mnMax; 531cdf0e10cSrcweir else if ( mnFieldValue < mnMin ) 532cdf0e10cSrcweir mnFieldValue = mnMin; 533cdf0e10cSrcweir mnLastValue = mnFieldValue; 534cdf0e10cSrcweir } 535cdf0e10cSrcweir 536cdf0e10cSrcweir if ( NUMERICFORMATTER_NOTHOUSANDSEP & nMask ) 537cdf0e10cSrcweir SetUseThousandSep( !(sal_Bool)pMgr->ReadShort() ); 538cdf0e10cSrcweir } 539cdf0e10cSrcweir } 540cdf0e10cSrcweir 541cdf0e10cSrcweir // ----------------------------------------------------------------------- 542cdf0e10cSrcweir 543cdf0e10cSrcweir NumericFormatter::~NumericFormatter() 544cdf0e10cSrcweir { 545cdf0e10cSrcweir } 546cdf0e10cSrcweir 547cdf0e10cSrcweir // ----------------------------------------------------------------------- 548cdf0e10cSrcweir 549cdf0e10cSrcweir void NumericFormatter::SetMin( sal_Int64 nNewMin ) 550cdf0e10cSrcweir { 551cdf0e10cSrcweir mnMin = nNewMin; 552cdf0e10cSrcweir if ( !IsEmptyFieldValue() ) 553cdf0e10cSrcweir ReformatAll(); 554cdf0e10cSrcweir } 555cdf0e10cSrcweir 556cdf0e10cSrcweir // ----------------------------------------------------------------------- 557cdf0e10cSrcweir 558cdf0e10cSrcweir void NumericFormatter::SetMax( sal_Int64 nNewMax ) 559cdf0e10cSrcweir { 560cdf0e10cSrcweir mnMax = nNewMax; 561cdf0e10cSrcweir if ( !IsEmptyFieldValue() ) 562cdf0e10cSrcweir ReformatAll(); 563cdf0e10cSrcweir } 564cdf0e10cSrcweir 565cdf0e10cSrcweir // ----------------------------------------------------------------------- 566cdf0e10cSrcweir 567cdf0e10cSrcweir void NumericFormatter::SetUseThousandSep( sal_Bool b ) 568cdf0e10cSrcweir { 569cdf0e10cSrcweir mbThousandSep = b; 570cdf0e10cSrcweir ReformatAll(); 571cdf0e10cSrcweir } 572cdf0e10cSrcweir 573cdf0e10cSrcweir // ----------------------------------------------------------------------- 574cdf0e10cSrcweir 575cdf0e10cSrcweir void NumericFormatter::SetDecimalDigits( sal_uInt16 nDigits ) 576cdf0e10cSrcweir { 577cdf0e10cSrcweir mnDecimalDigits = nDigits; 578cdf0e10cSrcweir ReformatAll(); 579cdf0e10cSrcweir } 580cdf0e10cSrcweir 581cdf0e10cSrcweir // ----------------------------------------------------------------------- 582cdf0e10cSrcweir 583cdf0e10cSrcweir void NumericFormatter::SetShowTrailingZeros( sal_Bool bShowTrailingZeros ) 584cdf0e10cSrcweir { 585cdf0e10cSrcweir if ( mbShowTrailingZeros != bShowTrailingZeros ) 586cdf0e10cSrcweir { 587cdf0e10cSrcweir mbShowTrailingZeros = bShowTrailingZeros; 588cdf0e10cSrcweir ReformatAll(); 589cdf0e10cSrcweir } 590cdf0e10cSrcweir } 591cdf0e10cSrcweir 592cdf0e10cSrcweir // ----------------------------------------------------------------------- 593cdf0e10cSrcweir 594cdf0e10cSrcweir sal_uInt16 NumericFormatter::GetDecimalDigits() const 595cdf0e10cSrcweir { 596cdf0e10cSrcweir return mnDecimalDigits; 597cdf0e10cSrcweir } 598cdf0e10cSrcweir 599cdf0e10cSrcweir // ----------------------------------------------------------------------- 600cdf0e10cSrcweir 601cdf0e10cSrcweir void NumericFormatter::SetValue( sal_Int64 nNewValue ) 602cdf0e10cSrcweir { 603cdf0e10cSrcweir SetUserValue( nNewValue ); 604cdf0e10cSrcweir mnFieldValue = mnLastValue; 605cdf0e10cSrcweir SetEmptyFieldValueData( sal_False ); 606cdf0e10cSrcweir } 607cdf0e10cSrcweir 608cdf0e10cSrcweir // ----------------------------------------------------------------------- 609cdf0e10cSrcweir 610cdf0e10cSrcweir XubString NumericFormatter::CreateFieldText( sal_Int64 nValue ) const 611cdf0e10cSrcweir { 612cdf0e10cSrcweir return ImplGetLocaleDataWrapper().getNum( nValue, GetDecimalDigits(), IsUseThousandSep(), IsShowTrailingZeros() ); 613cdf0e10cSrcweir } 614cdf0e10cSrcweir 615cdf0e10cSrcweir // ----------------------------------------------------------------------- 616cdf0e10cSrcweir 617cdf0e10cSrcweir void NumericFormatter::ImplSetUserValue( sal_Int64 nNewValue, Selection* pNewSelection ) 618cdf0e10cSrcweir { 619cdf0e10cSrcweir if ( nNewValue > mnMax ) 620cdf0e10cSrcweir nNewValue = mnMax; 621cdf0e10cSrcweir else if ( nNewValue < mnMin ) 622cdf0e10cSrcweir nNewValue = mnMin; 623cdf0e10cSrcweir mnLastValue = nNewValue; 624cdf0e10cSrcweir 625cdf0e10cSrcweir if ( GetField() ) 626cdf0e10cSrcweir ImplSetText( CreateFieldText( nNewValue ), pNewSelection ); 627cdf0e10cSrcweir } 628cdf0e10cSrcweir 629cdf0e10cSrcweir // ----------------------------------------------------------------------- 630cdf0e10cSrcweir 631cdf0e10cSrcweir void NumericFormatter::SetUserValue( sal_Int64 nNewValue ) 632cdf0e10cSrcweir { 633cdf0e10cSrcweir ImplSetUserValue( nNewValue ); 634cdf0e10cSrcweir } 635cdf0e10cSrcweir 636cdf0e10cSrcweir // ----------------------------------------------------------------------- 637cdf0e10cSrcweir 638cdf0e10cSrcweir sal_Int64 NumericFormatter::GetValue() const 639cdf0e10cSrcweir { 640cdf0e10cSrcweir if ( !GetField() ) 641cdf0e10cSrcweir return 0; 642cdf0e10cSrcweir 643cdf0e10cSrcweir double nTempValue; 644cdf0e10cSrcweir 645cdf0e10cSrcweir if ( ImplNumericGetValue( GetField()->GetText(), nTempValue, 646cdf0e10cSrcweir GetDecimalDigits(), ImplGetLocaleDataWrapper() ) ) 647cdf0e10cSrcweir { 648cdf0e10cSrcweir // caution: precision loss in double cast 649cdf0e10cSrcweir if ( nTempValue > mnMax ) 650cdf0e10cSrcweir nTempValue = (double)mnMax; 651cdf0e10cSrcweir else if ( nTempValue < mnMin ) 652cdf0e10cSrcweir nTempValue = (double)mnMin; 653cdf0e10cSrcweir return (sal_Int64)nTempValue; 654cdf0e10cSrcweir } 655cdf0e10cSrcweir else 656cdf0e10cSrcweir return mnLastValue; 657cdf0e10cSrcweir } 658cdf0e10cSrcweir 659cdf0e10cSrcweir // ----------------------------------------------------------------------- 660cdf0e10cSrcweir 661cdf0e10cSrcweir sal_Bool NumericFormatter::IsValueModified() const 662cdf0e10cSrcweir { 663cdf0e10cSrcweir if ( ImplGetEmptyFieldValue() ) 664cdf0e10cSrcweir return !IsEmptyFieldValue(); 665cdf0e10cSrcweir else if ( GetValue() != mnFieldValue ) 666cdf0e10cSrcweir return sal_True; 667cdf0e10cSrcweir else 668cdf0e10cSrcweir return sal_False; 669cdf0e10cSrcweir } 670cdf0e10cSrcweir 671cdf0e10cSrcweir // ----------------------------------------------------------------------- 672cdf0e10cSrcweir 673cdf0e10cSrcweir Fraction NumericFormatter::ConvertToFraction( sal_Int64 nValue ) 674cdf0e10cSrcweir { 675cdf0e10cSrcweir // caution: precision loss in double cast (and in fraction anyhow) 676cdf0e10cSrcweir return Fraction( (double)nValue/(double)ImplPower10( GetDecimalDigits() ) ); 677cdf0e10cSrcweir } 678cdf0e10cSrcweir 679cdf0e10cSrcweir // ----------------------------------------------------------------------- 680cdf0e10cSrcweir 681cdf0e10cSrcweir sal_Int64 NumericFormatter::ConvertToLong( const Fraction& rValue ) 682cdf0e10cSrcweir { 683cdf0e10cSrcweir Fraction aFract = rValue; 684cdf0e10cSrcweir aFract *= Fraction( (long)ImplPower10( GetDecimalDigits() ), 1 ); 685cdf0e10cSrcweir return (sal_Int64)(double)aFract; 686cdf0e10cSrcweir } 687cdf0e10cSrcweir 688cdf0e10cSrcweir // ----------------------------------------------------------------------- 689cdf0e10cSrcweir 690cdf0e10cSrcweir sal_Int64 NumericFormatter::Normalize( sal_Int64 nValue ) const 691cdf0e10cSrcweir { 692cdf0e10cSrcweir return (nValue * ImplPower10( GetDecimalDigits() ) ); 693cdf0e10cSrcweir } 694cdf0e10cSrcweir 695cdf0e10cSrcweir // ----------------------------------------------------------------------- 696cdf0e10cSrcweir 697cdf0e10cSrcweir sal_Int64 NumericFormatter::Denormalize( sal_Int64 nValue ) const 698cdf0e10cSrcweir { 699cdf0e10cSrcweir sal_Int64 nFactor = ImplPower10( GetDecimalDigits() ); 7005abfe151SYuri Dario 7015abfe151SYuri Dario if((nValue < ( SAL_MIN_INT64 + nFactor )) || 7025abfe151SYuri Dario (nValue > ( SAL_MAX_INT64 - nFactor ))) 7035abfe151SYuri Dario return ( nValue / nFactor ); 704cdf0e10cSrcweir if( nValue < 0 ) 705cdf0e10cSrcweir return ((nValue-(nFactor/2)) / nFactor ); 706cdf0e10cSrcweir else 707cdf0e10cSrcweir return ((nValue+(nFactor/2)) / nFactor ); 708cdf0e10cSrcweir } 709cdf0e10cSrcweir 710cdf0e10cSrcweir // ----------------------------------------------------------------------- 711cdf0e10cSrcweir 712cdf0e10cSrcweir void NumericFormatter::Reformat() 713cdf0e10cSrcweir { 714cdf0e10cSrcweir if ( !GetField() ) 715cdf0e10cSrcweir return; 716cdf0e10cSrcweir 717cdf0e10cSrcweir if ( !GetField()->GetText().Len() && ImplGetEmptyFieldValue() ) 718cdf0e10cSrcweir return; 719cdf0e10cSrcweir 720cdf0e10cSrcweir XubString aStr; 721cdf0e10cSrcweir // caution: precision loss in double cast 722cdf0e10cSrcweir double nTemp = (double)mnLastValue; 723cdf0e10cSrcweir sal_Bool bOK = ImplNumericReformat( GetField()->GetText(), nTemp, aStr ); 724cdf0e10cSrcweir mnLastValue = (sal_Int64)nTemp; 725cdf0e10cSrcweir if ( !bOK ) 726cdf0e10cSrcweir return; 727cdf0e10cSrcweir 728cdf0e10cSrcweir if ( aStr.Len() ) 729cdf0e10cSrcweir ImplSetText( aStr ); 730cdf0e10cSrcweir else 731cdf0e10cSrcweir SetValue( mnLastValue ); 732cdf0e10cSrcweir } 733cdf0e10cSrcweir 734cdf0e10cSrcweir // ----------------------------------------------------------------------- 735cdf0e10cSrcweir 736cdf0e10cSrcweir void NumericFormatter::FieldUp() 737cdf0e10cSrcweir { 738cdf0e10cSrcweir sal_Int64 nValue = GetValue(); 739cdf0e10cSrcweir nValue += mnSpinSize; 740cdf0e10cSrcweir if ( nValue > mnMax ) 741cdf0e10cSrcweir nValue = mnMax; 742cdf0e10cSrcweir 743cdf0e10cSrcweir ImplNewFieldValue( nValue ); 744cdf0e10cSrcweir } 745cdf0e10cSrcweir 746cdf0e10cSrcweir // ----------------------------------------------------------------------- 747cdf0e10cSrcweir 748cdf0e10cSrcweir void NumericFormatter::FieldDown() 749cdf0e10cSrcweir { 750cdf0e10cSrcweir sal_Int64 nValue = GetValue(); 751cdf0e10cSrcweir nValue -= mnSpinSize; 752cdf0e10cSrcweir if ( nValue < mnMin ) 753cdf0e10cSrcweir nValue = mnMin; 754cdf0e10cSrcweir 755cdf0e10cSrcweir ImplNewFieldValue( nValue ); 756cdf0e10cSrcweir } 757cdf0e10cSrcweir 758cdf0e10cSrcweir // ----------------------------------------------------------------------- 759cdf0e10cSrcweir 760cdf0e10cSrcweir void NumericFormatter::FieldFirst() 761cdf0e10cSrcweir { 762cdf0e10cSrcweir ImplNewFieldValue( mnFirst ); 763cdf0e10cSrcweir } 764cdf0e10cSrcweir 765cdf0e10cSrcweir // ----------------------------------------------------------------------- 766cdf0e10cSrcweir 767cdf0e10cSrcweir void NumericFormatter::FieldLast() 768cdf0e10cSrcweir { 769cdf0e10cSrcweir ImplNewFieldValue( mnLast ); 770cdf0e10cSrcweir } 771cdf0e10cSrcweir 772cdf0e10cSrcweir // ----------------------------------------------------------------------- 773cdf0e10cSrcweir 774cdf0e10cSrcweir void NumericFormatter::ImplNewFieldValue( sal_Int64 nNewValue ) 775cdf0e10cSrcweir { 776cdf0e10cSrcweir if ( GetField() ) 777cdf0e10cSrcweir { 778cdf0e10cSrcweir // !!! TH-18.2.99: Wenn wir Zeit haben sollte mal geklaert werden, 779cdf0e10cSrcweir // !!! warum nicht bei ImplSetUserValue() geprueft wird, ob 780cdf0e10cSrcweir // !!! sich der Wert aendert. Denn auch hier muesste dieses 781cdf0e10cSrcweir // !!! gemacht werden, da ansonsten der Modify-Aufruf 782cdf0e10cSrcweir // !!! nicht gemacht werden duerfte. Jedenfalls sollten die 783cdf0e10cSrcweir // !!! Wege von ImplNewFieldValue, ImplSetUserValue und 784cdf0e10cSrcweir // !!! ImplSetText ueberprueft und klarer gestalltet (mit Kommentar) 785cdf0e10cSrcweir // !!! werden, damit wir mal wissen, was dort ablaeuft!!! 786cdf0e10cSrcweir 787cdf0e10cSrcweir Selection aSelection = GetField()->GetSelection(); 788cdf0e10cSrcweir aSelection.Justify(); 789cdf0e10cSrcweir XubString aText = GetField()->GetText(); 790cdf0e10cSrcweir // Wenn bis ans Ende selektiert war, soll das auch so bleiben... 791cdf0e10cSrcweir if ( (xub_StrLen)aSelection.Max() == aText.Len() ) 792cdf0e10cSrcweir { 793cdf0e10cSrcweir if ( !aSelection.Len() ) 794cdf0e10cSrcweir aSelection.Min() = SELECTION_MAX; 795cdf0e10cSrcweir aSelection.Max() = SELECTION_MAX; 796cdf0e10cSrcweir } 797cdf0e10cSrcweir 798cdf0e10cSrcweir sal_Int64 nOldLastValue = mnLastValue; 799cdf0e10cSrcweir ImplSetUserValue( nNewValue, &aSelection ); 800cdf0e10cSrcweir mnLastValue = nOldLastValue; 801cdf0e10cSrcweir 802cdf0e10cSrcweir // Modify am Edit wird nur bei KeyInput gesetzt... 803cdf0e10cSrcweir if ( GetField()->GetText() != aText ) 804cdf0e10cSrcweir { 805cdf0e10cSrcweir GetField()->SetModifyFlag(); 806cdf0e10cSrcweir GetField()->Modify(); 807cdf0e10cSrcweir } 808cdf0e10cSrcweir } 809cdf0e10cSrcweir } 810cdf0e10cSrcweir 811cdf0e10cSrcweir // ----------------------------------------------------------------------- 812cdf0e10cSrcweir 813cdf0e10cSrcweir NumericField::NumericField( Window* pParent, WinBits nWinStyle ) : 814cdf0e10cSrcweir SpinField( pParent, nWinStyle ) 815cdf0e10cSrcweir { 816cdf0e10cSrcweir SetField( this ); 817cdf0e10cSrcweir Reformat(); 818cdf0e10cSrcweir } 819cdf0e10cSrcweir 820cdf0e10cSrcweir // ----------------------------------------------------------------------- 821cdf0e10cSrcweir 822cdf0e10cSrcweir NumericField::NumericField( Window* pParent, const ResId& rResId ) : 823cdf0e10cSrcweir SpinField( WINDOW_NUMERICFIELD ) 824cdf0e10cSrcweir { 825cdf0e10cSrcweir rResId.SetRT( RSC_NUMERICFIELD ); 826cdf0e10cSrcweir WinBits nStyle = ImplInitRes( rResId ) ; 827cdf0e10cSrcweir SpinField::ImplInit( pParent, nStyle ); 828cdf0e10cSrcweir SetField( this ); 829cdf0e10cSrcweir ImplLoadRes( rResId ); 830cdf0e10cSrcweir Reformat(); 831cdf0e10cSrcweir 832cdf0e10cSrcweir if ( !(nStyle & WB_HIDE ) ) 833cdf0e10cSrcweir Show(); 834cdf0e10cSrcweir } 835cdf0e10cSrcweir 836cdf0e10cSrcweir // ----------------------------------------------------------------------- 837cdf0e10cSrcweir 838cdf0e10cSrcweir void NumericField::ImplLoadRes( const ResId& rResId ) 839cdf0e10cSrcweir { 840cdf0e10cSrcweir SpinField::ImplLoadRes( rResId ); 841cdf0e10cSrcweir NumericFormatter::ImplLoadRes( ResId( (RSHEADER_TYPE *)GetClassRes(), *rResId.GetResMgr() ) ); 842cdf0e10cSrcweir 843cdf0e10cSrcweir sal_uLong nMask = ReadLongRes(); 844cdf0e10cSrcweir 845cdf0e10cSrcweir if ( NUMERICFIELD_FIRST & nMask ) 846cdf0e10cSrcweir mnFirst = ReadLongRes(); 847cdf0e10cSrcweir 848cdf0e10cSrcweir if ( NUMERICFIELD_LAST & nMask ) 849cdf0e10cSrcweir mnLast = ReadLongRes(); 850cdf0e10cSrcweir 851cdf0e10cSrcweir if ( NUMERICFIELD_SPINSIZE & nMask ) 852cdf0e10cSrcweir mnSpinSize = ReadLongRes(); 853cdf0e10cSrcweir } 854cdf0e10cSrcweir 855cdf0e10cSrcweir // ----------------------------------------------------------------------- 856cdf0e10cSrcweir 857cdf0e10cSrcweir NumericField::~NumericField() 858cdf0e10cSrcweir { 859cdf0e10cSrcweir } 860cdf0e10cSrcweir 861cdf0e10cSrcweir // ----------------------------------------------------------------------- 862cdf0e10cSrcweir 863cdf0e10cSrcweir long NumericField::PreNotify( NotifyEvent& rNEvt ) 864cdf0e10cSrcweir { 865cdf0e10cSrcweir if ( (rNEvt.GetType() == EVENT_KEYINPUT) && !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() ) 866cdf0e10cSrcweir { 867cdf0e10cSrcweir if ( ImplNumericProcessKeyInput( GetField(), *rNEvt.GetKeyEvent(), IsStrictFormat(), IsUseThousandSep(), ImplGetLocaleDataWrapper() ) ) 868cdf0e10cSrcweir return 1; 869cdf0e10cSrcweir } 870cdf0e10cSrcweir 871cdf0e10cSrcweir return SpinField::PreNotify( rNEvt ); 872cdf0e10cSrcweir } 873cdf0e10cSrcweir 874cdf0e10cSrcweir // ----------------------------------------------------------------------- 875cdf0e10cSrcweir 876cdf0e10cSrcweir long NumericField::Notify( NotifyEvent& rNEvt ) 877cdf0e10cSrcweir { 878cdf0e10cSrcweir if ( rNEvt.GetType() == EVENT_GETFOCUS ) 879cdf0e10cSrcweir MarkToBeReformatted( sal_False ); 880cdf0e10cSrcweir else if ( rNEvt.GetType() == EVENT_LOSEFOCUS ) 881cdf0e10cSrcweir { 882cdf0e10cSrcweir if ( MustBeReformatted() && (GetText().Len() || !IsEmptyFieldValueEnabled()) ) 883cdf0e10cSrcweir Reformat(); 884cdf0e10cSrcweir } 885cdf0e10cSrcweir 886cdf0e10cSrcweir return SpinField::Notify( rNEvt ); 887cdf0e10cSrcweir } 888cdf0e10cSrcweir 889cdf0e10cSrcweir // ----------------------------------------------------------------------- 890cdf0e10cSrcweir 891cdf0e10cSrcweir void NumericField::DataChanged( const DataChangedEvent& rDCEvt ) 892cdf0e10cSrcweir { 893cdf0e10cSrcweir SpinField::DataChanged( rDCEvt ); 894cdf0e10cSrcweir 895cdf0e10cSrcweir if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_LOCALE) ) 896cdf0e10cSrcweir { 897cdf0e10cSrcweir String sOldDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep(); 898cdf0e10cSrcweir String sOldThSep = ImplGetLocaleDataWrapper().getNumThousandSep(); 899cdf0e10cSrcweir if ( IsDefaultLocale() ) 900cdf0e10cSrcweir ImplGetLocaleDataWrapper().setLocale( GetSettings().GetLocale() ); 901cdf0e10cSrcweir String sNewDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep(); 902cdf0e10cSrcweir String sNewThSep = ImplGetLocaleDataWrapper().getNumThousandSep(); 903cdf0e10cSrcweir ImplUpdateSeparators( sOldDecSep, sNewDecSep, sOldThSep, sNewThSep, this ); 904cdf0e10cSrcweir ReformatAll(); 905cdf0e10cSrcweir } 906cdf0e10cSrcweir } 907cdf0e10cSrcweir 908cdf0e10cSrcweir // ----------------------------------------------------------------------- 909cdf0e10cSrcweir 910cdf0e10cSrcweir void NumericField::Modify() 911cdf0e10cSrcweir { 912cdf0e10cSrcweir MarkToBeReformatted( sal_True ); 913cdf0e10cSrcweir SpinField::Modify(); 914cdf0e10cSrcweir } 915cdf0e10cSrcweir 916cdf0e10cSrcweir // ----------------------------------------------------------------------- 917cdf0e10cSrcweir 918cdf0e10cSrcweir void NumericField::Up() 919cdf0e10cSrcweir { 920cdf0e10cSrcweir FieldUp(); 921cdf0e10cSrcweir SpinField::Up(); 922cdf0e10cSrcweir } 923cdf0e10cSrcweir 924cdf0e10cSrcweir // ----------------------------------------------------------------------- 925cdf0e10cSrcweir 926cdf0e10cSrcweir void NumericField::Down() 927cdf0e10cSrcweir { 928cdf0e10cSrcweir FieldDown(); 929cdf0e10cSrcweir SpinField::Down(); 930cdf0e10cSrcweir } 931cdf0e10cSrcweir 932cdf0e10cSrcweir // ----------------------------------------------------------------------- 933cdf0e10cSrcweir 934cdf0e10cSrcweir void NumericField::First() 935cdf0e10cSrcweir { 936cdf0e10cSrcweir FieldFirst(); 937cdf0e10cSrcweir SpinField::First(); 938cdf0e10cSrcweir } 939cdf0e10cSrcweir 940cdf0e10cSrcweir // ----------------------------------------------------------------------- 941cdf0e10cSrcweir 942cdf0e10cSrcweir void NumericField::Last() 943cdf0e10cSrcweir { 944cdf0e10cSrcweir FieldLast(); 945cdf0e10cSrcweir SpinField::Last(); 946cdf0e10cSrcweir } 947cdf0e10cSrcweir 948cdf0e10cSrcweir // ----------------------------------------------------------------------- 949cdf0e10cSrcweir 950cdf0e10cSrcweir NumericBox::NumericBox( Window* pParent, WinBits nWinStyle ) : 951cdf0e10cSrcweir ComboBox( pParent, nWinStyle ) 952cdf0e10cSrcweir { 953cdf0e10cSrcweir SetField( this ); 954cdf0e10cSrcweir Reformat(); 955cdf0e10cSrcweir } 956cdf0e10cSrcweir 957cdf0e10cSrcweir // ----------------------------------------------------------------------- 958cdf0e10cSrcweir 959cdf0e10cSrcweir NumericBox::NumericBox( Window* pParent, const ResId& rResId ) : 960cdf0e10cSrcweir ComboBox( WINDOW_NUMERICBOX ) 961cdf0e10cSrcweir { 962cdf0e10cSrcweir rResId.SetRT( RSC_NUMERICBOX ); 963cdf0e10cSrcweir WinBits nStyle = ImplInitRes( rResId ); 964cdf0e10cSrcweir ComboBox::ImplInit( pParent, nStyle ); 965cdf0e10cSrcweir SetField( this ); 966cdf0e10cSrcweir ComboBox::ImplLoadRes( rResId ); 967cdf0e10cSrcweir NumericFormatter::ImplLoadRes( ResId( (RSHEADER_TYPE *)GetClassRes(), *rResId.GetResMgr() ) ); 968cdf0e10cSrcweir Reformat(); 969cdf0e10cSrcweir 970cdf0e10cSrcweir if ( !(nStyle & WB_HIDE ) ) 971cdf0e10cSrcweir Show(); 972cdf0e10cSrcweir } 973cdf0e10cSrcweir 974cdf0e10cSrcweir // ----------------------------------------------------------------------- 975cdf0e10cSrcweir 976cdf0e10cSrcweir NumericBox::~NumericBox() 977cdf0e10cSrcweir { 978cdf0e10cSrcweir } 979cdf0e10cSrcweir 980cdf0e10cSrcweir // ----------------------------------------------------------------------- 981cdf0e10cSrcweir 982cdf0e10cSrcweir long NumericBox::PreNotify( NotifyEvent& rNEvt ) 983cdf0e10cSrcweir { 984cdf0e10cSrcweir if ( (rNEvt.GetType() == EVENT_KEYINPUT) && !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() ) 985cdf0e10cSrcweir { 986cdf0e10cSrcweir if ( ImplNumericProcessKeyInput( GetField(), *rNEvt.GetKeyEvent(), IsStrictFormat(), IsUseThousandSep(), ImplGetLocaleDataWrapper() ) ) 987cdf0e10cSrcweir return 1; 988cdf0e10cSrcweir } 989cdf0e10cSrcweir 990cdf0e10cSrcweir return ComboBox::PreNotify( rNEvt ); 991cdf0e10cSrcweir } 992cdf0e10cSrcweir 993cdf0e10cSrcweir // ----------------------------------------------------------------------- 994cdf0e10cSrcweir 995cdf0e10cSrcweir long NumericBox::Notify( NotifyEvent& rNEvt ) 996cdf0e10cSrcweir { 997cdf0e10cSrcweir if ( rNEvt.GetType() == EVENT_GETFOCUS ) 998cdf0e10cSrcweir MarkToBeReformatted( sal_False ); 999cdf0e10cSrcweir else if ( rNEvt.GetType() == EVENT_LOSEFOCUS ) 1000cdf0e10cSrcweir { 1001cdf0e10cSrcweir if ( MustBeReformatted() && (GetText().Len() || !IsEmptyFieldValueEnabled()) ) 1002cdf0e10cSrcweir Reformat(); 1003cdf0e10cSrcweir } 1004cdf0e10cSrcweir 1005cdf0e10cSrcweir return ComboBox::Notify( rNEvt ); 1006cdf0e10cSrcweir } 1007cdf0e10cSrcweir 1008cdf0e10cSrcweir // ----------------------------------------------------------------------- 1009cdf0e10cSrcweir 1010cdf0e10cSrcweir void NumericBox::DataChanged( const DataChangedEvent& rDCEvt ) 1011cdf0e10cSrcweir { 1012cdf0e10cSrcweir ComboBox::DataChanged( rDCEvt ); 1013cdf0e10cSrcweir 1014cdf0e10cSrcweir if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_LOCALE) ) 1015cdf0e10cSrcweir { 1016cdf0e10cSrcweir String sOldDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep(); 1017cdf0e10cSrcweir String sOldThSep = ImplGetLocaleDataWrapper().getNumThousandSep(); 1018cdf0e10cSrcweir if ( IsDefaultLocale() ) 1019cdf0e10cSrcweir ImplGetLocaleDataWrapper().setLocale( GetSettings().GetLocale() ); 1020cdf0e10cSrcweir String sNewDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep(); 1021cdf0e10cSrcweir String sNewThSep = ImplGetLocaleDataWrapper().getNumThousandSep(); 1022cdf0e10cSrcweir ImplUpdateSeparators( sOldDecSep, sNewDecSep, sOldThSep, sNewThSep, this ); 1023cdf0e10cSrcweir ReformatAll(); 1024cdf0e10cSrcweir } 1025cdf0e10cSrcweir } 1026cdf0e10cSrcweir 1027cdf0e10cSrcweir // ----------------------------------------------------------------------- 1028cdf0e10cSrcweir 1029cdf0e10cSrcweir void NumericBox::Modify() 1030cdf0e10cSrcweir { 1031cdf0e10cSrcweir MarkToBeReformatted( sal_True ); 1032cdf0e10cSrcweir ComboBox::Modify(); 1033cdf0e10cSrcweir } 1034cdf0e10cSrcweir 1035cdf0e10cSrcweir // ----------------------------------------------------------------------- 1036cdf0e10cSrcweir 1037cdf0e10cSrcweir void NumericBox::ReformatAll() 1038cdf0e10cSrcweir { 1039cdf0e10cSrcweir double nValue; 1040cdf0e10cSrcweir XubString aStr; 1041cdf0e10cSrcweir SetUpdateMode( sal_False ); 1042cdf0e10cSrcweir sal_uInt16 nEntryCount = GetEntryCount(); 1043cdf0e10cSrcweir for ( sal_uInt16 i=0; i < nEntryCount; i++ ) 1044cdf0e10cSrcweir { 1045cdf0e10cSrcweir ImplNumericReformat( GetEntry( i ), nValue, aStr ); 1046cdf0e10cSrcweir RemoveEntry( i ); 1047cdf0e10cSrcweir InsertEntry( aStr, i ); 1048cdf0e10cSrcweir } 1049cdf0e10cSrcweir NumericFormatter::Reformat(); 1050cdf0e10cSrcweir SetUpdateMode( sal_True ); 1051cdf0e10cSrcweir } 1052cdf0e10cSrcweir 1053cdf0e10cSrcweir // ----------------------------------------------------------------------- 1054cdf0e10cSrcweir 1055cdf0e10cSrcweir void NumericBox::InsertValue( sal_Int64 nValue, sal_uInt16 nPos ) 1056cdf0e10cSrcweir { 1057cdf0e10cSrcweir ComboBox::InsertEntry( CreateFieldText( nValue ), nPos ); 1058cdf0e10cSrcweir } 1059cdf0e10cSrcweir 1060cdf0e10cSrcweir // ----------------------------------------------------------------------- 1061cdf0e10cSrcweir 1062cdf0e10cSrcweir void NumericBox::RemoveValue( sal_Int64 nValue ) 1063cdf0e10cSrcweir { 1064cdf0e10cSrcweir ComboBox::RemoveEntry( CreateFieldText( nValue ) ); 1065cdf0e10cSrcweir } 1066cdf0e10cSrcweir 1067cdf0e10cSrcweir // ----------------------------------------------------------------------- 1068cdf0e10cSrcweir 1069cdf0e10cSrcweir sal_Int64 NumericBox::GetValue( sal_uInt16 nPos ) const 1070cdf0e10cSrcweir { 1071cdf0e10cSrcweir double nValue = 0; 1072cdf0e10cSrcweir ImplNumericGetValue( ComboBox::GetEntry( nPos ), nValue, GetDecimalDigits(), ImplGetLocaleDataWrapper() ); 1073cdf0e10cSrcweir return (sal_Int64)nValue; 1074cdf0e10cSrcweir } 1075cdf0e10cSrcweir 1076cdf0e10cSrcweir // ----------------------------------------------------------------------- 1077cdf0e10cSrcweir 1078cdf0e10cSrcweir sal_uInt16 NumericBox::GetValuePos( sal_Int64 nValue ) const 1079cdf0e10cSrcweir { 1080cdf0e10cSrcweir return ComboBox::GetEntryPos( CreateFieldText( nValue ) ); 1081cdf0e10cSrcweir } 1082cdf0e10cSrcweir 1083cdf0e10cSrcweir // ----------------------------------------------------------------------- 1084cdf0e10cSrcweir 1085cdf0e10cSrcweir static sal_Bool ImplMetricProcessKeyInput( Edit* pEdit, const KeyEvent& rKEvt, 1086cdf0e10cSrcweir sal_Bool, sal_Bool bUseThousandSep, const LocaleDataWrapper& rWrapper ) 1087cdf0e10cSrcweir { 1088cdf0e10cSrcweir // Es gibt hier kein sinnvolles StrictFormat, also alle 1089cdf0e10cSrcweir // Zeichen erlauben 1090cdf0e10cSrcweir return ImplNumericProcessKeyInput( pEdit, rKEvt, sal_False, bUseThousandSep, rWrapper ); 1091cdf0e10cSrcweir } 1092cdf0e10cSrcweir 1093cdf0e10cSrcweir // ----------------------------------------------------------------------- 1094cdf0e10cSrcweir 1095cdf0e10cSrcweir static XubString ImplMetricGetUnitText( const XubString& rStr ) 1096cdf0e10cSrcweir { 1097cdf0e10cSrcweir // Einheitentext holen 1098cdf0e10cSrcweir XubString aStr; 1099cdf0e10cSrcweir for ( short i = rStr.Len()-1; i >= 0; i-- ) 1100cdf0e10cSrcweir { 1101cdf0e10cSrcweir xub_Unicode c = rStr.GetChar( i ); 1102cdf0e10cSrcweir if ( unicode::isAlpha( c ) || 1103cdf0e10cSrcweir (c == '\'') || (c == '\"') || (c == '%' ) ) 1104cdf0e10cSrcweir aStr.Insert( c, 0 ); 1105cdf0e10cSrcweir else 1106cdf0e10cSrcweir { 1107cdf0e10cSrcweir if ( aStr.Len() ) 1108cdf0e10cSrcweir break; 1109cdf0e10cSrcweir } 1110cdf0e10cSrcweir } 1111cdf0e10cSrcweir return aStr; 1112cdf0e10cSrcweir 1113cdf0e10cSrcweir /* 1114cdf0e10cSrcweir // MT: #90545# Preparation for translated strings... 1115cdf0e10cSrcweir String aMetricText; 1116cdf0e10cSrcweir for ( sal_uInt16 n = rStr.Len(); n; ) 1117cdf0e10cSrcweir { 1118cdf0e10cSrcweir sal_Unicode c = rStr.GetChar( --n ); 1119cdf0e10cSrcweir sal_Int32 nType = xCharClass->getStringType( rStr, n, 1, rLocale ); 1120cdf0e10cSrcweir 1121cdf0e10cSrcweir if ( CharClass::isLetterType( nType ) ) 1122cdf0e10cSrcweir { 1123cdf0e10cSrcweir aMetricText.Insert( c, 0 ); 1124cdf0e10cSrcweir } 1125cdf0e10cSrcweir else 1126cdf0e10cSrcweir { 1127cdf0e10cSrcweir if ( aMetricText.Len() ) 1128cdf0e10cSrcweir break; 1129cdf0e10cSrcweir } 1130cdf0e10cSrcweir } 1131cdf0e10cSrcweir */ 1132cdf0e10cSrcweir } 1133cdf0e10cSrcweir 1134cdf0e10cSrcweir // ----------------------------------------------------------------------- 1135cdf0e10cSrcweir 1136cdf0e10cSrcweir // #104355# support localized mesaurements 1137cdf0e10cSrcweir 1138cdf0e10cSrcweir static const String& ImplMetricToString( FieldUnit rUnit ) 1139cdf0e10cSrcweir { 1140cdf0e10cSrcweir FieldUnitStringList* pList = ImplGetFieldUnits(); 1141cdf0e10cSrcweir if( pList ) 1142cdf0e10cSrcweir { 1143cdf0e10cSrcweir // return unit's default string (ie, the first one ) 1144cdf0e10cSrcweir for( FieldUnitStringList::const_iterator it = pList->begin(); it != pList->end(); ++it ) 1145cdf0e10cSrcweir { 1146cdf0e10cSrcweir if ( it->second == rUnit ) 1147cdf0e10cSrcweir return it->first; 1148cdf0e10cSrcweir } 1149cdf0e10cSrcweir } 1150cdf0e10cSrcweir 1151cdf0e10cSrcweir return String::EmptyString(); 1152cdf0e10cSrcweir } 1153cdf0e10cSrcweir 1154cdf0e10cSrcweir static FieldUnit ImplStringToMetric( const String &rMetricString ) 1155cdf0e10cSrcweir { 1156cdf0e10cSrcweir FieldUnitStringList* pList = ImplGetCleanedFieldUnits(); 1157cdf0e10cSrcweir if( pList ) 1158cdf0e10cSrcweir { 1159cdf0e10cSrcweir // return FieldUnit 1160cdf0e10cSrcweir String aStr( rMetricString ); 1161cdf0e10cSrcweir aStr.ToLowerAscii(); 1162cdf0e10cSrcweir aStr.EraseAllChars( sal_Unicode( ' ' ) ); 1163cdf0e10cSrcweir for( FieldUnitStringList::const_iterator it = pList->begin(); it != pList->end(); ++it ) 1164cdf0e10cSrcweir { 1165cdf0e10cSrcweir if ( it->first.Equals( aStr ) ) 1166cdf0e10cSrcweir return it->second; 1167cdf0e10cSrcweir } 1168cdf0e10cSrcweir } 1169cdf0e10cSrcweir 1170cdf0e10cSrcweir return FUNIT_NONE; 1171cdf0e10cSrcweir } 1172cdf0e10cSrcweir 1173cdf0e10cSrcweir // ----------------------------------------------------------------------- 1174cdf0e10cSrcweir 1175cdf0e10cSrcweir static FieldUnit ImplMetricGetUnit( const XubString& rStr ) 1176cdf0e10cSrcweir { 1177cdf0e10cSrcweir XubString aStr = ImplMetricGetUnitText( rStr ); 1178cdf0e10cSrcweir return ImplStringToMetric( aStr ); 1179cdf0e10cSrcweir } 1180cdf0e10cSrcweir 1181cdf0e10cSrcweir #define K *1000L 1182cdf0e10cSrcweir #define M *1000000L 1183cdf0e10cSrcweir #define X *5280L 1184cdf0e10cSrcweir 1185cdf0e10cSrcweir static const sal_Int64 aImplFactor[FUNIT_MILE+1][FUNIT_MILE+1] = 1186cdf0e10cSrcweir { /* 1187cdf0e10cSrcweir mm/100 mm cm m km twip point pica inch foot mile */ 1188cdf0e10cSrcweir { 1, 100, 1 K, 100 K, 100 M, 2540, 2540, 2540, 2540,2540*12,2540*12 X }, 1189cdf0e10cSrcweir { 1, 1, 10, 1 K, 1 M, 2540, 2540, 2540, 2540,2540*12,2540*12 X }, 1190cdf0e10cSrcweir { 1, 1, 1, 100, 100 K, 254, 254, 254, 254, 254*12, 254*12 X }, 1191cdf0e10cSrcweir { 1, 1, 1, 1, 1 K, 254, 254, 254, 254, 254*12, 254*12 X }, 1192cdf0e10cSrcweir { 1, 1, 1, 1, 1, 0, 254, 254, 254, 254*12, 254*12 X }, 1193cdf0e10cSrcweir { 1440,144 K,144 K,14400 K, 0, 1, 20, 240, 1440,1440*12,1440*12 X }, 1194cdf0e10cSrcweir { 72, 7200, 7200, 720 K, 720 M, 1, 1, 12, 72, 72*12, 72*12 X }, 1195cdf0e10cSrcweir { 6, 600, 600, 60 K, 60 M, 1, 1, 1, 6, 6*12, 6*12 X }, 1196cdf0e10cSrcweir { 1, 100, 100, 10 K, 10 M, 1, 1, 1, 1, 12, 12 X }, 1197cdf0e10cSrcweir { 1, 100, 100, 10 K, 10 M, 1, 1, 1, 1, 1, 1 X }, 1198cdf0e10cSrcweir { 1, 100, 100, 10 K, 10 M, 1, 1, 1, 1, 1, 1 } 1199cdf0e10cSrcweir }; 1200cdf0e10cSrcweir 1201cdf0e10cSrcweir #undef X 1202cdf0e10cSrcweir #undef M 1203cdf0e10cSrcweir #undef K 1204cdf0e10cSrcweir // twip in km 254/14400 M 1205cdf0e10cSrcweir 1206cdf0e10cSrcweir static FieldUnit eDefaultUnit = FUNIT_NONE; 1207cdf0e10cSrcweir 1208cdf0e10cSrcweir FieldUnit MetricField::GetDefaultUnit() { return eDefaultUnit; } 1209cdf0e10cSrcweir void MetricField::SetDefaultUnit( FieldUnit meUnit ) { eDefaultUnit = meUnit; } 1210cdf0e10cSrcweir 1211cdf0e10cSrcweir static FieldUnit ImplMap2FieldUnit( MapUnit meUnit, long& nDecDigits ) 1212cdf0e10cSrcweir { 1213cdf0e10cSrcweir switch( meUnit ) 1214cdf0e10cSrcweir { 1215cdf0e10cSrcweir case MAP_100TH_MM : 1216cdf0e10cSrcweir nDecDigits -= 2; 1217cdf0e10cSrcweir return FUNIT_MM; 1218cdf0e10cSrcweir case MAP_10TH_MM : 1219cdf0e10cSrcweir nDecDigits -= 1; 1220cdf0e10cSrcweir return FUNIT_MM; 1221cdf0e10cSrcweir case MAP_MM : 1222cdf0e10cSrcweir return FUNIT_MM; 1223cdf0e10cSrcweir case MAP_CM : 1224cdf0e10cSrcweir return FUNIT_CM; 1225cdf0e10cSrcweir case MAP_1000TH_INCH : 1226cdf0e10cSrcweir nDecDigits -= 3; 1227cdf0e10cSrcweir return FUNIT_INCH; 1228cdf0e10cSrcweir case MAP_100TH_INCH : 1229cdf0e10cSrcweir nDecDigits -= 2; 1230cdf0e10cSrcweir return FUNIT_INCH; 1231cdf0e10cSrcweir case MAP_10TH_INCH : 1232cdf0e10cSrcweir nDecDigits -= 1; 1233cdf0e10cSrcweir return FUNIT_INCH; 1234cdf0e10cSrcweir case MAP_INCH : 1235cdf0e10cSrcweir return FUNIT_INCH; 1236cdf0e10cSrcweir case MAP_POINT : 1237cdf0e10cSrcweir return FUNIT_POINT; 1238cdf0e10cSrcweir case MAP_TWIP : 1239cdf0e10cSrcweir return FUNIT_TWIP; 1240cdf0e10cSrcweir default: 1241cdf0e10cSrcweir DBG_ERROR( "default eInUnit" ); 1242cdf0e10cSrcweir break; 1243cdf0e10cSrcweir } 1244cdf0e10cSrcweir return FUNIT_NONE; 1245cdf0e10cSrcweir } 1246cdf0e10cSrcweir 1247cdf0e10cSrcweir // ----------------------------------------------------------------------- 1248cdf0e10cSrcweir 1249cdf0e10cSrcweir static double nonValueDoubleToValueDouble( double nValue ) 1250cdf0e10cSrcweir { 1251cdf0e10cSrcweir return rtl::math::isFinite( nValue ) ? nValue : 0.0; 1252cdf0e10cSrcweir } 1253cdf0e10cSrcweir 1254cdf0e10cSrcweir sal_Int64 MetricField::ConvertValue( sal_Int64 nValue, sal_Int64 mnBaseValue, sal_uInt16 nDecDigits, 1255cdf0e10cSrcweir FieldUnit eInUnit, FieldUnit eOutUnit ) 1256cdf0e10cSrcweir { 12575abfe151SYuri Dario double nDouble = nonValueDoubleToValueDouble( ConvertDoubleValue( 12585abfe151SYuri Dario (double)nValue, mnBaseValue, nDecDigits, eInUnit, eOutUnit ) ); 12595abfe151SYuri Dario sal_Int64 nLong ; 12605abfe151SYuri Dario 1261cdf0e10cSrcweir // caution: precision loss in double cast 12625abfe151SYuri Dario if ( nDouble <= (double)SAL_MIN_INT64 ) 12635abfe151SYuri Dario nLong = SAL_MIN_INT64; 12645abfe151SYuri Dario else if ( nDouble >= (double)SAL_MAX_INT64 ) 12655abfe151SYuri Dario nLong = SAL_MAX_INT64; 12665abfe151SYuri Dario else 12675abfe151SYuri Dario nLong = static_cast<sal_Int64>( nDouble ); 12685abfe151SYuri Dario return ( nLong ); 1269cdf0e10cSrcweir } 1270cdf0e10cSrcweir 1271cdf0e10cSrcweir // ----------------------------------------------------------------------- 1272cdf0e10cSrcweir 1273cdf0e10cSrcweir sal_Int64 MetricField::ConvertValue( sal_Int64 nValue, sal_uInt16 nDigits, 1274cdf0e10cSrcweir MapUnit eInUnit, FieldUnit eOutUnit ) 1275cdf0e10cSrcweir { 1276cdf0e10cSrcweir return static_cast<sal_Int64>( 1277cdf0e10cSrcweir nonValueDoubleToValueDouble( 1278cdf0e10cSrcweir ConvertDoubleValue( nValue, nDigits, eInUnit, eOutUnit ) ) ); 1279cdf0e10cSrcweir } 1280cdf0e10cSrcweir 1281cdf0e10cSrcweir // ----------------------------------------------------------------------- 1282cdf0e10cSrcweir 1283cdf0e10cSrcweir sal_Int64 MetricField::ConvertValue( sal_Int64 nValue, sal_uInt16 nDigits, 1284cdf0e10cSrcweir FieldUnit eInUnit, MapUnit eOutUnit ) 1285cdf0e10cSrcweir { 1286cdf0e10cSrcweir return static_cast<sal_Int64>( 1287cdf0e10cSrcweir // #150733# cast double to sal_Int64 can throw a 1288cdf0e10cSrcweir // EXCEPTION_FLT_INVALID_OPERATION on Windows 1289cdf0e10cSrcweir nonValueDoubleToValueDouble( 1290cdf0e10cSrcweir ConvertDoubleValue( nValue, nDigits, eInUnit, eOutUnit ) ) ); 1291cdf0e10cSrcweir } 1292cdf0e10cSrcweir 1293cdf0e10cSrcweir // ----------------------------------------------------------------------- 1294cdf0e10cSrcweir 1295cdf0e10cSrcweir double MetricField::ConvertDoubleValue( double nValue, sal_Int64 mnBaseValue, sal_uInt16 nDecDigits, 1296cdf0e10cSrcweir FieldUnit eInUnit, FieldUnit eOutUnit ) 1297cdf0e10cSrcweir { 1298cdf0e10cSrcweir if ( eInUnit != eOutUnit ) 1299cdf0e10cSrcweir { 1300cdf0e10cSrcweir sal_Int64 nMult = 1, nDiv = 1; 1301cdf0e10cSrcweir 1302cdf0e10cSrcweir if ( eInUnit == FUNIT_PERCENT ) 1303cdf0e10cSrcweir { 1304cdf0e10cSrcweir if ( (mnBaseValue <= 0) || (nValue <= 0) ) 1305cdf0e10cSrcweir return nValue; 1306cdf0e10cSrcweir nDiv = 100; 1307cdf0e10cSrcweir for ( sal_uInt16 i=0; i < nDecDigits; i++ ) 1308cdf0e10cSrcweir nDiv *= 10; 1309cdf0e10cSrcweir 1310cdf0e10cSrcweir nMult = mnBaseValue; 1311cdf0e10cSrcweir } 1312cdf0e10cSrcweir else if ( eOutUnit == FUNIT_PERCENT || 1313cdf0e10cSrcweir eOutUnit == FUNIT_CUSTOM || 1314cdf0e10cSrcweir eOutUnit == FUNIT_NONE || 1315cdf0e10cSrcweir eInUnit == FUNIT_CUSTOM || 1316cdf0e10cSrcweir eInUnit == FUNIT_NONE ) 1317cdf0e10cSrcweir return nValue; 1318cdf0e10cSrcweir else 1319cdf0e10cSrcweir { 1320cdf0e10cSrcweir if ( eOutUnit == FUNIT_100TH_MM ) 1321cdf0e10cSrcweir eOutUnit = FUNIT_NONE; 1322cdf0e10cSrcweir if ( eInUnit == FUNIT_100TH_MM ) 1323cdf0e10cSrcweir eInUnit = FUNIT_NONE; 1324cdf0e10cSrcweir 1325cdf0e10cSrcweir nDiv = aImplFactor[eInUnit][eOutUnit]; 1326cdf0e10cSrcweir nMult = aImplFactor[eOutUnit][eInUnit]; 1327cdf0e10cSrcweir 1328cdf0e10cSrcweir DBG_ASSERT( nMult > 0, "illegal *" ); 1329cdf0e10cSrcweir DBG_ASSERT( nDiv > 0, "illegal /" ); 1330cdf0e10cSrcweir } 1331cdf0e10cSrcweir 1332cdf0e10cSrcweir if ( nMult != 1 && nMult > 0 ) 1333cdf0e10cSrcweir nValue *= nMult; 1334cdf0e10cSrcweir if ( nDiv != 1 && nDiv > 0 ) 1335cdf0e10cSrcweir { 1336cdf0e10cSrcweir nValue += ( nValue < 0 ) ? (-nDiv/2) : (nDiv/2); 1337cdf0e10cSrcweir nValue /= nDiv; 1338cdf0e10cSrcweir } 1339cdf0e10cSrcweir } 1340cdf0e10cSrcweir 1341cdf0e10cSrcweir return nValue; 1342cdf0e10cSrcweir } 1343cdf0e10cSrcweir 1344cdf0e10cSrcweir // ----------------------------------------------------------------------- 1345cdf0e10cSrcweir 1346cdf0e10cSrcweir double MetricField::ConvertDoubleValue( double nValue, sal_uInt16 nDigits, 1347cdf0e10cSrcweir MapUnit eInUnit, FieldUnit eOutUnit ) 1348cdf0e10cSrcweir { 1349cdf0e10cSrcweir if ( eOutUnit == FUNIT_PERCENT || 1350cdf0e10cSrcweir eOutUnit == FUNIT_CUSTOM || 1351cdf0e10cSrcweir eOutUnit == FUNIT_NONE || 1352cdf0e10cSrcweir eInUnit == MAP_PIXEL || 1353cdf0e10cSrcweir eInUnit == MAP_SYSFONT || 1354cdf0e10cSrcweir eInUnit == MAP_APPFONT || 1355cdf0e10cSrcweir eInUnit == MAP_RELATIVE ) 1356cdf0e10cSrcweir { 1357cdf0e10cSrcweir DBG_ERROR( "invalid parameters" ); 1358cdf0e10cSrcweir return nValue; 1359cdf0e10cSrcweir } 1360cdf0e10cSrcweir 1361cdf0e10cSrcweir long nDecDigits = nDigits; 1362cdf0e10cSrcweir FieldUnit eFieldUnit = ImplMap2FieldUnit( eInUnit, nDecDigits ); 1363cdf0e10cSrcweir 1364cdf0e10cSrcweir if ( nDecDigits < 0 ) 1365cdf0e10cSrcweir { 1366cdf0e10cSrcweir while ( nDecDigits ) 1367cdf0e10cSrcweir { 1368cdf0e10cSrcweir nValue += 5; 1369cdf0e10cSrcweir nValue /= 10; 1370cdf0e10cSrcweir nDecDigits++; 1371cdf0e10cSrcweir } 1372cdf0e10cSrcweir } 1373cdf0e10cSrcweir else 1374cdf0e10cSrcweir { 1375cdf0e10cSrcweir while ( nDecDigits ) 1376cdf0e10cSrcweir { 1377cdf0e10cSrcweir nValue *= 10; 1378cdf0e10cSrcweir nDecDigits--; 1379cdf0e10cSrcweir } 1380cdf0e10cSrcweir } 1381cdf0e10cSrcweir 1382cdf0e10cSrcweir if ( eFieldUnit != eOutUnit ) 1383cdf0e10cSrcweir { 1384cdf0e10cSrcweir sal_Int64 nDiv = aImplFactor[eFieldUnit][eOutUnit]; 1385cdf0e10cSrcweir sal_Int64 nMult = aImplFactor[eOutUnit][eFieldUnit]; 1386cdf0e10cSrcweir 1387cdf0e10cSrcweir DBG_ASSERT( nMult > 0, "illegal *" ); 1388cdf0e10cSrcweir DBG_ASSERT( nDiv > 0, "illegal /" ); 1389cdf0e10cSrcweir 1390cdf0e10cSrcweir if ( nMult != 1 && nMult > 0) 1391cdf0e10cSrcweir nValue *= nMult; 1392cdf0e10cSrcweir if ( nDiv != 1 && nDiv > 0 ) 1393cdf0e10cSrcweir { 1394cdf0e10cSrcweir nValue += (nValue < 0) ? (-nDiv/2) : (nDiv/2); 1395cdf0e10cSrcweir nValue /= nDiv; 1396cdf0e10cSrcweir } 1397cdf0e10cSrcweir } 1398cdf0e10cSrcweir return nValue; 1399cdf0e10cSrcweir } 1400cdf0e10cSrcweir 1401cdf0e10cSrcweir // ----------------------------------------------------------------------- 1402cdf0e10cSrcweir 1403cdf0e10cSrcweir double MetricField::ConvertDoubleValue( double nValue, sal_uInt16 nDigits, 1404cdf0e10cSrcweir FieldUnit eInUnit, MapUnit eOutUnit ) 1405cdf0e10cSrcweir { 1406cdf0e10cSrcweir if ( eInUnit == FUNIT_PERCENT || 1407cdf0e10cSrcweir eInUnit == FUNIT_CUSTOM || 1408cdf0e10cSrcweir eInUnit == FUNIT_NONE || 1409cdf0e10cSrcweir eOutUnit == MAP_PIXEL || 1410cdf0e10cSrcweir eOutUnit == MAP_SYSFONT || 1411cdf0e10cSrcweir eOutUnit == MAP_APPFONT || 1412cdf0e10cSrcweir eOutUnit == MAP_RELATIVE ) 1413cdf0e10cSrcweir { 1414cdf0e10cSrcweir DBG_ERROR( "invalid parameters" ); 1415cdf0e10cSrcweir return nValue; 1416cdf0e10cSrcweir } 1417cdf0e10cSrcweir 1418cdf0e10cSrcweir long nDecDigits = nDigits; 1419cdf0e10cSrcweir FieldUnit eFieldUnit = ImplMap2FieldUnit( eOutUnit, nDecDigits ); 1420cdf0e10cSrcweir 1421cdf0e10cSrcweir if ( nDecDigits < 0 ) 1422cdf0e10cSrcweir { 1423cdf0e10cSrcweir while ( nDecDigits ) 1424cdf0e10cSrcweir { 1425cdf0e10cSrcweir nValue *= 10; 1426cdf0e10cSrcweir nDecDigits++; 1427cdf0e10cSrcweir } 1428cdf0e10cSrcweir } 1429cdf0e10cSrcweir else 1430cdf0e10cSrcweir { 1431cdf0e10cSrcweir while ( nDecDigits ) 1432cdf0e10cSrcweir { 1433cdf0e10cSrcweir nValue += 5; 1434cdf0e10cSrcweir nValue /= 10; 1435cdf0e10cSrcweir nDecDigits--; 1436cdf0e10cSrcweir } 1437cdf0e10cSrcweir } 1438cdf0e10cSrcweir 1439cdf0e10cSrcweir if ( eFieldUnit != eInUnit ) 1440cdf0e10cSrcweir { 1441cdf0e10cSrcweir sal_Int64 nDiv = aImplFactor[eInUnit][eFieldUnit]; 1442cdf0e10cSrcweir sal_Int64 nMult = aImplFactor[eFieldUnit][eInUnit]; 1443cdf0e10cSrcweir 1444cdf0e10cSrcweir DBG_ASSERT( nMult > 0, "illegal *" ); 1445cdf0e10cSrcweir DBG_ASSERT( nDiv > 0, "illegal /" ); 1446cdf0e10cSrcweir 1447cdf0e10cSrcweir if( nMult != 1 && nMult > 0 ) 1448cdf0e10cSrcweir nValue *= nMult; 1449cdf0e10cSrcweir if( nDiv != 1 && nDiv > 0 ) 1450cdf0e10cSrcweir { 1451cdf0e10cSrcweir nValue += (nValue < 0) ? (-nDiv/2) : (nDiv/2); 1452cdf0e10cSrcweir nValue /= nDiv; 1453cdf0e10cSrcweir } 1454cdf0e10cSrcweir } 1455cdf0e10cSrcweir return nValue; 1456cdf0e10cSrcweir } 1457cdf0e10cSrcweir 1458cdf0e10cSrcweir // ----------------------------------------------------------------------- 1459cdf0e10cSrcweir 1460cdf0e10cSrcweir static sal_Bool ImplMetricGetValue( const XubString& rStr, double& rValue, sal_Int64 nBaseValue, 1461cdf0e10cSrcweir sal_uInt16 nDecDigits, const LocaleDataWrapper& rLocaleDataWrapper, FieldUnit eUnit ) 1462cdf0e10cSrcweir { 1463cdf0e10cSrcweir // Zahlenwert holen 1464cdf0e10cSrcweir if ( !ImplNumericGetValue( rStr, rValue, nDecDigits, rLocaleDataWrapper ) ) 1465cdf0e10cSrcweir return sal_False; 1466cdf0e10cSrcweir 1467cdf0e10cSrcweir // Einheit rausfinden 1468cdf0e10cSrcweir FieldUnit eEntryUnit = ImplMetricGetUnit( rStr ); 1469cdf0e10cSrcweir 1470cdf0e10cSrcweir // Einheiten umrechnen 1471cdf0e10cSrcweir rValue = MetricField::ConvertDoubleValue( rValue, nBaseValue, nDecDigits, eEntryUnit, eUnit ); 1472cdf0e10cSrcweir 1473cdf0e10cSrcweir return sal_True; 1474cdf0e10cSrcweir } 1475cdf0e10cSrcweir 1476cdf0e10cSrcweir // ----------------------------------------------------------------------- 1477cdf0e10cSrcweir 1478cdf0e10cSrcweir sal_Bool MetricFormatter::ImplMetricReformat( const XubString& rStr, double& rValue, XubString& rOutStr ) 1479cdf0e10cSrcweir { 1480cdf0e10cSrcweir if ( !ImplMetricGetValue( rStr, rValue, mnBaseValue, GetDecimalDigits(), ImplGetLocaleDataWrapper(), meUnit ) ) 1481cdf0e10cSrcweir return sal_True; 1482cdf0e10cSrcweir else 1483cdf0e10cSrcweir { 1484cdf0e10cSrcweir double nTempVal = rValue; 1485cdf0e10cSrcweir // caution: precision loss in double cast 1486cdf0e10cSrcweir if ( nTempVal > GetMax() ) 1487cdf0e10cSrcweir nTempVal = (double)GetMax(); 1488cdf0e10cSrcweir else if ( nTempVal < GetMin()) 1489cdf0e10cSrcweir nTempVal = (double)GetMin(); 1490cdf0e10cSrcweir 1491cdf0e10cSrcweir if ( GetErrorHdl().IsSet() && (rValue != nTempVal) ) 1492cdf0e10cSrcweir { 1493cdf0e10cSrcweir mnCorrectedValue = (sal_Int64)nTempVal; 1494cdf0e10cSrcweir if ( !GetErrorHdl().Call( this ) ) 1495cdf0e10cSrcweir { 1496cdf0e10cSrcweir mnCorrectedValue = 0; 1497cdf0e10cSrcweir return sal_False; 1498cdf0e10cSrcweir } 1499cdf0e10cSrcweir else 1500cdf0e10cSrcweir mnCorrectedValue = 0; 1501cdf0e10cSrcweir } 1502cdf0e10cSrcweir 1503cdf0e10cSrcweir rOutStr = CreateFieldText( (sal_Int64)nTempVal ); 1504cdf0e10cSrcweir return sal_True; 1505cdf0e10cSrcweir } 1506cdf0e10cSrcweir } 1507cdf0e10cSrcweir 1508cdf0e10cSrcweir // ----------------------------------------------------------------------- 1509cdf0e10cSrcweir 1510cdf0e10cSrcweir inline void MetricFormatter::ImplInit() 1511cdf0e10cSrcweir { 1512cdf0e10cSrcweir mnBaseValue = 0; 1513cdf0e10cSrcweir meUnit = MetricField::GetDefaultUnit(); 1514cdf0e10cSrcweir mnType = FORMAT_METRIC; 1515cdf0e10cSrcweir } 1516cdf0e10cSrcweir 1517cdf0e10cSrcweir // ----------------------------------------------------------------------- 1518cdf0e10cSrcweir 1519cdf0e10cSrcweir MetricFormatter::MetricFormatter() 1520cdf0e10cSrcweir { 1521cdf0e10cSrcweir ImplInit(); 1522cdf0e10cSrcweir } 1523cdf0e10cSrcweir 1524cdf0e10cSrcweir // ----------------------------------------------------------------------- 1525cdf0e10cSrcweir 1526cdf0e10cSrcweir void MetricFormatter::ImplLoadRes( const ResId& rResId ) 1527cdf0e10cSrcweir { 1528cdf0e10cSrcweir NumericFormatter::ImplLoadRes( rResId ); 1529cdf0e10cSrcweir 1530cdf0e10cSrcweir ResMgr* pMgr = rResId.GetResMgr(); 1531cdf0e10cSrcweir if( pMgr ) 1532cdf0e10cSrcweir { 1533cdf0e10cSrcweir sal_uLong nMask = pMgr->ReadLong(); 1534cdf0e10cSrcweir 1535cdf0e10cSrcweir if ( METRICFORMATTER_UNIT & nMask ) 1536cdf0e10cSrcweir meUnit = (FieldUnit)pMgr->ReadLong(); 1537cdf0e10cSrcweir 1538cdf0e10cSrcweir if ( METRICFORMATTER_CUSTOMUNITTEXT & nMask ) 1539cdf0e10cSrcweir maCustomUnitText = pMgr->ReadString(); 1540cdf0e10cSrcweir } 1541cdf0e10cSrcweir } 1542cdf0e10cSrcweir 1543cdf0e10cSrcweir // ----------------------------------------------------------------------- 1544cdf0e10cSrcweir 1545cdf0e10cSrcweir MetricFormatter::~MetricFormatter() 1546cdf0e10cSrcweir { 1547cdf0e10cSrcweir } 1548cdf0e10cSrcweir 1549cdf0e10cSrcweir // ----------------------------------------------------------------------- 1550cdf0e10cSrcweir 1551cdf0e10cSrcweir void MetricFormatter::SetUnit( FieldUnit eNewUnit ) 1552cdf0e10cSrcweir { 1553cdf0e10cSrcweir if ( eNewUnit == FUNIT_100TH_MM ) 1554cdf0e10cSrcweir { 1555cdf0e10cSrcweir SetDecimalDigits( GetDecimalDigits() + 2 ); 1556cdf0e10cSrcweir meUnit = FUNIT_MM; 1557cdf0e10cSrcweir } 1558cdf0e10cSrcweir else 1559cdf0e10cSrcweir meUnit = eNewUnit; 1560cdf0e10cSrcweir ReformatAll(); 1561cdf0e10cSrcweir } 1562cdf0e10cSrcweir 1563cdf0e10cSrcweir // ----------------------------------------------------------------------- 1564cdf0e10cSrcweir 1565cdf0e10cSrcweir void MetricFormatter::SetCustomUnitText( const XubString& rStr ) 1566cdf0e10cSrcweir { 1567cdf0e10cSrcweir maCustomUnitText = rStr; 1568cdf0e10cSrcweir ReformatAll(); 1569cdf0e10cSrcweir } 1570cdf0e10cSrcweir 1571cdf0e10cSrcweir // ----------------------------------------------------------------------- 1572cdf0e10cSrcweir 1573cdf0e10cSrcweir void MetricFormatter::SetValue( sal_Int64 nNewValue, FieldUnit eInUnit ) 1574cdf0e10cSrcweir { 1575cdf0e10cSrcweir SetUserValue( nNewValue, eInUnit ); 1576cdf0e10cSrcweir mnFieldValue = mnLastValue; 1577cdf0e10cSrcweir } 1578cdf0e10cSrcweir 1579cdf0e10cSrcweir // ----------------------------------------------------------------------- 1580cdf0e10cSrcweir 1581cdf0e10cSrcweir XubString MetricFormatter::CreateFieldText( sal_Int64 nValue ) const 1582cdf0e10cSrcweir { 1583cdf0e10cSrcweir XubString aStr = NumericFormatter::CreateFieldText( nValue ); 1584cdf0e10cSrcweir 1585cdf0e10cSrcweir if( meUnit == FUNIT_CUSTOM ) 1586cdf0e10cSrcweir aStr += maCustomUnitText; 1587cdf0e10cSrcweir else 1588cdf0e10cSrcweir aStr += ImplMetricToString( meUnit ); 1589cdf0e10cSrcweir 1590cdf0e10cSrcweir return aStr; 1591cdf0e10cSrcweir } 1592cdf0e10cSrcweir 1593cdf0e10cSrcweir // ----------------------------------------------------------------------- 1594cdf0e10cSrcweir 1595cdf0e10cSrcweir void MetricFormatter::SetUserValue( sal_Int64 nNewValue, FieldUnit eInUnit ) 1596cdf0e10cSrcweir { 1597cdf0e10cSrcweir // Umrechnen auf eingestellte Einheiten 1598cdf0e10cSrcweir nNewValue = MetricField::ConvertValue( nNewValue, mnBaseValue, GetDecimalDigits(), eInUnit, meUnit ); 1599cdf0e10cSrcweir NumericFormatter::SetUserValue( nNewValue ); 1600cdf0e10cSrcweir } 1601cdf0e10cSrcweir 1602cdf0e10cSrcweir // ----------------------------------------------------------------------- 1603cdf0e10cSrcweir 1604cdf0e10cSrcweir sal_Int64 MetricFormatter::GetValue( FieldUnit eOutUnit ) const 1605cdf0e10cSrcweir { 1606cdf0e10cSrcweir if ( !GetField() ) 1607cdf0e10cSrcweir return 0; 1608cdf0e10cSrcweir 1609cdf0e10cSrcweir double nTempValue; 1610cdf0e10cSrcweir // caution: precision loss in double cast 1611cdf0e10cSrcweir if ( !ImplMetricGetValue( GetField()->GetText(), nTempValue, mnBaseValue, GetDecimalDigits(), ImplGetLocaleDataWrapper(), meUnit ) ) 1612cdf0e10cSrcweir nTempValue = (double)mnLastValue; 1613cdf0e10cSrcweir 1614cdf0e10cSrcweir // caution: precision loss in double cast 1615cdf0e10cSrcweir if ( nTempValue > mnMax ) 1616cdf0e10cSrcweir nTempValue = (double)mnMax; 1617cdf0e10cSrcweir else if ( nTempValue < mnMin ) 1618cdf0e10cSrcweir nTempValue = (double)mnMin; 1619cdf0e10cSrcweir 1620cdf0e10cSrcweir // Umrechnen auf gewuenschte Einheiten 1621cdf0e10cSrcweir return MetricField::ConvertValue( (sal_Int64)nTempValue, mnBaseValue, GetDecimalDigits(), meUnit, eOutUnit ); 1622cdf0e10cSrcweir } 1623cdf0e10cSrcweir 1624cdf0e10cSrcweir // ----------------------------------------------------------------------- 1625cdf0e10cSrcweir 1626cdf0e10cSrcweir void MetricFormatter::SetValue( sal_Int64 nValue ) 1627cdf0e10cSrcweir { 1628cdf0e10cSrcweir // Implementation not inline, because it is a virtual Function 1629cdf0e10cSrcweir SetValue( nValue, FUNIT_NONE ); 1630cdf0e10cSrcweir } 1631cdf0e10cSrcweir 1632cdf0e10cSrcweir // ----------------------------------------------------------------------- 1633cdf0e10cSrcweir 1634cdf0e10cSrcweir sal_Int64 MetricFormatter::GetValue() const 1635cdf0e10cSrcweir { 1636cdf0e10cSrcweir // Implementation not inline, because it is a virtual Function 1637cdf0e10cSrcweir return GetValue( FUNIT_NONE ); 1638cdf0e10cSrcweir } 1639cdf0e10cSrcweir 1640cdf0e10cSrcweir // ----------------------------------------------------------------------- 1641cdf0e10cSrcweir 1642cdf0e10cSrcweir void MetricFormatter::SetMin( sal_Int64 nNewMin, FieldUnit eInUnit ) 1643cdf0e10cSrcweir { 1644cdf0e10cSrcweir // Umrechnen auf gewuenschte Einheiten 1645cdf0e10cSrcweir NumericFormatter::SetMin( MetricField::ConvertValue( nNewMin, mnBaseValue, GetDecimalDigits(), 1646cdf0e10cSrcweir eInUnit, meUnit ) ); 1647cdf0e10cSrcweir } 1648cdf0e10cSrcweir 1649cdf0e10cSrcweir // ----------------------------------------------------------------------- 1650cdf0e10cSrcweir 1651cdf0e10cSrcweir sal_Int64 MetricFormatter::GetMin( FieldUnit eOutUnit ) const 1652cdf0e10cSrcweir { 1653cdf0e10cSrcweir // Umrechnen auf gewuenschte Einheiten 1654cdf0e10cSrcweir return MetricField::ConvertValue( NumericFormatter::GetMin(), mnBaseValue, 1655cdf0e10cSrcweir GetDecimalDigits(), meUnit, eOutUnit ); 1656cdf0e10cSrcweir } 1657cdf0e10cSrcweir 1658cdf0e10cSrcweir // ----------------------------------------------------------------------- 1659cdf0e10cSrcweir 1660cdf0e10cSrcweir void MetricFormatter::SetMax( sal_Int64 nNewMax, FieldUnit eInUnit ) 1661cdf0e10cSrcweir { 1662cdf0e10cSrcweir // Umrechnen auf gewuenschte Einheiten 1663cdf0e10cSrcweir NumericFormatter::SetMax( MetricField::ConvertValue( nNewMax, mnBaseValue, GetDecimalDigits(), 1664cdf0e10cSrcweir eInUnit, meUnit ) ); 1665cdf0e10cSrcweir } 1666cdf0e10cSrcweir 1667cdf0e10cSrcweir // ----------------------------------------------------------------------- 1668cdf0e10cSrcweir 1669cdf0e10cSrcweir sal_Int64 MetricFormatter::GetMax( FieldUnit eOutUnit ) const 1670cdf0e10cSrcweir { 1671cdf0e10cSrcweir // Umrechnen auf gewuenschte Einheiten 1672cdf0e10cSrcweir return MetricField::ConvertValue( NumericFormatter::GetMax(), mnBaseValue, 1673cdf0e10cSrcweir GetDecimalDigits(), meUnit, eOutUnit ); 1674cdf0e10cSrcweir } 1675cdf0e10cSrcweir 1676cdf0e10cSrcweir // ----------------------------------------------------------------------- 1677cdf0e10cSrcweir 1678cdf0e10cSrcweir void MetricFormatter::SetBaseValue( sal_Int64 nNewBase, FieldUnit eInUnit ) 1679cdf0e10cSrcweir { 1680cdf0e10cSrcweir mnBaseValue = MetricField::ConvertValue( nNewBase, mnBaseValue, GetDecimalDigits(), 1681cdf0e10cSrcweir eInUnit, meUnit ); 1682cdf0e10cSrcweir } 1683cdf0e10cSrcweir 1684cdf0e10cSrcweir // ----------------------------------------------------------------------- 1685cdf0e10cSrcweir 1686cdf0e10cSrcweir sal_Int64 MetricFormatter::GetBaseValue( FieldUnit eOutUnit ) const 1687cdf0e10cSrcweir { 1688cdf0e10cSrcweir // Umrechnen auf gewuenschte Einheiten 1689cdf0e10cSrcweir return MetricField::ConvertValue( mnBaseValue, mnBaseValue, GetDecimalDigits(), 1690cdf0e10cSrcweir meUnit, eOutUnit ); 1691cdf0e10cSrcweir } 1692cdf0e10cSrcweir 1693cdf0e10cSrcweir // ----------------------------------------------------------------------- 1694cdf0e10cSrcweir 1695cdf0e10cSrcweir void MetricFormatter::Reformat() 1696cdf0e10cSrcweir { 1697cdf0e10cSrcweir if ( !GetField() ) 1698cdf0e10cSrcweir return; 1699cdf0e10cSrcweir 1700cdf0e10cSrcweir XubString aText = GetField()->GetText(); 1701cdf0e10cSrcweir if ( meUnit == FUNIT_CUSTOM ) 1702cdf0e10cSrcweir maCurUnitText = ImplMetricGetUnitText( aText ); 1703cdf0e10cSrcweir 1704cdf0e10cSrcweir XubString aStr; 1705cdf0e10cSrcweir // caution: precision loss in double cast 1706cdf0e10cSrcweir double nTemp = (double)mnLastValue; 1707cdf0e10cSrcweir sal_Bool bOK = ImplMetricReformat( aText, nTemp, aStr ); 1708cdf0e10cSrcweir mnLastValue = (sal_Int64)nTemp; 1709cdf0e10cSrcweir 1710cdf0e10cSrcweir if ( !bOK ) 1711cdf0e10cSrcweir return; 1712cdf0e10cSrcweir 1713cdf0e10cSrcweir if ( aStr.Len() ) 1714cdf0e10cSrcweir { 1715cdf0e10cSrcweir ImplSetText( aStr ); 1716cdf0e10cSrcweir if ( meUnit == FUNIT_CUSTOM ) 1717cdf0e10cSrcweir CustomConvert(); 1718cdf0e10cSrcweir } 1719cdf0e10cSrcweir else 1720cdf0e10cSrcweir SetValue( mnLastValue ); 1721cdf0e10cSrcweir maCurUnitText.Erase(); 1722cdf0e10cSrcweir } 1723cdf0e10cSrcweir 1724cdf0e10cSrcweir // ----------------------------------------------------------------------- 1725cdf0e10cSrcweir 1726cdf0e10cSrcweir sal_Int64 MetricFormatter::GetCorrectedValue( FieldUnit eOutUnit ) const 1727cdf0e10cSrcweir { 1728cdf0e10cSrcweir // Umrechnen auf gewuenschte Einheiten 1729cdf0e10cSrcweir return MetricField::ConvertValue( mnCorrectedValue, mnBaseValue, GetDecimalDigits(), 1730cdf0e10cSrcweir meUnit, eOutUnit ); 1731cdf0e10cSrcweir } 1732cdf0e10cSrcweir 1733cdf0e10cSrcweir // ----------------------------------------------------------------------- 1734cdf0e10cSrcweir 1735cdf0e10cSrcweir MetricField::MetricField( Window* pParent, WinBits nWinStyle ) : 1736cdf0e10cSrcweir SpinField( pParent, nWinStyle ) 1737cdf0e10cSrcweir { 1738cdf0e10cSrcweir SetField( this ); 1739cdf0e10cSrcweir Reformat(); 1740cdf0e10cSrcweir } 1741cdf0e10cSrcweir 1742cdf0e10cSrcweir // ----------------------------------------------------------------------- 1743cdf0e10cSrcweir 1744cdf0e10cSrcweir MetricField::MetricField( Window* pParent, const ResId& rResId ) : 1745cdf0e10cSrcweir SpinField( WINDOW_METRICFIELD ) 1746cdf0e10cSrcweir { 1747cdf0e10cSrcweir rResId.SetRT( RSC_METRICFIELD ); 1748cdf0e10cSrcweir WinBits nStyle = ImplInitRes( rResId ) ; 1749cdf0e10cSrcweir SpinField::ImplInit( pParent, nStyle ); 1750cdf0e10cSrcweir SetField( this ); 1751cdf0e10cSrcweir ImplLoadRes( rResId ); 1752cdf0e10cSrcweir 1753cdf0e10cSrcweir if ( !(nStyle & WB_HIDE ) ) 1754cdf0e10cSrcweir Show(); 1755cdf0e10cSrcweir } 1756cdf0e10cSrcweir 1757cdf0e10cSrcweir // ----------------------------------------------------------------------- 1758cdf0e10cSrcweir 1759cdf0e10cSrcweir void MetricField::ImplLoadRes( const ResId& rResId ) 1760cdf0e10cSrcweir { 1761cdf0e10cSrcweir SpinField::ImplLoadRes( rResId ); 1762cdf0e10cSrcweir MetricFormatter::ImplLoadRes( ResId( (RSHEADER_TYPE *)GetClassRes(), *rResId.GetResMgr() ) ); 1763cdf0e10cSrcweir 1764cdf0e10cSrcweir sal_uLong nMask = ReadLongRes(); 1765cdf0e10cSrcweir 1766cdf0e10cSrcweir if ( METRICFIELD_FIRST & nMask ) 1767cdf0e10cSrcweir mnFirst = ReadLongRes(); 1768cdf0e10cSrcweir 1769cdf0e10cSrcweir if ( METRICFIELD_LAST & nMask ) 1770cdf0e10cSrcweir mnLast = ReadLongRes(); 1771cdf0e10cSrcweir 1772cdf0e10cSrcweir if ( METRICFIELD_SPINSIZE & nMask ) 1773cdf0e10cSrcweir mnSpinSize = ReadLongRes(); 1774cdf0e10cSrcweir 1775cdf0e10cSrcweir Reformat(); 1776cdf0e10cSrcweir } 1777cdf0e10cSrcweir 1778cdf0e10cSrcweir // ----------------------------------------------------------------------- 1779cdf0e10cSrcweir 1780cdf0e10cSrcweir MetricField::~MetricField() 1781cdf0e10cSrcweir { 1782cdf0e10cSrcweir } 1783cdf0e10cSrcweir 1784cdf0e10cSrcweir // ----------------------------------------------------------------------- 1785cdf0e10cSrcweir 1786cdf0e10cSrcweir void MetricField::SetFirst( sal_Int64 nNewFirst, FieldUnit eInUnit ) 1787cdf0e10cSrcweir { 1788cdf0e10cSrcweir // convert 1789cdf0e10cSrcweir nNewFirst = MetricField::ConvertValue( nNewFirst, mnBaseValue, GetDecimalDigits(), 1790cdf0e10cSrcweir eInUnit, meUnit ); 1791cdf0e10cSrcweir mnFirst = nNewFirst; 1792cdf0e10cSrcweir } 1793cdf0e10cSrcweir 1794cdf0e10cSrcweir // ----------------------------------------------------------------------- 1795cdf0e10cSrcweir 1796cdf0e10cSrcweir sal_Int64 MetricField::GetFirst( FieldUnit eOutUnit ) const 1797cdf0e10cSrcweir { 1798cdf0e10cSrcweir // convert 1799cdf0e10cSrcweir return MetricField::ConvertValue( mnFirst, mnBaseValue, GetDecimalDigits(), 1800cdf0e10cSrcweir meUnit, eOutUnit ); 1801cdf0e10cSrcweir } 1802cdf0e10cSrcweir 1803cdf0e10cSrcweir // ----------------------------------------------------------------------- 1804cdf0e10cSrcweir 1805cdf0e10cSrcweir void MetricField::SetLast( sal_Int64 nNewLast, FieldUnit eInUnit ) 1806cdf0e10cSrcweir { 1807cdf0e10cSrcweir // Umrechnen 1808cdf0e10cSrcweir nNewLast = MetricField::ConvertValue( nNewLast, mnBaseValue, GetDecimalDigits(), 1809cdf0e10cSrcweir eInUnit, meUnit ); 1810cdf0e10cSrcweir mnLast = nNewLast; 1811cdf0e10cSrcweir } 1812cdf0e10cSrcweir 1813cdf0e10cSrcweir // ----------------------------------------------------------------------- 1814cdf0e10cSrcweir 1815cdf0e10cSrcweir sal_Int64 MetricField::GetLast( FieldUnit eOutUnit ) const 1816cdf0e10cSrcweir { 1817cdf0e10cSrcweir // Umrechnen 1818cdf0e10cSrcweir return MetricField::ConvertValue( mnLast, mnBaseValue, GetDecimalDigits(), 1819cdf0e10cSrcweir meUnit, eOutUnit ); 1820cdf0e10cSrcweir } 1821cdf0e10cSrcweir 1822cdf0e10cSrcweir // ----------------------------------------------------------------------- 1823cdf0e10cSrcweir 1824cdf0e10cSrcweir long MetricField::PreNotify( NotifyEvent& rNEvt ) 1825cdf0e10cSrcweir { 1826cdf0e10cSrcweir if ( (rNEvt.GetType() == EVENT_KEYINPUT) && !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() ) 1827cdf0e10cSrcweir { 1828cdf0e10cSrcweir if ( ImplMetricProcessKeyInput( GetField(), *rNEvt.GetKeyEvent(), IsStrictFormat(), IsUseThousandSep(), ImplGetLocaleDataWrapper() ) ) 1829cdf0e10cSrcweir return 1; 1830cdf0e10cSrcweir } 1831cdf0e10cSrcweir 1832cdf0e10cSrcweir return SpinField::PreNotify( rNEvt ); 1833cdf0e10cSrcweir } 1834cdf0e10cSrcweir 1835cdf0e10cSrcweir // ----------------------------------------------------------------------- 1836cdf0e10cSrcweir 1837cdf0e10cSrcweir long MetricField::Notify( NotifyEvent& rNEvt ) 1838cdf0e10cSrcweir { 1839cdf0e10cSrcweir if ( rNEvt.GetType() == EVENT_GETFOCUS ) 1840cdf0e10cSrcweir MarkToBeReformatted( sal_False ); 1841cdf0e10cSrcweir else if ( rNEvt.GetType() == EVENT_LOSEFOCUS ) 1842cdf0e10cSrcweir { 1843cdf0e10cSrcweir if ( MustBeReformatted() && (GetText().Len() || !IsEmptyFieldValueEnabled()) ) 1844cdf0e10cSrcweir Reformat(); 1845cdf0e10cSrcweir } 1846cdf0e10cSrcweir 1847cdf0e10cSrcweir return SpinField::Notify( rNEvt ); 1848cdf0e10cSrcweir } 1849cdf0e10cSrcweir 1850cdf0e10cSrcweir // ----------------------------------------------------------------------- 1851cdf0e10cSrcweir 1852cdf0e10cSrcweir void MetricField::DataChanged( const DataChangedEvent& rDCEvt ) 1853cdf0e10cSrcweir { 1854cdf0e10cSrcweir SpinField::DataChanged( rDCEvt ); 1855cdf0e10cSrcweir 1856cdf0e10cSrcweir if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_LOCALE) ) 1857cdf0e10cSrcweir { 1858cdf0e10cSrcweir String sOldDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep(); 1859cdf0e10cSrcweir String sOldThSep = ImplGetLocaleDataWrapper().getNumThousandSep(); 1860cdf0e10cSrcweir if ( IsDefaultLocale() ) 1861cdf0e10cSrcweir ImplGetLocaleDataWrapper().setLocale( GetSettings().GetLocale() ); 1862cdf0e10cSrcweir String sNewDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep(); 1863cdf0e10cSrcweir String sNewThSep = ImplGetLocaleDataWrapper().getNumThousandSep(); 1864cdf0e10cSrcweir ImplUpdateSeparators( sOldDecSep, sNewDecSep, sOldThSep, sNewThSep, this ); 1865cdf0e10cSrcweir ReformatAll(); 1866cdf0e10cSrcweir } 1867cdf0e10cSrcweir } 1868cdf0e10cSrcweir 1869cdf0e10cSrcweir // ----------------------------------------------------------------------- 1870cdf0e10cSrcweir 1871cdf0e10cSrcweir void MetricField::Modify() 1872cdf0e10cSrcweir { 1873cdf0e10cSrcweir MarkToBeReformatted( sal_True ); 1874cdf0e10cSrcweir SpinField::Modify(); 1875cdf0e10cSrcweir } 1876cdf0e10cSrcweir 1877cdf0e10cSrcweir // ----------------------------------------------------------------------- 1878cdf0e10cSrcweir 1879cdf0e10cSrcweir void MetricField::Up() 1880cdf0e10cSrcweir { 1881cdf0e10cSrcweir FieldUp(); 1882cdf0e10cSrcweir SpinField::Up(); 1883cdf0e10cSrcweir } 1884cdf0e10cSrcweir 1885cdf0e10cSrcweir // ----------------------------------------------------------------------- 1886cdf0e10cSrcweir 1887cdf0e10cSrcweir void MetricField::Down() 1888cdf0e10cSrcweir { 1889cdf0e10cSrcweir FieldDown(); 1890cdf0e10cSrcweir SpinField::Down(); 1891cdf0e10cSrcweir } 1892cdf0e10cSrcweir 1893cdf0e10cSrcweir // ----------------------------------------------------------------------- 1894cdf0e10cSrcweir 1895cdf0e10cSrcweir void MetricField::First() 1896cdf0e10cSrcweir { 1897cdf0e10cSrcweir FieldFirst(); 1898cdf0e10cSrcweir SpinField::First(); 1899cdf0e10cSrcweir } 1900cdf0e10cSrcweir 1901cdf0e10cSrcweir // ----------------------------------------------------------------------- 1902cdf0e10cSrcweir 1903cdf0e10cSrcweir void MetricField::Last() 1904cdf0e10cSrcweir { 1905cdf0e10cSrcweir FieldLast(); 1906cdf0e10cSrcweir SpinField::Last(); 1907cdf0e10cSrcweir } 1908cdf0e10cSrcweir 1909cdf0e10cSrcweir // ----------------------------------------------------------------------- 1910cdf0e10cSrcweir 1911cdf0e10cSrcweir void MetricField::CustomConvert() 1912cdf0e10cSrcweir { 1913cdf0e10cSrcweir maCustomConvertLink.Call( this ); 1914cdf0e10cSrcweir } 1915cdf0e10cSrcweir 1916cdf0e10cSrcweir // ----------------------------------------------------------------------- 1917cdf0e10cSrcweir 1918cdf0e10cSrcweir MetricBox::MetricBox( Window* pParent, WinBits nWinStyle ) : 1919cdf0e10cSrcweir ComboBox( pParent, nWinStyle ) 1920cdf0e10cSrcweir { 1921cdf0e10cSrcweir SetField( this ); 1922cdf0e10cSrcweir Reformat(); 1923cdf0e10cSrcweir } 1924cdf0e10cSrcweir 1925cdf0e10cSrcweir // ----------------------------------------------------------------------- 1926cdf0e10cSrcweir 1927cdf0e10cSrcweir MetricBox::MetricBox( Window* pParent, const ResId& rResId ) : 1928cdf0e10cSrcweir ComboBox( WINDOW_METRICBOX ) 1929cdf0e10cSrcweir { 1930cdf0e10cSrcweir rResId.SetRT( RSC_METRICBOX ); 1931cdf0e10cSrcweir WinBits nStyle = ImplInitRes( rResId ); 1932cdf0e10cSrcweir ComboBox::ImplInit( pParent, nStyle ); 1933cdf0e10cSrcweir SetField( this ); 1934cdf0e10cSrcweir Reformat(); 1935cdf0e10cSrcweir ComboBox::ImplLoadRes( rResId ); 1936cdf0e10cSrcweir MetricFormatter::ImplLoadRes( ResId( (RSHEADER_TYPE *)GetClassRes(), *rResId.GetResMgr() ) ); 1937cdf0e10cSrcweir 1938cdf0e10cSrcweir if ( !(nStyle & WB_HIDE ) ) 1939cdf0e10cSrcweir Show(); 1940cdf0e10cSrcweir } 1941cdf0e10cSrcweir 1942cdf0e10cSrcweir // ----------------------------------------------------------------------- 1943cdf0e10cSrcweir 1944cdf0e10cSrcweir MetricBox::~MetricBox() 1945cdf0e10cSrcweir { 1946cdf0e10cSrcweir } 1947cdf0e10cSrcweir 1948cdf0e10cSrcweir // ----------------------------------------------------------------------- 1949cdf0e10cSrcweir 1950cdf0e10cSrcweir long MetricBox::PreNotify( NotifyEvent& rNEvt ) 1951cdf0e10cSrcweir { 1952cdf0e10cSrcweir if ( (rNEvt.GetType() == EVENT_KEYINPUT) && !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() ) 1953cdf0e10cSrcweir { 1954cdf0e10cSrcweir if ( ImplMetricProcessKeyInput( GetField(), *rNEvt.GetKeyEvent(), IsStrictFormat(), IsUseThousandSep(), ImplGetLocaleDataWrapper() ) ) 1955cdf0e10cSrcweir return 1; 1956cdf0e10cSrcweir } 1957cdf0e10cSrcweir 1958cdf0e10cSrcweir return ComboBox::PreNotify( rNEvt ); 1959cdf0e10cSrcweir } 1960cdf0e10cSrcweir 1961cdf0e10cSrcweir // ----------------------------------------------------------------------- 1962cdf0e10cSrcweir 1963cdf0e10cSrcweir long MetricBox::Notify( NotifyEvent& rNEvt ) 1964cdf0e10cSrcweir { 1965cdf0e10cSrcweir if ( rNEvt.GetType() == EVENT_GETFOCUS ) 1966cdf0e10cSrcweir MarkToBeReformatted( sal_False ); 1967cdf0e10cSrcweir else if ( rNEvt.GetType() == EVENT_LOSEFOCUS ) 1968cdf0e10cSrcweir { 1969cdf0e10cSrcweir if ( MustBeReformatted() && (GetText().Len() || !IsEmptyFieldValueEnabled()) ) 1970cdf0e10cSrcweir Reformat(); 1971cdf0e10cSrcweir } 1972cdf0e10cSrcweir 1973cdf0e10cSrcweir return ComboBox::Notify( rNEvt ); 1974cdf0e10cSrcweir } 1975cdf0e10cSrcweir 1976cdf0e10cSrcweir // ----------------------------------------------------------------------- 1977cdf0e10cSrcweir 1978cdf0e10cSrcweir void MetricBox::DataChanged( const DataChangedEvent& rDCEvt ) 1979cdf0e10cSrcweir { 1980cdf0e10cSrcweir ComboBox::DataChanged( rDCEvt ); 1981cdf0e10cSrcweir 1982cdf0e10cSrcweir if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_LOCALE) ) 1983cdf0e10cSrcweir { 1984cdf0e10cSrcweir String sOldDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep(); 1985cdf0e10cSrcweir String sOldThSep = ImplGetLocaleDataWrapper().getNumThousandSep(); 1986cdf0e10cSrcweir if ( IsDefaultLocale() ) 1987cdf0e10cSrcweir ImplGetLocaleDataWrapper().setLocale( GetSettings().GetLocale() ); 1988cdf0e10cSrcweir String sNewDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep(); 1989cdf0e10cSrcweir String sNewThSep = ImplGetLocaleDataWrapper().getNumThousandSep(); 1990cdf0e10cSrcweir ImplUpdateSeparators( sOldDecSep, sNewDecSep, sOldThSep, sNewThSep, this ); 1991cdf0e10cSrcweir ReformatAll(); 1992cdf0e10cSrcweir } 1993cdf0e10cSrcweir } 1994cdf0e10cSrcweir 1995cdf0e10cSrcweir // ----------------------------------------------------------------------- 1996cdf0e10cSrcweir 1997cdf0e10cSrcweir void MetricBox::Modify() 1998cdf0e10cSrcweir { 1999cdf0e10cSrcweir MarkToBeReformatted( sal_True ); 2000cdf0e10cSrcweir ComboBox::Modify(); 2001cdf0e10cSrcweir } 2002cdf0e10cSrcweir 2003cdf0e10cSrcweir // ----------------------------------------------------------------------- 2004cdf0e10cSrcweir 2005cdf0e10cSrcweir void MetricBox::ReformatAll() 2006cdf0e10cSrcweir { 2007cdf0e10cSrcweir double nValue; 2008cdf0e10cSrcweir XubString aStr; 2009cdf0e10cSrcweir SetUpdateMode( sal_False ); 2010cdf0e10cSrcweir sal_uInt16 nEntryCount = GetEntryCount(); 2011cdf0e10cSrcweir for ( sal_uInt16 i=0; i < nEntryCount; i++ ) 2012cdf0e10cSrcweir { 2013cdf0e10cSrcweir ImplMetricReformat( GetEntry( i ), nValue, aStr ); 2014cdf0e10cSrcweir RemoveEntry( i ); 2015cdf0e10cSrcweir InsertEntry( aStr, i ); 2016cdf0e10cSrcweir } 2017cdf0e10cSrcweir MetricFormatter::Reformat(); 2018cdf0e10cSrcweir SetUpdateMode( sal_True ); 2019cdf0e10cSrcweir } 2020cdf0e10cSrcweir 2021cdf0e10cSrcweir // ----------------------------------------------------------------------- 2022cdf0e10cSrcweir 2023cdf0e10cSrcweir void MetricBox::CustomConvert() 2024cdf0e10cSrcweir { 2025cdf0e10cSrcweir maCustomConvertLink.Call( this ); 2026cdf0e10cSrcweir } 2027cdf0e10cSrcweir 2028cdf0e10cSrcweir // ----------------------------------------------------------------------- 2029cdf0e10cSrcweir 2030cdf0e10cSrcweir void MetricBox::InsertValue( sal_Int64 nValue, FieldUnit eInUnit, sal_uInt16 nPos ) 2031cdf0e10cSrcweir { 2032cdf0e10cSrcweir // Umrechnen auf eingestellte Einheiten 2033cdf0e10cSrcweir nValue = MetricField::ConvertValue( nValue, mnBaseValue, GetDecimalDigits(), 2034cdf0e10cSrcweir eInUnit, meUnit ); 2035cdf0e10cSrcweir ComboBox::InsertEntry( CreateFieldText( nValue ), nPos ); 2036cdf0e10cSrcweir } 2037cdf0e10cSrcweir 2038cdf0e10cSrcweir // ----------------------------------------------------------------------- 2039cdf0e10cSrcweir 2040cdf0e10cSrcweir void MetricBox::RemoveValue( sal_Int64 nValue, FieldUnit eInUnit ) 2041cdf0e10cSrcweir { 2042cdf0e10cSrcweir // Umrechnen auf eingestellte Einheiten 2043cdf0e10cSrcweir nValue = MetricField::ConvertValue( nValue, mnBaseValue, GetDecimalDigits(), 2044cdf0e10cSrcweir eInUnit, meUnit ); 2045cdf0e10cSrcweir ComboBox::RemoveEntry( CreateFieldText( nValue ) ); 2046cdf0e10cSrcweir } 2047cdf0e10cSrcweir 2048cdf0e10cSrcweir // ----------------------------------------------------------------------- 2049cdf0e10cSrcweir 2050cdf0e10cSrcweir sal_Int64 MetricBox::GetValue( sal_uInt16 nPos, FieldUnit eOutUnit ) const 2051cdf0e10cSrcweir { 2052cdf0e10cSrcweir double nValue = 0; 2053cdf0e10cSrcweir ImplMetricGetValue( ComboBox::GetEntry( nPos ), nValue, mnBaseValue, 2054cdf0e10cSrcweir GetDecimalDigits(), ImplGetLocaleDataWrapper(), meUnit ); 2055cdf0e10cSrcweir 2056cdf0e10cSrcweir // Umrechnen auf eingestellte Einheiten 2057cdf0e10cSrcweir sal_Int64 nRetValue = MetricField::ConvertValue( (sal_Int64)nValue, mnBaseValue, GetDecimalDigits(), 2058cdf0e10cSrcweir meUnit, eOutUnit ); 2059cdf0e10cSrcweir 2060cdf0e10cSrcweir return nRetValue; 2061cdf0e10cSrcweir } 2062cdf0e10cSrcweir 2063cdf0e10cSrcweir // ----------------------------------------------------------------------- 2064cdf0e10cSrcweir 2065cdf0e10cSrcweir sal_uInt16 MetricBox::GetValuePos( sal_Int64 nValue, FieldUnit eInUnit ) const 2066cdf0e10cSrcweir { 2067cdf0e10cSrcweir // Umrechnen auf eingestellte Einheiten 2068cdf0e10cSrcweir nValue = MetricField::ConvertValue( nValue, mnBaseValue, GetDecimalDigits(), 2069cdf0e10cSrcweir eInUnit, meUnit ); 2070cdf0e10cSrcweir return ComboBox::GetEntryPos( CreateFieldText( nValue ) ); 2071cdf0e10cSrcweir } 2072cdf0e10cSrcweir 2073cdf0e10cSrcweir // ----------------------------------------------------------------------- 2074cdf0e10cSrcweir 2075cdf0e10cSrcweir sal_Int64 MetricBox::GetValue( FieldUnit eOutUnit ) const 2076cdf0e10cSrcweir { 2077cdf0e10cSrcweir // Implementation not inline, because it is a virtual Function 2078cdf0e10cSrcweir return MetricFormatter::GetValue( eOutUnit ); 2079cdf0e10cSrcweir } 2080cdf0e10cSrcweir 2081cdf0e10cSrcweir // ----------------------------------------------------------------------- 2082cdf0e10cSrcweir 2083cdf0e10cSrcweir sal_Int64 MetricBox::GetValue() const 2084cdf0e10cSrcweir { 2085cdf0e10cSrcweir // Implementation not inline, because it is a virtual Function 2086cdf0e10cSrcweir return GetValue( FUNIT_NONE ); 2087cdf0e10cSrcweir } 2088cdf0e10cSrcweir 2089cdf0e10cSrcweir // ----------------------------------------------------------------------- 2090cdf0e10cSrcweir 2091cdf0e10cSrcweir static sal_Bool ImplCurrencyProcessKeyInput( Edit* pEdit, const KeyEvent& rKEvt, 2092cdf0e10cSrcweir sal_Bool, sal_Bool bUseThousandSep, const LocaleDataWrapper& rWrapper ) 2093cdf0e10cSrcweir { 2094cdf0e10cSrcweir // Es gibt hier kein sinnvolles StrictFormat, also alle 2095cdf0e10cSrcweir // Zeichen erlauben 2096cdf0e10cSrcweir return ImplNumericProcessKeyInput( pEdit, rKEvt, sal_False, bUseThousandSep, rWrapper ); 2097cdf0e10cSrcweir } 2098cdf0e10cSrcweir 2099cdf0e10cSrcweir // ----------------------------------------------------------------------- 2100cdf0e10cSrcweir 2101cdf0e10cSrcweir inline sal_Bool ImplCurrencyGetValue( const XubString& rStr, double& rValue, 2102cdf0e10cSrcweir sal_uInt16 nDecDigits, const LocaleDataWrapper& rWrapper ) 2103cdf0e10cSrcweir { 2104cdf0e10cSrcweir // Zahlenwert holen 2105cdf0e10cSrcweir return ImplNumericGetValue( rStr, rValue, nDecDigits, rWrapper, sal_True ); 2106cdf0e10cSrcweir } 2107cdf0e10cSrcweir 2108cdf0e10cSrcweir // ----------------------------------------------------------------------- 2109cdf0e10cSrcweir 2110cdf0e10cSrcweir sal_Bool CurrencyFormatter::ImplCurrencyReformat( const XubString& rStr, 2111cdf0e10cSrcweir XubString& rOutStr ) 2112cdf0e10cSrcweir { 2113cdf0e10cSrcweir double nValue; 2114cdf0e10cSrcweir if ( !ImplNumericGetValue( rStr, nValue, GetDecimalDigits(), ImplGetLocaleDataWrapper(), sal_True ) ) 2115cdf0e10cSrcweir return sal_True; 2116cdf0e10cSrcweir else 2117cdf0e10cSrcweir { 2118cdf0e10cSrcweir double nTempVal = nValue; 2119cdf0e10cSrcweir // caution: precision loss in double cast 2120cdf0e10cSrcweir if ( nTempVal > GetMax() ) 2121cdf0e10cSrcweir nTempVal = (double)GetMax(); 2122cdf0e10cSrcweir else if ( nTempVal < GetMin()) 2123cdf0e10cSrcweir nTempVal = (double)GetMin(); 2124cdf0e10cSrcweir 2125cdf0e10cSrcweir if ( GetErrorHdl().IsSet() && (nValue != nTempVal) ) 2126cdf0e10cSrcweir { 2127cdf0e10cSrcweir mnCorrectedValue = (sal_Int64)nTempVal; 2128cdf0e10cSrcweir if ( !GetErrorHdl().Call( this ) ) 2129cdf0e10cSrcweir { 2130cdf0e10cSrcweir mnCorrectedValue = 0; 2131cdf0e10cSrcweir return sal_False; 2132cdf0e10cSrcweir } 2133cdf0e10cSrcweir else 2134cdf0e10cSrcweir mnCorrectedValue = 0; 2135cdf0e10cSrcweir } 2136cdf0e10cSrcweir 2137cdf0e10cSrcweir rOutStr = CreateFieldText( (long)nTempVal ); 2138cdf0e10cSrcweir return sal_True; 2139cdf0e10cSrcweir } 2140cdf0e10cSrcweir } 2141cdf0e10cSrcweir 2142cdf0e10cSrcweir // ----------------------------------------------------------------------- 2143cdf0e10cSrcweir 2144cdf0e10cSrcweir inline void CurrencyFormatter::ImplInit() 2145cdf0e10cSrcweir { 2146cdf0e10cSrcweir mnType = FORMAT_CURRENCY; 2147cdf0e10cSrcweir } 2148cdf0e10cSrcweir 2149cdf0e10cSrcweir // ----------------------------------------------------------------------- 2150cdf0e10cSrcweir 2151cdf0e10cSrcweir CurrencyFormatter::CurrencyFormatter() 2152cdf0e10cSrcweir { 2153cdf0e10cSrcweir ImplInit(); 2154cdf0e10cSrcweir } 2155cdf0e10cSrcweir 2156cdf0e10cSrcweir // ----------------------------------------------------------------------- 2157cdf0e10cSrcweir 2158cdf0e10cSrcweir CurrencyFormatter::~CurrencyFormatter() 2159cdf0e10cSrcweir { 2160cdf0e10cSrcweir } 2161cdf0e10cSrcweir 2162cdf0e10cSrcweir // ----------------------------------------------------------------------- 2163cdf0e10cSrcweir 2164cdf0e10cSrcweir void CurrencyFormatter::SetCurrencySymbol( const String& rStr ) 2165cdf0e10cSrcweir { 2166cdf0e10cSrcweir maCurrencySymbol= rStr; 2167cdf0e10cSrcweir ReformatAll(); 2168cdf0e10cSrcweir } 2169cdf0e10cSrcweir 2170cdf0e10cSrcweir // ----------------------------------------------------------------------- 2171cdf0e10cSrcweir 2172cdf0e10cSrcweir String CurrencyFormatter::GetCurrencySymbol() const 2173cdf0e10cSrcweir { 2174cdf0e10cSrcweir return maCurrencySymbol.Len() ? maCurrencySymbol : ImplGetLocaleDataWrapper().getCurrSymbol(); 2175cdf0e10cSrcweir } 2176cdf0e10cSrcweir 2177cdf0e10cSrcweir // ----------------------------------------------------------------------- 2178cdf0e10cSrcweir 2179cdf0e10cSrcweir void CurrencyFormatter::SetValue( sal_Int64 nNewValue ) 2180cdf0e10cSrcweir { 2181cdf0e10cSrcweir SetUserValue( nNewValue ); 2182cdf0e10cSrcweir mnFieldValue = mnLastValue; 2183cdf0e10cSrcweir SetEmptyFieldValueData( sal_False ); 2184cdf0e10cSrcweir } 2185cdf0e10cSrcweir 2186cdf0e10cSrcweir // ----------------------------------------------------------------------- 2187cdf0e10cSrcweir 2188cdf0e10cSrcweir XubString CurrencyFormatter::CreateFieldText( sal_Int64 nValue ) const 2189cdf0e10cSrcweir { 2190cdf0e10cSrcweir return ImplGetLocaleDataWrapper().getCurr( nValue, GetDecimalDigits(), GetCurrencySymbol(), IsUseThousandSep() ); 2191cdf0e10cSrcweir } 2192cdf0e10cSrcweir 2193cdf0e10cSrcweir // ----------------------------------------------------------------------- 2194cdf0e10cSrcweir 2195cdf0e10cSrcweir sal_Int64 CurrencyFormatter::GetValue() const 2196cdf0e10cSrcweir { 2197cdf0e10cSrcweir if ( !GetField() ) 2198cdf0e10cSrcweir return 0; 2199cdf0e10cSrcweir 2200cdf0e10cSrcweir double nTempValue; 2201cdf0e10cSrcweir if ( ImplCurrencyGetValue( GetField()->GetText(), nTempValue, GetDecimalDigits(), ImplGetLocaleDataWrapper() ) ) 2202cdf0e10cSrcweir { 2203cdf0e10cSrcweir // caution: precision loss in double cast 2204cdf0e10cSrcweir if ( nTempValue > mnMax ) 2205cdf0e10cSrcweir nTempValue = (double)mnMax; 2206cdf0e10cSrcweir else if ( nTempValue < mnMin ) 2207cdf0e10cSrcweir nTempValue = (double)mnMin; 2208cdf0e10cSrcweir return (sal_Int64)nTempValue; 2209cdf0e10cSrcweir } 2210cdf0e10cSrcweir else 2211cdf0e10cSrcweir return mnLastValue; 2212cdf0e10cSrcweir } 2213cdf0e10cSrcweir 2214cdf0e10cSrcweir // ----------------------------------------------------------------------- 2215cdf0e10cSrcweir 2216cdf0e10cSrcweir void CurrencyFormatter::Reformat() 2217cdf0e10cSrcweir { 2218cdf0e10cSrcweir if ( !GetField() ) 2219cdf0e10cSrcweir return; 2220cdf0e10cSrcweir 2221cdf0e10cSrcweir XubString aStr; 2222cdf0e10cSrcweir sal_Bool bOK = ImplCurrencyReformat( GetField()->GetText(), aStr ); 2223cdf0e10cSrcweir if ( !bOK ) 2224cdf0e10cSrcweir return; 2225cdf0e10cSrcweir 2226cdf0e10cSrcweir if ( aStr.Len() ) 2227cdf0e10cSrcweir { 2228cdf0e10cSrcweir ImplSetText( aStr ); 2229cdf0e10cSrcweir // caution: precision loss in double cast 2230cdf0e10cSrcweir double nTemp = (double)mnLastValue; 2231cdf0e10cSrcweir ImplCurrencyGetValue( aStr, nTemp, GetDecimalDigits(), ImplGetLocaleDataWrapper() ); 2232cdf0e10cSrcweir mnLastValue = (sal_Int64)nTemp; 2233cdf0e10cSrcweir } 2234cdf0e10cSrcweir else 2235cdf0e10cSrcweir SetValue( mnLastValue ); 2236cdf0e10cSrcweir } 2237cdf0e10cSrcweir 2238cdf0e10cSrcweir // ----------------------------------------------------------------------- 2239cdf0e10cSrcweir 2240cdf0e10cSrcweir CurrencyField::CurrencyField( Window* pParent, WinBits nWinStyle ) : 2241cdf0e10cSrcweir SpinField( pParent, nWinStyle ) 2242cdf0e10cSrcweir { 2243cdf0e10cSrcweir SetField( this ); 2244cdf0e10cSrcweir Reformat(); 2245cdf0e10cSrcweir } 2246cdf0e10cSrcweir 2247cdf0e10cSrcweir // ----------------------------------------------------------------------- 2248cdf0e10cSrcweir 2249cdf0e10cSrcweir CurrencyField::CurrencyField( Window* pParent, const ResId& rResId ) : 2250cdf0e10cSrcweir SpinField( WINDOW_CURRENCYFIELD ) 2251cdf0e10cSrcweir { 2252cdf0e10cSrcweir rResId.SetRT( RSC_CURRENCYFIELD ); 2253cdf0e10cSrcweir WinBits nStyle = ImplInitRes( rResId ); 2254cdf0e10cSrcweir SpinField::ImplInit( pParent, nStyle); 2255cdf0e10cSrcweir SetField( this ); 2256cdf0e10cSrcweir ImplLoadRes( rResId ); 2257cdf0e10cSrcweir 2258cdf0e10cSrcweir if ( !(nStyle & WB_HIDE ) ) 2259cdf0e10cSrcweir Show(); 2260cdf0e10cSrcweir } 2261cdf0e10cSrcweir 2262cdf0e10cSrcweir // ----------------------------------------------------------------------- 2263cdf0e10cSrcweir 2264cdf0e10cSrcweir void CurrencyField::ImplLoadRes( const ResId& rResId ) 2265cdf0e10cSrcweir { 2266cdf0e10cSrcweir SpinField::ImplLoadRes( rResId ); 2267cdf0e10cSrcweir CurrencyFormatter::ImplLoadRes( ResId( (RSHEADER_TYPE *)GetClassRes(), *rResId.GetResMgr() ) ); 2268cdf0e10cSrcweir 2269cdf0e10cSrcweir sal_uLong nMask = ReadLongRes(); 2270cdf0e10cSrcweir 2271cdf0e10cSrcweir if ( CURRENCYFIELD_FIRST & nMask ) 2272cdf0e10cSrcweir mnFirst = ReadLongRes(); 2273cdf0e10cSrcweir 2274cdf0e10cSrcweir if ( CURRENCYFIELD_LAST & nMask ) 2275cdf0e10cSrcweir mnLast = ReadLongRes(); 2276cdf0e10cSrcweir 2277cdf0e10cSrcweir if ( CURRENCYFIELD_SPINSIZE & nMask ) 2278cdf0e10cSrcweir mnSpinSize = ReadLongRes(); 2279cdf0e10cSrcweir 2280cdf0e10cSrcweir Reformat(); 2281cdf0e10cSrcweir } 2282cdf0e10cSrcweir 2283cdf0e10cSrcweir // ----------------------------------------------------------------------- 2284cdf0e10cSrcweir 2285cdf0e10cSrcweir CurrencyField::~CurrencyField() 2286cdf0e10cSrcweir { 2287cdf0e10cSrcweir } 2288cdf0e10cSrcweir 2289cdf0e10cSrcweir // ----------------------------------------------------------------------- 2290cdf0e10cSrcweir 2291cdf0e10cSrcweir long CurrencyField::PreNotify( NotifyEvent& rNEvt ) 2292cdf0e10cSrcweir { 2293cdf0e10cSrcweir if ( (rNEvt.GetType() == EVENT_KEYINPUT) && !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() ) 2294cdf0e10cSrcweir { 2295cdf0e10cSrcweir if ( ImplCurrencyProcessKeyInput( GetField(), *rNEvt.GetKeyEvent(), IsStrictFormat(), IsUseThousandSep(), ImplGetLocaleDataWrapper() ) ) 2296cdf0e10cSrcweir return 1; 2297cdf0e10cSrcweir } 2298cdf0e10cSrcweir 2299cdf0e10cSrcweir return SpinField::PreNotify( rNEvt ); 2300cdf0e10cSrcweir } 2301cdf0e10cSrcweir 2302cdf0e10cSrcweir // ----------------------------------------------------------------------- 2303cdf0e10cSrcweir 2304cdf0e10cSrcweir long CurrencyField::Notify( NotifyEvent& rNEvt ) 2305cdf0e10cSrcweir { 2306cdf0e10cSrcweir if ( rNEvt.GetType() == EVENT_GETFOCUS ) 2307cdf0e10cSrcweir MarkToBeReformatted( sal_False ); 2308cdf0e10cSrcweir else if ( rNEvt.GetType() == EVENT_LOSEFOCUS ) 2309cdf0e10cSrcweir { 2310cdf0e10cSrcweir if ( MustBeReformatted() && (GetText().Len() || !IsEmptyFieldValueEnabled()) ) 2311cdf0e10cSrcweir Reformat(); 2312cdf0e10cSrcweir } 2313cdf0e10cSrcweir 2314cdf0e10cSrcweir return SpinField::Notify( rNEvt ); 2315cdf0e10cSrcweir } 2316cdf0e10cSrcweir 2317cdf0e10cSrcweir // ----------------------------------------------------------------------- 2318cdf0e10cSrcweir 2319cdf0e10cSrcweir void CurrencyField::DataChanged( const DataChangedEvent& rDCEvt ) 2320cdf0e10cSrcweir { 2321cdf0e10cSrcweir SpinField::DataChanged( rDCEvt ); 2322cdf0e10cSrcweir 2323cdf0e10cSrcweir if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_LOCALE) ) 2324cdf0e10cSrcweir { 2325cdf0e10cSrcweir String sOldDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep(); 2326cdf0e10cSrcweir String sOldThSep = ImplGetLocaleDataWrapper().getNumThousandSep(); 2327cdf0e10cSrcweir if ( IsDefaultLocale() ) 2328cdf0e10cSrcweir ImplGetLocaleDataWrapper().setLocale( GetSettings().GetLocale() ); 2329cdf0e10cSrcweir String sNewDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep(); 2330cdf0e10cSrcweir String sNewThSep = ImplGetLocaleDataWrapper().getNumThousandSep(); 2331cdf0e10cSrcweir ImplUpdateSeparators( sOldDecSep, sNewDecSep, sOldThSep, sNewThSep, this ); 2332cdf0e10cSrcweir ReformatAll(); 2333cdf0e10cSrcweir } 2334cdf0e10cSrcweir } 2335cdf0e10cSrcweir 2336cdf0e10cSrcweir // ----------------------------------------------------------------------- 2337cdf0e10cSrcweir 2338cdf0e10cSrcweir void CurrencyField::Modify() 2339cdf0e10cSrcweir { 2340cdf0e10cSrcweir MarkToBeReformatted( sal_True ); 2341cdf0e10cSrcweir SpinField::Modify(); 2342cdf0e10cSrcweir } 2343cdf0e10cSrcweir 2344cdf0e10cSrcweir // ----------------------------------------------------------------------- 2345cdf0e10cSrcweir 2346cdf0e10cSrcweir void CurrencyField::Up() 2347cdf0e10cSrcweir { 2348cdf0e10cSrcweir FieldUp(); 2349cdf0e10cSrcweir SpinField::Up(); 2350cdf0e10cSrcweir } 2351cdf0e10cSrcweir 2352cdf0e10cSrcweir // ----------------------------------------------------------------------- 2353cdf0e10cSrcweir 2354cdf0e10cSrcweir void CurrencyField::Down() 2355cdf0e10cSrcweir { 2356cdf0e10cSrcweir FieldDown(); 2357cdf0e10cSrcweir SpinField::Down(); 2358cdf0e10cSrcweir } 2359cdf0e10cSrcweir 2360cdf0e10cSrcweir // ----------------------------------------------------------------------- 2361cdf0e10cSrcweir 2362cdf0e10cSrcweir void CurrencyField::First() 2363cdf0e10cSrcweir { 2364cdf0e10cSrcweir FieldFirst(); 2365cdf0e10cSrcweir SpinField::First(); 2366cdf0e10cSrcweir } 2367cdf0e10cSrcweir 2368cdf0e10cSrcweir // ----------------------------------------------------------------------- 2369cdf0e10cSrcweir 2370cdf0e10cSrcweir void CurrencyField::Last() 2371cdf0e10cSrcweir { 2372cdf0e10cSrcweir FieldLast(); 2373cdf0e10cSrcweir SpinField::Last(); 2374cdf0e10cSrcweir } 2375cdf0e10cSrcweir 2376cdf0e10cSrcweir // ----------------------------------------------------------------------- 2377cdf0e10cSrcweir 2378cdf0e10cSrcweir CurrencyBox::CurrencyBox( Window* pParent, WinBits nWinStyle ) : 2379cdf0e10cSrcweir ComboBox( pParent, nWinStyle ) 2380cdf0e10cSrcweir { 2381cdf0e10cSrcweir SetField( this ); 2382cdf0e10cSrcweir Reformat(); 2383cdf0e10cSrcweir } 2384cdf0e10cSrcweir 2385cdf0e10cSrcweir // ----------------------------------------------------------------------- 2386cdf0e10cSrcweir 2387cdf0e10cSrcweir CurrencyBox::CurrencyBox( Window* pParent, const ResId& rResId ) : 2388cdf0e10cSrcweir ComboBox( WINDOW_CURRENCYBOX ) 2389cdf0e10cSrcweir { 2390cdf0e10cSrcweir rResId.SetRT( RSC_CURRENCYBOX ); 2391cdf0e10cSrcweir WinBits nStyle = ImplInitRes( rResId ); 2392cdf0e10cSrcweir ComboBox::ImplInit( pParent, nStyle ); 2393cdf0e10cSrcweir CurrencyFormatter::ImplLoadRes( ResId( (RSHEADER_TYPE *)GetClassRes(), *rResId.GetResMgr() ) ); 2394cdf0e10cSrcweir SetField( this ); 2395cdf0e10cSrcweir ComboBox::ImplLoadRes( rResId ); 2396cdf0e10cSrcweir Reformat(); 2397cdf0e10cSrcweir 2398cdf0e10cSrcweir if ( !(nStyle & WB_HIDE ) ) 2399cdf0e10cSrcweir Show(); 2400cdf0e10cSrcweir } 2401cdf0e10cSrcweir 2402cdf0e10cSrcweir // ----------------------------------------------------------------------- 2403cdf0e10cSrcweir 2404cdf0e10cSrcweir CurrencyBox::~CurrencyBox() 2405cdf0e10cSrcweir { 2406cdf0e10cSrcweir } 2407cdf0e10cSrcweir 2408cdf0e10cSrcweir // ----------------------------------------------------------------------- 2409cdf0e10cSrcweir 2410cdf0e10cSrcweir long CurrencyBox::PreNotify( NotifyEvent& rNEvt ) 2411cdf0e10cSrcweir { 2412cdf0e10cSrcweir if ( (rNEvt.GetType() == EVENT_KEYINPUT) && !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() ) 2413cdf0e10cSrcweir { 2414cdf0e10cSrcweir if ( ImplCurrencyProcessKeyInput( GetField(), *rNEvt.GetKeyEvent(), IsStrictFormat(), IsUseThousandSep(), ImplGetLocaleDataWrapper() ) ) 2415cdf0e10cSrcweir return 1; 2416cdf0e10cSrcweir } 2417cdf0e10cSrcweir 2418cdf0e10cSrcweir return ComboBox::PreNotify( rNEvt ); 2419cdf0e10cSrcweir } 2420cdf0e10cSrcweir 2421cdf0e10cSrcweir // ----------------------------------------------------------------------- 2422cdf0e10cSrcweir 2423cdf0e10cSrcweir long CurrencyBox::Notify( NotifyEvent& rNEvt ) 2424cdf0e10cSrcweir { 2425cdf0e10cSrcweir if ( rNEvt.GetType() == EVENT_GETFOCUS ) 2426cdf0e10cSrcweir MarkToBeReformatted( sal_False ); 2427cdf0e10cSrcweir else if ( rNEvt.GetType() == EVENT_LOSEFOCUS ) 2428cdf0e10cSrcweir { 2429cdf0e10cSrcweir if ( MustBeReformatted() && (GetText().Len() || !IsEmptyFieldValueEnabled()) ) 2430cdf0e10cSrcweir Reformat(); 2431cdf0e10cSrcweir } 2432cdf0e10cSrcweir 2433cdf0e10cSrcweir return ComboBox::Notify( rNEvt ); 2434cdf0e10cSrcweir } 2435cdf0e10cSrcweir 2436cdf0e10cSrcweir // ----------------------------------------------------------------------- 2437cdf0e10cSrcweir 2438cdf0e10cSrcweir void CurrencyBox::DataChanged( const DataChangedEvent& rDCEvt ) 2439cdf0e10cSrcweir { 2440cdf0e10cSrcweir ComboBox::DataChanged( rDCEvt ); 2441cdf0e10cSrcweir 2442cdf0e10cSrcweir if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_LOCALE) ) 2443cdf0e10cSrcweir { 2444cdf0e10cSrcweir String sOldDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep(); 2445cdf0e10cSrcweir String sOldThSep = ImplGetLocaleDataWrapper().getNumThousandSep(); 2446cdf0e10cSrcweir if ( IsDefaultLocale() ) 2447cdf0e10cSrcweir ImplGetLocaleDataWrapper().setLocale( GetSettings().GetLocale() ); 2448cdf0e10cSrcweir String sNewDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep(); 2449cdf0e10cSrcweir String sNewThSep = ImplGetLocaleDataWrapper().getNumThousandSep(); 2450cdf0e10cSrcweir ImplUpdateSeparators( sOldDecSep, sNewDecSep, sOldThSep, sNewThSep, this ); 2451cdf0e10cSrcweir ReformatAll(); 2452cdf0e10cSrcweir } 2453cdf0e10cSrcweir } 2454cdf0e10cSrcweir 2455cdf0e10cSrcweir // ----------------------------------------------------------------------- 2456cdf0e10cSrcweir 2457cdf0e10cSrcweir void CurrencyBox::Modify() 2458cdf0e10cSrcweir { 2459cdf0e10cSrcweir MarkToBeReformatted( sal_True ); 2460cdf0e10cSrcweir ComboBox::Modify(); 2461cdf0e10cSrcweir } 2462cdf0e10cSrcweir 2463cdf0e10cSrcweir // ----------------------------------------------------------------------- 2464cdf0e10cSrcweir 2465cdf0e10cSrcweir void CurrencyBox::ReformatAll() 2466cdf0e10cSrcweir { 2467cdf0e10cSrcweir XubString aStr; 2468cdf0e10cSrcweir SetUpdateMode( sal_False ); 2469cdf0e10cSrcweir sal_uInt16 nEntryCount = GetEntryCount(); 2470cdf0e10cSrcweir for ( sal_uInt16 i=0; i < nEntryCount; i++ ) 2471cdf0e10cSrcweir { 2472cdf0e10cSrcweir ImplCurrencyReformat( GetEntry( i ), aStr ); 2473cdf0e10cSrcweir RemoveEntry( i ); 2474cdf0e10cSrcweir InsertEntry( aStr, i ); 2475cdf0e10cSrcweir } 2476cdf0e10cSrcweir CurrencyFormatter::Reformat(); 2477cdf0e10cSrcweir SetUpdateMode( sal_True ); 2478cdf0e10cSrcweir } 2479cdf0e10cSrcweir 2480cdf0e10cSrcweir // ----------------------------------------------------------------------- 2481cdf0e10cSrcweir 2482cdf0e10cSrcweir void CurrencyBox::InsertValue( sal_Int64 nValue, sal_uInt16 nPos ) 2483cdf0e10cSrcweir { 2484cdf0e10cSrcweir ComboBox::InsertEntry( CreateFieldText( nValue ), nPos ); 2485cdf0e10cSrcweir } 2486cdf0e10cSrcweir 2487cdf0e10cSrcweir // ----------------------------------------------------------------------- 2488cdf0e10cSrcweir 2489cdf0e10cSrcweir void CurrencyBox::RemoveValue( sal_Int64 nValue ) 2490cdf0e10cSrcweir { 2491cdf0e10cSrcweir ComboBox::RemoveEntry( CreateFieldText( nValue ) ); 2492cdf0e10cSrcweir } 2493cdf0e10cSrcweir 2494cdf0e10cSrcweir // ----------------------------------------------------------------------- 2495cdf0e10cSrcweir 2496cdf0e10cSrcweir sal_Int64 CurrencyBox::GetValue( sal_uInt16 nPos ) const 2497cdf0e10cSrcweir { 2498cdf0e10cSrcweir double nValue = 0; 2499cdf0e10cSrcweir ImplCurrencyGetValue( ComboBox::GetEntry( nPos ), nValue, GetDecimalDigits(), ImplGetLocaleDataWrapper() ); 2500cdf0e10cSrcweir return (sal_Int64)nValue; 2501cdf0e10cSrcweir } 2502cdf0e10cSrcweir 2503cdf0e10cSrcweir // ----------------------------------------------------------------------- 2504cdf0e10cSrcweir 2505cdf0e10cSrcweir sal_uInt16 CurrencyBox::GetValuePos( sal_Int64 nValue ) const 2506cdf0e10cSrcweir { 2507cdf0e10cSrcweir return ComboBox::GetEntryPos( CreateFieldText( nValue ) ); 2508cdf0e10cSrcweir } 2509cdf0e10cSrcweir 2510cdf0e10cSrcweir // ----------------------------------------------------------------------- 2511cdf0e10cSrcweir 2512cdf0e10cSrcweir sal_Int64 CurrencyBox::GetValue() const 2513cdf0e10cSrcweir { 2514cdf0e10cSrcweir // Implementation not inline, because it is a virtual Function 2515cdf0e10cSrcweir return CurrencyFormatter::GetValue(); 2516cdf0e10cSrcweir } 2517