]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkwidget.c
filechooserbutton: In SELECT_FOLDER, when the selection is empty, show (None) in...
[~andy/gtk] / gtk / gtkwidget.c
index b39bb2148694aed59e4c5b273554711d0677947a..37460e3419680aab8b42d52e0f51003bb474fc0a 100644 (file)
@@ -12,9 +12,7 @@
  * 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/>.
  */
 
 /*
 #include <stdarg.h>
 #include <string.h>
 #include <locale.h>
+#include <math.h>
 
 #include <gobject/gvaluecollector.h>
 #include <gobject/gobjectnotifyqueue.c>
 #include <cairo-gobject.h>
 
 #include "gtkcontainer.h"
-#include "gtkaccelmap.h"
+#include "gtkaccelmapprivate.h"
 #include "gtkclipboard.h"
+#include "gtkcssstylepropertyprivate.h"
+#include "gtkcssnumbervalueprivate.h"
 #include "gtkiconfactory.h"
 #include "gtkintl.h"
-#include "gtkmainprivate.h"
 #include "gtkmarshalers.h"
-#include "gtkrc.h"
 #include "gtkselectionprivate.h"
 #include "gtksettingsprivate.h"
 #include "gtksizegroup-private.h"
+#include "gtksizerequestcacheprivate.h"
 #include "gtkwidget.h"
 #include "gtkwidgetprivate.h"
 #include "gtkwindowprivate.h"
+#include "gtkcontainerprivate.h"
 #include "gtkbindings.h"
 #include "gtkprivate.h"
 #include "gtkaccessible.h"
 #include "gtkbuilderprivate.h"
 #include "gtksizerequest.h"
 #include "gtkstylecontextprivate.h"
-#include "gtksymboliccolor.h"
 #include "gtkcssprovider.h"
-#include "gtkanimationdescription.h"
 #include "gtkmodifierstyle.h"
 #include "gtkversion.h"
 #include "gtkdebug.h"
 #include "gtkplug.h"
 #include "gtktypebuiltins.h"
-
+#include "a11y/gtkwidgetaccessible.h"
 
 /**
  * SECTION:gtkwidget
  *   </accessibility>
  *   <child internal-child="accessible">
  *     <object class="AtkObject" id="a11y-button1">
- *       <property name="AtkObject::name">Clickable Button</property>
+ *       <property name="accessible-name">Clickable Button</property>
  *     </object>
  *   </child>
  * </object>
  * </refsect2>
  */
 
+/* Add flags here that should not be propagated to children. By default,
+ * all flags will be set on children (think prelight or active), but we
+ * might want to not do this for some.
+ */
+#define GTK_STATE_FLAGS_DONT_PROPAGATE (GTK_STATE_FLAG_FOCUSED | GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL)
+#define GTK_STATE_FLAGS_DO_PROPAGATE (~GTK_STATE_FLAGS_DONT_PROPAGATE)
+
 #define WIDGET_CLASS(w)         GTK_WIDGET_GET_CLASS (w)
-#define        INIT_PATH_SIZE  (512)
+
+#define GTK_STATE_FLAGS_BITS 9
 
 struct _GtkWidgetPrivate
 {
-  /* The state of the widget. There are actually only
-   * 5 widget states (defined in "gtkenums.h")
-   * so 3 bits.
+  /* The state of the widget. Needs to be able to hold all GtkStateFlags bits
+   * (defined in "gtkenums.h").
    */
-  guint state_flags : 6;
+  guint state_flags : GTK_STATE_FLAGS_BITS;
 
   guint direction             : 2;
 
@@ -328,7 +334,6 @@ struct _GtkWidgetPrivate
   guint receives_default      : 1;
   guint has_grab              : 1;
   guint shadowed              : 1;
-  guint rc_style              : 1;
   guint style_update_pending  : 1;
   guint app_paintable         : 1;
   guint double_buffered       : 1;
@@ -340,10 +345,7 @@ struct _GtkWidgetPrivate
   guint in_reparent           : 1;
 
   /* Queue-resize related flags */
-  guint resize_pending        : 1;
   guint alloc_needed          : 1;
-  guint width_request_needed  : 1;
-  guint height_request_needed : 1;
 
   /* Expand-related flags */
   guint need_compute_expand   : 1; /* Need to recompute computed_[hv]_expand */
@@ -355,50 +357,71 @@ struct _GtkWidgetPrivate
   guint vexpand_set           : 1; /* instead of computing from children */
 
   /* SizeGroup related flags */
-  guint sizegroup_visited     : 1;
-  guint sizegroup_bumping     : 1;
   guint have_size_groups      : 1;
 
+  guint opacity_group         : 1;
+  guint norender_children     : 1;
+  guint norender              : 1; /* Don't expose windows, instead recurse via draw */
+
+  guint8 alpha;
+  guint8 user_alpha;
+
   /* The widget's name. If the widget does not have a name
-   *  (the name is NULL), then its name (as returned by
-   *  "gtk_widget_get_name") is its class's name.
+   * (the name is NULL), then its name (as returned by
+   * "gtk_widget_get_name") is its class's name.
    * Among other things, the widget name is used to determine
-   *  the style to use for a widget.
+   * the style to use for a widget.
    */
   gchar *name;
 
+  /* The list of attached windows to this widget.
+   * We keep a list in order to call reset_style to all of them,
+   * recursively. */
+  GList *attached_windows; 
+
   /* The style for the widget. The style contains the
-   *  colors the widget should be drawn in for each state
-   *  along with graphics contexts used to draw with and
-   *  the font to use for text.
+   * colors the widget should be drawn in for each state
+   * along with graphics contexts used to draw with and
+   * the font to use for text.
    */
   GtkStyle *style;
   GtkStyleContext *context;
 
-  /* The widget's allocated size.
-   */
+  /* Widget's path for styling */
+  GtkWidgetPath *path;
+
+  /* The widget's allocated size */
   GtkAllocation allocation;
 
   /* The widget's requested sizes */
   SizeRequestCache requests;
 
+  /* actions attached to this or any parent widget */
+  GActionMuxer *muxer;
+
   /* The widget's window or its parent window if it does
-   *  not have a window. (Which will be indicated by the
-   *  GTK_NO_WINDOW flag being set).
+   * not have a window. (Which will be indicated by the
+   * GTK_NO_WINDOW flag being set).
    */
   GdkWindow *window;
+  GList *registered_windows;
 
-  /* The widget's parent.
-   */
+  /* The widget's parent */
   GtkWidget *parent;
 
+  /* Animations and other things to update on clock ticks */
+  GList *tick_callbacks;
+
 #ifdef G_ENABLE_DEBUG
   /* Number of gtk_widget_push_verify_invariants () */
   guint verifying_invariants_count;
 #endif /* G_ENABLE_DEBUG */
+};
 
-  /* Widget's path for styling */
-  GtkWidgetPath *path;
+struct _GtkWidgetClassPrivate
+{
+  GType accessible_type;
+  AtkRole accessible_role;
 };
 
 enum {
@@ -470,6 +493,7 @@ enum {
   QUERY_TOOLTIP,
   DRAG_FAILED,
   STYLE_UPDATED,
+  TOUCH_EVENT,
   LAST_SIGNAL
 };
 
@@ -496,6 +520,7 @@ enum {
   PROP_TOOLTIP_MARKUP,
   PROP_TOOLTIP_TEXT,
   PROP_WINDOW,
+  PROP_OPACITY,
   PROP_DOUBLE_BUFFERED,
   PROP_HALIGN,
   PROP_VALIGN,
@@ -513,20 +538,14 @@ enum {
 
 typedef        struct  _GtkStateData    GtkStateData;
 
-enum {
-  STATE_CHANGE_REPLACE,
-  STATE_CHANGE_SET,
-  STATE_CHANGE_UNSET
-};
-
 struct _GtkStateData
 {
-  guint         flags : 6;
-  guint         operation : 2;
-  guint                use_forall : 1;
+  guint         flags_to_set;
+  guint         flags_to_unset;
 };
 
 /* --- prototypes --- */
+static void    gtk_widget_base_class_init      (gpointer            g_class);
 static void    gtk_widget_class_init           (GtkWidgetClass     *klass);
 static void    gtk_widget_base_class_finalize  (GtkWidgetClass     *klass);
 static void    gtk_widget_init                 (GtkWidget          *widget);
@@ -538,6 +557,7 @@ static void gtk_widget_get_property          (GObject           *object,
                                                  guint              prop_id,
                                                  GValue            *value,
                                                  GParamSpec        *pspec);
+static void    gtk_widget_constructed           (GObject           *object);
 static void    gtk_widget_dispose               (GObject           *object);
 static void    gtk_widget_real_destroy          (GtkWidget         *object);
 static void    gtk_widget_finalize              (GObject           *object);
@@ -575,6 +595,8 @@ static gboolean             gtk_widget_real_focus_in_event           (GtkWidget       *widget,
                                                                  GdkEventFocus   *event);
 static gboolean                gtk_widget_real_focus_out_event         (GtkWidget        *widget,
                                                                 GdkEventFocus    *event);
+static gboolean         gtk_widget_real_touch_event             (GtkWidget        *widget,
+                                                                 GdkEventTouch    *event);
 static gboolean                gtk_widget_real_focus                   (GtkWidget        *widget,
                                                                 GtkDirectionType  direction);
 static void             gtk_widget_real_move_focus              (GtkWidget        *widget,
@@ -594,7 +616,8 @@ static PangoContext*        gtk_widget_peek_pango_context           (GtkWidget        *widget);
 static void            gtk_widget_update_pango_context         (GtkWidget        *widget);
 static void            gtk_widget_propagate_state              (GtkWidget        *widget,
                                                                 GtkStateData     *data);
-;
+static void             gtk_widget_update_alpha                 (GtkWidget        *widget);
+
 static gint            gtk_widget_event_internal               (GtkWidget        *widget,
                                                                 GdkEvent         *event);
 static gboolean                gtk_widget_real_mnemonic_activate       (GtkWidget        *widget,
@@ -613,7 +636,11 @@ static void             gtk_widget_real_get_width_for_height    (GtkWidget
                                                                  gint              height,
                                                                  gint             *minimum_width,
                                                                  gint             *natural_width);
+static void             gtk_widget_real_state_flags_changed     (GtkWidget        *widget,
+                                                                 GtkStateFlags     old_state);
 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
+static GtkWidgetAuxInfo* gtk_widget_get_aux_info                (GtkWidget        *widget,
+                                                                 gboolean          create);
 static void            gtk_widget_aux_info_destroy             (GtkWidgetAuxInfo *aux_info);
 static AtkObject*      gtk_widget_real_get_accessible          (GtkWidget        *widget);
 static void            gtk_widget_accessible_interface_init    (AtkImplementorIface *iface);
@@ -621,7 +648,6 @@ static AtkObject*   gtk_widget_ref_accessible               (AtkImplementor *implementor);
 static void             gtk_widget_invalidate_widget_windows    (GtkWidget        *widget,
                                                                 cairo_region_t        *region);
 static GdkScreen *      gtk_widget_get_screen_unchecked         (GtkWidget        *widget);
-static void            gtk_widget_queue_shallow_draw           (GtkWidget        *widget);
 static gboolean         gtk_widget_real_can_activate_accel      (GtkWidget *widget,
                                                                  guint      signal_id);
 
@@ -688,10 +714,17 @@ static void gtk_widget_set_device_enabled_internal (GtkWidget *widget,
                                                     gboolean   recurse,
                                                     gboolean   enabled);
 
+static void gtk_widget_on_frame_clock_update (GdkFrameClock *frame_clock,
+                                              GtkWidget     *widget);
+
+static gboolean event_window_is_still_viewable (GdkEvent *event);
+static void gtk_cairo_set_event (cairo_t        *cr,
+                                GdkEventExpose *event);
+static void gtk_widget_propagate_alpha (GtkWidget *widget);
+
 /* --- variables --- */
 static gpointer         gtk_widget_parent_class = NULL;
 static guint            widget_signals[LAST_SIGNAL] = { 0 };
-static GtkStyle        *gtk_default_style = NULL;
 static guint            composite_child_stack = 0;
 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
 static GParamSpecPool  *style_property_spec_pool = NULL;
@@ -707,7 +740,6 @@ static GQuark               quark_pointer_window = 0;
 static GQuark          quark_shape_info = 0;
 static GQuark          quark_input_shape_info = 0;
 static GQuark          quark_pango_context = 0;
-static GQuark          quark_rc_style = 0;
 static GQuark          quark_accessible_object = 0;
 static GQuark          quark_mnemonic_labels = 0;
 static GQuark          quark_tooltip_markup = 0;
@@ -731,7 +763,7 @@ gtk_widget_get_type (void)
       const GTypeInfo widget_info =
       {
        sizeof (GtkWidgetClass),
-       NULL,           /* base_init */
+       gtk_widget_base_class_init,
        (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
        (GClassInitFunc) gtk_widget_class_init,
        NULL,           /* class_finalize */
@@ -759,6 +791,8 @@ gtk_widget_get_type (void)
       widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
                                             &widget_info, G_TYPE_FLAG_ABSTRACT);
 
+      g_type_add_class_private (widget_type, sizeof (GtkWidgetClassPrivate));
+
       g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
                                    &accessibility_info) ;
       g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
@@ -768,6 +802,14 @@ gtk_widget_get_type (void)
   return widget_type;
 }
 
+static void
+gtk_widget_base_class_init (gpointer g_class)
+{
+  GtkWidgetClass *klass = g_class;
+
+  klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
+}
+
 static void
 child_property_notify_dispatcher (GObject     *object,
                                  guint        n_pspecs,
@@ -788,9 +830,24 @@ gtk_widget_draw_marshaller (GClosure     *closure,
                             gpointer      invocation_hint,
                             gpointer      marshal_data)
 {
+  GtkWidget *widget = g_value_get_object (&param_values[0]);
+  GdkEventExpose *tmp_event;
+  gboolean push_group;
   cairo_t *cr = g_value_get_boxed (&param_values[1]);
 
   cairo_save (cr);
+  tmp_event = _gtk_cairo_get_event (cr);
+
+  push_group =
+    widget->priv->opacity_group ||
+    (widget->priv->alpha != 255 &&
+     (!gtk_widget_get_has_window (widget) || tmp_event == NULL));
+
+  if (push_group)
+    {
+      cairo_push_group (cr);
+      gtk_cairo_set_event (cr, NULL);
+    }
 
   _gtk_marshal_BOOLEAN__BOXED (closure,
                                return_value,
@@ -799,7 +856,70 @@ gtk_widget_draw_marshaller (GClosure     *closure,
                                invocation_hint,
                                marshal_data);
 
+
+  if (push_group)
+    {
+      cairo_pop_group_to_source (cr);
+      cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+      cairo_paint_with_alpha (cr, widget->priv->alpha / 255.0);
+    }
+
+  gtk_cairo_set_event (cr, tmp_event);
+  cairo_restore (cr);
+}
+
+static void
+gtk_widget_draw_marshallerv (GClosure     *closure,
+                            GValue       *return_value,
+                            gpointer      instance,
+                            va_list       args,
+                            gpointer      marshal_data,
+                            int           n_params,
+                            GType        *param_types)
+{
+  GtkWidget *widget = GTK_WIDGET (instance);
+  GdkEventExpose *tmp_event;
+  gboolean push_group;
+  cairo_t *cr;
+  va_list args_copy;
+
+  G_VA_COPY (args_copy, args);
+  cr = va_arg (args_copy, gpointer);
+
+  cairo_save (cr);
+  tmp_event = _gtk_cairo_get_event (cr);
+
+  push_group =
+    widget->priv->opacity_group ||
+    (widget->priv->alpha != 255 &&
+     (!gtk_widget_get_has_window (widget) || tmp_event == NULL));
+
+  if (push_group)
+    {
+      cairo_push_group (cr);
+      gtk_cairo_set_event (cr, NULL);
+    }
+
+  _gtk_marshal_BOOLEAN__BOXEDv (closure,
+                               return_value,
+                               instance,
+                               args,
+                               marshal_data,
+                               n_params,
+                               param_types);
+
+
+  if (push_group)
+    {
+      cairo_pop_group_to_source (cr);
+      cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+      cairo_paint_with_alpha (cr, widget->priv->alpha / 255.0);
+    }
+
+  gtk_cairo_set_event (cr, tmp_event);
   cairo_restore (cr);
+
+  va_end (args_copy);
 }
 
 static void
@@ -822,7 +942,6 @@ gtk_widget_class_init (GtkWidgetClass *klass)
   quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
   quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
   quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
-  quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
   quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
   quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
   quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
@@ -839,6 +958,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
   cpn_context.dispatcher = child_property_notify_dispatcher;
   _gtk_widget_child_property_notify_context = &cpn_context;
 
+  gobject_class->constructed = gtk_widget_constructed;
   gobject_class->dispose = gtk_widget_dispose;
   gobject_class->finalize = gtk_widget_finalize;
   gobject_class->set_property = gtk_widget_set_property;
@@ -862,6 +982,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
   klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
   klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
   klass->state_changed = NULL;
+  klass->state_flags_changed = gtk_widget_real_state_flags_changed;
   klass->parent_set = NULL;
   klass->hierarchy_changed = NULL;
   klass->style_set = gtk_widget_real_style_set;
@@ -878,6 +999,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
   klass->button_press_event = NULL;
   klass->button_release_event = NULL;
   klass->motion_notify_event = NULL;
+  klass->touch_event = gtk_widget_real_touch_event;
   klass->delete_event = NULL;
   klass->destroy_event = NULL;
   klass->key_press_event = gtk_widget_real_key_press_event;
@@ -913,6 +1035,8 @@ gtk_widget_class_init (GtkWidgetClass *klass)
   klass->show_help = gtk_widget_real_show_help;
 
   /* Accessibility support */
+  klass->priv->accessible_type = GTK_TYPE_ACCESSIBLE;
+  klass->priv->accessible_role = ATK_ROLE_INVALID;
   klass->get_accessible = gtk_widget_real_get_accessible;
 
   klass->adjust_size_request = gtk_widget_real_adjust_size_request;
@@ -1125,7 +1249,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                                                        GTK_PARAM_READABLE));
 
   /**
-   * GtkWidget:double-buffered
+   * GtkWidget:double-buffered:
    *
    * Whether the widget is double buffered.
    *
@@ -1172,7 +1296,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                                                       GTK_PARAM_READWRITE));
 
   /**
-   * GtkWidget:margin-left
+   * GtkWidget:margin-left:
    *
    * Margin on left side of widget.
    *
@@ -1193,7 +1317,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                                                      GTK_PARAM_READWRITE));
 
   /**
-   * GtkWidget:margin-right
+   * GtkWidget:margin-right:
    *
    * Margin on right side of widget.
    *
@@ -1214,7 +1338,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                                                      GTK_PARAM_READWRITE));
 
   /**
-   * GtkWidget:margin-top
+   * GtkWidget:margin-top:
    *
    * Margin on top side of widget.
    *
@@ -1235,7 +1359,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                                                      GTK_PARAM_READWRITE));
 
   /**
-   * GtkWidget:margin-bottom
+   * GtkWidget:margin-bottom:
    *
    * Margin on bottom side of widget.
    *
@@ -1256,7 +1380,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                                                      GTK_PARAM_READWRITE));
 
   /**
-   * GtkWidget:margin
+   * GtkWidget:margin:
    *
    * Sets all four sides' margin at once. If read, returns max
    * margin on any side.
@@ -1291,7 +1415,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                   G_TYPE_NONE, 0);
 
   /**
-   * GtkWidget:hexpand
+   * GtkWidget:hexpand:
    *
    * Whether to expand horizontally. See gtk_widget_set_hexpand().
    *
@@ -1306,7 +1430,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                                                          GTK_PARAM_READWRITE));
 
   /**
-   * GtkWidget:hexpand-set
+   * GtkWidget:hexpand-set:
    *
    * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
    *
@@ -1321,7 +1445,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                                                          GTK_PARAM_READWRITE));
 
   /**
-   * GtkWidget:vexpand
+   * GtkWidget:vexpand:
    *
    * Whether to expand vertically. See gtk_widget_set_vexpand().
    *
@@ -1336,7 +1460,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                                                          GTK_PARAM_READWRITE));
 
   /**
-   * GtkWidget:vexpand-set
+   * GtkWidget:vexpand-set:
    *
    * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
    *
@@ -1351,7 +1475,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                                                          GTK_PARAM_READWRITE));
 
   /**
-   * GtkWidget:expand
+   * GtkWidget:expand:
    *
    * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
    *
@@ -1365,6 +1489,25 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                                                          FALSE,
                                                          GTK_PARAM_READWRITE));
 
+  /**
+   * GtkWidget:opacity:
+   *
+   * The requested opacity of the widget. See gtk_widget_set_opacity() for
+   * more details about window opacity.
+   *
+   * Before 3.8 this was only availible in GtkWindow
+   *
+   * Since: 3.8
+   */
+  g_object_class_install_property (gobject_class,
+                                  PROP_OPACITY,
+                                  g_param_spec_double ("opacity",
+                                                       P_("Opacity for Widget"),
+                                                       P_("The opacity of the widget, from 0 to 1"),
+                                                       0.0,
+                                                       1.0,
+                                                       1.0,
+                                                       GTK_PARAM_READWRITE));
   /**
    * GtkWidget::show:
    * @widget: the object which received the signal.
@@ -1630,7 +1773,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
   /**
    * GtkWidget::child-notify:
    * @widget: the object which received the signal
-   * @pspec: the #GParamSpec of the changed child property
+   * @child_property: the #GParamSpec of the changed child property
    *
    * The ::child-notify signal is emitted for each
    * <link linkend="child-properties">child property</link>  that has
@@ -1661,6 +1804,18 @@ gtk_widget_class_init (GtkWidgetClass *klass)
    * context passed as @cr in any way they like and don't need to
    * restore it. The signal emission takes care of calling cairo_save()
    * before and cairo_restore() after invoking the handler.
+   *
+   * The signal handler will get a @cr with a clip region already set to the
+   * widget's dirty region, i.e. to the area that needs repainting.  Complicated
+   * widgets that want to avoid redrawing themselves completely can get the full
+   * extents of the clip region with gdk_cairo_get_clip_rectangle(), or they can
+   * get a finer-grained representation of the dirty region with
+   * cairo_copy_clip_rectangle_list().
+   *
+   * Returns: %TRUE to stop other handlers from being invoked for the event.
+   % %FALSE to propagate the event further.
+   *
+   * Since: 3.0
    */
   widget_signals[DRAW] =
     g_signal_new (I_("draw"),
@@ -1671,11 +1826,16 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                    gtk_widget_draw_marshaller,
                   G_TYPE_BOOLEAN, 1,
                   CAIRO_GOBJECT_TYPE_CONTEXT);
+  g_signal_set_va_marshaller (widget_signals[DRAW], G_TYPE_FROM_CLASS (klass),
+                              gtk_widget_draw_marshallerv);
 
   /**
    * GtkWidget::mnemonic-activate:
    * @widget: the object which received the signal.
    * @arg1:
+   *
+   * Returns: %TRUE to stop other handlers from being invoked for the event.
+   * %FALSE to propagate the event further.
    */
   widget_signals[MNEMONIC_ACTIVATE] =
     g_signal_new (I_("mnemonic-activate"),
@@ -1783,6 +1943,8 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                  _gtk_marshal_BOOLEAN__BOXED,
                  G_TYPE_BOOLEAN, 1,
                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+  g_signal_set_va_marshaller (widget_signals[EVENT], G_TYPE_FROM_CLASS (klass),
+                              _gtk_marshal_BOOLEAN__BOXEDv);
 
   /**
    * GtkWidget::event-after:
@@ -1803,6 +1965,8 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                  _gtk_marshal_VOID__BOXED,
                  G_TYPE_NONE, 1,
                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+  g_signal_set_va_marshaller (widget_signals[EVENT_AFTER], G_TYPE_FROM_CLASS (klass),
+                              _gtk_marshal_BOOLEAN__BOXEDv);
 
   /**
    * GtkWidget::button-press-event:
@@ -1830,6 +1994,8 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                  _gtk_marshal_BOOLEAN__BOXED,
                  G_TYPE_BOOLEAN, 1,
                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+  g_signal_set_va_marshaller (widget_signals[BUTTON_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
+                              _gtk_marshal_BOOLEAN__BOXEDv);
 
   /**
    * GtkWidget::button-release-event:
@@ -1857,6 +2023,20 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                  _gtk_marshal_BOOLEAN__BOXED,
                  G_TYPE_BOOLEAN, 1,
                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+  g_signal_set_va_marshaller (widget_signals[BUTTON_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
+                              _gtk_marshal_BOOLEAN__BOXEDv);
+
+  widget_signals[TOUCH_EVENT] =
+    g_signal_new (I_("touch-event"),
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  G_STRUCT_OFFSET (GtkWidgetClass, touch_event),
+                  _gtk_boolean_handled_accumulator, NULL,
+                  _gtk_marshal_BOOLEAN__BOXED,
+                  G_TYPE_BOOLEAN, 1,
+                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+  g_signal_set_va_marshaller (widget_signals[TOUCH_EVENT], G_TYPE_FROM_CLASS (klass),
+                              _gtk_marshal_BOOLEAN__BOXEDv);
 
   /**
    * GtkWidget::scroll-event:
@@ -1869,7 +2049,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
    * button press events for buttons 4 and 5 when the wheel is turned.
    *
    * To receive this signal, the #GdkWindow associated to the widget needs
-   * to enable the #GDK_BUTTON_PRESS_MASK mask.
+   * to enable the #GDK_SCROLL_MASK mask.
    *
    * This signal will be sent to the grab widget if there is one.
    *
@@ -1885,6 +2065,8 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                  _gtk_marshal_BOOLEAN__BOXED,
                  G_TYPE_BOOLEAN, 1,
                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+  g_signal_set_va_marshaller (widget_signals[SCROLL_EVENT], G_TYPE_FROM_CLASS (klass),
+                              _gtk_marshal_BOOLEAN__BOXEDv);
 
   /**
    * GtkWidget::motion-notify-event:
@@ -1912,6 +2094,8 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                  _gtk_marshal_BOOLEAN__BOXED,
                  G_TYPE_BOOLEAN, 1,
                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+  g_signal_set_va_marshaller (widget_signals[MOTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
+                              _gtk_marshal_BOOLEAN__BOXEDv);
 
   /**
    * GtkWidget::composited-changed:
@@ -1953,6 +2137,8 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                  _gtk_marshal_BOOLEAN__BOXED,
                  G_TYPE_BOOLEAN, 1,
                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+  g_signal_set_va_marshaller (widget_signals[DELETE_EVENT], G_TYPE_FROM_CLASS (klass),
+                              _gtk_marshal_BOOLEAN__BOXEDv);
 
   /**
    * GtkWidget::destroy-event:
@@ -1980,6 +2166,8 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                  _gtk_marshal_BOOLEAN__BOXED,
                  G_TYPE_BOOLEAN, 1,
                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+  g_signal_set_va_marshaller (widget_signals[DESTROY_EVENT], G_TYPE_FROM_CLASS (klass),
+                              _gtk_marshal_BOOLEAN__BOXEDv);
 
   /**
    * GtkWidget::key-press-event:
@@ -2006,6 +2194,8 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                  _gtk_marshal_BOOLEAN__BOXED,
                  G_TYPE_BOOLEAN, 1,
                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+  g_signal_set_va_marshaller (widget_signals[KEY_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
+                              _gtk_marshal_BOOLEAN__BOXEDv);
 
   /**
    * GtkWidget::key-release-event:
@@ -2031,6 +2221,8 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                  _gtk_marshal_BOOLEAN__BOXED,
                  G_TYPE_BOOLEAN, 1,
                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+  g_signal_set_va_marshaller (widget_signals[KEY_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
+                              _gtk_marshal_BOOLEAN__BOXEDv);
 
   /**
    * GtkWidget::enter-notify-event:
@@ -2058,6 +2250,8 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                  _gtk_marshal_BOOLEAN__BOXED,
                  G_TYPE_BOOLEAN, 1,
                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+  g_signal_set_va_marshaller (widget_signals[ENTER_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
+                              _gtk_marshal_BOOLEAN__BOXEDv);
 
   /**
    * GtkWidget::leave-notify-event:
@@ -2085,6 +2279,8 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                  _gtk_marshal_BOOLEAN__BOXED,
                  G_TYPE_BOOLEAN, 1,
                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+  g_signal_set_va_marshaller (widget_signals[LEAVE_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
+                              _gtk_marshal_BOOLEAN__BOXEDv);
 
   /**
    * GtkWidget::configure-event:
@@ -2111,6 +2307,8 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                  _gtk_marshal_BOOLEAN__BOXED,
                  G_TYPE_BOOLEAN, 1,
                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+  g_signal_set_va_marshaller (widget_signals[CONFIGURE_EVENT], G_TYPE_FROM_CLASS (klass),
+                              _gtk_marshal_BOOLEAN__BOXEDv);
 
   /**
    * GtkWidget::focus-in-event:
@@ -2136,6 +2334,8 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                  _gtk_marshal_BOOLEAN__BOXED,
                  G_TYPE_BOOLEAN, 1,
                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+  g_signal_set_va_marshaller (widget_signals[FOCUS_IN_EVENT], G_TYPE_FROM_CLASS (klass),
+                              _gtk_marshal_BOOLEAN__BOXEDv);
 
   /**
    * GtkWidget::focus-out-event:
@@ -2161,6 +2361,8 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                  _gtk_marshal_BOOLEAN__BOXED,
                  G_TYPE_BOOLEAN, 1,
                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+  g_signal_set_va_marshaller (widget_signals[FOCUS_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
+                              _gtk_marshal_BOOLEAN__BOXEDv);
 
   /**
    * GtkWidget::map-event:
@@ -2186,6 +2388,8 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                  _gtk_marshal_BOOLEAN__BOXED,
                  G_TYPE_BOOLEAN, 1,
                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+  g_signal_set_va_marshaller (widget_signals[MAP_EVENT], G_TYPE_FROM_CLASS (klass),
+                              _gtk_marshal_BOOLEAN__BOXEDv);
 
   /**
    * GtkWidget::unmap-event:
@@ -2211,6 +2415,8 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                  _gtk_marshal_BOOLEAN__BOXED,
                  G_TYPE_BOOLEAN, 1,
                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+  g_signal_set_va_marshaller (widget_signals[UNMAP_EVENT], G_TYPE_FROM_CLASS (klass),
+                              _gtk_marshal_BOOLEAN__BOXEDv);
 
   /**
    * GtkWidget::property-notify-event:
@@ -2236,6 +2442,8 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                  _gtk_marshal_BOOLEAN__BOXED,
                  G_TYPE_BOOLEAN, 1,
                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+  g_signal_set_va_marshaller (widget_signals[PROPERTY_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
+                              _gtk_marshal_BOOLEAN__BOXEDv);
 
   /**
    * GtkWidget::selection-clear-event:
@@ -2258,6 +2466,8 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                  _gtk_marshal_BOOLEAN__BOXED,
                  G_TYPE_BOOLEAN, 1,
                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+  g_signal_set_va_marshaller (widget_signals[SELECTION_CLEAR_EVENT], G_TYPE_FROM_CLASS (klass),
+                              _gtk_marshal_BOOLEAN__BOXEDv);
 
   /**
    * GtkWidget::selection-request-event:
@@ -2281,6 +2491,8 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                  _gtk_marshal_BOOLEAN__BOXED,
                  G_TYPE_BOOLEAN, 1,
                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+  g_signal_set_va_marshaller (widget_signals[SELECTION_REQUEST_EVENT], G_TYPE_FROM_CLASS (klass),
+                              _gtk_marshal_BOOLEAN__BOXEDv);
 
   /**
    * GtkWidget::selection-notify-event:
@@ -2298,6 +2510,8 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                  _gtk_marshal_BOOLEAN__BOXED,
                  G_TYPE_BOOLEAN, 1,
                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+  g_signal_set_va_marshaller (widget_signals[SELECTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
+                              _gtk_marshal_BOOLEAN__BOXEDv);
 
   /**
    * GtkWidget::selection-received:
@@ -2358,6 +2572,8 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                  _gtk_marshal_BOOLEAN__BOXED,
                  G_TYPE_BOOLEAN, 1,
                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+  g_signal_set_va_marshaller (widget_signals[PROXIMITY_IN_EVENT], G_TYPE_FROM_CLASS (klass),
+                              _gtk_marshal_BOOLEAN__BOXEDv);
 
   /**
    * GtkWidget::proximity-out-event:
@@ -2382,11 +2598,13 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                  _gtk_marshal_BOOLEAN__BOXED,
                  G_TYPE_BOOLEAN, 1,
                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+  g_signal_set_va_marshaller (widget_signals[PROXIMITY_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
+                              _gtk_marshal_BOOLEAN__BOXEDv);
 
   /**
    * GtkWidget::drag-leave:
    * @widget: the object which received the signal.
-   * @drag_context: the drag context
+   * @context: the drag context
    * @time: the timestamp of the motion event
    *
    * The ::drag-leave signal is emitted on the drop site when the cursor
@@ -2408,11 +2626,11 @@ gtk_widget_class_init (GtkWidgetClass *klass)
   /**
    * GtkWidget::drag-begin:
    * @widget: the object which received the signal
-   * @drag_context: the drag context
+   * @context: the drag context
    *
    * The ::drag-begin signal is emitted on the drag source when a drag is
    * started. A typical reason to connect to this signal is to set up a
-   * custom drag icon with gtk_drag_source_set_icon().
+   * custom drag icon with e.g. gtk_drag_source_set_icon_pixbuf().
    *
    * Note that some widgets set up a drag icon in the default handler of
    * this signal, so you may have to use g_signal_connect_after() to
@@ -2431,7 +2649,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
   /**
    * GtkWidget::drag-end:
    * @widget: the object which received the signal
-   * @drag_context: the drag context
+   * @context: the drag context
    *
    * The ::drag-end signal is emitted on the drag source when a drag is
    * finished.  A typical reason to connect to this signal is to undo
@@ -2450,7 +2668,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
   /**
    * GtkWidget::drag-data-delete:
    * @widget: the object which received the signal
-   * @drag_context: the drag context
+   * @context: the drag context
    *
    * The ::drag-data-delete signal is emitted on the drag source when a drag
    * with the action %GDK_ACTION_MOVE is successfully completed. The signal
@@ -2470,7 +2688,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
   /**
    * GtkWidget::drag-failed:
    * @widget: the object which received the signal
-   * @drag_context: the drag context
+   * @context: the drag context
    * @result: the result of the drag operation
    *
    * The ::drag-failed signal is emitted on the drag source when a drag has
@@ -2497,13 +2715,12 @@ gtk_widget_class_init (GtkWidgetClass *klass)
   /**
    * GtkWidget::drag-motion:
    * @widget: the object which received the signal
-   * @drag_context: the drag context
+   * @context: the drag context
    * @x: the x coordinate of the current cursor position
    * @y: the y coordinate of the current cursor position
    * @time: the timestamp of the motion event
-   * @returns: whether the cursor position is in a drop zone
    *
-   * The drag-motion signal is emitted on the drop site when the user
+   * The ::drag-motion signal is emitted on the drop site when the user
    * moves the cursor over the widget during a drag. The signal handler
    * must determine whether the cursor position is in a drop zone or not.
    * If it is not in a drop zone, it returns %FALSE and no further processing
@@ -2526,11 +2743,11 @@ gtk_widget_class_init (GtkWidgetClass *klass)
    * the drop site with gtk_drag_highlight().
    * |[
    * static void
-   * drag_motion (GtkWidget *widget,
+   * drag_motion (GtkWidget      *widget,
    *              GdkDragContext *context,
-   *              gint x,
-   *              gint y,
-   *              guint time)
+   *              gint            x,
+   *              gint            y,
+   *              guint           time)
    * {
    *   GdkAtom target;
    *
@@ -2547,7 +2764,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
    *     gdk_drag_status (context, 0, time);
    *   else
    *    {
-   *      private_data->pending_status = context->suggested_action;
+   *      private_data->pending_status = gdk_drag_context_get_suggested_action (context);
    *      gtk_drag_get_data (widget, context, target, time);
    *    }
    *
@@ -2569,11 +2786,11 @@ gtk_widget_class_init (GtkWidgetClass *klass)
    *    {
    *      private_data->suggested_action = 0;
    *
-   *     /&ast; We are getting this data due to a request in drag_motion,
-   *      * rather than due to a request in drag_drop, so we are just
-   *      * supposed to call gdk_drag_status (), not actually paste in
-   *      * the data.
-   *      &ast;/
+   *      /&ast; We are getting this data due to a request in drag_motion,
+   *       * rather than due to a request in drag_drop, so we are just
+   *       * supposed to call gdk_drag_status(), not actually paste in
+   *       * the data.
+   *       &ast;/
    *      str = gtk_selection_data_get_text (selection_data);
    *      if (!data_is_acceptable (str))
    *        gdk_drag_status (context, 0, time);
@@ -2586,6 +2803,8 @@ gtk_widget_class_init (GtkWidgetClass *klass)
    *    }
    * }
    * ]|
+   *
+   * Returns: whether the cursor position is in a drop zone
    */
   widget_signals[DRAG_MOTION] =
     g_signal_new (I_("drag-motion"),
@@ -2603,11 +2822,10 @@ gtk_widget_class_init (GtkWidgetClass *klass)
   /**
    * GtkWidget::drag-drop:
    * @widget: the object which received the signal
-   * @drag_context: the drag context
+   * @context: the drag context
    * @x: the x coordinate of the current cursor position
    * @y: the y coordinate of the current cursor position
    * @time: the timestamp of the motion event
-   * @returns: whether the cursor position is in a drop zone
    *
    * The ::drag-drop signal is emitted on the drop site when the user drops
    * the data onto the widget. The signal handler must determine whether
@@ -2619,6 +2837,8 @@ gtk_widget_class_init (GtkWidgetClass *klass)
    * directly or in a #GtkWidget::drag-data-received handler which gets
    * triggered by calling gtk_drag_get_data() to receive the data for one
    * or more of the supported targets.
+   *
+   * Returns: whether the cursor position is in a drop zone
    */
   widget_signals[DRAG_DROP] =
     g_signal_new (I_("drag-drop"),
@@ -2636,7 +2856,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
   /**
    * GtkWidget::drag-data-get:
    * @widget: the object which received the signal
-   * @drag_context: the drag context
+   * @context: the drag context
    * @data: the #GtkSelectionData to be filled with the dragged data
    * @info: the info that has been registered with the target in the
    *        #GtkTargetList
@@ -2664,7 +2884,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
   /**
    * GtkWidget::drag-data-received:
    * @widget: the object which received the signal
-   * @drag_context: the drag context
+   * @context: the drag context
    * @x: where the drop happened
    * @y: where the drop happened
    * @data: the received data
@@ -2679,16 +2899,17 @@ gtk_widget_class_init (GtkWidgetClass *klass)
    * If the data was received in response to a #GtkWidget::drag-drop signal
    * (and this is the last target to be received), the handler for this
    * signal is expected to process the received data and then call
-   * gtk_drag_finish(), setting the @success parameter depending on whether
-   * the data was processed successfully.
+   * gtk_drag_finish(), setting the @success parameter depending on
+   * whether the data was processed successfully.
    *
-   * The handler may inspect and modify @drag_context->action before calling
-   * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
-   * following example:
+   * The handler may inspect the selected action with
+   * gdk_drag_context_get_selected_action() before calling
+   * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as
+   * shown in the following example:
    * |[
    * void
    * drag_data_received (GtkWidget          *widget,
-   *                     GdkDragContext     *drag_context,
+   *                     GdkDragContext     *context,
    *                     gint                x,
    *                     gint                y,
    *                     GtkSelectionData   *data,
@@ -2697,7 +2918,12 @@ gtk_widget_class_init (GtkWidgetClass *klass)
    * {
    *   if ((data->length >= 0) && (data->format == 8))
    *     {
-   *       if (drag_context->action == GDK_ACTION_ASK)
+   *       GdkDragAction action;
+   *
+   *       /&ast; handle data here &ast;/
+   *
+   *       action = gdk_drag_context_get_selected_action (context);
+   *       if (action == GDK_ACTION_ASK)
    *         {
    *           GtkWidget *dialog;
    *           gint response;
@@ -2712,16 +2938,15 @@ gtk_widget_class_init (GtkWidgetClass *klass)
    *           gtk_widget_destroy (dialog);
    *
    *           if (response == GTK_RESPONSE_YES)
-   *             drag_context->action = GDK_ACTION_MOVE;
+   *             action = GDK_ACTION_MOVE;
    *           else
-   *             drag_context->action = GDK_ACTION_COPY;
+   *             action = GDK_ACTION_COPY;
    *          }
    *
-   *       gtk_drag_finish (drag_context, TRUE, FALSE, time);
-   *       return;
+   *       gtk_drag_finish (context, TRUE, action == GDK_ACTION_MOVE, time);
    *     }
-   *
-   *    gtk_drag_finish (drag_context, FALSE, FALSE, time);
+   *   else
+   *     gtk_drag_finish (context, FALSE, FALSE, time);
    *  }
    * ]|
    */
@@ -2790,6 +3015,8 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                  _gtk_marshal_BOOLEAN__BOXED,
                  G_TYPE_BOOLEAN, 1,
                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+  g_signal_set_va_marshaller (widget_signals[WINDOW_STATE_EVENT], G_TYPE_FROM_CLASS (klass),
+                              _gtk_marshal_BOOLEAN__BOXEDv);
 
   /**
    * GtkWidget::damage-event:
@@ -2814,6 +3041,8 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                  _gtk_marshal_BOOLEAN__BOXED,
                  G_TYPE_BOOLEAN, 1,
                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+  g_signal_set_va_marshaller (widget_signals[DAMAGE_EVENT], G_TYPE_FROM_CLASS (klass),
+                              _gtk_marshal_BOOLEAN__BOXEDv);
 
 /**
    * GtkWidget::grab-broken-event:
@@ -2841,14 +3070,16 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                  _gtk_marshal_BOOLEAN__BOXED,
                  G_TYPE_BOOLEAN, 1,
                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+  g_signal_set_va_marshaller (widget_signals[GRAB_BROKEN_EVENT], G_TYPE_FROM_CLASS (klass),
+                              _gtk_marshal_BOOLEAN__BOXEDv);
 
   /**
    * GtkWidget::query-tooltip:
    * @widget: the object which received the signal
    * @x: the x coordinate of the cursor position where the request has
-   *     been emitted, relative to @widget->window
+   *     been emitted, relative to @widget's left side
    * @y: the y coordinate of the cursor position where the request has
-   *     been emitted, relative to @widget->window
+   *     been emitted, relative to @widget's top
    * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
    * @tooltip: a #GtkTooltip
    *
@@ -2883,7 +3114,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                  GTK_TYPE_TOOLTIP);
 
   /**
-   * GtkWidget::popup-menu
+   * GtkWidget::popup-menu:
    * @widget: the object which received the signal
    *
    * This signal gets emitted whenever a widget should pop up a context
@@ -2908,6 +3139,9 @@ gtk_widget_class_init (GtkWidgetClass *klass)
    * GtkWidget::show-help:
    * @widget: the object which received the signal.
    * @help_type:
+   *
+   * Returns: %TRUE to stop other handlers from being invoked for the event.
+   * %FALSE to propagate the event further.
    */
   widget_signals[SHOW_HELP] =
     g_signal_new (I_("show-help"),
@@ -3151,7 +3385,22 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                                                              1, G_MAXINT, 16,
                                                              GTK_PARAM_READABLE));
 
+  gtk_widget_class_install_style_property (klass,
+                                           g_param_spec_int ("text-handle-width",
+                                                             P_("Width of text selection handles"),
+                                                             P_("Width of text selection handles"),
+                                                             1, G_MAXINT, 16,
+                                                             GTK_PARAM_READABLE));
+  gtk_widget_class_install_style_property (klass,
+                                           g_param_spec_int ("text-handle-height",
+                                                             P_("Height of text selection handles"),
+                                                             P_("Height of text selection handles"),
+                                                             1, G_MAXINT, 20,
+                                                             GTK_PARAM_READABLE));
+
   g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
+
+  gtk_widget_class_set_accessible_type (klass, GTK_TYPE_WIDGET_ACCESSIBLE);
 }
 
 static void
@@ -3330,6 +3579,9 @@ gtk_widget_set_property (GObject         *object,
       gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
       g_object_thaw_notify (G_OBJECT (widget));
       break;
+    case PROP_OPACITY:
+      gtk_widget_set_opacity (widget, g_value_get_double (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -3455,7 +3707,7 @@ gtk_widget_get_property (GObject         *object,
       break;
     case PROP_MARGIN:
       {
-        GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
+        GtkWidgetAuxInfo *aux_info = gtk_widget_get_aux_info (widget, FALSE);
         if (aux_info == NULL)
           {
             g_value_set_int (value, 0);
@@ -3486,6 +3738,9 @@ gtk_widget_get_property (GObject         *object,
                            gtk_widget_get_hexpand (widget) &&
                            gtk_widget_get_vexpand (widget));
       break;
+    case PROP_OPACITY:
+      g_value_set_double (value, gtk_widget_get_opacity (widget));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -3508,6 +3763,8 @@ gtk_widget_init (GtkWidget *widget)
   priv->allocation.y = -1;
   priv->allocation.width = 1;
   priv->allocation.height = 1;
+  priv->user_alpha = 255;
+  priv->alpha = 255;
   priv->window = NULL;
   priv->parent = NULL;
 
@@ -3515,9 +3772,24 @@ gtk_widget_init (GtkWidget *widget)
   priv->composite_child = composite_child_stack != 0;
   priv->double_buffered = TRUE;
   priv->redraw_on_alloc = TRUE;
-  priv->width_request_needed = TRUE;
-  priv->height_request_needed = TRUE;
   priv->alloc_needed = TRUE;
+   
+  switch (gtk_widget_get_direction (widget))
+    {
+    case GTK_TEXT_DIR_LTR:
+      priv->state_flags = GTK_STATE_FLAG_DIR_LTR;
+      break;
+
+    case GTK_TEXT_DIR_RTL:
+      priv->state_flags = GTK_STATE_FLAG_DIR_RTL;
+      break;
+
+    case GTK_TEXT_DIR_NONE:
+    default:
+      g_assert_not_reached ();
+      break;
+    }
+
 
   /* this will be set to TRUE if the widget gets a child or if the
    * expand flag is set on the widget, but until one of those happen
@@ -3528,6 +3800,8 @@ gtk_widget_init (GtkWidget *widget)
    */
   priv->need_compute_expand = FALSE;
 
+  _gtk_size_request_cache_init (&priv->requests);
+
   priv->style = gtk_widget_get_default_style ();
   g_object_ref (priv->style);
 }
@@ -3580,37 +3854,17 @@ gtk_widget_freeze_child_notify (GtkWidget *widget)
  * on @widget.
  *
  * This is the analogue of g_object_notify() for child properties.
- **/
+ *
+ * Also see gtk_container_child_notify().
+ */
 void
 gtk_widget_child_notify (GtkWidget    *widget,
-                        const gchar  *child_property)
+                         const gchar  *child_property)
 {
-  GtkWidgetPrivate *priv = widget->priv;
-  GParamSpec *pspec;
-
-  g_return_if_fail (GTK_IS_WIDGET (widget));
-  g_return_if_fail (child_property != NULL);
-  if (!G_OBJECT (widget)->ref_count || !priv->parent)
+  if (widget->priv->parent == NULL)
     return;
 
-  g_object_ref (widget);
-  pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
-                                   child_property,
-                                   G_OBJECT_TYPE (priv->parent),
-                                   TRUE);
-  if (!pspec)
-    g_warning ("%s: container class `%s' has no child property named `%s'",
-              G_STRLOC,
-              G_OBJECT_TYPE_NAME (priv->parent),
-              child_property);
-  else
-    {
-      GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
-
-      g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
-      g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
-    }
-  g_object_unref (widget);
+  gtk_container_child_notify (GTK_CONTAINER (widget->priv->parent), widget, child_property);
 }
 
 /**
@@ -3646,8 +3900,8 @@ gtk_widget_thaw_child_notify (GtkWidget *widget)
  * gtk_widget_new:
  * @type: type ID of the widget to create
  * @first_property_name: name of first property to set
- * @Varargs: value of first property, followed by more properties,
- *           %NULL-terminated
+ * @...: value of first property, followed by more properties,
+ *     %NULL-terminated
  *
  * This is a convenience function for creating a widget and setting
  * its properties in one go. For example you might write:
@@ -3774,6 +4028,13 @@ gtk_widget_unparent (GtkWidget *widget)
       gtk_widget_queue_compute_expand (old_parent);
     }
 
+  /* Unset BACKDROP since we are no longer inside a toplevel window */
+  gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_BACKDROP);
+  if (priv->context)
+    gtk_style_context_set_parent (priv->context, NULL);
+
+  _gtk_widget_update_parent_muxer (widget);
+
   g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
   if (toplevel)
     {
@@ -3794,6 +4055,8 @@ gtk_widget_unparent (GtkWidget *widget)
     g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
   g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
 
+  gtk_widget_propagate_alpha (widget);
+
   gtk_widget_pop_verify_invariants (widget);
   g_object_unref (widget);
 }
@@ -4059,82 +4322,6 @@ gtk_widget_show_all (GtkWidget *widget)
     class->show_all (widget);
 }
 
-static void
-_gtk_widget_notify_state_change (GtkWidget     *widget,
-                                 GtkStateFlags  flag,
-                                 gboolean       target)
-{
-  GtkStateType state;
-
-  switch (flag)
-    {
-    case GTK_STATE_FLAG_ACTIVE:
-      state = GTK_STATE_ACTIVE;
-      break;
-    case GTK_STATE_FLAG_PRELIGHT:
-      state = GTK_STATE_PRELIGHT;
-      break;
-    case GTK_STATE_FLAG_SELECTED:
-      state = GTK_STATE_SELECTED;
-      break;
-    case GTK_STATE_FLAG_INSENSITIVE:
-      state = GTK_STATE_INSENSITIVE;
-      break;
-    case GTK_STATE_FLAG_INCONSISTENT:
-      state = GTK_STATE_INCONSISTENT;
-      break;
-    case GTK_STATE_FLAG_FOCUSED:
-      state = GTK_STATE_FOCUSED;
-      break;
-    default:
-      return;
-    }
-
-  gtk_style_context_notify_state_change (widget->priv->context,
-                                         gtk_widget_get_window (widget),
-                                         NULL, state, target);
-}
-
-/* Initializes state transitions for those states that
- * were enabled before mapping and have a looping animation.
- */
-static void
-_gtk_widget_start_state_transitions (GtkWidget *widget)
-{
-  GtkStateFlags state, flag;
-
-  if (!widget->priv->context)
-    return;
-
-  state = gtk_widget_get_state_flags (widget);
-  flag = GTK_STATE_FLAG_FOCUSED;
-
-  while (flag)
-    {
-      GtkAnimationDescription *animation_desc;
-
-      if ((state & flag) == 0)
-        {
-          flag >>= 1;
-          continue;
-        }
-
-      gtk_style_context_get (widget->priv->context, state,
-                             "transition", &animation_desc,
-                             NULL);
-
-      if (animation_desc)
-        {
-          if (_gtk_animation_description_get_loop (animation_desc))
-            _gtk_widget_notify_state_change (widget, flag, TRUE);
-
-          _gtk_animation_description_unref (animation_desc);
-        }
-
-      flag >>= 1;
-    }
-}
-
 /**
  * gtk_widget_map:
  * @widget: a #GtkWidget
@@ -4165,9 +4352,10 @@ gtk_widget_map (GtkWidget *widget)
       if (!gtk_widget_get_has_window (widget))
         gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
 
-      gtk_widget_pop_verify_invariants (widget);
+      if (widget->priv->context)
+        _gtk_style_context_update_animating (widget->priv->context);
 
-      _gtk_widget_start_state_transitions (widget);
+      gtk_widget_pop_verify_invariants (widget);
     }
 }
 
@@ -4194,13 +4382,14 @@ gtk_widget_unmap (GtkWidget *widget)
       if (!gtk_widget_get_has_window (widget))
        gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
       _gtk_tooltip_hide (widget);
+
+      if (widget->priv->context)
+        _gtk_style_context_update_animating (widget->priv->context);
+
       g_signal_emit (widget, widget_signals[UNMAP], 0);
 
       gtk_widget_pop_verify_invariants (widget);
 
-      if (priv->context)
-        gtk_style_context_cancel_animations (priv->context, NULL);
-
       /* Unset pointer/window info */
       g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
     }
@@ -4330,49 +4519,282 @@ gtk_widget_update_devices_mask (GtkWidget *widget,
     gtk_widget_set_device_enabled_internal (widget, GDK_DEVICE (l->data), recurse, TRUE);
 }
 
+typedef struct _GtkTickCallbackInfo GtkTickCallbackInfo;
+
+struct _GtkTickCallbackInfo
+{
+  guint refcount;
+
+  guint id;
+  GtkTickCallback callback;
+  gpointer user_data;
+  GDestroyNotify notify;
+
+  guint destroyed : 1;
+};
+
+static void
+ref_tick_callback_info (GtkTickCallbackInfo *info)
+{
+  info->refcount++;
+}
+
+static void
+unref_tick_callback_info (GtkWidget           *widget,
+                          GtkTickCallbackInfo *info,
+                          GList               *link)
+{
+  GtkWidgetPrivate *priv = widget->priv;
+
+  info->refcount--;
+  if (info->refcount == 0)
+    {
+      priv->tick_callbacks = g_list_delete_link (priv->tick_callbacks, link);
+      if (info->notify)
+        info->notify (info->user_data);
+      g_slice_free (GtkTickCallbackInfo, info);
+    }
+
+  if (priv->tick_callbacks == NULL && priv->realized)
+    {
+      GdkFrameClock *frame_clock = gtk_widget_get_frame_clock (widget);
+      g_signal_handlers_disconnect_by_func (frame_clock,
+                                            (gpointer) gtk_widget_on_frame_clock_update,
+                                            widget);
+      gdk_frame_clock_end_updating (frame_clock);
+    }
+}
+
+static void
+destroy_tick_callback_info (GtkWidget           *widget,
+                            GtkTickCallbackInfo *info,
+                            GList               *link)
+{
+  if (!info->destroyed)
+    {
+      info->destroyed = TRUE;
+      unref_tick_callback_info (widget, info, link);
+    }
+}
+
+static void
+gtk_widget_on_frame_clock_update (GdkFrameClock *frame_clock,
+                                  GtkWidget     *widget)
+{
+  GtkWidgetPrivate *priv = widget->priv;
+  GList *l;
+
+  g_object_ref (widget);
+
+  for (l = priv->tick_callbacks; l;)
+    {
+      GtkTickCallbackInfo *info = l->data;
+      GList *next;
+
+      ref_tick_callback_info (info);
+      if (!info->destroyed)
+        {
+          if (info->callback (widget,
+                              frame_clock,
+                              info->user_data) == G_SOURCE_REMOVE)
+            {
+              destroy_tick_callback_info (widget, info, l);
+            }
+        }
+
+      next = l->next;
+      unref_tick_callback_info (widget, info, l);
+      l = next;
+    }
+
+  g_object_unref (widget);
+}
+
+static guint tick_callback_id;
+
 /**
- * gtk_widget_realize:
+ * gtk_widget_add_tick_callback:
  * @widget: a #GtkWidget
+ * @callback: function to call for updating animations
+ * @user_data: data to pass to @callback
+ * @notify: function to call to free @user_data when the callback is removed.
  *
- * Creates the GDK (windowing system) resources associated with a
- * widget.  For example, @widget->window will be created when a widget
- * is realized.  Normally realization happens implicitly; if you show
- * a widget and all its parent containers, then the widget will be
- * realized and mapped automatically.
+ * Queues a animation frame update and adds a callback to be called
+ * before each frame. Until the tick callback is removed, it will be
+ * called frequently (usually at the frame rate of the output device
+ * or as quickly as the application an be repainted, whichever is
+ * slower). For this reason, is most suitable for handling graphics
+ * that change every frame or every few frames. The tick callback does
+ * not automatically imply a relayout or repaint. If you want a
+ * repaint or relayout, and aren't changing widget properties that
+ * would trigger that (for example, changing the text of a #GtkLabel),
+ * then you will have to call gtk_widget_queue_resize() or
+ * gtk_widget_queue_draw_area() yourself.
  *
- * Realizing a widget requires all
- * the widget's parent widgets to be realized; calling
- * gtk_widget_realize() realizes the widget's parents in addition to
- * @widget itself. If a widget is not yet inside a toplevel window
- * when you realize it, bad things will happen.
+ * gdk_frame_clock_get_frame_time() should generally be used for timing
+ * continuous animations and
+ * gdk_frame_timings_get_predicted_presentation_time() if you are
+ * trying to display isolated frames at particular times.
  *
- * This function is primarily used in widget implementations, and
- * isn't very useful otherwise. Many times when you think you might
- * need it, a better approach is to connect to a signal that will be
- * called after the widget is realized automatically, such as
- * #GtkWidget::draw. Or simply g_signal_connect () to the
- * #GtkWidget::realize signal.
- **/
-void
-gtk_widget_realize (GtkWidget *widget)
+ * This is a more convenient alternative to connecting directly to the
+ * #GdkFrameClock::update signal of #GdkFrameClock, since you don't
+ * have to worry about when a #GdkFrameClock is assigned to a widget.
+ *
+ * Returns: an id for the connection of this callback. Remove the callback
+ *     by passing it to gtk_widget_remove_tick_callback()
+ *
+ * Since: 3.8
+ */
+guint
+gtk_widget_add_tick_callback (GtkWidget       *widget,
+                              GtkTickCallback  callback,
+                              gpointer         user_data,
+                              GDestroyNotify   notify)
 {
   GtkWidgetPrivate *priv;
-  cairo_region_t *region;
+  GtkTickCallbackInfo *info;
 
-  g_return_if_fail (GTK_IS_WIDGET (widget));
-  g_return_if_fail (widget->priv->anchored ||
-                   GTK_IS_INVISIBLE (widget));
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
 
   priv = widget->priv;
 
-  if (!gtk_widget_get_realized (widget))
+  if (priv->tick_callbacks == NULL && priv->realized)
     {
-      gtk_widget_push_verify_invariants (widget);
+      GdkFrameClock *frame_clock = gtk_widget_get_frame_clock (widget);
+      g_signal_connect (frame_clock, "update",
+                        G_CALLBACK (gtk_widget_on_frame_clock_update),
+                        widget);
+      gdk_frame_clock_begin_updating (frame_clock);
+    }
 
-      /*
-       if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
-         g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
-      */
+  info = g_slice_new0 (GtkTickCallbackInfo);
+
+  info->refcount = 1;
+  info->id = ++tick_callback_id;
+  info->callback = callback;
+  info->user_data = user_data;
+  info->notify = notify;
+
+  priv->tick_callbacks = g_list_prepend (priv->tick_callbacks,
+                                         info);
+
+  return info->id;
+}
+
+/**
+ * gtk_widget_remove_tick_callback:
+ * @widget: a #GtkWidget
+ * @id: an id returned by gtk_widget_add_tick_callback()
+ *
+ * Removes a tick callback previously registered with
+ * gtk_widget_add_tick_callback().
+ *
+ * Since: 3.8
+ */
+void
+gtk_widget_remove_tick_callback (GtkWidget *widget,
+                                 guint      id)
+{
+  GtkWidgetPrivate *priv;
+  GList *l;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+
+  priv = widget->priv;
+
+  for (l = priv->tick_callbacks; l; l = l->next)
+    {
+      GtkTickCallbackInfo *info = l->data;
+      if (info->id == id)
+        destroy_tick_callback_info (widget, info, l);
+    }
+}
+
+static void
+gtk_widget_connect_frame_clock (GtkWidget     *widget,
+                                GdkFrameClock *frame_clock)
+{
+  GtkWidgetPrivate *priv = widget->priv;
+
+  if (GTK_IS_CONTAINER (widget))
+    _gtk_container_maybe_start_idle_sizer (GTK_CONTAINER (widget));
+
+  if (priv->tick_callbacks != NULL)
+    {
+      g_signal_connect (frame_clock, "update",
+                        G_CALLBACK (gtk_widget_on_frame_clock_update),
+                        widget);
+      gdk_frame_clock_begin_updating (frame_clock);
+    }
+
+  if (priv->context)
+    gtk_style_context_set_frame_clock (priv->context, frame_clock);
+}
+
+static void
+gtk_widget_disconnect_frame_clock (GtkWidget     *widget,
+                                   GdkFrameClock *frame_clock)
+{
+  GtkWidgetPrivate *priv = widget->priv;
+
+  if (GTK_IS_CONTAINER (widget))
+    _gtk_container_stop_idle_sizer (GTK_CONTAINER (widget));
+
+  if (priv->tick_callbacks)
+    {
+      g_signal_handlers_disconnect_by_func (frame_clock,
+                                            (gpointer) gtk_widget_on_frame_clock_update,
+                                            widget);
+      gdk_frame_clock_end_updating (frame_clock);
+    }
+
+  if (priv->context)
+    gtk_style_context_set_frame_clock (priv->context, NULL);
+}
+
+/**
+ * gtk_widget_realize:
+ * @widget: a #GtkWidget
+ *
+ * Creates the GDK (windowing system) resources associated with a
+ * widget.  For example, @widget->window will be created when a widget
+ * is realized.  Normally realization happens implicitly; if you show
+ * a widget and all its parent containers, then the widget will be
+ * realized and mapped automatically.
+ *
+ * Realizing a widget requires all
+ * the widget's parent widgets to be realized; calling
+ * gtk_widget_realize() realizes the widget's parents in addition to
+ * @widget itself. If a widget is not yet inside a toplevel window
+ * when you realize it, bad things will happen.
+ *
+ * This function is primarily used in widget implementations, and
+ * isn't very useful otherwise. Many times when you think you might
+ * need it, a better approach is to connect to a signal that will be
+ * called after the widget is realized automatically, such as
+ * #GtkWidget::draw. Or simply g_signal_connect () to the
+ * #GtkWidget::realize signal.
+ **/
+void
+gtk_widget_realize (GtkWidget *widget)
+{
+  GtkWidgetPrivate *priv;
+  cairo_region_t *region;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (widget->priv->anchored ||
+                   GTK_IS_INVISIBLE (widget));
+
+  priv = widget->priv;
+
+  if (!gtk_widget_get_realized (widget))
+    {
+      gtk_widget_push_verify_invariants (widget);
+
+      /*
+       if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
+         g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
+      */
 
       if (priv->parent == NULL &&
           !gtk_widget_is_toplevel (widget))
@@ -4410,6 +4832,9 @@ gtk_widget_realize (GtkWidget *widget)
       _gtk_widget_enable_device_events (widget);
       gtk_widget_update_devices_mask (widget, TRUE);
 
+      gtk_widget_connect_frame_clock (widget,
+                                      gtk_widget_get_frame_clock (widget));
+
       gtk_widget_pop_verify_invariants (widget);
     }
 }
@@ -4442,6 +4867,9 @@ gtk_widget_unrealize (GtkWidget *widget)
       if (widget->priv->mapped)
         gtk_widget_unmap (widget);
 
+      gtk_widget_disconnect_frame_clock (widget,
+                                         gtk_widget_get_frame_clock (widget));
+
       g_signal_emit (widget, widget_signals[UNREALIZE], 0);
       g_assert (!widget->priv->mapped);
       gtk_widget_set_realized (widget, FALSE);
@@ -4580,7 +5008,7 @@ gtk_widget_queue_resize (GtkWidget *widget)
   g_return_if_fail (GTK_IS_WIDGET (widget));
 
   if (gtk_widget_get_realized (widget))
-    gtk_widget_queue_shallow_draw (widget);
+    gtk_widget_queue_draw (widget);
 
   _gtk_size_group_queue_resize (widget, 0);
 }
@@ -4602,6 +5030,61 @@ gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
   _gtk_size_group_queue_resize (widget, 0);
 }
 
+/**
+ * gtk_widget_get_frame_clock:
+ * @widget: a #GtkWidget
+ *
+ * Obtains the frame clock for a widget. The frame clock is a global
+ * "ticker" that can be used to drive animations and repaints.  The
+ * most common reason to get the frame clock is to call
+ * gdk_frame_clock_get_frame_time(), in order to get a time to use for
+ * animating. For example you might record the start of the animation
+ * with an initial value from gdk_frame_clock_get_frame_time(), and
+ * then update the animation by calling
+ * gdk_frame_clock_get_frame_time() again during each repaint.
+ *
+ * gdk_frame_clock_request_phase() will result in a new frame on the
+ * clock, but won't necessarily repaint any widgets. To repaint a
+ * widget, you have to use gtk_widget_queue_draw() which invalidates
+ * the widget (thus scheduling it to receive a draw on the next
+ * frame). gtk_widget_queue_draw() will also end up requesting a frame
+ * on the appropriate frame clock.
+ *
+ * A widget's frame clock will not change while the widget is
+ * mapped. Reparenting a widget (which implies a temporary unmap) can
+ * change the widget's frame clock.
+ *
+ * Unrealized widgets do not have a frame clock.
+ *
+ * Return value: (transfer none): a #GdkFrameClock (or #NULL if widget is unrealized)
+ *
+ * Since: 3.0
+ */
+GdkFrameClock*
+gtk_widget_get_frame_clock (GtkWidget *widget)
+{
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
+
+  if (widget->priv->realized)
+    {
+      /* We use gtk_widget_get_toplevel() here to make it explicit that
+       * the frame clock is a property of the toplevel that a widget
+       * is anchored to; gdk_window_get_toplevel() will go up the
+       * hierarchy anyways, but should squash any funny business with
+       * reparenting windows and widgets.
+       */
+      GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
+      GdkWindow *window = gtk_widget_get_window (toplevel);
+      g_assert (window != NULL);
+
+      return gdk_window_get_frame_clock (window);
+    }
+  else
+    {
+      return NULL;
+    }
+}
+
 /**
  * gtk_widget_size_request:
  * @widget: a #GtkWidget
@@ -4702,29 +5185,6 @@ gtk_widget_invalidate_widget_windows (GtkWidget *widget,
                                       invalidate_predicate, widget);
 }
 
-/**
- * gtk_widget_queue_shallow_draw:
- * @widget: a #GtkWidget
- *
- * Like gtk_widget_queue_draw(), but only windows owned
- * by @widget are invalidated.
- **/
-static void
-gtk_widget_queue_shallow_draw (GtkWidget *widget)
-{
-  GdkRectangle rect;
-  cairo_region_t *region;
-
-  if (!gtk_widget_get_realized (widget))
-    return;
-
-  gtk_widget_get_allocation (widget, &rect);
-
-  region = cairo_region_create_rectangle (&rect);
-  gtk_widget_invalidate_widget_windows (widget, region);
-  cairo_region_destroy (region);
-}
-
 /**
  * gtk_widget_size_allocate:
  * @widget: a #GtkWidget
@@ -4757,6 +5217,9 @@ gtk_widget_size_allocate (GtkWidget       *widget,
 
   g_return_if_fail (GTK_IS_WIDGET (widget));
 
+  if (!priv->visible && !gtk_widget_is_toplevel (widget))
+    return;
+
   gtk_widget_push_verify_invariants (widget);
 
 #ifdef G_ENABLE_DEBUG
@@ -4782,9 +5245,8 @@ gtk_widget_size_allocate (GtkWidget       *widget,
 #endif /* G_ENABLE_DEBUG */
 
   alloc_needed = priv->alloc_needed;
-  if (!priv->width_request_needed && !priv->height_request_needed)
-    /* Preserve request/allocate ordering */
-    priv->alloc_needed = FALSE;
+  /* Preserve request/allocate ordering */
+  priv->alloc_needed = FALSE;
 
   old_allocation = priv->allocation;
   real_allocation = *allocation;
@@ -4797,7 +5259,7 @@ gtk_widget_size_allocate (GtkWidget       *widget,
        * when aligning implicitly.
        */
       gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
-      gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &dummy, &natural_height);
+      gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &min_height, &natural_height);
     }
   else
     {
@@ -4806,9 +5268,22 @@ gtk_widget_size_allocate (GtkWidget      *widget,
        * when aligning implicitly.
        */
       gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
-      gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &dummy, &natural_width);
+      gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &min_width, &natural_width);
     }
 
+#ifdef G_ENABLE_DEBUG
+  if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
+    {
+      if ((min_width > real_allocation.width || min_height > real_allocation.height) &&
+          !GTK_IS_SCROLLABLE (widget))
+        g_warning ("gtk_widget_size_allocate(): attempt to underallocate %s%s %s %p. "
+                   "Allocation is %dx%d, but minimum required size is %dx%d.",
+                   priv->parent ? G_OBJECT_TYPE_NAME (priv->parent) : "", priv->parent ? "'s child" : "toplevel",
+                   G_OBJECT_TYPE_NAME (widget), widget,
+                   real_allocation.width, real_allocation.height,
+                   min_width, min_height);
+    }
+#endif
   /* Now that we have the right natural height and width, go ahead and remove any margins from the
    * allocated sizes and possibly limit them to the natural sizes */
   GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
@@ -4863,9 +5338,7 @@ gtk_widget_size_allocate (GtkWidget       *widget,
   g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
 
   /* Size allocation is god... after consulting god, no further requests or allocations are needed */
-  priv->width_request_needed  = FALSE;
-  priv->height_request_needed = FALSE;
-  priv->alloc_needed          = FALSE;
+  priv->alloc_needed = FALSE;
 
   if (gtk_widget_get_mapped (widget))
     {
@@ -4893,14 +5366,6 @@ gtk_widget_size_allocate (GtkWidget      *widget,
              cairo_region_destroy (invalidate);
            }
        }
-
-      if (size_changed || position_changed)
-        {
-          GtkStyleContext *context;
-
-          context = gtk_widget_get_style_context (widget);
-          _gtk_style_context_invalidate_animation_areas (context);
-        }
     }
 
   if ((size_changed || position_changed) && priv->parent &&
@@ -5315,7 +5780,7 @@ widget_new_accel_closure (GtkWidget *widget,
 }
 
 /**
- * gtk_widget_add_accelerator
+ * gtk_widget_add_accelerator:
  * @widget:       widget to install an accelerator on
  * @accel_signal: widget signal to emit on accelerator activation
  * @accel_group:  accel group for this widget, added to its toplevel
@@ -5326,7 +5791,7 @@ widget_new_accel_closure (GtkWidget *widget,
  * Installs an accelerator for this @widget in @accel_group that causes
  * @accel_signal to be emitted if the accelerator is activated.
  * The @accel_group needs to be added to the widget's toplevel via
- * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
+ * gtk_window_add_accel_group(), and the signal must be of type %G_SIGNAL_ACTION.
  * Accelerators added through this function are not user changeable during
  * runtime. If you want to support accelerators that can be changed by the
  * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
@@ -5383,10 +5848,11 @@ gtk_widget_add_accelerator (GtkWidget      *widget,
  * @accel_group:  accel group for this widget
  * @accel_key:    GDK keyval of the accelerator
  * @accel_mods:   modifier key combination of the accelerator
- * @returns:      whether an accelerator was installed and could be removed
  *
  * Removes an accelerator from @widget, previously installed with
  * gtk_widget_add_accelerator().
+ *
+ * Returns: whether an accelerator was installed and could be removed
  */
 gboolean
 gtk_widget_remove_accelerator (GtkWidget      *widget,
@@ -5621,7 +6087,8 @@ gtk_cairo_set_event (cairo_t        *cr,
 /**
  * gtk_cairo_should_draw_window:
  * @cr: a cairo context
- * @window: the window to check
+ * @window: the window to check. @window may not be an input-only
+ *          window.
  *
  * This function is supposed to be called in #GtkWidget::draw
  * implementations for widgets that support multiple windows.
@@ -5652,6 +6119,20 @@ gtk_cairo_should_draw_window (cairo_t *cr,
          event->window == window;
 }
 
+static gboolean
+gtk_widget_get_clip_draw (GtkWidget *widget)
+{
+  /* labels are not clipped, because clipping them would cause
+   * mnemonics to not appear on characters that go beyond the
+   * baseline.
+   * https://bugzilla.gnome.org/show_bug.cgi?id=648570
+   */
+  if (GTK_IS_LABEL (widget))
+    return FALSE;
+
+  return TRUE;
+}
+
 /* code shared by gtk_container_propagate_draw() and
  * gtk_widget_draw()
  */
@@ -5660,11 +6141,11 @@ _gtk_widget_draw_internal (GtkWidget *widget,
                            cairo_t   *cr,
                            gboolean   clip_to_size)
 {
-  GtkStyleContext *context;
-
   if (!gtk_widget_is_drawable (widget))
     return;
 
+  clip_to_size &= gtk_widget_get_clip_draw (widget);
+
   if (clip_to_size)
     {
       cairo_rectangle (cr,
@@ -5681,10 +6162,20 @@ _gtk_widget_draw_internal (GtkWidget *widget,
       g_signal_emit (widget, widget_signals[DRAW],
                      0, cr,
                      &result);
-    }
 
-  context = gtk_widget_get_style_context (widget);
-  _gtk_style_context_coalesce_animation_areas (context, widget);
+      if (cairo_status (cr) &&
+          _gtk_cairo_get_event (cr))
+        {
+          /* We check the event so we only warn about internal GTK calls.
+           * Errors might come from PDF streams having write failures and
+           * we don't want to spam stderr in that case.
+           * We do want to catch errors from
+           */
+          g_warning ("drawing failure for widget `%s': %s",
+                     G_OBJECT_TYPE_NAME (widget),
+                     cairo_status_to_string (cairo_status (cr)));
+        }
+    }
 }
 
 /**
@@ -5755,7 +6246,7 @@ static gboolean
 gtk_widget_real_focus_in_event (GtkWidget     *widget,
                                 GdkEventFocus *event)
 {
-  gtk_widget_queue_shallow_draw (widget);
+  gtk_widget_queue_draw (widget);
 
   return FALSE;
 }
@@ -5764,11 +6255,81 @@ static gboolean
 gtk_widget_real_focus_out_event (GtkWidget     *widget,
                                  GdkEventFocus *event)
 {
-  gtk_widget_queue_shallow_draw (widget);
+  gtk_widget_queue_draw (widget);
 
   return FALSE;
 }
 
+static gboolean
+gtk_widget_real_touch_event (GtkWidget     *widget,
+                             GdkEventTouch *event)
+{
+  GdkEvent *bevent;
+  gboolean return_val;
+  gint signum;
+
+  if (!event->emulating_pointer)
+    return FALSE;
+
+  if (event->type == GDK_TOUCH_BEGIN ||
+      event->type == GDK_TOUCH_END)
+    {
+      GdkEventType type;
+
+      if (event->type == GDK_TOUCH_BEGIN)
+        {
+          type = GDK_BUTTON_PRESS;
+          signum = BUTTON_PRESS_EVENT;
+        }
+      else
+        {
+          type = GDK_BUTTON_RELEASE;
+          signum = BUTTON_RELEASE_EVENT;
+        }
+      bevent = gdk_event_new (type);
+      bevent->any.window = g_object_ref (event->window);
+      bevent->any.send_event = FALSE;
+      bevent->button.time = event->time;
+      bevent->button.state = event->state;
+      bevent->button.button = 1;
+      bevent->button.x_root = event->x_root;
+      bevent->button.y_root = event->y_root;
+      bevent->button.x = event->x;
+      bevent->button.y = event->y;
+      bevent->button.device = event->device;
+      bevent->button.axes = g_memdup (event->axes,
+                                      sizeof (gdouble) * gdk_device_get_n_axes (event->device));
+      gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
+    }
+  else if (event->type == GDK_TOUCH_UPDATE)
+    {
+      signum = MOTION_NOTIFY_EVENT;
+      bevent = gdk_event_new (GDK_MOTION_NOTIFY);
+      bevent->any.window = g_object_ref (event->window);
+      bevent->any.send_event = FALSE;
+      bevent->motion.time = event->time;
+      bevent->motion.state = event->state;
+      bevent->motion.x_root = event->x_root;
+      bevent->motion.y_root = event->y_root;
+      bevent->motion.x = event->x;
+      bevent->motion.y = event->y;
+      bevent->motion.device = event->device;
+      bevent->motion.is_hint = FALSE;
+      bevent->motion.axes = g_memdup (event->axes,
+                                      sizeof (gdouble) * gdk_device_get_n_axes (event->device));
+      gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
+    }
+  else
+    return FALSE;
+
+  g_signal_emit (widget, widget_signals[signum], 0, bevent, &return_val);
+
+  gdk_event_free (bevent);
+
+  return return_val;
+}
+
+
 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
      (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
 
@@ -5807,6 +6368,59 @@ gtk_widget_event (GtkWidget *widget,
   return gtk_widget_event_internal (widget, event);
 }
 
+void
+_gtk_widget_set_captured_event_handler (GtkWidget               *widget,
+                                        GtkCapturedEventHandler  callback)
+{
+  g_object_set_data (G_OBJECT (widget), "captured-event-handler", callback);
+}
+
+gboolean
+_gtk_widget_captured_event (GtkWidget *widget,
+                            GdkEvent  *event)
+{
+  gboolean return_val = FALSE;
+  GtkCapturedEventHandler handler;
+
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
+  g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
+
+  if (event->type == GDK_EXPOSE)
+    {
+      g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
+                "the same effect, call gdk_window_invalidate_rect/region(), "
+                "followed by gdk_window_process_updates().");
+      return TRUE;
+    }
+
+  if (!event_window_is_still_viewable (event))
+    return TRUE;
+
+  handler = g_object_get_data (G_OBJECT (widget), "captured-event-handler");
+  if (!handler)
+    return FALSE;
+
+  g_object_ref (widget);
+
+  return_val = handler (widget, event);
+  return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
+
+  /* The widget that was originally to receive the event
+   * handles motion hints, but the capturing widget might
+   * not, so ensure we get further motion events.
+   */
+  if (return_val &&
+      event->type == GDK_MOTION_NOTIFY &&
+      event->motion.is_hint &&
+      (gdk_window_get_events (event->any.window) &
+       GDK_POINTER_MOTION_HINT_MASK) != 0)
+    gdk_event_request_motions (&event->motion);
+
+  g_object_unref (widget);
+
+  return return_val;
+}
+
 /* Returns TRUE if a translation should be done */
 gboolean
 _gtk_widget_get_translation_to_window (GtkWidget      *widget,
@@ -6007,6 +6621,12 @@ gtk_widget_event_internal (GtkWidget *widget,
        case GDK_2BUTTON_PRESS:
        case GDK_3BUTTON_PRESS:
          signal_num = BUTTON_PRESS_EVENT;
+          break;
+        case GDK_TOUCH_BEGIN:
+        case GDK_TOUCH_UPDATE:
+        case GDK_TOUCH_END:
+        case GDK_TOUCH_CANCEL:
+         signal_num = TOUCH_EVENT;
          break;
        case GDK_SCROLL:
          signal_num = SCROLL_EVENT;
@@ -6302,16 +6922,16 @@ gtk_widget_intersect (GtkWidget          *widget,
  *          @widget->allocation. That is, relative to @widget->window
  *          for %NO_WINDOW widgets; relative to the parent window
  *          of @widget->window for widgets with their own window.
- * @returns: A newly allocated region holding the intersection of @widget
- *           and @region. The coordinates of the return value are
- *           relative to @widget->window for %NO_WINDOW widgets, and
- *           relative to the parent window of @widget->window for
- *           widgets with their own window.
  *
  * Computes the intersection of a @widget's area and @region, returning
  * the intersection. The result may be empty, use cairo_region_is_empty() to
  * check.
- **/
+ *
+ * Returns: A newly allocated region holding the intersection of @widget
+ *     and @region. The coordinates of the return value are relative to
+ *     @widget->window for %NO_WINDOW widgets, and relative to the parent
+ *     window of @widget->window for widgets with their own window.
+ */
 cairo_region_t *
 gtk_widget_region_intersect (GtkWidget       *widget,
                             const cairo_region_t *region)
@@ -6424,10 +7044,15 @@ gtk_widget_real_grab_focus (GtkWidget *focus_widget)
 
          if (widget)
            {
-             while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
+             GtkWidget *common_ancestor = gtk_widget_common_ancestor (widget, focus_widget);
+
+             if (widget != common_ancestor)
                {
-                 widget = widget->priv->parent;
-                 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
+                 while (widget->priv->parent && widget->priv->parent != common_ancestor)
+                   {
+                     widget = widget->priv->parent;
+                     gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
+                   }
                }
            }
        }
@@ -6478,11 +7103,21 @@ gtk_widget_real_query_tooltip (GtkWidget  *widget,
   return FALSE;
 }
 
+static void
+gtk_widget_real_state_flags_changed (GtkWidget     *widget,
+                                     GtkStateFlags  old_state)
+{
+  gtk_widget_update_pango_context (widget);
+}
+
 static void
 gtk_widget_real_style_updated (GtkWidget *widget)
 {
   GtkWidgetPrivate *priv = widget->priv;
 
+  gtk_widget_update_pango_context (widget);
+  gtk_widget_update_alpha (widget);
+
   if (priv->style != NULL &&
       priv->style != gtk_widget_get_default_style ())
     {
@@ -6497,14 +7132,27 @@ gtk_widget_real_style_updated (GtkWidget *widget)
 
   if (widget->priv->context)
     {
+      const GtkBitmask *changes = _gtk_style_context_get_changes (widget->priv->context);
+
       if (gtk_widget_get_realized (widget) &&
-          gtk_widget_get_has_window (widget))
+          gtk_widget_get_has_window (widget) &&
+          !gtk_widget_get_app_paintable (widget))
         gtk_style_context_set_background (widget->priv->context,
                                           widget->priv->window);
-    }
 
-  if (widget->priv->anchored)
-    gtk_widget_queue_resize (widget);
+      if (widget->priv->anchored)
+        {
+          if (changes && _gtk_css_style_property_changes_affect_size (changes))
+            gtk_widget_queue_resize (widget);
+          else
+            gtk_widget_queue_draw (widget);
+        }
+    }
+  else
+    {
+      if (widget->priv->anchored)
+        gtk_widget_queue_resize (widget);
+    }
 }
 
 static gboolean
@@ -6645,24 +7293,66 @@ gtk_widget_has_focus (GtkWidget *widget)
 }
 
 /**
- * gtk_widget_is_focus:
+ * gtk_widget_has_visible_focus:
  * @widget: a #GtkWidget
  *
- * Determines if the widget is the focus widget within its
- * toplevel. (This does not mean that the %HAS_FOCUS flag is
- * necessarily set; %HAS_FOCUS will only be set if the
- * toplevel widget additionally has the global input focus.)
+ * Determines if the widget should show a visible indication that
+ * it has the global input focus. This is a convenience function for
+ * use in ::draw handlers that takes into account whether focus
+ * indication should currently be shown in the toplevel window of
+ * @widget. See gtk_window_get_focus_visible() for more information
+ * about focus indication.
  *
- * Return value: %TRUE if the widget is the focus widget.
- **/
+ * To find out if the widget has the global input focus, use
+ * gtk_widget_has_focus().
+ *
+ * Return value: %TRUE if the widget should display a 'focus rectangle'
+ *
+ * Since: 3.2
+ */
 gboolean
-gtk_widget_is_focus (GtkWidget *widget)
+gtk_widget_has_visible_focus (GtkWidget *widget)
 {
-  GtkWidget *toplevel;
+  gboolean draw_focus;
 
   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
 
-  toplevel = gtk_widget_get_toplevel (widget);
+  if (widget->priv->has_focus)
+    {
+      GtkWidget *toplevel;
+
+      toplevel = gtk_widget_get_toplevel (widget);
+
+      if (GTK_IS_WINDOW (toplevel))
+        draw_focus = gtk_window_get_focus_visible (GTK_WINDOW (toplevel));
+      else
+        draw_focus = TRUE;
+    }
+  else
+    draw_focus = FALSE;
+
+  return draw_focus;
+}
+
+/**
+ * gtk_widget_is_focus:
+ * @widget: a #GtkWidget
+ *
+ * Determines if the widget is the focus widget within its
+ * toplevel. (This does not mean that the %HAS_FOCUS flag is
+ * necessarily set; %HAS_FOCUS will only be set if the
+ * toplevel widget additionally has the global input focus.)
+ *
+ * Return value: %TRUE if the widget is the focus widget.
+ **/
+gboolean
+gtk_widget_is_focus (GtkWidget *widget)
+{
+  GtkWidget *toplevel;
+
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
+
+  toplevel = gtk_widget_get_toplevel (widget);
 
   if (GTK_IS_WINDOW (toplevel))
     return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
@@ -6739,17 +7429,26 @@ void
 _gtk_widget_set_has_default (GtkWidget *widget,
                              gboolean   has_default)
 {
+  GtkStyleContext *context;
+
   widget->priv->has_default = has_default;
+
+  context = gtk_widget_get_style_context (widget);
+
+  if (has_default)
+    gtk_style_context_add_class (context, GTK_STYLE_CLASS_DEFAULT);
+  else
+    gtk_style_context_remove_class (context, GTK_STYLE_CLASS_DEFAULT);
 }
 
 /**
  * gtk_widget_grab_default:
  * @widget: a #GtkWidget
  *
- * Causes @widget to become the default widget. @widget must have the
- * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
- * yourself by calling <literal>gtk_widget_set_can_default (@widget,
- * %TRUE)</literal>. The default widget is activated when
+ * Causes @widget to become the default widget. @widget must be able to be
+ * a default widget; typically you would ensure this yourself
+ * by calling gtk_widget_set_can_default() with a %TRUE value.
+ * The default widget is activated when
  * the user presses Enter in a window. Default widgets must be
  * activatable, that is, gtk_widget_activate() should affect them. Note
  * that #GtkEntry widgets require the "activates-default" property
@@ -6804,13 +7503,13 @@ gtk_widget_set_receives_default (GtkWidget *widget,
  * gtk_widget_get_receives_default:
  * @widget: a #GtkWidget
  *
- * Determines whether @widget is alyways treated as default widget
- * withing its toplevel when it has the focus, even if another widget
+ * Determines whether @widget is always treated as the default widget
+ * within its toplevel when it has the focus, even if another widget
  * is the default.
  *
  * See gtk_widget_set_receives_default().
  *
- * Return value: %TRUE if @widget acts as default widget when focussed,
+ * Return value: %TRUE if @widget acts as the default widget when focussed,
  *               %FALSE otherwise
  *
  * Since: 2.18
@@ -6934,7 +7633,7 @@ gtk_widget_set_name (GtkWidget     *widget,
   g_free (priv->name);
   priv->name = new_name;
 
-  gtk_widget_reset_style (widget);
+  _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_NAME);
 
   g_object_notify (G_OBJECT (widget), "name");
 }
@@ -6949,7 +7648,7 @@ gtk_widget_set_name (GtkWidget     *widget,
  * Return value: name of the widget. This string is owned by GTK+ and
  * should not be modified or freed
  **/
-G_CONST_RETURN gchar*
+const gchar*
 gtk_widget_get_name (GtkWidget *widget)
 {
   GtkWidgetPrivate *priv;
@@ -6964,9 +7663,9 @@ gtk_widget_get_name (GtkWidget *widget)
 }
 
 static void
-_gtk_widget_update_state_flags (GtkWidget     *widget,
-                                GtkStateFlags  flags,
-                                guint          operation)
+gtk_widget_update_state_flags (GtkWidget     *widget,
+                               GtkStateFlags  flags_to_set,
+                               GtkStateFlags  flags_to_unset)
 {
   GtkWidgetPrivate *priv;
 
@@ -6975,28 +7674,22 @@ _gtk_widget_update_state_flags (GtkWidget     *widget,
   /* Handle insensitive first, since it is propagated
    * differently throughout the widget hierarchy.
    */
-  if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_UNSET))
+  if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags_to_unset & GTK_STATE_FLAG_INSENSITIVE))
     gtk_widget_set_sensitive (widget, TRUE);
-  else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation != STATE_CHANGE_UNSET))
+  else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags_to_set & GTK_STATE_FLAG_INSENSITIVE))
     gtk_widget_set_sensitive (widget, FALSE);
-  else if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && !(flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_REPLACE))
-    gtk_widget_set_sensitive (widget, TRUE);
 
-  if (operation != STATE_CHANGE_REPLACE)
-    flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
+  flags_to_set &= ~(GTK_STATE_FLAG_INSENSITIVE);
+  flags_to_unset &= ~(GTK_STATE_FLAG_INSENSITIVE);
 
-  if (flags != 0 ||
-      operation == STATE_CHANGE_REPLACE)
+  if (flags_to_set != 0 || flags_to_unset != 0)
     {
       GtkStateData data;
 
-      data.flags = flags;
-      data.operation = operation;
-      data.use_forall = FALSE;
+      data.flags_to_set = flags_to_set;
+      data.flags_to_unset = flags_to_unset;
 
       gtk_widget_propagate_state (widget, &data);
-
-      gtk_widget_queue_resize (widget);
     }
 }
 
@@ -7030,9 +7723,9 @@ gtk_widget_set_state_flags (GtkWidget     *widget,
     return;
 
   if (clear)
-    _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
+    gtk_widget_update_state_flags (widget, flags, ~(flags ^ (GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL)));
   else
-    _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_SET);
+    gtk_widget_update_state_flags (widget, flags, 0);
 }
 
 /**
@@ -7055,7 +7748,7 @@ gtk_widget_unset_state_flags (GtkWidget     *widget,
   if ((widget->priv->state_flags & flags) == 0)
     return;
 
-  _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_UNSET);
+  gtk_widget_update_state_flags (widget, 0, flags);
 }
 
 /**
@@ -7132,7 +7825,10 @@ gtk_widget_set_state (GtkWidget           *widget,
       break;
     }
 
-  _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
+  gtk_widget_update_state_flags (widget,
+                                 flags,
+                                 (GTK_STATE_FLAG_ACTIVE | GTK_STATE_FLAG_PRELIGHT | GTK_STATE_FLAG_SELECTED
+                                 | GTK_STATE_FLAG_INSENSITIVE | GTK_STATE_FLAG_INCONSISTENT | GTK_STATE_FLAG_FOCUSED) ^ flags);
 }
 
 /**
@@ -7202,16 +7898,28 @@ void
 _gtk_widget_set_visible_flag (GtkWidget *widget,
                               gboolean   visible)
 {
-  widget->priv->visible = visible;
+  GtkWidgetPrivate *priv = widget->priv;
+
+  priv->visible = visible;
+
+  if (!visible)
+    {
+      priv->allocation.x = -1;
+      priv->allocation.y = -1;
+      priv->allocation.width = 1;
+      priv->allocation.height = 1;
+    }
 }
 
 /**
  * gtk_widget_get_visible:
  * @widget: a #GtkWidget
  *
- * Determines whether the widget is visible. Note that this doesn't
- * take into account whether the widget's parent is also visible
- * or the widget is obscured in any way.
+ * Determines whether the widget is visible. If you want to
+ * take into account whether the widget's parent is also marked as
+ * visible, use gtk_widget_is_visible() instead.
+ *
+ * This function does not check if the widget is obscured in any way.
  *
  * See gtk_widget_set_visible().
  *
@@ -7227,6 +7935,39 @@ gtk_widget_get_visible (GtkWidget *widget)
   return widget->priv->visible;
 }
 
+/**
+ * gtk_widget_is_visible:
+ * @widget: a #GtkWidget
+ *
+ * Determines whether the widget and all its parents are marked as
+ * visible.
+ *
+ * This function does not check if the widget is obscured in any way.
+ *
+ * See also gtk_widget_get_visible() and gtk_widget_set_visible()
+ *
+ * Return value: %TRUE if the widget and all its parents are visible
+ *
+ * Since: 3.8
+ **/
+gboolean
+gtk_widget_is_visible (GtkWidget *widget)
+{
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
+
+  while (widget)
+    {
+      GtkWidgetPrivate *priv = widget->priv;
+
+      if (!priv->visible)
+        return FALSE;
+
+      widget = priv->parent;
+    }
+
+  return TRUE;
+}
+
 /**
  * gtk_widget_set_has_window:
  * @widget: a #GtkWidget
@@ -7466,7 +8207,7 @@ gtk_widget_get_app_paintable (GtkWidget *widget)
  * to turn off the buffering. "Double buffered" simply means that
  * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
  * automatically around expose events sent to the
- * widget. gdk_window_begin_paint() diverts all drawing to a widget's
+ * widget. gdk_window_begin_paint_region() diverts all drawing to a widget's
  * window to an offscreen buffer, and gdk_window_end_paint() draws the
  * buffer to the screen. The result is that users see the window
  * update in one smooth step, and don't see individual graphics
@@ -7479,7 +8220,7 @@ gtk_widget_get_app_paintable (GtkWidget *widget)
  * Note: if you turn off double-buffering, you have to handle
  * expose events, since even the clearing to the background color or
  * pixmap will not happen automatically (as it is done in
- * gdk_window_begin_paint()).
+ * gdk_window_begin_paint_region()).
  **/
 void
 gtk_widget_set_double_buffered (GtkWidget *widget,
@@ -7563,7 +8304,6 @@ gtk_widget_set_sensitive (GtkWidget *widget,
                          gboolean   sensitive)
 {
   GtkWidgetPrivate *priv;
-  GtkStateData data;
 
   g_return_if_fail (GTK_IS_WIDGET (widget));
 
@@ -7571,27 +8311,31 @@ gtk_widget_set_sensitive (GtkWidget *widget,
 
   sensitive = (sensitive != FALSE);
 
-  if (widget->priv->sensitive == sensitive)
+  if (priv->sensitive == sensitive)
     return;
 
-  data.flags = GTK_STATE_FLAG_INSENSITIVE;
+  priv->sensitive = sensitive;
 
-  if (sensitive)
+  if (priv->parent == NULL
+      || gtk_widget_is_sensitive (priv->parent))
     {
-      widget->priv->sensitive = TRUE;
-      data.operation = STATE_CHANGE_UNSET;
-    }
-  else
-    {
-      widget->priv->sensitive = FALSE;
-      data.operation = STATE_CHANGE_SET;
-    }
+      GtkStateData data;
 
-  data.use_forall = TRUE;
+      if (sensitive)
+        {
+          data.flags_to_set = 0;
+          data.flags_to_unset = GTK_STATE_FLAG_INSENSITIVE;
+        }
+      else
+        {
+          data.flags_to_set = GTK_STATE_FLAG_INSENSITIVE;
+          data.flags_to_unset = 0;
+        }
 
-  gtk_widget_propagate_state (widget, &data);
+      gtk_widget_propagate_state (widget, &data);
 
-  gtk_widget_queue_resize (widget);
+      gtk_widget_queue_resize (widget);
+    }
 
   g_object_notify (G_OBJECT (widget), "sensitive");
 }
@@ -7637,18 +8381,6 @@ gtk_widget_is_sensitive (GtkWidget *widget)
   return !(widget->priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
 }
 
-static void
-_gtk_widget_update_path (GtkWidget *widget)
-{
-  if (widget->priv->path)
-    {
-      gtk_widget_path_free (widget->priv->path);
-      widget->priv->path = NULL;
-    }
-
-  gtk_widget_get_path (widget);
-}
-
 /**
  * gtk_widget_set_parent:
  * @widget: a #GtkWidget
@@ -7698,16 +8430,16 @@ gtk_widget_set_parent (GtkWidget *widget,
   parent_flags = gtk_widget_get_state_flags (parent);
 
   /* Merge both old state and current parent state,
-   * We don't want the insensitive flag to propagate
-   * to the new child though */
-  data.flags = parent_flags & ~GTK_STATE_FLAG_INSENSITIVE;
-  data.flags |= priv->state_flags;
-
-  data.operation = STATE_CHANGE_REPLACE;
-  data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
+   * making sure to only propagate the right states */
+  data.flags_to_set = parent_flags & GTK_STATE_FLAGS_DO_PROPAGATE;
+  data.flags_to_unset = 0;
   gtk_widget_propagate_state (widget, &data);
 
-  gtk_widget_reset_style (widget);
+  if (priv->context)
+    gtk_style_context_set_parent (priv->context,
+                                  gtk_widget_get_style_context (parent));
+
+  _gtk_widget_update_parent_muxer (widget);
 
   g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
   if (priv->parent->priv->anchored)
@@ -7747,6 +8479,8 @@ gtk_widget_set_parent (GtkWidget *widget,
       gtk_widget_queue_compute_expand (parent);
     }
 
+  gtk_widget_propagate_alpha (widget);
+
   gtk_widget_pop_verify_invariants (widget);
 }
 
@@ -7766,269 +8500,11 @@ gtk_widget_get_parent (GtkWidget *widget)
   return widget->priv->parent;
 }
 
-/*****************************************
- * Widget styles
- * see docs/styles.txt
- *****************************************/
-
-/**
- * gtk_widget_style_attach:
- * @widget: a #GtkWidget
- *
- * This function attaches the widget's #GtkStyle to the widget's
- * #GdkWindow. It is a replacement for
- *
- * <programlisting>
- * widget->style = gtk_style_attach (widget->style, widget->window);
- * </programlisting>
- *
- * and should only ever be called in a derived widget's "realize"
- * implementation which does not chain up to its parent class'
- * "realize" implementation, because one of the parent classes
- * (finally #GtkWidget) would attach the style itself.
- *
- * Since: 2.20
- *
- * Deprecated: 3.0. This step is unnecessary with #GtkStyleContext.
- **/
-void
-gtk_widget_style_attach (GtkWidget *widget)
-{
-  g_return_if_fail (GTK_IS_WIDGET (widget));
-  g_return_if_fail (gtk_widget_get_realized (widget));
-}
-
-/**
- * gtk_widget_has_rc_style:
- * @widget: a #GtkWidget
- *
- * Determines if the widget style has been looked up through the rc mechanism.
- *
- * Returns: %TRUE if the widget has been looked up through the rc
- *   mechanism, %FALSE otherwise.
- *
- * Since: 2.20
- *
- * Deprecated:3.0: Use #GtkStyleContext instead
- **/
-gboolean
-gtk_widget_has_rc_style (GtkWidget *widget)
-{
-  g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
-
-  return widget->priv->rc_style;
-}
-
-/**
- * gtk_widget_set_style:
- * @widget: a #GtkWidget
- * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect
- *     of a previous call to gtk_widget_set_style() and go back to
- *     the default style
- *
- * Used to set the #GtkStyle for a widget (@widget->style). Since
- * GTK 3, this function does nothing, the passed in style is ignored.
- *
- * Deprecated:3.0: Use #GtkStyleContext instead
- */
-void
-gtk_widget_set_style (GtkWidget *widget,
-                      GtkStyle  *style)
-{
-  g_return_if_fail (GTK_IS_WIDGET (widget));
-}
-
-/**
- * gtk_widget_ensure_style:
- * @widget: a #GtkWidget
- *
- * Ensures that @widget has a style (@widget->style).
- *
- * Not a very useful function; most of the time, if you
- * want the style, the widget is realized, and realized
- * widgets are guaranteed to have a style already.
- *
- * Deprecated:3.0: Use #GtkStyleContext instead
- */
-void
-gtk_widget_ensure_style (GtkWidget *widget)
-{
-  GtkWidgetPrivate *priv;
-
-  g_return_if_fail (GTK_IS_WIDGET (widget));
-
-  priv = widget->priv;
-
-  if (priv->style == gtk_widget_get_default_style ())
-    {
-      g_object_unref (priv->style);
-
-      priv->style = NULL;
-
-      g_signal_emit (widget,
-                     widget_signals[STYLE_SET],
-                     0, NULL);
-    }
-}
-
-/**
- * gtk_widget_get_style:
- * @widget: a #GtkWidget
- *
- * Simply an accessor function that returns @widget->style.
- *
- * Return value: (transfer none): the widget's #GtkStyle
- *
- * Deprecated:3.0: Use #GtkStyleContext instead
- */
-GtkStyle*
-gtk_widget_get_style (GtkWidget *widget)
-{
-  GtkWidgetPrivate *priv;
-
-  g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
-
-  priv = widget->priv;
-
-  if (priv->style == NULL)
-    {
-      priv->style = g_object_new (GTK_TYPE_STYLE,
-                                  "context", gtk_widget_get_style_context (widget),
-                                  NULL);
-
-    }
-
-  return priv->style;
-}
-
-/**
- * gtk_widget_modify_style:
- * @widget: a #GtkWidget
- * @style: the #GtkRcStyle holding the style modifications
- *
- * Modifies style values on the widget.
- *
- * Modifications made using this technique take precedence over
- * style values set via an RC file, however, they will be overridden
- * if a style is explicitely set on the widget using gtk_widget_set_style().
- * The #GtkRcStyle structure is designed so each field can either be
- * set or unset, so it is possible, using this function, to modify some
- * style values and leave the others unchanged.
- *
- * Note that modifications made with this function are not cumulative
- * with previous calls to gtk_widget_modify_style() or with such
- * functions as gtk_widget_modify_fg(). If you wish to retain
- * previous values, you must first call gtk_widget_get_modifier_style(),
- * make your modifications to the returned style, then call
- * gtk_widget_modify_style() with that style. On the other hand,
- * if you first call gtk_widget_modify_style(), subsequent calls
- * to such functions gtk_widget_modify_fg() will have a cumulative
- * effect with the initial modifications.
- *
- * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
- */
-void
-gtk_widget_modify_style (GtkWidget      *widget,
-                         GtkRcStyle     *style)
-{
-  g_return_if_fail (GTK_IS_WIDGET (widget));
-  g_return_if_fail (GTK_IS_RC_STYLE (style));
-
-  g_object_set_qdata_full (G_OBJECT (widget),
-                           quark_rc_style,
-                           gtk_rc_style_copy (style),
-                           (GDestroyNotify) g_object_unref);
-}
-
-/**
- * gtk_widget_get_modifier_style:
- * @widget: a #GtkWidget
- *
- * Returns the current modifier style for the widget. (As set by
- * gtk_widget_modify_style().) If no style has previously set, a new
- * #GtkRcStyle will be created with all values unset, and set as the
- * modifier style for the widget. If you make changes to this rc
- * style, you must call gtk_widget_modify_style(), passing in the
- * returned rc style, to make sure that your changes take effect.
- *
- * Caution: passing the style back to gtk_widget_modify_style() will
- * normally end up destroying it, because gtk_widget_modify_style() copies
- * the passed-in style and sets the copy as the new modifier style,
- * thus dropping any reference to the old modifier style. Add a reference
- * to the modifier style if you want to keep it alive.
- *
- * Return value: (transfer none): the modifier style for the widget.
- *     This rc style is owned by the widget. If you want to keep a
- *     pointer to value this around, you must add a refcount using
- *     g_object_ref().
- *
- * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
- */
-GtkRcStyle *
-gtk_widget_get_modifier_style (GtkWidget *widget)
-{
-  GtkRcStyle *rc_style;
-
-  g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
-
-  rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
-
-  if (!rc_style)
-    {
-      rc_style = gtk_rc_style_new ();
-      g_object_set_qdata_full (G_OBJECT (widget),
-                               quark_rc_style,
-                               rc_style,
-                               (GDestroyNotify) g_object_unref);
-    }
-
-  return rc_style;
-}
-
-static void
-gtk_widget_modify_color_component (GtkWidget      *widget,
-                                   GtkRcFlags      component,
-                                   GtkStateType    state,
-                                   const GdkColor *color)
-{
-  GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
-
-  if (color)
-    {
-      switch (component)
-        {
-        case GTK_RC_FG:
-          rc_style->fg[state] = *color;
-          break;
-        case GTK_RC_BG:
-          rc_style->bg[state] = *color;
-          break;
-        case GTK_RC_TEXT:
-          rc_style->text[state] = *color;
-          break;
-        case GTK_RC_BASE:
-          rc_style->base[state] = *color;
-          break;
-        default:
-          g_assert_not_reached();
-        }
-
-      rc_style->color_flags[state] |= component;
-    }
-  else
-    rc_style->color_flags[state] &= ~component;
-
-  gtk_widget_modify_style (widget, rc_style);
-}
-
 static void
 modifier_style_changed (GtkModifierStyle *style,
                         GtkWidget        *widget)
 {
-  GtkStyleContext *context;
-
-  context = gtk_widget_get_style_context (widget);
-  gtk_style_context_invalidate (context);
+  _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
 }
 
 static GtkModifierStyle *
@@ -8065,7 +8541,7 @@ _gtk_widget_get_modifier_properties (GtkWidget *widget)
  * gtk_widget_override_color:
  * @widget: a #GtkWidget
  * @state: the state for which to set the color
- * @color: the color to assign, or %NULL to undo the effect
+ * @color: (allow-none): the color to assign, or %NULL to undo the effect
  *     of previous calls to gtk_widget_override_color()
  *
  * Sets the color to use for a widget.
@@ -8112,7 +8588,7 @@ gtk_widget_override_color (GtkWidget     *widget,
  * gtk_widget_override_background_color:
  * @widget: a #GtkWidget
  * @state: the state for which to set the background color
- * @color: the color to assign, or %NULL to undo the effect
+ * @color: (allow-none): the color to assign, or %NULL to undo the effect
  *     of previous calls to gtk_widget_override_background_color()
  *
  * Sets the background color to use for a widget.
@@ -8138,7 +8614,7 @@ gtk_widget_override_background_color (GtkWidget     *widget,
 /**
  * gtk_widget_override_font:
  * @widget: a #GtkWidget
- * @font_desc: the font descriptiong to use, or %NULL to undo
+ * @font_desc: (allow-none): the font descriptiong to use, or %NULL to undo
  *     the effect of previous calls to gtk_widget_override_font()
  *
  * Sets the font to use for a widget. All other style values are
@@ -8190,10 +8666,10 @@ gtk_widget_override_symbolic_color (GtkWidget     *widget,
 /**
  * gtk_widget_override_cursor:
  * @widget: a #GtkWidget
- * @cursor: the color to use for primary cursor (does not need to be
+ * @cursor: (allow-none): the color to use for primary cursor (does not need to be
  *     allocated), or %NULL to undo the effect of previous calls to
  *     of gtk_widget_override_cursor().
- * @secondary_cursor: the color to use for secondary cursor (does not
+ * @secondary_cursor: (allow-none): the color to use for secondary cursor (does not
  *     need to be allocated), or %NULL to undo the effect of previous
  *     calls to of gtk_widget_override_cursor().
  *
@@ -8226,279 +8702,18 @@ gtk_widget_override_cursor (GtkWidget     *widget,
                                           secondary_cursor);
 }
 
-/**
- * gtk_widget_modify_fg:
- * @widget: a #GtkWidget
- * @state: the state for which to set the foreground color
- * @color: (allow-none): the color to assign (does not need to be allocated),
- *     or %NULL to undo the effect of previous calls to
- *     of gtk_widget_modify_fg().
- *
- * Sets the foreground color for a widget in a particular state.
- *
- * All other style values are left untouched.
- * See also gtk_widget_modify_style().
- *
- * Deprecated:3.0: Use gtk_widget_override_color() instead
- */
-void
-gtk_widget_modify_fg (GtkWidget      *widget,
-                      GtkStateType    state,
-                      const GdkColor *color)
+static void
+gtk_widget_real_direction_changed (GtkWidget        *widget,
+                                   GtkTextDirection  previous_direction)
 {
-  GtkStateFlags flags;
-  GdkRGBA rgba;
+  gtk_widget_queue_resize (widget);
+}
 
-  g_return_if_fail (GTK_IS_WIDGET (widget));
-  g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
-
-  switch (state)
-    {
-    case GTK_STATE_ACTIVE:
-      flags = GTK_STATE_FLAG_ACTIVE;
-      break;
-    case GTK_STATE_PRELIGHT:
-      flags = GTK_STATE_FLAG_PRELIGHT;
-      break;
-    case GTK_STATE_SELECTED:
-      flags = GTK_STATE_FLAG_SELECTED;
-      break;
-    case GTK_STATE_INSENSITIVE:
-      flags = GTK_STATE_FLAG_INSENSITIVE;
-      break;
-    case GTK_STATE_NORMAL:
-    default:
-      flags = 0;
-    }
-
-  if (color)
-    {
-      rgba.red = color->red / 65535.;
-      rgba.green = color->green / 65535.;
-      rgba.blue = color->blue / 65535.;
-      rgba.alpha = 1;
-
-      gtk_widget_override_color (widget, flags, &rgba);
-    }
-  else
-    gtk_widget_override_color (widget, flags, NULL);
-}
-
-/**
- * gtk_widget_modify_bg:
- * @widget: a #GtkWidget
- * @state: the state for which to set the background color
- * @color: (allow-none): the color to assign (does not need
- *     to be allocated), or %NULL to undo the effect of previous
- *     calls to of gtk_widget_modify_bg().
- *
- * Sets the background color for a widget in a particular state.
- *
- * All other style values are left untouched.
- * See also gtk_widget_modify_style().
- *
- * <note><para>
- * Note that "no window" widgets (which have the %GTK_NO_WINDOW
- * flag set) draw on their parent container's window and thus may
- * not draw any background themselves. This is the case for e.g.
- * #GtkLabel.
- * </para><para>
- * To modify the background of such widgets, you have to set the
- * background color on their parent; if you want to set the background
- * of a rectangular area around a label, try placing the label in
- * a #GtkEventBox widget and setting the background color on that.
- * </para></note>
- *
- * Deprecated:3.0: Use gtk_widget_override_background_color() instead
- */
-void
-gtk_widget_modify_bg (GtkWidget      *widget,
-                      GtkStateType    state,
-                      const GdkColor *color)
-{
-  GtkStateFlags flags;
-  GdkRGBA rgba;
-
-  g_return_if_fail (GTK_IS_WIDGET (widget));
-  g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
-
-  switch (state)
-    {
-    case GTK_STATE_ACTIVE:
-      flags = GTK_STATE_FLAG_ACTIVE;
-      break;
-    case GTK_STATE_PRELIGHT:
-      flags = GTK_STATE_FLAG_PRELIGHT;
-      break;
-    case GTK_STATE_SELECTED:
-      flags = GTK_STATE_FLAG_SELECTED;
-      break;
-    case GTK_STATE_INSENSITIVE:
-      flags = GTK_STATE_FLAG_INSENSITIVE;
-      break;
-    case GTK_STATE_NORMAL:
-    default:
-      flags = 0;
-    }
-
-  if (color)
-    {
-      rgba.red = color->red / 65535.;
-      rgba.green = color->green / 65535.;
-      rgba.blue = color->blue / 65535.;
-      rgba.alpha = 1;
-
-      gtk_widget_override_background_color (widget, flags, &rgba);
-    }
-  else
-    gtk_widget_override_background_color (widget, flags, NULL);
-}
-
-/**
- * gtk_widget_modify_text:
- * @widget: a #GtkWidget
- * @state: the state for which to set the text color
- * @color: (allow-none): the color to assign (does not need to
- *     be allocated), or %NULL to undo the effect of previous
- *     calls to of gtk_widget_modify_text().
- *
- * Sets the text color for a widget in a particular state.
- *
- * All other style values are left untouched.
- * The text color is the foreground color used along with the
- * base color (see gtk_widget_modify_base()) for widgets such
- * as #GtkEntry and #GtkTextView.
- * See also gtk_widget_modify_style().
- *
- * Deprecated:3.0: Use gtk_widget_override_color() instead
- */
-void
-gtk_widget_modify_text (GtkWidget      *widget,
-                        GtkStateType    state,
-                        const GdkColor *color)
-{
-  g_return_if_fail (GTK_IS_WIDGET (widget));
-  g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
-
-  gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
-}
-
-/**
- * gtk_widget_modify_base:
- * @widget: a #GtkWidget
- * @state: the state for which to set the base color
- * @color: (allow-none): the color to assign (does not need to
- *     be allocated), or %NULL to undo the effect of previous
- *     calls to of gtk_widget_modify_base().
- *
- * Sets the base color for a widget in a particular state.
- * All other style values are left untouched. The base color
- * is the background color used along with the text color
- * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
- * and #GtkTextView. See also gtk_widget_modify_style().
- *
- * <note><para>
- * Note that "no window" widgets (which have the %GTK_NO_WINDOW
- * flag set) draw on their parent container's window and thus may
- * not draw any background themselves. This is the case for e.g.
- * #GtkLabel.
- * </para><para>
- * To modify the background of such widgets, you have to set the
- * base color on their parent; if you want to set the background
- * of a rectangular area around a label, try placing the label in
- * a #GtkEventBox widget and setting the base color on that.
- * </para></note>
- *
- * Deprecated:3.0: Use gtk_widget_override_background_color() instead
- */
-void
-gtk_widget_modify_base (GtkWidget      *widget,
-                        GtkStateType    state,
-                        const GdkColor *color)
-{
-  g_return_if_fail (GTK_IS_WIDGET (widget));
-  g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
-
-  gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
-}
-
-/**
- * gtk_widget_modify_cursor:
- * @widget: a #GtkWidget
- * @primary: the color to use for primary cursor (does not need to be
- *     allocated), or %NULL to undo the effect of previous calls to
- *     of gtk_widget_modify_cursor().
- * @secondary: the color to use for secondary cursor (does not need to be
- *     allocated), or %NULL to undo the effect of previous calls to
- *     of gtk_widget_modify_cursor().
- *
- * Sets the cursor color to use in a widget, overriding the
- * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
- * style properties.
- *
- * All other style values are left untouched.
- * See also gtk_widget_modify_style().
- *
- * Since: 2.12
- *
- * Deprecated: 3.0. Use gtk_widget_override_cursor() instead.
- */
-void
-gtk_widget_modify_cursor (GtkWidget      *widget,
-                          const GdkColor *primary,
-                          const GdkColor *secondary)
-{
-  GdkRGBA primary_rgba, secondary_rgba;
-
-  g_return_if_fail (GTK_IS_WIDGET (widget));
-
-  primary_rgba.red = primary->red / 65535.;
-  primary_rgba.green = primary->green / 65535.;
-  primary_rgba.blue = primary->blue / 65535.;
-  primary_rgba.alpha = 1;
-
-  secondary_rgba.red = secondary->red / 65535.;
-  secondary_rgba.green = secondary->green / 65535.;
-  secondary_rgba.blue = secondary->blue / 65535.;
-  secondary_rgba.alpha = 1;
-
-  gtk_widget_override_cursor (widget, &primary_rgba, &secondary_rgba);
-}
-
-/**
- * gtk_widget_modify_font:
- * @widget: a #GtkWidget
- * @font_desc: (allow-none): the font description to use, or %NULL
- *     to undo the effect of previous calls to gtk_widget_modify_font()
- *
- * Sets the font to use for a widget.
- *
- * All other style values are left untouched.
- * See also gtk_widget_modify_style().
- *
- * Deprecated:3.0: Use gtk_widget_override_font() instead
- */
-void
-gtk_widget_modify_font (GtkWidget            *widget,
-                        PangoFontDescription *font_desc)
-{
-  g_return_if_fail (GTK_IS_WIDGET (widget));
-
-  gtk_widget_override_font (widget, font_desc);
-}
-
-static void
-gtk_widget_real_direction_changed (GtkWidget        *widget,
-                                   GtkTextDirection  previous_direction)
-{
-  gtk_widget_queue_resize (widget);
-}
-
-static void
-gtk_widget_real_style_set (GtkWidget *widget,
-                           GtkStyle  *previous_style)
-{
-}
+static void
+gtk_widget_real_style_set (GtkWidget *widget,
+                           GtkStyle  *previous_style)
+{
+}
 
 typedef struct {
   GtkWidget *previous_toplevel;
@@ -8546,6 +8761,17 @@ gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
 
       priv->anchored = new_anchored;
 
+      /* This can only happen with gtk_widget_reparent() */
+      if (priv->realized)
+        {
+          if (new_anchored)
+            gtk_widget_connect_frame_clock (widget,
+                                            gtk_widget_get_frame_clock (widget));
+          else
+            gtk_widget_disconnect_frame_clock (widget,
+                                               gtk_widget_get_frame_clock (info->previous_toplevel));
+        }
+
       g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
       do_screen_change (widget, info->previous_screen, info->new_screen);
 
@@ -8692,7 +8918,7 @@ _gtk_widget_propagate_screen_changed (GtkWidget    *widget,
 static void
 reset_style_recurse (GtkWidget *widget, gpointer data)
 {
-  _gtk_widget_update_path (widget);
+  _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
 
   if (GTK_IS_CONTAINER (widget))
     gtk_container_forall (GTK_CONTAINER (widget),
@@ -8717,50 +8943,9 @@ gtk_widget_reset_style (GtkWidget *widget)
   g_return_if_fail (GTK_IS_WIDGET (widget));
 
   reset_style_recurse (widget, NULL);
-}
-
-/**
- * gtk_widget_reset_rc_styles:
- * @widget: a #GtkWidget.
- *
- * Reset the styles of @widget and all descendents, so when
- * they are looked up again, they get the correct values
- * for the currently loaded RC file settings.
- *
- * This function is not useful for applications.
- *
- * Deprecated:3.0: Use #GtkStyleContext instead, and gtk_widget_reset_style()
- */
-void
-gtk_widget_reset_rc_styles (GtkWidget *widget)
-{
-  g_return_if_fail (GTK_IS_WIDGET (widget));
-
-  reset_style_recurse (widget, NULL);
-}
-
-/**
- * gtk_widget_get_default_style:
- *
- * Returns the default style used by all widgets initially.
- *
- * Returns: (transfer none): the default style. This #GtkStyle
- *     object is owned by GTK+ and should not be modified or freed.
- *
- * Deprecated:3.0: Use #GtkStyleContext instead, and
- *     gtk_css_provider_get_default() to obtain a #GtkStyleProvider
- *     with the default widget style information.
- */
-GtkStyle*
-gtk_widget_get_default_style (void)
-{
-  if (!gtk_default_style)
-    {
-      gtk_default_style = gtk_style_new ();
-      g_object_ref (gtk_default_style);
-    }
 
-  return gtk_default_style;
+  g_list_foreach (widget->priv->attached_windows,
+                  (GFunc) reset_style_recurse, NULL);
 }
 
 #ifdef G_ENABLE_DEBUG
@@ -8883,10 +9068,6 @@ gtk_widget_verify_invariants (GtkWidget *widget)
 
 #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);
@@ -8964,12 +9145,8 @@ gtk_widget_peek_pango_context (GtkWidget *widget)
  * by gtk_widget_create_pango_context(), this context is owned by
  * the widget (it can be used until the screen for the widget changes
  * or the widget is removed from its toplevel), and will be updated to
- * match any changes to the widget's attributes.
- *
- * If you create and keep a #PangoLayout using this context, you must
- * deal with changes to the context by calling pango_layout_context_changed()
- * on the layout in response to the #GtkWidget::style-updated and
- * #GtkWidget::direction-changed signals for the widget.
+ * match any changes to the widget's attributes. This can be tracked
+ * by using the #GtkWidget::screen-changed signal on the widget.
  *
  * Return value: (transfer none): the #PangoContext for the widget.
  **/
@@ -9001,11 +9178,10 @@ update_pango_context (GtkWidget    *widget,
   GtkStyleContext *style_context;
 
   style_context = gtk_widget_get_style_context (widget);
-
   gtk_style_context_get (style_context,
-                        gtk_widget_get_state_flags (widget),
-                        "font", &font_desc,
-                        NULL);
+                         gtk_widget_get_state_flags (widget),
+                         "font", &font_desc,
+                         NULL);
 
   pango_context_set_font_description (context, font_desc);
   pango_context_set_base_dir (context,
@@ -9081,11 +9257,10 @@ gtk_widget_create_pango_context (GtkWidget *widget)
  * font description, and base direction for drawing text for
  * this widget.
  *
- * If you keep a #PangoLayout created in this way around, in order to
- * notify the layout of changes to the base direction or font of this
- * widget, you must call pango_layout_context_changed() in response to
- * the #GtkWidget::style-updated and #GtkWidget::direction-changed signals
- * for the widget.
+ * If you keep a #PangoLayout created in this way around, you need
+ * to re-create it when the widget #PangoContext is replaced.
+ * This can be tracked by using the #GtkWidget::screen-changed signal
+ * on the widget.
  *
  * Return value: (transfer full): the new #PangoLayout
  **/
@@ -9151,43 +9326,6 @@ gtk_widget_render_icon_pixbuf (GtkWidget   *widget,
   return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
 }
 
-/**
- * gtk_widget_render_icon:
- * @widget: a #GtkWidget
- * @stock_id: a stock ID
- * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
- *     render at the size of the source and don't scale (if there are
- *     multiple source sizes, GTK+ picks one of the available sizes).
- * @detail: (allow-none): render detail to pass to theme engine
- *
- * A convenience function that uses the theme settings for @widget
- * to look up @stock_id and render it to a pixbuf. @stock_id should
- * be a stock icon ID such as #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size
- * should be a size such as #GTK_ICON_SIZE_MENU. @detail should be a
- * string that identifies the widget or code doing the rendering, so
- * that theme engines can special-case rendering for that widget or
- * code.
- *
- * The pixels in the returned #GdkPixbuf are shared with the rest of
- * the application and should not be modified. The pixbuf should be
- * freed after use with g_object_unref().
- *
- * Return value: (transfer full): a new pixbuf, or %NULL if the
- *     stock ID wasn't known
- *
- * Deprecated: 3.0: Use gtk_widget_render_icon_pixbuf() instead.
- **/
-GdkPixbuf*
-gtk_widget_render_icon (GtkWidget      *widget,
-                        const gchar    *stock_id,
-                        GtkIconSize     size,
-                        const gchar    *detail)
-{
-  gtk_widget_ensure_style (widget);
-
-  return gtk_widget_render_icon_pixbuf (widget, stock_id, size);
-}
-
 /**
  * gtk_widget_set_parent_window:
  * @widget: a #GtkWidget.
@@ -9640,7 +9778,7 @@ gtk_widget_set_usize_internal (GtkWidget          *widget,
 
   g_object_freeze_notify (G_OBJECT (widget));
 
-  aux_info = _gtk_widget_get_aux_info (widget, TRUE);
+  aux_info = gtk_widget_get_aux_info (widget, TRUE);
 
   if (width > -2 && aux_info->width != width)
     {
@@ -9675,9 +9813,8 @@ gtk_widget_set_usize_internal (GtkWidget          *widget,
  * @height: height @widget should request, or -1 to unset
  *
  * Sets the minimum size of a widget; that is, the widget's size
- * request will be @width by @height. You can use this function to
- * force a widget to be either larger or smaller than it normally
- * would be.
+ * request will be at least @width by @height. You can use this 
+ * function to force a widget to be larger than it normally would be.
  *
  * In most cases, gtk_window_set_default_size() is a better choice for
  * toplevel windows than this function; setting the default size will
@@ -9701,9 +9838,6 @@ gtk_widget_set_usize_internal (GtkWidget          *widget,
  * If the size request in a given direction is -1 (unset), then
  * the "natural" size request of the widget will be used instead.
  *
- * Widgets can't actually be allocated a size less than 1 by 1, but
- * you can pass 0,0 to this function to mean "as small as possible."
- *
  * The size request set here does not include any margin from the
  * #GtkWidget properties margin-left, margin-right, margin-top, and
  * margin-bottom, but it does include pretty much all other padding
@@ -9765,7 +9899,7 @@ gtk_widget_get_size_request (GtkWidget *widget,
  * @width: new forced minimum width
  * @height: new forced minimum height
  * @old_width: location to store previous forced minimum width
- * @old_width: location to store previous forced minumum height
+ * @old_height: location to store previous forced minumum height
  *
  * Temporarily establishes a forced minimum size for a widget; this
  * is used by GtkWindow when calculating the size to add to the
@@ -10068,7 +10202,7 @@ gtk_widget_add_device_events (GtkWidget    *widget,
  * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
  * would return
  * %NULL if @widget wasn't inside a toplevel window, and if the
- * window was inside a #GtkWindow-derived widget which was in turn
+ * window was inside a #GtkWindow<!-- -->-derived widget which was in turn
  * inside the toplevel #GtkWindow. While the second case may
  * seem unlikely, it actually happens when a #GtkPlug is embedded
  * inside a #GtkSocket within the same application.
@@ -10137,7 +10271,7 @@ gtk_widget_get_ancestor (GtkWidget *widget,
  *
  * Sets the visual that should be used for by widget and its children for
  * creating #GdkWindows. The visual must be on the same #GdkScreen as
- * returned by gdk_widget_get_screen(), so handling the
+ * returned by gtk_widget_get_screen(), so handling the
  * #GtkWidget::screen-changed signal is necessary.
  *
  * Setting a new @visual will not cause @widget to recreate its windows,
@@ -10277,6 +10411,8 @@ gtk_widget_get_device_events (GtkWidget *widget,
  * defined as @widget->window coordinates for widgets that are not
  * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
  * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
+ *
+ * Deprecated: 3.4: Use gdk_window_get_device_position() instead.
  **/
 void
 gtk_widget_get_pointer (GtkWidget *widget,
@@ -10296,7 +10432,11 @@ gtk_widget_get_pointer (GtkWidget *widget,
 
   if (gtk_widget_get_realized (widget))
     {
-      gdk_window_get_pointer (priv->window, x, y, NULL);
+      gdk_window_get_device_position (priv->window,
+                                      gdk_device_manager_get_client_pointer (
+                                        gdk_display_get_device_manager (
+                                          gtk_widget_get_display (widget))),
+                                      x, y, NULL);
 
       if (!gtk_widget_get_has_window (widget))
        {
@@ -10434,11 +10574,32 @@ static void
 gtk_widget_emit_direction_changed (GtkWidget        *widget,
                                    GtkTextDirection  old_dir)
 {
+  GtkTextDirection direction;
+  GtkStateFlags state;
+
   gtk_widget_update_pango_context (widget);
 
-  if (widget->priv->context)
-    gtk_style_context_set_direction (widget->priv->context,
-                                     gtk_widget_get_direction (widget));
+  direction = gtk_widget_get_direction (widget);
+  state = widget->priv->state_flags;
+  state &= GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL;
+
+  switch (direction)
+    {
+    case GTK_TEXT_DIR_LTR:
+      state |= GTK_STATE_FLAG_DIR_LTR;
+      break;
+
+    case GTK_TEXT_DIR_RTL:
+      state |= GTK_STATE_FLAG_DIR_RTL;
+      break;
+
+    case GTK_TEXT_DIR_NONE:
+    default:
+      g_assert_not_reached ();
+      break;
+    }
+
+  gtk_widget_set_state_flags (widget, state, TRUE);
 
   g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
 }
@@ -10565,6 +10726,27 @@ gtk_widget_get_default_direction (void)
   return gtk_default_direction;
 }
 
+static void
+gtk_widget_constructed (GObject *object)
+{
+  GtkWidget *widget = GTK_WIDGET (object);
+  GtkWidgetPrivate *priv = widget->priv;
+
+  /* As strange as it may seem, this may happen on object construction.
+   * init() implementations of parent types may eventually call this function,
+   * each with its corresponding GType, which could leave a child
+   * implementation with a wrong widget type in the widget path
+   */
+  if (priv->path &&
+      G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (priv->path))
+    {
+      gtk_widget_path_free (priv->path);
+      priv->path = NULL;
+    }
+
+  G_OBJECT_CLASS (gtk_widget_parent_class)->constructed (object);
+}
+
 static void
 gtk_widget_dispose (GObject *object)
 {
@@ -10587,6 +10769,8 @@ gtk_widget_dispose (GObject *object)
       priv->in_destruction = FALSE;
     }
 
+  g_clear_object (&priv->muxer);
+
   G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
 }
 
@@ -10596,6 +10780,18 @@ gtk_widget_real_destroy (GtkWidget *object)
   /* gtk_object_destroy() will already hold a refcount on object */
   GtkWidget *widget = GTK_WIDGET (object);
   GtkWidgetPrivate *priv = widget->priv;
+  GList *l;
+
+  if (GTK_WIDGET_GET_CLASS (widget)->priv->accessible_type != GTK_TYPE_ACCESSIBLE)
+    {
+      GtkAccessible *accessible = g_object_steal_qdata (G_OBJECT (widget), quark_accessible_object);
+      
+      if (accessible)
+        {
+          gtk_accessible_set_widget (accessible, NULL);
+          g_object_unref (accessible);
+        }
+    }
 
   /* wipe accelerator closures (keep order) */
   g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
@@ -10606,6 +10802,13 @@ gtk_widget_real_destroy (GtkWidget *object)
 
   gtk_grab_remove (widget);
 
+  for (l = priv->tick_callbacks; l;)
+    {
+      GList *next = l->next;
+      destroy_tick_callback_info (widget, l->data, l);
+      l = next;
+    }
+
   if (priv->style)
     g_object_unref (priv->style);
   priv->style = gtk_widget_get_default_style ();
@@ -10627,7 +10830,7 @@ gtk_widget_finalize (GObject *object)
 
   g_free (priv->name);
 
-  aux_info =_gtk_widget_get_aux_info (widget, FALSE);
+  aux_info = gtk_widget_get_aux_info (widget, FALSE);
   if (aux_info)
     gtk_widget_aux_info_destroy (aux_info);
 
@@ -10639,9 +10842,12 @@ gtk_widget_finalize (GObject *object)
     gtk_widget_path_free (priv->path);
 
   if (priv->context)
-    g_object_unref (priv->context);
+    {
+      _gtk_style_context_set_widget (priv->context, NULL);
+      g_object_unref (priv->context);
+    }
 
-  _gtk_widget_free_cached_sizes (widget);
+  _gtk_size_request_cache_free (&priv->requests);
 
   if (g_object_is_floating (object))
     g_warning ("A floating object was finalized. This means that someone\n"
@@ -10752,7 +10958,7 @@ gtk_widget_real_unrealize (GtkWidget *widget)
 
   if (gtk_widget_get_has_window (widget))
     {
-      gdk_window_set_user_data (priv->window, NULL);
+      gtk_widget_unregister_window (widget, priv->window);
       gdk_window_destroy (priv->window);
       priv->window = NULL;
     }
@@ -11161,18 +11367,8 @@ gtk_widget_propagate_state (GtkWidget    *widget,
 
   old_state = gtk_widget_get_state (widget);
 
-  switch (data->operation)
-    {
-    case STATE_CHANGE_REPLACE:
-      priv->state_flags = data->flags;
-      break;
-    case STATE_CHANGE_SET:
-      priv->state_flags |= data->flags;
-      break;
-    case STATE_CHANGE_UNSET:
-      priv->state_flags &= ~(data->flags);
-      break;
-    }
+  priv->state_flags |= data->flags_to_set;
+  priv->state_flags &= ~(data->flags_to_unset);
 
   /* make insensitivity unoverridable */
   if (!priv->sensitive)
@@ -11197,10 +11393,13 @@ gtk_widget_propagate_state (GtkWidget    *widget,
       if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
         gtk_grab_remove (widget);
 
+      gtk_style_context_set_state (gtk_widget_get_style_context (widget), new_flags);
+
       g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
       g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
 
-      if (!priv->shadowed)
+      if (!priv->shadowed &&
+          (new_flags & GTK_STATE_FLAG_INSENSITIVE) != (old_flags & GTK_STATE_FLAG_INSENSITIVE))
         {
           GList *event_windows = NULL;
           GList *devices, *d;
@@ -11225,7 +11424,7 @@ gtk_widget_propagate_state (GtkWidget    *widget,
               if (!gtk_widget_is_sensitive (widget))
                 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
                                                  GDK_CROSSING_STATE_CHANGED);
-              else if (old_flags & GTK_STATE_FLAG_INSENSITIVE)
+              else
                 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
                                                  GDK_CROSSING_STATE_CHANGED);
 
@@ -11238,48 +11437,20 @@ gtk_widget_propagate_state (GtkWidget    *widget,
 
       if (GTK_IS_CONTAINER (widget))
         {
-          GtkStateData child_data = *data;
+          GtkStateData child_data;
 
-          /* Do not propagate focused state further */
-          child_data.flags &= ~GTK_STATE_FLAG_FOCUSED;
+          /* Make sure to only propate the right states further */
+          child_data.flags_to_set = data->flags_to_set & GTK_STATE_FLAGS_DO_PROPAGATE;
+          child_data.flags_to_unset = data->flags_to_unset & GTK_STATE_FLAGS_DO_PROPAGATE;
 
-          if (child_data.use_forall)
-            gtk_container_forall (GTK_CONTAINER (widget),
-                                  (GtkCallback) gtk_widget_propagate_state,
-                                  &child_data);
-          else
-            gtk_container_foreach (GTK_CONTAINER (widget),
-                                   (GtkCallback) gtk_widget_propagate_state,
-                                   &child_data);
+          gtk_container_forall (GTK_CONTAINER (widget),
+                                (GtkCallback) gtk_widget_propagate_state,
+                                &child_data);
         }
 
-      /* Trigger state change transitions for the widget */
-      if (priv->context &&
-          gtk_widget_get_mapped (widget))
-        {
-          gint diff, flag = 1;
-
-          diff = old_flags ^ new_flags;
-
-          while (diff != 0)
-            {
-              if ((diff & flag) != 0)
-                {
-                  gboolean target;
-
-                  target = ((new_flags & flag) != 0);
-                  _gtk_widget_notify_state_change (widget, flag, target);
-
-                  diff &= ~flag;
-                }
-
-              flag <<= 1;
-            }
-        }
-
-      g_object_unref (widget);
-    }
-}
+      g_object_unref (widget);
+    }
+}
 
 static const GtkWidgetAuxInfo default_aux_info = {
   -1, -1,
@@ -11289,7 +11460,7 @@ static const GtkWidgetAuxInfo default_aux_info = {
 };
 
 /*
- * _gtk_widget_get_aux_info:
+ * gtk_widget_get_aux_info:
  * @widget: a #GtkWidget
  * @create: if %TRUE, create the structure if it doesn't exist
  *
@@ -11298,9 +11469,9 @@ static const GtkWidgetAuxInfo default_aux_info = {
  * Return value: the #GtkAuxInfo structure for the widget, or
  *    %NULL if @create is %FALSE and one doesn't already exist.
  */
-GtkWidgetAuxInfo*
-_gtk_widget_get_aux_info (GtkWidget *widget,
-                         gboolean   create)
+static GtkWidgetAuxInfo *
+gtk_widget_get_aux_info (GtkWidget *widget,
+                        gboolean   create)
 {
   GtkWidgetAuxInfo *aux_info;
 
@@ -11322,7 +11493,7 @@ _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
 {
   GtkWidgetAuxInfo *aux_info;
 
-  aux_info = _gtk_widget_get_aux_info (widget, FALSE);
+  aux_info = gtk_widget_get_aux_info (widget, FALSE);
   if (aux_info == NULL)
     {
       return &default_aux_info;
@@ -11500,11 +11671,12 @@ gtk_widget_class_install_style_property (GtkWidgetClass *klass,
  * gtk_widget_class_find_style_property:
  * @klass: a #GtkWidgetClass
  * @property_name: the name of the style property to find
- * @returns: (transfer none): the #GParamSpec of the style property or
- *   %NULL if @class has no style property with that name.
  *
  * Finds a style property of a widget class by name.
  *
+ * Returns: (transfer none): the #GParamSpec of the style property or
+ *   %NULL if @class has no style property with that name.
+ *
  * Since: 2.2
  */
 GParamSpec*
@@ -11523,12 +11695,13 @@ gtk_widget_class_find_style_property (GtkWidgetClass *klass,
  * gtk_widget_class_list_style_properties:
  * @klass: a #GtkWidgetClass
  * @n_properties: location to return the number of style properties found
- * @returns: (array length=n_properties) (transfer container): an
- *       newly allocated array of #GParamSpec*. The array must be
- *       freed with g_free().
  *
  * Returns all style properties of a widget class.
  *
+ * Returns: (array length=n_properties) (transfer container): a
+ *     newly allocated array of #GParamSpec*. The array must be
+ *     freed with g_free().
+ *
  * Since: 2.2
  */
 GParamSpec**
@@ -11673,9 +11846,9 @@ gtk_widget_style_get_valist (GtkWidget   *widget,
  * gtk_widget_style_get:
  * @widget: a #GtkWidget
  * @first_property_name: the name of the first property to get
- * @Varargs: pairs of property names and locations to
- *   return the property values, starting with the location for
- *   @first_property_name, terminated by %NULL.
+ * @...: pairs of property names and locations to return the
+ *     property values, starting with the location for
+ *     @first_property_name, terminated by %NULL.
  *
  * Gets the values of a multiple style properties of @widget.
  */
@@ -11693,152 +11866,6 @@ gtk_widget_style_get (GtkWidget   *widget,
   va_end (var_args);
 }
 
-/**
- * gtk_widget_path:
- * @widget: a #GtkWidget
- * @path_length: (out) (allow-none): location to store length of the path,
- *     or %NULL
- * @path: (out) (allow-none): location to store allocated path string,
- *     or %NULL
- * @path_reversed: (out) (allow-none): location to store allocated reverse
- *     path string, or %NULL
- *
- * Obtains the full path to @widget. The path is simply the name of a
- * widget and all its parents in the container hierarchy, separated by
- * periods. The name of a widget comes from
- * gtk_widget_get_name(). Paths are used to apply styles to a widget
- * in gtkrc configuration files. Widget names are the type of the
- * widget by default (e.g. "GtkButton") or can be set to an
- * application-specific value with gtk_widget_set_name(). By setting
- * the name of a widget, you allow users or theme authors to apply
- * styles to that specific widget in their gtkrc
- * file. @path_reversed_p fills in the path in reverse order,
- * i.e. starting with @widget's name instead of starting with the name
- * of @widget's outermost ancestor.
- *
- * Deprecated:3.0: Use gtk_widget_get_path() instead
- **/
-void
-gtk_widget_path (GtkWidget *widget,
-                guint     *path_length,
-                gchar    **path,
-                gchar    **path_reversed)
-{
-  static gchar *rev_path = NULL;
-  static guint tmp_path_len = 0;
-  guint len;
-
-  g_return_if_fail (GTK_IS_WIDGET (widget));
-
-  len = 0;
-  do
-    {
-      const gchar *string;
-      const gchar *s;
-      gchar *d;
-      guint l;
-
-      string = gtk_widget_get_name (widget);
-      l = strlen (string);
-      while (tmp_path_len <= len + l + 1)
-       {
-         tmp_path_len += INIT_PATH_SIZE;
-         rev_path = g_realloc (rev_path, tmp_path_len);
-       }
-      s = string + l - 1;
-      d = rev_path + len;
-      while (s >= string)
-       *(d++) = *(s--);
-      len += l;
-
-      widget = widget->priv->parent;
-
-      if (widget)
-       rev_path[len++] = '.';
-      else
-       rev_path[len++] = 0;
-    }
-  while (widget);
-
-  if (path_length)
-    *path_length = len - 1;
-  if (path_reversed)
-    *path_reversed = g_strdup (rev_path);
-  if (path)
-    {
-      *path = g_strdup (rev_path);
-      g_strreverse (*path);
-    }
-}
-
-/**
- * gtk_widget_class_path:
- * @widget: a #GtkWidget
- * @path_length: (out) (allow-none): location to store the length of the
- *     class path, or %NULL
- * @path: (out) (allow-none): location to store the class path as an
- *     allocated string, or %NULL
- * @path_reversed: (out) (allow-none): location to store the reverse
- *     class path as an allocated string, or %NULL
- *
- * Same as gtk_widget_path(), but always uses the name of a widget's type,
- * never uses a custom name set with gtk_widget_set_name().
- *
- * Deprecated:3.0: Use gtk_widget_get_path() instead
- **/
-void
-gtk_widget_class_path (GtkWidget *widget,
-                      guint     *path_length,
-                      gchar    **path,
-                      gchar    **path_reversed)
-{
-  static gchar *rev_path = NULL;
-  static guint tmp_path_len = 0;
-  guint len;
-
-  g_return_if_fail (GTK_IS_WIDGET (widget));
-
-  len = 0;
-  do
-    {
-      const gchar *string;
-      const gchar *s;
-      gchar *d;
-      guint l;
-
-      string = g_type_name (G_OBJECT_TYPE (widget));
-      l = strlen (string);
-      while (tmp_path_len <= len + l + 1)
-       {
-         tmp_path_len += INIT_PATH_SIZE;
-         rev_path = g_realloc (rev_path, tmp_path_len);
-       }
-      s = string + l - 1;
-      d = rev_path + len;
-      while (s >= string)
-       *(d++) = *(s--);
-      len += l;
-
-      widget = widget->priv->parent;
-
-      if (widget)
-       rev_path[len++] = '.';
-      else
-       rev_path[len++] = 0;
-    }
-  while (widget);
-
-  if (path_length)
-    *path_length = len - 1;
-  if (path_reversed)
-    *path_reversed = g_strdup (rev_path);
-  if (path)
-    {
-      *path = g_strdup (rev_path);
-      g_strreverse (*path);
-    }
-}
-
 /**
  * gtk_requisition_new:
  *
@@ -11885,6 +11912,89 @@ G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
                      gtk_requisition_copy,
                      gtk_requisition_free)
 
+/**
+ * gtk_widget_class_set_accessible_type:
+ * @widget_class: class to set the accessible type for
+ * @type: The object type that implements the accessible for @widget_class
+ *
+ * Sets the type to be used for creating accessibles for widgets of
+ * @widget_class. The given @type must be a subtype of the type used for
+ * accessibles of the parent class.
+ *
+ * This function should only be called from class init functions of widgets.
+ *
+ * Since: 3.2
+ **/
+void
+gtk_widget_class_set_accessible_type (GtkWidgetClass *widget_class,
+                                      GType           type)
+{
+  GtkWidgetClassPrivate *priv;
+
+  g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
+  g_return_if_fail (g_type_is_a (type, widget_class->priv->accessible_type));
+
+  priv = widget_class->priv;
+
+  priv->accessible_type = type;
+  /* reset this - honoring the type's role is better. */
+  priv->accessible_role = ATK_ROLE_INVALID;
+}
+
+/**
+ * gtk_widget_class_set_accessible_role:
+ * @widget_class: class to set the accessible role for
+ * @role: The role to use for accessibles created for @widget_class
+ *
+ * Sets the default #AtkRole to be set on accessibles created for
+ * widgets of @widget_class. Accessibles may decide to not honor this
+ * setting if their role reporting is more refined. Calls to 
+ * gtk_widget_class_set_accessible_type() will reset this value.
+ *
+ * In cases where you want more fine-grained control over the role of
+ * accessibles created for @widget_class, you should provide your own
+ * accessible type and use gtk_widget_class_set_accessible_type()
+ * instead.
+ *
+ * If @role is #ATK_ROLE_INVALID, the default role will not be changed
+ * and the accessible's default role will be used instead.
+ *
+ * This function should only be called from class init functions of widgets.
+ *
+ * Since: 3.2
+ **/
+void
+gtk_widget_class_set_accessible_role (GtkWidgetClass *widget_class,
+                                      AtkRole         role)
+{
+  GtkWidgetClassPrivate *priv;
+
+  g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
+
+  priv = widget_class->priv;
+
+  priv->accessible_role = role;
+}
+
+/**
+ * _gtk_widget_peek_accessible:
+ * @widget: a #GtkWidget
+ *
+ * Gets the accessible for @widget, if it has been created yet.
+ * Otherwise, this function returns %NULL. If the @widget's implementation
+ * does not use the default way to create accessibles, %NULL will always be
+ * returned.
+ *
+ * Returns: the accessible for @widget or %NULL if none has been
+ *     created yet.
+ **/
+AtkObject *
+_gtk_widget_peek_accessible (GtkWidget *widget)
+{
+  return g_object_get_qdata (G_OBJECT (widget),
+                             quark_accessible_object);
+}
+
 /**
  * gtk_widget_get_accessible:
  * @widget: a #GtkWidget
@@ -11892,15 +12002,14 @@ G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
  * Returns the accessible object that describes the widget to an
  * assistive technology.
  *
- * If no accessibility library is loaded (i.e. no ATK implementation library is
- * loaded via <envar>GTK_MODULES</envar> or via another application library,
- * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
- * if no class-specific #AtkObject implementation is available for the widget
- * instance in question, it will inherit an #AtkObject implementation from the
- * first ancestor class for which such an implementation is defined.
+ * If accessibility support is not available, this #AtkObject
+ * instance may be a no-op. Likewise, if no class-specific #AtkObject
+ * implementation is available for the widget instance in question,
+ * it will inherit an #AtkObject implementation from the first ancestor
+ * class for which such an implementation is defined.
  *
  * The documentation of the
- * <ulink url="http://library.gnome.org/devel/atk/stable/">ATK</ulink>
+ * <ulink url="http://developer.gnome.org/atk/stable/">ATK</ulink>
  * library contains more information about accessible objects and their uses.
  *
  * Returns: (transfer none): the #AtkObject associated with @widget
@@ -11928,18 +12037,51 @@ gtk_widget_real_get_accessible (GtkWidget *widget)
                                    quark_accessible_object);
   if (!accessible)
   {
+    GtkWidgetClass *widget_class;
+    GtkWidgetClassPrivate *priv;
     AtkObjectFactory *factory;
     AtkRegistry *default_registry;
 
-    default_registry = atk_get_default_registry ();
-    factory = atk_registry_get_factory (default_registry,
-                                        G_TYPE_FROM_INSTANCE (widget));
-    accessible =
-      atk_object_factory_create_accessible (factory,
-                                           G_OBJECT (widget));
-    g_object_set_qdata (G_OBJECT (widget),
-                        quark_accessible_object,
-                        accessible);
+    widget_class = GTK_WIDGET_GET_CLASS (widget);
+    priv = widget_class->priv;
+
+    if (priv->accessible_type == GTK_TYPE_ACCESSIBLE)
+      {
+        default_registry = atk_get_default_registry ();
+        factory = atk_registry_get_factory (default_registry,
+                                            G_TYPE_FROM_INSTANCE (widget));
+        accessible =
+          atk_object_factory_create_accessible (factory,
+                                                G_OBJECT (widget));
+
+        if (priv->accessible_role != ATK_ROLE_INVALID)
+          atk_object_set_role (accessible, priv->accessible_role);
+
+        g_object_set_qdata (G_OBJECT (widget),
+                            quark_accessible_object,
+                            accessible);
+      }
+    else
+      {
+        accessible = g_object_new (priv->accessible_type,
+                                   "widget", widget,
+                                   NULL);
+        if (priv->accessible_role != ATK_ROLE_INVALID)
+          atk_object_set_role (accessible, priv->accessible_role);
+
+        g_object_set_qdata (G_OBJECT (widget),
+                            quark_accessible_object,
+                            accessible);
+
+        atk_object_initialize (accessible, widget);
+
+        /* Set the role again, since we don't want a role set
+         * in some parent initialize() function to override
+         * our own.
+         */
+        if (priv->accessible_role != ATK_ROLE_INVALID)
+          atk_object_set_role (accessible, priv->accessible_role);
+      }
   }
   return accessible;
 }
@@ -12537,8 +12679,7 @@ gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
        }
       g_object_unref (relation_set);
 
-      g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
-      g_slist_free (atk_relations);
+      g_slist_free_full (atk_relations, (GDestroyNotify) free_relation);
       g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
                          NULL);
     }
@@ -12945,8 +13086,7 @@ gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
           else
             g_warning ("accessibility action on a widget that does not implement AtkAction");
 
-         g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
-         g_slist_free (a11y_data->actions);
+         g_slist_free_full (a11y_data->actions, (GDestroyNotify) free_action);
        }
 
       if (a11y_data->relations)
@@ -13053,7 +13193,7 @@ gtk_widget_set_halign (GtkWidget *widget,
 
   g_return_if_fail (GTK_IS_WIDGET (widget));
 
-  aux_info = _gtk_widget_get_aux_info (widget, TRUE);
+  aux_info = gtk_widget_get_aux_info (widget, TRUE);
 
   if (aux_info->halign == align)
     return;
@@ -13094,7 +13234,7 @@ gtk_widget_set_valign (GtkWidget *widget,
 
   g_return_if_fail (GTK_IS_WIDGET (widget));
 
-  aux_info = _gtk_widget_get_aux_info (widget, TRUE);
+  aux_info = gtk_widget_get_aux_info (widget, TRUE);
 
   if (aux_info->valign == align)
     return;
@@ -13111,6 +13251,8 @@ gtk_widget_set_valign (GtkWidget *widget,
  * Gets the value of the #GtkWidget:margin-left property.
  *
  * Returns: The left margin of @widget
+ *
+ * Since: 3.0
  */
 gint
 gtk_widget_get_margin_left (GtkWidget *widget)
@@ -13127,6 +13269,8 @@ gtk_widget_get_margin_left (GtkWidget *widget)
  *
  * Sets the left margin of @widget.
  * See the #GtkWidget:margin-left property.
+ *
+ * Since: 3.0
  */
 void
 gtk_widget_set_margin_left (GtkWidget *widget,
@@ -13137,7 +13281,7 @@ gtk_widget_set_margin_left (GtkWidget *widget,
   g_return_if_fail (GTK_IS_WIDGET (widget));
   g_return_if_fail (margin <= G_MAXINT16);
 
-  aux_info = _gtk_widget_get_aux_info (widget, TRUE);
+  aux_info = gtk_widget_get_aux_info (widget, TRUE);
 
   if (aux_info->margin.left == margin)
     return;
@@ -13153,7 +13297,9 @@ gtk_widget_set_margin_left (GtkWidget *widget,
  *
  * Gets the value of the #GtkWidget:margin-right property.
  *
- * Returns: The left margin of @widget
+ * Returns: The right margin of @widget
+ *
+ * Since: 3.0
  */
 gint
 gtk_widget_get_margin_right (GtkWidget *widget)
@@ -13170,6 +13316,8 @@ gtk_widget_get_margin_right (GtkWidget *widget)
  *
  * Sets the right margin of @widget.
  * See the #GtkWidget:margin-right property.
+ *
+ * Since: 3.0
  */
 void
 gtk_widget_set_margin_right (GtkWidget *widget,
@@ -13180,7 +13328,7 @@ gtk_widget_set_margin_right (GtkWidget *widget,
   g_return_if_fail (GTK_IS_WIDGET (widget));
   g_return_if_fail (margin <= G_MAXINT16);
 
-  aux_info = _gtk_widget_get_aux_info (widget, TRUE);
+  aux_info = gtk_widget_get_aux_info (widget, TRUE);
 
   if (aux_info->margin.right == margin)
     return;
@@ -13197,6 +13345,8 @@ gtk_widget_set_margin_right (GtkWidget *widget,
  * Gets the value of the #GtkWidget:margin-top property.
  *
  * Returns: The top margin of @widget
+ *
+ * Since: 3.0
  */
 gint
 gtk_widget_get_margin_top (GtkWidget *widget)
@@ -13213,6 +13363,8 @@ gtk_widget_get_margin_top (GtkWidget *widget)
  *
  * Sets the top margin of @widget.
  * See the #GtkWidget:margin-top property.
+ *
+ * Since: 3.0
  */
 void
 gtk_widget_set_margin_top (GtkWidget *widget,
@@ -13223,7 +13375,7 @@ gtk_widget_set_margin_top (GtkWidget *widget,
   g_return_if_fail (GTK_IS_WIDGET (widget));
   g_return_if_fail (margin <= G_MAXINT16);
 
-  aux_info = _gtk_widget_get_aux_info (widget, TRUE);
+  aux_info = gtk_widget_get_aux_info (widget, TRUE);
 
   if (aux_info->margin.top == margin)
     return;
@@ -13240,6 +13392,8 @@ gtk_widget_set_margin_top (GtkWidget *widget,
  * Gets the value of the #GtkWidget:margin-bottom property.
  *
  * Returns: The bottom margin of @widget
+ *
+ * Since: 3.0
  */
 gint
 gtk_widget_get_margin_bottom (GtkWidget *widget)
@@ -13256,6 +13410,8 @@ gtk_widget_get_margin_bottom (GtkWidget *widget)
  *
  * Sets the bottom margin of @widget.
  * See the #GtkWidget:margin-bottom property.
+ *
+ * Since: 3.0
  */
 void
 gtk_widget_set_margin_bottom (GtkWidget *widget,
@@ -13266,7 +13422,7 @@ gtk_widget_set_margin_bottom (GtkWidget *widget,
   g_return_if_fail (GTK_IS_WIDGET (widget));
   g_return_if_fail (margin <= G_MAXINT16);
 
-  aux_info = _gtk_widget_get_aux_info (widget, TRUE);
+  aux_info = gtk_widget_get_aux_info (widget, TRUE);
 
   if (aux_info->margin.bottom == margin)
     return;
@@ -13598,7 +13754,7 @@ gtk_widget_queue_tooltip_query (GtkWidget *widget)
 /**
  * gtk_widget_set_tooltip_text:
  * @widget: a #GtkWidget
- * @text: the contents of the tooltip for @widget
+ * @text: (allow-none): the contents of the tooltip for @widget
  *
  * Sets @text as the contents of the tooltip. This function will take
  * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
@@ -13792,6 +13948,7 @@ gtk_widget_set_allocation (GtkWidget           *widget,
   GtkWidgetPrivate *priv;
 
   g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (gtk_widget_get_visible (widget) || gtk_widget_is_toplevel (widget));
   g_return_if_fail (allocation != NULL);
 
   priv = widget->priv;
@@ -13868,7 +14025,7 @@ gtk_widget_get_requisition (GtkWidget      *widget,
 /**
  * gtk_widget_set_window:
  * @widget: a #GtkWidget
- * @window: a #GdkWindow
+ * @window: (transfer full): a #GdkWindow
  *
  * Sets a widget's window. This function should only be used in a
  * widget's #GtkWidget::realize implementation. The %window passed is
@@ -13898,10 +14055,83 @@ gtk_widget_set_window (GtkWidget *widget,
   if (priv->window != window)
     {
       priv->window = window;
+
+      if (gtk_widget_get_has_window (widget) && window != NULL && !gdk_window_has_native (window))
+       gdk_window_set_opacity (window,
+                               priv->norender ? 0 : priv->alpha / 255.0);
+
       g_object_notify (G_OBJECT (widget), "window");
     }
 }
 
+/**
+ * gtk_widget_register_window:
+ * @widget: a #GtkWidget
+ * @window: a #GdkWindow
+ *
+ * Registers a #GdkWindow with the widget and sets it up so that
+ * the widget recieves events for it. Call gtk_widget_unregister_window()
+ * when destroying the window.
+ *
+ * Before 3.8 you needed to call gdk_window_set_user_data() directly to set
+ * this up. This is now deprecated and you should use gtk_widget_register_window()
+ * instead. Old code will keep working as is, although some new features like
+ * transparency might not work perfectly.
+ *
+ * Since: 3.8
+ */
+void
+gtk_widget_register_window (GtkWidget    *widget,
+                           GdkWindow    *window)
+{
+  GtkWidgetPrivate *priv;
+  gpointer user_data;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (GDK_IS_WINDOW (window));
+
+  gdk_window_get_user_data (window, &user_data);
+  g_assert (user_data == NULL);
+
+  priv = widget->priv;
+
+  gdk_window_set_user_data (window, widget);
+  priv->registered_windows = g_list_prepend (priv->registered_windows, window);
+
+  if (priv->window != window && !gdk_window_has_native (window))
+    gdk_window_set_opacity (window,
+                           priv->norender_children ? 0.0 : 1.0);
+}
+
+/**
+ * gtk_widget_unregister_window:
+ * @widget: a #GtkWidget
+ * @window: a #GdkWindow
+ *
+ * Unregisters a #GdkWindow from the widget that was previously set up with
+ * gtk_widget_register_window(). You need to call this when the window is
+ * no longer used by the widget, such as when you destroy it.
+ *
+ * Since: 3.8
+ */
+void
+gtk_widget_unregister_window (GtkWidget    *widget,
+                             GdkWindow    *window)
+{
+  GtkWidgetPrivate *priv;
+  gpointer user_data;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (GDK_IS_WINDOW (window));
+
+  priv = widget->priv;
+
+  gdk_window_get_user_data (window, &user_data);
+  g_assert (user_data == widget);
+  gdk_window_set_user_data (window, NULL);
+  priv->registered_windows = g_list_remove (priv->registered_windows, window);
+}
+
 /**
  * gtk_widget_get_window:
  * @widget: a #GtkWidget
@@ -13964,6 +14194,211 @@ gtk_widget_set_support_multidevice (GtkWidget *widget,
     gdk_window_set_support_multidevice (priv->window, support_multidevice);
 }
 
+/* There are multiple alpha related sources. First of all the user can specify alpha
+ * in gtk_widget_set_opacity, secondly we can get it from the css opacity. These two
+ * are multiplied together to form the total alpha. Secondly, the user can specify
+ * an opacity group for a widget, which means we must essentially handle it as having alpha.
+ *
+ * We handle opacity in two ways. For a windowed widget, with opacity set but no opacity
+ * group we directly set the opacity of widget->window. This will cause gdk to properly
+ * redirect drawing inside the window to a buffer and do OVER paint_with_alpha.
+ *
+ * However, if the widget is not windowed, or the user specified an opacity group for the
+ * widget we do the opacity handling in the ::draw marshaller for the widget. A naive
+ * implementation of this would break for windowed widgets or descendant widgets with
+ * windows, as these would not be handled by the ::draw signal. To handle this we set
+ * all such gdkwindows as fully transparent and then override gtk_cairo_should_draw_window()
+ * to make the draw signal propagate to *all* child widgets/windows.
+ *
+ * Note: We don't make all child windows fully transparent, we stop at the first one
+ * in each branch when propagating down the hierarchy.
+ */
+
+
+/* This is called when priv->alpha or priv->opacity_group group changes, and should
+ * update priv->norender and GdkWindow opacity for this widget and any children that
+ * needs changing. It is also called whenver the parent changes, the parents
+ * norender_children state changes, or the has_window state of the widget changes.
+ */
+static void
+gtk_widget_propagate_alpha (GtkWidget *widget)
+{
+  GtkWidgetPrivate *priv = widget->priv;
+  GtkWidget *parent;
+  gboolean norender, norender_children;
+  GList *l;
+
+  parent = priv->parent;
+
+  /* Norender affects only windowed widget and means don't render widget->window in the
+     normal fashion.
+     We only set this if the parent has norender_children, because:
+     a) For an opacity group (that does not have a norender_children parent) we still
+     need to render the window or we will never get an expose event.
+     b) For alpha we set the opacity of window->widget directly, so no other
+     work is needed.
+  */
+  norender = (parent != NULL && parent->priv->norender_children);
+
+  /* windows under this widget should not render if:
+     a) This widget has an opacity group
+     b) This widget has alpha and is no-windowed (otherwise we'd set alpha on widget->window)
+     c) This widget has norender but is no-windowed (a windowed widget would "swallow" the norender)
+  */
+  norender_children =
+    priv->opacity_group ||
+    (!gtk_widget_get_has_window (widget) &&
+     ( norender || priv->alpha != 255));
+
+  if (gtk_widget_get_has_window (widget))
+    {
+      if (priv->window != NULL && !gdk_window_has_native (priv->window))
+       gdk_window_set_opacity (priv->window,
+                               norender ? 0 : priv->alpha / 255.0);
+    }
+
+  for (l = priv->registered_windows; l != NULL; l = l->next)
+    {
+      GdkWindow *w = l->data;
+      if (w != priv->window && !gdk_window_has_native (w))
+       gdk_window_set_opacity (w, norender_children ? 0.0 : 1.0);
+    }
+
+  priv->norender = norender;
+  if (priv->norender_children != norender_children)
+    {
+      priv->norender_children = norender_children;
+
+      if (GTK_IS_CONTAINER (widget))
+       gtk_container_forall (GTK_CONTAINER (widget), (GtkCallback)gtk_widget_propagate_alpha, NULL);
+    }
+
+  if (gtk_widget_get_realized (widget))
+    gtk_widget_queue_draw (widget);
+}
+
+static void
+gtk_widget_update_alpha (GtkWidget *widget)
+{
+  GtkWidgetPrivate *priv;
+  double opacity;
+  guint8 alpha;
+
+  priv = widget->priv;
+
+  alpha = priv->user_alpha;
+
+  if (priv->context)
+    {
+      opacity =
+       _gtk_css_number_value_get (_gtk_style_context_peek_property (priv->context,
+                                                                    GTK_CSS_PROPERTY_OPACITY),
+                                  100);
+      opacity = CLAMP (opacity, 0.0, 1.0);
+      alpha = round (priv->user_alpha * opacity);
+    }
+
+  if (alpha == priv->alpha)
+    return;
+
+  priv->alpha = alpha;
+
+  gtk_widget_propagate_alpha (widget);
+
+}
+
+static void
+gtk_widget_set_has_opacity_group  (GtkWidget *widget,
+                                  gboolean has_opacity_group)
+{
+  GtkWidgetPrivate *priv;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+
+  priv = widget->priv;
+
+  has_opacity_group = !!has_opacity_group;
+
+  if (priv->opacity_group == has_opacity_group)
+    return;
+
+  priv->opacity_group = has_opacity_group;
+
+  gtk_widget_propagate_alpha (widget);
+}
+
+/**
+ * gtk_widget_set_opacity:
+ * @widget: a #GtkWidget
+ * @opacity: desired opacity, between 0 and 1
+ *
+ * Request the @widget to be rendered partially transparent,
+ * with opacity 0 being fully transparent and 1 fully opaque. (Opacity values
+ * are clamped to the [0,1] range.).
+ * This works on both toplevel widget, and child widgets, although there
+ * are some limitations:
+ *
+ * For toplevel widgets this depends on the capabilities of the windowing
+ * system. On X11 this has any effect only on X screens with a compositing manager
+ * running. See gtk_widget_is_composited(). On Windows it should work
+ * always, although setting a window's opacity after the window has been
+ * shown causes it to flicker once on Windows.
+ *
+ * For child widgets it doesn't work if any affected widget has a native window, or
+ * disables double buffering.
+ *
+ * Since: 3.8
+ **/
+void
+gtk_widget_set_opacity  (GtkWidget *widget,
+                        gdouble    opacity)
+{
+  GtkWidgetPrivate *priv;
+  guint8 alpha;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+
+  priv = widget->priv;
+
+  opacity = CLAMP (opacity, 0.0, 1.0);
+
+  alpha = round (opacity * 255);
+
+  /* As a kind of hack for internal use we treat an alpha very
+     close to 1.0 (rounds to 255) but not 1.0 as specifying that
+     we want the opacity group behaviour wrt draw handling, but
+     not actually an alpha value. See bug #687842 for discussions. */
+  gtk_widget_set_has_opacity_group (widget,
+                                   alpha == 255 && opacity != 1.0);
+
+  if (alpha == priv->user_alpha)
+    return;
+
+  priv->user_alpha = alpha;
+
+  gtk_widget_update_alpha (widget);
+
+}
+
+/**
+ * gtk_widget_get_opacity:
+ * @widget: a #GtkWidget
+ *
+ * Fetches the requested opacity for this widget. See
+ * gtk_widget_set_opacity().
+ *
+ * Return value: the requested opacity for this widget.
+ *
+ * Since: 3.8
+ **/
+gdouble
+gtk_widget_get_opacity (GtkWidget *widget)
+{
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), 0.0);
+
+  return widget->priv->alpha / 255.0;
+}
+
 static void
 _gtk_widget_set_has_focus (GtkWidget *widget,
                            gboolean   has_focus)
@@ -14048,19 +14483,6 @@ gtk_widget_in_destruction (GtkWidget *widget)
   return widget->priv->in_destruction;
 }
 
-gboolean
-_gtk_widget_get_resize_pending (GtkWidget *widget)
-{
-  return widget->priv->resize_pending;
-}
-
-void
-_gtk_widget_set_resize_pending (GtkWidget *widget,
-                                gboolean   resize_pending)
-{
-  widget->priv->resize_pending = resize_pending;
-}
-
 gboolean
 _gtk_widget_get_in_reparent (GtkWidget *widget)
 {
@@ -14113,58 +14535,6 @@ _gtk_widget_set_alloc_needed (GtkWidget *widget,
   widget->priv->alloc_needed = alloc_needed;
 }
 
-gboolean
-_gtk_widget_get_width_request_needed (GtkWidget *widget)
-{
-  return widget->priv->width_request_needed;
-}
-
-void
-_gtk_widget_set_width_request_needed (GtkWidget *widget,
-                                      gboolean   width_request_needed)
-{
-  widget->priv->width_request_needed = width_request_needed;
-}
-
-gboolean
-_gtk_widget_get_height_request_needed (GtkWidget *widget)
-{
-  return widget->priv->height_request_needed;
-}
-
-void
-_gtk_widget_set_height_request_needed (GtkWidget *widget,
-                                       gboolean   height_request_needed)
-{
-  widget->priv->height_request_needed = height_request_needed;
-}
-
-gboolean
-_gtk_widget_get_sizegroup_visited (GtkWidget    *widget)
-{
-  return widget->priv->sizegroup_visited;
-}
-
-void
-_gtk_widget_set_sizegroup_visited (GtkWidget    *widget,
-                                  gboolean      visited)
-{
-  widget->priv->sizegroup_visited = visited;
-}
-
-gboolean
-_gtk_widget_get_sizegroup_bumping (GtkWidget    *widget)
-{
-  return widget->priv->sizegroup_bumping;
-}
-
-void
-_gtk_widget_set_sizegroup_bumping (GtkWidget    *widget,
-                                  gboolean      bumping)
-{
-  widget->priv->sizegroup_bumping = bumping;
-}
-
 void
 _gtk_widget_add_sizegroup (GtkWidget    *widget,
                           gpointer      group)
@@ -14200,86 +14570,128 @@ _gtk_widget_get_sizegroups (GtkWidget    *widget)
   return NULL;
 }
 
+void
+_gtk_widget_add_attached_window (GtkWidget    *widget,
+                                 GtkWindow    *window)
+{
+  widget->priv->attached_windows = g_list_prepend (widget->priv->attached_windows, window);
+}
+
+void
+_gtk_widget_remove_attached_window (GtkWidget    *widget,
+                                    GtkWindow    *window)
+{
+  widget->priv->attached_windows = g_list_remove (widget->priv->attached_windows, window);
+}
+
 /**
- * gtk_widget_get_path:
- * @widget: a #GtkWidget
+ * gtk_widget_path_append_for_widget:
+ * @path: a widget path
+ * @widget: the widget to append to the widget path
  *
- * Returns the #GtkWidgetPath representing @widget, if the widget
- * is not connected to a toplevel widget, a partial path will be
- * created.
+ * Appends the data from @widget to the widget hierarchy represented
+ * by @path. This function is a shortcut for adding information from
+ * @widget to the given @path. This includes setting the name or
+ * adding the style classes from @widget.
  *
- * Returns: (transfer none): The #GtkWidgetPath representing @widget
- **/
-GtkWidgetPath *
-gtk_widget_get_path (GtkWidget *widget)
+ * Returns: the position where the data was inserted
+ *
+ * Since: 3.2
+ */
+gint
+gtk_widget_path_append_for_widget (GtkWidgetPath *path,
+                                   GtkWidget     *widget)
 {
-  g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
+  gint pos;
 
-  /* As strange as it may seem, this may happen on object construction.
-   * init() implementations of parent types may eventually call this function,
-   * each with its corresponding GType, which could leave a child
-   * implementation with a wrong widget type in the widget path
-   */
-  if (widget->priv->path &&
-      G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (widget->priv->path))
-    {
-      gtk_widget_path_free (widget->priv->path);
-      widget->priv->path = NULL;
-    }
+  g_return_val_if_fail (path != NULL, 0);
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
 
-  if (!widget->priv->path)
+  pos = gtk_widget_path_append_type (path, G_OBJECT_TYPE (widget));
+
+  if (widget->priv->name)
+    gtk_widget_path_iter_set_name (path, pos, widget->priv->name);
+
+  if (widget->priv->context)
     {
-      GtkWidget *parent;
-      guint pos;
+      GList *classes, *l;
 
-      parent = widget->priv->parent;
+      /* Also add any persistent classes in
+       * the style context the widget path
+       */
+      classes = gtk_style_context_list_classes (widget->priv->context);
 
-      if (parent)
-        widget->priv->path = gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
-      else
-        {
-          /* Widget is either toplevel or unparented, treat both
-           * as toplevels style wise, since there are situations
-           * where style properties might be retrieved on that
-           * situation.
-           */
-          widget->priv->path = gtk_widget_path_new ();
-        }
+      for (l = classes; l; l = l->next)
+        gtk_widget_path_iter_add_class (path, pos, l->data);
+
+      g_list_free (classes);
+    }
 
-      pos = gtk_widget_path_append_type (widget->priv->path, G_OBJECT_TYPE (widget));
+  return pos;
+}
 
-      if (widget->priv->name)
-        gtk_widget_path_iter_set_name (widget->priv->path, pos, widget->priv->name);
+GtkWidgetPath *
+_gtk_widget_create_path (GtkWidget *widget)
+{
+  GtkWidget *parent;
 
-      if (widget->priv->context)
-        {
-          GList *classes, *l;
+  parent = widget->priv->parent;
 
-          /* Also add any persistent classes in
-           * the style context the widget path
-           */
-          classes = gtk_style_context_list_classes (widget->priv->context);
+  if (parent)
+    return gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
+  else
+    {
+      /* Widget is either toplevel or unparented, treat both
+       * as toplevels style wise, since there are situations
+       * where style properties might be retrieved on that
+       * situation.
+       */
+      GtkWidget *attach_widget = NULL;
+      GtkWidgetPath *result;
 
-          for (l = classes; l; l = l->next)
-            gtk_widget_path_iter_add_class (widget->priv->path, pos, l->data);
+      if (GTK_IS_WINDOW (widget))
+        attach_widget = gtk_window_get_attached_to (GTK_WINDOW (widget));
 
-          gtk_style_context_set_path (widget->priv->context,
-                                      widget->priv->path);
+      if (attach_widget != NULL)
+        result = gtk_widget_path_copy (gtk_widget_get_path (attach_widget));
+      else
+        result = gtk_widget_path_new ();
 
-          g_list_free (classes);
-        }
+      gtk_widget_path_append_for_widget (result, widget);
+
+      return result;
     }
+}
+
+/**
+ * gtk_widget_get_path:
+ * @widget: a #GtkWidget
+ *
+ * Returns the #GtkWidgetPath representing @widget, if the widget
+ * is not connected to a toplevel widget, a partial path will be
+ * created.
+ *
+ * Returns: (transfer none): The #GtkWidgetPath representing @widget
+ **/
+GtkWidgetPath *
+gtk_widget_get_path (GtkWidget *widget)
+{
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
+
+  if (!widget->priv->path)
+    widget->priv->path = _gtk_widget_create_path (widget);
 
   return widget->priv->path;
 }
 
-static void
-style_context_changed (GtkStyleContext *context,
-                       gpointer         user_data)
+void
+_gtk_widget_style_context_invalidated (GtkWidget *widget)
 {
-  GtkWidget *widget = user_data;
-
-  gtk_widget_update_pango_context (widget);
+  if (widget->priv->path)
+    {
+      gtk_widget_path_free (widget->priv->path);
+      widget->priv->path = NULL;
+    }
 
   if (gtk_widget_get_realized (widget))
     g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
@@ -14290,9 +14702,6 @@ style_context_changed (GtkStyleContext *context,
        */
       widget->priv->style_update_pending = TRUE;
     }
-
-  if (widget->priv->anchored)
-    gtk_widget_queue_resize (widget);
 }
 
 /**
@@ -14308,33 +14717,151 @@ GtkStyleContext *
 gtk_widget_get_style_context (GtkWidget *widget)
 {
   GtkWidgetPrivate *priv;
-  GtkWidgetPath *path;
 
   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
 
   priv = widget->priv;
   
-  /* updates style context if it exists already */
-  path = gtk_widget_get_path (widget);
-
   if (G_UNLIKELY (priv->context == NULL))
     {
       GdkScreen *screen;
+      GdkFrameClock *frame_clock;
 
-      priv->context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
-                                    "direction", gtk_widget_get_direction (widget),
-                                    NULL);
+      priv->context = gtk_style_context_new ();
 
-      g_signal_connect (widget->priv->context, "changed",
-                        G_CALLBACK (style_context_changed), widget);
+      gtk_style_context_set_state (priv->context, priv->state_flags);
 
       screen = gtk_widget_get_screen (widget);
-
       if (screen)
         gtk_style_context_set_screen (priv->context, screen);
 
-      gtk_style_context_set_path (priv->context, path);
+      frame_clock = gtk_widget_get_frame_clock (widget);
+      if (frame_clock)
+        gtk_style_context_set_frame_clock (priv->context, frame_clock);
+
+      if (priv->parent)
+        gtk_style_context_set_parent (priv->context,
+                                      gtk_widget_get_style_context (priv->parent));
+
+      _gtk_style_context_set_widget (priv->context, widget);
     }
 
   return widget->priv->context;
 }
+
+void
+_gtk_widget_invalidate_style_context (GtkWidget    *widget,
+                                      GtkCssChange  change)
+{
+  GtkWidgetPrivate *priv;
+
+  priv = widget->priv;
+
+  if (priv->context == NULL)
+    return;
+
+  _gtk_style_context_queue_invalidate (priv->context, change);
+}
+
+/**
+ * gtk_widget_get_modifier_mask:
+ * @widget: a #GtkWidget
+ * @intent: the use case for the modifier mask
+ *
+ * Returns the modifier mask the @widget's windowing system backend
+ * uses for a particular purpose.
+ *
+ * See gdk_keymap_get_modifier_mask().
+ *
+ * Returns: the modifier mask used for @intent.
+ *
+ * Since: 3.4
+ **/
+GdkModifierType
+gtk_widget_get_modifier_mask (GtkWidget         *widget,
+                              GdkModifierIntent  intent)
+{
+  GdkDisplay *display;
+
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
+
+  display = gtk_widget_get_display (widget);
+
+  return gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
+                                       intent);
+}
+
+GtkStyle *
+_gtk_widget_get_style (GtkWidget *widget)
+{
+  return widget->priv->style;
+}
+
+void
+_gtk_widget_set_style (GtkWidget *widget,
+                       GtkStyle  *style)
+{
+  widget->priv->style = style;
+}
+
+void
+_gtk_widget_update_parent_muxer (GtkWidget *widget)
+{
+  GtkWidget *parent;
+  GActionMuxer *parent_muxer;
+
+  if (widget->priv->muxer == NULL)
+    return;
+
+  if (GTK_IS_MENU (widget))
+    parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
+  else
+    parent = gtk_widget_get_parent (widget);
+
+  parent_muxer = parent ? _gtk_widget_get_action_muxer (parent) : NULL;
+
+  g_action_muxer_set_parent (widget->priv->muxer, parent_muxer);
+}
+
+GActionMuxer *
+_gtk_widget_get_action_muxer (GtkWidget *widget)
+{
+  if (widget->priv->muxer == NULL)
+    {
+      widget->priv->muxer = g_action_muxer_new ();
+      _gtk_widget_update_parent_muxer (widget);
+    }
+
+  return widget->priv->muxer;
+}
+
+/**
+ * gtk_widget_insert_action_group:
+ * @widget: a #GtkWidget
+ * @name: the prefix for actions in @group
+ * @group: a #GActionGroup
+ *
+ * Inserts @group into @widget. Children of @widget that implement
+ * #GtkActionable can then be associated with actions in @group by
+ * setting their 'action-name' to
+ * @prefix.<replaceable>action-name</replaceable>.
+ *
+ * Since: 3.6
+ */
+void
+gtk_widget_insert_action_group (GtkWidget    *widget,
+                                const gchar  *name,
+                                GActionGroup *group)
+{
+  GActionMuxer *muxer;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (name != NULL);
+
+  muxer = _gtk_widget_get_action_muxer (widget);
+
+  if (group)
+    g_action_muxer_insert (muxer, name, group);
+  else
+    g_action_muxer_remove (muxer, name);
+}