Native.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using gint8 = System.Byte;
  8. using gint16 = System.Int16;
  9. using gint32 = System.Int32;
  10. using gint = System.Int32;
  11. using guint16 = System.UInt16;
  12. using guint32 = System.UInt32;
  13. using guint = System.UInt32;
  14. using gdouble = System.Double;
  15. namespace Avalonia.Gtk3.Interop
  16. {
  17. static class Native
  18. {
  19. public static class D
  20. {
  21. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gtk)]
  22. public delegate IntPtr gtk_application_new([MarshalAs(UnmanagedType.AnsiBStr)] string appId, int flags);
  23. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gtk)]
  24. public delegate void gtk_main_iteration();
  25. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gtk)]
  26. public delegate IntPtr gtk_window_new(GtkWindowType windowType);
  27. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gtk)]
  28. public delegate IntPtr gtk_init(int argc, IntPtr argv);
  29. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gtk)]
  30. public delegate void gtk_window_present(IntPtr gtkWindow);
  31. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gtk)]
  32. public delegate void gtk_widget_hide(IntPtr gtkWidget);
  33. [UnmanagedFunctionPointer(CallingConvention.Cdecl)] //No manual import
  34. public delegate IntPtr gdk_get_native_handle(IntPtr gdkWindow);
  35. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gtk)]
  36. public delegate IntPtr gtk_widget_get_window(IntPtr gtkWidget);
  37. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gtk)]
  38. public delegate IntPtr gtk_widget_get_screen(IntPtr gtkWidget);
  39. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gtk)]
  40. public delegate IntPtr gtk_widget_set_double_buffered(IntPtr gtkWidget, bool value);
  41. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gtk)]
  42. public delegate IntPtr gtk_widget_set_events(IntPtr gtkWidget, uint flags);
  43. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gdk)]
  44. public delegate int gdk_screen_get_height(IntPtr screen);
  45. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gdk)]
  46. public delegate int gdk_screen_get_width(IntPtr screen);
  47. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gdk)]
  48. public delegate int gdk_window_get_origin(IntPtr gdkWindow, out int x, out int y);
  49. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gtk)]
  50. public delegate void gtk_widget_realize(IntPtr gtkWidget);
  51. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gtk)]
  52. public delegate void gtk_window_set_title(IntPtr gtkWindow, Utf8Buffer title);
  53. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gtk)]
  54. public delegate void gtk_window_set_decorated(IntPtr gtkWindow, bool decorated);
  55. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gtk)]
  56. public delegate void gtk_window_get_size(IntPtr gtkWindow, out int width, out int height);
  57. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gtk)]
  58. public delegate void gtk_window_resize(IntPtr gtkWindow, int width, int height);
  59. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gtk)]
  60. public delegate void gtk_window_get_position(IntPtr gtkWindow, out int x, out int y);
  61. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gtk)]
  62. public delegate void gtk_window_move(IntPtr gtkWindow, int x, int y);
  63. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Cairo)]
  64. public delegate IntPtr cairo_image_surface_create(int format, int width, int height);
  65. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Cairo)]
  66. public delegate IntPtr cairo_image_surface_get_data(IntPtr surface);
  67. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Cairo)]
  68. public delegate int cairo_image_surface_get_stride(IntPtr surface);
  69. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Cairo)]
  70. public delegate void cairo_surface_mark_dirty(IntPtr surface);
  71. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Cairo)]
  72. public delegate void cairo_surface_flush(IntPtr surface);
  73. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Cairo)]
  74. public delegate void cairo_surface_destroy(IntPtr surface);
  75. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Cairo)]
  76. public delegate void cairo_set_source_surface(IntPtr cr, IntPtr surface, double x, double y);
  77. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Cairo)]
  78. public delegate void cairo_paint(IntPtr context);
  79. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gtk)]
  80. public delegate void gtk_widget_queue_draw_area(IntPtr gtkWindow, int x, int y, int width, int height);
  81. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gdk)]
  82. public delegate void gdk_window_invalidate_rect(IntPtr window, ref GdkRectangle rect, bool invalidate_children);
  83. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gobject)]
  84. public delegate ulong g_signal_connect_object(IntPtr instance, [MarshalAs(UnmanagedType.AnsiBStr)]string signal, IntPtr handler, IntPtr userData, int flags);
  85. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gobject)]
  86. public delegate ulong g_signal_handler_disconnect(IntPtr instance, ulong connectionId);
  87. [UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Glib)]
  88. public delegate ulong g_timeout_add(uint interval, timeout_callback callback, IntPtr data);
  89. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  90. public delegate bool signal_widget_draw(IntPtr gtkWidget, IntPtr cairoContext, IntPtr userData);
  91. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  92. public delegate bool signal_onevent(IntPtr gtkWidget, IntPtr ev, IntPtr userData);
  93. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  94. public delegate bool timeout_callback(IntPtr data);
  95. }
  96. public static D.gtk_window_set_decorated GtkWindowSetDecorated;
  97. public static D.gtk_window_set_title GtkWindowSetTitle;
  98. public static D.gtk_application_new GtkApplicationNew;
  99. public static D.gtk_main_iteration GtkMainIteration;
  100. public static D.gtk_window_new GtkWindowNew;
  101. public static D.gtk_init GtkInit;
  102. public static D.gtk_window_present GtkWindowPresent;
  103. public static D.gtk_widget_hide GtkWidgetHide;
  104. public static D.gdk_get_native_handle GetNativeGdkWindowHandle;
  105. public static D.gtk_widget_get_window GtkWidgetGetWindow;
  106. public static D.gtk_widget_get_screen GtkWidgetGetScreen;
  107. public static D.gtk_widget_realize GtkWidgetRealize;
  108. public static D.gtk_window_get_size GtkWindowGetSize;
  109. public static D.gtk_window_resize GtkWindowResize;
  110. public static D.gtk_window_get_position GtkWindowGetPosition;
  111. public static D.gtk_window_move GtkWindowMove;
  112. public static D.g_signal_connect_object GSignalConnectObject;
  113. public static D.g_signal_handler_disconnect GSignalHandlerDisconnect;
  114. public static D.g_timeout_add GTimeoutAdd;
  115. public static D.gtk_widget_set_double_buffered GtkWidgetSetDoubleBuffered;
  116. public static D.gtk_widget_set_events GtkWidgetSetEvents;
  117. public static D.gdk_window_invalidate_rect GdkWindowInvalidateRect;
  118. public static D.gtk_widget_queue_draw_area GtkWidgetQueueDrawArea;
  119. public static D.gdk_screen_get_height GdkScreenGetHeight;
  120. public static D.gdk_screen_get_width GdkScreenGetWidth;
  121. public static D.gdk_window_get_origin GdkWindowGetOrigin;
  122. public static D.cairo_image_surface_create CairoImageSurfaceCreate;
  123. public static D.cairo_image_surface_get_data CairoImageSurfaceGetData;
  124. public static D.cairo_image_surface_get_stride CairoImageSurfaceGetStride;
  125. public static D.cairo_surface_mark_dirty CairoSurfaceMarkDirty;
  126. public static D.cairo_surface_flush CairoSurfaceFlush;
  127. public static D.cairo_surface_destroy CairoSurfaceDestroy;
  128. public static D.cairo_set_source_surface CairoSetSourceSurface;
  129. public static D.cairo_paint CairoPaint;
  130. }
  131. public enum GtkWindowType
  132. {
  133. TopLevel,
  134. Popup
  135. }
  136. [StructLayout(LayoutKind.Sequential)]
  137. public struct GdkRectangle
  138. {
  139. public int X, Y, Width, Height;
  140. public static GdkRectangle FromRect(Rect rect)
  141. {
  142. return new GdkRectangle
  143. {
  144. X = (int) rect.X,
  145. Y = (int) rect.Y,
  146. Width = (int) rect.Width,
  147. Height = (int) rect.Height
  148. };
  149. }
  150. }
  151. enum GdkEventType
  152. {
  153. Nothing = -1,
  154. Delete = 0,
  155. Destroy = 1,
  156. Expose = 2,
  157. MotionNotify = 3,
  158. ButtonPress = 4,
  159. TwoButtonPress = 5,
  160. ThreeButtonPress = 6,
  161. ButtonRelease = 7,
  162. KeyPress = 8,
  163. KeyRelease = 9,
  164. EnterNotify = 10,
  165. LeaveNotify = 11,
  166. FocusChange = 12,
  167. Configure = 13,
  168. Map = 14,
  169. Unmap = 15,
  170. PropertyNotify = 16,
  171. SelectionClear = 17,
  172. SelectionRequest = 18,
  173. SelectionNotify = 19,
  174. ProximityIn = 20,
  175. ProximityOut = 21,
  176. DragEnter = 22,
  177. DragLeave = 23,
  178. DragMotion = 24,
  179. DragStatus = 25,
  180. DropStart = 26,
  181. DropFinished = 27,
  182. ClientEvent = 28,
  183. VisibilityNotify = 29,
  184. NoExpose = 30,
  185. Scroll = 31,
  186. WindowState = 32,
  187. Setting = 33,
  188. OwnerChange = 34,
  189. GrabBroken = 35,
  190. }
  191. enum GdkModifierType
  192. {
  193. ShiftMask = 1,
  194. LockMask = 2,
  195. ControlMask = 4,
  196. Mod1Mask = 8,
  197. Mod2Mask = 16,
  198. Mod3Mask = 32,
  199. Mod4Mask = 64,
  200. Mod5Mask = 128,
  201. Button1Mask = 256,
  202. Button2Mask = 512,
  203. Button3Mask = 1024,
  204. Button4Mask = 2048,
  205. Button5Mask = 4096,
  206. SuperMask = 67108864,
  207. HyperMask = 134217728,
  208. MetaMask = 268435456,
  209. ReleaseMask = 1073741824,
  210. ModifierMask = ReleaseMask | Button5Mask | Button4Mask | Button3Mask | Button2Mask | Button1Mask | Mod5Mask | Mod4Mask | Mod3Mask | Mod2Mask | Mod1Mask | ControlMask | LockMask | ShiftMask,
  211. None = 0,
  212. }
  213. enum GdkScrollDirection
  214. {
  215. Up,
  216. Down,
  217. Left,
  218. Right,
  219. Smooth
  220. }
  221. [StructLayout(LayoutKind.Sequential)]
  222. unsafe struct GdkEventButton
  223. {
  224. public GdkEventType type;
  225. public IntPtr window;
  226. public gint8 send_event;
  227. public guint32 time;
  228. public gdouble x;
  229. public gdouble y;
  230. public gdouble* axes;
  231. public GdkModifierType state;
  232. public guint button;
  233. public IntPtr device;
  234. public gdouble x_root, y_root;
  235. }
  236. [StructLayout(LayoutKind.Sequential)]
  237. unsafe struct GdkEventMotion
  238. {
  239. public GdkEventType type;
  240. public IntPtr window;
  241. public gint8 send_event;
  242. public guint32 time;
  243. public gdouble x;
  244. public gdouble y;
  245. public gdouble* axes;
  246. public GdkModifierType state;
  247. public gint16 is_hint;
  248. public IntPtr device;
  249. public gdouble x_root, y_root;
  250. }
  251. [StructLayout(LayoutKind.Sequential)]
  252. unsafe struct GdkEventScroll
  253. {
  254. public GdkEventType type;
  255. public IntPtr window;
  256. public gint8 send_event;
  257. public guint32 time;
  258. public gdouble x;
  259. public gdouble y;
  260. public GdkModifierType state;
  261. public GdkScrollDirection direction;
  262. public IntPtr device;
  263. public gdouble x_root, y_root;
  264. public gdouble delta_x;
  265. public gdouble delta_y;
  266. }
  267. }