summaryrefslogtreecommitdiff
path: root/indra/llwindow/llkeyboard.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llwindow/llkeyboard.cpp')
-rw-r--r--indra/llwindow/llkeyboard.cpp125
1 files changed, 74 insertions, 51 deletions
diff --git a/indra/llwindow/llkeyboard.cpp b/indra/llwindow/llkeyboard.cpp
index b3dcac6222..cb0c312a1d 100644
--- a/indra/llwindow/llkeyboard.cpp
+++ b/indra/llwindow/llkeyboard.cpp
@@ -41,7 +41,6 @@ std::map<KEY,std::string> LLKeyboard::sKeysToNames;
std::map<std::string,KEY> LLKeyboard::sNamesToKeys;
LLKeyStringTranslatorFunc* LLKeyboard::mStringTranslator = NULL; // Used for l10n + PC/Mac/Linux accelerator labeling
-
//
// Class Implementation
//
@@ -55,10 +54,10 @@ LLKeyboard::LLKeyboard() : mCallbacks(NULL)
for (i = 0; i < KEY_COUNT; i++)
{
mKeyLevelFrameCount[i] = 0;
- mKeyLevel[i] = FALSE;
- mKeyUp[i] = FALSE;
- mKeyDown[i] = FALSE;
- mKeyRepeated[i] = FALSE;
+ mKeyLevel[i] = false;
+ mKeyUp[i] = false;
+ mKeyDown[i] = false;
+ mKeyRepeated[i] = false;
}
mInsertMode = LL_KIM_INSERT;
@@ -150,18 +149,19 @@ void LLKeyboard::addKeyName(KEY key, const std::string& name)
void LLKeyboard::resetKeyDownAndHandle()
{
- MASK mask = currentMask(FALSE);
+ MASK mask = currentMask(false);
for (S32 i = 0; i < KEY_COUNT; i++)
{
if (mKeyLevel[i])
{
- mKeyDown[i] = FALSE;
- mKeyLevel[i] = FALSE;
- mKeyUp[i] = TRUE;
+ mKeyDown[i] = false;
+ mKeyLevel[i] = false;
+ mKeyUp[i] = true;
mCurTranslatedKey = (KEY)i;
mCallbacks->handleTranslatedKeyUp(i, mask);
}
}
+ mCurTranslatedKey = KEY_NONE;
}
// BUG this has to be called when an OS dialog is shown, otherwise modifier key state
@@ -174,51 +174,48 @@ void LLKeyboard::resetKeys()
{
if( mKeyLevel[i] )
{
- mKeyLevel[i] = FALSE;
+ mKeyLevel[i] = false;
}
}
for (i = 0; i < KEY_COUNT; i++)
{
- mKeyUp[i] = FALSE;
+ mKeyUp[i] = false;
}
for (i = 0; i < KEY_COUNT; i++)
{
- mKeyDown[i] = FALSE;
+ mKeyDown[i] = false;
}
for (i = 0; i < KEY_COUNT; i++)
{
- mKeyRepeated[i] = FALSE;
+ mKeyRepeated[i] = false;
}
}
-BOOL LLKeyboard::translateKey(const U16 os_key, KEY *out_key)
+bool LLKeyboard::translateKey(const NATIVE_KEY_TYPE os_key, KEY *out_key)
{
- std::map<U16, KEY>::iterator iter;
// Only translate keys in the map, ignore all other keys for now
- iter = mTranslateKeyMap.find(os_key);
+ auto iter = mTranslateKeyMap.find(os_key);
if (iter == mTranslateKeyMap.end())
{
//LL_WARNS() << "Unknown virtual key " << os_key << LL_ENDL;
*out_key = 0;
- return FALSE;
+ return false;
}
else
{
*out_key = iter->second;
- return TRUE;
+ return true;
}
}
-
-U16 LLKeyboard::inverseTranslateKey(const KEY translated_key)
+LLKeyboard::NATIVE_KEY_TYPE LLKeyboard::inverseTranslateKey(const KEY translated_key)
{
- std::map<KEY, U16>::iterator iter;
- iter = mInvTranslateKeyMap.find(translated_key);
+ auto iter = mInvTranslateKeyMap.find(translated_key);
if (iter == mInvTranslateKeyMap.end())
{
return 0;
@@ -230,47 +227,47 @@ U16 LLKeyboard::inverseTranslateKey(const KEY translated_key)
}
-BOOL LLKeyboard::handleTranslatedKeyDown(KEY translated_key, U32 translated_mask)
+bool LLKeyboard::handleTranslatedKeyDown(KEY translated_key, MASK translated_mask)
{
- BOOL handled = FALSE;
- BOOL repeated = FALSE;
+ bool handled = false;
+ bool repeated = false;
// is this the first time the key went down?
// if so, generate "character" message
if( !mKeyLevel[translated_key] )
{
- mKeyLevel[translated_key] = TRUE;
+ mKeyLevel[translated_key] = true;
mKeyLevelTimer[translated_key].reset();
mKeyLevelFrameCount[translated_key] = 0;
- mKeyRepeated[translated_key] = FALSE;
+ mKeyRepeated[translated_key] = false;
}
else
{
// Level is already down, assume it's repeated.
- repeated = TRUE;
- mKeyRepeated[translated_key] = TRUE;
+ repeated = true;
+ mKeyRepeated[translated_key] = true;
}
- mKeyDown[translated_key] = TRUE;
+ mKeyDown[translated_key] = true;
mCurTranslatedKey = (KEY)translated_key;
handled = mCallbacks->handleTranslatedKeyDown(translated_key, translated_mask, repeated);
return handled;
}
-BOOL LLKeyboard::handleTranslatedKeyUp(KEY translated_key, U32 translated_mask)
+bool LLKeyboard::handleTranslatedKeyUp(KEY translated_key, MASK translated_mask)
{
- BOOL handled = FALSE;
+ bool handled = false;
if( mKeyLevel[translated_key] )
{
- mKeyLevel[translated_key] = FALSE;
+ mKeyLevel[translated_key] = false;
// Only generate key up events if the key is thought to
// be down. This allows you to call resetKeys() in the
// middle of a frame and ignore subsequent KEY_UP
// messages in the same frame. This was causing the
// sequence W<return> in chat to move agents forward. JC
- mKeyUp[translated_key] = TRUE;
+ mKeyUp[translated_key] = true;
handled = mCallbacks->handleTranslatedKeyUp(translated_key, translated_mask);
}
@@ -280,6 +277,32 @@ BOOL LLKeyboard::handleTranslatedKeyUp(KEY translated_key, U32 translated_mask)
}
+bool LLKeyboard::handleKeyDown(const NATIVE_KEY_TYPE key, const MASK mask)
+{
+ MASK translated_mask = updateModifiers(mask);
+ KEY translated_key = 0;
+ bool handled = false;
+ if(translateKey(key, &translated_key))
+ {
+ handled = handleTranslatedKeyDown(translated_key, translated_mask);
+ }
+ return handled;
+}
+
+
+bool LLKeyboard::handleKeyUp(const NATIVE_KEY_TYPE key, const MASK mask)
+{
+ MASK translated_mask = updateModifiers(mask);
+ KEY translated_key = 0;
+ bool handled = false;
+ if(translateKey(key, &translated_key))
+ {
+ handled = handleTranslatedKeyUp(translated_key, translated_mask);
+ }
+ return handled;
+}
+
+
void LLKeyboard::toggleInsertMode()
{
if (LL_KIM_INSERT == mInsertMode)
@@ -306,14 +329,14 @@ S32 LLKeyboard::getKeyElapsedFrameCount(KEY key)
}
// static
-BOOL LLKeyboard::keyFromString(const std::string& str, KEY *key)
+bool LLKeyboard::keyFromString(const std::string& str, KEY *key)
{
std::string instring(str);
size_t length = instring.size();
if (length < 1)
{
- return FALSE;
+ return false;
}
if (length == 1)
{
@@ -326,7 +349,7 @@ BOOL LLKeyboard::keyFromString(const std::string& str, KEY *key)
('{' <= ch && ch <= '~')) // {|}~
{
*key = ch;
- return TRUE;
+ return true;
}
}
@@ -335,10 +358,10 @@ BOOL LLKeyboard::keyFromString(const std::string& str, KEY *key)
if (res != 0)
{
*key = res;
- return TRUE;
+ return true;
}
LL_WARNS() << "keyFromString failed: " << str << LL_ENDL;
- return FALSE;
+ return false;
}
@@ -359,7 +382,7 @@ std::string LLKeyboard::stringFromKey(KEY key, bool translate)
LLKeyStringTranslatorFunc *trans = gKeyboard->mStringTranslator;
if (trans != NULL)
{
- res = trans(res.c_str());
+ res = trans(res);
}
}
@@ -399,7 +422,7 @@ std::string LLKeyboard::stringFromMouse(EMouseClickType click, bool translate)
LLKeyStringTranslatorFunc* trans = gKeyboard->mStringTranslator;
if (trans != NULL)
{
- res = trans(res.c_str());
+ res = trans(res);
}
}
return res;
@@ -486,52 +509,52 @@ std::string LLKeyboard::stringFromAccelerator(MASK accel_mask, EMouseClickType c
}
//static
-BOOL LLKeyboard::maskFromString(const std::string& str, MASK *mask)
+bool LLKeyboard::maskFromString(const std::string& str, MASK *mask)
{
std::string instring(str);
if (instring == "NONE")
{
*mask = MASK_NONE;
- return TRUE;
+ return true;
}
else if (instring == "SHIFT")
{
*mask = MASK_SHIFT;
- return TRUE;
+ return true;
}
else if (instring == "CTL")
{
*mask = MASK_CONTROL;
- return TRUE;
+ return true;
}
else if (instring == "ALT")
{
*mask = MASK_ALT;
- return TRUE;
+ return true;
}
else if (instring == "CTL_SHIFT")
{
*mask = MASK_CONTROL | MASK_SHIFT;
- return TRUE;
+ return true;
}
else if (instring == "ALT_SHIFT")
{
*mask = MASK_ALT | MASK_SHIFT;
- return TRUE;
+ return true;
}
else if (instring == "CTL_ALT")
{
*mask = MASK_CONTROL | MASK_ALT;
- return TRUE;
+ return true;
}
else if (instring == "CTL_ALT_SHIFT")
{
*mask = MASK_CONTROL | MASK_ALT | MASK_SHIFT;
- return TRUE;
+ return true;
}
else
{
- return FALSE;
+ return false;
}
}