idlehomescreen/xmluirendering/renderingplugins/xnclockfactory/src/xnclockface.cpp
branchRCL_3
changeset 12 9674c1a575e9
parent 0 f72a12da539e
child 17 b8fae6b8a148
equal deleted inserted replaced
11:ff572dfe6d86 12:9674c1a575e9
    89 // (other items were commented in a header).
    89 // (other items were commented in a header).
    90 // -----------------------------------------------------------------------------
    90 // -----------------------------------------------------------------------------
    91 //
    91 //
    92 void CXnClockFaceDigital::DrawL( CXnClockAdapter& aAdapter, CWindowGc& aGc, 
    92 void CXnClockFaceDigital::DrawL( CXnClockAdapter& aAdapter, CWindowGc& aGc, 
    93     const TRect& aRect, const TTime& aTime )
    93     const TRect& aRect, const TTime& aTime )
    94     {        
    94     {
    95     TBuf< KMaxTimeFormatSpec > time;
    95     TBuf< KMaxTimeFormatSpec > time;
    96     aTime.FormatL( time, KTimeFormat() );         
    96     aTime.FormatL( time, KTimeFormat() );
    97 
    97 
    98     TBuf< KMaxTimeFormatSpec > ampm;
    98     TBuf< KMaxTimeFormatSpec > ampm;
    99     aTime.FormatL( ampm, KAmPmFormat() );
    99     aTime.FormatL( ampm, KAmPmFormat() );
   100     
   100 
   101     AknTextUtils::LanguageSpecificNumberConversion( time );
   101     AknTextUtils::LanguageSpecificNumberConversion( time );
   102     
   102 
   103     const CAknLayoutFont* clockFont( 
   103     const CAknLayoutFont* clockFont( 
   104             aAdapter.FontL( CXnClockAdapter::EDigitalFont ) );
   104             aAdapter.FontL( CXnClockAdapter::EDigitalFont ) );
   105     
   105 
   106     const CAknLayoutFont* ampmFont( 
   106     const CAknLayoutFont* ampmFont( 
   107             aAdapter.FontL( CXnClockAdapter::EAmPmFont ) );
   107             aAdapter.FontL( CXnClockAdapter::EAmPmFont ) );
   108 
   108 
   109     const CAknLayoutFont* dateFont( 
   109     const CAknLayoutFont* dateFont( 
   110             aAdapter.FontL( CXnClockAdapter::EDateFont ) );
   110             aAdapter.FontL( CXnClockAdapter::EDateFont ) );
   111     
   111 
   112     const TRgb& color( aAdapter.TextColorL() );
   112     const TRgb& color( aAdapter.TextColorL() );
   113     
   113 
   114     CXnNodePluginIf* date( aAdapter.Date() );
   114     CXnNodePluginIf* date( aAdapter.Date() );
   115         
   115 
   116     TInt ampmWidth( 0 );
   116     TInt ampmWidth( 0 );
   117     
   117 
   118     if( TLocale().TimeFormat() == ETime12 )
   118     if( TLocale().TimeFormat() == ETime12 )
   119         {                
   119         {
   120         // Measure the full width of the ampm string 
   120         // Measure the full width of the ampm string 
   121         ampmWidth = AknBidiTextUtils::MeasureTextBoundsWidth( *ampmFont, ampm, 
   121         ampmWidth = AknBidiTextUtils::MeasureTextBoundsWidth( *ampmFont, ampm, 
   122             CFont::TMeasureTextInput::EFVisualOrder );                                    
   122             CFont::TMeasureTextInput::EFVisualOrder );
   123         }
   123         }
   124     
   124 
       
   125 
   125     const TInt deltaHeight( aRect.Height() - clockFont->TextPaneHeight() );
   126     const TInt deltaHeight( aRect.Height() - clockFont->TextPaneHeight() );
   126     TInt offset( clockFont->TextPaneTopToBaseline() + deltaHeight / 2 );
   127     TInt offset( clockFont->TextPaneTopToBaseline() + deltaHeight / 2 );
   127     
   128 
   128     if( date )
   129     if( date )
   129         {
   130         {
   130         // When date string is shown, time string must be lifted up
   131         // When date string is shown, time string must be lifted up
   131         offset -= ( dateFont->TextPaneHeight() / 2 );
   132         offset -= ( dateFont->TextPaneHeight() / 2 );
   132         }
   133         }
   133     
   134 
   134     // Measure the full width of the time string 
   135     // Measure the full width of the time string 
   135     TInt textWidth( AknBidiTextUtils::MeasureTextBoundsWidth( *clockFont, time, 
   136     TInt textWidth( AknBidiTextUtils::MeasureTextBoundsWidth( *clockFont, time, 
   136         CFont::TMeasureTextInput::EFVisualOrder ) );
   137         CFont::TMeasureTextInput::EFVisualOrder ) );
   137     
   138 
   138     TInt extraWidth( aRect.Width() - ampmWidth - textWidth );
   139     TInt extraWidth( aRect.Width() - textWidth );
   139     
   140 
   140     TInt margin( extraWidth / 2 );
   141     TInt margin( extraWidth / 2 );
   141    
   142 
   142     aGc.SetPenColor( color );
   143     aGc.SetPenColor( color );
   143     
   144 
   144     aGc.UseFont( clockFont );
   145     aGc.UseFont( clockFont );
   145 
   146 
   146     CGraphicsContext::TTextAlign align;
   147     CGraphicsContext::TTextAlign align;
   147     
   148 
   148     TBool mirrored( AknLayoutUtils::LayoutMirrored() );
   149     TBool mirrored( AknLayoutUtils::LayoutMirrored() );
   149     
   150 
   150     if( mirrored )
   151     if( mirrored )
   151         {
   152         {
   152         align = CGraphicsContext::ERight;
   153         align = CGraphicsContext::ERight;
   153         }
   154         }
   154     else
   155     else
   155         {
   156         {
   156         align = CGraphicsContext::ELeft;
   157         align = CGraphicsContext::ELeft;
   157         }        
   158         }
   158        
   159 
   159     aGc.DrawText( time, aRect, offset, align, margin );
   160     aGc.DrawText( time, aRect, offset, align, margin );
   160 
   161 
   161     aGc.DiscardFont();
   162     aGc.DiscardFont();
   162     
   163 
   163     if( TLocale().TimeFormat() == ETime12 )
   164     if( TLocale().TimeFormat() == ETime12 )
   164         {
   165         {
   165         TRect ampmRect( aRect );
   166         TRect ampmRect( aRect );
   166     
   167         TInt ampmHeight( ampmFont->TextPaneHeight() );
       
   168 
   167         if( mirrored )
   169         if( mirrored )
   168             {
   170             {
   169             ampmRect.iBr.iX -= ( textWidth + ( margin / 2 ) );
   171             align = CGraphicsContext::ELeft;
   170             }
   172             }
   171         else
   173         else
   172             {
   174             {
   173             ampmRect.iTl.iX += ( textWidth + ( margin / 2 ) );
   175             align = CGraphicsContext::ERight;
   174             }            
   176             }
   175                             
   177 
   176         extraWidth = ampmRect.Width() - ampmWidth;
   178         ampmRect.iTl.iY += ampmHeight;
   177         
       
   178         margin = extraWidth / 2;
       
   179 
   179 
   180         aGc.UseFont( ampmFont );
   180         aGc.UseFont( ampmFont );
   181                 
   181 
   182         aGc.DrawText( ampm, ampmRect, offset, align, margin );
   182         aGc.DrawText( ampm, ampmRect, offset, align, margin );
   183         
   183 
   184         aGc.DiscardFont();
   184         aGc.DiscardFont();
   185         }    
   185         }
   186     
   186 
   187     if( date )
   187     if( date )
   188         {
   188         {
   189         const TDesC* dateStr( &KNullDesC() );
   189         const TDesC* dateStr( &KNullDesC() );
   190                     
   190 
   191         CXnText* textIf( NULL );
   191         CXnText* textIf( NULL );
   192 
   192 
   193         XnComponentInterface::MakeInterfaceL( textIf, date->AppIfL() );                                 
   193         XnComponentInterface::MakeInterfaceL( textIf, date->AppIfL() );
   194 
   194 
   195         if( textIf )
   195         if( textIf )
   196             {
   196             {
   197             dateStr = textIf->Text();
   197             dateStr = textIf->Text();
   198             }        
   198             }
   199                 
   199 
   200         // Measure the full width of the time string 
   200         // Measure the full width of the time string 
   201         TInt dateWidth( AknBidiTextUtils::MeasureTextBoundsWidth( *dateFont, *dateStr, 
   201         TInt dateWidth( AknBidiTextUtils::MeasureTextBoundsWidth( *dateFont, *dateStr, 
   202             CFont::TMeasureTextInput::EFVisualOrder ) );
   202             CFont::TMeasureTextInput::EFVisualOrder ) );
   203         
   203 
   204         TInt width( aRect.Width() - dateWidth );
   204         TInt width( aRect.Width() - dateWidth );
   205         TInt margin( width / 2 );
   205         TInt margin( width / 2 );
   206         
   206 
   207         // Move date string down by text pane height and 5% of rect height
   207         // Move date string down by text pane height and 5% of rect height
   208         offset += dateFont->TextPaneHeight() + ( aRect.Height() / 20 );
   208         offset += dateFont->TextPaneHeight() + ( aRect.Height() / 20 );
   209         
   209 
   210         aGc.UseFont( dateFont );
   210         aGc.UseFont( dateFont );
   211                      
   211 
   212         aGc.DrawText( *dateStr, aRect, offset, align, margin );
   212         aGc.DrawText( *dateStr, aRect, offset, align, margin );
   213         
   213 
   214         aGc.DiscardFont();        
   214         aGc.DiscardFont();
   215         }    
   215         }
   216     }
   216     }
   217 
   217 
   218 // ============================ MEMBER FUNCTIONS ===============================
   218 // ============================ MEMBER FUNCTIONS ===============================
   219 
   219 
   220 // -----------------------------------------------------------------------------
   220 // -----------------------------------------------------------------------------