2
* Copyright (c) 2011 Red Hat, Inc.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or (at your
7
* option) any later version.
9
* This program is distributed in the hope that it will be useful, but
10
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
12
* License for more details.
14
* You should have received a copy of the GNU Lesser General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
* Author: Cosimo Cecchi <cosimoc@redhat.com>
22
#include "gd-main-view-generic.h"
25
VIEW_SELECTION_CHANGED,
29
static guint signals[NUM_SIGNALS] = { 0, };
31
typedef GdMainViewGenericIface GdMainViewGenericInterface;
32
G_DEFINE_INTERFACE (GdMainViewGeneric, gd_main_view_generic, GTK_TYPE_WIDGET)
35
gd_main_view_generic_default_init (GdMainViewGenericInterface *iface)
37
signals[VIEW_SELECTION_CHANGED] =
38
g_signal_new ("view-selection-changed",
39
GD_TYPE_MAIN_VIEW_GENERIC,
46
* gd_main_view_generic_set_model:
48
* @model: (allow-none):
52
gd_main_view_generic_set_model (GdMainViewGeneric *self,
55
GdMainViewGenericInterface *iface;
57
iface = GD_MAIN_VIEW_GENERIC_GET_IFACE (self);
59
(* iface->set_model) (self, model);
63
gd_main_view_generic_get_path_at_pos (GdMainViewGeneric *self,
67
GdMainViewGenericInterface *iface;
69
iface = GD_MAIN_VIEW_GENERIC_GET_IFACE (self);
71
return (* iface->get_path_at_pos) (self, x, y);
75
gd_main_view_generic_set_selection_mode (GdMainViewGeneric *self,
76
gboolean selection_mode)
78
GdMainViewGenericInterface *iface;
80
iface = GD_MAIN_VIEW_GENERIC_GET_IFACE (self);
82
(* iface->set_selection_mode) (self, selection_mode);
87
GtkTreePath *rubberband_start;
88
GtkTreePath *rubberband_end;
92
rubber_band_info_destroy (RubberbandInfo *info)
94
g_clear_pointer (&info->rubberband_start,
96
g_clear_pointer (&info->rubberband_end,
98
g_slice_free (RubberbandInfo, info);
101
static RubberbandInfo*
102
get_rubber_band_info (GdMainViewGeneric *self)
104
RubberbandInfo *info;
106
info = g_object_get_data (G_OBJECT (self), "gd-main-view-generic-rubber-band");
109
info = g_slice_new0 (RubberbandInfo);
110
g_object_set_data_full (G_OBJECT (self), "gd-main-view-generic-rubber-band",
111
info, (GDestroyNotify)rubber_band_info_destroy);
118
gd_main_view_generic_set_rubberband_range (GdMainViewGeneric *self,
122
RubberbandInfo *info;
124
info = get_rubber_band_info (self);
126
if (start == NULL || end == NULL)
128
g_clear_pointer (&info->rubberband_start,
130
g_clear_pointer (&info->rubberband_end,
135
if (gtk_tree_path_compare (start, end) < 0)
137
info->rubberband_start = gtk_tree_path_copy (start);
138
info->rubberband_end = gtk_tree_path_copy (end);
142
info->rubberband_start = gtk_tree_path_copy (end);
143
info->rubberband_end = gtk_tree_path_copy (start);
147
gtk_widget_queue_draw (GTK_WIDGET (self));
151
_gd_main_view_generic_get_rubberband_range (GdMainViewGeneric *self,
155
RubberbandInfo *info;
157
info = get_rubber_band_info (self);
159
*start = info->rubberband_start;
160
*end = info->rubberband_end;
164
gd_main_view_generic_scroll_to_path (GdMainViewGeneric *self,
167
GdMainViewGenericInterface *iface;
169
iface = GD_MAIN_VIEW_GENERIC_GET_IFACE (self);
171
(* iface->scroll_to_path) (self, path);
175
* gd_main_view_generic_get_model:
177
* Returns: (transfer none): The associated model
180
gd_main_view_generic_get_model (GdMainViewGeneric *self)
182
GdMainViewGenericInterface *iface;
184
iface = GD_MAIN_VIEW_GENERIC_GET_IFACE (self);
186
return (* iface->get_model) (self);
190
build_selection_uris_foreach (GtkTreeModel *model,
195
GPtrArray *ptr_array = user_data;
197
gboolean is_selected;
199
gtk_tree_model_get (model, iter,
200
GD_MAIN_COLUMN_URI, &uri,
201
GD_MAIN_COLUMN_SELECTED, &is_selected,
205
g_ptr_array_add (ptr_array, uri);
213
model_get_selection_uris (GtkTreeModel *model)
215
GPtrArray *ptr_array = g_ptr_array_new ();
217
gtk_tree_model_foreach (model,
218
build_selection_uris_foreach,
221
g_ptr_array_add (ptr_array, NULL);
222
return (gchar **) g_ptr_array_free (ptr_array, FALSE);
226
set_selection_foreach (GtkTreeModel *model,
231
gboolean selection = GPOINTER_TO_INT (user_data);
233
gtk_list_store_set (GTK_LIST_STORE (model), iter,
234
GD_MAIN_COLUMN_SELECTED, selection,
241
set_all_selection (GdMainViewGeneric *self,
245
GtkTreeModel *actual_model;
250
if (GTK_IS_TREE_MODEL_FILTER (model))
251
actual_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
253
actual_model = model;
255
gtk_tree_model_foreach (actual_model,
256
set_selection_foreach,
257
GINT_TO_POINTER (selection));
258
g_signal_emit (self, signals[VIEW_SELECTION_CHANGED], 0);
262
gd_main_view_generic_select_all (GdMainViewGeneric *self)
264
GtkTreeModel *model = gd_main_view_generic_get_model (self);
266
set_all_selection (self, model, TRUE);
270
gd_main_view_generic_unselect_all (GdMainViewGeneric *self)
272
GtkTreeModel *model = gd_main_view_generic_get_model (self);
274
set_all_selection (self, model, FALSE);
278
_gd_main_view_generic_dnd_common (GtkTreeModel *model,
279
gboolean selection_mode,
281
GtkSelectionData *data)
287
uris = model_get_selection_uris (model);
297
res = gtk_tree_model_get_iter (model, &iter, path);
299
gtk_tree_model_get (model, &iter,
300
GD_MAIN_COLUMN_URI, &uri,
304
uris = g_new0 (gchar *, 2);
309
gtk_selection_data_set_uris (data, uris);