1 /* GTK - The GIMP Toolkit
2 * gtkrecentchooserwidget.c: embeddable recently used resources chooser widget
3 * Copyright (C) 2006 Emmanuele Bassi
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/>.
21 #include "gtkrecentchooserwidget.h"
22 #include "gtkrecentchooserdefault.h"
23 #include "gtkrecentchooserutils.h"
24 #include "gtkorientable.h"
25 #include "gtktypebuiltins.h"
28 * SECTION:gtkrecentchooserwidget
29 * @Short_description: Displays recently used files
30 * @Title: GtkRecentChooserWidget
31 * @See_also:#GtkRecentChooser, #GtkRecentChooserDialog
33 * #GtkRecentChooserWidget is a widget suitable for selecting recently used
34 * files. It is the main building block of a #GtkRecentChooserDialog. Most
35 * applications will only need to use the latter; you can use
36 * #GtkRecentChooserWidget as part of a larger window if you have special needs.
38 * Note that #GtkRecentChooserWidget does not have any methods of its own.
39 * Instead, you should use the functions that work on a #GtkRecentChooser.
41 * Recently used files are supported since GTK+ 2.10.
45 struct _GtkRecentChooserWidgetPrivate
47 GtkRecentManager *manager;
52 #define GTK_RECENT_CHOOSER_WIDGET_GET_PRIVATE(obj) (GTK_RECENT_CHOOSER_WIDGET (obj)->priv)
54 static GObject *gtk_recent_chooser_widget_constructor (GType type,
56 GObjectConstructParam *params);
57 static void gtk_recent_chooser_widget_set_property (GObject *object,
61 static void gtk_recent_chooser_widget_get_property (GObject *object,
65 static void gtk_recent_chooser_widget_finalize (GObject *object);
68 G_DEFINE_TYPE_WITH_CODE (GtkRecentChooserWidget,
69 gtk_recent_chooser_widget,
71 G_IMPLEMENT_INTERFACE (GTK_TYPE_RECENT_CHOOSER,
72 _gtk_recent_chooser_delegate_iface_init))
75 gtk_recent_chooser_widget_class_init (GtkRecentChooserWidgetClass *klass)
77 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
79 gobject_class->constructor = gtk_recent_chooser_widget_constructor;
80 gobject_class->set_property = gtk_recent_chooser_widget_set_property;
81 gobject_class->get_property = gtk_recent_chooser_widget_get_property;
82 gobject_class->finalize = gtk_recent_chooser_widget_finalize;
84 _gtk_recent_chooser_install_properties (gobject_class);
86 g_type_class_add_private (klass, sizeof (GtkRecentChooserWidgetPrivate));
91 gtk_recent_chooser_widget_init (GtkRecentChooserWidget *widget)
93 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget, GTK_TYPE_RECENT_CHOOSER_WIDGET,
94 GtkRecentChooserWidgetPrivate);
96 gtk_orientable_set_orientation (GTK_ORIENTABLE (widget),
97 GTK_ORIENTATION_VERTICAL);
101 gtk_recent_chooser_widget_constructor (GType type,
103 GObjectConstructParam *params)
106 GtkRecentChooserWidgetPrivate *priv;
108 object = G_OBJECT_CLASS (gtk_recent_chooser_widget_parent_class)->constructor (type,
112 priv = GTK_RECENT_CHOOSER_WIDGET_GET_PRIVATE (object);
113 priv->chooser = _gtk_recent_chooser_default_new (priv->manager);
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));
125 gtk_recent_chooser_widget_set_property (GObject *object,
130 GtkRecentChooserWidgetPrivate *priv;
132 priv = GTK_RECENT_CHOOSER_WIDGET_GET_PRIVATE (object);
136 case GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER:
137 priv->manager = g_value_get_object (value);
140 g_object_set_property (G_OBJECT (priv->chooser), pspec->name, value);
146 gtk_recent_chooser_widget_get_property (GObject *object,
151 GtkRecentChooserWidgetPrivate *priv;
153 priv = GTK_RECENT_CHOOSER_WIDGET_GET_PRIVATE (object);
155 g_object_get_property (G_OBJECT (priv->chooser), pspec->name, value);
159 gtk_recent_chooser_widget_finalize (GObject *object)
161 GtkRecentChooserWidgetPrivate *priv;
163 priv = GTK_RECENT_CHOOSER_WIDGET_GET_PRIVATE (object);
164 priv->manager = NULL;
166 G_OBJECT_CLASS (gtk_recent_chooser_widget_parent_class)->finalize (object);
174 * gtk_recent_chooser_widget_new:
176 * Creates a new #GtkRecentChooserWidget object. This is an embeddable widget
177 * used to access the recently used resources list.
179 * Return value: a new #GtkRecentChooserWidget
184 gtk_recent_chooser_widget_new (void)
186 return g_object_new (GTK_TYPE_RECENT_CHOOSER_WIDGET, NULL);
190 * gtk_recent_chooser_widget_new_for_manager:
191 * @manager: a #GtkRecentManager
193 * Creates a new #GtkRecentChooserWidget with a specified recent manager.
195 * This is useful if you have implemented your own recent manager, or if you
196 * have a customized instance of a #GtkRecentManager object.
198 * Return value: a new #GtkRecentChooserWidget
203 gtk_recent_chooser_widget_new_for_manager (GtkRecentManager *manager)
205 g_return_val_if_fail (manager == NULL || GTK_IS_RECENT_MANAGER (manager), NULL);
207 return g_object_new (GTK_TYPE_RECENT_CHOOSER_WIDGET,
208 "recent-manager", manager,