Mercurial > projects > dwt-linux
annotate dwt/widgets/TreeItem.d @ 255:5a30aa9820f3
removed tango.stdc.stringz imports and allow null for arrays and string arguments.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 15 Jun 2008 22:32:20 +0200 |
parents | ce446666f5a2 |
children | c0d810de7093 |
rev | line source |
---|---|
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
1 /******************************************************************************* |
90 | 2 * Copyright (c) 2000, 2007 IBM Corporation and others. |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
108 | 10 * Port to the D programming language: |
11 * Frank Benoit <benoit@tionex.de> | |
90 | 12 *******************************************************************************/ |
13 module dwt.widgets.TreeItem; | |
14 | |
238 | 15 import dwt.dwthelper.utils; |
16 | |
90 | 17 |
18 | |
19 import dwt.DWT; | |
20 import dwt.DWTException; | |
21 import dwt.graphics.Color; | |
22 import dwt.graphics.Font; | |
23 import dwt.graphics.Image; | |
24 import dwt.graphics.Rectangle; | |
25 import dwt.internal.gtk.OS; | |
26 import dwt.widgets.Item; | |
27 import dwt.widgets.Tree; | |
28 import dwt.widgets.ImageList; | |
29 | |
30 import Math = tango.math.Math; | |
31 | |
32 /** | |
33 * Instances of this class represent a selectable user interface object | |
34 * that represents a hierarchy of tree items in a tree widget. | |
35 * | |
36 * <dl> | |
37 * <dt><b>Styles:</b></dt> | |
38 * <dd>(none)</dd> | |
39 * <dt><b>Events:</b></dt> | |
40 * <dd>(none)</dd> | |
41 * </dl> | |
42 * <p> | |
43 * IMPORTANT: This class is <em>not</em> intended to be subclassed. | |
44 * </p> | |
45 */ | |
46 public class TreeItem : Item { | |
47 Tree parent; | |
48 Font font; | |
49 Font[] cellFont; | |
50 bool cached, grayed; | |
51 static final int EXPANDER_EXTRA_PADDING = 4; | |
52 | |
53 /** | |
54 * Constructs a new instance of this class given its parent | |
55 * (which must be a <code>Tree</code> or a <code>TreeItem</code>) | |
56 * and a style value describing its behavior and appearance. | |
57 * The item is added to the end of the items maintained by its parent. | |
58 * <p> | |
59 * The style value is either one of the style constants defined in | |
60 * class <code>DWT</code> which is applicable to instances of this | |
61 * class, or must be built by <em>bitwise OR</em>'ing together | |
62 * (that is, using the <code>int</code> "|" operator) two or more | |
63 * of those <code>DWT</code> style constants. The class description | |
64 * lists the style constants that are applicable to the class. | |
65 * Style bits are also inherited from superclasses. | |
66 * </p> | |
67 * | |
68 * @param parent a tree control which will be the parent of the new instance (cannot be null) | |
69 * @param style the style of control to construct | |
70 * | |
71 * @exception IllegalArgumentException <ul> | |
72 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
73 * </ul> | |
74 * @exception DWTException <ul> | |
75 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
76 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
77 * </ul> | |
78 * | |
79 * @see DWT | |
80 * @see Widget#checkSubclass | |
81 * @see Widget#getStyle | |
82 */ | |
83 public this (Tree parent, int style) { | |
84 this (checkNull (parent), null, style, -1, true); | |
85 } | |
86 | |
87 /** | |
88 * Constructs a new instance of this class given its parent | |
89 * (which must be a <code>Tree</code> or a <code>TreeItem</code>), | |
90 * a style value describing its behavior and appearance, and the index | |
91 * at which to place it in the items maintained by its parent. | |
92 * <p> | |
93 * The style value is either one of the style constants defined in | |
94 * class <code>DWT</code> which is applicable to instances of this | |
95 * class, or must be built by <em>bitwise OR</em>'ing together | |
96 * (that is, using the <code>int</code> "|" operator) two or more | |
97 * of those <code>DWT</code> style constants. The class description | |
98 * lists the style constants that are applicable to the class. | |
99 * Style bits are also inherited from superclasses. | |
100 * </p> | |
101 * | |
102 * @param parent a tree control which will be the parent of the new instance (cannot be null) | |
103 * @param style the style of control to construct | |
104 * @param index the zero-relative index to store the receiver in its parent | |
105 * | |
106 * @exception IllegalArgumentException <ul> | |
107 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
108 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li> | |
109 * </ul> | |
110 * @exception DWTException <ul> | |
111 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
112 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
113 * </ul> | |
114 * | |
115 * @see DWT | |
116 * @see Widget#checkSubclass | |
117 * @see Widget#getStyle | |
118 */ | |
119 public this (Tree parent, int style, int index) { | |
120 this (checkNull (parent), null, style, checkIndex (index), true); | |
121 } | |
122 | |
123 /** | |
124 * Constructs a new instance of this class given its parent | |
125 * (which must be a <code>Tree</code> or a <code>TreeItem</code>) | |
126 * and a style value describing its behavior and appearance. | |
127 * The item is added to the end of the items maintained by its parent. | |
128 * <p> | |
129 * The style value is either one of the style constants defined in | |
130 * class <code>DWT</code> which is applicable to instances of this | |
131 * class, or must be built by <em>bitwise OR</em>'ing together | |
132 * (that is, using the <code>int</code> "|" operator) two or more | |
133 * of those <code>DWT</code> style constants. The class description | |
134 * lists the style constants that are applicable to the class. | |
135 * Style bits are also inherited from superclasses. | |
136 * </p> | |
137 * | |
138 * @param parentItem a tree control which will be the parent of the new instance (cannot be null) | |
139 * @param style the style of control to construct | |
140 * | |
141 * @exception IllegalArgumentException <ul> | |
142 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
143 * </ul> | |
144 * @exception DWTException <ul> | |
145 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
146 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
147 * </ul> | |
148 * | |
149 * @see DWT | |
150 * @see Widget#checkSubclass | |
151 * @see Widget#getStyle | |
152 */ | |
153 public this (TreeItem parentItem, int style) { | |
154 this (checkNull (parentItem).parent, cast(GtkTreeIter*)parentItem.handle, style, -1, true); | |
155 } | |
156 | |
157 /** | |
158 * Constructs a new instance of this class given its parent | |
159 * (which must be a <code>Tree</code> or a <code>TreeItem</code>), | |
160 * a style value describing its behavior and appearance, and the index | |
161 * at which to place it in the items maintained by its parent. | |
162 * <p> | |
163 * The style value is either one of the style constants defined in | |
164 * class <code>DWT</code> which is applicable to instances of this | |
165 * class, or must be built by <em>bitwise OR</em>'ing together | |
166 * (that is, using the <code>int</code> "|" operator) two or more | |
167 * of those <code>DWT</code> style constants. The class description | |
168 * lists the style constants that are applicable to the class. | |
169 * Style bits are also inherited from superclasses. | |
170 * </p> | |
171 * | |
172 * @param parentItem a tree control which will be the parent of the new instance (cannot be null) | |
173 * @param style the style of control to construct | |
174 * @param index the zero-relative index to store the receiver in its parent | |
175 * | |
176 * @exception IllegalArgumentException <ul> | |
177 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
178 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li> | |
179 * </ul> | |
180 * @exception DWTException <ul> | |
181 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
182 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
183 * </ul> | |
184 * | |
185 * @see DWT | |
186 * @see Widget#checkSubclass | |
187 * @see Widget#getStyle | |
188 */ | |
189 public this (TreeItem parentItem, int style, int index) { | |
190 this (checkNull (parentItem).parent, cast(GtkTreeIter*)parentItem.handle, style, checkIndex (index), true); | |
191 } | |
192 | |
193 this (Tree parent, GtkTreeIter* parentIter, int style, int index, bool create) { | |
194 super (parent, style); | |
195 this.parent = parent; | |
196 if (create) { | |
197 parent.createItem (this, parentIter, index); | |
198 } else { | |
199 handle = cast(GtkWidget*)OS.g_malloc (GtkTreeIter.sizeof); | |
200 OS.gtk_tree_model_iter_nth_child (parent.modelHandle, handle, parentIter, index); | |
201 } | |
202 } | |
203 | |
204 static int checkIndex (int index) { | |
205 if (index < 0) DWT.error (DWT.ERROR_INVALID_RANGE); | |
206 return index; | |
207 } | |
208 | |
209 static TreeItem checkNull (TreeItem item) { | |
210 if (item is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
211 return item; | |
212 } | |
213 | |
214 static Tree checkNull (Tree control) { | |
215 if (control is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
216 return control; | |
217 } | |
218 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
219 protected override void checkSubclass () { |
90 | 220 if (!isValidSubclass ()) error (DWT.ERROR_INVALID_SUBCLASS); |
221 } | |
222 | |
240 | 223 Color _getBackground () { |
224 void* ptr; | |
225 OS.gtk_tree_model_get1 (parent.modelHandle, handle, Tree.BACKGROUND_COLUMN, &ptr); | |
226 if (ptr is null) return parent.getBackground (); | |
227 GdkColor* gdkColor = new GdkColor (); | |
228 *gdkColor = *cast(GdkColor*) ptr; | |
229 return Color.gtk_new (display, gdkColor); | |
230 } | |
231 | |
232 Color _getBackground (int index) { | |
233 int count = Math.max (1, parent.columnCount); | |
234 if (0 > index || index > count - 1) return _getBackground (); | |
235 void* ptr; | |
236 int modelIndex = parent.columnCount is 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; | |
237 OS.gtk_tree_model_get1 (parent.modelHandle, handle, modelIndex + Tree.CELL_BACKGROUND, &ptr); | |
238 if (ptr is null) return _getBackground (); | |
239 GdkColor* gdkColor = new GdkColor (); | |
240 *gdkColor = *cast(GdkColor*) ptr; | |
241 return Color.gtk_new (display, gdkColor); | |
242 } | |
243 | |
244 bool _getChecked () { | |
245 void* ptr; | |
246 OS.gtk_tree_model_get1 (parent.modelHandle, handle, Tree.CHECKED_COLUMN, &ptr); | |
247 return ptr !is null; | |
248 } | |
249 | |
250 Color _getForeground () { | |
251 void* ptr; | |
252 OS.gtk_tree_model_get1 (parent.modelHandle, handle, Tree.FOREGROUND_COLUMN, &ptr); | |
253 if (ptr is null) return parent.getForeground (); | |
254 GdkColor* gdkColor = new GdkColor (); | |
255 *gdkColor = *cast(GdkColor*) ptr; | |
256 return Color.gtk_new (display, gdkColor); | |
257 } | |
258 | |
259 Color _getForeground (int index) { | |
260 int count = Math.max (1, parent.columnCount); | |
261 if (0 > index || index > count - 1) return _getForeground (); | |
262 void* ptr; | |
263 int modelIndex = parent.columnCount is 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; | |
264 OS.gtk_tree_model_get1 (parent.modelHandle, handle, modelIndex + Tree.CELL_FOREGROUND, &ptr); | |
265 if (ptr is null) return _getForeground (); | |
266 GdkColor* gdkColor = new GdkColor (); | |
267 *gdkColor = *cast(GdkColor*) ptr; | |
268 return Color.gtk_new (display, gdkColor); | |
269 } | |
270 | |
271 Image _getImage (int index) { | |
272 int count = Math.max (1, parent.getColumnCount ()); | |
273 if (0 > index || index > count - 1) return null; | |
274 void* ptr; | |
275 int modelIndex = parent.columnCount is 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; | |
276 OS.gtk_tree_model_get1 (parent.modelHandle, handle, modelIndex + Tree.CELL_PIXBUF, &ptr); | |
277 if (ptr is null) return null; | |
278 ImageList imageList = parent.imageList; | |
279 int imageIndex = imageList.indexOf (ptr); | |
280 if (imageIndex is -1) return null; | |
281 return imageList.get (imageIndex); | |
282 } | |
283 | |
284 String _getText (int index) { | |
285 int count = Math.max (1, parent.getColumnCount ()); | |
286 if (0 > index || index > count - 1) return ""; | |
287 void* ptr; | |
288 int modelIndex = parent.columnCount is 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; | |
289 OS.gtk_tree_model_get1 (parent.modelHandle, handle, modelIndex + Tree.CELL_TEXT, &ptr); | |
290 if (ptr is null) return ""; //$NON-NLS-1$ | |
255
5a30aa9820f3
removed tango.stdc.stringz imports and allow null for arrays and string arguments.
Frank Benoit <benoit@tionex.de>
parents:
240
diff
changeset
|
291 char[] buffer = fromStringz( cast(char*)ptr).dup; |
240 | 292 OS.g_free (ptr); |
293 return buffer; | |
294 } | |
295 | |
90 | 296 void clear () { |
297 if (parent.currentItem is this) return; | |
298 if (cached || (parent.style & DWT.VIRTUAL) is 0) { | |
299 int columnCount = OS.gtk_tree_model_get_n_columns (parent.modelHandle); | |
300 for (int i=Tree.CHECKED_COLUMN; i<columnCount; i++) { | |
301 OS.gtk_tree_store_set1(parent.modelHandle, cast(GtkTreeIter*)handle, i, null); | |
302 } | |
303 /* | |
304 * Bug in GTK. When using fixed-height-mode, | |
305 * row changes do not cause the row to be repainted. The fix is to | |
306 * invalidate the row when it is cleared. | |
307 */ | |
308 if ((parent.style & DWT.VIRTUAL) !is 0) { | |
309 if (OS.GTK_VERSION >= OS.buildVERSION (2, 3, 2) && OS.GTK_VERSION < OS.buildVERSION (2, 6, 3)) { | |
310 redraw (); | |
311 } | |
312 } | |
313 } | |
314 cached = false; | |
315 font = null; | |
316 cellFont = null; | |
317 } | |
318 | |
319 /** | |
320 * Clears the item at the given zero-relative index in the receiver. | |
321 * The text, icon and other attributes of the item are set to the default | |
322 * value. If the tree was created with the <code>DWT.VIRTUAL</code> style, | |
323 * these attributes are requested again as needed. | |
324 * | |
325 * @param index the index of the item to clear | |
326 * @param all <code>true</code> if all child items of the indexed item should be | |
327 * cleared recursively, and <code>false</code> otherwise | |
328 * | |
329 * @exception IllegalArgumentException <ul> | |
330 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> | |
331 * </ul> | |
332 * @exception DWTException <ul> | |
333 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
334 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
335 * </ul> | |
336 * | |
337 * @see DWT#VIRTUAL | |
338 * @see DWT#SetData | |
339 * | |
340 * @since 3.2 | |
341 */ | |
342 public void clear (int index, bool all) { | |
343 checkWidget (); | |
344 parent.clear (cast(GtkTreeIter*)handle, index, all); | |
345 } | |
346 | |
347 /** | |
348 * Clears all the items in the receiver. The text, icon and other | |
349 * attributes of the items are set to their default values. If the | |
350 * tree was created with the <code>DWT.VIRTUAL</code> style, these | |
351 * attributes are requested again as needed. | |
352 * | |
353 * @param all <code>true</code> if all child items should be cleared | |
354 * recursively, and <code>false</code> otherwise | |
355 * | |
356 * @exception DWTException <ul> | |
357 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
358 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
359 * </ul> | |
360 * | |
361 * @see DWT#VIRTUAL | |
362 * @see DWT#SetData | |
363 * | |
364 * @since 3.2 | |
365 */ | |
366 public void clearAll (bool all) { | |
367 checkWidget (); | |
368 parent.clearAll (all, cast(GtkTreeIter*)handle); | |
369 } | |
370 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
371 override void destroyWidget () { |
90 | 372 parent.releaseItem (this, false); |
373 parent.destroyItem (this); | |
374 releaseHandle (); | |
375 } | |
376 | |
377 /** | |
378 * Returns the receiver's background color. | |
379 * | |
380 * @return the background color | |
381 * | |
382 * @exception DWTException <ul> | |
383 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
384 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
385 * </ul> | |
386 * | |
387 * @since 2.0 | |
388 * | |
389 */ | |
390 public Color getBackground () { | |
391 checkWidget (); | |
392 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); | |
240 | 393 return _getBackground (); |
90 | 394 } |
395 | |
396 /** | |
397 * Returns the background color at the given column index in the receiver. | |
398 * | |
399 * @param index the column index | |
400 * @return the background color | |
401 * | |
402 * @exception DWTException <ul> | |
403 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
404 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
405 * </ul> | |
406 * | |
407 * @since 3.1 | |
408 */ | |
409 public Color getBackground (int index) { | |
410 checkWidget (); | |
411 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); | |
240 | 412 return _getBackground (index); |
90 | 413 } |
414 | |
415 /** | |
416 * Returns a rectangle describing the receiver's size and location | |
417 * relative to its parent at a column in the tree. | |
418 * | |
419 * @param index the index that specifies the column | |
420 * @return the receiver's bounding column rectangle | |
421 * | |
422 * @exception DWTException <ul> | |
423 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
424 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
425 * </ul> | |
426 * | |
427 * @since 3.1 | |
428 */ | |
429 public Rectangle getBounds (int index) { | |
430 // TODO fully test on early and later versions of GTK | |
431 checkWidget(); | |
432 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); | |
433 auto parentHandle = parent.handle; | |
434 GtkTreeViewColumn* column; | |
435 if (index >= 0 && index < parent.columnCount) { | |
436 column = cast(GtkTreeViewColumn*)parent.columns [index].handle; | |
437 } else { | |
438 column = OS.gtk_tree_view_get_column (parentHandle, index); | |
439 } | |
440 if (column is null) return new Rectangle (0, 0, 0, 0); | |
441 auto path = OS.gtk_tree_model_get_path (parent.modelHandle, handle); | |
442 OS.gtk_widget_realize (parentHandle); | |
443 GdkRectangle rect; | |
444 OS.gtk_tree_view_get_cell_area (parentHandle, path, column, &rect); | |
240 | 445 if ((parent.getStyle () & DWT.MIRRORED) !is 0) rect.x = parent.getClientWidth () - rect.width - rect.x; |
90 | 446 |
447 if (OS.GTK_VERSION < OS.buildVERSION (2, 8, 18) && OS.gtk_tree_view_get_expander_column (parentHandle) is column) { | |
448 int buffer; | |
449 OS.gtk_widget_style_get1 (parentHandle, OS.expander_size.ptr, &buffer); | |
450 rect.x += buffer + TreeItem.EXPANDER_EXTRA_PADDING; | |
451 rect.width -= buffer + TreeItem.EXPANDER_EXTRA_PADDING; | |
452 OS.gtk_widget_style_get1 (parentHandle, OS.horizontal_separator.ptr, &buffer); | |
453 rect.x += buffer; | |
454 //rect.width -= buffer [0]; // TODO Is this required for some versions? | |
455 } | |
240 | 456 /* |
457 * Bug in GTK. In GTK 2.8.x, the cell area is left aligned even | |
458 * when the widget is mirrored. The fix is to sum up the indentation | |
459 * of the expanders. | |
460 */ | |
461 if ((parent.getStyle () & DWT.MIRRORED) !is 0 && (OS.GTK_VERSION < OS.buildVERSION (2, 10, 0))) { | |
462 int depth = OS.gtk_tree_path_get_depth (path); | |
463 int expanderSize; | |
464 OS.gtk_widget_style_get1 (parentHandle, OS.expander_size.ptr, &expanderSize); | |
465 rect.x += depth * (expanderSize + TreeItem.EXPANDER_EXTRA_PADDING); | |
466 } | |
467 OS.gtk_tree_path_free (path); | |
90 | 468 |
469 if (index is 0 && (parent.style & DWT.CHECK) !is 0) { | |
470 if (OS.GTK_VERSION >= OS.buildVERSION (2, 1, 3)) { | |
471 int x, w; | |
472 OS.gtk_tree_view_column_cell_get_position (column, parent.checkRenderer, &x, &w); | |
473 rect.x += x + w; | |
474 rect.width -= x + w; | |
475 } else { | |
476 int w; | |
477 OS.gtk_cell_renderer_get_size (parent.checkRenderer, parentHandle, null, null, null, &w, null); | |
478 int buffer; | |
479 OS.gtk_widget_style_get1 (parentHandle, OS.horizontal_separator.ptr, &buffer); | |
480 rect.x += w + buffer; | |
481 rect.width -= w + buffer; | |
482 } | |
483 } | |
240 | 484 int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width + 1 : 0; |
485 return new Rectangle (rect.x, rect.y, width, rect.height + 1); | |
90 | 486 } |
487 | |
488 /** | |
489 * Returns a rectangle describing the receiver's size and location | |
490 * relative to its parent. | |
491 * | |
492 * @return the receiver's bounding rectangle | |
493 * | |
494 * @exception DWTException <ul> | |
495 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
496 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
497 * </ul> | |
498 */ | |
499 public Rectangle getBounds () { | |
500 // TODO fully test on early and later versions of GTK | |
501 // shifted a bit too far right on later versions of GTK - however, old Tree also had this problem | |
502 checkWidget (); | |
503 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); | |
504 auto parentHandle = parent.handle; | |
505 auto column = OS.gtk_tree_view_get_column (parentHandle, 0); | |
506 if (column is null) return new Rectangle (0, 0, 0, 0); | |
507 auto textRenderer = parent.getTextRenderer (column); | |
508 auto pixbufRenderer = parent.getPixbufRenderer (column); | |
509 if (textRenderer is null || pixbufRenderer is null) return new Rectangle (0, 0, 0, 0); | |
510 | |
511 auto path = OS.gtk_tree_model_get_path (parent.modelHandle, handle); | |
512 OS.gtk_widget_realize (parentHandle); | |
513 | |
514 bool isExpander = OS.gtk_tree_model_iter_n_children (parent.modelHandle, handle) > 0; | |
515 bool isExpanded = cast(bool)OS.gtk_tree_view_row_expanded (parentHandle, path); | |
516 OS.gtk_tree_view_column_cell_set_cell_data (column, parent.modelHandle, handle, isExpander, isExpanded); | |
517 | |
518 GdkRectangle rect; | |
519 OS.gtk_tree_view_get_cell_area (parentHandle, path, column, &rect); | |
240 | 520 if ((parent.getStyle () & DWT.MIRRORED) !is 0) rect.x = parent.getClientWidth () - rect.width - rect.x; |
90 | 521 int right = rect.x + rect.width; |
522 | |
523 int x, w; | |
524 parent.ignoreSize = true; | |
525 OS.gtk_cell_renderer_get_size (textRenderer, parentHandle, null, null, null, &w, null); | |
526 parent.ignoreSize = false; | |
527 rect.width = w; | |
528 int buffer; | |
529 if (OS.GTK_VERSION < OS.buildVERSION (2, 8, 18) && OS.gtk_tree_view_get_expander_column (parentHandle) is column) { | |
530 OS.gtk_widget_style_get1 (parentHandle, OS.expander_size.ptr, &buffer); | |
531 rect.x += buffer + TreeItem.EXPANDER_EXTRA_PADDING; | |
532 } | |
240 | 533 /* |
534 * Bug in GTK. In GTK 2.8.x, the cell area is left aligned even | |
535 * when the widget is mirrored. The fix is to sum up the indentation | |
536 * of the expanders. | |
537 */ | |
538 if ((parent.getStyle () & DWT.MIRRORED) !is 0 && (OS.GTK_VERSION < OS.buildVERSION (2, 10, 0))) { | |
539 int depth = OS.gtk_tree_path_get_depth (path); | |
540 int expanderSize; | |
541 OS.gtk_widget_style_get1 (parentHandle, OS.expander_size.ptr, &expanderSize); | |
542 rect.x += depth * (expanderSize + TreeItem.EXPANDER_EXTRA_PADDING); | |
543 } | |
544 OS.gtk_tree_path_free (path); | |
545 | |
90 | 546 OS.gtk_widget_style_get1 (parentHandle, OS.horizontal_separator.ptr, &buffer); |
547 int horizontalSeparator = buffer; | |
548 rect.x += horizontalSeparator; | |
549 | |
550 if (OS.GTK_VERSION >= OS.buildVERSION (2, 1, 3)) { | |
551 OS.gtk_tree_view_column_cell_get_position (column, textRenderer, &x, null); | |
552 rect.x += x; | |
553 } else { | |
554 if ((parent.style & DWT.CHECK) !is 0) { | |
555 OS.gtk_cell_renderer_get_size (parent.checkRenderer, parentHandle, null, null, null, &w, null); | |
556 rect.x += w + horizontalSeparator; | |
557 } | |
558 OS.gtk_cell_renderer_get_size (pixbufRenderer, parentHandle, null, null, null, &w, null); | |
559 rect.x += w + horizontalSeparator; | |
560 } | |
561 if (parent.columnCount > 0) { | |
562 if (rect.x + rect.width > right) { | |
563 rect.width = Math.max (0, right - rect.x); | |
564 } | |
565 } | |
240 | 566 int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width + 1 : 0; |
567 return new Rectangle (rect.x, rect.y, width, rect.height + 1); | |
90 | 568 } |
569 | |
570 /** | |
571 * Returns <code>true</code> if the receiver is checked, | |
572 * and false otherwise. When the parent does not have | |
573 * the <code>CHECK style, return false. | |
574 * <p> | |
575 * | |
576 * @return the checked state | |
577 * | |
578 * @exception DWTException <ul> | |
579 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
580 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
581 * </ul> | |
582 */ | |
583 public bool getChecked () { | |
584 checkWidget(); | |
585 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); | |
586 if ((parent.style & DWT.CHECK) is 0) return false; | |
240 | 587 return _getChecked (); |
90 | 588 } |
589 | |
590 /** | |
591 * Returns <code>true</code> if the receiver is expanded, | |
592 * and false otherwise. | |
593 * <p> | |
594 * | |
595 * @return the expanded state | |
596 * | |
597 * @exception DWTException <ul> | |
598 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
599 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
600 * </ul> | |
601 */ | |
602 public bool getExpanded () { | |
603 checkWidget(); | |
604 auto path = OS.gtk_tree_model_get_path (parent.modelHandle, handle); | |
605 bool answer = cast(bool)OS.gtk_tree_view_row_expanded (parent.handle, path); | |
606 OS.gtk_tree_path_free (path); | |
607 return answer; | |
608 } | |
609 | |
610 /** | |
611 * Returns the font that the receiver will use to paint textual information for this item. | |
612 * | |
613 * @return the receiver's font | |
614 * | |
615 * @exception DWTException <ul> | |
616 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
617 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
618 * </ul> | |
619 * | |
620 * @since 3.0 | |
621 */ | |
622 public Font getFont () { | |
623 checkWidget (); | |
624 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); | |
625 return font !is null ? font : parent.getFont (); | |
626 } | |
627 | |
628 /** | |
629 * Returns the font that the receiver will use to paint textual information | |
630 * for the specified cell in this item. | |
631 * | |
632 * @param index the column index | |
633 * @return the receiver's font | |
634 * | |
635 * @exception DWTException <ul> | |
636 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
637 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
638 * </ul> | |
639 * | |
640 * @since 3.1 | |
641 */ | |
642 public Font getFont (int index) { | |
643 checkWidget (); | |
644 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); | |
645 int count = Math.max (1, parent.columnCount); | |
646 if (0 > index || index > count - 1) return getFont (); | |
647 if (cellFont is null || cellFont [index] is null) return getFont (); | |
648 return cellFont [index]; | |
649 } | |
650 | |
651 | |
652 /** | |
653 * Returns the foreground color that the receiver will use to draw. | |
654 * | |
655 * @return the receiver's foreground color | |
656 * | |
657 * @exception DWTException <ul> | |
658 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
659 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
660 * </ul> | |
661 * | |
662 * @since 2.0 | |
663 * | |
664 */ | |
665 public Color getForeground () { | |
666 checkWidget (); | |
667 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); | |
240 | 668 return _getForeground (); |
90 | 669 } |
670 | |
671 /** | |
672 * | |
673 * Returns the foreground color at the given column index in the receiver. | |
674 * | |
675 * @param index the column index | |
676 * @return the foreground color | |
677 * | |
678 * @exception DWTException <ul> | |
679 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
680 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
681 * </ul> | |
682 * | |
683 * @since 3.1 | |
684 */ | |
685 public Color getForeground (int index) { | |
686 checkWidget (); | |
687 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); | |
240 | 688 return _getForeground (index); |
90 | 689 } |
690 | |
691 /** | |
692 * Returns <code>true</code> if the receiver is grayed, | |
693 * and false otherwise. When the parent does not have | |
694 * the <code>CHECK style, return false. | |
695 * <p> | |
696 * | |
697 * @return the grayed state of the checkbox | |
698 * | |
699 * @exception DWTException <ul> | |
700 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
701 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
702 * </ul> | |
703 */ | |
704 public bool getGrayed () { | |
705 checkWidget (); | |
706 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); | |
707 if ((parent.style & DWT.CHECK) is 0) return false; | |
708 return grayed; | |
709 } | |
710 | |
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
711 public override Image getImage () { |
90 | 712 checkWidget (); |
713 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); | |
714 return getImage (0); | |
715 } | |
716 | |
717 /** | |
718 * Returns the image stored at the given column index in the receiver, | |
719 * or null if the image has not been set or if the column does not exist. | |
720 * | |
721 * @param index the column index | |
722 * @return the image stored at the given column index in the receiver | |
723 * | |
724 * @exception DWTException <ul> | |
725 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
726 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
727 * </ul> | |
728 * | |
729 * @since 3.1 | |
730 */ | |
731 public Image getImage (int index) { | |
732 checkWidget (); | |
733 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); | |
240 | 734 return _getImage (index); |
90 | 735 } |
736 | |
737 /** | |
738 * Returns a rectangle describing the size and location | |
739 * relative to its parent of an image at a column in the | |
740 * tree. | |
741 * | |
742 * @param index the index that specifies the column | |
743 * @return the receiver's bounding image rectangle | |
744 * | |
745 * @exception DWTException <ul> | |
746 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
747 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
748 * </ul> | |
749 * | |
750 * @since 3.1 | |
751 */ | |
752 public Rectangle getImageBounds (int index) { | |
753 // TODO fully test on early and later versions of GTK | |
754 checkWidget (); | |
755 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); | |
756 auto parentHandle = parent.handle; | |
757 GtkTreeViewColumn* column; | |
758 if (index >= 0 && index < parent.getColumnCount ()) { | |
759 column = cast(GtkTreeViewColumn*)parent.columns [index].handle; | |
760 } else { | |
761 column = OS.gtk_tree_view_get_column (parentHandle, index); | |
762 } | |
763 if (column is null) return new Rectangle (0, 0, 0, 0); | |
764 auto pixbufRenderer = parent.getPixbufRenderer (column); | |
765 if (pixbufRenderer is null) return new Rectangle (0, 0, 0, 0); | |
766 GdkRectangle rect; | |
767 auto path = OS.gtk_tree_model_get_path (parent.modelHandle, handle); | |
768 OS.gtk_widget_realize (parentHandle); | |
769 OS.gtk_tree_view_get_cell_area (parentHandle, path, column, &rect); | |
240 | 770 if ((parent.getStyle () & DWT.MIRRORED) !is 0) rect.x = parent.getClientWidth () - rect.width - rect.x; |
90 | 771 if (OS.GTK_VERSION < OS.buildVERSION (2, 8, 18) && OS.gtk_tree_view_get_expander_column (parentHandle) is column) { |
772 int buffer; | |
773 OS.gtk_widget_style_get1 (parentHandle, OS.expander_size.ptr, &buffer); | |
774 rect.x += buffer + TreeItem.EXPANDER_EXTRA_PADDING; | |
775 rect.width -= buffer + TreeItem.EXPANDER_EXTRA_PADDING; | |
776 //OS.gtk_widget_style_get (parentHandle, OS.horizontal_separator, buffer, 0); | |
777 //int horizontalSeparator = buffer[0]; | |
778 //rect.x += horizontalSeparator; | |
779 } | |
240 | 780 /* |
781 * Bug in GTK. In GTK 2.8.x, the cell area is left aligned even | |
782 * when the widget is mirrored. The fix is to sum up the indentation | |
783 * of the expanders. | |
784 */ | |
785 if ((parent.getStyle () & DWT.MIRRORED) !is 0 && (OS.GTK_VERSION < OS.buildVERSION (2, 10, 0))) { | |
786 int depth = OS.gtk_tree_path_get_depth (path); | |
787 int expanderSize; | |
788 OS.gtk_widget_style_get1 (parentHandle, OS.expander_size.ptr, &expanderSize); | |
789 rect.x += depth * (expanderSize + TreeItem.EXPANDER_EXTRA_PADDING); | |
790 } | |
791 OS.gtk_tree_path_free (path); | |
90 | 792 |
793 /* | |
794 * The OS call gtk_cell_renderer_get_size() provides the width of image to be drawn | |
795 * by the cell renderer. If there is no image in the cell, the width is zero. If the table contains | |
796 * images of varying widths, gtk_cell_renderer_get_size() will return the width of the image, | |
797 * not the width of the area in which the image is drawn. | |
798 * New API was added in GTK 2.1.3 for determining the full width of the renderer area. | |
799 * For earlier versions of GTK, the result is only correct if all rows have images of the same | |
800 * width. | |
801 */ | |
802 if (OS.GTK_VERSION >= OS.buildVERSION (2, 1, 3)) { | |
803 int x, w; | |
804 OS.gtk_tree_view_column_cell_get_position (column, pixbufRenderer, &x, &w); | |
805 rect.x += x; | |
806 rect.width = w; | |
807 } else { | |
808 int w; | |
809 OS.gtk_tree_view_column_cell_set_cell_data (column, parent.modelHandle, handle, false, false); | |
810 OS.gtk_cell_renderer_get_size (pixbufRenderer, parentHandle, null, null, null, &w, null); | |
811 rect.width = w; | |
812 } | |
240 | 813 int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width : 0; |
814 return new Rectangle (rect.x, rect.y, width, rect.height + 1); | |
90 | 815 } |
816 | |
817 /** | |
818 * Returns the number of items contained in the receiver | |
819 * that are direct item children of the receiver. | |
820 * | |
821 * @return the number of items | |
822 * | |
823 * @exception DWTException <ul> | |
824 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
825 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
826 * </ul> | |
827 */ | |
828 public int getItemCount () { | |
829 checkWidget(); | |
830 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); | |
831 return OS.gtk_tree_model_iter_n_children (parent.modelHandle, handle); | |
832 } | |
833 | |
834 /** | |
835 * Returns the item at the given, zero-relative index in the | |
836 * receiver. Throws an exception if the index is out of range. | |
837 * | |
838 * @param index the index of the item to return | |
839 * @return the item at the given index | |
840 * | |
841 * @exception IllegalArgumentException <ul> | |
842 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> | |
843 * </ul> | |
844 * @exception DWTException <ul> | |
845 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
846 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
847 * </ul> | |
848 * | |
849 * @since 3.1 | |
850 */ | |
851 public TreeItem getItem (int index) { | |
852 checkWidget(); | |
853 if (index < 0) error (DWT.ERROR_INVALID_RANGE); | |
854 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); | |
855 int itemCount = OS.gtk_tree_model_iter_n_children (parent.modelHandle, handle); | |
856 if (index >= itemCount) error (DWT.ERROR_INVALID_RANGE); | |
857 return parent._getItem (cast(GtkTreeIter*)handle, index); | |
858 } | |
859 | |
860 /** | |
861 * Returns a (possibly empty) array of <code>TreeItem</code>s which | |
862 * are the direct item children of the receiver. | |
863 * <p> | |
864 * Note: This is not the actual structure used by the receiver | |
865 * to maintain its list of items, so modifying the array will | |
866 * not affect the receiver. | |
867 * </p> | |
868 * | |
869 * @return the receiver's items | |
870 * | |
871 * @exception DWTException <ul> | |
872 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
873 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
874 * </ul> | |
875 */ | |
876 public TreeItem [] getItems () { | |
877 checkWidget(); | |
878 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); | |
879 return parent.getItems (cast(GtkTreeIter*)handle); | |
880 } | |
881 | |
238 | 882 override String getNameText () { |
90 | 883 if ((parent.style & DWT.VIRTUAL) !is 0) { |
884 if (!cached) return "*virtual*"; //$NON-NLS-1$ | |
885 } | |
886 return super.getNameText (); | |
887 } | |
888 | |
889 /** | |
890 * Returns the receiver's parent, which must be a <code>Tree</code>. | |
891 * | |
892 * @return the receiver's parent | |
893 * | |
894 * @exception DWTException <ul> | |
895 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
896 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
897 * </ul> | |
898 */ | |
899 public Tree getParent () { | |
900 checkWidget (); | |
901 return parent; | |
902 } | |
903 | |
904 /** | |
905 * Returns the receiver's parent item, which must be a | |
906 * <code>TreeItem</code> or null when the receiver is a | |
907 * root. | |
908 * | |
909 * @return the receiver's parent item | |
910 * | |
911 * @exception DWTException <ul> | |
912 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
913 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
914 * </ul> | |
915 */ | |
916 public TreeItem getParentItem () { | |
917 checkWidget(); | |
918 auto path = OS.gtk_tree_model_get_path (parent.modelHandle, handle); | |
919 TreeItem item = null; | |
920 int depth = OS.gtk_tree_path_get_depth (path); | |
921 if (depth > 1) { | |
922 OS.gtk_tree_path_up (path); | |
923 GtkTreeIter iter; | |
924 if (OS.gtk_tree_model_get_iter (parent.modelHandle, &iter, path)) { | |
925 item = parent._getItem (&iter); | |
926 } | |
927 } | |
928 OS.gtk_tree_path_free (path); | |
929 return item; | |
930 } | |
931 | |
238 | 932 public override String getText () { |
90 | 933 checkWidget (); |
934 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); | |
935 return getText (0); | |
936 } | |
937 | |
938 /** | |
939 * Returns the text stored at the given column index in the receiver, | |
940 * or empty string if the text has not been set. | |
941 * | |
942 * @param index the column index | |
943 * @return the text stored at the given column index in the receiver | |
944 * | |
945 * @exception DWTException <ul> | |
946 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
947 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
948 * </ul> | |
949 * | |
950 * @since 3.1 | |
951 */ | |
238 | 952 public String getText (int index) { |
90 | 953 checkWidget (); |
954 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); | |
240 | 955 return _getText (index); |
90 | 956 } |
957 | |
958 /** | |
959 * Returns a rectangle describing the size and location | |
960 * relative to its parent of the text at a column in the | |
961 * tree. | |
962 * | |
963 * @param index the index that specifies the column | |
964 * @return the receiver's bounding text rectangle | |
965 * | |
966 * @exception DWTException <ul> | |
967 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
968 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
969 * </ul> | |
970 * | |
971 * @since 3.3 | |
972 */ | |
973 public Rectangle getTextBounds (int index) { | |
974 checkWidget (); | |
975 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); | |
976 int count = Math.max (1, parent.getColumnCount ()); | |
977 if (0 > index || index > count - 1) return new Rectangle (0, 0, 0, 0); | |
978 // TODO fully test on early and later versions of GTK | |
979 // shifted a bit too far right on later versions of GTK - however, old Tree also had this problem | |
980 auto parentHandle = parent.handle; | |
981 GtkTreeViewColumn* column; | |
982 if (index >= 0 && index < parent.columnCount) { | |
983 column = cast(GtkTreeViewColumn*)parent.columns [index].handle; | |
984 } else { | |
985 column = OS.gtk_tree_view_get_column (parentHandle, index); | |
986 } | |
987 if (column is null) return new Rectangle (0, 0, 0, 0); | |
988 auto textRenderer = parent.getTextRenderer (column); | |
989 auto pixbufRenderer = parent.getPixbufRenderer (column); | |
990 if (textRenderer is null || pixbufRenderer is null) return new Rectangle (0, 0, 0, 0); | |
991 | |
992 auto path = OS.gtk_tree_model_get_path (parent.modelHandle, handle); | |
993 OS.gtk_widget_realize (parentHandle); | |
994 | |
995 bool isExpander = OS.gtk_tree_model_iter_n_children (parent.modelHandle, handle) > 0; | |
996 bool isExpanded = cast(bool)OS.gtk_tree_view_row_expanded (parentHandle, path); | |
997 OS.gtk_tree_view_column_cell_set_cell_data (column, parent.modelHandle, handle, isExpander, isExpanded); | |
998 | |
999 GdkRectangle rect; | |
1000 OS.gtk_tree_view_get_cell_area (parentHandle, path, column, &rect); | |
240 | 1001 if ((parent.getStyle () & DWT.MIRRORED) !is 0) rect.x = parent.getClientWidth () - rect.width - rect.x; |
90 | 1002 int right = rect.x + rect.width; |
1003 | |
1004 int x, w; | |
1005 parent.ignoreSize = true; | |
1006 OS.gtk_cell_renderer_get_size (textRenderer, parentHandle, null, null, null, &w, null); | |
1007 parent.ignoreSize = false; | |
1008 int buffer; | |
1009 if (OS.GTK_VERSION < OS.buildVERSION (2, 8, 18) && OS.gtk_tree_view_get_expander_column (parentHandle) is column) { | |
1010 OS.gtk_widget_style_get1 (parentHandle, OS.expander_size.ptr, &buffer); | |
1011 rect.x += buffer + TreeItem.EXPANDER_EXTRA_PADDING; | |
1012 } | |
240 | 1013 /* |
1014 * Bug in GTK. In GTK 2.8.x, the cell area is left aligned even | |
1015 * when the widget is mirrored. The fix is to sum up the indentation | |
1016 * of the expanders. | |
1017 */ | |
1018 if ((parent.getStyle () & DWT.MIRRORED) !is 0 && (OS.GTK_VERSION < OS.buildVERSION (2, 10, 0))) { | |
1019 int depth = OS.gtk_tree_path_get_depth (path); | |
1020 int expanderSize; | |
1021 OS.gtk_widget_style_get1 (parentHandle, OS.expander_size.ptr, &expanderSize); | |
1022 rect.x += depth * (expanderSize + TreeItem.EXPANDER_EXTRA_PADDING); | |
1023 } | |
1024 OS.gtk_tree_path_free (path); | |
1025 | |
90 | 1026 OS.gtk_widget_style_get1 (parentHandle, OS.horizontal_separator.ptr, &buffer); |
1027 int horizontalSeparator = buffer; | |
1028 rect.x += horizontalSeparator; | |
1029 if (OS.GTK_VERSION >= OS.buildVERSION (2, 1, 3)) { | |
1030 OS.gtk_tree_view_column_cell_get_position (column, textRenderer, &x, null); | |
1031 rect.x += x; | |
1032 } else { | |
1033 if ((parent.style & DWT.CHECK) !is 0) { | |
1034 OS.gtk_cell_renderer_get_size (parent.checkRenderer, parentHandle, null, null, null, &w, null); | |
1035 rect.x += w + horizontalSeparator; | |
1036 } | |
1037 OS.gtk_cell_renderer_get_size (pixbufRenderer, parentHandle, null, null, null, &w, null); | |
1038 rect.x += w + horizontalSeparator; | |
1039 } | |
1040 if (parent.columnCount > 0) { | |
1041 if (rect.x + rect.width > right) { | |
1042 rect.width = Math.max (0, right - rect.x); | |
1043 } | |
1044 } | |
240 | 1045 int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width + 1 : 0; |
1046 return new Rectangle (rect.x, rect.y, width, rect.height + 1); | |
90 | 1047 } |
1048 | |
1049 /** | |
1050 * Searches the receiver's list starting at the first item | |
1051 * (index 0) until an item is found that is equal to the | |
1052 * argument, and returns the index of that item. If no item | |
1053 * is found, returns -1. | |
1054 * | |
1055 * @param item the search item | |
1056 * @return the index of the item | |
1057 * | |
1058 * @exception IllegalArgumentException <ul> | |
1059 * <li>ERROR_NULL_ARGUMENT - if the item is null</li> | |
1060 * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li> | |
1061 * </ul> | |
1062 * @exception DWTException <ul> | |
1063 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1064 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1065 * </ul> | |
1066 * | |
1067 * @since 3.1 | |
1068 */ | |
1069 public int indexOf (TreeItem item) { | |
1070 checkWidget(); | |
1071 if (item is null) error (DWT.ERROR_NULL_ARGUMENT); | |
1072 if (item.isDisposed()) error (DWT.ERROR_INVALID_ARGUMENT); | |
1073 int index = -1; | |
1074 bool isParent = false; | |
1075 auto currentPath = OS.gtk_tree_model_get_path (parent.modelHandle, handle); | |
1076 auto parentPath = OS.gtk_tree_model_get_path (parent.modelHandle, item.handle); | |
1077 int depth = OS.gtk_tree_path_get_depth (parentPath); | |
1078 if (depth > 1 && OS.gtk_tree_path_up(parentPath)) { | |
1079 if (OS.gtk_tree_path_compare(currentPath, parentPath) is 0) isParent = true; | |
1080 } | |
1081 OS.gtk_tree_path_free (currentPath); | |
1082 OS.gtk_tree_path_free (parentPath); | |
1083 if (!isParent) return index; | |
1084 auto path = OS.gtk_tree_model_get_path (parent.modelHandle, item.handle); | |
1085 if (depth > 1) { | |
1086 auto indices = OS.gtk_tree_path_get_indices (path); | |
1087 if (indices !is null) { | |
1088 int[] temp = indices[ 0 .. depth]; | |
1089 index = temp[temp.length - 1]; | |
1090 } | |
1091 } | |
1092 OS.gtk_tree_path_free (path); | |
1093 return index; | |
1094 } | |
1095 | |
1096 void redraw () { | |
1097 auto parentHandle = parent.handle; | |
1098 if ((OS.GTK_WIDGET_FLAGS (parentHandle) & OS.GTK_REALIZED) !is 0) { | |
1099 auto path = OS.gtk_tree_model_get_path (parent.modelHandle, handle); | |
1100 GdkRectangle rect; | |
1101 OS.gtk_tree_view_get_cell_area (parentHandle, path, null, &rect); | |
1102 OS.gtk_tree_path_free (path); | |
1103 auto window = OS.gtk_tree_view_get_bin_window (parentHandle); | |
1104 rect.x = 0; | |
1105 int w, h; | |
1106 OS.gdk_drawable_get_size (window, &w, &h); | |
1107 rect.width = w; | |
1108 OS.gdk_window_invalidate_rect (window, &rect, false); | |
1109 } | |
1110 } | |
1111 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
1112 override void releaseChildren (bool destroy) { |
90 | 1113 if (destroy) { |
1114 parent.releaseItems (cast(GtkTreeIter*)handle); | |
1115 } | |
1116 super.releaseChildren (destroy); | |
1117 } | |
1118 | |
1119 override void releaseHandle () { | |
1120 if (handle !is null) OS.g_free (handle); | |
1121 handle = null; | |
1122 super.releaseHandle (); | |
1123 parent = null; | |
1124 } | |
1125 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
1126 override void releaseWidget () { |
90 | 1127 super.releaseWidget (); |
1128 font = null; | |
1129 cellFont = null; | |
1130 } | |
1131 | |
1132 /** | |
1133 * Removes all of the items from the receiver. | |
1134 * <p> | |
1135 * @exception DWTException <ul> | |
1136 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1137 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1138 * </ul> | |
1139 * | |
1140 * @since 3.1 | |
1141 */ | |
1142 public void removeAll () { | |
1143 checkWidget (); | |
1144 int length = OS.gtk_tree_model_iter_n_children (parent.modelHandle, handle); | |
1145 if (length is 0) return; | |
1146 GtkTreeIter iter; | |
1147 int index; | |
1148 while (OS.gtk_tree_model_iter_children (parent.modelHandle, &iter, handle)) { | |
1149 OS.gtk_tree_model_get1 (parent.modelHandle, &iter, Tree.ID_COLUMN, cast(void**)&index); | |
1150 if (index !is -1) { | |
1151 TreeItem item = parent.items [index]; | |
1152 if (item !is null && !item.isDisposed ()) { | |
1153 item.dispose (); | |
1154 } | |
1155 } | |
1156 } | |
1157 } | |
1158 | |
1159 /** | |
1160 * Sets the receiver's background color to the color specified | |
1161 * by the argument, or to the default system color for the item | |
1162 * if the argument is null. | |
1163 * | |
1164 * @param color the new color (or null) | |
1165 * | |
1166 * @exception IllegalArgumentException <ul> | |
1167 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> | |
1168 * </ul> | |
1169 * @exception DWTException <ul> | |
1170 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1171 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1172 * </ul> | |
1173 * | |
1174 * @since 2.0 | |
1175 * | |
1176 */ | |
1177 public void setBackground (Color color) { | |
1178 checkWidget (); | |
1179 if (color !is null && color.isDisposed ()) { | |
1180 DWT.error (DWT.ERROR_INVALID_ARGUMENT); | |
1181 } | |
240 | 1182 if (_getBackground ().opEquals (color)) return; |
90 | 1183 GdkColor* gdkColor = color !is null ? color.handle : null; |
1184 OS.gtk_tree_store_set1 (parent.modelHandle, cast(GtkTreeIter*)handle, Tree.BACKGROUND_COLUMN, gdkColor); | |
1185 /* | |
1186 * Bug in GTK. When using fixed-height-mode, | |
1187 * row changes do not cause the row to be repainted. The fix is to | |
1188 * invalidate the row when it is cleared. | |
1189 */ | |
1190 if ((parent.style & DWT.VIRTUAL) !is 0) { | |
1191 if (OS.GTK_VERSION >= OS.buildVERSION (2, 3, 2) && OS.GTK_VERSION < OS.buildVERSION (2, 6, 3)) { | |
1192 redraw (); | |
1193 } | |
1194 } | |
1195 cached = true; | |
1196 } | |
1197 | |
1198 /** | |
1199 * Sets the background color at the given column index in the receiver | |
1200 * to the color specified by the argument, or to the default system color for the item | |
1201 * if the argument is null. | |
1202 * | |
1203 * @param index the column index | |
1204 * @param color the new color (or null) | |
1205 * | |
1206 * @exception IllegalArgumentException <ul> | |
1207 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> | |
1208 * </ul> | |
1209 * @exception DWTException <ul> | |
1210 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1211 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1212 * </ul> | |
1213 * | |
1214 * @since 3.1 | |
1215 * | |
1216 */ | |
1217 public void setBackground (int index, Color color) { | |
1218 checkWidget (); | |
1219 if (color !is null && color.isDisposed ()) { | |
1220 DWT.error (DWT.ERROR_INVALID_ARGUMENT); | |
1221 } | |
240 | 1222 if (_getBackground (index).opEquals (color)) return; |
90 | 1223 int count = Math.max (1, parent.getColumnCount ()); |
1224 if (0 > index || index > count - 1) return; | |
1225 int modelIndex = parent.columnCount is 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; | |
1226 GdkColor* gdkColor = color !is null ? color.handle : null; | |
1227 OS.gtk_tree_store_set1 (parent.modelHandle, cast(GtkTreeIter*)handle, modelIndex + Tree.CELL_BACKGROUND, gdkColor); | |
1228 /* | |
1229 * Bug in GTK. When using fixed-height-mode, | |
1230 * row changes do not cause the row to be repainted. The fix is to | |
1231 * invalidate the row when it is cleared. | |
1232 */ | |
1233 if ((parent.style & DWT.VIRTUAL) !is 0) { | |
1234 if (OS.GTK_VERSION >= OS.buildVERSION (2, 3, 2) && OS.GTK_VERSION < OS.buildVERSION (2, 6, 3)) { | |
1235 redraw (); | |
1236 } | |
1237 } | |
1238 cached = true; | |
1239 | |
1240 if (color !is null) { | |
1241 bool customDraw = (parent.columnCount is 0) ? parent.firstCustomDraw : parent.columns [index].customDraw; | |
1242 if (!customDraw) { | |
1243 if ((parent.style & DWT.VIRTUAL) is 0) { | |
1244 auto parentHandle = parent.handle; | |
1245 GtkTreeViewColumn* column; | |
1246 if (parent.columnCount > 0) { | |
1247 column = cast(GtkTreeViewColumn*)parent.columns [index].handle; | |
1248 } else { | |
1249 column = OS.gtk_tree_view_get_column (parentHandle, index); | |
1250 } | |
1251 if (column is null) return; | |
1252 auto textRenderer = parent.getTextRenderer (column); | |
1253 auto imageRenderer = parent.getPixbufRenderer (column); | |
1254 display.doCellDataProc( parentHandle, cast(GtkTreeViewColumn*)column, cast(GtkCellRenderer*)textRenderer ); | |
1255 display.doCellDataProc( parentHandle, cast(GtkTreeViewColumn*)column, cast(GtkCellRenderer*)imageRenderer ); | |
1256 } | |
1257 if (parent.columnCount is 0) { | |
1258 parent.firstCustomDraw = true; | |
1259 } else { | |
1260 parent.columns [index].customDraw = true; | |
1261 } | |
1262 } | |
1263 } | |
1264 } | |
1265 | |
1266 /** | |
1267 * Sets the checked state of the receiver. | |
1268 * <p> | |
1269 * | |
1270 * @param checked the new checked state | |
1271 * | |
1272 * @exception DWTException <ul> | |
1273 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1274 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1275 * </ul> | |
1276 */ | |
1277 public void setChecked (bool checked) { | |
1278 checkWidget(); | |
1279 if ((parent.style & DWT.CHECK) is 0) return; | |
240 | 1280 if (_getChecked () is checked) return; |
90 | 1281 OS.gtk_tree_store_set1 (parent.modelHandle, cast(GtkTreeIter*)handle, Tree.CHECKED_COLUMN, cast(void*)cast(int)checked); |
1282 /* | |
1283 * GTK+'s "inconsistent" state does not match DWT's concept of grayed. To | |
1284 * show checked+grayed differently from unchecked+grayed, we must toggle the | |
1285 * grayed state on check and uncheck. | |
1286 */ | |
1287 OS.gtk_tree_store_set1 (parent.modelHandle, cast(GtkTreeIter*)handle, Tree.GRAYED_COLUMN, cast(void*)cast(int)( !checked ? false : grayed)); | |
1288 cached = true; | |
1289 } | |
1290 | |
1291 /** | |
1292 * Sets the expanded state of the receiver. | |
1293 * <p> | |
1294 * | |
1295 * @param expanded the new expanded state | |
1296 * | |
1297 * @exception DWTException <ul> | |
1298 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1299 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1300 * </ul> | |
1301 */ | |
1302 public void setExpanded (bool expanded) { | |
1303 checkWidget(); | |
1304 auto path = OS.gtk_tree_model_get_path (parent.modelHandle, handle); | |
1305 if (expanded) { | |
1306 OS.g_signal_handlers_block_matched (parent.handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udTEST_EXPAND_ROW); | |
1307 OS.gtk_tree_view_expand_row (parent.handle, path, false); | |
1308 OS.g_signal_handlers_unblock_matched (parent.handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udTEST_EXPAND_ROW); | |
1309 } else { | |
1310 OS.g_signal_handlers_block_matched (parent.handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udTEST_COLLAPSE_ROW); | |
1311 OS.gtk_widget_realize (parent.handle); | |
1312 OS.gtk_tree_view_collapse_row (parent.handle, path); | |
1313 OS.g_signal_handlers_unblock_matched (parent.handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udTEST_COLLAPSE_ROW); | |
1314 } | |
1315 OS.gtk_tree_path_free (path); | |
1316 cached = true; | |
1317 } | |
1318 | |
1319 | |
1320 /** | |
1321 * Sets the font that the receiver will use to paint textual information | |
1322 * for this item to the font specified by the argument, or to the default font | |
1323 * for that kind of control if the argument is null. | |
1324 * | |
1325 * @param font the new font (or null) | |
1326 * | |
1327 * @exception IllegalArgumentException <ul> | |
1328 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> | |
1329 * </ul> | |
1330 * @exception DWTException <ul> | |
1331 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1332 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1333 * </ul> | |
1334 * | |
1335 * @since 3.0 | |
1336 */ | |
1337 public void setFont (Font font){ | |
1338 checkWidget (); | |
1339 if (font !is null && font.isDisposed ()) { | |
1340 DWT.error (DWT.ERROR_INVALID_ARGUMENT); | |
1341 } | |
240 | 1342 Font oldFont = this.font; |
1343 if (oldFont is font) return; | |
90 | 1344 this.font = font; |
240 | 1345 if (oldFont !is null && oldFont.opEquals (font)) return; |
1346 void* fontHandle = font !is null ? font.handle : null; | |
90 | 1347 OS.gtk_tree_store_set1 (parent.modelHandle, cast(GtkTreeIter*)handle, Tree.FONT_COLUMN, fontHandle); |
1348 /* | |
1349 * Bug in GTK. When using fixed-height-mode, | |
1350 * row changes do not cause the row to be repainted. The fix is to | |
1351 * invalidate the row when it is cleared. | |
1352 */ | |
1353 if ((parent.style & DWT.VIRTUAL) !is 0) { | |
1354 if (OS.GTK_VERSION >= OS.buildVERSION (2, 3, 2) && OS.GTK_VERSION < OS.buildVERSION (2, 6, 3)) { | |
1355 redraw (); | |
1356 } | |
1357 } | |
1358 cached = true; | |
1359 } | |
1360 | |
1361 /** | |
1362 * Sets the font that the receiver will use to paint textual information | |
1363 * for the specified cell in this item to the font specified by the | |
1364 * argument, or to the default font for that kind of control if the | |
1365 * argument is null. | |
1366 * | |
1367 * @param index the column index | |
1368 * @param font the new font (or null) | |
1369 * | |
1370 * @exception IllegalArgumentException <ul> | |
1371 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> | |
1372 * </ul> | |
1373 * @exception DWTException <ul> | |
1374 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1375 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1376 * </ul> | |
1377 * | |
1378 * @since 3.1 | |
1379 */ | |
1380 public void setFont (int index, Font font) { | |
1381 checkWidget (); | |
1382 if (font !is null && font.isDisposed ()) { | |
1383 DWT.error (DWT.ERROR_INVALID_ARGUMENT); | |
1384 } | |
1385 int count = Math.max (1, parent.getColumnCount ()); | |
1386 if (0 > index || index > count - 1) return; | |
1387 if (cellFont is null) { | |
240 | 1388 if (font is null) return; |
90 | 1389 cellFont = new Font [count]; |
1390 } | |
240 | 1391 Font oldFont = cellFont [index]; |
1392 if (oldFont is font) return; | |
90 | 1393 cellFont [index] = font; |
240 | 1394 if (oldFont !is null && oldFont.opEquals (font)) return; |
90 | 1395 |
1396 int modelIndex = parent.columnCount is 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; | |
1397 auto fontHandle = font !is null ? font.handle : null; | |
1398 OS.gtk_tree_store_set1 (parent.modelHandle, cast(GtkTreeIter*)handle, modelIndex + Tree.CELL_FONT, fontHandle); | |
1399 /* | |
1400 * Bug in GTK. When using fixed-height-mode, | |
1401 * row changes do not cause the row to be repainted. The fix is to | |
1402 * invalidate the row when it is cleared. | |
1403 */ | |
1404 if ((parent.style & DWT.VIRTUAL) !is 0) { | |
1405 if (OS.GTK_VERSION >= OS.buildVERSION (2, 3, 2) && OS.GTK_VERSION < OS.buildVERSION (2, 6, 3)) { | |
1406 redraw (); | |
1407 } | |
1408 } | |
1409 cached = true; | |
1410 | |
1411 if (font !is null) { | |
1412 bool customDraw = (parent.columnCount is 0) ? parent.firstCustomDraw : parent.columns [index].customDraw; | |
1413 if (!customDraw) { | |
1414 if ((parent.style & DWT.VIRTUAL) is 0) { | |
1415 auto parentHandle = parent.handle; | |
1416 GtkTreeViewColumn* column; | |
1417 if (parent.columnCount > 0) { | |
1418 column = cast(GtkTreeViewColumn*)parent.columns [index].handle; | |
1419 } else { | |
1420 column = OS.gtk_tree_view_get_column (parentHandle, index); | |
1421 } | |
1422 if (column is null) return; | |
1423 auto textRenderer = parent.getTextRenderer (column); | |
1424 auto imageRenderer = parent.getPixbufRenderer (column); | |
1425 display.doCellDataProc( parentHandle, cast(GtkTreeViewColumn*)column, cast(GtkCellRenderer*)textRenderer ); | |
1426 display.doCellDataProc( parentHandle, cast(GtkTreeViewColumn*)column, cast(GtkCellRenderer*)imageRenderer ); | |
1427 } | |
1428 if (parent.columnCount is 0) { | |
1429 parent.firstCustomDraw = true; | |
1430 } else { | |
1431 parent.columns [index].customDraw = true; | |
1432 } | |
1433 } | |
1434 } | |
1435 } | |
1436 | |
1437 /** | |
1438 * Sets the receiver's foreground color to the color specified | |
1439 * by the argument, or to the default system color for the item | |
1440 * if the argument is null. | |
1441 * | |
1442 * @param color the new color (or null) | |
1443 * | |
1444 * @since 2.0 | |
1445 * | |
1446 * @exception IllegalArgumentException <ul> | |
1447 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> | |
1448 * </ul> | |
1449 * @exception DWTException <ul> | |
1450 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1451 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1452 * </ul> | |
1453 * | |
1454 * @since 2.0 | |
1455 * | |
1456 */ | |
1457 public void setForeground (Color color){ | |
1458 checkWidget (); | |
1459 if (color !is null && color.isDisposed ()) { | |
1460 DWT.error (DWT.ERROR_INVALID_ARGUMENT); | |
1461 } | |
240 | 1462 if (_getForeground ().opEquals (color)) return; |
90 | 1463 GdkColor *gdkColor = color !is null ? color.handle : null; |
1464 OS.gtk_tree_store_set1 (parent.modelHandle, cast(GtkTreeIter*)handle, Tree.FOREGROUND_COLUMN, gdkColor); | |
1465 /* | |
1466 * Bug in GTK. When using fixed-height-mode, | |
1467 * row changes do not cause the row to be repainted. The fix is to | |
1468 * invalidate the row when it is cleared. | |
1469 */ | |
1470 if ((parent.style & DWT.VIRTUAL) !is 0) { | |
1471 if (OS.GTK_VERSION >= OS.buildVERSION (2, 3, 2) && OS.GTK_VERSION < OS.buildVERSION (2, 6, 3)) { | |
1472 redraw (); | |
1473 } | |
1474 } | |
1475 cached = true; | |
1476 } | |
1477 | |
1478 /** | |
1479 * Sets the foreground color at the given column index in the receiver | |
1480 * to the color specified by the argument, or to the default system color for the item | |
1481 * if the argument is null. | |
1482 * | |
1483 * @param index the column index | |
1484 * @param color the new color (or null) | |
1485 * | |
1486 * @exception IllegalArgumentException <ul> | |
1487 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> | |
1488 * </ul> | |
1489 * @exception DWTException <ul> | |
1490 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1491 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1492 * </ul> | |
1493 * | |
1494 * @since 3.1 | |
1495 * | |
1496 */ | |
1497 public void setForeground (int index, Color color){ | |
1498 checkWidget (); | |
1499 if (color !is null && color.isDisposed ()) { | |
1500 DWT.error (DWT.ERROR_INVALID_ARGUMENT); | |
1501 } | |
240 | 1502 if (_getForeground (index).opEquals (color)) return; |
90 | 1503 int count = Math.max (1, parent.getColumnCount ()); |
1504 if (0 > index || index > count - 1) return; | |
1505 int modelIndex = parent.columnCount is 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; | |
1506 GdkColor *gdkColor = color !is null ? color.handle : null; | |
1507 OS.gtk_tree_store_set1 (parent.modelHandle, cast(GtkTreeIter*)handle, modelIndex + Tree.CELL_FOREGROUND, gdkColor); | |
1508 /* | |
1509 * Bug in GTK. When using fixed-height-mode, | |
1510 * row changes do not cause the row to be repainted. The fix is to | |
1511 * invalidate the row when it is cleared. | |
1512 */ | |
1513 if ((parent.style & DWT.VIRTUAL) !is 0) { | |
1514 if (OS.GTK_VERSION >= OS.buildVERSION (2, 3, 2) && OS.GTK_VERSION < OS.buildVERSION (2, 6, 3)) { | |
1515 redraw (); | |
1516 } | |
1517 } | |
1518 cached = true; | |
1519 | |
1520 if (color !is null) { | |
1521 bool customDraw = (parent.columnCount is 0) ? parent.firstCustomDraw : parent.columns [index].customDraw; | |
1522 if (!customDraw) { | |
1523 if ((parent.style & DWT.VIRTUAL) is 0) { | |
1524 auto parentHandle = parent.handle; | |
1525 GtkTreeViewColumn* column; | |
1526 if (parent.columnCount > 0) { | |
1527 column = cast(GtkTreeViewColumn*)parent.columns [index].handle; | |
1528 } else { | |
1529 column = OS.gtk_tree_view_get_column (parentHandle, index); | |
1530 } | |
1531 if (column is null) return; | |
1532 auto textRenderer = parent.getTextRenderer (column); | |
1533 auto imageRenderer = parent.getPixbufRenderer (column); | |
1534 display.doCellDataProc( parentHandle, cast(GtkTreeViewColumn*)column, cast(GtkCellRenderer*)textRenderer ); | |
1535 display.doCellDataProc( parentHandle, cast(GtkTreeViewColumn*)column, cast(GtkCellRenderer*)imageRenderer ); | |
1536 } | |
1537 if (parent.columnCount is 0) { | |
1538 parent.firstCustomDraw = true; | |
1539 } else { | |
1540 parent.columns [index].customDraw = true; | |
1541 } | |
1542 } | |
1543 } | |
1544 } | |
1545 | |
1546 /** | |
1547 * Sets the grayed state of the checkbox for this item. This state change | |
1548 * only applies if the Tree was created with the DWT.CHECK style. | |
1549 * | |
1550 * @param grayed the new grayed state of the checkbox | |
1551 * | |
1552 * @exception DWTException <ul> | |
1553 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1554 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1555 * </ul> | |
1556 */ | |
1557 public void setGrayed (bool grayed) { | |
1558 checkWidget(); | |
1559 if ((parent.style & DWT.CHECK) is 0) return; | |
240 | 1560 if (this.grayed is grayed) return; |
90 | 1561 this.grayed = grayed; |
1562 /* | |
1563 * GTK+'s "inconsistent" state does not match DWT's concept of grayed. | |
1564 * Render checked+grayed as "inconsistent", unchecked+grayed as blank. | |
1565 */ | |
1566 void* ptr; | |
1567 OS.gtk_tree_model_get1 (parent.modelHandle, handle, Tree.CHECKED_COLUMN, &ptr); | |
1568 OS.gtk_tree_store_set1 (parent.modelHandle, cast(GtkTreeIter*)handle, Tree.GRAYED_COLUMN, cast(void*)cast(int)( ptr is null ? false : grayed)); | |
1569 cached = true; | |
1570 } | |
1571 | |
1572 /** | |
1573 * Sets the receiver's image at a column. | |
1574 * | |
1575 * @param index the column index | |
1576 * @param image the new image | |
1577 * | |
1578 * @exception IllegalArgumentException <ul> | |
1579 * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> | |
1580 * </ul> | |
1581 * @exception DWTException <ul> | |
1582 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1583 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1584 * </ul> | |
1585 * | |
1586 * @since 3.1 | |
1587 */ | |
1588 public void setImage (int index, Image image) { | |
1589 checkWidget (); | |
1590 if (image !is null && image.isDisposed()) { | |
1591 error(DWT.ERROR_INVALID_ARGUMENT); | |
1592 } | |
240 | 1593 if (image !is null && image.type is DWT.ICON) { |
1594 if (image.opEquals (_getImage (index))) return; | |
1595 } | |
90 | 1596 int count = Math.max (1, parent.getColumnCount ()); |
1597 if (0 > index || index > count - 1) return; | |
1598 GdkPixbuf* pixbuf; | |
1599 if (image !is null) { | |
1600 ImageList imageList = parent.imageList; | |
1601 if (imageList is null) imageList = parent.imageList = new ImageList (); | |
1602 int imageIndex = imageList.indexOf (image); | |
1603 if (imageIndex is -1) imageIndex = imageList.add (image); | |
1604 pixbuf = imageList.getPixbuf (imageIndex); | |
1605 } | |
1606 int modelIndex = parent.columnCount is 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; | |
1607 OS.gtk_tree_store_set1 (parent.modelHandle, cast(GtkTreeIter*)handle, modelIndex + Tree.CELL_PIXBUF, pixbuf); | |
1608 /* | |
1609 * Bug in GTK. When using fixed-height-mode, | |
1610 * row changes do not cause the row to be repainted. The fix is to | |
1611 * invalidate the row when the image changes. | |
1612 */ | |
1613 if ((parent.style & DWT.VIRTUAL) !is 0) { | |
1614 if (OS.GTK_VERSION >= OS.buildVERSION (2, 3, 2) && OS.GTK_VERSION < OS.buildVERSION (2, 6, 3)) { | |
1615 if (parent.columnCount is 0) { | |
1616 redraw (); | |
1617 } | |
1618 } | |
1619 } | |
1620 /* | |
1621 * Bug in GTK. When using fixed-height-mode, GTK does not recalculate the cell renderer width | |
1622 * when the image is changed in the model. The fix is to force it to recalculate the width if | |
1623 * more space is required. | |
1624 */ | |
1625 if ((parent.style & DWT.VIRTUAL) !is 0 && parent.currentItem is null) { | |
1626 if (OS.GTK_VERSION >= OS.buildVERSION (2, 3, 2)) { | |
1627 if (image !is null) { | |
1628 auto parentHandle = parent.handle; | |
1629 auto column = OS.gtk_tree_view_get_column (parentHandle, index); | |
1630 int w; | |
1631 auto pixbufRenderer = parent.getPixbufRenderer(column); | |
1632 OS.gtk_tree_view_column_cell_get_position (column, pixbufRenderer, null, &w); | |
1633 if (w < image.getBounds().width) { | |
1634 /* | |
1635 * There is no direct way to clear the cell renderer width so we | |
1636 * are relying on the fact that it is done as part of modifying | |
1637 * the style. | |
1638 */ | |
1639 auto style = OS.gtk_widget_get_modifier_style (parentHandle); | |
240 | 1640 parent.modifyStyle (parentHandle, style); |
90 | 1641 } |
1642 } | |
1643 } | |
1644 } | |
1645 cached = true; | |
1646 } | |
1647 | |
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
1648 public override void setImage (Image image) { |
90 | 1649 checkWidget (); |
1650 setImage (0, image); | |
1651 } | |
1652 | |
1653 /** | |
1654 * Sets the image for multiple columns in the tree. | |
1655 * | |
1656 * @param images the array of new images | |
1657 * | |
1658 * @exception IllegalArgumentException <ul> | |
1659 * <li>ERROR_INVALID_ARGUMENT - if one of the images has been disposed</li> | |
1660 * </ul> | |
1661 * @exception DWTException <ul> | |
1662 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1663 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1664 * </ul> | |
1665 * | |
1666 * @since 3.1 | |
1667 */ | |
1668 public void setImage (Image [] images) { | |
1669 checkWidget (); | |
255
5a30aa9820f3
removed tango.stdc.stringz imports and allow null for arrays and string arguments.
Frank Benoit <benoit@tionex.de>
parents:
240
diff
changeset
|
1670 // DWT extension: allow null for zero length string |
5a30aa9820f3
removed tango.stdc.stringz imports and allow null for arrays and string arguments.
Frank Benoit <benoit@tionex.de>
parents:
240
diff
changeset
|
1671 //if (images is null) error (DWT.ERROR_NULL_ARGUMENT); |
90 | 1672 for (int i=0; i<images.length; i++) { |
1673 setImage (i, images [i]); | |
1674 } | |
1675 } | |
1676 | |
1677 /** | |
1678 * Sets the number of child items contained in the receiver. | |
1679 * | |
1680 * @param count the number of items | |
1681 * | |
1682 * @exception DWTException <ul> | |
1683 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1684 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1685 * </ul> | |
1686 * | |
1687 * @since 3.2 | |
1688 */ | |
1689 public void setItemCount (int count) { | |
1690 checkWidget (); | |
1691 count = Math.max (0, count); | |
1692 parent.setItemCount (cast(GtkTreeIter*)handle, count); | |
1693 } | |
1694 | |
1695 /** | |
1696 * Sets the receiver's text at a column | |
1697 * | |
1698 * @param index the column index | |
1699 * @param string the new text | |
1700 * | |
1701 * @exception DWTException <ul> | |
1702 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1703 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1704 * </ul> | |
1705 * | |
1706 * @since 3.1 | |
1707 */ | |
238 | 1708 public void setText (int index, String string) { |
90 | 1709 checkWidget (); |
255
5a30aa9820f3
removed tango.stdc.stringz imports and allow null for arrays and string arguments.
Frank Benoit <benoit@tionex.de>
parents:
240
diff
changeset
|
1710 // DWT extension: allow null for zero length string |
5a30aa9820f3
removed tango.stdc.stringz imports and allow null for arrays and string arguments.
Frank Benoit <benoit@tionex.de>
parents:
240
diff
changeset
|
1711 //if (string is null) error (DWT.ERROR_NULL_ARGUMENT); |
240 | 1712 if (_getText (index).equals (string)) return; |
90 | 1713 int count = Math.max (1, parent.getColumnCount ()); |
1714 if (0 > index || index > count - 1) return; | |
255
5a30aa9820f3
removed tango.stdc.stringz imports and allow null for arrays and string arguments.
Frank Benoit <benoit@tionex.de>
parents:
240
diff
changeset
|
1715 char* buffer = toStringz(string); |
90 | 1716 int modelIndex = parent.columnCount is 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; |
1717 OS.gtk_tree_store_set1 (parent.modelHandle, cast(GtkTreeIter*)handle, modelIndex + Tree.CELL_TEXT, buffer); | |
1718 /* | |
1719 * Bug in GTK. When using fixed-height-mode, | |
1720 * row changes do not cause the row to be repainted. The fix is to | |
1721 * invalidate the row when the text changes. | |
1722 */ | |
1723 if ((parent.style & DWT.VIRTUAL) !is 0) { | |
1724 if (OS.GTK_VERSION >= OS.buildVERSION (2, 3, 2) && OS.GTK_VERSION < OS.buildVERSION (2, 6, 3)) { | |
1725 redraw (); | |
1726 } | |
1727 } | |
1728 cached = true; | |
1729 } | |
1730 | |
238 | 1731 public override void setText (String string) { |
90 | 1732 checkWidget (); |
1733 setText (0, string); | |
1734 } | |
1735 | |
1736 /** | |
1737 * Sets the text for multiple columns in the tree. | |
1738 * | |
1739 * @param strings the array of new strings | |
1740 * | |
1741 * @exception DWTException <ul> | |
1742 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1743 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1744 * </ul> | |
1745 * | |
1746 * @since 3.1 | |
1747 */ | |
238 | 1748 public void setText (String [] strings) { |
90 | 1749 checkWidget (); |
255
5a30aa9820f3
removed tango.stdc.stringz imports and allow null for arrays and string arguments.
Frank Benoit <benoit@tionex.de>
parents:
240
diff
changeset
|
1750 // DWT extension: allow null for zero length string |
5a30aa9820f3
removed tango.stdc.stringz imports and allow null for arrays and string arguments.
Frank Benoit <benoit@tionex.de>
parents:
240
diff
changeset
|
1751 //if (strings is null) error (DWT.ERROR_NULL_ARGUMENT); |
90 | 1752 for (int i=0; i<strings.length; i++) { |
238 | 1753 String string = strings [i]; |
90 | 1754 if (string !is null) setText (i, string); |
1755 } | |
1756 } | |
1757 } |