1 /* 2 * Distributed under the Boost Software License, Version 1.0. 3 * (See accompanying file LICENSE_1_0.txt or copy at 4 * http://www.boost.org/LICENSE_1_0.txt) 5 */ 6 module gobject.gparam; 7 8 import gobject.gvalue; 9 import gobject.gtype; 10 import glib; 11 12 // /* --- standard type macros --- */ 13 // /** 14 // * G_TYPE_IS_PARAM: 15 // * @type: a #GType ID 16 // * 17 // * Checks whether @type "is a" %G_TYPE_PARAM. 18 // */ 19 // #define G_TYPE_IS_PARAM(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_PARAM) 20 // /** 21 // * G_PARAM_SPEC: 22 // * @pspec: a valid #GParamSpec 23 // * 24 // * Casts a derived #GParamSpec object (e.g. of type #GParamSpecInt) into 25 // * a #GParamSpec object. 26 // */ 27 // #define G_PARAM_SPEC(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM, GParamSpec)) 28 // /** 29 // * G_IS_PARAM_SPEC: 30 // * @pspec: a #GParamSpec 31 // * 32 // * Checks whether @pspec "is a" valid #GParamSpec structure of type %G_TYPE_PARAM 33 // * or derived. 34 // */ 35 // #if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_42 36 // #define G_IS_PARAM_SPEC(pspec) (G_TYPE_CHECK_INSTANCE_FUNDAMENTAL_TYPE ((pspec), G_TYPE_PARAM)) 37 // #else 38 // #define G_IS_PARAM_SPEC(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM)) 39 // #endif 40 // /** 41 // * G_PARAM_SPEC_CLASS: 42 // * @pclass: a valid #GParamSpecClass 43 // * 44 // * Casts a derived #GParamSpecClass structure into a #GParamSpecClass structure. 45 // */ 46 // #define G_PARAM_SPEC_CLASS(pclass) (G_TYPE_CHECK_CLASS_CAST ((pclass), G_TYPE_PARAM, GParamSpecClass)) 47 // /** 48 // * G_IS_PARAM_SPEC_CLASS: 49 // * @pclass: a #GParamSpecClass 50 // * 51 // * Checks whether @pclass "is a" valid #GParamSpecClass structure of type 52 // * %G_TYPE_PARAM or derived. 53 // */ 54 // #define G_IS_PARAM_SPEC_CLASS(pclass) (G_TYPE_CHECK_CLASS_TYPE ((pclass), G_TYPE_PARAM)) 55 // /** 56 // * G_PARAM_SPEC_GET_CLASS: 57 // * @pspec: a valid #GParamSpec 58 // * 59 // * Retrieves the #GParamSpecClass of a #GParamSpec. 60 // */ 61 // #define G_PARAM_SPEC_GET_CLASS(pspec) (G_TYPE_INSTANCE_GET_CLASS ((pspec), G_TYPE_PARAM, GParamSpecClass)) 62 // 63 // 64 // /* --- convenience macros --- */ 65 // /** 66 // * G_PARAM_SPEC_TYPE: 67 // * @pspec: a valid #GParamSpec 68 // * 69 // * Retrieves the #GType of this @pspec. 70 // */ 71 // #define G_PARAM_SPEC_TYPE(pspec) (G_TYPE_FROM_INSTANCE (pspec)) 72 // /** 73 // * G_PARAM_SPEC_TYPE_NAME: 74 // * @pspec: a valid #GParamSpec 75 // * 76 // * Retrieves the #GType name of this @pspec. 77 // */ 78 // #define G_PARAM_SPEC_TYPE_NAME(pspec) (g_type_name (G_PARAM_SPEC_TYPE (pspec))) 79 // /** 80 // * G_PARAM_SPEC_VALUE_TYPE: 81 // * @pspec: a valid #GParamSpec 82 // * 83 // * Retrieves the #GType to initialize a #GValue for this parameter. 84 // */ 85 // #define G_PARAM_SPEC_VALUE_TYPE(pspec) (G_PARAM_SPEC (pspec)->value_type) 86 // /** 87 // * G_VALUE_HOLDS_PARAM: 88 // * @value: a valid #GValue structure 89 // * 90 // * Checks whether the given #GValue can hold values derived from type %G_TYPE_PARAM. 91 // * 92 // * Returns: %TRUE on success. 93 // */ 94 // #define G_VALUE_HOLDS_PARAM(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_PARAM)) 95 // 96 97 enum GParamFlags 98 { 99 G_PARAM_READABLE = 1 << 0, 100 G_PARAM_WRITABLE = 1 << 1, 101 G_PARAM_READWRITE = (G_PARAM_READABLE | G_PARAM_WRITABLE), 102 G_PARAM_CONSTRUCT = 1 << 2, 103 G_PARAM_CONSTRUCT_ONLY = 1 << 3, 104 G_PARAM_LAX_VALIDATION = 1 << 4, 105 G_PARAM_STATIC_NAME = 1 << 5, 106 G_PARAM_STATIC_NICK = 1 << 6, 107 G_PARAM_STATIC_BLURB = 1 << 7, 108 /* User defined flags go here */ 109 G_PARAM_EXPLICIT_NOTIFY = 1 << 30, 110 G_PARAM_DEPRECATED = 1 << 31 111 } 112 113 114 enum G_PARAM_STATIC_STRINGS = GParamFlags.G_PARAM_STATIC_NAME | 115 GParamFlags.G_PARAM_STATIC_NICK | 116 GParamFlags.G_PARAM_STATIC_BLURB; 117 118 119 enum G_PARAM_MASK = 0x000000ff; 120 /** 121 * G_PARAM_USER_SHIFT: 122 * 123 * Minimum shift count to be used for user defined flags, to be stored in 124 * #GParamSpec.flags. The maximum allowed is 10. 125 */ 126 enum G_PARAM_USER_SHIFT = 8; 127 128 struct GParamSpecPool; 129 130 extern (C) { 131 132 struct GParamSpec 133 { 134 GTypeInstance g_type_instance; 135 136 const(gchar) *name; /* interned string */ 137 GParamFlags flags; 138 GType value_type; 139 GType owner_type; /* class or interface using this property */ 140 141 /*< private >*/ 142 gchar *_nick; 143 gchar *_blurb; 144 GData *qdata; 145 guint ref_count; 146 guint param_id; /* sort-criteria */ 147 } 148 149 150 151 struct GParamSpecClass 152 { 153 GTypeClass g_type_class; 154 155 GType value_type; 156 157 void function (GParamSpec *pspec) finalize; 158 159 /* GParam methods */ 160 void function (GParamSpec *pspec, 161 GValue *value) value_set_default; 162 gboolean function (GParamSpec *pspec, 163 GValue *value) value_validate; 164 gint function (GParamSpec *pspec, 165 const(GValue) *value1, 166 const(GValue) *value2) values_cmp; 167 /*< private >*/ 168 gpointer dummy[4]; 169 } 170 171 172 struct GParameter 173 { 174 const(gchar) *name; 175 GValue value; 176 } 177 178 179 /* --- prototypes --- */ 180 181 GParamSpec* g_param_spec_ref (GParamSpec *pspec); 182 183 void g_param_spec_unref (GParamSpec *pspec); 184 185 void g_param_spec_sink (GParamSpec *pspec); 186 187 GParamSpec* g_param_spec_ref_sink (GParamSpec *pspec); 188 189 gpointer g_param_spec_get_qdata (GParamSpec *pspec, 190 GQuark quark); 191 192 void g_param_spec_set_qdata (GParamSpec *pspec, 193 GQuark quark, 194 gpointer data); 195 196 void g_param_spec_set_qdata_full (GParamSpec *pspec, 197 GQuark quark, 198 gpointer data, 199 GDestroyNotify destroy); 200 201 gpointer g_param_spec_steal_qdata (GParamSpec *pspec, 202 GQuark quark); 203 204 GParamSpec* g_param_spec_get_redirect_target (GParamSpec *pspec); 205 206 207 void g_param_value_set_default (GParamSpec *pspec, 208 GValue *value); 209 210 gboolean g_param_value_defaults (GParamSpec *pspec, 211 GValue *value); 212 213 gboolean g_param_value_validate (GParamSpec *pspec, 214 GValue *value); 215 216 gboolean g_param_value_convert (GParamSpec *pspec, 217 const(GValue) *src_value, 218 GValue *dest_value, 219 gboolean strict_validation); 220 221 gint g_param_values_cmp (GParamSpec *pspec, 222 const(GValue) *value1, 223 const(GValue) *value2); 224 225 const(gchar) * g_param_spec_get_name (GParamSpec *pspec); 226 227 const(gchar) * g_param_spec_get_nick (GParamSpec *pspec); 228 229 const(gchar) * g_param_spec_get_blurb (GParamSpec *pspec); 230 231 void g_value_set_param (GValue *value, 232 GParamSpec *param); 233 234 GParamSpec* g_value_get_param (const(GValue) *value); 235 236 GParamSpec* g_value_dup_param (const(GValue) *value); 237 238 239 240 void g_value_take_param (GValue *value, 241 GParamSpec *param); 242 deprecated("use g_value_take_param") 243 void g_value_set_param_take_ownership (GValue *value, 244 GParamSpec *param); 245 246 const(GValue) * g_param_spec_get_default_value (GParamSpec *param); 247 248 struct GParamSpecTypeInfo 249 { 250 /* type system portion */ 251 guint16 instance_size; /* obligatory */ 252 guint16 n_preallocs; /* optional */ 253 void function (GParamSpec *pspec) instance_init; /* optional */ 254 255 /* class portion */ 256 GType value_type; /* obligatory */ 257 void function (GParamSpec *pspec) finalize; /* optional */ 258 void function (GParamSpec *pspec, /* recommended */ 259 GValue *value) value_set_default; 260 gboolean function (GParamSpec *pspec, /* optional */ 261 GValue *value) value_validate; 262 gint function (GParamSpec *pspec, /* recommended */ 263 const(GValue) *value1, 264 const(GValue) *value2) value_cmp; 265 }; 266 267 GType g_param_type_register_static (const(gchar) *name, 268 const(GParamSpecTypeInfo) *pspec_info); 269 270 /* For registering builting types */ 271 GType _g_param_type_register_static_constant (const(gchar) *name, 272 const(GParamSpecTypeInfo) *pspec_info, 273 GType opt_type); 274 275 276 /* --- protected --- */ 277 278 gpointer g_param_spec_internal (GType param_type, 279 const(gchar) *name, 280 const(gchar) *nick, 281 const(gchar) *blurb, 282 GParamFlags flags); 283 284 GParamSpecPool* g_param_spec_pool_new (gboolean type_prefixing); 285 286 void g_param_spec_pool_insert (GParamSpecPool *pool, 287 GParamSpec *pspec, 288 GType owner_type); 289 290 void g_param_spec_pool_remove (GParamSpecPool *pool, 291 GParamSpec *pspec); 292 293 GParamSpec* g_param_spec_pool_lookup (GParamSpecPool *pool, 294 const(gchar) *param_name, 295 GType owner_type, 296 gboolean walk_ancestors); 297 298 GList* g_param_spec_pool_list_owned (GParamSpecPool *pool, 299 GType owner_type); 300 301 GParamSpec** g_param_spec_pool_list (GParamSpecPool *pool, 302 GType owner_type, 303 guint *n_pspecs_p); 304 305 } 306