Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 170610 Details for
Bug 222859
Support native Mac toolbar
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
OSX Unified Toolbar
osx-unified-toolbar.patch (text/plain), 35.65 KB, created by
Yolian Ignatov
on 2010-06-01 02:53:31 EDT
(
hide
)
Description:
OSX Unified Toolbar
Filename:
MIME Type:
Creator:
Yolian Ignatov
Created:
2010-06-01 02:53:31 EDT
Size:
35.65 KB
patch
obsolete
>Index: org/eclipse/swt/SWT.java >=================================================================== >--- org/eclipse/swt/SWT.java (revision 4159) >+++ org/eclipse/swt/SWT.java (revision 4225) >@@ -905,6 +905,20 @@ > */ > public static final int SEPARATOR = 1 << 1; > >+ /** >+ * A Style constant representing a flexible space separator in a Cocoa >+ * Unified toolbar. Although the (1 << 7) bit is already taken (they all are >+ * several times over) it's in a different context so it shouldn't represent >+ * a conflict. Carries no meaning on WS-s other than Cocoa. >+ */ >+ public static final int FLEX_SPACER = 1 << 7; >+ >+ /** >+ * A Style constant representing a space separator in a Cocoa Unified >+ * toolbar. Carries no meaning on WS-s other than Cocoa. >+ */ >+ public static final int SPACER = 1 << 10; >+ > /** > * Style constant for toggle button behavior (value is 1<<1). > * <p><b>Used By:</b><ul> >Index: org/eclipse/swt/widgets/Control.java >=================================================================== >--- org/eclipse/swt/widgets/Control.java (revision 4159) >+++ org/eclipse/swt/widgets/Control.java (revision 4225) >@@ -1862,7 +1862,11 @@ > } > > boolean isDrawing () { >- return getDrawing() && parent.isDrawing(); >+ if (parent != null) { >+ return getDrawing() && parent.isDrawing(); >+ } else { >+ return getDrawing(); >+ } > } > > /** >Index: org/eclipse/swt/widgets/Combo.java >=================================================================== >--- org/eclipse/swt/widgets/Combo.java (revision 4159) >+++ org/eclipse/swt/widgets/Combo.java (revision 4225) >@@ -60,6 +60,18 @@ > boolean receivingFocus; > boolean ignoreVerify, ignoreSelection; > NSRange selectionRange; >+ private boolean arrowHit; >+ private Image image; >+ private ToolItem toolItem; >+ >+ /* >+ * When a combo with a dropdown is a small (i.e. 24x24) item in >+ * a unified toolbar, its arrow lives in a rectangle that is >+ * 10px wide and 24px high. >+ */ >+ private static final Rectangle arrow24Bounds = new Rectangle(38, 0, 10, 24); >+ >+ private static final Rectangle arrow32Bounds = new Rectangle(44, 0, 10, 32); > > /** > * the operating system limit for the number of characters >@@ -136,6 +148,9 @@ > NSMenu nsMenu = widget.menu(); > NSMenuItem nsItem = (NSMenuItem)new NSMenuItem().alloc(); > nsItem.initWithTitle(str, 0, NSString.stringWith("")); >+ if (((style & SWT.SMOOTH) != 0) && (string.length() == 0)){ >+ nsItem.setImage(image.handle); >+ } > nsMenu.addItem(nsItem); > nsItem.release(); > if (selection == -1) widget.selectItemAtIndex(-1); >@@ -144,6 +159,9 @@ > } > } > >+void setImage(Image image){ >+ this.image = image; >+} > /** > * Adds the argument to the receiver's list at the given > * zero-relative index. >@@ -406,6 +424,12 @@ > widget.menu().setAutoenablesItems(false); > widget.setTarget(widget); > widget.setAction(OS.sel_sendSelection); >+ if ((style & SWT.SMOOTH) != 0) { >+ /* When the button is not bordered, the bezel style is ignored. */ >+ widget.setBordered(false); >+ /* Choose the pull-down (down-pointing arrow) menu, not the pop-up one (up-down arrow) */ >+ widget.setPullsDown(true); >+ } > view = widget; > } else { > NSComboBox widget = (NSComboBox)new SWTComboBox().alloc(); >@@ -849,7 +873,33 @@ > return (int)/*64*/((NSComboBox)view).numberOfVisibleItems(); > } > } >- >+ >+/** >+ * Use hitTest() to determine whether, in the case when the combo is an item >+ * in a Unified toolbar, the user clicked on the dropdown arrow; store the >+ * result in arrowHit for later use in mouseDown() >+ */ >+int /*long*/ hitTest (int /*long*/ id, int /*long*/ sel, NSPoint point) { >+ if ((state & DISABLED) != 0) return 0; >+ if (!isActive ()) return 0; >+ if (((style & SWT.SMOOTH) != 0) && (image != null)) { >+ arrowHit = false; >+ NSView superview = new NSView(id).superview(); >+ if (superview != null) { >+ NSPoint pt = superview.convertPoint_toView_(point, view); >+ if (!view.isFlipped ()) { >+ pt.y = view.bounds().height - pt.y; >+ } >+ Rectangle arrowBounds = (toolItem.parent.toolbar.sizeMode() == NSToolbar.NSToolbarSizeModeSmall) ? arrow24Bounds >+ : arrow32Bounds; >+ if (arrowBounds.contains((int) pt.x, (int) pt.y)) { >+ arrowHit = true; >+ } >+ } >+ } >+ return super.hitTest(id, sel, point); >+} >+ > /** > * Searches the receiver's list starting at the first item > * (index 0) until an item is found that is equal to the >@@ -942,16 +992,31 @@ > } > > void mouseDown(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { >- // If this is a combo box with an editor field and the control is disposed >- // while the view's cell editor is open we crash while tearing down the >- // popup window. Fix is to retain the view before letting Cocoa track >- // the mouse events. >- >- // 'view' will be cleared if disposed during the mouseDown so cache it. >- NSView viewCopy = view; >- viewCopy.retain(); >- super.mouseDown(id, sel, theEvent); >- viewCopy.release(); >+ if (((style & SWT.SMOOTH) != 0) && ((style & SWT.DROP_DOWN) != 0) && (id == view.id)) { >+ super.mouseDown(id, sel, theEvent); >+ NSRect rect = view.frame(); >+ /* Convert the combo rect from combo-relative coordinates to its parent-, the >+ * toolbar, relative coordinates. */ >+ Point position = getDisplay().map(this, parent, (int)rect.x, (int)rect.y); >+ Event event = new Event (); >+ event.detail = arrowHit ? SWT.ARROW : 0; >+ event.x = position.x; >+ event.y = (int)(rect.y + rect.height); >+ if ((toolItem != null) && (toolItem.isDisposed() == false)) { >+ toolItem.postEvent (SWT.Selection, event); >+ } >+ } else { >+ // If this is a combo box with an editor field and the control is disposed >+ // while the view's cell editor is open we crash while tearing down the >+ // popup window. Fix is to retain the view before letting Cocoa track >+ // the mouse events. >+ >+ // 'view' will be cleared if disposed during the mouseDown so cache it. >+ NSView viewCopy = view; >+ viewCopy.retain(); >+ super.mouseDown(id, sel, theEvent); >+ viewCopy.release(); >+ } > } > > /** >@@ -999,12 +1064,23 @@ > display.addWidget(((NSControl)view).cell(), this); > } > >+void releaseParent () { >+ if ((style & SWT.SMOOTH) == 0) { >+ super.releaseParent(); >+ } >+} >+ > void releaseWidget () { > super.releaseWidget (); > if ((style & SWT.READ_ONLY) == 0) { > ((NSControl)view).abortEditing(); > } > selectionRange = null; >+ toolItem = null; >+ if (image != null) { >+ image.dispose(); >+ image = null; >+ } > } > > /** >@@ -1526,6 +1602,17 @@ > } > > /** >+ * Sets the ToolItem to be used to post events to when the combo is used as a >+ * menu-button in a toolbar. >+ * >+ * @param toolItem >+ */ >+void setToolItem(ToolItem toolItem) { >+ this.toolItem = toolItem; >+} >+ >+ >+/** > * Sets the number of items that are visible in the drop > * down portion of the receiver's list. > * <p> >Index: org/eclipse/swt/widgets/ToolBar.java >=================================================================== >--- org/eclipse/swt/widgets/ToolBar.java (revision 4159) >+++ org/eclipse/swt/widgets/ToolBar.java (revision 4225) >@@ -48,8 +48,11 @@ > public class ToolBar extends Composite { > int itemCount; > ToolItem [] items; >+ NSToolbar toolbar; > NSArray accessibilityAttributes = null; > >+ static int NEXT_ID; >+ > /** > * Constructs a new instance of this class given its parent > * and a style value describing its behavior and appearance. >@@ -101,6 +104,22 @@ > } > } > >+Control[] _getChildren() { >+ Control[] children = super._getChildren(); >+ int count = 0; >+ for (int i = 0; i < itemCount; i++) { >+ ToolItem item = items[i]; >+ if (item.control != null) count++; >+ } >+ Control[] result = new Control[children.length + count]; >+ System.arraycopy(children, 0, result, 0, children.length); >+ for (int i = 0, j= children.length; i < itemCount; i++) { >+ ToolItem item = items[i]; >+ if (item.control != null) result[j++] = item.control; >+ } >+ return result; >+} >+ > int /*long*/ accessibilityAttributeNames(int /*long*/ id, int /*long*/ sel) { > > if (accessibilityAttributes == null) { >@@ -200,11 +219,27 @@ > } > > void createHandle () { >- state |= THEME_BACKGROUND; >- NSView widget = (NSView)new SWTView().alloc(); >- widget.init(); >-// widget.setDrawsBackground(false); >- view = widget; >+ if (isUnified()) { >+ toolbar = ((NSToolbar)new SWTToolbar().alloc()).initWithIdentifier(NSString.stringWith(String.valueOf(NEXT_ID++))); >+ toolbar.setDelegate(toolbar); >+ toolbar.setSizeMode(NSToolbar.NSToolbarSizeModeRegular); >+ toolbar.setDisplayMode(NSToolbar.NSToolbarDisplayModeIconAndLabel); >+ NSWindow window = parent.view.window(); >+ window.setToolbar(toolbar); >+ toolbar.setVisible(true); >+ NSArray views = window.contentView().superview().subviews(); >+ for (int i = 0; i < views.count(); i++) { >+ id id = views.objectAtIndex(i); >+ if (new NSObject(id).className().getString().equals("NSToolbarView")) { >+ view = new NSView(id); >+ } >+ } >+ } else { >+ state |= THEME_BACKGROUND; >+ NSView widget = (NSView)new SWTView().alloc(); >+ widget.init(); >+ view = widget; >+ } > } > > void createItem (ToolItem item, int index) { >@@ -214,10 +249,25 @@ > System.arraycopy (items, 0, newItems, 0, items.length); > items = newItems; > } >- item.createWidget(); >- view.addSubview(item.view); >+ item.createWidget(); > System.arraycopy (items, index, items, index + 1, itemCount++ - index); > items [index] = item; >+ if (isUnified()) { >+ NSString itemId = null; >+ if ((item.style & SWT.SEPARATOR) != 0) { >+ itemId = OS.NSToolbarSeparatorItemIdentifier; >+ } else if ((item.style & SWT.SPACER) != 0) { >+ itemId = OS.NSToolbarSpaceItemIdentifier; >+ } else if ((item.style & SWT.FLEX_SPACER) != 0) { >+ itemId = OS.NSToolbarFlexibleSpaceItemIdentifier; >+ } else { >+ itemId = item.id; >+ } >+ toolbar.insertItemWithItemIdentifier(itemId, index); >+ item.createDropdown(); >+ } else { >+ view.addSubview(item.view); >+ } > relayout (); > } > >@@ -227,6 +277,11 @@ > itemCount = 0; > } > >+void deregister () { >+ super.deregister (); >+ if (toolbar != null) display.removeWidget (toolbar); >+} >+ > void destroyItem (ToolItem item) { > int index = 0; > while (index < itemCount) { >@@ -235,8 +290,12 @@ > } > if (index == itemCount) return; > System.arraycopy (items, index + 1, items, index, --itemCount - index); >- items [itemCount] = null; >- item.view.removeFromSuperview(); >+ if (isUnified()) { >+ toolbar.removeItemAtIndex(index); >+ } else { >+ items [itemCount] = null; >+ item.view.removeFromSuperview(); >+ } > relayout (); > } > >@@ -399,6 +458,10 @@ > return -1; > } > >+boolean isUnified() { >+ return ((style & SWT.SMOOTH) == SWT.SMOOTH); >+} >+ > int [] layoutHorizontal (int width, int height, boolean resize) { > int xSpacing = 0, ySpacing = 2; > int marginWidth = 0, marginHeight = 0; >@@ -474,6 +537,10 @@ > } > > int [] layout (int nWidth, int nHeight, boolean resize) { >+ if (isUnified()) { >+ Rectangle rect = getClientArea(); >+ return new int[] { 1, rect.width, rect.height }; >+ } > if ((style & SWT.VERTICAL) != 0) { > return layoutVertical (nWidth, nHeight, resize); > } else { >@@ -481,12 +548,26 @@ > } > } > >+void register() { >+ super.register(); >+ if (isUnified()) { >+ display.addWidget (toolbar, this); >+ } >+} >+ > void relayout () { > if (!getDrawing()) return; > Rectangle rect = getClientArea (); > layout (rect.width, rect.height, true); > } > >+void release (boolean destroy) { >+ if (isUnified()) { >+ parent = null; >+ } >+ >+ super.release(destroy); >+} > void releaseChildren (boolean destroy) { > if (items != null) { > for (int i=0; i<itemCount; i++) { >@@ -502,11 +583,30 @@ > } > > void releaseHandle () { >- super.releaseHandle (); >+ if (isUnified()) { >+ /* >+ * The super#releaseHandle() will call view#release() and will cause >+ * a crash, because it'll try to release the view, which was not >+ * created in a way that would bump up its reference count e.g. using >+ * alloc(), retain() etc., but was kind of 'attached' to the >+ * NSToolbarView hosting the toolbar (see createHandle() above). >+ * Don't call super.releaseHandle() for the the NSToolbar case. >+ */ >+ toolbar.release(); >+ toolbar = null; >+ } else { >+ super.releaseHandle (); >+ } > if (accessibilityAttributes != null) accessibilityAttributes.release(); > accessibilityAttributes = null; > } > >+void releaseParent () { >+ if (parent != null) { >+ super.releaseParent(); >+ } >+} >+ > void removeControl (Control control) { > super.removeControl (control); > for (int i=0; i<itemCount; i++) { >@@ -520,6 +620,16 @@ > relayout (); > } > >+void sendSelection (int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) { >+ for (int i = 0; i < itemCount; i++) { >+ ToolItem item = items[i]; >+ if (item.nsItem.id == arg0) { >+ item.postEvent(SWT.Selection); >+ break; >+ } >+ } >+} >+ > void setFont(NSFont font) { > for (int i = 0; i < itemCount; i++) { > ToolItem item = items[i]; >@@ -533,4 +643,63 @@ > if (redraw && drawCount == 0) relayout(); > } > >+public void setVisible(boolean visible) { >+ if (isUnified()) { >+ toolbar.setVisible(visible); >+ } else { >+ super.setVisible(visible); >+ } >+} >+ >+void setZOrder() { >+ if (toolbar != null) return; >+ super.setZOrder(); >+} >+ >+int /*long*/ toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar(int /*long*/ id, int /*long*/ sel, int /*long*/ toolbar, int /*long*/ itemIdentifier, boolean flag) { >+ NSString itemID = new NSString(itemIdentifier); >+ for (int j = 0; j < itemCount; j++) { >+ ToolItem item = items[j]; >+ if (itemID.isEqual(item.id)) { >+ return item.nsItem.id; >+ } >+ } >+ return 0; >+} >+ >+int /*long*/ toolbarAllowedItemIdentifiers(int /*long*/ id, int /*long*/ sel, int /*long*/ toolbar) { >+ NSMutableArray array = NSMutableArray.arrayWithCapacity(itemCount); >+ for (int i = 0; i < itemCount; i++) { >+ ToolItem item = items[i]; >+ NSString itemId = null; >+ if (((item.style & SWT.SEPARATOR) != 0) && (item.control == null)) { >+ itemId = OS.NSToolbarSeparatorItemIdentifier; >+ } else if ((item.style & SWT.SPACER) != 0) { >+ itemId = OS.NSToolbarSpaceItemIdentifier; >+ } else if ((item.style & SWT.FLEX_SPACER) != 0) { >+ itemId = OS.NSToolbarFlexibleSpaceItemIdentifier; >+ } else { >+ itemId = item.id; >+ } >+ array.addObject(itemId); >+ } >+ return array.id; >+} >+ >+int /*long*/ toolbarDefaultItemIdentifiers(int /*long*/ id, int /*long*/ sel, int /*long*/ toolbar) { >+ return toolbarAllowedItemIdentifiers(id, sel, toolbar); >+} >+ >+boolean validateToolbarItem(int id, int sel, int toolbarItem) { >+ NSToolbarItem nsItem = new NSToolbarItem(toolbarItem); >+ for (int itemIx = 0; itemIx < itemCount; itemIx++) { >+ ToolItem item = items[itemIx]; >+ if (item.nsItem.id == nsItem.id) { >+ return item.getEnabled(); >+ } >+ } >+ >+ return true; >+} >+ > } >Index: org/eclipse/swt/widgets/Display.java >=================================================================== >--- org/eclipse/swt/widgets/Display.java (revision 4159) >+++ org/eclipse/swt/widgets/Display.java (revision 4225) >@@ -2437,6 +2437,16 @@ > OS.class_addMethod(cls, OS.sel_timerProc_, proc3, "@:@"); > OS.class_addMethod(cls, OS.sel_systemSettingsChanged_, proc3, "@:@"); > OS.objc_registerClassPair(cls); >+ >+ className = "SWTToolbar"; >+ cls = OS.objc_allocateClassPair(OS.class_NSToolbar, className, 0); >+ OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types); >+ OS.class_addMethod(cls, OS.sel_toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar_, proc5, "@:@@Z"); >+ OS.class_addMethod(cls, OS.sel_toolbarAllowedItemIdentifiers_, proc3, "@:@"); >+ OS.class_addMethod(cls, OS.sel_toolbarDefaultItemIdentifiers_, proc3, "@:@"); >+ OS.class_addMethod(cls, OS.sel_sendSelection_, proc3, "@:@"); >+ OS.class_addMethod(cls, OS.sel_validateToolbarItem_, proc3, "@:@"); >+ OS.objc_registerClassPair(cls); > } > > NSFont getFont (int /*long*/ cls, int /*long*/ sel) { >@@ -4788,7 +4798,16 @@ > widget.setObjectValue(id, sel, arg0); > } else if (sel == OS.sel_updateOpenGLContext_) { > widget.updateOpenGLContext(id, sel, arg0); >- } >+ } else if (sel == OS.sel_toolbarAllowedItemIdentifiers_) { >+ return widget.toolbarAllowedItemIdentifiers(id, sel, arg0); >+ } else if (sel == OS.sel_toolbarDefaultItemIdentifiers_) { >+ return widget.toolbarDefaultItemIdentifiers(id, sel, arg0); >+ } else if (sel == OS.sel_sendSelection_) { >+ widget.sendSelection(id, sel, arg0); >+ } else if (sel == OS.sel_validateToolbarItem_) { >+ return widget.validateToolbarItem(id, sel, arg0) ? 1 : 0; >+ } >+ > return 0; > } > >@@ -4876,6 +4895,8 @@ > return (widget.tableView_writeRowsWithIndexes_toPasteboard(id, sel, arg0, arg1, arg2) ? 1 : 0); > } else if (sel == OS.sel_outlineView_writeItems_toPasteboard_) { > return (widget.outlineView_writeItems_toPasteboard(id, sel, arg0, arg1, arg2) ? 1 : 0); >+ } else if (sel == OS.sel_toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar_) { >+ return widget.toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar(id, sel, arg0, arg1, arg2 != 0); > } > return 0; > } >Index: org/eclipse/swt/widgets/Widget.java >=================================================================== >--- org/eclipse/swt/widgets/Widget.java (revision 4159) >+++ org/eclipse/swt/widgets/Widget.java (revision 4225) >@@ -1306,6 +1306,9 @@ > void sendSelection () { > } > >+void sendSelection (int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) { >+} >+ > void sendVerticalSelection () { > } > >@@ -1686,6 +1689,18 @@ > return result; > } > >+int /*long*/ toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar(int /*long*/ id, int /*long*/ sel, int /*long*/ toolbar, int /*long*/ itemID, boolean flag) { >+ return 0; >+} >+ >+int /*long*/ toolbarAllowedItemIdentifiers(int /*long*/ id, int /*long*/ sel, int /*long*/ toolbar) { >+ return 0; >+} >+ >+int /*long*/ toolbarDefaultItemIdentifiers(int /*long*/ id, int /*long*/ sel, int /*long*/ toolbar) { >+ return 0; >+} >+ > String tooltipText () { > return null; > } >@@ -1764,4 +1779,8 @@ > void updateOpenGLContext(int /*long*/ id, int /*long*/ sel, int /*long*/ notification) { > } > >+boolean validateToolbarItem(int id, int sel, int arg0) { >+ return true; >+} >+ > } >Index: org/eclipse/swt/widgets/ToolItem.java >=================================================================== >--- org/eclipse/swt/widgets/ToolItem.java (revision 4159) >+++ org/eclipse/swt/widgets/ToolItem.java (revision 4225) >@@ -39,6 +39,8 @@ > public class ToolItem extends Item { > NSView view; > NSButton button; >+ NSToolbarItem nsItem; >+ NSString id; > int width = DEFAULT_SEPARATOR_WIDTH; > ToolBar parent; > Image hotImage, disabledImage; >@@ -49,6 +51,14 @@ > static final int DEFAULT_WIDTH = 24; > static final int DEFAULT_HEIGHT = 22; > static final int DEFAULT_SEPARATOR_WIDTH = 6; >+ >+ static final int UNIFIED_SMALL_SIZE = 36; >+ static final int UNIFIED_SMALL_IMAGE_SIZE = 24; >+ static final int UNIFIED_SMALL_DROPDOWN_WIDTH = 48; >+ >+ static final int UNIFIED_REGULAR_SIZE = 44; >+ static final int UNIFIED_REGULAR_IMAGE_SIZE = 32; >+ static final int UNIFIED_REGULAR_DROPDOWN_WIDTH = 54; > /* > * An inset of 5, instead of 3, makes for less cramped toolbars and balances > * well with the height imposed by the search control, if such is hosted in >@@ -232,8 +242,14 @@ > } > } else { > if (text.length () != 0 || image != null) { >- NSButton widget = (NSButton)button; >- NSSize size = widget.cell().cellSize(); >+ NSSize size = new NSSize(); >+ if (nsItem == null) { >+ NSButton widget = (NSButton)button; >+ size = widget.cell().cellSize(); >+ } else { >+ size.width = DEFAULT_WIDTH; >+ size.height = DEFAULT_HEIGHT; >+ } > width = (int)Math.ceil(size.width); > height = (int)Math.ceil(size.height); > } else { >@@ -249,37 +265,55 @@ > return new Point (width, height); > } > >+void createDropdown () { >+ if ((parent.toolbar != null) && (style & SWT.DROP_DOWN) != 0) { >+ final Combo combo = new Combo(parent, SWT.READ_ONLY | SWT.SMOOTH); >+ if (parent.toolbar.sizeMode() == NSToolbar.NSToolbarSizeModeSmall) { >+ setWidth(UNIFIED_SMALL_DROPDOWN_WIDTH); >+ } else { >+ setWidth(UNIFIED_REGULAR_DROPDOWN_WIDTH); >+ } >+ setControl(combo); >+ combo.setToolItem(this); >+ } >+} > void createHandle () { >- if ((style & SWT.SEPARATOR) != 0) { >- NSBox widget = (NSBox)new SWTBox().alloc(); >- widget.init(); >- widget.setBoxType(OS.NSBoxSeparator); >- widget.setBorderWidth(0); >- view = widget; >+ if (parent.isUnified()) { >+ id = NSString.stringWith(String.valueOf(++ToolBar.NEXT_ID)); >+ id.retain(); >+ nsItem = ((NSToolbarItem)new NSToolbarItem().alloc()).initWithItemIdentifier(id); >+ nsItem.setTarget(parent.toolbar); >+ nsItem.setAction(OS.sel_sendSelection_); > } else { >- NSView widget = (NSView)new SWTView().alloc(); >- widget.init(); >- button = (NSButton)new SWTButton().alloc(); >- button.init(); >- /* >- * Feature in Cocoa. NSButtons without borders do not leave any margin >- * between their edge and their image. The workaround is to provide a >- * custom cell that displays the image in a better position. >- */ >- NSButtonCell cell = (NSButtonCell)new SWTButtonCell ().alloc ().init (); >- button.setCell (cell); >- cell.release(); >- button.setBordered(false); >- button.setAction(OS.sel_sendSelection); >- button.setTarget(button); >- Font font = parent.font != null ? parent.font : parent.defaultFont (); >- button.setFont(font.handle); >- button.setImagePosition(OS.NSImageOverlaps); >- NSString emptyStr = NSString.stringWith(""); >- button.setTitle(emptyStr); >- button.setEnabled(parent.getEnabled()); >- widget.addSubview(button); >- view = widget; >+ if ((style & SWT.SEPARATOR) != 0) { >+ NSBox widget = (NSBox)new SWTBox().alloc(); >+ widget.init(); >+ widget.setBoxType(OS.NSBoxSeparator); >+ widget.setBorderWidth(0); >+ view = widget; >+ } else { >+ NSView widget = (NSView)new SWTView().alloc(); >+ widget.init(); >+ button = (NSButton)new SWTButton().alloc(); >+ button.init(); >+ /* >+ * Feature in Cocoa. NSButtons without borders do not leave any margin >+ * between their edge and their image. The workaround is to provide a >+ * custom cell that displays the image in a better position. >+ */ >+ NSButtonCell cell = (NSButtonCell)new SWTButtonCell ().alloc ().init (); >+ button.setCell (cell); >+ button.setBordered(false); >+ button.setAction(OS.sel_sendSelection); >+ button.setTarget(button); >+ Font font = parent.font != null ? parent.font : parent.defaultFont (); >+ button.setFont(font.handle); >+ button.setImagePosition(OS.NSImageOverlaps); >+ button.setTitle(NSString.stringWith("")); >+ button.setEnabled(parent.getEnabled()); >+ widget.addSubview(button); >+ view = widget; >+ } > } > } > >@@ -354,8 +388,12 @@ > } > > void enableWidget(boolean enabled) { >- if ((style & SWT.SEPARATOR) == 0) { >- ((NSButton)button).setEnabled(enabled); >+ if (parent.isUnified()) { >+ nsItem.setEnabled(enabled); >+ } else { >+ if ((style & SWT.SEPARATOR) == 0) { >+ ((NSButton)button).setEnabled(enabled); >+ } > } > } > >@@ -372,8 +410,26 @@ > */ > public Rectangle getBounds () { > checkWidget(); >- NSRect rect = view.frame(); >- return new Rectangle((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height); >+ if (parent.isUnified()) { >+ if ((style & SWT.DROP_DOWN) != 0) { >+ NSRect rect = control.topView().frame(); >+ /* >+ * Convert the toolitem rect from toolitem-relative coordinates to its >+ * parent, the toolbar, relative coordinates. >+ */ >+ Point position = getDisplay().map(control, parent, (int)rect.x, (int)rect.y); >+ return new Rectangle((int)position.x, (int)rect.y, (int)rect.width, (int)rect.height); >+ } else { >+ if (parent.toolbar.sizeMode() == NSToolbar.NSToolbarSizeModeSmall) { >+ return new Rectangle(0, 0, UNIFIED_SMALL_SIZE, UNIFIED_SMALL_SIZE); >+ } else { >+ return new Rectangle(0, 0, UNIFIED_REGULAR_SIZE, UNIFIED_REGULAR_SIZE); >+ } >+ } >+ } else { >+ NSRect rect = view.frame(); >+ return new Rectangle((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height); >+ } > } > > void setClipRegion (float /*double*/ x, float /*double*/ y) { >@@ -656,12 +712,23 @@ > if (view != null) view.release (); > if (button != null) button.release (); > view = button = null; >+ if (nsItem != null) { >+ nsItem.release(); >+ nsItem = null; >+ } >+ if (id != null) { >+ id.release(); >+ id = null; >+ } > parent = null; > } > > void releaseWidget () { > super.releaseWidget (); >- control = null; >+ if (control != null) { >+ control.dispose(); >+ control = null; >+ } > toolTipText = null; > image = disabledImage = hotImage = null; > } >@@ -688,6 +755,7 @@ > } > > void setBounds (int x, int y, int width, int height) { >+ if (view == null) return; > NSRect rect = new NSRect(); > rect.x = x; > rect.y = y; >@@ -725,18 +793,58 @@ > if (control.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); > if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT); > } >- if ((style & SWT.SEPARATOR) == 0) return; >- if (this.control == control) return; >- NSBox widget = (NSBox)view; >- if (control == null) { >- widget.setBoxType(OS.NSBoxSeparator); >- } else { >- widget.setBoxType(OS.NSBoxCustom); >- } >+ if (this.control == control) return; >+ Control oldControl = this.control; > this.control = control; >- view.setHidden(control != null); >- if (control != null && !control.isDisposed ()) { >- control.moveAbove (null); >+ if (parent.isUnified()) { >+ /* Unified toolbar case */ >+ NSToolbar toolbar = parent.toolbar; >+ int index = parent.indexOf(this); >+ toolbar.removeItemAtIndex(index); >+ NSString itemId = null; >+ if (control != null) { >+ itemId = id; >+ } else if ((style & SWT.SEPARATOR) != 0){ >+ itemId = OS.NSToolbarSeparatorItemIdentifier; >+ } else if ((style & SWT.SPACER) != 0) { >+ itemId = OS.NSToolbarSpaceItemIdentifier; >+ } else if ((style & SWT.FLEX_SPACER) != 0) { >+ itemId = OS.NSToolbarFlexibleSpaceItemIdentifier; >+ } >+ >+ toolbar.insertItemWithItemIdentifier(itemId, index); >+ nsItem.setView(control != null ? control.topView() : null); >+ if (control != null) { >+ NSSize size = new NSSize(); >+ if ((style & SWT.DROP_DOWN) == 0){ >+ //TODO should not computeSize >+ size.height = control.computeSize(SWT.DEFAULT, SWT.DEFAULT).y; >+ } else { >+ if (parent.toolbar.sizeMode() == NSToolbar.NSToolbarSizeModeSmall) { >+ size.height = UNIFIED_SMALL_IMAGE_SIZE; >+ } else { >+ size.height = UNIFIED_REGULAR_IMAGE_SIZE; >+ } >+ } >+ size.width = width; >+ nsItem.setMinSize(size); >+ nsItem.setMaxSize(size); >+ } >+ if (oldControl != null && !oldControl.isDisposed()) { >+ oldControl.dispose(); >+ } >+ } else { >+ if ((style & SWT.SEPARATOR) == 0) return; >+ NSBox widget = (NSBox)view; >+ if (control == null) { >+ widget.setBoxType(OS.NSBoxSeparator); >+ } else { >+ widget.setBoxType(OS.NSBoxCustom); >+ } >+ view.setHidden(control != null); >+ if (control != null && !control.isDisposed ()) { >+ control.moveAbove (null); >+ } > } > parent.relayout (); > } >@@ -789,8 +897,10 @@ > checkWidget(); > if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); > if ((style & SWT.SEPARATOR) != 0) return; >- disabledImage = image; >- updateImage (true); >+ if ((disabledImage != null) || (image != null)) { >+ disabledImage = image; >+ updateImage (true); >+ } > } > > /** >@@ -823,6 +933,20 @@ > if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); > if ((style & SWT.SEPARATOR) != 0) return; > super.setImage (image); >+ if ((control instanceof Combo) && (control.isDisposed() == false) >+ && ((control.getStyle() & SWT.SMOOTH) != 0)) { >+ Combo combo = (Combo)control; >+ /* >+ * In a Unified toolbar, an NSComboBox will behave like a tool item with an icon >+ * and a dropdown arrow if it has an image and its first string needs to be an empty >+ * string. >+ */ >+ combo.setImage(image); >+ combo.removeAll(); >+ if (image != null) { >+ combo.add(""); >+ } >+ } > updateImage (true); > } > >@@ -887,16 +1011,23 @@ > if (string == null) error (SWT.ERROR_NULL_ARGUMENT); > if ((style & SWT.SEPARATOR) != 0) return; > super.setText (string); >- NSButton widget = (NSButton)button; >- widget.setAttributedTitle(createString()); >- if (text.length() != 0 && image != null) { >- if ((parent.style & SWT.RIGHT) != 0) { >- widget.setImagePosition(OS.NSImageLeft); >- } else { >- widget.setImagePosition(OS.NSImageAbove); >- } >+ if (parent.isUnified()) { >+ char [] chars = new char [text.length ()]; >+ text.getChars (0, chars.length, chars, 0); >+ int length = fixMnemonic (chars); >+ nsItem.setLabel(NSString.stringWithCharacters(chars, length)); > } else { >- widget.setImagePosition(text.length() != 0 ? OS.NSNoImage : OS.NSImageOnly); >+ NSButton widget = (NSButton)button; >+ widget.setAttributedTitle(createString()); >+ if (text.length() != 0 && image != null) { >+ if ((parent.style & SWT.RIGHT) != 0) { >+ widget.setImagePosition(OS.NSImageLeft); >+ } else { >+ widget.setImagePosition(OS.NSImageAbove); >+ } >+ } else { >+ widget.setImagePosition(text.length() != 0 ? OS.NSNoImage : OS.NSImageOnly); >+ } > } > parent.relayout (); > } >@@ -923,8 +1054,19 @@ > */ > public void setToolTipText (String string) { > checkWidget(); >- toolTipText = string; >- parent.checkToolTip (this); >+ if (string == null) { >+ return; >+ } >+ >+ if (parent.isUnified()) { >+ char[] chars = new char [string.length ()]; >+ string.getChars (0, chars.length, chars, 0); >+ int length = fixMnemonic (chars); >+ nsItem.setToolTip(NSString.stringWithCharacters (chars, length)); >+ } else { >+ toolTipText = string; >+ parent.checkToolTip (this); >+ } > } > > void setVisible (boolean visible) { >@@ -950,9 +1092,18 @@ > */ > public void setWidth (int width) { > checkWidget(); >- if ((style & SWT.SEPARATOR) == 0) return; > if (width < 0 || this.width == width) return; >- this.width = width; >+ if (parent.isUnified()) { >+ NSSize size = new NSSize(); >+ //TODO should not computeSize >+ size.height = control != null ? control.computeSize(SWT.DEFAULT, SWT.DEFAULT).y : 0; >+ size.width = width; >+ nsItem.setMinSize(size); >+ nsItem.setMaxSize(size); >+ } else { >+ if ((style & SWT.SEPARATOR) == 0) return; >+ } >+ this.width = width; > parent.relayout(); > } > >@@ -972,24 +1123,28 @@ > image = disabledImage; > } > } >- NSButton widget = (NSButton)button; >- /* >- * Feature in Cocoa. If the NSImage object being set into the button is >- * the same NSImage object that is already there then the button does not >- * redraw itself. This results in the button's image not visually updating >- * if the NSImage object's content has changed since it was last set >- * into the button. The workaround is to explicitly redraw the button. >- */ >- widget.setImage(image != null ? image.handle : null); >- widget.setNeedsDisplay(true); >- if (text.length() != 0 && image != null) { >- if ((parent.style & SWT.RIGHT) != 0) { >- widget.setImagePosition(OS.NSImageLeft); >- } else { >- ((NSButton)button).setImagePosition(OS.NSImageAbove); >- } >+ if (parent.isUnified()) { >+ nsItem.setImage(image != null ? image.handle : null); > } else { >- widget.setImagePosition(text.length() != 0 ? OS.NSNoImage : OS.NSImageOnly); >+ NSButton widget = (NSButton)button; >+ /* >+ * Feature in Cocoa. If the NSImage object being set into the button is >+ * the same NSImage object that is already there then the button does not >+ * redraw itself. This results in the button's image not visually updating >+ * if the NSImage object's content has changed since it was last set >+ * into the button. The workaround is to explicitly redraw the button. >+ */ >+ widget.setImage(image != null ? image.handle : null); >+ widget.setNeedsDisplay(true); >+ if (text.length() != 0 && image != null) { >+ if ((parent.style & SWT.RIGHT) != 0) { >+ widget.setImagePosition(OS.NSImageLeft); >+ } else { >+ ((NSButton)button).setImagePosition(OS.NSImageAbove); >+ } >+ } else { >+ widget.setImagePosition(text.length() != 0 ? OS.NSNoImage : OS.NSImageOnly); >+ } > } > parent.relayout(); > } >Index: org/eclipse/swt/internal/cocoa/NSToolbar.java >=================================================================== >--- org/eclipse/swt/internal/cocoa/NSToolbar.java (revision 4159) >+++ org/eclipse/swt/internal/cocoa/NSToolbar.java (revision 4225) >@@ -12,6 +12,22 @@ > > public class NSToolbar extends NSObject { > >+/* NSToolbarSizeMode */ >+public static final int NSToolbarSizeModeDefault = 0; >+ >+public static final int NSToolbarSizeModeRegular = 1; >+ >+public static final int NSToolbarSizeModeSmall = 2; >+ >+/* NSToolbarDisplayMode */ >+public static final int NSToolbarDisplayModeDefault = 0; >+ >+public static final int NSToolbarDisplayModeIconAndLabel = 1; >+ >+public static final int NSToolbarDisplayModeIconOnly = 2; >+ >+public static final int NSToolbarDisplayModeLabelOnly = 3; >+ > public NSToolbar() { > super(); > } >@@ -49,8 +65,16 @@ > OS.objc_msgSend(this.id, OS.sel_setDisplayMode_, displayMode); > } > >+public void setSizeMode(int /*long*/ sizeMode) { >+ OS.objc_msgSend(this.id, OS.sel_setSizeMode_, sizeMode); >+} >+ > public void setVisible(boolean shown) { > OS.objc_msgSend(this.id, OS.sel_setVisible_, shown); > } > >+public int /*long*/ sizeMode() { >+ return OS.objc_msgSend(this.id, OS.sel_sizeMode); >+} >+ > } >Index: org/eclipse/swt/internal/cocoa/OS.java >=================================================================== >--- org/eclipse/swt/internal/cocoa/OS.java (revision 4159) >+++ org/eclipse/swt/internal/cocoa/OS.java (revision 4225) >@@ -1624,6 +1624,8 @@ > public static final int /*long*/ sel_shouldChangeTextInRange_replacementString_ = sel_registerName("shouldChangeTextInRange:replacementString:"); > public static final int /*long*/ sel_shouldDelayWindowOrderingForEvent_ = sel_registerName("shouldDelayWindowOrderingForEvent:"); > public static final int /*long*/ sel_size = sel_registerName("size"); >+public static final int /*long*/ sel_setSizeMode_ = sel_registerName("setSizeMode:"); >+public static final int /*long*/ sel_sizeMode = sel_registerName("sizeMode"); > public static final int /*long*/ sel_sizeToFit = sel_registerName("sizeToFit"); > public static final int /*long*/ sel_sizeValue = sel_registerName("sizeValue"); > public static final int /*long*/ sel_skipDescendents = sel_registerName("skipDescendents"); >@@ -1735,6 +1737,7 @@ > public static final int /*long*/ sel_userInfo = sel_registerName("userInfo"); > public static final int /*long*/ sel_usesAlternatingRowBackgroundColors = sel_registerName("usesAlternatingRowBackgroundColors"); > public static final int /*long*/ sel_validAttributesForMarkedText = sel_registerName("validAttributesForMarkedText"); >+public static final int /*long*/ sel_validateToolbarItem_ = sel_registerName("validateToolbarItem:"); > public static final int /*long*/ sel_validateVisibleColumns = sel_registerName("validateVisibleColumns"); > public static final int /*long*/ sel_value = sel_registerName("value"); > public static final int /*long*/ sel_valueForKey_ = sel_registerName("valueForKey:");
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 222859
:
97896
|
99000
|
99485
|
99492
|
99494
|
100753
|
129651
|
129697
|
129893
|
129894
|
129909
|
129973
|
130031
|
130057
|
147838
|
170610
|
170611
|
180221
|
180379
|
180532
|
180977
|
189297
|
189299