Update semantic shortcuts
Update BKeymap::GetModifiedCharacters() to translate a given character and set of modifiers filling out a list of all characters that match for another set of modifiers. This allows us to, for example, get all characters in the normal map that have the '+' character in the corresponding shift map. It is fully generic allowing one to get a list of characters in any map given a character and modifiers of another map. Also I converted from using a BList to using a BObjectList. With this, along with BWindow::HasShortcut(), the semantic shortcuts now work not only with Command+'=', but any key in the normal map that has '+' in it's shift map as long as it isn't already taken by another shortcut.
This commit is contained in:
@@ -12,10 +12,9 @@
|
|||||||
|
|
||||||
#include <DataIO.h>
|
#include <DataIO.h>
|
||||||
#include <InterfaceDefs.h>
|
#include <InterfaceDefs.h>
|
||||||
|
#include <ObjectList.h>
|
||||||
|
|
||||||
|
|
||||||
class BList;
|
|
||||||
|
|
||||||
class BKeymap {
|
class BKeymap {
|
||||||
public:
|
public:
|
||||||
BKeymap();
|
BKeymap();
|
||||||
@@ -40,9 +39,9 @@ public:
|
|||||||
void GetChars(uint32 keyCode, uint32 modifiers,
|
void GetChars(uint32 keyCode, uint32 modifiers,
|
||||||
uint8 activeDeadKey, char** chars,
|
uint8 activeDeadKey, char** chars,
|
||||||
int32* numBytes) const;
|
int32* numBytes) const;
|
||||||
status_t GetModifiedCharacters(const char* normal,
|
status_t GetModifiedCharacters(const char* in,
|
||||||
int32 modifiers,
|
int32 inModifiers, int32 outModifiers,
|
||||||
BList* _modifiedCharacters);
|
BObjectList<const char>* _outList);
|
||||||
|
|
||||||
const key_map& Map() const { return fKeys; }
|
const key_map& Map() const { return fKeys; }
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,7 @@
|
|||||||
#include <Keymap.h>
|
#include <Keymap.h>
|
||||||
#include <LayoutBuilder.h>
|
#include <LayoutBuilder.h>
|
||||||
#include <Locale.h>
|
#include <Locale.h>
|
||||||
|
#include <ObjectList.h>
|
||||||
#include <MenuBar.h>
|
#include <MenuBar.h>
|
||||||
#include <MenuItem.h>
|
#include <MenuItem.h>
|
||||||
#include <MessageRunner.h>
|
#include <MessageRunner.h>
|
||||||
@@ -63,6 +64,7 @@
|
|||||||
#include <StatusBar.h>
|
#include <StatusBar.h>
|
||||||
#include <StringView.h>
|
#include <StringView.h>
|
||||||
#include <TextControl.h>
|
#include <TextControl.h>
|
||||||
|
#include <UnicodeChar.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
@@ -612,22 +614,20 @@ BrowserWindow::BrowserWindow(BRect frame, SettingsMessage* appSettings,
|
|||||||
|
|
||||||
BKeymap keymap;
|
BKeymap keymap;
|
||||||
keymap.SetToCurrent();
|
keymap.SetToCurrent();
|
||||||
BList shiftChars;
|
BObjectList<const char> unmodified(3, true);
|
||||||
if (keymap.GetModifiedCharacters("=", B_SHIFT_KEY, &shiftChars)
|
if (keymap.GetModifiedCharacters("+", B_SHIFT_KEY, 0, &unmodified)
|
||||||
== B_OK) {
|
== B_OK) {
|
||||||
int32 count = shiftChars.CountItems();
|
int32 count = unmodified.CountItems();
|
||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
if (strcmp((const char*)shiftChars.ItemAt(i), "+") == 0) {
|
uint32 key = BUnicodeChar::FromUTF8(unmodified.ItemAt(i));
|
||||||
|
if (!HasShortcut(key, 0)) {
|
||||||
// Add semantic zoom in shortcut, bug #7428
|
// Add semantic zoom in shortcut, bug #7428
|
||||||
AddShortcut('=', B_COMMAND_KEY,
|
AddShortcut(key, B_COMMAND_KEY,
|
||||||
new BMessage(ZOOM_FACTOR_INCREASE));
|
new BMessage(ZOOM_FACTOR_INCREASE));
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (!shiftChars.IsEmpty())
|
unmodified.MakeEmpty();
|
||||||
delete (const char*)shiftChars.RemoveItem((int32)0);
|
|
||||||
shiftChars.MakeEmpty();
|
|
||||||
|
|
||||||
be_app->PostMessage(WINDOW_OPENED);
|
be_app->PostMessage(WINDOW_OPENED);
|
||||||
}
|
}
|
||||||
|
|||||||
+57
-34
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#include <ByteOrder.h>
|
#include <ByteOrder.h>
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <List.h>
|
|
||||||
|
|
||||||
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
|
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
|
||||||
# include "SystemKeymap.h"
|
# include "SystemKeymap.h"
|
||||||
@@ -442,54 +442,77 @@ BKeymap::GetChars(uint32 keyCode, uint32 modifiers, uint8 activeDeadKey,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! Get a list of characters translated from a given character and
|
||||||
|
set of modifiers to another set of modifiers.
|
||||||
|
*/
|
||||||
status_t
|
status_t
|
||||||
BKeymap::GetModifiedCharacters(const char* normal, int32 modifiers,
|
BKeymap::GetModifiedCharacters(const char* in, int32 inModifiers,
|
||||||
BList* _modifiedCharacters)
|
int32 outModifiers, BObjectList<const char>* _outList)
|
||||||
{
|
{
|
||||||
if (normal == NULL || strcmp(normal, "") == 0
|
if (in == NULL || *in == '\0' || _outList == NULL)
|
||||||
|| _modifiedCharacters == NULL) {
|
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
}
|
|
||||||
|
|
||||||
int32 normalOffset;
|
int32 inOffset;
|
||||||
int32 modifiedOffset;
|
int32 outOffset;
|
||||||
|
|
||||||
for(uint32 i = 0; i < 128; i++) {
|
for(uint32 i = 0; i < 128; i++) {
|
||||||
normalOffset = fKeys.normal_map[i];
|
if (inModifiers == 0)
|
||||||
size_t sizeNormal = fChars[normalOffset++];
|
inOffset = fKeys.normal_map[i];
|
||||||
if (sizeNormal == 0
|
else if (inModifiers == B_SHIFT_KEY)
|
||||||
|| memcmp(normal, fChars + normalOffset, sizeNormal) != 0) {
|
inOffset = fKeys.shift_map[i];
|
||||||
|
else if (inModifiers == B_CONTROL_KEY)
|
||||||
|
inOffset = fKeys.control_map[i];
|
||||||
|
else if (inModifiers == B_OPTION_KEY)
|
||||||
|
inOffset = fKeys.option_map[i];
|
||||||
|
else if (inModifiers == (B_OPTION_KEY | B_SHIFT_KEY))
|
||||||
|
inOffset = fKeys.option_shift_map[i];
|
||||||
|
else if (inModifiers == B_CAPS_LOCK)
|
||||||
|
inOffset = fKeys.caps_map[i];
|
||||||
|
else if (inModifiers == (B_CAPS_LOCK | B_SHIFT_KEY))
|
||||||
|
inOffset = fKeys.caps_shift_map[i];
|
||||||
|
else if (inModifiers == (B_OPTION_KEY | B_CAPS_LOCK))
|
||||||
|
inOffset = fKeys.option_caps_map[i];
|
||||||
|
else if (inModifiers == (B_OPTION_KEY | B_CAPS_LOCK | B_SHIFT_KEY))
|
||||||
|
inOffset = fKeys.option_caps_shift_map[i];
|
||||||
|
else
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
size_t sizeIn = fChars[inOffset++];
|
||||||
|
if (sizeIn == 0 || memcmp(in, fChars + inOffset, sizeIn) != 0) {
|
||||||
// this character isn't mapped or doesn't match
|
// this character isn't mapped or doesn't match
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (modifiers == B_SHIFT_KEY)
|
if (outModifiers == 0)
|
||||||
modifiedOffset = fKeys.shift_map[i];
|
outOffset = fKeys.normal_map[i];
|
||||||
else if (modifiers == B_CONTROL_KEY)
|
else if (outModifiers == B_SHIFT_KEY)
|
||||||
modifiedOffset = fKeys.control_map[i];
|
outOffset = fKeys.shift_map[i];
|
||||||
else if (modifiers == B_OPTION_KEY)
|
else if (outModifiers == B_CONTROL_KEY)
|
||||||
modifiedOffset = fKeys.option_map[i];
|
outOffset = fKeys.control_map[i];
|
||||||
else if (modifiers == (B_OPTION_KEY | B_SHIFT_KEY))
|
else if (outModifiers == B_OPTION_KEY)
|
||||||
modifiedOffset = fKeys.option_shift_map[i];
|
outOffset = fKeys.option_map[i];
|
||||||
else if (modifiers == B_CAPS_LOCK)
|
else if (outModifiers == (B_OPTION_KEY | B_SHIFT_KEY))
|
||||||
modifiedOffset = fKeys.caps_map[i];
|
outOffset = fKeys.option_shift_map[i];
|
||||||
else if (modifiers == (B_CAPS_LOCK | B_SHIFT_KEY))
|
else if (outModifiers == B_CAPS_LOCK)
|
||||||
modifiedOffset = fKeys.caps_shift_map[i];
|
outOffset = fKeys.caps_map[i];
|
||||||
else if (modifiers == (B_OPTION_KEY | B_CAPS_LOCK))
|
else if (outModifiers == (B_CAPS_LOCK | B_SHIFT_KEY))
|
||||||
modifiedOffset = fKeys.option_caps_map[i];
|
outOffset = fKeys.caps_shift_map[i];
|
||||||
else if (modifiers == (B_OPTION_KEY | B_CAPS_LOCK | B_SHIFT_KEY))
|
else if (outModifiers == (B_OPTION_KEY | B_CAPS_LOCK))
|
||||||
modifiedOffset = fKeys.option_caps_shift_map[i];
|
outOffset = fKeys.option_caps_map[i];
|
||||||
|
else if (outModifiers == (B_OPTION_KEY | B_CAPS_LOCK | B_SHIFT_KEY))
|
||||||
|
outOffset = fKeys.option_caps_shift_map[i];
|
||||||
else
|
else
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
size_t sizeModified = fChars[modifiedOffset++];
|
size_t sizeOut = fChars[outOffset++];
|
||||||
char* modified = (char*)malloc(sizeModified + 1);
|
char* out = (char*)malloc(sizeOut + 1);
|
||||||
if (modified == NULL)
|
if (out == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
memcpy(modified, fChars + modifiedOffset, sizeModified);
|
memcpy(out, fChars + outOffset, sizeOut);
|
||||||
modified[sizeModified] = '\0';
|
out[sizeOut] = '\0';
|
||||||
_modifiedCharacters->AddItem(modified);
|
|
||||||
|
_outList->AddItem((const char*)out);
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ All rights reserved.
|
|||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <PopUpMenu.h>
|
#include <PopUpMenu.h>
|
||||||
#include <Screen.h>
|
#include <Screen.h>
|
||||||
|
#include <UnicodeChar.h>
|
||||||
#include <Volume.h>
|
#include <Volume.h>
|
||||||
#include <VolumeRoster.h>
|
#include <VolumeRoster.h>
|
||||||
#include <Roster.h>
|
#include <Roster.h>
|
||||||
@@ -937,26 +938,6 @@ BContainerWindow::Init(const BMessage* message)
|
|||||||
AddShortcuts();
|
AddShortcuts();
|
||||||
}
|
}
|
||||||
|
|
||||||
BKeymap keymap;
|
|
||||||
keymap.SetToCurrent();
|
|
||||||
BList shiftChars;
|
|
||||||
if (keymap.GetModifiedCharacters("=", B_SHIFT_KEY, &shiftChars)
|
|
||||||
== B_OK) {
|
|
||||||
int32 count = shiftChars.CountItems();
|
|
||||||
for (int32 i = 0; i < count; i++) {
|
|
||||||
if (strcmp((const char*)shiftChars.ItemAt(i), "+") == 0) {
|
|
||||||
// Add semantic zoom in shortcut, bug #6692
|
|
||||||
BMessage* increaseSize = new BMessage(kIconMode);
|
|
||||||
increaseSize->AddInt32("scale", 1);
|
|
||||||
AddShortcut('=', B_COMMAND_KEY, increaseSize, PoseView());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (!shiftChars.IsEmpty())
|
|
||||||
delete (const char*)shiftChars.RemoveItem((int32)0);
|
|
||||||
shiftChars.MakeEmpty();
|
|
||||||
|
|
||||||
AddContextMenus();
|
AddContextMenus();
|
||||||
AddShortcut('T', B_COMMAND_KEY | B_SHIFT_KEY, new BMessage(kDelete),
|
AddShortcut('T', B_COMMAND_KEY | B_SHIFT_KEY, new BMessage(kDelete),
|
||||||
PoseView());
|
PoseView());
|
||||||
@@ -982,6 +963,24 @@ BContainerWindow::Init(const BMessage* message)
|
|||||||
new BMessage('dpfL'), PoseView());
|
new BMessage('dpfL'), PoseView());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
BKeymap keymap;
|
||||||
|
keymap.SetToCurrent();
|
||||||
|
BObjectList<const char> unmodified(3, true);
|
||||||
|
if (keymap.GetModifiedCharacters("+", B_SHIFT_KEY, 0, &unmodified)
|
||||||
|
== B_OK) {
|
||||||
|
int32 count = unmodified.CountItems();
|
||||||
|
for (int32 i = 0; i < count; i++) {
|
||||||
|
uint32 key = BUnicodeChar::FromUTF8(unmodified.ItemAt(i));
|
||||||
|
if (!HasShortcut(key, 0)) {
|
||||||
|
// Add semantic zoom in shortcut, bug #6692
|
||||||
|
BMessage* increaseSize = new BMessage(kIconMode);
|
||||||
|
increaseSize->AddInt32("scale", 1);
|
||||||
|
AddShortcut(key, B_COMMAND_KEY, increaseSize, PoseView());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unmodified.MakeEmpty();
|
||||||
|
|
||||||
if (message)
|
if (message)
|
||||||
RestoreState(*message);
|
RestoreState(*message);
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user