aboutsummaryrefslogtreecommitdiff
path: root/guilib/GUIEditControl.cpp
diff options
context:
space:
mode:
authorjmarshallnz <jmarshallnz@svn>2009-10-11 02:52:56 +0000
committerjmarshallnz <jmarshallnz@svn>2009-10-11 02:52:56 +0000
commitd45e35ea92664ac224243eeee321910d3194e2cd (patch)
tree6da8d71849742e5687a8a31d24309b83a701bbd1 /guilib/GUIEditControl.cpp
parent341c949ebe589dde813db77a28ab1a1d3fc54d03 (diff)
fixed: Edit controls didn't support SMS input. Ticket #7315
git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@23589 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
Diffstat (limited to 'guilib/GUIEditControl.cpp')
-rw-r--r--guilib/GUIEditControl.cpp174
1 files changed, 114 insertions, 60 deletions
diff --git a/guilib/GUIEditControl.cpp b/guilib/GUIEditControl.cpp
index a5eb28d256..6faa06206a 100644
--- a/guilib/GUIEditControl.cpp
+++ b/guilib/GUIEditControl.cpp
@@ -31,6 +31,9 @@
#include "CocoaInterface.h"
#endif
+const char* CGUIEditControl::smsLetters[10] = { " !@#$%^&*()[]{}<>/\\|0", ".,;:\'\"-+_=?`~1", "abc2", "def3", "ghi4", "jkl5", "mno6", "pqrs7", "tuv8", "wxyz9" };
+const unsigned int CGUIEditControl::smsDelay = 1000;
+
using namespace std;
#ifdef WIN32
@@ -49,6 +52,8 @@ CGUIEditControl::CGUIEditControl(int parentID, int controlID, float posX, float
m_cursorBlink = 0;
m_inputHeading = 0;
m_inputType = INPUT_TYPE_TEXT;
+ m_smsLastKey = 0;
+ m_smsKeyIndex = 0;
SetLabel(text);
}
@@ -61,6 +66,8 @@ CGUIEditControl::CGUIEditControl(const CGUIButtonControl &button)
m_textWidth = GetWidth();
m_cursorPos = 0;
m_cursorBlink = 0;
+ m_smsLastKey = 0;
+ m_smsKeyIndex = 0;
}
CGUIEditControl::~CGUIEditControl(void)
@@ -79,6 +86,11 @@ bool CGUIEditControl::OnMessage(CGUIMessage &message)
message.SetLabel(GetLabel2());
return true;
}
+ else if (message.GetMessage() == GUI_MSG_SETFOCUS ||
+ message.GetMessage() == GUI_MSG_LOSTFOCUS)
+ {
+ m_smsTimer.Stop();
+ }
return CGUIButtonControl::OnMessage(message);
}
@@ -95,7 +107,7 @@ bool CGUIEditControl::OnAction(const CAction &action)
if (m_cursorPos)
{
m_text2.erase(--m_cursorPos, 1);
- OnTextChanged();
+ UpdateText();
}
return true;
}
@@ -104,7 +116,7 @@ bool CGUIEditControl::OnAction(const CAction &action)
if (m_cursorPos > 0)
{
m_cursorPos--;
- OnTextChanged();
+ UpdateText(false);
return true;
}
}
@@ -113,39 +125,13 @@ bool CGUIEditControl::OnAction(const CAction &action)
if ((unsigned int) m_cursorPos < m_text2.size())
{
m_cursorPos++;
- OnTextChanged();
+ UpdateText(false);
return true;
}
}
else if (action.id == ACTION_PASTE)
{
-#ifdef __APPLE__
- const char *szStr = Cocoa_Paste();
- if (szStr)
- {
- m_text2 += szStr;
- m_cursorPos+=strlen(szStr);
- OnTextChanged();
- }
-#elif defined _WIN32
- HGLOBAL hglb;
- LPTSTR lptstr;
- if (OpenClipboard(g_hWnd))
- {
- hglb = GetClipboardData(CF_TEXT);
- if (hglb != NULL)
- {
- lptstr = (LPTSTR)GlobalLock(hglb);
- if (lptstr != NULL)
- {
- m_text2 = (char*)lptstr;
- GlobalUnlock(hglb);
- }
- }
- CloseClipboard();
- OnTextChanged();
- }
-#endif
+ OnPasteClipboard();
}
else if (action.id >= KEY_VKEY && action.id < KEY_ASCII)
{
@@ -154,13 +140,13 @@ bool CGUIEditControl::OnAction(const CAction &action)
if (b == 0x25 && m_cursorPos > 0)
{ // left
m_cursorPos--;
- OnTextChanged();
+ UpdateText(false);
return true;
}
if (b == 0x27 && m_cursorPos < m_text2.length())
{ // right
m_cursorPos++;
- OnTextChanged();
+ UpdateText(false);
return true;
}
if (b == 0x2e)
@@ -168,7 +154,7 @@ bool CGUIEditControl::OnAction(const CAction &action)
if (m_cursorPos < m_text2.length())
{ // delete
m_text2.erase(m_cursorPos, 1);
- OnTextChanged();
+ UpdateText();
return true;
}
}
@@ -177,7 +163,7 @@ bool CGUIEditControl::OnAction(const CAction &action)
if (m_cursorPos > 0)
{ // backspace
m_text2.erase(--m_cursorPos, 1);
- OnTextChanged();
+ UpdateText();
}
return true;
}
@@ -206,30 +192,28 @@ bool CGUIEditControl::OnAction(const CAction &action)
if (m_cursorPos)
{
m_text2.erase(--m_cursorPos, 1);
- OnTextChanged();
}
break;
}
default:
{
- m_text2.insert(m_text2.begin() + m_cursorPos, (WCHAR)action.unicode);
- m_cursorPos++;
- OnTextChanged();
+ m_text2.insert(m_text2.begin() + m_cursorPos++, (WCHAR)action.unicode);
break;
}
}
- OnTextChanged();
+ UpdateText();
return true;
}
else if (action.id >= REMOTE_2 && action.id <= REMOTE_9)
{ // input from the remote
if (m_inputType == INPUT_TYPE_FILTER)
{ // filtering - use single number presses
- m_text2.insert(m_text2.begin() + m_cursorPos, L'0' + (action.id - REMOTE_0));
- m_cursorPos++;
- OnTextChanged();
+ m_text2.insert(m_text2.begin() + m_cursorPos++, L'0' + (action.id - REMOTE_0));
+ UpdateText();
return true;
}
+ else
+ OnSMSCharacter(action.id - REMOTE_0);
}
return CGUIButtonControl::OnAction(action);
}
@@ -273,10 +257,10 @@ void CGUIEditControl::OnClick()
textChanged = CGUIDialogNumeric::ShowAndGetIPAddress(utf8, heading);
break;
case INPUT_TYPE_SEARCH:
- CGUIDialogKeyboard::ShowAndGetFilter(utf8, true);
+ textChanged = CGUIDialogKeyboard::ShowAndGetFilter(utf8, true);
break;
case INPUT_TYPE_FILTER:
- CGUIDialogKeyboard::ShowAndGetFilter(utf8, false);
+ textChanged = CGUIDialogKeyboard::ShowAndGetFilter(utf8, false);
break;
case INPUT_TYPE_TEXT:
default:
@@ -287,11 +271,29 @@ void CGUIEditControl::OnClick()
{
g_charsetConverter.utf8ToW(utf8, m_text2);
m_cursorPos = m_text2.size();
- OnTextChanged();
+ UpdateText();
m_cursorPos = m_text2.size();
}
}
+void CGUIEditControl::UpdateText(bool sendUpdate)
+{
+ m_smsTimer.Stop();
+ if (sendUpdate)
+ {
+ SEND_CLICK_MESSAGE(GetID(), GetParentID(), 0);
+
+ vector<CGUIActionDescriptor> textChangeActions = m_textChangeActions;
+ for (unsigned int i = 0; i < textChangeActions.size(); i++)
+ {
+ CGUIMessage message(GUI_MSG_EXECUTE, GetID(), GetParentID());
+ message.SetAction(textChangeActions[i]);
+ g_windowManager.SendMessage(message);
+ }
+ }
+ SetInvalid();
+}
+
void CGUIEditControl::SetInputType(CGUIEditControl::INPUT_TYPE type, int heading)
{
m_inputType = type;
@@ -343,6 +345,9 @@ void CGUIEditControl::RecalcLabelPosition()
void CGUIEditControl::RenderText()
{
+ if (m_smsTimer.GetElapsedMilliseconds() > smsDelay)
+ UpdateText();
+
if (m_bInvalidated)
RecalcLabelPosition();
@@ -432,21 +437,6 @@ void CGUIEditControl::ValidateCursor()
m_cursorPos = m_text2.size();
}
-void CGUIEditControl::OnTextChanged()
-{
- SEND_CLICK_MESSAGE(GetID(), GetParentID(), 0);
-
- vector<CGUIActionDescriptor> textChangeActions = m_textChangeActions;
- for (unsigned int i = 0; i < textChangeActions.size(); i++)
- {
- CGUIMessage message(GUI_MSG_EXECUTE, GetID(), GetParentID());
- message.SetAction(textChangeActions[i]);
- g_windowManager.SendMessage(message);
- }
-
- SetInvalid();
-}
-
void CGUIEditControl::SetLabel(const std::string &text)
{
m_textLayout.Update(text);
@@ -481,3 +471,67 @@ void CGUIEditControl::SetCursorPosition(unsigned int iPosition)
{
m_cursorPos = iPosition;
}
+
+void CGUIEditControl::OnSMSCharacter(unsigned int key)
+{
+ assert(key < 10);
+ bool sendUpdate = false;
+ if (m_smsTimer.IsRunning())
+ {
+ // we're already entering an SMS character
+ if (key != m_smsLastKey || m_smsTimer.GetElapsedMilliseconds() > smsDelay)
+ { // a different key was clicked than last time, or we have timed out
+ m_smsLastKey = key;
+ m_smsKeyIndex = 0;
+ sendUpdate = true;
+ }
+ else
+ { // same key as last time within the appropriate time period
+ m_smsKeyIndex++;
+ if (m_cursorPos)
+ m_text2.erase(--m_cursorPos, 1);
+ }
+ }
+ else
+ { // key is pressed for the first time
+ m_smsLastKey = key;
+ m_smsKeyIndex = 0;
+ }
+
+ m_smsKeyIndex = m_smsKeyIndex % strlen(smsLetters[key]);
+
+ m_text2.insert(m_text2.begin() + m_cursorPos++, smsLetters[key][m_smsKeyIndex]);
+ UpdateText(sendUpdate);
+ m_smsTimer.StartZero();
+}
+
+void CGUIEditControl::OnPasteClipboard()
+{
+#ifdef __APPLE__
+ const char *szStr = Cocoa_Paste();
+ if (szStr)
+ {
+ m_text2 += szStr;
+ m_cursorPos+=strlen(szStr);
+ UpdateText();
+ }
+#elif defined _WIN32
+ HGLOBAL hglb;
+ LPTSTR lptstr;
+ if (OpenClipboard(g_hWnd))
+ {
+ hglb = GetClipboardData(CF_TEXT);
+ if (hglb != NULL)
+ {
+ lptstr = (LPTSTR)GlobalLock(hglb);
+ if (lptstr != NULL)
+ {
+ m_text2 = (char*)lptstr;
+ GlobalUnlock(hglb);
+ }
+ }
+ CloseClipboard();
+ UpdateText();
+ }
+#endif
+}