Add API for ellipsization support to wxGrid
This API is not implemented yet, i.e. ellipsization mode is not respected for now. This commit just adds the API, documents it and adds an example of using it in the sample.
This commit is contained in:
@@ -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<Mode>(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<wxEllipsizeMode>(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
|
||||
};
|
||||
|
@@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@@ -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",
|
||||
|
Reference in New Issue
Block a user