gizmo: Add a contains_func

Let GtkGizmo override the contains() implementation.
Update all callers to pass NULL for the contains_func.
This commit is contained in:
Matthias Clasen 2019-04-07 15:47:24 +00:00
parent 676ac380cd
commit 5b78a3048f
11 changed files with 45 additions and 32 deletions

View File

@ -46,6 +46,19 @@ gtk_gizmo_snapshot (GtkWidget *widget,
GTK_WIDGET_CLASS (gtk_gizmo_parent_class)->snapshot (widget, snapshot);
}
static gboolean
gtk_gizmo_contains (GtkWidget *widget,
double x,
double y)
{
GtkGizmo *self = GTK_GIZMO (widget);
if (self->contains_func)
return self->contains_func (self, x, y);
else
return GTK_WIDGET_CLASS (gtk_gizmo_parent_class)->contains (widget, x, y);
}
static void
gtk_gizmo_finalize (GObject *object)
{
@ -76,6 +89,7 @@ gtk_gizmo_class_init (GtkGizmoClass *klass)
widget_class->measure = gtk_gizmo_measure;
widget_class->size_allocate = gtk_gizmo_size_allocate;
widget_class->snapshot = gtk_gizmo_snapshot;
widget_class->contains = gtk_gizmo_contains;
}
static void
@ -88,7 +102,8 @@ GtkWidget *
gtk_gizmo_new (const char *css_name,
GtkGizmoMeasureFunc measure_func,
GtkGizmoAllocateFunc allocate_func,
GtkGizmoSnapshotFunc snapshot_func)
GtkGizmoSnapshotFunc snapshot_func,
GtkGizmoContainsFunc contains_func)
{
GtkGizmo *gizmo = GTK_GIZMO (g_object_new (GTK_TYPE_GIZMO,
"css-name", css_name,
@ -97,6 +112,7 @@ gtk_gizmo_new (const char *css_name,
gizmo->measure_func = measure_func;
gizmo->allocate_func = allocate_func;
gizmo->snapshot_func = snapshot_func;
gizmo->contains_func = contains_func;
return GTK_WIDGET (gizmo);
}

View File

@ -27,7 +27,9 @@ typedef void (* GtkGizmoAllocateFunc) (GtkGizmo *gizmo,
int baseline);
typedef void (* GtkGizmoSnapshotFunc) (GtkGizmo *gizmo,
GtkSnapshot *snapshot);
typedef gboolean (* GtkGizmoContainsFunc) (GtkGizmo *gizmo,
double x,
double y);
struct _GtkGizmo
{
@ -36,6 +38,7 @@ struct _GtkGizmo
GtkGizmoMeasureFunc measure_func;
GtkGizmoAllocateFunc allocate_func;
GtkGizmoSnapshotFunc snapshot_func;
GtkGizmoContainsFunc contains_func;
};
struct _GtkGizmoClass
@ -48,7 +51,8 @@ GType gtk_gizmo_get_type (void) G_GNUC_CONST;
GtkWidget *gtk_gizmo_new (const char *css_name,
GtkGizmoMeasureFunc measure_func,
GtkGizmoAllocateFunc allocate_func,
GtkGizmoSnapshotFunc snapshot_func);
GtkGizmoSnapshotFunc snapshot_func,
GtkGizmoContainsFunc contains_func);
#endif

View File

@ -580,7 +580,7 @@ update_block_nodes (GtkLevelBar *self)
priv->block_widget = g_renew (GtkWidget*, priv->block_widget, n_blocks);
for (i = priv->n_blocks; i < n_blocks; i++)
{
priv->block_widget[i] = gtk_gizmo_new ("block", NULL, NULL, NULL);
priv->block_widget[i] = gtk_gizmo_new ("block", NULL, NULL, NULL, NULL);
gtk_widget_insert_before (priv->block_widget[i], GTK_WIDGET (priv->trough_widget), NULL);
}
priv->n_blocks = n_blocks;
@ -1076,7 +1076,8 @@ gtk_level_bar_init (GtkLevelBar *self)
priv->trough_widget = gtk_gizmo_new ("trough",
gtk_level_bar_measure_trough,
gtk_level_bar_allocate_trough,
gtk_level_bar_render_trough);
gtk_level_bar_render_trough,
NULL);
gtk_widget_set_parent (priv->trough_widget, GTK_WIDGET (self));
gtk_level_bar_ensure_offset (self, GTK_LEVEL_BAR_OFFSET_LOW, 0.25);

View File

@ -1294,7 +1294,8 @@ gtk_notebook_init (GtkNotebook *notebook)
priv->tabs_widget = gtk_gizmo_new ("tabs",
gtk_notebook_measure_tabs,
gtk_notebook_allocate_tabs,
gtk_notebook_snapshot_tabs);
gtk_notebook_snapshot_tabs,
NULL);
gtk_widget_set_hexpand (priv->tabs_widget, TRUE);
gtk_container_add (GTK_CONTAINER (priv->header_widget), priv->tabs_widget);
@ -4044,7 +4045,7 @@ gtk_notebook_insert_notebook_page (GtkNotebook *notebook,
else
sibling = priv->arrow_widget[ARROW_RIGHT_AFTER];
page->tab_widget = gtk_gizmo_new ("tab", measure_tab, allocate_tab, NULL);
page->tab_widget = gtk_gizmo_new ("tab", measure_tab, allocate_tab, NULL, NULL);
g_object_set_data (G_OBJECT (page->tab_widget), "notebook", notebook);
gtk_widget_insert_before (page->tab_widget, priv->tabs_widget, sibling);

View File

@ -1366,10 +1366,7 @@ gtk_paned_init (GtkPaned *paned)
gtk_widget_add_controller (GTK_WIDGET (paned), GTK_EVENT_CONTROLLER (gesture));
priv->drag_gesture = gesture;
priv->handle_widget = gtk_gizmo_new ("separator",
NULL,
NULL,
gtk_paned_render_handle);
priv->handle_widget = gtk_gizmo_new ("separator", NULL, NULL, gtk_paned_render_handle, NULL);
gtk_widget_set_parent (priv->handle_widget, GTK_WIDGET (paned));
gtk_widget_set_cursor_from_name (priv->handle_widget, "col-resize");
}

View File

@ -371,10 +371,7 @@ gtk_popover_init (GtkPopover *popover)
G_CALLBACK (node_style_changed_cb), popover, 0);
g_object_unref (priv->arrow_node);
priv->contents_widget = gtk_gizmo_new ("contents",
measure_contents,
allocate_contents,
NULL);
priv->contents_widget = gtk_gizmo_new ("contents", measure_contents, allocate_contents, NULL, NULL);
gtk_widget_set_parent (priv->contents_widget, widget);

View File

@ -481,10 +481,11 @@ gtk_progress_bar_init (GtkProgressBar *pbar)
priv->trough_widget = gtk_gizmo_new ("trough",
NULL,
allocate_trough,
snapshot_trough);
snapshot_trough,
NULL);
gtk_widget_set_parent (priv->trough_widget, GTK_WIDGET (pbar));
priv->progress_widget = gtk_gizmo_new ("progress", NULL, NULL, NULL);
priv->progress_widget = gtk_gizmo_new ("progress", NULL, NULL, NULL, NULL);
gtk_widget_set_parent (priv->progress_widget, priv->trough_widget);
update_node_classes (pbar);

View File

@ -549,11 +549,12 @@ gtk_range_init (GtkRange *range)
priv->trough_widget = gtk_gizmo_new ("trough",
gtk_range_measure_trough,
gtk_range_allocate_trough,
gtk_range_render_trough);
gtk_range_render_trough,
NULL);
gtk_widget_set_parent (priv->trough_widget, GTK_WIDGET (range));
priv->slider_widget = gtk_gizmo_new ("slider", NULL, NULL, NULL);
priv->slider_widget = gtk_gizmo_new ("slider", NULL, NULL, NULL, NULL);
gtk_widget_set_parent (priv->slider_widget, priv->trough_widget);
/* Note: Order is important here.
@ -1122,7 +1123,7 @@ gtk_range_set_show_fill_level (GtkRange *range,
if (show_fill_level)
{
priv->fill_widget = gtk_gizmo_new ("fill", NULL, NULL, NULL);
priv->fill_widget = gtk_gizmo_new ("fill", NULL, NULL, NULL, NULL);
gtk_widget_insert_after (priv->fill_widget, priv->trough_widget, NULL);
update_fill_position (range);
}
@ -2825,7 +2826,7 @@ _gtk_range_set_has_origin (GtkRange *range,
if (has_origin)
{
priv->highlight_widget = gtk_gizmo_new ("highlight", NULL, NULL, NULL);
priv->highlight_widget = gtk_gizmo_new ("highlight", NULL, NULL, NULL, NULL);
gtk_widget_insert_before (priv->highlight_widget, priv->trough_widget, priv->slider_widget);
update_highlight_position (range);

View File

@ -1748,6 +1748,7 @@ gtk_scale_add_mark (GtkScale *scale,
priv->top_marks_widget = gtk_gizmo_new ("marks",
gtk_scale_measure_marks,
gtk_scale_allocate_marks,
NULL,
NULL);
gtk_widget_insert_after (priv->top_marks_widget,
@ -1767,6 +1768,7 @@ gtk_scale_add_mark (GtkScale *scale,
priv->bottom_marks_widget = gtk_gizmo_new ("marks",
gtk_scale_measure_marks,
gtk_scale_allocate_marks,
NULL,
NULL);
gtk_widget_insert_before (priv->bottom_marks_widget,
@ -1780,16 +1782,10 @@ gtk_scale_add_mark (GtkScale *scale,
marks_widget = priv->bottom_marks_widget;
}
mark->widget = gtk_gizmo_new ("mark",
gtk_scale_measure_mark,
gtk_scale_allocate_mark,
NULL);
mark->widget = gtk_gizmo_new ("mark", gtk_scale_measure_mark, gtk_scale_allocate_mark, NULL, NULL);
g_object_set_data (G_OBJECT (mark->widget), "mark", mark);
mark->indicator_widget = gtk_gizmo_new ("indicator",
NULL,
NULL,
NULL);
mark->indicator_widget = gtk_gizmo_new ("indicator", NULL, NULL, NULL, NULL);
gtk_widget_set_parent (mark->indicator_widget, mark->widget);
if (mark->markup && *mark->markup)
{

View File

@ -652,7 +652,7 @@ gtk_switch_init (GtkSwitch *self)
priv->off_image = gtk_image_new_from_icon_name ("switch-off-symbolic");
gtk_widget_set_parent (priv->off_image, GTK_WIDGET (self));
priv->slider = gtk_gizmo_new ("slider", NULL, NULL, NULL);
priv->slider = gtk_gizmo_new ("slider", NULL, NULL, NULL, NULL);
gtk_widget_set_parent (priv->slider, GTK_WIDGET (self));
}

View File

@ -203,8 +203,7 @@ _gtk_text_handle_ensure_widget (GtkTextHandle *handle,
GtkStyleContext *context;
GtkEventController *controller;
widget = gtk_gizmo_new (I_("cursor-handle"),
NULL, NULL, snapshot_func);
widget = gtk_gizmo_new (I_("cursor-handle"), NULL, NULL, snapshot_func, NULL);
gtk_widget_set_direction (widget, priv->windows[pos].dir);