From 95a11a738cdd53e84e30358d2e55f080c63f10b5 Mon Sep 17 00:00:00 2001 From: Logan Rathbone Date: Fri, 12 Feb 2021 16:30:26 -0500 Subject: Tweak layout of msg dialogs. Get font-setter to work with text-info. --- src/calendar.c | 8 +- src/main.c | 2 +- src/msg.c | 64 +-- src/text.c | 14 +- src/util.c | 129 ++++++ src/util.h | 1 + src/zenity.ui | 1311 +++++++++++++++++++++++++++++--------------------------- 7 files changed, 849 insertions(+), 680 deletions(-) (limited to 'src') diff --git a/src/calendar.c b/src/calendar.c index 21dc6a1..0fb84ed 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -112,13 +112,11 @@ zenity_calendar (ZenityData *data, ZenityCalendarData *cal_data) dialog); } - if (data->extra_label) { - int i = 0; - - while (data->extra_label[i] != NULL) { + if (data->extra_label) + { + for (int i = 0; data->extra_label[i] != NULL; ++i) { gtk_dialog_add_button (GTK_DIALOG(dialog), data->extra_label[i], i); - i++; } } diff --git a/src/main.c b/src/main.c index d4281cf..7a37c05 100644 --- a/src/main.c +++ b/src/main.c @@ -46,7 +46,6 @@ activate_cb (GtkApplication *app, gpointer user_data) int retval; results = zenity_option_parse (args->argc, args->argv); - g_free (args); switch (results->mode) { @@ -128,6 +127,7 @@ activate_cb (GtkApplication *app, gpointer user_data) retval = results->data->exit_code; zenity_option_free (); + g_free (args); // FIXME - pass retval to gapplication properly. // exit (retval); diff --git a/src/msg.c b/src/msg.c index 45c138d..983fd6a 100644 --- a/src/msg.c +++ b/src/msg.c @@ -33,18 +33,18 @@ static void zenity_msg_dialog_response (GtkWidget *widget, int response, gpointer data); static void -zenity_msg_construct_question_dialog ( - GtkWidget *dialog, ZenityMsgData *msg_data, ZenityData *data) { - +zenity_msg_construct_question_dialog (GtkWidget *dialog, + ZenityMsgData *msg_data, ZenityData *data) +{ GtkWidget *cancel_button, *ok_button; - cancel_button = gtk_dialog_add_button ( - GTK_DIALOG (dialog), _ ("_No"), GTK_RESPONSE_CANCEL); - ok_button = gtk_dialog_add_button ( - GTK_DIALOG (dialog), _ ("_Yes"), GTK_RESPONSE_OK); + cancel_button = gtk_dialog_add_button (GTK_DIALOG (dialog), + _("_No"), GTK_RESPONSE_CANCEL); + ok_button = gtk_dialog_add_button (GTK_DIALOG (dialog), + _("_Yes"), GTK_RESPONSE_OK); - gtk_widget_grab_focus ( - msg_data->default_cancel ? cancel_button : ok_button); + gtk_widget_grab_focus + (msg_data->default_cancel ? cancel_button : ok_button); if (data->cancel_label) { gtk_button_set_label (GTK_BUTTON (cancel_button), data->cancel_label); @@ -56,7 +56,8 @@ zenity_msg_construct_question_dialog ( } static void -zenity_label_widget_clipboard_selection (GtkWidget *widget) { +zenity_label_widget_clipboard_selection (GtkWidget *widget) +{ /* Workaround hotfix for suspected toolkit issue: since focus change of the dialog's focussed widget (text) somehow currently chooses to destroy @@ -140,12 +141,12 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data) break; } - if (data->extra_label) { - gint i = 0; - while (data->extra_label[i] != NULL) { - gtk_dialog_add_button ( - GTK_DIALOG (dialog), data->extra_label[i], i); - i++; + if (data->extra_label) + { + for (int i = 0; data->extra_label[i] != NULL; ++i) + { + gtk_dialog_add_button (GTK_DIALOG (dialog), + data->extra_label[i], i); } } @@ -199,31 +200,32 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data) default: break; } + if (data->width > -1 || data->height > -1) { + gtk_window_set_default_size (GTK_WINDOW(dialog), + data->width, data->height); + } - if (data->width > -1 || data->height > -1) - gtk_window_set_default_size ( - GTK_WINDOW (dialog), data->width, data->height); - - if (data->width > -1) + if (data->width > -1) { gtk_widget_set_size_request (GTK_WIDGET (text), data->width, -1); + } else if (!msg_data->ellipsize && !msg_data->no_wrap) { /* the magic number 60 is picked from gtk+/gtk/ui/gtkmessagedialog.ui - * however, 60 would increase the distance between the icon and the - * text, decreasing to 10 fix it. */ - gtk_label_set_width_chars (GTK_LABEL(text), 10); - gtk_label_set_max_width_chars (GTK_LABEL(text), 10); + gtk_label_set_max_width_chars (GTK_LABEL(text), 60); } if (data->modal) gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); - if (msg_data->dialog_text) { - if (msg_data->no_markup) + if (msg_data->dialog_text) + { + if (msg_data->no_markup) { gtk_label_set_text (GTK_LABEL (text), msg_data->dialog_text); - else - gtk_label_set_markup ( - GTK_LABEL (text), g_strcompress (msg_data->dialog_text)); + } + else { + gtk_label_set_markup (GTK_LABEL (text), + g_strcompress (msg_data->dialog_text)); + } zenity_label_widget_clipboard_selection (GTK_WIDGET (text)); } @@ -235,7 +237,7 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data) GTK_IMAGE (image), msg_data->dialog_icon); if (msg_data->no_wrap) - gtk_label_set_wrap (GTK_LABEL (text), FALSE); + gtk_label_set_wrap (GTK_LABEL(text), FALSE); zenity_util_show_dialog (dialog); diff --git a/src/text.c b/src/text.c index a7f47e2..291b5da 100644 --- a/src/text.c +++ b/src/text.c @@ -309,19 +309,17 @@ zenity_text (ZenityData *data, ZenityTextData *text_data) if (text_data->font) { + PangoFontDescription *desc; GtkStyleContext *context; GtkCssProvider *provider; - char *font_str; + char *css_str; - font_str = g_strdup_printf ( - "* { \n" - " font: %s\n" - "}\n", - text_data->font); + desc = pango_font_description_from_string (text_data->font); + css_str = zenity_util_pango_font_description_to_css (desc); provider = gtk_css_provider_new (); - gtk_css_provider_load_from_data (provider, font_str, -1); - g_free (font_str); + gtk_css_provider_load_from_data (provider, css_str, -1); + g_free (css_str); context = gtk_widget_get_style_context (GTK_WIDGET(text_view)); gtk_style_context_add_provider (context, diff --git a/src/util.c b/src/util.c index 0c35144..8ec7e29 100644 --- a/src/util.c +++ b/src/util.c @@ -390,6 +390,135 @@ zenity_util_make_transient (GdkWindow *window, Window parent) { #endif /* GDK_WINDOWING_X11 */ +/* helper for common_set_gtkhex_font_from_settings. + * + * This function was written by Matthias Clasen and is included somewhere in + * the GTK source tree.. I believe it is also included in libdazzle, but I + * didn't want to include a whole dependency just for one function. LGPL, but + * credit where credit is due! + */ +char * +zenity_util_pango_font_description_to_css (PangoFontDescription *desc) +{ + GString *s; + PangoFontMask set; + + s = g_string_new ("* { "); + + set = pango_font_description_get_set_fields (desc); + if (set & PANGO_FONT_MASK_FAMILY) + { + g_string_append (s, "font-family: "); + g_string_append (s, pango_font_description_get_family (desc)); + g_string_append (s, "; "); + } + if (set & PANGO_FONT_MASK_STYLE) + { + switch (pango_font_description_get_style (desc)) + { + case PANGO_STYLE_NORMAL: + g_string_append (s, "font-style: normal; "); + break; + case PANGO_STYLE_OBLIQUE: + g_string_append (s, "font-style: oblique; "); + break; + case PANGO_STYLE_ITALIC: + g_string_append (s, "font-style: italic; "); + break; + } + } + if (set & PANGO_FONT_MASK_VARIANT) + { + switch (pango_font_description_get_variant (desc)) + { + case PANGO_VARIANT_NORMAL: + g_string_append (s, "font-variant: normal; "); + break; + case PANGO_VARIANT_SMALL_CAPS: + g_string_append (s, "font-variant: small-caps; "); + break; + } + } + if (set & PANGO_FONT_MASK_WEIGHT) + { + switch (pango_font_description_get_weight (desc)) + { + case PANGO_WEIGHT_THIN: + g_string_append (s, "font-weight: 100; "); + break; + case PANGO_WEIGHT_ULTRALIGHT: + g_string_append (s, "font-weight: 200; "); + break; + case PANGO_WEIGHT_LIGHT: + case PANGO_WEIGHT_SEMILIGHT: + g_string_append (s, "font-weight: 300; "); + break; + case PANGO_WEIGHT_BOOK: + case PANGO_WEIGHT_NORMAL: + g_string_append (s, "font-weight: 400; "); + break; + case PANGO_WEIGHT_MEDIUM: + g_string_append (s, "font-weight: 500; "); + break; + case PANGO_WEIGHT_SEMIBOLD: + g_string_append (s, "font-weight: 600; "); + break; + case PANGO_WEIGHT_BOLD: + g_string_append (s, "font-weight: 700; "); + break; + case PANGO_WEIGHT_ULTRABOLD: + g_string_append (s, "font-weight: 800; "); + break; + case PANGO_WEIGHT_HEAVY: + case PANGO_WEIGHT_ULTRAHEAVY: + g_string_append (s, "font-weight: 900; "); + break; + } + } + if (set & PANGO_FONT_MASK_STRETCH) + { + switch (pango_font_description_get_stretch (desc)) + { + case PANGO_STRETCH_ULTRA_CONDENSED: + g_string_append (s, "font-stretch: ultra-condensed; "); + break; + case PANGO_STRETCH_EXTRA_CONDENSED: + g_string_append (s, "font-stretch: extra-condensed; "); + break; + case PANGO_STRETCH_CONDENSED: + g_string_append (s, "font-stretch: condensed; "); + break; + case PANGO_STRETCH_SEMI_CONDENSED: + g_string_append (s, "font-stretch: semi-condensed; "); + break; + case PANGO_STRETCH_NORMAL: + g_string_append (s, "font-stretch: normal; "); + break; + case PANGO_STRETCH_SEMI_EXPANDED: + g_string_append (s, "font-stretch: semi-expanded; "); + break; + case PANGO_STRETCH_EXPANDED: + g_string_append (s, "font-stretch: expanded; "); + break; + case PANGO_STRETCH_EXTRA_EXPANDED: + g_string_append (s, "font-stretch: extra-expanded; "); + break; + case PANGO_STRETCH_ULTRA_EXPANDED: + g_string_append (s, "font-stretch: ultra-expanded; "); + break; + } + } + if (set & PANGO_FONT_MASK_SIZE) + { + g_string_append_printf (s, "font-size: %dpt; ", + pango_font_description_get_size (desc) / PANGO_SCALE); + } + + g_string_append (s, "}"); + + return g_string_free (s, FALSE); +} + void zenity_util_show_dialog (GtkWidget *dialog) { diff --git a/src/util.h b/src/util.h index c1b2c34..78f3567 100644 --- a/src/util.h +++ b/src/util.h @@ -63,6 +63,7 @@ int zenity_util_return_exit_code (ZenityExitCode value); void zenity_util_exit_code_with_data (ZenityExitCode value, ZenityData *data); void zenity_util_show_dialog (GtkWidget *widget); gboolean zenity_util_timeout_handle (gpointer data); +char *zenity_util_pango_font_description_to_css (PangoFontDescription *desc); void zenity_util_gapp_main (GtkWindow *window); void zenity_util_gapp_quit (GtkWindow *window); diff --git a/src/zenity.ui b/src/zenity.ui index 25e8db9..96017f3 100644 --- a/src/zenity.ui +++ b/src/zenity.ui @@ -1,638 +1,679 @@ + - - - 100 - 1 - 1 - - - 1 - 0 - Adjust the scale value - 300 - 100 - - - 0 - - - 0 - vertical - 6 - - - center - 0 - Adjust the scale value - 0 - - - - - 1 - 1 - adjustment1 - 0 - right - - - - - - - - zenity_scale_cancel_button - zenity_scale_ok_button - - - - True - False - - - Cancel - - - - - OK - - - - - - - - 0 - Text View - 300 - 200 - - - 0 - 2 - - - 1 - 0 - vertical - - - 1 - - - 2 - 2 - 0 - word - 2 - 2 - textbuffer1 - - - - - - - center - 0 - - - - - - - - zenity_text_cancel_button - zenity_text_close_button - - - - True - False - - - Cancel - - - - - OK - 1 - - - - - - - 0 - Calendar selection - - - 0 - 2 - - - 0 - vertical - 6 - - - 1 - 0 - 6 - - - center - 0 - Select a date from below. - 1 - 0 - - - - - - - center - 0 - C_alendar: - 1 - zenity_calendar - 0 - - Calendar - zenity_calendar - - - - - - center - - - - - - - - zenity_calendar_cancel_button - zenity_calendar_ok_button - - - - True - False - - - Cancel - - - - - OK - - - - - - - 0 - Add a new entry - - - 0 - vertical - 2 - - - 0 - - - 1 - 0 - vertical - 6 - - - center - 0 - _Enter new text: - 1 - 0 - - - - - - - - - - - - - zenity_entry_cancel_button - zenity_entry_ok_button - - - - True - False - - - Cancel - - - - - OK - - - - - - - 0 - Error - - - 0 - 14 - - - 0 - - - 1 - 0 - 12 - - - center - 0 - dialog-error - - - - - center - An error has occurred. - 1 - 1 - 0 - - - - - - - - - - zenity_error_ok_button - - - - False - - - OK - - - - - - - 0 - - - 0 - 2 - - - 0 - - - 0 - 12 - 6 - 12 - 6 - 6 - 10 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 - Forms dialog - - - - - - - - - - - zenity_forms_cancel_button - zenity_forms_ok_button - - - - True - False - - - Cancel - 1 - - - - - OK - 1 - - - - - - - 0 - Information - - - 0 - 14 - - - 0 - 12 - - - center - 0 - dialog-information - - - - - center - All updates are complete. - 1 - 1 - 0 - - - - - - - - zenity_info_ok_button - - - - True - False - - - OK - - - - - - - 0 - Progress - - - 0 - 2 - - - center - 0 - vertical - 6 - - - center - 0 - Running... - 1 - 0 - - - - - center - 0 - 0.10000000149 - - - - - center - 0 - 0 - - - - - - - - zenity_progress_cancel_button - zenity_progress_ok_button - - - - True - False - - - Cancel - - - - - OK - 0 - - - - - - - 0 - Question - - - 0 - 14 - - - 0 - 12 - - - 0 - dialog-question - - - - - center - Are you sure you want to proceed? - 1 - 1 - 0 - - - - - - - - - True - False - - - - - 0 - Select items from the list - 300 - 196 - - - 0 - - - 0 - vertical - 6 - - - center - 0 - Select items from the list below. - 0 - - - - - 1 - 1 - - - - - - - - - - - - - - - zenity_tree_cancel_button - zenity_tree_ok_button - - - - False - - - Cancel - - - - - OK - - - - - - - 0 - Warning - - - 0 - 14 - - - 0 - 12 - - - 0 - dialog-warning - - - - - center - Are you sure you want to proceed? - 1 - 1 - 0 - - - - - - - - zenity_warning_ok_button - - - - True - False - - - OK - - - - - + + + 100 + 1 + 1 + + + 1 + 0 + Adjust the scale value + 300 + 100 + + + 0 + + + 0 + vertical + 6 + + + center + 0 + Adjust the scale value + 0 + + + + + true + 1 + adjustment1 + 0 + right + + + + + + + + zenity_scale_cancel_button + zenity_scale_ok_button + + + + True + False + + + true + _Cancel + + + + + true + _OK + + + + + + + + 0 + Text View + 300 + 200 + + + 0 + 2 + + + 1 + 0 + vertical + + + 1 + + + 2 + 2 + 0 + word + 2 + 2 + textbuffer1 + + + + + + + center + 0 + + + + + + + + zenity_text_cancel_button + zenity_text_close_button + + + + True + False + + + true + _Cancel + + + + + true + _OK + + + + + + + 0 + Calendar selection + + + 0 + 2 + + + 0 + vertical + 6 + + + 1 + 0 + 6 + + + center + 0 + Select a date from below. + 1 + 0 + + + + + + + center + 0 + C_alendar: + 1 + zenity_calendar + 0 + + Calendar + zenity_calendar + + + + + + center + + + + + + + + zenity_calendar_cancel_button + zenity_calendar_ok_button + + + + True + False + + + true + _Cancel + + + + + true + _OK + + + + + + + 0 + Add a new entry + + + 0 + vertical + 2 + + + 0 + + + 1 + 0 + vertical + 6 + + + center + 0 + _Enter new text: + 1 + 0 + + + + + + + + + + + + + zenity_entry_cancel_button + zenity_entry_ok_button + + + + True + False + + + true + _Cancel + + + + + true + _OK + + + + + + + 0 + Error + + + 0 + 14 + 12 + 12 + 12 + 12 + + + 0 + + + 1 + 0 + 12 + + + center + 0 + dialog-error + large + + + + + center + An error has occurred. + 1 + 1 + 0 + + + + + + + + + + zenity_error_ok_button + + + + False + + + true + _OK + + + + + + + 0 + + + 0 + 2 + + + 0 + + + 0 + 12 + 6 + 12 + 6 + 6 + 10 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + Forms dialog + + + + + + + + + + + zenity_forms_cancel_button + zenity_forms_ok_button + + + + True + False + + + true + _Cancel + + + + + true + _OK + + + + + + + 0 + Information + + + 0 + 14 + 12 + 12 + 12 + 12 + + + + 0 + 12 + + + center + 0 + dialog-information + large + + + + + center + All updates are complete. + 1 + 1 + 0 + + + + + + + + zenity_info_ok_button + + + + True + False + + + true + _OK + + + + + + + 0 + Progress + + + 0 + 2 + + + center + 0 + vertical + 6 + + + center + 0 + Running... + 1 + 0 + + + + + center + 0 + 0.10000000149 + + + + + center + 0 + 0 + + + + + + + + zenity_progress_cancel_button + zenity_progress_ok_button + + + + True + False + + + true + _Cancel + + + + + true + _OK + 0 + + + + + + + 0 + Question + + + 0 + 14 + 12 + 12 + 12 + 12 + + + 0 + 12 + + + 0 + dialog-question + large + + + + + center + Are you sure you want to proceed? + 1 + 1 + 0 + + + + + + + + + + True + False + + + + + 0 + Select items from the list + 300 + 196 + + + 0 + + + 0 + vertical + 6 + + + center + 0 + Select items from the list below. + 0 + + + + + 1 + 1 + + + + + + + + + + + + + + + zenity_tree_cancel_button + zenity_tree_ok_button + + + + False + + + true + _Cancel + + + + + true + _OK + + + + + + + 0 + Warning + false + + + + 0 + 14 + 12 + 12 + 12 + 12 + + + 0 + 12 + + + 0 + dialog-warning + large + + + + + center + true + true + Are you sure you want to proceed? + 1 + 1 + + + + + + + + zenity_warning_ok_button + + + + True + False + + + true + _OK + + + + + -- cgit v1.2.1