From 5313727812e1636f4c4aeceea3f9e93d01cfce43 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Sat, 14 Jan 2012 16:51:57 +0000 Subject: [PATCH] Make column width calculations in wxDataViewCtrl and wxHeaderCtrl consistent. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70338 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/headerctrl.h | 2 ++ interface/wx/headerctrl.h | 7 +++++++ src/common/headerctrlcmn.cpp | 19 +++++++++++++++++-- src/generic/datavgen.cpp | 8 +------- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/include/wx/headerctrl.h b/include/wx/headerctrl.h index 2d36093efc..9555e26155 100644 --- a/include/wx/headerctrl.h +++ b/include/wx/headerctrl.h @@ -154,6 +154,8 @@ public: // specified) and if the control has wxHD_ALLOW_REORDER style as well bool ShowCustomizeDialog(); + // compute column title width + int GetColumnTitleWidth(const wxHeaderColumn& col); // implementation only from now on // ------------------------------- diff --git a/interface/wx/headerctrl.h b/interface/wx/headerctrl.h index 718e02749a..1ead478039 100644 --- a/interface/wx/headerctrl.h +++ b/interface/wx/headerctrl.h @@ -374,6 +374,13 @@ public: */ bool ShowCustomizeDialog(); + /** + Returns width needed for given column's title. + + @since 2.9.4 + */ + int GetColumnTitleWidth(const wxHeaderColumn& col); + protected: /** Method to be implemented by the derived classes to return the diff --git a/src/common/headerctrlcmn.cpp b/src/common/headerctrlcmn.cpp index be858a6848..98025723ad 100644 --- a/src/common/headerctrlcmn.cpp +++ b/src/common/headerctrlcmn.cpp @@ -31,6 +31,7 @@ #include "wx/headerctrl.h" #include "wx/rearrangectrl.h" +#include "wx/renderer.h" namespace { @@ -107,6 +108,21 @@ void wxHeaderCtrlBase::SetColumnCount(unsigned int count) DoSetCount(count); } +int wxHeaderCtrlBase::GetColumnTitleWidth(const wxHeaderColumn& col) +{ + int w = wxWindowBase::GetTextExtent(col.GetTitle()).x; + + // add some margin: + w += wxRendererNative::Get().GetHeaderButtonMargin(this); + + // if a bitmap is used, add space for it and 2px border: + wxBitmap bmp = col.GetBitmap(); + if ( bmp.IsOk() ) + w += bmp.GetWidth() + 2; + + return w; +} + // ---------------------------------------------------------------------------- // wxHeaderCtrlBase event handling // ---------------------------------------------------------------------------- @@ -122,8 +138,7 @@ void wxHeaderCtrlBase::OnSeparatorDClick(wxHeaderCtrlEvent& event) return; } - int w = wxWindowBase::GetTextExtent(column.GetTitle()).x; - w += 4*GetCharWidth(); // add some arbitrary margins around text + int w = GetColumnTitleWidth(column); if ( !UpdateColumnWidthToFit(col, w) ) event.Skip(); diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index e8d83fed0a..852a50815e 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -4647,13 +4647,7 @@ unsigned int wxDataViewCtrl::GetBestColumnWidth(int idx) const m_clientArea->GetRowHeight()); if ( m_headerArea ) - { - int header_width = m_headerArea->GetTextExtent(column->GetTitle()).x; - // Labels on native MSW header are indented on both sides - header_width += - wxRendererNative::Get().GetHeaderButtonMargin(m_headerArea); - calculator.UpdateWithWidth(header_width); - } + calculator.UpdateWithWidth(m_headerArea->GetColumnTitleWidth(*column)); // The code below deserves some explanation. For very large controls, we // simply can't afford to calculate sizes for all items, it takes too -- 2.45.2