![]() |
Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
![]() |
00001 /******************************************************************************** 00002 * * 00003 * FOX Definitions, Types, and Macros * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 1997,2006 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.178.2.2 2006/11/09 23:21:43 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 // End Of Line 00075 #ifdef WIN32 00076 #define ENDLINE "\r\n" 00077 #else 00078 #define ENDLINE "\n" 00079 #endif 00080 00081 00082 // For Windows 00083 #ifdef _DEBUG 00084 #ifndef DEBUG 00085 #define DEBUG 00086 #endif 00087 #endif 00088 #ifdef _NDEBUG 00089 #ifndef NDEBUG 00090 #define NDEBUG 00091 #endif 00092 #endif 00093 00094 00095 // Shared library support 00096 #ifdef WIN32 00097 #define FXLOCAL 00098 #define FXEXPORT __declspec(dllexport) 00099 #define FXIMPORT __declspec(dllimport) 00100 #else 00101 #if defined(__GNUC__) && (__GNUC__ >= 4) 00102 #define FXLOCAL __attribute__ ((visibility("hidden"))) 00103 #define FXEXPORT __attribute__ ((visibility("default"))) 00104 #define FXIMPORT 00105 #else 00106 #define FXLOCAL 00107 #define FXEXPORT 00108 #define FXIMPORT 00109 #endif 00110 #endif 00111 00112 // Define FXAPI for DLL builds 00113 #ifdef FOXDLL 00114 #ifdef FOXDLL_EXPORTS 00115 #define FXAPI FXEXPORT 00116 #define FXTEMPLATE_EXTERN 00117 #else 00118 #define FXAPI FXIMPORT 00119 #define FXTEMPLATE_EXTERN extern 00120 #endif 00121 #else 00122 #define FXAPI 00123 #define FXTEMPLATE_EXTERN 00124 #endif 00125 00126 // Callback 00127 #ifdef WIN32 00128 #ifndef CALLBACK 00129 #define CALLBACK __stdcall 00130 #endif 00131 #endif 00132 00133 00134 // Disable some warnings in VC++ 00135 #ifdef _MSC_VER 00136 #pragma warning(disable: 4251) 00137 #pragma warning(disable: 4231) 00138 #pragma warning(disable: 4244) 00139 #endif 00140 00141 // Checking printf and scanf format strings 00142 #if defined(_CC_GNU_) || defined(__GNUG__) || defined(__GNUC__) 00143 #define FX_PRINTF(fmt,arg) __attribute__((format(printf,fmt,arg))) 00144 #define FX_SCANF(fmt,arg) __attribute__((format(scanf,fmt,arg))) 00145 #else 00146 #define FX_PRINTF(fmt,arg) 00147 #define FX_SCANF(fmt,arg) 00148 #endif 00149 00150 // Raw event type 00151 #ifndef WIN32 00152 union _XEvent; 00153 #else 00154 struct tagMSG; 00155 #endif 00156 00157 00158 namespace FX { 00159 00160 00161 // FOX System Defined Selector Types 00162 enum FXSelType { 00163 SEL_NONE, 00164 SEL_KEYPRESS, /// Key pressed 00165 SEL_KEYRELEASE, /// Key released 00166 SEL_LEFTBUTTONPRESS, /// Left mouse button pressed 00167 SEL_LEFTBUTTONRELEASE, /// Left mouse button released 00168 SEL_MIDDLEBUTTONPRESS, /// Middle mouse button pressed 00169 SEL_MIDDLEBUTTONRELEASE, /// Middle mouse button released 00170 SEL_RIGHTBUTTONPRESS, /// Right mouse button pressed 00171 SEL_RIGHTBUTTONRELEASE, /// Right mouse button released 00172 SEL_MOTION, /// Mouse motion 00173 SEL_ENTER, /// Mouse entered window 00174 SEL_LEAVE, /// Mouse left window 00175 SEL_FOCUSIN, /// Focus into window 00176 SEL_FOCUSOUT, /// Focus out of window 00177 SEL_KEYMAP, 00178 SEL_UNGRABBED, /// Lost the grab (Windows) 00179 SEL_PAINT, /// Must repaint window 00180 SEL_CREATE, 00181 SEL_DESTROY, 00182 SEL_UNMAP, /// Window was hidden 00183 SEL_MAP, /// Window was shown 00184 SEL_CONFIGURE, /// Resize 00185 SEL_SELECTION_LOST, /// Widget lost selection 00186 SEL_SELECTION_GAINED, /// Widget gained selection 00187 SEL_SELECTION_REQUEST, /// Inquire selection data 00188 SEL_RAISED, /// Window to top of stack 00189 SEL_LOWERED, /// Window to bottom of stack 00190 SEL_CLOSE, /// Close window 00191 SEL_DELETE, /// Delete window 00192 SEL_MINIMIZE, /// Iconified 00193 SEL_RESTORE, /// No longer iconified or maximized 00194 SEL_MAXIMIZE, /// Maximized 00195 SEL_UPDATE, /// GUI update 00196 SEL_COMMAND, /// GUI command 00197 SEL_CLICKED, /// Clicked 00198 SEL_DOUBLECLICKED, /// Double-clicked 00199 SEL_TRIPLECLICKED, /// Triple-clicked 00200 SEL_MOUSEWHEEL, /// Mouse wheel 00201 SEL_CHANGED, /// GUI has changed 00202 SEL_VERIFY, /// Verify change 00203 SEL_DESELECTED, /// Deselected 00204 SEL_SELECTED, /// Selected 00205 SEL_INSERTED, /// Inserted 00206 SEL_REPLACED, /// Replaced 00207 SEL_DELETED, /// Deleted 00208 SEL_OPENED, /// Opened 00209 SEL_CLOSED, /// Closed 00210 SEL_EXPANDED, /// Expanded 00211 SEL_COLLAPSED, /// Collapsed 00212 SEL_BEGINDRAG, /// Start a drag 00213 SEL_ENDDRAG, /// End a drag 00214 SEL_DRAGGED, /// Dragged 00215 SEL_LASSOED, /// Lassoed 00216 SEL_TIMEOUT, /// Timeout occurred 00217 SEL_SIGNAL, /// Signal received 00218 SEL_CLIPBOARD_LOST, /// Widget lost clipboard 00219 SEL_CLIPBOARD_GAINED, /// Widget gained clipboard 00220 SEL_CLIPBOARD_REQUEST, /// Inquire clipboard data 00221 SEL_CHORE, /// Background chore 00222 SEL_FOCUS_SELF, /// Focus on widget itself 00223 SEL_FOCUS_RIGHT, /// Focus moved right 00224 SEL_FOCUS_LEFT, /// Focus moved left 00225 SEL_FOCUS_DOWN, /// Focus moved down 00226 SEL_FOCUS_UP, /// Focus moved up 00227 SEL_FOCUS_NEXT, /// Focus moved to next widget 00228 SEL_FOCUS_PREV, /// Focus moved to previous widget 00229 SEL_DND_ENTER, /// Drag action entering potential drop target 00230 SEL_DND_LEAVE, /// Drag action leaving potential drop target 00231 SEL_DND_DROP, /// Drop on drop target 00232 SEL_DND_MOTION, /// Drag position changed over potential drop target 00233 SEL_DND_REQUEST, /// Inquire drag and drop data 00234 SEL_IO_READ, /// Read activity on a pipe 00235 SEL_IO_WRITE, /// Write activity on a pipe 00236 SEL_IO_EXCEPT, /// Except activity on a pipe 00237 SEL_PICKED, /// Picked some location 00238 SEL_QUERY_TIP, /// Message inquiring about tooltip 00239 SEL_QUERY_HELP, /// Message inquiring about statusline help 00240 SEL_DOCKED, /// Toolbar docked 00241 SEL_FLOATED, /// Toolbar floated 00242 SEL_SESSION_NOTIFY, /// Session is about to close 00243 SEL_SESSION_CLOSED, /// Session is closed 00244 SEL_LAST 00245 }; 00246 00247 00248 /// FOX Keyboard and Button states 00249 enum { 00250 SHIFTMASK = 0x001, /// Shift key is down 00251 CAPSLOCKMASK = 0x002, /// Caps Lock key is down 00252 CONTROLMASK = 0x004, /// Ctrl key is down 00253 #ifdef __APPLE__ 00254 ALTMASK = 0x2000, /// Alt key is down 00255 METAMASK = 0x10, /// Meta key is down 00256 #else 00257 ALTMASK = 0x008, /// Alt key is down 00258 METAMASK = 0x040, /// Meta key is down 00259 #endif 00260 NUMLOCKMASK = 0x010, /// Num Lock key is down 00261 SCROLLLOCKMASK = 0x0E0, /// Scroll Lock key is down (seems to vary) 00262 LEFTBUTTONMASK = 0x100, /// Left mouse button is down 00263 MIDDLEBUTTONMASK = 0x200, /// Middle mouse button is down 00264 RIGHTBUTTONMASK = 0x400 /// Right mouse button is down 00265 }; 00266 00267 00268 /// FOX Mouse buttons 00269 enum { 00270 LEFTBUTTON = 1, 00271 MIDDLEBUTTON = 2, 00272 RIGHTBUTTON = 3 00273 }; 00274 00275 00276 /// FOX window crossing modes 00277 enum { 00278 CROSSINGNORMAL, /// Normal crossing event 00279 CROSSINGGRAB, /// Crossing due to mouse grab 00280 CROSSINGUNGRAB /// Crossing due to mouse ungrab 00281 }; 00282 00283 00284 /// FOX window visibility modes 00285 enum { 00286 VISIBILITYTOTAL, 00287 VISIBILITYPARTIAL, 00288 VISIBILITYNONE 00289 }; 00290 00291 00292 /// Options for fxfilematch 00293 enum { 00294 FILEMATCH_FILE_NAME = 1, /// No wildcard can ever match `/' 00295 FILEMATCH_NOESCAPE = 2, /// Backslashes don't quote special chars 00296 FILEMATCH_PERIOD = 4, /// Leading `.' is matched only explicitly 00297 FILEMATCH_LEADING_DIR = 8, /// Ignore `/...' after a match 00298 FILEMATCH_CASEFOLD = 16 /// Compare without regard to case 00299 }; 00300 00301 00302 /// Drag and drop actions 00303 enum FXDragAction { 00304 DRAG_REJECT = 0, /// Reject all drop actions 00305 DRAG_ACCEPT = 1, /// Accept any drop action 00306 DRAG_COPY = 2, /// Copy 00307 DRAG_MOVE = 3, /// Move 00308 DRAG_LINK = 4, /// Link 00309 DRAG_PRIVATE = 5 /// Private 00310 }; 00311 00312 00313 /// Origin of data 00314 enum FXDNDOrigin { 00315 FROM_SELECTION = 0, /// Primary selection 00316 FROM_CLIPBOARD = 1, /// Clipboard 00317 FROM_DRAGNDROP = 2 /// Drag and drop source 00318 }; 00319 00320 00321 /// Exponent display 00322 enum FXExponent { 00323 EXP_NEVER=FALSE, /// Never use exponential notation 00324 EXP_ALWAYS=TRUE, /// Always use exponential notation 00325 EXP_AUTO=MAYBE /// Use exponential notation if needed 00326 }; 00327 00328 00329 /// Search modes for search/replace dialogs 00330 enum { 00331 SEARCH_FORWARD = 0, /// Search forward (default) 00332 SEARCH_BACKWARD = 1, /// Search backward 00333 SEARCH_NOWRAP = 0, /// Don't wrap (default) 00334 SEARCH_WRAP = 2, /// Wrap around to start 00335 SEARCH_EXACT = 0, /// Exact match (default) 00336 SEARCH_IGNORECASE = 4, /// Ignore case 00337 SEARCH_REGEX = 8, /// Regular expression match 00338 SEARCH_PREFIX = 16 /// Prefix of subject string 00339 }; 00340 00341 00342 /********************************* Typedefs **********************************/ 00343 00344 // Forward declarations 00345 class FXObject; 00346 class FXStream; 00347 class FXString; 00348 00349 00350 // Streamable types; these are fixed size! 00351 typedef char FXchar; 00352 typedef unsigned char FXuchar; 00353 typedef FXuchar FXbool; 00354 typedef unsigned short FXushort; 00355 typedef short FXshort; 00356 typedef unsigned int FXuint; 00357 typedef int FXint; 00358 typedef float FXfloat; 00359 typedef double FXdouble; 00360 typedef FXObject *FXObjectPtr; 00361 #ifdef WIN32 00362 typedef unsigned int FXwchar; 00363 #if defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED) 00364 typedef unsigned short FXnchar; 00365 #elif defined(__WATCOM_INT64__) 00366 typedef long char FXnchar; 00367 #else 00368 typedef wchar_t FXnchar; 00369 #endif 00370 #else 00371 typedef wchar_t FXwchar; 00372 typedef unsigned short FXnchar; 00373 #endif 00374 #if defined(__LP64__) || defined(_LP64) || (_MIPS_SZLONG == 64) || (__WORDSIZE == 64) 00375 typedef unsigned long FXulong; 00376 typedef long FXlong; 00377 #elif defined(_MSC_VER) || (defined(__BCPLUSPLUS__) && __BORLANDC__ > 0x500) || defined(__WATCOM_INT64__) 00378 typedef unsigned __int64 FXulong; 00379 typedef __int64 FXlong; 00380 #elif defined(__GNUG__) || defined(__GNUC__) || defined(__SUNPRO_CC) || defined(__MWERKS__) || defined(__SC__) || defined(_LONGLONG) 00381 typedef unsigned long long FXulong; 00382 typedef long long FXlong; 00383 #else 00384 #error "FXlong and FXulong not defined for this architecture!" 00385 #endif 00386 00387 // Integral types large enough to hold value of a pointer 00388 #if defined(_MSC_VER) && defined(_WIN64) 00389 typedef __int64 FXival; 00390 typedef unsigned __int64 FXuval; 00391 #else 00392 typedef long FXival; 00393 typedef unsigned long FXuval; 00394 #endif 00395 00396 00397 // Handle to something in server 00398 #ifndef WIN32 00399 typedef unsigned long FXID; 00400 #else 00401 typedef void* FXID; 00402 #endif 00403 00404 // Time since January 1, 1970 (UTC) 00405 typedef long FXTime; 00406 00407 // Pixel type (could be color index) 00408 typedef unsigned long FXPixel; 00409 00410 // RGBA pixel value 00411 typedef FXuint FXColor; 00412 00413 // Hot key 00414 typedef FXuint FXHotKey; 00415 00416 // Drag type 00417 #ifndef WIN32 00418 typedef FXID FXDragType; 00419 #else 00420 typedef FXushort FXDragType; 00421 #endif 00422 00423 // Input source handle type 00424 #ifndef WIN32 00425 typedef FXint FXInputHandle; 00426 #else 00427 typedef void* FXInputHandle; 00428 #endif 00429 00430 // Raw event type 00431 #ifndef WIN32 00432 typedef _XEvent FXRawEvent; 00433 #else 00434 typedef tagMSG FXRawEvent; 00435 #endif 00436 00437 00438 /********************************** Macros ***********************************/ 00439 00440 00441 /// Abolute value 00442 #define FXABS(val) (((val)>=0)?(val):-(val)) 00443 00444 /// Return the maximum of a or b 00445 #define FXMAX(a,b) (((a)>(b))?(a):(b)) 00446 00447 /// Return the minimum of a or b 00448 #define FXMIN(a,b) (((a)>(b))?(b):(a)) 00449 00450 /// Return the minimum of x, y and z 00451 #define FXMIN3(x,y,z) ((x)<(y)?FXMIN(x,z):FXMIN(y,z)) 00452 00453 /// Return the maximum of x, y and z 00454 #define FXMAX3(x,y,z) ((x)>(y)?FXMAX(x,z):FXMAX(y,z)) 00455 00456 /// Return the minimum of x, y, z, and w 00457 #define FXMIN4(x,y,z,w) (FXMIN(FXMIN(x,y),FXMIN(z,w))) 00458 00459 /// Return the maximum of of x, y, z, and w 00460 #define FXMAX4(x,y,z,w) (FXMAX(FXMAX(x,y),FXMAX(z,w))) 00461 00462 /// Return minimum and maximum of a, b 00463 #define FXMINMAX(lo,hi,a,b) ((a)<(b)?((lo)=(a),(hi)=(b)):((lo)=(b),(hi)=(a))) 00464 00465 /// Clamp value x to range [lo..hi] 00466 #define FXCLAMP(lo,x,hi) ((x)<(lo)?(lo):((x)>(hi)?(hi):(x))) 00467 00468 /// Swap a pair of numbers 00469 #define FXSWAP(a,b,t) ((t)=(a),(a)=(b),(b)=(t)) 00470 00471 /// Linear interpolation between a and b, where 0<=f<=1 00472 #define FXLERP(a,b,f) ((a)+((b)-(a))*(f)) 00473 00474 /// Offset of member in a structure 00475 #define STRUCTOFFSET(str,member) (((char *)(&(((str *)0)->member)))-((char *)0)) 00476 00477 /// Number of elements in a static array 00478 #define ARRAYNUMBER(array) (sizeof(array)/sizeof(array[0])) 00479 00480 /// Container class of a member class 00481 #define CONTAINER(ptr,str,mem) ((str*)(((char*)(ptr))-STRUCTOFFSET(str,mem))) 00482 00483 /// Make int out of two shorts 00484 #define MKUINT(l,h) ((((FX::FXuint)(l))&0xffff) | (((FX::FXuint)(h))<<16)) 00485 00486 /// Make selector from message type and message id 00487 #define FXSEL(type,id) ((((FX::FXuint)(id))&0xffff) | (((FX::FXuint)(type))<<16)) 00488 00489 /// Get type from selector 00490 #define FXSELTYPE(s) ((FX::FXushort)(((s)>>16)&0xffff)) 00491 00492 /// Get ID from selector 00493 #define FXSELID(s) ((FX::FXushort)((s)&0xffff)) 00494 00495 /// Reverse bits in byte 00496 #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)) 00497 00498 /// Test if character c is at the start of a utf8 sequence 00499 #define FXISUTF(c) (((c)&0xC0)!=0x80) 00500 00501 00502 // Definitions for big-endian machines 00503 #if FOX_BIGENDIAN == 1 00504 00505 /// Make RGBA color 00506 #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))) 00507 00508 /// Make RGB color 00509 #define FXRGB(r,g,b) (((FX::FXuint)(FX::FXuchar)(r)<<24) | ((FX::FXuint)(FX::FXuchar)(g)<<16) | ((FX::FXuint)(FX::FXuchar)(b)<<8) | 0x000000ff) 00510 00511 /// Get red value from RGBA color 00512 #define FXREDVAL(rgba) ((FX::FXuchar)(((rgba)>>24)&0xff)) 00513 00514 /// Get green value from RGBA color 00515 #define FXGREENVAL(rgba) ((FX::FXuchar)(((rgba)>>16)&0xff)) 00516 00517 /// Get blue value from RGBA color 00518 #define FXBLUEVAL(rgba) ((FX::FXuchar)(((rgba)>>8)&0xff)) 00519 00520 /// Get alpha value from RGBA color 00521 #define FXALPHAVAL(rgba) ((FX::FXuchar)((rgba)&0xff)) 00522 00523 /// Get component value of RGBA color 00524 #define FXRGBACOMPVAL(rgba,comp) ((FX::FXuchar)(((rgba)>>((3-(comp))<<3))&0xff)) 00525 00526 #endif 00527 00528 00529 // Definitions for little-endian machines 00530 #if FOX_BIGENDIAN == 0 00531 00532 /// Make RGBA color 00533 #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)) 00534 00535 /// Make RGB color 00536 #define FXRGB(r,g,b) (((FX::FXuint)(FX::FXuchar)(r)) | ((FX::FXuint)(FX::FXuchar)(g)<<8) | ((FX::FXuint)(FX::FXuchar)(b)<<16) | 0xff000000) 00537 00538 /// Get red value from RGBA color 00539 #define FXREDVAL(rgba) ((FX::FXuchar)((rgba)&0xff)) 00540 00541 /// Get green value from RGBA color 00542 #define FXGREENVAL(rgba) ((FX::FXuchar)(((rgba)>>8)&0xff)) 00543 00544 /// Get blue value from RGBA color 00545 #define FXBLUEVAL(rgba) ((FX::FXuchar)(((rgba)>>16)&0xff)) 00546 00547 /// Get alpha value from RGBA color 00548 #define FXALPHAVAL(rgba) ((FX::FXuchar)(((rgba)>>24)&0xff)) 00549 00550 /// Get component value of RGBA color 00551 #define FXRGBACOMPVAL(rgba,comp) ((FX::FXuchar)(((rgba)>>((comp)<<3))&0xff)) 00552 00553 #endif 00554 00555 00556 /** 00557 * FXASSERT() prints out a message when the expression fails, 00558 * and nothing otherwise. Unlike assert(), FXASSERT() will not 00559 * terminate the execution of the application. 00560 * When compiling your application for release, all assertions 00561 * are compiled out; thus there is no impact on execution speed. 00562 */ 00563 #ifndef NDEBUG 00564 #define FXASSERT(exp) ((exp)?((void)0):(void)FX::fxassert(#exp,__FILE__,__LINE__)) 00565 #else 00566 #define FXASSERT(exp) ((void)0) 00567 #endif 00568 00569 00570 /** 00571 * FXTRACE() allows you to trace the execution of your application 00572 * with increasing levels of detail the higher the trace level. 00573 * The trace level is determined by variable fxTraceLevel, which 00574 * may be set from the command line with "-tracelevel <level>". 00575 * When compiling your application for release, all trace statements 00576 * are compiled out, just like FXASSERT. 00577 * A statement like: FXTRACE((10,"The value of x=%d\n",x)) will 00578 * generate output only if fxTraceLevel is set to 11 or greater. 00579 * The default value fxTraceLevel=0 will block all trace outputs. 00580 * Note the double parentheses! 00581 */ 00582 #ifndef NDEBUG 00583 #define FXTRACE(arguments) FX::fxtrace arguments 00584 #else 00585 #define FXTRACE(arguments) ((void)0) 00586 #endif 00587 00588 00589 /** 00590 * Allocate a memory block of no elements of type and store a pointer 00591 * to it into the address pointed to by ptr. 00592 * Return FALSE if size!=0 and allocation fails, TRUE otherwise. 00593 * An allocation of a zero size block returns a NULL pointer. 00594 */ 00595 #define FXMALLOC(ptr,type,no) (FX::fxmalloc((void **)(ptr),sizeof(type)*(no))) 00596 00597 /** 00598 * Allocate a zero-filled memory block no elements of type and store a pointer 00599 * to it into the address pointed to by ptr. 00600 * Return FALSE if size!=0 and allocation fails, TRUE otherwise. 00601 * An allocation of a zero size block returns a NULL pointer. 00602 */ 00603 #define FXCALLOC(ptr,type,no) (FX::fxcalloc((void **)(ptr),sizeof(type)*(no))) 00604 00605 /** 00606 * Resize the memory block referred to by the pointer at the address ptr, to a 00607 * hold no elements of type. 00608 * Returns FALSE if size!=0 and reallocation fails, TRUE otherwise. 00609 * If reallocation fails, pointer is left to point to old block; a reallocation 00610 * to a zero size block has the effect of freeing it. 00611 * The ptr argument must be the address where the pointer to the allocated 00612 * block is to be stored. 00613 */ 00614 #define FXRESIZE(ptr,type,no) (FX::fxresize((void **)(ptr),sizeof(type)*(no))) 00615 00616 /** 00617 * Allocate and initialize memory from another block. 00618 * Return FALSE if size!=0 and source!=NULL and allocation fails, TRUE otherwise. 00619 * An allocation of a zero size block returns a NULL pointer. 00620 * The ptr argument must be the address where the pointer to the allocated 00621 * block is to be stored. 00622 */ 00623 #define FXMEMDUP(ptr,src,type,no) (FX::fxmemdup((void **)(ptr),(const void*)(src),sizeof(type)*(no))) 00624 00625 /** 00626 * Free a block of memory allocated with either FXMALLOC, FXCALLOC, FXRESIZE, or FXMEMDUP. 00627 * It is OK to call free a NULL pointer. The argument must be the address of the 00628 * pointer to the block to be released. The pointer is set to NULL to prevent 00629 * any further references to the block after releasing it. 00630 */ 00631 #define FXFREE(ptr) (FX::fxfree((void **)(ptr))) 00632 00633 00634 /** 00635 * These are some of the ISO C99 standard single-precision transcendental functions. 00636 * On LINUX, specify _GNU_SOURCE or _ISOC99_SOURCE to enable native implementation; 00637 * otherwise, these macros will be used. Apple OS-X implements fabsf(x), ceilf(x), 00638 * floorf(x), and fmodf(x,y). 00639 * Define FLOAT_MATH_FUNCTIONS if these functions are available in some other 00640 * library you're linking to. 00641 */ 00642 #ifdef __OpenBSD__ 00643 #define FLOAT_MATH_FUNCTIONS 00644 #endif 00645 #ifndef FLOAT_MATH_FUNCTIONS 00646 #ifndef __USE_ISOC99 00647 #ifndef __APPLE__ 00648 #define fabsf(x) ((float)fabs((double)(x))) 00649 #define ceilf(x) ((float)ceil((double)(x))) 00650 #define floorf(x) ((float)floor((double)(x))) 00651 #define fmodf(x,y) ((float)fmod((double)(x),(double)(y))) 00652 #endif 00653 #define sqrtf(x) ((float)sqrt((double)(x))) 00654 #define sinf(x) ((float)sin((double)(x))) 00655 #define cosf(x) ((float)cos((double)(x))) 00656 #define tanf(x) ((float)tan((double)(x))) 00657 #define asinf(x) ((float)asin((double)(x))) 00658 #define acosf(x) ((float)acos((double)(x))) 00659 #define atanf(x) ((float)atan((double)(x))) 00660 #define atan2f(y,x) ((float)atan2((double)(y),(double)(x))) 00661 #define powf(x,y) ((float)pow((double)(x),(double)(y))) 00662 #define expf(x) ((float)exp((double)(x))) 00663 #define logf(x) ((float)log((double)(x))) 00664 #define log10f(x) ((float)log10((double)(x))) 00665 #endif 00666 #endif 00667 00668 00669 /********************************** Globals **********************************/ 00670 00671 /// Simple, thread-safe, random number generator 00672 extern FXAPI FXuint fxrandom(FXuint& seed); 00673 00674 /// Allocate memory 00675 extern FXAPI FXint fxmalloc(void** ptr,unsigned long size); 00676 00677 /// Allocate cleaned memory 00678 extern FXAPI FXint fxcalloc(void** ptr,unsigned long size); 00679 00680 /// Resize memory 00681 extern FXAPI FXint fxresize(void** ptr,unsigned long size); 00682 00683 /// Duplicate memory 00684 extern FXAPI FXint fxmemdup(void** ptr,const void* src,unsigned long size); 00685 00686 /// Free memory, resets ptr to NULL afterward 00687 extern FXAPI void fxfree(void** ptr); 00688 00689 /// Error routine 00690 extern FXAPI void fxerror(const char* format,...) FX_PRINTF(1,2) ; 00691 00692 /// Warning routine 00693 extern FXAPI void fxwarning(const char* format,...) FX_PRINTF(1,2) ; 00694 00695 /// Log message to [typically] stderr 00696 extern FXAPI void fxmessage(const char* format,...) FX_PRINTF(1,2) ; 00697 00698 /// Assert failed routine:- usually not called directly but called through FXASSERT 00699 extern FXAPI void fxassert(const char* expression,const char* filename,unsigned int lineno); 00700 00701 /// Trace printout routine:- usually not called directly but called through FXTRACE 00702 extern FXAPI void fxtrace(unsigned int level,const char* format,...) FX_PRINTF(2,3) ; 00703 00704 /// Sleep n microseconds 00705 extern FXAPI void fxsleep(unsigned int n); 00706 00707 /// Match a file name with a pattern 00708 extern FXAPI bool fxfilematch(const char *pattern,const char *string,FXuint flags=(FILEMATCH_NOESCAPE|FILEMATCH_FILE_NAME)); 00709 00710 /// Get highlight color 00711 extern FXAPI FXColor makeHiliteColor(FXColor clr); 00712 00713 /// Get shadow color 00714 extern FXAPI FXColor makeShadowColor(FXColor clr); 00715 00716 /// Get process id 00717 extern FXAPI FXint fxgetpid(); 00718 00719 /// Convert string of length len to MSDOS; return new string and new length 00720 extern FXAPI bool fxtoDOS(FXchar*& string,FXint& len); 00721 00722 /// Convert string of length len from MSDOS; return new string and new length 00723 extern FXAPI bool fxfromDOS(FXchar*& string,FXint& len); 00724 00725 /// Duplicate string 00726 extern FXAPI FXchar *fxstrdup(const FXchar* str); 00727 00728 /// Calculate a hash value from a string 00729 extern FXAPI FXuint fxstrhash(const FXchar* str); 00730 00731 /// Get RGB value from color name 00732 extern FXAPI FXColor fxcolorfromname(const FXchar* colorname); 00733 00734 /// Get name of (closest) color to RGB 00735 extern FXAPI FXchar* fxnamefromcolor(FXchar *colorname,FXColor color); 00736 00737 /// Convert RGB to HSV 00738 extern FXAPI void fxrgb_to_hsv(FXfloat& h,FXfloat& s,FXfloat& v,FXfloat r,FXfloat g,FXfloat b); 00739 00740 /// Convert HSV to RGB 00741 extern FXAPI void fxhsv_to_rgb(FXfloat& r,FXfloat& g,FXfloat& b,FXfloat h,FXfloat s,FXfloat v); 00742 00743 /// Floating point number classification: 0=OK, +/-1=Inf, +/-2=NaN 00744 extern FXAPI FXint fxieeefloatclass(FXfloat number); 00745 extern FXAPI FXint fxieeedoubleclass(FXdouble number); 00746 00747 /// Convert keysym to unicode character 00748 extern FXAPI FXwchar fxkeysym2ucs(FXwchar sym); 00749 00750 /// Convert unicode character to keysym 00751 extern FXAPI FXwchar fxucs2keysym(FXwchar ucs); 00752 00753 /// Parse geometry, a-la X11 geometry specification 00754 extern FXAPI FXint fxparsegeometry(const FXchar *string,FXint& x,FXint& y,FXint& w,FXint& h); 00755 00756 /// True if executable with given path is a console application 00757 extern FXAPI FXbool fxisconsole(const FXchar *path); 00758 00759 /// Version number that the library has been compiled with 00760 extern FXAPI const FXuchar fxversion[3]; 00761 00762 /// Controls tracing level 00763 extern FXAPI unsigned int fxTraceLevel; 00764 00765 /// Return wide character from utf8 string at ptr 00766 extern FXAPI FXwchar wc(const FXchar *ptr); 00767 00768 /// Return wide character from utf16 string at ptr 00769 extern FXAPI FXwchar wc(const FXnchar *ptr); 00770 00771 /// Return number of FXchar's of wide character at ptr 00772 extern FXAPI FXint wclen(const FXchar *ptr); 00773 00774 /// Return number of FXnchar's of narrow character at ptr 00775 extern FXAPI FXint wclen(const FXnchar *ptr); 00776 00777 /// Return start of utf8 character containing position 00778 extern FXAPI FXint wcvalidate(const FXchar* string,FXint pos); 00779 00780 /// Return start of utf16 character containing position 00781 extern FXAPI FXint wcvalidate(const FXnchar *string,FXint pos); 00782 00783 /// Advance to next utf8 character start 00784 extern FXAPI FXint wcinc(const FXchar* string,FXint pos); 00785 00786 /// Advance to next utf16 character start 00787 extern FXAPI FXint wcinc(const FXnchar *string,FXint pos); 00788 00789 /// Retreat to previous utf8 character start 00790 extern FXAPI FXint wcdec(const FXchar* string,FXint pos); 00791 00792 /// Retreat to previous utf16 character start 00793 extern FXAPI FXint wcdec(const FXnchar *string,FXint pos); 00794 00795 /// Length of utf8 representation of wide characters string str of length n 00796 extern FXAPI FXint utfslen(const FXwchar *str,FXint n); 00797 00798 /// Length of utf8 representation of wide character string str 00799 extern FXAPI FXint utfslen(const FXwchar *str); 00800 00801 /// Length of utf8 representation of narrow characters string str of length n 00802 extern FXAPI FXint utfslen(const FXnchar *str,FXint n); 00803 00804 /// Length of utf8 representation of narrow characters string str 00805 extern FXAPI FXint utfslen(const FXnchar *str); 00806 00807 /// Length of wide character representation of utf8 string str of length n 00808 extern FXAPI FXint wcslen(const FXchar *str,FXint n); 00809 00810 /// Length of wide character representation of utf8 string str 00811 extern FXAPI FXint wcslen(const FXchar *str); 00812 00813 /// Length of narrow character representation of utf8 string str of length n 00814 extern FXAPI FXint ncslen(const FXchar *str,FXint n); 00815 00816 /// Length of narrow character representation of utf8 string str 00817 extern FXAPI FXint ncslen(const FXchar *str); 00818 00819 /// Copy utf8 string of length n to wide character string dst 00820 extern FXAPI FXint utf2wcs(FXwchar *dst,const FXchar *src,FXint n); 00821 00822 /// Copy utf8 string to wide character string dst 00823 extern FXAPI FXint utf2wcs(FXwchar *dst,const FXchar *src); 00824 00825 /// Copy utf8 string of length n to narrow character string dst 00826 extern FXAPI FXint utf2ncs(FXnchar *dst,const FXchar *src,FXint n); 00827 00828 /// Copy utf8 string to narrow character string dst 00829 extern FXAPI FXint utf2ncs(FXnchar *dst,const FXchar *src); 00830 00831 /// Copy wide character substring of length n to dst 00832 extern FXAPI FXint wc2utfs(FXchar* dst,const FXwchar *src,FXint n); 00833 00834 /// Copy wide character string to dst 00835 extern FXAPI FXint wc2utfs(FXchar* dst,const FXwchar *src); 00836 00837 /// Copy narrow character substring of length n to dst 00838 extern FXAPI FXint nc2utfs(FXchar* dst,const FXnchar *src,FXint n); 00839 00840 /// Copy narrow character string to dst 00841 extern FXAPI FXint nc2utfs(FXchar* dst,const FXnchar *src); 00842 00843 00844 } 00845 00846 #endif
![]() |