Permalink
Browse files

CGUIEditControl: add INPUT_TYPE_READONLY for a read-only mode (no inp…

…ut and no cursor)
  • Loading branch information...
1 parent f53edb6 commit aa0baa0a8d3133e02193d4a6847edcbcc5d99eb4 @Montellese committed Jun 7, 2012
Showing with 109 additions and 102 deletions.
  1. +108 −102 xbmc/guilib/GUIEditControl.cpp
  2. +1 −0 xbmc/guilib/GUIEditControl.h
@@ -101,138 +101,141 @@ bool CGUIEditControl::OnAction(const CAction &action)
{
ValidateCursor();
- if (action.GetID() == ACTION_BACKSPACE)
+ if (m_inputType != INPUT_TYPE_READONLY)
{
- // backspace
- if (m_cursorPos)
+ if (action.GetID() == ACTION_BACKSPACE)
{
- if (!ClearMD5())
- m_text2.erase(--m_cursorPos, 1);
- UpdateText();
- }
- return true;
- }
- else if (action.GetID() == ACTION_MOVE_LEFT)
- {
- if (m_cursorPos > 0)
- {
- m_cursorPos--;
- UpdateText(false);
- return true;
- }
- }
- else if (action.GetID() == ACTION_MOVE_RIGHT)
- {
- if ((unsigned int) m_cursorPos < m_text2.size())
- {
- m_cursorPos++;
- UpdateText(false);
- return true;
- }
- }
- else if (action.GetID() == ACTION_PASTE)
- {
- ClearMD5();
- OnPasteClipboard();
- }
- else if (action.GetID() >= KEY_VKEY && action.GetID() < KEY_ASCII)
- {
- // input from the keyboard (vkey, not ascii)
- BYTE b = action.GetID() & 0xFF;
- if (b == XBMCVK_HOME)
- {
- m_cursorPos = 0;
- UpdateText(false);
+ // backspace
+ if (m_cursorPos)
+ {
+ if (!ClearMD5())
+ m_text2.erase(--m_cursorPos, 1);
+ UpdateText();
+ }
return true;
}
- else if (b == XBMCVK_END)
+ else if (action.GetID() == ACTION_MOVE_LEFT)
{
- m_cursorPos = m_text2.length();
- UpdateText(false);
- return true;
+ if (m_cursorPos > 0)
+ {
+ m_cursorPos--;
+ UpdateText(false);
+ return true;
+ }
}
- if (b == XBMCVK_LEFT && m_cursorPos > 0)
+ else if (action.GetID() == ACTION_MOVE_RIGHT)
{
- m_cursorPos--;
- UpdateText(false);
- return true;
+ if ((unsigned int) m_cursorPos < m_text2.size())
+ {
+ m_cursorPos++;
+ UpdateText(false);
+ return true;
+ }
}
- if (b == XBMCVK_RIGHT && m_cursorPos < m_text2.length())
+ else if (action.GetID() == ACTION_PASTE)
{
- m_cursorPos++;
- UpdateText(false);
- return true;
+ ClearMD5();
+ OnPasteClipboard();
}
- if (b == XBMCVK_DELETE)
+ else if (action.GetID() >= KEY_VKEY && action.GetID() < KEY_ASCII)
{
- if (m_cursorPos < m_text2.length())
+ // input from the keyboard (vkey, not ascii)
+ BYTE b = action.GetID() & 0xFF;
+ if (b == XBMCVK_HOME)
{
- if (!ClearMD5())
- m_text2.erase(m_cursorPos, 1);
- UpdateText();
+ m_cursorPos = 0;
+ UpdateText(false);
return true;
}
- }
- if (b == XBMCVK_BACK)
- {
- if (m_cursorPos > 0)
+ else if (b == XBMCVK_END)
{
- if (!ClearMD5())
- m_text2.erase(--m_cursorPos, 1);
- UpdateText();
+ m_cursorPos = m_text2.length();
+ UpdateText(false);
+ return true;
}
- return true;
- }
- }
- else if (action.GetID() >= KEY_ASCII)
- {
- // input from the keyboard
- switch (action.GetUnicode())
- {
- case '\t':
- break;
- case 10:
- case 13:
+ if (b == XBMCVK_LEFT && m_cursorPos > 0)
{
- // enter - send click message, but otherwise ignore
- SEND_CLICK_MESSAGE(GetID(), GetParentID(), 1);
+ m_cursorPos--;
+ UpdateText(false);
return true;
}
- case 27:
- { // escape - fallthrough to default action
- return CGUIButtonControl::OnAction(action);
+ if (b == XBMCVK_RIGHT && m_cursorPos < m_text2.length())
+ {
+ m_cursorPos++;
+ UpdateText(false);
+ return true;
}
- case 8:
+ if (b == XBMCVK_DELETE)
{
- // backspace
- if (m_cursorPos)
+ if (m_cursorPos < m_text2.length())
+ {
+ if (!ClearMD5())
+ m_text2.erase(m_cursorPos, 1);
+ UpdateText();
+ return true;
+ }
+ }
+ if (b == XBMCVK_BACK)
+ {
+ if (m_cursorPos > 0)
{
if (!ClearMD5())
m_text2.erase(--m_cursorPos, 1);
+ UpdateText();
}
- break;
+ return true;
}
- default:
+ }
+ else if (action.GetID() >= KEY_ASCII)
+ {
+ // input from the keyboard
+ switch (action.GetUnicode())
{
- ClearMD5();
- m_text2.insert(m_text2.begin() + m_cursorPos++, (WCHAR)action.GetUnicode());
+ case '\t':
break;
+ case 10:
+ case 13:
+ {
+ // enter - send click message, but otherwise ignore
+ SEND_CLICK_MESSAGE(GetID(), GetParentID(), 1);
+ return true;
+ }
+ case 27:
+ { // escape - fallthrough to default action
+ return CGUIButtonControl::OnAction(action);
+ }
+ case 8:
+ {
+ // backspace
+ if (m_cursorPos)
+ {
+ if (!ClearMD5())
+ m_text2.erase(--m_cursorPos, 1);
+ }
+ break;
+ }
+ default:
+ {
+ ClearMD5();
+ m_text2.insert(m_text2.begin() + m_cursorPos++, (WCHAR)action.GetUnicode());
+ break;
+ }
}
- }
- UpdateText();
- return true;
- }
- else if (action.GetID() >= REMOTE_0 && action.GetID() <= REMOTE_9)
- { // input from the remote
- ClearMD5();
- if (m_inputType == INPUT_TYPE_FILTER)
- { // filtering - use single number presses
- m_text2.insert(m_text2.begin() + m_cursorPos++, L'0' + (action.GetID() - REMOTE_0));
UpdateText();
+ return true;
+ }
+ else if (action.GetID() >= REMOTE_0 && action.GetID() <= REMOTE_9)
+ { // input from the remote
+ ClearMD5();
+ if (m_inputType == INPUT_TYPE_FILTER)
+ { // filtering - use single number presses
+ m_text2.insert(m_text2.begin() + m_cursorPos++, L'0' + (action.GetID() - REMOTE_0));
+ UpdateText();
+ }
+ else
+ OnSMSCharacter(action.GetID() - REMOTE_0);
+ return true;
}
- else
- OnSMSCharacter(action.GetID() - REMOTE_0);
- return true;
}
return CGUIButtonControl::OnAction(action);
}
@@ -250,6 +253,9 @@ void CGUIEditControl::OnClick()
CStdString heading = g_localizeStrings.Get(m_inputHeading ? m_inputHeading : 16028);
switch (m_inputType)
{
+ case INPUT_TYPE_READONLY:
+ textChanged = false;
+ break;
case INPUT_TYPE_NUMBER:
textChanged = CGUIDialogNumeric::ShowAndGetNumber(utf8, heading);
break;
@@ -403,7 +409,7 @@ void CGUIEditControl::ProcessText(unsigned int currentTime)
}
CStdStringW text = GetDisplayedText();
// add the cursor if we're focused
- if (HasFocus())
+ if (HasFocus() && m_inputType != INPUT_TYPE_READONLY)
{
CStdStringW col;
if ((m_focusCounter % 64) > 32)
@@ -41,6 +41,7 @@ class CGUIEditControl : public CGUIButtonControl
{
public:
enum INPUT_TYPE {
+ INPUT_TYPE_READONLY = -1,
INPUT_TYPE_TEXT = 0,
INPUT_TYPE_NUMBER,
INPUT_TYPE_SECONDS,

0 comments on commit aa0baa0

Please sign in to comment.