X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/036da5e37479c4e2bc3493d3a7a37ac629757515..904ccf52370e021b55b8a4c1afc5f62bc904da20:/src/msw/button.cpp diff --git a/src/msw/button.cpp b/src/msw/button.cpp index c00c3d11d0..172cf7de5b 100644 --- a/src/msw/button.cpp +++ b/src/msw/button.cpp @@ -147,11 +147,16 @@ wxSize wxButton::DoGetBestSize() const // the button height is proportional to the height of the font used int hBtn = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hChar); - wxSize sz = GetDefaultSize(); - if (wBtn > sz.x) sz.x = wBtn; - if (hBtn > sz.y) sz.y = hBtn; + if (!HasFlag(wxBU_EXACTFIT)) + { + wxSize sz = GetDefaultSize(); + if (wBtn > sz.x) sz.x = wBtn; + if (hBtn > sz.y) sz.y = hBtn; + return sz; + } + else + return wxSize(wBtn, hBtn); - return sz; } /* static */ @@ -183,6 +188,34 @@ wxSize wxButtonBase::GetDefaultSize() // default button handling // ---------------------------------------------------------------------------- +/* + "Everything you ever wanted to know about the default buttons" or "Why do we + have to do all this?" + + In MSW the default button should be activated when the user presses Enter + and the current control doesn't process Enter itself somehow. This is + handled by ::DefWindowProc() (or maybe ::DefDialogProc()) using DM_SETDEFID + Another aspect of "defaultness" is that the default button has different + appearance: this is due to BS_DEFPUSHBUTTON style which is completely + separate from DM_SETDEFID stuff (!). + + Final complication is that when a button is active, it should be the default + one, i.e. pressing Enter on a button always activates it and not another + one. + + We handle this by maintaining a permanent and a temporary default items in + wxControlContainer (both may be NULL). When a button becomes the current + control (i.e. gets focus) it sets itself as the temporary default which + ensures that it has the right appearance and that Enter will be redirected + to it. When the button loses focus, it unsets the temporary default and so + the default item will be the permanent default -- that is the default button + if any had been set or none otherwise, which is just what we want. + + Remark that we probably don't need to send DM_SETDEFID as we don't use + ::IsDialogMessage() (which relies on it) any longer but OTOH it probably + doesn't hurt neither. + */ + // set this button as the (permanently) default one in its panel void wxButton::SetDefault() {