From c592363e95152fdd6eb7618b5505f815e40c4787 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 16 Apr 2016 17:03:54 +0200 Subject: [PATCH 01/10] Remove obsolete test for HDN_BEGINTRACKA being defined It's used without this test in src/msw/headerctrl.cpp, so we can be sure using this symbol doesn't create any problems any more. --- src/msw/listctrl.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index e37f779da2..2b2e42d79e 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -1998,11 +1998,6 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) NMHDR *nmhdr = (NMHDR *)lParam; - // if your compiler is as broken as this, you should really change it: this - // code is needed for normal operation! #ifdef below is only useful for - // automatic rebuilds which are done with a very old compiler version -#ifdef HDN_BEGINTRACKA - // check for messages from the header (in report view) HWND hwndHdr = ListView_GetHeader(GetHwnd()); @@ -2097,9 +2092,7 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) if ( ignore ) return wxListCtrlBase::MSWOnNotify(idCtrl, lParam, result); } - else -#endif // defined(HDN_BEGINTRACKA) - if ( nmhdr->hwndFrom == GetHwnd() ) + else if ( nmhdr->hwndFrom == GetHwnd() ) { // almost all messages use NM_LISTVIEW NM_LISTVIEW *nmLV = (NM_LISTVIEW *)nmhdr; From 246ae58c19e6985f6c52e094416267fc10d03526 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 16 Apr 2016 17:44:19 +0200 Subject: [PATCH 02/10] Replace wxTreeItemAttr and wxListItemAttr with wxItemAttr The two existing structs were completely identical, just replace them with a single wxItemAttr. Notice that wxDataViewItemAttr is not quite the same, although pretty similar, so it remains separate for now. It would be nice to combine it with this one too in the future, e.g. to make it simpler to make items bold in a wxListCtrl. --- Makefile.in | 1 + build/bakefiles/files.bkl | 1 + build/files | 1 + build/msw/wx_core.vcxproj | 1 + build/msw/wx_core.vcxproj.filters | 15 +++-- build/msw/wx_vc7_core.vcproj | 3 + build/msw/wx_vc8_core.vcproj | 4 ++ build/msw/wx_vc9_core.vcproj | 4 ++ include/wx/generic/private/listctrl.h | 10 ++-- include/wx/itemattr.h | 65 +++++++++++++++++++++ include/wx/listbase.h | 75 +++++------------------- include/wx/msw/listctrl.h | 4 +- include/wx/msw/treectrl.h | 3 +- include/wx/qt/listctrl.h | 2 +- include/wx/treebase.h | 34 ----------- interface/wx/itemattr.h | 82 +++++++++++++++++++++++++++ interface/wx/listctrl.h | 80 +------------------------- samples/listctrl/listtest.cpp | 6 +- samples/listctrl/listtest.h | 2 +- src/common/listctrlcmn.cpp | 4 +- src/generic/listctrl.cpp | 8 +-- src/generic/treectlg.cpp | 19 ++++--- src/msw/listctrl.cpp | 14 ++--- src/msw/treectrl.cpp | 15 ++--- 24 files changed, 232 insertions(+), 221 deletions(-) create mode 100644 include/wx/itemattr.h create mode 100644 interface/wx/itemattr.h diff --git a/Makefile.in b/Makefile.in index 782aa59413..a5c48ea26c 100644 --- a/Makefile.in +++ b/Makefile.in @@ -3872,6 +3872,7 @@ COND_USE_GUI_1_ALL_GUI_HEADERS = \ wx/systhemectrl.h \ wx/collheaderctrl.h \ wx/generic/collheaderctrl.h \ + wx/itemattr.h \ $(LOWLEVEL_HDR) \ $(GUI_CORE_HEADERS) \ $(ADVANCED_HDR) \ diff --git a/build/bakefiles/files.bkl b/build/bakefiles/files.bkl index e8a3dc4630..79a311f57a 100644 --- a/build/bakefiles/files.bkl +++ b/build/bakefiles/files.bkl @@ -1181,6 +1181,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! wx/systhemectrl.h wx/collheaderctrl.h wx/generic/collheaderctrl.h + wx/itemattr.h diff --git a/build/files b/build/files index c75433c695..b28fd79527 100644 --- a/build/files +++ b/build/files @@ -1039,6 +1039,7 @@ GUI_CMN_HDR = wx/imagtga.h wx/imagtiff.h wx/imagxpm.h + wx/itemattr.h wx/listbase.h wx/listbook.h wx/listctrl.h diff --git a/build/msw/wx_core.vcxproj b/build/msw/wx_core.vcxproj index 425d1e1845..fc524cf554 100644 --- a/build/msw/wx_core.vcxproj +++ b/build/msw/wx_core.vcxproj @@ -1379,6 +1379,7 @@ + diff --git a/build/msw/wx_core.vcxproj.filters b/build/msw/wx_core.vcxproj.filters index 39e16aeb8f..5a8a2cd509 100644 --- a/build/msw/wx_core.vcxproj.filters +++ b/build/msw/wx_core.vcxproj.filters @@ -690,6 +690,9 @@ MSW Sources + + MSW Sources + MSW Sources @@ -897,9 +900,6 @@ Common Sources - - MSW Sources - @@ -928,6 +928,9 @@ Common Headers + + Common Headers + Common Headers @@ -1312,6 +1315,9 @@ Common Headers + + Common Headers + Common Headers @@ -1672,9 +1678,6 @@ MSW Headers - - Common Headers - Common Headers diff --git a/build/msw/wx_vc7_core.vcproj b/build/msw/wx_vc7_core.vcproj index 1a69b3b619..363ba1eb54 100644 --- a/build/msw/wx_vc7_core.vcproj +++ b/build/msw/wx_vc7_core.vcproj @@ -2285,6 +2285,9 @@ + + diff --git a/build/msw/wx_vc8_core.vcproj b/build/msw/wx_vc8_core.vcproj index c87b463021..0e1dcaa624 100644 --- a/build/msw/wx_vc8_core.vcproj +++ b/build/msw/wx_vc8_core.vcproj @@ -3548,6 +3548,10 @@ RelativePath="..\..\include\wx\infobar.h" > + + diff --git a/build/msw/wx_vc9_core.vcproj b/build/msw/wx_vc9_core.vcproj index 24d92eb874..27ac832be8 100644 --- a/build/msw/wx_vc9_core.vcproj +++ b/build/msw/wx_vc9_core.vcproj @@ -3544,6 +3544,10 @@ RelativePath="..\..\include\wx\infobar.h" > + + diff --git a/include/wx/generic/private/listctrl.h b/include/wx/generic/private/listctrl.h index 9cd50707a8..0f5c002632 100644 --- a/include/wx/generic/private/listctrl.h +++ b/include/wx/generic/private/listctrl.h @@ -85,8 +85,8 @@ public: void GetItem( wxListItem &info ) const; - void SetAttr(wxListItemAttr *attr) { m_attr = attr; } - wxListItemAttr *GetAttr() const { return m_attr; } + void SetAttr(wxItemAttr *attr) { m_attr = attr; } + wxItemAttr *GetAttr() const { return m_attr; } public: // the item image or -1 @@ -103,7 +103,7 @@ public: wxListMainWindow *m_owner; // custom attributes or NULL - wxListItemAttr *m_attr; + wxItemAttr *m_attr; protected: // common part of all ctors @@ -263,8 +263,8 @@ public: wxString GetText(int index) const; void SetText( int index, const wxString& s ); - wxListItemAttr *GetAttr() const; - void SetAttr(wxListItemAttr *attr); + wxItemAttr *GetAttr() const; + void SetAttr(wxItemAttr *attr); // return true if the highlighting really changed bool Highlight( bool on ); diff --git a/include/wx/itemattr.h b/include/wx/itemattr.h new file mode 100644 index 0000000000..90ae149d85 --- /dev/null +++ b/include/wx/itemattr.h @@ -0,0 +1,65 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: wx/itemattr.h +// Purpose: wxItemAttr class declaration +// Author: Vadim Zeitlin +// Created: 2016-04-16 (extracted from wx/listctrl.h) +// Copyright: (c) 2016 Vadim Zeitlin +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_ITEMATTR_H_ +#define _WX_ITEMATTR_H_ + +// ---------------------------------------------------------------------------- +// wxItemAttr: a structure containing the visual attributes of an item +// ---------------------------------------------------------------------------- + +class wxItemAttr +{ +public: + // ctors + wxItemAttr() { } + wxItemAttr(const wxColour& colText, + const wxColour& colBack, + const wxFont& font) + : m_colText(colText), m_colBack(colBack), m_font(font) + { + } + + // default copy ctor, assignment operator and dtor are ok + + + // setters + void SetTextColour(const wxColour& colText) { m_colText = colText; } + void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; } + void SetFont(const wxFont& font) { m_font = font; } + + // accessors + bool HasTextColour() const { return m_colText.IsOk(); } + bool HasBackgroundColour() const { return m_colBack.IsOk(); } + bool HasFont() const { return m_font.IsOk(); } + + const wxColour& GetTextColour() const { return m_colText; } + const wxColour& GetBackgroundColour() const { return m_colBack; } + const wxFont& GetFont() const { return m_font; } + + + // this is almost like assignment operator except it doesn't overwrite the + // fields unset in the source attribute + void AssignFrom(const wxItemAttr& source) + { + if ( source.HasTextColour() ) + SetTextColour(source.GetTextColour()); + if ( source.HasBackgroundColour() ) + SetBackgroundColour(source.GetBackgroundColour()); + if ( source.HasFont() ) + SetFont(source.GetFont()); + } + +private: + wxColour m_colText, + m_colBack; + wxFont m_font; +}; + +#endif // _WX_ITEMATTR_H_ diff --git a/include/wx/listbase.h b/include/wx/listbase.h index 1c79de0084..841b4c00fa 100644 --- a/include/wx/listbase.h +++ b/include/wx/listbase.h @@ -16,6 +16,7 @@ #include "wx/gdicmn.h" #include "wx/event.h" #include "wx/control.h" +#include "wx/itemattr.h" #include "wx/systhemectrl.h" class WXDLLIMPEXP_FWD_CORE wxImageList; @@ -158,60 +159,10 @@ enum wxLIST_FIND_RIGHT }; -// ---------------------------------------------------------------------------- -// wxListItemAttr: a structure containing the visual attributes of an item -// ---------------------------------------------------------------------------- - -// TODO: this should be renamed to wxItemAttr or something general like this -// and used as base class for wxTextAttr which duplicates this class -// entirely currently -class WXDLLIMPEXP_CORE wxListItemAttr -{ -public: - // ctors - wxListItemAttr() { } - wxListItemAttr(const wxColour& colText, - const wxColour& colBack, - const wxFont& font) - : m_colText(colText), m_colBack(colBack), m_font(font) - { - } - - // default copy ctor, assignment operator and dtor are ok - - - // setters - void SetTextColour(const wxColour& colText) { m_colText = colText; } - void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; } - void SetFont(const wxFont& font) { m_font = font; } - - // accessors - bool HasTextColour() const { return m_colText.IsOk(); } - bool HasBackgroundColour() const { return m_colBack.IsOk(); } - bool HasFont() const { return m_font.IsOk(); } - - const wxColour& GetTextColour() const { return m_colText; } - const wxColour& GetBackgroundColour() const { return m_colBack; } - const wxFont& GetFont() const { return m_font; } - - - // this is almost like assignment operator except it doesn't overwrite the - // fields unset in the source attribute - void AssignFrom(const wxListItemAttr& source) - { - if ( source.HasTextColour() ) - SetTextColour(source.GetTextColour()); - if ( source.HasBackgroundColour() ) - SetBackgroundColour(source.GetBackgroundColour()); - if ( source.HasFont() ) - SetFont(source.GetFont()); - } - -private: - wxColour m_colText, - m_colBack; - wxFont m_font; -}; +// For compatibility, define the old name for this class. There is no need to +// deprecate it as it doesn't cost us anything to keep this typedef, but the +// new code should prefer to use the new wxItemAttr name. +typedef wxItemAttr wxListItemAttr; // ---------------------------------------------------------------------------- // wxListItem: the item or column info, used to exchange data with wxListCtrl @@ -237,7 +188,7 @@ public: { // copy list item attributes if ( item.HasAttributes() ) - m_attr = new wxListItemAttr(*item.GetAttributes()); + m_attr = new wxItemAttr(*item.GetAttributes()); } wxListItem& operator=(const wxListItem& item) @@ -254,7 +205,7 @@ public: m_data = item.m_data; m_format = item.m_format; m_width = item.m_width; - m_attr = item.m_attr ? new wxListItemAttr(*item.m_attr) : NULL; + m_attr = item.m_attr ? new wxItemAttr(*item.m_attr) : NULL; } return *this; @@ -310,7 +261,7 @@ public: int GetWidth() const { return m_width; } wxListColumnFormat GetAlign() const { return (wxListColumnFormat)m_format; } - wxListItemAttr *GetAttributes() const { return m_attr; } + wxItemAttr *GetAttributes() const { return m_attr; } bool HasAttributes() const { return m_attr != NULL; } wxColour GetTextColour() const @@ -342,10 +293,10 @@ public: protected: // creates m_attr if we don't have it yet - wxListItemAttr& Attributes() + wxItemAttr& Attributes() { if ( !m_attr ) - m_attr = new wxListItemAttr; + m_attr = new wxItemAttr; return *m_attr; } @@ -364,7 +315,7 @@ protected: m_width = 0; } - wxListItemAttr *m_attr; // optional pointer to the items style + wxItemAttr *m_attr; // optional pointer to the items style private: wxDECLARE_DYNAMIC_CLASS(wxListItem); @@ -443,7 +394,7 @@ public: virtual bool SetColumnWidth(int col, int width) = 0; // return the attribute for the item (may return NULL if none) - virtual wxListItemAttr *OnGetItemAttr(long item) const; + virtual wxItemAttr *OnGetItemAttr(long item) const; // Other miscellaneous accessors. // ------------------------------ @@ -475,7 +426,7 @@ protected: private: // user defined color to draw row lines, may be invalid - wxListItemAttr m_alternateRowColour; + wxItemAttr m_alternateRowColour; }; // ---------------------------------------------------------------------------- diff --git a/include/wx/msw/listctrl.h b/include/wx/msw/listctrl.h index 1b8beaed63..1790454cce 100644 --- a/include/wx/msw/listctrl.h +++ b/include/wx/msw/listctrl.h @@ -402,7 +402,7 @@ protected: // get the item attribute, either by quering it for virtual control, or by // returning the one previously set using setter methods for a normal one - wxListItemAttr *DoGetItemColumnAttr(long item, long column) const; + wxItemAttr *DoGetItemColumnAttr(long item, long column) const; wxTextCtrl* m_textCtrl; // The control used for editing a label @@ -437,7 +437,7 @@ protected: virtual int OnGetItemColumnImage(long item, long column) const; // return the attribute for the given item and column (may return NULL if none) - virtual wxListItemAttr *OnGetItemColumnAttr(long item, long WXUNUSED(column)) const + virtual wxItemAttr *OnGetItemColumnAttr(long item, long WXUNUSED(column)) const { return OnGetItemAttr(item); } diff --git a/include/wx/msw/treectrl.h b/include/wx/msw/treectrl.h index 914cddc395..b9206acfb9 100644 --- a/include/wx/msw/treectrl.h +++ b/include/wx/msw/treectrl.h @@ -34,7 +34,8 @@ class WXDLLIMPEXP_FWD_CORE wxDragImage; struct WXDLLIMPEXP_FWD_CORE wxTreeViewItem; // hash storing attributes for our items -WX_DECLARE_EXPORTED_VOIDPTR_HASH_MAP(wxTreeItemAttr *, wxMapTreeAttr); +class wxItemAttr; +WX_DECLARE_EXPORTED_VOIDPTR_HASH_MAP(wxItemAttr *, wxMapTreeAttr); // ---------------------------------------------------------------------------- // wxTreeCtrl diff --git a/include/wx/qt/listctrl.h b/include/wx/qt/listctrl.h index b534a0128e..3b08104dcc 100644 --- a/include/wx/qt/listctrl.h +++ b/include/wx/qt/listctrl.h @@ -279,7 +279,7 @@ public: virtual int OnGetItemColumnImage(long item, long column) const; // return the attribute for the given item and column (may return NULL if none) - virtual wxListItemAttr *OnGetItemColumnAttr(long item, long WXUNUSED(column)) const + virtual wxItemAttr *OnGetItemColumnAttr(long item, long WXUNUSED(column)) const { return OnGetItemAttr(item); } diff --git a/include/wx/treebase.h b/include/wx/treebase.h index 6ce145f603..f7513bb2ab 100644 --- a/include/wx/treebase.h +++ b/include/wx/treebase.h @@ -180,40 +180,6 @@ static const int wxTREE_HITTEST_ONITEM = wxTREE_HITTEST_ONITEMICON | // tree ctrl default name extern WXDLLIMPEXP_DATA_CORE(const char) wxTreeCtrlNameStr[]; -// ---------------------------------------------------------------------------- -// wxTreeItemAttr: a structure containing the visual attributes of an item -// ---------------------------------------------------------------------------- - -class WXDLLIMPEXP_CORE wxTreeItemAttr -{ -public: - // ctors - wxTreeItemAttr() { } - wxTreeItemAttr(const wxColour& colText, - const wxColour& colBack, - const wxFont& font) - : m_colText(colText), m_colBack(colBack), m_font(font) { } - - // setters - void SetTextColour(const wxColour& colText) { m_colText = colText; } - void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; } - void SetFont(const wxFont& font) { m_font = font; } - - // accessors - bool HasTextColour() const { return m_colText.IsOk(); } - bool HasBackgroundColour() const { return m_colBack.IsOk(); } - bool HasFont() const { return m_font.IsOk(); } - - const wxColour& GetTextColour() const { return m_colText; } - const wxColour& GetBackgroundColour() const { return m_colBack; } - const wxFont& GetFont() const { return m_font; } - -private: - wxColour m_colText, - m_colBack; - wxFont m_font; -}; - // ---------------------------------------------------------------------------- // wxTreeEvent is a special class for all events associated with tree controls // diff --git a/interface/wx/itemattr.h b/interface/wx/itemattr.h new file mode 100644 index 0000000000..49e72bd510 --- /dev/null +++ b/interface/wx/itemattr.h @@ -0,0 +1,82 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wx/itemattr.h +// Purpose: wxItemAttr documentation +// Author: Vadim Zeitlin +// Copyright: (c) 2016 Vadim Zeitlin +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +/** + @class wxItemAttr + + Represents the attributes (color, font, ...) of an item of a control with + multiple items such as e.g. wxListCtrl. + + @library{wxcore} + @category{data} + + @see @ref overview_listctrl + + @since 3.1.1 (previous versions had the identical wxListItemAttr class) +*/ +class wxItemAttr +{ +public: + /** + Default Constructor. + */ + wxItemAttr(); + + /** + Construct a wxItemAttr with the specified foreground and + background colors and font. + */ + wxItemAttr(const wxColour& colText, + const wxColour& colBack, + const wxFont& font); + + /** + Returns the currently set background color. + */ + const wxColour& GetBackgroundColour() const; + + /** + Returns the currently set font. + */ + const wxFont& GetFont() const; + + /** + Returns the currently set text color. + */ + const wxColour& GetTextColour() const; + + /** + Returns @true if the currently set background color is valid. + */ + bool HasBackgroundColour() const; + + /** + Returns @true if the currently set font is valid. + */ + bool HasFont() const; + + /** + Returns @true if the currently set text color is valid. + */ + bool HasTextColour() const; + + /** + Sets a new background color. + */ + void SetBackgroundColour(const wxColour& colour); + + /** + Sets a new font. + */ + void SetFont(const wxFont& font); + + /** + Sets a new text color. + */ + void SetTextColour(const wxColour& colour); +}; diff --git a/interface/wx/listctrl.h b/interface/wx/listctrl.h index cfe47e97df..c1538bfd1c 100644 --- a/interface/wx/listctrl.h +++ b/interface/wx/listctrl.h @@ -1278,14 +1278,14 @@ protected: @c item or @NULL to use the default appearance parameters. wxListCtrl will not delete the pointer or keep a reference of it. - You can return the same wxListItemAttr pointer for every OnGetItemAttr() call. + You can return the same wxItemAttr pointer for every OnGetItemAttr() call. The base class version always returns @NULL. @see OnGetItemImage(), OnGetItemColumnImage(), OnGetItemText(), OnGetItemColumnAttr() */ - virtual wxListItemAttr* OnGetItemAttr(long item) const; + virtual wxItemAttr* OnGetItemAttr(long item) const; /** This function may be overridden in the derived class for a control with @@ -1302,7 +1302,7 @@ protected: @see OnGetItemAttr(), OnGetItemText(), OnGetItemImage(), OnGetItemColumnImage(), */ - virtual wxListItemAttr* OnGetItemColumnAttr(long item, long column) const; + virtual wxItemAttr* OnGetItemColumnAttr(long item, long column) const; /** Override this function in the derived class for a control with @@ -1513,80 +1513,6 @@ wxEventType wxEVT_LIST_ITEM_CHECKED; wxEventType wxEVT_LIST_ITEM_UNCHECKED; -/** - @class wxListItemAttr - - Represents the attributes (color, font, ...) of a wxListCtrl's wxListItem. - - @library{wxcore} - @category{data} - - @see @ref overview_listctrl, wxListCtrl, wxListItem -*/ -class wxListItemAttr -{ -public: - /** - Default Constructor. - */ - wxListItemAttr(); - - /** - Construct a wxListItemAttr with the specified foreground and - background colors and font. - */ - wxListItemAttr(const wxColour& colText, - const wxColour& colBack, - const wxFont& font); - - /** - Returns the currently set background color. - */ - const wxColour& GetBackgroundColour() const; - - /** - Returns the currently set font. - */ - const wxFont& GetFont() const; - - /** - Returns the currently set text color. - */ - const wxColour& GetTextColour() const; - - /** - Returns @true if the currently set background color is valid. - */ - bool HasBackgroundColour() const; - - /** - Returns @true if the currently set font is valid. - */ - bool HasFont() const; - - /** - Returns @true if the currently set text color is valid. - */ - bool HasTextColour() const; - - /** - Sets a new background color. - */ - void SetBackgroundColour(const wxColour& colour); - - /** - Sets a new font. - */ - void SetFont(const wxFont& font); - - /** - Sets a new text color. - */ - void SetTextColour(const wxColour& colour); -}; - - - /** @class wxListView diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index c96eab1366..e839398409 100644 --- a/samples/listctrl/listtest.cpp +++ b/samples/listctrl/listtest.cpp @@ -1226,7 +1226,7 @@ void MyListCtrl::OnListKeyDown(wxListEvent& event) GetItem(info); - wxListItemAttr *attr = info.GetAttributes(); + wxItemAttr *attr = info.GetAttributes(); if ( !attr || !attr->HasTextColour() ) { info.SetTextColour(*wxCYAN); @@ -1416,13 +1416,13 @@ int MyListCtrl::OnGetItemColumnImage(long item, long column) const return -1; } -wxListItemAttr *MyListCtrl::OnGetItemAttr(long item) const +wxItemAttr *MyListCtrl::OnGetItemAttr(long item) const { // test to check that RefreshItem() works correctly: when m_updated is // set to some item and it is refreshed, we highlight the item if ( item == m_updated ) { - static wxListItemAttr s_attrHighlight(*wxRED, wxNullColour, wxNullFont); + static wxItemAttr s_attrHighlight(*wxRED, wxNullColour, wxNullFont); return &s_attrHighlight; } diff --git a/samples/listctrl/listtest.h b/samples/listctrl/listtest.h index f1f21b5b9a..7494dfec97 100644 --- a/samples/listctrl/listtest.h +++ b/samples/listctrl/listtest.h @@ -84,7 +84,7 @@ private: virtual wxString OnGetItemText(long item, long column) const wxOVERRIDE; virtual int OnGetItemColumnImage(long item, long column) const wxOVERRIDE; - virtual wxListItemAttr *OnGetItemAttr(long item) const wxOVERRIDE; + virtual wxItemAttr *OnGetItemAttr(long item) const wxOVERRIDE; long m_updated; diff --git a/src/common/listctrlcmn.cpp b/src/common/listctrlcmn.cpp index 25f29b8042..518718e94f 100644 --- a/src/common/listctrlcmn.cpp +++ b/src/common/listctrlcmn.cpp @@ -244,10 +244,10 @@ void wxListCtrlBase::EnableAlternateRowColours(bool enable) } } -wxListItemAttr *wxListCtrlBase::OnGetItemAttr(long item) const +wxItemAttr *wxListCtrlBase::OnGetItemAttr(long item) const { return (m_alternateRowColour.GetBackgroundColour().IsOk() && (item % 2)) - ? wxConstCast(&m_alternateRowColour, wxListItemAttr) + ? wxConstCast(&m_alternateRowColour, wxItemAttr) : NULL; // no attributes by default } diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index ef7aa27c6c..a3813d0323 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -168,7 +168,7 @@ void wxListItemData::SetItem( const wxListItem &info ) if ( m_attr ) m_attr->AssignFrom(*info.GetAttributes()); else - m_attr = new wxListItemAttr(*info.GetAttributes()); + m_attr = new wxItemAttr(*info.GetAttributes()); } if ( m_rect ) @@ -654,7 +654,7 @@ int wxListLineData::GetImage( int index ) const return item->GetImage(); } -wxListItemAttr *wxListLineData::GetAttr() const +wxItemAttr *wxListLineData::GetAttr() const { wxListItemDataList::compatibility_iterator node = m_items.GetFirst(); wxCHECK_MSG( node, NULL, wxT("invalid column index in GetAttr()") ); @@ -663,7 +663,7 @@ wxListItemAttr *wxListLineData::GetAttr() const return item->GetAttr(); } -void wxListLineData::SetAttr(wxListItemAttr *attr) +void wxListLineData::SetAttr(wxItemAttr *attr) { wxListItemDataList::compatibility_iterator node = m_items.GetFirst(); wxCHECK_RET( node, wxT("invalid column index in SetAttr()") ); @@ -677,7 +677,7 @@ void wxListLineData::ApplyAttributes(wxDC *dc, bool highlighted, bool current) { - const wxListItemAttr * const attr = GetAttr(); + const wxItemAttr * const attr = GetAttr(); wxWindow * const listctrl = m_owner->GetParent(); diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index 1aeac569fd..f45fca5e24 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -37,6 +37,7 @@ #include "wx/generic/treectlg.h" #include "wx/imaglist.h" +#include "wx/itemattr.h" #include "wx/renderer.h" @@ -223,7 +224,7 @@ public: { wxFont font; - wxTreeItemAttr * const attr = GetAttributes(); + wxItemAttr * const attr = GetAttributes(); if ( attr && attr->HasFont() ) font = attr->GetFont(); else if ( IsBold() ) @@ -282,19 +283,19 @@ public: // attributes // get them - may be NULL - wxTreeItemAttr *GetAttributes() const { return m_attr; } + wxItemAttr *GetAttributes() const { return m_attr; } // get them ensuring that the pointer is not NULL - wxTreeItemAttr& Attr() + wxItemAttr& Attr() { if ( !m_attr ) { - m_attr = new wxTreeItemAttr; + m_attr = new wxItemAttr; m_ownsAttr = true; } return *m_attr; } // set them - void SetAttributes(wxTreeItemAttr *attr) + void SetAttributes(wxItemAttr *attr) { if ( m_ownsAttr ) delete m_attr; m_attr = attr; @@ -303,7 +304,7 @@ public: m_widthText = -1; } // set them and delete when done - void AssignAttributes(wxTreeItemAttr *attr) + void AssignAttributes(wxItemAttr *attr) { SetAttributes(attr); m_ownsAttr = true; @@ -335,7 +336,7 @@ private: wxArrayGenericTreeItems m_children; // list of children wxGenericTreeItem *m_parent; // parent of this item - wxTreeItemAttr *m_attr; // attributes??? + wxItemAttr *m_attr; // attributes??? // tree ctrl images for the normal, selected, expanded and // expanded+selected states @@ -2554,7 +2555,7 @@ void wxGenericTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc) else { wxColour colBg; - wxTreeItemAttr * const attr = item->GetAttributes(); + wxItemAttr * const attr = item->GetAttributes(); if ( attr && attr->HasBackgroundColour() ) { drawItemBackground = @@ -2789,7 +2790,7 @@ wxGenericTreeCtrl::PaintLevel(wxGenericTreeItem *item, } else { - wxTreeItemAttr *attr = item->GetAttributes(); + wxItemAttr *attr = item->GetAttributes(); if (attr && attr->HasTextColour()) colText = attr->GetTextColour(); else diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index 2b2e42d79e..450fee8cda 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -198,7 +198,7 @@ private: /////////////////////////////////////////////////////// // Problem: // The MSW version had problems with SetTextColour() et -// al as the wxListItemAttr's were stored keyed on the +// al as the wxItemAttr's were stored keyed on the // item index. If a item was inserted anywhere but the end // of the list the text attributes (colour etc) for // the following items were out of sync. @@ -223,7 +223,7 @@ public: wxMSWListItemData() : attr(NULL), lParam(0) {} ~wxMSWListItemData() { delete attr; } - wxListItemAttr *attr; + wxItemAttr *attr; LPARAM lParam; // real user data wxDECLARE_NO_COPY_CLASS(wxMSWListItemData); @@ -811,13 +811,13 @@ bool wxListCtrl::SetItem(wxListItem& info) // attributes if ( info.HasAttributes() ) { - const wxListItemAttr& attrNew = *info.GetAttributes(); + const wxItemAttr& attrNew = *info.GetAttributes(); // don't overwrite the already set attributes if we have them if ( data->attr ) data->attr->AssignFrom(attrNew); else - data->attr = new wxListItemAttr(attrNew); + data->attr = new wxItemAttr(attrNew); } } @@ -1754,7 +1754,7 @@ long wxListCtrl::InsertItem(const wxListItem& info) if ( info.HasAttributes() ) { // take copy of attributes - data->attr = new wxListItemAttr(*info.GetAttributes()); + data->attr = new wxItemAttr(*info.GetAttributes()); // and remember that we have some now... m_hasAnyAttr = true; @@ -2858,7 +2858,7 @@ static void HandleItemPaint(LPNMLVCUSTOMDRAW pLVCD, HFONT hfont) static WXLPARAM HandleItemPrepaint(wxListCtrl *listctrl, LPNMLVCUSTOMDRAW pLVCD, - wxListItemAttr *attr) + wxItemAttr *attr) { if ( !attr ) { @@ -3103,7 +3103,7 @@ int wxListCtrl::OnGetItemColumnImage(long item, long column) const return -1; } -wxListItemAttr *wxListCtrl::DoGetItemColumnAttr(long item, long column) const +wxItemAttr *wxListCtrl::DoGetItemColumnAttr(long item, long column) const { if ( IsVirtual() ) return OnGetItemColumnAttr(item, column); diff --git a/src/msw/treectrl.cpp b/src/msw/treectrl.cpp index a2dc9138b4..25ca687277 100644 --- a/src/msw/treectrl.cpp +++ b/src/msw/treectrl.cpp @@ -39,6 +39,7 @@ #include "wx/msw/private.h" #include "wx/imaglist.h" +#include "wx/itemattr.h" #include "wx/msw/dragimag.h" #include "wx/msw/uxtheme.h" @@ -1146,14 +1147,14 @@ void wxTreeCtrl::SetItemTextColour(const wxTreeItemId& item, { wxCHECK_RET( item.IsOk(), wxT("invalid tree item") ); - wxTreeItemAttr *attr; + wxItemAttr *attr; wxMapTreeAttr::iterator it = m_attrs.find(item.m_pItem); if ( it == m_attrs.end() ) { m_hasAnyAttr = true; m_attrs[item.m_pItem] = - attr = new wxTreeItemAttr; + attr = new wxItemAttr; } else { @@ -1170,14 +1171,14 @@ void wxTreeCtrl::SetItemBackgroundColour(const wxTreeItemId& item, { wxCHECK_RET( item.IsOk(), wxT("invalid tree item") ); - wxTreeItemAttr *attr; + wxItemAttr *attr; wxMapTreeAttr::iterator it = m_attrs.find(item.m_pItem); if ( it == m_attrs.end() ) { m_hasAnyAttr = true; m_attrs[item.m_pItem] = - attr = new wxTreeItemAttr; + attr = new wxItemAttr; } else // already in the hash { @@ -1193,14 +1194,14 @@ void wxTreeCtrl::SetItemFont(const wxTreeItemId& item, const wxFont& font) { wxCHECK_RET( item.IsOk(), wxT("invalid tree item") ); - wxTreeItemAttr *attr; + wxItemAttr *attr; wxMapTreeAttr::iterator it = m_attrs.find(item.m_pItem); if ( it == m_attrs.end() ) { m_hasAnyAttr = true; m_attrs[item.m_pItem] = - attr = new wxTreeItemAttr; + attr = new wxItemAttr; } else // already in the hash { @@ -3550,7 +3551,7 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) break; } - wxTreeItemAttr * const attr = it->second; + wxItemAttr * const attr = it->second; wxTreeViewItem tvItem((void *)nmcd.dwItemSpec, TVIF_STATE, TVIS_DROPHILITED); From 64196306bc618c73d0badd75916c4013ae7cd281 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 17 Apr 2016 16:01:11 +0200 Subject: [PATCH 03/10] 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" > + + From c15f75b81dc36df77063120af6886ff8ff24ba2b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 17 Apr 2016 16:04:45 +0200 Subject: [PATCH 04/10] 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; } From e84053ed641b8d3634662faef53a0b7803f6a11b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 17 Apr 2016 17:19:20 +0200 Subject: [PATCH 05/10] Add wxItemAttr::HasColours() and IsDefault() accessors They are trivial but useful to have as testing for HasBackgroundColour() || HasTextColour() || HasFont() is too verbose. --- include/wx/itemattr.h | 3 +++ interface/wx/itemattr.h | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/wx/itemattr.h b/include/wx/itemattr.h index 90ae149d85..3a77cdaded 100644 --- a/include/wx/itemattr.h +++ b/include/wx/itemattr.h @@ -39,6 +39,9 @@ public: bool HasBackgroundColour() const { return m_colBack.IsOk(); } bool HasFont() const { return m_font.IsOk(); } + bool HasColours() const { return HasTextColour() || HasBackgroundColour(); } + bool IsDefault() const { return !HasColours() && !HasFont(); } + const wxColour& GetTextColour() const { return m_colText; } const wxColour& GetBackgroundColour() const { return m_colBack; } const wxFont& GetFont() const { return m_font; } diff --git a/interface/wx/itemattr.h b/interface/wx/itemattr.h index 49e72bd510..d47c618e68 100644 --- a/interface/wx/itemattr.h +++ b/interface/wx/itemattr.h @@ -17,7 +17,7 @@ @see @ref overview_listctrl - @since 3.1.1 (previous versions had the identical wxListItemAttr class) + @since 3.1.1 (previous versions had a similar wxListItemAttr class) */ class wxItemAttr { @@ -55,6 +55,13 @@ public: */ bool HasBackgroundColour() const; + /** + Returns @true if either text or background colour is set. + + @see HasBackgroundColour(), HasTextColour() + */ + bool HasColours() const; + /** Returns @true if the currently set font is valid. */ @@ -65,6 +72,11 @@ public: */ bool HasTextColour() const; + /** + Returns @true if this object has no custom attributes set. + */ + bool IsDefault() const; + /** Sets a new background color. */ From c17f1d7888cd319cf9879628831ff75a246efa27 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 17 Apr 2016 17:20:47 +0200 Subject: [PATCH 06/10] Consistently use British "colour" spelling in wxItemAttr documentation The methods of this class use "Colour", not "Color", so use "colour" and not "color" when documenting them too. --- interface/wx/itemattr.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/interface/wx/itemattr.h b/interface/wx/itemattr.h index d47c618e68..518e0426ed 100644 --- a/interface/wx/itemattr.h +++ b/interface/wx/itemattr.h @@ -9,7 +9,7 @@ /** @class wxItemAttr - Represents the attributes (color, font, ...) of an item of a control with + Represents the attributes (colour, font, ...) of an item of a control with multiple items such as e.g. wxListCtrl. @library{wxcore} @@ -29,14 +29,14 @@ public: /** Construct a wxItemAttr with the specified foreground and - background colors and font. + background colours and font. */ wxItemAttr(const wxColour& colText, const wxColour& colBack, const wxFont& font); /** - Returns the currently set background color. + Returns the currently set background colour. */ const wxColour& GetBackgroundColour() const; @@ -46,12 +46,12 @@ public: const wxFont& GetFont() const; /** - Returns the currently set text color. + Returns the currently set text colour. */ const wxColour& GetTextColour() const; /** - Returns @true if the currently set background color is valid. + Returns @true if the currently set background colour is valid. */ bool HasBackgroundColour() const; @@ -68,7 +68,7 @@ public: bool HasFont() const; /** - Returns @true if the currently set text color is valid. + Returns @true if the currently set text colour is valid. */ bool HasTextColour() const; @@ -78,7 +78,7 @@ public: bool IsDefault() const; /** - Sets a new background color. + Sets a new background colour. */ void SetBackgroundColour(const wxColour& colour); @@ -88,7 +88,7 @@ public: void SetFont(const wxFont& font); /** - Sets a new text color. + Sets a new text colour. */ void SetTextColour(const wxColour& colour); }; From dfb993274c2efc85daeaf1c054ea010abb33795f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 17 Apr 2016 17:36:20 +0200 Subject: [PATCH 07/10] Add equality operators to wxItemAttr It can be necessary to compare two item attributes for equality, e.g. to check if the attributes have changed, so provide a straightforward implementation of equality and inequality operator for it. --- include/wx/itemattr.h | 11 +++++++++++ interface/wx/itemattr.h | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/wx/itemattr.h b/include/wx/itemattr.h index 3a77cdaded..596cb2bab8 100644 --- a/include/wx/itemattr.h +++ b/include/wx/itemattr.h @@ -28,6 +28,17 @@ public: // default copy ctor, assignment operator and dtor are ok + bool operator==(const wxItemAttr& other) const + { + return m_colText == other.m_colText && + m_colBack == other.m_colBack && + m_font == other.m_font; + } + + bool operator!=(const wxItemAttr& other) const + { + return !(*this == other); + } // setters void SetTextColour(const wxColour& colText) { m_colText = colText; } diff --git a/interface/wx/itemattr.h b/interface/wx/itemattr.h index 518e0426ed..041bb2c37e 100644 --- a/interface/wx/itemattr.h +++ b/interface/wx/itemattr.h @@ -35,6 +35,16 @@ public: const wxColour& colBack, const wxFont& font); + /** + Compare two item attributes for equality. + */ + bool operator==(const wxItemAttr& other) const; + + /** + Compare two item attributes for inequality. + */ + bool operator!=(const wxItemAttr& other) const; + /** Returns the currently set background colour. */ From 5388c7a72e6ea724545c04ba606d5570ecfc78b8 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 17 Apr 2016 17:43:09 +0200 Subject: [PATCH 08/10] Add wxListCtrl::SetHeaderAttr() This method can be used to change the list view header appearance. Add the method declaration, documentation, show it in the sample and implement it for wxMSW (only, for now). --- docs/changes.txt | 1 + include/wx/listbase.h | 3 + include/wx/msw/listctrl.h | 8 +++ interface/wx/listctrl.h | 19 +++++++ samples/listctrl/listtest.cpp | 17 ++++++ samples/listctrl/listtest.h | 2 + src/msw/listctrl.cpp | 104 ++++++++++++++++++++++++++++++++++ 7 files changed, 154 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index 8bf63bcef4..874ae50525 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -71,6 +71,7 @@ All (GUI): - Add support for wxSL_MIN_MAX_LABELS and wxSL_VALUE_LABEL to XRC (ousnius). - Update Scintilla to v3.6.3 (Paul Kulchenko). - Make wxDataViewCtrl::Expand() expand ancestors in native ports too. +- Add wxListCtrl::SetHeaderAttr(). wxGTK: diff --git a/include/wx/listbase.h b/include/wx/listbase.h index 841b4c00fa..221052ac8b 100644 --- a/include/wx/listbase.h +++ b/include/wx/listbase.h @@ -411,6 +411,9 @@ public: void SetAlternateRowColour(const wxColour& colour); wxColour GetAlternateRowColour() const { return m_alternateRowColour.GetBackgroundColour(); } + // Header attributes support: only implemented in wxMSW currently. + virtual bool SetHeaderAttr(const wxItemAttr& WXUNUSED(attr)) { return false; } + // Checkboxes support: only implemented in wxMSW currently. virtual bool HasCheckboxes() const { return false; } virtual bool EnableCheckboxes(bool WXUNUSED(enable) = true) { return false; } diff --git a/include/wx/msw/listctrl.h b/include/wx/msw/listctrl.h index 1790454cce..95e2e883b2 100644 --- a/include/wx/msw/listctrl.h +++ b/include/wx/msw/listctrl.h @@ -16,6 +16,7 @@ #include "wx/vector.h" class wxMSWListItemData; +class wxMSWListHeaderCustomDraw; // define this symbol to indicate the availability of SetColumnsOrder() and // related functions @@ -115,6 +116,9 @@ public: bool SetForegroundColour(const wxColour& col); bool SetBackgroundColour(const wxColour& col); + // Header attributes + virtual bool SetHeaderAttr(const wxItemAttr& attr) wxOVERRIDE; + // Gets information about this column bool GetColumn(int col, wxListItem& item) const; @@ -461,6 +465,10 @@ private: void OnCharHook(wxKeyEvent& event); + // Object using for header custom drawing if necessary, may be NULL. + wxMSWListHeaderCustomDraw* m_headerCustomDraw; + + wxDECLARE_DYNAMIC_CLASS(wxListCtrl); wxDECLARE_EVENT_TABLE(); wxDECLARE_NO_COPY_CLASS(wxListCtrl); diff --git a/interface/wx/listctrl.h b/interface/wx/listctrl.h index c1538bfd1c..022743c8a6 100644 --- a/interface/wx/listctrl.h +++ b/interface/wx/listctrl.h @@ -1052,6 +1052,25 @@ public: */ bool SetColumnsOrder(const wxArrayInt& orders); + /** + Change the font and the colours used for the list control header. + + This method can be used to change the appearance of the header shown by + the control in report mode (unless @c wxLC_NO_HEADER style is used). + + Currently it is implemented only for wxMSW and does nothing in the + other ports. + + @param attr The object containing the font and text and background + colours to use. It may be default, i.e. not specify any custom font + nor colours, to reset any previously set custom attribute. + @return @true if the attributes have been updated or @false if this is + not supported by the current platform. + + @since 3.1.1 + */ + bool SetHeaderAttr(const wxItemAttr& attr); + /** Sets the image list associated with the control. diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index e839398409..abb07423c0 100644 --- a/samples/listctrl/listtest.cpp +++ b/samples/listctrl/listtest.cpp @@ -137,6 +137,7 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(LIST_SET_FG_COL, MyFrame::OnSetFgColour) EVT_MENU(LIST_SET_BG_COL, MyFrame::OnSetBgColour) EVT_MENU(LIST_ROW_LINES, MyFrame::OnSetRowLines) + EVT_MENU(LIST_CUSTOM_HEADER_ATTR, MyFrame::OnCustomHeaderAttr) EVT_MENU(LIST_TOGGLE_MULTI_SEL, MyFrame::OnToggleMultiSel) EVT_MENU(LIST_SHOW_COL_INFO, MyFrame::OnShowColInfo) EVT_MENU(LIST_SHOW_SEL_INFO, MyFrame::OnShowSelInfo) @@ -160,6 +161,7 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_UPDATE_UI(LIST_SHOW_COL_INFO, MyFrame::OnUpdateUIEnableInReport) EVT_UPDATE_UI(LIST_TOGGLE_HEADER, MyFrame::OnUpdateUIEnableInReport) + EVT_UPDATE_UI(LIST_CUSTOM_HEADER_ATTR, MyFrame::OnUpdateUIEnableInReport) EVT_UPDATE_UI(LIST_TOGGLE_MULTI_SEL, MyFrame::OnUpdateToggleMultiSel) EVT_UPDATE_UI(LIST_TOGGLE_CHECKBOXES, MyFrame::OnUpdateToggleCheckboxes) @@ -276,6 +278,7 @@ MyFrame::MyFrame(const wxChar *title) menuCol->Append(LIST_SET_FG_COL, wxT("&Foreground colour...")); menuCol->Append(LIST_SET_BG_COL, wxT("&Background colour...")); menuCol->AppendCheckItem(LIST_ROW_LINES, wxT("Alternating colours")); + menuCol->AppendCheckItem(LIST_CUSTOM_HEADER_ATTR, "&Custom header attributes"); wxMenuBar *menubar = new wxMenuBar; menubar->Append(menuFile, wxT("&File")); @@ -894,6 +897,20 @@ void MyFrame::OnSetRowLines(wxCommandEvent& event) m_listCtrl->Refresh(); } +void MyFrame::OnCustomHeaderAttr(wxCommandEvent& event) +{ + wxItemAttr attr; + if ( event.IsChecked() ) + { + attr.SetTextColour(*wxBLUE); + attr.SetFont(wxFontInfo(24).Italic()); + } + //else: leave it as default to disable custom header attributes + + if ( !m_listCtrl->SetHeaderAttr(attr) ) + wxLogMessage("Sorry, header attributes not supported on this platform"); +} + void MyFrame::OnAdd(wxCommandEvent& WXUNUSED(event)) { m_listCtrl->InsertItem(m_listCtrl->GetItemCount(), wxT("Appended item")); diff --git a/samples/listctrl/listtest.h b/samples/listctrl/listtest.h index 7494dfec97..be4e8adc3f 100644 --- a/samples/listctrl/listtest.h +++ b/samples/listctrl/listtest.h @@ -132,6 +132,7 @@ protected: void OnSetFgColour(wxCommandEvent& event); void OnSetBgColour(wxCommandEvent& event); void OnSetRowLines(wxCommandEvent& event); + void OnCustomHeaderAttr(wxCommandEvent& event); void OnToggleMultiSel(wxCommandEvent& event); void OnShowColInfo(wxCommandEvent& event); void OnShowSelInfo(wxCommandEvent& event); @@ -221,6 +222,7 @@ enum LIST_SET_FG_COL, LIST_SET_BG_COL, LIST_ROW_LINES, + LIST_CUSTOM_HEADER_ATTR, LIST_TOGGLE_MULTI_SEL, LIST_TOGGLE_HEADER, LIST_TOGGLE_BELL, diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index 450fee8cda..6a04fe2da3 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -42,6 +42,7 @@ #include "wx/vector.h" #include "wx/msw/private.h" +#include "wx/msw/private/customdraw.h" #include "wx/msw/private/keyboard.h" // Currently gcc doesn't define NMLVFINDITEM, and DMC only defines @@ -229,6 +230,34 @@ public: wxDECLARE_NO_COPY_CLASS(wxMSWListItemData); }; +// wxMSWListHeaderCustomDraw: custom draw helper for the header +class wxMSWListHeaderCustomDraw : public wxMSWImpl::CustomDraw +{ +public: + wxMSWListHeaderCustomDraw() + { + } + + // Make this field public to let wxListCtrl update it directly when its + // header 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; + } +}; + + wxBEGIN_EVENT_TABLE(wxListCtrl, wxListCtrlBase) EVT_PAINT(wxListCtrl::OnPaint) EVT_CHAR_HOOK(wxListCtrl::OnCharHook) @@ -255,6 +284,8 @@ void wxListCtrl::Init() m_textCtrl = NULL; m_hasAnyAttr = false; + + m_headerCustomDraw = NULL; } bool wxListCtrl::Create(wxWindow *parent, @@ -434,6 +465,8 @@ wxListCtrl::~wxListCtrl() delete m_imageListSmall; if (m_ownsImageListState) delete m_imageListState; + + delete m_headerCustomDraw; } // ---------------------------------------------------------------------------- @@ -520,6 +553,68 @@ bool wxListCtrl::SetBackgroundColour(const wxColour& col) return true; } +bool wxListCtrl::SetHeaderAttr(const wxItemAttr& attr) +{ + // We need to propagate the change of the font to the native header window + // as it also affects its layout. + bool fontChanged; + + // Start or stop custom drawing the header. + if ( attr.IsDefault() ) + { + if ( !m_headerCustomDraw ) + { + // Nothing changed, skip refreshing the control below. + return true; + } + + fontChanged = m_headerCustomDraw->m_attr.HasFont(); + + delete m_headerCustomDraw; + m_headerCustomDraw = NULL; + } + else // We do have custom attributes. + { + if ( !m_headerCustomDraw ) + m_headerCustomDraw = new wxMSWListHeaderCustomDraw(); + + if ( m_headerCustomDraw->m_attr == attr ) + { + // As above, skip refresh. + return true; + } + + fontChanged = attr.GetFont() != m_headerCustomDraw->m_attr.GetFont(); + + m_headerCustomDraw->m_attr = attr; + } + + if ( HWND hwndHdr = ListView_GetHeader(GetHwnd()) ) + { + if ( fontChanged ) + { + // Don't just reset the font if no font is specified, as the header + // uses the same font as the listview control and not the ugly + // default GUI font by default. + const wxFont& font = attr.HasFont() ? attr.GetFont() : GetFont(); + + // We need to tell the header about its new font to let it compute + // its new height. + ::SendMessage(hwndHdr, WM_SETFONT, + (WPARAM)GetHfontOf(font), MAKELPARAM(TRUE, 0)); + } + + // Refreshing the listview makes it notice the change in height of its + // header and redraws it too. We probably could do something less than + // a full refresh, but it doesn't seem to be worth it, the header + // attributes won't be changed that often, so keep it simple for now. + Refresh(); + } + //else: header not shown or not in report view? + + return true; +} + // Gets information about this column bool wxListCtrl::GetColumn(int col, wxListItem& item) const { @@ -2085,6 +2180,15 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) // doesn't seem to have any negative consequences return true; + case NM_CUSTOMDRAW: + if ( m_headerCustomDraw ) + { + *result = m_headerCustomDraw->HandleCustomDraw(lParam); + if ( *result != CDRF_DODEFAULT ) + return true; + } + wxFALLTHROUGH; + default: ignore = true; } From bed7d9fe741d2dead09be41c790f4e129f96bd97 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 22 Apr 2016 00:58:38 +0200 Subject: [PATCH 09/10] Add wxDataViewCtrl::SetHeaderAttr() too This is currently only implemented in the generic version but could be implemented at least for GTK+ native one as well in the future. --- docs/changes.txt | 1 + include/wx/dataview.h | 7 ++++++- include/wx/generic/dataview.h | 2 ++ interface/wx/dataview.h | 19 +++++++++++++++++++ samples/dataview/dataview.cpp | 20 ++++++++++++++++++++ src/generic/datavgen.cpp | 19 +++++++++++++++++++ 6 files changed, 67 insertions(+), 1 deletion(-) diff --git a/docs/changes.txt b/docs/changes.txt index 874ae50525..674d97d92e 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -71,6 +71,7 @@ All (GUI): - Add support for wxSL_MIN_MAX_LABELS and wxSL_VALUE_LABEL to XRC (ousnius). - Update Scintilla to v3.6.3 (Paul Kulchenko). - Make wxDataViewCtrl::Expand() expand ancestors in native ports too. +- Add wxDataViewCtrl::SetHeaderAttr(). - Add wxListCtrl::SetHeaderAttr(). wxGTK: diff --git a/include/wx/dataview.h b/include/wx/dataview.h index 3b8bc71e25..8349a29082 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -29,6 +29,7 @@ #include "wx/systhemectrl.h" class WXDLLIMPEXP_FWD_CORE wxImageList; +class WXDLLIMPEXP_FWD_CORE wxItemAttr; #if !(defined(__WXGTK20__) || defined(__WXOSX__) ) || defined(__WXUNIVERSAL__) // #if !(defined(__WXOSX__)) || defined(__WXUNIVERSAL__) @@ -128,7 +129,7 @@ private: // wxDataViewItemAttr: a structure containing the visual attributes of an item // ---------------------------------------------------------------------------- -// TODO: this should be renamed to wxItemAttr or something general like this +// TODO: Merge with wxItemAttr somehow. class WXDLLIMPEXP_ADV wxDataViewItemAttr { @@ -732,6 +733,10 @@ public: // define control visual attributes // -------------------------------- + // Header attributes: only implemented in the generic version currently. + virtual bool SetHeaderAttr(const wxItemAttr& WXUNUSED(attr)) + { return false; } + virtual wxVisualAttributes GetDefaultAttributes() const wxOVERRIDE { return GetClassDefaultAttributes(GetWindowVariant()); diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index 224f90f166..1f742e63c7 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -256,6 +256,8 @@ public: virtual void EditItem(const wxDataViewItem& item, const wxDataViewColumn *column) wxOVERRIDE; + virtual bool SetHeaderAttr(const wxItemAttr& attr) wxOVERRIDE; + // These methods are specific to generic wxDataViewCtrl implementation and // should not be used in portable code. wxColour GetAlternateRowColour() const { return m_alternateRowColour; } diff --git a/interface/wx/dataview.h b/interface/wx/dataview.h index a4a9362fbe..2c29c76049 100644 --- a/interface/wx/dataview.h +++ b/interface/wx/dataview.h @@ -1547,6 +1547,25 @@ public: */ void SetCurrentItem(const wxDataViewItem& item); + /** + Set custom colours and/or font to use for the header. + + This method allows to customize the display of the control header (it + does nothing if @c wxDV_NO_HEADER style is used). + + Currently it is only implemented in the generic version and just + returns @false without doing anything elsewhere. + + @param attr The attribute defining the colour(s) and font to use. It + can be default, in which case the attributes are reset to their + default values. + @return @true if the attributes were updated, @false if the method is + not implemented or failed. + + @since 3.1.1 + */ + bool SetHeaderAttr(const wxItemAttr& attr); + /** Sets the indentation. */ diff --git a/samples/dataview/dataview.cpp b/samples/dataview/dataview.cpp index a51a3146e6..89f0d66367 100644 --- a/samples/dataview/dataview.cpp +++ b/samples/dataview/dataview.cpp @@ -32,6 +32,7 @@ #include "wx/numdlg.h" #include "wx/spinctrl.h" #include "wx/imaglist.h" +#include "wx/itemattr.h" #include "wx/notebook.h" #include "mymodels.h" @@ -74,6 +75,7 @@ private: // event handlers void OnStyleChange(wxCommandEvent& event); void OnSetBackgroundColour(wxCommandEvent& event); + void OnCustomHeaderAttr(wxCommandEvent& event); void OnSetForegroundColour(wxCommandEvent& event); void OnIncIndent(wxCommandEvent& event); void OnDecIndent(wxCommandEvent& event); @@ -290,6 +292,7 @@ enum ID_CLEARLOG = wxID_HIGHEST+1, ID_BACKGROUND_COLOUR, ID_FOREGROUND_COLOUR, + ID_CUSTOM_HEADER_ATTR, ID_STYLE_MENU, ID_INC_INDENT, ID_DEC_INDENT, @@ -344,6 +347,7 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU( ID_FOREGROUND_COLOUR, MyFrame::OnSetForegroundColour ) EVT_MENU( ID_BACKGROUND_COLOUR, MyFrame::OnSetBackgroundColour ) + EVT_MENU( ID_CUSTOM_HEADER_ATTR, MyFrame::OnCustomHeaderAttr ) EVT_MENU( ID_INC_INDENT, MyFrame::OnIncIndent ) EVT_MENU( ID_DEC_INDENT, MyFrame::OnDecIndent ) @@ -431,6 +435,7 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int file_menu->Append(ID_CLEARLOG, "&Clear log\tCtrl-L"); file_menu->Append(ID_FOREGROUND_COLOUR, "Set &foreground colour...\tCtrl-S"); file_menu->Append(ID_BACKGROUND_COLOUR, "Set &background colour...\tCtrl-B"); + file_menu->AppendCheckItem(ID_CUSTOM_HEADER_ATTR, "C&ustom header attributes"); file_menu->Append(ID_STYLE_MENU, "&Style", style_menu); file_menu->Append(ID_INC_INDENT, "&Increase indent\tCtrl-I"); file_menu->Append(ID_DEC_INDENT, "&Decrease indent\tShift-Ctrl-I"); @@ -788,6 +793,21 @@ void MyFrame::OnSetBackgroundColour(wxCommandEvent& WXUNUSED(event)) } } +void MyFrame::OnCustomHeaderAttr(wxCommandEvent& event) +{ + wxItemAttr attr; + if ( event.IsChecked() ) + { + attr.SetTextColour(*wxRED); + attr.SetFont(wxFontInfo(20).Bold()); + } + //else: leave it as default to disable custom header attributes + + wxDataViewCtrl * const dvc = m_ctrl[m_notebook->GetSelection()]; + if ( !dvc->SetHeaderAttr(attr) ) + wxLogMessage("Sorry, header attributes not supported on this platform"); +} + void MyFrame::OnIncIndent(wxCommandEvent& WXUNUSED(event)) { wxDataViewCtrl * const dvc = m_ctrl[m_notebook->GetSelection()]; diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 41f4403240..90c921b5b5 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -41,6 +41,7 @@ #include "wx/renderer.h" #include "wx/dcbuffer.h" #include "wx/icon.h" +#include "wx/itemattr.h" #include "wx/list.h" #include "wx/listimpl.cpp" #include "wx/imaglist.h" @@ -5202,6 +5203,24 @@ bool wxDataViewCtrl::IsSelected( const wxDataViewItem & item ) const return false; } +bool wxDataViewCtrl::SetHeaderAttr(const wxItemAttr& attr) +{ + if ( !m_headerArea ) + return false; + + // Call all functions unconditionally to reset the previously set + // attributes, if any. + m_headerArea->SetForegroundColour(attr.GetTextColour()); + m_headerArea->SetBackgroundColour(attr.GetBackgroundColour()); + m_headerArea->SetFont(attr.GetFont()); + + // If the font has changed, the size of the header might need to be + // updated. + Layout(); + + return true; +} + void wxDataViewCtrl::SetAlternateRowColour(const wxColour& colour) { m_alternateRowColour = colour; From bed710d9a71fd3ecda8dc04accf186731c4d6702 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 22 Apr 2016 01:12:21 +0200 Subject: [PATCH 10/10] Add wxDataViewCtrl::GenericGetHeader() accessor And show how to use it to increase the header size in the sample. --- include/wx/dataview.h | 1 + include/wx/generic/dataview.h | 5 +++++ samples/dataview/dataview.cpp | 36 +++++++++++++++++++++++++++++++++++ src/generic/datavgen.cpp | 5 +++++ 4 files changed, 47 insertions(+) diff --git a/include/wx/dataview.h b/include/wx/dataview.h index 8349a29082..e9c35940f7 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -30,6 +30,7 @@ class WXDLLIMPEXP_FWD_CORE wxImageList; class WXDLLIMPEXP_FWD_CORE wxItemAttr; +class WXDLLIMPEXP_FWD_CORE wxHeaderCtrl; #if !(defined(__WXGTK20__) || defined(__WXOSX__) ) || defined(__WXUNIVERSAL__) // #if !(defined(__WXOSX__)) || defined(__WXUNIVERSAL__) diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index 1f742e63c7..694ee8ffe6 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -263,6 +263,11 @@ public: wxColour GetAlternateRowColour() const { return m_alternateRowColour; } void SetAlternateRowColour(const wxColour& colour); + // The returned pointer is null if the control has wxDV_NO_HEADER style. + // + // This method is only available in the generic versions. + wxHeaderCtrl* GenericGetHeader() const; + protected: void EnsureVisibleRowCol( int row, int column ); diff --git a/samples/dataview/dataview.cpp b/samples/dataview/dataview.cpp index 89f0d66367..fca7630647 100644 --- a/samples/dataview/dataview.cpp +++ b/samples/dataview/dataview.cpp @@ -35,6 +35,10 @@ #include "wx/itemattr.h" #include "wx/notebook.h" +#ifdef wxHAS_GENERIC_DATAVIEWCTRL + #include "wx/headerctrl.h" +#endif // wxHAS_GENERIC_DATAVIEWCTRL + #include "mymodels.h" // ---------------------------------------------------------------------------- @@ -76,6 +80,9 @@ private: void OnStyleChange(wxCommandEvent& event); void OnSetBackgroundColour(wxCommandEvent& event); void OnCustomHeaderAttr(wxCommandEvent& event); +#ifdef wxHAS_GENERIC_DATAVIEWCTRL + void OnCustomHeaderHeight(wxCommandEvent& event); +#endif // wxHAS_GENERIC_DATAVIEWCTRL void OnSetForegroundColour(wxCommandEvent& event); void OnIncIndent(wxCommandEvent& event); void OnDecIndent(wxCommandEvent& event); @@ -293,6 +300,9 @@ enum ID_BACKGROUND_COLOUR, ID_FOREGROUND_COLOUR, ID_CUSTOM_HEADER_ATTR, +#ifdef wxHAS_GENERIC_DATAVIEWCTRL + ID_CUSTOM_HEADER_HEIGHT, +#endif // wxHAS_GENERIC_DATAVIEWCTRL ID_STYLE_MENU, ID_INC_INDENT, ID_DEC_INDENT, @@ -348,6 +358,9 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU( ID_FOREGROUND_COLOUR, MyFrame::OnSetForegroundColour ) EVT_MENU( ID_BACKGROUND_COLOUR, MyFrame::OnSetBackgroundColour ) EVT_MENU( ID_CUSTOM_HEADER_ATTR, MyFrame::OnCustomHeaderAttr ) +#ifdef wxHAS_GENERIC_DATAVIEWCTRL + EVT_MENU( ID_CUSTOM_HEADER_HEIGHT, MyFrame::OnCustomHeaderHeight ) +#endif // wxHAS_GENERIC_DATAVIEWCTRL EVT_MENU( ID_INC_INDENT, MyFrame::OnIncIndent ) EVT_MENU( ID_DEC_INDENT, MyFrame::OnDecIndent ) @@ -436,6 +449,9 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int file_menu->Append(ID_FOREGROUND_COLOUR, "Set &foreground colour...\tCtrl-S"); file_menu->Append(ID_BACKGROUND_COLOUR, "Set &background colour...\tCtrl-B"); file_menu->AppendCheckItem(ID_CUSTOM_HEADER_ATTR, "C&ustom header attributes"); +#ifdef wxHAS_GENERIC_DATAVIEWCTRL + file_menu->AppendCheckItem(ID_CUSTOM_HEADER_HEIGHT, "Custom header &height"); +#endif // wxHAS_GENERIC_DATAVIEWCTRL file_menu->Append(ID_STYLE_MENU, "&Style", style_menu); file_menu->Append(ID_INC_INDENT, "&Increase indent\tCtrl-I"); file_menu->Append(ID_DEC_INDENT, "&Decrease indent\tShift-Ctrl-I"); @@ -808,6 +824,26 @@ void MyFrame::OnCustomHeaderAttr(wxCommandEvent& event) wxLogMessage("Sorry, header attributes not supported on this platform"); } +#ifdef wxHAS_GENERIC_DATAVIEWCTRL +void MyFrame::OnCustomHeaderHeight(wxCommandEvent& event) +{ + wxDataViewCtrl * const dvc = m_ctrl[m_notebook->GetSelection()]; + wxHeaderCtrl* const header = dvc->GenericGetHeader(); + if ( !header ) + { + wxLogMessage("No header"); + return; + } + + // Use a big height to show that this works. + wxSize size = event.IsChecked() ? FromDIP(wxSize(0, 80)) : wxDefaultSize; + header->SetMinSize(size); + header->Refresh(); + + dvc->Layout(); +} +#endif // wxHAS_GENERIC_DATAVIEWCTRL + void MyFrame::OnIncIndent(wxCommandEvent& WXUNUSED(event)) { wxDataViewCtrl * const dvc = m_ctrl[m_notebook->GetSelection()]; diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 90c921b5b5..95d235e91d 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -4625,6 +4625,11 @@ wxBorder wxDataViewCtrl::GetDefaultBorder() const return wxBORDER_THEME; } +wxHeaderCtrl* wxDataViewCtrl::GenericGetHeader() const +{ + return m_headerArea; +} + #ifdef __WXMSW__ WXLRESULT wxDataViewCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam,