Example #1
0
bool CDropDown::HandleMessage(CMessage* pMessage)
{
	bool bHandled = false;
	CRect SubRect(m_WindowRect);
	SubRect.Grow(-3);

	if (pMessage)
	{
		switch(pMessage->MessageType())
		{
		case CMessage::KEYBOARD_KEYDOWN:
    {
      CKeyboardMessage* pKeyboardMessage = dynamic_cast<CKeyboardMessage*>(pMessage);
      if (pKeyboardMessage && pMessage->Destination() == this)
      {
        switch (pKeyboardMessage->Key)
        {
          case SDLK_UP:
            SelectItem(GetSelectedIndex() - 1);
						ShowListBox();
            break;
          case SDLK_DOWN:
            SelectItem(GetSelectedIndex() + 1);
						ShowListBox();
            break;
          case SDLK_RETURN:
          case SDLK_SPACE:
						HideListBox();
            break;
          case SDLK_TAB:
						HideListBox();
            // intentional fall through: the parent frame will change focused widget
          default:
            // Forward all key downs to parent
            CMessageServer::Instance().QueueMessage(new CKeyboardMessage(CMessage::KEYBOARD_KEYDOWN, m_pParentWindow, this,
                  pKeyboardMessage->ScanCode, pKeyboardMessage->Modifiers, pKeyboardMessage->Key, pKeyboardMessage->Unicode));
            break;
        }
      }
      break;
    }
		case CMessage::MOUSE_BUTTONDOWN:
		{
			CMouseMessage* pMouseMessage = dynamic_cast<CMouseMessage*>(pMessage);
			if (pMouseMessage->Button == CMouseMessage::LEFT)
			{
				if (m_pListBox->IsVisible() &&
					m_pDropButton->GetWindowRect().SizeRect().HitTest(m_pDropButton->ViewToWindow(pMouseMessage->Point)) != CRect::RELPOS_INSIDE &&
					m_pListBox->GetWindowRect().SizeRect().HitTest(m_pListBox->ViewToWindow(pMouseMessage->Point)) != CRect::RELPOS_INSIDE)
				{
					HideListBox();
				}
			}
			break;
		}
		case CMessage::CTRL_SINGLELCLICK:
		{
			if (pMessage->Destination() == this)
			{
				if (pMessage->Source() == m_pDropButton)
				{
					if (m_pListBox->IsVisible())
					{
						HideListBox();
					}
					else
					{
						ShowListBox();
					}
					bHandled = true;
				}
			}
			break;
		}
		case CMessage::CTRL_VALUECHANGE:
		{
			TIntMessage* pCtrlMessage = dynamic_cast<TIntMessage*>(pMessage);
			if (pCtrlMessage && pMessage->Destination() == this)
			{
				if (pCtrlMessage->Source() == m_pListBox)
				{
					const SListItem& ListItem = m_pListBox->GetItem(pCtrlMessage->Value());
					SetWindowText(ListItem.sItemText);
					HideListBox();
					CMessageServer::Instance().QueueMessage(new TIntMessage(CMessage::CTRL_VALUECHANGE, m_pParentWindow, this, 0));
					bHandled = true;
				}
				else if (pCtrlMessage->Source() == m_pEditBox)
				{
					m_pListBox->SetAllSelections(false);
					HideListBox();
					CMessageServer::Instance().QueueMessage(new TIntMessage(CMessage::CTRL_VALUECHANGE, m_pParentWindow, this, 0));
					bHandled = true;
				}
			}
			break;
		}
		default :
			bHandled = CWindow::HandleMessage(pMessage);
			break;
		}
	}

	return bHandled;
}
Example #2
0
bool CDropDown::HandleMessage(CMessage* pMessage)
{
	bool bHandled = false;
	CRect SubRect(m_WindowRect);
	SubRect.Grow(-3);

	if (pMessage)
	{
		switch(pMessage->MessageType())
		{
		case CMessage::MOUSE_BUTTONDOWN:
		{
			CMouseMessage* pMouseMessage = dynamic_cast<CMouseMessage*>(pMessage);
			if (pMouseMessage->Button == CMouseMessage::LEFT)
			{
				if (m_pListBox->IsVisible() &&
					m_pDropButton->GetWindowRect().SizeRect().HitTest(m_pDropButton->ViewToWindow(pMouseMessage->Point)) != CRect::RELPOS_INSIDE &&
					m_pListBox->GetWindowRect().SizeRect().HitTest(m_pListBox->ViewToWindow(pMouseMessage->Point)) != CRect::RELPOS_INSIDE)
				{
					HideListBox();
				}
			}
			break;
		}
		case CMessage::CTRL_SINGLELCLICK:
		{
			if (pMessage->Destination() == this)
			{
				if (pMessage->Source() == m_pDropButton)
				{
					if (m_pListBox->IsVisible())
					{
						HideListBox();
					}
					else
					{
						ShowListBox();
					}
					bHandled = true;
				}
			}
			break;
		}
		case CMessage::CTRL_VALUECHANGE:
		{
			TIntMessage* pCtrlMessage = dynamic_cast<TIntMessage*>(pMessage);
			if (pCtrlMessage && pMessage->Destination() == this)
			{
				if (pCtrlMessage->Source() == m_pListBox)
				{
					const SListItem& ListItem = m_pListBox->GetItem(pCtrlMessage->Value());
					SetWindowText(ListItem.sItemText);
					HideListBox();
					CMessageServer::Instance().QueueMessage(new TIntMessage(CMessage::CTRL_VALUECHANGE, m_pParentWindow, this, 0));
					bHandled = true;
				}
				else if (pCtrlMessage->Source() == m_pEditBox)
				{
					m_pListBox->SetAllSelections(false);
					HideListBox();
					CMessageServer::Instance().QueueMessage(new TIntMessage(CMessage::CTRL_VALUECHANGE, m_pParentWindow, this, 0));
					bHandled = true;
				}
			}
			break;
		}
		default :
			bHandled = CWindow::HandleMessage(pMessage);
			break;
		}
	}

	return bHandled;
}