1
0

linux.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. #ifndef __LINUX_H_WASABI
  2. #define __LINUX_H_WASABI
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <ctype.h>
  6. #include <unistd.h>
  7. #include <sys/timeb.h>
  8. #include <stdarg.h>
  9. #include <sys/stat.h>
  10. #include <sys/types.h>
  11. #include <dirent.h>
  12. #include <dlfcn.h>
  13. #include <signal.h>
  14. #include <sys/ipc.h>
  15. #include <sys/msg.h>
  16. #include <errno.h>
  17. #include <math.h>
  18. #include <string.h>
  19. #include <strings.h>
  20. #include <sys/shm.h>
  21. #ifndef NOVTABLE
  22. #define NOVTABLE
  23. #endif
  24. #ifndef __USE_GNU
  25. #define __USE_GNU
  26. #include <pthread.h>
  27. #undef __USE_GNU
  28. #else
  29. #include <pthread.h>
  30. #endif
  31. #ifdef WASABI_COMPILE_WND
  32. // Fucking api_region and Font namespace conflicts
  33. #define _XRegion _XRegion
  34. #define api_region HRGN
  35. #define Font HFONT
  36. #define Cursor _Cursor
  37. #include <X11/Xlib.h>
  38. #include <X11/Xutil.h>
  39. #include <X11/Xresource.h>
  40. #include <X11/extensions/shape.h>
  41. #include <X11/extensions/XShm.h>
  42. #include <X11/Xos.h>
  43. #include <X11/Xatom.h>
  44. #include <X11/xpm.h>
  45. #include <X11/keysym.h>
  46. #include <X11/cursorfont.h>
  47. #undef _XRegion
  48. #undef api_region
  49. #undef Font
  50. #undef Cursor
  51. #ifdef WASABI_COMPILE_FONTS
  52. #ifdef __INCLUDE_FREETYPE
  53. #include <freetype/freetype.h>
  54. #include <freetype/ftglyph.h>
  55. #endif // freetype
  56. //typedef FT_Face HFONT;
  57. #endif // fonts
  58. #ifdef __INCLUDE_GTK
  59. #include <gdk/gdkx.h>
  60. #include <gtk/gtk.h>
  61. #endif // gtk
  62. typedef Window HWND;
  63. #else // wnd
  64. typedef void * HWND;
  65. #endif // wnd
  66. // I know about XRectangle, but it's easier to recreate this than it is
  67. // to merge it with the rest of the code
  68. typedef struct { int left, top, right, bottom; } RECT;
  69. typedef unsigned long COLORREF;
  70. typedef struct {
  71. char rgbBlue;
  72. char rgbGreen;
  73. char rgbRed;
  74. char filler;
  75. } RGBQUAD;
  76. #define RGB( r, g, b ) ((((r)&0xFF)<<16)|(((g)&0xFF)<<8)|((b)&0xFF))
  77. #define min( a, b ) ((a>b)?b:a)
  78. #define max( a, b ) ((a>b)?a:b)
  79. #define CLR_NONE 0
  80. #ifdef __cplusplus
  81. #ifndef XMD_H
  82. typedef int BOOL; // It's int not bool because of some inheritance conflicts
  83. #endif
  84. #ifndef TRUE
  85. #define TRUE true
  86. #endif
  87. #ifndef FALSE
  88. #define FALSE false
  89. #endif
  90. #else
  91. #ifndef XMD_H
  92. typedef int BOOL;
  93. #endif
  94. #ifndef TRUE
  95. #define TRUE 1
  96. #endif
  97. #ifndef FALSE
  98. #define FALSE 0
  99. #endif
  100. #endif
  101. typedef BOOL BOOLEAN;
  102. typedef struct { int x, y; } POINT;
  103. #ifdef WASABI_COMPILE_WND
  104. typedef void *HPEN;
  105. // The HDC knows what it's drawing on
  106. typedef struct hdc_typ {
  107. GC gc;
  108. Drawable d;
  109. HRGN clip;
  110. } *HDC;
  111. // Pixmaps don't have associated width and height, at least not that I know of
  112. typedef struct {
  113. Pixmap p;
  114. int bmWidth;
  115. int bmHeight;
  116. XShmSegmentInfo *shmseginfo;
  117. } BITMAP, HBITMAP;
  118. typedef Pixmap HICON;
  119. #endif // wnd
  120. typedef int LRESULT;
  121. typedef int LPARAM;
  122. typedef int WPARAM;
  123. typedef int RPARAM;
  124. typedef unsigned int TCHAR;
  125. typedef long long __int64;
  126. typedef long long LARGE_INTEGER;
  127. typedef unsigned long long ULARGE_INTEGER;
  128. #define OSPIPE int
  129. #define OSPROCESSID int
  130. #define LOWORD(a) ((a)&0xffff)
  131. #define HIWORD(a) (((a)>>16)&0xffff)
  132. #define MAX_PATH 8192
  133. #define COMEXP
  134. #define EXTC extern "C"
  135. #define __cdecl
  136. #define CALLBACK
  137. #define WINAPI
  138. #define HRESULT void*
  139. #define WINUSERAPI
  140. #define APIENTRY
  141. #define __declspec(a)
  142. typedef char * LPSTR;
  143. typedef unsigned long DWORD;
  144. typedef short int WORD;
  145. #ifndef XMD_H
  146. typedef unsigned char BYTE;
  147. #endif
  148. typedef void* LPVOID;
  149. typedef struct {
  150. long cx, cy;
  151. } SIZE;
  152. typedef long LONG;
  153. #define VOID void
  154. #ifdef WASABI_COMPILE_WND
  155. // Fix this for canvas
  156. typedef void * PAINTSTRUCT;
  157. #endif
  158. #ifndef WASABI_COMPILE_WND
  159. #ifndef None
  160. #define None (HWND)0
  161. #endif
  162. #endif
  163. typedef void* THREAD_RET;
  164. #ifdef WASABI_COMPILE_WND
  165. // Fix this with editwnd!
  166. typedef void * WNDPROC;
  167. typedef void * DRAWITEMSTRUCT;
  168. #define VK_MENU (XK_Alt_L | (XK_Alt_R << 16))
  169. #define VK_MBUTTON (XK_Meta_L | (XK_Meta_R << 16))
  170. #define VK_SHIFT (XK_Shift_L | (XK_Shift_R << 16))
  171. #define MK_RBUTTON ((XK_VoidSymbol << 16) | 1)
  172. #define MK_LBUTTON ((XK_VoidSymbol << 16) | 2)
  173. #define VK_CONTROL (XK_Control_L | (XK_Control_R << 16))
  174. #define VK_DELETE (XK_Delete | (XK_KP_Delete << 16))
  175. #define VK_RETURN (XK_Return)
  176. #define VK_ESCAPE (XK_Escape)
  177. #define VK_DOWN (XK_Down)
  178. #define VK_UP (XK_Up)
  179. #define VK_LEFT (XK_Left)
  180. #define VK_RIGHT (XK_Right)
  181. #define VK_HOME (XK_Home)
  182. #define VK_END (XK_End)
  183. #define VK_PRIOR (XK_Prior)
  184. #define VK_NEXT (XK_Next)
  185. #define VK_BACK (XK_BackSpace)
  186. #define VK_F1 (XK_F1)
  187. #define VK_SPACE (XK_space)
  188. #define INVALID_HANDLE_VALUE NULL
  189. #endif
  190. // Come back here later
  191. typedef struct {
  192. pthread_mutex_t mutex;
  193. pthread_t id;
  194. int count;
  195. } CRITICAL_SECTION;
  196. typedef pthread_t HANDLE;
  197. typedef char OLECHAR;
  198. //#define NO_MMX
  199. //CUT? #define NULLREGION 0
  200. #define MAIN_MINX 0
  201. #define MAIN_MINY 0
  202. typedef void (*TIMERPROC)(HWND, UINT, UINT, DWORD);
  203. typedef struct {
  204. HWND hwnd;
  205. UINT message;
  206. WPARAM wParam;
  207. LPARAM lParam;
  208. DWORD time;
  209. POINT pt;
  210. } MSG;
  211. #ifdef __cplusplus
  212. #define _TRY try
  213. #define _EXCEPT(x) catch(...)
  214. #include <new>
  215. #ifdef WASABI_COMPILE_WND
  216. #define NULLREGION 1
  217. #define SIMPLEREGION 2
  218. #define COMPLEXREGION 3
  219. #endif
  220. // some of these are used even without wnd support
  221. enum {
  222. WM_CREATE, // MULL
  223. WM_CLOSE, // NULL
  224. WM_PAINT, // NULL
  225. WM_NCPAINT, // NULL
  226. WM_SYNCPAINT, // NULL
  227. WM_SETCURSOR, // NULL
  228. WM_TIMER, // timerid
  229. WM_SETFOCUS, // NULL
  230. WM_KILLFOCUS, // NULL
  231. WM_LBUTTONDOWN, // xPos | yPos << 16
  232. WM_RBUTTONDOWN, // "
  233. WM_MOUSEMOVE, // "
  234. WM_LBUTTONUP, // "
  235. WM_RBUTTONUP, // "
  236. WM_CONTEXTMENU, // "
  237. WM_ERASEBKGND, // NULL
  238. WM_MOUSEWHEEL, // a << 16 | t (l=a/120)
  239. WM_CHAR, // char
  240. WM_KEYDOWN, // keypress
  241. WM_KEYUP, // "
  242. WM_SYSKEYDOWN, // look at OnSysKeyDown
  243. WM_SYSKEYUP, // "
  244. WM_SYSCOMMAND, // Hunh?
  245. WM_MOUSEACTIVATE, // Hunh?
  246. WM_ACTIVATEAPP, // Hunh?
  247. WM_ACTIVATE, // WA_ACTIVE || WA_CLICKACTIVE
  248. WM_NCACTIVATE, // NULL
  249. WM_WINDOWPOSCHANGED, // NULL, WINDOWPOS *
  250. WM_DROPFILES, // HDROP
  251. WM_CAPTURECHANGED, // NULL
  252. WM_COMMAND, // Commands?..
  253. WM_SETTINGCHANGE,
  254. WM_QUIT,
  255. WM_DESTROY,
  256. WM_USER = 1000, // wParam, lParam -> make sure this is last
  257. };
  258. #define PM_NOREMOVE 0x0000
  259. #define PM_REMOVE 0x0001
  260. #define PM_NOYIELD 0x0002 // ignored
  261. #ifdef WASABI_COMPILE_WND
  262. enum {
  263. WA_ACTIVE, WA_CLICKACTIVE,
  264. };
  265. enum {
  266. SC_CLOSE,
  267. };
  268. enum {
  269. DT_LEFT,
  270. DT_CENTER,
  271. DT_RIGHT,
  272. DT_VCENTER,
  273. DT_WORDBREAK,
  274. DT_SINGLELINE,
  275. DT_NOPREFIX,
  276. DT_PATH_ELLIPSIS,
  277. DT_END_ELLIPSIS,
  278. DT_MODIFYSTRING,
  279. DT_CALCRECT,
  280. };
  281. #define ALL_EVENTS ExposureMask | StructureNotifyMask | \
  282. KeyPressMask | KeyReleaseMask | \
  283. ButtonPressMask | ButtonReleaseMask | \
  284. PointerMotionMask | FocusChangeMask | \
  285. EnterWindowMask | LeaveWindowMask
  286. #define NO_INPUT_EVENTS ExposureMask | StructureNotifyMask | \
  287. PointerMotionMask | FocusChangeMask | \
  288. EnterWindowMask | LeaveWindowMask
  289. class Linux {
  290. private:
  291. static Display *display;
  292. static XContext context;
  293. public:
  294. static Display *getDisplay();
  295. static int getScreenNum();
  296. static Window RootWin();
  297. static Visual *DefaultVis();
  298. static int convertEvent( MSG *, XEvent * );
  299. static void initContextData( HWND h );
  300. static void nukeContextData( HWND h );
  301. static XContext getContext();
  302. static void setCursor( HWND h, int cursor );
  303. };
  304. #endif
  305. #endif
  306. typedef void* HINSTANCE; // Useless, just a placeholder
  307. typedef void* HMONITOR;
  308. typedef void* WIN32_FIND_DATA;
  309. typedef void* WIN32_FIND_DATAW;
  310. typedef void* BLENDFUNCTION;
  311. typedef void* ATOM;
  312. typedef void* HGLOBAL;
  313. typedef void* HKEY;
  314. typedef char* LPTSTR;
  315. typedef char* LPCTSTR;
  316. typedef DWORD* LPDWORD;
  317. #if defined(WASABI_API_TIMER) || defined(WASABI_API_WND)
  318. int GetMessage( MSG *, HWND, UINT, UINT );
  319. int PeekMessage( MSG *, HWND, UINT, UINT, UINT );
  320. int DispatchMessage( MSG * );
  321. int SendMessage( HWND, UINT, WPARAM, LPARAM );
  322. int SetTimer( HWND, int id, int ms, TIMERPROC );
  323. void KillTimer( HWND, int id );
  324. #endif
  325. #ifdef WASABI_COMPILE_WND
  326. void TranslateMessage( MSG * );
  327. void PostMessage( HWND, UINT, WPARAM, LPARAM );
  328. void PostQuitMessage( int );
  329. enum contextdata {
  330. GWL_HINSTANCE = 0,
  331. GWL_USERDATA,
  332. GWL_INVALIDREGION,
  333. GWL_RECT_LEFT,
  334. GWL_RECT_TOP,
  335. GWL_RECT_RIGHT,
  336. GWL_RECT_BOTTOM,
  337. GWL_HWND,
  338. GWL_PARENT,
  339. GWL_ENUM_SIZE
  340. };
  341. void MoveWindowRect( HWND, int, int );
  342. void SetWindowRect( HWND, RECT * );
  343. int GetWindowRect( HWND, RECT * );
  344. void SetWindowLong( HWND, enum contextdata, LONG );
  345. LONG GetWindowLong( HWND, enum contextdata );
  346. int GetUpdateRect( HWND, RECT *, BOOL );
  347. void GetUpdateRgn( HWND, HRGN, BOOL );
  348. void InvalidateRgn( HWND, HRGN, BOOL );
  349. void InvalidateRect( HWND, const RECT *, BOOL );
  350. void ValidateRgn( HWND, HRGN );
  351. void ValidateRect( HWND, const RECT * );
  352. HWND GetActiveWindow();
  353. HWND WindowFromPoint( POINT p );
  354. #endif
  355. void OutputDebugString( const char *s );
  356. int MulDiv( int m1, int m2, int d );
  357. DWORD GetTickCount();
  358. void Sleep( int ms );
  359. int IntersectRect(RECT *, const RECT *, const RECT *);
  360. void ExitProcess( int ret );
  361. DWORD GetModuleFileName(void *pid, const char *filename, int bufsize);
  362. const char *CharPrev(const char *lpszStart, const char *lpszCurrent);
  363. int SubtractRect( RECT *out, RECT *in1, RECT *in2 );
  364. int EqualRect( RECT *a, RECT *b );
  365. void CopyFile( const char *f1, const char *f2, BOOL b );
  366. #endif