Skip to content

Commit cbfa414

Browse files
author
徐扬斌
committed
wxMSW: Add support to use generic wxHeaderCtrl in wxMSW port with __WX_FORCE_USE_HEADERCTRL_GENERIC__ macro.
And do respect foreground and background colour set via wxDataViewCtrl::SetHeaderAttr(). Enable dark mode support of the header ctrl.
1 parent ae9cfe2 commit cbfa414

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

include/wx/headerctrl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class WXDLLIMPEXP_CORE wxHeaderCtrlBase : public wxControl
250250
// control, see wxHeaderCtrlSimple for a standalone version
251251
// ----------------------------------------------------------------------------
252252

253-
#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
253+
#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__) && !defined(__WX_FORCE_USE_HEADERCTRL_GENERIC__)
254254
#include "wx/msw/headerctrl.h"
255255
#else
256256
#define wxHAS_GENERIC_HEADERCTRL

src/generic/headerctrlg.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,16 @@ void wxHeaderCtrl::UpdateReorderingMarker(int xPhysical)
411411
wxDCOverlay dcover(m_overlay, &dc);
412412
dcover.Clear();
413413

414-
dc.SetPen(*wxBLUE);
415-
dc.SetBrush(*wxTRANSPARENT_BRUSH);
416-
414+
static const auto g_light_cyan_pen = wxPen{ wxColour{208, 226, 249} };
415+
static const auto g_light_cyan_brush = wxBrush{ wxColour{208, 226, 249} };
416+
if (wxSystemSettings::GetAppearance().IsDark()) {
417+
dc.SetPen(g_light_cyan_pen);
418+
dc.SetBrush(*wxTRANSPARENT_BRUSH);
419+
}
420+
else {
421+
dc.SetPen(*wxBLUE);
422+
dc.SetBrush(*wxTRANSPARENT_BRUSH);
423+
}
417424
// draw the phantom position of the column being dragged
418425
int x = xPhysical - m_dragOffset;
419426
int y = GetClientSize().y;
@@ -428,7 +435,10 @@ void wxHeaderCtrl::UpdateReorderingMarker(int xPhysical)
428435
{
429436
static const int DROP_MARKER_WIDTH = 4;
430437

431-
dc.SetBrush(*wxBLUE);
438+
if (wxSystemSettings::GetAppearance().IsDark())
439+
dc.SetBrush(g_light_cyan_brush);
440+
else
441+
dc.SetBrush(*wxBLUE);
432442
if (hover_region == Region::LeftHalf){
433443
dc.DrawRectangle(GetColStart(col) - DROP_MARKER_WIDTH/2, 0,
434444
DROP_MARKER_WIDTH, y);

src/msw/renderer.cpp

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -692,25 +692,17 @@ wxRendererXP::DrawHeaderButton(wxWindow *win,
692692
}
693693

694694
wxCHECK_MSG( dc.GetImpl(), -1, wxT("Invalid wxDC") );
695-
696-
RECT r = ConvertToRECT(dc, rect);
697-
698-
int state;
699-
if ( flags & wxCONTROL_PRESSED )
700-
state = HIS_PRESSED;
701-
else if ( flags & wxCONTROL_CURRENT )
702-
state = HIS_HOT;
703-
else
704-
state = HIS_NORMAL;
705-
::DrawThemeBackground
706-
(
707-
hTheme,
708-
GetHdcOf(dc.GetTempHDC()),
709-
HP_HEADERITEM,
710-
state,
711-
&r,
712-
NULL
713-
);
695+
696+
auto frame_bkg_color = win->GetBackgroundColour();
697+
auto bk_brush = wxBrush{ frame_bkg_color };
698+
dc.SetBrush(bk_brush);
699+
dc.SetPen(*wxTRANSPARENT_PEN);
700+
dc.DrawRectangle(rect);
701+
dc.SetPen(*wxLIGHT_GREY_PEN);
702+
dc.DrawLine(rect.GetLeftTop(), rect.GetLeftBottom());
703+
704+
if (params != nullptr)
705+
params->m_labelColour = win->GetForegroundColour();
714706

715707
// NOTE: Using the theme to draw HP_HEADERSORTARROW doesn't do anything.
716708
// Why? If this can be fixed then draw the sort arrows using the theme

0 commit comments

Comments
 (0)