void ModifierKeysWindow::_MarkMenuItems() { for (int32 key = MENU_ITEM_SHIFT; key <= MENU_ITEM_DISABLED; key++) { if (key == MENU_ITEM_SEPERATOR) continue; if (fCurrentMap->left_shift_key == _KeyToKeyCode(key) && fCurrentMap->right_shift_key == _KeyToKeyCode(key, true)) { fShiftMenu->ItemAt(key)->SetMarked(true); } if (fCurrentMap->left_control_key == _KeyToKeyCode(key) && fCurrentMap->right_control_key == _KeyToKeyCode(key, true)) { fControlMenu->ItemAt(key)->SetMarked(true); } if (fCurrentMap->left_option_key == _KeyToKeyCode(key) && fCurrentMap->right_option_key == _KeyToKeyCode(key, true)) { fOptionMenu->ItemAt(key)->SetMarked(true); } if (fCurrentMap->left_command_key == _KeyToKeyCode(key) && fCurrentMap->right_command_key == _KeyToKeyCode(key, true)) { fCommandMenu->ItemAt(key)->SetMarked(true); } } }
void ModifierKeysWindow::_MarkMenuItems() { for (int32 key = MENU_ITEM_SHIFT; key <= MENU_ITEM_DISABLED; key++) { if (key == MENU_ITEM_SEPERATOR) continue; if (fCurrentMap->left_shift_key == _KeyToKeyCode(key) && fCurrentMap->right_shift_key == _KeyToKeyCode(key, true)) { fShiftMenu->ItemAt(key)->SetMarked(true); } if (fCurrentMap->left_control_key == _KeyToKeyCode(key) && fCurrentMap->right_control_key == _KeyToKeyCode(key, true)) { fControlMenu->ItemAt(key)->SetMarked(true); } if (fCurrentMap->left_option_key == _KeyToKeyCode(key) && fCurrentMap->right_option_key == _KeyToKeyCode(key, true)) { fOptionMenu->ItemAt(key)->SetMarked(true); } if (fCurrentMap->left_command_key == _KeyToKeyCode(key) && fCurrentMap->right_command_key == _KeyToKeyCode(key, true)) { fCommandMenu->ItemAt(key)->SetMarked(true); } } // Set the warning icon if not marked BBitmap* shiftIcon = fShiftConflictView->Icon(); BBitmap* controlIcon = fControlConflictView->Icon(); BBitmap* optionIcon = fOptionConflictView->Icon(); BBitmap* commandIcon = fCommandConflictView->Icon(); fShiftConflictView->SetWarnIcon(fShiftMenu->FindMarked() == NULL); fControlConflictView->SetWarnIcon(fControlMenu->FindMarked() == NULL); fOptionConflictView->SetWarnIcon(fOptionMenu->FindMarked() == NULL); fCommandConflictView->SetWarnIcon(fCommandMenu->FindMarked() == NULL); // if there was a change invalidate the view if (shiftIcon != fShiftConflictView->Icon()) fShiftConflictView->Invalidate(); if (controlIcon != fControlConflictView->Icon()) fControlConflictView->Invalidate(); if (optionIcon != fOptionConflictView->Icon()) fOptionConflictView->Invalidate(); if (commandIcon != fCommandConflictView->Icon()) fCommandConflictView->Invalidate(); }
void ModifierKeysWindow::MessageReceived(BMessage* message) { switch (message->what) { case kMsgHideShowIcons: _HideShowIcons(); break; case kMsgUpdateModifier: { int32 menuitem = MENU_ITEM_SHIFT; int32 key = -1; for (; menuitem <= MENU_ITEM_COMMAND; menuitem++) { if (message->FindInt32(_KeyToString(menuitem), &key) == B_OK) break; } if (key == -1) return; // menuitem contains the item we want to set // key contains the item we want to set it to. switch (menuitem) { case MENU_ITEM_SHIFT: fCurrentMap->left_shift_key = _KeyToKeyCode(key); fCurrentMap->right_shift_key = _KeyToKeyCode(key, true); break; case MENU_ITEM_CONTROL: fCurrentMap->left_control_key = _KeyToKeyCode(key); fCurrentMap->right_control_key = _KeyToKeyCode(key, true); break; case MENU_ITEM_OPTION: fCurrentMap->left_option_key = _KeyToKeyCode(key); fCurrentMap->right_option_key = _KeyToKeyCode(key, true); break; case MENU_ITEM_COMMAND: fCurrentMap->left_command_key = _KeyToKeyCode(key); fCurrentMap->right_command_key = _KeyToKeyCode(key, true); break; } _MarkMenuItems(); _ValidateDuplicateKeys(); _HideShowIcons(); // enable/disable revert button fRevertButton->SetEnabled( memcmp(fCurrentMap, fSavedMap, sizeof(key_map))); break; } // OK button case kMsgApplyModifiers: { // if duplicate modifiers are found, don't update if (_DuplicateKeys() != 0) break; BMessage* updateModifiers = new BMessage(kMsgUpdateModifierKeys); if (fCurrentMap->left_shift_key != fSavedMap->left_shift_key) { updateModifiers->AddUInt32("left_shift_key", fCurrentMap->left_shift_key); } if (fCurrentMap->right_shift_key != fSavedMap->right_shift_key) { updateModifiers->AddUInt32("right_shift_key", fCurrentMap->right_shift_key); } if (fCurrentMap->left_control_key != fSavedMap->left_control_key) { updateModifiers->AddUInt32("left_control_key", fCurrentMap->left_control_key); } if (fCurrentMap->right_control_key != fSavedMap->right_control_key) { updateModifiers->AddUInt32("right_control_key", fCurrentMap->right_control_key); } if (fCurrentMap->left_option_key != fSavedMap->left_option_key) { updateModifiers->AddUInt32("left_option_key", fCurrentMap->left_option_key); } if (fCurrentMap->right_option_key != fSavedMap->right_option_key) { updateModifiers->AddUInt32("right_option_key", fCurrentMap->right_option_key); } if (fCurrentMap->left_command_key != fSavedMap->left_command_key) { updateModifiers->AddUInt32("left_command_key", fCurrentMap->left_command_key); } if (fCurrentMap->right_command_key != fSavedMap->right_command_key) { updateModifiers->AddUInt32("right_command_key", fCurrentMap->right_command_key); } // KeymapWindow updates the modifiers be_app->PostMessage(updateModifiers); // we are done here, close the window this->PostMessage(B_QUIT_REQUESTED); break; } // Revert button case kMsgRevertModifiers: memcpy(fCurrentMap, fSavedMap, sizeof(key_map)); _MarkMenuItems(); _ValidateDuplicateKeys(); _HideShowIcons(); fRevertButton->SetEnabled(false); break; default: BWindow::MessageReceived(message); } }