]> Pileus Git - ~andy/gtk/blob - gtk/gtkrecentchooserwidget.c
GtkRecentChooserWidget: derive from GtkBox, not GtkVBox
[~andy/gtk] / gtk / gtkrecentchooserwidget.c
1 /* GTK - The GIMP Toolkit
2  * gtkrecentchooserwidget.c: embeddable recently used resources chooser widget
3  * Copyright (C) 2006 Emmanuele Bassi
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, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #include "config.h"
22
23 #include "gtkrecentchooserwidget.h"
24 #include "gtkrecentchooserdefault.h"
25 #include "gtkrecentchooserutils.h"
26 #include "gtkorientable.h"
27 #include "gtktypebuiltins.h"
28
29 /**
30  * SECTION:gtkrecentchooserwidget
31  * @Short_description: Displays recently used files
32  * @Title: GtkRecentChooserWidget
33  * @See_also:#GtkRecentChooser, #GtkRecentChooserDialog
34  *
35  * #GtkRecentChooserWidget is a widget suitable for selecting recently used
36  * files.  It is the main building block of a #GtkRecentChooserDialog.  Most
37  * applications will only need to use the latter; you can use
38  * #GtkRecentChooserWidget as part of a larger window if you have special needs.
39  *
40  * Note that #GtkRecentChooserWidget does not have any methods of its own.
41  * Instead, you should use the functions that work on a #GtkRecentChooser.
42  *
43  * Recently used files are supported since GTK+ 2.10.
44  */
45
46
47 struct _GtkRecentChooserWidgetPrivate
48 {
49   GtkRecentManager *manager;
50   
51   GtkWidget *chooser;
52 };
53
54 #define GTK_RECENT_CHOOSER_WIDGET_GET_PRIVATE(obj)      (GTK_RECENT_CHOOSER_WIDGET (obj)->priv)
55
56 static GObject *gtk_recent_chooser_widget_constructor  (GType                  type,
57                                                         guint                  n_params,
58                                                         GObjectConstructParam *params);
59 static void     gtk_recent_chooser_widget_set_property (GObject               *object,
60                                                         guint                  prop_id,
61                                                         const GValue          *value,
62                                                         GParamSpec            *pspec);
63 static void     gtk_recent_chooser_widget_get_property (GObject               *object,
64                                                         guint                  prop_id,
65                                                         GValue                *value,
66                                                         GParamSpec            *pspec);
67 static void     gtk_recent_chooser_widget_finalize     (GObject               *object);
68
69
70 G_DEFINE_TYPE_WITH_CODE (GtkRecentChooserWidget,
71                          gtk_recent_chooser_widget,
72                          GTK_TYPE_BOX,
73                          G_IMPLEMENT_INTERFACE (GTK_TYPE_RECENT_CHOOSER,
74                                                 _gtk_recent_chooser_delegate_iface_init))
75
76 static void
77 gtk_recent_chooser_widget_class_init (GtkRecentChooserWidgetClass *klass)
78 {
79   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
80
81   gobject_class->constructor = gtk_recent_chooser_widget_constructor;
82   gobject_class->set_property = gtk_recent_chooser_widget_set_property;
83   gobject_class->get_property = gtk_recent_chooser_widget_get_property;
84   gobject_class->finalize = gtk_recent_chooser_widget_finalize;
85
86   _gtk_recent_chooser_install_properties (gobject_class);
87
88   g_type_class_add_private (klass, sizeof (GtkRecentChooserWidgetPrivate));
89 }
90
91
92 static void
93 gtk_recent_chooser_widget_init (GtkRecentChooserWidget *widget)
94 {
95   widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget, GTK_TYPE_RECENT_CHOOSER_WIDGET,
96                                               GtkRecentChooserWidgetPrivate);
97
98   gtk_orientable_set_orientation (GTK_ORIENTABLE (widget),
99                                   GTK_ORIENTATION_VERTICAL);
100 }
101
102 static GObject *
103 gtk_recent_chooser_widget_constructor (GType                  type,
104                                        guint                  n_params,
105                                        GObjectConstructParam *params)
106 {
107   GObject *object;
108   GtkRecentChooserWidgetPrivate *priv;
109
110   object = G_OBJECT_CLASS (gtk_recent_chooser_widget_parent_class)->constructor (type,
111                                                                                  n_params,
112                                                                                  params);
113
114   priv = GTK_RECENT_CHOOSER_WIDGET_GET_PRIVATE (object);
115   priv->chooser = _gtk_recent_chooser_default_new (priv->manager);
116   
117   
118   gtk_container_add (GTK_CONTAINER (object), priv->chooser);
119   gtk_widget_show (priv->chooser);
120   _gtk_recent_chooser_set_delegate (GTK_RECENT_CHOOSER (object),
121                                     GTK_RECENT_CHOOSER (priv->chooser));
122
123   return object;
124 }
125
126 static void
127 gtk_recent_chooser_widget_set_property (GObject      *object,
128                                         guint         prop_id,
129                                         const GValue *value,
130                                         GParamSpec   *pspec)
131 {
132   GtkRecentChooserWidgetPrivate *priv;
133
134   priv = GTK_RECENT_CHOOSER_WIDGET_GET_PRIVATE (object);
135   
136   switch (prop_id)
137     {
138     case GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER:
139       priv->manager = g_value_get_object (value);
140       break;
141     default:
142       g_object_set_property (G_OBJECT (priv->chooser), pspec->name, value);
143       break;
144     }
145 }
146
147 static void
148 gtk_recent_chooser_widget_get_property (GObject    *object,
149                                         guint       prop_id,
150                                         GValue     *value,
151                                         GParamSpec *pspec)
152 {
153   GtkRecentChooserWidgetPrivate *priv;
154
155   priv = GTK_RECENT_CHOOSER_WIDGET_GET_PRIVATE (object);
156
157   g_object_get_property (G_OBJECT (priv->chooser), pspec->name, value);
158 }
159
160 static void
161 gtk_recent_chooser_widget_finalize (GObject *object)
162 {
163   GtkRecentChooserWidgetPrivate *priv;
164   
165   priv = GTK_RECENT_CHOOSER_WIDGET_GET_PRIVATE (object);
166   priv->manager = NULL;
167   
168   G_OBJECT_CLASS (gtk_recent_chooser_widget_parent_class)->finalize (object);
169 }
170
171 /*
172  * Public API
173  */
174
175 /**
176  * gtk_recent_chooser_widget_new:
177  * 
178  * Creates a new #GtkRecentChooserWidget object.  This is an embeddable widget
179  * used to access the recently used resources list.
180  *
181  * Return value: a new #GtkRecentChooserWidget
182  *
183  * Since: 2.10
184  */
185 GtkWidget *
186 gtk_recent_chooser_widget_new (void)
187 {
188   return g_object_new (GTK_TYPE_RECENT_CHOOSER_WIDGET, NULL);
189 }
190
191 /**
192  * gtk_recent_chooser_widget_new_for_manager:
193  * @manager: a #GtkRecentManager
194  *
195  * Creates a new #GtkRecentChooserWidget with a specified recent manager.
196  *
197  * This is useful if you have implemented your own recent manager, or if you
198  * have a customized instance of a #GtkRecentManager object.
199  *
200  * Return value: a new #GtkRecentChooserWidget
201  *
202  * Since: 2.10
203  */
204 GtkWidget *
205 gtk_recent_chooser_widget_new_for_manager (GtkRecentManager *manager)
206 {
207   g_return_val_if_fail (manager == NULL || GTK_IS_RECENT_MANAGER (manager), NULL);
208   
209   return g_object_new (GTK_TYPE_RECENT_CHOOSER_WIDGET,
210                        "recent-manager", manager,
211                        NULL);
212 }