From fde4fecfd2064bdf4f52a02e90e76b6e67d3e3c8 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Sun, 17 Dec 2000 23:50:00 +0000 Subject: Port to GObject, can go back in gdk-pixbuf after setting up a 2000-12-16 Havoc Pennington * gtk/gdk-pixbuf-loader.h, gtk/gdk-pixbuf-loader.c: Port to GObject, can go back in gdk-pixbuf after setting up a gdk-pixbuf-marshal.h header over there. * gtk/gtktreeview.c: s/SEPERATOR/SEPARATOR/g; (gtk_tree_view_class_init): specify GTK_TYPE_ADJUSTMENT for signal args (gtk_tree_view_init): don't unset GTK_NO_WINDOW, it shouldn't be set (gtk_tree_view_realize_buttons): don't gtk_widget_show() buttons here, do it when we create the buttons later (gtk_tree_view_realize_buttons): add some g_return_if_fail (gtk_tree_view_map): paranoia checks that column->button is shown and unmapped (gtk_tree_view_size_request): only request visible children. Move header size calculation in here, for cleanliness, and to maintain invariants for child widgets if we eventually let users set different children inside the buttons (gtk_tree_view_map_buttons): factor out code to map buttons, since it was being called several times (gtk_tree_view_size_allocate_buttons): move_resize the drag windows instead of just moving them; their height may change if we allow random widgets in there, or the theme changes. (gtk_tree_view_size_allocate): move button size allocation above emitting the scroll signals, to ensure a sane state when we hit user code (gtk_tree_view_button_release): remove queue_resize after tree_view_set_size(), set_size() will handle any resize queuing that's needed (gtk_tree_view_focus_in): just queue a draw, don't fool with draw_focus goo (gtk_tree_view_focus): use gtk_get_current_event() and gdk_event_get_state() (gtk_tree_view_deleted): don't queue_resize() after calling set_size() (gtk_tree_view_build_tree): fix a "if (foo); {}" bug - i.e. remove semicolon (gtk_tree_view_create_button): show the button here (gtk_tree_view_button_clicked): actually emit the clicked signal on the column (_gtk_tree_view_set_size): return right away if the size is unchanged, as a cheesy optimization (gtk_tree_view_setup_model): rename set_model_realized to setup_model to match the flag that indicates whether we've called it (gtk_tree_view_get_hadjustment): create adjustment if it doesn't exist, because set_scroll_adjustment does that and it shouldn't matter what order you call these in (gtk_tree_view_get_vadjustment): ditto (gtk_tree_view_set_headers_visible): canonicalize the bool, for paranoia (gtk_tree_view_set_headers_visible): call gtk_tree_view_map_buttons() instead of using cut-and-paste code (gtk_tree_view_append_column): clarify whether the return value is the count of columns before or after, and do the increment separately from the return statement so you can tell from the code. (gtk_tree_view_remove_column): ditto (gtk_tree_view_insert_column): ditto (gtk_tree_view_get_column): remove g_return_if_fail for columns outside the existing range, the docs say that outside-range columns are allowed, so we handle them as documented. (Presumably this allows a nice loop with column != NULL as test.) (gtk_tree_view_move_to): document what 0.0, 0.5, 1.0 alignments mean (left/right/center etc.). (gtk_tree_view_collapse_all): only queue a draw if we're mapped (gtk_tree_view_expand_row): add docs (gtk_tree_view_collapse_row): add docs * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_clicked): new function to emit the clicked signal on a column * gdk/gdkevents.c (gdk_event_get_state): new function, to get the state of an event (gdk_event_get_time): don't treat GDK_SCROLL as a button event, remove default case from switch so gcc will whine if we don't explicitly handle all event types * gtk/gtktreeselection.h: added some FIXME * gtk/gtktreeprivate.h (struct _GtkTreeViewPrivate): rename "columns" to "n_columns" and "column" to "columns" for clarity --- gdk-pixbuf/ChangeLog | 9 +++ gdk-pixbuf/gdk-pixbuf-animation.c | 58 +++++++++++++ gdk-pixbuf/gdk-pixbuf-loader.c | 166 ++++++++++++++++++-------------------- gdk-pixbuf/gdk-pixbuf-loader.h | 21 +++-- gdk-pixbuf/gdk-pixbuf.h | 4 + 5 files changed, 159 insertions(+), 99 deletions(-) (limited to 'gdk-pixbuf') diff --git a/gdk-pixbuf/ChangeLog b/gdk-pixbuf/ChangeLog index 750c1a04c..623274409 100644 --- a/gdk-pixbuf/ChangeLog +++ b/gdk-pixbuf/ChangeLog @@ -1,3 +1,12 @@ +2000-12-16 Havoc Pennington + + * gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file): ref + the pixbuf in the frame, so we can use gdk_pixbuf_frame_free + (gdk_pixbuf_frame_copy): new function + (gdk_pixbuf_frame_free): new function + (gdk_pixbuf_frame_get_type): new function + (GDK_TYPE_PIXBUF_FRAME): macro to get type for GdkPixbufFrame + Tue Nov 14 11:51:26 2000 Owen Taylor * Makefile.am: Add -avoid-version for all modules. diff --git a/gdk-pixbuf/gdk-pixbuf-animation.c b/gdk-pixbuf/gdk-pixbuf-animation.c index 9d221d5c3..d0f7768f2 100644 --- a/gdk-pixbuf/gdk-pixbuf-animation.c +++ b/gdk-pixbuf/gdk-pixbuf-animation.c @@ -193,6 +193,7 @@ gdk_pixbuf_animation_new_from_file (const char *filename, frame = g_new (GdkPixbufFrame, 1); frame->pixbuf = pixbuf; + g_object_ref (G_OBJECT (frame->pixbuf)); frame->x_offset = 0; frame->y_offset = 0; frame->delay_time = -1; @@ -406,3 +407,60 @@ gdk_pixbuf_frame_get_action (GdkPixbufFrame *frame) return frame->action; } + +/** + * gdk_pixbuf_frame_copy: + * @src: a #GdkPixbufFrame to copy + * + * Copies a #GdkPixbufFrame. Free the result + * with gdk_pixbuf_frame_free(). + * + * Return value: a new #GdkPixbufFrame + **/ +GdkPixbufFrame* +gdk_pixbuf_frame_copy (GdkPixbufFrame *src) +{ + GdkPixbufFrame *frame; + + frame = g_new (GdkPixbufFrame, 1); + frame->pixbuf = src->pixbuf; + g_object_ref (G_OBJECT (frame->pixbuf)); + frame->x_offset = src->x_offset; + frame->y_offset = src->y_offset; + frame->delay_time = src->delay_time; + frame->action = src->action; + + return frame; +} + +/** + * gdk_pixbuf_frame_free: + * @frame: a #GdkPixbufFrame + * + * Frees a #GdkPixbufFrame. Don't do this with frames you got from + * #GdkPixbufAnimation, usually the animation owns those (it doesn't + * make a copy before returning the frame). + **/ +void +gdk_pixbuf_frame_free (GdkPixbufFrame *frame) +{ + g_return_if_fail (frame != NULL); + + g_object_unref (G_OBJECT (frame->pixbuf)); + g_free (frame); +} + +GType +gdk_pixbuf_frame_get_type (void) +{ + static GType our_type = 0; + + if (our_type == 0) + { + our_type = g_boxed_type_register_static ("GdkPixbufFrame", + gdk_pixbuf_frame_copy, + gdk_pixbuf_frame_free); + } + + return our_type; +} diff --git a/gdk-pixbuf/gdk-pixbuf-loader.c b/gdk-pixbuf/gdk-pixbuf-loader.c index 06f2e1df3..34cb3899a 100644 --- a/gdk-pixbuf/gdk-pixbuf-loader.c +++ b/gdk-pixbuf/gdk-pixbuf-loader.c @@ -1,4 +1,4 @@ -/* GdkPixbuf library - Main header file +/* GdkPixbuf library - Progressive loader object * * Copyright (C) 1999 The Free Software Foundation * @@ -43,7 +43,6 @@ enum { static void gdk_pixbuf_loader_class_init (GdkPixbufLoaderClass *klass); static void gdk_pixbuf_loader_init (GdkPixbufLoader *loader); -static void gdk_pixbuf_loader_destroy (GtkObject *loader); static void gdk_pixbuf_loader_finalize (GObject *loader); static gpointer parent_class = NULL; @@ -75,25 +74,29 @@ typedef struct * * Return value: The type ID of the #GdkPixbufLoader class. **/ -GtkType +GType gdk_pixbuf_loader_get_type (void) { - static GtkType loader_type = 0; + static GType loader_type = 0; if (!loader_type) { - static const GtkTypeInfo loader_info = { - "GdkPixbufLoader", - sizeof (GdkPixbufLoader), - sizeof (GdkPixbufLoaderClass), - (GtkClassInitFunc) gdk_pixbuf_loader_class_init, - (GtkObjectInitFunc) gdk_pixbuf_loader_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, + static const GTypeInfo loader_info = { + sizeof (GdkPixbufLoaderClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) gdk_pixbuf_loader_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (GdkPixbufLoader), + 0, /* n_preallocs */ + (GInstanceInitFunc) gdk_pixbuf_loader_init }; - loader_type = gtk_type_unique (GTK_TYPE_OBJECT, &loader_info); + loader_type = g_type_register_static (G_TYPE_OBJECT, + "GdkPixbufLoader", + &loader_info, + 0); } return loader_type; @@ -102,61 +105,63 @@ gdk_pixbuf_loader_get_type (void) static void gdk_pixbuf_loader_class_init (GdkPixbufLoaderClass *class) { - GObjectClass *gobject_class; - GtkObjectClass *object_class; + GObjectClass *object_class; - object_class = (GtkObjectClass *) class; - gobject_class = (GObjectClass *) class; + object_class = (GObjectClass *) class; - parent_class = gtk_type_class (GTK_TYPE_OBJECT); + parent_class = g_type_class_peek_parent (class); - object_class->destroy = gdk_pixbuf_loader_destroy; - gobject_class->finalize = gdk_pixbuf_loader_finalize; + object_class->finalize = gdk_pixbuf_loader_finalize; pixbuf_loader_signals[AREA_PREPARED] = - gtk_signal_new ("area_prepared", - GTK_RUN_LAST, - GTK_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (GdkPixbufLoaderClass, area_prepared), - gtk_marshal_VOID__VOID, - GTK_TYPE_NONE, 0); + g_signal_newc ("area_prepared", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GdkPixbufLoaderClass, area_prepared), + NULL, + gtk_marshal_VOID__VOID, + G_TYPE_NONE, 0); pixbuf_loader_signals[AREA_UPDATED] = - gtk_signal_new ("area_updated", - GTK_RUN_LAST, - GTK_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (GdkPixbufLoaderClass, area_updated), - gtk_marshal_VOID__INT_INT_INT_INT, - GTK_TYPE_NONE, 4, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_INT); + g_signal_newc ("area_updated", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GdkPixbufLoaderClass, area_updated), + NULL, + gtk_marshal_VOID__INT_INT_INT_INT, + G_TYPE_NONE, 4, + G_TYPE_INT, + G_TYPE_INT, + G_TYPE_INT, + G_TYPE_INT); pixbuf_loader_signals[FRAME_DONE] = - gtk_signal_new ("frame_done", - GTK_RUN_LAST, - GTK_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (GdkPixbufLoaderClass, frame_done), - gtk_marshal_VOID__POINTER, - GTK_TYPE_NONE, 1, - GTK_TYPE_POINTER); + g_signal_newc ("frame_done", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GdkPixbufLoaderClass, frame_done), + NULL, + gtk_marshal_VOID__POINTER, + G_TYPE_NONE, 1, + GDK_TYPE_PIXBUF_FRAME); pixbuf_loader_signals[ANIMATION_DONE] = - gtk_signal_new ("animation_done", - GTK_RUN_LAST, - GTK_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (GdkPixbufLoaderClass, animation_done), - gtk_marshal_VOID__VOID, - GTK_TYPE_NONE, 0); + g_signal_newc ("animation_done", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GdkPixbufLoaderClass, animation_done), + NULL, + gtk_marshal_VOID__VOID, + G_TYPE_NONE, 0); pixbuf_loader_signals[CLOSED] = - gtk_signal_new ("closed", - GTK_RUN_LAST, - GTK_CLASS_TYPE (object_class), - GTK_SIGNAL_OFFSET (GdkPixbufLoaderClass, closed), - gtk_marshal_VOID__VOID, - GTK_TYPE_NONE, 0); + g_signal_newc ("closed", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GdkPixbufLoaderClass, closed), + NULL, + gtk_marshal_VOID__VOID, + G_TYPE_NONE, 0); } static void @@ -169,38 +174,23 @@ gdk_pixbuf_loader_init (GdkPixbufLoader *loader) } static void -gdk_pixbuf_loader_destroy (GtkObject *object) +gdk_pixbuf_loader_finalize (GObject *object) { GdkPixbufLoader *loader; GdkPixbufLoaderPrivate *priv = NULL; - g_return_if_fail (object != NULL); - g_return_if_fail (GDK_IS_PIXBUF_LOADER (object)); - loader = GDK_PIXBUF_LOADER (object); priv = loader->private; - + if (!priv->closed) gdk_pixbuf_loader_close (loader); if (priv->animation) gdk_pixbuf_animation_unref (priv->animation); + if (priv->pixbuf) gdk_pixbuf_unref (priv->pixbuf); - if (GTK_OBJECT_CLASS (parent_class)->destroy) - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} - -static void -gdk_pixbuf_loader_finalize (GObject *object) -{ - GdkPixbufLoader *loader; - GdkPixbufLoaderPrivate *priv = NULL; - - loader = GDK_PIXBUF_LOADER (object); - priv = loader->private; - g_free (priv); if (G_OBJECT_CLASS (parent_class)->finalize) @@ -219,7 +209,7 @@ gdk_pixbuf_loader_prepare (GdkPixbuf *pixbuf, g_assert (priv->pixbuf == NULL); priv->pixbuf = pixbuf; - gtk_signal_emit (GTK_OBJECT (loader), pixbuf_loader_signals[AREA_PREPARED]); + g_signal_emit (G_OBJECT (loader), pixbuf_loader_signals[AREA_PREPARED], 0); } static void @@ -234,12 +224,13 @@ gdk_pixbuf_loader_update (GdkPixbuf *pixbuf, priv = GDK_PIXBUF_LOADER (loader)->private; - gtk_signal_emit (GTK_OBJECT (loader), - pixbuf_loader_signals[AREA_UPDATED], - x, y, - /* sanity check in here. Defend against an errant loader */ - MIN (width, gdk_pixbuf_get_width (priv->pixbuf)), - MIN (height, gdk_pixbuf_get_height (priv->pixbuf))); + g_signal_emit (G_OBJECT (loader), + pixbuf_loader_signals[AREA_UPDATED], + 0, + x, y, + /* sanity check in here. Defend against an errant loader */ + MIN (width, gdk_pixbuf_get_width (priv->pixbuf)), + MIN (height, gdk_pixbuf_get_height (priv->pixbuf))); } static void @@ -278,9 +269,10 @@ gdk_pixbuf_loader_frame_done (GdkPixbufFrame *frame, priv->animation->frames = g_list_append (priv->animation->frames, frame); priv->animation->n_frames++; - gtk_signal_emit (GTK_OBJECT (loader), - pixbuf_loader_signals[FRAME_DONE], - frame); + g_signal_emit (GTK_OBJECT (loader), + pixbuf_loader_signals[FRAME_DONE], + 0, + frame); } static void @@ -312,7 +304,7 @@ gdk_pixbuf_loader_animation_done (GdkPixbuf *pixbuf, current = current->next; } - gtk_signal_emit (GTK_OBJECT (loader), pixbuf_loader_signals[ANIMATION_DONE]); + g_signal_emit (G_OBJECT (loader), pixbuf_loader_signals[ANIMATION_DONE], 0); } static gint @@ -605,7 +597,7 @@ gdk_pixbuf_loader_get_animation (GdkPixbufLoader *loader) * gdk_pixbuf_loader_close: * @loader: A pixbuf loader. * - * Informs a pixbuf loader that no further writes with gdk_pixbuf_load_write() + * Informs a pixbuf loader that no further writes with gdk_pixbuf_loader_write() * will occur, so that it can free its internal loading structures. **/ void @@ -630,5 +622,5 @@ gdk_pixbuf_loader_close (GdkPixbufLoader *loader) priv->closed = TRUE; - gtk_signal_emit (GTK_OBJECT (loader), pixbuf_loader_signals[CLOSED]); + g_signal_emit (G_OBJECT (loader), pixbuf_loader_signals[CLOSED], 0); } diff --git a/gdk-pixbuf/gdk-pixbuf-loader.h b/gdk-pixbuf/gdk-pixbuf-loader.h index 402b69725..01532ad78 100644 --- a/gdk-pixbuf/gdk-pixbuf-loader.h +++ b/gdk-pixbuf/gdk-pixbuf-loader.h @@ -1,4 +1,4 @@ -/* GdkPixbuf library - Main header file +/* GdkPixbuf library - Progressive loader object * * Copyright (C) 1999 The Free Software Foundation * @@ -26,27 +26,24 @@ #ifndef GDK_PIXBUF_LOADER_H #define GDK_PIXBUF_LOADER_H -#include #include #ifdef __cplusplus extern "C" { #endif - - #define GDK_TYPE_PIXBUF_LOADER (gdk_pixbuf_loader_get_type ()) -#define GDK_PIXBUF_LOADER(obj) (GTK_CHECK_CAST ((obj), GDK_TYPE_PIXBUF_LOADER, GdkPixbufLoader)) -#define GDK_PIXBUF_LOADER_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GDK_TYPE_PIXBUF_LOADER, GdkPixbufLoaderClass)) -#define GDK_IS_PIXBUF_LOADER(obj) (GTK_CHECK_TYPE ((obj), GDK_TYPE_PIXBUF_LOADER)) -#define GDK_IS_PIXBUF_LOADER_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GDK_TYPE_PIXBUF_LOADER)) -#define GDK_PIXBUF_LOADER_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), GDK_TYPE_PIXBUF_LOADER, GdkPixbufLoaderClass)) +#define GDK_PIXBUF_LOADER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDK_TYPE_PIXBUF_LOADER, GdkPixbufLoader)) +#define GDK_PIXBUF_LOADER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_PIXBUF_LOADER, GdkPixbufLoaderClass)) +#define GDK_IS_PIXBUF_LOADER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GDK_TYPE_PIXBUF_LOADER)) +#define GDK_IS_PIXBUF_LOADER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_PIXBUF_LOADER)) +#define GDK_PIXBUF_LOADER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_PIXBUF_LOADER, GdkPixbufLoaderClass)) typedef struct _GdkPixbufLoader GdkPixbufLoader; struct _GdkPixbufLoader { - GtkObject object; + GObject parent_instance; /*< private >*/ gpointer private; @@ -55,7 +52,7 @@ struct _GdkPixbufLoader typedef struct _GdkPixbufLoaderClass GdkPixbufLoaderClass; struct _GdkPixbufLoaderClass { - GtkObjectClass parent_class; + GObjectClass parent_class; void (*area_prepared) (GdkPixbufLoader *loader); void (*area_updated) (GdkPixbufLoader *loader, @@ -70,7 +67,7 @@ struct _GdkPixbufLoaderClass }; -GtkType gdk_pixbuf_loader_get_type (void) G_GNUC_CONST; +GType gdk_pixbuf_loader_get_type (void) G_GNUC_CONST; GdkPixbufLoader * gdk_pixbuf_loader_new (void); GdkPixbufLoader * gdk_pixbuf_loader_new_with_type (const char *image_type, GError **error); diff --git a/gdk-pixbuf/gdk-pixbuf.h b/gdk-pixbuf/gdk-pixbuf.h index ee87b82bb..f089dcf90 100644 --- a/gdk-pixbuf/gdk-pixbuf.h +++ b/gdk-pixbuf/gdk-pixbuf.h @@ -279,6 +279,10 @@ int gdk_pixbuf_frame_get_x_offset (GdkPixbufFrame *frame); int gdk_pixbuf_frame_get_y_offset (GdkPixbufFrame *frame); int gdk_pixbuf_frame_get_delay_time (GdkPixbufFrame *frame); GdkPixbufFrameAction gdk_pixbuf_frame_get_action (GdkPixbufFrame *frame); +GdkPixbufFrame *gdk_pixbuf_frame_copy (GdkPixbufFrame *frame); +void gdk_pixbuf_frame_free (GdkPixbufFrame *frame); +GType gdk_pixbuf_frame_get_type (void) G_GNUC_CONST; +#define GDK_TYPE_PIXBUF_FRAME gdk_pixbuf_frame_get_type () /* General (presently empty) initialization hooks, primarily for gnome-libs */ -- cgit v1.2.1