Mercurial > projects > dwt-linux
annotate dwt/widgets/Tree.d @ 255:5a30aa9820f3
removed tango.stdc.stringz imports and allow null for arrays and string arguments.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 15 Jun 2008 22:32:20 +0200 |
parents | ce446666f5a2 |
children | c0d810de7093 |
rev | line source |
---|---|
115
52b32f5cb1e0
many file checked for switch default
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.Tree; | |
14 | |
15 | |
16 | |
17 import dwt.DWT; | |
18 import dwt.DWTException; | |
19 import dwt.events.SelectionEvent; | |
20 import dwt.events.SelectionListener; | |
21 import dwt.events.TreeListener; | |
22 import dwt.graphics.Color; | |
23 import dwt.graphics.Font; | |
24 import dwt.graphics.GC; | |
25 import dwt.graphics.Image; | |
26 import dwt.graphics.Point; | |
27 import dwt.graphics.Rectangle; | |
28 import dwt.internal.gtk.OS; | |
29 import dwt.widgets.TreeItem; | |
30 import dwt.widgets.TreeColumn; | |
31 import dwt.widgets.Composite; | |
32 import dwt.widgets.ImageList; | |
33 import dwt.widgets.Listener; | |
34 import dwt.widgets.Shell; | |
35 import dwt.widgets.Decorations; | |
36 import dwt.widgets.Menu; | |
37 import dwt.widgets.ScrollBar; | |
38 import dwt.widgets.Control; | |
39 import dwt.widgets.Display; | |
40 import dwt.widgets.Event; | |
41 import dwt.widgets.TypedListener; | |
200
08789b28bdf3
import dwt.dwthelper.utils now explicit
Frank Benoit <benoit@tionex.de>
parents:
152
diff
changeset
|
42 import dwt.dwthelper.utils; |
90 | 43 |
44 /** | |
45 * Instances of this class provide a selectable user interface object | |
46 * that displays a hierarchy of items and issues notification when an | |
47 * item in the hierarchy is selected. | |
48 * <p> | |
49 * The item children that may be added to instances of this class | |
50 * must be of type <code>TreeItem</code>. | |
51 * </p><p> | |
52 * Style <code>VIRTUAL</code> is used to create a <code>Tree</code> whose | |
53 * <code>TreeItem</code>s are to be populated by the client on an on-demand basis | |
54 * instead of up-front. This can provide significant performance improvements for | |
55 * trees that are very large or for which <code>TreeItem</code> population is | |
56 * expensive (for example, retrieving values from an external source). | |
57 * </p><p> | |
58 * Here is an example of using a <code>Tree</code> with style <code>VIRTUAL</code>: | |
59 * <code><pre> | |
60 * final Tree tree = new Tree(parent, DWT.VIRTUAL | DWT.BORDER); | |
61 * tree.setItemCount(20); | |
62 * tree.addListener(DWT.SetData, new Listener() { | |
63 * public void handleEvent(Event event) { | |
64 * TreeItem item = (TreeItem)event.item; | |
65 * TreeItem parentItem = item.getParentItem(); | |
66 * String text = null; | |
67 * if (parentItem is null) { | |
68 * text = "node " + tree.indexOf(item); | |
69 * } else { | |
70 * text = parentItem.getText() + " - " + parentItem.indexOf(item); | |
71 * } | |
72 * item.setText(text); | |
73 * System.out.println(text); | |
74 * item.setItemCount(10); | |
75 * } | |
76 * }); | |
77 * </pre></code> | |
78 * </p><p> | |
79 * Note that although this class is a subclass of <code>Composite</code>, | |
80 * it does not make sense to add <code>Control</code> children to it, | |
81 * or set a layout on it. | |
82 * </p><p> | |
83 * <dl> | |
84 * <dt><b>Styles:</b></dt> | |
85 * <dd>SINGLE, MULTI, CHECK, FULL_SELECTION, VIRTUAL</dd> | |
86 * <dt><b>Events:</b></dt> | |
87 * <dd>Selection, DefaultSelection, Collapse, Expand, SetData, MeasureItem, EraseItem, PaintItem</dd> | |
88 * </dl> | |
89 * </p><p> | |
90 * Note: Only one of the styles SINGLE and MULTI may be specified. | |
91 * </p><p> | |
92 * IMPORTANT: This class is <em>not</em> intended to be subclassed. | |
93 * </p> | |
94 */ | |
95 public class Tree : Composite { | |
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
115
diff
changeset
|
96 |
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
115
diff
changeset
|
97 alias Composite.computeSize computeSize; |
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
115
diff
changeset
|
98 alias Composite.createHandle createHandle; |
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
115
diff
changeset
|
99 alias Composite.dragDetect dragDetect; |
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
115
diff
changeset
|
100 alias Composite.mnemonicHit mnemonicHit; |
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
115
diff
changeset
|
101 alias Composite.mnemonicMatch mnemonicMatch; |
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
115
diff
changeset
|
102 alias Composite.setBackgroundColor setBackgroundColor; |
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
115
diff
changeset
|
103 alias Composite.setBounds setBounds; |
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
115
diff
changeset
|
104 |
90 | 105 CallbackData treeSelectionCallbackData; |
106 GtkTreeStore* modelHandle; | |
107 GtkCellRenderer* checkRenderer; | |
108 int columnCount, sortDirection; | |
109 GtkWidget* ignoreCell; | |
110 TreeItem[] items; | |
111 TreeColumn [] columns; | |
112 TreeColumn sortColumn; | |
113 TreeItem currentItem; | |
114 ImageList imageList, headerImageList; | |
115 bool firstCustomDraw; | |
116 bool modelChanged; | |
117 bool expandAll; | |
118 int drawState, drawFlags; | |
119 GdkColor* drawForeground; | |
120 bool ownerDraw, ignoreSize; | |
121 | |
122 static const int ID_COLUMN = 0; | |
123 static const int CHECKED_COLUMN = 1; | |
124 static const int GRAYED_COLUMN = 2; | |
125 static const int FOREGROUND_COLUMN = 3; | |
126 static const int BACKGROUND_COLUMN = 4; | |
127 static const int FONT_COLUMN = 5; | |
128 static const int FIRST_COLUMN = FONT_COLUMN + 1; | |
129 static const int CELL_PIXBUF = 0; | |
130 static const int CELL_TEXT = 1; | |
131 static const int CELL_FOREGROUND = 2; | |
132 static const int CELL_BACKGROUND = 3; | |
133 static const int CELL_FONT = 4; | |
134 static const int CELL_TYPES = CELL_FONT + 1; | |
135 | |
136 /** | |
137 * Constructs a new instance of this class given its parent | |
138 * and a style value describing its behavior and appearance. | |
139 * <p> | |
140 * The style value is either one of the style constants defined in | |
141 * class <code>DWT</code> which is applicable to instances of this | |
142 * class, or must be built by <em>bitwise OR</em>'ing together | |
143 * (that is, using the <code>int</code> "|" operator) two or more | |
144 * of those <code>DWT</code> style constants. The class description | |
145 * lists the style constants that are applicable to the class. | |
146 * Style bits are also inherited from superclasses. | |
147 * </p> | |
148 * | |
149 * @param parent a composite control which will be the parent of the new instance (cannot be null) | |
150 * @param style the style of control to construct | |
151 * | |
152 * @exception IllegalArgumentException <ul> | |
153 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
154 * </ul> | |
155 * @exception DWTException <ul> | |
156 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
157 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
158 * </ul> | |
159 * | |
160 * @see DWT#SINGLE | |
161 * @see DWT#MULTI | |
162 * @see DWT#CHECK | |
163 * @see Widget#checkSubclass | |
164 * @see Widget#getStyle | |
165 */ | |
166 public this (Composite parent, int style) { | |
167 super (parent, checkStyle (style)); | |
168 } | |
169 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
170 override void _addListener (int eventType, Listener listener) { |
90 | 171 super._addListener (eventType, listener); |
172 if (!ownerDraw) { | |
173 switch (eventType) { | |
174 case DWT.MeasureItem: | |
175 case DWT.EraseItem: | |
176 case DWT.PaintItem: | |
177 ownerDraw = true; | |
178 recreateRenderers (); | |
179 break; | |
115
52b32f5cb1e0
many file checked for switch default
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
180 default: |
90 | 181 } |
182 } | |
183 } | |
184 | |
185 TreeItem _getItem (GtkTreeIter* iter) { | |
186 int id = getId (iter, true); | |
187 if (items [id] !is null) return items [id]; | |
188 auto path = OS.gtk_tree_model_get_path (modelHandle, iter); | |
189 int depth = OS.gtk_tree_path_get_depth (path); | |
190 int [] indices = new int [depth]; | |
191 indices[] = OS.gtk_tree_path_get_indices (path)[ 0 .. depth ]; | |
192 GtkTreeIter parentIter; | |
193 if (depth > 1) { | |
194 OS.gtk_tree_path_up (path); | |
195 OS.gtk_tree_model_get_iter (modelHandle, &parentIter, path); | |
196 } | |
197 items [id] = new TreeItem (this, &parentIter, DWT.NONE, indices [indices.length -1], false); | |
198 OS.gtk_tree_path_free (path); | |
199 return items [id]; | |
200 } | |
201 | |
202 TreeItem _getItem (GtkTreeIter* parentIter, int index) { | |
203 GtkTreeIter iter; | |
204 OS.gtk_tree_model_iter_nth_child(modelHandle, &iter, parentIter, index); | |
205 int id = getId (&iter, true); | |
206 if (items [id] !is null) return items [id]; | |
207 return items [id] = new TreeItem (this, parentIter, DWT.NONE, index, false); | |
208 } | |
209 | |
210 int getId (GtkTreeIter* iter, bool queryModel) { | |
211 if (queryModel) { | |
212 int value; | |
213 OS.gtk_tree_model_get1 (modelHandle, iter, ID_COLUMN, cast(void**)&value); | |
214 if (value !is -1) return value ; | |
215 } | |
216 // find next available id | |
217 int id = 0; | |
218 while (id < items.length && items [id] !is null) id++; | |
219 if (id is items.length) { | |
220 TreeItem [] newItems = new TreeItem [items.length + 4]; | |
221 System.arraycopy (items, 0, newItems, 0, items.length); | |
222 items = newItems; | |
223 } | |
224 OS.gtk_tree_store_set1 (modelHandle, iter, ID_COLUMN, cast(void*)id ); | |
225 return id; | |
226 } | |
227 | |
228 static int checkStyle (int style) { | |
229 /* | |
240 | 230 * Feature in Windows. Even when WS_HSCROLL or |
231 * WS_VSCROLL is not specified, Windows creates | |
232 * trees and tables with scroll bars. The fix | |
233 * is to set H_SCROLL and V_SCROLL. | |
234 * | |
235 * NOTE: This code appears on all platforms so that | |
236 * applications have consistent scroll bar behavior. | |
90 | 237 */ |
240 | 238 if ((style & DWT.NO_SCROLL) is 0) { |
239 style |= DWT.H_SCROLL | DWT.V_SCROLL; | |
240 } | |
90 | 241 /* GTK is always FULL_SELECTION */ |
242 style |= DWT.FULL_SELECTION; | |
243 return checkBits (style, DWT.SINGLE, DWT.MULTI, 0, 0, 0, 0); | |
244 } | |
245 | |
246 override void cellDataProc ( | |
247 GtkTreeViewColumn *tree_column, | |
248 GtkCellRenderer *cell, | |
249 GtkTreeModel *tree_model, | |
250 GtkTreeIter *iter, | |
251 void* data) | |
252 { | |
253 if (cell is cast(GtkCellRenderer*)ignoreCell) return; | |
254 TreeItem item = _getItem (iter); | |
255 if (item !is null) OS.g_object_set_qdata (cast(GObject*)cell, Display.SWT_OBJECT_INDEX2, item.handle); | |
256 bool isPixbuf = OS.GTK_IS_CELL_RENDERER_PIXBUF (cell); | |
257 if (!(isPixbuf || OS.GTK_IS_CELL_RENDERER_TEXT (cell))) return; | |
258 int modelIndex = -1; | |
259 bool customDraw = false; | |
260 if (columnCount is 0) { | |
261 modelIndex = Tree.FIRST_COLUMN; | |
262 customDraw = firstCustomDraw; | |
263 } else { | |
264 TreeColumn* column = cast(TreeColumn*) display.getWidget (cast(GtkWidget*)tree_column); | |
265 if (column !is null) { | |
266 modelIndex = column.modelIndex; | |
267 customDraw = column.customDraw; | |
268 } | |
269 } | |
270 if (modelIndex is -1) return 0; | |
271 bool setData = false; | |
272 if ((style & DWT.VIRTUAL) !is 0) { | |
273 /* | |
274 * Feature in GTK. On GTK before 2.4, fixed_height_mode is not | |
275 * supported, and the tree asks for the data of all items. The | |
276 * fix is to only provide the data if the row is visible. | |
277 */ | |
278 if (OS.GTK_VERSION < OS.buildVERSION (2, 3, 2)) { | |
279 auto path = OS.gtk_tree_model_get_path (tree_model, iter); | |
280 OS.gtk_widget_realize (handle); | |
281 GdkRectangle visible; | |
282 OS.gtk_tree_view_get_visible_rect (handle, &visible); | |
283 GdkRectangle area; | |
284 OS.gtk_tree_view_get_cell_area (handle, path, tree_column, &area); | |
285 OS.gtk_tree_path_free (path); | |
286 if (area.y + area.height < 0 || area.y + visible.y > visible.y + visible.height ) { | |
287 /* Give an image from the image list to make sure the row has | |
288 * the correct height. | |
289 */ | |
290 if (imageList !is null && imageList.pixbufs.length > 0) { | |
291 if (isPixbuf) OS.g_object_set1 (cell, OS.pixbuf.ptr, cast(int)imageList.pixbufs [0]); | |
292 } | |
293 return 0; | |
294 } | |
295 } | |
296 if (!item.cached) { | |
297 //lastIndexOf = index [0]; | |
298 setData = checkData (item); | |
299 } | |
300 } | |
301 void* ptr; | |
302 if (setData) { | |
303 if (isPixbuf) { | |
304 ptr = null; | |
305 OS.gtk_tree_model_get1 (tree_model, iter, modelIndex + CELL_PIXBUF, &ptr); | |
306 OS.g_object_set1 (cell, OS.pixbuf.ptr, cast(int)ptr); | |
307 } else { | |
308 ptr = null; | |
309 OS.gtk_tree_model_get1 (tree_model, iter, modelIndex + CELL_TEXT, &ptr); | |
310 if (ptr !is null) { | |
311 OS.g_object_set1 (cell, OS.text.ptr, cast(int)ptr); | |
312 OS.g_free (ptr); | |
313 } | |
314 } | |
315 } | |
316 if (customDraw) { | |
317 /* | |
318 * Bug on GTK. Gtk renders the background on top of the checkbox and pixbuf. | |
319 * This only happens in version 2.2.1 and earlier. The fix is not to set the background. | |
320 */ | |
321 if (OS.GTK_VERSION > OS.buildVERSION (2, 2, 1)) { | |
322 if (!ownerDraw) { | |
323 ptr = null; | |
324 OS.gtk_tree_model_get1 (tree_model, iter, modelIndex + CELL_BACKGROUND, &ptr); | |
325 if (ptr !is null) { | |
326 OS.g_object_set1 (cell, OS.cell_background_gdk.ptr, cast(int)ptr); | |
327 } | |
328 } | |
329 } | |
330 if (!isPixbuf) { | |
331 ptr = null; | |
332 OS.gtk_tree_model_get1 (tree_model, iter, modelIndex + CELL_FOREGROUND, &ptr); | |
333 if (ptr !is null) { | |
334 OS.g_object_set1 (cell, OS.foreground_gdk.ptr, cast(int)ptr); | |
335 } | |
336 ptr = null; | |
337 OS.gtk_tree_model_get1 (tree_model, iter, modelIndex + CELL_FONT, &ptr); | |
338 if (ptr !is null) { | |
339 OS.g_object_set1 (cell, OS.font_desc.ptr, cast(int)ptr); | |
340 } | |
341 } | |
342 } | |
343 if (setData) { | |
344 ignoreCell = cast(GtkWidget*)cell; | |
345 setScrollWidth (tree_column, item); | |
346 ignoreCell = null; | |
347 } | |
348 } | |
349 | |
350 bool checkData (TreeItem item) { | |
351 if (item.cached) return true; | |
352 if ((style & DWT.VIRTUAL) !is 0) { | |
353 item.cached = true; | |
354 TreeItem parentItem = item.getParentItem (); | |
355 Event event = new Event (); | |
356 event.item = item; | |
357 event.index = parentItem is null ? indexOf (item) : parentItem.indexOf (item); | |
358 int mask = OS.G_SIGNAL_MATCH_DATA | OS.G_SIGNAL_MATCH_ID; | |
359 int signal_id = OS.g_signal_lookup (OS.row_changed.ptr, OS.gtk_tree_model_get_type ()); | |
360 OS.g_signal_handlers_block_matched (modelHandle, mask, signal_id, 0, null, null, handle); | |
361 currentItem = item; | |
362 sendEvent (DWT.SetData, event); | |
363 currentItem = null; | |
364 //widget could be disposed at this point | |
365 if (isDisposed ()) return false; | |
366 OS.g_signal_handlers_unblock_matched (modelHandle, mask, signal_id, 0, null, null, handle); | |
367 if (item.isDisposed ()) return false; | |
368 } | |
369 return true; | |
370 } | |
371 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
372 protected override void checkSubclass () { |
90 | 373 if (!isValidSubclass ()) error (DWT.ERROR_INVALID_SUBCLASS); |
374 } | |
375 | |
376 /** | |
377 * Adds the listener to the collection of listeners who will | |
378 * be notified when the user changes the receiver's selection, by sending | |
379 * it one of the messages defined in the <code>SelectionListener</code> | |
380 * interface. | |
381 * <p> | |
382 * When <code>widgetSelected</code> is called, the item field of the event object is valid. | |
383 * If the receiver has the <code>DWT.CHECK</code> style and the check selection changes, | |
384 * the event object detail field contains the value <code>DWT.CHECK</code>. | |
385 * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked. | |
386 * The item field of the event object is valid for default selection, but the detail field is not used. | |
387 * </p> | |
388 * | |
389 * @param listener the listener which should be notified when the user changes the receiver's selection | |
390 * | |
391 * @exception IllegalArgumentException <ul> | |
392 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
393 * </ul> | |
394 * @exception DWTException <ul> | |
395 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
396 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
397 * </ul> | |
398 * | |
399 * @see SelectionListener | |
400 * @see #removeSelectionListener | |
401 * @see SelectionEvent | |
402 */ | |
403 public void addSelectionListener (SelectionListener listener) { | |
404 checkWidget (); | |
405 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT); | |
406 TypedListener typedListener = new TypedListener (listener); | |
407 addListener (DWT.Selection, typedListener); | |
408 addListener (DWT.DefaultSelection, typedListener); | |
409 } | |
410 | |
411 /** | |
412 * Adds the listener to the collection of listeners who will | |
413 * be notified when an item in the receiver is expanded or collapsed | |
414 * by sending it one of the messages defined in the <code>TreeListener</code> | |
415 * interface. | |
416 * | |
417 * @param listener the listener which should be notified | |
418 * | |
419 * @exception IllegalArgumentException <ul> | |
420 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
421 * </ul> | |
422 * @exception DWTException <ul> | |
423 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
424 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
425 * </ul> | |
426 * | |
427 * @see TreeListener | |
428 * @see #removeTreeListener | |
429 */ | |
430 public void addTreeListener(TreeListener listener) { | |
431 checkWidget (); | |
432 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT); | |
433 TypedListener typedListener = new TypedListener (listener); | |
434 addListener (DWT.Expand, typedListener); | |
435 addListener (DWT.Collapse, typedListener); | |
436 } | |
437 | |
240 | 438 int calculateWidth (GtkTreeViewColumn *column, GtkTreeIter* iter, bool recurse) { |
90 | 439 OS.gtk_tree_view_column_cell_set_cell_data (column, modelHandle, iter, false, false); |
440 /* | |
441 * Bug in GTK. The width calculated by gtk_tree_view_column_cell_get_size() | |
442 * always grows in size regardless of the text or images in the table. | |
443 * The fix is to determine the column width from the cell renderers. | |
444 */ | |
445 // Code intentionally commented | |
446 //int [] width = new int [1]; | |
447 //OS.gtk_tree_view_column_cell_get_size (column, null, null, null, width, null); | |
448 //return width [0]; | |
449 | |
450 int width = 0; | |
451 int w; | |
240 | 452 GtkTreePath* path = null; |
453 | |
90 | 454 if (OS.gtk_tree_view_get_expander_column (handle) is column) { |
240 | 455 /* indent */ |
456 GdkRectangle rect; | |
457 OS.gtk_widget_realize (handle); | |
458 path = OS.gtk_tree_model_get_path (modelHandle, iter); | |
459 OS.gtk_tree_view_get_cell_area (handle, path, column, &rect); | |
460 width += rect.x; | |
461 /* expander */ | |
90 | 462 OS.gtk_widget_style_get1 (handle, OS.expander_size.ptr, &w); |
463 width += w + TreeItem.EXPANDER_EXTRA_PADDING; | |
464 } | |
465 OS.gtk_widget_style_get1(handle, OS.focus_line_width.ptr, &w); | |
466 width += 2 * w ; | |
467 auto list = OS.gtk_tree_view_column_get_cell_renderers (column); | |
468 if (list is null) return 0; | |
469 auto temp = list; | |
470 while (temp !is null) { | |
471 auto renderer = OS.g_list_data (temp); | |
472 if (renderer !is null) { | |
473 OS.gtk_cell_renderer_get_size (renderer, handle, null, null, null, &w, null); | |
474 width += w ; | |
475 } | |
476 temp = OS.g_list_next (temp); | |
477 } | |
478 OS.g_list_free (list); | |
240 | 479 |
480 if (recurse) { | |
481 if (path is null) path = OS.gtk_tree_model_get_path (modelHandle, iter); | |
482 bool expanded = OS.gtk_tree_view_row_expanded (handle, path) !is 0; | |
483 if (expanded) { | |
484 GtkTreeIter childIter; | |
485 bool valid = OS.gtk_tree_model_iter_children (modelHandle, &childIter, iter) !is 0; | |
486 while (valid) { | |
487 width = Math.max (width, calculateWidth (column, &childIter, true)); | |
488 valid = OS.gtk_tree_model_iter_next (modelHandle, &childIter) !is 0; | |
489 } | |
490 } | |
491 } | |
492 | |
493 if (path !is null) OS.gtk_tree_path_free (path); | |
90 | 494 return width; |
495 } | |
496 | |
497 /** | |
498 * Clears the item at the given zero-relative index in the receiver. | |
499 * The text, icon and other attributes of the item are set to the default | |
500 * value. If the tree was created with the <code>DWT.VIRTUAL</code> style, | |
501 * these attributes are requested again as needed. | |
502 * | |
503 * @param index the index of the item to clear | |
504 * @param all <code>true</code> if all child items of the indexed item should be | |
505 * cleared recursively, and <code>false</code> otherwise | |
506 * | |
507 * @exception IllegalArgumentException <ul> | |
508 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> | |
509 * </ul> | |
510 * @exception DWTException <ul> | |
511 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
512 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
513 * </ul> | |
514 * | |
515 * @see DWT#VIRTUAL | |
516 * @see DWT#SetData | |
517 * | |
518 * @since 3.2 | |
519 */ | |
520 public void clear(int index, bool all) { | |
521 checkWidget (); | |
522 clear (null, index, all); | |
523 } | |
524 | |
525 void clear (GtkTreeIter* parentIter, int index, bool all) { | |
526 GtkTreeIter iter; | |
527 OS.gtk_tree_model_iter_nth_child(modelHandle, &iter, parentIter, index); | |
528 int value; | |
529 OS.gtk_tree_model_get1 (modelHandle, &iter, ID_COLUMN, cast(void**)&value); | |
530 if (value !is -1) { | |
531 TreeItem item = items [value ]; | |
532 item.clear (); | |
533 } | |
534 if (all) clearAll (all, &iter); | |
535 } | |
536 | |
537 /** | |
538 * Clears all the items in the receiver. The text, icon and other | |
539 * attributes of the items are set to their default values. If the | |
540 * tree was created with the <code>DWT.VIRTUAL</code> style, these | |
541 * attributes are requested again as needed. | |
542 * | |
543 * @param all <code>true</code> if all child items should be cleared | |
544 * recursively, and <code>false</code> otherwise | |
545 * | |
546 * @exception DWTException <ul> | |
547 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
548 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
549 * </ul> | |
550 * | |
551 * @see DWT#VIRTUAL | |
552 * @see DWT#SetData | |
553 * | |
554 * @since 3.2 | |
555 */ | |
556 public void clearAll (bool all) { | |
557 checkWidget (); | |
558 clearAll (all, null); | |
559 } | |
560 void clearAll (bool all, GtkTreeIter* parentIter) { | |
561 int length = OS.gtk_tree_model_iter_n_children (modelHandle, parentIter); | |
562 if (length is 0) return; | |
563 GtkTreeIter iter; | |
564 bool valid = cast(bool)OS.gtk_tree_model_iter_children (modelHandle, &iter, parentIter); | |
565 int value; | |
566 while (valid) { | |
567 OS.gtk_tree_model_get1 (modelHandle, &iter, ID_COLUMN, cast(void**)&value); | |
568 if (value !is -1) { | |
569 TreeItem item = items [value ]; | |
570 item.clear (); | |
571 } | |
572 if (all) clearAll (all, &iter); | |
573 valid = cast(bool)OS.gtk_tree_model_iter_next (modelHandle, &iter); | |
574 } | |
575 } | |
576 | |
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
115
diff
changeset
|
577 public override Point computeSize (int wHint, int hHint, bool changed) { |
90 | 578 checkWidget (); |
579 if (wHint !is DWT.DEFAULT && wHint < 0) wHint = 0; | |
580 if (hHint !is DWT.DEFAULT && hHint < 0) hHint = 0; | |
581 Point size = computeNativeSize (handle, wHint, hHint, changed); | |
582 Rectangle trim = computeTrim (0, 0, size.x, size.y); | |
583 size.x = trim.width; | |
584 size.y = trim.height; | |
585 return size; | |
586 } | |
587 | |
588 void copyModel (void* oldModel, int oldStart, void* newModel, int newStart, uint [] types, void* oldParent, void* newParent, int modelLength) { | |
589 GtkTreeIter iter; | |
590 if (OS.gtk_tree_model_iter_children (oldModel, &iter, oldParent)) { | |
591 GtkTreeIter*[] oldItems = new GtkTreeIter*[]( OS.gtk_tree_model_iter_n_children (oldModel, oldParent)); | |
592 int oldIndex = 0; | |
593 do { | |
594 GtkTreeIter* newItem = cast(GtkTreeIter*)OS.g_malloc (GtkTreeIter.sizeof); | |
595 if (newItem is null) error (DWT.ERROR_NO_HANDLES); | |
596 OS.gtk_tree_store_append (newModel, newItem, newParent); | |
597 int index; | |
598 OS.gtk_tree_model_get1 (oldModel, &iter, ID_COLUMN, cast(void**)&index); | |
599 TreeItem item = null; | |
600 if (index !is -1) { | |
601 item = items [index ]; | |
602 if (item !is null) { | |
603 auto oldItem = cast(GtkTreeIter*)item.handle; | |
604 oldItems[oldIndex++] = oldItem; | |
605 void* ptr; | |
606 for (int j = 0; j < FIRST_COLUMN; j++) { | |
607 OS.gtk_tree_model_get1 (oldModel, oldItem, j, &ptr); | |
608 OS.gtk_tree_store_set1 (newModel, newItem, j, ptr ); | |
609 if (types [j] is OS.G_TYPE_STRING ()) OS.g_free ((ptr )); | |
610 } | |
611 for (int j= 0; j<modelLength - FIRST_COLUMN; j++) { | |
612 OS.gtk_tree_model_get1 (oldModel, oldItem, oldStart + j, &ptr); | |
613 OS.gtk_tree_store_set1 (newModel, newItem, newStart + j, ptr ); | |
614 if (types [j] is OS.G_TYPE_STRING ()) OS.g_free ((ptr )); | |
615 } | |
616 } | |
617 } else { | |
618 OS.gtk_tree_store_set1 (newModel, newItem, ID_COLUMN, cast(void*)-1 ); | |
619 } | |
620 // recurse through children | |
621 copyModel(oldModel, oldStart, newModel, newStart, types, &iter, newItem, modelLength); | |
622 | |
623 if (item!is null) { | |
624 item.handle = cast(GtkWidget*)newItem; | |
625 } else { | |
626 OS.g_free (newItem); | |
627 } | |
628 } while (OS.gtk_tree_model_iter_next(oldModel, &iter)); | |
629 for (int i = 0; i < oldItems.length; i++) { | |
630 auto oldItem = oldItems [i]; | |
631 if (oldItem !is null) { | |
632 OS.gtk_tree_store_remove (oldModel, oldItem); | |
633 OS.g_free (oldItem); | |
634 } | |
635 } | |
636 } | |
637 } | |
638 | |
639 void createColumn (TreeColumn column, int index) { | |
640 /* | |
641 * Bug in ATK. For some reason, ATK segments fault if | |
642 * the GtkTreeView has a column and does not have items. | |
643 * The fix is to insert the column only when an item is | |
644 * created. | |
645 */ | |
646 | |
647 int modelIndex = FIRST_COLUMN; | |
648 if (columnCount !is 0) { | |
649 int modelLength = OS.gtk_tree_model_get_n_columns (modelHandle); | |
650 bool [] usedColumns = new bool [modelLength]; | |
651 for (int i=0; i<columnCount; i++) { | |
652 int columnIndex = columns [i].modelIndex; | |
653 for (int j = 0; j < CELL_TYPES; j++) { | |
654 usedColumns [columnIndex + j] = true; | |
655 } | |
656 } | |
657 while (modelIndex < modelLength) { | |
658 if (!usedColumns [modelIndex]) break; | |
659 modelIndex++; | |
660 } | |
661 if (modelIndex is modelLength) { | |
662 auto oldModel = modelHandle; | |
663 uint[] types = getColumnTypes (columnCount + 4); // grow by 4 rows at a time | |
664 auto newModel = OS.gtk_tree_store_newv (types.length, types.ptr); | |
665 if (newModel is null) error (DWT.ERROR_NO_HANDLES); | |
666 copyModel (oldModel, FIRST_COLUMN, newModel, FIRST_COLUMN, types, null, null, modelLength); | |
667 OS.gtk_tree_view_set_model (handle, newModel); | |
668 OS.g_object_unref (oldModel); | |
669 modelHandle = newModel; | |
670 } | |
671 } | |
672 auto columnHandle = OS.gtk_tree_view_column_new (); | |
673 if (columnHandle is null) error (DWT.ERROR_NO_HANDLES); | |
674 if (index is 0 && columnCount > 0) { | |
675 TreeColumn checkColumn = columns [0]; | |
676 createRenderers (cast(GtkTreeViewColumn *)checkColumn.handle, checkColumn.modelIndex, false, checkColumn.style); | |
677 } | |
678 createRenderers (columnHandle, modelIndex, index is 0, column is null ? 0 : column.style); | |
679 /* | |
680 * Use GTK_TREE_VIEW_COLUMN_GROW_ONLY on GTK versions < 2.3.2 | |
681 * because fixed_height_mode is not supported. | |
682 */ | |
683 bool useVirtual = (style & DWT.VIRTUAL) !is 0 && OS.GTK_VERSION >= OS.buildVERSION (2, 3, 2); | |
684 if (!useVirtual && columnCount is 0) { | |
685 OS.gtk_tree_view_column_set_sizing (columnHandle, OS.GTK_TREE_VIEW_COLUMN_GROW_ONLY); | |
686 } else { | |
687 OS.gtk_tree_view_column_set_sizing (columnHandle, OS.GTK_TREE_VIEW_COLUMN_FIXED); | |
688 if (columnCount !is 0) OS.gtk_tree_view_column_set_visible (columnHandle, false); | |
689 } | |
690 OS.gtk_tree_view_column_set_resizable (columnHandle, true); | |
691 OS.gtk_tree_view_column_set_clickable (columnHandle, true); | |
692 OS.gtk_tree_view_column_set_min_width (columnHandle, 0); | |
693 OS.gtk_tree_view_insert_column (handle, columnHandle, index); | |
694 if (column !is null) { | |
695 column.handle = cast(GtkWidget*)columnHandle; | |
696 column.modelIndex = modelIndex; | |
697 } | |
698 /* Disable searching when using VIRTUAL */ | |
699 if ((style & DWT.VIRTUAL) !is 0) { | |
700 /* | |
701 * Bug in GTK. Until GTK 2.6.5, calling gtk_tree_view_set_enable_search(FALSE) | |
702 * would prevent the user from being able to type in text to search the tree. | |
703 * After 2.6.5, GTK introduced Ctrl+F as being the key binding for interactive | |
704 * search. This meant that even if FALSE was passed to enable_search, the user | |
705 * can still bring up the search pop up using the keybinding. GTK also introduced | |
706 * the notion of passing a -1 to gtk_set_search_column to disable searching | |
707 * (including the search key binding). The fix is to use the right calls | |
708 * for the right version. | |
709 */ | |
710 if (OS.GTK_VERSION >= OS.buildVERSION (2, 6, 5)) { | |
711 OS.gtk_tree_view_set_search_column (handle, -1); | |
712 } else { | |
713 OS.gtk_tree_view_set_enable_search (handle, false); | |
714 } | |
715 } else { | |
716 /* Set the search column whenever the model changes */ | |
717 int firstColumn = columnCount is 0 ? FIRST_COLUMN : columns [0].modelIndex; | |
718 OS.gtk_tree_view_set_search_column (handle, firstColumn + CELL_TEXT); | |
719 } | |
720 } | |
721 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
722 override void createHandle (int index) { |
90 | 723 state |= HANDLE; |
724 fixedHandle = cast(GtkWidget*)OS.g_object_new (display.gtk_fixed_get_type (), null); | |
725 if (fixedHandle is null) error (DWT.ERROR_NO_HANDLES); | |
726 OS.gtk_fixed_set_has_window (fixedHandle, true); | |
727 scrolledHandle = cast(GtkWidget*)OS.gtk_scrolled_window_new (null, null); | |
728 if (scrolledHandle is null) error (DWT.ERROR_NO_HANDLES); | |
729 uint[] types = getColumnTypes (1); | |
730 modelHandle = cast(GtkTreeStore*)OS.gtk_tree_store_newv (types.length, types.ptr); | |
731 if (modelHandle is null) error (DWT.ERROR_NO_HANDLES); | |
732 handle = cast(GtkWidget*)OS.gtk_tree_view_new_with_model (modelHandle); | |
733 if (handle is null) error (DWT.ERROR_NO_HANDLES); | |
734 if ((style & DWT.CHECK) !is 0) { | |
735 checkRenderer = cast(GtkCellRenderer*)OS.gtk_cell_renderer_toggle_new (); | |
736 if (checkRenderer is null) error (DWT.ERROR_NO_HANDLES); | |
737 OS.g_object_ref (checkRenderer); | |
738 } | |
739 createColumn (null, 0); | |
740 OS.gtk_container_add (fixedHandle, scrolledHandle); | |
741 OS.gtk_container_add (scrolledHandle, handle); | |
742 | |
743 int mode = (style & DWT.MULTI) !is 0 ? OS.GTK_SELECTION_MULTIPLE : OS.GTK_SELECTION_BROWSE; | |
744 auto selectionHandle = OS.gtk_tree_view_get_selection (handle); | |
745 OS.gtk_tree_selection_set_mode (selectionHandle, mode); | |
746 OS.gtk_tree_view_set_headers_visible (handle, false); | |
747 int hsp = (style & DWT.H_SCROLL) !is 0 ? OS.GTK_POLICY_AUTOMATIC : OS.GTK_POLICY_NEVER; | |
748 int vsp = (style & DWT.V_SCROLL) !is 0 ? OS.GTK_POLICY_AUTOMATIC : OS.GTK_POLICY_NEVER; | |
749 OS.gtk_scrolled_window_set_policy (scrolledHandle, hsp, vsp); | |
750 if ((style & DWT.BORDER) !is 0) OS.gtk_scrolled_window_set_shadow_type (scrolledHandle, OS.GTK_SHADOW_ETCHED_IN); | |
751 /* Disable searching when using VIRTUAL */ | |
752 if ((style & DWT.VIRTUAL) !is 0) { | |
753 /* The fixed_height_mode property only exists in GTK 2.3.2 and greater */ | |
754 if (OS.GTK_VERSION >= OS.buildVERSION (2, 3, 2)) { | |
755 OS.g_object_set1 (handle, OS.fixed_height_mode.ptr, true); | |
756 } | |
757 /* | |
758 * Bug in GTK. Until GTK 2.6.5, calling gtk_tree_view_set_enable_search(FALSE) | |
759 * would prevent the user from being able to type in text to search the tree. | |
760 * After 2.6.5, GTK introduced Ctrl+F as being the key binding for interactive | |
761 * search. This meant that even if FALSE was passed to enable_search, the user | |
762 * can still bring up the search pop up using the keybinding. GTK also introduced | |
763 * the notion of passing a -1 to gtk_set_search_column to disable searching | |
764 * (including the search key binding). The fix is to use the right calls | |
765 * for the right version. | |
766 */ | |
767 if (OS.GTK_VERSION >= OS.buildVERSION (2, 6, 5)) { | |
768 OS.gtk_tree_view_set_search_column (handle, -1); | |
769 } else { | |
770 OS.gtk_tree_view_set_enable_search (handle, false); | |
771 }; | |
772 } | |
773 } | |
774 | |
775 void createItem (TreeColumn column, int index) { | |
776 if (!(0 <= index && index <= columnCount)) error (DWT.ERROR_INVALID_RANGE); | |
777 if (index is 0) { | |
778 // first column must be left aligned | |
779 column.style &= ~(DWT.LEFT | DWT.RIGHT | DWT.CENTER); | |
780 column.style |= DWT.LEFT; | |
781 } | |
782 if (columnCount is 0) { | |
783 column.handle = cast(GtkWidget*)OS.gtk_tree_view_get_column (handle, 0); | |
784 OS.gtk_tree_view_column_set_sizing (column.handle, OS.GTK_TREE_VIEW_COLUMN_FIXED); | |
785 OS.gtk_tree_view_column_set_visible (column.handle, false); | |
786 column.modelIndex = FIRST_COLUMN; | |
787 createRenderers (cast(GtkTreeViewColumn *)column.handle, column.modelIndex, true, column.style); | |
788 column.customDraw = firstCustomDraw; | |
789 firstCustomDraw = false; | |
790 } else { | |
791 createColumn (column, index); | |
792 } | |
793 auto boxHandle = OS.gtk_hbox_new (false, 3); | |
794 if (boxHandle is null) error (DWT.ERROR_NO_HANDLES); | |
795 auto labelHandle = OS.gtk_label_new_with_mnemonic (null); | |
796 if (labelHandle is null) error (DWT.ERROR_NO_HANDLES); | |
797 auto imageHandle = OS.gtk_image_new (); | |
798 if (imageHandle is null) error (DWT.ERROR_NO_HANDLES); | |
799 OS.gtk_container_add (boxHandle, imageHandle); | |
800 OS.gtk_container_add (boxHandle, labelHandle); | |
801 OS.gtk_widget_show (boxHandle); | |
802 OS.gtk_widget_show (labelHandle); | |
803 column.labelHandle = labelHandle; | |
804 column.imageHandle = imageHandle; | |
805 OS.gtk_tree_view_column_set_widget (column.handle, boxHandle); | |
806 auto widget = OS.gtk_widget_get_parent (boxHandle); | |
807 while (widget !is handle) { | |
808 if (OS.GTK_IS_BUTTON (widget)) { | |
809 column.buttonHandle = widget; | |
810 break; | |
811 } | |
812 widget = OS.gtk_widget_get_parent (widget); | |
813 } | |
814 if (columnCount is columns.length) { | |
815 TreeColumn [] newColumns = new TreeColumn [columns.length + 4]; | |
816 System.arraycopy (columns, 0, newColumns, 0, columns.length); | |
817 columns = newColumns; | |
818 } | |
819 System.arraycopy (columns, index, columns, index + 1, columnCount++ - index); | |
820 columns [index] = column; | |
821 if ((state & FONT) !is 0) { | |
822 column.setFontDescription (getFontDescription ()); | |
823 } | |
824 if (columnCount >= 1) { | |
825 for (int i=0; i<items.length; i++) { | |
826 TreeItem item = items [i]; | |
827 if (item !is null) { | |
828 Font [] cellFont = item.cellFont; | |
829 if (cellFont !is null) { | |
830 Font [] temp = new Font [columnCount]; | |
831 System.arraycopy (cellFont, 0, temp, 0, index); | |
832 System.arraycopy (cellFont, index, temp, index+1, columnCount-index-1); | |
833 item.cellFont = temp; | |
834 } | |
835 } | |
836 } | |
837 } | |
838 } | |
839 | |
840 void createItem (TreeItem item, GtkTreeIter* parentIter, int index) { | |
841 int count = OS.gtk_tree_model_iter_n_children (modelHandle, parentIter); | |
842 if (index is -1) index = count; | |
843 if (!(0 <= index && index <= count)) error (DWT.ERROR_INVALID_RANGE); | |
844 item.handle = cast(GtkWidget*)OS.g_malloc (GtkTreeIter.sizeof); | |
845 if (item.handle is null) error(DWT.ERROR_NO_HANDLES); | |
846 /* | |
847 * Feature in GTK. It is much faster to append to a tree store | |
848 * than to insert at the end using gtk_tree_store_insert(). | |
849 */ | |
850 if (index is count) { | |
851 OS.gtk_tree_store_append (modelHandle, item.handle, parentIter); | |
852 } else { | |
853 OS.gtk_tree_store_insert (modelHandle, item.handle, parentIter, index); | |
854 } | |
855 int id = getId (cast(GtkTreeIter*) item.handle, false); | |
856 items [id] = item; | |
857 modelChanged = true; | |
858 } | |
859 | |
860 void createRenderers (GtkTreeViewColumn* columnHandle, int modelIndex, bool check, int columnStyle) { | |
861 OS.gtk_tree_view_column_clear (columnHandle); | |
862 if ((style & DWT.CHECK) !is 0 && check) { | |
863 OS.gtk_tree_view_column_pack_start (columnHandle, checkRenderer, false); | |
864 OS.gtk_tree_view_column_add_attribute (columnHandle, checkRenderer, OS.active.ptr, CHECKED_COLUMN); | |
865 /* | |
866 * Feature in GTK. The inconsistent property only exists in GTK 2.2.x. | |
867 */ | |
868 if (OS.GTK_VERSION >= OS.buildVERSION (2, 2, 0)) { | |
869 OS.gtk_tree_view_column_add_attribute (columnHandle, checkRenderer, OS.inconsistent.ptr, GRAYED_COLUMN); | |
870 } | |
871 /* | |
872 * Bug in GTK. GTK renders the background on top of the checkbox. | |
873 * This only happens in version 2.2.1 and earlier. The fix is not to set the background. | |
874 */ | |
875 if (OS.GTK_VERSION > OS.buildVERSION (2, 2, 1)) { | |
876 if (!ownerDraw) OS.gtk_tree_view_column_add_attribute (columnHandle, checkRenderer, OS.cell_background_gdk.ptr, BACKGROUND_COLUMN); | |
877 } | |
878 if (ownerDraw) { | |
879 display.doCellDataProc( handle, cast(GtkTreeViewColumn*)columnHandle, cast(GtkCellRenderer*)checkRenderer ); | |
880 OS.g_object_set_qdata (cast(GObject*)checkRenderer, Display.SWT_OBJECT_INDEX1, columnHandle); | |
881 } | |
882 } | |
883 auto pixbufRenderer = ownerDraw ? cast(GtkCellRenderer*)OS.g_object_new (display.gtk_cell_renderer_pixbuf_get_type (), null) : OS.gtk_cell_renderer_pixbuf_new (); | |
884 if (pixbufRenderer is null) error (DWT.ERROR_NO_HANDLES); | |
885 auto textRenderer = ownerDraw ? cast(GtkCellRenderer*)OS.g_object_new (display.gtk_cell_renderer_text_get_type (), null) : OS.gtk_cell_renderer_text_new (); | |
886 if (textRenderer is null) error (DWT.ERROR_NO_HANDLES); | |
887 | |
888 if (ownerDraw) { | |
889 OS.g_object_set_qdata (cast(GObject*)pixbufRenderer, Display.SWT_OBJECT_INDEX1, columnHandle); | |
890 OS.g_object_set_qdata (cast(GObject*)textRenderer, Display.SWT_OBJECT_INDEX1, columnHandle); | |
891 } | |
892 | |
893 /* | |
894 * Feature in GTK. When a tree view column contains only one activatable | |
895 * cell renderer such as a toggle renderer, mouse clicks anywhere in a cell | |
896 * activate that renderer. The workaround is to set a second cell renderer | |
897 * to be activatable. | |
898 */ | |
899 if ((style & DWT.CHECK) !is 0 && check) { | |
900 OS.g_object_set1 (pixbufRenderer, OS.mode.ptr, OS.GTK_CELL_RENDERER_MODE_ACTIVATABLE); | |
901 } | |
902 | |
903 /* Set alignment */ | |
904 if ((columnStyle & DWT.RIGHT) !is 0) { | |
215
8e159d7052e0
Fix column alignment for tree
Frank Benoit <benoit@tionex.de>
parents:
211
diff
changeset
|
905 OS.g_object_set1_float(textRenderer, OS.xalign.ptr, 1.0f); |
90 | 906 OS.gtk_tree_view_column_pack_end (columnHandle, textRenderer, true); |
907 OS.gtk_tree_view_column_pack_end (columnHandle, pixbufRenderer, false); | |
908 OS.gtk_tree_view_column_set_alignment (columnHandle, 1f); | |
909 } else if ((columnStyle & DWT.CENTER) !is 0) { | |
215
8e159d7052e0
Fix column alignment for tree
Frank Benoit <benoit@tionex.de>
parents:
211
diff
changeset
|
910 OS.g_object_set1_float(textRenderer, OS.xalign.ptr, 0.5f); |
90 | 911 OS.gtk_tree_view_column_pack_start (columnHandle, pixbufRenderer, false); |
912 OS.gtk_tree_view_column_pack_end (columnHandle, textRenderer, true); | |
913 OS.gtk_tree_view_column_set_alignment (columnHandle, 0.5f); | |
914 } else { | |
915 OS.gtk_tree_view_column_pack_start (columnHandle, pixbufRenderer, false); | |
916 OS.gtk_tree_view_column_pack_start (columnHandle, textRenderer, true); | |
917 OS.gtk_tree_view_column_set_alignment (columnHandle, 0f); | |
918 } | |
919 | |
920 /* Add attributes */ | |
921 OS.gtk_tree_view_column_add_attribute (columnHandle, pixbufRenderer, OS.pixbuf.ptr, modelIndex + CELL_PIXBUF); | |
922 /* | |
923 * Bug on GTK. Gtk renders the background on top of the pixbuf. | |
924 * This only happens in version 2.2.1 and earlier. The fix is not to set the background. | |
925 */ | |
926 if (OS.GTK_VERSION > OS.buildVERSION (2, 2, 1)) { | |
927 if (!ownerDraw) { | |
928 OS.gtk_tree_view_column_add_attribute (columnHandle, pixbufRenderer, OS.cell_background_gdk.ptr, BACKGROUND_COLUMN); | |
929 OS.gtk_tree_view_column_add_attribute (columnHandle, textRenderer, OS.cell_background_gdk.ptr, BACKGROUND_COLUMN); | |
930 } | |
931 } | |
932 OS.gtk_tree_view_column_add_attribute (columnHandle, textRenderer, OS.text.ptr, modelIndex + CELL_TEXT); | |
933 OS.gtk_tree_view_column_add_attribute (columnHandle, textRenderer, OS.foreground_gdk.ptr, FOREGROUND_COLUMN); | |
934 OS.gtk_tree_view_column_add_attribute (columnHandle, textRenderer, OS.font_desc.ptr, FONT_COLUMN); | |
935 | |
936 bool customDraw = firstCustomDraw; | |
937 if (columnCount !is 0) { | |
938 for (int i=0; i<columnCount; i++) { | |
939 if (columns [i].handle is cast(GtkWidget*)columnHandle) { | |
940 customDraw = columns [i].customDraw; | |
941 break; | |
942 } | |
943 } | |
944 } | |
945 if ((style & DWT.VIRTUAL) !is 0 || customDraw || ownerDraw) { | |
946 display.doCellDataProc( handle, cast(GtkTreeViewColumn*)columnHandle, cast(GtkCellRenderer*)textRenderer ); | |
947 display.doCellDataProc( handle, cast(GtkTreeViewColumn*)columnHandle, cast(GtkCellRenderer*)pixbufRenderer ); | |
948 } | |
949 } | |
950 | |
951 void createWidget (int index) { | |
952 super.createWidget (index); | |
953 items = new TreeItem [4]; | |
954 columns = new TreeColumn [4]; | |
955 columnCount = 0; | |
956 } | |
957 | |
958 GdkColor* defaultBackground () { | |
959 return display.COLOR_LIST_BACKGROUND; | |
960 } | |
961 | |
962 GdkColor* defaultForeground () { | |
963 return display.COLOR_LIST_FOREGROUND; | |
964 } | |
965 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
966 override void deregister () { |
90 | 967 super.deregister (); |
968 display.removeWidget (cast(GtkWidget*)OS.gtk_tree_view_get_selection (handle)); | |
969 if (checkRenderer !is null) display.removeWidget (cast(GtkWidget*)checkRenderer); | |
970 } | |
971 | |
240 | 972 public void deselect (TreeItem item) { |
973 checkWidget (); | |
974 if (item is null) error (DWT.ERROR_NULL_ARGUMENT); | |
975 if (item.isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT); | |
976 bool fixColumn = showFirstColumn (); | |
977 auto selection = OS.gtk_tree_view_get_selection (handle); | |
978 OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udCHANGED); | |
979 OS.gtk_tree_selection_unselect_iter (selection, item.handle); | |
980 OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udCHANGED); | |
981 if (fixColumn) hideFirstColumn (); | |
982 } | |
983 | |
90 | 984 /** |
985 * Deselects all selected items in the receiver. | |
986 * | |
987 * @exception DWTException <ul> | |
988 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
989 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
990 * </ul> | |
991 */ | |
992 public void deselectAll() { | |
993 checkWidget(); | |
994 bool fixColumn = showFirstColumn (); | |
995 auto selection = OS.gtk_tree_view_get_selection (handle); | |
996 OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udCHANGED); | |
997 OS.gtk_tree_selection_unselect_all (selection); | |
998 OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udCHANGED); | |
999 if (fixColumn) hideFirstColumn (); | |
1000 } | |
1001 | |
1002 void destroyItem (TreeColumn column) { | |
1003 int index = 0; | |
1004 while (index < columnCount) { | |
1005 if (columns [index] is column) break; | |
1006 index++; | |
1007 } | |
1008 if (index is columnCount) return; | |
1009 auto columnHandle = column.handle; | |
1010 if (columnCount is 1) { | |
1011 firstCustomDraw = column.customDraw; | |
1012 } | |
1013 System.arraycopy (columns, index + 1, columns, index, --columnCount - index); | |
1014 columns [columnCount] = null; | |
1015 OS.gtk_tree_view_remove_column (handle, columnHandle); | |
1016 if (columnCount is 0) { | |
1017 auto oldModel = modelHandle; | |
1018 uint[] types = getColumnTypes (1); | |
1019 auto newModel = OS.gtk_tree_store_newv (types.length, types.ptr); | |
1020 if (newModel is null) error (DWT.ERROR_NO_HANDLES); | |
1021 copyModel(oldModel, column.modelIndex, newModel, FIRST_COLUMN, types, null, null, FIRST_COLUMN + CELL_TYPES); | |
1022 OS.gtk_tree_view_set_model (handle, newModel); | |
1023 OS.g_object_unref (oldModel); | |
1024 modelHandle = newModel; | |
1025 createColumn (null, 0); | |
1026 | |
1027 } else { | |
1028 for (int i=0; i<items.length; i++) { | |
1029 TreeItem item = items [i]; | |
1030 if (item !is null) { | |
1031 auto iter = cast(GtkTreeIter*)item.handle; | |
1032 int modelIndex = column.modelIndex; | |
1033 OS.gtk_tree_store_set1 (modelHandle, iter, modelIndex + CELL_PIXBUF, null); | |
1034 OS.gtk_tree_store_set1 (modelHandle, iter, modelIndex + CELL_TEXT, null); | |
1035 OS.gtk_tree_store_set1 (modelHandle, iter, modelIndex + CELL_FOREGROUND, null); | |
1036 OS.gtk_tree_store_set1 (modelHandle, iter, modelIndex + CELL_BACKGROUND, null); | |
1037 OS.gtk_tree_store_set1 (modelHandle, iter, modelIndex + CELL_FONT, null); | |
1038 | |
1039 Font [] cellFont = item.cellFont; | |
1040 if (cellFont !is null) { | |
1041 if (columnCount is 0) { | |
1042 item.cellFont = null; | |
1043 } else { | |
1044 Font [] temp = new Font [columnCount]; | |
1045 System.arraycopy (cellFont, 0, temp, 0, index); | |
1046 System.arraycopy (cellFont, index + 1, temp, index, columnCount - index); | |
1047 item.cellFont = temp; | |
1048 } | |
1049 } | |
1050 } | |
1051 } | |
1052 if (index is 0) { | |
1053 // first column must be left aligned and must show check box | |
1054 TreeColumn firstColumn = columns [0]; | |
1055 firstColumn.style &= ~(DWT.LEFT | DWT.RIGHT | DWT.CENTER); | |
1056 firstColumn.style |= DWT.LEFT; | |
1057 createRenderers (cast(GtkTreeViewColumn*)firstColumn.handle, firstColumn.modelIndex, true, firstColumn.style); | |
1058 } | |
1059 } | |
1060 /* Disable searching when using VIRTUAL */ | |
1061 if ((style & DWT.VIRTUAL) !is 0) { | |
1062 /* | |
1063 * Bug in GTK. Until GTK 2.6.5, calling gtk_tree_view_set_enable_search(FALSE) | |
1064 * would prevent the user from being able to type in text to search the tree. | |
1065 * After 2.6.5, GTK introduced Ctrl+F as being the key binding for interactive | |
1066 * search. This meant that even if FALSE was passed to enable_search, the user | |
1067 * can still bring up the search pop up using the keybinding. GTK also introduced | |
1068 * the notion of passing a -1 to gtk_set_search_column to disable searching | |
1069 * (including the search key binding). The fix is to use the right calls | |
1070 * for the right version. | |
1071 */ | |
1072 if (OS.GTK_VERSION >= OS.buildVERSION (2, 6, 5)) { | |
1073 OS.gtk_tree_view_set_search_column (handle, -1); | |
1074 } else { | |
1075 OS.gtk_tree_view_set_enable_search (handle, false); | |
1076 } | |
1077 } else { | |
1078 /* Set the search column whenever the model changes */ | |
1079 int firstColumn = columnCount is 0 ? FIRST_COLUMN : columns [0].modelIndex; | |
1080 OS.gtk_tree_view_set_search_column (handle, firstColumn + CELL_TEXT); | |
1081 } | |
1082 } | |
1083 | |
1084 | |
1085 void destroyItem (TreeItem item) { | |
1086 /* | |
1087 * Bug in GTK. GTK segment faults when a root tree item | |
1088 * is destroyed when the tree is expanded and the last leaf of | |
1089 * the root is selected. This only happens in versions earlier | |
1090 * than 2.0.6. The fix is to collapse the tree item being destroyed | |
1091 * when it is a root, before it is destroyed. | |
1092 */ | |
1093 if (OS.GTK_VERSION < OS.buildVERSION (2, 0, 6)) { | |
1094 int length = OS.gtk_tree_model_iter_n_children (modelHandle, null); | |
1095 if (length > 0) { | |
1096 GtkTreeIter iter; | |
1097 bool valid = cast(bool)OS.gtk_tree_model_iter_children (modelHandle, &iter, null); | |
1098 while (valid) { | |
1099 //PORTING_TODO: is this condition reasonable? | |
1100 if (item.handle is cast(GtkWidget*)&iter) { | |
1101 item.setExpanded (false); | |
1102 break; | |
1103 } | |
1104 valid = cast(bool)OS.gtk_tree_model_iter_next (modelHandle, &iter); | |
1105 } | |
1106 } | |
1107 } | |
1108 auto selection = OS.gtk_tree_view_get_selection (handle); | |
1109 OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udCHANGED); | |
1110 OS.gtk_tree_store_remove (modelHandle, item.handle); | |
1111 OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udCHANGED); | |
1112 modelChanged = true; | |
1113 } | |
1114 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
1115 override bool dragDetect (int x, int y, bool filter, bool * consume) { |
90 | 1116 bool selected = false; |
1117 if (filter) { | |
1118 void* path; | |
1119 if (OS.gtk_tree_view_get_path_at_pos (handle, x, y, &path, null, null, null)) { | |
1120 if (path !is null) { | |
1121 auto selection = OS.gtk_tree_view_get_selection (handle); | |
1122 if (OS.gtk_tree_selection_path_is_selected (selection, path )) selected = true; | |
1123 OS.gtk_tree_path_free (path ); | |
1124 } | |
1125 } else { | |
1126 return false; | |
1127 } | |
1128 } | |
1129 bool dragDetect = super.dragDetect (x, y, filter, consume); | |
1130 if (dragDetect && selected && consume !is null) consume [0] = true; | |
1131 return dragDetect; | |
1132 } | |
1133 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
1134 override GdkDrawable* eventWindow () { |
90 | 1135 return paintWindow (); |
1136 } | |
1137 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
1138 override void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, Decorations oldDecorations, Menu [] menus) { |
90 | 1139 super.fixChildren (newShell, oldShell, newDecorations, oldDecorations, menus); |
1140 for (int i=0; i<columnCount; i++) { | |
1141 TreeColumn column = columns [i]; | |
1142 if (column.toolTipText !is null) { | |
1143 column.setToolTipText(oldShell, null); | |
1144 column.setToolTipText(newShell, column.toolTipText); | |
1145 } | |
1146 } | |
1147 } | |
1148 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
1149 override GdkColor* getBackgroundColor () { |
90 | 1150 return getBaseColor (); |
1151 } | |
1152 | |
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
115
diff
changeset
|
1153 public override Rectangle getClientArea () { |
90 | 1154 checkWidget (); |
1155 forceResize (); | |
1156 OS.gtk_widget_realize (handle); | |
1157 auto fixedWindow = OS.GTK_WIDGET_WINDOW (fixedHandle); | |
1158 auto binWindow = OS.gtk_tree_view_get_bin_window (handle); | |
1159 int binX, binY; | |
1160 OS.gdk_window_get_origin (binWindow, &binX, &binY); | |
1161 int fixedX, fixedY; | |
1162 OS.gdk_window_get_origin (fixedWindow, &fixedX, &fixedY); | |
1163 auto clientHandle = clientHandle (); | |
1164 int width = (state & ZERO_WIDTH) !is 0 ? 0 : OS.GTK_WIDGET_WIDTH (clientHandle); | |
1165 int height = (state & ZERO_HEIGHT) !is 0 ? 0 : OS.GTK_WIDGET_HEIGHT (clientHandle); | |
1166 return new Rectangle (fixedX - binX , fixedY - binY , width, height); | |
1167 } | |
1168 | |
240 | 1169 int getClientWidth () { |
1170 int w, h; | |
1171 OS.gtk_widget_realize (handle); | |
1172 OS.gdk_drawable_get_size(OS.gtk_tree_view_get_bin_window(handle), &w, &h); | |
1173 return w; | |
1174 } | |
1175 | |
90 | 1176 /** |
1177 * Returns the column at the given, zero-relative index in the | |
1178 * receiver. Throws an exception if the index is out of range. | |
1179 * Columns are returned in the order that they were created. | |
1180 * If no <code>TreeColumn</code>s were created by the programmer, | |
1181 * this method will throw <code>ERROR_INVALID_RANGE</code> despite | |
1182 * the fact that a single column of data may be visible in the tree. | |
1183 * This occurs when the programmer uses the tree like a list, adding | |
1184 * items but never creating a column. | |
1185 * | |
1186 * @param index the index of the column to return | |
1187 * @return the column at the given index | |
1188 * | |
1189 * @exception IllegalArgumentException <ul> | |
1190 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> | |
1191 * </ul> | |
1192 * @exception DWTException <ul> | |
1193 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1194 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1195 * </ul> | |
1196 * | |
1197 * @see Tree#getColumnOrder() | |
1198 * @see Tree#setColumnOrder(int[]) | |
1199 * @see TreeColumn#getMoveable() | |
1200 * @see TreeColumn#setMoveable(bool) | |
1201 * @see DWT#Move | |
1202 * | |
1203 * @since 3.1 | |
1204 */ | |
1205 public TreeColumn getColumn (int index) { | |
1206 checkWidget(); | |
1207 if (!(0 <= index && index < columnCount)) error (DWT.ERROR_INVALID_RANGE); | |
1208 return columns [index]; | |
1209 } | |
1210 | |
1211 /** | |
1212 * Returns the number of columns contained in the receiver. | |
1213 * If no <code>TreeColumn</code>s were created by the programmer, | |
1214 * this value is zero, despite the fact that visually, one column | |
1215 * of items may be visible. This occurs when the programmer uses | |
1216 * the tree like a list, adding items but never creating a column. | |
1217 * | |
1218 * @return the number of columns | |
1219 * | |
1220 * @exception DWTException <ul> | |
1221 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1222 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1223 * </ul> | |
1224 * | |
1225 * @since 3.1 | |
1226 */ | |
1227 public int getColumnCount () { | |
1228 checkWidget(); | |
1229 return columnCount; | |
1230 } | |
1231 | |
1232 /** | |
1233 * Returns an array of zero-relative integers that map | |
1234 * the creation order of the receiver's items to the | |
1235 * order in which they are currently being displayed. | |
1236 * <p> | |
1237 * Specifically, the indices of the returned array represent | |
1238 * the current visual order of the items, and the contents | |
1239 * of the array represent the creation order of the items. | |
1240 * </p><p> | |
1241 * Note: This is not the actual structure used by the receiver | |
1242 * to maintain its list of items, so modifying the array will | |
1243 * not affect the receiver. | |
1244 * </p> | |
1245 * | |
1246 * @return the current visual order of the receiver's items | |
1247 * | |
1248 * @exception DWTException <ul> | |
1249 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1250 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1251 * </ul> | |
1252 * | |
1253 * @see Tree#setColumnOrder(int[]) | |
1254 * @see TreeColumn#getMoveable() | |
1255 * @see TreeColumn#setMoveable(bool) | |
1256 * @see DWT#Move | |
1257 * | |
1258 * @since 3.2 | |
1259 */ | |
1260 public int [] getColumnOrder () { | |
1261 checkWidget (); | |
1262 if (columnCount is 0) return null; | |
1263 auto list = OS.gtk_tree_view_get_columns (handle); | |
1264 if (list is null) return null; | |
1265 int i = 0, count = OS.g_list_length (list); | |
1266 int [] order = new int [count]; | |
1267 auto temp = list; | |
1268 while (temp !is null) { | |
1269 auto column = OS.g_list_data (temp); | |
1270 if (column !is null) { | |
1271 for (int j=0; j<columnCount; j++) { | |
1272 if (columns [j].handle is column) { | |
1273 order [i++] = j; | |
1274 break; | |
1275 } | |
1276 } | |
1277 } | |
1278 temp = OS.g_list_next (temp); | |
1279 } | |
1280 OS.g_list_free (list); | |
1281 return order; | |
1282 } | |
1283 | |
1284 uint[] getColumnTypes (int columnCount) { | |
1285 uint[] types = new uint [FIRST_COLUMN + (columnCount * CELL_TYPES)]; | |
1286 // per row data | |
1287 types [ID_COLUMN] = OS.G_TYPE_INT (); | |
1288 types [CHECKED_COLUMN] = OS.G_TYPE_BOOLEAN (); | |
1289 types [GRAYED_COLUMN] = OS.G_TYPE_BOOLEAN (); | |
1290 types [FOREGROUND_COLUMN] = OS.GDK_TYPE_COLOR (); | |
1291 types [BACKGROUND_COLUMN] = OS.GDK_TYPE_COLOR (); | |
1292 types [FONT_COLUMN] = OS.PANGO_TYPE_FONT_DESCRIPTION (); | |
1293 // per cell data | |
1294 for (int i=FIRST_COLUMN; i<types.length; i+=CELL_TYPES) { | |
1295 types [i + CELL_PIXBUF] = OS.GDK_TYPE_PIXBUF (); | |
1296 types [i + CELL_TEXT] = OS.G_TYPE_STRING (); | |
1297 types [i + CELL_FOREGROUND] = OS.GDK_TYPE_COLOR (); | |
1298 types [i + CELL_BACKGROUND] = OS.GDK_TYPE_COLOR (); | |
1299 types [i + CELL_FONT] = OS.PANGO_TYPE_FONT_DESCRIPTION (); | |
1300 } | |
1301 return types; | |
1302 } | |
1303 | |
1304 /** | |
1305 * Returns an array of <code>TreeColumn</code>s which are the | |
1306 * columns in the receiver. Columns are returned in the order | |
1307 * that they were created. If no <code>TreeColumn</code>s were | |
1308 * created by the programmer, the array is empty, despite the fact | |
1309 * that visually, one column of items may be visible. This occurs | |
1310 * when the programmer uses the tree like a list, adding items but | |
1311 * never creating a column. | |
1312 * <p> | |
1313 * Note: This is not the actual structure used by the receiver | |
1314 * to maintain its list of items, so modifying the array will | |
1315 * not affect the receiver. | |
1316 * </p> | |
1317 * | |
1318 * @return the items in the receiver | |
1319 * | |
1320 * @exception DWTException <ul> | |
1321 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1322 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1323 * </ul> | |
1324 * | |
1325 * @see Tree#getColumnOrder() | |
1326 * @see Tree#setColumnOrder(int[]) | |
1327 * @see TreeColumn#getMoveable() | |
1328 * @see TreeColumn#setMoveable(bool) | |
1329 * @see DWT#Move | |
1330 * | |
1331 * @since 3.1 | |
1332 */ | |
1333 public TreeColumn [] getColumns () { | |
1334 checkWidget(); | |
1335 TreeColumn [] result = new TreeColumn [columnCount]; | |
1336 System.arraycopy (columns, 0, result, 0, columnCount); | |
1337 return result; | |
1338 } | |
1339 | |
1340 TreeItem getFocusItem () { | |
1341 GtkTreePath* path; | |
1342 OS.gtk_tree_view_get_cursor (handle, &path, null); | |
1343 if (path is null) return null; | |
1344 TreeItem item = null; | |
1345 GtkTreeIter iter; | |
1346 if (OS.gtk_tree_model_get_iter (modelHandle, &iter, path)) { | |
1347 int index; | |
1348 OS.gtk_tree_model_get1 (modelHandle, &iter, ID_COLUMN, cast(void**)&index); | |
1349 if (index !is -1) item = items [index ]; //TODO should we be creating this item when index is -1? | |
1350 } | |
1351 OS.gtk_tree_path_free (path ); | |
1352 return item; | |
1353 } | |
1354 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
1355 override GdkColor* getForegroundColor () { |
90 | 1356 return getTextColor (); |
1357 } | |
1358 | |
1359 /** | |
1360 * Returns the width in pixels of a grid line. | |
1361 * | |
1362 * @return the width of a grid line in pixels | |
1363 * | |
1364 * @exception DWTException <ul> | |
1365 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1366 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1367 * </ul> | |
1368 * | |
1369 * @since 3.1 | |
1370 */ | |
1371 public int getGridLineWidth () { | |
1372 checkWidget(); | |
1373 return 0; | |
1374 } | |
1375 | |
1376 /** | |
1377 * Returns the height of the receiver's header | |
1378 * | |
1379 * @return the height of the header or zero if the header is not visible | |
1380 * | |
1381 * @exception DWTException <ul> | |
1382 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1383 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1384 * </ul> | |
1385 * | |
1386 * @since 3.1 | |
1387 */ | |
1388 public int getHeaderHeight () { | |
1389 checkWidget (); | |
1390 if (!OS.gtk_tree_view_get_headers_visible (handle)) return 0; | |
1391 if (columnCount > 0) { | |
1392 GtkRequisition requisition; | |
1393 int height = 0; | |
1394 for (int i=0; i<columnCount; i++) { | |
1395 auto buttonHandle = columns [i].buttonHandle; | |
1396 if (buttonHandle !is null) { | |
1397 OS.gtk_widget_size_request (buttonHandle, &requisition); | |
1398 height = Math.max (height, requisition.height); | |
1399 } | |
1400 } | |
1401 return height; | |
1402 } | |
1403 OS.gtk_widget_realize (handle); | |
1404 auto fixedWindow = OS.GTK_WIDGET_WINDOW (fixedHandle); | |
1405 auto binWindow = OS.gtk_tree_view_get_bin_window (handle); | |
1406 int binY ; | |
1407 OS.gdk_window_get_origin (binWindow, null, &binY); | |
1408 int fixedY; | |
1409 OS.gdk_window_get_origin (fixedWindow, null, &fixedY); | |
1410 return binY - fixedY ; | |
1411 } | |
1412 | |
1413 /** | |
1414 * Returns <code>true</code> if the receiver's header is visible, | |
1415 * and <code>false</code> otherwise. | |
1416 * <p> | |
1417 * If one of the receiver's ancestors is not visible or some | |
1418 * other condition makes the receiver not visible, this method | |
1419 * may still indicate that it is considered visible even though | |
1420 * it may not actually be showing. | |
1421 * </p> | |
1422 * | |
1423 * @return the receiver's header's visibility state | |
1424 * | |
1425 * @exception DWTException <ul> | |
1426 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1427 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1428 * </ul> | |
1429 * | |
1430 * @since 3.1 | |
1431 */ | |
1432 public bool getHeaderVisible () { | |
1433 checkWidget(); | |
1434 return cast(bool)OS.gtk_tree_view_get_headers_visible (handle); | |
1435 } | |
1436 | |
1437 /** | |
1438 * Returns the item at the given, zero-relative index in the | |
1439 * receiver. Throws an exception if the index is out of range. | |
1440 * | |
1441 * @param index the index of the item to return | |
1442 * @return the item at the given index | |
1443 * | |
1444 * @exception IllegalArgumentException <ul> | |
1445 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> | |
1446 * </ul> | |
1447 * @exception DWTException <ul> | |
1448 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1449 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1450 * </ul> | |
1451 * | |
1452 * @since 3.1 | |
1453 */ | |
1454 public TreeItem getItem (int index) { | |
1455 checkWidget(); | |
1456 if (!(0 <= index && index < OS.gtk_tree_model_iter_n_children (modelHandle, null))) { | |
1457 error (DWT.ERROR_INVALID_RANGE); | |
1458 } | |
1459 return _getItem (null, index); | |
1460 } | |
1461 | |
1462 /** | |
1463 * Returns the item at the given point in the receiver | |
1464 * or null if no such item exists. The point is in the | |
1465 * coordinate system of the receiver. | |
1466 * <p> | |
1467 * The item that is returned represents an item that could be selected by the user. | |
1468 * For example, if selection only occurs in items in the first column, then null is | |
1469 * returned if the point is outside of the item. | |
1470 * Note that the DWT.FULL_SELECTION style hint, which specifies the selection policy, | |
1471 * determines the extent of the selection. | |
1472 * </p> | |
1473 * | |
1474 * @param point the point used to locate the item | |
1475 * @return the item at the given point, or null if the point is not in a selectable item | |
1476 * | |
1477 * @exception IllegalArgumentException <ul> | |
1478 * <li>ERROR_NULL_ARGUMENT - if the point is null</li> | |
1479 * </ul> | |
1480 * @exception DWTException <ul> | |
1481 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1482 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1483 * </ul> | |
1484 */ | |
1485 public TreeItem getItem (Point point) { | |
1486 checkWidget (); | |
1487 if (point is null) error (DWT.ERROR_NULL_ARGUMENT); | |
1488 void* path; | |
1489 OS.gtk_widget_realize (handle); | |
1490 GtkTreeViewColumn* columnHandle; | |
1491 if (!OS.gtk_tree_view_get_path_at_pos (handle, point.x, point.y, &path, &columnHandle, null, null)) return null; | |
1492 if (path is null) return null; | |
1493 TreeItem item = null; | |
1494 GtkTreeIter iter; | |
1495 if (OS.gtk_tree_model_get_iter (modelHandle, &iter, path )) { | |
1496 bool overExpander = false; | |
1497 if (OS.gtk_tree_view_get_expander_column (handle) is columnHandle ) { | |
1498 int buffer; | |
1499 GdkRectangle rect; | |
1500 OS.gtk_tree_view_get_cell_area (handle, path, columnHandle, &rect); | |
1501 if (OS.GTK_VERSION < OS.buildVERSION (2, 8, 18)) { | |
1502 OS.gtk_widget_style_get1 (handle, OS.expander_size.ptr, &buffer); | |
1503 int expanderSize = buffer + TreeItem.EXPANDER_EXTRA_PADDING; | |
1504 overExpander = point.x < rect.x + expanderSize; | |
1505 } else { | |
1506 overExpander = point.x < rect.x; | |
1507 } | |
1508 } | |
1509 if (!overExpander) { | |
1510 item = _getItem (&iter); | |
1511 } | |
1512 } | |
1513 OS.gtk_tree_path_free (path ); | |
1514 return item; | |
1515 } | |
1516 | |
1517 /** | |
1518 * Returns the number of items contained in the receiver | |
1519 * that are direct item children of the receiver. The | |
1520 * number that is returned is the number of roots in the | |
1521 * tree. | |
1522 * | |
1523 * @return the number of items | |
1524 * | |
1525 * @exception DWTException <ul> | |
1526 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1527 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1528 * </ul> | |
1529 */ | |
1530 public int getItemCount () { | |
1531 checkWidget (); | |
1532 return OS.gtk_tree_model_iter_n_children (modelHandle, null); | |
1533 } | |
1534 | |
1535 /** | |
1536 * Returns the height of the area which would be used to | |
1537 * display <em>one</em> of the items in the tree. | |
1538 * | |
1539 * @return the height of one item | |
1540 * | |
1541 * @exception DWTException <ul> | |
1542 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1543 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1544 * </ul> | |
1545 */ | |
1546 public int getItemHeight () { | |
1547 checkWidget (); | |
1548 int itemCount = OS.gtk_tree_model_iter_n_children (modelHandle, null); | |
1549 if (itemCount is 0) { | |
1550 auto column = OS.gtk_tree_view_get_column (handle, 0); | |
1551 int w, h; | |
1552 ignoreSize = true; | |
1553 OS.gtk_tree_view_column_cell_get_size (column, null, null, null, &w, &h); | |
1554 ignoreSize = false; | |
1555 return h ; | |
1556 } else { | |
1557 int height = 0; | |
1558 GtkTreeIter iter; | |
1559 OS.gtk_tree_model_get_iter_first (modelHandle, &iter); | |
1560 int columnCount = Math.max (1, this.columnCount); | |
1561 for (int i=0; i<columnCount; i++) { | |
1562 auto column = OS.gtk_tree_view_get_column (handle, i); | |
1563 OS.gtk_tree_view_column_cell_set_cell_data (column, modelHandle, &iter, false, false); | |
1564 int w, h; | |
1565 OS.gtk_tree_view_column_cell_get_size (column, null, null, null, &w, &h); | |
1566 height = Math.max (height, h ); | |
1567 } | |
1568 return height; | |
1569 } | |
1570 } | |
1571 | |
1572 /** | |
1573 * Returns a (possibly empty) array of items contained in the | |
1574 * receiver that are direct item children of the receiver. These | |
1575 * are the roots of the tree. | |
1576 * <p> | |
1577 * Note: This is not the actual structure used by the receiver | |
1578 * to maintain its list of items, so modifying the array will | |
1579 * not affect the receiver. | |
1580 * </p> | |
1581 * | |
1582 * @return the items | |
1583 * | |
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 public TreeItem [] getItems () { | |
1590 checkWidget(); | |
1591 return getItems (null); | |
1592 } | |
1593 | |
1594 TreeItem [] getItems (GtkTreeIter* parent) { | |
1595 int length = OS.gtk_tree_model_iter_n_children (modelHandle, parent); | |
1596 TreeItem[] result = new TreeItem [length]; | |
1597 if (length is 0) return result; | |
1598 if ((style & DWT.VIRTUAL) !is 0) { | |
1599 for (int i=0; i<length; i++) { | |
1600 result [i] = _getItem (parent, i); | |
1601 } | |
1602 } else { | |
1603 int i = 0; | |
1604 int index; | |
1605 GtkTreeIter iter; | |
1606 bool valid = cast(bool)OS.gtk_tree_model_iter_children (modelHandle, &iter, parent); | |
1607 while (valid) { | |
1608 OS.gtk_tree_model_get1 (modelHandle, &iter, ID_COLUMN, cast(void**)&index); | |
1609 result [i++] = items [index ]; | |
1610 valid = cast(bool)OS.gtk_tree_model_iter_next (modelHandle, &iter); | |
1611 } | |
1612 } | |
1613 return result; | |
1614 } | |
1615 | |
1616 /** | |
1617 * Returns <code>true</code> if the receiver's lines are visible, | |
1618 * and <code>false</code> otherwise. | |
1619 * <p> | |
1620 * If one of the receiver's ancestors is not visible or some | |
1621 * other condition makes the receiver not visible, this method | |
1622 * may still indicate that it is considered visible even though | |
1623 * it may not actually be showing. | |
1624 * </p> | |
1625 * | |
1626 * @return the visibility state of the lines | |
1627 * | |
1628 * @exception DWTException <ul> | |
1629 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1630 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1631 * </ul> | |
1632 * | |
1633 * @since 3.1 | |
1634 */ | |
1635 public bool getLinesVisible() { | |
1636 checkWidget(); | |
1637 return cast(bool)OS.gtk_tree_view_get_rules_hint (handle); | |
1638 } | |
1639 | |
1640 /** | |
1641 * Returns the receiver's parent item, which must be a | |
1642 * <code>TreeItem</code> or null when the receiver is a | |
1643 * root. | |
1644 * | |
1645 * @return the receiver's parent item | |
1646 * | |
1647 * @exception DWTException <ul> | |
1648 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1649 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1650 * </ul> | |
1651 */ | |
1652 public TreeItem getParentItem () { | |
1653 checkWidget (); | |
1654 return null; | |
1655 } | |
1656 | |
1657 GtkCellRendererPixbuf* getPixbufRenderer (GtkTreeViewColumn* column) { | |
1658 auto list = OS.gtk_tree_view_column_get_cell_renderers (column); | |
1659 if (list is null) return null; | |
1660 int count = OS.g_list_length (list); | |
1661 GtkCellRendererPixbuf* pixbufRenderer; | |
1662 int i = 0; | |
1663 while (i < count) { | |
1664 auto renderer = OS.g_list_nth_data (list, i); | |
1665 if (OS.GTK_IS_CELL_RENDERER_PIXBUF (renderer)) { | |
1666 pixbufRenderer = cast(GtkCellRendererPixbuf*)renderer; | |
1667 break; | |
1668 } | |
1669 i++; | |
1670 } | |
1671 OS.g_list_free (list); | |
1672 return pixbufRenderer; | |
1673 } | |
1674 | |
1675 /** | |
1676 * Returns an array of <code>TreeItem</code>s that are currently | |
1677 * selected in the receiver. The order of the items is unspecified. | |
1678 * An empty array indicates that no items are selected. | |
1679 * <p> | |
1680 * Note: This is not the actual structure used by the receiver | |
1681 * to maintain its selection, so modifying the array will | |
1682 * not affect the receiver. | |
1683 * </p> | |
1684 * @return an array representing the selection | |
1685 * | |
1686 * @exception DWTException <ul> | |
1687 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1688 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1689 * </ul> | |
1690 */ | |
1691 public TreeItem[] getSelection () { | |
1692 checkWidget(); | |
1693 auto selection = OS.gtk_tree_view_get_selection (handle); | |
1694 if (OS.GTK_VERSION < OS.buildVERSION (2, 2, 0)) { | |
1695 display.treeSelectionLength = 0; | |
1696 display.treeSelection = new int [items.length]; | |
1697 display.doTreeSelectionProcConnect( &treeSelectionCallbackData, handle, selection ); | |
1698 TreeItem [] result = new TreeItem [display.treeSelectionLength]; | |
1699 for (int i=0; i<result.length; i++) result [i] = items [display.treeSelection [i]]; | |
1700 return result; | |
1701 } | |
1702 /* | |
1703 * Bug in GTK. gtk_tree_selection_get_selected_rows() segmentation faults | |
1704 * in versions smaller than 2.2.4 if the model is NULL. The fix is | |
1705 * to give a valid pointer instead. | |
1706 */ | |
1707 int dummy; | |
1708 void* model = OS.GTK_VERSION < OS.buildVERSION (2, 2, 4) ? &dummy : null; | |
1709 auto list = OS.gtk_tree_selection_get_selected_rows (selection, &model); | |
1710 if (list !is null) { | |
1711 int count = OS.g_list_length (list); | |
1712 TreeItem [] treeSelection = new TreeItem [count]; | |
1713 int length_ = 0; | |
1714 for (int i=0; i<count; i++) { | |
1715 auto data = OS.g_list_nth_data (list, i); | |
1716 GtkTreeIter iter; | |
1717 if (OS.gtk_tree_model_get_iter (modelHandle, &iter, data)) { | |
1718 treeSelection [length_] = _getItem (&iter); | |
1719 length_++; | |
1720 } | |
1721 } | |
1722 OS.g_list_free (list); | |
1723 if (length_ < count) { | |
1724 TreeItem [] temp = new TreeItem [length_]; | |
1725 System.arraycopy(treeSelection, 0, temp, 0, length_); | |
1726 treeSelection = temp; | |
1727 } | |
1728 return treeSelection; | |
1729 } | |
1730 return null; | |
1731 } | |
1732 | |
1733 /** | |
1734 * Returns the number of selected items contained in the receiver. | |
1735 * | |
1736 * @return the number of selected items | |
1737 * | |
1738 * @exception DWTException <ul> | |
1739 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1740 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1741 * </ul> | |
1742 */ | |
1743 public int getSelectionCount () { | |
1744 checkWidget(); | |
1745 auto selection = OS.gtk_tree_view_get_selection (handle); | |
1746 if (OS.GTK_VERSION < OS.buildVERSION (2, 2, 0)) { | |
1747 display.treeSelectionLength = 0; | |
1748 display.treeSelection = null; | |
1749 display.doTreeSelectionProcConnect( &treeSelectionCallbackData, handle, selection ); | |
1750 return display.treeSelectionLength; | |
1751 } | |
1752 return OS.gtk_tree_selection_count_selected_rows (selection); | |
1753 } | |
1754 | |
1755 /** | |
1756 * Returns the column which shows the sort indicator for | |
1757 * the receiver. The value may be null if no column shows | |
1758 * the sort indicator. | |
1759 * | |
1760 * @return the sort indicator | |
1761 * | |
1762 * @exception DWTException <ul> | |
1763 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1764 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1765 * </ul> | |
1766 * | |
1767 * @see #setSortColumn(TreeColumn) | |
1768 * | |
1769 * @since 3.2 | |
1770 */ | |
1771 public TreeColumn getSortColumn () { | |
1772 checkWidget (); | |
1773 return sortColumn; | |
1774 } | |
1775 | |
1776 /** | |
1777 * Returns the direction of the sort indicator for the receiver. | |
1778 * The value will be one of <code>UP</code>, <code>DOWN</code> | |
1779 * or <code>NONE</code>. | |
1780 * | |
1781 * @return the sort direction | |
1782 * | |
1783 * @exception DWTException <ul> | |
1784 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1785 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1786 * </ul> | |
1787 * | |
1788 * @see #setSortDirection(int) | |
1789 * | |
1790 * @since 3.2 | |
1791 */ | |
1792 public int getSortDirection () { | |
1793 checkWidget (); | |
1794 return sortDirection; | |
1795 } | |
1796 | |
1797 GtkCellRendererText* getTextRenderer (GtkTreeViewColumn* column) { | |
1798 auto list = OS.gtk_tree_view_column_get_cell_renderers (column); | |
1799 if (list is null) return null; | |
1800 int count = OS.g_list_length (list); | |
1801 GtkCellRendererText* textRenderer; | |
1802 int i = 0; | |
1803 while (i < count) { | |
1804 auto renderer = OS.g_list_nth_data (list, i); | |
1805 if (OS.GTK_IS_CELL_RENDERER_TEXT (renderer)) { | |
1806 textRenderer = cast(GtkCellRendererText*)renderer; | |
1807 break; | |
1808 } | |
1809 i++; | |
1810 } | |
1811 OS.g_list_free (list); | |
1812 return textRenderer; | |
1813 } | |
1814 | |
1815 /** | |
1816 * Returns the item which is currently at the top of the receiver. | |
1817 * This item can change when items are expanded, collapsed, scrolled | |
1818 * or new items are added or removed. | |
1819 * | |
1820 * @return the item at the top of the receiver | |
1821 * | |
1822 * @exception DWTException <ul> | |
1823 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1824 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1825 * </ul> | |
1826 * | |
1827 * @since 2.1 | |
1828 */ | |
1829 public TreeItem getTopItem () { | |
1830 checkWidget (); | |
1831 void* path; | |
1832 OS.gtk_widget_realize (handle); | |
1833 if (!OS.gtk_tree_view_get_path_at_pos (handle, 1, 1, &path, null, null, null)) return null; | |
1834 if (path is null) return null; | |
1835 TreeItem item = null; | |
1836 GtkTreeIter iter; | |
1837 if (OS.gtk_tree_model_get_iter (modelHandle, &iter, path )) { | |
1838 item = _getItem (&iter); | |
1839 } | |
1840 OS.gtk_tree_path_free (path ); | |
1841 return item; | |
1842 } | |
1843 | |
1844 override int gtk_button_press_event (GtkWidget* widget, GdkEventButton* gdkEvent) { | |
1845 if (gdkEvent.window !is OS.gtk_tree_view_get_bin_window (handle)) return 0; | |
1846 auto result = super.gtk_button_press_event (widget, gdkEvent); | |
1847 if (result !is 0) return result; | |
1848 /* | |
1849 * Feature in GTK. In a multi-select tree view, when multiple items are already | |
1850 * selected, the selection state of the item is toggled and the previous selection | |
1851 * is cleared. This is not the desired behaviour when bringing up a popup menu. | |
1852 * Also, when an item is reselected with the right button, the tree view issues | |
1853 * an unwanted selection event. The workaround is to detect that case and not | |
1854 * run the default handler when the item is already part of the current selection. | |
1855 */ | |
1856 int button = gdkEvent.button; | |
1857 if (button is 3 && gdkEvent.type is OS.GDK_BUTTON_PRESS) { | |
1858 void* path; | |
1859 if (OS.gtk_tree_view_get_path_at_pos (handle, cast(int)gdkEvent.x, cast(int)gdkEvent.y, &path, null, null, null)) { | |
1860 if (path !is null) { | |
1861 auto selection = OS.gtk_tree_view_get_selection (handle); | |
1862 if (OS.gtk_tree_selection_path_is_selected (selection, path )) result = 1; | |
1863 OS.gtk_tree_path_free (path ); | |
1864 } | |
1865 } | |
1866 } | |
1867 | |
1868 /* | |
1869 * Feature in GTK. When the user clicks in a single selection GtkTreeView | |
1870 * and there are no selected items, the first item is selected automatically | |
1871 * before the click is processed, causing two selection events. The is fix | |
1872 * is the set the cursor item to be same as the clicked item to stop the | |
1873 * widget from automatically selecting the first item. | |
1874 */ | |
1875 if ((style & DWT.SINGLE) !is 0 && getSelectionCount () is 0) { | |
1876 void* path; | |
1877 if (OS.gtk_tree_view_get_path_at_pos (handle, cast(int)gdkEvent.x, cast(int)gdkEvent.y, &path, null, null, null)) { | |
1878 if (path !is null) { | |
1879 auto selection = OS.gtk_tree_view_get_selection (handle); | |
1880 OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udCHANGED); | |
1881 OS.gtk_tree_view_set_cursor (handle, path , null, false); | |
1882 OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udCHANGED); | |
1883 OS.gtk_tree_path_free (path ); | |
1884 } | |
1885 } | |
1886 } | |
1887 /* | |
1888 * Bug in GTK. GTK segments fault, if the GtkTreeView widget is | |
1889 * not in focus and all items in the widget are disposed before | |
1890 * it finishes processing a button press. The fix is to give | |
1891 * focus to the widget before it starts processing the event. | |
1892 */ | |
1893 if (!OS.GTK_WIDGET_HAS_FOCUS (handle)) { | |
1894 OS.gtk_widget_grab_focus (handle); | |
1895 } | |
1896 return result; | |
1897 } | |
1898 | |
1899 override int gtk_button_release_event (GtkWidget* widget, GdkEventButton* event) { | |
1900 auto window = OS.GDK_EVENT_WINDOW (event); | |
1901 if (window !is OS.gtk_tree_view_get_bin_window (handle)) return 0; | |
1902 return super.gtk_button_release_event (widget, event); | |
1903 } | |
1904 | |
1905 override int gtk_changed (GtkWidget* widget) { | |
1906 TreeItem item = getFocusItem (); | |
1907 if (item !is null) { | |
1908 Event event = new Event (); | |
1909 event.item = item; | |
1910 postEvent (DWT.Selection, event); | |
1911 } | |
1912 return 0; | |
1913 } | |
1914 | |
1915 override int gtk_expand_collapse_cursor_row (GtkWidget* widget, int /*long*/ logical, int /*long*/ expand, int /*long*/ open_all) { | |
1916 // FIXME - this flag is never cleared. It should be cleared when the expand all operation completes. | |
1917 if (expand !is 0 && open_all !is 0) expandAll = true; | |
1918 return 0; | |
1919 } | |
1920 | |
1921 override int gtk_key_press_event (GtkWidget* widget, GdkEventKey* keyEvent) { | |
1922 auto result = super.gtk_key_press_event (widget, keyEvent); | |
1923 if (result !is 0) return result; | |
1924 if (OS.GTK_VERSION < OS.buildVERSION (2, 2 ,0)) { | |
1925 /* | |
1926 * Feature in GTK 2.0.x. When an item is default selected using | |
1927 * the return key, GTK does not issue notification. The fix is | |
1928 * to issue this notification when the return key is pressed. | |
1929 */ | |
1930 int key = keyEvent.keyval; | |
1931 switch (key) { | |
1932 case OS.GDK_Return: | |
1933 case OS.GDK_KP_Enter: { | |
1934 Event event = new Event (); | |
1935 event.item = getFocusItem (); | |
1936 postEvent (DWT.DefaultSelection, event); | |
1937 break; | |
1938 } | |
115
52b32f5cb1e0
many file checked for switch default
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
1939 default: |
90 | 1940 } |
1941 } | |
1942 return result; | |
1943 } | |
1944 | |
1945 override int gtk_motion_notify_event (GtkWidget* widget, GdkEventMotion* event) { | |
1946 auto window = OS.GDK_EVENT_WINDOW (event); | |
1947 if (window !is OS.gtk_tree_view_get_bin_window (handle)) return 0; | |
1948 return super.gtk_motion_notify_event (widget, event); | |
1949 } | |
1950 | |
1951 override int gtk_popup_menu (GtkWidget* widget) { | |
1952 auto result = super.gtk_popup_menu (widget); | |
1953 /* | |
1954 * Bug in GTK. The context menu for the typeahead in GtkTreeViewer | |
1955 * opens in the bottom right corner of the screen when Shift+F10 | |
1956 * is pressed and the typeahead window was not visible. The fix is | |
1957 * to prevent the context menu from opening by stopping the default | |
1958 * handler. | |
1959 * | |
1960 * NOTE: The bug only happens in GTK 2.6.5 and lower. | |
1961 */ | |
1962 return OS.GTK_VERSION < OS.buildVERSION (2, 6, 5) ? 1 : result; | |
1963 } | |
1964 | |
1965 override void gtk_row_activated (GtkTreeView* tree, GtkTreePath* path, GtkTreeViewColumn* column) { | |
1966 if (path is null) return 0; | |
1967 TreeItem item = null; | |
1968 GtkTreeIter iter; | |
1969 if (OS.gtk_tree_model_get_iter (modelHandle, &iter, path)) { | |
1970 int index; | |
1971 OS.gtk_tree_model_get1 (modelHandle, &iter, ID_COLUMN, cast(void**)&index); | |
1972 item = items [index ]; | |
1973 } | |
1974 Event event = new Event (); | |
1975 event.item = item; | |
1976 postEvent (DWT.DefaultSelection, event); | |
1977 return 0; | |
1978 } | |
1979 | |
1980 override int gtk_test_collapse_row ( | |
1981 GtkTreeView *tree, | |
1982 GtkTreeIter *iter, | |
1983 GtkTreePath *path) | |
1984 { | |
1985 int index ; | |
1986 OS.gtk_tree_model_get1 (modelHandle, iter, ID_COLUMN, cast(void**)&index); | |
1987 TreeItem item = items [index ]; | |
1988 Event event = new Event (); | |
1989 event.item = item; | |
1990 bool oldModelChanged = modelChanged; | |
1991 modelChanged = false; | |
1992 sendEvent (DWT.Collapse, event); | |
1993 /* | |
1994 * Bug in GTK. Collapsing the target row during the test_collapse_row | |
1995 * handler will cause a segmentation fault if the animation code is allowed | |
1996 * to run. The fix is to block the animation if the row is already | |
1997 * collapsed. | |
1998 */ | |
1999 bool changed = modelChanged || !OS.gtk_tree_view_row_expanded (handle, path); | |
2000 modelChanged = oldModelChanged; | |
2001 if (isDisposed () || item.isDisposed ()) return 1; | |
2002 /* | |
2003 * Bug in GTK. Expanding or collapsing a row which has no more | |
2004 * children causes the model state to become invalid, causing | |
2005 * GTK to give warnings and behave strangely. Other changes to | |
2006 * the model can cause expansion to fail when using the multiple | |
2007 * expansion keys (such as *). The fix is to stop the expansion | |
2008 * if there are model changes. | |
2009 * | |
2010 * Note: This callback must return 0 for the collapsing | |
2011 * animation to occur. | |
2012 */ | |
2013 if (changed) { | |
2014 OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udTEST_COLLAPSE_ROW); | |
2015 OS.gtk_tree_view_collapse_row (handle, path); | |
2016 OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udTEST_COLLAPSE_ROW); | |
2017 return 1; | |
2018 } | |
2019 return 0; | |
2020 } | |
2021 | |
2022 override int gtk_test_expand_row ( | |
2023 GtkTreeView *tree, | |
2024 GtkTreeIter *iter, | |
2025 GtkTreePath *path) | |
2026 { | |
2027 int index ; | |
2028 OS.gtk_tree_model_get1 (modelHandle, iter, ID_COLUMN, cast(void**)&index); | |
2029 TreeItem item = items [index ]; | |
2030 Event event = new Event (); | |
2031 event.item = item; | |
2032 bool oldModelChanged = modelChanged; | |
2033 modelChanged = false; | |
2034 sendEvent (DWT.Expand, event); | |
2035 /* | |
2036 * Bug in GTK. Expanding the target row during the test_expand_row | |
2037 * handler will cause a segmentation fault if the animation code is allowed | |
2038 * to run. The fix is to block the animation if the row is already | |
2039 * expanded. | |
2040 */ | |
2041 bool changed = modelChanged || OS.gtk_tree_view_row_expanded (handle, path); | |
2042 modelChanged = oldModelChanged; | |
2043 if (isDisposed () || item.isDisposed ()) return 1; | |
2044 /* | |
2045 * Bug in GTK. Expanding or collapsing a row which has no more | |
2046 * children causes the model state to become invalid, causing | |
2047 * GTK to give warnings and behave strangely. Other changes to | |
2048 * the model can cause expansion to fail when using the multiple | |
2049 * expansion keys (such as *). The fix is to stop the expansion | |
2050 * if there are model changes. | |
2051 * | |
2052 * Bug in GTK. test-expand-row does not get called for each row | |
2053 * in an expand all operation. The fix is to block the initial | |
2054 * expansion and only expand a single level. | |
2055 * | |
2056 * Note: This callback must return 0 for the collapsing | |
2057 * animation to occur. | |
2058 */ | |
2059 if (changed || expandAll) { | |
2060 OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udTEST_EXPAND_ROW); | |
2061 OS.gtk_tree_view_expand_row (handle, path, false); | |
2062 OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udTEST_EXPAND_ROW); | |
2063 return 1; | |
2064 } | |
2065 return 0; | |
2066 } | |
2067 | |
2068 override int gtk_toggled (int /*long*/ renderer, char* pathStr) { | |
2069 auto path = OS.gtk_tree_path_new_from_string (pathStr); | |
2070 if (path is null) return 0; | |
2071 TreeItem item = null; | |
2072 GtkTreeIter iter; | |
2073 if (OS.gtk_tree_model_get_iter (modelHandle, &iter, path)) { | |
2074 item = _getItem (&iter); | |
2075 } | |
2076 OS.gtk_tree_path_free (path); | |
2077 if (item !is null) { | |
2078 item.setChecked (!item.getChecked ()); | |
2079 Event event = new Event (); | |
2080 event.detail = DWT.CHECK; | |
2081 event.item = item; | |
2082 postEvent (DWT.Selection, event); | |
2083 } | |
2084 return 0; | |
2085 } | |
2086 | |
2087 override void gtk_widget_size_request (GtkWidget* widget, GtkRequisition* requisition) { | |
2088 /* | |
2089 * Bug in GTK. For some reason, gtk_widget_size_request() fails | |
2090 * to include the height of the tree view items when there are | |
2091 * no columns visible. The fix is to temporarily make one column | |
2092 * visible. | |
2093 */ | |
2094 if (columnCount is 0) { | |
2095 super.gtk_widget_size_request (widget, requisition); | |
2096 return; | |
2097 } | |
2098 auto columns = OS.gtk_tree_view_get_columns (handle), list = columns; | |
2099 bool fixVisible = columns !is null; | |
2100 while (list !is null) { | |
2101 auto column = OS.g_list_data (list); | |
2102 if (OS.gtk_tree_view_column_get_visible (column)) { | |
2103 fixVisible = false; | |
2104 break; | |
2105 } | |
2106 list = OS.g_list_next (list); | |
2107 } | |
2108 GtkTreeViewColumn* columnHandle; | |
2109 if (fixVisible) { | |
2110 columnHandle = cast(GtkTreeViewColumn*)OS.g_list_data (columns); | |
2111 OS.gtk_tree_view_column_set_visible (columnHandle, true); | |
2112 } | |
2113 super.gtk_widget_size_request (widget, requisition); | |
2114 if (fixVisible) { | |
2115 OS.gtk_tree_view_column_set_visible (columnHandle, false); | |
2116 } | |
2117 if (columns !is null) OS.g_list_free (columns); | |
2118 } | |
2119 | |
2120 void hideFirstColumn () { | |
2121 auto firstColumn = OS.gtk_tree_view_get_column (handle, 0); | |
2122 OS.gtk_tree_view_column_set_visible (firstColumn, false); | |
2123 } | |
2124 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
2125 override void hookEvents () { |
90 | 2126 super.hookEvents (); |
2127 auto selection = OS.gtk_tree_view_get_selection(handle); | |
2128 OS.g_signal_connect_closure (selection, OS.changed.ptr, display.closures [CHANGED], false); | |
2129 OS.g_signal_connect_closure (handle, OS.row_activated.ptr, display.closures [ROW_ACTIVATED], false); | |
2130 OS.g_signal_connect_closure (handle, OS.test_expand_row.ptr, display.closures [TEST_EXPAND_ROW], false); | |
2131 OS.g_signal_connect_closure (handle, OS.test_collapse_row.ptr, display.closures [TEST_COLLAPSE_ROW], false); | |
2132 OS.g_signal_connect_closure (handle, OS.expand_collapse_cursor_row.ptr, display.closures [EXPAND_COLLAPSE_CURSOR_ROW], false); | |
2133 if (checkRenderer !is null) { | |
2134 OS.g_signal_connect_closure (checkRenderer, OS.toggled.ptr, display.closures [TOGGLED], false); | |
2135 } | |
2136 } | |
2137 | |
2138 /** | |
2139 * Searches the receiver's list starting at the first column | |
2140 * (index 0) until a column is found that is equal to the | |
2141 * argument, and returns the index of that column. If no column | |
2142 * is found, returns -1. | |
2143 * | |
2144 * @param column the search column | |
2145 * @return the index of the column | |
2146 * | |
2147 * @exception IllegalArgumentException <ul> | |
2148 * <li>ERROR_NULL_ARGUMENT - if the column is null</li> | |
2149 * </ul> | |
2150 * @exception DWTException <ul> | |
2151 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
2152 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2153 * </ul> | |
2154 * | |
2155 * @since 3.1 | |
2156 */ | |
2157 public int indexOf (TreeColumn column) { | |
2158 checkWidget(); | |
2159 if (column is null) error (DWT.ERROR_NULL_ARGUMENT); | |
2160 for (int i=0; i<columnCount; i++) { | |
2161 if (columns [i] is column) return i; | |
2162 } | |
2163 return -1; | |
2164 } | |
2165 | |
2166 /** | |
2167 * Searches the receiver's list starting at the first item | |
2168 * (index 0) until an item is found that is equal to the | |
2169 * argument, and returns the index of that item. If no item | |
2170 * is found, returns -1. | |
2171 * | |
2172 * @param item the search item | |
2173 * @return the index of the item | |
2174 * | |
2175 * @exception IllegalArgumentException <ul> | |
2176 * <li>ERROR_NULL_ARGUMENT - if the item is null</li> | |
2177 * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li> | |
2178 * </ul> | |
2179 * @exception DWTException <ul> | |
2180 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
2181 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2182 * </ul> | |
2183 * | |
2184 * @since 3.1 | |
2185 */ | |
2186 public int indexOf (TreeItem item) { | |
2187 checkWidget(); | |
2188 if (item is null) error (DWT.ERROR_NULL_ARGUMENT); | |
2189 if (item.isDisposed()) error (DWT.ERROR_INVALID_ARGUMENT); | |
2190 int index = -1; | |
2191 auto path = OS.gtk_tree_model_get_path (modelHandle, item.handle); | |
2192 int depth = OS.gtk_tree_path_get_depth (path); | |
2193 if (depth is 1) { | |
2194 auto indices = OS.gtk_tree_path_get_indices (path); | |
2195 if (indices !is null) { | |
2196 index = indices[0]; | |
2197 } | |
2198 } | |
2199 OS.gtk_tree_path_free (path); | |
2200 return index; | |
2201 } | |
2202 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
2203 override bool mnemonicHit (wchar key) { |
90 | 2204 for (int i=0; i<columnCount; i++) { |
2205 auto labelHandle = columns [i].labelHandle; | |
2206 if (labelHandle !is null && mnemonicHit (labelHandle, key)) return true; | |
2207 } | |
2208 return false; | |
2209 } | |
2210 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
2211 override bool mnemonicMatch (wchar key) { |
90 | 2212 for (int i=0; i<columnCount; i++) { |
2213 auto labelHandle = columns [i].labelHandle; | |
2214 if (labelHandle !is null && mnemonicMatch (labelHandle, key)) return true; | |
2215 } | |
2216 return false; | |
2217 } | |
2218 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
2219 override GdkDrawable* paintWindow () { |
90 | 2220 OS.gtk_widget_realize (handle); |
2221 return OS.gtk_tree_view_get_bin_window (handle); | |
2222 } | |
2223 | |
2224 void recreateRenderers () { | |
2225 if (checkRenderer !is null) { | |
2226 display.removeWidget (cast(GtkWidget*)checkRenderer); | |
2227 OS.g_object_unref (checkRenderer); | |
2228 checkRenderer = ownerDraw ? cast(GtkCellRenderer*)OS.g_object_new (display.gtk_cell_renderer_toggle_get_type(), null) : OS.gtk_cell_renderer_toggle_new (); | |
2229 if (checkRenderer is null) error (DWT.ERROR_NO_HANDLES); | |
2230 OS.g_object_ref (checkRenderer); | |
2231 display.addWidget (cast(GtkWidget*)checkRenderer, this); | |
2232 OS.g_signal_connect_closure (checkRenderer, OS.toggled.ptr, display.closures [TOGGLED], false); | |
2233 } | |
2234 if (columnCount is 0) { | |
2235 createRenderers (OS.gtk_tree_view_get_column (handle, 0), Tree.FIRST_COLUMN, true, 0); | |
2236 } else { | |
2237 for (int i = 0; i < columnCount; i++) { | |
2238 TreeColumn column = columns [i]; | |
2239 createRenderers (cast(GtkTreeViewColumn*)column.handle, column.modelIndex, i is 0, column.style); | |
2240 } | |
2241 } | |
2242 } | |
2243 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
2244 override void redrawBackgroundImage () { |
90 | 2245 Control control = findBackgroundControl (); |
2246 if (control !is null && control.backgroundImage !is null) { | |
2247 redrawWidget (0, 0, 0, 0, true, false, false); | |
2248 } | |
2249 } | |
2250 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
2251 override void register () { |
90 | 2252 super.register (); |
2253 display.addWidget (cast(GtkWidget*)OS.gtk_tree_view_get_selection (handle), this); | |
2254 if (checkRenderer !is null) display.addWidget (cast(GtkWidget*)checkRenderer, this); | |
2255 } | |
2256 | |
2257 void releaseItem (TreeItem item, bool release) { | |
2258 int index; | |
2259 OS.gtk_tree_model_get1 (modelHandle, item.handle, ID_COLUMN, cast(void**)&index); | |
2260 if (index is -1) return; | |
2261 if (release) item.release (false); | |
2262 items [index ] = null; | |
2263 } | |
2264 | |
2265 void releaseItems (GtkTreeIter* parentIter) { | |
2266 int index; | |
2267 GtkTreeIter iter; | |
2268 bool valid = cast(bool)OS.gtk_tree_model_iter_children (modelHandle, &iter, parentIter); | |
2269 while (valid) { | |
2270 releaseItems (&iter); | |
2271 if (!isDisposed ()) { | |
2272 OS.gtk_tree_model_get1 (modelHandle, &iter, ID_COLUMN, cast(void**)&index); | |
2273 if (index !is -1) { | |
2274 TreeItem item = items [index ]; | |
2275 if (item !is null) releaseItem (item, true); | |
2276 } | |
2277 } | |
2278 valid = cast(bool)OS.gtk_tree_model_iter_next (modelHandle, &iter); | |
2279 } | |
2280 } | |
2281 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
2282 override void releaseChildren (bool destroy) { |
90 | 2283 if (items !is null) { |
2284 for (int i=0; i<items.length; i++) { | |
2285 TreeItem item = items [i]; | |
2286 if (item !is null && !item.isDisposed ()) { | |
2287 item.release (false); | |
2288 } | |
2289 } | |
2290 items = null; | |
2291 } | |
2292 if (columns !is null) { | |
2293 for (int i=0; i<columnCount; i++) { | |
2294 TreeColumn column = columns [i]; | |
2295 if (column !is null && !column.isDisposed ()) { | |
2296 column.release (false); | |
2297 } | |
2298 } | |
2299 columns = null; | |
2300 } | |
2301 super.releaseChildren (destroy); | |
2302 } | |
2303 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
2304 override void releaseWidget () { |
90 | 2305 super.releaseWidget (); |
2306 if (modelHandle !is null) OS.g_object_unref (modelHandle); | |
2307 modelHandle = null; | |
2308 if (checkRenderer !is null) OS.g_object_unref (checkRenderer); | |
2309 checkRenderer = null; | |
2310 if (imageList !is null) imageList.dispose (); | |
2311 if (headerImageList !is null) headerImageList.dispose (); | |
2312 imageList = headerImageList = null; | |
2313 currentItem = null; | |
2314 } | |
2315 | |
2316 void remove (GtkTreeIter* parentIter, int start, int end) { | |
2317 if (start > end) return; | |
2318 int itemCount = OS.gtk_tree_model_iter_n_children (modelHandle, parentIter); | |
2319 if (!(0 <= start && start <= end && end < itemCount)) { | |
2320 error (DWT.ERROR_INVALID_RANGE); | |
2321 } | |
2322 auto selection = OS.gtk_tree_view_get_selection (handle); | |
2323 GtkTreeIter iter; | |
2324 int index = start; | |
2325 for (int i = start; i <= end; i++) { | |
2326 OS.gtk_tree_model_iter_nth_child (modelHandle, &iter, parentIter, index); | |
2327 int value; | |
2328 OS.gtk_tree_model_get1 (modelHandle, &iter, ID_COLUMN, cast(void**)&value); | |
2329 TreeItem item = value !is -1 ? items [value ] : null; | |
2330 if (item !is null && !item.isDisposed ()) { | |
2331 item.dispose (); | |
2332 } else { | |
2333 OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udCHANGED); | |
2334 OS.gtk_tree_store_remove (modelHandle, &iter); | |
2335 OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udCHANGED); | |
2336 } | |
2337 } | |
2338 } | |
2339 | |
2340 /** | |
2341 * Removes all of the items from the receiver. | |
2342 * | |
2343 * @exception DWTException <ul> | |
2344 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
2345 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2346 * </ul> | |
2347 */ | |
2348 public void removeAll () { | |
2349 checkWidget (); | |
2350 for (int i=0; i<items.length; i++) { | |
2351 TreeItem item = items [i]; | |
2352 if (item !is null && !item.isDisposed ()) item.release (false); | |
2353 } | |
2354 items = new TreeItem[4]; | |
2355 auto selection = OS.gtk_tree_view_get_selection (handle); | |
2356 OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udCHANGED); | |
240 | 2357 OS.gtk_tree_store_clear (modelHandle); |
90 | 2358 OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udCHANGED); |
2359 | |
2360 /* Disable searching when using VIRTUAL */ | |
2361 if ((style & DWT.VIRTUAL) !is 0) { | |
2362 /* | |
2363 * Bug in GTK. Until GTK 2.6.5, calling gtk_tree_view_set_enable_search(FALSE) | |
2364 * would prevent the user from being able to type in text to search the tree. | |
2365 * After 2.6.5, GTK introduced Ctrl+F as being the key binding for interactive | |
2366 * search. This meant that even if FALSE was passed to enable_search, the user | |
2367 * can still bring up the search pop up using the keybinding. GTK also introduced | |
2368 * the notion of passing a -1 to gtk_set_search_column to disable searching | |
2369 * (including the search key binding). The fix is to use the right calls | |
2370 * for the right version. | |
2371 */ | |
2372 if (OS.GTK_VERSION >= OS.buildVERSION (2, 6, 5)) { | |
2373 OS.gtk_tree_view_set_search_column (handle, -1); | |
2374 } else { | |
2375 OS.gtk_tree_view_set_enable_search (handle, false); | |
2376 } | |
2377 } else { | |
2378 /* Set the search column whenever the model changes */ | |
2379 int firstColumn = columnCount is 0 ? FIRST_COLUMN : columns [0].modelIndex; | |
2380 OS.gtk_tree_view_set_search_column (handle, firstColumn + CELL_TEXT); | |
2381 } | |
2382 } | |
2383 | |
2384 /** | |
2385 * Removes the listener from the collection of listeners who will | |
2386 * be notified when the user changes the receiver's selection. | |
2387 * | |
2388 * @param listener the listener which should no longer be notified | |
2389 * | |
2390 * @exception IllegalArgumentException <ul> | |
2391 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
2392 * </ul> | |
2393 * @exception DWTException <ul> | |
2394 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
2395 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2396 * </ul> | |
2397 * | |
2398 * @see SelectionListener | |
2399 * @see #addSelectionListener | |
2400 */ | |
2401 public void removeSelectionListener (SelectionListener listener) { | |
2402 checkWidget (); | |
2403 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT); | |
2404 eventTable.unhook (DWT.Selection, listener); | |
2405 eventTable.unhook (DWT.DefaultSelection, listener); | |
2406 } | |
2407 | |
2408 /** | |
2409 * Removes the listener from the collection of listeners who will | |
2410 * be notified when items in the receiver are expanded or collapsed. | |
2411 * | |
2412 * @param listener the listener which should no longer be notified | |
2413 * | |
2414 * @exception IllegalArgumentException <ul> | |
2415 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
2416 * </ul> | |
2417 * @exception DWTException <ul> | |
2418 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
2419 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2420 * </ul> | |
2421 * | |
2422 * @see TreeListener | |
2423 * @see #addTreeListener | |
2424 */ | |
2425 public void removeTreeListener(TreeListener listener) { | |
2426 checkWidget (); | |
2427 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT); | |
2428 if (eventTable is null) return; | |
2429 eventTable.unhook (DWT.Expand, listener); | |
2430 eventTable.unhook (DWT.Collapse, listener); | |
2431 } | |
2432 | |
2433 override void rendererGetSizeProc ( | |
2434 GtkCellRenderer *cell, | |
2435 GtkWidget *widget, | |
2436 GdkRectangle *cell_area, | |
2437 int *x_offset, | |
2438 int *y_offset, | |
2439 int *width, | |
2440 int *height) | |
2441 { | |
2442 auto g_class = OS.g_type_class_peek_parent (OS.G_OBJECT_GET_CLASS (cell)); | |
2443 GtkCellRendererClass* klass = cast(GtkCellRendererClass*)g_class; | |
2444 klass.get_size( cell, handle, cell_area, x_offset, y_offset, width, height); | |
2445 if (!ignoreSize && OS.GTK_IS_CELL_RENDERER_TEXT (cell)) { | |
2446 auto iter = cast(GtkTreeIter*)OS.g_object_get_qdata (cast(GObject*)cell, Display.SWT_OBJECT_INDEX2); | |
2447 TreeItem item = null; | |
2448 if (iter !is null) item = _getItem (iter); | |
2449 if (item !is null) { | |
2450 int columnIndex = 0; | |
2451 if (columnCount > 0) { | |
2452 auto columnHandle = cast(GtkTreeViewColumn*)OS.g_object_get_qdata (cast(GObject*)cell, Display.SWT_OBJECT_INDEX1); | |
2453 for (int i = 0; i < columnCount; i++) { | |
2454 if (columns [i].handle is cast(GtkWidget*)columnHandle) { | |
2455 columnIndex = i; | |
2456 break; | |
2457 } | |
2458 } | |
2459 } | |
2460 if (hooks (DWT.MeasureItem)) { | |
2461 int contentWidth, contentHeight; | |
2462 if (width !is null) contentWidth = *width; | |
2463 if (height !is null) contentHeight = *height; | |
2464 Image image = item.getImage (columnIndex); | |
2465 int imageWidth = 0; | |
2466 if (image !is null) { | |
2467 Rectangle bounds = image.getBounds (); | |
2468 imageWidth = bounds.width; | |
2469 } | |
2470 contentWidth += imageWidth; | |
2471 GC gc = new GC (this); | |
2472 gc.setFont (item.getFont (columnIndex)); | |
2473 Event event = new Event (); | |
2474 event.item = item; | |
2475 event.index = columnIndex; | |
2476 event.gc = gc; | |
2477 event.width = contentWidth ; | |
2478 event.height = contentHeight ; | |
2479 sendEvent (DWT.MeasureItem, event); | |
2480 gc.dispose (); | |
2481 contentWidth = event.width - imageWidth; | |
240 | 2482 if (contentHeight < event.height) contentHeight = event.height; |
90 | 2483 if (width !is null) *width = contentWidth; |
2484 if (height !is null) *height = contentHeight; | |
2485 } | |
2486 } | |
2487 } | |
2488 } | |
2489 | |
2490 override void rendererRenderProc ( | |
2491 GtkCellRenderer * cell, | |
2492 GdkDrawable * window, | |
2493 GtkWidget * widget, | |
2494 GdkRectangle *background_area, | |
2495 GdkRectangle *cell_area, | |
2496 GdkRectangle *expose_area, | |
2497 int flags) | |
2498 { | |
2499 TreeItem item = null; | |
2500 auto iter = cast(GtkTreeIter*)OS.g_object_get_qdata (cast(GObject*)cell, Display.SWT_OBJECT_INDEX2); | |
2501 if (iter !is null) item = _getItem (iter); | |
2502 auto columnHandle = cast(GtkTreeViewColumn*)OS.g_object_get_qdata (cast(GObject*)cell, Display.SWT_OBJECT_INDEX1); | |
2503 int columnIndex = 0; | |
2504 if (columnCount > 0) { | |
2505 for (int i = 0; i < columnCount; i++) { | |
2506 if (columns [i].handle is cast(GtkWidget*)columnHandle) { | |
2507 columnIndex = i; | |
2508 break; | |
2509 } | |
2510 } | |
2511 } | |
2512 if (item !is null) { | |
2513 if (OS.GTK_IS_CELL_RENDERER_TOGGLE (cell) || (OS.GTK_IS_CELL_RENDERER_PIXBUF (cell) && (columnIndex !is 0 || (style & DWT.CHECK) is 0))) { | |
2514 drawFlags = cast(int)/*64*/flags; | |
2515 drawState = DWT.FOREGROUND; | |
2516 void* ptr; | |
2517 OS.gtk_tree_model_get1 (modelHandle, item.handle, Tree.BACKGROUND_COLUMN, &ptr); | |
2518 if (ptr is null) { | |
2519 int modelIndex = columnCount is 0 ? Tree.FIRST_COLUMN : columns [columnIndex].modelIndex; | |
2520 OS.gtk_tree_model_get1 (modelHandle, item.handle, modelIndex + Tree.CELL_BACKGROUND, &ptr); | |
2521 } | |
2522 if (ptr !is null) drawState |= DWT.BACKGROUND; | |
2523 if ((flags & OS.GTK_CELL_RENDERER_SELECTED) !is 0) drawState |= DWT.SELECTED; | |
2524 if ((flags & OS.GTK_CELL_RENDERER_FOCUSED) !is 0) drawState |= DWT.FOCUSED; | |
2525 | |
2526 GdkRectangle rect; | |
2527 auto path = OS.gtk_tree_model_get_path (modelHandle, iter); | |
2528 OS.gtk_tree_view_get_background_area (handle, path, columnHandle, &rect); | |
2529 OS.gtk_tree_path_free (path); | |
2530 | |
2531 if ((drawState & DWT.SELECTED) is 0) { | |
2532 Control control = findBackgroundControl (); | |
2533 if (control !is null && control.backgroundImage !is null) { | |
2534 OS.gdk_window_clear_area (window, rect.x, rect.y, rect.width, rect.height); | |
2535 } | |
2536 } | |
2537 | |
2538 if (hooks (DWT.EraseItem)) { | |
2539 bool wasSelected = false; | |
2540 if ((drawState & DWT.SELECTED) !is 0) { | |
2541 wasSelected = true; | |
2542 OS.gdk_window_clear_area (window, rect.x, rect.y, rect.width, rect.height); | |
2543 } | |
2544 GC gc = new GC (this); | |
2545 if ((drawState & DWT.SELECTED) !is 0) { | |
2546 gc.setBackground (display.getSystemColor (DWT.COLOR_LIST_SELECTION)); | |
2547 gc.setForeground (display.getSystemColor (DWT.COLOR_LIST_SELECTION_TEXT)); | |
2548 } else { | |
2549 gc.setBackground (item.getBackground (columnIndex)); | |
2550 gc.setForeground (item.getForeground (columnIndex)); | |
2551 } | |
2552 gc.setFont (item.getFont (columnIndex)); | |
240 | 2553 if ((style & DWT.MIRRORED) !is 0) rect.x = getClientWidth () - rect.width - rect.x; |
90 | 2554 gc.setClipping (rect.x, rect.y, rect.width, rect.height); |
2555 Event event = new Event (); | |
2556 event.item = item; | |
2557 event.index = columnIndex; | |
2558 event.gc = gc; | |
2559 event.x = rect.x; | |
2560 event.y = rect.y; | |
2561 event.width = rect.width; | |
2562 event.height = rect.height; | |
2563 event.detail = drawState; | |
2564 sendEvent (DWT.EraseItem, event); | |
2565 drawForeground = null; | |
2566 drawState = event.doit ? event.detail : 0; | |
2567 drawFlags &= ~(OS.GTK_CELL_RENDERER_FOCUSED | OS.GTK_CELL_RENDERER_SELECTED); | |
2568 if ((drawState & DWT.SELECTED) !is 0) drawFlags |= OS.GTK_CELL_RENDERER_SELECTED; | |
2569 if ((drawState & DWT.FOCUSED) !is 0) drawFlags |= OS.GTK_CELL_RENDERER_FOCUSED; | |
2570 if ((drawState & DWT.SELECTED) !is 0) { | |
2571 auto style = OS.gtk_widget_get_style (widget); | |
2572 //TODO - parity and sorted | |
2573 OS.gtk_paint_flat_box (style, window, OS.GTK_STATE_SELECTED, OS.GTK_SHADOW_NONE, &rect, widget, "cell_odd".ptr, rect.x, rect.y, rect.width, rect.height); | |
2574 } else { | |
2575 if (wasSelected) drawForeground = gc.getForeground ().handle; | |
2576 } | |
2577 gc.dispose(); | |
2578 } | |
2579 } | |
2580 } | |
2581 int /*long*/ result = 0; | |
2582 if ((drawState & DWT.BACKGROUND) !is 0 && (drawState & DWT.SELECTED) is 0) { | |
2583 GC gc = new GC (this); | |
2584 gc.setBackground (item.getBackground (columnIndex)); | |
2585 gc.fillRectangle (background_area.x, background_area.y, background_area.width, background_area.height); | |
2586 gc.dispose (); | |
2587 } | |
2588 if ((drawState & DWT.FOREGROUND) !is 0 || OS.GTK_IS_CELL_RENDERER_TOGGLE (cell)) { | |
2589 auto g_class = OS.g_type_class_peek_parent (OS.G_OBJECT_GET_CLASS (cell)); | |
2590 GtkCellRendererClass* klass = cast(GtkCellRendererClass*)g_class; | |
2591 if (drawForeground !is null && OS.GTK_IS_CELL_RENDERER_TEXT (cell)) { | |
2592 OS.g_object_set1 (cell, OS.foreground_gdk.ptr, cast(int)drawForeground); | |
2593 } | |
2594 klass.render( cell, window, handle, background_area, cell_area, expose_area, drawFlags); | |
2595 } | |
2596 if (item !is null) { | |
2597 if (OS.GTK_IS_CELL_RENDERER_TEXT (cell)) { | |
2598 if (hooks (DWT.PaintItem)) { | |
2599 GdkRectangle rect; | |
2600 auto path = OS.gtk_tree_model_get_path (modelHandle, iter); | |
2601 OS.gtk_tree_view_get_cell_area (handle, path, columnHandle, &rect); | |
2602 OS.gtk_tree_path_free (path); | |
2603 if (OS.GTK_VERSION < OS.buildVERSION (2, 8, 18) && OS.gtk_tree_view_get_expander_column (handle) is columnHandle) { | |
2604 int buffer; | |
2605 OS.gtk_widget_style_get1 (handle, OS.expander_size.ptr, &buffer); | |
2606 rect.x += buffer + TreeItem.EXPANDER_EXTRA_PADDING; | |
2607 rect.width -= buffer + TreeItem.EXPANDER_EXTRA_PADDING; | |
2608 //OS.gtk_widget_style_get (handle, OS.horizontal_separator, buffer, 0); | |
2609 //rect.x += buffer[0]; | |
2610 //rect.width -= buffer [0]; // TODO Is this required for some versions? | |
2611 } | |
2612 ignoreSize = true; | |
2613 int contentX, contentWidth; | |
2614 OS.gtk_cell_renderer_get_size (cell, handle, null, null, null, &contentWidth, null); | |
2615 OS.gtk_tree_view_column_cell_get_position (columnHandle, cell, &contentX, null); | |
2616 ignoreSize = false; | |
2617 Image image = item.getImage (columnIndex); | |
2618 int imageWidth = 0; | |
2619 if (image !is null) { | |
2620 Rectangle bounds = image.getBounds (); | |
2621 imageWidth = bounds.width; | |
2622 } | |
2623 contentX -= imageWidth; | |
2624 contentWidth += imageWidth; | |
2625 GC gc = new GC (this); | |
2626 if ((drawState & DWT.SELECTED) !is 0) { | |
2627 gc.setBackground (display.getSystemColor (DWT.COLOR_LIST_SELECTION)); | |
2628 gc.setForeground (display.getSystemColor (DWT.COLOR_LIST_SELECTION_TEXT)); | |
2629 } else { | |
2630 gc.setBackground (item.getBackground (columnIndex)); | |
2631 Color foreground = drawForeground !is null ? Color.gtk_new (display, drawForeground) : item.getForeground (columnIndex); | |
2632 gc.setForeground (foreground); | |
2633 } | |
2634 gc.setFont (item.getFont (columnIndex)); | |
240 | 2635 if ((style & DWT.MIRRORED) !is 0) rect.x = getClientWidth () - rect.width - rect.x; |
90 | 2636 gc.setClipping (rect.x, rect.y, rect.width, rect.height); |
2637 Event event = new Event (); | |
2638 event.item = item; | |
2639 event.index = columnIndex; | |
2640 event.gc = gc; | |
2641 event.x = rect.x + contentX; | |
2642 event.y = rect.y; | |
2643 event.width = contentWidth; | |
2644 event.height = rect.height; | |
2645 event.detail = drawState; | |
2646 sendEvent (DWT.PaintItem, event); | |
2647 gc.dispose(); | |
2648 } | |
2649 } | |
2650 } | |
2651 return result; | |
2652 } | |
2653 | |
2654 void resetCustomDraw () { | |
2655 if ((style & DWT.VIRTUAL) !is 0 || ownerDraw) return; | |
2656 int end = Math.max (1, columnCount); | |
2657 for (int i=0; i<end; i++) { | |
2658 bool customDraw = columnCount !is 0 ? columns [i].customDraw : firstCustomDraw; | |
2659 if (customDraw) { | |
2660 auto column = OS.gtk_tree_view_get_column (handle, i); | |
2661 auto textRenderer = getTextRenderer (column); | |
2662 OS.gtk_tree_view_column_set_cell_data_func (column, textRenderer, null, null, null); | |
2663 if (columnCount !is 0) columns [i].customDraw = false; | |
2664 } | |
2665 } | |
2666 firstCustomDraw = false; | |
2667 } | |
2668 | |
2669 /** | |
2670 * Display a mark indicating the point at which an item will be inserted. | |
2671 * The drop insert item has a visual hint to show where a dragged item | |
2672 * will be inserted when dropped on the tree. | |
2673 * | |
2674 * @param item the insert item. Null will clear the insertion mark. | |
2675 * @param before true places the insert mark above 'item'. false places | |
2676 * the insert mark below 'item'. | |
2677 * | |
2678 * @exception IllegalArgumentException <ul> | |
2679 * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li> | |
2680 * </ul> | |
2681 * @exception DWTException <ul> | |
2682 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
2683 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2684 * </ul> | |
2685 */ | |
2686 public void setInsertMark (TreeItem item, bool before) { | |
2687 checkWidget (); | |
2688 if (item is null) { | |
240 | 2689 OS.gtk_tree_view_set_drag_dest_row(handle, null, OS.GTK_TREE_VIEW_DROP_BEFORE); |
90 | 2690 return; |
2691 } | |
2692 if (item.isDisposed()) error (DWT.ERROR_INVALID_ARGUMENT); | |
2693 if (item.parent !is this) return; | |
2694 Rectangle rect = item.getBounds(); | |
2695 void* path; | |
2696 OS.gtk_widget_realize (handle); | |
2697 if (!OS.gtk_tree_view_get_path_at_pos(handle, rect.x, rect.y, &path, null, null, null)) return; | |
2698 if (path is null) return; | |
2699 int position = before ? OS.GTK_TREE_VIEW_DROP_BEFORE : OS.GTK_TREE_VIEW_DROP_AFTER; | |
2700 OS.gtk_tree_view_set_drag_dest_row(handle, path, position); | |
2701 OS.gtk_tree_path_free (path ); | |
2702 } | |
2703 | |
2704 void setItemCount (GtkTreeIter* parentIter, int count) { | |
2705 int itemCount = OS.gtk_tree_model_iter_n_children (modelHandle, parentIter); | |
2706 if (count is itemCount) return; | |
2707 bool isVirtual = (style & DWT.VIRTUAL) !is 0; | |
2708 if (!isVirtual) setRedraw (false); | |
2709 remove (parentIter, count, itemCount - 1); | |
2710 if (isVirtual) { | |
2711 for (int i=itemCount; i<count; i++) { | |
2712 GtkTreeIter iter; | |
2713 OS.gtk_tree_store_append (modelHandle, &iter, parentIter); | |
2714 OS.gtk_tree_store_set1 (modelHandle, &iter, ID_COLUMN, cast(void*)-1); | |
2715 } | |
2716 } else { | |
2717 for (int i=itemCount; i<count; i++) { | |
2718 new TreeItem (this, parentIter, DWT.NONE, i, true); | |
2719 } | |
2720 } | |
2721 if (!isVirtual) setRedraw (true); | |
2722 modelChanged = true; | |
2723 } | |
2724 | |
2725 /** | |
2726 * Sets the number of root-level items contained in the receiver. | |
2727 * | |
2728 * @param count the number of items | |
2729 * | |
2730 * @exception DWTException <ul> | |
2731 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
2732 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2733 * </ul> | |
2734 * | |
2735 * @since 3.2 | |
2736 */ | |
2737 public void setItemCount (int count) { | |
2738 checkWidget (); | |
2739 count = Math.max (0, count); | |
2740 setItemCount (null, count); | |
2741 } | |
240 | 2742 |
2743 public void select (TreeItem item) { | |
2744 checkWidget (); | |
2745 if (item is null) error (DWT.ERROR_NULL_ARGUMENT); | |
2746 if (item.isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT); | |
2747 bool fixColumn = showFirstColumn (); | |
2748 auto selection = OS.gtk_tree_view_get_selection (handle); | |
2749 OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udCHANGED); | |
2750 OS.gtk_tree_selection_select_iter (selection, item.handle); | |
2751 OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udCHANGED); | |
2752 if (fixColumn) hideFirstColumn (); | |
2753 } | |
2754 | |
90 | 2755 /** |
2756 * Selects all of the items in the receiver. | |
2757 * <p> | |
2758 * If the receiver is single-select, do nothing. | |
2759 * </p> | |
2760 * | |
2761 * @exception DWTException <ul> | |
2762 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
2763 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2764 * </ul> | |
2765 */ | |
2766 public void selectAll () { | |
2767 checkWidget(); | |
2768 if ((style & DWT.SINGLE) !is 0) return; | |
2769 bool fixColumn = showFirstColumn (); | |
2770 auto selection = OS.gtk_tree_view_get_selection (handle); | |
2771 OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udCHANGED); | |
2772 OS.gtk_tree_selection_select_all (selection); | |
2773 OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udCHANGED); | |
2774 if (fixColumn) hideFirstColumn (); | |
2775 } | |
2776 | |
2777 override void setBackgroundColor (GdkColor* color) { | |
2778 super.setBackgroundColor (color); | |
2779 OS.gtk_widget_modify_base (handle, 0, color); | |
2780 } | |
2781 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
2782 override void setBackgroundPixmap (GdkPixmap* pixmap) { |
90 | 2783 super.setBackgroundPixmap (pixmap); |
2784 auto window = paintWindow (); | |
2785 if (window !is null) OS.gdk_window_set_back_pixmap (window, null, true); | |
2786 } | |
2787 | |
2788 override int setBounds (int x, int y, int width, int height, bool move, bool resize) { | |
2789 int result = super.setBounds (x, y, width, height, move, resize); | |
2790 /* | |
2791 * Bug on GTK. The tree view sometimes does not get a paint | |
2792 * event or resizes to a one pixel square when resized in a new | |
2793 * shell that is not visible after any event loop has been run. The | |
2794 * problem is intermittent. It doesn't seem to happen the first time | |
2795 * a new shell is created. The fix is to ensure the tree view is realized | |
2796 * after it has been resized. | |
2797 */ | |
2798 OS.gtk_widget_realize (handle); | |
2799 /* | |
2800 * Bug in GTK. An empty GtkTreeView fails to repaint the focus rectangle | |
2801 * correctly when resized on versions before 2.6.0. The fix is to force | |
2802 * the widget to redraw. | |
2803 */ | |
2804 if (OS.GTK_VERSION < OS.buildVERSION (2, 6, 0) && OS.gtk_tree_model_iter_n_children (modelHandle, null) is 0) { | |
2805 redraw (false); | |
2806 } | |
2807 return result; | |
2808 } | |
2809 | |
2810 /** | |
2811 * Sets the order that the items in the receiver should | |
2812 * be displayed in to the given argument which is described | |
2813 * in terms of the zero-relative ordering of when the items | |
2814 * were added. | |
2815 * | |
2816 * @param order the new order to display the items | |
2817 * | |
2818 * @exception DWTException <ul> | |
2819 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
2820 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2821 * </ul> | |
2822 * @exception IllegalArgumentException <ul> | |
2823 * <li>ERROR_INVALID_ARGUMENT - if the item order is not the same length as the number of items</li> | |
2824 * </ul> | |
2825 * | |
2826 * @see Tree#getColumnOrder() | |
2827 * @see TreeColumn#getMoveable() | |
2828 * @see TreeColumn#setMoveable(bool) | |
2829 * @see DWT#Move | |
2830 * | |
2831 * @since 3.2 | |
2832 */ | |
2833 public void setColumnOrder (int [] order) { | |
2834 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
|
2835 // 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
|
2836 //if (order is null) error (DWT.ERROR_NULL_ARGUMENT); |
90 | 2837 if (columnCount is 0) { |
2838 if (order.length > 0) error (DWT.ERROR_INVALID_ARGUMENT); | |
2839 return; | |
2840 } | |
2841 if (order.length !is columnCount) error (DWT.ERROR_INVALID_ARGUMENT); | |
2842 bool [] seen = new bool [columnCount]; | |
2843 for (int i = 0; i<order.length; i++) { | |
2844 int index = order [i]; | |
2845 if (index < 0 || index >= columnCount) error (DWT.ERROR_INVALID_RANGE); | |
2846 if (seen [index]) error (DWT.ERROR_INVALID_ARGUMENT); | |
2847 seen [index] = true; | |
2848 } | |
2849 void* baseColumn; | |
2850 for (int i=0; i<order.length; i++) { | |
2851 auto column = columns [order [i]].handle; | |
2852 OS.gtk_tree_view_move_column_after (handle, column, baseColumn); | |
2853 baseColumn = column; | |
2854 } | |
2855 } | |
2856 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
2857 override void setFontDescription (PangoFontDescription* font) { |
90 | 2858 super.setFontDescription (font); |
2859 TreeColumn[] columns = getColumns (); | |
2860 for (int i = 0; i < columns.length; i++) { | |
2861 if (columns[i] !is null) { | |
2862 columns[i].setFontDescription (font); | |
2863 } | |
2864 } | |
2865 } | |
2866 | |
2867 /** | |
2868 * Marks the receiver's header as visible if the argument is <code>true</code>, | |
2869 * and marks it invisible otherwise. | |
2870 * <p> | |
2871 * If one of the receiver's ancestors is not visible or some | |
2872 * other condition makes the receiver not visible, marking | |
2873 * it visible may not actually cause it to be displayed. | |
2874 * </p> | |
2875 * | |
2876 * @param show the new visibility state | |
2877 * | |
2878 * @exception DWTException <ul> | |
2879 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
2880 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2881 * </ul> | |
2882 * | |
2883 * @since 3.1 | |
2884 */ | |
2885 public void setHeaderVisible (bool show) { | |
2886 checkWidget (); | |
2887 OS.gtk_tree_view_set_headers_visible (handle, show); | |
2888 } | |
2889 | |
2890 /** | |
2891 * Marks the receiver's lines as visible if the argument is <code>true</code>, | |
2892 * and marks it invisible otherwise. | |
2893 * <p> | |
2894 * If one of the receiver's ancestors is not visible or some | |
2895 * other condition makes the receiver not visible, marking | |
2896 * it visible may not actually cause it to be displayed. | |
2897 * </p> | |
2898 * | |
2899 * @param show the new visibility state | |
2900 * | |
2901 * @exception DWTException <ul> | |
2902 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
2903 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2904 * </ul> | |
2905 * | |
2906 * @since 3.1 | |
2907 */ | |
2908 public void setLinesVisible (bool show) { | |
2909 checkWidget(); | |
2910 OS.gtk_tree_view_set_rules_hint (handle, show); | |
2911 } | |
2912 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
2913 override void setParentBackground () { |
90 | 2914 super.setParentBackground (); |
2915 auto window = paintWindow (); | |
2916 if (window !is null) OS.gdk_window_set_back_pixmap (window, null, true); | |
2917 } | |
2918 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
2919 override void setParentWindow (GtkWidget* widget) { |
90 | 2920 auto window = eventWindow (); |
2921 OS.gtk_widget_set_parent_window (widget, window); | |
2922 } | |
2923 | |
2924 void setScrollWidth (GtkTreeViewColumn* column, TreeItem item) { | |
2925 if (columnCount !is 0 || currentItem is item) return; | |
2926 /* | |
2927 * Use GTK_TREE_VIEW_COLUMN_GROW_ONLY on GTK versions < 2.3.2 | |
2928 * because fixed_height_mode is not supported. | |
2929 */ | |
2930 if (((style & DWT.VIRTUAL) !is 0) && OS.GTK_VERSION < OS.buildVERSION (2, 3, 2)) return; | |
2931 int width = OS.gtk_tree_view_column_get_fixed_width (column); | |
240 | 2932 int itemWidth = calculateWidth (column, cast(GtkTreeIter*)item.handle, true); |
90 | 2933 if (width < itemWidth) { |
2934 OS.gtk_tree_view_column_set_fixed_width (column, itemWidth); | |
2935 } | |
2936 } | |
2937 | |
2938 /** | |
2939 * Sets the receiver's selection to the given item. | |
2940 * The current selection is cleared before the new item is selected. | |
2941 * <p> | |
2942 * If the item is not in the receiver, then it is ignored. | |
2943 * </p> | |
2944 * | |
2945 * @param item the item to select | |
2946 * | |
2947 * @exception IllegalArgumentException <ul> | |
2948 * <li>ERROR_NULL_ARGUMENT - if the item is null</li> | |
2949 * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li> | |
2950 * </ul> | |
2951 * @exception DWTException <ul> | |
2952 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
2953 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2954 * </ul> | |
2955 * | |
2956 * @since 3.2 | |
2957 */ | |
2958 public void setSelection (TreeItem item) { | |
2959 checkWidget (); | |
2960 if (item is null) error (DWT.ERROR_NULL_ARGUMENT); | |
2961 setSelection ([item]); | |
2962 } | |
2963 | |
2964 /** | |
2965 * Sets the receiver's selection to be the given array of items. | |
2966 * The current selection is cleared before the new items are selected. | |
2967 * <p> | |
2968 * Items that are not in the receiver are ignored. | |
2969 * If the receiver is single-select and multiple items are specified, | |
2970 * then all items are ignored. | |
2971 * </p> | |
2972 * | |
2973 * @param items the array of items | |
2974 * | |
2975 * @exception IllegalArgumentException <ul> | |
2976 * <li>ERROR_INVALID_ARGUMENT - if one of the items has been disposed</li> | |
2977 * </ul> | |
2978 * @exception DWTException <ul> | |
2979 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
2980 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
2981 * </ul> | |
2982 * | |
2983 * @see Tree#deselectAll() | |
2984 */ | |
2985 public void setSelection (TreeItem [] items) { | |
2986 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
|
2987 // 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
|
2988 //if (items is null) error (DWT.ERROR_NULL_ARGUMENT); |
90 | 2989 deselectAll (); |
2990 int length = items.length; | |
2991 if (length is 0 || ((style & DWT.SINGLE) !is 0 && length > 1)) return; | |
2992 bool fixColumn = showFirstColumn (); | |
2993 auto selection = OS.gtk_tree_view_get_selection (handle); | |
2994 OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udCHANGED); | |
2995 bool first = true; | |
2996 for (int i = 0; i < length; i++) { | |
2997 TreeItem item = items [i]; | |
2998 if (item is null) continue; | |
2999 if (item.isDisposed ()) break; | |
3000 if (item.parent !is this) continue; | |
3001 auto path = OS.gtk_tree_model_get_path (modelHandle, item.handle); | |
3002 showItem (path, false); | |
3003 if (first) { | |
3004 OS.gtk_tree_view_set_cursor (handle, path, null, false); | |
3005 } | |
3006 OS.gtk_tree_selection_select_iter (selection, item.handle); | |
3007 OS.gtk_tree_path_free (path); | |
3008 first = false; | |
3009 } | |
3010 OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udCHANGED); | |
3011 if (fixColumn) hideFirstColumn (); | |
3012 } | |
3013 | |
3014 /** | |
3015 * Sets the column used by the sort indicator for the receiver. A null | |
3016 * value will clear the sort indicator. The current sort column is cleared | |
3017 * before the new column is set. | |
3018 * | |
3019 * @param column the column used by the sort indicator or <code>null</code> | |
3020 * | |
3021 * @exception IllegalArgumentException <ul> | |
3022 * <li>ERROR_INVALID_ARGUMENT - if the column is disposed</li> | |
3023 * </ul> | |
3024 * @exception DWTException <ul> | |
3025 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
3026 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3027 * </ul> | |
3028 * | |
3029 * @since 3.2 | |
3030 */ | |
3031 public void setSortColumn (TreeColumn column) { | |
3032 checkWidget (); | |
3033 if (column !is null && column.isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT); | |
3034 if (sortColumn !is null && !sortColumn.isDisposed()) { | |
3035 OS.gtk_tree_view_column_set_sort_indicator (sortColumn.handle, false); | |
3036 } | |
3037 sortColumn = column; | |
3038 if (sortColumn !is null && sortDirection !is DWT.NONE) { | |
3039 OS.gtk_tree_view_column_set_sort_indicator (sortColumn.handle, true); | |
3040 OS.gtk_tree_view_column_set_sort_order (sortColumn.handle, sortDirection is DWT.DOWN ? 0 : 1); | |
3041 } | |
3042 } | |
3043 | |
3044 /** | |
3045 * Sets the direction of the sort indicator for the receiver. The value | |
3046 * can be one of <code>UP</code>, <code>DOWN</code> or <code>NONE</code>. | |
3047 * | |
3048 * @param direction the direction of the sort indicator | |
3049 * | |
3050 * @exception DWTException <ul> | |
3051 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
3052 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3053 * </ul> | |
3054 * | |
3055 * @since 3.2 | |
3056 */ | |
3057 public void setSortDirection (int direction) { | |
3058 checkWidget (); | |
3059 if (direction !is DWT.UP && direction !is DWT.DOWN && direction !is DWT.NONE) return; | |
3060 sortDirection = direction; | |
3061 if (sortColumn is null || sortColumn.isDisposed ()) return; | |
3062 if (sortDirection is DWT.NONE) { | |
3063 OS.gtk_tree_view_column_set_sort_indicator (sortColumn.handle, false); | |
3064 } else { | |
3065 OS.gtk_tree_view_column_set_sort_indicator (sortColumn.handle, true); | |
3066 OS.gtk_tree_view_column_set_sort_order (sortColumn.handle, sortDirection is DWT.DOWN ? 0 : 1); | |
3067 } | |
3068 } | |
3069 | |
3070 /** | |
3071 * Sets the item which is currently at the top of the receiver. | |
3072 * This item can change when items are expanded, collapsed, scrolled | |
3073 * or new items are added or removed. | |
3074 * | |
3075 * @param item the item to be shown | |
3076 * | |
3077 * @exception IllegalArgumentException <ul> | |
3078 * <li>ERROR_NULL_ARGUMENT - if the item is null</li> | |
3079 * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li> | |
3080 * </ul> | |
3081 * @exception DWTException <ul> | |
3082 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
3083 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3084 * </ul> | |
3085 * | |
3086 * @see Tree#getTopItem() | |
3087 * | |
3088 * @since 2.1 | |
3089 */ | |
3090 public void setTopItem (TreeItem item) { | |
3091 if (item is null) error (DWT.ERROR_NULL_ARGUMENT); | |
3092 if (item.isDisposed ()) error(DWT.ERROR_INVALID_ARGUMENT); | |
3093 if (item.parent !is this) return; | |
3094 auto path = OS.gtk_tree_model_get_path (modelHandle, item.handle); | |
3095 showItem (path, false); | |
3096 OS.gtk_tree_view_scroll_to_cell (handle, path, null, true, 0f, 0f); | |
3097 if (OS.GTK_VERSION < OS.buildVERSION (2, 8, 0)) { | |
3098 /* | |
3099 * Bug in GTK. According to the documentation, gtk_tree_view_scroll_to_cell | |
3100 * should vertically scroll the cell to the top if use_align is true and row_align is 0. | |
3101 * However, prior to version 2.8 it does not scroll at all. The fix is to determine | |
3102 * the new location and use gtk_tree_view_scroll_to_point. | |
3103 * If the widget is a pinhead, calling gtk_tree_view_scroll_to_point | |
3104 * will have no effect. Therefore, it is still neccessary to call | |
3105 * gtk_tree_view_scroll_to_cell. | |
3106 */ | |
3107 OS.gtk_widget_realize (handle); | |
3108 GdkRectangle cellRect; | |
3109 OS.gtk_tree_view_get_cell_area (handle, path, null, &cellRect); | |
3110 int tx, ty; | |
3111 OS.gtk_tree_view_widget_to_tree_coords(handle, cellRect.x, cellRect.y, &tx, &ty); | |
3112 OS.gtk_tree_view_scroll_to_point (handle, -1, ty); | |
3113 } | |
3114 OS.gtk_tree_path_free (path); | |
3115 } | |
3116 | |
3117 /** | |
3118 * Shows the column. If the column is already showing in the receiver, | |
3119 * this method simply returns. Otherwise, the columns are scrolled until | |
3120 * the column is visible. | |
3121 * | |
3122 * @param column the column to be shown | |
3123 * | |
3124 * @exception IllegalArgumentException <ul> | |
3125 * <li>ERROR_NULL_ARGUMENT - if the item is null</li> | |
3126 * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li> | |
3127 * </ul> | |
3128 * @exception DWTException <ul> | |
3129 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
3130 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3131 * </ul> | |
3132 * | |
3133 * @since 3.1 | |
3134 */ | |
3135 public void showColumn (TreeColumn column) { | |
3136 checkWidget (); | |
3137 if (column is null) error (DWT.ERROR_NULL_ARGUMENT); | |
3138 if (column.isDisposed()) error(DWT.ERROR_INVALID_ARGUMENT); | |
3139 if (column.parent !is this) return; | |
3140 /* | |
3141 * This code is intentionally commented. According to the | |
3142 * documentation, gtk_tree_view_scroll_to_cell should scroll the | |
3143 * minimum amount to show the column but instead it scrolls strangely. | |
3144 */ | |
3145 //OS.gtk_tree_view_scroll_to_cell (handle, 0, column.handle, false, 0, 0); | |
3146 OS.gtk_widget_realize (handle); | |
3147 GdkRectangle cellRect; | |
3148 OS.gtk_tree_view_get_cell_area (handle, null, column.handle, &cellRect); | |
3149 GdkRectangle visibleRect; | |
3150 OS.gtk_tree_view_get_visible_rect (handle, &visibleRect); | |
3151 if (cellRect.x < visibleRect.x) { | |
3152 OS.gtk_tree_view_scroll_to_point (handle, cellRect.x, -1); | |
3153 } else { | |
3154 int width = Math.min (visibleRect.width, cellRect.width); | |
3155 if (cellRect.x + width > visibleRect.x + visibleRect.width) { | |
3156 int tree_x = cellRect.x + width - visibleRect.width; | |
3157 OS.gtk_tree_view_scroll_to_point (handle, tree_x, -1); | |
3158 } | |
3159 } | |
3160 } | |
3161 | |
3162 bool showFirstColumn () { | |
3163 /* | |
3164 * Bug in GTK. If no columns are visible, changing the selection | |
3165 * will fail. The fix is to temporarily make a column visible. | |
3166 */ | |
3167 int columnCount = Math.max (1, this.columnCount); | |
3168 for (int i=0; i<columnCount; i++) { | |
3169 auto column = OS.gtk_tree_view_get_column (handle, i); | |
3170 if (OS.gtk_tree_view_column_get_visible (column)) return false; | |
3171 } | |
3172 auto firstColumn = OS.gtk_tree_view_get_column (handle, 0); | |
3173 OS.gtk_tree_view_column_set_visible (firstColumn, true); | |
3174 return true; | |
3175 } | |
3176 | |
3177 /** | |
3178 * Shows the selection. If the selection is already showing in the receiver, | |
3179 * this method simply returns. Otherwise, the items are scrolled until | |
3180 * the selection is visible. | |
3181 * | |
3182 * @exception DWTException <ul> | |
3183 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
3184 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3185 * </ul> | |
3186 * | |
3187 * @see Tree#showItem(TreeItem) | |
3188 */ | |
3189 public void showSelection () { | |
3190 checkWidget(); | |
3191 TreeItem [] items = getSelection (); | |
3192 if (items.length !is 0 && items [0] !is null) showItem (items [0]); | |
3193 } | |
3194 | |
3195 void showItem (GtkTreePath* path, bool scroll) { | |
3196 int depth = OS.gtk_tree_path_get_depth (path); | |
3197 if (depth > 1) { | |
3198 auto indicesPtr = OS.gtk_tree_path_get_indices (path); | |
3199 int [] indices = indicesPtr[ 0 .. depth - 1]; | |
3200 auto tempPath = OS.gtk_tree_path_new (); | |
3201 for (int i=0; i<indices.length; i++) { | |
3202 OS.gtk_tree_path_append_index (tempPath, indices [i]); | |
3203 OS.gtk_tree_view_expand_row (handle, tempPath, false); | |
3204 } | |
3205 OS.gtk_tree_path_free (tempPath); | |
3206 } | |
3207 if (scroll) { | |
3208 OS.gtk_widget_realize (handle); | |
3209 GdkRectangle cellRect; | |
3210 OS.gtk_tree_view_get_cell_area (handle, path, null, &cellRect); | |
3211 bool isHidden = cellRect.y is 0 && cellRect.height is 0; | |
3212 int tx, ty; | |
3213 OS.gtk_tree_view_widget_to_tree_coords (handle, cellRect.x, cellRect.y, &tx, &ty); | |
3214 GdkRectangle visibleRect; | |
3215 OS.gtk_tree_view_get_visible_rect (handle, &visibleRect); | |
3216 if (!isHidden) { | |
3217 if (ty < visibleRect.y || ty + cellRect.height > visibleRect.y + visibleRect.height) { | |
3218 isHidden = true; | |
3219 } | |
3220 } | |
3221 if (isHidden) { | |
3222 /* | |
3223 * This code intentionally commented. | |
3224 * Bug in GTK. According to the documentation, gtk_tree_view_scroll_to_cell | |
3225 * should scroll the minimum amount to show the cell if use_align is false. | |
3226 * However, what actually happens is the cell is scrolled to the top. | |
3227 * The fix is to determine the new location and use gtk_tree_view_scroll_to_point. | |
3228 * If the widget is a pinhead, calling gtk_tree_view_scroll_to_point | |
3229 * will have no effect. Therefore, it is still neccessary to | |
3230 * call gtk_tree_view_scroll_to_cell. | |
3231 */ | |
3232 // OS.gtk_tree_view_scroll_to_cell (handle, path, 0, depth !is 1, 0.5f, 0.0f); | |
3233 if (depth !is 1) { | |
3234 OS.gtk_tree_view_scroll_to_cell (handle, path, null, true, 0.5f, 0.0f); | |
3235 } else { | |
3236 if (ty < visibleRect.y ) { | |
3237 OS.gtk_tree_view_scroll_to_point (handle, -1, ty); | |
3238 } else { | |
3239 int height = Math.min (visibleRect.height, cellRect.height); | |
3240 if (ty + height > visibleRect.y + visibleRect.height) { | |
3241 OS.gtk_tree_view_scroll_to_point (handle, -1, ty + cellRect.height - visibleRect.height); | |
3242 } | |
3243 } | |
3244 } | |
3245 } | |
3246 } | |
3247 } | |
3248 | |
3249 /** | |
3250 * Shows the item. If the item is already showing in the receiver, | |
3251 * this method simply returns. Otherwise, the items are scrolled | |
3252 * and expanded until the item is visible. | |
3253 * | |
3254 * @param item the item to be shown | |
3255 * | |
3256 * @exception IllegalArgumentException <ul> | |
3257 * <li>ERROR_NULL_ARGUMENT - if the item is null</li> | |
3258 * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li> | |
3259 * </ul> | |
3260 * @exception DWTException <ul> | |
3261 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
3262 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
3263 * </ul> | |
3264 * | |
3265 * @see Tree#showSelection() | |
3266 */ | |
3267 public void showItem (TreeItem item) { | |
3268 checkWidget (); | |
3269 if (item is null) error (DWT.ERROR_NULL_ARGUMENT); | |
3270 if (item.isDisposed ()) error(DWT.ERROR_INVALID_ARGUMENT); | |
3271 if (item.parent !is this) return; | |
3272 auto path = OS.gtk_tree_model_get_path (modelHandle, item.handle); | |
3273 showItem (path, true); | |
3274 OS.gtk_tree_path_free (path); | |
3275 } | |
3276 | |
3277 override void treeSelectionProc ( | |
3278 GtkTreeModel *model, | |
3279 GtkTreePath *path, | |
3280 GtkTreeIter *iter, | |
3281 int[] selection, | |
3282 int length_) | |
3283 { | |
3284 if (selection !is null) { | |
3285 int index; | |
3286 OS.gtk_tree_model_get1 (modelHandle, iter, ID_COLUMN, cast(void**)&index); | |
3287 selection [length_] = index; | |
3288 } | |
3289 return 0; | |
3290 } | |
3291 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
3292 override void updateScrollBarValue (ScrollBar bar) { |
90 | 3293 super.updateScrollBarValue (bar); |
3294 /* | |
3295 * Bug in GTK. Scrolling changes the XWindow position | |
3296 * and makes the child widgets appear to scroll even | |
3297 * though when queried their position is unchanged. | |
3298 * The fix is to queue a resize event for each child to | |
3299 * force the position to be corrected. | |
3300 */ | |
3301 auto parentHandle = parentingHandle (); | |
3302 auto list = OS.gtk_container_get_children (parentHandle); | |
3303 if (list is null) return; | |
3304 auto temp = list; | |
3305 while (temp !is null) { | |
3306 auto widget = OS.g_list_data (temp); | |
3307 if (widget !is null) OS.gtk_widget_queue_resize (widget); | |
3308 temp = OS.g_list_next (temp); | |
3309 } | |
3310 OS.g_list_free (list); | |
3311 } | |
3312 | |
3313 } |