Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

fxdefs.h

00001 /******************************************************************************** 00002 * * 00003 * FOX Definitions, Types, and Macros * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 1997,2005 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 00021 ********************************************************************************* 00022 * $Id: fxdefs.h,v 1.145 2005/01/16 16:06:06 fox Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXDEFS_H 00025 #define FXDEFS_H 00026 00027 00028 /******************************** Definitions ********************************/ 00029 00030 // Truth values 00031 #ifndef TRUE 00032 #define TRUE 1 00033 #endif 00034 #ifndef FALSE 00035 #define FALSE 0 00036 #endif 00037 #ifndef MAYBE 00038 #define MAYBE 2 00039 #endif 00040 #ifndef NULL 00041 #define NULL 0 00042 #endif 00043 00044 /// Pi 00045 #ifndef PI 00046 #define PI 3.1415926535897932384626433833 00047 #endif 00048 00049 /// Euler constant 00050 #define EULER 2.7182818284590452353602874713 00051 00052 /// Multiplier for degrees to radians 00053 #define DTOR 0.0174532925199432957692369077 00054 00055 /// Multiplier for radians to degrees 00056 #define RTOD 57.295779513082320876798154814 00057 00058 00059 // Path separator 00060 #ifdef WIN32 00061 #define PATHSEP '\\' 00062 #define PATHSEPSTRING "\\" 00063 #define PATHLISTSEP ';' 00064 #define PATHLISTSEPSTRING ";" 00065 #define ISPATHSEP(c) ((c)=='/' || (c)=='\\') 00066 #else 00067 #define PATHSEP '/' 00068 #define PATHSEPSTRING "/" 00069 #define PATHLISTSEP ':' 00070 #define PATHLISTSEPSTRING ":" 00071 #define ISPATHSEP(c) ((c)=='/') 00072 #endif 00073 00074 00075 // End Of Line 00076 #ifdef WIN32 00077 #define EOLSTRING "\r\n" 00078 #else 00079 #define EOLSTRING "\n" 00080 #endif 00081 00082 00083 // For Windows 00084 #ifdef _DEBUG 00085 #ifndef DEBUG 00086 #define DEBUG 00087 #endif 00088 #endif 00089 #ifdef _NDEBUG 00090 #ifndef NDEBUG 00091 #define NDEBUG 00092 #endif 00093 #endif 00094 00095 00096 // Shared library support 00097 #ifdef WIN32 00098 #define FXEXPORT __declspec(dllexport) 00099 #define FXIMPORT __declspec(dllimport) 00100 #else 00101 #define FXEXPORT 00102 #define FXIMPORT 00103 #endif 00104 00105 // Define FXAPI for DLL builds 00106 #ifdef FOXDLL 00107 #ifdef FOXDLL_EXPORTS 00108 #define FXAPI FXEXPORT 00109 #else 00110 #define FXAPI FXIMPORT 00111 #endif 00112 #else 00113 #define FXAPI 00114 #endif 00115 00116 // Callback 00117 #ifdef WIN32 00118 #ifndef CALLBACK 00119 #define CALLBACK __stdcall 00120 #endif 00121 #endif 00122 00123 00124 // Checking printf and scanf format strings 00125 #if defined(_CC_GNU_) || defined(__GNUG__) || defined(__GNUC__) 00126 #define FX_PRINTF(fmt,arg) __attribute__((format(printf,fmt,arg))) 00127 #define FX_SCANF(fmt,arg) __attribute__((format(scanf,fmt,arg))) 00128 #else 00129 #define FX_PRINTF(fmt,arg) 00130 #define FX_SCANF(fmt,arg) 00131 #endif 00132 00133 // Raw event type 00134 #ifndef WIN32 00135 union _XEvent; 00136 #else 00137 struct tagMSG; 00138 #endif 00139 00140 00141 namespace FX { 00142 00143 00144 // FOX System Defined Selector Types 00145 enum FXSelType { 00146 SEL_NONE, 00147 SEL_KEYPRESS, /// Key pressed 00148 SEL_KEYRELEASE, /// Key released 00149 SEL_LEFTBUTTONPRESS, /// Left mouse button pressed 00150 SEL_LEFTBUTTONRELEASE, /// Left mouse button released 00151 SEL_MIDDLEBUTTONPRESS, /// Middle mouse button pressed 00152 SEL_MIDDLEBUTTONRELEASE, /// Middle mouse button released 00153 SEL_RIGHTBUTTONPRESS, /// Right mouse button pressed 00154 SEL_RIGHTBUTTONRELEASE, /// Right mouse button released 00155 SEL_MOTION, /// Mouse motion 00156 SEL_ENTER, /// Mouse entered window 00157 SEL_LEAVE, /// Mouse left window 00158 SEL_FOCUSIN, /// Focus into window 00159 SEL_FOCUSOUT, /// Focus out of window 00160 SEL_KEYMAP, 00161 SEL_UNGRABBED, /// Lost the grab (Windows) 00162 SEL_PAINT, /// Must repaint window 00163 SEL_CREATE, 00164 SEL_DESTROY, 00165 SEL_UNMAP, 00166 SEL_MAP, 00167 SEL_CONFIGURE, // Resize 00168 SEL_SELECTION_LOST, // Widget lost selection 00169 SEL_SELECTION_GAINED, // Widget gained selection 00170 SEL_SELECTION_REQUEST, // Inquire selection data 00171 SEL_RAISED, // Window to top of stack 00172 SEL_LOWERED, // Window to bottom of stack 00173 SEL_CLOSE, // Close window 00174 SEL_DELETE, // Delete window 00175 SEL_MINIMIZE, // Iconified 00176 SEL_RESTORE, // No longer iconified or maximized 00177 SEL_MAXIMIZE, // Maximized 00178 SEL_UPDATE, // GUI update 00179 SEL_COMMAND, // GUI command 00180 SEL_CLICKED, // Clicked 00181 SEL_DOUBLECLICKED, // Double-clicked 00182 SEL_TRIPLECLICKED, // Triple-clicked 00183 SEL_MOUSEWHEEL, // Mouse wheel 00184 SEL_CHANGED, // GUI has changed 00185 SEL_VERIFY, // Verify change 00186 SEL_DESELECTED, // Deselected 00187 SEL_SELECTED, // Selected 00188 SEL_INSERTED, // Inserted 00189 SEL_REPLACED, // Replaced 00190 SEL_DELETED, // Deleted 00191 SEL_OPENED, // Opened 00192 SEL_CLOSED, // Closed 00193 SEL_EXPANDED, // Expanded 00194 SEL_COLLAPSED, // Collapsed 00195 SEL_BEGINDRAG, // Start a drag 00196 SEL_ENDDRAG, // End a drag 00197 SEL_DRAGGED, // Dragged 00198 SEL_LASSOED, // Lassoed 00199 SEL_TIMEOUT, // Timeout occurred 00200 SEL_SIGNAL, // Signal received 00201 SEL_CLIPBOARD_LOST, // Widget lost clipboard 00202 SEL_CLIPBOARD_GAINED, // Widget gained clipboard 00203 SEL_CLIPBOARD_REQUEST, // Inquire clipboard data 00204 SEL_CHORE, // Background chore 00205 SEL_FOCUS_SELF, // Focus on widget itself 00206 SEL_FOCUS_RIGHT, // Focus movements 00207 SEL_FOCUS_LEFT, 00208 SEL_FOCUS_DOWN, 00209 SEL_FOCUS_UP, 00210 SEL_FOCUS_NEXT, 00211 SEL_FOCUS_PREV, 00212 SEL_DND_ENTER, // Drag action entering potential drop target 00213 SEL_DND_LEAVE, // Drag action leaving potential drop target 00214 SEL_DND_DROP, // Drop on drop target 00215 SEL_DND_MOTION, // Drag position changed over potential drop target 00216 SEL_DND_REQUEST, // Inquire drag and drop data 00217 SEL_IO_READ, // Read activity on a pipe 00218 SEL_IO_WRITE, // Write activity on a pipe 00219 SEL_IO_EXCEPT, // Except activity on a pipe 00220 SEL_PICKED, // Picked some location 00221 SEL_QUERY_TIP, // Message inquiring about tooltip 00222 SEL_QUERY_HELP, // Message inquiring about statusline help 00223 SEL_LAST // Last message 00224 }; 00225 00226 00227 /// FOX Keyboard and Button states 00228 enum { 00229 SHIFTMASK = 0x001, /// Shift key is down 00230 CAPSLOCKMASK = 0x002, /// Caps Lock key is down 00231 CONTROLMASK = 0x004, /// Ctrl key is down 00232 #ifdef __APPLE__ 00233 ALTMASK = 0x2000 /// Alt key is down 00234 METAMASK = 0x10, /// Meta key is down 00235 #else 00236 ALTMASK = 0x008, /// Alt key is down 00237 METAMASK = 0x040, /// Meta key is down 00238 #endif 00239 NUMLOCKMASK = 0x010, /// Num Lock key is down 00240 SCROLLLOCKMASK = 0x0E0, /// Scroll Lock key is down (seems to vary) 00241 LEFTBUTTONMASK = 0x100, /// Left mouse button is down 00242 MIDDLEBUTTONMASK = 0x200, /// Middle mouse button is down 00243 RIGHTBUTTONMASK = 0x400 /// Right mouse button is down 00244 }; 00245 00246 00247 /// FOX Mouse buttons 00248 enum { 00249 LEFTBUTTON = 1, 00250 MIDDLEBUTTON = 2, 00251 RIGHTBUTTON = 3 00252 }; 00253 00254 00255 /// FOX window crossing modes 00256 enum { 00257 CROSSINGNORMAL, /// Normal crossing event 00258 CROSSINGGRAB, /// Crossing due to mouse grab 00259 CROSSINGUNGRAB /// Crossing due to mouse ungrab 00260 }; 00261 00262 00263 /// FOX window visibility modes 00264 enum { 00265 VISIBILITYTOTAL, 00266 VISIBILITYPARTIAL, 00267 VISIBILITYNONE 00268 }; 00269 00270 00271 /// Options for fxfilematch 00272 enum { 00273 FILEMATCH_FILE_NAME = 1, /// No wildcard can ever match `/' 00274 FILEMATCH_NOESCAPE = 2, /// Backslashes don't quote special chars 00275 FILEMATCH_PERIOD = 4, /// Leading `.' is matched only explicitly 00276 FILEMATCH_LEADING_DIR = 8, /// Ignore `/...' after a match 00277 FILEMATCH_CASEFOLD = 16 /// Compare without regard to case 00278 }; 00279 00280 00281 /// Drag and drop actions 00282 enum FXDragAction { 00283 DRAG_REJECT = 0, /// Reject all drop actions 00284 DRAG_ACCEPT = 1, /// Accept any drop action 00285 DRAG_COPY = 2, /// Copy 00286 DRAG_MOVE = 3, /// Move 00287 DRAG_LINK = 4, /// Link 00288 DRAG_PRIVATE = 5 /// Private 00289 }; 00290 00291 00292 /// Origin of data 00293 enum FXDNDOrigin { 00294 FROM_SELECTION = 0, /// Primary selection 00295 FROM_CLIPBOARD = 1, /// Clipboard 00296 FROM_DRAGNDROP = 2 /// Drag and drop source 00297 }; 00298 00299 00300 /// Exponent display 00301 enum FXExponent { 00302 EXP_NEVER=FALSE, /// Never use exponential notation 00303 EXP_ALWAYS=TRUE, /// Always use exponential notation 00304 EXP_AUTO=MAYBE /// Use exponential notation if needed 00305 }; 00306 00307 00308 /// Search modes for search/replace dialogs 00309 enum { 00310 SEARCH_FORWARD = 0, /// Search forward (default) 00311 SEARCH_BACKWARD = 1, /// Search backward 00312 SEARCH_NOWRAP = 0, /// Don't wrap (default) 00313 SEARCH_WRAP = 2, /// Wrap around to start 00314 SEARCH_EXACT = 0, /// Exact match (default) 00315 SEARCH_IGNORECASE = 4, /// Ignore case 00316 SEARCH_REGEX = 8, /// Regular expression match 00317 SEARCH_PREFIX = 16 /// Prefix of subject string 00318 }; 00319 00320 00321 /********************************* Typedefs **********************************/ 00322 00323 // Forward declarations 00324 class FXObject; 00325 class FXStream; 00326 class FXString; 00327 00328 00329 // Streamable types; these are fixed size! 00330 typedef char FXchar; 00331 typedef unsigned char FXuchar; 00332 typedef FXuchar FXbool; 00333 typedef unsigned short FXushort; 00334 typedef short FXshort; 00335 typedef unsigned int FXuint; 00336 typedef unsigned int FXwchar; 00337 typedef int FXint; 00338 typedef float FXfloat; 00339 typedef double FXdouble; 00340 typedef FXObject *FXObjectPtr; 00341 #if defined(__LP64__) || defined(_LP64) || (_MIPS_SZLONG == 64) || (__WORDSIZE == 64) 00342 typedef unsigned long FXulong; 00343 typedef long FXlong; 00344 #elif defined(_MSC_VER) || (defined(__BCPLUSPLUS__) && __BORLANDC__ > 0x500) || defined(__WATCOM_INT64__) 00345 typedef unsigned __int64 FXulong; 00346 typedef __int64 FXlong; 00347 #elif defined(__GNUG__) || defined(__GNUC__) || defined(__SUNPRO_CC) || defined(__MWERKS__) || defined(__SC__) || defined(_LONGLONG) 00348 typedef unsigned long long FXulong; 00349 typedef long long FXlong; 00350 #else 00351 #error "FXlong and FXulong not defined for this architecture!" 00352 #endif 00353 00354 // Integral types large enough to hold value of a pointer 00355 #if defined(_MSC_VER) && defined(_WIN64) 00356 typedef __int64 FXival; 00357 typedef unsigned __int64 FXuval; 00358 #else 00359 typedef long FXival; 00360 typedef unsigned long FXuval; 00361 #endif 00362 00363 00364 // Handle to something in server 00365 #ifndef WIN32 00366 typedef unsigned long FXID; 00367 #else 00368 typedef void* FXID; 00369 #endif 00370 00371 // Time since January 1, 1970 (UTC) 00372 typedef long FXTime; 00373 00374 // Pixel type (could be color index) 00375 typedef unsigned long FXPixel; 00376 00377 // RGBA pixel value 00378 typedef FXuint FXColor; 00379 00380 // Hot key 00381 typedef FXuint FXHotKey; 00382 00383 // Drag type 00384 #ifndef WIN32 00385 typedef FXID FXDragType; 00386 #else 00387 typedef FXushort FXDragType; 00388 #endif 00389 00390 // Input source handle type 00391 #ifndef WIN32 00392 typedef FXint FXInputHandle; 00393 #else 00394 typedef void* FXInputHandle; 00395 #endif 00396 00397 // Raw event type 00398 #ifndef WIN32 00399 typedef _XEvent FXRawEvent; 00400 #else 00401 typedef tagMSG FXRawEvent; 00402 #endif 00403 00404 00405 /********************************** Macros ***********************************/ 00406 00407 00408 /// Abolute value 00409 #define FXABS(val) (((val)>=0)?(val):-(val)) 00410 00411 /// Return the maximum of a or b 00412 #define FXMAX(a,b) (((a)>(b))?(a):(b)) 00413 00414 /// Return the minimum of a or b 00415 #define FXMIN(a,b) (((a)>(b))?(b):(a)) 00416 00417 /// Return the minimum of x, y and z 00418 #define FXMIN3(x,y,z) ((x)<(y)?FXMIN(x,z):FXMIN(y,z)) 00419 00420 /// Return the maximum of x, y and z 00421 #define FXMAX3(x,y,z) ((x)>(y)?FXMAX(x,z):FXMAX(y,z)) 00422 00423 /// Return minimum and maximum of a, b 00424 #define FXMINMAX(lo,hi,a,b) ((a)<(b)?((lo)=(a),(hi)=(b)):((lo)=(b),(hi)=(a))) 00425 00426 /// Clamp value x to range [lo..hi] 00427 #define FXCLAMP(lo,x,hi) ((x)<(lo)?(lo):((x)>(hi)?(hi):(x))) 00428 00429 /// Swap a pair of numbers 00430 #define FXSWAP(a,b,t) ((t)=(a),(a)=(b),(b)=(t)) 00431 00432 /// Linear interpolation between a and b, where 0<=f<=1 00433 #define FXLERP(a,b,f) ((a)+((b)-(a))*(f)) 00434 00435 /// Offset of member in a structure 00436 #define STRUCTOFFSET(str,member) (((char *)(&(((str *)0)->member)))-((char *)0)) 00437 00438 /// Number of elements in a static array 00439 #define ARRAYNUMBER(array) (sizeof(array)/sizeof(array[0])) 00440 00441 /// Container class of a member class 00442 #define CONTAINER(ptr,str,mem) ((str*)(((char*)(ptr))-STRUCTOFFSET(str,mem))) 00443 00444 /// Make int out of two shorts 00445 #define MKUINT(l,h) ((((FX::FXuint)(l))&0xffff) | (((FX::FXuint)(h))<<16)) 00446 00447 /// Make selector from message type and message id 00448 #define FXSEL(type,id) ((((FX::FXuint)(id))&0xffff) | (((FX::FXuint)(type))<<16)) 00449 00450 /// Get type from selector 00451 #define FXSELTYPE(s) ((FX::FXushort)(((s)>>16)&0xffff)) 00452 00453 /// Get ID from selector 00454 #define FXSELID(s) ((FX::FXushort)((s)&0xffff)) 00455 00456 /// Reverse bits in byte 00457 #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)) 00458 00459 // The order in memory is [R G B A] matches that in FXColor 00460 00461 // Definitions for big-endian machines 00462 #if FOX_BIGENDIAN == 1 00463 00464 /// Make RGBA color 00465 #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))) 00466 00467 /// Make RGB color 00468 #define FXRGB(r,g,b) (((FX::FXuint)(FX::FXuchar)(r)<<24) | ((FX::FXuint)(FX::FXuchar)(g)<<16) | ((FX::FXuint)(FX::FXuchar)(b)<<8) | 0x000000ff) 00469 00470 /// Get red value from RGBA color 00471 #define FXREDVAL(rgba) ((FX::FXuchar)(((rgba)>>24)&0xff)) 00472 00473 /// Get green value from RGBA color 00474 #define FXGREENVAL(rgba) ((FX::FXuchar)(((rgba)>>16)&0xff)) 00475 00476 /// Get blue value from RGBA color 00477 #define FXBLUEVAL(rgba) ((FX::FXuchar)(((rgba)>>8)&0xff)) 00478 00479 /// Get alpha value from RGBA color 00480 #define FXALPHAVAL(rgba) ((FX::FXuchar)((rgba)&0xff)) 00481 00482 /// Get component value of RGBA color 00483 #define FXRGBACOMPVAL(rgba,comp) ((FX::FXuchar)(((rgba)>>((3-(comp))<<3))&0xff)) 00484 00485 #endif 00486 00487 // Definitions for little-endian machines 00488 #if FOX_BIGENDIAN == 0 00489 00490 /// Make RGBA color 00491 #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)) 00492 00493 /// Make RGB color 00494 #define FXRGB(r,g,b) (((FX::FXuint)(FX::FXuchar)(r)) | ((FX::FXuint)(FX::FXuchar)(g)<<8) | ((FX::FXuint)(FX::FXuchar)(b)<<16) | 0xff000000) 00495 00496 /// Get red value from RGBA color 00497 #define FXREDVAL(rgba) ((FX::FXuchar)((rgba)&0xff)) 00498 00499 /// Get green value from RGBA color 00500 #define FXGREENVAL(rgba) ((FX::FXuchar)(((rgba)>>8)&0xff)) 00501 00502 /// Get blue value from RGBA color 00503 #define FXBLUEVAL(rgba) ((FX::FXuchar)(((rgba)>>16)&0xff)) 00504 00505 /// Get alpha value from RGBA color 00506 #define FXALPHAVAL(rgba) ((FX::FXuchar)(((rgba)>>24)&0xff)) 00507 00508 /// Get component value of RGBA color 00509 #define FXRGBACOMPVAL(rgba,comp) ((FX::FXuchar)(((rgba)>>((comp)<<3))&0xff)) 00510 00511 #endif 00512 00513 00514 /** 00515 * FXASSERT() prints out a message when the expression fails, 00516 * and nothing otherwise. Unlike assert(), FXASSERT() will not 00517 * terminate the execution of the application. 00518 * When compiling your application for release, all assertions 00519 * are compiled out; thus there is no impact on execution speed. 00520 */ 00521 #ifndef NDEBUG 00522 #define FXASSERT(exp) ((exp)?((void)0):(void)FX::fxassert(#exp,__FILE__,__LINE__)) 00523 #else 00524 #define FXASSERT(exp) ((void)0) 00525 #endif 00526 00527 00528 /** 00529 * FXTRACE() allows you to trace the execution of your application 00530 * with increasing levels of detail the higher the trace level. 00531 * The trace level is determined by variable fxTraceLevel, which 00532 * may be set from the command line with "-tracelevel <level>". 00533 * When compiling your application for release, all trace statements 00534 * are compiled out, just like FXASSERT. 00535 * A statement like: FXTRACE((10,"The value of x=%d\n",x)) will 00536 * generate output only if fxTraceLevel is set to 11 or greater. 00537 * The default value fxTraceLevel=0 will block all trace outputs. 00538 * Note the double parentheses! 00539 */ 00540 #ifndef NDEBUG 00541 #define FXTRACE(arguments) FX::fxtrace arguments 00542 #else 00543 #define FXTRACE(arguments) ((void)0) 00544 #endif 00545 00546 00547 /** 00548 * Allocate a memory block of no elements of type and store a pointer 00549 * to it into the address pointed to by ptr. 00550 * Return FALSE if size!=0 and allocation fails, TRUE otherwise. 00551 * An allocation of a zero size block returns a NULL pointer. 00552 */ 00553 #define FXMALLOC(ptr,type,no) (FX::fxmalloc((void **)(ptr),sizeof(type)*(no))) 00554 00555 /** 00556 * Allocate a zero-filled memory block no elements of type and store a pointer 00557 * to it into the address pointed to by ptr. 00558 * Return FALSE if size!=0 and allocation fails, TRUE otherwise. 00559 * An allocation of a zero size block returns a NULL pointer. 00560 */ 00561 #define FXCALLOC(ptr,type,no) (FX::fxcalloc((void **)(ptr),sizeof(type)*(no))) 00562 00563 /** 00564 * Resize the memory block referred to by the pointer at the address ptr, to a 00565 * hold no elements of type. 00566 * Returns FALSE if size!=0 and reallocation fails, TRUE otherwise. 00567 * If reallocation fails, pointer is left to point to old block; a reallocation 00568 * to a zero size block has the effect of freeing it. 00569 * The ptr argument must be the address where the pointer to the allocated 00570 * block is to be stored. 00571 */ 00572 #define FXRESIZE(ptr,type,no) (FX::fxresize((void **)(ptr),sizeof(type)*(no))) 00573 00574 /** 00575 * Allocate and initialize memory from another block. 00576 * Return FALSE if size!=0 and source!=NULL and allocation fails, TRUE otherwise. 00577 * An allocation of a zero size block returns a NULL pointer. 00578 * The ptr argument must be the address where the pointer to the allocated 00579 * block is to be stored. 00580 */ 00581 #define FXMEMDUP(ptr,src,type,no) (FX::fxmemdup((void **)(ptr),(const void*)(src),sizeof(type)*(no))) 00582 00583 /** 00584 * Free a block of memory allocated with either FXMALLOC, FXCALLOC, FXRESIZE, or FXMEMDUP. 00585 * It is OK to call free a NULL pointer. The argument must be the address of the 00586 * pointer to the block to be released. The pointer is set to NULL to prevent 00587 * any further references to the block after releasing it. 00588 */ 00589 #define FXFREE(ptr) (FX::fxfree((void **)(ptr))) 00590 00591 00592 /** 00593 * These are some of the ISO C99 standard single-precision transcendental functions. 00594 * On LINUX, specify _GNU_SOURCE or _ISOC99_SOURCE to enable native implementation; 00595 * otherwise, these macros will be used. Apple OS-X implements fabsf(x), ceilf(x), 00596 * floorf(x), and fmodf(x,y). 00597 */ 00598 #ifndef __USE_ISOC99 00599 #ifndef __APPLE__ 00600 #define fabsf(x) ((float)fabs((double)(x))) 00601 #define ceilf(x) ((float)ceil((double)(x))) 00602 #define floorf(x) ((float)floor((double)(x))) 00603 #define fmodf(x,y) ((float)fmod((double)(x),(double)(y))) 00604 #endif 00605 #define sqrtf(x) ((float)sqrt((double)(x))) 00606 #define sinf(x) ((float)sin((double)(x))) 00607 #define cosf(x) ((float)cos((double)(x))) 00608 #define tanf(x) ((float)tan((double)(x))) 00609 #define asinf(x) ((float)asin((double)(x))) 00610 #define acosf(x) ((float)acos((double)(x))) 00611 #define atanf(x) ((float)atan((double)(x))) 00612 #define atan2f(y,x) ((float)atan2((double)(y),(double)(x))) 00613 #define powf(x,y) ((float)pow((double)(x),(double)(y))) 00614 #define expf(x) ((float)exp((double)(x))) 00615 #define logf(x) ((float)log((double)(x))) 00616 #define log10f(x) ((float)log10((double)(x))) 00617 #endif 00618 00619 /********************************** Globals **********************************/ 00620 00621 /// Simple, thread-safe, random number generator 00622 extern FXAPI FXuint fxrandom(FXuint& seed); 00623 00624 /// Allocate memory 00625 extern FXAPI FXint fxmalloc(void** ptr,unsigned long size); 00626 00627 /// Allocate cleaned memory 00628 extern FXAPI FXint fxcalloc(void** ptr,unsigned long size); 00629 00630 /// Resize memory 00631 extern FXAPI FXint fxresize(void** ptr,unsigned long size); 00632 00633 /// Duplicate memory 00634 extern FXAPI FXint fxmemdup(void** ptr,const void* src,unsigned long size); 00635 00636 /// Free memory, resets ptr to NULL afterward 00637 extern FXAPI void fxfree(void** ptr); 00638 00639 /// Error routine 00640 extern FXAPI void fxerror(const char* format,...) FX_PRINTF(1,2) ; 00641 00642 /// Warning routine 00643 extern FXAPI void fxwarning(const char* format,...) FX_PRINTF(1,2) ; 00644 00645 /// Log message to [typically] stderr 00646 extern FXAPI void fxmessage(const char* format,...) FX_PRINTF(1,2) ; 00647 00648 /// Assert failed routine:- usually not called directly but called through FXASSERT 00649 extern FXAPI void fxassert(const char* expression,const char* filename,unsigned int lineno); 00650 00651 /// Trace printout routine:- usually not called directly but called through FXTRACE 00652 extern FXAPI void fxtrace(unsigned int level,const char* format,...) FX_PRINTF(2,3) ; 00653 00654 /// Sleep n microseconds 00655 extern FXAPI void fxsleep(unsigned int n); 00656 00657 /// Match a file name with a pattern 00658 extern FXAPI FXint fxfilematch(const char *pattern,const char *string,FXuint flags=(FILEMATCH_NOESCAPE|FILEMATCH_FILE_NAME)); 00659 00660 /// Get highlight color 00661 extern FXAPI FXColor makeHiliteColor(FXColor clr); 00662 00663 /// Get shadow color 00664 extern FXAPI FXColor makeShadowColor(FXColor clr); 00665 00666 /// Get process id 00667 extern FXAPI FXint fxgetpid(); 00668 00669 /// Convert to MSDOS 00670 extern FXAPI FXbool fxtoDOS(FXchar*& string,FXint& len); 00671 00672 /// Convert from MSDOS format 00673 extern FXAPI FXbool fxfromDOS(FXchar*& string,FXint& len); 00674 00675 /// Duplicate string 00676 extern FXAPI FXchar *fxstrdup(const FXchar* str); 00677 00678 /// Calculate a hash value from a string 00679 extern FXAPI FXuint fxstrhash(const FXchar* str); 00680 00681 /// Get RGB value from color name 00682 extern FXAPI FXColor fxcolorfromname(const FXchar* colorname); 00683 00684 /// Get name of (closest) color to RGB 00685 extern FXAPI FXchar* fxnamefromcolor(FXchar *colorname,FXColor color); 00686 00687 /// Convert RGB to HSV 00688 extern FXAPI void fxrgb_to_hsv(FXfloat& h,FXfloat& s,FXfloat& v,FXfloat r,FXfloat g,FXfloat b); 00689 00690 /// Convert HSV to RGB 00691 extern FXAPI void fxhsv_to_rgb(FXfloat& r,FXfloat& g,FXfloat& b,FXfloat h,FXfloat s,FXfloat v); 00692 00693 /// Floating point number classification: 0=OK, +/-1=Inf, +/-2=NaN 00694 extern FXAPI FXint fxieeefloatclass(FXfloat number); 00695 extern FXAPI FXint fxieeedoubleclass(FXdouble number); 00696 00697 /// Parse geometry, a-la X11 geometry specification 00698 extern FXAPI FXint fxparsegeometry(const FXchar *string,FXint& x,FXint& y,FXint& w,FXint& h); 00699 00700 /// True if executable with given path is a console application 00701 extern FXbool fxisconsole(const FXchar *path); 00702 00703 /// Version number that the library has been compiled with 00704 extern FXAPI const FXuchar fxversion[3]; 00705 00706 00707 /// Controls tracing level 00708 extern FXAPI unsigned int fxTraceLevel; 00709 00710 /** 00711 * Parse accelerator from string, yielding modifier and 00712 * key code. For example, fxparseAccel("Ctl+Shift+X") 00713 * yields MKUINT(KEY_X,CONTROLMASK|SHIFTMASK). 00714 */ 00715 extern FXAPI FXHotKey fxparseAccel(const FXString& string); 00716 00717 /** 00718 * Parse hot key from string, yielding modifier and 00719 * key code. For example, fxparseHotKey(""Salt && &Pepper!"") 00720 * yields MKUINT(KEY_p,ALTMASK). 00721 */ 00722 extern FXAPI FXHotKey fxparseHotKey(const FXString& string); 00723 00724 /** 00725 * Obtain hot key offset in string, or -1 if not found. 00726 * For example, findHotKey("Salt && &Pepper!") yields 7. 00727 */ 00728 extern FXAPI FXint fxfindHotKey(const FXString& string); 00729 00730 /** 00731 * Strip hot key combination from the string. 00732 * For example, stripHotKey("Salt && &Pepper") should 00733 * yield "Salt & Pepper". 00734 */ 00735 extern FXAPI FXString fxstripHotKey(const FXString& string); 00736 00737 } 00738 00739 #endif

Copyright © 1997-2005 Jeroen van der Zijp