64
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.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 |
*
|
|
14 |
* Description: ESMR editor impl.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "cesmreditor.h"
|
|
19 |
#include "nmrcolormanager.h"
|
|
20 |
#include "esmrfieldbuilderdef.h"
|
|
21 |
#include "esmrdef.h"
|
|
22 |
#include "mesmrlistobserver.h"
|
|
23 |
|
|
24 |
#include <txtfrmat.h>
|
|
25 |
#include <txtglobl.h>
|
|
26 |
#include <txtrich.h>
|
|
27 |
#include <gulfont.h>
|
|
28 |
#include <eikenv.h>
|
|
29 |
#include <avkon.hrh>
|
|
30 |
#include <AknUtils.h>
|
|
31 |
|
|
32 |
|
|
33 |
#include "emailtrace.h"
|
|
34 |
|
|
35 |
// ======== MEMBER FUNCTIONS ========
|
|
36 |
|
|
37 |
// ---------------------------------------------------------------------------
|
|
38 |
// CESMREditor::NewL
|
|
39 |
// ---------------------------------------------------------------------------
|
|
40 |
//
|
|
41 |
EXPORT_C CESMREditor* CESMREditor::NewL( )
|
|
42 |
{
|
|
43 |
FUNC_LOG;
|
|
44 |
/*
|
|
45 |
Default parameters for edwin. Note that as the parent
|
|
46 |
is NULL, the edwin MUST be EOwnsWindow-type edwin.
|
|
47 |
*/
|
|
48 |
return CESMREditor::NewL (
|
|
49 |
NULL, // parent
|
|
50 |
1, // number of lines
|
|
51 |
KTextLimit, // text limit
|
|
52 |
CEikEdwin::EResizable | CEikEdwin::EOwnsWindow );
|
|
53 |
}
|
|
54 |
|
|
55 |
// ---------------------------------------------------------------------------
|
|
56 |
// CESMREditor::NewL
|
|
57 |
// ---------------------------------------------------------------------------
|
|
58 |
//
|
|
59 |
EXPORT_C CESMREditor* CESMREditor::NewL(
|
|
60 |
const CCoeControl* aParent, TInt aNumberOfLines,
|
|
61 |
TInt aTextLimit, TInt aEdwinFlags )
|
|
62 |
{
|
|
63 |
FUNC_LOG;
|
|
64 |
CESMREditor* self = new (ELeave) CESMREditor();
|
|
65 |
CleanupStack::PushL ( self );
|
|
66 |
self->ConstructL ( aParent, aNumberOfLines, aTextLimit, aEdwinFlags );
|
|
67 |
CleanupStack::Pop ( self );
|
|
68 |
return self;
|
|
69 |
}
|
|
70 |
|
|
71 |
// ---------------------------------------------------------------------------
|
|
72 |
// CESMREditor::~CESMREditor
|
|
73 |
// ---------------------------------------------------------------------------
|
|
74 |
//
|
|
75 |
EXPORT_C CESMREditor::~CESMREditor( )
|
|
76 |
{
|
|
77 |
FUNC_LOG;
|
|
78 |
delete iDefaultText;
|
|
79 |
}
|
|
80 |
|
|
81 |
// ---------------------------------------------------------------------------
|
|
82 |
// CESMREditor::PositionChanged
|
|
83 |
// ---------------------------------------------------------------------------
|
|
84 |
//
|
|
85 |
EXPORT_C void CESMREditor::PositionChanged( )
|
|
86 |
{
|
|
87 |
FUNC_LOG;
|
|
88 |
CTextView* view = TextView();
|
|
89 |
if ( view )
|
|
90 |
{
|
|
91 |
view->SetViewRect ( Rect() );
|
|
92 |
}
|
|
93 |
}
|
|
94 |
|
|
95 |
// ---------------------------------------------------------------------------
|
|
96 |
// CESMREditor::OfferKeyEventL
|
|
97 |
// ---------------------------------------------------------------------------
|
|
98 |
//
|
|
99 |
EXPORT_C TKeyResponse CESMREditor::OfferKeyEventL(
|
|
100 |
const TKeyEvent& aKeyEvent,TEventCode aType )
|
|
101 |
{
|
|
102 |
FUNC_LOG;
|
|
103 |
|
|
104 |
TKeyResponse ret = CEikRichTextEditor::OfferKeyEventL(aKeyEvent, aType);
|
|
105 |
|
|
106 |
if ( aType == EEventKey )
|
|
107 |
{
|
|
108 |
TPoint firstRowExtra(0,RowHeight());
|
|
109 |
TextLayout()->DocPosToXyPosL( 0, firstRowExtra);
|
|
110 |
//firstRowExtra.iY
|
|
111 |
TPoint rel(PositionRelativeToScreen());
|
|
112 |
TPoint point(0,0);
|
|
113 |
TextLayout()->DocPosToXyPosL( CursorPos(), point);
|
|
114 |
|
|
115 |
// +1 because first line is zero
|
|
116 |
TInt currentLineNumber = TextLayout()->GetLineNumber( CursorPos() ) + 1;
|
|
117 |
TInt cursorLowerPosition = currentLineNumber * RowHeight();
|
|
118 |
TInt cursorUpperPosition = ( currentLineNumber -1 )* RowHeight();
|
|
119 |
|
|
120 |
if ( aKeyEvent.iCode == EKeyDownArrow && iObserver)
|
|
121 |
{
|
|
122 |
TPoint firstRowExtra(0,RowHeight());
|
|
123 |
TextLayout()->DocPosToXyPosL( 0, firstRowExtra);
|
|
124 |
TPoint cursorPos(0,0);
|
|
125 |
TextLayout()->DocPosToXyPosL( CursorPos(), cursorPos);
|
|
126 |
TInt edwinTlY = Position().iY;
|
|
127 |
TInt listHeight = iObserver->ListHeight();
|
|
128 |
|
|
129 |
// edwinTlY negative
|
|
130 |
if ( cursorLowerPosition > ( listHeight - edwinTlY ))
|
|
131 |
{
|
|
132 |
iObserver->RePositionFields( -RowHeight() );
|
|
133 |
}
|
|
134 |
}
|
|
135 |
else if ( aKeyEvent.iCode == EKeyUpArrow && iObserver)
|
|
136 |
{
|
|
137 |
TPoint firstRowExtra(0,RowHeight());
|
|
138 |
TextLayout()->DocPosToXyPosL( 0, firstRowExtra);
|
|
139 |
TPoint cursorPos(0,0);
|
|
140 |
TextLayout()->DocPosToXyPosL( CursorPos(), cursorPos);
|
|
141 |
TInt hiddenHeight = Position().iY;
|
|
142 |
// upper corner of field not visible
|
|
143 |
if ( hiddenHeight < 0 )
|
|
144 |
{
|
|
145 |
if ( (cursorPos.iY - firstRowExtra.iY * 2) < (-hiddenHeight))
|
|
146 |
{
|
|
147 |
iObserver->RePositionFields( RowHeight() );
|
|
148 |
}
|
|
149 |
}
|
|
150 |
}
|
|
151 |
}
|
|
152 |
|
|
153 |
|
|
154 |
return ret;
|
|
155 |
}
|
|
156 |
|
|
157 |
// ---------------------------------------------------------------------------
|
|
158 |
// CESMREditor::FocusChanged
|
|
159 |
// ---------------------------------------------------------------------------
|
|
160 |
//
|
|
161 |
EXPORT_C void CESMREditor::FocusChanged(TDrawNow aDrawNow)
|
|
162 |
{
|
|
163 |
FUNC_LOG;
|
|
164 |
|
|
165 |
CEikRichTextEditor::FocusChanged( aDrawNow );
|
|
166 |
|
|
167 |
TRAPD( error, TryToSetSelectionL() );
|
|
168 |
if ( error != KErrNone )
|
|
169 |
{
|
|
170 |
iCoeEnv->HandleError( error );// codescanner::eikonenvstatic
|
|
171 |
}
|
|
172 |
}
|
|
173 |
|
|
174 |
// ---------------------------------------------------------------------------
|
|
175 |
// CESMREditor::HandlePointerEventL
|
|
176 |
// ---------------------------------------------------------------------------
|
|
177 |
//
|
|
178 |
|
|
179 |
void CESMREditor::HandlePointerEventL( const TPointerEvent& aPointerEvent )
|
|
180 |
{
|
|
181 |
if ( Rect().Contains( aPointerEvent.iPosition ) )
|
|
182 |
{
|
|
183 |
switch ( aPointerEvent.iType )
|
|
184 |
{
|
|
185 |
case TPointerEvent::EButton1Down:
|
|
186 |
case TPointerEvent::EButton1Up:
|
|
187 |
{
|
|
188 |
CEikRichTextEditor::HandlePointerEventL( aPointerEvent );
|
|
189 |
break;
|
|
190 |
}
|
|
191 |
default:
|
|
192 |
break;
|
|
193 |
}
|
|
194 |
}
|
|
195 |
}
|
|
196 |
|
|
197 |
// ---------------------------------------------------------------------------
|
|
198 |
// CESMREditor::TryToSetSelectionL
|
|
199 |
// ---------------------------------------------------------------------------
|
|
200 |
//
|
|
201 |
void CESMREditor::TryToSetSelectionL()
|
|
202 |
{
|
|
203 |
FUNC_LOG;
|
|
204 |
if ( IsFocused() )
|
|
205 |
{
|
|
206 |
// set selection to text if it is the default text
|
|
207 |
HBufC* text = GetTextInHBufL();
|
|
208 |
if ( text )
|
|
209 |
{
|
|
210 |
CleanupStack::PushL( text );
|
|
211 |
if ( iDefaultText->Compare( *text ) == KErrNone )
|
|
212 |
{
|
|
213 |
SetSelectionL(0, text->Length() );
|
|
214 |
}
|
|
215 |
CleanupStack::PopAndDestroy( text );
|
|
216 |
}
|
|
217 |
}
|
|
218 |
}
|
|
219 |
|
|
220 |
// ---------------------------------------------------------------------------
|
|
221 |
// CESMREditor::HandleEdwinEventL
|
|
222 |
// ---------------------------------------------------------------------------
|
|
223 |
//
|
|
224 |
EXPORT_C void CESMREditor::HandleEdwinEventL(
|
|
225 |
CEikEdwin* aEdwin,TEdwinEvent aEventType )
|
|
226 |
{
|
|
227 |
FUNC_LOG;
|
|
228 |
if ( aEdwin == this )
|
|
229 |
{
|
|
230 |
switch( aEventType )
|
|
231 |
{
|
|
232 |
case EEventNavigation:
|
|
233 |
{
|
|
234 |
if ( iObserver )
|
|
235 |
{
|
|
236 |
TInt curPos = CursorPos ();
|
|
237 |
TInt textLength = TextLength();
|
|
238 |
// Update viewarea scrolling in cases where the cursor location
|
|
239 |
// is changed directly from bottom to upmost position or vise versa.
|
|
240 |
if ( CursorPos () == TextLength() || CursorPos () == 0 )
|
|
241 |
{
|
|
242 |
// KErrNotFound as field id is interpret as focused field:
|
|
243 |
iObserver->ScrollControlVisible( KErrNotFound );
|
|
244 |
}
|
|
245 |
}
|
|
246 |
break;
|
|
247 |
}
|
|
248 |
|
|
249 |
case EEventTextUpdate:
|
|
250 |
{
|
|
251 |
if ( IsVisible() )
|
|
252 |
{
|
|
253 |
DrawDeferred();
|
|
254 |
}
|
|
255 |
break;
|
|
256 |
}
|
|
257 |
|
|
258 |
default:
|
|
259 |
{
|
|
260 |
break;
|
|
261 |
}
|
|
262 |
}
|
|
263 |
}
|
|
264 |
}
|
|
265 |
|
|
266 |
// ---------------------------------------------------------------------------
|
|
267 |
// CESMREditor::ClearSelectionAndSetTextL
|
|
268 |
// ---------------------------------------------------------------------------
|
|
269 |
//
|
|
270 |
EXPORT_C void CESMREditor::ClearSelectionAndSetTextL( const TDesC& aText )
|
|
271 |
{
|
|
272 |
FUNC_LOG;
|
|
273 |
ClearSelectionL();
|
|
274 |
SetCursorPosL(0, EFalse );
|
|
275 |
SetTextL( &aText );
|
|
276 |
SetCursorPosL(0, EFalse );
|
|
277 |
HandleTextChangedL();
|
|
278 |
}
|
|
279 |
|
|
280 |
// ---------------------------------------------------------------------------
|
|
281 |
// CESMREditor::SetFontL
|
|
282 |
// ---------------------------------------------------------------------------
|
|
283 |
//
|
|
284 |
EXPORT_C void CESMREditor::SetFontL( const CFont* aFont )
|
|
285 |
{
|
|
286 |
FUNC_LOG;
|
|
287 |
const CFont* font = aFont;
|
|
288 |
TFontSpec fontSpec = font->FontSpecInTwips();
|
|
289 |
|
|
290 |
CParaFormat* paraFormat = CParaFormat::NewLC();
|
|
291 |
TParaFormatMask paraFormatMask;
|
|
292 |
paraFormat->iLineSpacingControl = CParaFormat::ELineSpacingExactlyInPixels;
|
|
293 |
|
|
294 |
paraFormatMask.SetAttrib( EAttLineSpacing );
|
|
295 |
paraFormat->iHorizontalAlignment = CParaFormat::ELeftAlign;
|
|
296 |
if ( AknLayoutUtils::LayoutMirrored() )
|
|
297 |
{
|
|
298 |
paraFormat->iHorizontalAlignment = CParaFormat::ERightAlign;
|
|
299 |
}
|
|
300 |
paraFormatMask.SetAttrib( EAttAlignment );
|
|
301 |
|
|
302 |
TCharFormat charFormat;
|
|
303 |
TCharFormatMask formatMask;
|
|
304 |
charFormat.iFontSpec = fontSpec;
|
|
305 |
|
|
306 |
formatMask.SetAttrib( EAttFontTypeface );
|
|
307 |
formatMask.SetAttrib( EAttFontHeight );
|
|
308 |
formatMask.SetAttrib( EAttFontPosture );
|
|
309 |
formatMask.SetAttrib( EAttFontStrokeWeight );
|
|
310 |
formatMask.SetAttrib(EAttFontHighlightColor);
|
|
311 |
formatMask.SetAttrib( EAttColor );
|
|
312 |
|
|
313 |
charFormat.iFontPresentation.iTextColor =
|
|
314 |
NMRColorManager::Color( NMRColorManager::EMRMainAreaTextColor );
|
|
315 |
|
|
316 |
charFormat.iFontPresentation.iHighlightColor =
|
|
317 |
NMRColorManager::Color( NMRColorManager::EMRCutCopyPasteHighlightColor );
|
|
318 |
|
|
319 |
CParaFormatLayer* paraFormatLayer =
|
|
320 |
CParaFormatLayer::NewL( paraFormat, paraFormatMask );
|
|
321 |
CleanupStack::PushL( paraFormatLayer );
|
|
322 |
CCharFormatLayer* charFormatLayer =
|
|
323 |
CCharFormatLayer::NewL( charFormat, formatMask );
|
|
324 |
|
|
325 |
SetParaFormatLayer( paraFormatLayer );
|
|
326 |
CleanupStack::Pop( paraFormatLayer );
|
|
327 |
CleanupStack::PopAndDestroy( paraFormat );
|
|
328 |
SetCharFormatLayer( charFormatLayer );
|
|
329 |
|
|
330 |
// This forces CEikEdwin::OnReformatL to notify observer
|
|
331 |
// through HandleEdwinSizeEventL about changed size.
|
|
332 |
// It is notified only if linecount changes.
|
|
333 |
CEikEdwin::iNumberOfLines = 0;
|
|
334 |
CEikEdwin::FormatTextL();
|
|
335 |
}
|
|
336 |
|
|
337 |
// ---------------------------------------------------------------------------
|
|
338 |
// CESMREditor::CursorLinePos
|
|
339 |
// ---------------------------------------------------------------------------
|
|
340 |
//
|
|
341 |
EXPORT_C TInt CESMREditor::CursorLinePos( ) const
|
|
342 |
{
|
|
343 |
FUNC_LOG;
|
|
344 |
return TextLayout()->GetLineNumber ( CursorPos ( ) );
|
|
345 |
}
|
|
346 |
|
|
347 |
// ---------------------------------------------------------------------------
|
|
348 |
// CESMREditor::LineCount
|
|
349 |
// ---------------------------------------------------------------------------
|
|
350 |
//
|
|
351 |
EXPORT_C TInt CESMREditor::LineCount( ) const
|
|
352 |
{
|
|
353 |
FUNC_LOG;
|
|
354 |
// first line is zero, that's why + 1 is added
|
|
355 |
TInt lineCount( TextLayout()->GetLineNumber ( TextLength ( ) ) + 1 );
|
|
356 |
return lineCount;
|
|
357 |
}
|
|
358 |
|
|
359 |
// ---------------------------------------------------------------------------
|
|
360 |
// CESMREditor::RowHeight
|
|
361 |
// ---------------------------------------------------------------------------
|
|
362 |
//
|
|
363 |
EXPORT_C TInt CESMREditor::RowHeight()
|
|
364 |
{
|
|
365 |
FUNC_LOG;
|
|
366 |
TInt bandHeight = TextLayout()->BandHeight();
|
|
367 |
// Starts from zero, so let's increase the count by one.
|
|
368 |
TInt lineNumberCount = TextLayout()->GetLineNumber(TextLength()) + 1;
|
|
369 |
|
|
370 |
return ( bandHeight / lineNumberCount );
|
|
371 |
}
|
|
372 |
|
|
373 |
// ---------------------------------------------------------------------------
|
|
374 |
// CESMREditor::CurrentLineNumber
|
|
375 |
// ---------------------------------------------------------------------------
|
|
376 |
//
|
|
377 |
EXPORT_C TInt CESMREditor::CurrentLineNumber()
|
|
378 |
{
|
|
379 |
FUNC_LOG;
|
|
380 |
// first line is zero, let's increase it by one
|
|
381 |
return TextLayout()->GetLineNumber( CursorPos() ) + 1;
|
|
382 |
}
|
|
383 |
|
|
384 |
// ---------------------------------------------------------------------------
|
|
385 |
// CESMREditor::LineCount
|
|
386 |
// ---------------------------------------------------------------------------
|
|
387 |
//
|
|
388 |
EXPORT_C void CESMREditor::SetDefaultTextL(
|
|
389 |
HBufC* aDefaultText ) // codescanner::nonconsthbufc
|
|
390 |
{
|
|
391 |
FUNC_LOG;
|
|
392 |
SetTextL( aDefaultText );
|
|
393 |
|
|
394 |
if ( iDefaultText )
|
|
395 |
{
|
|
396 |
delete iDefaultText;
|
|
397 |
iDefaultText = NULL;
|
|
398 |
}
|
|
399 |
iDefaultText = aDefaultText;
|
|
400 |
}
|
|
401 |
|
|
402 |
// ---------------------------------------------------------------------------
|
|
403 |
// CESMREditor::LineCount
|
|
404 |
// ---------------------------------------------------------------------------
|
|
405 |
//
|
|
406 |
EXPORT_C const TDesC& CESMREditor::DefaultText()
|
|
407 |
{
|
|
408 |
FUNC_LOG;
|
|
409 |
return *iDefaultText;
|
|
410 |
}
|
|
411 |
|
|
412 |
// ---------------------------------------------------------------------------
|
|
413 |
// CESMREditor::SetListObserver
|
|
414 |
// ---------------------------------------------------------------------------
|
|
415 |
//
|
|
416 |
EXPORT_C void CESMREditor::SetListObserver( MESMRListObserver* aObserver )
|
|
417 |
{
|
|
418 |
FUNC_LOG;
|
|
419 |
iObserver = aObserver;
|
|
420 |
}
|
|
421 |
|
|
422 |
// ---------------------------------------------------------------------------
|
|
423 |
// CESMREditor::CESMREditor
|
|
424 |
// ---------------------------------------------------------------------------
|
|
425 |
//
|
|
426 |
CESMREditor::CESMREditor( )
|
|
427 |
{
|
|
428 |
FUNC_LOG;
|
|
429 |
// Do nothing
|
|
430 |
}
|
|
431 |
|
|
432 |
// ---------------------------------------------------------------------------
|
|
433 |
// CESMREditor::ConstructL
|
|
434 |
// ---------------------------------------------------------------------------
|
|
435 |
//
|
|
436 |
void CESMREditor::ConstructL(const CCoeControl* aParent, TInt aNumberOfLines,
|
|
437 |
TInt aTextLimit, TInt aEdwinFlags )
|
|
438 |
{
|
|
439 |
FUNC_LOG;
|
|
440 |
CEikRichTextEditor::ConstructL ( aParent, aNumberOfLines, aTextLimit,
|
|
441 |
aEdwinFlags );
|
|
442 |
|
|
443 |
AddEdwinObserverL(this);
|
|
444 |
|
|
445 |
SetUpperFullFormattingLength( aTextLimit );
|
|
446 |
|
|
447 |
iLimitLength = aTextLimit;
|
|
448 |
}
|
|
449 |
|
|
450 |
// ---------------------------------------------------------------------------
|
|
451 |
// CESMREditor::GetLimitLength
|
|
452 |
// ---------------------------------------------------------------------------
|
|
453 |
//
|
|
454 |
EXPORT_C TInt CESMREditor::GetLimitLength() const
|
|
455 |
{
|
|
456 |
FUNC_LOG;
|
|
457 |
return iLimitLength;
|
|
458 |
}
|
|
459 |
|
|
460 |
//EOF
|