diff options
author | Jonathan Blandford <jrb@redhat.com> | 2004-02-27 23:51:16 +0000 |
---|---|---|
committer | Jonathan Blandford <jrb@src.gnome.org> | 2004-02-27 23:51:16 +0000 |
commit | 0cfdc7fb2bb48f38f30882de53ff2afb3093a34c (patch) | |
tree | 4263a91c66c0d7d6278cab75754a186149865644 | |
parent | c5fe469c82b6b79ee466bb0aa438e64e5cee59b6 (diff) | |
download | gtk+-0cfdc7fb2bb48f38f30882de53ff2afb3093a34c.tar.gz |
New private interface to help negotiate the default size of the widget.
Fri Feb 27 18:46:27 2004 Jonathan Blandford <jrb@redhat.com>
* gtk/gtkfilechooserembed.h: New private interface to help
negotiate the default size of the widget. Still a bit buggy, but
better than the old behavior.
* gtk/gtkfilechooserdefault.c: Implement the embed interface.
* gtk/gtkfilechooserwidget.c: Proxy the embed interface.
* gtk/gtkfilechooserdialog.c: Use the embed interface.
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | ChangeLog.pre-2-10 | 12 | ||||
-rw-r--r-- | ChangeLog.pre-2-4 | 12 | ||||
-rw-r--r-- | ChangeLog.pre-2-6 | 12 | ||||
-rw-r--r-- | ChangeLog.pre-2-8 | 12 | ||||
-rw-r--r-- | gtk/Makefile.am | 2 | ||||
-rw-r--r-- | gtk/gtkfilechooserdefault.c | 145 | ||||
-rw-r--r-- | gtk/gtkfilechooserdialog.c | 85 | ||||
-rw-r--r-- | gtk/gtkfilechooserembed.c | 163 | ||||
-rw-r--r-- | gtk/gtkfilechooserembed.h | 70 | ||||
-rw-r--r-- | gtk/gtkfilechooserutils.h | 1 | ||||
-rw-r--r-- | gtk/gtkfilechooserwidget.c | 15 |
12 files changed, 507 insertions, 34 deletions
@@ -1,3 +1,15 @@ +Fri Feb 27 18:46:27 2004 Jonathan Blandford <jrb@redhat.com> + + * gtk/gtkfilechooserembed.h: New private interface to help + negotiate the default size of the widget. Still a bit buggy, but + better than the old behavior. + + * gtk/gtkfilechooserdefault.c: Implement the embed interface. + + * gtk/gtkfilechooserwidget.c: Proxy the embed interface. + + * gtk/gtkfilechooserdialog.c: Use the embed interface. + 2004-02-27 Federico Mena Quintero <federico@ximian.com> * gtk/gtkfilesystem.c (gtk_file_system_insert_bookmark): Added a diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 06e3b77e98..4d0dc696bd 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,15 @@ +Fri Feb 27 18:46:27 2004 Jonathan Blandford <jrb@redhat.com> + + * gtk/gtkfilechooserembed.h: New private interface to help + negotiate the default size of the widget. Still a bit buggy, but + better than the old behavior. + + * gtk/gtkfilechooserdefault.c: Implement the embed interface. + + * gtk/gtkfilechooserwidget.c: Proxy the embed interface. + + * gtk/gtkfilechooserdialog.c: Use the embed interface. + 2004-02-27 Federico Mena Quintero <federico@ximian.com> * gtk/gtkfilesystem.c (gtk_file_system_insert_bookmark): Added a diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 06e3b77e98..4d0dc696bd 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,15 @@ +Fri Feb 27 18:46:27 2004 Jonathan Blandford <jrb@redhat.com> + + * gtk/gtkfilechooserembed.h: New private interface to help + negotiate the default size of the widget. Still a bit buggy, but + better than the old behavior. + + * gtk/gtkfilechooserdefault.c: Implement the embed interface. + + * gtk/gtkfilechooserwidget.c: Proxy the embed interface. + + * gtk/gtkfilechooserdialog.c: Use the embed interface. + 2004-02-27 Federico Mena Quintero <federico@ximian.com> * gtk/gtkfilesystem.c (gtk_file_system_insert_bookmark): Added a diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 06e3b77e98..4d0dc696bd 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,15 @@ +Fri Feb 27 18:46:27 2004 Jonathan Blandford <jrb@redhat.com> + + * gtk/gtkfilechooserembed.h: New private interface to help + negotiate the default size of the widget. Still a bit buggy, but + better than the old behavior. + + * gtk/gtkfilechooserdefault.c: Implement the embed interface. + + * gtk/gtkfilechooserwidget.c: Proxy the embed interface. + + * gtk/gtkfilechooserdialog.c: Use the embed interface. + 2004-02-27 Federico Mena Quintero <federico@ximian.com> * gtk/gtkfilesystem.c (gtk_file_system_insert_bookmark): Added a diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 06e3b77e98..4d0dc696bd 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,15 @@ +Fri Feb 27 18:46:27 2004 Jonathan Blandford <jrb@redhat.com> + + * gtk/gtkfilechooserembed.h: New private interface to help + negotiate the default size of the widget. Still a bit buggy, but + better than the old behavior. + + * gtk/gtkfilechooserdefault.c: Implement the embed interface. + + * gtk/gtkfilechooserwidget.c: Proxy the embed interface. + + * gtk/gtkfilechooserdialog.c: Use the embed interface. + 2004-02-27 Federico Mena Quintero <federico@ximian.com> * gtk/gtkfilesystem.c (gtk_file_system_insert_bookmark): Added a diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 0c9ad1bb65..41606ad938 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -275,6 +275,7 @@ gtk_private_h_sources = \ gtkcellview.h \ gtkcellviewmenuitem.h \ gtkentryprivate.h \ + gtkfilechooserembed.h \ gtkfilechooserentry.h \ gtkfilechooserdefault.h \ gtkfilechooserprivate.h \ @@ -348,6 +349,7 @@ gtk_c_sources = \ gtkexpander.c \ gtkfilechooser.c \ gtkfilechooserdialog.c \ + gtkfilechooserembed.c \ gtkfilechooserentry.c \ gtkfilechooserdefault.c \ gtkfilechooserutils.c \ diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 5055850463..2d8eecafde 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -29,6 +29,7 @@ #include "gtkentry.h" #include "gtkexpander.h" #include "gtkfilechooserdefault.h" +#include "gtkfilechooserembed.h" #include "gtkfilechooserentry.h" #include "gtkfilechooserutils.h" #include "gtkfilechooser.h" @@ -71,6 +72,8 @@ typedef struct _GtkFileChooserDefaultClass GtkFileChooserDefaultClass; #define GTK_IS_FILE_CHOOSER_DEFAULT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FILE_CHOOSER_DEFAULT)) #define GTK_FILE_CHOOSER_DEFAULT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FILE_CHOOSER_DEFAULT, GtkFileChooserDefaultClass)) +#define PREVIEW_HBOX_SPACING 12 + struct _GtkFileChooserDefaultClass { GtkVBoxClass parent_class; @@ -204,9 +207,10 @@ typedef enum { /* FIXME: maybe this should correspond to the font size in the tree views... */ #define ICON_SIZE 20 -static void gtk_file_chooser_default_class_init (GtkFileChooserDefaultClass *class); -static void gtk_file_chooser_default_iface_init (GtkFileChooserIface *iface); -static void gtk_file_chooser_default_init (GtkFileChooserDefault *impl); +static void gtk_file_chooser_default_class_init (GtkFileChooserDefaultClass *class); +static void gtk_file_chooser_default_iface_init (GtkFileChooserIface *iface); +static void gtk_file_chooser_embed_default_iface_init (GtkFileChooserEmbedIface *iface); +static void gtk_file_chooser_default_init (GtkFileChooserDefault *impl); static GObject* gtk_file_chooser_default_constructor (GType type, guint n_construct_properties, @@ -221,7 +225,11 @@ static void gtk_file_chooser_default_get_property (GObject *ob GValue *value, GParamSpec *pspec); static void gtk_file_chooser_default_dispose (GObject *object); -static void gtk_file_chooser_default_show_all (GtkWidget *widget); +static void gtk_file_chooser_default_show_all (GtkWidget *widget); +static void gtk_file_chooser_default_style_set (GtkWidget *widget, + GtkStyle *previous_style); +static void gtk_file_chooser_default_screen_changed (GtkWidget *widget, + GdkScreen *previous_screen); static void gtk_file_chooser_default_set_current_folder (GtkFileChooser *chooser, const GtkFilePath *path); @@ -249,6 +257,12 @@ static gboolean gtk_file_chooser_default_remove_shortcut_folder (GtkFileCh const GtkFilePath *path, GError **error); static GSList * gtk_file_chooser_default_list_shortcut_folders (GtkFileChooser *chooser); +static void gtk_file_chooser_default_get_default_size (GtkFileChooserEmbed *chooser_embed, + gint *default_width, + gint *default_height); +static void gtk_file_chooser_default_get_resizable_hints (GtkFileChooserEmbed *chooser_embed, + gboolean *resize_horizontally, + gboolean *resize_vertically); static void location_popup_handler (GtkFileChooserDefault *impl); static void up_folder_handler (GtkFileChooserDefault *impl); @@ -347,11 +361,22 @@ _gtk_file_chooser_default_get_type (void) NULL /* interface_data */ }; + static const GInterfaceInfo file_chooser_embed_info = + { + (GInterfaceInitFunc) gtk_file_chooser_embed_default_iface_init, /* interface_init */ + NULL, /* interface_finalize */ + NULL /* interface_data */ + }; + file_chooser_default_type = g_type_register_static (GTK_TYPE_VBOX, "GtkFileChooserDefault", &file_chooser_default_info, 0); + g_type_add_interface_static (file_chooser_default_type, GTK_TYPE_FILE_CHOOSER, &file_chooser_info); + g_type_add_interface_static (file_chooser_default_type, + GTK_TYPE_FILE_CHOOSER_EMBED, + &file_chooser_embed_info); } return file_chooser_default_type; @@ -373,6 +398,8 @@ gtk_file_chooser_default_class_init (GtkFileChooserDefaultClass *class) gobject_class->dispose = gtk_file_chooser_default_dispose; widget_class->show_all = gtk_file_chooser_default_show_all; + widget_class->style_set = gtk_file_chooser_default_style_set; + widget_class->screen_changed = gtk_file_chooser_default_screen_changed; signals[LOCATION_POPUP] = _gtk_binding_signal_new ("location-popup", @@ -449,6 +476,12 @@ gtk_file_chooser_default_iface_init (GtkFileChooserIface *iface) } static void +gtk_file_chooser_embed_default_iface_init (GtkFileChooserEmbedIface *iface) +{ + iface->get_default_size = gtk_file_chooser_default_get_default_size; + iface->get_resizable_hints = gtk_file_chooser_default_get_resizable_hints; +} +static void gtk_file_chooser_default_init (GtkFileChooserDefault *impl) { impl->local_only = TRUE; @@ -593,6 +626,8 @@ update_preview_widget_visibility (GtkFileChooserDefault *impl) gtk_widget_show (impl->preview_frame); else gtk_widget_hide (impl->preview_frame); + + g_signal_emit_by_name (impl, "default-size-changed"); } static void @@ -1751,7 +1786,7 @@ file_pane_create (GtkFileChooserDefault *impl, /* Box for lists and preview */ - hbox = gtk_hbox_new (FALSE, 12); + hbox = gtk_hbox_new (FALSE, PREVIEW_HBOX_SPACING); gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0); gtk_widget_show (hbox); @@ -2129,6 +2164,7 @@ update_appearance (GtkFileChooserDefault *impl) gtk_widget_hide (impl->save_extra_align); gtk_widget_hide (impl->browse_extra_align); } + g_signal_emit_by_name (impl, "default-size-changed"); } static void @@ -2274,6 +2310,26 @@ gtk_file_chooser_default_show_all (GtkWidget *widget) } static void +gtk_file_chooser_default_style_set (GtkWidget *widget, + GtkStyle *previous_style) +{ + if (GTK_WIDGET_CLASS (parent_class)->style_set) + GTK_WIDGET_CLASS (parent_class)->style_set (widget, previous_style); + + g_signal_emit_by_name (widget, "default-size-changed"); +} + +static void +gtk_file_chooser_default_screen_changed (GtkWidget *widget, + GdkScreen *previous_screen) +{ + if (GTK_WIDGET_CLASS (parent_class)->screen_changed) + GTK_WIDGET_CLASS (parent_class)->screen_changed (widget, previous_screen); + + g_signal_emit_by_name (widget, "default-size-changed"); +} + +static void expand_and_select_func (GtkFileSystemModel *model, GtkTreePath *path, GtkTreeIter *iter, @@ -3009,6 +3065,85 @@ gtk_file_chooser_default_list_shortcut_folders (GtkFileChooser *chooser) return g_slist_reverse (list); } +#define NUM_LINES 40 +#define NUM_CHARS 50 + +/* Guesses a size based upon font sizes */ +static void +find_good_size_from_style (GtkWidget *widget, + gint *width, + gint *height) +{ + GtkFileChooserDefault *impl; + gint default_width, default_height; + int font_size; + GtkRequisition req; + GtkRequisition preview_req; + + g_assert (widget->style != NULL); + impl = GTK_FILE_CHOOSER_DEFAULT (widget); + + font_size = pango_font_description_get_size (widget->style->font_desc); + font_size = PANGO_PIXELS (font_size); + + default_width = font_size * NUM_CHARS; + default_height = font_size * NUM_LINES; + + /* Use at least the requisition size not including the preview widget */ + gtk_widget_size_request (widget, &req); + + if (impl->preview_widget_active && impl->preview_widget) + gtk_widget_size_request (impl->preview_frame, &preview_req); + else + preview_req.width = 0; + + default_width = MAX (default_width, (req.width - (preview_req.width + PREVIEW_HBOX_SPACING))); + default_height = MAX (default_height, req.height); + + *width = default_width; + *height = default_height; +} + +static void +gtk_file_chooser_default_get_default_size (GtkFileChooserEmbed *chooser_embed, + gint *default_width, + gint *default_height) +{ + GtkFileChooserDefault *impl; + + impl = GTK_FILE_CHOOSER_DEFAULT (chooser_embed); + + find_good_size_from_style (GTK_WIDGET (chooser_embed), default_width, default_height); + + if (impl->preview_widget_active && impl->preview_widget) + *default_width += impl->preview_widget->requisition.width + PREVIEW_HBOX_SPACING; +} + +static void +gtk_file_chooser_default_get_resizable_hints (GtkFileChooserEmbed *chooser_embed, + gboolean *resize_horizontally, + gboolean *resize_vertically) +{ + GtkFileChooserDefault *impl; + + impl = GTK_FILE_CHOOSER_DEFAULT (chooser_embed); + + if (*resize_horizontally) + *resize_horizontally = TRUE; + + if (resize_vertically) + { + *resize_vertically = TRUE; + + if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE || + impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER) + { + if (! gtk_expander_get_expanded (GTK_EXPANDER (impl->save_expander))) + *resize_vertically = FALSE; + } + } +} + static void set_current_filter (GtkFileChooserDefault *impl, GtkFileFilter *filter) diff --git a/gtk/gtkfilechooserdialog.c b/gtk/gtkfilechooserdialog.c index 9b0c30b784..77ffa49138 100644 --- a/gtk/gtkfilechooserdialog.c +++ b/gtk/gtkfilechooserdialog.c @@ -21,6 +21,7 @@ #include "gtkfilechooserdialog.h" #include "gtkfilechooserwidget.h" #include "gtkfilechooserutils.h" +#include "gtkfilechooserembed.h" #include "gtkfilesystem.h" #include "gtktypebuiltins.h" @@ -32,8 +33,12 @@ struct _GtkFileChooserDialogPrivate { GtkWidget *widget; - + char *file_system; + + /* for use with GtkFileChooserEmbed */ + gint default_width; + gint default_height; }; #define GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE(o) (GTK_FILE_CHOOSER_DIALOG (o)->priv) @@ -54,11 +59,8 @@ static void gtk_file_chooser_dialog_get_property (GObject *obj GValue *value, GParamSpec *pspec); -static void gtk_file_chooser_dialog_realize (GtkWidget *widget); static void gtk_file_chooser_dialog_style_set (GtkWidget *widget, GtkStyle *previous_style); -static void gtk_file_chooser_dialog_screen_changed (GtkWidget *widget, - GdkScreen *previous_screen); static GObjectClass *parent_class; @@ -112,9 +114,7 @@ gtk_file_chooser_dialog_class_init (GtkFileChooserDialogClass *class) gobject_class->get_property = gtk_file_chooser_dialog_get_property; gobject_class->finalize = gtk_file_chooser_dialog_finalize; - widget_class->realize = gtk_file_chooser_dialog_realize; widget_class->style_set = gtk_file_chooser_dialog_style_set; - widget_class->screen_changed = gtk_file_chooser_dialog_screen_changed; _gtk_file_chooser_install_properties (gobject_class); @@ -128,6 +128,8 @@ gtk_file_chooser_dialog_init (GtkFileChooserDialog *dialog) GTK_TYPE_FILE_CHOOSER_DIALOG, GtkFileChooserDialogPrivate); dialog->priv = priv; + dialog->priv->default_width = -1; + dialog->priv->default_height = -1; gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); } @@ -150,6 +152,52 @@ file_chooser_widget_file_activated (GtkFileChooser *chooser, gtk_window_activate_default (GTK_WINDOW (dialog)); } +static void +file_chooser_widget_default_size_changed (GtkWidget *widget, + GtkFileChooserDialog *dialog) +{ + GtkFileChooserDialogPrivate *priv; + gint extra_width; + gint extra_height; + gint width, height; + + priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (dialog); + + /* Determine how much space the rest of the dialog uses compared to priv->widget */ + extra_width = GTK_WIDGET (dialog)->requisition.width - priv->widget->requisition.width; + extra_height = GTK_WIDGET (dialog)->requisition.height - priv->widget->requisition.height; + + _gtk_file_chooser_embed_get_default_size (GTK_FILE_CHOOSER_EMBED (priv->widget), + &width, &height); + + width = extra_width + width; + height = extra_height + height; + + /* g_print ("file_chooser_widget_default_size_changed: %d %d\n", width, height);*/ + /* FIXME: We should make sure that we arent' bigger than the current screen */ + if (GTK_WIDGET_REALIZED (dialog) && + priv->default_width > 0 && + priv->default_height > 0) + { + gint cur_width, cur_height; + gint dx, dy; + + gtk_window_get_size (GTK_WINDOW (dialog), &cur_width, &cur_height); + dx = width - priv->default_width; + dy = height - priv->default_height; + gtk_window_resize (GTK_WINDOW (dialog), + cur_width + dx, + cur_height + dy); + } + else + { + gtk_window_set_default_size (GTK_WINDOW (dialog), width, height); + } + priv->default_width = width; + priv->default_height = height; +} + + static GObject* gtk_file_chooser_dialog_constructor (GType type, guint n_construct_properties, @@ -174,6 +222,8 @@ gtk_file_chooser_dialog_constructor (GType type, g_signal_connect (priv->widget, "file-activated", G_CALLBACK (file_chooser_widget_file_activated), object); + g_signal_connect (priv->widget, "default-size-changed", + G_CALLBACK (file_chooser_widget_default_size_changed), object); gtk_box_pack_start (GTK_BOX (GTK_DIALOG (object)->vbox), priv->widget, TRUE, TRUE, 0); gtk_widget_show (priv->widget); @@ -268,13 +318,6 @@ set_default_size (GtkFileChooserDialog *dialog) } static void -gtk_file_chooser_dialog_realize (GtkWidget *widget) -{ - GTK_WIDGET_CLASS (parent_class)->realize (widget); - set_default_size (GTK_FILE_CHOOSER_DIALOG (widget)); -} - -static void gtk_file_chooser_dialog_style_set (GtkWidget *widget, GtkStyle *previous_style) { @@ -283,9 +326,6 @@ gtk_file_chooser_dialog_style_set (GtkWidget *widget, if (GTK_WIDGET_CLASS (parent_class)->style_set) GTK_WIDGET_CLASS (parent_class)->style_set (widget, previous_style); - if (GTK_WIDGET_REALIZED (widget)) - set_default_size (GTK_FILE_CHOOSER_DIALOG (widget)); - dialog = GTK_DIALOG (widget); /* Override the style properties with HIG-compliant spacings. Ugh. @@ -294,23 +334,12 @@ gtk_file_chooser_dialog_style_set (GtkWidget *widget, */ gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), 12); - gtk_box_set_spacing (GTK_BOX (dialog->vbox), 24); + gtk_box_set_spacing (GTK_BOX (dialog->vbox), 12); gtk_container_set_border_width (GTK_CONTAINER (dialog->action_area), 0); gtk_box_set_spacing (GTK_BOX (dialog->action_area), 6); } -static void -gtk_file_chooser_dialog_screen_changed (GtkWidget *widget, - GdkScreen *previous_screen) -{ - if (GTK_WIDGET_CLASS (parent_class)->screen_changed) - GTK_WIDGET_CLASS (parent_class)->screen_changed (widget, previous_screen); - - if (GTK_WIDGET_REALIZED (widget)) - set_default_size (GTK_FILE_CHOOSER_DIALOG (widget)); -} - static GtkWidget * gtk_file_chooser_dialog_new_valist (const gchar *title, GtkWindow *parent, diff --git a/gtk/gtkfilechooserembed.c b/gtk/gtkfilechooserembed.c new file mode 100644 index 0000000000..89637e3475 --- /dev/null +++ b/gtk/gtkfilechooserembed.c @@ -0,0 +1,163 @@ +#include "gtkfilechooserembed.h" +#include "gtkmarshalers.h" + +static void gtk_file_chooser_embed_class_init (gpointer g_iface); +static void delegate_get_default_size (GtkFileChooserEmbed *chooser_embed, + gint *default_width, + gint *default_height); +static void delegate_get_resizable_hints (GtkFileChooserEmbed *chooser_embed, + gboolean *resize_horizontally, + gboolean *resize_vertically); +static void delegate_default_size_changed (GtkFileChooserEmbed *chooser_embed, + gpointer data); +static void delegate_resizable_hints_changed (GtkFileChooserEmbed *chooser_embed, + gpointer data); + +static GtkFileChooserEmbed * +get_delegate (GtkFileChooserEmbed *receiver) +{ + return g_object_get_data (G_OBJECT (receiver), "gtk-file-chooser-embed-delegate"); +} + +/** + * _gtk_file_chooser_embed_delegate_iface_init: + * @iface: a #GtkFileChoserEmbedIface structure + * + * An interface-initialization function for use in cases where an object is + * simply delegating the methods, signals of the #GtkFileChooserEmbed interface + * to another object. _gtk_file_chooser_embed_set_delegate() must be called on + * each instance of the object so that the delegate object can be found. + **/ +void +_gtk_file_chooser_embed_delegate_iface_init (GtkFileChooserEmbedIface *iface) +{ + iface->get_default_size = delegate_get_default_size; + iface->get_resizable_hints = delegate_get_resizable_hints; +} + +/** + * _gtk_file_chooser_embed_set_delegate: + * @receiver: a GOobject implementing #GtkFileChooserEmbed + * @delegate: another GObject implementing #GtkFileChooserEmbed + * + * Establishes that calls on @receiver for #GtkFileChooser methods should be + * delegated to @delegate, and that #GtkFileChooser signals emitted on @delegate + * should be forwarded to @receiver. Must be used in confunction with + * _gtk_file_chooser_delegate_iface_init(). + **/ +void +_gtk_file_chooser_embed_set_delegate (GtkFileChooserEmbed *receiver, + GtkFileChooserEmbed *delegate) +{ + g_return_if_fail (GTK_IS_FILE_CHOOSER_EMBED (receiver)); + g_return_if_fail (GTK_IS_FILE_CHOOSER_EMBED (delegate)); + + g_object_set_data (G_OBJECT (receiver), "gtk-file-chooser-embed-delegate", delegate); + + g_signal_connect (delegate, "default_size_changed", + G_CALLBACK (delegate_default_size_changed), receiver); + g_signal_connect (delegate, "resizable_hints_changed", + G_CALLBACK (delegate_resizable_hints_changed), receiver); +} + + + +static void +delegate_get_default_size (GtkFileChooserEmbed *chooser_embed, + gint *default_width, + gint *default_height) +{ + _gtk_file_chooser_embed_get_default_size (get_delegate (chooser_embed), default_width, default_height); +} + +static void +delegate_get_resizable_hints (GtkFileChooserEmbed *chooser_embed, + gboolean *resize_horizontally, + gboolean *resize_vertically) +{ + _gtk_file_chooser_embed_get_resizable_hints (get_delegate (chooser_embed), resize_horizontally, resize_vertically); +} + +static void +delegate_default_size_changed (GtkFileChooserEmbed *chooser_embed, + gpointer data) +{ + g_signal_emit_by_name (data, "default-size-changed"); +} + +static void +delegate_resizable_hints_changed (GtkFileChooserEmbed *chooser_embed, + gpointer data) +{ + g_signal_emit_by_name (data, "resizable-hints-changed"); +} + + +/* publicly callable functions */ + +GType +_gtk_file_chooser_embed_get_type (void) +{ + static GType file_chooser_embed_type = 0; + + if (!file_chooser_embed_type) + { + static const GTypeInfo file_chooser_embed_info = + { + sizeof (GtkFileChooserEmbedIface), /* class_size */ + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc)gtk_file_chooser_embed_class_init, /* class_init */ + }; + + file_chooser_embed_type = g_type_register_static (G_TYPE_INTERFACE, + "GtkFileChooserEmbed", + &file_chooser_embed_info, 0); + + g_type_interface_add_prerequisite (file_chooser_embed_type, GTK_TYPE_WIDGET); + } + + return file_chooser_embed_type; +} + +static void +gtk_file_chooser_embed_class_init (gpointer g_iface) +{ + GType iface_type = G_TYPE_FROM_INTERFACE (g_iface); + + g_signal_new ("default-size-changed", + iface_type, + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GtkFileChooserEmbedIface, default_size_changed), + NULL, NULL, + _gtk_marshal_VOID__VOID, + G_TYPE_NONE, 0); + g_signal_new ("resizable-hints-changed", + iface_type, + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GtkFileChooserEmbedIface, resizable_hints_changed), + NULL, NULL, + _gtk_marshal_VOID__VOID, + G_TYPE_NONE, 0); +} + +void +_gtk_file_chooser_embed_get_default_size (GtkFileChooserEmbed *chooser_embed, + gint *default_width, + gint *default_height) +{ + g_return_if_fail (GTK_IS_FILE_CHOOSER_EMBED (chooser_embed)); + + GTK_FILE_CHOOSER_EMBED_GET_IFACE (chooser_embed)->get_default_size (chooser_embed, default_width, default_height); +} + +void +_gtk_file_chooser_embed_get_resizable_hints (GtkFileChooserEmbed *chooser_embed, + gboolean *resize_horizontally, + gboolean *resize_vertically) +{ + g_return_if_fail (GTK_IS_FILE_CHOOSER_EMBED (chooser_embed)); + + GTK_FILE_CHOOSER_EMBED_GET_IFACE (chooser_embed)->get_resizable_hints (chooser_embed, resize_horizontally, resize_vertically); +} + diff --git a/gtk/gtkfilechooserembed.h b/gtk/gtkfilechooserembed.h new file mode 100644 index 0000000000..a44f72b20d --- /dev/null +++ b/gtk/gtkfilechooserembed.h @@ -0,0 +1,70 @@ +/* GTK - The GIMP Toolkit + * gtkfilechooserembed.h: Abstract sizing interface for file selector implementations + * Copyright (C) 2004, Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GTK_FILE_CHOOSER_EMBED_H__ +#define __GTK_FILE_CHOOSER_EMBED_H__ + +#include <gtk/gtkwidget.h> + +G_BEGIN_DECLS + +#define GTK_TYPE_FILE_CHOOSER_EMBED (_gtk_file_chooser_embed_get_type ()) +#define GTK_FILE_CHOOSER_EMBED(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FILE_CHOOSER_EMBED, GtkFileChooserEmbed)) +#define GTK_IS_FILE_CHOOSER_EMBED(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FILE_CHOOSER_EMBED)) +#define GTK_FILE_CHOOSER_EMBED_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GTK_TYPE_FILE_CHOOSER_EMBED, GtkFileChooserEmbedIface)) + +typedef struct _GtkFileChooserEmbed GtkFileChooserEmbed; +typedef struct _GtkFileChooserEmbedIface GtkFileChooserEmbedIface; + + +struct _GtkFileChooserEmbedIface +{ + GTypeInterface base_iface; + + /* Methods + */ + void (*get_default_size) (GtkFileChooserEmbed *chooser_embed, + gint *default_width, + gint *default_height); + void (*get_resizable_hints) (GtkFileChooserEmbed *chooser_embed, + gboolean *resize_horizontally, + gboolean *resize_vertically); + /* Signals + */ + void (*default_size_changed) (GtkFileChooserEmbed *chooser_embed); + void (*resizable_hints_changed) (GtkFileChooserEmbed *chooser_embed); +}; + +GType _gtk_file_chooser_embed_get_type (void); + +void _gtk_file_chooser_embed_get_default_size (GtkFileChooserEmbed *chooser_embed, + gint *default_width, + gint *default_height); +void _gtk_file_chooser_embed_get_resizable_hints (GtkFileChooserEmbed *chooser_embed, + gboolean *resize_horizontally, + gboolean *resize_vertically); + +void _gtk_file_chooser_embed_delegate_iface_init (GtkFileChooserEmbedIface *iface); +void _gtk_file_chooser_embed_set_delegate (GtkFileChooserEmbed *receiver, + GtkFileChooserEmbed *delegate); + +G_END_DECLS + +#endif /* __GTK_FILE_CHOOSER_EMBED_H__ */ diff --git a/gtk/gtkfilechooserutils.h b/gtk/gtkfilechooserutils.h index 16c0f09de9..f6ce29c07e 100644 --- a/gtk/gtkfilechooserutils.h +++ b/gtk/gtkfilechooserutils.h @@ -31,7 +31,6 @@ typedef enum { GTK_FILE_CHOOSER_PROP_ACTION = GTK_FILE_CHOOSER_PROP_FIRST, GTK_FILE_CHOOSER_PROP_FILE_SYSTEM_BACKEND, GTK_FILE_CHOOSER_PROP_FILTER, - GTK_FILE_CHOOSER_PROP_FOLDER_MODE, GTK_FILE_CHOOSER_PROP_LOCAL_ONLY, GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET, GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE, diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c index f2a1d75364..9054ae98be 100644 --- a/gtk/gtkfilechooserwidget.c +++ b/gtk/gtkfilechooserwidget.c @@ -22,6 +22,7 @@ #include "gtkfilechooserdefault.h" #include "gtkfilechooserutils.h" #include "gtktypebuiltins.h" +#include "gtkfilechooserembed.h" struct _GtkFileChooserWidgetPrivate { @@ -77,11 +78,22 @@ gtk_file_chooser_widget_get_type (void) NULL /* interface_data */ }; + static const GInterfaceInfo file_chooser_embed_info = + { + (GInterfaceInitFunc) _gtk_file_chooser_embed_delegate_iface_init, /* interface_init */ + NULL, /* interface_finalize */ + NULL /* interface_data */ + }; + file_chooser_widget_type = g_type_register_static (GTK_TYPE_VBOX, "GtkFileChooserWidget", &file_chooser_widget_info, 0); + g_type_add_interface_static (file_chooser_widget_type, GTK_TYPE_FILE_CHOOSER, &file_chooser_info); + g_type_add_interface_static (file_chooser_widget_type, + GTK_TYPE_FILE_CHOOSER_EMBED, + &file_chooser_embed_info); } return file_chooser_widget_type; @@ -150,6 +162,9 @@ gtk_file_chooser_widget_constructor (GType type, _gtk_file_chooser_set_delegate (GTK_FILE_CHOOSER (object), GTK_FILE_CHOOSER (priv->impl)); + + _gtk_file_chooser_embed_set_delegate (GTK_FILE_CHOOSER (object), + GTK_FILE_CHOOSER (priv->impl)); gtk_widget_pop_composite_child (); |