// wxDataViewHeaderWindow
//-----------------------------------------------------------------------------
-#define USE_NATIVE_HEADER_WINDOW 1
+#define USE_NATIVE_HEADER_WINDOW 0
// NB: for some reason, this class must be dllexport'ed or we get warnings from
// MSVC in DLL build
class wxDataViewTreeNode
{
public:
- wxDataViewTreeNode( wxDataViewTreeNode * parent )
+ wxDataViewTreeNode( wxDataViewTreeNode * parent = NULL )
:leaves( wxGenericTreeModelItemCmp ),
nodes(wxGenericTreeModelNodeCmp)
{ this->parent = parent;
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;
//Below is the compare stuff
//For the generic implements, both the leaf nodes and the nodes are sorted for fast search when needed
static wxDataViewModel * g_model;
+static unsigned int g_column;
+static bool g_asending;
int LINKAGEMODE wxGenericTreeModelNodeCmp( wxDataViewTreeNode * node1, wxDataViewTreeNode * node2)
{
- return g_model->Compare( node1->GetItem(), node2->GetItem() );
+ return g_model->Compare( node1->GetItem(), node2->GetItem(), g_column, g_asending );
}
int LINKAGEMODE wxGenericTreeModelItemCmp( void * id1, void * id2)
{
- return g_model->Compare( id1, id2 );
+ return g_model->Compare( id1, id2, g_column, g_asending );
}
virtual ~wxDataViewMainWindow();
// notifications from wxDataViewModel
+ void SendModelEvent( wxEventType type, const wxDataViewItem & item);
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()
+ {
+ SortPrepare();
+ m_root->Resort();
+ UpdateDisplay();
+ }
+ void SortPrepare()
+ {
+ g_model = GetOwner()->GetModel();
+ g_column = GetOwner()->GetSortingColumn();
+ wxDataViewColumn * col = GetOwner()->GetColumn(g_column);
+ if( !col )
+ {
+ g_asending = true;
+ return;
+ }
+ g_asending = col->IsSortOrderAscending();
+ }
+
void SetOwner( wxDataViewCtrl* owner ) { m_owner = owner; }
wxDataViewCtrl *GetOwner() { return m_owner; }
const wxDataViewCtrl *GetOwner() const { return m_owner; }
void OnRenameTimer();
void ScrollWindow( int dx, int dy, const wxRect *rect = NULL );
+ void ScrollTo( int rows );
bool HasCurrentRow() { return m_currentRow != (unsigned int)-1; }
void ChangeCurrentRow( unsigned int row );
unsigned int GetRowCount() ;
wxDataViewItem GetSelection();
-
+ wxDataViewSelection GetSelections(){ return m_selection; }
+ void SetSelections( const wxDataViewSelection & sel ) { m_selection = sel; UpdateDisplay(); }
void Select( const wxArrayInt& aSelections );
void SelectAllRows( bool on );
void SelectRow( unsigned int row, bool on );
//Some useful functions for row and item mapping
wxDataViewItem GetItemByRow( unsigned int row );
- unsigned int GetRowByItem( const wxDataViewItem & item );
+ int GetRowByItem( const wxDataViewItem & item );
//Methods for building the mapping tree
void BuildTree( wxDataViewModel * model );
void DestroyTree();
+ void HitTest( const wxPoint & point, wxDataViewItem & item, unsigned int & column );
+ wxRect GetItemRect( const wxDataViewItem & item, unsigned int column );
private:
wxDataViewTreeNode * GetTreeNodeByRow( unsigned int row );
//We did not need this temporarily
int RecalculateCount() ;
+ wxDataViewEvent SendExpanderEvent( wxEventType type, const wxDataViewItem & item );
void OnExpanding( unsigned int row );
void OnCollapsing( unsigned int row );
virtual bool ItemAdded( const wxDataViewItem & parent, const wxDataViewItem & item )
{ return m_mainWindow->ItemAdded( parent , item ); }
virtual bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item )
- { return m_mainWindow->ItemDeleted( 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;
};
// 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 );
hdi.cxy = col->GetWidth();
hdi.cchTextMax = sizeof(hdi.pszText)/sizeof(hdi.pszText[0]);
hdi.fmt = HDF_LEFT | HDF_STRING;
+ //hdi.fmt &= ~(HDF_SORTDOWN|HDF_SORTUP);
+
+ //sorting support
+ if(model && m_owner->GetSortingColumn() == i)
+ {
+ //The Microsoft Comctrl32.dll 6.0 support SORTUP/SORTDOWN, but they are not default
+ //see http://msdn2.microsoft.com/en-us/library/ms649534.aspx for more detail
+ //hdi.fmt |= model->GetSortOrderAscending()? HDF_SORTUP:HDF_SORTDOWN;
+ ;
+ }
// lParam is reserved for application's use:
// we store there the column index to use it later in MSWOnNotify
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 && m_owner->GetSortingColumn() == idx)
+ {
+ bool order = col->IsSortOrderAscending();
+ col->SetSortOrder(!order);
+ }
+ else if(model)
+ {
+ m_owner->SetSortingColumn(idx);
+ }
+ }
+ UpdateDisplay();
+ if(model)
+ model->Resort();
+ }
+
wxEventType evt = nmHDR->iButton == 0 ?
wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK :
wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK;
int ch = h;
wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE;
- if (col->IsSortable())
+ if (col->IsSortable() && GetOwner()->GetSortingColumn() == i)
{
if (col->IsSortOrderAscending())
sortArrow = wxHDR_SORT_ICON_UP;
}
else // click on a column
{
+ wxDataViewModel * model = GetOwner()->GetModel();
wxEventType evt = event.LeftDown() ?
wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK :
wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK;
SendEvent(evt, m_column);
+
+ //Left click the header
+ if(event.LeftDown())
+ {
+ wxDataViewColumn *col = GetColumn(m_column);
+ if(col->IsSortable())
+ {
+ unsigned int colnum = m_owner->GetSortingColumn();
+ if(model && static_cast<int>(colnum) == m_column)
+ {
+ bool order = col->IsSortOrderAscending();
+ col->SetSortOrder(!order);
+ }
+ else if(model)
+ {
+ m_owner->SetSortingColumn(m_column);
+ }
+ }
+ UpdateDisplay();
+ if(model)
+ model->Resort();
+ //Send the column sorted event
+ SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, m_column);
+ }
}
}
else if (event.Moving())
virtual int operator() ( void * n ) = 0;
};
-#if 0
-class ItemAddJob: public DoJob
-{
-public:
- ItemAddJob( const wxDataViewItem & parent, const wxDataViewItem & item, int * count )
- { this->parent = parent ; this->item = item ; m_count = count; }
- virtual ~ItemAddJob(){};
-
- virtual int operator() ( wxDataViewTreeNode * node )
- {
- if( node->GetItem() == parent )
- {
- node->SetHasChildren( true );
- wxDataViewTreeNode * newnode = new wxDataViewTreeNode( node );
- newnode->SetItem(item);
- node->AppendChild( newnode);
- *m_count = -1;
- return OK;
- }
- return CONT;
- }
-
-private:
- int * m_count;
- wxDataViewItem parent, item;
-};
-#endif
-
bool Walker( wxDataViewTreeNode * node, DoJob & func )
{
if( node==NULL || !node->HasChildren())
return false;
+ switch( func( node ) )
+ {
+ case DoJob::OK :
+ return true ;
+ case DoJob::IGR:
+ return false;
+ case DoJob::CONT:
+ default:
+ ;
+ }
+
wxDataViewTreeNodes nodes = node->GetNodes();
wxDataViewTreeLeaves leaves = node->GetChildren();
int len_nodes = nodes.GetCount();
int len = leaves.GetCount();
int i = 0, nodes_i = 0;
+
for( ; i < len ; i ++ )
{
void * n = leaves[i];
wxDataViewTreeNode * nd = nodes[nodes_i];
nodes_i++;
- switch( func( nd ) )
- {
- case DoJob::OK :
- return true ;
- case DoJob::IGR:
- continue;
- case DoJob::CONT:
- default:
- ;
- }
-
if( Walker( nd , func ) )
return true;
return false;
}
+void wxDataViewMainWindow::SendModelEvent( wxEventType type, const wxDataViewItem & item )
+{
+ wxWindow *parent = GetParent();
+ wxDataViewEvent le(type, parent->GetId());
+
+ le.SetEventObject(parent);
+ le.SetModel(GetOwner()->GetModel());
+ le.SetItem( item );
+
+ parent->GetEventHandler()->ProcessEvent(le);
+}
+
bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem & parent, const wxDataViewItem & item)
{
- g_model = GetOwner()->GetModel();
+ SortPrepare();
wxDataViewTreeNode * node;
node = FindNode(parent);
+ SendModelEvent(wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_ADDED, item );
if( node == NULL )
return false;
{
wxDataViewTreeNode * newnode = new wxDataViewTreeNode( node );
newnode->SetItem(item);
+ newnode->SetHasChildren( true );
node->AddNode( newnode);
}
else
m_count = -1;
UpdateDisplay();
+
return true;
}
-#if 0
-class ItemDeleteJob: public DoJob
-{
-public:
- ItemDeleteJob( const wxDataViewItem & item, int * count ) { m_item = item; m_count = count; }
- virtual ~ItemDeleteJob(){}
- virtual int operator() ( wxDataViewTreeNode * node )
- {
- if( node->GetItem() == m_item )
- {
- node->GetParent()->GetChildren().Remove( node );
- delete node;
- *m_count = -1;
- return DoJob::OK;
- }
- return DoJob::CONT;
- }
-
-private:
- int * m_count;
- wxDataViewItem m_item;
-};
-#endif
-
void DestroyTreeHelper( wxDataViewTreeNode * node);
-bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem & item)
+bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent,
+ const wxDataViewItem& item)
{
- g_model = GetOwner()->GetModel();
+ SortPrepare();
wxDataViewTreeNode * node;
- wxDataViewItem parent_item = g_model->GetParent( item );
- node = FindNode(parent_item);
+ node = FindNode(parent);
+ SendModelEvent(wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_DELETED, item);
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);
bool wxDataViewMainWindow::ItemChanged(const wxDataViewItem & item)
{
- g_model = GetOwner()->GetModel();
+ SortPrepare();
+ g_model->Resort();
+
+ SendModelEvent(wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_CHANGED,item);
- unsigned int row = GetRowByItem(item);
- RefreshRow( row );
return true;
}
-bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem & item, unsigned int WXUNUSED(col) )
+bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem & item, unsigned int col )
{
// NOTE: to be valid, we cannot use e.g. INT_MAX - 1
/*#define MAX_VIRTUAL_WIDTH 100000
return true;
*/
- g_model = GetOwner()->GetModel();
+ SortPrepare();
+ g_model->Resort();
+
+ //Send event
+ wxWindow *parent = GetParent();
+ wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_MODEL_VALUE_CHANGED, parent->GetId());
+ le.SetEventObject(parent);
+ le.SetModel(GetOwner()->GetModel());
+ le.SetItem(item);
+ le.SetColumn(col);
+ le.SetDataViewColumn(GetOwner()->GetColumn(col));
+ parent->GetEventHandler()->ProcessEvent(le);
- unsigned int row = GetRowByItem(item);
- RefreshRow( row );
return true;
}
bool wxDataViewMainWindow::Cleared()
{
- g_model = GetOwner()->GetModel();
+ SortPrepare();
DestroyTree();
UpdateDisplay();
+
+ wxWindow *parent = GetParent();
+ wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_MODEL_CLEARED, parent->GetId());
+ le.SetEventObject(parent);
+ le.SetModel(GetOwner()->GetModel());
+ parent->GetEventHandler()->ProcessEvent(le);
+
return true;
}
GetOwner()->m_headerArea->ScrollWindow( dx, 0 );
}
+void wxDataViewMainWindow::ScrollTo( int rows )
+{
+ int x, y;
+ m_owner->GetScrollPixelsPerUnit( &x, &y );
+ int sc = rows*m_lineHeight/y;
+ m_owner->Scroll(0, sc );
+}
+
void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
{
wxDataViewModel *model = GetOwner()->GetModel();
return DoJob::IGR;
}
else
+ {
+ //If the current has no child node, we can find the desired item of the row number directly.
+ //This if can speed up finding in some case, and will has a very good effect when it comes to list view
+ if( node->GetNodes().GetCount() == 0)
+ {
+ int index = static_cast<int>(row) - current - 1;
+ ret = node->GetChildren().Item( index );
+ return DoJob::OK;
+ }
return DoJob::CONT;
+ }
}
virtual int operator() ( void * n )
wxDataViewItem wxDataViewMainWindow::GetItemByRow(unsigned int row)
{
- RowToItemJob job( row, -1 );
+ RowToItemJob job( row, -2 );
Walker( m_root , job );
return job.GetResult();
}
else
{
parent = node;
+ //If the current has no child node, we can find the desired item of the row number directly.
+ //This if can speed up finding in some case, and will has a very good effect when it comes to list view
+ if( node->GetNodes().GetCount() == 0)
+ {
+ int index = static_cast<int>(row) - current - 1;
+ void * n = node->GetChildren().Item( index );
+ ret = new wxDataViewTreeNode( parent ) ;
+ ret->SetItem( wxDataViewItem( n ));
+ ret->SetHasChildren(false);
+ return DoJob::OK;
+ }
return DoJob::CONT;
}
+
}
virtual int operator() ( void * n )
wxDataViewTreeNode * wxDataViewMainWindow::GetTreeNodeByRow(unsigned int row)
{
- RowToTreeNodeJob job( row , -1, m_root );
+ RowToTreeNodeJob job( row , -2, m_root );
Walker( m_root , job );
return job.GetResult();
}
-#if 0
-class CountJob : public DoJob
+wxDataViewEvent wxDataViewMainWindow::SendExpanderEvent( wxEventType type, const wxDataViewItem & item )
{
-public:
- CountJob(){ count = 0 ; }
- virtual ~CountJob(){};
+ wxWindow *parent = GetParent();
+ wxDataViewEvent le(type, parent->GetId());
- virtual int operator () ( wxDataViewTreeNode * node )
- {
- count ++;
- if ( node->IsOpen())
- return DoJob::CONT;
- else
- return DoJob::IGR;
- }
+ le.SetEventObject(parent);
+ le.SetModel(GetOwner()->GetModel());
+ le.SetItem( item );
- unsigned int GetResult()
- {
- return count ;
- }
-private:
- unsigned int count;
-};
-#endif
+ parent->GetEventHandler()->ProcessEvent(le);
+ return le;
+}
void wxDataViewMainWindow::OnExpanding( unsigned int row )
{
if( node != NULL )
{
if( node->HasChildren())
+ {
if( !node->IsOpen())
{
+ wxDataViewEvent e = SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING,node->GetItem());
+ //Check if the user prevent expanding
+ if( e.GetSkipped() )
+ return;
+
node->ToggleOpen();
//Here I build the children of current node
if( node->GetChildrenNumber() == 0 )
BuildTreeHelper(GetOwner()->GetModel(), node->GetItem(), node);
m_count = -1;
UpdateDisplay();
+ //Send the expanded event
+ SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED,node->GetItem());
}
else
{
SelectRow( row + 1, true );
ChangeCurrentRow( row + 1 );
}
+ }
else
delete node;
}
if( node->HasChildren() && node->IsOpen() )
{
+ wxDataViewEvent e = SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING,node->GetItem());
+ if( e.GetSkipped() )
+ return;
node->ToggleOpen();
m_count = -1;
UpdateDisplay();
- //RefreshRows(row,GetLastVisibleRow());
- }
- else
- {
- node = node->GetParent();
- if( node != NULL )
- {
- int parent = GetRowByItem( node->GetItem()) ;
- SelectRow( row, false);
- SelectRow(parent , true );
- ChangeCurrentRow( parent );
- }
- }
- if( !nd->HasChildren())
- delete nd;
+ SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED,nd->GetItem());
+ }
+ else
+ {
+ node = node->GetParent();
+ if( node != NULL )
+ {
+ int parent = GetRowByItem( node->GetItem() ) ;
+ if( parent >= 0 )
+ {
+ SelectRow( row, false);
+ SelectRow(parent , true );
+ ChangeCurrentRow( parent );
+ }
+ }
+ }
+ if( !nd->HasChildren())
+ delete nd;
}
}
//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( ItemList::Node * n = list.GetFirst(); n; n = n->GetNext() )
{
if( node->GetChildrenNumber() == 0 )
BuildTreeHelper(model, node->GetItem(), node);
- int len = node->GetNodeNumber();
wxDataViewTreeNodes nodes = node->GetNodes();
- int j = 0;
- 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 )
- {
- found = false;
+ //The wxSortedArray search a node in binary search, so using Item() is more efficient
+ wxDataViewTreeNode temp;
+ temp.SetItem(*(n->GetData()));
+ int index = nodes.Index( &temp );
+ if( index == wxNOT_FOUND )
return NULL;
- }
+ node = nodes[index];
}
else
return NULL;
return node;
}
+void wxDataViewMainWindow::HitTest( const wxPoint & point, wxDataViewItem & item, unsigned int & column )
+{
+ unsigned int cols = GetOwner()->GetColumnCount();
+ unsigned int colnum = 0;
+ unsigned int x_start = 0;
+ int x, y;
+ m_owner->CalcUnscrolledPosition( point.x, point.y, &x, &y );
+ for (x_start = 0; colnum < cols; colnum++)
+ {
+ wxDataViewColumn *col = GetOwner()->GetColumn(colnum);
+ if (col->IsHidden())
+ continue; // skip it!
+
+ unsigned int w = col->GetWidth();
+ if (x_start+w >= (unsigned int)x)
+ break;
+
+ x_start += w;
+ }
+
+ column = colnum;
+ item = GetItemByRow( y/m_lineHeight );
+}
+
+wxRect wxDataViewMainWindow::GetItemRect( const wxDataViewItem & item, unsigned int column )
+{
+ int row = GetRowByItem(item);
+ int y = row*m_lineHeight;
+ int h = m_lineHeight;
+ int x = 0;
+ wxDataViewColumn *col = NULL;
+ for( int i = 0, cols = GetOwner()->GetColumnCount(); i < cols; i ++ )
+ {
+ col = GetOwner()->GetColumn( i );
+ x += col->GetWidth();
+ if( i == column - 1 )
+ break;
+ }
+ int w = col->GetWidth();
+ m_owner->CalcScrolledPosition( x, y, &x, &y );
+ return wxRect(x, y, w, h);
+}
+
int wxDataViewMainWindow::RecalculateCount()
{
return m_root->GetSubTreeCount();
{
public:
ItemToRowJob(const wxDataViewItem & item, ItemList::Node * node )
- { this->item = item ; ret = 0 ; nd = node ; }
+ { this->item = item ; ret = -1 ; nd = node ; }
virtual ~ItemToRowJob(){};
+ //Maybe binary search will help to speed up this process
virtual int operator() ( wxDataViewTreeNode * node)
{
ret ++;
};
-unsigned int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem & item)
+int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem & item)
{
wxDataViewModel * model = GetOwner()->GetModel();
if( model == NULL )
return 0;
+ if( !item.IsOk() )
+ return -1;
+
//Compose the a parent-chain of the finding item
ItemList list;
+ wxDataViewItem * pItem = NULL;
list.DeleteContents( true );
wxDataViewItem it( item );
while( it.IsOk() )
{
- wxDataViewItem * pItem = new wxDataViewItem( it );
+ pItem = new wxDataViewItem( it );
list.Insert( pItem );
it = model->GetParent( it );
}
+ pItem = new wxDataViewItem( );
+ list.Insert( pItem );
ItemToRowJob job( item, list.GetFirst() );
Walker(m_root , job );
{
//First we define a invalid item to fetch the top-level elements
wxDataViewItem item;
- g_model = GetOwner()->GetModel();
+ SortPrepare();
BuildTreeHelper( model, item, m_root);
m_count = -1 ;
}
wxRect cell_rect( xpos, current * m_lineHeight,
col->GetWidth(), m_lineHeight );
cell->Activate( cell_rect, model, item, col->GetModelColumn() );
+
+ wxWindow *parent = GetParent();
+ wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, parent->GetId());
+
+ le.SetEventObject(parent);
+ le.SetColumn(col->GetModelColumn());
+ le.SetDataViewColumn(col);
+ le.SetModel(GetOwner()->GetModel());
+
+ parent->GetEventHandler()->ProcessEvent(le);
}
return;
}
m_clientArea->UpdateDisplay();
}
+//Selection code with wxDataViewItem as parameters
wxDataViewItem wxDataViewCtrl::GetSelection()
{
return m_clientArea->GetSelection();
}
-/********************************************************************
-void wxDataViewCtrl::SetSelection( int row )
+int wxDataViewCtrl::GetSelections( wxDataViewItemArray & sel ) const
+{
+ sel.Empty();
+ wxDataViewSelection selection = m_clientArea->GetSelections();
+ int len = selection.GetCount();
+ for( int i = 0; i < len; i ++)
+ {
+ unsigned int row = selection[i];
+ sel.Add( m_clientArea->GetItemByRow( row ) );
+ }
+ return len;
+}
+
+void wxDataViewCtrl::SetSelections( const wxDataViewItemArray & sel )
+{
+ wxDataViewSelection selection(wxDataViewSelectionCmp) ;
+ int len = sel.GetCount();
+ for( int i = 0; i < len; i ++ )
+ {
+ int row = m_clientArea->GetRowByItem( sel[i] );
+ if( row >= 0 )
+ selection.Add( static_cast<unsigned int>(row) );
+ }
+ m_clientArea->SetSelections( selection );
+}
+
+void wxDataViewCtrl::Select( const wxDataViewItem & item )
{
- m_clientArea->SelectRow(row, true);
+ int row = m_clientArea->GetRowByItem( item );
+ if( row >= 0 )
+ m_clientArea->SelectRow(row, true);
}
-void wxDataViewCtrl::SetSelectionRange( unsigned int from, unsigned int to )
+void wxDataViewCtrl::Unselect( const wxDataViewItem & item )
{
- m_clientArea->SelectRows(from, to, true);
+ int row = m_clientArea->GetRowByItem( item );
+ if( row >= 0 )
+ m_clientArea->SelectRow(row, false);
}
-void wxDataViewCtrl::SetSelections( const wxArrayInt& aSelections )
+bool wxDataViewCtrl::IsSelected( const wxDataViewItem & item ) const
{
- m_clientArea->Select(aSelections);
+ int row = m_clientArea->GetRowByItem( item );
+ if( row >= 0 )
+ {
+ return m_clientArea->IsRowSelected(row);
+ }
+ return false;
+}
+
+//Selection code with row number as parameter
+int wxDataViewCtrl::GetSelections( wxArrayInt & sel ) const
+{
+ sel.Empty();
+ wxDataViewSelection selection = m_clientArea->GetSelections();
+ int len = selection.GetCount();
+ for( int i = 0; i < len; i ++)
+ {
+ unsigned int row = selection[i];
+ sel.Add( row );
+ }
+ return len;
+}
+
+void wxDataViewCtrl::SetSelections( const wxArrayInt & sel )
+{
+ wxDataViewSelection selection(wxDataViewSelectionCmp) ;
+ int len = sel.GetCount();
+ for( int i = 0; i < len; i ++ )
+ {
+ int row = sel[i];
+ if( row >= 0 )
+ selection.Add( static_cast<unsigned int>(row) );
+ }
+ m_clientArea->SetSelections( selection );
}
-void wxDataViewCtrl::Unselect( unsigned int WXUNUSED(row) )
+void wxDataViewCtrl::Select( int row )
{
- // FIXME - TODO
+ if( row >= 0 )
+ m_clientArea->SelectRow( row, true );
}
-bool wxDataViewCtrl::IsSelected( unsigned int WXUNUSED(row) ) const
+void wxDataViewCtrl::Unselect( int row )
{
- // FIXME - TODO
+ if( row >= 0 )
+ m_clientArea->SelectRow(row, false);
+}
+bool wxDataViewCtrl::IsSelected( int row ) const
+{
+ if( row >= 0 )
+ return m_clientArea->IsRowSelected(row);
return false;
}
-int wxDataViewCtrl::GetSelection() const
+void wxDataViewCtrl::SelectRange( int from, int to )
{
- // FIXME - TODO
+ wxArrayInt sel;
+ for( int i = from; i < to; i ++ )
+ sel.Add( i );
+ m_clientArea->Select(sel);
+}
- return -1;
+void wxDataViewCtrl::UnselectRange( int from, int to )
+{
+ wxDataViewSelection sel = m_clientArea->GetSelections();
+ for( int i = from; i < to; i ++ )
+ if( sel.Index( i ) != wxNOT_FOUND )
+ sel.Remove( i );
+ m_clientArea->SetSelections(sel);
+}
+
+void wxDataViewCtrl::SelectAll()
+{
+ m_clientArea->SelectAllRows(true);
}
-int wxDataViewCtrl::GetSelections(wxArrayInt& WXUNUSED(aSelections) ) const
+void wxDataViewCtrl::UnselectAll()
{
- // FIXME - TODO
+ m_clientArea->SelectAllRows(false);
+}
- return 0;
+void wxDataViewCtrl::EnsureVisible( int row )
+{
+ m_clientArea->ScrollTo( row );
}
-*********************************************************************/
-#endif
+
+void wxDataViewCtrl::EnsureVisible( const wxDataViewItem & item, wxDataViewColumn * column )
+{
+ int row = m_clientArea->GetRowByItem(item);
+ if( row >= 0 )
+ EnsureVisible(row);
+}
+
+void wxDataViewCtrl::HitTest( const wxPoint & point, wxDataViewItem & item, unsigned int & column ) const
+{
+ m_clientArea->HitTest(point, item, column);
+}
+
+wxRect wxDataViewCtrl::GetItemRect( const wxDataViewItem & item, unsigned int column ) const
+{
+ return m_clientArea->GetItemRect(item, column);
+}
+
+wxDataViewItem wxDataViewCtrl::GetItemByRow( unsigned int row ) const
+{
+ return m_clientArea->GetItemByRow( row );
+}
+
+int wxDataViewCtrl::GetRowByItem( const wxDataViewItem & item ) const
+{
+ return m_clientArea->GetRowByItem( item );
+}
+
+ #endif
// !wxUSE_GENERICDATAVIEWCTRL
#endif