1 /******************************************************************************** 2 * * 3 * FOX Definitions, Types, and Macros * 4 * * 5 ********************************************************************************* 6 * Copyright (C) 1997,2006 by Jeroen van der Zijp. All Rights Reserved. * 7 ********************************************************************************* 8 * This library is free software; you can redistribute it and/or * 9 * modify it under the terms of the GNU Lesser General Public * 10 * License as published by the Free Software Foundation; either * 11 * version 2.1 of the License, or (at your option) any later version. * 12 * * 13 * This library is distributed in the hope that it will be useful, * 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 16 * Lesser General Public License for more details. * 17 * * 18 * You should have received a copy of the GNU Lesser General Public * 19 * License along with this library; if not, write to the Free Software * 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 21 ********************************************************************************* 22 * $Id: fxdefs.h,v 1.178.2.2 2006/11/09 23:21:43 fox Exp $ * 23 ********************************************************************************/ 24 #ifndef FXDEFS_H 25 #define FXDEFS_H 26 27 28 /******************************** Definitions ********************************/ 29 30 // Truth values 31 #ifndef TRUE 32 #define TRUE 1 33 #endif 34 #ifndef FALSE 35 #define FALSE 0 36 #endif 37 #ifndef MAYBE 38 #define MAYBE 2 39 #endif 40 #ifndef NULL 41 #define NULL 0 42 #endif 43 44 /// Pi 45 #ifndef PI 46 #define PI 3.1415926535897932384626433833 47 #endif 48 49 /// Euler constant 50 #define EULER 2.7182818284590452353602874713 51 52 /// Multiplier for degrees to radians 53 #define DTOR 0.0174532925199432957692369077 54 55 /// Multiplier for radians to degrees 56 #define RTOD 57.295779513082320876798154814 57 58 59 // Path separator 60 #ifdef WIN32 61 #define PATHSEP '\\' 62 #define PATHSEPSTRING "\\" 63 #define PATHLISTSEP ';' 64 #define PATHLISTSEPSTRING ";" 65 #define ISPATHSEP(c) ((c)=='/' || (c)=='\\') 66 #else 67 #define PATHSEP '/' 68 #define PATHSEPSTRING "/" 69 #define PATHLISTSEP ':' 70 #define PATHLISTSEPSTRING ":" 71 #define ISPATHSEP(c) ((c)=='/') 72 #endif 73 74 // End Of Line 75 #ifdef WIN32 76 #define ENDLINE "\r\n" 77 #else 78 #define ENDLINE "\n" 79 #endif 80 81 82 // For Windows 83 #ifdef _DEBUG 84 #ifndef DEBUG 85 #define DEBUG 86 #endif 87 #endif 88 #ifdef _NDEBUG 89 #ifndef NDEBUG 90 #define NDEBUG 91 #endif 92 #endif 93 94 95 // Shared library support 96 #ifdef WIN32 97 #define FXLOCAL 98 #define FXEXPORT __declspec(dllexport) 99 #define FXIMPORT __declspec(dllimport) 100 #else 101 #if defined(__GNUC__) && (__GNUC__ >= 4) 102 #define FXLOCAL __attribute__ ((visibility("hidden"))) 103 #define FXEXPORT __attribute__ ((visibility("default"))) 104 #define FXIMPORT 105 #else 106 #define FXLOCAL 107 #define FXEXPORT 108 #define FXIMPORT 109 #endif 110 #endif 111 112 // Define FXAPI for DLL builds 113 #ifdef FOXDLL 114 #ifdef FOXDLL_EXPORTS 115 #define FXAPI FXEXPORT 116 #define FXTEMPLATE_EXTERN 117 #else 118 #define FXAPI FXIMPORT 119 #define FXTEMPLATE_EXTERN extern 120 #endif 121 #else 122 #define FXAPI 123 #define FXTEMPLATE_EXTERN 124 #endif 125 126 // Callback 127 #ifdef WIN32 128 #ifndef CALLBACK 129 #define CALLBACK __stdcall 130 #endif 131 #endif 132 133 134 // Checking printf and scanf format strings 135 #if defined(_CC_GNU_) || defined(__GNUG__) || defined(__GNUC__) 136 #define FX_PRINTF(fmt,arg) __attribute__((format(printf,fmt,arg))) 137 #define FX_SCANF(fmt,arg) __attribute__((format(scanf,fmt,arg))) 138 #else 139 #define FX_PRINTF(fmt,arg) 140 #define FX_SCANF(fmt,arg) 141 #endif 142 143 // Raw event type 144 #ifndef WIN32 145 union _XEvent; 146 #else 147 struct tagMSG; 148 #endif 149 150 151 namespace FX { 152 153 154 // FOX System Defined Selector Types 155 enum FXSelType { 156 SEL_NONE, 157 SEL_KEYPRESS, /// Key pressed 158 SEL_KEYRELEASE, /// Key released 159 SEL_LEFTBUTTONPRESS, /// Left mouse button pressed 160 SEL_LEFTBUTTONRELEASE, /// Left mouse button released 161 SEL_MIDDLEBUTTONPRESS, /// Middle mouse button pressed 162 SEL_MIDDLEBUTTONRELEASE, /// Middle mouse button released 163 SEL_RIGHTBUTTONPRESS, /// Right mouse button pressed 164 SEL_RIGHTBUTTONRELEASE, /// Right mouse button released 165 SEL_MOTION, /// Mouse motion 166 SEL_ENTER, /// Mouse entered window 167 SEL_LEAVE, /// Mouse left window 168 SEL_FOCUSIN, /// Focus into window 169 SEL_FOCUSOUT, /// Focus out of window 170 SEL_KEYMAP, 171 SEL_UNGRABBED, /// Lost the grab (Windows) 172 SEL_PAINT, /// Must repaint window 173 SEL_CREATE, 174 SEL_DESTROY, 175 SEL_UNMAP, /// Window was hidden 176 SEL_MAP, /// Window was shown 177 SEL_CONFIGURE, /// Resize 178 SEL_SELECTION_LOST, /// Widget lost selection 179 SEL_SELECTION_GAINED, /// Widget gained selection 180 SEL_SELECTION_REQUEST, /// Inquire selection data 181 SEL_RAISED, /// Window to top of stack 182 SEL_LOWERED, /// Window to bottom of stack 183 SEL_CLOSE, /// Close window 184 SEL_DELETE, /// Delete window 185 SEL_MINIMIZE, /// Iconified 186 SEL_RESTORE, /// No longer iconified or maximized 187 SEL_MAXIMIZE, /// Maximized 188 SEL_UPDATE, /// GUI update 189 SEL_COMMAND, /// GUI command 190 SEL_CLICKED, /// Clicked 191 SEL_DOUBLECLICKED, /// Double-clicked 192 SEL_TRIPLECLICKED, /// Triple-clicked 193 SEL_MOUSEWHEEL, /// Mouse wheel 194 SEL_CHANGED, /// GUI has changed 195 SEL_VERIFY, /// Verify change 196 SEL_DESELECTED, /// Deselected 197 SEL_SELECTED, /// Selected 198 SEL_INSERTED, /// Inserted 199 SEL_REPLACED, /// Replaced 200 SEL_DELETED, /// Deleted 201 SEL_OPENED, /// Opened 202 SEL_CLOSED, /// Closed 203 SEL_EXPANDED, /// Expanded 204 SEL_COLLAPSED, /// Collapsed 205 SEL_BEGINDRAG, /// Start a drag 206 SEL_ENDDRAG, /// End a drag 207 SEL_DRAGGED, /// Dragged 208 SEL_LASSOED, /// Lassoed 209 SEL_TIMEOUT, /// Timeout occurred 210 SEL_SIGNAL, /// Signal received 211 SEL_CLIPBOARD_LOST, /// Widget lost clipboard 212 SEL_CLIPBOARD_GAINED, /// Widget gained clipboard 213 SEL_CLIPBOARD_REQUEST, /// Inquire clipboard data 214 SEL_CHORE, /// Background chore 215 SEL_FOCUS_SELF, /// Focus on widget itself 216 SEL_FOCUS_RIGHT, /// Focus moved right 217 SEL_FOCUS_LEFT, /// Focus moved left 218 SEL_FOCUS_DOWN, /// Focus moved down 219 SEL_FOCUS_UP, /// Focus moved up 220 SEL_FOCUS_NEXT, /// Focus moved to next widget 221 SEL_FOCUS_PREV, /// Focus moved to previous widget 222 SEL_DND_ENTER, /// Drag action entering potential drop target 223 SEL_DND_LEAVE, /// Drag action leaving potential drop target 224 SEL_DND_DROP, /// Drop on drop target 225 SEL_DND_MOTION, /// Drag position changed over potential drop target 226 SEL_DND_REQUEST, /// Inquire drag and drop data 227 SEL_IO_READ, /// Read activity on a pipe 228 SEL_IO_WRITE, /// Write activity on a pipe 229 SEL_IO_EXCEPT, /// Except activity on a pipe 230 SEL_PICKED, /// Picked some location 231 SEL_QUERY_TIP, /// Message inquiring about tooltip 232 SEL_QUERY_HELP, /// Message inquiring about statusline help 233 SEL_DOCKED, /// Toolbar docked 234 SEL_FLOATED, /// Toolbar floated 235 SEL_SESSION_NOTIFY, /// Session is about to close 236 SEL_SESSION_CLOSED, /// Session is closed 237 SEL_LAST 238 }; 239 240 241 /// FOX Keyboard and Button states 242 enum { 243 SHIFTMASK = 0x001, /// Shift key is down 244 CAPSLOCKMASK = 0x002, /// Caps Lock key is down 245 CONTROLMASK = 0x004, /// Ctrl key is down 246 #ifdef __APPLE__ 247 ALTMASK = 0x2000, /// Alt key is down 248 METAMASK = 0x10, /// Meta key is down 249 #else 250 ALTMASK = 0x008, /// Alt key is down 251 METAMASK = 0x040, /// Meta key is down 252 #endif 253 NUMLOCKMASK = 0x010, /// Num Lock key is down 254 SCROLLLOCKMASK = 0x0E0, /// Scroll Lock key is down (seems to vary) 255 LEFTBUTTONMASK = 0x100, /// Left mouse button is down 256 MIDDLEBUTTONMASK = 0x200, /// Middle mouse button is down 257 RIGHTBUTTONMASK = 0x400 /// Right mouse button is down 258 }; 259 260 261 /// FOX Mouse buttons 262 enum { 263 LEFTBUTTON = 1, 264 MIDDLEBUTTON = 2, 265 RIGHTBUTTON = 3 266 }; 267 268 269 /// FOX window crossing modes 270 enum { 271 CROSSINGNORMAL, /// Normal crossing event 272 CROSSINGGRAB, /// Crossing due to mouse grab 273 CROSSINGUNGRAB /// Crossing due to mouse ungrab 274 }; 275 276 277 /// FOX window visibility modes 278 enum { 279 VISIBILITYTOTAL, 280 VISIBILITYPARTIAL, 281 VISIBILITYNONE 282 }; 283 284 285 /// Options for fxfilematch 286 enum { 287 FILEMATCH_FILE_NAME = 1, /// No wildcard can ever match `/' 288 FILEMATCH_NOESCAPE = 2, /// Backslashes don't quote special chars 289 FILEMATCH_PERIOD = 4, /// Leading `.' is matched only explicitly 290 FILEMATCH_LEADING_DIR = 8, /// Ignore `/...' after a match 291 FILEMATCH_CASEFOLD = 16 /// Compare without regard to case 292 }; 293 294 295 /// Drag and drop actions 296 enum FXDragAction { 297 DRAG_REJECT = 0, /// Reject all drop actions 298 DRAG_ACCEPT = 1, /// Accept any drop action 299 DRAG_COPY = 2, /// Copy 300 DRAG_MOVE = 3, /// Move 301 DRAG_LINK = 4, /// Link 302 DRAG_PRIVATE = 5 /// Private 303 }; 304 305 306 /// Origin of data 307 enum FXDNDOrigin { 308 FROM_SELECTION = 0, /// Primary selection 309 FROM_CLIPBOARD = 1, /// Clipboard 310 FROM_DRAGNDROP = 2 /// Drag and drop source 311 }; 312 313 314 /// Exponent display 315 enum FXExponent { 316 EXP_NEVER=FALSE, /// Never use exponential notation 317 EXP_ALWAYS=TRUE, /// Always use exponential notation 318 EXP_AUTO=MAYBE /// Use exponential notation if needed 319 }; 320 321 322 /// Search modes for search/replace dialogs 323 enum { 324 SEARCH_FORWARD = 0, /// Search forward (default) 325 SEARCH_BACKWARD = 1, /// Search backward 326 SEARCH_NOWRAP = 0, /// Don't wrap (default) 327 SEARCH_WRAP = 2, /// Wrap around to start 328 SEARCH_EXACT = 0, /// Exact match (default) 329 SEARCH_IGNORECASE = 4, /// Ignore case 330 SEARCH_REGEX = 8, /// Regular expression match 331 SEARCH_PREFIX = 16 /// Prefix of subject string 332 }; 333 334 335 /********************************* Typedefs **********************************/ 336 337 // Forward declarations 338 class FXObject; 339 class FXStream; 340 class FXString; 341 342 343 // Streamable types; these are fixed size! 344 typedef char FXchar; 345 typedef unsigned char FXuchar; 346 typedef FXuchar FXbool; 347 typedef unsigned short FXushort; 348 typedef short FXshort; 349 typedef unsigned int FXuint; 350 typedef int FXint; 351 typedef float FXfloat; 352 typedef double FXdouble; 353 typedef FXObject *FXObjectPtr; 354 #ifdef WIN32 355 typedef unsigned int FXwchar; 356 #if defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED) 357 typedef unsigned short FXnchar; 358 #elif defined(__WATCOM_INT64__) 359 typedef long char FXnchar; 360 #else 361 typedef wchar_t FXnchar; 362 #endif 363 #else 364 typedef wchar_t FXwchar; 365 typedef unsigned short FXnchar; 366 #endif 367 #if defined(__LP64__) || defined(_LP64) || (_MIPS_SZLONG == 64) || (__WORDSIZE == 64) 368 typedef unsigned long FXulong; 369 typedef long FXlong; 370 #elif defined(_MSC_VER) || (defined(__BCPLUSPLUS__) && __BORLANDC__ > 0x500) || defined(__WATCOM_INT64__) 371 typedef unsigned __int64 FXulong; 372 typedef __int64 FXlong; 373 #elif defined(__GNUG__) || defined(__GNUC__) || defined(__SUNPRO_CC) || defined(__MWERKS__) || defined(__SC__) || defined(_LONGLONG) 374 typedef unsigned long long FXulong; 375 typedef long long FXlong; 376 #else 377 #error "FXlong and FXulong not defined for this architecture!" 378 #endif 379 380 // Integral types large enough to hold value of a pointer 381 #if defined(_MSC_VER) && defined(_WIN64) 382 typedef __int64 FXival; 383 typedef unsigned __int64 FXuval; 384 #elif defined(__GNUC__) && defined(_WIN64) 385 typedef long long FXival; 386 typedef unsigned long long FXuval; 387 #else 388 typedef long FXival; 389 typedef unsigned long FXuval; 390 #endif 391 392 393 // Handle to something in server 394 #ifndef WIN32 395 typedef unsigned long FXID; 396 #else 397 typedef void* FXID; 398 #endif 399 400 // Time since January 1, 1970 (UTC) 401 typedef long FXTime; 402 403 // Pixel type (could be color index) 404 typedef unsigned long FXPixel; 405 406 // RGBA pixel value 407 typedef FXuint FXColor; 408 409 // Hot key 410 typedef FXuint FXHotKey; 411 412 // Drag type 413 #ifndef WIN32 414 typedef FXID FXDragType; 415 #else 416 typedef FXushort FXDragType; 417 #endif 418 419 // Input source handle type 420 #ifndef WIN32 421 typedef FXint FXInputHandle; 422 #else 423 typedef void* FXInputHandle; 424 #endif 425 426 // Raw event type 427 #ifndef WIN32 428 typedef _XEvent FXRawEvent; 429 #else 430 typedef tagMSG FXRawEvent; 431 #endif 432 433 434 /********************************** Macros ***********************************/ 435 436 437 /// Abolute value 438 #define FXABS(val) (((val)>=0)?(val):-(val)) 439 440 /// Return the maximum of a or b 441 #define FXMAX(a,b) (((a)>(b))?(a):(b)) 442 443 /// Return the minimum of a or b 444 #define FXMIN(a,b) (((a)>(b))?(b):(a)) 445 446 /// Return the minimum of x, y and z 447 #define FXMIN3(x,y,z) ((x)<(y)?FXMIN(x,z):FXMIN(y,z)) 448 449 /// Return the maximum of x, y and z 450 #define FXMAX3(x,y,z) ((x)>(y)?FXMAX(x,z):FXMAX(y,z)) 451 452 /// Return the minimum of x, y, z, and w 453 #define FXMIN4(x,y,z,w) (FXMIN(FXMIN(x,y),FXMIN(z,w))) 454 455 /// Return the maximum of of x, y, z, and w 456 #define FXMAX4(x,y,z,w) (FXMAX(FXMAX(x,y),FXMAX(z,w))) 457 458 /// Return minimum and maximum of a, b 459 #define FXMINMAX(lo,hi,a,b) ((a)<(b)?((lo)=(a),(hi)=(b)):((lo)=(b),(hi)=(a))) 460 461 /// Clamp value x to range [lo..hi] 462 #define FXCLAMP(lo,x,hi) ((x)<(lo)?(lo):((x)>(hi)?(hi):(x))) 463 464 /// Swap a pair of numbers 465 #define FXSWAP(a,b,t) ((t)=(a),(a)=(b),(b)=(t)) 466 467 /// Linear interpolation between a and b, where 0<=f<=1 468 #define FXLERP(a,b,f) ((a)+((b)-(a))*(f)) 469 470 /// Offset of member in a structure 471 #define STRUCTOFFSET(str,member) (((char *)(&(((str *)0)->member)))-((char *)0)) 472 473 /// Number of elements in a static array 474 #define ARRAYNUMBER(array) (sizeof(array)/sizeof(array[0])) 475 476 /// Container class of a member class 477 #define CONTAINER(ptr,str,mem) ((str*)(((char*)(ptr))-STRUCTOFFSET(str,mem))) 478 479 /// Make int out of two shorts 480 #define MKUINT(l,h) ((((FX::FXuint)(l))&0xffff) | (((FX::FXuint)(h))<<16)) 481 482 /// Make selector from message type and message id 483 #define FXSEL(type,id) ((((FX::FXuint)(id))&0xffff) | (((FX::FXuint)(type))<<16)) 484 485 /// Get type from selector 486 #define FXSELTYPE(s) ((FX::FXushort)(((s)>>16)&0xffff)) 487 488 /// Get ID from selector 489 #define FXSELID(s) ((FX::FXushort)((s)&0xffff)) 490 491 /// Reverse bits in byte 492 #define FXBITREVERSE(b) (((b&0x01)<<7)|((b&0x02)<<5)|((b&0x04)<<3)|((b&0x08)<<1)|((b&0x10)>>1)|((b&0x20)>>3)|((b&0x40)>>5)|((b&0x80)>>7)) 493 494 /// Test if character c is at the start of a utf8 sequence 495 #define FXISUTF(c) (((c)&0xC0)!=0x80) 496 497 498 // Definitions for big-endian machines 499 #if FOX_BIGENDIAN == 1 500 501 /// Make RGBA color 502 #define FXRGBA(r,g,b,a) (((FX::FXuint)(FX::FXuchar)(r)<<24) | ((FX::FXuint)(FX::FXuchar)(g)<<16) | ((FX::FXuint)(FX::FXuchar)(b)<<8) | ((FX::FXuint)(FX::FXuchar)(a))) 503 504 /// Make RGB color 505 #define FXRGB(r,g,b) (((FX::FXuint)(FX::FXuchar)(r)<<24) | ((FX::FXuint)(FX::FXuchar)(g)<<16) | ((FX::FXuint)(FX::FXuchar)(b)<<8) | 0x000000ff) 506 507 /// Get red value from RGBA color 508 #define FXREDVAL(rgba) ((FX::FXuchar)(((rgba)>>24)&0xff)) 509 510 /// Get green value from RGBA color 511 #define FXGREENVAL(rgba) ((FX::FXuchar)(((rgba)>>16)&0xff)) 512 513 /// Get blue value from RGBA color 514 #define FXBLUEVAL(rgba) ((FX::FXuchar)(((rgba)>>8)&0xff)) 515 516 /// Get alpha value from RGBA color 517 #define FXALPHAVAL(rgba) ((FX::FXuchar)((rgba)&0xff)) 518 519 /// Get component value of RGBA color 520 #define FXRGBACOMPVAL(rgba,comp) ((FX::FXuchar)(((rgba)>>((3-(comp))<<3))&0xff)) 521 522 #endif 523 524 525 // Definitions for little-endian machines 526 #if FOX_BIGENDIAN == 0 527 528 /// Make RGBA color 529 #define FXRGBA(r,g,b,a) (((FX::FXuint)(FX::FXuchar)(r)) | ((FX::FXuint)(FX::FXuchar)(g)<<8) | ((FX::FXuint)(FX::FXuchar)(b)<<16) | ((FX::FXuint)(FX::FXuchar)(a)<<24)) 530 531 /// Make RGB color 532 #define FXRGB(r,g,b) (((FX::FXuint)(FX::FXuchar)(r)) | ((FX::FXuint)(FX::FXuchar)(g)<<8) | ((FX::FXuint)(FX::FXuchar)(b)<<16) | 0xff000000) 533 534 /// Get red value from RGBA color 535 #define FXREDVAL(rgba) ((FX::FXuchar)((rgba)&0xff)) 536 537 /// Get green value from RGBA color 538 #define FXGREENVAL(rgba) ((FX::FXuchar)(((rgba)>>8)&0xff)) 539 540 /// Get blue value from RGBA color 541 #define FXBLUEVAL(rgba) ((FX::FXuchar)(((rgba)>>16)&0xff)) 542 543 /// Get alpha value from RGBA color 544 #define FXALPHAVAL(rgba) ((FX::FXuchar)(((rgba)>>24)&0xff)) 545 546 /// Get component value of RGBA color 547 #define FXRGBACOMPVAL(rgba,comp) ((FX::FXuchar)(((rgba)>>((comp)<<3))&0xff)) 548 549 #endif 550 551 552 /** 553 * FXASSERT() prints out a message when the expression fails, 554 * and nothing otherwise. Unlike assert(), FXASSERT() will not 555 * terminate the execution of the application. 556 * When compiling your application for release, all assertions 557 * are compiled out; thus there is no impact on execution speed. 558 */ 559 #ifndef NDEBUG 560 #define FXASSERT(exp) ((exp)?((void)0):(void)FX::fxassert(#exp,__FILE__,__LINE__)) 561 #else 562 #define FXASSERT(exp) ((void)0) 563 #endif 564 565 566 /** 567 * FXTRACE() allows you to trace the execution of your application 568 * with increasing levels of detail the higher the trace level. 569 * The trace level is determined by variable fxTraceLevel, which 570 * may be set from the command line with "-tracelevel <level>". 571 * When compiling your application for release, all trace statements 572 * are compiled out, just like FXASSERT. 573 * A statement like: FXTRACE((10,"The value of x=%d\n",x)) will 574 * generate output only if fxTraceLevel is set to 11 or greater. 575 * The default value fxTraceLevel=0 will block all trace outputs. 576 * Note the double parentheses! 577 */ 578 #ifndef NDEBUG 579 #define FXTRACE(arguments) FX::fxtrace arguments 580 #else 581 #define FXTRACE(arguments) ((void)0) 582 #endif 583 584 585 /** 586 * Allocate a memory block of no elements of type and store a pointer 587 * to it into the address pointed to by ptr. 588 * Return FALSE if size!=0 and allocation fails, TRUE otherwise. 589 * An allocation of a zero size block returns a NULL pointer. 590 */ 591 #define FXMALLOC(ptr,type,no) (FX::fxmalloc((void **)(ptr),sizeof(type)*(no))) 592 593 /** 594 * Allocate a zero-filled memory block no elements of type and store a pointer 595 * to it into the address pointed to by ptr. 596 * Return FALSE if size!=0 and allocation fails, TRUE otherwise. 597 * An allocation of a zero size block returns a NULL pointer. 598 */ 599 #define FXCALLOC(ptr,type,no) (FX::fxcalloc((void **)(ptr),sizeof(type)*(no))) 600 601 /** 602 * Resize the memory block referred to by the pointer at the address ptr, to a 603 * hold no elements of type. 604 * Returns FALSE if size!=0 and reallocation fails, TRUE otherwise. 605 * If reallocation fails, pointer is left to point to old block; a reallocation 606 * to a zero size block has the effect of freeing it. 607 * The ptr argument must be the address where the pointer to the allocated 608 * block is to be stored. 609 */ 610 #define FXRESIZE(ptr,type,no) (FX::fxresize((void **)(ptr),sizeof(type)*(no))) 611 612 /** 613 * Allocate and initialize memory from another block. 614 * Return FALSE if size!=0 and source!=NULL and allocation fails, TRUE otherwise. 615 * An allocation of a zero size block returns a NULL pointer. 616 * The ptr argument must be the address where the pointer to the allocated 617 * block is to be stored. 618 */ 619 #define FXMEMDUP(ptr,src,type,no) (FX::fxmemdup((void **)(ptr),(const void*)(src),sizeof(type)*(no))) 620 621 /** 622 * Free a block of memory allocated with either FXMALLOC, FXCALLOC, FXRESIZE, or FXMEMDUP. 623 * It is OK to call free a NULL pointer. The argument must be the address of the 624 * pointer to the block to be released. The pointer is set to NULL to prevent 625 * any further references to the block after releasing it. 626 */ 627 #define FXFREE(ptr) (FX::fxfree((void **)(ptr))) 628 629 630 /** 631 * These are some of the ISO C99 standard single-precision transcendental functions. 632 * On LINUX, specify _GNU_SOURCE or _ISOC99_SOURCE to enable native implementation; 633 * otherwise, these macros will be used. Apple OS-X implements fabsf(x), ceilf(x), 634 * floorf(x), and fmodf(x,y). 635 * Define FLOAT_MATH_FUNCTIONS if these functions are available in some other 636 * library you're linking to. 637 */ 638 #ifdef __OpenBSD__ 639 #define FLOAT_MATH_FUNCTIONS 640 #endif 641 #ifndef FLOAT_MATH_FUNCTIONS 642 #ifndef __USE_ISOC99 643 #ifndef __APPLE__ 644 #define fabsf(x) ((float)fabs((double)(x))) 645 #define ceilf(x) ((float)ceil((double)(x))) 646 #define floorf(x) ((float)floor((double)(x))) 647 #define fmodf(x,y) ((float)fmod((double)(x),(double)(y))) 648 #endif 649 #define sqrtf(x) ((float)sqrt((double)(x))) 650 #define sinf(x) ((float)sin((double)(x))) 651 #define cosf(x) ((float)cos((double)(x))) 652 #define tanf(x) ((float)tan((double)(x))) 653 #define asinf(x) ((float)asin((double)(x))) 654 #define acosf(x) ((float)acos((double)(x))) 655 #define atanf(x) ((float)atan((double)(x))) 656 #define atan2f(y,x) ((float)atan2((double)(y),(double)(x))) 657 #define powf(x,y) ((float)pow((double)(x),(double)(y))) 658 #define expf(x) ((float)exp((double)(x))) 659 #define logf(x) ((float)log((double)(x))) 660 #define log10f(x) ((float)log10((double)(x))) 661 #endif 662 #endif 663 664 665 /********************************** Globals **********************************/ 666 667 /// Simple, thread-safe, random number generator 668 extern FXAPI FXuint fxrandom(FXuint& seed); 669 670 /// Allocate memory 671 extern FXAPI FXint fxmalloc(void** ptr,unsigned long size); 672 673 /// Allocate cleaned memory 674 extern FXAPI FXint fxcalloc(void** ptr,unsigned long size); 675 676 /// Resize memory 677 extern FXAPI FXint fxresize(void** ptr,unsigned long size); 678 679 /// Duplicate memory 680 extern FXAPI FXint fxmemdup(void** ptr,const void* src,unsigned long size); 681 682 /// Free memory, resets ptr to NULL afterward 683 extern FXAPI void fxfree(void** ptr); 684 685 /// Error routine 686 extern FXAPI void fxerror(const char* format,...) FX_PRINTF(1,2) ; 687 688 /// Warning routine 689 extern FXAPI void fxwarning(const char* format,...) FX_PRINTF(1,2) ; 690 691 /// Log message to [typically] stderr 692 extern FXAPI void fxmessage(const char* format,...) FX_PRINTF(1,2) ; 693 694 /// Assert failed routine:- usually not called directly but called through FXASSERT 695 extern FXAPI void fxassert(const char* expression,const char* filename,unsigned int lineno); 696 697 /// Trace printout routine:- usually not called directly but called through FXTRACE 698 extern FXAPI void fxtrace(unsigned int level,const char* format,...) FX_PRINTF(2,3) ; 699 700 /// Sleep n microseconds 701 extern FXAPI void fxsleep(unsigned int n); 702 703 /// Match a file name with a pattern 704 extern FXAPI bool fxfilematch(const char *pattern,const char *string,FXuint flags=(FILEMATCH_NOESCAPE|FILEMATCH_FILE_NAME)); 705 706 /// Get highlight color 707 extern FXAPI FXColor makeHiliteColor(FXColor clr); 708 709 /// Get shadow color 710 extern FXAPI FXColor makeShadowColor(FXColor clr); 711 712 /// Get process id 713 extern FXAPI FXint fxgetpid(); 714 715 /// Convert string of length len to MSDOS; return new string and new length 716 extern FXAPI bool fxtoDOS(FXchar*& string,FXint& len); 717 718 /// Convert string of length len from MSDOS; return new string and new length 719 extern FXAPI bool fxfromDOS(FXchar*& string,FXint& len); 720 721 /// Duplicate string 722 extern FXAPI FXchar *fxstrdup(const FXchar* str); 723 724 /// Calculate a hash value from a string 725 extern FXAPI FXuint fxstrhash(const FXchar* str); 726 727 /// Get RGB value from color name 728 extern FXAPI FXColor fxcolorfromname(const FXchar* colorname); 729 730 /// Get name of (closest) color to RGB 731 extern FXAPI FXchar* fxnamefromcolor(FXchar *colorname,FXColor color); 732 733 /// Convert RGB to HSV 734 extern FXAPI void fxrgb_to_hsv(FXfloat& h,FXfloat& s,FXfloat& v,FXfloat r,FXfloat g,FXfloat b); 735 736 /// Convert HSV to RGB 737 extern FXAPI void fxhsv_to_rgb(FXfloat& r,FXfloat& g,FXfloat& b,FXfloat h,FXfloat s,FXfloat v); 738 739 /// Floating point number classification: 0=OK, +/-1=Inf, +/-2=NaN 740 extern FXAPI FXint fxieeefloatclass(FXfloat number); 741 extern FXAPI FXint fxieeedoubleclass(FXdouble number); 742 743 /// Convert keysym to unicode character 744 extern FXAPI FXwchar fxkeysym2ucs(FXwchar sym); 745 746 /// Convert unicode character to keysym 747 extern FXAPI FXwchar fxucs2keysym(FXwchar ucs); 748 749 /// Parse geometry, a-la X11 geometry specification 750 extern FXAPI FXint fxparsegeometry(const FXchar *string,FXint& x,FXint& y,FXint& w,FXint& h); 751 752 /// True if executable with given path is a console application 753 extern FXAPI FXbool fxisconsole(const FXchar *path); 754 755 /// Version number that the library has been compiled with 756 extern FXAPI const FXuchar fxversion[3]; 757 758 /// Controls tracing level 759 extern FXAPI unsigned int fxTraceLevel; 760 761 /// Return wide character from utf8 string at ptr 762 extern FXAPI FXwchar wc(const FXchar *ptr); 763 764 /// Return wide character from utf16 string at ptr 765 extern FXAPI FXwchar wc(const FXnchar *ptr); 766 767 /// Return number of FXchar's of wide character at ptr 768 extern FXAPI FXint wclen(const FXchar *ptr); 769 770 /// Return number of FXnchar's of narrow character at ptr 771 extern FXAPI FXint wclen(const FXnchar *ptr); 772 773 /// Return start of utf8 character containing position 774 extern FXAPI FXint wcvalidate(const FXchar* string,FXint pos); 775 776 /// Return start of utf16 character containing position 777 extern FXAPI FXint wcvalidate(const FXnchar *string,FXint pos); 778 779 /// Advance to next utf8 character start 780 extern FXAPI FXint wcinc(const FXchar* string,FXint pos); 781 782 /// Advance to next utf16 character start 783 extern FXAPI FXint wcinc(const FXnchar *string,FXint pos); 784 785 /// Retreat to previous utf8 character start 786 extern FXAPI FXint wcdec(const FXchar* string,FXint pos); 787 788 /// Retreat to previous utf16 character start 789 extern FXAPI FXint wcdec(const FXnchar *string,FXint pos); 790 791 /// Length of utf8 representation of wide characters string str of length n 792 extern FXAPI FXint utfslen(const FXwchar *str,FXint n); 793 794 /// Length of utf8 representation of wide character string str 795 extern FXAPI FXint utfslen(const FXwchar *str); 796 797 /// Length of utf8 representation of narrow characters string str of length n 798 extern FXAPI FXint utfslen(const FXnchar *str,FXint n); 799 800 /// Length of utf8 representation of narrow characters string str 801 extern FXAPI FXint utfslen(const FXnchar *str); 802 803 /// Length of wide character representation of utf8 string str of length n 804 extern FXAPI FXint wcslen(const FXchar *str,FXint n); 805 806 /// Length of wide character representation of utf8 string str 807 extern FXAPI FXint wcslen(const FXchar *str); 808 809 /// Length of narrow character representation of utf8 string str of length n 810 extern FXAPI FXint ncslen(const FXchar *str,FXint n); 811 812 /// Length of narrow character representation of utf8 string str 813 extern FXAPI FXint ncslen(const FXchar *str); 814 815 /// Copy utf8 string of length n to wide character string dst 816 extern FXAPI FXint utf2wcs(FXwchar *dst,const FXchar *src,FXint n); 817 818 /// Copy utf8 string to wide character string dst 819 extern FXAPI FXint utf2wcs(FXwchar *dst,const FXchar *src); 820 821 /// Copy utf8 string of length n to narrow character string dst 822 extern FXAPI FXint utf2ncs(FXnchar *dst,const FXchar *src,FXint n); 823 824 /// Copy utf8 string to narrow character string dst 825 extern FXAPI FXint utf2ncs(FXnchar *dst,const FXchar *src); 826 827 /// Copy wide character substring of length n to dst 828 extern FXAPI FXint wc2utfs(FXchar* dst,const FXwchar *src,FXint n); 829 830 /// Copy wide character string to dst 831 extern FXAPI FXint wc2utfs(FXchar* dst,const FXwchar *src); 832 833 /// Copy narrow character substring of length n to dst 834 extern FXAPI FXint nc2utfs(FXchar* dst,const FXnchar *src,FXint n); 835 836 /// Copy narrow character string to dst 837 extern FXAPI FXint nc2utfs(FXchar* dst,const FXnchar *src); 838 839 840 } 841 842 #endif 843