24#include <gdk/gdkkeysyms.h>
52 gtk_widget_queue_draw(w);
62 gtk_window_get_position(ref, &x, &y);
65 x += px *
width / 100;
68 gtk_window_move(w, x, y);
79 button = gtk_button_new_with_mnemonic(label_text);
80 image = gtk_image_new_from_stock(stock, GTK_ICON_SIZE_BUTTON);
81 gtk_button_set_image(GTK_BUTTON(button), image);
92 gtk_button_set_label(GTK_BUTTON(button), label_text);
110 for (i = 0; i <
n; i++) {
124 it->
end = !gtk_tree_model_get_iter_first(it->
model, &it->
it);
140 it->
end = !gtk_tree_model_iter_next(it->
model, &it->
it);
151 gtk_tree_store_set_valist(GTK_TREE_STORE(it->
model), &it->
it, ap);
163 gtk_tree_model_get_valist(it->
model, &it->
it, ap);
172 it->
model = GTK_TREE_MODEL(store);
174 gtk_tree_store_append(GTK_TREE_STORE(it->
model), &it->
it, &parent->
it);
176 gtk_tree_store_append(GTK_TREE_STORE(it->
model), &it->
it, NULL);
186 return gtk_tree_selection_iter_is_selected(selection, &it->
it);
194 gtk_tree_selection_select_iter(selection, &it->
it);
202 gtk_tree_selection_unselect_iter(selection, &it->
it);
215 if (gtk_tree_selection_get_selected(selection, &model, &it)) {
219 path = gtk_tree_model_get_path(model, &it);
220 idx = gtk_tree_path_get_indices(path);
222 gtk_tree_path_free(path);
236 if ((model = gtk_tree_view_get_model(
view))
237 && gtk_tree_model_get_iter_first(model, &iter)
238 && (path = gtk_tree_model_get_path(model, &iter))) {
239 gtk_tree_view_set_cursor(
view, path, NULL,
FALSE);
240 gtk_tree_path_free(path);
241 gtk_widget_grab_focus(GTK_WIDGET(
view));
251 GtkWidget *menubar = gtk_menu_bar_new();
260 if (g_object_class_find_property(
261 G_OBJECT_CLASS(GTK_MENU_BAR_GET_CLASS(menubar)),
"ubuntu-local")) {
262 g_object_set(G_OBJECT(menubar),
"ubuntu-local",
TRUE, NULL);
273 gtk_widget_destroy(GTK_WIDGET(dialog));
284 gtk_window_set_transient_for(GTK_WINDOW(
shell),
286 gtk_window_set_type_hint(GTK_WINDOW(
shell),
287 GDK_WINDOW_TYPE_HINT_DIALOG);
289 gtk_window_set_type_hint(GTK_WINDOW(
shell),
290 GDK_WINDOW_TYPE_HINT_NORMAL);
294 if (GTK_IS_DIALOG(
shell)) {
327 g_signal_handler_disconnect(notebook, handler_id);
365 GdkEventAny *ev, gpointer data)
387 n = gtk_notebook_get_current_page(GTK_NOTEBOOK(
notebook));
388 if (gtk_notebook_get_nth_page(GTK_NOTEBOOK(
notebook),
n)
408 if (ev->keyval == GDK_KEY_Escape
409 || ((ev->state & GDK_CONTROL_MASK) && ev->keyval == GDK_KEY_w)) {
431 gtk_widget_override_color(dlg->
v.
tab.
label, GTK_STATE_FLAG_NORMAL, NULL);
451 g_object_ref(dlg->
vbox);
459 gtk_notebook_remove_page(GTK_NOTEBOOK(dlg->
v.
tab.
notebook),
n);
463 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
464 gtk_window_set_title(GTK_WINDOW(
window), dlg->
title);
467 gtk_container_add(GTK_CONTAINER(
window), dlg->
vbox);
469 g_signal_connect(
window,
"delete_event",
472 gtk_window_set_default_size(GTK_WINDOW(dlg->
v.
window),
475 gtk_widget_show_all(
window);
482 GdkEventButton* button,
485 if (button->type != GDK_2BUTTON_PRESS) {
488 if (button->button != 1) {
509 static int dialog_id_counter;
529 gui_action = gtk_size_group_new(GTK_SIZE_GROUP_VERTICAL);
531 dlg->
gui_button = gtk_size_group_new(GTK_SIZE_GROUP_BOTH);
533 vbox = gtk_grid_new();
535 gtk_grid_set_row_spacing(GTK_GRID(
action_area), 4);
536 gtk_grid_set_column_spacing(GTK_GRID(
action_area), 4);
542 gtk_orientable_set_orientation(GTK_ORIENTABLE(
action_area),
543 GTK_ORIENTATION_VERTICAL);
547 gtk_orientable_set_orientation(GTK_ORIENTABLE(
vbox),
548 GTK_ORIENTATION_VERTICAL);
551 gtk_widget_show(
vbox);
555 gtk_container_set_border_width(GTK_CONTAINER(
vbox), 2);
556 gtk_container_set_border_width(GTK_CONTAINER(
action_area), 2);
563 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
564 gtk_widget_set_name(
window,
"Freeciv");
565 gtk_window_set_position(GTK_WINDOW(
window), GTK_WIN_POS_MOUSE);
568 gtk_container_add(GTK_CONTAINER(
window),
vbox);
570 g_signal_connect(
window,
"delete_event",
577 GtkWidget *hbox, *
label, *image, *button, *event_box;
580 hbox = gtk_grid_new();
582 label = gtk_label_new(NULL);
583 gtk_widget_set_halign(
label, GTK_ALIGN_START);
584 gtk_widget_set_valign(
label, GTK_ALIGN_CENTER);
585 gtk_widget_set_margin_left(
label, 4);
586 gtk_widget_set_margin_right(
label, 4);
587 gtk_widget_set_margin_top(
label, 0);
588 gtk_widget_set_margin_bottom(
label, 0);
589 gtk_container_add(GTK_CONTAINER(hbox),
label);
591 button = gtk_button_new();
592 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
593 g_signal_connect_swapped(button,
"clicked",
596 buf = g_strdup_printf(
_(
"Close Tab:\n%s"),
_(
"Ctrl+W"));
597 gtk_widget_set_tooltip_text(button, buf);
600 image = gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
601 gtk_widget_set_margin_left(image, 0);
602 gtk_widget_set_margin_right(image, 0);
603 gtk_widget_set_margin_top(image, 0);
604 gtk_widget_set_margin_bottom(image, 0);
605 gtk_button_set_image(GTK_BUTTON(button), image);
607 gtk_container_add(GTK_CONTAINER(hbox), button);
609 gtk_widget_show_all(hbox);
611 event_box = gtk_event_box_new();
612 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box),
FALSE);
613 gtk_container_add(GTK_CONTAINER(event_box), hbox);
615 gtk_notebook_append_page(GTK_NOTEBOOK(
notebook),
vbox, event_box);
617 g_signal_connect(
notebook,
"switch-page",
624 gtk_widget_add_events(event_box, GDK_BUTTON2_MOTION_MASK);
625 g_signal_connect(event_box,
"button-press-event",
636 dlg->
id = dialog_id_counter;
640 g_signal_connect(
vbox,
"destroy",
642 g_signal_connect(
vbox,
"key_press_event",
645 g_object_set_data(G_OBJECT(
vbox),
"gui-dialog-data", dlg);
654 g_object_get_data(G_OBJECT(
vbox),
"gui-dialog-data");
656 g_object_get_data(G_OBJECT(button),
"gui-dialog-response-data");
671 g_object_set_data(G_OBJECT(button),
"gui-dialog-response-data",
672 GINT_TO_POINTER(response));
674 if ((signal_id = g_signal_lookup(
"clicked", GTK_TYPE_BUTTON))) {
678 G_OBJECT(dlg->
vbox));
679 g_signal_connect_closure_by_id(button, signal_id, 0, closure,
FALSE);
682 gtk_container_add(GTK_CONTAINER(dlg->
action_area), button);
683 gtk_size_group_add_widget(
gui_action, button);
684 gtk_size_group_add_widget(dlg->
gui_button, button);
692 const char *text,
int response)
697 gtk_widget_set_can_default(button,
TRUE);
707 const char *text,
int response)
711 button = gtk_button_new_from_stock(text);
712 gtk_widget_set_can_default(button,
TRUE);
738 children = gtk_container_get_children(GTK_CONTAINER(dlg->
action_area));
741 GtkWidget *button =
list->data;
743 if (GTK_IS_BUTTON(button)) {
744 gpointer data = g_object_get_data(G_OBJECT(button),
745 "gui-dialog-response-data");
747 if (response == GPOINTER_TO_INT(data)) {
748 gtk_widget_grab_default(button);
753 g_list_free(children);
765 children = gtk_container_get_children(GTK_CONTAINER(dlg->
action_area));
768 GtkWidget *button =
list->data;
770 if (GTK_IS_BUTTON(button)) {
771 gpointer data = g_object_get_data(G_OBJECT(button),
772 "gui-dialog-response-data");
774 if (response == GPOINTER_TO_INT(data)) {
775 gtk_widget_set_sensitive(button,
setting);
780 g_list_free(children);
788 return gtk_widget_get_toplevel(dlg->
vbox);
796 gtk_widget_show_all(dlg->
vbox);
801 gint num_visible = 0;
803 children = gtk_container_get_children(GTK_CONTAINER(dlg->
action_area));
806 GtkWidget *button =
list->data;
808 if (!GTK_IS_BUTTON(button)) {
811 gpointer data = g_object_get_data(G_OBJECT(button),
812 "gui-dialog-response-data");
813 int response = GPOINTER_TO_INT(data);
815 if (response != GTK_RESPONSE_CLOSE
816 && response != GTK_RESPONSE_CANCEL) {
819 gtk_widget_hide(button);
823 g_list_free(children);
825 if (num_visible == 0) {
840 gtk_widget_show(dlg->
v.
window);
847 current = gtk_notebook_get_current_page(
notebook);
852 GdkRGBA
color = {.red = 1.0, .green = 0, .blue = 0, .alpha = 1.0};
854 gtk_widget_override_color(
label, GTK_STATE_FLAG_NORMAL, &
color);
870 gtk_window_present(GTK_WINDOW(dlg->
v.
window));
878 gtk_notebook_set_current_page(
notebook,
n);
899 current = gtk_notebook_get_current_page(
notebook);
904 GdkRGBA
color = {.red = 0, .green = 0, .blue =1.0, .alpha = 1.0};
906 gtk_widget_override_color(
label, GTK_STATE_FLAG_NORMAL, &
color);
943 gtk_label_set_text_with_mnemonic(GTK_LABEL(dlg->
v.
tab.
label),
title);
955 gtk_widget_destroy(dlg->
v.
window);
962 gtk_notebook_remove_page(GTK_NOTEBOOK(dlg->
v.
tab.
notebook),
n);
976 it_next = g_list_next(it);
997 if (return_dialog == NULL) {
1010 GtkCssProvider *provider;
1011 PangoFontDescription *desc;
1017 desc = pango_font_description_from_string(font_value);
1023 fam = pango_font_description_get_family(desc);
1029 if (pango_font_description_get_style(desc) == PANGO_STYLE_ITALIC) {
1030 style =
"\n font-style: italic;";
1035 if (pango_font_description_get_weight(desc) >= 700) {
1036 weight =
"\n font-weight: bold;";
1041 size = pango_font_description_get_size(desc);
1044 if (pango_font_description_get_size_is_absolute(desc)) {
1045 str = g_strdup_printf(
"#Freeciv #%s { font-family: %s; font-size: %dpx;%s%s}",
1048 str = g_strdup_printf(
"#Freeciv #%s { font-family: %s; font-size: %dpt;%s%s}",
1052 str = g_strdup_printf(
"#Freeciv #%s { font-family: %s;%s%s}",
1056 pango_font_description_free(desc);
1058 provider = gtk_css_provider_new();
1059 gtk_css_provider_load_from_data(GTK_CSS_PROVIDER(provider),
1061 gtk_style_context_add_provider_for_screen(
1062 gtk_widget_get_screen(
toplevel), GTK_STYLE_PROVIDER(provider),
1063 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
1071 PangoFontDescription **font_desc)
1073 PangoFontDescription *f_desc;
1077 f_desc = pango_font_description_from_string(font_value);
1078 pango_font_description_free(*font_desc);
1080 *font_desc = f_desc;
1095 hid = g_signal_handler_find(obj, G_SIGNAL_MATCH_FUNC,
1096 0, 0, NULL, cb, NULL);
1097 g_signal_handler_block(obj, hid);
1111 hid = g_signal_handler_find(obj, G_SIGNAL_MATCH_FUNC,
1112 0, 0, NULL, cb, NULL);
1113 g_signal_handler_unblock(obj, hid);
1121 GType gtype,
int model_index)
1123 GtkTreeViewColumn *col;
1124 GtkCellRenderer *rend;
1131 if (gtype == G_TYPE_BOOLEAN) {
1132 rend = gtk_cell_renderer_toggle_new();
1134 }
else if (gtype == GDK_TYPE_PIXBUF) {
1135 rend = gtk_cell_renderer_pixbuf_new();
1138 rend = gtk_cell_renderer_text_new();
1142 col = gtk_tree_view_column_new_with_attributes(
title, rend, attr,
1144 gtk_tree_view_append_column(GTK_TREE_VIEW(
view), col);
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)
GtkWidget * gui_dialog_add_stockbutton(struct gui_dialog *dlg, const char *stock, const char *text, int response)
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)
GtkWidget * gtk_stockbutton_new(const gchar *stock, const gchar *label_text)
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
#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