X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/91a6c655582321b61a7545ed9c121ad6593ccbfe..ed8385818f26035d2f60d3a719250ffab48e6c34:/src/gtk/dataview.cpp diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index 60b0ec0791..a5c67b1bef 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -92,6 +92,9 @@ public: void SetSortColumn( int column ) { m_sort_column = column; } int GetSortColumn() { return m_sort_column; } + void SetDataViewSortColumn( wxDataViewColumn *column ) { m_dataview_sort_column = column; } + wxDataViewColumn *GetDataViewSortColumn() { return m_dataview_sort_column; } + bool IsSorted() { return (m_sort_column >= 0); } @@ -109,6 +112,7 @@ private: GtkWxTreeModel *m_gtk_model; wxDataViewCtrl *m_owner; GtkSortType m_sort_order; + wxDataViewColumn *m_dataview_sort_column; int m_sort_column; }; @@ -614,6 +618,8 @@ gboolean wxgtk_tree_model_get_sort_column_id (GtkTreeSortable *sortabl return TRUE; } +wxDataViewColumn *gs_lastLeftClickHeader = NULL; + void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable *sortable, gint sort_column_id, GtkSortType order) @@ -621,23 +627,29 @@ void wxgtk_tree_model_set_sort_column_id (GtkTreeSortable *sortable, GtkWxTreeModel *tree_model = (GtkWxTreeModel *) sortable; g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable) ); - if ((sort_column_id == (gint) tree_model->internal->GetSortColumn()) && - (order == tree_model->internal->GetSortOrder())) - return; + tree_model->internal->SetDataViewSortColumn( gs_lastLeftClickHeader ); - tree_model->internal->SetSortColumn( sort_column_id ); - - tree_model->internal->SetSortOrder( order ); + if ((sort_column_id != (gint) tree_model->internal->GetSortColumn()) || + (order != tree_model->internal->GetSortOrder())) + { + tree_model->internal->SetSortColumn( sort_column_id ); + tree_model->internal->SetSortOrder( order ); - gtk_tree_sortable_sort_column_changed (sortable); + gtk_tree_sortable_sort_column_changed (sortable); - tree_model->internal->GetDataViewModel()->Resort(); + tree_model->internal->GetDataViewModel()->Resort(); + } - wxDataViewCtrl *dv = tree_model->internal->GetOwner(); - wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, dv->GetId() ); - // TODO event.SetDataViewColumn( column ); - event.SetModel( dv->GetModel() ); - dv->GetEventHandler()->ProcessEvent( event ); + if (gs_lastLeftClickHeader) + { + wxDataViewCtrl *dv = tree_model->internal->GetOwner(); + wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, dv->GetId() ); + event.SetDataViewColumn( gs_lastLeftClickHeader ); + event.SetModel( dv->GetModel() ); + dv->GetEventHandler()->ProcessEvent( event ); + } + + gs_lastLeftClickHeader = NULL; } void wxgtk_tree_model_set_sort_func (GtkTreeSortable *sortable, @@ -1256,6 +1268,7 @@ void wxDataViewRenderer::SetMode( wxDataViewCellMode mode ) break; } + // This value is most often ignored in GtkTreeView GValue gvalue = { 0, }; g_value_init( &gvalue, gtk_cell_renderer_mode_get_type() ); g_value_set_enum( &gvalue, gtkMode ); @@ -1890,6 +1903,67 @@ bool wxDataViewDateRenderer::Activate( wxRect cell, wxDataViewModel *model, return true; } + +// --------------------------------------------------------- +// wxDataViewIconTextRenderer +// --------------------------------------------------------- + +IMPLEMENT_CLASS(wxDataViewIconTextRenderer, wxDataViewCustomRenderer) + +wxDataViewIconTextRenderer::wxDataViewIconTextRenderer( + const wxString &varianttype, wxDataViewCellMode mode, int align ) : + wxDataViewCustomRenderer( varianttype, mode, align ) +{ + SetMode(mode); + SetAlignment(align); +} + +wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer() +{ +} + +bool wxDataViewIconTextRenderer::SetValue( const wxVariant &value ) +{ + m_value << value; + return true; +} + +bool wxDataViewIconTextRenderer::GetValue( wxVariant &value ) const +{ + return false; +} + +bool wxDataViewIconTextRenderer::Render( wxRect cell, wxDC *dc, int state ) +{ + dc->SetFont( GetOwner()->GetOwner()->GetFont() ); + + const wxIcon &icon = m_value.GetIcon(); + if (icon.IsOk()) + { + dc->DrawIcon( icon, cell.x, cell.y ); // TODO centre + cell.x += icon.GetWidth()+4; + } + + dc->DrawText( m_value.GetText(), cell.x, cell.y ); + + return true; +} + +wxSize wxDataViewIconTextRenderer::GetSize() const +{ + return wxSize(80,16); // TODO +} + +wxControl* wxDataViewIconTextRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value ) +{ + return NULL; +} + +bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxControl* editor, wxVariant &value ) +{ + return false; +} + // --------------------------------------------------------- // wxDataViewColumn // --------------------------------------------------------- @@ -1905,6 +1979,8 @@ gtk_dataview_header_button_press_callback( GtkWidget *widget, if (gdk_event->button == 1) { + gs_lastLeftClickHeader = column; + wxDataViewCtrl *dv = column->GetOwner(); wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, dv->GetId() ); event.SetDataViewColumn( column ); @@ -1913,6 +1989,16 @@ gtk_dataview_header_button_press_callback( GtkWidget *widget, return FALSE; } + if (gdk_event->button == 3) + { + wxDataViewCtrl *dv = column->GetOwner(); + wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, dv->GetId() ); + event.SetDataViewColumn( column ); + event.SetModel( dv->GetModel() ); + if (dv->GetEventHandler()->ProcessEvent( event )) + return FALSE; + } + return FALSE; } @@ -2299,6 +2385,7 @@ wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl *owner, m_root = NULL; m_sort_order = GTK_SORT_ASCENDING; m_sort_column = -1; + m_dataview_sort_column = NULL; InitTree(); } @@ -2319,17 +2406,19 @@ void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode *node ) { if (node->GetChildCount() == 0) { - wxDataViewItem child = m_wx_model->GetFirstChild( node->GetItem() ); - while (child.IsOk()) + wxDataViewItemArray children; + unsigned int count = m_wx_model->GetChildren( node->GetItem(), children ); + unsigned int pos; + for (pos = 0; pos < count; pos++) { + wxDataViewItem child = children[pos]; + if (m_wx_model->IsContainer( child )) node->AddNode( new wxGtkTreeModelNode( node, child, this ) ); else node->AddLeave( child.GetID() ); // Don't send any events here - - child = m_wx_model->GetNextSibling( child ); } } } @@ -2726,7 +2815,7 @@ wxdataview_selection_changed_callback( GtkTreeSelection* selection, wxDataViewCt if (!GTK_WIDGET_REALIZED(dv->m_widget)) return; - wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_SELECTED, dv->GetId() ); + wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, dv->GetId() ); event.SetItem( dv->GetSelection() ); event.SetModel( dv->GetModel() ); dv->GetEventHandler()->ProcessEvent( event ); @@ -3048,6 +3137,24 @@ bool wxDataViewCtrl::ClearColumns() return true; } +int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn *column ) const +{ + GtkTreeViewColumn *gtk_column = GTK_TREE_VIEW_COLUMN(column->GetConstGtkHandle()); + + GList *list = gtk_tree_view_get_columns( GTK_TREE_VIEW(m_treeview) ); + + gint pos = g_list_index( list, (gconstpointer) gtk_column ); + + g_list_free( list ); + + return pos; +} + +wxDataViewColumn *wxDataViewCtrl::GetSortingColumn() const +{ + return m_internal->GetDataViewSortColumn(); +} + void wxDataViewCtrl::Expand( const wxDataViewItem & item ) { GtkTreeIter iter;