X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/57c0af52bffc66b12b7e7b49b3a2dfdcf2d2e352..2356708db31b737c6eae53c2316b642aa5a2e68d:/src/msw/button.cpp diff --git a/src/msw/button.cpp b/src/msw/button.cpp index 1d8bbaf990..307fad45d9 100644 --- a/src/msw/button.cpp +++ b/src/msw/button.cpp @@ -30,6 +30,8 @@ #ifndef WX_PRECOMP #include "wx/button.h" #include "wx/brush.h" + #include "wx/panel.h" + #include "wx/bmpbuttn.h" #endif #include "wx/msw/private.h" @@ -63,7 +65,7 @@ bool wxButton::Create(wxWindow *parent, const wxValidator& validator, const wxString& name) { - if ( !CreateBase(parent, id, pos, size, style, name) ) + if ( !CreateBase(parent, id, pos, size, style, validator, name) ) return FALSE; SetValidator(validator); @@ -113,68 +115,72 @@ wxButton::~wxButton() // size management including autosizing // ---------------------------------------------------------------------------- -void wxButton::DoSetSize(int x, int y, int width, int height, int sizeFlags) +wxSize wxButton::DoGetBestSize() { - int currentX, currentY; - GetPosition(¤tX, ¤tY); - int x1 = x; - int y1 = y; - if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - x1 = currentX; - if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - y1 = currentY; - - AdjustForParentClientOrigin(x1, y1, sizeFlags); - - int actualWidth = width; - int actualHeight = height; - int ww, hh; - GetSize(&ww, &hh); - - int current_width; - int cyf; - wxString buf = wxGetWindowText(GetHWND()); - GetTextExtent(buf, ¤t_width, &cyf, NULL, NULL, &GetFont()); - - // If we're prepared to use the existing width, then... - if (width == -1 && ((sizeFlags & wxSIZE_AUTO_WIDTH) != wxSIZE_AUTO_WIDTH)) - { - actualWidth = ww; - } - else if (width == -1) - { - int cx; - int cy; - wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont()); - actualWidth = (int)(current_width + 3*cx) ; - } + wxString label = wxGetWindowText(GetHWND()); + int wBtn; + GetTextExtent(label, &wBtn, NULL); - // If we're prepared to use the existing height, then... - if (height == -1 && ((sizeFlags & wxSIZE_AUTO_HEIGHT) != wxSIZE_AUTO_HEIGHT)) - { - actualHeight = hh; - } - else if (height == -1) - { - actualHeight = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(cyf); - } + int wChar, hChar; + wxGetCharSize(GetHWND(), &wChar, &hChar, &GetFont()); + + // add a margin - the button is wider than just its label + wBtn += 3*wChar; - MoveWindow(GetHwnd(), x1, y1, actualWidth, actualHeight, TRUE); + // the button height is proportional to the height of the font used + int hBtn = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hChar); + + return wxSize(wBtn, hBtn); } +/* static */ +wxSize wxButton::GetDefaultSize() +{ + // the base unit is the height of the system GUI font + int wChar, hChar; + wxGetCharSize(0, &wChar, &hChar, NULL); + + // the button height is proportional to the height of the font used + int hBtn = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hChar); + + // and the width/height ration is 75/23 + return wxSize((75 * hBtn) / 23, hBtn); +} + +// ---------------------------------------------------------------------------- +// set this button as the default one in its panel +// ---------------------------------------------------------------------------- + void wxButton::SetDefault() { wxWindow *parent = GetParent(); + wxButton *btnOldDefault = NULL; wxPanel *panel = wxDynamicCast(parent, wxPanel); if ( panel ) + { + btnOldDefault = panel->GetDefaultItem(); panel->SetDefaultItem(this); + } if ( parent ) { SendMessage(GetWinHwnd(parent), DM_SETDEFID, m_windowId, 0L); } - SendMessage(GetHwnd(), BM_SETSTYLE, BS_DEFPUSHBUTTON, 1L); + // this doesn't work with bitmap buttons because it also removes the + // "ownerdrawn" style... + if ( btnOldDefault && !wxDynamicCast(btnOldDefault, wxBitmapButton) ) + { + // remove the BS_DEFPUSHBUTTON style from the other button + long style = GetWindowLong(GetHwndOf(btnOldDefault), GWL_STYLE); + style &= ~BS_DEFPUSHBUTTON; + SendMessage(GetHwndOf(btnOldDefault), BM_SETSTYLE, style, 1L); + } + + // set this button as the default + long style = GetWindowLong(GetHwnd(), GWL_STYLE); + style |= BS_DEFPUSHBUTTON; + SendMessage(GetHwnd(), BM_SETSTYLE, style, 1L); } // ----------------------------------------------------------------------------