Audacity 3.2.0
Public Member Functions | Protected Member Functions | 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 (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)
 

Detailed Description

Supplies an accessible grid based on wxGrid.

wxGrid with support for accessibility.

Definition at line 184 of file Grid.h.

Constructor & Destructor Documentation

◆ Grid()

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

Definition at line 474 of file Grid.cpp.

480: wxGrid(parent, id, pos, size, style | wxWANTS_CHARS, name)
481{
482#if wxUSE_ACCESSIBILITY
483 GetGridWindow()->SetAccessible(mAx = safenew GridAx(this));
484#endif
485
486 // RegisterDataType takes ownership of renderer and editor
487
488 RegisterDataType(GRID_VALUE_TIME,
493
494 RegisterDataType(GRID_VALUE_FREQUENCY,
498 NumericConverter::HertzFormat(), 44100.0 });
499
500 RegisterDataType(GRID_VALUE_CHOICE,
501 safenew wxGridCellStringRenderer,
503
504 // Bug #2803:
505 // Ensure selection doesn't show up.
506 SetSelectionForeground(GetDefaultCellTextColour());
507 SetSelectionBackground(GetDefaultCellBackgroundColour());
508}
const TranslatableString name
Definition: Distortion.cpp:82
#define GRID_VALUE_TIME
Definition: Grid.h:34
#define GRID_VALUE_FREQUENCY
Definition: Grid.h:35
#define GRID_VALUE_CHOICE
Definition: Grid.h:117
#define safenew
Definition: MemoryX.h:10
Modified version of wxGridChoiceEditor using wxChoice instead of wxComboBox.
Definition: Grid.h:121
static NumericFormatSymbol HertzFormat()
static NumericFormatSymbol SecondsFormat()
wxGridCellEditor for the NumericTextCtrl.
Definition: Grid.h:38
wxGridCellRenderer for the NumericTextCtrl.
Definition: Grid.h:87

References NumericConverter::FREQUENCY, GRID_VALUE_CHOICE, GRID_VALUE_FREQUENCY, GRID_VALUE_TIME, NumericConverter::HertzFormat(), safenew, NumericConverter::SecondsFormat(), and NumericConverter::TIME.

Here is the call graph for this function:

◆ ~Grid()

Grid::~Grid ( )

Definition at line 510 of file Grid.cpp.

511{
512#if wxUSE_ACCESSIBILITY
513 int cnt = mChildren.size();
514 while (cnt--) {
515 // PRL: I found this loop destroying right-to-left.
516 // Is the sequence of destruction important?
517 mChildren.pop_back();
518 }
519#endif
520}

Member Function Documentation

◆ OnEditorShown()

void Grid::OnEditorShown ( wxGridEvent &  event)
protected

Definition at line 542 of file Grid.cpp.

543{
544 event.Skip();
545
546 // Bug #2803 (comment 7):
547 // Select row whenever an editor is displayed
548 SelectRow(GetGridCursorRow());
549}

◆ OnKeyDown()

void Grid::OnKeyDown ( wxKeyEvent &  event)
protected

Definition at line 551 of file Grid.cpp.

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

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 531 of file Grid.cpp.

532{
533 event.Skip();
534
535 MakeCellVisible(event.GetRow(), event.GetCol());
536
537#if wxUSE_ACCESSIBILITY
538 mAx->SetCurrentCell(event.GetRow(), event.GetCol());
539#endif
540}

◆ OnSetFocus()

void Grid::OnSetFocus ( wxFocusEvent &  event)
protected

Definition at line 522 of file Grid.cpp.

523{
524 event.Skip();
525
526#if wxUSE_ACCESSIBILITY
527 mAx->SetCurrentCell(GetGridCursorRow(), GetGridCursorCol());
528#endif
529}

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