Mercurial > projects > dwt-linux
annotate dwt/widgets/ColorDialog.d @ 255:5a30aa9820f3
removed tango.stdc.stringz imports and allow null for arrays and string arguments.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 15 Jun 2008 22:32:20 +0200 |
parents | ce446666f5a2 |
children | c0d810de7093 |
rev | line source |
---|---|
240 | 1 /******************************************************************************* |
77 | 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> | |
77 | 12 *******************************************************************************/ |
13 module dwt.widgets.ColorDialog; | |
14 | |
15 import dwt.DWT; | |
16 import dwt.DWTException; | |
17 import dwt.graphics.PaletteData; | |
18 import dwt.graphics.RGB; | |
19 import dwt.internal.gtk.OS; | |
20 import dwt.widgets.Dialog; | |
21 import dwt.widgets.Shell; | |
22 import dwt.widgets.Display; | |
23 | |
255
5a30aa9820f3
removed tango.stdc.stringz imports and allow null for arrays and string arguments.
Frank Benoit <benoit@tionex.de>
parents:
240
diff
changeset
|
24 import dwt.dwthelper.utils; |
77 | 25 |
26 /** | |
27 * Instances of this class allow the user to select a color | |
28 * from a predefined set of available colors. | |
29 * <dl> | |
30 * <dt><b>Styles:</b></dt> | |
31 * <dd>(none)</dd> | |
32 * <dt><b>Events:</b></dt> | |
33 * <dd>(none)</dd> | |
34 * </dl> | |
35 * <p> | |
36 * IMPORTANT: This class is intended to be subclassed <em>only</em> | |
37 * within the DWT implementation. | |
38 * </p> | |
39 */ | |
40 public class ColorDialog : Dialog { | |
41 RGB rgb; | |
42 /** | |
43 * Constructs a new instance of this class given only its parent. | |
44 * | |
45 * @param parent a composite control which will be the parent of the new instance | |
46 * | |
47 * @exception IllegalArgumentException <ul> | |
48 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
49 * </ul> | |
50 * @exception DWTException <ul> | |
51 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
52 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
53 * </ul> | |
54 * | |
55 * @see DWT | |
56 * @see Widget#checkSubclass | |
57 * @see Widget#getStyle | |
58 */ | |
59 public this (Shell parent) { | |
240 | 60 this (parent, DWT.APPLICATION_MODAL); |
77 | 61 } |
62 /** | |
63 * Constructs a new instance of this class given its parent | |
64 * and a style value describing its behavior and appearance. | |
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 | |
87 * @see Widget#checkSubclass | |
88 * @see Widget#getStyle | |
89 */ | |
90 public this (Shell parent, int style) { | |
240 | 91 super (parent, checkStyle (parent, style)); |
77 | 92 checkSubclass (); |
93 } | |
94 | |
95 /** | |
96 * Returns the currently selected color in the receiver. | |
97 * | |
98 * @return the RGB value for the selected color, may be null | |
99 * | |
100 * @see PaletteData#getRGBs | |
101 */ | |
102 public RGB getRGB () { | |
103 return rgb; | |
104 } | |
105 /** | |
106 * Makes the receiver visible and brings it to the front | |
107 * of the display. | |
108 * | |
109 * @return the selected color, or null if the dialog was | |
110 * cancelled, no color was selected, or an error | |
111 * occurred | |
112 * | |
113 * @exception DWTException <ul> | |
114 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
115 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
116 * </ul> | |
117 */ | |
118 public RGB open () { | |
119 char* buffer = toStringz(title); | |
120 auto handle = cast(GtkWidget*)OS.gtk_color_selection_dialog_new (buffer); | |
240 | 121 Display display = parent !is null ? parent.getDisplay (): Display.getCurrent (); |
77 | 122 if (parent !is null) { |
123 auto shellHandle = parent.topHandle (); | |
124 OS.gtk_window_set_transient_for (handle, shellHandle); | |
125 auto pixbufs = OS.gtk_window_get_icon_list (shellHandle); | |
126 if (pixbufs !is null) { | |
127 OS.gtk_window_set_icon_list (handle, pixbufs); | |
128 OS.g_list_free (pixbufs); | |
129 } | |
130 } | |
131 GtkColorSelectionDialog* dialog = cast(GtkColorSelectionDialog*)handle; | |
132 GdkColor color; | |
133 if (rgb !is null) { | |
134 color.red = cast(short)((rgb.red & 0xFF) | ((rgb.red & 0xFF) << 8)); | |
135 color.green = cast(short)((rgb.green & 0xFF) | ((rgb.green & 0xFF) << 8)); | |
136 color.blue = cast(short)((rgb.blue & 0xFF) | ((rgb.blue & 0xFF) << 8)); | |
137 OS.gtk_color_selection_set_current_color (dialog.colorsel, &color); | |
138 } | |
139 OS.gtk_color_selection_set_has_palette (dialog.colorsel, true); | |
140 display.addIdleProc (); | |
240 | 141 Dialog oldModal = null; |
142 if (OS.gtk_window_get_modal (handle)) { | |
143 oldModal = display.getModalDialog (); | |
144 display.setModalDialog (this); | |
145 } | |
146 int signalId = 0; | |
147 int /*long*/ hookId = 0; | |
148 CallbackData emissionData; | |
149 emissionData.display = display; | |
150 emissionData.data = handle; | |
151 if ((style & DWT.RIGHT_TO_LEFT) !is 0) { | |
152 signalId = OS.g_signal_lookup (OS.map.ptr, OS.GTK_TYPE_WIDGET()); | |
153 hookId = OS.g_signal_add_emission_hook (signalId, 0, &Display.emissionFunc, &emissionData, null); | |
154 } | |
77 | 155 int response = OS.gtk_dialog_run (handle); |
240 | 156 if ((style & DWT.RIGHT_TO_LEFT) !is 0) { |
157 OS.g_signal_remove_emission_hook (signalId, hookId); | |
158 } | |
159 if (OS.gtk_window_get_modal (handle)) { | |
160 display.setModalDialog (oldModal); | |
161 } | |
77 | 162 bool success = response is OS.GTK_RESPONSE_OK; |
163 if (success) { | |
164 OS.gtk_color_selection_get_current_color (dialog.colorsel, &color); | |
165 int red = (color.red >> 8) & 0xFF; | |
166 int green = (color.green >> 8) & 0xFF; | |
167 int blue = (color.blue >> 8) & 0xFF; | |
168 rgb = new RGB (red, green, blue); | |
169 } | |
170 display.removeIdleProc (); | |
171 OS.gtk_widget_destroy (handle); | |
172 if (!success) return null; | |
173 return rgb; | |
174 } | |
175 /** | |
176 * Sets the receiver's selected color to be the argument. | |
177 * | |
178 * @param rgb the new RGB value for the selected color, may be | |
179 * null to let the platform select a default when | |
180 * open() is called | |
181 * @see PaletteData#getRGBs | |
182 */ | |
183 public void setRGB (RGB rgb) { | |
184 this.rgb = rgb; | |
185 } | |
186 } |