Debian Codegraph @

gtk/src/iconview.hg

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 <vector>
18
19 #include <gtkmm/container.h>
20 #include <gtkmm/treemodel.h>
21 #include <gtkmm/treepath.h>
22 #include <gtkmm/celllayout.h>
23 #include <gtkmm/cellarea.h>
24 #include <gtkmm/cellrenderer.h>
25 #include <gtkmm/scrollable.h>
26 #include <gtkmm/tooltip.h>
27
28 _DEFS(gtkmm,gtk)
29 _PINCLUDE(gtkmm/private/container_p.h)
30
31 namespace Gtk
32 {
33
34 _WRAP_ENUM(IconViewDropPosition, GtkIconViewDropPosition, decl_prefix GTKMM_API)
35
36 /** The IconView provides an alternative view of a list model.
37 * It displays the model as a grid of icons with labels.
38 * Like the TreeView, it allows the user to select one or multiple items
39 * (depending on the selection mode - see set_selection_mode()).
40 * In addition to selection with the arrow keys, the IconView supports
41 * rubberband selection, by dragging the pointer.
42 *
43 * @ingroup Widgets
44 * @ingroup Containers
45 */
46 class GTKMM_API IconView
47 : public Container,
48 public CellLayout,
49 public Scrollable
50 {
51 _CLASS_GTKOBJECT(IconView, GtkIconView, GTK_ICON_VIEW, Gtk::Container, GtkContainer, , , GTKMM_API)
52 _IMPLEMENTS_INTERFACE(CellLayout)
53 _IMPLEMENTS_INTERFACE(Scrollable)
54 public:
55
56 _CTOR_DEFAULT()
57 _WRAP_CTOR(IconView(const Glib::RefPtr<TreeModel>& model), gtk_icon_view_new_with_model)
58 _WRAP_CTOR(IconView(const Glib::RefPtr<CellArea>& cell_area), gtk_icon_view_new_with_area)
59
60
61 _WRAP_METHOD(void set_model(const Glib::RefPtr<TreeModel>& model), gtk_icon_view_set_model)
62 _WRAP_METHOD(Glib::RefPtr<TreeModel> get_model(), gtk_icon_view_get_model, refreturn)
63 _WRAP_METHOD(Glib::RefPtr<const TreeModel> get_model() const, gtk_icon_view_get_model, refreturn, constversion)
64
65 /** Remove the model from the IconView.
66 *
67 * @see set_model().
68 *
69 * @newin{2,16}
70 */
71 void unset_model();
72
73 _WRAP_METHOD(void set_text_column(int column), gtk_icon_view_set_text_column)
74 _WRAP_METHOD(void set_text_column(const TreeModelColumnBase& model_column), gtk_icon_view_set_text_column)
75 _WRAP_METHOD(int get_text_column() const, gtk_icon_view_get_text_column)
76 _WRAP_METHOD(void set_markup_column(int column), gtk_icon_view_set_markup_column)
77 _WRAP_METHOD(void set_markup_column(const TreeModelColumnBase& column), gtk_icon_view_set_markup_column)
78 _WRAP_METHOD(int get_markup_column() const, gtk_icon_view_get_markup_column )
79 _WRAP_METHOD(void set_pixbuf_column(int column), gtk_icon_view_set_pixbuf_column)
80 _WRAP_METHOD(void set_pixbuf_column(const TreeModelColumnBase& column), gtk_icon_view_set_pixbuf_column)
81 _WRAP_METHOD(int get_pixbuf_column() const, gtk_icon_view_get_pixbuf_column)
82
83 _WRAP_METHOD(void set_item_orientation(Orientation orientation), gtk_icon_view_set_item_orientation)
84 _WRAP_METHOD(Orientation get_item_orientation() const, gtk_icon_view_get_item_orientation)
85
86 _WRAP_METHOD(void set_columns(int columns), gtk_icon_view_set_columns)
87 _WRAP_METHOD(int get_columns() const, gtk_icon_view_get_columns)
88 _WRAP_METHOD(void set_item_width(int item_width), gtk_icon_view_set_item_width)
89 _WRAP_METHOD(int get_icon_width() const, gtk_icon_view_get_item_width)
90 _WRAP_METHOD(void set_spacing(int spacing), gtk_icon_view_set_spacing)
91 _WRAP_METHOD(int get_spacing() const, gtk_icon_view_get_spacing)
92 _WRAP_METHOD(void set_row_spacing(int row_spacing), gtk_icon_view_set_row_spacing)
93 _WRAP_METHOD(gint get_row_spacing() const, gtk_icon_view_get_row_spacing)
94 _WRAP_METHOD(void set_column_spacing(int column_spacing), gtk_icon_view_set_column_spacing)
95 _WRAP_METHOD(int get_column_spacing() const, gtk_icon_view_get_column_spacing)
96
97 _WRAP_METHOD(void set_margin(int margin), gtk_icon_view_set_margin)
98 _WRAP_METHOD(int get_margin() const, gtk_icon_view_get_margin)
99
100 _WRAP_METHOD(void set_item_padding(int item_padding), gtk_icon_view_set_item_padding)
101 _WRAP_METHOD(int get_item_padding() const, gtk_icon_view_get_item_padding)
102
103 _WRAP_METHOD(TreeModel::Path get_path_at_pos(int x, int y) const, gtk_icon_view_get_path_at_pos )
104
105
106 /** Finds the path at the point (@a x, @a y), relative to widget coordinates.
107 *
108 * @param x The x position to be identified.
109 * @param y The y position to be identified.
110 * @param path The path.
111 * @param cell The renderer responsible for the cell at (@a x, @a y).
112 *
113 * @result true if an item exists at the specified position.
114 *
115 * @newin{2,6}
116 */
117 bool get_item_at_pos(int x, int y, TreeModel::Path& path, CellRenderer*& cell) const;
118
119 /** Finds the path at the point (@a x, @a y), relative to widget coordinates.
120 *
121 * @param x The x position to be identified.
122 * @param y The y position to be identified.
123 * @param path The path.
124 *
125 * @result true if an item exists at the specified position.
126 *
127 * @newin{2,6}
128 */
129 bool get_item_at_pos(int x, int y, TreeModel::Path& path) const;
130
131 /** Finds the path at the point (@a x, @a y), relative to widget coordinates.
132 *
133 * @param x The x position to be identified.
134 * @param y The y position to be identified.
135 * @param cell The renderer responsible for the cell at (@a x, @a y).
136 *
137 * @result true if an item exists at the specified position.
138 *
139 * @newin{2,6}
140 */
141 bool get_item_at_pos(int x, int y, CellRenderer*& cell) const;
142 _IGNORE(gtk_icon_view_get_item_at_pos)
143
144 bool get_visible_range(TreeModel::Path& start_path, TreeModel::Path& end_path) const;
145 _IGNORE(gtk_icon_view_get_visible_range)
146
147 _WRAP_METHOD(void set_activate_on_single_click(bool single = true), gtk_icon_view_set_activate_on_single_click)
148 _WRAP_METHOD(bool get_activate_on_single_click() const, gtk_icon_view_get_activate_on_single_click)
149
150 /** For instance,
151 * void on_foreach(const Gtk::TreeModel::Path& path);
152 */
153 typedef sigc::slot<void, const TreeModel::Path&> SlotForeach;
154
155 /** Calls a function for each selected icon. Note that the model or
156 * selection cannot be modified from within this function.
157 *
158 * @param slot The callback to call for each selected icon.
159 */
160 void selected_foreach(const SlotForeach& slot);
161 _IGNORE(gtk_icon_view_selected_foreach)
162
163 //Default value?:
164 _WRAP_METHOD(void set_selection_mode(SelectionMode mode), gtk_icon_view_set_selection_mode)
165 _WRAP_METHOD(SelectionMode get_selection_mode() const, gtk_icon_view_get_selection_mode)
166 _WRAP_METHOD(void select_path(const TreeModel::Path& path), gtk_icon_view_select_path)
167 _WRAP_METHOD(void unselect_path(const TreeModel::Path& path), gtk_icon_view_unselect_path)
168 _WRAP_METHOD(bool path_is_selected(const TreeModel::Path& path) const, gtk_icon_view_path_is_selected)
169
170 _WRAP_METHOD(int get_item_row(const TreeModel::Path& path) const, gtk_icon_view_get_item_row)
171 _WRAP_METHOD(int get_item_column(const TreeModel::Path& path) const, gtk_icon_view_get_item_column)
172
173 #m4 _CONVERSION(`GList*',`std::vector<TreePath>',`Glib::ListHandler<TreePath, TreePathTraits>::list_to_vector($3, Glib::OWNERSHIP_DEEP)')
174 _WRAP_METHOD(std::vector<TreePath> get_selected_items() const, gtk_icon_view_get_selected_items)
175
176 _WRAP_METHOD(void select_all(), gtk_icon_view_select_all)
177 _WRAP_METHOD(void unselect_all(), gtk_icon_view_unselect_all)
178 _WRAP_METHOD(void item_activated(const TreeModel::Path& path), gtk_icon_view_item_activated)
179
180 //TODO: Add a version with no cell parameter.
181 _WRAP_METHOD(void set_cursor(const TreeModel::Path& path, CellRenderer& cell{?}, bool start_editing), gtk_icon_view_set_cursor)
182
183 /** Fills in @a path and @a cell with the current cursor path and cell.
184 * If the cursor isn't currently set, then @a path will be empty.
185 * If no cell currently has focus, then @a cell will be NULL.
186 *
187 * @param path The current cursor path.
188 * @param cell The current focus cell.
189 * @result true if the cursor is set.
190 *
191 * @newin{2,8}
192 */
193 bool get_cursor(TreeModel::Path& path, CellRenderer*& cell) const;
194
195 /** Fills in @a path and @a cell with the current cursor path and cell.
196 * If the cursor isn't currently set, then @a path will be empty.
197 * If no cell currently has focus, then @a cell will be NULL.
198 *
199 * @param path The current cursor path.
200 * @result true if the cursor is set.
201 *
202 * @newin{2,8}
203 */
204 bool get_cursor(TreeModel::Path& path) const;
205
206 /** Fills in @a path and @a cell with the current cursor path and cell.
207 * If the cursor isn't currently set, then @a path will be empty.
208 * If no cell currently has focus, then @a cell will be NULL.
209 *
210 * @param cell The current focus cell.
211 * @result true if the cursor is set.
212 *
213 * @newin{2,8}
214 */
215 bool get_cursor(CellRenderer*& cell) const;
216 _IGNORE(gtk_icon_view_get_cursor)
217
218 _WRAP_METHOD(void scroll_to_path(const TreeModel::Path& path, bool use_align, gfloat row_align, gfloat col_align), gtk_icon_view_scroll_to_path)
219
220 /* Drag-and-Drop support */
221 /**
222 * Turns the IconView into a drag source for automatic DND.
223 *
224 * @param targets Standard container of targets that the drag will support.
225 * @param start_button_mask Mask of allowed buttons to start drag.
226 * @param actions The bitmask of possible actions for a drag from this widget.
227 */
228 void enable_model_drag_source(const std::vector<TargetEntry>& targets,
229 Gdk::ModifierType start_button_mask = Gdk::MODIFIER_MASK,
230 Gdk::DragAction actions = Gdk::ACTION_COPY | Gdk::ACTION_MOVE);
231 _IGNORE(gtk_icon_view_enable_model_drag_source)
232
233 /** Turns the IconView into a drop destination for automatic DND.
234 *
235 * @param targets The table of targets that the drag will support.
236 * @param actions The bitmask of possible actions for a drag from this widget.
237 */
238 void enable_model_drag_dest(const std::vector<TargetEntry>& targets, Gdk::DragAction actions = Gdk::ACTION_COPY | Gdk::ACTION_MOVE);
239 _IGNORE(gtk_icon_view_enable_model_drag_dest)
240
241 _WRAP_METHOD(void unset_model_drag_source(), gtk_icon_view_unset_model_drag_source)
242 _WRAP_METHOD(void unset_model_drag_dest(), gtk_icon_view_unset_model_drag_dest)
243
244 _WRAP_METHOD(void set_reorderable(bool reorderable = true), gtk_icon_view_set_reorderable)
245 _WRAP_METHOD(bool get_reorderable() const, gtk_icon_view_get_reorderable)
246
247
248 /* These are useful to implement your own custom stuff. */
249 //TODO: Discover what arguments are output arguments:
250 _WRAP_METHOD(void set_drag_dest_item(const TreeModel::Path& path, IconViewDropPosition pos), gtk_icon_view_set_drag_dest_item)
251
252 /** Gets information about the item that is highlighted for feedback.
253 *
254 * @param path The highlighted item.
255 * @param pos The drop position.
256 *
257 * @newin{2,10}
258 */
259 void get_drag_dest_item(TreeModel::Path& path, IconViewDropPosition& pos) const;
260
261 /** Gets information about the item that is highlighted for feedback.
262 *
263 * @param path The highlighted item.
264 *
265 * @newin{2,10}
266 */
267 void get_drag_dest_item(TreeModel::Path& path) const;
268
269 /** Gets information about the item that is highlighted for feedback.
270 *
271 * @param pos The drop position.
272 *
273 * @newin{2,10}
274 */
275 void get_drag_dest_item(IconViewDropPosition& pos) const;
276 _IGNORE(gtk_icon_view_get_drag_dest_item)
277
278 /** Determines the destination item for a given position.
279 *
280 * @param drag_x The position to determine the destination item for.
281 * @param drag_y the position to determine the destination item for.
282 * @param path The path of the item.
283 * @param pos: The drop position.
284 * @result whether there is an item at the given position.
285 *
286 * @newin{2,10}
287 */
288 bool get_dest_item_at_pos(int drag_x, int drag_y, TreeModel::Path& path, IconViewDropPosition& pos) const;
289
290 /** Determines the destination item for a given position.
291 *
292 * @param drag_x The position to determine the destination item for.
293 * @param drag_y the position to determine the destination item for.
294 * @param path The path of the item.
295 * @result whether there is an item at the given position.
296 *
297 * @newin{2,10}
298 */
299 bool get_dest_item_at_pos(int drag_x, int drag_y, TreeModel::Path& path) const;
300
301 /** Determines the destination item for a given position.
302 *
303 * @param drag_x The position to determine the destination item for.
304 * @param drag_y the position to determine the destination item for.
305 * @param pos: The drop position.
306 * @result whether there is an item at the given position.
307 *
308 * @newin{2,10}
309 */
310 bool get_dest_item_at_pos(int drag_x, int drag_y, IconViewDropPosition& pos) const;
311 _IGNORE(gtk_icon_view_get_dest_item_at_pos)
312
313 #m4 _CONVERSION(`cairo_surface_t*',`Cairo::RefPtr<Cairo::Surface>',`Cairo::RefPtr<Cairo::Surface>(new Cairo::Surface($3, false /* take reference */))')
314 _WRAP_METHOD(Cairo::RefPtr<Cairo::Surface> create_drag_icon( const TreeModel::Path& path), gtk_icon_view_create_drag_icon)
315
316 _WRAP_METHOD(void convert_widget_to_bin_window_coords(int wx, int wy, int& bx, int& by) const, gtk_icon_view_convert_widget_to_bin_window_coords)
317
318 #m4 _INITIALIZATION(`Gdk::Rectangle&',`GdkRectangle', `$3 = Glib::wrap(&($4))')
319 _WRAP_METHOD(bool get_cell_rect(const TreeModel::Path& path, const CellRenderer& cell{?}, Gdk::Rectangle& rect{.>>}) const, gtk_icon_view_get_cell_rect)
320
321
322 _WRAP_METHOD(void set_tooltip_item(const Glib::RefPtr<Tooltip>& tooltip, const TreeModel::Path& path), gtk_icon_view_set_tooltip_item)
323 _WRAP_METHOD(void set_tooltip_cell(const Glib::RefPtr<Tooltip>& tooltip, const TreeModel::Path& path, CellRenderer& cell), gtk_icon_view_set_tooltip_cell)
324
325 /** Sets the tip area of @a tooltip to the area occupied by
326 * the item pointed to by @a path. See also Tooltip::set_tip_area().
327 *
328 * @newin{2,12}
329 *
330 * @param tooltip A Gtk::Tooltip.
331 * @param path A Gtk::TreePath.
332 */
333 void set_tooltip_cell(const Glib::RefPtr<Tooltip>& tooltip, const TreeModel::Path& path);
334
335 /**
336 * @param x: the x coordinate (relative to widget coordinates)
337 * @param y: the y coordinate (relative to widget coordinates)
338 * @param keyboard_tip: whether this is a keyboard tooltip or not
339 * @param path: a reference to receive a Gtk::TreePath
340 *
341 * This function is supposed to be used in a Gtk::Widget::query-tooltip
342 * signal handler for Gtk::IconView. The x, y and keyboard_tip values
343 * which are received in the signal handler, should be passed to this
344 * function without modification.
345 *
346 * The return value indicates whether there is an icon view item at the given
347 * coordinates (true) or not (false) for mouse tooltips. For keyboard
348 * tooltips the item returned will be the cursor item. When true, then the
349 * path which has been provided will be set to point to
350 * that row and the corresponding model. x and y will always be converted
351 * to be relative to IconView's bin_window if keyboard_tooltip is false.
352 *
353 * Return value: whether or not the given tooltip context points to a item.
354 *
355 * @newin{2,12}
356 */
357 bool get_tooltip_context_path(int& x, int& y,
358 bool keyboard_tip,
359 TreeModel::Path& path);
360
361 /**
362 * @param x: the x coordinate (relative to widget coordinates)
363 * @param y: the y coordinate (relative to widget coordinates)
364 * @param keyboard_tip: whether this is a keyboard tooltip or not
365 * @param iter: a pointer to receive a Gtk::TreeIter
366 *
367 * This function is supposed to be used in a Gtk::Widget::query-tooltip
368 * signal handler for Gtk::IconView. The x, y and keyboard_tip values
369 * which are received in the signal handler, should be passed to this
370 * function without modification.
371 *
372 * The return value indicates whether there is an icon view item at the given
373 * coordinates (true) or not (false) for mouse tooltips. For keyboard
374 * tooltips the item returned will be the cursor item. When true, then the
375 * iter which has been provided will be set to point to
376 * that row and the corresponding model. x and y will always be converted
377 * to be relative to IconView's bin_window if keyboard_tooltip is false.
378 *
379 * Return value: whether or not the given tooltip context points to a item.
380 *
381 * @newin{2,12}
382 */
383 bool get_tooltip_context_iter(int& x, int& y,
384 bool keyboard_tip,
385 Gtk::TreeModel::iterator& iter);
386 _IGNORE(gtk_icon_view_get_tooltip_context)
387
388 _WRAP_METHOD(void set_tooltip_column(int column), gtk_icon_view_set_tooltip_column)
389 _WRAP_METHOD(int get_tooltip_column() const, gtk_icon_view_get_tooltip_column)
390
391 _WRAP_SIGNAL(void item_activated(const TreeModel::Path& path), item_activated)
392 _WRAP_SIGNAL(void selection_changed(), selection_changed)
393
394 /* Key binding signals */
395 _IGNORE_SIGNAL(select_all)
396 _IGNORE_SIGNAL(unselect_all)
397 _IGNORE_SIGNAL(select_cursor_item)
398 _IGNORE_SIGNAL(toggle_cursor_item)
399 _IGNORE_SIGNAL(move_cursor)
400 _IGNORE_SIGNAL(activate_cursor_item)
401
402 _WRAP_PROPERTY("pixbuf-column", int)
403 _WRAP_PROPERTY("text-column", int)
404 _WRAP_PROPERTY("markup-column", int)
405 _WRAP_PROPERTY("selection-mode", SelectionMode)
406 _WRAP_PROPERTY("item-orientation", Orientation)
407 _WRAP_PROPERTY("model", Glib::RefPtr<TreeModel>)
408 _WRAP_PROPERTY("columns", int)
409 _WRAP_PROPERTY("item-width", int)
410 _WRAP_PROPERTY("spacing", int)
411 _WRAP_PROPERTY("row-spacing", int)
412 _WRAP_PROPERTY("column-spacing", int)
413 _WRAP_PROPERTY("margin", int)
414 _WRAP_PROPERTY("reorderable", int)
415 _WRAP_PROPERTY("tooltip-column", int)
416 _WRAP_PROPERTY("item-padding", int)
417 _WRAP_PROPERTY("cell-area", Glib::RefPtr<CellArea>)
418 _WRAP_PROPERTY("activate-on-single-click", bool)
419 };
420
421 } // namespace Gtk