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:
parent
26a23118e7
commit
bd336e3abc
@ -12,10 +12,9 @@
|
||||
|
||||
#include <DataIO.h>
|
||||
#include <InterfaceDefs.h>
|
||||
#include <ObjectList.h>
|
||||
|
||||
|
||||
class BList;
|
||||
|
||||
class BKeymap {
|
||||
public:
|
||||
BKeymap();
|
||||
@ -40,9 +39,9 @@ public:
|
||||
void GetChars(uint32 keyCode, uint32 modifiers,
|
||||
uint8 activeDeadKey, char** chars,
|
||||
int32* numBytes) const;
|
||||
status_t GetModifiedCharacters(const char* normal,
|
||||
int32 modifiers,
|
||||
BList* _modifiedCharacters);
|
||||
status_t GetModifiedCharacters(const char* in,
|
||||
int32 inModifiers, int32 outModifiers,
|
||||
BObjectList<const char>* _outList);
|
||||
|
||||
const key_map& Map() const { return fKeys; }
|
||||
|
||||
|
@ -50,6 +50,7 @@
|
||||
#include <Keymap.h>
|
||||
#include <LayoutBuilder.h>
|
||||
#include <Locale.h>
|
||||
#include <ObjectList.h>
|
||||
#include <MenuBar.h>
|
||||
#include <MenuItem.h>
|
||||
#include <MessageRunner.h>
|
||||
@ -63,6 +64,7 @@
|
||||
#include <StatusBar.h>
|
||||
#include <StringView.h>
|
||||
#include <TextControl.h>
|
||||
#include <UnicodeChar.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
@ -612,22 +614,20 @@ BrowserWindow::BrowserWindow(BRect frame, SettingsMessage* appSettings,
|
||||
|
||||
BKeymap keymap;
|
||||
keymap.SetToCurrent();
|
||||
BList shiftChars;
|
||||
if (keymap.GetModifiedCharacters("=", B_SHIFT_KEY, &shiftChars)
|
||||
BObjectList<const char> unmodified(3, true);
|
||||
if (keymap.GetModifiedCharacters("+", B_SHIFT_KEY, 0, &unmodified)
|
||||
== B_OK) {
|
||||
int32 count = shiftChars.CountItems();
|
||||
int32 count = unmodified.CountItems();
|
||||
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
|
||||
AddShortcut('=', B_COMMAND_KEY,
|
||||
AddShortcut(key, B_COMMAND_KEY,
|
||||
new BMessage(ZOOM_FACTOR_INCREASE));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (!shiftChars.IsEmpty())
|
||||
delete (const char*)shiftChars.RemoveItem((int32)0);
|
||||
shiftChars.MakeEmpty();
|
||||
unmodified.MakeEmpty();
|
||||
|
||||
be_app->PostMessage(WINDOW_OPENED);
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
#include <ByteOrder.h>
|
||||
#include <File.h>
|
||||
#include <List.h>
|
||||
|
||||
|
||||
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
|
||||
# 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
|
||||
BKeymap::GetModifiedCharacters(const char* normal, int32 modifiers,
|
||||
BList* _modifiedCharacters)
|
||||
BKeymap::GetModifiedCharacters(const char* in, int32 inModifiers,
|
||||
int32 outModifiers, BObjectList<const char>* _outList)
|
||||
{
|
||||
if (normal == NULL || strcmp(normal, "") == 0
|
||||
|| _modifiedCharacters == NULL) {
|
||||
if (in == NULL || *in == '\0' || _outList == NULL)
|
||||
return B_BAD_VALUE;
|
||||
}
|
||||
|
||||
int32 normalOffset;
|
||||
int32 modifiedOffset;
|
||||
int32 inOffset;
|
||||
int32 outOffset;
|
||||
|
||||
for(uint32 i = 0; i < 128; i++) {
|
||||
normalOffset = fKeys.normal_map[i];
|
||||
size_t sizeNormal = fChars[normalOffset++];
|
||||
if (sizeNormal == 0
|
||||
|| memcmp(normal, fChars + normalOffset, sizeNormal) != 0) {
|
||||
if (inModifiers == 0)
|
||||
inOffset = fKeys.normal_map[i];
|
||||
else if (inModifiers == B_SHIFT_KEY)
|
||||
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
|
||||
continue;
|
||||
}
|
||||
|
||||
if (modifiers == B_SHIFT_KEY)
|
||||
modifiedOffset = fKeys.shift_map[i];
|
||||
else if (modifiers == B_CONTROL_KEY)
|
||||
modifiedOffset = fKeys.control_map[i];
|
||||
else if (modifiers == B_OPTION_KEY)
|
||||
modifiedOffset = fKeys.option_map[i];
|
||||
else if (modifiers == (B_OPTION_KEY | B_SHIFT_KEY))
|
||||
modifiedOffset = fKeys.option_shift_map[i];
|
||||
else if (modifiers == B_CAPS_LOCK)
|
||||
modifiedOffset = fKeys.caps_map[i];
|
||||
else if (modifiers == (B_CAPS_LOCK | B_SHIFT_KEY))
|
||||
modifiedOffset = fKeys.caps_shift_map[i];
|
||||
else if (modifiers == (B_OPTION_KEY | B_CAPS_LOCK))
|
||||
modifiedOffset = fKeys.option_caps_map[i];
|
||||
else if (modifiers == (B_OPTION_KEY | B_CAPS_LOCK | B_SHIFT_KEY))
|
||||
modifiedOffset = fKeys.option_caps_shift_map[i];
|
||||
if (outModifiers == 0)
|
||||
outOffset = fKeys.normal_map[i];
|
||||
else if (outModifiers == B_SHIFT_KEY)
|
||||
outOffset = fKeys.shift_map[i];
|
||||
else if (outModifiers == B_CONTROL_KEY)
|
||||
outOffset = fKeys.control_map[i];
|
||||
else if (outModifiers == B_OPTION_KEY)
|
||||
outOffset = fKeys.option_map[i];
|
||||
else if (outModifiers == (B_OPTION_KEY | B_SHIFT_KEY))
|
||||
outOffset = fKeys.option_shift_map[i];
|
||||
else if (outModifiers == B_CAPS_LOCK)
|
||||
outOffset = fKeys.caps_map[i];
|
||||
else if (outModifiers == (B_CAPS_LOCK | B_SHIFT_KEY))
|
||||
outOffset = fKeys.caps_shift_map[i];
|
||||
else if (outModifiers == (B_OPTION_KEY | B_CAPS_LOCK))
|
||||
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
|
||||
return B_BAD_VALUE;
|
||||
|
||||
size_t sizeModified = fChars[modifiedOffset++];
|
||||
char* modified = (char*)malloc(sizeModified + 1);
|
||||
if (modified == NULL)
|
||||
size_t sizeOut = fChars[outOffset++];
|
||||
char* out = (char*)malloc(sizeOut + 1);
|
||||
if (out == NULL)
|
||||
return B_NO_MEMORY;
|
||||
|
||||
memcpy(modified, fChars + modifiedOffset, sizeModified);
|
||||
modified[sizeModified] = '\0';
|
||||
_modifiedCharacters->AddItem(modified);
|
||||
memcpy(out, fChars + outOffset, sizeOut);
|
||||
out[sizeOut] = '\0';
|
||||
|
||||
_outList->AddItem((const char*)out);
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
|
@ -53,6 +53,7 @@ All rights reserved.
|
||||
#include <Path.h>
|
||||
#include <PopUpMenu.h>
|
||||
#include <Screen.h>
|
||||
#include <UnicodeChar.h>
|
||||
#include <Volume.h>
|
||||
#include <VolumeRoster.h>
|
||||
#include <Roster.h>
|
||||
@ -937,26 +938,6 @@ BContainerWindow::Init(const BMessage* message)
|
||||
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();
|
||||
AddShortcut('T', B_COMMAND_KEY | B_SHIFT_KEY, new BMessage(kDelete),
|
||||
PoseView());
|
||||
@ -982,6 +963,24 @@ BContainerWindow::Init(const BMessage* message)
|
||||
new BMessage('dpfL'), PoseView());
|
||||
#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)
|
||||
RestoreState(*message);
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user