00001 // Copyright (c) 2003 - 2004 Anselm R. Garbe <anselmg at t-online.de> 00002 // See ../LICENSE.txt for license details. 00003 // 00004 // $Id: shortcut.cpp 2 2007-05-16 10:38:27Z eg $ 00005 00006 #include "shortcut.h" 00007 00008 #include "logger.h" 00009 #include "util.h" 00010 #include "xcore.h" 00011 00012 Shortcut::Shortcut(unsigned long modMask, KeyCode keyCode, 00013 Shortcut *next, unsigned int button) 00014 { 00015 modMask_ = modMask; 00016 button_ = button; 00017 keyCode_ = keyCode; 00018 next_ = next; 00019 } 00020 00021 Shortcut::~Shortcut() { 00022 if (next_) { 00023 delete next_; 00024 } 00025 } 00026 00027 00028 Shortcut *Shortcut::shortcut(string keys) { 00029 00030 if (keys == "") { 00031 return 0; 00032 } 00033 00034 LOGDEBUG("entered shortcut construction"); 00035 // shortcut handling 00036 Shortcut *root = 0; 00037 Shortcut *tmp = 0; 00038 keys = Util::truncate(keys, ' '); 00039 unsigned int length = keys.length(); 00040 bool sep; 00041 string subkeys = ""; 00042 for (int i = 0; i < (int)length; i++) { 00043 sep = keys[i] == ':'; 00044 if (!sep) { 00045 subkeys += keys[i]; 00046 } 00047 else { 00048 i++; // ignore next ':' 00049 } 00050 00051 if (sep || (i == (int)(length - 1))) { 00052 LOGDEBUG("next shortcut: " + subkeys); 00053 // if no modifier is given, none is assumed 00054 if (subkeys.find('+') == string::npos) { 00055 subkeys = "none+" + subkeys; 00056 } 00057 string key = Util::lastToken(subkeys, '+'); 00058 // check if the key sequence contains a Button identifier 00059 unsigned int button = Util::buttonForString(key); 00060 Shortcut *shortcut = new Shortcut( 00061 Util::modMaskForString(subkeys), 00062 XCORE->stringToKeyCode(key), 0, button); 00063 if (!root) { 00064 root = shortcut; 00065 } 00066 else { 00067 tmp->setNext(shortcut); 00068 } 00069 tmp = shortcut; 00070 subkeys = ""; 00071 } 00072 } 00073 return root; 00074 } 00075 00076 00077 KeyCode Shortcut::keyCode() { 00078 return keyCode_; 00079 } 00080 00081 unsigned long Shortcut::modMask() const { 00082 return modMask_; 00083 } 00084 00085 unsigned int Shortcut::button() const { 00086 return button_; 00087 } 00088 00089 Shortcut *Shortcut::next() const { 00090 return next_; 00091 } 00092 00093 void Shortcut::setNext(Shortcut *next) { 00094 next_ = next; 00095 } 00096 00097 void Shortcut::setKeyCode(KeyCode keyCode) { 00098 keyCode_ = keyCode; 00099 } 00100 00101 void Shortcut::setModMask(unsigned long modMask) { 00102 modMask_ = modMask; 00103 }