2017-04-06 17:17:29 +00:00
|
|
|
|
|
|
|
#include "gtkgizmoprivate.h"
|
|
|
|
#include "gtkwidgetprivate.h"
|
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GtkGizmo, gtk_gizmo, GTK_TYPE_WIDGET);
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_gizmo_measure (GtkWidget *widget,
|
|
|
|
GtkOrientation orientation,
|
|
|
|
int for_size,
|
|
|
|
int *minimum,
|
|
|
|
int *natural,
|
|
|
|
int *minimum_baseline,
|
|
|
|
int *natural_baseline)
|
|
|
|
{
|
|
|
|
GtkGizmo *self = GTK_GIZMO (widget);
|
|
|
|
|
2017-05-04 06:13:07 +00:00
|
|
|
if (self->measure_func)
|
|
|
|
self->measure_func (self, orientation, for_size,
|
|
|
|
minimum, natural,
|
|
|
|
minimum_baseline, natural_baseline);
|
2017-04-06 17:17:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-08-16 04:53:03 +00:00
|
|
|
gtk_gizmo_size_allocate (GtkWidget *widget,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int baseline)
|
2017-04-06 17:17:29 +00:00
|
|
|
{
|
|
|
|
GtkGizmo *self = GTK_GIZMO (widget);
|
|
|
|
|
2017-05-04 06:13:07 +00:00
|
|
|
if (self->allocate_func)
|
2018-08-16 04:53:03 +00:00
|
|
|
self->allocate_func (self, width, height, baseline);
|
2017-04-06 17:17:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_gizmo_snapshot (GtkWidget *widget,
|
|
|
|
GtkSnapshot *snapshot)
|
|
|
|
{
|
|
|
|
GtkGizmo *self = GTK_GIZMO (widget);
|
|
|
|
|
2017-05-03 08:18:41 +00:00
|
|
|
if (self->snapshot_func)
|
|
|
|
self->snapshot_func (self, snapshot);
|
2017-05-11 19:49:37 +00:00
|
|
|
else
|
|
|
|
GTK_WIDGET_CLASS (gtk_gizmo_parent_class)->snapshot (widget, snapshot);
|
2017-04-06 17:17:29 +00:00
|
|
|
}
|
|
|
|
|
2019-04-07 15:47:24 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-05-11 19:52:18 +00:00
|
|
|
static void
|
|
|
|
gtk_gizmo_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkGizmo *self = GTK_GIZMO (object);
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
|
|
widget = _gtk_widget_get_first_child (GTK_WIDGET (self));
|
|
|
|
while (widget != NULL)
|
|
|
|
{
|
|
|
|
GtkWidget *next = _gtk_widget_get_next_sibling (widget);
|
|
|
|
|
|
|
|
gtk_widget_unparent (widget);
|
|
|
|
|
|
|
|
widget = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_gizmo_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2017-04-06 17:17:29 +00:00
|
|
|
static void
|
|
|
|
gtk_gizmo_class_init (GtkGizmoClass *klass)
|
|
|
|
{
|
2017-05-11 19:52:18 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2017-04-06 17:17:29 +00:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
2017-05-11 19:52:18 +00:00
|
|
|
object_class->finalize = gtk_gizmo_finalize;
|
|
|
|
|
2017-04-06 17:17:29 +00:00
|
|
|
widget_class->measure = gtk_gizmo_measure;
|
|
|
|
widget_class->size_allocate = gtk_gizmo_size_allocate;
|
|
|
|
widget_class->snapshot = gtk_gizmo_snapshot;
|
2019-04-07 15:47:24 +00:00
|
|
|
widget_class->contains = gtk_gizmo_contains;
|
2017-04-06 17:17:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_gizmo_init (GtkGizmo *self)
|
|
|
|
{
|
2018-03-20 14:21:12 +00:00
|
|
|
gtk_widget_set_has_surface (GTK_WIDGET (self), FALSE);
|
2017-04-06 17:17:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
gtk_gizmo_new (const char *css_name,
|
|
|
|
GtkGizmoMeasureFunc measure_func,
|
|
|
|
GtkGizmoAllocateFunc allocate_func,
|
2019-04-07 15:47:24 +00:00
|
|
|
GtkGizmoSnapshotFunc snapshot_func,
|
|
|
|
GtkGizmoContainsFunc contains_func)
|
2017-04-06 17:17:29 +00:00
|
|
|
{
|
|
|
|
GtkGizmo *gizmo = GTK_GIZMO (g_object_new (GTK_TYPE_GIZMO,
|
|
|
|
"css-name", css_name,
|
|
|
|
NULL));
|
|
|
|
|
|
|
|
gizmo->measure_func = measure_func;
|
|
|
|
gizmo->allocate_func = allocate_func;
|
|
|
|
gizmo->snapshot_func = snapshot_func;
|
2019-04-07 15:47:24 +00:00
|
|
|
gizmo->contains_func = contains_func;
|
2017-04-06 17:17:29 +00:00
|
|
|
|
|
|
|
return GTK_WIDGET (gizmo);
|
|
|
|
}
|