/** * Returns the height of a line. * * @return the height of a row of text * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ public int getLineHeight () { checkWidget (); Font font = this.font != null ? this.font : defaultFont(); if ((style & SWT.SINGLE) != 0) { NSDictionary dict = NSDictionary.dictionaryWithObject(font.handle, OS.NSFontAttributeName); NSString str = NSString.stringWith(" "); NSAttributedString attribStr = ((NSAttributedString)new NSAttributedString().alloc()).initWithString(str, dict); NSSize size = attribStr.size(); attribStr.release(); return (int) size.height; } else { NSTextView widget = (NSTextView)view; return (int)Math.ceil(widget.layoutManager().defaultLineHeightForFont(font.handle)); } }
long /*int*/ attributedSubstringFromRange (long /*int*/ id, long /*int*/ sel, long /*int*/ rangePtr) { Event event = new Event (); event.detail = SWT.COMPOSITION_SELECTION; sendEvent (SWT.ImeComposition, event); NSRange range = new NSRange (); OS.memmove (range, rangePtr, NSRange.sizeof); int start = (int)/*64*/range.location; int end = (int)/*64*/(range.location + range.length); if (event.start <= start && start <= event.end && event.start <= end && end <= event.end) { NSString str = (NSString) new NSString().alloc(); str = str.initWithString(event.text.substring(start - event.start, end - event.start)); NSAttributedString attriStr = ((NSAttributedString)new NSAttributedString().alloc()).initWithString(str, null); str.release(); attriStr.autorelease (); return attriStr.id; } return 0; }
NSRect drawTitleWithFrameInView (long /*int*/ id, long /*int*/ sel, long /*int*/ title, NSRect titleRect, long /*int*/ view) { boolean wrap = (style & SWT.WRAP) != 0 && text.length() != 0; if (wrap) { NSSize wrapSize = new NSSize(); wrapSize.width = titleRect.width; wrapSize.height = MAX_SIZE; NSAttributedString attribStr = createString(text, null, foreground, style, true, true, true); NSRect rect = attribStr.boundingRectWithSize(wrapSize, OS.NSStringDrawingUsesLineFragmentOrigin); switch (style & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) { case SWT.LEFT: rect.x = titleRect.x; break; case SWT.CENTER: rect.x = titleRect.x + (titleRect.width - rect.width) / 2f; break; case SWT.RIGHT: rect.x = titleRect.x + titleRect.width - rect.width; break; } rect.y = titleRect.y + (titleRect.height - rect.height) / 2; attribStr.drawInRect(rect); attribStr.release (); return rect; } return super.drawTitleWithFrameInView(id, sel, title, titleRect, view); }
void comboBoxSelectionDidChange(long /*int*/ id, long /*int*/ sel, long /*int*/ notification) { NSComboBox widget = (NSComboBox)view; long /*int*/ tableSelection = widget.indexOfSelectedItem(); widget.selectItemAtIndex(tableSelection); NSAttributedString attStr = new NSAttributedString (widget.itemObjectValueAtIndex(tableSelection)); NSString nsString = attStr.string(); if (nsString != null) setText(nsString.getString(), true); if (!ignoreSelection) sendSelectionEvent (SWT.Selection, null, display.trackingControl != this); }
NSAttributedString attribStr = ((NSAttributedString)new NSAttributedString().alloc()).initWithString(str, dict); dict.release(); str.release();
Font font = Font.cocoa_new(display, headerCell.font ()); attrString = parent.createString(displayText, font, null, SWT.LEFT, false, (parent.state & DISABLED) == 0, false); stringSize = attrString.size (); contentWidth += Math.ceil (stringSize.width); if (image != null) contentWidth += MARGIN; /* space between image and text */ destRect.width = Math.min (stringSize.width, cellRect.x + cellRect.width - MARGIN - drawX); destRect.height = Math.min (stringSize.height, cellRect.height); attrString.drawInRect (destRect); if (attrString != null) attrString.release ();
NSRect drawTitleWithFrameInView (long /*int*/ id, long /*int*/ sel, long /*int*/ title, NSRect titleRect, long /*int*/ view) { boolean hiliteShadow = new NSButtonCell(id).isHighlighted() && text.length() > 0 && image == null; // An unbordered cell doesn't draw any highlighting when pushed or selected, so we have to do it here. if (hiliteShadow) { NSColor transWhiteColor = NSColor.colorWithDeviceRed(1.0f, 1.0f, 1.0f, .8f); NSAttributedString attribStr = new NSAttributedString(title); NSMutableAttributedString tmpString = new NSMutableAttributedString(attribStr.mutableCopy()); NSRange range = new NSRange(); range.location = 0; range.length = attribStr.length(); tmpString.addAttribute(OS.NSForegroundColorAttributeName, transWhiteColor, range); tmpString.autorelease(); title = tmpString.id; } return super.drawTitleWithFrameInView(id, sel, title, titleRect, view); }
NSAttributedString attribStr = new NSAttributedString (string); str = attribStr.string (); int length = (int)/*64*/str.length (); styles = new TextStyle [length]; long /*int*/ ptr = OS.malloc (NSRange.sizeof); for (int i = 0; i < length;) { NSDictionary attribs = attribStr.attributesAtIndex(i, ptr, rangeLimit); OS.memmove (effectiveRange, ptr, NSRange.sizeof); i = (int)/*64*/(effectiveRange.location + effectiveRange.length);
public NSAttributedString attributedTitle() { long /*int*/ result = OS.objc_msgSend(this.id, OS.sel_attributedTitle); return result != 0 ? new NSAttributedString(result) : null; }
void releaseHandle () { super.releaseHandle (); if (nsItem != null) nsItem.release(); nsItem = null; if (attriStr != null) attriStr.release(); attriStr = null; parent = null; }
NSMutableAttributedString newStr = new NSMutableAttributedString(cell.attributedStringValue().mutableCopy()); NSRange range = new NSRange(); range.length = newStr.length(); NSSize size = attrStr.size(); if (rect.height > size.height) { rect.y += (rect.height - size.height) / 2;
wrapSize.height = MAX_SIZE; NSAttributedString attribStr = createString(text, null, foreground, style, true, true, true); NSRect rect = attribStr.boundingRectWithSize(wrapSize, OS.NSStringDrawingUsesLineFragmentOrigin); attribStr.release(); double /*float*/ trimHeight = size.height - titleRect.height; size.height = rect.height;
NSAttributedString createString(String string) { NSAttributedString attribStr = createString(string, null, foreground, SWT.LEFT, false, true, false); attribStr.autorelease(); return attribStr; }
void drawLabelInRect(long /*int*/ id, long /*int*/ sel, boolean shouldTruncateLabel, NSRect rect) { if (image != null && !image.isDisposed()) { NSSize imageSize = image.handle.size(); NSRect destRect = new NSRect(); destRect.x = rect.x; destRect.y = rect.y; destRect.width = imageSize.width; destRect.height = imageSize.height; NSGraphicsContext.static_saveGraphicsState(); NSAffineTransform transform = NSAffineTransform.transform(); transform.scaleXBy(1, -1); transform.translateXBy(0, -(destRect.height + 2 * destRect.y)); transform.concat(); image.handle.drawInRect(destRect, new NSRect(), OS.NSCompositeSourceOver, 1); NSGraphicsContext.static_restoreGraphicsState(); rect.x += imageSize.width + IMAGE_GAP; rect.width -= imageSize.width + IMAGE_GAP; } if (attriStr != null) { attriStr.drawInRect(rect); } super.drawLabelInRect(id, sel, shouldTruncateLabel, rect); }
boolean insertText (long /*int*/ id, long /*int*/ sel, long /*int*/ string) { if (startOffset == -1) return true; NSString str = new NSString (string); if (str.isKindOfClass (OS.class_NSAttributedString)) { str = new NSAttributedString (string).string (); } int length = (int)/*64*/str.length (); int end = startOffset + text.length (); resetStyles (); caretOffset = commitCount = length; Event event = new Event (); event.detail = SWT.COMPOSITION_CHANGED; event.start = startOffset; event.end = end; event.text = text = str.getString(); sendEvent (SWT.ImeComposition, event); text = ""; caretOffset = commitCount = 0; startOffset = -1; return event.doit; }
if (mnemonics) length = fixMnemonic (chars); NSString str = ((NSString)new NSString().alloc()).initWithCharacters(chars, length); NSAttributedString attribStr = ((NSAttributedString) new NSAttributedString ().alloc ()).initWithString (str, dict); str.release(); dict.release();
Font font = Font.cocoa_new(display, headerCell.font ()); attrString = parent.createString(displayText, font, null, SWT.LEFT, false, (parent.state & DISABLED) == 0, false); stringSize = attrString.size (); contentWidth += Math.ceil (stringSize.width); if (image != null) contentWidth += MARGIN; /* space between image and text */ destRect.width = Math.min (stringSize.width, cellRect.x + cellRect.width - MARGIN - drawX); destRect.height = Math.min (stringSize.height, cellRect.height); attrString.drawInRect (destRect); if (attrString != null) attrString.release ();
public static NSAttributedString attributedStringWithAttachment(NSTextAttachment attachment) { long /*int*/ result = OS.objc_msgSend(OS.class_NSAttributedString, OS.sel_attributedStringWithAttachment_, attachment != null ? attachment.id : 0); return result != 0 ? new NSAttributedString(result) : null; }
void updateText (boolean selected) { if (attriStr != null) { attriStr.release(); } double /*float*/ [] foreground = parent.foreground; if (foreground == null && selected && OS.VERSION >= 0x1070) { foreground = display.getNSColorRGB(NSColor.alternateSelectedControlTextColor()); } attriStr = parent.createString(text, null, foreground, 0, false, true, true); //force parent to resize nsItem.setLabel(NSString.string()); }