LCOV - code coverage report
Current view: top level - vcl/source/control - field2.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 790 1566 50.4 %
Date: 2012-08-25 Functions: 94 142 66.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 676 2411 28.0 %

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

Generated by: LCOV version 1.10