calendarui/views/src/calenmonthcelllistboxdata.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 /*
       
     2 * Copyright (c) 2002 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:   Drawing Cell of MonthView of Calendar application.
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 //debug
       
    21 #include "calendarui_debug.h"
       
    22 
       
    23 
       
    24 // INCLUDE FILES
       
    25 #include "calenmonthcelllistboxdata.h"
       
    26 
       
    27 #include "calendar.hrh"
       
    28 
       
    29 #include <AknsEffectAnim.h>
       
    30 #include <AknUtils.h>
       
    31 #include <gulicon.h>
       
    32 
       
    33 #include <aknlayoutscalable_apps.cdl.h>
       
    34 #include <aknlayoutscalable_avkon.cdl.h>
       
    35 
       
    36 
       
    37 // CONSTANTS
       
    38 const TInt KMonthCells(2);
       
    39 
       
    40 
       
    41 // ================= MEMBER FUNCTIONS =======================
       
    42 
       
    43 // Two-phased constructor.
       
    44 CCalenMonthCellListBoxData* CCalenMonthCellListBoxData::NewL()
       
    45     {
       
    46     TRACE_ENTRY_POINT;
       
    47     
       
    48     CCalenMonthCellListBoxData* self = new (ELeave) CCalenMonthCellListBoxData();
       
    49     // Construct grid animation by default
       
    50     self->ConstructLD( KAknsIIDQsnAnimGrid );
       
    51     
       
    52     TRACE_EXIT_POINT;
       
    53     return self;
       
    54     }
       
    55 
       
    56 // Destructor
       
    57 CCalenMonthCellListBoxData::~CCalenMonthCellListBoxData()
       
    58     {
       
    59     TRACE_ENTRY_POINT;
       
    60     TRACE_EXIT_POINT;
       
    61     }
       
    62 
       
    63 // C++ default constructor can NOT contain any code, that
       
    64 // might leave.
       
    65 //
       
    66 CCalenMonthCellListBoxData::CCalenMonthCellListBoxData()
       
    67     {
       
    68     TRACE_ENTRY_POINT;
       
    69     TRACE_EXIT_POINT;
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------
       
    73 // CCalenMonthCellListBoxData::DrawFormatted
       
    74 // Draw date and bitmap of Month Grid
       
    75 // (other items were commented in a header).
       
    76 // ---------------------------------------------------------
       
    77 //
       
    78 void CCalenMonthCellListBoxData::DrawFormatted( TListItemProperties aProperties, 
       
    79                                                 CWindowGc& aGc,
       
    80                                                 const TDesC* aText,
       
    81                                                 const TRect& aItemRect,
       
    82                                                 TBool /*aHighlight*/,
       
    83                                                 const TColors& aColors) const
       
    84     {
       
    85     TRACE_ENTRY_POINT;
       
    86     
       
    87     // This is minimized version of draw formatted needed to draw month view subcells.
       
    88     // In principle, there shouldn't be any month view specific functionality in here,
       
    89     // and we could use Avkon's DrawFormatted. However, Avkon DrawFormatted contains
       
    90     // lot of extra stuff, which seems unnecessary for month view.
       
    91 
       
    92     aGc.SetPenStyle(CGraphicsContext::ESolidPen);
       
    93     aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
       
    94     aGc.SetPenColor(aColors.iText);
       
    95     aGc.SetBrushColor(aColors.iBack);
       
    96 
       
    97     TInt lastSubCell(LastSubCell());
       
    98 
       
    99     TPtrC text;
       
   100 
       
   101     // Draw subcells (there are only two of them
       
   102     for (TInt subcell(0); subcell < lastSubCell; ++subcell)
       
   103         {
       
   104         TextUtils::ColumnText( text, subcell, aText );
       
   105         TMargins m( SubCellMargins( subcell ) );
       
   106         TRect rect( aItemRect.iTl + SubCellPosition( subcell ) + TSize( m.iLeft, m.iTop ),
       
   107                     SubCellSize( subcell ) - TSize( m.iRight + m.iLeft, m.iBottom + m.iTop ) );
       
   108 
       
   109         // SKIP subcell if either there's NO DATA, or area is 0
       
   110         if (text.Length() || rect.iTl.iX != rect.iBr.iX || rect.iTl.iY != rect.iBr.iY)
       
   111             {
       
   112             CGraphicsContext::TTextAlign align( CGraphicsContext::ECenter );
       
   113 
       
   114             if( !SubCellIsGraphics( subcell ) )
       
   115                 { // draw text
       
   116                 const CFont* usedFont = Font( aProperties, subcell );
       
   117                 if( usedFont == NULL )
       
   118                     {
       
   119                     usedFont = CEikonEnv::Static()->NormalFont();
       
   120                     }
       
   121                 aGc.UseFont( usedFont );
       
   122 
       
   123                 // baseline calc needed for each cell.
       
   124                 TBuf<ECalenCharsInLine> clipbuf( text );
       
   125                 AknTextUtils::DisplayTextLanguageSpecificNumberConversion( clipbuf );
       
   126                 TInt baseLineOffset( SubCellBaselinePos(subcell) );
       
   127                 baseLineOffset -= m.iTop;
       
   128                 aGc.DrawText( clipbuf, rect, baseLineOffset, align );
       
   129                 }
       
   130             else
       
   131                 {  // drawing bitmap
       
   132                 TLex lex(text);
       
   133                 TInt index(0);
       
   134                 lex.Val(index);
       
   135                 if (index >= 0)
       
   136                     { 
       
   137                     CGulIcon* icon = (*IconArray())[index];
       
   138                     TPoint bmpPos = rect.iTl;
       
   139 
       
   140                     CFbsBitmap* colorBitmap = icon->Bitmap();
       
   141                     const TRect bmpRect( colorBitmap->SizeInPixels() );
       
   142                     aGc.BitBltMasked( bmpPos, colorBitmap, bmpRect, icon->Mask(), ETrue );
       
   143                     }
       
   144                 }
       
   145             }
       
   146         }
       
   147     
       
   148     TRACE_EXIT_POINT;
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------
       
   152 // CCalenMonthCellListBoxData::LastSubCell
       
   153 // an ordinal number of last subcell of cell
       
   154 // (other items were commented in a header).
       
   155 // ---------------------------------------------------------
       
   156 //
       
   157 TInt CCalenMonthCellListBoxData::LastSubCell() const
       
   158     {
       
   159     TRACE_ENTRY_POINT;
       
   160     
       
   161     TRACE_EXIT_POINT;
       
   162     return KMonthCells;
       
   163     }
       
   164 
       
   165 // ---------------------------------------------------------
       
   166 // CCalenMonthCellListBoxData::Draw
       
   167 // Draw a cell of Month Grid
       
   168 // (other items were commented in a header).
       
   169 // ---------------------------------------------------------
       
   170 //
       
   171 void CCalenMonthCellListBoxData::Draw(TListItemProperties aProperties, CWindowGc& aGc, const TDesC* aText, const TRect& aRect, TBool aHighlight, const TColors& aColors) const
       
   172     {
       
   173     TRACE_ENTRY_POINT;
       
   174 
       
   175     TRect aItemRect(aRect);
       
   176 
       
   177     // draw skinned highlight
       
   178     TBool highlightDrawn = EFalse;
       
   179 
       
   180     if(aHighlight)
       
   181         {
       
   182         MAknsSkinInstance *skin = AknsUtils::SkinInstance();
       
   183         MAknsControlContext *cc = AknsDrawUtils::ControlContext( Control() );
       
   184 
       
   185         if(!cc) cc = SkinBackgroundContext();
       
   186 
       
   187         if(cc)
       
   188             {
       
   189             aGc.SetPenStyle( CGraphicsContext::ENullPen );
       
   190 
       
   191             if( HighlightAnim() )
       
   192                 {
       
   193                 AboutToDrawHighlightAnim();
       
   194                 if( HighlightAnim() )
       
   195                     highlightDrawn = HighlightAnim()->Render( aGc, aItemRect );
       
   196                 }
       
   197 
       
   198             // Either animation does not exist or drawing it failed
       
   199             if( !highlightDrawn )
       
   200                 {
       
   201                 TAknLayoutRect grid_highlight_pane_cp08;
       
   202                 grid_highlight_pane_cp08.LayoutRect( aItemRect /*P:cell_cale_month_pane*/, AknLayoutScalable_Apps::grid_highlight_pane_cp08().LayoutLine() );
       
   203 
       
   204                 TAknLayoutRect cell_highlight_pane_g1;
       
   205                 cell_highlight_pane_g1.LayoutRect(
       
   206                     grid_highlight_pane_cp08.Rect(),
       
   207                     AknLayoutScalable_Avkon::cell_highlight_pane_g1().LayoutLine() );
       
   208 
       
   209                 highlightDrawn = AknsDrawUtils::DrawFrame( skin, aGc,
       
   210                                                            grid_highlight_pane_cp08.Rect(), 
       
   211                                                            cell_highlight_pane_g1.Rect(), 
       
   212                                                            KAknsIIDQsnFrGrid, KAknsIIDQsnFrGridCenter );
       
   213                 }
       
   214             }
       
   215         }
       
   216 
       
   217     // draw the actual items.
       
   218     DrawFormatted(aProperties, aGc, aText, aItemRect, EFalse, aColors);
       
   219 
       
   220     aGc.Reset();
       
   221     
       
   222     TRACE_EXIT_POINT;
       
   223     }
       
   224 
       
   225 // End of File