Fix wxDataViewCtrl to omit expander space for all kinds of lists.

List-only models don't have expanders and so the control shouldn't
reserve any space for them; the notion of expander column doesn't make
sense here.

Previously, this was done correctly only for wxDataViewVirtualListModel;
"ordinary" list models, such as the one used by wxDataViewListCtrl, were
treated as generic tree models and 0th column had ugly empty space
reserved for (never used) expander.

This patch fixes it by adding IsListModel() helper function in
addition to existing IsVirtualListModel(). Some of the
IsVirtualListModel() tests were changed into IsListModel() checks as
appropriate.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65140 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík 2010-07-29 20:54:00 +00:00
parent e78778c8e2
commit ce5abbf9f5
3 changed files with 22 additions and 13 deletions

View File

@ -257,6 +257,7 @@ public:
virtual bool HasDefaultCompare() const { return false; }
// internal
virtual bool IsListModel() const { return false; }
virtual bool IsVirtualListModel() const { return false; }
protected:
@ -328,6 +329,8 @@ public:
{
return GetAttrByRow( GetRow(item), col, attr );
}
virtual bool IsListModel() const { return true; }
};
// ---------------------------------------------------------

View File

@ -411,6 +411,7 @@ public:
const wxString &name = wxT("wxdataviewctrlmainwindow") );
virtual ~wxDataViewMainWindow();
bool IsList() const { return GetOwner()->GetModel()->IsListModel(); }
bool IsVirtualList() const { return m_root == NULL; }
// notifications from wxDataViewModel
@ -1497,7 +1498,7 @@ wxBitmap wxDataViewMainWindow::CreateItemBitmap( unsigned int row, int &indent )
}
indent = 0;
if (!IsVirtualList())
if (!IsList())
{
wxDataViewTreeNode *node = GetTreeNodeByRow(row);
indent = GetOwner()->GetIndent() * node->GetIndentLevel();
@ -1764,7 +1765,7 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
// deal with the expander
int indent = 0;
if ((!IsVirtualList()) && (col == expander))
if ((!IsList()) && (col == expander))
{
// Calculate the indent first
indent = GetOwner()->GetIndent() * node->GetIndentLevel();
@ -2795,7 +2796,7 @@ wxDataViewEvent wxDataViewMainWindow::SendExpanderEvent( wxEventType type,
bool wxDataViewMainWindow::IsExpanded( unsigned int row ) const
{
if (IsVirtualList())
if (IsList())
return false;
wxDataViewTreeNode * node = GetTreeNodeByRow(row);
@ -2813,7 +2814,7 @@ bool wxDataViewMainWindow::IsExpanded( unsigned int row ) const
bool wxDataViewMainWindow::HasChildren( unsigned int row ) const
{
if (IsVirtualList())
if (IsList())
return false;
wxDataViewTreeNode * node = GetTreeNodeByRow(row);
@ -2831,7 +2832,7 @@ bool wxDataViewMainWindow::HasChildren( unsigned int row ) const
void wxDataViewMainWindow::Expand( unsigned int row )
{
if (IsVirtualList())
if (IsList())
return;
wxDataViewTreeNode * node = GetTreeNodeByRow(row);
@ -2887,7 +2888,7 @@ void wxDataViewMainWindow::Expand( unsigned int row )
void wxDataViewMainWindow::Collapse(unsigned int row)
{
if (IsVirtualList())
if (IsList())
return;
wxDataViewTreeNode *node = GetTreeNodeByRow(row);
@ -3086,7 +3087,7 @@ wxRect wxDataViewMainWindow::GetItemRect( const wxDataViewItem & item,
// to get the correct x position where the actual text is
int indent = 0;
int row = GetRowByItem(item);
if (!IsVirtualList() && (column == 0 || GetOwner()->GetExpanderColumn() == column) )
if (!IsList() && (column == 0 || GetOwner()->GetExpanderColumn() == column) )
{
wxDataViewTreeNode* node = GetTreeNodeByRow(row);
indent = GetOwner()->GetIndent() * node->GetIndentLevel();
@ -3332,7 +3333,7 @@ void wxDataViewMainWindow::OnChar( wxKeyEvent &event )
// Add the process for tree expanding/collapsing
case WXK_LEFT:
{
if (IsVirtualList())
if (IsList())
break;
wxDataViewTreeNode* node = GetTreeNodeByRow(m_currentRow);
@ -3473,7 +3474,7 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
// Test whether the mouse is hovered on the tree item button
bool hoverOverExpander = false;
if ((!IsVirtualList()) && (GetOwner()->GetExpanderColumn() == col))
if ((!IsList()) && (GetOwner()->GetExpanderColumn() == col))
{
wxDataViewTreeNode * node = GetTreeNodeByRow(current);
if( node!=NULL && node->HasChildren() )

View File

@ -3502,10 +3502,15 @@ bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem &item, unsigned
GtkTreeModelFlags wxDataViewCtrlInternal::get_flags()
{
if (m_wx_model->IsVirtualListModel())
return GTK_TREE_MODEL_LIST_ONLY;
else
return GTK_TREE_MODEL_ITERS_PERSIST;
int flags = 0;
if ( m_wx_model->IsListModel() )
flags |= GTK_TREE_MODEL_LIST_ONLY;
if ( !m_wx_model->IsVirtualListModel() )
flags |= GTK_TREE_MODEL_ITERS_PERSIST;
return GtkTreeModelFlags(flags);
}
gboolean wxDataViewCtrlInternal::get_iter( GtkTreeIter *iter, GtkTreePath *path )