changeset 51:6e4e3a8e4971

Label
author Frank Benoit <benoit@tionex.de>
date Sun, 03 Feb 2008 03:43:52 +0100
parents 2146ed8ff33c
children 0553f4e8ed93
files dwt/widgets/Label.d
diffstat 1 files changed, 85 insertions(+), 93 deletions(-) [+]
line wrap: on
line diff
--- a/dwt/widgets/Label.d	Sun Feb 03 03:05:19 2008 +0100
+++ b/dwt/widgets/Label.d	Sun Feb 03 03:43:52 2008 +0100
@@ -12,12 +12,7 @@
  *******************************************************************************/
 module dwt.widgets.Label;
 
-import dwt.widgets.Control;
-import dwt.widgets.Composite;
-class Label : Control {
-    this (Composite parent, int style) ;
-}
-/++
+
 import dwt.DWT;
 import dwt.DWTException;
 import dwt.graphics.GC;
@@ -25,16 +20,14 @@
 import dwt.graphics.Image;
 import dwt.graphics.Point;
 import dwt.graphics.Rectangle;
-import dwt.internal.win32.DRAWITEMSTRUCT;
-import dwt.internal.win32.LRESULT;
 import dwt.internal.win32.OS;
-import dwt.internal.win32.PAINTSTRUCT;
-import dwt.internal.win32.RECT;
-import dwt.internal.win32.TCHAR;
-import dwt.internal.win32.TEXTMETRIC;
-import dwt.internal.win32.TEXTMETRICA;
-import dwt.internal.win32.TEXTMETRICW;
-import dwt.internal.win32.WNDCLASS;
+
+import dwt.widgets.Control;
+import dwt.widgets.Composite;
+import dwt.widgets.Display;
+import dwt.widgets.Event;
+
+import dwt.dwthelper.utils;
 
 /**
  * Instances of this class represent a non-selectable
@@ -58,16 +51,16 @@
  * within the DWT implementation.
  * </p>
  */
-public class Label extends Control {
-    String text = "";
+public class Label : Control {
+    char[] text = "";
     Image image;
-    static final int MARGIN = 4;
-    static final bool IMAGE_AND_TEXT = false;
-    static final int LabelProc;
-    static final TCHAR LabelClass = new TCHAR (0, "STATIC", true);
-    static {
-        WNDCLASS lpWndClass = new WNDCLASS ();
-        OS.GetClassInfo (0, LabelClass, lpWndClass);
+    static const int MARGIN = 4;
+    static const bool IMAGE_AND_TEXT = false;
+    static const WNDPROC LabelProc;
+    static const TCHAR[] LabelClass = "STATIC\0";
+    static this() {
+        WNDCLASS lpWndClass;
+        OS.GetClassInfo (null, LabelClass.ptr, &lpWndClass);
         LabelProc = lpWndClass.lpfnWndProc;
     }
 
@@ -108,13 +101,13 @@
  * @see Widget#checkSubclass
  * @see Widget#getStyle
  */
-public Label (Composite parent, int style) {
+public this (Composite parent, int style) {
     super (parent, checkStyle (style));
 }
 
-int callWindowProc (int hwnd, int msg, int wParam, int lParam) {
-    if (handle is 0) return 0;
-    return OS.CallWindowProc (LabelProc, hwnd, msg, wParam, lParam);
+LRESULT callWindowProc (HWND hwnd, int msg, int wParam, int lParam) {
+    if (handle is null) return LRESULT.NULL;
+    return cast(LRESULT) OS.CallWindowProc (LabelProc, hwnd, msg, wParam, lParam);
 }
 
 static int checkStyle (int style) {
@@ -150,35 +143,35 @@
             width += rect.width;
             height += rect.height;
             if (IMAGE_AND_TEXT) {
-                if (text.length () !is 0) width += MARGIN;
+                if (text.length !is 0) width += MARGIN;
             } else {
                 drawText = false;
             }
         }
     }
     if (drawText) {
-        int hDC = OS.GetDC (handle);
-        int newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
-        int oldFont = OS.SelectObject (hDC, newFont);
+        auto hDC = OS.GetDC (handle);
+        auto newFont = cast(HFONT) OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
+        auto oldFont = OS.SelectObject (hDC, newFont);
         int length = OS.GetWindowTextLength (handle);
         if (length is 0) {
-            TEXTMETRIC tm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW () : new TEXTMETRICA ();
-            OS.GetTextMetrics (hDC, tm);
+            TEXTMETRIC tm;
+            OS.GetTextMetrics (hDC, &tm);
             height = Math.max (height, tm.tmHeight);
         } else {
-            RECT rect = new RECT ();
+            RECT rect;
             int flags = OS.DT_CALCRECT | OS.DT_EDITCONTROL | OS.DT_EXPANDTABS;
             if ((style & DWT.WRAP) !is 0 && wHint !is DWT.DEFAULT) {
                 flags |= OS.DT_WORDBREAK;
                 rect.right = Math.max (0, wHint - width);
             }
-            TCHAR buffer = new TCHAR (getCodePage (), length + 1);
-            OS.GetWindowText (handle, buffer, length + 1);
-            OS.DrawText (hDC, buffer, length, rect, flags);
+            TCHAR[] buffer = new TCHAR [/+getCodePage (),+/ length + 1];
+            OS.GetWindowText (handle, buffer.ptr, length + 1);
+            OS.DrawText (hDC, buffer.ptr, length, &rect, flags);
             width += rect.right - rect.left;
             height = Math.max (height, rect.bottom - rect.top);
         }
-        if (newFont !is 0) OS.SelectObject (hDC, oldFont);
+        if (newFont !is null) OS.SelectObject (hDC, oldFont);
         OS.ReleaseDC (handle, hDC);
     }
     if (wHint !is DWT.DEFAULT) width = wHint;
@@ -239,7 +232,7 @@
     return image;
 }
 
-String getNameText () {
+char[] getNameText () {
     return getText ();
 }
 
@@ -255,13 +248,13 @@
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
  * </ul>
  */
-public String getText () {
+public char[] getText () {
     checkWidget ();
     if ((style & DWT.SEPARATOR) !is 0) return "";
     return text;
 }
 
-bool mnemonicHit (char key) {
+bool mnemonicHit (wchar key) {
     Composite control = this.parent;
     while (control !is null) {
         Control [] children = control._getChildren ();
@@ -279,10 +272,10 @@
     return false;
 }
 
-bool mnemonicMatch (char key) {
-    char mnemonic = findMnemonic (getText ());
+bool mnemonicMatch (wchar key) {
+    wchar mnemonic = findMnemonic (getText ());
     if (mnemonic is '\0') return false;
-    return Character.toUpperCase (key) is Character.toUpperCase (mnemonic);
+    return CharacterToUpper (key) is CharacterToUpper (mnemonic);
 }
 
 void releaseWidget () {
@@ -382,7 +375,7 @@
  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
  * </ul>
  */
-public void setText (String string) {
+public void setText (char[] string) {
     checkWidget ();
     if (string is null) error (DWT.ERROR_NULL_ARGUMENT);
     if ((style & DWT.SEPARATOR) !is 0) return;
@@ -392,7 +385,7 @@
     * has not changed.  The fix is to check for this case and do
     * nothing.
     */
-    if (string.equals (text)) return;
+    if (string==/*eq*/text) return;
     text = string;
     if (image is null || !IMAGE_AND_TEXT) {
         int oldBits = OS.GetWindowLong (handle, OS.GWL_STYLE), newBits = oldBits;
@@ -409,7 +402,7 @@
         if (oldBits !is newBits) OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);
     }
     string = Display.withCrLf (string);
-    TCHAR buffer = new TCHAR (getCodePage (), string, true);
+    TCHAR* buffer = StrToTCHARz (/+getCodePage (),+/ string);
     OS.SetWindowText (handle, buffer);
     /*
     * Bug in Windows.  For some reason, the HBRUSH that
@@ -442,17 +435,17 @@
     return bits | OS.SS_LEFTNOWORDWRAP;
 }
 
-TCHAR windowClass () {
-    return LabelClass;
+char[] windowClass () {
+    return TCHARsToStr( LabelClass );
 }
 
 int windowProc () {
-    return LabelProc;
+    return cast(int) LabelProc;
 }
 
 LRESULT WM_ERASEBKGND (int wParam, int lParam) {
     LRESULT result = super.WM_ERASEBKGND (wParam, lParam);
-    if (result !is null) return result;
+    if (result !is LRESULT.NULL) return result;
     int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
     if ((bits & OS.SS_OWNERDRAW) is OS.SS_OWNERDRAW) {
         return LRESULT.ONE;
@@ -467,7 +460,7 @@
     */
     if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) {
         if (findImageControl () !is null) {
-            drawBackground (wParam);
+            drawBackground (cast(HANDLE)wParam);
             return LRESULT.ONE;
         }
     }
@@ -521,7 +514,7 @@
     if (redraw) {
         OS.InvalidateRect (handle, null, false);
         int code = OS.DefWindowProc (handle, OS.WM_UPDATEUISTATE, wParam, lParam);
-        return new LRESULT (code);
+        return cast(LRESULT) (code);
     }
     return result;
 }
@@ -540,8 +533,8 @@
         int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
         if ((bits & OS.SS_OWNERDRAW) !is OS.SS_OWNERDRAW) {
             if (findImageControl () !is null) {
-                OS.SetBkMode (wParam, OS.TRANSPARENT);
-                return new LRESULT (OS.GetStockObject (OS.NULL_BRUSH));
+                OS.SetBkMode ( cast(HANDLE) wParam, OS.TRANSPARENT);
+                return cast(LRESULT) (OS.GetStockObject (OS.NULL_BRUSH));
             }
         }
     }
@@ -553,28 +546,28 @@
         bool drawImage = image !is null;
         bool drawSeparator = (style & DWT.SEPARATOR) !is 0 && (style & DWT.SHADOW_NONE) is 0;
         if (drawImage || drawSeparator) {
-            LRESULT result = null;
-            PAINTSTRUCT ps = new PAINTSTRUCT ();
+            LRESULT result = LRESULT.NULL;
+            PAINTSTRUCT ps;
             GCData data = new GCData ();
-            data.ps = ps;
+            data.ps = &ps;
             data.hwnd = handle;
             GC gc = new_GC (data);
             if (gc !is null) {
                 drawBackground (gc.handle);
-                RECT clientRect = new RECT();
-                OS.GetClientRect (handle, clientRect);
+                RECT clientRect;
+                OS.GetClientRect (handle, &clientRect);
                 if (drawSeparator) {
-                    RECT rect = new RECT ();
+                    RECT rect;
                     int lineWidth = OS.GetSystemMetrics (OS.SM_CXBORDER);
                     int flags = (style & DWT.SHADOW_IN) !is 0 ? OS.EDGE_SUNKEN : OS.EDGE_ETCHED;
                     if ((style & DWT.HORIZONTAL) !is 0) {
                         int bottom = clientRect.top + Math.max (lineWidth * 2, (clientRect.bottom - clientRect.top) / 2);
-                        OS.SetRect (rect, clientRect.left, clientRect.top, clientRect.right, bottom);
-                        OS.DrawEdge (gc.handle, rect, flags, OS.BF_BOTTOM);
+                        OS.SetRect (&rect, clientRect.left, clientRect.top, clientRect.right, bottom);
+                        OS.DrawEdge (gc.handle, &rect, flags, OS.BF_BOTTOM);
                     } else {
                         int right = clientRect.left + Math.max (lineWidth * 2, (clientRect.right - clientRect.left) / 2);
-                        OS.SetRect (rect, clientRect.left, clientRect.top, right, clientRect.bottom);
-                        OS.DrawEdge (gc.handle, rect, flags, OS.BF_RIGHT);
+                        OS.SetRect (&rect, clientRect.left, clientRect.top, right, clientRect.bottom);
+                        OS.DrawEdge (gc.handle, &rect, flags, OS.BF_RIGHT);
                     }
                     result = LRESULT.ONE;
                 }
@@ -591,13 +584,13 @@
                     gc.drawImage (image, x, Math.max (0, (clientRect.bottom - imageBounds.height) / 2));
                     result = LRESULT.ONE;
                 }
-                int width = ps.right - ps.left;
-                int height = ps.bottom - ps.top;
+                int width = ps.rcPaint.right - ps.rcPaint.left;
+                int height = ps.rcPaint.bottom - ps.rcPaint.top;
                 if (width !is 0 && height !is 0) {
                     Event event = new Event ();
                     event.gc = gc;
-                    event.x = ps.left;
-                    event.y = ps.top;
+                    event.x = ps.rcPaint.left;
+                    event.y = ps.rcPaint.top;
                     event.width = width;
                     event.height = height;
                     sendEvent (DWT.Paint, event);
@@ -613,29 +606,28 @@
 }
 
 LRESULT wmDrawChild (int wParam, int lParam) {
-    DRAWITEMSTRUCT struct = new DRAWITEMSTRUCT ();
-    OS.MoveMemory (struct, lParam, DRAWITEMSTRUCT.sizeof);
-    drawBackground (struct.hDC);
+    DRAWITEMSTRUCT* struct_ = cast(DRAWITEMSTRUCT*)lParam;
+    drawBackground (struct_.hDC);
     if ((style & DWT.SEPARATOR) !is 0) {
-        if ((style & DWT.SHADOW_NONE) !is 0) return null;
-        RECT rect = new RECT ();
+        if ((style & DWT.SHADOW_NONE) !is 0) return LRESULT.NULL;
+        RECT rect;
         int lineWidth = OS.GetSystemMetrics (OS.SM_CXBORDER);
         int flags = (style & DWT.SHADOW_IN) !is 0 ? OS.EDGE_SUNKEN : OS.EDGE_ETCHED;
         if ((style & DWT.HORIZONTAL) !is 0) {
-            int bottom = struct.top + Math.max (lineWidth * 2, (struct.bottom - struct.top) / 2);
-            OS.SetRect (rect, struct.left, struct.top, struct.right, bottom);
-            OS.DrawEdge (struct.hDC, rect, flags, OS.BF_BOTTOM);
+            int bottom = struct_.rcItem.top + Math.max (lineWidth * 2, (struct_.rcItem.bottom - struct_.rcItem.top) / 2);
+            OS.SetRect (&rect, struct_.rcItem.left, struct_.rcItem.top, struct_.rcItem.right, bottom);
+            OS.DrawEdge (struct_.hDC, &rect, flags, OS.BF_BOTTOM);
         } else {
-            int right = struct.left + Math.max (lineWidth * 2, (struct.right - struct.left) / 2);
-            OS.SetRect (rect, struct.left, struct.top, right, struct.bottom);
-            OS.DrawEdge (struct.hDC, rect, flags, OS.BF_RIGHT);
+            int right = struct_.rcItem.left + Math.max (lineWidth * 2, (struct_.rcItem.right - struct_.rcItem.left) / 2);
+            OS.SetRect (&rect, struct_.rcItem.left, struct_.rcItem.top, right, struct_.rcItem.bottom);
+            OS.DrawEdge (struct_.hDC, &rect, flags, OS.BF_RIGHT);
         }
     } else {
-        int width = struct.right - struct.left;
-        int height = struct.bottom - struct.top;
+        int width = struct_.rcItem.right - struct_.rcItem.left;
+        int height = struct_.rcItem.bottom - struct_.rcItem.top;
         if (width !is 0 && height !is 0) {
             bool drawImage = image !is null;
-            bool drawText = IMAGE_AND_TEXT && text.length () !is 0;
+            bool drawText = IMAGE_AND_TEXT && text.length !is 0;
             int margin = drawText && drawImage ? MARGIN : 0;
             int imageWidth = 0, imageHeight = 0;
             if (drawImage) {
@@ -643,11 +635,11 @@
                 imageWidth = rect.width;
                 imageHeight = rect.height;
             }
-            RECT rect = null;
-            TCHAR buffer = null;
+            RECT rect;
+            TCHAR* buffer = null;
             int textWidth = 0, textHeight = 0, flags = 0;
             if (drawText) {
-                rect = new RECT ();
+                //rect = new RECT ();
                 flags = OS.DT_CALCRECT | OS.DT_EDITCONTROL | OS.DT_EXPANDTABS;
                 if ((style & DWT.LEFT) !is 0) flags |= OS.DT_LEFT;
                 if ((style & DWT.CENTER) !is 0) flags |= OS.DT_CENTER;
@@ -656,8 +648,8 @@
                     flags |= OS.DT_WORDBREAK;
                     rect.right = Math.max (0, width - imageWidth - margin);
                 }
-                buffer = new TCHAR (getCodePage (), text, true);
-                OS.DrawText (struct.hDC, buffer, -1, rect, flags);
+                buffer = StrToTCHARz (/+getCodePage (),+/ text);
+                OS.DrawText (struct_.hDC, buffer, -1, &rect, flags);
                 textWidth = rect.right - rect.left;
                 textHeight = rect.bottom - rect.top;
             }
@@ -672,7 +664,7 @@
             if (drawImage) {
                 GCData data = new GCData();
                 data.device = display;
-                GC gc = GC.win32_new (struct.hDC, data);
+                GC gc = GC.win32_new (struct_.hDC, data);
                 Image image = getEnabled () ? this.image : new Image (display, this.image, DWT.IMAGE_DISABLE);
                 gc.drawImage (image, x, Math.max (0, (height - imageHeight) / 2));
                 if (image !is this.image) image.dispose ();
@@ -685,12 +677,12 @@
                 rect.right += rect.left;
                 rect.top = Math.max (0, (height - textHeight) / 2);
                 rect.bottom += rect.top;
-                OS.DrawText (struct.hDC, buffer, -1, rect, flags);
+                OS.DrawText (struct_.hDC, buffer, -1, &rect, flags);
             }
         }
     }
-    return null;
+    return LRESULT.NULL;
 }
 
 }
-++/
+