[gtk+/wip/baedert/children: 53/54] WIP: focus_tab_sort for GtkWIdget
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/baedert/children: 53/54] WIP: focus_tab_sort for GtkWIdget
- Date: Mon, 28 Nov 2016 19:10:20 +0000 (UTC)
commit 81db8687e6f96cb9151dd6c982c14853c66b4cb3
Author: Timm Bäder <mail baedert org>
Date: Sat Nov 26 08:53:18 2016 +0100
WIP: focus_tab_sort for GtkWIdget
gtk/gtkcontainer.c | 5 +-
gtk/gtkcontainerprivate.h | 2 +-
gtk/gtkmenubar.c | 2 +-
gtk/gtkradiobutton.c | 2 +-
gtk/gtkwidget.c | 96 ++++++++++++++++++++++++++++++++++++++++----
gtk/gtkwindow.c | 8 ++--
6 files changed, 96 insertions(+), 19 deletions(-)
---
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index a289ce5..ebf7f85 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -460,7 +460,6 @@ gtk_container_class_init (GtkContainerClass *class)
widget_class->compute_expand = gtk_container_compute_expand;
widget_class->snapshot = gtk_container_snapshot;
widget_class->draw = gtk_container_draw;
- widget_class->focus = gtk_container_focus;
widget_class->get_request_mode = gtk_container_get_request_mode;
class->add = gtk_container_add_unimplemented;
@@ -2241,7 +2240,7 @@ tab_compare (gconstpointer a,
}
static GList *
-gtk_container_focus_sort_tab (GtkContainer *container,
+gtk_container_focus_sort_tab (GtkWidget *container,
GList *children,
GtkDirectionType direction,
GtkWidget *old_focus)
@@ -2615,7 +2614,7 @@ gtk_container_focus_sort_left_right (GtkContainer *container,
* removed.
**/
GList *
-_gtk_container_focus_sort (GtkContainer *container,
+_gtk_container_focus_sort (GtkWidget *container,
GList *children,
GtkDirectionType direction,
GtkWidget *old_focus)
diff --git a/gtk/gtkcontainerprivate.h b/gtk/gtkcontainerprivate.h
index 9a865d6..3f2eff9 100644
--- a/gtk/gtkcontainerprivate.h
+++ b/gtk/gtkcontainerprivate.h
@@ -32,7 +32,7 @@ void _gtk_container_clear_resize_widgets (GtkContainer *container);
gchar* _gtk_container_child_composite_name (GtkContainer *container,
GtkWidget *child);
void _gtk_container_dequeue_resize_handler (GtkContainer *container);
-GList * _gtk_container_focus_sort (GtkContainer *container,
+GList * _gtk_container_focus_sort (GtkWidget *container,
GList *children,
GtkDirectionType direction,
GtkWidget *old_focus);
diff --git a/gtk/gtkmenubar.c b/gtk/gtkmenubar.c
index fa56e09..80723d7 100644
--- a/gtk/gtkmenubar.c
+++ b/gtk/gtkmenubar.c
@@ -694,7 +694,7 @@ _gtk_menu_bar_cycle_focus (GtkMenuBar *menubar,
GList *menubars;
GList *current;
- menubars = _gtk_container_focus_sort (GTK_CONTAINER (toplevel), tmp_menubars,
+ menubars = _gtk_container_focus_sort (GTK_WIDGET (toplevel), tmp_menubars,
dir, GTK_WIDGET (menubar));
g_list_free (tmp_menubars);
diff --git a/gtk/gtkradiobutton.c b/gtk/gtkradiobutton.c
index d38fe95..bc1a441 100644
--- a/gtk/gtkradiobutton.c
+++ b/gtk/gtkradiobutton.c
@@ -650,7 +650,7 @@ gtk_radio_button_focus (GtkWidget *widget,
for (l = priv->group; l; l = l->next)
children = g_list_prepend (children, l->data);
- focus_list = _gtk_container_focus_sort (GTK_CONTAINER (toplevel), children, direction, widget);
+ focus_list = _gtk_container_focus_sort (GTK_WIDGET (toplevel), children, direction, widget);
tmp_list = g_list_find (focus_list, widget);
if (tmp_list)
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index b55d150..5212a69 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -7400,19 +7400,99 @@ gtk_widget_real_style_updated (GtkWidget *widget)
}
static gboolean
+gtk_widget_focus_move (GtkWidget *widget,
+ GList *children,
+ GtkDirectionType direction)
+{
+ GtkWidget *focus_child;
+ GtkWidget *child;
+ GList *l;
+
+ focus_child = gtk_widget_get_focus_child (widget);
+
+ l = children;
+ while (l)
+ {
+ child = l->data;
+ l = l->next;
+
+ if (focus_child)
+ {
+ if (focus_child == child)
+ {
+ focus_child = NULL;
+
+ if (gtk_widget_child_focus (child, direction))
+ return TRUE;
+ }
+ }
+ else if (_gtk_widget_is_drawable (child) &&
+ gtk_widget_is_ancestor (child, widget))
+ {
+ if (gtk_widget_child_focus (child, direction))
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+static gboolean
gtk_widget_real_focus (GtkWidget *widget,
GtkDirectionType direction)
{
- if (!gtk_widget_get_can_focus (widget))
- return FALSE;
-
- if (!gtk_widget_is_focus (widget))
+ if (gtk_widget_get_can_focus (widget))
{
- gtk_widget_grab_focus (widget);
- return TRUE;
+ if (!gtk_widget_has_focus (widget))
+ {
+ gtk_widget_grab_focus (widget);
+ return TRUE;
+ }
}
else
- return FALSE;
+ {
+ GtkWidget *child;
+ GList *children = NULL;
+ gboolean ret;
+
+ /* TODO: Focus chain support? */
+ for (child = gtk_widget_get_last_child (widget);
+ child != NULL;
+ child = gtk_widget_get_prev_sibling (child))
+ {
+ children = g_list_prepend (children, child);
+ }
+
+ children = _gtk_container_focus_sort (widget, children, direction, NULL);
+
+ /* Get a list of the containers children, allowing focus
+ * chain to override.
+ */
+ /*if (priv->has_focus_chain)*/
+ /*children = g_list_copy (get_focus_chain (container));*/
+ /*else*/
+ /*children = gtk_container_get_all_children (container);*/
+#if 0
+ if (priv->has_focus_chain &&
+ (direction == GTK_DIR_TAB_FORWARD ||
+ direction == GTK_DIR_TAB_BACKWARD))
+ {
+ sorted_children = g_list_copy (children);
+
+ if (direction == GTK_DIR_TAB_BACKWARD)
+ sorted_children = g_list_reverse (sorted_children);
+ }
+ else
+ sorted_children = _gtk_container_focus_sort (container, children, direction, NULL);
+#endif
+
+ ret = gtk_widget_focus_move (widget, children, direction);
+ g_list_free (children);
+
+ return ret;
+ }
+
+ return FALSE;
}
static void
@@ -15840,8 +15920,6 @@ gtk_widget_should_propagate_draw (GtkWidget *widget,
GtkWidget *child,
cairo_t *cr)
{
- GdkWindow *child_in_window;
-
if (!_gtk_widget_is_drawable (child))
return FALSE;
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index da70a89..d210885 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -2539,7 +2539,7 @@ gtk_window_set_focus (GtkWindow *window,
while ((parent = _gtk_widget_get_parent (widget)))
{
widget = parent;
- gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
+ gtk_widget_set_focus_child (widget, NULL);
}
}
@@ -8011,7 +8011,7 @@ gtk_window_focus (GtkWidget *widget,
parent = _gtk_widget_get_parent (priv->focus_widget);
while (parent)
{
- gtk_container_set_focus_child (GTK_CONTAINER (parent), NULL);
+ gtk_widget_set_focus_child (parent, NULL);
parent = _gtk_widget_get_parent (parent);
}
@@ -8216,7 +8216,7 @@ _gtk_window_unset_focus_and_default (GtkWindow *window,
g_object_ref (widget);
parent = _gtk_widget_get_parent (widget);
- if (gtk_container_get_focus_child (GTK_CONTAINER (parent)) == widget)
+ if (gtk_widget_get_focus_child (parent) == widget)
{
child = priv->focus_widget;
@@ -10414,7 +10414,7 @@ gtk_window_activate_menubar (GtkWindow *window,
if (tmp_menubars == NULL)
return FALSE;
- menubars = _gtk_container_focus_sort (GTK_CONTAINER (window), tmp_menubars,
+ menubars = _gtk_container_focus_sort (GTK_WIDGET (window), tmp_menubars,
GTK_DIR_TAB_FORWARD, NULL);
g_list_free (tmp_menubars);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]