diff options
author | Scott Kovatch <skovatch> | 2010-10-13 18:07:23 +0000 |
---|---|---|
committer | Scott Kovatch <skovatch> | 2010-10-13 18:07:23 +0000 |
commit | dbc3f579c8454ac59e01ac2d56752eda0d58b6cd (patch) | |
tree | b5eb5ee96acfce462daca5c50fe1bfb109808b42 | |
parent | 0279ac89ad933bec67322b956321e83b2a1ac93a (diff) | |
download | eclipse.platform.swt-dbc3f579c8454ac59e01ac2d56752eda0d58b6cd.tar.gz eclipse.platform.swt-dbc3f579c8454ac59e01ac2d56752eda0d58b6cd.tar.xz eclipse.platform.swt-dbc3f579c8454ac59e01ac2d56752eda0d58b6cd.zip |
222859 - NSToolbar-based ToolBar on Cocoa. Added Shell.getToolBar() for all platforms (mostly null right now).
26 files changed, 920 insertions, 64 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os.c b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os.c index f18f96bdcc..67207bda64 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os.c @@ -1290,6 +1290,20 @@ JNIEXPORT void JNICALL OS_NATIVE(CGContextAddPath) } #endif +#ifndef NO_CGContextBeginTransparencyLayerWithRect +JNIEXPORT void JNICALL OS_NATIVE(CGContextBeginTransparencyLayerWithRect) + (JNIEnv *env, jclass that, jintLong arg0, jobject arg1, jintLong arg2) +{ + CGRect _arg1, *lparg1=NULL; + OS_NATIVE_ENTER(env, that, CGContextBeginTransparencyLayerWithRect_FUNC); + if (arg1) if ((lparg1 = getCGRectFields(env, arg1, &_arg1)) == NULL) goto fail; + CGContextBeginTransparencyLayerWithRect((CGContextRef)arg0, *lparg1, (CFDictionaryRef)arg2); +fail: + if (arg1 && lparg1) setCGRectFields(env, arg1, lparg1); + OS_NATIVE_EXIT(env, that, CGContextBeginTransparencyLayerWithRect_FUNC); +} +#endif + #ifndef NO_CGContextCopyPath JNIEXPORT jintLong JNICALL OS_NATIVE(CGContextCopyPath) (JNIEnv *env, jclass that, jintLong arg0) @@ -1349,6 +1363,16 @@ fail: } #endif +#ifndef NO_CGContextEndTransparencyLayer +JNIEXPORT void JNICALL OS_NATIVE(CGContextEndTransparencyLayer) + (JNIEnv *env, jclass that, jintLong arg0) +{ + OS_NATIVE_ENTER(env, that, CGContextEndTransparencyLayer_FUNC); + CGContextEndTransparencyLayer((CGContextRef)arg0); + OS_NATIVE_EXIT(env, that, CGContextEndTransparencyLayer_FUNC); +} +#endif + #ifndef NO_CGContextFillRect JNIEXPORT void JNICALL OS_NATIVE(CGContextFillRect) (JNIEnv *env, jclass that, jintLong arg0, jobject arg1) @@ -4911,6 +4935,20 @@ JNIEXPORT jint JNICALL OS_NATIVE(NSRange_1sizeof) } #endif +#ifndef NO_NSRectFillUsingOperation +JNIEXPORT void JNICALL OS_NATIVE(NSRectFillUsingOperation) + (JNIEnv *env, jclass that, jobject arg0, jintLong arg1) +{ + NSRect _arg0, *lparg0=NULL; + OS_NATIVE_ENTER(env, that, NSRectFillUsingOperation_FUNC); + if (arg0) if ((lparg0 = getNSRectFields(env, arg0, &_arg0)) == NULL) goto fail; + NSRectFillUsingOperation(*lparg0, (NSCompositingOperation)arg1); +fail: + if (arg0 && lparg0) setNSRectFields(env, arg0, lparg0); + OS_NATIVE_EXIT(env, that, NSRectFillUsingOperation_FUNC); +} +#endif + #ifndef NO_NSRect_1sizeof JNIEXPORT jint JNICALL OS_NATIVE(NSRect_1sizeof) (JNIEnv *env, jclass that) @@ -9440,6 +9478,36 @@ fail: } #endif +#if (!defined(NO_objc_1msgSend_1bool__IILorg_eclipse_swt_internal_cocoa_NSPoint_2Lorg_eclipse_swt_internal_cocoa_NSRect_2) && !defined(JNI64)) || (!defined(NO_objc_1msgSend_1bool__JJLorg_eclipse_swt_internal_cocoa_NSPoint_2Lorg_eclipse_swt_internal_cocoa_NSRect_2) && defined(JNI64)) +#ifndef JNI64 +JNIEXPORT jboolean JNICALL OS_NATIVE(objc_1msgSend_1bool__IILorg_eclipse_swt_internal_cocoa_NSPoint_2Lorg_eclipse_swt_internal_cocoa_NSRect_2)(JNIEnv *env, jclass that, jintLong arg0, jintLong arg1, jobject arg2, jobject arg3) +#else +JNIEXPORT jboolean JNICALL OS_NATIVE(objc_1msgSend_1bool__JJLorg_eclipse_swt_internal_cocoa_NSPoint_2Lorg_eclipse_swt_internal_cocoa_NSRect_2)(JNIEnv *env, jclass that, jintLong arg0, jintLong arg1, jobject arg2, jobject arg3) +#endif +{ + NSPoint _arg2, *lparg2=NULL; + NSRect _arg3, *lparg3=NULL; + jboolean rc = 0; +#ifndef JNI64 + OS_NATIVE_ENTER(env, that, objc_1msgSend_1bool__IILorg_eclipse_swt_internal_cocoa_NSPoint_2Lorg_eclipse_swt_internal_cocoa_NSRect_2_FUNC); +#else + OS_NATIVE_ENTER(env, that, objc_1msgSend_1bool__JJLorg_eclipse_swt_internal_cocoa_NSPoint_2Lorg_eclipse_swt_internal_cocoa_NSRect_2_FUNC); +#endif + if (arg2) if ((lparg2 = getNSPointFields(env, arg2, &_arg2)) == NULL) goto fail; + if (arg3) if ((lparg3 = getNSRectFields(env, arg3, &_arg3)) == NULL) goto fail; + rc = (jboolean)((BOOL (*)(jintLong, jintLong, NSPoint, NSRect))objc_msgSend_bool)(arg0, arg1, *lparg2, *lparg3); +fail: + if (arg3 && lparg3) setNSRectFields(env, arg3, lparg3); + if (arg2 && lparg2) setNSPointFields(env, arg2, lparg2); +#ifndef JNI64 + OS_NATIVE_EXIT(env, that, objc_1msgSend_1bool__IILorg_eclipse_swt_internal_cocoa_NSPoint_2Lorg_eclipse_swt_internal_cocoa_NSRect_2_FUNC); +#else + OS_NATIVE_EXIT(env, that, objc_1msgSend_1bool__JJLorg_eclipse_swt_internal_cocoa_NSPoint_2Lorg_eclipse_swt_internal_cocoa_NSRect_2_FUNC); +#endif + return rc; +} +#endif + #if (!defined(NO_objc_1msgSend_1bool__IILorg_eclipse_swt_internal_cocoa_NSRange_2I) && !defined(JNI64)) || (!defined(NO_objc_1msgSend_1bool__JJLorg_eclipse_swt_internal_cocoa_NSRange_2J) && defined(JNI64)) #ifndef JNI64 JNIEXPORT jboolean JNICALL OS_NATIVE(objc_1msgSend_1bool__IILorg_eclipse_swt_internal_cocoa_NSRange_2I)(JNIEnv *env, jclass that, jintLong arg0, jintLong arg1, jobject arg2, jintLong arg3) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.c b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.c index 90b775d9fe..295c382773 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.c @@ -14,8 +14,8 @@ #ifdef NATIVE_STATS -int OS_nativeFunctionCount = 610; -int OS_nativeFunctionCallCount[610]; +int OS_nativeFunctionCount = 614; +int OS_nativeFunctionCallCount[614]; char * OS_nativeFunctionNames[] = { "ATSFontActivateFromFileReference", "AcquireRootMenu", @@ -85,9 +85,11 @@ char * OS_nativeFunctionNames[] = { "CGColorSpaceCreateDeviceRGB", "CGColorSpaceRelease", "CGContextAddPath", + "CGContextBeginTransparencyLayerWithRect", "CGContextCopyPath", "CGContextCopyWindowContentsToRect", "CGContextDrawImage", + "CGContextEndTransparencyLayer", "CGContextFillRect", "CGContextRelease", "CGContextReplacePathWithStrokedPath", @@ -375,6 +377,7 @@ char * OS_nativeFunctionNames[] = { "NSPrintSpoolJob", "NSRTFPboardType", "NSRange_1sizeof", + "NSRectFillUsingOperation", "NSRect_1sizeof", "NSSearchPathForDirectoriesInDomains", "NSSize_1sizeof", @@ -1081,6 +1084,11 @@ char * OS_nativeFunctionNames[] = { "objc_1msgSend_1bool__JJLorg_eclipse_swt_internal_cocoa_NSPoint_2", #endif #ifndef JNI64 + "objc_1msgSend_1bool__IILorg_eclipse_swt_internal_cocoa_NSPoint_2Lorg_eclipse_swt_internal_cocoa_NSRect_2", +#else + "objc_1msgSend_1bool__JJLorg_eclipse_swt_internal_cocoa_NSPoint_2Lorg_eclipse_swt_internal_cocoa_NSRect_2", +#endif +#ifndef JNI64 "objc_1msgSend_1bool__IILorg_eclipse_swt_internal_cocoa_NSRange_2I", #else "objc_1msgSend_1bool__JJLorg_eclipse_swt_internal_cocoa_NSRange_2J", diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.h index f4ac473da6..aa26c57125 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.h @@ -93,9 +93,11 @@ typedef enum { CGColorSpaceCreateDeviceRGB_FUNC, CGColorSpaceRelease_FUNC, CGContextAddPath_FUNC, + CGContextBeginTransparencyLayerWithRect_FUNC, CGContextCopyPath_FUNC, CGContextCopyWindowContentsToRect_FUNC, CGContextDrawImage_FUNC, + CGContextEndTransparencyLayer_FUNC, CGContextFillRect_FUNC, CGContextRelease_FUNC, CGContextReplacePathWithStrokedPath_FUNC, @@ -383,6 +385,7 @@ typedef enum { NSPrintSpoolJob_FUNC, NSRTFPboardType_FUNC, NSRange_1sizeof_FUNC, + NSRectFillUsingOperation_FUNC, NSRect_1sizeof_FUNC, NSSearchPathForDirectoriesInDomains_FUNC, NSSize_1sizeof_FUNC, @@ -1089,6 +1092,11 @@ typedef enum { objc_1msgSend_1bool__JJLorg_eclipse_swt_internal_cocoa_NSPoint_2_FUNC, #endif #ifndef JNI64 + objc_1msgSend_1bool__IILorg_eclipse_swt_internal_cocoa_NSPoint_2Lorg_eclipse_swt_internal_cocoa_NSRect_2_FUNC, +#else + objc_1msgSend_1bool__JJLorg_eclipse_swt_internal_cocoa_NSPoint_2Lorg_eclipse_swt_internal_cocoa_NSRect_2_FUNC, +#endif +#ifndef JNI64 objc_1msgSend_1bool__IILorg_eclipse_swt_internal_cocoa_NSRange_2I_FUNC, #else objc_1msgSend_1bool__JJLorg_eclipse_swt_internal_cocoa_NSRange_2J_FUNC, 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 4ddd357263..d2d941f30b 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 @@ -654,6 +654,10 @@ <arg swt_gen="true"></arg> <retval swt_gen="true"></retval> </method> + <method selector="setHighlightsBy:" swt_gen="true"> + <arg swt_gen="true"></arg> + <retval swt_gen="true"></retval> + </method> <method selector="setImagePosition:" swt_gen="true"> <arg swt_gen="true"></arg> <retval swt_gen="true"></retval> @@ -746,6 +750,10 @@ <arg swt_gen="true"></arg> <retval swt_gen="true"></retval> </method> + <method selector="setBackgroundStyle:" swt_gen="true"> + <arg swt_gen="true"></arg> + <retval swt_gen="true"></retval> + </method> <method selector="setBaseWritingDirection:" swt_gen="true"> <arg swt_gen="true"></arg> <retval swt_gen="true"></retval> @@ -3551,6 +3559,9 @@ <arg swt_gen="true"></arg> <retval swt_gen="true"></retval> </method> + <method selector="isVisible" swt_gen="true"> + <retval swt_gen="true"></retval> + </method> <method selector="removeItemAtIndex:" swt_gen="true"> <arg swt_gen="true"></arg> <retval swt_gen="true"></retval> @@ -3567,6 +3578,10 @@ <arg swt_gen="true"></arg> <retval swt_gen="true"></retval> </method> + <method selector="setSelectedItemIdentifier:" swt_gen="true"> + <arg swt_gen="true"></arg> + <retval swt_gen="true"></retval> + </method> <method selector="setVisible:" swt_gen="true"> <arg swt_gen="true"></arg> <retval swt_gen="true"></retval> @@ -3600,6 +3615,10 @@ <arg swt_gen="true"></arg> <retval swt_gen="true"></retval> </method> + <method selector="setMenuFormRepresentation:" swt_gen="true"> + <arg swt_gen="true"></arg> + <retval swt_gen="true"></retval> + </method> <method selector="setMinSize:" swt_gen="true"> <arg swt_gen="true"></arg> <retval swt_gen="true"></retval> @@ -3812,6 +3831,14 @@ <arg swt_gen="true"></arg> <retval swt_gen="true"></retval> </method> + <method selector="mouse:inRect:" swt_gen="true"> + <arg swt_gen="true"></arg> + <arg swt_gen="true"></arg> + <retval swt_gen="true"></retval> + </method> + <method selector="mouseDownCanMoveWindow" swt_gen="true"> + <retval swt_gen="true"></retval> + </method> <method selector="registerForDraggedTypes:" swt_gen="true"> <arg swt_gen="true"></arg> <retval swt_gen="true"></retval> @@ -4472,6 +4499,7 @@ <enum name="NSApplicationDefined" swt_gen="true"></enum> <enum name="NSApplicationDelegateReplySuccess" swt_gen="true"></enum> <enum name="NSAtTop" swt_gen="true"></enum> + <enum name="NSBackgroundStyleRaised" swt_gen="true"></enum> <enum name="NSBackingStoreBuffered" swt_gen="true"></enum> <enum name="NSBackspaceCharacter" swt_gen="true"></enum> <enum name="NSBevelLineJoinStyle" swt_gen="true"></enum> @@ -4491,8 +4519,10 @@ <enum name="NSCommandKeyMask" swt_gen="true"></enum> <enum name="NSCompositeClear" swt_gen="true"></enum> <enum name="NSCompositeCopy" swt_gen="true"></enum> + <enum name="NSCompositeSourceAtop" swt_gen="true"></enum> <enum name="NSCompositeSourceOver" swt_gen="true"></enum> <enum name="NSCompositeXOR" swt_gen="true"></enum> + <enum name="NSContentsCellMask" swt_gen="true"></enum> <enum name="NSControlKeyMask" swt_gen="true"></enum> <enum name="NSCriticalAlertStyle" swt_gen="true"></enum> <enum name="NSCurveToBezierPathElement" swt_gen="true"></enum> @@ -4618,6 +4648,7 @@ <enum name="NSTerminateNow" swt_gen="true"></enum> <enum name="NSTextFieldAndStepperDatePickerStyle" swt_gen="true"></enum> <enum name="NSTitledWindowMask" swt_gen="true"></enum> + <enum name="NSToolbarDisplayModeIconOnly" swt_gen="true"></enum> <enum name="NSUnderlineStyleDouble" swt_gen="true"></enum> <enum name="NSUnderlineStyleNone" swt_gen="true"></enum> <enum name="NSUnderlineStyleSingle" swt_gen="true"></enum> @@ -4695,6 +4726,10 @@ <arg swt_gen="true"></arg> <retval swt_gen="true"></retval> </function> + <function name="NSRectFillUsingOperation" swt_gen="true"> + <arg swt_gen="true"></arg> + <arg swt_gen="true"></arg> + </function> <function name="NSWindowList" swt_gen="true"> <arg swt_gen="true"></arg> <arg swt_gen="true" swt_java_type="int[]" swt_java_type64="long[]"></arg> @@ -4851,6 +4886,11 @@ <arg swt_gen="true"></arg> </method> </informal_protocol> + <informal_protocol name="NSMenuValidation" swt_gen="true"> + <method selector="validateMenuItem:" swt_gen="true"> + <arg swt_gen="true"></arg> + </method> + </informal_protocol> <informal_protocol name="NSOutlineViewDataSource" swt_gen="mixed"> <method selector="outlineView:acceptDrop:item:childIndex:" swt_gen="true"> <arg swt_gen="true"></arg> diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/CoreGraphicsFull.bridgesupport.extras b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/CoreGraphicsFull.bridgesupport.extras index f08cef2716..1f194083e4 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/CoreGraphicsFull.bridgesupport.extras +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/CoreGraphicsFull.bridgesupport.extras @@ -63,11 +63,19 @@ <arg swt_gen="true"></arg> <arg swt_gen="true"></arg> </function> + <function name="CGContextBeginTransparencyLayerWithRect" swt_gen="true"> + <arg swt_gen="true"></arg> + <arg swt_gen="true"></arg> + <arg swt_gen="true"></arg> + </function> <function name="CGContextDrawImage" swt_gen="true"> <arg swt_gen="true"></arg> <arg swt_gen="true"></arg> <arg swt_gen="true"></arg> </function> + <function name="CGContextEndTransparencyLayer" swt_gen="true"> + <arg swt_gen="true"></arg> + </function> <function name="CGContextFillRect" swt_gen="true"> <arg swt_gen="true"></arg> <arg swt_gen="true"></arg> diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSButtonCell.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSButtonCell.java index 51c8ce5844..bdc70b3e63 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSButtonCell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSButtonCell.java @@ -47,6 +47,10 @@ public void setButtonType(int /*long*/ aType) { OS.objc_msgSend(this.id, OS.sel_setButtonType_, aType); } +public void setHighlightsBy(int /*long*/ aType) { + OS.objc_msgSend(this.id, OS.sel_setHighlightsBy_, aType); +} + public void setImagePosition(int /*long*/ aPosition) { OS.objc_msgSend(this.id, OS.sel_setImagePosition_, aPosition); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSCell.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSCell.java index 8e0888c017..d5820a1147 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSCell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSCell.java @@ -114,6 +114,10 @@ public void setAttributedStringValue(NSAttributedString obj) { OS.objc_msgSend(this.id, OS.sel_setAttributedStringValue_, obj != null ? obj.id : 0); } +public void setBackgroundStyle(int /*long*/ style) { + OS.objc_msgSend(this.id, OS.sel_setBackgroundStyle_, style); +} + public void setBaseWritingDirection(int /*long*/ writingDirection) { OS.objc_msgSend(this.id, OS.sel_setBaseWritingDirection_, writingDirection); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSToolbar.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSToolbar.java index 82c8786c51..db010b427d 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSToolbar.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSToolbar.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -33,6 +33,10 @@ public void insertItemWithItemIdentifier(NSString itemIdentifier, int /*long*/ i OS.objc_msgSend(this.id, OS.sel_insertItemWithItemIdentifier_atIndex_, itemIdentifier != null ? itemIdentifier.id : 0, index); } +public boolean isVisible() { + return OS.objc_msgSend_bool(this.id, OS.sel_isVisible); +} + public void removeItemAtIndex(int /*long*/ index) { OS.objc_msgSend(this.id, OS.sel_removeItemAtIndex_, index); } @@ -49,6 +53,10 @@ public void setDisplayMode(int /*long*/ displayMode) { OS.objc_msgSend(this.id, OS.sel_setDisplayMode_, displayMode); } +public void setSelectedItemIdentifier(NSString itemIdentifier) { + OS.objc_msgSend(this.id, OS.sel_setSelectedItemIdentifier_, itemIdentifier != null ? itemIdentifier.id : 0); +} + public void setVisible(boolean shown) { OS.objc_msgSend(this.id, OS.sel_setVisible_, shown); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSToolbarItem.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSToolbarItem.java index ea08b1a961..efe821eb0f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSToolbarItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSToolbarItem.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -54,6 +54,10 @@ public void setMaxSize(NSSize size) { OS.objc_msgSend(this.id, OS.sel_setMaxSize_, size); } +public void setMenuFormRepresentation(NSMenuItem menuItem) { + OS.objc_msgSend(this.id, OS.sel_setMenuFormRepresentation_, menuItem != null ? menuItem.id : 0); +} + public void setMinSize(NSSize size) { OS.objc_msgSend(this.id, OS.sel_setMinSize_, size); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSView.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSView.java index 68ed879792..7292c4c9cc 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSView.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSView.java @@ -203,6 +203,14 @@ public NSMenu menuForEvent(NSEvent event) { return result != 0 ? new NSMenu(result) : null; } +public boolean mouse(NSPoint aPoint, NSRect aRect) { + return OS.objc_msgSend_bool(this.id, OS.sel_mouse_inRect_, aPoint, aRect); +} + +public boolean mouseDownCanMoveWindow() { + return OS.objc_msgSend_bool(this.id, OS.sel_mouseDownCanMoveWindow); +} + public void registerForDraggedTypes(NSArray newTypes) { OS.objc_msgSend(this.id, OS.sel_registerForDraggedTypes_, newTypes != null ? newTypes.id : 0); } 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 b354eee5dc..33a87f5509 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 @@ -137,6 +137,8 @@ public class OS extends C { public static final int /*long*/ class_JRSAppKitAWT = objc_getClass("JRSAppKitAWT"); public static final int /*long*/ sel_awtAppDelegate = sel_registerName("awtAppDelegate"); + public static final int /*long*/ class_NSToolbarView = objc_getClass("NSToolbarView"); + /** JNI natives */ /** @method flags=jni */ @@ -757,6 +759,7 @@ public static final int /*long*/ protocol_NSDraggingDestination = objc_getProtoc public static final int /*long*/ protocol_NSDraggingSource = objc_getProtocol("NSDraggingSource"); public static final int /*long*/ protocol_NSFontManagerResponderMethod = objc_getProtocol("NSFontManagerResponderMethod"); public static final int /*long*/ protocol_NSMenuDelegate = objc_getProtocol("NSMenuDelegate"); +public static final int /*long*/ protocol_NSMenuValidation = objc_getProtocol("NSMenuValidation"); public static final int /*long*/ protocol_NSOutlineViewDataSource = objc_getProtocol("NSOutlineViewDataSource"); public static final int /*long*/ protocol_NSOutlineViewDelegate = objc_getProtocol("NSOutlineViewDelegate"); public static final int /*long*/ protocol_NSOutlineViewNotifications = objc_getProtocol("NSOutlineViewNotifications"); @@ -1376,7 +1379,9 @@ public static final int /*long*/ sel_minimumSize = sel_registerName("minimumSize public static final int /*long*/ sel_minuteOfHour = sel_registerName("minuteOfHour"); public static final int /*long*/ sel_modifierFlags = sel_registerName("modifierFlags"); public static final int /*long*/ sel_monthOfYear = sel_registerName("monthOfYear"); +public static final int /*long*/ sel_mouse_inRect_ = sel_registerName("mouse:inRect:"); public static final int /*long*/ sel_mouseDown_ = sel_registerName("mouseDown:"); +public static final int /*long*/ sel_mouseDownCanMoveWindow = sel_registerName("mouseDownCanMoveWindow"); public static final int /*long*/ sel_mouseDragged_ = sel_registerName("mouseDragged:"); public static final int /*long*/ sel_mouseEntered_ = sel_registerName("mouseEntered:"); public static final int /*long*/ sel_mouseExited_ = sel_registerName("mouseExited:"); @@ -1641,6 +1646,7 @@ public static final int /*long*/ sel_setAutoresizingMask_ = sel_registerName("se public static final int /*long*/ sel_setAutosaveExpandedItems_ = sel_registerName("setAutosaveExpandedItems:"); public static final int /*long*/ sel_setBackgroundColor_ = sel_registerName("setBackgroundColor:"); public static final int /*long*/ sel_setBackgroundLayoutEnabled_ = sel_registerName("setBackgroundLayoutEnabled:"); +public static final int /*long*/ sel_setBackgroundStyle_ = sel_registerName("setBackgroundStyle:"); public static final int /*long*/ sel_setBadgeLabel_ = sel_registerName("setBadgeLabel:"); public static final int /*long*/ sel_setBaseWritingDirection_ = sel_registerName("setBaseWritingDirection:"); public static final int /*long*/ sel_setBaseWritingDirection_range_ = sel_registerName("setBaseWritingDirection:range:"); @@ -1733,6 +1739,7 @@ public static final int /*long*/ sel_setHidesOnDeactivate_ = sel_registerName("s public static final int /*long*/ sel_setHighlightMode_ = sel_registerName("setHighlightMode:"); public static final int /*long*/ sel_setHighlighted_ = sel_registerName("setHighlighted:"); public static final int /*long*/ sel_setHighlightedTableColumn_ = sel_registerName("setHighlightedTableColumn:"); +public static final int /*long*/ sel_setHighlightsBy_ = sel_registerName("setHighlightsBy:"); public static final int /*long*/ sel_setHorizontalScroller_ = sel_registerName("setHorizontalScroller:"); public static final int /*long*/ sel_setHorizontallyResizable_ = sel_registerName("setHorizontallyResizable:"); public static final int /*long*/ sel_setIcon_ = sel_registerName("setIcon:"); @@ -1776,6 +1783,7 @@ public static final int /*long*/ sel_setMaximumFractionDigits_ = sel_registerNam public static final int /*long*/ sel_setMaximumIntegerDigits_ = sel_registerName("setMaximumIntegerDigits:"); public static final int /*long*/ sel_setMenu_ = sel_registerName("setMenu:"); public static final int /*long*/ sel_setMenu_forSegment_ = sel_registerName("setMenu:forSegment:"); +public static final int /*long*/ sel_setMenuFormRepresentation_ = sel_registerName("setMenuFormRepresentation:"); public static final int /*long*/ sel_setMessage_ = sel_registerName("setMessage:"); public static final int /*long*/ sel_setMessageText_ = sel_registerName("setMessageText:"); public static final int /*long*/ sel_setMinSize_ = sel_registerName("setMinSize:"); @@ -1820,6 +1828,7 @@ public static final int /*long*/ sel_setSegmentCount_ = sel_registerName("setSeg public static final int /*long*/ sel_setSegmentStyle_ = sel_registerName("setSegmentStyle:"); public static final int /*long*/ sel_setSelectable_ = sel_registerName("setSelectable:"); public static final int /*long*/ sel_setSelected_forSegment_ = sel_registerName("setSelected:forSegment:"); +public static final int /*long*/ sel_setSelectedItemIdentifier_ = sel_registerName("setSelectedItemIdentifier:"); public static final int /*long*/ sel_setSelectedRange_ = sel_registerName("setSelectedRange:"); public static final int /*long*/ sel_setSelectedSegment_ = sel_registerName("setSelectedSegment:"); public static final int /*long*/ sel_setSelectedTextAttributes_ = sel_registerName("setSelectedTextAttributes:"); @@ -2005,6 +2014,7 @@ public static final int /*long*/ sel_userInfo = sel_registerName("userInfo"); public static final int /*long*/ sel_userSpaceScaleFactor = sel_registerName("userSpaceScaleFactor"); public static final int /*long*/ sel_usesAlternatingRowBackgroundColors = sel_registerName("usesAlternatingRowBackgroundColors"); public static final int /*long*/ sel_validAttributesForMarkedText = sel_registerName("validAttributesForMarkedText"); +public static final int /*long*/ sel_validateMenuItem_ = sel_registerName("validateMenuItem:"); public static final int /*long*/ sel_validateVisibleColumns = sel_registerName("validateVisibleColumns"); public static final int /*long*/ sel_value = sel_registerName("value"); public static final int /*long*/ sel_valueForKey_ = sel_registerName("valueForKey:"); @@ -2090,6 +2100,7 @@ public static final int NSAlternateKeyMask = 524288; public static final int NSApplicationDefined = 15; public static final int NSApplicationDelegateReplySuccess = 0; public static final int NSAtTop = 2; +public static final int NSBackgroundStyleRaised = 2; public static final int NSBackingStoreBuffered = 2; public static final int NSBackspaceCharacter = 8; public static final int NSBevelLineJoinStyle = 2; @@ -2109,8 +2120,10 @@ public static final int NSClosePathBezierPathElement = 3; public static final int NSCommandKeyMask = 1048576; public static final int NSCompositeClear = 0; public static final int NSCompositeCopy = 1; +public static final int NSCompositeSourceAtop = 5; public static final int NSCompositeSourceOver = 2; public static final int NSCompositeXOR = 10; +public static final int NSContentsCellMask = 1; public static final int NSControlKeyMask = 262144; public static final int NSCriticalAlertStyle = 2; public static final int NSCurveToBezierPathElement = 2; @@ -2236,6 +2249,7 @@ public static final int NSTerminateCancel = 0; public static final int NSTerminateNow = 1; public static final int NSTextFieldAndStepperDatePickerStyle = 0; public static final int NSTitledWindowMask = 1; +public static final int NSToolbarDisplayModeIconOnly = 2; public static final int NSUnderlineStyleDouble = 9; public static final int NSUnderlineStyleNone = 0; public static final int NSUnderlineStyleSingle = 1; @@ -2951,6 +2965,11 @@ public static final native void NSCountWindows(int[] /*long[]*/ count); */ public static final native int /*long*/ NSNumberOfColorComponents(int /*long*/ colorSpaceName); /** + * @param aRect flags=struct + * @param op cast=(NSCompositingOperation) + */ +public static final native void NSRectFillUsingOperation(NSRect aRect, int /*long*/ op); +/** * @param size cast=(NSInteger) * @param list cast=(NSInteger*) */ @@ -3073,12 +3092,22 @@ public static final native void CGColorSpaceRelease(int /*long*/ space); */ public static final native void CGContextAddPath(int /*long*/ context, int /*long*/ path); /** + * @param context cast=(CGContextRef) + * @param rect flags=struct + * @param auxiliaryInfo cast=(CFDictionaryRef) + */ +public static final native void CGContextBeginTransparencyLayerWithRect(int /*long*/ context, CGRect rect, int /*long*/ auxiliaryInfo); +/** * @param c cast=(CGContextRef) * @param rect flags=struct * @param image cast=(CGImageRef) */ public static final native void CGContextDrawImage(int /*long*/ c, CGRect rect, int /*long*/ image); /** + * @param context cast=(CGContextRef) + */ +public static final native void CGContextEndTransparencyLayer(int /*long*/ context); +/** * @param c cast=(CGContextRef) * @param rect flags=struct */ @@ -3529,6 +3558,12 @@ public static final native boolean objc_msgSend_bool(int /*long*/ id, int /*long /** * @method flags=cast * @param arg0 flags=struct + * @param arg1 flags=struct + */ +public static final native boolean objc_msgSend_bool(int /*long*/ id, int /*long*/ sel, NSPoint arg0, NSRect arg1); +/** + * @method flags=cast + * @param arg0 flags=struct */ public static final native boolean objc_msgSend_bool(int /*long*/ id, int /*long*/ sel, NSRange arg0, int /*long*/ arg1); /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Shell.java index 49bff9f9de..99742b07a4 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Shell.java @@ -990,6 +990,29 @@ float getThemeAlpha () { return 1; } +/** + * WARNING: API UNDER COSTRUCTION + * This API should be considered experimental and subject to change before the final release. + * + * Returns the instance of the ToolBar object representing the tool bar that can appear on the + * trim of the shell. This will return <code>null</code> if the platform does not support tool bars that + * not part of the content area of the shell, or if the style of the shell does not support a + * tool bar. + * <p> + * + * @return a ToolBar object representing the window's tool bar or null. + * + * @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> + * + * @since 3.7 + */ +public ToolBar getToolBar() { + return null; +} + boolean hasBorder () { return false; } 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 e38c76c89d..f1f3be068b 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 @@ -308,7 +308,7 @@ void drawImageWithFrameInView (int /*long*/ id, int /*long*/ sel, int /*long*/ i rect.height += EXTRA_HEIGHT; } } - callSuper (id, sel, image, rect, view); + super.drawImageWithFrameInView(id, sel, image, rect, view); } void drawInteriorWithFrame_inView (int /*long*/ id, int /*long*/ sel, NSRect cellRect, int /*long*/ viewid) { 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 ec64673f07..5d12d3bf7d 100755 --- 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 @@ -2133,6 +2133,7 @@ void addEventMethods (int /*long*/ cls, int /*long*/ proc2, int /*long*/ proc3, OS.class_addMethod(cls, OS.sel_resetCursorRects, proc2, "@:"); OS.class_addMethod(cls, OS.sel_updateTrackingAreas, proc2, "@:"); OS.class_addMethod(cls, OS.sel_getImageView, proc2, "@:"); + OS.class_addMethod(cls, OS.sel_mouseDownCanMoveWindow, proc2, "@:"); } if (needsDisplayInRectProc != 0) { OS.class_addMethod(cls, OS.sel_setNeedsDisplayInRect_, needsDisplayInRectProc, "@:{NSRect}"); @@ -2275,6 +2276,7 @@ void initClasses () { cls = OS.objc_allocateClassPair(OS.class_NSButton, className, 0); OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types); OS.class_addMethod(cls, OS.sel_sendSelection, proc2, "@:"); + OS.class_addMethod(cls, OS.sel_validateMenuItem_, proc3, "@:@"); addEventMethods(cls, proc2, proc3, drawRectProc, hitTestProc, setNeedsDisplayInRectProc); addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc); OS.objc_registerClassPair(cls); @@ -2290,7 +2292,6 @@ void initClasses () { addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); OS.class_addMethod (cls, OS.sel_drawImage_withFrame_inView_, drawImageWithFrameInViewProc, "@:@{NSRect}@"); OS.class_addMethod (cls, OS.sel_drawTitle_withFrame_inView_, drawTitleWithFrameInViewProc, "@:@{NSRect}@"); - OS.class_addMethod(cls, OS.sel_cellSize, cellSizeProc, "@:"); OS.class_addMethod(cls, OS.sel_drawInteriorWithFrame_inView_, drawInteriorWithFrameInViewProc, "@:{NSRect}@"); OS.class_addMethod(cls, OS.sel_titleRectForBounds_, titleRectForBoundsProc, "@:{NSRect}"); OS.class_addMethod(cls, OS.sel_cellSizeForBounds_, cellSizeForBoundsProc, "@:{NSRect}"); @@ -2689,6 +2690,25 @@ void initClasses () { addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); 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_toolbarSelectableItemIdentifiers_, proc3, "@:@"); + addEventMethods(cls, proc2, proc3, drawRectProc, hitTestProc, setNeedsDisplayInRectProc); + addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc); + addAccessibilityMethods(cls, proc2, proc3, proc4, accessibilityHitTestProc); + OS.objc_registerClassPair(cls); + + className = "SWTToolbarView"; + cls = OS.objc_allocateClassPair(OS.class_NSToolbarView, className, 0); + OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types); + addEventMethods(cls, proc2, proc3, drawRectProc, hitTestProc, setNeedsDisplayInRectProc); + addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc); + OS.objc_registerClassPair(cls); + className = "SWTWindowDelegate"; cls = OS.objc_allocateClassPair(OS.class_NSObject, className, 0); OS.class_addIvar(cls, SWT_OBJECT, size, (byte)align, types); @@ -4252,6 +4272,7 @@ void setMenuBar (Menu menu) { } //set parent of each item to NULL and add them to menubar if (menu != null) { + //menubar.setTitle(menu.g) MenuItem[] items = menu.getItems(); for (int i = 0; i < items.length; i++) { MenuItem item = items[i]; @@ -4616,7 +4637,7 @@ Control findControl (boolean checkTrim, NSView[] hitView) { // number passed to windowWithWindowNumber returns nil the window doesn't belong to // this process. if (window != null) { - NSView contentView = window.contentView(); + NSView contentView = window.contentView().superview(); if (contentView != null && OS.NSPointInRect(screenLocation, window.frame())) { NSPoint location = window.convertScreenToBase(screenLocation); view = contentView.hitTest (location); @@ -5124,6 +5145,8 @@ static int /*long*/ windowProc(int /*long*/ id, int /*long*/ sel) { return widget.accessibilityParameterizedAttributeNames(id, sel); } else if (sel == OS.sel_getImageView) { return widget.imageView(); + } else if (sel == OS.sel_mouseDownCanMoveWindow) { + return (widget.mouseDownCanMoveWindow(id, sel) ? 1 : 0); } else if (sel == OS.sel_accessibilityFocusedUIElement) { return widget.accessibilityFocusedUIElement(id, sel); } else if (sel == OS.sel_accessibilityIsIgnored) { @@ -5398,6 +5421,14 @@ static int /*long*/ windowProc(int /*long*/ id, int /*long*/ sel, int /*long*/ a widget.windowDidMiniturize(id, sel, arg0); } else if (sel == OS.sel_windowDidDeminiaturize_) { widget.windowDidDeminiturize(id, sel, arg0); + } 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_toolbarSelectableItemIdentifiers_) { + return widget.toolbarSelectableItemIdentifiers(id, sel, arg0); + } else if (sel == OS.sel_validateMenuItem_) { + return (widget.validateMenuItem(id, sel, arg0) ? 1 : 0); } return 0; } @@ -5508,6 +5539,8 @@ static int /*long*/ windowProc(int /*long*/ id, int /*long*/ sel, int /*long*/ a 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; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Shell.java index 1deda538d5..40dce0d126 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Shell.java @@ -124,6 +124,7 @@ public class Shell extends Decorations { boolean keyInputHappened; NSRect currentFrame; NSRect fullScreenFrame; + ToolBar toolBar; static int DEFAULT_CLIENT_WIDTH = -1; static int DEFAULT_CLIENT_HEIGHT = -1; @@ -410,6 +411,17 @@ public static Shell cocoa_new (Display display, int /*long*/ handle) { return new Shell (display, null, SWT.NO_TRIM, handle, true); } +Control [] _getChildren () { + Control [] children = super._getChildren(); + if (toolBar != null) { + Control [] newChildren = new Control [children.length + 1]; + System.arraycopy (children, 0, newChildren, 1, children.length); + newChildren[0] = toolBar; + children = newChildren; + } + return children; +} + static int checkStyle (Shell parent, int style) { style = Decorations.checkStyle (style); style &= ~SWT.TRANSPARENT; @@ -1104,6 +1116,31 @@ float getThemeAlpha () { return 1; } +/** + * WARNING: API UNDER COSTRUCTION + * This API should be considered experimental and subject to change before the final release. + * + * Returns the instance of the ToolBar object representing the tool bar that can appear on the + * trim of the shell. This will return <code>null</code> if the platform does not support tool bars that + * not part of the content area of the shell, or if the style of the shell does not support a + * tool bar. + * <p> + * + * @return a ToolBar object representing the window's tool bar or null. + * + * @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> + * + * @since 3.7 + */ +public ToolBar getToolBar() { + checkWidget(); + if (toolBar == null) toolBar = new ToolBar(this, SWT.HORIZONTAL | SWT.SMOOTH, true); + return toolBar; +} + boolean hasBorder () { return false; } @@ -1174,6 +1211,26 @@ void makeKeyAndOrderFront() { window.makeKeyAndOrderFront (null); } +Point minimumSize (int wHint, int Hint, boolean changed) { + // minimumSize is used by computeSize() to figure out how big the view + // (or, in this case, the content view of the Shell) should be. + // An NSToolbar does not contribute to the content area, but must be + // accounted for. If the shell has a toolbar but no other children + // this will return the width of the toolbar and a height of 1 + Control [] children = _getChildren (); + int width = 0, height = 0; + for (int i=0; i<children.length; i++) { + Rectangle rect = children [i].getBounds (); + width = Math.max (width, rect.x + rect.width); + if (children[i] != toolBar) { + height = Math.max (height, rect.y + rect.height); + } else { + height = Math.max (height, 1); + } + } + return new Point (width, height); +} + void mouseMoved(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { super.mouseMoved(id, sel, theEvent); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolBar.java index 11cb3f28d6..f4f86724e5 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolBar.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/ToolBar.java @@ -47,8 +47,10 @@ import org.eclipse.swt.internal.cocoa.*; public class ToolBar extends Composite { int itemCount; ToolItem [] items; + NSToolbar nsToolbar; NSArray accessibilityAttributes = null; ToolItem lastFocus; + static int NEXT_ID; /** * Constructs a new instance of this class given its parent @@ -84,7 +86,11 @@ public class ToolBar extends Composite { * @see Widget#getStyle() */ public ToolBar (Composite parent, int style) { - super (parent, checkStyle (style)); + this(parent, style, false); +} + +ToolBar(Composite parent, int style, boolean internal) { + super (parent, checkStyle (parent, style, internal)); /* * Ensure that either of HORIZONTAL or VERTICAL is set. @@ -141,7 +147,7 @@ boolean accessibilityIsIgnored(int /*long*/ id, int /*long*/ sel) { return super.accessibilityIsIgnored(id, sel); } -static int checkStyle (int style) { +static int checkStyle (Composite parent, int style, boolean internal) { /* * Even though it is legal to create this widget * with scroll bars, they serve no useful purpose @@ -149,7 +155,38 @@ static int checkStyle (int style) { * widget's client area. The fix is to clear * the SWT style. */ - return style & ~(SWT.H_SCROLL | SWT.V_SCROLL); + int newStyle = style & ~(SWT.H_SCROLL | SWT.V_SCROLL); + + /* + * Only internal clients can create an NSToolbar-based ToolBar. + */ + if (!internal && (newStyle & SWT.SMOOTH) != 0) { + newStyle &= ~SWT.SMOOTH; + } + + /* + * A unified toolbar can only be parented to a Shell, and + * there can only be one unified toolbar per shell. If neither of these + * conditions hold, turn off the SMOOTH flag. + */ + if ((style & SWT.SMOOTH) != 0) { + if (parent instanceof Shell) { + Shell s = (Shell)parent; + if (s.window.toolbar() != null) newStyle &= ~SWT.SMOOTH; + } else { + newStyle &= ~SWT.SMOOTH; + } + } + + /* + * Unified toolbar only supports a horizontal layout, and doesn't wrap. + */ + if ((newStyle & SWT.SMOOTH) != 0) { + newStyle &= ~(SWT.VERTICAL | SWT.WRAP); + newStyle |= SWT.HORIZONTAL; + } + + return newStyle; } protected void checkSubclass () { @@ -186,20 +223,39 @@ public Rectangle computeTrim (int x, int y, int width, int height) { } void createHandle () { - state |= THEME_BACKGROUND; - if (hasBorder()) { - NSRect rect = new NSRect(); - NSScrollView scrollWidget = (NSScrollView)new SWTScrollView().alloc(); - scrollWidget.initWithFrame (rect); - scrollWidget.setDrawsBackground(false); - scrollWidget.setBorderType(OS.NSBezelBorder); - scrollView = scrollWidget; - } - NSView widget = (NSView)new SWTView().alloc(); - widget.init(); -// widget.setDrawsBackground(false); - view = widget; - if (scrollView != null) view.setAutoresizingMask(OS.NSViewHeightSizable | OS.NSViewWidthSizable); + if ((style & SWT.SMOOTH) != 0) { + nsToolbar = ((NSToolbar)new SWTToolbar().alloc()).initWithIdentifier(NSString.stringWith(String.valueOf(NEXT_ID++))); + nsToolbar.setDelegate(nsToolbar); + nsToolbar.setDisplayMode(OS.NSToolbarDisplayModeIconOnly); + NSWindow window = parent.view.window(); + window.setToolbar(nsToolbar); + nsToolbar.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); + OS.object_setClass(view.id, OS.objc_getClass("SWTToolbarView")); + view.retain(); + break; + } + } + style &= ~SWT.SMOOTH; + } else { + state |= THEME_BACKGROUND; + if (hasBorder()) { + NSRect rect = new NSRect(); + NSScrollView scrollWidget = (NSScrollView)new SWTScrollView().alloc(); + scrollWidget.initWithFrame (rect); + scrollWidget.setDrawsBackground(false); + scrollWidget.setBorderType(OS.NSBezelBorder); + scrollView = scrollWidget; + } + NSView widget = (NSView)new SWTView().alloc(); + widget.init(); + view = widget; + if (scrollView != null) view.setAutoresizingMask(OS.NSViewHeightSizable | OS.NSViewWidthSizable); + } } void createItem (ToolItem item, int index) { @@ -209,10 +265,14 @@ void createItem (ToolItem item, int index) { System.arraycopy (items, 0, newItems, 0, items.length); items = newItems; } - item.createWidget(); - view.addSubview(item.view); + item.createWidget(); System.arraycopy (items, index, items, index + 1, itemCount++ - index); items [index] = item; + if (nsToolbar != null) { + nsToolbar.insertItemWithItemIdentifier(item.getItemID(), index); + } else { + view.addSubview(item.view); + } relayout (); } @@ -222,6 +282,15 @@ void createWidget () { itemCount = 0; } +NSFont defaultNSFont() { + return NSFont.systemFontOfSize(11.0f); +} + +void deregister () { + super.deregister (); + if (nsToolbar != null) display.removeWidget (nsToolbar); +} + void destroyItem (ToolItem item) { int index = 0; while (index < itemCount) { @@ -232,7 +301,11 @@ void destroyItem (ToolItem item) { if (item == lastFocus) lastFocus = null; System.arraycopy (items, index + 1, items, index, --itemCount - index); items [itemCount] = null; - item.view.removeFromSuperview(); + if (nsToolbar != null) { + nsToolbar.removeItemAtIndex(index); + } else { + item.view.removeFromSuperview(); + } relayout (); } @@ -262,6 +335,25 @@ Widget findTooltip (NSPoint pt) { return super.findTooltip (pt); } +void setZOrder() { + if (nsToolbar != null) return; + super.setZOrder(); +} + +public Rectangle getBounds () { + checkWidget(); + + if (nsToolbar != null) { + // The NSToolbar's view will always be a child of the Shell, so we can just + // convert the frame to window-relative coordinates. + NSRect rect = view.frame(); + rect = view.convertRect_toView_(rect, null); + return new Rectangle((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height); + } + + return super.getBounds(); +} + boolean forceFocus (NSView focusView) { if (lastFocus != null && lastFocus.setFocus ()) return true; ToolItem [] items = getItems (); @@ -448,6 +540,37 @@ int [] layoutHorizontal (int width, int height, boolean resize) { return new int [] {rows, maxX, y + itemHeight}; } +int [] layoutUnified (int width, int height, boolean resize) { + int x = 0, y = 0; + int itemHeight = 0, maxX = 0; + Point [] sizes = new Point [itemCount]; + NSRect [] containerRects = new NSRect[itemCount]; + // This next line relies on the observation that all of the toolbar item views are children of the first + // subview of the NSToolbarView. + NSArray itemViewers = new NSView(view.subviews().objectAtIndex(0)).subviews(); + for (int i=0; i<itemCount; i++) { + Point size = sizes [i] = items [i].computeSize (); + containerRects [i] = new NSView(itemViewers.objectAtIndex(i)).frame(); + if (i == 0) x = (int) containerRects[0].x; + itemHeight = Math.max (itemHeight, size.y); + } + for (int i=0; i<itemCount; i++) { + ToolItem item = items [i]; + Point size = sizes [i]; + if (resize) { + item.setBounds (0, 0, size.x, itemHeight); + Control control = item.control; + if (control != null) { + control.setBounds (x, y, size.x, itemHeight); + } + } + x += containerRects[i].width; + maxX = Math.max (maxX, x); + } + + return new int [] {1, maxX, itemHeight}; +} + int [] layoutVertical (int width, int height, boolean resize) { int xSpacing = 2, ySpacing = 0; int marginWidth = 0, marginHeight = 0; @@ -485,6 +608,10 @@ int [] layoutVertical (int width, int height, boolean resize) { } int [] layout (int nWidth, int nHeight, boolean resize) { + if (nsToolbar != null) { + return layoutUnified(nWidth, nHeight, resize); + } + if ((style & SWT.VERTICAL) != 0) { return layoutVertical (nWidth, nHeight, resize); } else { @@ -492,6 +619,11 @@ int [] layout (int nWidth, int nHeight, boolean resize) { } } +void register() { + super.register(); + if (nsToolbar != null) display.addWidget (nsToolbar, this); +} + void relayout () { if (!getDrawing()) return; Rectangle rect = getClientArea (); @@ -513,7 +645,13 @@ void releaseChildren (boolean destroy) { } void releaseHandle () { - super.releaseHandle (); + super.releaseHandle (); + + if (nsToolbar != null) { + nsToolbar.release(); + nsToolbar = null; + } + if (accessibilityAttributes != null) accessibilityAttributes.release(); accessibilityAttributes = null; } @@ -547,14 +685,13 @@ boolean sendMouseEvent (NSEvent nsEvent, int type, boolean send) { case SWT.MouseMove: // Start with the global mouse location, as the MouseEnter may occur due to // an application-activated event, which isn't associated with a window. - NSPoint toolbarPoint = NSEvent.mouseLocation(); - toolbarPoint = view.window().convertScreenToBase(toolbarPoint); - toolbarPoint = view.convertPoint_fromView_(toolbarPoint, null); + NSPoint windowPoint = NSEvent.mouseLocation(); + windowPoint = view.window().convertScreenToBase(windowPoint); for (int i = 0; i < itemCount; i++) { ToolItem item = items [i]; int currState = item.state; - - if (OS.NSPointInRect(toolbarPoint, item.view.frame())) { + NSPoint viewPoint = item.view.convertPoint_fromView_(windowPoint, null); + if (item.view.mouse(viewPoint, item.view.bounds())) { item.state |= Widget.HOT; } else { item.state &= ~Widget.HOT; @@ -576,6 +713,13 @@ boolean sendMouseEvent (NSEvent nsEvent, int type, boolean send) { return super.sendMouseEvent(nsEvent, type, send); } +void setBounds (int x, int y, int width, int height, boolean move, boolean resize) { + // In the unified toolbar case, the toolbar view size and position is completely controlled + // by the window, so don't change its bounds or location. + if (nsToolbar != null) return; + super.setBounds(x, y, width, height, move, resize); +} + void setFont(NSFont font) { for (int i = 0; i < itemCount; i++) { ToolItem item = items[i]; @@ -589,6 +733,53 @@ public void setRedraw (boolean redraw) { if (redraw && drawCount == 0) relayout(); } +public void setVisible(boolean visible) { + if (nsToolbar != null) nsToolbar.setVisible(visible); + super.setVisible(visible); +} + +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.nsItem.itemIdentifier())) { + return item.nsItem.id; + } + } + return 0; +} + +/* + * Returns an array of all toolbar item IDs allowed to be in the toolbar. Since the ToolBar created all of the ToolItems + * return all of the item IDs. + */ +int /*long*/ toolbarAllowedItemIdentifiers(int /*long*/ id, int /*long*/ sel, int /*long*/ toolbar) { + NSMutableArray array = NSMutableArray.arrayWithCapacity(itemCount); + for (int i = 0; i < itemCount; i++) { + array.addObject(items[i].nsItem.itemIdentifier()); + } + return array.id; +} + +/* + * This delegate method isn't really needed because ToolBars aren't customizable, but it's required according to the documentation. + */ +int /*long*/ toolbarDefaultItemIdentifiers(int /*long*/ id, int /*long*/ sel, int /*long*/ toolbar) { + return toolbarAllowedItemIdentifiers(id, sel, toolbar); +} + +/* + * toolbarSelectableItemIdentifiers returns an array of all items that can be the selected item, as determined + * by setSelectedItemIdentifier. + */ +int /*long*/ toolbarSelectableItemIdentifiers(int /*long*/ id, int /*long*/ sel, int /*long*/ toolbar) { + NSMutableArray array = NSMutableArray.arrayWithCapacity(itemCount); + for (int i = 0; i < itemCount; i++) { + if ((items[i].style & SWT.RADIO) != 0) array.addObject(items[i].nsItem.itemIdentifier()); + } + return array.id; +} + boolean translateTraversal (int key, NSEvent theEvent, boolean[] consume) { boolean result = super.translateTraversal (key, theEvent, consume); if (result) return result; 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 762412fa7d..2495535f42 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 @@ -39,7 +39,10 @@ import org.eclipse.swt.internal.cocoa.*; public class ToolItem extends Item { NSView view; NSButton button; - int width = DEFAULT_SEPARATOR_WIDTH; + NSToolbarItem nsItem; + NSMenuItem nsMenuRep; + NSString id; + int width; ToolBar parent; Image hotImage, disabledImage; String toolTipText; @@ -302,20 +305,22 @@ Point computeSize () { checkWidget(); int width = 0, height = 0; if ((style & SWT.SEPARATOR) != 0) { + // In the unified toolbar case the width is ignored if 0, DEFAULT, or SEPARATOR_FILL. if ((parent.style & SWT.HORIZONTAL) != 0) { width = getWidth (); + if (width == SWT.DEFAULT) width = DEFAULT_SEPARATOR_WIDTH; height = DEFAULT_HEIGHT; } else { width = DEFAULT_WIDTH; height = getWidth (); + if (height == SWT.DEFAULT) width = DEFAULT_SEPARATOR_WIDTH; } if (control != null) { height = Math.max (height, control.getMininumHeight ()); } } else { if (text.length () != 0 || image != null) { - NSButton widget = (NSButton)button; - NSSize size = widget.cell().cellSize(); + NSSize size = button.cell().cellSize(); width = (int)Math.ceil(size.width); height = (int)Math.ceil(size.height); } else { @@ -325,19 +330,38 @@ Point computeSize () { if ((style & SWT.DROP_DOWN) != 0) { width += ARROW_WIDTH + INSET; } - width += INSET * 2; - height += INSET * 2; + + if (parent.nsToolbar == null || image != null) { + width += INSET * 2; + height += INSET * 2; + } else { + height -= 2; + } } return new Point (width, height); } void createHandle () { + if (parent.nsToolbar != null) { + id = NSString.stringWith(String.valueOf(ToolBar.NEXT_ID++)); + id.retain(); + nsItem = ((NSToolbarItem)new NSToolbarItem().alloc()).initWithItemIdentifier(id); + nsItem.setAction(OS.sel_sendSelection); + nsMenuRep = ((NSMenuItem)new SWTMenuItem().alloc()).initWithTitle(NSString.string(), OS.sel_sendSelection, NSString.string()); + nsItem.setMenuFormRepresentation(nsMenuRep); + } + if ((style & SWT.SEPARATOR) != 0) { - NSBox widget = (NSBox)new SWTBox().alloc(); - widget.init(); - widget.setBoxType(OS.NSBoxSeparator); - widget.setBorderWidth(0); - view = widget; + if (parent.nsToolbar != null) { + view = (NSView)new SWTView().alloc(); + view.init(); + } else { + 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(); @@ -351,9 +375,14 @@ void createHandle () { NSButtonCell cell = (NSButtonCell)new SWTButtonCell ().alloc ().init (); button.setCell (cell); cell.release(); + if (parent.nsToolbar != null) { + cell.setHighlightsBy(OS.NSContentsCellMask); + cell.setBackgroundStyle(OS.NSBackgroundStyleRaised); + } button.setBordered(false); button.setAction(OS.sel_sendSelection); button.setTarget(button); + if (nsMenuRep != null) nsMenuRep.setTarget(button); Font font = parent.font != null ? parent.font : parent.defaultFont (); button.setFont(font.handle); button.setImagePosition(OS.NSImageOverlaps); @@ -393,12 +422,52 @@ void drawImageWithFrameInView (int /*long*/ id, int /*long*/ sel, int /*long*/ i rect.y += 3; } } - callSuper (id, sel, image, rect, view); + int /*long*/ cgContext = NSGraphicsContext.currentContext().graphicsPort(); + NSCell cell = new NSCell(id); + boolean drawSelected = (parent.nsToolbar != null) && getSelection() && ((style & SWT.CHECK) != 0) && !cell.isHighlighted(); + + if (drawSelected) { + NSGraphicsContext.currentContext().saveGraphicsState(); + CGRect cgRect = new CGRect(); + cgRect.origin.x = rect.x; + cgRect.origin.y = rect.y; + cgRect.size.width = rect.width; + cgRect.size.height = rect.height; + OS.CGContextBeginTransparencyLayerWithRect(cgContext, cgRect, 0); + } + + super.drawImageWithFrameInView(id, sel, image, rect, view); + + if (drawSelected) { + NSColor.colorWithCalibratedRed(0,0,0,.3f).setFill(); + OS.NSRectFillUsingOperation(rect, OS.NSCompositeSourceAtop); + OS.CGContextEndTransparencyLayer(cgContext); + NSGraphicsContext.currentContext().restoreGraphicsState(); + } +} + +NSRect drawTitleWithFrameInView (int /*long*/ id, int /*long*/ sel, int /*long*/ title, NSRect titleRect, int /*long*/ view) { + boolean hiliteShadow = new NSButtonCell(id).isHighlighted() && parent.nsToolbar != null && 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.colorWithCalibratedRed(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); } void drawWidget (int /*long*/ id, NSGraphicsContext context, NSRect rect) { if (id == view.id) { - if (getSelection ()) { + boolean drawSelected = getSelection() && (parent.nsToolbar == null); + if (drawSelected) { NSRect bounds = view.bounds(); context.saveGraphicsState(); NSColor.colorWithCalibratedRed(0.1f, 0.1f, 0.1f, 0.1f).setFill(); @@ -435,6 +504,10 @@ void drawWidget (int /*long*/ id, NSGraphicsContext context, NSRect rect) { } void enableWidget(boolean enabled) { + if (parent.nsToolbar != null) { + nsItem.setEnabled(enabled); + } + if ((style & SWT.SEPARATOR) == 0) { ((NSButton)button).setEnabled(enabled); updateImage(true); @@ -454,6 +527,15 @@ void enableWidget(boolean enabled) { */ public Rectangle getBounds () { checkWidget(); + if (parent.nsToolbar != null) { + NSRect rect = view.frame(); + // ToolItems in the unified toolbar are not contained directly within the Toolbar. + // Convert the toolitem rect from toolitem-relative coordinates to its + // parent, the toolbar, relative coordinates. + rect = parent.view.convertRect_fromView_(rect, view); + return new Rectangle((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height); + } + NSRect rect = view.frame(); return new Rectangle((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height); } @@ -540,6 +622,26 @@ public Image getHotImage () { return hotImage; } +NSString getItemID() { + NSString itemID = id; + + // For separators, return a Cocoa constant for the tool item ID. + if ((style & SWT.SEPARATOR) != 0) { + // If we are using a non-default width or control use that instead. + if (width <= 0 && control == null) { + if (width == 0) { + itemID = OS.NSToolbarSeparatorItemIdentifier; + } else if (width == SWT.DEFAULT) { + itemID = OS.NSToolbarSpaceItemIdentifier; + } else if (width == SWT.SEPARATOR_FILL) { + itemID = OS.NSToolbarFlexibleSpaceItemIdentifier; + } + } + } + + return itemID; +} + /** * Returns the receiver's parent, which must be a <code>ToolBar</code>. * @@ -652,6 +754,11 @@ void mouseDown(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { } } +boolean mouseDownCanMoveWindow(int /*long*/ id, int /*long*/ sel) { + if (id == view.id) return false; + return super.mouseDownCanMoveWindow(id, sel); +} + void mouseUp(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { if (!parent.mouseEvent(parent.view.id, sel, theEvent, SWT.MouseUp)) return; super.mouseUp(id, sel, theEvent); @@ -737,6 +844,18 @@ void releaseHandle () { 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; + } + if (nsMenuRep != null) { + nsMenuRep.release(); + nsMenuRep = null; + } parent = null; } @@ -770,18 +889,35 @@ void sendSelection () { void setBounds (int x, int y, int width, int height) { NSRect rect = new NSRect(); - rect.x = x; - rect.y = y; - rect.width = width; - rect.height = height; - view.setFrame(rect); - if (button != null) { - rect.x = 0; - rect.y = 0; + if (parent.nsToolbar == null) { + rect.x = x; + rect.y = y; rect.width = width; rect.height = height; - if ((style & SWT.DROP_DOWN) != 0) rect.width -= ARROW_WIDTH + INSET; - button.setFrame(rect); + view.setFrame(rect); + if (button != null) { + rect.x = 0; + rect.y = 0; + rect.width = width; + rect.height = height; + if ((style & SWT.DROP_DOWN) != 0) rect.width -= ARROW_WIDTH + INSET; + button.setFrame(rect); + } + } else { + // Let the NSToolbar manage the position of the view in the toolbar. + NSSize newSize = new NSSize(); + newSize.height = height; + newSize.width = width; + // Temporarily clear the view. This will force the item and toolbar to re-layout + // when the view is set again. + nsItem.setView(null); + view.setFrameSize(newSize); + if ((style & SWT.DROP_DOWN) != 0) newSize.width -= ARROW_WIDTH + INSET; + if (button != null) button.setFrameSize(newSize); + if ((style & SWT.DROP_DOWN) != 0) newSize.width += ARROW_WIDTH + INSET; + nsItem.setMinSize(newSize); + nsItem.setMaxSize(newSize); + nsItem.setView(view); } } @@ -808,11 +944,16 @@ public void setControl (Control control) { } if ((style & SWT.SEPARATOR) == 0) return; if (this.control == control) return; - NSBox widget = (NSBox)view; - if (control == null) { - widget.setBoxType(OS.NSBoxSeparator); + + if (parent.nsToolbar == null) { + NSBox widget = (NSBox)view; + if (control == null) { + widget.setBoxType(OS.NSBoxSeparator); + } else { + widget.setBoxType(OS.NSBoxCustom); + } } else { - widget.setBoxType(OS.NSBoxCustom); + nsItem.setMenuFormRepresentation(control == null ? nsMenuRep : NSMenuItem.separatorItem()); } this.control = control; view.setHidden(control != null); @@ -941,6 +1082,13 @@ public void setSelection (boolean selected) { checkWidget(); if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return; this.selection = selected; + + if (parent.nsToolbar != null) { + if ((style & SWT.RADIO) != 0 && selection) { + parent.nsToolbar.setSelectedItemIdentifier(nsItem.itemIdentifier()); + } + } + view.setNeedsDisplay(true); } @@ -975,6 +1123,13 @@ public void setText (String string) { if ((style & SWT.SEPARATOR) != 0) return; super.setText (string); NSButton widget = (NSButton)button; + if (parent.nsToolbar != null) { + char [] chars = new char [text.length ()]; + text.getChars (0, chars.length, chars, 0); + int length = fixMnemonic (chars); + nsMenuRep.setTitle(NSString.stringWithCharacters(chars, length)); + } + widget.setAttributedTitle(createString()); if (text.length() != 0 && image != null) { if ((parent.style & SWT.RIGHT) != 0) { @@ -1010,8 +1165,15 @@ public void setText (String string) { */ public void setToolTipText (String string) { checkWidget(); - toolTipText = string; - parent.checkToolTip (this); + toolTipText = string; + if (parent.nsToolbar != null) { + char[] chars = new char [toolTipText.length ()]; + string.getChars (0, chars.length, chars, 0); + int length = fixMnemonic (chars); + nsItem.setToolTip(NSString.stringWithCharacters (chars, length)); + } else { + parent.checkToolTip (this); + } } void setVisible (boolean visible) { @@ -1028,7 +1190,14 @@ void setVisible (boolean visible) { /** * Sets the width of the receiver, for <code>SEPARATOR</code> ToolItems. * - * @param width the new width + * @param width the new width. If the new value is <code>SWT.DEFAULT</code>, + * the width is a fixed-width area whose amount is determined by the platform. + * If the new value is 0 a vertical or horizontal line will be drawn, depending + * on the setting of the corresponding style bit (<code>SWT.VERTICAL</code> or + * <code>SWT.HORIZONTAL</code>). If the new value is <code>SWT.SEPARATOR_FILL</code> + * a variable-width space is inserted that acts as a spring between the two adjoining + * items which will push them out to the extent of the containing ToolBar. + * * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> @@ -1038,8 +1207,14 @@ void setVisible (boolean visible) { public void setWidth (int width) { checkWidget(); if ((style & SWT.SEPARATOR) == 0) return; - if (width < 0 || this.width == width) return; + if (width < SWT.SEPARATOR_FILL || this.width == width) return; this.width = width; + if (parent.nsToolbar != null) { + NSToolbar toolbar = parent.nsToolbar; + int index = parent.indexOf(this); + toolbar.removeItemAtIndex(index); + toolbar.insertItemWithItemIdentifier(getItemID(), index); + } parent.relayout(); } @@ -1083,4 +1258,8 @@ void updateImage (boolean layout) { parent.relayout(); } +boolean validateMenuItem(int /*long*/ id, int /*long*/ sel, int /*long*/ menuItem) { + return isEnabled(); +} + } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java index aefd75719f..9b58a860f4 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java @@ -666,6 +666,7 @@ void drawBackgroundInClipRect(int /*long*/ id, int /*long*/ sel, NSRect rect) { } void drawImageWithFrameInView (int /*long*/ id, int /*long*/ sel, int /*long*/ image, NSRect rect, int /*long*/ view) { + callSuper(id, sel, image, rect, view); } NSRect drawTitleWithFrameInView (int /*long*/ id, int /*long*/ sel, int /*long*/ title, NSRect rect, int /*long*/ view) { @@ -1062,6 +1063,10 @@ void mouseDown(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { mouseDownSuper(id, sel, theEvent); } +boolean mouseDownCanMoveWindow(int /*long*/ id, int /*long*/ sel) { + return callSuperBoolean(id, sel); +} + void mouseDownSuper(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) { callSuper(id, sel, theEvent); } @@ -1922,6 +1927,21 @@ NSRect titleRectForBounds (int /*long*/ id, int /*long*/ sel, NSRect cellFrame) 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; +} + +int /*long*/ toolbarSelectableItemIdentifiers(int /*long*/ id, int /*long*/ sel, int /*long*/ toolbar) { + return 0; +} String tooltipText () { return null; } @@ -1963,6 +1983,10 @@ boolean tableView_writeRowsWithIndexes_toPasteboard(int /*long*/ id, int /*long* return false; } +boolean validateMenuItem(int /*long*/ id, int /*long*/ sel, int /*long*/ menuItem) { + return true; +} + int /*long*/ view_stringForToolTip_point_userData (int /*long*/ id, int /*long*/ sel, int /*long*/ view, int /*long*/ tag, int /*long*/ point, int /*long*/ userData) { return 0; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java index 8d7c35511e..3557c797f5 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java @@ -1010,6 +1010,14 @@ public class SWT { */ public static final int SEPARATOR = 1 << 1; + /** + * Constant representing a flexible space separator in a ToolBar. + * <p><b>Used By:</b><ul> + * <li><code>ToolItem.setWidth()</code></li> + * </ul></p> + */ + public static final int SEPARATOR_FILL = -2; + /** * Style constant for toggle button behavior (value is 1<<1). * <p><b>Used By:</b><ul> diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java index 53576155cc..2cf8998b2e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java @@ -770,6 +770,29 @@ Composite findDeferredControl () { return layoutCount > 0 ? this : null; } +/** + * WARNING: API UNDER COSTRUCTION + * This API should be considered experimental and subject to change before the final release. + * + * Returns the instance of the ToolBar object representing the tool bar that can appear on the + * trim of the shell. This will return <code>null</code> if the platform does not support tool bars that + * not part of the content area of the shell, or if the style of the shell does not support a + * tool bar. + * <p> + * + * @return a ToolBar object representing the window's tool bar or null. + * + * @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> + * + * @since 3.7 + */ +public ToolBar getToolBar() { + return null; +} + boolean hasBorder () { return false; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java index 744b821434..0f6d5d62a0 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java @@ -1206,6 +1206,30 @@ public Point getSize () { getBounds (null, size, null); return size; } + +/** + * WARNING: API UNDER COSTRUCTION + * This API should be considered experimental and subject to change before the final release. + * + * Returns the instance of the ToolBar object representing the tool bar that can appear on the + * trim of the shell. This will return <code>null</code> if the platform does not support tool bars that + * not part of the content area of the shell, or if the style of the shell does not support a + * tool bar. + * <p> + * + * @return a ToolBar object representing the window's tool bar or null. + * + * @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> + * + * @since 3.7 + */ +public ToolBar getToolBar() { + return null; +} + public boolean getVisible () { checkWidget(); if (!OS.XtIsRealized (handle)) return false; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Shell.java index dbd6597d8c..32c090e6ae 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Shell.java @@ -791,6 +791,29 @@ public Point getSize () { return new Point (width, height); } +/** + * WARNING: API UNDER COSTRUCTION + * This API should be considered experimental and subject to change before the final release. + * + * Returns the instance of the ToolBar object representing the tool bar that can appear on the + * trim of the shell. This will return <code>null</code> if the platform does not support tool bars that + * not part of the content area of the shell, or if the style of the shell does not support a + * tool bar. + * <p> + * + * @return a ToolBar object representing the window's tool bar or null. + * + * @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> + * + * @since 3.7 + */ +public ToolBar getToolBar() { + return null; +} + void hookEvents () { super.hookEvents (); int windowProc = display.windowProc; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Shell.java index 662756b606..c26c92bd54 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Shell.java @@ -927,6 +927,29 @@ public class Shell extends Decorations { return result; } + /** + * WARNING: API UNDER COSTRUCTION + * This API should be considered experimental and subject to change before the final release. + * + * Returns the instance of the ToolBar object representing the tool bar that can appear on the + * trim of the shell. This will return <code>null</code> if the platform does not support tool bars that + * not part of the content area of the shell, or if the style of the shell does not support a + * tool bar. + * <p> + * + * @return a ToolBar object representing the window's tool bar or null. + * + * @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> + * + * @since 3.7 + */ + public ToolBar getToolBar() { + return null; + } + @Override protected Composite findDeferredControl() { return layoutCount > 0 ? this : null; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java index b15be30f19..ecc3782533 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java @@ -1134,6 +1134,29 @@ public Shell [] getShells () { return result; } +/** + * WARNING: API UNDER COSTRUCTION + * This API should be considered experimental and subject to change before the final release. + * + * Returns the instance of the ToolBar object representing the tool bar that can appear on the + * trim of the shell. This will return <code>null</code> if the platform does not support tool bars that + * not part of the content area of the shell, or if the style of the shell does not support a + * tool bar. + * <p> + * + * @return a ToolBar object representing the window's tool bar or null. + * + * @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> + * + * @since 3.7 + */ +public ToolBar getToolBar() { + return null; +} + Composite findDeferredControl () { return layoutCount > 0 ? this : null; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java index 2541aa19f1..7d847e5b08 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java @@ -869,7 +869,14 @@ public void setToolTipText (String string) { /** * Sets the width of the receiver, for <code>SEPARATOR</code> ToolItems. * - * @param width the new width + * @param width the new width. If the new value is <code>SWT.DEFAULT</code>, + * the width is a fixed-width area whose amount is determined by the platform. + * If the new value is 0 a vertical or horizontal line will be drawn, depending + * on the setting of the corresponding style bit (<code>SWT.VERTICAL</code> or + * <code>SWT.HORIZONTAL</code>). If the new value is <code>SWT.SEPARATOR_FILL</code> + * a variable-width space is inserted that acts as a spring between the two adjoining + * items which will push them out to the extent of the containing ToolBar. + * * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Shell.java index ba159fe4ba..8d65c22b15 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/widgets/Shell.java @@ -841,6 +841,29 @@ public Shell getShell () { return this; } +/** + * WARNING: API UNDER COSTRUCTION + * This API should be considered experimental and subject to change before the final release. + * + * Returns the instance of the ToolBar object representing the tool bar that can appear on the + * trim of the shell. This will return <code>null</code> if the platform does not support tool bars that + * not part of the content area of the shell, or if the style of the shell does not support a + * tool bar. + * <p> + * + * @return a ToolBar object representing the window's tool bar or null. + * + * @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> + * + * @since 3.7 + */ +public ToolBar getToolBar() { + return null; +} + public boolean getVisible () { checkWidget (); if ((style & SWT.ON_TOP) != 0)return OS.Popup_IsOpen (shellHandle); |