3 #include <X11/keysym.h>
7 #include <tkPlatDecls.h>
9 #include <X11/cursorfont.h>
11 extern Tcl_Interp
*xcinterp
;
12 extern XCWindowData
*areawin
;
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");
159 TkPutImage(NULL
, 0, dpy
, d
, gc
, img
, src_x
, src_y
, dest_x
, dest_y
,
165 // The following two functions may be defined as macros. . .
168 int XSync(Display
*dpy
, Bool discard
)
170 unimplemented("XSync");
176 int XFlush(Display
*dpy
)
178 unimplemented("XFlush");
184 Cursor
XCreateFontCursor(Display
*dpy
, unsigned int shape
)
186 Tk_Window win
= Tk_MainWindow(xcinterp
);
189 case XC_xterm
: return (Cursor
)Tk_GetCursor(xcinterp
, win
, "xterm");
190 case XC_watch
: return (Cursor
)Tk_GetCursor(xcinterp
, win
, "watch");
191 default: return (Cursor
)NULL
;
196 void XDefineCursor_TkW32(Display
*dpy
, Window w
, Cursor c
)
198 Tk_DefineCursor(Tk_IdToWindow(dpy
, w
), (Tk_Cursor
)c
);
201 static u_char
reverse_byte(u_char c
)
206 for (i
=(sizeof(char)*8-1); i
>=0; i
--, c
>>=1)
211 static void compute_cursor_src_mask(u_char
*src
, u_char
*mask
)
213 u_char pixsrc
= *src
, pixmask
= *mask
;
214 *src
= ~(reverse_byte(pixmask
));
215 *mask
= reverse_byte(~pixsrc
& pixmask
);
218 typedef struct tkw32cursor
{
224 Tcl_HashTable
*otherTable
;
225 Tcl_HashEntry
*hashPtr
;
226 Tcl_HashEntry
*idHashPtr
;
227 struct tkcursor
*nextPtr
;
234 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
)
238 wcursor
= (w32cursor
*)ckalloc(sizeof(w32cursor
));
239 wcursor
->info
.cursor
= (Tk_Cursor
)wcursor
;
240 wcursor
->winCursor
= NULL
;
243 wcursor
->winCursor
= CreateCursor(Tk_GetHINSTANCE(), xhot
, yhot
, width
, height
, src
, mask
);
244 if (wcursor
->winCursor
== NULL
) {
245 ckfree((char*)wcursor
);
249 return (Cursor
)wcursor
;
252 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
)
254 u_char
*new_src
, *new_mask
;
255 int nb
= (width
-1)/(8*sizeof(char))+1;
256 int nb2
= (GetSystemMetrics(SM_CXCURSOR
)-1)/(8*sizeof(char))+1, height2
= GetSystemMetrics(SM_CYCURSOR
);
257 int i
, j
, idx1
= 0, idx2
= 0;
260 new_src
= (u_char
*)malloc(sizeof(char)*nb2
*height2
);
261 new_mask
= (u_char
*)malloc(sizeof(char)*nb2
*height2
);
263 for (j
=0; j
<height
; j
++) {
264 for (i
=0; i
<nb
; i
++, idx1
++, idx2
++) {
265 new_src
[idx2
] = src
[idx1
];
266 new_mask
[idx2
] = mask
[idx1
];
267 compute_cursor_src_mask(&new_src
[idx2
], &new_mask
[idx2
]);
268 /*printf("%02x ", new_src[idx2]);*/
270 for (i
=0; i
<(nb2
-nb
); i
++, idx2
++) {
271 new_src
[idx2
] = 0xff;
272 new_mask
[idx2
] = 0x00;
273 /*printf("%02x ", new_src[idx2]);*/
277 for (j
=0; j
<(height2
-height
); j
++) {
278 for (i
=0; i
<nb2
; i
++, idx2
++) {
279 new_src
[idx2
] = 0xff;
280 new_mask
[idx2
] = 0x00;
281 /*printf("%02x ", new_src[idx2]);*/
287 cursor
= Tk_GetCursorFromData_TkW32(interp
, w
, new_src
, new_mask
, nb2
*8, height2
, xhot
, yhot
, fg
, bg
);
295 int XRecolorCursor(Display
*dpy
, Cursor cursor
, XColor
*foreground
, XColor
*background
)
297 unimplemented("XRecolorCursor");
301 Status
XAllocNamedColor(Display
*dpy
, Colormap cm
, char* cname
, XColor
*screen_return
, XColor
*exact_return
)
303 XColor
*c
= Tk_GetColor(xcinterp
, (areawin
? areawin
->area
: NULL
), cname
);
306 screen_return
->pixel
= c
->pixel
;
307 exact_return
->pixel
= c
->pixel
;
313 Status
XLookupColor_TkW32(Display
*dpy
, Colormap cmap
, const char *name
, XColor
*cvcolor
, XColor
*cvexact
)
315 if (XParseColor(dpy
, cmap
, name
, cvcolor
)) {
323 int XQueryColors_TkW32(Display
*dpy
, Colormap cmap
, XColor
*colors
, int ncolors
)
327 for (i
=0; i
<ncolors
; i
++) {
328 int pixel
= colors
[i
].pixel
;
329 colors
[i
].red
= ((pixel
&0x000000ff)<<8)|(pixel
&0x000000ff);
330 colors
[i
].green
= (pixel
&0x0000ff00)|((pixel
&0x0000ff00)>>8);
331 colors
[i
].blue
= ((pixel
&0x00ff0000)>>8)|((pixel
&0x00ff0000)>>16);
337 Bool
XQueryPointer_TkW32(Display
*dpy
, Window w
, Window
*root_return
, Window
*child_return
,
338 int *root_x
, int *root_y
, int *win_x
, int *win_y
, unsigned int *mask
)
345 ScreenToClient(Tk_GetHWND(w
), &p
);
353 Colormap
XCopyColormapAndFree(Display
*dpy
, Colormap cmap
)
355 unimplemented("XCopyColormapAndFree");
359 char* XDisplayString(Display
*dpy
)
361 /*printf("XDisplayString\n");*/
362 return "localhost:0.0\n";
366 char* XKeysymToString_TkW32(KeySym ks
)
368 return TkKeysymToString(ks
);
371 XFontStruct
* XLoadQueryFont(Display
*dpy
, char *fontname
)
377 tkfont
= Tk_GetFont(xcinterp
, Tk_MainWindow(xcinterp
), fontname
);
380 fs
= (XFontStruct
*)malloc(sizeof(XFontStruct
));
381 fs
->fid
= Tk_FontId(tkfont
);
382 Tk_GetFontMetrics(tkfont
, &tkfm
);
383 fs
->ascent
= tkfm
.ascent
;
384 fs
->descent
= tkfm
.descent
;
385 add_tkfont(tkfont
, fs
->fid
);
392 DIR* opendir(const char *name
)
394 DIR *d
= (DIR*)malloc(sizeof(DIR));
395 static char buffer
[MAX_PATH
];
397 strncpy(buffer
, name
, MAX_PATH
);
398 strncat(buffer
, "\\*", MAX_PATH
);
399 d
->hnd
= FindFirstFile(buffer
, &(d
->fd
));
400 if (d
->hnd
== INVALID_HANDLE_VALUE
)
406 void closedir(DIR *d
)
411 struct direct
* readdir(DIR *d
)
415 if (!FindNextFile(d
->hnd
, &(d
->fd
)))
418 d
->d
.d_name
= d
->fd
.cFileName
;