21#include <wx/clipbrd.h>
24#include <wx/settings.h>
25#include <wx/toplevel.h>
32#if wxUSE_ACCESSIBILITY
46 void SetCurrentCell(
int row,
int col);
48 bool GetRowCol(
int childId,
int & row,
int & col);
52 wxAccStatus GetChild(
int childId, wxAccessible **child)
override;
55 wxAccStatus GetChildCount(
int *childCount)
override;
63 wxAccStatus GetDefaultAction(
int childId, wxString *actionName)
override;
66 wxAccStatus GetDescription(
int childId, wxString *description)
override;
72 wxAccStatus GetFocus(
int *childId, wxAccessible **child)
override;
75 wxAccStatus GetHelpText(
int childId, wxString *helpText)
override;
79 wxAccStatus GetKeyboardShortcut(
int childId, wxString *shortcut)
override;
83 wxAccStatus GetLocation(wxRect & rect,
int elementId)
override;
86 wxAccStatus GetName(
int childId, wxString *
name)
override;
89 wxAccStatus GetParent(wxAccessible **parent)
override;
92 wxAccStatus GetRole(
int childId, wxAccRole *role)
override;
102 wxAccStatus GetSelections(wxVariant *selections)
override;
105 wxAccStatus GetState(
int childId,
long* state)
override;
109 wxAccStatus GetValue(
int childId, wxString* strValue)
override;
111#if defined(__WXMAC__)
113 wxAccStatus Select(
int childId, wxAccSelectionFlags selectFlags)
override;
126 : mContext { context }
128 mType = std::move(type);
152 wxGridCellEditor::Create(parent,
id,
handler);
157 wxSize
size = m_control->GetSize();
160 int x = rect.x + ((rect.width / 2) - (
size.x / 2)) + 1;
161 int y = rect.y + ((rect.height / 2) - (
size.y / 2)) + 1;
163 m_control->Move(x, y);
168 wxGridTableBase *table = grid->GetTable();
174 control->SetValue(
mOld);
175 control->EnableMenu();
181bool NumericEditor::EndEdit(
int WXUNUSED(row),
int WXUNUSED(col),
const wxGrid *WXUNUSED(grid),
const wxString &WXUNUSED(oldval), wxString *newval)
184 bool changed = newtime !=
mOld;
206 if (wxGridCellEditor::IsAcceptedKey(event)) {
207 if (event.GetKeyCode() == WXK_RETURN) {
241 wxGridCellAttr &attr,
248 wxGridCellRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);
250 wxGridTableBase *table = grid.GetTable();
258 table->
GetValue(row, col).ToDouble(&value);
265 wxPoint(10000, 10000));
271 dc.SetBackgroundMode(wxTRANSPARENT);
273 if (grid.IsEnabled())
277 dc.SetTextBackground(grid.GetSelectionBackground());
278 dc.SetTextForeground(grid.GetSelectionForeground());
282 dc.SetTextBackground(attr.GetBackgroundColour());
283 dc.SetTextForeground(attr.GetTextColour());
288 dc.SetTextBackground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
289 dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
292 dc.SetFont(attr.GetFont());
296 attr.GetAlignment(&hAlign, &vAlign);
298 grid.DrawTextRectangle(dc, tstr, rect, hAlign, vAlign);
302 wxGridCellAttr & WXUNUSED(attr),
307 wxGridTableBase *table = grid.GetTable();
314 table->
GetValue(row, col).ToDouble(&value);
320 wxPoint(10000, 10000));
339 for (
size_t n = 0; n < count; n++) {
364 m_control =
safenew wxChoice(parent,
370 wxGridCellEditor::Create(parent,
id, evtHandler);
376 wxSize
size = m_control->GetSize();
379 int x = rect.x + ((rect.width / 2) - (
size.x / 2)) + 1;
380 int y = rect.y + ((rect.height / 2) - (
size.y / 2)) + 1;
382 m_control->Move(x, y);
390 mOld = grid->GetTable()->GetValue(row, col);
401 bool changed =
EndEdit(row, col, grid,
mOld, &newvalue);
409 const wxGrid* WXUNUSED(grid),
410 const wxString &WXUNUSED(oldval), wxString *newval)
412 int sel =
Choice()->GetSelection();
415 if ((sel < 0) || (sel >= (
int)(
mChoices.size())))
421 bool changed = val !=
mOld;
456BEGIN_EVENT_TABLE(
Grid, wxGrid)
470 const wxString&
name)
471: wxGrid(parent,
id, pos,
size,
style | wxWANTS_CHARS,
name), mContext(context)
473#if wxUSE_ACCESSIBILITY
474 GetGridWindow()->SetAccessible(mAx =
safenew GridAx(mContext,
this));
492 safenew wxGridCellStringRenderer,
497 SetSelectionForeground(GetDefaultCellTextColour());
498 SetSelectionBackground(GetDefaultCellBackgroundColour());
503#if wxUSE_ACCESSIBILITY
504 int cnt = mChildren.size();
508 mChildren.pop_back();
517#if wxUSE_ACCESSIBILITY
518 mAx->SetCurrentCell(GetGridCursorRow(), GetGridCursorCol());
526 MakeCellVisible(event.GetRow(), event.GetCol());
528#if wxUSE_ACCESSIBILITY
529 mAx->SetCurrentCell(event.GetRow(), event.GetCol());
539 SelectRow(GetGridCursorRow());
544 auto keyCode =
event.GetKeyCode();
545 int crow = GetGridCursorRow();
546 int ccol = GetGridCursorCol();
548 if (event.CmdDown() && crow != wxGridNoCellCoords.GetRow() && ccol != wxGridNoCellCoords.GetCol())
550 wxClipboardLocker cb;
556 wxTextDataObject *data =
safenew wxTextDataObject(GetCellValue(crow, ccol));
564 wxTextDataObject *data =
safenew wxTextDataObject(GetCellValue(crow, ccol));
566 SetCellValue(crow, ccol,
"" );
575 wxTextDataObject data;
578 SetCellValue(crow, ccol, data.GetText());
592 int rows = GetNumberRows();
593 int cols = GetNumberCols();
595 const bool has_cells = rows > 0 && cols > 0;
598 int crow = GetGridCursorRow();
599 int ccol = GetGridCursorCol();
601 const bool has_no_selection = crow == wxGridNoCellCoords.GetRow() || ccol == wxGridNoCellCoords.GetCol();
603 if (has_no_selection) {
606 else if (event.GetKeyCode() == WXK_LEFT) {
607 if (crow == 0 && ccol == 0) {
610 else if (ccol == 0) {
611 SetGridCursor(crow - 1, cols - 1);
614 SetGridCursor(crow, ccol - 1);
618 if (crow == rows - 1 && ccol == cols - 1) {
621 else if (ccol == cols - 1) {
622 SetGridCursor(crow + 1, 0);
625 SetGridCursor(crow, ccol + 1);
630#if wxUSE_ACCESSIBILITY
632 mAx->SetCurrentCell(GetGridCursorRow(), GetGridCursorCol());
639 if (event.ControlDown()) {
640 int flags = wxNavigationKeyEvent::FromTab |
641 (
event.ShiftDown() ?
642 wxNavigationKeyEvent::IsBackward :
643 wxNavigationKeyEvent::IsForward );
648 int rows = GetNumberRows();
649 int cols = GetNumberCols();
650 int crow = GetGridCursorRow();
651 int ccol = GetGridCursorCol();
653 const auto is_empty = rows <= 0 || cols <= 0;
654 const auto has_no_selection = crow == wxGridNoCellCoords.GetRow() || ccol == wxGridNoCellCoords.GetCol();
656 if (event.ShiftDown()) {
658 Navigate(wxNavigationKeyEvent::FromTab | wxNavigationKeyEvent::IsBackward);
662 if (crow == 0 && ccol == 0) {
663 Navigate(wxNavigationKeyEvent::FromTab | wxNavigationKeyEvent::IsBackward);
667 if (has_no_selection) {
668 SetGridCursor(rows -1, cols - 1);
670 else if (ccol == 0) {
671 SetGridCursor(crow - 1, cols - 1);
674 SetGridCursor(crow, ccol - 1);
679 Navigate(wxNavigationKeyEvent::FromTab | wxNavigationKeyEvent::IsForward);
683 if (crow == rows - 1 && ccol == cols - 1) {
684 Navigate(wxNavigationKeyEvent::FromTab | wxNavigationKeyEvent::IsForward);
688 if (has_no_selection) {
691 else if (ccol == cols - 1) {
692 SetGridCursor(crow + 1, 0);
695 SetGridCursor(crow, ccol + 1);
699 MakeCellVisible(GetGridCursorRow(), GetGridCursorCol());
701#if wxUSE_ACCESSIBILITY
703 mAx->SetCurrentCell(GetGridCursorRow(), GetGridCursorCol());
709 case WXK_NUMPAD_ENTER:
711 if (!IsCellEditControlShown()) {
712 wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(
this), wxTopLevelWindow);
713 wxWindow *def = tlw->GetDefaultItem();
714 if (def && def->IsEnabled()) {
717 cevent.SetEventObject( def );
718 GetParent()->GetEventHandler()->ProcessEvent(cevent);
722 wxGrid::OnKeyDown(event);
727 SetGridCursor(GetGridCursorRow(), GetGridCursorCol());
733 wxGrid::OnKeyDown(event);
738#if wxUSE_ACCESSIBILITY
739void Grid::ClearGrid()
748bool Grid::InsertRows(
int pos,
int numRows,
bool updateLabels)
750 bool res = wxGrid::InsertRows(pos, numRows, updateLabels);
757bool Grid::AppendRows(
int numRows,
bool updateLabels)
759 bool res = wxGrid::AppendRows(numRows, updateLabels);
766bool Grid::DeleteRows(
int pos,
int numRows,
bool updateLabels)
768 bool res = wxGrid::DeleteRows(pos, numRows, updateLabels);
775bool Grid::InsertCols(
int pos,
int numCols,
bool updateLabels)
777 bool res = wxGrid::InsertCols(pos, numCols, updateLabels);
784bool Grid::AppendCols(
int numCols,
bool updateLabels)
786 bool res = wxGrid::AppendCols(numCols, updateLabels);
793bool Grid::DeleteCols(
int pos,
int numCols,
bool updateLabels)
795 bool res = wxGrid::DeleteCols(pos, numCols, updateLabels);
810void GridAx::TableUpdated()
812 NotifyEvent(wxACC_EVENT_OBJECT_REORDER,
813 mGrid->GetGridWindow(),
818void GridAx::SetCurrentCell(
int row,
int col)
820 int id = (((row * mGrid->GetNumberCols()) + col) + 1);
823 NotifyEvent(wxACC_EVENT_OBJECT_SELECTIONREMOVE,
824 mGrid->GetGridWindow(),
830 NotifyEvent(wxACC_EVENT_OBJECT_FOCUS,
831 mGrid->GetGridWindow(),
836 NotifyEvent(wxACC_EVENT_OBJECT_SELECTION,
837 mGrid->GetGridWindow(),
844bool GridAx::GetRowCol(
int childId,
int & row,
int & col)
846 if (childId == wxACC_SELF) {
850 int cols = mGrid->GetNumberCols();
851 int id = childId - 1;
861wxAccStatus GridAx::GetChild(
int childId, wxAccessible** child)
863 if (childId == wxACC_SELF) {
874wxAccStatus GridAx::GetChildCount(
int *childCount)
876 *childCount = mGrid->GetNumberRows() * mGrid->GetNumberCols();
887wxAccStatus GridAx::GetDefaultAction(
int WXUNUSED(childId), wxString *actionName)
895wxAccStatus GridAx::GetDescription(
int WXUNUSED(childId), wxString *description)
897 description->clear();
903wxAccStatus GridAx::GetHelpText(
int WXUNUSED(childId), wxString *helpText)
912wxAccStatus GridAx::GetKeyboardShortcut(
int WXUNUSED(childId), wxString *shortcut)
921wxAccStatus GridAx::GetLocation(wxRect & rect,
int elementId)
927 if (GetRowCol(elementId, row, col)) {
928 rect = mGrid->CellToRect(row, col);
929 rect.SetPosition(mGrid->CalcScrolledPosition(rect.GetPosition()));
930 rect.SetPosition(mGrid->GetGridWindow()->ClientToScreen(rect.GetPosition()));
933 rect = mGrid->GetRect();
934 rect.SetPosition(mGrid->GetParent()->ClientToScreen(rect.GetPosition()));
941wxAccStatus GridAx::GetName(
int childId, wxString *
name)
946 if (GetRowCol(childId, row, col)) {
947 wxString n = mGrid->GetColLabelValue(col);
948 wxString v = mGrid->GetCellValue(row, col);
959 static_cast<NumericEditor *
>(mGrid->GetCellEditor(row, col));
961 if (c && dt && df && ( c == dt || c == df)) {
968 v = converter.GetString();
984wxAccStatus GridAx::GetParent(wxAccessible ** WXUNUSED(parent))
986 return wxACC_NOT_IMPLEMENTED;
990wxAccStatus GridAx::GetRole(
int childId, wxAccRole *role)
992 if (childId == wxACC_SELF) {
993#if defined(__WXMSW__)
994 *role = wxROLE_SYSTEM_TABLE;
997#if defined(__WXMAC__)
998 *role = wxROLE_SYSTEM_GROUPING;
1002 *role = wxROLE_SYSTEM_TEXT;
1016wxAccStatus GridAx::GetSelections(wxVariant * WXUNUSED(selections))
1018 return wxACC_NOT_IMPLEMENTED;
1022wxAccStatus GridAx::GetState(
int childId,
long *state)
1024 int flag = wxACC_STATE_SYSTEM_FOCUSABLE |
1025 wxACC_STATE_SYSTEM_SELECTABLE;
1029 if (!GetRowCol(childId, row, col)) {
1034#if defined(__WXMSW__)
1035 flag |= wxACC_STATE_SYSTEM_FOCUSED |
1036 wxACC_STATE_SYSTEM_SELECTED;
1038 if (mGrid->IsReadOnly(row, col)) {
1042 flag = wxACC_STATE_SYSTEM_UNAVAILABLE | wxACC_STATE_SYSTEM_FOCUSED;
1046#if defined(__WXMAC__)
1047 if (mGrid->IsInSelection(row, col)) {
1048 flag |= wxACC_STATE_SYSTEM_SELECTED;
1051 if (mGrid->GetGridCursorRow() == row && mGrid->GetGridCursorCol() == col) {
1052 flag |= wxACC_STATE_SYSTEM_FOCUSED;
1055 if (mGrid->IsReadOnly(row, col)) {
1056 flag |= wxACC_STATE_SYSTEM_UNAVAILABLE;
1067#if defined(__WXMAC__)
1068wxAccStatus GridAx::GetValue(
int childId, wxString *strValue)
1070wxAccStatus GridAx::GetValue(
int WXUNUSED(childId), wxString *strValue)
1075#if defined(__WXMSW__)
1079#if defined(__WXMAC__)
1080 return GetName(childId, strValue);
1084#if defined(__WXMAC__)
1086wxAccStatus GridAx::Select(
int childId, wxAccSelectionFlags selectFlags)
1091 if (GetRowCol(childId, row, col)) {
1093 if (selectFlags & wxACC_SEL_TAKESELECTION) {
1094 mGrid->SetGridCursor(row, col);
1097 mGrid->SelectBlock(row, col, row, col, selectFlags & wxACC_SEL_ADDSELECTION);
1108wxAccStatus GridAx::GetFocus(
int * childId, wxAccessible **child)
1111 if (mGrid->GetNumberRows() * mGrid->GetNumberCols() == 0) {
1115 *childId = mGrid->GetGridCursorRow()*mGrid->GetNumberCols() +
1116 mGrid->GetGridCursorCol() + 1;
wxEVT_COMMAND_BUTTON_CLICKED
#define GRID_VALUE_FREQUENCY
#define GRID_VALUE_CHOICE
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
const NumericConverterType & NumericConverterType_FREQUENCY()
const NumericConverterType & NumericConverterType_TIME()
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)
const wxString & Internal() const
A context in which formatter operates.
Supplies an accessible grid based on wxGrid.
void OnKeyDown(wxKeyEvent &event)
void OnSelectCell(wxGridEvent &event)
void OnSetFocus(wxFocusEvent &event)
void OnEditorShown(wxGridEvent &event)
An explicitly nonlocalized string, not meant for the user to see.
NumericConverter provides the advanced formatting control used in the selection bar of Audacity.
wxGridCellEditor for the NumericTextCtrl.
NumericTextCtrl * GetNumericTextControl() const
wxString GetValue() const override
void ApplyEdit(int row, int col, wxGrid *grid) override
void SetFormat(const NumericFormatID &format)
void Create(wxWindow *parent, wxWindowID id, wxEvtHandler *handler) override
NumericConverterType mType
FormatterContext mContext
bool IsAcceptedKey(wxKeyEvent &event) override
NumericEditor(const FormatterContext &context, NumericConverterType type, const NumericFormatID &format)
void SetSize(const wxRect &rect) override
NumericFormatID GetFormat() const
void BeginEdit(int row, int col, wxGrid *grid) override
bool EndEdit(int row, int col, const wxGrid *grid, const wxString &oldval, wxString *newval) override
wxGridCellEditor * Clone() const override
wxGridCellRenderer for the NumericTextCtrl.
FormatterContext mContext
wxGridCellRenderer * Clone() const override
~NumericRenderer() override
void Draw(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &rect, int row, int col, bool isSelected) override
NumericConverterType mType
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)