|
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: Defines the Text Editor native side component |
|
15 * |
|
16 */ |
|
17 |
|
18 // EXTERNAL INCLUDES |
|
19 #include <MMIDCustomComponentContainer.h> |
|
20 #include <lcdui.h> |
|
21 #include <aknappui.h> |
|
22 #include <aknnavi.h> |
|
23 #include <j2me/jdebug.h> |
|
24 |
|
25 // INTERNAL INCLUDES |
|
26 #include "CMIDTextEditor.h" |
|
27 #include "CMIDTextEditorEdwin.h" |
|
28 #include "CMIDEditingStateIndicator.h" |
|
29 #include "CMIDEdwinUtils.h" |
|
30 #include "CMIDUtils.h" |
|
31 #include "CMIDFont.h" |
|
32 |
|
33 // Default background color. |
|
34 const TInt KDefColorBgRed = 0; |
|
35 const TInt KDefColorBgGreen = 0; |
|
36 const TInt KDefColorBgBlue = 0; |
|
37 const TInt KDefColorBgAlpha = 0; |
|
38 |
|
39 // Default foreground color. |
|
40 const TInt KDefColorFgRed = 0; |
|
41 const TInt KDefColorFgGreen = 0; |
|
42 const TInt KDefColorFgBlue = 0; |
|
43 const TInt KDefColorFgAlpha = 255; |
|
44 |
|
45 // Default highlight background color. |
|
46 const TInt KDefColorHlBgRed = 0; |
|
47 const TInt KDefColorHlBgGreen = 0; |
|
48 const TInt KDefColorHlBgBlue = 0; |
|
49 const TInt KDefColorHlBgAlpha = 255; |
|
50 |
|
51 // Default highlight foreground color. |
|
52 const TInt KDefColorHlFgRed = 255; |
|
53 const TInt KDefColorHlFgGreen = 255; |
|
54 const TInt KDefColorHlFgBlue = 255; |
|
55 const TInt KDefColorHlFgAlpha = 255; |
|
56 |
|
57 // Count of compound components in this custom component. |
|
58 const TInt KComponentCount = 2; |
|
59 |
|
60 // For all touch input modes to be disabled |
|
61 const TInt KAllTouchModesDisabled = 63; |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // CMIDTextEditor::NewL |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 CMIDTextEditor* CMIDTextEditor::NewL(const TCtorParams& aParams) |
|
68 { |
|
69 CMIDTextEditor* self = new(ELeave) CMIDTextEditor(); |
|
70 CleanupStack::PushL(self); |
|
71 self->ConstructL(aParams); |
|
72 CleanupStack::Pop(self); |
|
73 return self; |
|
74 } |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 // CMIDTextEditor::~CMIDTextEditor |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 CMIDTextEditor::~CMIDTextEditor() |
|
81 { |
|
82 DEBUG("CMIDTextEditor::~CMIDTextEditor +"); |
|
83 |
|
84 #ifdef RD_TACTILE_FEEDBACK |
|
85 if (iPenInputServerConnected) |
|
86 { |
|
87 // Close pen input server if the device is touch enabled and |
|
88 // connection was established |
|
89 iPenInputServerConnected = EFalse; |
|
90 iPenServer.Close(); |
|
91 } |
|
92 #endif // RD_TACTILE_FEEDBACK |
|
93 |
|
94 // Remove this component from the container if set. |
|
95 if (iComponentContainer) |
|
96 { |
|
97 iComponentContainer->UnregisterComponent(this); |
|
98 } |
|
99 |
|
100 // Remove association from the previous direct container. |
|
101 if (iDirectContainer) |
|
102 { |
|
103 iDirectContainer->MdcRemoveContent(this); |
|
104 } |
|
105 |
|
106 delete iTextEdwin; |
|
107 delete iEdwinUtils; |
|
108 delete iEditingStateIndicator; |
|
109 |
|
110 iUtils = NULL; |
|
111 |
|
112 DEBUG("CMIDTextEditor::~CMIDTextEditor -"); |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // CMIDTextEditor::CustomComponentControlCount |
|
117 // (other items are commented in the header file) |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 TInt CMIDTextEditor::CustomComponentControlCount() const |
|
121 { |
|
122 return KComponentCount; |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // CMIDTextEditor::CustomComponentControl |
|
127 // (other items are commented in the header file) |
|
128 // --------------------------------------------------------------------------- |
|
129 // |
|
130 CCoeControl* CMIDTextEditor::CustomComponentControl(TInt aIndex) |
|
131 { |
|
132 switch (aIndex) |
|
133 { |
|
134 case 0: |
|
135 { |
|
136 return iTextEdwin; |
|
137 } |
|
138 case 1: |
|
139 { |
|
140 return iEditingStateIndicator; |
|
141 } |
|
142 default: |
|
143 { |
|
144 __ASSERT_DEBUG(EFalse, User::Invariant()); |
|
145 } |
|
146 } |
|
147 |
|
148 return NULL; |
|
149 } |
|
150 |
|
151 // --------------------------------------------------------------------------- |
|
152 // CMIDTextEditor::CustomComponentContainerDisposing |
|
153 // (other items are commented in the header file) |
|
154 // --------------------------------------------------------------------------- |
|
155 // |
|
156 void CMIDTextEditor::CustomComponentContainerDisposing() |
|
157 { |
|
158 DEBUG("CMIDTextEditor::CustomComponentContainerDisposing +"); |
|
159 |
|
160 // Remove container association. |
|
161 iComponentContainer = NULL; |
|
162 |
|
163 // Uninitialize the text editor window. |
|
164 iTextEdwin->Uninitialize(); |
|
165 |
|
166 DEBUG("CMIDTextEditor::CustomComponentContainerDisposing -"); |
|
167 } |
|
168 |
|
169 // --------------------------------------------------------------------------- |
|
170 // CMIDTextEditor::SetObserver |
|
171 // (other items are commented in the header file) |
|
172 // --------------------------------------------------------------------------- |
|
173 // |
|
174 void CMIDTextEditor::SetObserver(MMIDTextEditorObserver* aObserver) |
|
175 { |
|
176 DEBUG("CMIDTextEditor::SetObserver +"); |
|
177 |
|
178 iObserver = aObserver; |
|
179 iTextEdwin->SetObserver(aObserver); |
|
180 |
|
181 DEBUG("CMIDTextEditor::SetObserver -"); |
|
182 } |
|
183 |
|
184 // --------------------------------------------------------------------------- |
|
185 // CMIDTextEditor::isTouchEnabled |
|
186 // (other items are commented in the header file) |
|
187 // --------------------------------------------------------------------------- |
|
188 // |
|
189 TBool CMIDTextEditor::IsTouchEnabled() |
|
190 { |
|
191 return iTouchEnabled; |
|
192 } |
|
193 |
|
194 // --------------------------------------------------------------------------- |
|
195 // CMIDTextEditor::setTouchEnabled |
|
196 // (other items are commented in the header file) |
|
197 // --------------------------------------------------------------------------- |
|
198 // |
|
199 void CMIDTextEditor::SetTouchEnabled(TBool aEnabled) |
|
200 { |
|
201 iTouchEnabled = aEnabled; |
|
202 } |
|
203 |
|
204 // --------------------------------------------------------------------------- |
|
205 // CMIDTextEditor::SetEditorSize |
|
206 // (other items are commented in the header file) |
|
207 // --------------------------------------------------------------------------- |
|
208 // |
|
209 void CMIDTextEditor::SetEditorSize(TInt aWidth, TInt aHeight) |
|
210 { |
|
211 DEBUG_INT2("CMIDTextEditor::SetEditorSize + aWidth=%d, aHeight=%d", |
|
212 aWidth, aHeight); |
|
213 |
|
214 // We need store non-scaled size of editor for possible resolution |
|
215 // and fullscreen mode changes. |
|
216 iNonScaledEditorSize = TSize(aWidth, aHeight); |
|
217 |
|
218 // If parent is in fullscreen mode then it tries scale input size. |
|
219 // Only setting otherwise. |
|
220 if (!iRowCountActive &&iComponentContainer && |
|
221 iComponentContainer->IsFullScreen()) |
|
222 { |
|
223 iTextEdwin->SetSize(iUtils->DoScaling(aWidth, CMIDUtils::EHorizontal), |
|
224 iUtils->DoScaling(aHeight, CMIDUtils::EVertical)); |
|
225 // Update the size of the indicator. Height does not need to be |
|
226 // calculated. |
|
227 iEditingStateIndicator->SetSize(iUtils->DoScaling( |
|
228 aWidth, CMIDUtils::EHorizontal), -1); |
|
229 } |
|
230 else |
|
231 { |
|
232 iTextEdwin->SetSize(aWidth, aHeight); |
|
233 // Update the size of the indicator. Height does not need to be |
|
234 // calculated. |
|
235 iEditingStateIndicator->SetSize(aWidth, -1); |
|
236 } |
|
237 |
|
238 // Updating of position of indicator is needed for change of its size. |
|
239 UpdateIndicatorPosition(); |
|
240 |
|
241 // Redraw the editor |
|
242 iTextEdwin->Redraw(); |
|
243 |
|
244 // Change the flag so now the font size changes will not |
|
245 // resize the editor any more. |
|
246 iRowCountActive = EFalse; |
|
247 |
|
248 DEBUG("CMIDTextEditor::SetEditorSize -"); |
|
249 } |
|
250 |
|
251 // --------------------------------------------------------------------------- |
|
252 // CMIDTextEditor::EditorSize |
|
253 // (other items are commented in the header file) |
|
254 // --------------------------------------------------------------------------- |
|
255 // |
|
256 TSize CMIDTextEditor::EditorSize() const |
|
257 { |
|
258 DEBUG("CMIDTextEditor::EditorSize"); |
|
259 |
|
260 TSize editorSize = iTextEdwin->Size(); |
|
261 |
|
262 // When scaling is on it has to descaled editor size. |
|
263 if (iComponentContainer && iComponentContainer->IsFullScreen()) |
|
264 { |
|
265 editorSize = iUtils->DoDescaling(editorSize); |
|
266 } |
|
267 |
|
268 return editorSize; |
|
269 } |
|
270 |
|
271 // --------------------------------------------------------------------------- |
|
272 // CMIDTextEditor::SetParentL |
|
273 // (other items are commented in the header file) |
|
274 // --------------------------------------------------------------------------- |
|
275 // |
|
276 void CMIDTextEditor::SetParentL( |
|
277 MMIDCustomComponentContainer* aComponentContainer) |
|
278 { |
|
279 DEBUG("CMIDTextEditor::SetParentL +"); |
|
280 |
|
281 // Remove association from the previous container. |
|
282 if (iComponentContainer) |
|
283 { |
|
284 DEBUG("CMIDTextEditor::SetParentL, unregistering old association"); |
|
285 |
|
286 // Remove focus |
|
287 SetFocusStateL(EFalse); |
|
288 // Remove editor from container |
|
289 iComponentContainer->UnregisterComponent(this); |
|
290 // Set editor window uninitialized |
|
291 iTextEdwin->Uninitialize(); |
|
292 iComponentContainer->Control().DrawDeferred(); |
|
293 iComponentContainer = NULL; |
|
294 } |
|
295 |
|
296 // Associate this component to the new container. |
|
297 if (aComponentContainer) |
|
298 { |
|
299 DEBUG("CMIDTextEditor::SetParentL, registering new"); |
|
300 |
|
301 CCoeControl& control = aComponentContainer->Control(); |
|
302 // Register container window for the editor. |
|
303 iTextEdwin->SetContainerWindowL(control); |
|
304 iTextEdwin->SetTopParent(&control); |
|
305 // Initialize the editor window. |
|
306 iTextEdwin->InitializeL(); |
|
307 // Set container window also for the indicator. |
|
308 iEditingStateIndicator->SetContainerWindowL(&control); |
|
309 |
|
310 // Register this custom component to the container. |
|
311 aComponentContainer->RegisterComponentL(this); |
|
312 } |
|
313 |
|
314 // Store container. NULL is ok. |
|
315 iComponentContainer = aComponentContainer; |
|
316 |
|
317 if (iComponentContainer && |
|
318 iComponentContainer->IsFullScreen()) |
|
319 { |
|
320 if (!iRowCountActive) |
|
321 { |
|
322 // When it is fullscreen we need call SetEditorSize to prevent wrong |
|
323 // scaling of TextEditor. |
|
324 // (only for TextEditor not created with row counter) |
|
325 SetEditorSize(iTextEdwin->Size().iWidth, iTextEdwin->Size().iHeight); |
|
326 } |
|
327 SetFontL(iNonScaledFont); |
|
328 } |
|
329 |
|
330 DEBUG("CMIDTextEditor::SetParentL -"); |
|
331 } |
|
332 |
|
333 // --------------------------------------------------------------------------- |
|
334 // CMIDTextEditor::SetDirectContainerL |
|
335 // (other items are commented in the header file) |
|
336 // --------------------------------------------------------------------------- |
|
337 // |
|
338 void CMIDTextEditor::SetDirectContainerL(MDirectContainer* aDirectContainer) |
|
339 { |
|
340 // Remove association from the previous direct container. |
|
341 if (iDirectContainer) |
|
342 { |
|
343 iDirectContainer->MdcRemoveContent(this); |
|
344 } |
|
345 |
|
346 // Associate this component to the new direct container. Note that this |
|
347 // needs to be done in order to disable the direct screen access of |
|
348 // the MID parent component. This way it does not draw on top of |
|
349 // the text editor when repaint etc. methods are called. |
|
350 if (aDirectContainer) |
|
351 { |
|
352 aDirectContainer->MdcAddContent(this); |
|
353 } |
|
354 |
|
355 // Store new container. Or NULL if passed. |
|
356 iDirectContainer = aDirectContainer; |
|
357 } |
|
358 |
|
359 // --------------------------------------------------------------------------- |
|
360 // CMIDTextEditor::SetElevationL |
|
361 // (other items are commented in the header file) |
|
362 // --------------------------------------------------------------------------- |
|
363 // |
|
364 void CMIDTextEditor::SetElevationL(TInt aElevation) |
|
365 { |
|
366 DEBUG_INT("CMIDTextEditor::SetElevationL +, aElevation=%d", aElevation); |
|
367 |
|
368 // Parent must have been set. |
|
369 __ASSERT_DEBUG(iComponentContainer, User::Invariant()); |
|
370 |
|
371 // The elevation is corrected in custom component container. |
|
372 iComponentContainer->SetComponentIndexL(this, aElevation); |
|
373 |
|
374 DEBUG("CMIDTextEditor::SetElevationL -"); |
|
375 } |
|
376 |
|
377 // --------------------------------------------------------------------------- |
|
378 // CMIDTextEditor::Elevation |
|
379 // (other items are commented in the header file) |
|
380 // --------------------------------------------------------------------------- |
|
381 // |
|
382 TInt CMIDTextEditor::Elevation() |
|
383 { |
|
384 DEBUG("CMIDTextEditor::Elevation +"); |
|
385 |
|
386 // Parent must have been set. |
|
387 __ASSERT_DEBUG(iComponentContainer, User::Invariant()); |
|
388 |
|
389 TInt index = iComponentContainer->ComponentIndex(this); |
|
390 |
|
391 DEBUG_INT("CMIDTextEditor::Elevation - index=%d", index); |
|
392 |
|
393 return index; |
|
394 } |
|
395 |
|
396 void CMIDTextEditor::TraverseL(const TKeyEvent& aEvent) |
|
397 { |
|
398 if (iTextEdwin->Traverse(aEvent)) |
|
399 { |
|
400 if (iObserver) |
|
401 { |
|
402 if ((aEvent.iCode == EKeyUpArrow) || |
|
403 (aEvent.iScanCode == EStdKeyUpArrow)) |
|
404 { |
|
405 iObserver->NotifyInputAction( |
|
406 MMIDTextEditorObserver::EActionTraversePrevious); |
|
407 } |
|
408 else if ((aEvent.iCode == EKeyDownArrow) || |
|
409 (aEvent.iScanCode == EStdKeyDownArrow)) |
|
410 { |
|
411 iObserver->NotifyInputAction( |
|
412 MMIDTextEditorObserver::EActionTraverseNext); |
|
413 } |
|
414 } |
|
415 } |
|
416 else |
|
417 { |
|
418 iTextEdwin->OfferKeyEventL(aEvent, EEventKeyDown); |
|
419 } |
|
420 } |
|
421 |
|
422 // --------------------------------------------------------------------------- |
|
423 // CMIDTextEditor::Show |
|
424 // (other items are commented in the header file) |
|
425 // --------------------------------------------------------------------------- |
|
426 // |
|
427 void CMIDTextEditor::SetVisibleL(TBool aVisible) |
|
428 { |
|
429 DEBUG_INT("CMIDTextEditor::SetVisibleL +, aVisible=%d", aVisible); |
|
430 |
|
431 // SetParentL must be called before Show. |
|
432 __ASSERT_DEBUG(iComponentContainer, User::Invariant()); |
|
433 |
|
434 if (aVisible && !iTextEdwin->IsVisible()) |
|
435 { |
|
436 DEBUG("CMIDTextEditor::SetVisibleL, setting editor visible"); |
|
437 |
|
438 // Show the text editor when it is hidden. |
|
439 iTextEdwin->MakeVisible(aVisible); |
|
440 |
|
441 // If setting visible already focused editor |
|
442 if (iFocusState) |
|
443 { |
|
444 iFocusState = EFalse; |
|
445 SetFocusStateL(ETrue); |
|
446 // Cursor is not shown automatically if the editor has focus. |
|
447 // So, set cursor visible. |
|
448 iTextEdwin->SetCursorVisible(ETrue); |
|
449 |
|
450 } |
|
451 else |
|
452 { |
|
453 // MakeVisible automatically selects the editor's content |
|
454 // Remove the selection at this point. The selection can be |
|
455 // set again with the API. |
|
456 SetCursorPositionL(iTextEdwin->CursorPos()); |
|
457 } |
|
458 } |
|
459 else if (!aVisible && iTextEdwin->IsVisible()) |
|
460 { |
|
461 DEBUG("CMIDTextEditor::SetVisibleL, setting editor hidden"); |
|
462 |
|
463 if (iFocusState) |
|
464 { |
|
465 // Remove the focus from the editor also. |
|
466 SetFocusStateL(EFalse); |
|
467 // Keep focus state for visibility changes |
|
468 iFocusState = ETrue; |
|
469 } |
|
470 // Hide the text editor when it is visible. |
|
471 iTextEdwin->MakeVisible(EFalse); |
|
472 |
|
473 // Always disable indicator if the editor is hidden. |
|
474 iEditingStateIndicator->MakeVisible(EFalse); |
|
475 } |
|
476 |
|
477 iTextEdwin->Redraw(); |
|
478 |
|
479 DEBUG("CMIDTextEditor::SetVisibleL -"); |
|
480 } |
|
481 |
|
482 // --------------------------------------------------------------------------- |
|
483 // CMIDTextEditor::IsVisible |
|
484 // (other items are commented in the header file) |
|
485 // --------------------------------------------------------------------------- |
|
486 // |
|
487 TBool CMIDTextEditor::IsVisible() const |
|
488 { |
|
489 return iTextEdwin->IsVisible(); |
|
490 } |
|
491 |
|
492 // --------------------------------------------------------------------------- |
|
493 // CMIDTextEditor::SetPosition |
|
494 // (other items are commented in the header file) |
|
495 // --------------------------------------------------------------------------- |
|
496 // |
|
497 void CMIDTextEditor::SetPosition(TInt aX, TInt aY) |
|
498 { |
|
499 DEBUG_INT2("CMIDTextEditor::SetPosition +, aX=%d, aY=%d", aX, aY); |
|
500 |
|
501 // We need store non-scaled position for possible resolution |
|
502 // and fullscreen mode changes. |
|
503 iNonScaledPosition = TPoint(aX, aY); |
|
504 |
|
505 // If parent is in fullscreen mode then it tries scale input position. |
|
506 // Only setting otherwise. |
|
507 if (iComponentContainer && iComponentContainer->IsFullScreen()) |
|
508 { |
|
509 DEBUG_INT2("CMIDTextEditor::SetPosition DoScaling, aX=%d, aY=%d", |
|
510 iUtils->DoScaling(aX, CMIDUtils::EHorizontal), |
|
511 iUtils->DoScaling(aY, CMIDUtils::EVertical)); |
|
512 iTextEdwin->SetPosition(iUtils->DoScalingAndPositioning(TPoint(aX, aY))); |
|
513 } |
|
514 else |
|
515 { |
|
516 iTextEdwin->SetPosition(TPoint(aX, aY)); |
|
517 } |
|
518 |
|
519 // There is needed redraw. |
|
520 iTextEdwin->Redraw(); |
|
521 |
|
522 // Update indicator's position if needed. |
|
523 UpdateIndicatorPosition(); |
|
524 |
|
525 DEBUG("CMIDTextEditor::SetPosition -"); |
|
526 } |
|
527 |
|
528 // --------------------------------------------------------------------------- |
|
529 // CMIDTextEditor::SetCaretXY |
|
530 // (other items are commented in the header file) |
|
531 // --------------------------------------------------------------------------- |
|
532 // |
|
533 void CMIDTextEditor::SetCaretXYL(TInt aX, TInt aY) |
|
534 { |
|
535 DEBUG_INT2("CMIDTextEditor::SetCaretXY +, aX=%d, aY=%d", aX, aY); |
|
536 |
|
537 // Requested point should be already recalculated to be relative |
|
538 // to editor position on canvas. |
|
539 TPoint pos(aX, aY); |
|
540 // If position will be found in formatted text, posInfo will be filled |
|
541 // with desired informations. |
|
542 TTmPosInfo2 posInfo; |
|
543 |
|
544 if (iTextEdwin->TextLayout()->FindXyPos(pos, posInfo)) |
|
545 { |
|
546 // Position was found. Try to set cursor to found position. |
|
547 iTextEdwin->SetCursorPosL(posInfo.iDocPos.iPos, EFalse); |
|
548 } |
|
549 |
|
550 DEBUG("CMIDTextEditor::SetCaretXY -"); |
|
551 } |
|
552 |
|
553 // --------------------------------------------------------------------------- |
|
554 // CMIDTextEditor::SetFocusStateL |
|
555 // (other items are commented in the header file) |
|
556 // --------------------------------------------------------------------------- |
|
557 // |
|
558 void CMIDTextEditor::SetFocusStateL(TBool aFocusState) |
|
559 { |
|
560 DEBUG_INT("CMIDTextEditor::SetFocusStateL +, aFocusState=%d", |
|
561 aFocusState); |
|
562 |
|
563 if ((aFocusState) && !(iFocusState)) |
|
564 { |
|
565 // Set focus if the text editor is not focused |
|
566 iFocusState = ETrue; |
|
567 // Call SetFocus on edwin |
|
568 iTextEdwin->SetFocus(ETrue); |
|
569 // Send the information about new focused component to parent |
|
570 iComponentContainer->SetFocusedComponent(this); |
|
571 |
|
572 // Set focus automatically selects the editor's content |
|
573 // Remove the selection at this point. The selection can be |
|
574 // set again with the API. |
|
575 SetCursorPositionL(iTextEdwin->CursorPos()); |
|
576 |
|
577 // If the editor is not visible. do not show the cursor either. |
|
578 if (!iTextEdwin->IsVisible()) |
|
579 { |
|
580 DEBUG("CMIDTextEditor::SetFocusStateL, hiding cursor"); |
|
581 |
|
582 iTextEdwin->SetCursorVisible(EFalse); |
|
583 } |
|
584 else if (iEditingStateIndicator->EnabledState() == |
|
585 CMIDEditingStateIndicator::EIndicatorStateRelative) |
|
586 { |
|
587 // Enable the custom indicators as in Avkon if not controlled |
|
588 // by the client application |
|
589 iEditingStateIndicator->MakeVisible(ETrue); |
|
590 } |
|
591 } |
|
592 else if (!(aFocusState) && (iFocusState)) |
|
593 { |
|
594 // Remove focus if the text editor is focused. |
|
595 iFocusState = EFalse; |
|
596 |
|
597 // Call SetFocus on edwin |
|
598 iTextEdwin->SetFocus(EFalse); |
|
599 |
|
600 if (iComponentContainer) |
|
601 { |
|
602 // Send the information about new focused component to parent |
|
603 iComponentContainer->SetFocusedComponent(NULL); |
|
604 } |
|
605 |
|
606 // Disable the custom indicators as in Avkon if not controlled by |
|
607 // the client application. |
|
608 if (iEditingStateIndicator->EnabledState() == |
|
609 CMIDEditingStateIndicator::EIndicatorStateRelative) |
|
610 { |
|
611 iEditingStateIndicator->MakeVisible(EFalse); |
|
612 } |
|
613 } |
|
614 |
|
615 iTextEdwin->Redraw(); |
|
616 |
|
617 DEBUG("CMIDTextEditor::SetFocusStateL -"); |
|
618 } |
|
619 |
|
620 TBool CMIDTextEditor::GetFocusState() |
|
621 { |
|
622 return iFocusState; |
|
623 } |
|
624 |
|
625 // --------------------------------------------------------------------------- |
|
626 // CMIDTextEditor::ContentL |
|
627 // (other items are commented in the header file) |
|
628 // --------------------------------------------------------------------------- |
|
629 // |
|
630 HBufC* CMIDTextEditor::ContentL() |
|
631 { |
|
632 DEBUG("CMIDTextEditor::ContentL +"); |
|
633 |
|
634 HBufC* content = iTextEdwin->GetTextInHBufL(); |
|
635 |
|
636 if (!content) |
|
637 { |
|
638 // Return an empty content if the current content of the editor |
|
639 // is NULL. |
|
640 content = HBufC::NewL(0); |
|
641 |
|
642 DEBUG("CMIDTextEditor::ContentL -, returning empty descriptor"); |
|
643 |
|
644 return content; |
|
645 } |
|
646 |
|
647 TPtr ptr = content->Des(); |
|
648 |
|
649 // Otherwise, convert content to Java specific format. |
|
650 // First, if the constraints indicates that this is a decimal field |
|
651 // convert the string from localized decimal. |
|
652 if (iTextEdwin->IsConstraintSet(MMIDTextField::EDecimal)) |
|
653 { |
|
654 DEBUG("CMIDTextEditor::ContentL, convert from localized decimal"); |
|
655 |
|
656 iEdwinUtils->ConvertFromLocalizedDecimal(content); |
|
657 } |
|
658 |
|
659 // Perform number conversion if it is needed. |
|
660 if (iEdwinUtils->IsNumberConversionNeeded(iConstraints)) |
|
661 { |
|
662 DEBUG( |
|
663 "CMIDTextEditor::ContentL, language specific number conversion"); |
|
664 |
|
665 AknTextUtils::ConvertDigitsTo(ptr, EDigitTypeWestern); |
|
666 } |
|
667 |
|
668 // Map Java-specific characters in the buffer. |
|
669 CMIDUtils::MapETextToJavaChars(content); |
|
670 |
|
671 DEBUG_STR("CMIDTextEditor::ContentL - content=%S", *content); |
|
672 |
|
673 return content; |
|
674 } |
|
675 |
|
676 // --------------------------------------------------------------------------- |
|
677 // CMIDTextEditor::SetContentL |
|
678 // (other items are commented in the header file) |
|
679 // --------------------------------------------------------------------------- |
|
680 // |
|
681 void CMIDTextEditor::SetContentL(const TDesC& aContent) |
|
682 { |
|
683 DEBUG("CMIDTextEditor::SetContentL +"); |
|
684 |
|
685 // Leave if text is not valid for the current set of constraints. |
|
686 // Note that if the constraints are set to phone number invalid |
|
687 // characters are simply removed. See CMIDEdwin. |
|
688 if (!(iTextEdwin->IsConstraintSet(MMIDTextField::EPhoneNumber)) && |
|
689 !(iEdwinUtils->ConstraintsValidForText( |
|
690 aContent, |
|
691 iConstraints, ETrue))) |
|
692 { |
|
693 User::Leave(KErrArgument); |
|
694 } |
|
695 |
|
696 // Get converted content (localized, number conversion and phone number |
|
697 // specific). |
|
698 HBufC* buf = ConvertedContentLC(aContent); |
|
699 |
|
700 // Set text to the editor window. |
|
701 iTextEdwin->SetTextL(buf); |
|
702 |
|
703 // Text buffer is not needed anymore, pop and destroy it. |
|
704 CleanupStack::PopAndDestroy(buf); |
|
705 |
|
706 // Text has been changed so inform the editor window that |
|
707 // it needs to redraw itself again. |
|
708 iTextEdwin->HandleTextChangedL(); |
|
709 |
|
710 // Cursor state is not automatically updated. Do it here. False indicates |
|
711 // that the text is not selected from the point where the cursor is moved. |
|
712 SetCursorPositionL(ContentLength()); |
|
713 |
|
714 DEBUG("CMIDTextEditor::SetContentL -"); |
|
715 } |
|
716 |
|
717 // --------------------------------------------------------------------------- |
|
718 // CMIDTextEditor::InsertContentL |
|
719 // (other items are commented in the header file) |
|
720 // --------------------------------------------------------------------------- |
|
721 // |
|
722 void CMIDTextEditor::InsertContentL(const TDesC& aContent, TInt aPosition) |
|
723 { |
|
724 DEBUG_STR("CMIDTextEditor::InsertContentL +, aContent=%S", aContent); |
|
725 DEBUG_INT("CMIDTextEditor::InsertContentL, aPosition=%d", aPosition); |
|
726 |
|
727 // Validate the new content before making any conversions or |
|
728 // modifications. |
|
729 // Leave if text is not valid for the current set of constraints. |
|
730 // Note that if the constraints are set to phone number invalid |
|
731 // characters are simply removed. See CMIDEdwin. |
|
732 if (!(iTextEdwin->IsConstraintSet(MMIDTextField::EPhoneNumber)) && |
|
733 !(iEdwinUtils->ConstraintsValidForText( |
|
734 aContent, |
|
735 iConstraints, ETrue))) |
|
736 { |
|
737 User::Leave(KErrArgument); |
|
738 } |
|
739 |
|
740 TInt contentLength = ContentLength(); |
|
741 |
|
742 // Get cursor position internally because CursorPosition() checks |
|
743 // wether the editor window is initialized or not. |
|
744 TInt cursorPosition = CursorPosition(); |
|
745 |
|
746 // Get language converted content. |
|
747 HBufC* originalContent = ContentL(); |
|
748 CleanupStack::PushL(originalContent); |
|
749 |
|
750 // If position is negative, convert it to zero. |
|
751 if (aPosition < 0) |
|
752 { |
|
753 aPosition = 0; |
|
754 } |
|
755 // Or if the position is greater than the length. |
|
756 else if (aPosition > contentLength) |
|
757 { |
|
758 aPosition = contentLength; |
|
759 } |
|
760 |
|
761 DEBUG_INT("CMIDTextEditor::InsertContentL, aPosition=%d", |
|
762 aPosition); |
|
763 DEBUG_INT("CMIDTextEditor::InsertContentL, cursorPosition=%d", |
|
764 cursorPosition); |
|
765 |
|
766 // Get converted content (localized, number conversion and phone number |
|
767 // specific). |
|
768 HBufC* content = ConvertedContentLC(aContent); |
|
769 |
|
770 // Leave with KErrArgument if the content is not valid. |
|
771 if (!iEdwinUtils->ConstraintsValidForInsertedTextL( |
|
772 *originalContent, *content, aPosition, iConstraints, ETrue)) |
|
773 { |
|
774 DEBUG("CMIDTextEditor::InsertContentL -, text not valid"); |
|
775 |
|
776 User::Leave(KErrArgument); |
|
777 } |
|
778 |
|
779 // Text can be now inserted. |
|
780 iTextEdwin->Text()->InsertL(aPosition, content->Des()); |
|
781 |
|
782 // Notify editor that its content has been changed. |
|
783 iTextEdwin->HandleTextChangedL(); |
|
784 |
|
785 // Update cursor position based on the inserted content. |
|
786 if (cursorPosition >= aPosition) |
|
787 { |
|
788 DEBUG("CMIDTextEditor::InsertContentL, adjusting cursor"); |
|
789 |
|
790 // Cursor is set to the end of inserted text. |
|
791 cursorPosition += content->Length(); |
|
792 } |
|
793 |
|
794 // else, cursor is on the left side of the inserted text. |
|
795 DEBUG_INT("CMIDTextEditor::InsertContentL, cursorPosition=%d", |
|
796 cursorPosition); |
|
797 |
|
798 SetCursorPositionL(cursorPosition); |
|
799 |
|
800 // New and original contents are not needed anymore. |
|
801 CleanupStack::PopAndDestroy(2, originalContent); |
|
802 |
|
803 DEBUG("CMIDTextEditor::InsertContentL -"); |
|
804 } |
|
805 |
|
806 // --------------------------------------------------------------------------- |
|
807 // CMIDTextEditor::DeleteContentL |
|
808 // (other items are commented in the header file) |
|
809 // --------------------------------------------------------------------------- |
|
810 // |
|
811 void CMIDTextEditor::DeleteContentL(TInt aOffset, TInt aLength) |
|
812 { |
|
813 DEBUG_INT2("CMIDTextEditor::DeleteContentL +, aOffset=%d, aLength=%d", |
|
814 aOffset, aLength); |
|
815 |
|
816 TInt originalSize = ContentLength(); |
|
817 |
|
818 // Get cursor position internally because CursorPosition() checks |
|
819 // wether the editor window is initialized or not. |
|
820 TInt cursorPosition = CursorPosition(); |
|
821 |
|
822 // Store current content to local heap descriptor. The content |
|
823 // needs to be verified before actual deletion. Note that if |
|
824 // the constraints are not valid for the new text, the state of the |
|
825 // editor must not be changed by this method!!! |
|
826 HBufC* originalContent = HBufC::NewLC(originalSize); |
|
827 |
|
828 // Note that FEP transaction is also in this text content. |
|
829 // Note that this function cannot be totally leave safe because |
|
830 // the cursor must be replaced acording to the deletion. |
|
831 TPtr contentPtr = originalContent->Des(); |
|
832 iTextEdwin->GetText(contentPtr); |
|
833 |
|
834 DEBUG_STR("CMIDTextEditor::DeleteContentL - old content=%S", |
|
835 contentPtr); |
|
836 |
|
837 // Perform deletion at this point. Editor is not changed yet. |
|
838 contentPtr.Delete(aOffset, aLength); |
|
839 |
|
840 DEBUG_STR("CMIDTextEditor::DeleteContentL - new content=%S", |
|
841 contentPtr); |
|
842 |
|
843 // Leave if the content is not valid for the current constraints. |
|
844 if (!iEdwinUtils->ConstraintsValidForText( |
|
845 contentPtr, iConstraints, ETrue)) |
|
846 { |
|
847 DEBUG("CMIDTextEditor::DeleteContentL -, text not valid"); |
|
848 |
|
849 User::Leave(KErrArgument); |
|
850 } |
|
851 |
|
852 // Constraints are valid. Perform with the modified text. Setting the text |
|
853 // cancels to ongoing FEP transaction. Selection is also canceled. |
|
854 iTextEdwin->SetTextL(originalContent); |
|
855 CleanupStack::PopAndDestroy(originalContent); |
|
856 |
|
857 // Notify editor window that the text has changed. |
|
858 iTextEdwin->HandleTextChangedL(); |
|
859 |
|
860 // Modify cursor position. FEP transaction cannot be restored anymore. |
|
861 // Cursor was in the middle of the deleted range. |
|
862 if ((cursorPosition > aOffset) && |
|
863 (cursorPosition < aOffset + aLength)) |
|
864 { |
|
865 cursorPosition = aOffset; |
|
866 } |
|
867 // Cursor was on the right side of the deleted range. |
|
868 else if (cursorPosition >= aOffset + aLength) |
|
869 { |
|
870 cursorPosition = |
|
871 (cursorPosition - aLength < 0 ? 0 : cursorPosition - aLength); |
|
872 } |
|
873 |
|
874 // else, cursor was on the left side and does not need modification. |
|
875 SetCursorPositionL(cursorPosition); |
|
876 |
|
877 DEBUG("CMIDTextEditor::DeleteContentL -"); |
|
878 } |
|
879 |
|
880 // --------------------------------------------------------------------------- |
|
881 // CMIDTextEditor::ContentLength |
|
882 // (other items are commented in the header file) |
|
883 // --------------------------------------------------------------------------- |
|
884 // |
|
885 TInt CMIDTextEditor::ContentLength() const |
|
886 { |
|
887 DEBUG_INT("CMIDTextEditor::ContentLength, length=%d", |
|
888 iTextEdwin->TextLength()); |
|
889 |
|
890 return iTextEdwin->TextLength(); |
|
891 } |
|
892 |
|
893 // --------------------------------------------------------------------------- |
|
894 // CMIDTextEditor::ContentHeight |
|
895 // (other items are commented in the header file) |
|
896 // --------------------------------------------------------------------------- |
|
897 // |
|
898 TInt CMIDTextEditor::ContentHeight() const |
|
899 { |
|
900 DEBUG("CMIDTextEditor::ContentHeight +"); |
|
901 |
|
902 // calculation of content height |
|
903 TInt lineHeight = iTextEdwin->LineHeight(); |
|
904 TInt rowCount = iTextEdwin->NumberOfLines(); |
|
905 TInt height = lineHeight * rowCount; |
|
906 |
|
907 // If parent is in fullscreen mode, |
|
908 // then content height has to be descaled. |
|
909 if (iComponentContainer && iComponentContainer->IsFullScreen()) |
|
910 { |
|
911 height = iUtils->DoDescaling(height, CMIDUtils::EHorizontal); |
|
912 } |
|
913 |
|
914 DEBUG_INT("CMIDTextEditor::ContentHeight - , contentHeight=%d", |
|
915 height); |
|
916 |
|
917 return height; |
|
918 } |
|
919 |
|
920 // --------------------------------------------------------------------------- |
|
921 // CMIDTextEditor::LineMarginHeight |
|
922 // (other items are commented in the header file) |
|
923 // --------------------------------------------------------------------------- |
|
924 // |
|
925 TInt CMIDTextEditor::LineMarginHeight() const |
|
926 { |
|
927 DEBUG("CMIDTextEditor::LineMarginHeight +"); |
|
928 |
|
929 // Currently line margin is equal to zero since content height is |
|
930 // line height * row count which gives the same height as the editor's |
|
931 // height is. There is no method for getting the line margin height |
|
932 // so at the moment it is considered to be zero. |
|
933 |
|
934 return 0; |
|
935 } |
|
936 |
|
937 // --------------------------------------------------------------------------- |
|
938 // CMIDTextEditor::VisibleContentPosition |
|
939 // (other items are commented in the header file) |
|
940 // --------------------------------------------------------------------------- |
|
941 // |
|
942 TInt CMIDTextEditor::VisibleContentPosition() const |
|
943 { |
|
944 return iTextEdwin->VisibleContentPosition(); |
|
945 } |
|
946 |
|
947 // --------------------------------------------------------------------------- |
|
948 // CMIDTextEditor::SetSelectionL |
|
949 // (other items are commented in the header file) |
|
950 // --------------------------------------------------------------------------- |
|
951 // |
|
952 void CMIDTextEditor::SetSelectionL(TInt aIndex, TInt aLength) |
|
953 { |
|
954 DEBUG_INT2("CMIDTextEditor::SetSelectionL +, aIndex=%d, aLength=%d", |
|
955 aIndex, aLength); |
|
956 |
|
957 TInt endIndex = aIndex + aLength; |
|
958 |
|
959 __ASSERT_DEBUG((aIndex >= 0 && aIndex <= ContentLength()) && |
|
960 (aLength >= 0 && endIndex <= ContentLength()), |
|
961 User::Invariant()); |
|
962 |
|
963 // Set cursor to the beginning of the new selection and set the new |
|
964 // position using the end index and selection. CEikEdwin::SetSelectionL |
|
965 // always sets the cursor to the beginning of the selection so it cannot |
|
966 // be used. |
|
967 iTextEdwin->SetCursorPosL(aIndex, EFalse); |
|
968 iTextEdwin->SetCursorPosL(endIndex, ETrue); |
|
969 |
|
970 DEBUG("CMIDTextEditor::SetSelectionL -"); |
|
971 } |
|
972 |
|
973 // --------------------------------------------------------------------------- |
|
974 // CMIDTextEditor::SelectionL |
|
975 // (other items are commented in the header file) |
|
976 // --------------------------------------------------------------------------- |
|
977 // |
|
978 HBufC* CMIDTextEditor::SelectionL() |
|
979 { |
|
980 DEBUG("CMIDTextEditor::SelectionL +"); |
|
981 |
|
982 // Get the whole content from the editor. Content is already correctly |
|
983 // converted at this point when using ContentL() method. |
|
984 HBufC* content = ContentL(); |
|
985 CleanupStack::PushL(content); |
|
986 |
|
987 // Get current selection and remove all other contents from the |
|
988 // descriptor. |
|
989 TCursorSelection selection = iTextEdwin->Selection(); |
|
990 TInt lowerPos = selection.LowerPos(); |
|
991 TInt length = selection.Length(); |
|
992 |
|
993 DEBUG_INT2("CMIDTextEditor::SelectionL, lower pos=%d, length=%d", |
|
994 lowerPos, length); |
|
995 |
|
996 HBufC* ret = HBufC::NewL(length); |
|
997 TPtr retPtr = ret->Des(); |
|
998 |
|
999 // Get the selected text from the editor and append it to the new |
|
1000 // descriptor. |
|
1001 retPtr.Append(content->Mid(lowerPos, length)); |
|
1002 |
|
1003 // Content is not needed anymore. |
|
1004 CleanupStack::PopAndDestroy(content); |
|
1005 |
|
1006 DEBUG("CMIDTextEditor::SelectionL -"); |
|
1007 |
|
1008 return ret; |
|
1009 } |
|
1010 |
|
1011 // --------------------------------------------------------------------------- |
|
1012 // CMIDTextEditor::SetConstraintsL |
|
1013 // (other items are commented in the header file) |
|
1014 // --------------------------------------------------------------------------- |
|
1015 // |
|
1016 void CMIDTextEditor::SetConstraintsL(TUint aConstraints) |
|
1017 { |
|
1018 DEBUG_INT("CMIDTextEditor::SetConstraintsL +, aConstraints=%d", |
|
1019 aConstraints); |
|
1020 |
|
1021 HBufC* content = ContentL(); |
|
1022 CleanupStack::PushL(content); |
|
1023 |
|
1024 TBool currentTextValid = |
|
1025 iEdwinUtils->ConstraintsValidForText( |
|
1026 content->Des(), aConstraints, ETrue); |
|
1027 |
|
1028 // Set the content to empty if the new constraints are not valid |
|
1029 // for the current text. |
|
1030 if (!currentTextValid) |
|
1031 { |
|
1032 iTextEdwin->SetTextL(&KNullDesC); |
|
1033 iTextEdwin->SetCursorPosL(0, EFalse); |
|
1034 iTextEdwin->HandleTextChangedL(); |
|
1035 } |
|
1036 |
|
1037 // Set constraints to the text editor window. |
|
1038 iTextEdwin->SetConstraintsL(aConstraints); |
|
1039 // Store constraints of this text editor. |
|
1040 iConstraints = aConstraints; |
|
1041 |
|
1042 if (currentTextValid) |
|
1043 { |
|
1044 // Convert breaks if needed if constraints that do not allow line |
|
1045 // breaks. Note that numeric, decimal and phonenumber do not allow |
|
1046 // line breaks and are checked before this so no need to check here |
|
1047 // again. |
|
1048 if (iConstraints & MMIDTextField::EPassword || |
|
1049 iTextEdwin->IsConstraintSet(MMIDTextField::EUrl) || |
|
1050 iTextEdwin->IsConstraintSet(MMIDTextField::EMailAddr)) |
|
1051 { |
|
1052 TPtr ptr = content->Des(); |
|
1053 iEdwinUtils->CropToSingleLine(ptr); |
|
1054 } |
|
1055 |
|
1056 // Set the content to the editor as it was cleared during |
|
1057 // SetConstraintsL method. |
|
1058 SetContentL(*content); |
|
1059 } |
|
1060 |
|
1061 CleanupStack::PopAndDestroy(content); |
|
1062 |
|
1063 DEBUG("CMIDTextEditor::SetConstraintsL -"); |
|
1064 } |
|
1065 |
|
1066 // --------------------------------------------------------------------------- |
|
1067 // CMIDTextEditor::SetMultilineL |
|
1068 // (other items are commented in the header file) |
|
1069 // --------------------------------------------------------------------------- |
|
1070 // |
|
1071 void CMIDTextEditor::SetMultilineL(TBool aMultiline) |
|
1072 { |
|
1073 DEBUG_INT("CMIDTextEditor::SetMultilineL +, aMultiline=%d", aMultiline); |
|
1074 |
|
1075 // Do nothing if the editor state is equal to the requested state or |
|
1076 // if the constraint modifier PASSWORD is set. Passwords are single |
|
1077 // line editors due to CMIDEdwinUtils::CPasswordText implementation. |
|
1078 if (aMultiline == iTextEdwin->IsWrapEnabled() || |
|
1079 iConstraints & MMIDTextField::EPassword) |
|
1080 { |
|
1081 DEBUG("CMIDTextEditor::SetMultilineL -, ignoring request"); |
|
1082 |
|
1083 return; |
|
1084 } |
|
1085 |
|
1086 // Content needs to be cropped to single line. |
|
1087 if (!aMultiline) |
|
1088 { |
|
1089 HBufC* content = ContentL(); |
|
1090 CleanupStack::PushL(content); |
|
1091 |
|
1092 // Crop line and paragraph breaks. |
|
1093 TPtr ptr = content->Des(); |
|
1094 iEdwinUtils->CropToSingleLine(ptr); |
|
1095 |
|
1096 // Set the cropped content to the editor. |
|
1097 SetContentL(*content); |
|
1098 CleanupStack::PopAndDestroy(content); |
|
1099 } |
|
1100 |
|
1101 // Apply wrap on. |
|
1102 iTextEdwin->SetWordWrapL(aMultiline); |
|
1103 // Text has been changed so inform the editor window that |
|
1104 // it needs to redraw itself again. |
|
1105 iTextEdwin->HandleTextChangedL(); |
|
1106 |
|
1107 DEBUG("CMIDTextEditor::SetMultilineL -"); |
|
1108 } |
|
1109 |
|
1110 // --------------------------------------------------------------------------- |
|
1111 // CMIDTextEditor::IsMultiline |
|
1112 // (other items are commented in the header file) |
|
1113 // --------------------------------------------------------------------------- |
|
1114 // |
|
1115 TBool CMIDTextEditor::IsMultiline() |
|
1116 { |
|
1117 DEBUG("CMIDTextEditor::IsMultiline +"); |
|
1118 TBool multiline = iTextEdwin->IsWrapEnabled(); |
|
1119 DEBUG("CMIDTextEditor::SetMultilineL -"); |
|
1120 return multiline; |
|
1121 } |
|
1122 |
|
1123 |
|
1124 // --------------------------------------------------------------------------- |
|
1125 // CMIDTextEditor::SetInitialInputModeL |
|
1126 // (other items are commented in the header file) |
|
1127 // --------------------------------------------------------------------------- |
|
1128 // |
|
1129 void CMIDTextEditor::SetInitialInputModeL(const TDesC& aCharacterSubset) |
|
1130 { |
|
1131 DEBUG("CMIDTextEditor::SetInitialInputModeL +"); |
|
1132 |
|
1133 // Edwin handles the initial input mode change. |
|
1134 iTextEdwin->SetInitialInputModeL(aCharacterSubset); |
|
1135 |
|
1136 DEBUG("CMIDTextEditor::SetInitialInputModeL -"); |
|
1137 } |
|
1138 |
|
1139 // --------------------------------------------------------------------------- |
|
1140 // CMIDTextEditor::SetMaxSizeL |
|
1141 // (other items are commented in the header file) |
|
1142 // --------------------------------------------------------------------------- |
|
1143 // |
|
1144 TInt CMIDTextEditor::SetMaxSizeL(TInt aMaxSize) |
|
1145 { |
|
1146 DEBUG_INT("CMIDTextEditor::SetMaxSizeL +, aMaxSize=%d", aMaxSize); |
|
1147 |
|
1148 // Maximum size cannot be zero or less. |
|
1149 __ASSERT_DEBUG(aMaxSize > 0, User::Invariant()); |
|
1150 |
|
1151 TInt contentLength = ContentLength(); |
|
1152 // Truncat from the end if the new maximum size is too small. |
|
1153 |
|
1154 if (contentLength > aMaxSize) |
|
1155 { |
|
1156 DeleteContentL(aMaxSize, contentLength - aMaxSize); |
|
1157 } |
|
1158 |
|
1159 // Store text limit to the editor. |
|
1160 iTextEdwin->SetTextLimit(aMaxSize); |
|
1161 |
|
1162 // Set upper full format length. This prevents the layout |
|
1163 // from dropping lines from formatting and causing problems |
|
1164 // when calculating line height and number of lines in the editor. |
|
1165 iTextEdwin->SetUpperFullFormattingLength(aMaxSize); |
|
1166 |
|
1167 DEBUG("CMIDTextEditor::SetMaxSizeL -"); |
|
1168 |
|
1169 return aMaxSize; |
|
1170 } |
|
1171 |
|
1172 // --------------------------------------------------------------------------- |
|
1173 // CMIDTextEditor::SetCursorPositionL |
|
1174 // (other items are commented in the header file) |
|
1175 // --------------------------------------------------------------------------- |
|
1176 // |
|
1177 void CMIDTextEditor::SetCursorPositionL(TInt aIndex) |
|
1178 { |
|
1179 DEBUG_INT("CMIDTextEditor::SetCursorPositionL +, aIndex=%d", aIndex); |
|
1180 |
|
1181 // Cursor must be set to a valid position within the content. |
|
1182 __ASSERT_DEBUG(aIndex >= 0 && aIndex <= ContentLength(), |
|
1183 User::Invariant()); |
|
1184 |
|
1185 // Cursor position handling is done in CMIDTextEditorEdwin |
|
1186 iTextEdwin->SetCursorPosL(aIndex, EFalse); |
|
1187 |
|
1188 DEBUG("CMIDTextEditor::SetCursorPositionL -"); |
|
1189 } |
|
1190 |
|
1191 // --------------------------------------------------------------------------- |
|
1192 // CMIDTextEditor::CursorPosition |
|
1193 // (other items are commented in the header file) |
|
1194 // --------------------------------------------------------------------------- |
|
1195 // |
|
1196 TInt CMIDTextEditor::CursorPosition() const |
|
1197 { |
|
1198 DEBUG("CMIDTextEditor::CursorPosition"); |
|
1199 |
|
1200 // Cursor position handling is done in CMIDTextEditorEdwin |
|
1201 return iTextEdwin->CursorPos(); |
|
1202 } |
|
1203 |
|
1204 // --------------------------------------------------------------------------- |
|
1205 // CMIDTextEditor::SetColorL |
|
1206 // (other items are commented in the header file) |
|
1207 // --------------------------------------------------------------------------- |
|
1208 // |
|
1209 void CMIDTextEditor::SetColorL(const TRgb& aColor, TColorType aColorType) |
|
1210 { |
|
1211 DEBUG_INT("CMIDTextEditor::SetColorL + aColorType=%d", aColorType); |
|
1212 |
|
1213 __ASSERT_DEBUG( |
|
1214 aColorType == MMIDTextEditor::EColorBackground || |
|
1215 aColorType == MMIDTextEditor::EColorForeground || |
|
1216 aColorType == MMIDTextEditor::EColorHighlightBackground || |
|
1217 aColorType == MMIDTextEditor::EColorHighlightForeground, |
|
1218 User::Invariant()); |
|
1219 |
|
1220 if (aColorType == MMIDTextEditor::EColorForeground) |
|
1221 { |
|
1222 // Apply new character format for the editor. |
|
1223 // Font color is handled internally in the editor window. |
|
1224 TCharFormat charFormat; |
|
1225 TCharFormatMask charMask; |
|
1226 iTextEdwin->OverrideColorL(EColorControlText, aColor); |
|
1227 |
|
1228 charMask.SetAttrib(EAttColor); |
|
1229 charFormat.iFontPresentation.iTextColor = aColor; |
|
1230 |
|
1231 // Apply character formats. |
|
1232 CGlobalText* text = static_cast< CGlobalText* >(iTextEdwin->Text()); |
|
1233 text->ApplyCharFormatL(charFormat, charMask, 0, ContentLength()); |
|
1234 } |
|
1235 else if (aColorType == MMIDTextEditor::EColorHighlightBackground) |
|
1236 { |
|
1237 // Highlight color is handled in the custom drawer. |
|
1238 // Just override the default color of highlight background |
|
1239 // and let the custom drawer to do the work. |
|
1240 iTextEdwin->OverrideColorL( |
|
1241 EColorControlHighlightBackground, aColor); |
|
1242 } |
|
1243 else if (aColorType == MMIDTextEditor::EColorHighlightForeground) |
|
1244 { |
|
1245 // Highlight color is handled in the custom drawer. |
|
1246 // Just override the default color of highlight background |
|
1247 // and let the custom drawer to do the work. |
|
1248 iTextEdwin->OverrideColorL(EColorControlHighlightText, aColor); |
|
1249 } |
|
1250 else if (aColorType == MMIDTextEditor::EColorBackground) |
|
1251 { |
|
1252 // Background color is handled internally in the Text Editor edwin. |
|
1253 // Just override the default color of the control's background |
|
1254 // and let the editor do the work. Background color alpha channel |
|
1255 // does not work correctly with paragraph format so it is not used |
|
1256 // here. |
|
1257 iTextEdwin->OverrideColorL(EColorControlBackground, aColor); |
|
1258 |
|
1259 // Apply paraformat if the color is not transparent. |
|
1260 if (!iTextEdwin->IsTransparent()) |
|
1261 { |
|
1262 CParaFormat* paraFormat = new(ELeave) CParaFormat(); |
|
1263 CleanupStack::PushL(paraFormat); |
|
1264 paraFormat->iFillColor = aColor; |
|
1265 |
|
1266 TParaFormatMask paraMask; |
|
1267 paraMask.SetAttrib(EAttFillColor); |
|
1268 |
|
1269 static_cast< CGlobalText* >( |
|
1270 iTextEdwin->Text())->ApplyParaFormatL( |
|
1271 paraFormat, |
|
1272 paraMask, |
|
1273 0, |
|
1274 iTextEdwin->TextLength()); |
|
1275 |
|
1276 CleanupStack::PopAndDestroy(paraFormat); |
|
1277 } |
|
1278 |
|
1279 // Apply same color to the custom indicator. |
|
1280 iEditingStateIndicator->OverrideColorL( |
|
1281 EColorControlBackground, aColor); |
|
1282 } |
|
1283 |
|
1284 // OverrideColorL does not apply colors yet. |
|
1285 // Redraw the control in order to get the colors in use. |
|
1286 iTextEdwin->Redraw(); |
|
1287 |
|
1288 DEBUG("CMIDTextEditor::SetColorL -"); |
|
1289 } |
|
1290 |
|
1291 // --------------------------------------------------------------------------- |
|
1292 // CMIDTextEditor::GetColorL |
|
1293 // (other items are commented in the header file) |
|
1294 // --------------------------------------------------------------------------- |
|
1295 // |
|
1296 TInt CMIDTextEditor::GetColor(TColorType aColorType) |
|
1297 { |
|
1298 DEBUG_INT("CMIDTextEditor::GetColorL + aColorType=%d", aColorType); |
|
1299 |
|
1300 __ASSERT_DEBUG( |
|
1301 aColorType == MMIDTextEditor::EColorBackground || |
|
1302 aColorType == MMIDTextEditor::EColorForeground, |
|
1303 User::Invariant()); |
|
1304 |
|
1305 TRgb color; |
|
1306 if (aColorType == MMIDTextEditor::EColorForeground) |
|
1307 { |
|
1308 iTextEdwin->GetColor(EColorControlText, color); |
|
1309 } |
|
1310 else if (aColorType == MMIDTextEditor::EColorBackground) |
|
1311 { |
|
1312 iTextEdwin->GetColor(EColorControlBackground, color); |
|
1313 } |
|
1314 |
|
1315 TInt red = color.Red(); |
|
1316 TInt green = color.Green(); |
|
1317 TInt blue = color.Blue(); |
|
1318 TInt alpha = color.Alpha(); |
|
1319 TInt returnColor = (alpha<<24)|(red<<16)|(green<<8)|blue; |
|
1320 |
|
1321 DEBUG("CMIDTextEditor::GetColorL -"); |
|
1322 return returnColor; |
|
1323 } |
|
1324 |
|
1325 // --------------------------------------------------------------------------- |
|
1326 // CMIDTextEditor::SetFontL |
|
1327 // (other items are commented in the header file) |
|
1328 // --------------------------------------------------------------------------- |
|
1329 // |
|
1330 void CMIDTextEditor::SetFontL(MMIDFont* aFont) |
|
1331 { |
|
1332 DEBUG("CMIDTextEditor::SetFontL +"); |
|
1333 |
|
1334 TFontSpec fontspec = (aFont->Font(ETrue))->FontSpecInTwips(); |
|
1335 // If scaling is on, this code does scaling of size of font. |
|
1336 if (iComponentContainer && iComponentContainer->IsFullScreen()) |
|
1337 { |
|
1338 fontspec.iHeight=iUtils->DoScaling(fontspec.iHeight, CMIDUtils::EVertical); |
|
1339 } |
|
1340 |
|
1341 TCharFormat charFormat(fontspec.iTypeface.iName, fontspec.iHeight); |
|
1342 TCharFormatMask charFormatMask; |
|
1343 |
|
1344 // For some reason TCharFormat does not get all the parameters from |
|
1345 // TFontSpec, so check and fill those (underline/bold/italic) manually. |
|
1346 charFormat.iFontPresentation.iUnderline = EUnderlineOff; |
|
1347 |
|
1348 if (aFont->IsUnderlined()) |
|
1349 { |
|
1350 charFormat.iFontPresentation.iUnderline = EUnderlineOn; |
|
1351 } |
|
1352 |
|
1353 charFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightNormal); |
|
1354 |
|
1355 if (fontspec.iFontStyle.StrokeWeight() == EStrokeWeightBold) |
|
1356 { |
|
1357 charFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold); |
|
1358 } |
|
1359 |
|
1360 charFormat.iFontSpec.iFontStyle.SetPosture(EPostureUpright); |
|
1361 |
|
1362 if (fontspec.iFontStyle.Posture() == EPostureItalic) |
|
1363 { |
|
1364 charFormat.iFontSpec.iFontStyle.SetPosture(EPostureItalic); |
|
1365 } |
|
1366 |
|
1367 charFormatMask.SetAll(); |
|
1368 |
|
1369 // Get current foreground font color and apply it to the new char |
|
1370 // format. Highlight color is currently handled in the custom draw. |
|
1371 TRgb color; |
|
1372 |
|
1373 if (iTextEdwin->GetColor(EColorControlText, color)) |
|
1374 { |
|
1375 charFormat.iFontPresentation.iTextColor = color; |
|
1376 } |
|
1377 |
|
1378 // Apply character formats. |
|
1379 CGlobalText* text = static_cast< CGlobalText* >(iTextEdwin->Text()); |
|
1380 text->ApplyCharFormatL(charFormat, charFormatMask, 0, ContentLength()); |
|
1381 iTextEdwin->HandleTextChangedL(); |
|
1382 |
|
1383 // Resize the editor window if editor was created with row count parameter |
|
1384 // AND the SetEditorSize method has not been called directly yet. |
|
1385 if (iRowCountActive) |
|
1386 { |
|
1387 TSize size = EditorSize(); |
|
1388 TInt newEditorWindowHeight = iTextEdwin->EditorWindowHeight(); |
|
1389 |
|
1390 if (size.iHeight != newEditorWindowHeight) |
|
1391 { |
|
1392 SetEditorSize(size.iWidth, newEditorWindowHeight); |
|
1393 } |
|
1394 // SetEditorSize method resets the flag, make sure it remains true |
|
1395 // here. |
|
1396 iRowCountActive = ETrue; |
|
1397 } |
|
1398 |
|
1399 // Move caret to its position along with the view |
|
1400 SetCursorPositionL(iTextEdwin->CursorPos()); |
|
1401 |
|
1402 // Store a non-scaled version of font for posibility of use it during |
|
1403 // orientation and fullscreen mode change. |
|
1404 iNonScaledFont = aFont; |
|
1405 |
|
1406 DEBUG("CMIDTextEditor::SetFontL -"); |
|
1407 } |
|
1408 |
|
1409 // --------------------------------------------------------------------------- |
|
1410 // CMIDTextEditor::SetPreferredTouchInputMode |
|
1411 // (other items are commented in the header file) |
|
1412 // --------------------------------------------------------------------------- |
|
1413 // |
|
1414 #ifdef RD_TACTILE_FEEDBACK |
|
1415 void CMIDTextEditor::SetPreferredTouchInputMode(TInt aInputMode) |
|
1416 #else |
|
1417 void CMIDTextEditor::SetPreferredTouchInputMode(TInt /*aInputMode*/) |
|
1418 #endif // RD_TACTILE_FEEDBACK |
|
1419 { |
|
1420 DEBUG("CMIDTextEditor::SetPreferredTouchInputMode +"); |
|
1421 |
|
1422 #ifdef RD_TACTILE_FEEDBACK |
|
1423 if (isConnected()) |
|
1424 { |
|
1425 DEBUG_INT( |
|
1426 "CMIDTextEditor::SetPreferredTouchInputMode, aInputMode=%d", |
|
1427 aInputMode); |
|
1428 |
|
1429 // Casting is ok since values map directly to TextEditor's |
|
1430 // S60 extension. |
|
1431 iPenServer.SetPreferredUiMode( |
|
1432 static_cast< TPluginInputMode >(aInputMode)); |
|
1433 } |
|
1434 #endif // RD_TACTILE_FEEDBACK |
|
1435 |
|
1436 DEBUG("CMIDTextEditor::SetPreferredTouchInputMode -"); |
|
1437 } |
|
1438 |
|
1439 // --------------------------------------------------------------------------- |
|
1440 // CMIDTextEditor::PreferredTouchInputMode |
|
1441 // (other items are commented in the header file) |
|
1442 // --------------------------------------------------------------------------- |
|
1443 // |
|
1444 TInt CMIDTextEditor::PreferredTouchInputMode() |
|
1445 { |
|
1446 DEBUG("CMIDTextEditor::PreferredTouchInputMode +"); |
|
1447 |
|
1448 // By default, there are not input modes preferred. |
|
1449 TInt preferredMode = 0; |
|
1450 |
|
1451 #ifdef RD_TACTILE_FEEDBACK |
|
1452 if (isConnected()) |
|
1453 { |
|
1454 DEBUG("CMIDTextEditor::PreferredTouchInputMode, pen enabled"); |
|
1455 |
|
1456 preferredMode = iPenServer.PreferredUiMode(); |
|
1457 } |
|
1458 #endif // RD_TACTILE_FEEDBACK |
|
1459 |
|
1460 DEBUG_INT("CMIDTextEditor::PreferredTouchInputMode -, preferredMode=%d", |
|
1461 preferredMode); |
|
1462 |
|
1463 return preferredMode; |
|
1464 } |
|
1465 |
|
1466 // --------------------------------------------------------------------------- |
|
1467 // CMIDTextEditor::SetDisabledTouchInputModes |
|
1468 // (other items are commented in the header file) |
|
1469 // --------------------------------------------------------------------------- |
|
1470 // |
|
1471 #ifdef RD_TACTILE_FEEDBACK |
|
1472 void CMIDTextEditor::SetDisabledTouchInputModes(TInt aInputModes) |
|
1473 #else |
|
1474 void CMIDTextEditor::SetDisabledTouchInputModes(TInt /*aInputModes*/) |
|
1475 #endif // RD_TACTILE_FEEDBACK |
|
1476 { |
|
1477 DEBUG("CMIDTextEditor::SetDisabledTouchInputModes +"); |
|
1478 |
|
1479 #ifdef RD_TACTILE_FEEDBACK |
|
1480 if (isConnected()) |
|
1481 { |
|
1482 DEBUG_INT( |
|
1483 "CMIDTextEditor::SetDisabledTouchInputModes, aInputModes=%d", |
|
1484 aInputModes); |
|
1485 |
|
1486 iPenServer.SetDisabledLayout(aInputModes); |
|
1487 } |
|
1488 #endif // RD_TACTILE_FEEDBACK |
|
1489 |
|
1490 DEBUG("CMIDTextEditor::SetDisabledTouchInputModes -"); |
|
1491 } |
|
1492 |
|
1493 // --------------------------------------------------------------------------- |
|
1494 // CMIDTextEditor::DisabledTouchInputModes |
|
1495 // (other items are commented in the header file) |
|
1496 // --------------------------------------------------------------------------- |
|
1497 // |
|
1498 TInt CMIDTextEditor::DisabledTouchInputModes() |
|
1499 { |
|
1500 DEBUG("CMIDTextEditor::DisabledTouchInputModes +"); |
|
1501 |
|
1502 // By default, all input modes are disabled. |
|
1503 TInt disabled = KAllTouchModesDisabled; |
|
1504 |
|
1505 #ifdef RD_TACTILE_FEEDBACK |
|
1506 if (isConnected()) |
|
1507 { |
|
1508 DEBUG("CMIDTextEditor::DisabledTouchInputModes, pen enabled"); |
|
1509 |
|
1510 disabled = iPenServer.DisabledLayout(); |
|
1511 } |
|
1512 #endif // RD_TACTILE_FEEDBACK |
|
1513 |
|
1514 DEBUG_INT("CMIDTextEditor::DisabledTouchInputModes -, disabled=%d", |
|
1515 disabled); |
|
1516 |
|
1517 return disabled; |
|
1518 } |
|
1519 |
|
1520 // --------------------------------------------------------------------------- |
|
1521 // CMIDTextEditor::SetIndicatorVisibilityL |
|
1522 // (other items are commented in the header file) |
|
1523 // --------------------------------------------------------------------------- |
|
1524 // |
|
1525 void CMIDTextEditor::SetIndicatorVisibilityL(TBool aVisible) |
|
1526 { |
|
1527 DEBUG("CMIDTextEditor::SetIndicatorVisibilityL +"); |
|
1528 |
|
1529 // Do not set the indicator's visibility if the editor is not visible. |
|
1530 if (iTextEdwin->IsVisible()) |
|
1531 { |
|
1532 DEBUG("CMIDTextEditor::SetIndicatorVisibilityL, \ |
|
1533 controlling visibility"); |
|
1534 |
|
1535 iEditingStateIndicator->SetVisibleL(aVisible); |
|
1536 |
|
1537 // Notify about state change so the indicator gets updated. |
|
1538 // Otherwise the indicator's state may not update correctly when |
|
1539 // set as visible. |
|
1540 if (aVisible) |
|
1541 { |
|
1542 iTextEdwin->NotifyEditorStateObserverOfStateChangeL(); |
|
1543 } |
|
1544 } |
|
1545 |
|
1546 DEBUG("CMIDTextEditor::SetIndicatorVisibilityL -"); |
|
1547 } |
|
1548 |
|
1549 // --------------------------------------------------------------------------- |
|
1550 // CMIDTextEditor::SetIndicatorPosition |
|
1551 // (other items are commented in the header file) |
|
1552 // --------------------------------------------------------------------------- |
|
1553 // |
|
1554 void CMIDTextEditor::SetIndicatorPosition(TInt aX, TInt aY) |
|
1555 { |
|
1556 DEBUG("CMIDTextEditor::SetIndicatorPosition +"); |
|
1557 |
|
1558 iEditingStateIndicator->SetPosition(aX, aY); |
|
1559 // Custom position set, state set to absolute. |
|
1560 |
|
1561 iEditingStateIndicator->SetEnabledState( |
|
1562 CMIDEditingStateIndicator::EIndicatorStateAbsolute); |
|
1563 |
|
1564 // Disable the current editing state indicator when custom indicator |
|
1565 // position has been specified by the client application. |
|
1566 MAknEditingStateIndicator* indicator = |
|
1567 CAknEnv::Static()->EditingStateIndicator(); |
|
1568 |
|
1569 if (indicator) |
|
1570 { |
|
1571 indicator->SetState(EStateNone); |
|
1572 } |
|
1573 |
|
1574 DEBUG("CMIDTextEditor::SetIndicatorPosition -"); |
|
1575 } |
|
1576 |
|
1577 // --------------------------------------------------------------------------- |
|
1578 // CMIDTextEditor::IndicatorSize |
|
1579 // (other items are commented in the header file) |
|
1580 // --------------------------------------------------------------------------- |
|
1581 // |
|
1582 TSize CMIDTextEditor::IndicatorSize() const |
|
1583 { |
|
1584 // The default size is (0,0) if indicators are in the status pane. |
|
1585 TSize size; |
|
1586 |
|
1587 if (iEditingStateIndicator->EnabledState() != |
|
1588 CMIDEditingStateIndicator::EIndicatorStateDisabled) |
|
1589 { |
|
1590 size = iEditingStateIndicator->Size(); |
|
1591 } |
|
1592 |
|
1593 return size; |
|
1594 } |
|
1595 |
|
1596 // --------------------------------------------------------------------------- |
|
1597 // CMIDTextEditor::SetDefaultIndicatorsL |
|
1598 // (other items are commented in the header file) |
|
1599 // --------------------------------------------------------------------------- |
|
1600 // |
|
1601 void CMIDTextEditor::SetDefaultIndicatorsL() |
|
1602 { |
|
1603 DEBUG("CMIDTextEditor::SetDefaultIndicatorsL +"); |
|
1604 |
|
1605 if (iComponentContainer) |
|
1606 { |
|
1607 if (!iComponentContainer->IsFullScreen()) |
|
1608 { |
|
1609 iEditingStateIndicator->SetEnabledState( |
|
1610 CMIDEditingStateIndicator::EIndicatorStateDisabled); |
|
1611 } |
|
1612 else |
|
1613 { |
|
1614 iEditingStateIndicator->SetEnabledState( |
|
1615 CMIDEditingStateIndicator::EIndicatorStateRelative); |
|
1616 } |
|
1617 } |
|
1618 // Update indicator location. |
|
1619 UpdateIndicatorPosition(); |
|
1620 |
|
1621 // Notify about state change so the indicator gets updated. |
|
1622 // Otherwise the indicator's state may not update correctly when |
|
1623 // set as visible. |
|
1624 iTextEdwin->NotifyEditorStateObserverOfStateChangeL(); |
|
1625 |
|
1626 DEBUG("CMIDTextEditor::SetDefaultIndicatorsL -"); |
|
1627 } |
|
1628 |
|
1629 // --------------------------------------------------------------------------- |
|
1630 // CMIDTextEditor::Dispose |
|
1631 // (other items are commented in the header file) |
|
1632 // --------------------------------------------------------------------------- |
|
1633 // |
|
1634 void CMIDTextEditor::Dispose() |
|
1635 { |
|
1636 DEBUG("CMIDTextEditor::Dispose +"); |
|
1637 |
|
1638 delete this; |
|
1639 |
|
1640 DEBUG("CMIDTextEditor::Dispose -"); |
|
1641 } |
|
1642 |
|
1643 // --------------------------------------------------------------------------- |
|
1644 // CMIDTextEditor::MdcContainerWindowRectChanged |
|
1645 // (other items are commented in the header file) |
|
1646 // --------------------------------------------------------------------------- |
|
1647 // |
|
1648 |
|
1649 void CMIDTextEditor::MdcContainerWindowRectChanged(const TRect& /*aRect*/) |
|
1650 { |
|
1651 DEBUG("CMIDTextEditor::MdcContainerWindowRectChanged +"); |
|
1652 |
|
1653 // Not used at the moment. |
|
1654 |
|
1655 DEBUG("CMIDTextEditor::MdcContainerWindowRectChanged -"); |
|
1656 } |
|
1657 |
|
1658 // --------------------------------------------------------------------------- |
|
1659 // CMIDTextEditor::MdcContainerVisibilityChanged |
|
1660 // (other items are commented in the header file) |
|
1661 // --------------------------------------------------------------------------- |
|
1662 // |
|
1663 void CMIDTextEditor::MdcContainerVisibilityChanged(TBool /*aVisible*/) |
|
1664 { |
|
1665 DEBUG("CMIDTextEditor::MdcContainerVisibilityChanged +"); |
|
1666 |
|
1667 // Not used at the moment. |
|
1668 |
|
1669 DEBUG("CMIDTextEditor::MdcContainerVisibilityChanged -"); |
|
1670 } |
|
1671 |
|
1672 // --------------------------------------------------------------------------- |
|
1673 // CMIDTextEditor::MdcContentBoundsChanged |
|
1674 // (other items are commented in the header file) |
|
1675 // --------------------------------------------------------------------------- |
|
1676 // |
|
1677 void CMIDTextEditor::MdcContentBoundsChanged(const TRect& /*aRect*/) |
|
1678 { |
|
1679 DEBUG("CMIDTextEditor::MdcContentBoundsChanged +"); |
|
1680 |
|
1681 CMIDEditingStateIndicator::TIndicatorState state = |
|
1682 iEditingStateIndicator->EnabledState(); |
|
1683 |
|
1684 // Check if the container has been set to full screen. If the indicator |
|
1685 // position is not controlled by the user, the state is enabled and set |
|
1686 // to relative. The indicator is drawn relative to the editor window. |
|
1687 // Otherwise, if using default indicators, disable custom indicators so |
|
1688 // that standard navi pane indicators are shown. |
|
1689 |
|
1690 if (iComponentContainer && iComponentContainer->IsFullScreen() && |
|
1691 state == CMIDEditingStateIndicator::EIndicatorStateDisabled) |
|
1692 { |
|
1693 DEBUG("CMIDTextEditor::MdcContentBoundsChanged, \ |
|
1694 setting indicators relative"); |
|
1695 |
|
1696 // Enable indicators and update position as relative to the editor. |
|
1697 iEditingStateIndicator->SetEnabledState( |
|
1698 CMIDEditingStateIndicator::EIndicatorStateRelative); |
|
1699 |
|
1700 // Make the indicator visible if the editor is visible and focused. |
|
1701 if (iTextEdwin->IsVisible() && iTextEdwin->IsFocused()) |
|
1702 { |
|
1703 iEditingStateIndicator->MakeVisible(ETrue); |
|
1704 } |
|
1705 } |
|
1706 else if (iComponentContainer && (!iComponentContainer->IsFullScreen()) && |
|
1707 (state == CMIDEditingStateIndicator::EIndicatorStateRelative)) |
|
1708 { |
|
1709 DEBUG( |
|
1710 "CMIDTextEditor::MdcContentBoundsChanged, disabling indicators"); |
|
1711 |
|
1712 // Disable indicators when relative and back to normal screen. |
|
1713 iEditingStateIndicator->SetEnabledState( |
|
1714 CMIDEditingStateIndicator::EIndicatorStateDisabled); |
|
1715 } |
|
1716 |
|
1717 // Update position. |
|
1718 UpdateIndicatorPosition(); |
|
1719 |
|
1720 // Notify editor about state change. |
|
1721 TRAP_IGNORE(iTextEdwin->NotifyEditorStateObserverOfStateChangeL()); |
|
1722 |
|
1723 DEBUG("CMIDTextEditor::MdcContentBoundsChanged -"); |
|
1724 } |
|
1725 |
|
1726 // --------------------------------------------------------------------------- |
|
1727 // CMIDTextEditor::MdcItemContentRectChanged |
|
1728 // (other items are commented in the header file) |
|
1729 // --------------------------------------------------------------------------- |
|
1730 // |
|
1731 void CMIDTextEditor::MdcItemContentRectChanged( |
|
1732 const TRect& /*aContentRect*/, |
|
1733 const TRect& /*aScreenRect*/) |
|
1734 { |
|
1735 DEBUG("CMIDTextEditor::MdcItemContentRectChanged +"); |
|
1736 |
|
1737 // Not used at the moment. |
|
1738 |
|
1739 DEBUG("CMIDTextEditor::MdcItemContentRectChanged -"); |
|
1740 } |
|
1741 |
|
1742 // --------------------------------------------------------------------------- |
|
1743 // CMIDTextEditor::MdcContainerDestroyed |
|
1744 // (other items are commented in the header file) |
|
1745 // --------------------------------------------------------------------------- |
|
1746 // |
|
1747 void CMIDTextEditor::MdcContainerDestroyed() |
|
1748 { |
|
1749 DEBUG("CMIDTextEditor::MdcContainerDestroyed +"); |
|
1750 |
|
1751 iDirectContainer = NULL; |
|
1752 |
|
1753 DEBUG("CMIDTextEditor::MdcContainerDestroyed -"); |
|
1754 } |
|
1755 |
|
1756 // --------------------------------------------------------------------------- |
|
1757 // CMIDTextEditor::HandleControlEventL |
|
1758 // (other items are commented in the header file) |
|
1759 // --------------------------------------------------------------------------- |
|
1760 // |
|
1761 void CMIDTextEditor::HandleControlEventL( |
|
1762 CCoeControl* aControl, |
|
1763 TCoeEvent aEventType) |
|
1764 { |
|
1765 if (iObserver && aControl == iEditingStateIndicator && |
|
1766 aEventType == MCoeControlObserver::EEventStateChanged) |
|
1767 { |
|
1768 iObserver->NotifyInputAction( |
|
1769 MMIDTextEditorObserver::EActionInputModeChange); |
|
1770 } |
|
1771 } |
|
1772 |
|
1773 |
|
1774 void CMIDTextEditor::MdcAbortDSA() |
|
1775 { |
|
1776 DEBUG("CMIDTextEditor::MdcAbortDSA +"); |
|
1777 |
|
1778 // Not used at the moment. |
|
1779 |
|
1780 DEBUG("CMIDTextEditor::MdcAbortDSA -"); |
|
1781 } |
|
1782 |
|
1783 |
|
1784 void CMIDTextEditor::MdcResumeDSA() |
|
1785 { |
|
1786 DEBUG("CMIDTextEditor::MdcResumeDSA +"); |
|
1787 |
|
1788 // Not used at the moment. |
|
1789 |
|
1790 DEBUG("CMIDTextEditor::MdcResumeDSA -"); |
|
1791 } |
|
1792 |
|
1793 // --------------------------------------------------------------------------- |
|
1794 // CMIDTextEditor::ProcessPointerEventL |
|
1795 // (other items are commented in the header file) |
|
1796 // --------------------------------------------------------------------------- |
|
1797 // |
|
1798 void CMIDTextEditor::ProcessPointerEventL(const TPointerEvent& aPointerEvent) |
|
1799 { |
|
1800 TSize size = EditorSize(); |
|
1801 TPoint position = iTextEdwin->Position(); |
|
1802 TRect rect = iTextEdwin->Rect(); |
|
1803 if (rect.Contains(aPointerEvent.iPosition)) |
|
1804 { |
|
1805 // Pointer event inside the editor |
|
1806 iTextEdwin->HandlePointerEventL(aPointerEvent); |
|
1807 } |
|
1808 else if (aPointerEvent.iPosition.iY < position.iY) |
|
1809 { |
|
1810 // If editor is scrolled, send scroll event to midlet |
|
1811 if (iTextEdwin->CursorPos() == 0) |
|
1812 { |
|
1813 if (iObserver) |
|
1814 { |
|
1815 iObserver->NotifyInputAction( |
|
1816 MMIDTextEditorObserver::EActionScrollUp); |
|
1817 } |
|
1818 } |
|
1819 else |
|
1820 { |
|
1821 iTextEdwin->HandlePointerEventL(aPointerEvent); |
|
1822 } |
|
1823 } |
|
1824 else if (aPointerEvent.iPosition.iY > (position.iY + size.iHeight)) |
|
1825 { |
|
1826 // If editor is scrolled, send scroll event to midlet |
|
1827 if (iTextEdwin->CursorPos() == ContentLength()) |
|
1828 { |
|
1829 if (iObserver) |
|
1830 { |
|
1831 iObserver->NotifyInputAction( |
|
1832 MMIDTextEditorObserver::EActionScrollDown); |
|
1833 } |
|
1834 } |
|
1835 else |
|
1836 { |
|
1837 iTextEdwin->HandlePointerEventL(aPointerEvent); |
|
1838 } |
|
1839 } |
|
1840 else |
|
1841 { |
|
1842 // Pointer event on the left or right side of editor |
|
1843 iTextEdwin->HandlePointerEventL(aPointerEvent); |
|
1844 } |
|
1845 } |
|
1846 |
|
1847 // --------------------------------------------------------------------------- |
|
1848 // CMIDTextEditor::ConvertedContentLC |
|
1849 // (other items are commented in the header file) |
|
1850 // --------------------------------------------------------------------------- |
|
1851 // |
|
1852 HBufC* CMIDTextEditor::ConvertedContentLC(const TDesC& aContent) |
|
1853 { |
|
1854 DEBUG("CMIDTextEditor::ConvertedContentLC +"); |
|
1855 |
|
1856 HBufC* content = aContent.AllocLC(); |
|
1857 TPtr contentPtr = content->Des(); |
|
1858 |
|
1859 // Convert breaks if needed if constraints that do not allow line breaks. |
|
1860 // Note that numeric, decimal, url, email address and phonenumber do not |
|
1861 // allow line breaks and are checked before this so no need to check here |
|
1862 // again. Note that conversion must be made here instead of after |
|
1863 // ConvertToLocalicedLC because it performs some line break |
|
1864 // transformations also. |
|
1865 if ((!iTextEdwin->IsWrapEnabled()) || |
|
1866 (iConstraints & MMIDTextField::EPassword)) |
|
1867 { |
|
1868 iEdwinUtils->CropToSingleLine(contentPtr); |
|
1869 } |
|
1870 else |
|
1871 { |
|
1872 // Convert legacy breaks to unicode breaks. |
|
1873 iEdwinUtils->ConvertToUnicodeBreaks(contentPtr); |
|
1874 } |
|
1875 |
|
1876 // Convert to language specific localized string. |
|
1877 HBufC* buf = iEdwinUtils->ConvertToLocalizedLC(*content, iConstraints); |
|
1878 TPtr ptr = buf->Des(); |
|
1879 |
|
1880 // Pop content. |
|
1881 CleanupStack::Pop(buf); |
|
1882 CleanupStack::PopAndDestroy(content); |
|
1883 CleanupStack::PushL(buf); |
|
1884 |
|
1885 // Perform number conversion if it is needed. |
|
1886 if (iEdwinUtils->IsNumberConversionNeeded(iConstraints)) |
|
1887 { |
|
1888 DEBUG("CMIDTextEditor::ConvertedContentLC, \ |
|
1889 language specific number conversion"); |
|
1890 |
|
1891 AknTextUtils::LanguageSpecificNumberConversion(ptr); |
|
1892 } |
|
1893 |
|
1894 // Remove other than phone number characters if this is only a phone |
|
1895 // number text editor. |
|
1896 if (iTextEdwin->IsConstraintSet(MMIDTextField::EPhoneNumber)) |
|
1897 { |
|
1898 DEBUG("CMIDTextEditor::ConvertedContentLC, \ |
|
1899 remove non phone number chars"); |
|
1900 |
|
1901 iEdwinUtils->RemoveNonPhoneNumberChars(buf); |
|
1902 } |
|
1903 |
|
1904 DEBUG("CMIDTextEditor::ConvertedContentLC -"); |
|
1905 |
|
1906 return buf; |
|
1907 } |
|
1908 |
|
1909 // --------------------------------------------------------------------------- |
|
1910 // CMIDTextEditor::UpdateIndicatorPosition |
|
1911 // --------------------------------------------------------------------------- |
|
1912 // |
|
1913 void CMIDTextEditor::UpdateIndicatorPosition() |
|
1914 { |
|
1915 DEBUG("CMIDTextEditor::UpdateIndicatorPosition +"); |
|
1916 |
|
1917 CMIDEditingStateIndicator::TIndicatorState state = |
|
1918 iEditingStateIndicator->EnabledState(); |
|
1919 |
|
1920 if (state == CMIDEditingStateIndicator::EIndicatorStateRelative) |
|
1921 { |
|
1922 TSize indicatorSize = iEditingStateIndicator->Size(); |
|
1923 TSize editorSize = iTextEdwin->Size(); |
|
1924 TPoint editorPos = iTextEdwin->Position(); |
|
1925 |
|
1926 // Adjust position according to the editor's size |
|
1927 TInt x = editorPos.iX + editorSize.iWidth - indicatorSize.iWidth; |
|
1928 TInt y = editorPos.iY - indicatorSize.iHeight; |
|
1929 |
|
1930 DEBUG_INT2( |
|
1931 "CMIDTextEditor::UpdateIndicatorPosition, indicatorPos.X=%d, \ |
|
1932 indicatorPos.Y=%d", x, y); |
|
1933 |
|
1934 iEditingStateIndicator->SetPosition(x, y); |
|
1935 |
|
1936 // Update the indicator. |
|
1937 if (iTextEdwin->IsVisible() && iTextEdwin->IsFocused()) |
|
1938 { |
|
1939 iEditingStateIndicator->Redraw(); |
|
1940 } |
|
1941 else |
|
1942 { |
|
1943 iEditingStateIndicator->MakeVisible(EFalse); |
|
1944 } |
|
1945 } |
|
1946 |
|
1947 DEBUG("CMIDTextEditor::UpdateIndicatorPosition -"); |
|
1948 } |
|
1949 |
|
1950 // --------------------------------------------------------------------------- |
|
1951 // CMIDTextEditor::CMIDTextEditor |
|
1952 // (other items were commented in a header |
|
1953 // --------------------------------------------------------------------------- |
|
1954 // |
|
1955 TBool CMIDTextEditor::isConnected() |
|
1956 { |
|
1957 #ifdef RD_TACTILE_FEEDBACK |
|
1958 if (!iPenInputServerConnected && AknLayoutUtils::PenEnabled()) |
|
1959 { |
|
1960 TInt err = iPenServer.Connect(); |
|
1961 iPenInputServerConnected = (err == KErrNone); |
|
1962 } |
|
1963 return iPenInputServerConnected; |
|
1964 #else |
|
1965 return EFalse; |
|
1966 #endif // RD_TACTILE_FEEDBACK |
|
1967 |
|
1968 } |
|
1969 |
|
1970 // --------------------------------------------------------------------------- |
|
1971 // CMIDTextEditor::CMIDTextEditor |
|
1972 // --------------------------------------------------------------------------- |
|
1973 // |
|
1974 CMIDTextEditor::CMIDTextEditor() : iNonScaledFont(NULL), |
|
1975 iNonScaledPosition(), |
|
1976 iNonScaledEditorSize() |
|
1977 { |
|
1978 // No implementation. |
|
1979 } |
|
1980 |
|
1981 // --------------------------------------------------------------------------- |
|
1982 // CMIDTextEditor::ConstructL |
|
1983 // (other items were commented in a header |
|
1984 // --------------------------------------------------------------------------- |
|
1985 // |
|
1986 void CMIDTextEditor::ConstructL(const TCtorParams& aParams) |
|
1987 { |
|
1988 DEBUG("CMIDTextEditor::ConstructL +"); |
|
1989 // Set default focus |
|
1990 iFocusState = EFalse; |
|
1991 |
|
1992 // Create editor window utils for verifying text input. |
|
1993 // Locale is used to get the decimal separator. |
|
1994 TLocale locale; |
|
1995 iEdwinUtils = CMIDEdwinUtils::NewL(NULL, locale.DecimalSeparator()); |
|
1996 |
|
1997 // Create custom editing state indicator. |
|
1998 iEditingStateIndicator = CMIDEditingStateIndicator::NewL(); |
|
1999 |
|
2000 // Set the size of the indicator container. |
|
2001 iEditingStateIndicator->SetSize(aParams.iWidth, -1); |
|
2002 iEditingStateIndicator->SetObserver(this); |
|
2003 |
|
2004 // Create text editor component. |
|
2005 iTextEdwin = new(ELeave) CMIDTextEditorEdwin(*iEdwinUtils); |
|
2006 |
|
2007 // Set custom editing state indicator. |
|
2008 iTextEdwin->SetEditingStateIndicator(iEditingStateIndicator); |
|
2009 |
|
2010 // Editor width is measured in pixels and the editor must be resizable. |
|
2011 TInt flags = |
|
2012 CEikEdwin::EWidthInPixels | |
|
2013 CEikEdwin::EResizable | |
|
2014 CEikEdwin::EInclusiveSizeFixed; |
|
2015 |
|
2016 if (aParams.iHeightInRows) |
|
2017 { |
|
2018 // Height is specified using rows. |
|
2019 iTextEdwin->ConstructL( |
|
2020 flags, aParams.iWidth, aParams.iMaxSize, aParams.iHeight); |
|
2021 iRowCountActive = ETrue; |
|
2022 iRowCount = aParams.iHeight; |
|
2023 |
|
2024 // Editor size is too wide when created with rows. Adjust the width |
|
2025 // accordingly again after construction. Note that SetEditorSize() |
|
2026 // must not be used since it makes the editor not to use row count. |
|
2027 // CCoeControl::Size does not yet return valid values, so use |
|
2028 // EditorWindowHeight() instead. |
|
2029 iTextEdwin->SetSize( |
|
2030 aParams.iWidth, |
|
2031 iTextEdwin->EditorWindowHeight()); |
|
2032 } |
|
2033 else |
|
2034 { |
|
2035 iTextEdwin->ConstructL(flags, aParams.iWidth, aParams.iMaxSize); |
|
2036 |
|
2037 // Set the size using width and heigth. |
|
2038 SetEditorSize(aParams.iWidth, aParams.iHeight); |
|
2039 } |
|
2040 |
|
2041 // Apply default colors. |
|
2042 SetColorL( |
|
2043 TRgb( |
|
2044 KDefColorBgRed, |
|
2045 KDefColorBgGreen, |
|
2046 KDefColorBgBlue, |
|
2047 KDefColorBgAlpha), |
|
2048 MMIDTextEditor::EColorBackground); |
|
2049 |
|
2050 SetColorL( |
|
2051 TRgb( |
|
2052 KDefColorFgRed, |
|
2053 KDefColorFgGreen, |
|
2054 KDefColorFgBlue, |
|
2055 KDefColorFgAlpha), |
|
2056 MMIDTextEditor::EColorForeground); |
|
2057 |
|
2058 SetColorL( |
|
2059 TRgb( |
|
2060 KDefColorHlBgRed, |
|
2061 KDefColorHlBgGreen, |
|
2062 KDefColorHlBgBlue, |
|
2063 KDefColorHlBgAlpha), |
|
2064 MMIDTextEditor::EColorHighlightBackground); |
|
2065 |
|
2066 SetColorL( |
|
2067 TRgb( |
|
2068 KDefColorHlFgRed, |
|
2069 KDefColorHlFgGreen, |
|
2070 KDefColorHlFgBlue, |
|
2071 KDefColorHlFgAlpha), |
|
2072 MMIDTextEditor::EColorHighlightForeground); |
|
2073 |
|
2074 // TextEditor should defaultly receive pointer events when focused |
|
2075 iTouchEnabled = ETrue; |
|
2076 |
|
2077 #ifdef RD_TACTILE_FEEDBACK |
|
2078 iPenInputServerConnected = EFalse; |
|
2079 #endif // RD_TACTILE_FEEDBACK |
|
2080 |
|
2081 iUtils = aParams.iUtils; |
|
2082 |
|
2083 DEBUG("CMIDTextEditor::ConstructL -"); |
|
2084 } |
|
2085 |
|
2086 // --------------------------------------------------------------------------- |
|
2087 // CMIDTextEditor::HandleFullscreenModeChange |
|
2088 // (other items were commented in a header |
|
2089 // --------------------------------------------------------------------------- |
|
2090 // |
|
2091 void CMIDTextEditor::HandleFullscreenModeChange() |
|
2092 { |
|
2093 // It is needed to store iRowCountActive, because SetEditorSize resets it. |
|
2094 TBool rowCountActive = iRowCountActive; |
|
2095 |
|
2096 // Calling all functions which sets sizes and position of TextEditor. |
|
2097 SetEditorSize(iNonScaledEditorSize.iWidth, iNonScaledEditorSize.iHeight); |
|
2098 SetPosition(iNonScaledPosition.iX, iNonScaledPosition.iY); |
|
2099 if (iNonScaledFont) |
|
2100 { |
|
2101 TRAPD(err, SetFontL(iNonScaledFont)); |
|
2102 if (err != KErrNone) |
|
2103 { |
|
2104 DEBUG_INT("CMIDTextEditor::HandleFullscreenModeChange - error %d", err); |
|
2105 } |
|
2106 } |
|
2107 |
|
2108 // restoring of iRowCountActive |
|
2109 iRowCountActive = rowCountActive; |
|
2110 } |
|
2111 |
|
2112 // --------------------------------------------------------------------------- |
|
2113 // CMIDTextEditor::HandleResolutionChange |
|
2114 // (other items were commented in a header |
|
2115 // --------------------------------------------------------------------------- |
|
2116 // |
|
2117 void CMIDTextEditor::HandleResolutionChange() |
|
2118 { |
|
2119 // Reset of scaling data is needed, because size of screen is changed. |
|
2120 iUtils->ResetScalingData(); |
|
2121 |
|
2122 // It is needed to store iRowCountActive, because SetEditorSize resets it. |
|
2123 TBool rowCountActive = iRowCountActive; |
|
2124 |
|
2125 // Calling all functions which sets sizes and position of TextEditor. |
|
2126 SetEditorSize(iNonScaledEditorSize.iWidth, iNonScaledEditorSize.iHeight); |
|
2127 SetPosition(iNonScaledPosition.iX, iNonScaledPosition.iY); |
|
2128 if (iNonScaledFont) |
|
2129 { |
|
2130 TRAPD(err, SetFontL(iNonScaledFont)); |
|
2131 if (err != KErrNone) |
|
2132 { |
|
2133 DEBUG_INT("CMIDTextEditor::HandleFullscreenModeChange - error %d", err); |
|
2134 } |
|
2135 } |
|
2136 |
|
2137 // restoring of iRowCountActive |
|
2138 iRowCountActive = rowCountActive; |
|
2139 } |
|
2140 |
|
2141 // End of file |