wvuing/wvuiave/AppSrc/CCAChatInfoArray.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Array of chat info structure
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    "CCAChatInfoArray.h"
       
    21 #include    "ChatDefinitions.h"
       
    22 #include	<eikenv.h>
       
    23 #include	<aknutils.h>
       
    24 #include    <aknlayoutscalable_avkon.cdl.h>
       
    25 
       
    26 // ================= MEMBER FUNCTIONS =======================
       
    27 // ---------------------------------------------------------
       
    28 // CCAChatInfoArray::CCAChatInfoArray()
       
    29 // C++ default constructor can NOT contain any code, that
       
    30 // might leave.
       
    31 // ---------------------------------------------------------
       
    32 //
       
    33 
       
    34 CCAChatInfoArray::CCAChatInfoArray()
       
    35     {
       
    36     }
       
    37 // ---------------------------------------------------------
       
    38 // CCAChatInfoArray::ConstructL()
       
    39 //Symbian OS default constructor can leave.
       
    40 //
       
    41 // ---------------------------------------------------------
       
    42 //
       
    43 void CCAChatInfoArray::ConstructL()
       
    44     {
       
    45     iLine = HBufC::NewL( KMaxLengthOfHBufC + KMaxTabLength );
       
    46     iTextFields = new ( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
    47     iLineWidthArray = new ( ELeave ) CArrayFixFlat<TInt>( KArrayGranularity );
       
    48 
       
    49     iFont = LatinBold13(); // LAF
       
    50 
       
    51     TAknLayoutRect temp, layout;
       
    52     TAknLayoutText myLayoutText;
       
    53 
       
    54     TRect myMainPaneRect;
       
    55     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane,
       
    56                                        myMainPaneRect );
       
    57 
       
    58     layout.LayoutRect( myMainPaneRect, AknLayoutScalable_Avkon::main_pane( 1 ) );
       
    59     temp.LayoutRect( layout.Rect(), AknLayoutScalable_Avkon::popup_menu_window( 13 ) );
       
    60     layout.LayoutRect( temp.Rect(), AknLayoutScalable_Avkon::listscroll_menu_pane( 0 ) );
       
    61     temp.LayoutRect( layout.Rect(), AknLayoutScalable_Avkon::list_menu_pane( 0 ) );
       
    62     myLayoutText.LayoutText( temp.Rect(), AknLayoutScalable_Avkon::list_single_heading_pane_t1_cp2( 0 ) );
       
    63 
       
    64     iFont = myLayoutText.Font();
       
    65 
       
    66     iSubCellWidth = myLayoutText.TextRect().Size().iWidth; // * 4 / 11;
       
    67 
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------
       
    71 // CCAChatInfoArray::SetLineWidthArrayL()
       
    72 // Sets the linewidth array full of integers
       
    73 // (other items were commented in a header).
       
    74 // ---------------------------------------------------------
       
    75 //
       
    76 void CCAChatInfoArray::SetLineWidthArrayL( CArrayFix<TInt>* aLineWidthArray,
       
    77                                            const TDesC& aTextField )
       
    78     {
       
    79 
       
    80 
       
    81     TInt maxSize( iFont->TextWidthInPixels( aTextField ) / iSubCellWidth );
       
    82     for ( TInt i( 0 ); i <= maxSize; ++i )
       
    83         {
       
    84         aLineWidthArray->AppendL( iSubCellWidth );
       
    85         }
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------
       
    89 // CCAChatInfoArray::NewL()
       
    90 //
       
    91 // ---------------------------------------------------------
       
    92 //
       
    93 
       
    94 CCAChatInfoArray* CCAChatInfoArray::NewL()
       
    95     {
       
    96     CCAChatInfoArray* self = new ( ELeave ) CCAChatInfoArray;
       
    97 
       
    98     CleanupStack::PushL( self );
       
    99     self->ConstructL();
       
   100     CleanupStack::Pop();
       
   101 
       
   102     return self;
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------
       
   106 // CCAChatInfoArray::~CCAChatInfoArray()
       
   107 // Destructor
       
   108 // ---------------------------------------------------------
       
   109 //
       
   110 CCAChatInfoArray::~CCAChatInfoArray()
       
   111     {
       
   112     delete iLine;
       
   113     delete iTextFields;
       
   114     delete iLineWidthArray;
       
   115     }
       
   116 
       
   117 // ---------------------------------------------------------
       
   118 // CCAChatInfoArray::AddLabelAndTextL()
       
   119 // Add labels and field texts to array
       
   120 // (other items were commented in a header).
       
   121 // ---------------------------------------------------------
       
   122 //
       
   123 void CCAChatInfoArray::AddLabelAndTextL( TInt aLabelResourceId,
       
   124                                          const TDesC& aFieldText,
       
   125                                          TBool /*aWrap*/ )
       
   126     {
       
   127     SetLineWidthArrayL( iLineWidthArray, aFieldText );
       
   128 
       
   129     //temp array that contains TPtrC values. Number 1 is granularity
       
   130     CArrayFixFlat<TPtrC>* tempArray = new ( ELeave ) CArrayFixFlat<TPtrC>( 1 );
       
   131     CleanupStack::PushL( tempArray );
       
   132     AknTextUtils::WrapToArrayL( aFieldText, *iLineWidthArray, *iFont,
       
   133                                 *tempArray );
       
   134 
       
   135     HBufC* itemBuf = HBufC::NewLC( KMaxLengthOfHBufC );
       
   136     TPtr itemPtr( itemBuf->Des() );
       
   137 
       
   138     HBufC* label = CEikonEnv::Static()->
       
   139                    AllocReadResourceLC( aLabelResourceId );
       
   140 
       
   141     TInt arrayCount( tempArray->Count() );
       
   142     for ( TInt i( 0 ); i < arrayCount; i++ )
       
   143         {
       
   144         itemPtr.Copy( tempArray->At( i ).Left( itemPtr.MaxLength() ) );
       
   145         itemPtr.Insert( 0, KTabulator );
       
   146         if ( i == 0 )
       
   147             {
       
   148             itemPtr.Insert( 0, *label );
       
   149             }
       
   150         iTextFields->AppendL( *itemBuf );
       
   151         itemPtr.Zero();
       
   152         }
       
   153     CleanupStack::PopAndDestroy( 3, tempArray ); // itemBuf, label, tempArray
       
   154     }
       
   155 
       
   156 // ---------------------------------------------------------
       
   157 // CCAChatInfoArray::MdcaCount() const
       
   158 // Returns number of items that are in array
       
   159 // (other items were commented in a header).
       
   160 // ---------------------------------------------------------
       
   161 //
       
   162 TInt CCAChatInfoArray::MdcaCount() const
       
   163     {
       
   164     __ASSERT_ALWAYS( iTextFields,
       
   165                      User::Panic( KPanicText, EChatInfoArrayNotExists ) );
       
   166     return iTextFields->MdcaCount();
       
   167     }
       
   168 
       
   169 // ---------------------------------------------------------
       
   170 // CCAChatInfoArray::MdcaPoint( TInt aIndex ) const
       
   171 // Returns formatted descriptor for given index
       
   172 // (other items were commented in a header).
       
   173 // ---------------------------------------------------------
       
   174 //
       
   175 TPtrC CCAChatInfoArray::MdcaPoint( TInt aIndex ) const
       
   176     {
       
   177     __ASSERT_ALWAYS( iTextFields,
       
   178                      User::Panic( KPanicText, EChatInfoArrayNotExists ) );
       
   179 
       
   180     __ASSERT_DEBUG( aIndex >= 0,
       
   181                     User::Panic( KPanicText, EChatInfoArrayIndexOutOfBounds ) );
       
   182 
       
   183     __ASSERT_DEBUG( aIndex < iTextFields->MdcaCount(),
       
   184                     User::Panic( KPanicText, EChatInfoArrayIndexOutOfBounds ) ) ;
       
   185 
       
   186     return iTextFields->MdcaPoint( aIndex );
       
   187     }
       
   188 
       
   189 //  End of File