0
|
1 |
/*
|
|
2 |
* Copyright (c) 2006 - 2007 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
1
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
0
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
1
|
14 |
* Description:
|
0
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
// INCLUDE FILES
|
|
20 |
#include "RichTextEditorContainer.h"
|
|
21 |
#include <txtrich.h> //Richtext
|
|
22 |
#include <eikrted.h> //RichText Editor
|
|
23 |
#include <avkon.mbg> // Image Ids
|
|
24 |
#include <eikenv.h> // ReadResource()
|
|
25 |
#include <RichTextEditor.rsg> // Demo Text Buffer
|
|
26 |
#include "mypicture.h" // CMyPicture
|
|
27 |
#include <AknUtils.h>
|
1
|
28 |
#include <eikapp.h>
|
0
|
29 |
|
|
30 |
|
|
31 |
// ================= MEMBER FUNCTIONS =======================
|
|
32 |
|
|
33 |
// Demo shows the T9 (Front End Processor) ,Scroller,
|
|
34 |
// "Insert Picture", disable Copy-Paste feature
|
|
35 |
// in RichText Editor
|
|
36 |
|
|
37 |
// CONSTANTS
|
|
38 |
_LIT( KImageBitmapFile, "picture.mbm");
|
|
39 |
//Text and images positions.
|
|
40 |
const TInt KLeftImagePositionInTheText = 21;
|
|
41 |
const TInt KRightImagePositionInTheText = 38;
|
|
42 |
const TInt KEndofCenterFormat = 55;
|
|
43 |
const TInt KLeftNokia = 6;
|
|
44 |
const TInt KRightNokia = 11;
|
|
45 |
const TInt KKImageWidth = 283;
|
|
46 |
const TInt KImageHeight = 113;
|
|
47 |
//buffer size
|
|
48 |
const TInt KBufSize = 256;
|
|
49 |
|
|
50 |
// ---------------------------------------------------------
|
|
51 |
// CRTEContainer::Prepare()
|
|
52 |
// Set the Editor flags
|
|
53 |
// ---------------------------------------------------------
|
|
54 |
//
|
|
55 |
void CRTEContainer::Prepare()
|
|
56 |
{
|
|
57 |
|
|
58 |
// Lower Case
|
|
59 |
iRtEd->SetAknEditorCase(EAknEditorLowerCase);
|
|
60 |
// Fixed case
|
|
61 |
|
|
62 |
iRtEd->SetAknEditorFlags
|
|
63 |
(
|
|
64 |
EAknEditorFlagFixedCase| //Set up the Allowed Cases
|
|
65 |
EAknEditorFlagEnableScrollBars // Set up the scroller
|
|
66 |
);
|
|
67 |
}
|
|
68 |
|
|
69 |
// ---------------------------------------------------------
|
|
70 |
// CRTEContainer::PreparePicture()
|
|
71 |
// Append Bitmap to iBitmap Array
|
|
72 |
// ---------------------------------------------------------
|
|
73 |
//
|
|
74 |
void CRTEContainer::PrepareBitmapL()
|
|
75 |
{
|
1
|
76 |
|
0
|
77 |
RFs fsSession;
|
|
78 |
User::LeaveIfError(fsSession.Connect());
|
|
79 |
CleanupClosePushL( fsSession );
|
|
80 |
TFileName name;
|
|
81 |
fsSession.PrivatePath( name );
|
|
82 |
name.Append( KImageBitmapFile );
|
|
83 |
|
|
84 |
#ifndef __WINS__
|
|
85 |
// insert the drive to the private path
|
|
86 |
TParsePtrC parse(
|
|
87 |
(CEikonEnv::Static()->EikAppUi()->Application())->AppFullName() );
|
|
88 |
name.Insert( 0, parse.Drive() );
|
|
89 |
#endif
|
|
90 |
|
1
|
91 |
|
0
|
92 |
|
|
93 |
// Create and Load the Bitmap
|
|
94 |
CFbsBitmap* bitmap = new( ELeave )CFbsBitmap;
|
|
95 |
CleanupStack::PushL(bitmap);
|
|
96 |
User::LeaveIfError(bitmap->Load(name));
|
|
97 |
//we have to free the memory at the Destructor() -> store the bitmap memory address
|
|
98 |
iBitmap->AppendL(bitmap);
|
|
99 |
|
|
100 |
CleanupStack::Pop(); //bitmap - container free bitmap at the destructor
|
1
|
101 |
|
0
|
102 |
CleanupStack::PopAndDestroy(1, &fsSession);
|
1
|
103 |
|
0
|
104 |
// last item in iBitmap array is ready to Insert
|
|
105 |
}
|
|
106 |
|
|
107 |
// ---------------------------------------------------------
|
|
108 |
// CRTEContainer::InsertMyPictureL()
|
|
109 |
// Call Richtext's InsertL() with the CPicture
|
|
110 |
// ---------------------------------------------------------
|
|
111 |
//
|
|
112 |
void CRTEContainer::InsertMyPictureL(TInt aPos)
|
|
113 |
{
|
|
114 |
CMyPicture* picture;
|
|
115 |
// Create a CPicture derived class which will draw our image, depending this Size
|
|
116 |
picture = new( ELeave )CMyPicture(TSize(KKImageWidth,KImageHeight),
|
|
117 |
*(iBitmap->At(iBitmap->Count()-1)/*process the last item of iBitmap*/));
|
|
118 |
CleanupStack::PushL(picture);
|
|
119 |
// Prepare the Picture header, which will be instered into the Richtext
|
|
120 |
TPictureHeader header;
|
|
121 |
header.iPicture =TSwizzle<CPicture>(picture);
|
|
122 |
iRtEd->RichText()->InsertL( aPos,header);
|
|
123 |
CleanupStack::Pop(); // picture - Richtext take the ownership
|
|
124 |
}
|
|
125 |
|
|
126 |
// ---------------------------------------------------------
|
|
127 |
// CRTEContainer::Demo()
|
|
128 |
// Create Demo Text Content
|
|
129 |
//
|
|
130 |
// Selecting text as holding the 'ABC'+ joystick
|
|
131 |
// Copy/Paste working through longpress 'ABC' and selecting the
|
|
132 |
// softkey which labelled as our need
|
|
133 |
//
|
|
134 |
// Clipboard content remain even when example closed
|
|
135 |
// ---------------------------------------------------------
|
|
136 |
//
|
|
137 |
void CRTEContainer::DemoL()
|
|
138 |
{
|
|
139 |
iRtEd->SetCursorPosL(0,EFalse);
|
|
140 |
// Set the Demo text to Richtext Editor
|
|
141 |
TBuf<KBufSize> Demobuf;
|
|
142 |
CEikonEnv::Static()->ReadResource(Demobuf, R_TYPE_II_DIALOG_TBUF_DEMO_TEXT);
|
|
143 |
iRtEd->SetTextL(&Demobuf);
|
|
144 |
|
|
145 |
// Insert a Bipmaps to Richtext
|
|
146 |
InsertMyPictureL(KLeftImagePositionInTheText);
|
|
147 |
InsertMyPictureL(KRightImagePositionInTheText);
|
|
148 |
|
|
149 |
//// To Compare the '\f' to EParagraphDelimiter change the comment status of the two following lines
|
|
150 |
//iRtEd->RichText()->InsertL( KEndofCenterFormat , CEditableText::EParagraphDelimiter);
|
|
151 |
_LIT(KFormat, "\f");
|
|
152 |
iRtEd->RichText()->InsertL( KEndofCenterFormat , KFormat);
|
|
153 |
|
|
154 |
// Basic Text Formatting border by EParagraphDelimiter, same as in Forum Nokia's Type - Example
|
|
155 |
iRtEd->RichText()->InsertL( KLeftImagePositionInTheText , CEditableText::EParagraphDelimiter);
|
|
156 |
|
|
157 |
// Do some color change
|
|
158 |
SetSelectionL(KLeftImagePositionInTheText, KRightImagePositionInTheText);
|
|
159 |
SetColor(KRgbRed);
|
|
160 |
SetSelectionL(KLeftNokia, KRightNokia);
|
|
161 |
SetColor(KRgbBlue);
|
|
162 |
|
|
163 |
//set newline end of document
|
|
164 |
iRtEd->RichText()->InsertL(iRtEd->Text()->DocumentLength() , CEditableText::ELineBreak);
|
|
165 |
|
|
166 |
// Set the cursor end of the document
|
|
167 |
iRtEd->SetCursorPosL(iRtEd->Text()->DocumentLength(), EFalse);
|
|
168 |
}
|
|
169 |
|
|
170 |
void CRTEContainer::SetupL()
|
|
171 |
{
|
|
172 |
// One way to remove the selection
|
|
173 |
//iRtEd->ClearSelectionL();
|
|
174 |
|
|
175 |
// Copy-Paste Support is allowed in Edwin but we can disable
|
|
176 |
// to do that uncomment the following line
|
|
177 |
//iRtEd->EnableCcpuSupportL(EFalse);
|
|
178 |
iRtEd->EnableCcpuSupportL(ETrue);
|
|
179 |
// Another way to remove the selection.
|
|
180 |
iRtEd->SetCursorPosL(0, EFalse);
|
|
181 |
|
|
182 |
iRtEd->UpdateScrollBarsL();
|
|
183 |
SizeChanged();
|
|
184 |
}
|
|
185 |
|
|
186 |
// ---------------------------------------------------------
|
|
187 |
// CRTEContainer::ConstructL(const TRect& aRect)
|
|
188 |
// EPOC two phased constructor
|
|
189 |
// ---------------------------------------------------------
|
|
190 |
//
|
|
191 |
void CRTEContainer::ConstructL(const TRect& aRect)
|
|
192 |
{
|
|
193 |
CreateWindowL();
|
|
194 |
|
|
195 |
iBitmap = new (ELeave) CArrayFixFlat<CFbsBitmap *>(2); // DemoL() show two image
|
|
196 |
iRtEd = new (ELeave) CEikRichTextEditor;
|
|
197 |
|
|
198 |
iStatusLine = new (ELeave) CEikLabel;
|
|
199 |
iStatusLine->SetAlignment(EHCenterVCenter);
|
|
200 |
|
|
201 |
Prepare();
|
|
202 |
PrepareBitmapL();
|
|
203 |
|
|
204 |
iRtEd->ConstructL(this,0,0,0);
|
|
205 |
iRtEd->SetFocus(ETrue);
|
|
206 |
|
|
207 |
SetRect(aRect);
|
|
208 |
|
|
209 |
IntroL();
|
|
210 |
ActivateL();
|
|
211 |
SetupL();
|
|
212 |
}
|
|
213 |
|
|
214 |
// ---------------------------------------------------------
|
|
215 |
// CRTEContainer::~CRTEContainer()
|
|
216 |
// Destructor - Free the allocated resources
|
|
217 |
// ---------------------------------------------------------
|
|
218 |
|
|
219 |
CRTEContainer::~CRTEContainer()
|
|
220 |
{
|
|
221 |
if(iRtEd)
|
|
222 |
delete iRtEd;
|
|
223 |
|
|
224 |
if(iStatusLine)
|
|
225 |
delete iStatusLine;
|
|
226 |
|
|
227 |
// Delete each image, which have reference in the Array
|
|
228 |
for(int i=0;i<iBitmap->Count();i++)
|
|
229 |
{
|
|
230 |
if(iBitmap->At(i))
|
|
231 |
delete iBitmap->At(i);
|
|
232 |
}
|
|
233 |
// Free the Array
|
|
234 |
if(iBitmap)
|
|
235 |
delete iBitmap;
|
|
236 |
}
|
|
237 |
|
|
238 |
// ---------------------------------------------------------
|
|
239 |
// CRTEContainer::SizeChanged()
|
|
240 |
// Called by framework when the view size is changed
|
|
241 |
// ---------------------------------------------------------
|
|
242 |
//
|
|
243 |
void CRTEContainer::SizeChanged()
|
|
244 |
{
|
|
245 |
TRect rect = Rect();
|
|
246 |
TInt StatusLineHeight = iStatusLine->Font()->HeightInPixels()+6;
|
|
247 |
iStatusLine->SetExtent(TPoint(0, 0),TSize(rect.Width(), StatusLineHeight));
|
|
248 |
|
1
|
249 |
|
0
|
250 |
TRect ScrollBarRect = iRtEd->ScrollBarFrame()->VerticalScrollBar()->Rect();
|
|
251 |
//In 3rd edition CEikRichTextEditor draw the view for the whole rect and
|
|
252 |
//the scrollbar doesn't show. That is a reason why CEikRichTextEditor Width() is
|
|
253 |
//rect.Width()-ScrollBarRect.Width()
|
|
254 |
iRtEd->SetExtent(TPoint(0,StatusLineHeight),
|
|
255 |
TSize(rect.Width()-ScrollBarRect.Width(), rect.Height()-StatusLineHeight));
|
1
|
256 |
|
0
|
257 |
}
|
|
258 |
|
|
259 |
// ---------------------------------------------------------
|
|
260 |
// CRTEContainer::CountComponentControls() const
|
|
261 |
// ---------------------------------------------------------
|
|
262 |
//
|
|
263 |
TInt CRTEContainer::CountComponentControls() const
|
|
264 |
{
|
|
265 |
return 2; // return number of controls inside this container
|
|
266 |
}
|
|
267 |
|
|
268 |
// ---------------------------------------------------------
|
|
269 |
// CRTEContainer::ComponentControl(TInt aIndex) const
|
|
270 |
// ---------------------------------------------------------
|
|
271 |
//
|
|
272 |
CCoeControl* CRTEContainer::ComponentControl(TInt aIndex) const
|
|
273 |
{
|
|
274 |
switch ( aIndex )
|
|
275 |
{
|
|
276 |
case 0:
|
|
277 |
return iRtEd;
|
|
278 |
case 1:
|
|
279 |
return iStatusLine;
|
|
280 |
default:
|
|
281 |
return NULL;
|
|
282 |
}
|
|
283 |
}
|
|
284 |
|
|
285 |
// ---------------------------------------------------------
|
|
286 |
// CRTEContainer::Draw(const TRect& aRect) const
|
|
287 |
// ---------------------------------------------------------
|
|
288 |
//
|
|
289 |
void CRTEContainer::Draw(const TRect& aRect) const
|
|
290 |
{
|
|
291 |
CWindowGc& gc = SystemGc();
|
|
292 |
gc.SetPenStyle(CGraphicsContext::ENullPen);
|
|
293 |
gc.SetBrushColor(KRgbWhite);
|
|
294 |
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
|
|
295 |
gc.DrawRect(aRect);
|
|
296 |
}
|
|
297 |
|
|
298 |
// ---------------------------------------------------------
|
|
299 |
// OfferKeyEventL()
|
|
300 |
// Distribute the key event to the Editor
|
|
301 |
// ---------------------------------------------------------
|
|
302 |
//
|
|
303 |
TKeyResponse CRTEContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
|
|
304 |
{
|
|
305 |
if (iRtEd->IsFocused())
|
|
306 |
{
|
|
307 |
return iRtEd->OfferKeyEventL(aKeyEvent, aType);
|
|
308 |
}
|
|
309 |
else
|
|
310 |
{
|
|
311 |
return EKeyWasNotConsumed;
|
|
312 |
}
|
|
313 |
}
|
|
314 |
|
|
315 |
// ----------------------------------------------------
|
|
316 |
// SetAlignment(CParaFormat::TAlignment aAlignment)
|
|
317 |
//
|
|
318 |
// Alignment formatting apply to the actual paragraph
|
|
319 |
// If there is only one, it apply for the whole text
|
|
320 |
//
|
|
321 |
// We expect one of the following input parameter value:
|
|
322 |
// CParaFormat::ELeftAlign
|
|
323 |
// CParaFormat::ECenterAlign
|
|
324 |
// CParaFormat::ERightAlign
|
|
325 |
//
|
|
326 |
// ----------------------------------------------------
|
|
327 |
void CRTEContainer::SetAlignment(CParaFormat::TAlignment aAlignment)
|
|
328 |
{
|
|
329 |
CParaFormat paraFormat;
|
|
330 |
TParaFormatMask paraFormatMask;
|
|
331 |
|
|
332 |
paraFormatMask.SetAttrib(EAttAlignment); // set the mask
|
|
333 |
paraFormat.iHorizontalAlignment = aAlignment;
|
|
334 |
|
|
335 |
iRtEd->ApplyParaFormatL(¶Format, paraFormatMask);
|
|
336 |
|
|
337 |
Echo(R_TYPE_DIALOG_TBUF_INDICATOR_ALIGNMENT);
|
|
338 |
}
|
|
339 |
|
|
340 |
// ----------------------------------------------------
|
|
341 |
// SetSelectionL(TInt aCursorPos,TInt aAnchorPos)
|
|
342 |
// Select a text in the Rich text editor
|
|
343 |
// ----------------------------------------------------
|
|
344 |
void CRTEContainer::SetSelectionL(TInt aCursorPos,TInt aAnchorPos)
|
|
345 |
{
|
|
346 |
iRtEd->SetSelectionL(aCursorPos,aAnchorPos);
|
|
347 |
}
|
|
348 |
|
|
349 |
// ----------------------------------------------------
|
|
350 |
// SetCharacterBIUAttrib(CEikGlobalTextEditor::TFontStyleFlags aFontFlags)
|
|
351 |
//
|
|
352 |
// Character formating apply for the selected text
|
|
353 |
// If nothing is selected it apply to actual word
|
|
354 |
// We expect one of the following input parameter value:
|
|
355 |
// CEikGlobalTextEditor::EBold
|
|
356 |
// CEikGlobalTextEditor::EItalic
|
|
357 |
// CEikGlobalTextEditor::EUnderline
|
|
358 |
// ----------------------------------------------------
|
|
359 |
|
|
360 |
void CRTEContainer::SetCharacterBIUAttribL(CEikGlobalTextEditor::TFontStyleFlags aFontFlags)
|
|
361 |
{
|
|
362 |
iRtEd->BoldItalicUnderlineEventL(aFontFlags);
|
|
363 |
Echo(R_TYPE_DIALOG_TBUF_INDICATOR_CHARACTER_FORMAT);
|
|
364 |
}
|
|
365 |
|
1
|
366 |
|
0
|
367 |
// ----------------------------------------------------
|
|
368 |
// SetFont(TInt aFontId)
|
|
369 |
// Change the text's font in the editor
|
|
370 |
// to the one specified as input parameter for the function
|
|
371 |
// ----------------------------------------------------
|
|
372 |
void CRTEContainer::SetFont(TInt aFontId)
|
|
373 |
{
|
|
374 |
// Get a logical font to base my font on:
|
|
375 |
const CFont* logicalFont = AknLayoutUtils::FontFromId(aFontId);
|
|
376 |
// Extract font information
|
|
377 |
TFontSpec fontspec = logicalFont->FontSpecInTwips();
|
|
378 |
|
|
379 |
TCharFormat charFormat(fontspec.iTypeface.iName, fontspec.iHeight);
|
|
380 |
TCharFormatMask charFormatMask;
|
|
381 |
|
|
382 |
charFormatMask.SetAttrib(EAttFontTypeface);
|
|
383 |
charFormatMask.SetAttrib(EAttFontHeight);
|
|
384 |
|
|
385 |
iRtEd->ApplyCharFormatL(charFormat, charFormatMask);
|
|
386 |
|
|
387 |
Echo(R_TYPE_DIALOG_TBUF_INDICATOR_FONT);
|
|
388 |
}
|
|
389 |
// ----------------------------------------------------
|
|
390 |
// Strike()
|
|
391 |
// Toggle between strikethrough or not strikethrough text
|
|
392 |
// It depend only bool switch in the code, which turn to opposite in every
|
|
393 |
// case Strikethrough selected from the menu.
|
|
394 |
// ----------------------------------------------------
|
|
395 |
void CRTEContainer::Strike()
|
|
396 |
{
|
|
397 |
TCharFormat charFormat;
|
|
398 |
TCharFormatMask charFormatMask;
|
|
399 |
|
|
400 |
iStrike=!iStrike;
|
|
401 |
charFormat.iFontPresentation.iStrikethrough=iStrike?EStrikethroughOn:EStrikethroughOff;
|
|
402 |
charFormatMask.SetAttrib(EAttFontStrikethrough);
|
|
403 |
iRtEd->ApplyCharFormatL(charFormat, charFormatMask);
|
|
404 |
|
|
405 |
if(iStrike)
|
|
406 |
{
|
|
407 |
Echo(R_TYPE_DIALOG_TBUF_INDICATOR_STRIKE_ON);
|
|
408 |
}
|
|
409 |
else
|
|
410 |
{
|
|
411 |
Echo(R_TYPE_DIALOG_TBUF_INDICATOR_STRIKE_OFF);
|
|
412 |
}
|
|
413 |
}
|
|
414 |
|
|
415 |
// ----------------------------------------------------
|
|
416 |
// SetColor(TRgb aColor)
|
|
417 |
// Set the selected text color based on the input parameter
|
|
418 |
// If nothing selected, text color changed only the cursor position.
|
|
419 |
// ----------------------------------------------------
|
|
420 |
void CRTEContainer::SetColor(TRgb aColor)
|
|
421 |
{
|
|
422 |
TCharFormat charFormat;
|
|
423 |
TCharFormatMask charFormatMask;
|
|
424 |
|
|
425 |
charFormat.iFontPresentation.iTextColor = aColor;
|
|
426 |
charFormatMask.SetAttrib(EAttColor);
|
|
427 |
iRtEd->ApplyCharFormatL(charFormat, charFormatMask);
|
|
428 |
|
|
429 |
// iRtEd->SetBackgroundColorL(aColor);
|
|
430 |
// It is possible to change the background color - if foreground and background
|
|
431 |
// color is same, the text became invisible.
|
|
432 |
}
|
|
433 |
|
|
434 |
// ----------------------------------------------------
|
|
435 |
// Echo(TInt aMessage)
|
|
436 |
// Echo the last operation to the status line
|
|
437 |
// ----------------------------------------------------
|
|
438 |
void CRTEContainer::Echo(TInt aMessage)
|
|
439 |
{
|
|
440 |
TBuf<32> buf;
|
|
441 |
CEikonEnv::Static()->ReadResource(buf, aMessage);
|
|
442 |
iStatusLine->SetTextL(buf);
|
|
443 |
}
|
|
444 |
|
|
445 |
// ----------------------------------------------------
|
|
446 |
// IntroL()
|
|
447 |
// Create Intro Text.
|
|
448 |
// ----------------------------------------------------
|
|
449 |
void CRTEContainer::IntroL()
|
|
450 |
{
|
|
451 |
TBuf<KBufSize> Introbuf;
|
|
452 |
CEikonEnv::Static()->ReadResource(Introbuf, R_TYPE_DIALOG_TBUF_INTRO_TEXT);
|
|
453 |
|
|
454 |
TBuf<KBufSize> HelpText;
|
|
455 |
CEikonEnv::Static()->ReadResource(HelpText, R_TYPE_DIALOG_TBUF_INTRO_HELP_TEXT);
|
|
456 |
HelpText.Append(CEditableText::ELineBreak);
|
|
457 |
|
|
458 |
//Start the center format.
|
|
459 |
SetAlignment(CParaFormat::ECenterAlign);
|
|
460 |
|
|
461 |
//Set the text.
|
|
462 |
iRtEd->SetTextL(&Introbuf);
|
|
463 |
iRtEd->RichText()->InsertL(iRtEd->Text()->DocumentLength()/* at the end*/, HelpText);
|
|
464 |
|
|
465 |
Echo(R_TYPE_DIALOG_TBUF_INDICATOR_DEMO);
|
|
466 |
}
|
|
467 |
|
|
468 |
// End of File
|