📄 richtexteditorcontainer.cpp
字号:
/*
* ============================================================================
* Name : CRTEContainer from RichTextEditorContainer.cpp
* Part of : RichTextEditor
* Created : 05/08/2006 by Forum Nokia
* Version : 2.0
* Copyright: Forum Nokia
* ============================================================================
*/
// INCLUDE FILES
#include "RichTextEditorContainer.h"
#include <txtrich.h> //Richtext
#include <eikrted.h> //RichText Editor
#include <avkon.mbg> // Image Ids
#include <eikenv.h> // ReadResource()
#include <RichTextEditor.rsg> // Demo Text Buffer
#include "mypicture.h" // CMyPicture
#include <AknUtils.h>
// ================= MEMBER FUNCTIONS =======================
// Demo shows the T9 (Front End Processor) ,Scroller,
// "Insert Picture", disable Copy-Paste feature
// in RichText Editor
// CONSTANTS
_LIT( KImageBitmapFile, "picture.mbm");
//Text and images positions.
const TInt KLeftImagePositionInTheText = 21;
const TInt KRightImagePositionInTheText = 38;
const TInt KEndofCenterFormat = 55;
const TInt KLeftNokia = 6;
const TInt KRightNokia = 11;
const TInt KKImageWidth = 283;
const TInt KImageHeight = 113;
//buffer size
const TInt KBufSize = 256;
// ---------------------------------------------------------
// CRTEContainer::Prepare()
// Set the Editor flags
// ---------------------------------------------------------
//
void CRTEContainer::Prepare()
{
// Lower Case
iRtEd->SetAknEditorCase(EAknEditorLowerCase);
// Fixed case
iRtEd->SetAknEditorFlags
(
EAknEditorFlagFixedCase| //Set up the Allowed Cases
EAknEditorFlagEnableScrollBars // Set up the scroller
);
}
// ---------------------------------------------------------
// CRTEContainer::PreparePicture()
// Append Bitmap to iBitmap Array
// ---------------------------------------------------------
//
void CRTEContainer::PrepareBitmapL()
{
TFileName name(KImageBitmapFile);
#ifndef __SERIES60_3X__
CompleteWithAppPath( name );
// windows build wants to install apps on rom drive ( "z:\" )
// but we want the data from "c:\" instead
#ifdef __WINS__
name[ 0 ] = 'C';
#endif
#endif
CFbsBitmap* bitmap;
// Create and Load the Bitmap
bitmap= new( ELeave )CFbsBitmap;
CleanupStack::PushL(bitmap);
User::LeaveIfError(bitmap->Load(name));
//we have to free the memory at the Destructor() -> store the bitmap memory address
iBitmap->AppendL(bitmap);
CleanupStack::Pop(); //bitmap - container free bitmap at the destructor
// last item in iBitmap array is ready to Insert
}
// ---------------------------------------------------------
// CRTEContainer::InsertMyPictureL()
// Call Richtext's InsertL() with the CPicture
// ---------------------------------------------------------
//
void CRTEContainer::InsertMyPictureL(TInt aPos)
{
CMyPicture* picture;
// Create a CPicture derived class which will draw our image, depending this Size
picture = new( ELeave )CMyPicture(TSize(KKImageWidth,KImageHeight),
*(iBitmap->At(iBitmap->Count()-1)/*process the last item of iBitmap*/));
CleanupStack::PushL(picture);
// Prepare the Picture header, which will be instered into the Richtext
TPictureHeader header;
header.iPicture =TSwizzle<CPicture>(picture);
iRtEd->RichText()->InsertL( aPos,header);
CleanupStack::Pop(); // picture - Richtext take the ownership
}
// ---------------------------------------------------------
// CRTEContainer::Demo()
// Create Demo Text Content
//
// Selecting text as holding the 'ABC'+ joystick
// Copy/Paste working through longpress 'ABC' and selecting the
// softkey which labelled as our need
//
// Clipboard content remain even when example closed
// ---------------------------------------------------------
//
void CRTEContainer::DemoL()
{
iRtEd->SetCursorPosL(0,EFalse);
// Set the Demo text to Richtext Editor
TBuf<KBufSize> Demobuf;
CEikonEnv::Static()->ReadResource(Demobuf, R_TYPE_II_DIALOG_TBUF_DEMO_TEXT);
iRtEd->SetTextL(&Demobuf);
// Insert a Bipmaps to Richtext
InsertMyPictureL(KLeftImagePositionInTheText);
InsertMyPictureL(KRightImagePositionInTheText);
//// To Compare the '\f' to EParagraphDelimiter change the comment status of the two following lines
//iRtEd->RichText()->InsertL( KEndofCenterFormat , CEditableText::EParagraphDelimiter);
_LIT(KFormat, "\f");
iRtEd->RichText()->InsertL( KEndofCenterFormat , KFormat);
// Basic Text Formatting border by EParagraphDelimiter, same as in Forum Nokia's Type - Example
iRtEd->RichText()->InsertL( KLeftImagePositionInTheText , CEditableText::EParagraphDelimiter);
// Do some color change
SetSelectionL(KLeftImagePositionInTheText, KRightImagePositionInTheText);
SetColor(KRgbRed);
SetSelectionL(KLeftNokia, KRightNokia);
SetColor(KRgbBlue);
//set newline end of document
iRtEd->RichText()->InsertL(iRtEd->Text()->DocumentLength() , CEditableText::ELineBreak);
// Set the cursor end of the document
iRtEd->SetCursorPosL(iRtEd->Text()->DocumentLength(), EFalse);
}
void CRTEContainer::SetupL()
{
// One way to remove the selection
//iRtEd->ClearSelectionL();
// Copy-Paste Support is allowed in Edwin but we can disable
// to do that uncomment the following line
//iRtEd->EnableCcpuSupportL(EFalse);
iRtEd->EnableCcpuSupportL(ETrue);
// Another way to remove the selection.
iRtEd->SetCursorPosL(0, EFalse);
iRtEd->UpdateScrollBarsL();
SizeChanged();
}
// ---------------------------------------------------------
// CRTEContainer::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CRTEContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
iBitmap = new (ELeave) CArrayFixFlat<CFbsBitmap *>(2); // DemoL() show two image
iRtEd = new (ELeave) CEikRichTextEditor;
iStatusLine = new (ELeave) CEikLabel;
iStatusLine->SetAlignment(EHCenterVCenter);
Prepare();
PrepareBitmapL();
iRtEd->ConstructL(this,0,0,0);
iRtEd->SetFocus(ETrue);
SetRect(aRect);
IntroL();
ActivateL();
SetupL();
}
// ---------------------------------------------------------
// CRTEContainer::~CRTEContainer()
// Destructor - Free the allocated resources
// ---------------------------------------------------------
CRTEContainer::~CRTEContainer()
{
if(iRtEd)
delete iRtEd;
if(iStatusLine)
delete iStatusLine;
// Delete each image, which have reference in the Array
for(int i=0;i<iBitmap->Count();i++)
{
if(iBitmap->At(i))
delete iBitmap->At(i);
}
// Free the Array
if(iBitmap)
delete iBitmap;
}
// ---------------------------------------------------------
// CRTEContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CRTEContainer::SizeChanged()
{
TRect rect = Rect();
TInt StatusLineHeight = iStatusLine->Font()->HeightInPixels()+6;
iStatusLine->SetExtent(TPoint(0, 0),TSize(rect.Width(), StatusLineHeight));
#ifdef __SERIES60_3X__
TRect ScrollBarRect = iRtEd->ScrollBarFrame()->VerticalScrollBar()->Rect();
//In 3rd edition CEikRichTextEditor draw the view for the whole rect and
//the scrollbar doesn't show. That is a reason why CEikRichTextEditor Width() is
//rect.Width()-ScrollBarRect.Width()
iRtEd->SetExtent(TPoint(0,StatusLineHeight),
TSize(rect.Width()-ScrollBarRect.Width(), rect.Height()-StatusLineHeight));
#else
iRtEd->SetExtent(TPoint(0,StatusLineHeight),
TSize(rect.Width(), rect.Height()-StatusLineHeight));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -