idlehomescreen/xmluirendering/renderingplugins/xnclockfactory/src/xnclockface.cpp
branchRCL_3
changeset 88 3321d3e205b6
parent 83 5456b4e8b3a8
child 93 b01126ce0bec
equal deleted inserted replaced
83:5456b4e8b3a8 88:3321d3e205b6
    36 
    36 
    37 // LOCAL CONSTANTS AND MACROS
    37 // LOCAL CONSTANTS AND MACROS
    38 _LIT( KAmPmFormat, "%B" );
    38 _LIT( KAmPmFormat, "%B" );
    39 _LIT( KTimeFormat, "%J%:1%T" );
    39 _LIT( KTimeFormat, "%J%:1%T" );
    40 
    40 
       
    41 _LIT( KClockFont, "EAknLogicalFontSecondaryFont" );
       
    42 _LIT( KAmpmFont, "EAknLogicalFontSecondaryFont" );
       
    43 
    41 // ============================ MEMBER FUNCTIONS ===============================
    44 // ============================ MEMBER FUNCTIONS ===============================
    42 
    45 
    43 // -----------------------------------------------------------------------------
    46 // -----------------------------------------------------------------------------
    44 // CXnClockFaceDigital::CXnClockFaceDigital
    47 // CXnClockFaceDigital::CXnClockFaceDigital
    45 // C++ default constructor can NOT contain any code, that
    48 // C++ default constructor can NOT contain any code, that
    84     {
    87     {
    85     }
    88     }
    86 
    89 
    87 // -----------------------------------------------------------------------------
    90 // -----------------------------------------------------------------------------
    88 // CXnClockFaceDigital::DrawL
    91 // CXnClockFaceDigital::DrawL
    89 // (other items were commented in a header).
       
    90 // -----------------------------------------------------------------------------
    92 // -----------------------------------------------------------------------------
    91 //
    93 //
    92 void CXnClockFaceDigital::DrawL( CXnClockAdapter& aAdapter, CWindowGc& aGc, 
    94 void CXnClockFaceDigital::DrawL( CXnClockAdapter& aAdapter, CWindowGc& aGc, 
    93     const TRect& aRect, const TTime& aTime )
    95         CXnNodePluginIf& aNode, const TTime& aTime, CXnNodePluginIf* aAmpm )
    94     {
    96     {    
    95     TBuf< KMaxTimeFormatSpec > time;
    97     TBuf< KMaxTimeFormatSpec > time;
    96     aTime.FormatL( time, KTimeFormat() );
    98     aTime.FormatL( time, KTimeFormat() );
    97 
    99 
       
   100     AknTextUtils::LanguageSpecificNumberConversion( time );
       
   101 
       
   102     const CAknLayoutFont* clockFont( CreateFontL( aAdapter, aNode, EClock ) );
       
   103     if ( !clockFont )
       
   104         {
       
   105         return;
       
   106         }
       
   107 
       
   108     const TRgb& color( CreateColorL( aAdapter, aNode, EClock) );
       
   109 
       
   110     const TInt deltaHeight( aNode.Rect().Height() - clockFont->TextPaneHeight() );
       
   111     TInt offset( clockFont->TextPaneTopToBaseline() + deltaHeight / 2 );
       
   112     
       
   113     CGraphicsContext::TTextAlign align = aAdapter.GetTextAlignL( aNode );
       
   114 
       
   115     aGc.SetPenColor( color );
       
   116     aGc.UseFont( clockFont );
       
   117     aGc.DrawText( time, aNode.Rect(), offset, align );
       
   118     aGc.DiscardFont();
       
   119 
       
   120     if( TLocale().TimeFormat() == ETime12 && aAmpm )
       
   121         {
       
   122         DrawAmpmL( aAdapter, aGc, aTime, *aAmpm );
       
   123         }
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CXnClockFaceDigital::DrawAmpmL
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 void CXnClockFaceDigital::DrawAmpmL( CXnClockAdapter& aAdapter,
       
   131                                      CWindowGc& aGc,
       
   132                                      const TTime& aTime,
       
   133                                      CXnNodePluginIf& aAmpm )
       
   134     {
    98     TBuf< KMaxTimeFormatSpec > ampm;
   135     TBuf< KMaxTimeFormatSpec > ampm;
    99     aTime.FormatL( ampm, KAmPmFormat() );
   136     aTime.FormatL( ampm, KAmPmFormat() );
   100 
   137     ampm.Trim();
   101     AknTextUtils::LanguageSpecificNumberConversion( time );
   138     
   102 
   139     const CAknLayoutFont* ampmFont( CreateFontL( aAdapter, aAmpm, EAmpm ) );
   103     const CAknLayoutFont* clockFont( 
   140     if ( !ampmFont )
   104             aAdapter.FontL( CXnClockAdapter::EDigitalFont ) );
   141         {
   105 
   142         return;
   106     const CAknLayoutFont* ampmFont( 
   143         }
   107             aAdapter.FontL( CXnClockAdapter::EAmPmFont ) );
   144     
   108 
   145     const TRgb& color( CreateColorL( aAdapter, aAmpm, EAmpm) );
   109     const CAknLayoutFont* dateFont( 
   146     
   110             aAdapter.FontL( CXnClockAdapter::EDateFont ) );
   147     const TInt deltaHeight( aAmpm.Rect().Height() - ampmFont->TextPaneHeight() );
   111 
   148     TInt offset( ampmFont->TextPaneTopToBaseline() + deltaHeight / 2 );
   112     const TRgb& color( aAdapter.TextColorL() );
   149     
   113 
   150     CGraphicsContext::TTextAlign align = aAdapter.GetTextAlignL( aAmpm );
   114     CXnNodePluginIf* date( aAdapter.Date() );
       
   115 
       
   116     const TInt deltaHeight( aRect.Height() - clockFont->TextPaneHeight() );
       
   117     TInt offset( clockFont->TextPaneTopToBaseline() + deltaHeight / 2 );
       
   118 
       
   119     if( date )
       
   120         {
       
   121         // When date string is shown, time string must be lifted up
       
   122         offset -= ( dateFont->TextPaneHeight() / 2 );
       
   123         }
       
   124 
       
   125     // Measure the full width of the time string 
       
   126     TInt textWidth( AknBidiTextUtils::MeasureTextBoundsWidth( *clockFont, time, 
       
   127         CFont::TMeasureTextInput::EFVisualOrder ) );
       
   128 
       
   129     TInt extraWidth( aRect.Width() - textWidth );
       
   130 
       
   131     TInt margin( extraWidth / 2 );
       
   132 
   151 
   133     aGc.SetPenColor( color );
   152     aGc.SetPenColor( color );
   134 
   153     aGc.UseFont( ampmFont );
   135     aGc.UseFont( clockFont );
   154     aGc.DrawText( ampm, aAmpm.Rect(), offset, align );
   136 
   155     aGc.DiscardFont();
   137     CGraphicsContext::TTextAlign align;
   156     }
   138 
   157 
   139     TBool mirrored( AknLayoutUtils::LayoutMirrored() );
   158 // -----------------------------------------------------------------------------
   140 
   159 // CXnClockFaceDigital::CreateFontL
   141     if( mirrored )
   160 // -----------------------------------------------------------------------------
   142         {
   161 //
   143         align = CGraphicsContext::ERight;
   162 const CAknLayoutFont* CXnClockFaceDigital::CreateFontL( CXnClockAdapter& aAdapter,
       
   163         CXnNodePluginIf& aNode,
       
   164         TXnClockFontType aFontType)
       
   165     {    
       
   166     if ( aFontType == EClock )
       
   167         {
       
   168         if ( !iClockFont )
       
   169             {
       
   170             aAdapter.CreateFontL( aNode, KClockFont, iClockFont );
       
   171             }
       
   172         return CAknLayoutFont::AsCAknLayoutFontOrNull( iClockFont );
   144         }
   173         }
   145     else
   174     else
   146         {
   175         {
   147         align = CGraphicsContext::ELeft;
   176         if ( !iAmpmFont )
   148         }
       
   149 
       
   150     aGc.DrawText( time, aRect, offset, align, margin );
       
   151 
       
   152     aGc.DiscardFont();
       
   153 
       
   154     if( TLocale().TimeFormat() == ETime12 )
       
   155         {
       
   156         TRect ampmRect( aRect );
       
   157         TInt ampmHeight( ampmFont->TextPaneHeight() );
       
   158 
       
   159         if( mirrored )
       
   160             {
   177             {
   161             align = CGraphicsContext::ELeft;
   178             aAdapter.CreateFontL( aNode, KAmpmFont, iAmpmFont );
   162             }
   179             }
   163         else
   180         return CAknLayoutFont::AsCAknLayoutFontOrNull( iAmpmFont );
       
   181         }
       
   182     }
       
   183 
       
   184 // -----------------------------------------------------------------------------
       
   185 // CXnClockFaceDigital::CreateColorL
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 const TRgb& CXnClockFaceDigital::CreateColorL( CXnClockAdapter& aAdapter,
       
   189         CXnNodePluginIf& aNode,
       
   190         TXnClockFontType aFontType )
       
   191     {
       
   192     if ( aFontType == EClock )
       
   193         {
       
   194         if ( !iIsFaceColorSet )
   164             {
   195             {
   165             align = CGraphicsContext::ERight;
   196             aAdapter.CreateColorL( aNode, iFaceColor );
       
   197             iIsFaceColorSet = ETrue;
   166             }
   198             }
   167 
   199         return iFaceColor;
   168         ampmRect.iTl.iY += ampmHeight;
   200         }
   169 
   201     else
   170         aGc.UseFont( ampmFont );
   202         {
   171 
   203         if ( !iIsAmpmColorSet )
   172         aGc.DrawText( ampm, ampmRect, offset, align, margin );
       
   173 
       
   174         aGc.DiscardFont();
       
   175         }
       
   176 
       
   177     if( date )
       
   178         {
       
   179         const TDesC* dateStr( &KNullDesC() );
       
   180 
       
   181         CXnText* textIf( NULL );
       
   182 
       
   183         XnComponentInterface::MakeInterfaceL( textIf, date->AppIfL() );
       
   184 
       
   185         if( textIf )
       
   186             {
   204             {
   187             dateStr = textIf->Text();
   205             aAdapter.CreateColorL( aNode, iAmpmColor );
       
   206             iIsAmpmColorSet = ETrue;
   188             }
   207             }
   189 
   208         return iAmpmColor;
   190         // Measure the full width of the time string 
   209         }
   191         TInt dateWidth( AknBidiTextUtils::MeasureTextBoundsWidth( *dateFont, *dateStr, 
   210     }
   192             CFont::TMeasureTextInput::EFVisualOrder ) );
   211 
   193 
   212 // -----------------------------------------------------------------------------
   194         TInt width( aRect.Width() - dateWidth );
   213 // CXnClockFaceDigital::ResetFont
   195         TInt margin( width / 2 );
   214 // -----------------------------------------------------------------------------
   196 
   215 //
   197         // Move date string down by text pane height and 5% of rect height
   216 void CXnClockFaceDigital::ResetFont()
   198         offset += dateFont->TextPaneHeight() + ( aRect.Height() / 20 );
   217     {
   199 
   218     iClockFont = iAmpmFont = NULL;
   200         aGc.UseFont( dateFont );
   219     iIsFaceColorSet = iIsAmpmColorSet = EFalse;
   201 
       
   202         aGc.DrawText( *dateStr, aRect, offset, align, margin );
       
   203 
       
   204         aGc.DiscardFont();
       
   205         }
       
   206     }
   220     }
   207 
   221 
   208 // ============================ MEMBER FUNCTIONS ===============================
   222 // ============================ MEMBER FUNCTIONS ===============================
   209 
   223 
   210 // -----------------------------------------------------------------------------
   224 // -----------------------------------------------------------------------------
   251     {
   265     {
   252     }
   266     }
   253 
   267 
   254 // -----------------------------------------------------------------------------
   268 // -----------------------------------------------------------------------------
   255 // CXnClockFaceAnalog::DrawL
   269 // CXnClockFaceAnalog::DrawL
   256 // (other items were commented in a header).
       
   257 // -----------------------------------------------------------------------------
   270 // -----------------------------------------------------------------------------
   258 //
   271 //
   259 void CXnClockFaceAnalog::DrawL( CXnClockAdapter& /*aAdapter*/, CWindowGc& aGc, 
   272 void CXnClockFaceAnalog::DrawL( CXnClockAdapter& /*aAdapter*/, CWindowGc& aGc, 
   260     const TRect& aRect, const TTime& aTime )
   273         CXnNodePluginIf& aNode, const TTime& aTime, CXnNodePluginIf* /*aAmpm*/ )
   261     {
   274     {    
   262     TSize faceSize( aRect.Size() );
   275     TSize faceSize( aNode.Rect().Size() );
   263     
   276     
   264     TDateTime dateTime( aTime.DateTime() );
   277     TDateTime dateTime( aTime.DateTime() );
   265     
   278     
   266     MAknsSkinInstance* skin( AknsUtils::SkinInstance() );
   279     MAknsSkinInstance* skin( AknsUtils::SkinInstance() );
   267  
   280  
   284 
   297 
   285     if( skinMask )
   298     if( skinMask )
   286         {
   299         {
   287         User::LeaveIfError( AknIconUtils::SetSize( skinMask, faceSize ) );
   300         User::LeaveIfError( AknIconUtils::SetSize( skinMask, faceSize ) );
   288         
   301         
   289         aGc.BitBltMasked( aRect.iTl,
   302         aGc.BitBltMasked( aNode.Rect().iTl,
   290                           skinBmp,
   303                           skinBmp,
   291                           TRect( TPoint( 0, 0 ), skinBmp->SizeInPixels() ),
   304                           TRect( TPoint( 0, 0 ), skinBmp->SizeInPixels() ),
   292                           skinMask,
   305                           skinMask,
   293                           ETrue );
   306                           ETrue );
   294         }
   307         }
   295     else
   308     else
   296         {
   309         {
   297         aGc.BitBlt( aRect.iTl, skinBmp );
   310         aGc.BitBlt( aNode.Rect().iTl, skinBmp );
   298         }
   311         }
   299 
   312 
   300     aGc.SetBrushStyle( CGraphicsContext::ENullBrush );
   313     aGc.SetBrushStyle( CGraphicsContext::ENullBrush );
   301     aGc.SetPenStyle( CGraphicsContext::ESolidPen );
   314     aGc.SetPenStyle( CGraphicsContext::ESolidPen );
   302   
   315   
   303     DrawHandsL( aGc, aRect, dateTime );
   316     DrawHandsL( aGc, aNode.Rect(), dateTime );
   304     }
   317     }
   305             
   318             
   306 // -----------------------------------------------------------------------------
   319 // -----------------------------------------------------------------------------
   307 // CXnClockFaceAnalog::DrawHands
   320 // CXnClockFaceAnalog::DrawHands
   308 // (other items were commented in a header).
       
   309 // -----------------------------------------------------------------------------
   321 // -----------------------------------------------------------------------------
   310 //
   322 //
   311 void CXnClockFaceAnalog::DrawHandsL( CWindowGc& aGc,
   323 void CXnClockFaceAnalog::DrawHandsL( CWindowGc& aGc,
   312                                      const TRect& aRect,
   324                                      const TRect& aRect,
   313                                      const TDateTime& aDateTime )                                    
   325                                      const TDateTime& aDateTime )                                    
   353                       minbitmap,
   365                       minbitmap,
   354                       TRect( TPoint( 0, 0 ), minbitmap->SizeInPixels() ),
   366                       TRect( TPoint( 0, 0 ), minbitmap->SizeInPixels() ),
   355                       minmask,
   367                       minmask,
   356                       EFalse );
   368                       EFalse );
   357     }
   369     }
       
   370 
       
   371 // -----------------------------------------------------------------------------
       
   372 // CXnClockFaceAnalog::ResetFont
       
   373 // -----------------------------------------------------------------------------
       
   374 //
       
   375 void CXnClockFaceAnalog::ResetFont()
       
   376     {
       
   377     }
   358     
   378     
   359 //  End of File
   379 //  End of File