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