1
0

platform.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. #pragma once
  2. #include <bfc/platform/types.h>
  3. #include <bfc/std_mkncc.h> // for MKnCC
  4. #ifdef WIN32
  5. # include <bfc/platform/win32.h>
  6. #define OSMODULEHANDLE HINSTANCE
  7. #define INVALIDOSMODULEHANDLE ((OSMODULEHANDLE)0)
  8. #define OSWINDOWHANDLE HWND
  9. #define INVALIDOSWINDOWHANDLE ((OSWINDOWHANDLE)0)
  10. #define OSICONHANDLE HICON
  11. #define INVALIDOSICONHANDLE ((OSICONHANDLE)0)
  12. #define OSCURSORHANDLE HICON
  13. #define INVALIDOSCURSORHANDLE ((OSCURSORHANDLE)0)
  14. #define OSTHREADHANDLE HANDLE
  15. #define INVALIDOSTHREADHANDLE ((OSTHREADHANDLE)0)
  16. #define OSREGIONHANDLE HRGN
  17. #define INVALIDOSREGIONHANDLE ((OSREGIONHANDLE)0)
  18. typedef HMENU OSMENUHANDLE;
  19. #define RGBA(r,g,b,a) ((ARGB32)((uint8_t)(r) | ((uint8_t)(g) << 8) | ((uint8_t)(b) << 16) | ((uint8_t)(a) << 24)))
  20. #ifndef PATH_MAX
  21. #define PATH_MAX MAX_PATH
  22. #endif
  23. #elif defined(LINUX)
  24. # include <bfc/platform/linux.h>
  25. #elif defined(__APPLE__)
  26. #include <Carbon/Carbon.h>
  27. typedef HIShapeRef OSREGIONHANDLE;
  28. typedef int OSCURSOR; // TODO: find a good one for this
  29. typedef int OSCURSORHANDLE; // TODO: find a good one for this
  30. typedef HIWindowRef OSWINDOWHANDLE;
  31. typedef void *OSMODULEHANDLE; // TODO:
  32. typedef CGContextRef HDC; // TODO: find a better name
  33. typedef MenuRef OSMENUHANDLE;
  34. typedef CGImageRef OSICONHANDLE;
  35. #ifdef __LITTLE_ENDIAN__
  36. #define RGBA(r,g,b,a) ((ARGB32)((uint8_t)(r) | ((uint8_t)(g) << 8) | ((uint8_t)(b) << 16) | ((uint8_t)(a) << 24)))
  37. #elif defined(__BIG_ENDIAN__)
  38. #define RGBA(r,g,b,a) ((ARGB32)((uint8_t)(a) | ((uint8_t)(r) << 8) | ((uint8_t)(g) << 16) | ((uint8_t)(b) << 24)))
  39. #else
  40. #error endian preprocessor symbol not defined
  41. #endif
  42. #define RGB(r,g,b) RGBA(r,g,b,0xFF)
  43. static const HIWindowRef INVALIDOSWINDOWHANDLE = 0; // TODO: maybe there's an apple-defined name for this
  44. #define INVALIDOSMODULEHANDLE 0
  45. #define INVALIDOSCURSORHANDLE 0
  46. typedef char OSFNCHAR;
  47. typedef char *OSFNSTR;
  48. typedef const char OSFNCCHAR;
  49. typedef const char *OSFNCSTR;
  50. #define FNT(x) x
  51. typedef struct tagRECT
  52. {
  53. int left;
  54. int top;
  55. int right;
  56. int bottom;
  57. }
  58. RECT;
  59. typedef RECT * LPRECT;
  60. inline RECT RECTFromHIRect(const HIRect *r)
  61. {
  62. RECT rect;
  63. rect.left = r->origin.x;
  64. rect.right = r->origin.x + r->size.width;
  65. rect.top = r->origin.y;
  66. rect.bottom = r->origin.y + r->size.height;
  67. return rect;
  68. }
  69. inline HIRect HIRectFromRECT(const RECT *r)
  70. {
  71. HIRect rect;
  72. rect.origin.x = r->left;
  73. rect.origin.y = r->top;
  74. rect.size.width = r->right - r->left;
  75. rect.size.height = r->bottom - r->top;
  76. return rect;
  77. }
  78. typedef struct tagPOINT
  79. {
  80. int x;
  81. int y;
  82. }
  83. POINT;
  84. typedef struct tagPOINT * LPPOINT;
  85. inline HIPoint HIPointFromPOINT(const POINT *pt)
  86. {
  87. HIPoint p;
  88. p.x = pt->x;
  89. p.y = pt->y;
  90. return p;
  91. }
  92. inline int MulDiv(int a, int b, int c)
  93. {
  94. int s;
  95. int v;
  96. s = 0;
  97. if (a < 0)
  98. {
  99. s = !s;
  100. a = -a;
  101. }
  102. if (b < 0)
  103. {
  104. s = !s;
  105. b = -b;
  106. }
  107. if (c < 0)
  108. {
  109. s = !s;
  110. c = -c;
  111. }
  112. double d;
  113. d = ((double)a * (double)b) / (double)c;
  114. if (d >= 4294967296.)
  115. return -1;
  116. v = d;
  117. if (s)
  118. v = -v;
  119. return v;
  120. }
  121. #else
  122. #error port me
  123. // Windows API dependant definitions for non-windows platforms
  124. #define __cdecl
  125. #define __stdcall
  126. #define WINAPI
  127. #define WINBASEAPI
  128. #define WINUSERAPI
  129. #define WINGDIAPI
  130. #define WINOLEAPI
  131. #define CALLBACK
  132. #define FARPROC void *
  133. #define FALSE 0
  134. #define TRUE 1
  135. #define ERROR 0
  136. #define CONST const
  137. #define VOID void
  138. typedef unsigned long DWORD;
  139. typedef unsigned short WORD;
  140. typedef unsigned char BYTE;
  141. typedef long LONG;
  142. typedef int INT;
  143. typedef int BOOL;
  144. typedef short SHORT;
  145. typedef void * PVOID;
  146. typedef void * LPVOID;
  147. typedef char CHAR;
  148. typedef unsigned short WCHAR;
  149. typedef char * LPSTR;
  150. typedef WCHAR * LPWSTR;
  151. typedef const char * LPCSTR;
  152. typedef const WCHAR * LPCWSTR;
  153. typedef LPWSTR PTSTR, LPTSTR;
  154. typedef LPCWSTR LPCTSTR;
  155. typedef char TCHAR;
  156. typedef WCHAR OLECHAR;
  157. typedef void * HANDLE;
  158. typedef void * HWND;
  159. typedef void * HDC;
  160. typedef void * HFONT;
  161. typedef void * HBITMAP;
  162. typedef void * HINSTANCE;
  163. typedef void * HICON;
  164. typedef void * HRGN;
  165. typedef void * HPEN;
  166. typedef void * HBRUSH;
  167. typedef void * HRSRC;
  168. typedef void * HGLOBAL;
  169. typedef void * HACCEL;
  170. typedef void * HMODULE;
  171. typedef void * HMENU;
  172. typedef void * HGDIOBJ;
  173. typedef void * ATOM;
  174. typedef void * CRITICAL_SECTION;
  175. typedef void * LPCRITICAL_SECTION;
  176. typedef UINT WPARAM;
  177. typedef UINT LPARAM;
  178. typedef LONG LRESULT;
  179. typedef UINT COLORREF;
  180. typedef LRESULT(*WNDPROC)(HWND, UINT, WPARAM, LPARAM);
  181. typedef BOOL CALLBACK WNDENUMPROC(HWND, LPARAM);
  182. typedef VOID CALLBACK *TIMERPROC(HWND, UINT, UINT, DWORD);
  183. typedef struct tagPOINT
  184. {
  185. LONG x;
  186. LONG y;
  187. }
  188. POINT;
  189. typedef struct tagPOINT * LPPOINT;
  190. typedef struct tagSIZE
  191. {
  192. LONG cx;
  193. LONG cy;
  194. }
  195. SIZE;
  196. typedef struct tagRECT
  197. {
  198. LONG left;
  199. LONG top;
  200. LONG right;
  201. LONG bottom;
  202. }
  203. RECT;
  204. typedef RECT * LPRECT;
  205. typedef struct _COORD
  206. {
  207. SHORT X;
  208. SHORT Y;
  209. }
  210. COORD, *PCOORD;
  211. typedef struct tagPAINTSTRUCT
  212. {
  213. HDC hdc;
  214. BOOL fErase;
  215. RECT rcPaint;
  216. BOOL fRestore;
  217. BOOL fIncUpdate;
  218. BYTE rgbReserved[32];
  219. }
  220. PAINTSTRUCT;
  221. typedef struct tagBITMAP
  222. { /* bm */
  223. int bmType;
  224. int bmWidth;
  225. int bmHeight;
  226. int bmWidthBytes;
  227. BYTE bmPlanes;
  228. BYTE bmBitsPixel;
  229. LPVOID bmBits;
  230. }
  231. BITMAP;
  232. typedef struct tagRGBQUAD
  233. {
  234. BYTE rgbRed;
  235. BYTE rgbGreen;
  236. BYTE rgbBlue;
  237. BYTE rgbReserved;
  238. }
  239. RGBQUAD;
  240. typedef struct tagBITMAPINFOHEADER
  241. {
  242. DWORD biSize;
  243. LONG biWidth;
  244. LONG biHeight;
  245. WORD biPlanes;
  246. WORD biBitCount;
  247. DWORD biCompression;
  248. DWORD biSizeImage;
  249. LONG biXPelsPerMeter;
  250. LONG biYPelsPerMeter;
  251. DWORD biClrUsed;
  252. DWORD biClrImportant;
  253. }
  254. BITMAPINFOHEADER;
  255. typedef struct tagBITMAPINFO
  256. {
  257. BITMAPINFOHEADER bmiHeader;
  258. RGBQUAD bmiColors[1];
  259. }
  260. BITMAPINFO, *LPBITMAPINFO;
  261. typedef struct tagMSG
  262. {
  263. HWND hwnd;
  264. UINT message;
  265. WPARAM wParam;
  266. LPARAM lParam;
  267. DWORD time;
  268. POINT pt;
  269. }
  270. MSG;
  271. typedef MSG * LPMSG;
  272. typedef struct _RGNDATAHEADER
  273. {
  274. DWORD dwSize;
  275. DWORD iType;
  276. DWORD nCount;
  277. DWORD nRgnSize;
  278. RECT rcBound;
  279. }
  280. RGNDATAHEADER, *PRGNDATAHEADER;
  281. typedef struct _RGNDATA
  282. {
  283. RGNDATAHEADER rdh;
  284. char Buffer[1];
  285. }
  286. RGNDATA, *PRGNDATA;
  287. // Windows messages
  288. #define WM_SYSCOMMAND 0x112
  289. #define WM_LBUTTONDOWN 0x201
  290. #define WM_LBUTTONUP 0x202
  291. #define WM_RBUTTONDOWN 0x204
  292. #define WM_RBUTTONUP 0x205
  293. #define WM_USER 0x400
  294. #define WS_EX_TOOLWINDOW 0x00000080L
  295. #define WS_OVERLAPPED 0x00000000L
  296. #define WS_MAXIMIZEBOX 0x00010000L
  297. #define WS_MINIMIZEBOX 0x00020000L
  298. #define WS_SYSMENU 0x00080000L
  299. #define WS_CAPTION 0x00C00000L
  300. #define WS_CLIPCHILDREN 0x02000000L
  301. #define WS_CLIPSIBLINGS 0x04000000L
  302. #define WS_VISIBLE 0x10000000L
  303. #define WS_CHILD 0x40000000L
  304. #define WS_POPUP 0x80000000L
  305. #define HWND_TOP ((HWND)0)
  306. #define HWND_TOPMOST ((HWND)-1)
  307. #define HWND_NOTOPMOST ((HWND)-2)
  308. #define GWL_STYLE (-16)
  309. #define GW_HWNDFIRST 0
  310. #define GW_HWNDNEXT 2
  311. #define SWP_NOMOVE 0x0002
  312. #define SWP_NOSIZE 0x0001
  313. #define SWP_SHOWWINDOW 0x0040
  314. #define SWP_DEFERERASE 0x2000
  315. #define SWP_NOZORDER 0x0004
  316. #define SWP_NOACTIVATE 0x0010
  317. #define SW_SHOW 5
  318. #define SC_MINIMIZE 0xF020
  319. #define SC_MAXIMIZE 0xF030
  320. #define SC_RESTORE 0xF120
  321. #define GCL_HICONSM (-34)
  322. #define GCL_HICON (-14)
  323. #define MB_OK 0
  324. #define MB_OKCANCEL 1
  325. #define MB_TASKMODAL 0x2000L
  326. #define IDOK 1
  327. #define IDCANCEL 2
  328. #define VK_SHIFT 0x10
  329. #define VK_CONTROL 0x11
  330. #define VK_MENU 0x12
  331. #define RT_RCDATA 10
  332. #define IMAGE_BITMAP 0
  333. #define LR_LOADFROMFILE 0x0010
  334. #define DIB_RGB_COLORS 0
  335. #define MAX_PATH 1024
  336. #define _MAX_PATH MAX_PATH
  337. #define _MAX_DRIVE 3
  338. #define _MAX_DIR 256
  339. #define _MAX_FNAME 256
  340. #define _MAX_EXT 256
  341. #define GMEM_FIXED 0x0
  342. #define GMEM_ZEROINIT 0x40
  343. #define GPTR (GMEM_FIXED | GMEM_ZEROINIT)
  344. #define SPI_GETWORKAREA 48
  345. #define SM_CXDOUBLECLK 36
  346. #define SM_CYDOUBLECLK 37
  347. #define COLORONCOLOR 3
  348. #define SRCCOPY (DWORD)0x00CC0020
  349. #define BI_RGB 0L
  350. #define NULLREGION 1
  351. #define DT_LEFT 0x00000000
  352. #define DT_CENTER 0x00000001
  353. #define DT_RIGHT 0x00000002
  354. #define DT_VCENTER 0x00000004
  355. #define DT_WORDBREAK 0x00000010
  356. #define DT_SINGLELINE 0x00000020
  357. #define DT_CALCRECT 0x00000400
  358. #define DT_NOPREFIX 0x00000800
  359. #define DT_PATH_ELLIPSIS 0x00004000
  360. #define DT_END_ELLIPSIS 0x00008000
  361. #define DT_MODIFYSTRING 0x00010000
  362. #define FW_NORMAL 400
  363. #define FW_BOLD 700
  364. #define FF_DONTCARE (0<<4)
  365. #define BLACK_BRUSH 4
  366. #define NULL_BRUSH 5
  367. #define PS_SOLID 0
  368. #define PS_DOT 2
  369. #define TRANSPARENT 1
  370. #define OPAQUE 2
  371. #define ANSI_CHARSET 0
  372. #define ANSI_VAR_FONT 12
  373. #define OUT_DEFAULT_PRECIS 0
  374. #define CLIP_DEFAULT_PRECIS 0
  375. #define PROOF_QUALITY 2
  376. #define VARIABLE_PITCH 2
  377. #define RGN_AND 1
  378. #define RGN_OR 2
  379. #define RGN_DIFF 4
  380. #define RGN_COPY 5
  381. #define RDH_RECTANGLES 1
  382. #define MAXLONG 0x7fffffff
  383. // define GUID
  384. #include <bfc/platform/guid.h>
  385. #endif /* not WIN32 */
  386. #include <stdio.h>
  387. #include <stdlib.h>
  388. //#ifdef __cplusplus
  389. //#include <new>
  390. //#else
  391. //#include <new.h>
  392. //#endif
  393. #include <limits.h>
  394. #ifdef WIN32
  395. #define OSPIPE HANDLE
  396. #define OSPROCESSID int
  397. #endif
  398. // Ode macro keyworkds
  399. #define DISPATCH_ // makes a method dispatchable, automatically assigns a free ID (requires Interface)
  400. #define DISPATCH(x) // makes a method dispatchable and specifies its ID (not duplicate check, requires Interface)
  401. #define NODISPATCH // prevents a method from being dispatched if the class is marked for dispatching by default
  402. #define EVENT // marks a method as being an event to which other classes can connect to receive notification (used by Script and DependentItem helpers)
  403. #define SCRIPT // exposes a method to script interfaces (requires Script helper)
  404. #define IN // Input parameter
  405. #define OUT // Output parameter
  406. #define INOUT // Input/Output parameter