+ if (!gtk_default_style)
+ {
+ gtk_default_style = gtk_style_new ();
+ g_object_ref (gtk_default_style);
+ }
+
+ return gtk_default_style;
+}
+
+#ifdef G_ENABLE_DEBUG
+
+/* Verify invariants, see docs/widget_system.txt for notes on much of
+ * this. Invariants may be temporarily broken while we're in the
+ * process of updating state, of course, so you can only
+ * verify_invariants() after a given operation is complete.
+ * Use push/pop_verify_invariants to help with that.
+ */
+static void
+gtk_widget_verify_invariants (GtkWidget *widget)
+{
+ GtkWidget *parent;
+
+ if (widget->priv->verifying_invariants_count > 0)
+ return;
+
+ parent = widget->priv->parent;
+
+ if (widget->priv->mapped)
+ {
+ /* Mapped implies ... */
+
+ if (!widget->priv->realized)
+ g_warning ("%s %p is mapped but not realized",
+ G_OBJECT_TYPE_NAME (widget), widget);
+
+ if (!widget->priv->visible)
+ g_warning ("%s %p is mapped but not visible",
+ G_OBJECT_TYPE_NAME (widget), widget);
+
+ if (!widget->priv->toplevel)
+ {
+ if (!widget->priv->child_visible)
+ g_warning ("%s %p is mapped but not child_visible",
+ G_OBJECT_TYPE_NAME (widget), widget);
+ }
+ }
+ else
+ {
+ /* Not mapped implies... */
+
+#if 0
+ /* This check makes sense for normal toplevels, but for
+ * something like a toplevel that is embedded within a clutter
+ * state, mapping may depend on external factors.
+ */
+ if (widget->priv->toplevel)
+ {
+ if (widget->priv->visible)
+ g_warning ("%s %p toplevel is visible but not mapped",
+ G_OBJECT_TYPE_NAME (widget), widget);
+ }
+#endif
+ }
+
+ /* Parent related checks aren't possible if parent has
+ * verifying_invariants_count > 0 because parent needs to recurse
+ * children first before the invariants will hold.
+ */
+ if (parent == NULL || parent->priv->verifying_invariants_count == 0)
+ {
+ if (parent &&
+ parent->priv->realized)
+ {
+ /* Parent realized implies... */
+
+#if 0
+ /* This is in widget_system.txt but appears to fail
+ * because there's no gtk_container_realize() that
+ * realizes all children... instead we just lazily
+ * wait for map to fix things up.
+ */
+ if (!widget->priv->realized)
+ g_warning ("%s %p is realized but child %s %p is not realized",
+ G_OBJECT_TYPE_NAME (parent), parent,
+ G_OBJECT_TYPE_NAME (widget), widget);
+#endif
+ }
+ else if (!widget->priv->toplevel)
+ {
+ /* No parent or parent not realized on non-toplevel implies... */
+
+ if (widget->priv->realized && !widget->priv->in_reparent)
+ g_warning ("%s %p is not realized but child %s %p is realized",
+ parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
+ G_OBJECT_TYPE_NAME (widget), widget);
+ }
+
+ if (parent &&
+ parent->priv->mapped &&
+ widget->priv->visible &&
+ widget->priv->child_visible)
+ {
+ /* Parent mapped and we are visible implies... */
+
+ if (!widget->priv->mapped)
+ g_warning ("%s %p is mapped but visible child %s %p is not mapped",
+ G_OBJECT_TYPE_NAME (parent), parent,
+ G_OBJECT_TYPE_NAME (widget), widget);
+ }
+ else if (!widget->priv->toplevel)
+ {
+ /* No parent or parent not mapped on non-toplevel implies... */
+
+ if (widget->priv->mapped && !widget->priv->in_reparent)
+ g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
+ G_OBJECT_TYPE_NAME (widget), widget,
+ widget->priv->visible,
+ widget->priv->child_visible,
+ parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
+ parent ? parent->priv->mapped : FALSE);
+ }
+ }
+
+ if (!widget->priv->realized)
+ {
+ /* Not realized implies... */
+
+#if 0
+ /* widget_system.txt says these hold, but they don't. */
+ if (widget->priv->resize_pending)
+ g_warning ("%s %p resize pending but not realized",
+ G_OBJECT_TYPE_NAME (widget), widget);
+
+ if (widget->priv->alloc_needed)
+ g_warning ("%s %p alloc needed but not realized",
+ G_OBJECT_TYPE_NAME (widget), widget);
+
+ if (widget->priv->width_request_needed)
+ g_warning ("%s %p width request needed but not realized",
+ G_OBJECT_TYPE_NAME (widget), widget);
+
+ if (widget->priv->height_request_needed)
+ g_warning ("%s %p height request needed but not realized",
+ G_OBJECT_TYPE_NAME (widget), widget);
+#endif
+ }
+}
+
+/* The point of this push/pop is that invariants may not hold while
+ * we're busy making changes. So we only check at the outermost call
+ * on the call stack, after we finish updating everything.
+ */
+static void
+gtk_widget_push_verify_invariants (GtkWidget *widget)
+{
+ widget->priv->verifying_invariants_count += 1;
+}
+
+static void
+gtk_widget_verify_child_invariants (GtkWidget *widget,
+ gpointer client_data)
+{
+ /* We don't recurse further; this is a one-level check. */
+ gtk_widget_verify_invariants (widget);
+}
+
+static void
+gtk_widget_pop_verify_invariants (GtkWidget *widget)
+{
+ g_assert (widget->priv->verifying_invariants_count > 0);
+
+ widget->priv->verifying_invariants_count -= 1;
+
+ if (widget->priv->verifying_invariants_count == 0)