- Timestamp:
- Nov 20, 2009, 4:27:07 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
r226 r231 1 1 package org.eclipse.swt.widgets; 2 3 /* 4 * OS/2 version. 5 * Copyright (c) 2002, 2009 EclipseOS2 Team. 6 */ 2 7 3 8 /* … … 94 99 public Text (Composite parent, int style) { 95 100 super (parent, checkStyle (style)); 96 if ((style & SWT.SINGLE) != 0)97 textLimit = 32;98 101 } 99 102 … … 108 111 void createHandle () { 109 112 super.createHandle (); 113 if ((style & SWT.MULTI) != 0) OS.WinSendMsg (handle, OS.MLM_SETTEXTLIMIT, -1, 0); 114 else OS.WinSendMsg (handle, OS.EM_SETTEXTLIMIT, LIMIT, 0); 110 115 } 111 116 … … 296 301 public Point computeSize (int wHint, int hHint, boolean changed) { 297 302 checkWidget (); 298 Point size = new Point (0, 0); 299 int count = ((style & SWT.MULTI) != 0)?OS.WinSendMsg (handle, OS.MLM_QUERYLINECOUNT, 0, 0):1; 303 int count = getLineCount(); 300 304 int hps = this.hps; 301 305 if (hps == 0) hps = OS.WinGetPS (handle); 302 FONTMETRICS fm = new FONTMETRICS(); 303 OS.GpiQueryFontMetrics (hps, FONTMETRICS.sizeof, fm); 304 int height = count * fm.lEmHeight, width = 0; 305 306 int height = count * getLineHeight (), width = 0; 306 307 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); 308 309 int length = ((style & SWT.MULTI) != 0)?OS.WinSendMsg (handle, OS.MLM_QUERYTEXTLENGTH, 0, 0):OS.WinQueryWindowTextLength (handle); 310 // System.out.println("Text::computeSize -> height = " + height); 311 // System.out.println("Text::computeSize -> lineas = " + count); 315 312 byte[] text = null; 316 if (length != 0) { 317 RECTL rect = new RECTL(); 318 text = getText().getBytes(); 319 int[] pnts = new int [OS.TXTBOX_COUNT * 2]; 320 /* 321 * Feature in OS/2. The maximum length of the string in string-related 322 * GPI functions is 512 chars. Do the cycle to handle larger strings. 323 */ 324 int extX = 0, dx = 0; 325 int is = 0; 326 while (is < length) { 327 //@@TODO (dmik): Unicode 328 // int ie = is + 256; 329 int ie = is + 512; 330 if (ie > length) ie = length; 331 if (is != 0) { 332 System.arraycopy (text, is, text, 0, ie - is); 333 } 334 //@@TODO (dmik): Unicode 335 // OS.GpiQueryTextBox (hps, (ie - is) << 1, text, OS.TXTBOX_COUNT, pnts); 336 OS.GpiQueryTextBox (hps, ie - is, text, OS.TXTBOX_COUNT, pnts); 337 extX += pnts [8]; 338 dx = pnts [4]; 339 if (dx < pnts [8]) dx = pnts [8]; 340 dx = dx - pnts [8]; 341 is = ie; 342 } 343 size.x = extX + dx; 344 } 345 width += size.x; 346 System.out.println("Text::computeSize -> ancho = " + width); 313 text = getText().getBytes(); 314 int[] pnts = new int [OS.TXTBOX_COUNT * 2]; 315 OS.GpiQueryTextBox (hps, length, text, OS.TXTBOX_COUNT, pnts); 316 width = Math.max (width, pnts[4] - pnts[0]); 317 // System.out.println("Text::computeSize -> ancho = " + width); 347 318 if (this.hps == 0) OS.WinReleasePS (hps); 348 // if (wrap && hHint == SWT.DEFAULT) { 349 // int newHeight = rect.bottom - rect.top; 350 // if (newHeight != 0) height = newHeight; 351 // } 352 // if (newFont != 0) OS.SelectObject (hDC, oldFont); 353 // OS.ReleaseDC (handle, hDC); 319 if (wrap && hHint == SWT.DEFAULT) { 320 int newHeight = pnts[1] - pnts[3]; 321 if (newHeight != 0) height = newHeight; 322 } 354 323 355 324 if (width == 0) width = DEFAULT_WIDTH; … … 357 326 if (wHint != SWT.DEFAULT) width = wHint; 358 327 if (hHint != SWT.DEFAULT) height = hHint; 359 // 360 // /* Calculate the margin width */ 361 // int margins = OS.SendMessage(handle, OS.EM_GETMARGINS, 0, 0); 362 // int marginWidth = (margins & 0xFFFF) + ((margins >> 16) & 0xFFFF); 363 // width += marginWidth; 364 // 365 // /* 366 // * The preferred height of a single-line text widget 367 // * has been hand-crafted to be the same height as 368 // * the single-line text widget in an editable combo 369 // * box. 370 // */ 371 // width += editRect.left * 2; 372 // height += editRect.top * 2; 328 373 329 if ((style & SWT.V_SCROLL) != 0) { 374 330 width += OS.WinQuerySysValue (OS.HWND_DESKTOP, OS.SV_CXVSCROLL); … … 600 556 public char getEchoChar () { 601 557 checkWidget (); 602 //@@TODO(lpino): Find out how to implement this. Maybe there is no need 603 // char echo = (char) OS.SendMessage (handle, OS.EM_GETPASSWORDCHAR, 0, 0); 604 // if (echo != 0 && (echo = mbcsToWcs (echo, getCodePage ())) == 0) echo = '*'; 605 // return echo; 606 return '*'; 558 return '*'; 607 559 } 608 560 … … 669 621 public int getLineHeight () { 670 622 checkWidget (); 671 // int newFont, oldFont = 0; 672 // int hDC = OS.GetDC (handle); 673 // newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); 674 // if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont); 675 // TEXTMETRIC tm = new TEXTMETRIC (); 676 // OS.GetTextMetrics (hDC, tm); 677 // if (newFont != 0) OS.SelectObject (hDC, oldFont); 678 // OS.ReleaseDC (handle, hDC); 679 // return tm.tmHeight; 680 681 //@@TODO(lpino): Implement MLM_QUERYFONT 682 // if ((style & SWT.MULTI) != 0){ 683 // FATTRS hFont; 684 // OS.WinSendMsg (handle, OS.MLM_QUERYFONT, hFont, 0); 685 // }else{ 623 if ((style & SWT.MULTI) != 0){ 624 FATTRS hFont = new FATTRS(); 625 OS.WinSendMsg (handle, OS.MLM_QUERYFONT, hFont, 0); 626 return hFont.lMaxBaselineExt + 4; 627 }else{ 686 628 int hps = this.hps; 687 629 if (hps == 0) hps = OS.WinGetPS (handle); 688 630 FONTMETRICS fm = new FONTMETRICS(); 689 631 OS.GpiQueryFontMetrics (hps, FONTMETRICS.sizeof, fm); 690 return fm.lEmHeight;691 // } 692 // return 0; 632 OS.WinReleasePS(hps); 633 return fm.lMaxBaselineExt + 4; 634 } 693 635 } 694 636 … … 784 726 int hps = this.hps; 785 727 if (hps == 0) hps = OS.WinGetPS (handle); 786 int extX = 0,dx = 0;728 int dx = 0; 787 729 int[] pnts = new int [OS.TXTBOX_COUNT * 2]; 788 // byte[] text = (new String(" ")).getBytes();789 730 PSZ buffer = new PSZ (" "); 790 731 OS.GpiQueryTextBox (hps, 1, buffer.getBytes(), OS.TXTBOX_COUNT, pnts); 791 extX += pnts [8]; 792 dx = pnts [4]; 793 if (dx < pnts [8]) dx = pnts [8]; 794 dx = dx - pnts [8]; 795 // System.out.println("TOTAL = " + (extX + dx)); 796 // for(int i=0;i<OS.TXTBOX_COUNT * 2;i++){ 797 // System.out.println("Punto " + i + "=" + pnts[i]); 798 // } 799 return extX + dx; 732 dx = pnts [4]-pnts [0]; 733 OS.WinReleasePS(hps); 734 return dx; 800 735 } 801 736 … … 815 750 public String getText () { 816 751 checkWidget (); 817 int length =OS.WinQueryWindowTextLength (handle);752 int length = ((style & SWT.MULTI) != 0)?OS.WinSendMsg (handle, OS.MLM_QUERYTEXTLENGTH, 0, 0):OS.WinQueryWindowTextLength (handle); 818 753 if (length == 0) return ""; 819 754 PSZ buffer = new PSZ(length); … … 1306 1241 checkWidget (); 1307 1242 super.setFont (font); 1308 //setTabStops (tabs);1243 setTabStops (tabs); 1309 1244 } 1310 1245 … … 1488 1423 if ((style & SWT.MULTI) != 0){ 1489 1424 OS.WinSendMsg(handle, OS.MLM_INSERT, buffer, 0); 1425 /* SWT places the I-beam before the inserted text */ 1426 OS.WinSendMsg(handle, OS.MLM_SETSEL, 0, 0); 1490 1427 } 1491 1428 else{ 1492 1429 OS.WinSetWindowText(handle, buffer); 1430 /* SWT places the I-beam before the inserted text */ 1431 OS.WinSendMsg (handle, OS.EM_SETSEL, OS.MPFROM2SHORT((short)0, (short)0), 0); 1493 1432 } 1494 1433 } … … 1577 1516 public void showSelection () { 1578 1517 checkWidget (); 1579 // OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0); 1518 int pos = OS.WinSendMsg (handle, OS.MLM_QUERYSEL, OS.MLFQS_ANCHORSEL , 0); 1519 OS.WinSendMsg (handle, OS.MLM_SETSEL, pos, pos); 1580 1520 } 1581 1521 … … 1665 1605 if ((style & SWT.H_SCROLL) != 0) bits |= OS.MLS_HSCROLL; 1666 1606 if ((style & SWT.BORDER) != 0) bits |= OS.MLS_BORDER; 1667 return bits | OS.WS_VISIBLE ;1607 return bits | OS.WS_VISIBLE | OS.WS_GROUP | OS.WS_TABSTOP; 1668 1608 } 1669 1609 else{ … … 1671 1611 if ((style & SWT.READ_ONLY) != 0) bits |= OS.ES_READONLY; 1672 1612 if ((style & SWT.BORDER) != 0) bits |= OS.ES_MARGIN; 1673 return bits | OS.WS_VISIBLE | OS.ES_AUTOSCROLL ;1613 return bits | OS.WS_VISIBLE | OS.ES_AUTOSCROLL | OS.ES_LEFT | OS.WS_TABSTOP; 1674 1614 } 1675 1615 } … … 1746 1686 // return result; 1747 1687 //} 1748 //1749 //LRESULT WM_GETDLGCODE (int wParam, int lParam) {1750 // LRESULT result = super.WM_GETDLGCODE (wParam, lParam);1751 // if (result != null) return result;1752 // /*1753 // * Feature in Windows. Despite the fact that the1754 // * text control is read only, it still returns a1755 // * dialog code indicating that it wants keys. The1756 // * fix is to detect this case and clear the bits.1757 // */1758 // if ((style & SWT.READ_ONLY) != 0) {1759 // int code = callWindowProc (OS.WM_GETDLGCODE, wParam, lParam);1760 // code &= ~(OS.DLGC_WANTALLKEYS | OS.DLGC_WANTTAB | OS.DLGC_WANTARROWS);1761 // return new LRESULT (code);1762 // }1763 // return null;1764 //}1765 //1766 1688 //LRESULT WM_IME_CHAR (int wParam, int lParam) { 1767 1689 // … … 1942 1864 } 1943 1865 1944 //MRESULT wmCommandChild (int mp1, int mp2) {1945 // int code = mp1 >> 16;1946 // switch (code) {1947 // case OS.EN_CHANGE:1948 // /*1949 // * It is possible (but unlikely), that application1950 // * code could have disposed the widget in the modify1951 // * event. If this happens, end the processing of the1952 // * Windows message by returning zero as the result of1953 // * the window proc.1954 // */1955 // sendEvent (SWT.Modify);1956 // if (isDisposed ()) return MRESULT.ZERO;1957 // break;1958 // }1959 // return super.wmCommandChild (mp1, mp2);1960 //}1961 1962 1866 MRESULT wmScroll (int msg, int mp1, int mp2) { 1963 1867 int code = callWindowProc (msg, mp1, mp2);
Note:
See TracChangeset
for help on using the changeset viewer.