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