NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
cellattributes.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2022 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19#ifndef CELLATTRIBUTES_HPP
20#define CELLATTRIBUTES_HPP
21
22#include <wx/renderer.h>
23#include <wx/generic/grideditors.h>
24
25#include "cellvalueshader.hpp"
26
27// Define the standard colors
28static wxColour HeadlineColor = wxColour(192, 192, 192);
29static wxColour FrameColor = wxColour(230, 230, 230);
30static wxColour HighlightColor = wxColour(192, 227, 248);
31static wxColour HighlightHeadlineColor = wxColour(131, 200, 241);
32
41static double calculateLuminosity(const wxColour& c)
42{
43 return c.Red() * 0.299 + c.Green() * 0.587 + c.Blue() * 0.114;
44}
45
46
54class AdvStringCellRenderer : public wxGridCellStringRenderer
55{
56 protected:
58
59 bool isHeadLine(const wxGrid& grid, int row)
60 {
61 return grid.GetRowLabelValue(row) == "#";
62 }
63
64 bool isFrame(const wxGrid& grid, int row, int col)
65 {
66 return col+1 == grid.GetNumberCols() || row+1 == grid.GetNumberRows();
67 }
68
69 bool isPartOfCursor(const wxGrid& grid, int row, int col)
70 {
71 return (grid.GetCursorColumn() == col || grid.GetCursorRow() == row)
72 && !isFrame(grid, row, col);
73 }
74
76 {
77 return m_shader.isActive();
78 }
79
80 wxGridCellAttr* createHighlightedAttr(const wxGridCellAttr& attr, const wxGrid& grid, int row, int col)
81 {
82 wxGridCellAttr* highlightAttr;
83
84 if (isHeadLine(grid, row))
85 {
86 highlightAttr = attr.Clone();
87 highlightAttr->SetBackgroundColour(HighlightHeadlineColor);
88 highlightAttr->SetFont(highlightAttr->GetFont().Bold());
89 highlightAttr->SetAlignment(wxALIGN_LEFT, wxALIGN_CENTER);
90 }
91 else if (hasCustomColor())
92 {
93 highlightAttr = createCustomColorAttr(attr, grid, row, col);
94 //static double highlightLuminosity = calculateLuminosity(HighlightColor);
95 double bgLuminosity = calculateLuminosity(highlightAttr->GetBackgroundColour());
96// double factor = (bgLuminosity/highlightLuminosity-1.0)*0.8 + 1.0;
97 double factor = ((bgLuminosity / 255.0 * 0.8) + 0.2);
98
99 highlightAttr->SetBackgroundColour(wxColour(std::min(255.0, HighlightColor.Red() * factor),
100 std::min(255.0, HighlightColor.Green() * factor),
101 std::min(255.0, HighlightColor.Blue() * factor)));
102 }
103 else
104 {
105 highlightAttr = attr.Clone();
106 highlightAttr->SetBackgroundColour(HighlightColor);
107 }
108
109 return highlightAttr;
110 }
111
112 wxGridCellAttr* createFrameAttr(const wxGridCellAttr& attr)
113 {
114 wxGridCellAttr* frameAttr = attr.Clone();
115 frameAttr->SetBackgroundColour(FrameColor);
116 return frameAttr;
117 }
118
119 wxGridCellAttr* createHeadlineAttr(const wxGridCellAttr& attr)
120 {
121 wxGridCellAttr* headlineAttr = attr.Clone();
122 headlineAttr->SetBackgroundColour(HeadlineColor);
123 headlineAttr->SetFont(headlineAttr->GetFont().Bold());
124 headlineAttr->SetAlignment(wxALIGN_LEFT, wxALIGN_CENTER);
125 return headlineAttr;
126 }
127
128 wxGridCellAttr* createCustomColorAttr(const wxGridCellAttr& attr, const wxGrid& grid, int row, int col)
129 {
130 wxGridCellAttr* customAttr = attr.Clone();
131
132 if (grid.GetTable()->CanGetValueAs(row, col, "complex"))
133 customAttr->SetBackgroundColour(m_shader.getColour(*static_cast<mu::value_type*>(grid.GetTable()->GetValueAsCustom(row, col, "complex"))));
134 else if (grid.GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_NUMBER) || grid.GetTable()->CanGetValueAs(row, col, "datetime"))
135 customAttr->SetBackgroundColour(m_shader.getColour(mu::value_type(grid.GetTable()->GetValueAsDouble(row, col))));
136 else if (grid.GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL))
137 customAttr->SetBackgroundColour(m_shader.getColour(mu::value_type(grid.GetTable()->GetValueAsBool(row, col))));
138 else
139 customAttr->SetBackgroundColour(m_shader.getColour(grid.GetTable()->GetValue(row, col)));
140
141 // Calculate luminosity and correct text colour, if necessary
142 const wxColour& bgColour = customAttr->GetBackgroundColour();
143 double luminosity = calculateLuminosity(bgColour);
144
145 if (luminosity < 128)
146 {
147 luminosity = 255;//std::min(255.0, 255 - luminosity + 10);
148 customAttr->SetTextColour(wxColour(luminosity, luminosity, luminosity));
149 }
150
151 return customAttr;
152 }
153
154 public:
156
157 virtual void Draw(wxGrid& grid,
158 wxGridCellAttr& attr,
159 wxDC& dc,
160 const wxRect& rect,
161 int row, int col,
162 bool isSelected)
163 {
164 if (isPartOfCursor(grid, row, col))
165 {
166 wxGridCellAttr* newAttr = createHighlightedAttr(attr, grid, row, col);
167 wxGridCellStringRenderer::Draw(grid, *newAttr, dc, rect, row, col, isSelected);
168 newAttr->DecRef();
169 }
170 else if (isFrame(grid, row, col))
171 {
172 wxGridCellAttr* newAttr = createFrameAttr(attr);
173 wxGridCellStringRenderer::Draw(grid, *newAttr, dc, rect, row, col, isSelected);
174 newAttr->DecRef();
175 }
176 else if (isHeadLine(grid, row))
177 {
178 wxGridCellAttr* newAttr = createHeadlineAttr(attr);
179 wxGridCellStringRenderer::Draw(grid, *newAttr, dc, rect, row, col, isSelected);
180 newAttr->DecRef();
181 }
182 else if (hasCustomColor())
183 {
184 wxGridCellAttr* newAttr = createCustomColorAttr(attr, grid, row, col);
185 wxGridCellStringRenderer::Draw(grid, *newAttr, dc, rect, row, col, isSelected);
186 newAttr->DecRef();
187 }
188 else
189 wxGridCellStringRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);
190 }
191
192 virtual wxGridCellRenderer *Clone() const
193 { return new AdvStringCellRenderer(m_shader); }
194};
195
196
204{
205 public:
207
208 // draw a check mark or nothing
209 virtual void Draw(wxGrid& grid,
210 wxGridCellAttr& attr,
211 wxDC& dc,
212 const wxRect& rect,
213 int row, int col,
214 bool isSelected)
215 {
216 if (grid.GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL) && !isHeadLine(grid, row))
217 {
218 if (isPartOfCursor(grid, row, col))
219 {
220 wxGridCellAttr* newAttr = createHighlightedAttr(attr, grid, row, col);
221 wxGridCellRenderer::Draw(grid, *newAttr, dc, rect, row, col, isSelected);
222 newAttr->DecRef();
223 }
224 else if (isFrame(grid, row, col))
225 {
226 wxGridCellAttr* newAttr = createFrameAttr(attr);
227 wxGridCellRenderer::Draw(grid, *newAttr, dc, rect, row, col, isSelected);
228 newAttr->DecRef();
229 }
230 else if (hasCustomColor())
231 {
232 wxGridCellAttr* newAttr = createCustomColorAttr(attr, grid, row, col);
233 wxGridCellRenderer::Draw(grid, *newAttr, dc, rect, row, col, isSelected);
234 newAttr->DecRef();
235 }
236 else
237 wxGridCellRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);
238
239 // draw a check mark in the centre (ignoring alignment - TODO)
240 wxSize size = GetBestSize(grid, attr, dc, row, col);
241
242 // don't draw outside the cell
243 wxCoord minSize = wxMin(rect.width, rect.height);
244 if ( size.x >= minSize || size.y >= minSize )
245 {
246 // and even leave (at least) 1 pixel margin
247 size.x = size.y = minSize;
248 }
249
250 // draw a border around checkmark
251 int vAlign, hAlign;
252 attr.GetAlignment(&hAlign, &vAlign);
253
254 wxRect rectBorder;
255 if (hAlign == wxALIGN_CENTRE)
256 {
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;
261 }
262 else if (hAlign == wxALIGN_LEFT)
263 {
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;
268 }
269 else if (hAlign == wxALIGN_RIGHT)
270 {
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;
275 }
276
277 bool value = grid.GetTable()->GetValueAsBool(row, col);
278 int flags = 0;
279
280 if (value)
281 flags |= wxCONTROL_CHECKED;
282
283 wxRendererNative::Get().DrawCheckBox( &grid, dc, rectBorder, flags );
284 }
285 else
286 AdvStringCellRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);
287 }
288
289 // return the checkmark size
290 virtual wxSize GetBestSize(wxGrid& grid,
291 wxGridCellAttr& attr,
292 wxDC& dc,
293 int row, int col)
294 {
295 // Calculate only once bc, "---" is wider than the checkmark
296 if (!bestSize.x)
297 bestSize = DoGetBestSize(attr, dc, "---");
298
299 return bestSize;
300 }
301
302 virtual wxGridCellRenderer *Clone() const
303 { return new AdvBooleanCellRenderer(m_shader); }
304
305 private:
306 static wxSize bestSize;
307};
308
309
311
312
319class CombinedCellEditor : public wxGridCellEditor
320{
321 public:
329 CombinedCellEditor(wxGrid* grid) : m_grid(grid), m_finished(false) {}
330
340 virtual void Create(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler) override
341 {
342 int style = wxTE_PROCESS_ENTER | wxTE_PROCESS_TAB | wxBORDER_NONE;
343
344 // Create the text control
345 m_text = new wxTextCtrl(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, style);
346 m_text->SetMargins(0, 0);
347 m_text->Hide();
348
349 // The text control is the default control
350 m_control = m_text;
351
352 // Create the check box
353 m_checkBox = new wxCheckBox(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
354 m_checkBox->Hide();
355
356 // Create the combo box with an empty set of choices
357 m_comboBox = new wxComboBox(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxArrayString(), style);
358 m_comboBox->Hide();
359
360 // Bind the ENTER key event of the combo box to the event
361 // handler in this class
362 m_comboBox->Bind(wxEVT_TEXT_ENTER, CombinedCellEditor::OnEnterKey, this);
363
364 wxGridCellEditor::Create(parent, id, evtHandler);
365 }
366
374 virtual void SetSize(const wxRect& _rect) override
375 {
376 SetTextCtrlSize(_rect);
377 SetCheckBoxSize(_rect);
378 }
379
389 virtual void PaintBackground(wxDC& dc, const wxRect& rectCell, const wxGridCellAttr& attr) override
390 {
391 wxGridCellEditor::PaintBackground(dc, rectCell, attr);
392 }
393
403 virtual bool IsAcceptedKey(wxKeyEvent& event) override
404 {
405 switch (event.GetKeyCode())
406 {
407 case WXK_DELETE:
408 case WXK_BACK:
409 case WXK_SPACE:
410 case '+':
411 case '-':
412 return true;
413
414 default:
415 return wxGridCellEditor::IsAcceptedKey(event);
416 }
417 }
418
430 virtual void BeginEdit(int row, int col, wxGrid* grid) override
431 {
432 // Get the underlying table of the grid
433 GridNumeReTable* _tab = static_cast<GridNumeReTable*>(grid->GetTable());
434
435 // Get the value of the current cell as string
436 m_value = _tab->GetValue(row, col);
437 m_finished = false;
438
439 // Get the column types of the table
440 std::vector<int> vTypes = _tab->getColumnTypes();
441
442 // Determine, whether the current row is a headline row
443 bool isHead = grid->GetRowLabelValue(row) == "#";
444
445 // Select the correct edit control from the column types and
446 // depending on whether the current row is a headline row
447 if (!isHead
448 && (int)vTypes.size() > col
449 && vTypes[col] == TableColumn::TYPE_LOGICAL)
450 {
451 // Select the check box
452 m_control = m_checkBox;
453 m_checkBox->SetValue(m_value == "true");
454 }
455 else if (!isHead
456 && (int)vTypes.size() > col
457 && vTypes[col] == TableColumn::TYPE_CATEGORICAL)
458 {
459 // Select the combo box
460 m_control = m_comboBox;
461
462 // Get the categories and pass them into a
463 // wxArrayString instance
464 const std::vector<std::string>& vCategories = _tab->getCategories(col);
465 wxArrayString cats;
466
467 for (const auto& c : vCategories)
468 cats.Add(c);
469
470 // Set the categories as choices for the current
471 // cell
472 m_comboBox->Set(cats);
473 wxGridCellEditorEvtHandler* evtHandler = nullptr;
474
475 if (m_comboBox)
476 evtHandler = wxDynamicCast(m_comboBox->GetEventHandler(), wxGridCellEditorEvtHandler);
477
478 // Don't immediately end if we get a kill focus event within BeginEdit
479 if (evtHandler)
480 evtHandler->SetInSetFocus(true);
481
482 Reset(); // this updates combo box to correspond to m_value
483
484 if (evtHandler)
485 {
486 // When dropping down the menu, a kill focus event
487 // happens after this point, so we can't reset the flag yet.
488 evtHandler->SetInSetFocus(false);
489 }
490 }
491 else // All other cases and the headline
492 {
493 // Select the text control, which is the default control
494 m_control = m_text;
495 m_text->SetValue(m_value);
496 m_text->SetInsertionPointEnd();
497 m_text->SelectAll();
498 }
499
500 // Show the selected control and give it the keyboard
501 // focus to allow direct interaction
502 m_control->Show();
503 m_control->SetFocus();
504 }
505
519 virtual bool EndEdit(int row, int col, const wxGrid* grid, const wxString& oldval, wxString *newval) override
520 {
521 // Do not call this function twice
522 if (m_finished)
523 return false;
524
525 m_finished = true;
526
527 // Get the value from the control
528 if (m_control == m_text)
529 {
530 const wxString value = m_text->GetValue();
531
532 if (value == m_value)
533 return false;
534
535 m_value = value;
536 }
537 else if (m_control == m_checkBox)
538 {
539 // Reset the control
540 m_control = m_text;
541 bool value = m_checkBox->GetValue();
542
543 if (toString(value) == m_value)
544 return false;
545
546 m_value = toString(value);
547 }
548 else if (m_control == m_comboBox)
549 {
550 // Reset the control
551 m_control = m_text;
552 const wxString value = m_comboBox->GetValue();
553
554 if (value == m_value)
555 return false;
556
557 m_value = value;
558 }
559 else
560 return false;
561
562 // Return the new value, if the used supplied a
563 // pointer
564 if (newval)
565 *newval = m_value;
566
567 return true;
568 }
569
581 virtual void ApplyEdit(int row, int col, wxGrid* grid) override
582 {
583 grid->GetTable()->SetValue(row, col, m_value);
584 m_value.clear();
585 }
586
593 virtual void Reset() override
594 {
595 if (m_control == m_text)
596 {
597 m_text->SetValue(m_value);
598 m_text->SetInsertionPointEnd();
599 }
600 else if (m_control == m_checkBox)
601 m_checkBox->SetValue(m_value == "true");
602 else if (m_control == m_comboBox)
603 {
604 m_comboBox->SetValue(m_value);
605 m_comboBox->SetInsertionPointEnd();
606 }
607 }
608
617 virtual void StartingClick() override
618 {
619 if (m_control == m_checkBox)
620 {
621 m_checkBox->SetValue(!m_checkBox->GetValue());
622 finalize(false);
623 }
624 }
625
635 virtual void StartingKey(wxKeyEvent& event) override
636 {
637 // Since this is now happening in the EVT_CHAR event EmulateKeyPress is no
638 // longer an appropriate way to get the character into the text control.
639 // Do it ourselves instead. We know that if we get this far that we have
640 // a valid character, so not a whole lot of testing needs to be done.
641 if (m_control == m_text || m_control == m_comboBox)
642 {
643 // Handle text ctrl and combo box commonly
644 wxTextEntry* textField = dynamic_cast<wxTextEntry*>(m_control);
645
646 // Ensure that the cast was successful
647 if (!textField)
648 return;
649
650 int ch;
651 bool isPrintable = false;
652
653 ch = event.GetUnicodeKey();
654
655 if (ch != WXK_NONE)
656 isPrintable = true;
657 else
658 {
659 ch = event.GetKeyCode();
660 isPrintable = ch >= WXK_SPACE && ch < WXK_START;
661 }
662
663 // Evaluate the pressed key
664 switch (ch)
665 {
666 case WXK_DELETE:
667 // Delete the initial character when starting to edit with DELETE.
668 textField->Remove(0, 1);
669 break;
670
671 case WXK_BACK:
672 // Delete the last character when starting to edit with BACKSPACE.
673 {
674 const long pos = textField->GetLastPosition();
675 textField->Remove(pos - 1, pos);
676 }
677 break;
678
679 case WXK_ESCAPE:
680 Reset();
681 break;
682
683 default:
684 if (isPrintable)
685 textField->WriteText(static_cast<wxChar>(ch));
686 break;
687 }
688 }
689 else if (m_control == m_checkBox)
690 {
691 int keycode = event.GetKeyCode();
692
693 // Evaluate the pressed key
694 switch (keycode)
695 {
696 case WXK_SPACE:
697 // Toggle
698 m_checkBox->SetValue(!m_checkBox->GetValue());
699 break;
700
701 case '+':
702 // Set true
703 m_checkBox->SetValue(true);
704 break;
705
706 case '-':
707 // Set false
708 m_checkBox->SetValue(false);
709 break;
710
711 case WXK_ESCAPE:
712 Reset();
713 break;
714
715 default:
716 // The user wants to change the column type. We'll
717 // hide the checkbox, enable the text control and
718 // re-call this function
719 m_checkBox->Hide();
720 m_control = m_text;
721 m_text->Show();
722 m_text->SetValue(m_value);
723 m_text->SetInsertionPointEnd();
724 m_text->SelectAll();
725 m_text->SetFocus();
726 StartingKey(event);
727 }
728 }
729 }
730
739 virtual void HandleReturn(wxKeyEvent& event) override
740 {
741 event.Skip();
742 }
743
750 virtual wxGridCellEditor *Clone() const override
751 {
752 return new CombinedCellEditor(m_grid);
753 }
754
761 virtual wxString GetValue() const override
762 {
763 return m_value;
764 }
765
776 virtual void Show(bool show, wxGridCellAttr *attr = nullptr) override
777 {
778 if (!show)
779 {
780 // Only hide here
781 m_text->Hide();
782 m_checkBox->Hide();
783 m_comboBox->Hide();
784 }
785
786 if (show)
787 {
788 wxColour colBg = attr ? attr->GetBackgroundColour() : *wxLIGHT_GREY;
789 m_checkBox->SetBackgroundColour(colBg);
790 }
791 }
792
793 protected:
794 wxTextCtrl* m_text;
795 wxCheckBox* m_checkBox;
796 wxComboBox* m_comboBox;
797 wxGrid* m_grid;
798 wxString m_value;
800
809 void SetTextCtrlSize(const wxRect& _rect)
810 {
811 wxRect rect(_rect);
812 wxRect textRect(_rect);
813 const wxSize bestSize = m_comboBox->GetBestSize();
814 const wxCoord diffY = bestSize.GetHeight() - rect.GetHeight();
815
816 if (diffY > 0)
817 {
818 // Do make it tall enough.
819 rect.height += diffY;
820
821 // Also centre the effective rectangle vertically with respect to the
822 // original one.
823 rect.y -= diffY/2;
824 }
825
826 // Make the edit control large enough to allow for internal margins
827 //
828 if (textRect.x == 0)
829 textRect.x += 2;
830 else
831 textRect.x += 3;
832
833 if (textRect.y == 0)
834 textRect.y += 2;
835 else
836 textRect.y += 3;
837
838 textRect.width -= 2;
839 textRect.height -= 2;
840 rect.width += 2;
841
842 m_text->SetSize(textRect, wxSIZE_ALLOW_MINUS_ONE);
843 m_comboBox->SetSize(rect, wxSIZE_ALLOW_MINUS_ONE);
844 }
845
854 void SetCheckBoxSize(const wxRect& _rect)
855 {
856 bool resize = false;
857 wxSize checkBoxSize = m_checkBox->GetSize();
858 wxCoord minSize = wxMin(_rect.width, _rect.height);
859
860 // check if the checkbox is not too big/small for this cell
861 wxSize sizeBest = m_checkBox->GetBestSize();
862
863 if (!(checkBoxSize == sizeBest))
864 {
865 // reset to default size if it had been made smaller
866 checkBoxSize = sizeBest;
867 resize = true;
868 }
869
870 if (checkBoxSize.x >= minSize || checkBoxSize.y >= minSize)
871 {
872 // leave 1 pixel margin
873 checkBoxSize.x = checkBoxSize.y = minSize - 2;
874 resize = true;
875 }
876
877 if (resize)
878 m_checkBox->SetSize(checkBoxSize);
879
880 // position it in the centre of the rectangle (TODO: support alignment?)
881 // here too, but in other way
882 checkBoxSize.x -= 2;
883 checkBoxSize.y -= 2;
884
885 int hAlign = wxALIGN_CENTRE;
886 int vAlign = wxALIGN_CENTRE;
887
888 if (GetCellAttr())
889 GetCellAttr()->GetAlignment(&hAlign, &vAlign);
890
891 int x = 0, y = 0;
892
893 if (hAlign == wxALIGN_LEFT)
894 {
895 x = _rect.x + 2;
896 x += 2;
897 y = _rect.y + _rect.height / 2 - checkBoxSize.y / 2;
898 }
899 else if (hAlign == wxALIGN_RIGHT)
900 {
901 x = _rect.x + _rect.width - checkBoxSize.x - 2;
902 y = _rect.y + _rect.height / 2 - checkBoxSize.y / 2;
903 }
904 else if (hAlign == wxALIGN_CENTRE)
905 {
906 x = 1 + _rect.x + _rect.width / 2 - checkBoxSize.x / 2;
907 y = _rect.y + _rect.height / 2 - checkBoxSize.y / 2;
908 }
909
910 m_checkBox->Move(x, y);
911 }
912
921 void OnEnterKey(wxCommandEvent& event)
922 {
923 finalize(true);
924 }
925
934 void finalize(bool moveCursor)
935 {
936 m_grid->SaveEditControlValue();
937 m_grid->HideCellEditControl();
938
939 if (moveCursor)
940 m_grid->MoveCursorDown(false);
941
942 m_grid->GetGridWindow()->SetFocus();
943 }
944};
945
946
947
948#endif // CELLATTRIBUTES_HPP
949
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
CellValueShader m_shader
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.
wxComboBox * m_comboBox
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.
wxCheckBox * m_checkBox
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...
Definition: gridtable.hpp:34
std::vector< std::string > getCategories(int col) const
Returns the categories in the selected column, if this is a categorical column.
Definition: gridtable.cpp:659
std::vector< int > getColumnTypes() const
Returns the types of the handled table.
Definition: gridtable.cpp:640
virtual wxString GetValue(int row, int col)
This virtual member function returns the value of the selected cell as string.
Definition: gridtable.cpp:246
MUP_BASETYPE value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:251
#define min(a, b)
Definition: resampler.cpp:34
std::string toString(int)
Converts an integer to a string without the Settings bloat.