Mercurial > projects > dwt-win
diff dwt/widgets/ToolItem.d @ 69:3b93cc2ffe96
ToolBar, ToolItem
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 04 Feb 2008 21:28:40 +0100 |
parents | 0f25be5cbe6f |
children | 42fc35b18200 |
line wrap: on
line diff
--- 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; } } -++/ +