Opened 7 years ago

Closed 11 months ago

Last modified 11 months ago

#9528 closed defect (fixed)

wxMSW can show 2 default buttons in a dialog

Reported by: mghie Owned by: vadz
Priority: normal Milestone:
Component: wxMSW Version: dev-latest
Keywords: wxButton SetDefault SetDefaultStyle Cc: mghie
Blocked By: Blocking:
Patch: yes

Description

Hi,

there is a problem with default buttons on MSW, more than one button can have the default appearance. Tested with 2.8 branch on Windows 2000 (compiled with MSVC++ 2003) and with SVN on Windows XP (compiled with MSVC++ 2008). Attached screen shot shows the problem, to reproduce simply open the generic colour chooser in the dialog sample (the OK button is visible as the default one), press the left mouse button on the Cancel button, drag the caret outside of the button and release the left button. Now both the OK and the Cancel button have the default border, and the Cancel button is focused.
There are more problems when SetDefault() is called explicitly in code, but that one is easiest to reproduce.

Attachments (2)

default_button_problem.png download (2.9 KB) - added by mghie 7 years ago.
button-state.patch download (1.1 KB) - added by awi 11 months ago.
Patch to fix incorrect border style when default button is changed.

Download all attachments as: .zip

Change History (7)

Changed 7 years ago by mghie

comment:1 Changed 7 years ago by vadz

  • Owner set to vadz
  • Status changed from new to accepted

I can indeed see it, thanks for reporting, I'll look into this.

comment:2 Changed 14 months ago by vadz

  • Keywords raymond-chen-needed added
  • Summary changed from wxMSW: Default button problem to wxMSW can show 2 default buttons in a dialog

I have no idea how to fix this, I've debugged this code and we do reset BS_DEFPUSHBUTTON from the "OK" button when the cancel button gets focus, but somehow the "OK" button keeps its default appearance. I really don't know what else can we do...

Changed 11 months ago by awi

Patch to fix incorrect border style when default button is changed.

comment:3 Changed 11 months ago by awi

  • Keywords SetDefault SetDefaultStyle added; SetDefault() raymond-chen-needed removed
  • Patch set
  • Version changed from stable-latest to dev-latest

It seems that first button (in this case "OK") retains its default state border because second button ("Cancel" in this sample) is set as default by sending DM_SETDEFID message and this message can cause some side effects:
"Sending a DM_SETDEFID message to change the default button will not always remove the default state border from the first push button."
See http://msdn.microsoft.com/en-us/library/windows/desktop/ms645413%28v=vs.85%29.aspx

Bug can be fixed if current order of operations when focus is acquired by the new button:

  1. Remove default border style from old button.
  2. Set new default button (DM_SETDEFID message) and set its border style as "default".

would be reverted:

  1. Set new default button (DM_SETDEFID message) and set its border style as "default".
  2. Remove default border style from old button.

Same applies to the situation when focus is released from the button.

Patch attached.

comment:4 Changed 11 months ago by VZ

  • Resolution set to fixed
  • Status changed from accepted to closed

(In [75732]) Fix a bug which could result in two default buttons in wxMSW dialogs.

Exchange the order of setting/resetting the new/old button as the default one
when focus is lost/gained to avoid the possibility of having two simultaneously
default buttons at once.

Closes #9528.

comment:5 Changed 11 months ago by VZ

(In [75739]) Fix a bug which could result in two default buttons in wxMSW dialogs.

Exchange the order of setting/resetting the new/old button as the default one
when focus is lost/gained to avoid the possibility of having two simultaneously
default buttons at once.

Closes #9528.

Note: See TracTickets for help on using tickets.