uifw/ganes/src/HgPopupDrawer.cpp
changeset 47 2f0c06423c72
parent 46 0e1e0022bd03
child 53 3c67ea82fafc
equal deleted inserted replaced
46:0e1e0022bd03 47:2f0c06423c72
     1 /*
       
     2 * Copyright (c) 2009 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:     
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "HgPopupDrawer.h"
       
    20 #include "HgConstants.h"
       
    21 
       
    22 #include <gdi.h>
       
    23 #include <AknUtils.h>
       
    24 #include <AknsDrawUtils.h>
       
    25 #include <bitstd.h>
       
    26 #include <skinlayout.cdl.h>
       
    27 #include <layoutmetadata.cdl.h>
       
    28 #include <aknlayoutscalable_avkon.cdl.h>
       
    29 #include <aknlayoutscalable_apps.cdl.h>
       
    30 
       
    31 
       
    32 THgPopupDrawer::THgPopupDrawer()
       
    33     {
       
    34     }
       
    35 
       
    36 void THgPopupDrawer::Init(  TRect aRect, const CFont* aFont )
       
    37     {
       
    38     iRect = aRect;
       
    39     iFont = aFont;
       
    40     iLongestMonth = 0;
       
    41     }
       
    42 
       
    43 void THgPopupDrawer::InitLongestMonth()
       
    44     {
       
    45     TTime time;
       
    46     time.HomeTime();
       
    47     TDateTime date = time.DateTime();
       
    48     date.SetMonth(EJanuary);
       
    49     time = date;
       
    50     
       
    51     TFileName month;
       
    52     month.Zero();
       
    53     
       
    54     for(TInt i = 0; i < 12; ++i)
       
    55         {
       
    56         TRAP_IGNORE
       
    57             (
       
    58             time.FormatL(month, KGanesMonthString);
       
    59             )
       
    60         time += TTimeIntervalMonths(1);
       
    61         TInt monthLen = iFont->TextWidthInPixels(month); 
       
    62         iLongestMonth = monthLen > iLongestMonth ? monthLen : iLongestMonth;
       
    63         }
       
    64     }
       
    65 
       
    66 void THgPopupDrawer::Draw( CWindowGc& aGc, const TDesC& aDesc )
       
    67     {
       
    68     // Resolve rect for the popup "window"
       
    69     const TInt textLength = iFont->TextWidthInPixels( aDesc );
       
    70     TInt width = iRect.Width()/KPopupWidthDiv > textLength + KPopupTextExtraPadding ? 
       
    71         iRect.Width()/KPopupWidthDiv : textLength + KPopupTextExtraPadding;
       
    72     TInt height = (iFont->FontMaxHeight() * 2);
       
    73     
       
    74     // calculate the position of the popup
       
    75     TPoint pos(((iRect.Width() - width )/2), (iRect.Height() - height)/2);
       
    76     TRect area( pos, TSize( width, height) );
       
    77 
       
    78     // First draw background box, after that the text
       
    79     DrawBackground(aGc, area);
       
    80     
       
    81     InitFont(aGc);
       
    82 
       
    83     // Draw Text
       
    84     TPoint point( area.iTl );
       
    85     point.iY += iFont->FontMaxAscent() + ((area.Height() - iFont->FontMaxHeight()) / 2);
       
    86 
       
    87     TRAP_IGNORE(
       
    88             TBidiText* text = TBidiText::NewL( aDesc, 1 );
       
    89             text->WrapText(area.Width(), *iFont, NULL);
       
    90             if(text->Directionality() == TBidiText::ELeftToRight ) 
       
    91                 {
       
    92                 point.iX += (area.Width() - textLength)/2;
       
    93                 }
       
    94             else
       
    95                 {
       
    96                 point.iX -= (area.Width() - textLength)/2;
       
    97                 }
       
    98         
       
    99             text->DrawText( aGc, point );
       
   100             delete text;
       
   101         )
       
   102     }
       
   103 
       
   104 void THgPopupDrawer::DrawNaviChar( CWindowGc& aGc, const TDesC& aDesc )
       
   105     {
       
   106     TRgb normal;
       
   107     AknsUtils::GetCachedColor(AknsUtils::SkinInstance(), 
       
   108             normal, 
       
   109             KAknsIIDQsnTextColors, 
       
   110             EAknsCIQsnTextColorsCG6 );
       
   111 
       
   112     TAknLayoutRect layout;
       
   113     layout.LayoutRect(iRect, AknLayoutScalable_Apps::popup_navstr_preview_pane(0));
       
   114 
       
   115     DrawBackground( aGc, layout.Rect() );
       
   116     
       
   117     TAknLayoutText textLayout;
       
   118     textLayout.LayoutText(layout.Rect(), AknLayoutScalable_Apps::popup_navstr_preview_pane_t1(0).LayoutLine());
       
   119     textLayout.DrawText(aGc, aDesc, ETrue, normal );
       
   120     
       
   121     }
       
   122 
       
   123 void THgPopupDrawer::Draw( CWindowGc& aGc, 
       
   124         const TDesC& aDesc1,
       
   125         const TDesC& aDesc2
       
   126         )
       
   127     {
       
   128     // init longest month value.
       
   129     if(!iLongestMonth)
       
   130         InitLongestMonth();
       
   131     
       
   132     // Resolve rect for the popup "window"
       
   133     TInt d1Length = iFont->TextWidthInPixels( aDesc1 );
       
   134     TInt d2Length = iFont->TextWidthInPixels( aDesc2 );
       
   135     
       
   136     // Calculate the dimensions
       
   137     TInt width = iRect.Width()/KPopupWidthDiv > iLongestMonth + KPopupTextExtraPadding ? 
       
   138         iRect.Width()/KPopupWidthDiv : iLongestMonth + KPopupTextExtraPadding;
       
   139     TInt height = (iFont->FontMaxHeight() * 3);
       
   140     
       
   141     // calculate the position of the popup
       
   142     TPoint pos(((iRect.Width() - width )/2), (iRect.Height() - height)/2);
       
   143     TRect area( pos, TSize( width, height) );
       
   144 
       
   145     // First draw background box, after that the text
       
   146     DrawBackground(aGc, area);
       
   147 
       
   148     InitFont(aGc);
       
   149     
       
   150     // First text
       
   151     TPoint point( area.iTl );
       
   152     point.iY += iFont->FontMaxAscent() + (iFont->FontMaxHeight() / 2);
       
   153     TRAP_IGNORE(
       
   154             TBidiText* text = TBidiText::NewL( aDesc1, 1 );
       
   155             text->WrapText(area.Width(), *iFont, NULL);
       
   156             if(text->Directionality() == TBidiText::ELeftToRight ) 
       
   157                 {
       
   158                 point.iX += (area.Width() - d1Length)/2;
       
   159                 }
       
   160             else
       
   161                 {
       
   162                 point.iX -= (area.Width() - d1Length)/2;
       
   163                 }
       
   164         
       
   165             text->DrawText( aGc, point );
       
   166             delete text;
       
   167         )
       
   168 
       
   169     // Second text
       
   170     point.iX = area.iTl.iX;
       
   171     point.iX += (area.Width() - d2Length)/2;
       
   172     point.iY += iFont->FontMaxHeight();
       
   173     aGc.DrawText(aDesc2, point );
       
   174     }
       
   175 
       
   176 void THgPopupDrawer::DrawBackground( CWindowGc& aGc, const TRect& aRect )
       
   177     {
       
   178     TAknLayoutRect cornerRect;
       
   179     // skinned draw uses submenu popup window skin (skinned border)
       
   180     cornerRect.LayoutRect(
       
   181         aRect,
       
   182         SkinLayout::Submenu_skin_placing_Line_2() );
       
   183     
       
   184     TRect innerRect( aRect );
       
   185     innerRect.Shrink( cornerRect.Rect().Width(), cornerRect.Rect().Height() );
       
   186     
       
   187     if ( !AknsDrawUtils::DrawFrame(
       
   188             AknsUtils::SkinInstance(),
       
   189             aGc,
       
   190             aRect,
       
   191             innerRect,
       
   192             KAknsIIDQsnFrPopupSub,
       
   193             KAknsIIDQsnFrPopupCenterSubmenu ) )
       
   194         {
       
   195         // skinned border failed -> black border
       
   196         aGc.SetPenStyle( CGraphicsContext::ESolidPen );
       
   197         aGc.SetBrushColor( KRgbBlack );
       
   198         aGc.DrawRect( aRect );
       
   199         }
       
   200     }
       
   201 
       
   202 void THgPopupDrawer::InitFont(CWindowGc& aGc)
       
   203     {
       
   204     // Get color for the text from the skin.
       
   205     TRgb normal;
       
   206     AknsUtils::GetCachedColor(AknsUtils::SkinInstance(), 
       
   207             normal, 
       
   208             KAknsIIDQsnTextColors, 
       
   209             EAknsCIQsnTextColorsCG6 );
       
   210     
       
   211     // Draw text
       
   212     aGc.UseFont( iFont );
       
   213     aGc.SetPenColor(normal);    
       
   214     }
       
   215