📄 richtexteditorrichtexteditor.cpp
字号:
/**
*
* @brief Definition of CRichTextEditorRichTextEditor
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/
// INCLUDE FILES
// Class include
#include "RichTextEditorRichTextEditor.h"
// System includes
#include <barsread.h> // TResourceReader
#include <orcer.rsg> // resources
#include <eikrted.h> // CEikRichTextEditor
//#include <gdi.h> // TFontStyle
#include <txtrich.h> // CRichText
// ================= MEMBER FUNCTIONS =======================
/**
* Symbian OS 2nd phase constructor. Creates a Window for the controls, which it contains.
* Constructs a label and adds it to the window, which it then activates.
*/
void CRichTextEditorRichTextEditor::ConstructL()
{
TResourceReader reader;
iCoeEnv->CreateResourceReaderLC(reader, R_ORCEREDITOR_ORCER_EDITOR);
ConstructFromResourceL(reader);
CleanupStack::PopAndDestroy(); // reader
SetFocus(ETrue);
}
/**
* Moves the cursor to the top of the editor scrolling any text as necessary
* This should be called after the container window is activated
*/
void CRichTextEditorRichTextEditor::DisplayStartOfHelpTextL()
{
SetCursorPosL(0, EFalse);
}
/**
* Sets underline on or off. This will be applied to text added in AddText()
* @param aOn ETrue to switch underline on, EFalse to switch it off
*/
void CRichTextEditorRichTextEditor::SetUnderlineOn(TBool aOn)
{
iCharFormatMask.SetAttrib(EAttFontUnderline);
if (aOn)
{
iCharFormat.iFontPresentation.iUnderline = EUnderlineOn;
}
else
{
iCharFormat.iFontPresentation.iUnderline = EUnderlineOff;
}
}
/**
* Sets bold on or off. This will be applied to text added in AddText()
* @param aOn ETrue to switch bold on, EFalse to switch it off
*/
void CRichTextEditorRichTextEditor::SetBoldOn(TBool aOn)
{
iCharFormatMask.SetAttrib(EAttFontStrokeWeight);
if (aOn)
{
iCharFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
}
else
{
iCharFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightNormal);
}
}
/**
* Appends a carriage return to the rich text in this editor
*/
void CRichTextEditorRichTextEditor::ApplyCharFormatL()
{
CRichText* richText = RichText();
richText->InsertL(richText->DocumentLength(), CEditableText::ELineBreak);
}
/**
* Appends the supplied text to the rich text in this editor
* Applies any formatting set in other methods, e.g. bold
*/
void CRichTextEditorRichTextEditor::AddTextL(const TDesC& aText)
{
CRichText* richText = RichText();
TInt documentLength = richText->DocumentLength();
richText->InsertL (documentLength, aText);
richText->ApplyCharFormatL(iCharFormat, iCharFormatMask,documentLength,aText.Length());
}
/**
* Symbian OS 2 phase constructor.
* Constructs the CRichTextEditorRichTextEditor using the NewLC method, popping
* the constructed object from the CleanupStack before returning it.
*
* @return The newly constructed CRichTextEditorRichTextEditor
*/
CRichTextEditorRichTextEditor* CRichTextEditorRichTextEditor::NewL()
{
CRichTextEditorRichTextEditor* self = CRichTextEditorRichTextEditor::NewLC();
CleanupStack::Pop(self);
return self;
}
/**
* Symbian OS 2 phase constructor.
* Constructs the CRichTextEditorRichTextEditor using the constructor and ConstructL
* method, leaving the constructed object on the CleanupStack before returning it.
*
* @return The newly constructed CRichTextEditorRichTextEditor
*/
CRichTextEditorRichTextEditor* CRichTextEditorRichTextEditor::NewLC()
{
CRichTextEditorRichTextEditor* self = new (ELeave) CRichTextEditorRichTextEditor;
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
/**
* Called by the framework whenever a key event occurs.
* If the key is the up or down scroller, moves the page up or down respectively and returns EKeyWasConsumed.
* Otherwise, passes the key event to the superclass to handle.
* @param aKeyEvent the Key event which occured, e.g. select key pressed
* @param aType the type of Key event which occurred, e.g. key up, key down
* @return TKeyResponse EKeyWasNotConsumed if the key was not processed, EKeyWasConsumed if it was
*/
TKeyResponse CRichTextEditorRichTextEditor::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
if (aType == EEventKey)
{
if (aKeyEvent.iCode == EKeyDownArrow)
{
MoveCursorL (TCursorPosition::EFPageDown, EFalse);
return EKeyWasConsumed;
}
else if (aKeyEvent.iCode == EKeyUpArrow)
{
MoveCursorL (TCursorPosition::EFPageUp, EFalse);
return EKeyWasConsumed;
}
else
{
return CEikRichTextEditor::OfferKeyEventL(aKeyEvent, aType);
}
}
return EKeyWasNotConsumed;
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -