Mercurial > projects > dwt-linux
annotate dwt/widgets/ExpandItem.d @ 240:ce446666f5a2
Update to SWT 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 12 May 2008 19:13:01 +0200 |
parents | 380bad9f6852 |
children | 5a30aa9820f3 |
rev | line source |
---|---|
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
1 /******************************************************************************* |
79 | 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> | |
79 | 12 *******************************************************************************/ |
13 module dwt.widgets.ExpandItem; | |
14 | |
238 | 15 import dwt.dwthelper.utils; |
16 | |
79 | 17 |
18 import dwt.DWT; | |
19 import dwt.DWTException; | |
20 import dwt.graphics.GC; | |
21 import dwt.graphics.Image; | |
22 import dwt.graphics.Point; | |
23 import dwt.graphics.Rectangle; | |
24 import dwt.internal.Converter; | |
25 import dwt.internal.gtk.OS; | |
26 import dwt.widgets.Item; | |
27 import dwt.widgets.Control; | |
28 import dwt.widgets.Display; | |
29 import dwt.widgets.ExpandBar; | |
30 import dwt.widgets.ImageList; | |
31 import dwt.widgets.Event; | |
32 | |
33 import Math = tango.math.Math; | |
34 static import tango.stdc.stringz; | |
35 | |
36 /** | |
37 * Instances of this class represent a selectable user interface object | |
38 * that represents a expandable item in a expand bar. | |
39 * <p> | |
40 * <dl> | |
41 * <dt><b>Styles:</b></dt> | |
42 * <dd>(none)</dd> | |
43 * <dt><b>Events:</b></dt> | |
44 * <dd>(none)</dd> | |
45 * </dl> | |
46 * </p><p> | |
47 * IMPORTANT: This class is <em>not</em> intended to be subclassed. | |
48 * </p> | |
49 * | |
50 * @see ExpandBar | |
51 * | |
52 * @since 3.2 | |
53 */ | |
54 public class ExpandItem : Item { | |
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
55 |
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
56 alias Item.setForegroundColor setForegroundColor; |
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
57 alias Item.windowProc windowProc; |
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
58 |
79 | 59 ExpandBar parent; |
60 Control control; | |
61 ImageList imageList; | |
62 GtkWidget* clientHandle, boxHandle, labelHandle, imageHandle; | |
63 bool expanded; | |
64 int x, y, width, height; | |
65 int imageHeight, imageWidth; | |
66 static final int TEXT_INSET = 6; | |
67 static final int BORDER = 1; | |
68 static final int CHEVRON_SIZE = 24; | |
69 | |
70 /** | |
71 * Constructs a new instance of this class given its parent | |
72 * and a style value describing its behavior and appearance. | |
73 * <p> | |
74 * The style value is either one of the style constants defined in | |
75 * class <code>DWT</code> which is applicable to instances of this | |
76 * class, or must be built by <em>bitwise OR</em>'ing together | |
77 * (that is, using the <code>int</code> "|" operator) two or more | |
78 * of those <code>DWT</code> style constants. The class description | |
79 * lists the style constants that are applicable to the class. | |
80 * Style bits are also inherited from superclasses. | |
81 * </p> | |
82 * | |
83 * @param parent a composite control which will be the parent of the new instance (cannot be null) | |
84 * @param style the style of control to construct | |
85 * | |
86 * @exception IllegalArgumentException <ul> | |
87 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
88 * </ul> | |
89 * @exception DWTException <ul> | |
90 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
91 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
92 * </ul> | |
93 * | |
94 * @see Widget#checkSubclass | |
95 * @see Widget#getStyle | |
96 */ | |
97 public this (ExpandBar parent, int style) { | |
98 super (parent, style); | |
99 this.parent = parent; | |
100 createWidget (parent.getItemCount ()); | |
101 } | |
102 | |
103 /** | |
104 * Constructs a new instance of this class given its parent, a | |
105 * style value describing its behavior and appearance, and the index | |
106 * at which to place it in the items maintained by its parent. | |
107 * <p> | |
108 * The style value is either one of the style constants defined in | |
109 * class <code>DWT</code> which is applicable to instances of this | |
110 * class, or must be built by <em>bitwise OR</em>'ing together | |
111 * (that is, using the <code>int</code> "|" operator) two or more | |
112 * of those <code>DWT</code> style constants. The class description | |
113 * lists the style constants that are applicable to the class. | |
114 * Style bits are also inherited from superclasses. | |
115 * </p> | |
116 * | |
117 * @param parent a composite control which will be the parent of the new instance (cannot be null) | |
118 * @param style the style of control to construct | |
119 * @param index the zero-relative index to store the receiver in its parent | |
120 * | |
121 * @exception IllegalArgumentException <ul> | |
122 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
123 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li> | |
124 * </ul> | |
125 * @exception DWTException <ul> | |
126 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
127 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
128 * </ul> | |
129 * | |
130 * @see Widget#checkSubclass | |
131 * @see Widget#getStyle | |
132 */ | |
133 public this (ExpandBar parent, int style, int index) { | |
134 super (parent, style); | |
135 this.parent = parent; | |
136 createWidget (index); | |
137 } | |
138 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
139 protected override void checkSubclass () { |
79 | 140 if (!isValidSubclass ()) error (DWT.ERROR_INVALID_SUBCLASS); |
141 } | |
142 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
143 override void createHandle (int index) { |
79 | 144 if (OS.GTK_VERSION >= OS.buildVERSION (2, 4, 0)) { |
145 state |= HANDLE; | |
146 handle = OS.gtk_expander_new (null); | |
147 if (handle is null) error (DWT.ERROR_NO_HANDLES); | |
148 clientHandle = cast(GtkWidget*)OS.g_object_new (display.gtk_fixed_get_type (), null); | |
149 if (clientHandle is null) error (DWT.ERROR_NO_HANDLES); | |
150 OS.gtk_container_add (handle, clientHandle); | |
151 boxHandle = cast(GtkWidget*)OS.gtk_hbox_new (false, 4); | |
152 if (boxHandle is null) error (DWT.ERROR_NO_HANDLES); | |
153 labelHandle = cast(GtkWidget*)OS.gtk_label_new (null); | |
154 if (labelHandle is null) error (DWT.ERROR_NO_HANDLES); | |
155 imageHandle = cast(GtkWidget*)OS.gtk_image_new (); | |
156 if (imageHandle is null) error (DWT.ERROR_NO_HANDLES); | |
157 OS.gtk_container_add (boxHandle, imageHandle); | |
158 OS.gtk_container_add (boxHandle, labelHandle); | |
159 OS.gtk_expander_set_label_widget (handle, boxHandle); | |
160 OS.GTK_WIDGET_SET_FLAGS (handle, OS.GTK_CAN_FOCUS); | |
161 } | |
162 } | |
163 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
164 override void createWidget (int index) { |
79 | 165 super.createWidget (index); |
166 showWidget (index); | |
167 parent.createItem (this, style, index); | |
168 } | |
169 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
170 override void deregister() { |
79 | 171 super.deregister(); |
172 if (OS.GTK_VERSION >= OS.buildVERSION (2, 4, 0)) { | |
173 display.removeWidget (clientHandle); | |
174 display.removeWidget (boxHandle); | |
175 display.removeWidget (labelHandle); | |
176 display.removeWidget (imageHandle); | |
177 } | |
178 } | |
179 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
180 override void destroyWidget () { |
79 | 181 parent.destroyItem (this); |
182 super.destroyWidget (); | |
183 } | |
184 | |
185 void drawChevron (GC gc, int x, int y) { | |
186 int [] polyline1, polyline2; | |
187 if (expanded) { | |
188 int px = x + 4 + 5; | |
189 int py = y + 4 + 7; | |
190 polyline1 = [ | |
191 px,py, px+1,py, px+1,py-1, px+2,py-1, px+2,py-2, px+3,py-2, px+3,py-3, | |
192 px+3,py-2, px+4,py-2, px+4,py-1, px+5,py-1, px+5,py, px+6,py]; | |
193 py += 4; | |
194 polyline2 = [ | |
195 px,py, px+1,py, px+1,py-1, px+2,py-1, px+2,py-2, px+3,py-2, px+3,py-3, | |
196 px+3,py-2, px+4,py-2, px+4,py-1, px+5,py-1, px+5,py, px+6,py]; | |
197 } else { | |
198 int px = x + 4 + 5; | |
199 int py = y + 4 + 4; | |
200 polyline1 = [ | |
201 px,py, px+1,py, px+1,py+1, px+2,py+1, px+2,py+2, px+3,py+2, px+3,py+3, | |
202 px+3,py+2, px+4,py+2, px+4,py+1, px+5,py+1, px+5,py, px+6,py]; | |
203 py += 4; | |
204 polyline2 = [ | |
205 px,py, px+1,py, px+1,py+1, px+2,py+1, px+2,py+2, px+3,py+2, px+3,py+3, | |
206 px+3,py+2, px+4,py+2, px+4,py+1, px+5,py+1, px+5,py, px+6,py]; | |
207 } | |
208 gc.setForeground (display.getSystemColor (DWT.COLOR_TITLE_FOREGROUND)); | |
209 gc.drawPolyline (polyline1); | |
210 gc.drawPolyline (polyline2); | |
211 } | |
212 | |
213 void drawItem (GC gc, bool drawFocus) { | |
214 int headerHeight = parent.getBandHeight (); | |
215 Display display = getDisplay (); | |
216 gc.setForeground (display.getSystemColor (DWT.COLOR_TITLE_BACKGROUND)); | |
217 gc.setBackground (display.getSystemColor (DWT.COLOR_TITLE_BACKGROUND_GRADIENT)); | |
218 gc.fillGradientRectangle (x, y, width, headerHeight, true); | |
219 if (expanded) { | |
220 gc.setForeground (display.getSystemColor (DWT.COLOR_TITLE_BACKGROUND_GRADIENT)); | |
221 gc.drawLine (x, y + headerHeight, x, y + headerHeight + height - 1); | |
222 gc.drawLine (x, y + headerHeight + height - 1, x + width - 1, y + headerHeight + height - 1); | |
223 gc.drawLine (x + width - 1, y + headerHeight + height - 1, x + width - 1, y + headerHeight); | |
224 } | |
225 int drawX = x; | |
226 if (image !is null) { | |
227 drawX += ExpandItem.TEXT_INSET; | |
228 if (imageHeight > headerHeight) { | |
229 gc.drawImage (image, drawX, y + headerHeight - imageHeight); | |
230 } else { | |
231 gc.drawImage (image, drawX, y + (headerHeight - imageHeight) / 2); | |
232 } | |
233 drawX += imageWidth; | |
234 } | |
235 if (text.length > 0) { | |
236 drawX += ExpandItem.TEXT_INSET; | |
237 Point size = gc.stringExtent (text); | |
238 gc.setForeground (parent.getForeground ()); | |
239 gc.drawString (text, drawX, y + (headerHeight - size.y) / 2, true); | |
240 } | |
241 int chevronSize = ExpandItem.CHEVRON_SIZE; | |
242 drawChevron (gc, x + width - chevronSize, y + (headerHeight - chevronSize) / 2); | |
243 if (drawFocus) { | |
244 gc.drawFocus (x + 1, y + 1, width - 2, headerHeight - 2); | |
245 } | |
246 } | |
247 | |
248 /** | |
249 * Returns the control that is shown when the item is expanded. | |
250 * If no control has been set, return <code>null</code>. | |
251 * | |
252 * @return the control | |
253 * | |
254 * @exception DWTException <ul> | |
255 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
256 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
257 * </ul> | |
258 */ | |
259 public Control getControl () { | |
260 checkWidget (); | |
261 return control; | |
262 } | |
263 | |
264 /** | |
265 * Returns <code>true</code> if the receiver is expanded, | |
266 * and false otherwise. | |
267 * | |
268 * @return the expanded state | |
269 * | |
270 * @exception DWTException <ul> | |
271 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
272 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
273 * </ul> | |
274 */ | |
275 public bool getExpanded () { | |
276 checkWidget (); | |
277 return expanded; | |
278 } | |
279 | |
280 /** | |
281 * Returns the height of the receiver's header | |
282 * | |
283 * @return the height of the header | |
284 * | |
285 * @exception DWTException <ul> | |
286 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
287 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
288 * </ul> | |
289 */ | |
290 public int getHeaderHeight () { | |
291 checkWidget (); | |
292 if (OS.GTK_VERSION >= OS.buildVERSION (2, 4, 0)) { | |
240 | 293 return OS.GTK_WIDGET_HEIGHT (handle) - (expanded ? height : 0); |
79 | 294 } |
295 return Math.max (parent.getBandHeight (), imageHeight); | |
296 } | |
297 | |
298 /** | |
299 * Gets the height of the receiver. | |
300 * | |
301 * @return the height | |
302 * | |
303 * @exception DWTException <ul> | |
304 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
305 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
306 * </ul> | |
307 */ | |
308 public int getHeight () { | |
309 checkWidget (); | |
310 return height; | |
311 } | |
312 | |
313 /** | |
314 * Returns the receiver's parent, which must be a <code>ExpandBar</code>. | |
315 * | |
316 * @return the receiver's parent | |
317 * | |
318 * @exception DWTException <ul> | |
319 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
320 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
321 * </ul> | |
322 */ | |
323 public ExpandBar getParent () { | |
324 checkWidget(); | |
325 return parent; | |
326 } | |
327 | |
328 int getPreferredWidth (GC gc) { | |
329 int width = ExpandItem.TEXT_INSET * 2 + ExpandItem.CHEVRON_SIZE; | |
330 if (image !is null) { | |
331 width += ExpandItem.TEXT_INSET + imageWidth; | |
332 } | |
333 if (text.length > 0) { | |
334 width += gc.stringExtent (text).x; | |
335 } | |
336 return width; | |
337 } | |
338 | |
339 override int /*long*/ gtk_activate (GtkWidget* widget) { | |
340 Event event = new Event (); | |
341 event.item = this; | |
342 int type = OS.gtk_expander_get_expanded (handle) ? DWT.Collapse : DWT.Expand; | |
343 parent.sendEvent (type, event); | |
344 return 0; | |
345 } | |
346 | |
347 override int /*long*/ gtk_button_press_event (GtkWidget* widget, GdkEventButton* event) { | |
348 setFocus (); | |
349 return 0; | |
350 } | |
351 | |
352 override int /*long*/ gtk_focus_out_event (GtkWidget* widget, GdkEventFocus* event) { | |
353 OS.GTK_WIDGET_UNSET_FLAGS (handle, OS.GTK_CAN_FOCUS); | |
354 parent.lastFocus = this; | |
355 return 0; | |
356 } | |
357 | |
358 override int /*long*/ gtk_size_allocate (GtkWidget* widget, int /*long*/ allocation) { | |
359 parent.layoutItems (0, false); | |
360 return 0; | |
361 } | |
362 | |
363 override int /*long*/ gtk_enter_notify_event (GtkWidget* widget, GdkEventCrossing* event) { | |
364 parent.gtk_enter_notify_event(widget, event); | |
365 return 0; | |
366 } | |
367 | |
368 bool hasFocus () { | |
369 return OS.GTK_WIDGET_HAS_FOCUS (handle); | |
370 } | |
371 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
372 override void hookEvents () { |
79 | 373 super.hookEvents (); |
374 if (OS.GTK_VERSION >= OS.buildVERSION (2, 4, 0)) { | |
375 OS.g_signal_connect_closure (handle, OS.activate.ptr, display.closures [ACTIVATE], false); | |
376 OS.g_signal_connect_closure (handle, OS.activate.ptr, display.closures [ACTIVATE_INVERSE], true); | |
377 OS.g_signal_connect_closure_by_id (handle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT], false); | |
378 OS.g_signal_connect_closure_by_id (handle, display.signalIds [FOCUS_OUT_EVENT], 0, display.closures [FOCUS_OUT_EVENT], false); | |
379 OS.g_signal_connect_closure (clientHandle, OS.size_allocate.ptr, display.closures [SIZE_ALLOCATE], true); | |
380 OS.g_signal_connect_closure_by_id (handle, display.signalIds [ENTER_NOTIFY_EVENT], 0, display.closures [ENTER_NOTIFY_EVENT], false); | |
381 } | |
382 } | |
383 | |
384 void redraw () { | |
385 if (OS.GTK_VERSION < OS.buildVERSION (2, 4, 0)) { | |
386 int headerHeight = parent.getBandHeight (); | |
387 if (imageHeight > headerHeight) { | |
388 parent.redraw (x + ExpandItem.TEXT_INSET, y + headerHeight - imageHeight, imageWidth, imageHeight, false); | |
389 } | |
390 parent.redraw (x, y, width, headerHeight + height, false); | |
391 } | |
392 } | |
393 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
394 override void register () { |
79 | 395 super.register (); |
396 if (OS.GTK_VERSION >= OS.buildVERSION (2, 4, 0)) { | |
397 display.addWidget (clientHandle, this); | |
398 display.addWidget (boxHandle, this); | |
399 display.addWidget (labelHandle, this); | |
400 display.addWidget (imageHandle, this); | |
401 } | |
402 } | |
403 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
404 override void releaseHandle () { |
79 | 405 super.releaseHandle (); |
406 clientHandle = boxHandle = labelHandle = imageHandle = null; | |
407 parent = null; | |
408 } | |
409 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
410 override void releaseWidget () { |
79 | 411 super.releaseWidget (); |
412 if (imageList !is null) imageList.dispose (); | |
413 if (OS.GTK_VERSION >= OS.buildVERSION (2, 4, 0)) { | |
414 if (parent.lastFocus is this) parent.lastFocus = null; | |
415 } | |
416 imageList = null; | |
417 control = null; | |
418 } | |
419 | |
420 void resizeControl (int yScroll) { | |
421 if (control !is null && !control.isDisposed ()) { | |
422 bool visible =cast(bool) OS.gtk_expander_get_expanded (handle); | |
423 if (visible) { | |
424 int x = OS.GTK_WIDGET_X (clientHandle); | |
425 int y = OS.GTK_WIDGET_Y (clientHandle); | |
426 if (x !is -1 && y !is -1) { | |
427 int width = OS.GTK_WIDGET_WIDTH (clientHandle); | |
428 int height = OS.GTK_WIDGET_HEIGHT (clientHandle); | |
429 int property; | |
430 OS.gtk_widget_style_get1 (handle, OS.focus_line_width.ptr, &property); | |
431 y += property * 2; | |
432 height -= property * 2; | |
433 control.setBounds (x, y - yScroll, width, Math.max (0, height), true, true); | |
434 } | |
435 } | |
436 control.setVisible (visible); | |
437 } | |
438 } | |
439 | |
440 void setBounds (int x, int y, int width, int height, bool move, bool size) { | |
441 redraw (); | |
442 int headerHeight = parent.getBandHeight (); | |
443 if (move) { | |
444 if (imageHeight > headerHeight) { | |
445 y += (imageHeight - headerHeight); | |
446 } | |
447 this.x = x; | |
448 this.y = y; | |
449 redraw (); | |
450 } | |
451 if (size) { | |
452 this.width = width; | |
453 this.height = height; | |
454 redraw (); | |
455 } | |
456 if (control !is null && !control.isDisposed ()) { | |
457 if (move) control.setLocation (x + BORDER, y + headerHeight); | |
458 if (size) control.setSize (Math.max (0, width - 2 * BORDER), Math.max (0, height - BORDER)); | |
459 } | |
460 } | |
461 | |
462 /** | |
463 * Sets the control that is shown when the item is expanded. | |
464 * | |
465 * @param control the new control (or null) | |
466 * | |
467 * @exception IllegalArgumentException <ul> | |
468 * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li> | |
469 * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li> | |
470 * </ul> | |
471 * @exception DWTException <ul> | |
472 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
473 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
474 * </ul> | |
475 */ | |
476 public void setControl (Control control) { | |
477 checkWidget (); | |
478 if (control !is null) { | |
479 if (control.isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT); | |
480 if (control.parent !is parent) error (DWT.ERROR_INVALID_PARENT); | |
481 } | |
482 if (this.control is control) return; | |
483 this.control = control; | |
484 if (control !is null) { | |
485 control.setVisible (expanded); | |
486 if (OS.GTK_VERSION < OS.buildVERSION (2, 4, 0)) { | |
487 int headerHeight = parent.getBandHeight (); | |
488 control.setBounds (x + BORDER, y + headerHeight, Math.max (0, width - 2 * BORDER), Math.max (0, height - BORDER)); | |
489 } | |
490 } | |
491 if (OS.GTK_VERSION >= OS.buildVERSION (2, 4, 0)) { | |
492 parent.layoutItems (0, true); | |
493 } | |
494 } | |
495 | |
496 /** | |
497 * Sets the expanded state of the receiver. | |
498 * | |
499 * @param expanded the new expanded state | |
500 * | |
501 * @exception DWTException <ul> | |
502 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
503 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
504 * </ul> | |
505 */ | |
506 public void setExpanded (bool expanded) { | |
507 checkWidget (); | |
508 this.expanded = expanded; | |
509 if (OS.GTK_VERSION >= OS.buildVERSION (2, 4, 0)) { | |
510 OS.gtk_expander_set_expanded (handle, expanded); | |
511 parent.layoutItems (0, true); | |
512 } else { | |
513 parent.showItem (this); | |
514 } | |
515 } | |
516 | |
517 bool setFocus () { | |
518 if (!OS.gtk_widget_get_child_visible (handle)) return false; | |
519 OS.GTK_WIDGET_SET_FLAGS (handle, OS.GTK_CAN_FOCUS); | |
520 OS.gtk_widget_grab_focus (handle); | |
521 bool result = cast(bool)OS.gtk_widget_is_focus (handle); | |
522 if (!result) OS.GTK_WIDGET_UNSET_FLAGS (handle, OS.GTK_CAN_FOCUS); | |
523 return result; | |
524 } | |
525 | |
526 void setFontDescription (PangoFontDescription* font) { | |
527 OS.gtk_widget_modify_font (handle, font); | |
528 if (labelHandle !is null) OS.gtk_widget_modify_font (labelHandle, font); | |
529 if (imageHandle !is null) OS.gtk_widget_modify_font (imageHandle, font); | |
530 } | |
531 | |
532 alias Item.setForegroundColor setForegroundColor; | |
533 void setForegroundColor (GdkColor* color) { | |
534 setForegroundColor (handle, color); | |
535 if (labelHandle !is null) setForegroundColor (labelHandle, color); | |
536 if (imageHandle !is null) setForegroundColor (imageHandle, color); | |
537 } | |
538 | |
539 /** | |
540 * Sets the height of the receiver. This is height of the item when it is expanded, | |
541 * excluding the height of the header. | |
542 * | |
543 * @param height the new height | |
544 * | |
545 * @exception DWTException <ul> | |
546 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
547 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
548 * </ul> | |
549 */ | |
550 public void setHeight (int height) { | |
551 checkWidget (); | |
552 if (height < 0) return; | |
553 if (OS.GTK_VERSION >= OS.buildVERSION (2, 4, 0)) { | |
554 this.height = height; | |
555 OS.gtk_widget_set_size_request (clientHandle, -1, height); | |
556 parent.layoutItems (0, false); | |
557 } else { | |
558 setBounds (0, 0, width, height, false, true); | |
559 if (expanded) parent.layoutItems (parent.indexOf (this) + 1, true); | |
560 } | |
561 } | |
562 | |
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
563 public override void setImage (Image image) { |
79 | 564 super.setImage (image); |
565 if (OS.GTK_VERSION >= OS.buildVERSION (2, 4, 0)) { | |
566 if (imageList !is null) imageList.dispose (); | |
567 imageList = null; | |
568 if (image !is null) { | |
569 if (image.isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT); | |
570 imageList = new ImageList (); | |
571 int imageIndex = imageList.add (image); | |
572 auto pixbuf = imageList.getPixbuf (imageIndex); | |
573 OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf); | |
574 if (text.length is 0) OS.gtk_widget_hide (labelHandle); | |
575 OS.gtk_widget_show (imageHandle); | |
576 } else { | |
577 OS.gtk_image_set_from_pixbuf (imageHandle, null); | |
578 OS.gtk_widget_show (labelHandle); | |
579 OS.gtk_widget_hide (imageHandle); | |
580 } | |
581 } else { | |
582 int oldImageHeight = imageHeight; | |
583 if (image !is null) { | |
584 Rectangle bounds = image.getBounds (); | |
585 imageHeight = bounds.height; | |
586 imageWidth = bounds.width; | |
587 } else { | |
588 imageHeight = imageWidth = 0; | |
589 } | |
590 if (oldImageHeight !is imageHeight) { | |
591 parent.layoutItems (parent.indexOf (this), true); | |
592 } else { | |
593 redraw (); | |
594 } | |
595 } | |
596 } | |
597 | |
240 | 598 void setOrientation() { |
599 super.setOrientation (); | |
600 if ((parent.style & DWT.RIGHT_TO_LEFT) !is 0) { | |
601 OS.gtk_widget_set_direction (handle, OS.GTK_TEXT_DIR_RTL); | |
602 display.doSetDirectionProc(handle, OS.GTK_TEXT_DIR_RTL); | |
603 } | |
604 } | |
605 | |
238 | 606 public override void setText (String string) { |
79 | 607 super.setText (string); |
608 if (OS.GTK_VERSION >= OS.buildVERSION (2, 4, 0)) { | |
609 OS.gtk_label_set_text (labelHandle, tango.stdc.stringz.toStringz(string)); | |
610 } else { | |
611 redraw (); | |
612 } | |
613 } | |
614 | |
615 void showWidget (int index) { | |
616 if (OS.GTK_VERSION >= OS.buildVERSION (2, 4, 0)) { | |
617 OS.gtk_widget_show (handle); | |
618 OS.gtk_widget_show (clientHandle); | |
619 OS.gtk_container_add (parent.handle, handle); | |
620 OS.gtk_box_set_child_packing (parent.handle, handle, false, false, 0, OS.GTK_PACK_START); | |
621 if (boxHandle !is null) OS.gtk_widget_show (boxHandle); | |
622 if (labelHandle !is null) OS.gtk_widget_show (labelHandle); | |
623 } | |
624 } | |
625 | |
626 override int /*long*/ windowProc (GtkWidget* handle, int /*long*/ user_data) { | |
627 switch (cast(int)/*64*/user_data) { | |
628 case ACTIVATE_INVERSE: { | |
629 expanded = cast(bool)OS.gtk_expander_get_expanded (handle); | |
630 parent.layoutItems (0, false); | |
631 return 0; | |
632 } | |
633 default: | |
634 } | |
635 return super.windowProc (handle, user_data); | |
636 } | |
637 } |