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 147838 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]
Toolbar patch
toolbar.txt (text/plain), 18.05 KB, created by
Kevin Barnes
on 2009-09-22 17:07:58 EDT
(
hide
)
Description:
Toolbar patch
Filename:
MIME Type:
Creator:
Kevin Barnes
Created:
2009-09-22 17:07:58 EDT
Size:
18.05 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.swt >Index: Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolItem.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolItem.java,v >retrieving revision 1.59 >diff -u -r1.59 ToolItem.java >--- Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolItem.java 28 Aug 2009 20:42:48 -0000 1.59 >+++ Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolItem.java 22 Sep 2009 21:05:05 -0000 >@@ -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; >@@ -245,35 +247,43 @@ > } > > 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.toolbar == null) { >+ 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); >+ 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); >+ button.setTitle(NSString.string()); >+ button.setEnabled(parent.getEnabled()); >+ widget.addSubview(button); >+ 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); >- 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); >- button.setTitle(NSString.string()); >- button.setEnabled(parent.getEnabled()); >- widget.addSubview(button); >- view = widget; >+ 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_); > } > } > >@@ -348,8 +358,12 @@ > } > > void enableWidget(boolean enabled) { >- if ((style & SWT.SEPARATOR) == 0) { >- ((NSButton)button).setEnabled(enabled); >+ if (nsItem == null) { >+ if ((style & SWT.SEPARATOR) == 0) { >+ ((NSButton)button).setEnabled(enabled); >+ } >+ } else { >+ nsItem.setEnabled(enabled); > } > } > >@@ -650,6 +664,10 @@ > 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; > } > >@@ -682,6 +700,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; >@@ -721,16 +740,37 @@ > } > 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); >- } >+ Control oldControl = this.control; > this.control = control; >- view.setHidden(control != null); >- if (control != null && !control.isDisposed ()) { >- control.moveAbove (null); >+ if (nsItem == null) { >+ 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); >+ } >+ } else { >+ NSToolbar toolbar = parent.toolbar; >+ int index = parent.indexOf(this); >+ toolbar.removeItemAtIndex(index); >+ toolbar.insertItemWithItemIdentifier(control != null ? id : OS.NSToolbarSeparatorItemIdentifier, index); >+ nsItem.setView(control != null ? control.topView() : null); >+ if (control != null) { >+ NSSize size = new NSSize(); >+ //TODO should not computeSize >+ size.height = control.computeSize(SWT.DEFAULT, SWT.DEFAULT).y; >+ size.width = width; >+ nsItem.setMinSize(size); >+ nsItem.setMaxSize(size); >+ } >+ if (oldControl != null && !oldControl.isDisposed()) { >+ parent.contentView().addSubview(oldControl.topView(), OS.NSWindowBelow, null); >+ oldControl.setBounds(0,0,0,0); >+ } > } > parent.relayout (); > } >@@ -881,16 +921,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); >+ if (nsItem == null) { >+ 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(OS.NSImageAbove); >+ widget.setImagePosition(text.length() != 0 ? OS.NSNoImage : OS.NSImageOnly); > } > } else { >- widget.setImagePosition(text.length() != 0 ? OS.NSNoImage : OS.NSImageOnly); >+ char [] chars = new char [text.length ()]; >+ text.getChars (0, chars.length, chars, 0); >+ int length = fixMnemonic (chars); >+ nsItem.setLabel(NSString.stringWithCharacters(chars, length)); > } > parent.relayout (); > } >@@ -917,8 +964,15 @@ > */ > public void setToolTipText (String string) { > checkWidget(); >- toolTipText = string; >- parent.checkToolTip (this); >+ if (nsItem == null) { >+ toolTipText = string; >+ parent.checkToolTip (this); >+ } else { >+ char[] chars = new char [string.length ()]; >+ string.getChars (0, chars.length, chars, 0); >+ int length = fixMnemonic (chars); >+ nsItem.setToolTip(NSString.stringWithCharacters (chars, length)); >+ } > } > > void setVisible (boolean visible) { >@@ -947,6 +1001,14 @@ > if ((style & SWT.SEPARATOR) == 0) return; > if (width < 0 || this.width == width) return; > this.width = width; >+ if (nsItem != null) { >+ 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); >+ } > parent.relayout(); > } > >@@ -966,24 +1028,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 (nsItem == null) { >+ 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); > } >- } else { >- widget.setImagePosition(text.length() != 0 ? OS.NSNoImage : OS.NSImageOnly); >+ } else { >+ nsItem.setImage(image != null ? image.handle : null); > } > parent.relayout(); > } >Index: Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolBar.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolBar.java,v >retrieving revision 1.29 >diff -u -r1.29 ToolBar.java >--- Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolBar.java 1 Jul 2009 14:50:26 -0000 1.29 >+++ Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolBar.java 22 Sep 2009 21:05:05 -0000 >@@ -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) { >@@ -201,10 +220,27 @@ > > void createHandle () { > state |= THEME_BACKGROUND; >- NSView widget = (NSView)new SWTView().alloc(); >- widget.init(); >-// widget.setDrawsBackground(false); >- view = widget; >+ if ((style & SWT.SMOOTH) == 0) { >+ NSView widget = (NSView)new SWTView().alloc(); >+ widget.init(); >+ // widget.setDrawsBackground(false); >+ view = widget; >+ } else { >+ //TODO leaking toolbar >+ toolbar = ((NSToolbar)new SWTToolbar().alloc()).initWithIdentifier(NSString.stringWith(String.valueOf(NEXT_ID++))); >+ toolbar.setDelegate(toolbar); >+ 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); >+ } >+ } >+// toolbar.setVisible(false); >+ } > } > > void createItem (ToolItem item, int index) { >@@ -214,10 +250,15 @@ > System.arraycopy (items, 0, newItems, 0, items.length); > items = newItems; > } >- item.createWidget(); >- view.addSubview(item.view); > System.arraycopy (items, index, items, index + 1, itemCount++ - index); > items [index] = item; >+ item.createWidget(); >+ if (toolbar == null) { >+ view.addSubview(item.view); >+ } else { >+ NSString id = (item.style & SWT.SEPARATOR) != 0 ? OS.NSToolbarSeparatorItemIdentifier : item.id; >+ toolbar.insertItemWithItemIdentifier(id, index); >+ } > relayout (); > } > >@@ -227,6 +268,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 +281,12 @@ > } > if (index == itemCount) return; > System.arraycopy (items, index + 1, items, index, --itemCount - index); >- items [itemCount] = null; >- item.view.removeFromSuperview(); >+ if (toolbar == null) { >+ items [itemCount] = null; >+ item.view.removeFromSuperview(); >+ } else { >+ toolbar.removeItemAtIndex(index); >+ } > relayout (); > } > >@@ -474,6 +524,7 @@ > } > > int [] layout (int nWidth, int nHeight, boolean resize) { >+ if (toolbar != null) return new int[]{1, 0, 0}; > if ((style & SWT.VERTICAL) != 0) { > return layoutVertical (nWidth, nHeight, resize); > } else { >@@ -481,6 +532,11 @@ > } > } > >+void register() { >+ super.register(); >+ if (toolbar != null) display.addWidget (toolbar, this); >+} >+ > void relayout () { > if (!getDrawing()) return; > Rectangle rect = getClientArea (); >@@ -503,6 +559,8 @@ > > void releaseHandle () { > super.releaseHandle (); >+ if (toolbar != null) toolbar.release(); >+ toolbar = null; > if (accessibilityAttributes != null) accessibilityAttributes.release(); > accessibilityAttributes = null; > } >@@ -520,6 +578,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 +601,34 @@ > if (redraw && drawCount == 0) relayout(); > } > >+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 = (item.style & SWT.SEPARATOR) != 0 && item.control == null ? OS.NSToolbarSeparatorItemIdentifier : 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); >+} >+ > } >Index: Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java,v >retrieving revision 1.288 >diff -u -r1.288 Display.java >--- Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java 21 Sep 2009 23:29:04 -0000 1.288 >+++ Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java 22 Sep 2009 21:05:05 -0000 >@@ -2295,6 +2295,15 @@ > OS.class_addMethod(cls, OS.sel_sendCancelSelection, proc2, "@:"); > 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.objc_registerClassPair(cls); >+ > cls = registerCellSubclass(NSSearchField.cellClass(), size, align, types); > addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); > NSSearchField.setCellClass(cls); >@@ -4819,6 +4828,12 @@ > NSRect rect = new NSRect(); > OS.memmove(rect, arg0, NSRect.sizeof); > widget.drawBackgroundInClipRect(id, sel, rect); >+ } 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); > } > return 0; > } >@@ -4911,6 +4926,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: Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java,v >retrieving revision 1.128 >diff -u -r1.128 Widget.java >--- Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java 21 Sep 2009 23:29:04 -0000 1.128 >+++ Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java 22 Sep 2009 21:05:05 -0000 >@@ -1327,6 +1327,9 @@ > void sendSelection () { > } > >+void sendSelection (int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) { >+} >+ > void sendVerticalSelection () { > } > >@@ -1719,6 +1722,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; > }
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