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
void DrawImage( int index, wxDC *dc, int x, int y );
void GetImageSize( int index, int &width, int &height ) const;
void DrawImage( int index, wxDC *dc, int x, int y );
void GetImageSize( int index, int &width, int &height ) const;
- int GetTextLength( const wxString &s ) const;
void SetImageList( wxImageList *imageList, int which );
void SetItemSpacing( int spacing, bool isSmall = false );
void SetImageList( wxImageList *imageList, int which );
void SetItemSpacing( int spacing, bool isSmall = false );
// delete all items but don't refresh: called from dtor
void DoDeleteAllItems();
// delete all items but don't refresh: called from dtor
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
wxCoord m_lineHeight;
// the height of one line using the current font
wxCoord m_lineHeight;
-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 )
{
m_dirty = true;
void wxListMainWindow::SetImageList( wxImageList *imageList, int which )
{
m_dirty = true;
// 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 )
{
wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
void wxListMainWindow::SetColumn( int col, const wxListItem &item )
{
wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
column->SetItem( item );
if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER )
column->SetItem( item );
if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER )
- column->SetWidth(GetTextLength( item.m_text ));
+ column->SetWidth(ComputeMinHeaderWidth(column));
wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin;
if ( headerWin )
wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin;
if ( headerWin )
if (width == wxLIST_AUTOSIZE_USEHEADER)
{
if (width == wxLIST_AUTOSIZE_USEHEADER)
{
- width = GetTextLength(column->GetText());
- 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;
- }
- }
+ width = ComputeMinHeaderWidth(column);
}
else if ( width == wxLIST_AUTOSIZE )
{
}
else if ( width == wxLIST_AUTOSIZE )
{
- if ( IsVirtual() )
- {
- // TODO: determine the max width somehow...
- width = WIDTH_COL_DEFAULT;
- }
- else // !virtual
+ width = ComputeMinHeaderWidth(column);
+
+ if ( !IsVirtual() )
{
wxClientDC dc(this);
dc.SetFont( GetFont() );
{
wxClientDC dc(this);
dc.SetFont( GetFont() );
m_aColWidths.Item(col)->nMaxWidth = max;
}
m_aColWidths.Item(col)->nMaxWidth = max;
}
- max = m_aColWidths.Item(col)->nMaxWidth;
- width = max + AUTOSIZE_COL_MARGIN;
+ max = m_aColWidths.Item(col)->nMaxWidth + AUTOSIZE_COL_MARGIN;
+ if ( width < max )
+ width = max;
{
wxListHeaderData *column = new wxListHeaderData( item );
if (item.m_width == wxLIST_AUTOSIZE_USEHEADER)
{
wxListHeaderData *column = new wxListHeaderData( item );
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();