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

472: wxGrid(parent, id, pos, size, style | wxWANTS_CHARS, name), mContext(context)
473{
474#if wxUSE_ACCESSIBILITY
475 GetGridWindow()->SetAccessible(mAx = safenew GridAx(mContext, this));
476#endif
477
478 // RegisterDataType takes ownership of renderer and editor
479
480 RegisterDataType(GRID_VALUE_TIME,
484
485 RegisterDataType(GRID_VALUE_FREQUENCY,
489
490 RegisterDataType(GRID_VALUE_CHOICE,
491 safenew wxGridCellStringRenderer,
493
494 // Bug #2803:
495 // Ensure selection doesn't show up.
496 SetSelectionForeground(GetDefaultCellTextColour());
497 SetSelectionBackground(GetDefaultCellBackgroundColour());
498}
const TranslatableString name
Definition: Distortion.cpp:76
#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()
Modified version of wxGridChoiceEditor using wxChoice instead of wxComboBox.
Definition: Grid.h:127
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(), NumericConverterType_FREQUENCY(), NumericConverterType_TIME(), safenew, and NumericConverterFormats::SecondsFormat().

Here is the call graph for this function:

◆ ~Grid()

Grid::~Grid ( )

Definition at line 500 of file Grid.cpp.

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

Member Function Documentation

◆ OnEditorShown()

void Grid::OnEditorShown ( wxGridEvent &  event)
protected

Definition at line 532 of file Grid.cpp.

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

◆ OnKeyDown()

void Grid::OnKeyDown ( wxKeyEvent &  event)
protected

Definition at line 541 of file Grid.cpp.

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

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

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

◆ OnSetFocus()

void Grid::OnSetFocus ( wxFocusEvent &  event)
protected

Definition at line 512 of file Grid.cpp.

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

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: