📄 richtexteditorcontainer.cpp
字号:
/**
*
* @brief Definition of CRichTextEditorContainer
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/
// INCLUDE FILES
// Class include
#include "RichTextEditorContainer.h"
// System includes
#include <barsread.h> // TResourceReader
#include <RichTextEditor.rsg> // resources
#include <StringLoader.h>
// User includes
#include "RichTextEditorRichTextEditor.h"
// CONSTANTS
// N.B. #define'd as DLL cannot contain writeable static data
#define KEditorPosition TPoint(0,0)
// ================= 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.
* @param aRect The rectangle for this window
*/
void CRichTextEditorContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
iEditor = CRichTextEditorRichTextEditor::NewL();
iEditor->SetContainerWindowL(*this);
AddTextToEditorL();
SetRect(aRect);
ActivateL();
iEditor->DisplayStartOfHelpTextL();
}
/**
* Reads the text from the resource file and adds it to the rich text editor, setting the formatting as
* appropriate.
*/
void CRichTextEditorContainer::AddTextToEditorL()
{
if (iEditor)
{
HBufC* header1 = StringLoader::LoadLC (R_RICHTEXTEDITOR_HELP_HEADER1);
iEditor->SetUnderlineOn(ETrue);
iEditor->SetBoldOn(ETrue);
iEditor->AddTextL (*header1);
CleanupStack::PopAndDestroy(header1);
iEditor->AddCarriageReturnL();
iEditor->SetUnderlineOn(EFalse);
iEditor->SetBoldOn(EFalse);
HBufC* text1 = StringLoader::LoadLC (R_RICHTEXTEDITOR_HELP_TEXT1);
iEditor->AddTextL (*text1);
iEditor->AddCarriageReturnL();
iEditor->AddCarriageReturnL();
CleanupStack::PopAndDestroy(text1);
HBufC* header2 = StringLoader::LoadLC (R_RICHTEXTEDITOR_HELP_HEADER2);
iEditor->SetUnderlineOn(ETrue);
iEditor->SetBoldOn(ETrue);
iEditor->AddTextL (*header2);
CleanupStack::PopAndDestroy(header2);
iEditor->AddCarriageReturnL();
iEditor->SetUnderlineOn(EFalse);
iEditor->SetBoldOn(EFalse);
HBufC* text2 = StringLoader::LoadLC (R_RICHTEXTEDITOR_HELP_TEXT2);
iEditor->AddTextL (*text2);
iEditor->AddCarriageReturnL();
iEditor->AddCarriageReturnL();
CleanupStack::PopAndDestroy(text2);
}
}
/**
* Symbian OS 2 phase constructor.
* Constructs the CRichTextEditorContainer using the NewLC method, popping
* the constructed object from the CleanupStack before returning it.
*
* @param aRect The rectangle for this window
* @return The newly constructed CRichTextEditorContainer
*/
CRichTextEditorContainer* CRichTextEditorContainer::NewL(const TRect& aRect)
{
CRichTextEditorContainer* self = CRichTextEditorContainer::NewLC(aRect);
CleanupStack::Pop(self);
return self;
}
/**
* Symbian OS 2 phase constructor.
* Constructs the CRichTextEditorContainer using the constructor and ConstructL
* method, leaving the constructed object on the CleanupStack before returning it.
*
* @param aRect The rectangle for this window
* @return The newly constructed CRichTextEditorContainer
*/
CRichTextEditorContainer* CRichTextEditorContainer::NewLC(const TRect& aRect)
{
CRichTextEditorContainer* self = new (ELeave) CRichTextEditorContainer;
CleanupStack::PushL(self);
self->ConstructL(aRect);
return self;
}
/**
* Destructor. Frees up memory for the iEditor.
*/
CRichTextEditorContainer::~CRichTextEditorContainer()
{
delete iEditor;
}
/**
*
* Called by framework when the view size is changed. Resizes the
* iEditor accordingly.
*
*/
void CRichTextEditorContainer::SizeChanged()
{
iEditor->SetExtent(KEditorPosition, iEditor->MinimumSize());
}
/**
* Called by the framework in compound controls
* @return The number of controls in this CRichTextEditorContainer
*/
TInt CRichTextEditorContainer::CountComponentControls() const
{
return 1; // return number of controls inside this container
}
/**
* Called by the framework in compound controls
* @param The index of the control to return
* @return The control for aIndex
*/
CCoeControl* CRichTextEditorContainer::ComponentControl(TInt aIndex) const
{
switch (aIndex)
{
case 0:
return iEditor;
default:
return NULL;
}
}
/**
* Called by the framework to draw this control. Clears the area in
* aRect.
* @param aRect in which to draw
*/
void CRichTextEditorContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.Clear(aRect);
}
/**
* Called by the framework whenever a key event occurs.
* Passes the key event to the editor if it is not null, otherwise returns
* EKeyWasNotConsumed
* @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 CRichTextEditorContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
if (iEditor)
return iEditor->OfferKeyEventL(aKeyEvent, aType);
else
return CCoeControl::OfferKeyEventL(aKeyEvent, aType);
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -