[haiku-commits] haiku: hrev46262 - src/kits/shared src/kits/tracker src/apps/webpositive headers/private/shared

  • From: jscipione@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 20 Oct 2013 01:31:40 +0200 (CEST)

hrev46262 adds 2 changesets to branch 'master'
old head: 6180dde4986edcb33ac0e95b3a0963fe18ff939a
new head: bd336e3abc7e939d2db16cff48d4cb9a2fe0dc60
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=bd336e3+%5E6180dde

----------------------------------------------------------------------------

26a2311: BWindow: use Unicode lowercase method

bd336e3: 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.

                                     [ John Scipione <jscipione@xxxxxxxxx> ]

----------------------------------------------------------------------------

5 files changed, 91 insertions(+), 70 deletions(-)
headers/private/shared/Keymap.h        |  9 ++-
src/apps/webpositive/BrowserWindow.cpp | 18 +++---
src/kits/interface/Window.cpp          |  4 +-
src/kits/shared/Keymap.cpp             | 91 +++++++++++++++++++-----------
src/kits/tracker/ContainerWindow.cpp   | 39 +++++++------

############################################################################

Commit:      26a23118e7bf9378a31a9ea6f72db35e0777a484
URL:         http://cgit.haiku-os.org/haiku/commit/?id=26a2311
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Sat Oct 19 22:53:34 2013 UTC

BWindow: use Unicode lowercase method

----------------------------------------------------------------------------

diff --git a/src/kits/interface/Window.cpp b/src/kits/interface/Window.cpp
index b609353..0dd6335 100644
--- a/src/kits/interface/Window.cpp
+++ b/src/kits/interface/Window.cpp
@@ -32,6 +32,7 @@
 #include <Roster.h>
 #include <Screen.h>
 #include <String.h>
+#include <UnicodeChar.h>
 
 #include <AppMisc.h>
 #include <AppServerLink.h>
@@ -293,8 +294,7 @@ BWindow::Shortcut::PrepareModifiers(uint32 modifiers)
 uint32
 BWindow::Shortcut::PrepareKey(uint32 key)
 {
-       return tolower(key);
-               // TODO: support unicode and/or more intelligent key mapping
+       return BUnicodeChar::ToLower(key);
 }
 
 

############################################################################

Revision:    hrev46262
Commit:      bd336e3abc7e939d2db16cff48d4cb9a2fe0dc60
URL:         http://cgit.haiku-os.org/haiku/commit/?id=bd336e3
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Sat Oct 19 23:29:26 2013 UTC

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.

----------------------------------------------------------------------------

diff --git a/headers/private/shared/Keymap.h b/headers/private/shared/Keymap.h
index 37d9060..3a8c750 100644
--- a/headers/private/shared/Keymap.h
+++ b/headers/private/shared/Keymap.h
@@ -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; }
 
diff --git a/src/apps/webpositive/BrowserWindow.cpp 
b/src/apps/webpositive/BrowserWindow.cpp
index fa5b2b8..109056a 100644
--- a/src/apps/webpositive/BrowserWindow.cpp
+++ b/src/apps/webpositive/BrowserWindow.cpp
@@ -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);
 }
diff --git a/src/kits/shared/Keymap.cpp b/src/kits/shared/Keymap.cpp
index 1aab46b..8106d86 100644
--- a/src/kits/shared/Keymap.cpp
+++ b/src/kits/shared/Keymap.cpp
@@ -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;
diff --git a/src/kits/tracker/ContainerWindow.cpp 
b/src/kits/tracker/ContainerWindow.cpp
index d18eef7..294bca4 100644
--- a/src/kits/tracker/ContainerWindow.cpp
+++ b/src/kits/tracker/ContainerWindow.cpp
@@ -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


Other related posts:

  • » [haiku-commits] haiku: hrev46262 - src/kits/shared src/kits/tracker src/apps/webpositive headers/private/shared - jscipione