wx/helphtml.h \
wx/icon.h \
wx/infobar.h \
+ wx/itemid.h \
wx/layout.h \
wx/listbox.h \
wx/mdi.h \
wx/helphtml.h
wx/icon.h
wx/infobar.h
+ wx/itemid.h
wx/layout.h
wx/listbox.h
wx/mdi.h
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\..\include\wx\itemid.h
+# End Source File
+# Begin Source File
+
SOURCE=..\..\include\wx\joystick.h\r
# End Source File\r
# Begin Source File\r
RelativePath="..\..\include\wx\infobar.h">\r
</File>\r
<File\r
+ RelativePath="..\..\include\wx\itemid.h">
+ </File>
+ <File
RelativePath="..\..\include\wx\joystick.h">\r
</File>\r
<File\r
>\r
</File>\r
<File\r
+ RelativePath="..\..\include\wx\itemid.h"
+ >
+ </File>
+ <File
RelativePath="..\..\include\wx\joystick.h"\r
>\r
</File>\r
>\r
</File>\r
<File\r
+ RelativePath="..\..\include\wx\itemid.h"
+ >
+ </File>
+ <File
RelativePath="..\..\include\wx\joystick.h"\r
>\r
</File>\r
#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"
// wxDataViewCtrl globals
// ----------------------------------------------------------------------------
-class WXDLLIMPEXP_FWD_ADV wxDataViewItem;
class WXDLLIMPEXP_FWD_ADV wxDataViewModel;
class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl;
class WXDLLIMPEXP_FWD_ADV wxDataViewColumn;
// 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);
// ---------------------------------------------------------
--- /dev/null
+///////////////////////////////////////////////////////////////////////////////
+// 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_
#include "wx/window.h" // for wxClientData
#include "wx/event.h"
#include "wx/dynarray.h"
+#include "wx/itemid.h"
#if WXWIN_COMPATIBILITY_2_6
#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
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
{