Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to access Mac About, Preferences and Quit from SWT
How to access Mac About, Preferences and Quit from SWT [message #449311] Fri, 21 January 2005 07:36 Go to next message
Ivan is currently offline IvanFriend
Messages: 149
Registered: July 2009
Senior Member
Hi all,

Is there anyway to link the About, Preferences and Quit into Mac menu ?

Thanks
Re: How to access Mac About, Preferences and Quit from SWT [message #449340 is a reply to message #449311] Fri, 21 January 2005 23:41 Go to previous messageGo to next message
Daniel Spiewak is currently offline Daniel SpiewakFriend
Messages: 263
Registered: July 2009
Senior Member
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
<font face="serif">Not from SWT proper.&nbsp; You have to use the classes in
the com.apple.cocoa.awt (very rough, it's something to that effect, use
content assist to find it).&nbsp; I suggest digging around in the classes
using content assist to find the one you need.&nbsp; The methods are pretty
self explanatory.<br>
<br>
Daniel<br>
</font><br>
Ivan wrote:
<blockquote cite="mid41F0B10B.4040508@pd.jaring.my" type="cite">Hi all,
<br>
<br>
&nbsp;&nbsp;&nbsp; Is there anyway to link the About, Preferences and Quit into Mac
menu ?
<br>
<br>
Thanks
<br>
<br>
</blockquote>
</body>
</html>
Re: How to access Mac About, Preferences and Quit from SWT [message #449343 is a reply to message #449340] Sat, 22 January 2005 07:01 Go to previous message
Benjamin Pasero is currently offline Benjamin PaseroFriend
Messages: 337
Registered: July 2009
Senior Member
Here is a Snippet that Andre Weinand once sent me as example on how to
create those Menus, maybe that helps:

import org.eclipse.swt.SWT;
import org.eclipse.swt.internal.Callback;
import org.eclipse.swt.internal.carbon.HICommand;
import org.eclipse.swt.internal.carbon.OS;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;

public class AppMenu {

private static final int kHICommandPreferences=
('p' << 24) + ('r' << 16) + ('e' << 8) + 'f';
private static final int kHICommandAbout=
('a' << 24) + ('b' << 16) + ('o' << 8) + 'u';
private static final int kHICommandServices=
('s' << 24) + ('e' << 16) + ('r' << 8) + 'v';

public static void main(String[] arg) {

Display.setAppName("AppMenu"); // sets name in Dock

Display display= Display.getDefault();

hookApplicationMenu(display, "About AppMenu");

Shell shell= new Shell(display);
shell.setText("Main Window");
shell.open();

while (!shell.isDisposed())
if (!display.readAndDispatch())
display.sleep();

display.dispose();
}

static void hookApplicationMenu(Display display, final String aboutName)
{

// Callback target
Object target= new Object() {
int commandProc(int nextHandler, int theEvent, int userData) {
if (OS.GetEventKind(theEvent) == OS.kEventProcessCommand) {
HICommand command= new HICommand();
OS.GetEventParameter(theEvent,
OS.kEventParamDirectObject, OS.typeHICommand, null,
HICommand.sizeof, null, command);
switch (command.commandID) {
case kHICommandPreferences:
return handleCommand("Preferences"); //$NON-NLS-1$
case kHICommandAbout:
return handleCommand(aboutName);
default:
break;
}
}
return OS.eventNotHandledErr;
}

int handleCommand(String command) {
Shell shell= new Shell();
MessageBox preferences= new MessageBox(shell,
SWT.ICON_WARNING);
preferences.setText(command);
preferences.open();
shell.dispose();
return OS.noErr;
}
};

final Callback commandCallback= new Callback(target,
"commandProc", 3); //$NON-NLS-1$
int commandProc= commandCallback.getAddress();
if (commandProc == 0) {
commandCallback.dispose();
return; // give up
}

// Install event handler for commands
int[] mask= new int[] { OS.kEventClassCommand,
OS.kEventProcessCommand};
OS.InstallEventHandler(OS.GetApplicationEventTarget(), commandProc,
mask.length / 2, mask, 0, null);

// create About ... menu command
int[] outMenu= new int[1];
short[] outIndex= new short[1];
if (OS.GetIndMenuItemWithCommandID(0, kHICommandPreferences, 1,
outMenu, outIndex) == OS.noErr && outMenu[0] != 0) {
int menu= outMenu[0];

int l= aboutName.length();
char buffer[]= new char[l];
aboutName.getChars(0, l, buffer, 0);
int str= OS.CFStringCreateWithCharacters(OS.kCFAllocatorDefault,
buffer, l);
OS.InsertMenuItemTextWithCFString(menu, str, (short) 0, 0,
kHICommandAbout);
OS.CFRelease(str);

// add separator between About & Preferences
OS.InsertMenuItemTextWithCFString(menu, 0, (short) 1,
OS.kMenuItemAttrSeparator, 0);

// enable pref menu
OS.EnableMenuCommand(menu, kHICommandPreferences);

// disable services menu
OS.DisableMenuCommand(menu, kHICommandServices);
}

// schedule disposal of callback object
display.disposeExec(new Runnable() {
public void run() {
commandCallback.dispose();
}
});
}

Ben
}


> Not from SWT proper. You have to use the classes in the
> com.apple.cocoa.awt (very rough, it's something to that effect, use
> content assist to find it). I suggest digging around in the classes
> using content assist to find the one you need. The methods are pretty
> self explanatory.
>
> Daniel
>
> Ivan wrote:
>
>> Hi all,
>>
>> Is there anyway to link the About, Preferences and Quit into Mac
>> menu ?
>>
>> Thanks
>>
Previous Topic:Image resizing (a smoother way?)
Next Topic:TableEditor Question/Proglem
Goto Forum:
  


Current Time: Thu Apr 18 02:58:56 GMT 2024

Powered by FUDForum. Page generated in 0.02032 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top