1 11 package org.eclipse.swt.widgets; 12 13 14 import org.eclipse.swt.internal.win32.*; 15 import org.eclipse.swt.*; 16 import org.eclipse.swt.graphics.*; 17 18 37 38 public class Canvas extends Composite { 39 Caret caret; 40 41 44 Canvas () { 45 } 46 47 74 public Canvas (Composite parent, int style) { 75 super (parent, style); 76 } 77 78 void clearArea (int x, int y, int width, int height) { 79 checkWidget (); 80 if (OS.IsWindowVisible (handle)) { 81 RECT rect = new RECT (); 82 OS.SetRect (rect, x, y, x + width, y + height); 83 int hDC = OS.GetDCEx (handle, 0, OS.DCX_CACHE | OS.DCX_CLIPCHILDREN | OS.DCX_CLIPSIBLINGS); 84 drawBackground (hDC, rect); 85 OS.ReleaseDC (handle, hDC); 86 } 87 } 88 89 107 public Caret getCaret () { 108 checkWidget (); 109 return caret; 110 } 111 112 void releaseChildren (boolean destroy) { 113 if (caret != null) { 114 caret.release (false); 115 caret = null; 116 } 117 super.releaseChildren (destroy); 118 } 119 120 141 public void drawBackground (GC gc, int x, int y, int width, int height) { 142 checkWidget (); 143 if (gc == null) error (SWT.ERROR_NULL_ARGUMENT); 144 if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); 145 RECT rect = new RECT (); 146 OS.SetRect (rect, x, y, x + width, y + height); 147 int hDC = gc.handle; 148 int pixel = background == -1 ? gc.getBackground ().handle : -1; 149 drawBackground (hDC, rect, pixel); 150 } 151 152 174 public void scroll (int destX, int destY, int x, int y, int width, int height, boolean all) { 175 checkWidget (); 176 forceResize (); 177 boolean isFocus = caret != null && caret.isFocusCaret (); 178 if (isFocus) caret.killFocus (); 179 RECT sourceRect = new RECT (); 180 OS.SetRect (sourceRect, x, y, x + width, y + height); 181 RECT clientRect = new RECT (); 182 OS.GetClientRect (handle, clientRect); 183 if (OS.IntersectRect (clientRect, sourceRect, clientRect)) { 184 if (OS.IsWinCE) { 185 OS.UpdateWindow (handle); 186 } else { 187 int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN; 188 OS.RedrawWindow (handle, null, 0, flags); 189 } 190 } 191 int deltaX = destX - x, deltaY = destY - y; 192 if (findImageControl () != null) { 193 if (OS.IsWinCE) { 194 OS.InvalidateRect (handle, sourceRect, true); 195 } else { 196 int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE; 197 if (all) flags |= OS.RDW_ALLCHILDREN; 198 OS.RedrawWindow (handle, sourceRect, 0, flags); 199 } 200 OS.OffsetRect (sourceRect, deltaX, deltaY); 201 if (OS.IsWinCE) { 202 OS.InvalidateRect (handle, sourceRect, true); 203 } else { 204 int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE; 205 if (all) flags |= OS.RDW_ALLCHILDREN; 206 OS.RedrawWindow (handle, sourceRect, 0, flags); 207 } 208 } else { 209 int flags = OS.SW_INVALIDATE | OS.SW_ERASE; 210 224 OS.ScrollWindowEx (handle, deltaX, deltaY, sourceRect, null, 0, null, flags); 226 } 227 if (all) { 228 Control [] children = _getChildren (); 229 for (int i=0; i<children.length; i++) { 230 Control child = children [i]; 231 Rectangle rect = child.getBounds (); 232 if (Math.min (x + width, rect.x + rect.width) >= Math.max (x, rect.x) && 233 Math.min (y + height, rect.y + rect.height) >= Math.max (y, rect.y)) { 234 child.setLocation (rect.x + deltaX, rect.y + deltaY); 235 } 236 } 237 } 238 if (isFocus) caret.setFocus (); 239 } 240 241 261 public void setCaret (Caret caret) { 262 checkWidget (); 263 Caret newCaret = caret; 264 Caret oldCaret = this.caret; 265 this.caret = newCaret; 266 if (hasFocus ()) { 267 if (oldCaret != null) oldCaret.killFocus (); 268 if (newCaret != null) { 269 if (newCaret.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); 270 newCaret.setFocus (); 271 } 272 } 273 } 274 275 public void setFont (Font font) { 276 checkWidget (); 277 if (caret != null) caret.setFont (font); 278 super.setFont (font); 279 } 280 281 int windowProc (int hwnd, int msg, int wParam, int lParam) { 282 if (msg == Display.SWT_RESTORECARET) { 283 if ((state & CANVAS) != 0) { 284 if (caret != null) { 285 caret.killFocus (); 286 caret.setFocus (); 287 return 1; 288 } 289 } 290 } 291 return super.windowProc (hwnd, msg, wParam, lParam); 292 } 293 294 LRESULT WM_IME_COMPOSITION (int wParam, int lParam) { 295 LRESULT result = super.WM_IME_COMPOSITION (wParam, lParam); 296 304 if (!OS.IsWinCE && OS.WIN32_VERSION == OS.VERSION (5, 1)) { 305 if (OS.IsDBLocale) { 306 short langID = OS.GetSystemDefaultUILanguage (); 307 short primaryLang = OS.PRIMARYLANGID (langID); 308 if (primaryLang == OS.LANG_KOREAN) { 309 if (caret != null && caret.isFocusCaret ()) { 310 POINT ptCurrentPos = new POINT (); 311 if (OS.GetCaretPos (ptCurrentPos)) { 312 COMPOSITIONFORM lpCompForm = new COMPOSITIONFORM (); 313 lpCompForm.dwStyle = OS.CFS_POINT; 314 lpCompForm.x = ptCurrentPos.x; 315 lpCompForm.y = ptCurrentPos.y; 316 int hIMC = OS.ImmGetContext (handle); 317 OS.ImmSetCompositionWindow (hIMC, lpCompForm); 318 OS.ImmReleaseContext (handle, hIMC); 319 } 320 } 321 } 322 } 323 } 324 return result; 325 } 326 327 LRESULT WM_INPUTLANGCHANGE (int wParam, int lParam) { 328 LRESULT result = super.WM_INPUTLANGCHANGE (wParam, lParam); 329 if (caret != null && caret.isFocusCaret ()) { 330 caret.setIMEFont (); 331 caret.resizeIME (); 332 } 333 return result; 334 } 335 336 LRESULT WM_KILLFOCUS (int wParam, int lParam) { 337 LRESULT result = super.WM_KILLFOCUS (wParam, lParam); 338 if (caret != null) caret.killFocus (); 339 return result; 340 } 341 342 LRESULT WM_SETFOCUS (int wParam, int lParam) { 343 LRESULT result = super.WM_SETFOCUS (wParam, lParam); 344 if (caret != null) caret.setFocus (); 345 return result; 346 } 347 348 LRESULT WM_SIZE (int wParam, int lParam) { 349 LRESULT result = super.WM_SIZE (wParam, lParam); 350 if (caret != null && caret.isFocusCaret ()) caret.resizeIME (); 351 return result; 352 } 353 354 LRESULT WM_WINDOWPOSCHANGED (int wParam, int lParam) { 355 LRESULT result = super.WM_WINDOWPOSCHANGED (wParam, lParam); 356 if (result != null) return result; 357 364 boolean isFocus = (style & SWT.RIGHT_TO_LEFT) != 0 && caret != null && caret.isFocusCaret (); 365 if (isFocus) caret.setFocus (); 366 return result; 367 } 368 369 LRESULT WM_WINDOWPOSCHANGING (int wParam, int lParam) { 370 LRESULT result = super.WM_WINDOWPOSCHANGING (wParam, lParam); 371 if (result != null) return result; 372 379 boolean isFocus = (style & SWT.RIGHT_TO_LEFT) != 0 && caret != null && caret.isFocusCaret (); 380 if (isFocus) caret.killFocus (); 381 return result; 382 } 383 384 } 385 | Popular Tags |