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