Question about the Widget#showMenu function? [message #463421] |
Fri, 04 November 2005 22:47 |
Kevin 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 |
Veronika Irvine 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.
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.02913 seconds