Merge branch 'grid-native-header-autosize'
Fixes for auto-sizing grid columns when using native header control. Closes https://github.com/wxWidgets/wxWidgets/pull/1579
This commit is contained in:
@@ -2282,6 +2282,7 @@ protected:
|
|||||||
friend class wxGridWindow;
|
friend class wxGridWindow;
|
||||||
friend class wxGridHeaderRenderer;
|
friend class wxGridHeaderRenderer;
|
||||||
|
|
||||||
|
friend class wxGridHeaderColumn;
|
||||||
friend class wxGridHeaderCtrl;
|
friend class wxGridHeaderCtrl;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -2404,6 +2405,8 @@ private:
|
|||||||
wxGridColLabelWindow* colLabelWin);
|
wxGridColLabelWindow* colLabelWin);
|
||||||
void ProcessCornerLabelMouseEvent(wxMouseEvent& event);
|
void ProcessCornerLabelMouseEvent(wxMouseEvent& event);
|
||||||
|
|
||||||
|
void HandleColumnAutosize(int col, const wxMouseEvent& event);
|
||||||
|
|
||||||
void DoColHeaderClick(int col);
|
void DoColHeaderClick(int col);
|
||||||
|
|
||||||
void DoStartResizeCol(int col);
|
void DoStartResizeCol(int col);
|
||||||
|
@@ -95,7 +95,7 @@ public:
|
|||||||
virtual wxString GetTitle() const wxOVERRIDE { return m_grid->GetColLabelValue(m_col); }
|
virtual wxString GetTitle() const wxOVERRIDE { return m_grid->GetColLabelValue(m_col); }
|
||||||
virtual wxBitmap GetBitmap() const wxOVERRIDE { return wxNullBitmap; }
|
virtual wxBitmap GetBitmap() const wxOVERRIDE { return wxNullBitmap; }
|
||||||
virtual int GetWidth() const wxOVERRIDE { return m_grid->GetColSize(m_col); }
|
virtual int GetWidth() const wxOVERRIDE { return m_grid->GetColSize(m_col); }
|
||||||
virtual int GetMinWidth() const wxOVERRIDE { return m_grid->GetColMinimalAcceptableWidth(); }
|
virtual int GetMinWidth() const wxOVERRIDE { return m_grid->GetColMinimalWidth(m_col); }
|
||||||
virtual wxAlignment GetAlignment() const wxOVERRIDE
|
virtual wxAlignment GetAlignment() const wxOVERRIDE
|
||||||
{
|
{
|
||||||
int horz,
|
int horz,
|
||||||
@@ -191,11 +191,9 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// override to implement column auto sizing
|
// override to implement column auto sizing
|
||||||
virtual bool UpdateColumnWidthToFit(unsigned int idx, int widthTitle) wxOVERRIDE
|
virtual bool UpdateColumnWidthToFit(unsigned int idx, int WXUNUSED(widthTitle)) wxOVERRIDE
|
||||||
{
|
{
|
||||||
// TODO: currently grid doesn't support computing the column best width
|
GetOwner()->HandleColumnAutosize(idx, GetDummyMouseEvent());
|
||||||
// from its contents so we just use the best label width as is
|
|
||||||
GetOwner()->SetColSize(idx, widthTitle);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -3874,13 +3874,7 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event, wxGridColLabelWindo
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// adjust column width depending on label text
|
HandleColumnAutosize(colEdge, event);
|
||||||
//
|
|
||||||
// TODO: generate RESIZING event, see #10754
|
|
||||||
if ( !SendGridSizeEvent(wxEVT_GRID_COL_AUTO_SIZE, -1, colEdge, event) )
|
|
||||||
AutoSizeColLabelSize( colEdge );
|
|
||||||
|
|
||||||
SendGridSizeEvent(wxEVT_GRID_COL_SIZE, -1, colEdge, event);
|
|
||||||
|
|
||||||
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, colLabelWin);
|
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, colLabelWin);
|
||||||
m_dragLastPos = -1;
|
m_dragLastPos = -1;
|
||||||
@@ -4023,6 +4017,17 @@ void wxGrid::ProcessCornerLabelMouseEvent( wxMouseEvent& event )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxGrid::HandleColumnAutosize(int col, const wxMouseEvent& event)
|
||||||
|
{
|
||||||
|
// adjust column width depending on label text
|
||||||
|
//
|
||||||
|
// TODO: generate RESIZING event, see #10754
|
||||||
|
if ( !SendGridSizeEvent(wxEVT_GRID_COL_AUTO_SIZE, -1, col, event) )
|
||||||
|
AutoSizeColLabelSize(col);
|
||||||
|
|
||||||
|
SendGridSizeEvent(wxEVT_GRID_COL_SIZE, -1, col, event);
|
||||||
|
}
|
||||||
|
|
||||||
void wxGrid::CancelMouseCapture()
|
void wxGrid::CancelMouseCapture()
|
||||||
{
|
{
|
||||||
// cancel operation currently in progress, whatever it is
|
// cancel operation currently in progress, whatever it is
|
||||||
@@ -9128,16 +9133,23 @@ void wxGrid::SetColSize( int col, int width )
|
|||||||
// show the column back using its old size.
|
// show the column back using its old size.
|
||||||
if ( width == -1 && GetColWidth(col) != 0 )
|
if ( width == -1 && GetColWidth(col) != 0 )
|
||||||
{
|
{
|
||||||
long w, h;
|
if ( m_useNativeHeader )
|
||||||
wxArrayString lines;
|
{
|
||||||
wxClientDC dc(m_colLabelWin);
|
width = GetGridColHeader()->GetColumnTitleWidth(col);
|
||||||
dc.SetFont(GetLabelFont());
|
}
|
||||||
StringToLines(GetColLabelValue(col), lines);
|
|
||||||
if ( GetColLabelTextOrientation() == wxHORIZONTAL )
|
|
||||||
GetTextBoxSize( dc, lines, &w, &h );
|
|
||||||
else
|
else
|
||||||
GetTextBoxSize( dc, lines, &h, &w );
|
{
|
||||||
width = w + 6;
|
long w, h;
|
||||||
|
wxArrayString lines;
|
||||||
|
wxClientDC dc(m_colLabelWin);
|
||||||
|
dc.SetFont(GetLabelFont());
|
||||||
|
StringToLines(GetColLabelValue(col), lines);
|
||||||
|
if ( GetColLabelTextOrientation() == wxHORIZONTAL )
|
||||||
|
GetTextBoxSize( dc, lines, &w, &h );
|
||||||
|
else
|
||||||
|
GetTextBoxSize( dc, lines, &h, &w );
|
||||||
|
width = w + 6;
|
||||||
|
}
|
||||||
|
|
||||||
// Check that it is not less than the minimal width and do use the
|
// Check that it is not less than the minimal width and do use the
|
||||||
// possibly greater than minimal-acceptable-width minimal-width itself
|
// possibly greater than minimal-acceptable-width minimal-width itself
|
||||||
|
Reference in New Issue
Block a user