Mercurial > projects > dwt-linux
annotate dwt/widgets/TreeColumn.d @ 259:c0d810de7093
Update SWT 3.4M7 to 3.4
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 29 Jun 2008 14:33:38 +0200 |
parents | 5a30aa9820f3 |
children |
rev | line source |
---|---|
115
52b32f5cb1e0
many file checked for switch default
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
1 /******************************************************************************* |
259 | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
90 | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
108 | 10 * Port to the D programming language: |
11 * Frank Benoit <benoit@tionex.de> | |
90 | 12 *******************************************************************************/ |
13 module dwt.widgets.TreeColumn; | |
14 | |
238 | 15 import dwt.dwthelper.utils; |
16 | |
90 | 17 |
18 | |
19 import dwt.DWT; | |
20 import dwt.DWTException; | |
21 import dwt.events.ControlListener; | |
22 import dwt.events.SelectionEvent; | |
23 import dwt.events.SelectionListener; | |
24 import dwt.graphics.Image; | |
25 import dwt.internal.gtk.OS; | |
26 import dwt.widgets.Item; | |
27 import dwt.widgets.Tree; | |
28 import dwt.widgets.Shell; | |
29 import dwt.widgets.ImageList; | |
30 import dwt.widgets.TypedListener; | |
31 | |
32 import Math = tango.math.Math; | |
33 | |
34 /** | |
35 * Instances of this class represent a column in a tree widget. | |
36 * <p><dl> | |
37 * <dt><b>Styles:</b></dt> | |
38 * <dd>LEFT, RIGHT, CENTER</dd> | |
39 * <dt><b>Events:</b></dt> | |
40 * <dd> Move, Resize, Selection</dd> | |
41 * </dl> | |
42 * </p><p> | |
43 * Note: Only one of the styles LEFT, RIGHT and CENTER may be specified. | |
44 * </p><p> | |
45 * IMPORTANT: This class is <em>not</em> intended to be subclassed. | |
46 * </p> | |
47 * | |
259 | 48 * @see <a href="http://www.eclipse.org/swt/snippets/#tree">Tree, TreeItem, TreeColumn snippets</a> |
49 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> | |
50 * | |
90 | 51 * @since 3.1 |
52 */ | |
53 public class TreeColumn : Item { | |
54 GtkWidget* labelHandle, imageHandle, buttonHandle; | |
55 Tree parent; | |
56 int modelIndex, lastButton, lastTime, lastX, lastWidth; | |
57 bool customDraw, useFixedWidth; | |
238 | 58 String toolTipText; |
90 | 59 |
60 /** | |
61 * Constructs a new instance of this class given its parent | |
62 * (which must be a <code>Tree</code>) and a style value | |
63 * describing its behavior and appearance. The item is added | |
64 * to the end of the items maintained by its parent. | |
65 * <p> | |
66 * The style value is either one of the style constants defined in | |
67 * class <code>DWT</code> which is applicable to instances of this | |
68 * class, or must be built by <em>bitwise OR</em>'ing together | |
69 * (that is, using the <code>int</code> "|" operator) two or more | |
70 * of those <code>DWT</code> style constants. The class description | |
71 * lists the style constants that are applicable to the class. | |
72 * Style bits are also inherited from superclasses. | |
73 * </p> | |
74 * | |
75 * @param parent a composite control which will be the parent of the new instance (cannot be null) | |
76 * @param style the style of control to construct | |
77 * | |
78 * @exception IllegalArgumentException <ul> | |
79 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
80 * </ul> | |
81 * @exception DWTException <ul> | |
82 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
83 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
84 * </ul> | |
85 * | |
86 * @see DWT#LEFT | |
87 * @see DWT#RIGHT | |
88 * @see DWT#CENTER | |
89 * @see Widget#checkSubclass | |
90 * @see Widget#getStyle | |
91 */ | |
92 public this (Tree parent, int style) { | |
93 super (parent, checkStyle (style)); | |
94 this.parent = parent; | |
95 createWidget (parent.getColumnCount ()); | |
96 } | |
97 | |
98 /** | |
99 * Constructs a new instance of this class given its parent | |
100 * (which must be a <code>Tree</code>), a style value | |
101 * describing its behavior and appearance, and the index | |
102 * at which to place it in the items maintained by its parent. | |
103 * <p> | |
104 * The style value is either one of the style constants defined in | |
105 * class <code>DWT</code> which is applicable to instances of this | |
106 * class, or must be built by <em>bitwise OR</em>'ing together | |
107 * (that is, using the <code>int</code> "|" operator) two or more | |
108 * of those <code>DWT</code> style constants. The class description | |
109 * lists the style constants that are applicable to the class. | |
110 * Style bits are also inherited from superclasses. | |
111 * </p> | |
259 | 112 * <p> |
113 * Note that due to a restriction on some platforms, the first column | |
114 * is always left aligned. | |
115 * </p> | |
90 | 116 * @param parent a composite control which will be the parent of the new instance (cannot be null) |
117 * @param style the style of control to construct | |
118 * @param index the zero-relative index to store the receiver in its parent | |
119 * | |
120 * @exception IllegalArgumentException <ul> | |
121 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
122 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li> | |
123 * </ul> | |
124 * @exception DWTException <ul> | |
125 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
126 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
127 * </ul> | |
128 * | |
129 * @see DWT#LEFT | |
130 * @see DWT#RIGHT | |
131 * @see DWT#CENTER | |
132 * @see Widget#checkSubclass | |
133 * @see Widget#getStyle | |
134 */ | |
135 public this (Tree parent, int style, int index) { | |
136 super (parent, checkStyle (style)); | |
137 this.parent = parent; | |
138 createWidget (index); | |
139 } | |
140 | |
141 /** | |
142 * Adds the listener to the collection of listeners who will | |
143 * be notified when the control is moved or resized, by sending | |
144 * it one of the messages defined in the <code>ControlListener</code> | |
145 * interface. | |
146 * | |
147 * @param listener the listener which should be notified | |
148 * | |
149 * @exception IllegalArgumentException <ul> | |
150 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
151 * </ul> | |
152 * @exception DWTException <ul> | |
153 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
154 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
155 * </ul> | |
156 * | |
157 * @see ControlListener | |
158 * @see #removeControlListener | |
159 */ | |
160 public void addControlListener(ControlListener listener) { | |
161 checkWidget(); | |
162 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT); | |
163 TypedListener typedListener = new TypedListener (listener); | |
164 addListener (DWT.Resize,typedListener); | |
165 addListener (DWT.Move,typedListener); | |
166 } | |
167 | |
168 /** | |
169 * Adds the listener to the collection of listeners who will | |
170 * be notified when the control is selected by the user, by sending | |
171 * it one of the messages defined in the <code>SelectionListener</code> | |
172 * interface. | |
173 * <p> | |
174 * <code>widgetSelected</code> is called when the column header is selected. | |
175 * <code>widgetDefaultSelected</code> is not called. | |
176 * </p> | |
177 * | |
178 * @param listener the listener which should be notified when the control is selected by the user | |
179 * | |
180 * @exception IllegalArgumentException <ul> | |
181 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
182 * </ul> | |
183 * @exception DWTException <ul> | |
184 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
185 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
186 * </ul> | |
187 * | |
188 * @see SelectionListener | |
189 * @see #removeSelectionListener | |
190 * @see SelectionEvent | |
191 */ | |
192 public void addSelectionListener (SelectionListener listener) { | |
193 checkWidget(); | |
194 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT); | |
195 TypedListener typedListener = new TypedListener (listener); | |
196 addListener (DWT.Selection,typedListener); | |
197 addListener (DWT.DefaultSelection,typedListener); | |
198 } | |
199 | |
200 static int checkStyle (int style) { | |
201 return checkBits (style, DWT.LEFT, DWT.CENTER, DWT.RIGHT, 0, 0, 0); | |
202 } | |
203 | |
204 protected void checkSubclass () { | |
205 if (!isValidSubclass ()) error (DWT.ERROR_INVALID_SUBCLASS); | |
206 } | |
207 | |
208 void createWidget (int index) { | |
209 parent.createItem (this, index); | |
240 | 210 setOrientation (); |
90 | 211 hookEvents (); |
212 register (); | |
213 text = ""; | |
214 } | |
215 | |
216 void deregister() { | |
217 super.deregister (); | |
218 display.removeWidget (handle); | |
219 if (buttonHandle !is null) display.removeWidget (buttonHandle); | |
220 if (labelHandle !is null) display.removeWidget (labelHandle); | |
221 } | |
222 | |
223 void destroyWidget () { | |
224 parent.destroyItem (this); | |
225 releaseHandle (); | |
226 } | |
227 | |
228 /** | |
229 * Returns a value which describes the position of the | |
230 * text or image in the receiver. The value will be one of | |
231 * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>. | |
232 * | |
233 * @return the alignment | |
234 * | |
235 * @exception DWTException <ul> | |
236 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
237 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
238 * </ul> | |
239 */ | |
240 public int getAlignment () { | |
241 checkWidget(); | |
242 if ((style & DWT.LEFT) !is 0) return DWT.LEFT; | |
243 if ((style & DWT.CENTER) !is 0) return DWT.CENTER; | |
244 if ((style & DWT.RIGHT) !is 0) return DWT.RIGHT; | |
245 return DWT.LEFT; | |
246 } | |
247 | |
248 /** | |
249 * Gets the moveable attribute. A column that is | |
250 * not moveable cannot be reordered by the user | |
251 * by dragging the header but may be reordered | |
252 * by the programmer. | |
253 * | |
254 * @return the moveable attribute | |
255 * | |
256 * @exception DWTException <ul> | |
257 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
258 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
259 * </ul> | |
260 * | |
261 * @see Tree#getColumnOrder() | |
262 * @see Tree#setColumnOrder(int[]) | |
263 * @see TreeColumn#setMoveable(bool) | |
264 * @see DWT#Move | |
265 * | |
266 * @since 3.2 | |
267 */ | |
268 public bool getMoveable() { | |
269 checkWidget(); | |
270 return cast(bool)OS.gtk_tree_view_column_get_reorderable (handle); | |
271 } | |
272 | |
273 /** | |
274 * Returns the receiver's parent, which must be a <code>Tree</code>. | |
275 * | |
276 * @return the receiver's parent | |
277 * | |
278 * @exception DWTException <ul> | |
279 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
280 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
281 * </ul> | |
282 */ | |
283 public Tree getParent () { | |
284 checkWidget(); | |
285 return parent; | |
286 } | |
287 | |
288 /** | |
289 * Gets the resizable attribute. A column that is | |
290 * not resizable cannot be dragged by the user but | |
291 * may be resized by the programmer. | |
292 * | |
293 * @return the resizable attribute | |
294 * | |
295 * @exception DWTException <ul> | |
296 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
297 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
298 * </ul> | |
299 */ | |
300 public bool getResizable () { | |
301 checkWidget(); | |
302 return cast(bool)OS.gtk_tree_view_column_get_resizable (handle); | |
303 } | |
304 | |
305 /** | |
306 * Returns the receiver's tool tip text, or null if it has | |
307 * not been set. | |
308 * | |
309 * @return the receiver's tool tip text | |
310 * | |
311 * @exception DWTException <ul> | |
312 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
313 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
314 * </ul> | |
315 * | |
316 * @since 3.2 | |
317 */ | |
238 | 318 public String getToolTipText () { |
90 | 319 checkWidget(); |
320 return toolTipText; | |
321 } | |
322 | |
323 /** | |
324 * Gets the width of the receiver. | |
325 * | |
326 * @return the width | |
327 * | |
328 * @exception DWTException <ul> | |
329 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
330 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
331 * </ul> | |
332 */ | |
333 public int getWidth () { | |
334 checkWidget(); | |
335 if (!OS.gtk_tree_view_column_get_visible (handle)) { | |
336 return 0; | |
337 } | |
338 if (useFixedWidth) return OS.gtk_tree_view_column_get_fixed_width (handle); | |
339 return OS.gtk_tree_view_column_get_width (handle); | |
340 } | |
341 | |
342 override int gtk_clicked (GtkWidget* widget) { | |
343 /* | |
344 * There is no API to get a double click on a table column. Normally, when | |
345 * the mouse is double clicked, this is indicated by GDK_2BUTTON_PRESS | |
346 * but the table column sends the click signal on button release. The fix is to | |
347 * test for double click by remembering the last click time and mouse button | |
348 * and testing for the double click interval. | |
349 */ | |
350 bool doubleClick = false; | |
351 bool postEvent_ = true; | |
352 auto eventPtr = OS.gtk_get_current_event (); | |
353 if (eventPtr !is null) { | |
354 GdkEventButton* gdkEvent = cast(GdkEventButton*)eventPtr; | |
355 scope(exit) OS.gdk_event_free (eventPtr); | |
356 switch (gdkEvent.type) { | |
357 case OS.GDK_BUTTON_RELEASE: { | |
358 int clickTime = display.getDoubleClickTime (); | |
359 int eventTime = gdkEvent.time, eventButton = gdkEvent.button; | |
360 if (lastButton is eventButton && lastTime !is 0 && Math.abs (lastTime - eventTime) <= clickTime) { | |
361 doubleClick = true; | |
362 } | |
363 lastTime = eventTime is 0 ? 1: eventTime; | |
364 lastButton = eventButton; | |
365 break; | |
366 } | |
367 case OS.GDK_MOTION_NOTIFY: { | |
368 /* | |
369 * Bug in GTK. Dragging a column in a GtkTreeView causes a clicked | |
370 * signal to be emitted even though the mouse button was never released. | |
371 * The fix to ignore the signal if the current GDK event is a motion notify. | |
372 * The GTK bug was fixed in version 2.6 | |
373 */ | |
374 if (OS.GTK_VERSION < OS.buildVERSION (2, 6, 0)) postEvent_ = false; | |
375 break; | |
376 } | |
115
52b32f5cb1e0
many file checked for switch default
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
377 default: |
90 | 378 } |
379 } | |
380 if (postEvent_) postEvent (doubleClick ? DWT.DefaultSelection : DWT.Selection); | |
381 return 0; | |
382 } | |
383 | |
384 override int gtk_mnemonic_activate (GtkWidget* widget, int /*long*/ arg1) { | |
385 return parent.gtk_mnemonic_activate (widget, arg1); | |
386 } | |
387 | |
388 override int gtk_size_allocate (GtkWidget* widget, int allocation) { | |
389 useFixedWidth = false; | |
390 int x = OS.GTK_WIDGET_X (widget); | |
391 int width = OS.GTK_WIDGET_WIDTH (widget); | |
392 if (x !is lastX) { | |
393 lastX = x; | |
394 sendEvent (DWT.Move); | |
395 } | |
396 if (width !is lastWidth) { | |
397 lastWidth = width; | |
398 sendEvent (DWT.Resize); | |
399 } | |
400 return 0; | |
401 } | |
402 | |
403 void hookEvents () { | |
404 super.hookEvents (); | |
405 OS.g_signal_connect_closure (handle, OS.clicked.ptr, display.closures [CLICKED], false); | |
406 if (buttonHandle !is null) OS.g_signal_connect_closure_by_id (buttonHandle, display.signalIds [SIZE_ALLOCATE], 0, display.closures [SIZE_ALLOCATE], false); | |
407 if (labelHandle !is null) OS.g_signal_connect_closure_by_id (labelHandle, display.signalIds [MNEMONIC_ACTIVATE], 0, display.closures [MNEMONIC_ACTIVATE], false); | |
408 } | |
409 | |
410 /** | |
411 * Causes the receiver to be resized to its preferred size. | |
412 * For a composite, this involves computing the preferred size | |
413 * from its layout, if there is one. | |
414 * | |
415 * @exception DWTException <ul> | |
416 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
417 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
418 * </ul> | |
419 * | |
420 */ | |
421 public void pack () { | |
422 checkWidget(); | |
423 int width = 0; | |
424 if (buttonHandle !is null) { | |
425 GtkRequisition requisition; | |
426 OS.gtk_widget_size_request (buttonHandle, &requisition); | |
427 width = requisition.width; | |
428 } | |
429 if ((parent.style & DWT.VIRTUAL) !is 0) { | |
430 //NOT DONE | |
431 } else { | |
432 GtkTreeIter iter; | |
433 if (OS.gtk_tree_model_get_iter_first (parent.modelHandle, &iter)) { | |
434 do { | |
240 | 435 width = Math.max (width, parent.calculateWidth (cast(GtkTreeViewColumn*)handle, &iter, true)); |
90 | 436 } while (OS.gtk_tree_model_iter_next(parent.modelHandle, &iter)); |
437 } | |
438 } | |
439 setWidth(width); | |
440 } | |
441 | |
442 void register () { | |
443 super.register (); | |
444 display.addWidget (handle, this); | |
445 if (buttonHandle !is null) display.addWidget (buttonHandle, this); | |
446 if (labelHandle !is null) display.addWidget (labelHandle, this); | |
447 } | |
448 | |
449 void releaseHandle () { | |
450 super.releaseHandle (); | |
451 handle = buttonHandle = labelHandle = imageHandle = null; | |
452 modelIndex = -1; | |
453 parent = null; | |
454 } | |
455 | |
456 void releaseParent () { | |
457 super.releaseParent (); | |
458 if (parent.sortColumn is this) { | |
459 parent.sortColumn = null; | |
460 } | |
461 } | |
462 | |
463 /** | |
464 * Removes the listener from the collection of listeners who will | |
465 * be notified when the control is moved or resized. | |
466 * | |
467 * @param listener the listener which should no longer be notified | |
468 * | |
469 * @exception IllegalArgumentException <ul> | |
470 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
471 * </ul> | |
472 * @exception DWTException <ul> | |
473 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
474 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
475 * </ul> | |
476 * | |
477 * @see ControlListener | |
478 * @see #addControlListener | |
479 */ | |
480 public void removeControlListener (ControlListener listener) { | |
481 checkWidget(); | |
482 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT); | |
483 if (eventTable is null) return; | |
484 eventTable.unhook (DWT.Move, listener); | |
485 eventTable.unhook (DWT.Resize, listener); | |
486 } | |
487 | |
488 /** | |
489 * Removes the listener from the collection of listeners who will | |
490 * be notified when the control is selected by the user. | |
491 * | |
492 * @param listener the listener which should no longer be notified | |
493 * | |
494 * @exception IllegalArgumentException <ul> | |
495 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
496 * </ul> | |
497 * @exception DWTException <ul> | |
498 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
499 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
500 * </ul> | |
501 * | |
502 * @see SelectionListener | |
503 * @see #addSelectionListener | |
504 */ | |
505 public void removeSelectionListener(SelectionListener listener) { | |
506 checkWidget(); | |
507 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT); | |
508 if (eventTable is null) return; | |
509 eventTable.unhook (DWT.Selection, listener); | |
510 eventTable.unhook (DWT.DefaultSelection,listener); | |
511 } | |
512 | |
513 /** | |
514 * Controls how text and images will be displayed in the receiver. | |
515 * The argument should be one of <code>LEFT</code>, <code>RIGHT</code> | |
516 * or <code>CENTER</code>. | |
259 | 517 * <p> |
518 * Note that due to a restriction on some platforms, the first column | |
519 * is always left aligned. | |
520 * </p> | |
90 | 521 * @param alignment the new alignment |
522 * | |
523 * @exception DWTException <ul> | |
524 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
525 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
526 * </ul> | |
527 */ | |
528 public void setAlignment (int alignment) { | |
529 checkWidget(); | |
530 if ((alignment & (DWT.LEFT | DWT.RIGHT | DWT.CENTER)) is 0) return; | |
531 int index = parent.indexOf (this); | |
532 if (index is -1 || index is 0) return; | |
533 style &= ~(DWT.LEFT | DWT.RIGHT | DWT.CENTER); | |
534 style |= alignment & (DWT.LEFT | DWT.RIGHT | DWT.CENTER); | |
535 parent.createRenderers (cast(GtkTreeViewColumn*)handle, modelIndex, index is 0, style); | |
536 } | |
537 | |
538 void setFontDescription (PangoFontDescription* font) { | |
539 OS.gtk_widget_modify_font (labelHandle, font); | |
540 OS.gtk_widget_modify_font (imageHandle, font); | |
541 } | |
542 | |
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
115
diff
changeset
|
543 public override void setImage (Image image) { |
90 | 544 checkWidget (); |
545 super.setImage (image); | |
546 if (image !is null) { | |
547 ImageList headerImageList = parent.headerImageList; | |
548 if (headerImageList is null) { | |
549 headerImageList = parent.headerImageList = new ImageList (); | |
550 } | |
551 int imageIndex = headerImageList.indexOf (image); | |
552 if (imageIndex is -1) imageIndex = headerImageList.add (image); | |
553 auto pixbuf = headerImageList.getPixbuf (imageIndex); | |
554 OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf); | |
555 OS.gtk_widget_show (imageHandle); | |
556 } else { | |
557 OS.gtk_image_set_from_pixbuf (imageHandle, null); | |
558 OS.gtk_widget_hide (imageHandle); | |
559 } | |
560 } | |
561 | |
562 /** | |
563 * Sets the moveable attribute. A column that is | |
564 * moveable can be reordered by the user by dragging | |
565 * the header. A column that is not moveable cannot be | |
566 * dragged by the user but may be reordered | |
567 * by the programmer. | |
568 * | |
569 * @param moveable the moveable attribute | |
570 * | |
571 * @exception DWTException <ul> | |
572 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
573 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
574 * </ul> | |
575 * | |
576 * @see Tree#setColumnOrder(int[]) | |
577 * @see Tree#getColumnOrder() | |
578 * @see TreeColumn#getMoveable() | |
579 * @see DWT#Move | |
580 * | |
581 * @since 3.2 | |
582 */ | |
583 public void setMoveable (bool moveable) { | |
584 checkWidget(); | |
585 OS.gtk_tree_view_column_set_reorderable (handle, moveable); | |
586 } | |
587 | |
240 | 588 void setOrientation() { |
589 if ((parent.style & DWT.RIGHT_TO_LEFT) !is 0) { | |
590 if (buttonHandle !is null) { | |
591 OS.gtk_widget_set_direction (buttonHandle, OS.GTK_TEXT_DIR_RTL); | |
592 display.doSetDirectionProc(buttonHandle, OS.GTK_TEXT_DIR_RTL); | |
593 } | |
594 } | |
595 } | |
596 | |
90 | 597 /** |
598 * Sets the resizable attribute. A column that is | |
599 * not resizable cannot be dragged by the user but | |
600 * may be resized by the programmer. | |
601 * | |
602 * @param resizable the resize attribute | |
603 * | |
604 * @exception DWTException <ul> | |
605 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
606 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
607 * </ul> | |
608 */ | |
609 public void setResizable (bool resizable) { | |
610 checkWidget(); | |
611 OS.gtk_tree_view_column_set_resizable (handle, resizable); | |
612 } | |
613 | |
238 | 614 public override void setText (String string) { |
90 | 615 checkWidget(); |
255
5a30aa9820f3
removed tango.stdc.stringz imports and allow null for arrays and string arguments.
Frank Benoit <benoit@tionex.de>
parents:
248
diff
changeset
|
616 // DWT extension: allow null for zero length string |
5a30aa9820f3
removed tango.stdc.stringz imports and allow null for arrays and string arguments.
Frank Benoit <benoit@tionex.de>
parents:
248
diff
changeset
|
617 //if (string is null) error (DWT.ERROR_NULL_ARGUMENT); |
90 | 618 super.setText (string); |
619 char [] chars = fixMnemonic (string); | |
248
34409a2fc053
Fix call OS.gtk_label_set_text_with_mnemonic with valid ptr, even for zero length strings.
Frank Benoit <benoit@tionex.de>
parents:
240
diff
changeset
|
620 OS.gtk_label_set_text_with_mnemonic (labelHandle, chars.toStringzValidPtr()); |
90 | 621 if (string.length !is 0) { |
622 OS.gtk_widget_show (labelHandle); | |
623 } else { | |
624 OS.gtk_widget_hide (labelHandle); | |
625 } | |
626 } | |
627 | |
628 /** | |
629 * Sets the receiver's tool tip text to the argument, which | |
630 * may be null indicating that no tool tip text should be shown. | |
631 * | |
632 * @param string the new tool tip text (or null) | |
633 * | |
634 * @exception DWTException <ul> | |
635 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
636 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
637 * </ul> | |
638 * | |
639 * @since 3.2 | |
640 */ | |
238 | 641 public void setToolTipText (String string) { |
90 | 642 checkWidget(); |
643 Shell shell = parent._getShell (); | |
644 setToolTipText (shell, string); | |
645 toolTipText = string; | |
646 } | |
647 | |
238 | 648 void setToolTipText (Shell shell, String newString) { |
90 | 649 shell.setToolTipText (buttonHandle, newString); |
650 } | |
651 | |
652 /** | |
653 * Sets the width of the receiver. | |
654 * | |
655 * @param width the new width | |
656 * | |
657 * @exception DWTException <ul> | |
658 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
659 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
660 * </ul> | |
661 */ | |
662 public void setWidth (int width) { | |
663 checkWidget(); | |
664 if (width < 0) return; | |
665 if (width is lastWidth) return; | |
666 if (width > 0) { | |
667 useFixedWidth = true; | |
668 OS.gtk_tree_view_column_set_fixed_width (handle, width); | |
669 } | |
670 /* | |
671 * Bug in GTK. For some reason, calling gtk_tree_view_column_set_visible() | |
672 * when the parent is not realized fails to show the column. The fix is to | |
673 * ensure that the table has been realized. | |
674 */ | |
675 if (width !is 0) OS.gtk_widget_realize (parent.handle); | |
676 OS.gtk_tree_view_column_set_visible (handle, width !is 0); | |
677 lastWidth = width; | |
678 sendEvent (DWT.Resize); | |
679 } | |
680 | |
681 } |