gbinding.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* gbinding.h: Binding for object properties
  2. *
  3. * Copyright (C) 2010 Intel Corp.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General
  16. * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * Author: Emmanuele Bassi <[email protected]>
  19. */
  20. #ifndef __G_BINDING_H__
  21. #define __G_BINDING_H__
  22. #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
  23. #error "Only <glib-object.h> can be included directly."
  24. #endif
  25. #include <glib.h>
  26. #include <gobject/gobject.h>
  27. G_BEGIN_DECLS
  28. #define G_TYPE_BINDING_FLAGS (g_binding_flags_get_type ())
  29. #define G_TYPE_BINDING (g_binding_get_type ())
  30. #define G_BINDING(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), G_TYPE_BINDING, GBinding))
  31. #define G_IS_BINDING(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), G_TYPE_BINDING))
  32. /**
  33. * GBinding:
  34. *
  35. * GBinding is an opaque structure whose members
  36. * cannot be accessed directly.
  37. *
  38. * Since: 2.26
  39. */
  40. typedef struct _GBinding GBinding;
  41. /**
  42. * GBindingTransformFunc:
  43. * @binding: a #GBinding
  44. * @from_value: the #GValue containing the value to transform
  45. * @to_value: the #GValue in which to store the transformed value
  46. * @user_data: data passed to the transform function
  47. *
  48. * A function to be called to transform @from_value to @to_value. If
  49. * this is the @transform_to function of a binding, then @from_value
  50. * is the @source_property on the @source object, and @to_value is the
  51. * @target_property on the @target object. If this is the
  52. * @transform_from function of a %G_BINDING_BIDIRECTIONAL binding,
  53. * then those roles are reversed.
  54. *
  55. * Returns: %TRUE if the transformation was successful, and %FALSE
  56. * otherwise
  57. *
  58. * Since: 2.26
  59. */
  60. typedef gboolean (* GBindingTransformFunc) (GBinding *binding,
  61. const GValue *from_value,
  62. GValue *to_value,
  63. gpointer user_data);
  64. /**
  65. * GBindingFlags:
  66. * @G_BINDING_DEFAULT: The default binding; if the source property
  67. * changes, the target property is updated with its value.
  68. * @G_BINDING_BIDIRECTIONAL: Bidirectional binding; if either the
  69. * property of the source or the property of the target changes,
  70. * the other is updated.
  71. * @G_BINDING_SYNC_CREATE: Synchronize the values of the source and
  72. * target properties when creating the binding; the direction of
  73. * the synchronization is always from the source to the target.
  74. * @G_BINDING_INVERT_BOOLEAN: If the two properties being bound are
  75. * booleans, setting one to %TRUE will result in the other being
  76. * set to %FALSE and vice versa. This flag will only work for
  77. * boolean properties, and cannot be used when passing custom
  78. * transformation functions to g_object_bind_property_full().
  79. *
  80. * Flags to be passed to g_object_bind_property() or
  81. * g_object_bind_property_full().
  82. *
  83. * This enumeration can be extended at later date.
  84. *
  85. * Since: 2.26
  86. */
  87. typedef enum { /*< prefix=G_BINDING >*/
  88. G_BINDING_DEFAULT = 0,
  89. G_BINDING_BIDIRECTIONAL = 1 << 0,
  90. G_BINDING_SYNC_CREATE = 1 << 1,
  91. G_BINDING_INVERT_BOOLEAN = 1 << 2
  92. } GBindingFlags;
  93. GLIB_AVAILABLE_IN_ALL
  94. GType g_binding_flags_get_type (void) G_GNUC_CONST;
  95. GLIB_AVAILABLE_IN_ALL
  96. GType g_binding_get_type (void) G_GNUC_CONST;
  97. GLIB_AVAILABLE_IN_ALL
  98. GBindingFlags g_binding_get_flags (GBinding *binding);
  99. GLIB_AVAILABLE_IN_ALL
  100. GObject * g_binding_get_source (GBinding *binding);
  101. GLIB_AVAILABLE_IN_ALL
  102. GObject * g_binding_get_target (GBinding *binding);
  103. GLIB_AVAILABLE_IN_ALL
  104. const gchar * g_binding_get_source_property (GBinding *binding);
  105. GLIB_AVAILABLE_IN_ALL
  106. const gchar * g_binding_get_target_property (GBinding *binding);
  107. GLIB_AVAILABLE_IN_2_38
  108. void g_binding_unbind (GBinding *binding);
  109. GLIB_AVAILABLE_IN_ALL
  110. GBinding *g_object_bind_property (gpointer source,
  111. const gchar *source_property,
  112. gpointer target,
  113. const gchar *target_property,
  114. GBindingFlags flags);
  115. GLIB_AVAILABLE_IN_ALL
  116. GBinding *g_object_bind_property_full (gpointer source,
  117. const gchar *source_property,
  118. gpointer target,
  119. const gchar *target_property,
  120. GBindingFlags flags,
  121. GBindingTransformFunc transform_to,
  122. GBindingTransformFunc transform_from,
  123. gpointer user_data,
  124. GDestroyNotify notify);
  125. GLIB_AVAILABLE_IN_ALL
  126. GBinding *g_object_bind_property_with_closures (gpointer source,
  127. const gchar *source_property,
  128. gpointer target,
  129. const gchar *target_property,
  130. GBindingFlags flags,
  131. GClosure *transform_to,
  132. GClosure *transform_from);
  133. G_END_DECLS
  134. #endif /* __G_BINDING_H__ */