bool CGUIDialogKeyboardGeneric::OnAction(const CAction &action)
{
  bool handled(true);
  if (action.GetID() == ACTION_BACKSPACE)
  {
    Backspace();
  }
  else if (action.GetID() == ACTION_ENTER)
  {
    OnOK();
  }
  else if (action.GetID() == ACTION_CURSOR_LEFT)
  {
    MoveCursor( -1);
  }
  else if (action.GetID() == ACTION_CURSOR_RIGHT)
  {
    if (m_strEditing.empty() && (unsigned int) GetCursorPos() == m_strEdit.size() && (m_strEdit.size() == 0 || m_strEdit[m_strEdit.size() - 1] != ' '))
    { // add a space
      Character(L' ');
    }
    else
      MoveCursor(1);
  }
  else if (action.GetID() == ACTION_SHIFT)
  {
    OnShift();
  }
  else if (action.GetID() == ACTION_SYMBOLS)
  {
    OnSymbols();
  }
  else if (action.GetID() >= REMOTE_0 && action.GetID() <= REMOTE_9)
  {
    OnRemoteNumberClick(action.GetID());
  }
  else if (action.GetID() == ACTION_PASTE)
  {
    OnPasteClipboard();
  }
  else if ( (action.GetID() >= KEY_VKEY && action.GetID() < KEY_ASCII) ||
  			(action.GetButtonCode() >= KEY_VKEY && action.GetButtonCode() < KEY_ASCII) )
  { // input from the keyboard (vkey, not ascii)
    if (!m_strEditing.empty())
      return handled;
    uint8_t b = action.GetButtonCode() ? action.GetButtonCode() & 0xFF : action.GetID() & 0xFF;
    
    switch (b)
    {
	case XBMCVK_HOME:
    	SetCursorPos(0);
    	break;
    case XBMCVK_END:
	    SetCursorPos(m_strEdit.size());
    	break;
    case XBMCVK_LEFT:
    	MoveCursor( -1);
    	break;
    case XBMCVK_RIGHT:
    	MoveCursor(1);
    	break;
    case XBMCVK_RETURN:
    case XBMCVK_NUMPADENTER:
    	OnOK();
    	break;
    case XBMCVK_DELETE:
		if (GetCursorPos() < (int)m_strEdit.size())
		{
			MoveCursor(1);
			Backspace();
		}
    	break;
    case XBMCVK_BACK:
    	Backspace();
    	break;
    case XBMCVK_ESCAPE:
    	Close();
    	break;
    case XBMCVK_LSHIFT:
    case XBMCVK_RSHIFT:
		OnShift();
		break;
	case XBMCVK_CAPSLOCK:
		OnCapsLock();
		break;
	}	
  }
  else if (action.GetID() >= KEY_ASCII)
  { // input from the keyboard
    //char ch = action.GetID() & 0xFF;
    int ch = action.GetUnicode();
    
    if( m_keyType == LOWER && m_bShift )
    {
		if (ch >= 'a' && ch <= 'z')
    		ch -= 32;
    		
    	OnShift();	
	}	
	else if( m_keyType == CAPS && !m_bShift )
	{
		if (ch >= 'a' && ch <= 'z')
    		ch -= 32;
    }
    else if( m_keyType == CAPS && m_bShift )
    	OnShift();
   		
    // Ignore non-printing characters
    if ( !((0 <= ch && ch < 0x8) || (0xE <= ch && ch < 0x1B) || (0x1C <= ch && ch < 0x20)) )
    {
      switch (ch)
      {
      case 0x8: // backspace
        Backspace();
        break;
      case 0x9: // Tab (do nothing)
      case 0xB: // Non-printing character, ignore
      case 0xC: // Non-printing character, ignore
        break;
      case 0xA: // enter
      case 0xD: // enter
        OnOK();
        break;
      case 0x1B: // escape
        Close();
        break;
      case 0x7F: // Delete
        if (GetCursorPos() < (int)m_strEdit.size())
        {
          MoveCursor(1);
          Backspace();
        }
        break;
      default:  //use character input
        // When we support text input method, we only accept text by gui text message.
        if (!g_Windowing.IsTextInputEnabled())
	        Character(ch);
	        //Character(action.GetUnicode());
        break;
      }
    }
  }
  else // unhandled by us - let's see if the baseclass wants it
    handled = CGUIDialog::OnAction(action);

  if (handled && m_pCharCallback)
  { // we did _something_, so make sure our search message filter is reset
    m_pCharCallback(this, GetText());
  }
  return handled;
}
Ejemplo n.º 2
0
bool CGUIEditControl::OnAction(const CAction &action)
{
  ValidateCursor();

  if (m_inputType != INPUT_TYPE_READONLY)
  {
    if (action.GetID() == ACTION_BACKSPACE)
    {
      // backspace
      if (m_cursorPos)
      {
        if (!ClearMD5())
          m_text2.erase(--m_cursorPos, 1);
        UpdateText();
      }
      return true;
    }
    else if (action.GetID() == ACTION_MOVE_LEFT ||
             action.GetID() == ACTION_CURSOR_LEFT)
    {
      if (m_cursorPos > 0)
      {
        m_cursorPos--;
        UpdateText(false);
        return true;
      }
    }
    else if (action.GetID() == ACTION_MOVE_RIGHT ||
             action.GetID() == ACTION_CURSOR_RIGHT)
    {
      if ((unsigned int) m_cursorPos < m_text2.size())
      {
        m_cursorPos++;
        UpdateText(false);
        return true;
      }
    }
    else if (action.GetID() == ACTION_PASTE)
    {
      ClearMD5();
      OnPasteClipboard();
      return true;
    }
    else if (action.GetID() >= KEY_VKEY && action.GetID() < KEY_ASCII && m_edit.empty())
    {
      // input from the keyboard (vkey, not ascii)
      BYTE b = action.GetID() & 0xFF;
      if (b == XBMCVK_HOME)
      {
        m_cursorPos = 0;
        UpdateText(false);
        return true;
      }
      else if (b == XBMCVK_END)
      {
        m_cursorPos = m_text2.length();
        UpdateText(false);
        return true;
      }
      if (b == XBMCVK_LEFT && m_cursorPos > 0)
      {
        m_cursorPos--;
        UpdateText(false);
        return true;
      }
      if (b == XBMCVK_RIGHT && m_cursorPos < m_text2.length())
      {
        m_cursorPos++;
        UpdateText(false);
        return true;
      }
      if (b == XBMCVK_DELETE)
      {
        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();
        }
        return true;
      }
      else if (b == XBMCVK_RETURN || b == XBMCVK_NUMPADENTER)
      {
        // enter - send click message, but otherwise ignore
        SEND_CLICK_MESSAGE(GetID(), GetParentID(), 1);
        return true;
      }
      else if (b == XBMCVK_ESCAPE)
      { // escape - fallthrough to default action
        return CGUIButtonControl::OnAction(action);
      }
    }
    else if (action.GetID() >= KEY_ASCII)
    {
      // input from the keyboard
      int ch = action.GetUnicode();
      // ignore non-printing characters
      if ( !((0 <= ch && ch < 0x8) || (0xE <= ch && ch < 0x1B) || (0x1C <= ch && ch < 0x20)) )
      {
      switch (ch)
      {
      case 9:  // tab, ignore
      case 11: // Non-printing character, ignore
      case 12: // Non-printing character, ignore
        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;
        }
      case 127:
        { // delete
          if (m_cursorPos < m_text2.length())
          {
            if (!ClearMD5())
              m_text2.erase(m_cursorPos, 1);
          }
        break;
        }
      default:
        {
          if (!g_Windowing.IsTextInputEnabled())
          {
            ClearMD5();
            m_edit.clear();
            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();
      m_edit.clear();
      OnSMSCharacter(action.GetID() - REMOTE_0);
      return true;
    }
    else if (action.GetID() == ACTION_INPUT_TEXT)
    {
      m_edit.clear();
      std::wstring str;
      g_charsetConverter.utf8ToW(action.GetText(), str);
      m_text2.insert(m_cursorPos, str);
      m_cursorPos += str.size();
      UpdateText();
      return true;
    }
  }
  return CGUIButtonControl::OnAction(action);
}