|
1 /* |
|
2 * Copyright (c) 2003 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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <eikcapc.h> |
|
20 // |
|
21 #include "CMIDTextFieldItem.h" |
|
22 // CMIDEdwin API for iTextField and CMIDTextFieldEdwin::NewL |
|
23 #include "CMIDTextFieldEdwin.h" |
|
24 // API for iLabelControl |
|
25 #include "CMIDItemLabel.h" |
|
26 // CAknEdwinDrawingModifier API for iDrawingModifier |
|
27 #include <aknedwindrawingmodifier.h> |
|
28 |
|
29 // LAF in UpdateLayout |
|
30 #include <aknlayoutscalable_avkon.cdl.h> |
|
31 // information to decorate text |
|
32 #include <AknTextDecorationMetrics.h> |
|
33 |
|
34 #include <j2me/jdebug.h> |
|
35 |
|
36 /** This macro is executed each time a trapped call returns an error code different than KErrNone */ |
|
37 #undef TRAP_INSTRUMENTATION_LEAVE |
|
38 #define TRAP_INSTRUMENTATION_LEAVE(aResult) DEBUG_INT2("In CMIDTextFieldItem.cpp, trapped method was called at line %D and got exception %D", __LINE__, aResult); |
|
39 |
|
40 |
|
41 MMIDTextField* CMIDTextFieldItem::NewL( |
|
42 const TDesC& aLabel, const TDesC& aText, TInt aConstraints, |
|
43 TInt aMaxSize, CMIDUIManager* aUIManager) |
|
44 { |
|
45 CMIDTextFieldItem* textFieldItem = new(ELeave)CMIDTextFieldItem(aUIManager); |
|
46 CleanupStack::PushL(textFieldItem); |
|
47 textFieldItem->ConstructL(aLabel,aText,aConstraints,aMaxSize); |
|
48 CleanupStack::Pop(textFieldItem); |
|
49 return textFieldItem; |
|
50 } |
|
51 |
|
52 CMIDTextFieldItem::~CMIDTextFieldItem() |
|
53 { |
|
54 if (iText) |
|
55 { |
|
56 delete iText; |
|
57 iText = NULL; |
|
58 } |
|
59 if (iTextField) |
|
60 { |
|
61 delete iTextField; |
|
62 iTextField = NULL; |
|
63 } |
|
64 if (iDrawingModifier) |
|
65 { |
|
66 delete iDrawingModifier; |
|
67 iDrawingModifier = NULL; |
|
68 } |
|
69 } |
|
70 |
|
71 void CMIDTextFieldItem::DeleteTextL(TInt aOffset,TInt aLength) |
|
72 { |
|
73 TextComponent()->DeleteTextL(aOffset,aLength); |
|
74 } |
|
75 |
|
76 void CMIDTextFieldItem::SetTextL(const TDesC& aText) |
|
77 { |
|
78 ASSERT(iTextField); |
|
79 // Position of cursor is temporally set to start of text. |
|
80 // This is prevetion of panic caused cursor posited off rectagle of CMIDTextField. |
|
81 iTextField->SetCursorPosL(0, EFalse); |
|
82 iTextField->SetTextL(aText); |
|
83 // Setting position to right position. |
|
84 iTextField->SetCursorPosL(aText.Length(), EFalse); |
|
85 } |
|
86 |
|
87 void CMIDTextFieldItem::InsertTextL(const TDesC& aText,TInt aPosition) |
|
88 { |
|
89 TextComponent()->InsertTextL(aText,aPosition); |
|
90 } |
|
91 |
|
92 void CMIDTextFieldItem::SetConstraintsL(TUint aConstraints) |
|
93 { |
|
94 HBufC* text = iTextField->GetTextL(); |
|
95 CleanupStack::PushL(text); |
|
96 TInt maxSize = iTextField->GetMaxSize(); |
|
97 |
|
98 delete iTextField; |
|
99 iTextField = NULL; |
|
100 |
|
101 CreateTextFieldL(KNullDesC, aConstraints, maxSize); |
|
102 iTextField->SetTextWithNewConstraintsL(text); |
|
103 |
|
104 if (iForm && IsFocused()) |
|
105 {//in case non-midlet cmds have been added or removed |
|
106 iForm->CurrentDisplayable().InitializeCbasL(); |
|
107 } |
|
108 |
|
109 if (iForm) |
|
110 { |
|
111 // the newly created textbox needs to be layouted, request layout for the whole form |
|
112 // as applying new constraints may change the size of the textfield |
|
113 iForm->RequestLayoutL(); |
|
114 } |
|
115 |
|
116 CleanupStack::PopAndDestroy(text); |
|
117 } |
|
118 |
|
119 void CMIDTextFieldItem::CreateTextFieldL(const TDesC& aText, TUint aConstraints, TInt aMaxSize) |
|
120 { |
|
121 ASSERT(!iTextField); |
|
122 |
|
123 iTextField = CMIDTextFieldEdwin::NewL(aConstraints, aText, aMaxSize, NULL, this); |
|
124 iTextField->SetFocusing(ETrue); |
|
125 iTextField->SetEdwinSizeObserver(this); |
|
126 iTextField->SetEdwinObserver(this); |
|
127 |
|
128 // Get cursor position set by CMIDEdwin::NewL. This is needed since SetContainerWindowL |
|
129 // and ActivateL calls lead into cursor position resetting, i.e. setting it to 0 pos. |
|
130 TInt cursorPos = iTextField->CursorPos(); |
|
131 |
|
132 if (IsFocused()) |
|
133 { |
|
134 iTextField->SetFocus(ETrue); |
|
135 } |
|
136 |
|
137 if (DrawableWindow()) |
|
138 { |
|
139 // do not set container window if the fieldItem does not have CCoeControl::iWin set |
|
140 iTextField->SetContainerWindowL(*this); |
|
141 } |
|
142 |
|
143 if (IsActivated()) |
|
144 { |
|
145 iTextField->ActivateL(); |
|
146 } |
|
147 |
|
148 // Restore original cursor position |
|
149 iTextField->SetCursorPosL(cursorPos, EFalse); |
|
150 } |
|
151 |
|
152 void CMIDTextFieldItem::UpdateLayout() |
|
153 { |
|
154 TAknWindowComponentLayout textPaneLayout = |
|
155 AknLayoutScalable_Avkon::form2_midp_text_pane(0); |
|
156 |
|
157 TAknTextComponentLayout textLayout = |
|
158 AknLayoutScalable_Avkon::form2_mdip_text_pane_t1(0); |
|
159 |
|
160 // set the top margin for Edwin |
|
161 iEdwinMarginTop = textPaneLayout.LayoutLine().it; |
|
162 |
|
163 // set the minimum height of the Edwin (one line text) |
|
164 TAknTextDecorationMetrics decorationMetrics(textLayout.LayoutLine().iFont); |
|
165 TInt topMargin, bottomMargin; |
|
166 |
|
167 decorationMetrics.GetTopAndBottomMargins(topMargin, bottomMargin); |
|
168 |
|
169 iEdwinMinHeight = textPaneLayout.LayoutLine().iH + topMargin + bottomMargin; |
|
170 } |
|
171 |
|
172 |
|
173 TInt CMIDTextFieldItem::SetMaxSizeL(TInt aMaxSize) |
|
174 { |
|
175 return TextComponent()->SetMaxSizeL(aMaxSize); |
|
176 } |
|
177 |
|
178 TInt CMIDTextFieldItem::GetMaxSize() |
|
179 { |
|
180 return TextComponent()->GetMaxSize(); |
|
181 } |
|
182 |
|
183 TInt CMIDTextFieldItem::Size() |
|
184 { |
|
185 return TextComponent()->Size(); |
|
186 } |
|
187 |
|
188 TInt CMIDTextFieldItem::GetCaretPosition() |
|
189 { |
|
190 return TextComponent()->GetCaretPosition(); |
|
191 } |
|
192 |
|
193 HBufC* CMIDTextFieldItem::GetTextL() |
|
194 { |
|
195 return TextComponent()->GetTextL(); |
|
196 } |
|
197 |
|
198 void CMIDTextFieldItem::SetInitialInputModeL(const TDesC& aCharacterSubset) |
|
199 { |
|
200 TextComponent()->SetInitialInputModeL(aCharacterSubset); |
|
201 } |
|
202 |
|
203 // --------------------------------------------------------------------------- |
|
204 // |
|
205 // --------------------------------------------------------------------------- |
|
206 // |
|
207 CMIDTextFieldItem::CMIDTextFieldItem(CMIDUIManager* aUIManager) |
|
208 : CMIDControlItem(EDefault, aUIManager) |
|
209 { |
|
210 iMMidItem = this; |
|
211 SetFocusing(ETrue); |
|
212 } |
|
213 |
|
214 /** Construct the item. |
|
215 |
|
216 We chose to inhibit redrawing of the edwin on reformat, |
|
217 see CEikEdwin::OnReformatL() - this is called when laying-out the edwin. |
|
218 This is done via iDrawingModifier. This avoids drawing of edwin in the wrong |
|
219 position when modifying the form, or changing focus between items and resizing |
|
220 the item when inserting or removing a line. |
|
221 */ |
|
222 void CMIDTextFieldItem::ConstructL(const TDesC& aLabel,const TDesC& aText, |
|
223 TInt aConstraints, TInt aMaxSize) |
|
224 { |
|
225 CMIDControlItem::ConstructL(); |
|
226 |
|
227 TInt formWidth = FormClientAreaWidth(); |
|
228 SetSize(TSize(formWidth, 0)); |
|
229 |
|
230 SetLabelL(aLabel); |
|
231 iLabelControl->SetWidthL(formWidth); |
|
232 |
|
233 iDrawingModifier = new(ELeave)CAknEdwinDrawingModifier(); |
|
234 iDrawingModifier->SetInhibitNotifyNewFormatDrawing(ETrue); |
|
235 |
|
236 CreateTextFieldL(aText, aConstraints, aMaxSize); |
|
237 |
|
238 UpdateLayout(); |
|
239 } |
|
240 |
|
241 CMIDEdwin* CMIDTextFieldItem::TextComponent() const |
|
242 { |
|
243 return iTextField; |
|
244 } |
|
245 |
|
246 /** The minimum size is usually the full form width and the height of the label, plus |
|
247 the minimum height of the editor (usually one line) plus 3 times the vertical margin. */ |
|
248 TSize CMIDTextFieldItem::MinimumSize() |
|
249 { |
|
250 TInt minHeight = |
|
251 iEdwinMarginTop + |
|
252 iEdwinMinHeight + |
|
253 ItemContentBottomMargin(); |
|
254 |
|
255 if (iLabelControl && iLabelControl->Text()->Length()) |
|
256 minHeight += OneLineLabelHeight(); |
|
257 |
|
258 return TSize(FormClientAreaWidth(), minHeight); |
|
259 } |
|
260 |
|
261 TInt CMIDTextFieldItem::CountComponentControls() const |
|
262 { |
|
263 return 2; |
|
264 } |
|
265 |
|
266 CCoeControl* CMIDTextFieldItem::ComponentControl(TInt aIndex) const |
|
267 { |
|
268 switch (aIndex) |
|
269 { |
|
270 case 0: |
|
271 return iLabelControl; |
|
272 case 1: |
|
273 return iTextField; |
|
274 } |
|
275 return NULL; |
|
276 } |
|
277 |
|
278 void CMIDTextFieldItem::Draw(const TRect& aRect) const |
|
279 { |
|
280 CMIDControlItem::Draw(aRect); |
|
281 } |
|
282 |
|
283 void CMIDTextFieldItem::SizeChanged() |
|
284 { |
|
285 TPoint position = Position(); |
|
286 |
|
287 TRect labelRect(position, TSize(FormClientAreaWidth(), LabelHeight())); |
|
288 |
|
289 TPoint textTl = TPoint(position.iX, |
|
290 LabelHeight() > 0 ? labelRect.iBr.iY : position.iY); |
|
291 TPoint textBr = Rect().iBr - TPoint(0, ItemContentBottomMargin()); |
|
292 |
|
293 TRect textRect(textTl, textBr); |
|
294 |
|
295 if (LabelHeight() > 0) |
|
296 { |
|
297 iLabelControl->SetRect(labelRect); |
|
298 } |
|
299 |
|
300 if (iTextField) |
|
301 { |
|
302 iTextField->DoLayout(textRect); |
|
303 } |
|
304 |
|
305 CMIDControlItem::SizeChanged(); |
|
306 } |
|
307 |
|
308 void CMIDTextFieldItem::SetContainerWindowL(const CCoeControl& aContainer) |
|
309 { |
|
310 CMIDControlItem::SetContainerWindowL(aContainer); |
|
311 |
|
312 // Save the original cursor position. This is needed since SetContainerWindowL |
|
313 // and ActivateL call lead into cursor position resetting, i.e. setting it to 0 pos. |
|
314 TInt cursorPos = iTextField->CursorPos(); |
|
315 |
|
316 iTextField->SetContainerWindowL(*this); |
|
317 |
|
318 SetObserver(iForm); |
|
319 |
|
320 ActivateL(); |
|
321 |
|
322 // Restore original cursor position |
|
323 iTextField->SetCursorPosL(cursorPos, EFalse); |
|
324 |
|
325 } |
|
326 |
|
327 void CMIDTextFieldItem::FocusChanged(TDrawNow aDrawNow) |
|
328 { |
|
329 if (IsFocused()) |
|
330 { |
|
331 // Setting focus to iTextField changes the cursor visibility. This might cause |
|
332 // a cursor flashing on the screen, if the focus is set to a TF that is not in the |
|
333 // visible form area currently when a form is switched from background |
|
334 // to foreground. To prevent this EAvkonDisableCursor is set temporarily. |
|
335 iTextField->AddFlagToUserFlags(CEikEdwin::EAvkonDisableCursor); |
|
336 iTextField->SetFocus(ETrue); |
|
337 iTextField->RemoveFlagFromUserFlags(CEikEdwin::EAvkonDisableCursor); |
|
338 SetCursorVisibility(IsVisible()); |
|
339 } |
|
340 else |
|
341 { |
|
342 iTextField->SetFocus(EFalse); |
|
343 } |
|
344 |
|
345 CMIDControlItem::FocusChanged(aDrawNow); |
|
346 // DoLayout and change text color when focused |
|
347 SizeChanged(); |
|
348 TRAP_IGNORE(UpdateTextColorsL()); |
|
349 } |
|
350 |
|
351 void CMIDTextFieldItem::HandleCurrentL(TBool aCurrent) |
|
352 { |
|
353 // set initial input modes when TextField becomes the focused item |
|
354 iTextField->HandleCurrentL(aCurrent); |
|
355 } |
|
356 |
|
357 void CMIDTextFieldItem::ResolutionChange(TInt /*aType*/) |
|
358 { |
|
359 UpdateLayout(); |
|
360 } |
|
361 |
|
362 void CMIDTextFieldItem::PostFocusTransferEvent(TBool aFocus, CMIDForm::TDirection /*aDirection*/) |
|
363 { |
|
364 TRAP_IGNORE(HandleCurrentL(aFocus)); |
|
365 } |
|
366 |
|
367 /** Basically pass the key event to the text box. Also check if the text has been |
|
368 modified and if so report an item state change event. Attention must be taken here |
|
369 because the text box may eat the EEventKey type so we must store the existing text |
|
370 in the key down event and compare it in the key up event. */ |
|
371 TKeyResponse CMIDTextFieldItem::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType) |
|
372 { |
|
373 |
|
374 if (aType == EEventKeyDown) |
|
375 { |
|
376 delete iText; |
|
377 iText = NULL; |
|
378 |
|
379 iText = iTextField->GetTextInHBufL(); |
|
380 } |
|
381 return iTextField->OfferKeyEventL(aKeyEvent, aType); |
|
382 } |
|
383 |
|
384 #ifdef RD_SCALABLE_UI_V2 |
|
385 void CMIDTextFieldItem::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
|
386 { |
|
387 if (AknLayoutUtils::PenEnabled()) |
|
388 { |
|
389 if (!iForm->PhysicsScrolling()) |
|
390 { |
|
391 SetCursorVisibility(ETrue); |
|
392 } |
|
393 |
|
394 //update focus |
|
395 if (!iForm->TryDetectLongTapL(aPointerEvent)) |
|
396 { |
|
397 #ifdef RD_JAVA_S60_RELEASE_9_2 |
|
398 // In single click UI VKB is opened with first tap. |
|
399 if (!iForm->PhysicsScrolling()) |
|
400 #else |
|
401 // In non-single click UI, |
|
402 // VKB is opened when tapping already focused item. |
|
403 if (!iForm->IsFocusChangingWithPen() && IsFocused() && !iForm->PhysicsScrolling()) |
|
404 #endif // RD_JAVA_S60_RELEASE_9_2 |
|
405 { |
|
406 TPointerEvent pEvent = aPointerEvent; |
|
407 // If label area is tapped the coordinates are transferred to editor area. |
|
408 // By doing coordinate switching VKB is launched also when label is tapped. |
|
409 if (iLabelControl->Rect().Contains(pEvent.iPosition)) |
|
410 { |
|
411 pEvent.iPosition.iY = iTextField->Rect().iTl.iY; |
|
412 } |
|
413 CCoeControl::HandlePointerEventL(pEvent); |
|
414 } |
|
415 //else do not forward pointer event to CCoeControl as do not want to have any action |
|
416 //on unfocused TextField. |
|
417 } |
|
418 } |
|
419 } |
|
420 #endif // RD_SCALABLE_UI_V2 |
|
421 |
|
422 void CMIDTextFieldItem::MakeVisible(TBool aVisible) |
|
423 { |
|
424 CMIDControlItem::MakeVisible(aVisible); |
|
425 SetCursorVisibility(aVisible); |
|
426 } |
|
427 |
|
428 TSize CMIDTextFieldItem::ResetPreferredSize() const |
|
429 { |
|
430 CMIDTextFieldItem* self = const_cast<CMIDTextFieldItem*>(this); |
|
431 TRAP_IGNORE(self->SetPreferredSizeL(iRequestedPreferredSize)); |
|
432 return iPreferredSize; |
|
433 } |
|
434 |
|
435 /** This is called before the form is re-laid-out. See ResetPreferredSize(). |
|
436 If we have a requested height we select the max between this height and our |
|
437 minimum height. The width is always the form or screen width. Then we do layout. |
|
438 |
|
439 If we don't have a requested height, we do layout with a negative height |
|
440 (-1) and this signals to CMIDEdwin to use whatever height correcsponds to the |
|
441 number of formatted lines. See CMIDEdwin::DoLayout(). So, in this case iPreferredSize |
|
442 is set after doing layout. |
|
443 |
|
444 The editor can be resized in HandleEdwinSizeEventL() only if the preferred height has |
|
445 not been given. |
|
446 |
|
447 @note SetPreferredSize() always sets TextField's preferred size |
|
448 (i.e. how much space it needs so all control (label+text) is visible) |
|
449 */ |
|
450 void CMIDTextFieldItem::SetPreferredSizeL(const TSize& aSize) |
|
451 { |
|
452 if (!iTextField) |
|
453 return; |
|
454 |
|
455 iRequestedPreferredSize = CheckRequestedSize(aSize); |
|
456 iPreferredSize = iRequestedPreferredSize; |
|
457 |
|
458 iPreferredSize.iWidth = FormClientAreaWidth(); //This is our fixed width, no less, no more |
|
459 |
|
460 TSize editorSize(iPreferredSize); |
|
461 |
|
462 // calculate the preferred size case |
|
463 TRect rect(TPoint(0,0), editorSize); |
|
464 iTextField->DoLayout(rect); |
|
465 |
|
466 iPreferredSize.iHeight = LabelHeight() + ItemPreferredHeightWithoutLabel(); |
|
467 } |
|
468 |
|
469 TInt CMIDTextFieldItem::ItemPreferredHeightWithoutLabel() |
|
470 { |
|
471 TInt height = ((CCoeControl*)iTextField)->Size().iHeight + |
|
472 iEdwinMarginTop + ItemContentBottomMargin(); |
|
473 |
|
474 return height; |
|
475 } |
|
476 |
|
477 TRect CMIDTextFieldItem::FocusableRect() |
|
478 { |
|
479 return iTextField->Rect(); |
|
480 } |
|
481 |
|
482 /** We set the new height of the textbox and form item by calling SetSize(). If we |
|
483 are inside a form (which we most likely are) we then call CMIDForm::RefreshItemL(this). |
|
484 This will take care of re-positioning all other items and updating the scroll bars. |
|
485 |
|
486 We will not resize the editor if the use has specified a preferrred height |
|
487 (iRequestedPreferredSize.iHeight) in which case the editor must be either this height |
|
488 or the minimum height. Also, if iPreferredSize.iHeight is -1, it means we are inside |
|
489 a SetPreferredSizeL() call, so we mustn't call iForm->RequestLayoutL() because this |
|
490 method ends up calling SetPreferredSizeL() and so we end up in infinite recursive calls. |
|
491 So iPreferredSize.iHeight == -1 means do not do anything basically. */ |
|
492 TBool CMIDTextFieldItem::HandleEdwinSizeEventL(CEikEdwin* /*aEdwin*/, |
|
493 TEdwinSizeEvent /*aEventType*/, TSize aDesirableEdwinSize) |
|
494 { |
|
495 if (iTextField->IsPartialFormatting()) |
|
496 { |
|
497 // ignore the asynchronous HandleEdwinSizeEvents (e.g TextLength() > 1900 chars) |
|
498 // that will occur much later when Edwin finishes formatting. |
|
499 // This is a protection against requesting form layout while form might be scrolling. |
|
500 // In this partial formatting mode, the preferred size reflects only those number of lines |
|
501 // that were reformatted when quering for the preferred size. |
|
502 // This way, TextFieldItem will continue to have the preferred size (which does not show all visible lines). |
|
503 |
|
504 return EFalse; |
|
505 } |
|
506 |
|
507 if (iPreferredSize.iHeight != -1) |
|
508 { |
|
509 TInt desiredHeight = |
|
510 LabelHeight() + |
|
511 iEdwinMarginTop + |
|
512 aDesirableEdwinSize.iHeight + |
|
513 ItemContentBottomMargin(); |
|
514 |
|
515 if (iPreferredSize.iHeight != desiredHeight) |
|
516 { |
|
517 if (iForm) |
|
518 {//new layout for form, hence new edwin size will be taken into account |
|
519 iForm->RequestLayoutL(ETrue); |
|
520 } |
|
521 } |
|
522 } |
|
523 |
|
524 return EFalse; |
|
525 } |
|
526 |
|
527 |
|
528 TTypeUid::Ptr CMIDTextFieldItem::MopSupplyObject(TTypeUid aId) |
|
529 { |
|
530 // Return the edwin drawing modifier, CAknEdwinDrawingModifier, if ID matches, see |
|
531 // HandleEdwinSizeEventL(). Otherwise call CMIDControlItem::MopSupplyObject(). |
|
532 if (aId.iUid == CAknEdwinDrawingModifier::ETypeId) |
|
533 return aId.MakePtr(iDrawingModifier); |
|
534 |
|
535 return CMIDControlItem::MopSupplyObject(aId); |
|
536 } |
|
537 |
|
538 void CMIDTextFieldItem::HandleEdwinEventL(CEikEdwin* /*aEdwin*/,TEdwinEvent /*aEventType*/) |
|
539 { |
|
540 DoHandleEdwinEventL(); |
|
541 } |
|
542 |
|
543 void CMIDTextFieldItem::HandleControlEventL(CCoeControl* /*aSource*/, |
|
544 MCoeControlObserver::TCoeEvent aEventType) |
|
545 { |
|
546 if (aEventType == MCoeControlObserver::EEventStateChanged) |
|
547 { |
|
548 DoHandleEdwinEventL(); |
|
549 |
|
550 // check if text has changed and eventually notify Java via |
|
551 // itemStateChanged() |
|
552 HBufC* newText = iTextField->GetTextInHBufL(); |
|
553 TBool textChanged = EFalse; |
|
554 |
|
555 if ((!iText && newText) || (iText && !newText) || |
|
556 (iText && newText && (*iText != *newText))) |
|
557 { |
|
558 textChanged = ETrue; |
|
559 } |
|
560 |
|
561 delete iText; |
|
562 iText = newText; |
|
563 |
|
564 if (textChanged) |
|
565 { |
|
566 ReportEventL(MCoeControlObserver::EEventStateChanged); |
|
567 } |
|
568 } |
|
569 else if (aEventType == MCoeControlObserver::EEventRequestFocus) |
|
570 { |
|
571 static_cast<MCoeControlObserver*>(iForm)->HandleControlEventL(this, aEventType); |
|
572 } |
|
573 } |
|
574 |
|
575 void CMIDTextFieldItem::DoHandleEdwinEventL() |
|
576 { |
|
577 TPoint point; |
|
578 TBool success = GetCursorPosL(point); |
|
579 if (success && iForm) |
|
580 { |
|
581 if (point.iY < 0) |
|
582 { |
|
583 iForm->ScrollRelative(-(point.iY - 10)); |
|
584 iForm->UpdatePhysics(); |
|
585 } |
|
586 else if (point.iY >= iForm->Height()) |
|
587 { |
|
588 iForm->ScrollRelative((iForm->Height() - point.iY) - 10); |
|
589 iForm->UpdatePhysics(); |
|
590 } |
|
591 } |
|
592 } |
|
593 |
|
594 TBool CMIDTextFieldItem::GetCursorPosL(TPoint& aPoint) |
|
595 { |
|
596 TInt pos = iTextField->CursorPos(); |
|
597 CTextView* tv = iTextField->TextView(); |
|
598 return tv->DocPosToXyPosL(pos, aPoint); |
|
599 } |
|
600 |
|
601 void CMIDTextFieldItem::SetLabelL(const TDesC& aLabel) |
|
602 { |
|
603 CMIDControlItem::SetLabelL(aLabel); |
|
604 } |
|
605 |
|
606 void CMIDTextFieldItem::Dispose() |
|
607 { |
|
608 delete this; |
|
609 } |
|
610 |
|
611 void CMIDTextFieldItem::SetLayoutL(TLayout aLayout) |
|
612 { |
|
613 CMIDItem::SetLayoutL(aLayout); |
|
614 } |
|
615 |
|
616 void CMIDTextFieldItem::AddCommandL(MMIDCommand* aCommand) |
|
617 { |
|
618 CMIDItem::AddCommandL(aCommand); |
|
619 } |
|
620 |
|
621 void CMIDTextFieldItem::RemoveCommand(MMIDCommand* aCommand) |
|
622 { |
|
623 CMIDItem::RemoveCommand(aCommand); |
|
624 } |
|
625 |
|
626 void CMIDTextFieldItem::SetDefaultCommand(MMIDCommand* aCommand) |
|
627 { |
|
628 CMIDItem::SetDefaultCommand(aCommand); |
|
629 } |
|
630 |
|
631 TSize CMIDTextFieldItem::PreferredSize() const |
|
632 { |
|
633 return iPreferredSize; |
|
634 } |
|
635 |
|
636 TSize CMIDTextFieldItem::MinimumSize() const |
|
637 { |
|
638 CCoeControl* control = const_cast<CMIDTextFieldItem*>(this); |
|
639 return control->MinimumSize(); |
|
640 } |
|
641 |
|
642 TCoeInputCapabilities CMIDTextFieldItem::InputCapabilities() const |
|
643 { |
|
644 TCoeInputCapabilities inputCapabilities(TCoeInputCapabilities::ENone, NULL, |
|
645 const_cast<CMIDTextFieldItem*>(this)); |
|
646 inputCapabilities.MergeWith(iTextField->InputCapabilities()); |
|
647 return inputCapabilities; |
|
648 } |
|
649 |
|
650 void CMIDTextFieldItem::RestoreInnerFocus() |
|
651 { |
|
652 // Restore active textfield line (with cursor) on screen by resetting |
|
653 // the text selection and the cursor position |
|
654 if (iTextField) |
|
655 { |
|
656 TCursorSelection sel = iTextField->Selection(); |
|
657 // Exceptions can be ignored, because failing of SetSelectionL may cause |
|
658 // only a cosmetic visual problems |
|
659 TRAP_IGNORE(iTextField->SetSelectionL(sel.iCursorPos, sel.iAnchorPos)); |
|
660 } |
|
661 } |
|
662 |
|
663 void CMIDTextFieldItem::SetCursorVisibility(TBool aVisible) |
|
664 { |
|
665 if (IsFocused()) |
|
666 { |
|
667 TCursor::TVisibility textCursor = |
|
668 aVisible ? TCursor::EFCursorFlashing : TCursor::EFCursorInvisible; |
|
669 |
|
670 // lineCursor is not used in TextField, so it is set to TCursor::EFCursorInvisible always |
|
671 TRAP_IGNORE(iTextField->TextView()->SetCursorVisibilityL(TCursor::EFCursorInvisible, |
|
672 textCursor)); |
|
673 } |
|
674 } |
|
675 |
|
676 void CMIDTextFieldItem::UpdateTextColorsL() |
|
677 { |
|
678 if (iTextField) |
|
679 { |
|
680 if (iHighlighted) |
|
681 { |
|
682 // Text colour from skin - highlighted |
|
683 iTextField->SetTextSkinColorIdL(EAknsCIQsnTextColorsCG8); |
|
684 } |
|
685 else |
|
686 { |
|
687 // Text colour from skin - unfocused |
|
688 iTextField->SetTextSkinColorIdL(EAknsCIQsnTextColorsCG6); |
|
689 } |
|
690 } |
|
691 } |