From 0601bdbd1957419ed81d881de947e269bd01ab1c Mon Sep 17 00:00:00 2001 From: Charlie Fenton Date: Thu, 21 Feb 2013 23:43:44 -0800 Subject: [PATCH] Attempt to fix appearance of Simple View buttons on Windows --- clientgui/sg_PanelBase.cpp | 47 ++++++++++++++++++--------- clientgui/sg_PanelBase.h | 2 ++ clientgui/sg_ProjectCommandPopup.cpp | 6 ++-- clientgui/sg_ProjectCommandPopup.h | 4 ++- clientgui/sg_ProjectPanel.cpp | 2 +- clientgui/sg_ProjectPanel.h | 2 +- clientgui/sg_ProjectWebSitesPopup.cpp | 6 ++-- clientgui/sg_ProjectWebSitesPopup.h | 3 +- clientgui/sg_TaskCommandPopup.cpp | 6 ++-- clientgui/sg_TaskCommandPopup.h | 4 ++- 10 files changed, 52 insertions(+), 30 deletions(-) diff --git a/clientgui/sg_PanelBase.cpp b/clientgui/sg_PanelBase.cpp index be2ef20a72..ce8c17c569 100644 --- a/clientgui/sg_PanelBase.cpp +++ b/clientgui/sg_PanelBase.cpp @@ -26,7 +26,11 @@ IMPLEMENT_DYNAMIC_CLASS(CSimplePanelBase, wxPanel) BEGIN_EVENT_TABLE(CSimplePanelBase, wxPanel) - EVT_PAINT(CSimplePanelBase::OnPaint) +#ifdef __WXMSW__ + EVT_ERASE_BACKGROUND(CSimplePanelBase::OnEraseBackground) +#else + EVT_PAINT(CSimplePanelBase::OnPaint) +#endif END_EVENT_TABLE() @@ -139,40 +143,51 @@ void CSimplePanelBase::MakeBGBitMap() { // events here, so use Paint events void CSimplePanelBase::OnPaint(wxPaintEvent& /*event*/) { wxPaintDC dc(this); + EraseBackground(&dc); +} + + +void CSimplePanelBase::OnEraseBackground(wxEraseEvent& event) { + wxDC *dc = event.GetDC(); + EraseBackground(dc); +} + + +void CSimplePanelBase::EraseBackground(wxDC *dc) { if (!m_GotBGBitMap) { MakeBGBitMap(); } - dc.DrawBitmap(m_TaskPanelBGBitMap, 0, 0); - wxPen oldPen= dc.GetPen(); - wxBrush oldBrush = dc.GetBrush(); - int oldMode = dc.GetBackgroundMode(); + dc->DrawBitmap(m_TaskPanelBGBitMap, 0, 0); + wxPen oldPen= dc->GetPen(); + wxBrush oldBrush = dc->GetBrush(); + int oldMode = dc->GetBackgroundMode(); wxCoord w, h; wxPen bgPen(*wxLIGHT_GREY, 3); wxBrush bgBrush(*wxLIGHT_GREY, wxTRANSPARENT); - dc.SetBackgroundMode(wxSOLID); - dc.SetPen(bgPen); - dc.SetBrush(bgBrush); - dc.GetSize(&w, &h); - dc.DrawRoundedRectangle(0, 0, w, h, RECTANGLERADIUS); + dc->SetBackgroundMode(wxSOLID); + dc->SetPen(bgPen); + dc->SetBrush(bgBrush); + dc->GetSize(&w, &h); + dc->DrawRoundedRectangle(0, 0, w, h, RECTANGLERADIUS); #ifdef __WXMAC__ // Mac progress bar can be hard to see on a colored // background, so put it on a white background wxRect* progressRect = GetProgressRect(); if (progressRect) { - dc.SetPen(*wxBLACK_PEN); - dc.SetBrush(*wxWHITE_BRUSH); - dc.DrawRoundedRectangle(progressRect->x, progressRect->y, progressRect->width, progressRect->height, 2); + dc->SetPen(*wxBLACK_PEN); + dc->SetBrush(*wxWHITE_BRUSH); + dc->DrawRoundedRectangle(progressRect->x, progressRect->y, progressRect->width, progressRect->height, 2); } #endif // Restore Mode, Pen and Brush - dc.SetBackgroundMode(oldMode); - dc.SetPen(oldPen); - dc.SetBrush(oldBrush); + dc->SetBackgroundMode(oldMode); + dc->SetPen(oldPen); + dc->SetBrush(oldBrush); } diff --git a/clientgui/sg_PanelBase.h b/clientgui/sg_PanelBase.h index dd53c98a23..4788195985 100644 --- a/clientgui/sg_PanelBase.h +++ b/clientgui/sg_PanelBase.h @@ -77,6 +77,8 @@ class CSimplePanelBase : public wxPanel protected: void MakeBGBitMap(); void OnPaint(wxPaintEvent& event); + void OnEraseBackground(wxEraseEvent& event); + void EraseBackground(wxDC *dc); wxBitmap m_TaskPanelBGBitMap; bool m_GotBGBitMap; diff --git a/clientgui/sg_ProjectCommandPopup.cpp b/clientgui/sg_ProjectCommandPopup.cpp index 3bc986515f..e4ef2c0066 100644 --- a/clientgui/sg_ProjectCommandPopup.cpp +++ b/clientgui/sg_ProjectCommandPopup.cpp @@ -24,9 +24,9 @@ #include "sg_ProjectPanel.h" #include "sg_ProjectCommandPopup.h" -IMPLEMENT_DYNAMIC_CLASS(CSimpleProjectCommandPopupButton, wxButton) +IMPLEMENT_DYNAMIC_CLASS(CSimpleProjectCommandPopupButton, CTransparentButton) -BEGIN_EVENT_TABLE(CSimpleProjectCommandPopupButton, wxButton) +BEGIN_EVENT_TABLE(CSimpleProjectCommandPopupButton, CTransparentButton) EVT_LEFT_DOWN(CSimpleProjectCommandPopupButton::OnProjectCommandsButton) EVT_MENU(ID_TASK_PROJECT_UPDATE, CSimpleProjectCommandPopupButton::OnProjectUpdate) EVT_MENU(ID_TASK_PROJECT_SUSPEND, CSimpleProjectCommandPopupButton::OnProjectSuspendResume) @@ -42,7 +42,7 @@ CSimpleProjectCommandPopupButton::CSimpleProjectCommandPopupButton() { CSimpleProjectCommandPopupButton::CSimpleProjectCommandPopupButton(wxWindow* parent, wxWindowID id, const wxString& label, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name) : - wxButton(parent, id, label, pos, size, style, validator, name) + CTransparentButton(parent, id, label, pos, size, style, validator, name) { m_ProjectCommandsPopUpMenu = new wxMenu(); diff --git a/clientgui/sg_ProjectCommandPopup.h b/clientgui/sg_ProjectCommandPopup.h index 9c2354c88e..1af185fc9c 100644 --- a/clientgui/sg_ProjectCommandPopup.h +++ b/clientgui/sg_ProjectCommandPopup.h @@ -18,7 +18,9 @@ #ifndef __sg_ProjectCommandPopup__ #define __sg_ProjectCommandPopup__ -class CSimpleProjectCommandPopupButton : public wxButton +#include "sg_CustomControls.h" + +class CSimpleProjectCommandPopupButton : public CTransparentButton { DECLARE_DYNAMIC_CLASS( CSimpleProjectCommandPopupButton ) DECLARE_EVENT_TABLE() diff --git a/clientgui/sg_ProjectPanel.cpp b/clientgui/sg_ProjectPanel.cpp index d62371af72..bb8a0740e3 100644 --- a/clientgui/sg_ProjectPanel.cpp +++ b/clientgui/sg_ProjectPanel.cpp @@ -94,7 +94,7 @@ CSimpleProjectPanel::CSimpleProjectPanel( wxWindow* parent ) : int addProjectWidth, synchronizeWidth, y; GetTextExtent(m_sAddProjectString, &addProjectWidth, &y); GetTextExtent(m_sSynchronizeString, &synchronizeWidth, &y); - m_TaskAddProjectButton = new wxButton( this, ID_ADDROJECTBUTTON, + m_TaskAddProjectButton = new CTransparentButton( this, ID_ADDROJECTBUTTON, (addProjectWidth > synchronizeWidth) ? m_sAddProjectString : m_sSynchronizeString, wxDefaultPosition, wxDefaultSize, 0 ); diff --git a/clientgui/sg_ProjectPanel.h b/clientgui/sg_ProjectPanel.h index 0511553345..876bd360e8 100644 --- a/clientgui/sg_ProjectPanel.h +++ b/clientgui/sg_ProjectPanel.h @@ -59,7 +59,7 @@ class CSimpleProjectPanel : public CSimplePanelBase protected: CTransparentStaticText* m_myProjectsLabel; CBOINCBitmapComboBox* m_ProjectSelectionCtrl; - wxButton* m_TaskAddProjectButton; + CTransparentButton* m_TaskAddProjectButton; CTransparentStaticText* m_TotalCreditValue; CSimpleProjectWebSitesPopupButton* m_ProjectWebSitesButton; CSimpleProjectCommandPopupButton* m_ProjectCommandsButton; diff --git a/clientgui/sg_ProjectWebSitesPopup.cpp b/clientgui/sg_ProjectWebSitesPopup.cpp index eaf8cff205..fd69b43de1 100644 --- a/clientgui/sg_ProjectWebSitesPopup.cpp +++ b/clientgui/sg_ProjectWebSitesPopup.cpp @@ -23,9 +23,9 @@ #include "sg_ProjectWebSitesPopup.h" -IMPLEMENT_DYNAMIC_CLASS(CSimpleProjectWebSitesPopupButton, wxButton) +IMPLEMENT_DYNAMIC_CLASS(CSimpleProjectWebSitesPopupButton, CTransparentButton) -BEGIN_EVENT_TABLE(CSimpleProjectWebSitesPopupButton, wxButton) +BEGIN_EVENT_TABLE(CSimpleProjectWebSitesPopupButton, CTransparentButton) EVT_LEFT_DOWN(CSimpleProjectWebSitesPopupButton::OnProjectWebSiteButton) EVT_MENU(WEBSITE_URL_MENU_ID,CSimpleProjectWebSitesPopupButton::OnMenuLinkClicked) EVT_MENU(WEBSITE_URL_MENU_ID_REMOVE_PROJECT,CSimpleProjectWebSitesPopupButton::OnMenuLinkClicked) @@ -37,7 +37,7 @@ CSimpleProjectWebSitesPopupButton::CSimpleProjectWebSitesPopupButton() { CSimpleProjectWebSitesPopupButton::CSimpleProjectWebSitesPopupButton(wxWindow* parent, wxWindowID id, const wxString& label, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name) : - wxButton(parent, id, label, pos, size, style, validator, name) + CTransparentButton(parent, id, label, pos, size, style, validator, name) { m_ProjectWebSitesPopUpMenu = new wxMenu(); diff --git a/clientgui/sg_ProjectWebSitesPopup.h b/clientgui/sg_ProjectWebSitesPopup.h index 5e89d3c369..085c66ba2e 100644 --- a/clientgui/sg_ProjectWebSitesPopup.h +++ b/clientgui/sg_ProjectWebSitesPopup.h @@ -18,8 +18,9 @@ #ifndef __sg_ProjectWebsitesPopup__ #define __sg_ProjectWebsitesPopup__ +#include "sg_CustomControls.h" -class CSimpleProjectWebSitesPopupButton : public wxButton +class CSimpleProjectWebSitesPopupButton : public CTransparentButton { DECLARE_DYNAMIC_CLASS( CSimpleProjectWebSitesPopupButton ) DECLARE_EVENT_TABLE() diff --git a/clientgui/sg_TaskCommandPopup.cpp b/clientgui/sg_TaskCommandPopup.cpp index 0c266a7bdd..3b6de710b1 100644 --- a/clientgui/sg_TaskCommandPopup.cpp +++ b/clientgui/sg_TaskCommandPopup.cpp @@ -24,9 +24,9 @@ #include "sg_TaskPanel.h" #include "sg_TaskCommandPopup.h" -IMPLEMENT_DYNAMIC_CLASS(CSimpleTaskPopupButton, wxButton) +IMPLEMENT_DYNAMIC_CLASS(CSimpleTaskPopupButton, CTransparentButton) -BEGIN_EVENT_TABLE(CSimpleTaskPopupButton, wxButton) +BEGIN_EVENT_TABLE(CSimpleTaskPopupButton, CTransparentButton) EVT_LEFT_DOWN(CSimpleTaskPopupButton::OnTasksCommandButton) EVT_MENU(ID_TASK_WORK_SHOWGRAPHICS, CSimpleTaskPopupButton::OnTaskShowGraphics) EVT_MENU(ID_TASK_WORK_SUSPEND, CSimpleTaskPopupButton::OnTaskSuspendResume) @@ -40,7 +40,7 @@ CSimpleTaskPopupButton::CSimpleTaskPopupButton() { CSimpleTaskPopupButton::CSimpleTaskPopupButton(wxWindow* parent, wxWindowID id, const wxString& label, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name) : - wxButton(parent, id, label, pos, size, style, validator, name) + CTransparentButton(parent, id, label, pos, size, style, validator, name) { m_TaskSuspendedViaGUI = false; diff --git a/clientgui/sg_TaskCommandPopup.h b/clientgui/sg_TaskCommandPopup.h index d5f5827be6..ce2454592b 100644 --- a/clientgui/sg_TaskCommandPopup.h +++ b/clientgui/sg_TaskCommandPopup.h @@ -19,7 +19,9 @@ #ifndef __sg_TaskCommandPopup__ #define __sg_TaskCommandPopup__ -class CSimpleTaskPopupButton : public wxButton +#include "sg_CustomControls.h" + +class CSimpleTaskPopupButton : public CTransparentButton { DECLARE_DYNAMIC_CLASS( CSimpleTaskPopupButton ) DECLARE_EVENT_TABLE()