uifw/AvKon/src/aknnavilabel.cpp
changeset 0 2f259fa3e83a
child 9 aabf2c525e0f
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2002-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:  Default label control for the status pane's navigation pane.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // SYSTEM INCLUDE FILES
       
    20 #include <gdi.h>
       
    21 #include <eikspane.h>
       
    22 #include <AknsDrawUtils.h>
       
    23 #include <bidivisual.h>
       
    24 #include <biditext.h>
       
    25 #include <aknlayoutscalable_avkon.cdl.h>
       
    26 
       
    27 #include <AknTasHook.h>
       
    28 // USER INCLUDE FILES
       
    29 #include "aknnavilabel.h"
       
    30 #include "AknPanic.h"
       
    31 #include "AknUtils.h"
       
    32 #include "aknconsts.h"
       
    33 #include "AknBidiTextUtils.h"
       
    34 #include "AknStatuspaneUtils.h"
       
    35 #include "aknenv.h"
       
    36 #include "aknnavide.h"
       
    37 #include <aknnavide.h>
       
    38 
       
    39 NONSHARABLE_CLASS( CAknNaviLabelExtension ) : public CBase
       
    40     {
       
    41 public:
       
    42     static CAknNaviLabelExtension* NewL();
       
    43     ~CAknNaviLabelExtension();
       
    44     void SetVisualBufferSizeL( TInt aSize );
       
    45 private:
       
    46     CAknNaviLabelExtension();
       
    47     void ConstructL();
       
    48 public: //data
       
    49     HBufC* iVisualTextBuffer;
       
    50     };
       
    51 
       
    52 CAknNaviLabelExtension* CAknNaviLabelExtension::NewL()
       
    53     {
       
    54     CAknNaviLabelExtension* self = new (ELeave) CAknNaviLabelExtension;
       
    55     CleanupStack::PushL( self );
       
    56     self->ConstructL();
       
    57     CleanupStack::Pop( self );
       
    58     return self;
       
    59     }
       
    60 
       
    61 CAknNaviLabelExtension::CAknNaviLabelExtension()
       
    62     {
       
    63     }
       
    64 
       
    65 CAknNaviLabelExtension::~CAknNaviLabelExtension()
       
    66     {
       
    67     delete iVisualTextBuffer;
       
    68     }
       
    69 
       
    70 void CAknNaviLabelExtension::ConstructL()
       
    71     {
       
    72     iVisualTextBuffer = HBufC::NewL(0);
       
    73     }
       
    74 
       
    75 void CAknNaviLabelExtension::SetVisualBufferSizeL( TInt aSize )
       
    76     {
       
    77     if ( aSize <= iVisualTextBuffer->Des().MaxLength() )
       
    78         {
       
    79         return;
       
    80         }
       
    81 
       
    82     HBufC* tempBuf = HBufC::NewL( aSize );
       
    83     delete iVisualTextBuffer;
       
    84     iVisualTextBuffer = tempBuf;
       
    85     }
       
    86 
       
    87 EXPORT_C CAknNaviLabel::~CAknNaviLabel()
       
    88     {
       
    89     AKNTASHOOK_REMOVE();
       
    90     delete iText;
       
    91     delete iExtension;
       
    92     }
       
    93 
       
    94 EXPORT_C CAknNaviLabel::CAknNaviLabel()
       
    95     {
       
    96     AKNTASHOOK_ADD( this, "CAknNaviLabel" );
       
    97     }
       
    98 
       
    99 EXPORT_C void CAknNaviLabel::SetTextL( const TDesC& aText )
       
   100     {
       
   101     __ASSERT_DEBUG( &aText, Panic( EAknPanicNullPointer ) );
       
   102 
       
   103     if ( !iExtension )
       
   104         {
       
   105         iExtension = CAknNaviLabelExtension::NewL();
       
   106         }
       
   107 
       
   108     User::LeaveIfError( AknBidiTextUtils::PrepareRunInfoArray( aText ) );
       
   109     HBufC* newText = aText.AllocLC();
       
   110     iExtension->SetVisualBufferSizeL(
       
   111         aText.Length() + KAknBidiExtraSpacePerLine );
       
   112     CleanupStack::Pop( newText );
       
   113 
       
   114     delete iText; // after all allocations succeed
       
   115     iText = newText;
       
   116 
       
   117     SizeChanged();
       
   118     }
       
   119 
       
   120 EXPORT_C void CAknNaviLabel::SetNaviLabelType( TNaviLabelType aLabelType )
       
   121     {
       
   122     iLabelType = aLabelType;
       
   123     }
       
   124 
       
   125 EXPORT_C CAknNaviLabel::TNaviLabelType CAknNaviLabel::NaviLabelType()
       
   126     {
       
   127     return iLabelType;
       
   128     }
       
   129 
       
   130 EXPORT_C void CAknNaviLabel::SizeChanged()
       
   131     {
       
   132     if ( !iExtension )
       
   133         {
       
   134         return;
       
   135         }
       
   136 
       
   137     TRect parentRect( Rect() );
       
   138 
       
   139     CGraphicsContext::TTextAlign alignment = CGraphicsContext::ELeft;
       
   140     iRightOffset = 0;
       
   141 
       
   142     TAknLayoutText textLayout( LayoutText() );
       
   143 
       
   144     switch ( iLabelType )
       
   145         {
       
   146         case ENavigationLabel:
       
   147             {
       
   148             TRect textRect( textLayout.TextRect() );
       
   149             TRect rect( Rect() );
       
   150 
       
   151             // because this components rect is not same as navipane
       
   152             // in LAF some calculations are needed.
       
   153 
       
   154             // The left margin amount of navipane that this labels
       
   155             // rect does not cover.
       
   156             TInt leftOutsideMargin = 0;
       
   157 
       
   158             // The right margin amount of navipane that this labels
       
   159             // rect does not cover.
       
   160             TInt rightOutsideMargin = 0;
       
   161 
       
   162             leftOutsideMargin = rect.iTl.iX;
       
   163             rightOutsideMargin = parentRect.iBr.iX - rect.iBr.iX;
       
   164 
       
   165             if ( leftOutsideMargin < 0 )
       
   166                 {
       
   167                 leftOutsideMargin = 0;
       
   168                 }
       
   169 
       
   170             if ( rightOutsideMargin < 0 )
       
   171                 {
       
   172                 rightOutsideMargin = 0;
       
   173                 }
       
   174 
       
   175             iLeftMargin  = textRect.iTl.iX - leftOutsideMargin;
       
   176             iRightMargin = rect.iBr.iX - textRect.iBr.iX;
       
   177             iFont        = textLayout.Font();
       
   178             iColor       = textLayout.Color();
       
   179             alignment    = textLayout.Align();
       
   180             }
       
   181             break;
       
   182 
       
   183         case EAdditionalInfoLabel: // fallthrough, these use same properties.
       
   184         case EHintText:
       
   185             {
       
   186             TRect textRect( textLayout.TextRect() );
       
   187             iLeftMargin  = textRect.iTl.iX;
       
   188             iRightMargin = parentRect.iBr.iX - textRect.iBr.iX;
       
   189             iFont        = textLayout.Font();
       
   190             iColor       = textLayout.Color();
       
   191             alignment    = textLayout.Align();
       
   192             }
       
   193             break;
       
   194 
       
   195         default:
       
   196             break;
       
   197         }
       
   198 
       
   199     TInt width = WidthInsideMargins();
       
   200     if ( width < 0 )
       
   201         {
       
   202         width = 0;
       
   203         }
       
   204 
       
   205     TPtr truncated = iExtension->iVisualTextBuffer->Des();
       
   206 
       
   207     AknBidiTextUtils::ConvertToVisualAndClip(
       
   208         *iText,
       
   209         truncated,
       
   210         *iFont,
       
   211         width,
       
   212         width );
       
   213 
       
   214     if ( alignment == CGraphicsContext::ECenter )
       
   215         {
       
   216         // Center the text. Must inform the text measurement algorithm that
       
   217         // the text is in visual, not logical order.
       
   218 
       
   219         CFont::TMeasureTextInput input;
       
   220         input.iFlags = CFont::TMeasureTextInput::EFVisualOrder;
       
   221 
       
   222         TInt textLength = iFont->MeasureText( truncated, &input );
       
   223 
       
   224         iRightOffset = ( width - textLength ) / 2;
       
   225         }
       
   226     }
       
   227 
       
   228 EXPORT_C void CAknNaviLabel::Draw( const TRect& /*aRect*/ ) const
       
   229     {
       
   230     if ( !iExtension )
       
   231         {
       
   232         return;
       
   233         }
       
   234 
       
   235     CWindowGc& gc = SystemGc();
       
   236 
       
   237     TRect rect( Rect() );
       
   238     gc.UseFont( iFont );
       
   239 
       
   240     TRgb color = iColor;
       
   241 
       
   242     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   243     TAknLayoutText layoutText( LayoutText() );
       
   244     if ( AknStatuspaneUtils::StaconPaneActive() ||
       
   245          AknStatuspaneUtils::FlatLayoutActive() )
       
   246         {
       
   247         AknsUtils::GetCachedColor( skin,
       
   248                                    color,
       
   249                                    KAknsIIDQsnTextColors,
       
   250                                    EAknsCIQsnTextColorsCG43 );
       
   251         }
       
   252     else
       
   253         {
       
   254         AknsUtils::GetCachedColor( skin,
       
   255                                    color,
       
   256                                    KAknsIIDQsnTextColors,
       
   257                                    EAknsCIQsnTextColorsCG2 );
       
   258         }
       
   259 
       
   260     layoutText.DrawText( gc, *iText, ETrue, color );
       
   261     }
       
   262 
       
   263 EXPORT_C void CAknNaviLabel::HandlePointerEventL(
       
   264     const TPointerEvent& aPointerEvent )
       
   265     {
       
   266     CAknControl::HandlePointerEventL( aPointerEvent );
       
   267     }
       
   268 
       
   269 EXPORT_C void* CAknNaviLabel::ExtensionInterface( TUid /*aInterface*/ )
       
   270     {
       
   271     return NULL;
       
   272     }
       
   273 
       
   274 TInt CAknNaviLabel::WidthInsideMargins() const
       
   275     {
       
   276     TInt width = Rect().Width() - iLeftMargin - iRightMargin;
       
   277     return width;
       
   278     }
       
   279 
       
   280 TAknLayoutText CAknNaviLabel::LayoutText() const
       
   281     {
       
   282     TRect parentRect( CAknNavigationDecorator::DecoratedControlRect(
       
   283         CAknNavigationDecorator::ENaviLabel ) );
       
   284 
       
   285     TAknWindowLineLayout naviPaneLayout;
       
   286     TAknWindowLineLayout naviTextPaneLayout;
       
   287     TAknTextLineLayout layout;
       
   288 
       
   289     // In flat status pane with narrow layout we have another layout
       
   290     TBool flatNarrow = AknStatuspaneUtils::FlatLayoutActive() &&
       
   291                        parentRect.Width() > Rect().Width();
       
   292 
       
   293     if ( flatNarrow )
       
   294         {
       
   295         parentRect = Rect();
       
   296         }
       
   297 
       
   298     if ( AknStatuspaneUtils::SmallLayoutActive() )
       
   299         {
       
   300         layout = AknLayoutScalable_Avkon::status_small_pane_t1( 0 );
       
   301         }
       
   302     else
       
   303         {
       
   304         switch ( iLabelType )
       
   305             {
       
   306             case ENavigationLabel:
       
   307                 {
       
   308                 if ( flatNarrow )
       
   309                     {
       
   310                     naviPaneLayout = AknLayoutScalable_Avkon::navi_navi_pane_srt().LayoutLine();
       
   311                     naviTextPaneLayout = AknLayoutScalable_Avkon::navi_navi_text_pane_srt().LayoutLine();
       
   312                     layout = TAknWindowComponentLayout::ComposeText( naviPaneLayout,
       
   313                                 TAknWindowComponentLayout::ComposeText( naviTextPaneLayout,
       
   314                                     AknLayoutScalable_Avkon::navi_navi_text_pane_srt_t1().LayoutLine() ) );
       
   315                     }
       
   316                 else
       
   317                     {
       
   318                     naviPaneLayout = AknLayoutScalable_Avkon::navi_navi_pane().LayoutLine();
       
   319                     naviTextPaneLayout = AknLayoutScalable_Avkon::navi_navi_text_pane().LayoutLine();
       
   320                     layout = TAknWindowComponentLayout::ComposeText( naviPaneLayout,
       
   321                                 TAknWindowComponentLayout::ComposeText( naviTextPaneLayout,
       
   322                                     AknLayoutScalable_Avkon::navi_navi_text_pane_t1().LayoutLine() ) );
       
   323                     }
       
   324                 }
       
   325                 break;
       
   326 
       
   327             case EAdditionalInfoLabel:
       
   328                 {
       
   329                 if ( flatNarrow )
       
   330                     {
       
   331                     naviTextPaneLayout = AknLayoutScalable_Avkon::navi_text_pane_srt(1).LayoutLine();
       
   332                     layout = TAknWindowComponentLayout::ComposeText( naviTextPaneLayout,
       
   333                                 AknLayoutScalable_Avkon::navi_text_pane_srt_t1().LayoutLine() );
       
   334                     }
       
   335                 else
       
   336                     {
       
   337                     naviTextPaneLayout = AknLayoutScalable_Avkon::navi_text_pane(1).LayoutLine();
       
   338                     layout = TAknWindowComponentLayout::ComposeText( naviTextPaneLayout,
       
   339                                 AknLayoutScalable_Avkon::navi_text_pane_t1().LayoutLine() );
       
   340                     }
       
   341                 }
       
   342                 break;
       
   343 
       
   344             case EHintText:
       
   345                 {
       
   346                 if ( flatNarrow )
       
   347                     {
       
   348                     naviTextPaneLayout = AknLayoutScalable_Avkon::navi_text_pane_srt(0).LayoutLine();
       
   349                     layout = TAknWindowComponentLayout::ComposeText( naviTextPaneLayout,
       
   350                                 AknLayoutScalable_Avkon::navi_text_pane_srt_t1().LayoutLine() );
       
   351                     }
       
   352                 else
       
   353                     {
       
   354                     naviTextPaneLayout = AknLayoutScalable_Avkon::navi_text_pane(0).LayoutLine();
       
   355                     layout = TAknWindowComponentLayout::ComposeText( naviTextPaneLayout,
       
   356                                 AknLayoutScalable_Avkon::navi_text_pane_t1().LayoutLine() );
       
   357                     }
       
   358                 }
       
   359                 break;
       
   360 
       
   361             default:
       
   362                 break;
       
   363             }
       
   364         }
       
   365 
       
   366     // In stacon pane text justification depends on which side the
       
   367     // soft keys are. We change justification here manually because
       
   368     // the LAF data does not support this yet. So this code overides also
       
   369     // A & H mirroring which is supposed to be not used in stacon pane anyway.
       
   370     if ( AknStatuspaneUtils::StaconPaneActive() &&
       
   371          layout.iJ != ELayoutAlignCenter )
       
   372         {
       
   373         if ( AknStatuspaneUtils::StaconSoftKeysLeft() )
       
   374             {
       
   375             layout.iJ = ELayoutAlignRight;
       
   376             }
       
   377         else
       
   378             {
       
   379             layout.iJ = ELayoutAlignLeft;
       
   380             }
       
   381         }
       
   382     // In flat status pane we change justification here manually because
       
   383     // the LAF data does not support this yet. This way we avoid odd looking
       
   384     // situation where navitexts are in the middle of the status pane area.
       
   385     // Right side is more sensible place (left in A&H).
       
   386     else if ( AknStatuspaneUtils::FlatLayoutActive() &&
       
   387               layout.iJ != ELayoutAlignCenter )
       
   388         {
       
   389         if ( AknLayoutUtils::LayoutMirrored() )
       
   390             {
       
   391             layout.iJ = ELayoutAlignLeft;
       
   392             }
       
   393         else
       
   394             {
       
   395             layout.iJ = ELayoutAlignRight;
       
   396             }
       
   397         }
       
   398 
       
   399 
       
   400 
       
   401     TAknLayoutText textLayout;
       
   402     textLayout.LayoutText( parentRect, layout );
       
   403     return textLayout;
       
   404     }
       
   405 
       
   406 //  End of File