📄 richtexteditorcontainer.cpp
字号:
/*
* ============================================================================
* Name : CRTEContainer from RichTextEditorContainer.cpp
* Part of : RichTextEditor
* Created : 05/08/2006 by Forum Nokia
* Version : 2.0
*
* Copyright (c) 2006 - 2007 Nokia Corporation.
* This material, including documentation and any related
* computer programs, is protected by copyright controlled by
* Nokia Corporation.
* ============================================================================
*/
// 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>
#ifdef __SERIES60_3X__
#include <eikapp.h>
#endif
// ================= 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()
{
#ifndef __SERIES60_3X__
TFileName name(KImageBitmapFile);
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
#else // 3rd ed
RFs fsSession;
User::LeaveIfError(fsSession.Connect());
CleanupClosePushL( fsSession );
TFileName name;
fsSession.PrivatePath( name );
name.Append( KImageBitmapFile );
#ifndef __WINS__
// insert the drive to the private path
TParsePtrC parse(
(CEikonEnv::Static()->EikAppUi()->Application())->AppFullName() );
name.Insert( 0, parse.Drive() );
#endif
#endif
// Create and Load the Bitmap
CFbsBitmap* 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
#ifdef __SERIES60_3X__
CleanupStack::PopAndDestroy(1, &fsSession);
#endif
// 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()
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -