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