]> git.saurik.com Git - wxWidgets.git/commitdiff
added wxBU_NOTEXT style to allow creating bitmap buttons with stock id not showing...
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 17 Jun 2009 22:13:46 +0000 (22:13 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 17 Jun 2009 22:13:46 +0000 (22:13 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61104 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/button.h
include/wx/gtk/bmpbuttn.h
interface/wx/button.h
src/gtk/button.cpp
src/msw/bmpbuttn.cpp
src/msw/button.cpp

index 53b164bbba1f1c511aa7f1670df190d02cf3f7d6..dfcf6610daf1f9a5bd259dee506498dad5703d97 100644 (file)
 // small as possible
 #define wxBU_EXACTFIT        0x0001
 
+// this flag can be used to disable using the text label in the button: it is
+// mostly useful when creating buttons showing bitmap and having stock id as
+// without it both the standard label corresponding to the stock id and the
+// bitmap would be shown
+#define wxBU_NOTEXT          0x0002
+
+
 #include "wx/bitmap.h"
 #include "wx/control.h"
 
@@ -146,6 +153,19 @@ public:
         State_Max
     };
 
+    // return true if this button shouldn't show the text label, either because
+    // it doesn't have it or because it was explicitly disabled with wxBU_NOTEXT
+    bool DontShowLabel() const
+    {
+        return HasFlag(wxBU_NOTEXT) || GetLabel().empty();
+    }
+
+    // return true if we do show the label
+    bool ShowsLabel() const
+    {
+        return !DontShowLabel();
+    }
+
 protected:
     // choose the default border for this window
     virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
index 47ee62fc2b81cf3308fdb253eda3a856b21bcd9a..a0a17b3ac091472da5616925e1c78b184a7ee8b7 100644 (file)
@@ -41,7 +41,8 @@ public:
                 const wxString& name = wxButtonNameStr)
     {
         if ( !wxBitmapButtonBase::Create(parent, id, "",
-                                         pos, size, style,
+                                         pos, size,
+                                         style | wxBU_NOTEXT,
                                          validator, name) )
             return false;
 
index 0ad5d3482fff9bdb42e023c17b68d6fa2479b00a..a36c8cacefddb9ea628d3ca54cdeec95a951b896 100644 (file)
 
     @beginStyleTable
     @style{wxBU_LEFT}
-           Left-justifies the label. Windows and GTK+ only.
+        Left-justifies the label. Windows and GTK+ only.
     @style{wxBU_TOP}
-           Aligns the label to the top of the button. Windows and GTK+ only.
+        Aligns the label to the top of the button. Windows and GTK+ only.
     @style{wxBU_RIGHT}
-           Right-justifies the bitmap label. Windows and GTK+ only.
+        Right-justifies the bitmap label. Windows and GTK+ only.
     @style{wxBU_BOTTOM}
-           Aligns the label to the bottom of the button. Windows and GTK+ only.
+        Aligns the label to the bottom of the button. Windows and GTK+ only.
     @style{wxBU_EXACTFIT}
-           Creates the button as small as possible instead of making it of the
-           standard size (which is the default behaviour ).
+        Creates the button as small as possible instead of making it of the
+        standard size (which is the default behaviour ).
+    @style{wxBU_NOTEXT}
+        Disables the display of the text label in the button even if it has one
+        or its id is one of the standard stock ids with an associated label:
+        without using this style a button which is only supposed to show a
+        bitmap but uses a standard id would display a label too.
     @style{wxBORDER_NONE}
-           Creates a flat button. Windows and GTK+ only.
+        Creates a flat button. Windows and GTK+ only.
     @endStyleTable
 
     By default, i.e. if none of the alignment styles are specified, the label
index 198a46a72dc6d8fd90f5b5b3241ea03b87758c44..0a6a838f90a42fb0f1f8728df4724ce2453ead60 100644 (file)
@@ -126,7 +126,8 @@ bool wxButton::Create(wxWindow *parent,
     // create either a standard button with text label (which may still contain
     // an image under GTK+ 2.6+) or a bitmap-only button if we don't have any
     // label
-    const bool useLabel = !label.empty() || wxIsStockID(id);
+    const bool
+        useLabel = !(style & wxBU_NOTEXT) && (!label.empty() || wxIsStockID(id));
     if ( useLabel )
     {
         m_widget = gtk_button_new_with_mnemonic("");
@@ -237,6 +238,10 @@ void wxButton::SetLabel( const wxString &lbl )
 
     wxControl::SetLabel(label);
 
+    // don't use label if it was explicitly disabled
+    if ( HasFlag(wxBU_NOTEXT) )
+        return;
+
     if (wxIsStockID(m_windowId) && wxIsStockLabel(m_windowId, label))
     {
         const char *stock = wxGetStockGtkID(m_windowId);
@@ -410,7 +415,7 @@ void wxButton::GTKDoShowBitmap(const wxBitmap& bitmap)
     wxASSERT_MSG( bitmap.IsOk(), "invalid bitmap" );
 
     GtkWidget *image;
-    if ( GetLabel().empty() )
+    if ( DontShowLabel() )
     {
         image = GTK_BIN(m_widget)->child;
     }
@@ -450,7 +455,7 @@ void wxButton::DoSetBitmap(const wxBitmap& bitmap, State which)
     switch ( which )
     {
         case State_Normal:
-            if ( GetLabel().empty() )
+            if ( DontShowLabel() )
             {
                 // we only have the bitmap in this button, never remove it but
                 // do invalidate the best size when the bitmap (and presumably
index 1438b7cffa5d2645f293968dd4501acad6cac03b..2e2072d0a2dff4632a6a3b4966d260127360a20c 100644 (file)
@@ -131,7 +131,9 @@ bool wxBitmapButton::Create(wxWindow *parent,
                             const wxString& name)
 {
     if ( !wxBitmapButtonBase::Create(parent, id, "",
-                                     pos, size, style, validator, name) )
+                                     pos, size,
+                                     style | wxBU_NOTEXT,
+                                     validator, name) )
         return false;
 
     SetBitmapLabel(bitmap);
index b789a6ccc2cae4e4aeae93fb15234e5b0ffee5e5..70edb407a22d70eec9470ce214ee4c063ff18ffa 100644 (file)
@@ -145,7 +145,7 @@ public:
 
         // we use margins when we have both bitmap and text, but when we have
         // only the bitmap it should take up the entire button area
-        if ( !btn->GetLabel().empty() )
+        if ( btn->ShowsLabel() )
         {
             m_margin.x = btn->GetCharWidth();
             m_margin.y = btn->GetCharHeight() / 2;
@@ -575,7 +575,7 @@ wxSize wxButton::DoGetBestSize() const
     wxSize size;
 
     // account for the text part
-    if ( !GetLabel().empty() )
+    if ( ShowsLabel() )
     {
         size = wxMSWButton::ComputeBestSize(const_cast<wxButton *>(this));
     }
@@ -946,7 +946,7 @@ void wxButton::DoSetBitmap(const wxBitmap& bitmap, State which)
         // (even if we use BUTTON_IMAGELIST_ALIGN_CENTER alignment and
         // BS_BITMAP style), at least under Windows 2003 so use owner drawn
         // strategy for bitmap-only buttons
-        if ( !GetLabel().empty() && wxUxThemeEngine::GetIfActive() )
+        if ( ShowsLabel() && wxUxThemeEngine::GetIfActive() )
         {
             m_imageData = new wxXPButtonImageData(this, bitmap);
         }
@@ -1262,8 +1262,6 @@ bool wxButton::MSWOnDraw(WXDRAWITEMSTRUCT *wxdis)
     RECT rectBtn;
     CopyRect(&rectBtn, &lpDIS->rcItem);
 
-    const wxString label = GetLabel();
-
     // draw the button background
 #if wxUSE_UXTHEME
     if ( wxUxThemeEngine::GetIfActive() )
@@ -1364,7 +1362,7 @@ bool wxButton::MSWOnDraw(WXDRAWITEMSTRUCT *wxdis)
 
 
     // finally draw the label
-    if ( !label.empty() )
+    if ( ShowsLabel() )
     {
         COLORREF colFg = state & ODS_DISABLED
                             ? ::GetSysColor(COLOR_GRAYTEXT)
@@ -1373,7 +1371,7 @@ bool wxButton::MSWOnDraw(WXDRAWITEMSTRUCT *wxdis)
         // notice that DT_HIDEPREFIX doesn't work on old (pre-Windows 2000)
         // systems but by happy coincidence ODS_NOACCEL is not used under them
         // neither so DT_HIDEPREFIX should never be used there
-        DrawButtonText(hdc, &rectBtn, label, colFg,
+        DrawButtonText(hdc, &rectBtn, GetLabel(), colFg,
                        state & ODS_NOACCEL ? DT_HIDEPREFIX : 0);
     }