選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

510 行
20 KiB

  1. /* GObject - GLib Type, Object, Parameter and Signal Library
  2. * Copyright (C) 2000-2001 Red Hat, Inc.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General
  15. * Public License along with this library; if not, write to the
  16. * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  17. * Boston, MA 02111-1307, USA.
  18. */
  19. #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
  20. #error "Only <glib-object.h> can be included directly."
  21. #endif
  22. #ifndef __G_SIGNAL_H__
  23. #define __G_SIGNAL_H__
  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. It is merely an alias to #GClosureMarshal since the #GClosure
  38. * mechanism takes over responsibility of actual function invocation for the
  39. * signal system.
  40. */
  41. typedef GClosureMarshal GSignalCMarshaller;
  42. /**
  43. * GSignalEmissionHook:
  44. * @ihint: Signal invocation hint, see #GSignalInvocationHint.
  45. * @n_param_values: the number of parameters to the function, including
  46. * the instance on which the signal was emitted.
  47. * @param_values: the instance on which the signal was emitted, followed by the
  48. * parameters of the emission.
  49. * @data: user data associated with the hook.
  50. *
  51. * A simple function pointer to get invoked when the signal is emitted. This
  52. * allows you to tie a hook to the signal type, so that it will trap all
  53. * emissions of that signal, from any object.
  54. *
  55. * You may not attach these to signals created with the #G_SIGNAL_NO_HOOKS flag.
  56. *
  57. * Returns: whether it wants to stay connected. If it returns %FALSE, the signal
  58. * hook is disconnected (and destroyed).
  59. */
  60. typedef gboolean (*GSignalEmissionHook) (GSignalInvocationHint *ihint,
  61. guint n_param_values,
  62. const GValue *param_values,
  63. gpointer data);
  64. /**
  65. * GSignalAccumulator:
  66. * @ihint: Signal invocation hint, see #GSignalInvocationHint.
  67. * @return_accu: Accumulator to collect callback return values in, this
  68. * is the return value of the current signal emission.
  69. * @handler_return: A #GValue holding the return value of the signal handler.
  70. * @data: Callback data that was specified when creating the signal.
  71. *
  72. * The signal accumulator is a special callback function that can be used
  73. * to collect return values of the various callbacks that are called
  74. * during a signal emission. The signal accumulator is specified at signal
  75. * creation time, if it is left %NULL, no accumulation of callback return
  76. * values is performed. The return value of signal emissions is then the
  77. * value returned by the last callback.
  78. *
  79. * Returns: The accumulator function returns whether the signal emission
  80. * should be aborted. Returning %FALSE means to abort the
  81. * current emission and %TRUE is returned for continuation.
  82. */
  83. typedef gboolean (*GSignalAccumulator) (GSignalInvocationHint *ihint,
  84. GValue *return_accu,
  85. const GValue *handler_return,
  86. gpointer data);
  87. /* --- run, match and connect types --- */
  88. /**
  89. * GSignalFlags:
  90. * @G_SIGNAL_RUN_FIRST: Invoke the object method handler in the first emission stage.
  91. * @G_SIGNAL_RUN_LAST: Invoke the object method handler in the third emission stage.
  92. * @G_SIGNAL_RUN_CLEANUP: Invoke the object method handler in the last emission stage.
  93. * @G_SIGNAL_NO_RECURSE: Signals being emitted for an object while currently being in
  94. * emission for this very object will not be emitted recursively,
  95. * but instead cause the first emission to be restarted.
  96. * @G_SIGNAL_DETAILED: This signal supports "::detail" appendices to the signal name
  97. * upon handler connections and emissions.
  98. * @G_SIGNAL_ACTION: Action signals are signals that may freely be emitted on alive
  99. * objects from user code via g_signal_emit() and friends, without
  100. * the need of being embedded into extra code that performs pre or
  101. * post emission adjustments on the object. They can also be thought
  102. * of as object methods which can be called generically by
  103. * third-party code.
  104. * @G_SIGNAL_NO_HOOKS: No emissions hooks are supported for this signal.
  105. *
  106. * The signal flags are used to specify a signal's behaviour, the overall
  107. * signal description outlines how especially the RUN flags control the
  108. * stages of a signal emission.
  109. */
  110. typedef enum
  111. {
  112. G_SIGNAL_RUN_FIRST = 1 << 0,
  113. G_SIGNAL_RUN_LAST = 1 << 1,
  114. G_SIGNAL_RUN_CLEANUP = 1 << 2,
  115. G_SIGNAL_NO_RECURSE = 1 << 3,
  116. G_SIGNAL_DETAILED = 1 << 4,
  117. G_SIGNAL_ACTION = 1 << 5,
  118. G_SIGNAL_NO_HOOKS = 1 << 6
  119. } GSignalFlags;
  120. /**
  121. * G_SIGNAL_FLAGS_MASK:
  122. *
  123. * A mask for all #GSignalFlags bits.
  124. */
  125. #define G_SIGNAL_FLAGS_MASK 0x7f
  126. /**
  127. * GConnectFlags:
  128. * @G_CONNECT_AFTER: whether the handler should be called before or after the
  129. * default handler of the signal.
  130. * @G_CONNECT_SWAPPED: whether the instance and data should be swapped when
  131. * calling the handler.
  132. *
  133. * The connection flags are used to specify the behaviour of a signal's
  134. * connection.
  135. */
  136. typedef enum
  137. {
  138. G_CONNECT_AFTER = 1 << 0,
  139. G_CONNECT_SWAPPED = 1 << 1
  140. } GConnectFlags;
  141. /**
  142. * GSignalMatchType:
  143. * @G_SIGNAL_MATCH_ID: The signal id must be equal.
  144. * @G_SIGNAL_MATCH_DETAIL: The signal detail be equal.
  145. * @G_SIGNAL_MATCH_CLOSURE: The closure must be the same.
  146. * @G_SIGNAL_MATCH_FUNC: The C closure callback must be the same.
  147. * @G_SIGNAL_MATCH_DATA: The closure data must be the same.
  148. * @G_SIGNAL_MATCH_UNBLOCKED: Only unblocked signals may matched.
  149. *
  150. * The match types specify what g_signal_handlers_block_matched(),
  151. * g_signal_handlers_unblock_matched() and g_signal_handlers_disconnect_matched()
  152. * match signals by.
  153. */
  154. typedef enum
  155. {
  156. G_SIGNAL_MATCH_ID = 1 << 0,
  157. G_SIGNAL_MATCH_DETAIL = 1 << 1,
  158. G_SIGNAL_MATCH_CLOSURE = 1 << 2,
  159. G_SIGNAL_MATCH_FUNC = 1 << 3,
  160. G_SIGNAL_MATCH_DATA = 1 << 4,
  161. G_SIGNAL_MATCH_UNBLOCKED = 1 << 5
  162. } GSignalMatchType;
  163. /**
  164. * G_SIGNAL_MATCH_MASK:
  165. *
  166. * A mask for all #GSignalMatchType bits.
  167. */
  168. #define G_SIGNAL_MATCH_MASK 0x3f
  169. /**
  170. * G_SIGNAL_TYPE_STATIC_SCOPE:
  171. *
  172. * This macro flags signal argument types for which the signal system may
  173. * assume that instances thereof remain persistent across all signal emissions
  174. * they are used in. This is only useful for non ref-counted, value-copy types.
  175. *
  176. * To flag a signal argument in this way, add
  177. * <literal>| G_SIGNAL_TYPE_STATIC_SCOPE</literal> to the corresponding argument
  178. * of g_signal_new().
  179. * |[
  180. * g_signal_new ("size_request",
  181. * G_TYPE_FROM_CLASS (gobject_class),
  182. * G_SIGNAL_RUN_FIRST,
  183. * G_STRUCT_OFFSET (GtkWidgetClass, size_request),
  184. * NULL, NULL,
  185. * _gtk_marshal_VOID__BOXED,
  186. * G_TYPE_NONE, 1,
  187. * GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
  188. * ]|
  189. */
  190. #define G_SIGNAL_TYPE_STATIC_SCOPE (G_TYPE_FLAG_RESERVED_ID_BIT)
  191. /* --- signal information --- */
  192. /**
  193. * GSignalInvocationHint:
  194. * @signal_id: The signal id of the signal invoking the callback
  195. * @detail: The detail passed on for this emission
  196. * @run_type: The stage the signal emission is currently in, this
  197. * field will contain one of %G_SIGNAL_RUN_FIRST,
  198. * %G_SIGNAL_RUN_LAST or %G_SIGNAL_RUN_CLEANUP.
  199. *
  200. * The #GSignalInvocationHint structure is used to pass on additional information
  201. * to callbacks during a signal emission.
  202. */
  203. struct _GSignalInvocationHint
  204. {
  205. guint signal_id;
  206. GQuark detail;
  207. GSignalFlags run_type;
  208. };
  209. /**
  210. * GSignalQuery:
  211. * @signal_id: The signal id of the signal being queried, or 0 if the
  212. * signal to be queried was unknown.
  213. * @signal_name: The signal name.
  214. * @itype: The interface/instance type that this signal can be emitted for.
  215. * @signal_flags: The signal flags as passed in to g_signal_new().
  216. * @return_type: The return type for user callbacks.
  217. * @n_params: The number of parameters that user callbacks take.
  218. * @param_types: The individual parameter types for user callbacks, note that the
  219. * effective callback signature is:
  220. * <programlisting>
  221. * @return_type callback (#gpointer data1,
  222. * [#param_types param_names,]
  223. * #gpointer data2);
  224. * </programlisting>
  225. *
  226. * A structure holding in-depth information for a specific signal. It is
  227. * filled in by the g_signal_query() function.
  228. */
  229. struct _GSignalQuery
  230. {
  231. guint signal_id;
  232. const gchar *signal_name;
  233. GType itype;
  234. GSignalFlags signal_flags;
  235. GType return_type; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
  236. guint n_params;
  237. const GType *param_types; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
  238. };
  239. /* --- signals --- */
  240. guint g_signal_newv (const gchar *signal_name,
  241. GType itype,
  242. GSignalFlags signal_flags,
  243. GClosure *class_closure,
  244. GSignalAccumulator accumulator,
  245. gpointer accu_data,
  246. GSignalCMarshaller c_marshaller,
  247. GType return_type,
  248. guint n_params,
  249. GType *param_types);
  250. guint g_signal_new_valist (const gchar *signal_name,
  251. GType itype,
  252. GSignalFlags signal_flags,
  253. GClosure *class_closure,
  254. GSignalAccumulator accumulator,
  255. gpointer accu_data,
  256. GSignalCMarshaller c_marshaller,
  257. GType return_type,
  258. guint n_params,
  259. va_list args);
  260. guint g_signal_new (const gchar *signal_name,
  261. GType itype,
  262. GSignalFlags signal_flags,
  263. guint class_offset,
  264. GSignalAccumulator accumulator,
  265. gpointer accu_data,
  266. GSignalCMarshaller c_marshaller,
  267. GType return_type,
  268. guint n_params,
  269. ...);
  270. guint g_signal_new_class_handler (const gchar *signal_name,
  271. GType itype,
  272. GSignalFlags signal_flags,
  273. GCallback class_handler,
  274. GSignalAccumulator accumulator,
  275. gpointer accu_data,
  276. GSignalCMarshaller c_marshaller,
  277. GType return_type,
  278. guint n_params,
  279. ...);
  280. void g_signal_emitv (const GValue *instance_and_params,
  281. guint signal_id,
  282. GQuark detail,
  283. GValue *return_value);
  284. void g_signal_emit_valist (gpointer instance,
  285. guint signal_id,
  286. GQuark detail,
  287. va_list var_args);
  288. void g_signal_emit (gpointer instance,
  289. guint signal_id,
  290. GQuark detail,
  291. ...);
  292. void g_signal_emit_by_name (gpointer instance,
  293. const gchar *detailed_signal,
  294. ...);
  295. guint g_signal_lookup (const gchar *name,
  296. GType itype);
  297. G_CONST_RETURN gchar* g_signal_name (guint signal_id);
  298. void g_signal_query (guint signal_id,
  299. GSignalQuery *query);
  300. guint* g_signal_list_ids (GType itype,
  301. guint *n_ids);
  302. gboolean g_signal_parse_name (const gchar *detailed_signal,
  303. GType itype,
  304. guint *signal_id_p,
  305. GQuark *detail_p,
  306. gboolean force_detail_quark);
  307. GSignalInvocationHint* g_signal_get_invocation_hint (gpointer instance);
  308. /* --- signal emissions --- */
  309. void g_signal_stop_emission (gpointer instance,
  310. guint signal_id,
  311. GQuark detail);
  312. void g_signal_stop_emission_by_name (gpointer instance,
  313. const gchar *detailed_signal);
  314. gulong g_signal_add_emission_hook (guint signal_id,
  315. GQuark detail,
  316. GSignalEmissionHook hook_func,
  317. gpointer hook_data,
  318. GDestroyNotify data_destroy);
  319. void g_signal_remove_emission_hook (guint signal_id,
  320. gulong hook_id);
  321. /* --- signal handlers --- */
  322. gboolean g_signal_has_handler_pending (gpointer instance,
  323. guint signal_id,
  324. GQuark detail,
  325. gboolean may_be_blocked);
  326. gulong g_signal_connect_closure_by_id (gpointer instance,
  327. guint signal_id,
  328. GQuark detail,
  329. GClosure *closure,
  330. gboolean after);
  331. gulong g_signal_connect_closure (gpointer instance,
  332. const gchar *detailed_signal,
  333. GClosure *closure,
  334. gboolean after);
  335. gulong g_signal_connect_data (gpointer instance,
  336. const gchar *detailed_signal,
  337. GCallback c_handler,
  338. gpointer data,
  339. GClosureNotify destroy_data,
  340. GConnectFlags connect_flags);
  341. void g_signal_handler_block (gpointer instance,
  342. gulong handler_id);
  343. void g_signal_handler_unblock (gpointer instance,
  344. gulong handler_id);
  345. void g_signal_handler_disconnect (gpointer instance,
  346. gulong handler_id);
  347. gboolean g_signal_handler_is_connected (gpointer instance,
  348. gulong handler_id);
  349. gulong g_signal_handler_find (gpointer instance,
  350. GSignalMatchType mask,
  351. guint signal_id,
  352. GQuark detail,
  353. GClosure *closure,
  354. gpointer func,
  355. gpointer data);
  356. guint g_signal_handlers_block_matched (gpointer instance,
  357. GSignalMatchType mask,
  358. guint signal_id,
  359. GQuark detail,
  360. GClosure *closure,
  361. gpointer func,
  362. gpointer data);
  363. guint g_signal_handlers_unblock_matched (gpointer instance,
  364. GSignalMatchType mask,
  365. guint signal_id,
  366. GQuark detail,
  367. GClosure *closure,
  368. gpointer func,
  369. gpointer data);
  370. guint g_signal_handlers_disconnect_matched (gpointer instance,
  371. GSignalMatchType mask,
  372. guint signal_id,
  373. GQuark detail,
  374. GClosure *closure,
  375. gpointer func,
  376. gpointer data);
  377. /* --- overriding and chaining --- */
  378. void g_signal_override_class_closure (guint signal_id,
  379. GType instance_type,
  380. GClosure *class_closure);
  381. void g_signal_override_class_handler (const gchar *signal_name,
  382. GType instance_type,
  383. GCallback class_handler);
  384. void g_signal_chain_from_overridden (const GValue *instance_and_params,
  385. GValue *return_value);
  386. void g_signal_chain_from_overridden_handler (gpointer instance,
  387. ...);
  388. /* --- convenience --- */
  389. /**
  390. * g_signal_connect:
  391. * @instance: the instance to connect to.
  392. * @detailed_signal: a string of the form "signal-name::detail".
  393. * @c_handler: the #GCallback to connect.
  394. * @data: data to pass to @c_handler calls.
  395. *
  396. * Connects a #GCallback function to a signal for a particular object.
  397. *
  398. * The handler will be called before the default handler of the signal.
  399. *
  400. * Returns: the handler id
  401. */
  402. #define g_signal_connect(instance, detailed_signal, c_handler, data) \
  403. g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, (GConnectFlags) 0)
  404. /**
  405. * g_signal_connect_after:
  406. * @instance: the instance to connect to.
  407. * @detailed_signal: a string of the form "signal-name::detail".
  408. * @c_handler: the #GCallback to connect.
  409. * @data: data to pass to @c_handler calls.
  410. *
  411. * Connects a #GCallback function to a signal for a particular object.
  412. *
  413. * The handler will be called after the default handler of the signal.
  414. *
  415. * Returns: the handler id
  416. */
  417. #define g_signal_connect_after(instance, detailed_signal, c_handler, data) \
  418. g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, G_CONNECT_AFTER)
  419. /**
  420. * g_signal_connect_swapped:
  421. * @instance: the instance to connect to.
  422. * @detailed_signal: a string of the form "signal-name::detail".
  423. * @c_handler: the #GCallback to connect.
  424. * @data: data to pass to @c_handler calls.
  425. *
  426. * Connects a #GCallback function to a signal for a particular object.
  427. *
  428. * The instance on which the signal is emitted and @data will be swapped when
  429. * calling the handler.
  430. *
  431. * Returns: the handler id
  432. */
  433. #define g_signal_connect_swapped(instance, detailed_signal, c_handler, data) \
  434. g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, G_CONNECT_SWAPPED)
  435. /**
  436. * g_signal_handlers_disconnect_by_func:
  437. * @instance: The instance to remove handlers from.
  438. * @func: The C closure callback of the handlers (useless for non-C closures).
  439. * @data: The closure data of the handlers' closures.
  440. *
  441. * Disconnects all handlers on an instance that match @func and @data.
  442. *
  443. * Returns: The number of handlers that matched.
  444. */
  445. #define g_signal_handlers_disconnect_by_func(instance, func, data) \
  446. g_signal_handlers_disconnect_matched ((instance), \
  447. (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \
  448. 0, 0, NULL, (func), (data))
  449. /**
  450. * g_signal_handlers_block_by_func:
  451. * @instance: The instance to block handlers from.
  452. * @func: The C closure callback of the handlers (useless for non-C closures).
  453. * @data: The closure data of the handlers' closures.
  454. *
  455. * Blocks all handlers on an instance that match @func and @data.
  456. *
  457. * Returns: The number of handlers that matched.
  458. */
  459. #define g_signal_handlers_block_by_func(instance, func, data) \
  460. g_signal_handlers_block_matched ((instance), \
  461. (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \
  462. 0, 0, NULL, (func), (data))
  463. /**
  464. * g_signal_handlers_unblock_by_func:
  465. * @instance: The instance to unblock handlers from.
  466. * @func: The C closure callback of the handlers (useless for non-C closures).
  467. * @data: The closure data of the handlers' closures.
  468. *
  469. * Unblocks all handlers on an instance that match @func and @data.
  470. *
  471. * Returns: The number of handlers that matched.
  472. */
  473. #define g_signal_handlers_unblock_by_func(instance, func, data) \
  474. g_signal_handlers_unblock_matched ((instance), \
  475. (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \
  476. 0, 0, NULL, (func), (data))
  477. gboolean g_signal_accumulator_true_handled (GSignalInvocationHint *ihint,
  478. GValue *return_accu,
  479. const GValue *handler_return,
  480. gpointer dummy);
  481. /*< private >*/
  482. void g_signal_handlers_destroy (gpointer instance);
  483. void _g_signals_destroy (GType itype);
  484. G_END_DECLS
  485. #endif /* __G_SIGNAL_H__ */