]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtktoolbar.c
filechooserbutton: Don't show the (None) item when the combo box is popped up
[~andy/gtk] / gtk / gtktoolbar.c
index b79cef98e9bccb821e8eb41d87804980bfdc81cd..e4dbfa45eb2aa79e5cf54a8f223a9e3161b264ef 100644 (file)
@@ -17,9 +17,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 "gtkarrow.h"
 #include "gtkbindings.h"
-#include "gtkhbox.h"
+#include "gtkcontainerprivate.h"
 #include "gtkimage.h"
 #include "gtklabel.h"
-#include "gtkmainprivate.h"
+#include "gtkmain.h"
 #include "gtkmarshalers.h"
 #include "gtkmenu.h"
 #include "gtkorientable.h"
+#include "gtkorientableprivate.h"
 #include "gtkradiobutton.h"
 #include "gtkradiotoolbutton.h"
 #include "gtkseparatormenuitem.h"
 #include "gtkseparatortoolitem.h"
 #include "gtkstock.h"
 #include "gtktoolshell.h"
-#include "gtkvbox.h"
+#include "gtkbox.h"
 #include "gtkprivate.h"
 #include "gtkintl.h"
 #include "gtktypebuiltins.h"
+#include "gtkwidgetpath.h"
+#include "gtkwidgetprivate.h"
 
 
 /**
@@ -83,8 +84,6 @@
 
 typedef struct _ToolbarContent ToolbarContent;
 
-#define DEFAULT_IPADDING    0
-
 #define DEFAULT_SPACE_SIZE  12
 #define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_LINE
 #define SPACE_LINE_DIVISION 10.0
@@ -121,8 +120,6 @@ struct _GtkToolbarPrivate
 
   GTimer          *timer;
 
-  GtkWidgetPath   *sibling_path;
-
   gulong           settings_connection;
 
   gint             idle_id;
@@ -218,6 +215,7 @@ static void       gtk_toolbar_get_child_property   (GtkContainer        *contain
                                                    GValue              *value,
                                                    GParamSpec          *pspec);
 static void       gtk_toolbar_finalize             (GObject             *object);
+static void       gtk_toolbar_dispose              (GObject             *object);
 static void       gtk_toolbar_show_all             (GtkWidget           *widget);
 static void       gtk_toolbar_add                  (GtkContainer        *container,
                                                    GtkWidget           *widget);
@@ -233,6 +231,8 @@ static GtkWidgetPath * gtk_toolbar_get_path_for_child
                                                    GtkWidget           *child);
 static void       gtk_toolbar_invalidate_order    (GtkToolbar           *toolbar);
 
+static void       gtk_toolbar_direction_changed    (GtkWidget           *widget,
+                                                    GtkTextDirection     previous_direction);
 static void       gtk_toolbar_orientation_changed  (GtkToolbar          *toolbar,
                                                    GtkOrientation       orientation);
 static void       gtk_toolbar_real_style_changed   (GtkToolbar          *toolbar,
@@ -251,9 +251,7 @@ static gboolean   gtk_toolbar_popup_menu           (GtkWidget           *toolbar
 static void       gtk_toolbar_reconfigured         (GtkToolbar          *toolbar);
 
 static GtkReliefStyle       get_button_relief    (GtkToolbar *toolbar);
-static gint                 get_internal_padding (GtkToolbar *toolbar);
 static gint                 get_max_child_expand (GtkToolbar *toolbar);
-static GtkShadowType        get_shadow_type      (GtkToolbar *toolbar);
 
 /* methods on ToolbarContent 'class' */
 static ToolbarContent *toolbar_content_new_tool_item        (GtkToolbar          *toolbar,
@@ -372,6 +370,7 @@ gtk_toolbar_class_init (GtkToolbarClass *klass)
   gobject_class->set_property = gtk_toolbar_set_property;
   gobject_class->get_property = gtk_toolbar_get_property;
   gobject_class->finalize = gtk_toolbar_finalize;
+  gobject_class->dispose = gtk_toolbar_dispose;
   
   widget_class->button_press_event = gtk_toolbar_button_press;
   widget_class->draw = gtk_toolbar_draw;
@@ -381,6 +380,8 @@ gtk_toolbar_class_init (GtkToolbarClass *klass)
   widget_class->style_updated = gtk_toolbar_style_updated;
   widget_class->focus = gtk_toolbar_focus;
 
+  gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_TOOL_BAR);
+
   /* need to override the base class function via override_class_handler,
    * because the signal slot is not available in GtkWidgetClass
    */
@@ -395,6 +396,7 @@ gtk_toolbar_class_init (GtkToolbarClass *klass)
   widget_class->unmap = gtk_toolbar_unmap;
   widget_class->popup_menu = gtk_toolbar_popup_menu;
   widget_class->show_all = gtk_toolbar_show_all;
+  widget_class->direction_changed = gtk_toolbar_direction_changed;
   
   container_class->add    = gtk_toolbar_add;
   container_class->remove = gtk_toolbar_remove;
@@ -573,13 +575,22 @@ gtk_toolbar_class_init (GtkToolbarClass *klass)
                                                              DEFAULT_SPACE_SIZE,
                                                             GTK_PARAM_READABLE));
   
+  /**
+   * GtkToolbar:internal-padding:
+   *
+   * Amount of border space between the toolbar shadow and the buttons.
+   *
+   * Deprecated: 3.6: Use the standard padding CSS property
+   *   (through objects like #GtkStyleContext and #GtkCssProvider); the value
+   *   of this style property is ignored.
+   */
   gtk_widget_class_install_style_property (widget_class,
                                           g_param_spec_int ("internal-padding",
                                                             P_("Internal padding"),
                                                             P_("Amount of border space between the toolbar shadow and the buttons"),
                                                             0,
                                                             G_MAXINT,
-                                                             DEFAULT_IPADDING,
+                                                             0,
                                                              GTK_PARAM_READABLE));
 
   gtk_widget_class_install_style_property (widget_class,
@@ -606,6 +617,15 @@ gtk_toolbar_class_init (GtkToolbarClass *klass)
                                                               GTK_TYPE_RELIEF_STYLE,
                                                               GTK_RELIEF_NONE,
                                                               GTK_PARAM_READABLE));
+  /**
+   * GtkToolbar:shadow-type:
+   *
+   * Style of bevel around the toolbar.
+   *
+   * Deprecated: 3.6: Use the standard border CSS property
+   *   (through objects like #GtkStyleContext and #GtkCssProvider); the value
+   *   of this style property is ignored.
+   */
   gtk_widget_class_install_style_property (widget_class,
                                            g_param_spec_enum ("shadow-type",
                                                               P_("Shadow type"),
@@ -827,7 +847,7 @@ gtk_toolbar_realize (GtkWidget *widget)
 
   priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
                                       &attributes, attributes_mask);
-  gdk_window_set_user_data (priv->event_window, toolbar);
+  gtk_widget_register_window (widget, priv->event_window);
 }
 
 static void
@@ -838,7 +858,7 @@ gtk_toolbar_unrealize (GtkWidget *widget)
 
   if (priv->event_window)
     {
-      gdk_window_set_user_data (priv->event_window, NULL);
+      gtk_widget_unregister_window (widget, priv->event_window);
       gdk_window_destroy (priv->event_window);
       priv->event_window = NULL;
     }
@@ -853,16 +873,11 @@ gtk_toolbar_draw (GtkWidget *widget,
   GtkToolbar *toolbar = GTK_TOOLBAR (widget);
   GtkToolbarPrivate *priv = toolbar->priv;
   GtkStyleContext *context;
-  GtkStateFlags state;
   GList *list;
   guint border_width;
 
   border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
   context = gtk_widget_get_style_context (widget);
-  state = gtk_widget_get_state_flags (widget);
-
-  gtk_style_context_save (context);
-  gtk_style_context_set_state (context, state);
 
   gtk_render_background (context, cr, border_width, border_width,
                          gtk_widget_get_allocated_width (widget) - 2 * border_width,
@@ -882,11 +897,29 @@ gtk_toolbar_draw (GtkWidget *widget,
                                priv->arrow_button,
                                cr);
 
-  gtk_style_context_restore (context);
-
   return FALSE;
 }
 
+static void
+get_widget_padding_and_border (GtkWidget *widget,
+                               GtkBorder *padding)
+{
+  GtkStyleContext *context;
+  GtkStateFlags state;
+  GtkBorder tmp;
+
+  context = gtk_widget_get_style_context (widget);
+  state = gtk_style_context_get_state (context);
+
+  gtk_style_context_get_padding (context, state, padding);
+  gtk_style_context_get_border (context, state, &tmp);
+
+  padding->top += tmp.top;
+  padding->right += tmp.right;
+  padding->bottom += tmp.bottom;
+  padding->left += tmp.left;
+}
+
 static void
 gtk_toolbar_size_request (GtkWidget      *widget,
                          GtkRequisition *requisition)
@@ -901,7 +934,7 @@ gtk_toolbar_size_request (GtkWidget      *widget,
   gint homogeneous_size;
   gint long_req;
   gint pack_front_size;
-  gint ipadding;
+  GtkBorder padding;
   guint border_width;
   GtkRequisition arrow_requisition;
   
@@ -995,27 +1028,13 @@ gtk_toolbar_size_request (GtkWidget      *widget,
       requisition->height = long_req;
       requisition->width = MAX (max_child_width, arrow_requisition.width);
     }
-  
-  /* Extra spacing */
-  ipadding = get_internal_padding (toolbar);
 
+  /* Extra spacing */
   border_width = gtk_container_get_border_width (GTK_CONTAINER (toolbar));
-  requisition->width += 2 * (ipadding + border_width);
-  requisition->height += 2 * (ipadding + border_width);
-  
-  if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
-    {
-      GtkStyleContext *context;
-      GtkStateFlags state;
-      GtkBorder padding;
-
-      context = gtk_widget_get_style_context (widget);
-      state = gtk_widget_get_state_flags (widget);
-      gtk_style_context_get_padding (context, state, &padding);
+  get_widget_padding_and_border (widget, &padding);
 
-      requisition->width += padding.left + padding.right;
-      requisition->height += padding.top + padding.bottom;
-    }
+  requisition->width += 2 * border_width + padding.left + padding.right;
+  requisition->height += 2 * border_width + padding.top + padding.bottom;
   
   priv->button_maxw = max_homogeneous_child_width;
   priv->button_maxh = max_homogeneous_child_height;
@@ -1243,13 +1262,11 @@ gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
   GtkAllocation allocation;
   GtkWidget *widget = GTK_WIDGET (toolbar);
   GtkToolbarPrivate *priv = toolbar->priv;
-  GtkStyleContext *context;
-  GtkStateFlags state;
-  GtkBorder padding;
   GList *list;
   gint cur_x;
   gint cur_y;
   gint border_width;
+  GtkBorder padding;
   gboolean rtl;
   gboolean vertical;
   
@@ -1267,14 +1284,13 @@ gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
     priv->idle_id = gdk_threads_add_idle (slide_idle_handler, toolbar);
 
   gtk_widget_get_allocation (widget, &allocation);
-  context = gtk_widget_get_style_context (widget);
-  state = gtk_widget_get_state_flags (widget);
-  gtk_style_context_get_padding (context, state, &padding);
 
   rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
   vertical = (priv->orientation == GTK_ORIENTATION_VERTICAL);
-  border_width = get_internal_padding (toolbar) + gtk_container_get_border_width (GTK_CONTAINER (toolbar));
-  
+
+  border_width = gtk_container_get_border_width (GTK_CONTAINER (toolbar));
+  get_widget_padding_and_border (GTK_WIDGET (toolbar), &padding);
+
   if (rtl)
     {
       cur_x = allocation.width - border_width - padding.right;
@@ -1481,8 +1497,6 @@ gtk_toolbar_size_allocate (GtkWidget     *widget,
   GtkAllocation *allocations;
   ItemState *new_states;
   GtkAllocation arrow_allocation;
-  GtkStyleContext *context;
-  GtkStateFlags state;
   GtkBorder padding;
   gint arrow_size;
   gint size, pos, short_size;
@@ -1498,11 +1512,6 @@ gtk_toolbar_size_allocate (GtkWidget     *widget,
   gboolean overflowing;
   gboolean size_changed;
   GtkAllocation item_area;
-  GtkShadowType shadow_type;
-
-  context = gtk_widget_get_style_context (widget);
-  state = gtk_widget_get_state_flags (widget);
-  gtk_style_context_get_padding (context, state, &padding);
 
   gtk_widget_get_allocation (widget, &widget_allocation);
   size_changed = FALSE;
@@ -1528,36 +1537,22 @@ gtk_toolbar_size_allocate (GtkWidget     *widget,
                             allocation->width - border_width * 2,
                             allocation->height - border_width * 2);
 
-  border_width += get_internal_padding (toolbar);
 
   gtk_widget_get_preferred_size (priv->arrow_button,
                                  &arrow_requisition, NULL);
-
-  shadow_type = get_shadow_type (toolbar);
+  get_widget_padding_and_border (widget, &padding);
 
   if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
     {
-      available_size = size = allocation->width - 2 * border_width;
-      short_size = allocation->height - 2 * border_width;
+      available_size = size = allocation->width - 2 * border_width - padding.left - padding.right;
+      short_size = allocation->height - 2 * border_width - padding.top - padding.bottom;
       arrow_size = arrow_requisition.width;
-
-      if (shadow_type != GTK_SHADOW_NONE)
-        {
-          available_size -= padding.left + padding.right;
-          short_size -= padding.top + padding.bottom;
-        }
     }
   else
     {
-      available_size = size = allocation->height - 2 * border_width;
-      short_size = allocation->width - 2 * border_width;
+      available_size = size = allocation->height - 2 * border_width - padding.top - padding.bottom;
+      short_size = allocation->width - 2 * border_width - padding.left - padding.right;
       arrow_size = arrow_requisition.height;
-
-      if (shadow_type != GTK_SHADOW_NONE)
-        {
-          available_size -= padding.top + padding.bottom;
-          short_size -= padding.left + padding.right;
-        }
     }
 
   n_items = g_list_length (priv->content);
@@ -1727,35 +1722,18 @@ gtk_toolbar_size_allocate (GtkWidget     *widget,
   /* translate the items by allocation->(x,y) */
   for (i = 0; i < n_items; ++i)
     {
-      allocations[i].x += allocation->x;
-      allocations[i].y += allocation->y;
-
-      if (shadow_type != GTK_SHADOW_NONE)
-        {
-          allocations[i].x += padding.left;
-          allocations[i].y += padding.top;
-        }
+      allocations[i].x += allocation->x + padding.left;
+      allocations[i].y += allocation->y + padding.top;
     }
 
   if (need_arrow)
     {
-      arrow_allocation.x += allocation->x;
-      arrow_allocation.y += allocation->y;
-
-      if (shadow_type != GTK_SHADOW_NONE)
-        {
-          arrow_allocation.x += padding.left;
-          arrow_allocation.y += padding.top;
-        }
+      arrow_allocation.x += allocation->x + padding.left;
+      arrow_allocation.y += allocation->y + padding.top;
     }
 
-  item_area.x += allocation->x;
-  item_area.y += allocation->y;
-  if (shadow_type != GTK_SHADOW_NONE)
-    {
-      item_area.x += padding.left;
-      item_area.y += padding.top;
-    }
+  item_area.x += allocation->x + padding.left;
+  item_area.y += allocation->y + padding.top;
 
   /* did anything change? */
   for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
@@ -1881,11 +1859,6 @@ gtk_toolbar_style_updated (GtkWidget *widget)
   GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->style_updated (widget);
 
   priv->max_homogeneous_pixels = -1;
-
-  if (gtk_widget_get_realized (widget))
-    gtk_style_context_set_background (gtk_widget_get_style_context (widget),
-                                      gtk_widget_get_window (widget));
-
   gtk_toolbar_update_button_relief (GTK_TOOLBAR (widget));
 }
 
@@ -2119,7 +2092,7 @@ gtk_toolbar_screen_changed (GtkWidget *widget,
   if (old_settings)
     {
       g_signal_handler_disconnect (old_settings, priv->settings_connection);
-
+      priv->settings_connection = 0;
       g_object_unref (old_settings);
     }
 
@@ -2534,34 +2507,34 @@ gtk_toolbar_remove (GtkContainer *container,
 
 static void
 gtk_toolbar_forall (GtkContainer *container,
-                   gboolean      include_internals,
-                   GtkCallback   callback,
-                   gpointer      callback_data)
+                    gboolean      include_internals,
+                    GtkCallback   callback,
+                    gpointer      callback_data)
 {
   GtkToolbar *toolbar = GTK_TOOLBAR (container);
   GtkToolbarPrivate *priv = toolbar->priv;
   GList *list;
-  
+
   g_return_if_fail (callback != NULL);
-  
+
   list = priv->content;
   while (list)
     {
       ToolbarContent *content = list->data;
       GList *next = list->next;
-      
+
       if (include_internals || !toolbar_content_is_placeholder (content))
-       {
-         GtkWidget *child = toolbar_content_get_widget (content);
-         
-         if (child)
-           callback (child, callback_data);
-       }
-      
+        {
+          GtkWidget *child = toolbar_content_get_widget (content);
+
+          if (child)
+            callback (child, callback_data);
+        }
+
       list = next;
     }
-  
-  if (include_internals)
+
+  if (include_internals && priv->arrow_button)
     callback (priv->arrow_button, callback_data);
 }
 
@@ -2606,6 +2579,7 @@ gtk_toolbar_orientation_changed (GtkToolbar    *toolbar,
       
       gtk_toolbar_reconfigured (toolbar);
       
+      _gtk_orientable_set_style_classes (GTK_ORIENTABLE (toolbar));
       gtk_widget_queue_resize (GTK_WIDGET (toolbar));
       g_object_notify (G_OBJECT (toolbar), "orientation");
     }
@@ -2654,7 +2628,7 @@ menu_position_func (GtkMenu  *menu,
                                                   gtk_widget_get_window (priv->arrow_button));
   if (monitor_num < 0)
     monitor_num = 0;
-  gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
+  gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
 
   gtk_widget_get_allocation (priv->arrow_button, &allocation);
 
@@ -2741,7 +2715,7 @@ gtk_toolbar_button_press (GtkWidget      *toolbar,
 {
   GtkWidget *window;
 
-  if (event->button == 3)
+  if (gdk_event_triggers_context_menu ((GdkEvent *) event))
     {
       gboolean return_value;
 
@@ -2752,6 +2726,9 @@ gtk_toolbar_button_press (GtkWidget      *toolbar,
       return return_value;
     }
 
+  if (event->type != GDK_BUTTON_PRESS)
+    return FALSE;
+
   window = gtk_widget_get_toplevel (toolbar);
 
   if (window)
@@ -3128,33 +3105,46 @@ gtk_toolbar_get_drop_index (GtkToolbar *toolbar,
 }
 
 static void
-gtk_toolbar_finalize (GObject *object)
+gtk_toolbar_dispose (GObject *object)
 {
-  GList *list;
   GtkToolbar *toolbar = GTK_TOOLBAR (object);
   GtkToolbarPrivate *priv = toolbar->priv;
 
   if (priv->arrow_button)
-    gtk_widget_unparent (priv->arrow_button);
-
-  for (list = priv->content; list != NULL; list = list->next)
     {
-      ToolbarContent *content = list->data;
-
-      toolbar_content_free (content);
+      gtk_widget_unparent (priv->arrow_button);
+      priv->arrow_button = NULL;
     }
-  
-  g_list_free (priv->content);
-  
-  g_timer_destroy (priv->timer);
-  
+
   if (priv->menu)
     {
       g_signal_handlers_disconnect_by_func (priv->menu,
                                             menu_deactivated, toolbar);
       gtk_widget_destroy (GTK_WIDGET (priv->menu));
+      priv->menu = NULL;
+    }
+
+  if (priv->settings_connection > 0)
+    {
+      g_signal_handler_disconnect (priv->settings, priv->settings_connection);
+      priv->settings_connection = 0;
     }
 
+  g_clear_object (&priv->settings);
+
+ G_OBJECT_CLASS (gtk_toolbar_parent_class)->dispose (object);
+}
+
+static void
+gtk_toolbar_finalize (GObject *object)
+{
+  GtkToolbar *toolbar = GTK_TOOLBAR (object);
+  GtkToolbarPrivate *priv = toolbar->priv;
+
+  g_list_free_full (priv->content, (GDestroyNotify)toolbar_content_free);
+
+  g_timer_destroy (priv->timer);
+
   if (priv->idle_id)
     g_source_remove (priv->idle_id);
 
@@ -3267,6 +3257,16 @@ struct _ToolbarContent
   guint          has_menu : 2;
 };
 
+static void
+toolbar_item_visiblity_notify_cb (GObject *obj,
+                                  GParamSpec *pspec,
+                                  gpointer user_data)
+{
+  GtkToolbar *toolbar = user_data;
+
+  gtk_toolbar_invalidate_order (toolbar);
+}
+
 static ToolbarContent *
 toolbar_content_new_tool_item (GtkToolbar  *toolbar,
                               GtkToolItem *item,
@@ -3283,10 +3283,13 @@ toolbar_content_new_tool_item (GtkToolbar  *toolbar,
   content->is_placeholder = is_placeholder;
 
   priv->content = g_list_insert (priv->content, content, pos);
-  
+
   gtk_widget_set_parent (GTK_WIDGET (item), GTK_WIDGET (toolbar));
   gtk_toolbar_invalidate_order (toolbar);
 
+  g_signal_connect (content->item, "notify::visible",
+                    G_CALLBACK (toolbar_item_visiblity_notify_cb), toolbar);
+
   if (!is_placeholder)
     {
       priv->num_children++;
@@ -3309,6 +3312,10 @@ toolbar_content_remove (ToolbarContent *content,
   gtk_toolbar_invalidate_order (toolbar);
   gtk_widget_unparent (GTK_WIDGET (content->item));
 
+  g_signal_handlers_disconnect_by_func (content->item,
+                                        toolbar_item_visiblity_notify_cb,
+                                        toolbar);
+
   priv->content = g_list_remove (priv->content, content);
 
   if (!toolbar_content_is_placeholder (content))
@@ -3329,18 +3336,12 @@ calculate_max_homogeneous_pixels (GtkWidget *widget)
 {
   PangoContext *context;
   PangoFontMetrics *metrics;
-  const PangoFontDescription *font_desc;
-  GtkStyleContext *style_context;
-  GtkStateFlags state;
   gint char_width;
   
   context = gtk_widget_get_pango_context (widget);
-  style_context = gtk_widget_get_style_context (widget);
-  state = gtk_widget_get_state_flags (widget);
-
-  font_desc = gtk_style_context_get_font (style_context, state);
 
-  metrics = pango_context_get_metrics (context, font_desc,
+  metrics = pango_context_get_metrics (context,
+                                       pango_context_get_font_description (context),
                                       pango_context_get_language (context));
   char_width = pango_font_metrics_get_approximate_char_width (metrics);
   pango_font_metrics_unref (metrics);
@@ -3631,18 +3632,6 @@ get_button_relief (GtkToolbar *toolbar)
   return button_relief;
 }
 
-static gint
-get_internal_padding (GtkToolbar *toolbar)
-{
-  gint ipadding = 0;
-  
-  gtk_widget_style_get (GTK_WIDGET (toolbar),
-                       "internal-padding", &ipadding,
-                       NULL);
-  
-  return ipadding;
-}
-
 static gint
 get_max_child_expand (GtkToolbar *toolbar)
 {
@@ -3654,18 +3643,6 @@ get_max_child_expand (GtkToolbar *toolbar)
   return mexpand;
 }
 
-static GtkShadowType
-get_shadow_type (GtkToolbar *toolbar)
-{
-  GtkShadowType shadow_type;
-  
-  gtk_widget_style_get (GTK_WIDGET (toolbar),
-                       "shadow-type", &shadow_type,
-                       NULL);
-  
-  return shadow_type;
-}
-
 /* GTK+ internal methods */
 
 gint
@@ -3854,6 +3831,9 @@ count_widget_position (GtkWidget *widget,
 {
   CountingData *count = data;
 
+  if (!gtk_widget_get_visible (widget))
+    return;
+
   if (count->widget == widget)
     count->found = TRUE;
   else if (count->found)
@@ -3868,22 +3848,32 @@ gtk_toolbar_get_visible_position (GtkToolbar *toolbar,
 {
   CountingData count = { child, FALSE, 0, 0 };
 
-  /* forall iterates in visible order */
+  if (child == (GtkWidget*)toolbar->priv->highlight_tool_item)
+    return 0;
+
+  /* foreach iterates in visible order */
   gtk_container_forall (GTK_CONTAINER (toolbar),
                         count_widget_position,
                         &count);
 
   g_assert (count.found);
 
-  /* FIXME: rtl */
+  if (toolbar->priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
+      gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
+    return count.after;
+
   return count.before;
 }
 
 static void
-add_widget_to_path (GtkWidget *widget,
-                    gpointer   path)
+add_widget_to_path (gpointer data,
+                    gpointer user_data)
 {
-  gtk_widget_path_append_for_widget (path, widget);
+  GtkWidget *widget = data;
+  GtkWidgetPath *path = user_data;
+
+  if (gtk_widget_get_visible (widget))
+    gtk_widget_path_append_for_widget (path, widget);
 }
 
 static GtkWidgetPath *
@@ -3893,44 +3883,65 @@ gtk_toolbar_get_path_for_child (GtkContainer *container,
   GtkWidgetPath *path;
   GtkToolbar *toolbar;
   GtkToolbarPrivate *priv;
+  GtkWidgetPath *sibling_path;
+  gint vis_index;
+  GList *children;
 
   toolbar = GTK_TOOLBAR (container);
   priv = toolbar->priv;
 
-  if (priv->sibling_path == NULL)
-    {
-      priv->sibling_path = gtk_widget_path_new ();
-      /* forall iterates in visible order */
-      gtk_container_forall (container,
-                            add_widget_to_path,
-                            priv->sibling_path);
-    }
+  /* build a path for all the visible children;
+   * get_children works in visible order
+   */
+  sibling_path = gtk_widget_path_new ();
+  children = _gtk_container_get_all_children (container);
+
+  if (priv->orientation != GTK_ORIENTATION_HORIZONTAL ||
+      gtk_widget_get_direction (GTK_WIDGET (toolbar)) != GTK_TEXT_DIR_RTL)
+    children = g_list_reverse (children);
 
-  path = gtk_widget_path_copy (gtk_widget_get_path (GTK_WIDGET (container)));
+  g_list_foreach (children, add_widget_to_path, sibling_path);
+  g_list_free (children);
+
+  path = _gtk_widget_create_path (GTK_WIDGET (container));
   if (gtk_widget_get_visible (child))
-    gtk_widget_path_append_with_siblings (path,
-                                          priv->sibling_path,
-                                          gtk_toolbar_get_visible_position (toolbar,
-                                                                            child));
+    {
+      vis_index = gtk_toolbar_get_visible_position (toolbar, child);
+
+      if (vis_index < gtk_widget_path_length (sibling_path))
+        gtk_widget_path_append_with_siblings (path,
+                                              sibling_path,
+                                              vis_index);
+      else
+        gtk_widget_path_append_for_widget (path, child);
+    }
   else
     gtk_widget_path_append_for_widget (path, child);
 
+  gtk_widget_path_unref (sibling_path);
   return path;
 }
 
+static void
+gtk_toolbar_invalidate_order_foreach (GtkWidget *widget)
+{
+  _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_POSITION | GTK_CSS_CHANGE_SIBLING_POSITION);
+}
+
 static void
 gtk_toolbar_invalidate_order (GtkToolbar *toolbar)
 {
-  GtkToolbarPrivate *priv = toolbar->priv;
+  gtk_container_forall (GTK_CONTAINER (toolbar),
+                        (GtkCallback) gtk_toolbar_invalidate_order_foreach,
+                        NULL);
+}
 
-  if (priv->sibling_path != NULL)
-    {
-      gtk_widget_path_unref (priv->sibling_path);
-      priv->sibling_path = NULL;
+static void
+gtk_toolbar_direction_changed (GtkWidget        *widget,
+                               GtkTextDirection  previous_direction)
+{
+  GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->direction_changed (widget, previous_direction);
 
-      gtk_container_foreach (GTK_CONTAINER (toolbar),
-                             (GtkCallback) gtk_widget_reset_style,
-                             NULL);
-    }
+  gtk_toolbar_invalidate_order (GTK_TOOLBAR (widget));
 }