selection-canvas-item: Use GObject macros to define type

This commit is contained in:
Ernestas Kulik 2018-07-30 13:45:32 +03:00
parent 48c64bd6d8
commit 9b3732e404
3 changed files with 44 additions and 72 deletions

View file

@ -125,6 +125,8 @@ struct _EelCanvasItem {
guint flags; guint flags;
}; };
G_DEFINE_AUTOPTR_CLEANUP_FUNC (EelCanvasItem, g_object_unref)
struct _EelCanvasItemClass { struct _EelCanvasItemClass {
GInitiallyUnownedClass parent_class; GInitiallyUnownedClass parent_class;

View file

@ -43,8 +43,10 @@ typedef struct
int x0, y0, x1, y1; int x0, y0, x1, y1;
} Rect; } Rect;
struct _NautilusSelectionCanvasItemDetails struct _NautilusSelectionCanvasItem
{ {
EelCanvasItem parent_instance;
Rect last_update_rect; Rect last_update_rect;
Rect last_outline_update_rect; Rect last_outline_update_rect;
int last_outline_update_width; int last_outline_update_width;
@ -69,10 +71,10 @@ nautilus_selection_canvas_item_snapshot (EelCanvasItem *item,
self = NAUTILUS_SELECTION_CANVAS_ITEM (item); self = NAUTILUS_SELECTION_CANVAS_ITEM (item);
x1 = MIN (self->priv->x1, self->priv->x2); x1 = MIN (self->x1, self->x2);
y1 = MIN (self->priv->y1, self->priv->y2); y1 = MIN (self->y1, self->y2);
x2 = MAX (self->priv->x1, self->priv->x2); x2 = MAX (self->x1, self->x2);
y2 = MAX (self->priv->y1, self->priv->y2); y2 = MAX (self->y1, self->y2);
context = gtk_widget_get_style_context (GTK_WIDGET (item->canvas)); context = gtk_widget_get_style_context (GTK_WIDGET (item->canvas));
if (EEL_IS_CANVAS_GROUP (item->parent)) if (EEL_IS_CANVAS_GROUP (item->parent))
{ {
@ -121,10 +123,10 @@ nautilus_selection_canvas_item_point (EelCanvasItem *item,
/* Find the bounds for the rectangle plus its outline width */ /* Find the bounds for the rectangle plus its outline width */
x1 = self->priv->x1; x1 = self->x1;
y1 = self->priv->y1; y1 = self->y1;
x2 = self->priv->x2; x2 = self->x2;
y2 = self->priv->y2; y2 = self->y2;
hwidth = (1.0 / item->canvas->pixels_per_unit) / 2.0; hwidth = (1.0 / item->canvas->pixels_per_unit) / 2.0;
@ -303,7 +305,6 @@ nautilus_selection_canvas_item_update (EelCanvasItem *item,
gint flags) gint flags)
{ {
NautilusSelectionCanvasItem *self; NautilusSelectionCanvasItem *self;
NautilusSelectionCanvasItemDetails *priv;
double x1, y1, x2, y2; double x1, y1, x2, y2;
int repaint_rects_count, i; int repaint_rects_count, i;
GtkStyleContext *context; GtkStyleContext *context;
@ -316,15 +317,14 @@ nautilus_selection_canvas_item_update (EelCanvasItem *item,
} }
self = NAUTILUS_SELECTION_CANVAS_ITEM (item); self = NAUTILUS_SELECTION_CANVAS_ITEM (item);
priv = self->priv;
x1 = priv->x1; x1 = self->x1;
y1 = priv->y1; y1 = self->y1;
x2 = priv->x2; x2 = self->x2;
y2 = priv->y2; y2 = self->y2;
update_rect = make_rect (x1, y1, x2 + 1, y2 + 1); update_rect = make_rect (x1, y1, x2 + 1, y2 + 1);
diff_rects (update_rect, priv->last_update_rect, diff_rects (update_rect, self->last_update_rect,
&repaint_rects_count, repaint_rects); &repaint_rects_count, repaint_rects);
for (i = 0; i < repaint_rects_count; i++) for (i = 0; i < repaint_rects_count; i++)
{ {
@ -333,7 +333,7 @@ nautilus_selection_canvas_item_update (EelCanvasItem *item,
repaint_rects[i].x1, repaint_rects[i].y1); repaint_rects[i].x1, repaint_rects[i].y1);
} }
priv->last_update_rect = update_rect; self->last_update_rect = update_rect;
context = gtk_widget_get_style_context (GTK_WIDGET (item->canvas)); context = gtk_widget_get_style_context (GTK_WIDGET (item->canvas));
@ -350,10 +350,10 @@ nautilus_selection_canvas_item_update (EelCanvasItem *item,
update_rect = make_rect (x1, y1, x2, y2); update_rect = make_rect (x1, y1, x2, y2);
request_redraw_borders (item->canvas, &update_rect, request_redraw_borders (item->canvas, &update_rect,
border.left + border.top + border.right + border.bottom); border.left + border.top + border.right + border.bottom);
request_redraw_borders (item->canvas, &priv->last_outline_update_rect, request_redraw_borders (item->canvas, &self->last_outline_update_rect,
priv->last_outline_update_width); self->last_outline_update_width);
priv->last_outline_update_rect = update_rect; self->last_outline_update_rect = update_rect;
priv->last_outline_update_width = border.left + border.top + border.right + border.bottom; self->last_outline_update_width = border.left + border.top + border.right + border.bottom;
item->x1 = x1; item->x1 = x1;
item->y1 = y1; item->y1 = y1;
@ -370,10 +370,10 @@ nautilus_selection_canvas_item_translate (EelCanvasItem *item,
self = NAUTILUS_SELECTION_CANVAS_ITEM (item); self = NAUTILUS_SELECTION_CANVAS_ITEM (item);
self->priv->x1 += dx; self->x1 += dx;
self->priv->y1 += dy; self->y1 += dy;
self->priv->x2 += dx; self->x2 += dx;
self->priv->y2 += dy; self->y2 += dy;
} }
static void static void
@ -395,10 +395,10 @@ nautilus_selection_canvas_item_bounds (EelCanvasItem *item,
gtk_style_context_get_border (context, &border); gtk_style_context_get_border (context, &border);
gtk_style_context_restore (context); gtk_style_context_restore (context);
*x1 = self->priv->x1 - (border.left / item->canvas->pixels_per_unit) / 2.0; *x1 = self->x1 - (border.left / item->canvas->pixels_per_unit) / 2.0;
*y1 = self->priv->y1 - (border.top / item->canvas->pixels_per_unit) / 2.0; *y1 = self->y1 - (border.top / item->canvas->pixels_per_unit) / 2.0;
*x2 = self->priv->x2 + (border.right / item->canvas->pixels_per_unit) / 2.0; *x2 = self->x2 + (border.right / item->canvas->pixels_per_unit) / 2.0;
*y2 = self->priv->y2 + (border.bottom / item->canvas->pixels_per_unit) / 2.0; *y2 = self->y2 + (border.bottom / item->canvas->pixels_per_unit) / 2.0;
} }
static void static void
@ -417,7 +417,7 @@ nautilus_selection_canvas_item_set_property (GObject *object,
{ {
case PROP_X1: case PROP_X1:
{ {
self->priv->x1 = g_value_get_double (value); self->x1 = g_value_get_double (value);
eel_canvas_item_request_update (item); eel_canvas_item_request_update (item);
} }
@ -425,7 +425,7 @@ nautilus_selection_canvas_item_set_property (GObject *object,
case PROP_Y1: case PROP_Y1:
{ {
self->priv->y1 = g_value_get_double (value); self->y1 = g_value_get_double (value);
eel_canvas_item_request_update (item); eel_canvas_item_request_update (item);
} }
@ -433,7 +433,7 @@ nautilus_selection_canvas_item_set_property (GObject *object,
case PROP_X2: case PROP_X2:
{ {
self->priv->x2 = g_value_get_double (value); self->x2 = g_value_get_double (value);
eel_canvas_item_request_update (item); eel_canvas_item_request_update (item);
} }
@ -441,7 +441,7 @@ nautilus_selection_canvas_item_set_property (GObject *object,
case PROP_Y2: case PROP_Y2:
{ {
self->priv->y2 = g_value_get_double (value); self->y2 = g_value_get_double (value);
eel_canvas_item_request_update (item); eel_canvas_item_request_update (item);
} }
@ -469,25 +469,25 @@ nautilus_selection_canvas_item_get_property (GObject *object,
{ {
case PROP_X1: case PROP_X1:
{ {
g_value_set_double (value, self->priv->x1); g_value_set_double (value, self->x1);
} }
break; break;
case PROP_Y1: case PROP_Y1:
{ {
g_value_set_double (value, self->priv->y1); g_value_set_double (value, self->y1);
} }
break; break;
case PROP_X2: case PROP_X2:
{ {
g_value_set_double (value, self->priv->x2); g_value_set_double (value, self->x2);
} }
break; break;
case PROP_Y2: case PROP_Y2:
{ {
g_value_set_double (value, self->priv->y2); g_value_set_double (value, self->y2);
} }
break; break;
@ -535,12 +535,9 @@ nautilus_selection_canvas_item_class_init (NautilusSelectionCanvasItemClass *kla
G_PARAM_READWRITE); G_PARAM_READWRITE);
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties); g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties);
g_type_class_add_private (klass, sizeof (NautilusSelectionCanvasItemDetails));
} }
static void static void
nautilus_selection_canvas_item_init (NautilusSelectionCanvasItem *self) nautilus_selection_canvas_item_init (NautilusSelectionCanvasItem *self)
{ {
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NAUTILUS_TYPE_SELECTION_CANVAS_ITEM,
NautilusSelectionCanvasItemDetails);
} }

View file

@ -27,36 +27,9 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define NAUTILUS_TYPE_SELECTION_CANVAS_ITEM nautilus_selection_canvas_item_get_type() #define NAUTILUS_TYPE_SELECTION_CANVAS_ITEM nautilus_selection_canvas_item_get_type ()
#define NAUTILUS_SELECTION_CANVAS_ITEM(obj) \ G_DECLARE_FINAL_TYPE (NautilusSelectionCanvasItem, nautilus_selection_canvas_item,
(G_TYPE_CHECK_INSTANCE_CAST ((obj), NAUTILUS_TYPE_SELECTION_CANVAS_ITEM, NautilusSelectionCanvasItem)) NAUTILUS, SELECTION_CANVAS_ITEM,
#define NAUTILUS_SELECTION_CANVAS_ITEM_CLASS(klass) \ EelCanvasItem)
(G_TYPE_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_SELECTION_CANVAS_ITEM, NautilusSelectionCanvasItemClass))
#define NAUTILUS_IS_SELECTION_CANVAS_ITEM(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), NAUTILUS_TYPE_SELECTION_CANVAS_ITEM))
#define NAUTILUS_IS_SELECTION_CANVAS_ITEM_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_SELECTION_CANVAS_ITEM))
#define NAUTILUS_SELECTION_CANVAS_ITEM_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), NAUTILUS_TYPE_SELECTION_CANVAS_ITEM, NautilusSelectionCanvasItemClass))
typedef struct _NautilusSelectionCanvasItem NautilusSelectionCanvasItem; G_END_DECLS
typedef struct _NautilusSelectionCanvasItemClass NautilusSelectionCanvasItemClass;
typedef struct _NautilusSelectionCanvasItemDetails NautilusSelectionCanvasItemDetails;
struct _NautilusSelectionCanvasItem {
EelCanvasItem item;
NautilusSelectionCanvasItemDetails *priv;
gpointer user_data;
};
struct _NautilusSelectionCanvasItemClass {
EelCanvasItemClass parent_class;
};
/* GObject */
GType nautilus_selection_canvas_item_get_type (void);
void nautilus_selection_canvas_item_fade_out (NautilusSelectionCanvasItem *self,
guint transition_time);
G_END_DECLS