- Timestamp:
- Oct 10, 2009, 7:00: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/List.java
r112 r196 98 98 if (result == OS.LIT_MEMERROR) error (SWT.ERROR_ITEM_NOT_ADDED); 99 99 if (result == OS.LIT_ERROR) error (SWT.ERROR_ITEM_NOT_ADDED); 100 //if ((style & SWT.H_SCROLL) != 0) setScrollWidth (buffer, true);100 if ((style & SWT.H_SCROLL) != 0) setScrollWidth (buffer, true); 101 101 } 102 102 /** … … 141 141 } 142 142 } 143 //if ((style & SWT.H_SCROLL) != 0) setScrollWidth (buffer, true);143 if ((style & SWT.H_SCROLL) != 0) setScrollWidth (buffer, true); 144 144 } 145 145 … … 193 193 // System.out.println("Ancho = " + OS.SHORT2FROMMP (rc)); 194 194 195 // int itemHeight = OS.SendMessage (handle, OS.LB_GETITEMHEIGHT, 0, 0);196 //int width = 0, height = count * itemHeight;197 // if ((style & SWT.H_SCROLL) != 0) { 198 // width = OS.SendMessage (handle, OS.LB_GETHORIZONTALEXTENT, 0, 0);199 // } else { 200 // int newFont, oldFont = 0;201 // int hDC = OS.GetDC (handle);202 // newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);203 // if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont); 204 // RECT rect = new RECT ();205 // int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX; 206 // int cp = getCodePage (); 207 // TCHAR buffer = new TCHAR (cp, 64+ 1);208 // for (int i=0; i<count; i++) { 209 // int length = OS.SendMessage (handle, OS.LB_GETTEXTLEN, i, 0);210 // if (length != OS.LB_ERR) {211 // if (length + 1 > buffer.length ()) { 212 // buffer = new TCHAR (cp, length + 1);213 // }214 // int result = OS.SendMessage (handle, OS.LB_GETTEXT, i, buffer);215 // if (result != OS.LB_ERR) {216 // OS.DrawText (hDC, buffer, length, rect, flags);217 // width = Math.max (width, rect.right - rect.left); 218 //}219 //}220 //}221 // if (newFont != 0) OS.SelectObject (hDC, oldFont);222 // OS.ReleaseDC (handle, hDC);223 // } 224 // if (width == 0) width = DEFAULT_WIDTH;225 // if (height == 0) height = DEFAULT_HEIGHT;226 // if (wHint != SWT.DEFAULT) width = wHint;227 // if (hHint != SWT.DEFAULT) height = hHint;228 // int border = getBorderWidth ();229 // width += border * 2 + 3; 230 // height += border * 2;231 // if ((style & SWT.V_SCROLL) != 0) { 232 // width += OS.GetSystemMetrics (OS.SM_CXVSCROLL);233 //}234 //if ((style & SWT.H_SCROLL) != 0) {235 // height += OS.GetSystemMetrics (OS.SM_CYHSCROLL);236 //}237 return new Point ( 0, 0);195 int itemHeight = getItemHeight(); 196 int width = 0, height = count * itemHeight; 197 int hps = this.hps; 198 if (hps == 0) hps = OS.WinGetPS (handle); 199 RECTL rcl = new RECTL(); 200 int flags = OS.DT_QUERYEXTENT | OS.DT_TEXTATTRS; 201 PSZ buffer = new PSZ(64+1); 202 int[] pnts = new int [OS.TXTBOX_COUNT * 2]; 203 for (int i=0; i<count; i++) { 204 int length = OS.WinSendMsg (handle, OS.LM_QUERYITEMTEXTLENGTH,(short)i, 0); 205 if (length != OS.LIT_ERROR) { 206 if (length + 1 > buffer.length()) { 207 buffer = new PSZ( length + 1); 208 } 209 int result = OS.WinSendMsg (handle, OS.LM_QUERYITEMTEXT, OS.MPFROM2SHORT((short)i,(short)length), buffer); 210 if (result != 0) { 211 OS.GpiQueryTextBox (hps, length, buffer.getBytes(), OS.TXTBOX_COUNT, pnts); 212 width = Math.max (width, pnts[4] - pnts[0]); 213 // System.out.println("List::computeSize -> pto 1 = " + pnts[0] + "," + pnts[1]); 214 // System.out.println("List::computeSize -> pto 2 = " + pnts[2] + "," + pnts[3]); 215 // System.out.println("List::computeSize -> pto 3 = " + pnts[4] + "," + pnts[5]); 216 // System.out.println("List::computeSize -> pto 4 = " + pnts[6] + "," + pnts[7]); 217 218 } 219 } 220 } 221 if (this.hps == 0) OS.WinReleasePS (hps); 222 if (width == 0) width = DEFAULT_WIDTH; 223 if (height == 0) height = DEFAULT_HEIGHT; 224 if (wHint != SWT.DEFAULT) width = wHint; 225 if (hHint != SWT.DEFAULT) height = hHint; 226 int border = getBorderWidth (); 227 width += border * 2 + 3; 228 height += border * 2; 229 if ((style & SWT.V_SCROLL) != 0) { 230 System.out.println("List::computeSize -> width antes de = " + width); 231 width += OS.WinQuerySysValue (handle, OS.SV_CXVSCROLL); 232 System.out.println("List::computeSize -> width despues de = " + width); 233 } 234 if ((style & SWT.H_SCROLL) != 0) { 235 height += OS.WinQuerySysValue (handle, OS.SV_CYHSCROLL); 236 } 237 return new Point (width, height); 238 238 } 239 239 … … 697 697 } 698 698 699 ///* Use LM_SEARCHSTRING to search for the item */699 /* Use LM_SEARCHSTRING to search for the item */ 700 700 int count = OS.WinSendMsg (handle, OS.LM_QUERYITEMCOUNT, 0, 0); 701 701 if (!((0 <= start) && (start < count))) return -1; … … 751 751 int count = OS.WinSendMsg (handle, OS.LM_QUERYITEMCOUNT, 0, 0); 752 752 int topIndex = OS.WinSendMsg (handle, OS.LM_QUERYTOPINDEX, 0, 0); 753 int newWidth = 0; 754 int hps = this.hps; 755 RECTL rcl = null; 753 756 // RECT rect = null; 754 757 // int hDC = 0, oldFont = 0, newFont = 0, newWidth = 0; 755 // if ((style & SWT.H_SCROLL) != 0) { 756 // rect = new RECT (); 758 if ((style & SWT.H_SCROLL) != 0) { 759 rcl = new RECTL (); 760 if (hps == 0) hps = OS.WinGetPS (handle); 757 761 // hDC = OS.GetDC (handle); 758 762 // newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); 759 763 // if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont); 760 //}764 } 761 765 // int cp = getCodePage (); 762 766 int i = 0, topCount = 0, last = -1; … … 764 768 int index = newIndices [i]; 765 769 if (index != last || i == 0) { 766 // TCHARbuffer = null;767 //if ((style & SWT.H_SCROLL) != 0) {768 // int length = OS.SendMessage (handle, OS.LB_GETTEXTLEN,index, 0);769 // if (length == OS.LB_ERR) break;770 // buffer = new TCHAR (cp,length + 1);771 // int result = OS.SendMessage (handle, OS.LB_GETTEXT, index, buffer);772 // if (result == OS.LB_ERR) break;773 //}770 PSZ buffer = null; 771 if ((style & SWT.H_SCROLL) != 0) { 772 int length = OS.WinSendMsg (handle, OS.LM_QUERYITEMTEXTLENGTH,(short)index, 0); 773 if (length == OS.LIT_ERROR) break; 774 buffer = new PSZ (length + 1); 775 int result = OS.WinSendMsg (handle, OS.LM_QUERYITEMTEXT, OS.MPFROM2SHORT((short)index,(short)length), buffer); 776 if (result == 0) break; 777 } 774 778 int result = OS.WinSendMsg (handle, OS.LM_DELETEITEM, index, 0); 775 779 // if (result == OS.LB_ERR) break; 776 //if ((style & SWT.H_SCROLL) != 0) {777 // int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX;778 // OS.DrawText (hDC, buffer, -1, rect, flags);779 // newWidth = Math.max (newWidth, rect.right - rect.left);780 //}780 if ((style & SWT.H_SCROLL) != 0) { 781 int flags = OS.DT_QUERYEXTENT | OS.DT_TEXTATTRS; 782 OS.WinDrawText (hps, -1, buffer.getBytes(), rcl, 0, 0, flags); 783 newWidth = Math.max (newWidth, rcl.xRight - rcl.xLeft); 784 } 781 785 if (index < topIndex) topCount++; 782 786 last = index; … … 784 788 i++; 785 789 } 786 //if ((style & SWT.H_SCROLL) != 0) {790 if ((style & SWT.H_SCROLL) != 0) { 787 791 // if (newFont != 0) OS.SelectObject (hDC, oldFont); 788 // OS.ReleaseDC (handle, hDC);789 //setScrollWidth (newWidth, false);790 //}792 if (this.hps == 0) OS.WinReleasePS (hps); 793 setScrollWidth (newWidth, false); 794 } 791 795 if (topCount > 0) { 792 796 topIndex -= topCount; … … 834 838 error (SWT.ERROR_INVALID_RANGE); 835 839 } 836 //@@TODO(lpino): 837 // if ((style & SWT.H_SCROLL) != 0) setScrollWidth (buffer, false); 840 if ((style & SWT.H_SCROLL) != 0) setScrollWidth (buffer, false); 838 841 if (index < topIndex) { 839 842 OS.WinSendMsg (handle, OS.LM_SETTOPINDEX, (short)(topIndex-1), 0); … … 865 868 int count = OS.WinSendMsg (handle, OS.LM_QUERYITEMCOUNT, 0, 0); 866 869 int topIndex = OS.WinSendMsg (handle, OS.LM_QUERYTOPINDEX, 0, 0); 867 // RECT rect = null; 868 // int hDC = 0, oldFont = 0, newFont = 0, newWidth = 0; 869 // if ((style & SWT.H_SCROLL) != 0) { 870 // rect = new RECT (); 871 // hDC = OS.GetDC (handle); 872 // newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); 873 // if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont); 874 // } 875 // int cp = getCodePage (); 870 int newWidth = 0; 871 int hps = this.hps; 872 RECTL rcl = null; 873 if ((style & SWT.H_SCROLL) != 0) { 874 rcl = new RECTL (); 875 if (hps == 0) hps = OS.WinGetPS (handle); 876 } 876 877 int index = start; 877 // int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX;878 int flags = OS.DT_QUERYEXTENT | OS.DT_TEXTATTRS; 878 879 while (index <= end) { 879 880 PSZ buffer = null; … … 887 888 int result =OS.WinSendMsg (handle, OS.LM_DELETEITEM,(short) start, 0); 888 889 if (result <=0) break; 889 //if ((style & SWT.H_SCROLL) != 0) {890 // OS.DrawText (hDC, buffer, -1, rect, flags);891 // newWidth = Math.max (newWidth, rect.right - rect.left);892 //}890 if ((style & SWT.H_SCROLL) != 0) { 891 OS.WinDrawText (hps, -1, buffer.getBytes(), rcl, 0, 0, flags); 892 newWidth = Math.max (newWidth, rcl.xRight - rcl.xLeft); 893 } 893 894 index++; 894 895 } 895 // if ((style & SWT.H_SCROLL) != 0) { 896 // if (newFont != 0) OS.SelectObject (hDC, oldFont); 897 // OS.ReleaseDC (handle, hDC); 898 // setScrollWidth (newWidth, false); 899 // } 896 if ((style & SWT.H_SCROLL) != 0) { 897 if (this.hps == 0) OS.WinReleasePS (hps); 898 setScrollWidth (newWidth, false); 899 } 900 900 if (end < topIndex) { 901 901 topIndex -= end - start + 1; … … 945 945 checkWidget (); 946 946 OS.WinSendMsg (handle, OS.LM_DELETEALL, 0, 0); 947 //@@TODO(lpino): 948 // if ((style & SWT.H_SCROLL) != 0) { 947 if ((style & SWT.H_SCROLL) != 0) { 949 948 // OS.SendMessage (handle, OS.LB_SETHORIZONTALEXTENT, 0, 0); 950 //}949 } 951 950 } 952 951 … … 1103 1102 } 1104 1103 1105 //void setBounds (int x, int y, int width, int height, int flags) {1104 void setBounds (int x, int y, int width, int height, int flags) { 1106 1105 // /* 1107 1106 // * Bug in Windows. If the receiver is scrolled horizontally … … 1113 1112 // return; 1114 1113 // } 1115 // RECT rect = new RECT();1116 // OS.GetWindowRect (handle, rect);1117 //super.setBounds (x, y, width, height, flags);1118 // if (((rect.right - rect.left) == width) || ((rect.bottom - rect.top) == height)) return;1114 RECTL rcl = new RECTL (); 1115 OS.WinQueryWindowRect (handle, rcl); 1116 super.setBounds (x, y, width, height, flags); 1117 if (((rcl.xRight - rcl.xLeft) == width) || ((rcl.yTop - rcl.yBottom) == height)) return; 1119 1118 // SCROLLINFO info = new SCROLLINFO (); 1120 1119 // info.cbSize = SCROLLINFO.sizeof; … … 1122 1121 // if (!OS.GetScrollInfo (handle, OS.SB_HORZ, info)) return; 1123 1122 // if (info.nPos != 0) OS.InvalidateRect (handle, null, true); 1124 //}1123 } 1125 1124 1126 1125 void setFocusIndex (int index) { … … 1132 1131 super.setFont (font); 1133 1132 //@@TODO(lpino): Implement setScrollWidth () 1134 //if ((style & SWT.H_SCROLL) != 0) setScrollWidth ();1133 if ((style & SWT.H_SCROLL) != 0) setScrollWidth (); 1135 1134 } 1136 1135 … … 1248 1247 } 1249 1248 //@@TODO(lpino): Implement ? 1250 //void setScrollWidth () { 1251 // int newWidth = 0; 1249 void setScrollWidth () { 1250 int newWidth = 0; 1251 int hps = this.hps; 1252 if (hps == 0) hps = OS.WinGetPS (handle); 1253 RECTL rcl = new RECTL(); 1254 int count = OS.WinSendMsg (handle, OS.LM_QUERYITEMCOUNT, 0, 0); 1255 int flags = OS.DT_QUERYEXTENT | OS.DT_TEXTATTRS; 1256 for (int i=0; i<count; i++) { 1257 int length = OS.WinSendMsg (handle, OS.LM_QUERYITEMTEXTLENGTH,(short)i, 0); 1258 if (length != OS.LIT_ERROR) { 1259 PSZ buffer = new PSZ( length + 1); 1260 int result = OS.WinSendMsg (handle, OS.LM_QUERYITEMTEXT, OS.MPFROM2SHORT((short)i,(short)length), buffer); 1261 if (result != 0) { 1262 OS.WinDrawText (hps, -1, buffer.getBytes(), rcl, 0, 0, flags); 1263 newWidth = Math.max (newWidth, rcl.xRight - rcl.xLeft); 1264 } 1265 } 1266 } 1267 if (this.hps == 0) OS.WinReleasePS (hps); 1268 OS.WinSendMsg (handle, OS.LM_SETITEMWIDTH, newWidth, 0); 1269 1252 1270 // RECT rect = new RECT (); 1253 1271 // int newFont, oldFont = 0; … … 1272 1290 // OS.ReleaseDC (handle, hDC); 1273 1291 // OS.SendMessage (handle, OS.LB_SETHORIZONTALEXTENT, newWidth + 3, 0); 1274 //}1292 } 1275 1293 //@@TODO(lpino): Implement ? 1276 //void setScrollWidth (TCHARbuffer, boolean grow) {1277 // RECT rect = new RECT();1294 void setScrollWidth (PSZ buffer, boolean grow) { 1295 RECTL rcl = new RECTL (); 1278 1296 // int newFont, oldFont = 0; 1279 1297 // int hDC = OS.GetDC (handle); 1298 int hps = this.hps; 1299 if (hps == 0) hps = OS.WinGetPS (handle); 1280 1300 // newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); 1281 1301 // if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont); 1282 1302 // int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX; 1303 int flags = OS.DT_QUERYEXTENT | OS.DT_TEXTATTRS; 1304 OS.WinDrawText (hps, -1, buffer.getBytes(), rcl, 0, 0, flags); 1305 if (this.hps == 0) OS.WinReleasePS (hps); 1283 1306 // OS.DrawText (hDC, buffer, -1, rect, flags); 1284 1307 // if (newFont != 0) OS.SelectObject (hDC, oldFont); 1285 1308 // OS.ReleaseDC (handle, hDC); 1286 // setScrollWidth (rect.right - rect.left, grow);1287 //}1288 1289 //void setScrollWidth (int newWidth, boolean grow) {1290 // int width = OS.SendMessage (handle, OS.LB_GETHORIZONTALEXTENT, 0, 0);1291 //if (grow) {1292 //if (newWidth <= width) return;1293 // OS.SendMessage (handle, OS.LB_SETHORIZONTALEXTENT, newWidth + 3, 0);1294 //} else {1295 //if (newWidth < width) return;1296 //setScrollWidth ();1297 //}1298 //}1309 setScrollWidth (rcl.xRight - rcl.xLeft, grow); 1310 } 1311 1312 void setScrollWidth (int newWidth, boolean grow) { 1313 int width = OS.WinQuerySysValue (handle, OS.SV_CYHSCROLL); 1314 if (grow) { 1315 if (newWidth <= width) return; 1316 OS.WinSendMsg (handle, OS.LM_SETITEMWIDTH, newWidth, 0); 1317 } else { 1318 if (newWidth < width) return; 1319 setScrollWidth (); 1320 } 1321 } 1299 1322 1300 1323 /** … … 1420 1443 checkWidget (); 1421 1444 if ((style & SWT.MULTI) != 0) deselectAll (); 1422 select (start, end);1445 select (start, end); 1423 1446 if ((style & SWT.MULTI) != 0) { 1424 1447 if (start != -1) setFocusIndex (start); … … 1464 1487 checkWidget (); 1465 1488 int index; 1466 int result = OS.WinSendMsg (handle, OS.LM_QUERYSELECTION, OS.LIT_FIRST, 0); 1467 index = result; 1468 if (result == OS.LIT_NONE) return; 1469 //@@TODO(lpino): Test border conditions to see if this code is necesary 1470 // int count = OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0); 1471 // if (count == 0) return; 1472 // int height = OS.SendMessage (handle, OS.LB_GETITEMHEIGHT, 0, 0); 1473 // RECT rect = new RECT (); 1474 // OS.GetClientRect (handle, rect); 1475 // int topIndex = OS.SendMessage (handle, OS.LB_GETTOPINDEX, 0, 0); 1476 // int visibleCount = Math.max (rect.bottom / height, 1); 1477 // int bottomIndex = Math.min (topIndex + visibleCount + 1, count - 1); 1478 // if ((topIndex <= index) && (index <= bottomIndex)) return; 1479 // int newTop = Math.min (Math.max (index - (visibleCount / 2), 0), count - 1); 1480 OS.WinSendMsg (handle, OS.LM_SETTOPINDEX,(short) index, 0); 1489 //@@INFO(lpino): There is no difference in OS/2 between selecting single and multiple selects. The API is the same 1490 // and one needs to call LM_QUERYSELECTION multiple times to get the indexes until it returns LIT_NONE 1491 index = OS.WinSendMsg (handle, OS.LM_QUERYSELECTION, OS.LIT_FIRST, 0); 1492 if (index == OS.LIT_NONE) return; 1493 1494 int count = OS.WinSendMsg (handle, OS.LM_QUERYITEMCOUNT, 0, 0); 1495 if (count == 0) return; 1496 int height = getItemHeight(); 1497 RECTL rect = new RECTL (); 1498 OS. WinQueryWindowRect (handle, rect); 1499 int topIndex = OS.WinSendMsg (handle, OS.LM_QUERYTOPINDEX, 0, 0); 1500 int visibleCount = Math.max (rect.yTop / height, 1); 1501 int bottomIndex = Math.min (topIndex + visibleCount + 1, count - 1); 1502 if ((topIndex <= index) && (index <= bottomIndex)) return; 1503 int newTop = Math.min (Math.max (index - (visibleCount / 2), 0), count - 1); 1504 OS.WinSendMsg (handle, OS.LM_SETTOPINDEX,(short) newTop, 0); 1481 1505 } 1482 1506 1483 1507 int widgetStyle () { 1484 int bits = super.widgetStyle () | OS.LS_NOADJUSTPOS;1508 int bits = super.widgetStyle (); 1485 1509 if ((style & SWT.SINGLE) != 0) return bits; 1486 1510 if ((style & SWT.MULTI) != 0) { 1487 1511 if ((style & SWT.SIMPLE) != 0) 1488 bits |= OS.LS_MULTIPLESEL; 1489 else 1490 bits |= OS.LS_EXTENDEDSEL; 1512 return bits |= OS.LS_MULTIPLESEL; 1513 return bits |= OS.LS_EXTENDEDSEL | OS.LS_EXTENDEDSEL; 1491 1514 } 1492 1515 if ((style & SWT.H_SCROLL) != 0) … … 1502 1525 return ListProc; 1503 1526 } 1504 //@@TODO(lpino): Implement this call1505 //MRESULT WM_MEASUREITEM (int mp1, int mp2) {1506 // return super.WM_MEASUREITEM (mp1, mp2);1507 //}1508 1527 1509 1528 MRESULT wmControlChild (int mp1, int mp2) { 1510 1529 int code = mp1 >> 16; 1511 1530 switch (code) { 1512 case OS.LN_ SELECT:1531 case OS.LN_ENTER: 1513 1532 postEvent (SWT.Selection); 1514 1533 break; 1515 case OS.LN_ ENTER:1534 case OS.LN_SELECT: 1516 1535 postEvent(SWT.DefaultSelection); 1517 1536 break; 1518 1537 } 1519 1538 return super.wmControlChild (mp1, mp2); … … 1527 1546 1528 1547 //@@TODO(lpino): Implement this 1529 //int wmMeasureItem (int msg, int mp1, int mp2) { 1548 MRESULT wmMeasureChild (int mp1, int mp2) { 1549 System.out.println("List::wmMeasureChild"); 1530 1550 // int code = callWindowProc (msg, mp1, mp2); 1531 1551 //// if (code == 0) return MRESULT.ZERO; 1532 // return code;1533 //}1534 1535 } 1552 return MRESULT.ZERO; 1553 } 1554 1555 }
Note:
See TracChangeset
for help on using the changeset viewer.