diff --git a/Makefile.in b/Makefile.in
index 5484f93194..4a339baefe 100644
--- a/Makefile.in
+++ b/Makefile.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 \
diff --git a/build/bakefiles/files.bkl b/build/bakefiles/files.bkl
index b4434de656..0f59a801da 100644
--- a/build/bakefiles/files.bkl
+++ b/build/bakefiles/files.bkl
@@ -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
diff --git a/build/msw/wx_core.dsp b/build/msw/wx_core.dsp
index b29e9c7732..8f33605177 100644
--- a/build/msw/wx_core.dsp
+++ b/build/msw/wx_core.dsp
@@ -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
diff --git a/build/msw/wx_vc7_core.vcproj b/build/msw/wx_vc7_core.vcproj
index 30aa6ce196..892a799170 100644
--- a/build/msw/wx_vc7_core.vcproj
+++ b/build/msw/wx_vc7_core.vcproj
@@ -5409,6 +5409,9 @@
RelativePath="..\..\include\wx\infobar.h">
+
+
+
+
diff --git a/build/msw/wx_vc9_core.vcproj b/build/msw/wx_vc9_core.vcproj
index 06b39192c0..d8110a956b 100644
--- a/build/msw/wx_vc9_core.vcproj
+++ b/build/msw/wx_vc9_core.vcproj
@@ -7228,6 +7228,10 @@
>
+
+
diff --git a/include/wx/dataview.h b/include/wx/dataview.h
index 96af042c9d..c99fe07fe7 100644
--- a/include/wx/dataview.h
+++ b/include/wx/dataview.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
{
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() { }
+ wxEXPLICIT wxDataViewItem(void* pItem) : wxItemId(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);
// ---------------------------------------------------------
diff --git a/include/wx/itemid.h b/include/wx/itemid.h
new file mode 100644
index 0000000000..fa61195fe8
--- /dev/null
+++ b/include/wx/itemid.h
@@ -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
+// 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
+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
+bool operator==(const wxItemId& left, const wxItemId& right)
+{
+ return left.GetID() == right.GetID();
+}
+
+template
+bool operator!=(const wxItemId& left, const wxItemId& right)
+{
+ return !(left == right);
+}
+
+#endif // _WX_ITEMID_H_
diff --git a/include/wx/treebase.h b/include/wx/treebase.h
index e623660865..4a6063c2f6 100644
--- a/include/wx/treebase.h
+++ b/include/wx/treebase.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
{
- 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() { }
+ wxTreeItemId(void* pItem) : wxItemId(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
{