932 & MMIDTextField::EConstraintMask) == MMIDTextField::EDecimal)) |
932 & MMIDTextField::EConstraintMask) == MMIDTextField::EDecimal)) |
933 { |
933 { |
934 TInt illegalCharPos = -1; |
934 TInt illegalCharPos = -1; |
935 TPtr16 ptr = res->Des(); |
935 TPtr16 ptr = res->Des(); |
936 TInt minusPos = ptr.LocateReverse(TChar('-')); |
936 TInt minusPos = ptr.LocateReverse(TChar('-')); |
937 iStrict = EFalse; |
937 TInt pointPosL = ptr.Locate(iDecimalSeparator); |
|
938 TInt pointPosR = ptr.LocateReverse(iDecimalSeparator); |
|
939 TInt cursorPos = GetCaretPosition(); |
938 |
940 |
939 // check if minus sign is inserted on incorrect place |
941 // check if minus sign is inserted on incorrect place |
940 // (not at the beginning) |
942 // (not at the beginning) |
941 if ((minusPos != KErrNotFound) && (minusPos != 0)) |
943 if ((minusPos != KErrNotFound) && (minusPos != 0)) |
942 { |
944 { |
949 else |
951 else |
950 { |
952 { |
951 ptr.Delete(minusPos, 1); |
953 ptr.Delete(minusPos, 1); |
952 ptr.Insert(0, KMinusChar); |
954 ptr.Insert(0, KMinusChar); |
953 minusPos = 0; |
955 minusPos = 0; |
|
956 iStrict = EFalse; |
|
957 |
|
958 // Decimal separator was inserted twice and minus |
|
959 // was next character in text. Minus was just set as first |
|
960 // character - so in fact we have two decimal separators |
|
961 // after minus character - this is not allowed, |
|
962 // delete extra character |
|
963 if (pointPosL != pointPosR && pointPosL == 0 && |
|
964 minusPos == pointPosL) |
|
965 { |
|
966 // Delete both decimal separator characters |
|
967 // and place new decimal separator in correct position |
|
968 ptr.Delete(pointPosR, 1); |
|
969 ptr.Delete((pointPosL + 1), 1); |
|
970 ptr.Insert(1, KFullStopChar); |
|
971 } |
954 SetTextL(*res); |
972 SetTextL(*res); |
955 textChanged = ETrue; |
973 textChanged = ETrue; |
|
974 |
|
975 // Set correct cusros possition |
|
976 if (pointPosL == 0 && minusPos == pointPosL) |
|
977 { |
|
978 SetCursorPositionL(pointPosL + 1); |
|
979 } |
956 } |
980 } |
957 } |
981 } |
958 |
982 |
959 TInt pointPosL = ptr.Locate(iDecimalSeparator); |
983 // Locate decimal separator again |
960 TInt pointPosR = ptr.LocateReverse(iDecimalSeparator); |
984 pointPosL = ptr.Locate(iDecimalSeparator); |
961 TInt cursorPos = GetCaretPosition(); |
985 pointPosR = ptr.LocateReverse(iDecimalSeparator); |
|
986 cursorPos = GetCaretPosition(); |
|
987 |
962 if ((minusPos != KErrNotFound) && (pointPosL == 0)) |
988 if ((minusPos != KErrNotFound) && (pointPosL == 0)) |
963 { |
989 { |
964 illegalCharPos = pointPosL; |
990 illegalCharPos = pointPosL; |
965 } |
991 } |
966 else if (pointPosL != pointPosR) |
992 else if (pointPosL != pointPosR) |
972 if (illegalCharPos >= 0) |
998 if (illegalCharPos >= 0) |
973 { |
999 { |
974 // deleting second minus or dot/comma char |
1000 // deleting second minus or dot/comma char |
975 // and set cursor position on the right place |
1001 // and set cursor position on the right place |
976 ptr.Delete(illegalCharPos, 1); |
1002 ptr.Delete(illegalCharPos, 1); |
|
1003 iStrict = EFalse; |
977 SetTextL(*res); |
1004 SetTextL(*res); |
978 textChanged = ETrue; |
1005 textChanged = ETrue; |
979 if (cursorPos >= 1) |
1006 if (cursorPos >= 1) |
980 { |
1007 { |
981 if (cursorPos == illegalCharPos) |
1008 if (cursorPos == (illegalCharPos + 1)) |
982 { |
1009 { |
983 cursorPos--; |
1010 cursorPos--; |
984 } |
1011 } |
985 SetCursorPositionL(cursorPos); |
1012 SetCursorPositionL(cursorPos); |
986 } |
1013 } |
994 // In EMAIL and URL mode, don't allow changes that would result |
1021 // In EMAIL and URL mode, don't allow changes that would result |
995 // in an illegal string; if there is '/n' or '/f', and line breaks |
1022 // in an illegal string; if there is '/n' or '/f', and line breaks |
996 // are not supported, chars need to be changed to space |
1023 // are not supported, chars need to be changed to space |
997 // SetText function before actual text change checks if line |
1024 // SetText function before actual text change checks if line |
998 // breaks are not supported |
1025 // breaks are not supported |
999 SetTextL(*res); |
1026 TPtr16 text = res->Des(); |
|
1027 TInt tmpPos; |
|
1028 |
|
1029 if ((text.Locate(TChar('\n'))) >=0 || |
|
1030 (text.Locate(TChar('\f'))) >=0) |
|
1031 { |
|
1032 tmpPos = GetCaretPosition(); |
|
1033 SetTextL(*res); |
|
1034 SetCursorPositionL(tmpPos); |
|
1035 } |
|
1036 |
1000 textChanged = ETrue; |
1037 textChanged = ETrue; |
1001 } |
1038 } |
1002 CleanupStack::Pop(res); |
1039 CleanupStack::Pop(res); |
1003 delete res; |
1040 delete res; |
1004 |
1041 |