Changeset 43:9c2b9c930ceb

Show
Ignore:
Timestamp:
02/01/08 16:31:06 (1 year ago)
Author:
Frank Benoit <benoit@tionex.de>
branch:
default
Message:

ColorDialog?

Files:

Legend:

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

    r31 r43  
    1313module dwt.widgets.ColorDialog; 
    1414 
    15 import dwt.widgets.Dialog; 
    16 import dwt.widgets.Shell; 
    17  
    18 class ColorDialog : Dialog { 
    19     public this (Shell parent, int style) { 
    20         super (parent, style); 
    21     } 
    22 
    23  
    24 /++ 
     15 
     16 
    2517import dwt.DWT; 
    2618import dwt.DWTException; 
    2719import dwt.graphics.PaletteData; 
    2820import dwt.graphics.RGB; 
    29 import dwt.internal.Callback; 
    30 import dwt.internal.win32.CHOOSECOLOR; 
    3121import dwt.internal.win32.OS; 
    32 import dwt.internal.win32.RECT; 
    33 import dwt.internal.win32.TCHAR; 
     22 
     23 
     24import dwt.widgets.Dialog; 
     25import dwt.widgets.Shell; 
     26import dwt.widgets.Display; 
     27 
    3428 
    3529/** 
     
    4842 */ 
    4943 
    50 public class ColorDialog extends Dialog { 
     44public class ColorDialog : Dialog { 
    5145    Display display; 
    5246    int width, height; 
     
    7064 * @see Widget#getStyle 
    7165 */ 
    72 public ColorDialog (Shell parent) { 
     66public this (Shell parent) { 
    7367    this (parent, DWT.PRIMARY_MODAL); 
    7468} 
     
    10296 * @see Widget#getStyle 
    10397 */ 
    104 public ColorDialog (Shell parent, int style) { 
     98public this (Shell parent, int style) { 
    10599    super (parent, style); 
    106100    checkSubclass (); 
    107101} 
    108102 
    109 int CCHookProc (int hdlg, int uiMsg, int lParam, int lpData) { 
     103private static extern(Windows) int CCHookFunc (HWND hdlg, int uiMsg, int lParam, int lpData) { 
     104    ColorDialog dlg = cast(ColorDialog)cast(void*)lpData; 
     105    return dlg.CCHookProc( hdlg, uiMsg, lParam ); 
     106
     107 
     108int CCHookProc (HWND hdlg, int uiMsg, int lParam ) { 
    110109    switch (uiMsg) { 
    111110        case OS.WM_INITDIALOG: { 
    112             RECT rect = new RECT ()
    113             OS.GetWindowRect (hdlg, rect); 
     111            RECT rect
     112            OS.GetWindowRect (hdlg, &rect); 
    114113            width = rect.right - rect.left; 
    115114            height = rect.bottom - rect.top; 
    116             if (title !is null && title.length () !is 0) { 
     115            if (title !is null && title.length !is 0) { 
    117116                /* Use the character encoding for the default locale */ 
    118                 TCHAR buffer = new TCHAR (0, title, true); 
    119                 OS.SetWindowText (hdlg, buffer); 
     117                OS.SetWindowText (hdlg, StrToTCHARz(title)); 
    120118            } 
    121119            break; 
    122120        } 
    123121        case OS.WM_DESTROY: { 
    124             RECT rect = new RECT ()
    125             OS.GetWindowRect (hdlg, rect); 
     122            RECT rect
     123            OS.GetWindowRect (hdlg, &rect); 
    126124            int newWidth = rect.right - rect.left; 
    127125            int newHeight = rect.bottom - rect.top; 
     
    166164 
    167165    /* Get the owner HWND for the dialog */ 
    168     int hwndOwner = parent.handle; 
     166    auto hwndOwner = parent.handle; 
    169167 
    170168    /* Create the CCHookProc */ 
    171     Callback callback = new Callback (this, "CCHookProc", 4); //$NON-NLS-1$ 
    172     int lpfnHook = callback.getAddress (); 
    173     if (lpfnHook is 0) DWT.error(DWT.ERROR_NO_MORE_CALLBACKS); 
     169    //Callback callback = new Callback (this, "CCHookProc", 4); //$NON-NLS-1$ 
     170    //int lpfnHook = callback.getAddress (); 
     171    //if (lpfnHook is 0) DWT.error(DWT.ERROR_NO_MORE_CALLBACKS); 
    174172 
    175173    /* Allocate the Custom Colors */ 
    176174    display = parent.display; 
    177     if (display.lpCustColors is 0) { 
    178         int hHeap = OS.GetProcessHeap (); 
    179         display.lpCustColors = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, 16 * 4); 
     175    if (display.lpCustColors is null) { 
     176        auto hHeap = OS.GetProcessHeap (); 
     177        display.lpCustColors = cast(uint*)OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, 16 * 4); 
    180178    } 
    181179 
    182180    /* Open the dialog */ 
    183     CHOOSECOLOR lpcc = new CHOOSECOLOR (); 
     181    CHOOSECOLOR lpcc; 
     182    lpcc.lCustData = cast(int)cast(void*)this; 
    184183    lpcc.lStructSize = CHOOSECOLOR.sizeof; 
    185184    lpcc.Flags = OS.CC_ANYCOLOR | OS.CC_ENABLEHOOK; 
    186185    //if (display.fullOpen) lpcc.Flags |= OS.CC_FULLOPEN; 
    187     lpcc.lpfnHook = lpfnHook
     186    lpcc.lpfnHook = &CCHookFunc
    188187    lpcc.hwndOwner = hwndOwner; 
    189188    lpcc.lpCustColors = display.lpCustColors; 
     
    204203 
    205204    /* Open the dialog */ 
    206     bool success = OS.ChooseColor (lpcc); 
     205    bool success = cast(bool) OS.ChooseColor (&lpcc); 
    207206 
    208207    /* Clear the temporary dialog modal parent */ 
     
    219218 
    220219    /* Free the CCHookProc */ 
    221     callback.dispose (); 
     220    //callback.dispose (); 
    222221 
    223222    /* Free the Custom Colors */ 
     
    255254 
    256255} 
    257 ++/