javauis/lcdui_akn/lcdui/src/CMIDTextBoxQueryDialog.cpp
branchRCL_3
changeset 19 71c436fe3ce0
parent 18 9ac0a0a7da70
child 21 4376525cdefb
equal deleted inserted replaced
18:9ac0a0a7da70 19:71c436fe3ce0
    86 
    86 
    87     iEdwinUtils = CMIDEdwinUtils::NewL(this, iDecimalSeparator);
    87     iEdwinUtils = CMIDEdwinUtils::NewL(this, iDecimalSeparator);
    88 
    88 
    89     iConstraints = aConstraints;
    89     iConstraints = aConstraints;
    90     iLastCountLine = 0;
    90     iLastCountLine = 0;
       
    91     iStrict = ETrue;
       
    92 
    91     // if text is invalid according to constraints, throw IllegalArgumentException,
    93     // if text is invalid according to constraints, throw IllegalArgumentException,
    92     // except for a PHONENUMBER which only has the invalid characters removed
    94     // except for a PHONENUMBER which only has the invalid characters removed
    93     if ((iConstraints & MMIDTextField::EConstraintMask) != MMIDTextField::EPhoneNumber
    95     if ((iConstraints & MMIDTextField::EConstraintMask) != MMIDTextField::EPhoneNumber
    94             && !iEdwinUtils->ConstraintsValidForText(aText,iConstraints,ETrue))
    96             && !iEdwinUtils->ConstraintsValidForText(aText,iConstraints,ETrue))
    95     {
    97     {
   219     // if text is invalid according to constraints, throw IllegalArgumentException,
   221     // if text is invalid according to constraints, throw IllegalArgumentException,
   220     //  except for a PHONENUMBER which only has the invalid characters removed
   222     //  except for a PHONENUMBER which only has the invalid characters removed
   221     if ((iConstraints & MMIDTextField::EConstraintMask) == MMIDTextField::EPhoneNumber)
   223     if ((iConstraints & MMIDTextField::EConstraintMask) == MMIDTextField::EPhoneNumber)
   222     {
   224     {
   223     }
   225     }
   224     else if (!iEdwinUtils->ConstraintsValidForText(aText, iConstraints, ETrue))
   226     else if (!iEdwinUtils->ConstraintsValidForText(aText, iConstraints, (iStrict ? ETrue : EFalse)))
   225     {
   227     {
   226         User::Leave(KErrArgument);
   228         User::Leave(KErrArgument);
   227     }
   229     }
   228     //
   230     iStrict = ETrue;
   229 
   231 
   230     HBufC* buf = iEdwinUtils->ConvertToLocalizedLC(aText, iConstraints);
   232     HBufC* buf = iEdwinUtils->ConvertToLocalizedLC(aText, iConstraints);
   231 
   233 
   232     if (IsNumberConversionNeeded())
   234     if (IsNumberConversionNeeded())
   233     {
   235     {
   288         iEditor->ClearSelectionL();
   290         iEditor->ClearSelectionL();
   289     }
   291     }
   290 
   292 
   291     temp = iEdwinUtils->ConvertToLocalizedLC(aText, iConstraints);
   293     temp = iEdwinUtils->ConvertToLocalizedLC(aText, iConstraints);
   292 
   294 
   293 
       
   294     if (IsNumberConversionNeeded())
   295     if (IsNumberConversionNeeded())
   295     {
   296     {
   296         TPtr ptr = temp->Des();
   297         TPtr ptr = temp->Des();
   297         AknTextUtils::LanguageSpecificNumberConversion(ptr);
   298         AknTextUtils::LanguageSpecificNumberConversion(ptr);
   298     }
   299     }
   453 }
   454 }
   454 
   455 
   455 void CMIDTextBoxQueryDialog::FocusChanged(TDrawNow aDrawNow)
   456 void CMIDTextBoxQueryDialog::FocusChanged(TDrawNow aDrawNow)
   456 {
   457 {
   457     CAknTextQueryDialog::FocusChanged(aDrawNow);
   458     CAknTextQueryDialog::FocusChanged(aDrawNow);
   458     TBool isFocused = IsFocused();
       
   459     SetRightScrollBarPosition();
   459     SetRightScrollBarPosition();
   460 }
   460 }
   461 //
   461 //
   462 // We do not want to become visible if we are not showing
   462 // We do not want to become visible if we are not showing
   463 //
   463 //
   602 
   602 
   603     //
   603     //
   604     //  End Enter Key
   604     //  End Enter Key
   605     //
   605     //
   606 
   606 
   607 
       
   608     // msk: this is needed if MSK is not enabled on the device
   607     // msk: this is needed if MSK is not enabled on the device
   609     if ((aType == EEventKey) && (aKeyEvent.iScanCode == EStdKeyDevice3))
   608     if ((aType == EEventKey) && (aKeyEvent.iScanCode == EStdKeyDevice3))
   610     {
   609     {
   611         iDisplayable->ShowOkOptionsMenuL();
   610         if (iDisplayable && iDisplayable->ShowOkOptionsMenuL())
   612         return EKeyWasConsumed;
   611         {
   613     }
   612             SetFocus(EFalse);
   614 
   613         }
   615 
       
   616     // msk: this is needed if MSK is not enabled on the device
       
   617     if ((aType == EEventKey) && (aKeyEvent.iScanCode == EStdKeyDevice3))
       
   618     {
       
   619         iDisplayable->ShowOkOptionsMenuL();
       
   620         return EKeyWasConsumed;
   614         return EKeyWasConsumed;
   621     }
   615     }
   622 
   616 
   623     // store the key pressed last time, used for warning beeps while reaching size limit
   617     // store the key pressed last time, used for warning beeps while reaching size limit
   624     if (aType == EEventKeyDown)
   618     if (aType == EEventKeyDown)
   682 #endif // RD_SCALABLE_UI_V2
   676 #endif // RD_SCALABLE_UI_V2
   683             ((scanCode==EStdKeyMinus) || (scanCode==EStdKeyFullStop)))
   677             ((scanCode==EStdKeyMinus) || (scanCode==EStdKeyFullStop)))
   684     {
   678     {
   685         CPlainText* res = iEditor->Text();
   679         CPlainText* res = iEditor->Text();
   686         TInt textLength = Size();
   680         TInt textLength = Size();
   687         if (scanCode == EStdKeyMinus)
   681         if (scanCode == EStdKeyMinus && textLength < iMaxSize)
   688         {
   682         {
   689             res->InsertL(GetCaretPosition(), KMinusChar);
   683             res->InsertL(GetCaretPosition(), KMinusChar);
   690         }
   684         }
   691         else if (scanCode == EStdKeyFullStop)
   685         else if (scanCode == EStdKeyFullStop && textLength < iMaxSize)
   692         {
   686         {
   693             res->InsertL(GetCaretPosition(), KFullStopChar);
   687             res->InsertL(GetCaretPosition(), KFullStopChar);
   694         }
   688         }
   695 
   689 
   696         iEditor->HandleTextChangedL(); // notify editor about the text changes
   690         iEditor->HandleTextChangedL(); // notify editor about the text changes
   697 
   691 
   698         if (Size() < iMaxSize)
   692         if (Size() < iMaxSize)
   699         {
   693         {
   700             SetCursorPositionL(GetCaretPosition() + 1);
   694             SetCursorPositionL(GetCaretPosition() + 1);
   701         }
   695         }
       
   696 
       
   697         HandleTextUpdateL(MEikEdwinObserver::EEventTextUpdate);
   702     }
   698     }
   703     //Error tone playing case1:
   699     //Error tone playing case1:
   704     //Play error tone if TextBox/TextField is read-only or maximum length has been reached.
   700     //Play error tone if TextBox/TextField is read-only or maximum length has been reached.
   705     //Here is handling of keys 0...9 for full keyboard and itu-t, but NOT virtual keyboard.
   701     //Here is handling of keys 0...9 for full keyboard and itu-t, but NOT virtual keyboard.
   706     if (aType == EEventKeyDown
   702     if (aType == EEventKeyDown
   765         return EKeyWasConsumed;
   761         return EKeyWasConsumed;
   766     }
   762     }
   767 
   763 
   768 
   764 
   769     TKeyResponse response = EKeyWasNotConsumed;
   765     TKeyResponse response = EKeyWasNotConsumed;
   770 
   766     TBool isFocused = IsFocused();
   771     //Error tone playing case2:
   767 
   772     //Play error tone if TextBox/TextField is read-only or maximum length has been reached.
   768     // If there is no focus textbox should not consume keys
   773     //Here is handling of full keyboard keys(NOT 0...9) and all virtual keyboard keys.
   769     if (isFocused)
   774     //(Note: Virtual keyboard sends only EEventKey type events, not up or down events)
   770     {
   775     //(Note: Error tone is played when there is no text to be replaced i.e. no text has been painted)
   771         //Error tone playing case2:
   776     if (!iEdwinUtils->IsNavigationKey(aKeyEvent) && !iEdwinUtils->IsHotKeyL(aKeyEvent, iCoeEnv) && !aKeyEvent.iCode == EKeyYes &&
   772         //Play error tone if TextBox/TextField is read-only or maximum length has been reached.
   777             (!iKeyEventsPending || (scanCode < KKeyQwerty0  || scanCode > KKeyQwerty9)))
   773         //Here is handling of full keyboard keys(NOT 0...9) and all virtual keyboard keys.
   778     {
   774         //(Note: Virtual keyboard sends only EEventKey type events, not up or down events)
   779         if (iEditor->IsReadOnly() || (Size() >= iMaxSize && aKeyEvent.iCode != EKeyBackspace))
   775         //(Note: Error tone is played when there is no text to be replaced i.e. no text has been painted)
   780         {
   776         if (!iEdwinUtils->IsNavigationKey(aKeyEvent) && !iEdwinUtils->IsHotKeyL(aKeyEvent, iCoeEnv) && !aKeyEvent.iCode == EKeyYes &&
   781             //SelectionLength() > 0 if text has been selected/painted
   777                 (!iKeyEventsPending || (scanCode < KKeyQwerty0  || scanCode > KKeyQwerty9)))
   782             if (iEditor->SelectionLength() == 0)
   778         {
   783             {
   779             if (iEditor->IsReadOnly() || (Size() >= iMaxSize && aKeyEvent.iCode != EKeyBackspace))
   784                 iAvkonAppUi->KeySounds()->PlaySound(EAvkonSIDErrorTone);
   780             {
   785             }
   781                 //SelectionLength() > 0 if text has been selected/painted
   786             response = iEditor->OfferKeyEventL(aKeyEvent,aType);
   782                 if (iEditor->SelectionLength() == 0)
       
   783                 {
       
   784                     iAvkonAppUi->KeySounds()->PlaySound(EAvkonSIDErrorTone);
       
   785                 }
       
   786                 response = iEditor->OfferKeyEventL(aKeyEvent,aType);
       
   787                 return response;
       
   788             }
       
   789         }
       
   790 
       
   791         TBool valid = EFalse;
       
   792 
       
   793         if (iEdwinUtils->IsNavigationKey(aKeyEvent) || iEdwinUtils->IsHotKeyL(aKeyEvent, iCoeEnv))
       
   794         {
       
   795             HBufC* oldText = GetTextL();
       
   796             CleanupStack::PushL(oldText);
       
   797             TCursorSelection sel = iEditor->Selection();
       
   798 
       
   799             response = CAknTextQueryDialog::OfferKeyEventL(aKeyEvent,aType);
       
   800             valid = iEdwinUtils->ConstraintsValidForText(iEditor->Text()?Read():TPtrC(),iConstraints,EFalse);
       
   801 
       
   802             if (!valid)
       
   803             {
       
   804                 SetTextL(*oldText);
       
   805                 iEditor->HandleTextChangedL();
       
   806                 iEditor->SetSelectionL(sel.iCursorPos,sel.iAnchorPos);
       
   807                 response = EKeyWasConsumed;
       
   808             }
       
   809             CleanupStack::PopAndDestroy(oldText);
       
   810 
   787             return response;
   811             return response;
   788         }
   812         }
   789     }
   813         else
   790 
   814         {
   791     TBool valid = EFalse;
   815             TBuf<1> key;
   792 
   816             key.Append(TChar(aKeyEvent.iCode));
   793     if (iEdwinUtils->IsNavigationKey(aKeyEvent) || iEdwinUtils->IsHotKeyL(aKeyEvent, iCoeEnv))
   817             valid = iEdwinUtils->ConstraintsValidForInsertedTextL(iEditor->Text()?Read():TPtrC(),
   794     {
   818                     key,
   795         HBufC* oldText = GetTextL();
   819                     GetCaretPosition(),
   796         CleanupStack::PushL(oldText);
   820                     iConstraints,
   797         TCursorSelection sel = iEditor->Selection();
   821                     EFalse);
   798 
   822             if (valid)
   799         response = CAknTextQueryDialog::OfferKeyEventL(aKeyEvent,aType);
   823             {
   800         valid = iEdwinUtils->ConstraintsValidForText(iEditor->Text()?Read():TPtrC(),iConstraints,EFalse);
   824                 response = iEditor->OfferKeyEventL(aKeyEvent,aType);
   801 
   825             }
   802         if (!valid)
   826             else
   803         {
   827             {
   804             SetTextL(*oldText);
   828                 // If minus char was entered in full querty editor mode
   805             iEditor->HandleTextChangedL();
   829                 if (IsConstraintSet(MMIDTextField::EDecimal) &&
   806             iEditor->SetSelectionL(sel.iCursorPos,sel.iAnchorPos);
   830                         (aType == EEventKey) && iEditor && !iEditor->IsReadOnly() &&
   807             response = EKeyWasConsumed;
   831                         (TChar(aKeyEvent.iCode) == TChar('-') && scanCode != EStdKeyMinus))
   808         }
   832                 {
   809         CleanupStack::PopAndDestroy(oldText);
   833                     CPlainText* res = iEditor->Text();
   810 
   834 
   811         return response;
   835                     if (res && TChar(aKeyEvent.iCode) == TChar('-') &&
   812     }
   836                             Size() < iMaxSize)
   813     else
   837                     {
   814     {
   838                         res->InsertL(GetCaretPosition(), KMinusChar);
   815         TBuf<1> key;
   839                         // notify editor about the text changes
   816         key.Append(TChar(aKeyEvent.iCode));
   840                         iEditor->HandleTextChangedL();
   817         valid = iEdwinUtils->ConstraintsValidForInsertedTextL(iEditor->Text()?Read():TPtrC(),
   841 
   818                 key,
   842                         if (Size() < iMaxSize)
   819                 GetCaretPosition(),
   843                         {
   820                 iConstraints,
   844                             SetCursorPositionL(GetCaretPosition() + 1);
   821                 EFalse);
   845                         }
   822         if (valid)
   846 
   823         {
   847                         //Prevent changes that would result in an illegal string
   824             response = iEditor->OfferKeyEventL(aKeyEvent,aType);
   848                         HandleTextUpdateL(MEikEdwinObserver::EEventTextUpdate);
   825         }
   849                     }
   826         return response;
   850                 }
   827     }
   851 
       
   852             }
       
   853             return response;
       
   854         }
       
   855     }
       
   856     return response;
   828 }
   857 }
   829 
   858 
   830 #ifdef RD_SCALABLE_UI_V2
   859 #ifdef RD_SCALABLE_UI_V2
   831 void CMIDTextBoxQueryDialog::HandlePointerEventL(const TPointerEvent &aPointerEvent)
   860 void CMIDTextBoxQueryDialog::HandlePointerEventL(const TPointerEvent &aPointerEvent)
   832 {
   861 {
   867         {
   896         {
   868             iThisMultitapKey = 0;
   897             iThisMultitapKey = 0;
   869             iLastMultitapKey = 0;
   898             iLastMultitapKey = 0;
   870         }
   899         }
   871 
   900 
       
   901         HandleTextUpdateL(MEikEdwinObserver::EEventTextUpdate);
       
   902 
       
   903         if (iEditor && iEditor->TextLayout())
       
   904         {
       
   905             if (iLastCountLine != iEditor->TextLayout()->GetLineNumber(iEditor->TextLength() - 1))
       
   906             {
       
   907                 iLastCountLine = iEditor->TextLayout()->GetLineNumber(iEditor->TextLength() - 1);
       
   908                 SetRightScrollBarPosition();
       
   909             }
       
   910         }
       
   911     }
       
   912 }
       
   913 
       
   914 void CMIDTextBoxQueryDialog::HandleTextUpdateL(TEdwinEvent aEventType)
       
   915 {
       
   916     if (aEventType == MEikEdwinObserver::EEventTextUpdate)
       
   917     {
   872         TBool textChanged = EFalse;
   918         TBool textChanged = EFalse;
   873         HBufC* res = NULL;
   919         HBufC* res = NULL;
   874         TRAPD(err, { res = GetTextL();});
   920         TRAPD(err, { res = GetTextL();});
   875         if (err != KErrNone || !res)
   921         if (err != KErrNone || !res)
   876         {
   922         {
   886                 & MMIDTextField::EConstraintMask) == MMIDTextField::EDecimal))
   932                 & MMIDTextField::EConstraintMask) == MMIDTextField::EDecimal))
   887         {
   933         {
   888             TInt illegalCharPos = -1;
   934             TInt illegalCharPos = -1;
   889             TPtr16 ptr = res->Des();
   935             TPtr16 ptr = res->Des();
   890             TInt minusPos = ptr.LocateReverse(TChar('-'));
   936             TInt minusPos = ptr.LocateReverse(TChar('-'));
       
   937             iStrict = EFalse;
   891 
   938 
   892             // check if minus sign is inserted on incorrect place
   939             // check if minus sign is inserted on incorrect place
   893             // (not at the beginning)
   940             // (not at the beginning)
   894             if ((minusPos != KErrNotFound) && (minusPos != 0))
   941             if ((minusPos != KErrNotFound) && (minusPos != 0))
   895             {
   942             {
   958         // if there were any modifications the text is updated
  1005         // if there were any modifications the text is updated
   959         if (textChanged)
  1006         if (textChanged)
   960         {
  1007         {
   961             iEditor->HandleTextChangedL();
  1008             iEditor->HandleTextChangedL();
   962         }
  1009         }
   963         if (iEditor && iEditor->TextLayout())
       
   964         {
       
   965             if (iLastCountLine != iEditor->TextLayout()->GetLineNumber(iEditor->TextLength() - 1))
       
   966             {
       
   967                 iLastCountLine = iEditor->TextLayout()->GetLineNumber(iEditor->TextLength() - 1);
       
   968                 SetRightScrollBarPosition();
       
   969             }
       
   970         }
       
   971     }
  1010     }
   972 }
  1011 }
   973 
  1012 
   974 void CMIDTextBoxQueryDialog::GetCaptionForFep(TDes& aCaption) const
  1013 void CMIDTextBoxQueryDialog::GetCaptionForFep(TDes& aCaption) const
   975 {
  1014 {
  1489 
  1528 
  1490 }
  1529 }
  1491 
  1530 
  1492 void CMIDTextBoxQueryDialog::SetRightScrollBarPosition()
  1531 void CMIDTextBoxQueryDialog::SetRightScrollBarPosition()
  1493 {
  1532 {
  1494     if (iEditor)
  1533     // Editor Rect should not be set with empty values
       
  1534     if (iEditor && iEditorRect.Height() != 0 && iEditorRect.Width() != 0)
  1495     {
  1535     {
  1496         iEditor->SetRect(iEditorRect);
  1536         iEditor->SetRect(iEditorRect);
  1497     }
  1537     }
  1498 }
  1538 }
  1499 // End of file
  1539 // End of file