| 1 11 package org.eclipse.swt.widgets; 12 13 14 import org.eclipse.swt.internal.*; 15 import org.eclipse.swt.internal.win32.*; 16 import org.eclipse.swt.*; 17 import org.eclipse.swt.graphics.*; 18 import org.eclipse.swt.events.*; 19 20 43 44 public class Button extends Control { 45 String text = "", message = ""; 46 Image image, image2, disabledImage; 47 ImageList imageList; 48 boolean ignoreMouse; 49 static final int MARGIN = 4; 50 static final int CHECK_WIDTH, CHECK_HEIGHT; 51 static final int ICON_WIDTH = 128, ICON_HEIGHT = 128; 52 static final boolean COMMAND_LINK = false; 53 static final int ButtonProc; 54 static final TCHAR ButtonClass = new TCHAR (0, "BUTTON", true); 55 static { 56 int hBitmap = OS.LoadBitmap (0, OS.OBM_CHECKBOXES); 57 if (hBitmap == 0) { 58 CHECK_WIDTH = OS.GetSystemMetrics (OS.IsWinCE ? OS.SM_CXSMICON : OS.SM_CXVSCROLL); 59 CHECK_HEIGHT = OS.GetSystemMetrics (OS.IsWinCE ? OS.SM_CYSMICON : OS.SM_CYVSCROLL); 60 } else { 61 BITMAP bitmap = new BITMAP (); 62 OS.GetObject (hBitmap, BITMAP.sizeof, bitmap); 63 OS.DeleteObject (hBitmap); 64 CHECK_WIDTH = bitmap.bmWidth / 4; 65 CHECK_HEIGHT = bitmap.bmHeight / 3; 66 } 67 WNDCLASS lpWndClass = new WNDCLASS (); 68 OS.GetClassInfo (0, ButtonClass, lpWndClass); 69 ButtonProc = lpWndClass.lpfnWndProc; 70 } 71 72 108 public Button (Composite parent, int style) { 109 super (parent, checkStyle (style)); 110 } 111 112 void _setImage (Image image) { 113 if ((style & SWT.COMMAND) != 0) return; 114 if (OS.COMCTL32_MAJOR >= 6) { 115 if (imageList != null) imageList.dispose (); 116 imageList = null; 117 if (image != null) { 118 imageList = new ImageList (style & SWT.RIGHT_TO_LEFT); 119 if (OS.IsWindowEnabled (handle)) { 120 imageList.add (image); 121 } else { 122 if (disabledImage != null) disabledImage.dispose (); 123 disabledImage = new Image (display, image, SWT.IMAGE_DISABLE); 124 imageList.add (disabledImage); 125 } 126 BUTTON_IMAGELIST buttonImageList = new BUTTON_IMAGELIST (); 127 buttonImageList.himl = imageList.getHandle (); 128 int oldBits = OS.GetWindowLong (handle, OS.GWL_STYLE), newBits = oldBits; 129 newBits &= ~(OS.BS_LEFT | OS.BS_CENTER | OS.BS_RIGHT); 130 if ((style & SWT.LEFT) != 0) newBits |= OS.BS_LEFT; 131 if ((style & SWT.CENTER) != 0) newBits |= OS.BS_CENTER; 132 if ((style & SWT.RIGHT) != 0) newBits |= OS.BS_RIGHT; 133 if (text.length () == 0) { 134 if ((style & SWT.LEFT) != 0) buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_LEFT; 135 if ((style & SWT.CENTER) != 0) buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_CENTER; 136 if ((style & SWT.RIGHT) != 0) buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_RIGHT; 137 } else { 138 buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_LEFT; 139 buttonImageList.margin_left = computeLeftMargin (); 140 buttonImageList.margin_right = MARGIN; 141 newBits &= ~(OS.BS_CENTER | OS.BS_RIGHT); 142 newBits |= OS.BS_LEFT; 143 } 144 if (newBits != oldBits) { 145 OS.SetWindowLong (handle, OS.GWL_STYLE, newBits); 146 OS.InvalidateRect (handle, null, true); 147 } 148 OS.SendMessage (handle, OS.BCM_SETIMAGELIST, 0, buttonImageList); 149 } else { 150 OS.SendMessage (handle, OS.BCM_SETIMAGELIST, 0, 0); 151 } 152 157 OS.InvalidateRect (handle, null, true); 158 } else { 159 if (image2 != null) image2.dispose (); 160 image2 = null; 161 int hImage = 0, imageBits = 0, fImageType = 0; 162 if (image != null) { 163 switch (image.type) { 164 case SWT.BITMAP: { 165 Rectangle rect = image.getBounds (); 166 ImageData data = image.getImageData (); 167 switch (data.getTransparencyType ()) { 168 case SWT.TRANSPARENCY_PIXEL: 169 if (rect.width <= ICON_WIDTH && rect.height <= ICON_HEIGHT) { 170 image2 = new Image (display, data, data.getTransparencyMask ()); 171 hImage = image2.handle; 172 imageBits = OS.BS_ICON; 173 fImageType = OS.IMAGE_ICON; 174 break; 175 } 176 case SWT.TRANSPARENCY_ALPHA: 178 image2 = new Image (display, rect.width, rect.height); 179 GC gc = new GC (image2); 180 gc.setBackground (getBackground ()); 181 gc.fillRectangle (rect); 182 gc.drawImage (image, 0, 0); 183 gc.dispose (); 184 hImage = image2.handle; 185 imageBits = OS.BS_BITMAP; 186 fImageType = OS.IMAGE_BITMAP; 187 break; 188 case SWT.TRANSPARENCY_NONE: 189 hImage = image.handle; 190 imageBits = OS.BS_BITMAP; 191 fImageType = OS.IMAGE_BITMAP; 192 break; 193 } 194 break; 195 } 196 case SWT.ICON: { 197 hImage = image.handle; 198 imageBits = OS.BS_ICON; 199 fImageType = OS.IMAGE_ICON; 200 break; 201 } 202 } 203 208 if ((style & SWT.RIGHT_TO_LEFT) != 0) { 209 if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (4, 10)) { 210 Rectangle rect = image.getBounds (); 211 int hDC = OS.GetDC (handle); 212 int dstHdc = OS.CreateCompatibleDC (hDC); 213 int hBitmap = OS.CreateCompatibleBitmap (hDC, rect.width, rect.height); 214 int oldBitmap = OS.SelectObject (dstHdc, hBitmap); 215 OS.SetLayout (dstHdc, OS.LAYOUT_RTL); 216 if (fImageType == OS.IMAGE_BITMAP) { 217 int srcHdc = OS.CreateCompatibleDC (hDC); 218 int oldSrcBitmap = OS.SelectObject (srcHdc, hImage); 219 OS.SetLayout (dstHdc, 0); 220 OS.BitBlt (dstHdc, 0, 0, rect.width, rect.height, srcHdc, 0, 0, OS.SRCCOPY); 221 OS.SelectObject (srcHdc, oldSrcBitmap); 222 OS.DeleteDC (srcHdc); 223 } else { 224 Control control = findBackgroundControl (); 225 if (control == null) control = this; 226 int newBrush = OS.CreateSolidBrush (control.getBackgroundPixel ()); 227 int oldBrush = OS.SelectObject (dstHdc, newBrush); 228 OS.PatBlt (dstHdc, 0, 0, rect.width, rect.height, OS.PATCOPY); 229 OS.DrawIconEx (dstHdc, 0, 0, hImage, 0, 0, 0, 0, OS.DI_NORMAL); 230 OS.SelectObject (dstHdc, oldBrush); 231 OS.DeleteObject (newBrush); 232 } 233 OS.SelectObject (dstHdc, oldBitmap); 234 OS.DeleteDC (dstHdc); 235 OS.ReleaseDC (handle, hDC); 236 if (image2 != null) image2.dispose (); 237 image2 = Image.win32_new (display, SWT.BITMAP, hBitmap); 238 imageBits = OS.BS_BITMAP; 239 fImageType = OS.IMAGE_BITMAP; 240 hImage = hBitmap; 241 } 242 } 243 } 244 int newBits = OS.GetWindowLong (handle, OS.GWL_STYLE), oldBits = newBits; 245 newBits &= ~(OS.BS_BITMAP | OS.BS_ICON); 246 newBits |= imageBits; 247 if (newBits != oldBits) OS.SetWindowLong (handle, OS.GWL_STYLE, newBits); 248 OS.SendMessage (handle, OS.BM_SETIMAGE, fImageType, hImage); 249 } 250 } 251 252 void _setText (String text) { 253 int oldBits = OS.GetWindowLong (handle, OS.GWL_STYLE), newBits = oldBits; 254 if (OS.COMCTL32_MAJOR >= 6) { 255 newBits &= ~(OS.BS_LEFT | OS.BS_CENTER | OS.BS_RIGHT); 256 if ((style & SWT.LEFT) != 0) newBits |= OS.BS_LEFT; 257 if ((style & SWT.CENTER) != 0) newBits |= OS.BS_CENTER; 258 if ((style & SWT.RIGHT) != 0) newBits |= OS.BS_RIGHT; 259 if (imageList != null) { 260 BUTTON_IMAGELIST buttonImageList = new BUTTON_IMAGELIST (); 261 buttonImageList.himl = imageList.getHandle (); 262 if (text.length () == 0) { 263 if ((style & SWT.LEFT) != 0) buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_LEFT; 264 if ((style & SWT.CENTER) != 0) buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_CENTER; 265 if ((style & SWT.RIGHT) != 0) buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_RIGHT; 266 } else { 267 buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_LEFT; 268 buttonImageList.margin_left = computeLeftMargin (); 269 buttonImageList.margin_right = MARGIN; 270 newBits &= ~(OS.BS_CENTER | OS.BS_RIGHT); 271 newBits |= OS.BS_LEFT; 272 } 273 OS.SendMessage (handle, OS.BCM_SETIMAGELIST, 0, buttonImageList); 274 } 275 } else { 276 newBits &= ~(OS.BS_BITMAP | OS.BS_ICON); 277 } 278 if (newBits != oldBits) { 279 OS.SetWindowLong (handle, OS.GWL_STYLE, newBits); 280 OS.InvalidateRect (handle, null, true); 281 } 282 287 if ((style & SWT.RIGHT_TO_LEFT) != 0) { 288 if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) { 289 text = OS.IsWindowEnabled (handle) ? text : " " + text + " "; 290 } 291 } 292 TCHAR buffer = new TCHAR (getCodePage (), text, true); 293 OS.SetWindowText (handle, buffer); 294 } 295 296 320 public void addSelectionListener (SelectionListener listener) { 321 checkWidget (); 322 if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); 323 TypedListener typedListener = new TypedListener (listener); 324 addListener (SWT.Selection,typedListener); 325 addListener (SWT.DefaultSelection,typedListener); 326 } 327 328 int callWindowProc (int hwnd, int msg, int wParam, int lParam) { 329 if (handle == 0) return 0; 330 return OS.CallWindowProc (ButtonProc, hwnd, msg, wParam, lParam); 331 } 332 333 static int checkStyle (int style) { 334 style = checkBits (style, SWT.PUSH, SWT.ARROW, SWT.CHECK, SWT.RADIO, SWT.TOGGLE, COMMAND_LINK ? SWT.COMMAND : 0); 335 if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) { 336 return checkBits (style, SWT.CENTER, SWT.LEFT, SWT.RIGHT, 0, 0, 0); 337 } 338 if ((style & (SWT.CHECK | SWT.RADIO)) != 0) { 339 return checkBits (style, SWT.LEFT, SWT.RIGHT, SWT.CENTER, 0, 0, 0); 340 } 341 if ((style & SWT.ARROW) != 0) { 342 style |= SWT.NO_FOCUS; 343 return checkBits (style, SWT.UP, SWT.DOWN, SWT.LEFT, SWT.RIGHT, 0, 0); 344 } 345 return style; 346 } 347 348 void click () { 349 355 ignoreMouse = true; 356 OS.SendMessage (handle, OS.BM_CLICK, 0, 0); 357 ignoreMouse = false; 358 } 359 360 int computeLeftMargin () { 361 if (OS.COMCTL32_MAJOR < 6) return MARGIN; 362 if ((style & (SWT.PUSH | SWT.TOGGLE)) == 0) return MARGIN; 363 int margin = 0; 364 if (image != null && text.length () != 0) { 365 Rectangle bounds = image.getBounds (); 366 margin += bounds.width + MARGIN * 2; 367 int oldFont = 0; 368 int hDC = OS.GetDC (handle); 369 int newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); 370 if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont); 371 TCHAR buffer = new TCHAR (getCodePage (), text, true); 372 RECT rect = new RECT (); 373 int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE; 374 OS.DrawText (hDC, buffer, -1, rect, flags); 375 margin += rect.right - rect.left; 376 if (newFont != 0) OS.SelectObject (hDC, oldFont); 377 OS.ReleaseDC (handle, hDC); 378 OS.GetClientRect (handle, rect); 379 margin = Math.max (MARGIN, (rect.right - rect.left - margin) / 2); 380 } 381 return margin; 382 } 383 384 public Point computeSize (int wHint, int hHint, boolean changed) { 385 checkWidget (); 386 int width = 0, height = 0, border = getBorderWidth (); 387 if ((style & SWT.ARROW) != 0) { 388 if ((style & (SWT.UP | SWT.DOWN)) != 0) { 389 width += OS.GetSystemMetrics (OS.SM_CXVSCROLL); 390 height += OS.GetSystemMetrics (OS.SM_CYVSCROLL); 391 } else { 392 width += OS.GetSystemMetrics (OS.SM_CXHSCROLL); 393 height += OS.GetSystemMetrics (OS.SM_CYHSCROLL); 394 } 395 } else { 396 if ((style & SWT.COMMAND) != 0) { 397 SIZE size = new SIZE (); 398 if (wHint != SWT.DEFAULT) { 399 size.cx = wHint; 400 OS.SendMessage (handle, OS.BCM_GETIDEALSIZE, 0, size); 401 width = size.cx; 402 height = size.cy; 403 } else { 404 OS.SendMessage (handle, OS.BCM_GETIDEALSIZE, 0, size); 405 width = size.cy; 406 height = size.cy; 407 size.cy = 0; 408 while (size.cy != height) { 409 size.cx = width++; 410 size.cy = 0; 411 OS.SendMessage (handle, OS.BCM_GETIDEALSIZE, 0, size); 412 } 413 } 414 } else { 415 int extra = 0; 416 boolean hasImage = image != null, hasText = true; 417 if (OS.COMCTL32_MAJOR < 6) { 418 if ((style & SWT.PUSH) == 0) { 419 int bits = OS.GetWindowLong (handle, OS.GWL_STYLE); 420 hasImage = (bits & (OS.BS_BITMAP | OS.BS_ICON)) != 0; 421 if (hasImage) hasText = false; 422 } 423 } 424 if (hasImage) { 425 if (image != null) { 426 Rectangle rect = image.getBounds (); 427 width = rect.width; 428 if (hasText && text.length () != 0) { 429 width += MARGIN * 2; 430 } 431 height = rect.height; 432 extra = MARGIN * 2; 433 } 434 } 435 if (hasText) { 436 int oldFont = 0; 437 int hDC = OS.GetDC (handle); 438 int newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); 439 if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont); 440 TEXTMETRIC lptm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW () : new TEXTMETRICA (); 441 OS.GetTextMetrics (hDC, lptm); 442 int length = text.length (); 443 if (length == 0) { 444 height = Math.max (height, lptm.tmHeight); 445 } else { 446 extra = Math.max (MARGIN * 2, lptm.tmAveCharWidth); 447 TCHAR buffer = new TCHAR (getCodePage (), text, true); 448 RECT rect = new RECT (); 449 int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE; 450 OS.DrawText (hDC, buffer, -1, rect, flags); 451 width += rect.right - rect.left; 452 height = Math.max (height, rect.bottom - rect.top); 453 } 454 if (newFont != 0) OS.SelectObject (hDC, oldFont); 455 OS.ReleaseDC (handle, hDC); 456 } 457 if ((style & (SWT.CHECK | SWT.RADIO)) != 0) { 458 width += CHECK_WIDTH + extra; 459 height = Math.max (height, CHECK_HEIGHT + 3); 460 } 461 if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) { 462 width += 12; height += 10; 463 } 464 } 465 } 466 if (wHint != SWT.DEFAULT) width = wHint; 467 if (hHint != SWT.DEFAULT) height = hHint; 468 width += border * 2; 469 height += border * 2; 470 return new Point (width, height); 471 } 472 473 void createHandle () { 474 super.createHandle (); 475 if ((style & SWT.PUSH) == 0) state |= THEME_BACKGROUND; 476 488 if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) { 489 if ((style & SWT.RADIO) != 0) state |= DRAW_BACKGROUND; 490 } 491 } 492 493 int defaultBackground () { 494 if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) { 495 return OS.GetSysColor (OS.COLOR_BTNFACE); 496 } 497 return super.defaultBackground (); 498 } 499 500 int defaultForeground () { 501 return OS.GetSysColor (OS.COLOR_BTNTEXT); 502 } 503 504 void enableWidget (boolean enabled) { 505 super.enableWidget (enabled); 506 511 if ((style & SWT.RIGHT_TO_LEFT) != 0) { 512 if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) { 513 int bits = OS.GetWindowLong (handle, OS.GWL_STYLE); 514 boolean hasImage = (bits & (OS.BS_BITMAP | OS.BS_ICON)) != 0; 515 if (!hasImage) { 516 String string = enabled ? text : " " + text + " "; 517 TCHAR buffer = new TCHAR (getCodePage (), string, true); 518 OS.SetWindowText (handle, buffer); 519 } 520 } 521 } 522 532 if (OS.COMCTL32_MAJOR >= 6) { 533 if (imageList != null) { 534 BUTTON_IMAGELIST buttonImageList = new BUTTON_IMAGELIST (); 535 OS.SendMessage (handle, OS.BCM_GETIMAGELIST, 0, buttonImageList); 536 if (imageList != null) imageList.dispose (); 537 imageList = new ImageList (style & SWT.RIGHT_TO_LEFT); 538 if (OS.IsWindowEnabled (handle)) { 539 imageList.add (image); 540 } else { 541 if (disabledImage != null) disabledImage.dispose (); 542 disabledImage = new Image (display, image, SWT.IMAGE_DISABLE); 543 imageList.add (disabledImage); 544 } 545 buttonImageList.himl = imageList.getHandle (); 546 OS.SendMessage (handle, OS.BCM_SETIMAGELIST, 0, buttonImageList); 547 552 OS.InvalidateRect (handle, null, true); 553 } 554 } 555 } 556 557 573 public int getAlignment () { 574 checkWidget (); 575 if ((style & SWT.ARROW) != 0) { 576 if ((style & SWT.UP) != 0) return SWT.UP; 577 if ((style & SWT.DOWN) != 0) return SWT.DOWN; 578 if ((style & SWT.LEFT) != 0) return SWT.LEFT; 579 if ((style & SWT.RIGHT) != 0) return SWT.RIGHT; 580 return SWT.UP; 581 } 582 if ((style & SWT.LEFT) != 0) return SWT.LEFT; 583 if ((style & SWT.CENTER) != 0) return SWT.CENTER; 584 if ((style & SWT.RIGHT) != 0) return SWT.RIGHT; 585 return SWT.LEFT; 586 } 587 588 boolean getDefault () { 589 if ((style & SWT.PUSH) == 0) return false; 590 int bits = OS.GetWindowLong (handle, OS.GWL_STYLE); 591 return (bits & OS.BS_DEFPUSHBUTTON) != 0; 592 } 593 594 605 public Image getImage () { 606 checkWidget (); 607 return image; 608 } 609 610 624 String getMessage () { 625 checkWidget (); 626 return message; 627 } 628 629 String getNameText () { 630 return getText (); 631 } 632 633 649 public boolean getSelection () { 650 checkWidget (); 651 if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return false; 652 int state = OS.SendMessage (handle, OS.BM_GETCHECK, 0, 0); 653 return (state & OS.BST_CHECKED) != 0; 654 } 655 656 668 public String getText () { 669 checkWidget (); 670 if ((style & SWT.ARROW) != 0) return ""; 671 return text; 672 } 673 674 boolean isTabItem () { 675 return super.isTabItem (); 678 } 679 680 boolean mnemonicHit (char ch) { 681 if (!setFocus ()) return false; 682 688 if ((style & SWT.RADIO) == 0) click (); 689 return true; 690 } 691 692 boolean mnemonicMatch (char key) { 693 char mnemonic = findMnemonic (getText ()); 694 if (mnemonic == '\0') return false; 695 return Character.toUpperCase (key) == Character.toUpperCase (mnemonic); 696 } 697 698 void releaseWidget () { 699 super.releaseWidget (); 700 if (imageList != null) imageList.dispose (); 701 imageList = null; 702 if (disabledImage != null) disabledImage.dispose (); 703 disabledImage = null; 704 if (image2 != null) image2.dispose (); 705 image2 = null; 706 text = null; 707 image = null; 708 } 709 710 727 public void removeSelectionListener (SelectionListener listener) { 728 checkWidget (); 729 if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); 730 if (eventTable == null) return; 731 eventTable.unhook (SWT.Selection, listener); 732 eventTable.unhook (SWT.DefaultSelection,listener); 733 } 734 735 void selectRadio () { 736 744 Control [] children = parent._getChildren (); 753 for (int i=0; i<children.length; i++) { 754 Control child = children [i]; 755 if (this != child) child.setRadioSelection (false); 756 } 757 setSelection (true); 758 } 759 760 776 public void setAlignment (int alignment) { 777 checkWidget (); 778 if ((style & SWT.ARROW) != 0) { 779 if ((style & (SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT)) == 0) return; 780 style &= ~(SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT); 781 style |= alignment & (SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT); 782 OS.InvalidateRect (handle, null, true); 783 return; 784 } 785 if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return; 786 style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER); 787 style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER); 788 int oldBits = OS.GetWindowLong (handle, OS.GWL_STYLE), newBits = oldBits; 789 newBits &= ~(OS.BS_LEFT | OS.BS_CENTER | OS.BS_RIGHT); 790 if ((style & SWT.LEFT) != 0) newBits |= OS.BS_LEFT; 791 if ((style & SWT.CENTER) != 0) newBits |= OS.BS_CENTER; 792 if ((style & SWT.RIGHT) != 0) newBits |= OS.BS_RIGHT; 793 if (OS.COMCTL32_MAJOR >= 6) { 794 if (imageList != null) { 795 BUTTON_IMAGELIST buttonImageList = new BUTTON_IMAGELIST (); 796 buttonImageList.himl = imageList.getHandle (); 797 if (text.length () == 0) { 798 if ((style & SWT.LEFT) != 0) buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_LEFT; 799 if ((style & SWT.CENTER) != 0) buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_CENTER; 800 if ((style & SWT.RIGHT) != 0) buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_RIGHT; 801 } else { 802 buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_LEFT; 803 buttonImageList.margin_left = computeLeftMargin (); 804 buttonImageList.margin_right = MARGIN; 805 newBits &= ~(OS.BS_CENTER | OS.BS_RIGHT); 806 newBits |= OS.BS_LEFT; 807 } 808 OS.SendMessage (handle, OS.BCM_SETIMAGELIST, 0, buttonImageList); 809 } 810 } 811 if (newBits != oldBits) { 812 OS.SetWindowLong (handle, OS.GWL_STYLE, newBits); 813 OS.InvalidateRect (handle, null, true); 814 } 815 } 816 817 void setDefault (boolean value) { 818 if ((style & SWT.PUSH) == 0) return; 819 int hwndShell = menuShell ().handle; 820 int bits = OS.GetWindowLong (handle, OS.GWL_STYLE); 821 if (value) { 822 bits |= OS.BS_DEFPUSHBUTTON; 823 OS.SendMessage (hwndShell, OS.DM_SETDEFID, handle, 0); 824 } else { 825 bits &= ~OS.BS_DEFPUSHBUTTON; 826 OS.SendMessage (hwndShell, OS.DM_SETDEFID, 0, 0); 827 } 828 OS.SendMessage (handle, OS.BM_SETSTYLE, bits, 1); 829 } 830 831 boolean setFixedFocus () { 832 837 if ((style & SWT.RADIO) != 0 && !getSelection ()) return false; 838 return super.setFixedFocus (); 839 } 840 841 860 public void setImage (Image image) { 861 checkWidget (); 862 if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); 863 if ((style & SWT.ARROW) != 0) return; 864 this.image = image; 865 866 _setImage (image); 873 } 874 875 892 void setMessage (String message) { 893 checkWidget (); 894 if (message == null) error (SWT.ERROR_NULL_ARGUMENT); 895 this.message = message; 896 if (OS.COMCTL32_VERSION >= OS.VERSION (6, 1)) { 897 if ((style & SWT.COMMAND) != 0) { 898 int length = message.length (); 899 char [] chars = new char [length + 1]; 900
|