messagingappbase/msgeditor/viewsrc/MsgCaptionedHighlight.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     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:  MsgCaptionedHighlight implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // ========== INCLUDE FILES ================================
       
    21 
       
    22 #include <barsread.h>                      // for TResourceReader
       
    23 #include <eiklabel.h>                      // for CEikLabel
       
    24 #include <eikenv.h>                        // for CEikonEnv
       
    25 #include <eikedwin.h>                      // for TClipboardFunc
       
    26 #include <txtrich.h>                       // for CRichText
       
    27 #include <AknUtils.h>                      // for AknUtils
       
    28 #include <aknenv.h>                        // for CAknEnv
       
    29 #include <AknDef.h>
       
    30 #include <AknLayoutFont.h>
       
    31 #include <applayout.cdl.h> // LAF
       
    32 #include <aknlayoutscalable_apps.cdl.h>
       
    33 #include <aknlayoutscalable_avkon.cdl.h>
       
    34 
       
    35 #include <AknsDrawUtils.h>                 // for Skinned drawing
       
    36 #include <AknsBasicBackgroundControlContext.h>					
       
    37 
       
    38 #include "MsgEditorCommon.h"
       
    39 #include "MsgBaseControl.h"
       
    40 #include "MsgHeader.h"
       
    41 #include "MsgCaptionedHighlight.h"
       
    42 #include "MsgExpandableControl.h"
       
    43 
       
    44 // ========== LOCAL CONSTANTS AND MACROS ===================
       
    45 
       
    46 _LIT( KMsgEditIndicator, ":" );
       
    47 
       
    48 // ---------------------------------------------------------
       
    49 // CMsgCaptionedHighlight::CMsgCaptionedHighlight
       
    50 // ---------------------------------------------------------
       
    51 //
       
    52 CMsgCaptionedHighlight* CMsgCaptionedHighlight::NewL( const CMsgHeader& aParent )
       
    53     {
       
    54     CMsgCaptionedHighlight* self = new ( ELeave )
       
    55         CMsgCaptionedHighlight( aParent );
       
    56     CleanupStack::PushL( self );
       
    57     self->ConstructL();
       
    58     CleanupStack::Pop();
       
    59     return self;
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------
       
    63 // CMsgCaptionedHighlight::HandleResourceChange
       
    64 //
       
    65 // Updates layout related parameter when layout is changed and
       
    66 // skinned text color when skin is changed.
       
    67 // ---------------------------------------------------------
       
    68 //
       
    69 void CMsgCaptionedHighlight::HandleResourceChange( TInt aType )
       
    70     {
       
    71 	if ( aType == KEikDynamicLayoutVariantSwitch )
       
    72         {
       
    73         ResolveLayouts();
       
    74         }
       
    75     else if ( aType == KAknsMessageSkinChange )
       
    76         {
       
    77         UpdateTextColor();
       
    78         }
       
    79         
       
    80     CCoeControl::HandleResourceChange( aType );
       
    81     }
       
    82 
       
    83 // ---------------------------------------------------------
       
    84 // CMsgCaptionedHighlight::CMsgCaptionedHighlight
       
    85 // ---------------------------------------------------------
       
    86 //
       
    87 CMsgCaptionedHighlight::CMsgCaptionedHighlight( const CMsgHeader& aParent )
       
    88     : iParent( aParent )
       
    89     {
       
    90     }
       
    91 
       
    92 // ---------------------------------------------------------
       
    93 // CMsgCaptionedHighlight::ConstructL
       
    94 //
       
    95 // Initializes layout related parameters and skin text color.
       
    96 // Connects the control to parent control and sets it ready
       
    97 // to be drawn on the screen.
       
    98 // ---------------------------------------------------------
       
    99 //
       
   100 void CMsgCaptionedHighlight::ConstructL()
       
   101     {
       
   102     ResolveLayouts();
       
   103     UpdateTextColor();
       
   104     SetContainerWindowL( iParent );
       
   105     ActivateL();
       
   106     }
       
   107 
       
   108 // ---------------------------------------------------------
       
   109 // CMsgCaptionedHighlight::ResolveLayouts
       
   110 // ---------------------------------------------------------
       
   111 //
       
   112 void CMsgCaptionedHighlight::ResolveLayouts()
       
   113     {    
       
   114     TRect dataPane = MsgEditorCommons::MsgDataPane();
       
   115     TAknLayoutRect msgTextPane;
       
   116     msgTextPane.LayoutRect(
       
   117         dataPane,
       
   118         AknLayoutScalable_Apps::msg_text_pane( 0 ).LayoutLine() );
       
   119     TAknLayoutRect msgHeaderPane;
       
   120     msgHeaderPane.LayoutRect(
       
   121         msgTextPane.Rect(),
       
   122         AknLayoutScalable_Apps::msg_header_pane().LayoutLine() );
       
   123     iFrame.LayoutRect(
       
   124         msgHeaderPane.Rect(),
       
   125         AknLayoutScalable_Apps::input_focus_pane_cp07().LayoutLine() );
       
   126     iText.LayoutText(
       
   127         msgHeaderPane.Rect(),
       
   128         AknLayoutScalable_Apps::msg_header_pane_t1( 0 ).LayoutLine() );
       
   129     iVertBar.LayoutRect(
       
   130         dataPane,
       
   131         AknLayoutScalable_Avkon::bg_list_pane_g4( 2 ).LayoutLine() );
       
   132     
       
   133     iBaseLineOffset = MsgEditorCommons::MsgBaseLineOffset();
       
   134     
       
   135     const CAknLayoutFont* layoutFont = CAknLayoutFont::AsCAknLayoutFontOrNull( iText.Font() );
       
   136     
       
   137     if ( layoutFont )
       
   138         {
       
   139         iTextBaselineOffset =  layoutFont->TextPaneTopToBaseline();
       
   140         }
       
   141     else
       
   142         {
       
   143         iTextBaselineOffset = ( ( iText.Font()->HeightInPixels() + iBaseLineOffset ) / 2 ) - 
       
   144                                 iText.Font()->DescentInPixels();
       
   145         }
       
   146     
       
   147     // Gap between the header control and text editor control.
       
   148     iTextGap = iText.TextRect().iTl.iY - msgHeaderPane.Rect().iTl.iY;
       
   149     }
       
   150 
       
   151 
       
   152 // ---------------------------------------------------------
       
   153 // CMsgCaptionedHighlight::Draw
       
   154 // ---------------------------------------------------------
       
   155 //
       
   156 EXPORT_C void CMsgCaptionedHighlight::Draw(const TRect& /*aRect*/) const
       
   157     {
       
   158     CWindowGc& gc = SystemGc();
       
   159 
       
   160     TRect rect( iParent.Rect() );
       
   161     TRect headerRect( iFrame.Rect().iTl.iX,
       
   162                       iParent.Rect().iTl.iY,
       
   163                       iFrame.Rect().iBr.iX,
       
   164                       iParent.Rect().iBr.iY );
       
   165 
       
   166     // clear top (0,0,176,6) area and draw top part of vertical bar.
       
   167     TRect clearRect( 0, 0, rect.iBr.iX, iBaseLineOffset );
       
   168     
       
   169     if( !AknsDrawUtils::Background( AknsUtils::SkinInstance(), 
       
   170                                     AknsDrawUtils::ControlContext( this ), 
       
   171                                     this, 
       
   172                                     gc, 
       
   173                                     clearRect ) )
       
   174         {        
       
   175     	gc.SetBrushColor( AKN_LAF_COLOR( 0 ) );
       
   176 		gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   177 		gc.SetPenStyle( CGraphicsContext::ENullPen );
       
   178 		gc.DrawRect( clearRect );
       
   179 		}
       
   180 
       
   181     // Reset default brush & pen styles
       
   182     gc.SetBrushStyle( CGraphicsContext::ENullBrush );
       
   183     gc.SetPenStyle( CGraphicsContext::ESolidPen );
       
   184 
       
   185     CMsgBaseControl* focused = iParent.FocusedControl();
       
   186     if ( focused && 
       
   187          focused->IsFocused() && 
       
   188          !focused->IsReadOnly() &&
       
   189          focused->Rect().iBr.iY > clearRect.iBr.iY &&
       
   190          focused->Rect().iTl.iY < MsgEditorCommons::MsgHeaderPane().Height() )
       
   191         {
       
   192         TRect focusedRect(
       
   193             headerRect.iTl.iX,
       
   194             focused->Rect().iTl.iY,
       
   195             headerRect.iBr.iX,
       
   196             focused->Rect().iBr.iY );
       
   197             DrawFrame( gc, focusedRect );
       
   198         }    
       
   199     }
       
   200 
       
   201 // ---------------------------------------------------------
       
   202 // CMsgCaptionedHighlight::DrawFrame
       
   203 //
       
   204 // Draws the focus highlight around currently focused field in editor.
       
   205 // Also performs colon drawing if button is not shown in the
       
   206 // field instead of caption (as is the case when touch screen
       
   207 // is present). Colon is not drawn either if the control's top 
       
   208 // position is not fully shown (i.e. colon is not shown if tall
       
   209 // control is scrolled so that first line is not shown). 
       
   210 // Colon is drawn with the text color from current skin and it is
       
   211 // drawn after focus highlight so that it would seem to appear
       
   212 // above highlight. 
       
   213 // ---------------------------------------------------------
       
   214 //
       
   215 void CMsgCaptionedHighlight::DrawFrame( CWindowGc& aGc, const TRect& aRect ) const
       
   216     {
       
   217     TRect drawRect( aRect );
       
   218     TBool drawColon = ETrue;
       
   219     
       
   220     CMsgExpandableControl* focusedControl = 
       
   221                         static_cast<CMsgExpandableControl*>( iParent.FocusedControl() );
       
   222                         
       
   223     if ( focusedControl &&
       
   224          focusedControl->Button() )
       
   225         {
       
   226         drawColon = EFalse;
       
   227         }
       
   228     
       
   229     if ( drawRect.iTl.iY < iBaseLineOffset )
       
   230         {
       
   231         drawRect.iTl.iY = iBaseLineOffset;
       
   232         drawColon = EFalse; // the control is not wholly in the screen
       
   233         }
       
   234         
       
   235     TInt maxBodyHeight( MsgEditorCommons::EditorViewHeigth() );
       
   236     if ( drawRect.iBr.iY > maxBodyHeight )
       
   237         {
       
   238         drawRect.iBr.iY = maxBodyHeight;
       
   239         }
       
   240         
       
   241     TAknLayoutRect tl;
       
   242     tl.LayoutRect( drawRect, AknLayoutScalable_Avkon::input_focus_pane_g2().LayoutLine() );
       
   243     
       
   244     TAknLayoutRect br;
       
   245     br.LayoutRect( drawRect, AknLayoutScalable_Avkon::input_focus_pane_g5().LayoutLine() );
       
   246 
       
   247     TRect innerRect = TRect(
       
   248         drawRect.iTl.iX + tl.Rect().Width(),
       
   249         drawRect.iTl.iY + tl.Rect().Height(),
       
   250         drawRect.iBr.iX - br.Rect().Width(),
       
   251         drawRect.iBr.iY - br.Rect().Height() );
       
   252 
       
   253   
       
   254         
       
   255     // Draw ':' for edit indicator.
       
   256     if( drawColon )
       
   257         {
       
   258         TPoint point( iVertBar.Rect().iTl.iX, drawRect.iTl.iY + iTextBaselineOffset + iTextGap );
       
   259         if ( point.iY > drawRect.iTl.iY )
       
   260             {
       
   261             aGc.SetPenColor( iTextColor );
       
   262             aGc.UseFont( iText.Font() );
       
   263             aGc.DrawText( KMsgEditIndicator, point );
       
   264             }
       
   265         }
       
   266     }
       
   267 
       
   268 
       
   269 // ---------------------------------------------------------
       
   270 // CMsgCaptionedHighlight::UpdateTextColor
       
   271 //
       
   272 // Text color used to draw colon is skinned. 
       
   273 // It uses the same text color from skin as caption.
       
   274 // ---------------------------------------------------------
       
   275 //
       
   276 void CMsgCaptionedHighlight::UpdateTextColor()
       
   277     {
       
   278     TRgb textColor = iText.Color();
       
   279     if ( AknsUtils::GetCachedColor( AknsUtils::SkinInstance(),
       
   280                                     textColor,
       
   281                                     KAknsIIDQsnTextColors,
       
   282                                     EAknsCIQsnTextColorsCG6 ) != KErrNone )
       
   283         {
       
   284         textColor = AKN_LAF_COLOR_STATIC( 215 );
       
   285         }
       
   286 
       
   287     iTextColor = textColor;
       
   288     }
       
   289 
       
   290 //  End of File