示例#1
0
// validate duplicate keys
void
ModifierKeysWindow::_ValidateDuplicateKeys()
{
    uint32 dupMask = _DuplicateKeys();

    BBitmap* shiftIcon = fShiftConflictView->Icon();
    BBitmap* controlIcon = fControlConflictView->Icon();
    BBitmap* optionIcon = fOptionConflictView->Icon();
    BBitmap* commandIcon = fCommandConflictView->Icon();

    if (dupMask != 0) {
        fShiftConflictView->ShowIcon((dupMask & SHIFT_KEY) != 0);
        fControlConflictView->ShowIcon((dupMask & CONTROL_KEY) != 0);
        fOptionConflictView->ShowIcon((dupMask & OPTION_KEY) != 0);
        fCommandConflictView->ShowIcon((dupMask & COMMAND_KEY) != 0);

        fOkButton->SetEnabled(false);
    } else {
        fShiftConflictView->ShowIcon(false);
        fControlConflictView->ShowIcon(false);
        fOptionConflictView->ShowIcon(false);
        fCommandConflictView->ShowIcon(false);

        fOkButton->SetEnabled(true);
    }

    // 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();
}
示例#2
0
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);
	}
}