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