* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* GTK_STOCK_OK, GTK_RESPONSE_OK);
* g_signal_connect (info_bar, "response",
* G_CALLBACK (gtk_widget_hide), NULL);
- * gtk_table_attach (GTK_TABLE (table),
- * info_bar,
- * 0, 1, 2, 3,
- * GTK_EXPAND | GTK_FILL, 0,
- * 0, 0);
+ * gtk_grid_attach (GTK_GRID (grid),
+ * info_bar,
+ * 0, 2, 1, 1);
*
* /* ... */
*
static guint signals[LAST_SIGNAL];
+#define ACTION_AREA_DEFAULT_BORDER 5
+#define ACTION_AREA_DEFAULT_SPACING 6
+#define CONTENT_AREA_DEFAULT_BORDER 8
+#define CONTENT_AREA_DEFAULT_SPACING 16
static void gtk_info_bar_set_property (GObject *object,
guint prop_id,
guint prop_id,
GValue *value,
GParamSpec *pspec);
-static void gtk_info_bar_style_updated (GtkWidget *widget);
-static gboolean gtk_info_bar_draw (GtkWidget *widget,
- cairo_t *cr);
+static void gtk_info_bar_get_preferred_width (GtkWidget *widget,
+ gint *minimum_width,
+ gint *natural_width);
+static void gtk_info_bar_get_preferred_height (GtkWidget *widget,
+ gint *minimum_height,
+ gint *natural_height);
+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,
GTK_RESPONSE_CANCEL);
}
-static gboolean
-gtk_info_bar_draw (GtkWidget *widget,
- cairo_t *cr)
+static void
+get_padding_and_border (GtkWidget *widget,
+ GtkBorder *border)
{
- GtkInfoBarPrivate *priv = GTK_INFO_BAR (widget)->priv;
- const char* type_class[] = {
- GTK_STYLE_CLASS_INFO,
- GTK_STYLE_CLASS_WARNING,
- GTK_STYLE_CLASS_QUESTION,
- GTK_STYLE_CLASS_ERROR,
- NULL
- };
-
- if (priv->message_type != GTK_MESSAGE_OTHER)
- {
- GtkStyleContext *context;
+ GtkStyleContext *context;
+ GtkStateFlags state;
+ GtkBorder tmp;
+
+ context = gtk_widget_get_style_context (widget);
+ state = gtk_widget_get_state_flags (widget);
+
+ gtk_style_context_get_padding (context, state, border);
+ gtk_style_context_get_border (context, state, &tmp);
+ border->top += tmp.top;
+ border->right += tmp.right;
+ border->bottom += tmp.bottom;
+ border->left += tmp.left;
+}
- context = gtk_widget_get_style_context (widget);
+static void
+gtk_info_bar_get_preferred_width (GtkWidget *widget,
+ gint *minimum_width,
+ gint *natural_width)
+{
+ GtkBorder border;
- gtk_style_context_save (context);
+ get_padding_and_border (widget, &border);
- if (type_class[priv->message_type])
- gtk_style_context_add_class (context,
- type_class[priv->message_type]);
+ GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->get_preferred_width (widget,
+ minimum_width,
+ natural_width);
+
+ if (minimum_width)
+ *minimum_width += border.left + border.right;
+ if (natural_width)
+ *natural_width += border.left + border.right;
+}
- 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));
+static void
+gtk_info_bar_get_preferred_height (GtkWidget *widget,
+ gint *minimum_height,
+ gint *natural_height)
+{
+ GtkBorder border;
- gtk_style_context_restore (context);
- }
+ get_padding_and_border (widget, &border);
+
+ GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->get_preferred_height (widget,
+ minimum_height,
+ natural_height);
- if (GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->draw)
- GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->draw (widget, cr);
+ if (minimum_height)
+ *minimum_height += border.top + border.bottom;
+ if (natural_height)
+ *natural_height += border.top + border.bottom;
+}
+
+static gboolean
+gtk_info_bar_draw (GtkWidget *widget,
+ cairo_t *cr)
+{
+ GtkStyleContext *context;
+
+ 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;
}
object_class->set_property = gtk_info_bar_set_property;
object_class->finalize = gtk_info_bar_finalize;
- widget_class->style_updated = gtk_info_bar_style_updated;
+ widget_class->get_preferred_width = gtk_info_bar_get_preferred_width;
+ widget_class->get_preferred_height = gtk_info_bar_get_preferred_height;
widget_class->draw = gtk_info_bar_draw;
klass->close = gtk_info_bar_close;
* content area of the info bar.
*
* Since: 2.18
+ * Deprecated: 3.6: Use gtk_container_set_border_width()
*/
gtk_widget_class_install_style_property (widget_class,
g_param_spec_int ("content-area-border",
P_("Width of border around the content area"),
0,
G_MAXINT,
- 8,
+ CONTENT_AREA_DEFAULT_BORDER,
GTK_PARAM_READABLE));
/**
* content area of the info bar.
*
* Since: 2.18
+ * Deprecated: 3.6: Use gtk_box_set_spacing()
*/
gtk_widget_class_install_style_property (widget_class,
g_param_spec_int ("content-area-spacing",
P_("Spacing between elements of the area"),
0,
G_MAXINT,
- 16,
+ CONTENT_AREA_DEFAULT_SPACING,
GTK_PARAM_READABLE));
/**
* Spacing between buttons in the action area of the info bar.
*
* Since: 2.18
+ * Deprecated: 3.6: Use gtk_box_set_spacing()
*/
gtk_widget_class_install_style_property (widget_class,
g_param_spec_int ("button-spacing",
P_("Spacing between buttons"),
0,
G_MAXINT,
- 6,
+ ACTION_AREA_DEFAULT_SPACING,
GTK_PARAM_READABLE));
/**
* Width of the border around the action area of the info bar.
*
* Since: 2.18
+ * Deprecated: 3.6: Use gtk_container_set_border_width()
*/
gtk_widget_class_install_style_property (widget_class,
g_param_spec_int ("action-area-border",
P_("Width of border around the action area"),
0,
G_MAXINT,
- 5,
+ ACTION_AREA_DEFAULT_BORDER,
GTK_PARAM_READABLE));
binding_set = gtk_binding_set_by_class (klass);
g_type_class_add_private (object_class, sizeof (GtkInfoBarPrivate));
}
-static void
-gtk_info_bar_style_updated (GtkWidget *widget)
-{
- GtkInfoBar *info_bar = GTK_INFO_BAR (widget);
- gint button_spacing;
- gint action_area_border;
- gint content_area_spacing;
- gint content_area_border;
-
- GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->style_updated (widget);
-
- gtk_widget_style_get (widget,
- "button-spacing", &button_spacing,
- "action-area-border", &action_area_border,
- "content-area-spacing", &content_area_spacing,
- "content-area-border", &content_area_border,
- NULL);
-
- gtk_box_set_spacing (GTK_BOX (info_bar->priv->action_area), button_spacing);
- gtk_container_set_border_width (GTK_CONTAINER (info_bar->priv->action_area),
- action_area_border);
- gtk_box_set_spacing (GTK_BOX (info_bar->priv->content_area), content_area_spacing);
- gtk_container_set_border_width (GTK_CONTAINER (info_bar->priv->content_area),
- content_area_border);
-}
-
static void
gtk_info_bar_init (GtkInfoBar *info_bar)
{
+ GtkWidget *widget = GTK_WIDGET (info_bar);
GtkWidget *content_area;
GtkWidget *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);
+ gtk_widget_set_app_paintable (widget, TRUE);
+ gtk_widget_set_redraw_on_allocate (widget, TRUE);
info_bar->priv->content_area = content_area;
info_bar->priv->action_area = action_area;
+ /* set default spacings */
+ gtk_box_set_spacing (GTK_BOX (info_bar->priv->action_area), ACTION_AREA_DEFAULT_SPACING);
+ gtk_container_set_border_width (GTK_CONTAINER (info_bar->priv->action_area), ACTION_AREA_DEFAULT_BORDER);
+ gtk_box_set_spacing (GTK_BOX (info_bar->priv->content_area), CONTENT_AREA_DEFAULT_SPACING);
+ gtk_container_set_border_width (GTK_CONTAINER (info_bar->priv->content_area), CONTENT_AREA_DEFAULT_BORDER);
+
+ /* message-type is a CONSTRUCT property, so we init to a value
+ * different from its default to trigger its property setter
+ * during construction */
+ info_bar->priv->message_type = GTK_MESSAGE_OTHER;
+
gtk_widget_pop_composite_child ();
}
{
ActionWidgetsSubParserData *parser_data;
- if (child)
- return FALSE;
+ if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
+ tagname, parser, data))
+ return TRUE;
- if (strcmp (tagname, "action-widgets") == 0)
+ if (!child && strcmp (tagname, "action-widgets") == 0)
{
parser_data = g_slice_new0 (ActionWidgetsSubParserData);
parser_data->info_bar = GTK_INFO_BAR (buildable);
return TRUE;
}
- return parent_buildable_iface->custom_tag_start (buildable, builder, child,
- tagname, parser, data);
+ return FALSE;
}
static void
GtkMessageType message_type)
{
GtkInfoBarPrivate *priv;
- AtkObject *atk_obj;
g_return_if_fail (GTK_IS_INFO_BAR (info_bar));
if (priv->message_type != message_type)
{
+ GtkStyleContext *context;
+ AtkObject *atk_obj;
+ const char *type_class[] = {
+ GTK_STYLE_CLASS_INFO,
+ GTK_STYLE_CLASS_WARNING,
+ GTK_STYLE_CLASS_QUESTION,
+ GTK_STYLE_CLASS_ERROR,
+ NULL
+ };
+
+ context = gtk_widget_get_style_context (GTK_WIDGET (info_bar));
+
+ if (type_class[priv->message_type])
+ gtk_style_context_remove_class (context, type_class[priv->message_type]);
+
priv->message_type = message_type;
gtk_widget_queue_draw (GTK_WIDGET (info_bar));
}
}
+ if (type_class[priv->message_type])
+ gtk_style_context_add_class (context, type_class[priv->message_type]);
+
g_object_notify (G_OBJECT (info_bar), "message-type");
}
}