📄 toolkit.h
字号:
/** * toolkit.h - * * Copyright (c) 1998 * Transvirtual Technologies, Inc. All rights reserved. * * See the file "license.terms" for information on usage and redistribution * of this file. */#ifndef __toolkit_h#define __toolkit_h#include "config.h"#include "config-std.h"#include "config-mem.h"#include "config-setjmp.h"#include "jcl.h"#undef DBG#include <X11/Xlib.h>#include <X11/Xutil.h>// #if defined(HAVE_LIBXEXT) && defined(HAVE_SYS_IPC_H) && defined(HAVE_SYS_SHM_H) && defined(HAVE_X11_EXTENSIONS_XSHM_H)// #define USE_XSHM_EXTENSION 1#include <sys/ipc.h>#include <sys/shm.h>#if defined(HAVE_LIBXEXT)#if defined(HAVE_X11_EXTENSIONS_XSHM_H)#include <X11/extensions/XShm.h>#endif /* defined(HAVE_X11_EXTENSIONS_XSHM_H) */#else// #undef USE_XSHM_EXTENSION#define XShmGetImage(A,B,C,D,E,F) 0#define XShmPutImage(A,B,C,D,E,F,G,H,I,J,K) 0#define XShmSegmentInfo void#endif#include <jni.h>#include "gtypes.h"#include "gc.h"#include "thread.h"#include "debug.h"#define DBG_ACTION(A,B)#ifdef HAVE_FCNTL_H#include <fcntl.h>#endif/******************************************************************************* * color conversion structures */#define N_DIRECT 256typedef struct _Rgb2Direct { unsigned char red[N_DIRECT]; unsigned char redPix[N_DIRECT]; int redShift; int nRed; unsigned char green[N_DIRECT]; unsigned char greenPix[N_DIRECT]; int greenShift; int nGreen; unsigned char blue[N_DIRECT]; unsigned char bluePix[N_DIRECT]; int blueShift; int nBlue;} Rgb2Direct;typedef struct _Rgb2True { unsigned int redMask; unsigned int greenMask; unsigned int blueMask; int blueShift; int redShift; int greenShift;} Rgb2True;typedef struct _RgbColor { unsigned char r; unsigned char g; unsigned char b;} RgbColor;typedef struct _Rgb2Pseudo { RgbColor rgb[256]; unsigned char pix[8][8][8];} Rgb2Pseudo;/******************************************************************************* * image handling structures */typedef struct _AlphaImage { /* storage for full alpha channel images */ unsigned char *buf; int width, height;} AlphaImage;#define NO_SHM 0 /* we don't have MIT-Shm support in the X server */#define USE_SHM 1 /* we have support, use it */#define SUSPEND_SHM 2 /* we have support, but it ran out of space */typedef struct _Image { Pixmap pix; /* pixmap for screen images */ XImage *xImg; /* "real" image */ XShmSegmentInfo *shmiImg; /* Shm info for shared mem real image */ XImage *xMask; /* mask image for reduced alpha (on/off) images */ XShmSegmentInfo *shmiMask; /* Shm info for shared mem mask image */ AlphaImage *alpha; /* full alpha channel (for alpha != 0x00 or 0xff) */ int trans; /* transparent index */ int left, top; /* some GIF movies require drawing offsets */ int width, height; /* we need this in case we are a pixmap */ short latency; /* between image flips, for "gif-movies" */ short frame; /* frame number for animations */ struct _Image *next; /* next movie-frame */} Image;/******************************************************************************* * structure to store guessed and computed Frame/Dialog insets (titlebar, borders) */typedef struct _DecoInset { int left; int top; int right; int bottom; char guess;} DecoInset; /******************************************************************************* * We use our own structure instead of directly storing X window handles, to * enable us to attach and query attributes (owners, states, flags..) to particular * X window instances. We could do this by means of X properties, but this might * end up in costly round-trips and even more memory (than we trade for speed here). * It's a must have for our popup key/focus event forwarding (see wnd.c) */typedef struct _WindowRec { Window w; unsigned flags; Window owner;} WindowRec;/******************************************************************************* * this is the master AWT structure (singleton object), glueing it al together */typedef struct _Toolkit { Display *dsp; Window root; char *buf; unsigned int nBuf; int colorMode; /* refers to CM_xx constants, not X visuals */ Rgb2True *tclr; Rgb2Pseudo *pclr; Rgb2Direct *dclr; int shm; int shmThreshold; Cursor cursors[14]; DecoInset frameInsets; DecoInset dialogInsets; XEvent event; char preFetched; char blocking; int pending; int evtId; fd_set rfds; /* used to select-check availability of X input (pthreads) */ Window lastWindow; int srcIdx; WindowRec *windows; int nWindows; Window cbdOwner; Window wakeUp; Window focus; /* this is the real focus, if it is in our process */ Window focusFwd; /* this might be a (owned) window we forward the focus to */ int fwdIdx; /* cached index of the focus forward window */#ifdef KAFFE_I18N XOM xom; /* X Output Method */#endif } Toolkit;/******************************************************************************* * global data def/decl */#ifdef MAINToolkit XTk;Toolkit *X = &XTk;Atom WM_PROTOCOLS;Atom WM_DELETE_WINDOW;Atom WM_TAKE_FOCUS;Atom WAKEUP;Atom RETRY_FOCUS;Atom FORWARD_FOCUS;Atom SELECTION_DATA;Atom JAVA_OBJECT;jclass AWTError;JNIEnv *JniEnv;#elseextern Toolkit* X;extern Atom WM_PROTOCOLS;extern Atom WM_DELETE_WINDOW;extern Atom WM_TAKE_FOCUS;extern Atom WAKEUP;extern Atom RETRY_FOCUS;extern Atom FORWARD_FOCUS;extern Atom SELECTION_DATA;extern Atom JAVA_OBJECT;extern jclass AWTError;extern JNIEnv* JniEnv;#endif /* MAIN */extern long StdEvents, PopupEvents;/***************************************************************************************** * heap wrapper macros */static inline void* _awt_malloc_wrapper ( size_t size ){ void *adr; enterUnsafeRegion(); adr = malloc( size); leaveUnsafeRegion(); DBG( AWT_MEM, printf("malloc: %zi -> %p\n", size, adr)); return adr;}static inline void* _awt_calloc_wrapper ( size_t n, size_t size ){ void *adr; enterUnsafeRegion(); adr = calloc( n, size); leaveUnsafeRegion(); DBG( AWT_MEM, printf("calloc: %zi,%zi -> %p\n", n, size, adr)); return adr;}static inline void _awt_free_wrapper ( void* adr ){ DBG( AWT_MEM, printf("free: %p\n", adr)); enterUnsafeRegion(); free( adr); leaveUnsafeRegion();}#define AWT_MALLOC(_n) \ _awt_malloc_wrapper( _n)#define AWT_CALLOC(_n,_sz) \ _awt_calloc_wrapper( _n, _sz)#define AWT_FREE(_adr) \ _awt_free_wrapper( _adr);/******************************************************************************* * */static inline char* java2CString ( JNIEnv *env, Toolkit* tk, jstring jstr ) { jboolean isCopy; register unsigned int i; jsize n = (*env)->GetStringLength( env, jstr); const jchar *jc = (*env)->GetStringChars( env, jstr, &isCopy); if ( n >= tk->nBuf ) { if ( tk->buf ) AWT_FREE( tk->buf); tk->buf = AWT_MALLOC( n+1); tk->nBuf = n+1; } for ( i=0; i<n; i++ ) tk->buf[i] = (char) jc[i]; tk->buf[i] = 0; (*env)->ReleaseStringChars( env, jstr, jc); return tk->buf;}static inline char* jchar2CString ( Toolkit* tk, jchar* jc, size_t len ) { register size_t i; size_t n = len+1; if ( n > tk->nBuf ) { if ( tk->buf ) AWT_FREE( tk->buf); tk->buf = AWT_MALLOC( n); tk->nBuf = n; } for ( i=0; i<len; i++ ) tk->buf[i] = (char) jc[i]; tk->buf[i] = 0; return tk->buf;}static inline void* getBuffer ( Toolkit* tk, unsigned int nBytes ) { if ( nBytes > tk->nBuf ) { if ( tk->buf ) AWT_FREE( tk->buf); tk->buf = AWT_MALLOC( nBytes); tk->nBuf = nBytes; } return tk->buf;}#ifdef KAFFE_I18Nstatic inline wchar_t* jchar2wchar( const jchar *jc, int len ) { int i; wchar_t *wch = (wchar_t *)malloc(sizeof(wchar_t)*len); for( i=0; i < len; i++ ) wch[i] = jc[i]; return wch;}static inline wchar_t* jbyte2wchar( jbyte *jc, int len ) { int i; wchar_t *wch = (wchar_t *)malloc(sizeof(wchar_t)*(len)); for( i=0; i < len; i++ ) wch[i] = jc[i]; return wch;}#endif/***************************************************************************************** * color functions & defines *//* * These are our directly supported visuals / color modes. Note that there is * no more 1-1 correspondence to X visuals, since we do a categorisation with * respect to our internal RGB <-> pixel conversion. All visuals not listed * explicitly are handled via the generic XAllocColor/XQueryColor (which might * slow down images considerably) * * NOTE: these values have to be != 0, since '0' is used to trigger color init */#define CM_PSEUDO_256 1 /* PseudoColor visual */#define CM_TRUE 2 /* general TrueColor visual */#define CM_TRUE_888 3 /* special 8-8-8 bit TrueColor visual */#define CM_DIRECT 4#define CM_GENERIC 5 /* grays, DirectColor (packed) etc. */int needsFullAlpha ( Toolkit* tk, Image *img, double threshold );void initColorMapping ( JNIEnv* env, jclass clazz, Toolkit* tk);jlong Java_java_awt_Toolkit_clrBright ( JNIEnv* env, jclass clazz, jint rgb );jlong Java_java_awt_Toolkit_clrDark ( JNIEnv* env, jclass clazz, jint rgb );#define JRGB(_r,_g,_b) (_r<<16 | _g<<8 | _b)#define JRED(_rgb) ((_rgb & 0xff0000) >> 16)#define JGREEN(_rgb) ((_rgb & 0x00ff00) >> 8)#define JBLUE(_rgb) (_rgb & 0x0000ff)#define D8 36.43 /* 255 / 7 */#define D16 18.21#define JI8(_v) (int)((_v + D16) / D8)#define XI8(_v) (int)(((_v>>8) + D16) / D8)#define ROUND_SHORT2CHAR(_n) \ ((unsigned short)_n >= 0xff70 ) ? 0xff : (unsigned char)(((unsigned short)_n + 0x80) >> 8)/* shift ops with negative values have undefined results */#define SIGNED_RSHIFT(_var,_val,_shift) \ _var = _val; \ if ( _shift > 0 ) _var >>= _shift; \ else _var <<= -_shift;#define SIGNED_LSHIFT(_var,_val,_shift) \ _var = _val; \ if ( _shift > 0 ) _var <<= _shift; \ else _var >>= -_shift;static inline jint
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -