19#ifndef CELLATTRIBUTES_HPP
20#define CELLATTRIBUTES_HPP
22#include <wx/renderer.h>
23#include <wx/generic/grideditors.h>
43 return c.Red() * 0.299 + c.Green() * 0.587 + c.Blue() * 0.114;
61 return grid.GetRowLabelValue(row) ==
"#";
64 bool isFrame(
const wxGrid& grid,
int row,
int col)
66 return col+1 == grid.GetNumberCols() || row+1 == grid.GetNumberRows();
71 return (grid.GetCursorColumn() == col || grid.GetCursorRow() == row)
82 wxGridCellAttr* highlightAttr;
86 highlightAttr = attr.Clone();
88 highlightAttr->SetFont(highlightAttr->GetFont().Bold());
89 highlightAttr->SetAlignment(wxALIGN_LEFT, wxALIGN_CENTER);
97 double factor = ((bgLuminosity / 255.0 * 0.8) + 0.2);
105 highlightAttr = attr.Clone();
109 return highlightAttr;
114 wxGridCellAttr* frameAttr = attr.Clone();
121 wxGridCellAttr* headlineAttr = attr.Clone();
123 headlineAttr->SetFont(headlineAttr->GetFont().Bold());
124 headlineAttr->SetAlignment(wxALIGN_LEFT, wxALIGN_CENTER);
130 wxGridCellAttr* customAttr = attr.Clone();
132 if (grid.GetTable()->CanGetValueAs(row, col,
"complex"))
134 else if (grid.GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_NUMBER) || grid.GetTable()->CanGetValueAs(row, col,
"datetime"))
136 else if (grid.GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL))
139 customAttr->SetBackgroundColour(
m_shader.
getColour(grid.GetTable()->GetValue(row, col)));
142 const wxColour& bgColour = customAttr->GetBackgroundColour();
145 if (luminosity < 128)
148 customAttr->SetTextColour(wxColour(luminosity, luminosity, luminosity));
157 virtual void Draw(wxGrid& grid,
158 wxGridCellAttr& attr,
167 wxGridCellStringRenderer::Draw(grid, *newAttr, dc, rect, row, col, isSelected);
170 else if (
isFrame(grid, row, col))
173 wxGridCellStringRenderer::Draw(grid, *newAttr, dc, rect, row, col, isSelected);
179 wxGridCellStringRenderer::Draw(grid, *newAttr, dc, rect, row, col, isSelected);
185 wxGridCellStringRenderer::Draw(grid, *newAttr, dc, rect, row, col, isSelected);
189 wxGridCellStringRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);
192 virtual wxGridCellRenderer *
Clone()
const
209 virtual void Draw(wxGrid& grid,
210 wxGridCellAttr& attr,
216 if (grid.GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL) && !
isHeadLine(grid, row))
221 wxGridCellRenderer::Draw(grid, *newAttr, dc, rect, row, col, isSelected);
224 else if (
isFrame(grid, row, col))
227 wxGridCellRenderer::Draw(grid, *newAttr, dc, rect, row, col, isSelected);
233 wxGridCellRenderer::Draw(grid, *newAttr, dc, rect, row, col, isSelected);
237 wxGridCellRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);
240 wxSize size =
GetBestSize(grid, attr, dc, row, col);
243 wxCoord minSize = wxMin(rect.width, rect.height);
244 if ( size.x >= minSize || size.y >= minSize )
247 size.x = size.y = minSize;
252 attr.GetAlignment(&hAlign, &vAlign);
255 if (hAlign == wxALIGN_CENTRE)
257 rectBorder.x = rect.x + rect.width / 2 - size.x / 2;
258 rectBorder.y = rect.y + rect.height / 2 - size.y / 2;
259 rectBorder.width = size.x;
260 rectBorder.height = size.y;
262 else if (hAlign == wxALIGN_LEFT)
264 rectBorder.x = rect.x + 2;
265 rectBorder.y = rect.y + rect.height / 2 - size.y / 2;
266 rectBorder.width = size.x;
267 rectBorder.height = size.y;
269 else if (hAlign == wxALIGN_RIGHT)
271 rectBorder.x = rect.x + rect.width - size.x - 2;
272 rectBorder.y = rect.y + rect.height / 2 - size.y / 2;
273 rectBorder.width = size.x;
274 rectBorder.height = size.y;
277 bool value = grid.GetTable()->GetValueAsBool(row, col);
281 flags |= wxCONTROL_CHECKED;
283 wxRendererNative::Get().DrawCheckBox( &grid, dc, rectBorder, flags );
291 wxGridCellAttr& attr,
297 bestSize = DoGetBestSize(attr, dc,
"---");
302 virtual wxGridCellRenderer *
Clone()
const
340 virtual void Create(wxWindow* parent, wxWindowID
id, wxEvtHandler* evtHandler)
override
342 int style = wxTE_PROCESS_ENTER | wxTE_PROCESS_TAB | wxBORDER_NONE;
345 m_text =
new wxTextCtrl(parent,
id, wxEmptyString, wxDefaultPosition, wxDefaultSize, style);
353 m_checkBox =
new wxCheckBox(parent,
id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
357 m_comboBox =
new wxComboBox(parent,
id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxArrayString(), style);
364 wxGridCellEditor::Create(parent,
id, evtHandler);
374 virtual void SetSize(
const wxRect& _rect)
override
389 virtual void PaintBackground(wxDC& dc,
const wxRect& rectCell,
const wxGridCellAttr& attr)
override
391 wxGridCellEditor::PaintBackground(dc, rectCell, attr);
405 switch (event.GetKeyCode())
415 return wxGridCellEditor::IsAcceptedKey(event);
430 virtual void BeginEdit(
int row,
int col, wxGrid* grid)
override
443 bool isHead = grid->GetRowLabelValue(row) ==
"#";
448 && (
int)vTypes.size() > col
456 && (
int)vTypes.size() > col
464 const std::vector<std::string>& vCategories = _tab->
getCategories(col);
467 for (
const auto& c : vCategories)
473 wxGridCellEditorEvtHandler* evtHandler =
nullptr;
476 evtHandler = wxDynamicCast(
m_comboBox->GetEventHandler(), wxGridCellEditorEvtHandler);
480 evtHandler->SetInSetFocus(
true);
488 evtHandler->SetInSetFocus(
false);
496 m_text->SetInsertionPointEnd();
503 m_control->SetFocus();
519 virtual bool EndEdit(
int row,
int col,
const wxGrid* grid,
const wxString& oldval, wxString *newval)
override
530 const wxString value =
m_text->GetValue();
552 const wxString value =
m_comboBox->GetValue();
581 virtual void ApplyEdit(
int row,
int col, wxGrid* grid)
override
583 grid->GetTable()->SetValue(row, col,
m_value);
598 m_text->SetInsertionPointEnd();
644 wxTextEntry* textField =
dynamic_cast<wxTextEntry*
>(m_control);
651 bool isPrintable =
false;
653 ch =
event.GetUnicodeKey();
659 ch =
event.GetKeyCode();
660 isPrintable = ch >= WXK_SPACE && ch < WXK_START;
668 textField->Remove(0, 1);
674 const long pos = textField->GetLastPosition();
675 textField->Remove(pos - 1, pos);
685 textField->WriteText(
static_cast<wxChar
>(ch));
691 int keycode =
event.GetKeyCode();
723 m_text->SetInsertionPointEnd();
750 virtual wxGridCellEditor *
Clone()
const override
776 virtual void Show(
bool show, wxGridCellAttr *attr =
nullptr)
override
788 wxColour colBg = attr ? attr->GetBackgroundColour() : *wxLIGHT_GREY;
812 wxRect textRect(_rect);
813 const wxSize bestSize =
m_comboBox->GetBestSize();
814 const wxCoord diffY = bestSize.GetHeight() - rect.GetHeight();
819 rect.height += diffY;
839 textRect.height -= 2;
842 m_text->SetSize(textRect, wxSIZE_ALLOW_MINUS_ONE);
843 m_comboBox->SetSize(rect, wxSIZE_ALLOW_MINUS_ONE);
858 wxCoord minSize = wxMin(_rect.width, _rect.height);
863 if (!(checkBoxSize == sizeBest))
866 checkBoxSize = sizeBest;
870 if (checkBoxSize.x >= minSize || checkBoxSize.y >= minSize)
873 checkBoxSize.x = checkBoxSize.y = minSize - 2;
885 int hAlign = wxALIGN_CENTRE;
886 int vAlign = wxALIGN_CENTRE;
889 GetCellAttr()->GetAlignment(&hAlign, &vAlign);
893 if (hAlign == wxALIGN_LEFT)
897 y = _rect.y + _rect.height / 2 - checkBoxSize.y / 2;
899 else if (hAlign == wxALIGN_RIGHT)
901 x = _rect.x + _rect.width - checkBoxSize.x - 2;
902 y = _rect.y + _rect.height / 2 - checkBoxSize.y / 2;
904 else if (hAlign == wxALIGN_CENTRE)
906 x = 1 + _rect.x + _rect.width / 2 - checkBoxSize.x / 2;
907 y = _rect.y + _rect.height / 2 - checkBoxSize.y / 2;
936 m_grid->SaveEditControlValue();
937 m_grid->HideCellEditControl();
940 m_grid->MoveCursorDown(
false);
942 m_grid->GetGridWindow()->SetFocus();
static wxColour HighlightColor
static wxColour FrameColor
static wxColour HeadlineColor
static wxColour HighlightHeadlineColor
static double calculateLuminosity(const wxColour &c)
Calculates the luminosity of the passed colour.
This class represents a special renderer for three-state booleans, i.e. booleans, which may have a un...
virtual void Draw(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &rect, int row, int col, bool isSelected)
virtual wxSize GetBestSize(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col)
AdvBooleanCellRenderer(const CellValueShader &shader=CellValueShader())
virtual wxGridCellRenderer * Clone() const
This class represents an extension to the usual cell string renderer to provide functionalities to hi...
bool isHeadLine(const wxGrid &grid, int row)
wxGridCellAttr * createHeadlineAttr(const wxGridCellAttr &attr)
wxGridCellAttr * createFrameAttr(const wxGridCellAttr &attr)
virtual void Draw(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &rect, int row, int col, bool isSelected)
wxGridCellAttr * createCustomColorAttr(const wxGridCellAttr &attr, const wxGrid &grid, int row, int col)
bool isPartOfCursor(const wxGrid &grid, int row, int col)
AdvStringCellRenderer(const CellValueShader shader=CellValueShader())
bool isFrame(const wxGrid &grid, int row, int col)
virtual wxGridCellRenderer * Clone() const
wxGridCellAttr * createHighlightedAttr(const wxGridCellAttr &attr, const wxGrid &grid, int row, int col)
A class to handle value-based cell shading using a custom colorscheme and custom conditions.
wxColour getColour(const mu::value_type &val) const
Calculate the colour for a numerical value.
bool isActive() const
Detect, whether this shader is actually active or an empty shader.
This class represents the grid cell editor which automatically selects the necessary edit control for...
virtual void ApplyEdit(int row, int col, wxGrid *grid) override
Called after EndEdit if the user did not cancel the process and will store the value in the correct c...
CombinedCellEditor(wxGrid *grid)
Construct this editor for the current wxGrid.
void OnEnterKey(wxCommandEvent &event)
Respond to ENTER key events created by the combo box control.
void SetTextCtrlSize(const wxRect &_rect)
Set the size and position of the text control and the combo box.
virtual void Reset() override
Reset the control to its initial state.
virtual void SetSize(const wxRect &_rect) override
Set size and position of the controls.
virtual void StartingKey(wxKeyEvent &event) override
Called after BeginEdit to give this control the possibility to respond to the initial key.
virtual void Show(bool show, wxGridCellAttr *attr=nullptr) override
Show or hide the edit control. Will in fact only hide the controls. Showing them is done in BeginEdit...
virtual void BeginEdit(int row, int col, wxGrid *grid) override
Begin the editing process. Will select the correct edit control depending on the underlying column da...
virtual void PaintBackground(wxDC &dc, const wxRect &rectCell, const wxGridCellAttr &attr) override
Paint the background.
virtual bool IsAcceptedKey(wxKeyEvent &event) override
Determine, whether the pressed key is accepted by this editor and will start the editing process.
virtual bool EndEdit(int row, int col, const wxGrid *grid, const wxString &oldval, wxString *newval) override
End the editing process. Will store the value of the edit control internally and reset the edit contr...
virtual void HandleReturn(wxKeyEvent &event) override
We do not handle the return key as a character.
void finalize(bool moveCursor)
Inform the grid to finalize the editing process.
virtual void Create(wxWindow *parent, wxWindowID id, wxEvtHandler *evtHandler) override
Create the necessary edit controls.
virtual wxGridCellEditor * Clone() const override
Get a copy of this editor instance.
void SetCheckBoxSize(const wxRect &_rect)
Set size and position of the check box.
virtual void StartingClick() override
Called after BeginEdit if the user clicked on this cell to handle the click event.
virtual wxString GetValue() const override
Get the value stored in this editor.
This class is a specialisation for the standard wxGridTableBase supporting complex numbers as well as...
std::vector< std::string > getCategories(int col) const
Returns the categories in the selected column, if this is a categorical column.
std::vector< int > getColumnTypes() const
Returns the types of the handled table.
virtual wxString GetValue(int row, int col)
This virtual member function returns the value of the selected cell as string.
MUP_BASETYPE value_type
The numeric datatype used by the parser.
std::string toString(int)
Converts an integer to a string without the Settings bloat.