Changeset 41:f871c501e610
- Timestamp:
- 02/01/08 16:10:37
(1 year ago)
- Author:
- Frank Benoit <benoit@tionex.de>
- branch:
- default
- Message:
Button
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r40 |
r41 |
|
| 1256 | 1256 | public static const int OBJ_FONT = 0x6; |
|---|
| 1257 | 1257 | public static const int OBJ_PEN = 0x1; |
|---|
| 1258 | | public static const int OBM_CHECKBOXES = 0x7ff7; |
|---|
| | 1258 | public static const TCHAR* OBM_CHECKBOXES = cast(TCHAR*)0x7ff7; |
|---|
| 1259 | 1259 | public static const int ODS_SELECTED = 0x1; |
|---|
| 1260 | 1260 | public static const int ODT_MENU = 0x1; |
|---|
| r33 |
r41 |
|
| 29 | 29 | } |
|---|
| 30 | 30 | |
|---|
| | 31 | struct BUTTON_IMAGELIST { |
|---|
| | 32 | HIMAGELIST himl; |
|---|
| | 33 | RECT margin; |
|---|
| | 34 | UINT uAlign; |
|---|
| | 35 | } |
|---|
| | 36 | |
|---|
| 31 | 37 | alias HANDLE HTHEME; |
|---|
| 32 | 38 | |
|---|
| 33 | 39 | // .... |
|---|
| 34 | | |
|---|
| | 40 | //-------------------------------------------------------------------------------- |
|---|
| 35 | 41 | |
|---|
| 36 | 42 | const int LF_FACESIZE = 32; |
|---|
| r39 |
r41 |
|
| 13 | 13 | module dwt.widgets.Button; |
|---|
| 14 | 14 | |
|---|
| 15 | | import dwt.widgets.Control; |
|---|
| 16 | | |
|---|
| 17 | | class Button : Control{ |
|---|
| 18 | | void setDefault (bool value) ; |
|---|
| 19 | | void click () ; |
|---|
| 20 | | } |
|---|
| 21 | | |
|---|
| 22 | | /++ |
|---|
| | 15 | |
|---|
| | 16 | |
|---|
| 23 | 17 | import dwt.DWT; |
|---|
| 24 | 18 | import dwt.DWTException; |
|---|
| … | … | |
| 31 | 25 | import dwt.graphics.Rectangle; |
|---|
| 32 | 26 | import dwt.internal.ImageList; |
|---|
| 33 | | import dwt.internal.win32.BITMAP; |
|---|
| 34 | | import dwt.internal.win32.BUTTON_IMAGELIST; |
|---|
| 35 | | import dwt.internal.win32.DRAWITEMSTRUCT; |
|---|
| 36 | | import dwt.internal.win32.LRESULT; |
|---|
| 37 | 27 | import dwt.internal.win32.OS; |
|---|
| 38 | | import dwt.internal.win32.RECT; |
|---|
| 39 | | import dwt.internal.win32.SIZE; |
|---|
| 40 | | import dwt.internal.win32.TCHAR; |
|---|
| 41 | | import dwt.internal.win32.TEXTMETRIC; |
|---|
| 42 | | import dwt.internal.win32.TEXTMETRICA; |
|---|
| 43 | | import dwt.internal.win32.TEXTMETRICW; |
|---|
| 44 | | import dwt.internal.win32.WNDCLASS; |
|---|
| | 28 | |
|---|
| | 29 | import dwt.widgets.Control; |
|---|
| | 30 | import dwt.widgets.Composite; |
|---|
| | 31 | import dwt.widgets.TypedListener; |
|---|
| | 32 | |
|---|
| | 33 | import dwt.dwthelper.utils; |
|---|
| 45 | 34 | |
|---|
| 46 | 35 | /** |
|---|
| … | … | |
| 68 | 57 | */ |
|---|
| 69 | 58 | |
|---|
| 70 | | public class Button extends Control { |
|---|
| 71 | | String text = "", message = ""; |
|---|
| | 59 | public class Button : Control { |
|---|
| | 60 | alias extern(Windows) int function( HWND, uint, uint, int ) TWindowProc; |
|---|
| | 61 | char[] text = "", message = ""; |
|---|
| 72 | 62 | Image image, image2, disabledImage; |
|---|
| 73 | 63 | ImageList imageList; |
|---|
| 74 | 64 | bool ignoreMouse; |
|---|
| 75 | | static final int MARGIN = 4; |
|---|
| 76 | | static final int CHECK_WIDTH, CHECK_HEIGHT; |
|---|
| 77 | | static final int ICON_WIDTH = 128, ICON_HEIGHT = 128; |
|---|
| 78 | | static final bool COMMAND_LINK = false; |
|---|
| 79 | | static final int ButtonProc; |
|---|
| 80 | | static final TCHAR ButtonClass = new TCHAR (0, "BUTTON", true); |
|---|
| 81 | | static { |
|---|
| 82 | | int hBitmap = OS.LoadBitmap (0, OS.OBM_CHECKBOXES); |
|---|
| 83 | | if (hBitmap is 0) { |
|---|
| | 65 | static const int MARGIN = 4; |
|---|
| | 66 | static const int CHECK_WIDTH, CHECK_HEIGHT; |
|---|
| | 67 | static const int ICON_WIDTH = 128, ICON_HEIGHT = 128; |
|---|
| | 68 | static const bool COMMAND_LINK = false; |
|---|
| | 69 | static const TWindowProc ButtonProc; |
|---|
| | 70 | static const TCHAR[] ButtonClass = "BUTTON\0"; |
|---|
| | 71 | static this() { |
|---|
| | 72 | auto hBitmap = OS.LoadBitmap (null, OS.OBM_CHECKBOXES); |
|---|
| | 73 | if (hBitmap is null) { |
|---|
| 84 | 74 | CHECK_WIDTH = OS.GetSystemMetrics (OS.IsWinCE ? OS.SM_CXSMICON : OS.SM_CXVSCROLL); |
|---|
| 85 | 75 | CHECK_HEIGHT = OS.GetSystemMetrics (OS.IsWinCE ? OS.SM_CYSMICON : OS.SM_CYVSCROLL); |
|---|
| 86 | 76 | } else { |
|---|
| 87 | | BITMAP bitmap = new BITMAP (); |
|---|
| 88 | | OS.GetObject (hBitmap, BITMAP.sizeof, bitmap); |
|---|
| | 77 | BITMAP bitmap; |
|---|
| | 78 | OS.GetObject (hBitmap, BITMAP.sizeof, &bitmap); |
|---|
| 89 | 79 | OS.DeleteObject (hBitmap); |
|---|
| 90 | 80 | CHECK_WIDTH = bitmap.bmWidth / 4; |
|---|
| 91 | 81 | CHECK_HEIGHT = bitmap.bmHeight / 3; |
|---|
| 92 | 82 | } |
|---|
| 93 | | WNDCLASS lpWndClass = new WNDCLASS (); |
|---|
| 94 | | OS.GetClassInfo (0, ButtonClass, lpWndClass); |
|---|
| | 83 | WNDCLASS lpWndClass; |
|---|
| | 84 | OS.GetClassInfo (null, ButtonClass.ptr, &lpWndClass); |
|---|
| 95 | 85 | ButtonProc = lpWndClass.lpfnWndProc; |
|---|
| 96 | 86 | } |
|---|
| … | … | |
| 132 | 122 | * @see Widget#getStyle |
|---|
| 133 | 123 | */ |
|---|
| 134 | | public Button (Composite parent, int style) { |
|---|
| | 124 | public this (Composite parent, int style) { |
|---|
| 135 | 125 | super (parent, checkStyle (style)); |
|---|
| 136 | 126 | } |
|---|
| … | … | |
| 150 | 140 | imageList.add (disabledImage); |
|---|
| 151 | 141 | } |
|---|
| 152 | | BUTTON_IMAGELIST buttonImageList = new BUTTON_IMAGELIST (); |
|---|
| | 142 | BUTTON_IMAGELIST buttonImageList; |
|---|
| 153 | 143 | buttonImageList.himl = imageList.getHandle (); |
|---|
| 154 | 144 | int oldBits = OS.GetWindowLong (handle, OS.GWL_STYLE), newBits = oldBits; |
|---|
| … | … | |
| 157 | 147 | if ((style & DWT.CENTER) !is 0) newBits |= OS.BS_CENTER; |
|---|
| 158 | 148 | if ((style & DWT.RIGHT) !is 0) newBits |= OS.BS_RIGHT; |
|---|
| 159 | | if (text.length () is 0) { |
|---|
| | 149 | if (text.length is 0) { |
|---|
| 160 | 150 | if ((style & DWT.LEFT) !is 0) buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_LEFT; |
|---|
| 161 | 151 | if ((style & DWT.CENTER) !is 0) buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_CENTER; |
|---|
| … | … | |
| 163 | 153 | } else { |
|---|
| 164 | 154 | buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_LEFT; |
|---|
| 165 | | buttonImageList.margin_left = computeLeftMargin (); |
|---|
| 166 | | buttonImageList.margin_right = MARGIN; |
|---|
| | 155 | buttonImageList.margin.left = computeLeftMargin (); |
|---|
| | 156 | buttonImageList.margin.right = MARGIN; |
|---|
| 167 | 157 | newBits &= ~(OS.BS_CENTER | OS.BS_RIGHT); |
|---|
| 168 | 158 | newBits |= OS.BS_LEFT; |
|---|
| … | … | |
| 172 | 162 | OS.InvalidateRect (handle, null, true); |
|---|
| 173 | 163 | } |
|---|
| 174 | | OS.SendMessage (handle, OS.BCM_SETIMAGELIST, 0, buttonImageList); |
|---|
| | 164 | OS.SendMessage (handle, OS.BCM_SETIMAGELIST, 0, &buttonImageList); |
|---|
| 175 | 165 | } else { |
|---|
| 176 | 166 | OS.SendMessage (handle, OS.BCM_SETIMAGELIST, 0, 0); |
|---|
| … | … | |
| 185 | 175 | if (image2 !is null) image2.dispose (); |
|---|
| 186 | 176 | image2 = null; |
|---|
| 187 | | int hImage = 0, imageBits = 0, fImageType = 0; |
|---|
| | 177 | HBITMAP hImage; |
|---|
| | 178 | int imageBits = 0, fImageType = 0; |
|---|
| 188 | 179 | if (image !is null) { |
|---|
| 189 | 180 | switch (image.type) { |
|---|
| … | … | |
| 235 | 226 | if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (4, 10)) { |
|---|
| 236 | 227 | Rectangle rect = image.getBounds (); |
|---|
| 237 | | int hDC = OS.GetDC (handle); |
|---|
| 238 | | int dstHdc = OS.CreateCompatibleDC (hDC); |
|---|
| 239 | | int hBitmap = OS.CreateCompatibleBitmap (hDC, rect.width, rect.height); |
|---|
| 240 | | int oldBitmap = OS.SelectObject (dstHdc, hBitmap); |
|---|
| | 228 | auto hDC = OS.GetDC (handle); |
|---|
| | 229 | auto dstHdc = OS.CreateCompatibleDC (hDC); |
|---|
| | 230 | auto hBitmap = OS.CreateCompatibleBitmap (hDC, rect.width, rect.height); |
|---|
| | 231 | auto oldBitmap = OS.SelectObject (dstHdc, hBitmap); |
|---|
| 241 | 232 | OS.SetLayout (dstHdc, OS.LAYOUT_RTL); |
|---|
| 242 | 233 | if (fImageType is OS.IMAGE_BITMAP) { |
|---|
| 243 | | int srcHdc = OS.CreateCompatibleDC (hDC); |
|---|
| 244 | | int oldSrcBitmap = OS.SelectObject (srcHdc, hImage); |
|---|
| | 234 | auto srcHdc = OS.CreateCompatibleDC (hDC); |
|---|
| | 235 | auto oldSrcBitmap = OS.SelectObject (srcHdc, hImage); |
|---|
| 245 | 236 | OS.SetLayout (dstHdc, 0); |
|---|
| 246 | 237 | OS.BitBlt (dstHdc, 0, 0, rect.width, rect.height, srcHdc, 0, 0, OS.SRCCOPY); |
|---|
| … | … | |
| 250 | 241 | Control control = findBackgroundControl (); |
|---|
| 251 | 242 | if (control is null) control = this; |
|---|
| 252 | | int newBrush = OS.CreateSolidBrush (control.getBackgroundPixel ()); |
|---|
| 253 | | int oldBrush = OS.SelectObject (dstHdc, newBrush); |
|---|
| | 243 | auto newBrush = OS.CreateSolidBrush (control.getBackgroundPixel ()); |
|---|
| | 244 | auto oldBrush = OS.SelectObject (dstHdc, newBrush); |
|---|
| 254 | 245 | OS.PatBlt (dstHdc, 0, 0, rect.width, rect.height, OS.PATCOPY); |
|---|
| 255 | | OS.DrawIconEx (dstHdc, 0, 0, hImage, 0, 0, 0, 0, OS.DI_NORMAL); |
|---|
| | 246 | OS.DrawIconEx (dstHdc, 0, 0, hImage, 0, 0, 0, null, OS.DI_NORMAL); |
|---|
| 256 | 247 | OS.SelectObject (dstHdc, oldBrush); |
|---|
| 257 | 248 | OS.DeleteObject (newBrush); |
|---|
| … | … | |
| 276 | 267 | } |
|---|
| 277 | 268 | |
|---|
| 278 | | void _setText (String text) { |
|---|
| | 269 | void _setText (char[] text) { |
|---|
| 279 | 270 | int oldBits = OS.GetWindowLong (handle, OS.GWL_STYLE), newBits = oldBits; |
|---|
| 280 | 271 | if (OS.COMCTL32_MAJOR >= 6) { |
|---|
| … | … | |
| 284 | 275 | if ((style & DWT.RIGHT) !is 0) newBits |= OS.BS_RIGHT; |
|---|
| 285 | 276 | if (imageList !is null) { |
|---|
| 286 | | BUTTON_IMAGELIST buttonImageList = new BUTTON_IMAGELIST (); |
|---|
| | 277 | BUTTON_IMAGELIST buttonImageList; |
|---|
| 287 | 278 | buttonImageList.himl = imageList.getHandle (); |
|---|
| 288 | | if (text.length () is 0) { |
|---|
| | 279 | if (text.length is 0) { |
|---|
| 289 | 280 | if ((style & DWT.LEFT) !is 0) buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_LEFT; |
|---|
| 290 | 281 | if ((style & DWT.CENTER) !is 0) buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_CENTER; |
|---|
| … | … | |
| 292 | 283 | } else { |
|---|
| 293 | 284 | buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_LEFT; |
|---|
| 294 | | buttonImageList.margin_left = computeLeftMargin (); |
|---|
| 295 | | buttonImageList.margin_right = MARGIN; |
|---|
| | 285 | buttonImageList.margin.left = computeLeftMargin (); |
|---|
| | 286 | buttonImageList.margin.right = MARGIN; |
|---|
| 296 | 287 | newBits &= ~(OS.BS_CENTER | OS.BS_RIGHT); |
|---|
| 297 | 288 | newBits |= OS.BS_LEFT; |
|---|
| 298 | 289 | } |
|---|
| 299 | | OS.SendMessage (handle, OS.BCM_SETIMAGELIST, 0, buttonImageList); |
|---|
| | 290 | OS.SendMessage (handle, OS.BCM_SETIMAGELIST, 0, &buttonImageList); |
|---|
| 300 | 291 | } |
|---|
| 301 | 292 | } else { |
|---|
| … | … | |
| 313 | 304 | if ((style & DWT.RIGHT_TO_LEFT) !is 0) { |
|---|
| 314 | 305 | if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) { |
|---|
| 315 | | text = OS.IsWindowEnabled (handle) ? text : " " + text + " "; |
|---|
| 316 | | } |
|---|
| 317 | | } |
|---|
| 318 | | TCHAR buffer = new TCHAR (getCodePage (), text, true); |
|---|
| | 306 | text = OS.IsWindowEnabled (handle) ? text : " " ~ text ~ " "; |
|---|
| | 307 | } |
|---|
| | 308 | } |
|---|
| | 309 | TCHAR* buffer = StrToTCHARz ( text ); |
|---|
| 319 | 310 | OS.SetWindowText (handle, buffer); |
|---|
| 320 | 311 | } |
|---|
| … | … | |
| 352 | 343 | } |
|---|
| 353 | 344 | |
|---|
| 354 | | int callWindowProc (int hwnd, int msg, int wParam, int lParam) { |
|---|
| 355 | | if (handle is 0) return 0; |
|---|
| 356 | | return OS.CallWindowProc (ButtonProc, hwnd, msg, wParam, lParam); |
|---|
| | 345 | override LRESULT callWindowProc (HWND hwnd, int msg, int wParam, int lParam) { |
|---|
| | 346 | if (handle is null) return LRESULT.ZERO; |
|---|
| | 347 | return cast(LRESULT) ButtonProc( hwnd, msg, wParam, lParam); |
|---|
| 357 | 348 | } |
|---|
| 358 | 349 | |
|---|
| … | … | |
| 388 | 379 | if ((style & (DWT.PUSH | DWT.TOGGLE)) is 0) return MARGIN; |
|---|
| 389 | 380 | int margin = 0; |
|---|
| 390 | | if (image !is null && text.length () !is 0) { |
|---|
| | 381 | if (image !is null && text.length !is 0) { |
|---|
| 391 | 382 | Rectangle bounds = image.getBounds (); |
|---|
| 392 | 383 | margin += bounds.width + MARGIN * 2; |
|---|
| 393 | | int oldFont = 0; |
|---|
| 394 | | int hDC = OS.GetDC (handle); |
|---|
| 395 | | int newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); |
|---|
| 396 | | if (newFont !is 0) oldFont = OS.SelectObject (hDC, newFont); |
|---|
| 397 | | TCHAR buffer = new TCHAR (getCodePage (), text, true); |
|---|
| 398 | | RECT rect = new RECT (); |
|---|
| | 384 | HFONT oldFont; |
|---|
| | 385 | auto hDC = OS.GetDC (handle); |
|---|
| | 386 | HFONT newFont = cast(HFONT) OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); |
|---|
| | 387 | if (newFont !is null) oldFont = OS.SelectObject (hDC, newFont); |
|---|
| | 388 | TCHAR* buffer = StrToTCHARz(text); |
|---|
| | 389 | RECT rect; |
|---|
| 399 | 390 | int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE; |
|---|
| 400 | | OS.DrawText (hDC, buffer, -1, rect, flags); |
|---|
| | 391 | OS.DrawText (hDC, buffer, -1, &rect, flags); |
|---|
| 401 | 392 | margin += rect.right - rect.left; |
|---|
| 402 | | if (newFont !is 0) OS.SelectObject (hDC, oldFont); |
|---|
| | 393 | if (newFont !is null) OS.SelectObject (hDC, oldFont); |
|---|
| 403 | 394 | OS.ReleaseDC (handle, hDC); |
|---|
| 404 | | OS.GetClientRect (handle, rect); |
|---|
| | 395 | OS.GetClientRect (handle, &rect); |
|---|
| 405 | 396 | margin = Math.max (MARGIN, (rect.right - rect.left - margin) / 2); |
|---|
| 406 | 397 | } |
|---|
| … | … | |
| 421 | 412 | } else { |
|---|
| 422 | 413 | if ((style & DWT.COMMAND) !is 0) { |
|---|
| 423 | | SIZE size = new SIZE (); |
|---|
| | 414 | SIZE size; |
|---|
| 424 | 415 | if (wHint !is DWT.DEFAULT) { |
|---|
| 425 | 416 | size.cx = wHint; |
|---|
| 426 | | OS.SendMessage (handle, OS.BCM_GETIDEALSIZE, 0, size); |
|---|
| | 417 | OS.SendMessage (handle, OS.BCM_GETIDEALSIZE, 0, &size); |
|---|
| 427 | 418 | width = size.cx; |
|---|
| 428 | 419 | height = size.cy; |
|---|
| 429 | 420 | } else { |
|---|
| 430 | | OS.SendMessage (handle, OS.BCM_GETIDEALSIZE, 0, size); |
|---|
| | 421 | OS.SendMessage (handle, OS.BCM_GETIDEALSIZE, 0, &size); |
|---|
| 431 | 422 | width = size.cy; |
|---|
| 432 | 423 | height = size.cy; |
|---|
| … | … | |
| 435 | 426 | size.cx = width++; |
|---|
| 436 | 427 | size.cy = 0; |
|---|
| 437 | | OS.SendMessage (handle, OS.BCM_GETIDEALSIZE, 0, size); |
|---|
| | 428 | OS.SendMessage (handle, OS.BCM_GETIDEALSIZE, 0, &size); |
|---|
| 438 | 429 | } |
|---|
| 439 | 430 | } |
|---|
| … | … | |
| 452 | 443 | Rectangle rect = image.getBounds (); |
|---|
| 453 | 444 | width = rect.width; |
|---|
| 454 | | if (hasText && text.length () !is 0) { |
|---|
| | 445 | if (hasText && text.length !is 0) { |
|---|
| 455 | 446 | width += MARGIN * 2; |
|---|
| 456 | 447 | } |
|---|
| … | … | |
| 460 | 451 | } |
|---|
| 461 | 452 | if (hasText) { |
|---|
| 462 | | int oldFont = 0; |
|---|
| 463 | | int hDC = OS.GetDC (handle); |
|---|
| 464 | | int newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); |
|---|
| 465 | | if (newFont !is 0) oldFont = OS.SelectObject (hDC, newFont); |
|---|
| 466 | | TEXTMETRIC lptm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW () : new TEXTMETRICA (); |
|---|
| 467 | | OS.GetTextMetrics (hDC, lptm); |
|---|
| 468 | | int length = text.length (); |
|---|
| 469 | | if (length is 0) { |
|---|
| | 453 | HFONT oldFont; |
|---|
| | 454 | auto hDC = OS.GetDC (handle); |
|---|
| | 455 | auto newFont = cast(HFONT) OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); |
|---|
| | 456 | if (newFont !is null) oldFont = OS.SelectObject (hDC, newFont); |
|---|
| | 457 | TEXTMETRIC lptm; |
|---|
| | 458 | OS.GetTextMetrics (hDC, &lptm); |
|---|
| | 459 | int length_ = text.length; |
|---|
| | 460 | if (length_ is 0) { |
|---|
| 470 | 461 | height = Math.max (height, lptm.tmHeight); |
|---|
| 471 | 462 | } else { |
|---|
| 472 | 463 | extra = Math.max (MARGIN * 2, lptm.tmAveCharWidth); |
|---|
| 473 | | TCHAR buffer = new TCHAR (getCodePage (), text, true); |
|---|
| 474 | | RECT rect = new RECT (); |
|---|
| | 464 | TCHAR* buffer = StrToTCHARz(text); |
|---|
| | 465 | RECT rect; |
|---|
| 475 | 466 | int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE; |
|---|
| 476 | | OS.DrawText (hDC, buffer, -1, rect, flags); |
|---|
| | 467 | OS.DrawText (hDC, buffer, -1, &rect, flags); |
|---|
| 477 | 468 | width += rect.right - rect.left; |
|---|
| 478 | 469 | height = Math.max (height, rect.bottom - rect.top); |
|---|
| 479 | 470 | } |
|---|
| 480 | | if (newFont !is 0) OS.SelectObject (hDC, oldFont); |
|---|
| | 471 | if (newFont !is null) OS.SelectObject (hDC, oldFont); |
|---|
| 481 | 472 | OS.ReleaseDC (handle, hDC); |
|---|
| 482 | 473 | } |
|---|
| … | … | |
| 540 | 531 | bool hasImage = (bits & (OS.BS_BITMAP | OS.BS_ICON)) !is 0; |
|---|
| 541 | 532 | if (!hasImage) { |
|---|
| 542 | | String string = enabled ? text : " " + text + " "; |
|---|
| 543 | | TCHAR buffer = new TCHAR (getCodePage (), string, true); |
|---|
| | 533 | char[] string = enabled ? text : " " ~ text ~ " "; |
|---|
| | 534 | TCHAR* buffer = StrToTCHARz (string); |
|---|
| 544 | 535 | OS.SetWindowText (handle, buffer); |
|---|
| 545 | 536 | } |
|---|
| … | … | |
| 558 | 549 | if (OS.COMCTL32_MAJOR >= 6) { |
|---|
| 559 | 550 | if (imageList !is null) { |
|---|
| 560 | | BUTTON_IMAGELIST buttonImageList = new BUTTON_IMAGELIST (); |
|---|
| 561 | | OS.SendMessage (handle, OS.BCM_GETIMAGELIST, 0, buttonImageList); |
|---|
| | 551 | BUTTON_IMAGELIST buttonImageList; |
|---|
| | 552 | OS.SendMessage (handle, OS.BCM_GETIMAGELIST, 0, &buttonImageList); |
|---|
| 562 | 553 | if (imageList !is null) imageList.dispose (); |
|---|
| 563 | 554 | imageList = new ImageList (style & DWT.RIGHT_TO_LEFT); |
|---|
| … | … | |
| 570 | 561 | } |
|---|
| 571 | 562 | buttonImageList.himl = imageList.getHandle (); |
|---|
| 572 | | OS.SendMessage (handle, OS.BCM_SETIMAGELIST, 0, buttonImageList); |
|---|
| | 563 | OS.SendMessage (handle, OS.BCM_SETIMAGELIST, 0, &buttonImageList); |
|---|
| 573 | 564 | /* |
|---|
| 574 | 565 | * Bug in Windows. Under certain cirumstances yet to be |
|---|
| … | … | |
| 648 | 639 | * @since 3.3 |
|---|
| 649 | 640 | */ |
|---|
| 650 | | /*public*/ String getMessage () { |
|---|
| | 641 | /*public*/ char[] getMessage () { |
|---|
| 651 | 642 | checkWidget (); |
|---|
| 652 | 643 | return message; |
|---|
| 653 | 644 | } |
|---|
| 654 | 645 | |
|---|
| 655 | | String getNameText () { |
|---|
| | 646 | char[] getNameText () { |
|---|
| 656 | 647 | return getText (); |
|---|
| 657 | 648 | } |
|---|
| … | … | |
| 692 | 683 | * </ul> |
|---|
| 693 | 684 | */ |
|---|
| 694 | | public String getText () { |
|---|
| | 685 | public char[] getText () { |
|---|
| 695 | 686 | checkWidget (); |
|---|
| 696 | 687 | if ((style & DWT.ARROW) !is 0) return ""; |
|---|
| … | … | |
| 704 | 695 | } |
|---|
| 705 | 696 | |
|---|
| 706 | | bool mnemonicHit (char ch) { |
|---|
| | 697 | bool mnemonicHit (wchar ch) { |
|---|
| 707 | 698 | if (!setFocus ()) return false; |
|---|
| 708 | 699 | /* |
|---|
| … | … | |
| 716 | 707 | } |
|---|
| 717 | 708 | |
|---|
| 718 | | bool mnemonicMatch (char key) { |
|---|
| 719 | | char mnemonic = findMnemonic (getText ()); |
|---|
| | 709 | bool mnemonicMatch (wchar key) { |
|---|
| | 710 | wchar mnemonic = findMnemonic (getText ()); |
|---|
| 720 | 711 | if (mnemonic is '\0') return false; |
|---|
| 721 | | return Character.toUpperCase (key) is Character.toUpperCase (mnemonic); |
|---|
| | 712 | return CharacterToUpper (key) is CharacterToUpper (mnemonic); |
|---|
| 722 | 713 | } |
|---|
| 723 | 714 | |
|---|
| … | … | |
| 819 | 810 | if (OS.COMCTL32_MAJOR >= 6) { |
|---|
| 820 | 811 | if (imageList !is null) { |
|---|
| 821 | | BUTTON_IMAGELIST buttonImageList = new BUTTON_IMAGELIST (); |
|---|
| | 812 | BUTTON_IMAGELIST buttonImageList; |
|---|
| 822 | 813 | buttonImageList.himl = imageList.getHandle (); |
|---|
| 823 | | if (text.length () is 0) { |
|---|
| | 814 | if (text.length is 0) { |
|---|
| 824 | 815 | if ((style & DWT.LEFT) !is 0) buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_LEFT; |
|---|
| 825 | 816 | if ((style & DWT.CENTER) !is 0) buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_CENTER; |
|---|
| … | … | |
| 827 | 818 | } else { |
|---|
| 828 | 819 | buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_LEFT; |
|---|
| 829 | | buttonImageList.margin_left = computeLeftMargin (); |
|---|
| 830 | | buttonImageList.margin_right = MARGIN; |
|---|
| | 820 | buttonImageList.margin.left = computeLeftMargin (); |
|---|
| | 821 | buttonImageList.margin.right = MARGIN; |
|---|
| 831 | 822 | newBits &= ~(OS.BS_CENTER | OS.BS_RIGHT); |
|---|
| 832 | 823 | newBits |= OS.BS_LEFT; |
|---|
| 833 | 824 | } |
|---|
| 834 | | OS.SendMessage (handle, OS.BCM_SETIMAGELIST, 0, buttonImageList); |
|---|
| | 825 | OS.SendMessage (handle, OS.BCM_SETIMAGELIST, 0, &buttonImageList); |
|---|
| 835 | 826 | } |
|---|
| 836 | 827 | } |
|---|
| … | … | |
| 843 | 834 | void setDefault (bool value) { |
|---|
| 844 | 835 | if ((style & DWT.PUSH) is 0) return; |
|---|
| 845 | | int hwndShell = menuShell ().handle; |
|---|
| | 836 | auto hwndShell = menuShell ().handle; |
|---|
| 846 | 837 | int bits = OS.GetWindowLong (handle, OS.GWL_STYLE); |
|---|
| 847 | 838 | if (value) { |
|---|
| … | … | |
| 891 | 882 | /* This code is intentionally commented */ |
|---|
| 892 | 883 | // if (OS.COMCTL32_MAJOR < 6) { |
|---|
| 893 | | // if (image is null || text.length () !is 0) { |
|---|
| | 884 | // if (image is null || text.length !is 0) { |
|---|
| 894 | 885 | // _setText (text); |
|---|
| 895 | 886 | // return; |
|---|
| … | … | |
| 916 | 907 | * @since 3.3 |
|---|
| 917 | 908 | */ |
|---|
| 918 | | /*public*/ void setMessage (String message) { |
|---|
| | 909 | /*public*/ void setMessage (char[] message) { |
|---|
| 919 | 910 | checkWidget (); |
|---|
| 920 | 911 | if (message is null) error (DWT.ERROR_NULL_ARGUMENT); |
|---|
| … | … | |
| 922 | 913 | if (OS.COMCTL32_VERSION >= OS.VERSION (6, 1)) { |
|---|
| 923 | 914 | if ((style & DWT.COMMAND) !is 0) { |
|---|
| 924 | | int length = message.length (); |
|---|
| 925 | | char [] chars = new char [length + 1]; |
|---|
| 926 | | message.getChars(0, length, chars, 0); |
|---|
| 927 | | OS.SendMessage (handle, OS.BCM_SETNOTE, 0, chars); |
|---|
| | 915 | OS.SendMessage (handle, OS.BCM_SETNOTE, 0, StrToTCHARz( message )); |
|---|
| 928 | 916 | } |
|---|
| 929 | 917 | } |
|---|
| … | … | |
| 1020 | 1008 | * </ul> |
|---|
| 1021 | 1009 | */ |
|---|
| 1022 | | public void setText (String string) { |
|---|
| | 1010 | public void setText (char[] string) { |
|---|
| 1023 | 1011 | checkWidget (); |
|---|
| 1024 | 1012 | if (string is null) error (DWT.ERROR_NULL_ARGUMENT); |
|---|
| … | … | |
| 1027 | 1015 | /* This code is intentionally commented */ |
|---|
| 1028 | 1016 | // if (OS.COMCTL32_MAJOR < 6) { |
|---|
| 1029 | | // if (text.length () is 0 && image !is null) { |
|---|
| | 1017 | // if (text.length is 0 && image !is null) { |
|---|
| 1030 | 1018 | // _setImage (image); |
|---|
| 1031 | 1019 | // return; |
|---|
| … | … | |
| 1050 | 1038 | } |
|---|
| 1051 | 1039 | |
|---|
| 1052 | | TCHAR windowClass () { |
|---|
| 1053 | | return ButtonClass; |
|---|
| | 1040 | char[] windowClass () { |
|---|
| | 1041 | return TCHARzToStr( ButtonClass.ptr ); |
|---|
| 1054 | 1042 | } |
|---|
| 1055 | 1043 | |
|---|
| 1056 | 1044 | int windowProc () { |
|---|
| 1057 | | return ButtonProc; |
|---|
| | 1045 | return cast(int) ButtonProc; |
|---|
| 1058 | 1046 | } |
|---|
| 1059 | 1047 | |
|---|
| … | … | |
| 1061 | 1049 | LRESULT WM_ERASEBKGND (int wParam, int lParam) { |
|---|
| 1062 | 1050 | LRESULT result = super.WM_ERASEBKGND (wParam, lParam); |
|---|
| 1063 | | if (result !is null) return result; |
|---|
| | 1051 | if (result !is LRESULT.NULL) return result; |
|---|
| 1064 | 1052 | /* |
|---|
| 1065 | 1053 | * Bug in Windows. For some reason, the HBRUSH that |
|---|
| … | … | |
| 1073 | 1061 | if ((style & (DWT.RADIO | DWT.CHECK)) !is 0) { |
|---|
| 1074 | 1062 | if (findImageControl () !is null) { |
|---|
| 1075 | | drawBackground (wParam); |
|---|
| | 1063 | drawBackground (cast(HWND)wParam); |
|---|
| 1076 | 1064 | return LRESULT.ONE; |
|---|
| 1077 | 1065 | } |
|---|
| … | … | |
| 1083 | 1071 | LRESULT WM_GETDLGCODE (int wParam, int lParam) { |
|---|
| 1084 | 1072 | LRESULT result = super.WM_GETDLGCODE (wParam, lParam); |
|---|
| 1085 | | if (result !is null) return result; |
|---|
| | 1073 | if (result !is LRESULT.NULL) return result; |
|---|
| 1086 | 1074 | if ((style & DWT.ARROW) !is 0) { |
|---|
| 1087 | | return new LRESULT (OS.DLGC_STATIC); |
|---|
| | 1075 | return cast( LRESULT )(OS.DLGC_STATIC); |
|---|
| 1088 | 1076 | } |
|---|
| 1089 | 1077 | return result; |
|---|
| … | … | |
| 1099 | 1087 | |
|---|
| 1100 | 1088 | LRESULT WM_LBUTTONDOWN (int wParam, int lParam) { |
|---|
| 1101 | | if (ignoreMouse) return null; |
|---|
| | 1089 | if (ignoreMouse) return LRESULT.NULL; |
|---|
| 1102 | 1090 | return super.WM_LBUTTONDOWN (wParam, lParam); |
|---|
| 1103 | 1091 | } |
|---|
| 1104 | 1092 | |
|---|
| 1105 | 1093 | LRESULT WM_LBUTTONUP (int wParam, int lParam) { |
|---|
| 1106 | | if (ignoreMouse) return null; |
|---|
| | 1094 | if (ignoreMouse) return LRESULT.NULL; |
|---|
| 1107 | 1095 | return super.WM_LBUTTONUP (wParam, lParam); |
|---|
| 1108 | 1096 | } |
|---|
| … | … | |
| 1131 | 1119 | LRESULT WM_SIZE (int wParam, int lParam) { |
|---|
| 1132 | 1120 | LRESULT result = super.WM_SIZE (wParam, lParam); |
|---|
| 1133 | | if (result !is null) return result; |
|---|
| | 1121 | if (result !is LRESULT.NULL) return result; |
|---|
| 1134 | 1122 | if (OS.COMCTL32_MAJOR >= 6) { |
|---|
| 1135 | 1123 | if ((style & (DWT.PUSH | DWT.TOGGLE)) !is 0) { |
|---|
| 1136 | | if (imageList !is null && text.length () !is 0) { |
|---|
| 1137 | | BUTTON_IMAGELIST buttonImageList = new BUTTON_IMAGELIST (); |
|---|
| 1138 | | OS.SendMessage (handle, OS.BCM_GETIMAGELIST, 0, buttonImageList); |
|---|
| | 1124 | if (imageList !is null && text.length !is 0) { |
|---|
| | 1125 | BUTTON_IMAGELIST buttonImageList; |
|---|
| | 1126 | OS.SendMessage (handle, OS.BCM_GETIMAGELIST, 0, &buttonImageList); |
|---|
| 1139 | 1127 | buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_LEFT; |
|---|
| 1140 | | buttonImageList.margin_left = computeLeftMargin (); |
|---|
| 1141 | | buttonImageList.margin_right = MARGIN; |
|---|
| 1142 | | OS.SendMessage (handle, OS.BCM_SETIMAGELIST, 0, buttonImageList); |
|---|
| | 1128 | buttonImageList.margin.left = computeLeftMargin (); |
|---|
| | 1129 | buttonImageList.margin.right = MARGIN; |
|---|
| | 1130 | OS.SendMessage (handle, OS.BCM_SETIMAGELIST, 0, &buttonImageList); |
|---|
| 1143 | 1131 | } |
|---|
| 1144 | 1132 | } |
|---|
| … | … | |
| 1149 | 1137 | LRESULT WM_SYSCOLORCHANGE (int wParam, int lParam) { |
|---|
| 1150 | 1138 | LRESULT result = super.WM_SYSCOLORCHANGE (wParam, lParam); |
|---|
| 1151 | | if (result !is null) return result; |
|---|
| | 1139 | if (result !is LRESULT.NULL) return result; |
|---|
| 1152 | 1140 | if (image2 !is null) _setImage (image); |
|---|
| 1153 | 1141 | return result; |
|---|
| … | … | |
| 1156 | 1144 | LRESULT WM_UPDATEUISTATE (int wParam, int lParam) { |
|---|
| 1157 | 1145 | LRESULT result = super.WM_UPDATEUISTATE (wParam, lParam); |
|---|
| 1158 | | if (result !is null) return result; |
|---|
| | 1146 | if (result !is LRESULT.NULL) return result; |
|---|
| 1159 | 1147 | /* |
|---|
| 1160 | 1148 | * Feature in Windows. When WM_UPDATEUISTATE is sent to |
|---|
| … | … | |
| 1182 | 1170 | OS.InvalidateRect (handle, null, false); |
|---|
| 1183 | 1171 | int code = OS.DefWindowProc (handle, OS.WM_UPDATEUISTATE, wParam, lParam); |
|---|
| 1184 | | return new LRESULT (code); |
|---|
| | 1172 | return cast( LRESULT )(code); |
|---|
| 1185 | 1173 | } |
|---|
| 1186 | 1174 | } |
|---|
| … | … | |
| 1223 | 1211 | if ((style & (DWT.RADIO | DWT.CHECK)) !is 0) { |
|---|
| 1224 | 1212 | if (findImageControl () !is null) { |
|---|
| 1225 | | OS.SetBkMode (wParam, OS.TRANSPARENT); |
|---|
| 1226 | | return new LRESULT (OS.GetStockObject (OS.NULL_BRUSH)); |
|---|
| | 1213 | OS.SetBkMode (cast(HANDLE)wParam, OS.TRANSPARENT); |
|---|
| | 1214 | return cast( LRESULT )(OS.GetStockObject (OS.NULL_BRUSH)); |
|---|
| 1227 | 1215 | } |
|---|
| 1228 | 1216 | } |
|---|
| … | … | |
| 1233 | 1221 | LRESULT wmDrawChild (int wParam, int lParam) { |
|---|
| 1234 | 1222 | if ((style & DWT.ARROW) is 0) return super.wmDrawChild (wParam, lParam); |
|---|
| 1235 | | DRAWITEMSTRUCT struct = new DRAWITEMSTRUCT (); |
|---|
| 1236 | | OS.MoveMemory (struct, lParam, DRAWITEMSTRUCT.sizeof); |
|---|
| 1237 | | RECT rect = new RECT (); |
|---|
| 1238 | | OS.SetRect (rect, struct.left, struct.top, struct.right, struct.bottom); |
|---|
| | 1223 | auto struct_ = cast(DRAWITEMSTRUCT*)lParam; |
|---|
| | 1224 | //OS.MoveMemory (struct_, lParam, DRAWITEMSTRUCT.sizeof); |
|---|
| | 1225 | RECT rect; |
|---|
| | 1226 | OS.SetRect (&rect, struct_.rcItem.left, struct_.rcItem.top, struct_.rcItem.right, struct_.rcItem.bottom); |
|---|
| 1239 | 1227 | if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) { |
|---|
| 1240 | 1228 | int iStateId = OS.ABS_LEFTNORMAL; |
|---|
| … | … | |
| 1251 | 1239 | */ |
|---|
| 1252 | 1240 | if (!getEnabled ()) iStateId += OS.ABS_UPDISABLED - OS.ABS_UPNORMAL; |
|---|
| 1253 | | if ((struct.itemState & OS.ODS_SELECTED) !is 0) iStateId += OS.ABS_UPPRESSED - OS.ABS_UPNORMAL; |
|---|
| 1254 | | OS.DrawThemeBackground (display.hScrollBarTheme (), struct.hDC, OS.SBP_ARROWBTN, iStateId, rect, null); |
|---|
| | 1241 | if ((struct_.itemState & OS.ODS_SELECTED) !is 0) iStateId += OS.ABS_UPPRESSED - OS.ABS_UPNORMAL; |
|---|
| | 1242 | OS.DrawThemeBackground (display.hScrollBarTheme (), struct_.hDC, OS.SBP_ARROWBTN, iStateId, &rect, null); |
|---|
| 1255 | 1243 | } else { |
|---|
| 1256 | 1244 | int uState = OS.DFCS_SCROLLLEFT; |
|---|
| … | … | |
| 1263 | 1251 | if (!getEnabled ()) uState |= OS.DFCS_INACTIVE; |
|---|
| 1264 | 1252 | if ((style & DWT.FLAT) is DWT.FLAT) uState |= OS.DFCS_FLAT; |
|---|
| 1265 | | if ((struct.itemState & OS.ODS_SELECTED) !is 0) uState |= OS.DFCS_PUSHED; |
|---|
| 1266 | | OS.DrawFrameControl (struct.hDC, rect, OS.DFC_SCROLL, uState); |
|---|
| 1267 | | } |
|---|
| 1268 | | return null; |
|---|
| 1269 | | } |
|---|
| 1270 | | |
|---|
| 1271 | | } |
|---|
| 1272 | | ++/ |
|---|
| | 1253 | if ((struct_.itemState & OS.ODS_SELECTED) !is 0) uState |= OS.DFCS_PUSHED; |
|---|
| | 1254 | OS.DrawFrameControl (struct_.hDC, &rect, OS.DFC_SCROLL, uState); |
|---|
| | 1255 | } |
|---|
| | 1256 | return LRESULT.NULL; |
|---|
| | 1257 | } |
|---|
| | 1258 | |
|---|
| | 1259 | } |
|---|