X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4264606eedb18f626e864020082d8dde8d055eea..3f4049ffb2aa35e0a7648f6ffc6869394f70fd8c:/src/gtk/dataview.cpp diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index 169dd8c446..a34303416b 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -59,6 +59,7 @@ public: wxDataViewCtrlInternal( wxDataViewCtrl *owner, wxDataViewModel *wx_model, GtkWxTreeModel *owner ); ~wxDataViewCtrlInternal(); + GtkTreeModelFlags get_flags(); gboolean get_iter( GtkTreeIter *iter, GtkTreePath *path ); GtkTreePath *get_path( GtkTreeIter *iter); gboolean iter_next( GtkTreeIter *iter ); @@ -431,9 +432,10 @@ wxgtk_tree_model_finalize (GObject *object) static GtkTreeModelFlags wxgtk_tree_model_get_flags (GtkTreeModel *tree_model) { - g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (tree_model), (GtkTreeModelFlags)0 ); + GtkWxTreeModel *wxtree_model = (GtkWxTreeModel *) tree_model; + g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (wxtree_model), (GtkTreeModelFlags)0 ); - return GTK_TREE_MODEL_ITERS_PERSIST; + return wxtree_model->internal->get_flags(); } static gint @@ -937,11 +939,20 @@ gtk_wx_cell_renderer_render (GtkCellRenderer *renderer, { wxRect renderrect( rect.x, rect.y, rect.width, rect.height ); wxWindowDC* dc = (wxWindowDC*) cell->GetDC(); +#if wxUSE_NEW_DC + wxGTKWindowDCImpl *impldc = (wxGTKWindowDCImpl *) dc->GetImpl(); + if (impldc->m_window == NULL) + { + impldc->m_window = window; + impldc->SetUpDC(); + } +#else if (dc->m_window == NULL) { dc->m_window = window; dc->SetUpDC(); } +#endif int state = 0; if (flags & GTK_CELL_RENDERER_SELECTED) @@ -1651,6 +1662,20 @@ class wxDataViewCtrlDC: public wxWindowDC public: wxDataViewCtrlDC( wxDataViewCtrl *window ) { +#if wxUSE_NEW_DC + wxGTKWindowDCImpl *impl = (wxGTKWindowDCImpl*) GetImpl(); + + GtkWidget *widget = window->m_treeview; + // Set later + impl->m_window = NULL; + + impl->m_context = window->GtkGetPangoDefaultContext(); + impl->m_layout = pango_layout_new( impl->m_context ); + impl->m_fontdesc = pango_font_description_copy( widget->style->font_desc ); + + impl->m_cmap = gtk_widget_get_colormap( widget ? widget : window->m_widget ); + +#else GtkWidget *widget = window->m_treeview; // Set later m_window = NULL; @@ -1660,7 +1685,7 @@ public: m_fontdesc = pango_font_description_copy( widget->style->font_desc ); m_cmap = gtk_widget_get_colormap( widget ? widget : window->m_widget ); - +#endif // Set m_window later // SetUpDC(); // m_owner = window; @@ -2084,6 +2109,9 @@ static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *column, wxDataViewModel *wx_model = tree_model->internal->GetDataViewModel(); + if (!wx_model->IsIndexListModel()) + { + if (wx_model->IsContainer( item )) { if (wx_model->HasContainerColumns( item ) || (cell->GetOwner()->GetModelColumn() == 0)) @@ -2113,6 +2141,8 @@ static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *column, g_object_set_property( G_OBJECT(renderer), "visible", &gvalue ); g_value_unset( &gvalue ); } + + } wxVariant value; wx_model->GetValue( value, item, cell->GetOwner()->GetModelColumn() ); @@ -2548,7 +2578,9 @@ wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl *owner, m_sort_order = GTK_SORT_ASCENDING; m_sort_column = -1; m_dataview_sort_column = NULL; - InitTree(); + + if (!m_wx_model->IsIndexListModel()) + InitTree(); } wxDataViewCtrlInternal::~wxDataViewCtrlInternal() @@ -2587,24 +2619,31 @@ void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode *node ) void wxDataViewCtrlInternal::Resort() { - m_root->Resort(); + if (!m_wx_model->IsIndexListModel()) + m_root->Resort(); } bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ) { - wxGtkTreeModelNode *parent_node = FindNode( parent ); - if (m_wx_model->IsContainer( item )) - parent_node->AddNode( new wxGtkTreeModelNode( parent_node, item, this ) ); - else - parent_node->AddLeave( item.GetID() ); + if (!m_wx_model->IsIndexListModel()) + { + wxGtkTreeModelNode *parent_node = FindNode( parent ); + if (m_wx_model->IsContainer( item )) + parent_node->AddNode( new wxGtkTreeModelNode( parent_node, item, this ) ); + else + parent_node->AddLeave( item.GetID() ); + } return true; } bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item ) { - wxGtkTreeModelNode *parent_node = FindNode( parent ); - parent_node->DeleteChild( item.GetID() ); + if (!m_wx_model->IsIndexListModel()) + { + wxGtkTreeModelNode *parent_node = FindNode( parent ); + parent_node->DeleteChild( item.GetID() ); + } return true; } @@ -2638,41 +2677,67 @@ bool wxDataViewCtrlInternal::Cleared() return true; } +GtkTreeModelFlags wxDataViewCtrlInternal::get_flags() +{ + if (m_wx_model->IsIndexListModel()) + return GTK_TREE_MODEL_LIST_ONLY; + else + return GTK_TREE_MODEL_ITERS_PERSIST; +} + gboolean wxDataViewCtrlInternal::get_iter( GtkTreeIter *iter, GtkTreePath *path ) { - int depth = gtk_tree_path_get_depth( path ); + if (m_wx_model->IsIndexListModel()) + { + wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model; + + unsigned int i = (unsigned int)gtk_tree_path_get_indices (path)[0]; - wxGtkTreeModelNode *node = m_root; + if (i >= wx_model->GetLastIndex()) + return FALSE; + + iter->stamp = m_gtk_model->stamp; + // user_data is just the index + iter->user_data = (gpointer) i; - int i; - for (i = 0; i < depth; i++) + return TRUE; + } + else { - BuildBranch( node ); + int depth = gtk_tree_path_get_depth( path ); + + wxGtkTreeModelNode *node = m_root; + + int i; + for (i = 0; i < depth; i++) + { + BuildBranch( node ); - gint pos = gtk_tree_path_get_indices (path)[i]; - if (pos < 0) return FALSE; - if ((size_t)pos >= node->GetChildCount()) return FALSE; + gint pos = gtk_tree_path_get_indices (path)[i]; + if (pos < 0) return FALSE; + if ((size_t)pos >= node->GetChildCount()) return FALSE; - void* id = node->GetChildren().Item( (size_t) pos ); + void* id = node->GetChildren().Item( (size_t) pos ); - if (i == depth-1) - { - iter->stamp = m_gtk_model->stamp; - iter->user_data = id; - return TRUE; - } - - size_t count = node->GetNodes().GetCount(); - size_t pos2; - for (pos2 = 0; pos2 < count; pos2++) - { - wxGtkTreeModelNode *child_node = node->GetNodes().Item( pos2 ); - if (child_node->GetItem().GetID() == id) + if (i == depth-1) { - node = child_node; - break; + iter->stamp = m_gtk_model->stamp; + iter->user_data = id; + return TRUE; } - } + + size_t count = node->GetNodes().GetCount(); + size_t pos2; + for (pos2 = 0; pos2 < count; pos2++) + { + wxGtkTreeModelNode *child_node = node->GetNodes().Item( pos2 ); + if (child_node->GetItem().GetID() == id) + { + node = child_node; + break; + } + } + } } return FALSE; @@ -2681,118 +2746,207 @@ gboolean wxDataViewCtrlInternal::get_iter( GtkTreeIter *iter, GtkTreePath *path GtkTreePath *wxDataViewCtrlInternal::get_path( GtkTreeIter *iter ) { GtkTreePath *retval = gtk_tree_path_new (); - void *id = iter->user_data; - wxGtkTreeModelNode *node = FindParentNode( iter ); - while (node) + if (m_wx_model->IsIndexListModel()) + { + // user_data is just the index + int i = (wxUIntPtr) iter->user_data; + gtk_tree_path_append_index (retval, i); + } + else { - int pos = node->GetChildren().Index( id ); + void *id = iter->user_data; + + wxGtkTreeModelNode *node = FindParentNode( iter ); + while (node) + { + int pos = node->GetChildren().Index( id ); - gtk_tree_path_prepend_index( retval, pos ); + gtk_tree_path_prepend_index( retval, pos ); - id = node->GetItem().GetID(); - node = node->GetParent(); + id = node->GetItem().GetID(); + node = node->GetParent(); + } } - + return retval; } gboolean wxDataViewCtrlInternal::iter_next( GtkTreeIter *iter ) { - wxGtkTreeModelNode *parent = FindParentNode( iter ); - if( parent == NULL ) - return FALSE; + if (m_wx_model->IsIndexListModel()) + { + wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model; + + int n = (wxUIntPtr) iter->user_data; - int pos = parent->GetChildren().Index( iter->user_data ); + if (n == -1) + return FALSE; - if (pos == (int) parent->GetChildCount()-1) - return FALSE; + if (n >= (int) wx_model->GetLastIndex()-2) + return FALSE; + + iter->user_data = (gpointer) ++n; + } + else + { + wxGtkTreeModelNode *parent = FindParentNode( iter ); + if( parent == NULL ) + return FALSE; + + int pos = parent->GetChildren().Index( iter->user_data ); + + if (pos == (int) parent->GetChildCount()-1) + return FALSE; - iter->stamp = m_gtk_model->stamp; - iter->user_data = parent->GetChildren().Item( pos+1 ); + iter->stamp = m_gtk_model->stamp; + iter->user_data = parent->GetChildren().Item( pos+1 ); + } return TRUE; } gboolean wxDataViewCtrlInternal::iter_children( GtkTreeIter *iter, GtkTreeIter *parent ) { - wxDataViewItem item( (void*) parent->user_data ); + if (m_wx_model->IsIndexListModel()) + { + // this is a list, nodes have no children + if (parent) + return FALSE; + + iter->stamp = m_gtk_model->stamp; + iter->user_data = (gpointer) -1; + + return TRUE; + } + else + { + wxDataViewItem item( (void*) parent->user_data ); - if (!m_wx_model->IsContainer( item )) - return FALSE; + if (!m_wx_model->IsContainer( item )) + return FALSE; - wxGtkTreeModelNode *parent_node = FindNode( parent ); - BuildBranch( parent_node ); + wxGtkTreeModelNode *parent_node = FindNode( parent ); + BuildBranch( parent_node ); - if (parent_node->GetChildCount() == 0) - return FALSE; + if (parent_node->GetChildCount() == 0) + return FALSE; - iter->stamp = m_gtk_model->stamp; - iter->user_data = (gpointer) parent_node->GetChildren().Item( 0 ); - + iter->stamp = m_gtk_model->stamp; + iter->user_data = (gpointer) parent_node->GetChildren().Item( 0 ); + } + return TRUE; } gboolean wxDataViewCtrlInternal::iter_has_child( GtkTreeIter *iter ) { - wxDataViewItem item( (void*) iter->user_data ); + if (m_wx_model->IsIndexListModel()) + { + // this is a list, nodes have no children + return FALSE; + } + else + { + wxDataViewItem item( (void*) iter->user_data ); - bool is_container = m_wx_model->IsContainer( item ); + bool is_container = m_wx_model->IsContainer( item ); - if (!is_container) - return FALSE; + if (!is_container) + return FALSE; - wxGtkTreeModelNode *node = FindNode( iter ); - BuildBranch( node ); + wxGtkTreeModelNode *node = FindNode( iter ); + BuildBranch( node ); - return (node->GetChildCount() > 0); + return (node->GetChildCount() > 0); + } } gint wxDataViewCtrlInternal::iter_n_children( GtkTreeIter *iter ) { - wxDataViewItem item( (void*) iter->user_data ); - - if (!m_wx_model->IsContainer( item )) + if (m_wx_model->IsIndexListModel()) + { + wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model; + + if (iter == NULL) + return (gint) wx_model->GetLastIndex()-1; + return 0; + } + else + { + wxDataViewItem item( (void*) iter->user_data ); + + if (!m_wx_model->IsContainer( item )) + return 0; - wxGtkTreeModelNode *parent_node = FindNode( iter ); - BuildBranch( parent_node ); + wxGtkTreeModelNode *parent_node = FindNode( iter ); + BuildBranch( parent_node ); - // wxPrintf( "iter_n_children %d\n", parent_node->GetChildCount() ); + // wxPrintf( "iter_n_children %d\n", parent_node->GetChildCount() ); - return parent_node->GetChildCount(); + return parent_node->GetChildCount(); + } } gboolean wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter *iter, GtkTreeIter *parent, gint n ) { - void* id = NULL; - if (parent) id = (void*) parent->user_data; - wxDataViewItem item( id ); + if (m_wx_model->IsIndexListModel()) + { + wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model; + + if (parent) + return FALSE; + + if (n < 0) + return FALSE; + + if (n >= (gint) wx_model->GetLastIndex()-1) + return FALSE; + + iter->stamp = m_gtk_model->stamp; + iter->user_data = (gpointer) n; + + return TRUE; + } + else + { + void* id = NULL; + if (parent) id = (void*) parent->user_data; + wxDataViewItem item( id ); - if (!m_wx_model->IsContainer( item )) - return FALSE; + if (!m_wx_model->IsContainer( item )) + return FALSE; - wxGtkTreeModelNode *parent_node = FindNode( parent ); - BuildBranch( parent_node ); + wxGtkTreeModelNode *parent_node = FindNode( parent ); + BuildBranch( parent_node ); - // wxPrintf( "iter_nth_child %d\n", n ); + // wxPrintf( "iter_nth_child %d\n", n ); - iter->stamp = m_gtk_model->stamp; - iter->user_data = parent_node->GetChildren().Item( n ); + iter->stamp = m_gtk_model->stamp; + iter->user_data = parent_node->GetChildren().Item( n ); - return TRUE; + return TRUE; + } } gboolean wxDataViewCtrlInternal::iter_parent( GtkTreeIter *iter, GtkTreeIter *child ) { - wxGtkTreeModelNode *node = FindParentNode( child ); - if (!node) + if (m_wx_model->IsIndexListModel()) + { return FALSE; + } + else + { + wxGtkTreeModelNode *node = FindParentNode( child ); + if (!node) + return FALSE; - iter->stamp = m_gtk_model->stamp; - iter->user_data = (gpointer) node->GetItem().GetID(); + iter->stamp = m_gtk_model->stamp; + iter->user_data = (gpointer) node->GetItem().GetID(); - return TRUE; + return TRUE; + } } static wxGtkTreeModelNode*