MiniGUI API Reference (MiniGUI-Standalone)  v4.0.0
A mature and proven cross-platform GUI system for embedded and smart IoT devices
common.h
Go to the documentation of this file.
1 //
3 // IMPORTANT NOTICE
4 //
5 // The following open source license statement does not apply to any
6 // entity in the Exception List published by FMSoft.
7 //
8 // For more information, please visit:
9 //
10 // https://www.fmsoft.cn/exception-list
11 //
13 
58 /*
59  * $Id: common.h 13674 2010-12-06 06:45:01Z wanzheng $
60  *
61  * MiniGUI for Linux/uClinux, eCos, uC/OS-II, VxWorks,
62  * pSOS, ThreadX, NuCleus, OSE, and Win32.
63  *
64  * The definitions of some data types and byte order macros
65  * borrowed from LGPL'ed SDL by Sam Lantinga.
66  *
67  * Fix point math routines come from Allegro (a gift software)
68  * by Shawn Hargreaves and others.
69  */
70 
71 #ifndef _MGUI_COMMON_H
72 
73 #define _MGUI_COMMON_H
74 
75 #ifndef MINIGUI_MAJOR_VERSION
76 # undef PACKAGE
77 # undef VERSION
78 # undef PACKAGE_BUGREPORT
79 # undef PACKAGE_NAME
80 # undef PACKAGE_STRING
81 # undef PACKAGE_TARNAME
82 # undef PACKAGE_VERSION
83 # ifdef __MINIGUI_LIB__
84 # ifdef _FOR_DATANG
85 # ifdef WIN32
86 # include <config-win32/mgconfig.h>
87 # elif defined (__THREADX__)
88 # include "config-threadx/mgconfig.h"
89 # elif defined (__NUCLEUS__)
90 # include "config-nucleus/mgconfig.h"
91 # endif
92 # else
93 # if defined(__CMAKE_PROJECT__) || defined(WIN32)
94 # include "mgconfig.h"
95 # else
96 # include "../mgconfig.h"
97 # endif
98 # endif
99 # else
100 # include "mgconfig.h"
101 # endif
102 #endif
103 
104 #include <stdio.h>
105 #include <stdlib.h>
106 #include <string.h>
107 #include <stdint.h>
108 #include <stdarg.h>
109 #include <errno.h>
110 #include <assert.h>
111 
132 #define _VERSION_CODE(major, minor, micro) (((major)<<16) | ((minor)<<8) | (micro))
133 
140 #define _MINIGUI_VERSION_CODE \
141  ((MINIGUI_MAJOR_VERSION << 16) | (MINIGUI_MINOR_VERSION << 8) | MINIGUI_MICRO_VERSION)
142 
154 typedef unsigned char Uint8;
159 typedef signed char Sint8;
164 typedef unsigned short Uint16;
169 typedef signed short Sint16;
174 typedef unsigned int Uint32;
179 typedef signed int Sint32;
180 
181 /* Figure out how to support 64-bit datatypes */
182 #if !defined(__STRICT_ANSI__)
183 # if defined(__GNUC__)
184 # define MGUI_HAS_64BIT_TYPE long long
185 # endif
186 # if defined(__CC_ARM)
187 # define MGUI_HAS_64BIT_TYPE long long
188 # endif
189 # if defined(_MSC_VER)
190 # define MGUI_HAS_64BIT_TYPE __int64
191 # endif
192 #endif /* !__STRICT_ANSI__ */
193 
194 /* The 64-bit datatype isn't supported on all platforms */
195 #ifdef MGUI_HAS_64BIT_TYPE
196 
203 typedef unsigned MGUI_HAS_64BIT_TYPE Uint64;
210 typedef signed MGUI_HAS_64BIT_TYPE Sint64;
211 #else
212 /* This is really just a hack to prevent the compiler from complaining */
213 typedef struct {
214  Uint32 hi;
215  Uint32 lo;
216 } Uint64, Sint64;
217 #endif
218 
219 /* Make sure the types really have the right sizes */
220 #define MGUI_COMPILE_TIME_ASSERT(name, x) \
221  typedef int MGUI_dummy_ ## name[(x) * 2 - 1]
222 
223 MGUI_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1);
224 MGUI_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1);
225 MGUI_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2);
226 MGUI_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2);
227 MGUI_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4);
228 MGUI_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4);
229 MGUI_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8);
230 MGUI_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
231 
232 #undef MGUI_COMPILE_TIME_ASSERT
233 
236 /* Here we provide MG_GNUC_EXTENSION as an alias for __extension__,
237  * where this is valid. This allows for warningless compilation of
238  * "long long" types even in the presence of '-ansi -pedantic'.
239  */
240 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
241 #define MG_GNUC_EXTENSION __extension__
242 #else
243 #define MG_GNUC_EXTENSION
244 #endif
245 
246 /*
247  * The MG_LIKELY and MG_UNLIKELY macros let the programmer give hints to
248  * the compiler about the expected result of an expression. Some compilers
249  * can use this information for optimizations.
250  */
251 #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
252 #define _MG_BOOLEAN_EXPR(expr) \
253  MG_GNUC_EXTENSION ({ \
254  int _g_boolean_var_; \
255  if (expr) \
256  _g_boolean_var_ = 1; \
257  else \
258  _g_boolean_var_ = 0; \
259  _g_boolean_var_; \
260 })
261 #define MG_LIKELY(expr) (__builtin_expect (_MG_BOOLEAN_EXPR(expr), 1))
262 #define MG_UNLIKELY(expr) (__builtin_expect (_MG_BOOLEAN_EXPR(expr), 0))
263 #else
264 #define MG_LIKELY(expr) (expr)
265 #define MG_UNLIKELY(expr) (expr)
266 #endif
267 
277 #define MGUI_LIL_ENDIAN 1234
278 
282 #define MGUI_BIG_ENDIAN 4321
283 
284 /* Pardon the mess, I'm trying to determine the endianness of this host.
285  * I'm doing it by preprocessor defines rather than some sort of configure
286  * script so that application code can use this too. The "right" way would
287  * be to dynamically generate this file on install, but that's a lot of work.
288  */
289 
307 #if defined(__i386__) || defined(__ia64__) || defined(__x86_64__) || defined(__amd64) || \
308  (defined(__alpha__) || defined(__alpha)) || \
309  defined(__arm__) || \
310  (defined(__CC_ARM) && !defined(__BIG_ENDIAN)) || \
311  (defined(__mips__) && defined(__MIPSEL__)) || \
312  defined(__LITTLE_ENDIAN__) || \
313  defined(WIN32)
314 # define MGUI_BYTEORDER MGUI_LIL_ENDIAN
315 #else
316 # define MGUI_BYTEORDER MGUI_BIG_ENDIAN
317 #endif
318 
331 typedef void *PVOID;
332 
337 #ifndef BOOL
338 typedef int BOOL;
339 #endif
340 
345 #ifndef FALSE
346  #define FALSE 0
347 #endif
348 
352 #ifndef TRUE
353  #define TRUE 1
354 #endif
355 
360 #ifndef NULL
361 # ifdef __cplusplus
362 # define NULL (0)
363 # else
364 # define NULL ((void *)0)
365 # endif
366 #endif
367 
372 #define INV_PTR ((void *)-1)
373 
374 #define GUIAPI
375 
376 #if !defined(__NODLL__) && (defined (WIN32) || defined (__NUCLEUS_MNT__))
377 # if defined(__MINIGUI_LIB__)
378 # define MG_EXPORT __declspec(dllexport)
379 # else
380 # define MG_EXPORT __declspec(dllimport)
381 # endif
382 #else
383 # define MG_EXPORT
384 #endif
385 
397 typedef PVOID GHANDLE;
402 typedef GHANDLE HWND;
407 typedef GHANDLE HDC;
417 typedef GHANDLE HCURSOR;
422 typedef GHANDLE HICON;
427 typedef GHANDLE HMENU;
432 typedef GHANDLE HACCEL;
437 typedef GHANDLE HDLG;
442 typedef GHANDLE HHOOK;
443 
455 typedef unsigned char BYTE;
456 
461 typedef signed char SBYTE;
462 
471 #if defined(_WIN64)
472 # define SIZEOF_PTR 8
473 # define SIZEOF_HPTR 4
474 #elif defined(__LP64__)
475 # define SIZEOF_PTR 8
476 # define SIZEOF_HPTR 4
477 #else
478 # define SIZEOF_PTR 4
479 # define SIZEOF_HPTR 2
480 #endif
481 
482 #if SIZEOF_PTR == 8
483 # define NR_BITS_BYTE (8)
484 # define NR_BITS_WORD (32)
485 # define NR_BITS_DWORD (64)
486 
487 # define BITMASK_BYTE (0xFF)
488 # define BITMASK_WORD (0xFFFFFFFF)
489 # define BITMASK_DWORD (0xFFFFFFFFFFFFFFFF)
490 
491 # define INT_PTR_MIN (-9223372036854775807L-1)
492 # define INT_PTR_MAX (9223372036854775807L)
493 # define UINT_PTR_MAX (18446744073709551615UL)
494 #else
495 # define NR_BITS_BYTE (8)
496 # define NR_BITS_WORD (16)
497 # define NR_BITS_DWORD (32)
498 
499 # define BITMASK_BYTE (0xFF)
500 # define BITMASK_WORD (0xFFFF)
501 # define BITMASK_DWORD (0xFFFFFFFF)
502 
503 # define INT_PTR_MIN (-2147483647-1)
504 # define INT_PTR_MAX (2147483647)
505 # define UINT_PTR_MAX (4294967295U)
506 #endif
507 
512 #if defined(_WIN64)
513 typedef unsigned int WORD_HPTR;
514 #elif defined(__LP64__)
515 typedef unsigned int WORD_HPTR;
516 #else
517 typedef unsigned short WORD_HPTR;
518 #endif
519 
524 #if defined(_WIN64)
525 typedef signed int SWORD_HPTR;
526 #elif defined(__LP64__)
527 typedef signed int SWORD_HPTR;
528 #else
529 typedef signed short SWORD_HPTR;
530 #endif
531 
536 typedef WORD_HPTR WORD;
537 
543 
548 typedef unsigned short WORD16;
549 
554 typedef signed short SWORD16;
555 
560 #if defined(_WIN64)
561 typedef __int64 LONG_PTR;
562 #elif defined(__LP64__)
563 typedef long LONG_PTR;
564 #else
565 typedef long LONG_PTR;
566 #endif
567 
572 typedef LONG_PTR LINT;
573 
579 
587 #if defined(_WIN64)
588 typedef unsigned __int64 DWORD_PTR;
589 #elif defined(__LP64__)
590 typedef unsigned long DWORD_PTR;
591 #else
592 typedef unsigned long DWORD_PTR;
593 #endif
594 
599 typedef DWORD_PTR DWORD;
600 
605 typedef unsigned int DWORD32;
606 
614 #if defined(_WIN64)
615 typedef signed __int64 SDWORD_PTR;
616 #elif defined(__LP64__)
617 typedef signed long SDWORD_PTR;
618 #else
619 typedef signed long SDWORD_PTR;
620 #endif
621 
627 
632 typedef signed int SDWORD32;
633 
634 #if SIZEOF_PTR == 8
635 typedef unsigned short QDWORD;
636 #define QDWORD_SHIFT 16
637 #else
638 typedef unsigned char QDWORD;
639 #define QDWORD_SHIFT 8
640 #endif
641 
642 #define MAKEDWORD(q1, q2, q3, q4) \
643  ((DWORD)( \
644  (((DWORD)(QDWORD)(q1))) | \
645  (((DWORD)((QDWORD)(q2))) << QDWORD_SHIFT) | \
646  (((DWORD)((QDWORD)(q3))) << (QDWORD_SHIFT*2)) | \
647  (((DWORD)((QDWORD)(q4))) << (QDWORD_SHIFT*3)) \
648  ))
649 
650 #define FIRST_QDWORD(dw) ((QDWORD)(((DWORD)(dw))))
651 #define SECOND_QDWORD(dw) ((QDWORD)((((DWORD)(dw)) >> QDWORD_SHIFT)))
652 #define THIRD_QDWORD(dw) ((QDWORD)((((DWORD)(dw)) >> (QDWORD_SHIFT*2))))
653 #define FOURTH_QDWORD(dw) ((QDWORD)((((DWORD)(dw)) >> (QDWORD_SHIFT*3))))
654 
659 typedef unsigned int UINT;
660 
665 #if defined(_WIN64)
666 typedef __int64 INT_PTR;
667 #elif defined(__LP64__)
668 typedef long INT_PTR;
669 #else
670 typedef int INT_PTR;
671 #endif
672 
677 #if defined(_WIN64)
678 typedef unsigned __int64 UINT_PTR;
679 #elif defined(__LP64__)
680 typedef unsigned long UINT_PTR;
681 #else
682 typedef unsigned long UINT_PTR;
683 #endif
684 
689 typedef long LONG;
690 
695 typedef unsigned long ULONG;
696 
701 typedef UINT_PTR WPARAM;
702 
707 typedef UINT_PTR LPARAM;
708 
715 #define LOBYTE(w) ((BYTE)(w))
716 
723 #define HIBYTE(w) ((BYTE)(((WORD)(w) >> NR_BITS_BYTE) & BITMASK_BYTE))
724 
731 #define MAKEWORD(low, high) ((WORD)(((BYTE)(low)) | (((WORD)((BYTE)(high))) << NR_BITS_BYTE)))
732 
739 #define MAKEWORD16(low, high) ((WORD16)(((BYTE)(low)) | (((WORD16)((BYTE)(high))) << 8)))
740 
747 #define MAKEDWORD32(first, second, third, fourth) \
748  ((DWORD32)( \
749  ((BYTE)(first)) | \
750  (((DWORD32)((BYTE)(second))) << 8) | \
751  (((DWORD32)((BYTE)(third))) << 16) | \
752  (((DWORD32)((BYTE)(fourth))) << 24) \
753  ))
754 
761 #define MAKEWPARAM(first, second, third, fourth) \
762  ((WPARAM)( \
763  ((BYTE)(first)) | \
764  (((WPARAM)((BYTE)(second))) << 8) | \
765  (((WPARAM)((BYTE)(third))) << 16) | \
766  (((WPARAM)((BYTE)(fourth))) << 24) \
767  ))
768 
775 #define FIRSTBYTE(w) ((BYTE)(w))
776 
783 #define SECONDBYTE(w) ((BYTE)(((DWORD32)(w)) >> 8))
784 
791 #define THIRDBYTE(w) ((BYTE)(((DWORD32)(w)) >> 16))
792 
799 #define FOURTHBYTE(w) ((BYTE)(((DWORD32)(w)) >> 24))
800 
807 #define LOWORD(l) ((WORD)(DWORD)(l))
808 
814 #define HIWORD(l) ((WORD)((((DWORD)(l)) >> NR_BITS_WORD) & BITMASK_WORD))
815 
822 #define LOSWORD(l) ((SWORD)(DWORD)(l))
823 
829 #define HISWORD(l) ((SWORD)((((DWORD)(l)) >> NR_BITS_WORD) & BITMASK_WORD))
830 
836 #define MAKELONG32(low, high) ((DWORD32)(((WORD16)(low)) | (((DWORD32)((WORD16)(high))) << 16)))
837 
843 #define MAKELONG(low, high) ((DWORD)(((WORD)(low)) | (((DWORD)((WORD)(high))) << NR_BITS_WORD)))
844 
850 
859 #define GetRValue(rgba) ((BYTE)(rgba))
860 
868 #define GetGValue(rgba) ((BYTE)(((DWORD32)(rgba)) >> 8))
869 
877 #define GetBValue(rgba) ((BYTE)((DWORD32)(rgba) >> 16))
878 
886 #define GetAValue(rgba) ((BYTE)((DWORD32)(rgba) >> 24))
887 
898 #define MakeRGBA(r, g, b, a) \
899  (((DWORD32)((BYTE)(r))) \
900  | ((DWORD32)((BYTE)(g)) << 8) \
901  | ((DWORD32)((BYTE)(b)) << 16) \
902  | ((DWORD32)((BYTE)(a)) << 24))
903 
914 #define MakeRGB(r, g, b) MakeRGBA((r), (g), (b), 255)
915 
925 typedef struct _RECT {
929  int left;
933  int top;
937  int right;
941  int bottom;
942 } RECT;
949 typedef RECT* PRECT;
950 
955 typedef struct _POINT
956 {
960  int x;
964  int y;
965 } POINT;
972 typedef POINT* PPOINT;
973 
978 typedef struct _SIZE
979 {
983  int cx;
987  int cy;
988 } SIZE;
995 typedef SIZE* PSIZE;
996 
1001 typedef struct _RGB
1002 {
1019 } RGB;
1020 
1027 typedef RGB* PRGB;
1028 
1049 
1064 
1079 
1084 typedef signed int gal_sint;
1089 typedef unsigned int gal_uint;
1090 
1101 
1106 typedef long fixed;
1107 
1112 typedef struct _GAL_Color
1113 {
1130 } GAL_Color;
1131 
1136 typedef struct _GAL_Palette
1137 {
1141  int ncolors;
1146 } GAL_Palette;
1147 
1152 typedef struct _GAL_Rect {
1156  Sint32 x, y;
1160  Sint32 w, h;
1161 } GAL_Rect;
1162 
1185 #define MGUI_NR_KEYS 255
1186 
1199 #ifndef NR_KEYS
1200 #define NR_KEYS 250
1201 #endif
1202 
1219 #define SCANCODE_USER (NR_KEYS + 1)
1220 
1221 #define SCANCODE_RESERVED 0
1222 #define SCANCODE_ESCAPE 1
1223  #define SCANCODE_ESC SCANCODE_ESCAPE
1224 
1225 #define SCANCODE_1 2
1226 #define SCANCODE_2 3
1227 #define SCANCODE_3 4
1228 #define SCANCODE_4 5
1229 #define SCANCODE_5 6
1230 #define SCANCODE_6 7
1231 #define SCANCODE_7 8
1232 #define SCANCODE_8 9
1233 #define SCANCODE_9 10
1234 #define SCANCODE_0 11
1235 
1236 #define SCANCODE_MINUS 12
1237 #define SCANCODE_EQUAL 13
1238 
1239 #define SCANCODE_BACKSPACE 14
1240 #define SCANCODE_TAB 15
1241 
1242 #define SCANCODE_Q 16
1243 #define SCANCODE_W 17
1244 #define SCANCODE_E 18
1245 #define SCANCODE_R 19
1246 #define SCANCODE_T 20
1247 #define SCANCODE_Y 21
1248 #define SCANCODE_U 22
1249 #define SCANCODE_I 23
1250 #define SCANCODE_O 24
1251 #define SCANCODE_P 25
1252 #define SCANCODE_BRACKET_LEFT 26
1253  #define SCANCODE_LEFTBRACE SCANCODE_BRACKET_LEFT
1254 #define SCANCODE_BRACKET_RIGHT 27
1255  #define SCANCODE_RIGHTBRACE SCANCODE_BRACKET_RIGHT
1256 
1257 #define SCANCODE_ENTER 28
1258 
1259 #define SCANCODE_LEFTCONTROL 29
1260  #define SCANCODE_LEFTCTRL SCANCODE_LEFTCONTROL
1261 
1262 #define SCANCODE_A 30
1263 #define SCANCODE_S 31
1264 #define SCANCODE_D 32
1265 #define SCANCODE_F 33
1266 #define SCANCODE_G 34
1267 #define SCANCODE_H 35
1268 #define SCANCODE_J 36
1269 #define SCANCODE_K 37
1270 #define SCANCODE_L 38
1271 #define SCANCODE_SEMICOLON 39
1272 #define SCANCODE_APOSTROPHE 40
1273 #define SCANCODE_GRAVE 41
1274 #define SCANCODE_LEFTSHIFT 42
1275 #define SCANCODE_BACKSLASH 43
1276 
1277 #define SCANCODE_Z 44
1278 #define SCANCODE_X 45
1279 #define SCANCODE_C 46
1280 #define SCANCODE_V 47
1281 #define SCANCODE_B 48
1282 #define SCANCODE_N 49
1283 #define SCANCODE_M 50
1284 #define SCANCODE_COMMA 51
1285 #define SCANCODE_PERIOD 52
1286  #define SCANCODE_DOT SCANCODE_PERIOD
1287 #define SCANCODE_SLASH 53
1288 #define SCANCODE_RIGHTSHIFT 54
1289 #define SCANCODE_KEYPADMULTIPLY 55
1290  #define SCANCODE_KPASTERISK SCANCODE_KEYPADMULTIPLY
1291 #define SCANCODE_LEFTALT 56
1292 #define SCANCODE_SPACE 57
1293 #define SCANCODE_CAPSLOCK 58
1294 
1295 #define SCANCODE_F1 59
1296 #define SCANCODE_F2 60
1297 #define SCANCODE_F3 61
1298 #define SCANCODE_F4 62
1299 #define SCANCODE_F5 63
1300 #define SCANCODE_F6 64
1301 #define SCANCODE_F7 65
1302 #define SCANCODE_F8 66
1303 #define SCANCODE_F9 67
1304 #define SCANCODE_F10 68
1305 
1306 #define SCANCODE_NUMLOCK 69
1307 #define SCANCODE_SCROLLLOCK 70
1308 
1309 #define SCANCODE_KEYPAD7 71
1310  #define SCANCODE_KP7 SCANCODE_KEYPAD7
1311 #define SCANCODE_CURSORUPLEFT 71
1312 #define SCANCODE_KEYPAD8 72
1313  #define SCANCODE_KP8 SCANCODE_KEYPAD8
1314 #define SCANCODE_CURSORUP 72
1315 #define SCANCODE_KEYPAD9 73
1316  #define SCANCODE_KP9 SCANCODE_KEYPAD9
1317 #define SCANCODE_CURSORUPRIGHT 73
1318 #define SCANCODE_KEYPADMINUS 74
1319  #define SCANCODE_KPMINUS SCANCODE_KEYPADMINUS
1320 #define SCANCODE_KEYPAD4 75
1321  #define SCANCODE_KP4 SCANCODE_KEYPAD4
1322 #define SCANCODE_CURSORLEFT 75
1323 #define SCANCODE_KEYPAD5 76
1324  #define SCANCODE_KP5 SCANCODE_KEYPAD5
1325 #define SCANCODE_KEYPAD6 77
1326  #define SCANCODE_KP6 SCANCODE_KEYPAD6
1327 #define SCANCODE_CURSORRIGHT 77
1328 #define SCANCODE_KEYPADPLUS 78
1329  #define SCANCODE_KPPLUS SCANCODE_KEYPADPLUS
1330 #define SCANCODE_KEYPAD1 79
1331  #define SCANCODE_KP1 SCANCODE_KEYPAD1
1332 #define SCANCODE_CURSORDOWNLEFT 79
1333 #define SCANCODE_KEYPAD2 80
1334  #define SCANCODE_KP2 SCANCODE_KEYPAD2
1335 #define SCANCODE_CURSORDOWN 80
1336 #define SCANCODE_KEYPAD3 81
1337  #define SCANCODE_KP3 SCANCODE_KEYPAD3
1338 #define SCANCODE_CURSORDOWNRIGHT 81
1339 #define SCANCODE_KEYPAD0 82
1340  #define SCANCODE_KP0 SCANCODE_KEYPAD0
1341 #define SCANCODE_KEYPADPERIOD 83
1342  #define SCANCODE_KPDOT SCANCODE_KEYPADPERIOD
1343 
1344 #define SCANCODE_ZENKAKUHANKAKU 85
1345 
1346 #define SCANCODE_LESS 86
1347 #define SCANCODE_102ND SCANCODE_LESS
1348 
1349 #define SCANCODE_F11 87
1350 #define SCANCODE_F12 88
1351 
1352 #define SCANCODE_RO 89
1353 #define SCANCODE_KATAKANA 90
1354 #define SCANCODE_HIRAGANA 91
1355 #define SCANCODE_HENKAN 92
1356 #define SCANCODE_KATAKANAHIRAGANA 93
1357 #define SCANCODE_MUHENKAN 94
1358 #define SCANCODE_KPJPCOMMA 95
1359 
1360 #define SCANCODE_KEYPADENTER 96
1361  #define SCANCODE_KPENTER SCANCODE_KEYPADENTER
1362 #define SCANCODE_RIGHTCONTROL 97
1363  #define SCANCODE_RIGHTCTRL SCANCODE_RIGHTCONTROL
1364 #define SCANCODE_CONTROL 97
1365 #define SCANCODE_KEYPADDIVIDE 98
1366  #define SCANCODE_KPSLASH SCANCODE_KEYPADDIVIDE
1367 #define SCANCODE_PRINTSCREEN 99
1368  #define SCANCODE_SYSRQ SCANCODE_PRINTSCREEN
1369 #define SCANCODE_RIGHTALT 100
1370 #define SCANCODE_LINEFEED 101
1371 
1372 #define SCANCODE_HOME 102
1373 #define SCANCODE_CURSORBLOCKUP 103 /* Cursor key block */
1374  #define SCANCODE_UP SCANCODE_CURSORBLOCKUP
1375 #define SCANCODE_PAGEUP 104
1376 #define SCANCODE_CURSORBLOCKLEFT 105 /* Cursor key block */
1377  #define SCANCODE_LEFT SCANCODE_CURSORBLOCKLEFT
1378 #define SCANCODE_CURSORBLOCKRIGHT 106 /* Cursor key block */
1379  #define SCANCODE_RIGHT SCANCODE_CURSORBLOCKRIGHT
1380 #define SCANCODE_END 107
1381 #define SCANCODE_CURSORBLOCKDOWN 108 /* Cursor key block */
1382  #define SCANCODE_DOWN SCANCODE_CURSORBLOCKDOWN
1383 #define SCANCODE_PAGEDOWN 109
1384 #define SCANCODE_INSERT 110
1385 #define SCANCODE_REMOVE 111
1386  #define SCANCODE_DELETE SCANCODE_REMOVE
1387 
1388 #define SCANCODE_MACRO 112
1389 #define SCANCODE_MUTE 113
1390 #define SCANCODE_VOLUMEDOWN 114
1391 #define SCANCODE_VOLUMEUP 115
1392 #define SCANCODE_POWER 116 /* SC System Power Down */
1393 #define SCANCODE_KPEQUAL 117
1394 #define SCANCODE_KPPLUSMINUS 118
1395 #define SCANCODE_BREAK 119
1396  #define SCANCODE_BREAK_ALTERNATIVE SCANCODE_BREAK
1397  #define SCANCODE_PAUSE SCANCODE_BREAK
1398 
1399 #define SCANCODE_SCALE 120 /* AL Compiz Scale (Expose) */
1400 #define SCANCODE_KPCOMMA 121
1401 #define SCANCODE_HANGEUL 122
1402 #define SCANCODE_HANJA 123
1403 #define SCANCODE_YEN 124
1404 #define SCANCODE_LEFTWIN 125
1405  #define SCANCODE_LEFTMETA SCANCODE_LEFTWIN
1406 #define SCANCODE_RIGHTWIN 126
1407  #define SCANCODE_RIGHTMETA SCANCODE_RIGHTWIN
1408 #define SCANCODE_COMPOSE 127
1409 #define SCANCODE_STOP 128 /* AC Stop */
1410 #define SCANCODE_AGAIN 129
1411 #define SCANCODE_PROPS 130 /* AC Properties */
1412 #define SCANCODE_UNDO 131 /* AC Undo */
1413 #define SCANCODE_FRONT 132
1414 #define SCANCODE_COPY 133 /* AC Copy */
1415 #define SCANCODE_OPEN 134 /* AC Open */
1416 #define SCANCODE_PASTE 135 /* AC Paste */
1417 #define SCANCODE_FIND 136 /* AC Search */
1418 #define SCANCODE_CUT 137 /* AC Cut */
1419 #define SCANCODE_HELP 138 /* AL Integrated Help Center */
1420 #define SCANCODE_MENU 139 /* Menu (show menu) */
1421 #define SCANCODE_CALC 140 /* AL Calculator */
1422 #define SCANCODE_SETUP 141
1423 #define SCANCODE_SLEEP 142 /* SC System Sleep */
1424 #define SCANCODE_WAKEUP 143 /* System Wake Up */
1425 #define SCANCODE_FILE 144 /* AL Local Machine Browser */
1426 #define SCANCODE_SENDFILE 145
1427 #define SCANCODE_DELETEFILE 146
1428 #define SCANCODE_XFER 147
1429 #define SCANCODE_PROG1 148
1430 #define SCANCODE_PROG2 149
1431 #define SCANCODE_WWW 150 /* AL Internet Browser */
1432 #define SCANCODE_MSDOS 151
1433 #define SCANCODE_COFFEE 152 /* AL Terminal Lock/Screensaver */
1434  #define SCANCODE_SCREENLOCK SCANCODE_COFFEE
1435 #define SCANCODE_ROTATE_DISPLAY 153 /* Display orientation for e.g. tablets */
1436  #define SCANCODE_DIRECTION SCANCODE_ROTATE_DISPLAY
1437 #define SCANCODE_CYCLEWINDOWS 154
1438 #define SCANCODE_MAIL 155
1439 #define SCANCODE_BOOKMARKS 156 /* AC Bookmarks */
1440 #define SCANCODE_COMPUTER 157
1441 #define SCANCODE_BACK 158 /* AC Back */
1442 #define SCANCODE_FORWARD 159 /* AC Forward */
1443 #define SCANCODE_CLOSECD 160
1444 #define SCANCODE_EJECTCD 161
1445 #define SCANCODE_EJECTCLOSECD 162
1446 #define SCANCODE_NEXTSONG 163
1447 #define SCANCODE_PLAYPAUSE 164
1448 #define SCANCODE_PREVIOUSSONG 165
1449 #define SCANCODE_STOPCD 166
1450 #define SCANCODE_RECORD 167
1451 #define SCANCODE_REWIND 168
1452 #define SCANCODE_PHONE 169 /* Media Select Telephone */
1453 #define SCANCODE_ISO 170
1454 #define SCANCODE_CONFIG 171 /* AL Consumer Control Configuration */
1455 #define SCANCODE_HOMEPAGE 172 /* AC Home */
1456 #define SCANCODE_REFRESH 173 /* AC Refresh */
1457 #define SCANCODE_EXIT 174 /* AC Exit */
1458 #define SCANCODE_MOVE 175
1459 #define SCANCODE_EDIT 176
1460 #define SCANCODE_SCROLLUP 177
1461 #define SCANCODE_SCROLLDOWN 178
1462 #define SCANCODE_KPLEFTPAREN 179
1463 #define SCANCODE_KPRIGHTPAREN 180
1464 #define SCANCODE_NEW 181 /* AC New */
1465 #define SCANCODE_REDO 182 /* AC Redo/Repeat */
1466 #define SCANCODE_F13 183
1467 #define SCANCODE_F14 184
1468 #define SCANCODE_F15 185
1469 #define SCANCODE_F16 186
1470 #define SCANCODE_F17 187
1471 #define SCANCODE_F18 188
1472 #define SCANCODE_F19 189
1473 #define SCANCODE_F20 190
1474 #define SCANCODE_F21 191
1475 #define SCANCODE_F22 192
1476 #define SCANCODE_F23 193
1477 #define SCANCODE_F24 194
1478 
1479 #define SCANCODE_PLAYCD 200
1480 #define SCANCODE_PAUSECD 201
1481 #define SCANCODE_PROG3 202
1482 #define SCANCODE_PROG4 203
1483 #define SCANCODE_DASHBOARD 204 /* AL Dashboard */
1484 #define SCANCODE_SUSPEND 205
1485 #define SCANCODE_CLOSE 206 /* AC Close */
1486 #define SCANCODE_PLAY 207
1487 #define SCANCODE_FASTFORWARD 208
1488 #define SCANCODE_BASSBOOST 209
1489 #define SCANCODE_PRINT 210 /* AC Print */
1490 #define SCANCODE_HP 211
1491 #define SCANCODE_CAMERA 212
1492 #define SCANCODE_SOUND 213
1493 #define SCANCODE_QUESTION 214
1494 #define SCANCODE_EMAIL 215
1495 #define SCANCODE_CHAT 216
1496 #define SCANCODE_SEARCH 217
1497 #define SCANCODE_CONNECT 218
1498 #define SCANCODE_FINANCE 219 /* AL Checkbook/Finance */
1499 #define SCANCODE_SPORT 220
1500 #define SCANCODE_SHOP 221
1501 #define SCANCODE_ALTERASE 222
1502 #define SCANCODE_CANCEL 223 /* AC Cancel */
1503 #define SCANCODE_BRIGHTNESSDOWN 224
1504 #define SCANCODE_BRIGHTNESSUP 225
1505 #define SCANCODE_MEDIA 226
1506 #define SCANCODE_SWITCHVIDEOMODE 227 /* Cycle between available video outputs (Monitor/LCD/TV-out/etc) */
1507 #define SCANCODE_KBDILLUMTOGGLE 228
1508 #define SCANCODE_KBDILLUMDOWN 229
1509 #define SCANCODE_KBDILLUMUP 230
1510 #define SCANCODE_SEND 231 /* AC Send */
1511 #define SCANCODE_REPLY 232 /* AC Reply */
1512 #define SCANCODE_FORWARDMAIL 233 /* AC Forward Msg */
1513 #define SCANCODE_SAVE 234 /* AC Save */
1514 #define SCANCODE_DOCUMENTS 235
1515 #define SCANCODE_BATTERY 236
1516 #define SCANCODE_BLUETOOTH 237
1517 #define SCANCODE_WLAN 238
1518 #define SCANCODE_UWB 239
1519 #define SCANCODE_UNKNOWN 240
1520 #define SCANCODE_VIDEO_NEXT 241 /* drive next video source */
1521 #define SCANCODE_VIDEO_PREV 242 /* drive previous video source */
1522 #define SCANCODE_BRIGHTNESS_CYCLE 243 /* brightness up, after max is min */
1523 #define SCANCODE_BRIGHTNESS_AUTO 244 /* Set Auto Brightness: manual brightness control is off, rely on ambient */
1524  #define SCANCODE_BRIGHTNESS_ZERO SCANCODE_BRIGHTNESS_AUTO
1525 #define SCANCODE_DISPLAY_OFF 245 /* display device to off state */
1526 #define SCANCODE_WWAN 246 /* Wireless WAN (LTE, UMTS, GSM, etc.) */
1527  #define SCANCODE_WIMAX SCANCODE_WWAN
1528 #define SCANCODE_RFKILL 247 /* Key that controls all radios */
1529 #define SCANCODE_MICMUTE 248 /* Mute / unmute the microphone */
1530 
1531 #define SCANCODE_LEFTBUTTON 0x1000
1532 #define SCANCODE_RIGHTBUTTON 0x2000
1533 #define SCANCODE_MIDDLBUTTON 0x4000
1534 
1544 #define KS_LEFTMETA 0x00002000
1545 
1555 #define KS_RIGHTMETA 0x00001000
1556 
1566 #define KS_META 0x00003000
1567 
1588 #define KS_REPEATED 0x00000800
1589 
1610 #define KS_CAPTURED 0x00000400
1611 
1618 #define KS_IMEPOST 0x00000200
1619 
1640 #define KS_CAPSLOCK 0x00000100
1641 
1649 #define KS_NUMLOCK 0x00000080
1650 
1658 #define KS_SCROLLLOCK 0x00000040
1659 
1667 #define KS_LEFTCTRL 0x00000020
1668 
1676 #define KS_RIGHTCTRL 0x00000010
1677 
1685 #define KS_CTRL 0x00000030
1686 
1694 #define KS_LEFTALT 0x00000008
1695 
1703 #define KS_RIGHTALT 0x00000004
1704 
1712 #define KS_ALT 0x0000000C
1713 
1721 #define KS_LEFTSHIFT 0x00000002
1722 
1730 #define KS_RIGHTSHIFT 0x00000001
1731 
1739 #define KS_SHIFT 0x00000003
1740 
1745 #define MASK_KS_SHIFTKEYS 0x0000FFFF
1746 
1754 #define KS_LEFTBUTTON 0x00010000
1755 
1763 #define KS_RIGHTBUTTON 0x00020000
1764 
1772 #define KS_MIDDLEBUTTON 0x00040000
1773 
1778 #define MASK_KS_BUTTONS 0x000F0000
1779 
1790 #define ERR_OK 0
1791 
1796 #define ERR_INV_HWND -1
1797 
1802 #define ERR_QUEUE_FULL -2
1803 
1808 #define ERR_INVALID_HANDLE -3
1809 
1814 #define ERR_INVALID_HMENU -4
1815 
1820 #define ERR_INVALID_POS -5
1821 
1826 #define ERR_INVALID_ID -6
1827 
1832 #define ERR_RES_ALLOCATION -7
1833 
1838 #define ERR_CTRLCLASS_INVNAME -8
1839 
1844 #define ERR_CTRLCLASS_INVLEN -9
1845 
1850 #define ERR_CTRLCLASS_MEM -10
1851 
1856 #define ERR_CTRLCLASS_INUSE -11
1857 
1862 #define ERR_ALREADY_EXIST -12
1863 
1868 #define ERR_NO_MATCH -13
1869 
1874 #define ERR_BAD_OWNER -14
1875 
1880 #define ERR_IME_TOOMUCHIMEWND -15
1881 
1886 #define ERR_IME_NOSUCHIMEWND -16
1887 
1892 #define ERR_IME_NOIMEWND -17
1893 
1898 #define ERR_CONFIG_FILE -18
1899 
1904 #define ERR_FILE_IO -19
1905 
1910 #define ERR_GFX_ENGINE -20
1911 
1916 #define ERR_INPUT_ENGINE -21
1917 
1922 #define ERR_NO_ENGINE -22
1923 
1928 #define ERR_INVALID_ARGS -23
1929 
1940 #define TABLESIZE(table) (sizeof(table)/sizeof(table[0]))
1941 
1942 /* MAX/MIN/ABS macors */
1947 #ifndef MAX
1948 #define MAX(x, y) (((x) > (y))?(x):(y))
1949 #endif
1950 
1954 #ifndef MIN
1955 #define MIN(x, y) (((x) < (y))?(x):(y))
1956 #endif
1957 
1961 #ifndef ABS
1962 #define ABS(x) (((x)<0) ? -(x) : (x))
1963 #endif
1964 
1965 /* Commonly used definitions */
1966 #if !defined(__NOUNIX__) || defined (__ECOS__)
1967 #include <limits.h>
1968 #endif
1969 
1970 #ifndef PATH_MAX
1971 # define PATH_MAX 256
1972 #endif
1973 
1974 #ifndef NAME_MAX
1975 # define NAME_MAX 64
1976 #endif
1977 
1978 
1984 #ifndef MAX_PATH
1985 # define MAX_PATH PATH_MAX
1986 #endif
1987 
1993 #ifndef MAX_NAME
1994 # define MAX_NAME NAME_MAX
1995 #endif
1996 
2001 #ifdef HAVE_TIME
2002 #include <time.h>
2003 #else
2004 typedef unsigned long time_t;
2005 
2006 struct tm {
2007  int tm_sec; /* seconds [0,61] */
2008  int tm_min; /* minutes [0,59] */
2009  int tm_hour; /* hour [0,23] */
2010  int tm_mday; /* day of month [1,31] */
2011  int tm_mon; /* month of year [0,11] */
2012  int tm_year; /* years since 1900 */
2013  int tm_wday; /* day of week [0,6] (Sunday = 0) */
2014  int tm_yday; /* day of year [0,365] */
2015  int tm_isdst; /* daylight savings flag */
2016 };
2017 #endif
2018 
2019 #ifdef __cplusplus
2020 extern "C" {
2021 #endif
2022 
2023 #if defined (__THREADX__) && defined (__TARGET_VFANVIL__)
2024 #include "fx_api.h"
2025 #include "tx_api.h"
2026 #include "os_type.h"
2027 #include "os_file_api.h"
2028 
2029 #define fopen tp_fopen
2030 #define fclose tp_fclose
2031 #define fwrite tp_fwrite
2032 #define fread tp_fread
2033 #define fseek tp_fseek
2034 #define feof tp_feof
2035 
2036 #undef assert
2037 #define _HAVE_ASSERT 1
2038 
2039 #define assert(e) do { \
2040  e; \
2041  } while (0)
2042 
2043 #undef stdin
2044 #undef stdout
2045 #undef stderr
2046 
2047 #define stdin ((FILE*)0)
2048 #define stdout ((FILE*)1)
2049 #define stderr ((FILE*)2)
2050 void Comm_Lock_Screen (void);
2051 void Comm_Unlock_Screen (void);
2052 
2053 #endif
2054 
2055 #ifdef __UCOSII__
2056 
2057 /* use our own implementation of strdup */
2058 #undef HAVE_STRDUP
2059 #undef strdup
2060 #define strdup own_strdup
2061 
2062 #endif /* __UCOSII__ */
2063 
2064 #ifndef HAVE_STRDUP
2065 MG_EXPORT char *strdup(const char *s);
2066 #endif
2067 
2068 #ifndef HAVE_STRCASECMP
2069 MG_EXPORT int strcasecmp(const char *s1, const char *s2);
2070 #endif
2071 
2072 #ifndef HAVE_STRNCASECMP
2073 MG_EXPORT int strncasecmp(const char *s1, const char *s2, unsigned int n);
2074 #endif
2075 
2076 #ifdef _MGUSE_OWN_MALLOC
2077 
2097 int init_minigui_malloc (unsigned char* heap, unsigned int heap_size,
2098  int (*lock_heap) (void), int (*unlock_heap) (void));
2099 
2100 #define USE_DL_PREFIX
2101 
2102 #include "own_malloc.h"
2103 
2104 /* wrappers for malloc functions */
2105 #define calloc dlcalloc
2106 #define free dlfree
2107 #define malloc dlmalloc
2108 #define memalign dlmemalign
2109 #define realloc dlrealloc
2110 #define valloc dlvalloc
2111 
2112 #endif
2113 
2114 /* Do not use the alloca of ARMCC */
2115 #if defined(__CC_ARM)
2116 # undef HAVE_ALLOCA
2117 # undef HAVE_ALLOCA_H
2118 #endif
2119 
2120 #ifdef HAVE_ALLOCA_H
2121 # include <alloca.h>
2122 # define ALLOCATE_LOCAL(size) alloca((int)(size))
2123 # define DEALLOCATE_LOCAL(ptr) /* as nothing */
2124 #else
2125 # define ALLOCATE_LOCAL(size) malloc((int)(size))
2126 # define DEALLOCATE_LOCAL(ptr) free(ptr)
2127 #endif
2128 
2129 #ifdef _MGUSE_OWN_STDIO
2130 
2143 int init_minigui_printf (int (*output_char) (int ch),
2144  int (*input_char) (void));
2145 
2146 #if defined (__UCOSII__) || defined (__VXWORKS__) || defined (__NUCLEUS__) || defined (__PSOS__)
2147 # undef _PRINTF_FLOATING_POINT
2148 # undef _SCANF_FLOATING_POINT
2149 #else
2150 # ifdef HAVE_MATH_H
2151 # define _PRINTF_FLOATING_POINT 1
2152 # define _SCANF_FLOATING_POINT 1
2153 # endif
2154 #endif
2155 
2156 #ifdef WIN32
2157 # include <float.h>
2158 # define isnan _isnan
2159 # define finite _finite
2160 #endif
2161 
2162 #undef _I18N_MB_REQUIRED
2163 
2164 #if defined(__VXWORKS__) || defined(WIN32) || defined (__NUCLEUS_MNT__) || defined (__PSOS__)
2165  #define _MGUSE_OWN_SNPRINTF
2166  #define _MGUSE_OWN_VSNPRINTF
2167  #define _MGUSE_OWN_VFNPRINTF
2168 #else
2169  #define _MGUSE_OWN_PRINTF
2170  #define _MGUSE_OWN_FPRINTF
2171  #define _MGUSE_OWN_SPRINTF
2172  #define _MGUSE_OWN_FNPRINTF
2173  #define _MGUSE_OWN_SNPRINTF
2174  #define _MGUSE_OWN_VPRINTF
2175  #define _MGUSE_OWN_VFPRINTF
2176  #define _MGUSE_OWN_VSPRINTF
2177  #define _MGUSE_OWN_VFNPRINTF
2178  #define _MGUSE_OWN_VSNPRINTF
2179  #define _MGUSE_OWN_SCANF
2180  #define _MGUSE_OWN_FSCANF
2181  #define _MGUSE_OWN_SSCANF
2182  #define _MGUSE_OWN_VSCANF
2183  #define _MGUSE_OWN_VFSCANF
2184  #define _MGUSE_OWN_VSSCANF
2185 #endif
2186 
2187 #include "own_stdio.h"
2188 
2189 /* wrappers for stdio functions */
2190 #ifdef _MGUSE_OWN_PRINTF
2191  #define printf own_printf
2192 #endif
2193 
2194 #ifdef _MGUSE_OWN_FPRINTF
2195  #define fprintf own_fprintf
2196 #endif
2197 
2198 #ifdef _MGUSE_OWN_SPRINTF
2199  #define sprintf own_sprintf
2200 #endif
2201 
2202 #ifdef _MGUSE_OWN_FNPRINTF
2203  #define fnprintf own_fnprintf
2204 #endif
2205 
2206 #ifdef _MGUSE_OWN_SNPRINTF
2207  #define snprintf own_snprintf
2208 #endif
2209 
2210 #ifdef _MGUSE_OWN_VPRINTF
2211  #define vprintf own_vprintf
2212 #endif
2213 
2214 #ifdef _MGUSE_OWN_VFPRINTF
2215  #define vfprintf own_vfprintf
2216 #endif
2217 
2218 #ifdef _MGUSE_OWN_VSPRINTF
2219  #define vsprintf own_vsprintf
2220 #endif
2221 
2222 #ifdef _MGUSE_OWN_VFNPRINTF
2223  #define vfnprintf own_vfnprintf
2224 #endif
2225 
2226 #ifdef _MGUSE_OWN_VSNPRINTF
2227  #define vsnprintf own_vsnprintf
2228 #endif
2229 
2230 #ifdef _MGUSE_OWN_SCANF
2231  #define scanf own_scanf
2232 #endif
2233 
2234 #ifdef _MGUSE_OWN_FSCANF
2235  #define fscanf own_fscanf
2236 #endif
2237 
2238 #ifdef _MGUSE_OWN_SSCANF
2239  #define sscanf own_sscanf
2240 #endif
2241 
2242 #ifdef _MGUSE_OWN_VSCANF
2243  #define vscanf own_vscanf
2244 #endif
2245 
2246 #ifdef _MGUSE_OWN_VFSCANF
2247  #define vfscanf own_vfscanf
2248 #endif
2249 
2250 #ifdef _MGUSE_OWN_VSSCANF
2251  #define vsscanf own_vsscanf
2252 #endif
2253 
2254 #endif /* _MGUSE_OWN_STDIO */
2255 
2256 #ifdef __LINUX__
2257  #define TCS_NONE(fp) fprintf (fp, "\e[0m")
2258  #define TCS_BLACK(fp) fprintf (fp, "\e[0;30m")
2259  #define TCS_BOLD_BLACK(fp) fprintf (fp, "\e[1;30m")
2260  #define TCS_RED(fp) fprintf (fp, "\e[0;31m")
2261  #define TCS_BOLD_RED(fp) fprintf (fp, "\e[1;31m")
2262  #define TCS_GREEN(fp) fprintf (fp, "\e[0;32m")
2263  #define TCS_BOLD_GREEN(fp) fprintf (fp, "\e[1;32m")
2264  #define TCS_BROWN(fp) fprintf (fp, "\e[0;33m")
2265  #define TCS_YELLOW(fp) fprintf (fp, "\e[1;33m")
2266  #define TCS_BLUE(fp) fprintf (fp, "\e[0;34m")
2267  #define TCS_BOLD_BLUE(fp) fprintf (fp, "\e[1;34m")
2268  #define TCS_PURPLE(fp) fprintf (fp, "\e[0;35m")
2269  #define TCS_BOLD_PURPLE(fp) fprintf (fp, "\e[1;35m")
2270  #define TCS_CYAN(fp) fprintf (fp, "\e[0;36m")
2271  #define TCS_BOLD_CYAN(fp) fprintf (fp, "\e[1;36m")
2272  #define TCS_GRAY(fp) fprintf (fp, "\e[0;37m")
2273  #define TCS_WHITE(fp) fprintf (fp, "\e[1;37m")
2274  #define TCS_BOLD(fp) fprintf (fp, "\e[1m")
2275  #define TCS_UNDERLINE(fp) fprintf (fp, "\e[4m")
2276  #define TCS_BLINK(fp) fprintf (fp, "\e[5m")
2277  #define TCS_REVERSE(fp) fprintf (fp, "\e[7m")
2278  #define TCS_HIDE(fp) fprintf (fp, "\e[8m")
2279  #define TCS_CLEAR(fp) fprintf (fp, "\e[2J")
2280  #define TCS_CLRLINE(fp) fprintf (fp, "\e[1K\r")
2281 #else
2282  #define TCS_NONE(fp)
2283  #define TCS_BLACK(fp)
2284  #define TCS_BOLD_BLACK(fp)
2285  #define TCS_RED(fp)
2286  #define TCS_BOLD_RED(fp)
2287  #define TCS_GREEN(fp)
2288  #define TCS_BOLD_GREEN(fp)
2289  #define TCS_BROWN(fp)
2290  #define TCS_YELLOW(fp)
2291  #define TCS_BLUE(fp)
2292  #define TCS_BOLD_BLUE(fp)
2293  #define TCS_PURPLE(fp)
2294  #define TCS_BOLD_PURPLE(fp)
2295  #define TCS_CYAN(fp)
2296  #define TCS_BOLD_CYAN(fp)
2297  #define TCS_GRAY(fp)
2298  #define TCS_WHITE(fp)
2299  #define TCS_BOLD(fp)
2300  #define TCS_UNDERLINE(fp)
2301  #define TCS_BLINK(fp)
2302  #define TCS_REVERSE(fp)
2303  #define TCS_HIDE(fp)
2304  #define TCS_CLEAR(fp)
2305  #define TCS_CLRLINE(fp)
2306 #endif
2307 
2308 #define _MG_PRINTF(fmt, ...) \
2309  do { \
2310  TCS_GREEN (stdout); \
2311  fprintf (stdout, fmt, ##__VA_ARGS__); \
2312  TCS_NONE (stdout); \
2313  } while (0)
2314 
2315 #define _WRN_PRINTF(fmt, ...) \
2316  do { \
2317  TCS_BROWN (stderr); \
2318  fprintf (stderr, "%s: ", __FUNCTION__); \
2319  fprintf (stderr, fmt, ##__VA_ARGS__); \
2320  fprintf (stderr, "\n"); \
2321  TCS_NONE (stderr); \
2322  } while (0)
2323 
2324 #define _ERR_PRINTF(fmt, ...) \
2325  do { \
2326  TCS_RED (stderr); \
2327  fprintf (stderr, fmt, ##__VA_ARGS__); \
2328  TCS_NONE (stderr); \
2329  } while (0)
2330 
2331 #if defined(_DEBUG)
2332 # define _DBG_PRINTF(fmt, ...) \
2333  do { \
2334  TCS_YELLOW (stderr); \
2335  fprintf (stderr, fmt, ##__VA_ARGS__); \
2336  TCS_NONE (stderr); \
2337  } while (0)
2338 # else
2339 # define _DBG_PRINTF(fmt, ...)
2340 #endif
2341 
2342 #ifdef _MGRM_THREADS
2343 
2344 #ifdef _MGUSE_OWN_PTHREAD
2345 
2346 #define MAIN_PTH_MIN_STACK_SIZE (1024)
2347 #define MAIN_PTH_DEF_STACK_SIZE (1024*4)
2348 
2372 int start_minigui_pthread (int (* pth_entry) (int argc, const char* argv []),
2373  int argc, const char* argv[],
2374  char* stack_base, unsigned int stack_size);
2375 
2376 #ifndef ESRCH
2377 # define ESRCH 3
2378 #endif
2379 
2380 #ifndef EAGAIN
2381 # define EAGAIN 11
2382 #endif
2383 
2384 #ifndef ENOMEM
2385 # define ENOMEM 12
2386 #endif
2387 
2388 #ifndef EBUSY
2389 # define EBUSY 16
2390 #endif
2391 
2392 #ifndef EINVAL
2393 # define EINVAL 22
2394 #endif
2395 
2396 #ifndef EDEADLK
2397 # define EDEADLK 35
2398 #endif
2399 
2400 #ifndef ENOSYS
2401 # define ENOSYS 38
2402 #endif
2403 
2404 #ifndef ENOTSUP
2405 # define ENOTSUP 95
2406 #endif
2407 
2408 #ifdef __VXWORKS__
2409 
2410 #define pthread_create vxworks_pthread_create
2411 #define pthread_self vxworks_pthread_self
2412 #define pthread_equal vxworks_pthread_equal
2413 #define pthread_exit vxworks_pthread_exit
2414 #define pthread_join vxworks_pthread_join
2415 #define pthread_detach vxworks_pthread_detach
2416 #define pthread_cancel vxworks_pthread_cancel
2417 #define pthread_once vxworks_pthread_once
2418 #define pthread_key_create vxworks_pthread_key_create
2419 #define pthread_key_delete vxworks_pthread_key_delete
2420 #define pthread_setspecific vxworks_pthread_setspecific
2421 #define pthread_getspecific vxworks_pthread_getspecific
2422 #define pthread_setcancelstate vxworks_pthread_setcancelstate
2423 #define pthread_setcanceltype vxworks_pthread_setcanceltype
2424 #define pthread_testcancel vxworks_pthread_testcancel
2425 
2426 #define pthread_attr_init vxworks_pthread_attr_init
2427 #define pthread_attr_destroy vxworks_pthread_attr_destroy
2428 #define pthread_attr_setdetachstate vxworks_pthread_attr_setdetachstate
2429 #define pthread_attr_getdetachstate vxworks_pthread_attr_getdetachstate
2430 #define pthread_attr_setscope vxworks_pthread_attr_setscope
2431 #define pthread_attr_getscope vxworks_pthread_attr_getscope
2432 #define pthread_attr_setinheritsched vxworks_pthread_attr_setinheritsched
2433 #define pthread_attr_getinheritsched vxworks_pthread_attr_getinheritsched
2434 #define pthread_attr_setschedpolicy vxworks_pthread_attr_setschedpolicy
2435 #define pthread_attr_getschedpolicy vxworks_pthread_attr_getschedpolicy
2436 #define pthread_attr_setschedparam vxworks_pthread_attr_setschedparam
2437 #define pthread_attr_getschedparam vxworks_pthread_attr_getschedparam
2438 #define pthread_attr_setstackaddr vxworks_pthread_attr_setstackaddr
2439 #define pthread_attr_getstackaddr vxworks_pthread_attr_getstackaddr
2440 #define pthread_attr_setstacksize vxworks_pthread_attr_setstacksize
2441 #define pthread_attr_getstacksize vxworks_pthread_attr_getstacksize
2442 #define pthread_setschedparam vxworks_pthread_setschedparam
2443 #define pthread_getschedparam vxworks_pthread_getschedparam
2444 
2445 #define pthread_mutex_init vxworks_pthread_mutex_init
2446 #define pthread_mutex_destroy vxworks_pthread_mutex_destroy
2447 #define pthread_mutex_lock vxworks_pthread_mutex_lock
2448 #define pthread_mutex_unlock vxworks_pthread_mutex_unlock
2449 #define pthread_mutex_trylock vxworks_pthread_mutex_trylock
2450 #define pthread_mutexattr_init vxworks_pthread_mutexattr_init
2451 #define pthread_mutexattr_destroy vxworks_pthread_mutexattr_destroy
2452 #define pthread_mutexattr_setpriorityinherit vxworks_pthread_mutexattr_setpriorityinherit
2453 #define pthread_mutexattr_getpriorityinherit vxworks_pthread_mutexattr_getpriorityinherit
2454 
2455 #ifdef _MGUSE_OWN_SEMAPHORE
2456 
2457 #define sem_t vxworks_sem_t
2458 
2459 #define sem_init vxworks_sem_init
2460 #define sem_destroy vxworks_sem_destroy
2461 #define sem_wait vxworks_sem_wait
2462 #define sem_trywait vxworks_sem_trywait
2463 #define sem_post vxworks_sem_post
2464 #define sem_getvalue vxworks_sem_getvalue
2465 
2466 #endif /* _MGUSE_OWN_SEMAPHORE */
2467 
2468 #endif /* __VXWORKS__ */
2469 
2470 #ifdef __MINIGUI_LIB__
2471 
2472 #ifdef __UCOSII__
2473 # include "ucos2_pthread.h"
2474 # include "ucos2_semaphore.h"
2475 #elif defined (__THREADX__)
2476 # include "threadx_pthread.h"
2477 # include "threadx_semaphore.h"
2478 #elif defined (__NUCLEUS__)
2479 # include "nucleus_pthread.h"
2480 # include "nucleus_semaphore.h"
2481 #elif defined (__VXWORKS__)
2482 # include "vxworks_pthread.h"
2483 # ifdef _MGUSE_OWN_SEMAPHORE
2484 # include "vxworks_semaphore.h"
2485 # else
2486 # include "semaphore.h"
2487 # endif
2488 #elif defined (__OSE__)
2489 # include "pthread.h"
2490 # include "ose_semaphore.h"
2491 #elif defined (__PSOS__)
2492 # include "psos_pthread.h"
2493 # include "psos_semaphore.h"
2494 #elif defined (WIN32)
2495 # include "win32_pthread.h"
2496 # include "win32_semaphore.h"
2497 #else
2498 # error No own pthread implementation for this OS!
2499 #endif
2500 
2501 #else
2502 
2503 # include <pthread.h>
2504 # include <semaphore.h>
2505 
2506 #endif /* __MINIGUI_LIB__ */
2507 
2508 #else /* _MGUSE_OWN_PTHREAD */
2509 
2510 #include <pthread.h>
2511 #include <semaphore.h>
2512 
2513 #endif /* !_MGUSE_OWN_PTHREAD */
2514 
2515 #ifdef __DARWIN__
2516 
2517 #define _USE_SEM_ON_SYSVIPC 1
2518 
2519 #endif
2520 
2521 #if defined (_USE_MUTEX_ON_SYSVIPC) || defined (_USE_SEM_ON_SYSVIPC)
2522 
2523 int _sysvipc_mutex_sem_init (void);
2524 int _sysvipc_mutex_sem_term (void);
2525 
2526 #endif
2527 
2528 #ifdef _USE_MUTEX_ON_SYSVIPC
2529 
2530 #define pthread_mutex_t _sysvipc_pthread_mutex_t
2531 #define pthread_mutexattr_t _sysvipc_pthread_mutexattr_t
2532 
2533 #define pthread_mutexattr_init _sysvipc_pthread_mutexattr_init
2534 #define pthread_mutexattr_destroy _sysvipc_pthread_mutexattr_destroy
2535 #define pthread_mutexattr_settype _sysvipc_pthread_mutexattr_settype
2536 #define pthread_mutexattr_gettype _sysvipc_pthread_mutexattr_gettype
2537 
2538 #define pthread_init _sysvipc_pthread_init
2539 #define pthread_mutex_init _sysvipc_pthread_mutex_init
2540 #define pthread_mutex_destroy _sysvipc_pthread_mutex_destroy
2541 #define pthread_mutex_lock _sysvipc_pthread_mutex_lock
2542 #define pthread_mutex_trylock _sysvipc_pthread_mutex_trylock
2543 #define pthread_mutex_unlock _sysvipc_pthread_mutex_unlock
2544 
2545 typedef struct
2546 {
2547  int kind;
2548  int semid;
2549  int sem_num;
2550  int locked_times;
2551 } pthread_mutex_t;
2552 
2553 #define SYSVIPC_PTHREAD_MUTEX_FAST_NP 0
2554 #define SYSVIPC_PTHREAD_MUTEX_RECURSIVE_NP 1
2555 #define SYSVIPC_PTHREAD_MUTEX_ERRORCHECK_NP 2
2556 
2557 typedef struct
2558 {
2559  int kind;
2560 } pthread_mutexattr_t;
2561 
2562 int pthread_mutexattr_init (pthread_mutexattr_t *attr);
2563 int pthread_mutexattr_destroy (pthread_mutexattr_t *attr);
2564 int pthread_mutexattr_settype (pthread_mutexattr_t *attr, int type);
2565 int pthread_mutexattr_gettype (const pthread_mutexattr_t *attr, int* type);
2566 
2567 int pthread_mutex_init (pthread_mutex_t *mutex,
2568  const pthread_mutexattr_t *mutex_attr);
2569 
2570 int pthread_mutex_destroy (pthread_mutex_t *mutex);
2571 
2572 int pthread_mutex_lock (pthread_mutex_t *mutex);
2573 int pthread_mutex_trylock (pthread_mutex_t *mutex);
2574 int pthread_mutex_unlock (pthread_mutex_t *mutex);
2575 
2576 #endif /* _USE_MUTEX_ON_SYSVIPC */
2577 
2578 #ifdef _USE_SEM_ON_SYSVIPC
2579 
2580 #define sem_t _sysvipc_sem_t
2581 
2582 #define sem_init _sysvipc_sem_init
2583 #define sem_destroy _sysvipc_sem_destroy
2584 #define sem_wait _sysvipc_sem_wait
2585 #define sem_trywait _sysvipc_sem_trywait
2586 #define sem_post _sysvipc_sem_post
2587 #define sem_getvalue _sysvipc_sem_getvalue
2588 
2589 #define SYSVIPC_SEM_VALUE_MAX USHRT_MAX
2590 
2591 /*-----------------------------------------------------------------------------
2592 ** Semaphore object definition
2593 */
2594 
2595 typedef struct
2596 {
2597  int semid;
2598  int sem_num;
2599 } sem_t;
2600 
2601 int sem_init (sem_t *sem, int pshared, unsigned int value);
2602 int sem_destroy (sem_t *sem);
2603 int sem_wait (sem_t *sem);
2604 int sem_trywait (sem_t *sem);
2605 int sem_post (sem_t *sem);
2606 int sem_getvalue (sem_t *sem, int *sval);
2607 
2608 #endif /* _USE_SEM_ON_SYSVIPC */
2609 
2610 #endif /* _MGRM_THREADS */
2611 
2612 #ifdef __cplusplus
2613 } /* end of extern "C" */
2614 #endif
2615 
2616 #endif /* _MGUI_COMMON_H */
2617 
struct _GAL_Rect GAL_Rect
GHANDLE HACCEL
Handle to accelarator.
Definition: common.h:432
struct _RECT RECT
Definition: common.h:955
int BOOL
A type definition for boolean value.
Definition: common.h:338
GAL_Color * colors
Definition: common.h:1145
long LONG
A type definition for long integer.
Definition: common.h:689
unsigned char BYTE
A type definition for an 8-bit unsigned character (byte).
Definition: common.h:455
SIZE * PSIZE
Data type of the pointer to a SIZE.
Definition: common.h:995
signed short SWORD16
A type definition for a 16-bit signed integer.
Definition: common.h:554
POINT * PPOINT
Data type of the pointer to a POINT.
Definition: common.h:972
BYTE g
Definition: common.h:1010
Uint32 gal_uint32
Data type of 32-bit unsigned integer.
Definition: common.h:1078
int cy
Definition: common.h:987
unsigned long DWORD_PTR
An unsigned long type for pointer precision.
Definition: common.h:592
Uint32 gal_attr
Data type of attribute value.
Definition: common.h:1100
Definition: common.h:925
Uint32 gal_pixel
Data type of pixel value.
Definition: common.h:1095
unsigned long long Uint64
A type definition for a 64-bit unsigned integer.
Definition: common.h:203
signed short Sint16
A type definition for a 16-bit signed integer.
Definition: common.h:169
int x
Definition: common.h:960
unsigned short Uint16
A type definition for a 16-bit unsigned integer.
Definition: common.h:164
DWORD32 RGBCOLOR
A type definition for a RGB color.
Definition: common.h:849
struct _GAL_Palette GAL_Palette
signed char Sint8
A type definition for an 8-bit signed character.
Definition: common.h:159
Sint32 x
Definition: common.h:1156
GHANDLE HDC
Handle to device context.
Definition: common.h:407
long LONG_PTR
A signed long type for pointer precision.
Definition: common.h:565
int ncolors
Definition: common.h:1141
int bottom
Definition: common.h:941
GHANDLE HHOOK
Handle to keyboard or mouse event hook.
Definition: common.h:442
unsigned int gal_uint
Data type of unsigned integer.
Definition: common.h:1089
unsigned short WORD16
A type definition for a 16-bit unsigned integer (word).
Definition: common.h:548
signed long long Sint64
A type definition for a 64-bit signed integer.
Definition: common.h:210
Uint8 gal_uint8
Data type of 8-bit unsigned integer.
Definition: common.h:1048
signed int Sint32
A type definition for a 32-bit signed integer.
Definition: common.h:179
GHANDLE HWND
Handle to main window or control.
Definition: common.h:402
GHANDLE HDLG
Handle to dialog box, same as HWND.
Definition: common.h:437
gal_uint8 a
Definition: common.h:1129
unsigned short WORD_HPTR
An unsigned int (word) type in half pointer precision.
Definition: common.h:517
int INT_PTR
A signed integer type for pointer precision.
Definition: common.h:670
Definition: common.h:978
RGB * PRGB
Data type of the pointer to a RGB.
Definition: common.h:1027
LONG_PTR LINT
Signed integer which has pointer precision.
Definition: common.h:572
struct _SIZE SIZE
GHANDLE HCURSOR
Handle to cursor.
Definition: common.h:417
PVOID GHANDLE
General handle.
Definition: common.h:397
RECT * PRECT
Data type of the pointer to a RECT.
Definition: common.h:949
int y
Definition: common.h:964
unsigned char Uint8
A type definition for an 8-bit unsigned character.
Definition: common.h:154
UINT_PTR LPARAM
A type definition for the second message paramter.
Definition: common.h:707
int right
Definition: common.h:937
GHANDLE HPALETTE
Handle to a logical palette.
Definition: common.h:412
Sint16 gal_sint16
Data type of 16-bit signed integer.
Definition: common.h:1056
Definition: common.h:1001
struct _RGB RGB
Sint8 gal_sint8
Data type of 8-bit signed integer.
Definition: common.h:1041
signed short SWORD_HPTR
An signed int type in half pointer precision.
Definition: common.h:529
unsigned long ULONG
A type definition for unsigned long integer.
Definition: common.h:695
struct _GAL_Color GAL_Color
long fixed
Data type of fixed point.
Definition: common.h:1106
WORD_HPTR WORD
A type definition for an unsigned integer (word).
Definition: common.h:536
unsigned int Uint32
A type definition for a 32-bit unsigned integer.
Definition: common.h:174
UINT_PTR WPARAM
A type definition for the first message paramter.
Definition: common.h:701
gal_uint8 r
Definition: common.h:1117
DWORD_PTR DWORD
A unsigned long type definition for pointer precision.
Definition: common.h:599
gal_uint8 g
Definition: common.h:1121
SWORD_HPTR SWORD
A type definition for a signed integer.
Definition: common.h:542
LONG_PTR LRESULT
Signed result of message processing.
Definition: common.h:578
int left
Definition: common.h:929
void * PVOID
A type definition for a pointer to any type.
Definition: common.h:331
signed long SDWORD_PTR
A signed long type for pointer precision.
Definition: common.h:619
unsigned long UINT_PTR
A unsigned integer type for pointer precision.
Definition: common.h:682
signed int gal_sint
Data type of signed integer.
Definition: common.h:1084
SDWORD_PTR SDWORD
A signed long type definition for pointer precision.
Definition: common.h:626
Sint32 w
Definition: common.h:1160
unsigned int UINT
A type definition for unsigned integer.
Definition: common.h:659
unsigned int DWORD32
A type definition for a 32-bit unsigned integer.
Definition: common.h:605
Sint32 gal_sint32
Data type of 32-bit signed integer.
Definition: common.h:1071
int cx
Definition: common.h:983
int top
Definition: common.h:933
BYTE b
Definition: common.h:1014
GHANDLE HMENU
Handle to menu.
Definition: common.h:427
struct _POINT POINT
Uint16 gal_uint16
Data type of 16-bit unsigned integer.
Definition: common.h:1063
gal_uint8 b
Definition: common.h:1125
signed char SBYTE
A type definition for an 8-bit signed character.
Definition: common.h:461
BYTE r
Definition: common.h:1006
BYTE a
Definition: common.h:1018
GHANDLE HICON
Handle to icon.
Definition: common.h:422
signed int SDWORD32
A type definition for a 32-bit signed integer.
Definition: common.h:632