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