1a05542005-07-28Martin Nilsson /* -*- C -*- */ class GTK2.AccelGroup; inherit G.Object; //! An AccelGroup stores keybindings. //! A group is automatically created by W(MenuFactory) //! //! NOIMG signal accel_activate; signal accel_changed; void create() //! Create a new accelerator group {
ba9e802006-02-27Martin Stjernholm  pgtk2_verify_setup(); pgtk2_verify_not_inited();
3d76632005-11-03Lance Dillon  { GtkAccelGroup *ga; ga=gtk_accel_group_new(); THIS->obj=G_OBJECT(ga); }
1a05542005-07-28Martin Nilsson /* add_ref(fp->current_object); one extra ref... No, not really */
ba9e802006-02-27Martin Stjernholm  pgtk2_pop_n_elems(args); pgtk2__init_this_object();
1a05542005-07-28Martin Nilsson } %{
ba9e802006-02-27Martin Stjernholm int pgtk2_accel_group_activate_key_callback(GtkAccelGroup *accel_group,
1a05542005-07-28Martin Nilsson  GObject *acceleratable, guint accel_key, GdkModifierType accel_mods, struct signal_data *d) { int res; push_svalue(&d->args);
3d76632005-11-03Lance Dillon  push_gobject(accel_group); push_gobject(acceleratable);
1a05542005-07-28Martin Nilsson  push_int(accel_key); push_int(accel_mods);
bdcd552016-03-03Henrik Grubbström (Grubba)  safe_apply_svalue(&d->cb, 5, 1);
1a05542005-07-28Martin Nilsson  res=Pike_sp[-1].u.integer; pop_stack(); return res; } %} void connect(int accel_key, int accel_mods, int accel_flags, function cb, mixed user_data) //! Installs an accelerator in this group. {
ba9e802006-02-27Martin Stjernholm  pgtk2_verify_inited();
1a05542005-07-28Martin Nilsson  { gint accel_key; GdkModifierType accel_mods; GtkAccelFlags accel_flags; GClosure *closure; struct signal_data *sd; if (args<5) Pike_error("Too few arguments, 5 required, got %d\n",args); accel_key=(gint)PGTK_GETINT(&Pike_sp[0-args]); accel_mods=(GdkModifierType)PGTK_GETINT(&Pike_sp[1-args]); accel_flags=(GtkAccelFlags)PGTK_GETINT(&Pike_sp[2-args]); sd=(struct signal_data *)g_malloc(sizeof(struct signal_data)); if (sd==NULL) SIMPLE_OUT_OF_MEMORY_ERROR("connect",sizeof(struct signal_data)); assign_svalue_no_free(&sd->cb,Pike_sp+3-args); assign_svalue_no_free(&sd->args,Pike_sp+4-args);
b4a3852013-03-08Chris Angelico  closure=g_cclosure_new(G_CALLBACK(pgtk2_accel_group_activate_key_callback),
ba9e802006-02-27Martin Stjernholm  sd,(GClosureNotify)pgtk2_free_signal_data);
1a05542005-07-28Martin Nilsson  gtk_accel_group_connect(GTK_ACCEL_GROUP(THIS->obj),accel_key, accel_mods,accel_flags,closure); } RETURN_THIS(); } void connect_by_path(string accel_path, function cb, mixed user_data) //! Installs an accelerator in this group, using an accelerator path to look //! up the appropriate key and modifiers. {
ba9e802006-02-27Martin Stjernholm  pgtk2_verify_inited();
1a05542005-07-28Martin Nilsson  { const gchar *accel_path; struct signal_data *sd; GClosure *closure; if (args<3) Pike_error("Too few arguments, 3 required, got %d\n",args); accel_path=PGTK_GETSTR(&Pike_sp[-args]); sd=(struct signal_data *)g_malloc(sizeof(struct signal_data)); if (sd==NULL) SIMPLE_OUT_OF_MEMORY_ERROR("connect_by_path",sizeof(struct signal_data)); assign_svalue_no_free(&sd->cb,Pike_sp+1-args); assign_svalue_no_free(&sd->args,Pike_sp+2-args);
ba9e802006-02-27Martin Stjernholm  closure=g_cclosure_new(G_CALLBACK(pgtk2_signal_func_wrapper), sd,(GClosureNotify)pgtk2_free_signal_data);
1a05542005-07-28Martin Nilsson  gtk_accel_group_connect_by_path(GTK_ACCEL_GROUP(THIS->obj),accel_path, closure); } RETURN_THIS(); } void disconnect(int accel_key, int accel_mods) //! Removes an accelerator previously installed. {
ba9e802006-02-27Martin Stjernholm  pgtk2_verify_inited();
1a05542005-07-28Martin Nilsson  {
cac4202005-12-17Marcus Comstedt  INT_TYPE accel_key; INT_TYPE accel_mods;
96f5f42018-08-05Martin Nilsson  get_all_args(NULL,args,"%i%i",&accel_key,&accel_mods);
1a05542005-07-28Martin Nilsson  gtk_accel_group_disconnect_key(GTK_ACCEL_GROUP(THIS->obj), accel_key,accel_mods); } RETURN_THIS(); } void lock(); //! Locks the group. void unlock(); //! Undoes the last call to lock().