/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */ /* * Copyright (C) 2011 Ruby-GNOME2 Project Team * Copyright (C) 2002,2003 Ruby-GNOME2 Project Team * Copyright (C) 1998-2000 Yukihiro Matsumoto, * Daisuke Kanda, * Hiroshi Igarashi * * 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 cAccelGroup #define _SELF(w) RVAL2GTKACCELGROUP(w) #define RVAL2MOD(mods) (NIL_P(mods) ? 0 : RVAL2GDKMODIFIERTYPE(mods)) static VALUE rg_initialize(VALUE self) { G_INITIALIZE(self, gtk_accel_group_new()); return Qnil; } static VALUE rg_connect(int argc, VALUE *argv, VALUE self) { VALUE key, mods, flags, path, closure; GClosure *rclosure; if (argc > 2){ rb_scan_args(argc, argv, "31", &key, &mods, &flags, &closure); if (NIL_P(closure)){ rclosure = g_rclosure_new(rb_block_proc(), Qnil, NULL); } else { rclosure = RVAL2GCLOSURE(closure); } g_rclosure_attach(rclosure, self); gtk_accel_group_connect(_SELF(self), NUM2UINT(key), RVAL2MOD(mods), RVAL2GTKACCELFLAGS(flags), rclosure); } else { rb_scan_args(argc, argv, "11", &path, &closure); if (NIL_P(closure)){ rclosure = g_rclosure_new(rb_block_proc(), Qnil, NULL); } else { rclosure = RVAL2GCLOSURE(closure); } g_rclosure_attach(rclosure, self); gtk_accel_group_connect_by_path(_SELF(self), RVAL2CSTR(path), rclosure); } return self; } static VALUE rg_disconnect_key(VALUE self, VALUE key, VALUE mods) { return CBOOL2RVAL(gtk_accel_group_disconnect_key(_SELF(self), NUM2UINT(key), RVAL2MOD(mods))); } static VALUE rg_query(VALUE self, VALUE key, VALUE mods) { GtkAccelGroupEntry *entries; guint n_entries; guint cnt; VALUE result; entries = gtk_accel_group_query(_SELF(self), NUM2UINT(key), RVAL2MOD(mods), &n_entries); if(n_entries == 0){ return Qnil; } else{ result = rb_ary_new2(n_entries); for(cnt=0; cnt