diff dwt/widgets/ExpandBar.d @ 47:6940f8be58ba

ExpandBar
author Frank Benoit <benoit@tionex.de>
date Sun, 03 Feb 2008 00:59:28 +0100
parents 92c102dd64a3
children 0f25be5cbe6f
line wrap: on
line diff
--- a/dwt/widgets/ExpandBar.d	Sat Feb 02 19:56:40 2008 +0100
+++ b/dwt/widgets/ExpandBar.d	Sun Feb 03 00:59:28 2008 +0100
@@ -12,10 +12,7 @@
  *******************************************************************************/
 module dwt.widgets.ExpandBar;
 
-import dwt.widgets.Composite;
-class ExpandBar : Composite {
-}
-/++
+
 import dwt.DWT;
 import dwt.DWTException;
 import dwt.events.ExpandAdapter;
@@ -26,19 +23,18 @@
 import dwt.graphics.GCData;
 import dwt.graphics.Point;
 import dwt.graphics.Rectangle;
-import dwt.internal.win32.LOGFONT;
-import dwt.internal.win32.LRESULT;
-import dwt.internal.win32.NONCLIENTMETRICS;
-import dwt.internal.win32.NONCLIENTMETRICSA;
-import dwt.internal.win32.NONCLIENTMETRICSW;
+import dwt.graphics.Drawable;
 import dwt.internal.win32.OS;
-import dwt.internal.win32.PAINTSTRUCT;
-import dwt.internal.win32.RECT;
-import dwt.internal.win32.SCROLLINFO;
-import dwt.internal.win32.TCHAR;
-import dwt.internal.win32.TEXTMETRIC;
-import dwt.internal.win32.TEXTMETRICA;
-import dwt.internal.win32.TEXTMETRICW;
+
+import dwt.widgets.Composite;
+import dwt.widgets.Control;
+import dwt.widgets.ExpandItem;
+import dwt.widgets.ScrollBar;
+import dwt.widgets.ExpandItem;
+import dwt.widgets.TypedListener;
+import dwt.widgets.Event;
+
+import dwt.dwthelper.utils;
 
 /**
  * Instances of this class support the layout of selectable
@@ -64,13 +60,13 @@
  *
  * @since 3.2
  */
-public class ExpandBar extends Composite {
+public class ExpandBar : Composite {
     ExpandItem[] items;
     int itemCount;
     ExpandItem focusItem;
     int spacing = 4;
     int yCurrentScroll;
-    int hFont;
+    HFONT hFont;
 
 
 /**
@@ -100,7 +96,7 @@
  * @see Widget#checkSubclass
  * @see Widget#getStyle
  */
-public ExpandBar (Composite parent, int style) {
+public this (Composite parent, int style) {
     super (parent, checkStyle (style));
 }
 
@@ -131,9 +127,9 @@
     addListener (DWT.Collapse, typedListener);
 }
 
-int callWindowProc (int hwnd, int msg, int wParam, int lParam) {
-    if (handle is 0) return 0;
-    return OS.DefWindowProc (hwnd, msg, wParam, lParam);
+LRESULT callWindowProc (HWND hwnd, int msg, int wParam, int lParam) {
+    if (handle is null) return LRESULT.ZERO;
+    return cast(LRESULT) OS.DefWindowProc (hwnd, msg, wParam, lParam);
 }
 
 protected void checkSubclass () {
@@ -150,26 +146,26 @@
     int height = 0, width = 0;
     if (wHint is DWT.DEFAULT || hHint is DWT.DEFAULT) {
         if (itemCount > 0) {
-            int hDC = OS.GetDC (handle);
-            int hTheme = 0;
+            auto hDC = OS.GetDC (handle);
+            HTHEME hTheme;
             if (isAppThemed ()) {
                 hTheme = display.hExplorerBarTheme ();
             }
-            int hCurrentFont = 0, oldFont = 0;
-            if (hTheme is 0) {
-                if (hFont !is 0) {
+            HFONT hCurrentFont, oldFont;
+            if (hTheme is null) {
+                if (hFont !is null) {
                     hCurrentFont = hFont;
                 } else {
                     if (!OS.IsWinCE) {
-                        NONCLIENTMETRICS info = OS.IsUnicode ? (NONCLIENTMETRICS) new NONCLIENTMETRICSW () : new NONCLIENTMETRICSA ();
+                        NONCLIENTMETRICS info;
                         info.cbSize = NONCLIENTMETRICS.sizeof;
-                        if (OS.SystemParametersInfo (OS.SPI_GETNONCLIENTMETRICS, 0, info, 0)) {
-                            LOGFONT logFont = OS.IsUnicode ? (LOGFONT) ((NONCLIENTMETRICSW)info).lfCaptionFont : ((NONCLIENTMETRICSA)info).lfCaptionFont;
+                        if (OS.SystemParametersInfo (OS.SPI_GETNONCLIENTMETRICS, 0, &info, 0)) {
+                            LOGFONT* logFont = &info.lfCaptionFont;
                             hCurrentFont = OS.CreateFontIndirect (logFont);
                         }
                     }
                 }
-                if (hCurrentFont !is 0) {
+                if (hCurrentFont !is null) {
                     oldFont = OS.SelectObject (hDC, hCurrentFont);
                 }
             }
@@ -181,7 +177,7 @@
                 height += spacing;
                 width = Math.max (width, item.getPreferredWidth (hTheme, hDC));
             }
-            if (hCurrentFont !is 0) {
+            if (hCurrentFont !is null) {
                 OS.SelectObject (hDC, oldFont);
                 if (hCurrentFont !is hFont) OS.DeleteObject (hCurrentFont);
             }
@@ -214,8 +210,8 @@
     itemCount++;
     if (focusItem is null) focusItem = item;
 
-    RECT rect = new RECT ();
-    OS.GetWindowRect (handle, rect);
+    RECT rect;
+    OS.GetWindowRect (handle, &rect);
     item.width = Math.max (0, rect.right - rect.left - spacing * 2);
     layoutItems (index, true);
 }
@@ -257,22 +253,22 @@
     layoutItems (index, true);
 }
 
-void drawThemeBackground (int hDC, int hwnd, RECT rect) {
-    RECT rect2 = new RECT ();
-    OS.GetClientRect (handle, rect2);
-    OS.MapWindowPoints (handle, hwnd, rect2, 2);
-    OS.DrawThemeBackground (display.hExplorerBarTheme (), hDC, OS.EBP_NORMALGROUPBACKGROUND, 0, rect2, null);
+void drawThemeBackground (HDC hDC, HWND hwnd, RECT* rect) {
+    RECT rect2;
+    OS.GetClientRect (handle, &rect2);
+    OS.MapWindowPoints (handle, hwnd, cast(POINT*) &rect2, 2);
+    OS.DrawThemeBackground (display.hExplorerBarTheme (), hDC, OS.EBP_NORMALGROUPBACKGROUND, 0, &rect2, null);
 }
 
-void drawWidget (GC gc, RECT clipRect) {
-    int hTheme = 0;
+void drawWidget (GC gc, RECT* clipRect) {
+    HTHEME hTheme;
     if (isAppThemed ()) {
         hTheme = display.hExplorerBarTheme ();
     }
-    if (hTheme !is 0) {
-        RECT rect = new RECT ();
-        OS.GetClientRect (handle, rect);
-        OS.DrawThemeBackground (hTheme, gc.handle, OS.EBP_HEADERBACKGROUND, 0, rect, clipRect);
+    if (hTheme !is null) {
+        RECT rect;
+        OS.GetClientRect (handle, &rect);
+        OS.DrawThemeBackground (hTheme, gc.handle, OS.EBP_HEADERBACKGROUND, 0, &rect, clipRect);
     } else {
         drawBackground (gc.handle);
     }
@@ -281,13 +277,13 @@
         int uiState = OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
         drawFocus = (uiState & OS.UISF_HIDEFOCUS) is 0;
     }
-    int hCaptionFont = 0, oldFont = 0;
-    if (hTheme is 0) {
-        if (!OS.IsWinCE && hFont is 0) {
-            NONCLIENTMETRICS info = OS.IsUnicode ? (NONCLIENTMETRICS) new NONCLIENTMETRICSW () : new NONCLIENTMETRICSA ();
+    HFONT hCaptionFont, oldFont;
+    if (hTheme is null) {
+        if (!OS.IsWinCE && hFont is null) {
+            NONCLIENTMETRICS info;
             info.cbSize = NONCLIENTMETRICS.sizeof;
-            if (OS.SystemParametersInfo (OS.SPI_GETNONCLIENTMETRICS, 0, info, 0)) {
-                LOGFONT logFont = OS.IsUnicode ? (LOGFONT) ((NONCLIENTMETRICSW)info).lfCaptionFont : ((NONCLIENTMETRICSA)info).lfCaptionFont;
+            if (OS.SystemParametersInfo (OS.SPI_GETNONCLIENTMETRICS, 0, &info, 0)) {
+                LOGFONT* logFont = &info.lfCaptionFont;
                 hCaptionFont = OS.CreateFontIndirect (logFont);
                 oldFont = OS.SelectObject (gc.handle, hCaptionFont);
             }
@@ -297,7 +293,7 @@
         ExpandItem item = items[i];
         item.drawItem (gc, hTheme, clipRect, item is focusItem && drawFocus);
     }
-    if (hCaptionFont !is 0) {
+    if (hCaptionFont !is null) {
         OS.SelectObject (gc.handle, oldFont);
         OS.DeleteObject (hCaptionFont);
     }
@@ -316,11 +312,11 @@
 }
 
 int getBandHeight () {
-    if (hFont is 0) return ExpandItem.CHEVRON_SIZE;
-    int hDC = OS.GetDC (handle);
-    int oldHFont = OS.SelectObject (hDC, hFont);
-    TEXTMETRIC lptm = OS.IsUnicode ? (TEXTMETRIC)new TEXTMETRICW() : new TEXTMETRICA();
-    OS.GetTextMetrics (hDC, lptm);
+    if (hFont is null) return ExpandItem.CHEVRON_SIZE;
+    auto hDC = OS.GetDC (handle);
+    auto oldHFont = OS.SelectObject (hDC, hFont);
+    TEXTMETRIC lptm;
+    OS.GetTextMetrics (hDC, &lptm);
     OS.SelectObject (hDC, oldHFont);
     OS.ReleaseDC (handle, hDC);
     return Math.max (ExpandItem.CHEVRON_SIZE, lptm.tmHeight + 4);
@@ -430,11 +426,11 @@
 bool isAppThemed () {
     if (background !is -1) return false;
     if (foreground !is -1) return false;
-    if (hFont !is 0) return false;
+    if (hFont !is null) return false;
     return OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ();
 }
 
-void layoutItems (int index, bool setScrollbar) {
+void layoutItems (int index, bool setScrollbar_) {
     if (index < itemCount) {
         int y = spacing - yCurrentScroll;
         for (int i = 0; i < index; i++) {
@@ -449,7 +445,7 @@
             y += item.getHeaderHeight () + spacing;
         }
     }
-    if (setScrollbar) setScrollbar ();
+    if (setScrollbar_) setScrollbar ();
 }
 
 void releaseChildren (bool destroy) {
@@ -495,13 +491,13 @@
     super.setBackgroundPixel (pixel);
     if (!OS.IsWinCE) {
         int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE | OS.RDW_ALLCHILDREN;
-        OS.RedrawWindow (handle, null, 0, flags);
+        OS.RedrawWindow (handle, null, null, flags);
     }
 }
 
 public void setFont (Font font) {
     super.setFont (font);
-    hFont = font !is null ? font.handle : 0;
+    hFont = font !is null ? font.handle : null;
     layoutItems (0, true);
 }
 
@@ -509,15 +505,15 @@
     super.setForegroundPixel (pixel);
     if (!OS.IsWinCE) {
         int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE | OS.RDW_ALLCHILDREN;
-        OS.RedrawWindow (handle, null, 0, flags);
+        OS.RedrawWindow (handle, null, null, flags);
     }
 }
 
 void setScrollbar () {
     if (itemCount is 0) return;
     if ((style & DWT.V_SCROLL) is 0) return;
-    RECT rect = new RECT();
-    OS.GetClientRect (handle, rect);
+    RECT rect;
+    OS.GetClientRect (handle, &rect);
     int height = rect.bottom - rect.top;
     ExpandItem item = items [itemCount - 1];
     int maxHeight = item.y + getBandHeight () + spacing;
@@ -530,7 +526,7 @@
     }
     maxHeight += yCurrentScroll;
 
-    SCROLLINFO info = new SCROLLINFO ();
+    SCROLLINFO info;
     info.cbSize = SCROLLINFO.sizeof;
     info.fMask = OS.SIF_RANGE | OS.SIF_PAGE | OS.SIF_POS;
     info.nMin = 0;
@@ -538,7 +534,7 @@
     info.nPage = height;
     info.nPos = Math.min (yCurrentScroll, info.nMax);
     if (info.nPage !is 0) info.nPage++;
-    OS.SetScrollInfo (handle, OS.SB_VERT, info, true);
+    OS.SetScrollInfo (handle, OS.SB_VERT, &info, true);
 }
 
 /**
@@ -555,8 +551,8 @@
     if (spacing < 0) return;
     if (spacing is this.spacing) return;
     this.spacing = spacing;
-    RECT rect = new RECT ();
-    OS.GetClientRect (handle, rect);
+    RECT rect;
+    OS.GetClientRect (handle, &rect);
     int width = Math.max (0, (rect.right - rect.left) - spacing * 2);
     for (int i = 0; i < itemCount; i++) {
         ExpandItem item = items[i];
@@ -576,17 +572,17 @@
     layoutItems (index + 1, true);
 }
 
-TCHAR windowClass () {
-    return display.windowClass;
+char[] windowClass () {
+    return display.windowClass();
 }
 
 int windowProc () {
-    return display.windowProc;
+    return cast(int) display.windowProc;
 }
 
 LRESULT WM_KEYDOWN (int wParam, int lParam) {
     LRESULT result = super.WM_KEYDOWN (wParam, lParam);
-    if (result !is null) return result;
+    if (result !is LRESULT.NULL) return result;
     if (focusItem is null) return result;
     switch (wParam) {
         case OS.VK_SPACE:
@@ -630,8 +626,8 @@
 LRESULT WM_LBUTTONDOWN (int wParam, int lParam) {
     LRESULT result = super.WM_LBUTTONDOWN (wParam, lParam);
     if (result is LRESULT.ZERO) return result;
-    int x = (short) (lParam & 0xFFFF);
-    int y = (short) (lParam >> 16);
+    int x = cast(short) (lParam & 0xFFFF);
+    int y = cast(short) (lParam >> 16);
     for (int i = 0; i < itemCount; i++) {
         ExpandItem item = items[i];
         bool hover = item.isHover (x, y);
@@ -650,8 +646,8 @@
     LRESULT result = super.WM_LBUTTONUP (wParam, lParam);
     if (result is LRESULT.ZERO) return result;
     if (focusItem is null) return result;
-    int x = (short) (lParam & 0xFFFF);
-    int y = (short) (lParam >> 16);
+    int x = cast(short) (lParam & 0xFFFF);
+    int y = cast(short) (lParam >> 16);
     bool hover = focusItem.isHover (x, y);
     if (hover) {
         Event event = new Event ();
@@ -665,7 +661,7 @@
 
 LRESULT WM_MOUSELEAVE (int wParam, int lParam) {
     LRESULT result = super.WM_MOUSELEAVE (wParam, lParam);
-    if (result !is null) return result;
+    if (result !is LRESULT.NULL) return result;
     for (int i = 0; i < itemCount; i++) {
         ExpandItem item = items [i];
         if (item.hover) {
@@ -680,8 +676,8 @@
 LRESULT WM_MOUSEMOVE (int wParam, int lParam) {
     LRESULT result = super.WM_MOUSEMOVE (wParam, lParam);
     if (result is LRESULT.ZERO) return result;
-    int x = (short) (lParam & 0xFFFF);
-    int y = (short) (lParam >> 16);
+    int x = cast(short) (lParam & 0xFFFF);
+    int y = cast(short) (lParam >> 16);
     for (int i = 0; i < itemCount; i++) {
         ExpandItem item = items [i];
         bool hover = item.isHover (x, y);
@@ -694,18 +690,18 @@
 }
 
 LRESULT WM_PAINT (int wParam, int lParam) {
-    PAINTSTRUCT ps = new PAINTSTRUCT ();
+    PAINTSTRUCT ps;
     GCData data = new GCData ();
-    data.ps = ps;
+    data.ps = &ps;
     data.hwnd = handle;
     GC gc = new_GC (data);
     if (gc !is null) {
-        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) {
-            RECT rect = new RECT ();
-            OS.SetRect (rect, ps.left, ps.top, ps.right, ps.bottom);
-            drawWidget (gc, rect);
+            RECT rect;
+            OS.SetRect (&rect, ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
+            drawWidget (gc, &rect);
             if (hooks (DWT.Paint) || filters (DWT.Paint)) {
                 Event event = new Event ();
                 event.gc = gc;
@@ -724,26 +720,26 @@
 
 LRESULT WM_PRINTCLIENT (int wParam, int lParam) {
     LRESULT result = super.WM_PRINTCLIENT (wParam, lParam);
-    RECT rect = new RECT ();
-    OS.GetClientRect (handle, rect);
+    RECT rect;
+    OS.GetClientRect (handle, &rect);
     GCData data = new GCData ();
     data.device = display;
     data.foreground = getForegroundPixel ();
-    GC gc = GC.win32_new (wParam, data);
-    drawWidget (gc, rect);
+    GC gc = GC.win32_new ( cast(Drawable)cast(void*)wParam, data);
+    drawWidget (gc, &rect);
     gc.dispose ();
     return result;
 }
 
 LRESULT WM_SETCURSOR (int wParam, int lParam) {
     LRESULT result = super.WM_SETCURSOR (wParam, lParam);
-    if (result !is null) return result;
+    if (result !is LRESULT.NULL) return result;
     int hitTest = lParam & 0xFFFF;
     if (hitTest is OS.HTCLIENT) {
         for (int i = 0; i < itemCount; i++) {
             ExpandItem item = items [i];
             if (item.hover) {
-                int hCursor = OS.LoadCursor (0, OS.IDC_HAND);
+                auto hCursor = OS.LoadCursor (null, OS.IDC_HAND);
                 OS.SetCursor (hCursor);
                 return LRESULT.ONE;
             }
@@ -760,8 +756,8 @@
 
 LRESULT WM_SIZE (int wParam, int lParam) {
     LRESULT result = super.WM_SIZE (wParam, lParam);
-    RECT rect = new RECT ();
-    OS.GetClientRect (handle, rect);
+    RECT rect;
+    OS.GetClientRect (handle, &rect);
     int width = Math.max (0, (rect.right - rect.left) - spacing * 2);
     for (int i = 0; i < itemCount; i++) {
         ExpandItem item = items[i];
@@ -772,14 +768,14 @@
     return result;
 }
 
-LRESULT wmScroll (ScrollBar bar, bool update, int hwnd, int msg, int wParam, int lParam) {
+LRESULT wmScroll (ScrollBar bar, bool update, HWND hwnd, int msg, int wParam, int lParam) {
     LRESULT result = super.wmScroll (bar, true, hwnd, msg, wParam, lParam);
-    SCROLLINFO info = new SCROLLINFO ();
+    SCROLLINFO info;
     info.cbSize = SCROLLINFO.sizeof;
     info.fMask = OS.SIF_POS;
-    OS.GetScrollInfo (handle, OS.SB_VERT, info);
+    OS.GetScrollInfo (handle, OS.SB_VERT, &info);
     int updateY = yCurrentScroll - info.nPos;
-    OS.ScrollWindowEx (handle, 0, updateY, null, null, 0, null, OS.SW_SCROLLCHILDREN | OS.SW_INVALIDATE);
+    OS.ScrollWindowEx (handle, 0, updateY, null, null, null, null, OS.SW_SCROLLCHILDREN | OS.SW_INVALIDATE);
     yCurrentScroll = info.nPos;
     if (updateY !is 0) {
         for (int i = 0; i < itemCount; i++) {
@@ -789,4 +785,4 @@
     return result;
 }
 }
-++/
+