|
Lines 25-33
Link Here
|
| 25 |
import org.eclipse.swt.widgets.Menu; |
25 |
import org.eclipse.swt.widgets.Menu; |
| 26 |
import org.eclipse.swt.widgets.MenuItem; |
26 |
import org.eclipse.swt.widgets.MenuItem; |
| 27 |
import org.eclipse.swt.widgets.Shell; |
27 |
import org.eclipse.swt.widgets.Shell; |
|
|
28 |
import org.eclipse.swt.widgets.Widget; |
| 28 |
import org.eclipse.ui.IStartup; |
29 |
import org.eclipse.ui.IStartup; |
|
|
30 |
import org.eclipse.ui.IWindowListener; |
| 29 |
import org.eclipse.ui.IWorkbenchWindow; |
31 |
import org.eclipse.ui.IWorkbenchWindow; |
| 30 |
import org.eclipse.ui.PlatformUI; |
32 |
import org.eclipse.ui.PlatformUI; |
|
|
33 |
import org.eclipse.ui.internal.WorkbenchWindow; |
| 31 |
|
34 |
|
| 32 |
/** |
35 |
/** |
| 33 |
* The CarbonUIEnhancer provides the standard "About" and "Preference" menu items |
36 |
* The CarbonUIEnhancer provides the standard "About" and "Preference" menu items |
|
Lines 80-90
Link Here
|
| 80 |
display.syncExec(new Runnable() { |
83 |
display.syncExec(new Runnable() { |
| 81 |
public void run() { |
84 |
public void run() { |
| 82 |
hookApplicationMenu(display); |
85 |
hookApplicationMenu(display); |
|
|
86 |
hookToolbarButton(); |
| 87 |
hookWorkbenchListener(); |
| 83 |
} |
88 |
} |
| 84 |
}); |
89 |
}); |
| 85 |
} |
90 |
} |
| 86 |
|
91 |
|
| 87 |
/** |
92 |
/** |
|
|
93 |
* Hooks a listener that tweaks newly opened workbench window shells with the proper OS flags |
| 94 |
*/ |
| 95 |
protected void hookWorkbenchListener() { |
| 96 |
PlatformUI.getWorkbench().addWindowListener(new IWindowListener() { |
| 97 |
|
| 98 |
public void windowActivated(IWorkbenchWindow window) { |
| 99 |
// no-op |
| 100 |
} |
| 101 |
|
| 102 |
public void windowDeactivated(IWorkbenchWindow window) { |
| 103 |
// no-op |
| 104 |
} |
| 105 |
|
| 106 |
public void windowClosed(IWorkbenchWindow window) { |
| 107 |
// no-op |
| 108 |
} |
| 109 |
|
| 110 |
public void windowOpened(IWorkbenchWindow window) { |
| 111 |
// modify the newly opened window with the correct OS X style |
| 112 |
// bits such that it possesses the toolbar button |
| 113 |
Shell shell = window.getShell(); |
| 114 |
int windowHandle = shell.shellHandle; |
| 115 |
OS.ChangeWindowAttributes(windowHandle, |
| 116 |
OS.kWindowToolbarButtonAttribute, 0); |
| 117 |
}}); |
| 118 |
|
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* Hook the window toolbar button to toggle the visibility of the coolbar and perspective bar. |
| 123 |
*/ |
| 124 |
protected void hookToolbarButton() { |
| 125 |
Object target = new Object() { |
| 126 |
int toolbarProc (int nextHandler, int theEvent, int userData) { |
| 127 |
int eventKind = OS.GetEventKind (theEvent); |
| 128 |
if (eventKind != OS.kEventWindowToolbarSwitchMode) |
| 129 |
return OS.eventNotHandledErr; |
| 130 |
|
| 131 |
int [] theWindow = new int [1]; |
| 132 |
OS.GetEventParameter (theEvent, OS.kEventParamDirectObject, OS.typeWindowRef, null, 4, null, theWindow); |
| 133 |
|
| 134 |
int [] theRoot = new int [1]; |
| 135 |
OS.GetRootControl (theWindow [0], theRoot); |
| 136 |
Widget widget = Display.getCurrent().findWidget(theRoot [0]); |
| 137 |
|
| 138 |
if (!(widget instanceof Shell)) { |
| 139 |
return OS.eventNotHandledErr; |
| 140 |
} |
| 141 |
Shell shell = (Shell) widget; |
| 142 |
IWorkbenchWindow [] windows = PlatformUI.getWorkbench().getWorkbenchWindows(); |
| 143 |
for (int i = 0; i < windows.length; i++) { |
| 144 |
if (windows[i].getShell() == shell) { |
| 145 |
WorkbenchWindow castedWindow = (WorkbenchWindow) windows[i]; |
| 146 |
boolean coolbarVisible = castedWindow.getCoolBarVisible(); |
| 147 |
boolean perspectivebarVisible = castedWindow.getPerspectiveBarVisible(); |
| 148 |
castedWindow.setCoolBarVisible(!coolbarVisible); |
| 149 |
castedWindow.setPerspectiveBarVisible(!perspectivebarVisible); |
| 150 |
shell.layout(); |
| 151 |
} |
| 152 |
} |
| 153 |
return OS.eventNotHandledErr; |
| 154 |
} |
| 155 |
|
| 156 |
}; |
| 157 |
|
| 158 |
final Callback commandCallback = new Callback(target, "toolbarProc", 3); //$NON-NLS-1$ |
| 159 |
int commandProc = commandCallback.getAddress(); |
| 160 |
if (commandProc == 0) { |
| 161 |
commandCallback.dispose(); |
| 162 |
return; // give up |
| 163 |
} |
| 164 |
|
| 165 |
int[] mask = new int[] { OS.kEventClassWindow, OS.kEventWindowToolbarSwitchMode }; |
| 166 |
OS.InstallEventHandler(OS.GetApplicationEventTarget(), commandProc, |
| 167 |
mask.length / 2, mask, 0, null); |
| 168 |
|
| 169 |
} |
| 170 |
|
| 171 |
/** |
| 88 |
* See Apple Technical Q&A 1079 (http://developer.apple.com/qa/qa2001/qa1079.html) |
172 |
* See Apple Technical Q&A 1079 (http://developer.apple.com/qa/qa2001/qa1079.html) |
| 89 |
*/ |
173 |
*/ |
| 90 |
private void hookApplicationMenu(Display display) { |
174 |
private void hookApplicationMenu(Display display) { |