notepad/notepad1/LibSrc/NpdEdwinSkinTest.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     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:  Implementation of Notepad/Template Editor.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <AknUtils.h>
       
    20 #include <txtglobl.h>
       
    21 #include <barsread.h>
       
    22 #include <NpdLib.rsg>
       
    23 #include "NpdEdwin.h"
       
    24 #include "NpdLibPanic.h"
       
    25 #include "NpdLib.laf"
       
    26 
       
    27 // ============================ MEMBER FUNCTIONS ===============================
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // CNotepadEdwin::LafSizeChanged
       
    31 // Called from CNotepadEditorLaf::SizeChanged().
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 void CNotepadEdwin::LafSizeChanged(const TRect& aRect)
       
    35     {
       
    36     iLayoutShadow.LayoutRect( aRect, 
       
    37         NOTEPAD_EDITOR_SHADOW_C, //TInt C
       
    38         NOTEPAD_EDITOR_SHADOW_L, //TInt l
       
    39         NOTEPAD_EDITOR_SHADOW_T, //TInt t
       
    40         AknLayoutUtilsNoValue, //TInt r
       
    41         AknLayoutUtilsNoValue, //TInt b
       
    42         NOTEPAD_EDITOR_SHADOW_W, //TInt W
       
    43         NOTEPAD_EDITOR_SHADOW_H ); //TInt H
       
    44     iLayoutOutline.LayoutRect( aRect, 
       
    45         NOTEPAD_EDITOR_OUTLINE_C, //TInt C
       
    46         NOTEPAD_EDITOR_OUTLINE_L, //TInt l
       
    47         NOTEPAD_EDITOR_OUTLINE_T, //TInt t
       
    48         AknLayoutUtilsNoValue, //TInt r
       
    49         AknLayoutUtilsNoValue, //TInt b
       
    50         NOTEPAD_EDITOR_OUTLINE_W, //TInt W
       
    51         NOTEPAD_EDITOR_OUTLINE_H ); //TInt H
       
    52     iLayoutInside.LayoutRect( aRect,
       
    53         NOTEPAD_EDITOR_INSIDE_C, //TInt C
       
    54         NOTEPAD_EDITOR_INSIDE_L, //TInt l
       
    55         NOTEPAD_EDITOR_INSIDE_T, //TInt t
       
    56         AknLayoutUtilsNoValue, //TInt r
       
    57         AknLayoutUtilsNoValue, //TInt b
       
    58         NOTEPAD_EDITOR_INSIDE_W, //TInt W
       
    59         NOTEPAD_EDITOR_INSIDE_H ); //TInt H
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CNotepadEdwin::InitNotepadEditorL
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 void CNotepadEdwin::InitNotepadEditorL(
       
    67     const TRect& aRect,
       
    68     CNotepadViewerLaf& aLafControl )
       
    69     {
       
    70     iLaf = &aLafControl;
       
    71     AknLayoutUtils::LayoutControl( iLaf, 
       
    72         aRect, 0, 0, 0, AknLayoutUtilsNoValue, AknLayoutUtilsNoValue, 
       
    73         aRect.Width(), aRect.Height() );
       
    74     AknLayoutUtils::LayoutEdwin(this, aRect,
       
    75         NOTEPAD_EDITOR_LAYOUT_FONT, //TInt font 
       
    76         NOTEPAD_EDITOR_LAYOUT_C, // TInt C
       
    77         NOTEPAD_EDITOR_LAYOUT_L, // TInt l 
       
    78         NOTEPAD_EDITOR_LAYOUT_R, // TInt r 
       
    79         NOTEPAD_EDITOR_LAYOUT_B, // TInt B
       
    80         NOTEPAD_EDITOR_LAYOUT_W, // TInt W
       
    81         NOTEPAD_EDITOR_LAYOUT_J, // TInt J
       
    82         NOTEPAD_EDITOR_LAYOUT_LINES, // TInt aNumberOfLinesShown
       
    83         NOTEPAD_EDITOR_LAYOUT_NEXTB); // TInt aNextLineBaseline
       
    84 
       
    85     // SetBackgroundColorL() contains modification to 
       
    86     // Edwin's CParaFormat which was created by 
       
    87     // AknLayoutUtils::LayoutEdwin(...), so iEditor->SetBackgroundColorL()
       
    88     // must be called after AknLayoutUtils::LayoutEdwin(...).
       
    89     //
       
    90     SetBackgroundColorL();
       
    91 
       
    92     // EdwinEvent is used for dynamically changing Laf bitmap
       
    93     //
       
    94     AddEdwinObserverL(this);
       
    95 
       
    96     Text()->SetHasChanged(EFalse);
       
    97     SetAmountToFormat(); // to show fast even if large text
       
    98     SetCanDrawOutsideRect(); // Redraw after Chinese FEP
       
    99     }
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CNotepadEdwin::ChangeDecorationGraphicsL
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 void CNotepadEdwin::ChangeDecorationGraphicsL()
       
   106     {
       
   107     __ASSERT_DEBUG( iLaf, 
       
   108         Panic(ENotepadLibraryPanicNoControlForDecorationGraphics) );
       
   109     TPoint p;
       
   110     iLaf->SetImage(iLayout->PosInBand(0, p) ? 0 : 1);
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CNotepadEdwin::HandleEdwinEventL
       
   115 // from MEikEdwinObserver
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 void CNotepadEdwin::HandleEdwinEventL(
       
   119     CEikEdwin* /*aEdwin*/,
       
   120     TEdwinEvent aEventType )
       
   121     {
       
   122     __ASSERT_DEBUG( iLaf, 
       
   123         Panic(ENotepadLibraryPanicNoControlForDecorationGraphics) );
       
   124     if ( aEventType == EEventNavigation )
       
   125         {
       
   126         ChangeDecorationGraphicsL();
       
   127         }
       
   128     }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // CNotepadEdwin::SetBackgroundColorL
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 void CNotepadEdwin::SetBackgroundColorL()
       
   135     {
       
   136     TRgb bgcolor(iLayoutInside.Color());
       
   137     CEikEdwin::SetBackgroundColorL(bgcolor);
       
   138     iTextView->SetBackgroundColor(bgcolor);
       
   139     CGlobalText* text = STATIC_CAST(CGlobalText*, Text());
       
   140     CParaFormat* paraFormat = CParaFormat::NewLC();
       
   141     TParaFormatMask paraFormatMask;
       
   142     text->GetParaFormatL(paraFormat, paraFormatMask, 
       
   143         0, text->DocumentLength());
       
   144     paraFormat->iFillColor = bgcolor;
       
   145     paraFormatMask.SetAttrib(EAttFillColor);
       
   146     text->ApplyParaFormatL(paraFormat,paraFormatMask, 
       
   147         0, text->DocumentLength());
       
   148     CleanupStack::PopAndDestroy(); // paraFormat
       
   149     TResourceReader rr;
       
   150     iCoeEnv->CreateResourceReaderLC(rr, R_NOTEPAD_CURSOR_COLOR);
       
   151     TRgb cursorColor(AKN_LAF_COLOR(rr.ReadInt16()));
       
   152     CleanupStack::PopAndDestroy(); // rr
       
   153     iTextView->SetCursorXorColor(
       
   154         TRgb( cursorColor.Value() ^ bgcolor.Value() ) );
       
   155     NotifyNewFormatL();
       
   156     }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // CNotepadEdwin::HandleResourceChange
       
   160 // from CCoeControl
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 void CNotepadEdwin::HandleResourceChange(TInt aType)
       
   164     {
       
   165     CEikEdwin::HandleResourceChange( aType );
       
   166     if( aType == KEikColorResourceChange )
       
   167         {
       
   168         TRAPD(r, SetBackgroundColorL());
       
   169         }
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CNotepadEdwin::Draw
       
   174 // from CCoeControl
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 #include <aknsutils.h>
       
   178 #include <aknsDrawUtils.h>
       
   179 #include <aknappui.h>
       
   180 void CNotepadEdwin::Draw(const TRect& aRect) const
       
   181     {
       
   182 MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   183 CFbsBitmap* bitmap = AknsUtils::GetCachedBitmap( skin, KAknsIIDSkinBmpMainPaneUsual);
       
   184     CWindowGc& gc = SystemGc();
       
   185     if (bitmap) {
       
   186 TSize size(bitmap->SizeInPixels());
       
   187 RDebug::Print(_L("size=(%d, %d)"), size.iWidth, size.iHeight);
       
   188         TRect rect(iAvkonAppUi->ClientRect());
       
   189         TAknLayoutRect layout;
       
   190         layout.LayoutRect(TRect(0, 0, 176, 164), 221, 0, 0,
       
   191         AknLayoutUtilsNoValue,
       
   192         AknLayoutUtilsNoValue,
       
   193         176, 164);
       
   194         layout.DrawImage(gc, bitmap, 0);
       
   195 //    iLayoutShadow.DrawImage(gc, bitmap, 0);
       
   196     }
       
   197     iLayoutShadow.DrawRect(gc);
       
   198     iLayoutOutline.DrawOutLineRect(gc);
       
   199     iLayoutInside.DrawRect(gc);
       
   200     CEikEdwin::Draw(aRect);
       
   201     }
       
   202 
       
   203 // End of File