]> git.saurik.com Git - wxWidgets.git/commitdiff
Extract "Close" button creation from wxInfoBarGeneric into new function.
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 13 Sep 2012 17:14:14 +0000 (17:14 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 13 Sep 2012 17:14:14 +0000 (17:14 +0000)
Such buttons may be needed in other places and it's not obvious to create
them, so add a new public wxBitmapButton::NewCloseButton() method to allow
creating them easily.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72474 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/bmpbuttn.h
interface/wx/bmpbuttn.h
src/common/bmpbtncmn.cpp
src/generic/infobar.cpp

index 49939c7e98889c5fd562bcbf4e9c0acb06c969cc..ee1ff7bf2e476baff8f1b7ed97b8751651bffcc8 100644 (file)
@@ -547,6 +547,7 @@ All (GUI):
 - Add expand/collapse button to wxRibbonBar (rakeshthp).
 - Fix item data access in wxDataViewListCtrl (Kry).
 - Fix problem with floating maximized AUI panes (Laurent Poujoulat).
+- Add wxBitmapButton::NewCloseButton().
 
 wxGTK:
 
index 5da4cb724bec93e403b25efe24875b73929b359c..fb1ed6f603cc401d703d9673358f7f86a883d523 100644 (file)
@@ -25,6 +25,8 @@
     #define wxHAS_BUTTON_BITMAP
 #endif
 
+class WXDLLIMPEXP_FWD_CORE wxBitmapButton;
+
 // ----------------------------------------------------------------------------
 // wxBitmapButton: a button which shows bitmaps instead of the usual string.
 // It has different bitmaps for different states (focused/disabled/pressed)
@@ -64,6 +66,12 @@ public:
                                 validator, name);
     }
 
+    // Special creation function for a standard "Close" bitmap. It allows to
+    // simply create a close button with the image appropriate for the common
+    // platform.
+    static wxBitmapButton* NewCloseButton(wxWindow* parent, wxWindowID winid);
+
+
     // set/get the margins around the button
     virtual void SetMargins(int x, int y)
     {
index 6af9eed0a956b4628f4f389dce5a500c02515854..20bd4ab54396be3bf2d13e96a32369a90a92022c 100644 (file)
@@ -99,5 +99,21 @@ public:
                 long style = wxBU_AUTODRAW,
                 const wxValidator& validator = wxDefaultValidator,
                 const wxString& name = wxButtonNameStr);
+
+    /**
+        Helper function creating a standard-looking "Close" button.
+
+        To get the best results, platform-specific code may need to be used to
+        create a small, title bar-like "Close" button. This function is
+        provided to avoid the need to test for the current platform and creates
+        the button with as native look as possible.
+
+        @param parent The button parent window, must be non-@NULL.
+        @param winid The identifier for the new button.
+        @return The new button.
+
+        @since 2.9.5
+     */
+    static wxBitmapButton* NewCloseButton(wxWindow* parent, wxWindowID winid);
 };
 
index 2a615da5ffe873f70ab74b3893f5d44a7476c521..ae06c723ef6270b88ee969547e0a80ab7ff258b2 100644 (file)
@@ -26,6 +26,9 @@
     #include "wx/image.h"
 #endif
 
+#include "wx/artprov.h"
+#include "wx/renderer.h"
+
 // ----------------------------------------------------------------------------
 // XTI
 // ----------------------------------------------------------------------------
@@ -90,4 +93,67 @@ bitmap "focus" ,
 bitmap "disabled" ,
 */
 
+namespace
+{
+
+#ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
+
+wxBitmap
+GetCloseButtonBitmap(wxWindow *win,
+                     const wxSize& size,
+                     const wxColour& colBg,
+                     int flags = 0)
+{
+    wxBitmap bmp(size);
+    wxMemoryDC dc(bmp);
+    dc.SetBackground(colBg);
+    dc.Clear();
+    wxRendererNative::Get().
+        DrawTitleBarBitmap(win, dc, size, wxTITLEBAR_BUTTON_CLOSE, flags);
+    return bmp;
+}
+
+#endif // wxHAS_DRAW_TITLE_BAR_BITMAP
+
+} // anonymous namespace
+
+/* static */
+wxBitmapButton*
+wxBitmapButtonBase::NewCloseButton(wxWindow* parent, wxWindowID winid)
+{
+    wxCHECK_MSG( parent, NULL, wxS("Must have a valid parent") );
+
+    const wxColour colBg = parent->GetBackgroundColour();
+
+#ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
+    const wxSize sizeBmp = wxArtProvider::GetSizeHint(wxART_BUTTON);
+    wxBitmap bmp = GetCloseButtonBitmap(parent, sizeBmp, colBg);
+#else // !wxHAS_DRAW_TITLE_BAR_BITMAP
+    wxBitmap bmp = wxArtProvider::GetBitmap(wxART_CLOSE, wxART_BUTTON);
+#endif // wxHAS_DRAW_TITLE_BAR_BITMAP
+
+    wxBitmapButton* const button = new wxBitmapButton
+                                       (
+                                        parent,
+                                        winid,
+                                        bmp,
+                                        wxDefaultPosition,
+                                        wxDefaultSize,
+                                        wxBORDER_NONE
+                                       );
+
+#ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
+    button->SetBitmapPressed(
+        GetCloseButtonBitmap(parent, sizeBmp, colBg, wxCONTROL_PRESSED));
+
+    button->SetBitmapCurrent(
+        GetCloseButtonBitmap(parent, sizeBmp, colBg, wxCONTROL_CURRENT));
+#endif // wxHAS_DRAW_TITLE_BAR_BITMAP
+
+    // The button should blend with its parent background.
+    button->SetBackgroundColour(colBg);
+
+    return button;
+}
+
 #endif // wxUSE_BMPBUTTON
index 76001a4a17e9df3035c16c1a588e55ff348f2f00..26a2368bdc273de39766bd6fbf1c64d035b0b1ee 100644 (file)
 #endif // WX_PRECOMP
 
 #include "wx/artprov.h"
-#include "wx/renderer.h"
 #include "wx/scopeguard.h"
 
 BEGIN_EVENT_TABLE(wxInfoBarGeneric, wxInfoBarBase)
     EVT_BUTTON(wxID_ANY, wxInfoBarGeneric::OnButton)
 END_EVENT_TABLE()
 
-// ----------------------------------------------------------------------------
-// local helpers
-// ----------------------------------------------------------------------------
-
-namespace
-{
-
-#ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
-
-wxBitmap
-GetCloseButtonBitmap(wxWindow *win,
-                     const wxSize& size,
-                     const wxColour& colBg,
-                     int flags = 0)
-{
-    wxBitmap bmp(size);
-    wxMemoryDC dc(bmp);
-    dc.SetBackground(colBg);
-    dc.Clear();
-    wxRendererNative::Get().
-        DrawTitleBarBitmap(win, dc, size, wxTITLEBAR_BUTTON_CLOSE, flags);
-    return bmp;
-}
-
-#endif // wxHAS_DRAW_TITLE_BAR_BITMAP
-
-} // anonymous namespace
-
 // ============================================================================
 // implementation
 // ============================================================================
@@ -111,31 +82,7 @@ bool wxInfoBarGeneric::Create(wxWindow *parent, wxWindowID winid)
 
     m_text = new wxStaticText(this, wxID_ANY, "");
 
-#ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
-    const wxSize sizeBmp = wxArtProvider::GetSizeHint(wxART_BUTTON);
-    wxBitmap bmp = GetCloseButtonBitmap(this, sizeBmp, colBg);
-#else // !wxHAS_DRAW_TITLE_BAR_BITMAP
-    wxBitmap bmp = wxArtProvider::GetBitmap(wxART_CLOSE, wxART_BUTTON);
-#endif // wxHAS_DRAW_TITLE_BAR_BITMAP
-    m_button = new wxBitmapButton
-                   (
-                    this,
-                    wxID_ANY,
-                    bmp,
-                    wxDefaultPosition,
-                    wxDefaultSize,
-                    wxBORDER_NONE
-                   );
-
-#ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
-    m_button->SetBitmapPressed(
-        GetCloseButtonBitmap(this, sizeBmp, colBg, wxCONTROL_PRESSED));
-
-    m_button->SetBitmapCurrent(
-        GetCloseButtonBitmap(this, sizeBmp, colBg, wxCONTROL_CURRENT));
-#endif // wxHAS_DRAW_TITLE_BAR_BITMAP
-
-    m_button->SetBackgroundColour(colBg);
+    m_button = wxBitmapButton::NewCloseButton(parent, wxID_ANY);
     m_button->SetToolTip(_("Hide this notification message."));
 
     // center the text inside the sizer with an icon to the left of it and a