]> Pileus Git - ~andy/gtk/blob - gtk/gtkfilechooserwidget.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / gtk / gtkfilechooserwidget.c
1 /* GTK - The GIMP Toolkit
2  * gtkfilechooserwidget.c: Embeddable file selector widget
3  * Copyright (C) 2003, Red Hat, Inc.
4  *
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.
9  *
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.
14  *
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/>.
17  */
18
19 #include "config.h"
20 #include "gtkfilechooserprivate.h"
21
22 #include "gtkfilechooserwidget.h"
23 #include "gtkfilechooserdefault.h"
24 #include "gtkfilechooserutils.h"
25 #include "gtktypebuiltins.h"
26 #include "gtkfilechooserembed.h"
27 #include "gtkorientable.h"
28 #include "gtkintl.h"
29
30
31 /**
32  * SECTION:gtkfilechooserwidget
33  * @Short_description: File chooser widget that can be embedded in other widgets
34  * @Title: GtkFileChooserWidget
35  * @See_also: #GtkFileChooser, #GtkFileChooserDialog
36  *
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
41  * special needs.
42  *
43  * Note that #GtkFileChooserWidget does not have any methods of its
44  * own.  Instead, you should use the functions that work on a
45  * #GtkFileChooser.
46  */
47
48
49 #define GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE(o)  (GTK_FILE_CHOOSER_WIDGET (o)->priv)
50
51 static void gtk_file_chooser_widget_finalize     (GObject                   *object);
52
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,
57                                                       guint                  prop_id,
58                                                       const GValue          *value,
59                                                       GParamSpec            *pspec);
60 static void     gtk_file_chooser_widget_get_property (GObject               *object,
61                                                       guint                  prop_id,
62                                                       GValue                *value,
63                                                       GParamSpec            *pspec);
64
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))
70
71 static void
72 gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
73 {
74   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
75
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;
80
81   _gtk_file_chooser_install_properties (gobject_class);
82
83   g_type_class_add_private (class, sizeof (GtkFileChooserWidgetPrivate));
84 }
85
86 static void
87 gtk_file_chooser_widget_init (GtkFileChooserWidget *chooser_widget)
88 {
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);
95 }
96
97 static void
98 gtk_file_chooser_widget_finalize (GObject *object)
99 {
100   GtkFileChooserWidget *chooser = GTK_FILE_CHOOSER_WIDGET (object);
101
102   g_free (chooser->priv->file_system);
103
104   G_OBJECT_CLASS (gtk_file_chooser_widget_parent_class)->finalize (object);
105 }
106
107 static GObject*
108 gtk_file_chooser_widget_constructor (GType                  type,
109                                      guint                  n_construct_properties,
110                                      GObjectConstructParam *construct_params)
111 {
112   GtkFileChooserWidgetPrivate *priv;
113   GObject *object;
114   
115   object = G_OBJECT_CLASS (gtk_file_chooser_widget_parent_class)->constructor (type,
116                                                                                n_construct_properties,
117                                                                                construct_params);
118   priv = GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE (object);
119
120   gtk_widget_push_composite_child ();
121
122   priv->impl = _gtk_file_chooser_default_new ();
123   
124   gtk_box_pack_start (GTK_BOX (object), priv->impl, TRUE, TRUE, 0);
125   gtk_widget_show (priv->impl);
126
127   _gtk_file_chooser_set_delegate (GTK_FILE_CHOOSER (object),
128                                   GTK_FILE_CHOOSER (priv->impl));
129
130   _gtk_file_chooser_embed_set_delegate (GTK_FILE_CHOOSER_EMBED (object),
131                                         GTK_FILE_CHOOSER_EMBED (priv->impl));
132   
133   gtk_widget_pop_composite_child ();
134
135   return object;
136 }
137
138 static void
139 gtk_file_chooser_widget_set_property (GObject         *object,
140                                       guint            prop_id,
141                                       const GValue    *value,
142                                       GParamSpec      *pspec)
143 {
144   GtkFileChooserWidgetPrivate *priv = GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE (object);
145
146   switch (prop_id)
147     {
148     default:
149       g_object_set_property (G_OBJECT (priv->impl), pspec->name, value);
150       break;
151     }
152 }
153
154 static void
155 gtk_file_chooser_widget_get_property (GObject         *object,
156                                       guint            prop_id,
157                                       GValue          *value,
158                                       GParamSpec      *pspec)
159 {
160   GtkFileChooserWidgetPrivate *priv = GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE (object);
161   
162   g_object_get_property (G_OBJECT (priv->impl), pspec->name, value);
163 }
164
165 /**
166  * gtk_file_chooser_widget_new:
167  * @action: Open or save mode for the widget
168  * 
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.
172  * 
173  * Return value: a new #GtkFileChooserWidget
174  *
175  * Since: 2.4
176  **/
177 GtkWidget *
178 gtk_file_chooser_widget_new (GtkFileChooserAction action)
179 {
180   return g_object_new (GTK_TYPE_FILE_CHOOSER_WIDGET,
181                        "action", action,
182                        NULL);
183 }