From 0f4a54a6556d348d4c9dd9e46a54d5f30fdbaa3b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 11 Jun 2011 23:56:44 +0000 Subject: [PATCH] Implement wxDataViewCtrl::SetRowHeight() for wxGTK. Also document that this method can only be used to increase the row height compared to the default, not to make it smaller. See #12749. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67920 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/dataview.h | 11 ++++++++++- interface/wx/dataview.h | 10 +++++++--- src/gtk/dataview.cpp | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/include/wx/gtk/dataview.h b/include/wx/gtk/dataview.h index 73254d4892..55beb85d48 100644 --- a/include/wx/gtk/dataview.h +++ b/include/wx/gtk/dataview.h @@ -158,7 +158,9 @@ public: wxDataViewColumn *&column ) const; virtual wxRect GetItemRect( const wxDataViewItem &item, const wxDataViewColumn *column = NULL ) const; - + + virtual bool SetRowHeight( int rowHeight ); + virtual void StartEditor( const wxDataViewItem & item, unsigned int column ); virtual void Expand( const wxDataViewItem & item ); @@ -182,6 +184,8 @@ public: virtual void OnInternalIdle(); + int GTKGetUniformRowHeight() const { return m_uniformRowHeight; } + protected: virtual void DoSetExpanderColumn(); virtual void DoSetIndent(); @@ -209,6 +213,11 @@ private: wxDataViewColumnList m_cols; wxDataViewItem m_ensureVisibleDefered; + // By default this is set to -1 and the height of the rows is determined by + // GetRect() methods of the renderers but this can be set to a positive + // value to force the height of all rows to the given value. + int m_uniformRowHeight; + virtual void AddChildGTK(wxWindowGTK* child); void GtkEnableSelectionEvents(); void GtkDisableSelectionEvents(); diff --git a/interface/wx/dataview.h b/interface/wx/dataview.h index 37404e1d1f..dd6e049534 100644 --- a/interface/wx/dataview.h +++ b/interface/wx/dataview.h @@ -1120,9 +1120,13 @@ public: This function can only be used when all rows have the same height, i.e. when wxDV_VARIABLE_LINE_HEIGHT flag is not used. - Currently this is implemented in the generic version only and nothing - is done (and @false returned) when using the native GTK or OS X - versions. + Currently this is implemented in the generic and native GTK versions + only and nothing is done (and @false returned) when using OS X port. + + Also notice that this method can only be used to increase the row + height compared with the default one (as determined by the return value + of wxDataViewRenderer::GetSize()), if it is set to a too small value + then the minimum required by the renderers will be used. @return @true if the line height was changed or @false otherwise. diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index c268ff4682..01ba4e009c 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -1333,6 +1333,17 @@ gtk_wx_cell_renderer_get_size (GtkCellRenderer *renderer, wxSize size = cell->GetSize(); + wxDataViewCtrl * const ctrl = cell->GetOwner()->GetOwner(); + + // Uniform row height, if specified, overrides the value returned by the + // renderer. + if ( !ctrl->HasFlag(wxDV_VARIABLE_LINE_HEIGHT) ) + { + const int uniformHeight = ctrl->GTKGetUniformRowHeight(); + if ( uniformHeight > 0 ) + size.y = uniformHeight; + } + int xpad, ypad; gtk_cell_renderer_get_padding(renderer, &xpad, &ypad); int calc_width = xpad * 2 + size.x; @@ -4473,6 +4484,8 @@ void wxDataViewCtrl::Init() m_internal = NULL; m_cols.DeleteContents( true ); + + m_uniformRowHeight = -1; } bool wxDataViewCtrl::Create(wxWindow *parent, @@ -5103,6 +5116,12 @@ wxDataViewCtrl::GetItemRect(const wxDataViewItem& WXUNUSED(item), return wxRect(); } +bool wxDataViewCtrl::SetRowHeight(int rowHeight) +{ + m_uniformRowHeight = rowHeight; + return true; +} + void wxDataViewCtrl::DoSetExpanderColumn() { gtk_tree_view_set_expander_column( GTK_TREE_VIEW(m_treeview),