Changeset 42:6a40adae94d5
- Timestamp:
- 02/01/08 16:20:30
(1 year ago)
- Author:
- Frank Benoit <benoit@tionex.de>
- branch:
- default
- Message:
Caret
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r38 |
r42 |
|
| 13 | 13 | module dwt.widgets.Caret; |
|---|
| 14 | 14 | |
|---|
| 15 | | import dwt.widgets.Widget; |
|---|
| 16 | | import dwt.graphics.Font; |
|---|
| 17 | | |
|---|
| 18 | | class Caret : Widget { |
|---|
| 19 | | this( Widget, int ); |
|---|
| 20 | | bool isFocusCaret () ; |
|---|
| 21 | | void killFocus () ; |
|---|
| 22 | | void setFocus () ; |
|---|
| 23 | | public void setFont (Font font) ; |
|---|
| 24 | | void setIMEFont () ; |
|---|
| 25 | | void resizeIME () ; |
|---|
| 26 | | } |
|---|
| 27 | | /++ |
|---|
| | 15 | |
|---|
| | 16 | |
|---|
| 28 | 17 | import dwt.DWT; |
|---|
| 29 | 18 | import dwt.DWTException; |
|---|
| … | … | |
| 32 | 21 | import dwt.graphics.Point; |
|---|
| 33 | 22 | import dwt.graphics.Rectangle; |
|---|
| 34 | | import dwt.internal.win32.COMPOSITIONFORM; |
|---|
| 35 | | import dwt.internal.win32.LOGFONT; |
|---|
| 36 | | import dwt.internal.win32.LOGFONTA; |
|---|
| 37 | | import dwt.internal.win32.LOGFONTW; |
|---|
| 38 | 23 | import dwt.internal.win32.OS; |
|---|
| 39 | | import dwt.internal.win32.POINT; |
|---|
| 40 | | import dwt.internal.win32.RECT; |
|---|
| | 24 | |
|---|
| | 25 | import dwt.widgets.Widget; |
|---|
| | 26 | import dwt.widgets.Canvas; |
|---|
| | 27 | |
|---|
| | 28 | import dwt.dwthelper.utils; |
|---|
| 41 | 29 | |
|---|
| 42 | 30 | /** |
|---|
| … | … | |
| 55 | 43 | */ |
|---|
| 56 | 44 | |
|---|
| 57 | | public class Caret extends Widget { |
|---|
| | 45 | public class Caret : Widget { |
|---|
| 58 | 46 | Canvas parent; |
|---|
| 59 | 47 | int x, y, width, height; |
|---|
| 60 | 48 | bool moved, resized; |
|---|
| 61 | | bool isVisible; |
|---|
| | 49 | bool isVisible_; |
|---|
| 62 | 50 | Image image; |
|---|
| 63 | 51 | Font font; |
|---|
| 64 | | LOGFONT oldFont; |
|---|
| | 52 | LOGFONT* oldFont; |
|---|
| 65 | 53 | |
|---|
| 66 | 54 | /** |
|---|
| … | … | |
| 92 | 80 | * @see Widget#getStyle |
|---|
| 93 | 81 | */ |
|---|
| 94 | | public Caret (Canvas parent, int style) { |
|---|
| | 82 | public this (Canvas parent, int style) { |
|---|
| 95 | 83 | super (parent, style); |
|---|
| 96 | 84 | this.parent = parent; |
|---|
| … | … | |
| 99 | 87 | |
|---|
| 100 | 88 | void createWidget () { |
|---|
| 101 | | isVisible = true; |
|---|
| | 89 | isVisible_ = true; |
|---|
| 102 | 90 | if (parent.getCaret () is null) { |
|---|
| 103 | 91 | parent.setCaret (this); |
|---|
| … | … | |
| 105 | 93 | } |
|---|
| 106 | 94 | |
|---|
| 107 | | int defaultFont () { |
|---|
| 108 | | int hwnd = parent.handle; |
|---|
| 109 | | int hwndIME = OS.ImmGetDefaultIMEWnd (hwnd); |
|---|
| 110 | | int hFont = 0; |
|---|
| 111 | | if (hwndIME !is 0) { |
|---|
| 112 | | hFont = OS.SendMessage (hwndIME, OS.WM_GETFONT, 0, 0); |
|---|
| 113 | | } |
|---|
| 114 | | if (hFont is 0) { |
|---|
| 115 | | hFont = OS.SendMessage (hwnd, OS.WM_GETFONT, 0, 0); |
|---|
| 116 | | } |
|---|
| 117 | | if (hFont is 0) return parent.defaultFont (); |
|---|
| | 95 | HFONT defaultFont () { |
|---|
| | 96 | auto hwnd = parent.handle; |
|---|
| | 97 | auto hwndIME = OS.ImmGetDefaultIMEWnd (hwnd); |
|---|
| | 98 | HFONT hFont; |
|---|
| | 99 | if (hwndIME !is null) { |
|---|
| | 100 | hFont = cast(HFONT) OS.SendMessage (hwndIME, OS.WM_GETFONT, 0, 0); |
|---|
| | 101 | } |
|---|
| | 102 | if (hFont is null) { |
|---|
| | 103 | hFont = cast(HFONT) OS.SendMessage (hwnd, OS.WM_GETFONT, 0, 0); |
|---|
| | 104 | } |
|---|
| | 105 | if (hFont is null) return parent.defaultFont (); |
|---|
| 118 | 106 | return hFont; |
|---|
| 119 | 107 | } |
|---|
| … | … | |
| 152 | 140 | checkWidget(); |
|---|
| 153 | 141 | if (font is null) { |
|---|
| 154 | | int hFont = defaultFont (); |
|---|
| | 142 | HFONT hFont = defaultFont (); |
|---|
| 155 | 143 | return Font.win32_new (display, hFont); |
|---|
| 156 | 144 | } |
|---|
| … | … | |
| 242 | 230 | public bool getVisible () { |
|---|
| 243 | 231 | checkWidget(); |
|---|
| 244 | | return isVisible; |
|---|
| | 232 | return isVisible_; |
|---|
| 245 | 233 | } |
|---|
| 246 | 234 | |
|---|
| … | … | |
| 269 | 257 | public bool isVisible () { |
|---|
| 270 | 258 | checkWidget(); |
|---|
| 271 | | return isVisible && parent.isVisible () && hasFocus (); |
|---|
| | 259 | return isVisible_ && parent.isVisible () && hasFocus (); |
|---|
| 272 | 260 | } |
|---|
| 273 | 261 | |
|---|
| … | … | |
| 285 | 273 | void resizeIME () { |
|---|
| 286 | 274 | if (!OS.IsDBLocale) return; |
|---|
| 287 | | POINT ptCurrentPos = new POINT (); |
|---|
| 288 | | if (!OS.GetCaretPos (ptCurrentPos)) return; |
|---|
| 289 | | int hwnd = parent.handle; |
|---|
| 290 | | RECT rect = new RECT (); |
|---|
| 291 | | OS.GetClientRect (hwnd, rect); |
|---|
| 292 | | COMPOSITIONFORM lpCompForm = new COMPOSITIONFORM (); |
|---|
| | 275 | POINT ptCurrentPos; |
|---|
| | 276 | if (!OS.GetCaretPos (&ptCurrentPos)) return; |
|---|
| | 277 | auto hwnd = parent.handle; |
|---|
| | 278 | RECT rect; |
|---|
| | 279 | OS.GetClientRect (hwnd, &rect); |
|---|
| | 280 | COMPOSITIONFORM lpCompForm; |
|---|
| 293 | 281 | lpCompForm.dwStyle = OS.CFS_RECT; |
|---|
| 294 | | lpCompForm.x = ptCurrentPos.x; |
|---|
| 295 | | lpCompForm.y = ptCurrentPos.y; |
|---|
| 296 | | lpCompForm.left = rect.left; |
|---|
| 297 | | lpCompForm.right = rect.right; |
|---|
| 298 | | lpCompForm.top = rect.top; |
|---|
| 299 | | lpCompForm.bottom = rect.bottom; |
|---|
| 300 | | int hIMC = OS.ImmGetContext (hwnd); |
|---|
| 301 | | OS.ImmSetCompositionWindow (hIMC, lpCompForm); |
|---|
| | 282 | lpCompForm.ptCurrentPos.x = ptCurrentPos.x; |
|---|
| | 283 | lpCompForm.ptCurrentPos.y = ptCurrentPos.y; |
|---|
| | 284 | lpCompForm.rcArea.left = rect.left; |
|---|
| | 285 | lpCompForm.rcArea.right = rect.right; |
|---|
| | 286 | lpCompForm.rcArea.top = rect.top; |
|---|
| | 287 | lpCompForm.rcArea.bottom = rect.bottom; |
|---|
| | 288 | auto hIMC = OS.ImmGetContext (hwnd); |
|---|
| | 289 | OS.ImmSetCompositionWindow (hIMC, &lpCompForm); |
|---|
| 302 | 290 | OS.ImmReleaseContext (hwnd, hIMC); |
|---|
| 303 | 291 | } |
|---|
| … | … | |
| 318 | 306 | void resize () { |
|---|
| 319 | 307 | resized = false; |
|---|
| 320 | | int hwnd = parent.handle; |
|---|
| | 308 | auto hwnd = parent.handle; |
|---|
| 321 | 309 | OS.DestroyCaret (); |
|---|
| 322 | | int hBitmap = image !is null ? image.handle : 0; |
|---|
| | 310 | auto hBitmap = image !is null ? image.handle : null; |
|---|
| 323 | 311 | OS.CreateCaret (hwnd, hBitmap, width, height); |
|---|
| 324 | 312 | OS.SetCaretPos (x, y); |
|---|
| … | … | |
| 330 | 318 | if (!OS.IsDBLocale) return; |
|---|
| 331 | 319 | if (oldFont is null) return; |
|---|
| 332 | | int hwnd = parent.handle; |
|---|
| 333 | | int hIMC = OS.ImmGetContext (hwnd); |
|---|
| | 320 | auto hwnd = parent.handle; |
|---|
| | 321 | auto hIMC = OS.ImmGetContext (hwnd); |
|---|
| 334 | 322 | OS.ImmSetCompositionFont (hIMC, oldFont); |
|---|
| 335 | 323 | OS.ImmReleaseContext (hwnd, hIMC); |
|---|
| … | … | |
| 362 | 350 | if (sameExtent) { |
|---|
| 363 | 351 | moved = true; |
|---|
| 364 | | if (isVisible && hasFocus ()) move (); |
|---|
| | 352 | if (isVisible_ && hasFocus ()) move (); |
|---|
| 365 | 353 | } else { |
|---|
| 366 | 354 | resized = true; |
|---|
| 367 | | if (isVisible && hasFocus ()) resize (); |
|---|
| | 355 | if (isVisible_ && hasFocus ()) resize (); |
|---|
| 368 | 356 | } |
|---|
| 369 | 357 | } |
|---|
| … | … | |
| 388 | 376 | |
|---|
| 389 | 377 | void setFocus () { |
|---|
| 390 | | int hwnd = parent.handle; |
|---|
| 391 | | int hBitmap = 0; |
|---|
| | 378 | auto hwnd = parent.handle; |
|---|
| | 379 | HBITMAP hBitmap; |
|---|
| 392 | 380 | if (image !is null) hBitmap = image.handle; |
|---|
| 393 | 381 | OS.CreateCaret (hwnd, hBitmap, width, height); |
|---|
| 394 | 382 | move (); |
|---|
| 395 | 383 | setIMEFont (); |
|---|
| 396 | | if (isVisible) OS.ShowCaret (hwnd); |
|---|
| | 384 | if (isVisible_) OS.ShowCaret (hwnd); |
|---|
| 397 | 385 | } |
|---|
| 398 | 386 | |
|---|
| … | … | |
| 442 | 430 | } |
|---|
| 443 | 431 | this.image = image; |
|---|
| 444 | | if (isVisible && hasFocus ()) resize (); |
|---|
| | 432 | if (isVisible_ && hasFocus ()) resize (); |
|---|
| 445 | 433 | } |
|---|
| 446 | 434 | |
|---|
| 447 | 435 | void setIMEFont () { |
|---|
| 448 | 436 | if (!OS.IsDBLocale) return; |
|---|
| 449 | | int hFont = 0; |
|---|
| | 437 | HFONT hFont; |
|---|
| 450 | 438 | if (font !is null) hFont = font.handle; |
|---|
| 451 | | if (hFont is 0) hFont = defaultFont (); |
|---|
| 452 | | int hwnd = parent.handle; |
|---|
| 453 | | int hIMC = OS.ImmGetContext (hwnd); |
|---|
| | 439 | if (hFont is null) hFont = defaultFont (); |
|---|
| | 440 | auto hwnd = parent.handle; |
|---|
| | 441 | auto hIMC = OS.ImmGetContext (hwnd); |
|---|
| 454 | 442 | /* Save the current IME font */ |
|---|
| 455 | 443 | if (oldFont is null) { |
|---|
| 456 | | oldFont = OS.IsUnicode ? (LOGFONT) new LOGFONTW () : new LOGFONTA (); |
|---|
| | 444 | oldFont = new LOGFONT; |
|---|
| 457 | 445 | if (!OS.ImmGetCompositionFont (hIMC, oldFont)) oldFont = null; |
|---|
| 458 | 446 | } |
|---|
| 459 | 447 | /* Set new IME font */ |
|---|
| 460 | | LOGFONT logFont = OS.IsUnicode ? (LOGFONT) new LOGFONTW () : new LOGFONTA (); |
|---|
| 461 | | if (OS.GetObject (hFont, LOGFONT.sizeof, logFont) !is 0) { |
|---|
| 462 | | OS.ImmSetCompositionFont (hIMC, logFont); |
|---|
| | 448 | LOGFONT logFont; |
|---|
| | 449 | if (OS.GetObject (hFont, LOGFONT.sizeof, &logFont) !is 0) { |
|---|
| | 450 | OS.ImmSetCompositionFont (hIMC, &logFont); |
|---|
| 463 | 451 | } |
|---|
| 464 | 452 | OS.ImmReleaseContext (hwnd, hIMC); |
|---|
| … | … | |
| 483 | 471 | this.x = x; this.y = y; |
|---|
| 484 | 472 | moved = true; |
|---|
| 485 | | if (isVisible && hasFocus ()) move (); |
|---|
| | 473 | if (isVisible_ && hasFocus ()) move (); |
|---|
| 486 | 474 | } |
|---|
| 487 | 475 | |
|---|
| … | … | |
| 520 | 508 | this.width = width; this.height = height; |
|---|
| 521 | 509 | resized = true; |
|---|
| 522 | | if (isVisible && hasFocus ()) resize (); |
|---|
| | 510 | if (isVisible_ && hasFocus ()) resize (); |
|---|
| 523 | 511 | } |
|---|
| 524 | 512 | |
|---|
| … | … | |
| 560 | 548 | public void setVisible (bool visible) { |
|---|
| 561 | 549 | checkWidget(); |
|---|
| 562 | | if (visible is isVisible) return; |
|---|
| 563 | | isVisible = visible; |
|---|
| 564 | | int hwnd = parent.handle; |
|---|
| | 550 | if (visible is isVisible_) return; |
|---|
| | 551 | isVisible_ = visible; |
|---|
| | 552 | auto hwnd = parent.handle; |
|---|
| 565 | 553 | if (OS.GetFocus () !is hwnd) return; |
|---|
| 566 | | if (!isVisible) { |
|---|
| | 554 | if (!isVisible_) { |
|---|
| 567 | 555 | OS.HideCaret (hwnd); |
|---|
| 568 | 556 | } else { |
|---|
| … | … | |
| 577 | 565 | |
|---|
| 578 | 566 | } |
|---|
| 579 | | ++/ |
|---|