Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 559920

Summary: [Win32] Opening a FileDialog resets radio buttons
Product: [Eclipse Project] Platform Reporter: Nikita Nemkin <nikita>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: dominik, paul-eclipse
Version: 4.15   
Target Milestone: ---   
Hardware: PC   
OS: Windows 10   
Whiteboard:
Attachments:
Description Flags
TestDialog.java none

Description Nikita Nemkin CLA 2020-02-07 08:04:44 EST
Created attachment 281735 [details]
TestDialog.java

When a FileDialog is closed, radio button selection in the parent shell is reset to the first ratio button.

Reported on StackOverflow: https://stackoverflow.com/questions/60099870/prevent-radio-buttons-resetting-after-push-button-has-been-clicked

Repro snippet by https://stackoverflow.com/users/12417497/dominik
Comment 1 Paul Pazderski CLA 2020-02-07 08:34:21 EST
Yes. See also bug 558015. 

From what I found so far it is a regression from bug 297510 because the savedFocus can contain the wrong radio button.
Comment 2 Dominik Maus CLA 2020-02-07 08:43:34 EST
If you move the push button above the radio buttons, the radio buttons won't reset.
Comment 3 Nikita Nemkin CLA 2020-02-07 08:52:16 EST
(In reply to Paul Pazderski from comment #1)
> Yes. See also bug 558015. 
> 
> From what I found so far it is a regression from bug 297510 because the
> savedFocus can contain the wrong radio button.

This might be a duplicate of Bug 558015, I'll investigate.

From my testing, the issue is that SWT can't properly save focus because GetFocus() in WM_ACTIVATE is zero. If the focus isn't saved, it falls on the first control in the tab order, which is a radio button.

It doesn't feel like SWT bug, more like some weird interaction between dialogs and focus.
Comment 4 Paul Pazderski CLA 2020-02-07 09:30:33 EST
(In reply to Nikita Nemkin from comment #3)
> (In reply to Paul Pazderski from comment #1)
> > Yes. See also bug 558015. 
> > 
> > From what I found so far it is a regression from bug 297510 because the
> > savedFocus can contain the wrong radio button.
> 
> This might be a duplicate of Bug 558015, I'll investigate.

I would be surprised if not.

> From my testing, the issue is that SWT can't properly save focus because
> GetFocus() in WM_ACTIVATE is zero.

Saw the same but couldn't find a reason.

> It doesn't feel like SWT bug, more like some weird interaction between
> dialogs and focus.

Well I wouldn't disagree but I bisected the problem (for bug 558015) and it worked (maybe by luck) before bug 297510.

I uploaded what I have tried as fix in bug 558015. https://git.eclipse.org/r/157366
It basically restores the special focus handling for radio button removed with bug 297510.
Comment 5 Nikita Nemkin CLA 2020-02-07 11:35:34 EST
(In reply to Paul Pazderski from comment #4)
> > From my testing, the issue is that SWT can't properly save focus because
> > GetFocus() in WM_ACTIVATE is zero.
> 
> Saw the same but couldn't find a reason.
Here's the reason, from CFileOpenSave::Show in comdlg32.dll

  v48 = GetFocus();
  v110 = v48;
  if ( !(unsigned int)SHIsChildOrSelf(hWnd, v48) )
  {
    v94 = 1;
    SetFocus(0i64);
  }

No idea why they are doing this. Maybe just to make us miserable...

> > It doesn't feel like SWT bug, more like some weird interaction between
> > dialogs and focus.
> 
> Well I wouldn't disagree but I bisected the problem (for bug 558015) and it
> worked (maybe by luck) before bug 297510.
> 
> I uploaded what I have tried as fix in bug 558015.
> https://git.eclipse.org/r/157366
> It basically restores the special focus handling for radio button removed
> with bug 297510.
Do you think your patch is still necessary if we fix focus saving? I mean, if we save focus for a radio button, it has to be selected already, so restoring it to selected state is fine. Is focused but unselected radio button possible at all? That special radio focus was added in Bug 93870, but I can't reproduce the original problem.

Focus saving isn't difficult to fix. I think an extra saveFocus() in WM_KILLFOCUS (when the target is zero) will do the trick.
Comment 6 Nikita Nemkin CLA 2020-02-07 11:36:08 EST

*** This bug has been marked as a duplicate of bug 558015 ***