Author: nick
Date: 2008-11-21 11:55:01 +0000 (Fri, 21 Nov 2008)
New Revision: 28874
Modified:
libxfcegui4/trunk/libxfcegui4/dialogs.c
Log:
* Move xfce_message_dialog_new_valist from libxfce4ui
to libxfcegui4. This should fix problems with 'wrong'
markup in the secondary text (caused by using
error->message).
* Replace tabs with spaces.
Modified: libxfcegui4/trunk/libxfcegui4/dialogs.c
===================================================================
--- libxfcegui4/trunk/libxfcegui4/dialogs.c 2008-11-21 11:41:55 UTC (rev
28873)
+++ libxfcegui4/trunk/libxfcegui4/dialogs.c 2008-11-21 11:55:01 UTC (rev
28874)
@@ -44,6 +44,10 @@
#include <glib.h>
#include <gtk/gtk.h>
+#ifdef GDK_WINDOWING_X11
+#include <gdk/gdkx.h>
+#endif
+
#include "dialogs.h"
#include "xfce-gtk-extensions.h"
@@ -80,12 +84,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;
}
@@ -96,12 +100,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;
}
@@ -140,17 +144,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);
@@ -159,12 +163,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;
}
@@ -192,7 +196,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);
}
@@ -216,24 +220,29 @@
GtkWidget*
xfce_create_mixed_button (const gchar *stock, const gchar *text)
{
- GtkWidget *button, *align, *image, *hbox, *label;
+ GtkWidget *button;
+ GtkWidget *image;
- 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 (stock != NULL || text != NULL, NULL);
- image = gtk_image_new_from_stock (stock, GTK_ICON_SIZE_BUTTON);
- hbox = gtk_hbox_new (FALSE, 2);
+ if (text != NULL)
+ {
+ /* create button */
+ button = gtk_button_new_with_mnemonic (text);
- align = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
+ 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);
+ }
- 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;
}
@@ -274,8 +283,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));
@@ -475,186 +484,238 @@
return FALSE;
}
-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)
+static GdkScreen *
+xfce_gdk_screen_get_active (gint *monitor_return)
{
- GtkWidget *dialog, *label;
- GtkWidget *hbox, *align;
- GtkWidget *image;
- gchar *markup = NULL;
- gint default_response = G_MININT;
+#ifdef GDK_WINDOWING_X11
+ GdkScreen *screen;
+ Window child;
+ Window root;
+ GSList *displays;
+ GSList *lp;
+ guint xmask;
+ gint rootx, rooty;
+ gint winx, winy;
+ gint n;
- /* 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)
+ /* determine the list of active displays */
+ displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
+ for (lp = displays; lp != NULL; lp = lp->next)
{
- 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);
+ /* 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;
+ }
+ }
}
- /* add the text */
- markup = NULL;
+ /* fallback to the default screen */
+ screen = gdk_screen_get_default ();
+
+ /* no monitor was found */
+ if (monitor_return)
+ *monitor_return = 0;
- if (primary_text && secondary_text)
- {
- markup = g_strdup_printf ("<span weight='bold' size='large'>%s</span>"
- "\n\n%s", primary_text, secondary_text);
- }
- else if (primary_text)
- {
- markup =
- g_strdup_printf ("<span weight='bold' size='large'>%s</span>",
- primary_text);
- }
- else
- {
- markup = g_strdup (secondary_text);
- }
+out:
+ /* release the displays */
+ g_slist_free (displays);
- label = gtk_label_new (NULL);
+ return screen;
+#else
+ /* dunno what to do on non-X11 window systems */
+ return gdk_screen_get_default ();
+#endif
+}
- 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);
+static GdkScreen *
+xfce_gtk_dialog_parse_parent (gpointer parent,
+ GtkWindow **window_return)
+{
+ GdkScreen *screen = NULL;
+ GtkWidget *window = NULL;
- gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
+ g_return_val_if_fail (parent == NULL || GDK_IS_SCREEN (parent) ||
GTK_IS_WIDGET (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)
+ /* determine the proper parent if one was set */
+ if (parent != NULL)
{
- const gchar *text;
- gint response_id;
+ 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;
+ }
- text = first_button_type;
+ /* determine the screen for the widget */
+ screen = gtk_widget_get_screen (GTK_WIDGET (parent));
+ }
+ }
- while (text != NULL)
- {
- GtkWidget *button;
+ /* use the active screen */
+ if (screen == NULL)
+ screen = xfce_gdk_screen_get_active (NULL);
- if (strcmp (text, XFCE_CUSTOM_PIXBUF_BUTTON) == 0)
- {
- GdkPixbuf *icon, *scaled;
- GtkWidget *align, *image, *hbox, *label;
- gint w, h;
+ /* return the window */
+ if (G_LIKELY (window_return != NULL))
+ *window_return = GTK_WINDOW (window);
- text = va_arg (args, gchar *);
- icon = va_arg (args, GdkPixbuf *);
- default_response = response_id = va_arg (args, int);
+ return screen;
+}
- button = gtk_button_new ();
- label = gtk_label_new_with_mnemonic (text);
- gtk_label_set_mnemonic_widget (GTK_LABEL (label), button);
+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;
- gtk_icon_size_lookup (GTK_ICON_SIZE_BUTTON, &w, &h);
+ g_return_val_if_fail (primary_text != NULL || secondary_text != NULL,
NULL);
- if ((gdk_pixbuf_get_width (icon) != w) &&
- (gdk_pixbuf_get_height (icon) != h))
- {
- scaled = gdk_pixbuf_scale_simple (icon, w, h,
- GDK_INTERP_BILINEAR);
+ /* parse the parent pointer */
+ screen = xfce_gtk_dialog_parse_parent (parent, &window);
- g_object_unref (G_OBJECT (icon));
- icon = scaled;
- }
+ /* 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);
+ }
- image = gtk_image_new_from_pixbuf (icon);
+ /* 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);
+ }
- hbox = gtk_hbox_new (FALSE, 2);
- align = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
+ /* set title */
+ if (title != NULL)
+ gtk_window_set_title (GTK_WINDOW (dialog), title);
- gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
- gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 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_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 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);
- text = va_arg (args, gchar *);
- icon_stock = va_arg (args, gchar *);
- default_response = response_id = va_arg (args, int);
+ /* 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);
- 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);
+ /* lookup real icons size for button icons */
+ gtk_icon_size_lookup (GTK_ICON_SIZE_BUTTON, &w, &h);
- button = gtk_button_new_with_label (text);
- }
+ /* 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);
else
- {
- default_response = response_id = va_arg (args, int);
+ scaled = NULL;
- button = gtk_button_new_from_stock (text);
- }
+ /* create image */
+ image = gtk_image_new_from_pixbuf (scaled ? scaled : pixbuf);
- GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
+ /* 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_show (button);
- gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button,
- response_id);
+ }
+ else /* stock button */
+ {
+ /* get arguments */
+ stock_id = text;
+ response = va_arg (args, gint);
- text = va_arg (args, gchar *);
+ /* add a stock button to the dialog */
+ gtk_dialog_add_button (GTK_DIALOG (dialog), stock_id, response);
}
+
+ /* 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;
}
@@ -794,21 +855,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;
}
@@ -818,29 +879,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