Move set_focus_child to GtkWidget

Move the set_focus_child vfunc from GtkContainer
to GtkWidget. This removes the last focus functionality
from GtkContainer.

Update the two users.
This commit is contained in:
Matthias Clasen 2020-04-19 11:18:02 -04:00
parent eeb41c82d1
commit d756c6e282
6 changed files with 37 additions and 64 deletions

View File

@ -109,8 +109,6 @@ static void gtk_container_remove_unimplemented (GtkContainer *container
static void gtk_container_compute_expand (GtkWidget *widget,
gboolean *hexpand_p,
gboolean *vexpand_p);
static void gtk_container_real_set_focus_child (GtkContainer *container,
GtkWidget *widget);
static void gtk_container_children_callback (GtkWidget *widget,
gpointer client_data);
static GtkSizeRequestMode gtk_container_get_request_mode (GtkWidget *widget);
@ -141,7 +139,6 @@ gtk_container_class_init (GtkContainerClass *class)
class->add = gtk_container_add_unimplemented;
class->remove = gtk_container_remove_unimplemented;
class->forall = NULL;
class->set_focus_child = gtk_container_real_set_focus_child;
class->child_type = NULL;
container_signals[ADD] =
@ -524,31 +521,6 @@ gtk_container_foreach (GtkContainer *container,
GTK_CONTAINER_GET_CLASS (container)->forall (container, callback, callback_data);
}
/**
* gtk_container_set_focus_child:
* @container: a #GtkContainer
* @child: (allow-none): a #GtkWidget, or %NULL
*
* Sets, or unsets if @child is %NULL, the focused child of @container.
*
* This function emits the GtkContainer::set_focus_child signal of
* @container. Implementations of #GtkContainer can override the
* default behaviour by overriding the class closure of this signal.
*
* This is function is mostly meant to be used by widgets. Applications can use
* gtk_widget_grab_focus() to manually set the focus to a specific widget.
*/
void
gtk_container_set_focus_child (GtkContainer *container,
GtkWidget *child)
{
g_return_if_fail (GTK_IS_CONTAINER (container));
if (child)
g_return_if_fail (GTK_IS_WIDGET (child));
GTK_CONTAINER_GET_CLASS (container)->set_focus_child (container, child);
}
/**
* gtk_container_get_children:
* @container: a #GtkContainer
@ -602,12 +574,6 @@ gtk_container_compute_expand (GtkWidget *widget,
*vexpand_p = vexpand;
}
static void
gtk_container_real_set_focus_child (GtkContainer *container,
GtkWidget *focus_child)
{
}
static void
gtk_container_children_callback (GtkWidget *widget,
gpointer client_data)

View File

@ -58,7 +58,6 @@ struct _GtkContainer
* @remove: Signal emitted when a widget is removed from container.
* @forall: Invokes callback on each child of container. The callback handler
* may remove the child.
* @set_focus_child: Sets the focused child of container.
* @child_type: Returns the type of the children supported by the container.
* @set_child_property: Set a property on a child of container.
* @get_child_property: Get a property from a child of container.
@ -78,8 +77,6 @@ struct _GtkContainerClass
void (*forall) (GtkContainer *container,
GtkCallback callback,
gpointer callback_data);
void (*set_focus_child) (GtkContainer *container,
GtkWidget *child);
GType (*child_type) (GtkContainer *container);

View File

@ -769,7 +769,7 @@ static void gtk_notebook_popup_menu (GtkWidget *widget,
const char *action_name,
GVariant *parameters);
static void gtk_notebook_motion (GtkEventController *controller,
double x,
double x,
double y,
gpointer user_data);
static void gtk_notebook_grab_notify (GtkWidget *widget,
@ -781,6 +781,8 @@ static void gtk_notebook_direction_changed (GtkWidget *widget,
static gboolean gtk_notebook_focus (GtkWidget *widget,
GtkDirectionType direction);
static gboolean gtk_notebook_grab_focus (GtkWidget *widget);
static void gtk_notebook_set_focus_child (GtkWidget *widget,
GtkWidget *child);
/*** Drag and drop Methods ***/
static void gtk_notebook_dnd_finished_cb (GdkDrag *drag,
@ -803,8 +805,6 @@ static void gtk_notebook_add (GtkContainer *container,
GtkWidget *widget);
static void gtk_notebook_remove (GtkContainer *container,
GtkWidget *widget);
static void gtk_notebook_set_focus_child (GtkContainer *container,
GtkWidget *child);
static GType gtk_notebook_child_type (GtkContainer *container);
static void gtk_notebook_forall (GtkContainer *container,
GtkCallback callback,
@ -1045,12 +1045,12 @@ gtk_notebook_class_init (GtkNotebookClass *class)
widget_class->direction_changed = gtk_notebook_direction_changed;
widget_class->focus = gtk_notebook_focus;
widget_class->grab_focus = gtk_notebook_grab_focus;
widget_class->set_focus_child = gtk_notebook_set_focus_child;
widget_class->compute_expand = gtk_notebook_compute_expand;
container_class->add = gtk_notebook_add;
container_class->remove = gtk_notebook_remove;
container_class->forall = gtk_notebook_forall;
container_class->set_focus_child = gtk_notebook_set_focus_child;
container_class->child_type = gtk_notebook_child_type;
class->switch_page = gtk_notebook_real_switch_page;
@ -3473,7 +3473,7 @@ focus_tabs_in (GtkNotebook *notebook)
if (notebook->show_tabs && gtk_notebook_has_current_page (notebook))
{
gtk_widget_grab_focus (GTK_WIDGET (notebook));
gtk_notebook_set_focus_child (GTK_CONTAINER (notebook), NULL);
gtk_notebook_set_focus_child (GTK_WIDGET (notebook), NULL);
gtk_notebook_switch_focus_tab (notebook,
g_list_find (notebook->children,
notebook->cur_page));
@ -3725,10 +3725,10 @@ gtk_notebook_grab_focus (GtkWidget *widget)
}
static void
gtk_notebook_set_focus_child (GtkContainer *container,
GtkWidget *child)
gtk_notebook_set_focus_child (GtkWidget *widget,
GtkWidget *child)
{
GtkNotebook *notebook = GTK_NOTEBOOK (container);
GtkNotebook *notebook = GTK_NOTEBOOK (widget);
GtkWidget *page_child;
GtkWidget *toplevel;
@ -3737,13 +3737,13 @@ gtk_notebook_set_focus_child (GtkContainer *container,
* for future use if we switch to the page with a mnemonic.
*/
toplevel = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (container)));
toplevel = GTK_WIDGET (gtk_widget_get_root (widget));
if (GTK_IS_WINDOW (toplevel))
{
page_child = gtk_window_get_focus (GTK_WINDOW (toplevel));
while (page_child)
{
if (gtk_widget_get_parent (page_child) == GTK_WIDGET (container))
if (gtk_widget_get_parent (page_child) == widget)
{
GList *list = gtk_notebook_find_child (notebook, page_child);
if (list != NULL)
@ -3787,7 +3787,7 @@ gtk_notebook_set_focus_child (GtkContainer *container,
else
notebook->child_has_focus = FALSE;
GTK_CONTAINER_CLASS (gtk_notebook_parent_class)->set_focus_child (container, child);
GTK_WIDGET_CLASS (gtk_notebook_parent_class)->set_focus_child (widget, child);
}
static void

View File

@ -240,7 +240,7 @@ static void gtk_paned_calc_position (GtkPaned *paned,
gint allocation,
gint child1_req,
gint child2_req);
static void gtk_paned_set_focus_child (GtkContainer *container,
static void gtk_paned_set_focus_child (GtkWidget *widget,
GtkWidget *child);
static void gtk_paned_set_saved_focus (GtkPaned *paned,
GtkWidget *widget);
@ -351,13 +351,13 @@ gtk_paned_class_init (GtkPanedClass *class)
widget_class->size_allocate = gtk_paned_size_allocate;
widget_class->unrealize = gtk_paned_unrealize;
widget_class->focus = gtk_paned_focus;
widget_class->set_focus_child = gtk_paned_set_focus_child;
widget_class->css_changed = gtk_paned_css_changed;
container_class->add = gtk_paned_add;
container_class->remove = gtk_paned_remove;
container_class->forall = gtk_paned_forall;
container_class->child_type = gtk_paned_child_type;
container_class->set_focus_child = gtk_paned_set_focus_child;
class->cycle_child_focus = gtk_paned_cycle_child_focus;
class->toggle_handle_focus = gtk_paned_toggle_handle_focus;
@ -1870,16 +1870,14 @@ paned_get_focus_widget (GtkPaned *paned)
}
static void
gtk_paned_set_focus_child (GtkContainer *container,
GtkWidget *focus_child)
gtk_paned_set_focus_child (GtkWidget *widget,
GtkWidget *child)
{
GtkPaned *paned = GTK_PANED (container);
GtkPaned *paned = GTK_PANED (widget);
GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned);
GtkWidget *container_focus_child;
GtkWidget *focus_child;
g_return_if_fail (GTK_IS_PANED (container));
if (focus_child == NULL)
if (child == NULL)
{
GtkWidget *last_focus;
GtkWidget *w;
@ -1895,16 +1893,15 @@ gtk_paned_set_focus_child (GtkContainer *container,
if (GTK_IS_PANED (w))
last_focus = w;
container_focus_child = gtk_widget_get_focus_child (GTK_WIDGET (container));
if (container_focus_child == priv->child1)
focus_child = gtk_widget_get_focus_child (widget);
if (focus_child == priv->child1)
gtk_paned_set_last_child1_focus (paned, last_focus);
else if (container_focus_child == priv->child2)
else if (focus_child == priv->child2)
gtk_paned_set_last_child2_focus (paned, last_focus);
}
}
if (GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child)
GTK_CONTAINER_CLASS (gtk_paned_parent_class)->set_focus_child (container, focus_child);
GTK_WIDGET_CLASS (gtk_paned_parent_class)->set_focus_child (widget, child);
}
static void

View File

@ -594,6 +594,8 @@ static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
static void gtk_widget_real_css_changed (GtkWidget *widget,
GtkCssStyleChange *change);
static void gtk_widget_real_set_focus_child (GtkWidget *widget,
GtkWidget *child);
static void gtk_widget_real_move_focus (GtkWidget *widget,
GtkDirectionType direction);
static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
@ -905,6 +907,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
klass->grab_focus = gtk_widget_grab_focus_self;
klass->focus = gtk_widget_focus_all;
klass->set_focus_child = gtk_widget_real_set_focus_child;
klass->move_focus = gtk_widget_real_move_focus;
klass->keynav_failed = gtk_widget_real_keynav_failed;
klass->query_tooltip = gtk_widget_real_query_tooltip;
@ -12000,8 +12003,6 @@ void
gtk_widget_set_focus_child (GtkWidget *widget,
GtkWidget *child)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
g_return_if_fail (GTK_IS_WIDGET (widget));
if (child != NULL)
@ -12010,6 +12011,15 @@ gtk_widget_set_focus_child (GtkWidget *widget,
g_return_if_fail (gtk_widget_get_parent (child) == widget);
}
GTK_WIDGET_GET_CLASS (widget)->set_focus_child (widget, child);
}
static void
gtk_widget_real_set_focus_child (GtkWidget *widget,
GtkWidget *child)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
g_set_object (&priv->focus_child, child);
}

View File

@ -187,6 +187,7 @@ struct _GtkWidget
* @grab_focus: Causes @widget to have the keyboard focus for the
* #GtkWindow its inside.
* @focus: Vfunc for gtk_widget_child_focus()
* @set_focus_child: Sets the focused child of a widget. Must chain up
* @move_focus: Signal emitted when a change of focus is requested
* @keynav_failed: Signal emitted if keyboard navigation fails.
* @get_accessible: Returns the accessible object that describes the
@ -250,6 +251,8 @@ struct _GtkWidgetClass
gboolean (* grab_focus) (GtkWidget *widget);
gboolean (* focus) (GtkWidget *widget,
GtkDirectionType direction);
void (* set_focus_child) (GtkWidget *widget,
GtkWidget *child);
/* keyboard navigation */
void (* move_focus) (GtkWidget *widget,