comparison dwt/widgets/Canvas.d @ 213:36f5cb12e1a2

Update to SWT 3.4M7
author Frank Benoit <benoit@tionex.de>
date Sat, 17 May 2008 17:34:28 +0200
parents d7264281cb4a
children fd9c62a2998e
comparison
equal deleted inserted replaced
212:ab60f3309436 213:36f5cb12e1a2
22 import dwt.graphics.Rectangle; 22 import dwt.graphics.Rectangle;
23 import dwt.internal.win32.OS; 23 import dwt.internal.win32.OS;
24 import dwt.widgets.Caret; 24 import dwt.widgets.Caret;
25 import dwt.widgets.Control; 25 import dwt.widgets.Control;
26 import dwt.widgets.Display; 26 import dwt.widgets.Display;
27 import dwt.widgets.IME;
27 28
28 import dwt.dwthelper.utils; 29 import dwt.dwthelper.utils;
29 30
30 /** 31 /**
31 * Instances of this class provide a surface for drawing 32 * Instances of this class provide a surface for drawing
51 52
52 alias Composite.drawBackground drawBackground; 53 alias Composite.drawBackground drawBackground;
53 alias Composite.windowProc windowProc; 54 alias Composite.windowProc windowProc;
54 55
55 Caret caret; 56 Caret caret;
57 IME ime;
56 58
57 /** 59 /**
58 * Prevents uninitialized instances from being created outside the package. 60 * Prevents uninitialized instances from being created outside the package.
59 */ 61 */
60 this () { 62 this () {
101 OS.ReleaseDC (handle, hDC); 103 OS.ReleaseDC (handle, hDC);
102 } 104 }
103 } 105 }
104 106
105 /** 107 /**
108 * Fills the interior of the rectangle specified by the arguments,
109 * with the receiver's background.
110 *
111 * @param gc the gc where the rectangle is to be filled
112 * @param x the x coordinate of the rectangle to be filled
113 * @param y the y coordinate of the rectangle to be filled
114 * @param width the width of the rectangle to be filled
115 * @param height the height of the rectangle to be filled
116 *
117 * @exception IllegalArgumentException <ul>
118 * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
119 * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li>
120 * </ul>
121 * @exception DWTException <ul>
122 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
123 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
124 * </ul>
125 *
126 * @since 3.2
127 */
128 public void drawBackground (GC gc, int x, int y, int width, int height) {
129 checkWidget ();
130 if (gc is null) error (DWT.ERROR_NULL_ARGUMENT);
131 if (gc.isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT);
132 RECT rect;
133 OS.SetRect (&rect, x, y, x + width, y + height);
134 auto hDC = gc.handle;
135 int pixel = background is -1 ? gc.getBackground ().handle : -1;
136 drawBackground (hDC, &rect, pixel);
137 }
138
139 /**
106 * Returns the caret. 140 * Returns the caret.
107 * <p> 141 * <p>
108 * The caret for the control is automatically hidden 142 * The caret for the control is automatically hidden
109 * and shown when the control is painted or resized, 143 * and shown when the control is painted or resized,
110 * when focus is gained or lost and when an the control 144 * when focus is gained or lost and when an the control
123 public Caret getCaret () { 157 public Caret getCaret () {
124 checkWidget (); 158 checkWidget ();
125 return caret; 159 return caret;
126 } 160 }
127 161
128 override void releaseChildren (bool destroy) { 162 /**
163 * Returns the IME.
164 *
165 * @return the IME
166 *
167 * @exception DWTException <ul>
168 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
169 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
170 * </ul>
171 *
172 * @since 3.4
173 */
174 public IME getIME () {
175 checkWidget ();
176 return ime;
177 }
178
179 void releaseChildren (bool destroy) {
129 if (caret !is null) { 180 if (caret !is null) {
130 caret.release (false); 181 caret.release (false);
131 caret = null; 182 caret = null;
132 } 183 }
184 if (ime !is null) {
185 ime.release (false);
186 ime = null;
187 }
133 super.releaseChildren (destroy); 188 super.releaseChildren (destroy);
134 }
135
136 /**
137 * Fills the interior of the rectangle specified by the arguments,
138 * with the receiver's background.
139 *
140 * @param gc the gc where the rectangle is to be filled
141 * @param x the x coordinate of the rectangle to be filled
142 * @param y the y coordinate of the rectangle to be filled
143 * @param width the width of the rectangle to be filled
144 * @param height the height of the rectangle to be filled
145 *
146 * @exception IllegalArgumentException <ul>
147 * <li>ERROR_NULL_ARGUMENT - if the gc is null</li>
148 * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li>
149 * </ul>
150 * @exception DWTException <ul>
151 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
152 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
153 * </ul>
154 *
155 * @since 3.2
156 */
157 public void drawBackground (GC gc, int x, int y, int width, int height) {
158 checkWidget ();
159 if (gc is null) error (DWT.ERROR_NULL_ARGUMENT);
160 if (gc.isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT);
161 RECT rect;
162 OS.SetRect (&rect, x, y, x + width, y + height);
163 auto hDC = gc.handle;
164 int pixel = background is -1 ? gc.getBackground ().handle : -1;
165 drawBackground (hDC, &rect, pixel);
166 } 189 }
167 190
168 /** 191 /**
169 * Scrolls a rectangular area of the receiver by first copying 192 * Scrolls a rectangular area of the receiver by first copying
170 * the source area to the destination and then causing the area 193 * the source area to the destination and then causing the area
294 checkWidget (); 317 checkWidget ();
295 if (caret !is null) caret.setFont (font); 318 if (caret !is null) caret.setFont (font);
296 super.setFont (font); 319 super.setFont (font);
297 } 320 }
298 321
322 /**
323 * Sets the receiver's IME.
324 *
325 * @param ime the new IME for the receiver, may be null
326 *
327 * @exception IllegalArgumentException <ul>
328 * <li>ERROR_INVALID_ARGUMENT - if the IME has been disposed</li>
329 * </ul>
330 * @exception DWTException <ul>
331 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
332 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
333 * </ul>
334 *
335 * @since 3.4
336 */
337 public void setIME (IME ime) {
338 checkWidget ();
339 if (ime !is null && ime.isDisposed()) error(DWT.ERROR_INVALID_ARGUMENT);
340 this.ime = ime;
341 }
342
299 override int windowProc (HWND hwnd, int msg, int wParam, int lParam) { 343 override int windowProc (HWND hwnd, int msg, int wParam, int lParam) {
300 if (msg is Display.SWT_RESTORECARET) { 344 if (msg is Display.SWT_RESTORECARET) {
301 if ((state & CANVAS) !is 0) { 345 if ((state & CANVAS) !is 0) {
302 if (caret !is null) { 346 if (caret !is null) {
303 caret.killFocus (); 347 caret.killFocus ();
307 } 351 }
308 } 352 }
309 return super.windowProc (hwnd, msg, wParam, lParam); 353 return super.windowProc (hwnd, msg, wParam, lParam);
310 } 354 }
311 355
312 override LRESULT WM_IME_COMPOSITION (int wParam, int lParam) { 356 override LRESULT WM_CHAR (int wParam, int lParam) {
313 LRESULT result = super.WM_IME_COMPOSITION (wParam, lParam); 357 LRESULT result = super.WM_CHAR (wParam, lParam);
358 if (result !is null) return result;
359 if (caret !is null) {
360 switch (wParam) {
361 case DWT.DEL:
362 case DWT.BS:
363 case DWT.ESC:
364 break;
365 default: {
366 if (OS.GetKeyState (OS.VK_CONTROL) >= 0) {
367 int value;
368 if (OS.SystemParametersInfo (OS.SPI_GETMOUSEVANISH, 0, &value, 0)) {
369 if (value !is 0) OS.SetCursor (null);
370 }
371 }
372 }
373 }
374 }
375 return result;
376 }
377
378 override LRESULT WM_IME_COMPOSITION (int /*long*/ wParam, int /*long*/ lParam) {
379 if (ime !is null) {
380 LRESULT result = ime.WM_IME_COMPOSITION (wParam, lParam);
381 if (result !is null) return result;
382 }
383
314 /* 384 /*
315 * Bug in Windows. On Korean Windows XP, the IME window 385 * Bug in Windows. On Korean Windows XP, the IME window
316 * for the Korean Input System (MS-IME 2002) always opens 386 * for the Korean Input System (MS-IME 2002) always opens
317 * in the top left corner of the screen, despite the fact 387 * in the top left corner of the screen, despite the fact
318 * that ImmSetCompositionWindow() was called to position 388 * that ImmSetCompositionWindow() was called to position
337 } 407 }
338 } 408 }
339 } 409 }
340 } 410 }
341 } 411 }
342 return result; 412 return super.WM_IME_COMPOSITION (wParam, lParam);
413 }
414
415 override LRESULT WM_IME_COMPOSITION_START (int /*long*/ wParam, int /*long*/ lParam) {
416 if (ime !is null) {
417 LRESULT result = ime.WM_IME_COMPOSITION_START (wParam, lParam);
418 if (result !is null) return result;
419 }
420 return super.WM_IME_COMPOSITION_START (wParam, lParam);
421 }
422
423 override LRESULT WM_IME_ENDCOMPOSITION (int /*long*/ wParam, int /*long*/ lParam) {
424 if (ime !is null) {
425 LRESULT result = ime.WM_IME_ENDCOMPOSITION (wParam, lParam);
426 if (result !is null) return result;
427 }
428 return super.WM_IME_ENDCOMPOSITION (wParam, lParam);
343 } 429 }
344 430
345 override LRESULT WM_INPUTLANGCHANGE (int wParam, int lParam) { 431 override LRESULT WM_INPUTLANGCHANGE (int wParam, int lParam) {
346 LRESULT result = super.WM_INPUTLANGCHANGE (wParam, lParam); 432 LRESULT result = super.WM_INPUTLANGCHANGE (wParam, lParam);
347 if (caret !is null && caret.isFocusCaret ()) { 433 if (caret !is null && caret.isFocusCaret ()) {
350 } 436 }
351 return result; 437 return result;
352 } 438 }
353 439
354 override LRESULT WM_KILLFOCUS (int wParam, int lParam) { 440 override LRESULT WM_KILLFOCUS (int wParam, int lParam) {
441 if (ime !is null) {
442 LRESULT result = ime.WM_KILLFOCUS (wParam, lParam);
443 if (result !is null) return result;
444 }
355 LRESULT result = super.WM_KILLFOCUS (wParam, lParam); 445 LRESULT result = super.WM_KILLFOCUS (wParam, lParam);
356 if (caret !is null) caret.killFocus (); 446 if (caret !is null) caret.killFocus ();
357 return result; 447 return result;
448 }
449
450 override LRESULT WM_LBUTTONDOWN (int /*long*/ wParam, int /*long*/ lParam) {
451 if (ime !is null) {
452 LRESULT result = ime.WM_LBUTTONDOWN (wParam, lParam);
453 if (result !is null) return result;
454 }
455 return super.WM_LBUTTONDOWN (wParam, lParam);
358 } 456 }
359 457
360 override LRESULT WM_SETFOCUS (int wParam, int lParam) { 458 override LRESULT WM_SETFOCUS (int wParam, int lParam) {
361 LRESULT result = super.WM_SETFOCUS (wParam, lParam); 459 LRESULT result = super.WM_SETFOCUS (wParam, lParam);
362 if (caret !is null) caret.setFocus (); 460 if (caret !is null) caret.setFocus ();
369 return result; 467 return result;
370 } 468 }
371 469
372 override LRESULT WM_WINDOWPOSCHANGED (int wParam, int lParam) { 470 override LRESULT WM_WINDOWPOSCHANGED (int wParam, int lParam) {
373 LRESULT result = super.WM_WINDOWPOSCHANGED (wParam, lParam); 471 LRESULT result = super.WM_WINDOWPOSCHANGED (wParam, lParam);
374 if (result !is null) return result; 472 //if (result !is null) return result;
375 /* 473 /*
376 * Bug in Windows. When a window with style WS_EX_LAYOUTRTL 474 * Bug in Windows. When a window with style WS_EX_LAYOUTRTL
377 * that contains a caret is resized, Windows does not move the 475 * that contains a caret is resized, Windows does not move the
378 * caret in relation to the mirrored origin in the top right. 476 * caret in relation to the mirrored origin in the top right.
379 * The fix is to hide the caret in WM_WINDOWPOSCHANGING and 477 * The fix is to hide the caret in WM_WINDOWPOSCHANGING and