}
virtual void UpdateDisplay() { Refresh(); }
-
+
// event handlers:
void OnPaint( wxPaintEvent &event );
//-----------------------------------------------------------------------------
// wxDataViewTreeNode
//-----------------------------------------------------------------------------
-class wxDataViewTreeNode;
+class wxDataViewTreeNode;
WX_DEFINE_SORTED_ARRAY( wxDataViewTreeNode *, wxDataViewTreeNodes );
WX_DEFINE_SORTED_ARRAY( void* , wxDataViewTreeLeaves);
wxDataViewTreeNode( wxDataViewTreeNode * parent )
:leaves( wxGenericTreeModelItemCmp ),
nodes(wxGenericTreeModelNodeCmp)
- { this->parent = parent;
+ { this->parent = parent;
if( parent == NULL )
open = true;
- else
- open = false;
+ else
+ open = false;
hasChildren = false;
subTreeCount = 0;
- }
+ }
//I don't know what I need to do in the destructure
~wxDataViewTreeNode()
{
-
+
}
wxDataViewTreeNode * GetParent() { return parent; }
void SetParent( wxDataViewTreeNode * parent ) { this->parent = parent; }
wxDataViewTreeNodes & GetNodes() { return nodes; }
wxDataViewTreeLeaves & GetChildren() { return leaves; }
-
- void AddNode( wxDataViewTreeNode * node )
+
+ void AddNode( wxDataViewTreeNode * node )
{
nodes.Add( node );
leaves.Add( node->GetItem().GetID() );
int GetIndentLevel()
{
int ret = 0 ;
- wxDataViewTreeNode * node = this;
- while( node->GetParent()->GetParent() != NULL )
- {
- node = node->GetParent();
- ret ++;
- }
- return ret;
+ wxDataViewTreeNode * node = this;
+ while( node->GetParent()->GetParent() != NULL )
+ {
+ node = node->GetParent();
+ ret ++;
+ }
+ return ret;
}
- bool IsOpen()
- {
- return open ;
- }
+ bool IsOpen()
+ {
+ return open ;
+ }
void ToggleOpen()
- {
+ {
int len = nodes.GetCount();
int sum = 0;
for ( int i = 0 ;i < len ; i ++)
void SetSubTreeCount( int num ) { subTreeCount = num; }
int GetSubTreeCount() { return subTreeCount; }
- void ChangeSubTreeCount( int num )
+ void ChangeSubTreeCount( int num )
{
if( !open )
return ;
parent->ChangeSubTreeCount(num);
}
+ void Resort()
+ {
+ wxDataViewTreeNodes nds = nodes;
+ wxDataViewTreeLeaves lvs = leaves;
+ nodes.Empty();
+ leaves.Empty();
+
+ int len = nds.GetCount();
+ if(len > 0)
+ {
+ int i;
+ for(i = 0; i < len; i ++)
+ nodes.Add(nds[i]);
+ for(i = 0; i < len; i ++)
+ nodes[i]->Resort();
+ }
+
+ len = lvs.GetCount();
+ if(len > 0)
+ {
+ for(int i = 0; i < len; i++)
+ leaves.Add(lvs[i]);
+ }
+ }
+
private:
wxDataViewTreeNode * parent;
wxDataViewTreeNodes nodes;
wxDataViewTreeLeaves leaves;
- wxDataViewItem item;
+ wxDataViewItem item;
bool open;
bool hasChildren;
int subTreeCount;
// notifications from wxDataViewModel
bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item );
- bool ItemDeleted( const wxDataViewItem &item );
+ bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item );
bool ItemChanged( const wxDataViewItem &item );
bool ValueChanged( const wxDataViewItem &item, unsigned int col );
bool Cleared();
+ void Resort()
+ { g_model = GetOwner()->GetModel(); m_root->Resort(); UpdateDisplay(); }
void SetOwner( wxDataViewCtrl* owner ) { m_owner = owner; }
wxDataViewCtrl *GetOwner() { return m_owner; }
void OnExpanding( unsigned int row );
void OnCollapsing( unsigned int row );
- wxDataViewTreeNode * FindNode( const wxDataViewItem & item );
+ wxDataViewTreeNode * FindNode( const wxDataViewItem & item );
private:
wxDataViewCtrl *m_owner;
wxPen m_penExpander;
//This is the tree structure of the model
- wxDataViewTreeNode * m_root;
+ wxDataViewTreeNode * m_root;
int m_count;
private:
DECLARE_DYNAMIC_CLASS(wxDataViewMainWindow)
virtual bool ItemAdded( const wxDataViewItem & parent, const wxDataViewItem & item )
{ return m_mainWindow->ItemAdded( parent , item ); }
- virtual bool ItemDeleted( const wxDataViewItem & item )
- { return m_mainWindow->ItemDeleted( item ); }
+ virtual bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item )
+ { return m_mainWindow->ItemDeleted( parent, item ); }
virtual bool ItemChanged( const wxDataViewItem & item )
{ return m_mainWindow->ItemChanged(item); }
virtual bool ValueChanged( const wxDataViewItem & item , unsigned int col )
{ return m_mainWindow->ValueChanged( item, col ); }
virtual bool Cleared()
{ return m_mainWindow->Cleared(); }
+ virtual void Resort()
+ { m_mainWindow->Resort(); }
wxDataViewMainWindow *m_mainWindow;
};
}
bool wxDataViewTextRenderer::HasEditorCtrl()
-{
+{
return true;
}
wxControl* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow *parent,
wxRect labelRect, const wxVariant &value )
{
- return new wxTextCtrl( parent, wxID_ANY, value,
+ return new wxTextCtrl( parent, wxID_ANY, value,
wxPoint(labelRect.x,labelRect.y),
wxSize(labelRect.width,labelRect.height) );
}
m_flags |= wxDATAVIEW_COL_SORTABLE;
else
m_flags &= ~wxDATAVIEW_COL_SORTABLE;
-
+
// Update header button
if (GetOwner())
GetOwner()->OnColumnChange();
void wxDataViewColumn::SetSortOrder( bool ascending )
{
m_ascending = ascending;
-
+
// Update header button
if (GetOwner())
GetOwner()->OnColumnChange();
// add the updated array of columns to the header control
unsigned int cols = GetOwner()->GetColumnCount();
unsigned int added = 0;
+ wxDataViewModel * model = GetOwner()->GetModel();
for (unsigned int i = 0; i < cols; i++)
{
wxDataViewColumn *col = GetColumn( i );
case HDN_ITEMCLICK:
{
unsigned int idx = GetColumnIdxFromHeader(nmHDR);
+ wxDataViewModel * model = GetOwner()->GetModel();
+
+ if(nmHDR->iButton == 0)
+ {
+ wxDataViewColumn *col = GetColumn(idx);
+ if(col->IsSortable())
+ {
+ if(model && model->GetSortingColumn() == idx)
+ {
+ bool order = col->IsSortOrderAscending();
+ col->SetSortOrder(!order);
+ // model->SetSortOrderAscending(!order);
+ }
+ else if(model)
+ {
+ model->SetSortingColumn(idx);
+ // model->SetSortOrderAscending(true);
+ }
+ }
+ UpdateDisplay();
+ if(model)
+ model->Resort();
+ }
+
wxEventType evt = nmHDR->iButton == 0 ?
wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK :
wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK;
{
public:
ItemAddJob( const wxDataViewItem & parent, const wxDataViewItem & item, int * count )
- { this->parent = parent ; this->item = item ; m_count = count; }
+ { this->parent = parent ; this->item = item ; m_count = count; }
virtual ~ItemAddJob(){};
virtual int operator() ( wxDataViewTreeNode * node )
default:
;
}
-
+
if( Walker( nd , func ) )
return true;
case DoJob::CONT:
default:
;
- }
+ }
}
return false;
}
void DestroyTreeHelper( wxDataViewTreeNode * node);
-bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem & item)
+bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent,
+ const wxDataViewItem& item)
{
g_model = GetOwner()->GetModel();
wxDataViewTreeNode * node;
- wxDataViewItem parent_item = g_model->GetParent( item );
- node = FindNode(parent_item);
+ node = FindNode(parent);
if( node == NULL || node->GetChildren().Index( item.GetID() ) == wxNOT_FOUND )
{
node->GetChildren().Remove( item.GetID() );
if( GetOwner()->GetModel()->IsContainer( item ) )
{
- wxDataViewTreeNode * n ;
+ wxDataViewTreeNode * n = NULL;
wxDataViewTreeNodes nodes = node->GetNodes();
int len = nodes.GetCount();
for( int i = 0 ; i < len; i ++)
break;
}
}
+
+ if (!n)
+ return false;
+
node->GetNodes().Remove( n );
sub -= n->GetSubTreeCount();
DestroyTreeHelper(n);
node->SetHasChildren( false );
//Make the row number invalid and get a new valid one when user call GetRowCount
- m_count = -1;
+ m_count = -1;
node->ChangeSubTreeCount(sub);
//Change the current row to the last row if the current exceed the max row number
if( m_currentRow > GetRowCount() )
{
// get the cell value and set it into the renderer
wxVariant value;
- wxDataViewTreeNode * node = GetTreeNodeByRow(item);
- if( node == NULL )
- {
- continue;
- }
-
+ wxDataViewTreeNode * node = GetTreeNodeByRow(item);
+ if( node == NULL )
+ {
+ continue;
+ }
+
wxDataViewItem dataitem = node->GetItem();
- model->GetValue( value, dataitem, col->GetModelColumn());
+ model->GetValue( value, dataitem, col->GetModelColumn());
cell->SetValue( value );
// update the y offset
cell_rect.y = item * m_lineHeight;
- //Draw the expander here.
+ //Draw the expander here.
int indent = node->GetIndentLevel();
if( col->GetModelColumn() == GetOwner()->GetExpanderColumn() )
{
//force the expander column to left-center align
cell->SetAlignment( wxALIGN_CENTER_VERTICAL );
}
-
- // cannot be bigger than allocated space
+
+ // cannot be bigger than allocated space
wxSize size = cell->GetSize();
// Because of the tree structure indent, here we should minus the width of the cell for drawing
size.x = wxMin( size.x + 2*PADDING_RIGHTLEFT, cell_rect.width - indent );
//Here we add the tree indent
item_rect.x += indent;
-
+
int state = 0;
if (m_selection.Index(item) != wxNOT_FOUND)
state |= wxDATAVIEW_CELL_SELECTED;
return y / m_lineHeight;
}
-unsigned int wxDataViewMainWindow::GetLastVisibleRow()
+unsigned int wxDataViewMainWindow::GetLastVisibleRow()
{
wxSize client_size = GetClientSize();
m_owner->CalcUnscrolledPosition( client_size.x, client_size.y,
return wxMin( GetRowCount()-1, ((unsigned)client_size.y/m_lineHeight)+1 );
}
-unsigned int wxDataViewMainWindow::GetRowCount()
+unsigned int wxDataViewMainWindow::GetRowCount()
{
if ( m_count == -1 )
{
{
current ++;
if( current == static_cast<int>(row))
- {
+ {
ret = node->GetItem() ;
return DoJob::OK;
}
{
current ++;
if( current == static_cast<int>(row))
- {
+ {
ret = wxDataViewItem( n ) ;
return DoJob::OK;
}
class RowToTreeNodeJob: public DoJob
{
public:
- RowToTreeNodeJob( unsigned int row , int current, wxDataViewTreeNode * node )
- {
- this->row = row;
- this->current = current ;
+ RowToTreeNodeJob( unsigned int row , int current, wxDataViewTreeNode * node )
+ {
+ this->row = row;
+ this->current = current ;
ret = NULL ;
parent = node;
}
{
current ++;
if( current == static_cast<int>(row))
- {
+ {
ret = node ;
return DoJob::OK;
}
{
current ++;
if( current == static_cast<int>(row))
- {
+ {
ret = new wxDataViewTreeNode( parent ) ;
ret->SetItem( wxDataViewItem( n ));
ret->SetHasChildren(false);
return DoJob::OK;
}
-
+
return DoJob::CONT;
}
wxDataViewTreeNode * GetResult(){ return ret; }
public:
CountJob(){ count = 0 ; }
virtual ~CountJob(){};
-
+
virtual int operator () ( wxDataViewTreeNode * node )
{
count ++;
it = model->GetParent( it );
}
- //Find the item along the parent-chain.
+ //Find the item along the parent-chain.
//This algorithm is designed to speed up the node-finding method
bool found = true;
wxDataViewTreeNode * node = m_root;
for( ; j < len; j ++)
{
if( nodes[j]->GetItem() == *(n->GetData()))
- {
+ {
node = nodes[j];
break;
- }
+ }
}
// Whenever we can't find the node in any level, return NULL to indicate the item can't be found
if( j == len )
return node;
}
-int wxDataViewMainWindow::RecalculateCount()
+int wxDataViewMainWindow::RecalculateCount()
{
return m_root->GetSubTreeCount();
}
ret += node->GetSubTreeCount();
return DoJob::IGR;
}
-
+
}
virtual int operator() ( void * n )
ItemList::Node * nd;
wxDataViewItem item;
int ret;
-
+
};
unsigned int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem & item)
{
if( !model->IsContainer( item ) )
return ;
-
+
wxDataViewItem i = model->GetFirstChild( item );
int num = 0;
while( i.IsOk() )
break;
//Add the process for tree expanding/collapsing
case WXK_LEFT:
- OnCollapsing(m_currentRow);
- break;
- case WXK_RIGHT:
- OnExpanding( m_currentRow);
- break;
+ OnCollapsing(m_currentRow);
+ break;
+ case WXK_RIGHT:
+ OnExpanding( m_currentRow);
+ break;
case WXK_END:
if (!IsEmpty())
OnArrowChar( GetRowCount() - 1, event );
m_clientArea->UpdateDisplay();
}
-wxDataViewItem wxDataViewCtrl::GetSelection()
+wxDataViewItem wxDataViewCtrl::GetSelection()
{
return m_clientArea->GetSelection();
}