|
Lines 39-44
Link Here
|
| 39 |
public class ToolItem extends Item { |
39 |
public class ToolItem extends Item { |
| 40 |
NSView view; |
40 |
NSView view; |
| 41 |
NSButton button; |
41 |
NSButton button; |
|
|
42 |
NSToolbarItem nsItem; |
| 43 |
NSMenuItem nsMenuRep; |
| 44 |
NSString id; |
| 42 |
int width = DEFAULT_SEPARATOR_WIDTH; |
45 |
int width = DEFAULT_SEPARATOR_WIDTH; |
| 43 |
ToolBar parent; |
46 |
ToolBar parent; |
| 44 |
Image hotImage, disabledImage; |
47 |
Image hotImage, disabledImage; |
|
Lines 46-51
Link Here
|
| 46 |
Control control; |
49 |
Control control; |
| 47 |
boolean selection; |
50 |
boolean selection; |
| 48 |
|
51 |
|
|
|
52 |
static final int SEPARATOR_MASK = SWT.SEPARATOR | SWT.SPACER | SWT.FLEX_SPACER; |
| 49 |
static final int DEFAULT_WIDTH = 24; |
53 |
static final int DEFAULT_WIDTH = 24; |
| 50 |
static final int DEFAULT_HEIGHT = 22; |
54 |
static final int DEFAULT_HEIGHT = 22; |
| 51 |
static final int DEFAULT_SEPARATOR_WIDTH = 6; |
55 |
static final int DEFAULT_SEPARATOR_WIDTH = 6; |
|
Lines 301-307
Link Here
|
| 301 |
Point computeSize () { |
305 |
Point computeSize () { |
| 302 |
checkWidget(); |
306 |
checkWidget(); |
| 303 |
int width = 0, height = 0; |
307 |
int width = 0, height = 0; |
| 304 |
if ((style & SWT.SEPARATOR) != 0) { |
308 |
if ((style & SEPARATOR_MASK) != 0) { |
| 305 |
if ((parent.style & SWT.HORIZONTAL) != 0) { |
309 |
if ((parent.style & SWT.HORIZONTAL) != 0) { |
| 306 |
width = getWidth (); |
310 |
width = getWidth (); |
| 307 |
height = DEFAULT_HEIGHT; |
311 |
height = DEFAULT_HEIGHT; |
|
Lines 314-321
Link Here
|
| 314 |
} |
318 |
} |
| 315 |
} else { |
319 |
} else { |
| 316 |
if (text.length () != 0 || image != null) { |
320 |
if (text.length () != 0 || image != null) { |
| 317 |
NSButton widget = (NSButton)button; |
321 |
NSSize size = button.cell().cellSize(); |
| 318 |
NSSize size = widget.cell().cellSize(); |
|
|
| 319 |
width = (int)Math.ceil(size.width); |
322 |
width = (int)Math.ceil(size.width); |
| 320 |
height = (int)Math.ceil(size.height); |
323 |
height = (int)Math.ceil(size.height); |
| 321 |
} else { |
324 |
} else { |
|
Lines 325-367
Link Here
|
| 325 |
if ((style & SWT.DROP_DOWN) != 0) { |
328 |
if ((style & SWT.DROP_DOWN) != 0) { |
| 326 |
width += ARROW_WIDTH + INSET; |
329 |
width += ARROW_WIDTH + INSET; |
| 327 |
} |
330 |
} |
| 328 |
width += INSET * 2; |
331 |
|
| 329 |
height += INSET * 2; |
332 |
if ((style & SWT.SMOOTH) == 0) { |
|
|
333 |
width += INSET * 2; |
| 334 |
height += INSET * 2; |
| 335 |
} |
| 330 |
} |
336 |
} |
| 331 |
return new Point (width, height); |
337 |
return new Point (width, height); |
| 332 |
} |
338 |
} |
| 333 |
|
339 |
|
| 334 |
void createHandle () { |
340 |
void createHandle () { |
| 335 |
if ((style & SWT.SEPARATOR) != 0) { |
341 |
if ((style & SWT.SMOOTH) != 0) { |
| 336 |
NSBox widget = (NSBox)new SWTBox().alloc(); |
342 |
id = NSString.stringWith(String.valueOf(++ToolBar.NEXT_ID)); |
| 337 |
widget.init(); |
343 |
id.retain(); |
| 338 |
widget.setBoxType(OS.NSBoxSeparator); |
344 |
nsItem = ((NSToolbarItem)new NSToolbarItem().alloc()).initWithItemIdentifier(id); |
| 339 |
widget.setBorderWidth(0); |
345 |
nsItem.setAction(OS.sel_sendSelection); |
| 340 |
view = widget; |
346 |
nsMenuRep = ((NSMenuItem)new SWTMenuItem().alloc()).initWithTitle(NSString.string(), OS.sel_sendSelection, NSString.string()); |
|
|
347 |
nsItem.setMenuFormRepresentation(nsMenuRep); |
| 348 |
} |
| 349 |
|
| 350 |
if ((style & SEPARATOR_MASK) != 0) { |
| 351 |
if ((style & SWT.SMOOTH) != 0) { |
| 352 |
view = (NSView)new SWTView().alloc(); |
| 353 |
view.init(); |
| 354 |
} else { |
| 355 |
NSBox widget = (NSBox)new SWTBox().alloc(); |
| 356 |
widget.init(); |
| 357 |
widget.setBoxType(OS.NSBoxSeparator); |
| 358 |
widget.setBorderWidth(0); |
| 359 |
view = widget; |
| 360 |
} |
| 341 |
} else { |
361 |
} else { |
| 342 |
NSView widget = (NSView)new SWTView().alloc(); |
362 |
NSView widget = (NSView)new SWTView().alloc(); |
| 343 |
widget.init(); |
363 |
widget.init(); |
| 344 |
button = (NSButton)new SWTButton().alloc(); |
364 |
NSButton tbButton = (NSButton)new SWTButton().alloc(); |
| 345 |
button.init(); |
365 |
tbButton.init(); |
| 346 |
/* |
366 |
/* |
| 347 |
* Feature in Cocoa. NSButtons without borders do not leave any margin |
367 |
* Feature in Cocoa. NSButtons without borders do not leave any margin |
| 348 |
* between their edge and their image. The workaround is to provide a |
368 |
* between their edge and their image. The workaround is to provide a |
| 349 |
* custom cell that displays the image in a better position. |
369 |
* custom cell that displays the image in a better position. |
| 350 |
*/ |
370 |
*/ |
| 351 |
NSButtonCell cell = (NSButtonCell)new SWTButtonCell ().alloc ().init (); |
371 |
if ((style & SWT.SMOOTH) == 0) { |
| 352 |
button.setCell (cell); |
372 |
NSCell cell = (NSCell)new SWTButtonCell().alloc().init(); |
| 353 |
cell.release(); |
373 |
tbButton.setCell (cell); |
| 354 |
button.setBordered(false); |
374 |
cell.release(); |
| 355 |
button.setAction(OS.sel_sendSelection); |
375 |
} else { |
| 356 |
button.setTarget(button); |
376 |
if ((style & SWT.CHECK) != 0) tbButton.setButtonType(OS.NSPushOnPushOffButton); |
|
|
377 |
NSButtonCell buttonCell = new NSButtonCell(tbButton.cell().id); |
| 378 |
buttonCell.setHighlightsBy(OS.NSContentsCellMask); |
| 379 |
buttonCell.setShowsStateBy(OS.NSContentsCellMask); |
| 380 |
} |
| 381 |
tbButton.setBordered(false); |
| 382 |
tbButton.setAction(OS.sel_sendSelection); |
| 383 |
tbButton.setTarget(tbButton); |
| 357 |
Font font = parent.font != null ? parent.font : parent.defaultFont (); |
384 |
Font font = parent.font != null ? parent.font : parent.defaultFont (); |
| 358 |
button.setFont(font.handle); |
385 |
tbButton.setFont(font.handle); |
| 359 |
button.setImagePosition(OS.NSImageOverlaps); |
386 |
tbButton.setTitle(NSString.stringWith("")); |
| 360 |
button.setTitle(NSString.string()); |
387 |
tbButton.setImagePosition(OS.NSImageOnly); |
| 361 |
button.setEnabled(parent.getEnabled()); |
388 |
tbButton.setEnabled(parent.getEnabled()); |
| 362 |
widget.addSubview(button); |
389 |
widget.addSubview(tbButton); |
|
|
390 |
button = tbButton; |
| 363 |
view = widget; |
391 |
view = widget; |
| 364 |
} |
392 |
} |
|
|
393 |
|
| 394 |
if (nsItem != null) { |
| 395 |
nsItem.setTarget(button); |
| 396 |
nsItem.setView(view); |
| 397 |
nsMenuRep.setTarget(button); |
| 398 |
} |
| 365 |
} |
399 |
} |
| 366 |
|
400 |
|
| 367 |
NSAttributedString createString() { |
401 |
NSAttributedString createString() { |
|
Lines 386-404
Link Here
|
| 386 |
} |
420 |
} |
| 387 |
|
421 |
|
| 388 |
void drawImageWithFrameInView (int /*long*/ id, int /*long*/ sel, int /*long*/ image, NSRect rect, int /*long*/ view) { |
422 |
void drawImageWithFrameInView (int /*long*/ id, int /*long*/ sel, int /*long*/ image, NSRect rect, int /*long*/ view) { |
| 389 |
if (text.length () > 0) { |
423 |
if ((style & SWT.SMOOTH) == 0) { |
| 390 |
if ((parent.style & SWT.RIGHT) != 0) { |
424 |
if (text.length () > 0) { |
| 391 |
rect.x += 3; |
425 |
if ((parent.style & SWT.RIGHT) != 0) { |
| 392 |
} else { |
426 |
rect.x += 3; |
| 393 |
rect.y += 3; |
427 |
} else { |
|
|
428 |
rect.y += 3; |
| 429 |
} |
| 394 |
} |
430 |
} |
| 395 |
} |
431 |
} |
| 396 |
callSuper (id, sel, image, rect, view); |
432 |
super.drawImageWithFrameInView(id, sel, image, rect, view); |
| 397 |
} |
433 |
} |
| 398 |
|
434 |
|
| 399 |
void drawWidget (int /*long*/ id, NSGraphicsContext context, NSRect rect) { |
435 |
void drawWidget (int /*long*/ id, NSGraphicsContext context, NSRect rect) { |
| 400 |
if (id == view.id) { |
436 |
if (id == view.id) { |
| 401 |
if (getSelection ()) { |
437 |
boolean drawSelected = getSelection() && ((style & (SWT.SMOOTH | SWT.CHECK)) == (SWT.SMOOTH | SWT.CHECK)) || ((style & SWT.SMOOTH) == 0); |
|
|
438 |
if (drawSelected) { |
| 402 |
NSRect bounds = view.bounds(); |
439 |
NSRect bounds = view.bounds(); |
| 403 |
context.saveGraphicsState(); |
440 |
context.saveGraphicsState(); |
| 404 |
NSColor.colorWithCalibratedRed(0.1f, 0.1f, 0.1f, 0.1f).setFill(); |
441 |
NSColor.colorWithCalibratedRed(0.1f, 0.1f, 0.1f, 0.1f).setFill(); |
|
Lines 435-443
Link Here
|
| 435 |
} |
472 |
} |
| 436 |
|
473 |
|
| 437 |
void enableWidget(boolean enabled) { |
474 |
void enableWidget(boolean enabled) { |
| 438 |
if ((style & SWT.SEPARATOR) == 0) { |
475 |
if ((style & SWT.SMOOTH) != 0) { |
| 439 |
((NSButton)button).setEnabled(enabled); |
476 |
nsItem.setEnabled(enabled); |
| 440 |
updateImage(true); |
477 |
} else { |
|
|
478 |
if ((style & SEPARATOR_MASK) == 0) { |
| 479 |
((NSButton)button).setEnabled(enabled); |
| 480 |
updateImage(true); |
| 481 |
} |
| 441 |
} |
482 |
} |
| 442 |
} |
483 |
} |
| 443 |
|
484 |
|
|
Lines 454-459
Link Here
|
| 454 |
*/ |
495 |
*/ |
| 455 |
public Rectangle getBounds () { |
496 |
public Rectangle getBounds () { |
| 456 |
checkWidget(); |
497 |
checkWidget(); |
|
|
498 |
if ((style & SWT.SMOOTH) != 0) { |
| 499 |
NSRect rect = view.frame(); |
| 500 |
// ToolItems in the unified toolbar are not contained directly within the Toolbar. |
| 501 |
// Convert the toolitem rect from toolitem-relative coordinates to its |
| 502 |
// parent, the toolbar, relative coordinates. |
| 503 |
rect = parent.view.convertRect_fromView_(rect, view); |
| 504 |
return new Rectangle((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height); |
| 505 |
} |
| 506 |
|
| 457 |
NSRect rect = view.frame(); |
507 |
NSRect rect = view.frame(); |
| 458 |
return new Rectangle((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height); |
508 |
return new Rectangle((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height); |
| 459 |
} |
509 |
} |
|
Lines 540-545
Link Here
|
| 540 |
return hotImage; |
590 |
return hotImage; |
| 541 |
} |
591 |
} |
| 542 |
|
592 |
|
|
|
593 |
NSString getItemID() { |
| 594 |
NSString itemID = id; |
| 595 |
|
| 596 |
// For separators, return a Cocoa constant for the tool item ID. |
| 597 |
if ((style & SEPARATOR_MASK) != 0) { |
| 598 |
// If we are using a non-default width or control use that instead. |
| 599 |
if (width == DEFAULT_SEPARATOR_WIDTH && control == null) { |
| 600 |
if ((style & SWT.SEPARATOR) != 0) { |
| 601 |
itemID = OS.NSToolbarSeparatorItemIdentifier; |
| 602 |
} else if ((style & SWT.SPACER) != 0) { |
| 603 |
itemID = OS.NSToolbarSpaceItemIdentifier; |
| 604 |
} else if ((style & SWT.FLEX_SPACER) != 0) { |
| 605 |
itemID = OS.NSToolbarFlexibleSpaceItemIdentifier; |
| 606 |
} |
| 607 |
} |
| 608 |
} |
| 609 |
|
| 610 |
return itemID; |
| 611 |
} |
| 612 |
|
| 543 |
/** |
613 |
/** |
| 544 |
* Returns the receiver's parent, which must be a <code>ToolBar</code>. |
614 |
* Returns the receiver's parent, which must be a <code>ToolBar</code>. |
| 545 |
* |
615 |
* |
|
Lines 652-657
Link Here
|
| 652 |
} |
722 |
} |
| 653 |
} |
723 |
} |
| 654 |
|
724 |
|
|
|
725 |
boolean mouseDownCanMoveWindow(int /*long*/ id, int /*long*/ sel) { |
| 726 |
if (id == view.id) return false; |
| 727 |
return super.mouseDownCanMoveWindow(id, sel); |
| 728 |
} |
| 729 |
|
| 655 |
void mouseUp(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { |
730 |
void mouseUp(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { |
| 656 |
if (!parent.mouseEvent(parent.view.id, sel, theEvent, SWT.MouseUp)) return; |
731 |
if (!parent.mouseEvent(parent.view.id, sel, theEvent, SWT.MouseUp)) return; |
| 657 |
super.mouseUp(id, sel, theEvent); |
732 |
super.mouseUp(id, sel, theEvent); |
|
Lines 737-742
Link Here
|
| 737 |
if (view != null) view.release (); |
812 |
if (view != null) view.release (); |
| 738 |
if (button != null) button.release (); |
813 |
if (button != null) button.release (); |
| 739 |
view = button = null; |
814 |
view = button = null; |
|
|
815 |
if (nsItem != null) { |
| 816 |
nsItem.release(); |
| 817 |
nsItem = null; |
| 818 |
} |
| 819 |
if (id != null) { |
| 820 |
id.release(); |
| 821 |
id = null; |
| 822 |
} |
| 823 |
if (nsMenuRep != null) { |
| 824 |
nsMenuRep.release(); |
| 825 |
nsMenuRep = null; |
| 826 |
} |
| 740 |
parent = null; |
827 |
parent = null; |
| 741 |
} |
828 |
} |
| 742 |
|
829 |
|
|
Lines 770-787
Link Here
|
| 770 |
|
857 |
|
| 771 |
void setBounds (int x, int y, int width, int height) { |
858 |
void setBounds (int x, int y, int width, int height) { |
| 772 |
NSRect rect = new NSRect(); |
859 |
NSRect rect = new NSRect(); |
| 773 |
rect.x = x; |
860 |
if ((style & SWT.SMOOTH) == 0) { |
| 774 |
rect.y = y; |
861 |
rect.x = x; |
| 775 |
rect.width = width; |
862 |
rect.y = y; |
| 776 |
rect.height = height; |
|
|
| 777 |
view.setFrame(rect); |
| 778 |
if (button != null) { |
| 779 |
rect.x = 0; |
| 780 |
rect.y = 0; |
| 781 |
rect.width = width; |
863 |
rect.width = width; |
| 782 |
rect.height = height; |
864 |
rect.height = height; |
| 783 |
if ((style & SWT.DROP_DOWN) != 0) rect.width -= ARROW_WIDTH + INSET; |
865 |
view.setFrame(rect); |
| 784 |
button.setFrame(rect); |
866 |
if (button != null) { |
|
|
867 |
rect.x = 0; |
| 868 |
rect.y = 0; |
| 869 |
rect.width = width; |
| 870 |
rect.height = height; |
| 871 |
if ((style & SWT.DROP_DOWN) != 0) rect.width -= ARROW_WIDTH + INSET; |
| 872 |
button.setFrame(rect); |
| 873 |
} |
| 874 |
} else { |
| 875 |
// Let the NSToolbar manage the position of the view in the toolbar. |
| 876 |
NSSize newSize = new NSSize(); |
| 877 |
newSize.height = height; |
| 878 |
newSize.width = width; |
| 879 |
view.setFrameSize(newSize); |
| 880 |
nsItem.setMinSize(newSize); |
| 881 |
nsItem.setMaxSize(newSize); |
| 882 |
if ((style & SWT.DROP_DOWN) != 0) newSize.width -= ARROW_WIDTH + INSET; |
| 883 |
if (button != null) button.setFrameSize(newSize); |
| 785 |
} |
884 |
} |
| 786 |
} |
885 |
} |
| 787 |
|
886 |
|
|
Lines 806-818
Link Here
|
| 806 |
if (control.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); |
905 |
if (control.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); |
| 807 |
if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT); |
906 |
if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT); |
| 808 |
} |
907 |
} |
| 809 |
if ((style & SWT.SEPARATOR) == 0) return; |
908 |
if ((style & SEPARATOR_MASK) == 0) return; |
| 810 |
if (this.control == control) return; |
909 |
if (this.control == control) return; |
| 811 |
NSBox widget = (NSBox)view; |
910 |
|
| 812 |
if (control == null) { |
911 |
if ((style & SWT.SMOOTH) == 0) { |
| 813 |
widget.setBoxType(OS.NSBoxSeparator); |
912 |
NSBox widget = (NSBox)view; |
| 814 |
} else { |
913 |
if (control == null) { |
| 815 |
widget.setBoxType(OS.NSBoxCustom); |
914 |
widget.setBoxType(OS.NSBoxSeparator); |
|
|
915 |
} else { |
| 916 |
widget.setBoxType(OS.NSBoxCustom); |
| 917 |
} |
| 816 |
} |
918 |
} |
| 817 |
this.control = control; |
919 |
this.control = control; |
| 818 |
view.setHidden(control != null); |
920 |
view.setHidden(control != null); |
|
Lines 869-875
Link Here
|
| 869 |
public void setDisabledImage (Image image) { |
971 |
public void setDisabledImage (Image image) { |
| 870 |
checkWidget(); |
972 |
checkWidget(); |
| 871 |
if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); |
973 |
if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); |
| 872 |
if ((style & SWT.SEPARATOR) != 0) return; |
974 |
if ((style & SEPARATOR_MASK) != 0) return; |
| 873 |
disabledImage = image; |
975 |
disabledImage = image; |
| 874 |
updateImage (true); |
976 |
updateImage (true); |
| 875 |
} |
977 |
} |
|
Lines 900-906
Link Here
|
| 900 |
public void setHotImage (Image image) { |
1002 |
public void setHotImage (Image image) { |
| 901 |
checkWidget(); |
1003 |
checkWidget(); |
| 902 |
if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); |
1004 |
if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); |
| 903 |
if ((style & SWT.SEPARATOR) != 0) return; |
1005 |
if ((style & SEPARATOR_MASK) != 0) return; |
| 904 |
hotImage = image; |
1006 |
hotImage = image; |
| 905 |
updateImage (true); |
1007 |
updateImage (true); |
| 906 |
} |
1008 |
} |
|
Lines 908-914
Link Here
|
| 908 |
public void setImage (Image image) { |
1010 |
public void setImage (Image image) { |
| 909 |
checkWidget(); |
1011 |
checkWidget(); |
| 910 |
if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); |
1012 |
if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); |
| 911 |
if ((style & SWT.SEPARATOR) != 0) return; |
1013 |
if ((style & SEPARATOR_MASK) != 0) return; |
| 912 |
super.setImage (image); |
1014 |
super.setImage (image); |
| 913 |
updateImage (true); |
1015 |
updateImage (true); |
| 914 |
} |
1016 |
} |
|
Lines 941-946
Link Here
|
| 941 |
checkWidget(); |
1043 |
checkWidget(); |
| 942 |
if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return; |
1044 |
if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return; |
| 943 |
this.selection = selected; |
1045 |
this.selection = selected; |
|
|
1046 |
|
| 1047 |
if ((style & (SWT.CHECK | SWT.SMOOTH)) == (SWT.CHECK | SWT.SMOOTH)) { |
| 1048 |
button.setState (selection ? OS.NSOnState : OS.NSOffState); |
| 1049 |
} |
| 1050 |
|
| 1051 |
if ((style & (SWT.RADIO | SWT.SMOOTH)) == (SWT.RADIO | SWT.SMOOTH) && selection) { |
| 1052 |
parent.toolbar.setSelectedItemIdentifier(nsItem.itemIdentifier()); |
| 1053 |
} |
| 944 |
view.setNeedsDisplay(true); |
1054 |
view.setNeedsDisplay(true); |
| 945 |
} |
1055 |
} |
| 946 |
|
1056 |
|
|
Lines 972-989
Link Here
|
| 972 |
public void setText (String string) { |
1082 |
public void setText (String string) { |
| 973 |
checkWidget(); |
1083 |
checkWidget(); |
| 974 |
if (string == null) error (SWT.ERROR_NULL_ARGUMENT); |
1084 |
if (string == null) error (SWT.ERROR_NULL_ARGUMENT); |
| 975 |
if ((style & SWT.SEPARATOR) != 0) return; |
1085 |
if ((style & SEPARATOR_MASK) != 0) return; |
| 976 |
super.setText (string); |
1086 |
super.setText (string); |
| 977 |
NSButton widget = (NSButton)button; |
1087 |
NSButton widget = (NSButton)button; |
| 978 |
widget.setAttributedTitle(createString()); |
1088 |
if ((style & SWT.SMOOTH) != 0) { |
| 979 |
if (text.length() != 0 && image != null) { |
1089 |
if (text.length() > 0) { |
| 980 |
if ((parent.style & SWT.RIGHT) != 0) { |
1090 |
char [] chars = new char [text.length ()]; |
| 981 |
widget.setImagePosition(OS.NSImageLeft); |
1091 |
text.getChars (0, chars.length, chars, 0); |
|
|
1092 |
int length = fixMnemonic (chars); |
| 1093 |
nsItem.setLabel(NSString.stringWithCharacters(chars, length)); |
| 1094 |
nsMenuRep.setTitle(NSString.stringWithCharacters(chars, length)); |
| 982 |
} else { |
1095 |
} else { |
| 983 |
widget.setImagePosition(OS.NSImageAbove); |
1096 |
nsItem.setLabel(NSString.string()); |
|
|
1097 |
nsMenuRep.setTitle(NSString.string()); |
| 984 |
} |
1098 |
} |
| 985 |
} else { |
1099 |
} else { |
| 986 |
widget.setImagePosition(text.length() != 0 ? OS.NSNoImage : OS.NSImageOnly); |
1100 |
widget.setAttributedTitle(createString()); |
|
|
1101 |
if (text.length() != 0 && image != null) { |
| 1102 |
if ((parent.style & SWT.RIGHT) != 0) { |
| 1103 |
widget.setImagePosition(OS.NSImageLeft); |
| 1104 |
} else { |
| 1105 |
widget.setImagePosition(OS.NSImageAbove); |
| 1106 |
} |
| 1107 |
} else { |
| 1108 |
widget.setImagePosition(text.length() != 0 ? OS.NSNoImage : OS.NSImageOnly); |
| 1109 |
} |
| 987 |
} |
1110 |
} |
| 988 |
parent.relayout (); |
1111 |
parent.relayout (); |
| 989 |
} |
1112 |
} |
|
Lines 1010-1017
Link Here
|
| 1010 |
*/ |
1133 |
*/ |
| 1011 |
public void setToolTipText (String string) { |
1134 |
public void setToolTipText (String string) { |
| 1012 |
checkWidget(); |
1135 |
checkWidget(); |
| 1013 |
toolTipText = string; |
1136 |
toolTipText = string; |
| 1014 |
parent.checkToolTip (this); |
1137 |
if ((style & SWT.SMOOTH) != 0) { |
|
|
1138 |
char[] chars = new char [toolTipText.length ()]; |
| 1139 |
string.getChars (0, chars.length, chars, 0); |
| 1140 |
int length = fixMnemonic (chars); |
| 1141 |
nsItem.setToolTip(NSString.stringWithCharacters (chars, length)); |
| 1142 |
} else { |
| 1143 |
parent.checkToolTip (this); |
| 1144 |
} |
| 1015 |
} |
1145 |
} |
| 1016 |
|
1146 |
|
| 1017 |
void setVisible (boolean visible) { |
1147 |
void setVisible (boolean visible) { |
|
Lines 1037-1045
Link Here
|
| 1037 |
*/ |
1167 |
*/ |
| 1038 |
public void setWidth (int width) { |
1168 |
public void setWidth (int width) { |
| 1039 |
checkWidget(); |
1169 |
checkWidget(); |
| 1040 |
if ((style & SWT.SEPARATOR) == 0) return; |
1170 |
if ((style & SEPARATOR_MASK) == 0) return; |
| 1041 |
if (width < 0 || this.width == width) return; |
1171 |
if (width < 0 || this.width == width) return; |
|
|
1172 |
if (width == SWT.DEFAULT) width = DEFAULT_SEPARATOR_WIDTH; |
| 1042 |
this.width = width; |
1173 |
this.width = width; |
|
|
1174 |
if ((style & SWT.SMOOTH) != 0) { |
| 1175 |
NSToolbar toolbar = parent.toolbar; |
| 1176 |
int index = parent.indexOf(this); |
| 1177 |
toolbar.removeItemAtIndex(index); |
| 1178 |
toolbar.insertItemWithItemIdentifier(getItemID(), index); |
| 1179 |
|
| 1180 |
NSRect newFrame = new NSRect(); |
| 1181 |
newFrame.width = width; |
| 1182 |
newFrame.height = 1; |
| 1183 |
view.setFrame(newFrame); |
| 1184 |
nsItem.setView(view); |
| 1185 |
} |
| 1043 |
parent.relayout(); |
1186 |
parent.relayout(); |
| 1044 |
} |
1187 |
} |
| 1045 |
|
1188 |
|
|
Lines 1048-1054
Link Here
|
| 1048 |
} |
1191 |
} |
| 1049 |
|
1192 |
|
| 1050 |
void updateImage (boolean layout) { |
1193 |
void updateImage (boolean layout) { |
| 1051 |
if ((style & SWT.SEPARATOR) != 0) return; |
1194 |
if ((style & SEPARATOR_MASK) != 0) return; |
| 1052 |
Image newImage = null; |
1195 |
Image newImage = null; |
| 1053 |
|
1196 |
|
| 1054 |
if ((state & DISABLED) == DISABLED && disabledImage != null) { |
1197 |
if ((state & DISABLED) == DISABLED && disabledImage != null) { |
|
Lines 1071-1084
Link Here
|
| 1071 |
*/ |
1214 |
*/ |
| 1072 |
widget.setImage(newImage != null ? newImage.handle : null); |
1215 |
widget.setImage(newImage != null ? newImage.handle : null); |
| 1073 |
widget.setNeedsDisplay(true); |
1216 |
widget.setNeedsDisplay(true); |
| 1074 |
if (text.length() != 0 && newImage != null) { |
1217 |
|
| 1075 |
if ((parent.style & SWT.RIGHT) != 0) { |
1218 |
if ((style & SWT.SMOOTH) == 0) { |
| 1076 |
widget.setImagePosition(OS.NSImageLeft); |
1219 |
if (text.length() != 0 && newImage != null) { |
|
|
1220 |
if ((parent.style & SWT.RIGHT) != 0) { |
| 1221 |
widget.setImagePosition(OS.NSImageLeft); |
| 1222 |
} else { |
| 1223 |
widget.setImagePosition(OS.NSImageAbove); |
| 1224 |
} |
| 1077 |
} else { |
1225 |
} else { |
| 1078 |
widget.setImagePosition(OS.NSImageAbove); |
1226 |
widget.setImagePosition(text.length() != 0 ? OS.NSNoImage : OS.NSImageOnly); |
| 1079 |
} |
1227 |
} |
| 1080 |
} else { |
|
|
| 1081 |
widget.setImagePosition(text.length() != 0 ? OS.NSNoImage : OS.NSImageOnly); |
| 1082 |
} |
1228 |
} |
| 1083 |
parent.relayout(); |
1229 |
parent.relayout(); |
| 1084 |
} |
1230 |
} |