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
85 bool reorder_notebook);
98 gint response_id, gpointer data)
102 switch (response_id) {
104 gtk_widget_destroy(GTK_WIDGET(dialog));
108 gtk_widget_destroy(GTK_WIDGET(dialog));
133 if (NULL != pdialog->
shell) {
135 pdialog->
shell = NULL;
148 if (NULL != pdialog) {
161 if (NULL != pdialog) {
174 if (NULL != pdialog) {
183 GdkEventButton *
event,
187 GtkWidget *menu, *
item;
194 menu = gtk_menu_new();
196 item = gtk_menu_item_new_with_label(
_(
"Refresh this option"));
197 gtk_menu_shell_append(GTK_MENU_SHELL(menu),
item);
198 g_signal_connect(
item,
"activate",
201 item = gtk_menu_item_new_with_label(
_(
"Reset this option"));
202 gtk_menu_shell_append(GTK_MENU_SHELL(menu),
item);
203 g_signal_connect(
item,
"activate",
206 item = gtk_menu_item_new_with_label(
_(
"Apply the changes for this option"));
207 gtk_menu_shell_append(GTK_MENU_SHELL(menu),
item);
208 g_signal_connect(
item,
"activate",
211 gtk_widget_show_all(menu);
212 gtk_menu_popup_at_pointer(GTK_MENU(menu), NULL);
238 GdkRGBA *
color = (GdkRGBA *) data;
241 gdk_rgba_free(
color);
249 const GdkRGBA *new_color)
251 GdkRGBA *current_color = g_object_get_data(G_OBJECT(button),
"color");
254 if (NULL == new_color) {
255 if (NULL != current_color) {
256 g_object_set_data(G_OBJECT(button),
"color", NULL);
257 if ((child = gtk_bin_get_child(GTK_BIN(button)))) {
258 gtk_widget_destroy(child);
265 if (NULL != current_color) {
267 *current_color = *new_color;
270 current_color = gdk_rgba_copy(new_color);
271 g_object_set_data_full(G_OBJECT(button),
"color", current_color,
274 if ((child = gtk_bin_get_child(GTK_BIN(button)))) {
275 gtk_widget_destroy(child);
280 cairo_surface_t *surface = cairo_image_surface_create(
281 CAIRO_FORMAT_RGB24, 16, 16);
282 cairo_t *cr = cairo_create(surface);
283 gdk_cairo_set_source_rgba(cr, current_color);
286 pixbuf = gdk_pixbuf_get_from_surface(surface, 0, 0, 16, 16);
287 cairo_surface_destroy(surface);
289 child = gtk_image_new_from_pixbuf(pixbuf);
290 gtk_container_add(GTK_CONTAINER(button), child);
291 gtk_widget_show(child);
292 g_object_unref(G_OBJECT(pixbuf));
300 gint res, gpointer data)
302 if (res == GTK_RESPONSE_REJECT) {
305 }
else if (res == GTK_RESPONSE_OK) {
307 GtkColorChooser *chooser =
308 GTK_COLOR_CHOOSER(g_object_get_data(G_OBJECT(dialog),
"chooser"));
311 gtk_color_chooser_get_rgba(chooser, &new_color);
315 gtk_widget_destroy(GTK_WIDGET(dialog));
323 GtkWidget *dialog, *chooser;
324 GdkRGBA *current_color = g_object_get_data(G_OBJECT(button),
"color");
326 dialog = gtk_dialog_new_with_buttons(
_(
"Select a color"), NULL,
328 _(
"_Cancel"), GTK_RESPONSE_CANCEL,
329 _(
"C_lear"), GTK_RESPONSE_REJECT,
330 _(
"_OK"), GTK_RESPONSE_OK, NULL);
332 g_signal_connect(dialog,
"response",
335 chooser = gtk_color_chooser_widget_new();
336 g_object_set_data(G_OBJECT(dialog),
"chooser", chooser);
337 gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), chooser,
340 gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(chooser), current_color);
343 gtk_widget_show_all(dialog);
359 pdialog->
shell = gtk_dialog_new_with_buttons(
name, NULL, 0,
366 pdialog->
notebook = gtk_notebook_new();
379 gtk_window_set_position(GTK_WINDOW(pdialog->
shell), GTK_WIN_POS_MOUSE);
380 gtk_window_set_default_size(GTK_WINDOW(pdialog->
shell), -1, 480);
381 g_signal_connect(pdialog->
shell,
"response",
383 g_signal_connect(pdialog->
shell,
"destroy",
386 gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(pdialog->
shell))),
397 gtk_widget_show_all(pdialog->
shell);
419 pdialog->
shell = NULL;
420 gtk_widget_destroy(
shell);
433 GObject *obj1 = G_OBJECT(*(GtkWidget **) w1);
434 GObject *obj2 = G_OBJECT(*(GtkWidget **) w2);
436 return (GPOINTER_TO_INT(g_object_get_data(obj1,
"category"))
437 - GPOINTER_TO_INT(g_object_get_data(obj2,
"category")));
446 const int pages_num = gtk_notebook_get_n_pages(
notebook);
449 GtkWidget *pages[pages_num];
452 for (i = 0; i < pages_num; i++) {
453 pages[i] = gtk_notebook_get_nth_page(
notebook, i);
456 for (i = 0; i < pages_num; i++) {
457 gtk_notebook_reorder_child(
notebook, pages[i], i);
466 void (*option_action)
472 option_action(poption);
481 bool reorder_notebook)
484 GtkWidget *main_hbox, *label, *ebox, *w = NULL;
489 if (NULL == pdialog->
vboxes[category]) {
492 sw = gtk_scrolled_window_new(NULL, NULL);
493 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
495 GTK_POLICY_AUTOMATIC);
496 g_object_set_data(G_OBJECT(sw),
"category", GINT_TO_POINTER(category));
497 gtk_notebook_append_page(GTK_NOTEBOOK(pdialog->
notebook), sw,
498 gtk_label_new_with_mnemonic
501 if (reorder_notebook) {
505 pdialog->
vboxes[category] = gtk_grid_new();
506 gtk_orientable_set_orientation(GTK_ORIENTABLE(pdialog->
vboxes[category]),
507 GTK_ORIENTATION_VERTICAL);
508 g_object_set(pdialog->
vboxes[category],
"margin", 8, NULL);
509 gtk_widget_set_hexpand(pdialog->
vboxes[category],
TRUE);
510 gtk_container_add(GTK_CONTAINER(sw), pdialog->
vboxes[category]);
512 gtk_widget_show_all(sw);
516 ebox = gtk_event_box_new();
518 gtk_container_add(GTK_CONTAINER(pdialog->
vboxes[category]), ebox);
519 g_signal_connect(ebox,
"button_press_event",
522 main_hbox = gtk_grid_new();
524 g_object_set(label,
"margin", 2, NULL);
525 gtk_container_add(GTK_CONTAINER(main_hbox), label);
526 gtk_container_add(GTK_CONTAINER(ebox), main_hbox);
530 w = gtk_check_button_new();
537 w = gtk_spin_button_new_with_range(min, max,
MAX((max - min) / 50, 1));
545 if (NULL != values) {
546 w = gtk_combo_box_text_new_with_entry();
548 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(w), value);
561 GtkCellRenderer *renderer;
565 model = gtk_list_store_new(2, G_TYPE_INT, G_TYPE_STRING);
566 w = gtk_combo_box_new_with_model(GTK_TREE_MODEL(model));
567 g_object_unref(model);
569 renderer = gtk_cell_renderer_text_new();
570 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(w), renderer,
FALSE);
571 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(w), renderer,
574 gtk_list_store_append(model, &iter);
575 gtk_list_store_set(model, &iter, 0, i, 1,
_(
str), -1);
583 GtkWidget *grid, *check;
587 w = gtk_frame_new(NULL);
588 grid = gtk_grid_new();
589 gtk_grid_set_column_spacing(GTK_GRID(grid), 4);
590 gtk_grid_set_row_homogeneous(GTK_GRID(grid),
TRUE);
591 gtk_container_add(GTK_CONTAINER(w), grid);
593 check = gtk_check_button_new();
594 gtk_grid_attach(GTK_GRID(grid), check, 0, i, 1, 1);
596 gtk_grid_attach(GTK_GRID(grid), label, 1, i, 1, 1);
599 g_object_set_data_full(G_OBJECT(w),
"check_buttons",
list,
600 (GDestroyNotify) g_list_free);
605 w = gtk_font_button_new();
606 g_object_set(G_OBJECT(w),
"use-font",
TRUE, NULL);
614 gtk_grid_set_column_spacing(GTK_GRID(w), 4);
615 gtk_grid_set_row_homogeneous(GTK_GRID(w),
TRUE);
618 button = gtk_button_new();
619 gtk_container_add(GTK_CONTAINER(w), button);
620 gtk_widget_set_tooltip_text(GTK_WIDGET(button),
621 _(
"Select the text color"));
622 g_object_set_data(G_OBJECT(w),
"fg_button", button);
623 g_signal_connect(button,
"clicked",
627 button = gtk_button_new();
628 gtk_container_add(GTK_CONTAINER(w), button);
629 gtk_widget_set_tooltip_text(GTK_WIDGET(button),
630 _(
"Select the background color"));
631 g_object_set_data(G_OBJECT(w),
"bg_button", button);
632 g_signal_connect(button,
"clicked",
638 log_error(
"Option type %s (%d) not supported yet.",
646 log_error(
"Failed to create a widget for option %d \"%s\".",
649 g_object_set_data(G_OBJECT(w),
"main_widget", ebox);
650 gtk_widget_set_hexpand(w,
TRUE);
651 gtk_widget_set_halign(w, GTK_ALIGN_END);
652 gtk_container_add(GTK_CONTAINER(main_hbox), w);
655 gtk_widget_show_all(ebox);
669 if (NULL !=
object) {
673 gtk_widget_destroy(GTK_WIDGET(g_object_get_data(
object,
"main_widget")));
677 gtk_notebook_remove_page(GTK_NOTEBOOK(pdialog->
notebook), category);
678 pdialog->
vboxes[category] = NULL;
689 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON
711 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN
725 GtkTreeModel *model = gtk_combo_box_get_model(combo);
729 if (gtk_tree_model_get_iter_first(model, &iter)) {
731 gtk_tree_model_get(model, &iter, 0, &i, -1);
733 gtk_combo_box_set_active_iter(combo, &iter);
736 }
while (gtk_tree_model_iter_next(model, &iter));
739 log_error(
"Didn't find the value %d for option \"%s\" (nb %d).",
750 GList *iter = g_object_get_data(data,
"check_buttons");
753 for (bit = 0; NULL != iter; iter = g_list_next(iter), bit++) {
754 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(iter->data),
765 gtk_font_chooser_set_font(GTK_FONT_CHOOSER
779 if (NULL !=
color.foreground
780 &&
'\0' !=
color.foreground[0]
781 && gdk_rgba_parse(&gdk_color,
color.foreground)) {
791 if (NULL !=
color.background
792 &&
'\0' !=
color.background[0]
793 && gdk_rgba_parse(&gdk_color,
color.background)) {
831 log_error(
"Option type %s (%d) not supported yet.",
869 log_error(
"Option type %s (%d) not supported yet.",
886 (GTK_TOGGLE_BUTTON(w)));
891 (GTK_SPIN_BUTTON(w)));
897 (GTK_ENTRY(gtk_bin_get_child(GTK_BIN(w)))));
908 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(w), &iter)) {
912 gtk_tree_model_get(gtk_combo_box_get_model(GTK_COMBO_BOX(w)),
913 &iter, 0, &value, -1);
920 GList *iter = g_object_get_data(G_OBJECT(w),
"check_buttons");
924 for (bit = 0; NULL != iter; iter = g_list_next(iter), bit++) {
925 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(iter->data))) {
935 (GTK_FONT_CHOOSER(w)));
940 gchar *fg_color_text = NULL, *bg_color_text = NULL;
945 button = g_object_get_data(G_OBJECT(w),
"fg_button");
946 color = g_object_get_data(button,
"color");
947 if (
color) fg_color_text = gdk_rgba_to_string(
color);
950 button = g_object_get_data(G_OBJECT(w),
"bg_button");
951 color = g_object_get_data(button,
"color");
952 if (
color) bg_color_text = gdk_rgba_to_string(
color);
956 g_free(fg_color_text);
957 g_free(bg_color_text);
962 log_error(
"Option type %s (%d) not supported yet.",
976 if (NULL != pdialog) {
990 if (NULL != pdialog) {
1002 if (strcmp(
option_name(poption),
"aifill") == 0) {
1004 }
else if (strcmp(
option_name(poption),
"nationset") == 0) {
1017 if (NULL != pdialog) {
1031 if (NULL != pdialog) {
1045 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)
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