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