comparison dwt/widgets/Canvas.d @ 240:ce446666f5a2

Update to SWT 3.4M7
author Frank Benoit <benoit@tionex.de>
date Mon, 12 May 2008 19:13:01 +0200
parents 17f8449522fd
children c0d810de7093
comparison
equal deleted inserted replaced
239:06a1f6829310 240:ce446666f5a2
17 import dwt.internal.gtk.OS; 17 import dwt.internal.gtk.OS;
18 import dwt.DWT; 18 import dwt.DWT;
19 import dwt.widgets.Composite; 19 import dwt.widgets.Composite;
20 import dwt.widgets.Caret; 20 import dwt.widgets.Caret;
21 import dwt.widgets.Control; 21 import dwt.widgets.Control;
22 import dwt.widgets.IME;
22 import dwt.graphics.GC; 23 import dwt.graphics.GC;
23 import dwt.graphics.Rectangle; 24 import dwt.graphics.Rectangle;
24 import dwt.graphics.Font; 25 import dwt.graphics.Font;
25 26
26 /** 27 /**
45 public class Canvas : Composite { 46 public class Canvas : Composite {
46 47
47 alias Composite.setBounds setBounds; 48 alias Composite.setBounds setBounds;
48 49
49 Caret caret; 50 Caret caret;
51 IME ime;
50 52
51 this () {} 53 this () {}
52 54
53 /** 55 /**
54 * Constructs a new instance of this class given its parent 56 * Constructs a new instance of this class given its parent
76 * @see DWT 78 * @see DWT
77 * @see Widget#checkSubclass 79 * @see Widget#checkSubclass
78 * @see Widget#getStyle 80 * @see Widget#getStyle
79 */ 81 */
80 public this (Composite parent, int style) { 82 public this (Composite parent, int style) {
81 super (parent, style); 83 super (parent, checkStyle (style));
82 } 84 }
83 85
84 /** 86 /**
85 * Fills the interior of the rectangle specified by the arguments, 87 * Fills the interior of the rectangle specified by the arguments,
86 * with the receiver's background. 88 * with the receiver's background.
135 override Point getIMCaretPos () { 137 override Point getIMCaretPos () {
136 if (caret is null) return super.getIMCaretPos (); 138 if (caret is null) return super.getIMCaretPos ();
137 return new Point (caret.x, caret.y); 139 return new Point (caret.x, caret.y);
138 } 140 }
139 141
142 public IME getIME () {
143 checkWidget ();
144 return ime;
145 }
146
147 override int /*long*/ gtk_button_press_event (GtkWidget* widget, GdkEventButton* event) {
148 if (ime !is null) {
149 auto result = ime.gtk_button_press_event (widget, event);
150 if (result !is 0) return result;
151 }
152 return super.gtk_button_press_event (widget, event);
153 }
154
155 override int /*long*/ gtk_commit (GtkIMContext* imcontext, char* text) {
156 if (ime !is null) {
157 auto result = ime.gtk_commit (imcontext, text);
158 if (result !is 0) return result;
159 }
160 return super.gtk_commit (imcontext, text);
161 }
162
140 override int /*long*/ gtk_expose_event (GtkWidget* widget, GdkEventExpose* event) { 163 override int /*long*/ gtk_expose_event (GtkWidget* widget, GdkEventExpose* event) {
141 if ((state & OBSCURED) !is 0) return 0; 164 if ((state & OBSCURED) !is 0) return 0;
142 bool isFocus = caret !is null && caret.isFocusCaret (); 165 bool isFocus = caret !is null && caret.isFocusCaret ();
143 if (isFocus) caret.killFocus (); 166 if (isFocus) caret.killFocus ();
144 auto result = super.gtk_expose_event (widget, event); 167 auto result = super.gtk_expose_event (widget, event);
156 auto result = super.gtk_focus_out_event (widget, event); 179 auto result = super.gtk_focus_out_event (widget, event);
157 if (caret !is null) caret.killFocus (); 180 if (caret !is null) caret.killFocus ();
158 return result; 181 return result;
159 } 182 }
160 183
184 override int /*long*/ gtk_preedit_changed (GtkIMContext* imcontext) {
185 if (ime !is null) {
186 auto result = ime.gtk_preedit_changed (imcontext);
187 if (result !is 0) return result;
188 }
189 return super.gtk_preedit_changed (imcontext);
190 }
191
161 override void redrawWidget (int x, int y, int width, int height, bool redrawAll, bool all, bool trim) { 192 override void redrawWidget (int x, int y, int width, int height, bool redrawAll, bool all, bool trim) {
162 bool isFocus = caret !is null && caret.isFocusCaret (); 193 bool isFocus = caret !is null && caret.isFocusCaret ();
163 if (isFocus) caret.killFocus (); 194 if (isFocus) caret.killFocus ();
164 super.redrawWidget (x, y, width, height, redrawAll, all, trim); 195 super.redrawWidget (x, y, width, height, redrawAll, all, trim);
165 if (isFocus) caret.setFocus (); 196 if (isFocus) caret.setFocus ();
167 198
168 override void releaseChildren (bool destroy) { 199 override void releaseChildren (bool destroy) {
169 if (caret !is null) { 200 if (caret !is null) {
170 caret.release (false); 201 caret.release (false);
171 caret = null; 202 caret = null;
203 }
204 if (ime !is null) {
205 ime.release (false);
206 ime = null;
172 } 207 }
173 super.releaseChildren (destroy); 208 super.releaseChildren (destroy);
174 } 209 }
175 210
176 /** 211 /**
196 * </ul> 231 * </ul>
197 */ 232 */
198 public void scroll (int destX, int destY, int x, int y, int width, int height, bool all) { 233 public void scroll (int destX, int destY, int x, int y, int width, int height, bool all) {
199 checkWidget(); 234 checkWidget();
200 if (width <= 0 || height <= 0) return; 235 if (width <= 0 || height <= 0) return;
236 if ((style & DWT.MIRRORED) !is 0) {
237 int clientWidth = getClientWidth ();
238 x = clientWidth - width - x;
239 destX = clientWidth - width - destX;
240 }
201 int deltaX = destX - x, deltaY = destY - y; 241 int deltaX = destX - x, deltaY = destY - y;
202 if (deltaX is 0 && deltaY is 0) return; 242 if (deltaX is 0 && deltaY is 0) return;
203 if (!isVisible ()) return; 243 if (!isVisible ()) return;
204 bool isFocus = caret !is null && caret.isFocusCaret (); 244 bool isFocus = caret !is null && caret.isFocusCaret ();
205 if (isFocus) caret.killFocus (); 245 if (isFocus) caret.killFocus ();
327 checkWidget(); 367 checkWidget();
328 if (caret !is null) caret.setFont (font); 368 if (caret !is null) caret.setFont (font);
329 super.setFont (font); 369 super.setFont (font);
330 } 370 }
331 371
372 public void setIME (IME ime) {
373 checkWidget ();
374 if (ime !is null && ime.isDisposed()) error(DWT.ERROR_INVALID_ARGUMENT);
375 this.ime = ime;
376 }
377
332 void updateCaret () { 378 void updateCaret () {
333 auto imHandle = imHandle (); 379 auto imHandle = imHandle ();
334 if (imHandle is null) return; 380 if (imHandle is null) return;
335 GdkRectangle* rect = new GdkRectangle (); 381 GdkRectangle* rect = new GdkRectangle ();
336 rect.x = caret.x; 382 rect.x = caret.x;