Audacity 3.2.0
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
Grid Class Referencefinal

Supplies an accessible grid based on wxGrid. More...

#include <Grid.h>

Inheritance diagram for Grid:
[legend]
Collaboration diagram for Grid:
[legend]

Public Member Functions

 Grid (const FormatterContext &context, wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxWANTS_CHARS|wxBORDER, const wxString &name=wxPanelNameStr)
 
 ~Grid ()
 

Protected Member Functions

void OnSetFocus (wxFocusEvent &event)
 
void OnSelectCell (wxGridEvent &event)
 
void OnEditorShown (wxGridEvent &event)
 
void OnKeyDown (wxKeyEvent &event)
 

Private Attributes

FormatterContext mContext
 

Detailed Description

Supplies an accessible grid based on wxGrid.

wxGrid with support for accessibility.

Definition at line 189 of file Grid.h.

Constructor & Destructor Documentation

◆ Grid()

Grid::Grid ( const FormatterContext context,
wxWindow *  parent,
wxWindowID  id,
const wxPoint &  pos = wxDefaultPosition,
const wxSize &  size = wxDefaultSize,
long  style = wxWANTS_CHARS | wxBORDER,
const wxString &  name = wxPanelNameStr 
)

Definition at line 463 of file Grid.cpp.

471: wxGrid(parent, id, pos, size, style | wxWANTS_CHARS, name), mContext(context)
472{
473#if wxUSE_ACCESSIBILITY
474 GetGridWindow()->SetAccessible(mAx = safenew GridAx(mContext, this));
475#endif
476
477 // RegisterDataType takes ownership of renderer and editor
478
479 RegisterDataType(GRID_VALUE_TIME,
484
485 RegisterDataType(GRID_VALUE_FREQUENCY,
490
491 RegisterDataType(GRID_VALUE_CHOICE,
492 safenew wxGridCellStringRenderer,
494
495 // Bug #2803:
496 // Ensure selection doesn't show up.
497 SetSelectionForeground(GetDefaultCellTextColour());
498 SetSelectionBackground(GetDefaultCellBackgroundColour());
499}
#define GRID_VALUE_TIME
Definition: Grid.h:36
#define GRID_VALUE_FREQUENCY
Definition: Grid.h:37
#define GRID_VALUE_CHOICE
Definition: Grid.h:123
#define safenew
Definition: MemoryX.h:10
const NumericConverterType & NumericConverterType_FREQUENCY()
const NumericConverterType & NumericConverterType_TIME()
wxString name
Definition: TagsEditor.cpp:166
Modified version of wxGridChoiceEditor using wxChoice instead of wxComboBox.
Definition: Grid.h:127
const wxString & Internal() const
FormatterContext mContext
Definition: Grid.h:225
wxGridCellEditor for the NumericTextCtrl.
Definition: Grid.h:40
wxGridCellRenderer for the NumericTextCtrl.
Definition: Grid.h:88
NUMERIC_FORMATS_API NumericFormatSymbol HertzFormat()
NUMERIC_FORMATS_API NumericFormatSymbol SecondsFormat()

References GRID_VALUE_CHOICE, GRID_VALUE_FREQUENCY, GRID_VALUE_TIME, NumericConverterFormats::HertzFormat(), ComponentInterfaceSymbol::Internal(), NumericConverterType_FREQUENCY(), NumericConverterType_TIME(), safenew, and NumericConverterFormats::SecondsFormat().

Here is the call graph for this function:

◆ ~Grid()

Grid::~Grid ( )

Definition at line 501 of file Grid.cpp.

502{
503#if wxUSE_ACCESSIBILITY
504 int cnt = mChildren.size();
505 while (cnt--) {
506 // PRL: I found this loop destroying right-to-left.
507 // Is the sequence of destruction important?
508 mChildren.pop_back();
509 }
510#endif
511}

Member Function Documentation

◆ OnEditorShown()

void Grid::OnEditorShown ( wxGridEvent &  event)
protected

Definition at line 533 of file Grid.cpp.

534{
535 event.Skip();
536
537 // Bug #2803 (comment 7):
538 // Select row whenever an editor is displayed
539 SelectRow(GetGridCursorRow());
540}

◆ OnKeyDown()

void Grid::OnKeyDown ( wxKeyEvent &  event)
protected

Definition at line 542 of file Grid.cpp.

543{
544 auto keyCode = event.GetKeyCode();
545 int crow = GetGridCursorRow();
546 int ccol = GetGridCursorCol();
547
548 if (event.CmdDown() && crow != wxGridNoCellCoords.GetRow() && ccol != wxGridNoCellCoords.GetCol())
549 {
550 wxClipboardLocker cb;
551
552 switch (keyCode)
553 {
554 case 'C': // Copy
555 {
556 wxTextDataObject *data = safenew wxTextDataObject(GetCellValue(crow, ccol));
557 wxClipboard::Get()->SetData(data);
558 return;
559 }
560 break;
561
562 case 'X': // Cut
563 {
564 wxTextDataObject *data = safenew wxTextDataObject(GetCellValue(crow, ccol));
565 wxClipboard::Get()->SetData(data);
566 SetCellValue(crow, ccol, "" );
567 return;
568 }
569 break;
570
571 case 'V': // Paste
572 {
573 if (wxClipboard::Get()->IsSupported(wxDF_UNICODETEXT))
574 {
575 wxTextDataObject data;
576 if (wxClipboard::Get()->GetData(data))
577 {
578 SetCellValue(crow, ccol, data.GetText());
579 return;
580 }
581 }
582 }
583 break;
584 }
585 }
586
587 switch (keyCode)
588 {
589 case WXK_LEFT:
590 case WXK_RIGHT:
591 {
592 int rows = GetNumberRows();
593 int cols = GetNumberCols();
594
595 const bool has_cells = rows > 0 && cols > 0;
596
597 if (has_cells) {
598 int crow = GetGridCursorRow();
599 int ccol = GetGridCursorCol();
600
601 const bool has_no_selection = crow == wxGridNoCellCoords.GetRow() || ccol == wxGridNoCellCoords.GetCol();
602
603 if (has_no_selection) {
604 SetGridCursor(0, 0);
605 }
606 else if (event.GetKeyCode() == WXK_LEFT) {
607 if (crow == 0 && ccol == 0) {
608 // do nothing
609 }
610 else if (ccol == 0) {
611 SetGridCursor(crow - 1, cols - 1);
612 }
613 else {
614 SetGridCursor(crow, ccol - 1);
615 }
616 }
617 else {
618 if (crow == rows - 1 && ccol == cols - 1) {
619 // do nothing
620 }
621 else if (ccol == cols - 1) {
622 SetGridCursor(crow + 1, 0);
623 }
624 else {
625 SetGridCursor(crow, ccol + 1);
626 }
627 }
628 }
629
630#if wxUSE_ACCESSIBILITY
631 // Make sure the NEW cell is made available to the screen reader
632 mAx->SetCurrentCell(GetGridCursorRow(), GetGridCursorCol());
633#endif
634 }
635 break;
636
637 case WXK_TAB:
638 {
639 if (event.ControlDown()) {
640 int flags = wxNavigationKeyEvent::FromTab |
641 ( event.ShiftDown() ?
642 wxNavigationKeyEvent::IsBackward :
643 wxNavigationKeyEvent::IsForward );
644 Navigate(flags);
645 return;
646 }
647
648 int rows = GetNumberRows();
649 int cols = GetNumberCols();
650 int crow = GetGridCursorRow();
651 int ccol = GetGridCursorCol();
652
653 const auto is_empty = rows <= 0 || cols <= 0;
654 const auto has_no_selection = crow == wxGridNoCellCoords.GetRow() || ccol == wxGridNoCellCoords.GetCol();
655
656 if (event.ShiftDown()) {
657 if (is_empty) {
658 Navigate(wxNavigationKeyEvent::FromTab | wxNavigationKeyEvent::IsBackward);
659 return;
660 }
661
662 if (crow == 0 && ccol == 0) {
663 Navigate(wxNavigationKeyEvent::FromTab | wxNavigationKeyEvent::IsBackward);
664 return;
665 }
666
667 if (has_no_selection) {
668 SetGridCursor(rows -1, cols - 1);
669 }
670 else if (ccol == 0) {
671 SetGridCursor(crow - 1, cols - 1);
672 }
673 else {
674 SetGridCursor(crow, ccol - 1);
675 }
676 }
677 else {
678 if (is_empty) {
679 Navigate(wxNavigationKeyEvent::FromTab | wxNavigationKeyEvent::IsForward);
680 return;
681 }
682
683 if (crow == rows - 1 && ccol == cols - 1) {
684 Navigate(wxNavigationKeyEvent::FromTab | wxNavigationKeyEvent::IsForward);
685 return;
686 }
687
688 if (has_no_selection) {
689 SetGridCursor(0, 0);
690 }
691 else if (ccol == cols - 1) {
692 SetGridCursor(crow + 1, 0);
693 }
694 else {
695 SetGridCursor(crow, ccol + 1);
696 }
697 }
698
699 MakeCellVisible(GetGridCursorRow(), GetGridCursorCol());
700
701#if wxUSE_ACCESSIBILITY
702 // Make sure the NEW cell is made available to the screen reader
703 mAx->SetCurrentCell(GetGridCursorRow(), GetGridCursorCol());
704#endif
705 }
706 break;
707
708 case WXK_RETURN:
709 case WXK_NUMPAD_ENTER:
710 {
711 if (!IsCellEditControlShown()) {
712 wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
713 wxWindow *def = tlw->GetDefaultItem();
714 if (def && def->IsEnabled()) {
715 wxCommandEvent cevent(wxEVT_COMMAND_BUTTON_CLICKED,
716 def->GetId());
717 cevent.SetEventObject( def );
718 GetParent()->GetEventHandler()->ProcessEvent(cevent);
719 }
720 }
721 else {
722 wxGrid::OnKeyDown(event);
723
724 // This looks strange, but what it does is selects the cell when
725 // enter is pressed after editing. Without it, Jaws and Window-Eyes
726 // do not speak the NEW cell contents (the one below the edited one).
727 SetGridCursor(GetGridCursorRow(), GetGridCursorCol());
728 }
729 break;
730 }
731
732 default:
733 wxGrid::OnKeyDown(event);
734 break;
735 }
736}
wxEVT_COMMAND_BUTTON_CLICKED
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:202

References BasicUI::Get(), safenew, and wxEVT_COMMAND_BUTTON_CLICKED.

Here is the call graph for this function:

◆ OnSelectCell()

void Grid::OnSelectCell ( wxGridEvent &  event)
protected

Definition at line 522 of file Grid.cpp.

523{
524 event.Skip();
525
526 MakeCellVisible(event.GetRow(), event.GetCol());
527
528#if wxUSE_ACCESSIBILITY
529 mAx->SetCurrentCell(event.GetRow(), event.GetCol());
530#endif
531}

◆ OnSetFocus()

void Grid::OnSetFocus ( wxFocusEvent &  event)
protected

Definition at line 513 of file Grid.cpp.

514{
515 event.Skip();
516
517#if wxUSE_ACCESSIBILITY
518 mAx->SetCurrentCell(GetGridCursorRow(), GetGridCursorCol());
519#endif
520}

Member Data Documentation

◆ mContext

FormatterContext Grid::mContext
private

Definition at line 225 of file Grid.h.


The documentation for this class was generated from the following files: