1*9f62ea84SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*9f62ea84SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*9f62ea84SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*9f62ea84SAndrew Rist * distributed with this work for additional information 6*9f62ea84SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*9f62ea84SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*9f62ea84SAndrew Rist * "License"); you may not use this file except in compliance 9*9f62ea84SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*9f62ea84SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*9f62ea84SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*9f62ea84SAndrew Rist * software distributed under the License is distributed on an 15*9f62ea84SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9f62ea84SAndrew Rist * KIND, either express or implied. See the License for the 17*9f62ea84SAndrew Rist * specific language governing permissions and limitations 18*9f62ea84SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*9f62ea84SAndrew Rist *************************************************************/ 21*9f62ea84SAndrew Rist 22*9f62ea84SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_vcl.hxx" 26cdf0e10cSrcweir #include <tools/debug.hxx> 27cdf0e10cSrcweir 28cdf0e10cSrcweir #include <tools/rc.h> 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <vcl/svapp.hxx> 31cdf0e10cSrcweir #include <vcl/sound.hxx> 32cdf0e10cSrcweir #include <vcl/event.hxx> 33cdf0e10cSrcweir #include <vcl/field.hxx> 34cdf0e10cSrcweir #include <vcl/unohelp.hxx> 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include <svdata.hxx> 37cdf0e10cSrcweir 38cdf0e10cSrcweir #include <i18npool/mslangid.hxx> 39cdf0e10cSrcweir 40cdf0e10cSrcweir #include <com/sun/star/lang/Locale.hpp> 41cdf0e10cSrcweir #include <com/sun/star/i18n/XCharacterClassification.hpp> 42cdf0e10cSrcweir #include <com/sun/star/i18n/KCharacterType.hpp> 43cdf0e10cSrcweir 44cdf0e10cSrcweir 45cdf0e10cSrcweir #include <unotools/localedatawrapper.hxx> 46cdf0e10cSrcweir #include <unotools/calendarwrapper.hxx> 47cdf0e10cSrcweir #include <unotools/charclass.hxx> 48cdf0e10cSrcweir #include <unotools/misccfg.hxx> 49cdf0e10cSrcweir 50cdf0e10cSrcweir using namespace ::com::sun::star; 51cdf0e10cSrcweir 52cdf0e10cSrcweir // ======================================================================= 53cdf0e10cSrcweir 54cdf0e10cSrcweir #define EDITMASK_LITERAL 'L' 55cdf0e10cSrcweir #define EDITMASK_ALPHA 'a' 56cdf0e10cSrcweir #define EDITMASK_UPPERALPHA 'A' 57cdf0e10cSrcweir #define EDITMASK_ALPHANUM 'c' 58cdf0e10cSrcweir #define EDITMASK_UPPERALPHANUM 'C' 59cdf0e10cSrcweir #define EDITMASK_NUM 'N' 60cdf0e10cSrcweir #define EDITMASK_NUMSPACE 'n' 61cdf0e10cSrcweir #define EDITMASK_ALLCHAR 'x' 62cdf0e10cSrcweir #define EDITMASK_UPPERALLCHAR 'X' 63cdf0e10cSrcweir 64cdf0e10cSrcweir uno::Reference< i18n::XCharacterClassification > ImplGetCharClass() 65cdf0e10cSrcweir { 66cdf0e10cSrcweir static uno::Reference< i18n::XCharacterClassification > xCharClass; 67cdf0e10cSrcweir if ( !xCharClass.is() ) 68cdf0e10cSrcweir xCharClass = vcl::unohelper::CreateCharacterClassification(); 69cdf0e10cSrcweir 70cdf0e10cSrcweir return xCharClass; 71cdf0e10cSrcweir } 72cdf0e10cSrcweir 73cdf0e10cSrcweir // ----------------------------------------------------------------------- 74cdf0e10cSrcweir 75cdf0e10cSrcweir static sal_Unicode* ImplAddString( sal_Unicode* pBuf, const String& rStr ) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir if ( rStr.Len() == 1 ) 78cdf0e10cSrcweir *pBuf++ = rStr.GetChar(0); 79cdf0e10cSrcweir else if ( rStr.Len() == 0 ) 80cdf0e10cSrcweir ; 81cdf0e10cSrcweir else 82cdf0e10cSrcweir { 83cdf0e10cSrcweir memcpy( pBuf, rStr.GetBuffer(), rStr.Len() * sizeof(sal_Unicode) ); 84cdf0e10cSrcweir pBuf += rStr.Len(); 85cdf0e10cSrcweir } 86cdf0e10cSrcweir return pBuf; 87cdf0e10cSrcweir } 88cdf0e10cSrcweir 89cdf0e10cSrcweir // ----------------------------------------------------------------------- 90cdf0e10cSrcweir 91cdf0e10cSrcweir static sal_Unicode* ImplAddNum( sal_Unicode* pBuf, sal_uLong nNumber, int nMinLen ) 92cdf0e10cSrcweir { 93cdf0e10cSrcweir // fill temp buffer with digits 94cdf0e10cSrcweir sal_Unicode aTempBuf[30]; 95cdf0e10cSrcweir sal_Unicode* pTempBuf = aTempBuf; 96cdf0e10cSrcweir do 97cdf0e10cSrcweir { 98cdf0e10cSrcweir *pTempBuf = (sal_Unicode)(nNumber % 10) + '0'; 99cdf0e10cSrcweir pTempBuf++; 100cdf0e10cSrcweir nNumber /= 10; 101cdf0e10cSrcweir if ( nMinLen ) 102cdf0e10cSrcweir nMinLen--; 103cdf0e10cSrcweir } 104cdf0e10cSrcweir while ( nNumber ); 105cdf0e10cSrcweir 106cdf0e10cSrcweir // fill with zeros up to the minimal length 107cdf0e10cSrcweir while ( nMinLen > 0 ) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir *pBuf = '0'; 110cdf0e10cSrcweir pBuf++; 111cdf0e10cSrcweir nMinLen--; 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir // copy temp buffer to real buffer 115cdf0e10cSrcweir do 116cdf0e10cSrcweir { 117cdf0e10cSrcweir pTempBuf--; 118cdf0e10cSrcweir *pBuf = *pTempBuf; 119cdf0e10cSrcweir pBuf++; 120cdf0e10cSrcweir } 121cdf0e10cSrcweir while ( pTempBuf != aTempBuf ); 122cdf0e10cSrcweir 123cdf0e10cSrcweir return pBuf; 124cdf0e10cSrcweir } 125cdf0e10cSrcweir 126cdf0e10cSrcweir // ----------------------------------------------------------------------- 127cdf0e10cSrcweir 128cdf0e10cSrcweir static sal_uInt16 ImplGetNum( const sal_Unicode*& rpBuf, sal_Bool& rbError ) 129cdf0e10cSrcweir { 130cdf0e10cSrcweir if ( !*rpBuf ) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir rbError = sal_True; 133cdf0e10cSrcweir return 0; 134cdf0e10cSrcweir } 135cdf0e10cSrcweir 136cdf0e10cSrcweir sal_uInt16 nNumber = 0; 137cdf0e10cSrcweir while( ( *rpBuf >= '0' ) && ( *rpBuf <= '9' ) ) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir nNumber *= 10; 140cdf0e10cSrcweir nNumber += *rpBuf - '0'; 141cdf0e10cSrcweir rpBuf++; 142cdf0e10cSrcweir } 143cdf0e10cSrcweir 144cdf0e10cSrcweir return nNumber; 145cdf0e10cSrcweir } 146cdf0e10cSrcweir 147cdf0e10cSrcweir // ----------------------------------------------------------------------- 148cdf0e10cSrcweir 149cdf0e10cSrcweir static void ImplSkipDelimiters( const sal_Unicode*& rpBuf ) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir while( ( *rpBuf == ',' ) || ( *rpBuf == '.' ) || ( *rpBuf == ';' ) || 152cdf0e10cSrcweir ( *rpBuf == ':' ) || ( *rpBuf == '-' ) || ( *rpBuf == '/' ) ) 153cdf0e10cSrcweir { 154cdf0e10cSrcweir rpBuf++; 155cdf0e10cSrcweir } 156cdf0e10cSrcweir } 157cdf0e10cSrcweir 158cdf0e10cSrcweir // ----------------------------------------------------------------------- 159cdf0e10cSrcweir 160cdf0e10cSrcweir static int ImplIsPatternChar( xub_Unicode cChar, sal_Char cEditMask ) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir sal_Int32 nType = 0; 163cdf0e10cSrcweir 164cdf0e10cSrcweir try 165cdf0e10cSrcweir { 166cdf0e10cSrcweir String aCharStr( cChar ); 167cdf0e10cSrcweir nType = ImplGetCharClass()->getStringType( aCharStr, 0, aCharStr.Len(), Application::GetSettings().GetLocale() ); 168cdf0e10cSrcweir } 169cdf0e10cSrcweir catch ( ::com::sun::star::uno::Exception& ) 170cdf0e10cSrcweir { 171cdf0e10cSrcweir DBG_ERRORFILE( "ImplIsPatternChar: Exception caught!" ); 172cdf0e10cSrcweir return sal_False; 173cdf0e10cSrcweir } 174cdf0e10cSrcweir 175cdf0e10cSrcweir if ( (cEditMask == EDITMASK_ALPHA) || (cEditMask == EDITMASK_UPPERALPHA) ) 176cdf0e10cSrcweir { 177cdf0e10cSrcweir if( !CharClass::isLetterType( nType ) ) 178cdf0e10cSrcweir return sal_False; 179cdf0e10cSrcweir } 180cdf0e10cSrcweir else if ( cEditMask == EDITMASK_NUM ) 181cdf0e10cSrcweir { 182cdf0e10cSrcweir if( !CharClass::isNumericType( nType ) ) 183cdf0e10cSrcweir return sal_False; 184cdf0e10cSrcweir } 185cdf0e10cSrcweir else if ( (cEditMask == EDITMASK_ALPHANUM) || (cEditMask == EDITMASK_UPPERALPHANUM) ) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir if( !CharClass::isLetterNumericType( nType ) ) 188cdf0e10cSrcweir return sal_False; 189cdf0e10cSrcweir } 190cdf0e10cSrcweir else if ( (cEditMask == EDITMASK_ALLCHAR) || (cEditMask == EDITMASK_UPPERALLCHAR) ) 191cdf0e10cSrcweir { 192cdf0e10cSrcweir if ( cChar < 32 ) 193cdf0e10cSrcweir return sal_False; 194cdf0e10cSrcweir } 195cdf0e10cSrcweir else if ( cEditMask == EDITMASK_NUMSPACE ) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir if ( !CharClass::isNumericType( nType ) && ( cChar != ' ' ) ) 198cdf0e10cSrcweir return sal_False; 199cdf0e10cSrcweir } 200cdf0e10cSrcweir else 201cdf0e10cSrcweir return sal_False; 202cdf0e10cSrcweir 203cdf0e10cSrcweir return sal_True; 204cdf0e10cSrcweir } 205cdf0e10cSrcweir 206cdf0e10cSrcweir // ----------------------------------------------------------------------- 207cdf0e10cSrcweir 208cdf0e10cSrcweir static xub_Unicode ImplPatternChar( xub_Unicode cChar, sal_Char cEditMask ) 209cdf0e10cSrcweir { 210cdf0e10cSrcweir if ( ImplIsPatternChar( cChar, cEditMask ) ) 211cdf0e10cSrcweir { 212cdf0e10cSrcweir if ( (cEditMask == EDITMASK_UPPERALPHA) || 213cdf0e10cSrcweir (cEditMask == EDITMASK_UPPERALPHANUM) || 214cdf0e10cSrcweir ( cEditMask == EDITMASK_UPPERALLCHAR ) ) 215cdf0e10cSrcweir { 216cdf0e10cSrcweir cChar = ImplGetCharClass()->toUpper( String(cChar),0,1,Application::GetSettings().GetLocale() )[0]; 217cdf0e10cSrcweir } 218cdf0e10cSrcweir return cChar; 219cdf0e10cSrcweir } 220cdf0e10cSrcweir else 221cdf0e10cSrcweir return 0; 222cdf0e10cSrcweir } 223cdf0e10cSrcweir 224cdf0e10cSrcweir // ----------------------------------------------------------------------- 225cdf0e10cSrcweir 226cdf0e10cSrcweir static int ImplKommaPointCharEqual( xub_Unicode c1, xub_Unicode c2 ) 227cdf0e10cSrcweir { 228cdf0e10cSrcweir if ( c1 == c2 ) 229cdf0e10cSrcweir return sal_True; 230cdf0e10cSrcweir else if ( ((c1 == '.') || (c1 == ',')) && 231cdf0e10cSrcweir ((c2 == '.') || (c2 == ',')) ) 232cdf0e10cSrcweir return sal_True; 233cdf0e10cSrcweir else 234cdf0e10cSrcweir return sal_False; 235cdf0e10cSrcweir } 236cdf0e10cSrcweir 237cdf0e10cSrcweir // ----------------------------------------------------------------------- 238cdf0e10cSrcweir 239cdf0e10cSrcweir static XubString ImplPatternReformat( const XubString& rStr, 240cdf0e10cSrcweir const ByteString& rEditMask, 241cdf0e10cSrcweir const XubString& rLiteralMask, 242cdf0e10cSrcweir sal_uInt16 nFormatFlags ) 243cdf0e10cSrcweir { 244cdf0e10cSrcweir if ( !rEditMask.Len() ) 245cdf0e10cSrcweir return rStr; 246cdf0e10cSrcweir 247cdf0e10cSrcweir XubString aStr = rStr; 248cdf0e10cSrcweir XubString aOutStr = rLiteralMask; 249cdf0e10cSrcweir xub_Unicode cTempChar; 250cdf0e10cSrcweir xub_Unicode cChar; 251cdf0e10cSrcweir xub_Unicode cLiteral; 252cdf0e10cSrcweir sal_Char cMask; 253cdf0e10cSrcweir xub_StrLen nStrIndex = 0; 254cdf0e10cSrcweir xub_StrLen i = 0; 255cdf0e10cSrcweir xub_StrLen n; 256cdf0e10cSrcweir 257cdf0e10cSrcweir while ( i < rEditMask.Len() ) 258cdf0e10cSrcweir { 259cdf0e10cSrcweir if ( nStrIndex >= aStr.Len() ) 260cdf0e10cSrcweir break; 261cdf0e10cSrcweir 262cdf0e10cSrcweir cChar = aStr.GetChar(nStrIndex); 263cdf0e10cSrcweir cLiteral = rLiteralMask.GetChar(i); 264cdf0e10cSrcweir cMask = rEditMask.GetChar(i); 265cdf0e10cSrcweir 266cdf0e10cSrcweir // Aktuelle Position ein Literal 267cdf0e10cSrcweir if ( cMask == EDITMASK_LITERAL ) 268cdf0e10cSrcweir { 269cdf0e10cSrcweir // Wenn es das Literal-Zeichen ist, uebernehmen, ansonsten 270cdf0e10cSrcweir // ignorieren, da es das naechste gueltige Zeichen vom String 271cdf0e10cSrcweir // sein kann 272cdf0e10cSrcweir if ( ImplKommaPointCharEqual( cChar, cLiteral ) ) 273cdf0e10cSrcweir nStrIndex++; 274cdf0e10cSrcweir else 275cdf0e10cSrcweir { 276cdf0e10cSrcweir // Ansonsten testen wir, ob es ein ungueltiges Zeichen ist. 277cdf0e10cSrcweir // Dies ist dann der Fall, wenn es nicht in das Muster 278cdf0e10cSrcweir // des naechsten nicht Literal-Zeichens passt 279cdf0e10cSrcweir n = i+1; 280cdf0e10cSrcweir while ( n < rEditMask.Len() ) 281cdf0e10cSrcweir { 282cdf0e10cSrcweir if ( rEditMask.GetChar(n) != EDITMASK_LITERAL ) 283cdf0e10cSrcweir { 284cdf0e10cSrcweir if ( !ImplIsPatternChar( cChar, rEditMask.GetChar(n) ) ) 285cdf0e10cSrcweir nStrIndex++; 286cdf0e10cSrcweir break; 287cdf0e10cSrcweir } 288cdf0e10cSrcweir 289cdf0e10cSrcweir n++; 290cdf0e10cSrcweir } 291cdf0e10cSrcweir } 292cdf0e10cSrcweir } 293cdf0e10cSrcweir else 294cdf0e10cSrcweir { 295cdf0e10cSrcweir // Gueltiges Zeichen an der Stelle 296cdf0e10cSrcweir cTempChar = ImplPatternChar( cChar, cMask ); 297cdf0e10cSrcweir if ( cTempChar ) 298cdf0e10cSrcweir { 299cdf0e10cSrcweir // dann Zeichen uebernehmen 300cdf0e10cSrcweir aOutStr.SetChar( i, cTempChar ); 301cdf0e10cSrcweir nStrIndex++; 302cdf0e10cSrcweir } 303cdf0e10cSrcweir else 304cdf0e10cSrcweir { 305cdf0e10cSrcweir // Wenn es das Literalzeichen ist, uebernehmen 306cdf0e10cSrcweir if ( cLiteral == cChar ) 307cdf0e10cSrcweir nStrIndex++; 308cdf0e10cSrcweir else 309cdf0e10cSrcweir { 310cdf0e10cSrcweir // Wenn das ungueltige Zeichen das naechste Literalzeichen 311cdf0e10cSrcweir // sein kann, dann springen wir bis dahin vor, ansonten 312cdf0e10cSrcweir // das Zeichen ignorieren 313cdf0e10cSrcweir // Nur machen, wenn leere Literale erlaubt sind 314cdf0e10cSrcweir if ( nFormatFlags & PATTERN_FORMAT_EMPTYLITERALS ) 315cdf0e10cSrcweir { 316cdf0e10cSrcweir n = i; 317cdf0e10cSrcweir while ( n < rEditMask.Len() ) 318cdf0e10cSrcweir { 319cdf0e10cSrcweir if ( rEditMask.GetChar( n ) == EDITMASK_LITERAL ) 320cdf0e10cSrcweir { 321cdf0e10cSrcweir if ( ImplKommaPointCharEqual( cChar, rLiteralMask.GetChar( n ) ) ) 322cdf0e10cSrcweir i = n+1; 323cdf0e10cSrcweir 324cdf0e10cSrcweir break; 325cdf0e10cSrcweir } 326cdf0e10cSrcweir 327cdf0e10cSrcweir n++; 328cdf0e10cSrcweir } 329cdf0e10cSrcweir } 330cdf0e10cSrcweir 331cdf0e10cSrcweir nStrIndex++; 332cdf0e10cSrcweir continue; 333cdf0e10cSrcweir } 334cdf0e10cSrcweir } 335cdf0e10cSrcweir } 336cdf0e10cSrcweir 337cdf0e10cSrcweir i++; 338cdf0e10cSrcweir } 339cdf0e10cSrcweir 340cdf0e10cSrcweir return aOutStr; 341cdf0e10cSrcweir } 342cdf0e10cSrcweir 343cdf0e10cSrcweir // ----------------------------------------------------------------------- 344cdf0e10cSrcweir 345cdf0e10cSrcweir static void ImplPatternMaxPos( const XubString rStr, const ByteString& rEditMask, 346cdf0e10cSrcweir sal_uInt16 nFormatFlags, sal_Bool bSameMask, 347cdf0e10cSrcweir sal_uInt16 nCursorPos, sal_uInt16& rPos ) 348cdf0e10cSrcweir { 349cdf0e10cSrcweir 350cdf0e10cSrcweir // Letzte Position darf nicht groesser als der enthaltene String sein 351cdf0e10cSrcweir xub_StrLen nMaxPos = rStr.Len(); 352cdf0e10cSrcweir 353cdf0e10cSrcweir // Wenn keine leeren Literale erlaubt sind, auch Leerzeichen 354cdf0e10cSrcweir // am Ende ignorieren 355cdf0e10cSrcweir if ( bSameMask && !(nFormatFlags & PATTERN_FORMAT_EMPTYLITERALS) ) 356cdf0e10cSrcweir { 357cdf0e10cSrcweir while ( nMaxPos ) 358cdf0e10cSrcweir { 359cdf0e10cSrcweir if ( (rEditMask.GetChar(nMaxPos-1) != EDITMASK_LITERAL) && 360cdf0e10cSrcweir (rStr.GetChar(nMaxPos-1) != ' ') ) 361cdf0e10cSrcweir break; 362cdf0e10cSrcweir nMaxPos--; 363cdf0e10cSrcweir } 364cdf0e10cSrcweir 365cdf0e10cSrcweir // Wenn wir vor einem Literal stehen, dann solange weitersuchen, 366cdf0e10cSrcweir // bis erste Stelle nach Literal 367cdf0e10cSrcweir xub_StrLen nTempPos = nMaxPos; 368cdf0e10cSrcweir while ( nTempPos < rEditMask.Len() ) 369cdf0e10cSrcweir { 370cdf0e10cSrcweir if ( rEditMask.GetChar(nTempPos) != EDITMASK_LITERAL ) 371cdf0e10cSrcweir { 372cdf0e10cSrcweir nMaxPos = nTempPos; 373cdf0e10cSrcweir break; 374cdf0e10cSrcweir } 375cdf0e10cSrcweir nTempPos++; 376cdf0e10cSrcweir } 377cdf0e10cSrcweir } 378cdf0e10cSrcweir 379cdf0e10cSrcweir if ( rPos > nMaxPos ) 380cdf0e10cSrcweir rPos = nMaxPos; 381cdf0e10cSrcweir // Zeichen sollte nicht nach links wandern 382cdf0e10cSrcweir if ( rPos < nCursorPos ) 383cdf0e10cSrcweir rPos = nCursorPos; 384cdf0e10cSrcweir } 385cdf0e10cSrcweir 386cdf0e10cSrcweir // ----------------------------------------------------------------------- 387cdf0e10cSrcweir 388cdf0e10cSrcweir static void ImplPatternProcessStrictModify( Edit* pEdit, 389cdf0e10cSrcweir const ByteString& rEditMask, 390cdf0e10cSrcweir const XubString& rLiteralMask, 391cdf0e10cSrcweir sal_uInt16 nFormatFlags, sal_Bool bSameMask ) 392cdf0e10cSrcweir { 393cdf0e10cSrcweir XubString aText = pEdit->GetText(); 394cdf0e10cSrcweir 395cdf0e10cSrcweir // Leerzeichen am Anfang entfernen 396cdf0e10cSrcweir if ( bSameMask && !(nFormatFlags & PATTERN_FORMAT_EMPTYLITERALS) ) 397cdf0e10cSrcweir { 398cdf0e10cSrcweir xub_StrLen i = 0; 399cdf0e10cSrcweir xub_StrLen nMaxLen = aText.Len(); 400cdf0e10cSrcweir while ( i < nMaxLen ) 401cdf0e10cSrcweir { 402cdf0e10cSrcweir if ( (rEditMask.GetChar( i ) != EDITMASK_LITERAL) && 403cdf0e10cSrcweir (aText.GetChar( i ) != ' ') ) 404cdf0e10cSrcweir break; 405cdf0e10cSrcweir 406cdf0e10cSrcweir i++; 407cdf0e10cSrcweir } 408cdf0e10cSrcweir // Alle Literalzeichen beibehalten 409cdf0e10cSrcweir while ( i && (rEditMask.GetChar( i ) == EDITMASK_LITERAL) ) 410cdf0e10cSrcweir i--; 411cdf0e10cSrcweir aText.Erase( 0, i ); 412cdf0e10cSrcweir } 413cdf0e10cSrcweir 414cdf0e10cSrcweir XubString aNewText = ImplPatternReformat( aText, rEditMask, rLiteralMask, nFormatFlags ); 415cdf0e10cSrcweir if ( aNewText != aText ) 416cdf0e10cSrcweir { 417cdf0e10cSrcweir // Selection so anpassen, das diese wenn sie vorher am Ende 418cdf0e10cSrcweir // stand, immer noch am Ende steht 419cdf0e10cSrcweir Selection aSel = pEdit->GetSelection(); 420cdf0e10cSrcweir sal_uLong nMaxSel = Max( aSel.Min(), aSel.Max() ); 421cdf0e10cSrcweir if ( nMaxSel >= aText.Len() ) 422cdf0e10cSrcweir { 423cdf0e10cSrcweir xub_StrLen nMaxPos = aNewText.Len(); 424cdf0e10cSrcweir ImplPatternMaxPos( aNewText, rEditMask, nFormatFlags, bSameMask, (xub_StrLen)nMaxSel, nMaxPos ); 425cdf0e10cSrcweir if ( aSel.Min() == aSel.Max() ) 426cdf0e10cSrcweir { 427cdf0e10cSrcweir aSel.Min() = nMaxPos; 428cdf0e10cSrcweir aSel.Max() = aSel.Min(); 429cdf0e10cSrcweir } 430cdf0e10cSrcweir else if ( aSel.Min() > aSel.Max() ) 431cdf0e10cSrcweir aSel.Min() = nMaxPos; 432cdf0e10cSrcweir else 433cdf0e10cSrcweir aSel.Max() = nMaxPos; 434cdf0e10cSrcweir } 435cdf0e10cSrcweir pEdit->SetText( aNewText, aSel ); 436cdf0e10cSrcweir } 437cdf0e10cSrcweir } 438cdf0e10cSrcweir 439cdf0e10cSrcweir // ----------------------------------------------------------------------- 440cdf0e10cSrcweir 441cdf0e10cSrcweir static xub_StrLen ImplPatternLeftPos( const ByteString& rEditMask, xub_StrLen nCursorPos ) 442cdf0e10cSrcweir { 443cdf0e10cSrcweir // Vorheriges Zeichen suchen, was kein Literal ist 444cdf0e10cSrcweir xub_StrLen nNewPos = nCursorPos; 445cdf0e10cSrcweir xub_StrLen nTempPos = nNewPos; 446cdf0e10cSrcweir while ( nTempPos ) 447cdf0e10cSrcweir { 448cdf0e10cSrcweir if ( rEditMask.GetChar(nTempPos-1) != EDITMASK_LITERAL ) 449cdf0e10cSrcweir { 450cdf0e10cSrcweir nNewPos = nTempPos-1; 451cdf0e10cSrcweir break; 452cdf0e10cSrcweir } 453cdf0e10cSrcweir nTempPos--; 454cdf0e10cSrcweir } 455cdf0e10cSrcweir return nNewPos; 456cdf0e10cSrcweir } 457cdf0e10cSrcweir 458cdf0e10cSrcweir // ----------------------------------------------------------------------- 459cdf0e10cSrcweir 460cdf0e10cSrcweir static xub_StrLen ImplPatternRightPos( const XubString& rStr, const ByteString& rEditMask, 461cdf0e10cSrcweir sal_uInt16 nFormatFlags, sal_Bool bSameMask, 462cdf0e10cSrcweir xub_StrLen nCursorPos ) 463cdf0e10cSrcweir { 464cdf0e10cSrcweir // Naechstes Zeichen suchen, was kein Literal ist 465cdf0e10cSrcweir xub_StrLen nNewPos = nCursorPos; 466cdf0e10cSrcweir xub_StrLen nTempPos = nNewPos; 467cdf0e10cSrcweir while ( nTempPos < rEditMask.Len() ) 468cdf0e10cSrcweir { 469cdf0e10cSrcweir if ( rEditMask.GetChar(nTempPos+1) != EDITMASK_LITERAL ) 470cdf0e10cSrcweir { 471cdf0e10cSrcweir nNewPos = nTempPos+1; 472cdf0e10cSrcweir break; 473cdf0e10cSrcweir } 474cdf0e10cSrcweir nTempPos++; 475cdf0e10cSrcweir } 476cdf0e10cSrcweir ImplPatternMaxPos( rStr, rEditMask, nFormatFlags, bSameMask, nCursorPos, nNewPos ); 477cdf0e10cSrcweir return nNewPos; 478cdf0e10cSrcweir } 479cdf0e10cSrcweir 480cdf0e10cSrcweir // ----------------------------------------------------------------------- 481cdf0e10cSrcweir 482cdf0e10cSrcweir static sal_Bool ImplPatternProcessKeyInput( Edit* pEdit, const KeyEvent& rKEvt, 483cdf0e10cSrcweir const ByteString& rEditMask, 484cdf0e10cSrcweir const XubString& rLiteralMask, 485cdf0e10cSrcweir sal_Bool bStrictFormat, 486cdf0e10cSrcweir sal_uInt16 nFormatFlags, 487cdf0e10cSrcweir sal_Bool bSameMask, 488cdf0e10cSrcweir sal_Bool& rbInKeyInput ) 489cdf0e10cSrcweir { 490cdf0e10cSrcweir if ( !rEditMask.Len() || !bStrictFormat ) 491cdf0e10cSrcweir return sal_False; 492cdf0e10cSrcweir 493cdf0e10cSrcweir Selection aOldSel = pEdit->GetSelection(); 494cdf0e10cSrcweir KeyCode aCode = rKEvt.GetKeyCode(); 495cdf0e10cSrcweir xub_Unicode cChar = rKEvt.GetCharCode(); 496cdf0e10cSrcweir sal_uInt16 nKeyCode = aCode.GetCode(); 497cdf0e10cSrcweir sal_Bool bShift = aCode.IsShift(); 498cdf0e10cSrcweir xub_StrLen nCursorPos = (xub_StrLen)aOldSel.Max(); 499cdf0e10cSrcweir xub_StrLen nNewPos; 500cdf0e10cSrcweir xub_StrLen nTempPos; 501cdf0e10cSrcweir 502cdf0e10cSrcweir if ( nKeyCode && !aCode.IsMod1() && !aCode.IsMod2() ) 503cdf0e10cSrcweir { 504cdf0e10cSrcweir if ( nKeyCode == KEY_LEFT ) 505cdf0e10cSrcweir { 506cdf0e10cSrcweir Selection aSel( ImplPatternLeftPos( rEditMask, nCursorPos ) ); 507cdf0e10cSrcweir if ( bShift ) 508cdf0e10cSrcweir aSel.Min() = aOldSel.Min(); 509cdf0e10cSrcweir pEdit->SetSelection( aSel ); 510cdf0e10cSrcweir return sal_True; 511cdf0e10cSrcweir } 512cdf0e10cSrcweir else if ( nKeyCode == KEY_RIGHT ) 513cdf0e10cSrcweir { 514cdf0e10cSrcweir // Hier nehmen wir Selectionsanfang als minimum, da falls durch 515cdf0e10cSrcweir // Focus alles selektiert ist, ist eine kleine Position schon 516cdf0e10cSrcweir // erlaubt. 517cdf0e10cSrcweir Selection aSel( aOldSel ); 518cdf0e10cSrcweir aSel.Justify(); 519cdf0e10cSrcweir nCursorPos = (xub_StrLen)aSel.Min(); 520cdf0e10cSrcweir aSel.Max() = ImplPatternRightPos( pEdit->GetText(), rEditMask, nFormatFlags, bSameMask, nCursorPos ); 521cdf0e10cSrcweir if ( bShift ) 522cdf0e10cSrcweir aSel.Min() = aOldSel.Min(); 523cdf0e10cSrcweir else 524cdf0e10cSrcweir aSel.Min() = aSel.Max(); 525cdf0e10cSrcweir pEdit->SetSelection( aSel ); 526cdf0e10cSrcweir return sal_True; 527cdf0e10cSrcweir } 528cdf0e10cSrcweir else if ( nKeyCode == KEY_HOME ) 529cdf0e10cSrcweir { 530cdf0e10cSrcweir // Home ist Position des ersten nicht literalen Zeichens 531cdf0e10cSrcweir nNewPos = 0; 532cdf0e10cSrcweir while ( (nNewPos < rEditMask.Len()) && 533cdf0e10cSrcweir (rEditMask.GetChar(nNewPos) == EDITMASK_LITERAL) ) 534cdf0e10cSrcweir nNewPos++; 535cdf0e10cSrcweir // Home sollte nicht nach rechts wandern 536cdf0e10cSrcweir if ( nCursorPos < nNewPos ) 537cdf0e10cSrcweir nNewPos = nCursorPos; 538cdf0e10cSrcweir Selection aSel( nNewPos ); 539cdf0e10cSrcweir if ( bShift ) 540cdf0e10cSrcweir aSel.Min() = aOldSel.Min(); 541cdf0e10cSrcweir pEdit->SetSelection( aSel ); 542cdf0e10cSrcweir return sal_True; 543cdf0e10cSrcweir } 544cdf0e10cSrcweir else if ( nKeyCode == KEY_END ) 545cdf0e10cSrcweir { 546cdf0e10cSrcweir // End ist die Position des letzten nicht literalen Zeichens 547cdf0e10cSrcweir nNewPos = rEditMask.Len(); 548cdf0e10cSrcweir while ( nNewPos && 549cdf0e10cSrcweir (rEditMask.GetChar(nNewPos-1) == EDITMASK_LITERAL) ) 550cdf0e10cSrcweir nNewPos--; 551cdf0e10cSrcweir // Hier nehmen wir Selectionsanfang als minimum, da falls durch 552cdf0e10cSrcweir // Focus alles selektiert ist, ist eine kleine Position schon 553cdf0e10cSrcweir // erlaubt. 554cdf0e10cSrcweir Selection aSel( aOldSel ); 555cdf0e10cSrcweir aSel.Justify(); 556cdf0e10cSrcweir nCursorPos = (xub_StrLen)aSel.Min(); 557cdf0e10cSrcweir ImplPatternMaxPos( pEdit->GetText(), rEditMask, nFormatFlags, bSameMask, nCursorPos, nNewPos ); 558cdf0e10cSrcweir aSel.Max() = nNewPos; 559cdf0e10cSrcweir if ( bShift ) 560cdf0e10cSrcweir aSel.Min() = aOldSel.Min(); 561cdf0e10cSrcweir else 562cdf0e10cSrcweir aSel.Min() = aSel.Max(); 563cdf0e10cSrcweir pEdit->SetSelection( aSel ); 564cdf0e10cSrcweir return sal_True; 565cdf0e10cSrcweir } 566cdf0e10cSrcweir else if ( (nKeyCode == KEY_BACKSPACE) || (nKeyCode == KEY_DELETE) ) 567cdf0e10cSrcweir { 568cdf0e10cSrcweir XubString aStr( pEdit->GetText() ); 569cdf0e10cSrcweir XubString aOldStr = aStr; 570cdf0e10cSrcweir Selection aSel = aOldSel; 571cdf0e10cSrcweir 572cdf0e10cSrcweir aSel.Justify(); 573cdf0e10cSrcweir nNewPos = (xub_StrLen)aSel.Min(); 574cdf0e10cSrcweir 575cdf0e10cSrcweir // Wenn Selection, dann diese Loeschen 576cdf0e10cSrcweir if ( aSel.Len() ) 577cdf0e10cSrcweir { 578cdf0e10cSrcweir if ( bSameMask ) 579cdf0e10cSrcweir aStr.Erase( (xub_StrLen)aSel.Min(), (xub_StrLen)aSel.Len() ); 580cdf0e10cSrcweir else 581cdf0e10cSrcweir { 582cdf0e10cSrcweir XubString aRep = rLiteralMask.Copy( (xub_StrLen)aSel.Min(), (xub_StrLen)aSel.Len() ); 583cdf0e10cSrcweir aStr.Replace( (xub_StrLen)aSel.Min(), aRep.Len(), aRep ); 584cdf0e10cSrcweir } 585cdf0e10cSrcweir } 586cdf0e10cSrcweir else 587cdf0e10cSrcweir { 588cdf0e10cSrcweir if ( nKeyCode == KEY_BACKSPACE ) 589cdf0e10cSrcweir { 590cdf0e10cSrcweir nTempPos = nNewPos; 591cdf0e10cSrcweir nNewPos = ImplPatternLeftPos( rEditMask, nTempPos ); 592cdf0e10cSrcweir } 593cdf0e10cSrcweir else 594cdf0e10cSrcweir nTempPos = ImplPatternRightPos( aStr, rEditMask, nFormatFlags, bSameMask, nNewPos ); 595cdf0e10cSrcweir 596cdf0e10cSrcweir if ( nNewPos != nTempPos ) 597cdf0e10cSrcweir { 598cdf0e10cSrcweir if ( bSameMask ) 599cdf0e10cSrcweir { 600cdf0e10cSrcweir if ( rEditMask.GetChar( nNewPos ) != EDITMASK_LITERAL ) 601cdf0e10cSrcweir aStr.Erase( nNewPos, 1 ); 602cdf0e10cSrcweir } 603cdf0e10cSrcweir else 604cdf0e10cSrcweir { 605cdf0e10cSrcweir XubString aTempStr = rLiteralMask.Copy( nNewPos, 1 ); 606cdf0e10cSrcweir aStr.Replace( nNewPos, aTempStr.Len(), aTempStr ); 607cdf0e10cSrcweir } 608cdf0e10cSrcweir } 609cdf0e10cSrcweir } 610cdf0e10cSrcweir 611cdf0e10cSrcweir if ( aOldStr != aStr ) 612cdf0e10cSrcweir { 613cdf0e10cSrcweir if ( bSameMask ) 614cdf0e10cSrcweir aStr = ImplPatternReformat( aStr, rEditMask, rLiteralMask, nFormatFlags ); 615cdf0e10cSrcweir rbInKeyInput = sal_True; 616cdf0e10cSrcweir pEdit->SetText( aStr, Selection( nNewPos ) ); 617cdf0e10cSrcweir pEdit->SetModifyFlag(); 618cdf0e10cSrcweir pEdit->Modify(); 619cdf0e10cSrcweir rbInKeyInput = sal_False; 620cdf0e10cSrcweir } 621cdf0e10cSrcweir else 622cdf0e10cSrcweir pEdit->SetSelection( Selection( nNewPos ) ); 623cdf0e10cSrcweir 624cdf0e10cSrcweir return sal_True; 625cdf0e10cSrcweir } 626cdf0e10cSrcweir else if ( nKeyCode == KEY_INSERT ) 627cdf0e10cSrcweir { 628cdf0e10cSrcweir // InsertModus kann man beim PatternField nur einstellen, 629cdf0e10cSrcweir // wenn Maske an jeder Eingabeposition die gleiche 630cdf0e10cSrcweir // ist 631cdf0e10cSrcweir if ( !bSameMask ) 632cdf0e10cSrcweir { 633cdf0e10cSrcweir Sound::Beep(); 634cdf0e10cSrcweir return sal_True; 635cdf0e10cSrcweir } 636cdf0e10cSrcweir } 637cdf0e10cSrcweir } 638cdf0e10cSrcweir 639cdf0e10cSrcweir if ( rKEvt.GetKeyCode().IsMod2() || (cChar < 32) || (cChar == 127) ) 640cdf0e10cSrcweir return sal_False; 641cdf0e10cSrcweir 642cdf0e10cSrcweir Selection aSel = aOldSel; 643cdf0e10cSrcweir aSel.Justify(); 644cdf0e10cSrcweir nNewPos = (xub_StrLen)aSel.Min(); 645cdf0e10cSrcweir 646cdf0e10cSrcweir if ( nNewPos < rEditMask.Len() ) 647cdf0e10cSrcweir { 648cdf0e10cSrcweir xub_Unicode cPattChar = ImplPatternChar( cChar, rEditMask.GetChar(nNewPos) ); 649cdf0e10cSrcweir if ( cPattChar ) 650cdf0e10cSrcweir cChar = cPattChar; 651cdf0e10cSrcweir else 652cdf0e10cSrcweir { 653cdf0e10cSrcweir // Wenn kein gueltiges Zeichen, dann testen wir, ob der 654cdf0e10cSrcweir // Anwender zum naechsten Literal springen wollte. Dies machen 655cdf0e10cSrcweir // wir nur, wenn er hinter einem Zeichen steht, damit 656cdf0e10cSrcweir // eingebene Literale die automatisch uebersprungenen wurden 657cdf0e10cSrcweir // nicht dazu fuehren, das der Anwender dann da steht, wo 658cdf0e10cSrcweir // er nicht stehen wollte. 659cdf0e10cSrcweir if ( nNewPos && 660cdf0e10cSrcweir (rEditMask.GetChar(nNewPos-1) != EDITMASK_LITERAL) && 661cdf0e10cSrcweir !aSel.Len() ) 662cdf0e10cSrcweir { 663cdf0e10cSrcweir // Naechstes Zeichen suchen, was kein Literal ist 664cdf0e10cSrcweir nTempPos = nNewPos; 665cdf0e10cSrcweir while ( nTempPos < rEditMask.Len() ) 666cdf0e10cSrcweir { 667cdf0e10cSrcweir if ( rEditMask.GetChar(nTempPos) == EDITMASK_LITERAL ) 668cdf0e10cSrcweir { 669cdf0e10cSrcweir // Gilt nur, wenn ein Literalzeichen vorhanden 670cdf0e10cSrcweir if ( (rEditMask.GetChar(nTempPos+1) != EDITMASK_LITERAL ) && 671cdf0e10cSrcweir ImplKommaPointCharEqual( cChar, rLiteralMask.GetChar(nTempPos) ) ) 672cdf0e10cSrcweir { 673cdf0e10cSrcweir nTempPos++; 674cdf0e10cSrcweir ImplPatternMaxPos( pEdit->GetText(), rEditMask, nFormatFlags, bSameMask, nNewPos, nTempPos ); 675cdf0e10cSrcweir if ( nTempPos > nNewPos ) 676cdf0e10cSrcweir { 677cdf0e10cSrcweir pEdit->SetSelection( Selection( nTempPos ) ); 678cdf0e10cSrcweir return sal_True; 679cdf0e10cSrcweir } 680cdf0e10cSrcweir } 681cdf0e10cSrcweir break; 682cdf0e10cSrcweir } 683cdf0e10cSrcweir nTempPos++; 684cdf0e10cSrcweir } 685cdf0e10cSrcweir } 686cdf0e10cSrcweir 687cdf0e10cSrcweir cChar = 0; 688cdf0e10cSrcweir } 689cdf0e10cSrcweir } 690cdf0e10cSrcweir else 691cdf0e10cSrcweir cChar = 0; 692cdf0e10cSrcweir if ( cChar ) 693cdf0e10cSrcweir { 694cdf0e10cSrcweir XubString aStr = pEdit->GetText(); 695cdf0e10cSrcweir sal_Bool bError = sal_False; 696cdf0e10cSrcweir if ( bSameMask && pEdit->IsInsertMode() ) 697cdf0e10cSrcweir { 698cdf0e10cSrcweir // Text um Spacezeichen und Literale am Ende kuerzen, bis zur 699cdf0e10cSrcweir // aktuellen Position 700cdf0e10cSrcweir xub_StrLen n = aStr.Len(); 701cdf0e10cSrcweir while ( n && (n > nNewPos) ) 702cdf0e10cSrcweir { 703cdf0e10cSrcweir if ( (aStr.GetChar( n-1 ) != ' ') && 704cdf0e10cSrcweir ((n > rEditMask.Len()) || (rEditMask.GetChar(n-1) != EDITMASK_LITERAL)) ) 705cdf0e10cSrcweir break; 706cdf0e10cSrcweir 707cdf0e10cSrcweir n--; 708cdf0e10cSrcweir } 709cdf0e10cSrcweir aStr.Erase( n ); 710cdf0e10cSrcweir 711cdf0e10cSrcweir if ( aSel.Len() ) 712cdf0e10cSrcweir aStr.Erase( (xub_StrLen)aSel.Min(), (xub_StrLen)aSel.Len() ); 713cdf0e10cSrcweir 714cdf0e10cSrcweir if ( aStr.Len() < rEditMask.Len() ) 715cdf0e10cSrcweir { 716cdf0e10cSrcweir // String evtl. noch bis Cursor-Position erweitern 717cdf0e10cSrcweir if ( aStr.Len() < nNewPos ) 718cdf0e10cSrcweir aStr += rLiteralMask.Copy( aStr.Len(), nNewPos-aStr.Len() ); 719cdf0e10cSrcweir if ( nNewPos < aStr.Len() ) 720cdf0e10cSrcweir aStr.Insert( cChar, nNewPos ); 721cdf0e10cSrcweir else if ( nNewPos < rEditMask.Len() ) 722cdf0e10cSrcweir aStr += cChar; 723cdf0e10cSrcweir aStr = ImplPatternReformat( aStr, rEditMask, rLiteralMask, nFormatFlags ); 724cdf0e10cSrcweir } 725cdf0e10cSrcweir else 726cdf0e10cSrcweir bError = sal_True; 727cdf0e10cSrcweir } 728cdf0e10cSrcweir else 729cdf0e10cSrcweir { 730cdf0e10cSrcweir if ( aSel.Len() ) 731cdf0e10cSrcweir { 732cdf0e10cSrcweir // Selection loeschen 733cdf0e10cSrcweir XubString aRep = rLiteralMask.Copy( (xub_StrLen)aSel.Min(), (xub_StrLen)aSel.Len() ); 734cdf0e10cSrcweir aStr.Replace( (xub_StrLen)aSel.Min(), aRep.Len(), aRep ); 735cdf0e10cSrcweir } 736cdf0e10cSrcweir 737cdf0e10cSrcweir if ( nNewPos < aStr.Len() ) 738cdf0e10cSrcweir aStr.SetChar( nNewPos, cChar ); 739cdf0e10cSrcweir else if ( nNewPos < rEditMask.Len() ) 740cdf0e10cSrcweir aStr += cChar; 741cdf0e10cSrcweir } 742cdf0e10cSrcweir 743cdf0e10cSrcweir if ( bError ) 744cdf0e10cSrcweir Sound::Beep(); 745cdf0e10cSrcweir else 746cdf0e10cSrcweir { 747cdf0e10cSrcweir rbInKeyInput = sal_True; 748cdf0e10cSrcweir Selection aNewSel( ImplPatternRightPos( aStr, rEditMask, nFormatFlags, bSameMask, nNewPos ) ); 749cdf0e10cSrcweir pEdit->SetText( aStr, aNewSel ); 750cdf0e10cSrcweir pEdit->SetModifyFlag(); 751cdf0e10cSrcweir pEdit->Modify(); 752cdf0e10cSrcweir rbInKeyInput = sal_False; 753cdf0e10cSrcweir } 754cdf0e10cSrcweir } 755cdf0e10cSrcweir else 756cdf0e10cSrcweir Sound::Beep(); 757cdf0e10cSrcweir 758cdf0e10cSrcweir return sal_True; 759cdf0e10cSrcweir } 760cdf0e10cSrcweir 761cdf0e10cSrcweir // ----------------------------------------------------------------------- 762cdf0e10cSrcweir 763cdf0e10cSrcweir void PatternFormatter::ImplSetMask( const ByteString& rEditMask, 764cdf0e10cSrcweir const XubString& rLiteralMask ) 765cdf0e10cSrcweir { 766cdf0e10cSrcweir maEditMask = rEditMask; 767cdf0e10cSrcweir maLiteralMask = rLiteralMask; 768cdf0e10cSrcweir mbSameMask = sal_True; 769cdf0e10cSrcweir 770cdf0e10cSrcweir if ( maEditMask.Len() != maLiteralMask.Len() ) 771cdf0e10cSrcweir { 772cdf0e10cSrcweir if ( maEditMask.Len() < maLiteralMask.Len() ) 773cdf0e10cSrcweir maLiteralMask.Erase( maEditMask.Len() ); 774cdf0e10cSrcweir else 775cdf0e10cSrcweir maLiteralMask.Expand( maEditMask.Len(), ' ' ); 776cdf0e10cSrcweir } 777cdf0e10cSrcweir 778cdf0e10cSrcweir // StrictModus erlaubt nur Input-Mode, wenn als Maske nur 779cdf0e10cSrcweir // gleiche Zeichen zugelassen werden und als Vorgabe nur 780cdf0e10cSrcweir // Spacezeichen vorgegeben werden, die durch die Maske 781cdf0e10cSrcweir // nicht zugelassen sind 782cdf0e10cSrcweir xub_StrLen i = 0; 783cdf0e10cSrcweir sal_Char c = 0; 784cdf0e10cSrcweir while ( i < rEditMask.Len() ) 785cdf0e10cSrcweir { 786cdf0e10cSrcweir sal_Char cTemp = rEditMask.GetChar( i ); 787cdf0e10cSrcweir if ( cTemp != EDITMASK_LITERAL ) 788cdf0e10cSrcweir { 789cdf0e10cSrcweir if ( (cTemp == EDITMASK_ALLCHAR) || 790cdf0e10cSrcweir (cTemp == EDITMASK_UPPERALLCHAR) || 791cdf0e10cSrcweir (cTemp == EDITMASK_NUMSPACE) ) 792cdf0e10cSrcweir { 793cdf0e10cSrcweir mbSameMask = sal_False; 794cdf0e10cSrcweir break; 795cdf0e10cSrcweir } 796cdf0e10cSrcweir if ( i < rLiteralMask.Len() ) 797cdf0e10cSrcweir { 798cdf0e10cSrcweir if ( rLiteralMask.GetChar( i ) != ' ' ) 799cdf0e10cSrcweir { 800cdf0e10cSrcweir mbSameMask = sal_False; 801cdf0e10cSrcweir break; 802cdf0e10cSrcweir } 803cdf0e10cSrcweir } 804cdf0e10cSrcweir if ( !c ) 805cdf0e10cSrcweir c = cTemp; 806cdf0e10cSrcweir if ( cTemp != c ) 807cdf0e10cSrcweir { 808cdf0e10cSrcweir mbSameMask = sal_False; 809cdf0e10cSrcweir break; 810cdf0e10cSrcweir } 811cdf0e10cSrcweir } 812cdf0e10cSrcweir i++; 813cdf0e10cSrcweir } 814cdf0e10cSrcweir } 815cdf0e10cSrcweir 816cdf0e10cSrcweir // ----------------------------------------------------------------------- 817cdf0e10cSrcweir 818cdf0e10cSrcweir PatternFormatter::PatternFormatter() 819cdf0e10cSrcweir { 820cdf0e10cSrcweir mnFormatFlags = 0; 821cdf0e10cSrcweir mbSameMask = sal_True; 822cdf0e10cSrcweir mbInPattKeyInput = sal_False; 823cdf0e10cSrcweir } 824cdf0e10cSrcweir 825cdf0e10cSrcweir // ----------------------------------------------------------------------- 826cdf0e10cSrcweir 827cdf0e10cSrcweir void PatternFormatter::ImplLoadRes( const ResId& rResId ) 828cdf0e10cSrcweir { 829cdf0e10cSrcweir ByteString aEditMask; 830cdf0e10cSrcweir XubString aLiteralMask; 831cdf0e10cSrcweir ResMgr* pMgr = rResId.GetResMgr(); 832cdf0e10cSrcweir if( pMgr ) 833cdf0e10cSrcweir { 834cdf0e10cSrcweir sal_uLong nMask = pMgr->ReadLong(); 835cdf0e10cSrcweir 836cdf0e10cSrcweir if ( PATTERNFORMATTER_STRICTFORMAT & nMask ) 837cdf0e10cSrcweir SetStrictFormat( (sal_Bool)pMgr->ReadShort() ); 838cdf0e10cSrcweir 839cdf0e10cSrcweir if ( PATTERNFORMATTER_EDITMASK & nMask ) 840cdf0e10cSrcweir aEditMask = ByteString( pMgr->ReadString(), RTL_TEXTENCODING_ASCII_US ); 841cdf0e10cSrcweir 842cdf0e10cSrcweir if ( PATTERNFORMATTER_LITTERALMASK & nMask ) 843cdf0e10cSrcweir aLiteralMask = pMgr->ReadString(); 844cdf0e10cSrcweir 845cdf0e10cSrcweir if ( (PATTERNFORMATTER_EDITMASK | PATTERNFORMATTER_LITTERALMASK) & nMask ) 846cdf0e10cSrcweir ImplSetMask( aEditMask, aLiteralMask ); 847cdf0e10cSrcweir } 848cdf0e10cSrcweir } 849cdf0e10cSrcweir 850cdf0e10cSrcweir // ----------------------------------------------------------------------- 851cdf0e10cSrcweir 852cdf0e10cSrcweir PatternFormatter::~PatternFormatter() 853cdf0e10cSrcweir { 854cdf0e10cSrcweir } 855cdf0e10cSrcweir 856cdf0e10cSrcweir // ----------------------------------------------------------------------- 857cdf0e10cSrcweir 858cdf0e10cSrcweir void PatternFormatter::SetMask( const ByteString& rEditMask, 859cdf0e10cSrcweir const XubString& rLiteralMask ) 860cdf0e10cSrcweir { 861cdf0e10cSrcweir ImplSetMask( rEditMask, rLiteralMask ); 862cdf0e10cSrcweir ReformatAll(); 863cdf0e10cSrcweir } 864cdf0e10cSrcweir 865cdf0e10cSrcweir // ----------------------------------------------------------------------- 866cdf0e10cSrcweir 867cdf0e10cSrcweir void PatternFormatter::SetString( const XubString& rStr ) 868cdf0e10cSrcweir { 869cdf0e10cSrcweir maFieldString = rStr; 870cdf0e10cSrcweir if ( GetField() ) 871cdf0e10cSrcweir { 872cdf0e10cSrcweir GetField()->SetText( rStr ); 873cdf0e10cSrcweir MarkToBeReformatted( sal_False ); 874cdf0e10cSrcweir } 875cdf0e10cSrcweir } 876cdf0e10cSrcweir 877cdf0e10cSrcweir // ----------------------------------------------------------------------- 878cdf0e10cSrcweir 879cdf0e10cSrcweir XubString PatternFormatter::GetString() const 880cdf0e10cSrcweir { 881cdf0e10cSrcweir if ( !GetField() ) 882cdf0e10cSrcweir return ImplGetSVEmptyStr(); 883cdf0e10cSrcweir else 884cdf0e10cSrcweir return ImplPatternReformat( GetField()->GetText(), maEditMask, maLiteralMask, mnFormatFlags ); 885cdf0e10cSrcweir } 886cdf0e10cSrcweir 887cdf0e10cSrcweir // ----------------------------------------------------------------------- 888cdf0e10cSrcweir 889cdf0e10cSrcweir void PatternFormatter::Reformat() 890cdf0e10cSrcweir { 891cdf0e10cSrcweir if ( GetField() ) 892cdf0e10cSrcweir { 893cdf0e10cSrcweir ImplSetText( ImplPatternReformat( GetField()->GetText(), maEditMask, maLiteralMask, mnFormatFlags ) ); 894cdf0e10cSrcweir if ( !mbSameMask && IsStrictFormat() && !GetField()->IsReadOnly() ) 895cdf0e10cSrcweir GetField()->SetInsertMode( sal_False ); 896cdf0e10cSrcweir } 897cdf0e10cSrcweir } 898cdf0e10cSrcweir 899cdf0e10cSrcweir // ----------------------------------------------------------------------- 900cdf0e10cSrcweir 901cdf0e10cSrcweir void PatternFormatter::SelectFixedFont() 902cdf0e10cSrcweir { 903cdf0e10cSrcweir if ( GetField() ) 904cdf0e10cSrcweir { 905cdf0e10cSrcweir Font aFont = OutputDevice::GetDefaultFont( DEFAULTFONT_FIXED, Application::GetSettings().GetLanguage(), 0 ); 906cdf0e10cSrcweir Font aControlFont; 907cdf0e10cSrcweir aControlFont.SetName( aFont.GetName() ); 908cdf0e10cSrcweir aControlFont.SetFamily( aFont.GetFamily() ); 909cdf0e10cSrcweir aControlFont.SetPitch( aFont.GetPitch() ); 910cdf0e10cSrcweir GetField()->SetControlFont( aControlFont ); 911cdf0e10cSrcweir } 912cdf0e10cSrcweir } 913cdf0e10cSrcweir 914cdf0e10cSrcweir // ----------------------------------------------------------------------- 915cdf0e10cSrcweir 916cdf0e10cSrcweir PatternField::PatternField( Window* pParent, WinBits nWinStyle ) : 917cdf0e10cSrcweir SpinField( pParent, nWinStyle ) 918cdf0e10cSrcweir { 919cdf0e10cSrcweir SetField( this ); 920cdf0e10cSrcweir Reformat(); 921cdf0e10cSrcweir } 922cdf0e10cSrcweir 923cdf0e10cSrcweir // ----------------------------------------------------------------------- 924cdf0e10cSrcweir 925cdf0e10cSrcweir PatternField::PatternField( Window* pParent, const ResId& rResId ) : 926cdf0e10cSrcweir SpinField( WINDOW_PATTERNFIELD ) 927cdf0e10cSrcweir { 928cdf0e10cSrcweir rResId.SetRT( RSC_PATTERNFIELD ); 929cdf0e10cSrcweir WinBits nStyle = ImplInitRes( rResId ); 930cdf0e10cSrcweir ImplInit( pParent, nStyle ); 931cdf0e10cSrcweir SetField( this ); 932cdf0e10cSrcweir SpinField::ImplLoadRes( rResId ); 933cdf0e10cSrcweir PatternFormatter::ImplLoadRes( ResId( (RSHEADER_TYPE *)GetClassRes(), *rResId.GetResMgr() ) ); 934cdf0e10cSrcweir Reformat(); 935cdf0e10cSrcweir 936cdf0e10cSrcweir if ( !(nStyle & WB_HIDE ) ) 937cdf0e10cSrcweir Show(); 938cdf0e10cSrcweir } 939cdf0e10cSrcweir 940cdf0e10cSrcweir // ----------------------------------------------------------------------- 941cdf0e10cSrcweir 942cdf0e10cSrcweir PatternField::~PatternField() 943cdf0e10cSrcweir { 944cdf0e10cSrcweir } 945cdf0e10cSrcweir 946cdf0e10cSrcweir // ----------------------------------------------------------------------- 947cdf0e10cSrcweir 948cdf0e10cSrcweir long PatternField::PreNotify( NotifyEvent& rNEvt ) 949cdf0e10cSrcweir { 950cdf0e10cSrcweir if ( (rNEvt.GetType() == EVENT_KEYINPUT) && !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() ) 951cdf0e10cSrcweir { 952cdf0e10cSrcweir if ( ImplPatternProcessKeyInput( GetField(), *rNEvt.GetKeyEvent(), GetEditMask(), GetLiteralMask(), 953cdf0e10cSrcweir IsStrictFormat(), GetFormatFlags(), 954cdf0e10cSrcweir ImplIsSameMask(), ImplGetInPattKeyInput() ) ) 955cdf0e10cSrcweir return 1; 956cdf0e10cSrcweir } 957cdf0e10cSrcweir 958cdf0e10cSrcweir return SpinField::PreNotify( rNEvt ); 959cdf0e10cSrcweir } 960cdf0e10cSrcweir 961cdf0e10cSrcweir // ----------------------------------------------------------------------- 962cdf0e10cSrcweir 963cdf0e10cSrcweir long PatternField::Notify( NotifyEvent& rNEvt ) 964cdf0e10cSrcweir { 965cdf0e10cSrcweir if ( rNEvt.GetType() == EVENT_GETFOCUS ) 966cdf0e10cSrcweir MarkToBeReformatted( sal_False ); 967cdf0e10cSrcweir else if ( rNEvt.GetType() == EVENT_LOSEFOCUS ) 968cdf0e10cSrcweir { 969cdf0e10cSrcweir if ( MustBeReformatted() && (GetText().Len() || !IsEmptyFieldValueEnabled()) ) 970cdf0e10cSrcweir Reformat(); 971cdf0e10cSrcweir } 972cdf0e10cSrcweir 973cdf0e10cSrcweir return SpinField::Notify( rNEvt ); 974cdf0e10cSrcweir } 975cdf0e10cSrcweir 976cdf0e10cSrcweir // ----------------------------------------------------------------------- 977cdf0e10cSrcweir 978cdf0e10cSrcweir void PatternField::Modify() 979cdf0e10cSrcweir { 980cdf0e10cSrcweir if ( !ImplGetInPattKeyInput() ) 981cdf0e10cSrcweir { 982cdf0e10cSrcweir if ( IsStrictFormat() ) 983cdf0e10cSrcweir ImplPatternProcessStrictModify( GetField(), GetEditMask(), GetLiteralMask(), GetFormatFlags(), ImplIsSameMask() ); 984cdf0e10cSrcweir else 985cdf0e10cSrcweir MarkToBeReformatted( sal_True ); 986cdf0e10cSrcweir } 987cdf0e10cSrcweir 988cdf0e10cSrcweir SpinField::Modify(); 989cdf0e10cSrcweir } 990cdf0e10cSrcweir 991cdf0e10cSrcweir // ----------------------------------------------------------------------- 992cdf0e10cSrcweir 993cdf0e10cSrcweir PatternBox::PatternBox( Window* pParent, WinBits nWinStyle ) : 994cdf0e10cSrcweir ComboBox( pParent, nWinStyle ) 995cdf0e10cSrcweir { 996cdf0e10cSrcweir SetField( this ); 997cdf0e10cSrcweir Reformat(); 998cdf0e10cSrcweir } 999cdf0e10cSrcweir 1000cdf0e10cSrcweir // ----------------------------------------------------------------------- 1001cdf0e10cSrcweir 1002cdf0e10cSrcweir PatternBox::PatternBox( Window* pParent, const ResId& rResId ) : 1003cdf0e10cSrcweir ComboBox( WINDOW_PATTERNBOX ) 1004cdf0e10cSrcweir { 1005cdf0e10cSrcweir rResId.SetRT( RSC_PATTERNBOX ); 1006cdf0e10cSrcweir WinBits nStyle = ImplInitRes( rResId ); 1007cdf0e10cSrcweir ImplInit( pParent, nStyle ); 1008cdf0e10cSrcweir 1009cdf0e10cSrcweir SetField( this ); 1010cdf0e10cSrcweir ComboBox::ImplLoadRes( rResId ); 1011cdf0e10cSrcweir PatternFormatter::ImplLoadRes( ResId( (RSHEADER_TYPE *)GetClassRes(), *rResId.GetResMgr() ) ); 1012cdf0e10cSrcweir Reformat(); 1013cdf0e10cSrcweir 1014cdf0e10cSrcweir if ( !(nStyle & WB_HIDE ) ) 1015cdf0e10cSrcweir Show(); 1016cdf0e10cSrcweir } 1017cdf0e10cSrcweir 1018cdf0e10cSrcweir // ----------------------------------------------------------------------- 1019cdf0e10cSrcweir 1020cdf0e10cSrcweir PatternBox::~PatternBox() 1021cdf0e10cSrcweir { 1022cdf0e10cSrcweir } 1023cdf0e10cSrcweir 1024cdf0e10cSrcweir // ----------------------------------------------------------------------- 1025cdf0e10cSrcweir 1026cdf0e10cSrcweir long PatternBox::PreNotify( NotifyEvent& rNEvt ) 1027cdf0e10cSrcweir { 1028cdf0e10cSrcweir if ( (rNEvt.GetType() == EVENT_KEYINPUT) && !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() ) 1029cdf0e10cSrcweir { 1030cdf0e10cSrcweir if ( ImplPatternProcessKeyInput( GetField(), *rNEvt.GetKeyEvent(), GetEditMask(), GetLiteralMask(), 1031cdf0e10cSrcweir IsStrictFormat(), GetFormatFlags(), 1032cdf0e10cSrcweir ImplIsSameMask(), ImplGetInPattKeyInput() ) ) 1033cdf0e10cSrcweir return 1; 1034cdf0e10cSrcweir } 1035cdf0e10cSrcweir 1036cdf0e10cSrcweir return ComboBox::PreNotify( rNEvt ); 1037cdf0e10cSrcweir } 1038cdf0e10cSrcweir 1039cdf0e10cSrcweir // ----------------------------------------------------------------------- 1040cdf0e10cSrcweir 1041cdf0e10cSrcweir long PatternBox::Notify( NotifyEvent& rNEvt ) 1042cdf0e10cSrcweir { 1043cdf0e10cSrcweir if ( rNEvt.GetType() == EVENT_GETFOCUS ) 1044cdf0e10cSrcweir MarkToBeReformatted( sal_False ); 1045cdf0e10cSrcweir else if ( rNEvt.GetType() == EVENT_LOSEFOCUS ) 1046cdf0e10cSrcweir { 1047cdf0e10cSrcweir if ( MustBeReformatted() && (GetText().Len() || !IsEmptyFieldValueEnabled()) ) 1048cdf0e10cSrcweir Reformat(); 1049cdf0e10cSrcweir } 1050cdf0e10cSrcweir 1051cdf0e10cSrcweir return ComboBox::Notify( rNEvt ); 1052cdf0e10cSrcweir } 1053cdf0e10cSrcweir 1054cdf0e10cSrcweir // ----------------------------------------------------------------------- 1055cdf0e10cSrcweir 1056cdf0e10cSrcweir void PatternBox::Modify() 1057cdf0e10cSrcweir { 1058cdf0e10cSrcweir if ( !ImplGetInPattKeyInput() ) 1059cdf0e10cSrcweir { 1060cdf0e10cSrcweir if ( IsStrictFormat() ) 1061cdf0e10cSrcweir ImplPatternProcessStrictModify( GetField(), GetEditMask(), GetLiteralMask(), GetFormatFlags(), ImplIsSameMask() ); 1062cdf0e10cSrcweir else 1063cdf0e10cSrcweir MarkToBeReformatted( sal_True ); 1064cdf0e10cSrcweir } 1065cdf0e10cSrcweir 1066cdf0e10cSrcweir ComboBox::Modify(); 1067cdf0e10cSrcweir } 1068cdf0e10cSrcweir 1069cdf0e10cSrcweir // ----------------------------------------------------------------------- 1070cdf0e10cSrcweir 1071cdf0e10cSrcweir void PatternBox::ReformatAll() 1072cdf0e10cSrcweir { 1073cdf0e10cSrcweir XubString aStr; 1074cdf0e10cSrcweir SetUpdateMode( sal_False ); 1075cdf0e10cSrcweir sal_uInt16 nEntryCount = GetEntryCount(); 1076cdf0e10cSrcweir for ( sal_uInt16 i=0; i < nEntryCount; i++ ) 1077cdf0e10cSrcweir { 1078cdf0e10cSrcweir aStr = ImplPatternReformat( GetEntry( i ), GetEditMask(), GetLiteralMask(), GetFormatFlags() ); 1079cdf0e10cSrcweir RemoveEntry( i ); 1080cdf0e10cSrcweir InsertEntry( aStr, i ); 1081cdf0e10cSrcweir } 1082cdf0e10cSrcweir PatternFormatter::Reformat(); 1083cdf0e10cSrcweir SetUpdateMode( sal_True ); 1084cdf0e10cSrcweir } 1085cdf0e10cSrcweir 1086cdf0e10cSrcweir // ----------------------------------------------------------------------- 1087cdf0e10cSrcweir 1088cdf0e10cSrcweir void PatternBox::InsertString( const XubString& rStr, sal_uInt16 nPos ) 1089cdf0e10cSrcweir { 1090cdf0e10cSrcweir ComboBox::InsertEntry( ImplPatternReformat( rStr, GetEditMask(), GetLiteralMask(), GetFormatFlags() ), nPos ); 1091cdf0e10cSrcweir } 1092cdf0e10cSrcweir 1093cdf0e10cSrcweir // ----------------------------------------------------------------------- 1094cdf0e10cSrcweir 1095cdf0e10cSrcweir void PatternBox::RemoveString( const XubString& rStr ) 1096cdf0e10cSrcweir { 1097cdf0e10cSrcweir ComboBox::RemoveEntry( ImplPatternReformat( rStr, GetEditMask(), GetLiteralMask(), GetFormatFlags() ) ); 1098cdf0e10cSrcweir } 1099cdf0e10cSrcweir 1100cdf0e10cSrcweir // ----------------------------------------------------------------------- 1101cdf0e10cSrcweir 1102cdf0e10cSrcweir XubString PatternBox::GetString( sal_uInt16 nPos ) const 1103cdf0e10cSrcweir { 1104cdf0e10cSrcweir return ImplPatternReformat( ComboBox::GetEntry( nPos ), GetEditMask(), GetLiteralMask(), GetFormatFlags() ); 1105cdf0e10cSrcweir } 1106cdf0e10cSrcweir 1107cdf0e10cSrcweir // ----------------------------------------------------------------------- 1108cdf0e10cSrcweir 1109cdf0e10cSrcweir sal_uInt16 PatternBox::GetStringPos( const XubString& rStr ) const 1110cdf0e10cSrcweir { 1111cdf0e10cSrcweir return ComboBox::GetEntryPos( ImplPatternReformat( rStr, GetEditMask(), GetLiteralMask(), GetFormatFlags() ) ); 1112cdf0e10cSrcweir } 1113cdf0e10cSrcweir 1114cdf0e10cSrcweir // ======================================================================= 1115cdf0e10cSrcweir 1116cdf0e10cSrcweir static ExtDateFieldFormat ImplGetExtFormat( DateFormat eOld ) 1117cdf0e10cSrcweir { 1118cdf0e10cSrcweir switch( eOld ) 1119cdf0e10cSrcweir { 1120cdf0e10cSrcweir case DMY: return XTDATEF_SHORT_DDMMYY; 1121cdf0e10cSrcweir case MDY: return XTDATEF_SHORT_MMDDYY; 1122cdf0e10cSrcweir default: return XTDATEF_SHORT_YYMMDD; 1123cdf0e10cSrcweir } 1124cdf0e10cSrcweir } 1125cdf0e10cSrcweir 1126cdf0e10cSrcweir // ----------------------------------------------------------------------- 1127cdf0e10cSrcweir 1128cdf0e10cSrcweir static sal_uInt16 ImplCutNumberFromString( XubString& rStr ) 1129cdf0e10cSrcweir { 1130cdf0e10cSrcweir // Nach Zahl suchen 1131cdf0e10cSrcweir while ( rStr.Len() && !(rStr.GetChar( 0 ) >= '0' && rStr.GetChar( 0 ) <= '9') ) 1132cdf0e10cSrcweir rStr.Erase( 0, 1 ); 1133cdf0e10cSrcweir if ( !rStr.Len() ) 1134cdf0e10cSrcweir return 0; 1135cdf0e10cSrcweir XubString aNumStr; 1136cdf0e10cSrcweir while ( rStr.Len() && (rStr.GetChar( 0 ) >= '0' && rStr.GetChar( 0 ) <= '9') ) 1137cdf0e10cSrcweir { 1138cdf0e10cSrcweir aNumStr.Insert( rStr.GetChar( 0 ) ); 1139cdf0e10cSrcweir rStr.Erase( 0, 1 ); 1140cdf0e10cSrcweir } 1141cdf0e10cSrcweir return (sal_uInt16)aNumStr.ToInt32(); 1142cdf0e10cSrcweir } 1143cdf0e10cSrcweir 1144cdf0e10cSrcweir // ----------------------------------------------------------------------- 1145cdf0e10cSrcweir 1146cdf0e10cSrcweir static sal_Bool ImplCutMonthName( XubString& rStr, const XubString& _rLookupMonthName ) 1147cdf0e10cSrcweir { 1148cdf0e10cSrcweir sal_uInt16 nPos = rStr.Search( _rLookupMonthName ); 1149cdf0e10cSrcweir if ( nPos != STRING_NOTFOUND ) 1150cdf0e10cSrcweir { 1151cdf0e10cSrcweir rStr.Erase( 0, nPos + _rLookupMonthName.Len() ); 1152cdf0e10cSrcweir return sal_True; 1153cdf0e10cSrcweir } 1154cdf0e10cSrcweir return sal_False; 1155cdf0e10cSrcweir } 1156cdf0e10cSrcweir 1157cdf0e10cSrcweir // ----------------------------------------------------------------------- 1158cdf0e10cSrcweir 1159cdf0e10cSrcweir static sal_uInt16 ImplCutMonthFromString( XubString& rStr, const CalendarWrapper& rCalendarWrapper ) 1160cdf0e10cSrcweir { 1161cdf0e10cSrcweir // search for a month' name 1162cdf0e10cSrcweir for ( sal_uInt16 i=1; i <= 12; i++ ) 1163cdf0e10cSrcweir { 1164cdf0e10cSrcweir String aMonthName = rCalendarWrapper.getMonths()[i-1].FullName; 1165cdf0e10cSrcweir // long month name? 1166cdf0e10cSrcweir if ( ImplCutMonthName( rStr, aMonthName ) ) 1167cdf0e10cSrcweir return i; 1168cdf0e10cSrcweir 1169cdf0e10cSrcweir // short month name? 1170cdf0e10cSrcweir String aAbbrevMonthName = rCalendarWrapper.getMonths()[i-1].AbbrevName; 1171cdf0e10cSrcweir if ( ImplCutMonthName( rStr, aAbbrevMonthName ) ) 1172cdf0e10cSrcweir return i; 1173cdf0e10cSrcweir } 1174cdf0e10cSrcweir 1175cdf0e10cSrcweir return ImplCutNumberFromString( rStr ); 1176cdf0e10cSrcweir } 1177cdf0e10cSrcweir 1178cdf0e10cSrcweir // ----------------------------------------------------------------------- 1179cdf0e10cSrcweir 1180cdf0e10cSrcweir static String ImplGetDateSep( const LocaleDataWrapper& rLocaleDataWrapper, ExtDateFieldFormat eFormat ) 1181cdf0e10cSrcweir { 1182cdf0e10cSrcweir String aDateSep = rLocaleDataWrapper.getDateSep(); 1183cdf0e10cSrcweir 1184cdf0e10cSrcweir if ( ( eFormat == XTDATEF_SHORT_YYMMDD_DIN5008 ) || ( eFormat == XTDATEF_SHORT_YYYYMMDD_DIN5008 ) ) 1185cdf0e10cSrcweir aDateSep = String( RTL_CONSTASCII_USTRINGPARAM( "-" ) ); 1186cdf0e10cSrcweir 1187cdf0e10cSrcweir return aDateSep; 1188cdf0e10cSrcweir } 1189cdf0e10cSrcweir 1190cdf0e10cSrcweir static sal_Bool ImplDateProcessKeyInput( Edit*, const KeyEvent& rKEvt, ExtDateFieldFormat eFormat, 1191cdf0e10cSrcweir const LocaleDataWrapper& rLocaleDataWrapper ) 1192cdf0e10cSrcweir { 1193cdf0e10cSrcweir xub_Unicode cChar = rKEvt.GetCharCode(); 1194cdf0e10cSrcweir sal_uInt16 nGroup = rKEvt.GetKeyCode().GetGroup(); 1195cdf0e10cSrcweir if ( (nGroup == KEYGROUP_FKEYS) || (nGroup == KEYGROUP_CURSOR) || 1196cdf0e10cSrcweir (nGroup == KEYGROUP_MISC)|| 1197cdf0e10cSrcweir ((cChar >= '0') && (cChar <= '9')) || 1198cdf0e10cSrcweir (cChar == ImplGetDateSep( rLocaleDataWrapper, eFormat ).GetChar(0) ) ) 1199cdf0e10cSrcweir return sal_False; 1200cdf0e10cSrcweir else 1201cdf0e10cSrcweir return sal_True; 1202cdf0e10cSrcweir } 1203cdf0e10cSrcweir 1204cdf0e10cSrcweir // ----------------------------------------------------------------------- 1205cdf0e10cSrcweir 1206cdf0e10cSrcweir static sal_Bool ImplDateGetValue( const XubString& rStr, Date& rDate, ExtDateFieldFormat eDateFormat, 1207cdf0e10cSrcweir const LocaleDataWrapper& rLocaleDataWrapper, const CalendarWrapper& rCalendarWrapper, 1208cdf0e10cSrcweir const AllSettings& ) 1209cdf0e10cSrcweir { 1210cdf0e10cSrcweir sal_uInt16 nDay = 0; 1211cdf0e10cSrcweir sal_uInt16 nMonth = 0; 1212cdf0e10cSrcweir sal_uInt16 nYear = 0; 1213cdf0e10cSrcweir sal_Bool bYear = sal_True; 1214cdf0e10cSrcweir sal_Bool bError = sal_False; 1215cdf0e10cSrcweir String aStr( rStr ); 1216cdf0e10cSrcweir 1217cdf0e10cSrcweir if ( eDateFormat == XTDATEF_SYSTEM_LONG ) 1218cdf0e10cSrcweir { 1219cdf0e10cSrcweir DateFormat eFormat = rLocaleDataWrapper.getLongDateFormat(); 1220cdf0e10cSrcweir switch( eFormat ) 1221cdf0e10cSrcweir { 1222cdf0e10cSrcweir case MDY: 1223cdf0e10cSrcweir nMonth = ImplCutMonthFromString( aStr, rCalendarWrapper ); 1224cdf0e10cSrcweir nDay = ImplCutNumberFromString( aStr ); 1225cdf0e10cSrcweir nYear = ImplCutNumberFromString( aStr ); 1226cdf0e10cSrcweir break; 1227cdf0e10cSrcweir case DMY: 1228cdf0e10cSrcweir nDay = ImplCutNumberFromString( aStr ); 1229cdf0e10cSrcweir nMonth = ImplCutMonthFromString( aStr, rCalendarWrapper ); 1230cdf0e10cSrcweir nYear = ImplCutNumberFromString( aStr ); 1231cdf0e10cSrcweir break; 1232cdf0e10cSrcweir case YMD: 1233cdf0e10cSrcweir default: 1234cdf0e10cSrcweir nYear = ImplCutNumberFromString( aStr ); 1235cdf0e10cSrcweir nMonth = ImplCutMonthFromString( aStr, rCalendarWrapper ); 1236cdf0e10cSrcweir nDay = ImplCutNumberFromString( aStr ); 1237cdf0e10cSrcweir break; 1238cdf0e10cSrcweir } 1239cdf0e10cSrcweir } 1240cdf0e10cSrcweir else 1241cdf0e10cSrcweir { 1242cdf0e10cSrcweir // Check if year is present: 1243cdf0e10cSrcweir String aDateSep = ImplGetDateSep( rLocaleDataWrapper, eDateFormat ); 1244cdf0e10cSrcweir sal_uInt16 nSepPos = aStr.Search( aDateSep ); 1245cdf0e10cSrcweir if ( nSepPos == STRING_NOTFOUND ) 1246cdf0e10cSrcweir return sal_False; 1247cdf0e10cSrcweir nSepPos = aStr.Search( aDateSep, nSepPos+1 ); 1248cdf0e10cSrcweir if ( ( nSepPos == STRING_NOTFOUND ) || ( nSepPos == (aStr.Len()-1) ) ) 1249cdf0e10cSrcweir { 1250cdf0e10cSrcweir bYear = sal_False; 1251cdf0e10cSrcweir nYear = Date().GetYear(); 1252cdf0e10cSrcweir } 1253cdf0e10cSrcweir 1254cdf0e10cSrcweir const sal_Unicode* pBuf = aStr.GetBuffer(); 1255cdf0e10cSrcweir ImplSkipDelimiters( pBuf ); 1256cdf0e10cSrcweir 1257cdf0e10cSrcweir switch ( eDateFormat ) 1258cdf0e10cSrcweir { 1259cdf0e10cSrcweir case XTDATEF_SHORT_DDMMYY: 1260cdf0e10cSrcweir case XTDATEF_SHORT_DDMMYYYY: 1261cdf0e10cSrcweir { 1262cdf0e10cSrcweir nDay = ImplGetNum( pBuf, bError ); 1263cdf0e10cSrcweir ImplSkipDelimiters( pBuf ); 1264cdf0e10cSrcweir nMonth = ImplGetNum( pBuf, bError ); 1265cdf0e10cSrcweir ImplSkipDelimiters( pBuf ); 1266cdf0e10cSrcweir if ( bYear ) 1267cdf0e10cSrcweir nYear = ImplGetNum( pBuf, bError ); 1268cdf0e10cSrcweir } 1269cdf0e10cSrcweir break; 1270cdf0e10cSrcweir case XTDATEF_SHORT_MMDDYY: 1271cdf0e10cSrcweir case XTDATEF_SHORT_MMDDYYYY: 1272cdf0e10cSrcweir { 1273cdf0e10cSrcweir nMonth = ImplGetNum( pBuf, bError ); 1274cdf0e10cSrcweir ImplSkipDelimiters( pBuf ); 1275cdf0e10cSrcweir nDay = ImplGetNum( pBuf, bError ); 1276cdf0e10cSrcweir ImplSkipDelimiters( pBuf ); 1277cdf0e10cSrcweir if ( bYear ) 1278cdf0e10cSrcweir nYear = ImplGetNum( pBuf, bError ); 1279cdf0e10cSrcweir } 1280cdf0e10cSrcweir break; 1281cdf0e10cSrcweir case XTDATEF_SHORT_YYMMDD: 1282cdf0e10cSrcweir case XTDATEF_SHORT_YYYYMMDD: 1283cdf0e10cSrcweir case XTDATEF_SHORT_YYMMDD_DIN5008: 1284cdf0e10cSrcweir case XTDATEF_SHORT_YYYYMMDD_DIN5008: 1285cdf0e10cSrcweir { 1286cdf0e10cSrcweir if ( bYear ) 1287cdf0e10cSrcweir nYear = ImplGetNum( pBuf, bError ); 1288cdf0e10cSrcweir ImplSkipDelimiters( pBuf ); 1289cdf0e10cSrcweir nMonth = ImplGetNum( pBuf, bError ); 1290cdf0e10cSrcweir ImplSkipDelimiters( pBuf ); 1291cdf0e10cSrcweir nDay = ImplGetNum( pBuf, bError ); 1292cdf0e10cSrcweir } 1293cdf0e10cSrcweir break; 1294cdf0e10cSrcweir 1295cdf0e10cSrcweir default: 1296cdf0e10cSrcweir { 1297cdf0e10cSrcweir DBG_ERROR( "DateFormat???" ); 1298cdf0e10cSrcweir } 1299cdf0e10cSrcweir } 1300cdf0e10cSrcweir } 1301cdf0e10cSrcweir 1302cdf0e10cSrcweir if ( bError || !nDay || !nMonth ) 1303cdf0e10cSrcweir return sal_False; 1304cdf0e10cSrcweir 1305cdf0e10cSrcweir Date aNewDate( nDay, nMonth, nYear ); 1306cdf0e10cSrcweir DateFormatter::ExpandCentury( aNewDate, utl::MiscCfg().GetYear2000() ); 1307cdf0e10cSrcweir if ( aNewDate.IsValid() ) 1308cdf0e10cSrcweir { 1309cdf0e10cSrcweir rDate = aNewDate; 1310cdf0e10cSrcweir return sal_True; 1311cdf0e10cSrcweir } 1312cdf0e10cSrcweir return sal_False; 1313cdf0e10cSrcweir } 1314cdf0e10cSrcweir 1315cdf0e10cSrcweir // ----------------------------------------------------------------------- 1316cdf0e10cSrcweir 1317cdf0e10cSrcweir sal_Bool DateFormatter::ImplDateReformat( const XubString& rStr, XubString& rOutStr, const AllSettings& rSettings ) 1318cdf0e10cSrcweir { 1319cdf0e10cSrcweir Date aDate( 0, 0, 0 ); 1320cdf0e10cSrcweir if ( !ImplDateGetValue( rStr, aDate, GetExtDateFormat(sal_True), ImplGetLocaleDataWrapper(), GetCalendarWrapper(), GetFieldSettings() ) ) 1321cdf0e10cSrcweir return sal_True; 1322cdf0e10cSrcweir 1323cdf0e10cSrcweir Date aTempDate = aDate; 1324cdf0e10cSrcweir if ( aTempDate > GetMax() ) 1325cdf0e10cSrcweir aTempDate = GetMax(); 1326cdf0e10cSrcweir else if ( aTempDate < GetMin() ) 1327cdf0e10cSrcweir aTempDate = GetMin(); 1328cdf0e10cSrcweir 1329cdf0e10cSrcweir if ( GetErrorHdl().IsSet() && (aDate != aTempDate) ) 1330cdf0e10cSrcweir { 1331cdf0e10cSrcweir maCorrectedDate = aTempDate; 1332cdf0e10cSrcweir if( !GetErrorHdl().Call( this ) ) 1333cdf0e10cSrcweir { 1334cdf0e10cSrcweir maCorrectedDate = Date(); 1335cdf0e10cSrcweir return sal_False; 1336cdf0e10cSrcweir } 1337cdf0e10cSrcweir else 1338cdf0e10cSrcweir maCorrectedDate = Date(); 1339cdf0e10cSrcweir } 1340cdf0e10cSrcweir 1341cdf0e10cSrcweir rOutStr = ImplGetDateAsText( aTempDate, rSettings ); 1342cdf0e10cSrcweir 1343cdf0e10cSrcweir return sal_True; 1344cdf0e10cSrcweir } 1345cdf0e10cSrcweir 1346cdf0e10cSrcweir // ----------------------------------------------------------------------- 1347cdf0e10cSrcweir 1348cdf0e10cSrcweir XubString DateFormatter::ImplGetDateAsText( const Date& rDate, 1349cdf0e10cSrcweir const AllSettings& ) const 1350cdf0e10cSrcweir { 1351cdf0e10cSrcweir sal_Bool bShowCentury = sal_False; 1352cdf0e10cSrcweir switch ( GetExtDateFormat() ) 1353cdf0e10cSrcweir { 1354cdf0e10cSrcweir case XTDATEF_SYSTEM_SHORT_YYYY: 1355cdf0e10cSrcweir case XTDATEF_SYSTEM_LONG: 1356cdf0e10cSrcweir case XTDATEF_SHORT_DDMMYYYY: 1357cdf0e10cSrcweir case XTDATEF_SHORT_MMDDYYYY: 1358cdf0e10cSrcweir case XTDATEF_SHORT_YYYYMMDD: 1359cdf0e10cSrcweir case XTDATEF_SHORT_YYYYMMDD_DIN5008: 1360cdf0e10cSrcweir { 1361cdf0e10cSrcweir bShowCentury = sal_True; 1362cdf0e10cSrcweir } 1363cdf0e10cSrcweir break; 1364cdf0e10cSrcweir default: 1365cdf0e10cSrcweir { 1366cdf0e10cSrcweir bShowCentury = sal_False; 1367cdf0e10cSrcweir } 1368cdf0e10cSrcweir } 1369cdf0e10cSrcweir 1370cdf0e10cSrcweir if ( !bShowCentury ) 1371cdf0e10cSrcweir { 1372cdf0e10cSrcweir // Check if I have to use force showing the century 1373cdf0e10cSrcweir sal_uInt16 nTwoDigitYearStart = utl::MiscCfg().GetYear2000(); 1374cdf0e10cSrcweir sal_uInt16 nYear = rDate.GetYear(); 1375cdf0e10cSrcweir 1376cdf0e10cSrcweir // Wenn Jahr nicht im 2stelligen Grenzbereich liegt, 1377cdf0e10cSrcweir if ( (nYear < nTwoDigitYearStart) || (nYear >= nTwoDigitYearStart+100) ) 1378cdf0e10cSrcweir bShowCentury = sal_True; 1379cdf0e10cSrcweir } 1380cdf0e10cSrcweir 1381cdf0e10cSrcweir sal_Unicode aBuf[128]; 1382cdf0e10cSrcweir sal_Unicode* pBuf = aBuf; 1383cdf0e10cSrcweir 1384cdf0e10cSrcweir String aDateSep = ImplGetDateSep( ImplGetLocaleDataWrapper(), GetExtDateFormat( sal_True ) ); 1385cdf0e10cSrcweir sal_uInt16 nDay = rDate.GetDay(); 1386cdf0e10cSrcweir sal_uInt16 nMonth = rDate.GetMonth(); 1387cdf0e10cSrcweir sal_uInt16 nYear = rDate.GetYear(); 1388cdf0e10cSrcweir sal_uInt16 nYearLen = bShowCentury ? 4 : 2; 1389cdf0e10cSrcweir 1390cdf0e10cSrcweir if ( !bShowCentury ) 1391cdf0e10cSrcweir nYear %= 100; 1392cdf0e10cSrcweir 1393cdf0e10cSrcweir switch ( GetExtDateFormat( sal_True ) ) 1394cdf0e10cSrcweir { 1395cdf0e10cSrcweir case XTDATEF_SYSTEM_LONG: 1396cdf0e10cSrcweir { 1397cdf0e10cSrcweir return ImplGetLocaleDataWrapper().getLongDate( rDate, GetCalendarWrapper(), 1, sal_False, 1, !bShowCentury ); 1398cdf0e10cSrcweir } 1399cdf0e10cSrcweir case XTDATEF_SHORT_DDMMYY: 1400cdf0e10cSrcweir case XTDATEF_SHORT_DDMMYYYY: 1401cdf0e10cSrcweir { 1402cdf0e10cSrcweir pBuf = ImplAddNum( pBuf, nDay, 2 ); 1403cdf0e10cSrcweir pBuf = ImplAddString( pBuf, aDateSep ); 1404cdf0e10cSrcweir pBuf = ImplAddNum( pBuf, nMonth, 2 ); 1405cdf0e10cSrcweir pBuf = ImplAddString( pBuf, aDateSep ); 1406cdf0e10cSrcweir pBuf = ImplAddNum( pBuf, nYear, nYearLen ); 1407cdf0e10cSrcweir } 1408cdf0e10cSrcweir break; 1409cdf0e10cSrcweir case XTDATEF_SHORT_MMDDYY: 1410cdf0e10cSrcweir case XTDATEF_SHORT_MMDDYYYY: 1411cdf0e10cSrcweir { 1412cdf0e10cSrcweir pBuf = ImplAddNum( pBuf, nMonth, 2 ); 1413cdf0e10cSrcweir pBuf = ImplAddString( pBuf, aDateSep ); 1414cdf0e10cSrcweir pBuf = ImplAddNum( pBuf, nDay, 2 ); 1415cdf0e10cSrcweir pBuf = ImplAddString( pBuf, aDateSep ); 1416cdf0e10cSrcweir pBuf = ImplAddNum( pBuf, nYear, nYearLen ); 1417cdf0e10cSrcweir } 1418cdf0e10cSrcweir break; 1419cdf0e10cSrcweir case XTDATEF_SHORT_YYMMDD: 1420cdf0e10cSrcweir case XTDATEF_SHORT_YYYYMMDD: 1421cdf0e10cSrcweir case XTDATEF_SHORT_YYMMDD_DIN5008: 1422cdf0e10cSrcweir case XTDATEF_SHORT_YYYYMMDD_DIN5008: 1423cdf0e10cSrcweir { 1424cdf0e10cSrcweir pBuf = ImplAddNum( pBuf, nYear, nYearLen ); 1425cdf0e10cSrcweir pBuf = ImplAddString( pBuf, aDateSep ); 1426cdf0e10cSrcweir pBuf = ImplAddNum( pBuf, nMonth, 2 ); 1427cdf0e10cSrcweir pBuf = ImplAddString( pBuf, aDateSep ); 1428cdf0e10cSrcweir pBuf = ImplAddNum( pBuf, nDay, 2 ); 1429cdf0e10cSrcweir } 1430cdf0e10cSrcweir break; 1431cdf0e10cSrcweir default: 1432cdf0e10cSrcweir { 1433cdf0e10cSrcweir DBG_ERROR( "DateFormat???" ); 1434cdf0e10cSrcweir } 1435cdf0e10cSrcweir } 1436cdf0e10cSrcweir 1437cdf0e10cSrcweir return String( aBuf, (xub_StrLen)(sal_uLong)(pBuf-aBuf) ); 1438cdf0e10cSrcweir } 1439cdf0e10cSrcweir 1440cdf0e10cSrcweir // ----------------------------------------------------------------------- 1441cdf0e10cSrcweir 1442cdf0e10cSrcweir static void ImplDateIncrementDay( Date& rDate, sal_Bool bUp ) 1443cdf0e10cSrcweir { 1444cdf0e10cSrcweir DateFormatter::ExpandCentury( rDate ); 1445cdf0e10cSrcweir 1446cdf0e10cSrcweir if ( bUp ) 1447cdf0e10cSrcweir { 1448cdf0e10cSrcweir if ( (rDate.GetDay() != 31) || (rDate.GetMonth() != 12) || (rDate.GetYear() != 9999) ) 1449cdf0e10cSrcweir rDate++; 1450cdf0e10cSrcweir } 1451cdf0e10cSrcweir else 1452cdf0e10cSrcweir { 1453cdf0e10cSrcweir if ( (rDate.GetDay() != 1 ) || (rDate.GetMonth() != 1) || (rDate.GetYear() != 0) ) 1454cdf0e10cSrcweir rDate--; 1455cdf0e10cSrcweir } 1456cdf0e10cSrcweir } 1457cdf0e10cSrcweir 1458cdf0e10cSrcweir // ----------------------------------------------------------------------- 1459cdf0e10cSrcweir 1460cdf0e10cSrcweir static void ImplDateIncrementMonth( Date& rDate, sal_Bool bUp ) 1461cdf0e10cSrcweir { 1462cdf0e10cSrcweir DateFormatter::ExpandCentury( rDate ); 1463cdf0e10cSrcweir 1464cdf0e10cSrcweir sal_uInt16 nMonth = rDate.GetMonth(); 1465cdf0e10cSrcweir sal_uInt16 nYear = rDate.GetYear(); 1466cdf0e10cSrcweir if ( bUp ) 1467cdf0e10cSrcweir { 1468cdf0e10cSrcweir if ( (nMonth == 12) && (nYear < 9999) ) 1469cdf0e10cSrcweir { 1470cdf0e10cSrcweir rDate.SetMonth( 1 ); 1471cdf0e10cSrcweir rDate.SetYear( nYear + 1 ); 1472cdf0e10cSrcweir } 1473cdf0e10cSrcweir else 1474cdf0e10cSrcweir { 1475cdf0e10cSrcweir if ( nMonth < 12 ) 1476cdf0e10cSrcweir rDate.SetMonth( nMonth + 1 ); 1477cdf0e10cSrcweir } 1478cdf0e10cSrcweir } 1479cdf0e10cSrcweir else 1480cdf0e10cSrcweir { 1481cdf0e10cSrcweir if ( (nMonth == 1) && (nYear > 0) ) 1482cdf0e10cSrcweir { 1483cdf0e10cSrcweir rDate.SetMonth( 12 ); 1484cdf0e10cSrcweir rDate.SetYear( nYear - 1 ); 1485cdf0e10cSrcweir } 1486cdf0e10cSrcweir else 1487cdf0e10cSrcweir { 1488cdf0e10cSrcweir if ( nMonth > 1 ) 1489cdf0e10cSrcweir rDate.SetMonth( nMonth - 1 ); 1490cdf0e10cSrcweir } 1491cdf0e10cSrcweir } 1492cdf0e10cSrcweir 1493cdf0e10cSrcweir sal_uInt16 nDaysInMonth = rDate.GetDaysInMonth(); 1494cdf0e10cSrcweir if ( rDate.GetDay() > nDaysInMonth ) 1495cdf0e10cSrcweir rDate.SetDay( nDaysInMonth ); 1496cdf0e10cSrcweir } 1497cdf0e10cSrcweir 1498cdf0e10cSrcweir // ----------------------------------------------------------------------- 1499cdf0e10cSrcweir 1500cdf0e10cSrcweir static void ImplDateIncrementYear( Date& rDate, sal_Bool bUp ) 1501cdf0e10cSrcweir { 1502cdf0e10cSrcweir DateFormatter::ExpandCentury( rDate ); 1503cdf0e10cSrcweir 1504cdf0e10cSrcweir sal_uInt16 nYear = rDate.GetYear(); 1505cdf0e10cSrcweir if ( bUp ) 1506cdf0e10cSrcweir { 1507cdf0e10cSrcweir if ( nYear < 9999 ) 1508cdf0e10cSrcweir rDate.SetYear( nYear + 1 ); 1509cdf0e10cSrcweir } 1510cdf0e10cSrcweir else 1511cdf0e10cSrcweir { 1512cdf0e10cSrcweir if ( nYear > 0 ) 1513cdf0e10cSrcweir rDate.SetYear( nYear - 1 ); 1514cdf0e10cSrcweir } 1515cdf0e10cSrcweir } 1516cdf0e10cSrcweir 1517cdf0e10cSrcweir // ----------------------------------------------------------------------- 1518cdf0e10cSrcweir sal_Bool DateFormatter::ImplAllowMalformedInput() const 1519cdf0e10cSrcweir { 1520cdf0e10cSrcweir return !IsEnforceValidValue(); 1521cdf0e10cSrcweir } 1522cdf0e10cSrcweir 1523cdf0e10cSrcweir // ----------------------------------------------------------------------- 1524cdf0e10cSrcweir 1525cdf0e10cSrcweir void DateField::ImplDateSpinArea( sal_Bool bUp ) 1526cdf0e10cSrcweir { 1527cdf0e10cSrcweir // Wenn alles selektiert ist, Tage hochzaehlen 1528cdf0e10cSrcweir if ( GetField() ) 1529cdf0e10cSrcweir { 1530cdf0e10cSrcweir Date aDate( GetDate() ); 1531cdf0e10cSrcweir Selection aSelection = GetField()->GetSelection(); 1532cdf0e10cSrcweir aSelection.Justify(); 1533cdf0e10cSrcweir XubString aText( GetText() ); 1534cdf0e10cSrcweir if ( (xub_StrLen)aSelection.Len() == aText.Len() ) 1535cdf0e10cSrcweir ImplDateIncrementDay( aDate, bUp ); 1536cdf0e10cSrcweir else 1537cdf0e10cSrcweir { 1538cdf0e10cSrcweir xub_StrLen nDateArea = 0; 1539cdf0e10cSrcweir 1540cdf0e10cSrcweir ExtDateFieldFormat eFormat = GetExtDateFormat( sal_True ); 1541cdf0e10cSrcweir if ( eFormat == XTDATEF_SYSTEM_LONG ) 1542cdf0e10cSrcweir { 1543cdf0e10cSrcweir eFormat = ImplGetExtFormat( ImplGetLocaleDataWrapper().getLongDateFormat() ); 1544cdf0e10cSrcweir nDateArea = 1; 1545cdf0e10cSrcweir } 1546cdf0e10cSrcweir else 1547cdf0e10cSrcweir { 1548cdf0e10cSrcweir // Area suchen 1549cdf0e10cSrcweir xub_StrLen nPos = 0; 1550cdf0e10cSrcweir String aDateSep = ImplGetDateSep( ImplGetLocaleDataWrapper(), eFormat ); 1551cdf0e10cSrcweir for ( xub_StrLen i = 1; i <= 3; i++ ) 1552cdf0e10cSrcweir { 1553cdf0e10cSrcweir nPos = aText.Search( aDateSep, nPos ); 1554cdf0e10cSrcweir if ( nPos >= (sal_uInt16)aSelection.Max() ) 1555cdf0e10cSrcweir { 1556cdf0e10cSrcweir nDateArea = i; 1557cdf0e10cSrcweir break; 1558cdf0e10cSrcweir } 1559cdf0e10cSrcweir else 1560cdf0e10cSrcweir nPos++; 1561cdf0e10cSrcweir } 1562cdf0e10cSrcweir } 1563cdf0e10cSrcweir 1564cdf0e10cSrcweir 1565cdf0e10cSrcweir switch( eFormat ) 1566cdf0e10cSrcweir { 1567cdf0e10cSrcweir case XTDATEF_SHORT_MMDDYY: 1568cdf0e10cSrcweir case XTDATEF_SHORT_MMDDYYYY: 1569cdf0e10cSrcweir switch( nDateArea ) 1570cdf0e10cSrcweir { 1571cdf0e10cSrcweir case 1: ImplDateIncrementMonth( aDate, bUp ); 1572cdf0e10cSrcweir break; 1573cdf0e10cSrcweir case 2: ImplDateIncrementDay( aDate, bUp ); 1574cdf0e10cSrcweir break; 1575cdf0e10cSrcweir case 3: ImplDateIncrementYear( aDate, bUp ); 1576cdf0e10cSrcweir break; 1577cdf0e10cSrcweir } 1578cdf0e10cSrcweir break; 1579cdf0e10cSrcweir case XTDATEF_SHORT_DDMMYY: 1580cdf0e10cSrcweir case XTDATEF_SHORT_DDMMYYYY: 1581cdf0e10cSrcweir switch( nDateArea ) 1582cdf0e10cSrcweir { 1583cdf0e10cSrcweir case 1: ImplDateIncrementDay( aDate, bUp ); 1584cdf0e10cSrcweir break; 1585cdf0e10cSrcweir case 2: ImplDateIncrementMonth( aDate, bUp ); 1586cdf0e10cSrcweir break; 1587cdf0e10cSrcweir case 3: ImplDateIncrementYear( aDate, bUp ); 1588cdf0e10cSrcweir break; 1589cdf0e10cSrcweir } 1590cdf0e10cSrcweir break; 1591cdf0e10cSrcweir case XTDATEF_SHORT_YYMMDD: 1592cdf0e10cSrcweir case XTDATEF_SHORT_YYYYMMDD: 1593cdf0e10cSrcweir case XTDATEF_SHORT_YYMMDD_DIN5008: 1594cdf0e10cSrcweir case XTDATEF_SHORT_YYYYMMDD_DIN5008: 1595cdf0e10cSrcweir switch( nDateArea ) 1596cdf0e10cSrcweir { 1597cdf0e10cSrcweir case 1: ImplDateIncrementYear( aDate, bUp ); 1598cdf0e10cSrcweir break; 1599cdf0e10cSrcweir case 2: ImplDateIncrementMonth( aDate, bUp ); 1600cdf0e10cSrcweir break; 1601cdf0e10cSrcweir case 3: ImplDateIncrementDay( aDate, bUp ); 1602cdf0e10cSrcweir break; 1603cdf0e10cSrcweir } 1604cdf0e10cSrcweir break; 1605cdf0e10cSrcweir default: 1606cdf0e10cSrcweir DBG_ERROR( "invalid conversion" ); 1607cdf0e10cSrcweir break; 1608cdf0e10cSrcweir } 1609cdf0e10cSrcweir } 1610cdf0e10cSrcweir 1611cdf0e10cSrcweir ImplNewFieldValue( aDate ); 1612cdf0e10cSrcweir } 1613cdf0e10cSrcweir } 1614cdf0e10cSrcweir 1615cdf0e10cSrcweir // ----------------------------------------------------------------------- 1616cdf0e10cSrcweir 1617cdf0e10cSrcweir void DateFormatter::ImplInit() 1618cdf0e10cSrcweir { 1619cdf0e10cSrcweir mbLongFormat = sal_False; 1620cdf0e10cSrcweir mbShowDateCentury = sal_True; 1621cdf0e10cSrcweir mpCalendarWrapper = NULL; 1622cdf0e10cSrcweir mnDateFormat = 0xFFFF; 1623cdf0e10cSrcweir mnExtDateFormat = XTDATEF_SYSTEM_SHORT; 1624cdf0e10cSrcweir } 1625cdf0e10cSrcweir 1626cdf0e10cSrcweir // ----------------------------------------------------------------------- 1627cdf0e10cSrcweir 1628cdf0e10cSrcweir DateFormatter::DateFormatter() : 1629cdf0e10cSrcweir maFieldDate( 0 ), 1630cdf0e10cSrcweir maLastDate( 0 ), 1631cdf0e10cSrcweir maMin( 1, 1, 1900 ), 1632cdf0e10cSrcweir maMax( 31, 12, 2200 ), 1633cdf0e10cSrcweir mbEnforceValidValue( sal_True ) 1634cdf0e10cSrcweir { 1635cdf0e10cSrcweir ImplInit(); 1636cdf0e10cSrcweir } 1637cdf0e10cSrcweir 1638cdf0e10cSrcweir // ----------------------------------------------------------------------- 1639cdf0e10cSrcweir 1640cdf0e10cSrcweir void DateFormatter::ImplLoadRes( const ResId& rResId ) 1641cdf0e10cSrcweir { 1642cdf0e10cSrcweir ResMgr* pMgr = rResId.GetResMgr(); 1643cdf0e10cSrcweir if( pMgr ) 1644cdf0e10cSrcweir { 1645cdf0e10cSrcweir sal_uLong nMask = pMgr->ReadLong(); 1646cdf0e10cSrcweir 1647cdf0e10cSrcweir if ( DATEFORMATTER_MIN & nMask ) 1648cdf0e10cSrcweir { 1649cdf0e10cSrcweir maMin = Date( ResId( (RSHEADER_TYPE *)pMgr->GetClass(), *pMgr ) ); 1650cdf0e10cSrcweir pMgr->Increment( pMgr->GetObjSize( (RSHEADER_TYPE*)pMgr->GetClass() ) ); 1651cdf0e10cSrcweir } 1652cdf0e10cSrcweir if ( DATEFORMATTER_MAX & nMask ) 1653cdf0e10cSrcweir { 1654cdf0e10cSrcweir maMax = Date( ResId( (RSHEADER_TYPE *)pMgr->GetClass(), *pMgr ) ); 1655cdf0e10cSrcweir pMgr->Increment( pMgr->GetObjSize( (RSHEADER_TYPE*)pMgr->GetClass() ) ); 1656cdf0e10cSrcweir } 1657cdf0e10cSrcweir if ( DATEFORMATTER_LONGFORMAT & nMask ) 1658cdf0e10cSrcweir mbLongFormat = (sal_Bool)pMgr->ReadShort(); 1659cdf0e10cSrcweir 1660cdf0e10cSrcweir if ( DATEFORMATTER_STRICTFORMAT & nMask ) 1661cdf0e10cSrcweir SetStrictFormat( (sal_Bool)pMgr->ReadShort() ); 1662cdf0e10cSrcweir 1663cdf0e10cSrcweir if ( DATEFORMATTER_VALUE & nMask ) 1664cdf0e10cSrcweir { 1665cdf0e10cSrcweir maFieldDate = Date( ResId( (RSHEADER_TYPE *)pMgr->GetClass(), *pMgr ) ); 1666cdf0e10cSrcweir pMgr->Increment( pMgr->GetObjSize( (RSHEADER_TYPE*)pMgr->GetClass() ) ); 1667cdf0e10cSrcweir if ( maFieldDate > maMax ) 1668cdf0e10cSrcweir maFieldDate = maMax; 1669cdf0e10cSrcweir if ( maFieldDate < maMin ) 1670cdf0e10cSrcweir maFieldDate = maMin; 1671cdf0e10cSrcweir maLastDate = maFieldDate; 1672cdf0e10cSrcweir } 1673cdf0e10cSrcweir } 1674cdf0e10cSrcweir } 1675cdf0e10cSrcweir 1676cdf0e10cSrcweir // ----------------------------------------------------------------------- 1677cdf0e10cSrcweir 1678cdf0e10cSrcweir DateFormatter::~DateFormatter() 1679cdf0e10cSrcweir { 1680cdf0e10cSrcweir delete mpCalendarWrapper; 1681cdf0e10cSrcweir mpCalendarWrapper = NULL; 1682cdf0e10cSrcweir } 1683cdf0e10cSrcweir 1684cdf0e10cSrcweir // ----------------------------------------------------------------------- 1685cdf0e10cSrcweir 1686cdf0e10cSrcweir void DateFormatter::SetLocale( const ::com::sun::star::lang::Locale& rLocale ) 1687cdf0e10cSrcweir { 1688cdf0e10cSrcweir delete mpCalendarWrapper; 1689cdf0e10cSrcweir mpCalendarWrapper = NULL; 1690cdf0e10cSrcweir FormatterBase::SetLocale( rLocale ); 1691cdf0e10cSrcweir } 1692cdf0e10cSrcweir 1693cdf0e10cSrcweir 1694cdf0e10cSrcweir // ----------------------------------------------------------------------- 1695cdf0e10cSrcweir 1696cdf0e10cSrcweir CalendarWrapper& DateFormatter::GetCalendarWrapper() const 1697cdf0e10cSrcweir { 1698cdf0e10cSrcweir if ( !mpCalendarWrapper ) 1699cdf0e10cSrcweir { 1700cdf0e10cSrcweir ((DateFormatter*)this)->mpCalendarWrapper = new CalendarWrapper( vcl::unohelper::GetMultiServiceFactory() ); 1701cdf0e10cSrcweir mpCalendarWrapper->loadDefaultCalendar( GetLocale() ); 1702cdf0e10cSrcweir } 1703cdf0e10cSrcweir 1704cdf0e10cSrcweir return *mpCalendarWrapper; 1705cdf0e10cSrcweir } 1706cdf0e10cSrcweir 1707cdf0e10cSrcweir // ----------------------------------------------------------------------- 1708cdf0e10cSrcweir 1709cdf0e10cSrcweir void DateFormatter::SetExtDateFormat( ExtDateFieldFormat eFormat ) 1710cdf0e10cSrcweir { 1711cdf0e10cSrcweir mnExtDateFormat = eFormat; 1712cdf0e10cSrcweir ReformatAll(); 1713cdf0e10cSrcweir } 1714cdf0e10cSrcweir 1715cdf0e10cSrcweir // ----------------------------------------------------------------------- 1716cdf0e10cSrcweir 1717cdf0e10cSrcweir ExtDateFieldFormat DateFormatter::GetExtDateFormat( sal_Bool bResolveSystemFormat ) const 1718cdf0e10cSrcweir { 1719cdf0e10cSrcweir ExtDateFieldFormat eDateFormat = (ExtDateFieldFormat)mnExtDateFormat; 1720cdf0e10cSrcweir 1721cdf0e10cSrcweir if ( bResolveSystemFormat && ( eDateFormat <= XTDATEF_SYSTEM_SHORT_YYYY ) ) 1722cdf0e10cSrcweir { 1723cdf0e10cSrcweir sal_Bool bShowCentury = (eDateFormat == XTDATEF_SYSTEM_SHORT_YYYY); 1724cdf0e10cSrcweir switch ( ImplGetLocaleDataWrapper().getDateFormat() ) 1725cdf0e10cSrcweir { 1726cdf0e10cSrcweir case DMY: eDateFormat = bShowCentury ? XTDATEF_SHORT_DDMMYYYY : XTDATEF_SHORT_DDMMYY; 1727cdf0e10cSrcweir break; 1728cdf0e10cSrcweir case MDY: eDateFormat = bShowCentury ? XTDATEF_SHORT_MMDDYYYY : XTDATEF_SHORT_MMDDYY; 1729cdf0e10cSrcweir break; 1730cdf0e10cSrcweir default: eDateFormat = bShowCentury ? XTDATEF_SHORT_YYYYMMDD : XTDATEF_SHORT_YYMMDD; 1731cdf0e10cSrcweir 1732cdf0e10cSrcweir } 1733cdf0e10cSrcweir } 1734cdf0e10cSrcweir 1735cdf0e10cSrcweir return eDateFormat; 1736cdf0e10cSrcweir } 1737cdf0e10cSrcweir 1738cdf0e10cSrcweir // ----------------------------------------------------------------------- 1739cdf0e10cSrcweir 1740cdf0e10cSrcweir void DateFormatter::ReformatAll() 1741cdf0e10cSrcweir { 1742cdf0e10cSrcweir Reformat(); 1743cdf0e10cSrcweir } 1744cdf0e10cSrcweir 1745cdf0e10cSrcweir // ----------------------------------------------------------------------- 1746cdf0e10cSrcweir 1747cdf0e10cSrcweir void DateFormatter::SetMin( const Date& rNewMin ) 1748cdf0e10cSrcweir { 1749cdf0e10cSrcweir maMin = rNewMin; 1750cdf0e10cSrcweir if ( !IsEmptyFieldValue() ) 1751cdf0e10cSrcweir ReformatAll(); 1752cdf0e10cSrcweir } 1753cdf0e10cSrcweir 1754cdf0e10cSrcweir // ----------------------------------------------------------------------- 1755cdf0e10cSrcweir 1756cdf0e10cSrcweir void DateFormatter::SetMax( const Date& rNewMax ) 1757cdf0e10cSrcweir { 1758cdf0e10cSrcweir maMax = rNewMax; 1759cdf0e10cSrcweir if ( !IsEmptyFieldValue() ) 1760cdf0e10cSrcweir ReformatAll(); 1761cdf0e10cSrcweir } 1762cdf0e10cSrcweir 1763cdf0e10cSrcweir // ----------------------------------------------------------------------- 1764cdf0e10cSrcweir 1765cdf0e10cSrcweir void DateFormatter::SetLongFormat( sal_Bool bLong ) 1766cdf0e10cSrcweir { 1767cdf0e10cSrcweir mbLongFormat = bLong; 1768cdf0e10cSrcweir 1769cdf0e10cSrcweir // #91913# Remove LongFormat and DateShowCentury - redundant 1770cdf0e10cSrcweir if ( bLong ) 1771cdf0e10cSrcweir { 1772cdf0e10cSrcweir SetExtDateFormat( XTDATEF_SYSTEM_LONG ); 1773cdf0e10cSrcweir } 1774cdf0e10cSrcweir else 1775cdf0e10cSrcweir { 1776cdf0e10cSrcweir if( mnExtDateFormat == XTDATEF_SYSTEM_LONG ) 1777cdf0e10cSrcweir SetExtDateFormat( XTDATEF_SYSTEM_SHORT ); 1778cdf0e10cSrcweir } 1779cdf0e10cSrcweir 1780cdf0e10cSrcweir ReformatAll(); 1781cdf0e10cSrcweir } 1782cdf0e10cSrcweir 1783cdf0e10cSrcweir // ----------------------------------------------------------------------- 1784cdf0e10cSrcweir 1785cdf0e10cSrcweir void DateFormatter::SetShowDateCentury( sal_Bool bShowDateCentury ) 1786cdf0e10cSrcweir { 1787cdf0e10cSrcweir mbShowDateCentury = bShowDateCentury; 1788cdf0e10cSrcweir 1789cdf0e10cSrcweir // #91913# Remove LongFormat and DateShowCentury - redundant 1790cdf0e10cSrcweir if ( bShowDateCentury ) 1791cdf0e10cSrcweir { 1792cdf0e10cSrcweir switch ( GetExtDateFormat() ) 1793cdf0e10cSrcweir { 1794cdf0e10cSrcweir case XTDATEF_SYSTEM_SHORT: 1795cdf0e10cSrcweir case XTDATEF_SYSTEM_SHORT_YY: 1796cdf0e10cSrcweir SetExtDateFormat( XTDATEF_SYSTEM_SHORT_YYYY ); break; 1797cdf0e10cSrcweir case XTDATEF_SHORT_DDMMYY: 1798cdf0e10cSrcweir SetExtDateFormat( XTDATEF_SHORT_DDMMYYYY ); break; 1799cdf0e10cSrcweir case XTDATEF_SHORT_MMDDYY: 1800cdf0e10cSrcweir SetExtDateFormat( XTDATEF_SHORT_MMDDYYYY ); break; 1801cdf0e10cSrcweir case XTDATEF_SHORT_YYMMDD: 1802cdf0e10cSrcweir SetExtDateFormat( XTDATEF_SHORT_YYYYMMDD ); break; 1803cdf0e10cSrcweir case XTDATEF_SHORT_YYMMDD_DIN5008: 1804cdf0e10cSrcweir SetExtDateFormat( XTDATEF_SHORT_YYYYMMDD_DIN5008 ); break; 1805cdf0e10cSrcweir default: 1806cdf0e10cSrcweir ; 1807cdf0e10cSrcweir } 1808cdf0e10cSrcweir } 1809cdf0e10cSrcweir else 1810cdf0e10cSrcweir { 1811cdf0e10cSrcweir switch ( GetExtDateFormat() ) 1812cdf0e10cSrcweir { 1813cdf0e10cSrcweir case XTDATEF_SYSTEM_SHORT: 1814cdf0e10cSrcweir case XTDATEF_SYSTEM_SHORT_YYYY: 1815cdf0e10cSrcweir SetExtDateFormat( XTDATEF_SYSTEM_SHORT_YY ); break; 1816cdf0e10cSrcweir case XTDATEF_SHORT_DDMMYYYY: 1817cdf0e10cSrcweir SetExtDateFormat( XTDATEF_SHORT_DDMMYY ); break; 1818cdf0e10cSrcweir case XTDATEF_SHORT_MMDDYYYY: 1819cdf0e10cSrcweir SetExtDateFormat( XTDATEF_SHORT_MMDDYY ); break; 1820cdf0e10cSrcweir case XTDATEF_SHORT_YYYYMMDD: 1821cdf0e10cSrcweir SetExtDateFormat( XTDATEF_SHORT_YYMMDD ); break; 1822cdf0e10cSrcweir case XTDATEF_SHORT_YYYYMMDD_DIN5008: 1823cdf0e10cSrcweir SetExtDateFormat( XTDATEF_SHORT_YYMMDD_DIN5008 ); break; 1824cdf0e10cSrcweir default: 1825cdf0e10cSrcweir ; 1826cdf0e10cSrcweir } 1827cdf0e10cSrcweir } 1828cdf0e10cSrcweir 1829cdf0e10cSrcweir ReformatAll(); 1830cdf0e10cSrcweir } 1831cdf0e10cSrcweir 1832cdf0e10cSrcweir // ----------------------------------------------------------------------- 1833cdf0e10cSrcweir 1834cdf0e10cSrcweir void DateFormatter::SetDate( const Date& rNewDate ) 1835cdf0e10cSrcweir { 1836cdf0e10cSrcweir SetUserDate( rNewDate ); 1837cdf0e10cSrcweir maFieldDate = maLastDate; 1838cdf0e10cSrcweir maLastDate = GetDate(); 1839cdf0e10cSrcweir } 1840cdf0e10cSrcweir 1841cdf0e10cSrcweir // ----------------------------------------------------------------------- 1842cdf0e10cSrcweir 1843cdf0e10cSrcweir void DateFormatter::SetUserDate( const Date& rNewDate ) 1844cdf0e10cSrcweir { 1845cdf0e10cSrcweir ImplSetUserDate( rNewDate ); 1846cdf0e10cSrcweir } 1847cdf0e10cSrcweir 1848cdf0e10cSrcweir // ----------------------------------------------------------------------- 1849cdf0e10cSrcweir 1850cdf0e10cSrcweir void DateFormatter::ImplSetUserDate( const Date& rNewDate, Selection* pNewSelection ) 1851cdf0e10cSrcweir { 1852cdf0e10cSrcweir Date aNewDate = rNewDate; 1853cdf0e10cSrcweir if ( aNewDate > maMax ) 1854cdf0e10cSrcweir aNewDate = maMax; 1855cdf0e10cSrcweir else if ( aNewDate < maMin ) 1856cdf0e10cSrcweir aNewDate = maMin; 1857cdf0e10cSrcweir maLastDate = aNewDate; 1858cdf0e10cSrcweir 1859cdf0e10cSrcweir if ( GetField() ) 1860cdf0e10cSrcweir ImplSetText( ImplGetDateAsText( aNewDate, GetFieldSettings() ), pNewSelection ); 1861cdf0e10cSrcweir } 1862cdf0e10cSrcweir 1863cdf0e10cSrcweir // ----------------------------------------------------------------------- 1864cdf0e10cSrcweir 1865cdf0e10cSrcweir void DateFormatter::ImplNewFieldValue( const Date& rDate ) 1866cdf0e10cSrcweir { 1867cdf0e10cSrcweir if ( GetField() ) 1868cdf0e10cSrcweir { 1869cdf0e10cSrcweir Selection aSelection = GetField()->GetSelection(); 1870cdf0e10cSrcweir aSelection.Justify(); 1871cdf0e10cSrcweir XubString aText = GetField()->GetText(); 1872cdf0e10cSrcweir // Wenn bis ans Ende selektiert war, soll das auch so bleiben... 1873cdf0e10cSrcweir if ( (xub_StrLen)aSelection.Max() == aText.Len() ) 1874cdf0e10cSrcweir { 1875cdf0e10cSrcweir if ( !aSelection.Len() ) 1876cdf0e10cSrcweir aSelection.Min() = SELECTION_MAX; 1877cdf0e10cSrcweir aSelection.Max() = SELECTION_MAX; 1878cdf0e10cSrcweir } 1879cdf0e10cSrcweir 1880cdf0e10cSrcweir Date aOldLastDate = maLastDate; 1881cdf0e10cSrcweir ImplSetUserDate( rDate, &aSelection ); 1882cdf0e10cSrcweir maLastDate = aOldLastDate; 1883cdf0e10cSrcweir 1884cdf0e10cSrcweir // Modify am Edit wird nur bei KeyInput gesetzt... 1885cdf0e10cSrcweir if ( GetField()->GetText() != aText ) 1886cdf0e10cSrcweir { 1887cdf0e10cSrcweir GetField()->SetModifyFlag(); 1888cdf0e10cSrcweir GetField()->Modify(); 1889cdf0e10cSrcweir } 1890cdf0e10cSrcweir } 1891cdf0e10cSrcweir } 1892cdf0e10cSrcweir 1893cdf0e10cSrcweir // ----------------------------------------------------------------------- 1894cdf0e10cSrcweir 1895cdf0e10cSrcweir Date DateFormatter::GetDate() const 1896cdf0e10cSrcweir { 1897cdf0e10cSrcweir Date aDate( 0, 0, 0 ); 1898cdf0e10cSrcweir 1899cdf0e10cSrcweir if ( GetField() ) 1900cdf0e10cSrcweir { 1901cdf0e10cSrcweir if ( ImplDateGetValue( GetField()->GetText(), aDate, GetExtDateFormat(sal_True), ImplGetLocaleDataWrapper(), GetCalendarWrapper(), GetFieldSettings() ) ) 1902cdf0e10cSrcweir { 1903cdf0e10cSrcweir if ( aDate > maMax ) 1904cdf0e10cSrcweir aDate = maMax; 1905cdf0e10cSrcweir else if ( aDate < maMin ) 1906cdf0e10cSrcweir aDate = maMin; 1907cdf0e10cSrcweir } 1908cdf0e10cSrcweir else 1909cdf0e10cSrcweir { 1910cdf0e10cSrcweir // !!! TH-18.2.99: Wenn wir Zeit haben sollte einmal 1911cdf0e10cSrcweir // !!! geklaert werden, warum dieses beim Datum gegenueber 1912cdf0e10cSrcweir // !!! allen anderen Feldern anders behandelt wird. 1913cdf0e10cSrcweir // !!! Siehe dazu Bug: 52304 1914cdf0e10cSrcweir 1915cdf0e10cSrcweir if ( !ImplAllowMalformedInput() ) 1916cdf0e10cSrcweir { 1917cdf0e10cSrcweir if ( maLastDate.GetDate() ) 1918cdf0e10cSrcweir aDate = maLastDate; 1919cdf0e10cSrcweir else if ( !IsEmptyFieldValueEnabled() ) 1920cdf0e10cSrcweir aDate = Date(); 1921cdf0e10cSrcweir } 1922cdf0e10cSrcweir else 1923cdf0e10cSrcweir aDate = GetInvalidDate(); 1924cdf0e10cSrcweir } 1925cdf0e10cSrcweir } 1926cdf0e10cSrcweir 1927cdf0e10cSrcweir return aDate; 1928cdf0e10cSrcweir } 1929cdf0e10cSrcweir 1930cdf0e10cSrcweir // ----------------------------------------------------------------------- 1931cdf0e10cSrcweir 1932cdf0e10cSrcweir Date DateFormatter::GetRealDate() const 1933cdf0e10cSrcweir { 1934cdf0e10cSrcweir // !!! TH-18.2.99: Wenn wir Zeit haben sollte dieses auch einmal 1935cdf0e10cSrcweir // !!! fuer die Numeric-Klassen eingebaut werden. 1936cdf0e10cSrcweir 1937cdf0e10cSrcweir Date aDate( 0, 0, 0 ); 1938cdf0e10cSrcweir 1939cdf0e10cSrcweir if ( GetField() ) 1940cdf0e10cSrcweir { 1941cdf0e10cSrcweir if ( !ImplDateGetValue( GetField()->GetText(), aDate, GetExtDateFormat(sal_True), ImplGetLocaleDataWrapper(), GetCalendarWrapper(), GetFieldSettings() ) ) 1942cdf0e10cSrcweir if ( ImplAllowMalformedInput() ) 1943cdf0e10cSrcweir aDate = GetInvalidDate(); 1944cdf0e10cSrcweir } 1945cdf0e10cSrcweir 1946cdf0e10cSrcweir return aDate; 1947cdf0e10cSrcweir } 1948cdf0e10cSrcweir 1949cdf0e10cSrcweir // ----------------------------------------------------------------------- 1950cdf0e10cSrcweir 1951cdf0e10cSrcweir void DateFormatter::SetEmptyDate() 1952cdf0e10cSrcweir { 1953cdf0e10cSrcweir FormatterBase::SetEmptyFieldValue(); 1954cdf0e10cSrcweir } 1955cdf0e10cSrcweir 1956cdf0e10cSrcweir // ----------------------------------------------------------------------- 1957cdf0e10cSrcweir 1958cdf0e10cSrcweir sal_Bool DateFormatter::IsEmptyDate() const 1959cdf0e10cSrcweir { 1960cdf0e10cSrcweir sal_Bool bEmpty = FormatterBase::IsEmptyFieldValue(); 1961cdf0e10cSrcweir 1962cdf0e10cSrcweir if ( GetField() && MustBeReformatted() && IsEmptyFieldValueEnabled() ) 1963cdf0e10cSrcweir { 1964cdf0e10cSrcweir if ( !GetField()->GetText().Len() ) 1965cdf0e10cSrcweir { 1966cdf0e10cSrcweir bEmpty = sal_True; 1967cdf0e10cSrcweir } 1968cdf0e10cSrcweir else if ( !maLastDate.GetDate() ) 1969cdf0e10cSrcweir { 1970cdf0e10cSrcweir Date aDate; 1971cdf0e10cSrcweir bEmpty = !ImplDateGetValue( GetField()->GetText(), aDate, GetExtDateFormat(sal_True), ImplGetLocaleDataWrapper(), GetCalendarWrapper(), GetFieldSettings() ); 1972cdf0e10cSrcweir } 1973cdf0e10cSrcweir } 1974cdf0e10cSrcweir return bEmpty; 1975cdf0e10cSrcweir } 1976cdf0e10cSrcweir 1977cdf0e10cSrcweir // ----------------------------------------------------------------------- 1978cdf0e10cSrcweir 1979cdf0e10cSrcweir sal_Bool DateFormatter::IsDateModified() const 1980cdf0e10cSrcweir { 1981cdf0e10cSrcweir if ( ImplGetEmptyFieldValue() ) 1982cdf0e10cSrcweir return !IsEmptyDate(); 1983cdf0e10cSrcweir else if ( GetDate() != maFieldDate ) 1984cdf0e10cSrcweir return sal_True; 1985cdf0e10cSrcweir else 1986cdf0e10cSrcweir return sal_False; 1987cdf0e10cSrcweir } 1988cdf0e10cSrcweir 1989cdf0e10cSrcweir // ----------------------------------------------------------------------- 1990cdf0e10cSrcweir 1991cdf0e10cSrcweir void DateFormatter::Reformat() 1992cdf0e10cSrcweir { 1993cdf0e10cSrcweir if ( !GetField() ) 1994cdf0e10cSrcweir return; 1995cdf0e10cSrcweir 1996cdf0e10cSrcweir if ( !GetField()->GetText().Len() && ImplGetEmptyFieldValue() ) 1997cdf0e10cSrcweir return; 1998cdf0e10cSrcweir 1999cdf0e10cSrcweir XubString aStr; 2000cdf0e10cSrcweir sal_Bool bOK = ImplDateReformat( GetField()->GetText(), aStr, GetFieldSettings() ); 2001cdf0e10cSrcweir if( !bOK ) 2002cdf0e10cSrcweir return; 2003cdf0e10cSrcweir 2004cdf0e10cSrcweir if ( aStr.Len() ) 2005cdf0e10cSrcweir { 2006cdf0e10cSrcweir ImplSetText( aStr ); 2007cdf0e10cSrcweir ImplDateGetValue( aStr, maLastDate, GetExtDateFormat(sal_True), ImplGetLocaleDataWrapper(), GetCalendarWrapper(), GetFieldSettings() ); 2008cdf0e10cSrcweir } 2009cdf0e10cSrcweir else 2010cdf0e10cSrcweir { 2011cdf0e10cSrcweir if ( maLastDate.GetDate() ) 2012cdf0e10cSrcweir SetDate( maLastDate ); 2013cdf0e10cSrcweir else if ( !IsEmptyFieldValueEnabled() ) 2014cdf0e10cSrcweir SetDate( Date() ); 2015cdf0e10cSrcweir else 2016cdf0e10cSrcweir { 2017cdf0e10cSrcweir ImplSetText( ImplGetSVEmptyStr() ); 2018cdf0e10cSrcweir SetEmptyFieldValueData( sal_True ); 2019cdf0e10cSrcweir } 2020cdf0e10cSrcweir } 2021cdf0e10cSrcweir } 2022cdf0e10cSrcweir 2023cdf0e10cSrcweir // ----------------------------------------------------------------------- 2024cdf0e10cSrcweir 2025cdf0e10cSrcweir void DateFormatter::ExpandCentury( Date& rDate ) 2026cdf0e10cSrcweir { 2027cdf0e10cSrcweir ExpandCentury( rDate, utl::MiscCfg().GetYear2000() ); 2028cdf0e10cSrcweir } 2029cdf0e10cSrcweir 2030cdf0e10cSrcweir // ----------------------------------------------------------------------- 2031cdf0e10cSrcweir 2032cdf0e10cSrcweir void DateFormatter::ExpandCentury( Date& rDate, sal_uInt16 nTwoDigitYearStart ) 2033cdf0e10cSrcweir { 2034cdf0e10cSrcweir sal_uInt16 nDateYear = rDate.GetYear(); 2035cdf0e10cSrcweir if ( nDateYear < 100 ) 2036cdf0e10cSrcweir { 2037cdf0e10cSrcweir sal_uInt16 nCentury = nTwoDigitYearStart / 100; 2038cdf0e10cSrcweir if ( nDateYear < (nTwoDigitYearStart % 100) ) 2039cdf0e10cSrcweir nCentury++; 2040cdf0e10cSrcweir rDate.SetYear( nDateYear + (nCentury*100) ); 2041cdf0e10cSrcweir } 2042cdf0e10cSrcweir } 2043cdf0e10cSrcweir 2044cdf0e10cSrcweir // ----------------------------------------------------------------------- 2045cdf0e10cSrcweir 2046cdf0e10cSrcweir DateField::DateField( Window* pParent, WinBits nWinStyle ) : 2047cdf0e10cSrcweir SpinField( pParent, nWinStyle ), 2048cdf0e10cSrcweir maFirst( GetMin() ), 2049cdf0e10cSrcweir maLast( GetMax() ) 2050cdf0e10cSrcweir { 2051cdf0e10cSrcweir SetField( this ); 2052cdf0e10cSrcweir SetText( ImplGetLocaleDataWrapper().getDate( ImplGetFieldDate() ) ); 2053cdf0e10cSrcweir Reformat(); 2054cdf0e10cSrcweir ResetLastDate(); 2055cdf0e10cSrcweir } 2056cdf0e10cSrcweir 2057cdf0e10cSrcweir // ----------------------------------------------------------------------- 2058cdf0e10cSrcweir 2059cdf0e10cSrcweir DateField::DateField( Window* pParent, const ResId& rResId ) : 2060cdf0e10cSrcweir SpinField( WINDOW_DATEFIELD ), 2061cdf0e10cSrcweir maFirst( GetMin() ), 2062cdf0e10cSrcweir maLast( GetMax() ) 2063cdf0e10cSrcweir { 2064cdf0e10cSrcweir rResId.SetRT( RSC_DATEFIELD ); 2065cdf0e10cSrcweir WinBits nStyle = ImplInitRes( rResId ); 2066cdf0e10cSrcweir SpinField::ImplInit( pParent, nStyle ); 2067cdf0e10cSrcweir SetField( this ); 2068cdf0e10cSrcweir SetText( ImplGetLocaleDataWrapper().getDate( ImplGetFieldDate() ) ); 2069cdf0e10cSrcweir ImplLoadRes( rResId ); 2070cdf0e10cSrcweir 2071cdf0e10cSrcweir if ( !(nStyle & WB_HIDE ) ) 2072cdf0e10cSrcweir Show(); 2073cdf0e10cSrcweir 2074cdf0e10cSrcweir ResetLastDate(); 2075cdf0e10cSrcweir } 2076cdf0e10cSrcweir 2077cdf0e10cSrcweir // ----------------------------------------------------------------------- 2078cdf0e10cSrcweir 2079cdf0e10cSrcweir void DateField::ImplLoadRes( const ResId& rResId ) 2080cdf0e10cSrcweir { 2081cdf0e10cSrcweir SpinField::ImplLoadRes( rResId ); 2082cdf0e10cSrcweir 2083cdf0e10cSrcweir ResMgr* pMgr = rResId.GetResMgr(); 2084cdf0e10cSrcweir if( pMgr ) 2085cdf0e10cSrcweir { 2086cdf0e10cSrcweir DateFormatter::ImplLoadRes( ResId( (RSHEADER_TYPE *)GetClassRes(), *pMgr ) ); 2087cdf0e10cSrcweir 2088cdf0e10cSrcweir sal_uLong nMask = ReadLongRes(); 2089cdf0e10cSrcweir if ( DATEFIELD_FIRST & nMask ) 2090cdf0e10cSrcweir { 2091cdf0e10cSrcweir maFirst = Date( ResId( (RSHEADER_TYPE *)GetClassRes(), *pMgr ) ); 2092cdf0e10cSrcweir IncrementRes( GetObjSizeRes( (RSHEADER_TYPE *)GetClassRes() ) ); 2093cdf0e10cSrcweir } 2094cdf0e10cSrcweir if ( DATEFIELD_LAST & nMask ) 2095cdf0e10cSrcweir { 2096cdf0e10cSrcweir maLast = Date( ResId( (RSHEADER_TYPE *)GetClassRes(), *pMgr ) ); 2097cdf0e10cSrcweir IncrementRes( GetObjSizeRes( (RSHEADER_TYPE *)GetClassRes() ) ); 2098cdf0e10cSrcweir } 2099cdf0e10cSrcweir } 2100cdf0e10cSrcweir 2101cdf0e10cSrcweir Reformat(); 2102cdf0e10cSrcweir } 2103cdf0e10cSrcweir 2104cdf0e10cSrcweir // ----------------------------------------------------------------------- 2105cdf0e10cSrcweir 2106cdf0e10cSrcweir DateField::~DateField() 2107cdf0e10cSrcweir { 2108cdf0e10cSrcweir } 2109cdf0e10cSrcweir 2110cdf0e10cSrcweir // ----------------------------------------------------------------------- 2111cdf0e10cSrcweir 2112cdf0e10cSrcweir long DateField::PreNotify( NotifyEvent& rNEvt ) 2113cdf0e10cSrcweir { 2114cdf0e10cSrcweir if ( (rNEvt.GetType() == EVENT_KEYINPUT) && IsStrictFormat() && 2115cdf0e10cSrcweir ( GetExtDateFormat() != XTDATEF_SYSTEM_LONG ) && 2116cdf0e10cSrcweir !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() ) 2117cdf0e10cSrcweir { 2118cdf0e10cSrcweir if ( ImplDateProcessKeyInput( GetField(), *rNEvt.GetKeyEvent(), GetExtDateFormat( sal_True ), ImplGetLocaleDataWrapper() ) ) 2119cdf0e10cSrcweir return 1; 2120cdf0e10cSrcweir } 2121cdf0e10cSrcweir 2122cdf0e10cSrcweir return SpinField::PreNotify( rNEvt ); 2123cdf0e10cSrcweir } 2124cdf0e10cSrcweir 2125cdf0e10cSrcweir // ----------------------------------------------------------------------- 2126cdf0e10cSrcweir 2127cdf0e10cSrcweir long DateField::Notify( NotifyEvent& rNEvt ) 2128cdf0e10cSrcweir { 2129cdf0e10cSrcweir if ( rNEvt.GetType() == EVENT_GETFOCUS ) 2130cdf0e10cSrcweir MarkToBeReformatted( sal_False ); 2131cdf0e10cSrcweir else if ( rNEvt.GetType() == EVENT_LOSEFOCUS ) 2132cdf0e10cSrcweir { 2133cdf0e10cSrcweir if ( MustBeReformatted() ) 2134cdf0e10cSrcweir { 2135cdf0e10cSrcweir // !!! TH-18.2.99: Wenn wir Zeit haben sollte einmal 2136cdf0e10cSrcweir // !!! geklaert werden, warum dieses beim Datum gegenueber 2137cdf0e10cSrcweir // !!! allen anderen Feldern anders behandelt wird. 2138cdf0e10cSrcweir // !!! Siehe dazu Bug: 52304 2139cdf0e10cSrcweir 2140cdf0e10cSrcweir sal_Bool bTextLen = GetText().Len() != 0; 2141cdf0e10cSrcweir if ( bTextLen || !IsEmptyFieldValueEnabled() ) 2142cdf0e10cSrcweir { 2143cdf0e10cSrcweir if ( !ImplAllowMalformedInput() ) 2144cdf0e10cSrcweir Reformat(); 2145cdf0e10cSrcweir else 2146cdf0e10cSrcweir { 2147cdf0e10cSrcweir Date aDate( 0, 0, 0 ); 2148cdf0e10cSrcweir if ( ImplDateGetValue( GetText(), aDate, GetExtDateFormat(sal_True), ImplGetLocaleDataWrapper(), GetCalendarWrapper(), GetFieldSettings() ) ) 2149cdf0e10cSrcweir // even with strict text analysis, our text is a valid date -> do a complete 2150cdf0e10cSrcweir // reformat 2151cdf0e10cSrcweir Reformat(); 2152cdf0e10cSrcweir } 2153cdf0e10cSrcweir } 2154cdf0e10cSrcweir else if ( !bTextLen && IsEmptyFieldValueEnabled() ) 2155cdf0e10cSrcweir { 2156cdf0e10cSrcweir ResetLastDate(); 2157cdf0e10cSrcweir SetEmptyFieldValueData( sal_True ); 2158cdf0e10cSrcweir } 2159cdf0e10cSrcweir } 2160cdf0e10cSrcweir } 2161cdf0e10cSrcweir 2162cdf0e10cSrcweir return SpinField::Notify( rNEvt ); 2163cdf0e10cSrcweir } 2164cdf0e10cSrcweir 2165cdf0e10cSrcweir // ----------------------------------------------------------------------- 2166cdf0e10cSrcweir 2167cdf0e10cSrcweir void DateField::DataChanged( const DataChangedEvent& rDCEvt ) 2168cdf0e10cSrcweir { 2169cdf0e10cSrcweir SpinField::DataChanged( rDCEvt ); 2170cdf0e10cSrcweir 2171cdf0e10cSrcweir if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & (SETTINGS_LOCALE|SETTINGS_MISC)) ) 2172cdf0e10cSrcweir { 2173cdf0e10cSrcweir if ( IsDefaultLocale() && ( rDCEvt.GetFlags() & SETTINGS_LOCALE ) ) 2174cdf0e10cSrcweir ImplGetLocaleDataWrapper().setLocale( GetSettings().GetLocale() ); 2175cdf0e10cSrcweir ReformatAll(); 2176cdf0e10cSrcweir } 2177cdf0e10cSrcweir } 2178cdf0e10cSrcweir 2179cdf0e10cSrcweir // ----------------------------------------------------------------------- 2180cdf0e10cSrcweir 2181cdf0e10cSrcweir void DateField::Modify() 2182cdf0e10cSrcweir { 2183cdf0e10cSrcweir MarkToBeReformatted( sal_True ); 2184cdf0e10cSrcweir SpinField::Modify(); 2185cdf0e10cSrcweir } 2186cdf0e10cSrcweir 2187cdf0e10cSrcweir // ----------------------------------------------------------------------- 2188cdf0e10cSrcweir 2189cdf0e10cSrcweir void DateField::Up() 2190cdf0e10cSrcweir { 2191cdf0e10cSrcweir ImplDateSpinArea( sal_True ); 2192cdf0e10cSrcweir SpinField::Up(); 2193cdf0e10cSrcweir } 2194cdf0e10cSrcweir 2195cdf0e10cSrcweir // ----------------------------------------------------------------------- 2196cdf0e10cSrcweir 2197cdf0e10cSrcweir void DateField::Down() 2198cdf0e10cSrcweir { 2199cdf0e10cSrcweir ImplDateSpinArea( sal_False ); 2200cdf0e10cSrcweir SpinField::Down(); 2201cdf0e10cSrcweir } 2202cdf0e10cSrcweir 2203cdf0e10cSrcweir // ----------------------------------------------------------------------- 2204cdf0e10cSrcweir 2205cdf0e10cSrcweir void DateField::First() 2206cdf0e10cSrcweir { 2207cdf0e10cSrcweir ImplNewFieldValue( maFirst ); 2208cdf0e10cSrcweir SpinField::First(); 2209cdf0e10cSrcweir } 2210cdf0e10cSrcweir 2211cdf0e10cSrcweir // ----------------------------------------------------------------------- 2212cdf0e10cSrcweir 2213cdf0e10cSrcweir void DateField::Last() 2214cdf0e10cSrcweir { 2215cdf0e10cSrcweir ImplNewFieldValue( maLast ); 2216cdf0e10cSrcweir SpinField::Last(); 2217cdf0e10cSrcweir } 2218cdf0e10cSrcweir 2219cdf0e10cSrcweir // ----------------------------------------------------------------------- 2220cdf0e10cSrcweir 2221cdf0e10cSrcweir DateBox::DateBox( Window* pParent, WinBits nWinStyle ) : 2222cdf0e10cSrcweir ComboBox( pParent, nWinStyle ) 2223cdf0e10cSrcweir { 2224cdf0e10cSrcweir SetField( this ); 2225cdf0e10cSrcweir SetText( ImplGetLocaleDataWrapper().getDate( ImplGetFieldDate() ) ); 2226cdf0e10cSrcweir Reformat(); 2227cdf0e10cSrcweir } 2228cdf0e10cSrcweir 2229cdf0e10cSrcweir // ----------------------------------------------------------------------- 2230cdf0e10cSrcweir 2231cdf0e10cSrcweir DateBox::DateBox( Window* pParent, const ResId& rResId ) : 2232cdf0e10cSrcweir ComboBox( WINDOW_DATEBOX ) 2233cdf0e10cSrcweir { 2234cdf0e10cSrcweir rResId.SetRT( RSC_DATEBOX ); 2235cdf0e10cSrcweir WinBits nStyle = ImplInitRes( rResId ); 2236cdf0e10cSrcweir ComboBox::ImplInit( pParent, nStyle ); 2237cdf0e10cSrcweir SetField( this ); 2238cdf0e10cSrcweir SetText( ImplGetLocaleDataWrapper().getDate( ImplGetFieldDate() ) ); 2239cdf0e10cSrcweir ComboBox::ImplLoadRes( rResId ); 2240cdf0e10cSrcweir ResMgr* pMgr = rResId.GetResMgr(); 2241cdf0e10cSrcweir if( pMgr ) 2242cdf0e10cSrcweir DateFormatter::ImplLoadRes( ResId( (RSHEADER_TYPE *)GetClassRes(), *pMgr ) ); 2243cdf0e10cSrcweir Reformat(); 2244cdf0e10cSrcweir 2245cdf0e10cSrcweir if ( !( nStyle & WB_HIDE ) ) 2246cdf0e10cSrcweir Show(); 2247cdf0e10cSrcweir } 2248cdf0e10cSrcweir 2249cdf0e10cSrcweir // ----------------------------------------------------------------------- 2250cdf0e10cSrcweir 2251cdf0e10cSrcweir DateBox::~DateBox() 2252cdf0e10cSrcweir { 2253cdf0e10cSrcweir } 2254cdf0e10cSrcweir 2255cdf0e10cSrcweir // ----------------------------------------------------------------------- 2256cdf0e10cSrcweir 2257cdf0e10cSrcweir long DateBox::PreNotify( NotifyEvent& rNEvt ) 2258cdf0e10cSrcweir { 2259cdf0e10cSrcweir if ( (rNEvt.GetType() == EVENT_KEYINPUT) && IsStrictFormat() && 2260cdf0e10cSrcweir ( GetExtDateFormat() != XTDATEF_SYSTEM_LONG ) && 2261cdf0e10cSrcweir !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() ) 2262cdf0e10cSrcweir { 2263cdf0e10cSrcweir if ( ImplDateProcessKeyInput( GetField(), *rNEvt.GetKeyEvent(), GetExtDateFormat( sal_True ), ImplGetLocaleDataWrapper() ) ) 2264cdf0e10cSrcweir return 1; 2265cdf0e10cSrcweir } 2266cdf0e10cSrcweir 2267cdf0e10cSrcweir return ComboBox::PreNotify( rNEvt ); 2268cdf0e10cSrcweir } 2269cdf0e10cSrcweir 2270cdf0e10cSrcweir // ----------------------------------------------------------------------- 2271cdf0e10cSrcweir 2272cdf0e10cSrcweir void DateBox::DataChanged( const DataChangedEvent& rDCEvt ) 2273cdf0e10cSrcweir { 2274cdf0e10cSrcweir ComboBox::DataChanged( rDCEvt ); 2275cdf0e10cSrcweir 2276cdf0e10cSrcweir if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_LOCALE) ) 2277cdf0e10cSrcweir { 2278cdf0e10cSrcweir if ( IsDefaultLocale() ) 2279cdf0e10cSrcweir ImplGetLocaleDataWrapper().setLocale( GetSettings().GetLocale() ); 2280cdf0e10cSrcweir ReformatAll(); 2281cdf0e10cSrcweir } 2282cdf0e10cSrcweir } 2283cdf0e10cSrcweir 2284cdf0e10cSrcweir // ----------------------------------------------------------------------- 2285cdf0e10cSrcweir 2286cdf0e10cSrcweir long DateBox::Notify( NotifyEvent& rNEvt ) 2287cdf0e10cSrcweir { 2288cdf0e10cSrcweir if ( rNEvt.GetType() == EVENT_GETFOCUS ) 2289cdf0e10cSrcweir MarkToBeReformatted( sal_False ); 2290cdf0e10cSrcweir else if ( rNEvt.GetType() == EVENT_LOSEFOCUS ) 2291cdf0e10cSrcweir { 2292cdf0e10cSrcweir if ( MustBeReformatted() ) 2293cdf0e10cSrcweir { 2294cdf0e10cSrcweir sal_Bool bTextLen = GetText().Len() != 0; 2295cdf0e10cSrcweir if ( bTextLen || !IsEmptyFieldValueEnabled() ) 2296cdf0e10cSrcweir Reformat(); 2297cdf0e10cSrcweir else if ( !bTextLen && IsEmptyFieldValueEnabled() ) 2298cdf0e10cSrcweir { 2299cdf0e10cSrcweir ResetLastDate(); 2300cdf0e10cSrcweir SetEmptyFieldValueData( sal_True ); 2301cdf0e10cSrcweir } 2302cdf0e10cSrcweir } 2303cdf0e10cSrcweir } 2304cdf0e10cSrcweir 2305cdf0e10cSrcweir return ComboBox::Notify( rNEvt ); 2306cdf0e10cSrcweir } 2307cdf0e10cSrcweir 2308cdf0e10cSrcweir // ----------------------------------------------------------------------- 2309cdf0e10cSrcweir 2310cdf0e10cSrcweir void DateBox::Modify() 2311cdf0e10cSrcweir { 2312cdf0e10cSrcweir MarkToBeReformatted( sal_True ); 2313cdf0e10cSrcweir ComboBox::Modify(); 2314cdf0e10cSrcweir } 2315cdf0e10cSrcweir 2316cdf0e10cSrcweir // ----------------------------------------------------------------------- 2317cdf0e10cSrcweir 2318cdf0e10cSrcweir void DateBox::ReformatAll() 2319cdf0e10cSrcweir { 2320cdf0e10cSrcweir XubString aStr; 2321cdf0e10cSrcweir SetUpdateMode( sal_False ); 2322cdf0e10cSrcweir sal_uInt16 nEntryCount = GetEntryCount(); 2323cdf0e10cSrcweir for ( sal_uInt16 i=0; i < nEntryCount; i++ ) 2324cdf0e10cSrcweir { 2325cdf0e10cSrcweir ImplDateReformat( GetEntry( i ), aStr, GetFieldSettings() ); 2326cdf0e10cSrcweir RemoveEntry( i ); 2327cdf0e10cSrcweir InsertEntry( aStr, i ); 2328cdf0e10cSrcweir } 2329cdf0e10cSrcweir DateFormatter::Reformat(); 2330cdf0e10cSrcweir SetUpdateMode( sal_True ); 2331cdf0e10cSrcweir } 2332cdf0e10cSrcweir 2333cdf0e10cSrcweir // ----------------------------------------------------------------------- 2334cdf0e10cSrcweir 2335cdf0e10cSrcweir void DateBox::InsertDate( const Date& rDate, sal_uInt16 nPos ) 2336cdf0e10cSrcweir { 2337cdf0e10cSrcweir Date aDate = rDate; 2338cdf0e10cSrcweir if ( aDate > GetMax() ) 2339cdf0e10cSrcweir aDate = GetMax(); 2340cdf0e10cSrcweir else if ( aDate < GetMin() ) 2341cdf0e10cSrcweir aDate = GetMin(); 2342cdf0e10cSrcweir 2343cdf0e10cSrcweir ComboBox::InsertEntry( ImplGetDateAsText( aDate, GetFieldSettings() ), nPos ); 2344cdf0e10cSrcweir } 2345cdf0e10cSrcweir 2346cdf0e10cSrcweir // ----------------------------------------------------------------------- 2347cdf0e10cSrcweir 2348cdf0e10cSrcweir void DateBox::RemoveDate( const Date& rDate ) 2349cdf0e10cSrcweir { 2350cdf0e10cSrcweir ComboBox::RemoveEntry( ImplGetDateAsText( rDate, GetFieldSettings() ) ); 2351cdf0e10cSrcweir } 2352cdf0e10cSrcweir 2353cdf0e10cSrcweir // ----------------------------------------------------------------------- 2354cdf0e10cSrcweir 2355cdf0e10cSrcweir Date DateBox::GetDate( sal_uInt16 nPos ) const 2356cdf0e10cSrcweir { 2357cdf0e10cSrcweir Date aDate( 0, 0, 0 ); 2358cdf0e10cSrcweir ImplDateGetValue( ComboBox::GetEntry( nPos ), aDate, GetExtDateFormat(sal_True), ImplGetLocaleDataWrapper(), GetCalendarWrapper(), GetSettings() ); 2359cdf0e10cSrcweir return aDate; 2360cdf0e10cSrcweir } 2361cdf0e10cSrcweir 2362cdf0e10cSrcweir // ----------------------------------------------------------------------- 2363cdf0e10cSrcweir 2364cdf0e10cSrcweir sal_uInt16 DateBox::GetDatePos( const Date& rDate ) const 2365cdf0e10cSrcweir { 2366cdf0e10cSrcweir XubString aStr; 2367cdf0e10cSrcweir if ( IsLongFormat() ) 2368cdf0e10cSrcweir aStr = ImplGetLocaleDataWrapper().getLongDate( rDate, GetCalendarWrapper(), 1, sal_False, 1, !IsShowDateCentury() ); 2369cdf0e10cSrcweir else 2370cdf0e10cSrcweir aStr = ImplGetLocaleDataWrapper().getDate( rDate ); 2371cdf0e10cSrcweir return ComboBox::GetEntryPos( aStr ); 2372cdf0e10cSrcweir } 2373cdf0e10cSrcweir 2374cdf0e10cSrcweir // ----------------------------------------------------------------------- 2375cdf0e10cSrcweir 2376cdf0e10cSrcweir static sal_Bool ImplTimeProcessKeyInput( Edit*, const KeyEvent& rKEvt, 2377cdf0e10cSrcweir sal_Bool bStrictFormat, sal_Bool bDuration, 2378cdf0e10cSrcweir TimeFieldFormat eFormat, 2379cdf0e10cSrcweir const LocaleDataWrapper& rLocaleDataWrapper ) 2380cdf0e10cSrcweir { 2381cdf0e10cSrcweir xub_Unicode cChar = rKEvt.GetCharCode(); 2382cdf0e10cSrcweir 2383cdf0e10cSrcweir if ( !bStrictFormat ) 2384cdf0e10cSrcweir return sal_False; 2385cdf0e10cSrcweir else 2386cdf0e10cSrcweir { 2387cdf0e10cSrcweir sal_uInt16 nGroup = rKEvt.GetKeyCode().GetGroup(); 2388cdf0e10cSrcweir if ( (nGroup == KEYGROUP_FKEYS) || (nGroup == KEYGROUP_CURSOR) || 2389cdf0e10cSrcweir (nGroup == KEYGROUP_MISC) || 2390cdf0e10cSrcweir ((cChar >= '0') && (cChar <= '9')) || 2391cdf0e10cSrcweir (cChar == rLocaleDataWrapper.getTimeSep()) || 2392cdf0e10cSrcweir ( ( rLocaleDataWrapper.getTimeAM().Search( cChar ) != STRING_NOTFOUND ) ) || 2393cdf0e10cSrcweir ( ( rLocaleDataWrapper.getTimePM().Search( cChar ) != STRING_NOTFOUND ) ) || 2394cdf0e10cSrcweir // Accept AM/PM: 2395cdf0e10cSrcweir (cChar == 'a') || (cChar == 'A') || (cChar == 'm') || (cChar == 'M') || (cChar == 'p') || (cChar == 'P') || 2396cdf0e10cSrcweir ((eFormat == TIMEF_100TH_SEC) && (cChar == rLocaleDataWrapper.getTime100SecSep())) || 2397cdf0e10cSrcweir ((eFormat == TIMEF_SEC_CS) && (cChar == rLocaleDataWrapper.getTime100SecSep())) || 2398cdf0e10cSrcweir (bDuration && (cChar == '-')) ) 2399cdf0e10cSrcweir return sal_False; 2400cdf0e10cSrcweir else 2401cdf0e10cSrcweir return sal_True; 2402cdf0e10cSrcweir } 2403cdf0e10cSrcweir } 2404cdf0e10cSrcweir 2405cdf0e10cSrcweir // ----------------------------------------------------------------------- 2406cdf0e10cSrcweir 2407cdf0e10cSrcweir static sal_Bool ImplIsOnlyDigits( const String& _rStr ) 2408cdf0e10cSrcweir { 2409cdf0e10cSrcweir const sal_Unicode* _pChr = _rStr.GetBuffer(); 2410cdf0e10cSrcweir for ( xub_StrLen i = 0; i < _rStr.Len(); ++i, ++_pChr ) 2411cdf0e10cSrcweir { 2412cdf0e10cSrcweir if ( *_pChr < '0' || *_pChr > '9' ) 2413cdf0e10cSrcweir return sal_False; 2414cdf0e10cSrcweir } 2415cdf0e10cSrcweir return sal_True; 2416cdf0e10cSrcweir } 2417cdf0e10cSrcweir 2418cdf0e10cSrcweir // ----------------------------------------------------------------------- 2419cdf0e10cSrcweir 2420cdf0e10cSrcweir static sal_Bool ImplIsValidTimePortion( sal_Bool _bSkipInvalidCharacters, const String& _rStr ) 2421cdf0e10cSrcweir { 2422cdf0e10cSrcweir if ( !_bSkipInvalidCharacters ) 2423cdf0e10cSrcweir { 2424cdf0e10cSrcweir if ( ( _rStr.Len() > 2 ) || ( _rStr.Len() < 1 ) || !ImplIsOnlyDigits( _rStr ) ) 2425cdf0e10cSrcweir return sal_False; 2426cdf0e10cSrcweir } 2427cdf0e10cSrcweir return sal_True; 2428cdf0e10cSrcweir } 2429cdf0e10cSrcweir 2430cdf0e10cSrcweir // ----------------------------------------------------------------------- 2431cdf0e10cSrcweir 2432cdf0e10cSrcweir static sal_Bool ImplCutTimePortion( String& _rStr, xub_StrLen _nSepPos, sal_Bool _bSkipInvalidCharacters, short* _pPortion ) 2433cdf0e10cSrcweir { 2434cdf0e10cSrcweir String sPortion = _rStr.Copy( 0, _nSepPos ); 2435cdf0e10cSrcweir _rStr.Erase( 0, _nSepPos + 1 ); 2436cdf0e10cSrcweir 2437cdf0e10cSrcweir if ( !ImplIsValidTimePortion( _bSkipInvalidCharacters, sPortion ) ) 2438cdf0e10cSrcweir return sal_False; 2439cdf0e10cSrcweir *_pPortion = (short)sPortion.ToInt32(); 2440cdf0e10cSrcweir return sal_True; 2441cdf0e10cSrcweir } 2442cdf0e10cSrcweir 2443cdf0e10cSrcweir // ----------------------------------------------------------------------- 2444cdf0e10cSrcweir 2445cdf0e10cSrcweir static sal_Bool ImplTimeGetValue( const XubString& rStr, Time& rTime, 2446cdf0e10cSrcweir TimeFieldFormat eFormat, sal_Bool bDuration, 2447cdf0e10cSrcweir const LocaleDataWrapper& rLocaleDataWrapper, sal_Bool _bSkipInvalidCharacters = sal_True ) 2448cdf0e10cSrcweir { 2449cdf0e10cSrcweir XubString aStr = rStr; 2450cdf0e10cSrcweir short nHour = 0; 2451cdf0e10cSrcweir short nMinute = 0; 2452cdf0e10cSrcweir short nSecond = 0; 2453cdf0e10cSrcweir short n100Sec = 0; 2454cdf0e10cSrcweir Time aTime( 0, 0, 0 ); 2455cdf0e10cSrcweir 2456cdf0e10cSrcweir if ( !rStr.Len() ) 2457cdf0e10cSrcweir return sal_False; 2458cdf0e10cSrcweir 2459cdf0e10cSrcweir // Nach Separatoren suchen 2460cdf0e10cSrcweir if ( rLocaleDataWrapper.getTimeSep().Len() ) 2461cdf0e10cSrcweir { 2462cdf0e10cSrcweir XubString aSepStr( RTL_CONSTASCII_USTRINGPARAM( ",.;:/" ) ); 2463cdf0e10cSrcweir if ( !bDuration ) 2464cdf0e10cSrcweir aSepStr.Append( '-' ); 2465cdf0e10cSrcweir 2466cdf0e10cSrcweir // Die obigen Zeichen durch das Separatorzeichen ersetzen 2467cdf0e10cSrcweir for ( xub_StrLen i = 0; i < aSepStr.Len(); i++ ) 2468cdf0e10cSrcweir { 2469cdf0e10cSrcweir if ( aSepStr.GetChar( i ) == rLocaleDataWrapper.getTimeSep() ) 2470cdf0e10cSrcweir continue; 2471cdf0e10cSrcweir for ( xub_StrLen j = 0; j < aStr.Len(); j++ ) 2472cdf0e10cSrcweir { 2473cdf0e10cSrcweir if ( aStr.GetChar( j ) == aSepStr.GetChar( i ) ) 2474cdf0e10cSrcweir aStr.SetChar( j, rLocaleDataWrapper.getTimeSep().GetChar(0) ); 2475cdf0e10cSrcweir } 2476cdf0e10cSrcweir } 2477cdf0e10cSrcweir } 2478cdf0e10cSrcweir 2479cdf0e10cSrcweir sal_Bool bNegative = sal_False; 2480cdf0e10cSrcweir xub_StrLen nSepPos = aStr.Search( rLocaleDataWrapper.getTimeSep() ); 2481cdf0e10cSrcweir if ( aStr.GetChar( 0 ) == '-' ) 2482cdf0e10cSrcweir bNegative = sal_True; 2483cdf0e10cSrcweir if ( eFormat != TIMEF_SEC_CS ) 2484cdf0e10cSrcweir { 2485cdf0e10cSrcweir if ( nSepPos == STRING_NOTFOUND ) 2486cdf0e10cSrcweir nSepPos = aStr.Len(); 2487cdf0e10cSrcweir if ( !ImplCutTimePortion( aStr, nSepPos, _bSkipInvalidCharacters, &nHour ) ) 2488cdf0e10cSrcweir return sal_False; 2489cdf0e10cSrcweir 2490cdf0e10cSrcweir nSepPos = aStr.Search( rLocaleDataWrapper.getTimeSep() ); 2491cdf0e10cSrcweir if ( aStr.GetChar( 0 ) == '-' ) 2492cdf0e10cSrcweir bNegative = sal_True; 2493cdf0e10cSrcweir if ( nSepPos != STRING_NOTFOUND ) 2494cdf0e10cSrcweir { 2495cdf0e10cSrcweir if ( !ImplCutTimePortion( aStr, nSepPos, _bSkipInvalidCharacters, &nMinute ) ) 2496cdf0e10cSrcweir return sal_False; 2497cdf0e10cSrcweir 2498cdf0e10cSrcweir nSepPos = aStr.Search( rLocaleDataWrapper.getTimeSep() ); 2499cdf0e10cSrcweir if ( aStr.GetChar( 0 ) == '-' ) 2500cdf0e10cSrcweir bNegative = sal_True; 2501cdf0e10cSrcweir if ( nSepPos != STRING_NOTFOUND ) 2502cdf0e10cSrcweir { 2503cdf0e10cSrcweir if ( !ImplCutTimePortion( aStr, nSepPos, _bSkipInvalidCharacters, &nSecond ) ) 2504cdf0e10cSrcweir return sal_False; 2505cdf0e10cSrcweir if ( aStr.GetChar( 0 ) == '-' ) 2506cdf0e10cSrcweir bNegative = sal_True; 2507cdf0e10cSrcweir n100Sec = (short)aStr.ToInt32(); 2508cdf0e10cSrcweir } 2509cdf0e10cSrcweir else 2510cdf0e10cSrcweir nSecond = (short)aStr.ToInt32(); 2511cdf0e10cSrcweir } 2512cdf0e10cSrcweir else 2513cdf0e10cSrcweir nMinute = (short)aStr.ToInt32(); 2514cdf0e10cSrcweir } 2515cdf0e10cSrcweir else if ( nSepPos == STRING_NOTFOUND ) 2516cdf0e10cSrcweir { 2517cdf0e10cSrcweir nSecond = (short)aStr.ToInt32(); 2518cdf0e10cSrcweir nMinute += nSecond / 60; 2519cdf0e10cSrcweir nSecond %= 60; 2520cdf0e10cSrcweir nHour += nMinute / 60; 2521cdf0e10cSrcweir nMinute %= 60; 2522cdf0e10cSrcweir } 2523cdf0e10cSrcweir else 2524cdf0e10cSrcweir { 2525cdf0e10cSrcweir nSecond = (short)aStr.Copy( 0, nSepPos ).ToInt32(); 2526cdf0e10cSrcweir aStr.Erase( 0, nSepPos+1 ); 2527cdf0e10cSrcweir 2528cdf0e10cSrcweir nSepPos = aStr.Search( rLocaleDataWrapper.getTimeSep() ); 2529cdf0e10cSrcweir if ( aStr.GetChar( 0 ) == '-' ) 2530cdf0e10cSrcweir bNegative = sal_True; 2531cdf0e10cSrcweir if ( nSepPos != STRING_NOTFOUND ) 2532cdf0e10cSrcweir { 2533cdf0e10cSrcweir nMinute = nSecond; 2534cdf0e10cSrcweir nSecond = (short)aStr.Copy( 0, nSepPos ).ToInt32(); 2535cdf0e10cSrcweir aStr.Erase( 0, nSepPos+1 ); 2536cdf0e10cSrcweir 2537cdf0e10cSrcweir nSepPos = aStr.Search( rLocaleDataWrapper.getTimeSep() ); 2538cdf0e10cSrcweir if ( aStr.GetChar( 0 ) == '-' ) 2539cdf0e10cSrcweir bNegative = sal_True; 2540cdf0e10cSrcweir if ( nSepPos != STRING_NOTFOUND ) 2541cdf0e10cSrcweir { 2542cdf0e10cSrcweir nHour = nMinute; 2543cdf0e10cSrcweir nMinute = nSecond; 2544cdf0e10cSrcweir nSecond = (short)aStr.Copy( 0, nSepPos ).ToInt32(); 2545cdf0e10cSrcweir aStr.Erase( 0, nSepPos+1 ); 2546cdf0e10cSrcweir } 2547cdf0e10cSrcweir else 2548cdf0e10cSrcweir { 2549cdf0e10cSrcweir nHour += nMinute / 60; 2550cdf0e10cSrcweir nMinute %= 60; 2551cdf0e10cSrcweir } 2552cdf0e10cSrcweir } 2553cdf0e10cSrcweir else 2554cdf0e10cSrcweir { 2555cdf0e10cSrcweir nMinute += nSecond / 60; 2556cdf0e10cSrcweir nSecond %= 60; 2557cdf0e10cSrcweir nHour += nMinute / 60; 2558cdf0e10cSrcweir nMinute %= 60; 2559cdf0e10cSrcweir } 2560cdf0e10cSrcweir n100Sec = (short)aStr.ToInt32(); 2561cdf0e10cSrcweir 2562cdf0e10cSrcweir if ( n100Sec ) 2563cdf0e10cSrcweir { 2564cdf0e10cSrcweir xub_StrLen nLen = 1; // mindestens eine Ziffer, weil sonst n100Sec==0 2565cdf0e10cSrcweir 2566cdf0e10cSrcweir while ( aStr.GetChar(nLen) >= '0' && aStr.GetChar(nLen) <= '9' ) 2567cdf0e10cSrcweir nLen++; 2568cdf0e10cSrcweir 2569cdf0e10cSrcweir if ( nLen > 2 ) 2570cdf0e10cSrcweir { 2571cdf0e10cSrcweir while( nLen > 3 ) 2572cdf0e10cSrcweir { 2573cdf0e10cSrcweir n100Sec = n100Sec / 10; 2574cdf0e10cSrcweir nLen--; 2575cdf0e10cSrcweir } 2576cdf0e10cSrcweir // Rundung bei negativen Zahlen??? 2577cdf0e10cSrcweir n100Sec = (n100Sec + 5) / 10; 2578cdf0e10cSrcweir } 2579cdf0e10cSrcweir else 2580cdf0e10cSrcweir { 2581cdf0e10cSrcweir while( nLen < 2 ) 2582cdf0e10cSrcweir { 2583cdf0e10cSrcweir n100Sec = n100Sec * 10; 2584cdf0e10cSrcweir nLen++; 2585cdf0e10cSrcweir } 2586cdf0e10cSrcweir } 2587cdf0e10cSrcweir } 2588cdf0e10cSrcweir } 2589cdf0e10cSrcweir 2590cdf0e10cSrcweir if ( (nMinute > 59) || (nSecond > 59) || (n100Sec > 100) ) 2591cdf0e10cSrcweir return sal_False; 2592cdf0e10cSrcweir 2593cdf0e10cSrcweir if ( eFormat == TIMEF_NONE ) 2594cdf0e10cSrcweir nSecond = n100Sec = 0; 2595cdf0e10cSrcweir else if ( eFormat == TIMEF_SEC ) 2596cdf0e10cSrcweir n100Sec = 0; 2597cdf0e10cSrcweir 2598cdf0e10cSrcweir if ( !bDuration ) 2599cdf0e10cSrcweir { 2600cdf0e10cSrcweir if ( bNegative || (nHour < 0) || (nMinute < 0) || 2601cdf0e10cSrcweir (nSecond < 0) || (n100Sec < 0) ) 2602cdf0e10cSrcweir return sal_False; 2603cdf0e10cSrcweir 2604cdf0e10cSrcweir aStr.ToUpperAscii(); 2605cdf0e10cSrcweir XubString aAM( rLocaleDataWrapper.getTimeAM() ); 2606cdf0e10cSrcweir XubString aPM( rLocaleDataWrapper.getTimePM() ); 2607cdf0e10cSrcweir aAM.ToUpperAscii(); 2608cdf0e10cSrcweir aPM.ToUpperAscii(); 2609cdf0e10cSrcweir XubString aAM2( RTL_CONSTASCII_USTRINGPARAM( "AM" ) ); // aAM is localized 2610cdf0e10cSrcweir XubString aPM2( RTL_CONSTASCII_USTRINGPARAM( "PM" ) ); // aPM is localized 2611cdf0e10cSrcweir 2612cdf0e10cSrcweir if ( (nHour < 12) && ( ( aStr.Search( aPM ) != STRING_NOTFOUND ) || ( aStr.Search( aPM2 ) != STRING_NOTFOUND ) ) ) 2613cdf0e10cSrcweir nHour += 12; 2614cdf0e10cSrcweir 2615cdf0e10cSrcweir if ( (nHour == 12) && ( ( aStr.Search( aAM ) != STRING_NOTFOUND ) || ( aStr.Search( aAM2 ) != STRING_NOTFOUND ) ) ) 2616cdf0e10cSrcweir nHour = 0; 2617cdf0e10cSrcweir 2618cdf0e10cSrcweir aTime = Time( (sal_uInt16)nHour, (sal_uInt16)nMinute, (sal_uInt16)nSecond, 2619cdf0e10cSrcweir (sal_uInt16)n100Sec ); 2620cdf0e10cSrcweir } 2621cdf0e10cSrcweir else 2622cdf0e10cSrcweir { 2623cdf0e10cSrcweir if ( bNegative || (nHour < 0) || (nMinute < 0) || 2624cdf0e10cSrcweir (nSecond < 0) || (n100Sec < 0) ) 2625cdf0e10cSrcweir { 2626cdf0e10cSrcweir bNegative = sal_True; 2627cdf0e10cSrcweir nHour = nHour < 0 ? -nHour : nHour; 2628cdf0e10cSrcweir nMinute = nMinute < 0 ? -nMinute : nMinute; 2629cdf0e10cSrcweir nSecond = nSecond < 0 ? -nSecond : nSecond; 2630cdf0e10cSrcweir n100Sec = n100Sec < 0 ? -n100Sec : n100Sec; 2631cdf0e10cSrcweir } 2632cdf0e10cSrcweir 2633cdf0e10cSrcweir aTime = Time( (sal_uInt16)nHour, (sal_uInt16)nMinute, (sal_uInt16)nSecond, 2634cdf0e10cSrcweir (sal_uInt16)n100Sec ); 2635cdf0e10cSrcweir if ( bNegative ) 2636cdf0e10cSrcweir aTime = -aTime; 2637cdf0e10cSrcweir } 2638cdf0e10cSrcweir 2639cdf0e10cSrcweir rTime = aTime; 2640cdf0e10cSrcweir 2641cdf0e10cSrcweir return sal_True; 2642cdf0e10cSrcweir } 2643cdf0e10cSrcweir 2644cdf0e10cSrcweir // ----------------------------------------------------------------------- 2645cdf0e10cSrcweir 2646cdf0e10cSrcweir sal_Bool TimeFormatter::ImplTimeReformat( const XubString& rStr, XubString& rOutStr ) 2647cdf0e10cSrcweir { 2648cdf0e10cSrcweir Time aTime( 0, 0, 0 ); 2649cdf0e10cSrcweir if ( !ImplTimeGetValue( rStr, aTime, GetFormat(), IsDuration(), ImplGetLocaleDataWrapper() ) ) 2650cdf0e10cSrcweir return sal_True; 2651cdf0e10cSrcweir 2652cdf0e10cSrcweir Time aTempTime = aTime; 2653cdf0e10cSrcweir if ( aTempTime > GetMax() ) 2654cdf0e10cSrcweir aTempTime = GetMax() ; 2655cdf0e10cSrcweir else if ( aTempTime < GetMin() ) 2656cdf0e10cSrcweir aTempTime = GetMin(); 2657cdf0e10cSrcweir 2658cdf0e10cSrcweir if ( GetErrorHdl().IsSet() && (aTime != aTempTime) ) 2659cdf0e10cSrcweir { 2660cdf0e10cSrcweir maCorrectedTime = aTempTime; 2661cdf0e10cSrcweir if ( !GetErrorHdl().Call( this ) ) 2662cdf0e10cSrcweir { 2663cdf0e10cSrcweir maCorrectedTime = Time(); 2664cdf0e10cSrcweir return sal_False; 2665cdf0e10cSrcweir } 2666cdf0e10cSrcweir else 2667cdf0e10cSrcweir maCorrectedTime = Time(); 2668cdf0e10cSrcweir } 2669cdf0e10cSrcweir 2670cdf0e10cSrcweir sal_Bool bSecond = sal_False; 2671cdf0e10cSrcweir sal_Bool b100Sec = sal_False; 2672cdf0e10cSrcweir if ( meFormat != TIMEF_NONE ) 2673cdf0e10cSrcweir bSecond = sal_True; 2674cdf0e10cSrcweir if ( meFormat == TIMEF_100TH_SEC ) 2675cdf0e10cSrcweir b100Sec = sal_True; 2676cdf0e10cSrcweir 2677cdf0e10cSrcweir if ( meFormat == TIMEF_SEC_CS ) 2678cdf0e10cSrcweir { 2679cdf0e10cSrcweir sal_uLong n = aTempTime.GetHour() * 3600L; 2680cdf0e10cSrcweir n += aTempTime.GetMin() * 60L; 2681cdf0e10cSrcweir n += aTempTime.GetSec(); 2682cdf0e10cSrcweir rOutStr = String::CreateFromInt32( n ); 2683cdf0e10cSrcweir rOutStr += ImplGetLocaleDataWrapper().getTime100SecSep(); 2684cdf0e10cSrcweir if ( aTempTime.Get100Sec() < 10 ) 2685cdf0e10cSrcweir rOutStr += '0'; 2686cdf0e10cSrcweir rOutStr += String::CreateFromInt32( aTempTime.Get100Sec() ); 2687cdf0e10cSrcweir } 2688cdf0e10cSrcweir else if ( mbDuration ) 2689cdf0e10cSrcweir rOutStr = ImplGetLocaleDataWrapper().getDuration( aTempTime, bSecond, b100Sec ); 2690cdf0e10cSrcweir else 2691cdf0e10cSrcweir { 2692cdf0e10cSrcweir rOutStr = ImplGetLocaleDataWrapper().getTime( aTempTime, bSecond, b100Sec ); 2693cdf0e10cSrcweir if ( GetTimeFormat() == HOUR_12 ) 2694cdf0e10cSrcweir { 2695cdf0e10cSrcweir if ( aTempTime.GetHour() > 12 ) 2696cdf0e10cSrcweir { 2697cdf0e10cSrcweir Time aT( aTempTime ); 2698cdf0e10cSrcweir aT.SetHour( aT.GetHour() % 12 ); 2699cdf0e10cSrcweir rOutStr = ImplGetLocaleDataWrapper().getTime( aT, bSecond, b100Sec ); 2700cdf0e10cSrcweir } 2701cdf0e10cSrcweir // Don't use LocaleDataWrapper, we want AM/PM 2702cdf0e10cSrcweir if ( aTempTime.GetHour() < 12 ) 2703cdf0e10cSrcweir rOutStr += String( RTL_CONSTASCII_USTRINGPARAM( "AM" ) ); // ImplGetLocaleDataWrapper().getTimeAM(); 2704cdf0e10cSrcweir else 2705cdf0e10cSrcweir rOutStr += String( RTL_CONSTASCII_USTRINGPARAM( "PM" ) ); // ImplGetLocaleDataWrapper().getTimePM(); 2706cdf0e10cSrcweir } 2707cdf0e10cSrcweir } 2708cdf0e10cSrcweir 2709cdf0e10cSrcweir return sal_True; 2710cdf0e10cSrcweir } 2711cdf0e10cSrcweir 2712cdf0e10cSrcweir // ----------------------------------------------------------------------- 2713cdf0e10cSrcweir sal_Bool TimeFormatter::ImplAllowMalformedInput() const 2714cdf0e10cSrcweir { 2715cdf0e10cSrcweir return !IsEnforceValidValue(); 2716cdf0e10cSrcweir } 2717cdf0e10cSrcweir 2718cdf0e10cSrcweir // ----------------------------------------------------------------------- 2719cdf0e10cSrcweir 2720cdf0e10cSrcweir void TimeField::ImplTimeSpinArea( sal_Bool bUp ) 2721cdf0e10cSrcweir { 2722cdf0e10cSrcweir if ( GetField() ) 2723cdf0e10cSrcweir { 2724cdf0e10cSrcweir xub_StrLen nTimeArea = 0; 2725cdf0e10cSrcweir Time aTime( GetTime() ); 2726cdf0e10cSrcweir XubString aText( GetText() ); 2727cdf0e10cSrcweir Selection aSelection( GetField()->GetSelection() ); 2728cdf0e10cSrcweir 2729cdf0e10cSrcweir // Area suchen 2730cdf0e10cSrcweir if ( GetFormat() != TIMEF_SEC_CS ) 2731cdf0e10cSrcweir { 2732cdf0e10cSrcweir for ( xub_StrLen i = 1, nPos = 0; i <= 4; i++ ) 2733cdf0e10cSrcweir { 2734cdf0e10cSrcweir xub_StrLen nPos1 = aText.Search( ImplGetLocaleDataWrapper().getTimeSep(), nPos ); 2735cdf0e10cSrcweir xub_StrLen nPos2 = aText.Search( ImplGetLocaleDataWrapper().getTime100SecSep(), nPos ); 2736cdf0e10cSrcweir nPos = nPos1 < nPos2 ? nPos1 : nPos2; 2737cdf0e10cSrcweir if ( nPos >= (xub_StrLen)aSelection.Max() ) 2738cdf0e10cSrcweir { 2739cdf0e10cSrcweir nTimeArea = i; 2740cdf0e10cSrcweir break; 2741cdf0e10cSrcweir } 2742cdf0e10cSrcweir else 2743cdf0e10cSrcweir nPos++; 2744cdf0e10cSrcweir } 2745cdf0e10cSrcweir } 2746cdf0e10cSrcweir else 2747cdf0e10cSrcweir { 2748cdf0e10cSrcweir xub_StrLen nPos = aText.Search( ImplGetLocaleDataWrapper().getTime100SecSep() ); 2749cdf0e10cSrcweir if ( nPos == STRING_NOTFOUND || nPos >= (xub_StrLen)aSelection.Max() ) 2750cdf0e10cSrcweir nTimeArea = 3; 2751cdf0e10cSrcweir else 2752cdf0e10cSrcweir nTimeArea = 4; 2753cdf0e10cSrcweir } 2754cdf0e10cSrcweir 2755cdf0e10cSrcweir if ( nTimeArea ) 2756cdf0e10cSrcweir { 2757cdf0e10cSrcweir Time aAddTime( 0, 0, 0 ); 2758cdf0e10cSrcweir if ( nTimeArea == 1 ) 2759cdf0e10cSrcweir aAddTime = Time( 1, 0 ); 2760cdf0e10cSrcweir else if ( nTimeArea == 2 ) 2761cdf0e10cSrcweir aAddTime = Time( 0, 1 ); 2762cdf0e10cSrcweir else if ( nTimeArea == 3 ) 2763cdf0e10cSrcweir aAddTime = Time( 0, 0, 1 ); 2764cdf0e10cSrcweir else if ( nTimeArea == 4 ) 2765cdf0e10cSrcweir aAddTime = Time( 0, 0, 0, 1 ); 2766cdf0e10cSrcweir 2767cdf0e10cSrcweir if ( !bUp ) 2768cdf0e10cSrcweir aAddTime = -aAddTime; 2769cdf0e10cSrcweir 2770cdf0e10cSrcweir aTime += aAddTime; 2771cdf0e10cSrcweir if ( !IsDuration() ) 2772cdf0e10cSrcweir { 2773cdf0e10cSrcweir Time aAbsMaxTime( 23, 59, 59, 99 ); 2774cdf0e10cSrcweir if ( aTime > aAbsMaxTime ) 2775cdf0e10cSrcweir aTime = aAbsMaxTime; 2776cdf0e10cSrcweir Time aAbsMinTime( 0, 0 ); 2777cdf0e10cSrcweir if ( aTime < aAbsMinTime ) 2778cdf0e10cSrcweir aTime = aAbsMinTime; 2779cdf0e10cSrcweir } 2780cdf0e10cSrcweir ImplNewFieldValue( aTime ); 2781cdf0e10cSrcweir } 2782cdf0e10cSrcweir 2783cdf0e10cSrcweir } 2784cdf0e10cSrcweir } 2785cdf0e10cSrcweir 2786cdf0e10cSrcweir // ----------------------------------------------------------------------- 2787cdf0e10cSrcweir 2788cdf0e10cSrcweir void TimeFormatter::ImplInit() 2789cdf0e10cSrcweir { 2790cdf0e10cSrcweir meFormat = TIMEF_NONE; 2791cdf0e10cSrcweir mbDuration = sal_False; 2792cdf0e10cSrcweir mnTimeFormat = HOUR_24; // Should become a ExtTimeFieldFormat in next implementation, merge with mbDuration and meFormat 2793cdf0e10cSrcweir } 2794cdf0e10cSrcweir 2795cdf0e10cSrcweir // ----------------------------------------------------------------------- 2796cdf0e10cSrcweir 2797cdf0e10cSrcweir TimeFormatter::TimeFormatter() : 2798cdf0e10cSrcweir maLastTime( 0, 0 ), 2799cdf0e10cSrcweir maMin( 0, 0 ), 2800cdf0e10cSrcweir maMax( 23, 59, 59, 99 ), 2801cdf0e10cSrcweir mbEnforceValidValue( sal_True ), 2802cdf0e10cSrcweir maFieldTime( 0, 0 ) 2803cdf0e10cSrcweir { 2804cdf0e10cSrcweir ImplInit(); 2805cdf0e10cSrcweir } 2806cdf0e10cSrcweir 2807cdf0e10cSrcweir // ----------------------------------------------------------------------- 2808cdf0e10cSrcweir 2809cdf0e10cSrcweir void TimeFormatter::ImplLoadRes( const ResId& rResId ) 2810cdf0e10cSrcweir { 2811cdf0e10cSrcweir ResMgr* pMgr = rResId.GetResMgr(); 2812cdf0e10cSrcweir if( pMgr ) 2813cdf0e10cSrcweir { 2814cdf0e10cSrcweir sal_uLong nMask = pMgr->ReadLong(); 2815cdf0e10cSrcweir 2816cdf0e10cSrcweir if ( TIMEFORMATTER_MIN & nMask ) 2817cdf0e10cSrcweir { 2818cdf0e10cSrcweir SetMin( Time( ResId( (RSHEADER_TYPE *)pMgr->GetClass(), *pMgr ) ) ); 2819cdf0e10cSrcweir pMgr->Increment( pMgr->GetObjSize( (RSHEADER_TYPE *)pMgr->GetClass() ) ); 2820cdf0e10cSrcweir } 2821cdf0e10cSrcweir 2822cdf0e10cSrcweir if ( TIMEFORMATTER_MAX & nMask ) 2823cdf0e10cSrcweir { 2824cdf0e10cSrcweir SetMax( Time( ResId( (RSHEADER_TYPE *)pMgr->GetClass(), *pMgr ) ) ); 2825cdf0e10cSrcweir pMgr->Increment( pMgr->GetObjSize( (RSHEADER_TYPE *)pMgr->GetClass() ) ); 2826cdf0e10cSrcweir } 2827cdf0e10cSrcweir 2828cdf0e10cSrcweir if ( TIMEFORMATTER_TIMEFIELDFORMAT & nMask ) 2829cdf0e10cSrcweir meFormat = (TimeFieldFormat)pMgr->ReadLong(); 2830cdf0e10cSrcweir 2831cdf0e10cSrcweir if ( TIMEFORMATTER_DURATION & nMask ) 2832cdf0e10cSrcweir mbDuration = (sal_Bool)pMgr->ReadShort(); 2833cdf0e10cSrcweir 2834cdf0e10cSrcweir if ( TIMEFORMATTER_STRICTFORMAT & nMask ) 2835cdf0e10cSrcweir SetStrictFormat( (sal_Bool)pMgr->ReadShort() ); 2836cdf0e10cSrcweir 2837cdf0e10cSrcweir if ( TIMEFORMATTER_VALUE & nMask ) 2838cdf0e10cSrcweir { 2839cdf0e10cSrcweir maFieldTime = Time( ResId( (RSHEADER_TYPE *)pMgr->GetClass(), *pMgr ) ); 2840cdf0e10cSrcweir if ( maFieldTime > GetMax() ) 2841cdf0e10cSrcweir maFieldTime = GetMax(); 2842cdf0e10cSrcweir if ( maFieldTime < GetMin() ) 2843cdf0e10cSrcweir maFieldTime = GetMin(); 2844cdf0e10cSrcweir maLastTime = maFieldTime; 2845cdf0e10cSrcweir 2846cdf0e10cSrcweir pMgr->Increment( pMgr->GetObjSize( (RSHEADER_TYPE *)pMgr->GetClass() ) ); 2847cdf0e10cSrcweir } 2848cdf0e10cSrcweir } 2849cdf0e10cSrcweir } 2850cdf0e10cSrcweir 2851cdf0e10cSrcweir // ----------------------------------------------------------------------- 2852cdf0e10cSrcweir 2853cdf0e10cSrcweir TimeFormatter::~TimeFormatter() 2854cdf0e10cSrcweir { 2855cdf0e10cSrcweir } 2856cdf0e10cSrcweir 2857cdf0e10cSrcweir // ----------------------------------------------------------------------- 2858cdf0e10cSrcweir 2859cdf0e10cSrcweir void TimeFormatter::ReformatAll() 2860cdf0e10cSrcweir { 2861cdf0e10cSrcweir Reformat(); 2862cdf0e10cSrcweir } 2863cdf0e10cSrcweir 2864cdf0e10cSrcweir // ----------------------------------------------------------------------- 2865cdf0e10cSrcweir 2866cdf0e10cSrcweir void TimeFormatter::SetMin( const Time& rNewMin ) 2867cdf0e10cSrcweir { 2868cdf0e10cSrcweir maMin = rNewMin; 2869cdf0e10cSrcweir if ( !IsEmptyFieldValue() ) 2870cdf0e10cSrcweir ReformatAll(); 2871cdf0e10cSrcweir } 2872cdf0e10cSrcweir 2873cdf0e10cSrcweir // ----------------------------------------------------------------------- 2874cdf0e10cSrcweir 2875cdf0e10cSrcweir void TimeFormatter::SetMax( const Time& rNewMax ) 2876cdf0e10cSrcweir { 2877cdf0e10cSrcweir maMax = rNewMax; 2878cdf0e10cSrcweir if ( !IsEmptyFieldValue() ) 2879cdf0e10cSrcweir ReformatAll(); 2880cdf0e10cSrcweir } 2881cdf0e10cSrcweir 2882cdf0e10cSrcweir // ----------------------------------------------------------------------- 2883cdf0e10cSrcweir 2884cdf0e10cSrcweir void TimeFormatter::SetTimeFormat( TimeFormatter::TimeFormat eNewFormat ) 2885cdf0e10cSrcweir { 2886cdf0e10cSrcweir mnTimeFormat = sal::static_int_cast<sal_uInt16>(eNewFormat); 2887cdf0e10cSrcweir } 2888cdf0e10cSrcweir 2889cdf0e10cSrcweir // ----------------------------------------------------------------------- 2890cdf0e10cSrcweir 2891cdf0e10cSrcweir TimeFormatter::TimeFormat TimeFormatter::GetTimeFormat() const 2892cdf0e10cSrcweir { 2893cdf0e10cSrcweir return (TimeFormat)mnTimeFormat; 2894cdf0e10cSrcweir } 2895cdf0e10cSrcweir 2896cdf0e10cSrcweir // ----------------------------------------------------------------------- 2897cdf0e10cSrcweir 2898cdf0e10cSrcweir void TimeFormatter::SetFormat( TimeFieldFormat eNewFormat ) 2899cdf0e10cSrcweir { 2900cdf0e10cSrcweir meFormat = eNewFormat; 2901cdf0e10cSrcweir ReformatAll(); 2902cdf0e10cSrcweir } 2903cdf0e10cSrcweir 2904cdf0e10cSrcweir // ----------------------------------------------------------------------- 2905cdf0e10cSrcweir 2906cdf0e10cSrcweir void TimeFormatter::SetDuration( sal_Bool bNewDuration ) 2907cdf0e10cSrcweir { 2908cdf0e10cSrcweir mbDuration = bNewDuration; 2909cdf0e10cSrcweir ReformatAll(); 2910cdf0e10cSrcweir } 2911cdf0e10cSrcweir 2912cdf0e10cSrcweir // ----------------------------------------------------------------------- 2913cdf0e10cSrcweir 2914cdf0e10cSrcweir void TimeFormatter::SetTime( const Time& rNewTime ) 2915cdf0e10cSrcweir { 2916cdf0e10cSrcweir SetUserTime( rNewTime ); 2917cdf0e10cSrcweir maFieldTime = maLastTime; 2918cdf0e10cSrcweir SetEmptyFieldValueData( sal_False ); 2919cdf0e10cSrcweir } 2920cdf0e10cSrcweir 2921cdf0e10cSrcweir // ----------------------------------------------------------------------- 2922cdf0e10cSrcweir 2923cdf0e10cSrcweir void TimeFormatter::ImplNewFieldValue( const Time& rTime ) 2924cdf0e10cSrcweir { 2925cdf0e10cSrcweir if ( GetField() ) 2926cdf0e10cSrcweir { 2927cdf0e10cSrcweir Selection aSelection = GetField()->GetSelection(); 2928cdf0e10cSrcweir aSelection.Justify(); 2929cdf0e10cSrcweir XubString aText = GetField()->GetText(); 2930cdf0e10cSrcweir // Wenn bis ans Ende selektiert war, soll das auch so bleiben... 2931cdf0e10cSrcweir if ( (xub_StrLen)aSelection.Max() == aText.Len() ) 2932cdf0e10cSrcweir { 2933cdf0e10cSrcweir if ( !aSelection.Len() ) 2934cdf0e10cSrcweir aSelection.Min() = SELECTION_MAX; 2935cdf0e10cSrcweir aSelection.Max() = SELECTION_MAX; 2936cdf0e10cSrcweir } 2937cdf0e10cSrcweir 2938cdf0e10cSrcweir Time aOldLastTime = maLastTime; 2939cdf0e10cSrcweir ImplSetUserTime( rTime, &aSelection ); 2940cdf0e10cSrcweir maLastTime = aOldLastTime; 2941cdf0e10cSrcweir 2942cdf0e10cSrcweir // Modify am Edit wird nur bei KeyInput gesetzt... 2943cdf0e10cSrcweir if ( GetField()->GetText() != aText ) 2944cdf0e10cSrcweir { 2945cdf0e10cSrcweir GetField()->SetModifyFlag(); 2946cdf0e10cSrcweir GetField()->Modify(); 2947cdf0e10cSrcweir } 2948cdf0e10cSrcweir } 2949cdf0e10cSrcweir } 2950cdf0e10cSrcweir 2951cdf0e10cSrcweir // ----------------------------------------------------------------------- 2952cdf0e10cSrcweir 2953cdf0e10cSrcweir void TimeFormatter::ImplSetUserTime( const Time& rNewTime, Selection* pNewSelection ) 2954cdf0e10cSrcweir { 2955cdf0e10cSrcweir Time aNewTime = rNewTime; 2956cdf0e10cSrcweir if ( aNewTime > GetMax() ) 2957cdf0e10cSrcweir aNewTime = GetMax(); 2958cdf0e10cSrcweir else if ( aNewTime < GetMin() ) 2959cdf0e10cSrcweir aNewTime = GetMin(); 2960cdf0e10cSrcweir maLastTime = aNewTime; 2961cdf0e10cSrcweir 2962cdf0e10cSrcweir if ( GetField() ) 2963cdf0e10cSrcweir { 2964cdf0e10cSrcweir XubString aStr; 2965cdf0e10cSrcweir sal_Bool bSec = sal_False; 2966cdf0e10cSrcweir sal_Bool b100Sec = sal_False; 2967cdf0e10cSrcweir if ( meFormat != TIMEF_NONE ) 2968cdf0e10cSrcweir bSec = sal_True; 2969cdf0e10cSrcweir if ( meFormat == TIMEF_100TH_SEC || meFormat == TIMEF_SEC_CS ) 2970cdf0e10cSrcweir b100Sec = sal_True; 2971cdf0e10cSrcweir if ( meFormat == TIMEF_SEC_CS ) 2972cdf0e10cSrcweir { 2973cdf0e10cSrcweir sal_uLong n = aNewTime.GetHour() * 3600L; 2974cdf0e10cSrcweir n += aNewTime.GetMin() * 60L; 2975cdf0e10cSrcweir n += aNewTime.GetSec(); 2976cdf0e10cSrcweir aStr = String::CreateFromInt32( n ); 2977cdf0e10cSrcweir aStr += ImplGetLocaleDataWrapper().getTime100SecSep(); 2978cdf0e10cSrcweir if ( aNewTime.Get100Sec() < 10 ) 2979cdf0e10cSrcweir aStr += '0'; 2980cdf0e10cSrcweir aStr += String::CreateFromInt32( aNewTime.Get100Sec() ); 2981cdf0e10cSrcweir } 2982cdf0e10cSrcweir else if ( mbDuration ) 2983cdf0e10cSrcweir { 2984cdf0e10cSrcweir aStr = ImplGetLocaleDataWrapper().getDuration( aNewTime, bSec, b100Sec ); 2985cdf0e10cSrcweir } 2986cdf0e10cSrcweir else 2987cdf0e10cSrcweir { 2988cdf0e10cSrcweir aStr = ImplGetLocaleDataWrapper().getTime( aNewTime, bSec, b100Sec ); 2989cdf0e10cSrcweir if ( GetTimeFormat() == HOUR_12 ) 2990cdf0e10cSrcweir { 2991cdf0e10cSrcweir if ( aNewTime.GetHour() > 12 ) 2992cdf0e10cSrcweir { 2993cdf0e10cSrcweir Time aT( aNewTime ); 2994cdf0e10cSrcweir aT.SetHour( aT.GetHour() % 12 ); 2995cdf0e10cSrcweir aStr = ImplGetLocaleDataWrapper().getTime( aT, bSec, b100Sec ); 2996cdf0e10cSrcweir } 2997cdf0e10cSrcweir // Don't use LocaleDataWrapper, we want AM/PM 2998cdf0e10cSrcweir if ( aNewTime.GetHour() < 12 ) 2999cdf0e10cSrcweir aStr += String( RTL_CONSTASCII_USTRINGPARAM( "AM" ) ); // ImplGetLocaleDataWrapper().getTimeAM(); 3000cdf0e10cSrcweir else 3001cdf0e10cSrcweir aStr += String( RTL_CONSTASCII_USTRINGPARAM( "PM" ) ); // ImplGetLocaleDataWrapper().getTimePM(); 3002cdf0e10cSrcweir } 3003cdf0e10cSrcweir } 3004cdf0e10cSrcweir 3005cdf0e10cSrcweir ImplSetText( aStr, pNewSelection ); 3006cdf0e10cSrcweir } 3007cdf0e10cSrcweir } 3008cdf0e10cSrcweir 3009cdf0e10cSrcweir // ----------------------------------------------------------------------- 3010cdf0e10cSrcweir 3011cdf0e10cSrcweir void TimeFormatter::SetUserTime( const Time& rNewTime ) 3012cdf0e10cSrcweir { 3013cdf0e10cSrcweir ImplSetUserTime( rNewTime ); 3014cdf0e10cSrcweir } 3015cdf0e10cSrcweir 3016cdf0e10cSrcweir // ----------------------------------------------------------------------- 3017cdf0e10cSrcweir 3018cdf0e10cSrcweir Time TimeFormatter::GetTime() const 3019cdf0e10cSrcweir { 3020cdf0e10cSrcweir Time aTime( 0, 0, 0 ); 3021cdf0e10cSrcweir 3022cdf0e10cSrcweir if ( GetField() ) 3023cdf0e10cSrcweir { 3024cdf0e10cSrcweir sal_Bool bAllowMailformed = ImplAllowMalformedInput(); 3025cdf0e10cSrcweir if ( ImplTimeGetValue( GetField()->GetText(), aTime, GetFormat(), IsDuration(), ImplGetLocaleDataWrapper(), !bAllowMailformed ) ) 3026cdf0e10cSrcweir { 3027cdf0e10cSrcweir if ( aTime > GetMax() ) 3028cdf0e10cSrcweir aTime = GetMax(); 3029cdf0e10cSrcweir else if ( aTime < GetMin() ) 3030cdf0e10cSrcweir aTime = GetMin(); 3031cdf0e10cSrcweir } 3032cdf0e10cSrcweir else 3033cdf0e10cSrcweir { 3034cdf0e10cSrcweir if ( bAllowMailformed ) 3035cdf0e10cSrcweir aTime = GetInvalidTime(); 3036cdf0e10cSrcweir else 3037cdf0e10cSrcweir aTime = maLastTime; 3038cdf0e10cSrcweir } 3039cdf0e10cSrcweir } 3040cdf0e10cSrcweir 3041cdf0e10cSrcweir return aTime; 3042cdf0e10cSrcweir } 3043cdf0e10cSrcweir 3044cdf0e10cSrcweir // ----------------------------------------------------------------------- 3045cdf0e10cSrcweir 3046cdf0e10cSrcweir Time TimeFormatter::GetRealTime() const 3047cdf0e10cSrcweir { 3048cdf0e10cSrcweir Time aTime( 0, 0, 0 ); 3049cdf0e10cSrcweir 3050cdf0e10cSrcweir if ( GetField() ) 3051cdf0e10cSrcweir { 3052cdf0e10cSrcweir sal_Bool bAllowMailformed = ImplAllowMalformedInput(); 3053cdf0e10cSrcweir if ( !ImplTimeGetValue( GetField()->GetText(), aTime, GetFormat(), IsDuration(), ImplGetLocaleDataWrapper(), !bAllowMailformed ) ) 3054cdf0e10cSrcweir if ( bAllowMailformed ) 3055cdf0e10cSrcweir aTime = GetInvalidTime(); 3056cdf0e10cSrcweir } 3057cdf0e10cSrcweir 3058cdf0e10cSrcweir return aTime; 3059cdf0e10cSrcweir } 3060cdf0e10cSrcweir 3061cdf0e10cSrcweir // ----------------------------------------------------------------------- 3062cdf0e10cSrcweir 3063cdf0e10cSrcweir sal_Bool TimeFormatter::IsTimeModified() const 3064cdf0e10cSrcweir { 3065cdf0e10cSrcweir if ( ImplGetEmptyFieldValue() ) 3066cdf0e10cSrcweir return !IsEmptyTime(); 3067cdf0e10cSrcweir else if ( GetTime() != maFieldTime ) 3068cdf0e10cSrcweir return sal_True; 3069cdf0e10cSrcweir else 3070cdf0e10cSrcweir return sal_False; 3071cdf0e10cSrcweir } 3072cdf0e10cSrcweir 3073cdf0e10cSrcweir // ----------------------------------------------------------------------- 3074cdf0e10cSrcweir 3075cdf0e10cSrcweir void TimeFormatter::Reformat() 3076cdf0e10cSrcweir { 3077cdf0e10cSrcweir if ( !GetField() ) 3078cdf0e10cSrcweir return; 3079cdf0e10cSrcweir 3080cdf0e10cSrcweir if ( !GetField()->GetText().Len() && ImplGetEmptyFieldValue() ) 3081cdf0e10cSrcweir return; 3082cdf0e10cSrcweir 3083cdf0e10cSrcweir XubString aStr; 3084cdf0e10cSrcweir sal_Bool bOK = ImplTimeReformat( GetField()->GetText(), aStr ); 3085cdf0e10cSrcweir if ( !bOK ) 3086cdf0e10cSrcweir return; 3087cdf0e10cSrcweir 3088cdf0e10cSrcweir if ( aStr.Len() ) 3089cdf0e10cSrcweir { 3090cdf0e10cSrcweir ImplSetText( aStr ); 3091cdf0e10cSrcweir ImplTimeGetValue( aStr, maLastTime, GetFormat(), IsDuration(), ImplGetLocaleDataWrapper() ); 3092cdf0e10cSrcweir } 3093cdf0e10cSrcweir else 3094cdf0e10cSrcweir SetTime( maLastTime ); 3095cdf0e10cSrcweir } 3096cdf0e10cSrcweir 3097cdf0e10cSrcweir // ----------------------------------------------------------------------- 3098cdf0e10cSrcweir 3099cdf0e10cSrcweir TimeField::TimeField( Window* pParent, WinBits nWinStyle ) : 3100cdf0e10cSrcweir SpinField( pParent, nWinStyle ), 3101cdf0e10cSrcweir maFirst( GetMin() ), 3102cdf0e10cSrcweir maLast( GetMax() ) 3103cdf0e10cSrcweir { 3104cdf0e10cSrcweir SetField( this ); 3105cdf0e10cSrcweir SetText( ImplGetLocaleDataWrapper().getTime( maFieldTime, sal_False, sal_False ) ); 3106cdf0e10cSrcweir Reformat(); 3107cdf0e10cSrcweir } 3108cdf0e10cSrcweir 3109cdf0e10cSrcweir // ----------------------------------------------------------------------- 3110cdf0e10cSrcweir 3111cdf0e10cSrcweir TimeField::TimeField( Window* pParent, const ResId& rResId ) : 3112cdf0e10cSrcweir SpinField( WINDOW_TIMEFIELD ), 3113cdf0e10cSrcweir maFirst( GetMin() ), 3114cdf0e10cSrcweir maLast( GetMax() ) 3115cdf0e10cSrcweir { 3116cdf0e10cSrcweir rResId.SetRT( RSC_TIMEFIELD ); 3117cdf0e10cSrcweir WinBits nStyle = ImplInitRes( rResId ); 3118cdf0e10cSrcweir SpinField::ImplInit( pParent, nStyle ); 3119cdf0e10cSrcweir SetField( this ); 3120cdf0e10cSrcweir SetText( ImplGetLocaleDataWrapper().getTime( maFieldTime, sal_False, sal_False ) ); 3121cdf0e10cSrcweir ImplLoadRes( rResId ); 3122cdf0e10cSrcweir 3123cdf0e10cSrcweir if ( !(nStyle & WB_HIDE ) ) 3124cdf0e10cSrcweir Show(); 3125cdf0e10cSrcweir } 3126cdf0e10cSrcweir 3127cdf0e10cSrcweir // ----------------------------------------------------------------------- 3128cdf0e10cSrcweir 3129cdf0e10cSrcweir void TimeField::ImplLoadRes( const ResId& rResId ) 3130cdf0e10cSrcweir { 3131cdf0e10cSrcweir SpinField::ImplLoadRes( rResId ); 3132cdf0e10cSrcweir ResMgr* pMgr = rResId.GetResMgr(); 3133cdf0e10cSrcweir if( pMgr ) 3134cdf0e10cSrcweir { 3135cdf0e10cSrcweir TimeFormatter::ImplLoadRes( ResId( (RSHEADER_TYPE *)GetClassRes(), *pMgr ) ); 3136cdf0e10cSrcweir 3137cdf0e10cSrcweir sal_uLong nMask = ReadLongRes(); 3138cdf0e10cSrcweir 3139cdf0e10cSrcweir if ( TIMEFIELD_FIRST & nMask ) 3140cdf0e10cSrcweir { 3141cdf0e10cSrcweir maFirst = Time( ResId( (RSHEADER_TYPE *)GetClassRes(), *pMgr ) ); 3142cdf0e10cSrcweir IncrementRes( GetObjSizeRes( (RSHEADER_TYPE *)GetClassRes() ) ); 3143cdf0e10cSrcweir } 3144cdf0e10cSrcweir if ( TIMEFIELD_LAST & nMask ) 3145cdf0e10cSrcweir { 3146cdf0e10cSrcweir maLast = Time( ResId( (RSHEADER_TYPE *)GetClassRes(), *pMgr ) ); 3147cdf0e10cSrcweir IncrementRes( GetObjSizeRes( (RSHEADER_TYPE *)GetClassRes() ) ); 3148cdf0e10cSrcweir } 3149cdf0e10cSrcweir } 3150cdf0e10cSrcweir 3151cdf0e10cSrcweir Reformat(); 3152cdf0e10cSrcweir } 3153cdf0e10cSrcweir 3154cdf0e10cSrcweir // ----------------------------------------------------------------------- 3155cdf0e10cSrcweir 3156cdf0e10cSrcweir TimeField::~TimeField() 3157cdf0e10cSrcweir { 3158cdf0e10cSrcweir } 3159cdf0e10cSrcweir 3160cdf0e10cSrcweir // ----------------------------------------------------------------------- 3161cdf0e10cSrcweir 3162cdf0e10cSrcweir long TimeField::PreNotify( NotifyEvent& rNEvt ) 3163cdf0e10cSrcweir { 3164cdf0e10cSrcweir if ( (rNEvt.GetType() == EVENT_KEYINPUT) && !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() ) 3165cdf0e10cSrcweir { 3166cdf0e10cSrcweir if ( ImplTimeProcessKeyInput( GetField(), *rNEvt.GetKeyEvent(), IsStrictFormat(), IsDuration(), GetFormat(), ImplGetLocaleDataWrapper() ) ) 3167cdf0e10cSrcweir return 1; 3168cdf0e10cSrcweir } 3169cdf0e10cSrcweir 3170cdf0e10cSrcweir return SpinField::PreNotify( rNEvt ); 3171cdf0e10cSrcweir } 3172cdf0e10cSrcweir 3173cdf0e10cSrcweir // ----------------------------------------------------------------------- 3174cdf0e10cSrcweir 3175cdf0e10cSrcweir long TimeField::Notify( NotifyEvent& rNEvt ) 3176cdf0e10cSrcweir { 3177cdf0e10cSrcweir if ( rNEvt.GetType() == EVENT_GETFOCUS ) 3178cdf0e10cSrcweir MarkToBeReformatted( sal_False ); 3179cdf0e10cSrcweir else if ( rNEvt.GetType() == EVENT_LOSEFOCUS ) 3180cdf0e10cSrcweir { 3181cdf0e10cSrcweir if ( MustBeReformatted() && (GetText().Len() || !IsEmptyFieldValueEnabled()) ) 3182cdf0e10cSrcweir { 3183cdf0e10cSrcweir if ( !ImplAllowMalformedInput() ) 3184cdf0e10cSrcweir Reformat(); 3185cdf0e10cSrcweir else 3186cdf0e10cSrcweir { 3187cdf0e10cSrcweir Time aTime( 0, 0, 0 ); 3188cdf0e10cSrcweir if ( ImplTimeGetValue( GetText(), aTime, GetFormat(), IsDuration(), ImplGetLocaleDataWrapper(), sal_False ) ) 3189cdf0e10cSrcweir // even with strict text analysis, our text is a valid time -> do a complete 3190cdf0e10cSrcweir // reformat 3191cdf0e10cSrcweir Reformat(); 3192cdf0e10cSrcweir } 3193cdf0e10cSrcweir } 3194cdf0e10cSrcweir } 3195cdf0e10cSrcweir 3196cdf0e10cSrcweir return SpinField::Notify( rNEvt ); 3197cdf0e10cSrcweir } 3198cdf0e10cSrcweir 3199cdf0e10cSrcweir // ----------------------------------------------------------------------- 3200cdf0e10cSrcweir 3201cdf0e10cSrcweir void TimeField::DataChanged( const DataChangedEvent& rDCEvt ) 3202cdf0e10cSrcweir { 3203cdf0e10cSrcweir SpinField::DataChanged( rDCEvt ); 3204cdf0e10cSrcweir 3205cdf0e10cSrcweir if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_LOCALE) ) 3206cdf0e10cSrcweir { 3207cdf0e10cSrcweir if ( IsDefaultLocale() ) 3208cdf0e10cSrcweir ImplGetLocaleDataWrapper().setLocale( GetSettings().GetLocale() ); 3209cdf0e10cSrcweir ReformatAll(); 3210cdf0e10cSrcweir } 3211cdf0e10cSrcweir } 3212cdf0e10cSrcweir 3213cdf0e10cSrcweir // ----------------------------------------------------------------------- 3214cdf0e10cSrcweir 3215cdf0e10cSrcweir void TimeField::Modify() 3216cdf0e10cSrcweir { 3217cdf0e10cSrcweir MarkToBeReformatted( sal_True ); 3218cdf0e10cSrcweir SpinField::Modify(); 3219cdf0e10cSrcweir } 3220cdf0e10cSrcweir 3221cdf0e10cSrcweir // ----------------------------------------------------------------------- 3222cdf0e10cSrcweir 3223cdf0e10cSrcweir void TimeField::Up() 3224cdf0e10cSrcweir { 3225cdf0e10cSrcweir ImplTimeSpinArea( sal_True ); 3226cdf0e10cSrcweir SpinField::Up(); 3227cdf0e10cSrcweir } 3228cdf0e10cSrcweir 3229cdf0e10cSrcweir // ----------------------------------------------------------------------- 3230cdf0e10cSrcweir 3231cdf0e10cSrcweir void TimeField::Down() 3232cdf0e10cSrcweir { 3233cdf0e10cSrcweir ImplTimeSpinArea( sal_False ); 3234cdf0e10cSrcweir SpinField::Down(); 3235cdf0e10cSrcweir } 3236cdf0e10cSrcweir 3237cdf0e10cSrcweir // ----------------------------------------------------------------------- 3238cdf0e10cSrcweir 3239cdf0e10cSrcweir void TimeField::First() 3240cdf0e10cSrcweir { 3241cdf0e10cSrcweir ImplNewFieldValue( maFirst ); 3242cdf0e10cSrcweir SpinField::First(); 3243cdf0e10cSrcweir } 3244cdf0e10cSrcweir 3245cdf0e10cSrcweir // ----------------------------------------------------------------------- 3246cdf0e10cSrcweir 3247cdf0e10cSrcweir void TimeField::Last() 3248cdf0e10cSrcweir { 3249cdf0e10cSrcweir ImplNewFieldValue( maLast ); 3250cdf0e10cSrcweir SpinField::Last(); 3251cdf0e10cSrcweir } 3252cdf0e10cSrcweir 3253cdf0e10cSrcweir // ----------------------------------------------------------------------- 3254cdf0e10cSrcweir 3255cdf0e10cSrcweir void TimeField::SetExtFormat( ExtTimeFieldFormat eFormat ) 3256cdf0e10cSrcweir { 3257cdf0e10cSrcweir switch ( eFormat ) 3258cdf0e10cSrcweir { 3259cdf0e10cSrcweir case EXTTIMEF_24H_SHORT: 3260cdf0e10cSrcweir { 3261cdf0e10cSrcweir SetTimeFormat( HOUR_24 ); 3262cdf0e10cSrcweir SetDuration( sal_False ); 3263cdf0e10cSrcweir SetFormat( TIMEF_NONE ); 3264cdf0e10cSrcweir } 3265cdf0e10cSrcweir break; 3266cdf0e10cSrcweir case EXTTIMEF_24H_LONG: 3267cdf0e10cSrcweir { 3268cdf0e10cSrcweir SetTimeFormat( HOUR_24 ); 3269cdf0e10cSrcweir SetDuration( sal_False ); 3270cdf0e10cSrcweir SetFormat( TIMEF_SEC ); 3271cdf0e10cSrcweir } 3272cdf0e10cSrcweir break; 3273cdf0e10cSrcweir case EXTTIMEF_12H_SHORT: 3274cdf0e10cSrcweir { 3275cdf0e10cSrcweir SetTimeFormat( HOUR_12 ); 3276cdf0e10cSrcweir SetDuration( sal_False ); 3277cdf0e10cSrcweir SetFormat( TIMEF_NONE ); 3278cdf0e10cSrcweir } 3279cdf0e10cSrcweir break; 3280cdf0e10cSrcweir case EXTTIMEF_12H_LONG: 3281cdf0e10cSrcweir { 3282cdf0e10cSrcweir SetTimeFormat( HOUR_12 ); 3283cdf0e10cSrcweir SetDuration( sal_False ); 3284cdf0e10cSrcweir SetFormat( TIMEF_SEC ); 3285cdf0e10cSrcweir } 3286cdf0e10cSrcweir break; 3287cdf0e10cSrcweir case EXTTIMEF_DURATION_SHORT: 3288cdf0e10cSrcweir { 3289cdf0e10cSrcweir SetDuration( sal_True ); 3290cdf0e10cSrcweir SetFormat( TIMEF_NONE ); 3291cdf0e10cSrcweir } 3292cdf0e10cSrcweir break; 3293cdf0e10cSrcweir case EXTTIMEF_DURATION_LONG: 3294cdf0e10cSrcweir { 3295cdf0e10cSrcweir SetDuration( sal_True ); 3296cdf0e10cSrcweir SetFormat( TIMEF_SEC ); 3297cdf0e10cSrcweir } 3298cdf0e10cSrcweir break; 3299cdf0e10cSrcweir default: DBG_ERROR( "ExtTimeFieldFormat unknown!" ); 3300cdf0e10cSrcweir } 3301cdf0e10cSrcweir 3302cdf0e10cSrcweir if ( GetField() && GetField()->GetText().Len() ) 3303cdf0e10cSrcweir SetUserTime( GetTime() ); 3304cdf0e10cSrcweir ReformatAll(); 3305cdf0e10cSrcweir } 3306cdf0e10cSrcweir 3307cdf0e10cSrcweir // ----------------------------------------------------------------------- 3308cdf0e10cSrcweir 3309cdf0e10cSrcweir TimeBox::TimeBox( Window* pParent, WinBits nWinStyle ) : 3310cdf0e10cSrcweir ComboBox( pParent, nWinStyle ) 3311cdf0e10cSrcweir { 3312cdf0e10cSrcweir SetField( this ); 3313cdf0e10cSrcweir SetText( ImplGetLocaleDataWrapper().getTime( maFieldTime, sal_False, sal_False ) ); 3314cdf0e10cSrcweir Reformat(); 3315cdf0e10cSrcweir } 3316cdf0e10cSrcweir 3317cdf0e10cSrcweir // ----------------------------------------------------------------------- 3318cdf0e10cSrcweir 3319cdf0e10cSrcweir TimeBox::TimeBox( Window* pParent, const ResId& rResId ) : 3320cdf0e10cSrcweir ComboBox( WINDOW_TIMEBOX ) 3321cdf0e10cSrcweir { 3322cdf0e10cSrcweir rResId.SetRT( RSC_TIMEBOX ); 3323cdf0e10cSrcweir WinBits nStyle = ImplInitRes( rResId ); 3324cdf0e10cSrcweir ComboBox::ImplInit( pParent, nStyle ); 3325cdf0e10cSrcweir SetField( this ); 3326cdf0e10cSrcweir SetText( ImplGetLocaleDataWrapper().getTime( maFieldTime, sal_False, sal_False ) ); 3327cdf0e10cSrcweir ComboBox::ImplLoadRes( rResId ); 3328cdf0e10cSrcweir ResMgr* pMgr = rResId.GetResMgr(); 3329cdf0e10cSrcweir if( pMgr ) 3330cdf0e10cSrcweir TimeFormatter::ImplLoadRes( ResId( (RSHEADER_TYPE *)GetClassRes(), *pMgr ) ); 3331cdf0e10cSrcweir Reformat(); 3332cdf0e10cSrcweir 3333cdf0e10cSrcweir if ( !(nStyle & WB_HIDE) ) 3334cdf0e10cSrcweir Show(); 3335cdf0e10cSrcweir } 3336cdf0e10cSrcweir 3337cdf0e10cSrcweir // ----------------------------------------------------------------------- 3338cdf0e10cSrcweir 3339cdf0e10cSrcweir TimeBox::~TimeBox() 3340cdf0e10cSrcweir { 3341cdf0e10cSrcweir } 3342cdf0e10cSrcweir 3343cdf0e10cSrcweir // ----------------------------------------------------------------------- 3344cdf0e10cSrcweir 3345cdf0e10cSrcweir long TimeBox::PreNotify( NotifyEvent& rNEvt ) 3346cdf0e10cSrcweir { 3347cdf0e10cSrcweir if ( (rNEvt.GetType() == EVENT_KEYINPUT) && !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() ) 3348cdf0e10cSrcweir { 3349cdf0e10cSrcweir if ( ImplTimeProcessKeyInput( GetField(), *rNEvt.GetKeyEvent(), IsStrictFormat(), IsDuration(), GetFormat(), ImplGetLocaleDataWrapper() ) ) 3350cdf0e10cSrcweir return 1; 3351cdf0e10cSrcweir } 3352cdf0e10cSrcweir 3353cdf0e10cSrcweir return ComboBox::PreNotify( rNEvt ); 3354cdf0e10cSrcweir } 3355cdf0e10cSrcweir 3356cdf0e10cSrcweir // ----------------------------------------------------------------------- 3357cdf0e10cSrcweir 3358cdf0e10cSrcweir long TimeBox::Notify( NotifyEvent& rNEvt ) 3359cdf0e10cSrcweir { 3360cdf0e10cSrcweir if ( rNEvt.GetType() == EVENT_GETFOCUS ) 3361cdf0e10cSrcweir MarkToBeReformatted( sal_False ); 3362cdf0e10cSrcweir else if ( rNEvt.GetType() == EVENT_LOSEFOCUS ) 3363cdf0e10cSrcweir { 3364cdf0e10cSrcweir if ( MustBeReformatted() && (GetText().Len() || !IsEmptyFieldValueEnabled()) ) 3365cdf0e10cSrcweir Reformat(); 3366cdf0e10cSrcweir } 3367cdf0e10cSrcweir 3368cdf0e10cSrcweir return ComboBox::Notify( rNEvt ); 3369cdf0e10cSrcweir } 3370cdf0e10cSrcweir 3371cdf0e10cSrcweir // ----------------------------------------------------------------------- 3372cdf0e10cSrcweir 3373cdf0e10cSrcweir void TimeBox::DataChanged( const DataChangedEvent& rDCEvt ) 3374cdf0e10cSrcweir { 3375cdf0e10cSrcweir ComboBox::DataChanged( rDCEvt ); 3376cdf0e10cSrcweir 3377cdf0e10cSrcweir if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_LOCALE) ) 3378cdf0e10cSrcweir { 3379cdf0e10cSrcweir if ( IsDefaultLocale() ) 3380cdf0e10cSrcweir ImplGetLocaleDataWrapper().setLocale( GetSettings().GetLocale() ); 3381cdf0e10cSrcweir ReformatAll(); 3382cdf0e10cSrcweir } 3383cdf0e10cSrcweir } 3384cdf0e10cSrcweir 3385cdf0e10cSrcweir // ----------------------------------------------------------------------- 3386cdf0e10cSrcweir 3387cdf0e10cSrcweir void TimeBox::Modify() 3388cdf0e10cSrcweir { 3389cdf0e10cSrcweir MarkToBeReformatted( sal_True ); 3390cdf0e10cSrcweir ComboBox::Modify(); 3391cdf0e10cSrcweir } 3392cdf0e10cSrcweir 3393cdf0e10cSrcweir // ----------------------------------------------------------------------- 3394cdf0e10cSrcweir 3395cdf0e10cSrcweir void TimeBox::ReformatAll() 3396cdf0e10cSrcweir { 3397cdf0e10cSrcweir XubString aStr; 3398cdf0e10cSrcweir SetUpdateMode( sal_False ); 3399cdf0e10cSrcweir sal_uInt16 nEntryCount = GetEntryCount(); 3400cdf0e10cSrcweir for ( sal_uInt16 i=0; i < nEntryCount; i++ ) 3401cdf0e10cSrcweir { 3402cdf0e10cSrcweir ImplTimeReformat( GetEntry( i ), aStr ); 3403cdf0e10cSrcweir RemoveEntry( i ); 3404cdf0e10cSrcweir InsertEntry( aStr, i ); 3405cdf0e10cSrcweir } 3406cdf0e10cSrcweir TimeFormatter::Reformat(); 3407cdf0e10cSrcweir SetUpdateMode( sal_True ); 3408cdf0e10cSrcweir } 3409cdf0e10cSrcweir 3410cdf0e10cSrcweir // ----------------------------------------------------------------------- 3411cdf0e10cSrcweir 3412cdf0e10cSrcweir void TimeBox::InsertTime( const Time& rTime, sal_uInt16 nPos ) 3413cdf0e10cSrcweir { 3414cdf0e10cSrcweir Time aTime = rTime; 3415cdf0e10cSrcweir if ( aTime > GetMax() ) 3416cdf0e10cSrcweir aTime = GetMax(); 3417cdf0e10cSrcweir else if ( aTime < GetMin() ) 3418cdf0e10cSrcweir aTime = GetMin(); 3419cdf0e10cSrcweir 3420cdf0e10cSrcweir sal_Bool bSec = sal_False; 3421cdf0e10cSrcweir sal_Bool b100Sec = sal_False; 3422cdf0e10cSrcweir if ( GetFormat() == TIMEF_SEC ) 3423cdf0e10cSrcweir bSec = sal_True; 3424cdf0e10cSrcweir if ( GetFormat() == TIMEF_100TH_SEC || GetFormat() == TIMEF_SEC_CS ) 3425cdf0e10cSrcweir bSec = b100Sec = sal_True; 3426cdf0e10cSrcweir ComboBox::InsertEntry( ImplGetLocaleDataWrapper().getTime( aTime, bSec, b100Sec ), nPos ); 3427cdf0e10cSrcweir } 3428cdf0e10cSrcweir 3429cdf0e10cSrcweir // ----------------------------------------------------------------------- 3430cdf0e10cSrcweir 3431cdf0e10cSrcweir void TimeBox::RemoveTime( const Time& rTime ) 3432cdf0e10cSrcweir { 3433cdf0e10cSrcweir sal_Bool bSec = sal_False; 3434cdf0e10cSrcweir sal_Bool b100Sec = sal_False; 3435cdf0e10cSrcweir if ( GetFormat() == TIMEF_SEC ) 3436cdf0e10cSrcweir bSec = sal_True; 3437cdf0e10cSrcweir if ( GetFormat() == TIMEF_100TH_SEC || TIMEF_SEC_CS ) 3438cdf0e10cSrcweir bSec = b100Sec = sal_True; 3439cdf0e10cSrcweir ComboBox::RemoveEntry( ImplGetLocaleDataWrapper().getTime( rTime, bSec, b100Sec ) ); 3440cdf0e10cSrcweir } 3441cdf0e10cSrcweir 3442cdf0e10cSrcweir // ----------------------------------------------------------------------- 3443cdf0e10cSrcweir 3444cdf0e10cSrcweir Time TimeBox::GetTime( sal_uInt16 nPos ) const 3445cdf0e10cSrcweir { 3446cdf0e10cSrcweir Time aTime( 0, 0, 0 ); 3447cdf0e10cSrcweir ImplTimeGetValue( ComboBox::GetEntry( nPos ), aTime, GetFormat(), IsDuration(), ImplGetLocaleDataWrapper() ); 3448cdf0e10cSrcweir return aTime; 3449cdf0e10cSrcweir } 3450cdf0e10cSrcweir 3451cdf0e10cSrcweir // ----------------------------------------------------------------------- 3452cdf0e10cSrcweir 3453cdf0e10cSrcweir sal_uInt16 TimeBox::GetTimePos( const Time& rTime ) const 3454cdf0e10cSrcweir { 3455cdf0e10cSrcweir sal_Bool bSec = sal_False; 3456cdf0e10cSrcweir sal_Bool b100Sec = sal_False; 3457cdf0e10cSrcweir if ( GetFormat() == TIMEF_SEC ) 3458cdf0e10cSrcweir bSec = sal_True; 3459cdf0e10cSrcweir if ( GetFormat() == TIMEF_100TH_SEC || TIMEF_SEC_CS ) 3460cdf0e10cSrcweir bSec = b100Sec = sal_True; 3461cdf0e10cSrcweir return ComboBox::GetEntryPos( ImplGetLocaleDataWrapper().getTime( rTime, bSec, b100Sec ) ); 3462cdf0e10cSrcweir } 3463