50#define SPECLIST_TAG option_dialog
51#define SPECLIST_TYPE struct option_dialog
53#define option_dialogs_iterate(pdialog) \
54 TYPED_LIST_ITERATE(struct option_dialog, option_dialogs, pdialog)
55#define option_dialogs_iterate_end LIST_ITERATE_END
87 bool reorder_notebook);
100 gint response_id, gpointer data)
104 switch (response_id) {
106 gtk_window_destroy(GTK_WINDOW(dialog));
110 gtk_window_destroy(GTK_WINDOW(dialog));
135 if (NULL != pdialog->
shell) {
137 pdialog->
shell = NULL;
151 if (NULL != pdialog) {
168 if (NULL != pdialog) {
185 if (NULL != pdialog) {
202 GtkEventController *controller = GTK_EVENT_CONTROLLER(gesture);
203 GtkWidget *parent = gtk_event_controller_get_widget(controller);
207 GdkRectangle rect = { .x = x, .y = y, .width = 1, .height = 1};
213 group = G_ACTION_GROUP(g_simple_action_group_new());
217 act = g_simple_action_new(
"refresh", NULL);
218 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
223 act = g_simple_action_new(
"unit_reset", NULL);
224 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
229 act = g_simple_action_new(
"units_apply", NULL);
230 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
233 g_menu_item_new(
_(
"Apply the changes for this option"),
236 opt_popover = gtk_popover_menu_new_from_model(G_MENU_MODEL(menu));
238 gtk_widget_insert_action_group(
opt_popover,
"win", group);
241 gtk_popover_set_pointing_to(GTK_POPOVER(
opt_popover), &rect);
269 GdkRGBA *
color = (GdkRGBA *) data;
272 gdk_rgba_free(
color);
280 const GdkRGBA *new_color)
282 GdkRGBA *current_color = g_object_get_data(G_OBJECT(button),
"color");
285 if (NULL == new_color) {
286 if (NULL != current_color) {
287 g_object_set_data(G_OBJECT(button),
"color", NULL);
288 gtk_button_set_child(button, NULL);
294 if (NULL != current_color) {
296 *current_color = *new_color;
299 current_color = gdk_rgba_copy(new_color);
300 g_object_set_data_full(G_OBJECT(button),
"color", current_color,
303 gtk_button_set_child(button, NULL);
307 cairo_surface_t *surface = cairo_image_surface_create(
308 CAIRO_FORMAT_RGB24, 16, 16);
309 cairo_t *cr = cairo_create(surface);
310 gdk_cairo_set_source_rgba(cr, current_color);
313 pixbuf = gdk_pixbuf_get_from_surface(surface, 0, 0, 16, 16);
314 cairo_surface_destroy(surface);
316 child = gtk_image_new_from_pixbuf(pixbuf);
317 gtk_button_set_child(GTK_BUTTON(button), child);
318 gtk_widget_show(child);
319 g_object_unref(G_OBJECT(pixbuf));
327 gint res, gpointer data)
329 if (res == GTK_RESPONSE_REJECT) {
332 }
else if (res == GTK_RESPONSE_OK) {
334 GtkColorChooser *chooser =
335 GTK_COLOR_CHOOSER(g_object_get_data(G_OBJECT(dialog),
"chooser"));
338 gtk_color_chooser_get_rgba(chooser, &new_color);
342 gtk_window_destroy(GTK_WINDOW(dialog));
350 GtkWidget *dialog, *chooser;
351 GdkRGBA *current_color = g_object_get_data(G_OBJECT(button),
"color");
353 dialog = gtk_dialog_new_with_buttons(
_(
"Select a color"), NULL,
355 _(
"_Cancel"), GTK_RESPONSE_CANCEL,
356 _(
"C_lear"), GTK_RESPONSE_REJECT,
357 _(
"_OK"), GTK_RESPONSE_OK, NULL);
359 g_signal_connect(dialog,
"response",
362 chooser = gtk_color_chooser_widget_new();
363 g_object_set_data(G_OBJECT(dialog),
"chooser", chooser);
364 gtk_box_insert_child_after(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),
367 gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(chooser), current_color);
370 gtk_widget_show(dialog);
385 pdialog->
shell = gtk_dialog_new_with_buttons(
name, NULL, 0,
392 pdialog->
notebook = gtk_notebook_new();
405 gtk_window_set_default_size(GTK_WINDOW(pdialog->
shell), -1, 480);
406 g_signal_connect(pdialog->
shell,
"response",
408 g_signal_connect(pdialog->
shell,
"destroy",
411 gtk_box_insert_child_after(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(pdialog->
shell))),
422 gtk_widget_show(pdialog->
shell);
444 pdialog->
shell = NULL;
445 gtk_window_destroy(GTK_WINDOW(
shell));
458 GObject *obj1 = G_OBJECT(*(GtkWidget **) w1);
459 GObject *obj2 = G_OBJECT(*(GtkWidget **) w2);
461 return (GPOINTER_TO_INT(g_object_get_data(obj1,
"category"))
462 - GPOINTER_TO_INT(g_object_get_data(obj2,
"category")));
471 const int pages_num = gtk_notebook_get_n_pages(
notebook);
474 GtkWidget *pages[pages_num];
477 for (i = 0; i < pages_num; i++) {
478 pages[i] = gtk_notebook_get_nth_page(
notebook, i);
481 for (i = 0; i < pages_num; i++) {
482 gtk_notebook_reorder_child(
notebook, pages[i], i);
491 void (*option_action)
497 option_action(poption);
506 bool reorder_notebook)
509 GtkWidget *main_hbox, *label, *w = NULL;
512 GtkEventController *controller;
517 if (NULL == pdialog->
vboxes[category]) {
520 sw = gtk_scrolled_window_new();
521 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
523 GTK_POLICY_AUTOMATIC);
524 gtk_scrolled_window_set_propagate_natural_height(GTK_SCROLLED_WINDOW(sw),
TRUE);
525 g_object_set_data(G_OBJECT(sw),
"category", GINT_TO_POINTER(category));
526 gtk_notebook_append_page(GTK_NOTEBOOK(pdialog->
notebook), sw,
527 gtk_label_new_with_mnemonic
530 if (reorder_notebook) {
534 pdialog->
vboxes[category] = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2);
535 gtk_widget_set_margin_bottom(pdialog->
vboxes[category], 8);
536 gtk_widget_set_margin_end(pdialog->
vboxes[category], 8);
537 gtk_widget_set_margin_start(pdialog->
vboxes[category], 8);
538 gtk_widget_set_margin_top(pdialog->
vboxes[category], 8);
539 gtk_widget_set_hexpand(pdialog->
vboxes[category],
TRUE);
540 gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(sw), pdialog->
vboxes[category]);
546 main_hbox = gtk_grid_new();
548 gtk_widget_set_margin_bottom(label, 2);
549 gtk_widget_set_margin_end(label, 2);
550 gtk_widget_set_margin_start(label, 2);
551 gtk_widget_set_margin_top(label, 2);
552 gtk_grid_attach(GTK_GRID(main_hbox), label, main_col++, 0, 1, 1);
554 gesture = gtk_gesture_click_new();
555 gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(gesture), 3);
556 controller = GTK_EVENT_CONTROLLER(gesture);
557 g_signal_connect(controller,
"pressed",
559 gtk_widget_add_controller(main_hbox, controller);
560 gtk_box_append(GTK_BOX(pdialog->
vboxes[category]), main_hbox);
564 w = gtk_check_button_new();
571 w = gtk_spin_button_new_with_range(min, max,
MAX((max - min) / 50, 1));
579 if (NULL != values) {
580 w = gtk_combo_box_text_new_with_entry();
582 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(w), value);
595 GtkCellRenderer *renderer;
599 model = gtk_list_store_new(2, G_TYPE_INT, G_TYPE_STRING);
600 w = gtk_combo_box_new_with_model(GTK_TREE_MODEL(model));
601 g_object_unref(model);
603 renderer = gtk_cell_renderer_text_new();
604 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(w), renderer,
FALSE);
605 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(w), renderer,
608 gtk_list_store_append(model, &iter);
609 gtk_list_store_set(model, &iter, 0, i, 1,
_(
str), -1);
617 GtkWidget *grid, *check;
621 w = gtk_frame_new(NULL);
622 grid = gtk_grid_new();
623 gtk_grid_set_column_spacing(GTK_GRID(grid), 4);
624 gtk_grid_set_row_homogeneous(GTK_GRID(grid),
TRUE);
625 gtk_frame_set_child(GTK_FRAME(w), grid);
627 check = gtk_check_button_new();
628 gtk_grid_attach(GTK_GRID(grid), check, 0, i, 1, 1);
630 gtk_grid_attach(GTK_GRID(grid), label, 1, i, 1, 1);
633 g_object_set_data_full(G_OBJECT(w),
"check_buttons",
list,
634 (GDestroyNotify) g_list_free);
639 w = gtk_font_button_new();
640 g_object_set(G_OBJECT(w),
"use-font",
TRUE, NULL);
649 gtk_grid_set_column_spacing(GTK_GRID(w), 4);
650 gtk_grid_set_row_homogeneous(GTK_GRID(w),
TRUE);
653 button = gtk_button_new();
654 gtk_grid_attach(GTK_GRID(w), button, grid_col++, 0, 1, 1);
655 gtk_widget_set_tooltip_text(GTK_WIDGET(button),
656 _(
"Select the text color"));
657 g_object_set_data(G_OBJECT(w),
"fg_button", button);
658 g_signal_connect(button,
"clicked",
662 button = gtk_button_new();
663 gtk_grid_attach(GTK_GRID(w), button, grid_col++, 0, 1, 1);
664 gtk_widget_set_tooltip_text(GTK_WIDGET(button),
665 _(
"Select the background color"));
666 g_object_set_data(G_OBJECT(w),
"bg_button", button);
667 g_signal_connect(button,
"clicked",
673 log_error(
"Option type %s (%d) not supported yet.",
681 log_error(
"Failed to create a widget for option %d \"%s\".",
684 g_object_set_data(G_OBJECT(w),
"main_widget", main_hbox);
685 g_object_set_data(G_OBJECT(w),
"parent_of_main", pdialog->
vboxes[category]);
686 gtk_widget_set_hexpand(w,
TRUE);
687 gtk_widget_set_halign(w, GTK_ALIGN_END);
688 gtk_grid_attach(GTK_GRID(main_hbox), w, main_col++, 0, 1, 1);
691 gtk_widget_show(main_hbox);
705 if (NULL !=
object) {
709 gtk_box_remove(GTK_BOX(g_object_get_data(
object,
"parent_of_main")),
710 GTK_WIDGET(g_object_get_data(
object,
"main_widget")));
714 gtk_notebook_remove_page(GTK_NOTEBOOK(pdialog->
notebook), category);
715 pdialog->
vboxes[category] = NULL;
726 gtk_check_button_set_active(GTK_CHECK_BUTTON
750 GtkWidget *child = gtk_combo_box_get_child(GTK_COMBO_BOX(wdg));
752 gtk_entry_buffer_set_text(gtk_entry_get_buffer(GTK_ENTRY(child)),
string, -1);
754 gtk_entry_buffer_set_text(gtk_entry_get_buffer(GTK_ENTRY(wdg)),
string, -1);
765 GtkTreeModel *model = gtk_combo_box_get_model(combo);
769 if (gtk_tree_model_get_iter_first(model, &iter)) {
771 gtk_tree_model_get(model, &iter, 0, &i, -1);
773 gtk_combo_box_set_active_iter(combo, &iter);
776 }
while (gtk_tree_model_iter_next(model, &iter));
779 log_error(
"Didn't find the value %d for option \"%s\" (nb %d).",
790 GList *iter = g_object_get_data(data,
"check_buttons");
793 for (bit = 0; NULL != iter; iter = g_list_next(iter), bit++) {
794 gtk_check_button_set_active(GTK_CHECK_BUTTON(iter->data),
805 gtk_font_chooser_set_font(GTK_FONT_CHOOSER
819 if (NULL !=
color.foreground
820 &&
'\0' !=
color.foreground[0]
821 && gdk_rgba_parse(&gdk_color,
color.foreground)) {
831 if (NULL !=
color.background
832 &&
'\0' !=
color.background[0]
833 && gdk_rgba_parse(&gdk_color,
color.background)) {
871 log_error(
"Option type %s (%d) not supported yet.",
909 log_error(
"Option type %s (%d) not supported yet.",
926 (GTK_CHECK_BUTTON(w)));
931 (GTK_SPIN_BUTTON(w)));
937 gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(w)));
940 gtk_entry_get_buffer(GTK_ENTRY(w))));
949 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(w), &iter)) {
953 gtk_tree_model_get(gtk_combo_box_get_model(GTK_COMBO_BOX(w)),
954 &iter, 0, &value, -1);
961 GList *iter = g_object_get_data(G_OBJECT(w),
"check_buttons");
965 for (bit = 0; NULL != iter; iter = g_list_next(iter), bit++) {
966 if (gtk_check_button_get_active(GTK_CHECK_BUTTON(iter->data))) {
976 (GTK_FONT_CHOOSER(w)));
981 gchar *fg_color_text = NULL, *bg_color_text = NULL;
986 button = g_object_get_data(G_OBJECT(w),
"fg_button");
987 color = g_object_get_data(button,
"color");
988 if (
color) fg_color_text = gdk_rgba_to_string(
color);
991 button = g_object_get_data(G_OBJECT(w),
"bg_button");
992 color = g_object_get_data(button,
"color");
993 if (
color) bg_color_text = gdk_rgba_to_string(
color);
997 g_free(fg_color_text);
998 g_free(bg_color_text);
1003 log_error(
"Option type %s (%d) not supported yet.",
1017 if (NULL != pdialog) {
1031 if (NULL != pdialog) {
1043 if (strcmp(
option_name(poption),
"aifill") == 0) {
1045 }
else if (strcmp(
option_name(poption),
"nationset") == 0) {
1058 if (NULL != pdialog) {
1072 if (NULL != pdialog) {
1086 if (NULL != pdialog) {
static struct fc_sockaddr_list * list
static struct ft_color ft_color_construct(const char *foreground, const char *background)
void nationset_sync_to_server(const char *nationset)
void setup_dialog(GtkWidget *shell, GtkWidget *parent)
static struct gui_dialog * shell
static void option_dialog_destroy_callback(GtkWidget *object, gpointer data)
static void color_selector_response_callback(GtkDialog *dialog, gint res, gpointer data)
static struct option_dialog * option_dialog_get(const struct option_set *poptset)
void option_gui_remove(struct option *poption)
static void option_dialog_option_refresh(struct option *poption)
void option_dialog_popdown(const struct option_set *poptset)
static void option_dialog_option_color_set(struct option *poption, struct ft_color color)
static void option_color_set_button_color(GtkButton *button, const GdkRGBA *new_color)
static void option_dialog_option_add(struct option_dialog *pdialog, struct option *poption, bool reorder_notebook)
#define option_dialogs_iterate_end
static void option_dialog_option_bitwise_set(struct option *poption, unsigned value)
static void option_dialog_destroy(struct option_dialog *pdialog)
static void option_dialog_option_bool_set(struct option *poption, bool value)
static void option_dialog_option_remove(struct option_dialog *pdialog, struct option *poption)
void option_gui_add(struct option *poption)
static void option_color_select_callback(GtkButton *button, gpointer data)
static void option_dialog_option_int_set(struct option *poption, int value)
static void option_dialog_reponse_callback(GtkDialog *dialog, gint response_id, gpointer data)
#define option_dialogs_iterate(pdialog)
static void option_gui_update_extra(struct option *poption)
static void option_apply_callback(GtkMenuItem *menuitem, gpointer data)
static void option_color_destroy_notify(gpointer data)
static void option_dialog_option_font_set(struct option *poption, const char *font)
void option_gui_update(struct option *poption)
static int option_dialog_pages_sort_func(const void *w1, const void *w2)
void option_dialog_popup(const char *name, const struct option_set *poptset)
static void option_dialog_reorder_notebook(struct option_dialog *pdialog)
static void option_dialog_option_apply(struct option *poption)
static gboolean option_button_press_callback(GtkWidget *widget, GdkEventButton *event, gpointer data)
static void option_dialog_option_reset(struct option *poption)
static void option_reset_callback(GtkMenuItem *menuitem, gpointer data)
static void option_dialog_foreach(struct option_dialog *pdialog, void(*option_action)(struct option *))
static void option_dialog_option_str_set(struct option *poption, const char *string)
static struct option_dialog_list * option_dialogs
static void option_dialog_option_enum_set(struct option *poption, int value)
static void option_refresh_callback(GtkMenuItem *menuitem, gpointer data)
void ai_fill_changed_by_server(int aifill)
#define menu_item_append_unref(menu, item)
static GtkWidget * opt_popover
static struct option_dialog * option_dialog_new(void)
#define fc_assert_ret(condition)
#define fc_assert(condition)
#define log_error(message,...)
#define fc_calloc(n, esz)
const struct strvec * option_str_values(const struct option *poption)
unsigned option_bitwise_def(const struct option *poption)
int option_int_min(const struct option *poption)
bool option_bool_def(const struct option *poption)
const char * option_font_def(const struct option *poption)
const struct option_set * server_optset
const char * option_description(const struct option *poption)
const char * option_help_text(const struct option *poption)
struct ft_color option_color_get(const struct option *poption)
int option_enum_get_int(const struct option *poption)
int option_number(const struct option *poption)
int option_category(const struct option *poption)
bool option_str_set(struct option *poption, const char *str)
const char * option_name(const struct option *poption)
int option_int_get(const struct option *poption)
bool option_color_set(struct option *poption, struct ft_color color)
bool option_bool_set(struct option *poption, bool val)
bool option_is_changeable(const struct option *poption)
void option_set_gui_data(struct option *poption, void *data)
const char * option_str_get(const struct option *poption)
void * option_get_gui_data(const struct option *poption)
bool option_enum_set_int(struct option *poption, int val)
bool option_bool_get(const struct option *poption)
int optset_category_number(const struct option_set *poptset)
enum option_type option_type(const struct option *poption)
const char * option_enum_int_to_str(const struct option *poption, int val)
const struct option_set * option_optset(const struct option *poption)
const char * option_str_def(const struct option *poption)
int option_int_max(const struct option *poption)
bool option_font_set(struct option *poption, const char *font)
void options_save(option_save_log_callback log_cb)
const struct strvec * option_bitwise_values(const struct option *poption)
bool option_bitwise_set(struct option *poption, unsigned val)
const char * option_font_get(const struct option *poption)
void desired_settable_options_update(void)
struct ft_color option_color_def(const struct option *poption)
unsigned option_bitwise_get(const struct option *poption)
int option_enum_def_int(const struct option *poption)
bool option_int_set(struct option *poption, int val)
const char * option_category_name(const struct option *poption)
int option_int_def(const struct option *poption)
#define options_iterate(poptset, poption)
#define options_iterate_end
const char * strvec_get(const struct strvec *psv, size_t svindex)
size_t strvec_size(const struct strvec *psv)
#define strvec_iterate(psv, str)
#define strvec_iterate_end
const struct option_set * poptset