Mercurial > projects > dwt-linux
annotate dwt/widgets/ExpandItem.d @ 238:380bad9f6852
reverted char[] to String
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 05 May 2008 00:42:55 +0200 |
parents | 17f8449522fd |
children | ce446666f5a2 |
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)) { | |
293 auto widget = OS.gtk_expander_get_label_widget (handle); | |
294 return OS.GTK_WIDGET_HEIGHT (widget); | |
295 } | |
296 return Math.max (parent.getBandHeight (), imageHeight); | |
297 } | |
298 | |
299 /** | |
300 * Gets the height of the receiver. | |
301 * | |
302 * @return the height | |
303 * | |
304 * @exception DWTException <ul> | |
305 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
306 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
307 * </ul> | |
308 */ | |
309 public int getHeight () { | |
310 checkWidget (); | |
311 return height; | |
312 } | |
313 | |
314 /** | |
315 * Returns the receiver's parent, which must be a <code>ExpandBar</code>. | |
316 * | |
317 * @return the receiver's parent | |
318 * | |
319 * @exception DWTException <ul> | |
320 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
321 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
322 * </ul> | |
323 */ | |
324 public ExpandBar getParent () { | |
325 checkWidget(); | |
326 return parent; | |
327 } | |
328 | |
329 int getPreferredWidth (GC gc) { | |
330 int width = ExpandItem.TEXT_INSET * 2 + ExpandItem.CHEVRON_SIZE; | |
331 if (image !is null) { | |
332 width += ExpandItem.TEXT_INSET + imageWidth; | |
333 } | |
334 if (text.length > 0) { | |
335 width += gc.stringExtent (text).x; | |
336 } | |
337 return width; | |
338 } | |
339 | |
340 override int /*long*/ gtk_activate (GtkWidget* widget) { | |
341 Event event = new Event (); | |
342 event.item = this; | |
343 int type = OS.gtk_expander_get_expanded (handle) ? DWT.Collapse : DWT.Expand; | |
344 parent.sendEvent (type, event); | |
345 return 0; | |
346 } | |
347 | |
348 override int /*long*/ gtk_button_press_event (GtkWidget* widget, GdkEventButton* event) { | |
349 setFocus (); | |
350 return 0; | |
351 } | |
352 | |
353 override int /*long*/ gtk_focus_out_event (GtkWidget* widget, GdkEventFocus* event) { | |
354 OS.GTK_WIDGET_UNSET_FLAGS (handle, OS.GTK_CAN_FOCUS); | |
355 parent.lastFocus = this; | |
356 return 0; | |
357 } | |
358 | |
359 override int /*long*/ gtk_size_allocate (GtkWidget* widget, int /*long*/ allocation) { | |
360 parent.layoutItems (0, false); | |
361 return 0; | |
362 } | |
363 | |
364 override int /*long*/ gtk_enter_notify_event (GtkWidget* widget, GdkEventCrossing* event) { | |
365 parent.gtk_enter_notify_event(widget, event); | |
366 return 0; | |
367 } | |
368 | |
369 bool hasFocus () { | |
370 return OS.GTK_WIDGET_HAS_FOCUS (handle); | |
371 } | |
372 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
373 override void hookEvents () { |
79 | 374 super.hookEvents (); |
375 if (OS.GTK_VERSION >= OS.buildVERSION (2, 4, 0)) { | |
376 OS.g_signal_connect_closure (handle, OS.activate.ptr, display.closures [ACTIVATE], false); | |
377 OS.g_signal_connect_closure (handle, OS.activate.ptr, display.closures [ACTIVATE_INVERSE], true); | |
378 OS.g_signal_connect_closure_by_id (handle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT], false); | |
379 OS.g_signal_connect_closure_by_id (handle, display.signalIds [FOCUS_OUT_EVENT], 0, display.closures [FOCUS_OUT_EVENT], false); | |
380 OS.g_signal_connect_closure (clientHandle, OS.size_allocate.ptr, display.closures [SIZE_ALLOCATE], true); | |
381 OS.g_signal_connect_closure_by_id (handle, display.signalIds [ENTER_NOTIFY_EVENT], 0, display.closures [ENTER_NOTIFY_EVENT], false); | |
382 } | |
383 } | |
384 | |
385 void redraw () { | |
386 if (OS.GTK_VERSION < OS.buildVERSION (2, 4, 0)) { | |
387 int headerHeight = parent.getBandHeight (); | |
388 if (imageHeight > headerHeight) { | |
389 parent.redraw (x + ExpandItem.TEXT_INSET, y + headerHeight - imageHeight, imageWidth, imageHeight, false); | |
390 } | |
391 parent.redraw (x, y, width, headerHeight + height, false); | |
392 } | |
393 } | |
394 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
395 override void register () { |
79 | 396 super.register (); |
397 if (OS.GTK_VERSION >= OS.buildVERSION (2, 4, 0)) { | |
398 display.addWidget (clientHandle, this); | |
399 display.addWidget (boxHandle, this); | |
400 display.addWidget (labelHandle, this); | |
401 display.addWidget (imageHandle, this); | |
402 } | |
403 } | |
404 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
405 override void releaseHandle () { |
79 | 406 super.releaseHandle (); |
407 clientHandle = boxHandle = labelHandle = imageHandle = null; | |
408 parent = null; | |
409 } | |
410 | |
152
17f8449522fd
overloads second walkthrough
Frank Benoit <benoit@tionex.de>
parents:
150
diff
changeset
|
411 override void releaseWidget () { |
79 | 412 super.releaseWidget (); |
413 if (imageList !is null) imageList.dispose (); | |
414 if (OS.GTK_VERSION >= OS.buildVERSION (2, 4, 0)) { | |
415 if (parent.lastFocus is this) parent.lastFocus = null; | |
416 } | |
417 imageList = null; | |
418 control = null; | |
419 } | |
420 | |
421 void resizeControl (int yScroll) { | |
422 if (control !is null && !control.isDisposed ()) { | |
423 bool visible =cast(bool) OS.gtk_expander_get_expanded (handle); | |
424 if (visible) { | |
425 int x = OS.GTK_WIDGET_X (clientHandle); | |
426 int y = OS.GTK_WIDGET_Y (clientHandle); | |
427 if (x !is -1 && y !is -1) { | |
428 int width = OS.GTK_WIDGET_WIDTH (clientHandle); | |
429 int height = OS.GTK_WIDGET_HEIGHT (clientHandle); | |
430 int property; | |
431 OS.gtk_widget_style_get1 (handle, OS.focus_line_width.ptr, &property); | |
432 y += property * 2; | |
433 height -= property * 2; | |
434 control.setBounds (x, y - yScroll, width, Math.max (0, height), true, true); | |
435 } | |
436 } | |
437 control.setVisible (visible); | |
438 } | |
439 } | |
440 | |
441 void setBounds (int x, int y, int width, int height, bool move, bool size) { | |
442 redraw (); | |
443 int headerHeight = parent.getBandHeight (); | |
444 if (move) { | |
445 if (imageHeight > headerHeight) { | |
446 y += (imageHeight - headerHeight); | |
447 } | |
448 this.x = x; | |
449 this.y = y; | |
450 redraw (); | |
451 } | |
452 if (size) { | |
453 this.width = width; | |
454 this.height = height; | |
455 redraw (); | |
456 } | |
457 if (control !is null && !control.isDisposed ()) { | |
458 if (move) control.setLocation (x + BORDER, y + headerHeight); | |
459 if (size) control.setSize (Math.max (0, width - 2 * BORDER), Math.max (0, height - BORDER)); | |
460 } | |
461 } | |
462 | |
463 /** | |
464 * Sets the control that is shown when the item is expanded. | |
465 * | |
466 * @param control the new control (or null) | |
467 * | |
468 * @exception IllegalArgumentException <ul> | |
469 * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li> | |
470 * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</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 public void setControl (Control control) { | |
478 checkWidget (); | |
479 if (control !is null) { | |
480 if (control.isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT); | |
481 if (control.parent !is parent) error (DWT.ERROR_INVALID_PARENT); | |
482 } | |
483 if (this.control is control) return; | |
484 this.control = control; | |
485 if (control !is null) { | |
486 control.setVisible (expanded); | |
487 if (OS.GTK_VERSION < OS.buildVERSION (2, 4, 0)) { | |
488 int headerHeight = parent.getBandHeight (); | |
489 control.setBounds (x + BORDER, y + headerHeight, Math.max (0, width - 2 * BORDER), Math.max (0, height - BORDER)); | |
490 } | |
491 } | |
492 if (OS.GTK_VERSION >= OS.buildVERSION (2, 4, 0)) { | |
493 parent.layoutItems (0, true); | |
494 } | |
495 } | |
496 | |
497 /** | |
498 * Sets the expanded state of the receiver. | |
499 * | |
500 * @param expanded the new expanded state | |
501 * | |
502 * @exception DWTException <ul> | |
503 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
504 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
505 * </ul> | |
506 */ | |
507 public void setExpanded (bool expanded) { | |
508 checkWidget (); | |
509 this.expanded = expanded; | |
510 if (OS.GTK_VERSION >= OS.buildVERSION (2, 4, 0)) { | |
511 OS.gtk_expander_set_expanded (handle, expanded); | |
512 parent.layoutItems (0, true); | |
513 } else { | |
514 parent.showItem (this); | |
515 } | |
516 } | |
517 | |
518 bool setFocus () { | |
519 if (!OS.gtk_widget_get_child_visible (handle)) return false; | |
520 OS.GTK_WIDGET_SET_FLAGS (handle, OS.GTK_CAN_FOCUS); | |
521 OS.gtk_widget_grab_focus (handle); | |
522 bool result = cast(bool)OS.gtk_widget_is_focus (handle); | |
523 if (!result) OS.GTK_WIDGET_UNSET_FLAGS (handle, OS.GTK_CAN_FOCUS); | |
524 return result; | |
525 } | |
526 | |
527 void setFontDescription (PangoFontDescription* font) { | |
528 OS.gtk_widget_modify_font (handle, font); | |
529 if (labelHandle !is null) OS.gtk_widget_modify_font (labelHandle, font); | |
530 if (imageHandle !is null) OS.gtk_widget_modify_font (imageHandle, font); | |
531 } | |
532 | |
533 alias Item.setForegroundColor setForegroundColor; | |
534 void setForegroundColor (GdkColor* color) { | |
535 setForegroundColor (handle, color); | |
536 if (labelHandle !is null) setForegroundColor (labelHandle, color); | |
537 if (imageHandle !is null) setForegroundColor (imageHandle, color); | |
538 } | |
539 | |
540 /** | |
541 * Sets the height of the receiver. This is height of the item when it is expanded, | |
542 * excluding the height of the header. | |
543 * | |
544 * @param height the new height | |
545 * | |
546 * @exception DWTException <ul> | |
547 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
548 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
549 * </ul> | |
550 */ | |
551 public void setHeight (int height) { | |
552 checkWidget (); | |
553 if (height < 0) return; | |
554 if (OS.GTK_VERSION >= OS.buildVERSION (2, 4, 0)) { | |
555 this.height = height; | |
556 OS.gtk_widget_set_size_request (clientHandle, -1, height); | |
557 parent.layoutItems (0, false); | |
558 } else { | |
559 setBounds (0, 0, width, height, false, true); | |
560 if (expanded) parent.layoutItems (parent.indexOf (this) + 1, true); | |
561 } | |
562 } | |
563 | |
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
564 public override void setImage (Image image) { |
79 | 565 super.setImage (image); |
566 if (OS.GTK_VERSION >= OS.buildVERSION (2, 4, 0)) { | |
567 if (imageList !is null) imageList.dispose (); | |
568 imageList = null; | |
569 if (image !is null) { | |
570 if (image.isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT); | |
571 imageList = new ImageList (); | |
572 int imageIndex = imageList.add (image); | |
573 auto pixbuf = imageList.getPixbuf (imageIndex); | |
574 OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf); | |
575 if (text.length is 0) OS.gtk_widget_hide (labelHandle); | |
576 OS.gtk_widget_show (imageHandle); | |
577 } else { | |
578 OS.gtk_image_set_from_pixbuf (imageHandle, null); | |
579 OS.gtk_widget_show (labelHandle); | |
580 OS.gtk_widget_hide (imageHandle); | |
581 } | |
582 } else { | |
583 int oldImageHeight = imageHeight; | |
584 if (image !is null) { | |
585 Rectangle bounds = image.getBounds (); | |
586 imageHeight = bounds.height; | |
587 imageWidth = bounds.width; | |
588 } else { | |
589 imageHeight = imageWidth = 0; | |
590 } | |
591 if (oldImageHeight !is imageHeight) { | |
592 parent.layoutItems (parent.indexOf (this), true); | |
593 } else { | |
594 redraw (); | |
595 } | |
596 } | |
597 } | |
598 | |
238 | 599 public override void setText (String string) { |
79 | 600 super.setText (string); |
601 if (OS.GTK_VERSION >= OS.buildVERSION (2, 4, 0)) { | |
602 OS.gtk_label_set_text (labelHandle, tango.stdc.stringz.toStringz(string)); | |
603 } else { | |
604 redraw (); | |
605 } | |
606 } | |
607 | |
608 void showWidget (int index) { | |
609 if (OS.GTK_VERSION >= OS.buildVERSION (2, 4, 0)) { | |
610 OS.gtk_widget_show (handle); | |
611 OS.gtk_widget_show (clientHandle); | |
612 OS.gtk_container_add (parent.handle, handle); | |
613 OS.gtk_box_set_child_packing (parent.handle, handle, false, false, 0, OS.GTK_PACK_START); | |
614 if (boxHandle !is null) OS.gtk_widget_show (boxHandle); | |
615 if (labelHandle !is null) OS.gtk_widget_show (labelHandle); | |
616 } | |
617 } | |
618 | |
619 override int /*long*/ windowProc (GtkWidget* handle, int /*long*/ user_data) { | |
620 switch (cast(int)/*64*/user_data) { | |
621 case ACTIVATE_INVERSE: { | |
622 expanded = cast(bool)OS.gtk_expander_get_expanded (handle); | |
623 parent.layoutItems (0, false); | |
624 return 0; | |
625 } | |
626 default: | |
627 } | |
628 return super.windowProc (handle, user_data); | |
629 } | |
630 } |