Mercurial > projects > dwt-linux
annotate dwt/widgets/ColorDialog.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 |
---|---|
240 | 1 /******************************************************************************* |
259 | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
77 | 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> | |
259 | 39 * |
40 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample, Dialog tab</a> | |
41 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> | |
77 | 42 */ |
43 public class ColorDialog : Dialog { | |
44 RGB rgb; | |
45 /** | |
46 * Constructs a new instance of this class given only its parent. | |
47 * | |
48 * @param parent a composite control which will be the parent of the new instance | |
49 * | |
50 * @exception IllegalArgumentException <ul> | |
51 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
52 * </ul> | |
53 * @exception DWTException <ul> | |
54 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
55 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
56 * </ul> | |
57 * | |
58 * @see DWT | |
59 * @see Widget#checkSubclass | |
60 * @see Widget#getStyle | |
61 */ | |
62 public this (Shell parent) { | |
240 | 63 this (parent, DWT.APPLICATION_MODAL); |
77 | 64 } |
65 /** | |
66 * Constructs a new instance of this class given its parent | |
67 * and a style value describing its behavior and appearance. | |
68 * <p> | |
69 * The style value is either one of the style constants defined in | |
70 * class <code>DWT</code> which is applicable to instances of this | |
71 * class, or must be built by <em>bitwise OR</em>'ing together | |
72 * (that is, using the <code>int</code> "|" operator) two or more | |
73 * of those <code>DWT</code> style constants. The class description | |
74 * lists the style constants that are applicable to the class. | |
75 * Style bits are also inherited from superclasses. | |
76 * </p> | |
77 * | |
78 * @param parent a composite control which will be the parent of the new instance (cannot be null) | |
79 * @param style the style of control to construct | |
80 * | |
81 * @exception IllegalArgumentException <ul> | |
82 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
83 * </ul> | |
84 * @exception DWTException <ul> | |
85 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
86 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
87 * </ul> | |
88 * | |
89 * @see DWT | |
90 * @see Widget#checkSubclass | |
91 * @see Widget#getStyle | |
92 */ | |
93 public this (Shell parent, int style) { | |
240 | 94 super (parent, checkStyle (parent, style)); |
77 | 95 checkSubclass (); |
96 } | |
97 | |
98 /** | |
99 * Returns the currently selected color in the receiver. | |
100 * | |
101 * @return the RGB value for the selected color, may be null | |
102 * | |
103 * @see PaletteData#getRGBs | |
104 */ | |
105 public RGB getRGB () { | |
106 return rgb; | |
107 } | |
108 /** | |
109 * Makes the receiver visible and brings it to the front | |
110 * of the display. | |
111 * | |
112 * @return the selected color, or null if the dialog was | |
113 * cancelled, no color was selected, or an error | |
114 * occurred | |
115 * | |
116 * @exception DWTException <ul> | |
117 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
118 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
119 * </ul> | |
120 */ | |
121 public RGB open () { | |
122 char* buffer = toStringz(title); | |
123 auto handle = cast(GtkWidget*)OS.gtk_color_selection_dialog_new (buffer); | |
240 | 124 Display display = parent !is null ? parent.getDisplay (): Display.getCurrent (); |
77 | 125 if (parent !is null) { |
126 auto shellHandle = parent.topHandle (); | |
127 OS.gtk_window_set_transient_for (handle, shellHandle); | |
128 auto pixbufs = OS.gtk_window_get_icon_list (shellHandle); | |
129 if (pixbufs !is null) { | |
130 OS.gtk_window_set_icon_list (handle, pixbufs); | |
131 OS.g_list_free (pixbufs); | |
132 } | |
133 } | |
134 GtkColorSelectionDialog* dialog = cast(GtkColorSelectionDialog*)handle; | |
135 GdkColor color; | |
136 if (rgb !is null) { | |
137 color.red = cast(short)((rgb.red & 0xFF) | ((rgb.red & 0xFF) << 8)); | |
138 color.green = cast(short)((rgb.green & 0xFF) | ((rgb.green & 0xFF) << 8)); | |
139 color.blue = cast(short)((rgb.blue & 0xFF) | ((rgb.blue & 0xFF) << 8)); | |
140 OS.gtk_color_selection_set_current_color (dialog.colorsel, &color); | |
141 } | |
142 OS.gtk_color_selection_set_has_palette (dialog.colorsel, true); | |
143 display.addIdleProc (); | |
240 | 144 Dialog oldModal = null; |
145 if (OS.gtk_window_get_modal (handle)) { | |
146 oldModal = display.getModalDialog (); | |
147 display.setModalDialog (this); | |
148 } | |
149 int signalId = 0; | |
150 int /*long*/ hookId = 0; | |
151 CallbackData emissionData; | |
152 emissionData.display = display; | |
153 emissionData.data = handle; | |
154 if ((style & DWT.RIGHT_TO_LEFT) !is 0) { | |
155 signalId = OS.g_signal_lookup (OS.map.ptr, OS.GTK_TYPE_WIDGET()); | |
156 hookId = OS.g_signal_add_emission_hook (signalId, 0, &Display.emissionFunc, &emissionData, null); | |
157 } | |
77 | 158 int response = OS.gtk_dialog_run (handle); |
240 | 159 if ((style & DWT.RIGHT_TO_LEFT) !is 0) { |
160 OS.g_signal_remove_emission_hook (signalId, hookId); | |
161 } | |
162 if (OS.gtk_window_get_modal (handle)) { | |
163 display.setModalDialog (oldModal); | |
164 } | |
77 | 165 bool success = response is OS.GTK_RESPONSE_OK; |
166 if (success) { | |
167 OS.gtk_color_selection_get_current_color (dialog.colorsel, &color); | |
168 int red = (color.red >> 8) & 0xFF; | |
169 int green = (color.green >> 8) & 0xFF; | |
170 int blue = (color.blue >> 8) & 0xFF; | |
171 rgb = new RGB (red, green, blue); | |
172 } | |
173 display.removeIdleProc (); | |
174 OS.gtk_widget_destroy (handle); | |
175 if (!success) return null; | |
176 return rgb; | |
177 } | |
178 /** | |
179 * Sets the receiver's selected color to be the argument. | |
180 * | |
181 * @param rgb the new RGB value for the selected color, may be | |
182 * null to let the platform select a default when | |
183 * open() is called | |
184 * @see PaletteData#getRGBs | |
185 */ | |
186 public void setRGB (RGB rgb) { | |
187 this.rgb = rgb; | |
188 } | |
189 } |