]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/button.cpp
unicode character events
[wxWidgets.git] / src / msw / button.cpp
index 422386516934a68d9c7a98db2ca9413d1d604cd5..cdad2d28dafdb742e21438f0d806505834d1e7d0 100644 (file)
@@ -40,6 +40,8 @@
     #include "wx/dcscreen.h"
 #endif
 
+#include "wx/stockitem.h"
+#include "wx/tokenzr.h"
 #include "wx/msw/private.h"
 
 // ----------------------------------------------------------------------------
@@ -121,13 +123,28 @@ IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
 
 bool wxButton::Create(wxWindow *parent,
                       wxWindowID id,
-                      const wxString& label,
+                      const wxString& lbl,
                       const wxPoint& pos,
                       const wxSize& size,
                       long style,
                       const wxValidator& validator,
                       const wxString& name)
 {
+    wxString label(lbl);
+    if (label.empty() && wxIsStockID(id))
+    {
+        // On Windows, some buttons aren't supposed to have
+        // mnemonics, so strip them out.
+        
+        label = wxGetStockLabel(id 
+#if defined(__WXMSW__) || defined(__WXWINCE__)
+                                        , ( id != wxID_OK &&
+                                            id != wxID_CANCEL &&
+                                            id != wxID_CLOSE )
+#endif
+                                );
+     }
+    
     if ( !CreateControl(parent, id, pos, size, style, validator, name) )
         return false;
 
@@ -199,17 +216,16 @@ WXDWORD wxButton::MSWGetStyle(long style, WXDWORD *exstyle) const
 
 wxSize wxButton::DoGetBestSize() const
 {
-    int wBtn;
-    GetTextExtent(wxGetWindowText(GetHWND()), &wBtn, NULL);
+    wxClientDC dc(wx_const_cast(wxButton *, this));
+    dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
 
-    int wChar, hChar;
-    wxGetCharSize(GetHWND(), &wChar, &hChar, GetFont());
+    wxCoord wBtn,
+            hBtn;
+    dc.GetMultiLineTextExtent(GetLabel(), &wBtn, &hBtn);
 
     // add a margin -- the button is wider than just its label
-    wBtn += 3*wChar;
-
-    // the button height is proportional to the height of the font used
-    int hBtn = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hChar);
+    wBtn += 3*GetCharWidth();
+    hBtn = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hBtn);
 
     // all buttons have at least the standard size unless the user explicitly
     // wants them to be of smaller size and used wxBU_EXACTFIT style when