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
This commit is contained in:
@@ -154,6 +154,8 @@ public:
|
|||||||
// specified) and if the control has wxHD_ALLOW_REORDER style as well
|
// specified) and if the control has wxHD_ALLOW_REORDER style as well
|
||||||
bool ShowCustomizeDialog();
|
bool ShowCustomizeDialog();
|
||||||
|
|
||||||
|
// compute column title width
|
||||||
|
int GetColumnTitleWidth(const wxHeaderColumn& col);
|
||||||
|
|
||||||
// implementation only from now on
|
// implementation only from now on
|
||||||
// -------------------------------
|
// -------------------------------
|
||||||
|
@@ -374,6 +374,13 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool ShowCustomizeDialog();
|
bool ShowCustomizeDialog();
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns width needed for given column's title.
|
||||||
|
|
||||||
|
@since 2.9.4
|
||||||
|
*/
|
||||||
|
int GetColumnTitleWidth(const wxHeaderColumn& col);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
Method to be implemented by the derived classes to return the
|
Method to be implemented by the derived classes to return the
|
||||||
|
@@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
#include "wx/headerctrl.h"
|
#include "wx/headerctrl.h"
|
||||||
#include "wx/rearrangectrl.h"
|
#include "wx/rearrangectrl.h"
|
||||||
|
#include "wx/renderer.h"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
@@ -107,6 +108,21 @@ void wxHeaderCtrlBase::SetColumnCount(unsigned int count)
|
|||||||
DoSetCount(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
|
// wxHeaderCtrlBase event handling
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -122,8 +138,7 @@ void wxHeaderCtrlBase::OnSeparatorDClick(wxHeaderCtrlEvent& event)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int w = wxWindowBase::GetTextExtent(column.GetTitle()).x;
|
int w = GetColumnTitleWidth(column);
|
||||||
w += 4*GetCharWidth(); // add some arbitrary margins around text
|
|
||||||
|
|
||||||
if ( !UpdateColumnWidthToFit(col, w) )
|
if ( !UpdateColumnWidthToFit(col, w) )
|
||||||
event.Skip();
|
event.Skip();
|
||||||
|
@@ -4647,13 +4647,7 @@ unsigned int wxDataViewCtrl::GetBestColumnWidth(int idx) const
|
|||||||
m_clientArea->GetRowHeight());
|
m_clientArea->GetRowHeight());
|
||||||
|
|
||||||
if ( m_headerArea )
|
if ( m_headerArea )
|
||||||
{
|
calculator.UpdateWithWidth(m_headerArea->GetColumnTitleWidth(*column));
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The code below deserves some explanation. For very large controls, we
|
// The code below deserves some explanation. For very large controls, we
|
||||||
// simply can't afford to calculate sizes for all items, it takes too
|
// simply can't afford to calculate sizes for all items, it takes too
|
||||||
|
Reference in New Issue
Block a user