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,
485
486 RegisterDataType(GRID_VALUE_FREQUENCY,
491
492 RegisterDataType(GRID_VALUE_CHOICE,
493 safenew wxGridCellStringRenderer,
495
496 // Bug #2803:
497 // Ensure selection doesn't show up.
498 SetSelectionForeground(GetDefaultCellTextColour());
499 SetSelectionBackground(GetDefaultCellBackgroundColour());
500}
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
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 502 of file Grid.cpp.

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

Member Function Documentation

◆ OnEditorShown()

void Grid::OnEditorShown ( wxGridEvent &  event)
protected

Definition at line 534 of file Grid.cpp.

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

◆ OnKeyDown()

void Grid::OnKeyDown ( wxKeyEvent &  event)
protected

Definition at line 543 of file Grid.cpp.

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

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

◆ OnSetFocus()

void Grid::OnSetFocus ( wxFocusEvent &  event)
protected

Definition at line 514 of file Grid.cpp.

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

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: