+ GtkSortType m_sort_order;
+ wxDataViewColumn *m_dataview_sort_column;
+ int m_sort_column;
+
+ GtkTargetEntry m_dragSourceTargetEntry;
+ wxCharBuffer m_dragSourceTargetEntryTarget;
+ wxDataObject *m_dragDataObject;
+
+ GtkTargetEntry m_dropTargetTargetEntry;
+ wxCharBuffer m_dropTargetTargetEntryTarget;
+ wxDataObject *m_dropDataObject;
+
+ wxGtkDataViewModelNotifier *m_notifier;
+
+ bool m_dirty;
+};
+
+
+//-----------------------------------------------------------------------------
+// wxGtkTreeModelNode
+//-----------------------------------------------------------------------------
+
+static
+int LINKAGEMODE wxGtkTreeModelChildCmp( void** id1, void** id2 )
+{
+ int ret = gs_internal->GetDataViewModel()->Compare( wxDataViewItem(*id1), wxDataViewItem(*id2),
+ gs_internal->GetSortColumn(), (gs_internal->GetSortOrder() == GTK_SORT_ASCENDING) );
+
+ return ret;
+}
+
+WX_DEFINE_ARRAY_PTR( wxGtkTreeModelNode*, wxGtkTreeModelNodes );
+WX_DEFINE_ARRAY_PTR( void*, wxGtkTreeModelChildren );
+
+class wxGtkTreeModelNode
+{
+public:
+ wxGtkTreeModelNode( wxGtkTreeModelNode* parent, const wxDataViewItem &item,
+ wxDataViewCtrlInternal *internal )
+ {
+ m_parent = parent;
+ m_item = item;
+ m_internal = internal;
+ }
+
+ ~wxGtkTreeModelNode()
+ {
+ size_t count = m_nodes.GetCount();
+ size_t i;
+ for (i = 0; i < count; i++)
+ {
+ wxGtkTreeModelNode *child = m_nodes.Item( i );
+ delete child;
+ }
+ }
+
+ void AddNode( wxGtkTreeModelNode* child )
+ {
+ m_nodes.Add( child );
+
+ void *id = child->GetItem().GetID();
+
+ m_children.Add( id );
+
+ if (m_internal->ShouldBeSorted())
+ {
+ gs_internal = m_internal;
+ m_children.Sort( &wxGtkTreeModelChildCmp );
+ }
+ }
+
+ void InsertNode( wxGtkTreeModelNode* child, unsigned pos )
+ {
+ if (m_internal->ShouldBeSorted())
+ {
+ AddNode(child);
+ return;
+ }
+
+ void *id = child->GetItem().GetID();
+
+ // Insert into m_nodes so that the order of nodes in m_nodes is the
+ // same as the order of their corresponding IDs in m_children:
+ const unsigned int count = m_nodes.GetCount();
+ bool inserted = false;
+ for (unsigned i = 0; i < count; i++)
+ {
+ wxGtkTreeModelNode *node = m_nodes[i];
+ int posInChildren = m_children.Index(node->GetItem().GetID());
+ if ( (unsigned)posInChildren >= pos )
+ {
+ m_nodes.Insert(child, i);
+ inserted = true;
+ break;
+ }
+ }
+ if ( !inserted )
+ m_nodes.Add(child);
+
+ m_children.Insert( id, pos );
+ }
+
+ void AddLeaf( void* id )
+ {
+ InsertLeaf(id, m_children.size());
+ }
+
+ void InsertLeaf( void* id, unsigned pos )
+ {
+ m_children.Insert( id, pos );
+
+ if (m_internal->ShouldBeSorted())
+ {
+ gs_internal = m_internal;
+ m_children.Sort( &wxGtkTreeModelChildCmp );
+ }
+ }
+
+ void DeleteChild( void* id )
+ {
+ m_children.Remove( id );
+
+ unsigned int count = m_nodes.GetCount();
+ unsigned int pos;
+ for (pos = 0; pos < count; pos++)
+ {
+ wxGtkTreeModelNode *node = m_nodes.Item( pos );
+ if (node->GetItem().GetID() == id)
+ {
+ m_nodes.RemoveAt( pos );
+ delete node;
+ break;
+ }
+ }
+ }
+
+ // returns position of child node for given item in children list or wxNOT_FOUND
+ int FindChildByItem(const wxDataViewItem& item) const
+ {
+ const void* itemId = item.GetID();
+ const wxGtkTreeModelChildren& nodes = m_children;
+ const int len = nodes.size();
+ for ( int i = 0; i < len; i++ )
+ {
+ if ( nodes[i] == itemId )
+ return i;
+ }
+ return wxNOT_FOUND;
+ }
+
+ wxGtkTreeModelNode* GetParent()
+ { return m_parent; }
+ wxGtkTreeModelNodes &GetNodes()
+ { return m_nodes; }
+ wxGtkTreeModelChildren &GetChildren()
+ { return m_children; }
+
+ unsigned int GetChildCount() const { return m_children.GetCount(); }
+ unsigned int GetNodesCount() const { return m_nodes.GetCount(); }
+
+ wxDataViewItem &GetItem() { return m_item; }
+ wxDataViewCtrlInternal *GetInternal() { return m_internal; }
+
+ void Resort();
+
+private:
+ wxGtkTreeModelNode *m_parent;
+ wxGtkTreeModelNodes m_nodes;
+ wxGtkTreeModelChildren m_children;
+ wxDataViewItem m_item;
+ wxDataViewCtrlInternal *m_internal;