Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Handling of SelectionChanging-Event on a TabFolder causes freeze of Mouse and Keyboard Events
Handling of SelectionChanging-Event on a TabFolder causes freeze of Mouse and Keyboard Events [message #436035] Mon, 10 May 2004 09:03 Go to next message
Eclipse UserFriend
Originally posted by: mbu.glance.ch

Hi

I'm trying to handle a SelectionChanging event on a TabFolder in order
to ask the user whether or not to save the contents of a TabItem before
changing the selection. The problem is that after the MessageBox is
disposed, event handling for the entire shell (onMouseOver in the menu,
the cursor change when moving over textfields, key accelerators etc.) is
blocked until i mouse-click somewhere in the shell. The effect appears
no matter whether the tab was changed or not. I tried several things
including explicitly setting the focus to certain widgets after closing
the Messagebox. The focus can be set and even text can be entered in
Text widgets, but still the MouseOver events and global key accelerators
are disabled.

I wonder if anybody has encountered a similar "freeze" of window events.
I believe it has to do with the MessageBox that is opened in the event
handling loop of the SelectionChanging event. When I dont' open a
Messagebox it all works fine. If the Messagebox ist made non-modal, the
freeze only appears after disposing the box, not while it's open. Does
the MessageBox.dispose() method somehow interfere with open shells?

I'm using swt-win32-2135.dll on Win2k.

Thanks for any hint!
Martin

--------
PS:
Here is some of the code I use:

A subclass of TabFolder knows about OS.TCN_SELCHANGING:

public class TabFolderX extends TabFolder {
LRESULT wmNotifyChild(int wParam, int lParam) {
NMHDR hdr = new NMHDR();
OS.MoveMemory(hdr, lParam, NMHDR.sizeof);
int code = hdr.code;
if (code == OS.TCN_SELCHANGING) {
if (!onSelChanging())
return LRESULT.ONE;
}
return super.wmNotifyChild(wParam, lParam);
}

private boolean onSelChanging() {
TabItem item = null;
int index = OS.SendMessage(handle, OS.TCM_GETCURSEL, 0, 0);
if (index != -1)
item = items[index];

Event event = new Event();
event.item = item;
sendEvent(SWTX.SelectionChanging, event);
return event.doit;
}

The SelectionChanging event is then handled by a TypedListenerX:

public class TypedListenerX extends TypedListener{
public void handleEvent(Event e) {
if (e.type == SWTX.SelectionChanging) {
e.doit =
((SelectionChangingListener) eventListener).selectionChanging(
new SelectionChangingEvent(e));
}
else {
super.handleEvent(e);
}
}
}

And here is my event handler:

public boolean selectionChanging(SelectionChangingEvent e){
MessageBox box = new MessageBox(_shell, SWT.YES | SWT.NO |
SWT.ICON_QUESTION);
box.setMessage("Do you really want to change the tab?");
return box.open()==SWT.YES;
}
--------------
Re: Handling of SelectionChanging-Event on a TabFolder causes freeze of Mouse and Keyboard Events [message #436083 is a reply to message #436035] Tue, 11 May 2004 09:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mbu.glance.ch

I figured out what the problem is but did not manage to solve it.

The OS.TCN_SELCHANGING event is triggered on MouseDown. Then i show the
dialog and let the user choose what to do. The problem is, that the
TabFolder never sees a MouseUp Event and stays in the MouseDown state.
When I change the tab by keyboard it all works fine.

So I tried to fake a MouseUp event before or after I open the dialog,
e.g. as follows:

--
if (code == OS.TCN_SELCHANGING){
int captureBefore = OS.GetCapture();
boolean doChange = onSelChanging(); // This opens the dialog
OS.SetCapture(captureBefore);

MSG buttonUpMsg = new MSG();
buttonUpMsg.message = OS.WM_LBUTTONUP;
buttonUpMsg.hwnd = handle;
buttonUpMsg.wParam = 0;
buttonUpMsg.lParam = lParam;
OS.DispatchMessage(buttonUpMsg);
--

Unfortunately my efforts didn't have any effect. Does anybody have an
idea how to solve this problem, e.g. by properly generating a fake mouse
event?

Thanks in advance
Martin
Re: Handling of SelectionChanging-Event on a TabFolder causes freeze of Mouse and Keyboard Events [message #436088 is a reply to message #436083] Tue, 11 May 2004 13:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: v.j.b

> Unfortunately my efforts didn't have any effect. Does anybody have an
> idea how to solve this problem, e.g. by properly generating a fake mouse
> event?

it seems you are directly extending an swt win32 widget implementation (ie,
tabfolder); besides the platform specific stuff you're working with, and the
possible problems (if any) on other platforms, isn't it easier just to add
some selectionlisteners to the tabfolder in question, and depending on user
input, set the 'event.doit' field to true, or false?

I haven't tested this, so i might be way off here.
Re: Handling of SelectionChanging-Event on a TabFolder causes freeze of Mouse and Keyboard Events [message #436093 is a reply to message #436088] Tue, 11 May 2004 14:06 Go to previous message
Eclipse UserFriend
Originally posted by: mbu.glance.ch

varname wrote:
>>Unfortunately my efforts didn't have any effect. Does anybody have an
>>idea how to solve this problem, e.g. by properly generating a fake mouse
>>event?
>
>
> it seems you are directly extending an swt win32 widget implementation (ie,
> tabfolder); besides the platform specific stuff you're working with, and the
> possible problems (if any) on other platforms, isn't it easier just to add
> some selectionlisteners to the tabfolder in question, and depending on user
> input, set the 'event.doit' field to true, or false?

The problem is that the SelectionListener's widgetSelected method is
called when the selection has already changed (the new tabitem is
already loaded). So the event.doit flag has no effect.
Previous Topic:Problem with SWT_AWT
Next Topic:SWT Versions?
Goto Forum:
  


Current Time: Thu Apr 25 19:54:35 GMT 2024

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

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

Back to the top