Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac: Support Dark Mode in Advanced View #5267

Merged
merged 11 commits into from
Jun 19, 2023
49 changes: 49 additions & 0 deletions clientgui/AdvancedFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1980,6 +1980,55 @@ void CAdvancedFrame::OnSelectAll(wxCommandEvent& WXUNUSED(event)) {
}


// On the Mac, we must destroy and recreate each wxListCtrl
// to properly transition between dark mode and regular mode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a blank comment line after this line.

void CAdvancedFrame::OnDarkModeChanged( wxSysColourChangedEvent& WXUNUSED(event) ) {
CBOINCBaseView* theView = NULL;;
CBOINCListCtrl* theListCtrl = NULL;
long bottomItem;
wxTimerEvent timerEvent;
int currentPage = _GetCurrentViewPage();

StopTimers();
SaveState();
// Get the list copntrol's current scroll position
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spell check: "control's"

if ((currentPage == VW_PROJ) || (currentPage == VW_TASK) || (currentPage == VW_XFER)) {
theView = (CBOINCBaseView*)(m_pNotebook->GetPage(m_pNotebook->GetSelection()));
theListCtrl = theView->GetListCtrl();
bottomItem = theListCtrl->GetTopItem() + theListCtrl->GetCountPerPage() - 1;
}
RepopulateNotebook();
RestoreState();

// The last tab label ("Disk") is ellipsed here unless the window is resized
// TODO: figure out how to replace this hack with a proper fix
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a blank comment line after this line.

int x, y;
GetSize(&x, &y);
SetSize(x+1, y);
SetSize(x, y);

// Scroll the recreated list control to the same row as before
if ((currentPage == VW_PROJ) || (currentPage == VW_TASK) || (currentPage == VW_XFER)) {
theView = (CBOINCBaseView*)(m_pNotebook->GetPage(m_pNotebook->GetSelection()));
theView->FireOnListRender(timerEvent);
theListCtrl = theView->GetListCtrl();
if (theListCtrl->GetCountPerPage() < theListCtrl->GetItemCount()) {
theListCtrl->EnsureVisible(bottomItem);
}
}
// TODO: figure out how to preserve notices tab (currentPage == VW_NOTIF) scrolled position

StartTimers();

CDlgEventLog* eventLog = wxGetApp().GetEventLog();
if (eventLog) {
wxGetApp().OnEventLogClose();
delete eventLog; // eventLog->Destroy() creates a race condition if used here.
wxGetApp().DisplayEventLog();
}
}


void CAdvancedFrame::UpdateActivityModeControls( CC_STATUS& status ) {
wxMenuBar* pMenuBar = GetMenuBar();
wxASSERT(pMenuBar);
Expand Down
1 change: 1 addition & 0 deletions clientgui/AdvancedFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class CAdvancedFrame : public CBOINCBaseFrame
void OnNetworkSelection( wxCommandEvent& event );

void OnSelectAll( wxCommandEvent& event );
void OnDarkModeChanged( wxSysColourChangedEvent& event );

void OnMenuOpening( wxMenuEvent &event);
void OnOptions( wxCommandEvent& event );
Expand Down
4 changes: 4 additions & 0 deletions clientgui/BOINCBaseFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ BEGIN_EVENT_TABLE (CBOINCBaseFrame, wxFrame)
EVT_CLOSE(CBOINCBaseFrame::OnClose)
EVT_MENU(ID_CLOSEWINDOW, CBOINCBaseFrame::OnCloseWindow)
EVT_MENU(wxID_EXIT, CBOINCBaseFrame::OnExit)
EVT_SYS_COLOUR_CHANGED(CBOINCBaseFrame::OnDarkModeChanged)
END_EVENT_TABLE ()


Expand Down Expand Up @@ -376,6 +377,9 @@ void CBOINCBaseFrame::OnExit(wxCommandEvent& WXUNUSED(event)) {
wxLogTrace(wxT("Function Start/End"), wxT("CAdvancedFrame::OnExit - Function End"));
}

void CBOINCBaseFrame::OnDarkModeChanged( wxSysColourChangedEvent& WXUNUSED(event) ) {
}


int CBOINCBaseFrame::GetCurrentViewPage() {
return _GetCurrentViewPage();
Expand Down
3 changes: 2 additions & 1 deletion clientgui/BOINCBaseFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class CBOINCBaseFrame : public wxFrame {
virtual void OnClose( wxCloseEvent& event );
virtual void OnCloseWindow( wxCommandEvent& event );
virtual void OnExit( wxCommandEvent& event );
virtual void OnDarkModeChanged( wxSysColourChangedEvent& event );

void OnWizardAttachProject( wxCommandEvent& event );
void OnWizardUpdate( wxCommandEvent& event );
Expand Down Expand Up @@ -107,7 +108,7 @@ class CBOINCBaseFrame : public wxFrame {
virtual bool RestoreState();
virtual bool SaveState();
virtual bool CreateMenus(){return true;}
void ResetReminderTimers();
void ResetReminderTimers();

protected:

Expand Down
9 changes: 6 additions & 3 deletions clientgui/BOINCListCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#endif

#include "stdwx.h"
#include "BOINCGUIApp.h"
#include "BOINCBaseView.h"
#include "BOINCListCtrl.h"
#include "Events.h"
Expand Down Expand Up @@ -81,6 +82,8 @@ CBOINCListCtrl::CBOINCListCtrl(
pView, iListWindowID, wxDefaultPosition, wxSize(-1, -1), iListWindowFlags
) {
m_pParentView = pView;
wxSystemAppearance appearance = wxSystemSettings::GetAppearance();
m_isDarkMode = appearance.IsDark();

// Enable Zebra Striping
EnableAlternateRowColours(true);
Expand Down Expand Up @@ -522,7 +525,7 @@ void CBOINCListCtrl::DrawProgressBars()
int n = (int)m_iRowsNeedingProgressBars.GetCount();
if (n <= 0) return;

wxColour progressColor = wxTheColourDatabase->Find(wxT("LIGHT BLUE"));
wxColour progressColor = m_isDarkMode ? wxColour(0, 64, 128) : wxColour(192, 217, 217);
wxBrush progressBrush(progressColor);

numItems = GetItemCount();
Expand Down Expand Up @@ -604,8 +607,8 @@ void CBOINCListCtrl::DrawProgressBars()
dc.SetPen(bkgd);
dc.SetBrush(bkgd);
#else
dc.SetPen(*wxWHITE_PEN);
dc.SetBrush(*wxWHITE_BRUSH);
dc.SetPen(m_isDarkMode ? *wxBLACK_PEN : *wxWHITE_PEN);
dc.SetBrush(m_isDarkMode ? *wxBLACK_BRUSH : *wxWHITE_BRUSH);
#endif
dc.DrawRectangle( rr );

Expand Down
1 change: 1 addition & 0 deletions clientgui/BOINCListCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class CBOINCListCtrl : public LISTCTRL_BASE {

CBOINCBaseView* m_pParentView;
wxArrayInt m_iRowsNeedingProgressBars;
bool m_isDarkMode;

#if ! USE_LIST_CACHE_HINT
void OnMouseDown(wxMouseEvent& event);
Expand Down
24 changes: 22 additions & 2 deletions clientgui/NoticeListCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ bool CNoticeListCtrl::Create( wxWindow* parent ) {
#endif
////@end CNoticeListCtrl creation

wxSystemAppearance appearance = wxSystemSettings::GetAppearance();
m_isDarkMode = appearance.IsDark();

wxBoxSizer *topsizer;
topsizer = new wxBoxSizer(wxVERTICAL);

Expand All @@ -101,7 +104,18 @@ bool CNoticeListCtrl::Create( wxWindow* parent ) {
SetSizer(topsizer);

m_itemCount = 0;
m_noticesBody = wxT("<html><head></head><body></body></html>");
if (m_isDarkMode){
m_noticesBody = wxT("<html><style>body{background-color:black;color:white;}</style><head></head><body></body></html>");
} else {
m_noticesBody = wxT("<html><head></head><body></body></html>");
}

// In Dark Mode, paint the windoe black immediately
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spell check: window

#if wxUSE_WEBVIEW
m_browser->SetPage(m_noticesBody, wxEmptyString);
#else
m_browser->SetPage(m_noticesBody);
#endif

// Display the fetching notices message until we have notices
// to display or have determined that there are no notices.
Expand Down Expand Up @@ -139,7 +153,13 @@ void CNoticeListCtrl::SetItemCount(int newCount) {
wxASSERT(wxDynamicCast(pSkinAdvanced, CSkinAdvanced));

m_itemCount = newCount;
m_noticesBody = wxT("<html><head></head><body><font face=helvetica>");


if (m_isDarkMode){
m_noticesBody = wxT("<html><style>body{background-color:black;color:white;}</style><head></head><body><font face=helvetica>");
} else {
m_noticesBody = wxT("<html><head></head><body><font face=helvetica>");
}

for (i=0; i<newCount; ++i) {
if (pDoc->IsConnected()) {
Expand Down
1 change: 1 addition & 0 deletions clientgui/NoticeListCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class CNoticeListCtrl: public wxWindow
bool m_bNeedsReloading;
int m_itemCount;
wxString m_noticesBody;
bool m_isDarkMode;
};

#endif
18 changes: 11 additions & 7 deletions clientgui/ViewResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ CViewResources::CViewResources(wxNotebook* pNotebook) :
{
m_BOINCwasEmpty=false;

wxSystemAppearance appearance = wxSystemSettings::GetAppearance();
m_isDarkMode = appearance.IsDark();

wxGridSizer* itemGridSizer = new wxGridSizer(2, 0, 3);
wxASSERT(itemGridSizer);

Expand All @@ -58,7 +61,7 @@ CViewResources::CViewResources(wxNotebook* pNotebook) :
m_pieCtrlTotal->SetTransparent(true);
m_pieCtrlTotal->SetHorLegendBorder(10);
m_pieCtrlTotal->SetLabelFont(*wxSWISS_FONT);
m_pieCtrlTotal->SetLabelColour(wxColour(0,0,0));
m_pieCtrlTotal->SetLabelColour(m_isDarkMode ? *wxWHITE : *wxBLACK);
m_pieCtrlTotal->SetLabel(_("Total disk usage"));

// initialize pie control
Expand All @@ -79,7 +82,7 @@ CViewResources::CViewResources(wxNotebook* pNotebook) :
m_pieCtrlBOINC->SetTransparent(true);
m_pieCtrlBOINC->SetHorLegendBorder(10);
m_pieCtrlBOINC->SetLabelFont(*wxSWISS_FONT);
m_pieCtrlBOINC->SetLabelColour(wxColour(0,0,0));
m_pieCtrlTotal->SetLabelColour(m_isDarkMode ? *wxWHITE : *wxBLACK);
m_pieCtrlBOINC->SetLabel(_("Disk usage by BOINC projects"));

// initialize pie control
Expand Down Expand Up @@ -260,7 +263,8 @@ void CViewResources::OnListRender( wxTimerEvent& WXUNUSED(event) ) {
FormatDiskSpace(boinc_total, diskspace);
part.SetLabel(_("used by BOINC: ") + diskspace);
part.SetValue(boinc_total);
part.SetColour(wxColour(0,0,0));
part.SetColour(m_isDarkMode ? wxColour(255, 255, 255) : wxColour(0,0,0));
part.SetColour(m_isDarkMode ? *wxWHITE : *wxBLACK);
m_pieCtrlTotal->m_Series.Add(part);

if (pDoc->disk_usage.d_allowed > 0) {
Expand All @@ -270,15 +274,15 @@ void CViewResources::OnListRender( wxTimerEvent& WXUNUSED(event) ) {
FormatDiskSpace(avail, diskspace);
part.SetLabel(_("free, available to BOINC: ") + diskspace);
part.SetValue(avail == 0 ? 1 : avail);
part.SetColour(wxColour(128, 128, 128));
part.SetColour(m_isDarkMode ? wxColour(108, 108, 108) : wxColour(128, 128, 128));
m_pieCtrlTotal->m_Series.Add(part);

double not_avail = free - avail;
if (not_avail > 0) {
FormatDiskSpace(not_avail, diskspace);
part.SetLabel(_("free, not available to BOINC: ") + diskspace);
part.SetValue(not_avail);
part.SetColour(wxColour(238,238,238));
part.SetColour(m_isDarkMode ? wxColour(172,172,172) : wxColour(238,238,238));
m_pieCtrlTotal->m_Series.Add(part);
}
} else {
Expand All @@ -288,7 +292,7 @@ void CViewResources::OnListRender( wxTimerEvent& WXUNUSED(event) ) {
FormatDiskSpace(free, diskspace);
part.SetLabel(_("free: ") + diskspace);
part.SetValue(free);
part.SetColour(wxColour(238,238,238));
part.SetColour(m_isDarkMode ? wxColour(172,172,172) : wxColour(238,238,238));
m_pieCtrlTotal->m_Series.Add(part);
}

Expand All @@ -297,7 +301,7 @@ void CViewResources::OnListRender( wxTimerEvent& WXUNUSED(event) ) {
FormatDiskSpace(used_by_others, diskspace);
part.SetLabel(_("used by other programs: ") + diskspace);
part.SetValue(used_by_others);
part.SetColour(wxColour(192,192,192));
part.SetColour(m_isDarkMode ? wxColour(140,140,140) : wxColour(192,192,192));
m_pieCtrlTotal->m_Series.Add(part);
m_pieCtrlTotal->Refresh();
}
Expand Down
1 change: 1 addition & 0 deletions clientgui/ViewResources.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class CViewResources : public CBOINCBaseView
wxPieCtrl* m_pieCtrlTotal;

bool m_BOINCwasEmpty;
bool m_isDarkMode;

virtual void UpdateSelection();

Expand Down
23 changes: 13 additions & 10 deletions clientgui/ViewStatistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ CPaintStatistics::CPaintStatistics(wxWindow* parent, wxWindowID id, const wxPoin
m_Legend_dY = 0;
m_LegendDraw = true;

wxSystemAppearance appearance = wxSystemSettings::GetAppearance();
m_isDarkMode = appearance.IsDark();

// Default colours
m_pen_MarkerLineColour = wxColour(0, 0, 0);
m_pen_ZoomRectColour = wxColour (128, 64, 95);
Expand All @@ -165,21 +168,20 @@ CPaintStatistics::CPaintStatistics(wxWindow* parent, wxWindowID id, const wxPoin
m_pen_AxisColourAutoZoom = wxColour(64, 128, 192);
m_pen_AxisXColour = wxColour(64, 128, 192);
m_pen_AxisYColour = wxColour(64, 128, 192);
m_pen_AxisXTextColour = wxColour(0, 0, 0);
m_pen_AxisYTextColour = wxColour(0, 0, 0);
m_pen_AxisXTextColour = m_isDarkMode ? wxColour(255, 255, 255) : wxColour(0,0,0);
m_pen_AxisYTextColour = m_isDarkMode ? wxColour(255, 255, 255) : wxColour(0,0,0);

m_brush_LegendColour = wxColour(235, 255, 255);//wxColour(220, 240, 255);
m_brush_LegendColour = m_isDarkMode ? wxColour(0, 64, 128) : wxColour(235, 255, 255);
m_brush_LegendSelectColour = wxColour(192, 224, 255);
m_pen_LegendSelectColour = wxColour(64, 128, 192);
m_pen_LegendSelectTextColour = wxColour(0, 0, 0);
m_pen_LegendSelectTextColour = m_isDarkMode ? wxColour(255, 255, 255) : wxColour(0,0,0);
m_pen_LegendColour = wxColour(64, 128, 192);
m_pen_LegendTextColour = wxColour(0, 0, 0);

m_brush_MainColour = wxColour(255, 255, 255);
m_pen_LegendTextColour = m_isDarkMode ? wxColour(255, 255, 255) : wxColour(0,0,0);
m_brush_MainColour = m_isDarkMode ? wxColour(0,0,0) : wxColour(255, 255, 255);
m_pen_MainColour = wxColour(64, 128, 192);

m_pen_HeadTextColour = wxColour(0, 0, 0);
m_pen_ProjectHeadTextColour = wxColour(0, 0, 0);
m_pen_HeadTextColour = m_isDarkMode ? wxColour(255, 255, 255) : wxColour(0,0,0);
m_pen_ProjectHeadTextColour = m_isDarkMode ? wxColour(255, 255, 255) : wxColour(0,0,0);

m_pen_GraphTotalColour = wxColour(255, 0, 0);
m_pen_GraphRACColour = wxColour(0, 160, 0);
Expand Down Expand Up @@ -625,7 +627,8 @@ void CPaintStatistics::DrawLegend(wxDC &dc, PROJECTS* proj, CMainDocument* pDoc,
dc.SetFont(m_font_bold);
}else {
dc.SetFont(m_font_standart_italic);
graphColour = wxColour(0, 0, 0);
graphColour = m_isDarkMode ? wxColour(255, 255, 255) : wxColour(0,0,0);

}

x0 = wxCoord(m_WorkSpace_X_end) + buffer_x1 + wxCoord(7) + wxCoord(m_GraphPointWidth);
Expand Down
2 changes: 2 additions & 0 deletions clientgui/ViewStatistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ class CPaintStatistics : public wxWindow
wxColour m_pen_GraphTotalHostColour;
wxColour m_pen_GraphRACHostColour;

bool m_isDarkMode;

protected:
void OnPaint(wxPaintEvent& event);
void OnEraseBackground(wxEraseEvent & /*event*/){};
Expand Down
12 changes: 8 additions & 4 deletions clientgui/common/wxPieCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,18 @@ wxPieCtrl::wxPieCtrl(wxWindow * parent, wxWindowID id, wxPoint pos,
wxSize sz, long style, wxString name)
:wxWindow(parent, id, pos, sz, style, name)
{
wxSystemAppearance appearance = wxSystemSettings::GetAppearance();
m_isDarkMode = appearance.IsDark();
if (m_isDarkMode) SetBackgroundColour(*wxBLACK);

m_ShowEdges=true;
m_CanRepaint=true;
m_BackColour=*wxWHITE;
m_BackColour = m_isDarkMode ? *wxBLACK : *wxWHITE;
m_padding=10;

m_TitleColour = wxColour(0,0,0);
m_LabelColour = *wxBLACK;
m_LegendBackColour = wxColour(255,255,0);
m_TitleColour = m_isDarkMode ? wxColour(255,255,255) : wxColour(0,0,0);
m_LabelColour = m_isDarkMode ? *wxWHITE : *wxBLACK;
m_LegendBackColour = m_isDarkMode ? wxColour(0, 0, 255) : wxColour(255,255,0);
m_TitleFont = *wxSWISS_FONT;
m_TitleFont.SetWeight(wxBOLD);
m_LabelFont = *wxSWISS_FONT;
Expand Down
1 change: 1 addition & 0 deletions clientgui/common/wxPieCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ using wxWindow::SetTransparent;
wxScrollBar* m_scrollBar;
int m_Scrollbar_width;
int m_firstlabelToDraw;
bool m_isDarkMode;

//internal methods
void GetPartAngles(wxArrayDouble & angles);
Expand Down
2 changes: 0 additions & 2 deletions clientgui/mac/templates/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,5 @@
<string>%VERSION%</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSRequiresAquaSystemAppearance</key>
<true/>
</dict>
</plist>