Changeset 43:9c2b9c930ceb
- 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
| r31 |
r43 |
|
| 13 | 13 | module dwt.widgets.ColorDialog; |
|---|
| 14 | 14 | |
|---|
| 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 | |
|---|
| 25 | 17 | import dwt.DWT; |
|---|
| 26 | 18 | import dwt.DWTException; |
|---|
| 27 | 19 | import dwt.graphics.PaletteData; |
|---|
| 28 | 20 | import dwt.graphics.RGB; |
|---|
| 29 | | import dwt.internal.Callback; |
|---|
| 30 | | import dwt.internal.win32.CHOOSECOLOR; |
|---|
| 31 | 21 | import dwt.internal.win32.OS; |
|---|
| 32 | | import dwt.internal.win32.RECT; |
|---|
| 33 | | import dwt.internal.win32.TCHAR; |
|---|
| | 22 | |
|---|
| | 23 | |
|---|
| | 24 | import dwt.widgets.Dialog; |
|---|
| | 25 | import dwt.widgets.Shell; |
|---|
| | 26 | import dwt.widgets.Display; |
|---|
| | 27 | |
|---|
| 34 | 28 | |
|---|
| 35 | 29 | /** |
|---|
| … | … | |
| 48 | 42 | */ |
|---|
| 49 | 43 | |
|---|
| 50 | | public class ColorDialog extends Dialog { |
|---|
| | 44 | public class ColorDialog : Dialog { |
|---|
| 51 | 45 | Display display; |
|---|
| 52 | 46 | int width, height; |
|---|
| … | … | |
| 70 | 64 | * @see Widget#getStyle |
|---|
| 71 | 65 | */ |
|---|
| 72 | | public ColorDialog (Shell parent) { |
|---|
| | 66 | public this (Shell parent) { |
|---|
| 73 | 67 | this (parent, DWT.PRIMARY_MODAL); |
|---|
| 74 | 68 | } |
|---|
| … | … | |
| 102 | 96 | * @see Widget#getStyle |
|---|
| 103 | 97 | */ |
|---|
| 104 | | public ColorDialog (Shell parent, int style) { |
|---|
| | 98 | public this (Shell parent, int style) { |
|---|
| 105 | 99 | super (parent, style); |
|---|
| 106 | 100 | checkSubclass (); |
|---|
| 107 | 101 | } |
|---|
| 108 | 102 | |
|---|
| 109 | | int CCHookProc (int hdlg, int uiMsg, int lParam, int lpData) { |
|---|
| | 103 | private 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 | |
|---|
| | 108 | int CCHookProc (HWND hdlg, int uiMsg, int lParam ) { |
|---|
| 110 | 109 | switch (uiMsg) { |
|---|
| 111 | 110 | case OS.WM_INITDIALOG: { |
|---|
| 112 | | RECT rect = new RECT (); |
|---|
| 113 | | OS.GetWindowRect (hdlg, rect); |
|---|
| | 111 | RECT rect; |
|---|
| | 112 | OS.GetWindowRect (hdlg, &rect); |
|---|
| 114 | 113 | width = rect.right - rect.left; |
|---|
| 115 | 114 | height = rect.bottom - rect.top; |
|---|
| 116 | | if (title !is null && title.length () !is 0) { |
|---|
| | 115 | if (title !is null && title.length !is 0) { |
|---|
| 117 | 116 | /* 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)); |
|---|
| 120 | 118 | } |
|---|
| 121 | 119 | break; |
|---|
| 122 | 120 | } |
|---|
| 123 | 121 | case OS.WM_DESTROY: { |
|---|
| 124 | | RECT rect = new RECT (); |
|---|
| 125 | | OS.GetWindowRect (hdlg, rect); |
|---|
| | 122 | RECT rect; |
|---|
| | 123 | OS.GetWindowRect (hdlg, &rect); |
|---|
| 126 | 124 | int newWidth = rect.right - rect.left; |
|---|
| 127 | 125 | int newHeight = rect.bottom - rect.top; |
|---|
| … | … | |
| 166 | 164 | |
|---|
| 167 | 165 | /* Get the owner HWND for the dialog */ |
|---|
| 168 | | int hwndOwner = parent.handle; |
|---|
| | 166 | auto hwndOwner = parent.handle; |
|---|
| 169 | 167 | |
|---|
| 170 | 168 | /* 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); |
|---|
| 174 | 172 | |
|---|
| 175 | 173 | /* Allocate the Custom Colors */ |
|---|
| 176 | 174 | 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); |
|---|
| 180 | 178 | } |
|---|
| 181 | 179 | |
|---|
| 182 | 180 | /* Open the dialog */ |
|---|
| 183 | | CHOOSECOLOR lpcc = new CHOOSECOLOR (); |
|---|
| | 181 | CHOOSECOLOR lpcc; |
|---|
| | 182 | lpcc.lCustData = cast(int)cast(void*)this; |
|---|
| 184 | 183 | lpcc.lStructSize = CHOOSECOLOR.sizeof; |
|---|
| 185 | 184 | lpcc.Flags = OS.CC_ANYCOLOR | OS.CC_ENABLEHOOK; |
|---|
| 186 | 185 | //if (display.fullOpen) lpcc.Flags |= OS.CC_FULLOPEN; |
|---|
| 187 | | lpcc.lpfnHook = lpfnHook; |
|---|
| | 186 | lpcc.lpfnHook = &CCHookFunc; |
|---|
| 188 | 187 | lpcc.hwndOwner = hwndOwner; |
|---|
| 189 | 188 | lpcc.lpCustColors = display.lpCustColors; |
|---|
| … | … | |
| 204 | 203 | |
|---|
| 205 | 204 | /* Open the dialog */ |
|---|
| 206 | | bool success = OS.ChooseColor (lpcc); |
|---|
| | 205 | bool success = cast(bool) OS.ChooseColor (&lpcc); |
|---|
| 207 | 206 | |
|---|
| 208 | 207 | /* Clear the temporary dialog modal parent */ |
|---|
| … | … | |
| 219 | 218 | |
|---|
| 220 | 219 | /* Free the CCHookProc */ |
|---|
| 221 | | callback.dispose (); |
|---|
| | 220 | //callback.dispose (); |
|---|
| 222 | 221 | |
|---|
| 223 | 222 | /* Free the Custom Colors */ |
|---|
| … | … | |
| 255 | 254 | |
|---|
| 256 | 255 | } |
|---|
| 257 | | ++/ |
|---|