1 /*
2 * e-selectable.c
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 * for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 *
16 *
17 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
18 *
19 */
20
21 #include "evolution-config.h"
22
23 #include "e-selectable.h"
24
G_DEFINE_INTERFACE(ESelectable,e_selectable,GTK_TYPE_WIDGET)25 G_DEFINE_INTERFACE (
26 ESelectable,
27 e_selectable,
28 GTK_TYPE_WIDGET)
29
30 static void
31 e_selectable_default_init (ESelectableInterface *iface)
32 {
33 g_object_interface_install_property (
34 iface,
35 g_param_spec_boxed (
36 "copy-target-list",
37 "Copy Target List",
38 NULL,
39 GTK_TYPE_TARGET_LIST,
40 G_PARAM_READABLE));
41
42 g_object_interface_install_property (
43 iface,
44 g_param_spec_boxed (
45 "paste-target-list",
46 "Paste Target List",
47 NULL,
48 GTK_TYPE_TARGET_LIST,
49 G_PARAM_READABLE));
50 }
51
52 void
e_selectable_update_actions(ESelectable * selectable,EFocusTracker * focus_tracker,GdkAtom * clipboard_targets,gint n_clipboard_targets)53 e_selectable_update_actions (ESelectable *selectable,
54 EFocusTracker *focus_tracker,
55 GdkAtom *clipboard_targets,
56 gint n_clipboard_targets)
57 {
58 ESelectableInterface *iface;
59
60 g_return_if_fail (E_IS_SELECTABLE (selectable));
61
62 iface = E_SELECTABLE_GET_INTERFACE (selectable);
63 g_return_if_fail (iface->update_actions != NULL);
64
65 iface->update_actions (
66 selectable, focus_tracker,
67 clipboard_targets, n_clipboard_targets);
68 }
69
70 void
e_selectable_cut_clipboard(ESelectable * selectable)71 e_selectable_cut_clipboard (ESelectable *selectable)
72 {
73 ESelectableInterface *iface;
74
75 g_return_if_fail (E_IS_SELECTABLE (selectable));
76
77 iface = E_SELECTABLE_GET_INTERFACE (selectable);
78
79 if (iface->cut_clipboard != NULL)
80 iface->cut_clipboard (selectable);
81 }
82
83 void
e_selectable_copy_clipboard(ESelectable * selectable)84 e_selectable_copy_clipboard (ESelectable *selectable)
85 {
86 ESelectableInterface *iface;
87
88 g_return_if_fail (E_IS_SELECTABLE (selectable));
89
90 iface = E_SELECTABLE_GET_INTERFACE (selectable);
91
92 if (iface->copy_clipboard != NULL)
93 iface->copy_clipboard (selectable);
94 }
95
96 void
e_selectable_paste_clipboard(ESelectable * selectable)97 e_selectable_paste_clipboard (ESelectable *selectable)
98 {
99 ESelectableInterface *iface;
100
101 g_return_if_fail (E_IS_SELECTABLE (selectable));
102
103 iface = E_SELECTABLE_GET_INTERFACE (selectable);
104
105 if (iface->paste_clipboard != NULL)
106 iface->paste_clipboard (selectable);
107 }
108
109 void
e_selectable_delete_selection(ESelectable * selectable)110 e_selectable_delete_selection (ESelectable *selectable)
111 {
112 ESelectableInterface *iface;
113
114 g_return_if_fail (E_IS_SELECTABLE (selectable));
115
116 iface = E_SELECTABLE_GET_INTERFACE (selectable);
117
118 if (iface->delete_selection != NULL)
119 iface->delete_selection (selectable);
120 }
121
122 void
e_selectable_select_all(ESelectable * selectable)123 e_selectable_select_all (ESelectable *selectable)
124 {
125 ESelectableInterface *iface;
126
127 g_return_if_fail (E_IS_SELECTABLE (selectable));
128
129 iface = E_SELECTABLE_GET_INTERFACE (selectable);
130
131 if (iface->select_all != NULL)
132 iface->select_all (selectable);
133 }
134
135 void
e_selectable_undo(ESelectable * selectable)136 e_selectable_undo (ESelectable *selectable)
137 {
138 ESelectableInterface *iface;
139
140 g_return_if_fail (E_IS_SELECTABLE (selectable));
141
142 iface = E_SELECTABLE_GET_INTERFACE (selectable);
143
144 if (iface->undo != NULL)
145 iface->undo (selectable);
146 }
147
148 void
e_selectable_redo(ESelectable * selectable)149 e_selectable_redo (ESelectable *selectable)
150 {
151 ESelectableInterface *iface;
152
153 g_return_if_fail (E_IS_SELECTABLE (selectable));
154
155 iface = E_SELECTABLE_GET_INTERFACE (selectable);
156
157 if (iface->redo != NULL)
158 iface->redo (selectable);
159 }
160
161 GtkTargetList *
e_selectable_get_copy_target_list(ESelectable * selectable)162 e_selectable_get_copy_target_list (ESelectable *selectable)
163 {
164 GtkTargetList *target_list;
165
166 g_return_val_if_fail (E_IS_SELECTABLE (selectable), NULL);
167
168 g_object_get (selectable, "copy-target-list", &target_list, NULL);
169
170 /* We want to return a borrowed reference to the target
171 * list, so undo the reference that g_object_get() added. */
172 gtk_target_list_unref (target_list);
173
174 return target_list;
175 }
176
177 GtkTargetList *
e_selectable_get_paste_target_list(ESelectable * selectable)178 e_selectable_get_paste_target_list (ESelectable *selectable)
179 {
180 GtkTargetList *target_list;
181
182 g_return_val_if_fail (E_IS_SELECTABLE (selectable), NULL);
183
184 g_object_get (selectable, "paste-target-list", &target_list, NULL);
185
186 /* We want to return a borrowed reference to the target
187 * list, so undo the reference that g_object_get() added. */
188 gtk_target_list_unref (target_list);
189
190 return target_list;
191 }
192