1 11 package org.eclipse.swt.widgets; 12 13 14 import org.eclipse.swt.internal.win32.*; 15 import org.eclipse.swt.*; 16 import org.eclipse.swt.graphics.*; 17 18 31 32 public class TableItem extends Item { 33 Table parent; 34 String [] strings; 35 Image [] images; 36 boolean checked, grayed, cached; 37 int imageIndent, background = -1, foreground = -1, font = -1; 38 int [] cellBackground, cellForeground, cellFont; 39 40 70 public TableItem (Table parent, int style) { 71 this (parent, style, checkNull (parent).getItemCount (), true); 72 } 73 74 106 public TableItem (Table parent, int style, int index) { 107 this (parent, style, index, true); 108 } 109 110 TableItem (Table parent, int style, int index, boolean create) { 111 super (parent, style); 112 this.parent = parent; 113 if (create) parent.createItem (this, index); 114 } 115 116 static Table checkNull (Table control) { 117 if (control == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); 118 return control; 119 } 120 121 protected void checkSubclass () { 122 if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); 123 } 124 125 void clear () { 126 text = ""; 127 image = null; 128 strings = null; 129 images = null; 130 imageIndent = 0; 131 checked = grayed = false; 132 background = foreground = font = -1; 133 cellBackground = cellForeground = cellFont = null; 134 if ((parent.style & SWT.VIRTUAL) != 0) cached = false; 135 } 136 137 void destroyWidget () { 138 parent.destroyItem (this); 139 releaseHandle (); 140 } 141 142 154 public Color getBackground () { 155 checkWidget (); 156 if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED); 157 if (background == -1) return parent.getBackground (); 158 return Color.win32_new (display, background); 159 } 160 161 174 public Color getBackground (int index) { 175 checkWidget (); 176 if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED); 177 int count = Math.max (1, parent.getColumnCount ()); 178 if (0 > index || index > count - 1) return getBackground (); 179 int pixel = cellBackground != null ? cellBackground [index] : -1; 180 return pixel == -1 ? getBackground () : Color.win32_new (display, pixel); 181 } 182 183 196 public Rectangle getBounds () { 197 checkWidget(); 198 if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED); 199 int itemIndex = parent.indexOf (this); 200 if (itemIndex == -1) return new Rectangle (0, 0, 0, 0); 201 RECT rect = getBounds (itemIndex, 0, true, false, false); 202 int width = rect.right - rect.left, height = rect.bottom - rect.top; 203 return new Rectangle (rect.left, rect.top, width, height); 204 } 205 206 218 public Rectangle getBounds (int index) { 219 checkWidget(); 220 if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED); 221 int itemIndex = parent.indexOf (this); 222 if (itemIndex == -1) return new Rectangle (0, 0, 0, 0); 223 RECT rect = getBounds (itemIndex, index, true, true, true); 224 int width = rect.right - rect.left, height = rect.bottom - rect.top; 225 return new Rectangle (rect.left, rect.top, width, height); 226 } 227 228 RECT getBounds (int row, int column, boolean getText, boolean getImage, boolean fullText) { 229 return getBounds (row, column, getText, getImage, fullText, false, 0); 230 } 231 232 RECT getBounds (int row, int column, boolean getText, boolean getImage, boolean fullText, boolean fullImage, int hDC) { 233 if (!getText && !getImage) return new RECT (); 234 int columnCount = parent.getColumnCount (); 235 if (!(0 <= column && column < Math.max (1, columnCount))) { 236 return new RECT (); 237 } 238 if (parent.fixScrollWidth) parent.setScrollWidth (null, true); 239 RECT rect = new RECT (); 240 int hwnd = parent.handle; 241 int bits = OS.SendMessage (hwnd, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0); 242 if (column == 0 && (bits & OS.LVS_EX_FULLROWSELECT) == 0) { 243 if (parent.explorerTheme) { 244 rect.left = OS.LVIR_ICON; 245 parent.ignoreCustomDraw = true; 246 int code = OS.SendMessage (hwnd, OS. LVM_GETITEMRECT, row, rect); 247 parent.ignoreCustomDraw = false; 248 if (code == 0) return new RECT (); 249 if (getText) { 250 int width = 0; 251 int hFont = cellFont != null ? cellFont [column] : -1; 252 if (hFont == -1) hFont = font; 253 if (hFont == -1 && hDC == 0) { 254 TCHAR buffer = new TCHAR (parent.getCodePage (), text, true); 255 width = OS.SendMessage (hwnd, OS.LVM_GETSTRINGWIDTH, 0, buffer); 256 } else { 257 TCHAR buffer = new TCHAR (parent.getCodePage (), text, false); 258 int textDC = hDC != 0 ? hDC : OS.GetDC (hwnd), oldFont = -1; 259 if (hDC == 0) { 260 if (hFont == -1) hFont = OS.SendMessage (hwnd, OS.WM_GETFONT, 0, 0); 261 oldFont = OS.SelectObject (textDC, hFont); 262 } 263 RECT textRect = new RECT (); 264 int flags = OS.DT_NOPREFIX | OS.DT_SINGLELINE | OS.DT_CALCRECT; 265 OS.DrawText (textDC, buffer, buffer.length (), textRect, flags); 266 width = textRect.right - textRect.left; 267 if (hDC == 0) { 268 if (oldFont != -1) OS.SelectObject (textDC, oldFont); 269 OS.ReleaseDC (hwnd, textDC); 270 } 271 } 272 if (!getImage) rect.left = rect.right; 273 rect.right += width + Table.INSET * 2; 274 } 275 } else { 276 if (getText) { 277 rect.left = OS.LVIR_SELECTBOUNDS; 278 parent.ignoreCustomDraw = true; 279 int code = OS.SendMessage (hwnd, OS.LVM_GETITEMRECT, row, rect); 280 parent.ignoreCustomDraw = false; 281 if (code == 0) return new RECT (); 282 if (!getImage) { 283 RECT iconRect = new RECT (); 284 iconRect.left = OS.LVIR_ICON; 285 parent.ignoreCustomDraw = true; 286 code = OS.SendMessage (hwnd, OS. LVM_GETITEMRECT, row, iconRect); 287 parent.ignoreCustomDraw = false; 288 if (code != 0) rect.left = iconRect.right; 289 } 290 } else { 291 rect.left = OS.LVIR_ICON; 292 parent.ignoreCustomDraw = true; 293 int code = OS.SendMessage (hwnd, OS.LVM_GETITEMRECT, row, rect); 294 parent.ignoreCustomDraw = false; 295 if (code == 0) return new RECT (); 296 } 297 } 298 if (fullText || fullImage) { 299 RECT headerRect = new RECT (); 300 int hwndHeader = OS.SendMessage (hwnd, OS.LVM_GETHEADER, 0, 0); 301 OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, 0, headerRect); 302 OS.MapWindowPoints (hwndHeader, hwnd, headerRect, 2); 303 if (getText && fullText) rect.right = headerRect.right; 304 if (getImage && fullImage) rect.left = headerRect.left; 305 } 306 } else { 307 313 boolean hasImage = (column == 0 && image != null) || (images != null && images [column] != null); 314 rect.top = column; 315 if (fullText || fullImage || hDC == 0) { 316 322 rect.left = getText ? OS.LVIR_LABEL : OS.LVIR_ICON; 323 parent.ignoreCustomDraw = true; 324 int code = OS.SendMessage (hwnd, OS. LVM_GETSUBITEMRECT, row, rect); 325 parent.ignoreCustomDraw = false; 326 if (code == 0) return new RECT (); 327 336 if (column == 0 && getText && getImage) { 337 RECT iconRect = new RECT (); 338 iconRect.left = OS.LVIR_ICON; 339 parent.ignoreCustomDraw = true; 340 code = OS.SendMessage (hwnd, OS. LVM_GETSUBITEMRECT, row, iconRect); 341 parent.ignoreCustomDraw = false; 342 if (code != 0) rect.left = iconRect.left; 343 } 344 if (hasImage) { 345 if (column != 0 && getText && !getImage) { 346 RECT iconRect = new RECT (); 347 iconRect.top = column; 348 iconRect.left = OS.LVIR_ICON; 349 if (OS.SendMessage (hwnd, OS. LVM_GETSUBITEMRECT, row, iconRect) != 0) { 350 rect.left = iconRect.right + Table.INSET / 2; 351 } 352 } 353 } else { 354 if (getImage && !getText) rect.right = rect.left; 355 } 356 if (column == 0 && fullImage) { 357 RECT headerRect = new RECT (); 358 int hwndHeader = OS.SendMessage (hwnd, OS.LVM_GETHEADER, 0, 0); 359 OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, 0, headerRect); 360 OS.MapWindowPoints (hwndHeader, hwnd, headerRect, 2); 361 rect.left = headerRect.left; 362 } 363 } else { 364 rect.left = OS.LVIR_ICON; 365 parent.ignoreCustomDraw = true; 366 int code = OS.SendMessage (hwnd, OS. LVM_GETSUBITEMRECT, row, rect); 367 parent.ignoreCustomDraw = false; 368 if (code == 0) return new RECT (); 369 if (!hasImage) rect.right = rect.left; 370 if (getText) { 371 String string = column == 0 ? text : strings != null ? strings [column] : null; 372 if (string != null) { 373 RECT textRect = new RECT (); 374 TCHAR buffer = new TCHAR (parent.getCodePage (), string, false); 375 int flags = OS.DT_NOPREFIX | OS.DT_SINGLELINE | OS.DT_CALCRECT; 376 OS.DrawText (hDC, buffer, buffer.length (), textRect, flags); 377 rect.right += textRect.right - textRect.left + Table.INSET * 3 + 1; 378 } 379 } 380 } 381 } 382 388 int gridWidth = parent.getLinesVisible () ? Table.GRID_WIDTH : 0; 389 if (OS.COMCTL32_VERSION >= OS.VERSION (5, 80)) rect.top -= gridWidth; 390 if (column != 0) rect.left += gridWidth; 391 rect.right = Math.max (rect.right, rect.left); 392 rect.top += gridWidth; 393 rect.bottom = Math.max (rect.bottom - gridWidth, rect.top); 394 return rect; 395 } 396 397 409 public boolean getChecked () { 410 checkWidget(); 411 if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED); 412 if ((parent.style & SWT.CHECK) == 0) return false; 413 return checked; 414 } 415 416 428 public Font getFont () { 429 checkWidget (); 430 if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED); 431 return font == -1 ? parent.getFont () : Font.win32_new (display, font); 432 } 433 434 448 public Font getFont (int index) { 449 checkWidget (); 450 if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED); 451 int count = Math.max (1, parent.getColumnCount ()); 452 if (0 > index || index > count -1) return getFont (); 453 int hFont = (cellFont != null) ? cellFont [index] : font; 454 return hFont == -1 ? getFont () : Font.win32_new (display, hFont); 455 } 456 457 469 public Color getForeground () { 470 checkWidget (); 471 if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED); 472 if (foreground == -1) return parent.getForeground (); 473 return Color.win32_new (display, foreground); 474 } 475 476 490 public Color getForeground (int index) { 491 checkWidget (); 492 if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED); 493 int count = Math.max (1, parent.getColumnCount ()); 494 if (0 > index || index > count -1) return getForeground (); 495 int pixel = cellForeground != null ? cellForeground [index] : -1; 496 return pixel == -1 ? getForeground () : Color.win32_new (display, pixel); 497 } 498 499 511 public boolean getGrayed () { 512 checkWidget(); 513 if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED); 514 if ((parent.style & SWT.CHECK) == 0) return false; 515 return grayed; 516 } 517 518 public Image getImage () { 519 checkWidget(); 520 if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED); 521 return super.getImage (); 522 } 523 524 536 public Image getImage (int index) { 537 checkWidget(); 538 if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED); 539 if (index == 0) return getImage (); 540 if (images != null) { 541 if (0 <= index && index < images.length) return images [index]; 542 } 543 return null; 544 } 545 546 560 public Rectangle getImageBounds (int index) { 561 checkWidget(); 562 if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED); 563 int itemIndex = parent.indexOf (this); 564 if (itemIndex == -1) return new Rectangle (0, 0, 0, 0); 565 RECT rect = getBounds (itemIndex, index, false, true, false); 566 int width = rect.right - rect.left, height = rect.bottom - rect.top; 567 return new Rectangle (rect.left, rect.top, width, height); 568 } 569 570 580 public int getImageIndent () { 581 checkWidget(); 582 if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED); 583 return imageIndent; 584 } 585 586 String getNameText () { 587 if ((parent.style & SWT.VIRTUAL) != 0) { 588 if (!cached) return "*virtual*"; } 590 return super.getNameText (); 591 } 592 593 603 public Table getParent () { 604 checkWidget(); 605 return parent; 606 } 607 608 public String getText () { 609 checkWidget(); 610 if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED); 611 return super.getText (); 612 } 613 614 626 public String getText (int index) { 627 checkWidget(); 628 if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED); 629 if (index == 0) return getText (); 630 if (strings != null) { 631 if (0 <= index && index < strings.length) { 632 String string = strings [index]; 633 return string != null ? string : ""; 634 } 635 } 636 return ""; 637 } 638 639 655 public Rectangle getTextBounds (int index) { 656 checkWidget(); 657 if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED); 658 int itemIndex = parent.indexOf (this); 659 if (itemIndex == -1) return new Rectangle (0, 0, 0, 0); 660 RECT rect = getBounds (itemIndex, index, true, false, true); 661 rect.left += 2; 662 if (index != 0) rect.left += Table.INSET; 663 rect.left = Math.min (rect.left, rect.right); 664 rect.right = rect.right - Table.INSET; 665 int width = Math.max (0, rect.right - rect.left); 666 int height = Math.max (0, rect.bottom - rect.top); 667 return new Rectangle (rect.left, rect.top, width, height); 668 } 669 670 void redraw () { 671 if (parent.currentItem == this || parent.drawCount != 0) return; 672 int hwnd = parent.handle; 673 if (!OS.IsWindowVisible (hwnd)) return; 674 int index = parent.indexOf (this); 675 if (index == -1) return; 676 OS.SendMessage (hwnd, OS.LVM_REDRAWITEMS, index, index); 677 } 678 679 void redraw (int column, boolean drawText, boolean drawImage) { 680 if (parent.currentItem == this || parent.drawCount != 0) return; 681 int hwnd = parent.handle; 682 if (!OS.IsWindowVisible (hwnd)) return; 683 int index = parent.indexOf (this); 684 if (index == -1) return; 685 RECT rect = getBounds (index, column, drawText, drawImage, true); 686 OS.InvalidateRect (hwnd, rect, true); 687 } 688 689 void releaseHandle () { 690 super.releaseHandle (); 691 parent = null; 692 } 693 694 void releaseWidget () { 695 super.releaseWidget (); 696 strings = null; 697 images = null; 698 cellBackground = cellForeground = cellFont = null; 699 } 700 701 718 public void setBackground (Color color) { 719 checkWidget (); 720 if (color != null && color.isDisposed ()) { 721 SWT.error (SWT.ERROR_INVALID_ARGUMENT); 722 } 723 int pixel = -1; 724 if (color != null) { 725 parent.setCustomDraw (true); 726 pixel = color.handle; 727 } 728 if (background == pixel) return; 729 background = pixel; 730 if ((parent.style & SWT.VIRTUAL) != 0) cached = true; 731 redraw (); 732 } 733 734 752 public void setBackground (int index, Color color) { 753 checkWidget (); 754 if (color != null && color.isDisposed ()) { 755 SWT.error (SWT.ERROR_INVALID_ARGUMENT); 756 } 757 int count = Math.max (1, parent.getColumnCount ()); 758 if (0 > index || index > count - 1) return; 759 int pixel = -1; 760 if (color != null) { 761 parent.setCustomDraw (true); 762 pixel = color.handle; 763 } 764 if (cellBackground == null) { 765 cellBackground = new int [count]; 766 for (int i = 0; i < count; i++) { 767 cellBackground [i] = -1; 768 } 769 } 770 if (cellBackground [index] == pixel) return; 771 cellBackground [index] = pixel; 772 if ((parent.style & SWT.VIRTUAL) != 0) cached = true; 773 redraw (index, true, true); 774 } 775 776 787 public void setChecked (boolean checked) { 788 checkWidget(); 789 if ((parent.style & SWT.CHECK) == 0) return; 790 if (this.checked == checked) return; 791 setChecked (checked, false); 792 } 793 794 void setChecked (boolean checked, boolean notify) { 795 this.checked = checked; 796 if ((parent.style & SWT.VIRTUAL) != 0) cached = true; 797 if (notify) { 798 Event event = new Event(); 799 event.item = this; 800 event.detail = SWT.CHECK; 801 parent.postEvent (SWT.Selection, event); 802 } 803 redraw (); 804 } 805 806 823 public void setFont (Font font){ 824 checkWidget (); 825 if (font != null && font.isDisposed ()) { 826 SWT.error (SWT.ERROR_INVALID_ARGUMENT); 827 } 828 int hFont = -1; 829 if (font != null) { 830 parent.setCustomDraw (true); 831 hFont = font.handle; 832 } 833 if (this.font == hFont) return; 834 this.font = hFont; 835 if ((parent.style & SWT.VIRTUAL) != 0) cached = true; 836 847 if ((parent.style & SWT.VIRTUAL) == 0 && cached) { 848 int itemIndex = parent.indexOf (this); 849 if (itemIndex != -1) { 850 int hwnd = parent.handle; 851 LVITEM lvItem = new LVITEM (); 852 lvItem.mask = OS.LVIF_TEXT; 853 lvItem.iItem = itemIndex; 854 lvItem.pszText = OS.LPSTR_TEXTCALLBACK; 855 OS.SendMessage (hwnd, OS.LVM_SETITEM, 0, lvItem); 856 cached = false; 857 } 858 } 859 parent.setScrollWidth (this, false); 860 redraw (); 861 } 862 863 882 public void setFont (int index, Font font) { 883 checkWidget (); 884 if (font != null && font.isDisposed ()) { 885 SWT.error (SWT.ERROR_INVALID_ARGUMENT); 886 } 887 int count = Math.max (1, parent.getColumnCount ()); 888 if (0 > index || index > count - 1) return; 889 int hFont = -1; 890 if (font != null) { 891 parent.setCustomDraw (true); 892 hFont = font.handle; 893 } 894 if (cellFont == null) { 895 cellFont = new int [count]; 896 for (int i = 0; i < count; i++) { 897 cellFont [i] = -1; 898 } 899 } 900 if (cellFont [index] == hFont) return; 901 cellFont [index] = hFont; 902 if ((parent.style & SWT.VIRTUAL) != 0) cached = true; 903 if (index == 0) { 904 915 if ((parent.style & SWT.VIRTUAL) == 0 && cached) { 916 int itemIndex = parent.indexOf (this); 917 if (itemIndex != -1) { 918 int hwnd = parent.handle; 919 LVITEM lvItem = new LVITEM (); 920 lvItem.mask = OS.LVIF_TEXT; 921 lvItem.iItem = itemIndex; 922 lvItem.pszText = OS.LPSTR_TEXTCALLBACK; 923 OS.SendMessage (hwnd, OS.LVM_SETITEM, 0, lvItem); 924 cached = false; 925 } 926 } 927 parent.setScrollWidth (this, false); 928 } 929 redraw (index, true, false); 930 } 931 932 949 public void setForeground (Color color){ 950 checkWidget (); 951 if (color != null && color.isDisposed ()) { 952 SWT.error (SWT.ERROR_INVALID_ARGUMENT); 953 } 954 int pixel = -1; 955 if (color != null) { 956 parent.setCustomDraw (true); 957 pixel = color.handle; 958 } 959 if (foreground == pixel) return; 960 foreground = pixel; 961 if ((parent.style & SWT.VIRTUAL) != 0) cached = true; 962 redraw (); 963 } 964 965 983 public void setForeground (int index, Color color){ 984 checkWidget (); 985 if (color != null && color.isDisposed ()) { 986 SWT.error (SWT.ERROR_INVALID_ARGUMENT); 987 } 988 int count = Math.max (1, parent.getColumnCount ()); 989 if (0 > index || index > count - 1) return; 990 int pixel = -1; 991 if (color != null) { 992 parent.setCustomDraw (true); 993 pixel = color.handle; 994 } 995 if (cellForeground == null) { 996 cellForeground = new int [count]; 997 for (int i = 0; i < count; i++) { 998 cellForeground [i] = -1; 999 } 1000 } 1001 if (cellForeground [index] == pixel) return; 1002 cellForeground [index] = pixel; 1003 if ((parent.style & SWT.VIRTUAL) != 0) cached = true; 1004 redraw (index, true, false); 1005} 1006 1007 1018public void setGrayed (boolean grayed) { 1019 checkWidget(); 1020 if ((parent.style & SWT.CHECK) == 0) return; 1021 if (this.grayed == grayed) return; 1022 this.grayed = grayed; 1023 if ((parent.style & SWT.VIRTUAL) != 0) cached = true; 1024 redraw (); 1025} 1026 1027 1041public void setImage (Image [] images) { 1042 checkWidget(); 1043 if (images == null) error (SWT.ERROR_NULL_ARGUMENT); 1044 for (int i=0; i<images.length; i++) { 1045 setImage (i, images [i]); 1046 } 1047} 1048 1049 1063public void setImage (int index, Image image) { 1064 checkWidget(); 1065 if (image != null && image.isDisposed ()) { 1066 error(SWT.ERROR_INVALID_ARGUMENT); 1067 } 1068 Image oldImage = null; 1069 if (index == 0) { 1070 if (image != null && image.type == SWT.ICON) { 1071 if (image.equals (this.image)) return; 1072 } 1073 oldImage = this.image; 1074 super.setImage (image); 1075 } 1076 int count = Math.max (1, parent.getColumnCount ()); 1077 if (0 > index || index > count - 1) return; 1078 if (images == null && index != 0) { 1079 images = new Image [count]; 1080 images [0] = image; 1081 } 1082 if (images != null) { 1083 if (image != null && image.type == SWT.ICON) { 1084 if (image.equals (images [index])) return; 1085 } 1086 oldImage = images [index]; 1087 images [index] = image; 1088 } 1089 if ((parent.style & SWT.VIRTUAL) != 0) cached = true; 1090 1091 1092 parent.imageIndex (image, index); 1093 1094 if (index == 0) parent.setScrollWidth (this, false); 1095 boolean drawText = (image == null && oldImage != null) || (image != null && oldImage == null); 1096 redraw (index, drawText, true); 1097} 1098 1099public void setImage (Image image) { 1100 checkWidget (); 1101 setImage (0, image); 1102} 1103 1104 1117public void setImageIndent (int indent) { 1118 checkWidget(); 1119 if (indent < 0) return; 1120 if (imageIndent == indent) return; 1121 imageIndent = indent; 1122 if ((parent.style & SWT.VIRTUAL) != 0) { 1123 cached = true; 1124 } else { 1125 int index = parent.indexOf (this); 1126 if (index != -1) { 1127 int hwnd = parent.handle; 1128 LVITEM lvItem = new LVITEM (); 1129 lvItem.mask = OS.LVIF_INDENT; 1130 lvItem.iItem = index; 1131 lvItem.iIndent = indent; 1132 OS.SendMessage (hwnd, OS.LVM_SETITEM, 0, lvItem); 1133 } 1134 } 1135 parent.setScrollWidth (this, false); 1136 redraw (); 1137} 1138 1139 1152public void setText (String [] strings) { 1153 checkWidget(); 1154 if (strings == null) error (SWT.ERROR_NULL_ARGUMENT); 1155 for (int i=0; i<strings.length; i++) { 1156 String string = strings [i]; 1157 if (string != null) setText (i, string); 1158 } 1159} 1160 1161 1175public void setText (int index, String string) { 1176 checkWidget(); 1177 if (string == null) error (SWT.ERROR_NULL_ARGUMENT); 1178 if (index == 0) { 1179 if (string.equals (text)) return; 1180 super.setText (string); 1181 } 1182 int count = Math.max (1, parent.getColumnCount ()); 1183 if (0 > index || index > count - 1) return; 1184 if (strings == null && index != 0) { 1185 strings = new String [count]; 1186 strings [0] = text; 1187 } 1188 if (strings != null) { 1189 if (string.equals (strings [index])) return; 1190 strings [index] = string; 1191 } 1192 if ((parent.style & SWT.VIRTUAL) != 0) cached = true; 1193 if (index == 0) { 1194 1205 if ((parent.style & SWT.VIRTUAL) == 0 && cached) { 1206 int itemIndex = parent.indexOf (this); 1207 if (itemIndex != -1) { 1208 int hwnd = parent.handle; 1209 LVITEM lvItem = new LVITEM (); 1210 lvItem.mask = OS.LVIF_TEXT; 1211 lvItem.iItem = itemIndex; 1212 lvItem.pszText = OS.LPSTR_TEXTCALLBACK; 1213 OS.SendMessage (hwnd, OS.LVM_SETITEM, 0, lvItem); 1214 cached = false; 1215 } 1216 } 1217 parent.setScrollWidth (this, false); 1218 } 1219 redraw (index, true, false); 1220} 1221 1222public void setText (String string) { 1223 checkWidget(); 1224 setText (0, string); 1225} 1226 1227} 1228 | Popular Tags |