voipplugins/accountcreationplugin/src/acpproviderspecificcontainer.cpp
branchRCL_3
changeset 22 d38647835c2e
parent 0 a4daefaec16c
equal deleted inserted replaced
21:f742655b05bf 22:d38647835c2e
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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:  Implements CAcpProviderSpecificContainer methods
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <aknlists.h>
       
    20 #include <StringLoader.h>
       
    21 #include <accountcreationplugin.rsg>
       
    22 // SKIN: includes
       
    23 #include <AknsDrawUtils.h>
       
    24 #include <AknsBasicBackgroundControlContext.h>
       
    25 #include <gdi.h>
       
    26 
       
    27 #include "acpproviderspecificcontainer.h"
       
    28 #include "accountcreationpluginlogger.h"
       
    29 #include "accountcreationpluginconstants.h"
       
    30 #include "acpcontroller.h"
       
    31 
       
    32 const TInt KComponentControlCount = 6;
       
    33 const TInt KScrollMin = -200;
       
    34 const TInt KScrollMax = 10;
       
    35 const TInt KEight = 8;
       
    36 const TInt KPositionX = 10;
       
    37 const TInt KScrollSpeed = 10;
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // CAcpProviderSpecificContainer::CAcpProviderSpecificContainer
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 CAcpProviderSpecificContainer::CAcpProviderSpecificContainer( 
       
    44     CAcpController& aController )
       
    45     : iController( aController ), iScrollY( KScrollMax )
       
    46     {
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // CAcpProviderSpecificContainer::ConstructL
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 void CAcpProviderSpecificContainer::ConstructL( const TRect& aRect )
       
    54     {
       
    55     ACPLOG( "CAcpProviderSpecificContainer::ConstructL begin" );
       
    56 
       
    57     CreateWindowL();
       
    58 
       
    59     // Skin background.
       
    60     //SKIN: create the skin context for our control
       
    61     iBgContext = CAknsBasicBackgroundControlContext::NewL( 
       
    62         KAknsIIDQsnBgAreaMain, aRect, ETrue );
       
    63 
       
    64     // Provider.
       
    65     TInt index = iController.ActiveIndex();
       
    66     TPtrC providerName = iController.ProviderNameFromIndexL( index );
       
    67     TPtrC providerType = iController.ProviderTypeFromIndexL( index );
       
    68     TPtrC providerDescription = 
       
    69         iController.ProviderDescriptionFromIndexL( index );
       
    70     
       
    71     // Name label.
       
    72     iLabel = new (ELeave) CEikLabel;
       
    73     iLabel->SetContainerWindowL( *this );
       
    74     HBufC* typeText;
       
    75     typeText = StringLoader::LoadLC( R_SERVTAB_CD_DETAIL_NAME );
       
    76     iLabel->SetTextL( *typeText );
       
    77     CleanupStack::PopAndDestroy( typeText );
       
    78 
       
    79     // Type label.
       
    80     iLabel2 = new (ELeave) CEikLabel;
       
    81     iLabel2->SetContainerWindowL( *this );
       
    82     HBufC* typeText2;
       
    83     typeText2 = StringLoader::LoadLC( R_SERVTAB_CD_DETAIL_TYPE );
       
    84     iLabel2->SetTextL( *typeText2 );
       
    85     CleanupStack::PopAndDestroy( typeText2 );
       
    86 
       
    87     // Description label
       
    88     iLabel3 = new (ELeave) CEikLabel;
       
    89     iLabel3->SetContainerWindowL( *this );
       
    90     HBufC* typeText3;
       
    91     typeText3 = StringLoader::LoadLC( R_SERVTAB_CD_DETAIL_DESCRIPTION );
       
    92     iLabel3->SetTextL( *typeText3 );
       
    93     CleanupStack::PopAndDestroy( typeText3 ); 
       
    94 
       
    95     // Edwin for name.
       
    96     TResourceReader reader; 
       
    97     iCoeEnv->CreateResourceReaderLC( reader, R_ACP_TYPE );
       
    98     iEdwin = new (ELeave) CEikEdwin;
       
    99     iEdwin->SetContainerWindowL( *this );
       
   100     iEdwin->ConstructFromResourceL( reader );       
       
   101     CleanupStack::PopAndDestroy();
       
   102     if ( !providerName.Length() )
       
   103     	{
       
   104     	HBufC* typeText6;
       
   105         typeText6 = StringLoader::LoadLC( R_SERVTAB_CD_VALUE_UNDEFINED );
       
   106         iEdwin->SetTextL( typeText6 );
       
   107         CleanupStack::PopAndDestroy( typeText6 );
       
   108     	}
       
   109     else
       
   110         {
       
   111     	iEdwin->SetTextL( &providerName );
       
   112         }
       
   113 
       
   114     // Edwin for type.
       
   115     TResourceReader reader2; 
       
   116     iCoeEnv->CreateResourceReaderLC( reader2, R_ACP_TYPE );
       
   117     iEdwin2 = new (ELeave) CEikEdwin;
       
   118     iEdwin2->SetContainerWindowL( *this );
       
   119     iEdwin2->ConstructFromResourceL( reader2 );       
       
   120     CleanupStack::PopAndDestroy();
       
   121     if ( !providerType.Length() )
       
   122     	{
       
   123     	HBufC* typeText7;
       
   124         typeText7 = StringLoader::LoadLC( R_SERVTAB_CD_VALUE_UNDEFINED );
       
   125         iEdwin2->SetTextL( typeText7 );
       
   126         CleanupStack::PopAndDestroy( typeText7 );
       
   127     	}
       
   128     else
       
   129         {
       
   130     	iEdwin2->SetTextL( &providerType );
       
   131         }
       
   132 
       
   133     // Edwin for description.
       
   134     TResourceReader reader3; 
       
   135     iCoeEnv->CreateResourceReaderLC( reader3, R_ACP_TYPE );
       
   136     iEdwin3 = new (ELeave) CEikEdwin;
       
   137     iEdwin3->SetContainerWindowL( *this );
       
   138     iEdwin3->ConstructFromResourceL( reader3 );       
       
   139     CleanupStack::PopAndDestroy();
       
   140     if ( !providerDescription.Length() )
       
   141     	{
       
   142     	HBufC* typeText8;
       
   143         typeText8 = StringLoader::LoadLC( R_SERVTAB_CD_VALUE_UNDEFINED );
       
   144         iEdwin3->SetTextL( typeText8 );
       
   145         CleanupStack::PopAndDestroy( typeText8 );
       
   146     	}
       
   147     else
       
   148         {
       
   149     	iEdwin3->SetTextL( &providerDescription );
       
   150         }
       
   151     
       
   152     // Get label colours from skin.
       
   153     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   154     TRgb color( 0, 0, 0 );
       
   155     
       
   156     AknsUtils::GetCachedColor( skin, color, KAknsIIDQsnTextColors,
       
   157         EAknsCIQsnTextColorsCG6 );
       
   158     iLabel->OverrideColorL( EColorLabelText, color );
       
   159     iLabel->SetEmphasis( CEikLabel::ENoEmphasis );
       
   160     iLabel2->OverrideColorL(EColorLabelText, color );
       
   161     iLabel2->SetEmphasis( CEikLabel::ENoEmphasis );
       
   162     iLabel3->OverrideColorL(EColorLabelText, color );
       
   163     iLabel3->SetEmphasis( CEikLabel::ENoEmphasis );
       
   164     
       
   165     CCharFormatLayer* formatLayer = CEikonEnv::NewDefaultCharFormatLayerL();
       
   166     CleanupStack::PushL( formatLayer );
       
   167     
       
   168     TCharFormat format;
       
   169     TCharFormatMask formatMask;
       
   170     formatLayer->Sense( format, formatMask );
       
   171     format.iFontPresentation.iTextColor = color;
       
   172     formatMask.SetAttrib( EAttColor );
       
   173     formatLayer->SetL( format, formatMask );
       
   174     
       
   175     iEdwin->SetCharFormatLayer( formatLayer->CloneL() );
       
   176     iEdwin2->SetCharFormatLayer( formatLayer->CloneL() );
       
   177     
       
   178     CleanupStack::Pop( formatLayer );
       
   179     iEdwin3->SetCharFormatLayer( formatLayer );
       
   180         
       
   181     SetRect( aRect );
       
   182     ActivateL();
       
   183 
       
   184     ACPLOG( "CAcpProviderSpecificContainer::ConstructL end" );
       
   185     }
       
   186 
       
   187 // ---------------------------------------------------------------------------
       
   188 // CAcpProviderSpecificContainer::NewL
       
   189 // ---------------------------------------------------------------------------
       
   190 //      
       
   191 CAcpProviderSpecificContainer* CAcpProviderSpecificContainer::NewL( 
       
   192     CAcpController& aController,
       
   193     const TRect& aRect )
       
   194     {    
       
   195     CAcpProviderSpecificContainer* self = 
       
   196         CAcpProviderSpecificContainer::NewLC( aController, aRect );
       
   197     CleanupStack::Pop( self );
       
   198     return self;
       
   199     }
       
   200 
       
   201 // ---------------------------------------------------------------------------
       
   202 // CAcpProviderSpecificContainer::NewLC
       
   203 // ---------------------------------------------------------------------------
       
   204 //
       
   205 CAcpProviderSpecificContainer* CAcpProviderSpecificContainer::NewLC(
       
   206     CAcpController& aController,
       
   207     const TRect& aRect )
       
   208     {    
       
   209     CAcpProviderSpecificContainer* self = 
       
   210         new ( ELeave ) CAcpProviderSpecificContainer( aController );
       
   211     CleanupStack::PushL( self );
       
   212     self->ConstructL( aRect );
       
   213     return self;
       
   214     }
       
   215 
       
   216 // ---------------------------------------------------------------------------
       
   217 // CAcpProviderSpecificContainer::~CAcpProviderSpecificContainer
       
   218 // ---------------------------------------------------------------------------
       
   219 //
       
   220 CAcpProviderSpecificContainer::~CAcpProviderSpecificContainer()
       
   221     {
       
   222     ACPLOG( 
       
   223       "CAcpProviderSpecificContainer::~CAcpProviderSpecificContainer begin" );
       
   224 
       
   225     delete iLabel;
       
   226     delete iLabel2;
       
   227     delete iLabel3;
       
   228     delete iEdwin;
       
   229     delete iEdwin2;    
       
   230     delete iEdwin3;
       
   231     delete iBgContext;
       
   232 
       
   233     ACPLOG( 
       
   234         "CAcpProviderSpecificContainer::~CAcpProviderSpecificContainer end" );
       
   235     }
       
   236 
       
   237 // ---------------------------------------------------------------------------
       
   238 // CAcpProviderSpecificContainer::ComponentControl
       
   239 // From class CoeControl.
       
   240 // ---------------------------------------------------------------------------
       
   241 //
       
   242 CCoeControl* CAcpProviderSpecificContainer::ComponentControl( 
       
   243     TInt aIndex ) const
       
   244     {
       
   245     const TInt KZeroCase  = 0;
       
   246     const TInt KOneCase   = 1;
       
   247     const TInt KTwoCase   = 2;
       
   248     const TInt KThreeCase = 3;
       
   249     const TInt KFourCase  = 4;
       
   250     const TInt KFiveCase  = 5;
       
   251 
       
   252     switch ( aIndex )
       
   253         {
       
   254             case KZeroCase:
       
   255                 return iLabel;
       
   256             case KOneCase:
       
   257                 return iLabel2;
       
   258     		case KTwoCase:
       
   259     			return iLabel3;
       
   260     		case KThreeCase:
       
   261     			return iEdwin;
       
   262     		case KFourCase:
       
   263     			return iEdwin2;	
       
   264     		case KFiveCase: 
       
   265     			return iEdwin3;
       
   266             default:
       
   267                 return NULL;
       
   268         }
       
   269     }
       
   270 
       
   271 // ---------------------------------------------------------------------------
       
   272 // CAcpProviderSpecificContainer::MopSupplyObject
       
   273 // From class CCoeControl.
       
   274 // SKIN: pass context to child controls.
       
   275 // ---------------------------------------------------------------------------
       
   276 //
       
   277 TTypeUid::Ptr CAcpProviderSpecificContainer::MopSupplyObject( TTypeUid aId )
       
   278     {
       
   279     if ( iBgContext )
       
   280         {
       
   281         return MAknsControlContext::SupplyMopObject( aId, iBgContext );
       
   282         }
       
   283     return CCoeControl::MopSupplyObject( aId );
       
   284     }
       
   285 
       
   286 // ---------------------------------------------------------------------------
       
   287 // CAcpProviderSpecificContainer::Draw
       
   288 // From class CoeControl.
       
   289 // ---------------------------------------------------------------------------
       
   290 //
       
   291 void CAcpProviderSpecificContainer::Draw( const TRect& aRect ) const
       
   292     {
       
   293     // Get the standard graphics context.
       
   294     CWindowGc& gc = SystemGc();
       
   295 
       
   296     // Draw skin backgound.
       
   297     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   298   	MAknsControlContext* cc = AknsDrawUtils::ControlContext( this );
       
   299     AknsDrawUtils::Background( skin, cc, this, gc, aRect );
       
   300     }
       
   301 
       
   302 // ---------------------------------------------------------------------------
       
   303 // CAcpProviderSpecificContainer::CountComponentControls
       
   304 // From class CoeControl.
       
   305 // ---------------------------------------------------------------------------
       
   306 //
       
   307 TInt CAcpProviderSpecificContainer::CountComponentControls() const
       
   308     {
       
   309     return KComponentControlCount;
       
   310     }
       
   311 
       
   312 // ---------------------------------------------------------------------------
       
   313 // CAcpProviderSpecificContainer::SizeChanged
       
   314 // From class CoeControl.
       
   315 // ---------------------------------------------------------------------------
       
   316 //
       
   317 void CAcpProviderSpecificContainer::SizeChanged()
       
   318     {
       
   319     RepositionLabels();
       
   320 
       
   321     // Redraw the control.
       
   322     DrawDeferred();
       
   323     }
       
   324 
       
   325 // ---------------------------------------------------------------------------
       
   326 // CAcpProviderSpecificContainer::HandleResourceChange
       
   327 // From class CCoeControl.
       
   328 // Called by framework when layout is changed.
       
   329 // ---------------------------------------------------------------------------
       
   330 //
       
   331 void CAcpProviderSpecificContainer::HandleResourceChange( TInt aType )
       
   332     {
       
   333     CCoeControl::HandleResourceChange( aType );
       
   334 
       
   335     // *****************************
       
   336     // ADDED FOR SCALABLE UI SUPPORT
       
   337     // *****************************
       
   338     if ( KEikDynamicLayoutVariantSwitch == aType )
       
   339         {
       
   340         TRect rect;
       
   341         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, rect );
       
   342         SetRect( rect );
       
   343         iBgContext->SetRect( rect );
       
   344         }
       
   345     }
       
   346 
       
   347 // ---------------------------------------------------------------------------
       
   348 // CAcpProviderSpecificContainer::ScrollText
       
   349 // Scrolls text labels up or down.
       
   350 // ---------------------------------------------------------------------------
       
   351 //
       
   352 void CAcpProviderSpecificContainer::ScrollText( TInt aDelta )
       
   353     {
       
   354     ACPLOG( "CAcpProviderSpecificContainer::ScrollText begin" );
       
   355     
       
   356     iScrollY += aDelta;
       
   357     if ( iScrollY > KScrollMax ) 
       
   358         {
       
   359         iScrollY = KScrollMax;
       
   360         }
       
   361     else if ( iScrollY < KScrollMin )
       
   362         {
       
   363         iScrollY = KScrollMin;
       
   364         }
       
   365     
       
   366     RepositionLabels();
       
   367     
       
   368     // Redraw the control.
       
   369     DrawDeferred();
       
   370     
       
   371     ACPLOG( "CAcpProviderSpecificContainer::ScrollText end" );
       
   372     }
       
   373 
       
   374 // ---------------------------------------------------------------------------
       
   375 // CAcpProviderSpecificContainer::RepositionLabels
       
   376 // ---------------------------------------------------------------------------
       
   377 //
       
   378 void CAcpProviderSpecificContainer::RepositionLabels()
       
   379     {
       
   380     const TInt KWidthX = Rect().Width() - KPositionX;
       
   381     const TInt KDeltaY = Rect().Height() / KEight;
       
   382     
       
   383     TInt yPos = iScrollY;
       
   384     iLabel->SetExtent( TPoint( KPositionX, yPos ), 
       
   385         TSize( KWidthX, KDeltaY ) );
       
   386     yPos += KDeltaY;
       
   387 
       
   388     iEdwin->SetExtent( TPoint( KPositionX, yPos ), 
       
   389         TSize( KWidthX, KDeltaY ) );
       
   390     yPos += KDeltaY;
       
   391 
       
   392     iLabel2->SetExtent( TPoint( KPositionX, yPos ), 
       
   393         TSize( KWidthX, KDeltaY ) );
       
   394     yPos += KDeltaY;
       
   395 
       
   396     iEdwin2->SetExtent( TPoint( KPositionX, yPos ), 
       
   397         TSize( KWidthX, KDeltaY ) );
       
   398     yPos += KDeltaY;
       
   399 
       
   400     iLabel3->SetExtent( TPoint( KPositionX, yPos ), 
       
   401         TSize( KWidthX, KDeltaY ) );
       
   402     yPos += KDeltaY;
       
   403 
       
   404     iEdwin3->SetExtent( TPoint( KPositionX, yPos ), 
       
   405         TSize( KWidthX, Rect().Height() ) );
       
   406     }
       
   407 
       
   408 // ---------------------------------------------------------------------------
       
   409 // CAcpProviderSpecificContainer::OfferKeyEventL
       
   410 // Handles key events.
       
   411 // ---------------------------------------------------------------------------
       
   412 //
       
   413 TKeyResponse CAcpProviderSpecificContainer::OfferKeyEventL(
       
   414     const TKeyEvent& aKeyEvent, TEventCode aType )
       
   415     {
       
   416     ACPLOG( "CAcpProviderSpecificContainer::OfferKeyEventL begin" );
       
   417     
       
   418     TKeyResponse ret = EKeyWasNotConsumed;
       
   419     
       
   420     switch ( aKeyEvent.iScanCode )
       
   421         {
       
   422         case EStdKeyUpArrow:
       
   423             if ( aType != EEventKeyUp )
       
   424                 {
       
   425                 ScrollText( KScrollSpeed );
       
   426                 ret = EKeyWasConsumed;
       
   427                 }
       
   428             break;
       
   429             
       
   430         case EStdKeyDownArrow:
       
   431             if ( aType != EEventKeyUp )
       
   432                 {
       
   433                 ScrollText( -KScrollSpeed );
       
   434                 ret = EKeyWasConsumed;
       
   435                 }
       
   436             break;
       
   437             
       
   438         default:
       
   439             break;
       
   440         }
       
   441     
       
   442     ACPLOG( "CAcpProviderSpecificContainer::OfferKeyEventL end" );
       
   443     return ret;
       
   444     }
       
   445 
       
   446 
       
   447 // End of file.