So now it can actually fail.
It doesn't yet though.
baseline);
}
-static void
+static gboolean
demo_tagged_entry_grab_focus (GtkWidget *widget)
{
DemoTaggedEntry *entry = DEMO_TAGGED_ENTRY (widget);
DemoTaggedEntryPrivate *priv = demo_tagged_entry_get_instance_private (entry);
- gtk_widget_grab_focus (priv->entry);
+ return gtk_widget_grab_focus (priv->entry);
}
static void
GValue *value,
GParamSpec *spec);
-static void gtk_combo_box_grab_focus (GtkWidget *widget);
+static gboolean gtk_combo_box_grab_focus (GtkWidget *widget);
static void gtk_combo_box_button_toggled (GtkWidget *widget,
gpointer data);
static void gtk_combo_box_add (GtkContainer *container,
return TRUE;
}
-static void
+static gboolean
gtk_combo_box_grab_focus (GtkWidget *widget)
{
GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
child = gtk_bin_get_child (GTK_BIN (combo_box));
if (child)
- gtk_widget_grab_focus (child);
+ return gtk_widget_grab_focus (child);
+ else
+ return FALSE;
}
else
- gtk_widget_grab_focus (priv->button);
+ return gtk_widget_grab_focus (priv->button);
}
static void
G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE,
gtk_entry_cell_editable_init))
-static void
+static gboolean
gtk_entry_grab_focus (GtkWidget *widget)
{
GtkEntry *entry = GTK_ENTRY (widget);
GtkEntryPrivate *priv = gtk_entry_get_instance_private (entry);
- gtk_widget_grab_focus (priv->text);
+ return gtk_widget_grab_focus (priv->text);
}
static gboolean
static void gtk_file_chooser_entry_finalize (GObject *object);
static void gtk_file_chooser_entry_dispose (GObject *object);
-static void gtk_file_chooser_entry_grab_focus (GtkWidget *widget);
+static gboolean gtk_file_chooser_entry_grab_focus (GtkWidget *widget);
static gboolean gtk_file_chooser_entry_tab_handler (GtkEventControllerKey *key,
guint keyval,
guint keycode,
gtk_widget_error_bell (GTK_WIDGET (chooser_entry));
}
-static void
+static gboolean
gtk_file_chooser_entry_grab_focus (GtkWidget *widget)
{
- GTK_WIDGET_CLASS (_gtk_file_chooser_entry_parent_class)->grab_focus (widget);
+ if (!GTK_WIDGET_CLASS (_gtk_file_chooser_entry_parent_class)->grab_focus (widget))
+ return FALSE;
+
_gtk_file_chooser_entry_select_filename (GTK_FILE_CHOOSER_ENTRY (widget));
+ return TRUE;
}
static void
GdkNotifyType detail,
gpointer data);
-static void gtk_label_grab_focus (GtkWidget *widget);
+static gboolean gtk_label_grab_focus (GtkWidget *widget);
static gboolean gtk_label_query_tooltip (GtkWidget *widget,
gint x,
gtk_label_select_region_index (label, min, max);
}
-static void
+static gboolean
gtk_label_grab_focus (GtkWidget *widget)
{
GtkLabel *label = GTK_LABEL (widget);
GList *l;
if (priv->select_info == NULL)
- return;
+ return FALSE;
- GTK_WIDGET_CLASS (gtk_label_parent_class)->grab_focus (widget);
+ if (!GTK_WIDGET_CLASS (gtk_label_parent_class)->grab_focus (widget))
+ return FALSE;
if (priv->select_info->selectable)
{
}
}
}
+
+ return TRUE;
}
static gboolean
G_OBJECT_CLASS (gtk_list_box_row_parent_class)->dispose (object);
}
-static void
+static gboolean
gtk_list_box_row_grab_focus (GtkWidget *widget)
{
GtkListBoxRow *row = GTK_LIST_BOX_ROW (widget);
GtkListBox *box = gtk_list_box_row_get_box (row);
- g_return_if_fail (box != NULL);
+ g_return_val_if_fail (box != NULL, FALSE);
+
+ if (!GTK_WIDGET_CLASS (gtk_list_box_row_parent_class)->grab_focus (widget))
+ return FALSE;
if (BOX_PRIV (box)->cursor_row != row)
gtk_list_box_update_cursor (box, row, FALSE);
- GTK_WIDGET_CLASS (gtk_list_box_row_parent_class)->grab_focus (widget);
+ return TRUE;
}
static void
return atk_obj;
}
-static void
+static gboolean
gtk_password_entry_grab_focus (GtkWidget *widget)
{
GtkPasswordEntry *entry = GTK_PASSWORD_ENTRY (widget);
GtkPasswordEntryPrivate *priv = gtk_password_entry_get_instance_private (entry);
- gtk_widget_grab_focus (priv->entry);
+ return gtk_widget_grab_focus (priv->entry);
}
static gboolean
return atk_obj;
}
-static void
+static gboolean
gtk_search_entry_grab_focus (GtkWidget *widget)
{
GtkSearchEntry *entry = GTK_SEARCH_ENTRY (widget);
GtkSearchEntryPrivate *priv = gtk_search_entry_get_instance_private (entry);
- gtk_text_grab_focus_without_selecting (GTK_TEXT (priv->entry));
+ return gtk_text_grab_focus_without_selecting (GTK_TEXT (priv->entry));
}
static gboolean
GTK_TYPE_SCROLL_TYPE, scroll)
-static void
+static gboolean
gtk_spin_button_grab_focus (GtkWidget *widget)
{
GtkSpinButton *spin_button = GTK_SPIN_BUTTON (widget);
GtkSpinButtonPrivate *priv = gtk_spin_button_get_instance_private (spin_button);
- gtk_widget_grab_focus (priv->entry);
+ return gtk_widget_grab_focus (priv->entry);
}
static gboolean
GtkSpinButton *spin_button = GTK_SPIN_BUTTON (widget);
GtkSpinButtonPrivate *priv = gtk_spin_button_get_instance_private (spin_button);
- gtk_widget_grab_focus (priv->entry);
-
- return TRUE;
+ return gtk_widget_grab_focus (priv->entry);
}
static void
GtkSnapshot *snapshot);
static void gtk_text_focus_in (GtkWidget *widget);
static void gtk_text_focus_out (GtkWidget *widget);
-static void gtk_text_grab_focus (GtkWidget *widget);
+static gboolean gtk_text_grab_focus (GtkWidget *widget);
static void gtk_text_style_updated (GtkWidget *widget);
static void gtk_text_direction_changed (GtkWidget *widget,
GtkTextDirection previous_dir);
g_signal_handlers_disconnect_by_func (keymap, keymap_direction_changed, self);
}
-static void
+static gboolean
gtk_text_grab_focus (GtkWidget *widget)
{
GtkText *self = GTK_TEXT (widget);
GtkTextPrivate *priv = gtk_text_get_instance_private (self);
gboolean select_on_focus;
- GTK_WIDGET_CLASS (gtk_text_parent_class)->grab_focus (GTK_WIDGET (self));
+ if (!GTK_WIDGET_CLASS (gtk_text_parent_class)->grab_focus (GTK_WIDGET (self)))
+ return FALSE;
if (priv->editable && !priv->in_click)
{
if (select_on_focus)
gtk_text_set_selection_bounds (self, 0, -1);
}
+
+ return TRUE;
}
/**
* You only want to call this on some special entries
* which the user usually doesn't want to replace all text in,
* such as search-as-you-type entries.
+ *
+ * Returns: %TRUE if focus is now inside @self
*/
-void
+gboolean
gtk_text_grab_focus_without_selecting (GtkText *self)
{
- g_return_if_fail (GTK_IS_TEXT (self));
+ g_return_val_if_fail (GTK_IS_TEXT (self), FALSE);
- GTK_WIDGET_CLASS (gtk_text_parent_class)->grab_focus (GTK_WIDGET (self));
+ return GTK_WIDGET_CLASS (gtk_text_parent_class)->grab_focus (GTK_WIDGET (self));
}
static void
PangoTabArray * gtk_text_get_tabs (GtkText *self);
GDK_AVAILABLE_IN_ALL
-void gtk_text_grab_focus_without_selecting (GtkText *self);
+gboolean gtk_text_grab_focus_without_selecting (GtkText *self);
GDK_AVAILABLE_IN_ALL
void gtk_text_set_extra_menu (GtkText *self,
static gint gtk_tree_view_focus (GtkWidget *widget,
GtkDirectionType direction);
-static void gtk_tree_view_grab_focus (GtkWidget *widget);
+static gboolean gtk_tree_view_grab_focus (GtkWidget *widget);
static void gtk_tree_view_style_updated (GtkWidget *widget);
/* container signals */
return FALSE;
case GTK_DIR_TAB_FORWARD:
case GTK_DIR_DOWN:
- gtk_widget_grab_focus (widget);
- return TRUE;
+ return gtk_widget_grab_focus (widget);
default:
g_assert_not_reached ();
return FALSE;
/* Case 2. We don't have focus at all. */
if (!gtk_widget_has_focus (widget))
{
- gtk_widget_grab_focus (widget);
- return TRUE;
+ return gtk_widget_grab_focus (widget);
}
/* Case 3. We have focus already. */
return FALSE;
/* Other directions caught by the keybindings */
- gtk_widget_grab_focus (widget);
- return TRUE;
+ return gtk_widget_grab_focus (widget);
}
-static void
+static gboolean
gtk_tree_view_grab_focus (GtkWidget *widget)
{
- GTK_WIDGET_CLASS (gtk_tree_view_parent_class)->grab_focus (widget);
+ if (!GTK_WIDGET_CLASS (gtk_tree_view_parent_class)->grab_focus (widget))
+ return FALSE;
gtk_tree_view_focus_to_cursor (GTK_TREE_VIEW (widget));
+ return TRUE;
}
static void
static void gtk_widget_real_direction_changed(GtkWidget *widget,
GtkTextDirection previous_direction);
-static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
+static gboolean gtk_widget_real_grab_focus (GtkWidget *focus_widget);
static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
gint x,
gint y,
if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
gtk_widget_activate (widget);
else if (gtk_widget_get_can_focus (widget))
- gtk_widget_grab_focus (widget);
+ return gtk_widget_grab_focus (widget);
else
{
g_warning ("widget '%s' isn't suitable for mnemonic activation",
* Causes @widget (or one of its descendents) to have the keyboard focus
* for the #GtkWindow it's inside.
*
- * @widget must be focusable, or have a ::grab_focus implementation that
- * transfers the focus to a descendant of @widget that is focusable.
+ * If @widget is not focusable, or its ::grab_focus implementation cannot
+ * transfer the focus to a descendant of @widget that is focusable, it will
+ * not take focus and %FALSE will be returned.
+ *
+ * Calling gtk_widget_grab_focus() on an already focused widget is allowed,
+ * should not have an effect, and return %TRUE.
+ *
+ * Returns: %TRUE if focus is now inside @widget.
**/
-void
+gboolean
gtk_widget_grab_focus (GtkWidget *widget)
{
- g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
- GTK_WIDGET_GET_CLASS (widget)->grab_focus (widget);
+ return GTK_WIDGET_GET_CLASS (widget)->grab_focus (widget);
}
-static void
+static gboolean
gtk_widget_real_grab_focus (GtkWidget *focus_widget)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (focus_widget);
- if (priv->root)
- gtk_root_set_focus (priv->root, focus_widget);
+
+ if (!priv->root)
+ return FALSE;
+
+ gtk_root_set_focus (priv->root, focus_widget);
+ return TRUE;
}
static gboolean
gboolean group_cycling);
/* explicit focus */
- void (* grab_focus) (GtkWidget *widget);
+ gboolean (* grab_focus) (GtkWidget *widget);
gboolean (* focus) (GtkWidget *widget,
GtkDirectionType direction);
GDK_AVAILABLE_IN_ALL
gboolean gtk_widget_has_visible_focus (GtkWidget *widget);
GDK_AVAILABLE_IN_ALL
-void gtk_widget_grab_focus (GtkWidget *widget);
+gboolean gtk_widget_grab_focus (GtkWidget *widget);
GDK_AVAILABLE_IN_ALL
void gtk_widget_set_focus_on_click (GtkWidget *widget,
gboolean focus_on_click);