Callback_v1<RadioButton*> RadioButton_Impl::uncheck_radio_buttons(GUIComponent *parent) { Callback_v1<RadioButton*> callback; std::vector<GUIComponent*> group = parent->get_child_component_group(radio->get_group_name()); std::vector<GUIComponent*>::size_type i; for (i=0; i < group.size(); i++) { RadioButton *rb = dynamic_cast<RadioButton*>(group[i]); if (rb && rb->get_group_name() == radio->get_group_name()) { if (callback.is_null() && !rb->func_group_selection_changed().is_null()) { callback = rb->func_group_selection_changed(); } if (rb->impl->part_checker.get_pseudo_class(CssStr::checked)) { if (!rb->impl->func_unselected.is_null()) rb->impl->func_unselected.invoke(); rb->impl->part_checker.set_pseudo_class(CssStr::checked, false); rb->impl->part_checker.set_pseudo_class(CssStr::unchecked, true); rb->set_selected_in_component_group(false); rb->request_repaint(); } } } return callback; }
void Tab_Impl::on_header_page_selected(TabPage *tab_page) { std::vector<TabPage*>::iterator it; for (it = pages.begin(); it != pages.end(); ++it) { if ((*it) != tab_page) (*it)->set_visible(false); else (*it)->set_visible(true); } if (!func_page_selected.is_null()) func_page_selected.invoke(tab_page); tab->request_repaint(); }
void ToolBar_Impl::unselect_all(ToolBarItem_Impl *ignore) { std::vector<ToolBarItem>::iterator it; for (it = items.begin(); it != items.end(); ++it) { ToolBarItem &item = *it; if (item.impl.get() == ignore) continue; if (item.is_pressed()) { item.impl->pressed = false; if (!func_item_unselected.is_null()) { func_item_unselected.invoke(item); } } } }
void TabHeader_Impl::on_process_message(std::shared_ptr<GUIMessage> &msg) { if(component->is_enabled()) { std::shared_ptr<GUIMessage_Input> input_msg = std::dynamic_pointer_cast<GUIMessage_Input>(msg); if (input_msg) { const InputEvent &e = input_msg->input_event; Point pos = e.mouse_pos; if (e.type == InputEvent::pressed && e.id == mouse_left) { std::vector<Handle>::iterator it; for (it = tabs.begin(); it != tabs.end(); ++it) { bool inside = (*it).rect.contains(pos); if (inside) { unselect_all(); (*it).part.set_pseudo_class(CssStr::selected, true); (*it).part.set_pseudo_class(CssStr::normal, false); component->request_repaint(); if (!func_page_selected.is_null()) func_page_selected.invoke((*it).tab_page); } } msg->consumed = true; } else if (e.type == InputEvent::pointer_moved) { std::vector<Handle>::iterator it; for (it = tabs.begin(); it != tabs.end(); ++it) { bool inside = (*it).rect.contains(pos); if (inside) { if ((*it).part.get_pseudo_class(CssStr::selected)) return; (*it).part.set_pseudo_class(CssStr::hover, true); (*it).part.set_pseudo_class(CssStr::normal, false); component->request_repaint(); msg->consumed = true; } else if ((*it).part.get_pseudo_class(CssStr::hover)) { (*it).part.set_pseudo_class(CssStr::hover, false); (*it).part.set_pseudo_class(CssStr::normal, true); component->request_repaint(); msg->consumed = true; } } } else if (e.type == InputEvent::pressed && e.id == keycode_left) { int next_page = selected_page - 1; if (next_page < 0) next_page = tabs.size()-1; unselect_all(); select_page(next_page); if (!func_page_selected.is_null()) func_page_selected.invoke(tabs[next_page].tab_page); component->select_page(next_page); msg->consumed = true; } else if (e.type == InputEvent::pressed && e.id == keycode_right) { int next_page = selected_page + 1; if (next_page >= tabs.size()) next_page = 0; unselect_all(); select_page(next_page); if (!func_page_selected.is_null()) func_page_selected.invoke(tabs[next_page].tab_page); component->request_repaint(); msg->consumed = true; } else if (e.type == InputEvent::pressed && (e.id == keycode_up || e.id == keycode_down)) { // block focus switching with up/down when in tab header. msg->consumed = true; } } std::shared_ptr<GUIMessage_Pointer> pointer = std::dynamic_pointer_cast<GUIMessage_Pointer>(msg); if (pointer) { if (pointer->pointer_type == GUIMessage_Pointer::pointer_leave) { std::vector<Handle>::iterator it; for (it = tabs.begin(); it != tabs.end(); ++it) { (*it).part.set_pseudo_class(CssStr::hover, false); (*it).part.set_pseudo_class(CssStr::normal, true); } component->request_repaint(); } } std::shared_ptr<GUIMessage_FocusChange> focus_change_msg = std::dynamic_pointer_cast<GUIMessage_FocusChange>(msg); if (focus_change_msg) { if (focus_change_msg->focus_type == GUIMessage_FocusChange::gained_focus) { component->set_pseudo_class(CssStr::focused, true); component->request_repaint(); } else { component->set_pseudo_class(CssStr::focused, false); component->request_repaint(); } msg->consumed = true; } } }
void RadioButton_Impl::on_process_message(std::shared_ptr<GUIMessage> &msg) { if (!radio->is_enabled()) return; std::shared_ptr<GUIMessage_Input> input_msg = std::dynamic_pointer_cast<GUIMessage_Input>(msg); if (input_msg) { const InputEvent &e = input_msg->input_event; if (e.type == InputEvent::pressed && e.id == mouse_left) { part_checker.set_pseudo_class(CssStr::pressed, true); radio->request_repaint(); msg->consumed = true; } else if (e.type == InputEvent::released && e.id == mouse_left) { if ((part_checker.get_pseudo_class(CssStr::checked) == false)) { Callback_v1<RadioButton*> cb = uncheck_radio_buttons(radio->get_parent_component()); part_checker.set_pseudo_class(CssStr::pressed, false); radio->set_selected(true); if (!cb.is_null()) cb.invoke(radio); if (!func_selected.is_null()) func_selected.invoke(); } else { part_checker.set_pseudo_class(CssStr::pressed, false); radio->request_repaint(); } radio->set_focus(true); msg->consumed = true; } else if (e.type == InputEvent::pressed && (e.id == keycode_left || e.id == keycode_up)) { std::vector<GUIComponent*> group = radio->get_parent_component()->get_child_component_group(radio->get_component_group_name()); // find previous visible & enabled radiobutton in the same group: GUIComponent *comp = radio->get_previous_sibling(); if (comp == 0) comp = group.back(); while (comp != radio) { if (comp->is_visible() && comp->is_enabled() && comp->get_component_group_name() == radio->get_component_group_name()) { RadioButton *focus_comp = dynamic_cast<RadioButton*>(comp); if (focus_comp) { Callback_v1<RadioButton*> cb = uncheck_radio_buttons(radio->get_parent_component()); focus_comp->set_selected(true); if (!cb.is_null()) cb.invoke(focus_comp); if (!focus_comp->func_selected().is_null()) focus_comp->func_selected().invoke(); focus_comp->set_focus(); break; } } if (!comp->get_previous_sibling() || comp->get_previous_sibling()->get_component_group_name() != radio->get_component_group_name()) { // reach first item in group, loop around from the last: comp = group.back(); } else comp = comp->get_previous_sibling(); } msg->consumed = true; } else if (e.type == InputEvent::pressed && (e.id == keycode_right || e.id == keycode_down)) { std::vector<GUIComponent*> group = radio->get_parent_component()->get_child_component_group(radio->get_component_group_name()); // find next visible & enabled radiobutton in the same group: GUIComponent *comp = radio->get_next_sibling(); if (comp == 0 || comp->get_component_group_name() != radio->get_component_group_name()) comp = group.front(); while (comp != radio) { if (comp->is_visible() && comp->is_enabled() && comp->get_component_group_name() == radio->get_component_group_name()) { RadioButton *focus_comp = dynamic_cast<RadioButton*>(comp); if (focus_comp) { Callback_v1<RadioButton*> cb = uncheck_radio_buttons(radio->get_parent_component()); focus_comp->set_selected(true); if (!cb.is_null()) cb.invoke(focus_comp); if (!focus_comp->func_selected().is_null()) focus_comp->func_selected().invoke(); focus_comp->set_focus(); break; } } if (!comp->get_previous_sibling() || comp->get_previous_sibling()->get_component_group_name() != radio->get_component_group_name()) { // reach first item in group, loop around from the last: comp = group.back(); } else comp = comp->get_next_sibling(); } msg->consumed = true; } } std::shared_ptr<GUIMessage_Pointer> pointer = std::dynamic_pointer_cast<GUIMessage_Pointer>(msg); if (pointer) { if (pointer->pointer_type == GUIMessage_Pointer::pointer_enter) { part_checker.set_pseudo_class(CssStr::hover, true); radio->request_repaint(); } else { part_checker.set_pseudo_class(CssStr::hover, false); radio->request_repaint(); } } std::shared_ptr<GUIMessage_FocusChange> focus_change_msg = std::dynamic_pointer_cast<GUIMessage_FocusChange>(msg); if (focus_change_msg) { if (focus_change_msg->focus_type == GUIMessage_FocusChange::gained_focus) { radio->set_pseudo_class(CssStr::focused, true); if (!radio->is_selected()) { Callback_v1<RadioButton*> cb = uncheck_radio_buttons(radio->get_parent_component()); radio->set_selected(true); if (!cb.is_null()) cb.invoke(radio); if (!func_selected.is_null()) func_selected.invoke(); } radio->request_repaint(); } else { radio->set_pseudo_class(CssStr::focused, false); radio->request_repaint(); } msg->consumed = true; } }
void ToolBar_Impl::on_process_message(std::shared_ptr<GUIMessage> &msg) { if (!toolbar->is_enabled()) return; std::shared_ptr<GUIMessage_Input> input_msg = std::dynamic_pointer_cast<GUIMessage_Input>(msg); if (input_msg) { const InputEvent &e = input_msg->input_event; if (e.type == InputEvent::released && e.id == mouse_right) { int index = find_item_at(e.mouse_pos); if (!func_mouse_right_up.is_null()) func_mouse_right_up.invoke(e.mouse_pos, index); } else if (mouse_mode == mouse_mode_normal) { int index = find_item_at(e.mouse_pos); if (index == -1) { if (index_hot_item != -1) { index_hot_item = -1; toolbar->request_repaint(); } return; } if (e.type == InputEvent::pressed && e.id == mouse_left) { index_hot_item = -1; index_pressed_item = index; mouse_mode = mouse_mode_pressed; toolbar->request_repaint(); toolbar->capture_mouse(true); } else { index_hot_item = index; toolbar->request_repaint(); } } else if (mouse_mode == mouse_mode_pressed) { if (e.type == InputEvent::released && e.id == mouse_left) { toolbar->capture_mouse(false); mouse_mode = mouse_mode_normal; int index = find_item_at(e.mouse_pos); bool perform_click = (index == index_pressed_item); bool pressed_state = items[index_pressed_item].is_pressed(); if (pressed_state == true && single_select_mode) { return; } if (items[index_pressed_item].impl->toggling && perform_click) items[index_pressed_item].impl->pressed = !items[index_pressed_item].impl->pressed; index_pressed_item = -1; index_hot_item = index; toolbar->request_repaint(); if (perform_click) { if (!func_item_clicked.is_null()) func_item_clicked.invoke(items[index]); if (items[index].is_toggling() && single_select_mode) { unselect_all(items[index].impl.get()); if (!func_item_selected.is_null()) func_item_selected.invoke(items[index]); } } } } } std::shared_ptr<GUIMessage_Pointer> pointer = std::dynamic_pointer_cast<GUIMessage_Pointer>(msg); if (pointer) { if (pointer->pointer_type == GUIMessage_Pointer::pointer_leave) { if (index_hot_item != -1) { index_hot_item = -1; toolbar->request_repaint(); } } } }