#include "entrybox.h" namespace sigc { SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE } EntryBox::Entry::Entry(const std::string& content, std::function on_activate, unsigned length) : Gtk::Entry(), on_activate(on_activate) { set_max_length(length); set_text(content); signal_activate().connect([this](){ if(this->on_activate) this->on_activate(get_text()); }); } EntryBox::Button::Button(const std::string& label, std::function on_activate) : Gtk::Button(label), on_activate(on_activate) { signal_clicked().connect([this](){ if(this->on_activate) this->on_activate(); }); } EntryBox::ToggleButton::ToggleButton(const std::string& label, std::function on_activate) : Gtk::ToggleButton(label), on_activate(on_activate) { signal_clicked().connect([this](){ if(this->on_activate) this->on_activate(); }); } EntryBox::Label::Label(std::function update) : Gtk::Label(), update(update) { if(this->update) this->update(-1, ""); } EntryBox::EntryBox() : Gtk::Box(Gtk::ORIENTATION_VERTICAL), upper_box(Gtk::ORIENTATION_HORIZONTAL), lower_box(Gtk::ORIENTATION_HORIZONTAL) { pack_start(upper_box, Gtk::PACK_SHRINK); pack_start(lower_box, Gtk::PACK_SHRINK); } void EntryBox::clear() { hide(); entries.clear(); buttons.clear(); toggle_buttons.clear(); labels.clear(); } void EntryBox::show() { std::vector focus_chain; for(auto& entry: entries) { upper_box.pack_start(entry, Gtk::PACK_SHRINK); focus_chain.emplace_back(&entry); } for(auto& button: buttons) upper_box.pack_start(button, Gtk::PACK_SHRINK); for(auto& toggle_button: toggle_buttons) upper_box.pack_start(toggle_button, Gtk::PACK_SHRINK); for(auto& label: labels) lower_box.pack_start(label, Gtk::PACK_SHRINK); upper_box.set_focus_chain(focus_chain); show_all(); if(entries.size()>0) { entries.begin()->grab_focus(); entries.begin()->select_region(0, entries.begin()->get_text_length()); } }