diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index 8f31c106ef..99645ba7cc 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -422,12 +422,35 @@ public: // Static methods allowing to create objects actually specifying behaviour. static wxGridFitMode Clip() { return wxGridFitMode(Mode_Clip); } static wxGridFitMode Overflow() { return wxGridFitMode(Mode_Overflow); } + static wxGridFitMode Ellipsize(wxEllipsizeMode ellipsize = wxELLIPSIZE_END) + { + // This cast works because the enum elements are the same, see below. + return wxGridFitMode(static_cast(ellipsize)); + } // Accessors. bool IsSpecified() const { return m_mode != Mode_Unset; } bool IsClip() const { return m_mode == Mode_Clip; } bool IsOverflow() const { return m_mode == Mode_Overflow; } + wxEllipsizeMode GetEllipsizeMode() const + { + switch ( m_mode ) + { + case Mode_Unset: + case Mode_EllipsizeStart: + case Mode_EllipsizeMiddle: + case Mode_EllipsizeEnd: + return static_cast(m_mode); + + case Mode_Overflow: + case Mode_Clip: + break; + } + + return wxELLIPSIZE_NONE; + } + // This one is used in the implementation only. static wxGridFitMode FromOverflowFlag(bool allow) { return allow ? Overflow() : Clip(); } @@ -435,7 +458,12 @@ public: private: enum Mode { - Mode_Unset = -1, + // This is a hack to save space: the first 4 elements of this enum are + // the same as those of wxEllipsizeMode. + Mode_Unset = wxELLIPSIZE_NONE, + Mode_EllipsizeStart = wxELLIPSIZE_START, + Mode_EllipsizeMiddle = wxELLIPSIZE_MIDDLE, + Mode_EllipsizeEnd = wxELLIPSIZE_END, Mode_Overflow, Mode_Clip }; diff --git a/interface/wx/grid.h b/interface/wx/grid.h index 0dc3108fc1..81a372cff3 100644 --- a/interface/wx/grid.h +++ b/interface/wx/grid.h @@ -888,6 +888,9 @@ public: cells, if the cell contents still doesn't fit after overflowing into the immediately neighbouring cell. - Clip the cell contents, discarding the part which doesn't fit. + - Ellipsize the cell contents, i.e. replace the non-fitting part with + ellipsis (@c ...), putting the ellipsis at the end by default, but possibly + at the beginning or in the middle. The default behaviour is to overflow, use wxGrid::SetDefaultCellFitMode() to change this, for example: @@ -925,6 +928,11 @@ public: */ static wxGridFitMode Overflow(); + /** + Pseudo-constructor for object specifying ellipsize behaviour. + */ + static wxGridFitMode Ellipsize(wxEllipsizeMode ellipsize = wxELLIPSIZE_END); + /** Return true if the object specifies some particular behaviour. @@ -946,6 +954,15 @@ public: This method returns @true only for the objects returned by Overflow(). */ bool IsOverflow() const; + + /** + Return ellipsize mode, possibly @c wxELLIPSIZE_NONE. + + For the objects constructed using Ellipsize(), the same ellipsization + mode as was passed to it is returned. For all the other objects, + ::wxELLIPSIZE_NONE is. + */ + wxEllipsizeMode GetEllipsizeMode() const; }; /** diff --git a/samples/grid/griddemo.cpp b/samples/grid/griddemo.cpp index 0560c38319..b76d441ef7 100644 --- a/samples/grid/griddemo.cpp +++ b/samples/grid/griddemo.cpp @@ -588,6 +588,12 @@ GridFrame::GridFrame() grid->SetCellRenderer(14, 1, new wxGridCellDateRenderer("%Y-%m-%d")); grid->SetCellEditor(14, 1, new wxGridCellDateEditor); + grid->SetCellValue(13, 3, "String using default ellipsization"); + grid->SetCellFitMode(13, 3, wxGridFitMode::Ellipsize()); + + grid->SetCellValue(13, 4, "String ellipsized in the middle"); + grid->SetCellFitMode(13, 4, wxGridFitMode::Ellipsize(wxELLIPSIZE_MIDDLE)); + const wxString choices[] = { "Please select a choice",