Mercurial > projects > dwt-win
changeset 69:3b93cc2ffe96
ToolBar, ToolItem
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 04 Feb 2008 21:28:40 +0100 |
parents | 5c549a70cf43 |
children | eabb41384d60 |
files | dwt/internal/win32/WINTYPES.d dwt/widgets/ToolBar.d dwt/widgets/ToolItem.d |
diffstat | 3 files changed, 202 insertions(+), 209 deletions(-) [+] |
line wrap: on
line diff
--- a/dwt/internal/win32/WINTYPES.d Mon Feb 04 20:53:04 2008 +0100 +++ b/dwt/internal/win32/WINTYPES.d Mon Feb 04 21:28:40 2008 +0100 @@ -64,7 +64,12 @@ UINT uNewState; UINT uOldState; } - +struct NMTBHOTITEM { + NMHDR hdr; + int idOld; + int idNew; + DWORD dwFlags; +} // .... //--------------------------------------------------------------------------------
--- a/dwt/widgets/ToolBar.d Mon Feb 04 20:53:04 2008 +0100 +++ b/dwt/widgets/ToolBar.d Mon Feb 04 21:28:40 2008 +0100 @@ -10,31 +10,22 @@ *******************************************************************************/ module dwt.widgets.ToolBar; -import dwt.widgets.Composite; -class ToolBar : Composite { -} -/++ - import dwt.DWT; import dwt.DWTException; import dwt.graphics.Font; import dwt.graphics.Point; import dwt.graphics.Rectangle; import dwt.internal.ImageList; -import dwt.internal.win32.LRESULT; -import dwt.internal.win32.NMCUSTOMDRAW; -import dwt.internal.win32.NMHDR; -import dwt.internal.win32.NMTBHOTITEM; -import dwt.internal.win32.NMTOOLBAR; -import dwt.internal.win32.NMTTDISPINFO; import dwt.internal.win32.OS; -import dwt.internal.win32.RECT; -import dwt.internal.win32.TBBUTTON; -import dwt.internal.win32.TBBUTTONINFO; -import dwt.internal.win32.TCHAR; -import dwt.internal.win32.TOOLINFO; -import dwt.internal.win32.WINDOWPOS; -import dwt.internal.win32.WNDCLASS; + +import dwt.widgets.Composite; +import dwt.widgets.ToolItem; +import dwt.widgets.Control; +import dwt.widgets.Display; +import dwt.widgets.Event; + +import dwt.dwthelper.utils; + /** * Instances of this class support the layout of selectable @@ -59,7 +50,7 @@ * IMPORTANT: This class is <em>not</em> intended to be subclassed. * </p> */ -public class ToolBar extends Composite { +public class ToolBar : Composite { alias Composite.computeSize computeSize; alias Composite.setBackgroundImage setBackgroundImage; @@ -70,11 +61,11 @@ ToolItem [] items; bool ignoreResize, ignoreMouse; ImageList imageList, disabledImageList, hotImageList; - static final int ToolBarProc; - static final TCHAR ToolBarClass = new TCHAR (0, OS.TOOLBARCLASSNAME, true); - static { - WNDCLASS lpWndClass = new WNDCLASS (); - OS.GetClassInfo (0, ToolBarClass, lpWndClass); + static const WNDPROC ToolBarProc; + static const TCHAR[] ToolBarClass = OS.TOOLBARCLASSNAME; + static this() { + WNDCLASS lpWndClass; + OS.GetClassInfo (null, ToolBarClass.ptr, &lpWndClass); ToolBarProc = lpWndClass.lpfnWndProc; } @@ -85,8 +76,8 @@ * set the button size, the size defaults * to 24 by 22 pixels". */ - static final int DEFAULT_WIDTH = 24; - static final int DEFAULT_HEIGHT = 22; + static const int DEFAULT_WIDTH = 24; + static const int DEFAULT_HEIGHT = 22; /** * Constructs a new instance of this class given its parent @@ -121,7 +112,7 @@ * @see Widget#checkSubclass() * @see Widget#getStyle() */ -public ToolBar (Composite parent, int style) { +public this (Composite parent, int style) { super (parent, checkStyle (style)); /* * Ensure that either of HORIZONTAL or VERTICAL is set. @@ -159,8 +150,8 @@ } } -override int callWindowProc (int hwnd, int msg, int wParam, int lParam) { - if (handle is 0) return 0; +override LRESULT callWindowProc (HWND hwnd, int msg, int wParam, int lParam) { + if (handle is null) return LRESULT.ZERO; /* * Bug in Windows. For some reason, during the processing * of WM_SYSCHAR, the tool bar window proc does not call the @@ -169,9 +160,9 @@ * window proc for WM_SYSCHAR. */ if (msg is OS.WM_SYSCHAR) { - return OS.DefWindowProc (hwnd, msg, wParam, lParam); + return cast(LRESULT) OS.DefWindowProc (hwnd, msg, wParam, lParam); } - return OS.CallWindowProc (ToolBarProc, hwnd, msg, wParam, lParam); + return cast(LRESULT) OS.CallWindowProc (ToolBarProc, hwnd, msg, wParam, lParam); } static int checkStyle (int style) { @@ -209,26 +200,26 @@ checkWidget (); int width = 0, height = 0; if ((style & DWT.VERTICAL) !is 0) { - RECT rect = new RECT (); - TBBUTTON lpButton = new TBBUTTON (); + RECT rect; + TBBUTTON lpButton; int count = OS.SendMessage (handle, OS.TB_BUTTONCOUNT, 0, 0); for (int i=0; i<count; i++) { - OS.SendMessage (handle, OS.TB_GETITEMRECT, i, rect); + OS.SendMessage (handle, OS.TB_GETITEMRECT, i, &rect); height = Math.max (height, rect.bottom); - OS.SendMessage (handle, OS.TB_GETBUTTON, i, lpButton); + OS.SendMessage (handle, OS.TB_GETBUTTON, i, &lpButton); if ((lpButton.fsStyle & OS.BTNS_SEP) !is 0) { - TBBUTTONINFO info = new TBBUTTONINFO (); + TBBUTTONINFO info; info.cbSize = TBBUTTONINFO.sizeof; info.dwMask = OS.TBIF_SIZE; - OS.SendMessage (handle, OS.TB_GETBUTTONINFO, lpButton.idCommand, info); + OS.SendMessage (handle, OS.TB_GETBUTTONINFO, lpButton.idCommand, &info); width = Math.max (width, info.cx); } else { width = Math.max (width, rect.right); } } } else { - RECT oldRect = new RECT (); - OS.GetWindowRect (handle, oldRect); + RECT oldRect; + OS.GetWindowRect (handle, &oldRect); int oldWidth = oldRect.right - oldRect.left; int oldHeight = oldRect.bottom - oldRect.top; int border = getBorderWidth (); @@ -238,15 +229,15 @@ ignoreResize = true; if (redraw) OS.UpdateWindow (handle); int flags = OS.SWP_NOACTIVATE | OS.SWP_NOMOVE | OS.SWP_NOREDRAW | OS.SWP_NOZORDER; - SetWindowPos (handle, 0, 0, 0, newWidth, newHeight, flags); + SetWindowPos (handle, null, 0, 0, newWidth, newHeight, flags); int count = OS.SendMessage (handle, OS.TB_BUTTONCOUNT, 0, 0); if (count !is 0) { - RECT rect = new RECT (); - OS.SendMessage (handle, OS.TB_GETITEMRECT, count - 1, rect); + RECT rect; + OS.SendMessage (handle, OS.TB_GETITEMRECT, count - 1, &rect); width = Math.max (width, rect.right); height = Math.max (height, rect.bottom); } - SetWindowPos (handle, 0, 0, 0, oldWidth, oldHeight, flags); + SetWindowPos (handle, null, 0, 0, oldWidth, oldHeight, flags); if (redraw) OS.ValidateRect (handle, null); ignoreResize = false; } @@ -324,7 +315,7 @@ * The control will not destroy a font that it did not * create. */ - int hFont = OS.GetStockObject (OS.SYSTEM_FONT); + HFONT hFont = OS.GetStockObject (OS.SYSTEM_FONT); OS.SendMessage (handle, OS.WM_SETFONT, hFont, 0); /* Set the button struct, bitmap and button sizes */ @@ -349,10 +340,10 @@ items = newItems; } int bits = item.widgetStyle (); - TBBUTTON lpButton = new TBBUTTON (); + TBBUTTON lpButton; lpButton.idCommand = id; - lpButton.fsStyle = (byte) bits; - lpButton.fsState = (byte) OS.TBSTATE_ENABLED; + lpButton.fsStyle = cast(byte) bits; + lpButton.fsState = cast(byte) OS.TBSTATE_ENABLED; /* * Bug in Windows. Despite the fact that the image list @@ -367,7 +358,7 @@ * separators cannot show images. */ if ((bits & OS.BTNS_SEP) is 0) lpButton.iBitmap = OS.I_IMAGENONE; - if (OS.SendMessage (handle, OS.TB_INSERTBUTTON, index, lpButton) is 0) { + if (OS.SendMessage (handle, OS.TB_INSERTBUTTON, index, &lpButton) is 0) { error (DWT.ERROR_ITEM_NOT_ADDED); } items [item.id = id] = item; @@ -387,10 +378,10 @@ } void destroyItem (ToolItem item) { - TBBUTTONINFO info = new TBBUTTONINFO (); + TBBUTTONINFO info; info.cbSize = TBBUTTONINFO.sizeof; info.dwMask = OS.TBIF_IMAGE | OS.TBIF_STYLE; - int index = OS.SendMessage (handle, OS.TB_GETBUTTONINFO, item.id, info); + int index = OS.SendMessage (handle, OS.TB_GETBUTTONINFO, item.id, &info); /* * Feature in Windows. For some reason, a tool item that has * the style BTNS_SEP does not return I_IMAGENONE when queried @@ -486,8 +477,8 @@ checkWidget (); int count = OS.SendMessage (handle, OS.TB_BUTTONCOUNT, 0, 0); if (!(0 <= index && index < count)) error (DWT.ERROR_INVALID_RANGE); - TBBUTTON lpButton = new TBBUTTON (); - int result = OS.SendMessage (handle, OS.TB_GETBUTTON, index, lpButton); + TBBUTTON lpButton; + int result = OS.SendMessage (handle, OS.TB_GETBUTTON, index, &lpButton); if (result is 0) error (DWT.ERROR_CANNOT_GET_ITEM); return items [lpButton.idCommand]; } @@ -553,10 +544,10 @@ public ToolItem [] getItems () { checkWidget (); int count = OS.SendMessage (handle, OS.TB_BUTTONCOUNT, 0, 0); - TBBUTTON lpButton = new TBBUTTON (); + TBBUTTON lpButton; ToolItem [] result = new ToolItem [count]; for (int i=0; i<count; i++) { - OS.SendMessage (handle, OS.TB_GETBUTTON, i, lpButton); + OS.SendMessage (handle, OS.TB_GETBUTTON, i, &lpButton); result [i] = items [lpButton.idCommand]; } return result; @@ -628,7 +619,7 @@ for (int i=0; i<items.length; i++) { ToolItem item = items [i]; if (item !is null) { - if (!hasText) hasText = item.text.length () !is 0; + if (!hasText) hasText = item.text.length !is 0; if (!hasImage) hasImage = item.image !is null; if (hasText && hasImage) break; } @@ -648,7 +639,7 @@ * the tool items. The fix is to use WM_SETFONT to force * the tool bar to redraw and lay out. */ - int hFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); + auto hFont = cast(HFONT) OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); OS.SendMessage (handle, OS.WM_SETFONT, hFont, 0); setDropDownItems (true); } @@ -665,11 +656,11 @@ * into account extra padding. */ if ((style & DWT.VERTICAL) !is 0) { - TBBUTTONINFO info = new TBBUTTONINFO (); + TBBUTTONINFO info; info.cbSize = TBBUTTONINFO.sizeof; info.dwMask = OS.TBIF_SIZE; int size = OS.SendMessage (handle, OS.TB_GETBUTTONSIZE, 0, 0); - info.cx = (short) (size & 0xFFFF); + info.cx = cast(short) (size & 0xFFFF); int index = 0; while (index < items.length) { ToolItem item = items [index]; @@ -683,7 +674,7 @@ for (int i=0; i<items.length; i++) { ToolItem item = items [i]; if (item !is null && (item.style & DWT.SEPARATOR) is 0) { - OS.SendMessage (handle, OS.TB_SETBUTTONINFO, item.id, info); + OS.SendMessage (handle, OS.TB_SETBUTTONINFO, item.id, &info); } } } @@ -693,24 +684,24 @@ } } -override bool mnemonicHit (char ch) { +override bool mnemonicHit (wchar ch) { int key = Display.wcsToMbcs (ch); - int [] id = new int [1]; - if (OS.SendMessage (handle, OS.TB_MAPACCELERATOR, key, id) is 0) { + int id; + if (OS.SendMessage (handle, OS.TB_MAPACCELERATOR, key, &id) is 0) { return false; } if ((style & DWT.FLAT) !is 0 && !setTabGroupFocus ()) return false; - int index = OS.SendMessage (handle, OS.TB_COMMANDTOINDEX, id [0], 0); + int index = OS.SendMessage (handle, OS.TB_COMMANDTOINDEX, id, 0); if (index is -1) return false; OS.SendMessage (handle, OS.TB_SETHOTITEM, index, 0); - items [id [0]].click (false); + items [id].click (false); return true; } -override bool mnemonicMatch (char ch) { +override bool mnemonicMatch (wchar ch) { int key = Display.wcsToMbcs (ch); - int [] id = new int [1]; - if (OS.SendMessage (handle, OS.TB_MAPACCELERATOR, key, id) is 0) { + int id; + if (OS.SendMessage (handle, OS.TB_MAPACCELERATOR, key, &id) is 0) { return false; } /* @@ -719,9 +710,9 @@ * undocumented and unwanted. The fix is to ensure that the tool item * contains a mnemonic when TB_MAPACCELERATOR returns true. */ - int index = OS.SendMessage (handle, OS.TB_COMMANDTOINDEX, id [0], 0); + int index = OS.SendMessage (handle, OS.TB_COMMANDTOINDEX, id, 0); if (index is -1) return false; - return findMnemonic (items [id [0]].text) !is '\0'; + return findMnemonic (items [id].text) !is '\0'; } override void releaseChildren (bool destroy) { @@ -764,9 +755,9 @@ } } -override void setBackgroundImage (int hBitmap) { +override void setBackgroundImage (HBITMAP hBitmap) { super.setBackgroundImage (hBitmap); - setBackgroundTransparent (hBitmap !is 0); + setBackgroundTransparent (hBitmap !is null); } override void setBackgroundPixel (int pixel) { @@ -841,7 +832,7 @@ for (int i=0; i<items.length; i++) { ToolItem item = items [i]; if (item !is null) { - if (!hasText) hasText = item.text.length () !is 0; + if (!hasText) hasText = item.text.length !is 0; if (!hasImage) hasImage = item.image !is null; if (hasText && hasImage) break; } @@ -850,16 +841,16 @@ for (int i=0; i<items.length; i++) { ToolItem item = items [i]; if (item !is null && (item.style & DWT.DROP_DOWN) !is 0) { - TBBUTTONINFO info = new TBBUTTONINFO (); + TBBUTTONINFO info; info.cbSize = TBBUTTONINFO.sizeof; info.dwMask = OS.TBIF_STYLE; - OS.SendMessage (handle, OS.TB_GETBUTTONINFO, item.id, info); + OS.SendMessage (handle, OS.TB_GETBUTTONINFO, item.id, &info); if (set) { info.fsStyle |= OS.BTNS_DROPDOWN; } else { info.fsStyle &= ~OS.BTNS_DROPDOWN; } - OS.SendMessage (handle, OS.TB_SETBUTTONINFO, item.id, info); + OS.SendMessage (handle, OS.TB_SETBUTTONINFO, item.id, &info); } } } @@ -868,7 +859,7 @@ void setDisabledImageList (ImageList imageList) { if (disabledImageList is imageList) return; - int hImageList = 0; + HBITMAP hImageList; if ((disabledImageList = imageList) !is null) { hImageList = disabledImageList.getHandle (); } @@ -904,7 +895,7 @@ void setHotImageList (ImageList imageList) { if (hotImageList is imageList) return; - int hImageList = 0; + HBITMAP hImageList; if ((hotImageList = imageList) !is null) { hImageList = hotImageList.getHandle (); } @@ -915,7 +906,7 @@ void setImageList (ImageList imageList) { if (this.imageList is imageList) return; - int hImageList = 0; + HBITMAP hImageList; if ((this.imageList = imageList) !is null) { hImageList = imageList.getHandle (); } @@ -946,9 +937,9 @@ * the items. This is unexpected. The fix is to save and restore * the current size of the tool bar. */ - RECT rect = new RECT (); - OS.GetWindowRect (handle, rect); - OS.MapWindowPoints (0, parent.handle, rect, 2); + RECT rect; + OS.GetWindowRect (handle, &rect); + OS.MapWindowPoints (null, parent.handle, cast(POINT*) &rect, 2); ignoreResize = true; /* * Feature in Windows. When the last button in a tool bar has the @@ -968,7 +959,7 @@ count += 2; OS.SendMessage (handle, OS.TB_SETROWS, (1 << 16) | count, 0); int flags = OS.SWP_NOACTIVATE | OS.SWP_NOMOVE | OS.SWP_NOZORDER; - SetWindowPos (handle, 0, 0, 0, rect.right - rect.left, rect.bottom - rect.top, flags); + SetWindowPos (handle, null, 0, 0, rect.right - rect.left, rect.bottom - rect.top, flags); ignoreResize = false; } } @@ -986,7 +977,7 @@ return super.setTabItemFocus (); } -override String toolTipText (NMTTDISPINFO hdr) { +override char[] toolTipText (NMTTDISPINFO* hdr) { if ((hdr.uFlags & OS.TTF_IDISHWND) !is 0) { return null; } @@ -998,10 +989,10 @@ * provide the string, causing no tool tip to be displayed. */ if (!hasCursor ()) return ""; //$NON-NLS-1$ - int index = hdr.idFrom; - int hwndToolTip = OS.SendMessage (handle, OS.TB_GETTOOLTIPS, 0, 0); - if (hwndToolTip is hdr.hwndFrom) { - if (toolTipText !is null) return ""; //$NON-NLS-1$ + int index = hdr.hdr.idFrom; + auto hwndToolTip = cast(HWND) OS.SendMessage (handle, OS.TB_GETTOOLTIPS, 0, 0); + if (hwndToolTip is hdr.hdr.hwndFrom) { + if (toolTipText_ !is null) return ""; //$NON-NLS-1$ if (0 <= index && index < items.length) { ToolItem item = items [index]; if (item !is null) return item.toolTipText; @@ -1035,17 +1026,17 @@ return bits; } -override TCHAR windowClass () { - return ToolBarClass; +override char[] windowClass () { + return TCHARsToStr(ToolBarClass); } override int windowProc () { - return ToolBarProc; + return cast(int)ToolBarProc; } override LRESULT WM_CAPTURECHANGED (int wParam, int lParam) { LRESULT result = super.WM_CAPTURECHANGED (wParam, lParam); - if (result !is null) return result; + if (result !is LRESULT.NULL) return result; /* * Bug in Windows. When the tool bar loses capture while an * item is pressed, the item remains pressed. The fix is @@ -1066,13 +1057,13 @@ override LRESULT WM_CHAR (int wParam, int lParam) { LRESULT result = super.WM_CHAR (wParam, lParam); - if (result !is null) return result; + if (result !is LRESULT.NULL) return result; switch (wParam) { case ' ': int index = OS.SendMessage (handle, OS.TB_GETHOTITEM, 0, 0); if (index !is -1) { - TBBUTTON lpButton = new TBBUTTON (); - int code = OS.SendMessage (handle, OS.TB_GETBUTTON, index, lpButton); + TBBUTTON lpButton; + int code = OS.SendMessage (handle, OS.TB_GETBUTTON, index, &lpButton); if (code !is 0) { items [lpButton.idCommand].click (false); return LRESULT.ZERO; @@ -1102,7 +1093,7 @@ * for this control. */ LRESULT result = super.WM_COMMAND (wParam, lParam); - if (result !is null) return result; + if (result !is LRESULT.NULL) return result; return LRESULT.ZERO; } @@ -1116,7 +1107,7 @@ */ if (findBackgroundControl () !is null) { if (OS.COMCTL32_MAJOR < 6) { - drawBackground (wParam); + drawBackground (cast(HANDLE) wParam); return LRESULT.ONE; } } @@ -1130,13 +1121,13 @@ * processed without needing to press the ALT key * when the widget has focus. */ - if (result !is null) return result; - return new LRESULT (OS.DLGC_BUTTON); + if (result !is LRESULT.NULL) return result; + return cast(LRESULT) (OS.DLGC_BUTTON); } override LRESULT WM_KEYDOWN (int wParam, int lParam) { LRESULT result = super.WM_KEYDOWN (wParam, lParam); - if (result !is null) return result; + if (result !is LRESULT.NULL) return result; switch (wParam) { case OS.VK_SPACE: /* @@ -1151,25 +1142,25 @@ override LRESULT WM_KILLFOCUS (int wParam, int lParam) { int index = OS.SendMessage (handle, OS.TB_GETHOTITEM, 0, 0); - TBBUTTON lpButton = new TBBUTTON (); - int code = OS.SendMessage (handle, OS.TB_GETBUTTON, index, lpButton); + TBBUTTON lpButton; + int code = OS.SendMessage (handle, OS.TB_GETBUTTON, index, &lpButton); if (code !is 0) lastFocusId = lpButton.idCommand; return super.WM_KILLFOCUS (wParam, lParam); } override LRESULT WM_LBUTTONDOWN (int wParam, int lParam) { - if (ignoreMouse) return null; + if (ignoreMouse) return LRESULT.NULL; return super.WM_LBUTTONDOWN (wParam, lParam); } override LRESULT WM_LBUTTONUP (int wParam, int lParam) { - if (ignoreMouse) return null; + if (ignoreMouse) return LRESULT.NULL; return super.WM_LBUTTONUP (wParam, lParam); } override LRESULT WM_MOUSELEAVE (int wParam, int lParam) { LRESULT result = super.WM_MOUSELEAVE (wParam, lParam); - if (result !is null) return result; + if (result !is LRESULT.NULL) return result; /* * Bug in Windows. On XP, when a tooltip is * hidden due to a time out or mouse press, @@ -1182,13 +1173,13 @@ * the mouse leaves the control. */ if (OS.COMCTL32_MAJOR >= 6) { - TOOLINFO lpti = new TOOLINFO (); + TOOLINFO lpti; lpti.cbSize = TOOLINFO.sizeof; - int hwndToolTip = OS.SendMessage (handle, OS.TB_GETTOOLTIPS, 0, 0); - if (OS.SendMessage (hwndToolTip, OS.TTM_GETCURRENTTOOL, 0, lpti) !is 0) { + auto hwndToolTip = cast(HWND) OS.SendMessage (handle, OS.TB_GETTOOLTIPS, 0, 0); + if (OS.SendMessage (hwndToolTip, OS.TTM_GETCURRENTTOOL, 0, &lpti) !is 0) { if ((lpti.uFlags & OS.TTF_IDISHWND) is 0) { - OS.SendMessage (hwndToolTip, OS.TTM_DELTOOL, 0, lpti); - OS.SendMessage (hwndToolTip, OS.TTM_ADDTOOL, 0, lpti); + OS.SendMessage (hwndToolTip, OS.TTM_DELTOOL, 0, &lpti); + OS.SendMessage (hwndToolTip, OS.TTM_ADDTOOL, 0, &lpti); } } } @@ -1215,7 +1206,7 @@ * for this control. */ LRESULT result = super.WM_NOTIFY (wParam, lParam); - if (result !is null) return result; + if (result !is LRESULT.NULL) return result; return LRESULT.ZERO; } @@ -1232,7 +1223,7 @@ if (ignoreResize) { int code = callWindowProc (handle, OS.WM_SIZE, wParam, lParam); if (code is 0) return LRESULT.ZERO; - return new LRESULT (code); + return cast(LRESULT) (code); } LRESULT result = super.WM_SIZE (wParam, lParam); if (isDisposed ()) return result; @@ -1247,14 +1238,14 @@ * and set it each time the tool bar is resized. */ if ((style & DWT.BORDER) !is 0 && (style & DWT.WRAP) !is 0) { - RECT windowRect = new RECT (); - OS.GetWindowRect (handle, windowRect); + RECT windowRect; + OS.GetWindowRect (handle, &windowRect); int index = 0, border = getBorderWidth () * 2; - RECT rect = new RECT (); + RECT rect; int count = OS.SendMessage (handle, OS.TB_BUTTONCOUNT, 0, 0); while (index < count) { - OS.SendMessage (handle, OS.TB_GETITEMRECT, index, rect); - OS.MapWindowPoints (handle, 0, rect, 2); + OS.SendMessage (handle, OS.TB_GETITEMRECT, index, &rect); + OS.MapWindowPoints (handle, null, cast(POINT*) &rect, 2); if (rect.right > windowRect.right - border * 2) break; index++; } @@ -1272,7 +1263,7 @@ override LRESULT WM_WINDOWPOSCHANGING (int wParam, int lParam) { LRESULT result = super.WM_WINDOWPOSCHANGING (wParam, lParam); - if (result !is null) return result; + if (result !is LRESULT.NULL) return result; if (ignoreResize) return result; /* * Bug in Windows. When a flat tool bar is wrapped, @@ -1291,45 +1282,45 @@ if (OS.SendMessage (handle, OS.TB_GETROWS, 0, 0) is 1) { return result; } - WINDOWPOS lpwp = new WINDOWPOS (); - OS.MoveMemory (lpwp, lParam, WINDOWPOS.sizeof); + WINDOWPOS* lpwp = cast(WINDOWPOS*)lParam; + //OS.MoveMemory (lpwp, lParam, WINDOWPOS.sizeof); if ((lpwp.flags & (OS.SWP_NOSIZE | OS.SWP_NOREDRAW)) !is 0) { return result; } - RECT oldRect = new RECT (); - OS.GetClientRect (handle, oldRect); - RECT newRect = new RECT (); - OS.SetRect (newRect, 0, 0, lpwp.cx, lpwp.cy); - OS.SendMessage (handle, OS.WM_NCCALCSIZE, 0, newRect); + RECT oldRect; + OS.GetClientRect (handle, &oldRect); + RECT newRect; + OS.SetRect (&newRect, 0, 0, lpwp.cx, lpwp.cy); + OS.SendMessage (handle, OS.WM_NCCALCSIZE, 0, &newRect); int oldWidth = oldRect.right - oldRect.left; int newWidth = newRect.right - newRect.left; if (newWidth > oldWidth) { - RECT rect = new RECT (); + RECT rect; int newHeight = newRect.bottom - newRect.top; - OS.SetRect (rect, oldWidth - 2, 0, oldWidth, newHeight); - OS.InvalidateRect (handle, rect, false); + OS.SetRect (&rect, oldWidth - 2, 0, oldWidth, newHeight); + OS.InvalidateRect (handle, &rect, false); } return result; } override LRESULT wmCommandChild (int wParam, int lParam) { ToolItem child = items [wParam & 0xFFFF]; - if (child is null) return null; + if (child is null) return LRESULT.NULL; return child.wmCommandChild (wParam, lParam); } -override LRESULT wmNotifyChild (NMHDR hdr, int wParam, int lParam) { +override LRESULT wmNotifyChild (NMHDR* hdr, int wParam, int lParam) { switch (hdr.code) { case OS.TBN_DROPDOWN: - NMTOOLBAR lpnmtb = new NMTOOLBAR (); - OS.MoveMemory (lpnmtb, lParam, NMTOOLBAR.sizeof); + NMTOOLBAR* lpnmtb = cast(NMTOOLBAR*)lParam; + //OS.MoveMemory (lpnmtb, lParam, NMTOOLBAR.sizeof); ToolItem child = items [lpnmtb.iItem]; if (child !is null) { Event event = new Event (); event.detail = DWT.ARROW; int index = OS.SendMessage (handle, OS.TB_COMMANDTOINDEX, lpnmtb.iItem, 0); - RECT rect = new RECT (); - OS.SendMessage (handle, OS.TB_GETITEMRECT, index, rect); + RECT rect; + OS.SendMessage (handle, OS.TB_GETITEMRECT, index, &rect); event.x = rect.left; event.y = rect.bottom; child.postEvent (DWT.Selection, event); @@ -1343,8 +1334,8 @@ * from the default Blue theme. The fix is to draw the * background. */ - NMCUSTOMDRAW nmcd = new NMCUSTOMDRAW (); - OS.MoveMemory (nmcd, lParam, NMCUSTOMDRAW.sizeof); + NMCUSTOMDRAW* nmcd = cast(NMCUSTOMDRAW*)lParam; + //OS.MoveMemory (nmcd, lParam, NMCUSTOMDRAW.sizeof); // if (drawCount !is 0 || !OS.IsWindowVisible (handle)) { // if (!OS.IsWinCE && OS.WindowFromDC (nmcd.hdc) is handle) break; // } @@ -1359,25 +1350,25 @@ if ((bits & OS.TBSTYLE_FLAT) is 0) { drawBackground (nmcd.hdc); } else { - RECT rect = new RECT (); - OS.SetRect (rect, nmcd.left, nmcd.top, nmcd.right, nmcd.bottom); - drawBackground (nmcd.hdc, rect); + RECT rect; + OS.SetRect (&rect, nmcd.rc.left, nmcd.rc.top, nmcd.rc.right, nmcd.rc.bottom); + drawBackground (nmcd.hdc, &rect); } - return new LRESULT (OS.CDRF_SKIPDEFAULT); + return cast(LRESULT) (OS.CDRF_SKIPDEFAULT); } } break; case OS.TBN_HOTITEMCHANGE: if (!OS.IsWinCE) { - NMTBHOTITEM lpnmhi = new NMTBHOTITEM (); - OS.MoveMemory (lpnmhi, lParam, NMTBHOTITEM.sizeof); + auto lpnmhi = cast(NMTBHOTITEM*)lParam; + //OS.MoveMemory (lpnmhi, lParam, NMTBHOTITEM.sizeof); switch (lpnmhi.dwFlags) { case OS.HICF_ARROWKEYS: - RECT client = new RECT (); - OS.GetClientRect (handle, client); + RECT client; + OS.GetClientRect (handle, &client); int index = OS.SendMessage (handle, OS.TB_COMMANDTOINDEX, lpnmhi.idNew, 0); - RECT rect = new RECT (); - OS.SendMessage (handle, OS.TB_GETITEMRECT, index, rect); + RECT rect; + OS.SendMessage (handle, OS.TB_GETITEMRECT, index, &rect); if (rect.right > client.right || rect.bottom > client.bottom) { return LRESULT.ONE; } @@ -1390,4 +1381,4 @@ } } -++/ +
--- a/dwt/widgets/ToolItem.d Mon Feb 04 20:53:04 2008 +0100 +++ b/dwt/widgets/ToolItem.d Mon Feb 04 21:28:40 2008 +0100 @@ -10,15 +10,6 @@ *******************************************************************************/ module dwt.widgets.ToolItem; -import dwt.widgets.Item; -import dwt.widgets.Widget; - -class ToolItem : Item { - public this (Widget parent, int style) { - super (parent, style); - } -} -/++ import dwt.DWT; import dwt.DWTException; import dwt.events.SelectionEvent; @@ -26,11 +17,16 @@ import dwt.graphics.Image; import dwt.graphics.Rectangle; import dwt.internal.ImageList; -import dwt.internal.win32.LRESULT; import dwt.internal.win32.OS; -import dwt.internal.win32.RECT; -import dwt.internal.win32.TBBUTTONINFO; -import dwt.internal.win32.TCHAR; + +import dwt.widgets.Item; +import dwt.widgets.Widget; +import dwt.widgets.ToolBar; +import dwt.widgets.Control; +import dwt.widgets.TypedListener; + +import dwt.dwthelper.utils; + /** * Instances of this class represent a selectable user interface object @@ -48,10 +44,10 @@ * IMPORTANT: This class is <em>not</em> intended to be subclassed. * </p> */ -public class ToolItem extends Item { +public class ToolItem : Item { ToolBar parent; Control control; - String toolTipText; + char[] toolTipText; Image disabledImage, hotImage; Image disabledImage2; int id; @@ -90,7 +86,7 @@ * @see Widget#checkSubclass * @see Widget#getStyle */ -public ToolItem (ToolBar parent, int style) { +public this (ToolBar parent, int style) { super (parent, checkStyle (style)); this.parent = parent; parent.createItem (this, parent.getItemCount ()); @@ -132,7 +128,7 @@ * @see Widget#checkSubclass * @see Widget#getStyle */ -public ToolItem (ToolBar parent, int style, int index) { +public this (ToolBar parent, int style, int index) { super (parent, checkStyle (style)); this.parent = parent; parent.createItem (this, index); @@ -180,11 +176,11 @@ } void click (bool dropDown) { - int hwnd = parent.handle; + auto hwnd = parent.handle; if (OS.GetKeyState (OS.VK_LBUTTON) < 0) return; int index = OS.SendMessage (hwnd, OS.TB_COMMANDTOINDEX, id, 0); - RECT rect = new RECT (); - OS.SendMessage (hwnd, OS.TB_GETITEMRECT, index, rect); + RECT rect; + OS.SendMessage (hwnd, OS.TB_GETITEMRECT, index, &rect); int hotIndex = OS.SendMessage (hwnd, OS.TB_GETHOTITEM, 0, 0); /* @@ -224,10 +220,10 @@ */ public Rectangle getBounds () { checkWidget(); - int hwnd = parent.handle; + auto hwnd = parent.handle; int index = OS.SendMessage (hwnd, OS.TB_COMMANDTOINDEX, id, 0); - RECT rect = new RECT (); - OS.SendMessage (hwnd, OS.TB_GETITEMRECT, index, rect); + RECT rect; + OS.SendMessage (hwnd, OS.TB_GETITEMRECT, index, &rect); int width = rect.right - rect.left; int height = rect.bottom - rect.top; return new Rectangle (rect.left, rect.top, width, height); @@ -288,7 +284,7 @@ if ((style & DWT.SEPARATOR) !is 0) { return (state & DISABLED) is 0; } - int hwnd = parent.handle; + auto hwnd = parent.handle; int fsState = OS.SendMessage (hwnd, OS.TB_GETSTATE, id, 0); return (fsState & OS.TBSTATE_ENABLED) !is 0; } @@ -347,7 +343,7 @@ public bool getSelection () { checkWidget(); if ((style & (DWT.CHECK | DWT.RADIO)) is 0) return false; - int hwnd = parent.handle; + auto hwnd = parent.handle; int fsState = OS.SendMessage (hwnd, OS.TB_GETSTATE, id, 0); return (fsState & OS.TBSTATE_CHECKED) !is 0; } @@ -362,7 +358,7 @@ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public String getToolTipText () { +public char[] getToolTipText () { checkWidget(); return toolTipText; } @@ -379,10 +375,10 @@ */ public int getWidth () { checkWidget(); - int hwnd = parent.handle; + auto hwnd = parent.handle; int index = OS.SendMessage (hwnd, OS.TB_COMMANDTOINDEX, id, 0); - RECT rect = new RECT (); - OS.SendMessage (hwnd, OS.TB_GETITEMRECT, index, rect); + RECT rect; + OS.SendMessage (hwnd, OS.TB_GETITEMRECT, index, &rect); return rect.right - rect.left; } @@ -423,11 +419,11 @@ } void releaseImages () { - TBBUTTONINFO info = new TBBUTTONINFO (); + TBBUTTONINFO info; info.cbSize = TBBUTTONINFO.sizeof; info.dwMask = OS.TBIF_IMAGE | OS.TBIF_STYLE; - int hwnd = parent.handle; - OS.SendMessage (hwnd, OS.TB_GETBUTTONINFO, id, info); + auto hwnd = parent.handle; + OS.SendMessage (hwnd, OS.TB_GETBUTTONINFO, id, &info); /* * Feature in Windows. For some reason, a tool item that has * the style BTNS_SEP does not return I_IMAGENONE when queried @@ -542,11 +538,11 @@ */ if ((parent.style & (DWT.WRAP | DWT.VERTICAL)) !is 0) { bool changed = false; - int hwnd = parent.handle; - TBBUTTONINFO info = new TBBUTTONINFO (); + auto hwnd = parent.handle; + TBBUTTONINFO info; info.cbSize = TBBUTTONINFO.sizeof; info.dwMask = OS.TBIF_STYLE | OS.TBIF_STATE; - OS.SendMessage (hwnd, OS.TB_GETBUTTONINFO, id, info); + OS.SendMessage (hwnd, OS.TB_GETBUTTONINFO, id, &info); if (control is null) { if ((info.fsStyle & OS.BTNS_SEP) is 0) { changed = true; @@ -569,7 +565,7 @@ } } if (changed) { - OS.SendMessage (hwnd, OS.TB_SETBUTTONINFO, id, info); + OS.SendMessage (hwnd, OS.TB_SETBUTTONINFO, id, &info); /* * Bug in Windows. When TB_SETBUTTONINFO changes the * style of a tool item from BTNS_SEP to BTNS_BUTTON @@ -605,7 +601,7 @@ */ public void setEnabled (bool enabled) { checkWidget(); - int hwnd = parent.handle; + auto hwnd = parent.handle; int fsState = OS.SendMessage (hwnd, OS.TB_GETSTATE, id, 0); /* * Feature in Windows. When TB_SETSTATE is used to set the @@ -712,7 +708,7 @@ public void setSelection (bool selected) { checkWidget(); if ((style & (DWT.CHECK | DWT.RADIO)) is 0) return; - int hwnd = parent.handle; + auto hwnd = parent.handle; int fsState = OS.SendMessage (hwnd, OS.TB_GETSTATE, id, 0); /* * Feature in Windows. When TB_SETSTATE is used to set the @@ -770,28 +766,29 @@ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -override public void setText (String string) { +override public void setText (char[] string) { checkWidget(); if (string is null) error (DWT.ERROR_NULL_ARGUMENT); if ((style & DWT.SEPARATOR) !is 0) return; - if (string.equals (text)) return; + if (string==/*eq*/text) return; super.setText (string); - int hwnd = parent.handle; - TBBUTTONINFO info = new TBBUTTONINFO (); + auto hwnd = parent.handle; + TBBUTTONINFO info; info.cbSize = TBBUTTONINFO.sizeof; info.dwMask = OS.TBIF_TEXT | OS.TBIF_STYLE; - info.fsStyle = (byte) (widgetStyle () | OS.BTNS_AUTOSIZE); - int hHeap = OS.GetProcessHeap (), pszText = 0; - if (string.length () !is 0) { + info.fsStyle = cast(byte) (widgetStyle () | OS.BTNS_AUTOSIZE); + auto hHeap = OS.GetProcessHeap (); + TCHAR* pszText; + if (string.length !is 0) { info.fsStyle |= OS.BTNS_SHOWTEXT; - TCHAR buffer = new TCHAR (parent.getCodePage (), string, true); - int byteCount = buffer.length () * TCHAR.sizeof; - pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); - OS.MoveMemory (pszText, buffer, byteCount); + TCHAR[] buffer = StrToTCHARs (parent.getCodePage (), string, true ); + int byteCount = buffer.length * TCHAR.sizeof; + pszText = cast(TCHAR*) OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); + OS.MoveMemory (pszText, buffer.ptr, byteCount); info.pszText = pszText; } - OS.SendMessage (hwnd, OS.TB_SETBUTTONINFO, id, info); - if (pszText !is 0) OS.HeapFree (hHeap, 0, pszText); + OS.SendMessage (hwnd, OS.TB_SETBUTTONINFO, id, &info); + if (pszText !is null) OS.HeapFree (hHeap, 0, pszText); /* * Bug in Windows. For some reason, when the font is set @@ -819,7 +816,7 @@ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public void setToolTipText (String string) { +public void setToolTipText (char[] string) { checkWidget(); toolTipText = string; } @@ -838,22 +835,22 @@ checkWidget(); if ((style & DWT.SEPARATOR) is 0) return; if (width < 0) return; - int hwnd = parent.handle; - TBBUTTONINFO info = new TBBUTTONINFO (); + auto hwnd = parent.handle; + TBBUTTONINFO info; info.cbSize = TBBUTTONINFO.sizeof; info.dwMask = OS.TBIF_SIZE; - info.cx = (short) width; - OS.SendMessage (hwnd, OS.TB_SETBUTTONINFO, id, info); + info.cx = cast(short) width; + OS.SendMessage (hwnd, OS.TB_SETBUTTONINFO, id, &info); parent.layoutItems (); } void updateImages (bool enabled) { if ((style & DWT.SEPARATOR) !is 0) return; - int hwnd = parent.handle; - TBBUTTONINFO info = new TBBUTTONINFO (); + auto hwnd = parent.handle; + TBBUTTONINFO info; info.cbSize = TBBUTTONINFO.sizeof; info.dwMask = OS.TBIF_IMAGE; - OS.SendMessage (hwnd, OS.TB_GETBUTTONINFO, id, info); + OS.SendMessage (hwnd, OS.TB_GETBUTTONINFO, id, &info); if (info.iImage is OS.I_IMAGENONE && image is null) return; ImageList imageList = parent.getImageList (); ImageList hotImageList = parent.getHotImageList (); @@ -938,7 +935,7 @@ */ info.dwMask |= OS.TBIF_SIZE; info.cx = 0; - OS.SendMessage (hwnd, OS.TB_SETBUTTONINFO, id, info); + OS.SendMessage (hwnd, OS.TB_SETBUTTONINFO, id, &info); parent.layoutItems (); } @@ -965,8 +962,8 @@ } } postEvent (DWT.Selection); - return null; + return LRESULT.NULL; } } -++/ +