idlehomescreen/xmluirendering/renderingplugins/xnclockfactory/src/xnclockface.cpp
branchRCL_3
changeset 102 ba63c83f4716
parent 93 b01126ce0bec
equal deleted inserted replaced
93:b01126ce0bec 102:ba63c83f4716
    28 
    28 
    29 // USER INCLUDE FILES
    29 // USER INCLUDE FILES
    30 #include "xnnodepluginif.h"
    30 #include "xnnodepluginif.h"
    31 #include "xnclockadapter.h"
    31 #include "xnclockadapter.h"
    32 #include "xntext.h"
    32 #include "xntext.h"
    33 #include "xnproperty.h"
       
    34 #include "xndomproperty.h"
       
    35 #include "xndomlist.h"
       
    36 
    33 
    37 #include "xnclockface.h"
    34 #include "xnclockface.h"
    38 
    35 
    39 
    36 
    40 // LOCAL CONSTANTS AND MACROS
    37 // LOCAL CONSTANTS AND MACROS
    41 _LIT( KAmPmFormat, "%B" );
    38 _LIT( KAmPmFormat, "%B" );
    42 _LIT( KTimeFormat, "%J%:1%T" );
    39 _LIT( KTimeFormat, "%J%:1%T" );
    43 
    40 
    44 const TInt KDefaultFaceAdjustmentValue = 0;
       
    45 
       
    46 // ============================ MEMBER FUNCTIONS ===============================
    41 // ============================ MEMBER FUNCTIONS ===============================
    47 
    42 
    48 // -----------------------------------------------------------------------------
    43 // -----------------------------------------------------------------------------
    49 // CXnClockFaceDigital::CXnClockFaceDigital
    44 // CXnClockFaceDigital::CXnClockFaceDigital
    50 // C++ default constructor can NOT contain any code, that
    45 // C++ default constructor can NOT contain any code, that
    89     {
    84     {
    90     }
    85     }
    91 
    86 
    92 // -----------------------------------------------------------------------------
    87 // -----------------------------------------------------------------------------
    93 // CXnClockFaceDigital::DrawL
    88 // CXnClockFaceDigital::DrawL
       
    89 // (other items were commented in a header).
    94 // -----------------------------------------------------------------------------
    90 // -----------------------------------------------------------------------------
    95 //
    91 //
    96 void CXnClockFaceDigital::DrawL( CXnClockAdapter& aAdapter, CWindowGc& aGc, 
    92 void CXnClockFaceDigital::DrawL( CXnClockAdapter& aAdapter, CWindowGc& aGc, 
    97         CXnNodePluginIf& aNode, const TTime& aTime, CXnNodePluginIf* aAmpm )
    93     const TRect& aRect, const TTime& aTime )
    98     {    
    94     {
    99     TBuf< KMaxTimeFormatSpec > time;
    95     TBuf< KMaxTimeFormatSpec > time;
   100     aTime.FormatL( time, KTimeFormat() );
    96     aTime.FormatL( time, KTimeFormat() );
   101 
    97 
   102     AknTextUtils::LanguageSpecificNumberConversion( time );
       
   103 
       
   104     const CAknLayoutFont* clockFont( CreateFontL( aAdapter, aNode, EClock ) );
       
   105     if ( !clockFont )
       
   106         {
       
   107         return;
       
   108         }
       
   109 
       
   110     const TRgb& color( CreateColorL( aAdapter, aNode, EClock) );
       
   111 
       
   112     const TInt deltaHeight( aNode.Rect().Height() - clockFont->TextPaneHeight() );
       
   113     TInt offset( clockFont->TextPaneTopToBaseline() + deltaHeight / 2 );
       
   114     
       
   115     CGraphicsContext::TTextAlign align = aAdapter.GetTextAlignL( aNode );
       
   116 
       
   117     aGc.SetPenColor( color );
       
   118     aGc.UseFont( clockFont );
       
   119     aGc.DrawText( time, aNode.Rect(), offset, align );
       
   120     aGc.DiscardFont();
       
   121 
       
   122     if( TLocale().TimeFormat() == ETime12 && aAmpm )
       
   123         {
       
   124         DrawAmpmL( aAdapter, aGc, aTime, *aAmpm );
       
   125         }
       
   126     }
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // CXnClockFaceDigital::DrawAmpmL
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 void CXnClockFaceDigital::DrawAmpmL( CXnClockAdapter& aAdapter,
       
   133                                      CWindowGc& aGc,
       
   134                                      const TTime& aTime,
       
   135                                      CXnNodePluginIf& aAmpm )
       
   136     {
       
   137     TBuf< KMaxTimeFormatSpec > ampm;
    98     TBuf< KMaxTimeFormatSpec > ampm;
   138     aTime.FormatL( ampm, KAmPmFormat() );
    99     aTime.FormatL( ampm, KAmPmFormat() );
   139     ampm.Trim();
   100 
   140     
   101     AknTextUtils::LanguageSpecificNumberConversion( time );
   141     const CAknLayoutFont* ampmFont( CreateFontL( aAdapter, aAmpm, EAmpm ) );
   102 
   142     if ( !ampmFont )
   103     const CAknLayoutFont* clockFont( 
   143         {
   104             aAdapter.FontL( CXnClockAdapter::EDigitalFont ) );
   144         return;
   105 
   145         }
   106     const CAknLayoutFont* ampmFont( 
   146     
   107             aAdapter.FontL( CXnClockAdapter::EAmPmFont ) );
   147     const TRgb& color( CreateColorL( aAdapter, aAmpm, EAmpm) );
   108 
   148     
   109     const CAknLayoutFont* dateFont( 
   149     const TInt deltaHeight( aAmpm.Rect().Height() - ampmFont->TextPaneHeight() );
   110             aAdapter.FontL( CXnClockAdapter::EDateFont ) );
   150     TInt offset( ampmFont->TextPaneTopToBaseline() + deltaHeight / 2 );
   111 
   151     
   112     const TRgb& color( aAdapter.TextColorL() );
   152     CGraphicsContext::TTextAlign align = aAdapter.GetTextAlignL( aAmpm );
   113 
       
   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 );
   153 
   132 
   154     aGc.SetPenColor( color );
   133     aGc.SetPenColor( color );
   155     aGc.UseFont( ampmFont );
   134 
   156     aGc.DrawText( ampm, aAmpm.Rect(), offset, align );
   135     aGc.UseFont( clockFont );
       
   136 
       
   137     CGraphicsContext::TTextAlign align;
       
   138 
       
   139     TBool mirrored( AknLayoutUtils::LayoutMirrored() );
       
   140 
       
   141     if( mirrored )
       
   142         {
       
   143         align = CGraphicsContext::ERight;
       
   144         }
       
   145     else
       
   146         {
       
   147         align = CGraphicsContext::ELeft;
       
   148         }
       
   149 
       
   150     aGc.DrawText( time, aRect, offset, align, margin );
       
   151 
   157     aGc.DiscardFont();
   152     aGc.DiscardFont();
   158     }
   153 
   159 
   154     if( TLocale().TimeFormat() == ETime12 )
   160 // -----------------------------------------------------------------------------
   155         {
   161 // CXnClockFaceDigital::CreateFontL
   156         TRect ampmRect( aRect );
   162 // -----------------------------------------------------------------------------
   157         TInt ampmHeight( ampmFont->TextPaneHeight() );
   163 //
   158 
   164 const CAknLayoutFont* CXnClockFaceDigital::CreateFontL( CXnClockAdapter& aAdapter,
   159         if( mirrored )
   165         CXnNodePluginIf& aNode,
       
   166         TXnClockFontType aFontType)
       
   167     {    
       
   168     if ( aFontType == EClock )
       
   169         {
       
   170         if ( !iClockFont )
       
   171             {
   160             {
   172             aAdapter.CreateFontL( aNode, iClockFont );
   161             align = CGraphicsContext::ELeft;
   173             }
   162             }
   174         return CAknLayoutFont::AsCAknLayoutFontOrNull( iClockFont );
   163         else
   175         }
       
   176     else
       
   177         {
       
   178         if ( !iAmpmFont )
       
   179             {
   164             {
   180             aAdapter.CreateFontL( aNode, iAmpmFont );
   165             align = CGraphicsContext::ERight;
   181             }
   166             }
   182         return CAknLayoutFont::AsCAknLayoutFontOrNull( iAmpmFont );
   167 
   183         }
   168         ampmRect.iTl.iY += ampmHeight;
   184     }
   169 
   185 
   170         aGc.UseFont( ampmFont );
   186 // -----------------------------------------------------------------------------
   171 
   187 // CXnClockFaceDigital::CreateColorL
   172         aGc.DrawText( ampm, ampmRect, offset, align, margin );
   188 // -----------------------------------------------------------------------------
   173 
   189 //
   174         aGc.DiscardFont();
   190 const TRgb& CXnClockFaceDigital::CreateColorL( CXnClockAdapter& aAdapter,
   175         }
   191         CXnNodePluginIf& aNode,
   176 
   192         TXnClockFontType aFontType )
   177     if( date )
   193     {
   178         {
   194     if ( aFontType == EClock )
   179         const TDesC* dateStr( &KNullDesC() );
   195         {
   180 
   196         if ( !iIsFaceColorSet )
   181         CXnText* textIf( NULL );
       
   182 
       
   183         XnComponentInterface::MakeInterfaceL( textIf, date->AppIfL() );
       
   184 
       
   185         if( textIf )
   197             {
   186             {
   198             aAdapter.CreateColorL( aNode, iFaceColor );
   187             dateStr = textIf->Text();
   199             iIsFaceColorSet = ETrue;
       
   200             }
   188             }
   201         return iFaceColor;
   189 
   202         }
   190         // Measure the full width of the time string 
   203     else
   191         TInt dateWidth( AknBidiTextUtils::MeasureTextBoundsWidth( *dateFont, *dateStr, 
   204         {
   192             CFont::TMeasureTextInput::EFVisualOrder ) );
   205         if ( !iIsAmpmColorSet )
   193 
   206             {
   194         TInt width( aRect.Width() - dateWidth );
   207             aAdapter.CreateColorL( aNode, iAmpmColor );
   195         TInt margin( width / 2 );
   208             iIsAmpmColorSet = ETrue;
   196 
   209             }
   197         // Move date string down by text pane height and 5% of rect height
   210         return iAmpmColor;
   198         offset += dateFont->TextPaneHeight() + ( aRect.Height() / 20 );
   211         }
   199 
   212     }
   200         aGc.UseFont( dateFont );
   213 
   201 
   214 // -----------------------------------------------------------------------------
   202         aGc.DrawText( *dateStr, aRect, offset, align, margin );
   215 // CXnClockFaceDigital::ResetFont
   203 
   216 // -----------------------------------------------------------------------------
   204         aGc.DiscardFont();
   217 //
   205         }
   218 void CXnClockFaceDigital::ResetFont()
       
   219     {
       
   220     iClockFont = iAmpmFont = NULL;
       
   221     iIsFaceColorSet = iIsAmpmColorSet = EFalse;
       
   222     }
   206     }
   223 
   207 
   224 // ============================ MEMBER FUNCTIONS ===============================
   208 // ============================ MEMBER FUNCTIONS ===============================
   225 
   209 
   226 // -----------------------------------------------------------------------------
   210 // -----------------------------------------------------------------------------
   228 // C++ default constructor can NOT contain any code, that
   212 // C++ default constructor can NOT contain any code, that
   229 // might leave.
   213 // might leave.
   230 // -----------------------------------------------------------------------------
   214 // -----------------------------------------------------------------------------
   231 //
   215 //
   232 CXnClockFaceAnalog::CXnClockFaceAnalog()     
   216 CXnClockFaceAnalog::CXnClockFaceAnalog()     
   233     :   iFaceAdjustmentValue( KErrNotFound )
       
   234     {
   217     {
   235     }
   218     }
   236 
   219 
   237 // -----------------------------------------------------------------------------
   220 // -----------------------------------------------------------------------------
   238 // CXnClockFaceAnalog::ConstructL
   221 // CXnClockFaceAnalog::ConstructL
   268     {
   251     {
   269     }
   252     }
   270 
   253 
   271 // -----------------------------------------------------------------------------
   254 // -----------------------------------------------------------------------------
   272 // CXnClockFaceAnalog::DrawL
   255 // CXnClockFaceAnalog::DrawL
       
   256 // (other items were commented in a header).
   273 // -----------------------------------------------------------------------------
   257 // -----------------------------------------------------------------------------
   274 //
   258 //
   275 void CXnClockFaceAnalog::DrawL( CXnClockAdapter& /*aAdapter*/, CWindowGc& aGc, 
   259 void CXnClockFaceAnalog::DrawL( CXnClockAdapter& /*aAdapter*/, CWindowGc& aGc, 
   276         CXnNodePluginIf& aNode, const TTime& aTime, CXnNodePluginIf* /*aAmpm*/ )
   260     const TRect& aRect, const TTime& aTime )
   277     {    
   261     {
   278     TRect faceRect( aNode.Rect() );
   262     TSize faceSize( aRect.Size() );
   279     
   263     
   280     TDateTime dateTime( aTime.DateTime() );
   264     TDateTime dateTime( aTime.DateTime() );
   281     
   265     
   282     MAknsSkinInstance* skin( AknsUtils::SkinInstance() );
   266     MAknsSkinInstance* skin( AknsUtils::SkinInstance() );
   283  
   267  
   293     // If there is no bitmap, don't draw
   277     // If there is no bitmap, don't draw
   294     if( !skinBmp )
   278     if( !skinBmp )
   295         {
   279         {
   296         return;
   280         return;
   297         }
   281         }
   298     
   282 
   299     TInt value( FaceAdjustmentValueL( aNode ) );
   283     User::LeaveIfError( AknIconUtils::SetSize( skinBmp, faceSize ) );
   300     
       
   301     TSize growthSize( value, 0 );
       
   302     faceRect.Grow( growthSize );
       
   303 
       
   304     User::LeaveIfError( AknIconUtils::SetSize( skinBmp, faceRect.Size() ) );
       
   305 
   284 
   306     if( skinMask )
   285     if( skinMask )
   307         {
   286         {
   308         User::LeaveIfError( AknIconUtils::SetSize( skinMask, faceRect.Size() ) );
   287         User::LeaveIfError( AknIconUtils::SetSize( skinMask, faceSize ) );
   309         
   288         
   310         aGc.BitBltMasked( faceRect.iTl,
   289         aGc.BitBltMasked( aRect.iTl,
   311                           skinBmp,
   290                           skinBmp,
   312                           TRect( TPoint( 0, 0 ), skinBmp->SizeInPixels() ),
   291                           TRect( TPoint( 0, 0 ), skinBmp->SizeInPixels() ),
   313                           skinMask,
   292                           skinMask,
   314                           ETrue );
   293                           ETrue );
   315         }
   294         }
   316     else
   295     else
   317         {
   296         {
   318         aGc.BitBlt( faceRect.iTl, skinBmp );
   297         aGc.BitBlt( aRect.iTl, skinBmp );
   319         }
   298         }
   320 
   299 
   321     aGc.SetBrushStyle( CGraphicsContext::ENullBrush );
   300     aGc.SetBrushStyle( CGraphicsContext::ENullBrush );
   322     aGc.SetPenStyle( CGraphicsContext::ESolidPen );
   301     aGc.SetPenStyle( CGraphicsContext::ESolidPen );
   323   
   302   
   324     DrawHandsL( aGc, aNode.Rect(), dateTime );
   303     DrawHandsL( aGc, aRect, dateTime );
   325     }
   304     }
   326             
   305             
   327 // -----------------------------------------------------------------------------
   306 // -----------------------------------------------------------------------------
   328 // CXnClockFaceAnalog::DrawHands
   307 // CXnClockFaceAnalog::DrawHands
       
   308 // (other items were commented in a header).
   329 // -----------------------------------------------------------------------------
   309 // -----------------------------------------------------------------------------
   330 //
   310 //
   331 void CXnClockFaceAnalog::DrawHandsL( CWindowGc& aGc,
   311 void CXnClockFaceAnalog::DrawHandsL( CWindowGc& aGc,
   332                                      const TRect& aRect,
   312                                      const TRect& aRect,
   333                                      const TDateTime& aDateTime )                                    
   313                                      const TDateTime& aDateTime )                                    
   373                       minbitmap,
   353                       minbitmap,
   374                       TRect( TPoint( 0, 0 ), minbitmap->SizeInPixels() ),
   354                       TRect( TPoint( 0, 0 ), minbitmap->SizeInPixels() ),
   375                       minmask,
   355                       minmask,
   376                       EFalse );
   356                       EFalse );
   377     }
   357     }
   378 
       
   379 // -----------------------------------------------------------------------------
       
   380 // CXnClockFaceAnalog::FaceAdjustmentValueL
       
   381 // -----------------------------------------------------------------------------
       
   382 //
       
   383 TInt CXnClockFaceAnalog::FaceAdjustmentValueL( CXnNodePluginIf& aNode )
       
   384     {
       
   385     if( iFaceAdjustmentValue == KErrNotFound )
       
   386         {
       
   387         CXnProperty* prop( aNode.GetPropertyL( XnPropertyNames::clock::KFaceAdjustmentValue ) );
       
   388         
       
   389         if( prop )
       
   390             {        
       
   391             TInt value = static_cast<TInt>( prop->FloatValueL() );
       
   392             
       
   393             if( value > KErrNotFound )
       
   394                 {
       
   395                 iFaceAdjustmentValue = value;
       
   396                 }
       
   397             }
       
   398         
       
   399         if( iFaceAdjustmentValue <= KErrNotFound )
       
   400             {
       
   401             iFaceAdjustmentValue = KDefaultFaceAdjustmentValue;
       
   402             }
       
   403         }
       
   404     
       
   405     return iFaceAdjustmentValue;
       
   406     }
       
   407 	
       
   408 // CXnClockFaceAnalog::ResetFont
       
   409 // -----------------------------------------------------------------------------
       
   410 //
       
   411 void CXnClockFaceAnalog::ResetFont()
       
   412     {
       
   413     }
       
   414     
   358     
   415 //  End of File
   359 //  End of File