nsresult nsAlertsIconListener::ShowAlert(GdkPixbuf* aPixbuf) { mNotification = notify_notification_new(mAlertTitle.get(), mAlertText.get(), nullptr, nullptr); if (!mNotification) return NS_ERROR_OUT_OF_MEMORY; if (aPixbuf) notify_notification_set_icon_from_pixbuf(mNotification, aPixbuf); NS_ADDREF(this); if (mAlertHasAction) { // What we put as the label doesn't matter here, if the action // string is "default" then that makes the entire bubble clickable // rather than creating a button. notify_notification_add_action(mNotification, "default", "Activate", notify_action_cb, this, nullptr); } // Fedora 10 calls NotifyNotification "closed" signal handlers with a // different signature, so a marshaller is used instead of a C callback to // get the user_data (this) in a parseable format. |closure| is created // with a floating reference, which gets sunk by g_signal_connect_closure(). GClosure* closure = g_closure_new_simple(sizeof(GClosure), this); g_closure_set_marshal(closure, notify_closed_marshal); mClosureHandler = g_signal_connect_closure(mNotification, "closed", closure, FALSE); gboolean result = notify_notification_show(mNotification, nullptr); return result ? NS_OK : NS_ERROR_FAILURE; }
/** * pyg_closure_new: * callback: a Python callable object * extra_args: a tuple of extra arguments, or None/NULL. * swap_data: an alternative python object to pass first. * * Creates a GClosure wrapping a Python callable and optionally a set * of additional function arguments. This is needed to attach python * handlers to signals, for instance. * * Returns: the new closure. */ GClosure * pyg_closure_new(PyObject *callback, PyObject *extra_args, PyObject *swap_data) { GClosure *closure; g_return_val_if_fail(callback != NULL, NULL); closure = g_closure_new_simple(sizeof(PyGClosure), NULL); g_closure_add_invalidate_notifier(closure, NULL, pyg_closure_invalidate); g_closure_set_marshal(closure, pyg_closure_marshal); Py_INCREF(callback); ((PyGClosure *)closure)->callback = callback; if (extra_args && extra_args != Py_None) { Py_INCREF(extra_args); if (!PyTuple_Check(extra_args)) { PyObject *tmp = PyTuple_New(1); PyTuple_SetItem(tmp, 0, extra_args); extra_args = tmp; } ((PyGClosure *)closure)->extra_args = extra_args; } if (swap_data) { Py_INCREF(swap_data); ((PyGClosure *)closure)->swap_data = swap_data; closure->derivative_flag = TRUE; } return closure; }
static inline GClosure *createCppClosure(ClosureDataBase *closureData) { GClosure *closure = g_closure_new_simple(sizeof(GClosure), closureData); g_closure_set_marshal(closure, &c_marshaller); g_closure_add_finalize_notifier(closure, NULL, &closureDestroyNotify); g_closure_ref(closure); g_closure_sink(closure); return closure; }
/** * g_source_set_dummy_callback: * @source: the source * * Sets a dummy callback for @source. The callback will do nothing, and * if the source expects a #gboolean return value, it will return %TRUE. * (If the source expects any other type of return value, it will return * a 0/%NULL value; whatever g_value_init() initializes a #GValue to for * that type.) * * If the source is not one of the standard GLib types, the * @closure_callback and @closure_marshal fields of the #GSourceFuncs * structure must have been filled in with pointers to appropriate * functions. */ void g_source_set_dummy_callback (GSource *source) { GClosure *closure; closure = g_closure_new_simple (sizeof (GClosure), NULL); g_closure_set_meta_marshal (closure, NULL, dummy_closure_marshal); g_source_set_closure (source, closure); }
/* Creates a new closure which invokes callback_func with user_data as the last parameter. 创建GCClosure, 并初始化 但仍返回GClosure */ GClosure* g_cclosure_new (GCallback callback_func, gpointer user_data, GClosureNotify destroy_data) { closure = g_closure_new_simple (sizeof (GCClosure), user_data); g_closure_add_finalize_notifier (closure, user_data, destroy_data); ((GCClosure*) closure)->callback = (gpointer) callback_func; }
Gtk$GObject$Closure_t *_from_ref(Std$Object_t **Function) { ref_closure_t *Handle = g_closure_new_simple(sizeof(ref_closure_t), 0); Handle->Function = Function; g_closure_set_marshal(Handle, __marshal_ref); Gtk$GObject$Closure_t *Closure = new(Gtk$GObject$Closure_t); Closure->Type = T; Closure->Handle = Handle; Handle->Closure = Closure; return Closure; };
Gtk$GObject$Closure_t *_from_val(Std$Object_t *Function) { val_closure_t *Handle = (val_closure_t *)g_closure_new_simple(sizeof(val_closure_t), 0); Handle->Function = Function; g_closure_set_marshal((GClosure *)Handle, (GClosureMarshal)__marshal_val); Gtk$GObject$Closure_t *Closure = new(Gtk$GObject$Closure_t); Closure->Type = T; Closure->Handle = (GClosure *)Handle; Handle->Closure = Closure; return Closure; };
/** * pyg_signal_class_closure_get: * * Returns the GClosure used for the class closure of signals. When * called, it will invoke the method do_signalname (for the signal * "signalname"). * * Returns: the closure. */ GClosure * pyg_signal_class_closure_get(void) { static GClosure *closure; if (closure == NULL) { closure = g_closure_new_simple(sizeof(GClosure), NULL); g_closure_set_marshal(closure, pyg_signal_class_closure_marshal); g_closure_ref(closure); g_closure_sink(closure); } return closure; }
GClosure* gjs_closure_new(JSContext *context, JSObject *callable, const char *description, gboolean root_function) { Closure *c; c = (Closure*) g_closure_new_simple(sizeof(Closure), NULL); c->runtime = JS_GetRuntime(context); /* The saved context is used for lifetime management, so that the closure will * be torn down with the context that created it. The context could be attached to * the default context of the runtime using if we wanted the closure to survive * the context that created it. */ c->context = context; JS_BeginRequest(context); c->obj = callable; c->unref_on_global_object_finalized = FALSE; GJS_INC_COUNTER(closure); /* the finalize notifier right now is purely to track the counter * of how many closures are alive. */ g_closure_add_finalize_notifier(&c->base, NULL, closure_finalized); if (root_function) { /* Fully manage closure lifetime if so asked */ gjs_keep_alive_add_global_child(context, global_context_finalized, c->obj, c); g_closure_add_invalidate_notifier(&c->base, NULL, closure_invalidated); } else { /* Only mark the closure as invalid if memory is managed outside (i.e. by object.c for signals) */ g_closure_add_invalidate_notifier(&c->base, NULL, closure_set_invalid); } gjs_debug_closure("Create closure %p which calls object %p '%s'", c, c->obj, description); JS_EndRequest(context); return &c->base; }
/** * g_cclosure_new: (skip) * @callback_func: the function to invoke * @user_data: user data to pass to @callback_func * @destroy_data: destroy notify to be called when @user_data is no longer used * * Creates a new closure which invokes @callback_func with @user_data as * the last parameter. * * Returns: a new #GCClosure */ GClosure* g_cclosure_new (GCallback callback_func, gpointer user_data, GClosureNotify destroy_data) { GClosure *closure; g_return_val_if_fail (callback_func != NULL, NULL); closure = g_closure_new_simple (sizeof (GCClosure), user_data); if (destroy_data) g_closure_add_finalize_notifier (closure, user_data, destroy_data); ((GCClosure*) closure)->callback = (gpointer) callback_func; return closure; }
static inline GClosure* mgtk_closure_new(gpointer callback_id) { GClosure *closure; /* printf("register id = %i\n",(int) callback_id); */ closure = g_closure_new_simple(sizeof(GClosure), callback_id); g_closure_set_marshal (closure, mgtk_callback_dispatch); g_closure_add_finalize_notifier (closure, callback_id, mgtk_callback_destroy); return closure; }
GClosure * gtk2hs_closure_new(HsStablePtr callback) { GClosure *closure; WHEN_DEBUG(g_debug("gtk2hs_closure_new: enter, callback=%p", callback)); closure = g_closure_new_simple(sizeof(Gtk2HsClosure), NULL); /* TODO: check if we should be using invalidate or finalise notifier */ g_closure_add_invalidate_notifier(closure, NULL, gtk2hs_closure_invalidate); g_closure_set_marshal(closure, gtk2hs_closure_marshal); ((Gtk2HsClosure *)closure)->callback = callback; WHEN_DEBUG(g_debug("gtk2hs_closure_new: leave")); return closure; }
GClosure * pygi_signal_closure_new (PyGObject *instance, GType g_type, const gchar *signal_name, PyObject *callback, PyObject *extra_args, PyObject *swap_data) { GClosure *closure = NULL; PyGISignalClosure *pygi_closure = NULL; GISignalInfo *signal_info = NULL; g_return_val_if_fail(callback != NULL, NULL); signal_info = _pygi_lookup_signal_from_g_type (g_type, signal_name); if (signal_info == NULL) return NULL; closure = g_closure_new_simple(sizeof(PyGISignalClosure), NULL); g_closure_add_invalidate_notifier(closure, NULL, pygi_signal_closure_invalidate); g_closure_set_marshal(closure, pygi_signal_closure_marshal); pygi_closure = (PyGISignalClosure *)closure; pygi_closure->signal_info = signal_info; Py_INCREF(callback); pygi_closure->pyg_closure.callback = callback; if (extra_args != NULL && extra_args != Py_None) { Py_INCREF(extra_args); if (!PyTuple_Check(extra_args)) { PyObject *tmp = PyTuple_New(1); PyTuple_SetItem(tmp, 0, extra_args); extra_args = tmp; } pygi_closure->pyg_closure.extra_args = extra_args; } if (swap_data) { Py_INCREF(swap_data); pygi_closure->pyg_closure.swap_data = swap_data; closure->derivative_flag = TRUE; } return closure; }
void terminal_accels_init (void) { guint i, j; settings_keybindings = g_settings_new (CONF_KEYS_SCHEMA); g_signal_connect (settings_keybindings, "changed", G_CALLBACK(keys_change_notify), NULL); gsettings_key_to_entry = g_hash_table_new (g_str_hash, g_str_equal); notification_group = gtk_accel_group_new (); for (i = 0; i < G_N_ELEMENTS (all_entries); ++i) { for (j = 0; j < all_entries[i].n_elements; ++j) { KeyEntry *key_entry; key_entry = &(all_entries[i].key_entry[j]); g_hash_table_insert (gsettings_key_to_entry, (gpointer) key_entry->gsettings_key, key_entry); key_entry->closure = g_closure_new_simple (sizeof (GClosure), key_entry); g_closure_ref (key_entry->closure); g_closure_sink (key_entry->closure); gtk_accel_group_connect_by_path (notification_group, I_(key_entry->accel_path), key_entry->closure); keys_change_notify (settings_keybindings, key_entry->gsettings_key, NULL); } } g_signal_connect (notification_group, "accel-changed", G_CALLBACK (accel_changed_callback), NULL); }
GClosure* g_rclosure_new(VALUE callback_proc, VALUE extra_args, GValToRValSignalFunc g2r_func) { GRClosure* closure; closure = (GRClosure*)g_closure_new_simple(sizeof(GRClosure), NULL); closure->count = 1; closure->g2r_func = g2r_func; closure->objects = NULL; closure->callback = callback_proc; closure->extra_args = extra_args; closure->rb_holder = Data_Wrap_Struct(rb_cData, gr_closure_holder_mark, gr_closure_holder_free, closure); closure->tag[0] = '\0'; g_closure_set_marshal((GClosure*)closure, &rclosure_marshal); g_closure_add_invalidate_notifier((GClosure*)closure, NULL, &rclosure_invalidate); return (GClosure*)closure; }
/** * Create one of our custom GClosure subclasses. To save us having to export * it, however, we just return the GClosure* that it extends. */ GClosure* bindings_java_closure_new ( JNIEnv* env, jobject handler, jclass receiver, const gchar* name, guint id ) { GClosure* closure; BindingsJavaClosure* bjc; GSignalQuery info; GString* buf; guint i; gchar* methodName; gchar* methodSignature; /* * First we allocate the closure and do the footwork to tell it what * its marshaller is */ closure = g_closure_new_simple(sizeof(BindingsJavaClosure), NULL); g_closure_add_finalize_notifier(closure, NULL, bindings_java_closure_destroy); g_closure_set_marshal(closure, bindings_java_marshaller); bjc = (BindingsJavaClosure*) closure; /* * And now we begin the legwork of figuring out what the methodID of * the callback to be invoked is and caching that in the closure. We * get the GSignalQuery data for the specified signal and then use that * to formulate a string that can be use to lookup the method. */ g_signal_query(id, &info); switch(G_TYPE_FUNDAMENTAL(info.return_type)) { case G_TYPE_BOOLEAN: bjc->returnType = 'Z'; break; case G_TYPE_INT: bjc->returnType = 'I'; break; case G_TYPE_ENUM: bjc->returnType = 'E'; break; case G_TYPE_STRING: /* * Strings are encoded as java.lang.String objects in signatures, * so we use the object type marker for gchar* (only). */ bjc->returnType = 'L'; break; case G_TYPE_NONE: bjc->returnType = 'V'; break; default: g_critical("Don't know what to do with signal return type %s", g_type_name(info.return_type)); return NULL; } /* * the name of the methods we invoke is algorithmic: "receiveName", * where Name is a PascalCase version of the signal name we were * passed in. */ buf = g_string_new("receive"); gchar** tokens = g_strsplit_set(name, "_-:", -1); for (i = 0; i < g_strv_length(tokens); i++) { gchar* token = tokens[i]; if (token[0] == '\0') { // skip past :: which splits signal name from "detail" continue; } gchar first = g_unichar_toupper(token[0]); g_string_append_c(buf, first); token++; g_string_append(buf, token); } methodName = buf->str; g_string_free(buf, FALSE); g_strfreev(tokens); /* * And here is the tricky bit: formulate the method signature that goes * along with this signal. A method of the signature * * boolean method(int, long, String) * * has a JNI encoding of * * (IJLjava/util/String;)Z */ buf = g_string_new("(Lorg/gnome/glib/Signal;J"); // add the signature for each parameter type for(i = 0; i < info.n_params; i++) { g_string_append(buf, bindings_java_typeToSignature(info.param_types[i])); } // and the return type g_string_append(buf, ")"); g_string_append(buf, bindings_java_typeToSignature(info.return_type)); methodSignature = buf->str; g_string_free(buf, FALSE); /* * Now at last we can lookup the method ID */ // jclass CANDIDATE = (*env)->FindClass(env, "org/gnome/gtk/GtkWidget"); // if ((*env)->IsSameObject(env, CANDIDATE, receiver)) { // g_debug("Received a GtkWidget"); // } bjc->receiver = receiver; bjc->method = (*env)->GetStaticMethodID(env, bjc->receiver, methodName, methodSignature); // g_debug("Looking for\nJava method %s\nwith signature %s\nin class %s\nto handle signal %s\n", // methodName, methodSignature, "FIXME", g_signal_name(id)); // clean up g_free(methodName); g_free(methodSignature); // and check for error if (bjc->method == NULL) { // Exception already thrown by GetMethodID return NULL; } /* * Set the reference so that the marshaller can find the Signal instance. */ bjc->handler = (*env)->NewWeakGlobalRef(env, handler); /* * And we're done! */ return closure; }
for ( ; i < n_param_values; i++) { zval_ptr_dtor(params[i]); efree(params[i]); } efree(params); phpg_handle_marshaller_exception(TSRMLS_C); } PHP_GTK_API GClosure* phpg_closure_new(zval *callback, zval *user_args, int connect_type, zval *replace_object TSRMLS_DC) { GClosure *closure; phpg_closure_t *phpg_closure; phpg_return_val_if_fail(callback != NULL, NULL); closure = g_closure_new_simple(sizeof(phpg_closure_t), NULL); g_closure_add_invalidate_notifier(closure, NULL, phpg_closure_invalidate); g_closure_set_marshal(closure, phpg_closure_marshal); phpg_closure = (phpg_closure_t *) closure; zval_add_ref(&callback); phpg_closure->callback = callback; phpg_closure->src_filename = estrdup(zend_get_executed_filename(TSRMLS_C)); phpg_closure->src_lineno = zend_get_executed_lineno(TSRMLS_C); #ifdef ZTS phpg_closure->TSRMLS_C = TSRMLS_C; #endif if (user_args) { zval_add_ref(&user_args); if (Z_TYPE_P(user_args) != IS_ARRAY) {