phoneuis/Ussd/src/UssdContainer.cpp
branchRCL_3
changeset 62 5266b1f337bd
equal deleted inserted replaced
61:41a7f70b3818 62:5266b1f337bd
       
     1 /*
       
     2 * Copyright (c) 2002-2010 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: 
       
    15 *             Declares container control for application.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include    <ussd.rsg>
       
    23 #include    <aknkeys.h>
       
    24 #include    <eikedwin.h>
       
    25 #include    <bldvariant.hrh>
       
    26 #include    <featmgr.h>
       
    27 #include    <centralrepository.h>
       
    28 #include    <telinternalcrkeys.h>
       
    29 #include <csxhelp/ussd.hlp.hrh>  // for help context
       
    30 
       
    31 // For skinning.
       
    32 #include    <AknsBasicBackgroundControlContext.h>
       
    33 #include    <AknsDrawUtils.h>
       
    34 #include    <AknsUtils.h>
       
    35 #include    <txtglobl.h>
       
    36 
       
    37 #include    "telephonyvariant.hrh"
       
    38 #include    "UssdComms.h"
       
    39 #include    "UssdNaviPane.h"
       
    40 #include    "UssdAppUi.h"
       
    41 #include    "UssdContainer.h"
       
    42 #include    "UssdEditorLines.h"
       
    43 #include    "UssdLayout.h"
       
    44 #include    "ussd.hrh"
       
    45 #include    "UssdApp.h" // for applicationUID
       
    46 #include    "UssdLogger.h"
       
    47 
       
    48 // ============================ MEMBER FUNCTIONS ===============================
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CUssdContainer::CUssdContainer
       
    52 // C++ constructor can NOT contain any code, that
       
    53 // might leave.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CUssdContainer::CUssdContainer( CUssdAppUi& aAppUi ): iAppUi( aAppUi )
       
    57     {
       
    58     }
       
    59 
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CUssdContainer::ConstructL
       
    63 // Symbian 2nd phase constructor can leave.
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 void CUssdContainer::ConstructL( const TRect& aRect )
       
    67     {
       
    68     _LOGSTRING( "CUssdContainer::ConstructL =>" )
       
    69     CreateWindowL();
       
    70 
       
    71     // Create background control context for skins.
       
    72     iBgContext = CAknsBasicBackgroundControlContext::NewL(
       
    73         KAknsIIDQsnBgAreaMainMessage, aRect, ETrue /*Parent absolute*/ );
       
    74 
       
    75     // Create editor
       
    76     iEditor = CreateEdwinL();
       
    77 
       
    78     // Lines
       
    79     iLines = new ( ELeave ) CUssdEditorLines;
       
    80     iLines->ConstructL( this );
       
    81 
       
    82     TInt featureBitmask( 0 );
       
    83 
       
    84     // Connecting and initialization KCRUidTelVariation
       
    85     CRepository* repository = CRepository::NewL( KCRUidTelVariation );
       
    86     CleanupStack::PushL( repository );
       
    87 
       
    88     // Get the value from Central Repository
       
    89     repository->Get( KTelVariationFlags, featureBitmask );
       
    90     if ( featureBitmask & KTelephonyLVFlagUssdUIRemainingChars )
       
    91         {
       
    92         iNaviPaneHandler = CUssdNaviPane::NewL( iAppUi );
       
    93         }
       
    94 
       
    95     CleanupStack::PopAndDestroy( repository );
       
    96 
       
    97     // Finish the job
       
    98     SetRect( aRect );
       
    99     ActivateL();
       
   100 
       
   101     iEditor->SetFocus( ETrue );
       
   102     _LOGSTRING( "CUssdContainer::ConstructL <=" )
       
   103     }
       
   104 
       
   105 
       
   106 // Destructor
       
   107 CUssdContainer::~CUssdContainer()
       
   108     {
       
   109     _LOGSTRING( "CUssdContainer::~CUssdContainer =>" ) 
       
   110     delete iLines;
       
   111 
       
   112     AknsUtils::DeregisterControlPosition( iEditor );
       
   113     delete iEditor;
       
   114     delete iNaviPaneHandler;
       
   115 
       
   116     delete iBgContext; // For skinning, can be deleted, NULL if not exist.
       
   117     _LOGSTRING( "CUssdContainer::~CUssdContainer <=" )
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CUssdContainer::HandleEdwinEventL
       
   122 // Called by framework when the Editor is changed
       
   123 //
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 void CUssdContainer::HandleEdwinEventL( CEikEdwin* /*aEdwin*/,
       
   127         TEdwinEvent aEventType )
       
   128     {
       
   129      switch( aEventType )
       
   130          {
       
   131          case EEventTextUpdate:
       
   132              {
       
   133              UpdateNavipaneMsgLengthL();
       
   134              break;
       
   135              }
       
   136          default:
       
   137              break;
       
   138          }
       
   139     }
       
   140     
       
   141 // -----------------------------------------------------------------------------
       
   142 // CUssdContainer::SizeChanged
       
   143 // Called by framework when the view size is changed
       
   144 //
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 void CUssdContainer::SizeChanged()
       
   148     {
       
   149     // Backgroud context
       
   150     iBgContext->SetParentPos( PositionRelativeToScreen() );
       
   151     iBgContext->SetRect( Rect() ) ;
       
   152     // Edwin
       
   153     AknLayoutUtils::LayoutEdwin(
       
   154         iEditor,
       
   155         Rect(),
       
   156         UssdLayout::MessageWritingTexts3() );
       
   157 
       
   158     // We need to make some room for scrollbar to fit
       
   159     // so the editor must be narrowed down a bit.
       
   160 
       
   161     TAknLayoutId layout = UssdLayout::CurrentLayout();
       
   162     TRect sbr = iEditor->ScrollBarFrame()->VerticalScrollBar()->Rect();
       
   163 
       
   164     if( layout != EAknLayoutIdABRW )
       
   165         {
       
   166         TPoint editorTLPoint(Rect().iTl.iX, iEditor->Rect().iTl.iY);
       
   167 
       
   168         iEditor->SetExtent( editorTLPoint ,
       
   169                     TSize( Rect().Width() - sbr.Width(), sbr.Height() ) );
       
   170         }
       
   171     else // right to left layout
       
   172         {
       
   173         TPoint editorTLPoint( ( Rect().iTl.iX + sbr.Width() ),
       
   174                                 iEditor->Rect().iTl.iY);
       
   175 
       
   176         iEditor->SetExtent( editorTLPoint ,
       
   177                             TSize( Rect().Width() - sbr.Width(),
       
   178                             sbr.Height() ) );
       
   179         }
       
   180 
       
   181     TRAP_IGNORE( UpdateNavipaneMsgLengthL() );
       
   182 
       
   183     // overwite inputmode in portraitmode
       
   184     if ( Rect().Height() > Rect().Width() )
       
   185         {
       
   186         iEditor->SetAknEditorCurrentInputMode( EAknEditorNumericInputMode );
       
   187         }
       
   188 
       
   189     // Change the colour of the edwin if needed
       
   190     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   191     if ( skin )
       
   192         {
       
   193         TRgb color;
       
   194         TInt error = AknsUtils::GetCachedColor(
       
   195             skin,
       
   196             color,
       
   197             KAknsIIDQsnTextColors,
       
   198             EAknsCIQsnTextColorsCG6 );
       
   199 
       
   200         if ( error == KErrNone )
       
   201             {
       
   202             TCharFormat charFormat;
       
   203             TCharFormatMask charFormatMask;
       
   204             ( reinterpret_cast< CGlobalText* >( iEditor->Text() ) )
       
   205                 ->GetCharFormat( charFormat, charFormatMask, 0, 0 );
       
   206 
       
   207             charFormat.iFontPresentation.iTextColor = color;
       
   208             charFormatMask.SetAll();
       
   209 
       
   210             CCharFormatLayer* charFormatLayer = NULL;
       
   211 
       
   212             TRAP( error, charFormatLayer =
       
   213                 CCharFormatLayer::NewL( charFormat,charFormatMask ) );
       
   214 
       
   215             if ( !error )
       
   216                 {
       
   217                 iEditor->SetCharFormatLayer( charFormatLayer );
       
   218                 }
       
   219             }
       
   220         }
       
   221 
       
   222     // Set editor lines
       
   223     iLines->SetRect( Rect() );
       
   224 
       
   225     AknsUtils::RegisterControlPosition( iEditor );
       
   226     }
       
   227 
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // CUssdContainer::CountComponentControls
       
   231 //
       
   232 //
       
   233 // -----------------------------------------------------------------------------
       
   234 //
       
   235 TInt CUssdContainer::CountComponentControls() const
       
   236     {
       
   237     return 2; // editor and lines
       
   238     }
       
   239 
       
   240 
       
   241 // -----------------------------------------------------------------------------
       
   242 // CUssdContainer::ComponentControl
       
   243 //
       
   244 // -----------------------------------------------------------------------------
       
   245 //
       
   246 CCoeControl* CUssdContainer::ComponentControl( TInt aIndex ) const
       
   247     {
       
   248     switch ( aIndex )
       
   249         {
       
   250         case 0:
       
   251             return iEditor;
       
   252         case 1:
       
   253             return iLines;
       
   254         default:
       
   255             return NULL;
       
   256         }
       
   257 
       
   258     }
       
   259 
       
   260 
       
   261 // -----------------------------------------------------------------------------
       
   262 // CUssdContainer::Draw
       
   263 //
       
   264 // -----------------------------------------------------------------------------
       
   265 //
       
   266 void CUssdContainer::Draw( const TRect& aRect ) const
       
   267     {
       
   268     CWindowGc& gc = SystemGc();
       
   269 
       
   270     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   271 
       
   272     if ( iBgContext )
       
   273         {
       
   274         AknsDrawUtils::Background(
       
   275             skin, iBgContext, this, gc, aRect);
       
   276         }
       
   277     else
       
   278         {
       
   279         // Otherwise clear the area
       
   280         gc.SetBrushColor( AKN_LAF_COLOR( UssdLayout::LayoutColourWhite() ) );
       
   281         DrawUtils::ClearBetweenRects( gc, aRect, iEditor->Rect() );
       
   282         }
       
   283     }
       
   284 
       
   285 
       
   286 // -----------------------------------------------------------------------------
       
   287 // CUssdContainer::OfferKeyEventL
       
   288 // -----------------------------------------------------------------------------
       
   289 //
       
   290 TKeyResponse CUssdContainer::OfferKeyEventL(
       
   291     const TKeyEvent& aKeyEvent, TEventCode aType )
       
   292     {
       
   293     _LOGSTRING3(
       
   294     "CUssdContainer::OfferKeyEventL =>,TKeyEvent::iCode=%d,TEventCode=%d",
       
   295     aKeyEvent.iCode, aType )
       
   296     TKeyResponse response = EKeyWasNotConsumed;
       
   297 
       
   298     // Special key handling comes first.
       
   299     if ( aKeyEvent.iScanCode == EStdKeyYes ) // Send key.
       
   300         {
       
   301         // The reason that the send key is handled via TStdScanCode rather than TKeyCode is that
       
   302         // we also have to be able to catch EEventKeyUp and EEventKeyDown key events in addition
       
   303         // to EEventKey. This is because TKeyEvent::iCode is always 0 when TEventCode is EEventKey.
       
   304         if ( iEditor->TextLength() )
       
   305             {
       
   306             if ( aType == EEventKey )
       
   307                 {
       
   308                 if ( FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   309                     {
       
   310                     iAppUi.HandleCommandL( EUssdMenuItemSend );
       
   311                     }
       
   312                 else
       
   313                     {
       
   314                     iAppUi.HandleCommandL( EUssdSoftkeySend );
       
   315                     }
       
   316                 }
       
   317             response = EKeyWasConsumed; // Dialer should not be launched when the USSD string exists and send key is used.
       
   318             }
       
   319         }
       
   320     else if ( aKeyEvent.iCode == EKeyEscape )
       
   321         {
       
   322         iAppUi.HandleCommandL( EAknSoftkeyExit );
       
   323         response = EKeyWasConsumed;
       
   324         }
       
   325     else // Default keys are handled here.
       
   326         {
       
   327         response = iEditor->OfferKeyEventL( aKeyEvent, aType );
       
   328 
       
   329         if ( aType == EEventKey || aType == EEventKeyUp )
       
   330             {
       
   331             UpdateNavipaneMsgLengthL();
       
   332             }
       
   333 
       
   334         if ( !FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   335             {
       
   336             // Change softkeys if needed.
       
   337             iAppUi.SetSoftkeySendVisibleL( iEditor->TextLength() != 0 );
       
   338             }
       
   339 
       
   340             iAppUi.Cba()->SetCommandSetL( R_USSD_SOFTKEYS_OPTIONS_EXIT_OPTIONS );
       
   341             iAppUi.Cba()->DrawNow();
       
   342         }
       
   343     _LOGSTRING2(
       
   344     "CUssdContainer::OfferKeyEventL <=, response=%d", response )
       
   345     return response;
       
   346     }
       
   347 
       
   348 
       
   349 // -----------------------------------------------------------------------------
       
   350 // CUssdContainer::Editor
       
   351 // Give editor
       
   352 // -----------------------------------------------------------------------------
       
   353 //
       
   354 CEikEdwin& CUssdContainer::Editor()
       
   355     {
       
   356     return *iEditor;
       
   357     }
       
   358 
       
   359 
       
   360 // -----------------------------------------------------------------------------
       
   361 // CUssdContainer::FocusChanged
       
   362 //
       
   363 // -----------------------------------------------------------------------------
       
   364 //
       
   365 void CUssdContainer::FocusChanged( TDrawNow aDrawNow )
       
   366     {
       
   367     iEditor->SetFocus( IsFocused(), aDrawNow );
       
   368     }
       
   369 
       
   370 
       
   371 
       
   372 // -----------------------------------------------------------------------------
       
   373 // CUssdContainer::GetHelpContext
       
   374 // This function is called when Help application is launched.
       
   375 //
       
   376 // -----------------------------------------------------------------------------
       
   377 //
       
   378 void CUssdContainer::GetHelpContext(
       
   379     TCoeHelpContext& aContext ) const
       
   380     {
       
   381     // If help defined.
       
   382     if ( FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   383         {
       
   384         aContext.iMajor = KUidussd;
       
   385         aContext.iContext = KUSSD_HLP_EDITOR;
       
   386         }
       
   387 
       
   388     // If help not defined, do nothing
       
   389     }
       
   390 
       
   391 
       
   392 
       
   393 // -----------------------------------------------------------------------------
       
   394 // CUssdContainer::HandleResourceChange
       
   395 // This function is called when Help application is launched.
       
   396 //
       
   397 // -----------------------------------------------------------------------------
       
   398 //
       
   399 void CUssdContainer::HandleResourceChange( TInt aType )
       
   400     {
       
   401     switch ( aType )
       
   402         {
       
   403         case KEikColorResourceChange:
       
   404         case KAknsMessageSkinChange:
       
   405             {
       
   406             SizeChanged();
       
   407             DrawDeferred();
       
   408             break;
       
   409             }
       
   410 
       
   411         default:
       
   412             {
       
   413             CCoeControl::HandleResourceChange( aType );
       
   414             }
       
   415         }
       
   416     }
       
   417 
       
   418 
       
   419 // -----------------------------------------------------------------------------
       
   420 // CUssdContainer::MopSupplyObject
       
   421 //
       
   422 // -----------------------------------------------------------------------------
       
   423 //
       
   424 TTypeUid::Ptr CUssdContainer::MopSupplyObject( TTypeUid aId )
       
   425     {
       
   426     if ( aId.iUid == MAknsControlContext::ETypeId )
       
   427         {
       
   428         return MAknsControlContext::SupplyMopObject( aId, iBgContext );
       
   429         }
       
   430     return CCoeControl::MopSupplyObject( aId );
       
   431     }
       
   432 
       
   433 
       
   434 // -----------------------------------------------------------------------------
       
   435 // CUssdContainer::CreateEdwinL
       
   436 // Creates new edwin
       
   437 //
       
   438 // -----------------------------------------------------------------------------
       
   439 //
       
   440 CEikEdwin* CUssdContainer::CreateEdwinL()
       
   441     {
       
   442     CEikEdwin* newEditor = new ( ELeave ) CEikEdwin;
       
   443     CleanupStack::PushL( newEditor );
       
   444     newEditor->SetContainerWindowL( *this );
       
   445     //Set the editor observer
       
   446     newEditor->SetEdwinObserver( this );
       
   447     
       
   448     newEditor->SetAknEditorAllowedInputModes(
       
   449         EAknEditorNumericInputMode | EAknEditorTextInputMode );
       
   450     newEditor->SetAknEditorInputMode( EAknEditorNumericInputMode );
       
   451     newEditor->SetAknEditorNumericKeymap( EAknEditorStandardNumberModeKeymap );
       
   452 
       
   453     TInt editorFlags = EAknEditorFlagNoT9 | EAknEditorFlagEnableScrollBars | 
       
   454         EAknEditorFlagLatinInputModesOnly;
       
   455 
       
   456      if( FeatureManager::FeatureSupported( KFeatureIdPenSupport ) )
       
   457         {
       
   458         editorFlags |= EAknEditorFlagDeliverVirtualKeyEventsToApplication;
       
   459         }
       
   460 
       
   461     newEditor->SetAknEditorFlags( editorFlags );
       
   462 
       
   463     // Get the layout, i.e. variant.
       
   464     EVariantFlag variant = AknLayoutUtils::Variant();
       
   465 
       
   466     // According to layout, construct the editor.
       
   467     if ( variant == EApacVariant )
       
   468         {
       
   469         // APAC variant
       
   470         AknEditUtils::ConstructEditingL( newEditor , R_USSD_EDWIN_EDITOR_APAC );
       
   471         }
       
   472     else
       
   473         {
       
   474         // EEuropeanVariant (includes ABRW)
       
   475         AknEditUtils::ConstructEditingL( newEditor , R_USSD_EDWIN_EDITOR_ELAF );
       
   476         }
       
   477 
       
   478     CleanupStack::Pop( newEditor );
       
   479     return newEditor;
       
   480     }
       
   481 
       
   482 // ---------------------------------------------------------
       
   483 // CUssdContainer::UpdateNavipaneMsgLengthL
       
   484 // ---------------------------------------------------------
       
   485 void CUssdContainer::UpdateNavipaneMsgLengthL()
       
   486     {
       
   487     _LOGSTRING( "CUssdContainer::UpdateNavipaneMsgLengthL =>" )
       
   488 
       
   489     if ( iNaviPaneHandler )
       
   490         {
       
   491 
       
   492         TInt maxLen=0;
       
   493         TBuf<KUssdEditorMaxLenght> inputTexts;
       
   494 
       
   495         iEditor->GetText( inputTexts );
       
   496 
       
   497         maxLen = iNaviPaneHandler->UpdateMsgLengthL( inputTexts, this );
       
   498 
       
   499         // if pasted more than 91 chinese characters then it must be
       
   500         // cutted and set correct message length in navi pane
       
   501         if ( inputTexts.Length() > maxLen )
       
   502             {
       
   503             inputTexts.Copy( inputTexts.Left( maxLen ) );
       
   504             iEditor->SetTextL( &inputTexts );
       
   505             iNaviPaneHandler->UpdateMsgLengthL( inputTexts, this );
       
   506             iEditor->DrawNow();
       
   507             iEditor->SetCursorPosL( maxLen, EFalse );
       
   508             }
       
   509 
       
   510         iEditor->SetMaxLength( maxLen );
       
   511 
       
   512         }
       
   513     _LOGSTRING( "CUssdContainer::UpdateNavipaneMsgLengthL <=" )
       
   514     }
       
   515 
       
   516 // End of File