| 498 | BMenuField* |
| 499 | KeymapWindow::_CreateModifiersMenuField() |
| 500 | { |
| 501 | fModifiersMenu = new BMenu(B_TRANSLATE("Select modifier keys")); |
| 502 | fModifiersMenu->SetRadioMode(true); |
| 503 | fModifiersMenu->SetLabelFromMarked(false); |
| 504 | |
| 505 | fModifiersMenu->AddItem( |
| 506 | new BMenuItem(B_TRANSLATE("Haiku modifier keys"), |
| 507 | new BMessage(kMsgModifiersHaiku)), MODIFIERS_HAIKU); |
| 508 | fModifiersMenu->AddItem( |
| 509 | new BMenuItem(B_TRANSLATE("Windows/Linux modifier keys"), |
| 510 | new BMessage(kMsgModifiersWinLinux)), MODIFIERS_WIN_LINUX); |
| 511 | fModifiersMenu->AddItem( |
| 512 | new BMenuItem(B_TRANSLATE("Mac modifier keys"), |
| 513 | new BMessage(kMsgModifiersMac)), MODIFIERS_MAC); |
| 514 | |
| 515 | return new BMenuField(NULL, fModifiersMenu); |
| 516 | } |
| 517 | |
| 518 | |
593 | | const char* label = B_TRANSLATE("Switch shortcut keys"); |
594 | | if (fCurrentMap.KeyForModifier(B_LEFT_COMMAND_KEY) == 0x5d |
595 | | && fCurrentMap.KeyForModifier(B_LEFT_CONTROL_KEY) == 0x5c) { |
596 | | label = B_TRANSLATE("Switch shortcut keys to Windows/Linux mode"); |
597 | | } else if (fCurrentMap.KeyForModifier(B_LEFT_COMMAND_KEY) == 0x5c |
598 | | && fCurrentMap.KeyForModifier(B_LEFT_CONTROL_KEY) == 0x5d) { |
599 | | label = B_TRANSLATE("Switch shortcut keys to Haiku mode"); |
| 627 | // Enable the default items (diabled again if custom keymap) |
| 628 | fModifiersMenu->ItemAt(MODIFIERS_HAIKU)->SetEnabled(true); |
| 629 | fModifiersMenu->ItemAt(MODIFIERS_WIN_LINUX)->SetEnabled(true); |
| 630 | fModifiersMenu->ItemAt(MODIFIERS_MAC)->SetEnabled(true); |
| 631 | // Remove the custom item (added back if custom keymap) |
| 632 | fModifiersMenu->RemoveItem(MODIFIERS_CUSTOM); |
| 633 | |
| 634 | // To be in a mode the modifier keys must either be unmapped (== 0), |
| 635 | // or mapped to the keys for the mode. |
| 636 | if (_HaikuMode()) |
| 637 | fModifiersMenu->ItemAt(MODIFIERS_HAIKU)->SetMarked(true); |
| 638 | else if (_WinLinuxMode()) |
| 639 | fModifiersMenu->ItemAt(MODIFIERS_WIN_LINUX)->SetMarked(true); |
| 640 | else if (_MacMode()) |
| 641 | fModifiersMenu->ItemAt(MODIFIERS_MAC)->SetMarked(true); |
| 642 | else { |
| 643 | // Custom modifier settings |
| 644 | |
| 645 | // Disable the default menu items |
| 646 | fModifiersMenu->ItemAt(MODIFIERS_HAIKU)->SetEnabled(false); |
| 647 | fModifiersMenu->ItemAt(MODIFIERS_WIN_LINUX)->SetEnabled(false); |
| 648 | fModifiersMenu->ItemAt(MODIFIERS_MAC)->SetEnabled(false); |
| 649 | |
| 650 | // Add custom menu item to the menu and mark it |
| 651 | fModifiersMenu->AddItem(new BMenuItem(B_TRANSLATE("Custom"), NULL), |
| 652 | MODIFIERS_CUSTOM); |
| 653 | fModifiersMenu->ItemAt(MODIFIERS_CUSTOM)->SetMarked(true); |
668 | | uint32 leftCommand = fCurrentMap.Map().left_command_key; |
669 | | uint32 leftControl = fCurrentMap.Map().left_control_key; |
670 | | uint32 rightCommand = fCurrentMap.Map().right_command_key; |
671 | | uint32 rightControl = fCurrentMap.Map().right_control_key; |
| 721 | key_map& keyMap = fCurrentMap.Map(); |
| 722 | |
| 723 | uint32 leftControl = fCurrentMap.KeyForModifier(B_LEFT_CONTROL_KEY); |
| 724 | uint32 leftCommand = fCurrentMap.KeyForModifier(B_LEFT_COMMAND_KEY); |
| 725 | uint32 leftOption = fCurrentMap.KeyForModifier(B_LEFT_OPTION_KEY); |
| 726 | uint32 rightControl = fCurrentMap.KeyForModifier(B_RIGHT_CONTROL_KEY); |
| 727 | uint32 rightCommand = fCurrentMap.KeyForModifier(B_RIGHT_COMMAND_KEY); |
| 728 | uint32 rightOption = fCurrentMap.KeyForModifier(B_RIGHT_OPTION_KEY); |
| 729 | |
| 730 | if (_HaikuMode()) { |
| 731 | switch (mode) { |
| 732 | case MODIFIERS_HAIKU: |
| 733 | // switching from Haiku mode to Haiku mode |
| 734 | return; |
| 735 | |
| 736 | case MODIFIERS_WIN_LINUX: |
| 737 | // switching from Haiku mode to Windows/Linux mode |
| 738 | // swap command and control keys |
| 739 | |
| 740 | // swap left side |
| 741 | keyMap.left_control_key = leftCommand; |
| 742 | keyMap.left_command_key = leftControl; |
| 743 | |
| 744 | // swap right side |
| 745 | keyMap.right_control_key = rightCommand; |
| 746 | keyMap.right_command_key = rightControl; |
| 747 | break; |
| 748 | |
| 749 | case MODIFIERS_MAC: |
| 750 | // switching from Haiku mode to Mac mode |
| 751 | // swap command and option keys |
| 752 | |
| 753 | // swap left side |
| 754 | keyMap.left_command_key = leftOption; |
| 755 | keyMap.left_option_key = leftCommand; |
| 756 | |
| 757 | // swap right side |
| 758 | keyMap.right_command_key = rightOption; |
| 759 | keyMap.right_option_key = rightCommand; |
| 760 | break; |
| 761 | } |
| 762 | } else if (_WinLinuxMode()) { |
| 763 | switch (mode) { |
| 764 | case MODIFIERS_HAIKU: |
| 765 | // switching from Windows/Linux mode to Haiku mode |
| 766 | // swap command and control keys |
| 767 | |
| 768 | // swap left side |
| 769 | keyMap.left_control_key = leftCommand; |
| 770 | keyMap.left_command_key = leftControl; |
| 771 | |
| 772 | // swap right side |
| 773 | keyMap.right_control_key = rightCommand; |
| 774 | keyMap.right_command_key = rightControl; |
| 775 | break; |
677 | | // switch right side |
678 | | fCurrentMap.Map().right_command_key = rightControl; |
679 | | fCurrentMap.Map().right_control_key = rightCommand; |
| 781 | case MODIFIERS_MAC: |
| 782 | // switching from Windows/Linux mode to Mac mode |
| 783 | // swap control and option keys |
| 784 | // then swap command and option keys |
| 785 | |
| 786 | // swap left side |
| 787 | keyMap.left_control_key = leftCommand; |
| 788 | keyMap.left_command_key = leftOption; |
| 789 | keyMap.left_option_key = leftControl; |
| 790 | |
| 791 | // swap right side |
| 792 | keyMap.right_control_key = rightCommand; |
| 793 | keyMap.right_command_key = rightOption; |
| 794 | keyMap.right_option_key = rightControl; |
| 795 | break; |
| 796 | } |
| 797 | } else if (_MacMode()) { |
| 798 | switch (mode) { |
| 799 | case MODIFIERS_HAIKU: |
| 800 | // switching from Mac mode to Haiku mode |
| 801 | // swap command and option keys |
| 802 | |
| 803 | // swap left side |
| 804 | keyMap.left_command_key = leftOption; |
| 805 | keyMap.left_option_key = leftCommand; |
| 806 | |
| 807 | // swap right side |
| 808 | keyMap.right_command_key = rightOption; |
| 809 | keyMap.right_option_key = rightCommand; |
| 810 | break; |
| 811 | |
| 812 | case MODIFIERS_WIN_LINUX: |
| 813 | // switching from Mac mode to Windows/Linux mode |
| 814 | // swap control and command |
| 815 | // then swap command and option |
| 816 | |
| 817 | // switch left side |
| 818 | keyMap.left_control_key = leftOption; |
| 819 | keyMap.left_command_key = leftControl; |
| 820 | keyMap.left_option_key = leftCommand; |
| 821 | |
| 822 | // switch right side |
| 823 | keyMap.right_control_key = rightOption; |
| 824 | keyMap.right_command_key = rightControl; |
| 825 | keyMap.right_option_key = rightCommand; |
| 826 | break; |
| 827 | |
| 828 | case MODIFIERS_MAC: |
| 829 | return; |
| 830 | } |
| 831 | } |
| 1098 | |
| 1099 | |
| 1100 | bool |
| 1101 | KeymapWindow::_HaikuMode() |
| 1102 | { |
| 1103 | uint32 leftControl = fCurrentMap.KeyForModifier(B_LEFT_CONTROL_KEY); |
| 1104 | uint32 leftCommand = fCurrentMap.KeyForModifier(B_LEFT_COMMAND_KEY); |
| 1105 | uint32 leftOption = fCurrentMap.KeyForModifier(B_LEFT_OPTION_KEY); |
| 1106 | uint32 rightControl = fCurrentMap.KeyForModifier(B_RIGHT_CONTROL_KEY); |
| 1107 | uint32 rightCommand = fCurrentMap.KeyForModifier(B_RIGHT_COMMAND_KEY); |
| 1108 | uint32 rightOption = fCurrentMap.KeyForModifier(B_RIGHT_OPTION_KEY); |
| 1109 | |
| 1110 | return leftControl == kLeftControlKey && leftCommand == kLeftCommandKey |
| 1111 | && leftOption == kLeftOptionKey |
| 1112 | && (rightControl == kRightControlKey || rightControl == 0) |
| 1113 | && (rightCommand == kRightCommandKey || rightCommand == kRightOptionKey |
| 1114 | || rightCommand == 0) |
| 1115 | && (rightOption == kRightOptionKey || rightOption == kRightCommandKey |
| 1116 | || rightOption == 0); |
| 1117 | } |
| 1118 | |
| 1119 | |
| 1120 | bool |
| 1121 | KeymapWindow::_WinLinuxMode() |
| 1122 | { |
| 1123 | uint32 leftControl = fCurrentMap.KeyForModifier(B_LEFT_CONTROL_KEY); |
| 1124 | uint32 leftCommand = fCurrentMap.KeyForModifier(B_LEFT_COMMAND_KEY); |
| 1125 | uint32 leftOption = fCurrentMap.KeyForModifier(B_LEFT_OPTION_KEY); |
| 1126 | uint32 rightControl = fCurrentMap.KeyForModifier(B_RIGHT_CONTROL_KEY); |
| 1127 | uint32 rightCommand = fCurrentMap.KeyForModifier(B_RIGHT_COMMAND_KEY); |
| 1128 | uint32 rightOption = fCurrentMap.KeyForModifier(B_RIGHT_OPTION_KEY); |
| 1129 | |
| 1130 | return leftControl == kLeftCommandKey && leftCommand == kLeftControlKey |
| 1131 | && leftOption == kLeftOptionKey |
| 1132 | && (rightControl == kRightCommandKey || rightControl == kRightOptionKey || |
| 1133 | rightControl == 0) |
| 1134 | && (rightCommand == kRightControlKey || rightCommand == 0) |
| 1135 | && (rightOption == kRightOptionKey || rightOption == kRightCommandKey |
| 1136 | || rightOption == 0); |
| 1137 | } |
| 1138 | |
| 1139 | |
| 1140 | bool |
| 1141 | KeymapWindow::_MacMode() |
| 1142 | { |
| 1143 | uint32 leftControl = fCurrentMap.KeyForModifier(B_LEFT_CONTROL_KEY); |
| 1144 | uint32 leftCommand = fCurrentMap.KeyForModifier(B_LEFT_COMMAND_KEY); |
| 1145 | uint32 leftOption = fCurrentMap.KeyForModifier(B_LEFT_OPTION_KEY); |
| 1146 | uint32 rightControl = fCurrentMap.KeyForModifier(B_RIGHT_CONTROL_KEY); |
| 1147 | uint32 rightCommand = fCurrentMap.KeyForModifier(B_RIGHT_COMMAND_KEY); |
| 1148 | uint32 rightOption = fCurrentMap.KeyForModifier(B_RIGHT_OPTION_KEY); |
| 1149 | |
| 1150 | return leftControl == kLeftControlKey && leftCommand == kLeftOptionKey |
| 1151 | && leftOption == kLeftCommandKey |
| 1152 | && (rightControl == kRightControlKey || rightControl == 0) |
| 1153 | && (rightCommand == kRightOptionKey || rightCommand == kRightCommandKey |
| 1154 | || rightCommand == 0) |
| 1155 | && (rightOption == kRightCommandKey || rightCommand == kRightOptionKey |
| 1156 | || rightOption == 0); |
| 1157 | } |