You Are Here:

Community: Wiki

This page was last modified 19:35, 17 March 2009.

Editor example

From Forum Nokia Wiki

CEditorContainer illustrates a simple container which you can use to add an editor into your project.

To modify the font used with the editor you can select another font in the CreateEditorL() method instead of LatinBold16(). The font color can be set by changing the KRgbBlack constant used in the TCharFormat.

Note that using a rich text editor can cause wasted resources if you don't need different paragraph or character formatting. In these cases you should use CEikEdwin which will allow you to set the font and color for the whole text. Also you could use CEikRichTextEditor directly or derive from it rather than using a container within a container.


Contents

Link against:

avkon.lib eikcoctl.lib eikctl.lib form.lib uiklaf.lib


Header Required:

#include <eikrted.h>


Required capabilities:

None

Editor_Container.cpp

#include<Editor_container.h>
void CEditorContainer::ConstructL(void)
{
	CreateWindowL();
	
	SetRect(CEikonEnv::Static()->EikAppUi()->ClientRect());
	
	CreateEditorL();
	
	ActivateL();
}
 
void CEditorContainer::CreateEditorL(void)
{
	iEditor = new (ELeave) CEikRichTextEditor;		
	iEditor->SetAknEditorFlags(EAknEditorFlagEnableScrollBars);
	iEditor->SetContainerWindowL(*this);
	iEditor->SetAvkonWrap(ETrue);
	iEditor->ConstructL(this,0,0,0);
		
	iEditor->SetFocus(ETrue);
	iEditor->EnableCcpuSupportL(ETrue);
	iEditor->SetCursorPosL(0, EFalse);
	iEditor->SetAvkonWrap(ETrue);
	
	TFontSpec fontspec = LatinBold16()->FontSpecInTwips();
	TCharFormat charFormat( fontspec.iTypeface.iName, fontspec.iHeight );
	TCharFormatMask charFormatMask;
 
	charFormat.iFontPresentation.iTextColor = KRgbBlack;
	charFormatMask.SetAttrib(EAttColor);
	
	charFormatMask.SetAttrib(EAttFontTypeface);
	charFormatMask.SetAttrib(EAttFontHeight);
	iEditor->ApplyCharFormatL(charFormat, charFormatMask);
		
	iEditor->UpdateScrollBarsL();
	SizeChanged();
}
 
 
CEditorContainer::~CEditorContainer()
{
	delete iEditor;
}
 
void CEditorContainer::HandleResourceChange(TInt aType)
{
	TRect rect;
	
	if ( aType==KEikDynamicLayoutVariantSwitch )
	{  	
		AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, rect );
		SetRect(rect);
 	}
 	
	CCoeControl::HandleResourceChange(aType);
}
 
void CEditorContainer::SizeChanged()
{
	TRect rect = Rect();
	
	if(iEditor)
	{
	#ifdef __SERIES60_3X__
		TRect ScrollBarRect = iEditor->ScrollBarFrame()->
VerticalScrollBar()->Rect();
		iEditor->SetExtent(TPoint(0,StatusLineHeight), 
		TSize(rect.Width()-ScrollBarRect.Width(), rect.Height()-StatusLineHeight));
	#else
		iEditor->SetExtent(TPoint(0,StatusLineHeight), 
		TSize(rect.Width(), rect.Height()-StatusLineHeight));
	#endif
	}
}
 
TInt CEditorContainer::CountComponentControls() const
{
	if(iEditor)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}
 
CCoeControl* CEditorContainer::ComponentControl(TInt /*aIndex*/) const
{
	return iEditor;
}
 
void CEditorContainer::Draw(const TRect& aRect) const
{
	CWindowGc& gc = SystemGc();
	gc.Clear();
}
 
TKeyResponse CEditorContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,
TEventCode aType)
{
	TKeyResponse Ret(EKeyWasNotConsumed);
	
	if (iEditor)
	{
		Ret = iEditor->OfferKeyEventL(aKeyEvent, aType);	
	}
 
	return Ret;
}
	
void CEditorContainer::SetEditorTextL(const TDesC& aText)
{
	if (iEditor)
	{
		iEditor->ClearSelectionL();	
		iEditor->RichText()->Reset();
		
		iEditor->RichText()->InsertL(0,aText);
		iEditor->RichText()->InsertL(iEditor->RichText()->
LdDocumentLength(),CEditableText::ELineBreak);
	
		iEditor->UpdateScrollBarsL();
		iEditor->DrawNow();
	}
}

Editor_Container.h

class CEditorContainer : public CCoeControl
    {
    public: 
        void ConstructL(void);
        ~CEditorContainer();
        void SetEditorTextL(const TDesC& aText);
    public: 
		TInt CountComponentControls() const;
        CCoeControl* ComponentControl(TInt aIndex) const;
    	TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);   
    private: 
    	void CreateEditorL(void);
        virtual void SizeChanged();
		virtual void HandleResourceChange(TInt aType);
        void Draw(const TRect& aRect) const;
    private: 
		CEikRichTextEditor* iEditor;
    };

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditFurlTechnocratiMagnoliaTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fMMPE5ffileX qdcZpublisherQUxhttpE3aE2fE2fswE2enokiaE2ecomE2fidE2fc764fd1cE2d8b06E2d499aE2d9a6aE2d17c3903d5a65E2fforumE5fnokiaE5fcrawlerE5fagentX qdcZtitleQSxMMPE20fileE20E2dE20ForumE20NokiaE20WikiX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfnTypeZCommunityContentQ qdcZtypeQUqfnTypeZE52esourceQ qdcZtypeQUqfnTypeZWebpageQ qdcZtypeQUqfnTypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qrssZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qfnZdistributionQUxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2fX qfnZtypeQUqfnTypeZCommunityContentQ qfnZtypeQUqfnTypeZE52esourceQ qfnZtypeQUqfnTypeZWebpageQ qfnZtypeQUqfnTypeZWikiContentQ qfnZupdatedQDx2008E2d10E2d02X qfnZuserE5ftagQSxfileX qfnZuserE5ftagQSxlibpathX qfnZuserE5ftagQSxmmpX qfnZuserE5ftagQSxresourceX qmarsZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfnTypeZCommunityContentQ qrdfZtypeQUqfnTypeZE52esourceQ qrdfZtypeQUqfnTypeZWebpageQ qrdfZtypeQUqfnTypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ