summaryrefslogtreecommitdiffstats
path: root/bundles/org.eclipse.swt
diff options
context:
space:
mode:
authorSilenio Quarti <silenio>2009-03-26 13:59:15 +0000
committerSilenio Quarti <silenio>2009-03-26 13:59:15 +0000
commit40b5d7f957fe454dda3cc72cef817e7a64eea1d9 (patch)
treef09e6b3298f18d2fecfb97269b8866ee67e27923 /bundles/org.eclipse.swt
parente619d691d044497570fcf3be984cbfd11be66986 (diff)
downloadeclipse.platform.swt-40b5d7f957fe454dda3cc72cef817e7a64eea1d9.tar.gz
eclipse.platform.swt-40b5d7f957fe454dda3cc72cef817e7a64eea1d9.tar.xz
eclipse.platform.swt-40b5d7f957fe454dda3cc72cef817e7a64eea1d9.zip
251608 - Artificial bold and italic style to font
Diffstat (limited to 'bundles/org.eclipse.swt')
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Font.java18
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Path.java1
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Button.java7
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java14
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Label.java6
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/List.java5
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Table.java42
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolItem.java7
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tree.java46
9 files changed, 102 insertions, 44 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Font.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Font.java
index 1626d9db34..89cd377eb3 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Font.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Font.java
@@ -44,7 +44,17 @@ public final class Font extends Resource {
*/
public NSFont handle;
- int extraTraits;
+ /**
+ * the traits not supported to the OS font resource
+ * (Warning: This field is platform dependent)
+ * <p>
+ * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
+ * public API. It is marked public only so that it can be shared
+ * within the packages provided by SWT. It is not available on all
+ * platforms and should never be accessed from application code.
+ * </p>
+ */
+ public int extraTraits;
static final double SYNTHETIC_BOLD = -2.5;
static final double SYNTHETIC_ITALIC = 0.2;
@@ -174,12 +184,12 @@ void addTraits(NSMutableAttributedString attrStr, NSRange range) {
}
}
-void addTraits(NSMutableDictionary attrStr) {
+void addTraits(NSMutableDictionary dict) {
if ((extraTraits & OS.NSBoldFontMask) != 0) {
- attrStr.setObject(NSNumber.numberWithDouble(SYNTHETIC_BOLD), OS.NSStrokeWidthAttributeName);
+ dict.setObject(NSNumber.numberWithDouble(SYNTHETIC_BOLD), OS.NSStrokeWidthAttributeName);
}
if ((extraTraits & OS.NSItalicFontMask) != 0) {
- attrStr.setObject(NSNumber.numberWithDouble(SYNTHETIC_ITALIC), OS.NSObliquenessAttributeName);
+ dict.setObject(NSNumber.numberWithDouble(SYNTHETIC_ITALIC), OS.NSObliquenessAttributeName);
}
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Path.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Path.java
index 77bb5b52c2..b236249b6c 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Path.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Path.java
@@ -325,6 +325,7 @@ public void addString(String string, float x, float y, Font font) {
attrStr.id = attrStr.initWithString(str).id;
attrStr.beginEditing();
attrStr.addAttribute(OS.NSFontAttributeName, font.handle, range);
+ font.addTraits(attrStr, range);
attrStr.endEditing();
textStorage.setAttributedString(attrStr);
attrStr.release();
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Button.java
index f350f5bb41..a1d8f5b569 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Button.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Button.java
@@ -199,8 +199,9 @@ NSAttributedString createString() {
NSColor color = NSColor.colorWithDeviceRed(foreground.handle[0], foreground.handle[1], foreground.handle[2], 1);
dict.setObject(color, OS.NSForegroundColorAttributeName);
}
-
- dict.setObject(getFont().handle, OS.NSFontAttributeName);
+ Font font = this.font != null ? this.font : defaultFont ();
+ dict.setObject(font.handle, OS.NSFontAttributeName);
+ addTraits(dict, font);
int alignment;
if ((style & SWT.CENTER) != 0) {
@@ -211,9 +212,9 @@ NSAttributedString createString() {
alignment = OS.NSRightTextAlignment;
}
NSMutableParagraphStyle pStyle = (NSMutableParagraphStyle)new NSMutableParagraphStyle().alloc().init();
- pStyle.autorelease();
pStyle.setAlignment(alignment);
dict.setObject(pStyle, OS.NSParagraphStyleAttributeName);
+ pStyle.release();
char [] chars = new char [text.length ()];
text.getChars (0, chars.length, chars, 0);
int length = fixMnemonic (chars);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java
index 985255b621..1d07eb16df 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java
@@ -582,6 +582,18 @@ public void addPaintListener(PaintListener listener) {
addListener(SWT.Paint,typedListener);
}
+static final double SYNTHETIC_BOLD = -2.5;
+static final double SYNTHETIC_ITALIC = 0.2;
+
+void addTraits(NSMutableDictionary dict, Font font) {
+ if ((font.extraTraits & OS.NSBoldFontMask) != 0) {
+ dict.setObject(NSNumber.numberWithDouble(SYNTHETIC_BOLD), OS.NSStrokeWidthAttributeName);
+ }
+ if ((font.extraTraits & OS.NSItalicFontMask) != 0) {
+ dict.setObject(NSNumber.numberWithDouble(SYNTHETIC_ITALIC), OS.NSObliquenessAttributeName);
+ }
+}
+
/**
* Adds the listener to the collection of listeners who will
* be notified when traversal events occur, by sending it
@@ -3158,7 +3170,6 @@ public void setFont (Font font) {
}
void setFont (NSFont font) {
- //TODO - bad cast
if (view instanceof NSControl) {
((NSControl)view).setFont(font);
}
@@ -3682,6 +3693,7 @@ NSSize textExtent (String string) {
NSMutableDictionary dict = ((NSMutableDictionary)new NSMutableDictionary().alloc()).initWithCapacity(1);
Font font = this.font != null ? this.font : defaultFont();
dict.setObject(font.handle, OS.NSFontAttributeName);
+ addTraits(dict, font);
int length = string.length();
char[] chars = new char[length];
string.getChars(0, length, chars, 0);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Label.java
index dd57913204..bce6343e58 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Label.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Label.java
@@ -258,9 +258,9 @@ NSAttributedString createString() {
NSColor color = NSColor.colorWithDeviceRed(foreground.handle[0], foreground.handle[1], foreground.handle[2], 1);
dict.setObject(color, OS.NSForegroundColorAttributeName);
}
- if (font != null) {
- dict.setObject(font.handle, OS.NSFontAttributeName);
- }
+ Font font = this.font != null ? this.font : defaultFont ();
+ dict.setObject(font.handle, OS.NSFontAttributeName);
+ addTraits(dict, font);
if ((style & SWT.WRAP) == 0) {
NSMutableParagraphStyle paragraphStyle = (NSMutableParagraphStyle)new NSMutableParagraphStyle ().alloc ().init ();
paragraphStyle.autorelease ();
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/List.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/List.java
index 25ad04d236..edb3532478 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/List.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/List.java
@@ -1424,9 +1424,8 @@ int /*long*/ tableView_objectValueForTableColumn_row(int /*long*/ id, int /*long
dict.setObject(color, OS.NSForegroundColorAttributeName);
}
Font font = this.font != null ? this.font : defaultFont ();
- if (font != null) {
- dict.setObject(font.handle, OS.NSFontAttributeName);
- }
+ dict.setObject(font.handle, OS.NSFontAttributeName);
+ addTraits(dict, font);
String text = items[(int)/*64*/rowIndex];
int length = text.length();
char[] chars = new char[length];
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Table.java
index 617f14fc6f..4b6db811c5 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Table.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Table.java
@@ -2909,36 +2909,54 @@ void tableView_willDisplayCell_forTableColumn_row (int /*long*/ id, int /*long*/
break;
}
}
+ NSTableView widget = (NSTableView)view;
NSTextFieldCell textCell = new NSTextFieldCell (cell);
OS.object_setInstanceVariable(cell, Display.SWT_ROW, rowIndex);
OS.object_setInstanceVariable(cell, Display.SWT_COLUMN, tableColumn);
Image image = index == 0 ? item.image : (item.images == null ? null : item.images [index]);
textCell.setImage (image != null ? image.handle : null);
- NSTableView widget = (NSTableView)view;
+ NSColor color;
if (widget.isRowSelected (rowIndex)) {
- textCell.setTextColor(NSColor.selectedControlTextColor());
+ color = NSColor.selectedControlTextColor();
} else {
Color foreground = item.cellForeground != null ? item.cellForeground [index] : null;
if (foreground == null) foreground = item.foreground;
if (foreground == null) foreground = this.foreground;
if (foreground == null) foreground = defaultForeground();
- NSColor color = NSColor.colorWithDeviceRed (foreground.handle [0], foreground.handle [1], foreground.handle [2], 1);
- textCell.setTextColor(color);
+ color = NSColor.colorWithDeviceRed (foreground.handle [0], foreground.handle [1], foreground.handle [2], 1);
}
- Font font = item.cellFont != null ? item.cellFont [index] : null;
- if (font == null) font = item.font;
- if (font == null) font = this.font;
- if (font == null) font = defaultFont ();
- textCell.setFont(font.handle);
- textCell.setAlignment (OS.NSLeftTextAlignment);
+ int alignment = OS.NSLeftTextAlignment;
if (columnCount > 0) {
int style = columns [index].style;
if ((style & SWT.CENTER) != 0) {
- textCell.setAlignment (OS.NSCenterTextAlignment);
+ alignment = OS.NSCenterTextAlignment;
} else if ((style & SWT.RIGHT) != 0) {
- textCell.setAlignment (OS.NSRightTextAlignment);
+ alignment = OS.NSRightTextAlignment;
}
}
+ Font font = item.cellFont != null ? item.cellFont [index] : null;
+ if (font == null) font = item.font;
+ if (font == null) font = this.font;
+ if (font == null) font = defaultFont ();
+ if (font.extraTraits != 0) {
+ NSMutableDictionary dict = ((NSMutableDictionary)new NSMutableDictionary().alloc()).initWithCapacity(5);
+ dict.setObject (color, OS.NSForegroundColorAttributeName);
+ dict.setObject (font.handle, OS.NSFontAttributeName);
+ addTraits(dict, font);
+ NSMutableParagraphStyle paragraphStyle = (NSMutableParagraphStyle)new NSMutableParagraphStyle ().alloc ().init ();
+ paragraphStyle.setLineBreakMode (OS.NSLineBreakByClipping);
+ paragraphStyle.setAlignment (alignment);
+ dict.setObject (paragraphStyle, OS.NSParagraphStyleAttributeName);
+ paragraphStyle.release ();
+ NSAttributedString attribStr = ((NSAttributedString) new NSAttributedString ().alloc ()).initWithString (textCell.title(), dict);
+ textCell.setAttributedStringValue(attribStr);
+ attribStr.release();
+ dict.release();
+ } else {
+ textCell.setFont(font.handle);
+ textCell.setTextColor(color);
+ textCell.setAlignment (alignment);
+ }
}
NSRect titleRectForBounds (int /*long*/ id, int /*long*/ sel, NSRect cellFrame) {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolItem.java
index 7e146e047e..81d75ce427 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolItem.java
@@ -283,10 +283,9 @@ NSAttributedString createString() {
NSColor color = NSColor.colorWithDeviceRed(foreground.handle[0], foreground.handle[1], foreground.handle[2], 1);
dict.setObject(color, OS.NSForegroundColorAttributeName);
}
- Font font = parent.getFont();
- if (font != null) {
- dict.setObject(font.handle, OS.NSFontAttributeName);
- }
+ Font font = parent.font != null ? parent.font : parent.defaultFont ();
+ dict.setObject(font.handle, OS.NSFontAttributeName);
+ parent.addTraits(dict, font);
char [] chars = new char [text.length ()];
text.getChars (0, chars.length, chars, 0);
int length = fixMnemonic (chars);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tree.java
index 73f6e7758b..7b991301c2 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tree.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tree.java
@@ -1858,37 +1858,55 @@ void outlineView_willDisplayCell_forTableColumn_item (int /*long*/ id, int /*lon
break;
}
}
+ NSOutlineView widget = (NSOutlineView)view;
+ int /*long*/ rowIndex = widget.rowForItem (item.handle);
NSTextFieldCell textCell = new NSTextFieldCell (cell);
OS.object_setInstanceVariable(cell, Display.SWT_ROW, itemID);
OS.object_setInstanceVariable(cell, Display.SWT_COLUMN, tableColumn);
Image image = index == 0 ? item.image : (item.images == null ? null : item.images [index]);
textCell.setImage (image != null ? image.handle : null);
- NSOutlineView widget = (NSOutlineView)view;
- int /*long*/ row = widget.rowForItem (item.handle);
- if (widget.isRowSelected (row)) {
- textCell.setTextColor(NSColor.selectedControlTextColor());
+ NSColor color;
+ if (widget.isRowSelected (rowIndex)) {
+ color = NSColor.selectedControlTextColor();
} else {
Color foreground = item.cellForeground != null ? item.cellForeground [index] : null;
if (foreground == null) foreground = item.foreground;
if (foreground == null) foreground = this.foreground;
if (foreground == null) foreground = defaultForeground();
- NSColor color = NSColor.colorWithDeviceRed (foreground.handle [0], foreground.handle [1], foreground.handle [2], 1);
- textCell.setTextColor(color);
+ color = NSColor.colorWithDeviceRed (foreground.handle [0], foreground.handle [1], foreground.handle [2], 1);
}
- Font font = item.cellFont != null ? item.cellFont [index] : null;
- if (font == null) font = item.font;
- if (font == null) font = this.font;
- if (font == null) font = defaultFont ();
- textCell.setFont(font.handle);
- textCell.setAlignment (OS.NSLeftTextAlignment);
+ int alignment = OS.NSLeftTextAlignment;
if (columnCount > 0) {
int style = columns [index].style;
if ((style & SWT.CENTER) != 0) {
- textCell.setAlignment (OS.NSCenterTextAlignment);
+ alignment = OS.NSCenterTextAlignment;
} else if ((style & SWT.RIGHT) != 0) {
- textCell.setAlignment (OS.NSRightTextAlignment);
+ alignment = OS.NSRightTextAlignment;
}
}
+ Font font = item.cellFont != null ? item.cellFont [index] : null;
+ if (font == null) font = item.font;
+ if (font == null) font = this.font;
+ if (font == null) font = defaultFont ();
+ if (font.extraTraits != 0) {
+ NSMutableDictionary dict = ((NSMutableDictionary)new NSMutableDictionary().alloc()).initWithCapacity(5);
+ dict.setObject (color, OS.NSForegroundColorAttributeName);
+ dict.setObject (font.handle, OS.NSFontAttributeName);
+ addTraits(dict, font);
+ NSMutableParagraphStyle paragraphStyle = (NSMutableParagraphStyle)new NSMutableParagraphStyle ().alloc ().init ();
+ paragraphStyle.setLineBreakMode (OS.NSLineBreakByClipping);
+ paragraphStyle.setAlignment (alignment);
+ dict.setObject (paragraphStyle, OS.NSParagraphStyleAttributeName);
+ paragraphStyle.release ();
+ NSAttributedString attribStr = ((NSAttributedString) new NSAttributedString ().alloc ()).initWithString (textCell.title(), dict);
+ textCell.setAttributedStringValue(attribStr);
+ attribStr.release();
+ dict.release();
+ } else {
+ textCell.setFont(font.handle);
+ textCell.setTextColor(color);
+ textCell.setAlignment (alignment);
+ }
}
void outlineViewColumnDidMove (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {