textinput/peninputhwrtrui/src/truiinfomessagecontainer.cpp
changeset 27 694fa80c203c
parent 24 fc42a86c98e3
child 35 0f326f2e628e
equal deleted inserted replaced
24:fc42a86c98e3 27:694fa80c203c
     1 /*
       
     2 * Copyright (c) 2007 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:  Implement of class CTruiInfoMessageContainer
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <eikenv.h>
       
    20 #include <AknsBasicBackgroundControlContext.h>
       
    21 #include <AknsDrawUtils.h>
       
    22 #include <trui.rsg>
       
    23 #include <eiklabel.h>
       
    24 #include <eikon.hrh>
       
    25 #include <AknUtils.h>
       
    26 #include <aknlayoutscalable_apps.cdl.h>
       
    27 #include <layoutmetadata.cdl.h>
       
    28 #include <eikedwin.h>
       
    29 
       
    30 #include "truiinfomessagecontainer.h"
       
    31 #include "truiappradiobutton.h"
       
    32 #include "truiappui.h"
       
    33 #include "truiengine.h"
       
    34 #include "truicontainerbase.h"
       
    35 
       
    36 // Varity of instruct pane both for landscape and portrait
       
    37 const TInt KVarityInstructPane = 4;
       
    38 
       
    39 // Varity of list pane both for landscape and portrait
       
    40 const TInt KVarityListPane = 2;
       
    41 
       
    42 // Varity of symbol option pane both for landscape and portrait
       
    43 const TInt KVaritySymbolOptionPane = 2;
       
    44 
       
    45 // Varity of list symbol option pane both for landscape and portrait
       
    46 const TInt KVarityListSymbolOptionPane = 1;
       
    47 
       
    48 
       
    49 // ======== MEMBER FUNCTIONS ========
       
    50 
       
    51 CTruiInfoMessageContainer::CTruiInfoMessageContainer()
       
    52     {  
       
    53     }
       
    54     
       
    55 void CTruiInfoMessageContainer::ConstructL( const TRect& aRect )
       
    56     {    
       
    57     // Initialize control array
       
    58     InitComponentArrayL();
       
    59         
       
    60     // Set parent control or owning window
       
    61     CreateWindowL();       
       
    62 
       
    63     // Initialize controls
       
    64     InitializeControlsL();
       
    65 
       
    66     iLabelText = iEikonEnv->AllocReadResourceL( R_TRUI_INFOMAESSAGEVIEW_MESSAGE );
       
    67     iEdwin->SetTextL( iLabelText );    
       
    68 
       
    69     SetRect( aRect );
       
    70     ActivateL();   
       
    71     
       
    72     iBackGround = CAknsBasicBackgroundControlContext::NewL
       
    73                   ( KAknsIIDQsnBgAreaMain, Rect(), EFalse);
       
    74     iEdwin->SetSkinBackgroundControlContextL( iBackGround );
       
    75     }        
       
    76     
       
    77 CTruiInfoMessageContainer* CTruiInfoMessageContainer::NewL( const TRect& aRect )
       
    78     {
       
    79     CTruiInfoMessageContainer* self = CTruiInfoMessageContainer::NewLC( aRect );
       
    80     CleanupStack::Pop( self );
       
    81     return self;
       
    82     }
       
    83     
       
    84 CTruiInfoMessageContainer* CTruiInfoMessageContainer::NewLC( const TRect& aRect )
       
    85     {
       
    86     CTruiInfoMessageContainer* self = new (ELeave) CTruiInfoMessageContainer();
       
    87     CleanupStack::PushL( self );
       
    88     self->ConstructL( aRect );
       
    89     return self;
       
    90     }
       
    91     
       
    92 CTruiInfoMessageContainer::~CTruiInfoMessageContainer()
       
    93     {
       
    94     delete iBackGround;        
       
    95     delete iLabelText;
       
    96     }
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // Do something before exit.
       
   100 // ---------------------------------------------------------------------------
       
   101 // 
       
   102 void CTruiInfoMessageContainer::PrepareToExitL()
       
   103     {
       
   104     // Save checkbox setting
       
   105     const RArray<CTruiRadioButton::TRadioButtonStatus>& statusArray = 
       
   106                                           iRadioButtonContainer->StatusArray();
       
   107     TBool isDisplayed = statusArray.Count() && statusArray[0] ? EFalse : ETrue;
       
   108     iEngine->SetDisplayWizard( isDisplayed );
       
   109     if ( statusArray.Count() )
       
   110         {
       
   111         SaveSettingIntoIniFileL( KAlwaysDisplayWizardKey, statusArray[0] );
       
   112         }    
       
   113     }
       
   114     
       
   115 // ---------------------------------------------------------------------------
       
   116 // Create controls to be displayed in this container.
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 void CTruiInfoMessageContainer::InitializeControlsL()
       
   120     {
       
   121     iRadioButtonContainer = CTruiRadioButton::NewL( this, 
       
   122                                                CTruiRadioButton:: ECheckBox );
       
   123     Components().AppendLC( iRadioButtonContainer );
       
   124     CleanupStack::Pop( iRadioButtonContainer );
       
   125     
       
   126     HBufC* radioText1 = iEikonEnv->AllocReadResourceLC
       
   127                              ( R_TRUI_INFOMAESSAGEVIEW_CHECKBOX_TEXT );
       
   128     iRadioButtonContainer->AddItem( radioText1, CTruiRadioButton::ENonSelected );
       
   129     CleanupStack::Pop( radioText1 ); // transfered ownership
       
   130     iRadioButtonContainer->HandleItemAdditionL();
       
   131     
       
   132     iEdwin = new (ELeave) CEikEdwin;
       
   133     iEdwin->ConstructL();
       
   134     iEdwin->SetReadOnly( ETrue );     
       
   135     Components().AppendLC( iEdwin );
       
   136     CleanupStack::Pop( iEdwin );
       
   137     
       
   138     }
       
   139 
       
   140 // ---------------------------------------------------------------------------
       
   141 // Create label and display it in the container.
       
   142 // ---------------------------------------------------------------------------
       
   143 //
       
   144 CEikLabel* CTruiInfoMessageContainer::CreateLabelL( const CCoeControl* aParent )
       
   145     {
       
   146     CEikLabel* aknLabel = new (ELeave) CEikLabel();
       
   147     CleanupStack::PushL( aknLabel );
       
   148     aknLabel->SetContainerWindowL( *aParent );
       
   149     aknLabel->ActivateL();
       
   150     CleanupStack::Pop( aknLabel ); 
       
   151     return aknLabel;
       
   152     }
       
   153 
       
   154 
       
   155 // ---------------------------------------------------------------------------
       
   156 // From class CCoeControl.
       
   157 // Responds to changes to the size and position of the contents of this control.
       
   158 // ---------------------------------------------------------------------------
       
   159 //
       
   160 void CTruiInfoMessageContainer::SizeChanged()
       
   161     {
       
   162     TRect rect = Rect();
       
   163 
       
   164     TAknWindowComponentLayout main_pane_layout = 
       
   165                             AknLayoutScalable_Apps::main_hwr_training_pane();
       
   166     TAknLayoutRect main_pane_layout_rect;
       
   167     main_pane_layout_rect.LayoutRect( rect, main_pane_layout );
       
   168     TRect main_pane_rect = main_pane_layout_rect.Rect();
       
   169 
       
   170     // hwr_training_instruct_pane    
       
   171     TAknWindowComponentLayout instruct_pane_layout = 
       
   172                AknLayoutScalable_Apps::hwr_training_instruct_pane( KVarityInstructPane );    
       
   173     TAknLayoutRect instruct_pane_layout_rect;
       
   174     instruct_pane_layout_rect.LayoutRect( main_pane_rect, instruct_pane_layout );
       
   175     iInstructPaneRect = instruct_pane_layout_rect.Rect();
       
   176     
       
   177     // count of text rows    
       
   178     TInt count = AknLayoutScalable_Apps::
       
   179                list_single_hwr_training_instruct_pane_ParamLimits( KVarityListPane )
       
   180                .LastRow() + 1;
       
   181     
       
   182     // array contains all text rows in help screen
       
   183     RArray<TAknTextComponentLayout> textLayoutArray;
       
   184     for( TInt i = 0; i < count; i++ )
       
   185         {       
       
   186         // pane area for each row
       
   187         TAknWindowComponentLayout each_row_layout =  
       
   188             AknLayoutScalable_Apps::list_single_hwr_training_instruct_pane
       
   189                                     ( KVarityListPane, 0, i );
       
   190         TAknLayoutRect each_row_layout_rect;
       
   191         each_row_layout_rect.LayoutRect( iInstructPaneRect, 
       
   192                                          each_row_layout );
       
   193         // smaller pane for text itself
       
   194         TAknTextComponentLayout each_row_text_layout =  
       
   195             AknLayoutScalable_Apps::list_single_hwr_training_instruct_pane_t1();
       
   196     
       
   197         // composition of two latter componets
       
   198         TAknTextComponentLayout textCompCompositionWiz = 
       
   199             TAknWindowComponentLayout::ComposeText(
       
   200                 each_row_layout, each_row_text_layout );
       
   201  
       
   202         TRAPD( error, textLayoutArray.AppendL( textCompCompositionWiz ) );
       
   203         // if error in append function, then just exit the loop      
       
   204         if ( error != KErrNone )
       
   205             {
       
   206             break;
       
   207             }
       
   208         }       
       
   209     iMultilineLayout = TAknTextComponentLayout::Multiline( textLayoutArray );
       
   210     textLayoutArray.Close();
       
   211 
       
   212     // Do layout for edwin
       
   213     AknLayoutUtils::LayoutEdwin( iEdwin, 
       
   214                                  iInstructPaneRect, 
       
   215                                  iMultilineLayout,
       
   216                                  EAknsCIQsnTextColorsCG6 ); 
       
   217 
       
   218 	// Do layout for radio button
       
   219     // hwr_training_instruct_pane
       
   220     TAknWindowComponentLayout symbol_option_pane = 
       
   221                AknLayoutScalable_Apps::main_hwr_training_symbol_option_pane
       
   222                                       ( KVaritySymbolOptionPane );
       
   223     TAknLayoutRect symbol_option_pane_layout_rect;
       
   224     symbol_option_pane_layout_rect.LayoutRect( main_pane_rect, symbol_option_pane );
       
   225     
       
   226 	TAknWindowComponentLayout list_option_pane = 
       
   227                AknLayoutScalable_Apps::list_single_hwr_training_symbol_option_pane
       
   228                                       ( KVarityListSymbolOptionPane );
       
   229     TAknLayoutRect list_option_pane_layout_rect;
       
   230     list_option_pane_layout_rect.LayoutRect( symbol_option_pane_layout_rect.Rect(), 
       
   231                                              list_option_pane );
       
   232     // Create multiline text for radion button
       
   233     // count of text rows    
       
   234     TInt radionLines = AknLayoutScalable_Apps::
       
   235                list_single_hwr_training_symbol_option_pane_ParamLimits
       
   236                ( KVarityListSymbolOptionPane )
       
   237                .LastRow() + 1;
       
   238     
       
   239     // array contains all text rows in help screen
       
   240     RArray<TAknTextComponentLayout> radionTextLayoutArray;
       
   241     for( TInt i = 0; i < radionLines; i++ )
       
   242         {       
       
   243         // pane area for each row
       
   244         TAknWindowComponentLayout each_row_layout =  
       
   245             AknLayoutScalable_Apps::list_single_hwr_training_symbol_option_pane
       
   246                                     ( KVarityListSymbolOptionPane, 0, i );
       
   247         TAknLayoutRect each_row_layout_rect;
       
   248         each_row_layout_rect.LayoutRect( symbol_option_pane_layout_rect.Rect(), 
       
   249                                          each_row_layout );
       
   250         // smaller pane for text itself
       
   251         TAknTextComponentLayout each_row_text_layout =  
       
   252             AknLayoutScalable_Apps::list_single_hwr_training_symbol_option_pane_t1();
       
   253     
       
   254         // composition of two latter componets
       
   255         TAknTextComponentLayout textCompCompositionWiz = 
       
   256             TAknWindowComponentLayout::ComposeText(
       
   257                 each_row_layout, each_row_text_layout );
       
   258  
       
   259         TRAPD( error, radionTextLayoutArray.AppendL( textCompCompositionWiz ) );
       
   260         // if error in append function, then just exit the loop      
       
   261         if ( error != KErrNone )
       
   262             {
       
   263             break;
       
   264             }
       
   265         }       
       
   266     TAknMultiLineTextLayout radioMultilineLayout 
       
   267                             = TAknTextComponentLayout::Multiline( radionTextLayoutArray );
       
   268     radionTextLayoutArray.Close();  
       
   269     iRadioButtonContainer->SetMultilineLayout( radioMultilineLayout );
       
   270     iRadioButtonContainer->SetRect( symbol_option_pane_layout_rect.Rect() );
       
   271     
       
   272     if ( iBackGround )
       
   273         {
       
   274         iBackGround->SetRect( Rect() );
       
   275         }
       
   276     }
       
   277     
       
   278 // ---------------------------------------------------------------------------
       
   279 // Draw.
       
   280 // ---------------------------------------------------------------------------
       
   281 //    
       
   282 void CTruiInfoMessageContainer::Draw( const TRect& /*aRect*/ ) const
       
   283    {
       
   284     // Get the standard graphics context
       
   285     CWindowGc& gc = SystemGc();
       
   286     // Gets the control's extent
       
   287     TRect rect( Rect());
       
   288     // Clears the screen
       
   289     gc.Clear( rect );
       
   290 
       
   291     MAknsSkinInstance* skin = AknsUtils::SkinInstance();  
       
   292     if ( AknsDrawUtils::HasBitmapBackground( skin, iBackGround ) ) 
       
   293         {
       
   294         AknsDrawUtils::Background( skin, iBackGround, gc, rect );
       
   295         }   
       
   296     }
       
   297 // ---------------------------------------------------------------------------
       
   298 // From class CCoeControl.
       
   299 // Handles a change to the control's resources.
       
   300 // ---------------------------------------------------------------------------
       
   301 //
       
   302 void CTruiInfoMessageContainer::HandleResourceChange( TInt aType )
       
   303     {    
       
   304     CTruiContainerBase::HandleResourceChange( aType );
       
   305     if ( aType == KAknsMessageSkinChange )
       
   306         {
       
   307         if ( iEdwin )
       
   308             {
       
   309             // Do layout for edwin
       
   310             AknLayoutUtils::LayoutEdwin( iEdwin, 
       
   311                                          iInstructPaneRect, 
       
   312                                          iMultilineLayout,
       
   313                                          EAknsCIQsnTextColorsCG6 );
       
   314             }
       
   315         }
       
   316     }