Debian Codegraph @

gtk/src/iconview.ccg

raw
1 /* Copyright (C) 1998-2004 The gtkmm Development Team
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
15 */
16
17 #include <glibmm/vectorutils.h>
18
19 #include <gtkmm/adjustment.h>
20 #include <gtk/gtk.h>
21
22 namespace //anonymous namespace
23 {
24
25 static void proxy_foreach_callback(GtkIconView* /* icon_view */, GtkTreePath* path, void* data)
26 {
27 typedef Gtk::IconView::SlotForeach SlotType;
28 auto& slot = *static_cast<SlotType*>(data);
29
30 try
31 {
32 slot(Gtk::TreeModel::Path(path, true));
33 }
34 catch(...)
35 {
36 Glib::exception_handlers_invoke();
37 }
38 }
39
40 } //anonymous namespace
41
42
43 namespace Gtk
44 {
45
46 void IconView::unset_model()
47 {
48 gtk_icon_view_set_model(gobj(), nullptr);
49 }
50
51 void IconView::selected_foreach(const SlotForeach& slot)
52 {
53 SlotForeach slot_copy(slot);
54 gtk_icon_view_selected_foreach(const_cast<GtkIconView*>(gobj()), &proxy_foreach_callback, &slot_copy);
55 }
56
57 bool IconView::get_item_at_pos(int x, int y, TreeModel::Path& path, CellRenderer*& cell) const
58 {
59 GtkTreePath* cpath = nullptr;
60 GtkCellRenderer* ccell = nullptr;
61 bool result = gtk_icon_view_get_item_at_pos(const_cast<GtkIconView*>(gobj()), x, y, &cpath, &ccell);
62
63 path = Glib::wrap(cpath); //Don't take copy because the gtk_icon_view_get_item_at_pos documentation says we should free this.
64 cell = Glib::wrap(ccell);
65 return result;
66 }
67
68 bool IconView::get_item_at_pos(int x, int y, TreeModel::Path& path) const
69 {
70 GtkTreePath* cpath = nullptr;
71 bool result = gtk_icon_view_get_item_at_pos(const_cast<GtkIconView*>(gobj()), x, y, &cpath, nullptr);
72
73 path = Glib::wrap(cpath); //Don't take copy because the gtk_icon_view_get_item_at_pos documentation says we should free this.
74 return result;
75 }
76
77 bool IconView::get_item_at_pos(int x, int y, CellRenderer*& cell) const
78 {
79 GtkCellRenderer* ccell = nullptr;
80 bool result = gtk_icon_view_get_item_at_pos(const_cast<GtkIconView*>(gobj()), x, y, nullptr, &ccell);
81
82 cell = Glib::wrap(ccell);
83 return result;
84 }
85
86 bool IconView::get_visible_range(TreeModel::Path& start_path, TreeModel::Path& end_path) const
87 {
88 GtkTreePath* cstart_path = nullptr;
89 GtkTreePath* cend_path = nullptr;
90 bool result = gtk_icon_view_get_visible_range(const_cast<GtkIconView*>(gobj()), &cstart_path, &cend_path);
91
92 start_path = Glib::wrap(cstart_path); //Don't take copy because the gtk_icon_view_get_visible_range documentation says we should free this.
93 end_path = Glib::wrap(cend_path); //Don't take copy because the gtk_icon_view_get_visible_range documentation says we should free this.
94 return result;
95 }
96
97 _IGNORE(gtk_icon_view_get_visible_range)
98
99 bool IconView::get_cursor(TreeModel::Path& path, CellRenderer*& cell) const
100 {
101 GtkTreePath* cpath = nullptr;
102 GtkCellRenderer* ccell = nullptr;
103 bool result = gtk_icon_view_get_cursor(const_cast<GtkIconView*>(gobj()), &cpath, &ccell);
104
105 path = Glib::wrap(cpath); //Don't take copy because the gtk_icon_view_get_cursor documentation says we should free this.
106 cell = Glib::wrap(ccell);
107 return result;
108 }
109
110 bool IconView::get_cursor(TreeModel::Path& path) const
111 {
112 GtkTreePath* cpath = nullptr;
113 bool result = gtk_icon_view_get_cursor(const_cast<GtkIconView*>(gobj()), &cpath, nullptr);
114
115 path = Glib::wrap(cpath); //Don't take copy because the gtk_icon_view_get_cursor documentation says we should free this.
116 return result;
117 }
118
119 bool IconView::get_cursor(CellRenderer*& cell) const
120 {
121 GtkCellRenderer* ccell = nullptr;
122 bool result = gtk_icon_view_get_cursor(const_cast<GtkIconView*>(gobj()), nullptr, &ccell);
123
124 cell = Glib::wrap(ccell);
125 return result;
126 }
127
128 void IconView::get_drag_dest_item(TreeModel::Path& path, IconViewDropPosition& pos) const
129 {
130 GtkTreePath* cpath = nullptr;
131 gtk_icon_view_get_drag_dest_item(const_cast<GtkIconView*>(gobj()), &cpath, (GtkIconViewDropPosition*)(&pos));
132 if(cpath)
133 path = Gtk::TreeModel::Path(cpath, true /* make_a_copy */);
134 }
135
136 void IconView::get_drag_dest_item(TreeModel::Path& path) const
137 {
138 GtkTreePath* cpath = nullptr;
139 gtk_icon_view_get_drag_dest_item(const_cast<GtkIconView*>(gobj()), &cpath, nullptr);
140 if(cpath)
141 path = Gtk::TreeModel::Path(cpath, true /* make_a_copy */);
142 }
143
144 void IconView::get_drag_dest_item(IconViewDropPosition& pos) const
145 {
146 gtk_icon_view_get_drag_dest_item(const_cast<GtkIconView*>(gobj()), nullptr, (GtkIconViewDropPosition*)(&pos));
147 }
148
149
150 bool IconView::get_dest_item_at_pos(int drag_x, int drag_y, TreeModel::Path& path, IconViewDropPosition& pos) const
151 {
152 GtkTreePath* cpath = nullptr;
153 const bool result = gtk_icon_view_get_dest_item_at_pos(const_cast<GtkIconView*>(gobj()), drag_x, drag_y, &cpath, (GtkIconViewDropPosition*)(&pos));
154 if(cpath)
155 path = Gtk::TreeModel::Path(cpath, true /* make_a_copy */);
156
157 return result;
158 }
159
160 bool IconView::get_dest_item_at_pos(int drag_x, int drag_y, TreeModel::Path& path) const
161 {
162 GtkTreePath* cpath = nullptr;
163 const bool result = gtk_icon_view_get_dest_item_at_pos(const_cast<GtkIconView*>(gobj()), drag_x, drag_y, &cpath, nullptr);
164 if(cpath)
165 path = Gtk::TreeModel::Path(cpath, true /* make_a_copy */);
166
167 return result;
168 }
169
170 bool IconView::get_dest_item_at_pos(int drag_x, int drag_y, IconViewDropPosition& pos) const
171 {
172 return gtk_icon_view_get_dest_item_at_pos(const_cast<GtkIconView*>(gobj()), drag_x, drag_y, nullptr, (GtkIconViewDropPosition*)(&pos));
173 }
174
175
176 void IconView::enable_model_drag_source(const std::vector<TargetEntry>& targets, Gdk::ModifierType start_button_mask, Gdk::DragAction actions)
177 {
178 gtk_icon_view_enable_model_drag_source(gobj(), (GdkModifierType)start_button_mask, Glib::ArrayHandler<TargetEntry, TargetEntryTraits>::vector_to_array(targets).data (), targets.size(), (GdkDragAction)actions);
179 }
180
181
182 void IconView::enable_model_drag_dest(const std::vector<TargetEntry>& targets, Gdk::DragAction actions)
183 {
184 gtk_icon_view_enable_model_drag_dest(gobj(), Glib::ArrayHandler<TargetEntry, TargetEntryTraits>::vector_to_array(targets).data(), targets.size(), (GdkDragAction)actions);
185 }
186
187 bool
188 IconView::get_tooltip_context_path(int& x, int& y,
189 bool keyboard_tip,
190 TreeModel::Path& path)
191 {
192 GtkTreePath* cpath = nullptr;
193
194 gboolean result =
195 gtk_icon_view_get_tooltip_context(gobj(),
196 &x, &y,
197 keyboard_tip,
198 nullptr,
199 &cpath,
200 nullptr);
201
202 // If result is false, cpath is not modified, it's still 0.
203 // wrap() can handle that situation.
204 path = Glib::wrap(cpath, /* take_copy= */ false);
205
206 return result;
207 }
208
209 bool
210 IconView::get_tooltip_context_iter(int& x, int& y,
211 bool keyboard_tip,
212 Gtk::TreeModel::iterator& iter)
213 {
214 GtkTreeIter src_iter;
215
216 gboolean result =
217 gtk_icon_view_get_tooltip_context(gobj(),
218 &x, &y,
219 keyboard_tip,
220 nullptr,
221 nullptr,
222 &src_iter);
223
224 iter = TreeIter(gtk_icon_view_get_model(this->gobj()), &src_iter);
225
226 return result;
227 }
228
229 } // namespace Gtk