Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » change in handling of MenuDetect events ?
change in handling of MenuDetect events ? [message #451704] Sun, 06 March 2005 14:27 Go to next message
Eclipse UserFriend
Originally posted by: johns.atwork.comhem.se

There is a change in behavior i the MenuDetect handling from how it is done
in version 3.0.1 and how it is done in version 3.1M4 (and 3.1M5a).

OS: Windows XP sp2
JVM: j2re1.4.2_06

There is an example in a book on SWT where the event handler for MenuDetect
is the inital creator of the menu and in subsequent calls disposes of the menu
and creates a new menu with a sequence number that increases on each call.

In version 3.0 this works fine.

But in version 3.1 the context menu didn't show!?

After some experimenting I discovered that the menu was automatically
set visible in version 3.0 but that I had to explicitly setVisible(true)
in handleEvent in version 3.1.

If the event handler only modifies an existing menu, this is not a problem.

The event should make the context menu, if there is one, visible. But it
doesn't do it if the menu is created in the event handler (and susequently
set to the shell).

My question:

Did you (someone) move the setVisible(true) from being after the handleEvent (in version 3.0)
to being before it (in version 3.1)?

Thanks in advance!

/John Schluter
Re: change in handling of MenuDetect events ? [message #451719 is a reply to message #451704] Mon, 07 March 2005 15:12 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
Can you post some code showing the problem?

I have looked at the code where MenuDetect is sent and this has not changed
since M4.

"John S" <johns.atwork@comhem.se> wrote in message
news:d0f40d$jua$1@www.eclipse.org...
> There is a change in behavior i the MenuDetect handling from how it is
> done
> in version 3.0.1 and how it is done in version 3.1M4 (and 3.1M5a).
>
> OS: Windows XP sp2
> JVM: j2re1.4.2_06
>
> There is an example in a book on SWT where the event handler for
> MenuDetect
> is the inital creator of the menu and in subsequent calls disposes of the
> menu
> and creates a new menu with a sequence number that increases on each call.
>
> In version 3.0 this works fine.
>
> But in version 3.1 the context menu didn't show!?
>
> After some experimenting I discovered that the menu was automatically
> set visible in version 3.0 but that I had to explicitly setVisible(true)
> in handleEvent in version 3.1.
>
> If the event handler only modifies an existing menu, this is not a
> problem.
>
> The event should make the context menu, if there is one, visible. But it
> doesn't do it if the menu is created in the event handler (and susequently
> set to the shell).
>
> My question:
>
> Did you (someone) move the setVisible(true) from being after the
> handleEvent (in version 3.0)
> to being before it (in version 3.1)?
>
> Thanks in advance!
>
> /John Schluter
Re: change in handling of MenuDetect events ? [message #451738 is a reply to message #451719] Mon, 07 March 2005 19:13 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: johns.atwork.comhem.se

The following works perfectly if run with
the SWT in org.eclipse.swt.win32_3.0.1
(dll : swt-win32-3063.dll)

========================================================
/*
* Copyright (c) 2004 Steve Northover and Mike Wilson
* <long copyright notice cut here to save space>
*/
package part1.ch3;

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;

public class ContextMenu {

static int Count;
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.addListener(SWT.MenuDetect, new Listener() {
public void handleEvent(Event event) {
Menu menu = shell.getMenu();
if (menu != null) menu.dispose();
menu = new Menu(shell, SWT.POP_UP);
MenuItem item = new MenuItem(menu, SWT.PUSH);
item.setText("Menu " + Count++);
shell.setMenu(menu);
}
});
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}

}
========================================================

It does not work if run with
the SWT in org.eclipse.swt.win32_3.1.0
(dll : swt-win32-3116.dll)

or later.

I discovered that adding

menu.setVisible(true);

after

shell.setMenu(menu);

makes it work in 3.1M4 (and later).

The change was after version 3.0.1 and before or at version 3.1M4.

What I am guessing is that in version 3.0.1 if there exists a menu
*after* the eventhandler then it is set visible. But in version 3.1M4
if there exists a menu *before* the eventhandler then it is set visible.

Since the existing menu is disposed of in the eventhandler and
a new one is created (in the example above), the new one is not visible
in the case of version 3.1M4 and later. That is, not automatically.

/John Schluter

PS Thanks to Steve and Mike for a great book. I am learning alot very
quickly!


Veronika Irvine wrote:
> Can you post some code showing the problem?
>
> I have looked at the code where MenuDetect is sent and this has not changed
> since M4.
>
> "John S" <johns.atwork@comhem.se> wrote in message
> news:d0f40d$jua$1@www.eclipse.org...
>
>>There is a change in behavior i the MenuDetect handling from how it is
>>done
>>in version 3.0.1 and how it is done in version 3.1M4 (and 3.1M5a).
>>
>>OS: Windows XP sp2
>>JVM: j2re1.4.2_06
>>
>>There is an example in a book on SWT where the event handler for
>>MenuDetect
>>is the inital creator of the menu and in subsequent calls disposes of the
>>menu
>>and creates a new menu with a sequence number that increases on each call.
>>
>>In version 3.0 this works fine.
>>
>>But in version 3.1 the context menu didn't show!?
>>
>>After some experimenting I discovered that the menu was automatically
>>set visible in version 3.0 but that I had to explicitly setVisible(true)
>>in handleEvent in version 3.1.
>>
>>If the event handler only modifies an existing menu, this is not a
>>problem.
>>
>>The event should make the context menu, if there is one, visible. But it
>>doesn't do it if the menu is created in the event handler (and susequently
>>set to the shell).
>>
>>My question:
>>
>>Did you (someone) move the setVisible(true) from being after the
>>handleEvent (in version 3.0)
>>to being before it (in version 3.1)?
>>
>>Thanks in advance!
>>
>>/John Schluter
>
>
>
Re: change in handling of MenuDetect events ? [message #451748 is a reply to message #451738] Tue, 08 March 2005 13:00 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
Found the change. It happened Nov 5, 2004.

The following bug report tracks the problem:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=87363


"John S" <johns.atwork@comhem.se> wrote in message
news:d0i94g$or6$1@www.eclipse.org...
> The following works perfectly if run with
> the SWT in org.eclipse.swt.win32_3.0.1
> (dll : swt-win32-3063.dll)
>
> ========================================================
> /*
> * Copyright (c) 2004 Steve Northover and Mike Wilson
> * <long copyright notice cut here to save space>
> */
> package part1.ch3;
>
> import org.eclipse.swt.*;
> import org.eclipse.swt.widgets.*;
>
> public class ContextMenu {
>
> static int Count;
> public static void main(String[] args) {
> Display display = new Display();
> final Shell shell = new Shell(display);
> shell.addListener(SWT.MenuDetect, new Listener() {
> public void handleEvent(Event event) {
> Menu menu = shell.getMenu();
> if (menu != null) menu.dispose();
> menu = new Menu(shell, SWT.POP_UP);
> MenuItem item = new MenuItem(menu, SWT.PUSH);
> item.setText("Menu " + Count++);
> shell.setMenu(menu);
> }
> });
> shell.pack();
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch()) display.sleep();
> }
> display.dispose();
> }
>
> }
> ========================================================
>
> It does not work if run with
> the SWT in org.eclipse.swt.win32_3.1.0
> (dll : swt-win32-3116.dll)
>
> or later.
>
> I discovered that adding
>
> menu.setVisible(true);
>
> after
>
> shell.setMenu(menu);
>
> makes it work in 3.1M4 (and later).
>
> The change was after version 3.0.1 and before or at version 3.1M4.
>
> What I am guessing is that in version 3.0.1 if there exists a menu
> *after* the eventhandler then it is set visible. But in version 3.1M4
> if there exists a menu *before* the eventhandler then it is set visible.
>
> Since the existing menu is disposed of in the eventhandler and
> a new one is created (in the example above), the new one is not visible
> in the case of version 3.1M4 and later. That is, not automatically.
>
> /John Schluter
>
> PS Thanks to Steve and Mike for a great book. I am learning alot very
> quickly!
>
>
> Veronika Irvine wrote:
>> Can you post some code showing the problem?
>>
>> I have looked at the code where MenuDetect is sent and this has not
>> changed since M4.
>>
>> "John S" <johns.atwork@comhem.se> wrote in message
>> news:d0f40d$jua$1@www.eclipse.org...
>>
>>>There is a change in behavior i the MenuDetect handling from how it is
>>>done
>>>in version 3.0.1 and how it is done in version 3.1M4 (and 3.1M5a).
>>>
>>>OS: Windows XP sp2
>>>JVM: j2re1.4.2_06
>>>
>>>There is an example in a book on SWT where the event handler for
>>>MenuDetect
>>>is the inital creator of the menu and in subsequent calls disposes of the
>>>menu
>>>and creates a new menu with a sequence number that increases on each
>>>call.
>>>
>>>In version 3.0 this works fine.
>>>
>>>But in version 3.1 the context menu didn't show!?
>>>
>>>After some experimenting I discovered that the menu was automatically
>>>set visible in version 3.0 but that I had to explicitly setVisible(true)
>>>in handleEvent in version 3.1.
>>>
>>>If the event handler only modifies an existing menu, this is not a
>>>problem.
>>>
>>>The event should make the context menu, if there is one, visible. But it
>>>doesn't do it if the menu is created in the event handler (and
>>>susequently
>>>set to the shell).
>>>
>>>My question:
>>>
>>>Did you (someone) move the setVisible(true) from being after the
>>>handleEvent (in version 3.0)
>>>to being before it (in version 3.1)?
>>>
>>>Thanks in advance!
>>>
>>>/John Schluter
>>
>>
Re: change in handling of MenuDetect events ? [message #451750 is a reply to message #451748] Tue, 08 March 2005 14:31 Go to previous message
Eclipse UserFriend
Originally posted by: johns.atwork.comhem.se

Ok, now I understand.
Being new to SWT, I was unsure which behavior was correct but now I get it.

Thanks for the help and the info.

/John Schluter

Veronika Irvine wrote:

> Found the change. It happened Nov 5, 2004.

> The following bug report tracks the problem:

> https://bugs.eclipse.org/bugs/show_bug.cgi?id=87363


> "John S" <johns.atwork@comhem.se> wrote in message
> news:d0i94g$or6$1@www.eclipse.org...
>> The following works perfectly if run with
>> the SWT in org.eclipse.swt.win32_3.0.1
>> (dll : swt-win32-3063.dll)
>>
>> ========================================================
>> /*
>> * Copyright (c) 2004 Steve Northover and Mike Wilson
>> * <long copyright notice cut here to save space>
>> */
>> package part1.ch3;
>>
>> import org.eclipse.swt.*;
>> import org.eclipse.swt.widgets.*;
>>
>> public class ContextMenu {
>>
>> static int Count;
>> public static void main(String[] args) {
>> Display display = new Display();
>> final Shell shell = new Shell(display);
>> shell.addListener(SWT.MenuDetect, new Listener() {
>> public void handleEvent(Event event) {
>> Menu menu = shell.getMenu();
>> if (menu != null) menu.dispose();
>> menu = new Menu(shell, SWT.POP_UP);
>> MenuItem item = new MenuItem(menu, SWT.PUSH);
>> item.setText("Menu " + Count++);
>> shell.setMenu(menu);
>> }
>> });
>> shell.pack();
>> shell.open();
>> while (!shell.isDisposed()) {
>> if (!display.readAndDispatch()) display.sleep();
>> }
>> display.dispose();
>> }
>>
>> }
>> ========================================================
>>
>> It does not work if run with
>> the SWT in org.eclipse.swt.win32_3.1.0
>> (dll : swt-win32-3116.dll)
>>
>> or later.
>>
>> I discovered that adding
>>
>> menu.setVisible(true);
>>
>> after
>>
>> shell.setMenu(menu);
>>
>> makes it work in 3.1M4 (and later).
>>
>> The change was after version 3.0.1 and before or at version 3.1M4.
>>
>> What I am guessing is that in version 3.0.1 if there exists a menu
>> *after* the eventhandler then it is set visible. But in version 3.1M4
>> if there exists a menu *before* the eventhandler then it is set visible.
>>
>> Since the existing menu is disposed of in the eventhandler and
>> a new one is created (in the example above), the new one is not visible
>> in the case of version 3.1M4 and later. That is, not automatically.
>>
>> /John Schluter
>>
>> PS Thanks to Steve and Mike for a great book. I am learning alot very
>> quickly!
>>
>>
>> Veronika Irvine wrote:
>>> Can you post some code showing the problem?
>>>
>>> I have looked at the code where MenuDetect is sent and this has not
>>> changed since M4.
>>>
>>> "John S" <johns.atwork@comhem.se> wrote in message
>>> news:d0f40d$jua$1@www.eclipse.org...
>>>
>>>>There is a change in behavior i the MenuDetect handling from how it is
>>>>done
>>>>in version 3.0.1 and how it is done in version 3.1M4 (and 3.1M5a).
>>>>
>>>>OS: Windows XP sp2
>>>>JVM: j2re1.4.2_06
>>>>
>>>>There is an example in a book on SWT where the event handler for
>>>>MenuDetect
>>>>is the inital creator of the menu and in subsequent calls disposes of the
>>>>menu
>>>>and creates a new menu with a sequence number that increases on each
>>>>call.
>>>>
>>>>In version 3.0 this works fine.
>>>>
>>>>But in version 3.1 the context menu didn't show!?
>>>>
>>>>After some experimenting I discovered that the menu was automatically
>>>>set visible in version 3.0 but that I had to explicitly setVisible(true)
>>>>in handleEvent in version 3.1.
>>>>
>>>>If the event handler only modifies an existing menu, this is not a
>>>>problem.
>>>>
>>>>The event should make the context menu, if there is one, visible. But it
>>>>doesn't do it if the menu is created in the event handler (and
>>>>susequently
>>>>set to the shell).
>>>>
>>>>My question:
>>>>
>>>>Did you (someone) move the setVisible(true) from being after the
>>>>handleEvent (in version 3.0)
>>>>to being before it (in version 3.1)?
>>>>
>>>>Thanks in advance!
>>>>
>>>>/John Schluter
>>>
>>>
Previous Topic:DirectedGraph and the Edge.tree field
Next Topic:Browser Widget and <Ctrl> N
Goto Forum:
  


Current Time: Thu Apr 25 19:16:13 GMT 2024

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

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

Back to the top