2020-11-17 11:16:16 +00:00
|
|
|
#include "uilib.h"
|
|
|
|
|
|
|
|
#include <tuple>
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "gtkutil/dialog.h"
|
|
|
|
#include "gtkutil/filechooser.h"
|
|
|
|
#include "gtkutil/messagebox.h"
|
|
|
|
#include "gtkutil/window.h"
|
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
bool init(int *argc, char **argv[], char const *parameter_string, char const **error)
|
|
|
|
{
|
|
|
|
gtk_disable_setlocale();
|
|
|
|
static GOptionEntry entries[] = {{}};
|
|
|
|
char const *translation_domain = NULL;
|
|
|
|
GError *gerror = NULL;
|
|
|
|
bool ret = gtk_init_with_args(argc, argv, parameter_string, entries, translation_domain, &gerror) != 0;
|
|
|
|
if (!ret) {
|
|
|
|
*error = gerror->message;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
gtk_main();
|
|
|
|
}
|
|
|
|
|
|
|
|
void process()
|
|
|
|
{
|
|
|
|
while (gtk_events_pending()) {
|
|
|
|
gtk_main_iteration();
|
|
|
|
}
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
|
|
|
#define IMPL(T, F) template<> _IMPL(T, F)
|
|
|
|
#define _IMPL(T, F) struct verify<T *> { using self = T; static self test(self it) { return self::from(F(it)); } }
|
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
template<class T>
|
|
|
|
struct verify;
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
template<class T> _IMPL(T,);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
template<class T>
|
|
|
|
using pointer_remove_const = std::add_pointer<
|
|
|
|
typename std::remove_const<
|
|
|
|
typename std::remove_pointer<T>::type
|
|
|
|
>::type
|
|
|
|
>;
|
2020-11-17 11:16:16 +00:00
|
|
|
|
|
|
|
#define this (verify<self>::test(*static_cast<self>(const_cast<pointer_remove_const<decltype(this)>::type>(this))))
|
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(Editable, GTK_EDITABLE);
|
|
|
|
|
|
|
|
void IEditable::editable(bool value)
|
|
|
|
{
|
|
|
|
gtk_editable_set_editable(this, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL(TreeModel, GTK_TREE_MODEL);
|
|
|
|
|
|
|
|
IMPL(Widget, GTK_WIDGET);
|
|
|
|
|
|
|
|
Widget::Widget(ui::New_t) : Widget(nullptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Window IWidget::window()
|
|
|
|
{
|
|
|
|
return Window::from(gtk_widget_get_toplevel(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
IWidget::file_dialog(bool open, const char *title, const char *path, const char *pattern, bool want_load,
|
|
|
|
bool want_import, bool want_save)
|
|
|
|
{
|
|
|
|
return ::file_dialog(this.window(), open, title, path, pattern, want_load, want_import, want_save);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IWidget::visible()
|
|
|
|
{
|
|
|
|
return gtk_widget_get_visible(this) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IWidget::visible(bool shown)
|
|
|
|
{
|
|
|
|
if (shown) {
|
|
|
|
this.show();
|
|
|
|
} else {
|
|
|
|
this.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IWidget::show()
|
|
|
|
{
|
|
|
|
gtk_widget_show(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IWidget::hide()
|
|
|
|
{
|
|
|
|
gtk_widget_hide(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
Dimensions IWidget::dimensions()
|
|
|
|
{
|
|
|
|
GtkAllocation allocation;
|
|
|
|
gtk_widget_get_allocation(this, &allocation);
|
|
|
|
return Dimensions{allocation.width, allocation.height};
|
|
|
|
}
|
|
|
|
|
|
|
|
void IWidget::dimensions(int width, int height)
|
|
|
|
{
|
|
|
|
gtk_widget_set_size_request(this, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IWidget::destroy()
|
|
|
|
{
|
|
|
|
gtk_widget_destroy(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL(Container, GTK_CONTAINER);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
void IContainer::add(Widget widget)
|
|
|
|
{
|
|
|
|
gtk_container_add(this, widget);
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
void IContainer::remove(Widget widget)
|
|
|
|
{
|
|
|
|
gtk_container_remove(this, widget);
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(Bin, GTK_BIN);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(Window, GTK_WINDOW);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
Window::Window(window_type type) : Window(GTK_WINDOW(gtk_window_new(
|
|
|
|
type == window_type::TOP ? GTK_WINDOW_TOPLEVEL :
|
|
|
|
type == window_type::POPUP ? GTK_WINDOW_POPUP :
|
|
|
|
GTK_WINDOW_TOPLEVEL
|
|
|
|
)))
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
Window IWindow::create_dialog_window(const char *title, void func(), void *data, int default_w, int default_h)
|
|
|
|
{
|
|
|
|
return Window(::create_dialog_window(this, title, func, data, default_w, default_h));
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
Window IWindow::create_modal_dialog_window(const char *title, ModalDialog &dialog, int default_w, int default_h)
|
|
|
|
{
|
|
|
|
return Window(::create_modal_dialog_window(this, title, dialog, default_w, default_h));
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
Window IWindow::create_floating_window(const char *title)
|
|
|
|
{
|
|
|
|
return Window(::create_floating_window(title, this));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::uint64_t IWindow::on_key_press(bool (*f)(Widget widget, _GdkEventKey *event, void *extra), void *extra)
|
|
|
|
{
|
|
|
|
using f_t = decltype(f);
|
|
|
|
struct user_data {
|
|
|
|
f_t f;
|
|
|
|
void *extra;
|
|
|
|
} *pass = new user_data{f, extra};
|
|
|
|
auto dtor = [](user_data *data, GClosure *) {
|
|
|
|
delete data;
|
|
|
|
};
|
|
|
|
auto func = [](_GtkWidget *widget, GdkEventKey *event, user_data *args) -> bool {
|
|
|
|
return args->f(Widget::from(widget), event, args->extra);
|
|
|
|
};
|
|
|
|
auto clos = g_cclosure_new(G_CALLBACK(+func), pass, reinterpret_cast<GClosureNotify>(+dtor));
|
|
|
|
return g_signal_connect_closure(G_OBJECT(this), "key-press-event", clos, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IWindow::add_accel_group(AccelGroup group)
|
|
|
|
{
|
|
|
|
gtk_window_add_accel_group(this, group);
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL(Alignment, GTK_ALIGNMENT);
|
|
|
|
|
|
|
|
Alignment::Alignment(float xalign, float yalign, float xscale, float yscale)
|
|
|
|
: Alignment(GTK_ALIGNMENT(gtk_alignment_new(xalign, yalign, xscale, yscale)))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL(Frame, GTK_FRAME);
|
|
|
|
|
|
|
|
Frame::Frame(const char *label) : Frame(GTK_FRAME(gtk_frame_new(label)))
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(Button, GTK_BUTTON);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
Button::Button(ui::New_t) : Button(GTK_BUTTON(gtk_button_new()))
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
Button::Button(const char *label) : Button(GTK_BUTTON(gtk_button_new_with_label(label)))
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(ToggleButton, GTK_TOGGLE_BUTTON);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
bool IToggleButton::active() const
|
|
|
|
{
|
|
|
|
return gtk_toggle_button_get_active(this) != 0;
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
void IToggleButton::active(bool value)
|
|
|
|
{
|
|
|
|
gtk_toggle_button_set_active(this, value);
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(CheckButton, GTK_CHECK_BUTTON);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
CheckButton::CheckButton(ui::New_t) : CheckButton(GTK_CHECK_BUTTON(gtk_check_button_new()))
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
CheckButton::CheckButton(const char *label) : CheckButton(GTK_CHECK_BUTTON(gtk_check_button_new_with_label(label)))
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(MenuItem, GTK_MENU_ITEM);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
MenuItem::MenuItem(ui::New_t) : MenuItem(GTK_MENU_ITEM(gtk_menu_item_new()))
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
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)))
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(TearoffMenuItem, GTK_TEAROFF_MENU_ITEM);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
TearoffMenuItem::TearoffMenuItem(ui::New_t) : TearoffMenuItem(GTK_TEAROFF_MENU_ITEM(gtk_tearoff_menu_item_new()))
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(ComboBoxText, GTK_COMBO_BOX_TEXT);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
ComboBoxText::ComboBoxText(ui::New_t) : ComboBoxText(GTK_COMBO_BOX_TEXT(gtk_combo_box_text_new_with_entry()))
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(ScrolledWindow, GTK_SCROLLED_WINDOW);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
ScrolledWindow::ScrolledWindow(ui::New_t) : ScrolledWindow(GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(nullptr, nullptr)))
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
void IScrolledWindow::overflow(Policy x, Policy y)
|
|
|
|
{
|
|
|
|
gtk_scrolled_window_set_policy(this, static_cast<GtkPolicyType>(x), static_cast<GtkPolicyType>(y));
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(Box, GTK_BOX);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
void IBox::pack_start(ui::Widget child, bool expand, bool fill, unsigned int padding)
|
|
|
|
{
|
|
|
|
gtk_box_pack_start(this, child, expand, fill, padding);
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
void IBox::pack_end(ui::Widget child, bool expand, bool fill, unsigned int padding)
|
|
|
|
{
|
|
|
|
gtk_box_pack_end(this, child, expand, fill, padding);
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(VBox, GTK_VBOX);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
VBox::VBox(bool homogenous, int spacing) : VBox(GTK_VBOX(gtk_vbox_new(homogenous, spacing)))
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(HBox, GTK_HBOX);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
HBox::HBox(bool homogenous, int spacing) : HBox(GTK_HBOX(gtk_hbox_new(homogenous, spacing)))
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(HPaned, GTK_HPANED);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
HPaned::HPaned(ui::New_t) : HPaned(GTK_HPANED(gtk_hpaned_new()))
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(VPaned, GTK_VPANED);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
VPaned::VPaned(ui::New_t) : VPaned(GTK_VPANED(gtk_vpaned_new()))
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(Menu, GTK_MENU);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
Menu::Menu(ui::New_t) : Menu(GTK_MENU(gtk_menu_new()))
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(Table, GTK_TABLE);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
Table::Table(std::size_t rows, std::size_t columns, bool homogenous) : Table(
|
|
|
|
GTK_TABLE(gtk_table_new(rows, columns, homogenous))
|
|
|
|
)
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
void ITable::attach(Widget child, TableAttach attach, TableAttachOptions options, TablePadding padding) {
|
|
|
|
gtk_table_attach(this, child,
|
|
|
|
attach.left, attach.right, attach.top, attach.bottom,
|
|
|
|
static_cast<GtkAttachOptions>(options.x), static_cast<GtkAttachOptions>(options.y),
|
|
|
|
padding.x, padding.y
|
|
|
|
);
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(TextView, GTK_TEXT_VIEW);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
TextView::TextView(ui::New_t) : TextView(GTK_TEXT_VIEW(gtk_text_view_new()))
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
void ITextView::text(char const *str)
|
|
|
|
{
|
|
|
|
GtkTextBuffer *buffer = gtk_text_view_get_buffer(this);
|
|
|
|
gtk_text_buffer_set_text(buffer, str, -1);
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
TreeView::TreeView(ui::New_t) : TreeView(GTK_TREE_VIEW(gtk_tree_view_new()))
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
TreeView::TreeView(TreeModel model) : TreeView(GTK_TREE_VIEW(gtk_tree_view_new_with_model(model)))
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(Label, GTK_LABEL);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
Label::Label(const char *label) : Label(GTK_LABEL(gtk_label_new(label)))
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
void ILabel::text(char const *str)
|
|
|
|
{
|
|
|
|
gtk_label_set_text(this, str);
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(Image, GTK_IMAGE);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
Image::Image(ui::New_t) : Image(GTK_IMAGE(gtk_image_new()))
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(Entry, GTK_ENTRY);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
Entry::Entry(ui::New_t) : Entry(GTK_ENTRY(gtk_entry_new()))
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
Entry::Entry(std::size_t max_length) : Entry(ui::New)
|
|
|
|
{
|
|
|
|
gtk_entry_set_max_length(this, static_cast<gint>(max_length));
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
char const *IEntry::text()
|
|
|
|
{
|
|
|
|
return gtk_entry_get_text(this);
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
void IEntry::text(char const *str)
|
|
|
|
{
|
|
|
|
return gtk_entry_set_text(this, str);
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(SpinButton, GTK_SPIN_BUTTON);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
SpinButton::SpinButton(Adjustment adjustment, double climb_rate, std::size_t digits) : SpinButton(
|
|
|
|
GTK_SPIN_BUTTON(gtk_spin_button_new(adjustment, climb_rate, digits)))
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(HScale, GTK_HSCALE);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
HScale::HScale(Adjustment adjustment) : HScale(GTK_HSCALE(gtk_hscale_new(adjustment)))
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
HScale::HScale(double min, double max, double step) : HScale(GTK_HSCALE(gtk_hscale_new_with_range(min, max, step)))
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(Adjustment, GTK_ADJUSTMENT);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
Adjustment::Adjustment(double value,
|
|
|
|
double lower, double upper,
|
|
|
|
double step_increment, double page_increment,
|
|
|
|
double page_size)
|
|
|
|
: Adjustment(
|
|
|
|
GTK_ADJUSTMENT(gtk_adjustment_new(value, lower, upper, step_increment, page_increment, page_size)))
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(CellRendererText, GTK_CELL_RENDERER_TEXT);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
CellRendererText::CellRendererText(ui::New_t) : CellRendererText(GTK_CELL_RENDERER_TEXT(gtk_cell_renderer_text_new()))
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(TreeViewColumn, GTK_TREE_VIEW_COLUMN);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
TreeViewColumn::TreeViewColumn(const char *title, CellRenderer renderer,
|
|
|
|
std::initializer_list<TreeViewColumnAttribute> attributes)
|
|
|
|
: TreeViewColumn(gtk_tree_view_column_new_with_attributes(title, renderer, nullptr))
|
|
|
|
{
|
|
|
|
for (auto &it : attributes) {
|
|
|
|
gtk_tree_view_column_add_attribute(this, renderer, it.attribute, it.column);
|
|
|
|
}
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(AccelGroup, GTK_ACCEL_GROUP);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
AccelGroup::AccelGroup(ui::New_t) : AccelGroup(GTK_ACCEL_GROUP(gtk_accel_group_new()))
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(ListStore, GTK_LIST_STORE);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
void IListStore::clear()
|
|
|
|
{
|
|
|
|
gtk_list_store_clear(this);
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
void IListStore::append()
|
|
|
|
{
|
|
|
|
gtk_list_store_append(this, nullptr);
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(TreeStore, GTK_TREE_STORE);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
// IMPL(TreePath, GTK_TREE_PATH);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
TreePath::TreePath(ui::New_t) : TreePath(gtk_tree_path_new())
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
TreePath::TreePath(const char *path) : TreePath(gtk_tree_path_new_from_string(path))
|
|
|
|
{
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
// Custom
|
2020-11-17 11:16:16 +00:00
|
|
|
|
|
|
|
#if GTK_TARGET == 3
|
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(GLArea, (void *));
|
2020-11-17 11:16:16 +00:00
|
|
|
|
|
|
|
#elif GTK_TARGET == 2
|
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
IMPL(GLArea, GTK_DRAWING_AREA);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
guint IGLArea::on_render(GCallback pFunction, void *data)
|
|
|
|
{
|
2020-11-17 11:16:16 +00:00
|
|
|
#if GTK_TARGET == 3
|
2021-08-04 20:23:18 +00:00
|
|
|
return this.connect("render", pFunction, data);
|
2020-11-17 11:16:16 +00:00
|
|
|
#endif
|
|
|
|
#if GTK_TARGET == 2
|
2021-08-04 20:23:18 +00:00
|
|
|
return this.connect("expose_event", pFunction, data);
|
2020-11-17 11:16:16 +00:00
|
|
|
#endif
|
2021-08-04 20:23:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// global
|
|
|
|
|
|
|
|
Window root{ui::null};
|
|
|
|
|
|
|
|
alert_response alert(Window parent, std::string text, std::string title, alert_type type, alert_icon icon)
|
|
|
|
{
|
|
|
|
auto ret = gtk_MessageBox(parent, text.c_str(),
|
|
|
|
title.c_str(),
|
|
|
|
type == alert_type::OK ? eMB_OK :
|
|
|
|
type == alert_type::OKCANCEL ? eMB_OKCANCEL :
|
|
|
|
type == alert_type::YESNO ? eMB_YESNO :
|
|
|
|
type == alert_type::YESNOCANCEL ? eMB_YESNOCANCEL :
|
|
|
|
type == alert_type::NOYES ? eMB_NOYES :
|
|
|
|
eMB_OK,
|
|
|
|
icon == alert_icon::Default ? eMB_ICONDEFAULT :
|
|
|
|
icon == alert_icon::Error ? eMB_ICONERROR :
|
|
|
|
icon == alert_icon::Warning ? eMB_ICONWARNING :
|
|
|
|
icon == alert_icon::Question ? eMB_ICONQUESTION :
|
|
|
|
icon == alert_icon::Asterisk ? eMB_ICONASTERISK :
|
|
|
|
eMB_ICONDEFAULT
|
|
|
|
);
|
|
|
|
return
|
|
|
|
ret == eIDOK ? alert_response::OK :
|
|
|
|
ret == eIDCANCEL ? alert_response::CANCEL :
|
|
|
|
ret == eIDYES ? alert_response::YES :
|
|
|
|
ret == eIDNO ? alert_response::NO :
|
|
|
|
alert_response::OK;
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
|
|
|
}
|