align the items correctly with wxLC_ALIGN_TOP

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@23587 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2003-09-14 21:10:22 +00:00
parent 13602ebd04
commit 94dd23aebc

View File

@@ -282,6 +282,18 @@ public:
// the part to be highlighted // the part to be highlighted
wxRect m_rectHighlight; wxRect m_rectHighlight;
// extend all our rects to be centered inside theo ne of given width
void ExtendWidth(wxCoord w)
{
wxASSERT_MSG( m_rectAll.width <= w,
_T("width can only be increased") );
m_rectAll.width = w;
m_rectLabel.x = m_rectAll.x + (w - m_rectLabel.width)/2;
m_rectIcon.x = m_rectAll.x + (w - m_rectIcon.width)/2;
m_rectHighlight.x = m_rectAll.x + (w - m_rectHighlight.width)/2;
}
} *m_gi; } *m_gi;
// is this item selected? [NB: not used in virtual mode] // is this item selected? [NB: not used in virtual mode]
@@ -1115,16 +1127,17 @@ void wxListLineData::CalculateSize( wxDC *dc, int spacing )
wxListItemData *item = node->GetData(); wxListItemData *item = node->GetData();
wxString s;
wxCoord lw, lh;
switch ( GetMode() ) switch ( GetMode() )
{ {
case wxLC_ICON: case wxLC_ICON:
case wxLC_SMALL_ICON: case wxLC_SMALL_ICON:
{
m_gi->m_rectAll.width = spacing; m_gi->m_rectAll.width = spacing;
wxString s = item->GetText(); s = item->GetText();
wxCoord lw, lh;
if ( s.empty() ) if ( s.empty() )
{ {
lh = lh =
@@ -1170,14 +1183,11 @@ void wxListLineData::CalculateSize( wxDC *dc, int spacing )
m_gi->m_rectHighlight.width = m_gi->m_rectIcon.width; m_gi->m_rectHighlight.width = m_gi->m_rectIcon.width;
m_gi->m_rectHighlight.height = m_gi->m_rectIcon.height; m_gi->m_rectHighlight.height = m_gi->m_rectIcon.height;
} }
}
break; break;
case wxLC_LIST: case wxLC_LIST:
{ s = item->GetTextForMeasuring();
wxString s = item->GetTextForMeasuring();
wxCoord lw,lh;
dc->GetTextExtent( s, &lw, &lh ); dc->GetTextExtent( s, &lw, &lh );
if (lh < SCROLL_UNIT_Y) if (lh < SCROLL_UNIT_Y)
lh = SCROLL_UNIT_Y; lh = SCROLL_UNIT_Y;
@@ -1204,7 +1214,6 @@ void wxListLineData::CalculateSize( wxDC *dc, int spacing )
m_gi->m_rectHighlight.width = m_gi->m_rectAll.width; m_gi->m_rectHighlight.width = m_gi->m_rectAll.width;
m_gi->m_rectHighlight.height = m_gi->m_rectAll.height; m_gi->m_rectHighlight.height = m_gi->m_rectAll.height;
}
break; break;
case wxLC_REPORT: case wxLC_REPORT:
@@ -1446,17 +1455,28 @@ void wxListLineData::Draw( wxDC *dc )
dc->DrawRectangle( m_gi->m_rectHighlight ); dc->DrawRectangle( m_gi->m_rectHighlight );
} }
// just for debugging to better see where the items are
#if 0
dc->SetPen(*wxRED_PEN);
dc->SetBrush(*wxTRANSPARENT_BRUSH);
dc->DrawRectangle( m_gi->m_rectAll );
dc->SetPen(*wxGREEN_PEN);
dc->DrawRectangle( m_gi->m_rectIcon );
#endif // 0
wxListItemData *item = node->GetData(); wxListItemData *item = node->GetData();
if (item->HasImage()) if (item->HasImage())
{ {
wxRect rectIcon = m_gi->m_rectIcon; // centre the image inside our rectangle, this looks nicer when items
m_owner->DrawImage( item->GetImage(), dc, // ae aligned in a row
rectIcon.x, rectIcon.y ); const wxRect& rectIcon = m_gi->m_rectIcon;
m_owner->DrawImage(item->GetImage(), dc, rectIcon.x, rectIcon.y);
} }
if (item->HasText()) if (item->HasText())
{ {
wxRect rectLabel = m_gi->m_rectLabel; const wxRect& rectLabel = m_gi->m_rectLabel;
wxDCClipper clipper(*dc, rectLabel); wxDCClipper clipper(*dc, rectLabel);
dc->DrawText(item->GetText(), rectLabel.x, rectLabel.y); dc->DrawText(item->GetText(), rectLabel.x, rectLabel.y);
@@ -3892,7 +3912,10 @@ void wxListMainWindow::RecalculatePositions(bool noRefresh)
int x = EXTRA_BORDER_X; int x = EXTRA_BORDER_X;
int y = EXTRA_BORDER_Y; int y = EXTRA_BORDER_Y;
for ( size_t i = 0; i < count; i++ ) wxCoord widthMax = 0;
size_t i;
for ( i = 0; i < count; i++ )
{ {
wxListLineData *line = GetLine(i); wxListLineData *line = GetLine(i);
line->CalculateSize( &dc, iconSpacing ); line->CalculateSize( &dc, iconSpacing );
@@ -3902,6 +3925,9 @@ void wxListMainWindow::RecalculatePositions(bool noRefresh)
if ( HasFlag(wxLC_ALIGN_TOP) ) if ( HasFlag(wxLC_ALIGN_TOP) )
{ {
if ( sizeLine.x > widthMax )
widthMax = sizeLine.x;
y += sizeLine.y; y += sizeLine.y;
} }
else // wxLC_ALIGN_LEFT else // wxLC_ALIGN_LEFT
@@ -3910,6 +3936,18 @@ void wxListMainWindow::RecalculatePositions(bool noRefresh)
} }
} }
if ( HasFlag(wxLC_ALIGN_TOP) )
{
// traverse the items again and tweak their sizes so that they are
// all the same in a row
for ( i = 0; i < count; i++ )
{
wxListLineData *line = GetLine(i);
line->m_gi->ExtendWidth(widthMax);
}
}
SetScrollbars SetScrollbars
( (
SCROLL_UNIT_X, SCROLL_UNIT_X,