diff options
Diffstat (limited to 'bundles')
8 files changed, 105 insertions, 2 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 7869c289a6..9d196bf08e 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 @@ -283,6 +283,12 @@ <arg swt_gen="true"></arg> <retval swt_gen="true"></retval> </method> + <method class_method="true" selector="bezierPathWithRoundedRect:xRadius:yRadius:" swt_gen="true"> + <arg swt_gen="true"></arg> + <arg swt_gen="true"></arg> + <arg swt_gen="true"></arg> + <retval swt_gen="true"></retval> + </method> <method selector="bounds" swt_gen="true"> <retval swt_gen="true"></retval> </method> @@ -2946,9 +2952,17 @@ <method selector="cancelButtonCell" swt_gen="true"> <retval swt_gen="true"></retval> </method> + <method selector="cancelButtonRectForBounds:" swt_gen="true"> + <arg swt_gen="true"></arg> + <retval swt_gen="true"></retval> + </method> <method selector="searchButtonCell" swt_gen="true"> <retval swt_gen="true"></retval> </method> + <method selector="searchButtonRectForBounds:" swt_gen="true"> + <arg swt_gen="true"></arg> + <retval swt_gen="true"></retval> + </method> <method selector="searchTextRectForBounds:" swt_gen="true"> <arg swt_gen="true"></arg> <retval swt_gen="true"></retval> diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSBezierPath.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSBezierPath.java index 5f81279e8b..b48bad7c88 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSBezierPath.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSBezierPath.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2017 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -71,6 +71,11 @@ public static NSBezierPath bezierPathWithRect(NSRect rect) { return result != 0 ? new NSBezierPath(result) : null; } +public static NSBezierPath bezierPathWithRoundedRect(NSRect rect, double /*float*/ xRadius, double /*float*/ yRadius) { + long /*int*/ result = OS.objc_msgSend(OS.class_NSBezierPath, OS.sel_bezierPathWithRoundedRect_xRadius_yRadius_, rect, xRadius, yRadius); + return result != 0 ? new NSBezierPath(result) : null; +} + public NSRect bounds() { NSRect result = new NSRect(); OS.objc_msgSend_stret(result, this.id, OS.sel_bounds); diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSSearchFieldCell.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSSearchFieldCell.java index bf3a4b9368..e3fd11cc7b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSSearchFieldCell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSSearchFieldCell.java @@ -29,11 +29,23 @@ public NSButtonCell cancelButtonCell() { return result != 0 ? new NSButtonCell(result) : null; } +public NSRect cancelButtonRectForBounds(NSRect rect) { + NSRect result = new NSRect(); + OS.objc_msgSend_stret(result, this.id, OS.sel_cancelButtonRectForBounds_, rect); + return result; +} + public NSButtonCell searchButtonCell() { long /*int*/ result = OS.objc_msgSend(this.id, OS.sel_searchButtonCell); return result != 0 ? new NSButtonCell(result) : null; } +public NSRect searchButtonRectForBounds(NSRect rect) { + NSRect result = new NSRect(); + OS.objc_msgSend_stret(result, this.id, OS.sel_searchButtonRectForBounds_, rect); + return result; +} + public NSRect searchTextRectForBounds(NSRect rect) { NSRect result = new NSRect(); OS.objc_msgSend_stret(result, this.id, OS.sel_searchTextRectForBounds_, rect); 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 c32c57de3a..a44b3a8e1e 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 @@ -1060,6 +1060,7 @@ public static final long /*int*/ sel_bestRepresentationForDevice_ = sel_register public static final long /*int*/ sel_bezierPath = sel_registerName("bezierPath"); public static final long /*int*/ sel_bezierPathByFlatteningPath = sel_registerName("bezierPathByFlatteningPath"); public static final long /*int*/ sel_bezierPathWithRect_ = sel_registerName("bezierPathWithRect:"); +public static final long /*int*/ sel_bezierPathWithRoundedRect_xRadius_yRadius_ = sel_registerName("bezierPathWithRoundedRect:xRadius:yRadius:"); public static final long /*int*/ sel_bitmapData = sel_registerName("bitmapData"); public static final long /*int*/ sel_bitmapFormat = sel_registerName("bitmapFormat"); public static final long /*int*/ sel_bitmapImageRepForCachingDisplayInRect_ = sel_registerName("bitmapImageRepForCachingDisplayInRect:"); @@ -1095,6 +1096,7 @@ public static final long /*int*/ sel_canUndo = sel_registerName("canUndo"); public static final long /*int*/ sel_cancel = sel_registerName("cancel"); public static final long /*int*/ sel_cancelAuthenticationChallenge_ = sel_registerName("cancelAuthenticationChallenge:"); public static final long /*int*/ sel_cancelButtonCell = sel_registerName("cancelButtonCell"); +public static final long /*int*/ sel_cancelButtonRectForBounds_ = sel_registerName("cancelButtonRectForBounds:"); public static final long /*int*/ sel_cancelOperation_ = sel_registerName("cancelOperation:"); public static final long /*int*/ sel_cancelTracking = sel_registerName("cancelTracking"); public static final long /*int*/ sel_cascadeTopLeftFromPoint_ = sel_registerName("cascadeTopLeftFromPoint:"); @@ -1804,6 +1806,7 @@ public static final long /*int*/ sel_scrollWheel_ = sel_registerName("scrollWhee public static final long /*int*/ sel_scrollerWidth = sel_registerName("scrollerWidth"); public static final long /*int*/ sel_scrollerWidthForControlSize_ = sel_registerName("scrollerWidthForControlSize:"); public static final long /*int*/ sel_searchButtonCell = sel_registerName("searchButtonCell"); +public static final long /*int*/ sel_searchButtonRectForBounds_ = sel_registerName("searchButtonRectForBounds:"); public static final long /*int*/ sel_searchTextRectForBounds_ = sel_registerName("searchTextRectForBounds:"); public static final long /*int*/ sel_secondOfMinute = sel_registerName("secondOfMinute"); public static final long /*int*/ sel_secondarySelectedControlColor = sel_registerName("secondarySelectedControlColor"); @@ -3349,7 +3352,7 @@ public static final native void CFRunLoopStop(long /*int*/ rl); public static final native long /*int*/ CFStringCreateWithCharacters(long /*int*/ alloc, char[] chars, long /*int*/ numChars); /** * @param allocator cast=(CFAllocatorRef) - * @param fsRef cast=(struct FSRef*) + * @param fsRef cast=(structFSRef*) */ public static final native long /*int*/ CFURLCreateFromFSRef(long /*int*/ allocator, byte[] fsRef); /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/SWTSearchField.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/SWTSearchField.java index 58a79640b6..58693737c1 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/SWTSearchField.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/SWTSearchField.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.swt.internal.cocoa; + public class SWTSearchField extends NSSearchField { } diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/SWTSearchFieldCell.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/SWTSearchFieldCell.java new file mode 100644 index 0000000000..741e91b9b9 --- /dev/null +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/SWTSearchFieldCell.java @@ -0,0 +1,16 @@ +package org.eclipse.swt.internal.cocoa; + +public class SWTSearchFieldCell extends NSSearchFieldCell { + + public SWTSearchFieldCell() { + super(); + } + + public SWTSearchFieldCell(id id) { + super(id); + } + + public SWTSearchFieldCell(long id) { + super(id); + } +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java index 20b917ea72..4bed47a96d 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java @@ -2749,6 +2749,16 @@ void initClasses () { cls = registerCellSubclass(NSSearchField.cellClass(), size, align, types); addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); + className = "SWTSearchFieldCell"; + cls = OS.objc_allocateClassPair(OS.class_NSSearchFieldCell, className, 0); + OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types); + addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); + OS.class_addMethod(cls, OS.sel_drawInteriorWithFrame_inView_, drawInteriorWithFrameInViewProc, "@:{NSRect}@"); + OS.objc_registerClassPair(cls); + + // replace default search field class + NSSearchField.setCellClass(cls); + // Don't subclass NSSecureTextFieldCell -- you'll get an NSException from [NSSecureTextField setCellClass:]! className = "SWTSecureTextField"; cls = OS.objc_allocateClassPair(OS.class_NSSecureTextField, className, 0); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Text.java index 8e3b54ea82..9f3ebf695c 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Text.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Text.java @@ -692,14 +692,56 @@ void drawInteriorWithFrame_inView(long /*int*/ id, long /*int*/ sel, NSRect cell Control control = findBackgroundControl(); if (control == null) control = this; Image image = control.backgroundImage; + if (image != null && !image.isDisposed()) { NSGraphicsContext context = NSGraphicsContext.currentContext(); control.fillBackground (view, context, cellFrame, -1); + } else if ((style & SWT.SEARCH) != 0) { + // If no background image is set, call custom paint code for search field + drawInteriorWithFrame_inView_searchfield(id, sel, cellFrame, viewid); } + super.drawInteriorWithFrame_inView(id, sel, cellFrame, viewid); } +void drawInteriorWithFrame_inView_searchfield(long /*int*/ id, long /*int*/ sel, NSRect cellFrame, long /*int*/ viewid) { + /* + * Cocoa does not support a background color for the search field. Therefore we + * paint it ourselves, if a background color is set. + */ + if (background == null) { + return; + } + // Shrink the cell frame by 1px on each side, to keep the border drawn by Cocoa visible + cellFrame.x += 1.0; + cellFrame.width -= 2.0; + cellFrame.y = (cellFrame.height - 20.0) / 2.0; + cellFrame.height = 20.0; // A search field is always 22px in height. 22-2=20 + + // Create a path of the cellFrame with rounded corners + NSBezierPath path = NSBezierPath.bezierPathWithRoundedRect(cellFrame, 2.0d, 2.0d); + path.addClip(); + + // Create the native color and fill the background with it + NSColor bgColor = NSColor.colorWithDeviceRed (background [0], background [1], background [2], background [3]); + bgColor.setFill(); + path.fill(); + + // Finally, paint the search and cancel icons (if present) on top of the filled background + NSSearchField searchField = ((NSSearchField)view); + NSCell _cell = (NSCell) searchField.cell(); + SWTSearchFieldCell cell = new SWTSearchFieldCell(_cell.id); + + if (cell.searchButtonCell() != null) { + cell.searchButtonCell().drawInteriorWithFrame(cell.searchButtonRectForBounds(cellFrame), view); + } + + if (cell.cancelButtonCell() != null && ((NSSearchField) view).stringValue().length() > 0) { + cell.cancelButtonCell().drawInteriorWithFrame(cell.cancelButtonRectForBounds(cellFrame), view); + } +} + @Override boolean dragDetect (int x, int y, boolean filter, boolean [] consume) { Point selection = getSelection (); |