Improve column auto-sizing code in generic wxListCtrl.
Take the width of the header itself into account when setting width to wxLIST_AUTOSIZE. Also refactor the code to reuse the code used in wxLIST_AUTOSIZE_USEHEADER case in SetColumnWidth() when inserting or updating the column width to this value. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70285 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -575,7 +575,6 @@ public:
|
|||||||
|
|
||||||
void DrawImage( int index, wxDC *dc, int x, int y );
|
void DrawImage( int index, wxDC *dc, int x, int y );
|
||||||
void GetImageSize( int index, int &width, int &height ) const;
|
void GetImageSize( int index, int &width, int &height ) const;
|
||||||
int GetTextLength( const wxString &s ) const;
|
|
||||||
|
|
||||||
void SetImageList( wxImageList *imageList, int which );
|
void SetImageList( wxImageList *imageList, int which );
|
||||||
void SetItemSpacing( int spacing, bool isSmall = false );
|
void SetItemSpacing( int spacing, bool isSmall = false );
|
||||||
@@ -793,6 +792,10 @@ private:
|
|||||||
// delete all items but don't refresh: called from dtor
|
// delete all items but don't refresh: called from dtor
|
||||||
void DoDeleteAllItems();
|
void DoDeleteAllItems();
|
||||||
|
|
||||||
|
// Compute the minimal width needed to fully display the column header.
|
||||||
|
int ComputeMinHeaderWidth(const wxListHeaderData* header) const;
|
||||||
|
|
||||||
|
|
||||||
// the height of one line using the current font
|
// the height of one line using the current font
|
||||||
wxCoord m_lineHeight;
|
wxCoord m_lineHeight;
|
||||||
|
|
||||||
|
@@ -2964,17 +2964,6 @@ void wxListMainWindow::GetImageSize( int index, int &width, int &height ) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxListMainWindow::GetTextLength( const wxString &s ) const
|
|
||||||
{
|
|
||||||
wxClientDC dc( wxConstCast(this, wxListMainWindow) );
|
|
||||||
dc.SetFont( GetFont() );
|
|
||||||
|
|
||||||
wxCoord lw;
|
|
||||||
dc.GetTextExtent( s, &lw, NULL );
|
|
||||||
|
|
||||||
return lw + AUTOSIZE_COL_MARGIN;
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxListMainWindow::SetImageList( wxImageList *imageList, int which )
|
void wxListMainWindow::SetImageList( wxImageList *imageList, int which )
|
||||||
{
|
{
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
@@ -3017,6 +3006,30 @@ int wxListMainWindow::GetItemSpacing( bool isSmall )
|
|||||||
// columns
|
// columns
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
int
|
||||||
|
wxListMainWindow::ComputeMinHeaderWidth(const wxListHeaderData* column) const
|
||||||
|
{
|
||||||
|
wxClientDC dc(const_cast<wxListMainWindow*>(this));
|
||||||
|
|
||||||
|
int width = dc.GetTextExtent(column->GetText()).x + AUTOSIZE_COL_MARGIN;
|
||||||
|
|
||||||
|
width += 2*EXTRA_WIDTH;
|
||||||
|
|
||||||
|
// check for column header's image availability
|
||||||
|
const int image = column->GetImage();
|
||||||
|
if ( image != -1 )
|
||||||
|
{
|
||||||
|
if ( m_small_image_list )
|
||||||
|
{
|
||||||
|
int ix = 0, iy = 0;
|
||||||
|
m_small_image_list->GetSize(image, ix, iy);
|
||||||
|
width += ix + HEADER_IMAGE_MARGIN_IN_REPORT_MODE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
void wxListMainWindow::SetColumn( int col, const wxListItem &item )
|
void wxListMainWindow::SetColumn( int col, const wxListItem &item )
|
||||||
{
|
{
|
||||||
wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
|
wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
|
||||||
@@ -3027,7 +3040,7 @@ void wxListMainWindow::SetColumn( int col, const wxListItem &item )
|
|||||||
column->SetItem( item );
|
column->SetItem( item );
|
||||||
|
|
||||||
if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER )
|
if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER )
|
||||||
column->SetWidth(GetTextLength( item.m_text ));
|
column->SetWidth(ComputeMinHeaderWidth(column));
|
||||||
|
|
||||||
wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin;
|
wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin;
|
||||||
if ( headerWin )
|
if ( headerWin )
|
||||||
@@ -3062,29 +3075,13 @@ void wxListMainWindow::SetColumnWidth( int col, int width )
|
|||||||
|
|
||||||
if (width == wxLIST_AUTOSIZE_USEHEADER)
|
if (width == wxLIST_AUTOSIZE_USEHEADER)
|
||||||
{
|
{
|
||||||
width = GetTextLength(column->GetText());
|
width = ComputeMinHeaderWidth(column);
|
||||||
width += 2*EXTRA_WIDTH;
|
|
||||||
|
|
||||||
// check for column header's image availability
|
|
||||||
const int image = column->GetImage();
|
|
||||||
if ( image != -1 )
|
|
||||||
{
|
|
||||||
if ( m_small_image_list )
|
|
||||||
{
|
|
||||||
int ix = 0, iy = 0;
|
|
||||||
m_small_image_list->GetSize(image, ix, iy);
|
|
||||||
width += ix + HEADER_IMAGE_MARGIN_IN_REPORT_MODE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if ( width == wxLIST_AUTOSIZE )
|
else if ( width == wxLIST_AUTOSIZE )
|
||||||
{
|
{
|
||||||
if ( IsVirtual() )
|
width = ComputeMinHeaderWidth(column);
|
||||||
{
|
|
||||||
// TODO: determine the max width somehow...
|
if ( !IsVirtual() )
|
||||||
width = WIDTH_COL_DEFAULT;
|
|
||||||
}
|
|
||||||
else // !virtual
|
|
||||||
{
|
{
|
||||||
wxClientDC dc(this);
|
wxClientDC dc(this);
|
||||||
dc.SetFont( GetFont() );
|
dc.SetFont( GetFont() );
|
||||||
@@ -3114,8 +3111,9 @@ void wxListMainWindow::SetColumnWidth( int col, int width )
|
|||||||
m_aColWidths.Item(col)->nMaxWidth = max;
|
m_aColWidths.Item(col)->nMaxWidth = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
max = m_aColWidths.Item(col)->nMaxWidth;
|
max = m_aColWidths.Item(col)->nMaxWidth + AUTOSIZE_COL_MARGIN;
|
||||||
width = max + AUTOSIZE_COL_MARGIN;
|
if ( width < max )
|
||||||
|
width = max;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4129,7 +4127,7 @@ void wxListMainWindow::InsertColumn( long col, const wxListItem &item )
|
|||||||
{
|
{
|
||||||
wxListHeaderData *column = new wxListHeaderData( item );
|
wxListHeaderData *column = new wxListHeaderData( item );
|
||||||
if (item.m_width == wxLIST_AUTOSIZE_USEHEADER)
|
if (item.m_width == wxLIST_AUTOSIZE_USEHEADER)
|
||||||
column->SetWidth(GetTextLength( item.m_text ));
|
column->SetWidth(ComputeMinHeaderWidth(column));
|
||||||
|
|
||||||
wxColWidthInfo *colWidthInfo = new wxColWidthInfo();
|
wxColWidthInfo *colWidthInfo = new wxColWidthInfo();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user