]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/button.cpp
*** empty log message ***
[wxWidgets.git] / src / msw / button.cpp
index 1a34a34d0e659c360d2be3fddb9c2bbfdfc31abf..93684233508744d7073e1095e6f25d9e775cfa92 100644 (file)
@@ -30,6 +30,7 @@
 #ifndef WX_PRECOMP
     #include "wx/button.h"
     #include "wx/brush.h"
+    #include "wx/panel.h"
 #endif
 
 #include "wx/msw/private.h"
@@ -63,7 +64,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);
@@ -131,6 +132,20 @@ wxSize wxButton::DoGetBestSize()
     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
 // ----------------------------------------------------------------------------
@@ -138,16 +153,33 @@ wxSize wxButton::DoGetBestSize()
 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);
 }
 
 // ----------------------------------------------------------------------------