1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
|
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
/*
* Copyright (C) 2011-2014 Ruby-GNOME2 Project Team
* Copyright (C) 2005 Masao Mutoh
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
#include "rbgtk3private.h"
#define RG_TARGET_NAMESPACE cIconView
#define _SELF(s) (RVAL2GTKICONVIEW(s))
static ID id_model;
static ID id_select_path;
static VALUE
rg_initialize(int argc, VALUE *argv, VALUE self)
{
VALUE model;
rb_scan_args(argc, argv, "01", &model);
if (NIL_P(model)){
RBGTK_INITIALIZE(self, gtk_icon_view_new());
} else {
G_CHILD_SET(self, id_model, model);
RBGTK_INITIALIZE(self,
gtk_icon_view_new_with_model(RVAL2GTKTREEMODEL(model)));
}
return Qnil;
}
static VALUE
rg_get_path_at_pos(VALUE self, VALUE x, VALUE y)
{
return GTKTREEPATH2RVAL(gtk_icon_view_get_path_at_pos(_SELF(self), NUM2INT(x), NUM2INT(y)));
}
static void
iview_foreach_func(GtkIconView *iview, GtkTreePath *path, gpointer *func)
{
rb_funcall((VALUE)func, id_call, 2, GOBJ2RVAL(iview), GTKTREEPATH2RVAL(path));
}
static VALUE
rg_selected_each(VALUE self)
{
VALUE func = rb_block_proc();
G_RELATIVE(self, func);
gtk_icon_view_selected_foreach(_SELF(self),
(GtkIconViewForeachFunc)iview_foreach_func,
(gpointer)func);
return self;
}
#if GTK_CHECK_VERSION(3, 6, 0)
static VALUE
rg_get_cell_rect(int argc, VALUE *argv, VALUE self)
{
VALUE path, cell;
GdkRectangle rectangle;
gboolean found;
rb_scan_args(argc, argv, "11", &path, &cell);
found = gtk_icon_view_get_cell_rect(_SELF(self),
RVAL2GTKTREEPATH(path),
RVAL2GTKCELLRENDERER(cell),
&rectangle);
if (!found) {
return Qnil;
}
return GDKRECTANGLE2RVAL(&rectangle);
}
#endif
static VALUE
rg_select_path(VALUE self, VALUE path)
{
G_CHILD_SET(self, id_select_path, path);
gtk_icon_view_select_path(_SELF(self), RVAL2GTKTREEPATH(path));
return self;
}
static VALUE
rg_unselect_path(VALUE self, VALUE path)
{
G_CHILD_UNSET(self, id_select_path);
gtk_icon_view_unselect_path(_SELF(self), RVAL2GTKTREEPATH(path));
return self;
}
static VALUE
rg_path_is_selected_p(VALUE self, VALUE path)
{
return CBOOL2RVAL(gtk_icon_view_path_is_selected(_SELF(self), RVAL2GTKTREEPATH(path)));
}
static VALUE
rg_selected_items(VALUE self)
{
GList* list = gtk_icon_view_get_selected_items(_SELF(self));
VALUE ret = BOXEDGLIST2RVAL(list, GTK_TYPE_TREE_PATH);
g_list_foreach(list, (GFunc)gtk_tree_path_free, NULL);
g_list_free(list);
return ret;
}
static VALUE
rg_item_activated(VALUE self, VALUE path)
{
gtk_icon_view_item_activated(_SELF(self), RVAL2GTKTREEPATH(path));
return self;
}
static VALUE
rg_create_drag_icon(VALUE self, VALUE path)
{
return GOBJ2RVAL(gtk_icon_view_create_drag_icon(_SELF(self), RVAL2GTKTREEPATH(path)));
}
static VALUE
rg_enable_model_drag_dest(VALUE self, VALUE rbtargets, VALUE rbactions)
{
GtkIconView *icon_view = _SELF(self);
GdkDragAction actions = RVAL2GDKDRAGACTION(rbactions);
long n;
GtkTargetEntry *targets = RVAL2GTKTARGETENTRIES(rbtargets, &n);
gtk_icon_view_enable_model_drag_dest(icon_view, targets, n, actions);
g_free(targets);
return self;
}
static VALUE
rg_enable_model_drag_source(VALUE self, VALUE rbstart_button_mask, VALUE rbtargets, VALUE rbactions)
{
GtkIconView *icon_view = _SELF(self);
GdkModifierType start_button_mask = RVAL2GDKMODIFIERTYPE(rbstart_button_mask);
GdkDragAction actions = RVAL2GDKDRAGACTION(rbactions);
long n;
GtkTargetEntry *targets = RVAL2GTKTARGETENTRIES(rbtargets, &n);
gtk_icon_view_enable_model_drag_source(icon_view, start_button_mask, targets, n, actions);
g_free(targets);
return self;
}
static VALUE
rg_cursor(VALUE self)
{
GtkTreePath* path;
GtkCellRenderer* cell;
gboolean cursor_set = gtk_icon_view_get_cursor(_SELF(self), &path, &cell);
return cursor_set ? rb_assoc_new(GTKTREEPATH2RVAL(path), GOBJ2RVAL(cell)) : Qnil;
}
static VALUE
rg_get_dest_item(VALUE self, VALUE drag_x, VALUE drag_y)
{
GtkTreePath* path;
GtkIconViewDropPosition pos;
gboolean item_at_pos = gtk_icon_view_get_dest_item_at_pos(_SELF(self), NUM2INT(drag_x), NUM2INT(drag_y), &path, &pos);
return item_at_pos ? rb_assoc_new(GTKTREEPATH2RVAL(path),
GTKICONVIEWDROPPOSITION2RVAL(pos)) : Qnil;
}
static VALUE
rg_drag_dest_item(VALUE self)
{
GtkTreePath* path;
GtkIconViewDropPosition pos;
gtk_icon_view_get_drag_dest_item(_SELF(self), &path, &pos);
return rb_assoc_new(GTKTREEPATH2RVAL(path),
GTKICONVIEWDROPPOSITION2RVAL(pos));
}
static VALUE
rg_get_item(VALUE self, VALUE x, VALUE y)
{
GtkTreePath* path;
GtkCellRenderer* cell;
gboolean item_at_pos = gtk_icon_view_get_item_at_pos(_SELF(self), NUM2INT(x), NUM2INT(y), &path, &cell);
return item_at_pos ? rb_assoc_new(GTKTREEPATH2RVAL(path), GOBJ2RVAL(cell)) : Qnil;
}
static VALUE
rg_visible_range(VALUE self)
{
GtkTreePath* start_path;
GtkTreePath* end_path;
gboolean valid_paths = gtk_icon_view_get_visible_range(_SELF(self), &start_path, &end_path);
return valid_paths ? rb_assoc_new(GTKTREEPATH2RVAL(start_path),
GTKTREEPATH2RVAL(end_path)) : Qnil;
}
static VALUE
rg_scroll_to_path(VALUE self, VALUE path, VALUE use_align, VALUE row_align, VALUE col_align)
{
gtk_icon_view_scroll_to_path(_SELF(self),
RVAL2GTKTREEPATH(path),
RVAL2CBOOL(use_align),
NUM2DBL(row_align),
NUM2DBL(col_align));
return self;
}
static VALUE
rg_set_cursor(VALUE self, VALUE path, VALUE cell, VALUE start_editing)
{
gtk_icon_view_set_cursor(_SELF(self),
RVAL2GTKTREEPATH(path),
NIL_P(cell) ? NULL : RVAL2GTKCELLRENDERER(cell),
RVAL2CBOOL(start_editing));
return self;
}
static VALUE
rg_set_drag_dest_item(VALUE self, VALUE path, VALUE pos)
{
gtk_icon_view_set_drag_dest_item(_SELF(self),
NIL_P(path) ? NULL : RVAL2GTKTREEPATH(path),
RVAL2GTKICONVIEWDROPPOSITION(pos));
return self;
}
static VALUE
rg_unset_model_drag_dest(VALUE self)
{
gtk_icon_view_unset_model_drag_dest(_SELF(self));
return self;
}
static VALUE
rg_unset_model_drag_source(VALUE self)
{
gtk_icon_view_unset_model_drag_source(_SELF(self));
return self;
}
void
Init_gtk_iconview(VALUE mGtk)
{
VALUE RG_TARGET_NAMESPACE = G_DEF_CLASS(GTK_TYPE_ICON_VIEW, "IconView", mGtk);
id_model = rb_intern("model");
id_select_path = rb_intern("select_path");
RG_DEF_METHOD(initialize, -1);
RG_DEF_METHOD(get_path_at_pos, 2);
RG_DEF_ALIAS("get_path", "get_path_at_pos");
RG_DEF_METHOD(selected_each, 0);
#if GTK_CHECK_VERSION(3, 6, 0)
RG_DEF_METHOD(get_cell_rect, -1);
#endif
RG_DEF_METHOD(select_path, 1);
RG_DEF_METHOD(unselect_path, 1);
RG_DEF_METHOD_P(path_is_selected, 1);
RG_DEF_METHOD(selected_items, 0);
RG_DEF_METHOD(item_activated, 1);
RG_DEF_METHOD(create_drag_icon, 1);
RG_DEF_METHOD(enable_model_drag_dest, 2);
RG_DEF_METHOD(enable_model_drag_source, 3);
RG_DEF_METHOD(cursor, 0);
RG_DEF_METHOD(get_dest_item, 2);
RG_DEF_METHOD(drag_dest_item, 0);
RG_DEF_METHOD(get_item, 2);
RG_DEF_METHOD(visible_range, 0);
RG_DEF_METHOD(scroll_to_path, 4);
RG_DEF_METHOD(set_cursor, 3);
RG_DEF_METHOD(set_drag_dest_item, 2);
RG_DEF_METHOD(unset_model_drag_dest, 0);
RG_DEF_METHOD(unset_model_drag_source, 0);
G_DEF_CLASS(GTK_TYPE_ICON_VIEW_DROP_POSITION, "Type", RG_TARGET_NAMESPACE);
}
|