notepad/notepad1/LibSrc/NpdEdwinBase.cpp
changeset 0 f979ecb2b13e
child 11 0f07cd1b5772
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 "NpdEdwinBase.h"
       
    20 
       
    21 #include <AknUtils.h>
       
    22 #include <txtglobl.h>
       
    23 #include <barsread.h>
       
    24 
       
    25 #include <AknsUtils.h>
       
    26 #include <AknsDrawUtils.h>
       
    27 #include <AknsBasicBackgroundControlContext.h>
       
    28 #include <AknsFrameBackgroundControlContext.h>
       
    29 #include <applayout.cdl.h>
       
    30 #include <eikdialg.h>
       
    31 #include <skinlayout.cdl.h>
       
    32 #include <aknlayoutscalable_apps.cdl.h>
       
    33 #include <aknappui.h>
       
    34 #include <NpdLib.rsg>
       
    35 
       
    36 #include "NpdEdwin.h"
       
    37 #include "NpdRichTextEditor.h"
       
    38 
       
    39 #include "NpdLibPanic.h"
       
    40 #include "NpdEdwinLines.h"
       
    41 
       
    42 
       
    43 // ============================ MEMBER FUNCTIONS ===============================
       
    44 
       
    45 // ---------------------------------------------------------
       
    46 // CNotepadEdwinBase::CNotepadEdwinBase()
       
    47 // Constructor
       
    48 // ---------------------------------------------------------
       
    49 //
       
    50 CNotepadEdwinBase::CNotepadEdwinBase()
       
    51 	{
       
    52 	iEdwinLines = NULL;
       
    53 	iBgContext = NULL;
       
    54 	iSkinContext = NULL;
       
    55     iIsFirstTimeDrawEditor = ETrue;
       
    56 	}
       
    57 
       
    58 // ---------------------------------------------------------
       
    59 // CNotepadEdwinBase::~CNotepadEdwinBase()
       
    60 // Destructor
       
    61 // ---------------------------------------------------------
       
    62 //
       
    63 CNotepadEdwinBase::~CNotepadEdwinBase()
       
    64 	{
       
    65 	if(iBgContext)
       
    66 		{
       
    67 		delete iBgContext;
       
    68 		iBgContext = NULL;	
       
    69 		}
       
    70 	if(iSkinContext)
       
    71 		{
       
    72 		delete iSkinContext;	
       
    73 		}
       
    74 	}
       
    75 
       
    76 // ---------------------------------------------------------
       
    77 // CNotepadEdwinBase::Share(CEikEdwin* aEdwin, MNotepadEdwinExposer* aEdwinExposer)
       
    78 // Shares the edwin and its exposer
       
    79 // ---------------------------------------------------------
       
    80 //
       
    81 void CNotepadEdwinBase::Share(CEikEdwin* aEdwin, MNotepadEdwinExposer* aEdwinExposer)
       
    82 	{
       
    83 	iEdwin = aEdwin;
       
    84 	iEdwinExposer = aEdwinExposer;
       
    85 	}
       
    86 // -----------------------------------------------------------------------------
       
    87 // CNotepadEdwinBase::DoEditorLayoutL
       
    88 // Sets the layout of the Edwin and the scrollbar.
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 void CNotepadEdwinBase::DoEditorLayoutL()
       
    92 	{
       
    93     	if (!iBgContext)
       
    94         	return;
       
    95     	UpdateScrollLayout();
       
    96     	iBackgroundRect = iParent->Rect();
       
    97     	if(iEdwinLines != NULL)
       
    98     		{
       
    99     		AknLayoutUtils::LayoutControl( iEdwinLines, 
       
   100         			iBackgroundRect, 0, 0, 0, 
       
   101         			AknLayoutUtilsNoValue, 
       
   102         			AknLayoutUtilsNoValue, 
       
   103         			iBackgroundRect.Width(), 
       
   104         			iBackgroundRect.Height() );
       
   105 	 	}
       
   106 	TAknLayoutRect mainNotesPane;
       
   107 	TAknLayoutRect lineLayout;
       
   108 	TRect tempMainPane;
       
   109 	AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,tempMainPane);
       
   110 	TRect mainPane(TPoint(0, 0), tempMainPane.Size());
       
   111 	mainNotesPane.LayoutRect(mainPane, AknLayoutScalable_Apps::main_notes_pane().LayoutLine());
       
   112 	lineLayout.LayoutRect(mainNotesPane.Rect(),AknLayoutScalable_Apps::list_notes_pane().LayoutLine());
       
   113 	TAknLayoutScalableParameterLimits textLimits =AknLayoutScalable_Apps::list_notes_text_pane_ParamLimits();
       
   114 	RArray<TAknTextComponentLayout> layouts;
       
   115 	for (TInt i = 0; i < textLimits.LastRow()+1 ; i++)
       
   116     		{
       
   117     		TAknWindowComponentLayout paneLayout = AknLayoutScalable_Apps::list_notes_text_pane(i);
       
   118     		TAknTextComponentLayout textLayout = AknLayoutScalable_Apps::list_notes_text_pane_t1();
       
   119     		TAknTextComponentLayout composedTextLayout = TAknWindowComponentLayout::ComposeText(paneLayout, textLayout);
       
   120   		layouts.AppendL(composedTextLayout); 
       
   121     		}    
       
   122 	TAknMultiLineTextLayout edwinLayout =
       
   123 	TAknTextComponentLayout::Multiline( layouts );              
       
   124 	AknLayoutUtils::LayoutEdwin(iEdwin, lineLayout.Rect(), edwinLayout, EAknsCIQsnTextColorsCG6);
       
   125 	layouts.Reset();
       
   126 
       
   127     	// layout edwin overrides this value
       
   128     	iEdwin->SetTextSkinColorIdL(EAknsCIQsnTextColorsCG34);
       
   129 
       
   130     	// SetBackgroundColorL() contains modification to 
       
   131     	// Edwin's CParaFormat which was created by 
       
   132     	// AknLayoutUtils::LayoutEdwin(...), so iEditor->SetBackgroundColorL()
       
   133     	// must be called after AknLayoutUtils::LayoutEdwin(...).
       
   134     	//
       
   135     	SetBackgroundColorL();
       
   136 	}
       
   137 
       
   138 // -----------------------------------------------------------------------------
       
   139 // CNotepadEdwinBase::InitNotepadEditorL
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 void CNotepadEdwinBase::InitNotepadEditorL(
       
   143     CEikDialog* aParent,
       
   144     TBool aIsRichTextEditor, 
       
   145     CNotepadEdwinLines* aEdwinLines)
       
   146     {
       
   147     iParent = aParent;
       
   148     iBackgroundRect = iParent->Rect();
       
   149     iEdwinLines = aEdwinLines;
       
   150     iIsRichTextEditor = aIsRichTextEditor;
       
   151     if (!iBgContext)
       
   152     	{
       
   153     	iBgContext = CAknsFrameBackgroundControlContext::NewL( KAknsIIDQsnFrNotepad, iBackgroundRect, iBackgroundRect, EFalse );
       
   154     	}
       
   155     if(!iSkinContext)
       
   156     	{
       
   157     	iSkinContext = CAknsBasicBackgroundControlContext::NewL(KAknsIIDQsnBgAreaMain,iBackgroundRect,EFalse);
       
   158     	}
       
   159     iBgContext->SetParentContext( iSkinContext );
       
   160     DoEditorLayoutL();    
       
   161 
       
   162     // EdwinEvent is used for dynamically changing Laf bitmap
       
   163     //
       
   164     iEdwin->AddEdwinObserverL(this);
       
   165 
       
   166     iEdwin->SetAknEditorFlags(EAknEditorFlagUseSCTNumericCharmap
       
   167                                 | EAknEditorFlagEnablePictographInput
       
   168                                 | EAknEditorFlagAllowEntersWithScrollDown );
       
   169 
       
   170     iEdwin->Text()->SetHasChanged(EFalse);
       
   171     SetAmountToFormat(iEdwin->Text()->DocumentLength()); // ensure switch to band formatting 
       
   172     iEdwinExposer->CallSetCanDrawOutsideRect(); // Redraw after Chinese FEP
       
   173     }
       
   174 
       
   175 // ---------------------------------------------------------
       
   176 // CNotepadEdwinBase::SupplyMopObject(TTypeUid aId,TTypeUid::Ptr& ptr)
       
   177 // Gets an object whose type is encapsulated by 
       
   178 // the specified TTypeUid object.
       
   179 // ---------------------------------------------------------
       
   180 //
       
   181 TBool CNotepadEdwinBase::SupplyMopObject(TTypeUid aId,TTypeUid::Ptr& ptr)
       
   182 	{
       
   183 	if(aId.iUid == MAknsControlContext::ETypeId)
       
   184 		{
       
   185 		ptr =  MAknsControlContext::SupplyMopObject(aId, iSkinContext);
       
   186 		return ETrue;
       
   187 		}
       
   188 	return EFalse;
       
   189 	}
       
   190 
       
   191 // -----------------------------------------------------------------------------
       
   192 // CNotepadEdwinBase::HandleEdwinEventL
       
   193 // from MEikEdwinObserver
       
   194 // -----------------------------------------------------------------------------
       
   195 //
       
   196 void CNotepadEdwinBase::HandleEdwinEventL(
       
   197     CEikEdwin* /*aEdwin*/,
       
   198     TEdwinEvent aEventType )
       
   199     {
       
   200 
       
   201     iTextLength = iEdwin->TextLength();
       
   202 
       
   203     if ( aEventType == EEventFormatChanged )
       
   204         {
       
   205         iEdwin->DrawNow();
       
   206         }
       
   207     if ( aEventType == EEventTextUpdate )
       
   208         { 
       
   209         iEdwin->TextView()->DocPosToXyPosL( iEdwin->CursorPos(), iPointAtCursor );
       
   210         iLineNumByYCoordinate = iPointAtCursor.iY;
       
   211 
       
   212         if ( !iIsFirstTimeDrawEditor )
       
   213             {
       
   214 
       
   215             if ( iTextLength < iPreTextLength &&  iLineNumByYCoordinate < iPreLineNumByYCoordinate )
       
   216             	{
       
   217                 iEdwin->NotifyNewFormatL();
       
   218                 iEdwin->DrawDeferred();
       
   219             	}
       
   220             }
       
   221         else
       
   222             {
       
   223             iIsFirstTimeDrawEditor = EFalse;
       
   224             }
       
   225         
       
   226 
       
   227         iPreLineNumByYCoordinate = iLineNumByYCoordinate;
       
   228         }
       
   229 
       
   230      iPreTextLength = iTextLength;
       
   231     }
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // CNotepadEdwinBase::SetBackgroundColorL
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 void CNotepadEdwinBase::SetBackgroundColorL()
       
   238 	{
       
   239     	TAknLayoutRect insiderect;
       
   240 	TAknLayoutRect bgLayout;
       
   241 	TAknLayoutRect mainNotesPane;
       
   242     TRect tempMainPane;
       
   243     TBool hasChanged;
       
   244     
       
   245     hasChanged = iEdwin->Text()->HasChanged();
       
   246     	AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,tempMainPane);
       
   247 	TRect mainPane(TPoint(0, 0), tempMainPane.Size());
       
   248 	mainNotesPane.LayoutRect(mainPane, AknLayoutScalable_Apps::main_notes_pane().LayoutLine());
       
   249 	bgLayout.LayoutRect(mainNotesPane.Rect(), AknLayoutScalable_Apps::bg_notes_pane().LayoutLine());
       
   250 	insiderect.LayoutRect(bgLayout.Rect(), AknLayoutScalable_Apps::notes_bg_pane_g1().LayoutLine());
       
   251 	TRgb bgcolor(insiderect.Color());
       
   252 	iEdwin->CEikEdwin::SetBackgroundColorL(bgcolor);
       
   253     	iEdwinExposer->GetTextView().SetBackgroundColor(bgcolor);
       
   254 	iEdwin->CEikEdwin::SetSkinBackgroundControlContextL(iBgContext);
       
   255 	CGlobalText* text = STATIC_CAST(CGlobalText*, iEdwin->Text());
       
   256     	CParaFormat* paraFormat = CParaFormat::NewLC();
       
   257     	TParaFormatMask paraFormatMask;
       
   258     	text->GetParaFormatL(paraFormat, paraFormatMask, 
       
   259        		0, text->DocumentLength());
       
   260     	paraFormat->iFillColor = bgcolor;
       
   261     	paraFormatMask.SetAttrib(EAttFillColor);
       
   262     	text->ApplyParaFormatL(paraFormat,paraFormatMask, 
       
   263         	0, text->DocumentLength());
       
   264     if ( !hasChanged )
       
   265         {
       
   266         iEdwin->Text()->SetHasChanged( EFalse );
       
   267         }
       
   268 
       
   269 	if(iIsRichTextEditor)
       
   270     		{
       
   271     		(STATIC_CAST(CEikRichTextEditor*,iEdwin))->ApplyParaFormatL(paraFormat,paraFormatMask);
       
   272     		}
       
   273      	CleanupStack::PopAndDestroy(); // paraFormat
       
   274 	TResourceReader rr;
       
   275         iEdwinExposer->GetCoeEnv().CreateResourceReaderLC(rr, R_NOTEPAD_CURSOR_COLOR);
       
   276     	TRgb cursorColor(AKN_LAF_COLOR(rr.ReadInt16()));
       
   277     	CleanupStack::PopAndDestroy(); // rr
       
   278     	iEdwinExposer->GetTextView().SetCursorXorColor( TRgb( cursorColor.Value() ^ bgcolor.Value() ) );
       
   279     	iEdwin->NotifyNewFormatL();
       
   280 	}
       
   281 
       
   282 // -----------------------------------------------------------------------------
       
   283 // CNotepadEdwinBase::HandleResourceChange
       
   284 // -----------------------------------------------------------------------------
       
   285 //
       
   286 void CNotepadEdwinBase::HandleResourceChange(TInt aType)
       
   287     {
       
   288     iEdwin->CEikEdwin::HandleResourceChange( aType );
       
   289     switch(aType)
       
   290     	{
       
   291     	case KEikColorResourceChange:
       
   292     	case KAknsMessageSkinChange:
       
   293     		TInt ignore;	
       
   294         	TRAP(ignore, SetBackgroundColorL());
       
   295         	break;
       
   296     	}
       
   297     if( aType == KAknsMessageSkinChange )
       
   298         {
       
   299         UpdateScrollLayout();
       
   300         }
       
   301     }
       
   302 
       
   303 // -----------------------------------------------------------------------------
       
   304 // CNotepadEdwinBase::Draw
       
   305 // -----------------------------------------------------------------------------
       
   306 //
       
   307 void CNotepadEdwinBase::Draw(const TRect& aRect) const   
       
   308 	{
       
   309     CWindowGc& gc = iEdwin->SystemGc();
       
   310     TRect tempMainPane;
       
   311     AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,tempMainPane);
       
   312 	TRect mainPane(TPoint(0, 0), tempMainPane.Size());
       
   313     	if( iBgContext )
       
   314 		{
       
   315     		TAknLayoutRect mainpaneSkinTl;
       
   316     		TAknLayoutRect mainpaneSkinBr;
       
   317     		mainpaneSkinTl.LayoutRect( mainPane, SkinLayout::Notepad_skin_element_placing_Line_2() );  // <CDL LAYOUT>
       
   318     		mainpaneSkinBr.LayoutRect( mainPane, SkinLayout::Notepad_skin_element_placing_Line_5() );  // <CDL LAYOUT>
       
   319     		TAknWindowLineLayout mainPaneSkinCenter = SkinLayout::Notepad_skin_element_placing_Line_1();  // <CDL LAYOUT>
       
   320 		TAknLayoutRect mainPaneLayout;
       
   321 		mainPaneLayout.LayoutRect(mainPane,mainPaneSkinCenter);
       
   322     		TRect skinCenter( mainPaneLayout.Rect() );
       
   323     		TRect viewRect;
       
   324     		viewRect.iTl= mainpaneSkinTl.Rect().iTl;
       
   325     		viewRect.iBr = mainpaneSkinBr.Rect().iBr;
       
   326     	
       
   327     		if(iSkinContext)
       
   328     			{
       
   329     			iSkinContext->SetRect(iParent->Rect());
       
   330     			TRAP_IGNORE( iEdwin->CEikEdwin::SetSkinBackgroundControlContextL(iSkinContext) );
       
   331         		AknsDrawUtils::Background( AknsUtils::SkinInstance(), iSkinContext, iEdwin, gc, mainPane);	
       
   332     			}
       
   333         	TRAP_IGNORE( iEdwin->CEikEdwin::SetSkinBackgroundControlContextL(iBgContext) );
       
   334     		iBgContext->SetFrameRects( viewRect, mainPaneLayout.Rect() );
       
   335     		AknsDrawUtils::Background( AknsUtils::SkinInstance(), iBgContext, iEdwin, gc, mainPane,KAknsDrawParamNoClearUnderImage);
       
   336  		}
       
   337    	iEdwin->CEikEdwin::Draw(aRect);
       
   338 	}
       
   339 
       
   340 // ---------------------------------------------------------
       
   341 // CNotepadEdwinBase::UpdateScrollLayout()
       
   342 // Updates the scroll layout
       
   343 // ---------------------------------------------------------
       
   344 //
       
   345 void CNotepadEdwinBase::UpdateScrollLayout()
       
   346 	{
       
   347 	CEikScrollBarFrame* sbFrame = iEdwin->ScrollBarFrame();
       
   348     	TInt type = sbFrame->TypeOfVScrollBar();
       
   349 	if( type == CEikScrollBarFrame::EDoubleSpan )
       
   350         	{
       
   351 		TAknLayoutRect mainNotesPane;
       
   352 		TRect tempMainPane;
       
   353         	AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,tempMainPane);
       
   354 		TRect mainPane(TPoint(0, 0), tempMainPane.Size());
       
   355 		TAknWindowLineLayout scrollPane = AknLayoutScalable_Apps::scroll_pane_cp06().LayoutLine();
       
   356 		mainNotesPane.LayoutRect(mainPane, AknLayoutScalable_Apps::main_notes_pane().LayoutLine());
       
   357         	AknLayoutUtils::LayoutVerticalScrollBar(sbFrame, mainNotesPane.Rect(), scrollPane);
       
   358         	}
       
   359 	}
       
   360 // End of File