PageRenderTime 54ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/src/wrappers/gobject/library/g_object.e

http://github.com/tybor/Liberty
Specman e | 1598 lines | 451 code | 345 blank | 802 comment | 8 complexity | f6f99415bd86c242bcabeb25591b9264 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, GPL-2.0
  1. indexing
  2. description: "The base object type of gobject library"
  3. long: "[
  4. Currently the only wrapped features are those explicitly necessary to
  5. wrap GTK+ 2.x GObject is the fundamental type providing the common
  6. attributes and methods for all object types in GTK+, Pango and other
  7. libraries based on GObject. The GObject class provides methods for
  8. object construction and destruction, property access methods, and signal
  9. support. Signals are described in detail in Signals(3).
  10. ]"
  11. copyright: "(C) 2005 Paolo Redaelli "
  12. license: "LGPL v2 or later"
  13. deferred class G_OBJECT
  14. -- GObject is the fundamental type providing the common attributes
  15. -- and methods for all object types in GTK+, Pango and other
  16. -- libraries based on GObject. The GObject class provides methods
  17. -- for object construction and destruction, property access
  18. -- methods, and signal support.
  19. -- TODO: provide Eiffellied descriptio for signals.
  20. -- The initial reference a GObject is created with is flagged as a
  21. -- floating reference. This means that it is not specifically
  22. -- claimed to be "owned" by any code portion. The main motivation
  23. -- for providing floating references is C convenience. In
  24. -- particular, it allowes code to be written as:
  25. -- TODO: Eiffelize Example 1.
  26. -- container = create_container();
  27. -- container_add_child (container, create_child());
  28. -- If container_add_child() will g_object_ref_sink() the
  29. -- passed in child, no reference of the newly created child
  30. -- is leaked. Without floating references,
  31. -- container_add_child() can only g_object_ref() the new
  32. -- child, so to implement this code without reference leaks,
  33. -- it would have to be written as:
  34. -- TODO: Eiffelize Example 2.
  35. -- Child *child;
  36. -- container = create_container();
  37. -- child = create_child();
  38. -- container_add_child (container, child);
  39. -- g_object_unref (child);
  40. -- The floating reference can be converted into an ordinary
  41. -- reference by calling g_object_ref_sink(). For already
  42. -- sunken objects (objects that don't have a floating
  43. -- reference anymore), g_object_ref_sink() is equivalent to
  44. -- g_object_ref() and returns a new reference. Since floating
  45. -- references are useful allmost exclusively for C
  46. -- convenience, language bindings that provide automated
  47. -- reference and memory ownership maintenance (such as smart
  48. -- pointers or garbage collection) therefore don't need to
  49. -- expose floating references in their API.
  50. -- Some object implementations may need to save an objects
  51. -- floating state across certain code portions (an example is
  52. -- GtkMenu), to achive this, the following sequence can be
  53. -- used:
  54. -- Example 3.
  55. -- /* save floating state */
  56. -- gboolean was_floating = g_object_is_floating (object);
  57. -- g_object_ref_sink (object);
  58. -- /* protected code portion */
  59. -- ...;
  60. -- /* restore floating state */
  61. -- if (was_floating)
  62. -- g_object_force_floating (object);
  63. -- g_obejct_unref (object); /* release previously acquired reference */
  64. inherit
  65. C_STRUCT
  66. redefine
  67. from_external_pointer
  68. end
  69. REFERENCE_COUNTED
  70. redefine
  71. dispose
  72. end
  73. insert
  74. GLIB_MEMORY_ALLOCATION export {} all end
  75. GOBJECT_EXTERNALS
  76. GVALUE_EXTERNALS
  77. SHARED_EIFFEL_KEY
  78. G_SIGNALS
  79. -- Features inserted to implement smart_get_property and smart_set_property
  80. G_PARAM_SPEC_EXTERNALS export {} all end
  81. G_TYPE_EXTERNALS
  82. POINTER_HANDLING -- to get `address_of' and `content_of'
  83. feature
  84. store_eiffel_wrapper is
  85. -- Store a pointer to Current into the underlying
  86. -- gobject. This pointer will be used to retrieve the Eiffel
  87. -- wrapper object when a C feature returns a generic object
  88. -- (i.e. the preview widget set in GTK_FILE_CHOOSER).
  89. -- It also take care of storing an hidden pointer to the
  90. -- underlying GobjectClass
  91. require not_stored: not is_eiffel_wrapper_stored
  92. do
  93. g_object_set_qdata (handle, eiffel_key.quark, to_pointer)
  94. -- g_object_set_qdata is called directly to avoid an
  95. -- invariant check when passing Current as argument. Using
  96. -- the Eiffel method "set_qdata (eiffel_key, Current)" easily
  97. -- trigger a "fake" invariant violation.
  98. -- Precursor -- To allow usage of the wrapped object with C
  99. -- data structures that are not aware of the specificities of
  100. -- G_OBJECT.
  101. -- Note: it is necessary to call Precursor AFTER having
  102. -- called g_object_set_qdata. Since we have re-defined the
  103. -- feature `is_eiffel_wrapper_stored' that appears into a
  104. -- postcondition to use `has_qdata', we must satisfy that
  105. -- postcondition before calling Precursor.
  106. ensure
  107. stored: is_eiffel_wrapper_stored
  108. main_wrapper: is_main_wrapper
  109. end
  110. unstore_eiffel_wrapper is
  111. -- Remove the pointer to Current stored into the underlying
  112. -- gobject. Note: a precondition like "require stored:
  113. -- is_eiffel_wrapper_stored" is not necessary; an unnecessary
  114. -- call to this feature should not be harmful
  115. require is_main_wrapper
  116. do
  117. --Precursor
  118. g_object_set_qdata (handle, eiffel_key.quark, default_pointer)
  119. ensure not_stored: not is_eiffel_wrapper_stored
  120. end
  121. is_eiffel_wrapper_stored: BOOLEAN is
  122. -- Has a pointer to the Current Eiffel wrapper been stored
  123. -- into the underlying GObject's qdata property with the
  124. -- GQuark `eiffel_key' (which is currently "eiffel-wrapper")?
  125. do
  126. Result := has_qdata (eiffel_key)
  127. end
  128. is_main_wrapper: BOOLEAN is
  129. -- Is Current the wrapper G_OBJECT linked from the underlying
  130. -- GObject?
  131. do
  132. Result := g_object_get_qdata(handle,eiffel_key.quark)=to_pointer
  133. end
  134. feature {WRAPPER} -- GObject type system implementation.
  135. type: like g_type is
  136. do
  137. Result := g_object_type (handle)
  138. end
  139. type_name: STRING is
  140. do
  141. create {CONST_STRING} Result.from_external (g_object_type_name (handle))
  142. end
  143. feature {WRAPPER, WRAPPER_HANDLER} -- Object creation
  144. -- There are several low-level features used to create an effective heir of G_OBJECT.
  145. -- main_wrapper_from is used to create long-lived wrappers that will be
  146. -- used extensively, stored into collections; those Eiffel wrapper are the
  147. -- one that will be returned by a G_OBJECT_FACTORY when asked for a GObject
  148. -- that have already been wrapped.
  149. -- transient, short-lived wrapper could be created with secondary_wrapper_from.
  150. -- When you do not know if the Gobject you're wrapping has already been
  151. -- wrapped you can either use secondary_wrapper or from_external_pointer.
  152. -- from_external_pointer will check if there is already a wrapper for the
  153. -- wrappee GObject. If it is not the case the G_OBJECT being created
  154. -- becomes the main wrapper.
  155. main_wrapper_from (an_external_pointer: POINTER) is
  156. -- Create a "main" wrapper from `an_external_pointer'. A
  157. -- "main" wrapper is the Eiffel object linked to in the
  158. -- underlying Gobject, whose reference is stored in a qdata
  159. -- property with the `eiffel_key' Gquark key.
  160. -- "main" wrappers are used when the object will be used for a long
  161. -- time, for example in collections
  162. require
  163. called_on_creation: is_null
  164. not_null_pointer: an_external_pointer.is_not_null
  165. no_other_wrappers_exists: not (create {G_OBJECT_EXPANDED_FACTORY [like Current]}).has_eiffel_wrapper_stored (an_external_pointer)
  166. do
  167. handle := an_external_pointer
  168. ref
  169. store_eiffel_wrapper
  170. end
  171. unreffed_main_wrapper_from (an_external_pointer: POINTER) is
  172. -- Create a "main" wrapper from `an_external_pointer'. The
  173. -- underlying GObject is not ref-fed; it is useful when a
  174. -- particular C function returns an already referenced
  175. -- pointer.
  176. require
  177. called_on_creation: is_null
  178. pointer_not_null: an_external_pointer.is_not_null
  179. no_other_wrappers_exists: not (create {G_OBJECT_EXPANDED_FACTORY [like Current]}).has_eiffel_wrapper_stored (an_external_pointer)
  180. do
  181. handle := an_external_pointer
  182. store_eiffel_wrapper
  183. end
  184. secondary_wrapper_from (an_external_pointer: POINTER) is
  185. -- Create a non-main wrapper from `an_external_pointer'.
  186. require
  187. called_on_creation: is_null
  188. pointer_not_null: an_external_pointer.is_not_null
  189. do
  190. handle := an_external_pointer
  191. ref
  192. ensure
  193. is_secondary_wrapper: not is_main_wrapper
  194. end
  195. from_external_pointer (a_ptr: POINTER) is
  196. require
  197. called_on_creation: is_null
  198. pointer_not_null: a_ptr.is_not_null
  199. -- not_existing_wrapper: not (create {G_OBJECT_FACTORY[like Current]}).has_eiffel_wrapper_stored (a_ptr)
  200. do
  201. Precursor (a_ptr)
  202. if not is_eiffel_wrapper_stored then store_eiffel_wrapper end
  203. ref -- add a reference to the underlying g_object
  204. end
  205. from_external_pointer_no_ref (a_ptr: POINTER) is
  206. -- create a new wrapper for a GObject, without ref-ing it.
  207. -- This is useful when some C function returns an already
  208. -- reffed pointer to a Gobject. In this case the Eiffel
  209. -- wrapper must not call ref at creation time, just unref at
  210. -- dispose time.
  211. require
  212. called_on_creation: is_null
  213. pointer_not_null: a_ptr.is_not_null
  214. -- not_existing_wrapper: not (create {G_OBJECT_EXPANDED_FACTORY [like Current]}).has_eiffel_wrapper_stored (a_ptr)
  215. do
  216. handle := a_ptr
  217. if not is_eiffel_wrapper_stored then store_eiffel_wrapper end
  218. end
  219. feature -- Disposing
  220. dispose is
  221. -- Dispose the g_object, calling unref and setting its handle to default_pointer.
  222. -- TODO: once the iusse explained in the debug tense in the implementation is
  223. -- solved put a "require is_a_gobject: g_is_object (handle)" precondition
  224. do
  225. -- Note: when Eiffel disposes a G_OBJECT it just unrefs it and
  226. -- cleans its handle. The actual reclaiming of the memory
  227. -- allocated on the C side is left to the gobject runtime.
  228. check is_g_object end
  229. if is_main_wrapper then
  230. debug
  231. std_error.put_line("G_OBJECT.dispose: disposing the main wrapper of a "+type_name)
  232. end
  233. unstore_eiffel_wrapper
  234. else
  235. debug
  236. std_error.put_line("G_OBJECT.dispose: not disposing "+to_pointer.out+" not a main wrapper of a "+type_name)
  237. end
  238. end
  239. debug print(once "Unreffing a "+generating_type+"%N") end
  240. unref
  241. -- There are some shared G_OBJECTS that we shouldn't unref.
  242. -- Check for example pango_cairo_font_map_get_default
  243. handle := default_pointer
  244. end
  245. feature {} -- Disposing helper
  246. is_g_object: BOOLEAN is
  247. -- Is current handle a pointer to a g_object?
  248. do
  249. Result := (g_is_object (handle) /= 0)
  250. end
  251. feature -- Reference count
  252. ref is
  253. -- Increases the reference count of object.
  254. local ptr: POINTER
  255. do
  256. ptr := g_object_ref (handle)
  257. check
  258. ptr_equals_handle: ptr = handle
  259. end
  260. end
  261. unref is
  262. -- Decreases the reference count if object. When its reference count
  263. -- drops to 0, the object is finalized (i.e. its memory is freed).
  264. do
  265. g_object_unref (handle)
  266. end
  267. feature -- Data storing and retrieving
  268. get_data (a_key: STRING): ANY is
  269. -- Gets a named field from the objects table of associations (see
  270. -- set_data). `a_key': name of the key for that association; Void if no
  271. -- `a_key' field is present
  272. require valid_key: a_key /= Void
  273. local ptr: POINTER
  274. do
  275. -- Note: wrappers that needs to store C pointers and do other low-level
  276. -- stuff are invited to use g_object_get_data directly
  277. -- Note: Perhaps it is better to use GQuarks and g_object_get_qdata
  278. ptr := g_object_get_data (handle, a_key.to_external)
  279. if ptr.is_not_null then Result:=ptr.to_any end
  280. end
  281. set_data (a_key: STRING; data: ANY) is
  282. -- Store a reference to `data' under the name `a_key'. Each object
  283. -- carries around a table of associations from strings to pointers. If
  284. -- the object already had an association with that name, the old
  285. -- association will be destroyed.
  286. -- a_key : name of the key
  287. -- data : data to associate with that key
  288. require
  289. valid_key: a_key /= Void
  290. do
  291. -- Note: a_key is not duplicated since g_object_set_data requires a const
  292. -- gchar *;
  293. g_object_set_data (handle,a_key.to_external, data.to_pointer)
  294. end
  295. steal_data (a_key: STRING): ANY is
  296. -- Remove a specified datum from the object's data associations, --
  297. -- without invoking the association's destroy handler. Void if there's
  298. -- no data with `a_key'
  299. require valid_key: a_key /= Void
  300. local ptr: POINTER
  301. do
  302. ptr := g_object_steal_data (handle, a_key.to_external)
  303. if ptr.is_not_null then Result:=ptr.to_any end
  304. end
  305. feature -- Quark-based data storing and retrieving
  306. has_qdata (a_key: G_QUARK): BOOLEAN is
  307. -- Is `a_key' field present in table of associations (see
  308. -- set_qdata)? `a_key': a GQuark, naming the user data
  309. -- pointer
  310. do
  311. Result := (g_object_get_qdata (handle, a_key.quark).is_not_null)
  312. end
  313. get_qdata (a_key: G_QUARK): ANY is
  314. -- Gets a named field from the objects table of associations
  315. -- (see set_data). `a_key': a GQuark, naming the user data
  316. -- pointer; Void if no `a_key' field is present
  317. local ptr: POINTER
  318. do
  319. ptr := g_object_get_qdata (handle, a_key.quark)
  320. if ptr.is_not_null then Result:=ptr.to_any end
  321. end
  322. set_qdata (a_key: G_QUARK; data: ANY) is
  323. -- Store a reference to `data' under the GQuark `a_key'. Each
  324. -- object carries around a table of associations from strings
  325. -- to pointers. If the object already had an association with
  326. -- that name, the old association will be destroyed.
  327. -- a_key : name of the key
  328. -- data : data to associate with that key
  329. do
  330. g_object_set_qdata (handle,a_key.quark, data.to_pointer)
  331. end
  332. feature -- Properties notifying
  333. notify (a_property_name: STRING) is
  334. -- Emits a "notify" signal for the property `a_property_name' on
  335. -- object.
  336. do
  337. g_object_notify (handle, a_property_name.to_external)
  338. end
  339. freeze_notify is
  340. -- Stops emission of "notify" signals on object. The signals are queued
  341. -- until thaw_notify is called on object. This is necessary for
  342. -- accessors that modify multiple properties to prevent premature
  343. -- notification while the object is still being modified.
  344. do
  345. g_object_freeze_notify (handle)
  346. end
  347. thaw_notify is
  348. -- Causes all queued "notify" signals on object to be
  349. -- emitted. Reverts the effect of a previous call to
  350. -- freeze_notify.
  351. do
  352. g_object_thaw_notify (handle)
  353. end
  354. feature -- Properties query
  355. find_property (a_property_name: STRING): G_PARAM_SPEC is
  356. -- Find the parameter's spec for `a_property_name'. Void if
  357. -- the class doesn't have a property of that name.
  358. require valid_name: a_property_name /= Void
  359. local
  360. param_spec_ptr: POINTER
  361. do
  362. param_spec_ptr:=g_object_class_find_property (g_object_get_class(handle),a_property_name.to_external)
  363. if param_spec_ptr.is_not_null then
  364. create Result.from_external_pointer (param_spec_ptr)
  365. end
  366. end
  367. has_property (a_property_name: STRING): BOOLEAN is
  368. -- Does Current has a property named `a_property_name'?
  369. require valid_name: a_property_name /= Void
  370. do
  371. Result:= (g_object_class_find_property
  372. (g_object_get_class(handle),a_property_name.to_external).is_not_null)
  373. end
  374. properties: COLLECTION[G_PARAM_SPEC] is
  375. -- The properties of the G_OBJECT
  376. local
  377. a_length, another_length: INTEGER;
  378. c_array_ptr: POINTER;
  379. another: C_ARRAY[G_PARAM_SPEC]
  380. do
  381. not_yet_implemented
  382. -- if hidden_properties=Void then
  383. -- create {C_ARRAY[G_PARAM_SPEC]}
  384. -- hidden_properties.from_external_array
  385. -- (g_object_class_list_properties(g_object_get_class(handle), $a_length),
  386. -- a_length, g_param_spec_factory)
  387. -- end
  388. -- Result:=hidden_properties
  389. -- debug
  390. -- create another.from_external_array
  391. -- (g_object_class_list_properties(g_object_get_class(handle), $another_length),
  392. -- another_length, g_param_spec_factory)
  393. -- check -- the assumption that list properties is "stable" over time.
  394. -- -- Using a cached, hidden properties collection requires
  395. -- -- that the actual properties are the same. Having a
  396. -- -- caching factory allows to use same_items of the
  397. -- -- result, after having created another copy of.
  398. -- Result.same_items(another)
  399. -- end
  400. -- end
  401. end
  402. feature -- Property getter/setter
  403. set_properties (some_properties: COLLECTION [TUPLE[STRING,G_VALUE]]) is
  404. require
  405. no_void_property_names: --TODO
  406. no_void_property_values: --TODO
  407. local iter: ITERATOR [TUPLE[STRING,G_VALUE]]
  408. do
  409. freeze_notify
  410. iter := some_properties.get_new_iterator
  411. from iter.start until iter.is_off
  412. loop
  413. -- Note: The original C implementation of this feature
  414. -- retrieve the G_PARAM_SPEC linked to each property and
  415. -- then checks:
  416. -- * if theres a property with that name
  417. -- * it the property is writable
  418. -- * if the property is settable only at creation time
  419. -- I'm not sure that an Eiffel implementation should
  420. -- implement this, because it should be already checked
  421. -- by Gobject. Paolo 2006-07-06
  422. check
  423. name_not_void: iter.item.item_1 /= Void
  424. value_not_void: iter.item.item_2 /= Void
  425. end
  426. set_property (iter.item.item_1, iter.item.item_2)
  427. iter.next
  428. end
  429. end
  430. smart_set_property (a_parameter_specification: G_PARAM_SPEC; a_value: G_VALUE) is
  431. -- Sets the property specified by
  432. -- `a_parameter_specification' on Current object to
  433. -- `a_value'.
  434. -- Smart Eiffel-specific reimplementation of the original
  435. -- GObject feature. All the logic and checks related to
  436. -- correctness is handled throught static typing and
  437. -- preconditions.
  438. require
  439. parameter_specification_not_void: a_parameter_specification /= Void
  440. has_property: has_property(a_parameter_specification.name)
  441. is_writable: a_parameter_specification.is_writable
  442. not_at_construction_time_only: not (a_parameter_specification.is_set_only_at_construction)
  443. value_not_void: a_value /= Void
  444. correct_value_type: a_parameter_specification.validate(a_value) or
  445. True -- It is convertible
  446. not_redirected: -- TODO not find_property(a_property_name).is_redirected
  447. -- local redirect: POINTER
  448. do
  449. -- Note: here we work directly with pointers to the C data
  450. -- structure, to avoid yet another layer of
  451. -- abstraction/reindirection and its performance loss. We are
  452. -- seeking performance and we assume to be enabled to fiddle
  453. -- with low-level details.
  454. -- Note: The original C implementation uses this (private)
  455. -- data structure; code dealing with it is left here
  456. -- commented for later inspection: GObjectNotifyQueue
  457. -- *nqueue;
  458. -- NOTE: avoiding ref, since we already has a reference
  459. -- nqueue = g_object_notify_queue_freeze (object,
  460. -- &property_notify_context);
  461. freeze_notify
  462. -- redirect := g_param_spec_get_redirect_target (pspec)
  463. -- if redirect.is_not_null then pspec := redirect end
  464. -- /* provide a copy to work from, convert (if necessary) and validate */
  465. -- g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
  466. -- if (!g_value_transform (value, &tmp_value))
  467. -- g_warning ("unable to set property `%s' of type `%s' from value of type `%s'",
  468. -- pspec->name,
  469. -- g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
  470. -- G_VALUE_TYPE_NAME (value));
  471. -- else if (g_param_value_validate (pspec, &tmp_value) && !(pspec->flags & G_PARAM_LAX_VALIDATION))
  472. -- {
  473. -- gchar *contents = g_strdup_value_contents (value);
  474. -- g_warning ("value \"%s\" of type `%s' is invalid or out of range for property `%s' of type `%s'",
  475. -- contents,
  476. -- G_VALUE_TYPE_NAME (value),
  477. -- pspec->name,
  478. -- g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
  479. -- g_free (contents);
  480. -- }
  481. -- else
  482. -- {
  483. -- The following code calls the underlying C "virtual" call;
  484. -- it mimicks "class->set_property (object, param_id,
  485. -- &tmp_value, pspec);"
  486. invoke_set_property (a_parameter_specification.owner_class,
  487. handle,
  488. a_parameter_specification.param_id, a_value.handle,
  489. a_parameter_specification.handle)
  490. -- g_object_notify_queue_add (object, nqueue, pspec);
  491. -- g_object_notify_queue_thaw (object, nqueue);
  492. -- NOTE: avoiding unref, since we didn't acquire any above
  493. thaw_notify
  494. ensure
  495. value_set: -- a_value.is_equal (get_property(a_property_name))
  496. end
  497. set_property (a_property_name: STRING; a_value: G_VALUE) is
  498. -- Sets `a_property_name' property on Current object to
  499. -- `a_value'. This feature uses the underlying C
  500. -- implementation which is slower, since it always makes
  501. -- many checks.
  502. require
  503. valid_name: a_property_name /= Void
  504. has_property: has_property (a_property_name)
  505. is_writable: find_property (a_property_name).is_writable
  506. valid_value: a_value /= Void
  507. correct_value_type: a_value.is_a (find_property (a_property_name).value_gtype)
  508. do
  509. g_object_set_property (handle, a_property_name.to_external, a_value.handle)
  510. ensure
  511. value_set: -- TODO: a_value.is_equal (get_property(a_property_name))
  512. end
  513. property, get_property (a_property_name: STRING): G_VALUE is
  514. -- Gets the property name `a_property_name' of an object.
  515. -- Note: The underlying C implementation has the following
  516. -- "preconditions" that are not compiled-in in optimized
  517. -- code:
  518. -- * handle is a GObject
  519. -- * property name C-string is not a NULL pointer
  520. -- * the GValue passed in should be a GValue....
  521. -- It also always check that:
  522. -- * There's a property with that name
  523. -- * the property is readable
  524. -- * the value passed in is of the same type of the property
  525. -- or it is convertible into a correct type
  526. -- All those checkes are made for each and every access to
  527. -- any property, beside the fact that the actual property
  528. -- getter is usually a big switch statement hidded under
  529. -- another 2 layers of calls.
  530. -- Isn't it nicely inefficient, it is?
  531. -- In this Eiffel wrapper the first checks are statically
  532. -- enforced, while second group of checks can be handled by
  533. -- preconditions and it is duty of the caller to check them
  534. -- if necessary. The very last check is automatically
  535. -- followed
  536. -- Therefore this implementation will directly
  537. -- call the hidden virtual call, i.e.: "class->get_property
  538. -- (object, param_id, value, pspec);" see gobject/gobject.c
  539. -- function "object_get_property" for further
  540. -- informations. Paolo 2006-07-25
  541. require
  542. valid_name: a_property_name /= Void
  543. has_property: has_property (a_property_name)
  544. is_readable: find_property (a_property_name).is_readable
  545. local gvalue_ptr: POINTER; parameter_specification: G_PARAM_SPEC
  546. do
  547. parameter_specification := find_property(a_property_name)
  548. create Result.with_gtype (parameter_specification.value_gtype)
  549. g_object_get_property (handle,a_property_name.to_external, Result.handle)
  550. -- while (name) { GValue value = { 0, }; GParamSpec *pspec;
  551. -- gchar *error;
  552. -- pspec = g_param_spec_pool_lookup (pspec_pool,
  553. -- name,
  554. -- G_OBJECT_TYPE (object),
  555. -- TRUE);
  556. -- if (!pspec)
  557. -- {
  558. -- g_warning ("%s: object class `%s' has no property named `%s'",
  559. -- G_STRFUNC,
  560. -- G_OBJECT_TYPE_NAME (object),
  561. -- name);
  562. -- break;
  563. -- }
  564. -- if (!(pspec->flags & G_PARAM_READABLE))
  565. -- {
  566. -- g_warning ("%s: property `%s' of object class `%s' is not readable",
  567. -- G_STRFUNC,
  568. -- pspec->name,
  569. -- G_OBJECT_TYPE_NAME (object));
  570. -- break;
  571. -- }
  572. -- g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
  573. -- object_get_property (object, pspec, &value);
  574. -- G_VALUE_LCOPY (&value, var_args, 0, &error);
  575. -- if (error)
  576. -- {
  577. -- g_warning ("%s: %s", G_STRFUNC, error);
  578. -- g_free (error);
  579. -- g_value_unset (&value);
  580. -- break;
  581. -- }
  582. -- g_value_unset (&value);
  583. -- name = va_arg (var_args, gchar*);
  584. -- }
  585. -- g_object_unref (object);
  586. ensure
  587. not_void: Result /= Void
  588. correct_type: Result.is_a (find_property(a_property_name).value_gtype)
  589. end
  590. feature -- String property
  591. set_string_property (a_property_name, a_string: STRING) is
  592. require
  593. name_not_void: a_property_name /= Void
  594. string_not_void: a_string /= Void
  595. do
  596. hidden_gvalue.turn_to_string; hidden_gvalue.set_string (a_string)
  597. g_object_set_property (handle,a_property_name.to_external, hidden_gvalue.handle)
  598. end
  599. string_property, get_string_property (a_property_name: STRING): STRING is
  600. -- the string property named `a_property_name' of an object. Can be
  601. -- Void. TODO: this is complemetely untested! Test it, for
  602. -- example in GTK_CELL_RENDERER_PROGRESS
  603. require
  604. valid_name: a_property_name /= Void
  605. has_property: has_property (a_property_name)
  606. is_string_property: find_property (a_property_name).is_string
  607. local ptr: POINTER
  608. do
  609. hidden_gvalue.turn_to_string
  610. g_object_get_property (handle,a_property_name.to_external,hidden_gvalue.handle)
  611. Result := hidden_gvalue.string
  612. end
  613. feature -- integer property
  614. set_integer_property (a_property_name: STRING; a_value: INTEGER) is
  615. -- Set property with `a_name' to `a_value'
  616. require
  617. valid_name: a_property_name /= Void
  618. property_exists: has_property (a_property_name)
  619. is_writable: find_property (a_property_name).is_writable
  620. is_integer_property: find_property (a_property_name).is_integer
  621. do
  622. hidden_gvalue.turn_to_integer
  623. hidden_gvalue.set_integer (a_value)
  624. g_object_set_property (handle, a_property_name.to_external, hidden_gvalue.handle)
  625. end
  626. integer_property (a_property_name: STRING): INTEGER is
  627. -- the integer property named `a_property_name' of an object.
  628. require
  629. valid_name: a_property_name /= Void
  630. has_property: has_property (a_property_name)
  631. is_string_property: find_property (a_property_name).is_integer
  632. do
  633. hidden_gvalue.turn_to_integer
  634. g_object_get_property (handle,a_property_name.to_external,hidden_gvalue.handle)
  635. Result := hidden_gvalue.integer
  636. end
  637. feature -- double/REAL_64 property
  638. set_real_64_property, set_double_property (a_property_name: STRING; a_value: REAL_64) is
  639. -- Set property with `a_name' to `a_value'
  640. require
  641. valid_name: a_property_name /= Void
  642. property_exists: has_property (a_property_name)
  643. is_writable: find_property (a_property_name).is_writable
  644. is_double_property: find_property (a_property_name).is_real_64
  645. do
  646. hidden_gvalue.turn_to_real_64
  647. hidden_gvalue.set_real_64 (a_value)
  648. g_object_set_property (handle, a_property_name.to_external, hidden_gvalue.handle)
  649. end
  650. real_64_property, double_property (a_property_name: STRING): REAL_64 is
  651. -- the double property named `a_property_name' of an object.
  652. require
  653. valid_name: a_property_name /= Void
  654. has_property: has_property (a_property_name)
  655. is_real_64_property: find_property (a_property_name).is_real_64
  656. do
  657. hidden_gvalue.turn_to_real_64
  658. g_object_get_property (handle,a_property_name.to_external,hidden_gvalue.handle)
  659. Result := hidden_gvalue.real_64
  660. end
  661. real_64_property_from_pspec, double_property_from_pspec (a_parameter_specification: G_PARAM_SPEC): REAL_64 is
  662. -- the double property with `a_parameter_specification'. This
  663. -- feature is faster than the plain `double_property'
  664. -- because the latter retrieves the parameter specification
  665. -- from the name given. Storing the specification in a once
  666. -- feature hasten property retrieving.
  667. -- TODO: I'm unsure but I suspect that this feature still has
  668. -- sub-optimal performance because it still creates a new
  669. -- G_VALUE each time. I would help if G_VALUE is expanded and
  670. -- holds the actual GValue C structure like an expanded
  671. -- feature. This way the G_VALUE would be created on the
  672. -- stack, obtaining better performances.
  673. -- Note: the previous TODO should have been implemented in
  674. -- may 2007
  675. require
  676. specification_not_void: a_parameter_specification /= Void
  677. do
  678. hidden_gvalue.turn_to_real_64
  679. invoke_get_property (a_parameter_specification.owner_class, handle,
  680. a_parameter_specification.param_id, hidden_gvalue.handle,
  681. a_parameter_specification.handle)
  682. Result := hidden_gvalue.real_64
  683. end
  684. feature -- float/REAL_32 property
  685. set_real_32_property, set_float_property (a_property_name: STRING; a_value: REAL_32) is
  686. -- Set property with `a_name' to `a_value'
  687. require
  688. valid_name: a_property_name /= Void
  689. property_exists: has_property (a_property_name)
  690. is_writable: find_property (a_property_name).is_writable
  691. is_float_property: find_property (a_property_name).is_real_32
  692. do
  693. hidden_gvalue.turn_to_real_32
  694. hidden_gvalue.set_real_32 (a_value)
  695. g_object_set_property (handle, a_property_name.to_external, hidden_gvalue.handle)
  696. end
  697. real_32_property, float_property (a_property_name: STRING): REAL_32 is
  698. -- the float property named `a_property_name' of an object.
  699. require
  700. valid_name: a_property_name /= Void
  701. has_property: has_property (a_property_name)
  702. is_real_32_property: find_property (a_property_name).is_real_32
  703. do
  704. hidden_gvalue.turn_to_real_32
  705. g_object_get_property (handle,a_property_name.to_external,hidden_gvalue.handle)
  706. Result := hidden_gvalue.real_32
  707. end
  708. real_32_property_from_pspec, float_property_from_pspec (a_parameter_specification: G_PARAM_SPEC): REAL_32 is
  709. -- the float property with `a_parameter_specification'. This
  710. -- feature is faster than the plain `float_property'
  711. -- because the latter retrieves the parameter specification
  712. -- from the name given. Storing the specification in a once
  713. -- feature hasten property retrieving.
  714. -- TODO: I'm unsure but I suspect that this feature still has
  715. -- sub-optimal performance because it still creates a new
  716. -- G_VALUE each time. I would help if G_VALUE is expanded and
  717. -- holds the actual GValue C structure like an expanded
  718. -- feature. This way the G_VALUE would be created on the
  719. -- stack, obtaining better performances.
  720. -- Note: the previous TODO should have been implemented in
  721. -- may 2007
  722. require
  723. specification_not_void: a_parameter_specification /= Void
  724. do
  725. hidden_gvalue.turn_to_real_32
  726. invoke_get_property (a_parameter_specification.owner_class, handle,
  727. a_parameter_specification.param_id, hidden_gvalue.handle,
  728. a_parameter_specification.handle)
  729. Result := hidden_gvalue.real_32
  730. end
  731. feature -- boolean property
  732. set_boolean_property (a_property_name: STRING; a_value: BOOLEAN) is
  733. -- Set boolean property with `a_name' to `a_value'
  734. require
  735. valid_name: a_property_name /= Void
  736. property_exists: has_property (a_property_name)
  737. is_writable: find_property (a_property_name).is_writable
  738. is_integer_property: find_property (a_property_name).is_boolean
  739. do
  740. hidden_gvalue.turn_to_boolean; hidden_gvalue.set_boolean (a_value)
  741. g_object_set_property (handle, a_property_name.to_external, hidden_gvalue.handle)
  742. end
  743. boolean_property (a_property_name: STRING): BOOLEAN is
  744. -- the boolean property named `a_property_name' of an object.
  745. require
  746. valid_name: a_property_name /= Void
  747. has_property: has_property (a_property_name)
  748. is_string_property: find_property (a_property_name).is_boolean
  749. do
  750. hidden_gvalue.turn_to_boolean
  751. g_object_get_property (handle, a_property_name.to_external, hidden_gvalue.handle)
  752. Result := hidden_gvalue.boolean
  753. end
  754. boolean_property_from_pspec (a_parameter_specification: G_PARAM_SPEC): BOOLEAN is
  755. -- the boolean property with `a_parameter_specification'. This
  756. -- feature is faster than the plain `boolean_property'
  757. -- because the latter retrieves the parameter specification
  758. -- from the name given. Storing the specification in a once
  759. -- feature hasten property retrieving.
  760. -- TODO: I'm unsure but I suspect that this feature still has
  761. -- sub-optimal performance because it still creates a new
  762. -- G_VALUE each time. I would help if G_VALUE is expanded and
  763. -- holds the actual GValue C structure like an expanded
  764. -- feature. This way the G_VALUE would be created on the
  765. -- stack, obtaining better performances.
  766. -- Note: the previous TODO should have been implemented in
  767. -- may 2007
  768. require
  769. specification_not_void: a_parameter_specification /= Void
  770. do
  771. hidden_gvalue.turn_to_boolean
  772. invoke_get_property (a_parameter_specification.owner_class, handle,
  773. a_parameter_specification.param_id, hidden_gvalue.handle,
  774. a_parameter_specification.handle)
  775. Result := hidden_gvalue.boolean
  776. end
  777. feature -- enum property
  778. set_enum_property (a_property_name: STRING; a_value: INTEGER) is
  779. -- Set the enumeration property with `a_name' to `a_value'.
  780. require
  781. valid_name: a_property_name /= Void
  782. property_exists: has_property (a_property_name)
  783. is_writable: find_property (a_property_name).is_writable
  784. is_enum_property: find_property (a_property_name).is_enum
  785. do
  786. hidden_gvalue.turn_to_integer
  787. hidden_gvalue.set_integer (a_value)
  788. g_object_set_property (handle, a_property_name.to_external,hidden_gvalue.handle)
  789. end
  790. enum_property (a_property_name: STRING): INTEGER is
  791. -- the enumeration property named `a_property_name' of an object.
  792. require
  793. valid_name: a_property_name /= Void
  794. has_property: has_property (a_property_name)
  795. is_string_property: find_property (a_property_name).is_enum
  796. do
  797. hidden_gvalue.turn_to_integer
  798. g_object_get_property (handle,a_property_name.to_external,hidden_gvalue.handle)
  799. Result:=hidden_gvalue.integer
  800. end
  801. feature {} -- Unwrapped API
  802. -- ----------------------------------------------------------------------------------------------------------------
  803. -- GObjectClass
  804. -- typedef struct {
  805. -- GTypeClass g_type_class;
  806. -- /* overridable methods */
  807. -- GObject* (*constructor) (GType type,
  808. -- guint n_construct_properties,
  809. -- GObjectConstructParam *construct_properties);
  810. -- void (*set_property) (GObject *object,
  811. -- guint property_id,
  812. -- const GValue *value,
  813. -- GParamSpec *pspec);
  814. -- void (*get_property) (GObject *object,
  815. -- guint property_id,
  816. -- GValue *value,
  817. -- GParamSpec *pspec);
  818. -- void (*dispose) (GObject *object);
  819. -- void (*finalize) (GObject *object);
  820. -- /* seldomly overidden */
  821. -- void (*dispatch_properties_changed) (GObject *object,
  822. -- guint n_pspecs,
  823. -- GParamSpec **pspecs);
  824. -- /* signals */
  825. -- void (*notify) (GObject *object,
  826. -- GParamSpec *pspec);
  827. -- } GObjectClass;
  828. -- The class structure for the GObject type.
  829. -- Example 4. Implementing singletons using a constructor
  830. -- static MySingleton *the_singleton = NULL;
  831. -- static GObject*
  832. -- my_singleton_constructor (GType type,
  833. -- guint n_construct_params,
  834. -- GObjectConstructParam *construct_params)
  835. -- {
  836. -- GObject *object;
  837. -- if (!the_singleton)
  838. -- {
  839. -- object = G_OBJECT_CLASS (parent_class)->constructor (type,
  840. -- n_construct_params,
  841. -- construct_params);
  842. -- the_singleton = MY_SINGLETON (object);
  843. -- }
  844. -- else
  845. -- object = g_object_ref (G_OBJECT (the_singleton));
  846. -- return object;
  847. -- }
  848. -- GTypeClass g_type_class; the parent class
  849. -- constructor () the constructor function is called by g_object_new() to complete the object
  850. -- initialization after all the construction properties are set. The first thing a
  851. -- constructor implementation must do is chain up to the constructor of the parent
  852. -- class. Overriding constructor should be rarely needed, e.g. to handle construct
  853. -- properties, or to implement singletons.
  854. -- set_property () the generic setter for all properties of this type. Should be overridden for
  855. -- every type with properties. Implementations of set_property don't need to emit
  856. -- property change notification explicitly, this is handled by the type system.
  857. -- get_property () the generic getter for all properties of this type. Should be overridden for
  858. -- every type with properties.
  859. -- dispose () the dispose function is supposed to drop all references to other objects, but
  860. -- keep the instance otherwise intact, so that client method invocations still work.
  861. -- It may be run multiple times (due to reference loops). Before returning, dispose
  862. -- should chain up to the dispose method of the parent class.
  863. -- finalize () instance finalization function, should finish the finalization of the instance
  864. -- begun in dispose and chain up to the finalize method of the parent class.
  865. -- dispatch_properties_changed () emits property change notification for a bunch of properties. Overriding
  866. -- dispatch_properties_changed should be rarely needed.
  867. -- notify () the class closure for the notify signal
  868. -- ----------------------------------------------------------------------------------------------------------------
  869. -- GObjectConstructParam
  870. -- typedef struct {
  871. -- GParamSpec *pspec;
  872. -- GValue *value;
  873. -- } GObjectConstructParam;
  874. -- The GObjectConstructParam struct is an auxiliary structure used to hand GParamSpec/GValue pairs to the
  875. -- constructor of a GObjectClass.
  876. -- GParamSpec *pspec; the GParamSpec of the construct parameter
  877. -- GValue *value; the value to set the parameter to
  878. -- ----------------------------------------------------------------------------------------------------------------
  879. -- GObjectGetPropertyFunc ()
  880. -- void (*GObjectGetPropertyFunc) (GObject *object,
  881. -- guint property_id,
  882. -- GValue *value,
  883. -- GParamSpec *pspec);
  884. -- The type of the get_property function of GObjectClass.
  885. -- object : a GObject
  886. -- property_id : the numeric id under which the property was registered with g_object_class_install_property().
  887. -- value : a GValue to return the property value in
  888. -- pspec : the GParamSpec describing the property
  889. -- ----------------------------------------------------------------------------------------------------------------
  890. -- GObjectSetPropertyFunc ()
  891. -- void (*GObjectSetPropertyFunc) (GObject *object,
  892. -- guint property_id,
  893. -- const GValue *value,
  894. -- GParamSpec *pspec);
  895. -- The type of the set_property function of GObjectClass.
  896. -- object : a GObject
  897. -- property_id : the numeric id under which the property was registered with g_object_class_install_property().
  898. -- value : the new value for the property
  899. -- pspec : the GParamSpec describing the property
  900. -- ----------------------------------------------------------------------------------------------------------------
  901. -- GObjectFinalizeFunc ()
  902. -- void (*GObjectFinalizeFunc) (GObject *object);
  903. -- The type of the finalize function of GObjectClass.
  904. -- object : the GObject being finalized
  905. -- ----------------------------------------------------------------------------------------------------------------
  906. -- G_TYPE_IS_OBJECT()
  907. -- #define G_TYPE_IS_OBJECT(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_OBJECT)
  908. -- Returns a boolean value of FALSE or TRUE indicating whether the passed in type id is a G_TYPE_OBJECT or derived
  909. -- from it.
  910. -- type : Type id to check for is a G_TYPE_OBJECT relationship.
  911. -- Returns : FALSE or TRUE, indicating whether type is a G_TYPE_OBJECT.
  912. -- ----------------------------------------------------------------------------------------------------------------
  913. -- G_OBJECT()
  914. -- #define G_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), G_TYPE_OBJECT, GObject))
  915. -- Casts a GObject or derived pointer into a (GObject*) pointer. Depending on the current debugging level, this
  916. -- function may invoke certain runtime checks to identify invalid casts.
  917. -- object : Object which is subject to casting.
  918. -- ----------------------------------------------------------------------------------------------------------------
  919. -- G_IS_OBJECT()
  920. -- #define G_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), G_TYPE_OBJECT))
  921. -- Checks whether a valid GTypeInstance pointer is of type G_TYPE_OBJECT.
  922. -- object : Instance to check for being a G_TYPE_OBJECT.
  923. -- ----------------------------------------------------------------------------------------------------------------
  924. -- G_OBJECT_CLASS()
  925. -- #define G_OBJECT_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_OBJECT, GObjectClass))
  926. -- Casts a derived GObjectClass structure into a GObjectClass structure.
  927. -- class : a valid GObjectClass
  928. -- ----------------------------------------------------------------------------------------------------------------
  929. -- G_IS_OBJECT_CLASS()
  930. -- #define G_IS_OBJECT_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_OBJECT))
  931. -- Checks whether class "is a" valid GObjectClass structure of type G_TYPE_OBJECT or derived.
  932. -- class : a GObjectClass
  933. -- ----------------------------------------------------------------------------------------------------------------
  934. -- G_OBJECT_GET_CLASS()
  935. -- #define G_OBJECT_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), G_TYPE_OBJECT, GObjectClass))
  936. -- Returns the class structure associated to a GObject instance.
  937. -- object : a GObject instance.
  938. -- ----------------------------------------------------------------------------------------------------------------
  939. -- G_OBJECT_TYPE()
  940. -- #define G_OBJECT_TYPE(object) (G_TYPE_FROM_INSTANCE (object))
  941. -- Return the type id of an object.
  942. -- object : Object to return the type id for.
  943. -- Returns : Type id of object.
  944. -- ----------------------------------------------------------------------------------------------------------------
  945. -- G_OBJECT_TYPE_NAME()
  946. -- #define G_OBJECT_TYPE_NAME(object) (g_type_name (G_OBJECT_TYPE (object)))
  947. -- Returns the name of an object's type.
  948. -- object : Object to return the type name for.
  949. -- Returns : Type name of object. The string is owned by the type system and should not be freed.
  950. -- ----------------------------------------------------------------------------------------------------------------
  951. -- G_OBJECT_CLASS_TYPE()
  952. -- #define G_OBJECT_CLASS_TYPE(class) (G_TYPE_FROM_CLASS (class))
  953. -- Return the type id of a class structure.
  954. -- class : a valid GObjectClass
  955. -- Returns : Type id of class.
  956. -- ----------------------------------------------------------------------------------------------------------------
  957. -- G_OBJECT_CLASS_NAME()
  958. -- #define G_OBJECT_CLASS_NAME(class) (g_type_name (G_OBJECT_CLASS_TYPE (class)))
  959. -- Return the name of a class structure's type.
  960. -- class : a valid GObjectClass
  961. -- Returns : Type name of class. The string is owned by the type system and should not be freed.
  962. -- ----------------------------------------------------------------------------------------------------------------
  963. -- g_object_class_install_property ()
  964. -- void g_object_class_install_property (GObjectClass *oclass,
  965. -- guint property_id,
  966. -- GParamSpec *pspec);
  967. -- Installs a new property. This is usually done in the class initializer.
  968. -- oclass : a GObjectClass
  969. -- property_id : the id for the new property
  970. -- pspec : the GParamSpec for the new property
  971. -- ----------------------------------------------------------------------------------------------------------------
  972. -- g_object_class_list_properties ()
  973. -- GParamSpec** g_object_class_list_properties (GObjectClass *oclass,
  974. -- guint *n_properties);
  975. -- Returns an array of GParamSpec* for all properties of a class.
  976. -- oclass : a GObjectClass
  977. -- n_properties : return location for the length of the returned array
  978. -- Returns : an array of GParamSpec* which should be freed after use
  979. -- ----------------------------------------------------------------------------------------------------------------
  980. -- g_object_class_override_property ()
  981. -- void g_object_class_override_property
  982. -- (GObjectClass *oclass,
  983. -- guint property_id,
  984. -- const gchar *name);
  985. -- Registers property_id as referring to a property with the name name in a parent class or in an interface
  986. -- implemented by oclass. This allows this class to override a property implementation in a parent class or to
  987. -- provide the implementation of a property from an interface.
  988. -- Note
  989. -- Internally, overriding is implemented by creating a property of type GParamSpecOverride; generally operations
  990. -- that query the properties of the object class, such as g_object_class_find_property() or
  991. -- g_object_class_list_properties() will return the overridden property. However, in one case, the
  992. -- construct_properties argument of the constructor virtual function, the GParamSpecOverride is passed instead, so
  993. -- that the param_id field of the GParamSpec will be correct. For virtually all uses, this makes no difference. If
  994. -- you need to get the overridden property, you can call g_param_spec_get_redirect_target().
  995. -- oclass : a GObjectClass
  996. -- property_id : the new property ID
  997. -- name : the name of a property registered in a parent class or in an interface of this class.
  998. -- ----------------------------------------------------------------------------------------------------------------
  999. -- g_object_interface_install_property ()
  1000. -- void g_object_interface_install_property
  1001. -- (gpointer g_iface,
  1002. -- GParamSpec *pspec);
  1003. -- Add a property to an interface; this is only useful for interfaces that are added to GObject-derived types.
  1004. -- Adding a property to an interface forces all objects classes with that interface to have a compatible property.
  1005. -- The compatible property could be a newly created GParamSpec, but normally g_object_class_override_property()
  1006. -- will be used so that the object class only needs to provide an implementation and inherits the property
  1007. -- description, default value, bounds, and so forth from the interface property.
  1008. -- This function is meant to be called from the interface's default vtable initialization function (the class_init
  1009. -- member of GTypeInfo.) It must not be called after after class_init has been called for any object types
  1010. -- implementing this interface.
  1011. -- g_iface : any interface vtable for the interface, or the default vtable for the interface.
  1012. -- pspec : the GParamSpec for the new property
  1013. -- Since 2.4
  1014. -- ----------------------------------------------------------------------------------------------------------------
  1015. -- g_object_interface_find_property ()
  1016. -- GParamSpec* g_object_interface_find_property
  1017. -- (gpointer g_iface,
  1018. -- const gchar *property_name);
  1019. -- Find the GParamSpec with the given name for an interface. Generally, the interface vtable passed in as g_iface
  1020. -- will be the default vtable from g_type_default_interface_ref(), or, if you know the interface has already been
  1021. -- loaded, g_type_default_interface_peek().
  1022. -- g_iface : any interface vtable for the interface, or the default vtable for the interface
  1023. -- property_name : name of a property to lookup.
  1024. -- Returns : the GParamSpec for the property of the interface with the name property_name, or NULL if no such
  1025. -- property exists.
  1026. -- Since 2.4
  1027. -- ----------------------------------------------------------------------------------------------------------------
  1028. -- g_object_interface_list_properties ()
  1029. -- GParamSpec** g_object_interface_list_properties
  1030. -- (gpointer g_iface,
  1031. -- guint *n_properties_p);
  1032. -- Lists the properties of an interface.Generally, the interface vtable passed in as g_iface will be the default
  1033. -- vtable from g_type_default_interface_ref(), or, if you know the interface has already been loaded,
  1034. -- g_type_default_interface_peek().
  1035. -- g_iface : any interface vtable for the interface, or the default vtable for the interface
  1036. -- n_properties_p : location to store number of properties returned.
  1037. -- Returns : a pointer to an array of pointers to GParamSpec structures. The paramspecs are owned by GLib,
  1038. -- but the array should be freed with g_free() when you are done with it.
  1039. -- Since 2.4
  1040. -- ----------------------------------------------------------------------------------------------------------------
  1041. -- g_object_new ()
  1042. -- gpointer g_object_new (GType object_type,
  1043. -- const gchar *first_property_name,
  1044. -- ...);
  1045. -- Creates a new instance of a GObject subtype and sets its properties.
  1046. -- Construction parameters (see G_PARAM_CONSTRUCT, G_PARAM_CONSTRUCT_ONLY) which are not explicitly specified are
  1047. -- set to their default values.
  1048. -- object_type : the type id of the GObject subtype to instantiate
  1049. -- first_property_name : the name of the first property
  1050. -- ... : the value of the first property, followed optionally by more name/value pairs, followed by
  1051. -- NULL
  1052. -- Returns : a new instance of object_type
  1053. -- ----------------------------------------------------------------------------------------------------------------
  1054. -- g_object_newv ()
  1055. -- gpointer g_object_newv (GType object_type,
  1056. -- guint n_parameters,
  1057. -- GParameter *parameters);
  1058. -- Creates a new instance of a GObject subtype and sets its properties.
  1059. -- Construction parameters (see G_PARAM_CONSTRUCT, G_PARAM_CONSTRUCT_ONLY) which are not explicitly specified are
  1060. -- set to their default values.
  1061. -- object_type : the type id of the GObject subtype to instantiate
  1062. -- n_parameters : the length of the parameters array
  1063. -- parameters : an array of GParameter
  1064. -- Returns : a new instance of object_type
  1065. -- ----------------------------------------------------------------------------------------------------------------
  1066. -- GParameter
  1067. -- typedef struct {
  1068. -- const gchar *name;
  1069. -- GValue value;
  1070. -- } GParameter;
  1071. -- The GParameter struct is an auxiliary structure used to hand parameter name/value pairs to g_object_newv().
  1072. -- const gchar *name; the parameter name
  1073. -- GValue value; the parameter value
  1074. -- ----------------------------------------------------------------------------------------------------------------
  1075. -- g_object_ref ()
  1076. -- gpointer g_object_ref (gpointer object);
  1077. -- Increases the reference count of object.
  1078. -- object : a GObject
  1079. -- Returns : object
  1080. -- ----------------------------------------------------------------------------------------------------------------
  1081. -- g_object_unref ()
  1082. -- void g_object_unref (gpointer object);
  1083. -- Decreases the reference count if object. When its reference count drops to 0, the object is finalized (i.e. its
  1084. -- memory is freed).
  1085. -- object : a GObject
  1086. -- ----------------------------------------------------------------------------------------------------------------
  1087. -- g_object_ref_sink ()
  1088. -- gpointer g_object_ref_sink (gpointer object);
  1089. -- Increase the reference count of object, and possibly remove the floating reference, if object has a floating
  1090. -- reference.
  1091. -- object : a GObject
  1092. -- Returns : object
  1093. -- Since 2.10
  1094. -- ----------------------------------------------------------------------------------------------------------------
  1095. is_floating: BOOLEAN is
  1096. -- TRUE if the object still has its floating reference count.
  1097. require
  1098. handle.is_not_null
  1099. do
  1100. Result:= (g_object_is_floating(handle)).to_boolean
  1101. end
  1102. -- ----------------------------------------------------------------------------------------------------------------
  1103. -- g_object_force_floating ()
  1104. -- void g_object_force_floating (GObject *object);
  1105. -- This function is intended for GObject implementations to re-enforce a floating object reference. Doing this is
  1106. -- seldomly required, all GObjects are created with a floating reference which usually just needs to be sunken by
  1107. -- calling g_object_ref_sink().
  1108. -- object : a GObject
  1109. -- Since 2.10
  1110. -- ----------------------------------------------------------------------------------------------------------------
  1111. -- GWeakNotify ()
  1112. -- void (*GWeakNotify) (gpointer data,
  1113. -- GObject *where_the_object_was);
  1114. -- A GWeakNotify function can be added to an object as a callback that gets triggered when the object is finalized.
  1115. -- Since the object is already being finalized when the GWeakNotify is called, there's not much you could do with
  1116. -- the object, apart from e.g. using its adress as hash-index or the like.
  1117. -- data : data that was provided when the weak reference was established
  1118. -- where_the_object_was : the object being finalized
  1119. -- ----------------------------------------------------------------------------------------------------------------
  1120. -- g_object_weak_ref ()
  1121. -- void g_object_weak_ref (GObject *object,
  1122. -- GWeakNotify notify,
  1123. -- gpointer data);
  1124. -- Adds a weak reference callback to an object. Weak references are used for notification when an object is
  1125. -- finalized. They are called "weak references" because they allow you to safely hold a pointer to an object
  1126. -- without calling g_object_ref() (g_object_ref() adds a strong reference, that is, forces the object to stay
  1127. -- alive).
  1128. -- object : GObject to reference weakly
  1129. -- notify : callback to invoke before the object is freed
  1130. -- data : extra data to pass to notify
  1131. -- ----------------------------------------------------------------------------------------------------------------
  1132. -- g_object_weak_unref ()
  1133. -- void g_object_weak_unref (GObject *object,
  1134. -- GWeakNotify notify,
  1135. -- gpointer data);
  1136. -- Removes a weak reference callback to an object.
  1137. -- object : GObject to remove a weak reference from
  1138. -- notify : callback to search for
  1139. -- data : data to search for
  1140. -- ----------------------------------------------------------------------------------------------------------------
  1141. -- g_object_add_weak_pointer ()
  1142. -- void g_object_add_weak_pointer (GObject *object,
  1143. -- gpointer *weak_pointer_location);
  1144. -- Adds a weak reference from weak_pointer to object to indicate that the pointer located at weak_pointer_location
  1145. -- is only valid during the lifetime of object. When the object is finalized, weak_pointer will be set to NULL.
  1146. -- object : The object that should be weak referenced.
  1147. -- weak_pointer_location : The memory address of a pointer.
  1148. -- ----------------------------------------------------------------------------------------------------------------
  1149. -- g_object_remove_weak_pointer ()
  1150. -- void g_object_remove_weak_pointer (GObject *object,
  1151. -- gpointer *weak_pointer_location);
  1152. -- Removes a weak reference from object that was previously added using g_object_add_weak_pointer(). The
  1153. -- weak_pointer_location has to match the one used with g_object_add_weak_pointer().
  1154. -- object : The object that is weak referenced.
  1155. -- weak_pointer_location : The memory address of a pointer.
  1156. -- ----------------------------------------------------------------------------------------------------------------
  1157. -- GToggleNotify ()
  1158. -- void (*GToggleNotify) (gpointer data,
  1159. -- GObject *object,
  1160. -- gboolean is_last_ref);
  1161. -- A callback function used for notification when the state of a toggle reference changes. See
  1162. -- g_object_add_toggle_ref().
  1163. -- data : Callback data passed to g_object_add_toggle_ref()
  1164. -- object : The object on which g_object_add_toggle_ref() was called.
  1165. -- is_last_ref : TRUE if the toggle reference is now the last reference to the object. FALSE if the toggle
  1166. -- reference was the last reference and there are now other references.
  1167. -- ----------------------------------------------------------------------------------------------------------------
  1168. -- g_object_add_toggle_ref ()
  1169. -- void g_object_add_toggle_ref (GObject *object,
  1170. -- GToggleNotify notify,
  1171. -- gpointer data);
  1172. -- Increases the reference count of the object by one and sets a callback to be called when all other references to
  1173. -- the object are dropped, or when this is already the last reference to the object and another reference is
  1174. -- established.
  1175. -- This functionality is intended for binding object to a proxy object managed by another memory manager. This is
  1176. -- done with two paired references: the strong reference added by g_object_add_toggle_ref() and a reverse reference
  1177. -- to the proxy object which is either a strong reference or weak reference.
  1178. -- The setup is that when there are no other references to object, only a weak reference is held in the reverse
  1179. -- direction from object to the proxy object, but when there are other references held to object, a strong
  1180. -- reference is held. The notify callback is called when the reference from object to the proxy object should be
  1181. -- toggled from strong to weak (is_last_ref true) or weak to strong (is_last_ref false).
  1182. -- Since a (normal) reference must be held to the object before calling g_object_toggle_ref(), the initial state of
  1183. -- the reverse link is always strong.
  1184. -- Multiple toggle references may be added to the same gobject, however if there are multiple toggle references to
  1185. -- an object, none of them will ever be notified until all but one are removed. For this reason, you should only
  1186. -- ever use a toggle reference if there is important state in the proxy object.
  1187. -- object : a GObject
  1188. -- notify : a function to call when this reference is the last reference to the object, or is no longer the last
  1189. -- reference.
  1190. -- data : data to pass to notify
  1191. -- ----------------------------------------------------------------------------------------------------------------
  1192. -- g_object_remove_toggle_ref ()
  1193. -- void g_object_remove_toggle_ref (GObject *object,
  1194. -- GToggleNotify notify,
  1195. -- gpointer data);
  1196. -- Removes a reference added with g_object_add_toggle_ref(). The reference count of the object is decreased by one.
  1197. -- object : a GObject
  1198. -- notify : a function to call when this reference is the last reference to the object, or is no longer the last
  1199. -- reference.
  1200. -- data : data to pass to notify
  1201. -- ----------------------------------------------------------------------------------------------------------------
  1202. -- g_object_connect ()
  1203. -- gpointer g_object_connect (gpointer object,
  1204. -- const gchar *signal_spec,
  1205. -- ...);
  1206. -- A convenience function to connect multiple signals at once.
  1207. -- The signal specs expected by this function have the form "modifier::signal_name", where modifier can be one of
  1208. -- the following:
  1209. -- signal equivalent to g_signal_connect_data (...)
  1210. -- object_signal, object-signal equivalent to g_signal_connect_object (...)
  1211. -- swapped_signal, swapped-signal equivalent to g_signal_connect_data (..., G_CONNECT_SWAPPED)
  1212. -- swapped_object_signal, swapped-object-signal equivalent to g_signal_connect_object (..., G_CONNECT_SWAPPED)
  1213. -- signal_after, signal-after equivalent to g_signal_connect_data (..., G_CONNECT_AFTER)
  1214. -- object_signal_after, object-signal-after equivalent to g_signal_connect_object (..., G_CONNECT_AFTER)
  1215. -- swapped_signal_after, swapped-signal-after equivalent to g_signal_connect_data (..., G_CONNECT_SWAPPED |
  1216. -- G_CONNECT_AFTER)
  1217. -- swapped_object_signal_after, equivalent to g_signal_connect_object (..., G_CONNECT_SWAPPED |
  1218. -- swapped-object-signal-after G_CONNECT_AFTER)
  1219. -- menu->toplevel = g_object_connect (g_object_new (GTK_TYPE_WINDOW,
  1220. -- "type", GTK_WINDOW_POPUP,
  1221. -- "child", menu,
  1222. -- NULL),
  1223. -- "signal::event", gtk_menu_window_event, menu,
  1224. -- "signal::size_request", gtk_menu_window_size_request, menu,
  1225. -- "signal::destroy", gtk_widget_destroyed, &menu->toplevel,
  1226. -- NULL);
  1227. -- object : a GObject
  1228. -- signal_spec : the spec for the first signal
  1229. -- ... : GCallback for the first signal, followed by data for the first signal, followed optionally by more
  1230. -- signal spec/callback/data triples, followed by NULL
  1231. -- Returns : object
  1232. -- ----------------------------------------------------------------------------------------------------------------
  1233. -- g_object_disconnect ()
  1234. -- void g_object_disconnect (gpointer object,
  1235. -- const gchar *signal_spec,
  1236. -- ...);
  1237. -- A convenience function to disconnect multiple signals at once.
  1238. -- The signal specs expected by this function have the form "any_signal", which means to disconnect any signal with
  1239. -- matching callback and data, or "any_signal::signal_name", which only disconnects the signal named "signal_name".
  1240. -- object : a GObject
  1241. -- signal_spec : the spec for the first signal
  1242. -- ... : GCallback for the first signal, followed by data for the first signal, followed optionally by more
  1243. -- signal spec/callback/data triples, followed by NULL
  1244. -- ----------------------------------------------------------------------------------------------------------------
  1245. -- g_object_set ()
  1246. -- void g_object_set (gpointer object,
  1247. -- const gchar *first_property_name,
  1248. -- ...);
  1249. -- Sets properties on an object.
  1250. -- object : a GObject
  1251. -- first_property_name : name of the first property to set
  1252. -- ... : value for the first property, followed optionally by more name/value pairs, followed by
  1253. --