void WidgetDropDown::ProcessEvent(Core::Event& event)
{
	// Process the button onclick
	if (event == "click" &&
		!parent_element->IsDisabled())
	{

		if (event.GetCurrentElement()->GetParentNode() == selection_element)
		{
			// Find the element in the options and fire the selection event
			for (size_t i = 0; i < options.size(); i++)
			{
				if (options[i].GetElement() == event.GetCurrentElement())
				{
					if (options[i].IsSelectable())
					{
						SetSelection(i);
						event.StopPropagation();

						ShowSelectBox(false);
						parent_element->Focus();
					}
				}
			}
		}
		else
		{
			// We have to check that this event isn't targeted to an element
			// inside the selection box as we'll get all events coming from our
			// root level select element as well as the ones coming from options (which
			// get caught in the above if)
			Core::Element* element = event.GetTargetElement();
			while (element && element != parent_element)
			{
				if (element == selection_element)
					return;
				element = element->GetParentNode();
			}

			if (selection_element->GetProperty< int >("visibility") == Core::VISIBILITY_HIDDEN)
				ShowSelectBox(true);
			else
				ShowSelectBox(false);
		}		
	}
	else if (event == "blur" && event.GetTargetElement() == parent_element)
		ShowSelectBox(false);
}
Ejemplo n.º 2
0
void WidgetDropDown::ProcessEvent(Core::Event& event)
{
	if (parent_element->IsDisabled()) 
		return;

	// Process the button onclick
	if (event == "click")
	{

		if (event.GetCurrentElement()->GetParentNode() == selection_element)
		{
			// Find the element in the options and fire the selection event
			for (size_t i = 0; i < options.size(); i++)
			{
				if (options[i].GetElement() == event.GetCurrentElement())
				{
					if (options[i].IsSelectable())
					{
						SetSelection(i);
						event.StopPropagation();

						ShowSelectBox(false);
						parent_element->Focus();
					}
				}
			}
		}
		else
		{
			// We have to check that this event isn't targeted to an element
			// inside the selection box as we'll get all events coming from our
			// root level select element as well as the ones coming from options (which
			// get caught in the above if)
			Core::Element* element = event.GetTargetElement();
			while (element && element != parent_element)
			{
				if (element == selection_element)
					return;
				element = element->GetParentNode();
			}

			if (selection_element->GetProperty< int >("visibility") == Core::VISIBILITY_HIDDEN)
				ShowSelectBox(true);
			else
				ShowSelectBox(false);
		}		
	}
	else if (event == "blur" && event.GetTargetElement() == parent_element)
	{
		ShowSelectBox(false);
	}
	else if (event == "keydown")
	{
		Core::Input::KeyIdentifier key_identifier = (Core::Input::KeyIdentifier) event.GetParameter< int >("key_identifier", 0);

		switch (key_identifier)
		{
			case Core::Input::KI_UP:
				SetSelection( (selected_option - 1 + options.size()) % options.size() );
				break;
			case Core::Input::KI_DOWN:		
				SetSelection( (selected_option + 1) % options.size() );
				break;
			default:
				break;
		}
	}

	if (event.GetTargetElement() == parent_element)
	{
		if (event == "focus")
		{
			value_element->SetPseudoClass("focus", true);
			button_element->SetPseudoClass("focus", true);
		}
		else if (event == "blur")
		{
			value_element->SetPseudoClass("focus", false);
			button_element->SetPseudoClass("focus", false);
		}
	}

}