bool TBSelectList::OnEvent(const TBWidgetEvent &ev) { if (ev.type == EVENT_TYPE_CLICK && ev.target->GetParent() == m_layout.GetContentRoot()) { // SetValue (EVENT_TYPE_CHANGED) might cause something to delete this (f.ex closing // the dropdown menu. We want to sent another event, so ensure we're still around. TBWidgetSafePointer this_widget(this); int index = ev.target->data.GetInt(); SetValue(index); // If we're still around, invoke the click event too. if (this_widget.Get()) { TBSelectList *target_list = this; // If the parent window is a TBMenuWindow, we will iterate up the event destination // chain to find the top TBMenuWindow and invoke the event there. // That way events in submenus will reach the caller properly, and seem like it was // invoked on the top menu. TBWindow *window = GetParentWindow(); while (TBMenuWindow *menu_win = TBSafeCast<TBMenuWindow>(window)) { target_list = menu_win->GetList(); window = menu_win->GetEventDestination()->GetParentWindow(); } // Invoke the click event on the target list TBWidgetEvent ev(EVENT_TYPE_CLICK); if (TBWidget *widget = GetItemWidget(m_value)) ev.ref_id = widget->GetID(); target_list->InvokeEvent(ev); } return true; } else if (ev.type == EVENT_TYPE_KEY_DOWN) { if (ChangeValue(ev.special_key)) return true; // Give the scroll container a chance to handle the key so it may // scroll. This matters if the list itself is focused instead of // some child view of any select item (since that would have passed // the container already) if (GetScrollContainer()->OnEvent(ev)) return true; } return false; }
bool TBButton::OnEvent(const TBWidgetEvent &ev) { if (CanToggle() && ev.type == EVENT_TYPE_CLICK && ev.target == this) { TBWidgetSafePointer this_widget(this); // Toggle the value, if it's not a grouped widget with value on. if (!(GetGroupID() && GetValue())) SetValue(!GetValue()); if (!this_widget.Get()) return true; // We got removed so we actually handled this event. // Intentionally don't return true for this event. We want it to continue propagating. } return TBWidget::OnEvent(ev); }
bool TBMenuWindow::OnEvent(const TBWidgetEvent &ev) { if (ev.type == EVENT_TYPE_CLICK && &m_select_list == ev.target) { TBWidgetSafePointer this_widget(this); // Invoke the click on the target TBWidgetEvent target_ev(EVENT_TYPE_CLICK); target_ev.ref_id = ev.ref_id; InvokeEvent(target_ev); // If target got deleted, close if (this_widget.Get()) Close(); return true; } return TBPopupWindow::OnEvent(ev); }
bool TBButton::OnEvent(const TBWidgetEvent &ev) { if (m_toggle_mode && ev.type == EVENT_TYPE_CLICK && ev.target == this) { TBWidgetSafePointer this_widget(this); SetValue(!GetValue()); if (!this_widget.Get()) return true; // We got removed so we actually handled this event. // Invoke a changed event. TBWidgetEvent ev(EVENT_TYPE_CHANGED); InvokeEvent(ev); if (!this_widget.Get()) return true; // We got removed so we actually handled this event. // Intentionally don't return true for this event. We want it to continue propagating. } return TBWidget::OnEvent(ev); }
bool TBMessageWindow::OnEvent(const TBWidgetEvent &ev) { if (ev.type == EVENT_TYPE_CLICK && ev.target->IsOfType<TBButton>()) { TBWidgetSafePointer this_widget(this); // Invoke the click on the target TBWidgetEvent target_ev(EVENT_TYPE_CLICK); target_ev.ref_id = ev.target->GetID(); InvokeEvent(target_ev); // If target got deleted, close if (this_widget.Get()) Close(); return true; } else if (ev.type == EVENT_TYPE_KEY_DOWN && ev.special_key == TB_KEY_ESC) { TBWidgetEvent click_ev(EVENT_TYPE_CLICK); m_close_button.InvokeEvent(click_ev); return true; } return TBWindow::OnEvent(ev); }