|
1 /* |
|
2 * Copyright (c) 2007-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: This file implements class CESMRNcsEditor. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "emailtrace.h" |
|
19 #include "cesmrncseditor.h" |
|
20 |
|
21 #include <avkon.hrh> |
|
22 #include <aknenv.h> // CAknEnv |
|
23 #include <txtrich.h> |
|
24 #include <AknUtils.h> // AknLayoutUtils |
|
25 #include <txtglobl.h> |
|
26 |
|
27 #include <AknsConstants.h> |
|
28 #include <AknsUtils.h> |
|
29 #include <AknsSkinInstance.h> |
|
30 #include <AknsBasicBackgroundControlContext.h> |
|
31 |
|
32 #include "cesmrlayoutmgr.h" |
|
33 |
|
34 // ======== MEMBER FUNCTIONS ======== |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // constructor |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 CESMRNcsEditor::CESMRNcsEditor( HBufC* aDefaultText ) : |
|
41 iPreviousFontHeight( -1 ), |
|
42 iPreviousLineSpacingInTwips( -1 ), |
|
43 iDefaultText( aDefaultText ) |
|
44 { |
|
45 FUNC_LOG; |
|
46 //do nothing |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // destructor |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 CESMRNcsEditor::~CESMRNcsEditor() |
|
54 { |
|
55 FUNC_LOG; |
|
56 delete iBgContext; |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CESMRNcsEditor::GetLineRectL() const |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 void CESMRNcsEditor::GetLineRectL( TRect& aLineRect ) const |
|
64 { |
|
65 FUNC_LOG; |
|
66 TPoint position; |
|
67 iLayout->DocPosToXyPosL( CursorPos(), position ); |
|
68 iLayout->GetLineRect( position.iY, aLineRect ); |
|
69 } |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CESMRNcsEditor::CursorLineNumber() const |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 TInt CESMRNcsEditor::CursorLineNumber() const |
|
76 { |
|
77 FUNC_LOG; |
|
78 TInt ret = iLayout->GetLineNumber( CursorPos() ); |
|
79 ret++; |
|
80 return ret; |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // CESMRNcsEditor::CursorPositionL() const |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 TInt CESMRNcsEditor::CursorPositionL() const |
|
88 { |
|
89 FUNC_LOG; |
|
90 // Return the position of the cursor relative |
|
91 // to the top of the control (in pixels) |
|
92 TPoint position; |
|
93 TInt cp = CursorPos(); |
|
94 iLayout->DocPosToXyPosL( cp , position ); |
|
95 position.iY += iLayout->PixelsAboveBand(); |
|
96 return position.iY; |
|
97 } |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 // CESMRNcsEditor::OfferKeyEventL() const |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 TKeyResponse CESMRNcsEditor::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
104 { |
|
105 FUNC_LOG; |
|
106 TKeyResponse ret( EKeyWasNotConsumed ); |
|
107 if( aKeyEvent.iCode == EKeyDelete && CursorPos() == TextLength() ) |
|
108 { |
|
109 ClearSelectionL(); |
|
110 return EKeyWasConsumed; |
|
111 } |
|
112 else |
|
113 { |
|
114 ret = CEikRichTextEditor::OfferKeyEventL( aKeyEvent, aType ); |
|
115 } |
|
116 |
|
117 return ret; |
|
118 } |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // CESMRNcsEditor::SetTextL |
|
122 // ----------------------------------------------------------------------------- |
|
123 // |
|
124 void CESMRNcsEditor::SetTextL( const TDesC* aDes ) |
|
125 { |
|
126 FUNC_LOG; |
|
127 CEikEdwin::SetTextL( aDes ); |
|
128 if ( ( *aDes ).Compare( KNullDesC ) == 0 ) |
|
129 { |
|
130 // when text is emptied, set text color again |
|
131 UpdateColors(); |
|
132 } |
|
133 } |
|
134 |
|
135 // ----------------------------------------------------------------------------- |
|
136 // CESMRNcsEditor::SetRect |
|
137 // ----------------------------------------------------------------------------- |
|
138 // |
|
139 void CESMRNcsEditor::SetRect( const TRect& aRect ) |
|
140 { |
|
141 FUNC_LOG; |
|
142 CCoeControl::SetRect( aRect ); |
|
143 |
|
144 if ( iBgContext ) |
|
145 { |
|
146 iBgContext->SetRect( aRect ); |
|
147 } |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CESMRNcsEditor::HandleResourceChange |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 void CESMRNcsEditor::HandleResourceChange( TInt aType ) |
|
155 { |
|
156 FUNC_LOG; |
|
157 CEikEdwin::HandleResourceChange( aType ); |
|
158 |
|
159 if ( aType == KAknsMessageSkinChange ) |
|
160 { |
|
161 UpdateGraphics(); |
|
162 UpdateColors(); |
|
163 } |
|
164 else if ( aType == KEikMessageColorSchemeChange ) |
|
165 { |
|
166 UpdateColors(); |
|
167 } |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CESMRNcsEditor::SetupEditorL() |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 void CESMRNcsEditor::SetupEditorL() |
|
175 { |
|
176 FUNC_LOG; |
|
177 // Set the cursor position to initialize the edit control |
|
178 SetCursorPosL(0,EFalse); |
|
179 |
|
180 UpdateColors(); |
|
181 UpdateGraphics(); |
|
182 UpdateEditorL(); |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CESMRNcsEditor::UpdateEditorL() |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 void CESMRNcsEditor::UpdateEditorL() |
|
190 { |
|
191 FUNC_LOG; |
|
192 //do nothing |
|
193 } |
|
194 |
|
195 // ----------------------------------------------------------------------------- |
|
196 // CESMRNcsEditor::LineCount() const |
|
197 // ----------------------------------------------------------------------------- |
|
198 // |
|
199 TInt CESMRNcsEditor::LineCount() const |
|
200 { |
|
201 FUNC_LOG; |
|
202 TInt lineCount = iLayout->GetLineNumber( TextLength() ); |
|
203 lineCount++; |
|
204 return lineCount; |
|
205 } |
|
206 |
|
207 TInt CESMRNcsEditor::ScrollableLines() const |
|
208 { |
|
209 FUNC_LOG; |
|
210 TRect lineRect; |
|
211 // First get the rect for one line |
|
212 iLayout->GetLineRect(0, lineRect); |
|
213 TRect rect = Rect(); |
|
214 TInt lines = rect.Height()/lineRect.Height(); |
|
215 return lines; |
|
216 } |
|
217 |
|
218 // ----------------------------------------------------------------------------- |
|
219 // CESMRNcsEditor::PositionChanged() const |
|
220 // ----------------------------------------------------------------------------- |
|
221 // |
|
222 void CESMRNcsEditor::PositionChanged() |
|
223 { |
|
224 FUNC_LOG; |
|
225 |
|
226 if( iTextView ) |
|
227 { |
|
228 TRect displayRect=iBorder.InnerRect(Rect()); |
|
229 displayRect=iMargins.InnerRect(displayRect); |
|
230 iTextView->SetViewRect(displayRect); |
|
231 } |
|
232 } |
|
233 |
|
234 // ----------------------------------------------------------------------------- |
|
235 // CESMRNcsEditor::DebugDump() const |
|
236 // Is is meant for debugging. |
|
237 // Break here to see what the values are. |
|
238 // ----------------------------------------------------------------------------- |
|
239 // |
|
240 #ifdef _DEBUG |
|
241 void CESMRNcsEditor::DebugDump() |
|
242 { |
|
243 FUNC_LOG; |
|
244 TInt aBandHeight = iLayout->BandHeight(); |
|
245 TInt aFirstDocPosFullyInBad = iLayout->FirstDocPosFullyInBand(); |
|
246 TInt aFirstLineInBand = iLayout->FirstLineInBand(); |
|
247 TInt aPixelsAboveBand = iLayout->PixelsAboveBand(); |
|
248 } |
|
249 #endif |
|
250 |
|
251 // ----------------------------------------------------------------------------- |
|
252 // CESMRNcsEditor::SetTextColorL() |
|
253 // ----------------------------------------------------------------------------- |
|
254 // |
|
255 void CESMRNcsEditor::SetTextColorL( TLogicalRgb aColor ) |
|
256 { |
|
257 FUNC_LOG; |
|
258 TCharFormat charFormat; |
|
259 charFormat.iFontPresentation.iTextColor = aColor; |
|
260 TCharFormatMask charFormatMask; |
|
261 charFormatMask.SetAttrib( EAttColor ); |
|
262 ApplyCharFormatL( charFormat, charFormatMask ); |
|
263 } |
|
264 |
|
265 // ----------------------------------------------------------------------------- |
|
266 // CESMRNcsEditor::HasDefaultText() |
|
267 // ----------------------------------------------------------------------------- |
|
268 // |
|
269 TBool CESMRNcsEditor::HasDefaultText() |
|
270 { |
|
271 FUNC_LOG; |
|
272 EditObserver(0,2); |
|
273 |
|
274 return iHasDefaultText; |
|
275 } |
|
276 |
|
277 // ----------------------------------------------------------------------------- |
|
278 // CESMRNcsEditor::TrimmedTextLengthL() |
|
279 // ----------------------------------------------------------------------------- |
|
280 // |
|
281 TInt CESMRNcsEditor::TrimmedTextLengthL() |
|
282 { |
|
283 FUNC_LOG; |
|
284 HBufC* text = GetTextInHBufL(); |
|
285 TInt length = 0; |
|
286 if ( text ) |
|
287 { |
|
288 CleanupStack::PushL( text ); |
|
289 text->Des().TrimAll(); |
|
290 length = text->Des().Length(); |
|
291 CleanupStack::PopAndDestroy( text ); |
|
292 } |
|
293 return length; |
|
294 } |
|
295 |
|
296 // ----------------------------------------------------------------------------- |
|
297 // CESMRNcsEditor::EditObserver() |
|
298 // ----------------------------------------------------------------------------- |
|
299 // |
|
300 void CESMRNcsEditor::EditObserver( TInt aStart, TInt aExtent ) |
|
301 { |
|
302 FUNC_LOG; |
|
303 CEikRichTextEditor::EditObserver( aStart, aExtent ); |
|
304 |
|
305 HBufC* text = NULL; |
|
306 TRAPD( error, text = GetTextInHBufL()); |
|
307 if (error!= KErrNone) |
|
308 { |
|
309 CEikonEnv::Static()-> // codescanner::eikonenvstatic |
|
310 HandleError(error); |
|
311 } |
|
312 |
|
313 // if we are adding or removing multiple characters check |
|
314 // if we have default text |
|
315 if ( iDefaultText && ( aExtent > 1 || aExtent < -1 ) ) |
|
316 { |
|
317 if ( text ) |
|
318 { |
|
319 text->Des().TrimAll(); |
|
320 iHasDefaultText = |
|
321 ( ( *text ).Compare( *iDefaultText ) == 0 ) ? ETrue : EFalse; |
|
322 } |
|
323 else |
|
324 { |
|
325 // text reseted |
|
326 iHasDefaultText = EFalse; |
|
327 } |
|
328 } |
|
329 delete text; |
|
330 } |
|
331 |
|
332 // ----------------------------------------------------------------------------- |
|
333 // CESMRNcsEditor::UpdateColors |
|
334 // ----------------------------------------------------------------------------- |
|
335 // |
|
336 void CESMRNcsEditor::UpdateColors() |
|
337 { |
|
338 // Nothing to do. |
|
339 } |
|
340 |
|
341 // ----------------------------------------------------------------------------- |
|
342 // CESMRNcsEditor::UpdateGraphics |
|
343 // ----------------------------------------------------------------------------- |
|
344 // |
|
345 void CESMRNcsEditor::UpdateGraphics() |
|
346 { |
|
347 FUNC_LOG; |
|
348 TRAP_IGNORE( DoUpdateGraphicsL() ); |
|
349 } |
|
350 |
|
351 // ----------------------------------------------------------------------------- |
|
352 // CESMRNcsEditor::DoUpdateGraphicsL |
|
353 // ----------------------------------------------------------------------------- |
|
354 // |
|
355 void CESMRNcsEditor::DoUpdateGraphicsL() |
|
356 { |
|
357 // Nothing to do. |
|
358 } |
|
359 |
|
360 // ----------------------------------------------------------------------------- |
|
361 // CESMRNcsEditor::GetLabelText |
|
362 // ----------------------------------------------------------------------------- |
|
363 // |
|
364 const TDesC& CESMRNcsEditor::GetLabelText() const |
|
365 { |
|
366 FUNC_LOG; |
|
367 return KNullDesC; |
|
368 } |
|
369 |
|
370 // ----------------------------------------------------------------------------- |
|
371 // CESMRNcsEditor::GetNumChars |
|
372 // ----------------------------------------------------------------------------- |
|
373 // |
|
374 TInt CESMRNcsEditor::GetNumChars() const |
|
375 { |
|
376 FUNC_LOG; |
|
377 TInt cnt = iLayout->DocumentLength(); |
|
378 return cnt; |
|
379 } |
|
380 |
|
381 // ----------------------------------------------------------------------------- |
|
382 // CESMRNcsEditor::GetLineHeightL |
|
383 // ----------------------------------------------------------------------------- |
|
384 // |
|
385 TInt CESMRNcsEditor::GetLineHeightL() const |
|
386 { |
|
387 FUNC_LOG; |
|
388 TPoint pos; |
|
389 TRect rect; |
|
390 iLayout->DocPosToXyPosL(0, pos); |
|
391 iLayout->GetLineRect(pos.iY,rect); |
|
392 return rect.Height(); |
|
393 } |
|
394 |
|
395 // ----------------------------------------------------------------------------- |
|
396 // CESMRNcsEditor::DocumentLength |
|
397 // ----------------------------------------------------------------------------- |
|
398 // |
|
399 TInt CESMRNcsEditor::DocumentLength() const |
|
400 { |
|
401 FUNC_LOG; |
|
402 return iLayout->DocumentLength(); |
|
403 } |
|
404 |
|
405 // ----------------------------------------------------------------------------- |
|
406 // CESMRNcsEditor::PixelsAboveBand |
|
407 // ----------------------------------------------------------------------------- |
|
408 // |
|
409 TInt CESMRNcsEditor::PixelsAboveBand() const |
|
410 { |
|
411 FUNC_LOG; |
|
412 return iLayout->PixelsAboveBand(); |
|
413 } |
|
414 |
|
415 // ----------------------------------------------------------------------------- |
|
416 // CESMRNcsEditor::ChangeBandTopL |
|
417 // ----------------------------------------------------------------------------- |
|
418 // |
|
419 TInt CESMRNcsEditor::ChangeBandTopL(TInt aPixels) |
|
420 { |
|
421 FUNC_LOG; |
|
422 TInt px = aPixels; |
|
423 return iLayout->ChangeBandTopL(px); |
|
424 } |
|
425 |
|
426 // ----------------------------------------------------------------------------- |
|
427 // CESMRNcsEditor::SetFontL |
|
428 // ----------------------------------------------------------------------------- |
|
429 // |
|
430 void CESMRNcsEditor::SetFontL( const CFont* aFont, CESMRLayoutManager* aLayout ) |
|
431 { |
|
432 FUNC_LOG; |
|
433 const CFont* font = aFont; |
|
434 TFontSpec fontSpec = font->FontSpecInTwips(); |
|
435 |
|
436 CParaFormat *paraFormat = CParaFormat::NewLC(); |
|
437 TParaFormatMask paraFormatMask; |
|
438 paraFormat->iLineSpacingControl = CParaFormat::ELineSpacingExactlyInPixels; |
|
439 |
|
440 paraFormatMask.SetAttrib( EAttLineSpacing ); |
|
441 paraFormat->iHorizontalAlignment = CParaFormat::ELeftAlign; |
|
442 paraFormatMask.SetAttrib( EAttAlignment ); |
|
443 |
|
444 TCharFormat charFormat; |
|
445 TCharFormatMask formatMask; |
|
446 charFormat.iFontSpec = fontSpec; |
|
447 |
|
448 formatMask.SetAttrib( EAttFontTypeface ); |
|
449 formatMask.SetAttrib( EAttFontHeight ); |
|
450 formatMask.SetAttrib( EAttFontPosture ); |
|
451 formatMask.SetAttrib( EAttFontStrokeWeight ); |
|
452 |
|
453 charFormat.iFontPresentation.iTextColor = aLayout->NormalTextColor(); |
|
454 formatMask.SetAttrib( EAttColor ); |
|
455 |
|
456 CParaFormatLayer* paraFormatLayer = |
|
457 CParaFormatLayer::NewL( paraFormat, paraFormatMask ); |
|
458 CleanupStack::PushL( paraFormatLayer ); |
|
459 CCharFormatLayer* charFormatLayer = |
|
460 CCharFormatLayer::NewL( charFormat, formatMask ); |
|
461 |
|
462 SetParaFormatLayer( paraFormatLayer ); |
|
463 CleanupStack::Pop( paraFormatLayer ); |
|
464 CleanupStack::PopAndDestroy( paraFormat ); |
|
465 SetCharFormatLayer( charFormatLayer ); |
|
466 |
|
467 // This forces CEikEdwin::OnReformatL to notify observer |
|
468 // through HandleEdwinSizeEventL about changed size. |
|
469 // It is notified only if linecount changes. |
|
470 CEikEdwin::iNumberOfLines = 0; |
|
471 CEikEdwin::FormatTextL(); |
|
472 } |
|
473 |
|
474 //EOF |
|
475 |