javauis/lcdui_akn/lcdui/src/CMIDTextBoxQueryDialog.cpp
branchRCL_3
changeset 19 04becd199f91
child 23 98ccebc37403
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Popu-up TextBox dialog implementation for S60
       
    15 *
       
    16 */
       
    17 
       
    18 #include <eikenv.h>
       
    19 #include "CMIDTextBoxQueryDialog.h"
       
    20 
       
    21 #include "lcdui.hrh"
       
    22 #include <lcdui.rsg>
       
    23 #include <EIKCOCTL.rsg>
       
    24 
       
    25 #include "CMIDEdwinUtils.h"
       
    26 
       
    27 #include <eikcapc.h>
       
    28 #include <avkon.rsg>
       
    29 #include <avkon.hrh>
       
    30 
       
    31 #include <aknenv.h>
       
    32 #include <AknSettingCache.h>
       
    33 
       
    34 // FEP CR
       
    35 // constants for FEP
       
    36 #include <AknFepInternalCRKeys.h>
       
    37 #include <centralrepository.h>
       
    38 
       
    39 // CAknExtendedInputCapabilities for extended input capabilities
       
    40 #include <aknextendedinputcapabilities.h>
       
    41 
       
    42 // sound files
       
    43 #include <aknappui.h>
       
    44 #include <aknsoundsystem.h>
       
    45 
       
    46 // aiw used to invoke phonebook
       
    47 #include <AiwContactSelectionDataTypes.h>
       
    48 // phone client API classes for starting phone call
       
    49 #include <AiwCommon.h>
       
    50 #include <aiwdialdata.h>
       
    51 #include <aiwdialdataext.h>
       
    52 
       
    53 
       
    54 #include <j2me/jdebug.h>
       
    55 
       
    56 CMIDTextBoxQueryDialog* CMIDTextBoxQueryDialog::NewLC(TInt aConstraints,
       
    57         TDes& aResult,
       
    58         TInt aMaxSize,
       
    59         CMIDDisplayable* aDisplayable,
       
    60         const TDesC& aText)
       
    61 {
       
    62     CMIDTextBoxQueryDialog* self = new(ELeave) CMIDTextBoxQueryDialog(aResult);
       
    63     CleanupStack::PushL(self);
       
    64     self->ConstructL(aConstraints, aMaxSize, aDisplayable, aText);
       
    65     return self;
       
    66 }
       
    67 
       
    68 CMIDTextBoxQueryDialog::~CMIDTextBoxQueryDialog()
       
    69 {
       
    70     delete iAiwPbkClient;
       
    71     delete iEdwinUtils;
       
    72     RemoveNonMidletCommands();
       
    73 }
       
    74 
       
    75 void CMIDTextBoxQueryDialog::ConstructL(TInt aConstraints,
       
    76                                         TInt aMaxSize,
       
    77                                         CMIDDisplayable* aDisplayable,
       
    78                                         const TDesC& aText)
       
    79 {
       
    80     TLocale loc;
       
    81     iDecimalSeparator = loc.DecimalSeparator();
       
    82     if (iDecimalSeparator != ',')
       
    83     {
       
    84         iDecimalSeparator = '.';
       
    85     }
       
    86 
       
    87     iEdwinUtils = CMIDEdwinUtils::NewL(this, iDecimalSeparator);
       
    88 
       
    89     iConstraints = aConstraints;
       
    90 
       
    91     // if text is invalid according to constraints, throw IllegalArgumentException,
       
    92     // except for a PHONENUMBER which only has the invalid characters removed
       
    93     if ((iConstraints & MMIDTextField::EConstraintMask) != MMIDTextField::EPhoneNumber
       
    94             && !iEdwinUtils->ConstraintsValidForText(aText,iConstraints,ETrue))
       
    95     {
       
    96         User::Leave(KErrArgument);
       
    97     }
       
    98 
       
    99     iMaxSize = aMaxSize;
       
   100     iDisplayable = aDisplayable;
       
   101 
       
   102     // This is aprotected method call must be inside the class itself.
       
   103     // ConstructSleepingDialogL is replacing the call of ReadResourceLC
       
   104     // in CMIDTextBoxDialogControl::CreateTextBoxQueryDialogL
       
   105     ConstructSleepingDialogL(R_MIDP_POPUP_TEXTBOX);
       
   106 }
       
   107 
       
   108 CMIDTextBoxQueryDialog::CMIDTextBoxQueryDialog(TDes& aResult)
       
   109         : CAknTextQueryDialog(aResult, CAknQueryDialog::ENoTone)
       
   110 {
       
   111 }
       
   112 
       
   113 TInt CMIDTextBoxQueryDialog::RouseSleepingDialog()
       
   114 {
       
   115     return CAknTextQueryDialog::RouseSleepingDialog();
       
   116 }
       
   117 
       
   118 void CMIDTextBoxQueryDialog::ExitSleepingDialog()
       
   119 {
       
   120     CAknTextQueryDialog::ExitSleepingDialog();
       
   121 }
       
   122 
       
   123 void CMIDTextBoxQueryDialog::TryExitL(TInt aButtonId)
       
   124 {
       
   125     iDisplayable->MenuHandler()->ProcessCommandL(aButtonId);
       
   126 }
       
   127 
       
   128 TBool CMIDTextBoxQueryDialog::ProcessCommandL(CMIDCommand* aCommand)
       
   129 {
       
   130     ASSERT(aCommand);
       
   131     TBool ret = EFalse;
       
   132 
       
   133     switch (aCommand->Id())
       
   134     {
       
   135     case CMIDEdwinUtils::EMenuCommandFetchPhoneNumber:
       
   136         // for fetching data from phonebook
       
   137         if (!iAiwPbkClient)
       
   138         {
       
   139             iAiwPbkClient = CMIDAiwPbk2Client::NewL(*this);
       
   140         }
       
   141         iAiwPbkClient->FetchFromPhoneBookL(EAiwPhoneNumberSelect);
       
   142         ret = ETrue;
       
   143         break;
       
   144     case CMIDEdwinUtils::EMenuCommandFetchEmailAddress:
       
   145         // for fetching data from phonebook
       
   146         if (!iAiwPbkClient)
       
   147         {
       
   148             iAiwPbkClient = CMIDAiwPbk2Client::NewL(*this);
       
   149         }
       
   150         iAiwPbkClient->FetchFromPhoneBookL(EAiwEMailSelect);
       
   151         ret = ETrue;
       
   152         break;
       
   153     case CMIDEdwinUtils::EMenuCommandCreatePhoneCall:
       
   154         CreatePhoneCallL();
       
   155         ret = ETrue;
       
   156         break;
       
   157     default:
       
   158         break;
       
   159     }
       
   160 
       
   161     return ret;
       
   162 }
       
   163 
       
   164 void CMIDTextBoxQueryDialog::DeleteTextL(TInt aOffset,TInt aLength)
       
   165 {
       
   166     // get all initial values before deletion
       
   167     TInt oldSize = Size();
       
   168     HBufC* oldText = iEditor->GetTextInHBufL();
       
   169     CleanupStack::PushL(oldText);
       
   170 
       
   171     TInt cursorPos = GetCaretPosition();
       
   172 
       
   173     TCursorSelection selection = TCursorSelection(aOffset, aOffset + aLength);
       
   174     _LIT(KEmptyText, "");
       
   175     iEditor->InsertDeleteCharsL(aOffset, KEmptyText, selection);
       
   176 
       
   177     // Check that new content is valid.
       
   178     // If not, return old content and throw exception.
       
   179     TBool valid = iEdwinUtils->ConstraintsValidForText(Read(), iConstraints, ETrue);
       
   180     if (!valid)
       
   181     {
       
   182         iEditor->SetTextL(oldText);
       
   183     }
       
   184     CleanupStack::PopAndDestroy(oldText);
       
   185 
       
   186     iEditor->HandleTextChangedL();
       
   187 
       
   188     if (!valid)
       
   189     {
       
   190         User::Leave(KErrArgument);
       
   191     }
       
   192 
       
   193     // Handle cursor moving
       
   194 
       
   195     // Cursor is in the middle of delete area
       
   196     if ((cursorPos > aOffset) && (cursorPos < (aOffset + aLength)))
       
   197     {
       
   198         SetCursorPositionL(aOffset);
       
   199     }
       
   200     // cursor is on the right side of delete area
       
   201     else if (cursorPos > (aOffset + aLength))
       
   202     {
       
   203         TInt newPosition = cursorPos - aLength;
       
   204         if (newPosition < 0)
       
   205         {
       
   206             newPosition = 0;
       
   207         }
       
   208         SetCursorPositionL(newPosition);
       
   209     }
       
   210     // cursor is on the left side of delete area
       
   211     else
       
   212     {
       
   213         SetCursorPositionL(cursorPos);
       
   214     }
       
   215 }
       
   216 
       
   217 void CMIDTextBoxQueryDialog::SetTextL(const TDesC& aText)
       
   218 {
       
   219     // if text is invalid according to constraints, throw IllegalArgumentException,
       
   220     //  except for a PHONENUMBER which only has the invalid characters removed
       
   221     if ((iConstraints & MMIDTextField::EConstraintMask) == MMIDTextField::EPhoneNumber)
       
   222     {
       
   223     }
       
   224     else if (!iEdwinUtils->ConstraintsValidForText(aText, iConstraints, ETrue))
       
   225     {
       
   226         User::Leave(KErrArgument);
       
   227     }
       
   228     //
       
   229 
       
   230     HBufC* buf = iEdwinUtils->ConvertToLocalizedLC(aText, iConstraints);
       
   231 
       
   232     if (IsNumberConversionNeeded())
       
   233     {
       
   234         TPtr ptr = buf->Des();
       
   235         AknTextUtils::LanguageSpecificNumberConversion(ptr);
       
   236     }
       
   237 
       
   238     if ((iConstraints & MMIDTextField::EConstraintMask) == MMIDTextField::EPhoneNumber)
       
   239     {
       
   240         iEdwinUtils->RemoveNonPhoneNumberChars(buf);
       
   241     }
       
   242     iEditor->SetTextL(buf);
       
   243     iEditor->HandleTextChangedL();
       
   244     CleanupStack::PopAndDestroy(buf);
       
   245 
       
   246     // move cursor to end of the new text
       
   247     SetCursorPositionL(Size());
       
   248 }
       
   249 
       
   250 void CMIDTextBoxQueryDialog::InsertTextL(const TDesC& aText,TInt aPosition)
       
   251 {
       
   252     //VALIDATE EXISTING TEXT
       
   253     HBufC* temp = NULL;
       
   254     if ((iConstraints & MMIDTextField::EConstraintMask) == MMIDTextField::EDecimal)
       
   255     {
       
   256         // Convert decimal content to unlocalized form before testing validity
       
   257         // of insertion.
       
   258         temp = GetTextL();
       
   259         if (temp)
       
   260         {
       
   261             CleanupStack::PushL(temp);
       
   262             iEdwinUtils->ConvertFromLocalizedDecimal(temp);
       
   263         }
       
   264     }
       
   265 
       
   266     if (aPosition < 0)
       
   267         aPosition = 0;
       
   268     //
       
   269     TInt size = Size();
       
   270     if (aPosition > size)
       
   271         aPosition = size;
       
   272     //
       
   273     if (!iEdwinUtils->ConstraintsValidForInsertedTextL((temp ? temp->Des() : Read()),
       
   274             aText,
       
   275             aPosition,
       
   276             iConstraints,
       
   277             ETrue))
       
   278         User::Leave(KErrArgument);
       
   279     if (temp)
       
   280     {
       
   281         CleanupStack::PopAndDestroy(temp);
       
   282         temp = NULL;
       
   283     }
       
   284     //
       
   285     //TEXT INSERTION STARTS HERE
       
   286     if (IsReadyToDraw())
       
   287     {
       
   288         iEditor->ClearSelectionL();
       
   289     }
       
   290 
       
   291     temp = iEdwinUtils->ConvertToLocalizedLC(aText, iConstraints);
       
   292 
       
   293 
       
   294     if (IsNumberConversionNeeded())
       
   295     {
       
   296         TPtr ptr = temp->Des();
       
   297         AknTextUtils::LanguageSpecificNumberConversion(ptr);
       
   298     }
       
   299     iEditor->Text()->InsertL(aPosition, temp->Des());
       
   300 
       
   301     iEditor->HandleTextChangedL();
       
   302 
       
   303     // Get the cursor position and move it forward along with inserter characters, if
       
   304     // characters were inserted on the left side of the cursor.
       
   305     TInt cursorPos = GetCaretPosition();
       
   306     TInt numberOfAddedCharacters = Size() - size;
       
   307 
       
   308     if (cursorPos >= aPosition)
       
   309     {
       
   310         if ((cursorPos + numberOfAddedCharacters) < iMaxSize)
       
   311         {
       
   312             SetCursorPositionL(cursorPos + numberOfAddedCharacters);
       
   313         }
       
   314     }
       
   315 
       
   316     CleanupStack::PopAndDestroy(temp);
       
   317 }
       
   318 
       
   319 void CMIDTextBoxQueryDialog::SetConstraintsL(TUint /*aConstraints*/)
       
   320 {
       
   321 }
       
   322 
       
   323 void CMIDTextBoxQueryDialog::SetFEPModeAndCharFormat()
       
   324 {
       
   325     iEdwinUtils->SetFEPModeAndCharFormat(iConstraints, iEditor);
       
   326 }
       
   327 
       
   328 TInt CMIDTextBoxQueryDialog::SetMaxSizeL(TInt aSize)
       
   329 {
       
   330     TInt oldSize = Size();
       
   331     if (aSize < oldSize)
       
   332     {
       
   333         DeleteTextL(aSize, oldSize - aSize);
       
   334     }
       
   335     iMaxSize = aSize;
       
   336     iEditor->SetTextLimit(iMaxSize);
       
   337     iMaxSize = GetMaxSize();
       
   338     return iMaxSize;
       
   339 }
       
   340 
       
   341 TInt CMIDTextBoxQueryDialog::GetMaxSize()
       
   342 {
       
   343     return iEditor->MaxLength();
       
   344 }
       
   345 
       
   346 TInt CMIDTextBoxQueryDialog::Size()
       
   347 {
       
   348     return iEditor->TextLength();
       
   349 }
       
   350 
       
   351 TInt CMIDTextBoxQueryDialog::GetCaretPosition()
       
   352 {
       
   353     return iEditor->CursorPos();
       
   354 }
       
   355 
       
   356 HBufC* CMIDTextBoxQueryDialog::GetTextL()
       
   357 {
       
   358     // getting of native text
       
   359     HBufC* buf = iEditor->GetTextInHBufL();
       
   360 
       
   361     // If there is no text in iEditor, this set empty buf.
       
   362     if (!buf)
       
   363     {
       
   364         buf = HBufC::NewL(0);
       
   365     }
       
   366 
       
   367     // convert decimal from localized to MIDlet-visible representation
       
   368     if ((iConstraints & MMIDTextField::EConstraintMask) == MMIDTextField::EDecimal)
       
   369     {
       
   370         iEdwinUtils->ConvertFromLocalizedDecimal(buf);
       
   371     }
       
   372 
       
   373     // convert digits, if needed
       
   374     if (IsNumberConversionNeeded())
       
   375     {
       
   376         TPtr ptr = buf->Des();
       
   377         AknTextUtils::ConvertDigitsTo(ptr, EDigitTypeWestern);
       
   378     }
       
   379 
       
   380     // Return a copy of the contents where newlines etc. are
       
   381     // mapped to their Java representations.
       
   382     CMIDUtils::MapETextToJavaChars(buf);
       
   383 
       
   384 
       
   385     return buf;
       
   386 }
       
   387 
       
   388 void CMIDTextBoxQueryDialog::SetInitialInputModeL(const TDesC& aCharacterSubset)
       
   389 {
       
   390     iEdwinUtils->SetInitialInputModeL(aCharacterSubset,
       
   391                                       iConstraints,
       
   392                                       iInitialCurrentCase,
       
   393                                       iInitialCurrentInputMode,
       
   394                                       iInitialCurrentLanguage);
       
   395 
       
   396     TUint constraint = iConstraints & MMIDTextField::EConstraintMask;
       
   397 
       
   398     // Set permitted case modes for TextBox in lowercase or uppercase mode.
       
   399     if (aCharacterSubset.Compare(KMidpUppercaseLatin) == 0 ||
       
   400             aCharacterSubset.Compare(KMidpLowercaseLatin) == 0)
       
   401     {
       
   402         // MIDP_UPPERCASE_LATIN or MIDP_LOWERCASE_LATIN are ignored if
       
   403         // INITIAL_CAPS_SENTENCE or INITIAL_CAPS_WORD modifier in ANY.
       
   404         if (!(iConstraints & MMIDTextField::EInitialCapsWordSentence ||
       
   405                 iConstraints & MMIDTextField::EInitialCapsWord) ||
       
   406                 constraint != MMIDTextField::EAny)
       
   407         {
       
   408             // If initial input mode is uppercase or lowercase then permit
       
   409             // only explicit case mode changes, automatic changes are not
       
   410             // allowed.
       
   411             iEditor->SetAknEditorPermittedCaseModes(EAknEditorUpperCase |
       
   412                                                     EAknEditorLowerCase);
       
   413         }
       
   414     }
       
   415     else
       
   416     {
       
   417         iEditor->SetAknEditorPermittedCaseModes(EAknEditorAllCaseModes);
       
   418     }
       
   419 }
       
   420 
       
   421 void CMIDTextBoxQueryDialog::SetTitleL(const TDesC* aString)
       
   422 {
       
   423     if (aString)
       
   424     {
       
   425         SetPromptL(*aString);
       
   426     }
       
   427     else
       
   428     {
       
   429         SetPromptL(KNullDesC);
       
   430     }
       
   431 }
       
   432 
       
   433 void CMIDTextBoxQueryDialog::SetCursorPositionL(TInt aPosition)
       
   434 {
       
   435     TInt textLength = iEditor->TextLength();
       
   436     if (textLength < aPosition)
       
   437     {
       
   438         aPosition = textLength;
       
   439     }
       
   440     if (textLength >0)
       
   441     {
       
   442         iEditor->SetCursorPosL(aPosition, EFalse);
       
   443     }
       
   444     else
       
   445     {
       
   446         iEditor->SetCursorPosL(0, EFalse);
       
   447     }
       
   448 }
       
   449 
       
   450 TSize CMIDTextBoxQueryDialog::ContentSize() const
       
   451 {
       
   452     return CCoeControl::Size();
       
   453 }
       
   454 
       
   455 void CMIDTextBoxQueryDialog::FocusChanged(TDrawNow aDrawNow)
       
   456 {
       
   457     CAknTextQueryDialog::FocusChanged(aDrawNow);
       
   458     TBool isFocused = IsFocused();
       
   459 }
       
   460 //
       
   461 // We do not want to become visible if we are not showing
       
   462 //
       
   463 void CMIDTextBoxQueryDialog::MakeVisible(TBool aVisible)
       
   464 {
       
   465     if (!aVisible)
       
   466     {
       
   467         CAknTextQueryDialog::MakeVisible(aVisible);
       
   468     }
       
   469     else if (iShowing)
       
   470     {
       
   471         if (aVisible)
       
   472         {
       
   473             //re-layouting done just before dialog is shown
       
   474             //to be sure layout is correct in CAknPopupForm
       
   475             CAknTextQueryDialog::SizeChanged();
       
   476         }
       
   477         CAknTextQueryDialog::MakeVisible(aVisible);
       
   478     }
       
   479 }
       
   480 
       
   481 void CMIDTextBoxQueryDialog::SizeChanged()
       
   482 {
       
   483     if (iShowing)
       
   484     {
       
   485         CAknTextQueryDialog::SizeChanged();
       
   486     }
       
   487 }
       
   488 
       
   489 TKeyResponse CMIDTextBoxQueryDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
       
   490 {
       
   491     // If midlet is closed from applications menu or by pressing end key, then
       
   492     // 'esc' key event is generated. That event is not handled here.
       
   493     // See OfferKeyEventL function of CMIDTextBoxDialogControl.
       
   494     if (aKeyEvent.iCode == EKeyEscape)
       
   495     {
       
   496         return EKeyWasNotConsumed;
       
   497     }
       
   498     //
       
   499     //  Enter Key:
       
   500     //
       
   501     //
       
   502     if (aType == EEventKey)
       
   503     {
       
   504         iusedKeyEvent = &aKeyEvent;
       
   505     }
       
   506 
       
   507     // If TextBox have constraints below params
       
   508     // Any and Password
       
   509     // Numeric or Numeric and Password or
       
   510     // Decimal or Decimal and Password  or
       
   511     // PhoneNumber or PhoneNumber and Password or
       
   512     // MailAddr or MailAddr and Password or
       
   513     // PhoneNumber Uneditable or MailAddr Uneditable or
       
   514     // Url or Url and Password
       
   515     // then show menu or activate one command.
       
   516     if (((aType == EEventKey && aKeyEvent.iCode == EKeyEnter) ||
       
   517             (aType == EEventKeyUp && aKeyEvent.iScanCode ==   EStdKeyEnter &&
       
   518              aKeyEvent.iCode == EKeyEnter && iusedKeyEvent!=&aKeyEvent)))
       
   519     {
       
   520 
       
   521         if ((iConstraints == MMIDTextField::EAny + MMIDTextField::EPassword) ||
       
   522 
       
   523                 (iConstraints == MMIDTextField::ENumeric ||
       
   524                  (iConstraints == MMIDTextField::ENumeric  + MMIDTextField::EPassword) ||
       
   525                  iConstraints == MMIDTextField::EDecimal ||
       
   526                  (iConstraints == MMIDTextField::EDecimal + MMIDTextField::EPassword)) ||
       
   527 
       
   528                 (iConstraints == MMIDTextField::EPhoneNumber ||
       
   529                  (iConstraints == MMIDTextField::EPhoneNumber + MMIDTextField::EPassword) ||
       
   530                  iConstraints == MMIDTextField::EMailAddr ||
       
   531                  (iConstraints == MMIDTextField::EMailAddr  + MMIDTextField::EPassword))  ||
       
   532 
       
   533                 ((iConstraints == MMIDTextField::EPhoneNumber + MMIDTextField::EUneditable) ||
       
   534                  (iConstraints == MMIDTextField::EMailAddr  + MMIDTextField::EUneditable)) ||
       
   535 
       
   536                 (iConstraints == MMIDTextField::EUrl ||
       
   537                  (iConstraints == MMIDTextField::EUrl + MMIDTextField::EPassword)))
       
   538         {
       
   539 
       
   540             // counter OK and Item elements from options menu
       
   541             TInt numOpt = iDisplayable->NumCommandsForOkOptionsMenu();
       
   542 
       
   543             //open menu
       
   544             if (numOpt > 1)
       
   545             {
       
   546                 iDisplayable->MenuHandler()->ShowMenuL(CMIDMenuHandler::EOkMenu);
       
   547             }
       
   548             else
       
   549             {
       
   550                 CMIDCommand* cmdTmp = NULL;
       
   551 
       
   552                 // counter of all elements from options menu
       
   553                 TInt numItemCommands = iDisplayable->MainCommandList()->Count();
       
   554 
       
   555                 for (TInt i = 0; i < numItemCommands; i++)
       
   556                 {
       
   557                     // for each command from menu
       
   558                     // count offset index only for commands
       
   559                     // without FetchPhoneNumber, EmailAddress, PhoneCall
       
   560                     cmdTmp = iDisplayable->MainCommandList()->At(i).iCommand;
       
   561 
       
   562                     if (cmdTmp)
       
   563                     {
       
   564                         if ((cmdTmp->Id() != CMIDEdwinUtils::EMenuCommandFetchPhoneNumber) &&
       
   565                                 (cmdTmp->Id() != CMIDEdwinUtils::EMenuCommandFetchEmailAddress) &&
       
   566                                 (cmdTmp->Id() != CMIDEdwinUtils::EMenuCommandCreatePhoneCall))
       
   567                         {
       
   568                             break;
       
   569                         }
       
   570                     }
       
   571                 }
       
   572 
       
   573                 // execute command
       
   574                 if (cmdTmp)
       
   575                 {
       
   576                     if ((cmdTmp->CommandType() == MMIDCommand::EOk ||
       
   577                             cmdTmp->CommandType() == MMIDCommand::EItem ||
       
   578                             cmdTmp->CommandType() == MMIDCommand::EScreen))
       
   579                     {
       
   580                         // get command index from option menu
       
   581                         TInt offsetIdx = iDisplayable->MainCommandList()->FindCommandIndex(cmdTmp);
       
   582 
       
   583                         if (offsetIdx != KErrNotFound &&
       
   584                                 iDisplayable->MainCommandList()->At(offsetIdx).iCommand == cmdTmp)
       
   585                         {
       
   586                             iDisplayable->ProcessCommandL(iDisplayable->MainCommandList()->CommandOffset() + offsetIdx);
       
   587                         }
       
   588 
       
   589                     }
       
   590                 }
       
   591             }
       
   592             return EKeyWasConsumed;
       
   593         }
       
   594     }
       
   595 
       
   596     //
       
   597     //  End Enter Key
       
   598     //
       
   599 
       
   600 
       
   601     // msk: this is needed if MSK is not enabled on the device
       
   602     if ((aType == EEventKey) && (aKeyEvent.iScanCode == EStdKeyDevice3))
       
   603     {
       
   604         iDisplayable->ShowOkOptionsMenuL();
       
   605         return EKeyWasConsumed;
       
   606     }
       
   607 
       
   608 
       
   609     // msk: this is needed if MSK is not enabled on the device
       
   610     if ((aType == EEventKey) && (aKeyEvent.iScanCode == EStdKeyDevice3))
       
   611     {
       
   612         iDisplayable->ShowOkOptionsMenuL();
       
   613         return EKeyWasConsumed;
       
   614     }
       
   615 
       
   616     // store the key pressed last time, used for warning beeps while reaching size limit
       
   617     if (aType == EEventKeyDown)
       
   618     {
       
   619         iLastMultitapKey = iThisMultitapKey;
       
   620         iThisMultitapKey = aKeyEvent.iScanCode;
       
   621     }
       
   622 
       
   623     if (aType == EEventKeyDown)
       
   624     {
       
   625         iKeyEventsPending = ETrue;
       
   626     }
       
   627     else if (aType == EEventKeyUp)
       
   628     {
       
   629         iKeyEventsPending = EFalse;
       
   630     }
       
   631     //
       
   632     // Post ItemStateChangedEvent before a command is delivered to the Form's CommandListener
       
   633     //
       
   634     TUint scanCode = aKeyEvent.iScanCode;
       
   635 
       
   636     //
       
   637     // ignore up and down arrows on PASSWORD TextField to avoid funny behaviour
       
   638     // with line breaks
       
   639     if (iDisplayable && (iConstraints & MMIDTextField::EPassword)
       
   640             && (aKeyEvent.iCode == EKeyDownArrow || aKeyEvent.iCode == EKeyUpArrow))
       
   641     {
       
   642         return EKeyWasConsumed;
       
   643     }
       
   644 
       
   645     // when pressing the send key on a phonenumber-type box, call the number
       
   646 #ifdef RD_SCALABLE_UI_V2
       
   647     if ((aType == EEventKey) && (scanCode == EStdKeyYes))
       
   648 #else
       
   649     if ((aType == EEventKeyUp) && (scanCode == EStdKeyYes))
       
   650 #endif // RD_SCALABLE_UI_V2
       
   651     {
       
   652         if ((iConstraints & MMIDTextField::EConstraintMask) == MMIDTextField::EPhoneNumber)
       
   653         {
       
   654             CreatePhoneCallL();
       
   655             return EKeyWasConsumed;
       
   656         }
       
   657     }
       
   658 
       
   659 #ifdef RD_SCALABLE_UI_V2
       
   660     if (IsConstraintSet(MMIDTextField::ENumeric) && (aType == EEventKey || aType == EEventKeyUp) && !iEditor->IsReadOnly() &&
       
   661 #else
       
   662     if (IsConstraintSet(MMIDTextField::ENumeric) && (aType == EEventKeyUp) && !iEditor->IsReadOnly() &&
       
   663 #endif // RD_SCALABLE_UI_V2
       
   664             ((scanCode==EStdKeyNkpAsterisk) || (scanCode == EStdKeyMinus) || (scanCode==EStdKeyNkpMinus) || (scanCode == 0x2A) || (scanCode == 0x2D)))
       
   665     {
       
   666         HandleMinusCharEventL(MEikEdwinObserver::EEventTextUpdate);
       
   667         return EKeyWasConsumed;
       
   668     }
       
   669 
       
   670     //handling of qwerty keypad "-" or "." pressing in Decimal mode
       
   671 #ifdef RD_SCALABLE_UI_V2
       
   672     if (IsConstraintSet(MMIDTextField::EDecimal) && (aType == EEventKey) && !iEditor->IsReadOnly() &&
       
   673 #else
       
   674     if (IsConstraintSet(MMIDTextField::EDecimal) && (aType == EEventKeyUp) && !iEditor->IsReadOnly() &&
       
   675 #endif // RD_SCALABLE_UI_V2
       
   676             ((scanCode==EStdKeyMinus) || (scanCode==EStdKeyFullStop)))
       
   677     {
       
   678         CPlainText* res = iEditor->Text();
       
   679         TInt textLength = Size();
       
   680         if (scanCode == EStdKeyMinus)
       
   681         {
       
   682             res->InsertL(GetCaretPosition(), KMinusChar);
       
   683         }
       
   684         else if (scanCode == EStdKeyFullStop)
       
   685         {
       
   686             res->InsertL(GetCaretPosition(), KFullStopChar);
       
   687         }
       
   688 
       
   689         iEditor->HandleTextChangedL(); // notify editor about the text changes
       
   690 
       
   691         if (Size() < iMaxSize)
       
   692         {
       
   693             SetCursorPositionL(GetCaretPosition() + 1);
       
   694         }
       
   695     }
       
   696     //Error tone playing case1:
       
   697     //Play error tone if TextBox/TextField is read-only or maximum length has been reached.
       
   698     //Here is handling of keys 0...9 for full keyboard and itu-t, but NOT virtual keyboard.
       
   699     if (aType == EEventKeyDown
       
   700             && ((scanCode >= KKeyQwerty0 && scanCode <= KKeyQwerty9)
       
   701                 || scanCode == EStdKeyHash
       
   702                 || scanCode == EStdKeyNkpAsterisk
       
   703                 || scanCode == KMidpKeyNkpAsteriskHW))
       
   704     {
       
   705         if ((scanCode == EStdKeyNkpAsterisk || scanCode == KMidpKeyNkpAsteriskHW)
       
   706                 && !iEditor->IsReadOnly() && IsConstraintSet(MMIDTextField::ENumeric))
       
   707         {
       
   708             //Do nothing here in case of minus char toggle
       
   709         }
       
   710         else if (iEditor->IsReadOnly())
       
   711         {
       
   712             iAvkonAppUi->KeySounds()->PlaySound(EAvkonSIDErrorTone);
       
   713             return EKeyWasConsumed;
       
   714         }
       
   715 
       
   716         // All possible sources of warning beep are separated to be easy to read
       
   717         else if (Size() >= iMaxSize)
       
   718         {
       
   719             TInt ret = KErrNone;
       
   720             TInt inputModeValue = iEditor->AknEditorCurrentInputMode();
       
   721             if (inputModeValue != EAknEditorTextInputMode)
       
   722             {
       
   723                 iAvkonAppUi->KeySounds()->PlaySound(EAvkonSIDErrorTone);
       
   724                 return EKeyWasConsumed;
       
   725             }
       
   726 
       
   727             TInt aknRepositoryValue = 0;
       
   728             CRepository* aknFepRepository = NULL;
       
   729             TRAP(ret, aknFepRepository = CRepository::NewL(KCRUidAknFep));
       
   730             if ((ret != KErrNone) || (!aknFepRepository))
       
   731             {
       
   732                 // if we cannot get the repository (something is wrong), play nothing
       
   733                 return EKeyWasConsumed;
       
   734             }
       
   735             aknFepRepository->Get(KAknFepPredTxtFlag, aknRepositoryValue);
       
   736 
       
   737             delete aknFepRepository;
       
   738             aknFepRepository = NULL;
       
   739 
       
   740             if (aknRepositoryValue == 1)    // 1 means the predictive input is on
       
   741             {
       
   742                 iAvkonAppUi->KeySounds()->PlaySound(EAvkonSIDErrorTone);
       
   743                 return EKeyWasConsumed;
       
   744             }
       
   745             // now only nonpredictive textinput is left
       
   746             if (iThisMultitapKey != iLastMultitapKey) // different key tapped -> no multitap
       
   747             {
       
   748                 iAvkonAppUi->KeySounds()->PlaySound(EAvkonSIDErrorTone);
       
   749                 iThisMultitapKey = 0;
       
   750                 iLastMultitapKey = 0;
       
   751                 return EKeyWasConsumed;
       
   752             }
       
   753         }
       
   754     }
       
   755 
       
   756     if (aType != EEventKey)
       
   757     {
       
   758         return EKeyWasConsumed;
       
   759     }
       
   760 
       
   761 
       
   762     TKeyResponse response = EKeyWasNotConsumed;
       
   763 
       
   764     //Error tone playing case2:
       
   765     //Play error tone if TextBox/TextField is read-only or maximum length has been reached.
       
   766     //Here is handling of full keyboard keys(NOT 0...9) and all virtual keyboard keys.
       
   767     //(Note: Virtual keyboard sends only EEventKey type events, not up or down events)
       
   768     //(Note: Error tone is played when there is no text to be replaced i.e. no text has been painted)
       
   769     if (!iEdwinUtils->IsNavigationKey(aKeyEvent) && !iEdwinUtils->IsHotKeyL(aKeyEvent, iCoeEnv) && !aKeyEvent.iCode == EKeyYes &&
       
   770             (!iKeyEventsPending || (scanCode < KKeyQwerty0  || scanCode > KKeyQwerty9)))
       
   771     {
       
   772         if (iEditor->IsReadOnly() || (Size() >= iMaxSize && aKeyEvent.iCode != EKeyBackspace))
       
   773         {
       
   774             //SelectionLength() > 0 if text has been selected/painted
       
   775             if (iEditor->SelectionLength() == 0)
       
   776             {
       
   777                 iAvkonAppUi->KeySounds()->PlaySound(EAvkonSIDErrorTone);
       
   778             }
       
   779             response = iEditor->OfferKeyEventL(aKeyEvent,aType);
       
   780             return response;
       
   781         }
       
   782     }
       
   783 
       
   784     TBool valid = EFalse;
       
   785 
       
   786     if (iEdwinUtils->IsNavigationKey(aKeyEvent) || iEdwinUtils->IsHotKeyL(aKeyEvent, iCoeEnv))
       
   787     {
       
   788         HBufC* oldText = GetTextL();
       
   789         CleanupStack::PushL(oldText);
       
   790         TCursorSelection sel = iEditor->Selection();
       
   791 
       
   792         response = CAknTextQueryDialog::OfferKeyEventL(aKeyEvent,aType);
       
   793         valid = iEdwinUtils->ConstraintsValidForText(iEditor->Text()?Read():TPtrC(),iConstraints,EFalse);
       
   794 
       
   795         if (!valid)
       
   796         {
       
   797             SetTextL(*oldText);
       
   798             iEditor->HandleTextChangedL();
       
   799             iEditor->SetSelectionL(sel.iCursorPos,sel.iAnchorPos);
       
   800             response = EKeyWasConsumed;
       
   801         }
       
   802         CleanupStack::PopAndDestroy(oldText);
       
   803 
       
   804         return response;
       
   805     }
       
   806     else
       
   807     {
       
   808         TBuf<1> key;
       
   809         key.Append(TChar(aKeyEvent.iCode));
       
   810         valid = iEdwinUtils->ConstraintsValidForInsertedTextL(iEditor->Text()?Read():TPtrC(),
       
   811                 key,
       
   812                 GetCaretPosition(),
       
   813                 iConstraints,
       
   814                 EFalse);
       
   815         if (valid)
       
   816         {
       
   817             response = iEditor->OfferKeyEventL(aKeyEvent,aType);
       
   818         }
       
   819         return response;
       
   820     }
       
   821 }
       
   822 
       
   823 #ifdef RD_SCALABLE_UI_V2
       
   824 void CMIDTextBoxQueryDialog::HandlePointerEventL(const TPointerEvent &aPointerEvent)
       
   825 {
       
   826     if (AknLayoutUtils::PenEnabled() && Rect().Contains(aPointerEvent.iPosition))
       
   827     {
       
   828         TBool consumed = STATIC_CAST(CMIDDisplayable*, iDisplayable)->TryDetectLongTapL(aPointerEvent);
       
   829         if (!consumed)
       
   830         {
       
   831             CAknTextQueryDialog::HandlePointerEventL(aPointerEvent);
       
   832         }
       
   833     }
       
   834 }
       
   835 #endif // RD_SCALABLE_UI_V2
       
   836 
       
   837 TCoeInputCapabilities CMIDTextBoxQueryDialog::InputCapabilities() const
       
   838 {
       
   839     TCoeInputCapabilities inputCapabilities(TCoeInputCapabilities::ENone, NULL,
       
   840                                             const_cast<CMIDTextBoxQueryDialog*>(this));
       
   841     inputCapabilities.MergeWith(iEditor->InputCapabilities());
       
   842     return inputCapabilities;
       
   843 }
       
   844 
       
   845 void CMIDTextBoxQueryDialog::HandleEdwinEventL(CEikEdwin* aEdwin, TEdwinEvent aEventType)
       
   846 {
       
   847     if (aEdwin != iEditor)
       
   848     {
       
   849         return;
       
   850     }
       
   851 
       
   852     if (aEventType == MEikEdwinObserver::EEventTextUpdate)
       
   853     {
       
   854         // handles clearing multitap counter
       
   855         if ((iLastMultitapKey != 0) && (iLastMultitapKey != iThisMultitapKey))
       
   856         {
       
   857             iLastMultitapKey = 0;
       
   858         }
       
   859         else
       
   860         {
       
   861             iThisMultitapKey = 0;
       
   862             iLastMultitapKey = 0;
       
   863         }
       
   864 
       
   865         TBool textChanged = EFalse;
       
   866         HBufC* res = NULL;
       
   867         TRAPD(err, { res = GetTextL();});
       
   868         if (err != KErrNone || !res)
       
   869         {
       
   870             return;
       
   871         }
       
   872         CleanupStack::PushL(res);
       
   873 
       
   874         // in DECIMAL mode, don't allow changes that would result
       
   875         // in an illegal string;
       
   876         //  1) if there is a minus, it must be the first character
       
   877         //  2) there can be at most one decimal separator
       
   878         if ((aEventType == EEventTextUpdate) && ((iConstraints
       
   879                 & MMIDTextField::EConstraintMask) == MMIDTextField::EDecimal))
       
   880         {
       
   881             TInt illegalCharPos = -1;
       
   882             TPtr16 ptr = res->Des();
       
   883             TInt minusPos = ptr.LocateReverse(TChar('-'));
       
   884 
       
   885             // check if minus sign is inserted on incorrect place
       
   886             // (not at the beginning)
       
   887             if ((minusPos != KErrNotFound) && (minusPos != 0))
       
   888             {
       
   889                 // check if minus sign isn't inserted twice
       
   890                 if (minusPos != ptr.Locate(TChar('-')))
       
   891                 {
       
   892                     illegalCharPos = minusPos;
       
   893                 }
       
   894                 // insert minus char at the beginning of decimal field
       
   895                 else
       
   896                 {
       
   897                     ptr.Delete(minusPos, 1);
       
   898                     ptr.Insert(0, KMinusChar);
       
   899                     minusPos = 0;
       
   900                     SetTextL(*res);
       
   901                     textChanged = ETrue;
       
   902                 }
       
   903             }
       
   904 
       
   905             TInt pointPosL = ptr.Locate(iDecimalSeparator);
       
   906             TInt pointPosR = ptr.LocateReverse(iDecimalSeparator);
       
   907             TInt cursorPos = GetCaretPosition();
       
   908             if ((minusPos != KErrNotFound) && (pointPosL == 0))
       
   909             {
       
   910                 illegalCharPos = pointPosL;
       
   911             }
       
   912             else if (pointPosL != pointPosR)
       
   913             {
       
   914                 illegalCharPos = pointPosR;
       
   915             }
       
   916 
       
   917             // if minus or dot/comma char is displayed more than once
       
   918             if (illegalCharPos >= 0)
       
   919             {
       
   920                 // deleting second minus or dot/comma char
       
   921                 // and set cursor position on the right place
       
   922                 ptr.Delete(illegalCharPos, 1);
       
   923                 SetTextL(*res);
       
   924                 textChanged = ETrue;
       
   925                 if (cursorPos >= 1)
       
   926                 {
       
   927                     if (cursorPos == illegalCharPos)
       
   928                     {
       
   929                         cursorPos--;
       
   930                     }
       
   931                     SetCursorPositionL(cursorPos);
       
   932                 }
       
   933             }
       
   934         }
       
   935         else if (((iConstraints &
       
   936                    MMIDTextField::EConstraintMask) == MMIDTextField::EMailAddr) ||
       
   937                  ((iConstraints &
       
   938                    MMIDTextField::EConstraintMask) == MMIDTextField::EUrl))
       
   939         {
       
   940             // In EMAIL and URL mode, don't allow changes that would result
       
   941             // in an illegal string; if there is '/n' or '/f', and line breaks
       
   942             // are not supported, chars need to be changed to space
       
   943             // SetText function before actual text change checks if line
       
   944             // breaks are not supported
       
   945             SetTextL(*res);
       
   946             textChanged = ETrue;
       
   947         }
       
   948         CleanupStack::Pop(res);
       
   949         delete res;
       
   950 
       
   951         // if there were any modifications the text is updated
       
   952         if (textChanged)
       
   953         {
       
   954             iEditor->HandleTextChangedL();
       
   955         }
       
   956     }
       
   957 }
       
   958 
       
   959 void CMIDTextBoxQueryDialog::GetCaptionForFep(TDes& aCaption) const
       
   960 {
       
   961     aCaption = Prompt();
       
   962 }
       
   963 
       
   964 void CMIDTextBoxQueryDialog::ProcessModifiers()
       
   965 {
       
   966     // set general edwin attributes according to TextBox constraints
       
   967     iEditor->SetReadOnly(iConstraints & MMIDTextField::EUneditable);
       
   968 }
       
   969 
       
   970 void CMIDTextBoxQueryDialog::ShowL(TBool aShow)
       
   971 {
       
   972     if (aShow != iShowing)
       
   973     {
       
   974         if (aShow)
       
   975         {
       
   976             iShowing = ETrue;
       
   977 
       
   978 #ifdef RD_SCALABLE_UI_V2
       
   979             SetPointerCapture(ETrue);
       
   980 #endif
       
   981             RouseSleepingDialog();
       
   982 
       
   983             UpdateInitialInputModes();
       
   984         }
       
   985         else
       
   986         {
       
   987             ExitSleepingDialog();
       
   988 #ifdef RD_SCALABLE_UI_V2
       
   989             SetPointerCapture(EFalse);
       
   990 #endif
       
   991 
       
   992             iShowing = EFalse; //attention: iShowing must be true when dismissing
       
   993             // a dialog or else MakeVisible() won't execute and
       
   994             // we won't update the fader's stack, @see MakeVisible()
       
   995 
       
   996         }
       
   997 
       
   998         UpdateCbasL();
       
   999     }
       
  1000 }
       
  1001 
       
  1002 void CMIDTextBoxQueryDialog::SetTextWithNewConstraintsL(HBufC* aText)
       
  1003 {
       
  1004     // If the current contents of the TextBox do not match the new constraints,the
       
  1005     // contents are set to empty, except for a PHONENUMBER which only has the
       
  1006     // invalid characters removed. Otherwise, set the text as given.
       
  1007     if ((iConstraints & MMIDTextField::EConstraintMask) == MMIDTextField::EPhoneNumber)
       
  1008     {
       
  1009         iEdwinUtils->RemoveNonPhoneNumberChars(aText);
       
  1010         SetTextL(*aText);
       
  1011     }
       
  1012     else if (!iEdwinUtils->ConstraintsValidForText(aText->Des(),
       
  1013              iConstraints & MMIDTextField::EConstraintMask,
       
  1014              ETrue))
       
  1015     {
       
  1016         SetTextL(KNullDesC);
       
  1017     }
       
  1018     else
       
  1019     {
       
  1020         SetTextL(*aText);
       
  1021     }
       
  1022 }
       
  1023 
       
  1024 void  CMIDTextBoxQueryDialog::UpdateLeftSoftKeyL()
       
  1025 {
       
  1026 }
       
  1027 
       
  1028 TBool CMIDTextBoxQueryDialog::OkToExitL(TInt aCommandId)
       
  1029 {
       
  1030     TInt offset = iDisplayable->MainCommandList()->CommandOffset();
       
  1031     if (aCommandId ==EEikBidCancel)
       
  1032     {
       
  1033         return ETrue;
       
  1034     }
       
  1035     if (aCommandId == EAknSoftkeyOptions)   // 3000
       
  1036     {
       
  1037         iDisplayable->MenuHandler()->ProcessCommandL(EAknSoftkeyOptions);
       
  1038         SetFocus(EFalse);
       
  1039     }
       
  1040     else if (aCommandId - offset < 0)   // aCommandId value is over 3000 - used by MSK
       
  1041     {
       
  1042         iDisplayable->ProcessCommandL(aCommandId);
       
  1043     }
       
  1044     else // aCommandId value is 7000 and over - used by LSK, RSK and EnterKey
       
  1045     {
       
  1046         CMIDCommand* tempCmd = NULL;
       
  1047         CMIDCommand* command = NULL;
       
  1048         TBool isMaped = EFalse;
       
  1049         TInt mapedCnt = ENone;
       
  1050         TInt mapedId = ENone;
       
  1051 
       
  1052         // number of all commands
       
  1053         TInt numberOfCommands = iDisplayable->CommandCount();
       
  1054         // number of Ok and Item commands
       
  1055         TInt numberOfOkOptionsCommands = iDisplayable->NumCommandsForOkOptionsMenu();
       
  1056         // command ID which is get from aCommandId
       
  1057         TInt commandId = aCommandId - offset;
       
  1058 
       
  1059         if (numberOfCommands > 0)
       
  1060         {
       
  1061             // Go through every midlet command, and save its ID if maped
       
  1062             // and also count maped commands.
       
  1063             for (TInt i = 0; i < numberOfCommands; i++)
       
  1064             {
       
  1065                 tempCmd = iDisplayable->MainCommandList()->At(i).iCommand;
       
  1066                 if (tempCmd->IsMappedToSoftKey())
       
  1067                 {
       
  1068                     mapedId = i;
       
  1069                     isMaped = ETrue;
       
  1070                     mapedCnt++;
       
  1071                 }
       
  1072             }
       
  1073 
       
  1074             // If there are more than one maped command (LSK & RSK maped)
       
  1075             // or maped command is different than commandId (EnterKey used),
       
  1076             // set CMIDCommand command with this command, which index
       
  1077             // is the same as commandId value.
       
  1078             if (mapedCnt > 1 || mapedId != commandId)
       
  1079             {
       
  1080                 command = iDisplayable->MainCommandList()->At(commandId).iCommand;
       
  1081             }
       
  1082             else // Else if there are one or zero command maped.
       
  1083             {
       
  1084                 if (isMaped)   // One command maped.
       
  1085                 {
       
  1086                     command = iDisplayable->MainCommandList()->At(mapedId).iCommand;
       
  1087                 }
       
  1088                 else // Zero commands maped.
       
  1089                 {
       
  1090                     command = iDisplayable->MainCommandList()->At(0).iCommand;
       
  1091                 }
       
  1092             }
       
  1093 
       
  1094             // type of the command
       
  1095             TInt commandType = command->CommandType();
       
  1096 
       
  1097             // If there aren't any EExit, EBack, ECancel and EStop
       
  1098             // command mapped and there are still some commands
       
  1099             // show menu, else process with maped command.
       
  1100             if (commandType != MMIDCommand::EExit &&
       
  1101                     commandType != MMIDCommand::EBack &&
       
  1102                     commandType != MMIDCommand::ECancel &&
       
  1103                     commandType != MMIDCommand::EStop &&
       
  1104                     numberOfOkOptionsCommands > 1)
       
  1105             {
       
  1106                 iDisplayable->MenuHandler()->ShowMenuL(CMIDMenuHandler::EOkMenu);
       
  1107             }
       
  1108             else
       
  1109             {
       
  1110                 iDisplayable->ProcessCommandL(aCommandId);
       
  1111             }
       
  1112         }
       
  1113     }
       
  1114 
       
  1115     //The dialog can only be dismissed java side or else we'll end
       
  1116     //up with the TextBox displayed and no dialog
       
  1117     return EFalse;
       
  1118 }
       
  1119 
       
  1120 void CMIDTextBoxQueryDialog::SetEditorL()
       
  1121 {
       
  1122     iEditor = (CEikEdwin*)QueryControl()->ControlByLayoutOrNull(EDataLayout);
       
  1123     iEditor->SetAknEditorFlags(CEikEdwin::EZeroEnumValue);
       
  1124 
       
  1125     TBool singleLineEditor = IsConstraintSet(MMIDTextField::EMailAddr)
       
  1126                              || IsConstraintSet(MMIDTextField::EUrl)
       
  1127                              || (iConstraints & MMIDTextField::EPassword);
       
  1128 
       
  1129     if (((iConstraints & MMIDTextField::EConstraintMask) == MMIDTextField::EAny)
       
  1130             && !(iConstraints & MMIDTextField::EPassword))
       
  1131     {
       
  1132         iEditor->SetAknEditorFlags(EAknEditorFlagEnableScrollBars | iEditor->AknEdwinFlags());
       
  1133     }
       
  1134 
       
  1135     AknEditUtils::ConstructEditingL(iEditor,                        // aEdwin
       
  1136                                     iMaxSize,                      // aEditingSpace
       
  1137                                     (singleLineEditor ? 1 : 0),    // aEditingWindow
       
  1138                                     EAknEditorCharactersLowerCase, // aCharacterCase
       
  1139                                     EAknEditorAlignLeft,           // aJustification
       
  1140                                     ETrue,                         // aAllowedToMoveInsertionPoint
       
  1141                                     ETrue,                         // aCursorYesNo
       
  1142                                     EFalse);                       // aOverflowYesNo
       
  1143 
       
  1144 
       
  1145     if (iConstraints & MMIDTextField::EPassword)
       
  1146     {
       
  1147         TUint32 userFlags = iEditor->UserFlags();
       
  1148         iEditor->SetAknEditorFlags(userFlags |= CEikEdwin::EUserSuppliedText);
       
  1149         CreatePasswordTextL();
       
  1150     }
       
  1151 
       
  1152     HBufC* buf = GetTextL();
       
  1153     CleanupStack::PushL(buf);
       
  1154     if (buf)
       
  1155     {
       
  1156         CMIDUtils::MapJavaToETextChars(buf);
       
  1157         if ((iConstraints & MMIDTextField::EConstraintMask) == MMIDTextField::EPhoneNumber)
       
  1158         {
       
  1159             iEdwinUtils->RemoveNonPhoneNumberChars(buf);
       
  1160         }
       
  1161         SetTextL(*buf);
       
  1162     }
       
  1163     CleanupStack::PopAndDestroy(buf);
       
  1164 
       
  1165     iEditor->CreateTextViewL();
       
  1166     ProcessModifiers();
       
  1167     SetFEPModeAndCharFormat();
       
  1168     iEditor->AddEdwinObserverL(this);
       
  1169 
       
  1170     CreateNonMidletCommandsL();
       
  1171 
       
  1172     if ((iConstraints & MMIDTextField::EConstraintMask) == MMIDTextField::ENonPredictive)
       
  1173     {
       
  1174         SetPredictiveTextInputPermitted(EFalse);
       
  1175     }
       
  1176     else
       
  1177     {
       
  1178         SetPredictiveTextInputPermitted(ETrue);
       
  1179     }
       
  1180     // Publish MIDP constraints via input capabilities of the CEikEdwin
       
  1181     // The information is needed by chinese VKB/HWR system that adjusts its behavior
       
  1182     // based on MIDP constraints (most notably by checking if the field is a PASSWORD field).
       
  1183     TCoeInputCapabilities inputCapabilities = InputCapabilities();
       
  1184     if (inputCapabilities != TCoeInputCapabilities::ENone)
       
  1185     {
       
  1186         MObjectProvider* mop = inputCapabilities.ObjectProvider();
       
  1187         if (mop)
       
  1188         {
       
  1189             CAknExtendedInputCapabilities* extendedInputCapabilities = NULL;
       
  1190             extendedInputCapabilities = mop->MopGetObject(extendedInputCapabilities);
       
  1191             if (extendedInputCapabilities)
       
  1192             {
       
  1193                 extendedInputCapabilities->SetMIDPConstraints(iConstraints);
       
  1194             }
       
  1195         }
       
  1196     }
       
  1197 
       
  1198     iThisMultitapKey = 0;   // reset key counter
       
  1199     iLastMultitapKey = 0;
       
  1200 }
       
  1201 
       
  1202 TBool CMIDTextBoxQueryDialog::Showing()
       
  1203 {
       
  1204     return iShowing;
       
  1205 }
       
  1206 
       
  1207 TInt CMIDTextBoxQueryDialog::Constraints()
       
  1208 {
       
  1209     return iConstraints;
       
  1210 }
       
  1211 
       
  1212 void CMIDTextBoxQueryDialog::UpdateCbasL()
       
  1213 {
       
  1214     if (iShowing)
       
  1215     {
       
  1216         iDisplayable->SetCba(&ButtonGroupContainer());
       
  1217         iDisplayable->InitializeCbasL();
       
  1218         CCoeControl* cba = ButtonGroupContainer().ButtonGroup()->AsControl();
       
  1219         cba->DrawableWindow()->SetOrdinalPosition(0);
       
  1220         cba->MakeVisible(ETrue);
       
  1221         cba->DrawNow();
       
  1222     }
       
  1223     else
       
  1224     {
       
  1225         iDisplayable->SetCba(iDisplayable->MenuHandler()->Cba());
       
  1226     }
       
  1227 }
       
  1228 
       
  1229 TBool CMIDTextBoxQueryDialog::IsNumberConversionNeeded()
       
  1230 {
       
  1231     return iEdwinUtils->IsNumberConversionNeeded(GetConstraints());
       
  1232 }
       
  1233 
       
  1234 void CMIDTextBoxQueryDialog::HandleMinusCharEventL(MEikEdwinObserver::TEdwinEvent aEventType)
       
  1235 {
       
  1236     if ((aEventType == MEikEdwinObserver::EEventTextUpdate) && ((iConstraints & MMIDTextField::EConstraintMask) == MMIDTextField::ENumeric))
       
  1237     {
       
  1238         CPlainText* res = iEditor->Text();
       
  1239         TBuf<1> firstChar;
       
  1240         if (Size() != 0)
       
  1241         {
       
  1242             res->Extract(firstChar,  0, 1);
       
  1243         }
       
  1244         TInt cursorPos = GetCaretPosition();
       
  1245         //toggle '-' char in the first position
       
  1246         TInt pos = firstChar.Locate(TChar('-'));
       
  1247         if (pos == KErrNotFound)
       
  1248         {
       
  1249             if (Size() < iMaxSize)
       
  1250             {
       
  1251                 res->InsertL(0, KMinusChar);
       
  1252                 cursorPos++;
       
  1253             }
       
  1254             else
       
  1255             {
       
  1256                 //play error sound if text limit is to be exceeded
       
  1257                 iAvkonAppUi->KeySounds()->PlaySound(EAvkonSIDErrorTone);
       
  1258             }
       
  1259         }
       
  1260         else
       
  1261         {
       
  1262             TBool deletion = res->DeleteL(0,1);
       
  1263             if (cursorPos >= 1)
       
  1264             {
       
  1265                 cursorPos--;
       
  1266             }
       
  1267         }
       
  1268         iEditor->HandleTextChangedL(); // notify editor about the text changes
       
  1269         SetCursorPositionL(cursorPos);
       
  1270     }
       
  1271 }
       
  1272 
       
  1273 TPtrC CMIDTextBoxQueryDialog::Read() const
       
  1274 {
       
  1275     if (iConstraints & MMIDTextField::EPassword)
       
  1276     {
       
  1277         return static_cast<CPasswordBoxGlobalText*>(iEditor->Text())->ClearText();
       
  1278     }
       
  1279     else
       
  1280     {
       
  1281         return iEditor->Text()->Read(0,iEditor->TextLength());
       
  1282     }
       
  1283 }
       
  1284 
       
  1285 /** Create non-midlet commands according to the constraints and add them
       
  1286 to either the displayable or to the item. Commands will be processed in ProcessCommandL(). */
       
  1287 void CMIDTextBoxQueryDialog::CreateNonMidletCommandsL()
       
  1288 {
       
  1289     RPointerArray<MMIDCommand> array;
       
  1290     CleanupClosePushL(array);
       
  1291 
       
  1292     if (((iConstraints & MMIDTextField::EConstraintMask) == MMIDTextField::EPhoneNumber) && !(iConstraints & MMIDTextField::EUneditable))
       
  1293     {
       
  1294         AddCommandToArrayL(array, R_MIDP_PB_FETCH_NUMBER_SHORT_COMMAND_TEXT, R_MIDP_PB_FETCH_NUMBER_COMMAND_TEXT, CMIDEdwinUtils::EMenuCommandFetchPhoneNumber);
       
  1295         AddCommandToArrayL(array, R_MIDP_CREATE_CALL_SHORT_COMMAND_TEXT, R_MIDP_CREATE_CALL_COMMAND_TEXT, CMIDEdwinUtils::EMenuCommandCreatePhoneCall);
       
  1296     }
       
  1297 
       
  1298     if (((iConstraints & MMIDTextField::EConstraintMask) == MMIDTextField::EPhoneNumber) && (iConstraints & MMIDTextField::EUneditable))
       
  1299     {
       
  1300         AddCommandToArrayL(array, R_MIDP_CREATE_CALL_SHORT_COMMAND_TEXT, R_MIDP_CREATE_CALL_COMMAND_TEXT, CMIDEdwinUtils::EMenuCommandCreatePhoneCall);
       
  1301     }
       
  1302 
       
  1303     if (((iConstraints & MMIDTextField::EConstraintMask) == MMIDTextField::EMailAddr) && !(iConstraints & MMIDTextField::EUneditable))
       
  1304     {
       
  1305         AddCommandToArrayL(array, R_MIDP_PB_FETCH_EMAIL_SHORT_COMMAND_TEXT, R_MIDP_PB_FETCH_EMAIL_COMMAND_TEXT, CMIDEdwinUtils::EMenuCommandFetchEmailAddress);
       
  1306     }
       
  1307     AddCommandsToEdwinL(array);
       
  1308 
       
  1309     CleanupStack::PopAndDestroy(&array);
       
  1310 }
       
  1311 
       
  1312 /**
       
  1313 Creates and adds new command to array based on shot & long label resource ids
       
  1314 and other parameters.
       
  1315 */
       
  1316 void CMIDTextBoxQueryDialog::AddCommandToArrayL(RPointerArray<MMIDCommand>& aArray,
       
  1317         TInt aCommandResIdShort, TInt aCommandResIdLong, TInt aCommandId)
       
  1318 {
       
  1319     TBuf<64> shortLabel;
       
  1320     iEikonEnv->ReadResourceL(shortLabel, aCommandResIdShort);
       
  1321     TBuf<64> longLabel;
       
  1322     iEikonEnv->ReadResourceL(longLabel, aCommandResIdLong);
       
  1323 
       
  1324     MMIDCommand* cmd = CMIDCommand::NewL(shortLabel, longLabel, MMIDCommand::EItem, 0, aCommandId);
       
  1325     CleanupStack::PushL(cmd);
       
  1326 
       
  1327     STATIC_CAST(CMIDCommand*,cmd)->SetObserver(this);
       
  1328 
       
  1329     aArray.AppendL(cmd);
       
  1330     CleanupStack::Pop(cmd);
       
  1331 }
       
  1332 
       
  1333 /**
       
  1334 Creates and adds new command to array, short label is the same as long label.
       
  1335 */
       
  1336 void CMIDTextBoxQueryDialog::AddCommandToArrayL(RPointerArray<MMIDCommand>& aArray,
       
  1337         TInt aCommandResId, TInt aCommandId)
       
  1338 {
       
  1339     AddCommandToArrayL(aArray, aCommandResId, aCommandResId, aCommandId);
       
  1340 }
       
  1341 
       
  1342 /** This method is called from the destructor and removes
       
  1343     the commands added by CreateNonMidletCommandsL(). To do
       
  1344     this we examine cmds on the list (either of the displayable
       
  1345     or the item as applicable) and remove those whose observer is us.
       
  1346     */
       
  1347 void CMIDTextBoxQueryDialog::RemoveNonMidletCommands()
       
  1348 {
       
  1349     CMIDCommandList* list = NULL;
       
  1350     if (iDisplayable)
       
  1351     {
       
  1352         list = STATIC_CAST(CMIDDisplayable*, iDisplayable)->MainCommandList();
       
  1353     }
       
  1354 
       
  1355     if (!list)
       
  1356     {
       
  1357         return;
       
  1358     }
       
  1359 
       
  1360     for (TInt i = 0; i < list->Count(); i++)
       
  1361     {
       
  1362         CMIDCommand* cmd = list->At(i).iCommand;
       
  1363         if (cmd && (cmd->Observer() == this))
       
  1364         {
       
  1365             list->Remove(cmd);
       
  1366             cmd->Dispose();
       
  1367             i--;
       
  1368         }
       
  1369     }
       
  1370 }
       
  1371 
       
  1372 void CMIDTextBoxQueryDialog::AddCommandsToEdwinL(RPointerArray<MMIDCommand>& aArray)
       
  1373 {
       
  1374     for (TInt i = 0; i < aArray.Count(); i++)
       
  1375     {
       
  1376         STATIC_CAST(CMIDDisplayable*, iDisplayable)->AddCommandL(aArray[i]);
       
  1377     }
       
  1378 }
       
  1379 
       
  1380 void CMIDTextBoxQueryDialog::CreatePhoneCallL()
       
  1381 {
       
  1382     iEdwinUtils->CreatePhoneCallL(Size(), CCoeEnv::Static()->WsSession(), iEditor);
       
  1383 }
       
  1384 
       
  1385 void CMIDTextBoxQueryDialog::CreatePasswordTextL()
       
  1386 {
       
  1387     CGlobalText* oldGText = STATIC_CAST(CGlobalText*,iEditor->Text());
       
  1388     CPasswordBoxGlobalText* text = new(ELeave) CPasswordBoxGlobalText
       
  1389     (oldGText->GlobalParaFormatLayer(),oldGText->GlobalCharFormatLayer(),*iEditor);
       
  1390     CleanupStack::PushL(text);
       
  1391     text->ConstructL();
       
  1392     CleanupStack::Pop(text);
       
  1393 
       
  1394     CPlainText*  editorText = iEditor->Text();
       
  1395     delete editorText;
       
  1396     editorText = NULL;
       
  1397 
       
  1398     iEditor->SetDocumentContentL(*text,CEikEdwin::EUseText);
       
  1399 }
       
  1400 
       
  1401 void CMIDTextBoxQueryDialog::UpdateInitialInputModes()
       
  1402 {
       
  1403     // when becoming the current Displayable, set editor input mode
       
  1404     // to the one set by SetInitialInputModeL
       
  1405     if (((iConstraints & MMIDTextField::EConstraintMask) == MMIDTextField::EAny ||
       
  1406             (iConstraints & MMIDTextField::EConstraintMask) == MMIDTextField::EMailAddr ||
       
  1407             (iConstraints & MMIDTextField::EConstraintMask) == MMIDTextField::EUrl))
       
  1408     {
       
  1409         if (iInitialCurrentLanguage)
       
  1410         {
       
  1411             iEditor->SetAknEditorLocalLanguage(iInitialCurrentLanguage);
       
  1412             if (iInitialCurrentInputMode == 0)
       
  1413             {
       
  1414                 // clears any number mode used previously
       
  1415                 iEditor->SetAknEditorCurrentInputMode(EAknEditorNullInputMode);
       
  1416             }
       
  1417         }
       
  1418 
       
  1419         if (iInitialCurrentInputMode)
       
  1420         {
       
  1421             iEditor->SetAknEditorCurrentInputMode(iInitialCurrentInputMode);
       
  1422         }
       
  1423 
       
  1424         if (iInitialCurrentCase)
       
  1425         {
       
  1426             if ((iConstraints & MMIDTextField::EPassword ||
       
  1427                     iConstraints & MMIDTextField::EMailAddr ||
       
  1428                     iConstraints & MMIDTextField::EUrl) &&
       
  1429                     iInitialCurrentCase == EAknEditorTextCase)
       
  1430             {
       
  1431                 // Text case is not used in passwords, emailaddrs and urls
       
  1432                 iInitialCurrentCase = EAknEditorLowerCase;
       
  1433             }
       
  1434             iEditor->SetAknEditorCurrentCase(iInitialCurrentCase);
       
  1435             iEditor->SetAknEditorCase(iInitialCurrentCase);
       
  1436         }
       
  1437     }
       
  1438 }
       
  1439 
       
  1440 TTypeUid::Ptr CMIDTextBoxQueryDialog::MopSupplyObject(TTypeUid aId)
       
  1441 {
       
  1442     if (aId.iUid == CEikMenuBar::ETypeId)
       
  1443     {
       
  1444         if (iDisplayable && iDisplayable->MenuHandler())
       
  1445         {
       
  1446             return SupplyMopObject(aId,
       
  1447                                    iDisplayable->MenuHandler()->Cba(),
       
  1448                                    iDisplayable->MenuHandler()->MenuBar());
       
  1449         }
       
  1450     }
       
  1451     return CAknTextQueryDialog::MopSupplyObject(aId);
       
  1452 }
       
  1453 
       
  1454 // End of file