comparison dwt/widgets/TableItem.d @ 213:36f5cb12e1a2

Update to SWT 3.4M7
author Frank Benoit <benoit@tionex.de>
date Sat, 17 May 2008 17:34:28 +0200
parents ab60f3309436
children fd9c62a2998e
comparison
equal deleted inserted replaced
212:ab60f3309436 213:36f5cb12e1a2
43 43
44 public class TableItem : Item { 44 public class TableItem : Item {
45 Table parent; 45 Table parent;
46 String [] strings; 46 String [] strings;
47 Image [] images; 47 Image [] images;
48 Font font;
49 Font [] cellFont;
48 bool checked, grayed, cached; 50 bool checked, grayed, cached;
49 int imageIndent, background = -1, foreground = -1; 51 int imageIndent, background = -1, foreground = -1;
50 HFONT font = cast(HFONT)-1;
51 int [] cellBackground, cellForeground; 52 int [] cellBackground, cellForeground;
52 HFONT[] cellFont;
53 53
54 /** 54 /**
55 * Constructs a new instance of this class given its parent 55 * Constructs a new instance of this class given its parent
56 * (which must be a <code>Table</code>) and a style value 56 * (which must be a <code>Table</code>) and a style value
57 * describing its behavior and appearance. The item is added 57 * describing its behavior and appearance. The item is added
141 image = null; 141 image = null;
142 strings = null; 142 strings = null;
143 images = null; 143 images = null;
144 imageIndent = 0; 144 imageIndent = 0;
145 checked = grayed = false; 145 checked = grayed = false;
146 font = null;
146 background = foreground = -1; 147 background = foreground = -1;
147 font = cast(HFONT)-1; 148 cellFont = null;
148 cellBackground = cellForeground = null; 149 cellBackground = cellForeground = null;
149 cellFont = null; 150 cellFont = null;
150 if ((parent.style & DWT.VIRTUAL) !is 0) cached = false; 151 if ((parent.style & DWT.VIRTUAL) !is 0) cached = false;
151 } 152 }
152 153
153 override void destroyWidget () { 154 override void destroyWidget () {
154 parent.destroyItem (this); 155 parent.destroyItem (this);
155 releaseHandle (); 156 releaseHandle ();
157 }
158
159 HFONT fontHandle (int index) {
160 if (cellFont !is null && cellFont [index] !is null) return cellFont [index].handle;
161 if (font !is null) return font.handle;
162 return cast(HFONT)-1;
156 } 163 }
157 164
158 /** 165 /**
159 * Returns the receiver's background color. 166 * Returns the receiver's background color.
160 * 167 *
262 int code = OS.SendMessage (hwnd, OS. LVM_GETITEMRECT, row, &rect); 269 int code = OS.SendMessage (hwnd, OS. LVM_GETITEMRECT, row, &rect);
263 parent.ignoreCustomDraw = false; 270 parent.ignoreCustomDraw = false;
264 if (code is 0) return RECT.init; 271 if (code is 0) return RECT.init;
265 if (getText) { 272 if (getText) {
266 int width = 0; 273 int width = 0;
267 auto hFont = cellFont !is null ? cellFont [column] : cast(HFONT)-1; 274 auto hFont = fontHandle (column);
268 if (hFont is cast(HFONT)-1) hFont = font;
269 if (hFont is cast(HFONT)-1 && hDC is null) { 275 if (hFont is cast(HFONT)-1 && hDC is null) {
270 TCHAR* buffer = StrToTCHARz (parent.getCodePage (), text); 276 TCHAR* buffer = StrToTCHARz (parent.getCodePage (), text);
271 width = OS.SendMessage (hwnd, OS.LVM_GETSTRINGWIDTH, 0, buffer); 277 width = OS.SendMessage (hwnd, OS.LVM_GETSTRINGWIDTH, 0, buffer);
272 } else { 278 } else {
273 TCHAR[] buffer = StrToTCHARs (parent.getCodePage (), text, false); 279 TCHAR[] buffer = StrToTCHARs (parent.getCodePage (), text, false);
442 * @since 3.0 448 * @since 3.0
443 */ 449 */
444 public Font getFont () { 450 public Font getFont () {
445 checkWidget (); 451 checkWidget ();
446 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); 452 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED);
447 return font is cast(HFONT)-1 ? parent.getFont () : Font.win32_new (display, font); 453 return font !is null ? font : parent.getFont ();
448 } 454 }
449 455
450 /** 456 /**
451 * Returns the font that the receiver will use to paint textual information 457 * Returns the font that the receiver will use to paint textual information
452 * for the specified cell in this item. 458 * for the specified cell in this item.
464 public Font getFont (int index) { 470 public Font getFont (int index) {
465 checkWidget (); 471 checkWidget ();
466 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); 472 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED);
467 int count = Math.max (1, parent.getColumnCount ()); 473 int count = Math.max (1, parent.getColumnCount ());
468 if (0 > index || index > count -1) return getFont (); 474 if (0 > index || index > count -1) return getFont ();
469 auto hFont = (cellFont !is null) ? cellFont [index] : font; 475 if (cellFont is null || cellFont [index] is null) return getFont ();
470 return hFont is cast(HFONT)-1 ? getFont () : Font.win32_new (display, hFont); 476 return cellFont [index];
471 } 477 }
472 478
473 /** 479 /**
474 * Returns the foreground color that the receiver will use to draw. 480 * Returns the foreground color that the receiver will use to draw.
475 * 481 *
709 715
710 override void releaseWidget () { 716 override void releaseWidget () {
711 super.releaseWidget (); 717 super.releaseWidget ();
712 strings = null; 718 strings = null;
713 images = null; 719 images = null;
720 cellFont = null;
714 cellBackground = cellForeground = null; 721 cellBackground = cellForeground = null;
715 cellFont = null;
716 } 722 }
717 723
718 /** 724 /**
719 * Sets the receiver's background color to the color specified 725 * Sets the receiver's background color to the color specified
720 * by the argument, or to the default system color for the item 726 * by the argument, or to the default system color for the item
840 public void setFont (Font font){ 846 public void setFont (Font font){
841 checkWidget (); 847 checkWidget ();
842 if (font !is null && font.isDisposed ()) { 848 if (font !is null && font.isDisposed ()) {
843 DWT.error (DWT.ERROR_INVALID_ARGUMENT); 849 DWT.error (DWT.ERROR_INVALID_ARGUMENT);
844 } 850 }
845 HFONT hFont = cast(HFONT)-1; 851 Font oldFont = this.font;
846 if (font !is null) { 852 if (oldFont is font) return;
847 parent.setCustomDraw (true); 853 this.font = font;
848 hFont = font.handle; 854 if (oldFont !is null && oldFont.opEquals (font)) return;
849 } 855 if (font !is null) parent.setCustomDraw (true);
850 if (this.font is hFont) return;
851 this.font = hFont;
852 if ((parent.style & DWT.VIRTUAL) !is 0) cached = true; 856 if ((parent.style & DWT.VIRTUAL) !is 0) cached = true;
853 /* 857 /*
854 * Bug in Windows. Despite the fact that every item in the 858 * Bug in Windows. Despite the fact that every item in the
855 * table always has LPSTR_TEXTCALLBACK, Windows caches the 859 * table always has LPSTR_TEXTCALLBACK, Windows caches the
856 * bounds for the selected items. This means that 860 * bounds for the selected items. This means that
901 if (font !is null && font.isDisposed ()) { 905 if (font !is null && font.isDisposed ()) {
902 DWT.error (DWT.ERROR_INVALID_ARGUMENT); 906 DWT.error (DWT.ERROR_INVALID_ARGUMENT);
903 } 907 }
904 int count = Math.max (1, parent.getColumnCount ()); 908 int count = Math.max (1, parent.getColumnCount ());
905 if (0 > index || index > count - 1) return; 909 if (0 > index || index > count - 1) return;
906 auto hFont = cast(HFONT)-1;
907 if (font !is null) {
908 parent.setCustomDraw (true);
909 hFont = font.handle;
910 }
911 if (cellFont is null) { 910 if (cellFont is null) {
912 cellFont = new HFONT [count]; 911 if (font is null) return;
913 for (int i = 0; i < count; i++) { 912 cellFont = new Font [count];
914 cellFont [i] = cast(HFONT)-1; 913 }
915 } 914 Font oldFont = cellFont [index];
916 } 915 if (oldFont is font) return;
917 if (cellFont [index] is hFont) return; 916 cellFont [index] = font;
918 cellFont [index] = hFont; 917 if (oldFont !is null && oldFont.opEquals (font)) return;
918 if (font !is null) parent.setCustomDraw (true);
919 if ((parent.style & DWT.VIRTUAL) !is 0) cached = true; 919 if ((parent.style & DWT.VIRTUAL) !is 0) cached = true;
920 if (index is 0) { 920 if (index is 0) {
921 /* 921 /*
922 * Bug in Windows. Despite the fact that every item in the 922 * Bug in Windows. Despite the fact that every item in the
923 * table always has LPSTR_TEXTCALLBACK, Windows caches the 923 * table always has LPSTR_TEXTCALLBACK, Windows caches the