23#include <wx/clipbrd.h>
26#include <wx/settings.h>
27#include <wx/toplevel.h>
31#if wxUSE_ACCESSIBILITY
45 void SetCurrentCell(
int row,
int col);
47 bool GetRowCol(
int childId,
int & row,
int & col);
51 wxAccStatus GetChild(
int childId, wxAccessible **child)
override;
54 wxAccStatus GetChildCount(
int *childCount)
override;
62 wxAccStatus GetDefaultAction(
int childId, wxString *actionName)
override;
65 wxAccStatus GetDescription(
int childId, wxString *description)
override;
71 wxAccStatus GetFocus(
int *childId, wxAccessible **child)
override;
74 wxAccStatus GetHelpText(
int childId, wxString *helpText)
override;
78 wxAccStatus GetKeyboardShortcut(
int childId, wxString *shortcut)
override;
82 wxAccStatus GetLocation(wxRect & rect,
int elementId)
override;
85 wxAccStatus GetName(
int childId, wxString *
name)
override;
88 wxAccStatus GetParent(wxAccessible **parent)
override;
91 wxAccStatus GetRole(
int childId, wxAccRole *role)
override;
101 wxAccStatus GetSelections(wxVariant *selections)
override;
104 wxAccStatus GetState(
int childId,
long* state)
override;
108 wxAccStatus GetValue(
int childId, wxString* strValue)
override;
110#if defined(__WXMAC__)
112 wxAccStatus Select(
int childId, wxAccSelectionFlags selectFlags)
override;
150 wxGridCellEditor::Create(parent,
id,
handler);
155 wxSize
size = m_control->GetSize();
158 int x = rect.x + ((rect.width / 2) - (
size.x / 2)) + 1;
159 int y = rect.y + ((rect.height / 2) - (
size.y / 2)) + 1;
161 m_control->Move(x, y);
166 wxGridTableBase *table = grid->GetTable();
172 control->SetValue(
mOld);
173 control->EnableMenu();
179bool NumericEditor::EndEdit(
int WXUNUSED(row),
int WXUNUSED(col),
const wxGrid *WXUNUSED(grid),
const wxString &WXUNUSED(oldval), wxString *newval)
182 bool changed = newtime !=
mOld;
204 if (wxGridCellEditor::IsAcceptedKey(event)) {
205 if (event.GetKeyCode() == WXK_RETURN) {
249 wxGridCellAttr &attr,
256 wxGridCellRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);
258 wxGridTableBase *table = grid.GetTable();
266 table->
GetValue(row, col).ToDouble(&value);
274 wxPoint(10000, 10000));
280 dc.SetBackgroundMode(wxTRANSPARENT);
282 if (grid.IsEnabled())
286 dc.SetTextBackground(grid.GetSelectionBackground());
287 dc.SetTextForeground(grid.GetSelectionForeground());
291 dc.SetTextBackground(attr.GetBackgroundColour());
292 dc.SetTextForeground(attr.GetTextColour());
297 dc.SetTextBackground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
298 dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
301 dc.SetFont(attr.GetFont());
305 attr.GetAlignment(&hAlign, &vAlign);
307 grid.DrawTextRectangle(dc, tstr, rect, hAlign, vAlign);
311 wxGridCellAttr & WXUNUSED(attr),
316 wxGridTableBase *table = grid.GetTable();
323 table->
GetValue(row, col).ToDouble(&value);
330 wxPoint(10000, 10000));
349 for (
size_t n = 0; n < count; n++) {
374 m_control =
safenew wxChoice(parent,
380 wxGridCellEditor::Create(parent,
id, evtHandler);
386 wxSize
size = m_control->GetSize();
389 int x = rect.x + ((rect.width / 2) - (
size.x / 2)) + 1;
390 int y = rect.y + ((rect.height / 2) - (
size.y / 2)) + 1;
392 m_control->Move(x, y);
400 mOld = grid->GetTable()->GetValue(row, col);
411 bool changed =
EndEdit(row, col, grid,
mOld, &newvalue);
419 const wxGrid* WXUNUSED(grid),
420 const wxString &WXUNUSED(oldval), wxString *newval)
422 int sel =
Choice()->GetSelection();
425 if ((sel < 0) || (sel >= (
int)(
mChoices.size())))
431 bool changed = val !=
mOld;
466BEGIN_EVENT_TABLE(
Grid, wxGrid)
478 const wxString&
name)
479: wxGrid(parent,
id, pos,
size, style | wxWANTS_CHARS,
name)
481#if wxUSE_ACCESSIBILITY
482 GetGridWindow()->SetAccessible(mAx =
safenew GridAx(
this));
500 safenew wxGridCellStringRenderer,
505 SetSelectionForeground(GetDefaultCellTextColour());
506 SetSelectionBackground(GetDefaultCellBackgroundColour());
511#if wxUSE_ACCESSIBILITY
512 int cnt = mChildren.size();
516 mChildren.pop_back();
525#if wxUSE_ACCESSIBILITY
526 mAx->SetCurrentCell(GetGridCursorRow(), GetGridCursorCol());
534 MakeCellVisible(event.GetRow(), event.GetCol());
536#if wxUSE_ACCESSIBILITY
537 mAx->SetCurrentCell(event.GetRow(), event.GetCol());
547 SelectRow(GetGridCursorRow());
552 auto keyCode =
event.GetKeyCode();
553 int crow = GetGridCursorRow();
554 int ccol = GetGridCursorCol();
556 if (event.CmdDown() && crow != wxGridNoCellCoords.GetRow() && ccol != wxGridNoCellCoords.GetCol())
558 wxClipboardLocker cb;
564 wxTextDataObject *data =
safenew wxTextDataObject(GetCellValue(crow, ccol));
572 wxTextDataObject *data =
safenew wxTextDataObject(GetCellValue(crow, ccol));
574 SetCellValue(crow, ccol,
"" );
583 wxTextDataObject data;
586 SetCellValue(crow, ccol, data.GetText());
600 int rows = GetNumberRows();
601 int cols = GetNumberCols();
603 const bool has_cells = rows > 0 && cols > 0;
606 int crow = GetGridCursorRow();
607 int ccol = GetGridCursorCol();
609 const bool has_no_selection = crow == wxGridNoCellCoords.GetRow() || ccol == wxGridNoCellCoords.GetCol();
611 if (has_no_selection) {
614 else if (event.GetKeyCode() == WXK_LEFT) {
615 if (crow == 0 && ccol == 0) {
618 else if (ccol == 0) {
619 SetGridCursor(crow - 1, cols - 1);
622 SetGridCursor(crow, ccol - 1);
626 if (crow == rows - 1 && ccol == cols - 1) {
629 else if (ccol == cols - 1) {
630 SetGridCursor(crow + 1, 0);
633 SetGridCursor(crow, ccol + 1);
638#if wxUSE_ACCESSIBILITY
640 mAx->SetCurrentCell(GetGridCursorRow(), GetGridCursorCol());
647 if (event.ControlDown()) {
648 int flags = wxNavigationKeyEvent::FromTab |
649 (
event.ShiftDown() ?
650 wxNavigationKeyEvent::IsBackward :
651 wxNavigationKeyEvent::IsForward );
656 int rows = GetNumberRows();
657 int cols = GetNumberCols();
658 int crow = GetGridCursorRow();
659 int ccol = GetGridCursorCol();
661 const auto is_empty = rows <= 0 || cols <= 0;
662 const auto has_no_selection = crow == wxGridNoCellCoords.GetRow() || ccol == wxGridNoCellCoords.GetCol();
664 if (event.ShiftDown()) {
666 Navigate(wxNavigationKeyEvent::FromTab | wxNavigationKeyEvent::IsBackward);
670 if (crow == 0 && ccol == 0) {
671 Navigate(wxNavigationKeyEvent::FromTab | wxNavigationKeyEvent::IsBackward);
675 if (has_no_selection) {
676 SetGridCursor(rows -1, cols - 1);
678 else if (ccol == 0) {
679 SetGridCursor(crow - 1, cols - 1);
682 SetGridCursor(crow, ccol - 1);
687 Navigate(wxNavigationKeyEvent::FromTab | wxNavigationKeyEvent::IsForward);
691 if (crow == rows - 1 && ccol == cols - 1) {
692 Navigate(wxNavigationKeyEvent::FromTab | wxNavigationKeyEvent::IsForward);
696 if (has_no_selection) {
699 else if (ccol == cols - 1) {
700 SetGridCursor(crow + 1, 0);
703 SetGridCursor(crow, ccol + 1);
707 MakeCellVisible(GetGridCursorRow(), GetGridCursorCol());
709#if wxUSE_ACCESSIBILITY
711 mAx->SetCurrentCell(GetGridCursorRow(), GetGridCursorCol());
717 case WXK_NUMPAD_ENTER:
719 if (!IsCellEditControlShown()) {
720 wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(
this), wxTopLevelWindow);
721 wxWindow *def = tlw->GetDefaultItem();
722 if (def && def->IsEnabled()) {
725 cevent.SetEventObject( def );
726 GetParent()->GetEventHandler()->ProcessEvent(cevent);
730 wxGrid::OnKeyDown(event);
735 SetGridCursor(GetGridCursorRow(), GetGridCursorCol());
741 wxGrid::OnKeyDown(event);
746#if wxUSE_ACCESSIBILITY
747void Grid::ClearGrid()
756bool Grid::InsertRows(
int pos,
int numRows,
bool updateLabels)
758 bool res = wxGrid::InsertRows(pos, numRows, updateLabels);
765bool Grid::AppendRows(
int numRows,
bool updateLabels)
767 bool res = wxGrid::AppendRows(numRows, updateLabels);
774bool Grid::DeleteRows(
int pos,
int numRows,
bool updateLabels)
776 bool res = wxGrid::DeleteRows(pos, numRows, updateLabels);
783bool Grid::InsertCols(
int pos,
int numCols,
bool updateLabels)
785 bool res = wxGrid::InsertCols(pos, numCols, updateLabels);
792bool Grid::AppendCols(
int numCols,
bool updateLabels)
794 bool res = wxGrid::AppendCols(numCols, updateLabels);
801bool Grid::DeleteCols(
int pos,
int numCols,
bool updateLabels)
803 bool res = wxGrid::DeleteCols(pos, numCols, updateLabels);
810GridAx::GridAx(
Grid *grid)
817void GridAx::TableUpdated()
819 NotifyEvent(wxACC_EVENT_OBJECT_REORDER,
820 mGrid->GetGridWindow(),
825void GridAx::SetCurrentCell(
int row,
int col)
827 int id = (((row * mGrid->GetNumberCols()) + col) + 1);
830 NotifyEvent(wxACC_EVENT_OBJECT_SELECTIONREMOVE,
831 mGrid->GetGridWindow(),
837 NotifyEvent(wxACC_EVENT_OBJECT_FOCUS,
838 mGrid->GetGridWindow(),
843 NotifyEvent(wxACC_EVENT_OBJECT_SELECTION,
844 mGrid->GetGridWindow(),
851bool GridAx::GetRowCol(
int childId,
int & row,
int & col)
853 if (childId == wxACC_SELF) {
857 int cols = mGrid->GetNumberCols();
858 int id = childId - 1;
868wxAccStatus GridAx::GetChild(
int childId, wxAccessible** child)
870 if (childId == wxACC_SELF) {
881wxAccStatus GridAx::GetChildCount(
int *childCount)
883 *childCount = mGrid->GetNumberRows() * mGrid->GetNumberCols();
894wxAccStatus GridAx::GetDefaultAction(
int WXUNUSED(childId), wxString *actionName)
902wxAccStatus GridAx::GetDescription(
int WXUNUSED(childId), wxString *description)
904 description->clear();
910wxAccStatus GridAx::GetHelpText(
int WXUNUSED(childId), wxString *helpText)
919wxAccStatus GridAx::GetKeyboardShortcut(
int WXUNUSED(childId), wxString *shortcut)
928wxAccStatus GridAx::GetLocation(wxRect & rect,
int elementId)
934 if (GetRowCol(elementId, row, col)) {
935 rect = mGrid->CellToRect(row, col);
936 rect.SetPosition(mGrid->CalcScrolledPosition(rect.GetPosition()));
937 rect.SetPosition(mGrid->GetGridWindow()->ClientToScreen(rect.GetPosition()));
940 rect = mGrid->GetRect();
941 rect.SetPosition(mGrid->GetParent()->ClientToScreen(rect.GetPosition()));
948wxAccStatus GridAx::GetName(
int childId, wxString *
name)
953 if (GetRowCol(childId, row, col)) {
954 wxString n = mGrid->GetColLabelValue(col);
955 wxString v = mGrid->GetCellValue(row, col);
966 static_cast<NumericEditor *
>(mGrid->GetCellEditor(row, col));
968 if (c && dt && df && ( c == dt || c == df)) {
976 v = converter.GetString();
992wxAccStatus GridAx::GetParent(wxAccessible ** WXUNUSED(parent))
994 return wxACC_NOT_IMPLEMENTED;
998wxAccStatus GridAx::GetRole(
int childId, wxAccRole *role)
1000 if (childId == wxACC_SELF) {
1001#if defined(__WXMSW__)
1002 *role = wxROLE_SYSTEM_TABLE;
1005#if defined(__WXMAC__)
1006 *role = wxROLE_SYSTEM_GROUPING;
1010 *role = wxROLE_SYSTEM_TEXT;
1024wxAccStatus GridAx::GetSelections(wxVariant * WXUNUSED(selections))
1026 return wxACC_NOT_IMPLEMENTED;
1030wxAccStatus GridAx::GetState(
int childId,
long *state)
1032 int flag = wxACC_STATE_SYSTEM_FOCUSABLE |
1033 wxACC_STATE_SYSTEM_SELECTABLE;
1037 if (!GetRowCol(childId, row, col)) {
1042#if defined(__WXMSW__)
1043 flag |= wxACC_STATE_SYSTEM_FOCUSED |
1044 wxACC_STATE_SYSTEM_SELECTED;
1046 if (mGrid->IsReadOnly(row, col)) {
1050 flag = wxACC_STATE_SYSTEM_UNAVAILABLE | wxACC_STATE_SYSTEM_FOCUSED;
1054#if defined(__WXMAC__)
1055 if (mGrid->IsInSelection(row, col)) {
1056 flag |= wxACC_STATE_SYSTEM_SELECTED;
1059 if (mGrid->GetGridCursorRow() == row && mGrid->GetGridCursorCol() == col) {
1060 flag |= wxACC_STATE_SYSTEM_FOCUSED;
1063 if (mGrid->IsReadOnly(row, col)) {
1064 flag |= wxACC_STATE_SYSTEM_UNAVAILABLE;
1075#if defined(__WXMAC__)
1076wxAccStatus GridAx::GetValue(
int childId, wxString *strValue)
1078wxAccStatus GridAx::GetValue(
int WXUNUSED(childId), wxString *strValue)
1083#if defined(__WXMSW__)
1087#if defined(__WXMAC__)
1088 return GetName(childId, strValue);
1092#if defined(__WXMAC__)
1094wxAccStatus GridAx::Select(
int childId, wxAccSelectionFlags selectFlags)
1099 if (GetRowCol(childId, row, col)) {
1101 if (selectFlags & wxACC_SEL_TAKESELECTION) {
1102 mGrid->SetGridCursor(row, col);
1105 mGrid->SelectBlock(row, col, row, col, selectFlags & wxACC_SEL_ADDSELECTION);
1116wxAccStatus GridAx::GetFocus(
int * childId, wxAccessible **child)
1119 if (mGrid->GetNumberRows() * mGrid->GetNumberCols() == 0) {
1123 *childId = mGrid->GetGridCursorRow()*mGrid->GetNumberCols() +
1124 mGrid->GetGridCursorCol() + 1;
wxEVT_COMMAND_BUTTON_CLICKED
const TranslatableString name
#define GRID_VALUE_FREQUENCY
#define GRID_VALUE_CHOICE
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
void ConnectEvent(wxWindow *w)
void DisconnectEvent(wxWindow *w)
Modified version of wxGridChoiceEditor using wxChoice instead of wxComboBox.
wxChoice * Choice() const
void SetSize(const wxRect &rect) override
void Create(wxWindow *parent, wxWindowID id, wxEvtHandler *evtHandler) override
bool EndEdit(int row, int col, wxGrid *grid)
void ApplyEdit(int row, int col, wxGrid *grid) override
wxGridCellEditor * Clone() const override
wxString GetValue() const override
ChoiceEditor::FocusHandler mHandler
ChoiceEditor(size_t count=0, const wxString choices[]=NULL)
void BeginEdit(int row, int col, wxGrid *grid) override
void SetChoices(const wxArrayString &choices)
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Supplies an accessible grid based on wxGrid.
void OnKeyDown(wxKeyEvent &event)
void OnSelectCell(wxGridEvent &event)
void OnSetFocus(wxFocusEvent &event)
void OnEditorShown(wxGridEvent &event)
NumericConverter provides the advanced formatting control used in the selection bar of Audacity.
static NumericFormatSymbol HertzFormat()
static NumericFormatSymbol SecondsFormat()
wxGridCellEditor for the NumericTextCtrl.
NumericTextCtrl * GetNumericTextControl() const
wxString GetValue() const override
void ApplyEdit(int row, int col, wxGrid *grid) override
void SetRate(double rate)
void Create(wxWindow *parent, wxWindowID id, wxEvtHandler *handler) override
NumericFormatSymbol mFormat
bool IsAcceptedKey(wxKeyEvent &event) override
void SetSize(const wxRect &rect) override
NumericConverter::Type mType
NumericEditor(NumericConverter::Type type, const NumericFormatSymbol &format, double rate)
NumericFormatSymbol GetFormat() const
void BeginEdit(int row, int col, wxGrid *grid) override
void SetFormat(const NumericFormatSymbol &format)
bool EndEdit(int row, int col, const wxGrid *grid, const wxString &oldval, wxString *newval) override
wxGridCellEditor * Clone() const override
wxGridCellRenderer for the NumericTextCtrl.
NumericConverter::Type mType
wxGridCellRenderer * Clone() const override
~NumericRenderer() override
void Draw(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &rect, int row, int col, bool isSelected) override
wxSize GetBestSize(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col) override
void SetValue(double newValue)
static const int UndefinedFrequency
An alternative to using wxWindowAccessible, which in wxWidgets 3.1.1 contained GetParent() which was ...
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
std::unique_ptr< WindowPlacement > FindFocus()
Find the window that is accepting keyboard input, if any.
AuthorizationHandler handler
Options & AutoPos(bool enable)