gbinding.h 6.4 KB

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