changeset 49:8b6ed0169471

ExpandItem
author Frank Benoit <benoit@tionex.de>
date Sun, 03 Feb 2008 02:29:42 +0100
parents 9a64a7781bab
children 2146ed8ff33c
files doc/Common.txt dwt/internal/win32/OS.d dwt/internal/win32/WINAPI.d dwt/widgets/ExpandItem.d
diffstat 4 files changed, 83 insertions(+), 104 deletions(-) [+]
line wrap: on
line diff
--- a/doc/Common.txt	Sun Feb 03 01:14:54 2008 +0100
+++ b/doc/Common.txt	Sun Feb 03 02:29:42 2008 +0100
@@ -26,7 +26,10 @@
 Left out widgets:
     DateTime
     DirectoryDialog
+    FileDialog
+    FontDialog
 
 
 
 
+
--- a/dwt/internal/win32/OS.d	Sun Feb 03 01:14:54 2008 +0100
+++ b/dwt/internal/win32/OS.d	Sun Feb 03 02:29:42 2008 +0100
@@ -4255,6 +4255,7 @@
 alias WINAPI.GetMessagePos GetMessagePos;
 alias WINAPI.GetMessageTime GetMessageTime;
 alias STDWIN.GetMetaRgn GetMetaRgn;
+alias WINAPI.GetThemeTextExtent GetThemeTextExtent;
 alias WINAPI.GetMessageW GetMessageW;
 alias WINAPI.GetModuleFileNameA GetModuleFileNameA;
 alias WINAPI.GetModuleFileNameW GetModuleFileNameW;
--- a/dwt/internal/win32/WINAPI.d	Sun Feb 03 01:14:54 2008 +0100
+++ b/dwt/internal/win32/WINAPI.d	Sun Feb 03 02:29:42 2008 +0100
@@ -136,6 +136,18 @@
 WORD PRIMARYLANGID(
   WORD lgid
 );
+
+HRESULT GetThemeTextExtent(
+    HTHEME hTheme,
+    HDC hdc,
+    int iPartId,
+    int iStateId,
+    LPCWSTR pszText,
+    int iCharCount,
+    DWORD dwTextFlags,
+    LPCRECT pBoundingRect,
+    LPRECT pExtentRect
+);
 }
 //--------------------------------------------------------------------------------------
 
--- a/dwt/widgets/ExpandItem.d	Sun Feb 03 01:14:54 2008 +0100
+++ b/dwt/widgets/ExpandItem.d	Sun Feb 03 02:29:42 2008 +0100
@@ -21,52 +21,15 @@
 import dwt.widgets.Control;
 import dwt.widgets.ExpandBar;
 import dwt.widgets.Item;
-class  ExpandItem : Item {
-    public this (Widget parent, int style) {
-        super (parent, style);
-    }
-    void redraw(bool);
-    override void releaseWidget();
-    override void destroyWidget();
-    override void releaseHandle();
-    bool getExpanded();
-    void setControl(Control);
-    void drawItem(GC, HTHEME, RECT*, bool);
-    bool isHover(int, int);
-    void setExpanded(bool);
-    ExpandBar getParent();
-    void setBounds(int, int, int, int, bool, bool);
-    int getHeight();
-    override void setText(char[]);
-    Control getControl();
-    void setHeight(int);
-    override void setImage(Image);
-    int getPreferredWidth(HTHEME, HDC);
-    int getHeaderHeight();
-    ExpandBar parent;
-    Control control;
-    bool expanded;
-    bool hover;
-    int x;
-    int y;
-    int width;
-    int height;
-    int imageHeight;
-    int imageWidth;
-    static int TEXT_INSET;
-    static int BORDER;
-    static int CHEVRON_SIZE;
-}
 
-/++
 import dwt.DWT;
 import dwt.DWTException;
 import dwt.graphics.GC;
 import dwt.graphics.Image;
 import dwt.graphics.Rectangle;
 import dwt.internal.win32.OS;
-import dwt.internal.win32.RECT;
-import dwt.internal.win32.TCHAR;
+
+import dwt.dwthelper.utils;
 
 /**
  * Instances of this class represent a selectable user interface object
@@ -86,15 +49,15 @@
  *
  * @since 3.2
  */
-public class ExpandItem extends Item {
+public class ExpandItem : Item {
     ExpandBar parent;
     Control control;
     bool expanded, hover;
     int x, y, width, height;
     int imageHeight, imageWidth;
-    static final int TEXT_INSET = 6;
-    static final int BORDER = 1;
-    static final int CHEVRON_SIZE = 24;
+    static const int TEXT_INSET = 6;
+    static const int BORDER = 1;
+    static const int CHEVRON_SIZE = 24;
 
 /**
  * Constructs a new instance of this class given its parent
@@ -123,7 +86,7 @@
  * @see Widget#checkSubclass
  * @see Widget#getStyle
  */
-public ExpandItem (ExpandBar parent, int style) {
+public this (ExpandBar parent, int style) {
     this (parent, style, checkNull (parent).getItemCount ());
 }
 
@@ -157,7 +120,7 @@
  * @see Widget#checkSubclass
  * @see Widget#getStyle
  */
-public ExpandItem (ExpandBar parent, int style, int index) {
+public this (ExpandBar parent, int style, int index) {
     super (parent, style);
     this.parent = parent;
     parent.createItem (this, style, index);
@@ -168,55 +131,55 @@
     return control;
 }
 
-private void drawChevron (int hDC, RECT rect) {
-    int oldBrush = OS.SelectObject (hDC, OS.GetSysColorBrush (OS.COLOR_BTNFACE));
+private void drawChevron (HDC hDC, RECT* rect) {
+    HBRUSH oldBrush = OS.SelectObject (hDC, OS.GetSysColorBrush (OS.COLOR_BTNFACE));
     OS.PatBlt (hDC, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, OS.PATCOPY);
     OS.SelectObject (hDC, oldBrush);
     rect.left += 4;
     rect.top += 4;
     rect.right -= 4;
     rect.bottom -= 4;
-    int hPen = OS.CreatePen (OS.PS_SOLID, 1, parent.foreground);
-    int oldPen = OS.SelectObject (hDC, hPen);
+    HPEN hPen = OS.CreatePen (OS.PS_SOLID, 1, parent.foreground);
+    HPEN oldPen = OS.SelectObject (hDC, hPen);
     int [] polyline1, polyline2;
     if (expanded) {
         int px = rect.left + 5;
         int py = rect.top + 7;
-        polyline1 = new int [] {
+        polyline1 = [
                 px,py, px+1,py, px+1,py-1, px+2,py-1, px+2,py-2, px+3,py-2, px+3,py-3,
-                px+3,py-2, px+4,py-2, px+4,py-1, px+5,py-1, px+5,py, px+7,py};
+                px+3,py-2, px+4,py-2, px+4,py-1, px+5,py-1, px+5,py, px+7,py];
         py += 4;
-        polyline2 = new int [] {
+        polyline2 = [
                 px,py, px+1,py, px+1,py-1, px+2,py-1, px+2,py-2, px+3,py-2, px+3,py-3,
-                px+3,py-2, px+4,py-2, px+4,py-1,  px+5,py-1, px+5,py, px+7,py};
+                px+3,py-2, px+4,py-2, px+4,py-1,  px+5,py-1, px+5,py, px+7,py];
     } else {
         int px = rect.left + 5;
         int py = rect.top + 4;
-        polyline1 = new int[] {
+        polyline1 = [
                 px,py, px+1,py, px+1,py+1, px+2,py+1, px+2,py+2, px+3,py+2, px+3,py+3,
-                px+3,py+2, px+4,py+2, px+4,py+1,  px+5,py+1, px+5,py, px+7,py};
+                px+3,py+2, px+4,py+2, px+4,py+1,  px+5,py+1, px+5,py, px+7,py];
         py += 4;
-        polyline2 = new int [] {
+        polyline2 = [
                 px,py, px+1,py, px+1,py+1, px+2,py+1, px+2,py+2, px+3,py+2, px+3,py+3,
-                px+3,py+2, px+4,py+2, px+4,py+1,  px+5,py+1, px+5,py, px+7,py};
+                px+3,py+2, px+4,py+2, px+4,py+1,  px+5,py+1, px+5,py, px+7,py];
     }
-    OS.Polyline (hDC, polyline1, polyline1.length / 2);
-    OS.Polyline (hDC, polyline2, polyline2.length / 2);
+    OS.Polyline (hDC, cast(POINT*)polyline1.ptr, polyline1.length / 2);
+    OS.Polyline (hDC, cast(POINT*)polyline2.ptr, polyline2.length / 2);
     if (hover) {
-        int whitePen = OS.CreatePen (OS.PS_SOLID, 1, OS.GetSysColor (OS.COLOR_3DHILIGHT));
-        int darkGrayPen = OS.CreatePen (OS.PS_SOLID, 1, OS.GetSysColor (OS.COLOR_3DSHADOW));
+        HPEN whitePen = OS.CreatePen (OS.PS_SOLID, 1, OS.GetSysColor (OS.COLOR_3DHILIGHT));
+        HPEN darkGrayPen = OS.CreatePen (OS.PS_SOLID, 1, OS.GetSysColor (OS.COLOR_3DSHADOW));
         OS.SelectObject (hDC, whitePen);
-        int [] points1 = {
+        int [] points1 = [
                 rect.left, rect.bottom,
                 rect.left, rect.top,
-                rect.right, rect.top};
-        OS.Polyline (hDC, points1, points1.length / 2);
+                rect.right, rect.top];
+        OS.Polyline (hDC, cast(POINT*)points1.ptr, points1.length / 2);
         OS.SelectObject (hDC, darkGrayPen);
-        int [] points2 = {
+        int [] points2 = [
                 rect.right, rect.top,
                 rect.right, rect.bottom,
-                rect.left, rect.bottom};
-        OS.Polyline (hDC, points2, points2.length / 2);
+                rect.left, rect.bottom];
+        OS.Polyline (hDC, cast(POINT*)points2.ptr, points2.length / 2);
         OS.SelectObject (hDC, oldPen);
         OS.DeleteObject (whitePen);
         OS.DeleteObject (darkGrayPen);
@@ -227,14 +190,14 @@
 }
 
 void drawItem (GC gc, HTHEME hTheme, RECT* clipRect, bool drawFocus) {
-    int hDC = gc.handle;
+    auto hDC = gc.handle;
     int headerHeight = parent.getBandHeight ();
-    RECT rect = new RECT ();
-    OS.SetRect (rect, x, y, x + width, y + headerHeight);
-    if (hTheme !is 0) {
-        OS.DrawThemeBackground (hTheme, hDC, OS.EBP_NORMALGROUPHEAD, 0, rect, clipRect);
+    RECT rect;
+    OS.SetRect (&rect, x, y, x + width, y + headerHeight);
+    if (hTheme !is null) {
+        OS.DrawThemeBackground (hTheme, hDC, OS.EBP_NORMALGROUPHEAD, 0, &rect, clipRect);
     } else {
-        int oldBrush = OS.SelectObject (hDC, OS.GetSysColorBrush (OS.COLOR_BTNFACE));
+        HBRUSH oldBrush = OS.SelectObject (hDC, OS.GetSysColorBrush (OS.COLOR_BTNFACE));
         OS.PatBlt (hDC, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, OS.PATCOPY);
         OS.SelectObject (hDC, oldBrush);
     }
@@ -247,14 +210,14 @@
         }
         rect.left += imageWidth;
     }
-    if (text.length () > 0) {
+    if (text.length > 0) {
         rect.left += ExpandItem.TEXT_INSET;
-        TCHAR buffer = new TCHAR (parent.getCodePage (), text, false);
-        if (hTheme !is 0) {
-            OS.DrawThemeText (hTheme, hDC, OS.EBP_NORMALGROUPHEAD, 0, buffer.chars, buffer.length(), OS.DT_VCENTER | OS.DT_SINGLELINE, 0, rect);
+        TCHAR[] buffer = StrToTCHARs ( text/+, parent.getCodePage ()+/ );
+        if (hTheme !is null) {
+            OS.DrawThemeText (hTheme, hDC, OS.EBP_NORMALGROUPHEAD, 0, buffer.ptr, buffer.length, OS.DT_VCENTER | OS.DT_SINGLELINE, 0, &rect);
         } else {
             int oldBkMode = OS.SetBkMode (hDC, OS.TRANSPARENT);
-            OS.DrawText (hDC, buffer, buffer.length (), rect, OS.DT_VCENTER | OS.DT_SINGLELINE);
+            OS.DrawText (hDC, buffer.ptr, buffer.length, &rect, OS.DT_VCENTER | OS.DT_SINGLELINE);
             OS.SetBkMode (hDC, oldBkMode);
         }
     }
@@ -262,27 +225,27 @@
     rect.left = rect.right - chevronSize;
     rect.top = y + (headerHeight - chevronSize) / 2;
     rect.bottom = rect.top + chevronSize;
-    if (hTheme !is 0) {
+    if (hTheme !is null) {
         int partID = expanded ? OS.EBP_NORMALGROUPCOLLAPSE : OS.EBP_NORMALGROUPEXPAND;
         int stateID = hover ? OS.EBNGC_HOT : OS.EBNGC_NORMAL;
-        OS.DrawThemeBackground (hTheme, hDC, partID, stateID, rect, clipRect);
+        OS.DrawThemeBackground (hTheme, hDC, partID, stateID, &rect, clipRect);
     } else {
-        drawChevron (hDC, rect);
+        drawChevron (hDC, &rect);
     }
     if (drawFocus) {
-        OS.SetRect (rect, x + 1, y + 1, x + width - 2, y + headerHeight - 2);
-        OS.DrawFocusRect (hDC, rect);
+        OS.SetRect (&rect, x + 1, y + 1, x + width - 2, y + headerHeight - 2);
+        OS.DrawFocusRect (hDC, &rect);
     }
     if (expanded) {
         if (!parent.isAppThemed ()) {
-            int pen = OS.CreatePen (OS.PS_SOLID, 1, OS.GetSysColor (OS.COLOR_BTNFACE));
-            int oldPen = OS.SelectObject (hDC, pen);
-            int [] points = {
+            HPEN pen = OS.CreatePen (OS.PS_SOLID, 1, OS.GetSysColor (OS.COLOR_BTNFACE));
+            HPEN oldPen = OS.SelectObject (hDC, pen);
+            int [] points = [
                     x, y + headerHeight,
                     x, y + headerHeight + height,
                     x + width - 1, y + headerHeight + height,
-                    x + width - 1, y + headerHeight - 1};
-            OS.Polyline (hDC, points, points.length / 2);
+                    x + width - 1, y + headerHeight - 1];
+            OS.Polyline (hDC, cast(POINT*) points.ptr, points.length / 2);
             OS.SelectObject (hDC, oldPen);
             OS.DeleteObject (pen);
         }
@@ -376,13 +339,13 @@
     if (image !is null) {
         width += ExpandItem.TEXT_INSET + imageWidth;
     }
-    if (text.length() > 0) {
-        RECT rect = new RECT ();
-        TCHAR buffer = new TCHAR (parent.getCodePage (), text, false);
-        if (hTheme !is 0) {
-            OS.GetThemeTextExtent (hTheme, hDC, OS.EBP_NORMALGROUPHEAD, 0, buffer.chars, buffer.length(), OS.DT_SINGLELINE, null, rect);
+    if (text.length > 0) {
+        RECT rect;
+        TCHAR[] buffer = StrToTCHARs (/+parent.getCodePage (),+/ text);
+        if (hTheme !is null) {
+            OS.GetThemeTextExtent (hTheme, hDC, OS.EBP_NORMALGROUPHEAD, 0, buffer.ptr, buffer.length, OS.DT_SINGLELINE, null, &rect);
         } else {
-            OS.DrawText (hDC, buffer, buffer.length (), rect, OS.DT_CALCRECT);
+            OS.DrawText (hDC, buffer.ptr, buffer.length, &rect, OS.DT_CALCRECT);
         }
         width += (rect.right - rect.left);
     }
@@ -395,19 +358,19 @@
 }
 
 void redraw (bool all) {
-    int parentHandle = parent.handle;
+    auto parentHandle = parent.handle;
     int headerHeight = parent.getBandHeight ();
-    RECT rect = new RECT ();
+    RECT rect;
     int left = all ? x : x + width - headerHeight;
-    OS.SetRect (rect, left, y, x + width, y + headerHeight);
-    OS.InvalidateRect (parentHandle, rect, true);
+    OS.SetRect (&rect, left, y, x + width, y + headerHeight);
+    OS.InvalidateRect (parentHandle, &rect, true);
     if (imageHeight > headerHeight) {
-        OS.SetRect (rect, x + ExpandItem.TEXT_INSET, y + headerHeight - imageHeight, x + ExpandItem.TEXT_INSET + imageWidth, y);
-        OS.InvalidateRect (parentHandle, rect, true);
+        OS.SetRect (&rect, x + ExpandItem.TEXT_INSET, y + headerHeight - imageHeight, x + ExpandItem.TEXT_INSET + imageWidth, y);
+        OS.InvalidateRect (parentHandle, &rect, true);
     }
     if (!parent.isAppThemed ()) {
-        OS.SetRect (rect, x, y + headerHeight, x + width, y + headerHeight + height + 1);
-        OS.InvalidateRect (parentHandle, rect, true);
+        OS.SetRect (&rect, x, y + headerHeight, x + width, y + headerHeight + height + 1);
+        OS.InvalidateRect (parentHandle, &rect, true);
     }
 }
 
@@ -534,9 +497,9 @@
     }
 }
 
-public void setText (String string) {
+public void setText (char[] string) {
     super.setText (string);
     redraw (true);
 }
 }
-++/
+