24#include <gdk/gdkkeysyms.h>
54 gtk_widget_queue_draw(w);
64 const gchar *label_text)
68 fc_assert(icon_name != NULL || label_text != NULL);
70 if (label_text != NULL) {
71 button = gtk_button_new_with_mnemonic(label_text);
72 }
else if (icon_name != NULL) {
73 button = gtk_button_new_from_icon_name(icon_name);
87 gtk_button_set_label(GTK_BUTTON(button), label_text);
105 for (i = 0; i <
n; i++) {
119 it->
end = !gtk_tree_model_get_iter_first(it->
model, &it->
it);
135 it->
end = !gtk_tree_model_iter_next(it->
model, &it->
it);
146 gtk_tree_store_set_valist(GTK_TREE_STORE(it->
model), &it->
it, ap);
158 gtk_tree_model_get_valist(it->
model, &it->
it, ap);
167 it->
model = GTK_TREE_MODEL(store);
169 gtk_tree_store_append(GTK_TREE_STORE(it->
model), &it->
it, &parent->
it);
171 gtk_tree_store_append(GTK_TREE_STORE(it->
model), &it->
it, NULL);
180 return gtk_tree_selection_iter_is_selected(selection, &it->
it);
188 gtk_tree_selection_select_iter(selection, &it->
it);
196 gtk_tree_selection_unselect_iter(selection, &it->
it);
209 if (gtk_tree_selection_get_selected(selection, &model, &it)) {
213 path = gtk_tree_model_get_path(model, &it);
214 idx = gtk_tree_path_get_indices(path);
216 gtk_tree_path_free(path);
230 if ((model = gtk_tree_view_get_model(
view))
231 && gtk_tree_model_get_iter_first(model, &iter)
232 && (path = gtk_tree_model_get_path(model, &iter))) {
233 gtk_tree_view_set_cursor(
view, path, NULL,
FALSE);
234 gtk_tree_path_free(path);
235 gtk_widget_grab_focus(GTK_WIDGET(
view));
245 GtkWidget *menu_button = gtk_menu_button_new();
255 gtk_window_destroy(GTK_WINDOW(dialog));
266 gtk_window_set_transient_for(GTK_WINDOW(
shell),
271 if (GTK_IS_DIALOG(
shell)) {
304 g_signal_handler_disconnect(notebook, handler_id);
363 n = gtk_notebook_get_current_page(GTK_NOTEBOOK(
notebook));
364 if (gtk_notebook_get_nth_page(GTK_NOTEBOOK(
notebook),
n)
381 guint keyval, guint keycode,
382 GdkModifierType state,
387 if (keyval == GDK_KEY_Escape
388 || ((state & GDK_CONTROL_MASK) && keyval == GDK_KEY_w)) {
410 gtk_widget_remove_css_class(dlg->
v.
tab.
label,
"alert");
411 gtk_widget_remove_css_class(dlg->
v.
tab.
label,
"notice");
431 g_object_ref(dlg->
grid);
439 gtk_notebook_remove_page(GTK_NOTEBOOK(dlg->
v.
tab.
notebook),
n);
443 window = gtk_window_new();
444 gtk_window_set_title(GTK_WINDOW(
window), dlg->
title);
447 gtk_window_set_child(GTK_WINDOW(
window), dlg->
grid);
449 g_signal_connect(
window,
"close-request",
452 gtk_window_set_default_size(GTK_WINDOW(dlg->
v.
window),
463 double x,
double y, gpointer data)
485 static int dialog_id_counter;
486 GtkEventController *controller;
506 gui_action = gtk_size_group_new(GTK_SIZE_GROUP_VERTICAL);
508 dlg->
gui_button = gtk_size_group_new(GTK_SIZE_GROUP_BOTH);
510 dlg->
grid = gtk_grid_new();
517 action_area = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
522 action_area = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
523 gtk_orientable_set_orientation(GTK_ORIENTABLE(dlg->
grid),
524 GTK_ORIENTATION_VERTICAL);
528 gtk_widget_show(dlg->
grid);
532 gtk_widget_set_margin_start(dlg->
grid, 2);
533 gtk_widget_set_margin_end(dlg->
grid, 2);
534 gtk_widget_set_margin_top(dlg->
grid, 2);
535 gtk_widget_set_margin_bottom(dlg->
grid, 2);
547 window = gtk_window_new();
548 gtk_widget_set_name(
window,
"Freeciv");
551 gtk_window_set_child(GTK_WINDOW(
window), dlg->
grid);
553 g_signal_connect(
window,
"close-request",
560 GtkWidget *hbox, *
label, *button;
563 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
565 label = gtk_label_new(NULL);
566 gtk_widget_set_halign(
label, GTK_ALIGN_START);
567 gtk_widget_set_valign(
label, GTK_ALIGN_CENTER);
568 gtk_widget_set_margin_start(
label, 4);
569 gtk_widget_set_margin_end(
label, 4);
570 gtk_widget_set_margin_top(
label, 0);
571 gtk_widget_set_margin_bottom(
label, 0);
572 gtk_box_append(GTK_BOX(hbox),
label);
574 button = gtk_button_new();
575 gtk_button_set_has_frame(GTK_BUTTON(button),
FALSE);
576 g_signal_connect_swapped(button,
"clicked",
579 buf = g_strdup_printf(
_(
"Close Tab:\n%s"),
_(
"Ctrl+W"));
580 gtk_widget_set_tooltip_text(button, buf);
583 gtk_button_set_icon_name(GTK_BUTTON(button),
"window-close");
585 gtk_box_append(GTK_BOX(hbox), button);
587 gtk_widget_show(hbox);
589 gtk_notebook_append_page(GTK_NOTEBOOK(
notebook), dlg->
grid, hbox);
591 g_signal_connect(
notebook,
"switch-page",
598 controller = GTK_EVENT_CONTROLLER(gtk_gesture_click_new());
599 g_signal_connect(controller,
"pressed",
601 gtk_widget_add_controller(hbox, controller);
610 dlg->
id = dialog_id_counter;
614 g_signal_connect(dlg->
grid,
"destroy",
616 controller = gtk_event_controller_key_new();
617 g_signal_connect(controller,
"key-pressed",
619 gtk_widget_add_controller(dlg->
grid, controller);
621 g_object_set_data(G_OBJECT(dlg->
grid),
"gui-dialog-data", dlg);
630 g_object_get_data(G_OBJECT(
vbox),
"gui-dialog-data");
632 g_object_get_data(G_OBJECT(button),
"gui-dialog-response-data");
647 g_object_set_data(G_OBJECT(button),
"gui-dialog-response-data",
648 GINT_TO_POINTER(response));
650 if ((signal_id = g_signal_lookup(
"clicked", GTK_TYPE_BUTTON))) {
654 G_OBJECT(dlg->
grid));
655 g_signal_connect_closure_by_id(button, signal_id, 0, closure,
FALSE);
659 gtk_size_group_add_widget(dlg->
gui_button, button);
666 const char *icon_name,
667 const char *text,
int response)
698 for (iter = gtk_widget_get_first_child(dlg->
actions);
700 iter = gtk_widget_get_next_sibling(iter)) {
701 if (GTK_IS_BUTTON(iter)) {
702 gpointer data = g_object_get_data(G_OBJECT(iter),
703 "gui-dialog-response-data");
705 if (response == GPOINTER_TO_INT(data)) {
706 gtk_widget_set_sensitive(iter,
setting);
717 return gtk_widget_get_ancestor(dlg->
grid, GTK_TYPE_WINDOW);
725 gtk_widget_show(dlg->
grid);
729 gint num_visible = 0;
731 for (iter = gtk_widget_get_first_child(dlg->
actions);
733 iter = gtk_widget_get_next_sibling(iter)) {
734 if (!GTK_IS_BUTTON(iter)) {
737 gpointer data = g_object_get_data(G_OBJECT(iter),
738 "gui-dialog-response-data");
739 int response = GPOINTER_TO_INT(data);
741 if (response != GTK_RESPONSE_CLOSE
742 && response != GTK_RESPONSE_CANCEL) {
745 gtk_widget_hide(iter);
750 if (num_visible == 0) {
765 gtk_widget_show(dlg->
v.
window);
772 current = gtk_notebook_get_current_page(
notebook);
776 gtk_widget_add_css_class(dlg->
v.
tab.
label,
"notice");
792 gtk_window_present(GTK_WINDOW(dlg->
v.
window));
800 gtk_notebook_set_current_page(
notebook,
n);
821 current = gtk_notebook_get_current_page(
notebook);
826 gtk_widget_remove_css_class(dlg->
v.
tab.
label,
"notice");
827 gtk_widget_add_css_class(dlg->
v.
tab.
label,
"alert");
864 gtk_label_set_text_with_mnemonic(GTK_LABEL(dlg->
v.
tab.
label),
title);
876 gtk_window_destroy(GTK_WINDOW(dlg->
v.
window));
883 gtk_notebook_remove_page(GTK_NOTEBOOK(dlg->
v.
tab.
notebook),
n);
897 it_next = g_list_next(it);
918 if (return_dialog == NULL) {
931 GtkCssProvider *provider;
932 PangoFontDescription *desc;
938 desc = pango_font_description_from_string(font_value);
944 fam = pango_font_description_get_family(desc);
950 if (pango_font_description_get_style(desc) == PANGO_STYLE_ITALIC) {
951 style =
"\n font-style: italic;";
956 if (pango_font_description_get_weight(desc) >= 700) {
957 weight =
"\n font-weight: bold;";
962 size = pango_font_description_get_size(desc);
965 if (pango_font_description_get_size_is_absolute(desc)) {
966 str = g_strdup_printf(
"#Freeciv #%s { font-family: %s; font-size: %dpx;%s%s}",
969 str = g_strdup_printf(
"#Freeciv #%s { font-family: %s; font-size: %dpt;%s%s}",
973 str = g_strdup_printf(
"#Freeciv #%s { font-family: %s;%s%s}",
977 pango_font_description_free(desc);
979 provider = gtk_css_provider_new();
980 gtk_css_provider_load_from_data(GTK_CSS_PROVIDER(provider),
982 gtk_style_context_add_provider_for_display(
983 gtk_widget_get_display(
toplevel), GTK_STYLE_PROVIDER(provider),
984 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
992 PangoFontDescription **font_desc)
994 PangoFontDescription *f_desc;
998 f_desc = pango_font_description_from_string(font_value);
999 pango_font_description_free(*font_desc);
1001 *font_desc = f_desc;
1016 hid = g_signal_handler_find(obj, G_SIGNAL_MATCH_FUNC,
1017 0, 0, NULL, cb, NULL);
1018 g_signal_handler_block(obj, hid);
1032 hid = g_signal_handler_find(obj, G_SIGNAL_MATCH_FUNC,
1033 0, 0, NULL, cb, NULL);
1034 g_signal_handler_unblock(obj, hid);
1042 GType gtype,
int model_index)
1044 GtkTreeViewColumn *col;
1045 GtkCellRenderer *rend;
1052 if (gtype == G_TYPE_BOOLEAN) {
1053 rend = gtk_cell_renderer_toggle_new();
1055 }
else if (gtype == GDK_TYPE_PIXBUF) {
1056 rend = gtk_cell_renderer_pixbuf_new();
1059 rend = gtk_cell_renderer_text_new();
1063 col = gtk_tree_view_column_new_with_attributes(
title, rend, attr,
1065 gtk_tree_view_append_column(GTK_TREE_VIEW(
view), col);
1079 "color: rgba(255, 0, 0, 255);\n"
1082 "color: rgba(0, 0, 255, 255);\n"
1086 gtk_style_context_add_provider_for_display(
1089 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
1098 gtk_grid_attach(GTK_GRID(dlg->
grid), wdg,
1101 gtk_grid_attach(GTK_GRID(dlg->
grid), wdg,
1120 g_main_loop_quit(bd_data->
loop);
1129 GMainLoop *dlg_loop;
1131 gtk_widget_show(dlg);
1132 dlg_loop = g_main_loop_new(NULL,
FALSE);
1133 data.
loop = dlg_loop;
1137 g_main_loop_run(dlg_loop);
1147 *(GtkWidget **)data = NULL;
1156 return gtk_widget_get_first_child(wdg);
struct canvas int int struct sprite int int int int height
struct canvas int int struct sprite int int int width
#define GUI_GTK_OPTION(optname)
void gtk_tree_view_focus(GtkTreeView *view)
void gui_dialog_destroy(struct gui_dialog *dlg)
static void gui_dialog_pack_button(struct gui_dialog *dlg, GtkWidget *button, int response)
void gui_dialog_present(struct gui_dialog *dlg)
static void gui_dialog_switch_page_handler(GtkNotebook *notebook, GtkWidget *page, guint num, struct gui_dialog *dlg)
void gtk_stockbutton_set_label(GtkWidget *button, const gchar *label_text)
void itree_get(ITree *it,...)
void itree_set(ITree *it,...)
void gui_dialog_raise(struct gui_dialog *dlg)
void gui_dialog_new(struct gui_dialog **pdlg, GtkNotebook *notebook, gpointer user_data, bool check_top)
void disable_gobject_callback(GObject *obj, GCallback cb)
gint gtk_tree_selection_get_row(GtkTreeSelection *selection)
void gui_dialog_set_return_dialog(struct gui_dialog *dlg, struct gui_dialog *return_dialog)
void gui_dialog_response_set_callback(struct gui_dialog *dlg, GUI_DIALOG_RESPONSE_FUN fun)
static GtkSizeGroup * gui_action
void itree_begin(GtkTreeModel *model, ITree *it)
static void gui_dialog_destroyed(struct gui_dialog *dlg, int response, gpointer data)
GtkWidget * gui_dialog_add_button(struct gui_dialog *dlg, const char *text, int response)
static void action_widget_activated(GtkWidget *button, GtkWidget *vbox)
void itree_unselect(GtkTreeSelection *selection, ITree *it)
void enable_gobject_callback(GObject *obj, GCallback cb)
static void gui_dialog_detach(struct gui_dialog *dlg)
void gui_dialog_show_all(struct gui_dialog *dlg)
static gboolean gui_dialog_key_press_handler(GtkWidget *w, GdkEventKey *ev, gpointer data)
static gint gui_dialog_delete_handler(GtkWidget *widget, GdkEventAny *ev, gpointer data)
void itree_select(GtkTreeSelection *selection, ITree *it)
void gui_dialog_set_title(struct gui_dialog *dlg, const char *title)
static void close_callback(GtkDialog *dialog, gpointer data)
void gui_dialog_set_default_size(struct gui_dialog *dlg, int width, int height)
void gui_dialog_alert(struct gui_dialog *dlg)
GtkTreeViewColumn * add_treeview_column(GtkWidget *view, const char *title, GType gtype, int model_index)
static void gui_dialog_destroy_handler(GtkWidget *w, struct gui_dialog *dlg)
void tstore_append(GtkTreeStore *store, ITree *it, ITree *parent)
static gint gui_dialog_delete_tab_handler(struct gui_dialog *dlg)
void itree_next(ITree *it)
void gui_dialog_destroy_all(void)
static gboolean click_on_tab_callback(GtkWidget *w, GdkEventButton *button, gpointer data)
gboolean itree_is_selected(GtkTreeSelection *selection, ITree *it)
void setup_dialog(GtkWidget *shell, GtkWidget *parent)
static GList * dialog_list
void gui_update_font_full(const char *font_name, const char *font_value, PangoFontDescription **font_desc)
void gtk_expose_now(GtkWidget *w)
void gui_dialog_set_response_sensitive(struct gui_dialog *dlg, int response, bool setting)
GtkWidget * gui_dialog_get_toplevel(struct gui_dialog *dlg)
void intl_slist(int n, const char **s, bool *done)
gboolean itree_end(ITree *it)
static void gui_dialog_response(struct gui_dialog *dlg, int response)
void(* GUI_DIALOG_RESPONSE_FUN)(struct gui_dialog *, int, gpointer)
static struct gui_dialog * shell
static GtkCssProvider * dlg_tab_provider
void dlg_tab_provider_prepare(void)
GtkWidget * icon_label_button_new(const gchar *icon_name, const gchar *label_text)
gint blocking_dialog(GtkWidget *dlg)
GtkWidget * aux_menu_new(void)
void gui_dialog_add_content_widget(struct gui_dialog *dlg, GtkWidget *wdg)
GtkWidget * widget_get_child(GtkWidget *wdg)
static void blocking_dialog_response(GtkWidget *dlg, gint response, void *data)
GtkWidget * gui_dialog_add_action_widget(struct gui_dialog *dlg, GtkWidget *widget)
void widget_destroyed(GtkWidget *wdg, void *data)
#define fc_assert_ret(condition)
#define fc_assert(condition)
#define fc_assert_ret_val(condition, val)
GtkSizeGroup * gui_button
GUI_DIALOG_RESPONSE_FUN response_callback
struct gui_dialog::@149::@150 tab
struct gui_dialog ** source
enum gui_dialog_type type