javauis/lcdui_akn/lcdui/src/CMIDTextFieldItem.cpp
branchRCL_3
changeset 14 04becd199f91
child 19 71c436fe3ce0
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     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 }
       
   347 
       
   348 void CMIDTextFieldItem::HandleCurrentL(TBool aCurrent)
       
   349 {
       
   350     // set initial input modes when TextField becomes the focused item
       
   351     iTextField->HandleCurrentL(aCurrent);
       
   352 }
       
   353 
       
   354 void CMIDTextFieldItem::ResolutionChange(TInt /*aType*/)
       
   355 {
       
   356     UpdateLayout();
       
   357 }
       
   358 
       
   359 void CMIDTextFieldItem::PostFocusTransferEvent(TBool aFocus, CMIDForm::TDirection /*aDirection*/)
       
   360 {
       
   361     TRAP_IGNORE(HandleCurrentL(aFocus));
       
   362 }
       
   363 
       
   364 /** Basically pass the key event to the text box. Also check if the text has been
       
   365 modified and if so report an item state change event. Attention must be taken here
       
   366 because the text box may eat the EEventKey type so we must store the existing text
       
   367 in the key down event and compare it in the key up event. */
       
   368 TKeyResponse CMIDTextFieldItem::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
       
   369 {
       
   370 
       
   371     if (aType == EEventKeyDown)
       
   372     {
       
   373         delete iText;
       
   374         iText = NULL;
       
   375 
       
   376         iText = iTextField->GetTextInHBufL();
       
   377     }
       
   378     return iTextField->OfferKeyEventL(aKeyEvent, aType);
       
   379 }
       
   380 
       
   381 #ifdef RD_SCALABLE_UI_V2
       
   382 void CMIDTextFieldItem::HandlePointerEventL(const TPointerEvent& aPointerEvent)
       
   383 {
       
   384     if (AknLayoutUtils::PenEnabled())
       
   385     {
       
   386         if (!iForm->PhysicsScrolling())
       
   387         {
       
   388             SetCursorVisibility(ETrue);
       
   389         }
       
   390 
       
   391         //update focus
       
   392         if (!iForm->TryDetectLongTapL(aPointerEvent))
       
   393         {
       
   394 #ifdef RD_JAVA_S60_RELEASE_9_2
       
   395             // In single click UI VKB is opened with first tap.
       
   396             if (!iForm->PhysicsScrolling())
       
   397 #else
       
   398             // In non-single click UI,
       
   399             // VKB is opened when tapping already focused item.
       
   400             if (!iForm->IsFocusChangingWithPen() && IsFocused() && !iForm->PhysicsScrolling())
       
   401 #endif // RD_JAVA_S60_RELEASE_9_2
       
   402             {
       
   403                 TPointerEvent pEvent = aPointerEvent;
       
   404                 // If label area is tapped the coordinates are transferred to editor area.
       
   405                 // By doing coordinate switching VKB is launched also when label is tapped.
       
   406                 if (iLabelControl->Rect().Contains(pEvent.iPosition))
       
   407                 {
       
   408                     pEvent.iPosition.iY = iTextField->Rect().iTl.iY;
       
   409                 }
       
   410                 CCoeControl::HandlePointerEventL(pEvent);
       
   411             }
       
   412             //else do not forward pointer event to CCoeControl as do not want to have any action
       
   413             //on unfocused TextField.
       
   414         }
       
   415     }
       
   416 }
       
   417 #endif // RD_SCALABLE_UI_V2
       
   418 
       
   419 void CMIDTextFieldItem::MakeVisible(TBool aVisible)
       
   420 {
       
   421     CMIDControlItem::MakeVisible(aVisible);
       
   422     SetCursorVisibility(aVisible);
       
   423 }
       
   424 
       
   425 TSize CMIDTextFieldItem::ResetPreferredSize() const
       
   426 {
       
   427     CMIDTextFieldItem* self = const_cast<CMIDTextFieldItem*>(this);
       
   428     TRAP_IGNORE(self->SetPreferredSizeL(iRequestedPreferredSize));
       
   429     return iPreferredSize;
       
   430 }
       
   431 
       
   432 /** This is called before the form is re-laid-out. See ResetPreferredSize().
       
   433     If we have a requested height we select the max between this height and our
       
   434     minimum height. The width is always the form or screen width. Then we do layout.
       
   435 
       
   436     If we don't have a requested height, we do layout with a negative height
       
   437     (-1) and this signals to CMIDEdwin to use whatever height correcsponds to the
       
   438     number of formatted lines. See CMIDEdwin::DoLayout(). So, in this case iPreferredSize
       
   439     is set after doing layout.
       
   440 
       
   441     The editor can be resized in HandleEdwinSizeEventL() only if the preferred height has
       
   442     not been given.
       
   443 
       
   444     @note SetPreferredSize() always sets TextField's preferred size
       
   445     (i.e. how much space it needs so all control (label+text) is visible)
       
   446 */
       
   447 void CMIDTextFieldItem::SetPreferredSizeL(const TSize& aSize)
       
   448 {
       
   449     if (!iTextField)
       
   450         return;
       
   451 
       
   452     iRequestedPreferredSize = CheckRequestedSize(aSize);
       
   453     iPreferredSize = iRequestedPreferredSize;
       
   454 
       
   455     iPreferredSize.iWidth = FormClientAreaWidth(); //This is our fixed width, no less, no more
       
   456 
       
   457     TSize editorSize(iPreferredSize);
       
   458 
       
   459     // calculate the preferred size case
       
   460     TRect rect(TPoint(0,0), editorSize);
       
   461     iTextField->DoLayout(rect);
       
   462 
       
   463     iPreferredSize.iHeight = LabelHeight() + ItemPreferredHeightWithoutLabel();
       
   464 }
       
   465 
       
   466 TInt CMIDTextFieldItem::ItemPreferredHeightWithoutLabel()
       
   467 {
       
   468     TInt height = ((CCoeControl*)iTextField)->Size().iHeight +
       
   469                   iEdwinMarginTop + ItemContentBottomMargin();
       
   470 
       
   471     return height;
       
   472 }
       
   473 
       
   474 TRect CMIDTextFieldItem::FocusableRect()
       
   475 {
       
   476     return iTextField->Rect();
       
   477 }
       
   478 
       
   479 /** We set the new height of the textbox and form item by calling SetSize(). If we
       
   480 are inside a form (which we most likely are) we then call CMIDForm::RefreshItemL(this).
       
   481 This will take care of re-positioning all other items and updating the scroll bars.
       
   482 
       
   483 We will not resize the editor if the use has specified a preferrred height
       
   484 (iRequestedPreferredSize.iHeight) in which case the editor must be either this height
       
   485 or the minimum height. Also, if iPreferredSize.iHeight is -1, it means we are inside
       
   486 a SetPreferredSizeL() call, so we mustn't call  iForm->RequestLayoutL() because this
       
   487 method ends up calling SetPreferredSizeL() and so we end up in infinite recursive calls.
       
   488 So iPreferredSize.iHeight == -1 means do not do anything basically. */
       
   489 TBool CMIDTextFieldItem::HandleEdwinSizeEventL(CEikEdwin* /*aEdwin*/,
       
   490         TEdwinSizeEvent /*aEventType*/, TSize aDesirableEdwinSize)
       
   491 {
       
   492     if (iTextField->IsPartialFormatting())
       
   493     {
       
   494         // ignore the asynchronous HandleEdwinSizeEvents (e.g TextLength() > 1900 chars)
       
   495         // that will occur much later when Edwin finishes formatting.
       
   496         // This is a protection against requesting form layout while form might be scrolling.
       
   497         // In this partial formatting mode, the preferred size reflects only those number of lines
       
   498         // that were reformatted when quering for the preferred size.
       
   499         // This way, TextFieldItem will continue to have the preferred size (which does not show all visible lines).
       
   500 
       
   501         return EFalse;
       
   502     }
       
   503 
       
   504     if (iPreferredSize.iHeight != -1)
       
   505     {
       
   506         TInt desiredHeight =
       
   507             LabelHeight() +
       
   508             iEdwinMarginTop +
       
   509             aDesirableEdwinSize.iHeight +
       
   510             ItemContentBottomMargin();
       
   511 
       
   512         if (iPreferredSize.iHeight != desiredHeight)
       
   513         {
       
   514             if (iForm)
       
   515             {//new layout for form, hence new edwin size will be taken into account
       
   516                 iForm->RequestLayoutL(ETrue);
       
   517             }
       
   518         }
       
   519     }
       
   520 
       
   521     return EFalse;
       
   522 }
       
   523 
       
   524 
       
   525 TTypeUid::Ptr CMIDTextFieldItem::MopSupplyObject(TTypeUid aId)
       
   526 {
       
   527     // Return the edwin drawing modifier, CAknEdwinDrawingModifier, if ID matches, see
       
   528     // HandleEdwinSizeEventL(). Otherwise call CMIDControlItem::MopSupplyObject().
       
   529     if (aId.iUid == CAknEdwinDrawingModifier::ETypeId)
       
   530         return aId.MakePtr(iDrawingModifier);
       
   531 
       
   532     return CMIDControlItem::MopSupplyObject(aId);
       
   533 }
       
   534 
       
   535 void CMIDTextFieldItem::HandleEdwinEventL(CEikEdwin* /*aEdwin*/,TEdwinEvent /*aEventType*/)
       
   536 {
       
   537     DoHandleEdwinEventL();
       
   538 }
       
   539 
       
   540 void CMIDTextFieldItem::HandleControlEventL(CCoeControl* /*aSource*/,
       
   541         MCoeControlObserver::TCoeEvent aEventType)
       
   542 {
       
   543     if (aEventType == MCoeControlObserver::EEventStateChanged)
       
   544     {
       
   545         DoHandleEdwinEventL();
       
   546 
       
   547         // check if text has changed and eventually notify Java via
       
   548         // itemStateChanged()
       
   549         HBufC* newText = iTextField->GetTextInHBufL();
       
   550         TBool textChanged = EFalse;
       
   551 
       
   552         if ((!iText && newText) || (iText && !newText) ||
       
   553                 (iText && newText && (*iText != *newText)))
       
   554         {
       
   555             textChanged = ETrue;
       
   556         }
       
   557 
       
   558         delete iText;
       
   559         iText = newText;
       
   560 
       
   561         if (textChanged)
       
   562         {
       
   563             ReportEventL(MCoeControlObserver::EEventStateChanged);
       
   564         }
       
   565     }
       
   566     else if (aEventType == MCoeControlObserver::EEventRequestFocus)
       
   567     {
       
   568         static_cast<MCoeControlObserver*>(iForm)->HandleControlEventL(this, aEventType);
       
   569     }
       
   570 }
       
   571 
       
   572 void CMIDTextFieldItem::DoHandleEdwinEventL()
       
   573 {
       
   574     TPoint point;
       
   575     TBool success = GetCursorPosL(point);
       
   576     if (success && iForm)
       
   577     {
       
   578         if (point.iY < 0)
       
   579         {
       
   580             iForm->ScrollRelative(-(point.iY - 10));
       
   581             iForm->UpdatePhysics();
       
   582         }
       
   583         else if (point.iY >= iForm->Height())
       
   584         {
       
   585             iForm->ScrollRelative((iForm->Height() - point.iY) - 10);
       
   586             iForm->UpdatePhysics();
       
   587         }
       
   588     }
       
   589 }
       
   590 
       
   591 TBool CMIDTextFieldItem::GetCursorPosL(TPoint& aPoint)
       
   592 {
       
   593     TInt pos = iTextField->CursorPos();
       
   594     CTextView* tv = iTextField->TextView();
       
   595     return tv->DocPosToXyPosL(pos, aPoint);
       
   596 }
       
   597 
       
   598 void CMIDTextFieldItem::SetLabelL(const TDesC& aLabel)
       
   599 {
       
   600     CMIDControlItem::SetLabelL(aLabel);
       
   601 }
       
   602 
       
   603 void CMIDTextFieldItem::Dispose()
       
   604 {
       
   605     delete this;
       
   606 }
       
   607 
       
   608 void CMIDTextFieldItem::SetLayoutL(TLayout aLayout)
       
   609 {
       
   610     CMIDItem::SetLayoutL(aLayout);
       
   611 }
       
   612 
       
   613 void CMIDTextFieldItem::AddCommandL(MMIDCommand* aCommand)
       
   614 {
       
   615     CMIDItem::AddCommandL(aCommand);
       
   616 }
       
   617 
       
   618 void CMIDTextFieldItem::RemoveCommand(MMIDCommand* aCommand)
       
   619 {
       
   620     CMIDItem::RemoveCommand(aCommand);
       
   621 }
       
   622 
       
   623 void CMIDTextFieldItem::SetDefaultCommand(MMIDCommand* aCommand)
       
   624 {
       
   625     CMIDItem::SetDefaultCommand(aCommand);
       
   626 }
       
   627 
       
   628 TSize CMIDTextFieldItem::PreferredSize() const
       
   629 {
       
   630     return iPreferredSize;
       
   631 }
       
   632 
       
   633 TSize CMIDTextFieldItem::MinimumSize() const
       
   634 {
       
   635     CCoeControl* control = const_cast<CMIDTextFieldItem*>(this);
       
   636     return control->MinimumSize();
       
   637 }
       
   638 
       
   639 TCoeInputCapabilities CMIDTextFieldItem::InputCapabilities() const
       
   640 {
       
   641     TCoeInputCapabilities inputCapabilities(TCoeInputCapabilities::ENone, NULL,
       
   642                                             const_cast<CMIDTextFieldItem*>(this));
       
   643     inputCapabilities.MergeWith(iTextField->InputCapabilities());
       
   644     return inputCapabilities;
       
   645 }
       
   646 
       
   647 void CMIDTextFieldItem::RestoreInnerFocus()
       
   648 {
       
   649     // Restore active textfield line (with cursor) on screen by resetting
       
   650     // the text selection and the cursor position
       
   651     if (iTextField)
       
   652     {
       
   653         TCursorSelection sel = iTextField->Selection();
       
   654         // Exceptions can be ignored, because failing of SetSelectionL may cause
       
   655         // only a cosmetic visual problems
       
   656         TRAP_IGNORE(iTextField->SetSelectionL(sel.iCursorPos, sel.iAnchorPos));
       
   657     }
       
   658 }
       
   659 
       
   660 void CMIDTextFieldItem::SetCursorVisibility(TBool aVisible)
       
   661 {
       
   662     if (IsFocused())
       
   663     {
       
   664         TCursor::TVisibility textCursor =
       
   665             aVisible ? TCursor::EFCursorFlashing : TCursor::EFCursorInvisible;
       
   666 
       
   667         // lineCursor is not used in TextField, so it is set to TCursor::EFCursorInvisible always
       
   668         TRAP_IGNORE(iTextField->TextView()->SetCursorVisibilityL(TCursor::EFCursorInvisible,
       
   669                     textCursor));
       
   670     }
       
   671 }
       
   672