📄 richtexteditorcontainer.cpp
字号:
#endif
}
// ---------------------------------------------------------
// CRTEContainer::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CRTEContainer::CountComponentControls() const
{
return 2; // return number of controls inside this container
}
// ---------------------------------------------------------
// CRTEContainer::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CRTEContainer::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0:
return iRtEd;
case 1:
return iStatusLine;
default:
return NULL;
}
}
// ---------------------------------------------------------
// CRTEContainer::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CRTEContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.SetPenStyle(CGraphicsContext::ENullPen);
gc.SetBrushColor(KRgbWhite);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);
}
// ---------------------------------------------------------
// OfferKeyEventL()
// Distribute the key event to the Editor
// ---------------------------------------------------------
//
TKeyResponse CRTEContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
if (iRtEd->IsFocused())
{
return iRtEd->OfferKeyEventL(aKeyEvent, aType);
}
else
{
return EKeyWasNotConsumed;
}
}
// ----------------------------------------------------
// SetAlignment(CParaFormat::TAlignment aAlignment)
//
// Alignment formatting apply to the actual paragraph
// If there is only one, it apply for the whole text
//
// We expect one of the following input parameter value:
// CParaFormat::ELeftAlign
// CParaFormat::ECenterAlign
// CParaFormat::ERightAlign
//
// ----------------------------------------------------
void CRTEContainer::SetAlignment(CParaFormat::TAlignment aAlignment)
{
CParaFormat paraFormat;
TParaFormatMask paraFormatMask;
paraFormatMask.SetAttrib(EAttAlignment); // set the mask
paraFormat.iHorizontalAlignment = aAlignment;
iRtEd->ApplyParaFormatL(¶Format, paraFormatMask);
Echo(R_TYPE_DIALOG_TBUF_INDICATOR_ALIGNMENT);
}
// ----------------------------------------------------
// SetSelectionL(TInt aCursorPos,TInt aAnchorPos)
// Select a text in the Rich text editor
// ----------------------------------------------------
void CRTEContainer::SetSelectionL(TInt aCursorPos,TInt aAnchorPos)
{
iRtEd->SetSelectionL(aCursorPos,aAnchorPos);
}
// ----------------------------------------------------
// SetCharacterBIUAttrib(CEikGlobalTextEditor::TFontStyleFlags aFontFlags)
//
// Character formating apply for the selected text
// If nothing is selected it apply to actual word
// We expect one of the following input parameter value:
// CEikGlobalTextEditor::EBold
// CEikGlobalTextEditor::EItalic
// CEikGlobalTextEditor::EUnderline
// ----------------------------------------------------
void CRTEContainer::SetCharacterBIUAttribL(CEikGlobalTextEditor::TFontStyleFlags aFontFlags)
{
iRtEd->BoldItalicUnderlineEventL(aFontFlags);
Echo(R_TYPE_DIALOG_TBUF_INDICATOR_CHARACTER_FORMAT);
}
#ifdef __SERIES60_3X__
// ----------------------------------------------------
// SetFont(TInt aFontId)
// Change the text's font in the editor
// to the one specified as input parameter for the function
// ----------------------------------------------------
void CRTEContainer::SetFont(TInt aFontId)
{
// Get a logical font to base my font on:
const CFont* logicalFont = AknLayoutUtils::FontFromId(aFontId);
// Extract font information
TFontSpec fontspec = logicalFont->FontSpecInTwips();
TCharFormat charFormat(fontspec.iTypeface.iName, fontspec.iHeight);
TCharFormatMask charFormatMask;
charFormatMask.SetAttrib(EAttFontTypeface);
charFormatMask.SetAttrib(EAttFontHeight);
iRtEd->ApplyCharFormatL(charFormat, charFormatMask);
Echo(R_TYPE_DIALOG_TBUF_INDICATOR_FONT);
}
#else
// ----------------------------------------------------
// SetFont(const CFont *aFont)
// Change the text's font in the editor
// to the one specified as input parameter for the function
// ----------------------------------------------------
void CRTEContainer::SetFont(const CFont *aFont)
{
/*
TCursorSelection cs = iRtEd->Selection();
SetSelectionL(cs.iCursorPos, cs.iAnchorPos-1);
*/
TFontSpec fontspec = aFont->FontSpecInTwips();
TCharFormat charFormat( fontspec.iTypeface.iName, fontspec.iHeight );
TCharFormatMask charFormatMask;
charFormatMask.SetAttrib(EAttFontTypeface);
charFormatMask.SetAttrib(EAttFontHeight);
iRtEd->ApplyCharFormatL(charFormat, charFormatMask);
Echo(R_TYPE_DIALOG_TBUF_INDICATOR_FONT);
}
#endif
// ----------------------------------------------------
// Strike()
// Toggle between strikethrough or not strikethrough text
// It depend only bool switch in the code, which turn to opposite in every
// case Strikethrough selected from the menu.
// ----------------------------------------------------
void CRTEContainer::Strike()
{
TCharFormat charFormat;
TCharFormatMask charFormatMask;
iStrike=!iStrike;
charFormat.iFontPresentation.iStrikethrough=iStrike?EStrikethroughOn:EStrikethroughOff;
charFormatMask.SetAttrib(EAttFontStrikethrough);
iRtEd->ApplyCharFormatL(charFormat, charFormatMask);
if(iStrike)
{
Echo(R_TYPE_DIALOG_TBUF_INDICATOR_STRIKE_ON);
}
else
{
Echo(R_TYPE_DIALOG_TBUF_INDICATOR_STRIKE_OFF);
}
}
// ----------------------------------------------------
// SetColor(TRgb aColor)
// Set the selected text color based on the input parameter
// If nothing selected, text color changed only the cursor position.
// ----------------------------------------------------
void CRTEContainer::SetColor(TRgb aColor)
{
TCharFormat charFormat;
TCharFormatMask charFormatMask;
charFormat.iFontPresentation.iTextColor = aColor;
charFormatMask.SetAttrib(EAttColor);
iRtEd->ApplyCharFormatL(charFormat, charFormatMask);
// iRtEd->SetBackgroundColorL(aColor);
// It is possible to change the background color - if foreground and background
// color is same, the text became invisible.
}
// ----------------------------------------------------
// Echo(TInt aMessage)
// Echo the last operation to the status line
// ----------------------------------------------------
void CRTEContainer::Echo(TInt aMessage)
{
TBuf<32> buf;
CEikonEnv::Static()->ReadResource(buf, aMessage);
iStatusLine->SetTextL(buf);
}
// ----------------------------------------------------
// IntroL()
// Create Intro Text.
// ----------------------------------------------------
void CRTEContainer::IntroL()
{
TBuf<KBufSize> Introbuf;
CEikonEnv::Static()->ReadResource(Introbuf, R_TYPE_DIALOG_TBUF_INTRO_TEXT);
TBuf<KBufSize> HelpText;
CEikonEnv::Static()->ReadResource(HelpText, R_TYPE_DIALOG_TBUF_INTRO_HELP_TEXT);
HelpText.Append(CEditableText::ELineBreak);
//Start the center format.
SetAlignment(CParaFormat::ECenterAlign);
//Set the text.
iRtEd->SetTextL(&Introbuf);
iRtEd->RichText()->InsertL(iRtEd->Text()->DocumentLength()/* at the end*/, HelpText);
Echo(R_TYPE_DIALOG_TBUF_INDICATOR_DEMO);
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -