Bug 275987 - SWT seems to prevent WS_EX_NOACTIVATE from having any effect
Summary: SWT seems to prevent WS_EX_NOACTIVATE from having any effect
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.4.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Steve Northover CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-05-12 19:28 EDT by Peter Flynn (Adobe) CLA
Modified: 2019-09-06 16:19 EDT (History)
3 users (show)

See Also:


Attachments
Testcase SWT snippet (2.03 KB, application/octet-stream)
2009-05-12 19:28 EDT, Peter Flynn (Adobe) CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Flynn (Adobe) CLA 2009-05-12 19:28:43 EDT
Created attachment 135480 [details]
Testcase SWT snippet

Build ID: M20080911-1700

Steps To Reproduce:
1. Run the attached snippet
2. Click the "Open popup" button
3. Click on the red popup area

Result: the original window is no longer the active window

Expected: original window stays active, since popup is not supposed to activate (see MSDN docs)


More information:
The other way to make a window not activate on click is to hook WM_MOUSEACTIVATE and return MA_NOACTIVATE, but of course subclassing event handlers is pretty much impossible in SWT.  If you're willing to have the window be SWT.ON_TOP you can get SWT's own event handler to return this return code, but that puts the window over top of every app on your OS, which may not be acceptable.
Comment 1 Felipe Heidrich CLA 2009-05-13 09:35:24 EDT
You can't call internal APIs, your testcase is not supported.

Not sure what you are trying to accomplish, but I think you want to open the shell using shell.setVisible(true) instead of shell.open();
Comment 2 Steve Northover CLA 2009-05-13 09:55:54 EDT
Let me take a look at this ...
Comment 3 Peter Flynn (Adobe) CLA 2009-05-13 17:06:02 EDT
To clarify, the goal is to make a window that does not become the active window when clicked. SWT only supports this behavior for SWT.ON_TOP Shells, so you have to fall back to OS-specific code if you want it otherwise. WS_EX_NOACTIVATE is a standard way to do this on Windows, but SWT is doing something that subverts this flag.
Comment 4 Steve Northover CLA 2009-05-13 18:19:59 EDT
First off, you patch sets GWL_STYLE instead of GWL_EXSTYLE.  I changed this and it still didn't fix the problem.  The documentation says that a window won't become active unless someone calls ActivateWindow() or SetForegroundWindow().  I'm pretty sure the operating system calls these things internally for native controls such as buttons.  However, I could be wrong.

Can you confirm 100% that WS_EX_NOACTIVATE does what you want using native code and that SWT is doing something bad?
Comment 5 Felipe Heidrich CLA 2009-05-14 09:40:04 EDT
This worked for me:

Shell window = new Shell(mainWindow, SWT.NO_TRIM);
window.setLayout(new FillLayout());
		
Label label = new Label(window, SWT.NONE);
label.setText("Popup!");
label.setBackground(new Color(null, 255,200,200));

window.setSize(200, 100);
window.addListener(SWT.Activate, new Listener() {
	public void handleEvent(Event e) {
		mainWindow.setActive();
	}
});
			
window.setVisible(true);

----------------------------------------------

Peter, is that the behaviour you want ?

Steve, do you see any problems with the code above ?
Comment 6 Steve Northover CLA 2009-05-14 12:30:19 EDT
Felipe, I think that Peter never wants the popup to get focus, even when clicked with the mouse.

As far as I know, this is not possible unless all controls don't call SetActiveWindow() as in comment #7.  It's possible to make all controls that you write not call this, but built-in controls such as the native push button can call this way down deep in the C code of Windows.

What exactly are you trying to do?
Comment 7 Steve Northover CLA 2009-05-14 12:35:38 EDT
Wow.  Ok, now I read Felipe's code.  He is making another window active when the popup becomes active.  This looks a bit dangerous because you might get into a loop where activating one window activates the other (if you are not carful using this approach).
Comment 8 Eclipse Webmaster CLA 2019-09-06 16:19:20 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.