2017-02-10 20:21:38 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gtkwidgetprivate.h"
|
|
|
|
#include "gtkwindow.h"
|
|
|
|
|
|
|
|
typedef struct _CompareInfo CompareInfo;
|
|
|
|
|
2017-02-10 20:50:41 +00:00
|
|
|
enum Axis {
|
|
|
|
HORIZONTAL = 0,
|
|
|
|
VERTICAL = 1
|
|
|
|
};
|
|
|
|
|
2017-02-10 20:21:38 +00:00
|
|
|
struct _CompareInfo
|
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
int x;
|
|
|
|
int y;
|
2017-02-10 20:50:41 +00:00
|
|
|
guint reverse : 1;
|
|
|
|
guint axis : 1;
|
2017-02-10 20:21:38 +00:00
|
|
|
};
|
|
|
|
|
2017-02-10 20:50:41 +00:00
|
|
|
static inline void
|
2018-04-08 09:35:39 +00:00
|
|
|
get_axis_info (const graphene_rect_t *bounds,
|
|
|
|
int axis,
|
|
|
|
int *start,
|
|
|
|
int *end)
|
2017-02-10 20:50:41 +00:00
|
|
|
{
|
|
|
|
if (axis == HORIZONTAL)
|
|
|
|
{
|
2018-04-08 09:35:39 +00:00
|
|
|
*start = bounds->origin.x;
|
|
|
|
*end = bounds->size.width;
|
2017-02-10 20:50:41 +00:00
|
|
|
}
|
|
|
|
else if (axis == VERTICAL)
|
|
|
|
{
|
2018-04-08 09:35:39 +00:00
|
|
|
*start = bounds->origin.y;
|
|
|
|
*end = bounds->size.height;
|
2017-02-10 20:50:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
g_assert(FALSE);
|
|
|
|
}
|
|
|
|
|
2017-02-10 20:21:38 +00:00
|
|
|
/* Utility function, equivalent to g_list_reverse */
|
|
|
|
static void
|
|
|
|
reverse_ptr_array (GPtrArray *arr)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < arr->len / 2; i ++)
|
|
|
|
{
|
|
|
|
void *a = g_ptr_array_index (arr, i);
|
|
|
|
void *b = g_ptr_array_index (arr, arr->len - 1 - i);
|
|
|
|
|
|
|
|
arr->pdata[i] = b;
|
|
|
|
arr->pdata[arr->len - 1 - i] = a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
tab_sort_func (gconstpointer a,
|
|
|
|
gconstpointer b,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2018-04-08 09:35:39 +00:00
|
|
|
graphene_rect_t child_bounds1, child_bounds2;
|
|
|
|
GtkWidget *child1 = *((GtkWidget **)a);
|
|
|
|
GtkWidget *child2 = *((GtkWidget **)b);
|
2017-02-10 20:21:38 +00:00
|
|
|
GtkTextDirection text_direction = GPOINTER_TO_INT (user_data);
|
2018-04-08 09:35:39 +00:00
|
|
|
float y1, y2;
|
2017-02-10 20:21:38 +00:00
|
|
|
|
2018-04-08 09:35:39 +00:00
|
|
|
gtk_widget_compute_bounds (child1, gtk_widget_get_parent (child1), &child_bounds1);
|
|
|
|
gtk_widget_compute_bounds (child2, gtk_widget_get_parent (child2), &child_bounds2);
|
2017-02-10 20:21:38 +00:00
|
|
|
|
2018-04-08 09:35:39 +00:00
|
|
|
y1 = child_bounds1.origin.y + (child_bounds1.size.height / 2.0f);
|
|
|
|
y2 = child_bounds2.origin.y + (child_bounds2.size.height / 2.0f);
|
2017-02-10 20:21:38 +00:00
|
|
|
|
|
|
|
if (y1 == y2)
|
|
|
|
{
|
2018-07-31 18:58:10 +00:00
|
|
|
const float x1 = child_bounds1.origin.x + (child_bounds1.size.width / 2.0f);
|
|
|
|
const float x2 = child_bounds2.origin.x + (child_bounds2.size.width / 2.0f);
|
2017-02-10 20:21:38 +00:00
|
|
|
|
|
|
|
if (text_direction == GTK_TEXT_DIR_RTL)
|
|
|
|
return (x1 < x2) ? 1 : ((x1 == x2) ? 0 : -1);
|
|
|
|
else
|
|
|
|
return (x1 < x2) ? -1 : ((x1 == x2) ? 0 : 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return (y1 < y2) ? -1 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
focus_sort_tab (GtkWidget *widget,
|
|
|
|
GtkDirectionType direction,
|
|
|
|
GPtrArray *focus_order)
|
|
|
|
{
|
|
|
|
GtkTextDirection text_direction = _gtk_widget_get_direction (widget);
|
|
|
|
|
|
|
|
g_ptr_array_sort_with_data (focus_order, tab_sort_func, GINT_TO_POINTER (text_direction));
|
|
|
|
|
|
|
|
if (direction == GTK_DIR_TAB_BACKWARD)
|
|
|
|
reverse_ptr_array (focus_order);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Look for a child in @children that is intermediate between
|
|
|
|
* the focus widget and container. This widget, if it exists,
|
|
|
|
* acts as the starting widget for focus navigation.
|
|
|
|
*/
|
|
|
|
static GtkWidget *
|
|
|
|
find_old_focus (GtkWidget *widget,
|
|
|
|
GPtrArray *children)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < children->len; i ++)
|
|
|
|
{
|
|
|
|
GtkWidget *child = g_ptr_array_index (children, i);
|
|
|
|
GtkWidget *child_ptr = child;
|
|
|
|
|
|
|
|
while (child_ptr && child_ptr != widget)
|
|
|
|
{
|
|
|
|
GtkWidget *parent;
|
|
|
|
|
|
|
|
parent = _gtk_widget_get_parent (child_ptr);
|
|
|
|
|
|
|
|
if (parent && (gtk_widget_get_focus_child (parent) != child_ptr))
|
|
|
|
{
|
|
|
|
child = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
child_ptr = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (child)
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2018-04-08 09:35:39 +00:00
|
|
|
old_focus_coords (GtkWidget *widget,
|
|
|
|
graphene_rect_t *old_focus_bounds)
|
2017-02-10 20:21:38 +00:00
|
|
|
{
|
|
|
|
GtkWidget *toplevel = _gtk_widget_get_toplevel (widget);
|
|
|
|
GtkWidget *old_focus;
|
|
|
|
|
|
|
|
if (GTK_IS_WINDOW (toplevel))
|
|
|
|
{
|
|
|
|
old_focus = gtk_window_get_focus (GTK_WINDOW (toplevel));
|
|
|
|
if (old_focus)
|
2018-04-08 09:35:39 +00:00
|
|
|
return gtk_widget_compute_bounds (old_focus, widget, old_focus_bounds);
|
2017-02-10 20:21:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-02-10 20:50:41 +00:00
|
|
|
axis_compare (gconstpointer a,
|
|
|
|
gconstpointer b,
|
|
|
|
gpointer user_data)
|
2017-02-10 20:21:38 +00:00
|
|
|
{
|
2018-04-08 09:35:39 +00:00
|
|
|
graphene_rect_t bounds1;
|
|
|
|
graphene_rect_t bounds2;
|
2017-02-10 20:21:38 +00:00
|
|
|
CompareInfo *compare = user_data;
|
2018-04-08 09:35:39 +00:00
|
|
|
int start1, end1;
|
|
|
|
int start2, end2;
|
2017-02-10 20:21:38 +00:00
|
|
|
|
2018-04-08 09:35:39 +00:00
|
|
|
gtk_widget_compute_bounds (*((GtkWidget **)a), compare->widget, &bounds1);
|
|
|
|
gtk_widget_compute_bounds (*((GtkWidget **)b), compare->widget, &bounds2);
|
2017-02-10 20:21:38 +00:00
|
|
|
|
2018-04-08 09:35:39 +00:00
|
|
|
get_axis_info (&bounds1, compare->axis, &start1, &end1);
|
|
|
|
get_axis_info (&bounds2, compare->axis, &start2, &end2);
|
2017-02-10 20:21:38 +00:00
|
|
|
|
2018-04-08 09:35:39 +00:00
|
|
|
start1 = start1 + (end1 / 2);
|
|
|
|
start2 = start2 + (end2 / 2);
|
2017-02-10 20:21:38 +00:00
|
|
|
|
2018-04-08 09:35:39 +00:00
|
|
|
if (start1 == start2)
|
2017-02-10 20:21:38 +00:00
|
|
|
{
|
2017-02-10 20:50:41 +00:00
|
|
|
/* Now use origin/bounds to compare the 2 widgets on the other axis */
|
2018-04-08 09:35:39 +00:00
|
|
|
get_axis_info (&bounds1, 1 - compare->axis, &start1, &end1);
|
|
|
|
get_axis_info (&bounds2, 1 - compare->axis, &start2, &end2);
|
2017-02-10 20:50:41 +00:00
|
|
|
|
2018-04-08 09:35:39 +00:00
|
|
|
int x1 = abs (start1 + (end1 / 2) - compare->x);
|
|
|
|
int x2 = abs (start2 + (end2 / 2) - compare->x);
|
2017-02-10 20:21:38 +00:00
|
|
|
|
|
|
|
if (compare->reverse)
|
|
|
|
return (x1 < x2) ? 1 : ((x1 == x2) ? 0 : -1);
|
|
|
|
else
|
|
|
|
return (x1 < x2) ? -1 : ((x1 == x2) ? 0 : 1);
|
|
|
|
}
|
|
|
|
else
|
2018-04-08 09:35:39 +00:00
|
|
|
return (start1 < start2) ? -1 : 1;
|
2017-02-10 20:21:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
focus_sort_left_right (GtkWidget *widget,
|
|
|
|
GtkDirectionType direction,
|
|
|
|
GPtrArray *focus_order)
|
|
|
|
{
|
|
|
|
CompareInfo compare_info;
|
|
|
|
GtkWidget *old_focus = gtk_widget_get_focus_child (widget);
|
2018-04-08 09:35:39 +00:00
|
|
|
graphene_rect_t old_bounds;
|
2017-02-10 20:21:38 +00:00
|
|
|
|
|
|
|
compare_info.widget = widget;
|
|
|
|
compare_info.reverse = (direction == GTK_DIR_LEFT);
|
|
|
|
|
|
|
|
if (!old_focus)
|
|
|
|
old_focus = find_old_focus (widget, focus_order);
|
|
|
|
|
2018-04-08 09:35:39 +00:00
|
|
|
if (old_focus && gtk_widget_compute_bounds (old_focus, widget, &old_bounds))
|
2017-02-10 20:21:38 +00:00
|
|
|
{
|
2018-04-08 09:35:39 +00:00
|
|
|
float compare_y1;
|
|
|
|
float compare_y2;
|
|
|
|
float compare_x;
|
2017-02-10 20:21:38 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Delete widgets from list that don't match minimum criteria */
|
|
|
|
|
2018-04-08 09:35:39 +00:00
|
|
|
compare_y1 = old_bounds.origin.y;
|
|
|
|
compare_y2 = old_bounds.origin.y + old_bounds.size.height;
|
2017-02-10 20:21:38 +00:00
|
|
|
|
|
|
|
if (direction == GTK_DIR_LEFT)
|
2018-04-08 09:35:39 +00:00
|
|
|
compare_x = old_bounds.origin.x;
|
2017-02-10 20:21:38 +00:00
|
|
|
else
|
2018-04-08 09:35:39 +00:00
|
|
|
compare_x = old_bounds.origin.x + old_bounds.size.width;
|
2017-02-10 20:21:38 +00:00
|
|
|
|
|
|
|
for (i = 0; i < focus_order->len; i ++)
|
|
|
|
{
|
|
|
|
GtkWidget *child = g_ptr_array_index (focus_order, i);
|
|
|
|
|
|
|
|
if (child != old_focus)
|
|
|
|
{
|
2018-04-08 09:35:39 +00:00
|
|
|
graphene_rect_t child_bounds;
|
|
|
|
|
|
|
|
if (gtk_widget_compute_bounds (child, widget, &child_bounds))
|
2017-02-10 20:21:38 +00:00
|
|
|
{
|
2018-04-08 09:35:39 +00:00
|
|
|
const float child_y1 = child_bounds.origin.y;
|
|
|
|
const float child_y2 = child_bounds.origin.y + child_bounds.size.height;
|
2017-02-10 20:21:38 +00:00
|
|
|
|
|
|
|
if ((child_y2 <= compare_y1 || child_y1 >= compare_y2) /* No vertical overlap */ ||
|
2018-04-08 09:35:39 +00:00
|
|
|
(direction == GTK_DIR_RIGHT && child_bounds.origin.x + child_bounds.size.width < compare_x) || /* Not to left */
|
|
|
|
(direction == GTK_DIR_LEFT && child_bounds.origin.x > compare_x)) /* Not to right */
|
2017-02-10 20:21:38 +00:00
|
|
|
{
|
|
|
|
g_ptr_array_remove_index (focus_order, i);
|
|
|
|
i --;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_ptr_array_remove_index (focus_order, i);
|
|
|
|
i --;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
compare_info.y = (compare_y1 + compare_y2) / 2;
|
2018-04-08 09:35:39 +00:00
|
|
|
compare_info.x = old_bounds.origin.x + (old_bounds.size.width / 2.0f);
|
2017-02-10 20:21:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* No old focus widget, need to figure out starting x,y some other way
|
|
|
|
*/
|
2018-04-08 09:35:39 +00:00
|
|
|
graphene_rect_t bounds;
|
|
|
|
GtkWidget *parent;
|
|
|
|
graphene_rect_t old_focus_bounds;
|
2017-02-10 20:21:38 +00:00
|
|
|
|
2018-04-08 09:35:39 +00:00
|
|
|
parent = gtk_widget_get_parent (widget);
|
|
|
|
gtk_widget_compute_bounds (widget, parent ? parent : widget, &bounds);
|
2017-02-10 20:21:38 +00:00
|
|
|
|
2018-04-08 09:35:39 +00:00
|
|
|
if (old_focus_coords (widget, &old_focus_bounds))
|
2017-02-10 20:21:38 +00:00
|
|
|
{
|
2018-04-08 09:35:39 +00:00
|
|
|
compare_info.y = old_focus_bounds.origin.y + (old_focus_bounds.size.height / 2.0f);
|
2017-02-10 20:21:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-03-20 14:21:12 +00:00
|
|
|
if (!_gtk_widget_get_has_surface (widget))
|
2018-04-08 09:35:39 +00:00
|
|
|
compare_info.y = bounds.origin.y + bounds.size.height;
|
2017-02-10 20:21:38 +00:00
|
|
|
else
|
2018-04-08 09:35:39 +00:00
|
|
|
compare_info.y = bounds.size.height / 2.0f;
|
2017-02-10 20:21:38 +00:00
|
|
|
}
|
|
|
|
|
2018-03-20 14:21:12 +00:00
|
|
|
if (!_gtk_widget_get_has_surface (widget))
|
2018-04-08 09:35:39 +00:00
|
|
|
compare_info.x = (direction == GTK_DIR_RIGHT) ? bounds.origin.x : bounds.origin.x + bounds.size.width;
|
2017-02-10 20:21:38 +00:00
|
|
|
else
|
2018-04-08 09:35:39 +00:00
|
|
|
compare_info.x = (direction == GTK_DIR_RIGHT) ? 0 : bounds.size.width;
|
2017-02-10 20:21:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-10 20:50:41 +00:00
|
|
|
compare_info.axis = HORIZONTAL;
|
|
|
|
g_ptr_array_sort_with_data (focus_order, axis_compare, &compare_info);
|
2017-02-10 20:21:38 +00:00
|
|
|
|
|
|
|
if (compare_info.reverse)
|
|
|
|
reverse_ptr_array (focus_order);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
focus_sort_up_down (GtkWidget *widget,
|
|
|
|
GtkDirectionType direction,
|
|
|
|
GPtrArray *focus_order)
|
|
|
|
{
|
|
|
|
CompareInfo compare_info;
|
|
|
|
GtkWidget *old_focus = gtk_widget_get_focus_child (widget);
|
2018-04-08 09:35:39 +00:00
|
|
|
graphene_rect_t old_bounds;
|
2017-02-10 20:21:38 +00:00
|
|
|
|
|
|
|
compare_info.widget = widget;
|
|
|
|
compare_info.reverse = (direction == GTK_DIR_UP);
|
|
|
|
|
|
|
|
if (!old_focus)
|
|
|
|
old_focus = find_old_focus (widget, focus_order);
|
|
|
|
|
2018-04-08 09:35:39 +00:00
|
|
|
if (old_focus && gtk_widget_compute_bounds (old_focus, widget, &old_bounds))
|
2017-02-10 20:21:38 +00:00
|
|
|
{
|
2018-04-08 09:35:39 +00:00
|
|
|
float compare_x1;
|
|
|
|
float compare_x2;
|
|
|
|
float compare_y;
|
2017-02-10 20:21:38 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Delete widgets from list that don't match minimum criteria */
|
|
|
|
|
2018-04-08 09:35:39 +00:00
|
|
|
compare_x1 = old_bounds.origin.x;
|
|
|
|
compare_x2 = old_bounds.origin.x + old_bounds.size.width;
|
2017-02-10 20:21:38 +00:00
|
|
|
|
|
|
|
if (direction == GTK_DIR_UP)
|
2018-04-08 09:35:39 +00:00
|
|
|
compare_y = old_bounds.origin.y;
|
2017-02-10 20:21:38 +00:00
|
|
|
else
|
2018-04-08 09:35:39 +00:00
|
|
|
compare_y = old_bounds.origin.y + old_bounds.size.height;
|
2017-02-10 20:21:38 +00:00
|
|
|
|
|
|
|
for (i = 0; i < focus_order->len; i ++)
|
|
|
|
{
|
|
|
|
GtkWidget *child = g_ptr_array_index (focus_order, i);
|
|
|
|
|
|
|
|
if (child != old_focus)
|
|
|
|
{
|
2018-04-08 09:35:39 +00:00
|
|
|
graphene_rect_t child_bounds;
|
|
|
|
|
|
|
|
if (gtk_widget_compute_bounds (child, widget, &child_bounds))
|
2017-02-10 20:21:38 +00:00
|
|
|
{
|
2018-04-08 09:35:39 +00:00
|
|
|
const float child_x1 = child_bounds.origin.x;
|
|
|
|
const float child_x2 = child_bounds.origin.x + child_bounds.size.width;
|
2017-02-10 20:21:38 +00:00
|
|
|
|
|
|
|
if ((child_x2 <= compare_x1 || child_x1 >= compare_x2) /* No horizontal overlap */ ||
|
2018-04-08 09:35:39 +00:00
|
|
|
(direction == GTK_DIR_DOWN && child_bounds.origin.y + child_bounds.size.height < compare_y) || /* Not below */
|
|
|
|
(direction == GTK_DIR_UP && child_bounds.origin.y > compare_y)) /* Not above */
|
2017-02-10 20:21:38 +00:00
|
|
|
{
|
|
|
|
g_ptr_array_remove_index (focus_order, i);
|
|
|
|
i --;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_ptr_array_remove_index (focus_order, i);
|
|
|
|
i --;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
compare_info.x = (compare_x1 + compare_x2) / 2;
|
2018-04-08 09:35:39 +00:00
|
|
|
compare_info.y = old_bounds.origin.y + (old_bounds.size.height / 2.0f);
|
2017-02-10 20:21:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* No old focus widget, need to figure out starting x,y some other way
|
|
|
|
*/
|
2018-04-08 09:35:39 +00:00
|
|
|
GtkWidget *parent;
|
|
|
|
graphene_rect_t bounds;
|
|
|
|
graphene_rect_t old_focus_bounds;
|
2017-02-10 20:21:38 +00:00
|
|
|
|
2018-04-08 09:35:39 +00:00
|
|
|
parent = gtk_widget_get_parent (widget);
|
|
|
|
gtk_widget_compute_bounds (widget, parent ? parent : widget, &bounds);
|
2017-02-10 20:21:38 +00:00
|
|
|
|
2018-04-08 09:35:39 +00:00
|
|
|
if (old_focus_coords (widget, &old_focus_bounds))
|
2017-02-10 20:21:38 +00:00
|
|
|
{
|
2018-04-08 09:35:39 +00:00
|
|
|
compare_info.x = old_focus_bounds.origin.x + (old_focus_bounds.size.width / 2.0f);
|
2017-02-10 20:21:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-03-20 14:21:12 +00:00
|
|
|
if (!_gtk_widget_get_has_surface (widget))
|
2018-04-08 09:35:39 +00:00
|
|
|
compare_info.x = bounds.origin.x + (bounds.size.width / 2.0f);
|
2017-02-10 20:21:38 +00:00
|
|
|
else
|
2018-04-08 09:35:39 +00:00
|
|
|
compare_info.x = bounds.size.width / 2.0f;
|
2017-02-10 20:21:38 +00:00
|
|
|
}
|
|
|
|
|
2018-03-20 14:21:12 +00:00
|
|
|
if (!_gtk_widget_get_has_surface (widget))
|
2018-04-08 09:35:39 +00:00
|
|
|
compare_info.y = (direction == GTK_DIR_DOWN) ? bounds.origin.y : bounds.origin.y + bounds.size.height;
|
2017-02-10 20:21:38 +00:00
|
|
|
else
|
2018-04-08 09:35:39 +00:00
|
|
|
compare_info.y = (direction == GTK_DIR_DOWN) ? 0 : + bounds.size.height;
|
2017-02-10 20:21:38 +00:00
|
|
|
}
|
|
|
|
|
2017-02-10 20:50:41 +00:00
|
|
|
compare_info.axis = VERTICAL;
|
|
|
|
g_ptr_array_sort_with_data (focus_order, axis_compare, &compare_info);
|
2017-02-10 20:21:38 +00:00
|
|
|
|
|
|
|
if (compare_info.reverse)
|
|
|
|
reverse_ptr_array (focus_order);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_widget_focus_sort (GtkWidget *widget,
|
|
|
|
GtkDirectionType direction,
|
|
|
|
GPtrArray *focus_order)
|
|
|
|
{
|
|
|
|
GtkWidget *child;
|
|
|
|
|
2018-03-17 08:54:22 +00:00
|
|
|
g_assert (focus_order != NULL);
|
2017-02-10 20:21:38 +00:00
|
|
|
|
2018-03-17 08:54:22 +00:00
|
|
|
if (focus_order->len == 0)
|
2017-02-10 20:21:38 +00:00
|
|
|
{
|
2018-03-17 08:54:22 +00:00
|
|
|
/* Initialize the list with all realized child widgets */
|
|
|
|
for (child = _gtk_widget_get_first_child (widget);
|
|
|
|
child != NULL;
|
|
|
|
child = _gtk_widget_get_next_sibling (child))
|
|
|
|
{
|
|
|
|
if (_gtk_widget_get_realized (child))
|
|
|
|
g_ptr_array_add (focus_order, child);
|
|
|
|
}
|
2017-02-10 20:21:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Now sort that list depending on @direction */
|
|
|
|
switch (direction)
|
|
|
|
{
|
|
|
|
case GTK_DIR_TAB_FORWARD:
|
|
|
|
case GTK_DIR_TAB_BACKWARD:
|
|
|
|
focus_sort_tab (widget, direction, focus_order);
|
|
|
|
break;
|
|
|
|
case GTK_DIR_UP:
|
|
|
|
case GTK_DIR_DOWN:
|
|
|
|
focus_sort_up_down (widget, direction, focus_order);
|
|
|
|
break;
|
|
|
|
case GTK_DIR_LEFT:
|
|
|
|
case GTK_DIR_RIGHT:
|
|
|
|
focus_sort_left_right (widget, direction, focus_order);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gtk_widget_focus_move (GtkWidget *widget,
|
|
|
|
GtkDirectionType direction,
|
|
|
|
GPtrArray *focus_order)
|
|
|
|
{
|
|
|
|
GtkWidget *focus_child = gtk_widget_get_focus_child (widget);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < focus_order->len; i ++)
|
|
|
|
{
|
|
|
|
GtkWidget *child = g_ptr_array_index (focus_order, i);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|