Use wxRendererNative::DrawTitleBarBitmap() for info bar close button.

If supported by the current platform, draw natively-looking close button using
multiple bitmaps for normal, pressed and current stats. Otherwise fall back on
the old wxArtProvider-based bitmap.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62296 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-10-05 22:57:09 +00:00
parent b50d93d1da
commit cc2608047b

View File

@@ -36,6 +36,7 @@
#include "wx/infobar.h"
#include "wx/artprov.h"
#include "wx/renderer.h"
#include "wx/scopeguard.h"
#include "wx/sizer.h"
@@ -43,6 +44,34 @@ 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
// ============================================================================
@@ -69,7 +98,8 @@ bool wxInfoBarGeneric::Create(wxWindow *parent, wxWindowID winid)
return false;
// use special, easy to notice, colours
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_INFOBK));
const wxColour colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_INFOBK);
SetBackgroundColour(colBg);
SetOwnForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_INFOTEXT));
// create the controls: icon, text and the button to dismiss the
@@ -80,16 +110,31 @@ 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_FRAME_ICON);
wxBitmap bmp = GetCloseButtonBitmap(this, sizeBmp, colBg);
#else // !wxHAS_DRAW_TITLE_BAR_BITMAP
wxBitmap bmp = wxArtProvider::GetBitmap(wxART_CLOSE, wxART_MENU);
#endif // wxHAS_DRAW_TITLE_BAR_BITMAP
m_button = new wxBitmapButton
(
this,
wxID_ANY,
wxArtProvider::GetBitmap(wxART_CLOSE, wxART_MENU),
bmp,
wxDefaultPosition,
wxDefaultSize,
wxBORDER_NONE
);
m_button->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_INFOBK));
#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->SetToolTip(_("Hide this notification message."));
// center the text inside the sizer with an icon to the left of it and a