Playing with CEikEdwin
CEikEdwin is the base class for all the Symbian editors and is powerful.... once you understand how it works as some quite simple operations are not that easy to implement.
Here is a set of such primitives we comonly use at NewLC. In all the code below the CMyEdwin is a class deriving from CEikEdwin:
Playing with text
Appending some text at the end of a text field is a basic operation for a text field, but in Symbian OS, it does not exists as is. To implement it, you have to use the InsertDeleteCharsL:
* Append some text at the end of the edwin
* @param aText The text to append
*/
void CMyEdwin::AppendTextL(const TDesC& aText)
{
InsertDeleteCharsL(TextLength(),
aText,
TCursorSelection(0,0));
}
Playing with lines and cursor
The NumberOfLines() function retrieves the number of lines of text currently displayed in the editor. This value may change if you resize the edwin:
* Get the number of lines contained in this edwin
* @return The line count (0 if empty)
*/
TInt CMyEdwin::NumberOfLines()
{
return(TextLayout()->GetLineNumber(TextLength()));
}
CursorLinePos() returns the line on which the cursor is currently positionned:
* Get the line on which the cursor is located
* @return The line of the cursor
*/
TInt CMyEdwin::CursorLinePos()
{
return(TextLayout()->GetLineNumber(CursorPos()));
}
CursorAtTop() and CursorAtBottom() are primitives that checks whether the cursor is on the first or last line of the CEikEdwin:
* Test whether cursor is on the first line of the edwin or not
* @return ETrue if cursor is on first line, EFalse in other case
*/
TBool CMyEdwin::CursorAtTop()
{
TBool res=EFalse;
if(CursorLinePos()==0)
res=ETrue;
return(res);
}
* Test whether cursor is on the last line of the edwin or not
* @return ETrue if cursor is on last line, EFalse in other case
*/
TBool CMyEdwin::CursorAtBottom()
{
TBool res=EFalse;
TInt lineNum=CursorLinePos();
TInt lineCount= NumberOfLines();
if(lineNum==lastLineNum)
res=ETrue;
return(res);
}
Playing with colors
CEikGlobalTextEditor may be a wiser choice if you need to change the background and text color. However, this is still possible with a basic CEikEdwin, even if a little bit tricky:
* Set the Edwin background color
* @param aColor The RGB color to use as background
*/
void CMyEdwin::SetBackgroundColor(const TRgb& aColor)
{
CParaFormatLayer*pFormatLayer = CEikonEnv::NewDefaultParaFormatLayerL();
CleanupStack::PushL(pFormatLayer);
CParaFormat* paraFormat=CParaFormat::NewLC();
TParaFormatMask paraFormatMask;
pFormatLayer->SenseL(paraFormat,paraFormatMask);
paraFormat->iFillColor=aColor;
paraFormatMask.SetAttrib(EAttFillColor);
pFormatLayer->SetL(paraFormat, paraFormatMask);
SetParaFormatLayer(pFormatLayer); // Edwin takes the ownership
CleanupStack::PopAndDestroy(paraFormat);
CleanupStack::Pop(pFormatLayer);
}
* Set the Edwin text color
* @param aColor The RGB color to use for text
*/
void CMyEdwin::SetTextColor(const TRgb& aColor)
{
CCharFormatLayer* FormatLayer = CEikonEnv::NewDefaultCharFormatLayerL();
TCharFormat charFormat;
TCharFormatMask charFormatMask;
FormatLayer->Sense(charFormat, charFormatMask);
charFormat.iFontPresentation.iTextColor=aColor;
charFormatMask.SetAttrib(EAttColor);
FormatLayer->SetL(charFormat, charFormatMask);
SetCharFormatLayer(FormatLayer); // Edwin takes the ownership
}
Disabling T9
On S60, you may also want to disable the T9 predictive text input. You should then call a simple avkon specific function to do so:
CEikEdwin::SetAknEditorFlags( EAknEditorFlagNoT9 );
Alternatively you may prefer doing it through the editor resource definition:
{
...
avkon_flags = EAknEditorFlagNoT9; // this will disable T9
...
}






> Playing with CEikEdwin
Hello Dear Eric, this will be a real great contribution if you could share "how to over ride a RichTextEditor to draw a background image behind a richtext on a richtext editor" .
hope to here back :)
Regards, a GonZaLiz
> Playing with CEikEdwin
Eric,
I think you have typo in the method below:
void CMyEdwin::SetTextColor(const TRgb& aColor) CCharFormatLayer* FormatLayer = CEikonEnv::NewDefaultCharFormatLayerL(); TCharFormat charFormat; TCharFormatMask charFormatMask; FormatLayer->Sense(charFormat, charFormatMask); charFormat.iFontPresentation.iTextColor=KRgbWhite; charFormatMask.SetAttrib(EAttColor); FormatLayer->SetL(charFormat, charFormatMask); SetCharFormatLayer(FormatLayer); // Edwin takes the ownership
Should bolded line indicate above be the following:
charFormat.iFontPresentation.iTextColor=aColor
Regards,
> Playing with CEikEdwin
> Playing with CEikEdwin
The paragraph "Playing with text" describing how to append text to an edwin was very useful. Thank you!
The given piece of code seemed to position the cursor always to the beginning of the control. I also needed to insert line breaks into my iOutputWindow (CEikGlobalTextEditor), so I did the following:
iOutputWindow->InsertDeleteCharsL(iOutputWindow->TextLength(), aText, TCursorSelection(0,0));
_LIT(KTextNewLine, "\f");
iOutputWindow->InsertDeleteCharsL(iOutputWindow->TextLength(), KTextNewLine, TCursorSelection(0,0));
iOutputWindow->SetCursorPosL(iOutputWindow->TextLength(), EFalse);
> Playing with CEikEdwin
> Playing with CEikEdwin
> Playing with CEikEdwin
Hi,
I tried using your function for setting the background color of my edwin. It almost works :) This problem is that the text is shorter than the edwin is wide. The background color is changed but just behind the text, the background that hasn't got any text is not changed.
It's a bit tough to explain, I hope you understand. Do you know what I can do to make the whole background color change?
Re: > Playing with CEikEdwin
Hi,
I met the same problem ,i can not change all the background color of the edwin.
have you resolved the problem yet?Thank you!
BRs,
lamalado.
> Playing with CEikEdwin
Hi,
This example was very good. I have one more problem.
When I try to display a really long line in CEikEdwin, the line at the end of the EDWIN rectangle shows only have a line of text and I don't know how to make the EDWIN display full lines.
If the remaining height of the EDWIN rectangle is not enough to display the line, then the line should be displayed in the next page.
Please help,
sriram
> Playing with CEikEdwin
svg image as background in Richtext editor
how to display svg image as background for S60 MR edition and also set
background image in richtext (behind richtext) becos am new
to symbian... so plese kindly tel me r copy the source code of it...
regds
Vijay
vi_ragha@yahoo.com
Playing with CEikEdwin
Hi Eric,
I Have a Two Edwins in One Container. One is a Rich Text Editor and The other a Normal Text Edtior.
The Rich Text Editor is Read Only. Now i am Displaying the RichText Editor all the While over the whole screen when no Key is Pressed.
But when a Key is Pressed bringing the Text Editor to Foreground and Showing it Just Below the Rich Text Edtior.
But the Problem Is When i First Press a Key the Text Editor takes it as a Number but i want it as alphahbet.
Any Suggestions??
Re: Playing with CEikEdwin
Eirc,
Thanks for a helpful tutorial.
Regards,
rnd