cell renderer text: Drop the priv pointer

This commit is contained in:
Matthias Clasen 2019-05-26 20:27:36 -04:00
parent a5c2ad18d5
commit 70af933804
2 changed files with 30 additions and 54 deletions

View File

@ -160,6 +160,8 @@ static GParamSpec *text_cell_renderer_props [LAST_PROP];
#define GTK_CELL_RENDERER_TEXT_PATH "gtk-cell-renderer-text-path" #define GTK_CELL_RENDERER_TEXT_PATH "gtk-cell-renderer-text-path"
typedef struct _GtkCellRendererTextPrivate GtkCellRendererTextPrivate;
struct _GtkCellRendererTextPrivate struct _GtkCellRendererTextPrivate
{ {
GtkWidget *entry; GtkWidget *entry;
@ -212,12 +214,9 @@ G_DEFINE_TYPE_WITH_PRIVATE (GtkCellRendererText, gtk_cell_renderer_text, GTK_TYP
static void static void
gtk_cell_renderer_text_init (GtkCellRendererText *celltext) gtk_cell_renderer_text_init (GtkCellRendererText *celltext)
{ {
GtkCellRendererTextPrivate *priv; GtkCellRendererTextPrivate *priv = gtk_cell_renderer_text_get_instance_private (celltext);
GtkCellRenderer *cell = GTK_CELL_RENDERER (celltext); GtkCellRenderer *cell = GTK_CELL_RENDERER (celltext);
celltext->priv = gtk_cell_renderer_text_get_instance_private (celltext);
priv = celltext->priv;
gtk_cell_renderer_set_alignment (cell, 0.0, 0.5); gtk_cell_renderer_set_alignment (cell, 0.0, 0.5);
gtk_cell_renderer_set_padding (cell, 2, 2); gtk_cell_renderer_set_padding (cell, 2, 2);
priv->font_scale = 1.0; priv->font_scale = 1.0;
@ -647,7 +646,7 @@ static void
gtk_cell_renderer_text_finalize (GObject *object) gtk_cell_renderer_text_finalize (GObject *object)
{ {
GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object); GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
GtkCellRendererTextPrivate *priv = celltext->priv; GtkCellRendererTextPrivate *priv = gtk_cell_renderer_text_get_instance_private (celltext);
pango_font_description_free (priv->font); pango_font_description_free (priv->font);
@ -694,7 +693,7 @@ gtk_cell_renderer_text_get_property (GObject *object,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object); GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
GtkCellRendererTextPrivate *priv = celltext->priv; GtkCellRendererTextPrivate *priv = gtk_cell_renderer_text_get_instance_private (celltext);
switch (param_id) switch (param_id)
{ {
@ -873,7 +872,7 @@ static void
set_bg_color (GtkCellRendererText *celltext, set_bg_color (GtkCellRendererText *celltext,
GdkRGBA *rgba) GdkRGBA *rgba)
{ {
GtkCellRendererTextPrivate *priv = celltext->priv; GtkCellRendererTextPrivate *priv = gtk_cell_renderer_text_get_instance_private (celltext);
if (rgba) if (rgba)
{ {
@ -895,12 +894,11 @@ set_bg_color (GtkCellRendererText *celltext,
} }
} }
static void static void
set_fg_color (GtkCellRendererText *celltext, set_fg_color (GtkCellRendererText *celltext,
GdkRGBA *rgba) GdkRGBA *rgba)
{ {
GtkCellRendererTextPrivate *priv = celltext->priv; GtkCellRendererTextPrivate *priv = gtk_cell_renderer_text_get_instance_private (celltext);
if (rgba) if (rgba)
{ {
@ -1005,7 +1003,7 @@ static void
set_font_description (GtkCellRendererText *celltext, set_font_description (GtkCellRendererText *celltext,
PangoFontDescription *font_desc) PangoFontDescription *font_desc)
{ {
GtkCellRendererTextPrivate *priv = celltext->priv; GtkCellRendererTextPrivate *priv = gtk_cell_renderer_text_get_instance_private (celltext);
GObject *object = G_OBJECT (celltext); GObject *object = G_OBJECT (celltext);
PangoFontDescription *new_font_desc; PangoFontDescription *new_font_desc;
PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask; PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask;
@ -1042,7 +1040,7 @@ gtk_cell_renderer_text_set_property (GObject *object,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object); GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
GtkCellRendererTextPrivate *priv = celltext->priv; GtkCellRendererTextPrivate *priv = gtk_cell_renderer_text_get_instance_private (celltext);
switch (param_id) switch (param_id)
{ {
@ -1409,7 +1407,7 @@ gtk_cell_renderer_text_new (void)
static inline gboolean static inline gboolean
show_placeholder_text (GtkCellRendererText *celltext) show_placeholder_text (GtkCellRendererText *celltext)
{ {
GtkCellRendererTextPrivate *priv = celltext->priv; GtkCellRendererTextPrivate *priv = gtk_cell_renderer_text_get_instance_private (celltext);
return priv->editable && priv->placeholder_text && return priv->editable && priv->placeholder_text &&
(!priv->text || !priv->text[0]); (!priv->text || !priv->text[0]);
@ -1431,7 +1429,7 @@ get_layout (GtkCellRendererText *celltext,
const GdkRectangle *cell_area, const GdkRectangle *cell_area,
GtkCellRendererState flags) GtkCellRendererState flags)
{ {
GtkCellRendererTextPrivate *priv = celltext->priv; GtkCellRendererTextPrivate *priv = gtk_cell_renderer_text_get_instance_private (celltext);
PangoAttrList *attr_list; PangoAttrList *attr_list;
PangoLayout *layout; PangoLayout *layout;
PangoUnderline uline; PangoUnderline uline;
@ -1602,7 +1600,7 @@ get_size (GtkCellRenderer *cell,
gint *height) gint *height)
{ {
GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (cell); GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (cell);
GtkCellRendererTextPrivate *priv = celltext->priv; GtkCellRendererTextPrivate *priv = gtk_cell_renderer_text_get_instance_private (celltext);
PangoRectangle rect; PangoRectangle rect;
gint xpad, ypad; gint xpad, ypad;
gint cell_width, cell_height; gint cell_width, cell_height;
@ -1710,7 +1708,7 @@ gtk_cell_renderer_text_snapshot (GtkCellRenderer *cell,
{ {
GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (cell); GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (cell);
GtkCellRendererTextPrivate *priv = celltext->priv; GtkCellRendererTextPrivate *priv = gtk_cell_renderer_text_get_instance_private (celltext);
GtkStyleContext *context; GtkStyleContext *context;
PangoLayout *layout; PangoLayout *layout;
gint x_offset = 0; gint x_offset = 0;
@ -1763,13 +1761,12 @@ static void
gtk_cell_renderer_text_editing_done (GtkCellEditable *entry, gtk_cell_renderer_text_editing_done (GtkCellEditable *entry,
gpointer data) gpointer data)
{ {
GtkCellRendererTextPrivate *priv; GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (data);
GtkCellRendererTextPrivate *priv = gtk_cell_renderer_text_get_instance_private (celltext);
const gchar *path; const gchar *path;
const gchar *new_text; const gchar *new_text;
gboolean canceled; gboolean canceled;
priv = GTK_CELL_RENDERER_TEXT (data)->priv;
g_clear_object (&priv->entry); g_clear_object (&priv->entry);
if (priv->focus_out_id > 0) if (priv->focus_out_id > 0)
@ -1807,9 +1804,8 @@ gtk_cell_renderer_text_editing_done (GtkCellEditable *entry,
static gboolean static gboolean
popdown_timeout (gpointer data) popdown_timeout (gpointer data)
{ {
GtkCellRendererTextPrivate *priv; GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (data);
GtkCellRendererTextPrivate *priv = gtk_cell_renderer_text_get_instance_private (celltext);
priv = GTK_CELL_RENDERER_TEXT (data)->priv;
priv->entry_menu_popdown_timeout = 0; priv->entry_menu_popdown_timeout = 0;
@ -1823,9 +1819,8 @@ static void
gtk_cell_renderer_text_popup_unmap (GtkMenu *menu, gtk_cell_renderer_text_popup_unmap (GtkMenu *menu,
gpointer data) gpointer data)
{ {
GtkCellRendererTextPrivate *priv; GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (data);
GtkCellRendererTextPrivate *priv = gtk_cell_renderer_text_get_instance_private (celltext);
priv = GTK_CELL_RENDERER_TEXT (data)->priv;
priv->in_entry_menu = FALSE; priv->in_entry_menu = FALSE;
@ -1841,9 +1836,8 @@ gtk_cell_renderer_text_populate_popup (GtkEntry *entry,
GtkMenu *menu, GtkMenu *menu,
gpointer data) gpointer data)
{ {
GtkCellRendererTextPrivate *priv; GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (data);
GtkCellRendererTextPrivate *priv = gtk_cell_renderer_text_get_instance_private (celltext);
priv = GTK_CELL_RENDERER_TEXT (data)->priv;
if (priv->entry_menu_popdown_timeout) if (priv->entry_menu_popdown_timeout)
{ {
@ -1862,9 +1856,8 @@ gtk_cell_renderer_text_focus_changed (GtkWidget *entry,
GParamSpec *pspec, GParamSpec *pspec,
gpointer data) gpointer data)
{ {
GtkCellRendererTextPrivate *priv; GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (data);
GtkCellRendererTextPrivate *priv = gtk_cell_renderer_text_get_instance_private (celltext);
priv = GTK_CELL_RENDERER_TEXT (data)->priv;
if (gtk_widget_has_focus (entry)) if (gtk_widget_has_focus (entry))
return; return;
@ -1888,13 +1881,10 @@ gtk_cell_renderer_text_start_editing (GtkCellRenderer *cell,
const GdkRectangle *cell_area, const GdkRectangle *cell_area,
GtkCellRendererState flags) GtkCellRendererState flags)
{ {
GtkCellRendererText *celltext; GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (cell);
GtkCellRendererTextPrivate *priv; GtkCellRendererTextPrivate *priv = gtk_cell_renderer_text_get_instance_private (celltext);
gfloat xalign, yalign; gfloat xalign, yalign;
celltext = GTK_CELL_RENDERER_TEXT (cell);
priv = celltext->priv;
/* If the cell isn't editable we return NULL. */ /* If the cell isn't editable we return NULL. */
if (priv->editable == FALSE) if (priv->editable == FALSE)
return NULL; return NULL;
@ -1955,15 +1945,12 @@ void
gtk_cell_renderer_text_set_fixed_height_from_font (GtkCellRendererText *renderer, gtk_cell_renderer_text_set_fixed_height_from_font (GtkCellRendererText *renderer,
gint number_of_rows) gint number_of_rows)
{ {
GtkCellRendererTextPrivate *priv; GtkCellRendererTextPrivate *priv = gtk_cell_renderer_text_get_instance_private (renderer);
GtkCellRenderer *cell; GtkCellRenderer *cell = GTK_CELL_RENDERER (renderer);
g_return_if_fail (GTK_IS_CELL_RENDERER_TEXT (renderer)); g_return_if_fail (GTK_IS_CELL_RENDERER_TEXT (renderer));
g_return_if_fail (number_of_rows == -1 || number_of_rows > 0); g_return_if_fail (number_of_rows == -1 || number_of_rows > 0);
cell = GTK_CELL_RENDERER (renderer);
priv = renderer->priv;
if (number_of_rows == -1) if (number_of_rows == -1)
{ {
gint width, height; gint width, height;
@ -1984,8 +1971,8 @@ gtk_cell_renderer_text_get_preferred_width (GtkCellRenderer *cell,
gint *minimum_size, gint *minimum_size,
gint *natural_size) gint *natural_size)
{ {
GtkCellRendererTextPrivate *priv; GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (cell);
GtkCellRendererText *celltext; GtkCellRendererTextPrivate *priv = gtk_cell_renderer_text_get_instance_private (celltext);
PangoLayout *layout; PangoLayout *layout;
PangoContext *context; PangoContext *context;
PangoFontMetrics *metrics; PangoFontMetrics *metrics;
@ -2001,10 +1988,6 @@ gtk_cell_renderer_text_get_preferred_width (GtkCellRenderer *cell,
* - minimum size should be MAX (width-chars, 0) * - minimum size should be MAX (width-chars, 0)
* - natural size should be MIN (wrap-width, strlen (label->text)) * - natural size should be MIN (wrap-width, strlen (label->text))
*/ */
celltext = GTK_CELL_RENDERER_TEXT (cell);
priv = celltext->priv;
gtk_cell_renderer_get_padding (cell, &xpad, NULL); gtk_cell_renderer_get_padding (cell, &xpad, NULL);
layout = get_layout (celltext, widget, NULL, 0); layout = get_layout (celltext, widget, NULL, 0);
@ -2071,13 +2054,10 @@ gtk_cell_renderer_text_get_preferred_height_for_width (GtkCellRenderer *cell,
gint *minimum_height, gint *minimum_height,
gint *natural_height) gint *natural_height)
{ {
GtkCellRendererText *celltext; GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (cell);
PangoLayout *layout; PangoLayout *layout;
gint text_height, xpad, ypad; gint text_height, xpad, ypad;
celltext = GTK_CELL_RENDERER_TEXT (cell);
gtk_cell_renderer_get_padding (cell, &xpad, &ypad); gtk_cell_renderer_get_padding (cell, &xpad, &ypad);
layout = get_layout (celltext, widget, NULL, 0); layout = get_layout (celltext, widget, NULL, 0);

View File

@ -37,15 +37,11 @@ G_BEGIN_DECLS
#define GTK_CELL_RENDERER_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CELL_RENDERER_TEXT, GtkCellRendererTextClass)) #define GTK_CELL_RENDERER_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CELL_RENDERER_TEXT, GtkCellRendererTextClass))
typedef struct _GtkCellRendererText GtkCellRendererText; typedef struct _GtkCellRendererText GtkCellRendererText;
typedef struct _GtkCellRendererTextPrivate GtkCellRendererTextPrivate;
typedef struct _GtkCellRendererTextClass GtkCellRendererTextClass; typedef struct _GtkCellRendererTextClass GtkCellRendererTextClass;
struct _GtkCellRendererText struct _GtkCellRendererText
{ {
GtkCellRenderer parent; GtkCellRenderer parent;
/*< private >*/
GtkCellRendererTextPrivate *priv;
}; };
struct _GtkCellRendererTextClass struct _GtkCellRendererTextClass