7 #include "gtkutil/dialog.h"
8 #include "gtkutil/filechooser.h"
9 #include "gtkutil/messagebox.h"
10 #include "gtkutil/window.h"
14 void init(int argc, char *argv[])
16 gtk_disable_setlocale();
17 gtk_init(&argc, &argv);
27 alert_response Widget::alert(std::string text, std::string title, alert_type type, alert_icon icon)
29 auto ret = gtk_MessageBox(*this, text.c_str(),
31 type == alert_type::OK ? eMB_OK :
32 type == alert_type::OKCANCEL ? eMB_OKCANCEL :
33 type == alert_type::YESNO ? eMB_YESNO :
34 type == alert_type::YESNOCANCEL ? eMB_YESNOCANCEL :
35 type == alert_type::NOYES ? eMB_NOYES :
37 icon == alert_icon::DEFAULT ? eMB_ICONDEFAULT :
38 icon == alert_icon::ERROR ? eMB_ICONERROR :
39 icon == alert_icon::WARNING ? eMB_ICONWARNING :
40 icon == alert_icon::QUESTION ? eMB_ICONQUESTION :
41 icon == alert_icon::ASTERISK ? eMB_ICONASTERISK :
45 ret == eIDOK ? alert_response::OK :
46 ret == eIDCANCEL ? alert_response::CANCEL :
47 ret == eIDYES ? alert_response::YES :
48 ret == eIDNO ? alert_response::NO :
52 const char *Widget::file_dialog(bool open, const char *title, const char *path,
53 const char *pattern, bool want_load, bool want_import,
56 return ::file_dialog(*this, open, title, path, pattern, want_load, want_import, want_save);
59 Window Window::create_dialog_window(const char *title, void func(), void *data, int default_w, int default_h)
61 return Window(::create_dialog_window(*this, title, func, data, default_w, default_h));
64 Window Window::create_modal_dialog_window(const char *title, ui_modal &dialog, int default_w, int default_h)
66 return Window(::create_modal_dialog_window(*this, title, dialog, default_w, default_h));
69 Window Window::create_floating_window(const char *title)
71 return Window(::create_floating_window(title, *this));
74 std::uint64_t Window::on_key_press(bool (*f)(Widget widget, ui_evkey *event, void *extra), void *extra)
76 auto pass = std::make_tuple(f, extra);
77 auto func = [](ui_widget *widget, GdkEventKey *event, void *pass_) -> bool {
78 using pass_t = decltype(pass);
79 auto &args = *(pass_t *) pass_;
80 auto func = std::get<0>(args);
81 auto pass = std::get<1>(args);
82 return func(Widget(widget), event, pass);
84 return g_signal_connect(G_OBJECT(*this), "key-press-event", (GCallback) +func, &pass);
87 Alignment::Alignment(float xalign, float yalign, float xscale, float yscale)
88 : Alignment(GTK_ALIGNMENT(gtk_alignment_new(xalign, yalign, xscale, yscale)))
91 Button::Button() : Button(GTK_BUTTON(gtk_button_new()))
94 Button::Button(const char *label) : Button(GTK_BUTTON(gtk_button_new_with_label(label)))
97 CheckButton::CheckButton(const char *label) : CheckButton(GTK_CHECK_BUTTON(gtk_check_button_new_with_label(label)))
100 HBox::HBox(bool homogenous, int spacing) : HBox(GTK_HBOX(gtk_hbox_new(homogenous, spacing)))
103 Label::Label(const char *label) : Label(GTK_LABEL(gtk_label_new(label)))
106 MenuItem::MenuItem(const char *label, bool mnemonic) : MenuItem(GTK_MENU_ITEM((mnemonic ? gtk_menu_item_new_with_mnemonic : gtk_menu_item_new_with_label)(label)))
109 ScrolledWindow::ScrolledWindow() : ScrolledWindow(GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(nullptr, nullptr)))
112 TreeView::TreeView(TreeModel model) : TreeView(GTK_TREE_VIEW(gtk_tree_view_new_with_model(model)))
115 VBox::VBox(bool homogenous, int spacing) : VBox(GTK_VBOX(gtk_vbox_new(homogenous, spacing)))