calendarui/editors/src/CalenDescriptionField.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // system includes
       
    20 #include <AknUtils.h>
       
    21 #include <AknDef.h>
       
    22 
       
    23 // user includes
       
    24 #include "CalenDescriptionField.h"
       
    25 #include "CalenDescription.h"
       
    26 
       
    27 // debug
       
    28 #include "calendarui_debug.h"
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // CCalenDescriptionField::CCalenDescriptionField
       
    34 // C++ constructor can NOT contain any code, that might leave.
       
    35 // (other items were commented in a header).
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 CCalenDescriptionField::CCalenDescriptionField( CCalenDescription& aDescription )
       
    39     : iDescription( aDescription )
       
    40     {
       
    41     TRACE_ENTRY_POINT;
       
    42     TRACE_EXIT_POINT;
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CCalenDescriptionField::~CCalenDescriptionField
       
    47 // Destructor.
       
    48 // (other items were commented in a header).
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 CCalenDescriptionField::~CCalenDescriptionField()
       
    52     {
       
    53     TRACE_ENTRY_POINT;
       
    54     TRACE_EXIT_POINT;
       
    55     }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CCalenDescriptionField::OfferKeyEventL
       
    59 // Handle key events. Could show/edit/remove description.
       
    60 // (other items were commented in a header).
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 TKeyResponse CCalenDescriptionField::OfferKeyEventL( const TKeyEvent& aKeyEvent,
       
    64                                                      TEventCode aType )
       
    65     {
       
    66     TRACE_ENTRY_POINT;
       
    67     
       
    68     TKeyResponse exitCode = EKeyWasNotConsumed;
       
    69     if (aType == EEventKey)
       
    70         {
       
    71         switch( aKeyEvent.iCode )
       
    72             {
       
    73             case EKeyOK:
       
    74                 {
       
    75                 iDescription.ShowL();
       
    76                 exitCode = EKeyWasConsumed;
       
    77                 }
       
    78                 break;
       
    79            	case EKeyEnter:
       
    80            	    {
       
    81                 iDescription.ShowL(); // Open notepad to edit description
       
    82                 exitCode = EKeyWasConsumed;
       
    83            	    }
       
    84                 break;            
       
    85             case EKeyBackspace:
       
    86                 {
       
    87                 iDescription.RemoveL();
       
    88                 exitCode = EKeyWasConsumed;
       
    89                 }
       
    90                 break;
       
    91             default:
       
    92                 break;
       
    93             }
       
    94         }
       
    95     else if( aType == EEventKeyDown )
       
    96         {
       
    97         TInt code = aKeyEvent.iScanCode;
       
    98         if ( ('0' <= code && code <= '9') || // digit keys 
       
    99              ('A' <= code && code <= 'Z') ) // character keys
       
   100             {
       
   101             // calls modal dialog, for which key is posted
       
   102             iDescription.EditL(); 
       
   103             exitCode = EKeyWasConsumed;
       
   104             }
       
   105         }
       
   106     else
       
   107         {
       
   108         // do nothing
       
   109         }
       
   110 
       
   111     if( exitCode != EKeyWasConsumed )
       
   112         {
       
   113         exitCode = CEikEdwin::OfferKeyEventL( aKeyEvent, aType );
       
   114         }
       
   115 
       
   116     TRACE_EXIT_POINT;
       
   117     return exitCode;
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CCalenDescriptionField::SetTextL
       
   122 // Sets the given text to the description field.
       
   123 // (other items were commented in a header).
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 void CCalenDescriptionField::SetTextL( const TDesC* aData ) 
       
   127     {
       
   128     TRACE_ENTRY_POINT;
       
   129 
       
   130     // Shorten data  and take max length of head of text, 
       
   131     // otherwise edwin takes tail of text. 
       
   132     CTextLayout* layout = const_cast<CTextLayout *>( iTextView->Layout() );
       
   133 
       
   134     if ( !layout->Truncating() )
       
   135         {
       
   136         layout->SetTruncating( TRUE );
       
   137         }
       
   138 
       
   139     TInt maxLen = iTextLimit;
       
   140     HBufC* stripBuf = HBufC::NewLC( maxLen );
       
   141     TPtr stripPtr = stripBuf->Des();
       
   142     stripPtr.Append( aData->Left( maxLen ) );
       
   143     // Replace some common unicode control characters with spaces
       
   144     // as Edwin can't show them correctly. 
       
   145     // - normal ASCII line break (\n) 
       
   146     // - normal ASCII tab (\t)
       
   147     // - paragraph separator (0x2029)
       
   148     // - line break (0x2028)
       
   149     _LIT( KParagraphCharacter, "\n\t\x2029\x2028" );
       
   150     TChar space(' ');
       
   151     AknTextUtils::ReplaceCharacters( stripPtr, KParagraphCharacter, space );
       
   152     CEikEdwin::SetTextL( stripBuf );
       
   153     CleanupStack::PopAndDestroy( stripBuf );
       
   154 
       
   155     TRACE_EXIT_POINT;
       
   156     }
       
   157 
       
   158 //  End of File