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.
This commit is contained in:
Vadim Zeitlin
2016-04-16 17:44:19 +02:00
parent c592363e95
commit 246ae58c19
24 changed files with 232 additions and 221 deletions

View File

@@ -3872,6 +3872,7 @@ COND_USE_GUI_1_ALL_GUI_HEADERS = \
wx/systhemectrl.h \ wx/systhemectrl.h \
wx/collheaderctrl.h \ wx/collheaderctrl.h \
wx/generic/collheaderctrl.h \ wx/generic/collheaderctrl.h \
wx/itemattr.h \
$(LOWLEVEL_HDR) \ $(LOWLEVEL_HDR) \
$(GUI_CORE_HEADERS) \ $(GUI_CORE_HEADERS) \
$(ADVANCED_HDR) \ $(ADVANCED_HDR) \

View File

@@ -1181,6 +1181,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
wx/systhemectrl.h wx/systhemectrl.h
wx/collheaderctrl.h wx/collheaderctrl.h
wx/generic/collheaderctrl.h wx/generic/collheaderctrl.h
wx/itemattr.h
</set> </set>
<!-- ====================================================================== --> <!-- ====================================================================== -->

View File

@@ -1039,6 +1039,7 @@ GUI_CMN_HDR =
wx/imagtga.h wx/imagtga.h
wx/imagtiff.h wx/imagtiff.h
wx/imagxpm.h wx/imagxpm.h
wx/itemattr.h
wx/listbase.h wx/listbase.h
wx/listbook.h wx/listbook.h
wx/listctrl.h wx/listctrl.h

View File

@@ -1379,6 +1379,7 @@
<ClInclude Include="..\..\include\wx\collheaderctrl.h" /> <ClInclude Include="..\..\include\wx\collheaderctrl.h" />
<ClInclude Include="..\..\include\wx\generic\collheaderctrl.h" /> <ClInclude Include="..\..\include\wx\generic\collheaderctrl.h" />
<ClInclude Include="..\..\include\wx\msw\rt\utils.h" /> <ClInclude Include="..\..\include\wx\msw\rt\utils.h" />
<ClInclude Include="..\..\include\wx\itemattr.h" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">

View File

@@ -690,6 +690,9 @@
<ClCompile Include="..\..\src\msw\graphics.cpp"> <ClCompile Include="..\..\src\msw\graphics.cpp">
<Filter>MSW Sources</Filter> <Filter>MSW Sources</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\msw\graphicsd2d.cpp">
<Filter>MSW Sources</Filter>
</ClCompile>
<ClCompile Include="..\..\src\msw\headerctrl.cpp"> <ClCompile Include="..\..\src\msw\headerctrl.cpp">
<Filter>MSW Sources</Filter> <Filter>MSW Sources</Filter>
</ClCompile> </ClCompile>
@@ -897,9 +900,6 @@
<ClCompile Include="..\..\src\xrc\xmlreshandler.cpp"> <ClCompile Include="..\..\src\xrc\xmlreshandler.cpp">
<Filter>Common Sources</Filter> <Filter>Common Sources</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\msw\graphicsd2d.cpp">
<Filter>MSW Sources</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="..\..\src\msw\version.rc"> <ResourceCompile Include="..\..\src\msw\version.rc">
@@ -928,6 +928,9 @@
<ClInclude Include="..\..\include\wx\anybutton.h"> <ClInclude Include="..\..\include\wx\anybutton.h">
<Filter>Common Headers</Filter> <Filter>Common Headers</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\include\wx\appprogress.h">
<Filter>Common Headers</Filter>
</ClInclude>
<ClInclude Include="..\..\include\wx\artprov.h"> <ClInclude Include="..\..\include\wx\artprov.h">
<Filter>Common Headers</Filter> <Filter>Common Headers</Filter>
</ClInclude> </ClInclude>
@@ -1312,6 +1315,9 @@
<ClInclude Include="..\..\include\wx\infobar.h"> <ClInclude Include="..\..\include\wx\infobar.h">
<Filter>Common Headers</Filter> <Filter>Common Headers</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\include\wx\itemattr.h">
<Filter>Common Headers</Filter>
</ClInclude>
<ClInclude Include="..\..\include\wx\itemid.h"> <ClInclude Include="..\..\include\wx\itemid.h">
<Filter>Common Headers</Filter> <Filter>Common Headers</Filter>
</ClInclude> </ClInclude>
@@ -1672,9 +1678,6 @@
<ClInclude Include="..\..\include\wx\msw\window.h"> <ClInclude Include="..\..\include\wx\msw\window.h">
<Filter>MSW Headers</Filter> <Filter>MSW Headers</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\include\wx\appprogress.h">
<Filter>Common Headers</Filter>
</ClInclude>
<ClInclude Include="..\..\include\wx\nativewin.h"> <ClInclude Include="..\..\include\wx\nativewin.h">
<Filter>Common Headers</Filter> <Filter>Common Headers</Filter>
</ClInclude> </ClInclude>

View File

@@ -2285,6 +2285,9 @@
<File <File
RelativePath="..\..\include\wx\infobar.h"> RelativePath="..\..\include\wx\infobar.h">
</File> </File>
<File
RelativePath="..\..\include\wx\itemattr.h">
</File>
<File <File
RelativePath="..\..\include\wx\itemid.h"> RelativePath="..\..\include\wx\itemid.h">
</File> </File>

View File

@@ -3548,6 +3548,10 @@
RelativePath="..\..\include\wx\infobar.h" RelativePath="..\..\include\wx\infobar.h"
> >
</File> </File>
<File
RelativePath="..\..\include\wx\itemattr.h"
>
</File>
<File <File
RelativePath="..\..\include\wx\itemid.h" RelativePath="..\..\include\wx\itemid.h"
> >

View File

@@ -3544,6 +3544,10 @@
RelativePath="..\..\include\wx\infobar.h" RelativePath="..\..\include\wx\infobar.h"
> >
</File> </File>
<File
RelativePath="..\..\include\wx\itemattr.h"
>
</File>
<File <File
RelativePath="..\..\include\wx\itemid.h" RelativePath="..\..\include\wx\itemid.h"
> >

View File

@@ -85,8 +85,8 @@ public:
void GetItem( wxListItem &info ) const; void GetItem( wxListItem &info ) const;
void SetAttr(wxListItemAttr *attr) { m_attr = attr; } void SetAttr(wxItemAttr *attr) { m_attr = attr; }
wxListItemAttr *GetAttr() const { return m_attr; } wxItemAttr *GetAttr() const { return m_attr; }
public: public:
// the item image or -1 // the item image or -1
@@ -103,7 +103,7 @@ public:
wxListMainWindow *m_owner; wxListMainWindow *m_owner;
// custom attributes or NULL // custom attributes or NULL
wxListItemAttr *m_attr; wxItemAttr *m_attr;
protected: protected:
// common part of all ctors // common part of all ctors
@@ -263,8 +263,8 @@ public:
wxString GetText(int index) const; wxString GetText(int index) const;
void SetText( int index, const wxString& s ); void SetText( int index, const wxString& s );
wxListItemAttr *GetAttr() const; wxItemAttr *GetAttr() const;
void SetAttr(wxListItemAttr *attr); void SetAttr(wxItemAttr *attr);
// return true if the highlighting really changed // return true if the highlighting really changed
bool Highlight( bool on ); bool Highlight( bool on );

65
include/wx/itemattr.h Normal file
View File

@@ -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 <vadim@wxwidgets.org>
// 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_

View File

@@ -16,6 +16,7 @@
#include "wx/gdicmn.h" #include "wx/gdicmn.h"
#include "wx/event.h" #include "wx/event.h"
#include "wx/control.h" #include "wx/control.h"
#include "wx/itemattr.h"
#include "wx/systhemectrl.h" #include "wx/systhemectrl.h"
class WXDLLIMPEXP_FWD_CORE wxImageList; class WXDLLIMPEXP_FWD_CORE wxImageList;
@@ -158,60 +159,10 @@ enum
wxLIST_FIND_RIGHT wxLIST_FIND_RIGHT
}; };
// ---------------------------------------------------------------------------- // For compatibility, define the old name for this class. There is no need to
// wxListItemAttr: a structure containing the visual attributes of an item // 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;
// 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;
};
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxListItem: the item or column info, used to exchange data with wxListCtrl // wxListItem: the item or column info, used to exchange data with wxListCtrl
@@ -237,7 +188,7 @@ public:
{ {
// copy list item attributes // copy list item attributes
if ( item.HasAttributes() ) if ( item.HasAttributes() )
m_attr = new wxListItemAttr(*item.GetAttributes()); m_attr = new wxItemAttr(*item.GetAttributes());
} }
wxListItem& operator=(const wxListItem& item) wxListItem& operator=(const wxListItem& item)
@@ -254,7 +205,7 @@ public:
m_data = item.m_data; m_data = item.m_data;
m_format = item.m_format; m_format = item.m_format;
m_width = item.m_width; 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; return *this;
@@ -310,7 +261,7 @@ public:
int GetWidth() const { return m_width; } int GetWidth() const { return m_width; }
wxListColumnFormat GetAlign() const { return (wxListColumnFormat)m_format; } 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; } bool HasAttributes() const { return m_attr != NULL; }
wxColour GetTextColour() const wxColour GetTextColour() const
@@ -342,10 +293,10 @@ public:
protected: protected:
// creates m_attr if we don't have it yet // creates m_attr if we don't have it yet
wxListItemAttr& Attributes() wxItemAttr& Attributes()
{ {
if ( !m_attr ) if ( !m_attr )
m_attr = new wxListItemAttr; m_attr = new wxItemAttr;
return *m_attr; return *m_attr;
} }
@@ -364,7 +315,7 @@ protected:
m_width = 0; m_width = 0;
} }
wxListItemAttr *m_attr; // optional pointer to the items style wxItemAttr *m_attr; // optional pointer to the items style
private: private:
wxDECLARE_DYNAMIC_CLASS(wxListItem); wxDECLARE_DYNAMIC_CLASS(wxListItem);
@@ -443,7 +394,7 @@ public:
virtual bool SetColumnWidth(int col, int width) = 0; virtual bool SetColumnWidth(int col, int width) = 0;
// return the attribute for the item (may return NULL if none) // 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. // Other miscellaneous accessors.
// ------------------------------ // ------------------------------
@@ -475,7 +426,7 @@ protected:
private: private:
// user defined color to draw row lines, may be invalid // user defined color to draw row lines, may be invalid
wxListItemAttr m_alternateRowColour; wxItemAttr m_alternateRowColour;
}; };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -402,7 +402,7 @@ protected:
// get the item attribute, either by quering it for virtual control, or by // 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 // 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 wxTextCtrl* m_textCtrl; // The control used for editing a label
@@ -437,7 +437,7 @@ protected:
virtual int OnGetItemColumnImage(long item, long column) const; virtual int OnGetItemColumnImage(long item, long column) const;
// return the attribute for the given item and column (may return NULL if none) // 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); return OnGetItemAttr(item);
} }

View File

@@ -34,7 +34,8 @@ class WXDLLIMPEXP_FWD_CORE wxDragImage;
struct WXDLLIMPEXP_FWD_CORE wxTreeViewItem; struct WXDLLIMPEXP_FWD_CORE wxTreeViewItem;
// hash storing attributes for our items // 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 // wxTreeCtrl

View File

@@ -279,7 +279,7 @@ public:
virtual int OnGetItemColumnImage(long item, long column) const; virtual int OnGetItemColumnImage(long item, long column) const;
// return the attribute for the given item and column (may return NULL if none) // 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); return OnGetItemAttr(item);
} }

View File

@@ -180,40 +180,6 @@ static const int wxTREE_HITTEST_ONITEM = wxTREE_HITTEST_ONITEMICON |
// tree ctrl default name // tree ctrl default name
extern WXDLLIMPEXP_DATA_CORE(const char) wxTreeCtrlNameStr[]; 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 // wxTreeEvent is a special class for all events associated with tree controls
// //

82
interface/wx/itemattr.h Normal file
View File

@@ -0,0 +1,82 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/itemattr.h
// Purpose: wxItemAttr documentation
// Author: Vadim Zeitlin
// Copyright: (c) 2016 Vadim Zeitlin <vadim@wxwidgets.org>
// 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);
};

View File

@@ -1278,14 +1278,14 @@ protected:
@c item or @NULL to use the default appearance parameters. @c item or @NULL to use the default appearance parameters.
wxListCtrl will not delete the pointer or keep a reference of it. 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. The base class version always returns @NULL.
@see OnGetItemImage(), OnGetItemColumnImage(), OnGetItemText(), @see OnGetItemImage(), OnGetItemColumnImage(), OnGetItemText(),
OnGetItemColumnAttr() 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 This function may be overridden in the derived class for a control with
@@ -1302,7 +1302,7 @@ protected:
@see OnGetItemAttr(), OnGetItemText(), @see OnGetItemAttr(), OnGetItemText(),
OnGetItemImage(), OnGetItemColumnImage(), 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 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; 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 @class wxListView

View File

@@ -1226,7 +1226,7 @@ void MyListCtrl::OnListKeyDown(wxListEvent& event)
GetItem(info); GetItem(info);
wxListItemAttr *attr = info.GetAttributes(); wxItemAttr *attr = info.GetAttributes();
if ( !attr || !attr->HasTextColour() ) if ( !attr || !attr->HasTextColour() )
{ {
info.SetTextColour(*wxCYAN); info.SetTextColour(*wxCYAN);
@@ -1416,13 +1416,13 @@ int MyListCtrl::OnGetItemColumnImage(long item, long column) const
return -1; 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 // test to check that RefreshItem() works correctly: when m_updated is
// set to some item and it is refreshed, we highlight the item // set to some item and it is refreshed, we highlight the item
if ( item == m_updated ) if ( item == m_updated )
{ {
static wxListItemAttr s_attrHighlight(*wxRED, wxNullColour, wxNullFont); static wxItemAttr s_attrHighlight(*wxRED, wxNullColour, wxNullFont);
return &s_attrHighlight; return &s_attrHighlight;
} }

View File

@@ -84,7 +84,7 @@ private:
virtual wxString OnGetItemText(long item, long column) const wxOVERRIDE; virtual wxString OnGetItemText(long item, long column) const wxOVERRIDE;
virtual int OnGetItemColumnImage(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; long m_updated;

View File

@@ -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)) return (m_alternateRowColour.GetBackgroundColour().IsOk() && (item % 2))
? wxConstCast(&m_alternateRowColour, wxListItemAttr) ? wxConstCast(&m_alternateRowColour, wxItemAttr)
: NULL; // no attributes by default : NULL; // no attributes by default
} }

View File

@@ -168,7 +168,7 @@ void wxListItemData::SetItem( const wxListItem &info )
if ( m_attr ) if ( m_attr )
m_attr->AssignFrom(*info.GetAttributes()); m_attr->AssignFrom(*info.GetAttributes());
else else
m_attr = new wxListItemAttr(*info.GetAttributes()); m_attr = new wxItemAttr(*info.GetAttributes());
} }
if ( m_rect ) if ( m_rect )
@@ -654,7 +654,7 @@ int wxListLineData::GetImage( int index ) const
return item->GetImage(); return item->GetImage();
} }
wxListItemAttr *wxListLineData::GetAttr() const wxItemAttr *wxListLineData::GetAttr() const
{ {
wxListItemDataList::compatibility_iterator node = m_items.GetFirst(); wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
wxCHECK_MSG( node, NULL, wxT("invalid column index in GetAttr()") ); wxCHECK_MSG( node, NULL, wxT("invalid column index in GetAttr()") );
@@ -663,7 +663,7 @@ wxListItemAttr *wxListLineData::GetAttr() const
return item->GetAttr(); return item->GetAttr();
} }
void wxListLineData::SetAttr(wxListItemAttr *attr) void wxListLineData::SetAttr(wxItemAttr *attr)
{ {
wxListItemDataList::compatibility_iterator node = m_items.GetFirst(); wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
wxCHECK_RET( node, wxT("invalid column index in SetAttr()") ); wxCHECK_RET( node, wxT("invalid column index in SetAttr()") );
@@ -677,7 +677,7 @@ void wxListLineData::ApplyAttributes(wxDC *dc,
bool highlighted, bool highlighted,
bool current) bool current)
{ {
const wxListItemAttr * const attr = GetAttr(); const wxItemAttr * const attr = GetAttr();
wxWindow * const listctrl = m_owner->GetParent(); wxWindow * const listctrl = m_owner->GetParent();

View File

@@ -37,6 +37,7 @@
#include "wx/generic/treectlg.h" #include "wx/generic/treectlg.h"
#include "wx/imaglist.h" #include "wx/imaglist.h"
#include "wx/itemattr.h"
#include "wx/renderer.h" #include "wx/renderer.h"
@@ -223,7 +224,7 @@ public:
{ {
wxFont font; wxFont font;
wxTreeItemAttr * const attr = GetAttributes(); wxItemAttr * const attr = GetAttributes();
if ( attr && attr->HasFont() ) if ( attr && attr->HasFont() )
font = attr->GetFont(); font = attr->GetFont();
else if ( IsBold() ) else if ( IsBold() )
@@ -282,19 +283,19 @@ public:
// attributes // attributes
// get them - may be NULL // 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 // get them ensuring that the pointer is not NULL
wxTreeItemAttr& Attr() wxItemAttr& Attr()
{ {
if ( !m_attr ) if ( !m_attr )
{ {
m_attr = new wxTreeItemAttr; m_attr = new wxItemAttr;
m_ownsAttr = true; m_ownsAttr = true;
} }
return *m_attr; return *m_attr;
} }
// set them // set them
void SetAttributes(wxTreeItemAttr *attr) void SetAttributes(wxItemAttr *attr)
{ {
if ( m_ownsAttr ) delete m_attr; if ( m_ownsAttr ) delete m_attr;
m_attr = attr; m_attr = attr;
@@ -303,7 +304,7 @@ public:
m_widthText = -1; m_widthText = -1;
} }
// set them and delete when done // set them and delete when done
void AssignAttributes(wxTreeItemAttr *attr) void AssignAttributes(wxItemAttr *attr)
{ {
SetAttributes(attr); SetAttributes(attr);
m_ownsAttr = true; m_ownsAttr = true;
@@ -335,7 +336,7 @@ private:
wxArrayGenericTreeItems m_children; // list of children wxArrayGenericTreeItems m_children; // list of children
wxGenericTreeItem *m_parent; // parent of this item wxGenericTreeItem *m_parent; // parent of this item
wxTreeItemAttr *m_attr; // attributes??? wxItemAttr *m_attr; // attributes???
// tree ctrl images for the normal, selected, expanded and // tree ctrl images for the normal, selected, expanded and
// expanded+selected states // expanded+selected states
@@ -2554,7 +2555,7 @@ void wxGenericTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc)
else else
{ {
wxColour colBg; wxColour colBg;
wxTreeItemAttr * const attr = item->GetAttributes(); wxItemAttr * const attr = item->GetAttributes();
if ( attr && attr->HasBackgroundColour() ) if ( attr && attr->HasBackgroundColour() )
{ {
drawItemBackground = drawItemBackground =
@@ -2789,7 +2790,7 @@ wxGenericTreeCtrl::PaintLevel(wxGenericTreeItem *item,
} }
else else
{ {
wxTreeItemAttr *attr = item->GetAttributes(); wxItemAttr *attr = item->GetAttributes();
if (attr && attr->HasTextColour()) if (attr && attr->HasTextColour())
colText = attr->GetTextColour(); colText = attr->GetTextColour();
else else

View File

@@ -198,7 +198,7 @@ private:
/////////////////////////////////////////////////////// ///////////////////////////////////////////////////////
// Problem: // Problem:
// The MSW version had problems with SetTextColour() et // 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 // item index. If a item was inserted anywhere but the end
// of the list the text attributes (colour etc) for // of the list the text attributes (colour etc) for
// the following items were out of sync. // the following items were out of sync.
@@ -223,7 +223,7 @@ public:
wxMSWListItemData() : attr(NULL), lParam(0) {} wxMSWListItemData() : attr(NULL), lParam(0) {}
~wxMSWListItemData() { delete attr; } ~wxMSWListItemData() { delete attr; }
wxListItemAttr *attr; wxItemAttr *attr;
LPARAM lParam; // real user data LPARAM lParam; // real user data
wxDECLARE_NO_COPY_CLASS(wxMSWListItemData); wxDECLARE_NO_COPY_CLASS(wxMSWListItemData);
@@ -811,13 +811,13 @@ bool wxListCtrl::SetItem(wxListItem& info)
// attributes // attributes
if ( info.HasAttributes() ) if ( info.HasAttributes() )
{ {
const wxListItemAttr& attrNew = *info.GetAttributes(); const wxItemAttr& attrNew = *info.GetAttributes();
// don't overwrite the already set attributes if we have them // don't overwrite the already set attributes if we have them
if ( data->attr ) if ( data->attr )
data->attr->AssignFrom(attrNew); data->attr->AssignFrom(attrNew);
else else
data->attr = new wxListItemAttr(attrNew); data->attr = new wxItemAttr(attrNew);
} }
} }
@@ -1754,7 +1754,7 @@ long wxListCtrl::InsertItem(const wxListItem& info)
if ( info.HasAttributes() ) if ( info.HasAttributes() )
{ {
// take copy of attributes // take copy of attributes
data->attr = new wxListItemAttr(*info.GetAttributes()); data->attr = new wxItemAttr(*info.GetAttributes());
// and remember that we have some now... // and remember that we have some now...
m_hasAnyAttr = true; m_hasAnyAttr = true;
@@ -2858,7 +2858,7 @@ static void HandleItemPaint(LPNMLVCUSTOMDRAW pLVCD, HFONT hfont)
static WXLPARAM HandleItemPrepaint(wxListCtrl *listctrl, static WXLPARAM HandleItemPrepaint(wxListCtrl *listctrl,
LPNMLVCUSTOMDRAW pLVCD, LPNMLVCUSTOMDRAW pLVCD,
wxListItemAttr *attr) wxItemAttr *attr)
{ {
if ( !attr ) if ( !attr )
{ {
@@ -3103,7 +3103,7 @@ int wxListCtrl::OnGetItemColumnImage(long item, long column) const
return -1; return -1;
} }
wxListItemAttr *wxListCtrl::DoGetItemColumnAttr(long item, long column) const wxItemAttr *wxListCtrl::DoGetItemColumnAttr(long item, long column) const
{ {
if ( IsVirtual() ) if ( IsVirtual() )
return OnGetItemColumnAttr(item, column); return OnGetItemColumnAttr(item, column);

View File

@@ -39,6 +39,7 @@
#include "wx/msw/private.h" #include "wx/msw/private.h"
#include "wx/imaglist.h" #include "wx/imaglist.h"
#include "wx/itemattr.h"
#include "wx/msw/dragimag.h" #include "wx/msw/dragimag.h"
#include "wx/msw/uxtheme.h" #include "wx/msw/uxtheme.h"
@@ -1146,14 +1147,14 @@ void wxTreeCtrl::SetItemTextColour(const wxTreeItemId& item,
{ {
wxCHECK_RET( item.IsOk(), wxT("invalid tree item") ); wxCHECK_RET( item.IsOk(), wxT("invalid tree item") );
wxTreeItemAttr *attr; wxItemAttr *attr;
wxMapTreeAttr::iterator it = m_attrs.find(item.m_pItem); wxMapTreeAttr::iterator it = m_attrs.find(item.m_pItem);
if ( it == m_attrs.end() ) if ( it == m_attrs.end() )
{ {
m_hasAnyAttr = true; m_hasAnyAttr = true;
m_attrs[item.m_pItem] = m_attrs[item.m_pItem] =
attr = new wxTreeItemAttr; attr = new wxItemAttr;
} }
else else
{ {
@@ -1170,14 +1171,14 @@ void wxTreeCtrl::SetItemBackgroundColour(const wxTreeItemId& item,
{ {
wxCHECK_RET( item.IsOk(), wxT("invalid tree item") ); wxCHECK_RET( item.IsOk(), wxT("invalid tree item") );
wxTreeItemAttr *attr; wxItemAttr *attr;
wxMapTreeAttr::iterator it = m_attrs.find(item.m_pItem); wxMapTreeAttr::iterator it = m_attrs.find(item.m_pItem);
if ( it == m_attrs.end() ) if ( it == m_attrs.end() )
{ {
m_hasAnyAttr = true; m_hasAnyAttr = true;
m_attrs[item.m_pItem] = m_attrs[item.m_pItem] =
attr = new wxTreeItemAttr; attr = new wxItemAttr;
} }
else // already in the hash 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") ); wxCHECK_RET( item.IsOk(), wxT("invalid tree item") );
wxTreeItemAttr *attr; wxItemAttr *attr;
wxMapTreeAttr::iterator it = m_attrs.find(item.m_pItem); wxMapTreeAttr::iterator it = m_attrs.find(item.m_pItem);
if ( it == m_attrs.end() ) if ( it == m_attrs.end() )
{ {
m_hasAnyAttr = true; m_hasAnyAttr = true;
m_attrs[item.m_pItem] = m_attrs[item.m_pItem] =
attr = new wxTreeItemAttr; attr = new wxItemAttr;
} }
else // already in the hash else // already in the hash
{ {
@@ -3550,7 +3551,7 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
break; break;
} }
wxTreeItemAttr * const attr = it->second; wxItemAttr * const attr = it->second;
wxTreeViewItem tvItem((void *)nmcd.dwItemSpec, wxTreeViewItem tvItem((void *)nmcd.dwItemSpec,
TVIF_STATE, TVIS_DROPHILITED); TVIF_STATE, TVIS_DROPHILITED);