3
#include <X11/keysym.h>
7
#include <tkPlatDecls.h>
9
#include <X11/cursorfont.h>
11
extern Tcl_Interp *xcinterp;
12
extern Clientdata areastruct;
13
extern char* TkKeysymToString(KeySym ks);
15
static void unimplemented(const char *str)
17
printf(">>>>>>>>> Unimplemented: %s\n", str);
20
typedef struct font_item {
23
struct font_item *next;
25
static struct font_item *font_map = NULL;
27
static void add_tkfont(Tk_Font tkfont, Font fid)
29
struct font_item *item = (struct font_item*)malloc(sizeof(struct font_item));
31
item->next = font_map;
33
item->tkfont = tkfont;
37
static Tk_Font get_tkfont(Font fid)
39
struct font_item *item = font_map;
41
while (item != NULL) {
46
fprintf(stderr, "Font not found: ID=%d\n", fid);
51
int XDrawPoint(Display *dpy, Drawable d, GC gc, int x, int y)
59
SetPixelV(hdc, x, y, gc->foreground);
63
/* This is pretty slow when called a lot
64
hdc = CreateCompatibleDC(NULL);
65
SelectObject(hdc, hwnd);
66
SetPixelV(hdc, x, y, gc->foreground);
74
int XClearArea(Display *dpy, Window w, int x, int y, unsigned int width, unsigned int height, Bool exposures)
83
oldROP = SetROP2(hdc, R2_COPYPEN);
84
GetClientRect(hnd, &r);
85
if (width != 0 || height != 0) {
90
FillRect(hdc, &r, (HBRUSH)(COLOR_WINDOW+1));
97
Pixmap XCreatePixmap(Display *dpy, Drawable d, unsigned int width, unsigned int height, unsigned int depth)
99
return Tk_GetPixmap(dpy, d, width, height, depth);
102
int XLookupString(XKeyEvent *event, char *buf, int buflen, KeySym *keysym, XComposeStatus *status)
105
printf("code : %04x\n", event->keycode);
106
printf("state: %04x\n", event->state);
108
switch (event->keycode) {
119
*keysym = XK_KP_0 + (event->keycode - VK_NUMPAD0);
120
event->state |= ShiftMask;
123
*keysym = XKeycodeToKeysym(NULL, event->keycode, event->state);
129
Bool XCheckWindowEvent(Display *dpy, Window w, long event_mask, XEvent *event)
131
unimplemented("XCheckWindowEvent");
135
int XTextWidth(XFontStruct *font, char *string, int len)
137
Tk_Font tkfont = get_tkfont(font->fid);
138
return Tk_TextWidth(tkfont, string, len);
141
int XDrawString(Display *dpy, Drawable d, GC gc, int x, int y, char *string, int len)
143
Tk_Font tkfont = get_tkfont(gc->font);
144
Tk_DrawChars(dpy, d, gc, tkfont, string, len, x, y);
148
int XFreePixmap(Display *dpy, Pixmap pix)
150
Tk_FreePixmap(dpy, pix);
155
int XPutImage(Display *dpy, Drawable d, GC gc, XImage *img, int src_x, int src_y, int dest_x, int dest_y, unsigned int width, unsigned int height)
157
unimplemented("XPutImage");
162
int XSync(Display *dpy, Bool discard)
164
unimplemented("XSync");
168
int XFlush(Display *dpy)
170
unimplemented("XFlush");
175
Cursor XCreateFontCursor(Display *dpy, unsigned int shape)
177
Tk_Window win = Tk_MainWindow(xcinterp);
180
case XC_xterm: return (Cursor)Tk_GetCursor(xcinterp, win, "xterm");
181
case XC_watch: return (Cursor)Tk_GetCursor(xcinterp, win, "watch");
182
default: return (Cursor)NULL;
187
void XDefineCursor_TkW32(Display *dpy, Window w, Cursor c)
189
Tk_DefineCursor(Tk_IdToWindow(dpy, w), (Tk_Cursor)c);
192
static u_char reverse_byte(u_char c)
197
for (i=(sizeof(char)*8-1); i>=0; i--, c>>=1)
202
static void compute_cursor_src_mask(u_char *src, u_char *mask)
204
u_char pixsrc = *src, pixmask = *mask;
205
*src = ~(reverse_byte(pixmask));
206
*mask = reverse_byte(~pixsrc & pixmask);
209
typedef struct tkw32cursor {
215
Tcl_HashTable *otherTable;
216
Tcl_HashEntry *hashPtr;
217
Tcl_HashEntry *idHashPtr;
218
struct tkcursor *nextPtr;
225
Cursor Tk_GetCursorFromData_TkW32(Tcl_Interp *interp, Tk_Window w, u_char *src, u_char *mask, int width, int height, int xhot, int yhot, Tk_Uid fg, Tk_Uid bg)
229
wcursor = (w32cursor*)ckalloc(sizeof(w32cursor));
230
wcursor->info.cursor = (Tk_Cursor)wcursor;
231
wcursor->winCursor = NULL;
234
wcursor->winCursor = CreateCursor(Tk_GetHINSTANCE(), xhot, yhot, width, height, src, mask);
235
if (wcursor->winCursor == NULL) {
236
ckfree((char*)wcursor);
240
return (Cursor)wcursor;
243
Cursor CreateW32Cursor(Tcl_Interp *interp, Tk_Window w, u_char *src, u_char *mask, int width, int height, int xhot, int yhot, Tk_Uid fg, Tk_Uid bg)
245
u_char *new_src, *new_mask;
246
int nb = (width-1)/(8*sizeof(char))+1;
247
int nb2 = (GetSystemMetrics(SM_CXCURSOR)-1)/(8*sizeof(char))+1, height2 = GetSystemMetrics(SM_CYCURSOR);
248
int i, j, idx1 = 0, idx2 = 0;
251
new_src = (u_char*)malloc(sizeof(char)*nb2*height2);
252
new_mask = (u_char*)malloc(sizeof(char)*nb2*height2);
254
for (j=0; j<height; j++) {
255
for (i=0; i<nb; i++, idx1++, idx2++) {
256
new_src[idx2] = src[idx1];
257
new_mask[idx2] = mask[idx1];
258
compute_cursor_src_mask(&new_src[idx2], &new_mask[idx2]);
259
/*printf("%02x ", new_src[idx2]);*/
261
for (i=0; i<(nb2-nb); i++, idx2++) {
262
new_src[idx2] = 0xff;
263
new_mask[idx2] = 0x00;
264
/*printf("%02x ", new_src[idx2]);*/
268
for (j=0; j<(height2-height); j++) {
269
for (i=0; i<nb2; i++, idx2++) {
270
new_src[idx2] = 0xff;
271
new_mask[idx2] = 0x00;
272
/*printf("%02x ", new_src[idx2]);*/
278
cursor = Tk_GetCursorFromData_TkW32(interp, w, new_src, new_mask, nb2*8, height2, xhot, yhot, fg, bg);
286
int XRecolorCursor(Display *dpy, Cursor cursor, XColor *foreground, XColor *background)
288
unimplemented("XRecolorCursor");
292
Status XAllocNamedColor(Display *dpy, Colormap cm, char* cname, XColor *screen_return, XColor *exact_return)
294
XColor *c = Tk_GetColor(xcinterp, areastruct.area, cname);
297
screen_return->pixel = c->pixel;
298
exact_return->pixel = c->pixel;
304
Status XLookupColor_TkW32(Display *dpy, Colormap cmap, const char *name, XColor *cvcolor, XColor *cvexact)
306
if (XParseColor(dpy, cmap, name, cvcolor)) {
314
int XQueryColors_TkW32(Display *dpy, Colormap cmap, XColor *colors, int ncolors)
318
for (i=0; i<ncolors; i++) {
319
int pixel = colors[i].pixel;
320
colors[i].red = ((pixel&0x000000ff)<<8)|(pixel&0x000000ff);
321
colors[i].green = (pixel&0x0000ff00)|((pixel&0x0000ff00)>>8);
322
colors[i].blue = ((pixel&0x00ff0000)>>8)|((pixel&0x00ff0000)>>16);
328
Bool XQueryPointer_TkW32(Display *dpy, Window w, Window *root_return, Window *child_return,
329
int *root_x, int *root_y, int *win_x, int *win_y, unsigned int *mask)
336
ScreenToClient(Tk_GetHWND(w), &p);
344
Colormap XCopyColormapAndFree(Display *dpy, Colormap cmap)
346
unimplemented("XCopyColormapAndFree");
350
char* XDisplayString(Display *dpy)
352
/*printf("XDisplayString\n");*/
353
return "localhost:0.0\n";
357
char* XKeysymToString_TkW32(KeySym ks)
359
return TkKeysymToString(ks);
362
XFontStruct* XLoadQueryFont(Display *dpy, char *fontname)
368
tkfont = Tk_GetFont(xcinterp, Tk_MainWindow(xcinterp), fontname);
371
fs = (XFontStruct*)malloc(sizeof(XFontStruct));
372
fs->fid = Tk_FontId(tkfont);
373
Tk_GetFontMetrics(tkfont, &tkfm);
374
fs->ascent = tkfm.ascent;
375
fs->descent = tkfm.descent;
376
add_tkfont(tkfont, fs->fid);
383
DIR* opendir(const char *name)
385
DIR *d = (DIR*)malloc(sizeof(DIR));
386
static char buffer[MAX_PATH];
388
strncpy(buffer, name, MAX_PATH);
389
strncat(buffer, "\\*", MAX_PATH);
390
d->hnd = FindFirstFile(buffer, &(d->fd));
391
if (d->hnd == INVALID_HANDLE_VALUE)
397
void closedir(DIR *d)
402
struct direct* readdir(DIR *d)
406
if (!FindNextFile(d->hnd, &(d->fd)))
409
d->d.d_name = d->fd.cFileName;