Changeset 198 for trunk/src/plugins


Ignore:
Timestamp:
Oct 10, 2009, 7:04:03 PM (16 years ago)
Author:
lpino
Message:
  • Implement most of the sendKeyEvent method
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plugins/org.eclipse.swt/Eclipse SWT/pm/org/eclipse/swt/widgets/Text.java

    r189 r198  
    504504//      * pixel coordinates (0,0).
    505505//      */
    506 //      int [] start = new int [1];
     506//      int start = 0;
    507507//      OS.SendMessage (handle, OS.EM_GETSEL, start, (int []) null);
    508508//      int pos = OS.SendMessage (handle, OS.EM_POSFROMCHAR, start [0], 0);
     
    579579}
    580580//
    581 //String getClipboardText () {
    582 //      String string = "";
    583 //      if (OS.OpenClipboard (0)) {
     581String getClipboardText () {
     582        String string = "";
     583        int hab = parent.getDisplay ().hab;
     584        if (OS.WinOpenClipbrd (hab)) {
    584585//              int hMem = OS.GetClipboardData (OS.IsUnicode ? OS.CF_UNICODETEXT : OS.CF_TEXT);
    585586//              if (hMem != 0) {
     
    594595//                      }
    595596//              }
    596 //              OS.CloseClipboard ();
    597 //      }
    598 //      return string;
    599 //}
     597                OS.WinCloseClipbr (hab);
     598        }
     599        return string;
     600}
    600601
    601602/**
     
    11461147}
    11471148
    1148 //boolean sendKeyEvent (int type, int msg, int wParam, int lParam, Event event) {
    1149 //      if (!super.sendKeyEvent (type, msg, wParam, lParam, event)) {
    1150 //              return false;
    1151 //      }
    1152 //      if (ignoreVerify) return true;
    1153 //      if (type != SWT.KeyDown) return true;
    1154 //      if (msg != OS.WM_CHAR && msg != OS.WM_KEYDOWN && msg != OS.WM_IME_CHAR) {
    1155 //              return true;
    1156 //      }
    1157 //      if (event.character == 0) return true;
    1158 //      if (!hooks (SWT.Verify)) return true;
    1159 //      char key = event.character;
    1160 //      int stateMask = event.stateMask;
    1161 //     
    1162 //      /* Disable all magic keys that could modify the text */
    1163 //      switch (msg) {
    1164 //              case OS.WM_CHAR:
    1165 //                      if (key != 0x08 && key != 0x7F && key != '\r' && key != '\t' && key != '\n') break;
    1166 //                      // FALL THROUGH
     1149boolean sendKeyEvent (int type, int msg, int mp1, int mp2, Event event) {
     1150        if (!super.sendKeyEvent (type, msg, mp1, mp2, event)) {
     1151                return false;
     1152        }
     1153        if (ignoreVerify) return true;
     1154        if (type != SWT.KeyDown) return true;
     1155        if (msg != OS.WM_CHAR /*&& msg != OS.WM_KEYDOWN && msg != OS.WM_IME_CHAR*/) {
     1156                return true;
     1157        }
     1158        if (event.character == 0) return true;
     1159        if (!hooks (SWT.Verify)) return true;
     1160        char key = event.character;
     1161        int stateMask = event.stateMask;
     1162       
     1163        /* Disable all magic keys that could modify the text */
     1164        switch (msg) {
     1165                case OS.WM_CHAR:{
     1166                        if (key != 0x08 && key != 0x7F && key != '\r' && key != '\t' && key != '\n')
     1167                                break;
     1168                        else{
     1169                                if ((stateMask & (SWT.CTRL | SWT.SHIFT | SWT.ALT)) != 0) return false;
     1170                                break;
     1171                        }
     1172                }
     1173                        // FALL THROUGH
    11671174//              case OS.WM_KEYDOWN:
    11681175//                      if ((stateMask & (SWT.CTRL | SWT.SHIFT | SWT.ALT)) != 0) return false;
    11691176//                      break;
    1170 //      }
    1171 //
    1172 //      /*
    1173 //      * If the left button is down, the text widget
    1174 //      * refuses the character.
    1175 //      */
    1176 //      if (OS.GetKeyState (OS.VK_LBUTTON) < 0) {
    1177 //              return true;
    1178 //      }
    1179 //
    1180 //      /* Verify the character */
    1181 //      String oldText = "";
    1182 //      int [] start = new int [1], end = new int [1];
    1183 //      OS.SendMessage (handle, OS.EM_GETSEL, start, end);
    1184 //      switch (key) {
    1185 //              case 0x08:      /* Bs */
    1186 //                      if (start [0] == end [0]) {
    1187 //                              if (start [0] == 0) return true;
    1188 //                              int lineStart = OS.SendMessage (handle, OS.EM_LINEINDEX, -1, 0);
    1189 //                              if (start [0] == lineStart) {
    1190 //                                      start [0] = start [0] - DELIMITER.length ();
    1191 //                              } else {
    1192 //                                      start [0] = start [0] - 1;
     1177        }
     1178
     1179        /*
     1180        * If the left button is down, the text widget
     1181        * refuses the character.
     1182        */
     1183        if (OS.WinGetKeyState (OS.HWND_DESKTOP, OS.VK_BUTTON1) < 0) {
     1184                return true;
     1185        }
     1186
     1187        /* Verify the character */
     1188        String oldText = "";
     1189        int  start = 0, end = 0;
     1190        int pos = ((style & SWT.MULTI) != 0)?OS.WinSendMsg(handle, OS.MLM_QUERYSEL, OS.MLFQS_MINMAXSEL, 0):OS.WinSendMsg (handle, OS.EM_QUERYSEL, 0, 0);
     1191        start = OS.SHORT1FROMMP(pos);
     1192        end = OS.SHORT2FROMMP(pos);
     1193        switch (key) {
     1194                case 0x08:      /* Bs */
     1195                        if (start == end ) {
     1196                                if (start == 0) return true;
     1197                                int lineStart = ((style & SWT.MULTI) != 0)?OS.WinSendMsg (handle, OS.MLM_CHARFROMLINE, -1, 0):OS.WinSendMsg(handle, OS.EM_QUERYFIRSTCHAR, 0, 0);
     1198                                if (start == lineStart) {
     1199                                        start = start - DELIMITER.length ();
     1200                                } else {
     1201                                        start = start - 1;
    11931202//                                      if (OS.IsDBLocale) {
    11941203//                                              int [] newStart = new int [1], newEnd = new int [1];
     
    11971206//                                              if (start [0] != newStart [0]) start [0] = start [0] - 1;
    11981207//                                      }
    1199 //                              }
    1200 //                              start [0] = Math.max (start [0], 0);
    1201 //                      }
    1202 //                      break;
    1203 //              case 0x7F:      /* Del */
    1204 //                      if (start [0] == end [0]) {
    1205 //                              int length = OS.GetWindowTextLength (handle);
    1206 //                              if (start [0] == length) return true;
    1207 //                              int line = OS.SendMessage (handle, OS.EM_LINEFROMCHAR, end [0], 0);
    1208 //                              int lineStart = OS.SendMessage (handle, OS.EM_LINEINDEX, line + 1, 0);
    1209 //                              if (end [0] == lineStart - DELIMITER.length ()) {
    1210 //                                      end [0] = end [0] + DELIMITER.length ();
    1211 //                              } else {
    1212 //                                      end [0] = end [0] + 1;
     1208                                }
     1209                                start = Math.max (start, 0);
     1210                        }
     1211                        break;
     1212                case 0x7F:      /* Del */
     1213                        if (start == end) {
     1214                                int length = OS.WinQueryWindowTextLength (handle);
     1215                                if (start == length) return true;
     1216                                int line = ((style & SWT.MULTI) != 0)?OS.WinSendMsg(handle, OS.MLM_LINEFROMCHAR, end, 0):1;
     1217                                int lineStart = ((style & SWT.MULTI) != 0)?OS.WinSendMsg (handle, OS.MLM_CHARFROMLINE, line + 1, 0):OS.WinSendMsg(handle, OS.EM_QUERYFIRSTCHAR, 0, 0);
     1218                                if (end == lineStart - DELIMITER.length ()) {
     1219                                        end = end + DELIMITER.length ();
     1220                                } else {
     1221                                        end = end + 1;
    12131222//                                      if (OS.IsDBLocale) {
    12141223//                                              int [] newStart = new int [1], newEnd = new int [1];
     
    12171226//                                              if (end [0] != newEnd [0]) end [0] = end [0] + 1;
    12181227//                                      }
    1219 //                              }
    1220 //                              end [0] = Math.min (end [0], length);
    1221 //                      }
    1222 //                      break;
    1223 //              case '\r':      /* Return */
    1224 //                      int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
    1225 //                      if ((bits & OS.ES_MULTILINE) == 0) return true;
    1226 //                      oldText = DELIMITER;
    1227 //                      break;
    1228 //              default:        /* Tab and other characters */
    1229 //                      if (key != '\t' && key < 0x20) return true;
    1230 //                      oldText = new String (new char [] {key});
    1231 //                      break;
    1232 //      }
    1233 //      String newText = verifyText (oldText, start [0], end [0], event);
    1234 //      if (newText == null) return false;
    1235 //      if (newText == oldText) return true;
    1236 //      newText = Display.withCrLf (newText);
    1237 //      TCHAR buffer = new TCHAR (getCodePage (), newText, true);
    1238 //      OS.SendMessage (handle, OS.EM_SETSEL, start [0], end [0]);
    1239 //      OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
    1240 //      return false;
    1241 //}
     1228                                }
     1229                                end = Math.min (end, length);
     1230                        }
     1231                        break;
     1232                case '\r':      /* Return */
     1233                        if ((style & SWT.MULTI) == 0) return true;
     1234                        oldText = DELIMITER;
     1235                        break;
     1236                default:        /* Tab and other characters */
     1237                        if (key != '\t' && key < 0x20) return true;
     1238                        oldText = new String (new char [] {key});
     1239                        break;
     1240        }
     1241        String newText = verifyText (oldText, start, end, event);
     1242        if (newText == null) return false;
     1243        if (newText == oldText) return true;
     1244        newText = Display.withCrLf (newText);
     1245        PSZ buffer = new PSZ(newText);
     1246        if ((style & SWT.MULTI) != 0){
     1247                OS.WinSendMsg (handle, OS.MLM_SETSEL, start, end);
     1248                OS.WinSendMsg (handle, OS.MLM_INSERT, buffer, 0);
     1249        }
     1250        else{
     1251                int length = OS.WinQueryWindowTextLength (handle);
     1252                int newlength = length + buffer.toString().length();
     1253                OS.WinSendMsg (handle, OS.EM_SETSEL, OS.MPFROM2SHORT((short)start, (short)end), 0);
     1254                OS.WinSetWindowText(handle, buffer);
     1255                OS.WinSendMsg(handle, OS.EM_SETFIRSTCHAR, (short)(newlength), 0);
     1256        }
     1257        return false;
     1258}
    12421259
    12431260/**
Note: See TracChangeset for help on using the changeset viewer.