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':
556 {
557 wxTextDataObject *data =
safenew wxTextDataObject(GetCellValue(crow, ccol));
559 return;
560 }
561 break;
562
563 case 'X':
564 {
565 wxTextDataObject *data =
safenew wxTextDataObject(GetCellValue(crow, ccol));
567 SetCellValue(crow, ccol, "" );
568 return;
569 }
570 break;
571
572 case 'V':
573 {
575 {
576 wxTextDataObject 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
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
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
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
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()) {
717 def->GetId());
718 cevent.SetEventObject( def );
719 GetParent()->GetEventHandler()->ProcessEvent(cevent);
720 }
721 }
722 else {
723 wxGrid::OnKeyDown(event);
724
725
726
727
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.