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