gsignal.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. /* GObject - GLib Type, Object, Parameter and Signal Library
  2. * Copyright (C) 2000-2001 Red Hat, Inc.
  3. *
  4. * SPDX-License-Identifier: LGPL-2.1-or-later
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General
  17. * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef __G_SIGNAL_H__
  20. #define __G_SIGNAL_H__
  21. #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
  22. #error "Only <glib-object.h> can be included directly."
  23. #endif
  24. #include <gobject/gclosure.h>
  25. #include <gobject/gvalue.h>
  26. #include <gobject/gparam.h>
  27. #include <gobject/gmarshal.h>
  28. G_BEGIN_DECLS
  29. /* --- typedefs --- */
  30. typedef struct _GSignalQuery GSignalQuery;
  31. typedef struct _GSignalInvocationHint GSignalInvocationHint;
  32. /**
  33. * GSignalCMarshaller:
  34. *
  35. * This is the signature of marshaller functions, required to marshall
  36. * arrays of parameter values to signal emissions into C language callback
  37. * invocations.
  38. *
  39. * It is merely an alias to #GClosureMarshal since the #GClosure mechanism
  40. * takes over responsibility of actual function invocation for the signal
  41. * system.
  42. */
  43. typedef GClosureMarshal GSignalCMarshaller;
  44. /**
  45. * GSignalCVaMarshaller:
  46. *
  47. * This is the signature of va_list marshaller functions, an optional
  48. * marshaller that can be used in some situations to avoid
  49. * marshalling the signal argument into GValues.
  50. */
  51. typedef GVaClosureMarshal GSignalCVaMarshaller;
  52. /**
  53. * GSignalEmissionHook:
  54. * @ihint: Signal invocation hint, see #GSignalInvocationHint.
  55. * @n_param_values: the number of parameters to the function, including
  56. * the instance on which the signal was emitted.
  57. * @param_values: (array length=n_param_values): the instance on which
  58. * the signal was emitted, followed by the parameters of the emission.
  59. * @data: user data associated with the hook.
  60. *
  61. * A simple function pointer to get invoked when the signal is emitted.
  62. *
  63. * Emission hooks allow you to tie a hook to the signal type, so that it will
  64. * trap all emissions of that signal, from any object.
  65. *
  66. * You may not attach these to signals created with the %G_SIGNAL_NO_HOOKS flag.
  67. *
  68. * Returns: whether it wants to stay connected. If it returns %FALSE, the signal
  69. * hook is disconnected (and destroyed).
  70. */
  71. typedef gboolean (*GSignalEmissionHook) (GSignalInvocationHint *ihint,
  72. guint n_param_values,
  73. const GValue *param_values,
  74. gpointer data);
  75. /**
  76. * GSignalAccumulator:
  77. * @ihint: Signal invocation hint, see #GSignalInvocationHint.
  78. * @return_accu: Accumulator to collect callback return values in, this
  79. * is the return value of the current signal emission.
  80. * @handler_return: A #GValue holding the return value of the signal handler.
  81. * @data: Callback data that was specified when creating the signal.
  82. *
  83. * The signal accumulator is a special callback function that can be used
  84. * to collect return values of the various callbacks that are called
  85. * during a signal emission.
  86. *
  87. * The signal accumulator is specified at signal creation time, if it is
  88. * left %NULL, no accumulation of callback return values is performed.
  89. * The return value of signal emissions is then the value returned by the
  90. * last callback.
  91. *
  92. * Returns: The accumulator function returns whether the signal emission
  93. * should be aborted. Returning %TRUE will continue with
  94. * the signal emission. Returning %FALSE will abort the current emission.
  95. * Since 2.62, returning %FALSE will skip to the CLEANUP stage. In this case,
  96. * emission will occur as normal in the CLEANUP stage and the handler's
  97. * return value will be accumulated.
  98. */
  99. typedef gboolean (*GSignalAccumulator) (GSignalInvocationHint *ihint,
  100. GValue *return_accu,
  101. const GValue *handler_return,
  102. gpointer data);
  103. /* --- run, match and connect types --- */
  104. /**
  105. * GSignalFlags:
  106. * @G_SIGNAL_RUN_FIRST: Invoke the object method handler in the first emission stage.
  107. * @G_SIGNAL_RUN_LAST: Invoke the object method handler in the third emission stage.
  108. * @G_SIGNAL_RUN_CLEANUP: Invoke the object method handler in the last emission stage.
  109. * @G_SIGNAL_NO_RECURSE: Signals being emitted for an object while currently being in
  110. * emission for this very object will not be emitted recursively,
  111. * but instead cause the first emission to be restarted.
  112. * @G_SIGNAL_DETAILED: This signal supports "::detail" appendices to the signal name
  113. * upon handler connections and emissions.
  114. * @G_SIGNAL_ACTION: Action signals are signals that may freely be emitted on alive
  115. * objects from user code via g_signal_emit() and friends, without
  116. * the need of being embedded into extra code that performs pre or
  117. * post emission adjustments on the object. They can also be thought
  118. * of as object methods which can be called generically by
  119. * third-party code.
  120. * @G_SIGNAL_NO_HOOKS: No emissions hooks are supported for this signal.
  121. * @G_SIGNAL_MUST_COLLECT: Varargs signal emission will always collect the
  122. * arguments, even if there are no signal handlers connected. Since 2.30.
  123. * @G_SIGNAL_DEPRECATED: The signal is deprecated and will be removed
  124. * in a future version. A warning will be generated if it is connected while
  125. * running with G_ENABLE_DIAGNOSTIC=1. Since 2.32.
  126. * @G_SIGNAL_ACCUMULATOR_FIRST_RUN: Only used in #GSignalAccumulator accumulator
  127. * functions for the #GSignalInvocationHint::run_type field to mark the first
  128. * call to the accumulator function for a signal emission. Since 2.68.
  129. *
  130. * The signal flags are used to specify a signal's behaviour.
  131. */
  132. typedef enum
  133. {
  134. G_SIGNAL_RUN_FIRST = 1 << 0,
  135. G_SIGNAL_RUN_LAST = 1 << 1,
  136. G_SIGNAL_RUN_CLEANUP = 1 << 2,
  137. G_SIGNAL_NO_RECURSE = 1 << 3,
  138. G_SIGNAL_DETAILED = 1 << 4,
  139. G_SIGNAL_ACTION = 1 << 5,
  140. G_SIGNAL_NO_HOOKS = 1 << 6,
  141. G_SIGNAL_MUST_COLLECT = 1 << 7,
  142. G_SIGNAL_DEPRECATED = 1 << 8,
  143. /* normal signal flags until 1 << 16 */
  144. G_SIGNAL_ACCUMULATOR_FIRST_RUN = 1 << 17,
  145. } GSignalFlags;
  146. /**
  147. * G_SIGNAL_FLAGS_MASK:
  148. *
  149. * A mask for all #GSignalFlags bits.
  150. */
  151. #define G_SIGNAL_FLAGS_MASK 0x1ff
  152. /**
  153. * GConnectFlags:
  154. * @G_CONNECT_DEFAULT: Default behaviour (no special flags). Since: 2.74
  155. * @G_CONNECT_AFTER: If set, the handler should be called after the
  156. * default handler of the signal. Normally, the handler is called before
  157. * the default handler.
  158. * @G_CONNECT_SWAPPED: If set, the instance and data should be swapped when
  159. * calling the handler; see g_signal_connect_swapped() for an example.
  160. *
  161. * The connection flags are used to specify the behaviour of a signal's
  162. * connection.
  163. */
  164. typedef enum
  165. {
  166. G_CONNECT_DEFAULT GOBJECT_AVAILABLE_ENUMERATOR_IN_2_74 = 0,
  167. G_CONNECT_AFTER = 1 << 0,
  168. G_CONNECT_SWAPPED = 1 << 1
  169. } GConnectFlags;
  170. /**
  171. * GSignalMatchType:
  172. * @G_SIGNAL_MATCH_ID: The signal id must be equal.
  173. * @G_SIGNAL_MATCH_DETAIL: The signal detail must be equal.
  174. * @G_SIGNAL_MATCH_CLOSURE: The closure must be the same.
  175. * @G_SIGNAL_MATCH_FUNC: The C closure callback must be the same.
  176. * @G_SIGNAL_MATCH_DATA: The closure data must be the same.
  177. * @G_SIGNAL_MATCH_UNBLOCKED: Only unblocked signals may be matched.
  178. *
  179. * The match types specify what g_signal_handlers_block_matched(),
  180. * g_signal_handlers_unblock_matched() and g_signal_handlers_disconnect_matched()
  181. * match signals by.
  182. */
  183. typedef enum
  184. {
  185. G_SIGNAL_MATCH_ID = 1 << 0,
  186. G_SIGNAL_MATCH_DETAIL = 1 << 1,
  187. G_SIGNAL_MATCH_CLOSURE = 1 << 2,
  188. G_SIGNAL_MATCH_FUNC = 1 << 3,
  189. G_SIGNAL_MATCH_DATA = 1 << 4,
  190. G_SIGNAL_MATCH_UNBLOCKED = 1 << 5
  191. } GSignalMatchType;
  192. /**
  193. * G_SIGNAL_MATCH_MASK:
  194. *
  195. * A mask for all #GSignalMatchType bits.
  196. */
  197. #define G_SIGNAL_MATCH_MASK 0x3f
  198. /**
  199. * G_SIGNAL_TYPE_STATIC_SCOPE:
  200. *
  201. * This macro flags signal argument types for which the signal system may
  202. * assume that instances thereof remain persistent across all signal emissions
  203. * they are used in. This is only useful for non ref-counted, value-copy types.
  204. *
  205. * To flag a signal argument in this way, add `| G_SIGNAL_TYPE_STATIC_SCOPE`
  206. * to the corresponding argument of g_signal_new().
  207. * |[
  208. * g_signal_new ("size_request",
  209. * G_TYPE_FROM_CLASS (gobject_class),
  210. * G_SIGNAL_RUN_FIRST,
  211. * G_STRUCT_OFFSET (GtkWidgetClass, size_request),
  212. * NULL, NULL,
  213. * _gtk_marshal_VOID__BOXED,
  214. * G_TYPE_NONE, 1,
  215. * GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
  216. * ]|
  217. */
  218. #define G_SIGNAL_TYPE_STATIC_SCOPE (G_TYPE_FLAG_RESERVED_ID_BIT)
  219. /* --- signal information --- */
  220. /**
  221. * GSignalInvocationHint:
  222. * @signal_id: The signal id of the signal invoking the callback
  223. * @detail: The detail passed on for this emission
  224. * @run_type: The stage the signal emission is currently in, this
  225. * field will contain one of %G_SIGNAL_RUN_FIRST,
  226. * %G_SIGNAL_RUN_LAST or %G_SIGNAL_RUN_CLEANUP and %G_SIGNAL_ACCUMULATOR_FIRST_RUN.
  227. * %G_SIGNAL_ACCUMULATOR_FIRST_RUN is only set for the first run of the accumulator
  228. * function for a signal emission.
  229. *
  230. * The #GSignalInvocationHint structure is used to pass on additional information
  231. * to callbacks during a signal emission.
  232. */
  233. struct _GSignalInvocationHint
  234. {
  235. guint signal_id;
  236. GQuark detail;
  237. GSignalFlags run_type;
  238. };
  239. /**
  240. * GSignalQuery:
  241. * @signal_id: The signal id of the signal being queried, or 0 if the
  242. * signal to be queried was unknown.
  243. * @signal_name: The signal name.
  244. * @itype: The interface/instance type that this signal can be emitted for.
  245. * @signal_flags: The signal flags as passed in to g_signal_new().
  246. * @return_type: The return type for user callbacks.
  247. * @n_params: The number of parameters that user callbacks take.
  248. * @param_types: (array length=n_params): The individual parameter types for
  249. * user callbacks, note that the effective callback signature is:
  250. * |[<!-- language="C" -->
  251. * @return_type callback (#gpointer data1,
  252. * [param_types param_names,]
  253. * gpointer data2);
  254. * ]|
  255. *
  256. * A structure holding in-depth information for a specific signal.
  257. *
  258. * See also: g_signal_query()
  259. */
  260. struct _GSignalQuery
  261. {
  262. guint signal_id;
  263. const gchar *signal_name;
  264. GType itype;
  265. GSignalFlags signal_flags;
  266. GType return_type; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
  267. guint n_params;
  268. const GType *param_types; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
  269. };
  270. /* --- signals --- */
  271. GOBJECT_AVAILABLE_IN_ALL
  272. guint g_signal_newv (const gchar *signal_name,
  273. GType itype,
  274. GSignalFlags signal_flags,
  275. GClosure *class_closure,
  276. GSignalAccumulator accumulator,
  277. gpointer accu_data,
  278. GSignalCMarshaller c_marshaller,
  279. GType return_type,
  280. guint n_params,
  281. GType *param_types);
  282. GOBJECT_AVAILABLE_IN_ALL
  283. guint g_signal_new_valist (const gchar *signal_name,
  284. GType itype,
  285. GSignalFlags signal_flags,
  286. GClosure *class_closure,
  287. GSignalAccumulator accumulator,
  288. gpointer accu_data,
  289. GSignalCMarshaller c_marshaller,
  290. GType return_type,
  291. guint n_params,
  292. va_list args);
  293. GOBJECT_AVAILABLE_IN_ALL
  294. guint g_signal_new (const gchar *signal_name,
  295. GType itype,
  296. GSignalFlags signal_flags,
  297. guint class_offset,
  298. GSignalAccumulator accumulator,
  299. gpointer accu_data,
  300. GSignalCMarshaller c_marshaller,
  301. GType return_type,
  302. guint n_params,
  303. ...);
  304. GOBJECT_AVAILABLE_IN_ALL
  305. guint g_signal_new_class_handler (const gchar *signal_name,
  306. GType itype,
  307. GSignalFlags signal_flags,
  308. GCallback class_handler,
  309. GSignalAccumulator accumulator,
  310. gpointer accu_data,
  311. GSignalCMarshaller c_marshaller,
  312. GType return_type,
  313. guint n_params,
  314. ...);
  315. GOBJECT_AVAILABLE_IN_ALL
  316. void g_signal_set_va_marshaller (guint signal_id,
  317. GType instance_type,
  318. GSignalCVaMarshaller va_marshaller);
  319. GOBJECT_AVAILABLE_IN_ALL
  320. void g_signal_emitv (const GValue *instance_and_params,
  321. guint signal_id,
  322. GQuark detail,
  323. GValue *return_value);
  324. GOBJECT_AVAILABLE_IN_ALL
  325. void g_signal_emit_valist (gpointer instance,
  326. guint signal_id,
  327. GQuark detail,
  328. va_list var_args);
  329. GOBJECT_AVAILABLE_IN_ALL
  330. void g_signal_emit (gpointer instance,
  331. guint signal_id,
  332. GQuark detail,
  333. ...);
  334. GOBJECT_AVAILABLE_IN_ALL
  335. void g_signal_emit_by_name (gpointer instance,
  336. const gchar *detailed_signal,
  337. ...);
  338. GOBJECT_AVAILABLE_IN_ALL
  339. guint g_signal_lookup (const gchar *name,
  340. GType itype);
  341. GOBJECT_AVAILABLE_IN_ALL
  342. const gchar * g_signal_name (guint signal_id);
  343. GOBJECT_AVAILABLE_IN_ALL
  344. void g_signal_query (guint signal_id,
  345. GSignalQuery *query);
  346. GOBJECT_AVAILABLE_IN_ALL
  347. guint* g_signal_list_ids (GType itype,
  348. guint *n_ids);
  349. GOBJECT_AVAILABLE_IN_2_66
  350. gboolean g_signal_is_valid_name (const gchar *name);
  351. GOBJECT_AVAILABLE_IN_ALL
  352. gboolean g_signal_parse_name (const gchar *detailed_signal,
  353. GType itype,
  354. guint *signal_id_p,
  355. GQuark *detail_p,
  356. gboolean force_detail_quark);
  357. GOBJECT_AVAILABLE_IN_ALL
  358. GSignalInvocationHint* g_signal_get_invocation_hint (gpointer instance);
  359. /* --- signal emissions --- */
  360. GOBJECT_AVAILABLE_IN_ALL
  361. void g_signal_stop_emission (gpointer instance,
  362. guint signal_id,
  363. GQuark detail);
  364. GOBJECT_AVAILABLE_IN_ALL
  365. void g_signal_stop_emission_by_name (gpointer instance,
  366. const gchar *detailed_signal);
  367. GOBJECT_AVAILABLE_IN_ALL
  368. gulong g_signal_add_emission_hook (guint signal_id,
  369. GQuark detail,
  370. GSignalEmissionHook hook_func,
  371. gpointer hook_data,
  372. GDestroyNotify data_destroy);
  373. GOBJECT_AVAILABLE_IN_ALL
  374. void g_signal_remove_emission_hook (guint signal_id,
  375. gulong hook_id);
  376. /* --- signal handlers --- */
  377. GOBJECT_AVAILABLE_IN_ALL
  378. gboolean g_signal_has_handler_pending (gpointer instance,
  379. guint signal_id,
  380. GQuark detail,
  381. gboolean may_be_blocked);
  382. GOBJECT_AVAILABLE_IN_ALL
  383. gulong g_signal_connect_closure_by_id (gpointer instance,
  384. guint signal_id,
  385. GQuark detail,
  386. GClosure *closure,
  387. gboolean after);
  388. GOBJECT_AVAILABLE_IN_ALL
  389. gulong g_signal_connect_closure (gpointer instance,
  390. const gchar *detailed_signal,
  391. GClosure *closure,
  392. gboolean after);
  393. GOBJECT_AVAILABLE_IN_ALL
  394. gulong g_signal_connect_data (gpointer instance,
  395. const gchar *detailed_signal,
  396. GCallback c_handler,
  397. gpointer data,
  398. GClosureNotify destroy_data,
  399. GConnectFlags connect_flags);
  400. GOBJECT_AVAILABLE_IN_ALL
  401. void g_signal_handler_block (gpointer instance,
  402. gulong handler_id);
  403. GOBJECT_AVAILABLE_IN_ALL
  404. void g_signal_handler_unblock (gpointer instance,
  405. gulong handler_id);
  406. GOBJECT_AVAILABLE_IN_ALL
  407. void g_signal_handler_disconnect (gpointer instance,
  408. gulong handler_id);
  409. GOBJECT_AVAILABLE_IN_ALL
  410. gboolean g_signal_handler_is_connected (gpointer instance,
  411. gulong handler_id);
  412. GOBJECT_AVAILABLE_IN_ALL
  413. gulong g_signal_handler_find (gpointer instance,
  414. GSignalMatchType mask,
  415. guint signal_id,
  416. GQuark detail,
  417. GClosure *closure,
  418. gpointer func,
  419. gpointer data);
  420. GOBJECT_AVAILABLE_IN_ALL
  421. guint g_signal_handlers_block_matched (gpointer instance,
  422. GSignalMatchType mask,
  423. guint signal_id,
  424. GQuark detail,
  425. GClosure *closure,
  426. gpointer func,
  427. gpointer data);
  428. GOBJECT_AVAILABLE_IN_ALL
  429. guint g_signal_handlers_unblock_matched (gpointer instance,
  430. GSignalMatchType mask,
  431. guint signal_id,
  432. GQuark detail,
  433. GClosure *closure,
  434. gpointer func,
  435. gpointer data);
  436. GOBJECT_AVAILABLE_IN_ALL
  437. guint g_signal_handlers_disconnect_matched (gpointer instance,
  438. GSignalMatchType mask,
  439. guint signal_id,
  440. GQuark detail,
  441. GClosure *closure,
  442. gpointer func,
  443. gpointer data);
  444. GOBJECT_AVAILABLE_IN_2_62
  445. void g_clear_signal_handler (gulong *handler_id_ptr,
  446. gpointer instance);
  447. #define g_clear_signal_handler(handler_id_ptr, instance) \
  448. G_STMT_START { \
  449. gpointer const _instance = (instance); \
  450. gulong *const _handler_id_ptr = (handler_id_ptr); \
  451. const gulong _handler_id = *_handler_id_ptr; \
  452. \
  453. if (_handler_id > 0) \
  454. { \
  455. *_handler_id_ptr = 0; \
  456. g_signal_handler_disconnect (_instance, _handler_id); \
  457. } \
  458. } G_STMT_END \
  459. GOBJECT_AVAILABLE_MACRO_IN_2_62
  460. /* --- overriding and chaining --- */
  461. GOBJECT_AVAILABLE_IN_ALL
  462. void g_signal_override_class_closure (guint signal_id,
  463. GType instance_type,
  464. GClosure *class_closure);
  465. GOBJECT_AVAILABLE_IN_ALL
  466. void g_signal_override_class_handler (const gchar *signal_name,
  467. GType instance_type,
  468. GCallback class_handler);
  469. GOBJECT_AVAILABLE_IN_ALL
  470. void g_signal_chain_from_overridden (const GValue *instance_and_params,
  471. GValue *return_value);
  472. GOBJECT_AVAILABLE_IN_ALL
  473. void g_signal_chain_from_overridden_handler (gpointer instance,
  474. ...);
  475. /* --- convenience --- */
  476. /**
  477. * g_signal_connect:
  478. * @instance: the instance to connect to.
  479. * @detailed_signal: a string of the form "signal-name::detail".
  480. * @c_handler: the #GCallback to connect.
  481. * @data: data to pass to @c_handler calls.
  482. *
  483. * Connects a [type@GObject.Callback] function to a signal for a particular object.
  484. *
  485. * The handler will be called synchronously, before the default handler of the signal.
  486. * [func@GObject.signal_emit] will not return control until all handlers are called.
  487. *
  488. * See [memory management of signal handlers](signals.html#Memory_management_of_signal_handlers) for
  489. * details on how to handle the return value and memory management of @data.
  490. *
  491. * This function cannot fail. If the given signal doesn’t exist, a critical
  492. * warning is emitted.
  493. *
  494. * Returns: the handler ID, of type `gulong` (always greater than 0)
  495. */
  496. /* Intentionally not using G_CONNECT_DEFAULT here to avoid deprecation
  497. * warnings with older GLIB_VERSION_MAX_ALLOWED */
  498. #define g_signal_connect(instance, detailed_signal, c_handler, data) \
  499. g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, (GConnectFlags) 0)
  500. /**
  501. * g_signal_connect_after:
  502. * @instance: the instance to connect to.
  503. * @detailed_signal: a string of the form "signal-name::detail".
  504. * @c_handler: the #GCallback to connect.
  505. * @data: data to pass to @c_handler calls.
  506. *
  507. * Connects a #GCallback function to a signal for a particular object.
  508. *
  509. * The handler will be called synchronously, after the default handler of the signal.
  510. *
  511. * This function cannot fail. If the given signal doesn’t exist, a critical
  512. * warning is emitted.
  513. *
  514. * Returns: the handler ID, of type `gulong` (always greater than 0)
  515. */
  516. #define g_signal_connect_after(instance, detailed_signal, c_handler, data) \
  517. g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, G_CONNECT_AFTER)
  518. /**
  519. * g_signal_connect_swapped:
  520. * @instance: the instance to connect to.
  521. * @detailed_signal: a string of the form "signal-name::detail".
  522. * @c_handler: the #GCallback to connect.
  523. * @data: data to pass to @c_handler calls.
  524. *
  525. * Connects a #GCallback function to a signal for a particular object.
  526. *
  527. * The instance on which the signal is emitted and @data will be swapped when
  528. * calling the handler. This is useful when calling pre-existing functions to
  529. * operate purely on the @data, rather than the @instance: swapping the
  530. * parameters avoids the need to write a wrapper function.
  531. *
  532. * For example, this allows the shorter code:
  533. * |[<!-- language="C" -->
  534. * g_signal_connect_swapped (button, "clicked",
  535. * (GCallback) gtk_widget_hide, other_widget);
  536. * ]|
  537. *
  538. * Rather than the cumbersome:
  539. * |[<!-- language="C" -->
  540. * static void
  541. * button_clicked_cb (GtkButton *button, GtkWidget *other_widget)
  542. * {
  543. * gtk_widget_hide (other_widget);
  544. * }
  545. *
  546. * ...
  547. *
  548. * g_signal_connect (button, "clicked",
  549. * (GCallback) button_clicked_cb, other_widget);
  550. * ]|
  551. *
  552. * This function cannot fail. If the given signal doesn’t exist, a critical
  553. * warning is emitted.
  554. *
  555. * Returns: the handler ID, of type `gulong` (always greater than 0)
  556. */
  557. #define g_signal_connect_swapped(instance, detailed_signal, c_handler, data) \
  558. g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, G_CONNECT_SWAPPED)
  559. /**
  560. * g_signal_handlers_disconnect_by_func:
  561. * @instance: The instance to remove handlers from.
  562. * @func: The C closure callback of the handlers (useless for non-C closures).
  563. * @data: The closure data of the handlers' closures.
  564. *
  565. * Disconnects all handlers on an instance that match @func and @data.
  566. *
  567. * Returns: The number of handlers that matched.
  568. */
  569. #define g_signal_handlers_disconnect_by_func(instance, func, data) \
  570. g_signal_handlers_disconnect_matched ((instance), \
  571. (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \
  572. 0, 0, NULL, (func), (data))
  573. /**
  574. * g_signal_handlers_disconnect_by_data:
  575. * @instance: The instance to remove handlers from
  576. * @data: the closure data of the handlers' closures
  577. *
  578. * Disconnects all handlers on an instance that match @data.
  579. *
  580. * Returns: The number of handlers that matched.
  581. *
  582. * Since: 2.32
  583. */
  584. #define g_signal_handlers_disconnect_by_data(instance, data) \
  585. g_signal_handlers_disconnect_matched ((instance), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, (data))
  586. /**
  587. * g_signal_handlers_block_by_func:
  588. * @instance: The instance to block handlers from.
  589. * @func: The C closure callback of the handlers (useless for non-C closures).
  590. * @data: The closure data of the handlers' closures.
  591. *
  592. * Blocks all handlers on an instance that match @func and @data.
  593. *
  594. * Returns: The number of handlers that matched.
  595. */
  596. #define g_signal_handlers_block_by_func(instance, func, data) \
  597. g_signal_handlers_block_matched ((instance), \
  598. (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \
  599. 0, 0, NULL, (func), (data))
  600. /**
  601. * g_signal_handlers_unblock_by_func:
  602. * @instance: The instance to unblock handlers from.
  603. * @func: The C closure callback of the handlers (useless for non-C closures).
  604. * @data: The closure data of the handlers' closures.
  605. *
  606. * Unblocks all handlers on an instance that match @func and @data.
  607. *
  608. * Returns: The number of handlers that matched.
  609. */
  610. #define g_signal_handlers_unblock_by_func(instance, func, data) \
  611. g_signal_handlers_unblock_matched ((instance), \
  612. (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \
  613. 0, 0, NULL, (func), (data))
  614. GOBJECT_AVAILABLE_IN_ALL
  615. gboolean g_signal_accumulator_true_handled (GSignalInvocationHint *ihint,
  616. GValue *return_accu,
  617. const GValue *handler_return,
  618. gpointer dummy);
  619. GOBJECT_AVAILABLE_IN_ALL
  620. gboolean g_signal_accumulator_first_wins (GSignalInvocationHint *ihint,
  621. GValue *return_accu,
  622. const GValue *handler_return,
  623. gpointer dummy);
  624. /*< private >*/
  625. GOBJECT_AVAILABLE_IN_ALL
  626. void g_signal_handlers_destroy (gpointer instance);
  627. void _g_signals_destroy (GType itype);
  628. G_END_DECLS
  629. #endif /* __G_SIGNAL_H__ */