# HG changeset patch # User Frank Benoit # Date 1201901466 -3600 # Node ID 9c2b9c930ceb698dc8240ffcf1bcf5eb6e21dc03 # Parent 6a40adae94d5a2ddd5422d2fc76d2d04feb0e782 ColorDialog diff -r 6a40adae94d5 -r 9c2b9c930ceb dwt/widgets/ColorDialog.d --- a/dwt/widgets/ColorDialog.d Fri Feb 01 22:20:30 2008 +0100 +++ b/dwt/widgets/ColorDialog.d Fri Feb 01 22:31:06 2008 +0100 @@ -12,25 +12,19 @@ *******************************************************************************/ module dwt.widgets.ColorDialog; -import dwt.widgets.Dialog; -import dwt.widgets.Shell; -class ColorDialog : Dialog { - public this (Shell parent, int style) { - super (parent, style); - } -} -/++ import dwt.DWT; import dwt.DWTException; import dwt.graphics.PaletteData; import dwt.graphics.RGB; -import dwt.internal.Callback; -import dwt.internal.win32.CHOOSECOLOR; import dwt.internal.win32.OS; -import dwt.internal.win32.RECT; -import dwt.internal.win32.TCHAR; + + +import dwt.widgets.Dialog; +import dwt.widgets.Shell; +import dwt.widgets.Display; + /** * Instances of this class allow the user to select a color @@ -47,7 +41,7 @@ *

*/ -public class ColorDialog extends Dialog { +public class ColorDialog : Dialog { Display display; int width, height; RGB rgb; @@ -69,7 +63,7 @@ * @see Widget#checkSubclass * @see Widget#getStyle */ -public ColorDialog (Shell parent) { +public this (Shell parent) { this (parent, DWT.PRIMARY_MODAL); } @@ -101,28 +95,32 @@ * @see Widget#checkSubclass * @see Widget#getStyle */ -public ColorDialog (Shell parent, int style) { +public this (Shell parent, int style) { super (parent, style); checkSubclass (); } -int CCHookProc (int hdlg, int uiMsg, int lParam, int lpData) { +private static extern(Windows) int CCHookFunc (HWND hdlg, int uiMsg, int lParam, int lpData) { + ColorDialog dlg = cast(ColorDialog)cast(void*)lpData; + return dlg.CCHookProc( hdlg, uiMsg, lParam ); +} + +int CCHookProc (HWND hdlg, int uiMsg, int lParam ) { switch (uiMsg) { case OS.WM_INITDIALOG: { - RECT rect = new RECT (); - OS.GetWindowRect (hdlg, rect); + RECT rect; + OS.GetWindowRect (hdlg, &rect); width = rect.right - rect.left; height = rect.bottom - rect.top; - if (title !is null && title.length () !is 0) { + if (title !is null && title.length !is 0) { /* Use the character encoding for the default locale */ - TCHAR buffer = new TCHAR (0, title, true); - OS.SetWindowText (hdlg, buffer); + OS.SetWindowText (hdlg, StrToTCHARz(title)); } break; } case OS.WM_DESTROY: { - RECT rect = new RECT (); - OS.GetWindowRect (hdlg, rect); + RECT rect; + OS.GetWindowRect (hdlg, &rect); int newWidth = rect.right - rect.left; int newHeight = rect.bottom - rect.top; if (newWidth < width || newHeight < height) { @@ -165,26 +163,27 @@ public RGB open () { /* Get the owner HWND for the dialog */ - int hwndOwner = parent.handle; + auto hwndOwner = parent.handle; /* Create the CCHookProc */ - Callback callback = new Callback (this, "CCHookProc", 4); //$NON-NLS-1$ - int lpfnHook = callback.getAddress (); - if (lpfnHook is 0) DWT.error(DWT.ERROR_NO_MORE_CALLBACKS); + //Callback callback = new Callback (this, "CCHookProc", 4); //$NON-NLS-1$ + //int lpfnHook = callback.getAddress (); + //if (lpfnHook is 0) DWT.error(DWT.ERROR_NO_MORE_CALLBACKS); /* Allocate the Custom Colors */ display = parent.display; - if (display.lpCustColors is 0) { - int hHeap = OS.GetProcessHeap (); - display.lpCustColors = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, 16 * 4); + if (display.lpCustColors is null) { + auto hHeap = OS.GetProcessHeap (); + display.lpCustColors = cast(uint*)OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, 16 * 4); } /* Open the dialog */ - CHOOSECOLOR lpcc = new CHOOSECOLOR (); + CHOOSECOLOR lpcc; + lpcc.lCustData = cast(int)cast(void*)this; lpcc.lStructSize = CHOOSECOLOR.sizeof; lpcc.Flags = OS.CC_ANYCOLOR | OS.CC_ENABLEHOOK; //if (display.fullOpen) lpcc.Flags |= OS.CC_FULLOPEN; - lpcc.lpfnHook = lpfnHook; + lpcc.lpfnHook = &CCHookFunc; lpcc.hwndOwner = hwndOwner; lpcc.lpCustColors = display.lpCustColors; if (rgb !is null) { @@ -203,7 +202,7 @@ } /* Open the dialog */ - bool success = OS.ChooseColor (lpcc); + bool success = cast(bool) OS.ChooseColor (&lpcc); /* Clear the temporary dialog modal parent */ if ((style & (DWT.APPLICATION_MODAL | DWT.SYSTEM_MODAL)) !is 0) { @@ -218,7 +217,7 @@ } /* Free the CCHookProc */ - callback.dispose (); + //callback.dispose (); /* Free the Custom Colors */ /* @@ -254,4 +253,3 @@ } } -++/ \ No newline at end of file