X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6608fdab17beec0a485a96a6d03a1d071c2fba5e..409521e45d44fc57df39efcb965701d378edcb20:/src/gtk/dataview.cpp diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index 7a22e83dfd..a34303416b 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -20,25 +20,18 @@ #include "wx/log.h" #include "wx/dcclient.h" #include "wx/sizer.h" + #include "wx/icon.h" + #include "wx/list.h" + #include "wx/settings.h" + #include "wx/crt.h" #endif #include "wx/stockitem.h" #include "wx/calctrl.h" #include "wx/popupwin.h" -#include "wx/icon.h" -#include "wx/list.h" #include "wx/listimpl.cpp" - #include "wx/gtk/private.h" -#include "wx/gtk/win_gtk.h" - -#include -#include -#include -#include - -#include //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -58,7 +51,7 @@ typedef struct _GtkWxTreeModel GtkWxTreeModel; //----------------------------------------------------------------------------- WX_DECLARE_LIST(wxDataViewItem, ItemList); -WX_DEFINE_LIST(ItemList); +WX_DEFINE_LIST(ItemList) class wxDataViewCtrlInternal { @@ -66,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 ); @@ -438,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 @@ -467,7 +462,8 @@ wxgtk_tree_model_get_column_type (GtkTreeModel *tree_model, gtype = G_TYPE_STRING; else { - wxFAIL_MSG( _T("non-string columns not supported yet") ); + gtype = G_TYPE_STRING; + // wxFAIL_MSG( _T("non-string columns not supported yet") ); } return gtype; @@ -919,6 +915,13 @@ gtk_wx_cell_renderer_render (GtkCellRenderer *renderer, GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer; wxDataViewCustomRenderer *cell = wxrenderer->cell; + cell->window = window; + cell->widget = widget; + cell->background_area = (void*) background_area; + cell->cell_area = (void*) cell_area; + cell->expose_area = (void*) expose_area; + cell->flags = (int) flags; + GdkRectangle rect; gtk_wx_cell_renderer_get_size (renderer, widget, cell_area, &rect.x, @@ -936,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) @@ -987,8 +999,10 @@ gtk_wx_cell_renderer_activate( wxDataViewModel *model = cell->GetOwner()->GetOwner()->GetModel(); GtkTreePath *treepath = gtk_tree_path_new_from_string( path ); - // TODO - wxDataViewItem item; + + GtkTreeIter iter; + cell->GetOwner()->GetOwner()->GtkGetInternal()->get_iter( &iter, treepath ); + wxDataViewItem item( iter.user_data ); gtk_tree_path_free( treepath ); unsigned int model_col = cell->GetOwner()->GetModelColumn(); @@ -1431,7 +1445,7 @@ bool wxDataViewTextRenderer::SetValue( const wxVariant &value ) GValue gvalue = { 0, }; g_value_init( &gvalue, G_TYPE_STRING ); - g_value_set_string( &gvalue, wxGTK_CONV_FONT( tmp, GetOwner()->GetOwner()->GetFont() ) ); + g_value_set_string( &gvalue, wxGTK_CONV( tmp ) ); g_object_set_property( G_OBJECT(m_renderer), "text", &gvalue ); g_value_unset( &gvalue ); @@ -1443,8 +1457,7 @@ bool wxDataViewTextRenderer::GetValue( wxVariant &value ) const GValue gvalue = { 0, }; g_value_init( &gvalue, G_TYPE_STRING ); g_object_get_property( G_OBJECT(m_renderer), "text", &gvalue ); - wxString tmp = wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue ), - wx_const_cast(wxDataViewTextRenderer*, this)->GetOwner()->GetOwner()->GetFont() ); + wxString tmp = wxGTK_CONV_BACK( g_value_get_string( &gvalue ) ); g_value_unset( &gvalue ); value = tmp; @@ -1473,6 +1486,18 @@ void wxDataViewTextRenderer::SetAlignment( int align ) g_value_unset( &gvalue ); } +// --------------------------------------------------------- +// wxDataViewTextRendererAttr +// --------------------------------------------------------- + +IMPLEMENT_CLASS(wxDataViewTextRendererAttr,wxDataViewTextRenderer) + +wxDataViewTextRendererAttr::wxDataViewTextRendererAttr( const wxString &varianttype, + wxDataViewCellMode mode, int align ) : + wxDataViewTextRenderer( varianttype, mode, align ) +{ +} + // --------------------------------------------------------- // wxDataViewBitmapRenderer // --------------------------------------------------------- @@ -1637,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; @@ -1646,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; @@ -1665,6 +1704,7 @@ wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString &varianttype, wxDataViewRenderer( varianttype, mode, align ) { m_dc = NULL; + m_text_renderer = NULL; if (no_init) m_renderer = NULL; @@ -1672,6 +1712,41 @@ wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString &varianttype, Init(mode, align); } +void wxDataViewCustomRenderer::RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state ) +{ +#if 0 + wxDataViewCtrl *view = GetOwner()->GetOwner(); + wxColour col = (state & wxDATAVIEW_CELL_SELECTED) ? + wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) : + view->GetForegroundColour(); + dc->SetTextForeground(col); + dc->DrawText( text, cell.x + xoffset, cell.y + ((cell.height - dc->GetCharHeight()) / 2)); +#else + if (!m_text_renderer) + m_text_renderer = gtk_cell_renderer_text_new(); + + GValue gvalue = { 0, }; + g_value_init( &gvalue, G_TYPE_STRING ); + g_value_set_string( &gvalue, wxGTK_CONV( text ) ); + g_object_set_property( G_OBJECT(m_text_renderer), "text", &gvalue ); + g_value_unset( &gvalue ); + + ((GdkRectangle*) cell_area)->x += xoffset; + ((GdkRectangle*) cell_area)->width -= xoffset; + + gtk_cell_renderer_render( m_text_renderer, + window, + widget, + (GdkRectangle*) background_area, + (GdkRectangle*) cell_area, + (GdkRectangle*) expose_area, + (GtkCellRendererState) flags ); + + ((GdkRectangle*) cell_area)->x -= xoffset; + ((GdkRectangle*) cell_area)->width += xoffset; +#endif +} + bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode, int align) { GtkWxCellRenderer *renderer = (GtkWxCellRenderer *) gtk_wx_cell_renderer_new(); @@ -1691,6 +1766,9 @@ wxDataViewCustomRenderer::~wxDataViewCustomRenderer() { if (m_dc) delete m_dc; + + if (m_text_renderer) + gtk_object_sink( GTK_OBJECT(m_text_renderer) ); } wxDC *wxDataViewCustomRenderer::GetDC() @@ -1728,8 +1806,7 @@ wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString &label, GValue gvalue = { 0, }; g_value_init( &gvalue, G_TYPE_STRING ); - // FIXME: font encoding support - g_value_set_string( &gvalue, wxGTK_CONV_SYS(m_label) ); + g_value_set_string( &gvalue, wxGTK_CONV(m_label) ); g_object_set_property( G_OBJECT(m_renderer), "text", &gvalue ); g_value_unset( &gvalue ); @@ -1873,8 +1950,7 @@ bool wxDataViewDateRenderer::Render( wxRect cell, wxDC *dc, int state ) { dc->SetFont( GetOwner()->GetOwner()->GetFont() ); wxString tmp = m_date.FormatDate(); - dc->DrawText( tmp, cell.x, cell.y ); - + RenderText( tmp, 0, cell, dc, state ); return true; } @@ -1935,23 +2011,30 @@ bool wxDataViewIconTextRenderer::GetValue( wxVariant &value ) const bool wxDataViewIconTextRenderer::Render( wxRect cell, wxDC *dc, int state ) { - dc->SetFont( GetOwner()->GetOwner()->GetFont() ); - const wxIcon &icon = m_value.GetIcon(); + int offset = 0; if (icon.IsOk()) { - dc->DrawIcon( icon, cell.x, cell.y ); // TODO centre - cell.x += icon.GetWidth()+4; + int yoffset = wxMax( 0, (cell.height - icon.GetHeight()) / 2 ); + dc->DrawIcon( icon, cell.x, cell.y + yoffset ); + offset = icon.GetWidth() + 4; } - dc->DrawText( m_value.GetText(), cell.x, cell.y ); + RenderText( m_value.GetText(), offset, cell, dc, state ); return true; } wxSize wxDataViewIconTextRenderer::GetSize() const { - return wxSize(80,16); // TODO + wxSize size; + if (m_value.GetIcon().IsOk()) + size.x = 4 + m_value.GetIcon().GetWidth(); + wxCoord x,y,d; + GetView()->GetTextExtent( m_value.GetText(), &x, &y, &d ); + size.x += x; + size.y = y+d; + return size; } wxControl* wxDataViewIconTextRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value ) @@ -2024,8 +2107,45 @@ static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *column, wxDataViewItem item( (void*) iter->user_data ); + 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)) + { + GValue gvalue = { 0, }; + g_value_init( &gvalue, G_TYPE_BOOLEAN ); + g_value_set_boolean( &gvalue, TRUE ); + g_object_set_property( G_OBJECT(renderer), "visible", &gvalue ); + g_value_unset( &gvalue ); + } + else + { + GValue gvalue = { 0, }; + g_value_init( &gvalue, G_TYPE_BOOLEAN ); + g_value_set_boolean( &gvalue, FALSE ); + g_object_set_property( G_OBJECT(renderer), "visible", &gvalue ); + g_value_unset( &gvalue ); + + return; + } + } + else + { + GValue gvalue = { 0, }; + g_value_init( &gvalue, G_TYPE_BOOLEAN ); + g_value_set_boolean( &gvalue, TRUE ); + g_object_set_property( G_OBJECT(renderer), "visible", &gvalue ); + g_value_unset( &gvalue ); + } + + } + wxVariant value; - tree_model->internal->GetDataViewModel()->GetValue( value, item, cell->GetOwner()->GetModelColumn() ); + wx_model->GetValue( value, item, cell->GetOwner()->GetModelColumn() ); if (value.GetType() != cell->GetVariantType()) wxLogError( wxT("Wrong type, required: %s but: %s"), @@ -2034,10 +2154,82 @@ static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *column, cell->SetValue( value ); -#if 0 - wxListItemAttr attr; - tree_model->model->GetAttr( attr, cell->GetOwner()->GetModelColumn(), model_row ); + if (cell->GtkHasAttributes()) + { + wxDataViewItemAttr attr; + bool colour_set = false; + bool style_set = false; + bool weight_set = false; + + if (wx_model->GetAttr( item, cell->GetOwner()->GetModelColumn(), attr )) + { + // this must be a GtkCellRendererText + wxColour colour = attr.GetColour(); + if (colour.IsOk()) + { + const GdkColor * const gcol = colour.GetColor(); + + GValue gvalue = { 0, }; + g_value_init( &gvalue, GDK_TYPE_COLOR ); + g_value_set_boxed( &gvalue, gcol ); + g_object_set_property( G_OBJECT(renderer), "foreground_gdk", &gvalue ); + g_value_unset( &gvalue ); + + colour_set = true; + } + + if (attr.GetItalic()) + { + GValue gvalue = { 0, }; + g_value_init( &gvalue, PANGO_TYPE_STYLE ); + g_value_set_enum( &gvalue, PANGO_STYLE_ITALIC ); + g_object_set_property( G_OBJECT(renderer), "style", &gvalue ); + g_value_unset( &gvalue ); + + style_set = true; + } + + if (attr.GetBold()) + { + GValue gvalue = { 0, }; + g_value_init( &gvalue, PANGO_TYPE_WEIGHT ); + g_value_set_enum( &gvalue, PANGO_WEIGHT_BOLD ); + g_object_set_property( G_OBJECT(renderer), "weight", &gvalue ); + g_value_unset( &gvalue ); + + weight_set = true; + } + } + + if (!style_set) + { + GValue gvalue = { 0, }; + g_value_init( &gvalue, G_TYPE_BOOLEAN ); + g_value_set_boolean( &gvalue, FALSE ); + g_object_set_property( G_OBJECT(renderer), "style-set", &gvalue ); + g_value_unset( &gvalue ); + } + + if (!weight_set) + { + GValue gvalue = { 0, }; + g_value_init( &gvalue, G_TYPE_BOOLEAN ); + g_value_set_boolean( &gvalue, FALSE ); + g_object_set_property( G_OBJECT(renderer), "weight-set", &gvalue ); + g_value_unset( &gvalue ); + } + + if (!colour_set) + { + GValue gvalue = { 0, }; + g_value_init( &gvalue, G_TYPE_BOOLEAN ); + g_value_set_boolean( &gvalue, FALSE ); + g_object_set_property( G_OBJECT(renderer), "foreground-set", &gvalue ); + g_value_unset( &gvalue ); + } + } +#if 0 if (attr.HasBackgroundColour()) { wxColour colour = attr.GetBackgroundColour(); @@ -2064,7 +2256,7 @@ static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *column, IMPLEMENT_CLASS(wxDataViewColumn, wxDataViewColumnBase) #include -WX_DEFINE_LIST(wxDataViewColumnList); +WX_DEFINE_LIST(wxDataViewColumnList) wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewRenderer *cell, unsigned int model_column, int width, @@ -2386,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() @@ -2425,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; } @@ -2476,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]; + + if (i >= wx_model->GetLastIndex()) + return FALSE; - wxGtkTreeModelNode *node = m_root; + 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; @@ -2519,117 +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 ); - bool is_container = m_wx_model->IsContainer( item ); - - if (!is_container) + if (m_wx_model->IsIndexListModel()) + { + // this is a list, nodes have no children return FALSE; + } + else + { + wxDataViewItem item( (void*) iter->user_data ); - wxGtkTreeModelNode *node = FindNode( iter ); - BuildBranch( node ); + bool is_container = m_wx_model->IsContainer( item ); + + if (!is_container) + return FALSE; + + 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 ); - wxGtkTreeModelNode *parent_node = FindNode( iter ); - BuildBranch( parent_node ); + if (!m_wx_model->IsContainer( item )) + return 0; + + 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* @@ -2641,6 +2958,7 @@ wxDataViewCtrlInternal_FindNode( wxDataViewModel * model, wxGtkTreeModelNode *tr ItemList list; list.DeleteContents( true ); wxDataViewItem it( item ); + while( it.IsOk() ) { wxDataViewItem * pItem = new wxDataViewItem( it ); @@ -2690,7 +3008,7 @@ wxGtkTreeModelNode *wxDataViewCtrlInternal::FindNode( GtkTreeIter *iter ) if (!result) { - wxPrintf( "Not found %d\n", (int) iter->user_data ); + wxLogDebug( "Not found %p", iter->user_data ); char *crash = NULL; *crash = 0; } @@ -2707,7 +3025,7 @@ wxGtkTreeModelNode *wxDataViewCtrlInternal::FindNode( const wxDataViewItem &item if (!result) { - wxPrintf( "Not found %d\n", (int) item.GetID() ); + wxLogDebug( "Not found %p", item.GetID() ); char *crash = NULL; *crash = 0; } @@ -3119,6 +3437,19 @@ bool wxDataViewCtrl::AppendColumn( wxDataViewColumn *col ) return true; } +bool wxDataViewCtrl::PrependColumn( wxDataViewColumn *col ) +{ + if (!wxDataViewCtrlBase::PrependColumn(col)) + return false; + + m_cols.Insert( col ); + + gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview), + GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()), 0 ); + + return true; +} + unsigned int wxDataViewCtrl::GetColumnCount() const { return m_cols.GetCount();