Refactor: replace wxTreeItemId and wxDataViewItem with new wxItemId<>.
Add wxItemId<> template which can be used to identify items in different {tree,list}-like controls, including wxDataViewCtrl (where it replaces, in backwards compatible way, wxDataViewItem), wxTreeCtrl (where it replaces wxTreeItemId) and the upcoming wxTreeListCtrl. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68812 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -3905,6 +3905,7 @@ COND_USE_GUI_1_ALL_GUI_HEADERS = \
|
||||
wx/helphtml.h \
|
||||
wx/icon.h \
|
||||
wx/infobar.h \
|
||||
wx/itemid.h \
|
||||
wx/layout.h \
|
||||
wx/listbox.h \
|
||||
wx/mdi.h \
|
||||
|
@@ -879,6 +879,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
|
||||
wx/helphtml.h
|
||||
wx/icon.h
|
||||
wx/infobar.h
|
||||
wx/itemid.h
|
||||
wx/layout.h
|
||||
wx/listbox.h
|
||||
wx/mdi.h
|
||||
|
@@ -6444,6 +6444,10 @@ SOURCE=..\..\include\wx\infobar.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\include\wx\itemid.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\include\wx\joystick.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
@@ -5408,6 +5408,9 @@
|
||||
<File
|
||||
RelativePath="..\..\include\wx\infobar.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\wx\itemid.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\wx\joystick.h">
|
||||
</File>
|
||||
|
@@ -7231,6 +7231,10 @@
|
||||
RelativePath="..\..\include\wx\infobar.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\wx\itemid.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\wx\joystick.h"
|
||||
>
|
||||
|
@@ -7227,6 +7227,10 @@
|
||||
RelativePath="..\..\include\wx\infobar.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\wx\itemid.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\wx\joystick.h"
|
||||
>
|
||||
|
@@ -21,6 +21,7 @@
|
||||
#include "wx/variant.h"
|
||||
#include "wx/dynarray.h"
|
||||
#include "wx/icon.h"
|
||||
#include "wx/itemid.h"
|
||||
#include "wx/weakref.h"
|
||||
#include "wx/vector.h"
|
||||
#include "wx/dataobj.h"
|
||||
@@ -45,7 +46,6 @@ class WXDLLIMPEXP_FWD_CORE wxImageList;
|
||||
// wxDataViewCtrl globals
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class WXDLLIMPEXP_FWD_ADV wxDataViewItem;
|
||||
class WXDLLIMPEXP_FWD_ADV wxDataViewModel;
|
||||
class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl;
|
||||
class WXDLLIMPEXP_FWD_ADV wxDataViewColumn;
|
||||
@@ -79,34 +79,14 @@ extern WXDLLIMPEXP_DATA_ADV(const char) wxDataViewCtrlNameStr[];
|
||||
// wxDataViewItem
|
||||
// ---------------------------------------------------------
|
||||
|
||||
class WXDLLIMPEXP_ADV wxDataViewItem
|
||||
// Make it a class and not a typedef to allow forward declaring it.
|
||||
class wxDataViewItem : public wxItemId<void*>
|
||||
{
|
||||
public:
|
||||
wxDataViewItem() : m_id(NULL) {}
|
||||
wxDataViewItem(const wxDataViewItem &item) : m_id(item.m_id) {}
|
||||
|
||||
wxEXPLICIT wxDataViewItem(void* id) : m_id(id) {}
|
||||
|
||||
bool IsOk() const { return m_id != NULL; }
|
||||
void* GetID() const { return m_id; }
|
||||
operator const void* () const { return m_id; }
|
||||
|
||||
private:
|
||||
void* m_id;
|
||||
wxDataViewItem() : wxItemId<void*>() { }
|
||||
wxEXPLICIT wxDataViewItem(void* pItem) : wxItemId<void*>(pItem) { }
|
||||
};
|
||||
|
||||
inline
|
||||
bool operator==(const wxDataViewItem& left, const wxDataViewItem& right)
|
||||
{
|
||||
return left.GetID() == right.GetID();
|
||||
}
|
||||
|
||||
inline
|
||||
bool operator!=(const wxDataViewItem& left, const wxDataViewItem& right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
WX_DEFINE_ARRAY(wxDataViewItem, wxDataViewItemArray);
|
||||
|
||||
// ---------------------------------------------------------
|
||||
|
59
include/wx/itemid.h
Normal file
59
include/wx/itemid.h
Normal file
@@ -0,0 +1,59 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/itemid.h
|
||||
// Purpose: wxItemId class declaration.
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2011-08-17
|
||||
// RCS-ID: $Id: wxhead.h,v 1.12 2010-04-22 12:44:51 zeitlin Exp $
|
||||
// Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_ITEMID_H_
|
||||
#define _WX_ITEMID_H_
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxItemId: an opaque item identifier used with wx{Tree,TreeList,DataView}Ctrl.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// The template argument T is typically a pointer to some opaque type. While
|
||||
// wxTreeItemId and wxDataViewItem use a pointer to void, this is dangerous and
|
||||
// not recommended for the new item id classes.
|
||||
template <typename T>
|
||||
class wxItemId
|
||||
{
|
||||
public:
|
||||
typedef T Type;
|
||||
|
||||
// This ctor is implicit which is fine for non-void* types, but if you use
|
||||
// this class with void* you're strongly advised to make the derived class
|
||||
// ctor explicit as implicitly converting from any pointer is simply too
|
||||
// dangerous.
|
||||
wxItemId(Type item = NULL) : m_pItem(item) { }
|
||||
|
||||
// Default copy ctor, assignment operator and dtor are ok.
|
||||
|
||||
bool IsOk() const { return m_pItem != NULL; }
|
||||
Type GetID() const { return m_pItem; }
|
||||
operator const Type() const { return m_pItem; }
|
||||
|
||||
void Unset() { m_pItem = NULL; }
|
||||
|
||||
// This field is public *only* for compatibility with the old wxTreeItemId
|
||||
// implementation and must not be used in any new code.
|
||||
//private:
|
||||
Type m_pItem;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
bool operator==(const wxItemId<T>& left, const wxItemId<T>& right)
|
||||
{
|
||||
return left.GetID() == right.GetID();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool operator!=(const wxItemId<T>& left, const wxItemId<T>& right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
#endif // _WX_ITEMID_H_
|
@@ -23,6 +23,7 @@
|
||||
#include "wx/window.h" // for wxClientData
|
||||
#include "wx/event.h"
|
||||
#include "wx/dynarray.h"
|
||||
#include "wx/itemid.h"
|
||||
|
||||
#if WXWIN_COMPATIBILITY_2_6
|
||||
|
||||
@@ -38,53 +39,19 @@ enum
|
||||
#endif // WXWIN_COMPATIBILITY_2_6
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxTreeItemId identifies an element of the tree. In this implementation, it's
|
||||
// just a trivial wrapper around Win32 HTREEITEM or a pointer to some private
|
||||
// data structure in the generic version. It's opaque for the application and
|
||||
// the only method which can be used by user code is IsOk().
|
||||
// wxTreeItemId identifies an element of the tree. It's opaque for the
|
||||
// application and the only method which can be used by user code is IsOk().
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Using this typedef removes an ambiguity when calling Remove()
|
||||
typedef void *wxTreeItemIdValue;
|
||||
|
||||
class WXDLLIMPEXP_CORE wxTreeItemId
|
||||
// This is a class and not a typedef because existing code may forward declare
|
||||
// wxTreeItemId as a class and we don't want to break it without good reason.
|
||||
class wxTreeItemId : public wxItemId<void*>
|
||||
{
|
||||
friend bool operator==(const wxTreeItemId&, const wxTreeItemId&);
|
||||
public:
|
||||
// ctors
|
||||
// 0 is invalid value for HTREEITEM
|
||||
wxTreeItemId() { m_pItem = 0; }
|
||||
|
||||
// construct wxTreeItemId from the native item id
|
||||
wxTreeItemId(void *pItem) { m_pItem = pItem; }
|
||||
|
||||
// default copy ctor/assignment operator are ok for us
|
||||
|
||||
// accessors
|
||||
// is this a valid tree item?
|
||||
bool IsOk() const { return m_pItem != 0; }
|
||||
// return true if this item is not valid
|
||||
bool operator!() const { return !IsOk(); }
|
||||
|
||||
// operations
|
||||
// invalidate the item
|
||||
void Unset() { m_pItem = 0; }
|
||||
|
||||
operator bool() const { return IsOk(); }
|
||||
|
||||
wxTreeItemIdValue m_pItem;
|
||||
wxTreeItemId() : wxItemId<void*>() { }
|
||||
wxTreeItemId(void* pItem) : wxItemId<void*>(pItem) { }
|
||||
};
|
||||
|
||||
inline bool operator==(const wxTreeItemId& i1, const wxTreeItemId& i2)
|
||||
{
|
||||
return i1.m_pItem == i2.m_pItem;
|
||||
}
|
||||
|
||||
inline bool operator!=(const wxTreeItemId& i1, const wxTreeItemId& i2)
|
||||
{
|
||||
return i1.m_pItem != i2.m_pItem;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxTreeItemData is some (arbitrary) user class associated with some item. The
|
||||
// main advantage of having this class (compared to old untyped interface) is
|
||||
@@ -119,10 +86,12 @@ protected:
|
||||
wxTreeItemId m_pItem;
|
||||
};
|
||||
|
||||
typedef void *wxTreeItemIdValue;
|
||||
|
||||
WX_DEFINE_EXPORTED_ARRAY_PTR(wxTreeItemIdValue, wxArrayTreeItemIdsBase);
|
||||
|
||||
// this is a wrapper around the array class defined above which allow to wok
|
||||
// with vaue of natural wxTreeItemId type instead of using wxTreeItemIdValue
|
||||
// with values of natural wxTreeItemId type instead of using wxTreeItemIdValue
|
||||
// and does it without any loss of efficiency
|
||||
class WXDLLIMPEXP_CORE wxArrayTreeItemIds : public wxArrayTreeItemIdsBase
|
||||
{
|
||||
|
Reference in New Issue
Block a user