# HG changeset patch # User Frank Benoit # Date 1202004319 -3600 # Node ID 2146ed8ff33cced62937cce6638d71e4c094f07b # Parent 8b6ed01694711bc36f30a766b08415c0f0587748 Group diff -r 8b6ed0169471 -r 2146ed8ff33c dwt/widgets/Group.d --- a/dwt/widgets/Group.d Sun Feb 03 02:29:42 2008 +0100 +++ b/dwt/widgets/Group.d Sun Feb 03 03:05:19 2008 +0100 @@ -12,24 +12,16 @@ *******************************************************************************/ module dwt.widgets.Group; -import dwt.widgets.Composite; -class Group : Composite { -} -/++ + import dwt.DWT; import dwt.DWTException; import dwt.graphics.Font; import dwt.graphics.Point; import dwt.graphics.Rectangle; -import dwt.internal.win32.LRESULT; import dwt.internal.win32.OS; -import dwt.internal.win32.RECT; -import dwt.internal.win32.TCHAR; -import dwt.internal.win32.TEXTMETRIC; -import dwt.internal.win32.TEXTMETRICA; -import dwt.internal.win32.TEXTMETRICW; -import dwt.internal.win32.WINDOWPOS; -import dwt.internal.win32.WNDCLASS; +import dwt.widgets.Composite; + +import dwt.dwthelper.utils; /** * Instances of this class provide an etched border @@ -52,12 +44,17 @@ *

*/ -public class Group extends Composite { - String text = ""; - static final int CLIENT_INSET = 3; - static final int GroupProc; - static final TCHAR GroupClass = new TCHAR (0, OS.IsWinCE ? "BUTTON" : "SWT_GROUP", true); - static { +public class Group : Composite { + char[] text = ""; + static const int CLIENT_INSET = 3; + static const WNDPROC GroupProc; + static if( OS.IsWinCE ){ + static const TCHAR[] GroupClass = "BUTTON\0"; + } + else{ + static const TCHAR[] GroupClass = "SWT_GROUP\0"; + } + static this() { /* * Feature in Windows. The group box window class * uses the CS_HREDRAW and CS_VREDRAW style bits to @@ -71,24 +68,24 @@ * CreateWindowEx() to crash. The workaround is to use * the class Button directly. */ - WNDCLASS lpWndClass = new WNDCLASS (); + WNDCLASS lpWndClass; if (OS.IsWinCE) { - OS.GetClassInfo (0, GroupClass, lpWndClass); + OS.GetClassInfo (null, GroupClass.ptr, &lpWndClass); GroupProc = lpWndClass.lpfnWndProc; } else { - TCHAR WC_BUTTON = new TCHAR (0, "BUTTON", true); - OS.GetClassInfo (0, WC_BUTTON, lpWndClass); + TCHAR[] WC_BUTTON = "BUTTON\0"; + OS.GetClassInfo (null, WC_BUTTON.ptr, &lpWndClass); GroupProc = lpWndClass.lpfnWndProc; - int hInstance = OS.GetModuleHandle (null); - if (!OS.GetClassInfo (hInstance, GroupClass, lpWndClass)) { - int hHeap = OS.GetProcessHeap (); + auto hInstance = OS.GetModuleHandle (null); + if (!OS.GetClassInfo (hInstance, GroupClass.ptr, &lpWndClass)) { + auto hHeap = OS.GetProcessHeap (); lpWndClass.hInstance = hInstance; lpWndClass.style &= ~(OS.CS_HREDRAW | OS.CS_VREDRAW); - int byteCount = GroupClass.length () * TCHAR.sizeof; - int lpszClassName = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); - OS.MoveMemory (lpszClassName, GroupClass, byteCount); + int byteCount = GroupClass.length * TCHAR.sizeof; + auto lpszClassName = cast(TCHAR*)OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); + OS.MoveMemory (lpszClassName, GroupClass.ptr, byteCount); lpWndClass.lpszClassName = lpszClassName; - OS.RegisterClass (lpWndClass); + OS.RegisterClass (&lpWndClass); OS.HeapFree (hHeap, 0, lpszClassName); } } @@ -126,12 +123,12 @@ * @see Widget#checkSubclass * @see Widget#getStyle */ -public Group (Composite parent, int style) { +public this (Composite parent, int style) { super (parent, checkStyle (style)); } -int callWindowProc (int hwnd, int msg, int wParam, int lParam) { - if (handle is 0) return 0; +LRESULT callWindowProc (HWND hwnd, int msg, int wParam, int lParam) { + if (handle is null) return LRESULT.NULL; /* * Feature in Windows. When the user clicks on the group * box label, the group box takes focus. This is unwanted. @@ -140,9 +137,9 @@ switch (msg) { case OS.WM_LBUTTONDOWN: case OS.WM_LBUTTONDBLCLK: - return OS.DefWindowProc (hwnd, msg, wParam, lParam); + return cast(LRESULT) OS.DefWindowProc (hwnd, msg, wParam, lParam); } - return OS.CallWindowProc (GroupProc, hwnd, msg, wParam, lParam); + return cast(LRESULT) OS.CallWindowProc (GroupProc, hwnd, msg, wParam, lParam); } static int checkStyle (int style) { @@ -164,7 +161,7 @@ public Point computeSize (int wHint, int hHint, bool changed) { checkWidget (); Point size = super.computeSize (wHint, hHint, changed); - int length = text.length (); + int length = text.length; if (length !is 0) { /* * Bug in Windows. When a group control is right-to-left and @@ -173,25 +170,25 @@ * the work around must run all the time to stop the preferred * size from changing when a group is enabled and disabled. */ - String string = text; + char[] string = text; if ((style & DWT.RIGHT_TO_LEFT) !is 0) { if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) { - string = " " + string + " "; + string = " " ~ string ~ " "; } } /* * If the group has text, and the text is wider than the * client area, pad the width so the text is not clipped. */ - TCHAR buffer = new TCHAR (getCodePage (), string, true); - int newFont, oldFont = 0; - int hDC = OS.GetDC (handle); - newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); - if (newFont !is 0) oldFont = OS.SelectObject (hDC, newFont); - RECT rect = new RECT (); + TCHAR* buffer = StrToTCHARz (/+getCodePage (),+/ string); + HFONT newFont, oldFont; + auto hDC = OS.GetDC (handle); + newFont = cast(HFONT) OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); + if (newFont !is null) oldFont = OS.SelectObject (hDC, newFont); + RECT rect; int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE; - OS.DrawText (hDC, buffer, -1, rect, flags); - if (newFont !is 0) OS.SelectObject (hDC, oldFont); + OS.DrawText (hDC, buffer, -1, &rect, flags); + if (newFont !is null) OS.SelectObject (hDC, oldFont); OS.ReleaseDC (handle, hDC); size.x = Math.max (size.x, rect.right - rect.left + CLIENT_INSET * 6); } @@ -201,13 +198,13 @@ public Rectangle computeTrim (int x, int y, int width, int height) { checkWidget (); Rectangle trim = super.computeTrim (x, y, width, height); - int newFont, oldFont = 0; - int hDC = OS.GetDC (handle); - newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); - if (newFont !is 0) oldFont = OS.SelectObject (hDC, newFont); - TEXTMETRIC tm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW () : new TEXTMETRICA (); - OS.GetTextMetrics (hDC, tm); - if (newFont !is 0) OS.SelectObject (hDC, oldFont); + HFONT newFont, oldFont; + auto hDC = OS.GetDC (handle); + newFont = cast(HFONT) OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); + if (newFont !is null) oldFont = OS.SelectObject (hDC, newFont); + TEXTMETRIC tm; + OS.GetTextMetrics (hDC, &tm); + if (newFont !is null) OS.SelectObject (hDC, oldFont); OS.ReleaseDC (handle, hDC); trim.x -= CLIENT_INSET; trim.y -= tm.tmHeight; @@ -231,8 +228,8 @@ */ if ((style & DWT.RIGHT_TO_LEFT) !is 0) { if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) { - String string = enabled || text.length() is 0 ? text : " " + text + " "; - TCHAR buffer = new TCHAR (getCodePage (), string, true); + char[] string = enabled || text.length is 0 ? text : " " ~ text ~ " "; + TCHAR* buffer = StrToTCHARz (/+getCodePage (),+/ string); OS.SetWindowText (handle, buffer); } } @@ -241,15 +238,15 @@ public Rectangle getClientArea () { checkWidget (); forceResize (); - RECT rect = new RECT (); - OS.GetClientRect (handle, rect); - int newFont, oldFont = 0; - int hDC = OS.GetDC (handle); - newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); - if (newFont !is 0) oldFont = OS.SelectObject (hDC, newFont); - TEXTMETRIC tm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW () : new TEXTMETRICA (); - OS.GetTextMetrics (hDC, tm); - if (newFont !is 0) OS.SelectObject (hDC, oldFont); + RECT rect; + OS.GetClientRect (handle, &rect); + HFONT newFont, oldFont; + auto hDC = OS.GetDC (handle); + newFont = cast(HFONT) OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); + if (newFont !is null) oldFont = OS.SelectObject (hDC, newFont); + TEXTMETRIC tm; + OS.GetTextMetrics (hDC, &tm); + if (newFont !is null) OS.SelectObject (hDC, oldFont); OS.ReleaseDC (handle, hDC); int x = CLIENT_INSET, y = tm.tmHeight; int width = Math.max (0, rect.right - CLIENT_INSET * 2); @@ -257,7 +254,7 @@ return new Rectangle (x, y, width, height); } -String getNameText () { +char[] getNameText () { return getText (); } @@ -273,19 +270,19 @@ *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • * */ -public String getText () { +public char[] getText () { checkWidget (); return text; } -bool mnemonicHit (char key) { +bool mnemonicHit (wchar key) { return setFocus (); } -bool mnemonicMatch (char key) { - char mnemonic = findMnemonic (getText ()); +bool mnemonicMatch (wchar key) { + wchar mnemonic = findMnemonic (getText ()); if (mnemonic is '\0') return false; - return Character.toUpperCase (key) is Character.toUpperCase (mnemonic); + return CharacterToUpper (key) is CharacterToUpper (mnemonic); } void releaseWidget () { @@ -298,7 +295,7 @@ Rectangle oldRect = getClientArea (); super.setFont (font); Rectangle newRect = getClientArea (); - if (!oldRect.equals (newRect)) sendResize (); + if (oldRect!=newRect) sendResize (); } /** @@ -325,7 +322,7 @@ *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • * */ -public void setText (String string) { +public void setText (char[] string) { checkWidget (); if (string is null) error (DWT.ERROR_NULL_ARGUMENT); text = string; @@ -337,11 +334,11 @@ if ((style & DWT.RIGHT_TO_LEFT) !is 0) { if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) { if (!OS.IsWindowEnabled (handle)) { - if (string.length() !is 0) string = " " + string + " "; + if (string.length !is 0) string = " " ~ string ~ " "; } } } - TCHAR buffer = new TCHAR (getCodePage (), string, true); + TCHAR* buffer = StrToTCHARz(/+getCodePage (),+/ string); OS.SetWindowText (handle, buffer); } @@ -360,29 +357,29 @@ return super.widgetStyle () | OS.BS_GROUPBOX | OS.WS_CLIPCHILDREN | OS.WS_CLIPSIBLINGS; } -TCHAR windowClass () { - return GroupClass; +char[] windowClass () { + return TCHARsToStr( GroupClass ); } int windowProc () { - return GroupProc; + return cast(int) GroupProc; } LRESULT WM_ERASEBKGND (int wParam, int lParam) { LRESULT result = super.WM_ERASEBKGND (wParam, lParam); - if (result !is null) return result; + if (result !is LRESULT.NULL) return result; /* * Feature in Windows. Group boxes do not erase * the background before drawing. The fix is to * fill the background. */ - drawBackground (wParam); + drawBackground (cast(HANDLE) wParam); return LRESULT.ONE; } LRESULT WM_NCHITTEST (int wParam, int lParam) { LRESULT result = super.WM_NCHITTEST (wParam, lParam); - if (result !is null) return result; + if (result !is LRESULT.NULL) return result; /* * Feature in Windows. The window proc for the group box * returns HTTRANSPARENT indicating that mouse messages @@ -394,12 +391,12 @@ */ int code = callWindowProc (handle, OS.WM_NCHITTEST, wParam, lParam); if (code is OS.HTTRANSPARENT) code = OS.HTCLIENT; - return new LRESULT (code); + return cast(LRESULT) (code); } LRESULT WM_MOUSEMOVE (int wParam, int lParam) { LRESULT result = super.WM_MOUSEMOVE (wParam, lParam); - if (result !is null) return result; + if (result !is LRESULT.NULL) return result; /* * Feature in Windows. In version 6.00 of COMCTL32.DLL, * every time the mouse moves, the group title redraws. @@ -411,7 +408,7 @@ LRESULT WM_PRINTCLIENT (int wParam, int lParam) { LRESULT result = super.WM_PRINTCLIENT (wParam, lParam); - if (result !is null) return result; + if (result !is LRESULT.NULL) return result; /* * Feature in Windows. In version 6.00 of COMCTL32.DLL, * when WM_PRINTCLIENT is sent from a child BS_GROUP @@ -423,17 +420,17 @@ * and restore the current font. */ if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) { - int nSavedDC = OS.SaveDC (wParam); + auto nSavedDC = OS.SaveDC (cast(HDC)wParam); int code = callWindowProc (handle, OS.WM_PRINTCLIENT, wParam, lParam); - OS.RestoreDC (wParam, nSavedDC); - return new LRESULT (code); + OS.RestoreDC (cast(HDC)wParam, nSavedDC); + return cast(LRESULT) (code); } return result; } LRESULT WM_UPDATEUISTATE (int wParam, int lParam) { LRESULT result = super.WM_UPDATEUISTATE (wParam, lParam); - if (result !is null) return result; + if (result !is LRESULT.NULL) return result; /* * Feature in Windows. When WM_UPDATEUISTATE is sent to * a group, it sends WM_CTLCOLORBTN to get the foreground @@ -454,14 +451,14 @@ if (redraw) { OS.InvalidateRect (handle, null, false); int code = OS.DefWindowProc (handle, OS.WM_UPDATEUISTATE, wParam, lParam); - return new LRESULT (code); + return cast(LRESULT) (code); } return result; } 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; /* * Invalidate the portion of the group widget that needs to * be redrawn. Note that for some reason, invalidating the @@ -470,17 +467,17 @@ */ if (OS.IsWinCE) return result; if (!OS.IsWindowVisible (handle)) 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 rect = new RECT (); - OS.SetRect (rect, 0, 0, lpwp.cx, lpwp.cy); - OS.SendMessage (handle, OS.WM_NCCALCSIZE, 0, rect); + RECT rect; + OS.SetRect (&rect, 0, 0, lpwp.cx, lpwp.cy); + OS.SendMessage (handle, OS.WM_NCCALCSIZE, 0, &rect); int newWidth = rect.right - rect.left; int newHeight = rect.bottom - rect.top; - OS.GetClientRect (handle, rect); + OS.GetClientRect (handle, &rect); int oldWidth = rect.right - rect.left; int oldHeight = rect.bottom - rect.top; if (newWidth is oldWidth && newHeight is oldHeight) { @@ -489,17 +486,16 @@ if (newWidth !is oldWidth) { int left = oldWidth; if (newWidth < oldWidth) left = newWidth; - OS.SetRect (rect, left - CLIENT_INSET, 0, newWidth, newHeight); - OS.InvalidateRect (handle, rect, true); + OS.SetRect (&rect, left - CLIENT_INSET, 0, newWidth, newHeight); + OS.InvalidateRect (handle, &rect, true); } if (newHeight !is oldHeight) { int bottom = oldHeight; if (newHeight < oldHeight) bottom = newHeight; if (newWidth < oldWidth) oldWidth -= CLIENT_INSET; - OS.SetRect (rect, 0, bottom - CLIENT_INSET, oldWidth, newHeight); - OS.InvalidateRect (handle, rect, true); + OS.SetRect (&rect, 0, bottom - CLIENT_INSET, oldWidth, newHeight); + OS.InvalidateRect (handle, &rect, true); } return result; } } -++/ \ No newline at end of file