infobar: port to use a gadget

This commit is contained in:
Cosimo Cecchi 2016-01-02 15:28:12 -08:00
parent f246dc1c85
commit feb741babf

View File

@ -37,6 +37,7 @@
#include "gtkbuilderprivate.h" #include "gtkbuilderprivate.h"
#include "gtkbbox.h" #include "gtkbbox.h"
#include "gtkbox.h" #include "gtkbox.h"
#include "gtkcsscustomgadgetprivate.h"
#include "gtklabel.h" #include "gtklabel.h"
#include "gtkbutton.h" #include "gtkbutton.h"
#include "gtkenums.h" #include "gtkenums.h"
@ -48,6 +49,7 @@
#include "gtkorientable.h" #include "gtkorientable.h"
#include "gtkrender.h" #include "gtkrender.h"
#include "gtktypebuiltins.h" #include "gtktypebuiltins.h"
#include "gtkwidgetprivate.h"
#include "deprecated/gtkstock.h" #include "deprecated/gtkstock.h"
/** /**
@ -141,6 +143,8 @@ struct _GtkInfoBarPrivate
GtkWidget *close_button; GtkWidget *close_button;
GtkWidget *revealer; GtkWidget *revealer;
GtkCssGadget *gadget;
gboolean show_close_button; gboolean show_close_button;
GtkMessageType message_type; GtkMessageType message_type;
}; };
@ -248,6 +252,10 @@ gtk_info_bar_get_property (GObject *object,
static void static void
gtk_info_bar_finalize (GObject *object) gtk_info_bar_finalize (GObject *object)
{ {
GtkInfoBar *info_bar = GTK_INFO_BAR (object);
g_clear_object (&info_bar->priv->gadget);
G_OBJECT_CLASS (gtk_info_bar_parent_class)->finalize (object); G_OBJECT_CLASS (gtk_info_bar_parent_class)->finalize (object);
} }
@ -314,22 +322,25 @@ gtk_info_bar_close (GtkInfoBar *info_bar)
} }
static void static void
get_padding_and_border (GtkWidget *widget, gtk_info_bar_measure (GtkCssGadget *gadget,
GtkBorder *border) GtkOrientation orientation,
int size,
int *minimum,
int *natural,
int *minimum_baseline,
int *natural_baseline,
gpointer data)
{ {
GtkStyleContext *context; GtkWidget *widget = gtk_css_gadget_get_owner (gadget);
GtkStateFlags state;
GtkBorder tmp;
context = gtk_widget_get_style_context (widget); if (orientation == GTK_ORIENTATION_HORIZONTAL)
state = gtk_style_context_get_state (context); GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->get_preferred_width (widget,
minimum,
gtk_style_context_get_padding (context, state, border); natural);
gtk_style_context_get_border (context, state, &tmp); else
border->top += tmp.top; GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->get_preferred_height (widget,
border->right += tmp.right; minimum,
border->bottom += tmp.bottom; natural);
border->left += tmp.left;
} }
static void static void
@ -337,16 +348,11 @@ gtk_info_bar_get_preferred_width (GtkWidget *widget,
gint *minimum_width, gint *minimum_width,
gint *natural_width) gint *natural_width)
{ {
GtkBorder border; gtk_css_gadget_get_preferred_size (GTK_INFO_BAR (widget)->priv->gadget,
GTK_ORIENTATION_HORIZONTAL,
get_padding_and_border (widget, &border); -1,
minimum_width, natural_width,
GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->get_preferred_width (widget, NULL, NULL);
minimum_width,
natural_width);
*minimum_width += border.left + border.right;
*natural_width += border.left + border.right;
} }
static void static void
@ -354,34 +360,34 @@ gtk_info_bar_get_preferred_height (GtkWidget *widget,
gint *minimum_height, gint *minimum_height,
gint *natural_height) gint *natural_height)
{ {
GtkBorder border; gtk_css_gadget_get_preferred_size (GTK_INFO_BAR (widget)->priv->gadget,
GTK_ORIENTATION_VERTICAL,
-1,
minimum_height, natural_height,
NULL, NULL);
}
get_padding_and_border (widget, &border); static gboolean
gtk_info_bar_render (GtkCssGadget *gadget,
cairo_t *cr,
int x,
int y,
int width,
int height,
gpointer data)
{
GtkWidget *widget = gtk_css_gadget_get_owner (gadget);
GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->get_preferred_height (widget, GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->draw (widget, cr);
minimum_height,
natural_height);
*minimum_height += border.top + border.bottom; return FALSE;
*natural_height += border.top + border.bottom;
} }
static gboolean static gboolean
gtk_info_bar_draw (GtkWidget *widget, gtk_info_bar_draw (GtkWidget *widget,
cairo_t *cr) cairo_t *cr)
{ {
GtkStyleContext *context; gtk_css_gadget_draw (GTK_INFO_BAR (widget)->priv->gadget, cr);
context = gtk_widget_get_style_context (widget);
gtk_render_background (context, cr, 0, 0,
gtk_widget_get_allocated_width (widget),
gtk_widget_get_allocated_height (widget));
gtk_render_frame (context, cr, 0, 0,
gtk_widget_get_allocated_width (widget),
gtk_widget_get_allocated_height (widget));
GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->draw (widget, cr);
return FALSE; return FALSE;
} }
@ -608,6 +614,7 @@ gtk_info_bar_init (GtkInfoBar *info_bar)
{ {
GtkInfoBarPrivate *priv; GtkInfoBarPrivate *priv;
GtkWidget *widget = GTK_WIDGET (info_bar); GtkWidget *widget = GTK_WIDGET (info_bar);
GtkCssNode *widget_node;
priv = info_bar->priv = gtk_info_bar_get_instance_private (info_bar); priv = info_bar->priv = gtk_info_bar_get_instance_private (info_bar);
@ -623,6 +630,14 @@ gtk_info_bar_init (GtkInfoBar *info_bar)
gtk_widget_set_no_show_all (priv->close_button, TRUE); gtk_widget_set_no_show_all (priv->close_button, TRUE);
g_signal_connect (priv->close_button, "clicked", g_signal_connect (priv->close_button, "clicked",
G_CALLBACK (close_button_clicked_cb), info_bar); G_CALLBACK (close_button_clicked_cb), info_bar);
widget_node = gtk_widget_get_css_node (widget);
priv->gadget = gtk_css_custom_gadget_new_for_node (widget_node,
widget,
gtk_info_bar_measure,
NULL,
gtk_info_bar_render,
NULL, NULL);
} }
static GtkBuildableIface *parent_buildable_iface; static GtkBuildableIface *parent_buildable_iface;