1 /* GTK - The GIMP Toolkit
2 * gtkfilechooserwidget.c: Embeddable file selector widget
3 * Copyright (C) 2003, Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
20 #include "gtkfilechooserprivate.h"
22 #include "gtkfilechooserwidget.h"
23 #include "gtkfilechooserdefault.h"
24 #include "gtkfilechooserutils.h"
25 #include "gtktypebuiltins.h"
26 #include "gtkfilechooserembed.h"
27 #include "gtkorientable.h"
32 * SECTION:gtkfilechooserwidget
33 * @Short_description: File chooser widget that can be embedded in other widgets
34 * @Title: GtkFileChooserWidget
35 * @See_also: #GtkFileChooser, #GtkFileChooserDialog
37 * #GtkFileChooserWidget is a widget suitable for selecting files.
38 * It is the main building block of a #GtkFileChooserDialog. Most
39 * applications will only need to use the latter; you can use
40 * #GtkFileChooserWidget as part of a larger window if you have
43 * Note that #GtkFileChooserWidget does not have any methods of its
44 * own. Instead, you should use the functions that work on a
49 #define GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE(o) (GTK_FILE_CHOOSER_WIDGET (o)->priv)
51 static void gtk_file_chooser_widget_finalize (GObject *object);
53 static GObject* gtk_file_chooser_widget_constructor (GType type,
54 guint n_construct_properties,
55 GObjectConstructParam *construct_params);
56 static void gtk_file_chooser_widget_set_property (GObject *object,
60 static void gtk_file_chooser_widget_get_property (GObject *object,
65 G_DEFINE_TYPE_WITH_CODE (GtkFileChooserWidget, gtk_file_chooser_widget, GTK_TYPE_BOX,
66 G_IMPLEMENT_INTERFACE (GTK_TYPE_FILE_CHOOSER,
67 _gtk_file_chooser_delegate_iface_init)
68 G_IMPLEMENT_INTERFACE (GTK_TYPE_FILE_CHOOSER_EMBED,
69 _gtk_file_chooser_embed_delegate_iface_init))
72 gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
74 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
76 gobject_class->constructor = gtk_file_chooser_widget_constructor;
77 gobject_class->set_property = gtk_file_chooser_widget_set_property;
78 gobject_class->get_property = gtk_file_chooser_widget_get_property;
79 gobject_class->finalize = gtk_file_chooser_widget_finalize;
81 _gtk_file_chooser_install_properties (gobject_class);
83 g_type_class_add_private (class, sizeof (GtkFileChooserWidgetPrivate));
87 gtk_file_chooser_widget_init (GtkFileChooserWidget *chooser_widget)
89 GtkFileChooserWidgetPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (chooser_widget,
90 GTK_TYPE_FILE_CHOOSER_WIDGET,
91 GtkFileChooserWidgetPrivate);
92 chooser_widget->priv = priv;
93 gtk_orientable_set_orientation (GTK_ORIENTABLE (chooser_widget),
94 GTK_ORIENTATION_VERTICAL);
98 gtk_file_chooser_widget_finalize (GObject *object)
100 GtkFileChooserWidget *chooser = GTK_FILE_CHOOSER_WIDGET (object);
102 g_free (chooser->priv->file_system);
104 G_OBJECT_CLASS (gtk_file_chooser_widget_parent_class)->finalize (object);
108 gtk_file_chooser_widget_constructor (GType type,
109 guint n_construct_properties,
110 GObjectConstructParam *construct_params)
112 GtkFileChooserWidgetPrivate *priv;
115 object = G_OBJECT_CLASS (gtk_file_chooser_widget_parent_class)->constructor (type,
116 n_construct_properties,
118 priv = GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE (object);
120 gtk_widget_push_composite_child ();
122 priv->impl = _gtk_file_chooser_default_new ();
124 gtk_box_pack_start (GTK_BOX (object), priv->impl, TRUE, TRUE, 0);
125 gtk_widget_show (priv->impl);
127 _gtk_file_chooser_set_delegate (GTK_FILE_CHOOSER (object),
128 GTK_FILE_CHOOSER (priv->impl));
130 _gtk_file_chooser_embed_set_delegate (GTK_FILE_CHOOSER_EMBED (object),
131 GTK_FILE_CHOOSER_EMBED (priv->impl));
133 gtk_widget_pop_composite_child ();
139 gtk_file_chooser_widget_set_property (GObject *object,
144 GtkFileChooserWidgetPrivate *priv = GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE (object);
149 g_object_set_property (G_OBJECT (priv->impl), pspec->name, value);
155 gtk_file_chooser_widget_get_property (GObject *object,
160 GtkFileChooserWidgetPrivate *priv = GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE (object);
162 g_object_get_property (G_OBJECT (priv->impl), pspec->name, value);
166 * gtk_file_chooser_widget_new:
167 * @action: Open or save mode for the widget
169 * Creates a new #GtkFileChooserWidget. This is a file chooser widget that can
170 * be embedded in custom windows, and it is the same widget that is used by
171 * #GtkFileChooserDialog.
173 * Return value: a new #GtkFileChooserWidget
178 gtk_file_chooser_widget_new (GtkFileChooserAction action)
180 return g_object_new (GTK_TYPE_FILE_CHOOSER_WIDGET,