Replace macro-based items array with wxVector in wxDataViewCtrl
No real changes, just try to minimize the use of the old macro-based containers as there is really no reason to do it here.
This commit is contained in:
@@ -35,6 +35,7 @@
|
|||||||
#include "wx/msgdlg.h"
|
#include "wx/msgdlg.h"
|
||||||
#include "wx/dcscreen.h"
|
#include "wx/dcscreen.h"
|
||||||
#include "wx/frame.h"
|
#include "wx/frame.h"
|
||||||
|
#include "wx/vector.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/stockitem.h"
|
#include "wx/stockitem.h"
|
||||||
@@ -422,7 +423,8 @@ public:
|
|||||||
|
|
||||||
class wxDataViewMainWindow;
|
class wxDataViewMainWindow;
|
||||||
class wxDataViewTreeNode;
|
class wxDataViewTreeNode;
|
||||||
WX_DEFINE_ARRAY( wxDataViewTreeNode *, wxDataViewTreeNodes );
|
|
||||||
|
typedef wxVector<wxDataViewTreeNode*> wxDataViewTreeNodes;
|
||||||
|
|
||||||
class wxDataViewTreeNode
|
class wxDataViewTreeNode
|
||||||
{
|
{
|
||||||
@@ -474,7 +476,7 @@ public:
|
|||||||
void RemoveChild(unsigned index)
|
void RemoveChild(unsigned index)
|
||||||
{
|
{
|
||||||
wxCHECK_RET( m_branchData != NULL, "leaf node doesn't have children" );
|
wxCHECK_RET( m_branchData != NULL, "leaf node doesn't have children" );
|
||||||
m_branchData->children.RemoveAt(index);
|
m_branchData->RemoveChild(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns position of child node for given item in children list or wxNOT_FOUND
|
// returns position of child node for given item in children list or wxNOT_FOUND
|
||||||
@@ -525,7 +527,7 @@ public:
|
|||||||
int sum = 0;
|
int sum = 0;
|
||||||
|
|
||||||
const wxDataViewTreeNodes& nodes = m_branchData->children;
|
const wxDataViewTreeNodes& nodes = m_branchData->children;
|
||||||
const int len = nodes.GetCount();
|
const int len = nodes.size();
|
||||||
for ( int i = 0;i < len; i ++)
|
for ( int i = 0;i < len; i ++)
|
||||||
sum += 1 + nodes[i]->GetSubTreeCount();
|
sum += 1 + nodes[i]->GetSubTreeCount();
|
||||||
|
|
||||||
@@ -622,6 +624,16 @@ private:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InsertChild(wxDataViewTreeNode* node, unsigned index)
|
||||||
|
{
|
||||||
|
children.insert(children.begin() + index, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveChild(unsigned index)
|
||||||
|
{
|
||||||
|
children.erase(children.begin() + index);
|
||||||
|
}
|
||||||
|
|
||||||
// Child nodes. Note that this may be empty even if m_hasChildren in
|
// Child nodes. Note that this may be empty even if m_hasChildren in
|
||||||
// case this branch of the tree wasn't expanded and realized yet.
|
// case this branch of the tree wasn't expanded and realized yet.
|
||||||
wxDataViewTreeNodes children;
|
wxDataViewTreeNodes children;
|
||||||
@@ -1660,7 +1672,7 @@ void wxDataViewTreeNode::InsertChild(wxDataViewTreeNode *node, unsigned index)
|
|||||||
// in which case the children are nevertheless sorted (because
|
// in which case the children are nevertheless sorted (because
|
||||||
// there is only one of them), but we need to set the correct sort
|
// there is only one of them), but we need to set the correct sort
|
||||||
// order.
|
// order.
|
||||||
wxASSERT_MSG( !m_parent && m_branchData->children.IsEmpty(),
|
wxASSERT_MSG( !m_parent && m_branchData->children.empty(),
|
||||||
"Logic error in wxDVC sorting code" );
|
"Logic error in wxDVC sorting code" );
|
||||||
|
|
||||||
m_branchData->sortColumn = g_column;
|
m_branchData->sortColumn = g_column;
|
||||||
@@ -1670,7 +1682,7 @@ void wxDataViewTreeNode::InsertChild(wxDataViewTreeNode *node, unsigned index)
|
|||||||
// We can use fast insertion.
|
// We can use fast insertion.
|
||||||
insertSorted = true;
|
insertSorted = true;
|
||||||
}
|
}
|
||||||
else if ( m_branchData->children.IsEmpty() )
|
else if ( m_branchData->children.empty() )
|
||||||
{
|
{
|
||||||
// We're inserting the first child of a closed node. We can choose
|
// We're inserting the first child of a closed node. We can choose
|
||||||
// whether to consider this empty child list sorted or unsorted.
|
// whether to consider this empty child list sorted or unsorted.
|
||||||
@@ -1712,11 +1724,11 @@ void wxDataViewTreeNode::InsertChild(wxDataViewTreeNode *node, unsigned index)
|
|||||||
else
|
else
|
||||||
lo = hi = mid;
|
lo = hi = mid;
|
||||||
}
|
}
|
||||||
m_branchData->children.Insert(node, lo);
|
m_branchData->InsertChild(node, lo);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_branchData->children.Insert(node, index);
|
m_branchData->InsertChild(node, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1742,13 +1754,15 @@ void wxDataViewTreeNode::Resort()
|
|||||||
if ( (g_column != m_branchData->sortColumn) ||
|
if ( (g_column != m_branchData->sortColumn) ||
|
||||||
(g_asending != m_branchData->sortAscending) )
|
(g_asending != m_branchData->sortAscending) )
|
||||||
{
|
{
|
||||||
nodes.Sort(&wxGenericTreeModelNodeCmp);
|
qsort(&m_branchData->children[0], m_branchData->children.size(),
|
||||||
|
sizeof(m_branchData->children[0]),
|
||||||
|
(CMPFUNC)&wxGenericTreeModelNodeCmp);
|
||||||
m_branchData->sortColumn = g_column;
|
m_branchData->sortColumn = g_column;
|
||||||
m_branchData->sortAscending = g_asending;
|
m_branchData->sortAscending = g_asending;
|
||||||
}
|
}
|
||||||
|
|
||||||
// There may be open child nodes that also need a resort.
|
// There may be open child nodes that also need a resort.
|
||||||
int len = nodes.GetCount();
|
int len = nodes.size();
|
||||||
for ( int i = 0; i < len; i++ )
|
for ( int i = 0; i < len; i++ )
|
||||||
{
|
{
|
||||||
if ( nodes[i]->HasChildren() )
|
if ( nodes[i]->HasChildren() )
|
||||||
@@ -1820,7 +1834,7 @@ void wxDataViewTreeNode::PutChildInSortOrder(wxDataViewTreeNode* childNode)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Remove and reinsert the node in the child list
|
// Remove and reinsert the node in the child list
|
||||||
nodes.RemoveAt(oldLocation);
|
m_branchData->RemoveChild(oldLocation);
|
||||||
hi = nodes.size();
|
hi = nodes.size();
|
||||||
int lo = 0;
|
int lo = 0;
|
||||||
while ( lo < hi )
|
while ( lo < hi )
|
||||||
@@ -1834,7 +1848,7 @@ void wxDataViewTreeNode::PutChildInSortOrder(wxDataViewTreeNode* childNode)
|
|||||||
else
|
else
|
||||||
lo = hi = mid;
|
lo = hi = mid;
|
||||||
}
|
}
|
||||||
nodes.Insert(childNode, lo);
|
m_branchData->InsertChild(childNode, lo);
|
||||||
|
|
||||||
// Make sure the change is actually shown right away
|
// Make sure the change is actually shown right away
|
||||||
m_window->UpdateDisplay();
|
m_window->UpdateDisplay();
|
||||||
@@ -3700,7 +3714,7 @@ wxDataViewTreeNode * wxDataViewMainWindow::FindNode( const wxDataViewItem & item
|
|||||||
const wxDataViewTreeNodes& nodes = node->GetChildNodes();
|
const wxDataViewTreeNodes& nodes = node->GetChildNodes();
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
for (unsigned i = 0; i < nodes.GetCount(); ++i)
|
for (unsigned i = 0; i < nodes.size(); ++i)
|
||||||
{
|
{
|
||||||
wxDataViewTreeNode* currentNode = nodes[i];
|
wxDataViewTreeNode* currentNode = nodes[i];
|
||||||
if (currentNode->GetItem() == parentChain[iter])
|
if (currentNode->GetItem() == parentChain[iter])
|
||||||
|
Reference in New Issue
Block a user