View | Details | Raw Unified | Return to bug 104744 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ui/carbon/CarbonUIEnhancer.java (-1 / +53 lines)
Lines 19-24 Link Here
19
import org.eclipse.jface.action.ActionContributionItem;
19
import org.eclipse.jface.action.ActionContributionItem;
20
import org.eclipse.jface.action.IAction;
20
import org.eclipse.jface.action.IAction;
21
import org.eclipse.swt.internal.Callback;
21
import org.eclipse.swt.internal.Callback;
22
import org.eclipse.swt.internal.carbon.EventRecord;
22
import org.eclipse.swt.internal.carbon.HICommand;
23
import org.eclipse.swt.internal.carbon.HICommand;
23
import org.eclipse.swt.internal.carbon.OS;
24
import org.eclipse.swt.internal.carbon.OS;
24
import org.eclipse.swt.widgets.Display;
25
import org.eclipse.swt.widgets.Display;
Lines 85-90 Link Here
85
            public void run() {
86
            public void run() {
86
				hookApplicationMenu(display);
87
				hookApplicationMenu(display);
87
				hookToolbarButtonCallback();
88
				hookToolbarButtonCallback();
89
				hookApplescriptCallback();
88
				hookWorkbenchListener();
90
				hookWorkbenchListener();
89
				// modify all shells opened on startup
91
				// modify all shells opened on startup
90
				IWorkbenchWindow[] windows = PlatformUI.getWorkbench()
92
				IWorkbenchWindow[] windows = PlatformUI.getWorkbench()
Lines 96-102 Link Here
96
        });
98
        });
97
    }
99
    }
98
100
99
    /**
101
    protected void hookApplescriptCallback() {
102
		Object target = new Object() {
103
			public int applescriptProc(int nextHandler, int inEvent,
104
					int userData) {
105
				boolean doRelease = false;
106
				int err = OS.noErr;
107
				EventRecord eventRecord = new EventRecord();
108
109
				if (doRelease = OS.IsEventInQueue(OS.GetMainEventQueue(),
110
						inEvent)) {
111
112
					OS.RetainEvent(inEvent);
113
					OS.RemoveEventFromQueue(OS.GetMainEventQueue(), inEvent);
114
				}
115
116
				OS.ConvertEventRefToEventRecord(inEvent, eventRecord);
117
				err = OS.AEProcessAppleEvent(eventRecord);
118
				if (doRelease)
119
					OS.ReleaseEvent(inEvent);
120
				return err;
121
			}
122
123
		};
124
		final Callback commandCallback = new Callback(target,
125
				"applescriptProc", 3); //$NON-NLS-1$
126
		int commandProc = commandCallback.getAddress();
127
		if (commandProc == 0) {
128
			commandCallback.dispose();
129
			return; // give up
130
		}
131
132
		int[] mask = new int[] { OS.kEventClassAppleEvent, OS.kEventAppleEvent };
133
		OS.InstallEventHandler(OS.GetApplicationEventTarget(), commandProc,
134
				mask.length / 2, mask, 0, null);
135
		
136
		Object openAppleScriptHandler = new Object() {
137
			public int handle(int inEvent, int outEvent, int ref) {
138
				System.out.println("Handled."); //$NON-NLS-1$
139
				return OS.noErr;
140
			}
141
		};
142
		final Callback appleScriptCallback = new Callback(openAppleScriptHandler, "handle", 3); //$NON-NLS-1$
143
		int openAppleScriptProc = appleScriptCallback.getAddress();
144
		if (openAppleScriptProc == 0) {
145
			appleScriptCallback.dispose();
146
			return; // give up
147
		}
148
		OS.AEInstallEventHandler(AppleScriptConstants.kCoreEventClass, AppleScriptConstants.kAEOpenApplication, openAppleScriptProc, 0, false);
149
	}
150
151
	/**
100
	 * Hooks a listener that tweaks newly opened workbench window shells with
152
	 * Hooks a listener that tweaks newly opened workbench window shells with
101
	 * the proper OS flags.
153
	 * the proper OS flags.
102
	 * 
154
	 * 
(-)src/org/eclipse/ui/carbon/AppleScriptHelper.java (+35 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.ui.carbon;
13
14
15
/**
16
 * @since 3.2
17
 *
18
 */
19
public final class AppleScriptHelper {
20
	
21
	/**
22
	 * Generate the integer event id based on a 4 character event string.
23
	 * 
24
	 * @param eventId
25
	 *            the 4 character event string
26
	 * @return the integer event id
27
	 */
28
	public static int generateEventId(String eventId) {
29
//		if (eventId.length() != 4)
30
//			throw new IllegalArgumentException();
31
32
		return (eventId.charAt(0) << 24) + (eventId.charAt(1) << 16)
33
				+ (eventId.charAt(2) << 8) + eventId.charAt(3);
34
	}
35
}
(-)src/org/eclipse/ui/carbon/AppleScriptConstants.java (+36 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.carbon;
12
13
/**
14
 * 
15
 * @since 3.2
16
 */
17
public interface AppleScriptConstants {
18
19
	public final static int kCoreEventClass = AppleScriptHelper
20
			.generateEventId("aevt"); //$NON-NLS-1$
21
22
	public final static int kAEOpenApplication = AppleScriptHelper
23
			.generateEventId("oapp"); //$NON-NLS-1$
24
25
	public final static int kAEReopenApplication = AppleScriptHelper
26
			.generateEventId("rapp"); //$NON-NLS-1$
27
28
	public final static int kAEOpenDocuments = AppleScriptHelper
29
			.generateEventId("odoc"); //$NON-NLS-1$
30
31
	public final static int kAEPrintDocuments = AppleScriptHelper
32
			.generateEventId("pdoc"); //$NON-NLS-1$
33
34
	public final static int kAEOpenContents = AppleScriptHelper
35
			.generateEventId("ocon"); //$NON-NLS-1$
36
}

Return to bug 104744