Implemented the style changes and other improvements suggested by Axel to the Keymap preference app Modifier Keys window. The number of lines of code in the class was significantly reduced by these changes. I also made one small change to change the window title from 'Modifers Keys' to 'Modifier Keys'.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43221 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
John Scipione
2011-11-08 06:47:31 +00:00
parent 98f88d29c4
commit bce949f531
5 changed files with 183 additions and 255 deletions
+3 -2
View File
@@ -12,8 +12,9 @@
KeymapApplication::KeymapApplication() KeymapApplication::KeymapApplication()
: BApplication("application/x-vnd.Haiku-Keymap"), :
fModifierKeysWindow(NULL) BApplication("application/x-vnd.Haiku-Keymap"),
fModifierKeysWindow(NULL)
{ {
// create the window // create the window
fWindow = new KeymapWindow(); fWindow = new KeymapWindow();
+2 -1
View File
@@ -12,13 +12,14 @@
#include "KeymapWindow.h" #include "KeymapWindow.h"
#include "ModifierKeysWindow.h"
#include <Application.h> #include <Application.h>
#include <Catalog.h> #include <Catalog.h>
#include <Entry.h> #include <Entry.h>
#include <Locale.h> #include <Locale.h>
#include "ModifierKeysWindow.h"
static const uint32 kMsgShowModifierKeysWindow = 'smkw'; static const uint32 kMsgShowModifierKeysWindow = 'smkw';
static const uint32 kMsgCloseModifierKeysWindow = 'hmkw'; static const uint32 kMsgCloseModifierKeysWindow = 'hmkw';
+1 -1
View File
@@ -418,7 +418,7 @@ KeymapWindow::_CreateMenu()
new BMessage(kMsgMenuFileSaveAs))); new BMessage(kMsgMenuFileSaveAs)));
menu->AddSeparatorItem(); menu->AddSeparatorItem();
menu->AddItem(new BMenuItem( menu->AddItem(new BMenuItem(
B_TRANSLATE("Set Modifiers Keys" B_UTF8_ELLIPSIS), B_TRANSLATE("Set Modifier Keys" B_UTF8_ELLIPSIS),
new BMessage(kMsgShowModifierKeysWindow))); new BMessage(kMsgShowModifierKeysWindow)));
menu->AddSeparatorItem(); menu->AddSeparatorItem();
menu->AddItem(new BMenuItem(B_TRANSLATE("Quit"), menu->AddItem(new BMenuItem(B_TRANSLATE("Quit"),
+174 -250
View File
@@ -6,6 +6,7 @@
* John Scipione, [email protected] * John Scipione, [email protected]
*/ */
#include "ModifierKeysWindow.h" #include "ModifierKeysWindow.h"
#include <stdio.h> #include <stdio.h>
@@ -25,8 +26,9 @@
#include "KeymapApplication.h" #include "KeymapApplication.h"
enum { enum {
MENU_ITEM_CAPS_LOCK, MENU_ITEM_CAPS_LOCK = 0,
MENU_ITEM_CONTROL, MENU_ITEM_CONTROL,
MENU_ITEM_OPTION, MENU_ITEM_OPTION,
MENU_ITEM_COMMAND, MENU_ITEM_COMMAND,
@@ -34,40 +36,20 @@ enum {
MENU_ITEM_DISABLED MENU_ITEM_DISABLED
}; };
#undef B_TRANSLATE_CONTEXT static const uint32 kMsgUpdateModifier = 'upmd';
#define B_TRANSLATE_CONTEXT "Modifier keys window"
static const uint32 kMsgCapsLockCapsLock = 'clcl';
static const uint32 kMsgCapsLockControl = 'clct';
static const uint32 kMsgCapsLockOption = 'clop';
static const uint32 kMsgCapsLockCommand = 'clcm';
static const uint32 kMsgCapsLockDisabled = 'clds';
static const uint32 kMsgControlCapsLock = 'ctcl';
static const uint32 kMsgControlControl = 'ctct';
static const uint32 kMsgControlOption = 'ctop';
static const uint32 kMsgControlCommand = 'ctcm';
static const uint32 kMsgOptionCapsLock = 'opcl';
static const uint32 kMsgOptionControl = 'opct';
static const uint32 kMsgOptionOption = 'opop';
static const uint32 kMsgOptionCommand = 'opcm';
static const uint32 kMsgCommmandCapsLock = 'cmcl';
static const uint32 kMsgCommmandControl = 'cmct';
static const uint32 kMsgCommmandOption = 'cmop';
static const uint32 kMsgCommmandCommand = 'cmcm';
static const uint32 kMsgApplyModifiers = 'apmd'; static const uint32 kMsgApplyModifiers = 'apmd';
static const uint32 kMsgRevertModifiers = 'rvmd'; static const uint32 kMsgRevertModifiers = 'rvmd';
#undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "Modifier Keys window"
ModifierKeysWindow::ModifierKeysWindow() ModifierKeysWindow::ModifierKeysWindow()
: :
BWindow(BRect(80, 50, 400, 260), B_TRANSLATE("Modifiers Keys"), BWindow(BRect(80, 50, 400, 260), B_TRANSLATE("Modifier Keys"),
B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE
| B_AUTO_UPDATE_SIZE_LIMITS) | B_AUTO_UPDATE_SIZE_LIMITS)
{ {
get_key_map(&fCurrentMap, &fCurrentBuffer); get_key_map(&fCurrentMap, &fCurrentBuffer);
get_key_map(&fSavedMap, &fSavedBuffer); get_key_map(&fSavedMap, &fSavedBuffer);
@@ -130,8 +112,6 @@ ModifierKeysWindow::ModifierKeysWindow()
.SetInsets(10, 10, 10, 10) .SetInsets(10, 10, 10, 10)
); );
_MarkMenuItems();
CenterOnScreen(); CenterOnScreen();
} }
@@ -146,120 +126,68 @@ void
ModifierKeysWindow::MessageReceived(BMessage* message) ModifierKeysWindow::MessageReceived(BMessage* message)
{ {
switch (message->what) { switch (message->what) {
// Caps Lock case kMsgUpdateModifier:
case kMsgCapsLockCapsLock: {
fCurrentMap->caps_key = 0x3b; int32 menu = MENU_ITEM_CAPS_LOCK;
fCapsLockMenu->ItemAt(MENU_ITEM_CAPS_LOCK)->SetMarked(true); int32 key = -1;
_EnableRevertButton();
break;
case kMsgCapsLockControl: for (; menu <= MENU_ITEM_COMMAND; menu++) {
fCurrentMap->caps_key = 0x5c; if (message->FindInt32(_KeyToString(menu), &key) == B_OK)
fCapsLockMenu->ItemAt(MENU_ITEM_CONTROL)->SetMarked(true); break;
_EnableRevertButton(); }
break;
case kMsgCapsLockOption: if (key == -1) {
fCurrentMap->caps_key = 0x66; // No option was found, don't update
fCapsLockMenu->ItemAt(MENU_ITEM_OPTION)->SetMarked(true); return;
_EnableRevertButton(); }
break;
case kMsgCapsLockCommand: // Now 'menu' contains the menu we want to set and 'key' contains
fCurrentMap->caps_key = 0x5d; // the option we want to set it to.
fCapsLockMenu->ItemAt(MENU_ITEM_COMMAND)->SetMarked(true);
_EnableRevertButton();
break;
case kMsgCapsLockDisabled: switch (menu) {
fCurrentMap->caps_key = 0; case MENU_ITEM_CAPS_LOCK:
fCapsLockMenu->ItemAt(MENU_ITEM_DISABLED)->SetMarked(true); fCurrentMap->caps_key = _KeyToKeyCode(key);
_EnableRevertButton(); fCapsLockMenu->ItemAt(key)->SetMarked(true);
break; break;
// Control case MENU_ITEM_CONTROL:
case kMsgControlCapsLock: fCurrentMap->left_control_key
fCurrentMap->left_control_key = 0x3b; = _KeyToKeyCode(key);
fControlMenu->ItemAt(MENU_ITEM_CAPS_LOCK)->SetMarked(true); if (key != MENU_ITEM_CAPS_LOCK) {
_EnableRevertButton(); fCurrentMap->right_control_key
break; = _KeyToKeyCode(key, true);
}
case kMsgControlControl: fControlMenu->ItemAt(key)->SetMarked(true);
fCurrentMap->left_control_key = 0x5c; break;
fCurrentMap->right_control_key = 0x60;
fControlMenu->ItemAt(MENU_ITEM_CONTROL)->SetMarked(true);
_EnableRevertButton();
break;
case kMsgControlOption: case MENU_ITEM_OPTION:
fCurrentMap->left_control_key = 0x66; fCurrentMap->left_option_key
fCurrentMap->right_control_key = 0x67; = _KeyToKeyCode(key);
fControlMenu->ItemAt(MENU_ITEM_OPTION)->SetMarked(true); if (key != MENU_ITEM_CAPS_LOCK) {
_EnableRevertButton(); fCurrentMap->right_option_key
break; = _KeyToKeyCode(key, true);
}
case kMsgControlCommand: fOptionMenu->ItemAt(key)->SetMarked(true);
fCurrentMap->left_control_key = 0x5d; break;
fCurrentMap->right_control_key = 0x5f;
fControlMenu->ItemAt(MENU_ITEM_COMMAND)->SetMarked(true);
_EnableRevertButton();
break;
// Option case MENU_ITEM_COMMAND:
case kMsgOptionCapsLock: fCurrentMap->left_command_key
fCurrentMap->left_option_key = 0x3b; = _KeyToKeyCode(key);
fOptionMenu->ItemAt(MENU_ITEM_CAPS_LOCK)->SetMarked(true); if (key != MENU_ITEM_CAPS_LOCK) {
_EnableRevertButton(); fCurrentMap->right_command_key
break; = _KeyToKeyCode(key, true);
}
case kMsgOptionControl: fCommandMenu->ItemAt(key)->SetMarked(true);
fCurrentMap->left_option_key = 0x5c; break;
fCurrentMap->right_option_key = 0x60; }
fOptionMenu->ItemAt(MENU_ITEM_CONTROL)->SetMarked(true);
_EnableRevertButton();
break;
case kMsgOptionOption: fRevertButton->SetEnabled(memcmp(fCurrentMap, fSavedMap,
fCurrentMap->left_option_key = 0x66; sizeof(key_map)));
fCurrentMap->right_option_key = 0x67;
fOptionMenu->ItemAt(MENU_ITEM_OPTION)->SetMarked(true);
_EnableRevertButton();
break;
case kMsgOptionCommand:
fCurrentMap->left_option_key = 0x5d;
fCurrentMap->right_option_key = 0x5f;
fOptionMenu->ItemAt(MENU_ITEM_COMMAND)->SetMarked(true);
_EnableRevertButton();
break;
// Command
case kMsgCommmandCapsLock:
fCurrentMap->left_command_key = 0x3b;
fCommandMenu->ItemAt(MENU_ITEM_CAPS_LOCK)->SetMarked(true);
_EnableRevertButton();
break;
case kMsgCommmandControl:
fCurrentMap->left_command_key = 0x5c;
fCurrentMap->right_command_key = 0x60;
fCommandMenu->ItemAt(MENU_ITEM_CONTROL)->SetMarked(true);
_EnableRevertButton();
break;
case kMsgCommmandOption:
fCurrentMap->left_command_key = 0x66;
fCurrentMap->right_command_key = 0x67;
fCommandMenu->ItemAt(MENU_ITEM_OPTION)->SetMarked(true);
_EnableRevertButton();
break;
case kMsgCommmandCommand:
fCurrentMap->left_command_key = 0x5d;
fCurrentMap->right_command_key = 0x5f;
fCommandMenu->ItemAt(MENU_ITEM_COMMAND)->SetMarked(true);
_EnableRevertButton();
break; break;
}
// Ok button // Ok button
case kMsgApplyModifiers: case kMsgApplyModifiers:
@@ -301,20 +229,17 @@ ModifierKeysWindow::MessageReceived(BMessage* message)
fCurrentMap->right_command_key); fCurrentMap->right_command_key);
} }
// Tell KeymapWindow to update the modifier keys
be_app->PostMessage(updateModifiers); be_app->PostMessage(updateModifiers);
// We are done here, close the window
this->PostMessage(B_QUIT_REQUESTED); this->PostMessage(B_QUIT_REQUESTED);
break; break;
} }
// Revert button // Revert button
case kMsgRevertModifiers: case kMsgRevertModifiers:
fCurrentMap->caps_key = fSavedMap->caps_key; memcpy(fCurrentMap, fSavedMap, sizeof(key_map));
fCurrentMap->left_control_key = fSavedMap->left_control_key;
fCurrentMap->right_control_key = fSavedMap->right_control_key;
fCurrentMap->left_option_key = fSavedMap->left_option_key;
fCurrentMap->right_option_key = fSavedMap->right_option_key;
fCurrentMap->left_command_key = fSavedMap->left_command_key;
fCurrentMap->right_command_key = fSavedMap->right_command_key;
_MarkMenuItems(); _MarkMenuItems();
fRevertButton->SetEnabled(false); fRevertButton->SetEnabled(false);
@@ -329,30 +254,26 @@ ModifierKeysWindow::MessageReceived(BMessage* message)
BMenuField* BMenuField*
ModifierKeysWindow::_CreateCapsLockMenuField() ModifierKeysWindow::_CreateCapsLockMenuField()
{ {
fCapsLockMenu = new BPopUpMenu(B_TRANSLATE("Caps Lock"), true, true); fCapsLockMenu = new BPopUpMenu(
B_TRANSLATE(_KeyToString(MENU_ITEM_CAPS_LOCK)), true, true);
BMenuItem* capsLock = new BMenuItem(B_TRANSLATE("Caps Lock"), for (int32 key = MENU_ITEM_CAPS_LOCK; key <= MENU_ITEM_DISABLED; key++) {
new BMessage(kMsgCapsLockCapsLock)); if (key == MENU_ITEM_SEPERATOR) {
fCapsLockMenu->AddItem(capsLock, MENU_ITEM_CAPS_LOCK); BSeparatorItem* separator = new BSeparatorItem;
fCapsLockMenu->AddItem(separator, key);
} else {
BMessage* message = new BMessage(kMsgUpdateModifier);
message->AddInt32(_KeyToString(MENU_ITEM_CAPS_LOCK), key);
BMenuItem* control = new BMenuItem(B_TRANSLATE("Control"), BMenuItem* item = new BMenuItem(B_TRANSLATE(_KeyToString(key)),
new BMessage(kMsgCapsLockControl)); message);
fCapsLockMenu->AddItem(control, MENU_ITEM_CONTROL);
BMenuItem* option = new BMenuItem(B_TRANSLATE("Option"), if (fCurrentMap->caps_key == _KeyToKeyCode(key))
new BMessage(kMsgCapsLockOption)); item->SetMarked(true);
fCapsLockMenu->AddItem(option, MENU_ITEM_OPTION);
BMenuItem* command = new BMenuItem(B_TRANSLATE("Command"), fCapsLockMenu->AddItem(item, key);
new BMessage(kMsgCapsLockCommand)); }
fCapsLockMenu->AddItem(command, MENU_ITEM_COMMAND); }
BSeparatorItem* separator = new BSeparatorItem;
fCapsLockMenu->AddItem(separator, MENU_ITEM_SEPERATOR);
BMenuItem* disabled = new BMenuItem(B_TRANSLATE("Disabled"),
new BMessage(kMsgCapsLockDisabled));
fCapsLockMenu->AddItem(disabled, MENU_ITEM_DISABLED);
return new BMenuField(NULL, fCapsLockMenu); return new BMenuField(NULL, fCapsLockMenu);
} }
@@ -361,23 +282,21 @@ ModifierKeysWindow::_CreateCapsLockMenuField()
BMenuField* BMenuField*
ModifierKeysWindow::_CreateControlMenuField() ModifierKeysWindow::_CreateControlMenuField()
{ {
fControlMenu = new BPopUpMenu(B_TRANSLATE("Control"), true, true); fControlMenu = new BPopUpMenu(
B_TRANSLATE(_KeyToString(MENU_ITEM_CONTROL)), true, true);
BMenuItem* capsLock = new BMenuItem(B_TRANSLATE("Caps Lock"), for (int32 key = MENU_ITEM_CAPS_LOCK; key <= MENU_ITEM_COMMAND; key++) {
new BMessage(kMsgControlCapsLock)); BMessage* message = new BMessage(kMsgUpdateModifier);
fControlMenu->AddItem(capsLock, MENU_ITEM_CAPS_LOCK); message->AddInt32(_KeyToString(MENU_ITEM_CONTROL), key);
BMenuItem* control = new BMenuItem(B_TRANSLATE("Control"), BMenuItem* item = new BMenuItem(B_TRANSLATE(_KeyToString(key)),
new BMessage(kMsgControlControl)); message);
fControlMenu->AddItem(control, MENU_ITEM_CONTROL);
BMenuItem* option = new BMenuItem(B_TRANSLATE("Option"), if (fCurrentMap->left_control_key == _KeyToKeyCode(key))
new BMessage(kMsgControlOption)); item->SetMarked(true);
fControlMenu->AddItem(option, MENU_ITEM_OPTION);
BMenuItem* command = new BMenuItem(B_TRANSLATE("Command"), fControlMenu->AddItem(item, key);
new BMessage(kMsgControlCommand)); }
fControlMenu->AddItem(command, MENU_ITEM_COMMAND);
return new BMenuField(NULL, fControlMenu); return new BMenuField(NULL, fControlMenu);
} }
@@ -386,23 +305,21 @@ ModifierKeysWindow::_CreateControlMenuField()
BMenuField* BMenuField*
ModifierKeysWindow::_CreateOptionMenuField() ModifierKeysWindow::_CreateOptionMenuField()
{ {
fOptionMenu = new BPopUpMenu(B_TRANSLATE("Option"), true, true); fOptionMenu = new BPopUpMenu(
B_TRANSLATE(_KeyToString(MENU_ITEM_OPTION)), true, true);
BMenuItem* capsLock = new BMenuItem(B_TRANSLATE("Caps Lock"), for (int32 key = MENU_ITEM_CAPS_LOCK; key <= MENU_ITEM_COMMAND; key++) {
new BMessage(kMsgOptionCapsLock)); BMessage* message = new BMessage(kMsgUpdateModifier);
fOptionMenu->AddItem(capsLock, MENU_ITEM_CAPS_LOCK); message->AddInt32(_KeyToString(MENU_ITEM_OPTION), key);
BMenuItem* control = new BMenuItem(B_TRANSLATE("Control"), BMenuItem* item = new BMenuItem(B_TRANSLATE(_KeyToString(key)),
new BMessage(kMsgOptionControl)); message);
fOptionMenu->AddItem(control, MENU_ITEM_CONTROL);
BMenuItem* option = new BMenuItem(B_TRANSLATE("Option"), if (fCurrentMap->left_option_key == _KeyToKeyCode(key))
new BMessage(kMsgOptionOption)); item->SetMarked(true);
fOptionMenu->AddItem(option, MENU_ITEM_OPTION);
BMenuItem* command = new BMenuItem(B_TRANSLATE("Command"), fOptionMenu->AddItem(item, key);
new BMessage(kMsgOptionCommand)); }
fOptionMenu->AddItem(command, MENU_ITEM_COMMAND);
return new BMenuField(NULL, fOptionMenu); return new BMenuField(NULL, fOptionMenu);
} }
@@ -411,23 +328,21 @@ ModifierKeysWindow::_CreateOptionMenuField()
BMenuField* BMenuField*
ModifierKeysWindow::_CreateCommandMenuField() ModifierKeysWindow::_CreateCommandMenuField()
{ {
fCommandMenu = new BPopUpMenu(B_TRANSLATE("Command"), true, true); fCommandMenu = new BPopUpMenu(
B_TRANSLATE(_KeyToString(MENU_ITEM_COMMAND)), true, true);
BMenuItem* capsLock = new BMenuItem(B_TRANSLATE("Caps Lock"), for (int32 key = MENU_ITEM_CAPS_LOCK; key <= MENU_ITEM_COMMAND; key++) {
new BMessage(kMsgCommmandCapsLock)); BMessage* message = new BMessage(kMsgUpdateModifier);
fCommandMenu->AddItem(capsLock, MENU_ITEM_CAPS_LOCK); message->AddInt32(_KeyToString(MENU_ITEM_COMMAND), key);
BMenuItem* control = new BMenuItem(B_TRANSLATE("Control"), BMenuItem* item = new BMenuItem(B_TRANSLATE(_KeyToString(key)),
new BMessage(kMsgCommmandControl)); message);
fCommandMenu->AddItem(control, MENU_ITEM_CONTROL);
BMenuItem* option = new BMenuItem(B_TRANSLATE("Option"), if (fCurrentMap->left_command_key == _KeyToKeyCode(key))
new BMessage(kMsgCommmandOption)); item->SetMarked(true);
fCommandMenu->AddItem(option, MENU_ITEM_OPTION);
BMenuItem* command = new BMenuItem(B_TRANSLATE("Command"), fCommandMenu->AddItem(item, key);
new BMessage(kMsgCommmandCommand)); }
fCommandMenu->AddItem(command, MENU_ITEM_COMMAND);
return new BMenuField(NULL, fCommandMenu); return new BMenuField(NULL, fCommandMenu);
} }
@@ -436,61 +351,70 @@ ModifierKeysWindow::_CreateCommandMenuField()
void void
ModifierKeysWindow::_MarkMenuItems() ModifierKeysWindow::_MarkMenuItems()
{ {
// Caps Lock Menu for (int32 key = MENU_ITEM_CAPS_LOCK; key <= MENU_ITEM_COMMAND; key++) {
if (fCurrentMap->caps_key == 0x3b) if (fCurrentMap->caps_key == _KeyToKeyCode(key))
fCapsLockMenu->ItemAt(MENU_ITEM_CAPS_LOCK)->SetMarked(true); fCapsLockMenu->ItemAt(key)->SetMarked(true);
else if (fCurrentMap->caps_key == 0x5c)
fCapsLockMenu->ItemAt(MENU_ITEM_CONTROL)->SetMarked(true); if (fCurrentMap->left_control_key == _KeyToKeyCode(key)
else if (fCurrentMap->caps_key == 0x66) && fCurrentMap->right_control_key == _KeyToKeyCode(key, true))
fCapsLockMenu->ItemAt(MENU_ITEM_OPTION)->SetMarked(true); fControlMenu->ItemAt(key)->SetMarked(true);
else if (fCurrentMap->caps_key == 0x5d)
fCapsLockMenu->ItemAt(MENU_ITEM_COMMAND)->SetMarked(true); if (fCurrentMap->left_option_key == _KeyToKeyCode(key)
else if (fCurrentMap->caps_key == 0) && 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);
}
// Check if caps lock is disabled
if (fCurrentMap->caps_key == _KeyToKeyCode(MENU_ITEM_DISABLED))
fCapsLockMenu->ItemAt(MENU_ITEM_DISABLED)->SetMarked(true); fCapsLockMenu->ItemAt(MENU_ITEM_DISABLED)->SetMarked(true);
// Control Menu
if (fCurrentMap->left_control_key == 0x3b)
fControlMenu->ItemAt(MENU_ITEM_CAPS_LOCK)->SetMarked(true);
else if (fCurrentMap->left_control_key == 0x5c)
fControlMenu->ItemAt(MENU_ITEM_CONTROL)->SetMarked(true);
else if (fCurrentMap->left_control_key == 0x66)
fControlMenu->ItemAt(MENU_ITEM_OPTION)->SetMarked(true);
else if (fCurrentMap->left_control_key == 0x5d)
fControlMenu->ItemAt(MENU_ITEM_COMMAND)->SetMarked(true);
// Option Menu
if (fCurrentMap->left_option_key == 0x3b)
fOptionMenu->ItemAt(MENU_ITEM_CAPS_LOCK)->SetMarked(true);
else if (fCurrentMap->left_option_key == 0x5c)
fOptionMenu->ItemAt(MENU_ITEM_CONTROL)->SetMarked(true);
else if (fCurrentMap->left_option_key == 0x66)
fOptionMenu->ItemAt(MENU_ITEM_OPTION)->SetMarked(true);
else if (fCurrentMap->left_option_key == 0x5d)
fOptionMenu->ItemAt(MENU_ITEM_COMMAND)->SetMarked(true);
// Command menu
if (fCurrentMap->left_command_key == 0x3b)
fCommandMenu->ItemAt(MENU_ITEM_CAPS_LOCK)->SetMarked(true);
else if (fCurrentMap->left_command_key == 0x5c)
fCommandMenu->ItemAt(MENU_ITEM_CONTROL)->SetMarked(true);
else if (fCurrentMap->left_command_key == 0x66)
fCommandMenu->ItemAt(MENU_ITEM_OPTION)->SetMarked(true);
else if (fCurrentMap->left_command_key == 0x5d)
fCommandMenu->ItemAt(MENU_ITEM_COMMAND)->SetMarked(true);
} }
void const char*
ModifierKeysWindow::_EnableRevertButton() ModifierKeysWindow::_KeyToString(int32 key)
{ {
if (fCurrentMap->caps_key != fSavedMap->caps_key switch (key) {
|| fCurrentMap->left_control_key != fSavedMap->left_control_key case MENU_ITEM_CAPS_LOCK:
|| fCurrentMap->right_control_key != fSavedMap->right_control_key return "Caps Lock";
|| fCurrentMap->left_option_key != fSavedMap->left_option_key case MENU_ITEM_CONTROL:
|| fCurrentMap->right_option_key != fSavedMap->right_option_key return "Control";
|| fCurrentMap->left_command_key != fSavedMap->left_command_key case MENU_ITEM_OPTION:
|| fCurrentMap->right_command_key != fSavedMap->right_command_key) return "Option";
fRevertButton->SetEnabled(true); case MENU_ITEM_COMMAND:
else return "Command";
fRevertButton->SetEnabled(false); case MENU_ITEM_DISABLED:
return "Disabled";
}
return "";
}
uint32
ModifierKeysWindow::_KeyToKeyCode(int32 key, bool right = false)
{
switch (key) {
case MENU_ITEM_CAPS_LOCK:
return 0x3b;
case MENU_ITEM_CONTROL:
if (right)
return 0x60;
return 0x5c;
case MENU_ITEM_OPTION:
if (right)
return 0x67;
return 0x66;
case MENU_ITEM_COMMAND:
if (right)
return 0x5f;
return 0x5d;
case MENU_ITEM_DISABLED:
return 0;
}
return 0;
} }
+3 -1
View File
@@ -30,7 +30,8 @@ protected:
BMenuField* _CreateCommandMenuField(); BMenuField* _CreateCommandMenuField();
void _MarkMenuItems(); void _MarkMenuItems();
void _EnableRevertButton(); const char* _KeyToString(int32 key);
uint32 _KeyToKeyCode(int32 key, bool right = false);
private: private:
BPopUpMenu* fCapsLockMenu; BPopUpMenu* fCapsLockMenu;
@@ -49,4 +50,5 @@ private:
char* fSavedBuffer; char* fSavedBuffer;
}; };
#endif // MODIFIER_KEYS_WINDOW_H #endif // MODIFIER_KEYS_WINDOW_H