Implement support for ellipsization mode in wxGrid
Add another wxGrid::DrawTextRectangle() overload, taking wxGridCellAttr and ellipsizing the string if necessary, i.e. if the fitting mode of this attribute indicates that we should do it. Switch the code of all renderers for which it makes sense to use ellipsization to use the new overload.
This commit is contained in:
@@ -1160,6 +1160,13 @@ public:
|
|||||||
int verticalAlignment = wxALIGN_TOP,
|
int verticalAlignment = wxALIGN_TOP,
|
||||||
int textOrientation = wxHORIZONTAL ) const;
|
int textOrientation = wxHORIZONTAL ) const;
|
||||||
|
|
||||||
|
void DrawTextRectangle(wxDC& dc,
|
||||||
|
const wxString& text,
|
||||||
|
const wxRect& rect,
|
||||||
|
const wxGridCellAttr& attr,
|
||||||
|
int defaultHAlign = wxALIGN_INVALID,
|
||||||
|
int defaultVAlign = wxALIGN_INVALID);
|
||||||
|
|
||||||
// ------ grid render function for printing
|
// ------ grid render function for printing
|
||||||
//
|
//
|
||||||
void Render( wxDC& dc,
|
void Render( wxDC& dc,
|
||||||
|
@@ -6822,6 +6822,28 @@ void wxGrid::DrawTextRectangle(wxDC& dc,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxGrid::DrawTextRectangle(wxDC& dc,
|
||||||
|
const wxString& text,
|
||||||
|
const wxRect& rect,
|
||||||
|
const wxGridCellAttr& attr,
|
||||||
|
int hAlign,
|
||||||
|
int vAlign)
|
||||||
|
{
|
||||||
|
attr.GetNonDefaultAlignment(&hAlign, &vAlign);
|
||||||
|
|
||||||
|
// This does nothing if there is no need to ellipsize.
|
||||||
|
const wxString& ellipsizedText = wxControl::Ellipsize
|
||||||
|
(
|
||||||
|
text,
|
||||||
|
dc,
|
||||||
|
attr.GetFitMode().GetEllipsizeMode(),
|
||||||
|
rect.GetWidth(),
|
||||||
|
wxELLIPSIZE_FLAGS_NONE
|
||||||
|
);
|
||||||
|
|
||||||
|
DrawTextRectangle(dc, ellipsizedText, rect, hAlign, vAlign);
|
||||||
|
}
|
||||||
|
|
||||||
// Split multi-line text up into an array of strings.
|
// Split multi-line text up into an array of strings.
|
||||||
// Any existing contents of the string array are preserved.
|
// Any existing contents of the string array are preserved.
|
||||||
//
|
//
|
||||||
|
@@ -148,15 +148,12 @@ void wxGridCellDateRenderer::Draw(wxGrid& grid,
|
|||||||
|
|
||||||
SetTextColoursAndFont(grid, attr, dc, isSelected);
|
SetTextColoursAndFont(grid, attr, dc, isSelected);
|
||||||
|
|
||||||
// draw the text right aligned by default
|
|
||||||
int hAlign = wxALIGN_RIGHT,
|
|
||||||
vAlign = wxALIGN_INVALID;
|
|
||||||
attr.GetNonDefaultAlignment(&hAlign, &vAlign);
|
|
||||||
|
|
||||||
wxRect rect = rectCell;
|
wxRect rect = rectCell;
|
||||||
rect.Inflate(-1);
|
rect.Inflate(-1);
|
||||||
|
|
||||||
grid.DrawTextRectangle(dc, GetString(grid, row, col), rect, hAlign, vAlign);
|
// draw the text right aligned by default
|
||||||
|
grid.DrawTextRectangle(dc, GetString(grid, row, col), rect, attr,
|
||||||
|
wxALIGN_RIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxSize wxGridCellDateRenderer::GetBestSize(wxGrid& grid,
|
wxSize wxGridCellDateRenderer::GetBestSize(wxGrid& grid,
|
||||||
@@ -246,15 +243,12 @@ void wxGridCellEnumRenderer::Draw(wxGrid& grid,
|
|||||||
|
|
||||||
SetTextColoursAndFont(grid, attr, dc, isSelected);
|
SetTextColoursAndFont(grid, attr, dc, isSelected);
|
||||||
|
|
||||||
// draw the text right aligned by default
|
|
||||||
int hAlign = wxALIGN_RIGHT,
|
|
||||||
vAlign = wxALIGN_INVALID;
|
|
||||||
attr.GetNonDefaultAlignment(&hAlign, &vAlign);
|
|
||||||
|
|
||||||
wxRect rect = rectCell;
|
wxRect rect = rectCell;
|
||||||
rect.Inflate(-1);
|
rect.Inflate(-1);
|
||||||
|
|
||||||
grid.DrawTextRectangle(dc, GetString(grid, row, col), rect, hAlign, vAlign);
|
// draw the text right aligned by default
|
||||||
|
grid.DrawTextRectangle(dc, GetString(grid, row, col), rect, attr,
|
||||||
|
wxALIGN_RIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxSize wxGridCellEnumRenderer::GetBestSize(wxGrid& grid,
|
wxSize wxGridCellEnumRenderer::GetBestSize(wxGrid& grid,
|
||||||
@@ -308,6 +302,8 @@ wxGridCellAutoWrapStringRenderer::Draw(wxGrid& grid,
|
|||||||
wxRect rect = rectCell;
|
wxRect rect = rectCell;
|
||||||
rect.Inflate(-1);
|
rect.Inflate(-1);
|
||||||
|
|
||||||
|
// Do not use here the overload taking the attribute, as this would
|
||||||
|
// ellipsize the text, which is never necessary with this renderer.
|
||||||
grid.DrawTextRectangle(dc, GetTextLines(grid,dc,attr,rect,row,col),
|
grid.DrawTextRectangle(dc, GetTextLines(grid,dc,attr,rect,row,col),
|
||||||
rect, horizAlign, vertAlign);
|
rect, horizAlign, vertAlign);
|
||||||
}
|
}
|
||||||
@@ -595,11 +591,11 @@ void wxGridCellStringRenderer::Draw(wxGrid& grid,
|
|||||||
// erase only this cells background, overflow cells should have been erased
|
// erase only this cells background, overflow cells should have been erased
|
||||||
wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected);
|
wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected);
|
||||||
|
|
||||||
int hAlign, vAlign;
|
|
||||||
attr.GetAlignment(&hAlign, &vAlign);
|
|
||||||
|
|
||||||
if (attr.GetOverflow())
|
if (attr.GetOverflow())
|
||||||
{
|
{
|
||||||
|
int hAlign, vAlign;
|
||||||
|
attr.GetAlignment(&hAlign, &vAlign);
|
||||||
|
|
||||||
int overflowCols = 0;
|
int overflowCols = 0;
|
||||||
int cols = grid.GetNumberCols();
|
int cols = grid.GetNumberCols();
|
||||||
int best_width = GetBestSize(grid,attr,dc,row,col).GetWidth();
|
int best_width = GetBestSize(grid,attr,dc,row,col).GetWidth();
|
||||||
@@ -675,7 +671,7 @@ void wxGridCellStringRenderer::Draw(wxGrid& grid,
|
|||||||
SetTextColoursAndFont(grid, attr, dc, isSelected);
|
SetTextColoursAndFont(grid, attr, dc, isSelected);
|
||||||
|
|
||||||
grid.DrawTextRectangle(dc, grid.GetCellValue(row, col),
|
grid.DrawTextRectangle(dc, grid.GetCellValue(row, col),
|
||||||
rect, hAlign, vAlign);
|
rect, attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -709,15 +705,12 @@ void wxGridCellNumberRenderer::Draw(wxGrid& grid,
|
|||||||
|
|
||||||
SetTextColoursAndFont(grid, attr, dc, isSelected);
|
SetTextColoursAndFont(grid, attr, dc, isSelected);
|
||||||
|
|
||||||
// draw the text right aligned by default
|
|
||||||
int hAlign = wxALIGN_RIGHT,
|
|
||||||
vAlign = wxALIGN_INVALID;
|
|
||||||
attr.GetNonDefaultAlignment(&hAlign, &vAlign);
|
|
||||||
|
|
||||||
wxRect rect = rectCell;
|
wxRect rect = rectCell;
|
||||||
rect.Inflate(-1);
|
rect.Inflate(-1);
|
||||||
|
|
||||||
grid.DrawTextRectangle(dc, GetString(grid, row, col), rect, hAlign, vAlign);
|
// draw the text right aligned by default
|
||||||
|
grid.DrawTextRectangle(dc, GetString(grid, row, col), rect, attr,
|
||||||
|
wxALIGN_RIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxSize wxGridCellNumberRenderer::GetBestSize(wxGrid& grid,
|
wxSize wxGridCellNumberRenderer::GetBestSize(wxGrid& grid,
|
||||||
@@ -824,15 +817,12 @@ void wxGridCellFloatRenderer::Draw(wxGrid& grid,
|
|||||||
|
|
||||||
SetTextColoursAndFont(grid, attr, dc, isSelected);
|
SetTextColoursAndFont(grid, attr, dc, isSelected);
|
||||||
|
|
||||||
// draw the text right aligned by default
|
|
||||||
int hAlign = wxALIGN_RIGHT,
|
|
||||||
vAlign = wxALIGN_INVALID;
|
|
||||||
attr.GetNonDefaultAlignment(&hAlign, &vAlign);
|
|
||||||
|
|
||||||
wxRect rect = rectCell;
|
wxRect rect = rectCell;
|
||||||
rect.Inflate(-1);
|
rect.Inflate(-1);
|
||||||
|
|
||||||
grid.DrawTextRectangle(dc, GetString(grid, row, col), rect, hAlign, vAlign);
|
// draw the text right aligned by default
|
||||||
|
grid.DrawTextRectangle(dc, GetString(grid, row, col), rect, attr,
|
||||||
|
wxALIGN_RIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxSize wxGridCellFloatRenderer::GetBestSize(wxGrid& grid,
|
wxSize wxGridCellFloatRenderer::GetBestSize(wxGrid& grid,
|
||||||
|
Reference in New Issue
Block a user