From e23903504ea78e9ace9bf6e0e9a214111b74dd4f Mon Sep 17 00:00:00 2001 From: lsv Date: Fri, 13 Oct 2023 15:17:14 +0500 Subject: [PATCH] Add ellipsize in gridcell MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Для знанчений, которые не могут быть отображены полностью в ячейке результата, то справа или слева выводиться "..." --- ctl/ctlSQLGrid.cpp | 1 + include/ctl/ctlSQLGrid.h | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ctl/ctlSQLGrid.cpp b/ctl/ctlSQLGrid.cpp index 450c1e1..0722b62 100644 --- a/ctl/ctlSQLGrid.cpp +++ b/ctl/ctlSQLGrid.cpp @@ -189,6 +189,7 @@ void ctlSQLGrid::OnGridColSize(wxGridSizeEvent &event) { // Save key="index:label", value=size int col = event.GetRowOrCol(); + if (col < 0) return; colSizes[GetColKeyValue(col)] = GetColSize(col); } diff --git a/include/ctl/ctlSQLGrid.h b/include/ctl/ctlSQLGrid.h index 0191b9d..b233928 100644 --- a/include/ctl/ctlSQLGrid.h +++ b/include/ctl/ctlSQLGrid.h @@ -203,6 +203,7 @@ class CursorCellRenderer : public wxGridCellStringRenderer { int hAlign, vAlign; int sPos=-1; + bool multiline = false; attr.GetAlignment(&hAlign, &vAlign); ////////////////////////////////////////////////////////////////////////////// //CursorCellRenderer::Draw(grid, attr, dc, rect, row, col, isSelected); // @@ -226,8 +227,10 @@ class CursorCellRenderer : public wxGridCellStringRenderer { wxColor color; color.Set(239, 228, 176); - if (sPos=text.Find(wxT('\n'))!=wxNOT_FOUND ) - dc.SetBrush( wxBrush(color, wxSOLID) ); + if (sPos = text.Find(wxT('\n')) != wxNOT_FOUND) { + dc.SetBrush(wxBrush(color, wxSOLID)); + multiline = true; + } else dc.SetBrush( wxBrush(attr.GetBackgroundColour(), wxSOLID) ); } @@ -287,6 +290,20 @@ class CursorCellRenderer : public wxGridCellStringRenderer } } + if (!multiline) { + //int textWidth = dc.GetTextExtent(text).GetWidth(); + wxEllipsizeMode mode(wxELLIPSIZE_END); + if (hAlign == wxALIGN_RIGHT) mode = wxELLIPSIZE_START; + const wxString& ellipsizedText = wxControl::Ellipsize + ( + text, + dc, + mode, + rect.GetWidth() - 2, + wxELLIPSIZE_FLAGS_NONE + ); + if (ellipsizedText != text) text=ellipsizedText; + } grid.DrawTextRectangle(dc, text, rect, hAlign, vAlign); }