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