Fix drawing of expander buttons in wxDataViewCtrl under MSW
The buttons were truncated, making them look ugly, because we didn't allocate enough space for them. Instead of complicating generic wxDataViewCtrl code even further with more MSW-specific code, just let DrawItemTreeButton() center the expander itself in the space allocated for it. This still involves guessing the width of the expander, but this doesn't need to be done as precisely, so it's still an advantage. Note that previously calculating expander size involved m_lineHeight, for some reason, but now we use GetCharWidth() for it, which is more appropriate. Closes #17863.
This commit is contained in:
@@ -75,15 +75,6 @@ static const int SCROLL_UNIT_X = 15;
|
|||||||
// the cell padding on the left/right
|
// the cell padding on the left/right
|
||||||
static const int PADDING_RIGHTLEFT = 3;
|
static const int PADDING_RIGHTLEFT = 3;
|
||||||
|
|
||||||
// the expander space margin
|
|
||||||
static const int EXPANDER_MARGIN = 4;
|
|
||||||
|
|
||||||
#ifdef __WXMSW__
|
|
||||||
static const int EXPANDER_OFFSET = 4;
|
|
||||||
#else
|
|
||||||
static const int EXPANDER_OFFSET = 1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -2540,23 +2531,20 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
|||||||
// Calculate the indent first
|
// Calculate the indent first
|
||||||
indent = GetOwner()->GetIndent() * node->GetIndentLevel();
|
indent = GetOwner()->GetIndent() * node->GetIndentLevel();
|
||||||
|
|
||||||
// we reserve m_lineHeight of horizontal space for the expander
|
// We don't have any method to return the size of the expander
|
||||||
// but leave EXPANDER_MARGIN around the expander itself
|
// button currently (TODO: add one to wxRendererNative), so
|
||||||
int exp_x = cell_rect.x + indent + EXPANDER_MARGIN;
|
// just guesstimate it.
|
||||||
|
const int expWidth = 3*dc.GetCharWidth();
|
||||||
|
|
||||||
indent += m_lineHeight;
|
// draw expander if needed
|
||||||
|
if ( node->HasChildren() )
|
||||||
// draw expander if needed and visible
|
|
||||||
if ( node->HasChildren() && exp_x < cell_rect.GetRight() )
|
|
||||||
{
|
{
|
||||||
dc.SetPen( m_penExpander );
|
dc.SetPen( m_penExpander );
|
||||||
dc.SetBrush( wxNullBrush );
|
dc.SetBrush( wxNullBrush );
|
||||||
|
|
||||||
int exp_size = m_lineHeight - 2*EXPANDER_MARGIN;
|
wxRect rect = cell_rect;
|
||||||
int exp_y = cell_rect.y + (cell_rect.height - exp_size)/2
|
rect.x += indent;
|
||||||
+ EXPANDER_MARGIN - EXPANDER_OFFSET;
|
rect.width = expWidth;
|
||||||
|
|
||||||
const wxRect rect(exp_x, exp_y, exp_size, exp_size);
|
|
||||||
|
|
||||||
int flag = 0;
|
int flag = 0;
|
||||||
if ( m_underMouse == node )
|
if ( m_underMouse == node )
|
||||||
@@ -2571,6 +2559,8 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
|||||||
wxRendererNative::Get().DrawTreeItemButton( this, dc, rect, flag);
|
wxRendererNative::Get().DrawTreeItemButton( this, dc, rect, flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
indent += expWidth;
|
||||||
|
|
||||||
// force the expander column to left-center align
|
// force the expander column to left-center align
|
||||||
cell->SetAlignment( wxALIGN_CENTER_VERTICAL );
|
cell->SetAlignment( wxALIGN_CENTER_VERTICAL );
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user