+ else
+ gdk_display_beep (gtk_widget_get_display (GTK_WIDGET (notebook)));
+}
+
+static GtkDirectionType
+get_effective_direction (GtkNotebook *notebook,
+ GtkDirectionType direction)
+{
+ /* Remap the directions into the effective direction it would be for a
+ * GTK_POS_TOP notebook
+ */
+
+#define D(rest) GTK_DIR_##rest
+
+ static const GtkDirectionType translate_direction[2][4][6] = {
+ /* LEFT */ {{ D(TAB_FORWARD), D(TAB_BACKWARD), D(LEFT), D(RIGHT), D(UP), D(DOWN) },
+ /* RIGHT */ { D(TAB_BACKWARD), D(TAB_FORWARD), D(LEFT), D(RIGHT), D(DOWN), D(UP) },
+ /* TOP */ { D(TAB_FORWARD), D(TAB_BACKWARD), D(UP), D(DOWN), D(LEFT), D(RIGHT) },
+ /* BOTTOM */ { D(TAB_BACKWARD), D(TAB_FORWARD), D(DOWN), D(UP), D(LEFT), D(RIGHT) }},
+ /* LEFT */ {{ D(TAB_BACKWARD), D(TAB_FORWARD), D(LEFT), D(RIGHT), D(DOWN), D(UP) },
+ /* RIGHT */ { D(TAB_FORWARD), D(TAB_BACKWARD), D(LEFT), D(RIGHT), D(UP), D(DOWN) },
+ /* TOP */ { D(TAB_FORWARD), D(TAB_BACKWARD), D(UP), D(DOWN), D(RIGHT), D(LEFT) },
+ /* BOTTOM */ { D(TAB_BACKWARD), D(TAB_FORWARD), D(DOWN), D(UP), D(RIGHT), D(LEFT) }},
+ };
+
+#undef D
+
+ int text_dir = gtk_widget_get_direction (GTK_WIDGET (notebook)) == GTK_TEXT_DIR_RTL ? 1 : 0;
+
+ return translate_direction[text_dir][notebook->tab_pos][direction];
+}
+
+static gint
+get_effective_tab_pos (GtkNotebook *notebook)
+{
+ if (gtk_widget_get_direction (GTK_WIDGET (notebook)) == GTK_TEXT_DIR_RTL)
+ {
+ switch (notebook->tab_pos)
+ {
+ case GTK_POS_LEFT:
+ return GTK_POS_RIGHT;
+ case GTK_POS_RIGHT:
+ return GTK_POS_LEFT;
+ default: ;
+ }
+ }
+
+ return notebook->tab_pos;
+}
+
+static void
+gtk_notebook_move_focus_out (GtkNotebook *notebook,
+ GtkDirectionType direction_type)
+{
+ GtkDirectionType effective_direction = get_effective_direction (notebook, direction_type);
+ GtkWidget *toplevel;
+
+ if (GTK_CONTAINER (notebook)->focus_child && effective_direction == GTK_DIR_UP)
+ if (focus_tabs_in (notebook))
+ return;
+ if (gtk_widget_is_focus (GTK_WIDGET (notebook)) && effective_direction == GTK_DIR_DOWN)
+ if (focus_child_in (notebook, GTK_DIR_TAB_FORWARD))
+ return;
+
+ /* At this point, we know we should be focusing out of the notebook entirely. We
+ * do this by setting a flag, then propagating the focus motion to the notebook.
+ */
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (notebook));
+ if (!GTK_WIDGET_TOPLEVEL (toplevel))
+ return;
+
+ g_object_ref (notebook);
+
+ notebook->focus_out = TRUE;
+ g_signal_emit_by_name (toplevel, "move_focus", direction_type);
+ notebook->focus_out = FALSE;
+
+ g_object_unref (notebook);
+