- Timestamp:
- Nov 16, 2009, 1:25:40 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/plugins/org.eclipse.swt/Eclipse SWT/pm/org/eclipse/swt/widgets/Text.java
r198 r226 297 297 checkWidget (); 298 298 Point size = new Point (0, 0); 299 int count = ((style & SWT.MULTI) != 0)?OS.WinSendMsg (handle, OS.MLM_QUERYLINECOUNT, 0, 0):1; 299 300 int hps = this.hps; 300 301 if (hps == 0) hps = OS.WinGetPS (handle); 301 // int newFont, oldFont = 0;302 // int hDC = OS.GetDC (handle);303 // newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);304 // if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);305 // TEXTMETRIC tm = new TEXTMETRIC ();306 // OS.GetTextMetrics (hDC, tm);307 302 FONTMETRICS fm = new FONTMETRICS(); 308 303 OS.GpiQueryFontMetrics (hps, FONTMETRICS.sizeof, fm); 309 int count = ((style & SWT.MULTI) != 0)?OS.WinSendMsg (handle, OS.MLM_QUERYLINECOUNT, 0, 0):1;310 304 int height = count * fm.lEmHeight, width = 0; 311 // RECT rect = new RECT (); 312 // int flags = OS.DT_CALCRECT | OS.DT_EDITCONTROL | OS.DT_NOPREFIX; 313 // boolean wrap = (style & SWT.MULTI) != 0 && (style & SWT.WRAP) != 0; 314 // if (wrap && wHint != SWT.DEFAULT) { 315 // flags |= OS.DT_WORDBREAK; 316 // rect.right = wHint; 317 // } 318 // String text = getText (); 319 // PSZ buffer = new PSZ (text); 320 // TCHAR buffer = new TCHAR (getCodePage (), text, false); 321 // OS.DrawText (hDC, buffer, buffer.length (), rect, flags); 322 // width = rect.right - rect.left; 323 int length = OS.WinQueryWindowTextLength (handle); 305 306 boolean wrap = (style & SWT.MULTI) != 0 && (style & SWT.WRAP) != 0; 307 308 /* int[] pts = new int[8]; 309 OS.WinSendMsg (handle, OS.MLM_QUERYFORMATRECT, pts, OS.MLFFMTRECT_MATCHWINDOW); 310 */ 311 int length = OS.WinQueryWindowTextLength (handle); 312 System.out.println("Text::computeSize -> text = " + getText()); 313 System.out.println("Text::computeSize -> lineas = " + count); 314 System.out.println("Text::computeSize -> handle = " + Integer.toHex); 324 315 byte[] text = null; 325 316 if (length != 0) { … … 353 344 } 354 345 width += size.x; 346 System.out.println("Text::computeSize -> ancho = " + width); 355 347 if (this.hps == 0) OS.WinReleasePS (hps); 356 348 // if (wrap && hHint == SWT.DEFAULT) { … … 474 466 return OS.WinSendMsg(handle, OS.MLM_CHARFROMLINE, -1, 0); 475 467 else 476 //@@TODO(lpino): Check if this it's OK for SINGLE style477 468 return 1; 478 469 } … … 491 482 * </ul> 492 483 */ 493 //public Point getCaretLocation () { 494 // checkWidget (); 495 // /* 496 // * Bug in Windows. For some reason, Windows is unable 497 // * to return the pixel coordinates of the last character 498 // * in the widget. The fix is to temporarily insert a 499 // * space, query the coordinates and delete the space. 500 // * The selection is always an i-beam in this case because 501 // * this is the only time the start of the selection can 502 // * be equal to the last character position in the widget. 503 // * If EM_POSFROMCHAR fails for any other reason, return 504 // * pixel coordinates (0,0). 505 // */ 506 // int start = 0; 507 // OS.SendMessage (handle, OS.EM_GETSEL, start, (int []) null); 508 // int pos = OS.SendMessage (handle, OS.EM_POSFROMCHAR, start [0], 0); 509 // if (pos == -1) { 510 // pos = 0; 511 // if (start [0] >= OS.GetWindowTextLength (handle)) { 512 // int cp = getCodePage (); 513 // OS.SendMessage (handle, OS.EM_REPLACESEL, 0, new TCHAR (cp, " ", true)); 514 // pos = OS.SendMessage (handle, OS.EM_POSFROMCHAR, start [0], 0); 515 // OS.SendMessage (handle, OS.EM_SETSEL, start [0], start [0] + 1); 516 // OS.SendMessage (handle, OS.EM_REPLACESEL, 0, new TCHAR (cp, "", true)); 517 // } 518 // } 519 // return new Point ((short) (pos & 0xFFFF), (short) (pos >> 16)); 520 //} 484 public Point getCaretLocation () { 485 checkWidget (); 486 /* int pos = 0; 487 if ((style & SWT.MULTI) != 0){ 488 pos = OS.WinSendMsg (handle, OS.MLM_QUERYSEL, OS.MLFQS_MINSEL, 0); 489 } else { 490 pos = OS.WinSendMsg (handle, OS.EM_QUERYSEL, 0, 0); 491 } 492 return new Point ((short) (pos & 0xFFFF), (short) (pos >> 16)); 493 */ 494 return null; 495 } 521 496 522 497 /** … … 551 526 return OS.SHORT1FROMMP(pos); 552 527 } 553 // int [] start = new int [1], end = new int [1];554 // OS.SendMessage (handle, OS.EM_GETSEL, start, end);555 // int startLine = OS.SendMessage (handle, OS.EM_LINEFROMCHAR, start [0], 0);556 // int caretPos = OS.SendMessage (handle, OS.EM_LINEINDEX, -1, 0);557 // int caretLine = OS.SendMessage (handle, OS.EM_LINEFROMCHAR, caretPos, 0);558 // int caret = end [0];559 // if (caretLine == startLine) caret = start [0];560 // return caret;561 528 } 562 529 … … 743 710 public Point getSelection () { 744 711 checkWidget (); 745 int pos = 0; 746 pos = OS.WinSendMsg (handle, OS.EM_QUERYSEL, 0, 0); 712 int pos = 0; 713 if ((style & SWT.MULTI) != 0){ 714 pos = OS.WinSendMsg (handle, OS.MLM_QUERYSEL, (short)OS.MLFQS_MINMAXSEL , 0); 715 }else{ 716 pos = OS.WinSendMsg (handle, OS.EM_QUERYSEL, 0, 0); 717 } 747 718 //@@TODO(lpino): Do we need to consider DB? 748 719 // if (OS.IsDBLocale) { … … 1298 1269 * </ul> 1299 1270 */ 1300 //public void setEchoChar (char echo) {1301 //checkWidget ();1271 public void setEchoChar (char echo) { 1272 checkWidget (); 1302 1273 // if (echo != 0) { 1303 1274 // if ((echo = (char) wcsToMbcs (echo, getCodePage ())) == 0) echo = '*'; … … 1310 1281 // */ 1311 1282 // OS.InvalidateRect (handle, null, true); 1312 //}1283 } 1313 1284 1314 1285 /** … … 1410 1381 } 1411 1382 1412 //public void setRedraw (boolean redraw) {1413 //checkWidget ();1414 //super.setRedraw (redraw);1383 public void setRedraw (boolean redraw) { 1384 checkWidget (); 1385 super.setRedraw (redraw); 1415 1386 // /* 1416 1387 // * Feature in Windows. When WM_SETREDRAW is used to turn … … 1429 1400 // if (oldStart == start [0] && oldEnd == end [0]) return; 1430 1401 // OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0); 1431 //}1402 } 1432 1403 1433 1404 /** … … 1566 1537 * </ul> 1567 1538 */ 1568 //public void setTopIndex (int index) { 1569 // checkWidget (); 1570 // int bits = OS.GetWindowLong (handle, OS.GWL_STYLE); 1571 // if ((bits & OS.ES_MULTILINE) == 0) return; 1572 // int count = OS.SendMessage (handle, OS.EM_GETLINECOUNT, 0, 0); 1573 // index = Math.min (Math.max (index, 0), count - 1); 1574 // int topIndex = OS.SendMessage (handle, OS.EM_GETFIRSTVISIBLELINE, 0, 0); 1575 // OS.SendMessage (handle, OS.EM_LINESCROLL, 0, index - topIndex); 1576 //} 1539 public void setTopIndex (int index) { 1540 checkWidget (); 1541 if ((style & SWT.MULTI) == 0) return; 1542 /* int bits = OS.WinQueryWindowULong (handle, OS.QWL_STYLE); 1543 if ((bits & OS.ES_MULTILINE) == 0) return; */ 1544 int count = OS.WinSendMsg (handle, OS.MLM_QUERYLINECOUNT, 0, 0); 1545 index = Math.min (Math.max (index, 0), count - 1); 1546 /* In PM this is the actual char position */ 1547 int topIndex = OS.WinSendMsg (handle, OS.MLM_QUERYFIRSTCHAR, 0, 0); 1548 /* This will cause a scroll to the selected position */ 1549 OS.WinSendMsg (handle, OS.MLM_SETSEL, topIndex, topIndex); 1550 } 1577 1551 1578 1552 /* … … 1686 1660 int bits = super.widgetStyle (); 1687 1661 if ((style & SWT.MULTI) != 0){ 1688 if ((style & SWT.READ_ONLY) != 0) bits |= OS.MLS_READONLY; 1689 // if ((style & SWT.SINGLE) != 0) return bits | OS.MLS_HSCROLL; 1690 // bits |= OS.MLS_HSCROLL; 1662 if ((style & SWT.READ_ONLY) != 0) bits |= OS.MLS_READONLY; 1691 1663 if ((style & SWT.WRAP) != 0) bits |= OS.MLS_WORDWRAP; 1692 1664 if ((style & SWT.V_SCROLL) != 0) bits |= OS.MLS_VSCROLL; 1693 1665 if ((style & SWT.H_SCROLL) != 0) bits |= OS.MLS_HSCROLL; 1694 return bits | OS.MLS_BORDER; 1666 if ((style & SWT.BORDER) != 0) bits |= OS.MLS_BORDER; 1667 return bits | OS.WS_VISIBLE; 1695 1668 } 1696 1669 else{
Note:
See TracChangeset
for help on using the changeset viewer.