Changeset 49:8b6ed0169471

Show
Ignore:
Timestamp:
02/02/08 20:29:42 (1 year ago)
Author:
Frank Benoit <benoit@tionex.de>
branch:
default
Message:

ExpandItem?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • doc/Common.txt

    r47 r49  
    2727    DateTime 
    2828    DirectoryDialog 
     29    FileDialog 
     30    FontDialog 
    2931 
    3032 
    3133 
    3234 
     35 
  • dwt/internal/win32/OS.d

    r47 r49  
    42564256alias WINAPI.GetMessageTime GetMessageTime; 
    42574257alias STDWIN.GetMetaRgn GetMetaRgn; 
     4258alias WINAPI.GetThemeTextExtent GetThemeTextExtent; 
    42584259alias WINAPI.GetMessageW GetMessageW; 
    42594260alias WINAPI.GetModuleFileNameA GetModuleFileNameA; 
  • dwt/internal/win32/WINAPI.d

    r38 r49  
    136136WORD PRIMARYLANGID( 
    137137  WORD lgid 
     138); 
     139 
     140HRESULT GetThemeTextExtent( 
     141    HTHEME hTheme, 
     142    HDC hdc, 
     143    int iPartId, 
     144    int iStateId, 
     145    LPCWSTR pszText, 
     146    int iCharCount, 
     147    DWORD dwTextFlags, 
     148    LPCRECT pBoundingRect, 
     149    LPRECT pExtentRect 
    138150); 
    139151} 
  • dwt/widgets/ExpandItem.d

    r47 r49  
    2222import dwt.widgets.ExpandBar; 
    2323import dwt.widgets.Item; 
    24 class  ExpandItem : Item { 
    25     public this (Widget parent, int style) { 
    26         super (parent, style); 
    27     } 
    28     void redraw(bool); 
    29     override void releaseWidget(); 
    30     override void destroyWidget(); 
    31     override void releaseHandle(); 
    32     bool getExpanded(); 
    33     void setControl(Control); 
    34     void drawItem(GC, HTHEME, RECT*, bool); 
    35     bool isHover(int, int); 
    36     void setExpanded(bool); 
    37     ExpandBar getParent(); 
    38     void setBounds(int, int, int, int, bool, bool); 
    39     int getHeight(); 
    40     override void setText(char[]); 
    41     Control getControl(); 
    42     void setHeight(int); 
    43     override void setImage(Image); 
    44     int getPreferredWidth(HTHEME, HDC); 
    45     int getHeaderHeight(); 
    46     ExpandBar parent; 
    47     Control control; 
    48     bool expanded; 
    49     bool hover; 
    50     int x; 
    51     int y; 
    52     int width; 
    53     int height; 
    54     int imageHeight; 
    55     int imageWidth; 
    56     static int TEXT_INSET; 
    57     static int BORDER; 
    58     static int CHEVRON_SIZE; 
    59 
    60  
    61 /++ 
     24 
    6225import dwt.DWT; 
    6326import dwt.DWTException; 
     
    6629import dwt.graphics.Rectangle; 
    6730import dwt.internal.win32.OS; 
    68 import dwt.internal.win32.RECT; 
    69 import dwt.internal.win32.TCHAR
     31 
     32import dwt.dwthelper.utils
    7033 
    7134/** 
     
    8750 * @since 3.2 
    8851 */ 
    89 public class ExpandItem extends Item { 
     52public class ExpandItem : Item { 
    9053    ExpandBar parent; 
    9154    Control control; 
     
    9356    int x, y, width, height; 
    9457    int imageHeight, imageWidth; 
    95     static final int TEXT_INSET = 6; 
    96     static final int BORDER = 1; 
    97     static final int CHEVRON_SIZE = 24; 
     58    static const int TEXT_INSET = 6; 
     59    static const int BORDER = 1; 
     60    static const int CHEVRON_SIZE = 24; 
    9861 
    9962/** 
     
    12487 * @see Widget#getStyle 
    12588 */ 
    126 public ExpandItem (ExpandBar parent, int style) { 
     89public this (ExpandBar parent, int style) { 
    12790    this (parent, style, checkNull (parent).getItemCount ()); 
    12891} 
     
    158121 * @see Widget#getStyle 
    159122 */ 
    160 public ExpandItem (ExpandBar parent, int style, int index) { 
     123public this (ExpandBar parent, int style, int index) { 
    161124    super (parent, style); 
    162125    this.parent = parent; 
     
    169132} 
    170133 
    171 private void drawChevron (int hDC, RECT rect) { 
    172     int oldBrush = OS.SelectObject (hDC, OS.GetSysColorBrush (OS.COLOR_BTNFACE)); 
     134private void drawChevron (HDC hDC, RECT* rect) { 
     135    HBRUSH oldBrush = OS.SelectObject (hDC, OS.GetSysColorBrush (OS.COLOR_BTNFACE)); 
    173136    OS.PatBlt (hDC, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, OS.PATCOPY); 
    174137    OS.SelectObject (hDC, oldBrush); 
     
    177140    rect.right -= 4; 
    178141    rect.bottom -= 4; 
    179     int hPen = OS.CreatePen (OS.PS_SOLID, 1, parent.foreground); 
    180     int oldPen = OS.SelectObject (hDC, hPen); 
     142    HPEN hPen = OS.CreatePen (OS.PS_SOLID, 1, parent.foreground); 
     143    HPEN oldPen = OS.SelectObject (hDC, hPen); 
    181144    int [] polyline1, polyline2; 
    182145    if (expanded) { 
    183146        int px = rect.left + 5; 
    184147        int py = rect.top + 7; 
    185         polyline1 = new int [] { 
     148        polyline1 = [ 
    186149                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, 
    187                 px+3,py-2, px+4,py-2, px+4,py-1, px+5,py-1, px+5,py, px+7,py}
     150                px+3,py-2, px+4,py-2, px+4,py-1, px+5,py-1, px+5,py, px+7,py]
    188151        py += 4; 
    189         polyline2 = new int [] { 
     152        polyline2 = [ 
    190153                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, 
    191                 px+3,py-2, px+4,py-2, px+4,py-1,  px+5,py-1, px+5,py, px+7,py}
     154                px+3,py-2, px+4,py-2, px+4,py-1,  px+5,py-1, px+5,py, px+7,py]
    192155    } else { 
    193156        int px = rect.left + 5; 
    194157        int py = rect.top + 4; 
    195         polyline1 = new int[] { 
     158        polyline1 = [ 
    196159                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, 
    197                 px+3,py+2, px+4,py+2, px+4,py+1,  px+5,py+1, px+5,py, px+7,py}
     160                px+3,py+2, px+4,py+2, px+4,py+1,  px+5,py+1, px+5,py, px+7,py]
    198161        py += 4; 
    199         polyline2 = new int [] { 
     162        polyline2 = [ 
    200163                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, 
    201                 px+3,py+2, px+4,py+2, px+4,py+1,  px+5,py+1, px+5,py, px+7,py}
    202     } 
    203     OS.Polyline (hDC, polyline1, polyline1.length / 2); 
    204     OS.Polyline (hDC, polyline2, polyline2.length / 2); 
     164                px+3,py+2, px+4,py+2, px+4,py+1,  px+5,py+1, px+5,py, px+7,py]
     165    } 
     166    OS.Polyline (hDC, cast(POINT*)polyline1.ptr, polyline1.length / 2); 
     167    OS.Polyline (hDC, cast(POINT*)polyline2.ptr, polyline2.length / 2); 
    205168    if (hover) { 
    206         int whitePen = OS.CreatePen (OS.PS_SOLID, 1, OS.GetSysColor (OS.COLOR_3DHILIGHT)); 
    207         int darkGrayPen = OS.CreatePen (OS.PS_SOLID, 1, OS.GetSysColor (OS.COLOR_3DSHADOW)); 
     169        HPEN whitePen = OS.CreatePen (OS.PS_SOLID, 1, OS.GetSysColor (OS.COLOR_3DHILIGHT)); 
     170        HPEN darkGrayPen = OS.CreatePen (OS.PS_SOLID, 1, OS.GetSysColor (OS.COLOR_3DSHADOW)); 
    208171        OS.SelectObject (hDC, whitePen); 
    209         int [] points1 = { 
     172        int [] points1 = [ 
    210173                rect.left, rect.bottom, 
    211174                rect.left, rect.top, 
    212                 rect.right, rect.top}
    213         OS.Polyline (hDC, points1, points1.length / 2); 
     175                rect.right, rect.top]
     176        OS.Polyline (hDC, cast(POINT*)points1.ptr, points1.length / 2); 
    214177        OS.SelectObject (hDC, darkGrayPen); 
    215         int [] points2 = { 
     178        int [] points2 = [ 
    216179                rect.right, rect.top, 
    217180                rect.right, rect.bottom, 
    218                 rect.left, rect.bottom}
    219         OS.Polyline (hDC, points2, points2.length / 2); 
     181                rect.left, rect.bottom]
     182        OS.Polyline (hDC, cast(POINT*)points2.ptr, points2.length / 2); 
    220183        OS.SelectObject (hDC, oldPen); 
    221184        OS.DeleteObject (whitePen); 
     
    228191 
    229192void drawItem (GC gc, HTHEME hTheme, RECT* clipRect, bool drawFocus) { 
    230     int hDC = gc.handle; 
     193    auto hDC = gc.handle; 
    231194    int headerHeight = parent.getBandHeight (); 
    232     RECT rect = new RECT ()
    233     OS.SetRect (rect, x, y, x + width, y + headerHeight); 
    234     if (hTheme !is 0) { 
    235         OS.DrawThemeBackground (hTheme, hDC, OS.EBP_NORMALGROUPHEAD, 0, rect, clipRect); 
     195    RECT rect
     196    OS.SetRect (&rect, x, y, x + width, y + headerHeight); 
     197    if (hTheme !is null) { 
     198        OS.DrawThemeBackground (hTheme, hDC, OS.EBP_NORMALGROUPHEAD, 0, &rect, clipRect); 
    236199    } else { 
    237         int oldBrush = OS.SelectObject (hDC, OS.GetSysColorBrush (OS.COLOR_BTNFACE)); 
     200        HBRUSH oldBrush = OS.SelectObject (hDC, OS.GetSysColorBrush (OS.COLOR_BTNFACE)); 
    238201        OS.PatBlt (hDC, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, OS.PATCOPY); 
    239202        OS.SelectObject (hDC, oldBrush); 
     
    248211        rect.left += imageWidth; 
    249212    } 
    250     if (text.length () > 0) { 
     213    if (text.length > 0) { 
    251214        rect.left += ExpandItem.TEXT_INSET; 
    252         TCHAR buffer = new TCHAR (parent.getCodePage (), text, false); 
    253         if (hTheme !is 0) { 
    254             OS.DrawThemeText (hTheme, hDC, OS.EBP_NORMALGROUPHEAD, 0, buffer.chars, buffer.length(), OS.DT_VCENTER | OS.DT_SINGLELINE, 0, rect); 
     215        TCHAR[] buffer = StrToTCHARs ( text/+, parent.getCodePage ()+/ ); 
     216        if (hTheme !is null) { 
     217            OS.DrawThemeText (hTheme, hDC, OS.EBP_NORMALGROUPHEAD, 0, buffer.ptr, buffer.length, OS.DT_VCENTER | OS.DT_SINGLELINE, 0, &rect); 
    255218        } else { 
    256219            int oldBkMode = OS.SetBkMode (hDC, OS.TRANSPARENT); 
    257             OS.DrawText (hDC, buffer, buffer.length (), rect, OS.DT_VCENTER | OS.DT_SINGLELINE); 
     220            OS.DrawText (hDC, buffer.ptr, buffer.length, &rect, OS.DT_VCENTER | OS.DT_SINGLELINE); 
    258221            OS.SetBkMode (hDC, oldBkMode); 
    259222        } 
     
    263226    rect.top = y + (headerHeight - chevronSize) / 2; 
    264227    rect.bottom = rect.top + chevronSize; 
    265     if (hTheme !is 0) { 
     228    if (hTheme !is null) { 
    266229        int partID = expanded ? OS.EBP_NORMALGROUPCOLLAPSE : OS.EBP_NORMALGROUPEXPAND; 
    267230        int stateID = hover ? OS.EBNGC_HOT : OS.EBNGC_NORMAL; 
    268         OS.DrawThemeBackground (hTheme, hDC, partID, stateID, rect, clipRect); 
     231        OS.DrawThemeBackground (hTheme, hDC, partID, stateID, &rect, clipRect); 
    269232    } else { 
    270         drawChevron (hDC, rect); 
     233        drawChevron (hDC, &rect); 
    271234    } 
    272235    if (drawFocus) { 
    273         OS.SetRect (rect, x + 1, y + 1, x + width - 2, y + headerHeight - 2); 
    274         OS.DrawFocusRect (hDC, rect); 
     236        OS.SetRect (&rect, x + 1, y + 1, x + width - 2, y + headerHeight - 2); 
     237        OS.DrawFocusRect (hDC, &rect); 
    275238    } 
    276239    if (expanded) { 
    277240        if (!parent.isAppThemed ()) { 
    278             int pen = OS.CreatePen (OS.PS_SOLID, 1, OS.GetSysColor (OS.COLOR_BTNFACE)); 
    279             int oldPen = OS.SelectObject (hDC, pen); 
    280             int [] points = { 
     241            HPEN pen = OS.CreatePen (OS.PS_SOLID, 1, OS.GetSysColor (OS.COLOR_BTNFACE)); 
     242            HPEN oldPen = OS.SelectObject (hDC, pen); 
     243            int [] points = [ 
    281244                    x, y + headerHeight, 
    282245                    x, y + headerHeight + height, 
    283246                    x + width - 1, y + headerHeight + height, 
    284                     x + width - 1, y + headerHeight - 1}
    285             OS.Polyline (hDC, points, points.length / 2); 
     247                    x + width - 1, y + headerHeight - 1]
     248            OS.Polyline (hDC, cast(POINT*) points.ptr, points.length / 2); 
    286249            OS.SelectObject (hDC, oldPen); 
    287250            OS.DeleteObject (pen); 
     
    377340        width += ExpandItem.TEXT_INSET + imageWidth; 
    378341    } 
    379     if (text.length() > 0) { 
    380         RECT rect = new RECT ()
    381         TCHAR buffer = new TCHAR (parent.getCodePage (), text, false); 
    382         if (hTheme !is 0) { 
    383             OS.GetThemeTextExtent (hTheme, hDC, OS.EBP_NORMALGROUPHEAD, 0, buffer.chars, buffer.length(), OS.DT_SINGLELINE, null, rect); 
     342    if (text.length > 0) { 
     343        RECT rect
     344        TCHAR[] buffer = StrToTCHARs (/+parent.getCodePage (),+/ text); 
     345        if (hTheme !is null) { 
     346            OS.GetThemeTextExtent (hTheme, hDC, OS.EBP_NORMALGROUPHEAD, 0, buffer.ptr, buffer.length, OS.DT_SINGLELINE, null, &rect); 
    384347        } else { 
    385             OS.DrawText (hDC, buffer, buffer.length (), rect, OS.DT_CALCRECT); 
     348            OS.DrawText (hDC, buffer.ptr, buffer.length, &rect, OS.DT_CALCRECT); 
    386349        } 
    387350        width += (rect.right - rect.left); 
     
    396359 
    397360void redraw (bool all) { 
    398     int parentHandle = parent.handle; 
     361    auto parentHandle = parent.handle; 
    399362    int headerHeight = parent.getBandHeight (); 
    400     RECT rect = new RECT ()
     363    RECT rect
    401364    int left = all ? x : x + width - headerHeight; 
    402     OS.SetRect (rect, left, y, x + width, y + headerHeight); 
    403     OS.InvalidateRect (parentHandle, rect, true); 
     365    OS.SetRect (&rect, left, y, x + width, y + headerHeight); 
     366    OS.InvalidateRect (parentHandle, &rect, true); 
    404367    if (imageHeight > headerHeight) { 
    405         OS.SetRect (rect, x + ExpandItem.TEXT_INSET, y + headerHeight - imageHeight, x + ExpandItem.TEXT_INSET + imageWidth, y); 
    406         OS.InvalidateRect (parentHandle, rect, true); 
     368        OS.SetRect (&rect, x + ExpandItem.TEXT_INSET, y + headerHeight - imageHeight, x + ExpandItem.TEXT_INSET + imageWidth, y); 
     369        OS.InvalidateRect (parentHandle, &rect, true); 
    407370    } 
    408371    if (!parent.isAppThemed ()) { 
    409         OS.SetRect (rect, x, y + headerHeight, x + width, y + headerHeight + height + 1); 
    410         OS.InvalidateRect (parentHandle, rect, true); 
     372        OS.SetRect (&rect, x, y + headerHeight, x + width, y + headerHeight + height + 1); 
     373        OS.InvalidateRect (parentHandle, &rect, true); 
    411374    } 
    412375} 
     
    535498} 
    536499 
    537 public void setText (String string) { 
     500public void setText (char[] string) { 
    538501    super.setText (string); 
    539502    redraw (true); 
    540503} 
    541504} 
    542 ++/ 
     505