Changeset 50:2146ed8ff33c

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

Group

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dwt/widgets/Group.d

    r31 r50  
    1313module dwt.widgets.Group; 
    1414 
    15 import dwt.widgets.Composite; 
    16 class Group : Composite { 
    17 
    18 /++ 
     15 
    1916import dwt.DWT; 
    2017import dwt.DWTException; 
     
    2219import dwt.graphics.Point; 
    2320import dwt.graphics.Rectangle; 
    24 import dwt.internal.win32.LRESULT; 
    2521import dwt.internal.win32.OS; 
    26 import dwt.internal.win32.RECT; 
    27 import dwt.internal.win32.TCHAR; 
    28 import dwt.internal.win32.TEXTMETRIC; 
    29 import dwt.internal.win32.TEXTMETRICA; 
    30 import dwt.internal.win32.TEXTMETRICW; 
    31 import dwt.internal.win32.WINDOWPOS; 
    32 import dwt.internal.win32.WNDCLASS; 
     22import dwt.widgets.Composite; 
     23 
     24import dwt.dwthelper.utils; 
    3325 
    3426/** 
     
    5345 */ 
    5446 
    55 public class Group extends Composite { 
    56     String text = ""; 
    57     static final int CLIENT_INSET = 3; 
    58     static final int GroupProc; 
    59     static final TCHAR GroupClass = new TCHAR (0, OS.IsWinCE ? "BUTTON" : "SWT_GROUP", true); 
    60     static { 
     47public class Group : Composite { 
     48    char[] text = ""; 
     49    static const int CLIENT_INSET = 3; 
     50    static const WNDPROC GroupProc; 
     51    static if( OS.IsWinCE ){ 
     52        static const TCHAR[] GroupClass = "BUTTON\0"; 
     53    } 
     54    else{ 
     55        static const TCHAR[] GroupClass = "SWT_GROUP\0"; 
     56    } 
     57    static this() { 
    6158        /* 
    6259        * Feature in Windows.  The group box window class 
     
    7269        * the class Button directly. 
    7370        */ 
    74         WNDCLASS lpWndClass = new WNDCLASS ()
     71        WNDCLASS lpWndClass
    7572        if (OS.IsWinCE) { 
    76             OS.GetClassInfo (0, GroupClass, lpWndClass); 
     73            OS.GetClassInfo (null, GroupClass.ptr, &lpWndClass); 
    7774            GroupProc = lpWndClass.lpfnWndProc; 
    7875        } else { 
    79             TCHAR WC_BUTTON = new TCHAR (0, "BUTTON", true)
    80             OS.GetClassInfo (0, WC_BUTTON, lpWndClass); 
     76            TCHAR[] WC_BUTTON = "BUTTON\0"
     77            OS.GetClassInfo (null, WC_BUTTON.ptr, &lpWndClass); 
    8178            GroupProc = lpWndClass.lpfnWndProc; 
    82             int hInstance = OS.GetModuleHandle (null); 
    83             if (!OS.GetClassInfo (hInstance, GroupClass, lpWndClass)) { 
    84                 int hHeap = OS.GetProcessHeap (); 
     79            auto hInstance = OS.GetModuleHandle (null); 
     80            if (!OS.GetClassInfo (hInstance, GroupClass.ptr, &lpWndClass)) { 
     81                auto hHeap = OS.GetProcessHeap (); 
    8582                lpWndClass.hInstance = hInstance; 
    8683                lpWndClass.style &= ~(OS.CS_HREDRAW | OS.CS_VREDRAW); 
    87                 int byteCount = GroupClass.length () * TCHAR.sizeof; 
    88                 int lpszClassName = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); 
    89                 OS.MoveMemory (lpszClassName, GroupClass, byteCount); 
     84                int byteCount = GroupClass.length * TCHAR.sizeof; 
     85                auto lpszClassName = cast(TCHAR*)OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); 
     86                OS.MoveMemory (lpszClassName, GroupClass.ptr, byteCount); 
    9087                lpWndClass.lpszClassName = lpszClassName; 
    91                 OS.RegisterClass (lpWndClass); 
     88                OS.RegisterClass (&lpWndClass); 
    9289                OS.HeapFree (hHeap, 0, lpszClassName); 
    9390            } 
     
    127124 * @see Widget#getStyle 
    128125 */ 
    129 public Group (Composite parent, int style) { 
     126public this (Composite parent, int style) { 
    130127    super (parent, checkStyle (style)); 
    131128} 
    132129 
    133 int callWindowProc (int hwnd, int msg, int wParam, int lParam) { 
    134     if (handle is 0) return 0
     130LRESULT callWindowProc (HWND hwnd, int msg, int wParam, int lParam) { 
     131    if (handle is null) return LRESULT.NULL
    135132    /* 
    136133    * Feature in Windows.  When the user clicks on the group 
     
    141138        case OS.WM_LBUTTONDOWN: 
    142139        case OS.WM_LBUTTONDBLCLK: 
    143             return OS.DefWindowProc (hwnd, msg, wParam, lParam); 
    144     } 
    145     return OS.CallWindowProc (GroupProc, hwnd, msg, wParam, lParam); 
     140            return cast(LRESULT) OS.DefWindowProc (hwnd, msg, wParam, lParam); 
     141    } 
     142    return cast(LRESULT) OS.CallWindowProc (GroupProc, hwnd, msg, wParam, lParam); 
    146143} 
    147144 
     
    165162    checkWidget (); 
    166163    Point size = super.computeSize (wHint, hHint, changed); 
    167     int length = text.length ()
     164    int length = text.length
    168165    if (length !is 0) { 
    169166        /* 
     
    174171        * size from changing when a group is enabled and disabled. 
    175172        */ 
    176         String string = text; 
     173        char[] string = text; 
    177174        if ((style & DWT.RIGHT_TO_LEFT) !is 0) { 
    178175            if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) { 
    179                 string = " " + string + " "; 
     176                string = " " ~ string ~ " "; 
    180177            } 
    181178        } 
     
    184181        * client area, pad the width so the text is not clipped. 
    185182        */ 
    186         TCHAR buffer = new TCHAR (getCodePage (), string, true); 
    187         int newFont, oldFont = 0
    188         int hDC = OS.GetDC (handle); 
    189         newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); 
    190         if (newFont !is 0) oldFont = OS.SelectObject (hDC, newFont); 
    191         RECT rect = new RECT ()
     183        TCHAR* buffer = StrToTCHARz (/+getCodePage (),+/ string); 
     184        HFONT newFont, oldFont
     185        auto hDC = OS.GetDC (handle); 
     186        newFont = cast(HFONT) OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); 
     187        if (newFont !is null) oldFont = OS.SelectObject (hDC, newFont); 
     188        RECT rect
    192189        int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE; 
    193         OS.DrawText (hDC, buffer, -1, rect, flags); 
    194         if (newFont !is 0) OS.SelectObject (hDC, oldFont); 
     190        OS.DrawText (hDC, buffer, -1, &rect, flags); 
     191        if (newFont !is null) OS.SelectObject (hDC, oldFont); 
    195192        OS.ReleaseDC (handle, hDC); 
    196193        size.x = Math.max (size.x, rect.right - rect.left + CLIENT_INSET * 6); 
     
    202199    checkWidget (); 
    203200    Rectangle trim = super.computeTrim (x, y, width, height); 
    204     int newFont, oldFont = 0
    205     int hDC = OS.GetDC (handle); 
    206     newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); 
    207     if (newFont !is 0) oldFont = OS.SelectObject (hDC, newFont); 
    208     TEXTMETRIC tm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW () : new TEXTMETRICA ()
    209     OS.GetTextMetrics (hDC, tm); 
    210     if (newFont !is 0) OS.SelectObject (hDC, oldFont); 
     201    HFONT newFont, oldFont
     202    auto hDC = OS.GetDC (handle); 
     203    newFont = cast(HFONT) OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); 
     204    if (newFont !is null) oldFont = OS.SelectObject (hDC, newFont); 
     205    TEXTMETRIC tm
     206    OS.GetTextMetrics (hDC, &tm); 
     207    if (newFont !is null) OS.SelectObject (hDC, oldFont); 
    211208    OS.ReleaseDC (handle, hDC); 
    212209    trim.x -= CLIENT_INSET; 
     
    232229    if ((style & DWT.RIGHT_TO_LEFT) !is 0) { 
    233230        if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) { 
    234             String string = enabled || text.length() is 0 ? text : " " + text + " "; 
    235             TCHAR buffer = new TCHAR (getCodePage (), string, true); 
     231            char[] string = enabled || text.length is 0 ? text : " " ~ text ~ " "; 
     232            TCHAR* buffer = StrToTCHARz (/+getCodePage (),+/ string); 
    236233            OS.SetWindowText (handle, buffer); 
    237234        } 
     
    242239    checkWidget (); 
    243240    forceResize (); 
    244     RECT rect = new RECT ()
    245     OS.GetClientRect (handle, rect); 
    246     int newFont, oldFont = 0
    247     int hDC = OS.GetDC (handle); 
    248     newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); 
    249     if (newFont !is 0) oldFont = OS.SelectObject (hDC, newFont); 
    250     TEXTMETRIC tm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW () : new TEXTMETRICA ()
    251     OS.GetTextMetrics (hDC, tm); 
    252     if (newFont !is 0) OS.SelectObject (hDC, oldFont); 
     241    RECT rect
     242    OS.GetClientRect (handle, &rect); 
     243    HFONT newFont, oldFont
     244    auto hDC = OS.GetDC (handle); 
     245    newFont = cast(HFONT) OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); 
     246    if (newFont !is null) oldFont = OS.SelectObject (hDC, newFont); 
     247    TEXTMETRIC tm
     248    OS.GetTextMetrics (hDC, &tm); 
     249    if (newFont !is null) OS.SelectObject (hDC, oldFont); 
    253250    OS.ReleaseDC (handle, hDC); 
    254251    int x = CLIENT_INSET, y = tm.tmHeight; 
     
    258255} 
    259256 
    260 String getNameText () { 
     257char[] getNameText () { 
    261258    return getText (); 
    262259} 
     
    274271 * </ul> 
    275272 */ 
    276 public String getText () { 
     273public char[] getText () { 
    277274    checkWidget (); 
    278275    return text; 
    279276} 
    280277 
    281 bool mnemonicHit (char key) { 
     278bool mnemonicHit (wchar key) { 
    282279    return setFocus (); 
    283280} 
    284281 
    285 bool mnemonicMatch (char key) { 
    286     char mnemonic = findMnemonic (getText ()); 
     282bool mnemonicMatch (wchar key) { 
     283    wchar mnemonic = findMnemonic (getText ()); 
    287284    if (mnemonic is '\0') return false; 
    288     return Character.toUpperCase (key) is Character.toUpperCase (mnemonic); 
     285    return CharacterToUpper (key) is CharacterToUpper (mnemonic); 
    289286} 
    290287 
     
    299296    super.setFont (font); 
    300297    Rectangle newRect = getClientArea (); 
    301     if (!oldRect.equals (newRect)) sendResize (); 
     298    if (oldRect!=newRect) sendResize (); 
    302299} 
    303300 
     
    326323 * </ul> 
    327324 */ 
    328 public void setText (String string) { 
     325public void setText (char[] string) { 
    329326    checkWidget (); 
    330327    if (string is null) error (DWT.ERROR_NULL_ARGUMENT); 
     
    338335        if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) { 
    339336            if (!OS.IsWindowEnabled (handle)) { 
    340                 if (string.length() !is 0) string = " " + string + " "; 
     337                if (string.length !is 0) string = " " ~ string ~ " "; 
    341338            } 
    342339        } 
    343340    } 
    344     TCHAR buffer = new TCHAR (getCodePage (), string, true); 
     341    TCHAR* buffer = StrToTCHARz(/+getCodePage (),+/ string); 
    345342    OS.SetWindowText (handle, buffer); 
    346343} 
     
    361358} 
    362359 
    363 TCHAR windowClass () { 
    364     return GroupClass
     360char[] windowClass () { 
     361    return TCHARsToStr( GroupClass )
    365362} 
    366363 
    367364int windowProc () { 
    368     return GroupProc; 
     365    return cast(int) GroupProc; 
    369366} 
    370367 
    371368LRESULT WM_ERASEBKGND (int wParam, int lParam) { 
    372369    LRESULT result = super.WM_ERASEBKGND (wParam, lParam); 
    373     if (result !is null) return result; 
     370    if (result !is LRESULT.NULL) return result; 
    374371    /* 
    375372    * Feature in Windows.  Group boxes do not erase 
     
    377374    * fill the background. 
    378375    */ 
    379     drawBackground (wParam); 
     376    drawBackground (cast(HANDLE) wParam); 
    380377    return LRESULT.ONE; 
    381378} 
     
    383380LRESULT WM_NCHITTEST (int wParam, int lParam) { 
    384381    LRESULT result = super.WM_NCHITTEST (wParam, lParam); 
    385     if (result !is null) return result; 
     382    if (result !is LRESULT.NULL) return result; 
    386383    /* 
    387384    * Feature in Windows.  The window proc for the group box 
     
    395392    int code = callWindowProc (handle, OS.WM_NCHITTEST, wParam, lParam); 
    396393    if (code is OS.HTTRANSPARENT) code = OS.HTCLIENT; 
    397     return new LRESULT (code); 
     394    return cast(LRESULT) (code); 
    398395} 
    399396 
    400397LRESULT WM_MOUSEMOVE (int wParam, int lParam) { 
    401398    LRESULT result = super.WM_MOUSEMOVE (wParam, lParam); 
    402     if (result !is null) return result; 
     399    if (result !is LRESULT.NULL) return result; 
    403400    /* 
    404401    * Feature in Windows.  In version 6.00 of COMCTL32.DLL, 
     
    412409LRESULT WM_PRINTCLIENT (int wParam, int lParam) { 
    413410    LRESULT result = super.WM_PRINTCLIENT (wParam, lParam); 
    414     if (result !is null) return result; 
     411    if (result !is LRESULT.NULL) return result; 
    415412    /* 
    416413    * Feature in Windows.  In version 6.00 of COMCTL32.DLL, 
     
    424421    */ 
    425422    if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) { 
    426         int nSavedDC = OS.SaveDC (wParam); 
     423        auto nSavedDC = OS.SaveDC (cast(HDC)wParam); 
    427424        int code = callWindowProc (handle, OS.WM_PRINTCLIENT, wParam, lParam); 
    428         OS.RestoreDC (wParam, nSavedDC); 
    429         return new LRESULT (code); 
     425        OS.RestoreDC (cast(HDC)wParam, nSavedDC); 
     426        return cast(LRESULT) (code); 
    430427    } 
    431428    return result; 
     
    434431LRESULT WM_UPDATEUISTATE (int wParam, int lParam) { 
    435432    LRESULT result = super.WM_UPDATEUISTATE (wParam, lParam); 
    436     if (result !is null) return result; 
     433    if (result !is LRESULT.NULL) return result; 
    437434    /* 
    438435    * Feature in Windows.  When WM_UPDATEUISTATE is sent to 
     
    455452        OS.InvalidateRect (handle, null, false); 
    456453        int code = OS.DefWindowProc (handle, OS.WM_UPDATEUISTATE, wParam, lParam); 
    457         return new LRESULT (code); 
     454        return cast(LRESULT) (code); 
    458455    } 
    459456    return result; 
     
    462459LRESULT WM_WINDOWPOSCHANGING (int wParam, int lParam) { 
    463460    LRESULT result = super.WM_WINDOWPOSCHANGING (wParam, lParam); 
    464     if (result !is null) return result; 
     461    if (result !is LRESULT.NULL) return result; 
    465462    /* 
    466463    * Invalidate the portion of the group widget that needs to 
     
    471468    if (OS.IsWinCE) return result; 
    472469    if (!OS.IsWindowVisible (handle)) return result; 
    473     WINDOWPOS lpwp = new WINDOWPOS ()
    474     OS.MoveMemory (lpwp, lParam, WINDOWPOS.sizeof); 
     470    WINDOWPOS* lpwp = cast(WINDOWPOS*)lParam
     471    //OS.MoveMemory (lpwp, lParam, WINDOWPOS.sizeof); 
    475472    if ((lpwp.flags & (OS.SWP_NOSIZE | OS.SWP_NOREDRAW)) !is 0) { 
    476473        return result; 
    477474    } 
    478     RECT rect = new RECT ()
    479     OS.SetRect (rect, 0, 0, lpwp.cx, lpwp.cy); 
    480     OS.SendMessage (handle, OS.WM_NCCALCSIZE, 0, rect); 
     475    RECT rect
     476    OS.SetRect (&rect, 0, 0, lpwp.cx, lpwp.cy); 
     477    OS.SendMessage (handle, OS.WM_NCCALCSIZE, 0, &rect); 
    481478    int newWidth = rect.right - rect.left; 
    482479    int newHeight = rect.bottom - rect.top; 
    483     OS.GetClientRect (handle, rect); 
     480    OS.GetClientRect (handle, &rect); 
    484481    int oldWidth = rect.right - rect.left; 
    485482    int oldHeight = rect.bottom - rect.top; 
     
    490487        int left = oldWidth; 
    491488        if (newWidth < oldWidth) left = newWidth; 
    492         OS.SetRect (rect, left - CLIENT_INSET, 0, newWidth, newHeight); 
    493         OS.InvalidateRect (handle, rect, true); 
     489        OS.SetRect (&rect, left - CLIENT_INSET, 0, newWidth, newHeight); 
     490        OS.InvalidateRect (handle, &rect, true); 
    494491    } 
    495492    if (newHeight !is oldHeight) { 
     
    497494        if (newHeight < oldHeight) bottom = newHeight; 
    498495        if (newWidth < oldWidth) oldWidth -= CLIENT_INSET; 
    499         OS.SetRect (rect, 0, bottom - CLIENT_INSET, oldWidth, newHeight); 
    500         OS.InvalidateRect (handle, rect, true); 
     496        OS.SetRect (&rect, 0, bottom - CLIENT_INSET, oldWidth, newHeight); 
     497        OS.InvalidateRect (handle, &rect, true); 
    501498    } 
    502499    return result; 
    503500} 
    504501} 
    505 ++/