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 "ephy-overview-store.h"
23
#include "ephy-removable-pixbuf-renderer.h"
24
#include "gd-main-icon-view.h"
25
#include "gd-main-view.h"
26
#include "gd-main-view-generic.h"
27
#include "gd-toggle-pixbuf-renderer.h"
28
#include "gd-two-lines-renderer.h"
31
#include <glib/gi18n.h>
33
#define VIEW_ITEM_WIDTH 140
34
#define VIEW_ITEM_WRAP_WIDTH 128
35
#define VIEW_COLUMN_SPACING 20
36
#define VIEW_MARGIN 16
38
struct _GdMainIconViewPrivate {
39
GtkCellRenderer *pixbuf_cell;
40
gboolean selection_mode;
43
static void gd_main_view_generic_iface_init (GdMainViewGenericIface *iface);
44
G_DEFINE_TYPE_WITH_CODE (GdMainIconView, gd_main_icon_view, GTK_TYPE_ICON_VIEW,
45
G_IMPLEMENT_INTERFACE (GD_TYPE_MAIN_VIEW_GENERIC,
46
gd_main_view_generic_iface_init))
49
get_source_row (GdkDragContext *context)
51
GtkTreeRowReference *ref;
53
ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
56
return gtk_tree_row_reference_get_path (ref);
62
gd_main_icon_view_drag_data_get (GtkWidget *widget,
63
GdkDragContext *drag_context,
64
GtkSelectionData *data,
68
GdMainIconView *self = GD_MAIN_ICON_VIEW (widget);
69
GtkTreeModel *model = gtk_icon_view_get_model (GTK_ICON_VIEW (self));
74
_gd_main_view_generic_dnd_common (model, self->priv->selection_mode,
75
get_source_row (drag_context), data);
77
GTK_WIDGET_CLASS (gd_main_icon_view_parent_class)->drag_data_get (widget, drag_context,
82
on_cell_delete_clicked (EphyRemovablePixbufRenderer *cell,
86
_gd_main_view_generic_item_delete_clicked (GD_MAIN_VIEW_GENERIC (self), path);
90
gd_main_icon_view_constructed (GObject *obj)
92
GdMainIconView *self = GD_MAIN_ICON_VIEW (obj);
93
GtkCellRenderer *cell;
94
const GtkTargetEntry targets[] = {
95
{ "text/uri-list", GTK_TARGET_OTHER_APP, 0 }
98
G_OBJECT_CLASS (gd_main_icon_view_parent_class)->constructed (obj);
100
gtk_widget_set_hexpand (GTK_WIDGET (self), TRUE);
101
gtk_widget_set_vexpand (GTK_WIDGET (self), TRUE);
102
gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (self), GTK_SELECTION_NONE);
105
"column-spacing", VIEW_COLUMN_SPACING,
106
"margin", VIEW_MARGIN,
109
self->priv->pixbuf_cell = cell = ephy_removable_pixbuf_renderer_new ();
114
g_signal_connect (cell, "delete-clicked",
115
G_CALLBACK (on_cell_delete_clicked),
118
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (self), cell, FALSE);
119
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (self), cell,
120
"active", GD_MAIN_COLUMN_SELECTED);
121
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (self), cell,
122
"pixbuf", GD_MAIN_COLUMN_ICON);
123
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (self), cell,
124
"render-policy", EPHY_OVERVIEW_STORE_CLOSE_BUTTON_RENDER_POLICY);
126
cell = gd_two_lines_renderer_new ();
128
"alignment", PANGO_ALIGN_CENTER,
129
"wrap-mode", PANGO_WRAP_WORD_CHAR,
130
"wrap-width", VIEW_ITEM_WRAP_WIDTH,
133
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (self), cell, FALSE);
134
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (self), cell,
135
"text", GD_MAIN_COLUMN_TITLE);
136
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (self), cell,
137
"line-two", GD_MAIN_COLUMN_AUTHOR);
139
gtk_icon_view_enable_model_drag_source (GTK_ICON_VIEW (self),
146
gd_main_icon_view_class_init (GdMainIconViewClass *klass)
148
GObjectClass *oclass = G_OBJECT_CLASS (klass);
149
GtkWidgetClass *wclass = GTK_WIDGET_CLASS (klass);
151
oclass->constructed = gd_main_icon_view_constructed;
152
wclass->drag_data_get = gd_main_icon_view_drag_data_get;
154
gtk_widget_class_install_style_property (wclass,
155
g_param_spec_int ("check-icon-size",
161
g_type_class_add_private (klass, sizeof (GdMainIconViewPrivate));
165
gd_main_icon_view_init (GdMainIconView *self)
167
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GD_TYPE_MAIN_ICON_VIEW, GdMainIconViewPrivate);
171
gd_main_icon_view_get_path_at_pos (GdMainViewGeneric *mv,
175
return gtk_icon_view_get_path_at_pos (GTK_ICON_VIEW (mv), x, y);
179
gd_main_icon_view_set_selection_mode (GdMainViewGeneric *mv,
180
gboolean selection_mode)
182
GdMainIconView *self = GD_MAIN_ICON_VIEW (mv);
184
self->priv->selection_mode = selection_mode;
186
g_object_set (self->priv->pixbuf_cell,
187
"toggle-visible", selection_mode,
189
gtk_widget_queue_draw (GTK_WIDGET (self));
193
gd_main_icon_view_scroll_to_path (GdMainViewGeneric *mv,
196
gtk_icon_view_scroll_to_path (GTK_ICON_VIEW (mv), path, TRUE, 0.5, 0.5);
200
gd_main_icon_view_set_model (GdMainViewGeneric *mv,
203
gtk_icon_view_set_model (GTK_ICON_VIEW (mv), model);
207
gd_main_view_generic_iface_init (GdMainViewGenericIface *iface)
209
iface->set_model = gd_main_icon_view_set_model;
210
iface->get_path_at_pos = gd_main_icon_view_get_path_at_pos;
211
iface->scroll_to_path = gd_main_icon_view_scroll_to_path;
212
iface->set_selection_mode = gd_main_icon_view_set_selection_mode;
216
gd_main_icon_view_new (void)
218
return g_object_new (GD_TYPE_MAIN_ICON_VIEW, NULL);