bool ScrollContainerWindow::OnEvent(const TBWidgetEvent &ev) { if (ev.type == EVENT_TYPE_CLICK) { if (ev.target->GetID() == TBIDC("add img")) { TBButton *button = TBSafeCast<TBButton>(ev.target); TBSkinImage *skin_image = new TBSkinImage; skin_image->SetSkinBg(TBIDC("Icon16")); button->GetContentRoot()->AddChild(skin_image, WIDGET_Z_BOTTOM); return true; } else if (ev.target->GetID() == TBIDC("new buttons")) { for(int i = 0; i < ev.target->data.GetInt(); i++) { TBStr str; str.SetFormatted("Remove %d", i); TBButton *button = new TBButton; button->SetID(TBIDC("remove button")); button->SetText(str); ev.target->GetParent()->AddChild(button); } return true; } else if (ev.target->GetID() == TBIDC("new buttons delayed")) { for(int i = 0; i < ev.target->data.GetInt(); i++) { TBMessageData *data = new TBMessageData(); data->id1 = ev.target->GetParent()->GetID(); data->v1.SetInt(i); PostMessageDelayed(TBIDC("new button"), data, 100 + i * 500); } return true; } else if (ev.target->GetID() == TBIDC("remove button")) { ev.target->GetParent()->RemoveChild(ev.target); delete ev.target; return true; } else if (ev.target->GetID() == TBIDC("showpopupmenu1")) { if (TBMenuWindow *menu = new TBMenuWindow(ev.target, TBIDC("popupmenu1"))) menu->Show(&popup_menu_source, TBPopupAlignment()); return true; } else if (ev.target->GetID() == TBIDC("popupmenu1")) { TBStr str; str.SetFormatted("Menu event received!\nref_id: %d", (int)ev.ref_id); TBMessageWindow *msg_win = new TBMessageWindow(this, TBIDC("popup_dialog")); msg_win->Show("Info", str); return true; } } return DemoWindow::OnEvent(ev); }
void TBSelectDropdown::OpenWindow() { if (!m_source || !m_source->GetNumItems() || m_window_pointer.Get()) return; if (TBMenuWindow *window = new TBMenuWindow(this, TBIDC("TBSelectDropdown.window"))) { m_window_pointer.Set(window); window->SetSkinBg(TBIDC("TBSelectDropdown.window")); window->Show(m_source, TBPopupAlignment(), GetValue()); } }
void TBSimpleLayoutItemWidget::OpenSubMenu() { if (m_menu) return; // Open a new menu window for the submenu with this widget as target m_menu = new TBMenuWindow(this, TBIDC("submenu")); if (m_menu) { SetState(WIDGET_STATE_SELECTED, true); m_menu->AddListener(this); m_menu->Show(m_source, TBPopupAlignment(TB_ALIGN_RIGHT), -1); } }
bool TBEditField::OnEvent(const TBWidgetEvent &ev) { if (ev.type == EVENT_TYPE_CHANGED && ev.target == &m_scrollbar_x) { m_style_edit.SetScrollPos(m_scrollbar_x.GetValue(), m_style_edit.scroll_y); OnScroll(m_scrollbar_x.GetValue(), m_style_edit.scroll_y); return true; } else if (ev.type == EVENT_TYPE_CHANGED && ev.target == &m_scrollbar_y) { m_style_edit.SetScrollPos(m_style_edit.scroll_x, m_scrollbar_y.GetValue()); OnScroll(m_style_edit.scroll_x, m_scrollbar_y.GetValue()); return true; } else if (ev.type == EVENT_TYPE_WHEEL && ev.modifierkeys == TB_MODIFIER_NONE) { int old_val = m_scrollbar_y.GetValue(); m_scrollbar_y.SetValue(old_val + ev.delta_y * TBSystem::GetPixelsPerLine()); return m_scrollbar_y.GetValue() != old_val; } else if (ev.type == EVENT_TYPE_POINTER_DOWN && ev.target == this) { TBRect padding_rect = GetPaddingRect(); if (m_style_edit.MouseDown( TBPoint(ev.target_x - padding_rect.x, ev.target_y - padding_rect.y), 1, ev.count, TB_MODIFIER_NONE, ev.touch)) { // Post a message to start selection scroll PostMessageDelayed(TBIDC("selscroll"), nullptr, SELECTION_SCROLL_DELAY); return true; } } else if (ev.type == EVENT_TYPE_POINTER_MOVE && ev.target == this) { TBRect padding_rect = GetPaddingRect(); return m_style_edit.MouseMove(TBPoint(ev.target_x - padding_rect.x, ev.target_y - padding_rect.y)); } else if (ev.type == EVENT_TYPE_POINTER_UP && ev.target == this) { TBRect padding_rect = GetPaddingRect(); return m_style_edit.MouseUp(TBPoint(ev.target_x - padding_rect.x, ev.target_y - padding_rect.y), 1, TB_MODIFIER_NONE, ev.touch); } else if (ev.type == EVENT_TYPE_KEY_DOWN) { return m_style_edit.KeyDown(ev.key, ev.special_key, ev.modifierkeys); } else if (ev.type == EVENT_TYPE_KEY_UP) { return true; } else if ((ev.type == EVENT_TYPE_CLICK && ev.target->GetID() == TBIDC("popupmenu")) || (ev.type == EVENT_TYPE_SHORTCUT)) { if (ev.ref_id == TBIDC("cut") && !m_style_edit.packed.read_only) m_style_edit.Cut(); else if (ev.ref_id == TBIDC("copy")) m_style_edit.Copy(); else if (ev.ref_id == TBIDC("paste") && !m_style_edit.packed.read_only) m_style_edit.Paste(); else if (ev.ref_id == TBIDC("delete") && !m_style_edit.packed.read_only) m_style_edit.Delete(); else if (ev.ref_id == TBIDC("undo") && !m_style_edit.packed.read_only) m_style_edit.Undo(); else if (ev.ref_id == TBIDC("redo") && !m_style_edit.packed.read_only) m_style_edit.Redo(); else if (ev.ref_id == TBIDC("selectall")) m_style_edit.selection.SelectAll(); else return false; return true; } else if (ev.type == EVENT_TYPE_CONTEXT_MENU && ev.target == this) { TBPoint pos_in_root(ev.target_x, ev.target_y); ev.target->ConvertToRoot(pos_in_root.x, pos_in_root.y); if (TBMenuWindow *menu = new TBMenuWindow(ev.target, TBIDC("popupmenu"))) { TBGenericStringItemSource *source = menu->GetList()->GetDefaultSource(); source->AddItem(new TBGenericStringItem(g_tb_lng->GetString(TBIDC("cut")), TBIDC("cut"))); source->AddItem(new TBGenericStringItem(g_tb_lng->GetString(TBIDC("copy")), TBIDC("copy"))); source->AddItem(new TBGenericStringItem(g_tb_lng->GetString(TBIDC("paste")), TBIDC("paste"))); source->AddItem(new TBGenericStringItem(g_tb_lng->GetString(TBIDC("delete")), TBIDC("delete"))); source->AddItem(new TBGenericStringItem("-")); source->AddItem(new TBGenericStringItem(g_tb_lng->GetString(TBIDC("selectall")), TBIDC("selectall"))); menu->Show(source, TBPopupAlignment(pos_in_root), -1); } return true; } return false; }
virtual bool OnEvent(const TBWidgetEvent &ev) { if (ev.type == EVENT_TYPE_CLICK) { TBEditField *edit = GetWidgetByIDAndType<TBEditField>(TBIDC("editfield")); if (!edit) return false; if (ev.target->GetID() == TBIDC("clear")) { edit->SetText(""); return true; } else if (ev.target->GetID() == TBIDC("undo")) { edit->GetStyleEdit()->Undo(); return true; } else if (ev.target->GetID() == TBIDC("redo")) { edit->GetStyleEdit()->Redo(); return true; } else if (ev.target->GetID() == TBIDC("menu")) { static TBGenericStringItemSource source; if (!source.GetNumItems()) { source.AddItem(new TBGenericStringItem("Default font", TBIDC("default font"))); source.AddItem(new TBGenericStringItem("Default font (larger)", TBIDC("large font"))); source.AddItem(new TBGenericStringItem("RGB font (Neon)", TBIDC("rgb font Neon"))); source.AddItem(new TBGenericStringItem("RGB font (Orangutang)", TBIDC("rgb font Orangutang"))); source.AddItem(new TBGenericStringItem("RGB font (Orange)", TBIDC("rgb font Orange"))); source.AddItem(new TBGenericStringItem("-")); source.AddItem(new TBGenericStringItem("Glyph cache stresstest (CJK)", TBIDC("CJK"))); source.AddItem(new TBGenericStringItem("-")); source.AddItem(new TBGenericStringItem("Toggle wrapping", TBIDC("toggle wrapping"))); source.AddItem(new TBGenericStringItem("-")); source.AddItem(new TBGenericStringItem("Align left", TBIDC("align left"))); source.AddItem(new TBGenericStringItem("Align center", TBIDC("align center"))); source.AddItem(new TBGenericStringItem("Align right", TBIDC("align right"))); } if (TBMenuWindow *menu = new TBMenuWindow(ev.target, TBIDC("popup_menu"))) menu->Show(&source, TBPopupAlignment()); return true; } else if (ev.target->GetID() == TBIDC("popup_menu")) { if (ev.ref_id == TBIDC("default font")) edit->SetFontDescription(TBFontDescription()); else if (ev.ref_id == TBIDC("large font")) { TBFontDescription fd = g_font_manager->GetDefaultFontDescription(); fd.SetSize(28); edit->SetFontDescription(fd); } else if (ev.ref_id == TBIDC("rgb font Neon")) { TBFontDescription fd = edit->GetCalculatedFontDescription(); fd.SetID(TBIDC("Neon")); edit->SetFontDescription(fd); } else if (ev.ref_id == TBIDC("rgb font Orangutang")) { TBFontDescription fd = edit->GetCalculatedFontDescription(); fd.SetID(TBIDC("Orangutang")); edit->SetFontDescription(fd); } else if (ev.ref_id == TBIDC("rgb font Orange")) { TBFontDescription fd = edit->GetCalculatedFontDescription(); fd.SetID(TBIDC("Orange")); edit->SetFontDescription(fd); } else if (ev.ref_id == TBIDC("CJK")) { TBTempBuffer buf; for (int i = 0, cp = 0x4E00; cp <= 0x9FCC; cp++, i++) { char utf8[8]; int len = utf8::encode(cp, utf8); buf.Append(utf8, len); if (i % 64 == 63) buf.Append("\n", 1); } edit->GetStyleEdit()->SetText(buf.GetData(), buf.GetAppendPos()); } else if (ev.ref_id == TBIDC("toggle wrapping")) edit->SetWrapping(!edit->GetWrapping()); else if (ev.ref_id == TBIDC("align left")) edit->SetTextAlign(TB_TEXT_ALIGN_LEFT); else if (ev.ref_id == TBIDC("align center")) edit->SetTextAlign(TB_TEXT_ALIGN_CENTER); else if (ev.ref_id == TBIDC("align right")) edit->SetTextAlign(TB_TEXT_ALIGN_RIGHT); return true; } } return DemoWindow::OnEvent(ev); }