diff options
author | Felipe Heidrich <fheidric> | 2009-10-02 20:46:07 +0000 |
---|---|---|
committer | Felipe Heidrich <fheidric> | 2009-10-02 20:46:07 +0000 |
commit | 2c8a13d0df1694740c0af6220e23682b3ddd10de (patch) | |
tree | 91b9c14ba95a9ecf66ced415e65f4b6bf921deeb | |
parent | 9b206a3ef3da346ba734676d2f43256fbdc58e5a (diff) | |
download | eclipse.platform.swt-2c8a13d0df1694740c0af6220e23682b3ddd10de.tar.gz eclipse.platform.swt-2c8a13d0df1694740c0af6220e23682b3ddd10de.tar.xz eclipse.platform.swt-2c8a13d0df1694740c0af6220e23682b3ddd10de.zip |
Bug 288554: BIDI improvements
6 files changed, 101 insertions, 36 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/AppKitFull.bridgesupport.extras b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/AppKitFull.bridgesupport.extras index 0c54e835b8..aaf0a84b1f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/AppKitFull.bridgesupport.extras +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/AppKitFull.bridgesupport.extras @@ -1601,6 +1601,10 @@ <method selector="leading" swt_gen="true"> <retval swt_gen="true"></retval> </method> + <method class_method="true" selector="menuFontOfSize:" swt_gen="true"> + <arg name="fontSize" swt_gen="true"></arg> + <retval swt_gen="true"></retval> + </method> <method selector="pointSize" swt_gen="true"> <retval swt_gen="true"></retval> </method> @@ -2085,6 +2089,9 @@ </method> </class> <class name="NSMenuItem" swt_gen="mixed"> + <method selector="attributedTitle" swt_gen="true"> + <retval swt_gen="true"></retval> + </method> <method selector="initWithTitle:action:keyEquivalent:" swt_gen="true"> <arg name="aString" swt_gen="true"></arg> <arg name="aSelector" swt_gen="true"></arg> @@ -4821,26 +4828,26 @@ </informal_protocol> <class name="NSSecureTextField" swt_gen="true" swt_superclass="NSTextField"></class> <informal_protocol name="NSTextInput" swt_gen="true"> - <method selector="markedRange" swt_gen="true" swt_gen_custom_callback="true"></method> + <method selector="hasMarkedText" swt_gen="true"></method> <method selector="insertText:" swt_gen="true"> <arg name="aString" swt_gen="true"></arg> </method> <method selector="unmarkText" swt_gen="true"></method> - <method selector="hasMarkedText" swt_gen="true"></method> - <method selector="validAttributesForMarkedText" swt_gen="true"></method> + <method selector="selectedRange" swt_gen="true" swt_gen_custom_callback="true"></method> <method selector="characterIndexForPoint:" swt_gen="true" swt_gen_custom_callback="true"> <arg name="thePoint" swt_gen="true"></arg> </method> + <method selector="firstRectForCharacterRange:" swt_gen="true" swt_gen_custom_callback="true"> + <arg name="theRange" swt_gen="true"></arg> + </method> + <method selector="validAttributesForMarkedText" swt_gen="true"></method> <method selector="attributedSubstringFromRange:" swt_gen="true" swt_gen_custom_callback="true"> <arg name="theRange" swt_gen="true"></arg> </method> - <method selector="selectedRange" swt_gen="true" swt_gen_custom_callback="true"></method> <method selector="setMarkedText:selectedRange:" swt_gen="true" swt_gen_custom_callback="true"> <arg name="selRange" swt_gen="true"></arg> <arg name="aString" swt_gen="true"></arg> </method> - <method selector="firstRectForCharacterRange:" swt_gen="true" swt_gen_custom_callback="true"> - <arg name="theRange" swt_gen="true"></arg> - </method> + <method selector="markedRange" swt_gen="true" swt_gen_custom_callback="true"></method> </informal_protocol> </signatures> diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSFont.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSFont.java index 1b265d96f1..0ea7888f5d 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSFont.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSFont.java @@ -56,6 +56,11 @@ public float /*double*/ leading() { return (float)OS.objc_msgSend_fpret(this.id, OS.sel_leading); } +public static NSFont menuFontOfSize(float /*double*/ fontSize) { + int /*long*/ result = OS.objc_msgSend(OS.class_NSFont, OS.sel_menuFontOfSize_, fontSize); + return result != 0 ? new NSFont(result) : null; +} + public float /*double*/ pointSize() { return (float)OS.objc_msgSend_fpret(this.id, OS.sel_pointSize); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSMenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSMenuItem.java index da6094c487..483575e85f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSMenuItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSMenuItem.java @@ -24,6 +24,11 @@ public NSMenuItem(id id) { super(id); } +public NSAttributedString attributedTitle() { + int /*long*/ result = OS.objc_msgSend(this.id, OS.sel_attributedTitle); + return result != 0 ? new NSAttributedString(result) : null; +} + public NSMenuItem initWithTitle(NSString aString, int /*long*/ aSelector, NSString charCode) { int /*long*/ result = OS.objc_msgSend(this.id, OS.sel_initWithTitle_action_keyEquivalent_, aString != null ? aString.id : 0, aSelector, charCode != null ? charCode.id : 0); return result == this.id ? this : (result != 0 ? new NSMenuItem(result) : null); diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java index c4ac687560..e3905e5215 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java @@ -1187,6 +1187,7 @@ public static final int /*long*/ sel_maximumIntegerDigits = sel_registerName("ma public static final int /*long*/ sel_menu = sel_registerName("menu"); public static final int /*long*/ sel_menu_willHighlightItem_ = sel_registerName("menu:willHighlightItem:"); public static final int /*long*/ sel_menuDidClose_ = sel_registerName("menuDidClose:"); +public static final int /*long*/ sel_menuFontOfSize_ = sel_registerName("menuFontOfSize:"); public static final int /*long*/ sel_menuForEvent_ = sel_registerName("menuForEvent:"); public static final int /*long*/ sel_menuNeedsUpdate_ = sel_registerName("menuNeedsUpdate:"); public static final int /*long*/ sel_menuWillOpen_ = sel_registerName("menuWillOpen:"); diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/WebKitFull.bridgesupport.extras b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/WebKitFull.bridgesupport.extras index ae1fa48af4..a5edadde01 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/WebKitFull.bridgesupport.extras +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/WebKitFull.bridgesupport.extras @@ -409,17 +409,17 @@ <arg name="sender" swt_gen="true"></arg> </method> </informal_protocol> + <informal_protocol name="WebDocumentRepresentation" swt_gen="true"> + <method selector="documentSource" swt_gen="true"></method> + </informal_protocol> <informal_protocol name="WebOpenPanelResultListener" swt_gen="true"> <method selector="chooseFilename:" swt_gen="true"> <arg name="theRange" swt_gen="true"></arg> </method> </informal_protocol> - <informal_protocol name="WebDocumentRepresentation" swt_gen="true"> - <method selector="documentSource" swt_gen="true"></method> - </informal_protocol> <informal_protocol name="WebPolicyDecisionListener" swt_gen="true"> + <method selector="ignore" swt_gen="true"></method> <method selector="use" swt_gen="true"></method> <method selector="download" swt_gen="true"></method> - <method selector="ignore" swt_gen="true"></method> </informal_protocol> </signatures> diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Combo.java index 068ad52b94..4b57bccc70 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Combo.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Combo.java @@ -130,13 +130,15 @@ public Combo (Composite parent, int style) { public void add (String string) { checkWidget (); if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - NSString str = NSString.stringWith(string); + NSAttributedString str = createString(string); if ((style & SWT.READ_ONLY) != 0) { NSPopUpButton widget = (NSPopUpButton)view; int /*long*/ selection = widget.indexOfSelectedItem(); NSMenu nsMenu = widget.menu(); NSMenuItem nsItem = (NSMenuItem)new NSMenuItem().alloc(); - nsItem.initWithTitle(str, 0, NSString.stringWith("")); + NSString empty = NSString.string(); + nsItem.initWithTitle(empty, 0, empty); + nsItem.setAttributedTitle(str); nsMenu.addItem(nsItem); nsItem.release(); if (selection == -1) widget.selectItemAtIndex(-1); @@ -173,13 +175,15 @@ public void add (String string, int index) { if (string == null) error (SWT.ERROR_NULL_ARGUMENT); int count = getItemCount (); if (0 > index || index > count) error (SWT.ERROR_INVALID_RANGE); - NSString str = NSString.stringWith(string); + NSAttributedString str = createString(string); if ((style & SWT.READ_ONLY) != 0) { NSPopUpButton widget = (NSPopUpButton)view; int /*long*/ selection = widget.indexOfSelectedItem(); NSMenu nsMenu = widget.menu(); NSMenuItem nsItem = (NSMenuItem)new NSMenuItem().alloc(); - nsItem.initWithTitle(str, 0, NSString.stringWith("")); + NSString empty = NSString.string(); + nsItem.initWithTitle(empty, 0, empty); + nsItem.setAttributedTitle(str); nsMenu.insertItem(nsItem, index); nsItem.release(); if (selection == -1) widget.selectItemAtIndex(-1); @@ -340,14 +344,16 @@ public void clearSelection () { } void setObjectValue(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) { - super.setObjectValue(id, sel, ignoreSetObject ? arg0 : NSString.stringWith(text).id); + super.setObjectValue(id, sel, ignoreSetObject ? arg0 : createString(text).id); } void comboBoxSelectionDidChange(int /*long*/ id, int /*long*/ sel, int /*long*/ notification) { NSComboBox widget = (NSComboBox)view; int /*long*/ tableSelection = widget.indexOfSelectedItem(); widget.selectItemAtIndex(tableSelection); - setText(new NSString(widget.itemObjectValueAtIndex(tableSelection)).getString(), true); + NSAttributedString attStr = new NSAttributedString (widget.itemObjectValueAtIndex(tableSelection)); + NSString nsString = attStr.string(); + if (nsString != null) setText(nsString.getString(), true); if (!ignoreSelection) sendEvent(SWT.Selection, null, display.trackingControl != this); } @@ -368,8 +374,8 @@ public Point computeSize (int wHint, int hHint, boolean changed) { if (length > 0) { cell = new NSComboBoxCell (cell.copy ()); for (int i = 0; i < length; i++) { - id object = array.objectAtIndex (i); - cell.setTitle (new NSString (object)); + NSAttributedString attStr = new NSAttributedString (array.objectAtIndex (i)); + cell.setAttributedStringValue(attStr); size = cell.cellSize (); width = Math.max (width, (int)Math.ceil (size.width)); } @@ -428,6 +434,12 @@ void createHandle () { } } +NSAttributedString createString(String string) { + NSAttributedString attribStr = createString(string, null, foreground, SWT.LEFT, false, true, false); + attribStr.autorelease(); + return attribStr; +} + void createWidget() { text = ""; super.createWidget(); @@ -596,11 +608,12 @@ public String getItem (int index) { checkWidget (); int count = getItemCount (); if (0 > index || index >= count) error (SWT.ERROR_INVALID_RANGE); - NSString str; + NSString str = null; if ((style & SWT.READ_ONLY) != 0) { str = ((NSPopUpButton)view).itemTitleAtIndex(index); } else { - str = new NSString(((NSComboBox)view).itemObjectValueAtIndex(index)); + NSAttributedString attString = new NSAttributedString(((NSComboBox)view).itemObjectValueAtIndex(index)); + if (attString != null) str = attString.string(); } if (str == null) error(SWT.ERROR_CANNOT_GET_ITEM); return str.getString(); @@ -1268,16 +1281,21 @@ void setBounds (int x, int y, int width, int height, boolean move, boolean resiz super.setBounds (x, y, width, height, move, resize); } +void setFont (NSFont font) { + super.setFont(font); + updateItems(); +} + void setForeground (float /*double*/ [] color) { - NSColor nsColor; - if (color == null) { - nsColor = NSColor.textColor (); - } else { - nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1); - } - if ((style & SWT.READ_ONLY) != 0) { - //TODO - } else { + super.setForeground(color); + updateItems(); + if ((style & SWT.READ_ONLY) == 0) { + NSColor nsColor; + if (color == null) { + nsColor = NSColor.textColor (); + } else { + nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1); + } ((NSTextField)view).setTextColor(nsColor); } } @@ -1304,10 +1322,10 @@ public void setItem (int index, String string) { int count = getItemCount (); if (0 > index || index >= count) error (SWT.ERROR_INVALID_RANGE); int selection = getSelectionIndex(); - NSString str = NSString.stringWith(string); + NSAttributedString str = createString(string); if ((style & SWT.READ_ONLY) != 0) { NSMenuItem nsItem = ((NSPopUpButton)view).itemAtIndex(index); - nsItem.setTitle(str); + nsItem.setAttributedTitle(str); } else { NSComboBox widget = (NSComboBox)view; widget.insertItemWithObjectValue(str, index); @@ -1339,11 +1357,13 @@ public void setItems (String [] items) { removeAll(); if (items.length == 0) return; for (int i= 0; i < items.length; i++) { - NSString str = NSString.stringWith(items[i]); + NSAttributedString str = createString(items[i]); if ((style & SWT.READ_ONLY) != 0) { NSMenu nsMenu = ((NSPopUpButton)view).menu(); NSMenuItem nsItem = (NSMenuItem)new NSMenuItem().alloc(); - nsItem.initWithTitle(str, 0, NSString.stringWith("")); + NSString empty = NSString.string(); + nsItem.initWithTitle(empty, 0, empty); + nsItem.setAttributedTitle(str); nsMenu.addItem(nsItem); nsItem.release(); //clear the selection @@ -1398,6 +1418,11 @@ public void setOrientation (int orientation) { checkWidget(); } +void setOrientation () { + int direction = (style & SWT.RIGHT_TO_LEFT) != 0 ? OS.NSWritingDirectionRightToLeft : OS.NSWritingDirectionLeftToRight; + ((NSControl)view).setBaseWritingDirection(direction); +} + /** * Sets the selection in the receiver's text field to the * range specified by the argument whose x coordinate is the @@ -1479,8 +1504,7 @@ void setText (String string, boolean notify) { char[] buffer = new char [Math.min(string.length (), textLimit)]; string.getChars (0, buffer.length, buffer, 0); text = new String (buffer,0, buffer.length); - NSString nsstring = NSString.stringWithCharacters (buffer, buffer.length); - ((NSComboBox)view).cell().setTitle(nsstring); + ((NSComboBox)view).cell().setAttributedStringValue(createString(text)); if (notify) sendEvent (SWT.Modify); } selectionRange = null; @@ -1605,6 +1629,29 @@ NSRange textView_willChangeSelectionFromCharacterRange_toCharacterRange(int /*lo return result; } +void updateItems () { + if ((style & SWT.READ_ONLY) != 0) { + NSPopUpButton widget = (NSPopUpButton)view; + int count = (int)/*64*/ widget.numberOfItems(); + for (int i = 0; i < count; i++) { + NSMenuItem item = new NSMenuItem (widget.itemAtIndex(i)); + NSAttributedString attStr = item.attributedTitle(); + String string = attStr.string().getString(); + item.setAttributedTitle(createString(string)); + } + } else { + NSComboBox widget = (NSComboBox)view; + int count = (int)/*64*/ widget.numberOfItems(); + for (int i = 0; i < count; i++) { + NSAttributedString attStr = new NSAttributedString (widget.itemObjectValueAtIndex(i)); + String string = attStr.string().getString(); + widget.insertItemWithObjectValue(createString(string), i); + widget.removeItemAtIndex(i + 1); + } + widget.cell().setAttributedStringValue(createString(text)); + } +} + String verifyText (String string, int start, int end, NSEvent keyEvent) { Event event = new Event (); if (keyEvent != null) setKeyState(event, SWT.MouseDown, keyEvent); |