ghook.inc 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. {*
  2. * ghook.inc
  3. *
  4. * depends on gmem.inc
  5. *}
  6. { --- typedefs --- }
  7. type
  8. PGHook = ^TGHook;
  9. TGHook = record
  10. data : gpointer;
  11. next : PGHook;
  12. prev : PGHook;
  13. ref_count : guint;
  14. hook_id : gulong;
  15. flags : guint;
  16. func : gpointer;
  17. destroy : TGDestroyNotify;
  18. end;
  19. PGHookList = ^TGHookList;
  20. TGHookCompareFunc = function (new_hook:PGHook; sibling:PGHook):gint;cdecl;
  21. TGHookFindFunc = function (hook:PGHook; data:gpointer):gboolean;cdecl;
  22. TGHookMarshaller = procedure (hook:PGHook; marshal_data:gpointer);cdecl;
  23. TGHookCheckMarshaller = function (hook:PGHook; marshal_data:gpointer):gboolean;cdecl;
  24. TGHookFunc = procedure (data:gpointer);cdecl;
  25. TGHookCheckFunc = function (data:gpointer):gboolean;cdecl;
  26. TGHookFinalizeFunc = procedure (hook_list:PGHookList; hook:PGHook);cdecl;
  27. TGHookList = record
  28. seq_id : gulong;
  29. flag0 : longint;
  30. hooks : PGHook;
  31. hook_memchunk : PGMemChunk;
  32. finalize_hook : TGHookFinalizeFunc;
  33. dummy : array[0..1] of gpointer;
  34. end;
  35. type
  36. PGHookFlagMask = ^TGHookFlagMask;
  37. TGHookFlagMask = integer;
  38. const
  39. G_HOOK_FLAG_ACTIVE = 1 shl 0;
  40. G_HOOK_FLAG_IN_CALL = 1 shl 1;
  41. G_HOOK_FLAG_MASK = $0f;
  42. const
  43. G_HOOK_FLAG_USER_SHIFT = 4;
  44. { added for manipulating the TGHookList structure }
  45. bm_TGHookList_hook_size = $FFFF;
  46. bp_TGHookList_hook_size = 0;
  47. bm_TGHookList_is_setup = $10000;
  48. bp_TGHookList_is_setup = 16;
  49. function TGHookList_hook_size (var a : TGHookList) : guint;
  50. procedure TGHookList_set_hook_size (var a : TGHookList; __hook_size : guint);
  51. function TGHookList_is_setup (var a : TGHookList) : guint;
  52. procedure TGHookList_set_is_setup (var a : TGHookList; __is_setup : guint);
  53. { --- macros --- }
  54. function G_HOOK(hook : pointer) : PGHook;
  55. function G_HOOK_FLAGS(hook : PGHook) : guint;
  56. function G_HOOK_ACTIVE (hook: PGHook): boolean;
  57. function G_HOOK_IN_CALL (hook: PGHook): boolean;
  58. function G_HOOK_IS_VALID (hook: PGHook): boolean;
  59. function G_HOOK_IS_UNLINKED (hook: PGHook): boolean;
  60. { --- prototypes --- }
  61. { callback mainenance functions }
  62. procedure g_hook_list_init (hook_list : PGHookList; hook_size : guint);cdecl; external gliblib name 'g_hook_list_init';
  63. procedure g_hook_list_clear(hook_list:PGHookList);cdecl;external gliblib name 'g_hook_list_clear';
  64. function g_hook_alloc(hook_list:PGHookList):PGHook;cdecl;external gliblib name 'g_hook_alloc';
  65. procedure g_hook_free(hook_list:PGHookList; hook:PGHook);cdecl;external gliblib name 'g_hook_free';
  66. procedure g_hook_ref(hook_list:PGHookList; hook:PGHook);cdecl;external gliblib name 'g_hook_ref';
  67. procedure g_hook_unref(hook_list:PGHookList; hook:PGHook);cdecl;external gliblib name 'g_hook_unref';
  68. function g_hook_destroy(hook_list:PGHookList; hook_id:gulong):gboolean;cdecl;external gliblib name 'g_hook_destroy';
  69. procedure g_hook_destroy_link(hook_list:PGHookList; hook:PGHook);cdecl;external gliblib name 'g_hook_destroy_link';
  70. procedure g_hook_prepend(hook_list:PGHookList; hook:PGHook);cdecl;external gliblib name 'g_hook_prepend';
  71. procedure g_hook_insert_before(hook_list:PGHookList; sibling:PGHook; hook:PGHook);cdecl;external gliblib name 'g_hook_insert_before';
  72. procedure g_hook_insert_sorted(hook_list:PGHookList; hook:PGHook; func:TGHookCompareFunc);cdecl;external gliblib name 'g_hook_insert_sorted';
  73. function g_hook_get(hook_list:PGHookList; hook_id:gulong):PGHook;cdecl;external gliblib name 'g_hook_get';
  74. function g_hook_find(hook_list:PGHookList; need_valids:gboolean; func:TGHookFindFunc; data:gpointer):PGHook;cdecl;external gliblib name 'g_hook_find';
  75. function g_hook_find_data(hook_list:PGHookList; need_valids:gboolean; data:gpointer):PGHook;cdecl;external gliblib name 'g_hook_find_data';
  76. function g_hook_find_func(hook_list:PGHookList; need_valids:gboolean; func:gpointer):PGHook;cdecl;external gliblib name 'g_hook_find_func';
  77. function g_hook_find_func_data(hook_list:PGHookList; need_valids:gboolean; func:gpointer; data:gpointer):PGHook;cdecl;external gliblib name 'g_hook_find_func_data';
  78. { return the first valid hook, and increment its reference count }
  79. function g_hook_first_valid(hook_list:PGHookList; may_be_in_call:gboolean):PGHook;cdecl;external gliblib name 'g_hook_first_valid';
  80. { return the next valid hook with incremented reference count, and
  81. decrement the reference count of the original hook
  82. }
  83. function g_hook_next_valid(hook_list:PGHookList; hook:PGHook; may_be_in_call:gboolean):PGHook;cdecl;external gliblib name 'g_hook_next_valid';
  84. { GHookCompareFunc implementation to insert hooks sorted by their id }
  85. function g_hook_compare_ids(new_hook:PGHook; sibling:PGHook):gint;cdecl;external gliblib name 'g_hook_compare_ids';
  86. { convenience macros }
  87. procedure g_hook_append (hook_list: PGHookList; hook:PGHook);
  88. { invoke all valid hooks with the ( GHookCheckFunc) signature,
  89. and destroy the hook if FALSE is returned.
  90. }
  91. procedure g_hook_list_invoke_check(hook_list:PGHookList; may_recurse:gboolean);cdecl;external gliblib name 'g_hook_list_invoke_check';
  92. { invoke a marshaller on all valid hooks.
  93. }
  94. procedure g_hook_list_marshal(hook_list:PGHookList; may_recurse:gboolean; marshaller:TGHookMarshaller; marshal_data:gpointer);cdecl;external gliblib name 'g_hook_list_marshal';
  95. procedure g_hook_list_marshal_check(hook_list:PGHookList; may_recurse:gboolean; marshaller:TGHookCheckMarshaller; marshal_data:gpointer);cdecl;external gliblib name 'g_hook_list_marshal_check';