gmain.inc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. {$ifndef __G_MAIN_H__}
  2. {$define __G_MAIN_H__}
  3. //{$include gslist.inc}
  4. //{$include gthread.inc}
  5. type
  6. PGMainContext = pointer;
  7. PGMainLoop = pointer;
  8. PGSourceFunc = ^TGSourceFunc;
  9. TGSourceFunc = function (data:gpointer):gboolean;cdecl;
  10. {< private > }
  11. PGSourceCallbackFuncs = ^TGSourceCallbackFuncs;
  12. PGSource = ^TGSource;
  13. PGSourceFuncs = ^TGSourceFuncs;
  14. TGSource = record
  15. callback_data : gpointer;
  16. callback_funcs : PGSourceCallbackFuncs;
  17. source_funcs : PGSourceFuncs;
  18. ref_count : guint;
  19. context : PGMainContext;
  20. priority : gint;
  21. flags : guint;
  22. source_id : guint;
  23. poll_fds : PGSList;
  24. prev : PGSource;
  25. next : PGSource;
  26. reserved1 : gpointer;
  27. reserved2 : gpointer;
  28. end;
  29. TGSourceCallbackFuncs = record
  30. ref : procedure (cb_data:gpointer); cdecl;
  31. unref : procedure (cb_data:gpointer); cdecl;
  32. get : procedure (cb_data:gpointer; source:PGSource; func:PGSourceFunc; data:Pgpointer); cdecl;
  33. end;
  34. TGSourceDummyMarshal = procedure {no parameters} ;cdecl;
  35. { Can be NULL }
  36. { For use by g_source_set_closure }
  37. { Really is of type GClosureMarshal }
  38. TGSourceFuncs = record
  39. prepare : function (source:PGSource; timeout:gint):gboolean; cdecl;
  40. check : function (source:PGSource):gboolean; cdecl;
  41. dispatch : function (source:PGSource; callback:TGSourceFunc; user_data:gpointer):gboolean; cdecl;
  42. finalize : procedure (source:PGSource); cdecl;
  43. closure_callback : TGSourceFunc;
  44. closure_marshal : TGSourceDummyMarshal;
  45. end;
  46. { Any definitions using GPollFD or GPollFunc are primarily
  47. for Unix and not guaranteed to be the compatible on all
  48. operating systems on which GLib runs. Right now, the
  49. GLib does use these functions on Win32 as well, but interprets
  50. them in a fairly different way than on Unix. If you use
  51. these definitions, you are should be prepared to recode
  52. for different operating systems.
  53. On Win32, the fd in a GPollFD should be Win32 HANDLE ( not a file
  54. descriptor as provided by the C runtime) that can be used by
  55. MsgWaitForMultipleObjects. This does not include file handles
  56. from CreateFile, SOCKETs, nor pipe handles. (But you can use
  57. WSAEventSelect to signal events when a SOCKET is readable).
  58. On Win32, fd can also be the special value G_WIN32_MSG_HANDLE to
  59. indicate polling for messages. These message queue GPollFDs should
  60. be added with the g_main_poll_win32_msg_add function.
  61. But note that G_WIN32_MSG_HANDLE GPollFDs should not be used by GDK
  62. (GTK) programs, as GDK itself wants to read messages and convert them
  63. to GDK events.
  64. So, unless you really know what you are doing, it's best not to try
  65. to use the main loop polling stuff for your own needs on
  66. Win32. It's really only written for the GIMP's needs so
  67. far.
  68. }
  69. PGPollFD = ^TGPollFD;
  70. TGPollFD = record
  71. fd : gint;
  72. events : gushort;
  73. revents : gushort;
  74. end;
  75. TGPollFunc = function (ufds:PGPollFD; nfsd:guint; timeout:gint):gint;cdecl;
  76. { Standard priorities }
  77. const
  78. G_PRIORITY_HIGH = -(100);
  79. G_PRIORITY_DEFAULT = 0;
  80. G_PRIORITY_HIGH_IDLE = 100;
  81. G_PRIORITY_DEFAULT_IDLE = 200;
  82. G_PRIORITY_LOW = 300;
  83. { GMainContext: }
  84. function g_main_context_new:PGMainContext;cdecl;external gliblib name 'g_main_context_new';
  85. procedure g_main_context_ref(context:PGMainContext);cdecl;external gliblib name 'g_main_context_ref';
  86. procedure g_main_context_unref(context:PGMainContext);cdecl;external gliblib name 'g_main_context_unref';
  87. function g_main_context_default:PGMainContext;cdecl;external gliblib name 'g_main_context_default';
  88. function g_main_context_iteration(context:PGMainContext; may_block:gboolean):gboolean;cdecl;external gliblib name 'g_main_context_iteration';
  89. function g_main_context_pending(context:PGMainContext):gboolean;cdecl;external gliblib name 'g_main_context_pending';
  90. { For implementation of legacy interfaces
  91. }
  92. function g_main_context_find_source_by_id(context:PGMainContext; source_id:guint):PGSource;cdecl;external gliblib name 'g_main_context_find_source_by_id';
  93. function g_main_context_find_source_by_user_data(context:PGMainContext; user_data:gpointer):PGSource;cdecl;external gliblib name 'g_main_context_find_source_by_user_data';
  94. function g_main_context_find_source_by_funcs_user_data(context:PGMainContext; funcs:PGSourceFuncs; user_data:gpointer):PGSource;cdecl;external gliblib name 'g_main_context_find_source_by_funcs_user_data';
  95. { Low level functions for implementing custom main loops.
  96. }
  97. procedure g_main_context_wakeup(context:PGMainContext);cdecl;external gliblib name 'g_main_context_wakeup';
  98. function g_main_context_acquire(context:PGMainContext):gboolean;cdecl;external gliblib name 'g_main_context_acquire';
  99. procedure g_main_context_release(context:PGMainContext);cdecl;external gliblib name 'g_main_context_release';
  100. function g_main_context_wait(context:PGMainContext; cond:PGCond; mutex:PGMutex):gboolean;cdecl;external gliblib name 'g_main_context_wait';
  101. function g_main_context_prepare(context:PGMainContext; priority:Pgint):gboolean;cdecl;external gliblib name 'g_main_context_prepare';
  102. function g_main_context_query(context:PGMainContext; max_priority:gint; timeout:Pgint; fds:PGPollFD; n_fds:gint):gint;cdecl;external gliblib name 'g_main_context_query';
  103. function g_main_context_check(context:PGMainContext; max_priority:gint; fds:PGPollFD; n_fds:gint):gint;cdecl;external gliblib name 'g_main_context_check';
  104. procedure g_main_context_dispatch(context:PGMainContext);cdecl;external gliblib name 'g_main_context_dispatch';
  105. procedure g_main_context_set_poll_func(context:PGMainContext; func:TGPollFunc);cdecl;external gliblib name 'g_main_context_set_poll_func';
  106. function g_main_context_get_poll_func(context:PGMainContext):TGPollFunc;cdecl;external gliblib name 'g_main_context_get_poll_func';
  107. { Low level functions for use by source implementations
  108. }
  109. procedure g_main_context_add_poll(context:PGMainContext; fd:PGPollFD; priority:gint);cdecl;external gliblib name 'g_main_context_add_poll';
  110. procedure g_main_context_remove_poll(context:PGMainContext; fd:PGPollFD);cdecl;external gliblib name 'g_main_context_remove_poll';
  111. { GMainLoop: }
  112. function g_main_loop_new(context:PGMainContext; is_running:gboolean):PGMainLoop;cdecl;external gliblib name 'g_main_loop_new';
  113. procedure g_main_loop_run(loop:PGMainLoop);cdecl;external gliblib name 'g_main_loop_run';
  114. procedure g_main_loop_quit(loop:PGMainLoop);cdecl;external gliblib name 'g_main_loop_quit';
  115. function g_main_loop_ref(loop:PGMainLoop):PGMainLoop;cdecl;external gliblib name 'g_main_loop_ref';
  116. procedure g_main_loop_unref(loop:PGMainLoop);cdecl;external gliblib name 'g_main_loop_unref';
  117. function g_main_loop_is_running(loop:PGMainLoop):gboolean;cdecl;external gliblib name 'g_main_loop_is_running';
  118. function g_main_loop_get_context(loop:PGMainLoop):PGMainContext;cdecl;external gliblib name 'g_main_loop_get_context';
  119. { GSource: }
  120. function g_source_new(source_funcs:PGSourceFuncs; struct_size:guint):PGSource;cdecl;external gliblib name 'g_source_new';
  121. function g_source_ref(source:PGSource):PGSource;cdecl;external gliblib name 'g_source_ref';
  122. procedure g_source_unref(source:PGSource);cdecl;external gliblib name 'g_source_unref';
  123. function g_source_attach(source:PGSource; context:PGMainContext):guint;cdecl;external gliblib name 'g_source_attach';
  124. procedure g_source_destroy(source:PGSource);cdecl;external gliblib name 'g_source_destroy';
  125. procedure g_source_set_priority(source:PGSource; priority:gint);cdecl;external gliblib name 'g_source_set_priority';
  126. function g_source_get_priority(source:PGSource):gint;cdecl;external gliblib name 'g_source_get_priority';
  127. procedure g_source_set_can_recurse(source:PGSource; can_recurse:gboolean);cdecl;external gliblib name 'g_source_set_can_recurse';
  128. function g_source_get_can_recurse(source:PGSource):gboolean;cdecl;external gliblib name 'g_source_get_can_recurse';
  129. function g_source_get_id(source:PGSource):guint;cdecl;external gliblib name 'g_source_get_id';
  130. function g_source_get_context(source:PGSource):PGMainContext;cdecl;external gliblib name 'g_source_get_context';
  131. procedure g_source_set_callback(source:PGSource; func:TGSourceFunc; data:gpointer; notify:TGDestroyNotify);cdecl;external gliblib name 'g_source_set_callback';
  132. { Used to implement g_source_connect_closure and internally }
  133. procedure g_source_set_callback_indirect(source:PGSource; callback_data:gpointer; callback_funcs:PGSourceCallbackFuncs);cdecl;external gliblib name 'g_source_set_callback_indirect';
  134. procedure g_source_add_poll(source:PGSource; fd:PGPollFD);cdecl;external gliblib name 'g_source_add_poll';
  135. procedure g_source_remove_poll(source:PGSource; fd:PGPollFD);cdecl;external gliblib name 'g_source_remove_poll';
  136. procedure g_source_get_current_time(source:PGSource; timeval:PGTimeVal);cdecl;external gliblib name 'g_source_get_current_time';
  137. { void g_source_connect_closure (GSource source,
  138. GClosure closure);
  139. }
  140. { Specific source types
  141. }
  142. function g_idle_source_new:PGSource;cdecl;external gliblib name 'g_idle_source_new';
  143. function g_timeout_source_new(interval:guint):PGSource;cdecl;external gliblib name 'g_timeout_source_new';
  144. { Miscellaneous functions
  145. }
  146. procedure g_get_current_time(result:PGTimeVal);cdecl;external gliblib name 'g_get_current_time';
  147. { ============== Compat main loop stuff ================== }
  148. function g_main_new(is_running: gboolean): PGMainLoop;
  149. { these functions are maped to their newer versions }
  150. procedure g_main_run (loop:PGMainLoop);cdecl;external gliblib name 'g_main_loop_run';
  151. procedure g_main_quit (loop:PGMainLoop);cdecl;external gliblib name 'g_main_loop_quit';
  152. procedure g_main_destroy (loop:PGMainLoop);cdecl;external gliblib name 'g_main_loop_unref';
  153. function g_main_is_running (loop:PGMainLoop):gboolean;cdecl;external gliblib name 'g_main_loop_is_running';
  154. { Functions to manipulate the default main loop}
  155. function g_main_iteration (may_block: gboolean): gboolean;
  156. function g_main_pending: gboolean;
  157. // g_main_context_pending (NULL)
  158. procedure g_main_set_poll_func(func: TGPollFunc);
  159. // g_main_context_set_poll_func (NULL, func)
  160. { ======= end of Compat main loop stuff ================== }
  161. { Source manipulation by ID }
  162. function g_source_remove(tag:guint):gboolean;cdecl;external gliblib name 'g_source_remove';
  163. function g_source_remove_by_user_data(user_data:gpointer):gboolean;cdecl;external gliblib name 'g_source_remove_by_user_data';
  164. function g_source_remove_by_funcs_user_data(funcs:PGSourceFuncs; user_data:gpointer):gboolean;cdecl;external gliblib name 'g_source_remove_by_funcs_user_data';
  165. { Idles and timeouts }
  166. function g_timeout_add_full(priority:gint; interval:guint; _function:TGSourceFunc; data:gpointer; notify:TGDestroyNotify):guint;cdecl;external gliblib name 'g_timeout_add_full';
  167. function g_timeout_add(interval:guint; _function:TGSourceFunc; data:gpointer):guint;cdecl;external gliblib name 'g_timeout_add';
  168. function g_idle_add(_function:TGSourceFunc; data:gpointer):guint;cdecl;external gliblib name 'g_idle_add';
  169. function g_idle_add_full(priority:gint; _function:TGSourceFunc; data:gpointer; notify:TGDestroyNotify):guint;cdecl;external gliblib name 'g_idle_add_full';
  170. function g_idle_remove_by_data(data:gpointer):gboolean;cdecl;external gliblib name 'g_idle_remove_by_data';
  171. { Hook for GClosure / GSource integration. Don't touch }
  172. // GLIB_VAR GSourceFuncs g_timeout_funcs;
  173. // GLIB_VAR GSourceFuncs g_idle_funcs;
  174. {$ifdef win32}
  175. { This is used to add polling for Windows messages. GDK (GTK+) programs
  176. should not use this.
  177. }
  178. procedure g_main_poll_win32_msg_add(priority:gint; fd:PGPollFD; hwnd:guint);cdecl;external gliblib name 'g_main_poll_win32_msg_add';
  179. {$endif}
  180. {$endif}