#ifndef __toolkit_h
#define __toolkit_h
extern "C" {
#include "config.h"
#include "config-std.h"
#include "config-io.h"
#include "config-mem.h"
#include "jni.h"
};
#include <InterfaceKit.h>
#include "cmnwnd.hpp"
extern "C" {
#include "../../../../kaffe/kaffevm/gtypes.h"
#include "../../../../kaffe/kaffevm/locks.h"
#include "../../../../include/java_lang_Object.h"
#include "../../../../kaffe/kaffevm/gc.h"
#include "../../../../kaffe/kaffevm/debug.h"
}
/*** debug ***/
#include <stdio.h>
#undef DBG
#define DBG(_topic,_msgSpec) if (kaffevmDebugMask & DBG_##_topic) printf _msgSpec
#define DBG_ACTION(_topic,__action) if (kaffevmDebugMask & DBG_##_topic) __action
#define UNIMPLEMENTED(block) printf("unimplemented statements @ %s:%d\n", __FILE__ , __LINE__)
#define TOFIX() printf("incomplete function called @ %s:%d\n", __FILE__ , __LINE__)
/* #define D_LOOP_MODE 1
already tried, but we are not able to natively post events from the window's thread,
we would need the already running window's BLooper to become a Java thread, TEP
*/
#if 0
extern "C" LRESULT WINAPI WndProc( HWND, UINT, WPARAM, LPARAM);
#endif
#define TCHAR char
#define AWT_EXPORT extern "C"
/*******************************************************************************
* image handling structures
*/
typedef struct _AlphaImage { /* storage for full alpha channel images */
unsigned char *buf;
int width, height;
} AlphaImage;
typedef struct _Image {
int trans; /* transparent index */
int left, top;
int width, height; /* we need this in case we are a pixmap */
BBitmap * bitmap;
#if TODO
int latency; /* between image flips, for "gif-movies" */
int frame;
struct _Image *next; /* next movie-frame */
#endif
} 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;
/*******************************************************************************
* this is the master AWT structure (singleton object), glueing it all together
*/
class EventQueue;
typedef struct _Toolkit {
/* !!!
HDC display;
*/
char *buf;
unsigned int nBuf;
BCursor * cursors[14];
DecoInset frameInsets;
DecoInset dialogInsets;
KWnd **windows;
int nWindows;
KWnd *lastWnd;
BWindow *lastNativeWnd;
jobject jEvt;
EventQueue *eventQueue;
/* !!!
int dspTid;
HWND wakeUp;
*/
} Toolkit;
/*******************************************************************************
* font struct
*/
/* !!!
typedef struct _Font {
HFONT fnt;
TEXTMETRIC fm;
} Font;
**/
typedef BFont Font;
/*******************************************************************************
* global data def/decl
*/
#ifdef MAIN
Toolkit XTk;
Toolkit *X = &XTk;
jclass Tlk;
JNIEnv *JniEnv;
#else
extern Toolkit *X;
extern jclass Tlk;
extern JNIEnv *JniEnv;
#endif
/*****************************************************************************************
* heap wrapper macros
*/
#undef malloc
#undef calloc
#undef free
static inline void* _awt_malloc_wrapper ( size_t size )
{
void *adr = KMALLOC( size);
DBG( AWT_MEM, ("malloc: %ld -> %p\n", size, adr));
return adr;
}
static inline void* _awt_calloc_wrapper ( int n, size_t size )
{
void *adr = KCALLOC( n, size);
DBG( AWT_MEM, ("calloc: %d,%ld -> %p\n", n, size, adr));
return adr;
}
/* !!! KFREE on non-lvalues does not support DEBUG
static inline void _awt_free_wrapper ( void* adr )
{
DBG( awt_mem, ("free: %p\n", adr));
KFREE( adr);
}
*/
#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);
*/
#define AWT_FREE(_adr) jfree(_adr) /* !!! to fix DEBUG problem in jmalloc.h */
static inline void* getBuffer ( Toolkit* X, unsigned int nBytes ) {
if ( nBytes > X->nBuf ) {
if ( X->buf )
AWT_FREE( X->buf);
X->buf = (TCHAR*)AWT_MALLOC( nBytes * sizeof(TCHAR));
X->nBuf = nBytes;
}
return X->buf;
}
static inline char* java2CString ( JNIEnv *env, Toolkit* X, jstring jstr ) {
jboolean isCopy;
register unsigned i;
unsigned n = env->GetStringLength( jstr);
const jchar *jc = env->GetStringChars( jstr, &isCopy);
char *c;
if ( n >= X->nBuf ) {
if ( X->buf )
AWT_FREE( X->buf);
X->buf = (TCHAR*) AWT_MALLOC( n+1);
X->nBuf = n+1;
}
for ( i=0, c=(char*)X->buf; i<n; i++ ) *c++ = (char) jc[i];
*c = 0;
env->ReleaseStringChars( jstr, jc);
return (char*)X->buf;
}
static inline char* jbyte2CString ( Toolkit* X, jbyte* jb, int len ) {
register int i;
getBuffer( X, len+1);
for ( i=0; i<len; i++ ) {
X->buf[i] = (TCHAR) jb[i];
}
X->buf[i] = 0;
return (X->buf);
}
static inline char* jchar2CString ( Toolkit* X, jchar* jc, int len ) {
register int i;
getBuffer( X, len+1);
for ( i=0; i<len; i++ ) {
X->buf[i] = (TCHAR) jc[i];
}
X->buf[i] = 0;
return (X->buf);
}
#if REMOVE_WHEN_READY
//---------------------------------------------------
static inline TCHAR* java2WinString ( JNIEnv *env, Toolkit* X, jstring jstr ) {
jboolean isCopy;
UINT i, n;
const jchar *jc;
if ( ! jstr) {
X->buf[0] = 0;
return X->buf;
}
n = env->GetStringLength( jstr);
jc = env->GetStringChars( jstr, &isCopy);
getBuffer( X, n+1);
for ( i=0; i<n; i++ ) X->buf[i] = (TCHAR) jc[i];
X->buf[i] = 0;
env->ReleaseStringChars( jstr, jc);
return X->buf;
}
static inline TCHAR* jbyte2WinString ( Toolkit* X, jbyte* jb, int len ) {
register int i;
getBuffer( X, len+1);
for ( i=0; i<len; i++ ) {
X->buf[i] = (TCHAR) jb[i];
}
X->buf[i] = 0;
return (X->buf);
}
//---------------------------------------------------
#endif
static inline char* CString2UTF(Toolkit* X, TCHAR* str, int len) {
#if !defined(_UNICODE)
return (str);
#else
register int i;
char* buf;
getBuffer(X, len+1);
buf = (char*)X->buf;
for (i = 0; i < len; i++) {
buf[i] = (char)str[i];
}
buf[i] = 0;
return (buf);
#endif
}
static inline BCursor * getCursor ( jint jCursor )
{
UNIMPLEMENTED((
if (jCursor == 2) {
return B_CURSOR_I_BEAM; /* 2: TEXT_CURSOR */
} else {
return B_CURSOR_SYSTEM_DEFAULT;
}
));
return NULL;
}
#if 0
/* !!! DO IT */
static inline KWnd* getWnd ( HWND hwnd )
{
if ( hwnd != X->lastHwnd ){
X->lastWnd = (KWnd*)GetWindowLong( hwnd, GWL_USERDATA);
X->lastHwnd = hwnd;
}
return X->lastWnd;
}
static inline void setWnd ( HWND hwnd, KWnd* wnd )
{
X->lastWnd = wnd;
X->lastHwnd = hwnd;
SetWindowLong( hwnd, GWL_USERDATA, (long)wnd);
}
#endif
extern "C" {
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,_a) (_a<<24 | _r<<16 | _g<<8 | _b) /* Java RGB color + alpha */
#define NRGB(_r,_g,_b,_a) (_a<<24 | _b<<16 | _g<<8 | _r) /* BeOS RGB color + alpha */
#define GetAValue(_rgb) ((_rgb & 0xff000000) >> 24)
#define GetRValue(_rgb) ((_rgb & 0xff0000) >> 16)
#define GetGValue(_rgb) ((_rgb & 0x00ff00) >> 8)
#define GetBValue(_rgb) (_rgb & 0x0000ff)
#define RGBCAST(_jint) (*(rgb_color *)&_jint)
static inline void
rgbValues ( Toolkit* X, unsigned long pixel, int* r, int* g, int* b )
{
*r = GetRValue( pixel);
*g = GetGValue( pixel);
*b = GetBValue( pixel);
}
static inline rgb_color
ColorJ2N(int jrgb) {
rgb_color nrgb = { GetRValue( jrgb), GetGValue( jrgb), GetBValue( jrgb), GetAValue( jrgb) };
return ( nrgb);
}
static inline int
ColorN2J(rgb_color nrgb) {
// !!! ALPHA IS NOT PRESERVED
return ( JRGB( nrgb.red, nrgb.green, nrgb.blue, nrgb.alpha ));
}
/* !!! where is it used ?
static inline int
ColorN(int nrgb) {
return (nrgb);
}
*/
/*****************************************************************************************
* image functions
*/
Image* createImage ( int width, int height);
Image* readImage( BPositionIO * stream);
void createMaskImage( Toolkit* X, Image* img);
void createClrImage ( Toolkit* X, Image* img);
void freeImage( Toolkit* X, Image* img);
/*****************************************************************************************
* clipboard functions
*/
jobject selectionClear ( JNIEnv* env, Toolkit* X );
jobject selectionRequest ( JNIEnv* env, Toolkit* X );
/*****************************************************************************************
* file io wrapper macros (for image production)
*/
#define AWT_OPEN(_file) open(_file, O_RDONLY|O_BINARY)
#define AWT_REWIND(_fd) lseek(_fd, 0, SEEK_SET)
#define AWT_SETPOS(_fd,_off) lseek(_fd, _off, SEEK_CUR)
#define AWT_READ(_fd,_buf,_count) read(_fd,_buf,_count)
#define AWT_CLOSE(_fd) close(_fd)
#endif