Author: nick
Date: 2008-11-22 10:49:25 +0000 (Sat, 22 Nov 2008)
New Revision: 28882
Modified:
libxfcegui4/trunk/libxfcegui4/dialogs.c
Log:
* Revert previous commit and use g_markup_escape_text().
Modified: libxfcegui4/trunk/libxfcegui4/dialogs.c
===================================================================
--- libxfcegui4/trunk/libxfcegui4/dialogs.c 2008-11-21 23:57:42 UTC (rev
28881)
+++ libxfcegui4/trunk/libxfcegui4/dialogs.c 2008-11-22 10:49:25 UTC (rev
28882)
@@ -44,10 +44,6 @@
#include <glib.h>
#include <gtk/gtk.h>
-#ifdef GDK_WINDOWING_X11
-#include <gdk/gdkx.h>
-#endif
-
#include "dialogs.h"
#include "xfce-gtk-extensions.h"
@@ -84,12 +80,12 @@
GtkStyle *style;
if (recursive > 0)
- return;
+ return;
++recursive;
style = gtk_widget_get_style (widget);
gtk_widget_modify_bg (widget, GTK_STATE_NORMAL,
- &style->bg[GTK_STATE_SELECTED]);
+ &style->bg[GTK_STATE_SELECTED]);
--recursive;
}
@@ -100,12 +96,12 @@
GtkStyle *style;
if (recursive > 0)
- return;
+ return;
++recursive;
style = gtk_widget_get_style (widget);
gtk_widget_modify_fg (widget, GTK_STATE_NORMAL,
- &style->fg[GTK_STATE_SELECTED]);
+ &style->fg[GTK_STATE_SELECTED]);
--recursive;
}
@@ -144,17 +140,17 @@
if (image)
{
- gtk_widget_show (image);
- gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
+ gtk_widget_show (image);
+ gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
}
style = gtk_widget_get_style (eventbox);
gtk_widget_modify_bg (eventbox, GTK_STATE_NORMAL,
- &style->bg[GTK_STATE_SELECTED]);
+ &style->bg[GTK_STATE_SELECTED]);
markup =
- g_strconcat ("<span size=\"larger\" weight=\"bold\">", text,
- "</span>", NULL);
+ g_strconcat ("<span size=\"larger\" weight=\"bold\">", text,
+ "</span>", NULL);
label = gtk_label_new (markup);
g_free (markup);
gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
@@ -163,12 +159,12 @@
style = gtk_widget_get_style (label);
gtk_widget_modify_fg (label, GTK_STATE_NORMAL,
- &style->fg[GTK_STATE_SELECTED]);
+ &style->fg[GTK_STATE_SELECTED]);
g_signal_connect_after (G_OBJECT (eventbox), "style_set",
- G_CALLBACK (private_cb_eventbox_style_set), NULL);
+ G_CALLBACK (private_cb_eventbox_style_set), NULL);
g_signal_connect_after (G_OBJECT (label), "style_set",
- G_CALLBACK (private_cb_label_style_set), NULL);
+ G_CALLBACK (private_cb_label_style_set), NULL);
return eventbox;
}
@@ -196,7 +192,7 @@
GtkWidget *image = NULL;
if (icon)
- image = gtk_image_new_from_pixbuf (icon);
+ image = gtk_image_new_from_pixbuf (icon);
return xfce_create_header_with_image (image, text);
}
@@ -220,29 +216,24 @@
GtkWidget*
xfce_create_mixed_button (const gchar *stock, const gchar *text)
{
- GtkWidget *button;
- GtkWidget *image;
+ GtkWidget *button, *align, *image, *hbox, *label;
- g_return_val_if_fail (stock != NULL || text != NULL, NULL);
+ button = gtk_button_new ();
+ label = gtk_label_new_with_mnemonic (text);
+ gtk_label_set_mnemonic_widget (GTK_LABEL (label), button);
- if (text != NULL)
- {
- /* create button */
- button = gtk_button_new_with_mnemonic (text);
+ image = gtk_image_new_from_stock (stock, GTK_ICON_SIZE_BUTTON);
+ hbox = gtk_hbox_new (FALSE, 2);
- if (stock != NULL)
- {
- /* create image widget */
- image = gtk_image_new_from_stock (stock, GTK_ICON_SIZE_BUTTON);
- gtk_button_set_image (GTK_BUTTON (button), image);
- }
- }
- else
- {
- /* fall back to a stock button */
- button = gtk_button_new_from_stock (stock);
- }
+ align = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
+ gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
+ gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+
+ gtk_container_add (GTK_CONTAINER (button), align);
+ gtk_container_add (GTK_CONTAINER (align), hbox);
+ gtk_widget_show_all (align);
+
return button;
}
@@ -283,8 +274,8 @@
GtkWidget *dlg;
dlg = gtk_message_dialog_new (NULL,
- GTK_DIALOG_MODAL,
- type, GTK_BUTTONS_CLOSE, "%s", message);
+ GTK_DIALOG_MODAL,
+ type, GTK_BUTTONS_CLOSE, "%s", message);
xfce_gtk_window_center_on_monitor_with_pointer (GTK_WINDOW (dlg));
gtk_dialog_run (GTK_DIALOG (dlg));
@@ -484,238 +475,193 @@
return FALSE;
}
-static GdkScreen *
-xfce_gdk_screen_get_active (gint *monitor_return)
+static GtkWidget *
+xfce_message_dialog_new_valist(GtkWindow *parent,
+ const gchar *title,
+ const gchar *icon_id,
+ const gchar *primary_text,
+ const gchar *secondary_text,
+ const gchar *first_button_type,
+ va_list args)
{
-#ifdef GDK_WINDOWING_X11
- GdkScreen *screen;
- Window child;
- Window root;
- GSList *displays;
- GSList *lp;
- guint xmask;
- gint rootx, rooty;
- gint winx, winy;
- gint n;
+ GtkWidget *dialog, *label;
+ GtkWidget *hbox, *align;
+ GtkWidget *image;
+ gchar *markup = NULL;
+ gint default_response = G_MININT;
+ gchar *primary_escaped, *secondary_escaped;
- /* determine the list of active displays */
- displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
- for (lp = displays; lp != NULL; lp = lp->next)
+ /* create the dialog */
+ dialog = gtk_dialog_new ();
+
+ gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+ gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
+ gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
+
+ /* set title if needed */
+ if (title)
+ gtk_window_set_title (GTK_WINDOW (dialog), title);
+ else
+ gtk_window_set_title (GTK_WINDOW (dialog), "");
+
+ /* add image */
+ hbox = gtk_hbox_new (FALSE, 12);
+
+ if (icon_id)
{
- /* check all screens on this display */
- for (n = 0; n < gdk_display_get_n_screens (lp->data); ++n)
- {
- /* check if this screen contains the pointer */
- screen = gdk_display_get_screen (lp->data, n);
- if (XQueryPointer (GDK_SCREEN_XDISPLAY (screen),
- GDK_DRAWABLE_XID (gdk_screen_get_root_window
(screen)),
- &root, &child, &rootx, &rooty, &winx, &winy,
&xmask))
- {
- /* return the monitor number */
- if (monitor_return)
- *monitor_return = gdk_screen_get_monitor_at_point (screen,
rootx, rooty);
-
- /* yap, this screen contains the pointer, hence it's the
active screen */
- goto out;
- }
- }
+ image = gtk_image_new_from_stock (icon_id, GTK_ICON_SIZE_DIALOG);
+ gtk_misc_set_alignment (GTK_MISC (image), 0, 0);
+
+ gtk_box_pack_start (GTK_BOX (hbox), image, TRUE, FALSE, 0);
}
- /* fallback to the default screen */
- screen = gdk_screen_get_default ();
-
- /* no monitor was found */
- if (monitor_return)
- *monitor_return = 0;
+ /* add the text */
+ markup = NULL;
-out:
- /* release the displays */
- g_slist_free (displays);
+ if (primary_text && secondary_text)
+ {
+ primary_escaped = g_markup_escape_text (primary_text, -1);
+ secondary_escaped = g_markup_escape_text (secondary_text, -1);
+ markup = g_strdup_printf ("<span weight='bold' size='large'>%s</span>"
+ "\n\n%s", primary_escaped,
secondary_escaped);
+ g_free (primary_escaped);
+ g_free (secondary_escaped);
+ }
+ else if (primary_text)
+ {
+ primary_escaped = g_markup_escape_text (primary_text, -1);
+ markup =
+ g_strdup_printf ("<span weight='bold' size='large'>%s</span>",
+ primary_escaped);
+ g_free (primary_escaped);
+ }
+ else
+ {
+ markup = g_markup_escape_text (secondary_text, -1);
+ }
- return screen;
-#else
- /* dunno what to do on non-X11 window systems */
- return gdk_screen_get_default ();
-#endif
-}
+ label = gtk_label_new (NULL);
-static GdkScreen *
-xfce_gtk_dialog_parse_parent (gpointer parent,
- GtkWindow **window_return)
-{
- GdkScreen *screen = NULL;
- GtkWidget *window = NULL;
+ gtk_label_set_markup (GTK_LABEL (label), markup);
+ gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+ gtk_label_set_selectable (GTK_LABEL (label), TRUE);
- g_return_val_if_fail (parent == NULL || GDK_IS_SCREEN (parent) ||
GTK_IS_WIDGET (parent), NULL);
+ gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
- /* determine the proper parent if one was set */
- if (parent != NULL)
+ g_free (markup);
+
+ gtk_widget_show_all (hbox);
+ gtk_box_pack_start (GTK_BOX ((GTK_DIALOG (dialog))->vbox), hbox,
+ FALSE, FALSE, 0);
+
+ align = gtk_alignment_new (0, 0, 0, 0);
+ gtk_widget_set_size_request (align, 12, 12);
+ gtk_widget_show (align);
+ gtk_box_pack_start (GTK_BOX ((GTK_DIALOG (dialog))->vbox), align,
+ FALSE, FALSE, 0);
+
+ /* sizing according to GNOME HIG,
+ * except with a border of 8 instead of 12 */
+ gtk_container_set_border_width (GTK_CONTAINER (dialog), 2);
+ gtk_container_set_border_width (GTK_CONTAINER (hbox), 6);
+
+ /* add the buttons */
+ if (first_button_type)
{
- if (GDK_IS_SCREEN (parent))
- {
- /* yep, that's a screen */
- screen = GDK_SCREEN (parent);
- }
- else if (GTK_IS_WIDGET (parent))
- {
- /* parent is a widget, so let's determine the toplevel window */
- window = gtk_widget_get_toplevel (GTK_WIDGET (parent));
- if (GTK_WIDGET_TOPLEVEL (window))
- {
- /* make sure the toplevel window is shown */
- gtk_widget_show_now (window);
- }
- else
- {
- /* no toplevel, not usable then */
- window = NULL;
- }
+ const gchar *text;
+ gint response_id;
- /* determine the screen for the widget */
- screen = gtk_widget_get_screen (GTK_WIDGET (parent));
- }
- }
+ text = first_button_type;
- /* use the active screen */
- if (screen == NULL)
- screen = xfce_gdk_screen_get_active (NULL);
+ while (text != NULL)
+ {
+ GtkWidget *button;
- /* return the window */
- if (G_LIKELY (window_return != NULL))
- *window_return = GTK_WINDOW (window);
+ if (strcmp (text, XFCE_CUSTOM_PIXBUF_BUTTON) == 0)
+ {
+ GdkPixbuf *icon, *scaled;
+ GtkWidget *align, *image, *hbox, *label;
+ gint w, h;
- return screen;
-}
+ text = va_arg (args, gchar *);
+ icon = va_arg (args, GdkPixbuf *);
+ default_response = response_id = va_arg (args, int);
-static GtkWidget *
-xfce_message_dialog_new_valist(GtkWindow *parent,
- const gchar *title,
- const gchar *icon_stock_id,
- const gchar *primary_text,
- const gchar *secondary_text,
- const gchar *first_button_type,
- va_list args)
-{
- GtkWidget *dialog;
- GtkWindow *window;
- GdkScreen *screen;
- gchar *markup;
- GtkWidget *image;
- GtkWidget *button;
- const gchar *text = first_button_type;
- const gchar *label;
- const gchar *stock_id;
- gint response;
- GdkPixbuf *pixbuf, *scaled;
- gint w, h;
+ button = gtk_button_new ();
+ label = gtk_label_new_with_mnemonic (text);
+ gtk_label_set_mnemonic_widget (GTK_LABEL (label), button);
- g_return_val_if_fail (primary_text != NULL || secondary_text != NULL,
NULL);
+ gtk_icon_size_lookup (GTK_ICON_SIZE_BUTTON, &w, &h);
- /* parse the parent pointer */
- screen = xfce_gtk_dialog_parse_parent (parent, &window);
+ if ((gdk_pixbuf_get_width (icon) != w) &&
+ (gdk_pixbuf_get_height (icon) != h))
+ {
+ scaled = gdk_pixbuf_scale_simple (icon, w, h,
+ GDK_INTERP_BILINEAR);
- /* create the dialog */
- if (G_LIKELY (primary_text != NULL))
- {
- /* create dialog with large bold text */
- markup = g_strdup_printf ("<span weight='bold'
size='large'>%s</span>", primary_text);
- dialog = gtk_message_dialog_new_with_markup (window,
-
GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
- GTK_MESSAGE_OTHER,
GTK_BUTTONS_NONE,
- markup);
- g_free (markup);
-
- /* set secondary text */
- if (secondary_text != NULL)
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG
(dialog), secondary_text);
- }
- else
- {
- /* create dialog with normal seconday text */
- dialog = gtk_message_dialog_new (window,
- GTK_DIALOG_DESTROY_WITH_PARENT |
GTK_DIALOG_MODAL,
- GTK_MESSAGE_OTHER, GTK_BUTTONS_NONE,
- secondary_text);
- }
+ g_object_unref (G_OBJECT (icon));
+ icon = scaled;
+ }
- /* move the dialog to the appropriate screen and center it */
- if (G_UNLIKELY (window == NULL && screen != NULL))
- {
- gtk_window_set_screen (GTK_WINDOW (dialog), screen);
- gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
- }
+ image = gtk_image_new_from_pixbuf (icon);
- /* set title */
- if (title != NULL)
- gtk_window_set_title (GTK_WINDOW (dialog), title);
+ hbox = gtk_hbox_new (FALSE, 2);
+ align = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
- if (icon_stock_id != NULL)
- {
- /* set dialog and window icon */
- image = gtk_image_new_from_stock (icon_stock_id, GTK_ICON_SIZE_DIALOG);
- gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image);
- gtk_widget_show (image);
- gtk_window_set_icon_name (GTK_WINDOW (dialog), icon_stock_id);
- }
+ gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
+ gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
- /* add buttons */
- while (text != NULL)
- {
- if (strcmp (text, XFCE_CUSTOM_BUTTON) == 0)
- {
- /* get arguments */
- stock_id = va_arg (args, const gchar *);
- label = va_arg (args, const gchar *);
- response = va_arg (args, gint);
+ gtk_container_add (GTK_CONTAINER (button), align);
+ gtk_container_add (GTK_CONTAINER (align), hbox);
+ gtk_widget_show_all (align);
+ }
+ else if (strcmp (text, XFCE_CUSTOM_STOCK_BUTTON) == 0)
+ {
+ gchar *icon_stock;
- /* add a mixed button to the dialog */
- button = xfce_create_mixed_button (stock_id, label);
- gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button,
response);
- gtk_widget_show (button);
- }
- else if (strcmp (text, XFCE_CUSTOM_PIXBUF_BUTTON) == 0)
- {
- /* get arguments */
- pixbuf = va_arg (args, GdkPixbuf *);
- label = va_arg (args, const gchar *);
- response = va_arg (args, gint);
+ text = va_arg (args, gchar *);
+ icon_stock = va_arg (args, gchar *);
+ default_response = response_id = va_arg (args, int);
- /* lookup real icons size for button icons */
- gtk_icon_size_lookup (GTK_ICON_SIZE_BUTTON, &w, &h);
+ button = xfce_create_mixed_button (icon_stock, text);
+ }
+ else if (strcmp (text, XFCE_CUSTOM_BUTTON) == 0)
+ {
+ text = va_arg (args, gchar *);
+ default_response = response_id = va_arg (args, int);
- /* scale the pixbuf if needed */
- if (gdk_pixbuf_get_width (pixbuf) != w || gdk_pixbuf_get_height
(pixbuf) != h)
- scaled = gdk_pixbuf_scale_simple (pixbuf, w, h,
GDK_INTERP_BILINEAR);
+ button = gtk_button_new_with_label (text);
+ }
else
- scaled = NULL;
+ {
+ default_response = response_id = va_arg (args, int);
- /* create image */
- image = gtk_image_new_from_pixbuf (scaled ? scaled : pixbuf);
+ button = gtk_button_new_from_stock (text);
+ }
- /* release scaled image */
- if (scaled != NULL)
- g_object_unref (G_OBJECT (scaled));
-
- /* create button and add it to the dialog */
- button = gtk_button_new_with_label (label);
- gtk_button_set_image (GTK_BUTTON (button), image);
- gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button,
response);
+ GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_widget_show (button);
- }
- else /* stock button */
- {
- /* get arguments */
- stock_id = text;
- response = va_arg (args, gint);
+ gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button,
+ response_id);
- /* add a stock button to the dialog */
- gtk_dialog_add_button (GTK_DIALOG (dialog), stock_id, response);
+ text = va_arg (args, gchar *);
}
-
- /* get the next argument */
- text = va_arg (args, const gchar *);
}
+
+ if (default_response != G_MININT)
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog),
default_response);
+ if (parent)
+ {
+ gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
+ gtk_window_set_position (GTK_WINDOW (dialog),
+ GTK_WIN_POS_CENTER_ON_PARENT);
+ }
+ else
+ {
+ xfce_gtk_window_center_on_monitor_with_pointer (GTK_WINDOW (dialog));
+ }
+
return dialog;
}
@@ -855,21 +801,21 @@
exec_command (gchar * command)
{
gboolean success = TRUE;
- GError *error = NULL; /* this must be NULL to prevent crash :( */
+ GError *error = NULL; /* this must be NULL to prevent crash :( */
g_return_val_if_fail (command != NULL, FALSE);
if (!g_spawn_command_line_async (command, &error))
{
- char *msg = g_strcompress (error->message);
- char *text =
- g_strconcat ("Could not run command: ", command, ":\n", msg,
- NULL);
- show_error (text);
- g_free (msg);
- g_free (text);
- g_error_free (error);
- success = FALSE;
+ char *msg = g_strcompress (error->message);
+ char *text =
+ g_strconcat ("Could not run command: ", command, ":\n", msg,
+ NULL);
+ show_error (text);
+ g_free (msg);
+ g_free (text);
+ g_error_free (error);
+ success = FALSE;
}
return success;
}
@@ -879,29 +825,29 @@
{
gboolean success = TRUE;
gboolean retval;
- GError *error = NULL; /* this must be NULL to prevent crash :( */
+ GError *error = NULL; /* this must be NULL to prevent crash :( */
g_return_val_if_fail (argv != NULL, FALSE);
if (envp == NULL)
{
- envp = environ;
+ envp = environ;
}
retval =
- g_spawn_async (NULL, argv, envp, G_SPAWN_SEARCH_PATH, NULL, NULL,
- NULL, &error);
+ g_spawn_async (NULL, argv, envp, G_SPAWN_SEARCH_PATH, NULL, NULL,
+ NULL, &error);
if (!retval)
{
- gchar *msg = g_strcompress (error->message);
- char *text =
- g_strconcat ("Could not run command: ", argv[0], ":\n", msg,
- NULL);
- g_error_free (error);
- g_free (msg);
- show_error (text);
- g_free (text);
- success = FALSE;
+ gchar *msg = g_strcompress (error->message);
+ char *text =
+ g_strconcat ("Could not run command: ", argv[0], ":\n", msg,
+ NULL);
+ g_error_free (error);
+ g_free (msg);
+ show_error (text);
+ g_free (text);
+ success = FALSE;
}
return success;
_______________________________________________
Xfce4-commits mailing list
[email protected]
http://foo-projects.org/mailman/listinfo/xfce4-commits