]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/button.cpp
Added wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT to fix tree and list control selection rendering.
[wxWidgets.git] / src / msw / button.cpp
index 9d7fa154a70b631f185d4f09d2c0f0928b7f27ea..1a9b4d6ca25c7b7c63e31b3a88ac33e17fd44866 100644 (file)
     #include "wx/dcscreen.h"
     #include "wx/dcclient.h"
     #include "wx/toplevel.h"
+    #include "wx/msw/wrapcctl.h"
+    #include "wx/msw/private.h"
+    #include "wx/msw/missing.h"
 #endif
 
 #include "wx/imaglist.h"
 #include "wx/stockitem.h"
-#include "wx/msw/private.h"
 #include "wx/msw/private/button.h"
 #include "wx/msw/private/dc.h"
 #include "wx/private/window.h"
-#include "wx/msw/missing.h"
 
 using namespace wxMSWImpl;
 
@@ -224,13 +225,13 @@ public:
 
         m_data.himl = GetHimagelistOf(&m_iml);
 
-        // use default margins
+        // no margins by default
         m_data.margin.left =
-        m_data.margin.right = btn->GetCharWidth();
+        m_data.margin.right =
         m_data.margin.top =
-        m_data.margin.bottom = btn->GetCharHeight() / 2;
+        m_data.margin.bottom = 0;
 
-        // and default alignment
+        // use default alignment
         m_data.uAlign = BUTTON_IMAGELIST_ALIGN_LEFT;
 
         UpdateImageInfo();
@@ -353,67 +354,6 @@ private:
 // macros
 // ----------------------------------------------------------------------------
 
-#if wxUSE_EXTENDED_RTTI
-
-WX_DEFINE_FLAGS( wxButtonStyle )
-
-wxBEGIN_FLAGS( wxButtonStyle )
-    // new style border flags, we put them first to
-    // use them for streaming out
-    wxFLAGS_MEMBER(wxBORDER_SIMPLE)
-    wxFLAGS_MEMBER(wxBORDER_SUNKEN)
-    wxFLAGS_MEMBER(wxBORDER_DOUBLE)
-    wxFLAGS_MEMBER(wxBORDER_RAISED)
-    wxFLAGS_MEMBER(wxBORDER_STATIC)
-    wxFLAGS_MEMBER(wxBORDER_NONE)
-
-    // old style border flags
-    wxFLAGS_MEMBER(wxSIMPLE_BORDER)
-    wxFLAGS_MEMBER(wxSUNKEN_BORDER)
-    wxFLAGS_MEMBER(wxDOUBLE_BORDER)
-    wxFLAGS_MEMBER(wxRAISED_BORDER)
-    wxFLAGS_MEMBER(wxSTATIC_BORDER)
-    wxFLAGS_MEMBER(wxBORDER)
-
-    // standard window styles
-    wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
-    wxFLAGS_MEMBER(wxCLIP_CHILDREN)
-    wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
-    wxFLAGS_MEMBER(wxWANTS_CHARS)
-    wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
-    wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
-    wxFLAGS_MEMBER(wxVSCROLL)
-    wxFLAGS_MEMBER(wxHSCROLL)
-
-    wxFLAGS_MEMBER(wxBU_LEFT)
-    wxFLAGS_MEMBER(wxBU_RIGHT)
-    wxFLAGS_MEMBER(wxBU_TOP)
-    wxFLAGS_MEMBER(wxBU_BOTTOM)
-    wxFLAGS_MEMBER(wxBU_EXACTFIT)
-wxEND_FLAGS( wxButtonStyle )
-
-IMPLEMENT_DYNAMIC_CLASS_XTI(wxButton, wxControl,"wx/button.h")
-
-wxBEGIN_PROPERTIES_TABLE(wxButton)
-    wxEVENT_PROPERTY( Click , wxEVT_COMMAND_BUTTON_CLICKED , wxCommandEvent)
-
-    wxPROPERTY( Font , wxFont , SetFont , GetFont  , EMPTY_MACROVALUE, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
-    wxPROPERTY( Label, wxString , SetLabel, GetLabel, wxString(), 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
-
-    wxPROPERTY_FLAGS( WindowStyle , wxButtonStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
-
-wxEND_PROPERTIES_TABLE()
-
-wxBEGIN_HANDLERS_TABLE(wxButton)
-wxEND_HANDLERS_TABLE()
-
-wxCONSTRUCTOR_6( wxButton , wxWindow* , Parent , wxWindowID , Id , wxString , Label , wxPoint , Position , wxSize , Size , long , WindowStyle  )
-
-
-#else
-IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
-#endif
-
 // ============================================================================
 // implementation
 // ============================================================================
@@ -448,7 +388,6 @@ wxSize wxMSWButton::GetFittingSize(wxWindow *win,
     wxSize sizeBtn = sizeLabel;
 
     sizeBtn.x += 3*win->GetCharWidth();
-    sizeBtn.y = 11*EDIT_HEIGHT_FROM_CHAR_HEIGHT(sizeLabel.y)/10;
 
     // account for the shield UAC icon if we have it
     if ( flags & Size_AuthNeeded )
@@ -457,21 +396,28 @@ wxSize wxMSWButton::GetFittingSize(wxWindow *win,
     return sizeBtn;
 }
 
-wxSize wxMSWButton::ComputeBestSize(wxControl *btn, int flags)
+wxSize wxMSWButton::ComputeBestFittingSize(wxControl *btn, int flags)
 {
     wxClientDC dc(btn);
 
     wxSize sizeBtn;
     dc.GetMultiLineTextExtent(btn->GetLabelText(), &sizeBtn.x, &sizeBtn.y);
 
-    sizeBtn = GetFittingSize(btn, sizeBtn, flags);
+    return GetFittingSize(btn, sizeBtn, flags);
+}
+
+wxSize wxMSWButton::IncreaseToStdSizeAndCache(wxControl *btn, const wxSize& size)
+{
+    wxSize sizeBtn(size);
 
     // 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
     // creating the button
     if ( !btn->HasFlag(wxBU_EXACTFIT) )
     {
-        // The size of a standard button in the dialog units is 50x14, use it.
+        // The 50x14 button size is documented in the "Recommended sizing and
+        // spacing" section of MSDN layout article.
+        //
         // Note that we intentionally don't use GetDefaultSize() here, because
         // it's inexact -- dialog units depend on this dialog's font.
         wxSize sizeDef = btn->ConvertDialogToPixels(wxSize(50, 14));
@@ -591,8 +537,7 @@ void wxButton::SetLabel(const wxString& label)
 
 void wxButton::AdjustForBitmapSize(wxSize &size) const
 {
-    if ( !m_imageData )
-        return;
+    wxCHECK_RET( m_imageData, wxT("shouldn't be called if no image") );
 
     // account for the bitmap size
     const wxSize sizeBmp = m_imageData->GetBitmap(State_Normal).GetSize();
@@ -656,28 +601,24 @@ void wxButton::AdjustForBitmapSize(wxSize &size) const
 
 wxSize wxButton::DoGetBestSize() const
 {
+    wxButton * const self = const_cast<wxButton *>(this);
+
     wxSize size;
 
-    // account for the text part if we have it or if we don't have any image at
-    // all (buttons initially created with empty label should still have a non
-    // zero size)
-    if ( ShowsLabel() || !m_imageData )
+    // Account for the text part if we have it.
+    if ( ShowsLabel() )
     {
         int flags = 0;
         if ( GetAuthNeeded() )
             flags |= wxMSWButton::Size_AuthNeeded;
 
-        size = wxMSWButton::ComputeBestSize(const_cast<wxButton *>(this), flags);
+        size = wxMSWButton::ComputeBestFittingSize(self, flags);
     }
 
     if ( m_imageData )
-    {
         AdjustForBitmapSize(size);
 
-        CacheBestSize(size);
-    }
-
-    return size;
+    return wxMSWButton::IncreaseToStdSizeAndCache(self, size);
 }
 
 /* static */