Add notes files on signals and parameters

parent 6f52855d
-*- org -*-
* class_init() does this:
props[PROP_ICON_NAME] =
g_param_spec_string ("icon-name",
P_("Icon Name"),
P_("The name of the icon used to automatically populate the button"),
NULL,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
props[PROP_FOO] =
g_param_spec_blah (...);
g_object_class_install_properties (gobject_class, LAST_PROP, props);
Those props[N] remain for the duration of the program for static
types. The code uses them in ::set_property() and ::get_property()
* This last function is a shortcut for:
void
g_object_class_install_property (GObjectClass *class,
guint property_id,
GParamSpec *pspec)
property_id > 0, plus extra validation inside the pspec
* Note that properties are numbered starting from 1 (this is from GtkButton):
enum {
PROP_0,
PROP_LABEL,
PROP_RELIEF,
PROP_USE_UNDERLINE,
PROP_ICON_NAME,
/* actionable properties */
PROP_ACTION_NAME,
PROP_ACTION_TARGET,
LAST_PROP = PROP_ACTION_NAME
};
* Most parameters have default values; scalars have min/max values.
* Complex parameters: arrays (gtype for element type), enums, flags,
objects, boxed values.
* Vala syntax: https://wiki.gnome.org/Projects/Vala/PropertiesSample
public class PropertyDemo : Object {
/* Property-backing fields */
private string _name;
private string _read_only;
/* Properties */
public string automatic { get; set; }
public string name {
get { return _name; }
set { _name = value; }
}
public string read_only {
get { return _read_only; }
}
public PropertyDemo (string name) {
this.automatic = "InitialAutomatic"; // is this translated to being the default value?
_name = name;
_read_only = "InitialReadOnly";
}
}
** More Vala syntax
public int construct_only_prop {
construct {
_c_o_prop = value;
}
get {
return _c_o_prop;
}
}
public int construct_get_set_prop {
construct set {
_c_g_s_prop = value;
}
get {
return _c_g_s_prop;
}
}
// this bit is from https://wiki.gnome.org/Projects/Vala/Tutorial#Properties
[Description(nick = "age in years", blurb = "This is the person's age in years")]
public int age { get; set; default = 32; }
/* Creation method */
public MyConstructor (int a, int b, int c) {
Object (construct_only_prop: a, construct_get_set_prop: b); // construct superclass
this.get_set_prop = c;
}
/* Construct block, gets called after all properties have been set. This uses GObjectClass::constructor */
construct {
stdout.printf ("++++++++++ construct block +++++++++++++++\n\n");
this.get_set_prop = 5;
stdout.printf ("++++++++++ end of construct block ++++++++\n\n");
}
myobj = g_object_new (G_TYPE_SOME_CLASS,
"prop1", oasidjf,
);
* Vala examples at https://github.com/aruiz/rust-vala
-*- org -*-
* From https://wiki.gnome.org/Projects/Vala/Tutorial#Signals
public class Test : GLib.Object {
public signal void sig_1(int a);
public static int main(string[] args) {
Test t1 = new Test();
t1.sig_1.connect((t, a) => {
stdout.printf("%d\n", a);
});
t1.sig_1(5);
return 0;
}
}
* Signal flags:
[Signal (action=true, detailed=true, run=true, no_recurse=true, no_hooks=true)]
public signal void sig_1 ();
* Prototypes
guint g_signal_newv (const gchar *signal_name,
GType itype,
GSignalFlags signal_flags,
GClosure *class_closure,
GSignalAccumulator accumulator,
gpointer accu_data,
GSignalCMarshaller c_marshaller,
GType return_type,
guint n_params,
GType *param_types);
GLIB_AVAILABLE_IN_ALL
guint g_signal_new (const gchar *signal_name,
GType itype,
GSignalFlags signal_flags,
guint class_offset,
GSignalAccumulator accumulator,
gpointer accu_data,
GSignalCMarshaller c_marshaller,
GType return_type,
guint n_params,
...);
GLIB_AVAILABLE_IN_ALL
guint g_signal_new_class_handler (const gchar *signal_name,
GType itype,
GSignalFlags signal_flags,
GCallback class_handler,
GSignalAccumulator accumulator,
gpointer accu_data,
GSignalCMarshaller c_marshaller,
GType return_type,
guint n_params,
...) {
return g_signal_new_valist (signal_name, itype, signal_flags,
class_handler ? g_cclosure_new (class_handler, NULL, NULL) : NULL,
accumulator, accu_data, c_marshaller,
return_type, n_params, args);
}
* Flags
/**
* GSignalFlags:
* @G_SIGNAL_RUN_FIRST: Invoke the object method handler in the first emission stage.
* @G_SIGNAL_RUN_LAST: Invoke the object method handler in the third emission stage.
* @G_SIGNAL_RUN_CLEANUP: Invoke the object method handler in the last emission stage.
* @G_SIGNAL_NO_RECURSE: Signals being emitted for an object while currently being in
* emission for this very object will not be emitted recursively,
* but instead cause the first emission to be restarted.
* @G_SIGNAL_DETAILED: This signal supports "::detail" appendices to the signal name
* upon handler connections and emissions.
* @G_SIGNAL_ACTION: Action signals are signals that may freely be emitted on alive
* objects from user code via g_signal_emit() and friends, without
* the need of being embedded into extra code that performs pre or
* post emission adjustments on the object. They can also be thought
* of as object methods which can be called generically by
* third-party code.
* @G_SIGNAL_NO_HOOKS: No emissions hooks are supported for this signal.
* @G_SIGNAL_MUST_COLLECT: Varargs signal emission will always collect the
* arguments, even if there are no signal handlers connected. Since 2.30.
* @G_SIGNAL_DEPRECATED: The signal is deprecated and will be removed
* in a future version. A warning will be generated if it is connected while
* running with G_ENABLE_DIAGNOSTIC=1. Since 2.32.
*
* The signal flags are used to specify a signal's behaviour, the overall
* signal description outlines how especially the RUN flags control the
* stages of a signal emission.
*/
typedef enum
{
G_SIGNAL_RUN_FIRST = 1 << 0,
G_SIGNAL_RUN_LAST = 1 << 1,
G_SIGNAL_RUN_CLEANUP = 1 << 2,
G_SIGNAL_NO_RECURSE = 1 << 3,
G_SIGNAL_DETAILED = 1 << 4,
G_SIGNAL_ACTION = 1 << 5,
G_SIGNAL_NO_HOOKS = 1 << 6,
G_SIGNAL_MUST_COLLECT = 1 << 7,
G_SIGNAL_DEPRECATED = 1 << 8
} GSignalFlags;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment