diff options
author | Federico Mena Quintero <federico@ximian.com> | 2003-09-03 05:52:35 +0000 |
---|---|---|
committer | Federico Mena Quintero <federico@src.gnome.org> | 2003-09-03 05:52:35 +0000 |
commit | 36dfea8ece7cae37ff6b7a17e3370fed2e92c834 (patch) | |
tree | 72ff8526d4216558d6d6ed096332ed55f410a15a | |
parent | fafe735f130700fbb0184d5a9523a51160b2c94d (diff) | |
download | gdk-pixbuf-36dfea8ece7cae37ff6b7a17e3370fed2e92c834.tar.gz |
Removed the "extra widget" bit, implemented with the following:
2003-09-03 Federico Mena Quintero <federico@ximian.com>
* TODO: Removed the "extra widget" bit, implemented with the
following:
* gtkfilechooser.h: Added gtk_file_chooser_{set,get}_extra_widget().
* gtkfilechooser.c (gtk_file_chooser_base_init): Install an
"extra-widget" interface property.
(gtk_file_chooser_set_extra_widget): Implemented.
(gtk_file_chooser_get_extra_widget): Implemented.
* gtkfilechooserutils.h (GtkFileChooserProp): Added
GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET.
* gtkfilechooserutils.c (_gtk_file_chooser_install_properties):
Added the "extra-widget" property.
* gtkfilechooserimpldefault.c (struct _GtkFileChooserImplDefault):
Added an extra_widget field.
(gtk_file_chooser_impl_default_set_property): Handle the
"extra-widget" property.
(gtk_file_chooser_impl_default_get_property): Likewise.
(set_preview_widget): Fix the call gtk_container_remove(). Also,
we don't need to ref/sink/unref the preview widget, as that gets
already done by container_add/remove.
(set_extra_widget): New utility function.
* testfilechooser.c (main): Add an extra widget.
-rw-r--r-- | gtk/gtkfilechooser.c | 50 | ||||
-rw-r--r-- | gtk/gtkfilechooser.h | 6 | ||||
-rw-r--r-- | gtk/gtkfilechooserdefault.c | 38 | ||||
-rw-r--r-- | gtk/gtkfilechooserutils.c | 5 | ||||
-rw-r--r-- | gtk/gtkfilechooserutils.h | 1 | ||||
-rw-r--r-- | tests/testfilechooser.c | 5 |
6 files changed, 95 insertions, 10 deletions
diff --git a/gtk/gtkfilechooser.c b/gtk/gtkfilechooser.c index c04ea5aef..eb2338cac 100644 --- a/gtk/gtkfilechooser.c +++ b/gtk/gtkfilechooser.c @@ -128,6 +128,12 @@ gtk_file_chooser_base_init (gpointer g_iface) TRUE, G_PARAM_READWRITE)); g_object_interface_install_property (g_iface, + g_param_spec_object ("extra-widget", + _("Extra widget"), + _("Application supplied widget for extra options."), + GTK_TYPE_WIDGET, + G_PARAM_READWRITE)); + g_object_interface_install_property (g_iface, g_param_spec_boolean ("select-multiple", _("Select Multiple"), _("Whether to allow multiple files to be selected"), @@ -1079,6 +1085,50 @@ gtk_file_chooser_get_preview_uri (GtkFileChooser *chooser) } /** + * gtk_file_chooser_set_extra_widget: + * @chooser: a #GtkFileChooser + * @extra_widget: widget for extra options + * + * Sets an application-supplied widget to provide extra options to the user. + **/ +void +gtk_file_chooser_set_extra_widget (GtkFileChooser *chooser, + GtkWidget *extra_widget) +{ + g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser)); + + g_object_set (chooser, "extra-widget", extra_widget, NULL); +} + +/** + * gtk_file_chooser_get_extra_widget: + * @chooser: a #GtkFileChooser + * + * Gets the current preview widget; see + * gtk_file_chooser_set_extra_widget(). + * + * Return value: the current extra widget, or %NULL + **/ +GtkWidget * +gtk_file_chooser_get_extra_widget (GtkFileChooser *chooser) +{ + GtkWidget *extra_widget; + + g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL); + + g_object_get (chooser, "extra-widget", &extra_widget, NULL); + + /* Horrid hack; g_object_get() refs returned objects but + * that contradicts the memory management conventions + * for accessors. + */ + if (extra_widget) + g_object_unref (extra_widget); + + return extra_widget; +} + +/** * gtk_file_chooser_add_filter: * @chooser: a #GtkFileChooser * @filter: a #GtkFileFilter diff --git a/gtk/gtkfilechooser.h b/gtk/gtkfilechooser.h index afc797d7c..e2d55c240 100644 --- a/gtk/gtkfilechooser.h +++ b/gtk/gtkfilechooser.h @@ -101,6 +101,12 @@ gboolean gtk_file_chooser_get_preview_widget_active (GtkFileChooser *chooser); char *gtk_file_chooser_get_preview_filename (GtkFileChooser *file_chooser); char *gtk_file_chooser_get_preview_uri (GtkFileChooser *file_chooser); +/* Extra widget + */ +void gtk_file_chooser_set_extra_widget (GtkFileChooser *chooser, + GtkWidget *extra_widget); +GtkWidget *gtk_file_chooser_get_extra_widget (GtkFileChooser *chooser); + /* List of user selectable filters */ void gtk_file_chooser_add_filter (GtkFileChooser *chooser, diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 25cdeeb59..b1f5acc87 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -89,6 +89,7 @@ struct _GtkFileChooserImplDefault GtkWidget *list; GtkWidget *entry; GtkWidget *preview_widget; + GtkWidget *extra_widget; }; static void gtk_file_chooser_impl_default_class_init (GtkFileChooserImplDefaultClass *class); @@ -277,20 +278,12 @@ set_preview_widget (GtkFileChooserImplDefault *impl, return; if (impl->preview_widget) - { - g_object_unref (impl->preview_widget); - impl->preview_widget = NULL; - - gtk_container_remove (GTK_CONTAINER (impl->preview_frame), - impl->preview_widget); - } + gtk_container_remove (GTK_CONTAINER (impl->preview_frame), + impl->preview_widget); impl->preview_widget = preview_widget; if (impl->preview_widget) { - g_object_ref (impl->preview_widget); - gtk_object_sink (GTK_OBJECT (impl->preview_widget)); - gtk_widget_show (impl->preview_widget); gtk_container_add (GTK_CONTAINER (impl->preview_frame), impl->preview_widget); @@ -485,6 +478,25 @@ gtk_file_chooser_impl_default_constructor (GType type, return object; } +/* Sets the extra_widget by packing it in the appropriate place */ +static void +set_extra_widget (GtkFileChooserImplDefault *impl, + GtkWidget *extra_widget) +{ + if (extra_widget == impl->extra_widget) + return; + + if (impl->extra_widget) + gtk_container_remove (GTK_CONTAINER (impl), impl->extra_widget); + + impl->extra_widget = extra_widget; + if (impl->extra_widget) + { + gtk_widget_show (impl->extra_widget); + gtk_box_pack_end (GTK_BOX (impl), impl->extra_widget, FALSE, FALSE, 0); + } +} + static void gtk_file_chooser_impl_default_set_property (GObject *object, guint prop_id, @@ -538,6 +550,9 @@ gtk_file_chooser_impl_default_set_property (GObject *object, impl->preview_widget_active = g_value_get_boolean (value); update_preview_widget_visibility (impl); break; + case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET: + set_extra_widget (impl, g_value_get_object (value)); + break; case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE: { gboolean select_multiple = g_value_get_boolean (value); @@ -599,6 +614,9 @@ gtk_file_chooser_impl_default_get_property (GObject *object, case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE: g_value_set_boolean (value, impl->preview_widget_active); break; + case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET: + g_value_set_object (value, impl->extra_widget); + break; case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE: g_value_set_boolean (value, impl->select_multiple); break; diff --git a/gtk/gtkfilechooserutils.c b/gtk/gtkfilechooserutils.c index e60c82660..f5a55256f 100644 --- a/gtk/gtkfilechooserutils.c +++ b/gtk/gtkfilechooserutils.c @@ -103,6 +103,11 @@ _gtk_file_chooser_install_properties (GObjectClass *klass) G_TYPE_BOOLEAN, G_PARAM_READWRITE)); g_object_class_install_property (klass, + GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET, + g_param_spec_override ("extra-widget", + GTK_TYPE_WIDGET, + G_PARAM_READWRITE)); + g_object_class_install_property (klass, GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE, g_param_spec_override ("select-multiple", G_TYPE_BOOLEAN, diff --git a/gtk/gtkfilechooserutils.h b/gtk/gtkfilechooserutils.h index 874e56da3..038114140 100644 --- a/gtk/gtkfilechooserutils.h +++ b/gtk/gtkfilechooserutils.h @@ -35,6 +35,7 @@ typedef enum { GTK_FILE_CHOOSER_PROP_LOCAL_ONLY, GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET, GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE, + GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET, GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE, GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN, GTK_FILE_CHOOSER_PROP_LAST = GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN, diff --git a/tests/testfilechooser.c b/tests/testfilechooser.c index a4c35e750..be4922aea 100644 --- a/tests/testfilechooser.c +++ b/tests/testfilechooser.c @@ -264,6 +264,7 @@ main (int argc, char **argv) GtkFileSystem *file_system; GtkFileFilter *filter; GtkWidget *preview_vbox; + GtkWidget *extra; gtk_init (&argc, &argv); @@ -329,6 +330,10 @@ main (int argc, char **argv) update_preview_cb (GTK_FILE_CHOOSER (dialog)); g_signal_connect (dialog, "update-preview", G_CALLBACK (update_preview_cb), NULL); + + /* Extra widget */ + extra = gtk_check_button_new_with_mnemonic ("_Frobnicate the file"); + gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dialog), extra); gtk_window_set_default_size (GTK_WINDOW (dialog), 600, 400); /* show_all() to reveal bugs in composite widget handling */ |