Author: fendrin
Date: Thu Oct 27 01:59:08 2011
New Revision: 51664

URL: http://svn.gna.org/viewcvs/wesnoth?rev=51664&view=rev
Log:
Fix bug #17323

Modified:
    trunk/src/hotkeys.cpp
    trunk/src/hotkeys.hpp
    trunk/src/preferences_display.cpp

Modified: trunk/src/hotkeys.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/hotkeys.cpp?rev=51664&r1=51663&r2=51664&view=diff
==============================================================================
--- trunk/src/hotkeys.cpp (original)
+++ trunk/src/hotkeys.cpp Thu Oct 27 01:59:08 2011
@@ -324,7 +324,6 @@
        description_(description),
        scope_(s),
        type_(UNBOUND),
-       character_(0),
        ctrl_(false),
        alt_(false),
        cmd_(false),
@@ -372,8 +371,11 @@
 
        if (key == CLEARED_TEXT)
        {
-               type_ = hotkey_item::CLEARED;
+               type_ = CLEARED;
                return;
+       } else {
+               type_ = BY_KEYCODE;
+               keycode_ = sdl_keysym_from_name(key);
        }
 
        wide_string wkey = utils::string_to_wstring(key);
@@ -381,9 +383,6 @@
        // They may really want a specific key on the keyboard: we assume
        // that any single character keyname is a character.
        if (wkey.size() > 1) {
-               type_ = BY_KEYCODE;
-
-               keycode_ = sdl_keysym_from_name(key);
                if (keycode_ == SDLK_UNKNOWN) {
                        if (tolower(key[0]) != 'f') {
                                ERR_CF << "hotkey key '" << key << "' 
invalid\n";
@@ -405,24 +404,13 @@
                // files.
                type_ = BY_KEYCODE;
                keycode_ = wkey[0];
-       } else {
-               type_ = BY_CHARACTER;
-               character_ = wkey[0];
        }
 }
 
 std::string hotkey_item::get_name() const
 {
        std::stringstream str;
-       if (type_ == BY_CHARACTER) {
-               if (alt_)
-                       str << "alt+";
-               if (cmd_)
-                       str << "cmd+";
-               if (ctrl_)
-                       str << "ctrl+";
-               str << static_cast<char>(character_);
-       } else if (type_ == BY_KEYCODE) {
+       if (type_ == BY_KEYCODE) {
                if (alt_)
                        str << "alt+";
                if (ctrl_)
@@ -466,6 +454,7 @@
                                break;
                        default:
                                direction = "Unknown";
+                               break;
                }
                str << "Joy" << joystick_ << "Hat" << hat_ << direction;
        }
@@ -496,48 +485,21 @@
        type_ = HAT;
 }
 
-void hotkey_item::set_key(int character, int keycode, bool shift, bool ctrl, 
bool alt, bool cmd)
-{
-       const std::string keyname = SDL_GetKeyName(SDLKey(keycode));
-
-       LOG_G << "setting hotkey: char=" << lexical_cast<std::string>(character)
-                  << " keycode="  << lexical_cast<std::string>(keycode) << " "
+void hotkey_item::set_key(int keycode, bool shift, bool ctrl, bool alt, bool 
cmd)
+{
+       LOG_G << "setting hotkey: keycode="  << 
lexical_cast<std::string>(keycode) << " "
                   << (shift ? "shift," : "")
                   << (ctrl ? "ctrl," : "")
                   << (alt ? "alt," : "")
                   << (cmd ? "cmd," : "")
                   << "\n";
 
-       // Sometimes control modifies by -64, ie ^A == 1.
-       if (character < 64 && ctrl) {
-               if (shift)
-                       character += 64;
-               else
-                       character += 96;
-               LOG_G << "Mapped to character " << 
lexical_cast<std::string>(character) << "\n";
-       }
-
-       // For some reason on Mac OS, if cmd and shift are down, the character 
doesn't get upper-cased
-       if (cmd && character > 96 && character < 123 && shift)
-               character -= 32;
-
-       // We handle simple cases by character, others by the actual key.
-       if (isprint(character) && !isspace(character)) {
-               type_ = BY_CHARACTER;
-               character_ = character;
-               ctrl_ = ctrl;
-               alt_ = alt;
-               cmd_ = cmd;
-               LOG_G << "type = BY_CHARACTER\n";
-       } else {
-               type_ = BY_KEYCODE;
-               keycode_ = keycode;
-               shift_ = shift;
-               ctrl_ = ctrl;
-               alt_ = alt;
-               cmd_ = cmd;
-               LOG_G << "type = BY_KEYCODE\n";
-       }
+       type_ = BY_KEYCODE;
+       keycode_ = keycode;
+       shift_ = shift;
+       ctrl_ = ctrl;
+       alt_ = alt;
+       cmd_ = cmd;
 }
 
 manager::manager()
@@ -643,12 +605,10 @@
                if (i->get_type() == hotkey_item::BY_KEYCODE) {
                        item["key"] = SDL_GetKeyName(SDLKey(i->get_keycode()));
                        item["shift"] = i->get_shift();
-               } else if (i->get_type() == hotkey_item::BY_CHARACTER) {
-                       item["key"] = 
utils::wchar_to_string(i->get_character());
-               }
-               item["alt"] = i->get_alt();
-               item["ctrl"] = i->get_ctrl();
-               item["cmd"] = i->get_cmd();
+                       item["alt"] = i->get_alt();
+                       item["ctrl"] = i->get_ctrl();
+                       item["cmd"] = i->get_cmd();
+               }
        }
 }
 
@@ -721,48 +681,20 @@
        return *itor;
 }
 
-hotkey_item& get_hotkey(int character, int keycode, bool shift, bool ctrl,
+hotkey_item& get_hotkey(int keycode, bool shift, bool ctrl,
        bool alt, bool cmd)
 {
        std::vector<hotkey_item>::iterator itor;
 
-       DBG_G << "getting hotkey: char=" << lexical_cast<std::string>(character)
-                  << " keycode="  << lexical_cast<std::string>(keycode) << " "
+       DBG_G << "getting hotkey: keycode="  << 
lexical_cast<std::string>(keycode) << " "
                   << (shift ? "shift," : "")
                   << (ctrl ? "ctrl," : "")
                   << (alt ? "alt," : "")
                   << (cmd ? "cmd," : "")
                   << "\n";
 
-       // Sometimes control modifies by -64, ie ^A == 1.
-       if (0 < character && character < 64 && ctrl) {
-               if (shift)
-                       character += 64;
-               else
-                       character += 96;
-               DBG_G << "Mapped to character " << 
lexical_cast<std::string>(character) << "\n";
-       }
-
-       // For some reason on Mac OS, if cmd and shift are down, the character 
doesn't get upper-cased
-       if (cmd && character > 96 && character < 123 && shift)
-               character -= 32;
-
        for (itor = hotkeys_.begin(); itor != hotkeys_.end(); ++itor) {
-               if (itor->get_type() == hotkey_item::BY_CHARACTER) {
-                       if (character == itor->get_character()) {
-                               if (ctrl == itor->get_ctrl()
-                                               && alt == itor->get_alt()
-                                               && cmd == itor->get_cmd()) {
-                                       if (itor->is_in_active_scope()) {
-                                               DBG_G << "Could match by 
character..." << "yes\n";
-                                               break;
-                                       } else {
-                                               DBG_G << "Could match by 
character..." << "yes, but scope is inactive\n";
-                                       }
-                               }
-                               DBG_G << "Could match by character..." << "but 
modifiers different\n";
-                       }
-               } else if (itor->get_type() == hotkey_item::BY_KEYCODE) {
+               if (itor->get_type() == hotkey_item::BY_KEYCODE) {
                        if (keycode == itor->get_keycode()) {
                                if (shift == itor->get_shift()
                                                && ctrl == itor->get_ctrl()
@@ -798,7 +730,7 @@
 
 hotkey_item& get_hotkey(const SDL_KeyboardEvent& event)
 {
-       return get_hotkey(event.keysym.unicode, event.keysym.sym,
+       return get_hotkey(event.keysym.sym,
                        (event.keysym.mod & KMOD_SHIFT) != 0,
                        (event.keysym.mod & KMOD_CTRL) != 0,
                        (event.keysym.mod & KMOD_ALT) != 0,

Modified: trunk/src/hotkeys.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/hotkeys.hpp?rev=51664&r1=51663&r2=51664&view=diff
==============================================================================
--- trunk/src/hotkeys.hpp (original)
+++ trunk/src/hotkeys.hpp Thu Oct 27 01:59:08 2011
@@ -131,7 +131,6 @@
                description_(),
                scope_(SCOPE_GENERAL),
                type_(UNBOUND),
-               character_(0),
                ctrl_(false),
                alt_(false),
                cmd_(false),
@@ -160,12 +159,11 @@
        void set_button(int button, int joystick);
        void set_hat(int joystick, int hat, int value);
 
-       void set_key(int character, int keycode, bool shift, bool ctrl, bool 
alt, bool cmd);
+       void set_key(int keycode, bool shift, bool ctrl, bool alt, bool cmd);
 
        enum type {
                UNBOUND,
                BY_KEYCODE,
-               BY_CHARACTER,
                CLEARED,
                BUTTON,
                HAT
@@ -180,7 +178,6 @@
        bool is_in_active_scope() const { return is_scope_active(get_scope()); }
 
        // Returns unicode value of keypress.
-       int get_character() const { return character_; }
        int get_button() const { return button_; }
        int get_joystick() const { return joystick_; }
        int get_hat() const { return hat_; }
@@ -208,8 +205,6 @@
        // BUTTON means gamepad/joystick button_.
        enum type type_;
 
-       // Actual unicode character
-       int character_;
        bool ctrl_;
        bool alt_;
        bool cmd_;
@@ -217,6 +212,7 @@
        // These used for function keys (which don't have a unicode value) or
        // space (which doesn't have a distinct unicode value when shifted).
        bool shift_;
+       // Actual unicode character
        int keycode_;
 
        // In case type=BUTTON
@@ -260,7 +256,7 @@
 
 hotkey_item& get_hotkey(int joy_num, int button_num);
 hotkey_item& get_hotkey(int joy_num, int hat_num, int hat_value);
-hotkey_item& get_hotkey(int character, int keycode, bool shift,
+hotkey_item& get_hotkey(int keycode, bool shift,
                bool ctrl, bool alt, bool cmd);
 hotkey_item& get_hotkey(const SDL_JoyButtonEvent& event);
 hotkey_item& get_hotkey(const SDL_JoyHatEvent& event);

Modified: trunk/src/preferences_display.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/preferences_display.cpp?rev=51664&r1=51663&r2=51664&view=diff
==============================================================================
--- trunk/src/preferences_display.cpp (original)
+++ trunk/src/preferences_display.cpp Thu Oct 27 01:59:08 2011
@@ -353,16 +353,15 @@
                        disp.update_display();
                        SDL_Event event;
                        event.type = 0;
-                       int character = 0, keycode = 0, mod = 0; // Just to 
avoid warning
+                       int keycode = 0, mod = 0; // Just to avoid warning
                        int joystick = 0, button = 0, hat = 0, value = 0;
-                       const int any_mod = KMOD_CTRL | KMOD_ALT | KMOD_LMETA;
+                       const int any_mod = KMOD_CTRL | KMOD_ALT | KMOD_LMETA | 
KMOD_SHIFT;
 
                        while (event.type!=SDL_KEYDOWN && 
event.type!=SDL_JOYBUTTONDOWN && event.type!= SDL_JOYHATMOTION) 
SDL_PollEvent(&event);
                        do {
                                if (event.type==SDL_KEYDOWN)
                                {
                                        keycode=event.key.keysym.sym;
-                                       character=event.key.keysym.unicode;
                                        mod=event.key.keysym.mod;
                                };
                                if (event.type==SDL_JOYBUTTONDOWN) {
@@ -383,7 +382,7 @@
                        if (keycode == SDLK_ESCAPE && (mod & any_mod) == 0) {
                                //cancel -- no action
                        } else {
-                               const hotkey::hotkey_item& oldhk = 
hotkey::get_hotkey(character, keycode, (mod & KMOD_SHIFT) != 0,
+                               const hotkey::hotkey_item& oldhk = 
hotkey::get_hotkey(keycode, (mod & KMOD_SHIFT) != 0,
                                                (mod & KMOD_CTRL) != 0, (mod & 
KMOD_ALT) != 0, (mod & KMOD_LMETA) != 0);
 
                                hotkey::hotkey_item& newhk = 
hotkey::get_visible_hotkey(menu_.selection());
@@ -418,7 +417,7 @@
                                                }
                                        } else {
 
-                                               newhk.set_key(character, 
keycode, (mod & KMOD_SHIFT) != 0,
+                                               newhk.set_key(keycode, (mod & 
KMOD_SHIFT) != 0,
                                                                (mod & 
KMOD_CTRL) != 0, (mod & KMOD_ALT) != 0, (mod & KMOD_LMETA) != 0);
 
                                                
menu_.change_item(menu_.selection(), 1, font::NULL_MARKUP + newhk.get_name());


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to