changeset 42:6a40adae94d5

Caret
author Frank Benoit <benoit@tionex.de>
date Fri, 01 Feb 2008 22:20:30 +0100
parents f871c501e610
children 9c2b9c930ceb
files dwt/widgets/Caret.d
diffstat 1 files changed, 61 insertions(+), 74 deletions(-) [+]
line wrap: on
line diff
--- a/dwt/widgets/Caret.d	Fri Feb 01 22:10:37 2008 +0100
+++ b/dwt/widgets/Caret.d	Fri Feb 01 22:20:30 2008 +0100
@@ -12,32 +12,20 @@
  *******************************************************************************/
 module dwt.widgets.Caret;
 
-import dwt.widgets.Widget;
-import dwt.graphics.Font;
 
-class Caret : Widget {
-    this( Widget, int );
-bool isFocusCaret () ;
-void killFocus () ;
-void setFocus () ;
-public void setFont (Font font) ;
-void setIMEFont () ;
-void resizeIME () ;
-}
-/++
+
 import dwt.DWT;
 import dwt.DWTException;
 import dwt.graphics.Font;
 import dwt.graphics.Image;
 import dwt.graphics.Point;
 import dwt.graphics.Rectangle;
-import dwt.internal.win32.COMPOSITIONFORM;
-import dwt.internal.win32.LOGFONT;
-import dwt.internal.win32.LOGFONTA;
-import dwt.internal.win32.LOGFONTW;
 import dwt.internal.win32.OS;
-import dwt.internal.win32.POINT;
-import dwt.internal.win32.RECT;
+
+import dwt.widgets.Widget;
+import dwt.widgets.Canvas;
+
+import dwt.dwthelper.utils;
 
 /**
  * Instances of this class provide an i-beam that is typically used
@@ -54,14 +42,14 @@
  * </p>
  */
 
-public class Caret extends Widget {
+public class Caret : Widget {
     Canvas parent;
     int x, y, width, height;
     bool moved, resized;
-    bool isVisible;
+    bool isVisible_;
     Image image;
     Font font;
-    LOGFONT oldFont;
+    LOGFONT* oldFont;
 
 /**
  * Constructs a new instance of this class given its parent
@@ -91,30 +79,30 @@
  * @see Widget#checkSubclass
  * @see Widget#getStyle
  */
-public Caret (Canvas parent, int style) {
+public this (Canvas parent, int style) {
     super (parent, style);
     this.parent = parent;
     createWidget ();
 }
 
 void createWidget () {
-    isVisible = true;
+    isVisible_ = true;
     if (parent.getCaret () is null) {
         parent.setCaret (this);
     }
 }
 
-int defaultFont () {
-    int hwnd = parent.handle;
-    int hwndIME = OS.ImmGetDefaultIMEWnd (hwnd);
-    int hFont = 0;
-    if (hwndIME !is 0) {
-        hFont = OS.SendMessage (hwndIME, OS.WM_GETFONT, 0, 0);
+HFONT defaultFont () {
+    auto hwnd = parent.handle;
+    auto hwndIME = OS.ImmGetDefaultIMEWnd (hwnd);
+    HFONT hFont;
+    if (hwndIME !is null) {
+        hFont = cast(HFONT) OS.SendMessage (hwndIME, OS.WM_GETFONT, 0, 0);
     }
-    if (hFont is 0) {
-        hFont = OS.SendMessage (hwnd, OS.WM_GETFONT, 0, 0);
+    if (hFont is null) {
+        hFont = cast(HFONT) OS.SendMessage (hwnd, OS.WM_GETFONT, 0, 0);
     }
-    if (hFont is 0) return parent.defaultFont ();
+    if (hFont is null) return parent.defaultFont ();
     return hFont;
 }
 
@@ -151,7 +139,7 @@
 public Font getFont () {
     checkWidget();
     if (font is null) {
-        int hFont = defaultFont ();
+        HFONT hFont = defaultFont ();
         return Font.win32_new (display, hFont);
     }
     return font;
@@ -241,7 +229,7 @@
  */
 public bool getVisible () {
     checkWidget();
-    return isVisible;
+    return isVisible_;
 }
 
 bool hasFocus () {
@@ -268,7 +256,7 @@
  */
 public bool isVisible () {
     checkWidget();
-    return isVisible && parent.isVisible () && hasFocus ();
+    return isVisible_ && parent.isVisible () && hasFocus ();
 }
 
 void killFocus () {
@@ -284,21 +272,21 @@
 
 void resizeIME () {
     if (!OS.IsDBLocale) return;
-    POINT ptCurrentPos = new POINT ();
-    if (!OS.GetCaretPos (ptCurrentPos)) return;
-    int hwnd = parent.handle;
-    RECT rect = new RECT ();
-    OS.GetClientRect (hwnd, rect);
-    COMPOSITIONFORM lpCompForm = new COMPOSITIONFORM ();
+    POINT ptCurrentPos;
+    if (!OS.GetCaretPos (&ptCurrentPos)) return;
+    auto hwnd = parent.handle;
+    RECT rect;
+    OS.GetClientRect (hwnd, &rect);
+    COMPOSITIONFORM lpCompForm;
     lpCompForm.dwStyle = OS.CFS_RECT;
-    lpCompForm.x = ptCurrentPos.x;
-    lpCompForm.y = ptCurrentPos.y;
-    lpCompForm.left = rect.left;
-    lpCompForm.right = rect.right;
-    lpCompForm.top = rect.top;
-    lpCompForm.bottom = rect.bottom;
-    int hIMC = OS.ImmGetContext (hwnd);
-    OS.ImmSetCompositionWindow (hIMC, lpCompForm);
+    lpCompForm.ptCurrentPos.x = ptCurrentPos.x;
+    lpCompForm.ptCurrentPos.y = ptCurrentPos.y;
+    lpCompForm.rcArea.left = rect.left;
+    lpCompForm.rcArea.right = rect.right;
+    lpCompForm.rcArea.top = rect.top;
+    lpCompForm.rcArea.bottom = rect.bottom;
+    auto hIMC = OS.ImmGetContext (hwnd);
+    OS.ImmSetCompositionWindow (hIMC, &lpCompForm);
     OS.ImmReleaseContext (hwnd, hIMC);
 }
 
@@ -317,9 +305,9 @@
 
 void resize () {
     resized = false;
-    int hwnd = parent.handle;
+    auto hwnd = parent.handle;
     OS.DestroyCaret ();
-    int hBitmap = image !is null ? image.handle : 0;
+    auto hBitmap = image !is null ? image.handle : null;
     OS.CreateCaret (hwnd, hBitmap, width, height);
     OS.SetCaretPos (x, y);
     OS.ShowCaret (hwnd);
@@ -329,8 +317,8 @@
 void restoreIMEFont () {
     if (!OS.IsDBLocale) return;
     if (oldFont is null) return;
-    int hwnd = parent.handle;
-    int hIMC = OS.ImmGetContext (hwnd);
+    auto hwnd = parent.handle;
+    auto hIMC = OS.ImmGetContext (hwnd);
     OS.ImmSetCompositionFont (hIMC, oldFont);
     OS.ImmReleaseContext (hwnd, hIMC);
     oldFont = null;
@@ -361,10 +349,10 @@
     this.width = width;  this.height = height;
     if (sameExtent) {
         moved = true;
-        if (isVisible && hasFocus ()) move ();
+        if (isVisible_ && hasFocus ()) move ();
     } else {
         resized = true;
-        if (isVisible && hasFocus ()) resize ();
+        if (isVisible_ && hasFocus ()) resize ();
     }
 }
 
@@ -387,13 +375,13 @@
 }
 
 void setFocus () {
-    int hwnd = parent.handle;
-    int hBitmap = 0;
+    auto hwnd = parent.handle;
+    HBITMAP hBitmap;
     if (image !is null) hBitmap = image.handle;
     OS.CreateCaret (hwnd, hBitmap, width, height);
     move ();
     setIMEFont ();
-    if (isVisible) OS.ShowCaret (hwnd);
+    if (isVisible_) OS.ShowCaret (hwnd);
 }
 
 /**
@@ -441,25 +429,25 @@
         error (DWT.ERROR_INVALID_ARGUMENT);
     }
     this.image = image;
-    if (isVisible && hasFocus ()) resize ();
+    if (isVisible_ && hasFocus ()) resize ();
 }
 
 void setIMEFont () {
     if (!OS.IsDBLocale) return;
-    int hFont = 0;
+    HFONT hFont;
     if (font !is null) hFont = font.handle;
-    if (hFont is 0) hFont = defaultFont ();
-    int hwnd = parent.handle;
-    int hIMC = OS.ImmGetContext (hwnd);
+    if (hFont is null) hFont = defaultFont ();
+    auto hwnd = parent.handle;
+    auto hIMC = OS.ImmGetContext (hwnd);
     /* Save the current IME font */
     if (oldFont is null) {
-        oldFont = OS.IsUnicode ? (LOGFONT) new LOGFONTW () : new LOGFONTA ();
+        oldFont = new LOGFONT;
         if (!OS.ImmGetCompositionFont (hIMC, oldFont)) oldFont = null;
     }
     /* Set new IME font */
-    LOGFONT logFont = OS.IsUnicode ? (LOGFONT) new LOGFONTW () : new LOGFONTA ();
-    if (OS.GetObject (hFont, LOGFONT.sizeof, logFont) !is 0) {
-        OS.ImmSetCompositionFont (hIMC, logFont);
+    LOGFONT logFont;
+    if (OS.GetObject (hFont, LOGFONT.sizeof, &logFont) !is 0) {
+        OS.ImmSetCompositionFont (hIMC, &logFont);
     }
     OS.ImmReleaseContext (hwnd, hIMC);
 }
@@ -482,7 +470,7 @@
     if (this.x is x && this.y is y) return;
     this.x = x;  this.y = y;
     moved = true;
-    if (isVisible && hasFocus ()) move ();
+    if (isVisible_ && hasFocus ()) move ();
 }
 
 /**
@@ -519,7 +507,7 @@
     if (this.width is width && this.height is height) return;
     this.width = width;  this.height = height;
     resized = true;
-    if (isVisible && hasFocus ()) resize ();
+    if (isVisible_ && hasFocus ()) resize ();
 }
 
 /**
@@ -559,11 +547,11 @@
  */
 public void setVisible (bool visible) {
     checkWidget();
-    if (visible is isVisible) return;
-    isVisible = visible;
-    int hwnd = parent.handle;
+    if (visible is isVisible_) return;
+    isVisible_ = visible;
+    auto hwnd = parent.handle;
     if (OS.GetFocus () !is hwnd) return;
-    if (!isVisible) {
+    if (!isVisible_) {
         OS.HideCaret (hwnd);
     } else {
         if (resized) {
@@ -576,4 +564,3 @@
 }
 
 }
-++/
\ No newline at end of file