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 { |
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 { |