×
Namespaces

Variants
Actions

How to use custom background for text editors

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): S60 Emulators
Compatibility
Platform(s): Symbian
Article
Keywords: CEikEdwin, CEikRichTextEditor, CreateCustomDrawL, CLafEdwinCustomDrawBase, DrawBackground, SystemColor
Created: chenziteng (29 Sep 2009)
Last edited: hamishwillee (30 May 2013)

Contents

Overview

This article describes how to use custom background for text editors CEikEdwin, CEikRichTextEditor by custom drawer, with this solution you can actually draw anything on the editor's background.


Background color

  • The topic is covered by the following wiki articles:
 -How to use custom background color for edwin in S60 3rd Edition
 -How to use custom background color for edwin in S60 2nd Edition



Skin Background

  • It is possible for a control, say a custom container or a text editor in it, to reuse a skin background. The solution is explained well in the relative articles so it is not necessary to repeat here.
 -Using Skins in S60
 -Drawing skins in container
 -TSS000683 - Using the same background as built-in applications


  • Here are the example applications that reuse the main pane skin background (and make the text editor look like has a transparent background).




Custom Background

  • To apply a custom background for a text editor we shall first create a custom text editor derived from the CEikEdwin, and then override the CreateCustomDrawL() to return the custom drawer.
class CMyEdwin : public CEikEdwin
{
protected:
CLafEdwinCustomDrawBase* CreateCustomDrawL();
};
 
CLafEdwinCustomDrawBase* CMyEdwin::CreateCustomDrawL()
{
return CMyCustomDraw::NewL(iEikonEnv->LafEnv(), *this);
}
  • The custom drawer should be derived from the CLafEdwinCustomDrawBase, and by overriding the DrawBackground() you can actually draw anything on the text editor's background. Below we simply paint an image
class CMyCustomDraw : public CLafEdwinCustomDrawBase
{
...
public:
void DrawBackground(const TParam& aParam,const TRgb& aBackground,TRect& aDrawn) const;
...
};
 
void CMyCustomDraw::DrawBackground(const TParam& aParam,const TRgb& aBackground,TRect& aDrawn) const
{
CLafEdwinCustomDrawBase::DrawBackground(aParam, aBackground, aDrawn);
if((iBitmap!=NULL)&&(iBitmap->Handle()!=0))
{
TRect rect = TRect(TPoint(0,0), iBitmap->SizeInPixels());
aParam.iGc.SetClippingRect(aParam.iDrawRect);
aParam.iGc.DrawBitmap(rect, iBitmap);
}
}
  • See the screenshots of the example applications running under emulator.


  • The solution also works for CEikRichTextEditor, see the example applications below:
  • Further discussion: If you'd like to change the size and position of the editor but at the same time keep the custom background, you need to calculate the offset of the edwin and then modify the DrawBackground() a little bit to correct the draw behavior.
class CMyCustomDraw : public CLafEdwinCustomDrawBase
{
...
public:
void DrawBackground(const TParam& aParam,const TRgb& aBackground,TRect& aDrawn) const;
...
public:
// iParent is the edwin's parent control, you need to pass the pointer
// to the custom draw class when create it.
CCoeControl* iParent;
};
 
 
void CMyCustomDraw::DrawBackground(const TParam& aParam,const TRgb& aBackground,TRect& aDrawn) const
{
CLafEdwinCustomDrawBase::DrawBackground(aParam, aBackground, aDrawn);
if((iBitmap!=NULL)&&(iBitmap->Handle()!=0))
{
// calculate the offset of the edwin
TPoint point = TPoint(0, iParent.Position().iY-iParent.PositionRelativeToScreen().iY);
TRect rect = TRect(point, iBitmap->SizeInPixels());
aParam.iGc.SetClippingRect(aParam.iDrawRect);
aParam.iGc.DrawBitmap(rect, iBitmap);
}
}
This page was last modified on 30 May 2013, at 07:39.
66 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×