Wed, 21 Dec 2005 18:43:39 +0000
[gaim-migrate @ 14935]
Jason LeBrun wrote to gaim-devel:
"I have found a small quirk in the way gdk_pixbuf_loader works. When you
are using it without signalling, the proper way to use it is to call
gdk_pixbuf_loader_close *before* calling gdk_pixbuf_loader_get_animation
or gdk_pixbuf_loader_get_pixbuf. The call to gdk_pixbuf_loader_close
signals that no more writes will be occuring.
In particular, this affects images that are less than 1k in size. If
gdk_pixbuf_loader_close is not called before _get_animation, the loader
will not return anything unless it has received more than 1k of data
(the file type sniffing buffer size) or it has been closed.
So, the proper order of calls for loaders in the gtk*.c code is:
gdk_pixbuf_loader_new();
gdk_pixbuf_loader_write();
gdk_pixbuf_loader_close();
gdk_pixbuf_loader_get_animation();"
I know we fixed a bug by changing this in one place. I've gone through and updated the rest.
| 10708 | 1 | /* gtkcelllayout.c |
| 2 | * Copyright (C) 2003 Kristian Rietveld <kris@gtk.org> | |
| 3 | * | |
| 4 | * This library is free software; you can redistribute it and/or | |
| 5 | * modify it under the terms of the GNU Library General Public | |
| 6 | * License as published by the Free Software Foundation; either | |
| 7 | * version 2 of the License, or (at your option) any later version. | |
| 8 | * | |
| 9 | * This library is distributed in the hope that it will be useful, | |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 12 | * Library General Public License for more details. | |
| 13 | * | |
| 14 | * You should have received a copy of the GNU Library General Public | |
| 15 | * License along with this library; if not, write to the | |
| 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
| 17 | * Boston, MA 02111-1307, USA. | |
| 18 | */ | |
| 19 | ||
| 20 | /* | |
| 21 | #include <config.h> | |
| 22 | */ | |
| 23 | #include <gtk/gtkversion.h> | |
| 24 | #if !GTK_CHECK_VERSION(2,4,0) | |
| 25 | #include "gtkcelllayout.h" | |
| 26 | ||
| 27 | GType | |
| 28 | gtk_cell_layout_get_type (void) | |
| 29 | { | |
| 30 | static GType cell_layout_type = 0; | |
| 31 | ||
| 32 | if (! cell_layout_type) | |
| 33 | { | |
| 34 | static const GTypeInfo cell_layout_info = | |
| 35 | { | |
| 36 | sizeof (GtkCellLayoutIface), | |
| 37 | NULL, | |
| 38 | NULL, | |
| 39 | NULL, | |
| 40 | NULL, | |
| 41 | NULL, | |
| 42 | 0, | |
| 43 | 0, | |
| 44 | NULL | |
| 45 | }; | |
| 46 | ||
| 47 | cell_layout_type = | |
| 48 | g_type_register_static (G_TYPE_INTERFACE, "GaimGtkCellLayout", | |
| 49 | &cell_layout_info, 0); | |
| 50 | ||
| 51 | g_type_interface_add_prerequisite (cell_layout_type, G_TYPE_OBJECT); | |
| 52 | } | |
| 53 | ||
| 54 | return cell_layout_type; | |
| 55 | } | |
| 56 | ||
| 57 | /** | |
| 58 | * gtk_cell_layout_pack_start: | |
| 59 | * @cell_layout: A #GtkCellLayout. | |
| 60 | * @cell: A #GtkCellRenderer. | |
| 61 | * @expand: %TRUE if @cell is to be given extra space allocated to @cell_layout. | |
| 62 | * | |
| 63 | * Packs the @cell into the beginning of @cell_layout. If @expand is %FALSE, | |
| 64 | * then the @cell is allocated no more space than it needs. Any unused space | |
| 65 | * is divided evenly between cells for which @expand is %TRUE. | |
| 66 | * | |
| 67 | * Since: 2.4 | |
| 68 | */ | |
| 69 | void | |
| 70 | gtk_cell_layout_pack_start (GtkCellLayout *cell_layout, | |
| 71 | GtkCellRenderer *cell, | |
| 72 | gboolean expand) | |
| 73 | { | |
| 74 | g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout)); | |
| 75 | g_return_if_fail (GTK_IS_CELL_RENDERER (cell)); | |
| 76 | ||
| 77 | (* GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->pack_start) (cell_layout, | |
| 78 | cell, | |
| 79 | expand); | |
| 80 | } | |
| 81 | ||
| 82 | /** | |
| 83 | * gtk_cell_layout_pack_end: | |
| 84 | * @cell_layout: A #GtkCellLayout. | |
| 85 | * @cell: A #GtkCellRenderer. | |
| 86 | * @expand: %TRUE if @cell is to be given extra space allocated to @cell_layout. | |
| 87 | * | |
| 88 | * Adds the @cell to the end of @cell_layout. If @expand is %FALSE, then the | |
| 89 | * @cell is allocated no more space than it needs. Any unused space is | |
| 90 | * divided evenly between cells for which @expand is %TRUE. | |
| 91 | * | |
| 92 | * Since: 2.4 | |
| 93 | */ | |
| 94 | void | |
| 95 | gtk_cell_layout_pack_end (GtkCellLayout *cell_layout, | |
| 96 | GtkCellRenderer *cell, | |
| 97 | gboolean expand) | |
| 98 | { | |
| 99 | g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout)); | |
| 100 | g_return_if_fail (GTK_IS_CELL_RENDERER (cell)); | |
| 101 | ||
| 102 | (* GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->pack_end) (cell_layout, | |
| 103 | cell, | |
| 104 | expand); | |
| 105 | } | |
| 106 | ||
| 107 | /** | |
| 108 | * gtk_cell_layout_clear: | |
| 109 | * @cell_layout: A #GtkCellLayout. | |
| 110 | * | |
| 111 | * Unsets all the mappings on all renderers on @cell_layout and | |
| 112 | * removes all renderers from @cell_layout. | |
| 113 | * | |
| 114 | * Since: 2.4 | |
| 115 | */ | |
| 116 | void | |
| 117 | gtk_cell_layout_clear (GtkCellLayout *cell_layout) | |
| 118 | { | |
| 119 | g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout)); | |
| 120 | ||
| 121 | (* GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->clear) (cell_layout); | |
| 122 | } | |
| 123 | ||
| 124 | static void | |
| 125 | gtk_cell_layout_set_attributesv (GtkCellLayout *cell_layout, | |
| 126 | GtkCellRenderer *cell, | |
| 127 | va_list args) | |
| 128 | { | |
| 129 | gchar *attribute; | |
| 130 | gint column; | |
| 131 | GtkCellLayoutIface *iface; | |
| 132 | ||
| 133 | attribute = va_arg (args, gchar *); | |
| 134 | ||
| 135 | iface = GTK_CELL_LAYOUT_GET_IFACE (cell_layout); | |
| 136 | ||
| 137 | (* iface->clear_attributes) (cell_layout, cell); | |
| 138 | ||
| 139 | while (attribute != NULL) | |
| 140 | { | |
| 141 | column = va_arg (args, gint); | |
| 142 | (* iface->add_attribute) (cell_layout, cell, attribute, column); | |
| 143 | attribute = va_arg (args, gchar *); | |
| 144 | } | |
| 145 | } | |
| 146 | ||
| 147 | /** | |
| 148 | * gtk_cell_layout_set_attributes: | |
| 149 | * @cell_layout: A #GtkCellLayout. | |
| 150 | * @cell: A #GtkCellRenderer. | |
| 151 | * @Varargs: A %NULL-terminated list of attributes. | |
| 152 | * | |
| 153 | * Sets the attributes in list as the attributes of @cell_layout. The | |
| 154 | * attributes should be in attribute/column order, as in | |
| 155 | * gtk_cell_layout_add_attribute(). All existing attributes are removed, and | |
| 156 | * replaced with the new attributes. | |
| 157 | * | |
| 158 | * Since: 2.4 | |
| 159 | */ | |
| 160 | void | |
| 161 | gtk_cell_layout_set_attributes (GtkCellLayout *cell_layout, | |
| 162 | GtkCellRenderer *cell, | |
| 163 | ...) | |
| 164 | { | |
| 165 | va_list args; | |
| 166 | ||
| 167 | g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout)); | |
| 168 | g_return_if_fail (GTK_IS_CELL_RENDERER (cell)); | |
| 169 | ||
| 170 | va_start (args, cell); | |
| 171 | gtk_cell_layout_set_attributesv (cell_layout, cell, args); | |
| 172 | va_end (args); | |
| 173 | } | |
| 174 | ||
| 175 | /** | |
| 176 | * gtk_cell_layout_add_attribute: | |
| 177 | * @cell_layout: A #GtkCellLayout. | |
| 178 | * @cell: A #GtkCellRenderer. | |
| 179 | * @attribute: An attribute on the renderer. | |
| 180 | * @column: The column position on the model to get the attribute from. | |
| 181 | * | |
| 182 | * Adds an attribute mapping to the list in @cell_layout. The @column is the | |
| 183 | * column of the model to get a value from, and the @attribute is the | |
| 184 | * parameter on @cell to be set from the value. So for example if column 2 | |
| 185 | * of the model contains strings, you could have the "text" attribute of a | |
| 186 | * #GtkCellRendererText get its values from column 2. | |
| 187 | * | |
| 188 | * Since: 2.4 | |
| 189 | */ | |
| 190 | void | |
| 191 | gtk_cell_layout_add_attribute (GtkCellLayout *cell_layout, | |
| 192 | GtkCellRenderer *cell, | |
| 193 | const gchar *attribute, | |
| 194 | gint column) | |
| 195 | { | |
| 196 | g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout)); | |
| 197 | g_return_if_fail (GTK_IS_CELL_RENDERER (cell)); | |
| 198 | g_return_if_fail (attribute != NULL); | |
| 199 | g_return_if_fail (column >= 0); | |
| 200 | ||
| 201 | (* GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->add_attribute) (cell_layout, | |
| 202 | cell, | |
| 203 | attribute, | |
| 204 | column); | |
| 205 | } | |
| 206 | ||
| 207 | /** | |
| 208 | * gtk_cell_layout_set_cell_data_func: | |
| 209 | * @cell_layout: A #GtkCellLayout. | |
| 210 | * @cell: A #GtkCellRenderer. | |
| 211 | * @func: The #GtkCellLayoutDataFunc to use. | |
| 212 | * @func_data: The user data for @func. | |
| 213 | * @destroy: The destroy notification for @func_data. | |
| 214 | * | |
| 215 | * Sets the #GtkCellLayoutDataFunc to use for @cell_layout. This function | |
| 216 | * is used instead of the standard attributes mapping for setting the | |
| 217 | * column value, and should set the value of @cell_layout's cell renderer(s) | |
| 218 | * as appropriate. @func may be %NULL to remove and older one. | |
| 219 | * | |
| 220 | * Since: 2.4 | |
| 221 | */ | |
| 222 | void | |
| 223 | gtk_cell_layout_set_cell_data_func (GtkCellLayout *cell_layout, | |
| 224 | GtkCellRenderer *cell, | |
| 225 | GtkCellLayoutDataFunc func, | |
| 226 | gpointer func_data, | |
| 227 | GDestroyNotify destroy) | |
| 228 | { | |
| 229 | g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout)); | |
| 230 | g_return_if_fail (GTK_IS_CELL_RENDERER (cell)); | |
| 231 | ||
| 232 | (* GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->set_cell_data_func) (cell_layout, | |
| 233 | cell, | |
| 234 | func, | |
| 235 | func_data, | |
| 236 | destroy); | |
| 237 | } | |
| 238 | ||
| 239 | /** | |
| 240 | * gtk_cell_layout_clear_attributes: | |
| 241 | * @cell_layout: A #GtkCellLayout. | |
| 242 | * @cell: A #GtkCellRenderer to clear the attribute mapping on. | |
| 243 | * | |
| 244 | * Clears all existing attributes previously set with | |
| 245 | * gtk_cell_layout_set_attributes(). | |
| 246 | * | |
| 247 | * Since: 2.4 | |
| 248 | */ | |
| 249 | void | |
| 250 | gtk_cell_layout_clear_attributes (GtkCellLayout *cell_layout, | |
| 251 | GtkCellRenderer *cell) | |
| 252 | { | |
| 253 | g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout)); | |
| 254 | g_return_if_fail (GTK_IS_CELL_RENDERER (cell)); | |
| 255 | ||
| 256 | (* GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->clear_attributes) (cell_layout, | |
| 257 | cell); | |
| 258 | } | |
| 259 | ||
| 260 | /** | |
| 261 | * gtk_cell_layout_reorder: | |
| 262 | * @cell_layout: A #GtkCellLayout. | |
| 263 | * @cell: A #GtkCellRenderer to reorder. | |
| 264 | * @position: New position to insert @cell at. | |
| 265 | * | |
| 266 | * Re-inserts @cell at @position. Note that @cell has already to be packed | |
| 267 | * into @cell_layout for this to function properly. | |
| 268 | * | |
| 269 | * Since: 2.4 | |
| 270 | */ | |
| 271 | void | |
| 272 | gtk_cell_layout_reorder (GtkCellLayout *cell_layout, | |
| 273 | GtkCellRenderer *cell, | |
| 274 | gint position) | |
| 275 | { | |
| 276 | g_return_if_fail (GTK_IS_CELL_LAYOUT (cell_layout)); | |
| 277 | g_return_if_fail (GTK_IS_CELL_RENDERER (cell)); | |
| 278 | ||
| 279 | (* GTK_CELL_LAYOUT_GET_IFACE (cell_layout)->reorder) (cell_layout, | |
| 280 | cell, | |
| 281 | position); | |
| 282 | } | |
| 283 | #endif /* Gtk 2.4 */ |