[gtk+] Bug 586691 – Better GtkInfoBar defaults
- From: David Zeuthen <davidz src gnome org>
- To: svn-commits-list gnome org
- Subject: [gtk+] Bug 586691 – Better GtkInfoBar defaults
- Date: Thu, 25 Jun 2009 19:29:47 +0000 (UTC)
commit a92c9ce9a5874665cf35fe7ac11ce315563cb92a
Author: David Zeuthen <davidz redhat com>
Date: Mon Jun 22 17:22:23 2009 -0400
Bug 586691 â?? Better GtkInfoBar defaults
Signed-off-by: David Zeuthen <davidz redhat com>
demos/gtk-demo/Makefile.am | 3 +-
demos/gtk-demo/infobar.c | 104 ++++++++++++++++++++++++++++++++++
gtk/gtkinfobar.c | 133 +++++++++++++++++++++-----------------------
3 files changed, 169 insertions(+), 71 deletions(-)
---
diff --git a/demos/gtk-demo/Makefile.am b/demos/gtk-demo/Makefile.am
index aced886..23eed00 100644
--- a/demos/gtk-demo/Makefile.am
+++ b/demos/gtk-demo/Makefile.am
@@ -23,7 +23,8 @@ demos = \
iconview.c \
iconview_edit.c \
images.c \
- links.c \
+ infobar.c \
+ links.c \
list_store.c \
menus.c \
panes.c \
diff --git a/demos/gtk-demo/infobar.c b/demos/gtk-demo/infobar.c
new file mode 100644
index 0000000..7743c5f
--- /dev/null
+++ b/demos/gtk-demo/infobar.c
@@ -0,0 +1,104 @@
+/* Info bar
+ *
+ * Info bar widgets are used to report important messages to the user.
+ */
+
+#include <gtk/gtk.h>
+
+static GtkWidget *window = NULL;
+
+static void
+on_bar_response (GtkInfoBar *info_bar,
+ gint response_id,
+ gpointer user_data)
+{
+ GtkWidget *dialog;
+
+ dialog = gtk_message_dialog_new (GTK_WINDOW (window),
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_INFO,
+ GTK_BUTTONS_OK,
+ "You clicked a button on an info bar");
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ "Your response has id %d", response_id);
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+}
+
+GtkWidget *
+do_infobar (GtkWidget *do_widget)
+{
+ GtkWidget *frame;
+ GtkWidget *bar;
+ GtkWidget *vbox;
+ GtkWidget *vbox2;
+ GtkWidget *label;
+
+ if (!window)
+ {
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_screen (GTK_WINDOW (window),
+ gtk_widget_get_screen (do_widget));
+ gtk_window_set_title (GTK_WINDOW (window), "Info Bars");
+
+ g_signal_connect (window, "destroy", G_CALLBACK (gtk_widget_destroyed), &window);
+ gtk_container_set_border_width (GTK_CONTAINER (window), 8);
+
+ vbox = gtk_vbox_new (FALSE, 0);
+ gtk_container_add (GTK_CONTAINER (window), vbox);
+
+ bar = gtk_info_bar_new ();
+ gtk_box_pack_start (GTK_BOX (vbox), bar, FALSE, FALSE, 0);
+ gtk_info_bar_set_message_type (GTK_INFO_BAR (bar), GTK_MESSAGE_INFO);
+ label = gtk_label_new ("This is an info bar with message type GTK_MESSAGE_INFO");
+ gtk_box_pack_start (GTK_BOX (gtk_info_bar_get_content_area (GTK_INFO_BAR (bar))), label, FALSE, FALSE, 0);
+
+ bar = gtk_info_bar_new ();
+ gtk_box_pack_start (GTK_BOX (vbox), bar, FALSE, FALSE, 0);
+ gtk_info_bar_set_message_type (GTK_INFO_BAR (bar), GTK_MESSAGE_WARNING);
+ label = gtk_label_new ("This is an info bar with message type GTK_MESSAGE_WARNING");
+ gtk_box_pack_start (GTK_BOX (gtk_info_bar_get_content_area (GTK_INFO_BAR (bar))), label, FALSE, FALSE, 0);
+
+ bar = gtk_info_bar_new_with_buttons (GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
+ g_signal_connect (bar, "response", G_CALLBACK (on_bar_response), window);
+ gtk_box_pack_start (GTK_BOX (vbox), bar, FALSE, FALSE, 0);
+ gtk_info_bar_set_message_type (GTK_INFO_BAR (bar), GTK_MESSAGE_QUESTION);
+ label = gtk_label_new ("This is an info bar with message type GTK_MESSAGE_QUESTION");
+ gtk_box_pack_start (GTK_BOX (gtk_info_bar_get_content_area (GTK_INFO_BAR (bar))), label, FALSE, FALSE, 0);
+
+ bar = gtk_info_bar_new ();
+ gtk_box_pack_start (GTK_BOX (vbox), bar, FALSE, FALSE, 0);
+ gtk_info_bar_set_message_type (GTK_INFO_BAR (bar), GTK_MESSAGE_ERROR);
+ label = gtk_label_new ("This is an info bar with message type GTK_MESSAGE_ERROR");
+ gtk_box_pack_start (GTK_BOX (gtk_info_bar_get_content_area (GTK_INFO_BAR (bar))), label, FALSE, FALSE, 0);
+
+ bar = gtk_info_bar_new ();
+ gtk_box_pack_start (GTK_BOX (vbox), bar, FALSE, FALSE, 0);
+ gtk_info_bar_set_message_type (GTK_INFO_BAR (bar), GTK_MESSAGE_OTHER);
+ label = gtk_label_new ("This is an info bar with message type GTK_MESSAGE_OTHER");
+ gtk_box_pack_start (GTK_BOX (gtk_info_bar_get_content_area (GTK_INFO_BAR (bar))), label, FALSE, FALSE, 0);
+
+ frame = gtk_frame_new ("Info bars");
+ gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 8);
+
+ vbox2 = gtk_vbox_new (FALSE, 8);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
+ gtk_container_add (GTK_CONTAINER (frame), vbox2);
+
+ /* Standard message dialog */
+ label = gtk_label_new ("An example of different info bars");
+ gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, FALSE, 0);
+ }
+
+ if (!GTK_WIDGET_VISIBLE (window))
+ {
+ gtk_widget_show_all (window);
+ }
+ else
+ {
+ gtk_widget_destroy (window);
+ window = NULL;
+ }
+
+ return window;
+}
diff --git a/gtk/gtkinfobar.c b/gtk/gtkinfobar.c
index c96bd84..568bd79 100644
--- a/gtk/gtkinfobar.c
+++ b/gtk/gtkinfobar.c
@@ -307,7 +307,6 @@ gtk_info_bar_expose (GtkWidget *widget,
GdkEventExpose *event)
{
GtkInfoBarPrivate *priv = GTK_INFO_BAR_GET_PRIVATE (widget);
- gboolean use_tooltip_style;
const char* type_detail[] = {
"infobar-info",
"infobar-warning",
@@ -315,28 +314,25 @@ gtk_info_bar_expose (GtkWidget *widget,
"infobar-error",
"infobar"
};
- const char *detail;
- gtk_widget_style_get (widget,
- "use-tooltip-style", &use_tooltip_style,
- NULL);
-
- if (use_tooltip_style)
- detail = "toolbar";
- else
- detail = type_detail[priv->message_type];
-
- gtk_paint_flat_box (widget->style,
- widget->window,
- GTK_STATE_NORMAL,
- GTK_SHADOW_OUT,
- NULL,
- widget,
- detail,
- widget->allocation.x,
- widget->allocation.y,
- widget->allocation.width + 1,
- widget->allocation.height + 1);
+ if (priv->message_type != GTK_MESSAGE_OTHER)
+ {
+ const char *detail;
+
+ detail = type_detail[priv->message_type];
+
+ gtk_paint_box (widget->style,
+ widget->window,
+ GTK_STATE_NORMAL,
+ GTK_SHADOW_OUT,
+ NULL,
+ widget,
+ detail,
+ widget->allocation.x,
+ widget->allocation.y,
+ widget->allocation.width + 1,
+ widget->allocation.height + 1);
+ }
if (GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->expose_event)
GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->expose_event (widget, event);
@@ -374,9 +370,12 @@ gtk_info_bar_class_init (GtkInfoBarClass *klass)
* "info_fg_color", "info_bg_color",
* "warning_fg_color", "warning_bg_color",
* "question_fg_color", "question_bg_color",
- * "error_fg_color", "error_bg_color",
+ * "error_fg_color", "error_bg_color".
* "other_fg_color", "other_bg_color".
*
+ * If the type is #GTK_MESSAGE_OTHER, no info bar is painted but the
+ * colors are still set.
+ *
* Since: 2.18
*/
g_object_class_install_property (object_class,
@@ -385,7 +384,7 @@ gtk_info_bar_class_init (GtkInfoBarClass *klass)
P_("Message Type"),
P_("The type of message"),
GTK_TYPE_MESSAGE_TYPE,
- GTK_MESSAGE_OTHER,
+ GTK_MESSAGE_INFO,
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
/**
* GtkInfoBar::response:
@@ -493,22 +492,6 @@ gtk_info_bar_class_init (GtkInfoBarClass *klass)
5,
GTK_PARAM_READABLE));
- /**
- * GtkInfoBar:use-tooltip-style:
- *
- * When %TRUE, use the same background/foreground color as #GtkTooltip.
- * Otherwise, GTK+ uses #GtkInfoBar::message-type to determine which
- * symbolic colors to use.
- *
- * Since: 2.18
- */
- gtk_widget_class_install_style_property (widget_class,
- g_param_spec_boolean ("use-tooltip-style",
- P_("Use tooltip style"),
- P_("Wether to use the same style as GtkTooltip for drawing"),
- TRUE,
- GTK_PARAM_READABLE));
-
binding_set = gtk_binding_set_by_class (klass);
gtk_binding_entry_add_signal (binding_set, GDK_Escape, 0, "close", 0);
@@ -521,11 +504,18 @@ gtk_info_bar_update_colors (GtkInfoBar *info_bar)
{
GtkWidget *widget = (GtkWidget*)info_bar;
GtkInfoBarPrivate *priv;
- GdkColor default_border_color = { 0, 0xb800, 0xad00, 0x9d00 };
- GdkColor default_fill_color = { 0, 0xff00, 0xff00, 0xbf00 };
+ GdkColor info_default_border_color = { 0, 0xb800, 0xad00, 0x9d00 };
+ GdkColor info_default_fill_color = { 0, 0xff00, 0xff00, 0xbf00 };
+ GdkColor warning_default_border_color = { 0, 0xb000, 0x7a00, 0x2b00 };
+ GdkColor warning_default_fill_color = { 0, 0xfc00, 0xaf00, 0x3e00 };
+ GdkColor question_default_border_color = { 0, 0x6200, 0x7b00, 0xd960 };
+ GdkColor question_default_fill_color = { 0, 0x8c00, 0xb000, 0xd700 };
+ GdkColor error_default_border_color = { 0, 0xa800, 0x2700, 0x2700 };
+ GdkColor error_default_fill_color = { 0, 0xf000, 0x3800, 0x3800 };
+ GdkColor other_default_border_color = { 0, 0xb800, 0xad00, 0x9d00 };
+ GdkColor other_default_fill_color = { 0, 0xff00, 0xff00, 0xbf00 };
GdkColor *fg, *bg;
GdkColor sym_fg, sym_bg;
- gboolean use_tooltip_style;
GtkStyle *style;
const char* fg_color_name[] = {
"info_fg_color",
@@ -541,48 +531,51 @@ gtk_info_bar_update_colors (GtkInfoBar *info_bar)
"error_bg_color",
"other_bg_color"
};
- gboolean has_color;
priv = GTK_INFO_BAR_GET_PRIVATE (info_bar);
style = gtk_widget_get_style (widget);
- gtk_widget_style_get (widget,
- "use-tooltip-style", &use_tooltip_style, NULL);
-
- has_color = FALSE;
-
if (gtk_style_lookup_color (style, fg_color_name[priv->message_type], &sym_fg) &&
gtk_style_lookup_color (style, bg_color_name[priv->message_type], &sym_bg))
{
fg = &sym_fg;
bg = &sym_bg;
- has_color = TRUE;
}
- else if (use_tooltip_style)
+ else
{
- style = gtk_rc_get_style_by_paths (gtk_widget_get_settings (widget),
- "gtk-tooltip", "GtkTooltip", G_TYPE_NONE);
- if (style)
- {
- fg = &style->fg[GTK_STATE_NORMAL];
- bg = &style->bg[GTK_STATE_NORMAL];
- }
- else
+ switch (priv->message_type)
{
- fg = &default_border_color;
- bg = &default_fill_color;
- }
+ case GTK_MESSAGE_INFO:
+ fg = &info_default_border_color;
+ bg = &info_default_fill_color;
+ break;
- has_color = TRUE;
- }
+ case GTK_MESSAGE_WARNING:
+ fg = &warning_default_border_color;
+ bg = &warning_default_fill_color;
+ break;
- if (has_color)
- {
- if (!gdk_color_equal (bg, &widget->style->bg[GTK_STATE_NORMAL]))
- gtk_widget_modify_bg (widget, GTK_STATE_NORMAL, bg);
- if (!gdk_color_equal (fg, &widget->style->fg[GTK_STATE_NORMAL]))
- gtk_widget_modify_fg (widget, GTK_STATE_NORMAL, fg);
+ case GTK_MESSAGE_QUESTION:
+ fg = &question_default_border_color;
+ bg = &question_default_fill_color;
+ break;
+
+ case GTK_MESSAGE_ERROR:
+ fg = &error_default_border_color;
+ bg = &error_default_fill_color;
+ break;
+
+ case GTK_MESSAGE_OTHER:
+ fg = &other_default_border_color;
+ bg = &other_default_fill_color;
+ break;
+ }
}
+
+ if (!gdk_color_equal (bg, &widget->style->bg[GTK_STATE_NORMAL]))
+ gtk_widget_modify_bg (widget, GTK_STATE_NORMAL, bg);
+ if (!gdk_color_equal (fg, &widget->style->fg[GTK_STATE_NORMAL]))
+ gtk_widget_modify_fg (widget, GTK_STATE_NORMAL, fg);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]