diff options
-rw-r--r-- | demos/gtk-demo/filtermodel.ui | 18 | ||||
-rw-r--r-- | demos/gtk-demo/listbox.ui | 3 | ||||
-rw-r--r-- | demos/gtk-demo/scale.ui | 30 | ||||
-rw-r--r-- | demos/gtk-demo/theming.ui | 1 | ||||
-rw-r--r-- | demos/icon-browser/window.ui | 36 | ||||
-rw-r--r-- | demos/widget-factory/widget-factory.ui | 25 | ||||
-rw-r--r-- | gdk/gdktexture.c | 7 | ||||
-rw-r--r-- | gsk/gl/gskgldriver.c | 254 | ||||
-rw-r--r-- | gsk/gl/gskgldriverprivate.h | 10 | ||||
-rw-r--r-- | gsk/gl/gskglrenderer.c | 121 | ||||
-rw-r--r-- | gsk/gskrendernodeimpl.c | 13 | ||||
-rw-r--r-- | gtk/gtkcontainer.c | 122 | ||||
-rw-r--r-- | gtk/gtkgrid.c | 336 | ||||
-rw-r--r-- | gtk/gtklevelbar.c | 167 | ||||
-rw-r--r-- | gtk/gtklevelbar.h | 5 | ||||
-rw-r--r-- | gtk/gtkpaned.c | 123 | ||||
-rw-r--r-- | gtk/gtkpaned.h | 6 | ||||
-rw-r--r-- | gtk/gtkprogressbar.c | 112 | ||||
-rw-r--r-- | gtk/gtkprogressbar.h | 6 | ||||
-rw-r--r-- | gtk/gtksnapshot.c | 14 | ||||
-rw-r--r-- | gtk/gtkstylecontext.c | 6 | ||||
-rw-r--r-- | gtk/gtkswitch.c | 1 | ||||
-rw-r--r-- | gtk/gtkwidget.c | 46 | ||||
-rw-r--r-- | gtk/inspector/object-tree.c | 14 | ||||
-rw-r--r-- | tests/meson.build | 3 | ||||
-rw-r--r-- | tests/testtexture.c | 144 | ||||
-rw-r--r-- | testsuite/a11y/label-static.txt | 75 | ||||
-rw-r--r-- | testsuite/a11y/label-static.ui | 17 | ||||
-rw-r--r-- | testsuite/gtk/builder.c | 22 |
29 files changed, 1121 insertions, 616 deletions
diff --git a/demos/gtk-demo/filtermodel.ui b/demos/gtk-demo/filtermodel.ui index 8d7d3acf29..585ad696cc 100644 --- a/demos/gtk-demo/filtermodel.ui +++ b/demos/gtk-demo/filtermodel.ui @@ -45,6 +45,9 @@ <attributes> <attribute name="weight" value="bold"/> </attributes> + <accessibility> + <relation type="label-for" target="treeview1"/> + </accessibility> </object> <packing> <property name="left-attach">0</property> @@ -81,6 +84,9 @@ </child> </object> </child> + <accessibility> + <relation type="labelled-by" target="label1"/> + </accessibility> </object> <packing> <property name="left-attach">0</property> @@ -129,6 +135,9 @@ </child> </object> </child> + <accessibility> + <relation type="labelled-by" target="label2"/> + </accessibility> </object> <packing> <property name="left-attach">1</property> @@ -142,6 +151,9 @@ <attributes> <attribute name="weight" value="bold"/> </attributes> + <accessibility> + <relation type="label-for" target="treeview2"/> + </accessibility> </object> <packing> <property name="left-attach">1</property> @@ -155,6 +167,9 @@ <attributes> <attribute name="weight" value="bold"/> </attributes> + <accessibility> + <relation type="label-for" target="treeview3"/> + </accessibility> </object> <packing> <property name="left-attach">0</property> @@ -185,6 +200,9 @@ </child> </object> </child> + <accessibility> + <relation type="labelled-by" target="label3"/> + </accessibility> </object> <packing> <property name="left-attach">0</property> diff --git a/demos/gtk-demo/listbox.ui b/demos/gtk-demo/listbox.ui index 76b49b285d..606a520224 100644 --- a/demos/gtk-demo/listbox.ui +++ b/demos/gtk-demo/listbox.ui @@ -98,6 +98,9 @@ <property name="yalign">0</property> <property name="label" translatable="0">Message</property> <property name="wrap">1</property> + <accessibility> + <role type="static"/> + </accessibility> </object> <packing> <property name="left-attach">1</property> diff --git a/demos/gtk-demo/scale.ui b/demos/gtk-demo/scale.ui index 7d4329d669..7654044186 100644 --- a/demos/gtk-demo/scale.ui +++ b/demos/gtk-demo/scale.ui @@ -27,9 +27,12 @@ <property name="column-spacing">10</property> <property name="margin">20</property> <child> - <object class="GtkLabel"> + <object class="GtkLabel" id="label_plain"> <property name="label">Plain</property> <property name="xalign">0</property> + <accessibility> + <relation type="label-for" target="scale_plain"/> + </accessibility> </object> <packing> <property name="left-attach">0</property> @@ -37,12 +40,15 @@ </packing> </child> <child> - <object class="GtkScale"> + <object class="GtkScale" id="scale_plain"> <property name="can-focus">1</property> <property name="width-request">200</property> <property name="draw-value">0</property> <property name="adjustment">adjustment1</property> <property name="hexpand">1</property> + <accessibility> + <relation type="labelled-by" target="label_plain"/> + </accessibility> </object> <packing> <property name="left-attach">1</property> @@ -50,9 +56,12 @@ </packing> </child> <child> - <object class="GtkLabel"> + <object class="GtkLabel" id="label_marks"> <property name="label">Marks</property> <property name="xalign">0</property> + <accessibility> + <relation type="label-for" target="scale_marks"/> + </accessibility> </object> <packing> <property name="left-attach">0</property> @@ -60,7 +69,7 @@ </packing> </child> <child> - <object class="GtkScale"> + <object class="GtkScale" id="scale_marks"> <property name="can-focus">1</property> <property name="width-request">200</property> <property name="draw-value">0</property> @@ -73,6 +82,9 @@ <mark value="3" position="bottom"></mark> <mark value="4" position="bottom"></mark> </marks> + <accessibility> + <relation type="labelled-by" target="label_marks"/> + </accessibility> </object> <packing> <property name="left-attach">1</property> @@ -80,9 +92,12 @@ </packing> </child> <child> - <object class="GtkLabel"> + <object class="GtkLabel" id="label_discrete"> <property name="label">Discrete</property> <property name="xalign">0</property> + <accessibility> + <relation type="label-for" target="scale_discrete"/> + </accessibility> </object> <packing> <property name="left-attach">0</property> @@ -90,13 +105,16 @@ </packing> </child> <child> - <object class="GtkScale"> + <object class="GtkScale" id="scale_discrete"> <property name="can-focus">1</property> <property name="width-request">200</property> <property name="round-digits">0</property> <property name="draw-value">0</property> <property name="adjustment">adjustment3</property> <property name="hexpand">1</property> + <accessibility> + <relation type="labelled-by" target="label_discrete"/> + </accessibility> <marks> <mark value="0" position="bottom"></mark> <mark value="1" position="bottom"></mark> diff --git a/demos/gtk-demo/theming.ui b/demos/gtk-demo/theming.ui index 864a29faf0..59cd956eca 100644 --- a/demos/gtk-demo/theming.ui +++ b/demos/gtk-demo/theming.ui @@ -104,6 +104,7 @@ <child> <object class="GtkSwitch" id="switch1"> <property name="can-focus">1</property> + <property name="tooltip_text">Switch it</property> </object> </child> </object> diff --git a/demos/icon-browser/window.ui b/demos/icon-browser/window.ui index 8692295bdf..c56dcbaa6c 100644 --- a/demos/icon-browser/window.ui +++ b/demos/icon-browser/window.ui @@ -133,6 +133,9 @@ <object class="GtkImage" id="image1"> <property name="halign">center</property> <property name="valign">end</property> + <accessibility> + <relation type="labelled-by" target="label1"/> + </accessibility> </object> <packing> <property name="left-attach">0</property> @@ -143,6 +146,9 @@ <object class="GtkImage" id="image2"> <property name="halign">center</property> <property name="valign">end</property> + <accessibility> + <relation type="labelled-by" target="label2"/> + </accessibility> </object> <packing> <property name="left-attach">1</property> @@ -153,6 +159,9 @@ <object class="GtkImage" id="image3"> <property name="halign">center</property> <property name="valign">end</property> + <accessibility> + <relation type="labelled-by" target="label3"/> + </accessibility> </object> <packing> <property name="left-attach">2</property> @@ -163,6 +172,9 @@ <object class="GtkImage" id="image4"> <property name="halign">center</property> <property name="valign">end</property> + <accessibility> + <relation type="labelled-by" target="label4"/> + </accessibility> </object> <packing> <property name="left-attach">3</property> @@ -173,6 +185,9 @@ <object class="GtkImage" id="image5"> <property name="halign">center</property> <property name="valign">end</property> + <accessibility> + <relation type="labelled-by" target="label5"/> + </accessibility> </object> <packing> <property name="left-attach">4</property> @@ -183,6 +198,9 @@ <object class="GtkImage" id="image6"> <property name="halign">center</property> <property name="valign">end</property> + <accessibility> + <relation type="labelled-by" target="label6"/> + </accessibility> </object> <packing> <property name="left-attach">5</property> @@ -197,6 +215,9 @@ <style> <class name="dim-label"/> </style> + <accessibility> + <relation type="label-for" target="image1"/> + </accessibility> </object> <packing> <property name="left-attach">0</property> @@ -211,6 +232,9 @@ <style> <class name="dim-label"/> </style> + <accessibility> + <relation type="label-for" target="image2"/> + </accessibility> </object> <packing> <property name="left-attach">1</property> @@ -225,6 +249,9 @@ <style> <class name="dim-label"/> </style> + <accessibility> + <relation type="label-for" target="image3"/> + </accessibility> </object> <packing> <property name="left-attach">2</property> @@ -239,6 +266,9 @@ <style> <class name="dim-label"/> </style> + <accessibility> + <relation type="label-for" target="image4"/> + </accessibility> </object> <packing> <property name="left-attach">3</property> @@ -253,6 +283,9 @@ <style> <class name="dim-label"/> </style> + <accessibility> + <relation type="label-for" target="image5"/> + </accessibility> </object> <packing> <property name="left-attach">4</property> @@ -267,6 +300,9 @@ <style> <class name="dim-label"/> </style> + <accessibility> + <relation type="label-for" target="image6"/> + </accessibility> </object> <packing> <property name="left-attach">5</property> diff --git a/demos/widget-factory/widget-factory.ui b/demos/widget-factory/widget-factory.ui index 8474d08d76..9bc330c0db 100644 --- a/demos/widget-factory/widget-factory.ui +++ b/demos/widget-factory/widget-factory.ui @@ -3274,6 +3274,9 @@ bad things might happen.</property> <object class="GtkLabel"> <property name="margin">20</property> <property name="label" translatable="yes">To free the princess, you have to slay the dragon.</property> + <accessibility> + <role type="static"/> + </accessibility> </object> </child> </object> @@ -3464,9 +3467,12 @@ bad things might happen.</property> <property name="row-spacing">10</property> <property name="column-spacing">10</property> <child> - <object class="GtkLabel"> + <object class="GtkLabel" id="title_label"> <property name="label">Title:</property> <property name="xalign">1</property> + <accessibility> + <relation type="label-for" target="open_popover_entry"/> + </accessibility> </object> <packing> <property name="left-attach">0</property> @@ -3474,10 +3480,13 @@ bad things might happen.</property> </packing> </child> <child> - <object class="GtkLabel"> + <object class="GtkLabel" id="description_label"> <property name="valign">start</property> <property name="label">Description:</property> <property name="xalign">1</property> + <accessibility> + <relation type="label-for" target="open_popover_textview"/> + </accessibility> </object> <packing> <property name="left-attach">0</property> @@ -3493,7 +3502,11 @@ bad things might happen.</property> <property name="min-content-width">100</property> <property name="max-content-width">100</property> <child> - <object class="GtkTextView" id="open_popover_textview"/> + <object class="GtkTextView" id="open_popover_textview"> + <accessibility> + <relation type="labelled-by" target="description_label"/> + </accessibility> + </object> </child> </object> <packing> @@ -3504,6 +3517,9 @@ bad things might happen.</property> <child> <object class="GtkEntry" id="open_popover_entry"> <property name="activates-default">1</property> + <accessibility> + <relation type="labelled-by" target="title_label"/> + </accessibility> </object> <packing> <property name="left-attach">1</property> @@ -3551,6 +3567,9 @@ bad things might happen.</property> <child> <object class="GtkLabel" id="notebook_info_label"> <property name="label">No updates at this time</property> + <accessibility> + <role type="static"/> + </accessibility> </object> </child> </object> diff --git a/gdk/gdktexture.c b/gdk/gdktexture.c index 6aeed4152a..c518bac8a4 100644 --- a/gdk/gdktexture.c +++ b/gdk/gdktexture.c @@ -151,9 +151,16 @@ static cairo_surface_t * gdk_texture_real_download_surface (GdkTexture *texture) { cairo_surface_t *surface; + cairo_status_t surface_status; surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, texture->width, texture->height); + + surface_status = cairo_surface_status (surface); + if (surface_status != CAIRO_STATUS_SUCCESS) + g_warning ("%s: surface error: %s", __FUNCTION__, + cairo_status_to_string (surface_status)); + gdk_texture_download (texture, cairo_image_surface_get_data (surface), cairo_image_surface_get_stride (surface)); diff --git a/gsk/gl/gskgldriver.c b/gsk/gl/gskgldriver.c index bfca26ee61..3f6c4c70d0 100644 --- a/gsk/gl/gskgldriver.c +++ b/gsk/gl/gskgldriver.c @@ -25,6 +25,10 @@ typedef struct { GdkTexture *user; guint in_use : 1; guint permanent : 1; + + /* TODO: Make this optional and not for every texture... */ + TextureSlice *slices; + guint n_slices; } Texture; struct _GskGLDriver @@ -72,6 +76,7 @@ static void texture_free (gpointer data) { Texture *t = data; + guint i; if (t->user) gdk_texture_clear_render_data (t->user); @@ -79,10 +84,32 @@ texture_free (gpointer data) if (t->fbo.fbo_id != 0) fbo_clear (&t->fbo); - glDeleteTextures (1, &t->texture_id); + if (t->texture_id != 0) + { + glDeleteTextures (1, &t->texture_id); + } + else + { + g_assert_cmpint (t->n_slices, >, 0); + + for (i = 0; i < t->n_slices; i ++) + glDeleteTextures (1, &t->slices[i].texture_id); + } + g_slice_free (Texture, t); } +static void +gsk_gl_driver_set_texture_parameters (GskGLDriver *self, + int min_filter, + int mag_filter) +{ + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter); + + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); +} static void gsk_gl_driver_finalize (GObject *gobject) @@ -206,18 +233,18 @@ gsk_gl_driver_end_frame (GskGLDriver *self) } int -gsk_gl_driver_collect_textures (GskGLDriver *driver) +gsk_gl_driver_collect_textures (GskGLDriver *self) { GHashTableIter iter; gpointer value_p = NULL; int old_size; - g_return_val_if_fail (GSK_IS_GL_DRIVER (driver), 0); - g_return_val_if_fail (!driver->in_frame, 0); + g_return_val_if_fail (GSK_IS_GL_DRIVER (self), 0); + g_return_val_if_fail (!self->in_frame, 0); - old_size = g_hash_table_size (driver->textures); + old_size = g_hash_table_size (self->textures); - g_hash_table_iter_init (&iter, driver->textures); + g_hash_table_iter_init (&iter, self->textures); while (g_hash_table_iter_next (&iter, NULL, &value_p)) { Texture *t = value_p; @@ -239,43 +266,43 @@ gsk_gl_driver_collect_textures (GskGLDriver *driver) g_hash_table_iter_remove (&iter); } - return old_size - g_hash_table_size (driver->textures); + return old_size - g_hash_table_size (self->textures); } int -gsk_gl_driver_get_max_texture_size (GskGLDriver *driver) +gsk_gl_driver_get_max_texture_size (GskGLDriver *self) { - if (driver->max_texture_size < 0) + if (self->max_texture_size < 0) { - if (gdk_gl_context_get_use_es (driver->gl_context)) + if (gdk_gl_context_get_use_es (self->gl_context)) return 2048; return 1024; } - return driver->max_texture_size; + return self->max_texture_size; } static Texture * -gsk_gl_driver_get_texture (GskGLDriver *driver, +gsk_gl_driver_get_texture (GskGLDriver *self, int texture_id) { Texture *t; - if (g_hash_table_lookup_extended (driver->textures, GINT_TO_POINTER (texture_id), NULL, (gpointer *) &t)) + if (g_hash_table_lookup_extended (self->textures, GINT_TO_POINTER (texture_id), NULL, (gpointer *) &t)) return t; return NULL; } static const Fbo * -gsk_gl_driver_get_fbo (GskGLDriver *driver, +gsk_gl_driver_get_fbo (GskGLDriver *self, int texture_id) { - Texture *t = gsk_gl_driver_get_texture (driver, texture_id); + Texture *t = gsk_gl_driver_get_texture (self, texture_id); if (t->fbo.fbo_id == 0) - return &driver->default_fbo; + return &self->default_fbo; return &t->fbo; } @@ -313,8 +340,8 @@ create_texture (GskGLDriver *self, g_assert (width > 0); g_assert (height > 0); - if (width >= self->max_texture_size || - height >= self->max_texture_size) + if (width > self->max_texture_size || + height > self->max_texture_size) { g_critical ("Texture %d x %d is bigger than supported texture limit of %d; clipping...", width, height, @@ -362,8 +389,110 @@ gsk_gl_driver_release_texture (gpointer data) t->user = NULL; } +void +gsk_gl_driver_slice_texture (GskGLDriver *self, + GdkTexture *texture, + TextureSlice **out_slices, + guint *out_n_slices) +{ + const int max_texture_size = gsk_gl_driver_get_max_texture_size (self) / 4; // XXX Too much? + const int tex_width = texture->width; + const int tex_height = texture->height; + const int cols = (texture->width / max_texture_size) + 1; + const int rows = (texture->height / max_texture_size) + 1; + int col, row; + int x = 0, y = 0; /* Position in the texture */ + TextureSlice *slices; + Texture *tex; + + g_assert (tex_width > max_texture_size || tex_height > max_texture_size); + + + tex = gdk_texture_get_render_data (texture, self); + + if (tex != NULL) + { + g_assert (tex->n_slices > 0); + *out_slices = tex->slices; + *out_n_slices = tex->n_slices; + return; + } + + slices = g_new0 (TextureSlice, cols * rows); + + /* TODO: (Perf): + * We still create a surface here, which should obviously be unnecessary + * and we should eventually remove it and upload the data directly. + */ + for (col = 0; col < cols; col ++) + { + const int slice_width = MIN (max_texture_size, texture->width - x); + const int stride = slice_width * 4; + + for (row = 0; row < rows; row ++) + { + const int slice_height = MIN (max_texture_size, texture->height - y); + const int slice_index = (col * rows) + row; + guchar *data; + guint texture_id; + cairo_surface_t *surface; + + data = g_malloc (sizeof (guchar) * stride * slice_height); + + gdk_texture_download_area (texture, + &(GdkRectangle){x, y, slice_width, slice_height}, + data, stride); + surface = cairo_image_surface_create_for_data (data, + CAIRO_FORMAT_ARGB32, + slice_width, slice_height, + stride); + + glGenTextures (1, &texture_id); + +#ifdef G_ENABLE_DEBUG + gsk_profiler_counter_inc (self->profiler, self->counters.created_textures); +#endif + glBindTexture (GL_TEXTURE_2D, texture_id); + gsk_gl_driver_set_texture_parameters (self, GL_NEAREST, GL_NEAREST); + gdk_cairo_surface_upload_to_gl (surface, GL_TEXTURE_2D, slice_width, slice_height, NULL); + +#ifdef G_ENABLE_DEBUG + gsk_profiler_counter_inc (self->profiler, self->counters.surface_uploads); +#endif + + slices[slice_index].rect = (GdkRectangle){x, y, slice_width, slice_height}; + slices[slice_index].texture_id = texture_id; + + g_free (data); + cairo_surface_destroy (surface); + + y += slice_height; + } + + y = 0; + x += slice_width; + } + + /* Allocate one Texture for the entire thing. */ + tex = texture_new (); + tex->width = texture->width; + tex->height = texture->height; + tex->min_filter = GL_NEAREST; + tex->mag_filter = GL_NEAREST; + tex->in_use = TRUE; + tex->slices = slices; + tex->n_slices = cols * rows; + + /* Use texture_free as destroy notify here since we are not inserting this Texture + * into self->textures! */ + gdk_texture_set_render_data (texture, self, tex, texture_free); + + *out_slices = slices; + *out_n_slices = cols * rows; +} + int -gsk_gl_driver_get_texture_for_texture (GskGLDriver *driver, +gsk_gl_driver_get_texture_for_texture (GskGLDriver *self, GdkTexture *texture, int min_filter, int mag_filter) @@ -375,23 +504,23 @@ gsk_gl_driver_get_texture_for_texture (GskGLDriver *driver, { GdkGLContext *texture_context = gdk_gl_texture_get_context ((GdkGLTexture *)texture); - if (texture_context != driver->gl_context) + if (texture_context != self->gl_context) { /* In this case, we have to temporarily make the texture's context the current one, * download its data into our context and then create a texture from it. */ gdk_gl_context_make_current (texture_context); surface = gdk_texture_download_surface (texture); - gdk_gl_context_make_current (driver->gl_context); + gdk_gl_context_make_current (self->gl_context); } else { /* A GL texture from the same GL context is a simple task... */ - return gdk_gl_texture_get_id (GDK_GL_TEXTURE (texture)); + return gdk_gl_texture_get_id ((GdkGLTexture *)texture); } } else { - t = gdk_texture_get_render_data (texture, driver); + t = gdk_texture_get_render_data (texture, self); if (t) { @@ -402,13 +531,13 @@ gsk_gl_driver_get_texture_for_texture (GskGLDriver *driver, surface = gdk_texture_download_surface (texture); } - t = create_texture (driver, gdk_texture_get_width (texture), gdk_texture_get_height (texture)); + t = create_texture (self, gdk_texture_get_width (texture), gdk_texture_get_height (texture)); - if (gdk_texture_set_render_data (texture, driver, t, gsk_gl_driver_release_texture)) + if (gdk_texture_set_render_data (texture, self, t, gsk_gl_driver_release_texture)) t->user = texture; - gsk_gl_driver_bind_source_texture (driver, t->texture_id); - gsk_gl_driver_init_texture_with_surface (driver, + gsk_gl_driver_bind_source_texture (self, t->texture_id); + gsk_gl_driver_init_texture_with_surface (self, t->texture_id, surface, min_filter, @@ -434,21 +563,21 @@ gsk_gl_driver_create_permanent_texture (GskGLDriver *self, } int -gsk_gl_driver_create_texture (GskGLDriver *driver, +gsk_gl_driver_create_texture (GskGLDriver *self, float width, float height) { Texture *t; - g_return_val_if_fail (GSK_IS_GL_DRIVER (driver), -1); + g_return_val_if_fail (GSK_IS_GL_DRIVER (self), -1); - t = create_texture (driver, width, height); + t = create_texture (self, width, height); return t->texture_id; } int -gsk_gl_driver_create_render_target (GskGLDriver *driver, +gsk_gl_driver_create_render_target (GskGLDriver *self, int texture_id, gboolean add_depth_buffer, gboolean add_stencil_buffer) @@ -456,10 +585,10 @@ gsk_gl_driver_create_render_target (GskGLDriver *driver, GLuint fbo_id, depth_stencil_buffer_id; Texture *t; - g_return_val_if_fail (GSK_IS_GL_DRIVER (driver), -1); - g_return_val_if_fail (driver->in_frame, -1); + g_return_val_if_fail (GSK_IS_GL_DRIVER (self), -1); + g_return_val_if_fail (self->in_frame, -1); - t = gsk_gl_driver_get_texture (driver, texture_id); + t = gsk_gl_driver_get_texture (self, texture_id); if (t == NULL) return -1; @@ -497,60 +626,60 @@ gsk_gl_driver_create_render_target (GskGLDriver *driver, t->fbo.depth_stencil_id = depth_stencil_buffer_id; g_assert_cmphex (glCheckFramebufferStatus (GL_FRAMEBUFFER), ==, GL_FRAMEBUFFER_COMPLETE); - glBindFramebuffer (GL_FRAMEBUFFER, driver->default_fbo.fbo_id); + glBindFramebuffer (GL_FRAMEBUFFER, self->default_fbo.fbo_id); return fbo_id; } void -gsk_gl_driver_bind_source_texture (GskGLDriver *driver, +gsk_gl_driver_bind_source_texture (GskGLDriver *self, int texture_id) { Texture *t; - g_return_if_fail (GSK_IS_GL_DRIVER (driver)); - g_return_if_fail (driver->in_frame); + g_return_if_fail (GSK_IS_GL_DRIVER (self)); + g_return_if_fail (self->in_frame); - t = gsk_gl_driver_get_texture (driver, texture_id); + t = gsk_gl_driver_get_texture (self, texture_id); if (t == NULL) { g_critical ("No texture %d found.", texture_id); return; } - if (driver->bound_source_texture != t) + if (self->bound_source_texture != t) { glActiveTexture (GL_TEXTURE0); glBindTexture (GL_TEXTURE_2D, t->texture_id); - driver->bound_source_texture = t; + self->bound_source_texture = t; } } gboolean -gsk_gl_driver_bind_render_target (GskGLDriver *driver, +gsk_gl_driver_bind_render_target (GskGLDriver *self, int texture_id) { int status; const Fbo *f; - g_return_val_if_fail (GSK_IS_GL_DRIVER (driver), FALSE); - g_return_val_if_fail (driver->in_frame, FALSE); + g_return_val_if_fail (GSK_IS_GL_DRIVER (self), FALSE); + g_return_val_if_fail (self->in_frame, FALSE); if (texture_id == 0) { glBindFramebuffer (GL_FRAMEBUFFER, 0); - driver->bound_fbo = &driver->default_fbo; + self->bound_fbo = &self->default_fbo; goto out; } - f = gsk_gl_driver_get_fbo (driver, texture_id); + f = gsk_gl_driver_get_fbo (self, texture_id); - if (f != driver->bound_fbo) + if (f != self->bound_fbo) { glBindFramebuffer (GL_FRAMEBUFFER, f->fbo_id); - driver->bound_fbo = f; + self->bound_fbo = f; } out: @@ -565,50 +694,39 @@ out: } void -gsk_gl_driver_destroy_texture (GskGLDriver *driver, +gsk_gl_driver_destroy_texture (GskGLDriver *self, int texture_id) { - g_return_if_fail (GSK_IS_GL_DRIVER (driver)); + g_return_if_fail (GSK_IS_GL_DRIVER (self)); - g_hash_table_remove (driver->textures, GINT_TO_POINTER (texture_id)); + g_hash_table_remove (self->textures, GINT_TO_POINTER (texture_id)); } -static void -gsk_gl_driver_set_texture_parameters (GskGLDriver *driver, - int min_filter, - int mag_filter) -{ - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter); - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter); - - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); -} void -gsk_gl_driver_init_texture_empty (GskGLDriver *driver, +gsk_gl_driver_init_texture_empty (GskGLDriver *self, int texture_id) { Texture *t; - g_return_if_fail (GSK_IS_GL_DRIVER (driver)); + g_return_if_fail (GSK_IS_GL_DRIVER (self)); - t = gsk_gl_driver_get_texture (driver, texture_id); + t = gsk_gl_driver_get_texture (self, texture_id); if (t == NULL) { g_critical ("No texture %d found.", texture_id); return; } - if (driver->bound_source_texture != t) + if (self->bound_source_texture != t) { g_critical ("You must bind the texture before initializing it."); return; } - gsk_gl_driver_set_texture_parameters (driver, t->min_filter, t->mag_filter); + gsk_gl_driver_set_texture_parameters (self, t->min_filter, t->mag_filter); - if (gdk_gl_context_get_use_es (driver->gl_context)) + if (gdk_gl_context_get_use_es (self->gl_context)) glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, t->width, t->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); else glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, t->width, t->height, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); diff --git a/gsk/gl/gskgldriverprivate.h b/gsk/gl/gskgldriverprivate.h index 17e7c5c84a..7d7a41fe28 100644 --- a/gsk/gl/gskgldriverprivate.h +++ b/gsk/gl/gskgldriverprivate.h @@ -16,6 +16,12 @@ typedef struct { float uv[2]; } GskQuadVertex; +typedef struct { + cairo_rectangle_int_t rect; + guint texture_id; +} TextureSlice; + + GskGLDriver * gsk_gl_driver_new (GdkGLContext *context); int gsk_gl_driver_get_max_texture_size (GskGLDriver *driver); @@ -55,6 +61,10 @@ void gsk_gl_driver_destroy_texture (GskGLDriver *driver int texture_id); int gsk_gl_driver_collect_textures (GskGLDriver *driver); +void gsk_gl_driver_slice_texture (GskGLDriver *self, + GdkTexture *texture, + TextureSlice **out_slices, + guint *out_n_slices); G_END_DECLS diff --git a/gsk/gl/gskglrenderer.c b/gsk/gl/gskglrenderer.c index 8f335d4dcc..a429adfc2a 100644 --- a/gsk/gl/gskglrenderer.c +++ b/gsk/gl/gskglrenderer.c @@ -551,78 +551,75 @@ render_color_node (GskGLRenderer *self, } static inline void -render_texture_node (GskGLRenderer *self, - GskRenderNode *node, - RenderOpBuilder *builder) +render_texture_node (GskGLRenderer *self, + GskRenderNode *node, + RenderOpBuilder *builder) { - float min_x = builder->dx + node->bounds.origin.x; - float min_y = builder->dy + node->bounds.origin.y; - float max_x = min_x + node->bounds.size.width; - float max_y = min_y + node->bounds.size.height; GdkTexture *texture = gsk_texture_node_get_texture (node); - int gl_min_filter = GL_NEAREST, gl_mag_filter = GL_NEAREST; - int texture_id; - const GskRoundedRect *clip = &builder->current_clip; - graphene_rect_t node_bounds = node->bounds; - float tx1, ty1, tx2, ty2; /* texture coords */ - - /* Offset the node position and apply the modelview here already */ - graphene_rect_offset (&node_bounds, builder->dx, builder->dy); - graphene_matrix_transform_bounds (&builder->current_modelview, &node_bounds, &node_bounds); + const int max_texture_size = gsk_gl_driver_get_max_texture_size (self->gl_driver); + const float min_x = builder->dx + node->bounds.origin.x; + const float min_y = builder->dy + node->bounds.origin.y; + const float max_x = min_x + node->bounds.size.width; + const float max_y = min_y + node->bounds.size.height; - get_gl_scaling_filters (node, &gl_min_filter, &gl_mag_filter); + if (texture->width > max_texture_size || texture->height > max_texture_size) + { + const float scale_x = (max_x - min_x) / texture->width; + const float scale_y = (max_y - min_y) / texture->height; + TextureSlice *slices; + guint n_slices; + guint i; - texture_id = gsk_gl_driver_get_texture_for_texture (self->gl_driver, - texture, - gl_min_filter, - gl_mag_filter); - ops_set_program (builder, &self->blit_program); - ops_set_texture (builder, texture_id); + gsk_gl_driver_slice_texture (self->gl_driver, texture, &slices, &n_slices); - if (!graphene_rect_contains_rect (&clip->bounds, &node_bounds)) - { - const float scale_x = node->bounds.size.width / gdk_texture_get_width (texture); - const float scale_y = node->bounds.size.height / gdk_texture_get_height (texture); - graphene_matrix_t inverse_transform; - graphene_rect_t intersection; - graphene_rect_intersection (&clip->bounds, &node_bounds, &intersection); - - /* The texture is completely outside of the current clip bounds */ - if (graphene_rect_equal (&intersection, graphene_rect_zero ())) - return; - - tx1 = (intersection.origin.x - node_bounds.origin.x) / gdk_texture_get_width (texture) / scale_x; - ty1 = (intersection.origin.y - node_bounds.origin.y) / gdk_texture_get_height (texture) / scale_y; - tx2 = tx1 + (intersection.size.width / gdk_texture_get_width (texture)) / scale_x; - ty2 = ty1 + (intersection.size.height / gdk_texture_get_height (texture)) / scale_y; - - /* Invert intersection again, since we will apply the modelview once more in the shader */ - graphene_matrix_inverse (&builder->current_modelview, &inverse_transform); - graphene_matrix_transform_bounds (&inverse_transform, &intersection, &intersection); - - min_x = intersection.origin.x; - min_y = intersection.origin.y; - max_x = min_x + intersection.size.width; - max_y = min_y + intersection.size.height; + ops_set_program (builder, &self->blit_program); + for (i = 0; i < n_slices; i ++) + { + const TextureSlice *slice = &slices[i]; + float x1, x2, y1, y2; + + x1 = min_x + (scale_x * slice->rect.x); + x2 = x1 + (slice->rect.width * scale_x); + y1 = min_y + (scale_y * slice->rect.y); + y2 = y1 + (slice->rect.height * scale_y); + + ops_set_texture (builder, slice->texture_id); + ops_draw (builder, (GskQuadVertex[GL_N_VERTICES]) { + { { x1, y1 }, { 0, 0 }, }, + { { x1, y2 }, { 0, 1 }, }, + { { x2, y1 }, { 1, 0 }, }, + + { { x2, y2 }, { 1, 1 }, }, + { { x1, y2 }, { 0, 1 }, }, + { { x2, y1 }, { 1, 0 }, }, + }); + } } else { - /* The whole thing */ - tx1 = 0; - ty1 = 0; - tx2 = 1; - ty2 = 1; - } + int gl_min_filter = GL_NEAREST, gl_mag_filter = GL_NEAREST; + int texture_id; - ops_draw (builder, (GskQuadVertex[GL_N_VERTICES]) { - { { min_x, min_y }, { tx1, ty1 }, }, - { { min_x, max_y }, { tx1, ty2 }, }, - { { max_x, min_y }, { tx2, ty1 }, }, + get_gl_scaling_filters (node, &gl_min_filter, &gl_mag_filter); - { { max_x, max_y }, { tx2, ty2 }, }, - { { min_x, max_y }, { tx1, ty2 }, }, - { { max_x, min_y }, { tx2, ty1 }, }, - }); + texture_id = gsk_gl_driver_get_texture_for_texture (self->gl_driver, + texture, + gl_min_filter, + gl_mag_filter); + ops_set_program (builder, &self->blit_program); + ops_set_texture (builder, texture_id); + + + ops_draw (builder, (GskQuadVertex[GL_N_VERTICES]) { + { { min_x, min_y }, { 0, 0 }, }, + { { min_x, max_y }, { 0, 1 }, }, + { { max_x, min_y }, { 1, 0 }, }, + + { { max_x, max_y }, { 1, 1 }, }, + { { min_x, max_y }, { 0, 1 }, }, + { { max_x, min_y }, { 1, 0 }, }, + }); + } } static inline void diff --git a/gsk/gskrendernodeimpl.c b/gsk/gskrendernodeimpl.c index f7e552ac09..5faf5ed950 100644 --- a/gsk/gskrendernodeimpl.c +++ b/gsk/gskrendernodeimpl.c @@ -697,12 +697,13 @@ static GVariant * gsk_texture_node_serialize (GskRenderNode *node) { GskTextureNode *self = (GskTextureNode *) node; - cairo_surface_t *surface; + guchar *data; GVariant *result; + gsize stride; - surface = gdk_texture_download_surface (self->texture); - - g_assert (cairo_image_surface_get_width (surface) * 4 == cairo_image_surface_get_stride (surface)); + stride = 4 * self->texture->width; + data = g_malloc (sizeof (guchar) * stride * self->texture->height); + gdk_texture_download (self->texture, data, stride); result = g_variant_new ("(dddduu@au)", (double) node->bounds.origin.x, (double) node->bounds.origin.y, @@ -710,12 +711,12 @@ gsk_texture_node_serialize (GskRenderNode *node) (guint32) gdk_texture_get_width (self->texture), (guint32) gdk_texture_get_height (self->texture), g_variant_new_fixed_array (G_VARIANT_TYPE ("u"), - cairo_image_surface_get_data (surface), + data, gdk_texture_get_width (self->texture) * gdk_texture_get_height (self->texture), sizeof (guint32))); - cairo_surface_destroy (surface); + g_free (data); return result; } diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c index fabdb983f9..18b6ccfe9d 100644 --- a/gtk/gtkcontainer.c +++ b/gtk/gtkcontainer.c @@ -1709,45 +1709,38 @@ gtk_container_real_check_resize (GtkContainer *container) } } -typedef struct { - gint hfw; - gint wfh; -} RequestModeCount; - -static void -count_request_modes (GtkWidget *widget, - RequestModeCount *count) -{ - GtkSizeRequestMode mode = gtk_widget_get_request_mode (widget); - - switch (mode) - { - case GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH: - count->hfw++; - break; - case GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT: - count->wfh++; - break; - case GTK_SIZE_REQUEST_CONSTANT_SIZE: - default: - break; - } -} - static GtkSizeRequestMode gtk_container_get_request_mode (GtkWidget *widget) { - GtkContainer *container = GTK_CONTAINER (widget); - RequestModeCount count = { 0, 0 }; + GtkWidget *w; + int wfh = 0, hfw = 0; + + for (w = gtk_widget_get_first_child (widget); + w != NULL; + w = gtk_widget_get_next_sibling (w)) + { + GtkSizeRequestMode mode = gtk_widget_get_request_mode (w); - gtk_container_forall (container, (GtkCallback)count_request_modes, &count); + switch (mode) + { + case GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH: + hfw ++; + break; + case GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT: + wfh ++; + break; + case GTK_SIZE_REQUEST_CONSTANT_SIZE: + default: + break; + } + } - if (!count.hfw && !count.wfh) + if (hfw == 0 && wfh == 0) return GTK_SIZE_REQUEST_CONSTANT_SIZE; else - return count.wfh > count.hfw ? + return wfh > hfw ? GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT : - GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH; + GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH; } /** @@ -1856,51 +1849,36 @@ gtk_container_get_children (GtkContainer *container) return g_list_reverse (children); } -typedef struct { - gboolean hexpand; - gboolean vexpand; -} ComputeExpandData; - static void -gtk_container_compute_expand_callback (GtkWidget *widget, - gpointer client_data) -{ - ComputeExpandData *data = client_data; - - /* note that we don't get_expand on the child if we already know we - * have to expand, so we only recurse into children until we find - * one that expands and then we basically don't do any more - * work. This means that we can leave some children in a - * need_compute_expand state, which is fine, as long as GtkWidget - * doesn't rely on an invariant that "if a child has - * need_compute_expand, its parents also do" - * - * gtk_widget_compute_expand() always returns FALSE if the - * child is !visible so that's taken care of. - */ - data->hexpand = data->hexpand || - gtk_widget_compute_expand (widget, GTK_ORIENTATION_HORIZONTAL); - - data->vexpand = data->vexpand || - gtk_widget_compute_expand (widget, GTK_ORIENTATION_VERTICAL); -} - -static void -gtk_container_compute_expand (GtkWidget *widget, - gboolean *hexpand_p, - gboolean *vexpand_p) +gtk_container_compute_expand (GtkWidget *widget, + gboolean *hexpand_p, + gboolean *vexpand_p) { - ComputeExpandData data; - - data.hexpand = FALSE; - data.vexpand = FALSE; + GtkWidget *w; + gboolean hexpand = FALSE; + gboolean vexpand = FALSE; - gtk_container_forall (GTK_CONTAINER (widget), - gtk_container_compute_expand_callback, - &data); + for (w = gtk_widget_get_first_child (widget); + w != NULL; + w = gtk_widget_get_next_sibling (w)) + { + /* note that we don't get_expand on the child if we already know we + * have to expand, so we only recurse into children until we find + * one that expands and then we basically don't do any more + * work. This means that we can leave some children in a + * need_compute_expand state, which is fine, as long as GtkWidget + * doesn't rely on an invariant that "if a child has + * need_compute_expand, its parents also do" + * + * gtk_widget_compute_expand() always returns FALSE if the + * child is !visible so that's taken care of. + */ + hexpand = hexpand || gtk_widget_compute_expand (w, GTK_ORIENTATION_HORIZONTAL); + vexpand = vexpand || gtk_widget_compute_expand (w, GTK_ORIENTATION_VERTICAL); + } - *hexpand_p = data.hexpand; - *vexpand_p = data.vexpand; + *hexpand_p = hexpand; + *vexpand_p = vexpand; } static void diff --git a/gtk/gtkgrid.c b/gtk/gtkgrid.c index 674ba18025..65dd19b475 100644 --- a/gtk/gtkgrid.c +++ b/gtk/gtkgrid.c @@ -85,7 +85,6 @@ static const GtkGridRowProperties gtk_grid_row_properties_default = { struct _GtkGridChild { - GtkWidget *widget; GtkGridChildAttach attach[2]; }; @@ -105,7 +104,6 @@ struct _GtkGridLineData struct _GtkGridPrivate { - GList *children; GList *row_properties; GtkOrientation orientation; @@ -118,6 +116,8 @@ typedef struct _GtkGridPrivate GtkGridPrivate; #define ROWS(priv) (&(priv)->linedata[GTK_ORIENTATION_HORIZONTAL]) #define COLUMNS(priv) (&(priv)->linedata[GTK_ORIENTATION_VERTICAL]) +static GQuark child_data_quark = 0; + /* A GtkGridLine struct represents a single row or column * during size requests */ @@ -282,22 +282,9 @@ gtk_grid_set_property (GObject *object, } static GtkGridChild * -find_grid_child (GtkGrid *grid, - GtkWidget *widget) +get_grid_child (GtkWidget *widget) { - GtkGridPrivate *priv = gtk_grid_get_instance_private (grid); - GtkGridChild *child; - GList *list; - - for (list = priv->children; list; list = list->next) - { - child = list->data; - - if (child->widget == widget) - return child; - } - - return NULL; + return (GtkGridChild *) g_object_get_qdata (G_OBJECT (widget), child_data_quark); } static void @@ -307,10 +294,9 @@ gtk_grid_get_child_property (GtkContainer *container, GValue *value, GParamSpec *pspec) { - GtkGrid *grid = GTK_GRID (container); GtkGridChild *grid_child; - grid_child = find_grid_child (grid, child); + grid_child = get_grid_child (child); if (grid_child == NULL) { @@ -352,7 +338,7 @@ gtk_grid_set_child_property (GtkContainer *container, GtkGrid *grid = GTK_GRID (container); GtkGridChild *grid_child; - grid_child = find_grid_child (grid, child); + grid_child = get_grid_child (child); if (grid_child == NULL) { @@ -407,17 +393,15 @@ grid_attach (GtkGrid *grid, gint width, gint height) { - GtkGridPrivate *priv = gtk_grid_get_instance_private (grid); GtkGridChild *child; - child = g_slice_new (GtkGridChild); - child->widget = widget; + child = g_new (GtkGridChild, 1); CHILD_LEFT (child) = left; CHILD_TOP (child) = top; CHILD_WIDTH (child) = width; CHILD_HEIGHT (child) = height; - priv->children = g_list_prepend (priv->children, child); + g_object_set_qdata_full (G_OBJECT (widget), child_data_quark, child, g_free); gtk_widget_set_parent (widget, GTK_WIDGET (grid)); } @@ -436,11 +420,9 @@ find_attach_position (GtkGrid *grid, gint op_span, gboolean max) { - GtkGridPrivate *priv = gtk_grid_get_instance_private (grid); - GtkGridChild *grid_child; GtkGridChildAttach *attach; GtkGridChildAttach *opposite; - GList *list; + GtkWidget *child; gint pos; gboolean hit; @@ -451,9 +433,11 @@ find_attach_position (GtkGrid *grid, hit = FALSE; - for (list = priv->children; list; list = list->next) + for (child = gtk_widget_get_first_child (GTK_WIDGET (grid)); + child != NULL; + child = gtk_widget_get_next_sibling (child)) { - grid_child = list->data; + GtkGridChild *grid_child = get_grid_child (child); attach = &grid_child->attach[orientation]; opposite = &grid_child->attach[1 - orientation]; @@ -493,30 +477,13 @@ gtk_grid_remove (GtkContainer *container, GtkWidget *child) { GtkGrid *grid = GTK_GRID (container); - GtkGridPrivate *priv = gtk_grid_get_instance_private (grid); - GtkGridChild *grid_child; - GList *list; - - for (list = priv->children; list; list = list->next) - { - grid_child = list->data; - - if (grid_child->widget == child) - { - gboolean was_visible = _gtk_widget_get_visible (child); - - gtk_widget_unparent (child); - - priv->children = g_list_remove (priv->children, grid_child); + gboolean was_visible; - g_slice_free (GtkGridChild, grid_child); + was_visible = _gtk_widget_get_visible (child); + gtk_widget_unparent (child); - if (was_visible && _gtk_widget_get_visible (GTK_WIDGET (grid))) - gtk_widget_queue_resize (GTK_WIDGET (grid)); - - break; - } - } + if (was_visible && _gtk_widget_get_visible (GTK_WIDGET (grid))) + gtk_widget_queue_resize (GTK_WIDGET (grid)); } static void @@ -524,18 +491,16 @@ gtk_grid_forall (GtkContainer *container, GtkCallback callback, gpointer callback_data) { - GtkGrid *grid = GTK_GRID (container); - GtkGridPrivate *priv = gtk_grid_get_instance_private (grid); - GtkGridChild *child; - GList *list; + GtkWidget *child; - list = priv->children; - while (list) + child = gtk_widget_get_first_child (GTK_WIDGET (container)); + while (child) { - child = list->data; - list = list->next; + GtkWidget *next = gtk_widget_get_next_sibling (child); - (* callback) (child->widget, callback_data); + (* callback) (child, callback_data); + + child = next; } } @@ -567,20 +532,19 @@ get_spacing (GtkGrid *grid, static void gtk_grid_request_count_lines (GtkGridRequest *request) { - GtkGridPrivate *priv = gtk_grid_get_instance_private (request->grid); - GtkGridChild *child; - GtkGridChildAttach *attach; - GList *list; + GtkWidget *child; gint min[2]; gint max[2]; min[0] = min[1] = G_MAXINT; max[0] = max[1] = G_MININT; - for (list = priv->children; list; list = list->next) + for (child = gtk_widget_get_first_child (GTK_WIDGET (request->grid)); + child != NULL; + child = gtk_widget_get_next_sibling (child)) { - child = list->data; - attach = child->attach; + GtkGridChild *grid_child = get_grid_child (child); + GtkGridChildAttach *attach = grid_child->attach; min[0] = MIN (min[0], attach[0].pos); max[0] = MAX (max[0], attach[0].pos + attach[0].span); @@ -601,11 +565,9 @@ static void gtk_grid_request_init (GtkGridRequest *request, GtkOrientation orientation) { - GtkGridPrivate *priv = gtk_grid_get_instance_private (request->grid); - GtkGridChild *child; + GtkWidget *child; GtkGridChildAttach *attach; GtkGridLines *lines; - GList *list; gint i; lines = &request->lines[orientation]; @@ -622,12 +584,15 @@ gtk_grid_request_init (GtkGridRequest *request, lines->lines[i].empty = TRUE; } - for (list = priv->children; list; list = list->next) + + for (child = gtk_widget_get_first_child (GTK_WIDGET (request->grid)); + child != NULL; + child = gtk_widget_get_next_sibling (child)) { - child = list->data; + GtkGridChild *grid_child = get_grid_child (child); - attach = &child->attach[orientation]; - if (attach->span == 1 && gtk_widget_compute_expand (child->widget, orientation)) + attach = &grid_child->attach[orientation]; + if (attach->span == 1 && gtk_widget_compute_expand (child, orientation)) lines->lines[attach->pos - lines->min].expand = TRUE; } } @@ -660,7 +625,8 @@ compute_allocation_for_child (GtkGridRequest *request, static void compute_request_for_child (GtkGridRequest *request, - GtkGridChild *child, + GtkWidget *child, + GtkGridChild *grid_child, GtkOrientation orientation, gboolean contextual, gint *minimum, @@ -677,9 +643,9 @@ compute_request_for_child (GtkGridRequest *request, { gint size; - size = compute_allocation_for_child (request, child, 1 - orientation); + size = compute_allocation_for_child (request, grid_child, 1 - orientation); - gtk_widget_measure (child->widget, + gtk_widget_measure (child, orientation, size, minimum, natural, @@ -687,7 +653,7 @@ compute_request_for_child (GtkGridRequest *request, } else { - gtk_widget_measure (child->widget, + gtk_widget_measure (child, orientation, -1, minimum, natural, @@ -704,12 +670,10 @@ gtk_grid_request_non_spanning (GtkGridRequest *request, GtkOrientation orientation, gboolean contextual) { - GtkGridPrivate *priv = gtk_grid_get_instance_private (request->grid); - GtkGridChild *child; + GtkWidget *child; GtkGridChildAttach *attach; GtkGridLines *lines; GtkGridLine *line; - GList *list; gint i; GtkBaselinePosition baseline_pos; gint minimum, minimum_baseline; @@ -717,18 +681,20 @@ gtk_grid_request_non_spanning (GtkGridRequest *request, lines = &request->lines[orientation]; - for (list = priv->children; list; list = list->next) + for (child = gtk_widget_get_first_child (GTK_WIDGET (request->grid)); + child != NULL; + child = gtk_widget_get_next_sibling (child)) { - child = list->data; + GtkGridChild *grid_child = get_grid_child (child); - if (!_gtk_widget_get_visible (child->widget)) + if (!_gtk_widget_get_visible (child)) continue; - attach = &child->attach[orientation]; + attach = &grid_child->attach[orientation]; if (attach->span != 1) continue; - compute_request_for_child (request, child, orientation, contextual, &minimum, &natural, &minimum_baseline, &natural_baseline); + compute_request_for_child (request, child, grid_child, orientation, contextual, &minimum, &natural, &minimum_baseline, &natural_baseline); line = &lines->lines[attach->pos - lines->min]; @@ -831,8 +797,7 @@ gtk_grid_request_spanning (GtkGridRequest *request, gboolean contextual) { GtkGridPrivate *priv = gtk_grid_get_instance_private (request->grid); - GList *list; - GtkGridChild *child; + GtkWidget *child; GtkGridChildAttach *attach; GtkGridLineData *linedata; GtkGridLines *lines; @@ -853,19 +818,21 @@ gtk_grid_request_spanning (GtkGridRequest *request, lines = &request->lines[orientation]; spacing = get_spacing (request->grid, orientation); - for (list = priv->children; list; list = list->next) + for (child = gtk_widget_get_first_child (GTK_WIDGET (request->grid)); + child != NULL; + child = gtk_widget_get_next_sibling (child)) { - child = list->data; + GtkGridChild *grid_child = get_grid_child (child); - if (!_gtk_widget_get_visible (child->widget)) + if (!_gtk_widget_get_visible (child)) continue; - attach = &child->attach[orientation]; + attach = &grid_child->attach[orientation]; if (attach->span == 1) continue; /* We ignore baselines for spanning children */ - compute_request_for_child (request, child, orientation, contextual, &minimum, &natural, NULL, NULL); + compute_request_for_child (request, child, grid_child, orientation, contextual, &minimum, &natural, NULL, NULL); span_minimum = (attach->span - 1) * spacing; span_natural = (attach->span - 1) * spacing; @@ -970,10 +937,8 @@ gtk_grid_request_compute_expand (GtkGridRequest *request, gint *nonempty_lines, gint *expand_lines) { - GtkGridPrivate *priv = gtk_grid_get_instance_private (request->grid); - GtkGridChild *child; + GtkWidget *child; GtkGridChildAttach *attach; - GList *list; gint i; GtkGridLines *lines; GtkGridLine *line; @@ -993,14 +958,16 @@ gtk_grid_request_compute_expand (GtkGridRequest *request, lines->lines[i].empty = TRUE; } - for (list = priv->children; list; list = list->next) + for (child = gtk_widget_get_first_child (GTK_WIDGET (request->grid)); + child != NULL; + child = gtk_widget_get_next_sibling (child)) { - child = list->data; + GtkGridChild *grid_child = get_grid_child (child); - if (!_gtk_widget_get_visible (child->widget)) + if (!_gtk_widget_get_visible (child)) continue; - attach = &child->attach[orientation]; + attach = &grid_child->attach[orientation]; if (attach->span != 1) continue; @@ -1009,18 +976,20 @@ gtk_grid_request_compute_expand (GtkGridRequest *request, line = &lines->lines[attach->pos - lines->min]; line->empty = FALSE; - if (gtk_widget_compute_expand (child->widget, orientation)) + if (gtk_widget_compute_expand (child, orientation)) line->expand = TRUE; } - for (list = priv->children; list; list = list->next) + for (child = gtk_widget_get_first_child (GTK_WIDGET (request->grid)); + child != NULL; + child = gtk_widget_get_next_sibling (child)) { - child = list->data; + GtkGridChild *grid_child = get_grid_child (child); - if (!_gtk_widget_get_visible (child->widget)) + if (!_gtk_widget_get_visible (child)) continue; - attach = &child->attach[orientation]; + attach = &grid_child->attach[orientation]; if (attach->span == 1) continue; @@ -1038,7 +1007,7 @@ gtk_grid_request_compute_expand (GtkGridRequest *request, line->empty = FALSE; } - if (!has_expand && gtk_widget_compute_expand (child->widget, orientation)) + if (!has_expand && gtk_widget_compute_expand (child, orientation)) { for (i = 0; i < attach->span; i++) { @@ -1430,7 +1399,6 @@ gtk_grid_get_size (GtkGrid *grid, gint *minimum_baseline, gint *natural_baseline) { - GtkGridPrivate *priv = gtk_grid_get_instance_private (grid); GtkGridRequest request; GtkGridLines *lines; @@ -1443,7 +1411,7 @@ gtk_grid_get_size (GtkGrid *grid, if (natural_baseline) *natural_baseline = -1; - if (priv->children == NULL) + if (gtk_widget_get_first_child (GTK_WIDGET (grid)) == NULL) return; request.grid = grid; @@ -1466,7 +1434,6 @@ gtk_grid_get_size_for_size (GtkGrid *grid, gint *minimum_baseline, gint *natural_baseline) { - GtkGridPrivate *priv = gtk_grid_get_instance_private (grid); GtkGridRequest request; GtkGridLines *lines; gint min_size, nat_size; @@ -1480,7 +1447,7 @@ gtk_grid_get_size_for_size (GtkGrid *grid, if (natural_baseline) *natural_baseline = -1; - if (priv->children == NULL) + if (gtk_widget_get_first_child (GTK_WIDGET (grid)) == NULL) return; request.grid = grid; @@ -1523,7 +1490,8 @@ gtk_grid_measure (GtkWidget *widget, static void allocate_child (GtkGridRequest *request, GtkOrientation orientation, - GtkGridChild *child, + GtkWidget *child, + GtkGridChild *grid_child, gint *position, gint *size, gint *baseline) @@ -1534,10 +1502,10 @@ allocate_child (GtkGridRequest *request, gint i; lines = &request->lines[orientation]; - attach = &child->attach[orientation]; + attach = &grid_child->attach[orientation]; *position = lines->lines[attach->pos - lines->min].position; - if (attach->span == 1 && gtk_widget_get_valign (child->widget) == GTK_ALIGN_BASELINE) + if (attach->span == 1 && gtk_widget_get_valign (child) == GTK_ALIGN_BASELINE) *baseline = lines->lines[attach->pos - lines->min].allocated_baseline; else *baseline = -1; @@ -1555,22 +1523,23 @@ gtk_grid_request_allocate_children (GtkGridRequest *request, const GtkAllocation *allocation, GtkAllocation *out_clip) { - GtkGridPrivate *priv = gtk_grid_get_instance_private (request->grid); - GList *list; - GtkGridChild *child; + GtkWidget *child; GtkAllocation child_allocation; GtkAllocation child_clip; gint x, y, width, height, baseline, ignore; - for (list = priv->children; list; list = list->next) + + for (child = gtk_widget_get_first_child (GTK_WIDGET (request->grid)); + child != NULL; + child = gtk_widget_get_next_sibling (child)) { - child = list->data; + GtkGridChild *grid_child = get_grid_child (child); - if (!_gtk_widget_get_visible (child->widget)) + if (!_gtk_widget_get_visible (child)) continue; - allocate_child (request, GTK_ORIENTATION_HORIZONTAL, child, &x, &width, &ignore); - allocate_child (request, GTK_ORIENTATION_VERTICAL, child, &y, &height, &baseline); + allocate_child (request, GTK_ORIENTATION_HORIZONTAL, child, grid_child, &x, &width, &ignore); + allocate_child (request, GTK_ORIENTATION_VERTICAL, child, grid_child, &y, &height, &baseline); child_allocation.x = x; child_allocation.y = y; @@ -1581,7 +1550,7 @@ gtk_grid_request_allocate_children (GtkGridRequest *request, child_allocation.x = allocation->x + allocation->width - (child_allocation.x - allocation->x) - child_allocation.width; - gtk_widget_size_allocate (child->widget, &child_allocation, baseline, &child_clip); + gtk_widget_size_allocate (child, &child_allocation, baseline, &child_clip); gdk_rectangle_union (out_clip, &child_clip, out_clip); } } @@ -1595,12 +1564,11 @@ gtk_grid_size_allocate (GtkWidget *widget, GtkAllocation *out_clip) { GtkGrid *grid = GTK_GRID (widget); - GtkGridPrivate *priv = gtk_grid_get_instance_private (grid); GtkGridRequest request; GtkGridLines *lines; GtkOrientation orientation; - if (priv->children == NULL) + if (gtk_widget_get_first_child (widget) == NULL) return; request.grid = grid; @@ -1720,7 +1688,9 @@ gtk_grid_class_init (GtkGridClass *class) 1, G_MAXINT, 1, GTK_PARAM_READWRITE); + gtk_container_class_install_child_properties (container_class, N_CHILD_PROPERTIES, child_properties); + child_data_quark = g_quark_from_static_string ("gtk-grid-child-data"); gtk_widget_class_set_css_name (widget_class, I_("grid")); } @@ -1731,7 +1701,6 @@ gtk_grid_init (GtkGrid *grid) gtk_widget_set_has_surface (GTK_WIDGET (grid), FALSE); - priv->children = NULL; priv->orientation = GTK_ORIENTATION_HORIZONTAL; priv->baseline_row = 0; @@ -1829,7 +1798,7 @@ gtk_grid_attach_next_to (GtkGrid *grid, if (sibling) { - grid_sibling = find_grid_child (grid, sibling); + grid_sibling = get_grid_child (sibling); switch (side) { @@ -1899,21 +1868,21 @@ gtk_grid_get_child_at (GtkGrid *grid, gint left, gint top) { - GtkGridPrivate *priv = gtk_grid_get_instance_private (grid); - GtkGridChild *child; - GList *list; + GtkWidget *child; g_return_val_if_fail (GTK_IS_GRID (grid), NULL); - for (list = priv->children; list; list = list->next) + for (child = gtk_widget_get_first_child (GTK_WIDGET (grid)); + child != NULL; + child = gtk_widget_get_next_sibling (child)) { - child = list->data; + GtkGridChild *grid_child = get_grid_child (child); - if (CHILD_LEFT (child) <= left && - CHILD_LEFT (child) + CHILD_WIDTH (child) > left && - CHILD_TOP (child) <= top && - CHILD_TOP (child) + CHILD_HEIGHT (child) > top) - return child->widget; + if (CHILD_LEFT (grid_child) <= left && + CHILD_LEFT (grid_child) + CHILD_WIDTH (grid_child) > left && + CHILD_TOP (grid_child) <= top && + CHILD_TOP (grid_child) + CHILD_HEIGHT (grid_child) > top) + return child; } return NULL; @@ -1935,31 +1904,33 @@ gtk_grid_insert_row (GtkGrid *grid, gint position) { GtkGridPrivate *priv = gtk_grid_get_instance_private (grid); - GtkGridChild *child; + GtkWidget *child; + int top, height; GList *list; - gint top, height; g_return_if_fail (GTK_IS_GRID (grid)); - for (list = priv->children; list; list = list->next) + for (child = gtk_widget_get_first_child (GTK_WIDGET (grid)); + child != NULL; + child = gtk_widget_get_next_sibling (child)) { - child = list->data; + GtkGridChild *grid_child = get_grid_child (child); - top = CHILD_TOP (child); - height = CHILD_HEIGHT (child); + top = CHILD_TOP (grid_child); + height = CHILD_HEIGHT (grid_child); if (top >= position) { - CHILD_TOP (child) = top + 1; + CHILD_TOP (grid_child) = top + 1; gtk_container_child_notify_by_pspec (GTK_CONTAINER (grid), - child->widget, + child, child_properties[CHILD_PROP_TOP_ATTACH]); } else if (top + height > position) { - CHILD_HEIGHT (child) = height + 1; + CHILD_HEIGHT (grid_child) = height + 1; gtk_container_child_notify_by_pspec (GTK_CONTAINER (grid), - child->widget, + child, child_properties[CHILD_PROP_HEIGHT]); } } @@ -1989,21 +1960,19 @@ void gtk_grid_remove_row (GtkGrid *grid, gint position) { - GtkGridPrivate *priv = gtk_grid_get_instance_private (grid); - GtkGridChild *child; - GList *list; - gint top, height; + int top, height; + GtkWidget *child; g_return_if_fail (GTK_IS_GRID (grid)); - list = priv->children; - while (list) + child = gtk_widget_get_first_child (GTK_WIDGET (grid)); + while (child) { - child = list->data; - list = list->next; + GtkGridChild *grid_child = get_grid_child (child); + GtkWidget *next = gtk_widget_get_next_sibling (child); - top = CHILD_TOP (child); - height = CHILD_HEIGHT (child); + top = CHILD_TOP (grid_child); + height = CHILD_HEIGHT (grid_child); if (top <= position && top + height > position) height--; @@ -2011,12 +1980,13 @@ gtk_grid_remove_row (GtkGrid *grid, top--; if (height <= 0) - gtk_container_remove (GTK_CONTAINER (grid), child->widget); + gtk_container_remove (GTK_CONTAINER (grid), child); else - gtk_container_child_set (GTK_CONTAINER (grid), child->widget, + gtk_container_child_set (GTK_CONTAINER (grid), child, "height", height, "top-attach", top, NULL); + child = next; } } @@ -2035,32 +2005,32 @@ void gtk_grid_insert_column (GtkGrid *grid, gint position) { - GtkGridPrivate *priv = gtk_grid_get_instance_private (grid); - GtkGridChild *child; - GList *list; - gint left, width; + GtkWidget *child; + int left, width; g_return_if_fail (GTK_IS_GRID (grid)); - for (list = priv->children; list; list = list->next) + for (child = gtk_widget_get_first_child (GTK_WIDGET (grid)); + child != NULL; + child = gtk_widget_get_next_sibling (child)) { - child = list->data; + GtkGridChild *grid_child = get_grid_child (child); - left = CHILD_LEFT (child); - width = CHILD_WIDTH (child); + left = CHILD_LEFT (grid_child); + width = CHILD_WIDTH (grid_child); if (left >= position) { - CHILD_LEFT (child) = left + 1; + CHILD_LEFT (grid_child) = left + 1; gtk_container_child_notify_by_pspec (GTK_CONTAINER (grid), - child->widget, + child, child_properties[CHILD_PROP_LEFT_ATTACH]); } else if (left + width > position) { - CHILD_WIDTH (child) = width + 1; + CHILD_WIDTH (grid_child) = width + 1; gtk_container_child_notify_by_pspec (GTK_CONTAINER (grid), - child->widget, + child, child_properties[CHILD_PROP_WIDTH]); } } @@ -2082,21 +2052,19 @@ void gtk_grid_remove_column (GtkGrid *grid, gint position) { - GtkGridPrivate *priv = gtk_grid_get_instance_private (grid); - GtkGridChild *child; - GList *list; - gint left, width; + GtkWidget *child; + int left, width; g_return_if_fail (GTK_IS_GRID (grid)); - list = priv->children; - while (list) + child = gtk_widget_get_first_child (GTK_WIDGET (grid)); + while (child) { - child = list->data; - list = list->next; + GtkGridChild *grid_child = get_grid_child (child); + GtkWidget *next = gtk_widget_get_next_sibling (child); - left = CHILD_LEFT (child); - width = CHILD_WIDTH (child); + left = CHILD_LEFT (grid_child); + width = CHILD_WIDTH (grid_child); if (left <= position && left + width > position) width--; @@ -2104,12 +2072,14 @@ gtk_grid_remove_column (GtkGrid *grid, left--; if (width <= 0) - gtk_container_remove (GTK_CONTAINER (grid), child->widget); + gtk_container_remove (GTK_CONTAINER (grid), child); else - gtk_container_child_set (GTK_CONTAINER (grid), child->widget, + gtk_container_child_set (GTK_CONTAINER (grid), child, "width", width, "left-attach", left, NULL); + + child = next; } } @@ -2138,7 +2108,7 @@ gtk_grid_insert_next_to (GtkGrid *grid, g_return_if_fail (GTK_IS_WIDGET (sibling)); g_return_if_fail (_gtk_widget_get_parent (sibling) == (GtkWidget*)grid); - child = find_grid_child (grid, sibling); + child = get_grid_child (sibling); switch (side) { diff --git a/gtk/gtklevelbar.c b/gtk/gtklevelbar.c index 2e3a783265..d7fbfbe3af 100644 --- a/gtk/gtklevelbar.c +++ b/gtk/gtklevelbar.c @@ -164,6 +164,7 @@ typedef struct { gdouble value; } GtkLevelBarOffset; +typedef struct _GtkLevelBarPrivate GtkLevelBarPrivate; struct _GtkLevelBarPrivate { GtkOrientation orientation; @@ -237,11 +238,12 @@ gtk_level_bar_ensure_offset (GtkLevelBar *self, const gchar *name, gdouble value) { + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); GList *existing; GtkLevelBarOffset *offset = NULL; GtkLevelBarOffset *new_offset; - existing = g_list_find_custom (self->priv->offsets, name, offset_find_func); + existing = g_list_find_custom (priv->offsets, name, offset_find_func); if (existing) offset = existing->data; @@ -253,10 +255,10 @@ gtk_level_bar_ensure_offset (GtkLevelBar *self, if (offset) { gtk_level_bar_offset_free (offset); - self->priv->offsets = g_list_delete_link (self->priv->offsets, existing); + priv->offsets = g_list_delete_link (priv->offsets, existing); } - self->priv->offsets = g_list_insert_sorted (self->priv->offsets, new_offset, offset_sort_func); + priv->offsets = g_list_insert_sorted (priv->offsets, new_offset, offset_sort_func); return TRUE; } @@ -265,17 +267,21 @@ static gboolean gtk_level_bar_value_in_interval (GtkLevelBar *self, gdouble value) { - return ((value >= self->priv->min_value) && - (value <= self->priv->max_value)); + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); + + return ((value >= priv->min_value) && + (value <= priv->max_value)); } static gint gtk_level_bar_get_num_blocks (GtkLevelBar *self) { - if (self->priv->bar_mode == GTK_LEVEL_BAR_MODE_CONTINUOUS) + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); + + if (priv->bar_mode == GTK_LEVEL_BAR_MODE_CONTINUOUS) return 1; - else if (self->priv->bar_mode == GTK_LEVEL_BAR_MODE_DISCRETE) - return MAX (1, (gint) (round (self->priv->max_value) - round (self->priv->min_value))); + else if (priv->bar_mode == GTK_LEVEL_BAR_MODE_DISCRETE) + return MAX (1, (gint) (round (priv->max_value) - round (priv->min_value))); return 0; } @@ -283,7 +289,8 @@ gtk_level_bar_get_num_blocks (GtkLevelBar *self) static gint gtk_level_bar_get_num_block_nodes (GtkLevelBar *self) { - if (self->priv->bar_mode == GTK_LEVEL_BAR_MODE_CONTINUOUS) + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); + if (priv->bar_mode == GTK_LEVEL_BAR_MODE_CONTINUOUS) return 2; else return gtk_level_bar_get_num_blocks (self); @@ -294,6 +301,7 @@ gtk_level_bar_get_min_block_size (GtkLevelBar *self, gint *block_width, gint *block_height) { + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); guint i, n_blocks; gint width, height; @@ -302,12 +310,12 @@ gtk_level_bar_get_min_block_size (GtkLevelBar *self, for (i = 0; i < n_blocks; i++) { - gtk_widget_measure (self->priv->block_widget[i], + gtk_widget_measure (priv->block_widget[i], GTK_ORIENTATION_HORIZONTAL, -1, &width, NULL, NULL, NULL); - gtk_widget_measure (self->priv->block_widget[i], + gtk_widget_measure (priv->block_widget[i], GTK_ORIENTATION_VERTICAL, -1, &height, NULL, @@ -321,11 +329,12 @@ gtk_level_bar_get_min_block_size (GtkLevelBar *self, static gboolean gtk_level_bar_get_real_inverted (GtkLevelBar *self) { + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); if (gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_RTL && - self->priv->orientation == GTK_ORIENTATION_HORIZONTAL) - return !self->priv->inverted; + priv->orientation == GTK_ORIENTATION_HORIZONTAL) + return !priv->inverted; - return self->priv->inverted; + return priv->inverted; } static gboolean @@ -334,19 +343,20 @@ gtk_level_bar_render_trough (GtkGizmo *gizmo, { GtkWidget *widget = GTK_WIDGET (gizmo); GtkLevelBar *self = GTK_LEVEL_BAR (gtk_widget_get_parent (GTK_WIDGET (gizmo))); + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); - if (self->priv->bar_mode == GTK_LEVEL_BAR_MODE_CONTINUOUS) + if (priv->bar_mode == GTK_LEVEL_BAR_MODE_CONTINUOUS) { gboolean inverted; inverted = gtk_level_bar_get_real_inverted (self); /* render the empty (unfilled) part */ - gtk_widget_snapshot_child (widget, self->priv->block_widget[inverted ? 0 : 1], snapshot); + gtk_widget_snapshot_child (widget, priv->block_widget[inverted ? 0 : 1], snapshot); /* now render the filled part on top of it */ - if (self->priv->cur_value != 0) - gtk_widget_snapshot_child (widget, self->priv->block_widget[inverted ? 1 : 0], snapshot); + if (priv->cur_value != 0) + gtk_widget_snapshot_child (widget, priv->block_widget[inverted ? 1 : 0], snapshot); } else { @@ -355,7 +365,7 @@ gtk_level_bar_render_trough (GtkGizmo *gizmo, num_blocks = gtk_level_bar_get_num_blocks (self); for (i = 0; i < num_blocks; i++) - gtk_widget_snapshot_child (widget, self->priv->block_widget[i], snapshot); + gtk_widget_snapshot_child (widget, priv->block_widget[i], snapshot); } return FALSE; @@ -366,8 +376,9 @@ gtk_level_bar_snapshot (GtkWidget *widget, GtkSnapshot *snapshot) { GtkLevelBar *self = GTK_LEVEL_BAR (widget); + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); - gtk_widget_snapshot_child (widget, self->priv->trough_widget, snapshot); + gtk_widget_snapshot_child (widget, priv->trough_widget, snapshot); } static void @@ -381,6 +392,7 @@ gtk_level_bar_measure_trough (GtkGizmo *gizmo, { GtkWidget *widget = GTK_WIDGET (gizmo); GtkLevelBar *self = GTK_LEVEL_BAR (gtk_widget_get_parent (widget)); + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); gint num_blocks, size; gint block_width, block_height; @@ -389,14 +401,14 @@ gtk_level_bar_measure_trough (GtkGizmo *gizmo, if (orientation == GTK_ORIENTATION_HORIZONTAL) { - if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL) + if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) size = num_blocks * block_width; else size = block_width; } else { - if (self->priv->orientation == GTK_ORIENTATION_VERTICAL) + if (priv->orientation == GTK_ORIENTATION_VERTICAL) size = num_blocks * block_height; else size = block_height; @@ -415,7 +427,9 @@ gtk_level_bar_measure (GtkWidget *widget, int *minimum_baseline, int *natural_baseline) { - gtk_widget_measure (GTK_LEVEL_BAR (widget)->priv->trough_widget, + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (GTK_LEVEL_BAR (widget)); + + gtk_widget_measure (priv->trough_widget, orientation, for_size, minimum, natural, @@ -423,11 +437,12 @@ gtk_level_bar_measure (GtkWidget *widget, } static void -gtk_level_bar_allocate_trough_continuous (GtkLevelBar *self, +gtk_level_bar_allocate_trough_continuous (GtkLevelBar *self, const GtkAllocation *allocation, - int baseline, - GtkAllocation *out_clip) + int baseline, + GtkAllocation *out_clip) { + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); GtkAllocation block_area, clip; gdouble fill_percentage; gboolean inverted; @@ -436,25 +451,25 @@ gtk_level_bar_allocate_trough_continuous (GtkLevelBar *self, inverted = gtk_level_bar_get_real_inverted (self); /* allocate the empty (unfilled) part */ - gtk_widget_size_allocate (self->priv->block_widget[inverted ? 0 : 1], + gtk_widget_size_allocate (priv->block_widget[inverted ? 0 : 1], allocation, baseline, out_clip); - if (self->priv->cur_value == 0) + if (priv->cur_value == 0) return; /* now allocate the filled part */ block_area = *allocation; - fill_percentage = (self->priv->cur_value - self->priv->min_value) / - (self->priv->max_value - self->priv->min_value); + fill_percentage = (priv->cur_value - priv->min_value) / + (priv->max_value - priv->min_value); - gtk_widget_measure (self->priv->block_widget[inverted ? 1 : 0], - self->priv->orientation, -1, + gtk_widget_measure (priv->block_widget[inverted ? 1 : 0], + priv->orientation, -1, &block_min, NULL, NULL, NULL); - if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL) + if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) { block_area.width = (gint) floor (block_area.width * fill_percentage); block_area.width = MAX (block_area.width, block_min); @@ -471,7 +486,7 @@ gtk_level_bar_allocate_trough_continuous (GtkLevelBar *self, block_area.y += allocation->height - block_area.height; } - gtk_widget_size_allocate (self->priv->block_widget[inverted ? 1 : 0], + gtk_widget_size_allocate (priv->block_widget[inverted ? 1 : 0], &block_area, baseline, &clip); @@ -484,6 +499,7 @@ gtk_level_bar_allocate_trough_discrete (GtkLevelBar *self, int baseline, GtkAllocation *out_clip) { + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); GtkAllocation block_area, clip; gint num_blocks, i; gint block_width, block_height; @@ -494,7 +510,7 @@ gtk_level_bar_allocate_trough_discrete (GtkLevelBar *self, if (num_blocks == 0) return; - if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL) + if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) { block_width = MAX (block_width, (gint) floor (allocation->width / num_blocks)); block_height = allocation->height; @@ -512,13 +528,13 @@ gtk_level_bar_allocate_trough_discrete (GtkLevelBar *self, for (i = 0; i < num_blocks; i++) { - gtk_widget_size_allocate (self->priv->block_widget[i], + gtk_widget_size_allocate (priv->block_widget[i], &block_area, baseline, &clip); gdk_rectangle_intersect (out_clip, &clip, out_clip); - if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL) + if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) block_area.x += block_area.width; else block_area.y += block_area.height; @@ -533,8 +549,9 @@ gtk_level_bar_allocate_trough (GtkGizmo *gizmo, { GtkWidget *widget = GTK_WIDGET (gizmo); GtkLevelBar *self = GTK_LEVEL_BAR (gtk_widget_get_parent (widget)); + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); - if (self->priv->bar_mode == GTK_LEVEL_BAR_MODE_CONTINUOUS) + if (priv->bar_mode == GTK_LEVEL_BAR_MODE_CONTINUOUS) gtk_level_bar_allocate_trough_continuous (self, allocation, baseline, out_clip); else gtk_level_bar_allocate_trough_discrete (self, allocation, baseline, out_clip); @@ -554,7 +571,7 @@ gtk_level_bar_size_allocate (GtkWidget *widget, static void update_block_nodes (GtkLevelBar *self) { - GtkLevelBarPrivate *priv = self->priv; + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); guint n_blocks; guint i; @@ -586,7 +603,7 @@ update_block_nodes (GtkLevelBar *self) static void update_mode_style_classes (GtkLevelBar *self) { - GtkLevelBarPrivate *priv = self->priv; + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); GtkCssNode *widget_node; widget_node = gtk_widget_get_css_node (GTK_WIDGET (self)); @@ -605,7 +622,7 @@ update_mode_style_classes (GtkLevelBar *self) static void update_level_style_classes (GtkLevelBar *self) { - GtkLevelBarPrivate *priv = self->priv; + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); gdouble value; const gchar *value_class = NULL; GtkLevelBarOffset *offset, *prev_offset; @@ -689,18 +706,19 @@ gtk_level_bar_direction_changed (GtkWidget *widget, static void gtk_level_bar_ensure_offsets_in_range (GtkLevelBar *self) { + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); GtkLevelBarOffset *offset; - GList *l = self->priv->offsets; + GList *l = priv->offsets; while (l != NULL) { offset = l->data; l = l->next; - if (offset->value < self->priv->min_value) - gtk_level_bar_ensure_offset (self, offset->name, self->priv->min_value); - else if (offset->value > self->priv->max_value) - gtk_level_bar_ensure_offset (self, offset->name, self->priv->max_value); + if (offset->value < priv->min_value) + gtk_level_bar_ensure_offset (self, offset->name, priv->min_value); + else if (offset->value > priv->max_value) + gtk_level_bar_ensure_offset (self, offset->name, priv->max_value); } } @@ -837,9 +855,10 @@ static void gtk_level_bar_set_orientation (GtkLevelBar *self, GtkOrientation orientation) { - if (self->priv->orientation != orientation) + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); + if (priv->orientation != orientation) { - self->priv->orientation = orientation; + priv->orientation = orientation; _gtk_orientable_set_style_classes (GTK_ORIENTABLE (self)); gtk_widget_queue_resize (GTK_WIDGET (self)); g_object_notify (G_OBJECT (self), "orientation"); @@ -853,6 +872,7 @@ gtk_level_bar_get_property (GObject *obj, GParamSpec *pspec) { GtkLevelBar *self = GTK_LEVEL_BAR (obj); + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); switch (property_id) { @@ -872,7 +892,7 @@ gtk_level_bar_get_property (GObject *obj, g_value_set_boolean (value, gtk_level_bar_get_inverted (self)); break; case PROP_ORIENTATION: - g_value_set_enum (value, self->priv->orientation); + g_value_set_enum (value, priv->orientation); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec); @@ -918,7 +938,7 @@ static void gtk_level_bar_finalize (GObject *obj) { GtkLevelBar *self = GTK_LEVEL_BAR (obj); - GtkLevelBarPrivate *priv = self->priv; + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); gint i; g_list_free_full (priv->offsets, (GDestroyNotify) gtk_level_bar_offset_free); @@ -1053,9 +1073,7 @@ gtk_level_bar_class_init (GtkLevelBarClass *klass) static void gtk_level_bar_init (GtkLevelBar *self) { - GtkLevelBarPrivate *priv; - - priv = self->priv = gtk_level_bar_get_instance_private (self); + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); priv->cur_value = 0.0; priv->min_value = 0.0; @@ -1132,9 +1150,11 @@ gtk_level_bar_new_for_interval (gdouble min_value, gdouble gtk_level_bar_get_min_value (GtkLevelBar *self) { + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); + g_return_val_if_fail (GTK_IS_LEVEL_BAR (self), 0.0); - return self->priv->min_value; + return priv->min_value; } /** @@ -1148,9 +1168,11 @@ gtk_level_bar_get_min_value (GtkLevelBar *self) gdouble gtk_level_bar_get_max_value (GtkLevelBar *self) { + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); + g_return_val_if_fail (GTK_IS_LEVEL_BAR (self), 0.0); - return self->priv->max_value; + return priv->max_value; } /** @@ -1165,18 +1187,22 @@ gtk_level_bar_get_max_value (GtkLevelBar *self) gdouble gtk_level_bar_get_value (GtkLevelBar *self) { + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); + g_return_val_if_fail (GTK_IS_LEVEL_BAR (self), 0.0); - return self->priv->cur_value; + return priv->cur_value; } static void gtk_level_bar_set_value_internal (GtkLevelBar *self, gdouble value) { - self->priv->cur_value = value; + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); + + priv->cur_value = value; g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_VALUE]); - gtk_widget_queue_allocate (GTK_WIDGET (self->priv->trough_widget)); + gtk_widget_queue_allocate (GTK_WIDGET (priv->trough_widget)); } /** @@ -1193,7 +1219,7 @@ void gtk_level_bar_set_min_value (GtkLevelBar *self, gdouble value) { - GtkLevelBarPrivate *priv = self->priv; + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); g_return_if_fail (GTK_IS_LEVEL_BAR (self)); g_return_if_fail (value >= 0.0); @@ -1225,7 +1251,7 @@ void gtk_level_bar_set_max_value (GtkLevelBar *self, gdouble value) { - GtkLevelBarPrivate *priv = self->priv; + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); g_return_if_fail (GTK_IS_LEVEL_BAR (self)); g_return_if_fail (value >= 0.0); @@ -1256,9 +1282,11 @@ void gtk_level_bar_set_value (GtkLevelBar *self, gdouble value) { + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); + g_return_if_fail (GTK_IS_LEVEL_BAR (self)); - if (value == self->priv->cur_value) + if (value == priv->cur_value) return; gtk_level_bar_set_value_internal (self, value); @@ -1276,9 +1304,11 @@ gtk_level_bar_set_value (GtkLevelBar *self, GtkLevelBarMode gtk_level_bar_get_mode (GtkLevelBar *self) { + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); + g_return_val_if_fail (GTK_IS_LEVEL_BAR (self), 0); - return self->priv->bar_mode; + return priv->bar_mode; } /** @@ -1292,7 +1322,7 @@ void gtk_level_bar_set_mode (GtkLevelBar *self, GtkLevelBarMode mode) { - GtkLevelBarPrivate *priv = self->priv; + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); g_return_if_fail (GTK_IS_LEVEL_BAR (self)); @@ -1320,9 +1350,11 @@ gtk_level_bar_set_mode (GtkLevelBar *self, gboolean gtk_level_bar_get_inverted (GtkLevelBar *self) { + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); + g_return_val_if_fail (GTK_IS_LEVEL_BAR (self), FALSE); - return self->priv->inverted; + return priv->inverted; } /** @@ -1336,7 +1368,7 @@ void gtk_level_bar_set_inverted (GtkLevelBar *self, gboolean inverted) { - GtkLevelBarPrivate *priv = self->priv; + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); g_return_if_fail (GTK_IS_LEVEL_BAR (self)); @@ -1361,7 +1393,7 @@ void gtk_level_bar_remove_offset_value (GtkLevelBar *self, const gchar *name) { - GtkLevelBarPrivate *priv = self->priv; + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); GList *existing; g_return_if_fail (GTK_IS_LEVEL_BAR (self)); @@ -1424,12 +1456,13 @@ gtk_level_bar_get_offset_value (GtkLevelBar *self, const gchar *name, gdouble *value) { + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); GList *existing; GtkLevelBarOffset *offset = NULL; g_return_val_if_fail (GTK_IS_LEVEL_BAR (self), 0.0); - existing = g_list_find_custom (self->priv->offsets, name, offset_find_func); + existing = g_list_find_custom (priv->offsets, name, offset_find_func); if (existing) offset = existing->data; diff --git a/gtk/gtklevelbar.h b/gtk/gtklevelbar.h index b9c14336c4..67c274f851 100644 --- a/gtk/gtklevelbar.h +++ b/gtk/gtklevelbar.h @@ -59,13 +59,10 @@ G_BEGIN_DECLS typedef struct _GtkLevelBarClass GtkLevelBarClass; typedef struct _GtkLevelBar GtkLevelBar; -typedef struct _GtkLevelBarPrivate GtkLevelBarPrivate; struct _GtkLevelBar { /*< private >*/ - GtkWidget parent; - - GtkLevelBarPrivate *priv; + GtkWidget parent_instance; }; struct _GtkLevelBarClass { diff --git a/gtk/gtkpaned.c b/gtk/gtkpaned.c index 62cd9d8088..75f441a0f3 100644 --- a/gtk/gtkpaned.c +++ b/gtk/gtkpaned.c @@ -128,6 +128,7 @@ enum { CHILD2 }; +typedef struct _GtkPanedPrivate GtkPanedPrivate; struct _GtkPanedPrivate { GtkPaned *first_paned; @@ -697,7 +698,7 @@ static GType gtk_paned_child_type (GtkContainer *container) { GtkPaned *paned = GTK_PANED (container); - GtkPanedPrivate *priv = paned->priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); if (!priv->child1 || !priv->child2) return GTK_TYPE_WIDGET; @@ -711,7 +712,7 @@ initiates_touch_drag (GtkPaned *paned, gdouble start_y) { gint handle_size, handle_pos, drag_pos; - GtkPanedPrivate *priv = paned->priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); #define TOUCH_EXTRA_AREA_WIDTH 50 gtk_widget_measure (priv->handle_widget, @@ -746,7 +747,7 @@ gesture_drag_begin_cb (GtkGestureDrag *gesture, gdouble start_y, GtkPaned *paned) { - GtkPanedPrivate *priv = paned->priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); GdkEventSequence *sequence; GdkRectangle handle_area; const GdkEvent *event; @@ -779,7 +780,7 @@ gesture_drag_begin_cb (GtkGestureDrag *gesture, else priv->drag_pos = start_y - priv->handle_pos.y; - paned->priv->panning = TRUE; + priv->panning = TRUE; gtk_grab_add (GTK_WIDGET (paned)); gtk_gesture_set_state (GTK_GESTURE (gesture), @@ -811,12 +812,13 @@ gesture_drag_end_cb (GtkGestureDrag *gesture, gdouble offset_y, GtkPaned *paned) { + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); - if (!paned->priv->panning) + if (!priv->panning) gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_DENIED); gtk_grab_remove (GTK_WIDGET (paned)); - paned->priv->panning = FALSE; + priv->panning = FALSE; } static void @@ -826,7 +828,7 @@ gtk_paned_set_property (GObject *object, GParamSpec *pspec) { GtkPaned *paned = GTK_PANED (object); - GtkPanedPrivate *priv = paned->priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); switch (prop_id) { @@ -875,7 +877,7 @@ gtk_paned_get_property (GObject *object, GParamSpec *pspec) { GtkPaned *paned = GTK_PANED (object); - GtkPanedPrivate *priv = paned->priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); switch (prop_id) { @@ -911,7 +913,7 @@ gtk_paned_set_child_property (GtkContainer *container, GParamSpec *pspec) { GtkPaned *paned = GTK_PANED (container); - GtkPanedPrivate *priv = paned->priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); gboolean old_value, new_value; g_assert (child == priv->child1 || child == priv->child2); @@ -960,7 +962,7 @@ gtk_paned_get_child_property (GtkContainer *container, GParamSpec *pspec) { GtkPaned *paned = GTK_PANED (container); - GtkPanedPrivate *priv = paned->priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); if (child != priv->child1 && child != priv->child2) @@ -995,9 +997,9 @@ gtk_paned_finalize (GObject *object) gtk_paned_set_saved_focus (paned, NULL); gtk_paned_set_first_paned (paned, NULL); - g_clear_object (&paned->priv->pan_gesture); - g_clear_object (&paned->priv->drag_gesture); - g_clear_object (&paned->priv->motion_controller); + g_clear_object (&priv->pan_gesture); + g_clear_object (&priv->drag_gesture); + g_clear_object (&priv->motion_controller); gtk_widget_unparent (priv->handle_widget); @@ -1013,7 +1015,7 @@ gtk_paned_compute_position (GtkPaned *paned, gint *max_pos, gint *out_pos) { - GtkPanedPrivate *priv = paned->priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); gint min, max, pos; min = priv->child1_shrink ? 0 : child1_req; @@ -1069,7 +1071,7 @@ gtk_paned_get_preferred_size_for_orientation (GtkWidget *widget, gint *natural) { GtkPaned *paned = GTK_PANED (widget); - GtkPanedPrivate *priv = paned->priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); gint child_min, child_nat; *minimum = *natural = 0; @@ -1116,7 +1118,7 @@ gtk_paned_get_preferred_size_for_opposite_orientation (GtkWidget *widget, gint *natural) { GtkPaned *paned = GTK_PANED (widget); - GtkPanedPrivate *priv = paned->priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); gint for_child1, for_child2; gint child_min, child_nat; @@ -1185,7 +1187,7 @@ gtk_paned_measure (GtkWidget *widget, int *natural_baseline) { GtkPaned *paned = GTK_PANED (widget); - GtkPanedPrivate *priv = paned->priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); if (orientation == priv->orientation) gtk_paned_get_preferred_size_for_orientation (widget, for_size, minimum, natural); @@ -1210,7 +1212,7 @@ gtk_paned_set_child_visible (GtkPaned *paned, guint id, gboolean visible) { - GtkPanedPrivate *priv = paned->priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); GtkWidget *child; child = id == CHILD1 ? priv->child1 : priv->child2; @@ -1228,7 +1230,7 @@ gtk_paned_size_allocate (GtkWidget *widget, GtkAllocation *out_clip) { GtkPaned *paned = GTK_PANED (widget); - GtkPanedPrivate *priv = paned->priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); GtkAllocation child_clip; if (priv->child1 && gtk_widget_get_visible (priv->child1) && @@ -1494,15 +1496,12 @@ connect_drag_gesture_signals (GtkPaned *paned, static void gtk_paned_init (GtkPaned *paned) { - GtkPanedPrivate *priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); GtkGesture *gesture; gtk_widget_set_has_surface (GTK_WIDGET (paned), FALSE); gtk_widget_set_can_focus (GTK_WIDGET (paned), TRUE); - paned->priv = gtk_paned_get_instance_private (paned); - priv = paned->priv; - priv->orientation = GTK_ORIENTATION_HORIZONTAL; priv->child1 = NULL; @@ -1553,7 +1552,7 @@ gtk_paned_init (GtkPaned *paned) static gboolean is_rtl (GtkPaned *paned) { - GtkPanedPrivate *priv = paned->priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); if (priv->orientation == GTK_ORIENTATION_HORIZONTAL && gtk_widget_get_direction (GTK_WIDGET (paned)) == GTK_TEXT_DIR_RTL) @@ -1569,7 +1568,7 @@ update_drag (GtkPaned *paned, int xpos, int ypos) { - GtkPanedPrivate *priv = paned->priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); gint pos; gint handle_size; gint size; @@ -1625,8 +1624,9 @@ gtk_paned_direction_changed (GtkWidget *widget, GtkTextDirection previous_direction) { GtkPaned *paned = GTK_PANED (widget); + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); - if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL) + if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) gtk_css_node_reverse_children (gtk_widget_get_css_node (widget)); } @@ -1693,13 +1693,11 @@ gtk_paned_pack1 (GtkPaned *paned, gboolean resize, gboolean shrink) { - GtkPanedPrivate *priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); g_return_if_fail (GTK_IS_PANED (paned)); g_return_if_fail (GTK_IS_WIDGET (child)); - priv = paned->priv; - if (!priv->child1) { priv->child1 = child; @@ -1728,13 +1726,11 @@ gtk_paned_pack2 (GtkPaned *paned, gboolean resize, gboolean shrink) { - GtkPanedPrivate *priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); g_return_if_fail (GTK_IS_PANED (paned)); g_return_if_fail (GTK_IS_WIDGET (child)); - priv = paned->priv; - if (!priv->child2) { priv->child2 = child; @@ -1759,7 +1755,7 @@ gtk_paned_add (GtkContainer *container, g_return_if_fail (GTK_IS_PANED (container)); paned = GTK_PANED (container); - priv = paned->priv; + priv = gtk_paned_get_instance_private (paned); if (!priv->child1) gtk_paned_add1 (paned, widget); @@ -1774,7 +1770,7 @@ gtk_paned_remove (GtkContainer *container, GtkWidget *widget) { GtkPaned *paned = GTK_PANED (container); - GtkPanedPrivate *priv = paned->priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); if (priv->child1 == widget) { @@ -1795,14 +1791,10 @@ gtk_paned_forall (GtkContainer *container, GtkCallback callback, gpointer callback_data) { - GtkPanedPrivate *priv; - GtkPaned *paned; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (GTK_PANED (container)); g_return_if_fail (callback != NULL); - paned = GTK_PANED (container); - priv = paned->priv; - if (priv->child1) (*callback) (priv->child1, callback_data); if (priv->child2) @@ -1820,9 +1812,11 @@ gtk_paned_forall (GtkContainer *container, gint gtk_paned_get_position (GtkPaned *paned) { + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); + g_return_val_if_fail (GTK_IS_PANED (paned), 0); - return paned->priv->child1_size; + return priv->child1_size; } /** @@ -1837,12 +1831,10 @@ void gtk_paned_set_position (GtkPaned *paned, gint position) { - GtkPanedPrivate *priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); g_return_if_fail (GTK_IS_PANED (paned)); - priv = paned->priv; - g_object_freeze_notify (G_OBJECT (paned)); if (position >= 0) @@ -1896,9 +1888,11 @@ gtk_paned_set_position (GtkPaned *paned, GtkWidget * gtk_paned_get_child1 (GtkPaned *paned) { + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); + g_return_val_if_fail (GTK_IS_PANED (paned), NULL); - return paned->priv->child1; + return priv->child1; } /** @@ -1912,9 +1906,11 @@ gtk_paned_get_child1 (GtkPaned *paned) GtkWidget * gtk_paned_get_child2 (GtkPaned *paned) { + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); + g_return_val_if_fail (GTK_IS_PANED (paned), NULL); - return paned->priv->child2; + return priv->child2; } static void @@ -1923,7 +1919,7 @@ gtk_paned_calc_position (GtkPaned *paned, gint child1_req, gint child2_req) { - GtkPanedPrivate *priv = paned->priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); gint old_position; gint old_min_position; gint old_max_position; @@ -1955,7 +1951,7 @@ gtk_paned_calc_position (GtkPaned *paned, static void gtk_paned_set_saved_focus (GtkPaned *paned, GtkWidget *widget) { - GtkPanedPrivate *priv = paned->priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); if (priv->saved_focus) g_object_remove_weak_pointer (G_OBJECT (priv->saved_focus), @@ -1971,7 +1967,7 @@ gtk_paned_set_saved_focus (GtkPaned *paned, GtkWidget *widget) static void gtk_paned_set_first_paned (GtkPaned *paned, GtkPaned *first_paned) { - GtkPanedPrivate *priv = paned->priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); if (priv->first_paned) g_object_remove_weak_pointer (G_OBJECT (priv->first_paned), @@ -1987,7 +1983,7 @@ gtk_paned_set_first_paned (GtkPaned *paned, GtkPaned *first_paned) static void gtk_paned_set_last_child1_focus (GtkPaned *paned, GtkWidget *widget) { - GtkPanedPrivate *priv = paned->priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); if (priv->last_child1_focus) g_object_remove_weak_pointer (G_OBJECT (priv->last_child1_focus), @@ -2003,7 +1999,7 @@ gtk_paned_set_last_child1_focus (GtkPaned *paned, GtkWidget *widget) static void gtk_paned_set_last_child2_focus (GtkPaned *paned, GtkWidget *widget) { - GtkPanedPrivate *priv = paned->priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); if (priv->last_child2_focus) g_object_remove_weak_pointer (G_OBJECT (priv->last_child2_focus), @@ -2032,20 +2028,17 @@ static void gtk_paned_set_focus_child (GtkContainer *container, GtkWidget *focus_child) { - GtkPaned *paned; - GtkPanedPrivate *priv; + GtkPaned *paned = GTK_PANED (container); + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); GtkWidget *container_focus_child; g_return_if_fail (GTK_IS_PANED (container)); - paned = GTK_PANED (container); - priv = paned->priv; - if (focus_child == NULL) { GtkWidget *last_focus; GtkWidget *w; - + last_focus = paned_get_focus_widget (paned); if (last_focus) @@ -2074,7 +2067,7 @@ gtk_paned_get_cycle_chain (GtkPaned *paned, GtkDirectionType direction, GList **widgets) { - GtkPanedPrivate *priv = paned->priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); GtkWidget *ancestor = NULL; GtkWidget *focus_child; GtkWidget *parent; @@ -2220,7 +2213,7 @@ get_child_panes (GtkWidget *widget, if (GTK_IS_PANED (widget)) { GtkPaned *paned = GTK_PANED (widget); - GtkPanedPrivate *priv = paned->priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); get_child_panes (priv->child1, panes); *panes = g_list_prepend (*panes, widget); @@ -2285,7 +2278,7 @@ static gboolean gtk_paned_move_handle (GtkPaned *paned, GtkScrollType scroll) { - GtkPanedPrivate *priv = paned->priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); if (gtk_widget_is_focus (GTK_WIDGET (paned))) { @@ -2363,7 +2356,7 @@ gtk_paned_move_handle (GtkPaned *paned, static void gtk_paned_restore_focus (GtkPaned *paned) { - GtkPanedPrivate *priv = paned->priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); if (gtk_widget_is_focus (GTK_WIDGET (paned))) { @@ -2398,7 +2391,7 @@ gtk_paned_restore_focus (GtkPaned *paned) static gboolean gtk_paned_accept_position (GtkPaned *paned) { - GtkPanedPrivate *priv = paned->priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); if (gtk_widget_is_focus (GTK_WIDGET (paned))) { @@ -2415,7 +2408,7 @@ gtk_paned_accept_position (GtkPaned *paned) static gboolean gtk_paned_cancel_position (GtkPaned *paned) { - GtkPanedPrivate *priv = paned->priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); if (gtk_widget_is_focus (GTK_WIDGET (paned))) { @@ -2436,7 +2429,7 @@ static gboolean gtk_paned_cycle_handle_focus (GtkPaned *paned, gboolean reversed) { - GtkPanedPrivate *priv = paned->priv; + GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned); GtkPaned *next, *prev; if (gtk_widget_is_focus (GTK_WIDGET (paned))) @@ -2484,7 +2477,7 @@ gtk_paned_cycle_handle_focus (GtkPaned *paned, if (!gtk_widget_is_focus (GTK_WIDGET (paned))) { priv->original_position = -1; - focus->priv->original_position = gtk_paned_get_position (focus); + priv->original_position = gtk_paned_get_position (focus); } } else @@ -2542,7 +2535,7 @@ gtk_paned_cycle_handle_focus (GtkPaned *paned, if (GTK_IS_WINDOW (toplevel)) gtk_paned_set_saved_focus (focus, gtk_window_get_focus (GTK_WINDOW (toplevel))); gtk_paned_set_first_paned (focus, first); - focus->priv->original_position = gtk_paned_get_position (focus); + priv->original_position = gtk_paned_get_position (focus); gtk_widget_grab_focus (GTK_WIDGET (focus)); } diff --git a/gtk/gtkpaned.h b/gtk/gtkpaned.h index 8b0ad49832..c144b353a4 100644 --- a/gtk/gtkpaned.h +++ b/gtk/gtkpaned.h @@ -43,14 +43,10 @@ G_BEGIN_DECLS typedef struct _GtkPaned GtkPaned; typedef struct _GtkPanedClass GtkPanedClass; -typedef struct _GtkPanedPrivate GtkPanedPrivate; struct _GtkPaned { - GtkContainer container; - - /*< private >*/ - GtkPanedPrivate *priv; + GtkContainer parent_instance; }; struct _GtkPanedClass diff --git a/gtk/gtkprogressbar.c b/gtk/gtkprogressbar.c index a3d7f7ebcb..7c5dea58cb 100644 --- a/gtk/gtkprogressbar.c +++ b/gtk/gtkprogressbar.c @@ -91,7 +91,7 @@ * in overlays like the one Epiphany has for page loading progress. */ -struct _GtkProgressBarPrivate +typedef struct { gchar *text; @@ -118,7 +118,7 @@ struct _GtkProgressBarPrivate guint ellipsize : 3; guint show_text : 1; guint inverted : 1; -}; +} GtkProgressBarPrivate; enum { PROP_0, @@ -147,8 +147,6 @@ static void gtk_progress_bar_size_allocate (GtkWidget *widget, int baseline, GtkAllocation *out_clip); -static void gtk_progress_bar_snapshot (GtkWidget *widget, - GtkSnapshot *snapshot); static void gtk_progress_bar_act_mode_enter (GtkProgressBar *progress); static void gtk_progress_bar_act_mode_leave (GtkProgressBar *progress); static void gtk_progress_bar_finalize (GObject *object); @@ -182,9 +180,8 @@ gtk_progress_bar_class_init (GtkProgressBarClass *class) gobject_class->get_property = gtk_progress_bar_get_property; gobject_class->finalize = gtk_progress_bar_finalize; - widget_class->snapshot = gtk_progress_bar_snapshot; - widget_class->size_allocate = gtk_progress_bar_size_allocate; widget_class->measure = gtk_progress_bar_measure; + widget_class->size_allocate = gtk_progress_bar_size_allocate; widget_class->direction_changed = gtk_progress_bar_direction_changed; g_object_class_override_property (gobject_class, PROP_ORIENTATION, "orientation"); @@ -269,7 +266,7 @@ gtk_progress_bar_class_init (GtkProgressBarClass *class) static void update_fraction_classes (GtkProgressBar *pbar) { - GtkProgressBarPrivate *priv = pbar->priv; + GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); GtkStyleContext *context; gboolean empty = FALSE; gboolean full = FALSE; @@ -301,7 +298,7 @@ update_fraction_classes (GtkProgressBar *pbar) static void update_node_classes (GtkProgressBar *pbar) { - GtkProgressBarPrivate *priv = pbar->priv; + GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); GtkStyleContext *context; gboolean left = FALSE; gboolean right = FALSE; @@ -381,7 +378,7 @@ allocate_trough (GtkGizmo *gizmo, { GtkProgressBar *pbar = GTK_PROGRESS_BAR (gtk_widget_get_parent (GTK_WIDGET (gizmo))); - GtkProgressBarPrivate *priv = pbar->priv; + GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); GtkAllocation alloc; gint width, height; gboolean inverted; @@ -455,8 +452,9 @@ snapshot_trough (GtkGizmo *gizmo, { GtkProgressBar *pbar = GTK_PROGRESS_BAR (gtk_widget_get_parent (GTK_WIDGET (gizmo))); + GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); - gtk_widget_snapshot_child (GTK_WIDGET (gizmo), pbar->priv->progress_widget, snapshot); + gtk_widget_snapshot_child (GTK_WIDGET (gizmo), priv->progress_widget, snapshot); return FALSE; } @@ -464,10 +462,7 @@ snapshot_trough (GtkGizmo *gizmo, static void gtk_progress_bar_init (GtkProgressBar *pbar) { - GtkProgressBarPrivate *priv; - - pbar->priv = gtk_progress_bar_get_instance_private (pbar); - priv = pbar->priv; + GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); priv->orientation = GTK_ORIENTATION_HORIZONTAL; priv->inverted = FALSE; @@ -543,7 +538,7 @@ gtk_progress_bar_get_property (GObject *object, GParamSpec *pspec) { GtkProgressBar *pbar = GTK_PROGRESS_BAR (object); - GtkProgressBarPrivate* priv = pbar->priv; + GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); switch (prop_id) { @@ -595,7 +590,7 @@ static void gtk_progress_bar_finalize (GObject *object) { GtkProgressBar *pbar = GTK_PROGRESS_BAR (object); - GtkProgressBarPrivate *priv = pbar->priv; + GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); if (priv->activity_mode) gtk_progress_bar_act_mode_leave (pbar); @@ -614,7 +609,7 @@ gtk_progress_bar_finalize (GObject *object) static gchar * get_current_text (GtkProgressBar *pbar) { - GtkProgressBarPrivate *priv = pbar->priv; + GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); if (priv->text) return g_strdup (priv->text); @@ -629,14 +624,12 @@ gtk_progress_bar_size_allocate (GtkWidget *widget, GtkAllocation *out_clip) { GtkAllocation child_clip = *allocation; - GtkProgressBarPrivate *priv; + GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (GTK_PROGRESS_BAR (widget)); gint bar_width, bar_height; gint text_width, text_height, text_min, text_nat; GtkAllocation alloc; GtkAllocation text_clip; - priv = GTK_PROGRESS_BAR (widget)->priv; - if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) { gtk_widget_measure (priv->trough_widget, GTK_ORIENTATION_VERTICAL, -1, @@ -700,14 +693,11 @@ gtk_progress_bar_measure (GtkWidget *widget, int *minimum_baseline, int *natural_baseline) { - GtkProgressBar *pbar; - GtkProgressBarPrivate *priv; + GtkProgressBar *pbar = GTK_PROGRESS_BAR (widget); + GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); gint text_minimum, text_natural; gint trough_minimum, trough_natural; - pbar = GTK_PROGRESS_BAR (widget); - priv = pbar->priv; - if (priv->show_text) gtk_widget_measure (priv->label, orientation, -1, &text_minimum, &text_natural, @@ -753,7 +743,7 @@ tick_cb (GtkWidget *widget, gpointer user_data) { GtkProgressBar *pbar = GTK_PROGRESS_BAR (widget); - GtkProgressBarPrivate *priv = pbar->priv; + GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); gint64 frame_time; gdouble iteration, pulse_iterations, current_iterations, fraction; @@ -809,7 +799,7 @@ tick_cb (GtkWidget *widget, static void gtk_progress_bar_act_mode_enter (GtkProgressBar *pbar) { - GtkProgressBarPrivate *priv = pbar->priv; + GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); GtkWidget *widget = GTK_WIDGET (pbar); gboolean inverted; @@ -847,7 +837,7 @@ gtk_progress_bar_act_mode_enter (GtkProgressBar *pbar) static void gtk_progress_bar_act_mode_leave (GtkProgressBar *pbar) { - GtkProgressBarPrivate *priv = pbar->priv; + GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); if (priv->tick_id) gtk_widget_remove_tick_callback (GTK_WIDGET (pbar), priv->tick_id); @@ -859,22 +849,10 @@ gtk_progress_bar_act_mode_leave (GtkProgressBar *pbar) } static void -gtk_progress_bar_snapshot (GtkWidget *widget, - GtkSnapshot *snapshot) -{ - GtkProgressBar *pbar = GTK_PROGRESS_BAR (widget); - GtkProgressBarPrivate *priv = pbar->priv; - - gtk_widget_snapshot_child (widget, priv->trough_widget, snapshot); - if (priv->show_text) - gtk_widget_snapshot_child (widget, priv->label, snapshot); -} - -static void gtk_progress_bar_set_activity_mode (GtkProgressBar *pbar, gboolean activity_mode) { - GtkProgressBarPrivate *priv = pbar->priv; + GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); activity_mode = !!activity_mode; @@ -904,12 +882,10 @@ void gtk_progress_bar_set_fraction (GtkProgressBar *pbar, gdouble fraction) { - GtkProgressBarPrivate* priv; + GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar)); - priv = pbar->priv; - priv->fraction = CLAMP (fraction, 0.0, 1.0); if (priv->label) @@ -930,7 +906,7 @@ gtk_progress_bar_set_fraction (GtkProgressBar *pbar, static void gtk_progress_bar_update_pulse (GtkProgressBar *pbar) { - GtkProgressBarPrivate *priv = pbar->priv; + GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); gint64 pulse_time = g_get_monotonic_time (); if (priv->pulse2 == pulse_time) @@ -979,12 +955,10 @@ void gtk_progress_bar_set_text (GtkProgressBar *pbar, const gchar *text) { - GtkProgressBarPrivate *priv; + GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar)); - priv = pbar->priv; - /* Don't notify again if nothing's changed. */ if (g_strcmp0 (priv->text, text) == 0) return; @@ -1018,12 +992,10 @@ void gtk_progress_bar_set_show_text (GtkProgressBar *pbar, gboolean show_text) { - GtkProgressBarPrivate *priv; + GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar)); - priv = pbar->priv; - show_text = !!show_text; if (priv->show_text == show_text) @@ -1070,9 +1042,11 @@ gtk_progress_bar_set_show_text (GtkProgressBar *pbar, gboolean gtk_progress_bar_get_show_text (GtkProgressBar *pbar) { + GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); + g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), FALSE); - return pbar->priv->show_text; + return priv->show_text; } /** @@ -1087,12 +1061,10 @@ void gtk_progress_bar_set_pulse_step (GtkProgressBar *pbar, gdouble fraction) { - GtkProgressBarPrivate *priv; + GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar)); - priv = pbar->priv; - priv->pulse_fraction = fraction; g_object_notify_by_pspec (G_OBJECT (pbar), progress_props[PROP_PULSE_STEP]); @@ -1113,7 +1085,7 @@ static void gtk_progress_bar_set_orientation (GtkProgressBar *pbar, GtkOrientation orientation) { - GtkProgressBarPrivate *priv = pbar->priv; + GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); if (priv->orientation == orientation) return; @@ -1139,12 +1111,10 @@ void gtk_progress_bar_set_inverted (GtkProgressBar *pbar, gboolean inverted) { - GtkProgressBarPrivate *priv; + GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar)); - priv = pbar->priv; - if (priv->inverted == inverted) return; @@ -1171,9 +1141,11 @@ gtk_progress_bar_set_inverted (GtkProgressBar *pbar, const gchar* gtk_progress_bar_get_text (GtkProgressBar *pbar) { + GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); + g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), NULL); - return pbar->priv->text; + return priv->text; } /** @@ -1187,9 +1159,11 @@ gtk_progress_bar_get_text (GtkProgressBar *pbar) gdouble gtk_progress_bar_get_fraction (GtkProgressBar *pbar) { + GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); + g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), 0); - return pbar->priv->fraction; + return priv->fraction; } /** @@ -1203,9 +1177,11 @@ gtk_progress_bar_get_fraction (GtkProgressBar *pbar) gdouble gtk_progress_bar_get_pulse_step (GtkProgressBar *pbar) { + GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); + g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), 0); - return pbar->priv->pulse_fraction; + return priv->pulse_fraction; } /** @@ -1219,9 +1195,11 @@ gtk_progress_bar_get_pulse_step (GtkProgressBar *pbar) gboolean gtk_progress_bar_get_inverted (GtkProgressBar *pbar) { + GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); + g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), FALSE); - return pbar->priv->inverted; + return priv->inverted; } /** @@ -1236,14 +1214,12 @@ void gtk_progress_bar_set_ellipsize (GtkProgressBar *pbar, PangoEllipsizeMode mode) { - GtkProgressBarPrivate *priv; + GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar)); g_return_if_fail (mode >= PANGO_ELLIPSIZE_NONE && mode <= PANGO_ELLIPSIZE_END); - priv = pbar->priv; - if ((PangoEllipsizeMode)priv->ellipsize != mode) { priv->ellipsize = mode; @@ -1268,7 +1244,9 @@ gtk_progress_bar_set_ellipsize (GtkProgressBar *pbar, PangoEllipsizeMode gtk_progress_bar_get_ellipsize (GtkProgressBar *pbar) { + GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar); + g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), PANGO_ELLIPSIZE_NONE); - return pbar->priv->ellipsize; + return priv->ellipsize; } diff --git a/gtk/gtkprogressbar.h b/gtk/gtkprogressbar.h index 70c936d05b..c757be794f 100644 --- a/gtk/gtkprogressbar.h +++ b/gtk/gtkprogressbar.h @@ -42,15 +42,11 @@ G_BEGIN_DECLS typedef struct _GtkProgressBar GtkProgressBar; -typedef struct _GtkProgressBarPrivate GtkProgressBarPrivate; typedef struct _GtkProgressBarClass GtkProgressBarClass; struct _GtkProgressBar { - GtkWidget parent; - - /*< private >*/ - GtkProgressBarPrivate *priv; + GtkWidget parent_instance; }; struct _GtkProgressBarClass diff --git a/gtk/gtksnapshot.c b/gtk/gtksnapshot.c index c9ebf0b5a0..420f7b6c87 100644 --- a/gtk/gtksnapshot.c +++ b/gtk/gtksnapshot.c @@ -1339,6 +1339,20 @@ gtk_snapshot_append_cairo (GtkSnapshot *snapshot, g_return_val_if_fail (bounds != NULL, NULL); graphene_rect_offset_r (bounds, current_state->translate_x, current_state->translate_y, &real_bounds); + + if (current_state->clip_region) + { + cairo_rectangle_int_t clip_extents; + cairo_region_get_extents (current_state->clip_region, &clip_extents); + graphene_rect_intersection (&GRAPHENE_RECT_INIT ( + clip_extents.x, + clip_extents.y, + clip_extents.width, + clip_extents.height + ), + &real_bounds, &real_bounds); + } + node = gsk_cairo_node_new (&real_bounds); if (name && snapshot->record_names) diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c index 16897067d0..5ea19b3d7b 100644 --- a/gtk/gtkstylecontext.c +++ b/gtk/gtkstylecontext.c @@ -170,7 +170,11 @@ gtk_style_context_real_changed (GtkStyleContext *context) GtkStyleContextPrivate *priv = gtk_style_context_get_instance_private (context); if (GTK_IS_CSS_WIDGET_NODE (priv->cssnode)) - _gtk_widget_style_context_invalidated (gtk_css_widget_node_get_widget (GTK_CSS_WIDGET_NODE (priv->cssnode))); + { + GtkWidget *widget = gtk_css_widget_node_get_widget (GTK_CSS_WIDGET_NODE (priv->cssnode)); + if (widget != NULL) + _gtk_widget_style_context_invalidated (widget); + } } static void diff --git a/gtk/gtkswitch.c b/gtk/gtkswitch.c index 7189437d11..71121abb57 100644 --- a/gtk/gtkswitch.c +++ b/gtk/gtkswitch.c @@ -334,7 +334,6 @@ gtk_switch_size_allocate (GtkWidget *widget, slider_alloc.height = allocation->height; gtk_widget_size_allocate (priv->slider, &slider_alloc, -1, &child_clip); - gtk_widget_get_clip (priv->slider, &child_clip); gdk_rectangle_union (out_clip, &child_clip, out_clip); diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 8c5b72fefd..9c8b5acb31 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -10685,6 +10685,7 @@ typedef struct GtkBuilder *builder; GSList *actions; GSList *relations; + AtkRole role; } AccessibilitySubParserData; static void @@ -10764,6 +10765,45 @@ accessibility_start_element (GMarkupParseContext *context, data->actions = g_slist_prepend (data->actions, action); } + else if (strcmp (element_name, "role") == 0) + { + const gchar *type; + AtkRole role; + + if (!_gtk_builder_check_parent (data->builder, context, "accessibility", error)) + return; + + if (data->role != ATK_ROLE_INVALID) + { + g_set_error (error, + GTK_BUILDER_ERROR, + GTK_BUILDER_ERROR_INVALID_VALUE, + "Duplicate accessibility role definition"); + _gtk_builder_prefix_error (data->builder, context, error); + return; + } + + if (!g_markup_collect_attributes (element_name, names, values, error, + G_MARKUP_COLLECT_STRING, "type", &type, + G_MARKUP_COLLECT_INVALID)) + { + _gtk_builder_prefix_error (data->builder, context, error); + return; + } + + role = atk_role_for_name (type); + if (role == ATK_ROLE_INVALID) + { + g_set_error (error, + GTK_BUILDER_ERROR, + GTK_BUILDER_ERROR_INVALID_VALUE, + "No such role type: '%s'", type); + _gtk_builder_prefix_error (data->builder, context, error); + return; + } + + data->role = role; + } else if (strcmp (element_name, "accessibility") == 0) { if (!_gtk_builder_check_parent (data->builder, context, "object", error)) @@ -11108,6 +11148,12 @@ gtk_widget_buildable_custom_finished (GtkBuildable *buildable, g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations, a11y_data->relations); + if (a11y_data->role != ATK_ROLE_INVALID) + { + AtkObject *accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable)); + atk_object_set_role (accessible, a11y_data->role); + } + g_slice_free (AccessibilitySubParserData, a11y_data); } else if (strcmp (tagname, "style") == 0) diff --git a/gtk/inspector/object-tree.c b/gtk/inspector/object-tree.c index d4a491de66..5d215eab46 100644 --- a/gtk/inspector/object-tree.c +++ b/gtk/inspector/object-tree.c @@ -125,6 +125,14 @@ object_tree_widget_get_parent (GObject *object) return G_OBJECT (gtk_widget_get_parent (GTK_WIDGET (object))); } +static GObject * +object_tree_menu_get_parent (GObject *object) +{ + GtkWidget *w = gtk_menu_get_attach_widget (GTK_MENU (object)); + + return w ? G_OBJECT (w) : NULL; +} + static gboolean object_tree_widget_get_sensitive (GObject *object) { @@ -441,6 +449,12 @@ static const ObjectTreeClassFuncs object_tree_class_funcs[] = { object_tree_widget_get_sensitive }, { + gtk_menu_get_type, + object_tree_menu_get_parent, + object_tree_widget_forall, + object_tree_widget_get_sensitive + }, + { gtk_widget_get_type, object_tree_widget_get_parent, object_tree_widget_forall, diff --git a/tests/meson.build b/tests/meson.build index a3955d430d..c5b1d0792a 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -128,7 +128,8 @@ gtk_tests = [ ['showrendernode'], ['testborderdrawing'], ['testoutsetshadowdrawing'], - ['testblur'] + ['testblur'], + ['testtexture'], ] if os_linux diff --git a/tests/testtexture.c b/tests/testtexture.c new file mode 100644 index 0000000000..51fd99e56d --- /dev/null +++ b/tests/testtexture.c @@ -0,0 +1,144 @@ +#include <gtk/gtk.h> + + + +typedef struct _GtkTextureView GtkTextureView; +typedef struct _GtkTextureViewClass GtkTextureViewClass; + +#define GTK_TYPE_TEXTURE_VIEW (gtk_texture_view_get_type ()) +#define GTK_TEXTURE_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, GTK_TYPE_TEXTURE_VIEW, GtkTextureView)) +#define GTK_TEXTURE_VIEW_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST(cls, GTK_TYPE_TEXTURE_VIEW, GtkTextureViewClass)) +struct _GtkTextureView +{ + GtkWidget parent_instance; + + GdkTexture *texture; +}; + +struct _GtkTextureViewClass +{ + GtkWidgetClass parent_class; +}; + +GType gtk_texture_view_get_type (void) G_GNUC_CONST; + + +G_DEFINE_TYPE(GtkTextureView, gtk_texture_view, GTK_TYPE_WIDGET) + +static void +gtk_texture_view_measure (GtkWidget *widget, + GtkOrientation orientation, + int for_size, + int *minimum, + int *natural, + int *minimum_baseline, + int *natural_baseline) +{ + GtkTextureView *self = GTK_TEXTURE_VIEW (widget); + + if (self->texture == NULL) + return; + + if (orientation == GTK_ORIENTATION_HORIZONTAL) + { + *minimum = 0; + *natural = gdk_texture_get_width (self->texture); + } + else /* VERTICAL */ + { + *minimum = 0; + *natural = gdk_texture_get_height (self->texture); + } +} + +static void +gtk_texture_view_snapshot (GtkWidget *widget, + GtkSnapshot *snapshot) +{ + GtkTextureView *self = GTK_TEXTURE_VIEW (widget); + int width = gtk_widget_get_width (widget); + int height = gtk_widget_get_height (widget); + + if (self->texture != NULL) + { + graphene_rect_t bounds; + + bounds.origin.x = MAX (0, width / 2 - gdk_texture_get_width (self->texture)); + bounds.origin.y = MAX (0, height / 2 - gdk_texture_get_height (self->texture)); + + bounds.size.width = MIN (width, gdk_texture_get_width (self->texture)); + bounds.size.height = MIN (height, gdk_texture_get_height (self->texture)); + + gtk_snapshot_append_texture (snapshot, self->texture, &bounds, "Texture"); + } +} + +static void +gtk_texture_view_finalize (GObject *object) +{ + GtkTextureView *self = GTK_TEXTURE_VIEW (object); + + g_clear_object (&self->texture); + + G_OBJECT_CLASS (gtk_texture_view_parent_class)->finalize (object); +} + +static void +gtk_texture_view_init (GtkTextureView *self) +{ + gtk_widget_set_has_window (GTK_WIDGET (self), FALSE); +} + +static void +gtk_texture_view_class_init (GtkTextureViewClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + object_class->finalize = gtk_texture_view_finalize; + + widget_class->measure = gtk_texture_view_measure; + widget_class->snapshot = gtk_texture_view_snapshot; +} + +int +main (int argc, char **argv) +{ + GtkWidget *window; + GtkWidget *view; + GdkTexture *texture; + GFile *file; + GError *error = NULL; + + gtk_init (); + + if (argc != 2) + { + g_error ("No texture file path given."); + return -1; + } + + file = g_file_new_for_path (argv[1]); + texture = gdk_texture_new_from_file (file, &error); + + if (error != NULL) + { + g_error ("Error: %s", error->message); + return -1; + } + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); + view = g_object_new (GTK_TYPE_TEXTURE_VIEW, NULL); + ((GtkTextureView*)view)->texture = g_steal_pointer (&texture); + + gtk_container_add (GTK_CONTAINER (window), view); + + gtk_widget_show (window); + gtk_main (); + + + g_object_unref (file); + + return 0; +} diff --git a/testsuite/a11y/label-static.txt b/testsuite/a11y/label-static.txt new file mode 100644 index 0000000000..cfffa4c8ed --- /dev/null +++ b/testsuite/a11y/label-static.txt @@ -0,0 +1,75 @@ +window1 + "window" + index: 0 + state: enabled resizable sensitive showing visible + toolkit: gtk + window-type: normal + <AtkComponent> + layer: window + alpha: 1 + label1 + "static" + parent: window1 + index: 0 + name: Go to the GTK+ website or >google it + state: enabled focusable multi-line sensitive has-tooltip + toolkit: gtk + <AtkComponent> + layer: widget + alpha: 1 + <AtkText> + text: Go to the GTK+ website or >google it + character count: 36 + caret offset: 0 + default attributes: bg-color: <omitted> + bg-full-height: 0 + direction: <omitted> + editable: false + family-name: <omitted> + fg-color: <omitted> + indent: 0 + invisible: false + justification: left + language: <omitted> + left-margin: 0 + pixels-above-lines: 0 + pixels-below-lines: 0 + pixels-inside-wrap: 0 + right-margin: 0 + rise: 0 + scale: 1 + size: <omitted> + stretch: <omitted> + strikethrough: false + style: <omitted> + underline: none + variant: <omitted> + weight: <omitted> + wrap-mode: word + <AtkHypertext> + <AtkHyperlink> + start index: 10 + end index: 22 + anchors: http://www.gtk.org + <AtkHyperlink> + start index: 27 + end index: 36 + anchors: http://www.google.com + unnamed-GtkLabelAccessibleLinkImpl-0 + "link" + parent: label1 + state: enabled focusable multi-line sensitive has-tooltip + <AtkHyperlinkImpl> + <AtkHyperlink> + start index: 10 + end index: 22 + anchors: http://www.gtk.org + unnamed-GtkLabelAccessibleLinkImpl-1 + "link" + parent: label1 + state: enabled focusable multi-line sensitive has-tooltip + <AtkHyperlinkImpl> + <AtkHyperlink> + start index: 27 + end index: 36 + anchors: http://www.google.com diff --git a/testsuite/a11y/label-static.ui b/testsuite/a11y/label-static.ui new file mode 100644 index 0000000000..1e478c0b63 --- /dev/null +++ b/testsuite/a11y/label-static.ui @@ -0,0 +1,17 @@ + +<interface> + <!-- interface-requires gtk+ 3.0 --> + <object class="GtkWindow" id="window1"> + <property name="can_focus">False</property> + <property name="type">popup</property> + <child> + <object class="GtkLabel" id="label1"> + <property name="label">Go to the <a href="http://www.gtk.org" title="<i>Our</i> website">GTK+ website</a> or <small>><a href="http://www.google.com">google it</a></small></property> + <property name="use-markup">True</property> + <accessibility> + <role type="static"/> + </accessibility> + </object> + </child> + </object> +</interface> diff --git a/testsuite/gtk/builder.c b/testsuite/gtk/builder.c index 9d5fb822f3..e662570a26 100644 --- a/testsuite/gtk/builder.c +++ b/testsuite/gtk/builder.c @@ -1520,6 +1520,20 @@ test_widget (void) " </child>" " </object>" "</interface>"; + const gchar *buffer4 = + "<interface>" + " <object class=\"GtkWindow\" id=\"window1\">" + " <child>" + " <object class=\"GtkLabel\" id=\"label1\">" + " <property name=\"label\">Thelabel</property>" + " <property name=\"can_focus\">False</property>" + " <accessibility>" + " <role type=\"static\"/>" + " </accessibility>" + " </object>" + " </child>" + " </object>" + "</interface>"; GtkBuilder *builder; GObject *window1, *button1, *label1; AtkObject *accessible; @@ -1565,6 +1579,14 @@ test_widget (void) gtk_widget_destroy (GTK_WIDGET (window1)); g_object_unref (builder); + + builder = builder_new_from_string (buffer4, -1, NULL); + label1 = gtk_builder_get_object (builder, "label1"); + + accessible = gtk_widget_get_accessible (GTK_WIDGET (label1)); + g_assert (atk_object_get_role (accessible) == ATK_ROLE_STATIC); + + g_object_unref (builder); } static void |