multimediacommsengine/tsrc/testdriver/testclient/ui/src/CTcContainer.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <bldvariant.hrh>
       
    19 #include <eikenv.h>
       
    20 #include <eiklabel.h>
       
    21 
       
    22 #include "CTcTestRunner.h"
       
    23 #include "CTcContainer.h"
       
    24 #include "TestClientConstants.h"
       
    25 
       
    26 #ifdef __SERIES90_
       
    27 #include <cknenv.h>	// skin support
       
    28 #endif
       
    29 
       
    30 #ifdef __SERIES60_
       
    31 #include <akndef.h>
       
    32 #endif
       
    33 
       
    34 
       
    35 CTcContainer* CTcContainer::NewL( const TRect& aRect )
       
    36 	{
       
    37 	CTcContainer* self = new( ELeave ) CTcContainer;
       
    38 
       
    39 	CleanupStack::PushL( self );
       
    40 	self->ConstructL( aRect );
       
    41 	CleanupStack::Pop( self );
       
    42 
       
    43 	return self;
       
    44 	}
       
    45 
       
    46 CTcContainer::~CTcContainer()
       
    47 	{
       
    48 	// Delete all labels
       
    49 	iLabels.ResetAndDestroy();
       
    50 	}
       
    51 
       
    52 CTcContainer::CTcContainer()
       
    53 	: iLabels( 1 )	// Minimum granularity
       
    54 	{
       
    55 	}
       
    56 
       
    57 void CTcContainer::ConstructL( const TRect& aRect )
       
    58 	{
       
    59 	// Create a window for this application view
       
    60 	CreateWindowL();
       
    61 
       
    62 #ifdef __SERIES90_
       
    63 	// Set skin configuration
       
    64 	CCknSkinBase& skin = CknEnv().Skin();
       
    65 	skin.SetAppViewType( ESkinAppViewNoCbaNoToolband );
       
    66 #endif
       
    67     
       
    68     CreateLabelsL( aRect );
       
    69 
       
    70 	// Set windows size and activate it
       
    71 	SetRect( aRect );
       
    72 	ActivateL();
       
    73 	}
       
    74 
       
    75 void CTcContainer::Draw( const TRect& aRect ) const
       
    76 	{
       
    77 	// Clear the view area
       
    78 	CWindowGc& gc = SystemGc();
       
    79 	gc.Clear( aRect );
       
    80 #ifdef __SERIES90_
       
    81 	CknEnv().Skin().DrawAppView( gc, aRect );
       
    82 #endif
       
    83 	}
       
    84 
       
    85 TInt CTcContainer::CountComponentControls() const
       
    86 	{
       
    87 	// Return amount of label control
       
    88 	return iLabels.Count();
       
    89 	}
       
    90 
       
    91 CCoeControl* CTcContainer::ComponentControl( TInt aIndex ) const
       
    92 	{
       
    93 	// Return pointer to a label control
       
    94 	return iLabels[ aIndex ];
       
    95 	}
       
    96 
       
    97 void CTcContainer::Update( CTcTestRunner& aRunner )
       
    98 	{
       
    99 	// Update "Value" labels
       
   100 	SetLabelText( ETestCaseValue, aRunner.CurrentTestCaseName() );
       
   101 	SetLabelText( ERequestValue, aRunner.CurrentRequestName() );
       
   102 
       
   103 	// Force screen update NOW
       
   104 	DrawDeferred();
       
   105 	CEikonEnv::Static()->WsSession().Flush();
       
   106 	}
       
   107 
       
   108 void CTcContainer::UpdateStatus( const TDesC8& aStatus )
       
   109 	{
       
   110 	// Update "Status" label
       
   111 	SetLabelText( EStatusValue, aStatus );
       
   112 
       
   113 	// Force screen update NOW
       
   114 	DrawNow();
       
   115 	CEikonEnv::Static()->WsSession().Flush();
       
   116 	}
       
   117 
       
   118 CEikLabel* CTcContainer::CreateLabelL( const TRect& aRect, const TDesC& aText )
       
   119 	{
       
   120 	// Create new label and add it to the label array
       
   121 	CEikLabel* label = new( ELeave ) CEikLabel;
       
   122 	CleanupStack::PushL( label );
       
   123 	iLabels.AppendL( label );
       
   124 	CleanupStack::Pop( label );
       
   125 
       
   126 	// Set label container, area and text
       
   127 	label->SetContainerWindowL( *this );
       
   128 	label->SetRect( aRect );
       
   129 	label->SetTextL( aText );
       
   130 
       
   131 	return label;
       
   132 	}
       
   133 
       
   134 void CTcContainer::SetLabelText( TInt aLabelId, const TDesC8& aText )
       
   135 	{
       
   136 	// 8bit to unicode conversion
       
   137 	TBuf< KMaxLabelSize > tmp16;
       
   138 	tmp16.Copy( aText );
       
   139 
       
   140 	// replace an empty text with "<none>"
       
   141 	if( tmp16 == KNullDesC )
       
   142 		{
       
   143 		tmp16 = KNone;
       
   144 		}
       
   145 
       
   146 	// Set text, ignore any errors
       
   147 	TRAP_IGNORE( iLabels[ aLabelId ]->SetTextL( tmp16 ) )
       
   148 	}
       
   149 	
       
   150 #ifdef __SERIES60_
       
   151 
       
   152 void CTcContainer::SizeChanged()
       
   153     {
       
   154     ReLayoutAllLabels( Rect() );
       
   155     }
       
   156 
       
   157 void CTcContainer::HandleResourceChange( TInt aType )
       
   158 	{
       
   159 	CCoeControl::HandleResourceChange( aType );
       
   160 	
       
   161     if ( aType == KEikDynamicLayoutVariantSwitch )
       
   162         {
       
   163         TRect mainPaneRect;
       
   164         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, 
       
   165                                            mainPaneRect );
       
   166         SetRect( mainPaneRect );
       
   167         DrawNow();
       
   168         }
       
   169 	}
       
   170 	
       
   171 AknLayoutUtils::SAknLayoutTextMultiline CTcContainer::GetLabelLayout( 
       
   172     const TRect& aRect, TInt aLabelBase, TAknLogicalFontId aFontId ) const
       
   173     {
       
   174     /*
       
   175     SAknLayoutTextMultiline struct:
       
   176     
       
   177     @param iFont      font id, ELatinPlain12, ELatinBold12, ELatinBold13 etc..
       
   178 	@param iC         colour index, 0..255
       
   179 	@param iL         left margin
       
   180 	@param iR         right margin
       
   181 	@param iB         Baseline from top of the parent rectangle
       
   182 	@param iW         text width in pixels
       
   183 	@param iJ         justification. ELayoutAlignNone; ELayoutAlignCenter;
       
   184 	                  ELayoutAlignLeft; ELayoutAlignRight; ELayoutAlignBidi
       
   185 	                  
       
   186 	@param iNumberOfLinesShown
       
   187 	@param iNextLineB baseline of 2nd line for multi-line labels/editors
       
   188 	*/
       
   189 
       
   190     const TInt KFontColorIndexBlack( 200 );	
       
   191 
       
   192 	AknLayoutUtils::SAknLayoutTextMultiline labelLayout;
       
   193 	labelLayout.iFont = aFontId;
       
   194     labelLayout.iC = KFontColorIndexBlack;
       
   195     labelLayout.iL = KLabelTlX;
       
   196     labelLayout.iR = KLabelTlX;
       
   197     labelLayout.iB = aLabelBase;
       
   198     labelLayout.iW = aRect.Width() - labelLayout.iL - labelLayout.iR;
       
   199     labelLayout.iJ = ELayoutAlignLeft;
       
   200     labelLayout.iNumberOfLinesShown = 1;
       
   201     return labelLayout;
       
   202     }
       
   203 
       
   204 TInt CTcContainer::FontTotalHeightInPixels( TAknLogicalFontId aFontId ) const
       
   205     {
       
   206     const CFont* font = AknLayoutUtils::FontFromId( aFontId );
       
   207     
       
   208    	_LIT( KPanicCntx, "TestClient" );
       
   209 	__ASSERT_ALWAYS( font, User::Panic( KPanicCntx(), KErrNotFound ) );
       
   210 	
       
   211 	return  font->HeightInPixels();
       
   212     }
       
   213 
       
   214 void CTcContainer::CreateLabelsL( const TRect& aRect )
       
   215     {
       
   216     // Create labels
       
   217 	CEikLabel* label;
       
   218 	
       
   219 	TInt primaryFontTotalHeight( FontTotalHeightInPixels( EAknLogicalFontPrimaryFont ) );
       
   220 	TInt secondaryFontTotalHeight( FontTotalHeightInPixels( EAknLogicalFontSecondaryFont ) );
       
   221 	
       
   222 	TInt labelBase = KLabelTlY + primaryFontTotalHeight;	
       
   223     AknLayoutUtils::SAknLayoutTextMultiline labelLayout = 
       
   224         GetLabelLayout( aRect, labelBase, EAknLogicalFontPrimaryFont );
       
   225 	TRect rect( KLabelTlX, KLabelTlY, 
       
   226 	            aRect.Width() - KLabelTlX, KLabelTlY + primaryFontTotalHeight );
       
   227 
       
   228     label = CreateLabelL( rect, KTestCase );
       
   229     AknLayoutUtils::LayoutLabel( label, rect, labelLayout );
       
   230     
       
   231 	rect.Move( 0, secondaryFontTotalHeight );
       
   232 	labelBase += secondaryFontTotalHeight;
       
   233 	labelLayout = GetLabelLayout( aRect, labelBase, EAknLogicalFontSecondaryFont );
       
   234 	label = CreateLabelL( rect, KNone );
       
   235     AknLayoutUtils::LayoutLabel( label, rect, labelLayout );
       
   236 
       
   237 	rect.Move( 0, primaryFontTotalHeight );
       
   238 	labelBase += primaryFontTotalHeight;
       
   239 	labelLayout = GetLabelLayout( aRect, labelBase, EAknLogicalFontPrimaryFont );
       
   240 	label = CreateLabelL( rect, KRequest );
       
   241 	AknLayoutUtils::LayoutLabel( label, rect, labelLayout );
       
   242 	rect.Move( 0, secondaryFontTotalHeight );
       
   243 	labelBase += secondaryFontTotalHeight;
       
   244 	labelLayout = GetLabelLayout( aRect, labelBase, EAknLogicalFontSecondaryFont );
       
   245 	label = CreateLabelL( rect, KNone );
       
   246 	AknLayoutUtils::LayoutLabel( label, rect, labelLayout );
       
   247 
       
   248 
       
   249 	rect.Move( 0, primaryFontTotalHeight );
       
   250 	labelBase += primaryFontTotalHeight;
       
   251 	labelLayout = GetLabelLayout( aRect, labelBase, EAknLogicalFontPrimaryFont );
       
   252 	label = CreateLabelL( rect, KStatus );
       
   253 	AknLayoutUtils::LayoutLabel( label, rect, labelLayout );
       
   254 	rect.Move( 0, secondaryFontTotalHeight );
       
   255 	labelBase += secondaryFontTotalHeight;
       
   256 	labelLayout = GetLabelLayout( aRect, labelBase, EAknLogicalFontSecondaryFont );
       
   257 	label = CreateLabelL( rect, KNone );
       
   258 	AknLayoutUtils::LayoutLabel( label, rect, labelLayout );
       
   259     }
       
   260     
       
   261  
       
   262 void CTcContainer::ReLayoutAllLabels( const TRect& aRect )
       
   263     {
       
   264     if ( iLabels.Count() != 6 )
       
   265         {
       
   266         return;
       
   267         }
       
   268         
       
   269     CEikLabel* label;
       
   270     
       
   271     TInt primaryFontTotalHeight( FontTotalHeightInPixels( EAknLogicalFontPrimaryFont ) );
       
   272 	TInt secondaryFontTotalHeight( FontTotalHeightInPixels( EAknLogicalFontSecondaryFont ) );
       
   273 	
       
   274 	TInt labelBase = KLabelTlY + primaryFontTotalHeight;	
       
   275     AknLayoutUtils::SAknLayoutTextMultiline labelLayout = 
       
   276         GetLabelLayout( aRect, labelBase, EAknLogicalFontPrimaryFont );
       
   277 	TRect rect( KLabelTlX, KLabelTlY, 
       
   278 	            aRect.Width() - KLabelTlX, KLabelTlY + primaryFontTotalHeight );
       
   279 
       
   280     label = iLabels[ 0 ];
       
   281     AknLayoutUtils::LayoutLabel( label, rect, labelLayout );
       
   282     
       
   283 	rect.Move( 0, secondaryFontTotalHeight );
       
   284 	labelBase += secondaryFontTotalHeight;
       
   285 	labelLayout = GetLabelLayout( aRect, labelBase, EAknLogicalFontSecondaryFont );
       
   286 	label = iLabels[ 1 ];
       
   287     AknLayoutUtils::LayoutLabel( label, rect, labelLayout );
       
   288 
       
   289 	rect.Move( 0, primaryFontTotalHeight );
       
   290 	labelBase += primaryFontTotalHeight;
       
   291 	labelLayout = GetLabelLayout( aRect, labelBase, EAknLogicalFontPrimaryFont );
       
   292 	label = iLabels[ 2 ];
       
   293 	AknLayoutUtils::LayoutLabel( label, rect, labelLayout );
       
   294 	rect.Move( 0, secondaryFontTotalHeight );
       
   295 	labelBase += secondaryFontTotalHeight;
       
   296 	labelLayout = GetLabelLayout( aRect, labelBase, EAknLogicalFontSecondaryFont );
       
   297 	label = iLabels[ 3 ];
       
   298 	AknLayoutUtils::LayoutLabel( label, rect, labelLayout );
       
   299 
       
   300 
       
   301 	rect.Move( 0, primaryFontTotalHeight );
       
   302 	labelBase += primaryFontTotalHeight;
       
   303 	labelLayout = GetLabelLayout( aRect, labelBase, EAknLogicalFontPrimaryFont );
       
   304 	label = iLabels[ 4 ];
       
   305 	AknLayoutUtils::LayoutLabel( label, rect, labelLayout );
       
   306 	rect.Move( 0, secondaryFontTotalHeight );
       
   307 	labelBase += secondaryFontTotalHeight;
       
   308 	labelLayout = GetLabelLayout( aRect, labelBase, EAknLogicalFontSecondaryFont );
       
   309 	label = iLabels[ 5 ];
       
   310 	AknLayoutUtils::LayoutLabel( label, rect, labelLayout );
       
   311     }
       
   312     
       
   313 #else
       
   314     
       
   315 void CTcContainer::CreateLabelsL( const TRect& /*aRect*/ )
       
   316     {
       
   317    	// Create labels
       
   318 	CEikLabel* label;
       
   319 	TRect rect( KLabelTlX, KLabelTlY, KLabelBrX, KLabelBrY );
       
   320 	label = CreateLabelL( rect, KTestCase );
       
   321 	rect.Move( 0, KLabelSpacing );
       
   322 	label = CreateLabelL( rect, KNone );
       
   323 	// Use smaller for for this label
       
   324 	label->SetFont( CEikonEnv::Static()->AnnotationFont() );
       
   325 
       
   326 	rect.Move( 0, KLabelSpacing );
       
   327 	label = CreateLabelL( rect, KRequest );
       
   328 	rect.Move( 0, KLabelSpacing );
       
   329 	label = CreateLabelL( rect, KNone );
       
   330 	// Use smaller for for this label
       
   331 	label->SetFont( CEikonEnv::Static()->AnnotationFont() );
       
   332 
       
   333 	rect.Move( 0, KLabelSpacing );
       
   334 	label = CreateLabelL( rect, KStatus );
       
   335 	rect.Move( 0, KLabelSpacing );
       
   336 	label = CreateLabelL( rect, KNone );
       
   337 	// Use smaller for for this label
       
   338 	label->SetFont( CEikonEnv::Static()->AnnotationFont() );
       
   339     }
       
   340 
       
   341 #endif // __SERIES60_
       
   342 
       
   343