]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkinfobar.c
gtk: remove "gboolean homogeneous" from gtk_box_new()
[~andy/gtk] / gtk / gtkinfobar.c
index c96bd84b522b7563ce25df7ab0ae7847fcc58a8b..86859786e05d4a02021c93efba947a0bf2e2941e 100644 (file)
@@ -47,8 +47,6 @@
 #include "gtkprivate.h"
 #include "gtkstock.h"
 #include "gdkkeysyms.h"
-#include "gtkalias.h"
-
 
 /**
  * SECTION:gtkinfobar
  * </refsect2>
  */
 
-#define GTK_INFO_BAR_GET_PRIVATE(object) \
-  (G_TYPE_INSTANCE_GET_PRIVATE ((object), \
-                                GTK_TYPE_INFO_BAR, \
-                                GtkInfoBarPrivate))
-
 enum
 {
   PROP_0,
@@ -166,8 +159,8 @@ static void     gtk_info_bar_get_property (GObject        *object,
                                            GParamSpec     *pspec);
 static void     gtk_info_bar_style_set    (GtkWidget      *widget,
                                            GtkStyle       *prev_style);
-static gboolean gtk_info_bar_expose       (GtkWidget      *widget,
-                                           GdkEventExpose *event);
+static gboolean gtk_info_bar_draw         (GtkWidget      *widget,
+                                           cairo_t        *cr);
 static void     gtk_info_bar_buildable_interface_init     (GtkBuildableIface *iface);
 static GObject *gtk_info_bar_buildable_get_internal_child (GtkBuildable  *buildable,
                                                            GtkBuilder    *builder,
@@ -199,7 +192,7 @@ gtk_info_bar_set_property (GObject      *object,
   GtkInfoBarPrivate *priv;
 
   info_bar = GTK_INFO_BAR (object);
-  priv = GTK_INFO_BAR_GET_PRIVATE (info_bar);
+  priv = info_bar->priv;
 
   switch (prop_id)
     {
@@ -222,7 +215,7 @@ gtk_info_bar_get_property (GObject    *object,
   GtkInfoBarPrivate *priv;
 
   info_bar = GTK_INFO_BAR (object);
-  priv = GTK_INFO_BAR_GET_PRIVATE (info_bar);
+  priv = info_bar->priv;
 
   switch (prop_id)
     {
@@ -303,11 +296,10 @@ gtk_info_bar_close (GtkInfoBar *info_bar)
 }
 
 static gboolean
-gtk_info_bar_expose (GtkWidget      *widget,
-                     GdkEventExpose *event)
+gtk_info_bar_draw (GtkWidget      *widget,
+                   cairo_t        *cr)
 {
-  GtkInfoBarPrivate *priv = GTK_INFO_BAR_GET_PRIVATE (widget);
-  gboolean use_tooltip_style;
+  GtkInfoBarPrivate *priv = GTK_INFO_BAR (widget)->priv;
   const char* type_detail[] = {
     "infobar-info",
     "infobar-warning",
@@ -315,31 +307,26 @@ 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 (priv->message_type != GTK_MESSAGE_OTHER)
+    {
+      const char *detail;
+
+      detail = type_detail[priv->message_type];
+
+      gtk_paint_box (gtk_widget_get_style (widget),
+                     cr,
+                     GTK_STATE_NORMAL,
+                     GTK_SHADOW_OUT,
+                     widget,
+                     detail,
+                     0, 0,
+                     gtk_widget_get_allocated_width (widget),
+                     gtk_widget_get_allocated_height (widget));
+    }
 
-  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 (GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->expose_event)
-    GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->expose_event (widget, event);
+  if (GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->draw)
+    GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->draw (widget, cr);
 
   return FALSE;
 }
@@ -359,7 +346,7 @@ gtk_info_bar_class_init (GtkInfoBarClass *klass)
   object_class->finalize = gtk_info_bar_finalize;
 
   widget_class->style_set = gtk_info_bar_style_set;
-  widget_class->expose_event = gtk_info_bar_expose;
+  widget_class->draw = gtk_info_bar_draw;
 
   klass->close = gtk_info_bar_close;
 
@@ -374,9 +361,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 +375,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,25 +483,9 @@ 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);
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0, "close", 0);
 
   g_type_class_add_private (object_class, sizeof (GtkInfoBarPrivate));
 }
@@ -519,13 +493,20 @@ gtk_info_bar_class_init (GtkInfoBarClass *klass)
 static void
 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 };
+  GtkWidget *widget = GTK_WIDGET (info_bar);
+  GtkInfoBarPrivate *priv = info_bar->priv;
+  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 +522,55 @@ 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;
+
+        default:
+          g_assert_not_reached();
+          fg = NULL;
+          bg = NULL;
+        }
     }
+
+  if (!gdk_color_equal (bg, &style->bg[GTK_STATE_NORMAL]))
+    gtk_widget_modify_bg (widget, GTK_STATE_NORMAL, bg);
+  if (!gdk_color_equal (fg, &style->fg[GTK_STATE_NORMAL]))
+    gtk_widget_modify_fg (widget, GTK_STATE_NORMAL, fg);
 }
 
 static void
@@ -620,18 +608,21 @@ gtk_info_bar_init (GtkInfoBar *info_bar)
 
   gtk_widget_push_composite_child ();
 
-  info_bar->priv = GTK_INFO_BAR_GET_PRIVATE (info_bar);
+  info_bar->priv = G_TYPE_INSTANCE_GET_PRIVATE (info_bar,
+                                                GTK_TYPE_INFO_BAR,
+                                                GtkInfoBarPrivate);
 
-  content_area = gtk_hbox_new (FALSE, 0);
+  content_area = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
   gtk_widget_show (content_area);
   gtk_box_pack_start (GTK_BOX (info_bar), content_area, TRUE, TRUE, 0);
 
-  action_area = gtk_vbutton_box_new ();
+  action_area = gtk_button_box_new (GTK_ORIENTATION_VERTICAL);
   gtk_widget_show (action_area);
   gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
   gtk_box_pack_start (GTK_BOX (info_bar), action_area, FALSE, TRUE, 0);
 
   gtk_widget_set_app_paintable (GTK_WIDGET (info_bar), TRUE);
+  gtk_widget_set_redraw_on_allocate (GTK_WIDGET (info_bar), TRUE);
 
   info_bar->priv->content_area = content_area;
   info_bar->priv->action_area = action_area;
@@ -745,7 +736,7 @@ gtk_info_bar_add_action_widget (GtkInfoBar *info_bar,
  *
  * Returns the action area of @info_bar.
  *
- * Returns: the action area.
+ * Returns: (transfer none): the action area
  *
  * Since: 2.18
  */
@@ -763,7 +754,7 @@ gtk_info_bar_get_action_area (GtkInfoBar *info_bar)
  *
  * Returns the content area of @info_bar.
  *
- * Returns: the content area.
+ * Returns: (transfer none): the content area
  *
  * Since: 2.18
  */
@@ -787,7 +778,7 @@ gtk_info_bar_get_content_area (GtkInfoBar *info_bar)
  * to the end of the info bars's action area. The button widget is
  * returned, but usually you don't need it.
  *
- * Returns: the button widget that was added
+ * Returns: (transfer none): the button widget that was added
  *
  * Since: 2.18
  */
@@ -803,7 +794,7 @@ gtk_info_bar_add_button (GtkInfoBar  *info_bar,
 
   button = gtk_button_new_from_stock (button_text);
 
-  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
+  gtk_widget_set_can_default (button, TRUE);
 
   gtk_widget_show (button);
 
@@ -883,7 +874,7 @@ gtk_info_bar_new (void)
 
 /**
  * gtk_info_bar_new_with_buttons:
- * @first_button_text: stock ID or text to go in first button, or %NULL
+ * @first_button_text: (allow-none): stock ID or text to go in first button, or %NULL
  * @...: response ID for first button, then additional buttons, ending
  *    with %NULL
  *
@@ -957,6 +948,9 @@ gtk_info_bar_set_response_sensitive (GtkInfoBar *info_bar,
  * the given response_id as the default widget for the dialog.
  * Pressing "Enter" normally activates the default widget.
  *
+ * Note that this function currently requires @info_bar to
+ * be added to a widget hierarchy. 
+ *
  * Since: 2.18
  */
 void
@@ -1182,7 +1176,7 @@ gtk_info_bar_set_message_type (GtkInfoBar     *info_bar,
 
   g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
 
-  priv = GTK_INFO_BAR_GET_PRIVATE (info_bar);
+  priv = info_bar->priv;
 
   if (priv->message_type != message_type)
     {
@@ -1249,15 +1243,7 @@ gtk_info_bar_set_message_type (GtkInfoBar     *info_bar,
 GtkMessageType
 gtk_info_bar_get_message_type (GtkInfoBar *info_bar)
 {
-  GtkInfoBarPrivate *priv;
-
   g_return_val_if_fail (GTK_IS_INFO_BAR (info_bar), GTK_MESSAGE_OTHER);
 
-  priv = GTK_INFO_BAR_GET_PRIVATE (info_bar);
-
-  return priv->message_type;
+  return info_bar->priv->message_type;
 }
-
-
-#define __GTK_INFO_BAR_C__
-#include "gtkaliasdef.c"