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_image_menu_item_new_with_label(
_(
"Refresh this option"));
197 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(
item),
198 gtk_image_new_from_stock(GTK_STOCK_REFRESH, GTK_ICON_SIZE_MENU));
199 gtk_menu_shell_append(GTK_MENU_SHELL(menu),
item);
200 g_signal_connect(
item,
"activate",
203 item = gtk_image_menu_item_new_with_label(
_(
"Reset this option"));
204 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(
item),
205 gtk_image_new_from_stock(GTK_STOCK_CLEAR, GTK_ICON_SIZE_MENU));
206 gtk_menu_shell_append(GTK_MENU_SHELL(menu),
item);
207 g_signal_connect(
item,
"activate",
210 item = gtk_image_menu_item_new_with_label(
211 _(
"Apply the changes for this option"));
212 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(
item),
213 gtk_image_new_from_stock(GTK_STOCK_APPLY, GTK_ICON_SIZE_MENU));
214 gtk_menu_shell_append(GTK_MENU_SHELL(menu),
item);
215 g_signal_connect(
item,
"activate",
218 gtk_widget_show_all(menu);
219 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, 0);
245 GdkRGBA *
color = (GdkRGBA *) data;
248 gdk_rgba_free(
color);
256 const GdkRGBA *new_color)
258 GdkRGBA *current_color = g_object_get_data(G_OBJECT(button),
"color");
261 if (NULL == new_color) {
262 if (NULL != current_color) {
263 g_object_set_data(G_OBJECT(button),
"color", NULL);
264 if ((child = gtk_bin_get_child(GTK_BIN(button)))) {
265 gtk_widget_destroy(child);
272 if (NULL != current_color) {
274 *current_color = *new_color;
277 current_color = gdk_rgba_copy(new_color);
278 g_object_set_data_full(G_OBJECT(button),
"color", current_color,
281 if ((child = gtk_bin_get_child(GTK_BIN(button)))) {
282 gtk_widget_destroy(child);
287 cairo_surface_t *surface = cairo_image_surface_create(
288 CAIRO_FORMAT_RGB24, 16, 16);
289 cairo_t *cr = cairo_create(surface);
290 gdk_cairo_set_source_rgba(cr, current_color);
293 pixbuf = gdk_pixbuf_get_from_surface(surface, 0, 0, 16, 16);
294 cairo_surface_destroy(surface);
296 child = gtk_image_new_from_pixbuf(pixbuf);
297 gtk_container_add(GTK_CONTAINER(button), child);
298 gtk_widget_show(child);
299 g_object_unref(G_OBJECT(pixbuf));
307 gint res, gpointer data)
309 if (res == GTK_RESPONSE_REJECT) {
312 }
else if (res == GTK_RESPONSE_OK) {
314 GtkColorChooser *chooser =
315 GTK_COLOR_CHOOSER(g_object_get_data(G_OBJECT(dialog),
"chooser"));
318 gtk_color_chooser_get_rgba(chooser, &new_color);
322 gtk_widget_destroy(GTK_WIDGET(dialog));
330 GtkWidget *dialog, *chooser;
331 GdkRGBA *current_color = g_object_get_data(G_OBJECT(button),
"color");
333 dialog = gtk_dialog_new_with_buttons(
_(
"Select a color"), NULL,
335 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
336 GTK_STOCK_CLEAR, GTK_RESPONSE_REJECT,
337 GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
339 g_signal_connect(dialog,
"response",
342 chooser = gtk_color_chooser_widget_new();
343 g_object_set_data(G_OBJECT(dialog),
"chooser", chooser);
344 gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), chooser,
347 gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(chooser), current_color);
350 gtk_widget_show_all(dialog);
366 pdialog->
shell = gtk_dialog_new_with_buttons(
name, NULL, 0,
373 pdialog->
notebook = gtk_notebook_new();
386 gtk_window_set_position(GTK_WINDOW(pdialog->
shell), GTK_WIN_POS_MOUSE);
387 gtk_window_set_default_size(GTK_WINDOW(pdialog->
shell), -1, 480);
388 g_signal_connect(pdialog->
shell,
"response",
390 g_signal_connect(pdialog->
shell,
"destroy",
393 gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(pdialog->
shell))),
404 gtk_widget_show_all(pdialog->
shell);
426 pdialog->
shell = NULL;
427 gtk_widget_destroy(
shell);
440 GObject *obj1 = G_OBJECT(*(GtkWidget **) w1);
441 GObject *obj2 = G_OBJECT(*(GtkWidget **) w2);
443 return (GPOINTER_TO_INT(g_object_get_data(obj1,
"category"))
444 - GPOINTER_TO_INT(g_object_get_data(obj2,
"category")));
453 const int pages_num = gtk_notebook_get_n_pages(
notebook);
456 GtkWidget *pages[pages_num];
459 for (i = 0; i < pages_num; i++) {
460 pages[i] = gtk_notebook_get_nth_page(
notebook, i);
463 for (i = 0; i < pages_num; i++) {
464 gtk_notebook_reorder_child(
notebook, pages[i], i);
473 void (*option_action)
479 option_action(poption);
488 bool reorder_notebook)
491 GtkWidget *main_hbox, *label, *ebox, *w = NULL;
496 if (NULL == pdialog->
vboxes[category]) {
499 sw = gtk_scrolled_window_new(NULL, NULL);
500 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
502 GTK_POLICY_AUTOMATIC);
503 g_object_set_data(G_OBJECT(sw),
"category", GINT_TO_POINTER(category));
504 gtk_notebook_append_page(GTK_NOTEBOOK(pdialog->
notebook), sw,
505 gtk_label_new_with_mnemonic
508 if (reorder_notebook) {
512 pdialog->
vboxes[category] = gtk_grid_new();
513 gtk_orientable_set_orientation(GTK_ORIENTABLE(pdialog->
vboxes[category]),
514 GTK_ORIENTATION_VERTICAL);
515 g_object_set(pdialog->
vboxes[category],
"margin", 8, NULL);
516 gtk_widget_set_hexpand(pdialog->
vboxes[category],
TRUE);
517 gtk_container_add(GTK_CONTAINER(sw), pdialog->
vboxes[category]);
519 gtk_widget_show_all(sw);
523 ebox = gtk_event_box_new();
525 gtk_container_add(GTK_CONTAINER(pdialog->
vboxes[category]), ebox);
526 g_signal_connect(ebox,
"button_press_event",
529 main_hbox = gtk_grid_new();
531 g_object_set(label,
"margin", 2, NULL);
532 gtk_container_add(GTK_CONTAINER(main_hbox), label);
533 gtk_container_add(GTK_CONTAINER(ebox), main_hbox);
537 w = gtk_check_button_new();
544 w = gtk_spin_button_new_with_range(min, max,
MAX((max - min) / 50, 1));
552 if (NULL != values) {
553 w = gtk_combo_box_text_new_with_entry();
555 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(w), value);
568 GtkCellRenderer *renderer;
572 model = gtk_list_store_new(2, G_TYPE_INT, G_TYPE_STRING);
573 w = gtk_combo_box_new_with_model(GTK_TREE_MODEL(model));
574 g_object_unref(model);
576 renderer = gtk_cell_renderer_text_new();
577 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(w), renderer,
FALSE);
578 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(w), renderer,
581 gtk_list_store_append(model, &iter);
582 gtk_list_store_set(model, &iter, 0, i, 1,
_(
str), -1);
590 GtkWidget *grid, *check;
594 w = gtk_frame_new(NULL);
595 grid = gtk_grid_new();
596 gtk_grid_set_column_spacing(GTK_GRID(grid), 4);
597 gtk_grid_set_row_homogeneous(GTK_GRID(grid),
TRUE);
598 gtk_container_add(GTK_CONTAINER(w), grid);
600 check = gtk_check_button_new();
601 gtk_grid_attach(GTK_GRID(grid), check, 0, i, 1, 1);
603 gtk_grid_attach(GTK_GRID(grid), label, 1, i, 1, 1);
606 g_object_set_data_full(G_OBJECT(w),
"check_buttons",
list,
607 (GDestroyNotify) g_list_free);
612 w = gtk_font_button_new();
613 g_object_set(G_OBJECT(w),
"use-font",
TRUE, NULL);
621 gtk_grid_set_column_spacing(GTK_GRID(w), 4);
622 gtk_grid_set_row_homogeneous(GTK_GRID(w),
TRUE);
625 button = gtk_button_new();
626 gtk_container_add(GTK_CONTAINER(w), button);
627 gtk_widget_set_tooltip_text(GTK_WIDGET(button),
628 _(
"Select the text color"));
629 g_object_set_data(G_OBJECT(w),
"fg_button", button);
630 g_signal_connect(button,
"clicked",
634 button = gtk_button_new();
635 gtk_container_add(GTK_CONTAINER(w), button);
636 gtk_widget_set_tooltip_text(GTK_WIDGET(button),
637 _(
"Select the background color"));
638 g_object_set_data(G_OBJECT(w),
"bg_button", button);
639 g_signal_connect(button,
"clicked",
645 log_error(
"Option type %s (%d) not supported yet.",
653 log_error(
"Failed to create a widget for option %d \"%s\".",
656 g_object_set_data(G_OBJECT(w),
"main_widget", ebox);
657 gtk_widget_set_hexpand(w,
TRUE);
658 gtk_widget_set_halign(w, GTK_ALIGN_END);
659 gtk_container_add(GTK_CONTAINER(main_hbox), w);
662 gtk_widget_show_all(ebox);
676 if (NULL !=
object) {
680 gtk_widget_destroy(GTK_WIDGET(g_object_get_data(
object,
"main_widget")));
684 gtk_notebook_remove_page(GTK_NOTEBOOK(pdialog->
notebook), category);
685 pdialog->
vboxes[category] = NULL;
696 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON
718 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN
732 GtkTreeModel *model = gtk_combo_box_get_model(combo);
736 if (gtk_tree_model_get_iter_first(model, &iter)) {
738 gtk_tree_model_get(model, &iter, 0, &i, -1);
740 gtk_combo_box_set_active_iter(combo, &iter);
743 }
while (gtk_tree_model_iter_next(model, &iter));
746 log_error(
"Didn't find the value %d for option \"%s\" (nb %d).",
757 GList *iter = g_object_get_data(data,
"check_buttons");
760 for (bit = 0; NULL != iter; iter = g_list_next(iter), bit++) {
761 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(iter->data),
772 gtk_font_chooser_set_font(GTK_FONT_CHOOSER
786 if (NULL !=
color.foreground
787 &&
'\0' !=
color.foreground[0]
788 && gdk_rgba_parse(&gdk_color,
color.foreground)) {
798 if (NULL !=
color.background
799 &&
'\0' !=
color.background[0]
800 && gdk_rgba_parse(&gdk_color,
color.background)) {
838 log_error(
"Option type %s (%d) not supported yet.",
876 log_error(
"Option type %s (%d) not supported yet.",
893 (GTK_TOGGLE_BUTTON(w)));
898 (GTK_SPIN_BUTTON(w)));
904 (GTK_ENTRY(gtk_bin_get_child(GTK_BIN(w)))));
915 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(w), &iter)) {
919 gtk_tree_model_get(gtk_combo_box_get_model(GTK_COMBO_BOX(w)),
920 &iter, 0, &value, -1);
927 GList *iter = g_object_get_data(G_OBJECT(w),
"check_buttons");
931 for (bit = 0; NULL != iter; iter = g_list_next(iter), bit++) {
932 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(iter->data))) {
942 (GTK_FONT_CHOOSER(w)));
947 gchar *fg_color_text = NULL, *bg_color_text = NULL;
952 button = g_object_get_data(G_OBJECT(w),
"fg_button");
953 color = g_object_get_data(button,
"color");
954 if (
color) fg_color_text = gdk_rgba_to_string(
color);
957 button = g_object_get_data(G_OBJECT(w),
"bg_button");
958 color = g_object_get_data(button,
"color");
959 if (
color) bg_color_text = gdk_rgba_to_string(
color);
963 g_free(fg_color_text);
964 g_free(bg_color_text);
969 log_error(
"Option type %s (%d) not supported yet.",
983 if (NULL != pdialog) {
997 if (NULL != pdialog) {
1009 if (strcmp(
option_name(poption),
"aifill") == 0) {
1011 }
else if (strcmp(
option_name(poption),
"nationset") == 0) {
1024 if (NULL != pdialog) {
1038 if (NULL != pdialog) {
1052 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