Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Question about the Widget#showMenu function?
Question about the Widget#showMenu function? [message #463421] Fri, 04 November 2005 22:47 Go to next message
Kevin is currently offline KevinFriend
Messages: 34
Registered: July 2009
Member
boolean showMenu (int x, int y) {
Event event = new Event ();
event.x = x;
event.y = y;
sendEvent (SWT.MenuDetect, event);
if (!event.doit) return true;
Menu menu = getMenu ();
if (menu != null && !menu.isDisposed ()) {
if (x != event.x || y != event.y) {
menu.setLocation (event.x, event.y);
}
menu.setVisible (true);
return true;
}
return false;
}


The event.x, y are set to the x, y parameter. Why does it need the " if (x
!= event.x || y != event.y)" to call the menu.setLocation. Does the
sendEvent or somewhere will modify the event.x,y? What condtion is that if
statement true?

I try the menu.setLocation, but I find out I need to set it back to 0.
Otherwise, the next menu popup will be at that location.

Thanks,

Kevin.
Re: Question about the Widget#showMenu function? [message #463462 is a reply to message #463421] Mon, 07 November 2005 15:42 Go to previous message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
In the event handler, the application can change the event.x and event.y
values. For example:

public static void main(String[] args) {
Display display = new Display();
final Clipboard cb = new Clipboard(display);
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
Menu menu = new Menu(shell, SWT.POP_UP);
final MenuItem item = new MenuItem(menu, SWT.PUSH);
item.setText("Menu Item");
shell.addListener(SWT.MenuDetect, new Listener() {
public void handleEvent(Event e) {
e.x = 10;
e.y = 10;
}
});
shell.setMenu(menu);
shell.setSize(200, 200);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
cb.dispose();
display.dispose();
}


"Kevin" <kevinlouisnospam@hotmail.com> wrote in message
news:dkgodd$2bn$1@news.eclipse.org...
> boolean showMenu (int x, int y) {
> Event event = new Event ();
> event.x = x;
> event.y = y;
> sendEvent (SWT.MenuDetect, event);
> if (!event.doit) return true;
> Menu menu = getMenu ();
> if (menu != null && !menu.isDisposed ()) {
> if (x != event.x || y != event.y) {
> menu.setLocation (event.x, event.y);
> }
> menu.setVisible (true);
> return true;
> }
> return false;
> }
>
>
> The event.x, y are set to the x, y parameter. Why does it need the " if
> (x
> != event.x || y != event.y)" to call the menu.setLocation. Does the
> sendEvent or somewhere will modify the event.x,y? What condtion is that
> if
> statement true?
>
> I try the menu.setLocation, but I find out I need to set it back to 0.
> Otherwise, the next menu popup will be at that location.
>
> Thanks,
>
> Kevin.
>
>
Previous Topic:Wanted: Example of IE Browser in Pane
Next Topic:How to select only one cell in a Table
Goto Forum:
  


Current Time: Thu Apr 18 22:58:06 GMT 2024

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

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

Back to the top