From c15f75b81dc36df77063120af6886ff8ff24ba2b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 17 Apr 2016 16:04:45 +0200 Subject: [PATCH] Use custom draw in wxMSW wxHeaderCtrl to support colours Add a helper wxMSWImpl::CustomDraw class which will be reused in the other places too and, for now, use it just to implement support for custom colours in wxHeaderCtrl. Notice that the control took care of the custom font on its anyhow and that background colour is ignored when themes are enabled, so the net effect of this change is that now changing the header foreground colour works, while it was ignored before. --- Makefile.in | 16 ++++ build/bakefiles/files.bkl | 1 + build/files | 1 + build/msw/makefile.bcc | 16 ++++ build/msw/makefile.gcc | 16 ++++ build/msw/makefile.vc | 16 ++++ build/msw/wx_core.vcxproj | 1 + build/msw/wx_core.vcxproj.filters | 3 + build/msw/wx_vc7_core.vcproj | 3 + build/msw/wx_vc8_core.vcproj | 4 + build/msw/wx_vc9_core.vcproj | 4 + include/wx/msw/headerctrl.h | 16 +++- include/wx/msw/private/customdraw.h | 54 ++++++++++++++ src/msw/customdraw.cpp | 66 ++++++++++++++++ src/msw/headerctrl.cpp | 112 ++++++++++++++++++++++++++++ 15 files changed, 328 insertions(+), 1 deletion(-) create mode 100644 include/wx/msw/private/customdraw.h create mode 100644 src/msw/customdraw.cpp diff --git a/Makefile.in b/Makefile.in index a5c48ea26c..94aa146edb 100644 --- a/Makefile.in +++ b/Makefile.in @@ -5352,6 +5352,7 @@ COND_TOOLKIT_MSW___GUI_SRC_OBJECTS = \ monodll_msw_tglbtn.o \ monodll_treectrl.o \ monodll_systhemectrl.o \ + monodll_customdraw.o \ monodll_msw_checklst.o \ monodll_msw_fdrepdlg.o \ monodll_msw_fontdlg.o @@ -7366,6 +7367,7 @@ COND_TOOLKIT_MSW___GUI_SRC_OBJECTS_1 = \ monolib_msw_tglbtn.o \ monolib_treectrl.o \ monolib_systhemectrl.o \ + monolib_customdraw.o \ monolib_msw_checklst.o \ monolib_msw_fdrepdlg.o \ monolib_msw_fontdlg.o @@ -9521,6 +9523,7 @@ COND_TOOLKIT_MSW___GUI_SRC_OBJECTS_2 = \ coredll_msw_tglbtn.o \ coredll_treectrl.o \ coredll_systhemectrl.o \ + coredll_customdraw.o \ coredll_msw_checklst.o \ coredll_msw_fdrepdlg.o \ coredll_msw_fontdlg.o @@ -10990,6 +10993,7 @@ COND_TOOLKIT_MSW___GUI_SRC_OBJECTS_3 = \ corelib_msw_tglbtn.o \ corelib_treectrl.o \ corelib_systhemectrl.o \ + corelib_customdraw.o \ corelib_msw_checklst.o \ corelib_msw_fdrepdlg.o \ corelib_msw_fontdlg.o @@ -16391,6 +16395,9 @@ monodll_treectrl.o: $(srcdir)/src/msw/treectrl.cpp $(MONODLL_ODEP) monodll_systhemectrl.o: $(srcdir)/src/msw/systhemectrl.cpp $(MONODLL_ODEP) $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/msw/systhemectrl.cpp +monodll_customdraw.o: $(srcdir)/src/msw/customdraw.cpp $(MONODLL_ODEP) + $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/msw/customdraw.cpp + monodll_msw_checklst.o: $(srcdir)/src/msw/checklst.cpp $(MONODLL_ODEP) $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/msw/checklst.cpp @@ -21221,6 +21228,9 @@ monolib_treectrl.o: $(srcdir)/src/msw/treectrl.cpp $(MONOLIB_ODEP) monolib_systhemectrl.o: $(srcdir)/src/msw/systhemectrl.cpp $(MONOLIB_ODEP) $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/msw/systhemectrl.cpp +monolib_customdraw.o: $(srcdir)/src/msw/customdraw.cpp $(MONOLIB_ODEP) + $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/msw/customdraw.cpp + monolib_msw_checklst.o: $(srcdir)/src/msw/checklst.cpp $(MONOLIB_ODEP) $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/msw/checklst.cpp @@ -26702,6 +26712,9 @@ coredll_treectrl.o: $(srcdir)/src/msw/treectrl.cpp $(COREDLL_ODEP) coredll_systhemectrl.o: $(srcdir)/src/msw/systhemectrl.cpp $(COREDLL_ODEP) $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/msw/systhemectrl.cpp +coredll_customdraw.o: $(srcdir)/src/msw/customdraw.cpp $(COREDLL_ODEP) + $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/msw/customdraw.cpp + coredll_msw_checklst.o: $(srcdir)/src/msw/checklst.cpp $(COREDLL_ODEP) $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/msw/checklst.cpp @@ -30089,6 +30102,9 @@ corelib_treectrl.o: $(srcdir)/src/msw/treectrl.cpp $(CORELIB_ODEP) corelib_systhemectrl.o: $(srcdir)/src/msw/systhemectrl.cpp $(CORELIB_ODEP) $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/msw/systhemectrl.cpp +corelib_customdraw.o: $(srcdir)/src/msw/customdraw.cpp $(CORELIB_ODEP) + $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/msw/customdraw.cpp + corelib_msw_checklst.o: $(srcdir)/src/msw/checklst.cpp $(CORELIB_ODEP) $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/msw/checklst.cpp diff --git a/build/bakefiles/files.bkl b/build/bakefiles/files.bkl index 79a311f57a..64b427a190 100644 --- a/build/bakefiles/files.bkl +++ b/build/bakefiles/files.bkl @@ -1983,6 +1983,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! src/msw/tglbtn.cpp src/msw/treectrl.cpp src/msw/systhemectrl.cpp + src/msw/customdraw.cpp wx/generic/clrpickerg.h diff --git a/build/files b/build/files index b28fd79527..8d10fa53f1 100644 --- a/build/files +++ b/build/files @@ -1798,6 +1798,7 @@ MSW_SRC = src/msw/combo.cpp src/msw/combobox.cpp src/msw/control.cpp + src/msw/customdraw.cpp src/msw/dialog.cpp src/msw/dirdlg.cpp src/msw/dragimag.cpp diff --git a/build/msw/makefile.bcc b/build/msw/makefile.bcc index ab07b27785..d32214c760 100644 --- a/build/msw/makefile.bcc +++ b/build/msw/makefile.bcc @@ -1897,6 +1897,7 @@ ____CORE_SRC_FILENAMES_OBJECTS = \ $(OBJS)\monodll_msw_tglbtn.obj \ $(OBJS)\monodll_treectrl.obj \ $(OBJS)\monodll_systhemectrl.obj \ + $(OBJS)\monodll_customdraw.obj \ $(OBJS)\monodll_msw_checklst.obj \ $(OBJS)\monodll_msw_fdrepdlg.obj \ $(OBJS)\monodll_fontdlg.obj \ @@ -2728,6 +2729,7 @@ ____CORE_SRC_FILENAMES_1_OBJECTS = \ $(OBJS)\monolib_msw_tglbtn.obj \ $(OBJS)\monolib_treectrl.obj \ $(OBJS)\monolib_systhemectrl.obj \ + $(OBJS)\monolib_customdraw.obj \ $(OBJS)\monolib_msw_checklst.obj \ $(OBJS)\monolib_msw_fdrepdlg.obj \ $(OBJS)\monolib_fontdlg.obj \ @@ -3431,6 +3433,7 @@ ____CORE_SRC_FILENAMES_2_OBJECTS = \ $(OBJS)\coredll_msw_tglbtn.obj \ $(OBJS)\coredll_treectrl.obj \ $(OBJS)\coredll_systhemectrl.obj \ + $(OBJS)\coredll_customdraw.obj \ $(OBJS)\coredll_msw_checklst.obj \ $(OBJS)\coredll_msw_fdrepdlg.obj \ $(OBJS)\coredll_fontdlg.obj \ @@ -4002,6 +4005,7 @@ ____CORE_SRC_FILENAMES_3_OBJECTS = \ $(OBJS)\corelib_msw_tglbtn.obj \ $(OBJS)\corelib_treectrl.obj \ $(OBJS)\corelib_systhemectrl.obj \ + $(OBJS)\corelib_customdraw.obj \ $(OBJS)\corelib_msw_checklst.obj \ $(OBJS)\corelib_msw_fdrepdlg.obj \ $(OBJS)\corelib_fontdlg.obj \ @@ -6927,6 +6931,9 @@ $(OBJS)\monodll_treectrl.obj: ..\..\src\msw\treectrl.cpp $(OBJS)\monodll_systhemectrl.obj: ..\..\src\msw\systhemectrl.cpp $(CXX) -q -c -P -o$@ $(MONODLL_CXXFLAGS) ..\..\src\msw\systhemectrl.cpp +$(OBJS)\monodll_customdraw.obj: ..\..\src\msw\customdraw.cpp + $(CXX) -q -c -P -o$@ $(MONODLL_CXXFLAGS) ..\..\src\msw\customdraw.cpp + $(OBJS)\monodll_msw_checklst.obj: ..\..\src\msw\checklst.cpp $(CXX) -q -c -P -o$@ $(MONODLL_CXXFLAGS) ..\..\src\msw\checklst.cpp @@ -9462,6 +9469,9 @@ $(OBJS)\monolib_treectrl.obj: ..\..\src\msw\treectrl.cpp $(OBJS)\monolib_systhemectrl.obj: ..\..\src\msw\systhemectrl.cpp $(CXX) -q -c -P -o$@ $(MONOLIB_CXXFLAGS) ..\..\src\msw\systhemectrl.cpp +$(OBJS)\monolib_customdraw.obj: ..\..\src\msw\customdraw.cpp + $(CXX) -q -c -P -o$@ $(MONOLIB_CXXFLAGS) ..\..\src\msw\customdraw.cpp + $(OBJS)\monolib_msw_checklst.obj: ..\..\src\msw\checklst.cpp $(CXX) -q -c -P -o$@ $(MONOLIB_CXXFLAGS) ..\..\src\msw\checklst.cpp @@ -12405,6 +12415,9 @@ $(OBJS)\coredll_treectrl.obj: ..\..\src\msw\treectrl.cpp $(OBJS)\coredll_systhemectrl.obj: ..\..\src\msw\systhemectrl.cpp $(CXX) -q -c -P -o$@ $(COREDLL_CXXFLAGS) ..\..\src\msw\systhemectrl.cpp +$(OBJS)\coredll_customdraw.obj: ..\..\src\msw\customdraw.cpp + $(CXX) -q -c -P -o$@ $(COREDLL_CXXFLAGS) ..\..\src\msw\customdraw.cpp + $(OBJS)\coredll_msw_checklst.obj: ..\..\src\msw\checklst.cpp $(CXX) -q -c -P -o$@ $(COREDLL_CXXFLAGS) ..\..\src\msw\checklst.cpp @@ -13882,6 +13895,9 @@ $(OBJS)\corelib_treectrl.obj: ..\..\src\msw\treectrl.cpp $(OBJS)\corelib_systhemectrl.obj: ..\..\src\msw\systhemectrl.cpp $(CXX) -q -c -P -o$@ $(CORELIB_CXXFLAGS) ..\..\src\msw\systhemectrl.cpp +$(OBJS)\corelib_customdraw.obj: ..\..\src\msw\customdraw.cpp + $(CXX) -q -c -P -o$@ $(CORELIB_CXXFLAGS) ..\..\src\msw\customdraw.cpp + $(OBJS)\corelib_msw_checklst.obj: ..\..\src\msw\checklst.cpp $(CXX) -q -c -P -o$@ $(CORELIB_CXXFLAGS) ..\..\src\msw\checklst.cpp diff --git a/build/msw/makefile.gcc b/build/msw/makefile.gcc index 492fe10dad..ed7ec53ffc 100644 --- a/build/msw/makefile.gcc +++ b/build/msw/makefile.gcc @@ -1916,6 +1916,7 @@ ____CORE_SRC_FILENAMES_OBJECTS = \ $(OBJS)\monodll_msw_tglbtn.o \ $(OBJS)\monodll_treectrl.o \ $(OBJS)\monodll_systhemectrl.o \ + $(OBJS)\monodll_customdraw.o \ $(OBJS)\monodll_msw_checklst.o \ $(OBJS)\monodll_msw_fdrepdlg.o \ $(OBJS)\monodll_fontdlg.o \ @@ -2753,6 +2754,7 @@ ____CORE_SRC_FILENAMES_1_OBJECTS = \ $(OBJS)\monolib_msw_tglbtn.o \ $(OBJS)\monolib_treectrl.o \ $(OBJS)\monolib_systhemectrl.o \ + $(OBJS)\monolib_customdraw.o \ $(OBJS)\monolib_msw_checklst.o \ $(OBJS)\monolib_msw_fdrepdlg.o \ $(OBJS)\monolib_fontdlg.o \ @@ -3472,6 +3474,7 @@ ____CORE_SRC_FILENAMES_2_OBJECTS = \ $(OBJS)\coredll_msw_tglbtn.o \ $(OBJS)\coredll_treectrl.o \ $(OBJS)\coredll_systhemectrl.o \ + $(OBJS)\coredll_customdraw.o \ $(OBJS)\coredll_msw_checklst.o \ $(OBJS)\coredll_msw_fdrepdlg.o \ $(OBJS)\coredll_fontdlg.o \ @@ -4051,6 +4054,7 @@ ____CORE_SRC_FILENAMES_3_OBJECTS = \ $(OBJS)\corelib_msw_tglbtn.o \ $(OBJS)\corelib_treectrl.o \ $(OBJS)\corelib_systhemectrl.o \ + $(OBJS)\corelib_customdraw.o \ $(OBJS)\corelib_msw_checklst.o \ $(OBJS)\corelib_msw_fdrepdlg.o \ $(OBJS)\corelib_fontdlg.o \ @@ -7102,6 +7106,9 @@ $(OBJS)\monodll_treectrl.o: ../../src/msw/treectrl.cpp $(OBJS)\monodll_systhemectrl.o: ../../src/msw/systhemectrl.cpp $(CXX) -c -o $@ $(MONODLL_CXXFLAGS) $(CPPDEPS) $< +$(OBJS)\monodll_customdraw.o: ../../src/msw/customdraw.cpp + $(CXX) -c -o $@ $(MONODLL_CXXFLAGS) $(CPPDEPS) $< + $(OBJS)\monodll_msw_checklst.o: ../../src/msw/checklst.cpp $(CXX) -c -o $@ $(MONODLL_CXXFLAGS) $(CPPDEPS) $< @@ -9639,6 +9646,9 @@ $(OBJS)\monolib_treectrl.o: ../../src/msw/treectrl.cpp $(OBJS)\monolib_systhemectrl.o: ../../src/msw/systhemectrl.cpp $(CXX) -c -o $@ $(MONOLIB_CXXFLAGS) $(CPPDEPS) $< +$(OBJS)\monolib_customdraw.o: ../../src/msw/customdraw.cpp + $(CXX) -c -o $@ $(MONOLIB_CXXFLAGS) $(CPPDEPS) $< + $(OBJS)\monolib_msw_checklst.o: ../../src/msw/checklst.cpp $(CXX) -c -o $@ $(MONOLIB_CXXFLAGS) $(CPPDEPS) $< @@ -12584,6 +12594,9 @@ $(OBJS)\coredll_treectrl.o: ../../src/msw/treectrl.cpp $(OBJS)\coredll_systhemectrl.o: ../../src/msw/systhemectrl.cpp $(CXX) -c -o $@ $(COREDLL_CXXFLAGS) $(CPPDEPS) $< +$(OBJS)\coredll_customdraw.o: ../../src/msw/customdraw.cpp + $(CXX) -c -o $@ $(COREDLL_CXXFLAGS) $(CPPDEPS) $< + $(OBJS)\coredll_msw_checklst.o: ../../src/msw/checklst.cpp $(CXX) -c -o $@ $(COREDLL_CXXFLAGS) $(CPPDEPS) $< @@ -14061,6 +14074,9 @@ $(OBJS)\corelib_treectrl.o: ../../src/msw/treectrl.cpp $(OBJS)\corelib_systhemectrl.o: ../../src/msw/systhemectrl.cpp $(CXX) -c -o $@ $(CORELIB_CXXFLAGS) $(CPPDEPS) $< +$(OBJS)\corelib_customdraw.o: ../../src/msw/customdraw.cpp + $(CXX) -c -o $@ $(CORELIB_CXXFLAGS) $(CPPDEPS) $< + $(OBJS)\corelib_msw_checklst.o: ../../src/msw/checklst.cpp $(CXX) -c -o $@ $(CORELIB_CXXFLAGS) $(CPPDEPS) $< diff --git a/build/msw/makefile.vc b/build/msw/makefile.vc index 5f3afb2537..1ec0c63716 100644 --- a/build/msw/makefile.vc +++ b/build/msw/makefile.vc @@ -2197,6 +2197,7 @@ ____CORE_SRC_FILENAMES_OBJECTS = \ $(OBJS)\monodll_msw_tglbtn.obj \ $(OBJS)\monodll_treectrl.obj \ $(OBJS)\monodll_systhemectrl.obj \ + $(OBJS)\monodll_customdraw.obj \ $(OBJS)\monodll_msw_checklst.obj \ $(OBJS)\monodll_msw_fdrepdlg.obj \ $(OBJS)\monodll_fontdlg.obj \ @@ -3034,6 +3035,7 @@ ____CORE_SRC_FILENAMES_1_OBJECTS = \ $(OBJS)\monolib_msw_tglbtn.obj \ $(OBJS)\monolib_treectrl.obj \ $(OBJS)\monolib_systhemectrl.obj \ + $(OBJS)\monolib_customdraw.obj \ $(OBJS)\monolib_msw_checklst.obj \ $(OBJS)\monolib_msw_fdrepdlg.obj \ $(OBJS)\monolib_fontdlg.obj \ @@ -3803,6 +3805,7 @@ ____CORE_SRC_FILENAMES_2_OBJECTS = \ $(OBJS)\coredll_msw_tglbtn.obj \ $(OBJS)\coredll_treectrl.obj \ $(OBJS)\coredll_systhemectrl.obj \ + $(OBJS)\coredll_customdraw.obj \ $(OBJS)\coredll_msw_checklst.obj \ $(OBJS)\coredll_msw_fdrepdlg.obj \ $(OBJS)\coredll_fontdlg.obj \ @@ -4380,6 +4383,7 @@ ____CORE_SRC_FILENAMES_3_OBJECTS = \ $(OBJS)\corelib_msw_tglbtn.obj \ $(OBJS)\corelib_treectrl.obj \ $(OBJS)\corelib_systhemectrl.obj \ + $(OBJS)\corelib_customdraw.obj \ $(OBJS)\corelib_msw_checklst.obj \ $(OBJS)\corelib_msw_fdrepdlg.obj \ $(OBJS)\corelib_fontdlg.obj \ @@ -7619,6 +7623,9 @@ $(OBJS)\monodll_treectrl.obj: ..\..\src\msw\treectrl.cpp $(OBJS)\monodll_systhemectrl.obj: ..\..\src\msw\systhemectrl.cpp $(CXX) /c /nologo /TP /Fo$@ $(MONODLL_CXXFLAGS) ..\..\src\msw\systhemectrl.cpp +$(OBJS)\monodll_customdraw.obj: ..\..\src\msw\customdraw.cpp + $(CXX) /c /nologo /TP /Fo$@ $(MONODLL_CXXFLAGS) ..\..\src\msw\customdraw.cpp + $(OBJS)\monodll_msw_checklst.obj: ..\..\src\msw\checklst.cpp $(CXX) /c /nologo /TP /Fo$@ $(MONODLL_CXXFLAGS) ..\..\src\msw\checklst.cpp @@ -10154,6 +10161,9 @@ $(OBJS)\monolib_treectrl.obj: ..\..\src\msw\treectrl.cpp $(OBJS)\monolib_systhemectrl.obj: ..\..\src\msw\systhemectrl.cpp $(CXX) /c /nologo /TP /Fo$@ $(MONOLIB_CXXFLAGS) ..\..\src\msw\systhemectrl.cpp +$(OBJS)\monolib_customdraw.obj: ..\..\src\msw\customdraw.cpp + $(CXX) /c /nologo /TP /Fo$@ $(MONOLIB_CXXFLAGS) ..\..\src\msw\customdraw.cpp + $(OBJS)\monolib_msw_checklst.obj: ..\..\src\msw\checklst.cpp $(CXX) /c /nologo /TP /Fo$@ $(MONOLIB_CXXFLAGS) ..\..\src\msw\checklst.cpp @@ -13097,6 +13107,9 @@ $(OBJS)\coredll_treectrl.obj: ..\..\src\msw\treectrl.cpp $(OBJS)\coredll_systhemectrl.obj: ..\..\src\msw\systhemectrl.cpp $(CXX) /c /nologo /TP /Fo$@ $(COREDLL_CXXFLAGS) ..\..\src\msw\systhemectrl.cpp +$(OBJS)\coredll_customdraw.obj: ..\..\src\msw\customdraw.cpp + $(CXX) /c /nologo /TP /Fo$@ $(COREDLL_CXXFLAGS) ..\..\src\msw\customdraw.cpp + $(OBJS)\coredll_msw_checklst.obj: ..\..\src\msw\checklst.cpp $(CXX) /c /nologo /TP /Fo$@ $(COREDLL_CXXFLAGS) ..\..\src\msw\checklst.cpp @@ -14574,6 +14587,9 @@ $(OBJS)\corelib_treectrl.obj: ..\..\src\msw\treectrl.cpp $(OBJS)\corelib_systhemectrl.obj: ..\..\src\msw\systhemectrl.cpp $(CXX) /c /nologo /TP /Fo$@ $(CORELIB_CXXFLAGS) ..\..\src\msw\systhemectrl.cpp +$(OBJS)\corelib_customdraw.obj: ..\..\src\msw\customdraw.cpp + $(CXX) /c /nologo /TP /Fo$@ $(CORELIB_CXXFLAGS) ..\..\src\msw\customdraw.cpp + $(OBJS)\corelib_msw_checklst.obj: ..\..\src\msw\checklst.cpp $(CXX) /c /nologo /TP /Fo$@ $(CORELIB_CXXFLAGS) ..\..\src\msw\checklst.cpp diff --git a/build/msw/wx_core.vcxproj b/build/msw/wx_core.vcxproj index fc524cf554..291c6f866d 100644 --- a/build/msw/wx_core.vcxproj +++ b/build/msw/wx_core.vcxproj @@ -1007,6 +1007,7 @@ + diff --git a/build/msw/wx_core.vcxproj.filters b/build/msw/wx_core.vcxproj.filters index 5a8a2cd509..4295676e97 100644 --- a/build/msw/wx_core.vcxproj.filters +++ b/build/msw/wx_core.vcxproj.filters @@ -612,6 +612,9 @@ MSW Sources + + MSW Sources + MSW Sources diff --git a/build/msw/wx_vc7_core.vcproj b/build/msw/wx_vc7_core.vcproj index 363ba1eb54..583cc7eeee 100644 --- a/build/msw/wx_vc7_core.vcproj +++ b/build/msw/wx_vc7_core.vcproj @@ -769,6 +769,9 @@ + + diff --git a/build/msw/wx_vc8_core.vcproj b/build/msw/wx_vc8_core.vcproj index 0e1dcaa624..91212e072e 100644 --- a/build/msw/wx_vc8_core.vcproj +++ b/build/msw/wx_vc8_core.vcproj @@ -1430,6 +1430,10 @@ RelativePath="..\..\src\msw\cursor.cpp" > + + diff --git a/build/msw/wx_vc9_core.vcproj b/build/msw/wx_vc9_core.vcproj index 27ac832be8..91d8b8dbd3 100644 --- a/build/msw/wx_vc9_core.vcproj +++ b/build/msw/wx_vc9_core.vcproj @@ -1426,6 +1426,10 @@ RelativePath="..\..\src\msw\cursor.cpp" > + + diff --git a/include/wx/msw/headerctrl.h b/include/wx/msw/headerctrl.h index db702c5a19..af2125bfb5 100644 --- a/include/wx/msw/headerctrl.h +++ b/include/wx/msw/headerctrl.h @@ -12,6 +12,8 @@ class WXDLLIMPEXP_FWD_CORE wxImageList; +class wxMSWHeaderCtrlCustomDraw; + // ---------------------------------------------------------------------------- // wxHeaderCtrl // ---------------------------------------------------------------------------- @@ -45,7 +47,11 @@ public: virtual ~wxHeaderCtrl(); - + // Override to implement colours support via custom drawing. + virtual bool SetBackgroundColour(const wxColour& colour) wxOVERRIDE; + virtual bool SetForegroundColour(const wxColour& colour) wxOVERRIDE; + virtual bool SetFont(const wxFont& font) wxOVERRIDE; + protected: // override wxWindow methods which must be implemented by a new control virtual wxSize DoGetBestSize() const; @@ -98,6 +104,10 @@ private: // mouse button wxEventType GetClickEventType(bool dblclk, int button); + // allocate m_customDraw if we need it or free it if it no longer is, + // return the pointer which can be used to update it if it's non-null + wxMSWHeaderCtrlCustomDraw* GetCustomDraw(); + // the number of columns in the control, including the hidden ones (not // taken into account by the native control, see comment in DoGetCount()) @@ -129,6 +139,10 @@ private: // actual column we are dragging or -1 if not dragging anything int m_colBeingDragged; + // the custom draw helper: initially NULL, created on demand, use + // GetCustomDraw() to do it + wxMSWHeaderCtrlCustomDraw *m_customDraw; + wxDECLARE_NO_COPY_CLASS(wxHeaderCtrl); }; diff --git a/include/wx/msw/private/customdraw.h b/include/wx/msw/private/customdraw.h new file mode 100644 index 0000000000..36bd009659 --- /dev/null +++ b/include/wx/msw/private/customdraw.h @@ -0,0 +1,54 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: wx/msw/private/customdraw.h +// Purpose: Helper for implementing custom drawing support in wxMSW +// Author: Vadim Zeitlin +// Created: 2016-04-16 +// Copyright: (c) 2016 Vadim Zeitlin +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_MSW_CUSTOMDRAW_H_ +#define _WX_MSW_CUSTOMDRAW_H_ + +#include "wx/itemattr.h" + +#include "wx/msw/wrapcctl.h" + +namespace wxMSWImpl +{ + +// ---------------------------------------------------------------------------- +// CustomDraw: inherit from this class and forward NM_CUSTOMDRAW to it +// ---------------------------------------------------------------------------- + +class CustomDraw +{ +public: + // Trivial default ctor needed for non-copyable class. + CustomDraw() + { + } + + // Implementation of NM_CUSTOMDRAW handler, returns one of CDRF_XXX + // constants, possibly CDRF_DODEFAULT if custom drawing is not necessary. + LPARAM HandleCustomDraw(LPARAM lParam); + +private: + // Return true if we need custom drawing at all. + virtual bool HasCustomDrawnItems() const = 0; + + // Return the attribute to use for the given item, can return NULL if this + // item doesn't need to be custom-drawn. + virtual const wxItemAttr* GetItemAttr(DWORD_PTR dwItemSpec) const = 0; + + + // Set the colours and font for the specified HDC, return CDRF_NEWFONT if + // the font was changed. + LPARAM HandleItemPrepaint(const wxItemAttr& attr, HDC hdc); + + wxDECLARE_NO_COPY_CLASS(CustomDraw); +}; + +} // namespace wxMSWImpl + +#endif // _WX_MSW_CUSTOMDRAW_H_ diff --git a/src/msw/customdraw.cpp b/src/msw/customdraw.cpp new file mode 100644 index 0000000000..aae74669b8 --- /dev/null +++ b/src/msw/customdraw.cpp @@ -0,0 +1,66 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: src/msw/customdraw.cpp +// Purpose: wxMSWCustomDraw implementation +// Author: Vadim Zeitlin +// Created: 2016-04-16 +// Copyright: (c) 2016 Vadim Zeitlin +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +// for compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#include "wx/msw/private/customdraw.h" + +// ============================================================================ +// implementation +// ============================================================================ + +LPARAM wxMSWImpl::CustomDraw::HandleItemPrepaint(const wxItemAttr& attr, HDC hdc) +{ + if ( attr.HasTextColour() ) + ::SetTextColor(hdc, wxColourToRGB(attr.GetTextColour())); + + if ( attr.HasBackgroundColour() ) + ::SetBkColor(hdc, wxColourToRGB(attr.GetBackgroundColour())); + + if ( attr.HasFont() ) + { + ::SelectObject(hdc, GetHfontOf(attr.GetFont())); + + return CDRF_NEWFONT; + } + + return CDRF_DODEFAULT; +} + +LPARAM wxMSWImpl::CustomDraw::HandleCustomDraw(LPARAM lParam) +{ + NMCUSTOMDRAW* nmcd = reinterpret_cast(lParam); + switch ( nmcd->dwDrawStage ) + { + case CDDS_PREPAINT: + if ( HasCustomDrawnItems() ) + return CDRF_NOTIFYITEMDRAW; + break; + + case CDDS_ITEMPREPAINT: + const wxItemAttr* const attr = GetItemAttr(nmcd->dwItemSpec); + if ( attr ) + return HandleItemPrepaint(*attr, nmcd->hdc); + } + + return CDRF_DODEFAULT; +} diff --git a/src/msw/headerctrl.cpp b/src/msw/headerctrl.cpp index 359324b439..befc28c119 100644 --- a/src/msw/headerctrl.cpp +++ b/src/msw/headerctrl.cpp @@ -37,6 +37,7 @@ #include "wx/msw/wrapcctl.h" #include "wx/msw/private.h" +#include "wx/msw/private/customdraw.h" #ifndef HDM_SETBITMAPMARGIN #define HDM_SETBITMAPMARGIN 0x1234 @@ -50,6 +51,36 @@ // from src/msw/listctrl.cpp extern int WXDLLIMPEXP_CORE wxMSWGetColumnClicked(NMHDR *nmhdr, POINT *ptClick); +// ---------------------------------------------------------------------------- +// wxMSWHeaderCtrlCustomDraw: our custom draw helper +// ---------------------------------------------------------------------------- + +class wxMSWHeaderCtrlCustomDraw : public wxMSWImpl::CustomDraw +{ +public: + wxMSWHeaderCtrlCustomDraw() + { + } + + // Make this field public to let wxHeaderCtrl update it directly when its + // attributes change. + wxItemAttr m_attr; + +private: + virtual bool HasCustomDrawnItems() const wxOVERRIDE + { + // We only exist if the header does need to be custom drawn. + return true; + } + + virtual const wxItemAttr* + GetItemAttr(DWORD_PTR WXUNUSED(dwItemSpec)) const wxOVERRIDE + { + // We use the same attribute for all items for now. + return &m_attr; + } +}; + // ============================================================================ // wxHeaderCtrl implementation // ============================================================================ @@ -64,6 +95,7 @@ void wxHeaderCtrl::Init() m_imageList = NULL; m_scrollOffset = 0; m_colBeingDragged = -1; + m_customDraw = NULL; } bool wxHeaderCtrl::Create(wxWindow *parent, @@ -116,6 +148,7 @@ WXDWORD wxHeaderCtrl::MSWGetStyle(long style, WXDWORD *exstyle) const wxHeaderCtrl::~wxHeaderCtrl() { delete m_imageList; + delete m_customDraw; } // ---------------------------------------------------------------------------- @@ -466,6 +499,73 @@ int wxHeaderCtrl::MSWFromNativeOrder(int order) return pos; } +// ---------------------------------------------------------------------------- +// wxHeaderCtrl appearance +// ---------------------------------------------------------------------------- + +wxMSWHeaderCtrlCustomDraw* wxHeaderCtrl::GetCustomDraw() +{ + // There is no need to make the control custom drawn just because it has a + // custom font, the native control handles the font just fine on its own, + // so if our custom colours were reset, don't bother with custom drawing + // any longer. + if ( !m_hasBgCol && !m_hasFgCol ) + { + if ( m_customDraw ) + { + delete m_customDraw; + m_customDraw = NULL; + } + + return NULL; + } + + // We do have at least one custom colour, so enable custom drawing. + if ( !m_customDraw ) + m_customDraw = new wxMSWHeaderCtrlCustomDraw(); + + return m_customDraw; +} + +bool wxHeaderCtrl::SetBackgroundColour(const wxColour& colour) +{ + if ( !wxHeaderCtrlBase::SetBackgroundColour(colour) ) + return false; + + if ( wxMSWHeaderCtrlCustomDraw* customDraw = GetCustomDraw() ) + { + customDraw->m_attr.SetBackgroundColour(colour); + } + + return true; +} + +bool wxHeaderCtrl::SetForegroundColour(const wxColour& colour) +{ + if ( !wxHeaderCtrlBase::SetForegroundColour(colour) ) + return false; + + if ( wxMSWHeaderCtrlCustomDraw* customDraw = GetCustomDraw() ) + { + customDraw->m_attr.SetTextColour(colour); + } + + return true; +} + +bool wxHeaderCtrl::SetFont(const wxFont& font) +{ + if ( !wxHeaderCtrlBase::SetFont(font) ) + return false; + + if ( wxMSWHeaderCtrlCustomDraw* customDraw = GetCustomDraw() ) + { + customDraw->m_attr.SetFont(font); + } + + return true; +} + // ---------------------------------------------------------------------------- // wxHeaderCtrl events // ---------------------------------------------------------------------------- @@ -670,6 +770,18 @@ bool wxHeaderCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) // Dragging the column was cancelled. m_colBeingDragged = -1; break; + + // other events + // ------------ + + case NM_CUSTOMDRAW: + if ( m_customDraw ) + { + *result = m_customDraw->HandleCustomDraw(lParam); + if ( *result != CDRF_DODEFAULT ) + return true; + } + break; }