X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7f6cbcead99e018aa640fca5ceb30054f2513243..fc5d9e38ee002c024be3019e37b63f1a1d88e7c2:/src/gtk/dataview.cpp diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index 697d1cf9cc..32bdc03dc4 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -975,11 +975,11 @@ static GtkCellEditable *gtk_wx_cell_renderer_start_editing( { GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer; wxDataViewCustomRenderer *cell = wxrenderer->cell; - + // Renderer doesn't support in-place editing if (!cell->HasEditorCtrl()) return NULL; - + // An in-place editing control is still around if (cell->GetEditorCtrl()) return NULL; @@ -1086,7 +1086,7 @@ gtk_wx_cell_renderer_render (GtkCellRenderer *renderer, rect.y += cell_area->y; rect.width -= renderer->xpad * 2; rect.height -= renderer->ypad * 2; - + GdkRectangle dummy; if (gdk_rectangle_intersect (expose_area, &rect, &dummy)) { @@ -1477,18 +1477,18 @@ wxDataViewCellMode wxDataViewRenderer::GetMode() const void wxDataViewRenderer::GtkUpdateAlignment() { int align = m_alignment; - + // query alignment from column ? if (align == -1) { // None there yet if (GetOwner() == NULL) return; - + align = GetOwner()->GetAlignment(); align |= wxALIGN_CENTRE_VERTICAL; } - + // horizontal alignment: gfloat xalign = 0.0; @@ -1541,7 +1541,7 @@ static void wxGtkTextRendererEditedCallback( GtkCellRendererText *renderer, static void wxGtkTextRendererEditedCallback( GtkCellRendererText *WXUNUSED(renderer), gchar *arg1, gchar *arg2, gpointer user_data ) { - wxDataViewTextRenderer *cell = (wxDataViewTextRenderer*) user_data; + wxDataViewRenderer *cell = (wxDataViewRenderer*) user_data; wxString tmp = wxGTK_CONV_BACK_FONT(arg2, cell->GetOwner()->GetOwner()->GetFont()); wxVariant value = tmp; @@ -1605,7 +1605,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_FONT( g_value_get_string( &gvalue ), const_cast(this)->GetOwner()->GetOwner()->GetFont() ); g_value_unset( &gvalue ); value = tmp; @@ -2021,6 +2021,120 @@ wxSize wxDataViewProgressRenderer::GetSize() const return wxSize(40,12); } +// ------------------------------------- +// wxDataViewChoiceRenderer +// ------------------------------------- + +wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString &choices, + wxDataViewCellMode mode, int alignment ) : + wxDataViewCustomRenderer( "string", mode, alignment, true ) +{ + m_choices = choices; + +#ifdef __WXGTK26__ + if (!gtk_check_version(2,6,0)) + { + m_renderer = (GtkCellRenderer*) gtk_cell_renderer_combo_new(); + + GtkListStore *store = gtk_list_store_new( 1, G_TYPE_STRING ); + size_t n; + for (n = 0; n < m_choices.GetCount(); n++) + gtk_list_store_insert_with_values( store, NULL, n, 0, m_choices[n].utf8_str(), -1 ); + + g_object_set (m_renderer, + "model", store, + "text-column", 0, + "has-entry", FALSE, + NULL); + + bool editable = (mode & wxDATAVIEW_CELL_EDITABLE); + g_object_set (m_renderer, "editable", editable, NULL); + + SetAlignment(alignment); + + g_signal_connect_after( m_renderer, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback), this ); + + GtkInitHandlers(); + } + else +#endif + { + // Use custom cell code + wxDataViewCustomRenderer::Init(mode, alignment); + } +} + +bool wxDataViewChoiceRenderer::Render( wxRect rect, wxDC *dc, int state ) +{ + RenderText( m_data, 0, rect, dc, state ); + return true; +} + +wxSize wxDataViewChoiceRenderer::GetSize() const +{ + return wxSize(70,20); +} + +bool wxDataViewChoiceRenderer::SetValue( const wxVariant &value ) +{ + +#ifdef __WXGTK26__ + if (!gtk_check_version(2,6,0)) + { + GValue gvalue = { 0, }; + g_value_init( &gvalue, G_TYPE_STRING ); + g_value_set_string( &gvalue, wxGTK_CONV_FONT( value.GetString(), GetOwner()->GetOwner()->GetFont() ) ); + g_object_set_property( G_OBJECT(m_renderer), "text", &gvalue ); + g_value_unset( &gvalue ); + } + else +#endif + m_data = value.GetString(); + + return true; +} + +bool wxDataViewChoiceRenderer::GetValue( wxVariant &value ) const +{ +#ifdef __WXGTK26__ + if (!gtk_check_version(2,6,0)) + { + GValue gvalue = { 0, }; + g_value_init( &gvalue, G_TYPE_STRING ); + g_object_get_property( G_OBJECT(m_renderer), "text", &gvalue ); + wxString temp = wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue ), const_cast(this)->GetOwner()->GetOwner()->GetFont() ); + g_value_unset( &gvalue ); + value = temp; + wxPrintf( "temp %s\n", temp ); + } + else +#endif + value = m_data; + + return true; +} + +void wxDataViewChoiceRenderer::SetAlignment( int align ) +{ + wxDataViewCustomRenderer::SetAlignment(align); + + if (gtk_check_version(2,10,0)) + return; + + // horizontal alignment: + PangoAlignment pangoAlign = PANGO_ALIGN_LEFT; + if (align & wxALIGN_RIGHT) + pangoAlign = PANGO_ALIGN_RIGHT; + else if (align & wxALIGN_CENTER_HORIZONTAL) + pangoAlign = PANGO_ALIGN_CENTER; + + GValue gvalue = { 0, }; + g_value_init( &gvalue, gtk_cell_renderer_mode_get_type() ); + g_value_set_enum( &gvalue, pangoAlign ); + g_object_set_property( G_OBJECT(m_renderer), "alignment", &gvalue ); + g_value_unset( &gvalue ); +} + // --------------------------------------------------------- // wxDataViewDateRenderer // --------------------------------------------------------- @@ -2401,26 +2515,23 @@ static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *WXUNUSED(column), } -IMPLEMENT_CLASS(wxDataViewColumn, wxDataViewColumnBase) - #include WX_DEFINE_LIST(wxDataViewColumnList) wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewRenderer *cell, unsigned int model_column, int width, - wxAlignment align, int flags ) : - wxDataViewColumnBase( title, cell, model_column, width, align, flags ) + wxAlignment align, int flags ) + : wxDataViewColumnBase( cell, model_column ) { Init( align, flags, width ); - gtk_tree_view_column_set_clickable( GTK_TREE_VIEW_COLUMN(m_column), TRUE ); SetTitle( title ); } wxDataViewColumn::wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *cell, unsigned int model_column, int width, - wxAlignment align, int flags ) : - wxDataViewColumnBase( bitmap, cell, model_column, width, align, flags ) + wxAlignment align, int flags ) + : wxDataViewColumnBase( bitmap, cell, model_column ) { Init( align, flags, width ); @@ -2449,17 +2560,13 @@ void wxDataViewColumn::Init(wxAlignment align, int flags, int width) m_label = gtk_label_new(""); gtk_box_pack_end( GTK_BOX(box), GTK_WIDGET(m_label), FALSE, FALSE, 1 ); gtk_tree_view_column_set_widget( column, box ); - + gtk_tree_view_column_pack_end( column, renderer, TRUE ); gtk_tree_view_column_set_cell_data_func( column, renderer, wxGtkTreeCellDataFunc, (gpointer) GetRenderer(), NULL ); } -wxDataViewColumn::~wxDataViewColumn() -{ -} - void wxDataViewColumn::OnInternalIdle() { if (m_isConnected) @@ -2558,7 +2665,7 @@ void wxDataViewColumn::SetAlignment( wxAlignment align ) xalign = 0.5; gtk_tree_view_column_set_alignment( column, xalign ); - + if (m_renderer && m_renderer->GetAlignment() == -1) m_renderer->GtkUpdateAlignment(); } @@ -2579,7 +2686,7 @@ void wxDataViewColumn::SetSortable( bool sortable ) { GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); - if (sortable) + if ( sortable ) { gtk_tree_view_column_set_sort_column_id( column, GetModelColumn() ); } @@ -2587,13 +2694,28 @@ void wxDataViewColumn::SetSortable( bool sortable ) { gtk_tree_view_column_set_sort_column_id( column, -1 ); gtk_tree_view_column_set_sort_indicator( column, FALSE ); + gtk_tree_view_column_set_clickable( column, FALSE ); } } bool wxDataViewColumn::IsSortable() const { GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); - return (gtk_tree_view_column_get_sort_column_id( column ) != -1); + return gtk_tree_view_column_get_clickable( column ); +} + +void wxDataViewColumn::SetAsSortKey( bool WXUNUSED(sort) ) +{ + // it might not make sense to have this function in wxHeaderColumn at + // all in fact, changing of the sort order should only be done using the + // associated control API + wxFAIL_MSG( "not implemented" ); +} + +bool wxDataViewColumn::IsSortKey() const +{ + GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column); + return gtk_tree_view_column_get_sort_indicator( column ); } bool wxDataViewColumn::IsResizeable() const @@ -3439,14 +3561,9 @@ wxdataview_row_collapsed_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter* // wxDataViewCtrl //----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -// InsertChild for wxDataViewCtrl -//----------------------------------------------------------------------------- - -static void wxInsertChildInDataViewCtrl( wxWindowGTK* parent, wxWindowGTK* child ) +void wxDataViewCtrl::AddChildGTK(wxWindowGTK* child) { - wxDataViewCtrl * dvc = (wxDataViewCtrl*) parent; - GtkWidget *treeview = dvc->GtkGetTreeView(); + GtkWidget* treeview = GtkGetTreeView(); // Insert widget in GtkTreeView if (GTK_WIDGET_REALIZED(treeview)) @@ -3588,7 +3705,7 @@ void wxDataViewCtrl::Init() { m_notifier = NULL; m_internal = NULL; - + m_cols.DeleteContents( true ); } @@ -3607,9 +3724,8 @@ bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, return false; } - m_insertCallback = wxInsertChildInDataViewCtrl; - m_widget = gtk_scrolled_window_new (NULL, NULL); + g_object_ref(m_widget); GtkScrolledWindowSetBorder(m_widget, style); @@ -3897,6 +4013,17 @@ void wxDataViewCtrl::Collapse( const wxDataViewItem & item ) gtk_tree_path_free( path ); } +bool wxDataViewCtrl::IsExpanded( const wxDataViewItem & item ) const +{ + GtkTreeIter iter; + iter.user_data = item.GetID(); + GtkTreePath *path = m_internal->get_path( &iter ); + bool res = gtk_tree_view_row_expanded( GTK_TREE_VIEW(m_treeview), path ); + gtk_tree_path_free( path ); + + return res; +} + wxDataViewItem wxDataViewCtrl::GetSelection() const { GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); @@ -3990,6 +4117,7 @@ void wxDataViewCtrl::SetSelections( const wxDataViewItemArray & sel ) for (i = 0; i < sel.GetCount(); i++) { GtkTreeIter iter; + iter.stamp = m_internal->GetGtkModel()->stamp; iter.user_data = (gpointer) sel[i].GetID(); gtk_tree_selection_select_iter( selection, &iter ); } @@ -4004,6 +4132,7 @@ void wxDataViewCtrl::Select( const wxDataViewItem & item ) GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); GtkTreeIter iter; + iter.stamp = m_internal->GetGtkModel()->stamp; iter.user_data = (gpointer) item.GetID(); gtk_tree_selection_select_iter( selection, &iter ); @@ -4017,6 +4146,7 @@ void wxDataViewCtrl::Unselect( const wxDataViewItem & item ) GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); GtkTreeIter iter; + iter.stamp = m_internal->GetGtkModel()->stamp; iter.user_data = (gpointer) item.GetID(); gtk_tree_selection_unselect_iter( selection, &iter ); @@ -4028,6 +4158,7 @@ bool wxDataViewCtrl::IsSelected( const wxDataViewItem & item ) const GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); GtkTreeIter iter; + iter.stamp = m_internal->GetGtkModel()->stamp; iter.user_data = (gpointer) item.GetID(); return gtk_tree_selection_iter_is_selected( selection, &iter ); @@ -4056,8 +4187,10 @@ void wxDataViewCtrl::UnselectAll() } void wxDataViewCtrl::EnsureVisible(const wxDataViewItem& item, - const wxDataViewColumn *WXUNUSED(column)) + const wxDataViewColumn *column) { + wxDataViewCtrlBase::EnsureVisible(item,column); + GtkTreeIter iter; iter.user_data = (gpointer) item.GetID(); GtkTreePath *path = m_internal->get_path( &iter );