messagingappbase/msgeditor/viewsrc/MsgEditorCustomDraw.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2006 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:  MsgEditorCustomDraw implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // ========== INCLUDE FILES ================================
       
    21 #include "MsgEditorCustomDraw.h"
       
    22 
       
    23 #include <gulicon.h>
       
    24 #include <AknUtils.h>                      
       
    25 #include <eikedwin.h>
       
    26 #include "MsgEditor.hrh"                   // for typedefs
       
    27 
       
    28 #include <AknsUtils.h>
       
    29 #include <applayout.cdl.h>                 
       
    30 #include <aknlayoutscalable_apps.cdl.h>
       
    31 
       
    32 #include <msgeditor.mbg>
       
    33 
       
    34 #include "MsgEditorCommon.h"
       
    35 
       
    36 // ========== EXTERNAL DATA STRUCTURES =====================
       
    37 
       
    38 // ========== EXTERNAL FUNCTION PROTOTYPES =================
       
    39 
       
    40 // ========== CONSTANTS ====================================
       
    41 
       
    42 // ========== MACROS =======================================
       
    43 
       
    44 // ========== LOCAL CONSTANTS AND MACROS ===================
       
    45 
       
    46 // ========== MODULE DATA STRUCTURES =======================
       
    47 
       
    48 // ========== LOCAL FUNCTION PROTOTYPES ====================
       
    49 
       
    50 // ========== LOCAL FUNCTIONS ==============================
       
    51 
       
    52 // ========== MEMBER FUNCTIONS =============================
       
    53 
       
    54 // ---------------------------------------------------------
       
    55 // CMsgEditorCustomDraw::NewL
       
    56 // ---------------------------------------------------------
       
    57 //
       
    58 CMsgEditorCustomDraw* CMsgEditorCustomDraw::NewL( const MFormCustomDraw* aParentCustomDraw,
       
    59                                                   const CEikEdwin* aParentControl,const TInt aControlType  )
       
    60     {
       
    61     CMsgEditorCustomDraw* self = new (ELeave) CMsgEditorCustomDraw( aParentCustomDraw,
       
    62                                                                     aParentControl,aControlType );
       
    63     
       
    64     CleanupStack::PushL( self );
       
    65     self->ConstructL();
       
    66     CleanupStack::Pop( self );
       
    67     
       
    68     return self;
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------
       
    72 // CMsgEditorCustomDraw::ConstructL
       
    73 // ---------------------------------------------------------
       
    74 //
       
    75 void CMsgEditorCustomDraw::ConstructL()
       
    76     {
       
    77     iIcon = AknsUtils::CreateGulIconL( AknsUtils::SkinInstance(),
       
    78                                        KAknsIIDQgnGrafLineMessageHorizontal,
       
    79                                        KMsgEditorMbm,
       
    80                                        EMbmMsgeditorQgn_graf_line_message_horizontal,
       
    81                                        EMbmMsgeditorQgn_graf_line_message_horizontal_mask );
       
    82     
       
    83     ResolveLayouts();
       
    84     }
       
    85 
       
    86 
       
    87 // ---------------------------------------------------------
       
    88 // CMsgEditorCustomDraw::CMsgEditorCustomDraw
       
    89 // ---------------------------------------------------------
       
    90 //
       
    91 CMsgEditorCustomDraw::CMsgEditorCustomDraw( const MFormCustomDraw* aParentCustomDraw,
       
    92                                             const CEikEdwin* aParentControl,const TInt aControlType ) :
       
    93     iParentCustomDraw( aParentCustomDraw ),
       
    94     iParentControl( aParentControl ),
       
    95     iControlType(aControlType)
       
    96     {
       
    97     }
       
    98 
       
    99 // ---------------------------------------------------------
       
   100 // CMsgEditorCustomDraw::~CMsgEditorCustomDraw
       
   101 // ---------------------------------------------------------
       
   102 //
       
   103 CMsgEditorCustomDraw::~CMsgEditorCustomDraw()
       
   104     {
       
   105     delete iIcon;
       
   106     }
       
   107 
       
   108 // ---------------------------------------------------------
       
   109 // CMsgEditorCustomDraw::ResolveLayouts
       
   110 // ---------------------------------------------------------
       
   111 //
       
   112 void CMsgEditorCustomDraw::ResolveLayouts()
       
   113     {
       
   114     TRect dataPane = MsgEditorCommons::MsgDataPane();
       
   115 
       
   116     TAknLayoutRect msgTextPane;
       
   117     msgTextPane.LayoutRect( dataPane,
       
   118                             AknLayoutScalable_Apps::msg_text_pane( 0 ).LayoutLine() );
       
   119         
       
   120     TAknLayoutRect msgBodyPane;
       
   121     msgBodyPane.LayoutRect( msgTextPane.Rect(),
       
   122                             AknLayoutScalable_Apps::msg_body_pane().LayoutLine() );
       
   123         
       
   124     TAknLayoutRect lineLayout;
       
   125     lineLayout.LayoutRect( msgBodyPane.Rect(),
       
   126                            AknLayoutScalable_Apps::msg_body_pane_g1().LayoutLine() );
       
   127     
       
   128     AknIconUtils::SetSize( iIcon->Bitmap(), 
       
   129                            lineLayout.Rect().Size(), 
       
   130                            EAspectRatioNotPreserved );
       
   131 
       
   132     TInt lineOffset = MsgEditorCommons::MsgBaseLineOffset();
       
   133     
       
   134     iLineDelta = MsgEditorCommons::MsgBaseLineDelta();
       
   135     
       
   136     // Calculate first line rectangle's correct position.
       
   137     iFirstLineRect = TRect( TPoint( lineLayout.Rect().iTl.iX,
       
   138                                     lineOffset + iLineDelta - lineLayout.Rect().Height() ),
       
   139                                     lineLayout.Rect().Size() );
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------
       
   143 // CMsgEditorCustomDraw::DrawBackground
       
   144 // ---------------------------------------------------------
       
   145 //
       
   146 void CMsgEditorCustomDraw::DrawBackground( const TParam& aParam,
       
   147                                            const TRgb& aRgb,
       
   148                                            TRect& aDrawn ) const 
       
   149     {
       
   150     iParentCustomDraw->DrawBackground( aParam, aRgb, aDrawn );
       
   151     
       
   152     if ( !iParentControl->IsReadOnly() || iControlType == EMsgAttachmentControl)
       
   153         {
       
   154         DrawEditorLines( aParam );
       
   155         }
       
   156     }
       
   157 
       
   158 // ---------------------------------------------------------
       
   159 // CMsgEditorCustomDraw::DrawBackground
       
   160 // ---------------------------------------------------------
       
   161 //
       
   162 void CMsgEditorCustomDraw::DrawLineGraphics( const TParam& aParam, 
       
   163                                              const TLineInfo& aLineInfo ) const
       
   164     {
       
   165     iParentCustomDraw->DrawLineGraphics( aParam, aLineInfo );
       
   166     }
       
   167 
       
   168 // ---------------------------------------------------------
       
   169 // CMsgEditorCustomDraw::DrawText
       
   170 // ---------------------------------------------------------
       
   171 //
       
   172 void CMsgEditorCustomDraw::DrawText( const TParam& aParam,
       
   173                                      const TLineInfo& aLineInfo,
       
   174                                      const TCharFormat& aFormat,
       
   175                                      const TDesC& aText,
       
   176                                      const TPoint& aTextOrigin,
       
   177                                      TInt aExtraPixels ) const
       
   178     {
       
   179     iParentCustomDraw->DrawText( aParam, 
       
   180                                  aLineInfo, 
       
   181                                  aFormat, 
       
   182                                  aText, 
       
   183                                  aTextOrigin, 
       
   184                                  aExtraPixels );
       
   185     }
       
   186     
       
   187 // 107-24185 : Emoticon support for SMS and MMS
       
   188 
       
   189 // -----------------------------------------------------------------------------
       
   190 // CMsgEditorCustomDraw::DrawText
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 void CMsgEditorCustomDraw::DrawText( const TParam& aParam, 
       
   194     const TLineInfo& aLineInfo, const TCharFormat& aFormat, const TDesC& aText, 
       
   195     const TInt aStart, const TInt aEnd, const TPoint& aTextOrigin, 
       
   196     TInt aExtraPixels ) const
       
   197     {
       
   198     iParentCustomDraw->DrawText( aParam, aLineInfo, aFormat, 
       
   199         aText.Mid( aStart, aEnd - aStart ), aTextOrigin, aExtraPixels );
       
   200     }
       
   201     
       
   202 // ---------------------------------------------------------
       
   203 // CMsgEditorCustomDraw::DrawText
       
   204 // ---------------------------------------------------------
       
   205 //
       
   206 TRgb CMsgEditorCustomDraw::SystemColor( TUint aColorIndex, TRgb aDefaultColor ) const
       
   207     {
       
   208     return iParentCustomDraw->SystemColor( aColorIndex, aDefaultColor );
       
   209     }
       
   210 
       
   211 // ---------------------------------------------------------
       
   212 // CMsgEditorCustomDraw::DrawEditorLines
       
   213 // ---------------------------------------------------------
       
   214 //
       
   215 void CMsgEditorCustomDraw::DrawEditorLines( const TParam& aParam ) const
       
   216     {
       
   217     TRect currentRect( iFirstLineRect );
       
   218     
       
   219     while ( currentRect.iBr.iY <= aParam.iDrawRect.iBr.iY )
       
   220         {
       
   221         if ( currentRect.iTl.iY >= aParam.iDrawRect.iTl.iY  )
       
   222             {
       
   223             aParam.iGc.DrawBitmapMasked( currentRect,
       
   224                                          iIcon->Bitmap(), 
       
   225                                          TRect( TPoint( 0 ,0 ), currentRect.Size() ), 
       
   226                                          iIcon->Mask(),
       
   227                                          ETrue );
       
   228             }
       
   229             
       
   230         currentRect.Move( 0, iLineDelta );
       
   231         }
       
   232     } 
       
   233 
       
   234 // ---------------------------------------------------------
       
   235 // CMsgEditorCustomDraw::SkinChanged
       
   236 //
       
   237 //
       
   238 // ---------------------------------------------------------
       
   239 //
       
   240 void CMsgEditorCustomDraw::SkinChanged()
       
   241     {
       
   242     CGulIcon* newIcon = NULL;
       
   243     TRAP_IGNORE( newIcon = AknsUtils::CreateGulIconL( AknsUtils::SkinInstance(),
       
   244     												  KAknsIIDQgnGrafLineMessageHorizontal,
       
   245     												  KMsgEditorMbm,
       
   246     												  EMbmMsgeditorQgn_graf_line_message_horizontal,
       
   247     												  EMbmMsgeditorQgn_graf_line_message_horizontal_mask ) );
       
   248     
       
   249     if ( newIcon )
       
   250     	{
       
   251     	delete iIcon;
       
   252     	iIcon = newIcon;
       
   253     	
       
   254         ResolveLayouts();
       
   255     	}
       
   256     }
       
   257 
       
   258 //  End of File