Applied patch from Bo, WIP
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48424 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -328,7 +328,8 @@ class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase,
|
|||||||
public:
|
public:
|
||||||
wxDataViewCtrl() : wxScrollHelperNative(this)
|
wxDataViewCtrl() : wxScrollHelperNative(this)
|
||||||
{
|
{
|
||||||
m_sortingColumn = 0;
|
//No sorting column at start, I think
|
||||||
|
m_sortingColumn = NULL;
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -338,6 +339,7 @@ public:
|
|||||||
const wxValidator& validator = wxDefaultValidator )
|
const wxValidator& validator = wxDefaultValidator )
|
||||||
: wxScrollHelperNative(this)
|
: wxScrollHelperNative(this)
|
||||||
{
|
{
|
||||||
|
m_sortingColumn = NULL;
|
||||||
Create(parent, id, pos, size, style, validator );
|
Create(parent, id, pos, size, style, validator );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -393,8 +395,8 @@ protected:
|
|||||||
virtual wxDataViewItem GetItemByRow( unsigned int row ) const;
|
virtual wxDataViewItem GetItemByRow( unsigned int row ) const;
|
||||||
virtual int GetRowByItem( const wxDataViewItem & item ) const;
|
virtual int GetRowByItem( const wxDataViewItem & item ) const;
|
||||||
|
|
||||||
unsigned int GetSortingColumn() { return m_sortingColumn; }
|
wxDataViewColumn* GetSortingColumn() { return m_sortingColumn; }
|
||||||
void SetSortingColumn( unsigned int column ) { m_sortingColumn = column; }
|
void SetSortingColumn( wxDataViewColumn* column ) { m_sortingColumn = column; }
|
||||||
|
|
||||||
public: // utility functions not part of the API
|
public: // utility functions not part of the API
|
||||||
|
|
||||||
@@ -414,7 +416,7 @@ private:
|
|||||||
wxDataViewModelNotifier *m_notifier;
|
wxDataViewModelNotifier *m_notifier;
|
||||||
wxDataViewMainWindow *m_clientArea;
|
wxDataViewMainWindow *m_clientArea;
|
||||||
wxDataViewHeaderWindow *m_headerArea;
|
wxDataViewHeaderWindow *m_headerArea;
|
||||||
unsigned int m_sortingColumn;
|
wxDataViewColumn* m_sortingColumn;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void OnSize( wxSizeEvent &event );
|
void OnSize( wxSizeEvent &event );
|
||||||
|
@@ -68,6 +68,12 @@ static const int EXPANDER_MARGIN = 4;
|
|||||||
|
|
||||||
#define USE_NATIVE_HEADER_WINDOW 0
|
#define USE_NATIVE_HEADER_WINDOW 0
|
||||||
|
|
||||||
|
//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 int g_column;
|
||||||
|
static bool g_asending;
|
||||||
|
|
||||||
// NB: for some reason, this class must be dllexport'ed or we get warnings from
|
// NB: for some reason, this class must be dllexport'ed or we get warnings from
|
||||||
// MSVC in DLL build
|
// MSVC in DLL build
|
||||||
class WXDLLIMPEXP_ADV wxDataViewHeaderWindowBase : public wxControl
|
class WXDLLIMPEXP_ADV wxDataViewHeaderWindowBase : public wxControl
|
||||||
@@ -254,18 +260,16 @@ public:
|
|||||||
// wxDataViewTreeNode
|
// wxDataViewTreeNode
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
class wxDataViewTreeNode;
|
class wxDataViewTreeNode;
|
||||||
WX_DEFINE_SORTED_ARRAY( wxDataViewTreeNode *, wxDataViewTreeNodes );
|
WX_DEFINE_ARRAY( wxDataViewTreeNode *, wxDataViewTreeNodes );
|
||||||
WX_DEFINE_SORTED_ARRAY( void* , wxDataViewTreeLeaves);
|
WX_DEFINE_ARRAY( void* , wxDataViewTreeLeaves);
|
||||||
|
|
||||||
int LINKAGEMODE wxGenericTreeModelNodeCmp( wxDataViewTreeNode * node1, wxDataViewTreeNode * node2);
|
int LINKAGEMODE wxGenericTreeModelNodeCmp( wxDataViewTreeNode ** node1, wxDataViewTreeNode ** node2);
|
||||||
int LINKAGEMODE wxGenericTreeModelItemCmp( void * id1, void * id2);
|
int LINKAGEMODE wxGenericTreeModelItemCmp( void ** id1, void ** id2);
|
||||||
|
|
||||||
class wxDataViewTreeNode
|
class wxDataViewTreeNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxDataViewTreeNode( wxDataViewTreeNode * parent = NULL )
|
wxDataViewTreeNode( wxDataViewTreeNode * parent = NULL )
|
||||||
:leaves( wxGenericTreeModelItemCmp ),
|
|
||||||
nodes(wxGenericTreeModelNodeCmp)
|
|
||||||
{ this->parent = parent;
|
{ this->parent = parent;
|
||||||
if( parent == NULL )
|
if( parent == NULL )
|
||||||
open = true;
|
open = true;
|
||||||
@@ -287,10 +291,19 @@ public:
|
|||||||
|
|
||||||
void AddNode( wxDataViewTreeNode * node )
|
void AddNode( wxDataViewTreeNode * node )
|
||||||
{
|
{
|
||||||
nodes.Add( node );
|
|
||||||
leaves.Add( node->GetItem().GetID() );
|
leaves.Add( node->GetItem().GetID() );
|
||||||
|
if (g_column >= 0)
|
||||||
|
leaves.Sort( &wxGenericTreeModelItemCmp );
|
||||||
|
nodes.Add( node );
|
||||||
|
if (g_column >= 0)
|
||||||
|
nodes.Sort( &wxGenericTreeModelNodeCmp );
|
||||||
|
}
|
||||||
|
void AddLeaf( void * leaf )
|
||||||
|
{
|
||||||
|
leaves.Add( leaf );
|
||||||
|
if (g_column >= 0)
|
||||||
|
leaves.Sort( &wxGenericTreeModelItemCmp );
|
||||||
}
|
}
|
||||||
void AddLeaf( void * leaf ) { leaves.Add( leaf ); }
|
|
||||||
|
|
||||||
wxDataViewItem & GetItem() { return item; }
|
wxDataViewItem & GetItem() { return item; }
|
||||||
void SetItem( const wxDataViewItem & item ) { this->item = item; }
|
void SetItem( const wxDataViewItem & item ) { this->item = item; }
|
||||||
@@ -349,26 +362,15 @@ public:
|
|||||||
|
|
||||||
void Resort()
|
void Resort()
|
||||||
{
|
{
|
||||||
wxDataViewTreeNodes nds = nodes;
|
if (g_column >= 0)
|
||||||
wxDataViewTreeLeaves lvs = leaves;
|
|
||||||
nodes.Empty();
|
|
||||||
leaves.Empty();
|
|
||||||
|
|
||||||
int len = nds.GetCount();
|
|
||||||
if(len > 0)
|
|
||||||
{
|
{
|
||||||
int i;
|
nodes.Sort( &wxGenericTreeModelNodeCmp );
|
||||||
for(i = 0; i < len; i ++)
|
int len = nodes.GetCount();
|
||||||
nodes.Add(nds[i]);
|
for (int i = 0; i < len; i ++)
|
||||||
for(i = 0; i < len; i ++)
|
{
|
||||||
nodes[i]->Resort();
|
nodes[i]->Resort();
|
||||||
}
|
}
|
||||||
|
leaves.Sort( &wxGenericTreeModelItemCmp );
|
||||||
len = lvs.GetCount();
|
|
||||||
if(len > 0)
|
|
||||||
{
|
|
||||||
for(int i = 0; i < len; i++)
|
|
||||||
leaves.Add(lvs[i]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -382,20 +384,14 @@ private:
|
|||||||
int subTreeCount;
|
int subTreeCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
//Below is the compare stuff
|
int LINKAGEMODE wxGenericTreeModelNodeCmp( wxDataViewTreeNode ** node1, wxDataViewTreeNode ** node2)
|
||||||
//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(), g_column, g_asending );
|
return g_model->Compare( (*node1)->GetItem(), (*node2)->GetItem(), g_column, g_asending );
|
||||||
}
|
}
|
||||||
|
|
||||||
int LINKAGEMODE wxGenericTreeModelItemCmp( void * id1, void * id2)
|
int LINKAGEMODE wxGenericTreeModelItemCmp( void ** id1, void ** id2)
|
||||||
{
|
{
|
||||||
return g_model->Compare( id1, id2, g_column, g_asending );
|
return g_model->Compare( *id1, *id2, g_column, g_asending );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -436,13 +432,14 @@ public:
|
|||||||
void SortPrepare()
|
void SortPrepare()
|
||||||
{
|
{
|
||||||
g_model = GetOwner()->GetModel();
|
g_model = GetOwner()->GetModel();
|
||||||
g_column = GetOwner()->GetSortingColumn();
|
wxDataViewColumn* col = GetOwner()->GetSortingColumn();
|
||||||
wxDataViewColumn * col = GetOwner()->GetColumn(g_column);
|
|
||||||
if( !col )
|
if( !col )
|
||||||
{
|
{
|
||||||
|
g_column = -1;
|
||||||
g_asending = true;
|
g_asending = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
g_column = col->GetModelColumn();
|
||||||
g_asending = col->IsSortOrderAscending();
|
g_asending = col->IsSortOrderAscending();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1222,7 +1219,7 @@ void wxDataViewHeaderWindowMSW::UpdateDisplay()
|
|||||||
//hdi.fmt &= ~(HDF_SORTDOWN|HDF_SORTUP);
|
//hdi.fmt &= ~(HDF_SORTDOWN|HDF_SORTUP);
|
||||||
|
|
||||||
//sorting support
|
//sorting support
|
||||||
if(model && m_owner->GetSortingColumn() == i)
|
if(model && m_owner->GetSortingColumn() == col)
|
||||||
{
|
{
|
||||||
//The Microsoft Comctrl32.dll 6.0 support SORTUP/SORTDOWN, but they are not default
|
//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
|
//see http://msdn2.microsoft.com/en-us/library/ms649534.aspx for more detail
|
||||||
@@ -1357,14 +1354,14 @@ bool wxDataViewHeaderWindowMSW::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARA
|
|||||||
wxDataViewColumn *col = GetColumn(idx);
|
wxDataViewColumn *col = GetColumn(idx);
|
||||||
if(col->IsSortable())
|
if(col->IsSortable())
|
||||||
{
|
{
|
||||||
if(model && m_owner->GetSortingColumn() == idx)
|
if(model && m_owner->GetSortingColumn() == col)
|
||||||
{
|
{
|
||||||
bool order = col->IsSortOrderAscending();
|
bool order = col->IsSortOrderAscending();
|
||||||
col->SetSortOrder(!order);
|
col->SetSortOrder(!order);
|
||||||
}
|
}
|
||||||
else if(model)
|
else if(model)
|
||||||
{
|
{
|
||||||
m_owner->SetSortingColumn(idx);
|
m_owner->SetSortingColumn(col);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UpdateDisplay();
|
UpdateDisplay();
|
||||||
@@ -1528,7 +1525,7 @@ void wxGenericDataViewHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
|||||||
int ch = h;
|
int ch = h;
|
||||||
|
|
||||||
wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE;
|
wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE;
|
||||||
if (col->IsSortable() && GetOwner()->GetSortingColumn() == i)
|
if (col->IsSortable() && GetOwner()->GetSortingColumn() == col)
|
||||||
{
|
{
|
||||||
if (col->IsSortOrderAscending())
|
if (col->IsSortOrderAscending())
|
||||||
sortArrow = wxHDR_SORT_ICON_UP;
|
sortArrow = wxHDR_SORT_ICON_UP;
|
||||||
@@ -1693,15 +1690,15 @@ void wxGenericDataViewHeaderWindow::OnMouse( wxMouseEvent &event )
|
|||||||
wxDataViewColumn *col = GetColumn(m_column);
|
wxDataViewColumn *col = GetColumn(m_column);
|
||||||
if(col->IsSortable())
|
if(col->IsSortable())
|
||||||
{
|
{
|
||||||
unsigned int colnum = m_owner->GetSortingColumn();
|
wxDataViewColumn* sortCol = m_owner->GetSortingColumn();
|
||||||
if(model && static_cast<int>(colnum) == m_column)
|
if(model && sortCol == col)
|
||||||
{
|
{
|
||||||
bool order = col->IsSortOrderAscending();
|
bool order = col->IsSortOrderAscending();
|
||||||
col->SetSortOrder(!order);
|
col->SetSortOrder(!order);
|
||||||
}
|
}
|
||||||
else if(model)
|
else if(model)
|
||||||
{
|
{
|
||||||
m_owner->SetSortingColumn(m_column);
|
m_owner->SetSortingColumn(col);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UpdateDisplay();
|
UpdateDisplay();
|
||||||
@@ -2016,9 +2013,7 @@ bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent,
|
|||||||
//Manuplate selection
|
//Manuplate selection
|
||||||
if( m_selection.GetCount() > 1 )
|
if( m_selection.GetCount() > 1 )
|
||||||
{
|
{
|
||||||
int row = m_selection[0];
|
|
||||||
m_selection.Empty();
|
m_selection.Empty();
|
||||||
m_selection.Add(row);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( GetOwner()->GetModel()->IsContainer( item ) )
|
if( GetOwner()->GetModel()->IsContainer( item ) )
|
||||||
@@ -3407,9 +3402,7 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
|
|||||||
}
|
}
|
||||||
if (event.LeftDown() || forceClick)
|
if (event.LeftDown() || forceClick)
|
||||||
{
|
{
|
||||||
#ifdef __WXMSW__
|
|
||||||
SetFocus();
|
SetFocus();
|
||||||
#endif
|
|
||||||
|
|
||||||
m_lineBeforeLastClicked = m_lineLastClicked;
|
m_lineBeforeLastClicked = m_lineLastClicked;
|
||||||
m_lineLastClicked = current;
|
m_lineLastClicked = current;
|
||||||
@@ -3713,7 +3706,12 @@ void wxDataViewCtrl::Select( const wxDataViewItem & item )
|
|||||||
{
|
{
|
||||||
int row = m_clientArea->GetRowByItem( item );
|
int row = m_clientArea->GetRowByItem( item );
|
||||||
if( row >= 0 )
|
if( row >= 0 )
|
||||||
|
{
|
||||||
|
//Unselect all rows before select another in the single select mode
|
||||||
|
if (m_clientArea->IsSingleSel())
|
||||||
|
m_clientArea->SelectAllRows(false);
|
||||||
m_clientArea->SelectRow(row, true);
|
m_clientArea->SelectRow(row, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxDataViewCtrl::Unselect( const wxDataViewItem & item )
|
void wxDataViewCtrl::Unselect( const wxDataViewItem & item )
|
||||||
@@ -3763,7 +3761,11 @@ void wxDataViewCtrl::SetSelections( const wxArrayInt & sel )
|
|||||||
void wxDataViewCtrl::Select( int row )
|
void wxDataViewCtrl::Select( int row )
|
||||||
{
|
{
|
||||||
if( row >= 0 )
|
if( row >= 0 )
|
||||||
|
{
|
||||||
|
if (m_clientArea->IsSingleSel())
|
||||||
|
m_clientArea->SelectAllRows(false);
|
||||||
m_clientArea->SelectRow( row, true );
|
m_clientArea->SelectRow( row, true );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxDataViewCtrl::Unselect( int row )
|
void wxDataViewCtrl::Unselect( int row )
|
||||||
|
Reference in New Issue
Block a user