javauis/lcdui_qt/src/javax/microedition/lcdui/TextWrapper.java
changeset 35 85266cc22c7f
parent 23 98ccebc37403
equal deleted inserted replaced
26:dc7c549001d5 35:85266cc22c7f
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 package javax.microedition.lcdui;
    17 package javax.microedition.lcdui;
    18 
    18 
    19 import org.eclipse.ercp.swt.mobile.ConstrainedText;
       
    20 import org.eclipse.ercp.swt.mobile.TextExtension;
    19 import org.eclipse.ercp.swt.mobile.TextExtension;
       
    20 import org.eclipse.swt.internal.extension.TextExtensionExtension;
    21 import org.eclipse.swt.SWT;
    21 import org.eclipse.swt.SWT;
    22 import org.eclipse.swt.events.ModifyListener;
    22 import org.eclipse.swt.events.ModifyListener;
    23 import org.eclipse.swt.events.SelectionListener;
    23 import org.eclipse.swt.events.SelectionListener;
    24 import org.eclipse.swt.graphics.Color;
    24 import org.eclipse.swt.graphics.Color;
    25 import org.eclipse.swt.graphics.Rectangle;
    25 import org.eclipse.swt.graphics.Rectangle;
   324                 {
   324                 {
   325                     if(control instanceof TextExtension)
   325                     if(control instanceof TextExtension)
   326                     {
   326                     {
   327                         retTopPixel = ((TextExtension) control).getTopPixel();
   327                         retTopPixel = ((TextExtension) control).getTopPixel();
   328                     }
   328                     }
   329                     // ConstrainedText does not scroll -> value is 0
       
   330                 }
   329                 }
   331             });
   330             });
   332         }
   331         }
   333         return retTopPixel;
   332         return retTopPixel;
   334     }
   333     }
   835         {
   834         {
   836             if(control instanceof TextExtension)
   835             if(control instanceof TextExtension)
   837             {
   836             {
   838                 ((TextExtension) control).addModifyListener(ltnr);
   837                 ((TextExtension) control).addModifyListener(ltnr);
   839             }
   838             }
   840             else
       
   841             {
       
   842                 ((ConstrainedText) control).addModifyListener(ltnr);
       
   843             }
       
   844         }
   839         }
   845     }
   840     }
   846 
   841 
   847     /**
   842     /**
   848      * Add selection listener.
   843      * Add selection listener.
   855         if(control != null && ltnr != null)
   850         if(control != null && ltnr != null)
   856         {
   851         {
   857             if(control instanceof TextExtension)
   852             if(control instanceof TextExtension)
   858             {
   853             {
   859                 ((TextExtension) control).addSelectionListener(ltnr);
   854                 ((TextExtension) control).addSelectionListener(ltnr);
   860             }
       
   861             else
       
   862             {
       
   863                 ((ConstrainedText) control).addSelectionListener(ltnr);
       
   864             }
   855             }
   865         }
   856         }
   866     }
   857     }
   867 
   858 
   868     /**
   859     /**
   873      * @param aConstraints
   864      * @param aConstraints
   874      * @return
   865      * @return
   875      */
   866      */
   876     static Control eswtConstructText(Composite parent, int aStyle, int aConstraints)
   867     static Control eswtConstructText(Composite parent, int aStyle, int aConstraints)
   877     {
   868     {
   878         Control ret = null;
       
   879 
   869 
   880         int style = aStyle;
   870         int style = aStyle;
   881         int extractedFlag = aConstraints & ~TextField.CONSTRAINT_MASK;
   871         int extractedFlag = aConstraints & ~TextField.CONSTRAINT_MASK;
   882         int extractedConstraint = aConstraints & TextField.CONSTRAINT_MASK;
   872         int extractedConstraint = aConstraints & TextField.CONSTRAINT_MASK;
   883 
   873 
   884         if((extractedFlag & TextField.PASSWORD) == TextField.PASSWORD)
   874         if((extractedFlag & TextField.PASSWORD) == TextField.PASSWORD)
   885         {
   875         {
   886             // Text class will remove incompatible flags for SINGLE
   876             // Text class will remove incompatible flags for SINGLE
       
   877             style &= ~SWT.MULTI;
   887             style |= SWT.SINGLE | SWT.PASSWORD;
   878             style |= SWT.SINGLE | SWT.PASSWORD;
   888         }
   879         }
   889         if((extractedFlag & TextField.UNEDITABLE) == TextField.UNEDITABLE)
   880         if((extractedFlag & TextField.UNEDITABLE) == TextField.UNEDITABLE)
   890         {
   881         {
   891             style |= SWT.READ_ONLY;
   882             style |= SWT.READ_ONLY;
   892         }
   883         }
   893 
   884 
   894         if(extractedConstraint == TextField.NUMERIC)
   885         if(extractedConstraint == TextField.NUMERIC)
   895         {
   886         {
   896             ret = new ConstrainedText(parent, style, ConstrainedText.NUMERIC);
   887             extractedConstraint = TextExtensionExtension.NUMERIC;
   897         }
   888         }
   898         else if(extractedConstraint == TextField.DECIMAL)
   889         else if(extractedConstraint == TextField.DECIMAL)
   899         {
   890         {
   900             ret = new ConstrainedText(parent, style, ConstrainedText.DECIMAL);
   891             extractedConstraint = TextExtensionExtension.DECIMAL;
   901         }
   892         }
   902         else if(extractedConstraint == TextField.PHONENUMBER)
   893         else if(extractedConstraint == TextField.PHONENUMBER)
   903         {
   894         {
   904             ret = new ConstrainedText(parent, style, ConstrainedText.PHONENUMBER);
   895             extractedConstraint = TextExtensionExtension.PHONENUMBER;
   905         }
   896        }
   906         else if(extractedConstraint == TextField.NON_PREDICTIVE
   897        else {
   907                 || extractedConstraint == TextField.SENSITIVE)
   898             extractedConstraint = 0;
   908         {
   899        }
   909             // We treat non-predictive and sensitive to be equal
   900         return new TextExtensionExtension(parent, style,extractedConstraint);
   910             ret = new TextExtension(parent, style, TextExtension.NON_PREDICTIVE);
   901     }
   911         }
   902 
   912         else
   903     /**
   913         {
   904      * Get caret position.
   914             ret = new TextExtension(parent, style);
   905      *
       
   906      * @param control text control
       
   907      */
       
   908     static int eswtGetCaretPosition(Control control)
       
   909     {
       
   910         int ret = 0;
       
   911         if(control != null)
       
   912         {
       
   913             if(control instanceof TextExtension)
       
   914             {
       
   915                 ret = ((TextExtension) control).getCaretPosition();
       
   916             }
   915         }
   917         }
   916         return ret;
   918         return ret;
   917     }
   919     }
   918 
   920 
   919     /**
   921     /**
   920      * Get caret position.
   922      * Get caret line number.
   921      *
   923      *
   922      * @param control text control
   924      * @param control text control
   923      */
   925      */
   924     static int eswtGetCaretPosition(Control control)
   926     static int eswtGetCaretLine(Control control)
   925     {
   927     {
   926         int ret = 0;
   928         int ret = 0;
   927         if(control != null)
   929         if(control != null)
   928         {
   930         {
   929             if(control instanceof TextExtension)
   931             if(control instanceof TextExtension)
   930             {
   932             {
   931                 ret = ((TextExtension) control).getCaretPosition();
   933                 ret = ((TextExtension) control).getCaretLineNumber();
   932             }
       
   933             else
       
   934             {
       
   935                 ret = ((ConstrainedText) control).getCaretPosition();
       
   936             }
   934             }
   937         }
   935         }
   938         return ret;
   936         return ret;
   939     }
   937     }
   940 
   938 
   941     /**
   939     /**
   942      * Get caret line number.
   940      * Get content.
   943      *
   941      *
   944      * @param control text control
   942      * @param control text control
   945      */
   943      */
   946     static int eswtGetCaretLine(Control control)
   944     static String eswtGetContent(Control control)
       
   945     {
       
   946         String ret = "";
       
   947         if(control != null)
       
   948         {
       
   949             if(control instanceof TextExtension)
       
   950             {
       
   951                 ret = ((TextExtension) control).getText();
       
   952             }
       
   953         }
       
   954         return ret;
       
   955     }
       
   956 
       
   957     /**
       
   958      * Get line count.
       
   959      *
       
   960      * @param control text control
       
   961      */
       
   962     static int eswtGetLineCount(Control control)
       
   963     {
       
   964         int ret = 1;
       
   965         if(control != null)
       
   966         {
       
   967             if(control instanceof TextExtension)
       
   968             {
       
   969                 ret = ((TextExtension) control).getLineCount();
       
   970             }
       
   971         }
       
   972         return ret;
       
   973     }
       
   974 
       
   975     /**
       
   976      * Get line height.
       
   977      *
       
   978      * @param control text control
       
   979      */
       
   980     static int eswtGetLineHeight(Control control)
   947     {
   981     {
   948         int ret = 0;
   982         int ret = 0;
   949         if(control != null)
   983         if(control != null)
   950         {
   984         {
   951             if(control instanceof TextExtension)
   985             if(control instanceof TextExtension)
   952             {
   986             {
   953                 ret = ((TextExtension) control).getCaretLineNumber();
   987                 ret = ((TextExtension) control).getLineHeight();
   954             }
   988             }
   955         }
   989         }
   956         return ret;
   990         return ret;
   957     }
   991     }
   958 
   992 
   959     /**
   993     /**
   960      * Get content.
   994      * Get maximum content size.
   961      *
   995      *
   962      * @param control text control
   996      * @param control text control
   963      */
   997      */
   964     static String eswtGetContent(Control control)
   998     static int eswtGetMaxSize(Control control)
       
   999     {
       
  1000         int ret = 0;
       
  1001         if(control != null)
       
  1002         {
       
  1003             if(control instanceof TextExtension)
       
  1004             {
       
  1005                 ret = ((TextExtension) control).getTextLimit();
       
  1006             }
       
  1007         }
       
  1008         return ret;
       
  1009     }
       
  1010 
       
  1011     /**
       
  1012      * Get selected content.
       
  1013      *
       
  1014      * @param control text control
       
  1015      */
       
  1016     static String eswtGetSelectedContent(Control control)
   965     {
  1017     {
   966         String ret = "";
  1018         String ret = "";
   967         if(control != null)
  1019         if(control != null)
   968         {
  1020         {
   969             if(control instanceof TextExtension)
  1021             if(control instanceof TextExtension)
   970             {
  1022             {
   971                 ret = ((TextExtension) control).getText();
  1023                 ret = ((TextExtension) control).getSelectionText();
   972             }
       
   973             else
       
   974             {
       
   975                 ret = ((ConstrainedText) control).getText();
       
   976             }
  1024             }
   977         }
  1025         }
   978         return ret;
  1026         return ret;
   979     }
  1027     }
   980 
  1028 
   981     /**
  1029     /**
   982      * Get line count.
  1030      * Get content size.
   983      *
  1031      *
   984      * @param control text control
  1032      * @param control text control
   985      */
  1033      */
   986     static int eswtGetLineCount(Control control)
  1034     static int eswtGetSize(Control control)
   987     {
  1035     {
   988         int ret = 1;
  1036         int ret = 0;
   989         if(control != null)
  1037         if(control != null)
   990         {
  1038         {
   991             if(control instanceof TextExtension)
  1039             if(control instanceof TextExtension)
   992             {
  1040             {
   993                 ret = ((TextExtension) control).getLineCount();
  1041                 ret = ((TextExtension) control).getCharCount();
   994             }
  1042             }
   995         }
  1043         }
   996         return ret;
  1044         return ret;
   997     }
  1045     }
   998 
  1046 
   999     /**
  1047     /**
  1000      * Get line height.
       
  1001      *
       
  1002      * @param control text control
       
  1003      */
       
  1004     static int eswtGetLineHeight(Control control)
       
  1005     {
       
  1006         int ret = 0;
       
  1007         if(control != null)
       
  1008         {
       
  1009             if(control instanceof TextExtension)
       
  1010             {
       
  1011                 ret = ((TextExtension) control).getLineHeight();
       
  1012             }
       
  1013             else
       
  1014             {
       
  1015                 ret = ((ConstrainedText) control).getSize().y;
       
  1016             }
       
  1017         }
       
  1018         return ret;
       
  1019     }
       
  1020 
       
  1021     /**
       
  1022      * Get maximum content size.
       
  1023      *
       
  1024      * @param control text control
       
  1025      */
       
  1026     static int eswtGetMaxSize(Control control)
       
  1027     {
       
  1028         int ret = 0;
       
  1029         if(control != null)
       
  1030         {
       
  1031             if(control instanceof TextExtension)
       
  1032             {
       
  1033                 ret = ((TextExtension) control).getTextLimit();
       
  1034             }
       
  1035             else
       
  1036             {
       
  1037                 ret = ((ConstrainedText) control).getTextLimit();
       
  1038             }
       
  1039         }
       
  1040         return ret;
       
  1041     }
       
  1042 
       
  1043     /**
       
  1044      * Get selected content.
       
  1045      *
       
  1046      * @param control text control
       
  1047      */
       
  1048     static String eswtGetSelectedContent(Control control)
       
  1049     {
       
  1050         String ret = "";
       
  1051         if(control != null)
       
  1052         {
       
  1053             if(control instanceof TextExtension)
       
  1054             {
       
  1055                 ret = ((TextExtension) control).getSelectionText();
       
  1056             }
       
  1057             else
       
  1058             {
       
  1059                 // TODO: eSWT support required - get selection in ConstrainedText
       
  1060                 ret = ((ConstrainedText) control).getText();
       
  1061             }
       
  1062         }
       
  1063         return ret;
       
  1064     }
       
  1065 
       
  1066     /**
       
  1067      * Get content size.
       
  1068      *
       
  1069      * @param control text control
       
  1070      */
       
  1071     static int eswtGetSize(Control control)
       
  1072     {
       
  1073         int ret = 0;
       
  1074         if(control != null)
       
  1075         {
       
  1076             if(control instanceof TextExtension)
       
  1077             {
       
  1078                 ret = ((TextExtension) control).getCharCount();
       
  1079             }
       
  1080             else
       
  1081             {
       
  1082                 ret = ((ConstrainedText) control).getCharCount();
       
  1083             }
       
  1084         }
       
  1085         return ret;
       
  1086     }
       
  1087 
       
  1088     /**
       
  1089      * Remove modify listener.
  1048      * Remove modify listener.
  1090      *
  1049      *
  1091      * @param control text control
  1050      * @param control text control
  1092      * @param ltnr listener
  1051      * @param ltnr listener
  1093      */
  1052      */
  1097         {
  1056         {
  1098             if(control instanceof TextExtension)
  1057             if(control instanceof TextExtension)
  1099             {
  1058             {
  1100                 ((TextExtension) control).removeModifyListener(ltnr);
  1059                 ((TextExtension) control).removeModifyListener(ltnr);
  1101             }
  1060             }
  1102             else
       
  1103             {
       
  1104                 ((ConstrainedText) control).removeModifyListener(ltnr);
       
  1105             }
       
  1106         }
  1061         }
  1107     }
  1062     }
  1108 
  1063 
  1109     /**
  1064     /**
  1110      * Remove modify listener.
  1065      * Remove modify listener.
  1118         {
  1073         {
  1119             if(control instanceof TextExtension)
  1074             if(control instanceof TextExtension)
  1120             {
  1075             {
  1121                 ((TextExtension) control).removeSelectionListener(ltnr);
  1076                 ((TextExtension) control).removeSelectionListener(ltnr);
  1122             }
  1077             }
  1123             else
       
  1124             {
       
  1125                 ((ConstrainedText) control).removeSelectionListener(ltnr);
       
  1126             }
       
  1127         }
  1078         }
  1128     }
  1079     }
  1129 
  1080 
  1130     /**
  1081     /**
  1131      * Set content.
  1082      * Set content.
  1138         if(control != null)
  1089         if(control != null)
  1139         {
  1090         {
  1140             if(control instanceof TextExtension)
  1091             if(control instanceof TextExtension)
  1141             {
  1092             {
  1142                 ((TextExtension) control).setText(text);
  1093                 ((TextExtension) control).setText(text);
  1143             }
       
  1144             else
       
  1145             {
       
  1146                 ((ConstrainedText) control).setText(text);
       
  1147             }
  1094             }
  1148         }
  1095         }
  1149     }
  1096     }
  1150 
  1097 
  1151     /**
  1098     /**
  1231         {
  1178         {
  1232             if(control instanceof TextExtension)
  1179             if(control instanceof TextExtension)
  1233             {
  1180             {
  1234                 ((TextExtension) control).setTextLimit(maxSize);
  1181                 ((TextExtension) control).setTextLimit(maxSize);
  1235             }
  1182             }
  1236             else
       
  1237             {
       
  1238                 ((ConstrainedText) control).setTextLimit(maxSize);
       
  1239             }
       
  1240         }
  1183         }
  1241     }
  1184     }
  1242 
  1185 
  1243     /**
  1186     /**
  1244      * Set selection.
  1187      * Set selection.
  1252         if(control != null)
  1195         if(control != null)
  1253         {
  1196         {
  1254             if(control instanceof TextExtension)
  1197             if(control instanceof TextExtension)
  1255             {
  1198             {
  1256                 ((TextExtension) control).setSelection(sta, end);
  1199                 ((TextExtension) control).setSelection(sta, end);
  1257             }
       
  1258             else
       
  1259             {
       
  1260                 ((ConstrainedText) control).setSelection(sta, end);
       
  1261             }
  1200             }
  1262         }
  1201         }
  1263     }
  1202     }
  1264 
  1203 
  1265     /**
  1204     /**