24#include <gdk/gdkkeysyms.h>
54 gtk_widget_queue_draw(w);
64 gtk_window_get_position(ref, &x, &y);
67 x += px *
width / 100;
70 gtk_window_move(w, x, y);
77 const gchar *label_text)
82 button = gtk_button_new_with_mnemonic(label_text);
84 if (icon_name != NULL) {
85 image = gtk_image_new_from_icon_name(icon_name, GTK_ICON_SIZE_BUTTON);
86 gtk_button_set_image(GTK_BUTTON(button), image);
98 gtk_button_set_label(GTK_BUTTON(button), label_text);
116 for (i = 0; i <
n; i++) {
130 it->
end = !gtk_tree_model_get_iter_first(it->
model, &it->
it);
146 it->
end = !gtk_tree_model_iter_next(it->
model, &it->
it);
157 gtk_tree_store_set_valist(GTK_TREE_STORE(it->
model), &it->
it, ap);
169 gtk_tree_model_get_valist(it->
model, &it->
it, ap);
178 it->
model = GTK_TREE_MODEL(store);
180 gtk_tree_store_append(GTK_TREE_STORE(it->
model), &it->
it, &parent->
it);
182 gtk_tree_store_append(GTK_TREE_STORE(it->
model), &it->
it, NULL);
192 return gtk_tree_selection_iter_is_selected(selection, &it->
it);
200 gtk_tree_selection_select_iter(selection, &it->
it);
208 gtk_tree_selection_unselect_iter(selection, &it->
it);
221 if (gtk_tree_selection_get_selected(selection, &model, &it)) {
225 path = gtk_tree_model_get_path(model, &it);
226 idx = gtk_tree_path_get_indices(path);
228 gtk_tree_path_free(path);
242 if ((model = gtk_tree_view_get_model(
view))
243 && gtk_tree_model_get_iter_first(model, &iter)
244 && (path = gtk_tree_model_get_path(model, &iter))) {
245 gtk_tree_view_set_cursor(
view, path, NULL,
FALSE);
246 gtk_tree_path_free(path);
247 gtk_widget_grab_focus(GTK_WIDGET(
view));
257 GtkWidget *menubar = gtk_menu_bar_new();
266 if (g_object_class_find_property(
267 G_OBJECT_CLASS(GTK_MENU_BAR_GET_CLASS(menubar)),
"ubuntu-local")) {
268 g_object_set(G_OBJECT(menubar),
"ubuntu-local",
TRUE, NULL);
279 gtk_widget_destroy(GTK_WIDGET(dialog));
290 gtk_window_set_transient_for(GTK_WINDOW(
shell),
292 gtk_window_set_type_hint(GTK_WINDOW(
shell),
293 GDK_WINDOW_TYPE_HINT_DIALOG);
295 gtk_window_set_type_hint(GTK_WINDOW(
shell),
296 GDK_WINDOW_TYPE_HINT_NORMAL);
300 if (GTK_IS_DIALOG(
shell)) {
333 g_signal_handler_disconnect(notebook, handler_id);
371 GdkEventAny *ev, gpointer data)
393 n = gtk_notebook_get_current_page(GTK_NOTEBOOK(
notebook));
394 if (gtk_notebook_get_nth_page(GTK_NOTEBOOK(
notebook),
n)
414 if (ev->keyval == GDK_KEY_Escape
415 || ((ev->state & GDK_CONTROL_MASK) && ev->keyval == GDK_KEY_w)) {
437 GtkStyleContext *context = gtk_widget_get_style_context(dlg->
v.
tab.
label);
439 gtk_style_context_remove_class(context,
"alert");
440 gtk_style_context_remove_class(context,
"notice");
460 g_object_ref(dlg->
vbox);
468 gtk_notebook_remove_page(GTK_NOTEBOOK(dlg->
v.
tab.
notebook),
n);
472 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
473 gtk_window_set_title(GTK_WINDOW(
window), dlg->
title);
476 gtk_container_add(GTK_CONTAINER(
window), dlg->
vbox);
478 g_signal_connect(
window,
"delete_event",
481 gtk_window_set_default_size(GTK_WINDOW(dlg->
v.
window),
484 gtk_widget_show_all(
window);
491 GdkEventButton* button,
494 if (button->type != GDK_2BUTTON_PRESS) {
497 if (button->button != 1) {
518 static int dialog_id_counter;
538 gui_action = gtk_size_group_new(GTK_SIZE_GROUP_VERTICAL);
540 dlg->
gui_button = gtk_size_group_new(GTK_SIZE_GROUP_BOTH);
542 vbox = gtk_grid_new();
544 gtk_grid_set_row_spacing(GTK_GRID(
action_area), 4);
545 gtk_grid_set_column_spacing(GTK_GRID(
action_area), 4);
551 gtk_orientable_set_orientation(GTK_ORIENTABLE(
action_area),
552 GTK_ORIENTATION_VERTICAL);
556 gtk_orientable_set_orientation(GTK_ORIENTABLE(
vbox),
557 GTK_ORIENTATION_VERTICAL);
560 gtk_widget_show(
vbox);
564 gtk_container_set_border_width(GTK_CONTAINER(
vbox), 2);
565 gtk_container_set_border_width(GTK_CONTAINER(
action_area), 2);
572 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
573 gtk_widget_set_name(
window,
"Freeciv");
574 gtk_window_set_position(GTK_WINDOW(
window), GTK_WIN_POS_MOUSE);
577 gtk_container_add(GTK_CONTAINER(
window),
vbox);
579 g_signal_connect(
window,
"delete_event",
586 GtkWidget *hbox, *
label, *image, *button, *event_box;
589 hbox = gtk_grid_new();
591 label = gtk_label_new(NULL);
592 gtk_widget_set_halign(
label, GTK_ALIGN_START);
593 gtk_widget_set_valign(
label, GTK_ALIGN_CENTER);
594 gtk_widget_set_margin_start(
label, 4);
595 gtk_widget_set_margin_end(
label, 4);
596 gtk_widget_set_margin_top(
label, 0);
597 gtk_widget_set_margin_bottom(
label, 0);
598 gtk_container_add(GTK_CONTAINER(hbox),
label);
600 button = gtk_button_new();
601 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
602 g_signal_connect_swapped(button,
"clicked",
605 buf = g_strdup_printf(
_(
"Close Tab:\n%s"),
_(
"Ctrl+W"));
606 gtk_widget_set_tooltip_text(button, buf);
609 image = gtk_image_new_from_icon_name(
"window-close", GTK_ICON_SIZE_MENU);
610 gtk_widget_set_margin_start(image, 0);
611 gtk_widget_set_margin_end(image, 0);
612 gtk_widget_set_margin_top(image, 0);
613 gtk_widget_set_margin_bottom(image, 0);
614 gtk_button_set_image(GTK_BUTTON(button), image);
616 gtk_container_add(GTK_CONTAINER(hbox), button);
618 gtk_widget_show_all(hbox);
620 event_box = gtk_event_box_new();
621 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box),
FALSE);
622 gtk_container_add(GTK_CONTAINER(event_box), hbox);
624 gtk_notebook_append_page(GTK_NOTEBOOK(
notebook),
vbox, event_box);
626 g_signal_connect(
notebook,
"switch-page",
630 gtk_style_context_add_provider(gtk_widget_get_style_context(
label),
632 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
636 gtk_widget_add_events(event_box, GDK_BUTTON2_MOTION_MASK);
637 g_signal_connect(event_box,
"button-press-event",
648 dlg->
id = dialog_id_counter;
652 g_signal_connect(
vbox,
"destroy",
654 g_signal_connect(
vbox,
"key_press_event",
657 g_object_set_data(G_OBJECT(
vbox),
"gui-dialog-data", dlg);
666 g_object_get_data(G_OBJECT(
vbox),
"gui-dialog-data");
668 g_object_get_data(G_OBJECT(button),
"gui-dialog-response-data");
683 g_object_set_data(G_OBJECT(button),
"gui-dialog-response-data",
684 GINT_TO_POINTER(response));
686 if ((signal_id = g_signal_lookup(
"clicked", GTK_TYPE_BUTTON))) {
690 G_OBJECT(dlg->
vbox));
691 g_signal_connect_closure_by_id(button, signal_id, 0, closure,
FALSE);
694 gtk_container_add(GTK_CONTAINER(dlg->
action_area), button);
695 gtk_size_group_add_widget(
gui_action, button);
696 gtk_size_group_add_widget(dlg->
gui_button, button);
703 const char *icon_name,
704 const char *text,
int response)
709 gtk_widget_set_can_default(button,
TRUE);
735 children = gtk_container_get_children(GTK_CONTAINER(dlg->
action_area));
738 GtkWidget *button =
list->data;
740 if (GTK_IS_BUTTON(button)) {
741 gpointer data = g_object_get_data(G_OBJECT(button),
742 "gui-dialog-response-data");
744 if (response == GPOINTER_TO_INT(data)) {
745 gtk_widget_grab_default(button);
750 g_list_free(children);
762 children = gtk_container_get_children(GTK_CONTAINER(dlg->
action_area));
765 GtkWidget *button =
list->data;
767 if (GTK_IS_BUTTON(button)) {
768 gpointer data = g_object_get_data(G_OBJECT(button),
769 "gui-dialog-response-data");
771 if (response == GPOINTER_TO_INT(data)) {
772 gtk_widget_set_sensitive(button,
setting);
777 g_list_free(children);
785 return gtk_widget_get_toplevel(dlg->
vbox);
793 gtk_widget_show_all(dlg->
vbox);
798 gint num_visible = 0;
800 children = gtk_container_get_children(GTK_CONTAINER(dlg->
action_area));
803 GtkWidget *button =
list->data;
805 if (!GTK_IS_BUTTON(button)) {
808 gpointer data = g_object_get_data(G_OBJECT(button),
809 "gui-dialog-response-data");
810 int response = GPOINTER_TO_INT(data);
812 if (response != GTK_RESPONSE_CLOSE
813 && response != GTK_RESPONSE_CANCEL) {
816 gtk_widget_hide(button);
820 g_list_free(children);
822 if (num_visible == 0) {
837 gtk_widget_show(dlg->
v.
window);
844 current = gtk_notebook_get_current_page(
notebook);
850 gtk_style_context_add_class(gtk_widget_get_style_context(
label),
867 gtk_window_present(GTK_WINDOW(dlg->
v.
window));
875 gtk_notebook_set_current_page(
notebook,
n);
896 current = gtk_notebook_get_current_page(
notebook);
901 GtkStyleContext *context = gtk_widget_get_style_context(
label);
904 gtk_style_context_remove_class(context,
"notice");
905 gtk_style_context_add_class(context,
"alert");
942 gtk_label_set_text_with_mnemonic(GTK_LABEL(dlg->
v.
tab.
label),
title);
954 gtk_widget_destroy(dlg->
v.
window);
961 gtk_notebook_remove_page(GTK_NOTEBOOK(dlg->
v.
tab.
notebook),
n);
975 it_next = g_list_next(it);
996 if (return_dialog == NULL) {
1009 GtkCssProvider *provider;
1010 PangoFontDescription *desc;
1016 desc = pango_font_description_from_string(font_value);
1022 fam = pango_font_description_get_family(desc);
1028 if (pango_font_description_get_style(desc) == PANGO_STYLE_ITALIC) {
1029 style =
"\n font-style: italic;";
1034 if (pango_font_description_get_weight(desc) >= 700) {
1035 weight =
"\n font-weight: bold;";
1040 size = pango_font_description_get_size(desc);
1043 if (pango_font_description_get_size_is_absolute(desc)) {
1044 str = g_strdup_printf(
"#Freeciv #%s { font-family: %s; font-size: %dpx;%s%s}",
1047 str = g_strdup_printf(
"#Freeciv #%s { font-family: %s; font-size: %dpt;%s%s}",
1051 str = g_strdup_printf(
"#Freeciv #%s { font-family: %s;%s%s}",
1055 pango_font_description_free(desc);
1057 provider = gtk_css_provider_new();
1058 gtk_css_provider_load_from_data(GTK_CSS_PROVIDER(provider),
1060 gtk_style_context_add_provider_for_screen(
1061 gtk_widget_get_screen(
toplevel), GTK_STYLE_PROVIDER(provider),
1062 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
1070 PangoFontDescription **font_desc)
1072 PangoFontDescription *f_desc;
1076 f_desc = pango_font_description_from_string(font_value);
1077 pango_font_description_free(*font_desc);
1079 *font_desc = f_desc;
1094 hid = g_signal_handler_find(obj, G_SIGNAL_MATCH_FUNC,
1095 0, 0, NULL, cb, NULL);
1096 g_signal_handler_block(obj, hid);
1110 hid = g_signal_handler_find(obj, G_SIGNAL_MATCH_FUNC,
1111 0, 0, NULL, cb, NULL);
1112 g_signal_handler_unblock(obj, hid);
1120 GType gtype,
int model_index)
1122 GtkTreeViewColumn *col;
1123 GtkCellRenderer *rend;
1130 if (gtype == G_TYPE_BOOLEAN) {
1131 rend = gtk_cell_renderer_toggle_new();
1133 }
else if (gtype == GDK_TYPE_PIXBUF) {
1134 rend = gtk_cell_renderer_pixbuf_new();
1137 rend = gtk_cell_renderer_text_new();
1141 col = gtk_tree_view_column_new_with_attributes(
title, rend, attr,
1143 gtk_tree_view_append_column(GTK_TREE_VIEW(
view), col);
1157 "color: rgba(255, 0, 0, 255);\n"
1160 "color: rgba(0, 0, 255, 255);\n"
struct canvas int int struct sprite int int int int height
struct canvas int int struct sprite int int int width
static struct fc_sockaddr_list * list
#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 gui_dialog_set_default_response(struct gui_dialog *dlg, int response)
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)
GtkWidget * gui_dialog_add_widget(struct gui_dialog *dlg, GtkWidget *widget)
gint gtk_tree_selection_get_row(GtkTreeSelection *selection)
void gui_dialog_set_return_dialog(struct gui_dialog *dlg, struct gui_dialog *return_dialog)
void set_relative_window_position(GtkWindow *ref, GtkWindow *w, int px, int py)
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)
GtkWidget * gtk_aux_menu_bar_new(void)
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)
#define fc_assert_ret(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