From 64196306bc618c73d0badd75916c4013ae7cd281 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 17 Apr 2016 16:01:11 +0200 Subject: [PATCH] Add a very simple page showing wxHeaderCtrl in the widgets sample This is mostly in order to test that changing font and colours works for this control (or, rather, that currently it doesn't in wxMSW). --- samples/widgets/Makefile.in | 4 + samples/widgets/headerctrl.cpp | 114 +++++++++++++++++++++++++++++ samples/widgets/icons/header.xpm | 54 ++++++++++++++ samples/widgets/makefile.bcc | 4 + samples/widgets/makefile.gcc | 4 + samples/widgets/makefile.unx | 4 + samples/widgets/makefile.vc | 4 + samples/widgets/widgets.bkl | 1 + samples/widgets/widgets_vc7.vcproj | 3 + samples/widgets/widgets_vc8.vcproj | 4 + samples/widgets/widgets_vc9.vcproj | 4 + 11 files changed, 200 insertions(+) create mode 100644 samples/widgets/headerctrl.cpp create mode 100644 samples/widgets/icons/header.xpm diff --git a/samples/widgets/Makefile.in b/samples/widgets/Makefile.in index d4d7647218..e51b00adce 100644 --- a/samples/widgets/Makefile.in +++ b/samples/widgets/Makefile.in @@ -70,6 +70,7 @@ WIDGETS_OBJECTS = \ widgets_filepicker.o \ widgets_fontpicker.o \ widgets_gauge.o \ + widgets_headerctrl.o \ widgets_hyperlnk.o \ widgets_itemcontainer.o \ widgets_listbox.o \ @@ -265,6 +266,9 @@ widgets_fontpicker.o: $(srcdir)/fontpicker.cpp widgets_gauge.o: $(srcdir)/gauge.cpp $(CXXC) -c -o $@ $(WIDGETS_CXXFLAGS) $(srcdir)/gauge.cpp +widgets_headerctrl.o: $(srcdir)/headerctrl.cpp + $(CXXC) -c -o $@ $(WIDGETS_CXXFLAGS) $(srcdir)/headerctrl.cpp + widgets_hyperlnk.o: $(srcdir)/hyperlnk.cpp $(CXXC) -c -o $@ $(WIDGETS_CXXFLAGS) $(srcdir)/hyperlnk.cpp diff --git a/samples/widgets/headerctrl.cpp b/samples/widgets/headerctrl.cpp new file mode 100644 index 0000000000..92979e49a0 --- /dev/null +++ b/samples/widgets/headerctrl.cpp @@ -0,0 +1,114 @@ +///////////////////////////////////////////////////////////////////////////// +// Program: wxWidgets Widgets Sample +// Name: headerctrl.cpp +// Purpose: Part of the widgets sample showing wxHeaderCtrl +// Author: Vadim Zeitlin +// Created: 2016-04-17 +// Copyright: (c) 2016 wxWindows team +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +// for compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#if wxUSE_HEADERCTRL + +// for all others, include the necessary headers +#ifndef WX_PRECOMP + #include "wx/button.h" + #include "wx/sizer.h" + #include "wx/stattext.h" +#endif + +#include "wx/headerctrl.h" + +#include "widgets.h" + +#include "icons/header.xpm" + +// ---------------------------------------------------------------------------- +// HeaderCtrlWidgetsPage +// ---------------------------------------------------------------------------- + +class HeaderCtrlWidgetsPage : public WidgetsPage +{ +public: + HeaderCtrlWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist) + : WidgetsPage(book, imaglist, header_xpm) + { + m_header = NULL; + m_sizerHeader = NULL; + } + + virtual wxWindow *GetWidget() const wxOVERRIDE { return m_header; } + virtual void RecreateWidget() wxOVERRIDE; + + // lazy creation of the content + virtual void CreateContent() wxOVERRIDE; + +protected: + // the control itself and the sizer it is in + wxHeaderCtrlSimple *m_header; + wxSizer *m_sizerHeader; + +private: + DECLARE_WIDGETS_PAGE(HeaderCtrlWidgetsPage) +}; + +// ============================================================================ +// implementation +// ============================================================================ + +#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__) + #define HEADER_CTRL_FAMILY NATIVE_CTRLS +#else + #define HEADER_CTRL_FAMILY GENERIC_CTRLS +#endif + +IMPLEMENT_WIDGETS_PAGE(HeaderCtrlWidgetsPage, + wxT("Header"), HEADER_CTRL_FAMILY); + +void HeaderCtrlWidgetsPage::CreateContent() +{ + m_sizerHeader = new wxStaticBoxSizer(wxVERTICAL, this, "Header"); + RecreateWidget(); + + wxSizer* const sizerTop = new wxBoxSizer(wxHORIZONTAL); + sizerTop->Add(m_sizerHeader, wxSizerFlags(1).Expand().DoubleBorder()); + + SetSizer(sizerTop); +} + +void HeaderCtrlWidgetsPage::RecreateWidget() +{ + m_sizerHeader->Clear(true /* delete windows */); + + int flags = GetAttrs().m_defaultFlags; + + flags |= wxHD_DEFAULT_STYLE; + + m_header = new wxHeaderCtrlSimple(this, wxID_ANY, + wxDefaultPosition, wxDefaultSize, + flags); + m_header->AppendColumn(wxHeaderColumnSimple("First", 100)); + m_header->AppendColumn(wxHeaderColumnSimple("Second", 200)); + + m_sizerHeader->AddStretchSpacer(); + m_sizerHeader->Add(m_header, wxSizerFlags().Expand()); + m_sizerHeader->AddStretchSpacer(); + m_sizerHeader->Layout(); +} + +#endif // wxUSE_HEADERCTRL diff --git a/samples/widgets/icons/header.xpm b/samples/widgets/icons/header.xpm new file mode 100644 index 0000000000..ce95e30dff --- /dev/null +++ b/samples/widgets/icons/header.xpm @@ -0,0 +1,54 @@ +/* XPM */ +static const char *const header_xpm[] = { +/* columns rows colors chars-per-pixel */ +"32 32 16 1", +" c Gray0", +". c #808000", +"X c #000080", +"o c #808080", +"O c #000000", +"+ c #808000", +"@ c #000080", +"# c none", +"$ c #808080", +"% c Red", +"& c Green", +"* c Yellow", +"= c Blue", +"- c Magenta", +"; c Cyan", +": c Gray100", +/* pixels */ +" ", +" ############################## ", +" #&&&&&&&&&&&&&&&&&&&&&&&&&&&&# ", +" #&&&&&&&&&&&&&&&&&&&&&&&&&&&&# ", +" #&&&&&&&&&&&&&&&&&&&&&&&&&&&&# ", +" ############################## ", +" ############################## ", +" ############################## ", +" ############################## ", +" ############################## ", +" ############################## ", +" ############################## ", +" ############################## ", +" ############################## ", +" ############################## ", +" ############################## ", +" ############################## ", +" ############################## ", +" ############################## ", +" ############################## ", +" ############################## ", +" ############################## ", +" ############################## ", +" ############################## ", +" ############################## ", +" ############################## ", +" ############################## ", +" ############################## ", +" ############################## ", +" ############################## ", +" ############################## ", +" " +}; diff --git a/samples/widgets/makefile.bcc b/samples/widgets/makefile.bcc index 991ea88449..03fdfd2a7e 100644 --- a/samples/widgets/makefile.bcc +++ b/samples/widgets/makefile.bcc @@ -51,6 +51,7 @@ WIDGETS_OBJECTS = \ $(OBJS)\widgets_filepicker.obj \ $(OBJS)\widgets_fontpicker.obj \ $(OBJS)\widgets_gauge.obj \ + $(OBJS)\widgets_headerctrl.obj \ $(OBJS)\widgets_hyperlnk.obj \ $(OBJS)\widgets_itemcontainer.obj \ $(OBJS)\widgets_listbox.obj \ @@ -310,6 +311,9 @@ $(OBJS)\widgets_fontpicker.obj: .\fontpicker.cpp $(OBJS)\widgets_gauge.obj: .\gauge.cpp $(CXX) -q -c -P -o$@ $(WIDGETS_CXXFLAGS) .\gauge.cpp +$(OBJS)\widgets_headerctrl.obj: .\headerctrl.cpp + $(CXX) -q -c -P -o$@ $(WIDGETS_CXXFLAGS) .\headerctrl.cpp + $(OBJS)\widgets_hyperlnk.obj: .\hyperlnk.cpp $(CXX) -q -c -P -o$@ $(WIDGETS_CXXFLAGS) .\hyperlnk.cpp diff --git a/samples/widgets/makefile.gcc b/samples/widgets/makefile.gcc index 3a0009ae8e..8f4c99d4ea 100644 --- a/samples/widgets/makefile.gcc +++ b/samples/widgets/makefile.gcc @@ -44,6 +44,7 @@ WIDGETS_OBJECTS = \ $(OBJS)\widgets_filepicker.o \ $(OBJS)\widgets_fontpicker.o \ $(OBJS)\widgets_gauge.o \ + $(OBJS)\widgets_headerctrl.o \ $(OBJS)\widgets_hyperlnk.o \ $(OBJS)\widgets_itemcontainer.o \ $(OBJS)\widgets_listbox.o \ @@ -299,6 +300,9 @@ $(OBJS)\widgets_fontpicker.o: ./fontpicker.cpp $(OBJS)\widgets_gauge.o: ./gauge.cpp $(CXX) -c -o $@ $(WIDGETS_CXXFLAGS) $(CPPDEPS) $< +$(OBJS)\widgets_headerctrl.o: ./headerctrl.cpp + $(CXX) -c -o $@ $(WIDGETS_CXXFLAGS) $(CPPDEPS) $< + $(OBJS)\widgets_hyperlnk.o: ./hyperlnk.cpp $(CXX) -c -o $@ $(WIDGETS_CXXFLAGS) $(CPPDEPS) $< diff --git a/samples/widgets/makefile.unx b/samples/widgets/makefile.unx index 6ec2d07a6e..08b3bfe112 100644 --- a/samples/widgets/makefile.unx +++ b/samples/widgets/makefile.unx @@ -68,6 +68,7 @@ WIDGETS_OBJECTS = \ widgets_filepicker.o \ widgets_fontpicker.o \ widgets_gauge.o \ + widgets_headerctrl.o \ widgets_hyperlnk.o \ widgets_itemcontainer.o \ widgets_listbox.o \ @@ -165,6 +166,9 @@ widgets_fontpicker.o: ./fontpicker.cpp widgets_gauge.o: ./gauge.cpp $(CXX) -c -o $@ $(WIDGETS_CXXFLAGS) $(CPPDEPS) $< +widgets_headerctrl.o: ./headerctrl.cpp + $(CXX) -c -o $@ $(WIDGETS_CXXFLAGS) $(CPPDEPS) $< + widgets_hyperlnk.o: ./hyperlnk.cpp $(CXX) -c -o $@ $(WIDGETS_CXXFLAGS) $(CPPDEPS) $< diff --git a/samples/widgets/makefile.vc b/samples/widgets/makefile.vc index aaa243fbae..7670f32252 100644 --- a/samples/widgets/makefile.vc +++ b/samples/widgets/makefile.vc @@ -46,6 +46,7 @@ WIDGETS_OBJECTS = \ $(OBJS)\widgets_filepicker.obj \ $(OBJS)\widgets_fontpicker.obj \ $(OBJS)\widgets_gauge.obj \ + $(OBJS)\widgets_headerctrl.obj \ $(OBJS)\widgets_hyperlnk.obj \ $(OBJS)\widgets_itemcontainer.obj \ $(OBJS)\widgets_listbox.obj \ @@ -433,6 +434,9 @@ $(OBJS)\widgets_fontpicker.obj: .\fontpicker.cpp $(OBJS)\widgets_gauge.obj: .\gauge.cpp $(CXX) /c /nologo /TP /Fo$@ $(WIDGETS_CXXFLAGS) .\gauge.cpp +$(OBJS)\widgets_headerctrl.obj: .\headerctrl.cpp + $(CXX) /c /nologo /TP /Fo$@ $(WIDGETS_CXXFLAGS) .\headerctrl.cpp + $(OBJS)\widgets_hyperlnk.obj: .\hyperlnk.cpp $(CXX) /c /nologo /TP /Fo$@ $(WIDGETS_CXXFLAGS) .\hyperlnk.cpp diff --git a/samples/widgets/widgets.bkl b/samples/widgets/widgets.bkl index 41dc5907e2..74536f79d7 100644 --- a/samples/widgets/widgets.bkl +++ b/samples/widgets/widgets.bkl @@ -37,6 +37,7 @@ filepicker.cpp fontpicker.cpp gauge.cpp + headerctrl.cpp hyperlnk.cpp itemcontainer.cpp listbox.cpp diff --git a/samples/widgets/widgets_vc7.vcproj b/samples/widgets/widgets_vc7.vcproj index 92eb7877da..f721fb2ba1 100644 --- a/samples/widgets/widgets_vc7.vcproj +++ b/samples/widgets/widgets_vc7.vcproj @@ -328,6 +328,9 @@ + + diff --git a/samples/widgets/widgets_vc8.vcproj b/samples/widgets/widgets_vc8.vcproj index 93c0a27227..0eaddea77e 100644 --- a/samples/widgets/widgets_vc8.vcproj +++ b/samples/widgets/widgets_vc8.vcproj @@ -866,6 +866,10 @@ RelativePath=".\gauge.cpp" > + + diff --git a/samples/widgets/widgets_vc9.vcproj b/samples/widgets/widgets_vc9.vcproj index dac1d5654c..d3743d808e 100644 --- a/samples/widgets/widgets_vc9.vcproj +++ b/samples/widgets/widgets_vc9.vcproj @@ -838,6 +838,10 @@ RelativePath=".\gauge.cpp" > + +