ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/W11/w32/xlib.c
Revision: 1.1
Committed: Mon Nov 24 17:28:08 2003 UTC (20 years, 7 months ago) by pcg
Content type: text/plain
Branch: MAIN
CVS Tags: rel-7_0, post_menubar_removal, rel-6_2, rel-6_3, rel-6_0, rel-6_1, rel-2_1_0, rel-5_5, rel-5_4, rel-5_7, rel-5_1, rel-5_0, rel-5_3, rel-5_2, rel-4_4, rel-4_6, rel-4_7, rel-5_9, rel-5_8, rel-4_2, rel-4_3, rel-3_7, rel-3_8, rel-3_5, rel-3_4, rel-3_3, rel-3_2, rel-2_8, rel-3_0, rel-4_0, rel-2_4, rel-2_5, rel-2_2, rel-2_3, rel-2_0, rel-4_1, rel-1-9, rel-1-3, rel-1-2, rxvt-2-0, rel-1_9, rel-3_6, rel-2_7, rel-4_8, rel-4_9
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 pcg 1.1 /*****************************************************************\
2    
3    
4     Library of X window functions which call Windows 32
5     equivalent functions.
6    
7     Some data structures are maintained by this code,
8     simulating the operation of an X server and window manager.
9    
10     Aug/Sep-92 xyz $$1 Created.
11     Oct-92 abc $$2 Added color stuff.
12    
13     \******************************************************************/
14    
15     #ifndef __XNT
16     #define __XNT
17    
18     #include <X11/Xlib.h>
19     #include <X11/Xatom.h>
20    
21     #include <stdio.h>
22     #include <math.h>
23     #include <string.h>
24     #include <fcntl.h>
25     #include "ntdef.h"
26    
27     /* Local Data */
28    
29     static void NT_set_GC_pen();
30     static void NT_set_GC_brush();
31     static HPEN NT_get_GC_pen();
32     static HBRUSH NT_get_GC_brush();
33     static HBRUSH NT_get_GC_bgbrush();
34    
35     void NT_set_rop();
36     double NT_deg64_to_rad(int a);
37    
38     /*----------------------------------------------------------------*\
39     | FUNCTIONS TO MAINTAIN AN INTERNAL LIST OF WINDOWS AND THEIR |
40     | ATTRIBUTES - AS WOULD BE MAINTAINED IN THE X SERVER. |
41     \*----------------------------------------------------------------*/
42    
43     /* Structure to hold pen and brush info in GC ext_data field */
44    
45     typedef struct NTGC_
46     {
47     HPEN pen;
48     HBRUSH brush;
49     HBRUSH bgbrush;
50     } NTGC;
51    
52     HDC
53     cjh_get_dc(NT_window *window)
54     {
55     /* pixmaps have to do SelectObject() on their dc's */
56     if (window->hDC == INVALID_HANDLE)
57     if (window->w == INVALID_HANDLE)
58     {
59     window->hDC= CreateDC("DISPLAY", NULL, NULL, NULL);
60     }
61     else
62     window->hDC=GetDC(window->w);
63     return window->hDC;
64     }
65    
66     int
67     cjh_rel_dc(NT_window *window,HDC dc)
68     {
69     return TRUE;
70     /* return ReleaseDC(window, dc); */
71     }
72    
73     HDC
74     drawableGetDC(Drawable drawable)
75     {
76     cjh_get_dc((NT_window *)drawable);
77     }
78    
79     int
80     drawableRelDC(Drawable drawable, HDC hDC)
81     {
82     cjh_rel_dc((NT_window *)drawable, hDC);
83     }
84    
85    
86    
87     /*****************************************************************\
88    
89     Function: XOpenDisplay
90     Inputs: Display name
91    
92     Comments: Fills out a Display structure and a Visual and Screen.
93     Hopefully all the X macros should work with this
94     structure. Note that the default visual is for a
95     True colour screen (24bits).
96     \*****************************************************************/
97     Display *
98     XOpenDisplay (name)
99     const char *name;
100     {
101     static char vstring[]="NT Xlibemu",
102     *vs,*dn;
103    
104     Display *d = NULL;
105     Screen *scrd;
106     static Depth dlist[1];
107     static Visual vlist[1];
108     Colormap cmap;
109     RECT rect;
110     int depth;
111     HDC rootDC = CreateDC("DISPLAY",NULL,NULL,NULL);
112    
113     depth = GetDeviceCaps(rootDC, BITSPIXEL);
114    
115     xtrace("XOpenDisplay\n");
116    
117     initQ();
118    
119     dlist[0].depth=depth;
120     dlist[0].nvisuals=1;
121     dlist[0].visuals=vlist;
122     vlist[0].ext_data=NULL;
123     vlist[0].visualid=0;
124     vlist[0].class=PseudoColor;
125     vlist[0].bits_per_rgb=8;
126     vlist[0].map_entries=256;
127     vlist[0].red_mask=255;
128     vlist[0].green_mask=255<<8;
129     vlist[0].blue_mask=255<<16;
130     scrd=(Screen *) allocateMemory (sizeof (Screen));
131     (NT_window*)(scrd->root)= NT_new_window();
132     ((NT_window*)(scrd->root))->w=GetDesktopWindow();
133     ((NT_window*)(scrd->root))->parent=0;
134     GetWindowRect(GetDesktopWindow(),&rect);
135     scrd->width=rect.right-rect.left;
136     scrd->height=rect.bottom-rect.top;
137     scrd->mwidth=260;
138     scrd->mheight=190;
139     scrd->ndepths=1;
140     scrd->depths=dlist;
141     scrd->root_depth=depth;
142     scrd->root_visual=vlist;
143     scrd->default_gc=NULL;
144     scrd->cmap=cmap;
145     scrd->white_pixel=0xffffff;
146     scrd->black_pixel=0;
147    
148     d=(Display *) allocateMemory (sizeof (Display));
149     scrd->display=d;
150     vs=(char *) allocateMemory (sizeof (char)*strlen (vstring)+1);
151     dn=(char *) allocateMemory (sizeof (char)*strlen (name)+1);
152     strcpy (vs,vstring);
153     strcpy (dn,name);
154     d->ext_data=NULL;
155     d->fd=0;
156     d->proto_major_version=11;
157     d->proto_minor_version=4;
158     d->vendor=vs;
159     d->release=4;
160     d->display_name=dn;
161     d->nscreens=1;
162     d->screens=scrd;
163     d->max_keycode=255;
164    
165     return (d);
166     }
167    
168    
169     int
170     XCloseDisplay(Display *display)
171     {
172     NT_window *wanderer;
173    
174     xtrace("XCloseDisplay\n");
175     /* Do something ? */
176     /* Must GlobalDelete all atoms/properties leftover */
177     return 0;
178     }
179    
180     char *
181     XDisplayString(Display *display)
182     {
183     return (display->display_name);
184     }
185    
186    
187     int
188     XFlush(Display *display)
189     {
190     xtrace("XFlush\n");
191     return 0;
192     }
193    
194    
195     int
196     XSync(display,discard)
197     Display *display;
198     int discard;
199     {
200     /* Do nothing here either */
201     return 0;
202     }
203    
204     /*****************************************************************\
205    
206     Function: XGetVisualInfo
207     Inputs: display, info mask, template, number of matches.
208     Returned: List of XVisualInfo structures, one for each matching
209     Visual.
210    
211     Comments: Behaves like X routine, but there is only ever one
212     Visual, so the returned list is never longer than one.
213    
214     \*****************************************************************/
215     XVisualInfo *
216     XGetVisualInfo(display,vinm,vint,n)
217     Display *display;
218     long vinm;
219     XVisualInfo *vint;
220     int *n;
221     {
222     static XVisualInfo xvi;
223     int status=1;
224     xtrace("XGetVisualInfo\n");
225    
226     if ((vinm&VisualIDMask|vinm==VisualAllMask)&&
227     vint->visualid!=display->screens->root_visual->visualid)
228     status=0;
229     if ((vinm&VisualScreenMask|vinm==VisualAllMask)&&
230     vint->screen!=0)
231     status=0;
232     if ((vinm&VisualDepthMask|vinm==VisualAllMask)&&
233     vint->depth!=24)
234     status=0;
235     if ((vinm&VisualClassMask|vinm==VisualAllMask)&&
236     vint->class!=display->screens->root_visual->class)
237     status=0;
238     if ((vinm&VisualRedMaskMask|vinm==VisualAllMask)&&
239     vint->red_mask!=display->screens->root_visual->red_mask)
240     status=0;
241     if ((vinm&VisualGreenMaskMask|vinm==VisualAllMask)&&
242     vint->green_mask!=display->screens->root_visual->green_mask)
243     status=0;
244     if ((vinm&VisualBlueMaskMask|vinm==VisualAllMask)&&
245     vint->blue_mask!=display->screens->root_visual->blue_mask)
246     status=0;
247     if ((vinm&VisualColormapSizeMask|vinm==VisualAllMask)&&
248     vint->colormap_size!=display->screens->root_visual->map_entries)
249     status=0;
250     if ((vinm&VisualBitsPerRGBMask|vinm==VisualAllMask)&&
251     vint->bits_per_rgb!=display->screens->root_visual->bits_per_rgb)
252     status=0;
253     if (status==1)
254     {
255     xvi.visualid=display->screens->root_visual->visualid;
256     xvi.screen=0;
257     xvi.depth=display->screens->root_visual->bits_per_rgb;
258     xvi.class=display->screens->root_visual->class;
259     xvi.red_mask=display->screens->root_visual->red_mask;
260     xvi.green_mask=display->screens->root_visual->green_mask;
261     xvi.blue_mask=display->screens->root_visual->blue_mask;
262     xvi.colormap_size=display->screens->root_visual->map_entries;
263     xvi.bits_per_rgb=display->screens->root_visual->bits_per_rgb;
264     xvi.visual=display->screens->root_visual;
265     *n=1;
266     return (&xvi);
267     }
268     *n=0;
269     return (&xvi);
270     }
271    
272     StatusDef XMatchVisualInfo(
273     Display* display,
274     int screen,
275     int depth,
276     int class,
277     XVisualInfo* vinfo_return)
278     {
279     int status=0;
280     xtrace("XMatchVisualInfo\n");
281     return status;
282     }
283    
284     /*****************************************************************\
285    
286     Function: XClearWindow
287     Inputs: display, window
288    
289     Comments: As mentioned, the Window structure is not the one windows
290     recognises. The background colour for the window is
291     stored in this structure.
292    
293     The sequence of GetDC, CreateBrush/Pen, SelectObject,
294     <draw stuff>, DeleteObject, ReleaseDC occurs in all the
295     drawing functions.
296    
297     \*****************************************************************/
298     int
299     XClearWindow(display, w)
300     Display *display;
301     Window w;
302     {
303     RECT rRect;
304     HBRUSH hbrush;
305     HDC hDC;
306     HANDLE oldObj;
307     int oldROP;
308     NT_window *window = (NT_window *)w;
309     xtrace("XClearWindow\n");
310    
311     if (VALID_WINDOW(window)) {
312     rRect.left= rRect.right=rRect.bottom=rRect.top =0;
313    
314     hDC = cjh_get_dc(window);
315     oldROP = SetROP2(hDC,R2_COPYPEN);
316     hbrush = window->bg;
317     oldObj = SelectObject(hDC, hbrush);
318     GetClientRect(window->w, &rRect);
319     FillRect(hDC, &rRect, hbrush);
320     SelectObject(hDC, oldObj);
321     // DeleteObject(hbrush);
322     SetROP2(hDC,oldROP);
323     cjh_rel_dc(window,hDC);
324     }
325    
326     return 0;
327     }
328    
329     /*****************************************************************\
330    
331     Function: XCreateSimpleWindow
332     Inputs: display, parent window, geometry, border width,
333     border colour, background colour.
334     Returned: Window ID
335    
336     Comments: The first time a window is made by the application, it
337     has to be registered.
338     To simulate the action of a window manager, the toplevel
339     client window is reparented and a frame window is created.
340     A MapNotify event is sent to the new client.
341     Note that child windows are created in the manner of the
342     default X behaviour, ie. each is clipped individually.
343    
344    
345     NOTE: This routine has now changed. As part of our role as
346     Window manager, we now defer creation of the windows until
347     they are mapped. The fact that a window has been created
348     and not mapped is flagged to other routines by setting the
349     w element of the structure to -1.
350     WE STILL CREATE THE Window STRUCTURES.
351     (SEE XMapWindow)
352    
353     \*****************************************************************/
354    
355     Window
356     XCreateSimpleWindow(display, parent,x, y, w, h, brd, brd_col, bg)
357     Display *display;
358     Window parent;
359     int x, y;
360     unsigned int brd,w,h;
361     unsigned long bg, brd_col;
362     {
363     NT_window *canvas;
364     xtrace("XCreateSimpleWindow\n");
365    
366     canvas = NT_new_window();
367    
368     canvas->x = x;
369     canvas->y = y;
370     canvas->wdth = w;
371     canvas->hght = h;
372     NT_add_child((NT_window *)parent,canvas);
373     canvas->bg=CreateSolidBrush (CNUMTORGB(bg));
374     canvas->parent=(NT_window *)parent;
375     canvas->title_text = NULL;
376     if (canvas->parent->w == GetDesktopWindow())
377     {
378     if (x==0 && y==0)
379     {
380     canvas->x = -1;
381     canvas->y = -1;
382     }
383     canvas->top_flag = TRUE;
384     }
385     else
386     canvas->top_flag = 0;
387     return ((Window)canvas);
388     }
389    
390    
391     /*****************************************************************\
392    
393     Function: XCreateWindow
394     Inputs: display, parent window, geometry, border width, depth,
395     class, visual, attributes mask, attributes structure
396     Returned: Window ID
397    
398     Comments: Simply calls XCreateSimpleWindow. Some of the arguments
399     are ignored :-).
400    
401     \*****************************************************************/
402    
403     Window
404     XCreateWindow(display,parent,x,y,width,height,bw,depth,class,visual,
405     valuemask,attr)
406     Display *display;
407     Window parent;
408     int x,y;
409     unsigned int width,height,bw;
410     int depth;
411     unsigned int class;
412     Visual *visual;
413     unsigned long valuemask;
414     XSetWindowAttributes *attr;
415     {
416     xtrace("XCreateWindow\n");
417     return (XCreateSimpleWindow(display,parent,x,y,width,height,bw,
418     attr->border_pixel,attr->background_pixel));
419     }
420    
421    
422     /*****************************************************************\
423    
424     Function: XDestroyWindow
425     Inputs: Display, window to be destroyed.
426    
427     Comments: Removes a window from the server.
428    
429     \*****************************************************************/
430     int
431     XDestroyWindow(display,w)
432     Display *display;
433     Window w;
434     {
435     NT_window *ntw = (NT_window *)w;
436     xtrace("XDestroyWindow\n");
437     if (ntw->hDC != INVALID_HANDLE)
438     {
439     ReleaseDC(ntw->w,ntw->hDC);
440     ntw->hDC = INVALID_HANDLE;
441     }
442    
443     /*DestroyWindow(w->w);*/
444     NT_delete_window(ntw); /* Remove window from data structure */
445     return 0;
446     }
447    
448    
449     /*****************************************************************\
450    
451     Function: XGetGeometry
452     Inputs: display, window
453     Returned: root window, screen depth, geometry, border width
454    
455     Comments: fetches information from the windows kernel and our
456     display structure.
457    
458     \*****************************************************************/
459    
460     StatusDef
461     XGetGeometry(display,w,root,x,y,width,height,bw,depth)
462     Display *display;
463     Drawable w;
464     Window *root;
465     int *x,*y;
466     unsigned int *width,*height;
467     unsigned int *bw,*depth;
468     {
469     NT_window *ntw = (NT_window *)w;
470     RECT r;
471     xtrace("XGetGeometry\n");
472    
473     *root=display->screens[0].root;
474     *depth=24;
475    
476     GetWindowRect(ntw->w,&r);
477     *x=r.left;
478     *y=r.top;
479     GetClientRect(ntw->w,&r);
480     *width=r.right-r.left;
481     if (*width<ntw->minx)
482     *width=ntw->minx;
483     *height=r.bottom-r.top;
484     if (*height<ntw->miny)
485     *height=ntw->miny;
486     *bw=(*width-(r.right-r.left))/2;
487    
488     return 0;
489     }
490    
491    
492     /*****************************************************************\
493    
494     Function: XGetWindowAttributes
495     Inputs: display, window, attributes
496     Returned: 1 = ok.
497    
498     Comments: Fills out attributes structure.
499    
500     \*****************************************************************/
501    
502     StatusDef
503     XGetWindowAttributes(display,w,wattr)
504     Display *display;
505     Window w;
506     XWindowAttributes *wattr;
507     {
508     xtrace("XGetWindowAttributes\n");
509     XGetGeometry(display,w,&wattr->root,&wattr->x,&wattr->y,&wattr->width,
510     &wattr->height,&wattr->border_width,&wattr->depth);
511     wattr->class=InputOutput;
512     wattr->bit_gravity=StaticGravity;
513     wattr->win_gravity=CenterGravity;
514     wattr->backing_store=NotUseful;
515     wattr->backing_planes=0;
516     wattr->backing_pixel=0;
517     wattr->save_under=0;
518     wattr->colormap=None;
519     wattr->map_installed=TRUE;
520     wattr->map_state=IsViewable;
521     wattr->override_redirect=FALSE;
522     wattr->screen=display->screens;
523     return (1);
524     }
525    
526    
527    
528     int
529     XSelectInput(display, window, mask)
530     Display *display;
531     Window window;
532     long mask;
533     {
534     NT_window *ntw = (NT_window *)window;
535     xtrace("XSelectInput\n");
536     ntw->mask=mask;
537     return 0;
538     }
539    
540     void NT_dispError(char *msg)
541     {
542     LPVOID lpMsgBuf=NULL;
543     FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,NULL,
544     GetLastError(),
545     MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
546     (LPTSTR) &lpMsgBuf,
547     0,
548     NULL);
549     MessageBox( NULL, lpMsgBuf, msg, MB_OK|MB_ICONINFORMATION );
550     LocalFree( lpMsgBuf );
551     }
552    
553    
554     /*****************************************************************\
555    
556     Function: XMapWindow
557     Inputs: display, window to be mapped
558    
559     Comments: If the specified window is not already mapped, this
560     routine calls the Windows function which displays it.
561     Again, frames have to be mapped as well as clients.
562    
563     \*****************************************************************/
564     int
565     XMapWindow(display, window)
566     Display *display;
567     Window window;
568     {
569     NT_window *ntw = (NT_window *)window;
570     RECT rect;
571     unsigned char *hints;
572     Atom property;
573     Atom ret_type;
574     int ret_format;
575     DWORD frame_style;
576     long ret_nitems;
577     long ret_after;
578     HDC hDC;
579     char *title = "";
580     xtrace("XMapWindow\n");
581    
582     if (ntw->w == INVALID_HANDLE)
583     {
584     frame_style = WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
585     if (ntw->top_flag)
586     {
587     /* frame_style = WS_CLIPCHILDREN;
588     frame_style |= WS_BORDER;
589     frame_style |= WS_THICKFRAME;
590     frame_style |= WS_CAPTION;
591     frame_style |= WS_POPUP;
592     frame_style |= WS_SYSMENU;
593     frame_style |= WS_MINIMIZEBOX;
594     frame_style |= WS_MAXIMIZEBOX;
595     */
596     frame_style = WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN;
597     ntw->hght += GetSystemMetrics(SM_CYSIZE)+(GetSystemMetrics(SM_CYBORDER)+GetSystemMetrics(SM_CYFRAME))*2;
598     ntw->wdth += (GetSystemMetrics(SM_CXBORDER) + GetSystemMetrics(SM_CXFRAME))*2;
599     title = ntw->title_text;
600     if (ntw->x == -1 && ntw->y == -1)
601     {
602     ntw->x = CW_USEDEFAULT;
603     ntw->y = CW_USEDEFAULT;
604     }
605     }
606     else if (ntw->x == -1 && ntw->y == -1)
607     {
608     GetClientRect(ntw->parent->w,&rect);
609     ntw->x = rect.left;
610     ntw->y = rect.top;
611     ntw->wdth = rect.right-rect.left;
612     ntw->hght = rect.bottom - rect.top;
613     }
614    
615     ntw->hDC = INVALID_HANDLE;
616    
617     if (ntw->parent->w == INVALID_HANDLE)
618     {
619     XMapWindow(display, (Window)ntw->parent);
620     }
621     ntw->w = NT_create_window(title,frame_style,
622     ntw->x,ntw->y,ntw->wdth,ntw->hght,
623     ntw->parent->w);
624     if (ntw->w==NULL) NT_dispError("create window1");
625     hDC = cjh_get_dc(ntw);
626     PostMessage(ntw->w,USR_MapNotify,0,0);
627     }
628     if (IsWindowVisible(ntw->w)==0)
629     {
630     ShowWindow(ntw->w, SW_SHOW);
631     PostMessage(ntw->w,USR_MapNotify,0,0);
632     }
633     UpdateWindow(ntw->w);
634     return 0;
635     }
636    
637     int
638     XIconifyWindow(Display *display,
639     Window w,
640     int screen_number)
641     {
642     xtrace("XIconifyWindow\n");
643     return 0;
644     }
645    
646    
647     /*****************************************************************\
648    
649     Function: XCreateGC
650     Inputs: display, window, mask of setup values, setup values.
651     Returned: GC pointer.
652    
653     Comments: Fills out a GC structure with the X defaults unless
654     the caller specifies otherwise.
655    
656     \*****************************************************************/
657    
658     GC
659     XCreateGC(display, window, mask, gc_values)
660     Display *display;
661     Drawable window;
662     unsigned long mask;
663     XGCValues *gc_values;
664     {
665     GC local_gc;
666     int size;
667     char *ptr;
668     xtrace("XCreateGC\n");
669    
670     size = sizeof(GC);
671    
672     ptr = (char *)allocateMemory((size_t)1000);
673     local_gc = (GC)ptr;
674     local_gc->ext_data = NULL;
675     local_gc->gid=(GContext) window;
676     local_gc->rects=FALSE;
677     local_gc->dashes=FALSE;
678    
679     if (mask&GCArcMode)
680     local_gc->values.arc_mode=gc_values->arc_mode;
681     else
682     local_gc->values.arc_mode=ArcPieSlice;
683     if (mask&GCBackground)
684     local_gc->values.background=gc_values->background;
685     else
686     local_gc->values.background=display->screens->white_pixel;
687     if (mask&GCCapStyle)
688     local_gc->values.cap_style=gc_values->cap_style;
689     else
690     local_gc->values.cap_style=CapButt;
691     if (mask&GCClipMask)
692     local_gc->values.clip_mask=gc_values->clip_mask;
693     else
694     local_gc->values.clip_mask=None;
695     if (mask&GCClipXOrigin)
696     local_gc->values.clip_x_origin=gc_values->clip_x_origin;
697     else
698     local_gc->values.clip_x_origin=0;
699     if (mask&GCClipYOrigin)
700     local_gc->values.clip_y_origin=gc_values->clip_y_origin;
701     else
702     local_gc->values.clip_y_origin=0;
703     if (mask&GCDashList)
704     local_gc->values.dashes=gc_values->dashes;
705     else
706     local_gc->values.dashes=4;
707     if (mask&GCDashOffset)
708     local_gc->values.dash_offset=gc_values->dash_offset;
709     else
710     local_gc->values.dash_offset=0;
711     if (mask&GCFillRule)
712     local_gc->values.fill_rule=gc_values->fill_rule;
713     else
714     local_gc->values.fill_rule=EvenOddRule;
715     if (mask&GCFillStyle)
716     local_gc->values.fill_style=gc_values->fill_style;
717     else
718     local_gc->values.fill_style=FillSolid;
719     if (mask&GCFont)
720     local_gc->values.font=gc_values->font;
721     else
722     local_gc->values.font= 999;/*"fixed";*/
723     if (mask&GCForeground)
724     local_gc->values.foreground=gc_values->foreground;
725     else
726     local_gc->values.foreground=display->screens->black_pixel;
727     if (mask&GCFunction)
728     local_gc->values.function=gc_values->function;
729     else
730     local_gc->values.function=GXcopy;
731     if (mask&GCGraphicsExposures)
732     local_gc->values.graphics_exposures=gc_values->graphics_exposures;
733     else
734     local_gc->values.graphics_exposures=True;
735     if (mask&GCJoinStyle)
736     local_gc->values.join_style=gc_values->join_style;
737     else
738     local_gc->values.join_style=JoinMiter;
739     if (mask&GCLineStyle)
740     local_gc->values.line_style=gc_values->line_style;
741     else
742     local_gc->values.line_style=LineSolid;
743     if (mask&GCLineWidth)
744     local_gc->values.line_width=gc_values->line_width;
745     else
746     local_gc->values.line_width=0;
747     if (mask&GCPlaneMask)
748     local_gc->values.plane_mask=gc_values->plane_mask;
749     else
750     local_gc->values.plane_mask=255;
751     if (mask&GCStipple)
752     local_gc->values.stipple=gc_values->stipple;
753     else
754     local_gc->values.stipple=0;
755     if (mask&GCSubwindowMode)
756     local_gc->values.subwindow_mode=gc_values->subwindow_mode;
757     else
758     local_gc->values.subwindow_mode=ClipByChildren;
759     if (mask&GCTile)
760     local_gc->values.tile=gc_values->tile;
761     else
762     local_gc->values.tile=0;
763     if (mask&GCTileStipXOrigin)
764     local_gc->values.ts_x_origin=gc_values->ts_x_origin;
765     else
766     local_gc->values.ts_x_origin=0;
767     if (mask&GCTileStipYOrigin)
768     local_gc->values.ts_y_origin=gc_values->ts_y_origin;
769     else
770     local_gc->values.ts_y_origin=0;
771    
772     local_gc->dirty = ~0;
773    
774     return (local_gc);
775     }
776    
777     int
778     XFreeGC(display, gc)
779     Display *display;
780     GC gc;
781     {
782     freeMemory(gc);
783     }
784    
785     /*****************************************************************\
786    
787     Function: XSetForeground
788     Inputs: display, gc, colour.
789    
790     Comments: Colour is an RGB triple (24bits).
791     \*****************************************************************/
792     int
793     XSetForeground(display, gc, color)
794     Display *display;
795     GC gc;
796     unsigned long color;
797     {
798     xtrace("XSetForegrond\n");
799     gc->values.foreground=color;
800     gc->dirty |= GCForeground;
801     return 0;
802     }
803    
804    
805     /*****************************************************************\
806    
807     Function: XDrawString
808     Inputs: display, window, gc, position, string, length of string.
809    
810     Comments: Writes text to the screen in the manner of X windows.
811     Note that the y origin is on the text baseline, ie.
812     the lowest part of a letter o rests on the baseline and
813     descenders fall below it.
814     The text is transparent.
815    
816     \*****************************************************************/
817    
818     int
819     XDrawString(Display *display, Drawable window,
820     GC gc, int x, int y, const char* str, int len)
821     {
822     HDC hDC;
823     TEXTMETRIC tmet;
824     HFONT old;
825     xtrace("XDrawString\n");
826    
827     if (VALID_WINDOW(window))
828     {
829     hDC = drawableGetDC(window);
830     SetBkMode(hDC,TRANSPARENT);
831     SetTextColor(hDC,CNUMTORGB(gc->values.foreground));
832     old=SelectObject(hDC,(HFONT)gc->values.font);
833     GetTextMetrics(hDC,&tmet);
834     TextOut(hDC,x,y-tmet.tmAscent,str,len);
835     SelectObject(hDC,old);
836     drawableRelDC(window,hDC);
837     }
838     return 0;
839     }
840    
841    
842    
843     int
844     XDrawString16(Display *display, Drawable window,
845     GC gc, int x, int y,
846     const XChar2b* str,
847     int len)
848     {
849     xtrace("XDrawString16\n");
850     XDrawString(display, window, gc, x, y, (const char*)str, len*2);
851     return 0;
852     }
853     XDrawImageString(
854     Display* display,
855     Drawable d,
856     GC gc,
857     int x,
858     int y,
859     const char* string,
860     int length)
861     {
862     HDC hDC = NULL;
863     TEXTMETRIC tmet;
864     HFONT old;
865     xtrace("XDrawImageString\n");
866     if (VALID_WINDOW(d))
867     {
868     hDC = drawableGetDC(d);
869     SetBkMode(hDC,TRANSPARENT);
870     SetBkColor(hDC, CNUMTORGB(gc->values.background));
871     SetTextColor(hDC,CNUMTORGB(gc->values.foreground));
872     old=SelectObject(hDC,(HFONT)gc->values.font);
873     if (GetTextMetrics(hDC,&tmet) && length>0) {
874     RECT fill;
875     fill.top = y-tmet.tmAscent;
876     fill.bottom = y+tmet.tmDescent;
877     fill.left = x;
878     fill.right = x + (tmet.tmAveCharWidth * length);
879     FillRect( hDC, &fill, NT_get_GC_bgbrush(hDC,gc));
880     }
881     TextOut( hDC, x, y-tmet.tmAscent, string, length );
882     SelectObject(hDC,old);
883     drawableRelDC(d,hDC);
884     }
885     return 0;
886     }
887    
888     int
889     XDrawImageString16(Display *display, Drawable window,
890     GC gc, int x, int y,
891     const XChar2b* str,
892     int len)
893     {
894     xtrace("XDrawImageString16\n");
895     XDrawImageString(display, window, gc, x, y, (const char*)str, len*2);
896     return 0;
897     }
898    
899    
900     /*****************************************************************\
901    
902     Function: XFillRectangle
903     Inputs: display, window, gc, geometry.
904    
905     Comments: fills rectangles in uniform colours. No tiles/Pixmaps
906     are implemented yet.
907    
908     \*****************************************************************/
909    
910     int
911     XFillRectangle (display,window,gc,x,y,w,h)
912     Display *display;
913     Drawable window;
914     GC gc;
915     int x,y;
916     unsigned int w,h;
917     {
918     RECT rct;
919     HBRUSH hbrush;
920     HDC hDC;
921     HANDLE oldObj;
922     int ret;
923     xtrace("XFillRectangle\n");
924    
925     if (VALID_WINDOW(window))
926     {
927     hDC = drawableGetDC(window);
928     NT_set_rop(hDC,gc);
929     hbrush = NT_get_GC_brush(hDC,gc);
930     oldObj = SelectObject(hDC, hbrush);
931     rct.left=(LONG) x;
932     rct.right=(LONG) (x+w);
933     rct.top=(LONG) y;
934     rct.bottom=(LONG) (y+h);
935     ret=FillRect(hDC, &rct, hbrush);
936     SelectObject(hDC, oldObj);
937     drawableRelDC(window,hDC);
938     }
939     return (ret);
940     }
941    
942    
943     /*****************************************************************\
944    
945     Function: XClearArea
946     Inputs: display, geometry, exposure events allowed.
947    
948     Comments: Straightforward.
949    
950     \*****************************************************************/
951     int
952     XClearArea(display,w,x,y,width,height,exposures)
953     Display *display;
954     Window w;
955     int x,y;
956     unsigned int width,height;
957     BoolDef exposures;
958     {
959     NT_window *ntw = (NT_window *)w;
960     RECT rct;
961     HBRUSH hbrush;
962     HDC hDC;
963     HANDLE oldObj;
964     int oldROP;
965     xtrace("XClearArea\n");
966    
967     if (VALID_WINDOW(ntw))
968     {
969     hDC = cjh_get_dc(ntw);
970     oldROP = SetROP2(hDC,R2_COPYPEN);
971     hbrush=ntw->bg;
972     oldObj = SelectObject(hDC,hbrush);
973     GetClientRect(ntw->w,&rct);
974    
975     if ((width != 0) && (height != 0))
976     {
977     rct.left=(LONG)x;
978     rct.right=(LONG)(x+width);
979     rct.top=(LONG)y;
980     rct.bottom=(LONG)(y+height);
981     FillRect(hDC,&rct,hbrush);
982     }
983    
984     SelectObject(hDC, oldObj);
985     // DeleteObject(hbrush);
986     SetROP2(hDC,oldROP);
987     cjh_rel_dc(ntw,hDC);
988     }
989     return 0;
990     }
991    
992    
993     Region
994     XCreateRegion()
995     {
996     HRGN hrgn;
997     xtrace("XCreateRegion\n");
998    
999     hrgn=CreateRectRgn(0,0,1,1);
1000     return ((Region)hrgn);
1001     }
1002    
1003    
1004     /* Untested. The Region stuff needs thinking about. */
1005    
1006     int
1007     XClipBox(hrgn,rect)
1008     Region hrgn;
1009     XRectangle *rect;
1010     {
1011     RECT rct;
1012     xtrace("XClipBox\n");
1013    
1014     GetRgnBox((HRGN)hrgn,&rct);
1015     rect->x=(short)rct.left;
1016     rect->y=(short)rct.top;
1017     rect->width=(unsigned short)(rct.right-rct.left);
1018     rect->height=(unsigned short)(rct.bottom-rct.top);
1019     return TRUE;/*(rect);*/
1020     }
1021    
1022    
1023     int
1024     XSetRegion(display,gc,hrgn)
1025     Display *display;
1026     GC gc;
1027     Region hrgn;
1028     {
1029     /* What to do here ? */
1030     xtrace("XSetRegion\n");
1031     return 0;
1032     }
1033    
1034    
1035     int
1036     XDestroyRegion(hrgn)
1037     Region hrgn;
1038     {
1039     xtrace("XDestroyRegion\n");
1040     DeleteObject(hrgn);
1041     return 0;
1042     }
1043    
1044    
1045     int
1046     XUnionRectWithRegion(rect,hrgnsrc,hrgndest)
1047     XRectangle *rect;
1048     Region hrgnsrc,hrgndest;
1049     {
1050     HRGN temp;
1051     xtrace("XUnionRectWithRegion\n");
1052     temp=CreateRectRgn(rect->x,rect->y,rect->x+rect->width,
1053     rect->y+rect->height);
1054     CombineRgn((HRGN)hrgndest,(HRGN)hrgnsrc,temp,RGN_OR);
1055     return 0;
1056     }
1057    
1058    
1059     /*****************************************************************\
1060    
1061     Function: XDrawArc
1062     Inputs: display, window, gc, bounding box geometry, arc angles.
1063    
1064     Comments: Works fine.
1065    
1066     \*****************************************************************/
1067    
1068     int
1069     XDrawArc(display,w,gc,x,y,width,height,a1,a2)
1070     Display *display;
1071     Drawable w;
1072     GC gc;
1073     int x,y;
1074     unsigned int width,height;
1075     int a1,a2;
1076     {
1077     HDC hDC;
1078     HPEN hpen;
1079     int tmp;
1080     double NT_deg64_to_rad();
1081     HANDLE oldObj;
1082     xtrace("XDrawArc\n");
1083     if (a2>=0)
1084     a2+=a1;
1085     else
1086     {
1087     tmp=a1;
1088     a1-=a2;
1089     a2=tmp;
1090     }
1091    
1092     if (VALID_WINDOW(w))
1093     {
1094     hDC = drawableGetDC(w);
1095     hpen = NT_get_GC_pen(hDC,gc);
1096     oldObj = SelectObject(hDC,hpen);
1097     Arc(hDC,x,y,x+width-1,y+height-1,
1098     (int) (x+width/2+width*cos(NT_deg64_to_rad(a1))),
1099     (int) (y+height/2-height*sin(NT_deg64_to_rad(a1))),
1100     (int) (x+width/2+width*cos(NT_deg64_to_rad(a2))),
1101     (int) (y+height/2-height*sin(NT_deg64_to_rad(a2))));
1102     SelectObject(hDC, oldObj);
1103     drawableRelDC(w,hDC);
1104     }
1105     return 0;
1106     }
1107    
1108    
1109     /*****************************************************************\
1110    
1111     Function: XFillArc
1112     Inputs: display, window, gc, geometry as above.
1113    
1114     Comments: Not tested at all, but should work.
1115    
1116     \*****************************************************************/
1117    
1118     int
1119     XFillArc(display,w,gc,x,y,width,height,a1,a2)
1120     Display *display;
1121     Drawable w;
1122     GC gc;
1123     int x,y;
1124     unsigned int width,height;
1125     int a1,a2;
1126     {
1127     HDC hDC;
1128     HBRUSH hbrush;
1129     int tmp;
1130     HANDLE oldObj;
1131     xtrace("XFillArc\n");
1132     if (a2>=0)
1133     a2+=a1;
1134     else
1135     {
1136     tmp=a1;
1137     a1-=a2;
1138     a2=tmp;
1139     }
1140     if (VALID_WINDOW(w))
1141     {
1142     hDC = drawableGetDC(w);
1143     hbrush = NT_get_GC_brush(hDC,gc);
1144     oldObj = SelectObject(hDC,hbrush);
1145     if (gc->values.arc_mode==ArcChord)
1146     {
1147     Chord(hDC,x,y,x+width,y+height,
1148     (int) (x+width/2+width*cos(NT_deg64_to_rad(a1))),
1149     (int) (y+height/2+height*sin(NT_deg64_to_rad(a1))),
1150     (int) (x+width/2+width*cos(NT_deg64_to_rad(a2))),
1151     (int) (y+height/2+height*sin(NT_deg64_to_rad(a2))));
1152     }
1153     else
1154     {
1155     Pie(hDC,x,y,x+width,y+height,
1156     (int) (x+width/2+width*cos(NT_deg64_to_rad(a1))),
1157     (int) (y+height/2+height*sin(NT_deg64_to_rad(a1))),
1158     (int) (x+width/2+width*cos(NT_deg64_to_rad(a2))),
1159     (int) (y+height/2+height*sin(NT_deg64_to_rad(a2))));
1160     }
1161     SelectObject(hDC, oldObj);
1162     drawableRelDC(w,hDC);
1163     }
1164     return 0;
1165     }
1166    
1167    
1168     /*****************************************************************\
1169    
1170     Function: XFillPolygon
1171     Inputs: display, window, gc, points list, number of points,
1172     shape hint, relative drawing mode.
1173    
1174     Comments: Works for convex polygons. Untested on otherwise.
1175     Optimisation hints are unused, as is the mode.
1176    
1177     \*****************************************************************/
1178    
1179     int
1180     XFillPolygon(display,w,gc,points,nps,shape,mode)
1181     Display *display;
1182     Drawable w;
1183     GC gc;
1184     XPoint *points;
1185     int nps,shape,mode;
1186     {
1187     HBRUSH hbrush;
1188     int n;
1189     POINT ntps[1000];
1190     HDC hDC;
1191     HANDLE oldObj;
1192     xtrace("XFillPolygon\n");
1193     /*ntps=allocateMemory(sizeof(POINT)*nps);*/
1194     if (VALID_WINDOW(w))
1195     {
1196     hDC = drawableGetDC(w);
1197     hbrush = NT_get_GC_brush(hDC,gc);
1198     oldObj = SelectObject(hDC,hbrush);
1199     for (n=0;n<nps;++n)
1200     {
1201     (ntps+n)->x=(LONG)points->x;
1202     (ntps+n)->y=(LONG)(points++)->y;
1203     }
1204     Polygon(hDC,ntps,nps);
1205     SelectObject(hDC, oldObj);
1206     drawableRelDC(w,hDC);
1207     }
1208    
1209     /*free(ntps);*/
1210     return 0;
1211     }
1212    
1213    
1214     /*****************************************************************\
1215    
1216     Function: XDrawLine
1217     Inputs: display, window, geometry.
1218    
1219     Comments: Seems to work ok.
1220    
1221     \*****************************************************************/
1222    
1223     int
1224     XDrawLine(display,w,gc,x1,y1,x2,y2)
1225     Display *display;
1226     Drawable w;
1227     GC gc;
1228     int x1,y1,x2,y2;
1229     {
1230     HDC hDC;
1231     HPEN hpen;
1232     RECT da;
1233     HANDLE oldObj;
1234     xtrace("XDrawLine\n");
1235    
1236     if (VALID_WINDOW(w))
1237     {
1238     hDC = drawableGetDC(w);
1239     hpen = NT_get_GC_pen(hDC,gc);
1240     oldObj = SelectObject(hDC,hpen);
1241     MoveToEx(hDC,x1,y1,NULL);
1242     LineTo(hDC,x2,y2);
1243     SelectObject(hDC, oldObj);
1244     drawableRelDC(w,hDC);
1245     }
1246     return 0;
1247     }
1248    
1249    
1250     /*****************************************************************\
1251    
1252     Function: XDrawLines
1253     Inputs: display, window, gc, points list, number of points, mode.
1254    
1255     Comments: Untested.
1256    
1257     \*****************************************************************/
1258    
1259     int
1260     XDrawLines(display,w,gc,points,nps,mode)
1261     Display *display;
1262     Drawable w;
1263     GC gc;
1264     XPoint *points;
1265     int nps,mode;
1266     {
1267     HPEN hpen;
1268     int n;
1269     POINT pts[1000];
1270     HDC hDC;
1271     HANDLE oldObj;
1272     xtrace("XDrawLines\n");
1273    
1274     pts->x=(LONG)points->x;
1275     pts->y=(LONG)points->y;
1276    
1277     for(n=1;n<nps;++n)
1278     if (mode==CoordModeOrigin)
1279     {
1280     (pts+n)->x=(LONG)(points+n)->x;
1281     (pts+n)->y=(LONG)(points+n)->y;
1282     }
1283     else
1284     {
1285     (pts+n)->x=(LONG)(points+n)->x+(pts+n-1)->x;
1286     (pts+n)->y=(LONG)(points+n)->y+(pts+n-1)->y;
1287     }
1288    
1289     if (VALID_WINDOW(w))
1290     {
1291     hDC = drawableGetDC(w);
1292     hpen = NT_get_GC_pen(hDC,gc);
1293     oldObj = SelectObject(hDC,hpen);
1294     Polyline(hDC,pts,nps);
1295     SelectObject(hDC, oldObj);
1296     drawableRelDC(w,hDC);
1297     }
1298     return 0;
1299     }
1300    
1301    
1302     /*****************************************************************\
1303    
1304     Function: XDrawPoints
1305     Inputs: display, window, gc, points list, number of points, mode.
1306    
1307     Comments: Untested.
1308    
1309     \*****************************************************************/
1310    
1311     int
1312     XDrawPoints(display,w,gc,points,nps,mode)
1313     Display *display;
1314     Drawable w;
1315     GC gc;
1316     XPoint *points;
1317     int nps,mode;
1318     {
1319     HDC hDC;
1320     int n;
1321     xtrace("XDrawPoints\n");
1322     if (VALID_WINDOW(w))
1323     {
1324     hDC = drawableGetDC(w);
1325     SetPixelV(hDC,points->x,points->y,CNUMTORGB(gc->values.foreground));
1326     for (n=1;n<nps;++n)
1327     {
1328     if (mode==CoordModeOrigin)
1329     SetPixelV(hDC,(points+n)->x,(points+n)->y,
1330     CNUMTORGB(gc->values.foreground));
1331     else
1332     SetPixelV(hDC,(points+n-1)->x+(points+n)->x,
1333     (points+n-1)->y+(points+n)->y,
1334     CNUMTORGB(gc->values.foreground));
1335     }
1336     drawableRelDC(w,hDC);
1337     }
1338     return 0;
1339     }
1340     int
1341     XDrawPoint(display,w,gc,x,y)
1342     Display *display;
1343     Drawable w;
1344     GC gc;
1345     int x,y;
1346     {
1347     HDC hDC;
1348     xtrace("XDrawPoint\n");
1349     if (VALID_WINDOW(w))
1350     {
1351     hDC = drawableGetDC(w);
1352     SetPixelV(hDC,x,y,CNUMTORGB(gc->values.foreground));
1353     drawableRelDC(w,hDC);
1354     }
1355     return 0;
1356     }
1357    
1358    
1359     /*****************************************************************\
1360    
1361     Function: XDrawRectangle
1362     Inputs: display, window, gc, geometry
1363    
1364     Comments: Seems to work.
1365    
1366     \*****************************************************************/
1367    
1368     int
1369     XDrawRectangle(display,w,gc,x,y,width,height)
1370     Display *display;
1371     Drawable w;
1372     GC gc;
1373     int x,y;
1374     unsigned int width,height;
1375     {
1376     HDC hDC;
1377     RECT rect;
1378     HBRUSH hbrush;
1379     HPEN hpen;
1380     HANDLE oldbrush, oldpen;
1381     xtrace("XDrawRectangle\n");
1382     if (VALID_WINDOW(w))
1383     {
1384     hDC = drawableGetDC(w);
1385     hbrush = NT_get_GC_brush(hDC,gc);
1386     rect.left=(LONG)x;
1387     rect.right=(LONG)(x+width);
1388     rect.top=(LONG)y;
1389     rect.bottom=(LONG)(y+height);
1390     oldbrush = SelectObject(hDC,GetStockObject(NULL_BRUSH));
1391     hpen = NT_get_GC_pen(hDC,gc);
1392     oldpen = SelectObject(hDC,hpen);
1393    
1394     Rectangle(hDC,(int)rect.left,(int)rect.top,(int)rect.right,(int)rect.bottom);
1395     /*
1396     FrameRect(hDC,&rect,hbrush);
1397     */
1398     SelectObject(hDC, oldbrush);
1399     SelectObject(hDC, oldpen);
1400     drawableRelDC(w,hDC);
1401     }
1402     return 0;
1403     }
1404    
1405    
1406     /*****************************************************************\
1407    
1408     Function: XDrawSegments
1409     Inputs: display, window, gc, segment list, number of segments.
1410    
1411     Comments: Untested.
1412    
1413     \*****************************************************************/
1414    
1415     int
1416     XDrawSegments(display,w,gc,segs,nsegs)
1417     Display *display;
1418     Drawable w;
1419     GC gc;
1420     XSegment *segs;
1421     int nsegs;
1422     {
1423     HDC hDC;
1424     HPEN hpen;
1425     int n;
1426     HANDLE oldObj;
1427     xtrace("XDrawSegments\n");
1428     if (VALID_WINDOW(w))
1429     {
1430     hDC = drawableGetDC(w);
1431     hpen = NT_get_GC_pen(hDC,gc);
1432     oldObj = SelectObject(hDC,hpen);
1433     SetBkMode(hDC,TRANSPARENT);
1434     for (n=0;n<nsegs;n++)
1435     {
1436     MoveToEx(hDC,(segs+n)->x1,(segs+n)->y1,NULL);
1437     LineTo(hDC,(segs+n)->x2,(segs+n)->y2);
1438     }
1439     SelectObject(hDC, oldObj);
1440     drawableRelDC(w,hDC);
1441     }
1442     return 0;
1443     }
1444    
1445     Pixmap
1446     XCreatePixmap(display,drawable,width,height,depth)
1447     Display *display;
1448     Drawable drawable;
1449     unsigned int width, height;
1450     unsigned int depth;
1451     {
1452     RECT rct;
1453     NT_window *w = (NT_window *)NT_new_window();
1454     HDC parenthDC = drawableGetDC(drawable);
1455     w->hDC = CreateCompatibleDC(parenthDC);
1456     w->hBitmap = CreateCompatibleBitmap(parenthDC,width,height);
1457     SelectObject(w->hDC, w->hBitmap);
1458    
1459     rct.left=(LONG) 0;
1460     rct.right=(LONG) width;
1461     rct.top=(LONG) 0;
1462     rct.bottom=(LONG) height;
1463     FillRect(w->hDC, &rct, GetStockObject(WHITE_BRUSH));
1464    
1465     drawableRelDC(drawable,parenthDC);
1466    
1467     w->w = NONMAPPED_HANDLE;
1468     w->x=0;
1469     w->y=0;
1470     w->wdth = width;
1471     w->hght = height;
1472     w->min = depth;
1473     return (Pixmap)w;
1474     }
1475    
1476     const char revBytes[]={
1477     0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 0x10, 0x90, 0x50,
1478     0xd0, 0x30, 0xb0, 0x70, 0xf0, 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8,
1479     0x68, 0xe8, 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, 0x04,
1480     0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, 0x14, 0x94, 0x54, 0xd4,
1481     0x34, 0xb4, 0x74, 0xf4, 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c,
1482     0xec, 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, 0x02, 0x82,
1483     0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, 0x12, 0x92, 0x52, 0xd2, 0x32,
1484     0xb2, 0x72, 0xf2, 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
1485     0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, 0x06, 0x86, 0x46,
1486     0xc6, 0x26, 0xa6, 0x66, 0xe6, 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6,
1487     0x76, 0xf6, 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, 0x1e,
1488     0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, 0x01, 0x81, 0x41, 0xc1,
1489     0x21, 0xa1, 0x61, 0xe1, 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71,
1490     0xf1, 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, 0x19, 0x99,
1491     0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, 0x05, 0x85, 0x45, 0xc5, 0x25,
1492     0xa5, 0x65, 0xe5, 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
1493     0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, 0x1d, 0x9d, 0x5d,
1494     0xdd, 0x3d, 0xbd, 0x7d, 0xfd, 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3,
1495     0x63, 0xe3, 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, 0x0b,
1496     0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, 0x1b, 0x9b, 0x5b, 0xdb,
1497     0x3b, 0xbb, 0x7b, 0xfb, 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67,
1498     0xe7, 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, 0x0f, 0x8f,
1499     0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, 0x1f, 0x9f, 0x5f, 0xdf, 0x3f,
1500     0xbf, 0x7f, 0xff
1501     };
1502    
1503    
1504     Pixmap
1505     XCreateBitmapFromData(Display *display,
1506     Drawable drawable, const char *data,
1507     unsigned int width, unsigned int height)
1508     {
1509     NT_window *w = (NT_window *)NT_new_window();
1510     HDC parenthDC = drawableGetDC(drawable);
1511     w->hDC = CreateCompatibleDC(parenthDC);
1512    
1513     {
1514     int i,j;
1515     char *newdata;
1516     int bytes = (width+7)>>3;
1517     int newbytes = (bytes&1)?bytes+1:bytes;
1518     newdata = allocateMemory(newbytes*height);
1519     for (i=0;i<height;i++)
1520     {
1521     for (j=0;j<bytes;j++)
1522     {
1523     newdata[(i*newbytes)+j]=revBytes[(unsigned char)data[(i*bytes)+j]];
1524     }
1525     }
1526     w->hBitmap = CreateBitmap(width,height,1,1,newdata);
1527     freeMemory(newdata);
1528     }
1529    
1530     SelectObject(w->hDC, w->hBitmap);
1531     drawableRelDC(drawable,parenthDC);
1532     w->x=0;
1533     w->y=0;
1534     w->wdth = width;
1535     w->hght = height;
1536     w->min = 1;
1537     return (Pixmap)w;
1538     }
1539    
1540     int
1541     XFreePixmap(display, pixmap)
1542     Display *display;
1543     Pixmap pixmap;
1544     {
1545     NT_window *w = (NT_window *)pixmap;
1546     NT_delete_window(w);
1547     return 0;
1548     }
1549    
1550     int
1551     XCopyArea(display, src, dest, gc, src_x, src_y, width, height, dest_x, dest_y)
1552     Display *display;
1553     Drawable src, dest;
1554     GC gc;
1555     int src_x, src_y;
1556     unsigned int width, height;
1557     int dest_x, dest_y;
1558     {
1559     HDC hsrc, hdst;
1560     hsrc = drawableGetDC(src);
1561     if (VALID_WINDOW(dest))
1562     {
1563     hdst = drawableGetDC(dest);
1564     (void)BitBlt(hdst,dest_x,dest_y,width,height,hsrc,src_x,src_y,SRCCOPY);
1565     drawableRelDC(src,hsrc);
1566     }
1567     drawableRelDC(dest,hdst);
1568     return 0;
1569     }
1570    
1571     XImage *
1572     NT_XCreateImage()
1573     {
1574     return NULL;
1575     }
1576    
1577     int NT_XDestroyImage(ximage)
1578     XImage *ximage;
1579     {
1580     /* freeMemory(ximage->data); */
1581     freeMemory(ximage);
1582     return 1;
1583     }
1584    
1585     unsigned long
1586     NT_XGetPixel(ximage,x,y)
1587     XImage *ximage;
1588     int x,y;
1589     {
1590     return 0;
1591     }
1592     int
1593     NT_XPutPixel(ximage,x,y,pixel)
1594     XImage *ximage;
1595     int x,y;
1596     unsigned long pixel;
1597     {
1598     return 0;
1599     }
1600     XImage *
1601     NT_XSubImage(ximage,x,y,w,h)
1602     XImage *ximage;
1603     int x,y;
1604     unsigned int w,h;
1605     {
1606     return NULL;
1607     }
1608     int
1609     NT_XAddPixel(ximage,value)
1610     XImage *ximage;
1611     unsigned long value;
1612     {
1613     return 0;
1614     }
1615    
1616     XImage *
1617     XGetImage(display,drawable,x,y,width,height,plane_mask,format)
1618     Display *display;
1619     Drawable drawable;
1620     int x,y;
1621     unsigned int width, height;
1622     unsigned long plane_mask;
1623     int format;
1624     {
1625     return NULL;
1626     }
1627    
1628     XImage *
1629     XCreateImage(display,visual,depth,format,offset,data,width,height, bitmap_pad, bytes_per_line)
1630     Display *display;
1631     Visual *visual;
1632     unsigned int depth;
1633     int format;
1634     int offset;
1635     char *data;
1636     unsigned int width, height;
1637     int bitmap_pad, bytes_per_line;
1638     {
1639     XImage *img = (XImage *) allocateMemory(sizeof(XImage));
1640    
1641     if (img) {
1642     img->depth = 24; /* depth; */
1643     img->format = format;
1644     img->xoffset = offset;
1645     img->data = data;
1646     img->width = width;
1647     img->height = height;
1648     img->bitmap_pad = 32;
1649     img->bytes_per_line=width*((24)>>3);
1650     img->bits_per_pixel = 24; /* depth; */
1651     img->bitmap_bit_order = LSBFirst;
1652     img->byte_order = MSBFirst;
1653     img->blue_mask = 0x0ff00000;
1654     img->green_mask=0x00ff0000;
1655     img->red_mask= 0x0000ff00;
1656    
1657     img->f.create_image = NT_XCreateImage;
1658     img->f.destroy_image = NT_XDestroyImage;
1659     img->f.get_pixel = NT_XGetPixel;
1660     img->f.put_pixel = NT_XPutPixel;
1661     img->f.sub_image = NT_XSubImage;
1662     img->f.add_pixel = NT_XAddPixel;
1663    
1664     }
1665    
1666     return img;
1667     }
1668     void
1669     DrawBitmap(HDC hdc, HBITMAP hBitmap, int xStart, int yStart)
1670     {
1671     BITMAP bm;
1672     HDC hdcMem;
1673     DWORD dwSize;
1674     POINT ptSize, ptOrg;
1675     hdcMem = CreateCompatibleDC(hdc);
1676     SelectObject(hdcMem, hBitmap);
1677     SetMapMode(hdcMem,GetMapMode(hdc));
1678     GetObject(hBitmap, sizeof(BITMAP), (LPVOID)&bm);
1679     ptSize.x = bm.bmWidth;
1680     ptSize.y = bm.bmHeight;
1681     DPtoLP(hdc, &ptSize,1);
1682     ptOrg.x=0;
1683     ptOrg.y=0;
1684     DPtoLP(hdcMem,&ptOrg,1);
1685     BitBlt(hdc,xStart,yStart,ptSize.x,ptSize.y,hdcMem,ptOrg.x,ptOrg.y,SRCCOPY);
1686     DeleteDC(hdcMem);
1687     }
1688     /*
1689     static unsigned char wBrickBits[]={
1690     0xff,0x0c,0x0c,0x0c, 0xff,0xc0,0xc0,0xc0,
1691     0xff,0x0c,0xff,0xff, 0xff,0xff,0xc0,0xc0,
1692     0xff,0x0c,0xff,0xff, 0xff,0xff,0xc0,0xc0,
1693     0xff,0x0c,0x0c,0x0c, 0xff,0xc0,0xc0,0xc0
1694     };
1695     */
1696     int
1697     XPutImage(display,w,gc,image,sx,sy,dx,dy,width,height)
1698     Display *display;
1699     Drawable w;
1700     XImage *image;
1701     GC gc;
1702     int sx,sy,dx,dy;
1703     unsigned int width,height;
1704     {
1705     BITMAPINFO bmInfo;
1706     NT_window *pix = (NT_window *)w;
1707     int res;
1708     if (VALID_WINDOW(w))
1709     {
1710     HDC hDC = drawableGetDC(w);
1711     bmInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1712     bmInfo.bmiHeader.biWidth = width;
1713     bmInfo.bmiHeader.biHeight = height;
1714     bmInfo.bmiHeader.biPlanes = 1;
1715     bmInfo.bmiHeader.biBitCount = 24; /*image->depth; */
1716     bmInfo.bmiHeader.biCompression = BI_RGB;
1717     bmInfo.bmiHeader.biSizeImage = 0;
1718     bmInfo.bmiHeader.biXPelsPerMeter = 3600;
1719     bmInfo.bmiHeader.biYPelsPerMeter = 3600;
1720     bmInfo.bmiHeader.biClrUsed = 0;
1721     bmInfo.bmiHeader.biClrImportant = 0;
1722     res = SetDIBitsToDevice(hDC,0,0,width,height,0,0,0,height,image->data,&bmInfo,DIB_RGB_COLORS);
1723     /* BitBlt(CreateDC("DISPLAY",NULL,NULL,NULL),10,0,width,height,hDC,0,0,SRCCOPY); */
1724     if (res==0)
1725     printf("SetDIBitsfailed %d\n",res,GetLastError());
1726     drawableRelDC(w,hDC);
1727     }
1728     return 0;
1729     }
1730    
1731     int
1732     XSetWindowBackground(display, w, bg)
1733     Display *display;
1734     Window w;
1735     unsigned long bg;
1736     {
1737     NT_window *window = (NT_window *)w;
1738     xtrace("XSetWindowBackground\n");
1739     DeleteObject(window->bg);
1740     window->bg=CreateSolidBrush(CNUMTORGB(bg));
1741     return 0;
1742     }
1743    
1744     int
1745     XSetWindowBackgroundPixmap(display, w, background_tile)
1746     Display *display;
1747     Window w;
1748     Pixmap background_tile;
1749     {
1750     NT_window *window = (NT_window *)w;
1751     NT_window *wpix = (NT_window *)background_tile;
1752     BITMAPINFO *bmInfo;
1753     BITMAP bm;
1754     int res;
1755    
1756     xtrace("XSetWindowBackgroundPixmap\n");
1757     if (background_tile==ParentRelative)
1758     {
1759     if (!window->parentRelative)
1760     {
1761     HBITMAP hb = NT_getWallpaper();
1762     if (hb!=NULL) {
1763     DeleteObject(window->bg);
1764     window->bg = CreatePatternBrush(hb);
1765     window->parentRelative=1;
1766     NT_configureNotify(window,window->x,window->y);
1767     }
1768     }
1769     }
1770     else
1771     {
1772     GetObject(wpix->hBitmap, sizeof(BITMAP), &bm);
1773    
1774     bmInfo = allocateMemory(sizeof(BITMAPINFO) + ( (bm.bmBitsPixel>>3)* bm.bmWidth*bm.bmHeight));
1775     bmInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1776     bmInfo->bmiHeader.biWidth = bm.bmWidth;
1777     bmInfo->bmiHeader.biHeight = bm.bmHeight;
1778     bmInfo->bmiHeader.biPlanes = 1;
1779     bmInfo->bmiHeader.biBitCount = bm.bmBitsPixel;
1780     bmInfo->bmiHeader.biCompression = BI_RGB;
1781     bmInfo->bmiHeader.biSizeImage = 0;
1782     bmInfo->bmiHeader.biClrImportant = 0;
1783     bmInfo->bmiHeader.biClrUsed = 0;
1784    
1785     res =GetDIBits(wpix->hDC,wpix->hBitmap,0,bm.bmHeight,bmInfo->bmiColors,bmInfo,DIB_RGB_COLORS);
1786     if (res==0)
1787     printf("getDIBits failed %d\n",res,GetLastError());
1788    
1789     DeleteObject(window->bg);
1790     window->bg = CreateDIBPatternBrushPt(bmInfo, DIB_RGB_COLORS);
1791     freeMemory(bmInfo);
1792     }
1793     }
1794    
1795    
1796     /*****************************************************************\
1797    
1798     Function: XSetFillStyle
1799     Inputs: display, gc, fill style.
1800    
1801     Comments: ZZzzz...
1802    
1803     \*****************************************************************/
1804    
1805     int
1806     XSetFillStyle(display,gc,fs)
1807     Display *display;
1808     GC gc;
1809     int fs;
1810     {
1811     xtrace("XSetFillStyle\n");
1812     gc->values.fill_style=fs;
1813     gc->dirty |= GCFillStyle;
1814     return 0;
1815     }
1816    
1817    
1818     int
1819     XSetDashes(Display *display,
1820     GC gc, int dash_offset,
1821     const char * dash_list,
1822     int n)
1823     {
1824     xtrace("XSetDashes\n");
1825     return 0;
1826     }
1827    
1828    
1829     int
1830     XChangeWindowAttributes(display,w,vmask,attr)
1831     Display *display;
1832     Window w;
1833     unsigned long vmask;
1834     XSetWindowAttributes *attr;
1835     {
1836     xtrace("XChangeWindowAttributes\n");
1837     return 0;
1838     }
1839    
1840    
1841     /*****************************************************************\
1842    
1843     Function: XLowerWindow
1844     Inputs: display, window to be lowered.
1845    
1846     Comments: Make sure if the window has a frame that that gets lowered
1847     too.
1848    
1849     \*****************************************************************/
1850    
1851     int
1852     XLowerWindow(display,w)
1853     Display *display;
1854     Window w;
1855     {
1856     NT_window *ntw=(NT_window *)w;
1857     xtrace("XLowerWindow\n");
1858     SetWindowPos((HWND)ntw->w,HWND_BOTTOM,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
1859     return 0;
1860     }
1861    
1862    
1863     /*****************************************************************\
1864    
1865     Function: XMapRaised
1866     Inputs: display, window.
1867    
1868     Comments: Frames get raised first.
1869    
1870     \*****************************************************************/
1871    
1872     int
1873     XMapRaised(display,w)
1874     Display *display;
1875     Window w;
1876     {
1877     NT_window *ntw=(NT_window *)w;
1878     xtrace("XMapRaised\n");
1879     XMapWindow(display,w);
1880     SetWindowPos(ntw->w,HWND_TOP,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
1881     return 0;
1882     }
1883    
1884    
1885     /*****************************************************************\
1886    
1887     Function: XMapSubwindows
1888     Inputs: display, window.
1889    
1890     Comments: Unfortunately, the optimisations normally made by
1891     the X server are not made here.
1892    
1893     \*****************************************************************/
1894    
1895     int
1896     XMapSubwindows(display,w)
1897     Display *display;
1898     Window w;
1899     {
1900     NT_window *ntw=(NT_window *)w;
1901     struct NT_child *tmp;
1902    
1903     xtrace("XMapSubWindows\n");
1904     tmp=ntw->child;
1905     while (tmp!=NULL)
1906     {
1907     XMapWindow(display,(Window)tmp->w);
1908     tmp=tmp->next;
1909     }
1910     return 0;
1911     }
1912    
1913    
1914     /*****************************************************************\
1915    
1916     Function: XQueryTree
1917     Inputs: display, window.
1918     Returned: root window, parent window, list of children, status.
1919    
1920     Comments: Not fully implemented. The child field is wrong.
1921    
1922     \*****************************************************************/
1923    
1924     StatusDef
1925     XQueryTree(display,w,root,parent,ch,n)
1926     Display *display;
1927     Window w;
1928     Window* root;
1929     Window* parent;
1930     Window** ch;
1931     unsigned int *n;
1932     {
1933     NT_window *ntw=(NT_window *)w;
1934     StatusDef status=1;
1935    
1936     xtrace("XQueryTree\n");
1937     *parent=(Window)ntw->parent;
1938     if (ntw->parent==NULL)
1939     status=0;
1940     *root=display->screens[0].root;
1941     *ch=NULL;
1942     *n=0;
1943     return (status);
1944     }
1945    
1946    
1947     /*****************************************************************\
1948    
1949     Function: XRaiseWindow
1950     Inputs: display, window.
1951    
1952     Comments: Recursive raising of window and its children.
1953    
1954     \*****************************************************************/
1955    
1956     int
1957     XRaiseWindow(display,w)
1958     Display *display;
1959     Window w;
1960     {
1961     NT_window *ntw=(NT_window *)w;
1962     struct NT_child *tmp;
1963     xtrace("XRaiseWindows\n");
1964    
1965     BringWindowToTop(ntw->w);
1966     tmp=ntw->child;
1967     while (tmp!=NULL)
1968     {
1969     XRaiseWindow(display,(Window)tmp->w);
1970     tmp=tmp->next;
1971     }
1972     return 0;
1973     }
1974    
1975    
1976     /*****************************************************************\
1977    
1978     Function: XRootWindow
1979     Inputs: display, screen number
1980     Returned: root window ID.
1981    
1982     Comments: Info taken from display structure.
1983    
1984     \*****************************************************************/
1985    
1986     Window
1987     XRootWindow(display,scr)
1988     Display *display;
1989     int scr;
1990     {
1991     xtrace("XRootWindow\n");
1992     return(display->screens[0].root);
1993     }
1994    
1995    
1996     /*****************************************************************\
1997    
1998     Function: XRootWindowOfScreen
1999     Inputs: screen pointer
2000     Returned: root window ID.
2001    
2002     Comments: ZZzzz...
2003    
2004     \*****************************************************************/
2005    
2006     Window
2007     XRootWindowOfScreen(scr)
2008     Screen *scr;
2009     {
2010     xtrace("XRootWindowOfScreen\n");
2011     return(scr->root);
2012     }
2013    
2014    
2015     /*****************************************************************\
2016    
2017     Function: XTranslateCoordinates
2018     Inputs: display, source window, destination window, source x, y.
2019     Returned: destination x, y, child window if any.
2020    
2021     Comments: Seems to work properly.
2022    
2023     \*****************************************************************/
2024    
2025     BoolDef
2026     XTranslateCoordinates(display,sw,dw,sx,sy,dx,dy,ch)
2027     Display *display;
2028     Window sw,dw;
2029     int sx,sy,*dx,*dy;
2030     Window *ch;
2031     {
2032     xtrace("XTranslateCoordinates\n");
2033     return (True);
2034     }
2035    
2036    
2037     /*****************************************************************\
2038    
2039     Function: XUnmapWindow
2040     Inputs: display, window.
2041    
2042     Comments: Removes a window and its frame, if it has one, from the
2043     screen.
2044    
2045     \*****************************************************************/
2046    
2047     int
2048     XUnmapWindow(display,w)
2049     Display *display;
2050     Window w;
2051     {
2052     NT_window *ntw=(NT_window *)w;
2053     xtrace("XUnmapWindow\n");
2054     ShowWindow(ntw->w,SW_HIDE);
2055     return 0;
2056     }
2057    
2058    
2059     /*****************************************************************\
2060    
2061     Function: XCopyGC
2062     Inputs: display, source gc, values mask, destination gc.
2063    
2064     Comments: Copies masked elements from source to destination.
2065    
2066     \*****************************************************************/
2067    
2068     int
2069     XCopyGC(display,sgc,vmask,dgc)
2070     Display *display;
2071     GC sgc,dgc;
2072     unsigned long vmask;
2073     {
2074     xtrace("XCopyGC\n");
2075     if (vmask&GCFunction)
2076     dgc->values.function=sgc->values.function;
2077     if (vmask&GCPlaneMask)
2078     dgc->values.plane_mask=sgc->values.plane_mask;
2079     if (vmask&GCForeground)
2080     dgc->values.foreground=sgc->values.foreground;
2081     if (vmask&GCBackground)
2082     dgc->values.background=sgc->values.background;
2083     if (vmask&GCLineWidth)
2084     dgc->values.line_width=sgc->values.line_width;
2085     if (vmask&GCLineStyle)
2086     dgc->values.line_style=sgc->values.line_style;
2087     if (vmask&GCCapStyle)
2088     dgc->values.cap_style=sgc->values.cap_style;
2089     if (vmask&GCJoinStyle)
2090     dgc->values.join_style=sgc->values.join_style;
2091     if (vmask&GCFillStyle)
2092     dgc->values.fill_style=sgc->values.fill_style;
2093     if (vmask&GCFillRule)
2094     dgc->values.fill_rule=sgc->values.fill_rule;
2095     if (vmask&GCTile)
2096     dgc->values.tile=sgc->values.tile;
2097     if (vmask&GCStipple)
2098     dgc->values.stipple=sgc->values.stipple;
2099     if (vmask&GCTileStipXOrigin)
2100     dgc->values.ts_x_origin=sgc->values.ts_x_origin;
2101     if (vmask&GCTileStipYOrigin)
2102     dgc->values.ts_y_origin=sgc->values.ts_y_origin;
2103     if (vmask&GCFont)
2104     dgc->values.font=sgc->values.font;
2105     if (vmask&GCSubwindowMode)
2106     dgc->values.subwindow_mode=sgc->values.subwindow_mode;
2107     if (vmask&GCGraphicsExposures)
2108     dgc->values.graphics_exposures=sgc->values.graphics_exposures;
2109     if (vmask&GCClipXOrigin)
2110     dgc->values.clip_x_origin=sgc->values.clip_x_origin;
2111     if (vmask&GCClipYOrigin)
2112     dgc->values.clip_y_origin=sgc->values.clip_y_origin;
2113     if (vmask&GCClipMask)
2114     dgc->values.clip_mask=sgc->values.clip_mask;
2115     if (vmask&GCDashList)
2116     dgc->values.dashes=sgc->values.dashes;
2117     if (vmask&GCArcMode)
2118     dgc->values.arc_mode=sgc->values.arc_mode;
2119    
2120     dgc->dirty = 0xFFFF;
2121     return 0;
2122     }
2123    
2124    
2125     int
2126     XSetClipMask(display,gc,cmask)
2127     Display *display;
2128     GC gc;
2129     Pixmap cmask;
2130     {
2131     xtrace("XSetClipMask\n");
2132     return 0;
2133     }
2134    
2135    
2136     int
2137     XSetClipRectangles(display,gc,clx,cly,rs,n,order)
2138     Display *display;
2139     GC gc;
2140     int clx,cly;
2141     XRectangle *rs;
2142     int n,order;
2143     {
2144     xtrace("XSetClipRectangles\n");
2145     return 0;
2146     }
2147    
2148    
2149     /*****************************************************************\
2150    
2151     Function: XSetFunction
2152     Inputs: display, gc, graphics operation.
2153    
2154     Comments: ZZzzz...
2155    
2156     \*****************************************************************/
2157    
2158     int
2159     XSetFunction(display,gc,fn)
2160     Display *display;
2161     GC gc;
2162     int fn;
2163     {
2164     xtrace("XSetFunction\n");
2165     gc->values.function=fn;
2166     gc->dirty |= GCFunction;
2167     return 0;
2168     }
2169    
2170    
2171     /*****************************************************************\
2172    
2173     Function: XSetLineAttributes
2174     Inputs: display, gc, line width, line style, cap style, join style.
2175    
2176     Comments: These all have windows equivalents.
2177    
2178     \*****************************************************************/
2179    
2180     int
2181     XSetLineAttributes(display,gc,lw,ls,cs,js)
2182     Display *display;
2183     GC gc;
2184     unsigned int lw;
2185     int ls,cs,js;
2186     {
2187     xtrace("XSetLineAttributes\n");
2188     gc->values.line_width=lw;
2189     gc->values.line_style=ls;
2190     gc->values.cap_style=cs;
2191     gc->values.join_style=js;
2192     gc->dirty |= GCLineWidth | GCLineStyle | GCCapStyle | GCJoinStyle;
2193     return 0;
2194     }
2195    
2196    
2197     /*****************************************************************\
2198    
2199     Function: XSetPlaneMask
2200     Inputs: display, gc, plane mask.
2201    
2202     Comments: What's a plane mask?
2203    
2204     \*****************************************************************/
2205    
2206     int
2207     XSetPlaneMask(display,gc,pmask)
2208     Display *display;
2209     GC gc;
2210     unsigned long pmask;
2211     {
2212     xtrace("XSetPlaneMask\n");
2213     gc->values.plane_mask=pmask;
2214     return 0;
2215     }
2216    
2217    
2218     int
2219     XSetTile(display,gc,tile)
2220     Display *display;
2221     GC gc;
2222     Pixmap tile;
2223     {
2224     xtrace("XSetTile\n");
2225     return 0;
2226     }
2227    
2228    
2229     StatusDef
2230     XAllocColorCells(display,cmap,cont,pmasks,np,pixels,nc)
2231     Display *display;
2232     Colormap cmap;
2233     BoolDef cont;
2234     unsigned long *pmasks;
2235     unsigned int np;
2236     unsigned long *pixels;
2237     unsigned int nc;
2238     {
2239     unsigned int i;
2240     xtrace("XAllocColorCells\n");
2241     for (i = 0;i<nc;i++)
2242     pixels[i] = i;
2243     if(np==1)
2244     {
2245     *pmasks = nc;
2246     }
2247     return 1;
2248     }
2249    
2250    
2251     /*****************************************************************\
2252    
2253     Function: XAllocColorPlanes
2254     Inputs: display, colour map, contiguous flag, pixel value list,
2255     number of colours, number of reds, greens, blues.
2256     Returned: red mask, green mask, blue mask, status.
2257    
2258     Comments: Works for True Colour only.
2259    
2260     \*****************************************************************/
2261    
2262     StatusDef
2263     XAllocColorPlanes(display,cmap,cont,pixels,nc,nr,ng,nb,rmask,gmask,bmask)
2264     Display *display;
2265     Colormap cmap;
2266     BoolDef cont;
2267     unsigned long *pixels;
2268     int nc;
2269     int nr,ng,nb;
2270     unsigned long *rmask,*gmask,*bmask;
2271     {
2272     xtrace("XAllocColorPlanes\n");
2273     *rmask=255;
2274     *gmask=255<<8;
2275     *bmask=255<<16;
2276     return (1);
2277     }
2278    
2279    
2280     StatusDef
2281     XAllocNamedColor(Display *display,
2282     Colormap cmap, const char *cname,
2283     XColor *cell, XColor *rgb)
2284     {
2285     xtrace("XAllocNamedColor\n");
2286     return 0;
2287     }
2288    
2289    
2290     Colormap
2291     XCreateColormap(display,w,visual,alloc)
2292     Display *display;
2293     Window w;
2294     Visual *visual;
2295     int alloc;
2296     {
2297     xtrace("XCreateColormap\n");
2298     return 0;
2299     }
2300    
2301    
2302     StatusDef
2303     XGetStandardColormap(display,w,cmapinf,prop)
2304     Display *display;
2305     Window w;
2306     XStandardColormap *cmapinf;
2307     Atom prop;
2308     {
2309     xtrace("XGetStandardColormap\n");
2310     return 0;
2311     }
2312    
2313     StatusDef
2314     XAllocColor(display,cmap,xc)
2315     Display *display;
2316     Colormap cmap;
2317     XColor *xc;
2318     {
2319     xtrace("XAllocColor\n");
2320     xc->pixel = RGB((BYTE) (xc->red>>8)&0xff, (BYTE) (xc->green>>8)&0xff, (BYTE) (xc->blue>>8)&0xff);
2321     return 1;
2322     }
2323    
2324     int
2325     XQueryColor(display,cmap,cell)
2326     Display *display;
2327     Colormap cmap;
2328     XColor *cell;
2329     {
2330     xtrace("XQueryColor\n");
2331     cell->red = (cell->pixel>>8)&0x0ff00;
2332     cell->green = (cell->pixel)&0x0ff00;
2333     cell->blue = (cell->pixel<<8)&0x0ff00;
2334     return 1;
2335     }
2336    
2337    
2338     int
2339     XQueryColors(display,cmap,cells,nc)
2340     Display *display;
2341     Colormap cmap;
2342     XColor *cells;
2343     int nc;
2344     {
2345     int i;
2346    
2347     xtrace("XQueryColors\n");
2348     for (i=0;i<nc;i++)
2349     {
2350     cells[i].red=(cells[i].pixel>>8)&0xff00;
2351     cells[i].green=(cells[i].pixel)&0xff00;
2352     cells[i].blue=(cells[i].pixel<<8)&0xff00;
2353     }
2354     return 0;
2355     }
2356    
2357    
2358     int
2359     XStoreColor(display,cmap,cell)
2360     Display *display;
2361     Colormap cmap;
2362     XColor *cell;
2363     {
2364     xtrace("XStoreColor\n");
2365     return 0;
2366     }
2367    
2368    
2369    
2370     int
2371     XStoreColors(display,cmap,cells,nc)
2372     Display *display;
2373     Colormap cmap;
2374     XColor *cells;
2375     int nc;
2376     {
2377     int i;
2378     xtrace("XStoreColors\n");
2379     return 0;
2380     }
2381    
2382     char **
2383     XGetFontPath(display,nps)
2384     Display *display;
2385     int *nps;
2386     {
2387     xtrace("XGetFontPath\n");
2388     return (NULL);
2389     }
2390    
2391    
2392     BoolDef
2393     XGetFontProperty(fstruct,atom,val)
2394     XFontStruct *fstruct;
2395     Atom atom;
2396     unsigned long *val;
2397     {
2398     xtrace("XGetFontProperty\n");
2399     return (0);
2400     }
2401    
2402     static BYTE
2403     getCharSetFromName(const char *name,char **lang)
2404     {
2405     static struct {
2406     char *label;
2407     BYTE id;
2408     } charset[] = {
2409     "-gb2312", GB2312_CHARSET,
2410     "-big5", CHINESEBIG5_CHARSET,
2411     "-jis", SHIFTJIS_CHARSET,
2412     NULL, DEFAULT_CHARSET
2413     };
2414     int i;
2415     char *p;
2416     if (!name)
2417     {
2418     if (lang) *lang=NULL;
2419     return DEFAULT_CHARSET;
2420     }
2421     else if (lang) *lang=(char *)name+strlen((char *)name);
2422     for (i=0; charset[i].label; i++)
2423     if (NULL!=(p=strstr(name, charset[i].label)))
2424     {
2425     if (lang) *lang=p;
2426     break;
2427     }
2428     return charset[i].id;
2429     }
2430    
2431     /* attempts to translate the font name into
2432     ** something win32 understands.
2433     **
2434     */
2435     Font
2436     NT_loadfont(name)
2437     char *name;
2438     {
2439     LOGFONT lf;
2440     HFONT hfont;
2441     char *p,*q,*lang;
2442     int size = 0;
2443     char buff[33];
2444    
2445     memset(&lf,0,sizeof(lf));
2446     lf.lfHeight = -13;
2447    
2448     lf.lfWeight = FW_NORMAL;
2449     lf.lfFaceName[0]='\0';
2450    
2451     lf.lfCharSet = getCharSetFromName(name,&lang);
2452    
2453     if (name && strstr(name,"-bold"))
2454     {
2455     lf.lfWeight = FW_BOLD;
2456     }
2457     for(p=name, q=buff; p&&p<=lang; p++)
2458     {
2459     if (((!*p || *p=='-') && q!=buff) || (q-buff>31))
2460     {
2461     *q++='\0';
2462     if (lf.lfFaceName[0]=='\0')
2463     {
2464     if (isalpha(buff[0]) || IsDBCSLeadByte(buff[0]))
2465     strcpy(lf.lfFaceName, buff);
2466     else if (isdigit(buff[0]) && ((q=strchr(buff,'x')) || (q=strchr(buff,'X'))))
2467     {
2468     strcpy(lf.lfFaceName, "Courier New");
2469     size = -atoi(q+1);
2470     }
2471     else if (size == 0 && isdigit(buff[0]))
2472     size = -atoi(buff);
2473     }
2474     else if (size == 0 && isdigit(buff[0]))
2475     {
2476     size = -atoi(buff);
2477     }
2478     q = buff;
2479     }
2480     else
2481     *q++ = *p;
2482     if (!*p) break;
2483     }
2484    
2485     if (size > 99)
2486     lf.lfHeight = - (size/10);
2487     else if (size)
2488     lf.lfHeight = - size;
2489    
2490     if (!strcmp(lf.lfFaceName,"lucidatypewriter"))
2491     strcpy(lf.lfFaceName,"Lucida Console");
2492     else if (lf.lfFaceName[0]=='\0'&&lf.lfCharSet==DEFAULT_CHARSET)
2493     strcpy(lf.lfFaceName,"Courier New");
2494     hfont = CreateFontIndirect(&lf);
2495     return (Font)hfont;
2496     }
2497    
2498     XFontStruct *
2499     XLoadQueryFont(Display *display, const char *name)
2500     {
2501     XFontStruct *fs;
2502     TEXTMETRIC tm;
2503     HDC hdc;
2504     HWND root;
2505     HFONT old;
2506     int i;
2507    
2508     xtrace("XLoadQueryFont\n");
2509     fs = allocateMemory(sizeof(XFontStruct));
2510     fs->fid = NT_loadfont(name);
2511    
2512     root=GetDesktopWindow();
2513     hdc=GetDC(root);
2514     old = SelectObject(hdc, (HFONT)fs->fid);
2515     GetTextMetrics(hdc, &tm);
2516     fs->min_bounds.width = tm.tmAveCharWidth;
2517     fs->max_bounds.width = tm.tmMaxCharWidth;
2518     fs->n_properties = 0;
2519     fs->properties = NULL;
2520     fs->min_char_or_byte2 =tm.tmFirstChar;
2521     fs->max_char_or_byte2 =tm.tmLastChar;
2522     fs->per_char = (XCharStruct*)allocateMemory(sizeof(XCharStruct)*(tm.tmLastChar+1));
2523     ZeroMemory(fs->per_char, sizeof(XCharStruct)*(tm.tmLastChar+1));
2524    
2525     if (!(tm.tmPitchAndFamily & TMPF_FIXED_PITCH)) {
2526     for (i=tm.tmFirstChar; i<=tm.tmLastChar; i++) {
2527     fs->per_char[i].width = tm.tmAveCharWidth;
2528     fs->per_char[i].rbearing = tm.tmAveCharWidth;
2529     }
2530     } else if (tm.tmPitchAndFamily & TMPF_TRUETYPE) {
2531     for (i=tm.tmFirstChar; i<=tm.tmLastChar; i++)
2532     {
2533     ABC abc;
2534     if (!GetCharABCWidths(hdc,i,i,&abc))
2535     {
2536     abc.abcA = 0;
2537     abc.abcB = tm.tmAveCharWidth;
2538     abc.abcC = 0;
2539     }
2540     fs->per_char[i].lbearing = abc.abcA;
2541     fs->per_char[i].width = abc.abcB;
2542     fs->per_char[i].rbearing = abc.abcB+abc.abcC;
2543     }
2544     } else {
2545     for (i=tm.tmFirstChar; i<=tm.tmLastChar; i++)
2546     {
2547     INT fw;
2548     if (!GetCharWidth(hdc,i,i,&fw))
2549     {
2550     fw = tm.tmAveCharWidth;
2551     }
2552     fs->per_char[i].lbearing = 0;
2553     fs->per_char[i].width = fw;
2554     fs->per_char[i].rbearing = fw;
2555     }
2556     }
2557     if (getCharSetFromName(name,NULL) == DEFAULT_CHARSET)
2558     {
2559     int last = tm.tmLastChar;
2560    
2561     switch(tm.tmCharSet) {
2562     case CHINESEBIG5_CHARSET:
2563     case GB2312_CHARSET:
2564     case SHIFTJIS_CHARSET:
2565     if (tm.tmLastChar > 127) last = 127;
2566     break;
2567     }
2568    
2569     if (last >= tm.tmFirstChar)
2570     {
2571     fs->max_bounds = fs->per_char[last];
2572     fs->min_bounds = fs->per_char[last];
2573     for (i=tm.tmFirstChar; i<last; i++)
2574     {
2575     if (fs->per_char[i].lbearing > fs->max_bounds.lbearing)
2576     fs->max_bounds.lbearing = fs->per_char[i].lbearing;
2577     else if(fs->per_char[i].lbearing < fs->min_bounds.lbearing)
2578     fs->min_bounds.lbearing = fs->per_char[i].lbearing;
2579    
2580     if (fs->per_char[i].width > fs->max_bounds.width)
2581     fs->max_bounds.width = fs->per_char[i].width;
2582     else if(fs->per_char[i].width < fs->min_bounds.width)
2583     fs->min_bounds.width = fs->per_char[i].width;
2584    
2585     if (fs->per_char[i].rbearing > fs->max_bounds.rbearing)
2586     fs->max_bounds.rbearing = fs->per_char[i].rbearing;
2587     else if(fs->per_char[i].rbearing < fs->min_bounds.rbearing)
2588     fs->min_bounds.rbearing = fs->per_char[i].rbearing;
2589     }
2590     }
2591     }
2592     fs->ascent = tm.tmAscent;
2593     fs->descent= tm.tmDescent;
2594     SelectObject(hdc,old);
2595     ReleaseDC(root,hdc);
2596     return(fs);
2597     }
2598    
2599     XFontStruct *
2600     XQueryFont(display, font_id)
2601     Display *display;
2602     XID font_id;
2603     {
2604     static XFontStruct fs;
2605    
2606     xtrace("XQueryFont\n");
2607     return(&fs);
2608     }
2609    
2610     KeySym
2611     XKeycodeToKeysym(display, keycode, index)
2612     Display *display;
2613     unsigned int keycode;
2614     int index;
2615     {
2616     xtrace("XKeycodeToKeysym\n");
2617     if (keycode == 254) return XK_Alt_L;
2618     else if (keycode == 255) return XK_Num_Lock;
2619     return(NoSymbol);
2620     }
2621     KeyCode
2622     XKeysymToKeycode(display, keysym)
2623     Display *display;
2624     KeySym keysym;
2625     {
2626     xtrace("XKeycodeToKeysym\n");
2627     if (keysym == XK_Alt_L) return 254;
2628     else if (keysym == XK_Num_Lock) return 255;
2629     return(0);
2630     }
2631     KeySym
2632     XStringToKeysym(const char *str)
2633     {
2634     xtrace("XStringToKeysym\n");
2635     return(NoSymbol);
2636     }
2637    
2638     XModifierKeymap *
2639     XGetModifierMapping(display)
2640     Display *display;
2641     {
2642     XModifierKeymap *map = NULL;
2643     xtrace("XGetModifierMapping\n");
2644     map = (XModifierKeymap *)allocateMemory(sizeof(XModifierKeymap));
2645     map->max_keypermod = 1;
2646     map->modifiermap = (KeyCode *)allocateMemory(sizeof(KeyCode)*8);
2647     map->modifiermap[0]=0;
2648     map->modifiermap[1]=0;
2649     map->modifiermap[2]=0;
2650     map->modifiermap[3]=XKeysymToKeycode(display,XK_Alt_L);
2651     map->modifiermap[4]=0;
2652     map->modifiermap[5]=0;
2653     map->modifiermap[6]=0;
2654     map->modifiermap[7]=XKeysymToKeycode(display,XK_Num_Lock);
2655     return(map);
2656     }
2657     int
2658     XFreeModifiermap(XModifierKeymap *modmap)
2659     {
2660     xtrace("XFreeModifiermap\n");
2661     freeMemory(modmap->modifiermap);
2662     freeMemory(modmap);
2663     return 0;
2664     }
2665    
2666    
2667     int
2668     XSetFont(display,gc,font)
2669     Display *display;
2670     GC gc;
2671     Font font;
2672     {
2673     xtrace("XSetFont\n");
2674     gc->values.font = font;
2675     return 0;
2676     }
2677    
2678    
2679     int
2680     XSetFontPath(display,dirs,nd)
2681     Display *display;
2682     char **dirs;
2683     int nd;
2684     {
2685     xtrace("XSetFontPath\n");
2686     return 0;
2687     }
2688    
2689    
2690     /*****************************************************************\
2691    
2692     Function: XTextExtents
2693     Inputs: font structure, string, string length.
2694     Returned: writing direction, max ascent, max descent, font overall
2695     characteristics.
2696    
2697     Comments: The design of windows fonts is similar to X, as far as
2698     ascent and descent are concerned. However, they are
2699     positioned differently on the screen (see XDrawText).
2700    
2701     \*****************************************************************/
2702    
2703     static HDC desktopHDC;
2704     static int firstTE = TRUE;
2705     int
2706     XTextExtents(fstruct,str,nc,dir,ascent,descent,overall)
2707     XFontStruct *fstruct;
2708     const char *str;
2709     int nc;
2710     int *dir,*ascent,*descent;
2711     XCharStruct *overall;
2712     {
2713     TEXTMETRIC tmet;
2714     HDC hdc;
2715     SIZE tsize;
2716     HWND desktop;
2717     HFONT old;
2718    
2719     xtrace("XTextExtents\n");
2720     if (firstTE)
2721     {
2722     firstTE = FALSE;
2723     desktop=GetDesktopWindow();
2724     desktopHDC=GetDC(desktop);
2725     }
2726     hdc = desktopHDC;
2727     old = SelectObject(hdc, (HFONT)fstruct->fid);
2728     GetTextMetrics(hdc,&tmet);
2729     GetTextExtentPoint(hdc,str,nc,&tsize);
2730     *dir=FontLeftToRight;
2731     *ascent=tmet.tmAscent + 1;
2732     *descent=tmet.tmDescent;
2733     overall->ascent=(short)(tmet.tmAscent + 1);
2734     overall->descent=(short)tmet.tmDescent;
2735     overall->width=(short)tsize.cx;
2736     overall->lbearing=0;
2737     overall->rbearing=(short)tsize.cx;
2738     /* cjh_rel_dc(desktop,hdc);*/
2739     SelectObject(hdc,old);
2740     return 0;
2741     }
2742    
2743    
2744     int
2745     XTextExtents16(fstruct,str,nc,dir,ascent,descent,overall)
2746     XFontStruct *fstruct;
2747     const XChar2b *str;
2748     int nc;
2749     int *dir,*ascent,*descent;
2750     XCharStruct *overall;
2751     {
2752     xtrace("XTextExtents16\n");
2753     return 0;
2754     }
2755    
2756    
2757     /*****************************************************************\
2758    
2759    
2760     Function: XTextWidth
2761     Inputs: font structure, string, length of string.
2762     Returned: String width in pixels.
2763    
2764     Comments:
2765    
2766     \*****************************************************************/
2767    
2768     int
2769     XTextWidth(fstruct,str,co)
2770     XFontStruct *fstruct;
2771     const char *str;
2772     int co;
2773     {
2774     HDC hdc;
2775     SIZE tsize;
2776     HWND root;
2777     HFONT old;
2778     xtrace("XTextWidth\n");
2779    
2780     if(firstTE)
2781     {
2782     firstTE = FALSE;
2783     root=GetDesktopWindow();
2784     hdc=GetDC(root);
2785     }
2786     old = SelectObject(hdc, (HFONT)fstruct->fid);
2787     GetTextExtentPoint(hdc,str,co,&tsize);
2788     SelectObject(hdc,old);
2789     /*cjh_rel_dc(root,hdc);*/
2790     return (tsize.cx);
2791     }
2792    
2793    
2794     int
2795     XTextWidth16(fstruct,str,co)
2796     XFontStruct *fstruct;
2797     const XChar2b *str;
2798     int co;
2799     {
2800     xtrace("XTextWidth16\n");
2801     return 0;
2802     }
2803    
2804    
2805     int
2806     XGetErrorDatabaseText(display,name,msg,defstr,buf,len)
2807     Display *display;
2808     const char *name,*msg;
2809     const char *defstr;
2810     char *buf;
2811     int len;
2812     {
2813     static char def_err[]="Errors not implemented";
2814     int n;
2815    
2816     xtrace("XGetErrorDatabaseText\n");
2817     while (n<len && def_err[n] != 0)
2818     *(buf+n)=def_err[n++];
2819     *(buf+n)=0;
2820     return 0;
2821     }
2822    
2823    
2824     int
2825     XGetErrorText(display,code,buf,len)
2826     Display *display;
2827     int code;
2828     char *buf;
2829     int len;
2830     {
2831     xtrace("XGetErrorText\n");
2832     return 0;
2833     }
2834    
2835    
2836     XErrorHandler
2837     XSetErrorHandler(handler)
2838     XErrorHandler handler;
2839     {
2840     xtrace("XSetErrorHandler\n");
2841     return 0;
2842     }
2843    
2844    
2845     /*****************************************************************\
2846    
2847    
2848     Function: XDefaultScreen
2849     Inputs: display
2850     Returned: default screen number
2851    
2852     Comments:
2853    
2854     \*****************************************************************/
2855    
2856     int
2857     XDefaultScreen(display)
2858     Display *display;
2859     {
2860     xtrace("XDefaultScreen\n");
2861     return (display->default_screen);
2862     }
2863    
2864     Visual *
2865     XDefaultVisual(display, screen)
2866     Display *display;
2867     int screen;
2868     {
2869     xtrace("XDefaultVisual\n");
2870     return DefaultVisual(display, screen);
2871     }
2872     int
2873     XDefaultDepth(display, screen)
2874     Display *display;
2875     int screen;
2876     {
2877     xtrace("XDefaultDepth\n");
2878     return DefaultDepth(display, screen);
2879     }
2880     Colormap
2881     XDefaultColormap(display, screen)
2882     Display *display;
2883     int screen;
2884     {
2885     xtrace("XDefaultColormap\n");
2886     return DefaultColormap(display, screen);
2887     }
2888    
2889    
2890     /*****************************************************************\
2891    
2892    
2893     Function: XScreenOfDisplay
2894     Inputs: display,screen number
2895     Returned: screen list.
2896    
2897     Comments:
2898    
2899     \*****************************************************************/
2900    
2901     Screen *
2902     XScreenOfDisplay(display,scr)
2903     Display *display;
2904     int scr;
2905     {
2906     xtrace("XScreenOfDisplay\n");
2907     return (display->screens);
2908     }
2909    
2910    
2911     Cursor
2912     XCreateFontCursor(display,shape)
2913     Display *display;
2914     unsigned int shape;
2915     {
2916     xtrace("XCreateFontCursor\n");
2917     return 0;
2918     }
2919    
2920    
2921     int
2922     XRecolorCursor(display,cursor,fg,bg)
2923     Display *display;
2924     Cursor cursor;
2925     XColor *fg,*bg;
2926     {
2927     xtrace("XRecolorCursor\n");
2928     return 0;
2929     }
2930    
2931    
2932     /*****************************************************************\
2933    
2934    
2935     Function: XWarpPointer
2936     Inputs: display, source window, destination window, source window
2937     geometry, destination x, y.
2938    
2939     Comments: Not knowingly tested.
2940    
2941     \*****************************************************************/
2942    
2943     int
2944     XWarpPointer(display,sw,dw,sx,sy,swidth,sheight,dx,dy)
2945     Display *display;
2946     Window sw,dw;
2947     int sx,sy;
2948     unsigned int swidth,sheight;
2949     int dx,dy;
2950     {
2951     NT_window *ntsw=(NT_window *)sw;
2952     NT_window *ntdw=(NT_window *)dw;
2953    
2954     POINT cpt,tmp;
2955     RECT srct;
2956     HDC hDC;
2957    
2958     xtrace("XWarpPointer\n");
2959     GetCursorPos(&cpt);
2960     if (ntsw==None)
2961     {
2962     if (ntdw==None)
2963     SetCursorPos(dx,dy);
2964     else
2965     {
2966     tmp.x=dx;
2967     tmp.y=dy;
2968     ClientToScreen(ntdw->w,&tmp);
2969     SetCursorPos(tmp.x,tmp.y);
2970     }
2971     }
2972     else
2973     {
2974     GetWindowRect(ntsw->w,&srct);
2975     tmp.x=sx;
2976     tmp.y=sy;
2977     ClientToScreen(ntsw->w,&tmp);
2978     if (swidth==0)
2979     swidth=srct.right-sx;
2980     if (sheight==0)
2981     sheight=srct.bottom-sy;
2982     hDC = cjh_get_dc(ntdw);
2983     if (cpt.x>=tmp.x && cpt.x<tmp.x+(int)swidth &&
2984     cpt.y>=tmp.y && cpt.y<tmp.y+(int)sheight &&
2985     PtVisible(hDC,cpt.x,cpt.y))
2986     {
2987     if (ntdw==None)
2988     SetCursorPos(cpt.x+dx,cpt.y+dy);
2989     else
2990     {
2991     tmp.x=dx;
2992     tmp.y=dy;
2993     ClientToScreen(ntdw->w,&tmp);
2994     SetCursorPos(tmp.x,tmp.y);
2995     }
2996     }
2997     cjh_rel_dc(ntdw,hDC);
2998     }
2999     return 0;
3000     }
3001    
3002    
3003     /*****************************************************************\
3004    
3005    
3006     Function: XBell
3007     Inputs: display, percent loudness.
3008    
3009     Comments: Don't throw away your CD just yet.
3010    
3011     \*****************************************************************/
3012    
3013     int
3014     XBell(display,pc)
3015     Display *display;
3016     int pc;
3017     {
3018     xtrace("XBell\n");
3019     MessageBeep(MB_OK);
3020     return 0;
3021     }
3022    
3023    
3024     /*****************************************************************\
3025    
3026    
3027     Function: XGetInputFocus
3028     Inputs: display, focus window, revert to window.
3029    
3030     Comments: We don't have the data in place for the revert to field
3031     to work.
3032    
3033     \*****************************************************************/
3034    
3035     int
3036     XGetInputFocus(display,focus,revto)
3037     Display *display;
3038     Window *focus;
3039     int *revto;
3040     {
3041     xtrace("XGetInputFocus\n");
3042     *focus=(Window)GetFocus(); /* Note: returns NULL if the focus window */
3043     revto=RevertToNone; /* belongs to another thread. */
3044     return 0;
3045     }
3046    
3047    
3048     /*****************************************************************\
3049    
3050    
3051     Function: XSetInputFocus
3052     Inputs: display, focus window, revert to window, time.
3053    
3054     Comments: Set focus to requested client window.
3055    
3056     \*****************************************************************/
3057    
3058     int
3059     XSetInputFocus(display,focus,revto,time)
3060     Display *display;
3061     Window focus;
3062     int revto;
3063     Time time;
3064     {
3065     NT_window *ntw=(NT_window *)focus;
3066     xtrace("XSetInputFocus\n");
3067     SetFocus(ntw->w);
3068     return 0;
3069     }
3070    
3071    
3072     int
3073     XLookupString(event,buf,nbytes,keysym,status)
3074     XKeyEvent *event;
3075     char *buf;
3076     int nbytes;
3077     KeySym *keysym;
3078     XComposeStatus *status;
3079     {
3080     xtrace("XLookupString\n");
3081     *buf=event->keycode;
3082     *keysym=event->keycode;
3083     return 1;
3084     }
3085    
3086    
3087     int
3088     XRefreshKeyboardMapping(event)
3089     XMappingEvent *event;
3090     {
3091     xtrace("XRefreshKeyboardMapping\n");
3092     return 0;
3093     }
3094    
3095    
3096     int
3097     XSetClassHint(display,w,chints)
3098     Display *display;
3099     Window w;
3100     XClassHint *chints;
3101     {
3102     xtrace("XSetClassHint\n");
3103     return 0;
3104     }
3105    
3106    
3107     /*****************************************************************\
3108    
3109    
3110     Function: XSetNormalHints
3111     Inputs: display, window, size hints.
3112    
3113     Comments: Assuming the role of the window manager, we alter the
3114     window geometry as requested.
3115    
3116     \*****************************************************************/
3117    
3118     int
3119     XSetNormalHints(display,w,hints)
3120     Display *display;
3121     Window w;
3122     XSizeHints *hints;
3123     {
3124     NT_window *ntw=(NT_window *)w;
3125     UINT ff;
3126    
3127     xtrace("XSetNormalHints\n");
3128    
3129     if (!hints->flags&PPosition)
3130     ff=SWP_NOMOVE;
3131     else
3132     ff=0;
3133    
3134     if (!hints->flags&PSize)
3135     ff=ff|SWP_NOSIZE;
3136    
3137     if (hints->flags &USPosition)
3138     {
3139     ntw->x = hints->x;
3140     ntw->y = hints->y;
3141     }
3142     if (hints->flags & USSize)
3143     {
3144     ntw->wdth = hints->width;
3145     ntw->hght = hints->height;
3146     }
3147    
3148     if (hints->flags&PMinSize)
3149     {
3150     ntw->minx = hints->min_width;
3151     ntw->miny = hints->min_height;
3152     }
3153    
3154     if (VALID_WINDOW(ntw) && (hints->flags & USSize || hints->flags &USPosition))
3155     {
3156     SetWindowPos(ntw->w,HWND_TOPMOST,hints->x,hints->y,
3157     hints->width,hints->height,ff|SWP_SHOWWINDOW);
3158     }
3159     return 0;
3160     }
3161    
3162    
3163     int
3164     XSetWMHints(display,w,wmhints)
3165     Display *display;
3166     Window w;
3167     XWMHints *wmhints;
3168     {
3169     xtrace("XSetWMHints\n");
3170     return 0;
3171     }
3172    
3173    
3174     StatusDef
3175     XSetWMProtocols(display,w,prots,co)
3176     Display *display;
3177     Window w;
3178     Atom *prots;
3179     int co;
3180     {
3181     xtrace("XSetWMProtocols\n");
3182     return 0;
3183     }
3184    
3185    
3186     /*****************************************************************\
3187    
3188    
3189     Function: XStoreName
3190     Inputs: display, window, window name.
3191    
3192     Comments: Only set names to the frame windows, otherwise captions
3193     appear in the client areas.
3194    
3195     \*****************************************************************/
3196    
3197     int
3198     XStoreName(display,w,wname)
3199     Display *display;
3200     Window w;
3201     const char *wname;
3202     {
3203     NT_window *ntw=(NT_window *)w;
3204     int status = 0;
3205    
3206     xtrace("XStoreName\n");
3207     if (ntw->top_flag)
3208     {
3209     ntw->title_text = strdup(wname);
3210     if (VALID_WINDOW(ntw))
3211     status = SetWindowText (ntw->w , wname);
3212     }
3213     return(status);
3214     }
3215    
3216     StatusDef
3217     XFetchName(
3218     Display *display,
3219     Window w,
3220     char **window_name_return)
3221     {
3222     NT_window *ntw=(NT_window *)w;
3223     int status = 1;
3224     xtrace("XFetchName\n");
3225     *window_name_return = NULL;
3226     if (ntw->title_text!=NULL)
3227     {
3228     *window_name_return = strdup(ntw->title_text);
3229     status =0;
3230     }
3231     return(status);
3232     }
3233    
3234    
3235    
3236     /*****************************************************************\
3237    
3238    
3239     Function: XDoesBackingStore
3240     Inputs: screen
3241    
3242     Comments: No backing store at the moment. Windows doesn't seem
3243     to support it, unless we do it ourselves with compatible
3244     bitmaps.
3245    
3246     \*****************************************************************/
3247    
3248     int
3249     XDoesBackingStore(scr)
3250     Screen *scr;
3251     {
3252     xtrace("XDoesBackingStore\n");
3253     return(0);
3254     }
3255    
3256    
3257     XExtCodes *
3258     XInitExtension(display,name)
3259     Display *display;
3260     const char *name;
3261     {
3262     xtrace("XInitExtension\n");
3263     return 0;
3264     }
3265    
3266    
3267     /*****************************************************************\
3268    
3269    
3270     Function: XFree
3271     Inputs: data to be freed.
3272    
3273     Comments: This might need changing sometime. No crashes so far.
3274    
3275     \*****************************************************************/
3276    
3277     int
3278     XFree(data)
3279     void *data;
3280     {
3281     xtrace("XFree\n");
3282     freeMemory(data);
3283     return 0;
3284     }
3285    
3286     /*****************************************************************\
3287    
3288    
3289     Function: XServerVendor
3290     Inputs: display.
3291     Returned: string of vendor's name.
3292    
3293     Comments: Copied from the display structure.
3294    
3295     \*****************************************************************/
3296    
3297     char *
3298     XServerVendor(display)
3299     Display *display;
3300     {
3301     xtrace("XServerVendor\n");
3302     return (display->vendor);
3303     }
3304    
3305    
3306     int
3307     XSetIconName(display,w,iname)
3308     Display *display;
3309     Window w;
3310     const char *iname;
3311     {
3312     xtrace("XSetIconName\n");
3313     return 0;
3314     }
3315     int
3316     XGetIconName(display,w,iname)
3317     Display *display;
3318     Window w;
3319     char **iname;
3320     {
3321     xtrace("XGetIconName\n");
3322     *iname = NULL;
3323     return 0;
3324     }
3325    
3326    
3327     int
3328     XSetSelectionOwner(display, sel, owner, time)
3329     Display* display;
3330     Atom sel;
3331     Window owner;
3332     Time time;
3333     {
3334     HWND hwnd = owner ? ((NT_window*)owner)->w : NULL;
3335     HWND cowner = GetClipboardOwner();
3336     OpenClipboard(hwnd);
3337     if (cowner==hwnd)
3338     catchNextDestroyClipboard();
3339     EmptyClipboard();
3340     CloseClipboard();
3341     return 0;
3342     }
3343    
3344     Window
3345     XGetSelectionOwner(display,selection)
3346     Display* display;
3347     Atom selection;
3348     {
3349     HWND hwnd = NULL;
3350     Window w;
3351     xtrace("XGetSelectionOwner\n");
3352     hwnd = GetClipboardOwner();
3353     w = (Window)NT_find_window_from_id(hwnd);
3354     if (!w) w=None;
3355     return w;
3356     }
3357    
3358     /*****************************************************************\
3359    
3360     Function: NT_set_rop
3361     Inputs: window device context, X graphics context
3362    
3363     Comments: Sets the graphics drawing operation.
3364    
3365     \*****************************************************************/
3366    
3367     void
3368     NT_set_rop(hdc,gc)
3369     HDC hdc;
3370     GC gc;
3371     {
3372     switch (gc->values.function)
3373     {
3374     case GXclear:
3375     SetROP2(hdc,R2_BLACK);
3376     break;
3377    
3378     case GXand:
3379     SetROP2(hdc,R2_MASKPEN);
3380     break;
3381    
3382     case GXandReverse:
3383     SetROP2(hdc,R2_MASKPENNOT);
3384     break;
3385    
3386     case GXcopy:
3387     SetROP2(hdc,R2_COPYPEN);
3388     break;
3389    
3390     case GXnoop:
3391     SetROP2(hdc,R2_NOP);
3392     break;
3393    
3394     case GXxor:
3395     SetROP2(hdc,R2_XORPEN);/*XORPEN);*/
3396     break;
3397    
3398     case GXor:
3399     SetROP2(hdc,R2_MERGEPEN);
3400     break;
3401    
3402     case GXnor:
3403     SetROP2(hdc,R2_NOTMERGEPEN);
3404     break;
3405    
3406     case GXequiv:
3407     SetROP2(hdc,R2_NOTXORPEN);
3408     break;
3409    
3410     case GXinvert:
3411     SetROP2(hdc,R2_NOT);
3412     break;
3413    
3414     case GXorReverse:
3415     SetROP2(hdc,R2_MERGEPENNOT);
3416     break;
3417    
3418     case GXcopyInverted:
3419     SetROP2(hdc,R2_NOTCOPYPEN);
3420     break;
3421    
3422     case GXorInverted:
3423     SetROP2(hdc,R2_MERGENOTPEN);
3424     break;
3425    
3426     case GXnand:
3427     SetROP2(hdc,R2_NOTMASKPEN);
3428     break;
3429    
3430     case GXset:
3431     SetROP2(hdc,R2_WHITE);
3432     break;
3433     }
3434     }
3435    
3436     /*****************************************************************\
3437    
3438     Function: NT_check_update_GC
3439     Inputs: gc - Graphics Context
3440    
3441     Comments: Check what has changed in the GC and modify the
3442     pen and brush accordingly.
3443    
3444     \*****************************************************************/
3445     static int
3446     NT_check_update_GC(gc)
3447     GC gc;
3448     {
3449     DWORD style=PS_GEOMETRIC;
3450     LOGBRUSH lbr;
3451     int width;
3452     NTGC *lntgc;
3453    
3454     if ( gc->ext_data == NULL )
3455     {
3456     gc->ext_data = (XExtData *)allocateMemory(sizeof(XExtData));
3457     lntgc = (NTGC *)allocateMemory(sizeof(NTGC));
3458     gc->ext_data->private_data = (char *)lntgc;
3459     lntgc->pen = INVALID_HANDLE;
3460     lntgc->brush = INVALID_HANDLE;
3461     lntgc->bgbrush = INVALID_HANDLE;
3462     gc->dirty=~0;
3463     }
3464    
3465     if ((gc->dirty & GCForeground) ||
3466     (gc->dirty & GCLineStyle) ||
3467     (gc->dirty & GCCapStyle) ||
3468     (gc->dirty & GCJoinStyle) ||
3469     (gc->dirty & GCLineWidth) )
3470     {
3471     lbr.lbStyle=BS_SOLID;
3472     lbr.lbColor=CNUMTORGB(gc->values.foreground);
3473     lbr.lbHatch=0;
3474    
3475     if (gc->values.line_style==LineDoubleDash)
3476     style|=PS_DASHDOT;
3477     else if (gc->values.line_style==LineOnOffDash)
3478     style|=PS_DASH;
3479     else
3480     style|=PS_SOLID;
3481    
3482     if (gc->values.cap_style==CapProjecting)
3483     style|=PS_ENDCAP_SQUARE;
3484     else if (gc->values.cap_style==CapRound)
3485     style|=PS_ENDCAP_ROUND;
3486     else
3487     style|=PS_ENDCAP_FLAT;
3488    
3489     if (gc->values.join_style==JoinRound)
3490     style|=PS_JOIN_ROUND;
3491     else if (gc->values.join_style==JoinMiter)
3492     style|=PS_JOIN_MITER;
3493     else
3494     style|=PS_JOIN_BEVEL;
3495     width=gc->values.line_width;
3496     if (width==0)
3497     width=1;
3498    
3499     lntgc = (NTGC *)gc->ext_data->private_data;
3500     if ( lntgc->pen != INVALID_HANDLE )
3501     DeleteObject(lntgc->pen);
3502    
3503     lntgc->pen = ExtCreatePen(style,width,&lbr,0,NULL);
3504     }
3505     if (gc->values.fill_style != FillSolid)
3506     {
3507     if ((gc->dirty & GCStipple))
3508     {
3509     NT_window *pixmap = (NT_window *)gc->values.stipple;
3510     lntgc->brush = CreatePatternBrush(pixmap->hBitmap);
3511     }
3512     }
3513     else if ((gc->dirty & GCForeground) )
3514     {
3515     lntgc = (NTGC *)gc->ext_data->private_data;
3516     if ( lntgc->brush != INVALID_HANDLE )
3517     DeleteObject(lntgc->brush);
3518     lntgc->brush = CreateSolidBrush(CNUMTORGB(gc->values.foreground));
3519    
3520     }
3521    
3522     if ((gc->dirty & GCBackground) )
3523     {
3524     lntgc = (NTGC *)gc->ext_data->private_data;
3525     if ( lntgc->bgbrush != INVALID_HANDLE )
3526     DeleteObject(lntgc->bgbrush);
3527     lntgc->bgbrush = CreateSolidBrush(CNUMTORGB(gc->values.background));
3528    
3529     }
3530    
3531     gc->dirty = 0;
3532    
3533     return(1);
3534     }
3535    
3536    
3537     /*****************************************************************\
3538    
3539     Function: NT_get_GC_pen
3540     Inputs: device context, graphics context
3541    
3542     Comments: Sets the device context and pen according to the
3543     graphics context.
3544    
3545     \*****************************************************************/
3546     static HPEN
3547     NT_get_GC_pen(hdc,gc)
3548     HDC hdc;
3549     GC gc;
3550     {
3551     NTGC *lntgc;
3552    
3553     NT_check_update_GC(gc);
3554     NT_set_rop(hdc,gc);
3555    
3556     lntgc = (NTGC *)gc->ext_data->private_data;
3557    
3558     return(lntgc->pen);
3559     }
3560    
3561    
3562     /*****************************************************************\
3563    
3564     Function: NT_get_GC_brush
3565     Inputs: device context, graphics context
3566     Returns: handle for brush.
3567    
3568     Comments: Same as above for painting operations.
3569    
3570     \*****************************************************************/
3571     static HBRUSH
3572     NT_get_GC_brush(hdc,gc)
3573     HDC hdc;
3574     GC gc;
3575     {
3576     NTGC *lntgc;
3577    
3578     NT_check_update_GC(gc);
3579    
3580     if (gc->values.fill_rule==EvenOddRule)
3581     SetPolyFillMode(hdc,ALTERNATE);
3582     else
3583     SetPolyFillMode(hdc,WINDING);
3584    
3585     if (gc->values.fill_style == FillSolid ||
3586     gc->values.fill_style == FillOpaqueStippled)
3587     {
3588     SetTextColor(hdc, CNUMTORGB(gc->values.foreground));
3589     SetBkColor(hdc, CNUMTORGB(gc->values.background));
3590     }
3591    
3592     NT_set_rop(hdc,gc);
3593    
3594     lntgc = (NTGC *)gc->ext_data->private_data;
3595    
3596     return(lntgc->brush);
3597     }
3598    
3599     static HBRUSH
3600     NT_get_GC_bgbrush(hdc,gc)
3601     HDC hdc;
3602     GC gc;
3603     {
3604     NTGC *lntgc;
3605     NT_check_update_GC(gc);
3606     lntgc = (NTGC *)gc->ext_data->private_data;
3607     return(lntgc->bgbrush);
3608     }
3609    
3610    
3611    
3612     /*****************************************************************\
3613    
3614     Function: NT_deg64_to_rad
3615     Inputs: angle (in 64ths of a degree)
3616    
3617     Comments: Converts int angle to double in radians.
3618    
3619     \*****************************************************************/
3620    
3621     double
3622     NT_deg64_to_rad(a)
3623     int a;
3624     {
3625     return ((double)a/64.0*0.017453);
3626     }
3627    
3628    
3629     /******************************************************************/
3630     /* */
3631     /* Atoms and properties code. */
3632     /* */
3633     /******************************************************************/
3634    
3635     static char **nt_atoms;
3636     static int num_nt_atoms = 0;
3637     static int max_num_nt_atoms = 0;
3638     #define ATOMS_BLOCK_SIZE 40
3639    
3640     /******************************************************************\
3641    
3642     Function: XInternAtom
3643     Inputs: Display, property name, creation flag.
3644    
3645     Comments: Could be made much more efficient.
3646    
3647     \******************************************************************/
3648    
3649     Atom
3650     XInternAtom(display, property_name, only_if_exists)
3651     Display *display;
3652     const char *property_name;
3653     BoolDef only_if_exists;
3654     {
3655     int i;
3656     char **new_nt_atoms;
3657    
3658     xtrace("XInternAtom\n");
3659     if (strcmp(property_name,"VT_SELECTION")==0)
3660     {
3661     return XA_LAST_PREDEFINED + 667;
3662     }
3663    
3664     for (i=0;i< num_nt_atoms ;i++)
3665     if (strcmp(nt_atoms[i],property_name) == 0)
3666     return XA_LAST_PREDEFINED + i;
3667    
3668     if (only_if_exists)
3669     return None;
3670    
3671     if (num_nt_atoms >= max_num_nt_atoms)
3672     {
3673     new_nt_atoms = (char **)realloc(nt_atoms,(max_num_nt_atoms + ATOMS_BLOCK_SIZE)*sizeof(char *));
3674     if (!new_nt_atoms)
3675     return None;
3676     nt_atoms = new_nt_atoms;
3677     max_num_nt_atoms+= ATOMS_BLOCK_SIZE;
3678     nt_atoms[num_nt_atoms] = allocateMemory(strlen(property_name)+1);
3679     if (!nt_atoms[num_nt_atoms])
3680     return None;
3681     strcpy(nt_atoms[num_nt_atoms],property_name);
3682     return (XA_LAST_PREDEFINED + num_nt_atoms++);
3683     }
3684     }
3685    
3686     /******************************************************************\
3687    
3688     Function: XGetAtomName
3689     Inputs: Display,Atom
3690    
3691     Comments: None.
3692    
3693     \******************************************************************/
3694     char *
3695     XGetAtomName(display,atom)
3696     Display *display;
3697     Atom atom;
3698     {
3699     char *ret_string;
3700     xtrace("XGetAtomName\n");
3701     if (atom > num_nt_atoms + XA_LAST_PREDEFINED)
3702     return NULL;
3703    
3704     if (! (ret_string = allocateMemory(strlen(nt_atoms[atom - XA_LAST_PREDEFINED])+1)))
3705     return FALSE;
3706    
3707     strcpy(ret_string,nt_atoms[atom]);
3708    
3709     return ret_string;
3710     }
3711    
3712     /******************************************************************\
3713    
3714     Function: XChangeProperty
3715     Inputs: Display,Window,Property,type,format,mode,data,
3716     nelements.
3717    
3718     Comments: None.
3719    
3720     \******************************************************************/
3721     int
3722     XChangeProperty(
3723     Display *display,
3724     Window window,
3725     Atom property,
3726     Atom type,
3727     int format,
3728     int mode,
3729     const unsigned char *data,
3730     int nelements)
3731     {
3732     NT_window *ntw=(NT_window *)window;
3733     struct NT_prop_list *wanderer, *new;
3734     xtrace("XChangeProperty\n");
3735    
3736     if (property == XA_CUT_BUFFER0 && type==XA_STRING)
3737     {
3738     HGLOBAL handle=NULL;
3739     char *buffer=NULL;
3740     int i,j,cr=0;
3741     for (i=0; i<nelements; i++)
3742     if (data[i]=='\n' && (i==0 || data[i-1]!='\r')) cr++;
3743    
3744     handle = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE, nelements+cr+1);
3745     if (!handle) return;
3746     OpenClipboard(ntw->w);
3747     buffer = GlobalLock(handle);
3748     for (i=j=0; i<nelements; buffer[j++]=data[i++])
3749     if (data[i]=='\n' && (i==0 || data[i-1]!='\r')) buffer[j++]='\r';
3750     buffer[j++]='\0';
3751     GlobalUnlock(handle);
3752     SetClipboardData(CF_TEXT, handle);
3753     handle = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE, sizeof(LCID));
3754     if (handle) {
3755     *(LCID*)GlobalLock(handle) = GetThreadLocale();
3756     GlobalUnlock(handle);
3757     SetClipboardData(CF_LOCALE, handle);
3758     }
3759     CloseClipboard();
3760     return;
3761     }
3762     }
3763    
3764     int
3765     XDeleteProperty(
3766     Display *display,
3767     Window w,
3768     Atom property)
3769     {
3770     return 0;
3771     }
3772    
3773     static char *
3774     NT_getClipboard()
3775     {
3776     char *ret = NULL;
3777     char *s,*t;
3778     int size, format=0;
3779     HGLOBAL handle;
3780     LPVOID data;
3781     OpenClipboard(NULL);
3782     for (format = EnumClipboardFormats(format); format; format = EnumClipboardFormats(format)) {
3783     if (format != CF_TEXT && format != CF_UNICODETEXT) continue;
3784     handle = GetClipboardData(format);
3785     if (handle==NULL) break;
3786     data = GlobalLock(handle);
3787     if (format == CF_UNICODETEXT) {
3788     int conv = CP_THREAD_ACP;
3789     size = WideCharToMultiByte(conv,0,data,-1,NULL,0,NULL,NULL);
3790     if (size == 0) /* NT doesn't support CF_THREAD_ACP */
3791     size = WideCharToMultiByte( (conv = CP_UTF8),0,data,-1,NULL,0,NULL,NULL);
3792     if (size==0) continue; /* let windows convert it */
3793     ret = allocateMemory(size);
3794     WideCharToMultiByte(conv, 0, data, -1, ret, size, NULL, NULL);
3795     } else {
3796     size = strlen(data)+1;
3797     ret = allocateMemory(size);
3798     strcpy(ret,data);
3799     }
3800     GlobalUnlock(handle);
3801     break;
3802     }
3803     CloseClipboard();
3804     for (s=t=ret;s && (*t=*s++);) if (*t!='\r') t++;
3805     return ret;
3806     }
3807    
3808     int
3809     XGetWindowProperty(display,window,property,long_offset,long_length,delete,
3810     req_type,actual_type_return,actual_format_return,
3811     nitems_return,bytes_after_return,prop_return)
3812     Display *display;
3813     Window window;
3814     Atom property;
3815     long long_offset;
3816     long long_length;
3817     BoolDef delete;
3818     Atom req_type;
3819     Atom *actual_type_return;
3820     int *actual_format_return;
3821     unsigned long *nitems_return;
3822     unsigned long *bytes_after_return;
3823     unsigned char **prop_return;
3824     {
3825     xtrace("XGetWindowProperty\n");
3826     if (property == XA_CUT_BUFFER0 && prop_return && (*prop_return = NT_getClipboard())) {
3827     *nitems_return=strlen(*prop_return);
3828     *actual_type_return = XA_STRING;
3829     *bytes_after_return = 0;
3830     }
3831     else {
3832     *prop_return = NULL;
3833     *actual_type_return = None;
3834     *actual_format_return = 0;
3835     *bytes_after_return = 0;
3836     }
3837     return 0;
3838     }
3839    
3840    
3841    
3842     char **
3843     XListExtensions(display,ret_num)
3844     Display *display;
3845     int *ret_num;
3846     {
3847     *ret_num = 0;
3848     xtrace("XListExtensions\n");
3849     return NULL;
3850     }
3851    
3852     XFreeExtensionList(list)
3853     char **list;
3854     {
3855     xtrace("XFreeExtensionList\n");
3856     return 0;
3857     }
3858    
3859     XChangeGC(
3860     Display* display,
3861     GC gc,
3862     unsigned long mask,
3863     XGCValues* gc_values)
3864     {
3865     xtrace("XChangeGC\n");
3866     if (mask&GCArcMode)
3867     gc->values.arc_mode=gc_values->arc_mode;
3868     if (mask&GCBackground)
3869     gc->values.background=gc_values->background;
3870     if (mask&GCCapStyle)
3871     gc->values.cap_style=gc_values->cap_style;
3872     if (mask&GCClipMask)
3873     gc->values.clip_mask=gc_values->clip_mask;
3874     if (mask&GCClipXOrigin)
3875     gc->values.clip_x_origin=gc_values->clip_x_origin;
3876     if (mask&GCClipYOrigin)
3877     gc->values.clip_y_origin=gc_values->clip_y_origin;
3878     if (mask&GCDashList)
3879     gc->values.dashes=gc_values->dashes;
3880     if (mask&GCDashOffset)
3881     gc->values.dash_offset=gc_values->dash_offset;
3882     if (mask&GCFillRule)
3883     gc->values.fill_rule=gc_values->fill_rule;
3884     if (mask&GCFillStyle)
3885     gc->values.fill_style=gc_values->fill_style;
3886     if (mask&GCFont)
3887     gc->values.font=gc_values->font;
3888     if (mask&GCForeground)
3889     gc->values.foreground=gc_values->foreground;
3890     if (mask&GCFunction)
3891     gc->values.function=gc_values->function;
3892     if (mask&GCGraphicsExposures)
3893     gc->values.graphics_exposures=gc_values->graphics_exposures;
3894     if (mask&GCJoinStyle)
3895     gc->values.join_style=gc_values->join_style;
3896     if (mask&GCLineStyle)
3897     gc->values.line_style=gc_values->line_style;
3898     if (mask&GCLineWidth)
3899     gc->values.line_width=gc_values->line_width;
3900     if (mask&GCPlaneMask)
3901     gc->values.plane_mask=gc_values->plane_mask;
3902     if (mask&GCStipple)
3903     gc->values.stipple=gc_values->stipple;
3904     if (mask&GCSubwindowMode)
3905     gc->values.subwindow_mode=gc_values->subwindow_mode;
3906     if (mask&GCTile)
3907     gc->values.tile=gc_values->tile;
3908     if (mask&GCTileStipXOrigin)
3909     gc->values.ts_x_origin=gc_values->ts_x_origin;
3910     if (mask&GCTileStipYOrigin)
3911     gc->values.ts_y_origin=gc_values->ts_y_origin;
3912     gc->dirty |= mask;
3913     return 0;
3914     }
3915    
3916     int
3917     XConnectionNumber(Display* display)
3918     {
3919     int fd;
3920     xtrace("XConnectionNumber\n");
3921     fd = open ("/dev/windows", O_NONBLOCK, 0);
3922     return fd;
3923     }
3924    
3925     XFreeFont(Display* display,XFontStruct* font_struct)
3926     {
3927     xtrace("XFreeFont\n");
3928     return 0;
3929     }
3930    
3931     char *
3932     _Xsetlocale(int category, const char *name)
3933     {
3934     xtrace("Xsetlocale\n");
3935     return (char *)name;
3936     }
3937    
3938     char *
3939     XSetLocaleModifiers(const char* modifier_list)
3940     {
3941     xtrace("XSetLocaleModifiers\n");
3942     return NULL;
3943     }
3944     XIM
3945     XOpenIM(
3946     Display* dpy,
3947     struct _XrmHashBucketRec* rdb,
3948     char* res_name,
3949     char* res_class)
3950     {
3951     xtrace("XOpenIM\n");
3952     return 0;
3953     }
3954     char *
3955     XGetIMValues(XIM im , ...)
3956     {
3957     xtrace("XGetIMValues\n");
3958     return NULL;
3959     }
3960     XIC
3961     XCreateIC(XIM im , ...)
3962     {
3963     xtrace("XCreateIC\n");
3964     return 0;
3965     }
3966     StatusDef
3967     XCloseIM(XIM im)
3968     {
3969     xtrace("XCloseIM\n");
3970     return 0;
3971     }
3972    
3973     char *
3974     XrmQuarkToString(void *quark)
3975     {
3976     xtrace("XrmQuarkToString\n");
3977     return NULL;
3978     }
3979    
3980     int
3981     XmbLookupString(
3982     XIC ic,
3983     XKeyPressedEvent* event,
3984     char* buffer_return,
3985     int bytes_buffer,
3986     KeySym* keysym_return,
3987     StatusDef* status_return)
3988     {
3989     xtrace("XmbLookupString\n");
3990     return 0;
3991     }
3992     int
3993     XmbTextPropertyToTextList(
3994     Display *display,
3995     XTextProperty *text_prop,
3996     char ***list_return,
3997     int *count_return)
3998     {
3999     xtrace("XmbTextPropertyToTextList\n");
4000     /* in the future copy this, for 2.7.1 rxvt leaks this, so don't yet */
4001     *list_return = (char **)allocateMemory(sizeof(char *));
4002     *list_return[0] = text_prop->value;
4003     *count_return = 1;
4004     return 0;
4005     }
4006    
4007     void
4008     XFreeStringList(char **list)
4009     {
4010     freeMemory(list);
4011     }
4012    
4013     int
4014     XmbTextListToTextProperty(
4015     Display *display,
4016     char **list,
4017     int count,
4018     XICCEncodingStyle style,
4019     XTextProperty *text_prop_return)
4020     {
4021     int ret = 0;
4022     if (count!=1) ret = XNoMemory;
4023     text_prop_return->value = strdup(list[0]);
4024     switch (style)
4025     {
4026     case XStringStyle: text_prop_return->encoding = XA_STRING; break;
4027     /* case XCompoundTextStyle: text_prop_return->encoding = XA_COMPOUND; break; */
4028     default: ret = XLocaleNotSupported;
4029     }
4030     text_prop_return->format = 8;
4031     text_prop_return->nitems = count;
4032     return ret;
4033     }
4034     void XmbDrawString(
4035     Display *display,
4036     Drawable d,
4037     XFontSet font_set,
4038     GC gc,
4039     int x, int y,
4040     char *string,
4041     int num_bytes)
4042     {
4043     xtrace("XmbDrawString\n");
4044     }
4045    
4046    
4047     void
4048     XSetICFocus(XIC ic)
4049     {
4050     xtrace("XSetICFocus\n");
4051     }
4052     void
4053     XUnsetICFocus(XIC ic)
4054     {
4055     xtrace("XUnsetICFocus\n");
4056     }
4057    
4058    
4059    
4060     /* lifted from emacs */
4061     /*
4062     * XParseGeometry parses strings of the form
4063     * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
4064     * width, height, xoffset, and yoffset are unsigned integers.
4065     * Example: "=80x24+300-49"
4066     * The equal sign is optional.
4067     * It returns a bitmask that indicates which of the four values
4068     * were actually found in the string. For each value found,
4069     * the corresponding argument is updated; for each value
4070     * not found, the corresponding argument is left unchanged.
4071     */
4072    
4073     static int
4074     read_integer (string, NextString)
4075     register char *string;
4076     char **NextString;
4077     {
4078     register int Result = 0;
4079     int Sign = 1;
4080    
4081     if (*string == '+')
4082     string++;
4083     else if (*string == '-')
4084     {
4085     string++;
4086     Sign = -1;
4087     }
4088     for (; (*string >= '0') && (*string <= '9'); string++)
4089     {
4090     Result = (Result * 10) + (*string - '0');
4091     }
4092     *NextString = string;
4093     if (Sign >= 0)
4094     return (Result);
4095     else
4096     return (-Result);
4097     }
4098    
4099     /* lifted from emacs */
4100     int
4101     XParseGeometry(
4102     const char* string,
4103     int* x,
4104     int* y,
4105     unsigned int* width,
4106     unsigned int* height)
4107     {
4108     int mask = NoValue;
4109     register char *strind;
4110     unsigned int tempWidth, tempHeight;
4111     int tempX, tempY;
4112     char *nextCharacter;
4113    
4114     if ((string == NULL) || (*string == '\0')) return (mask);
4115     if (*string == '=')
4116     string++; /* ignore possible '=' at beg of geometry spec */
4117    
4118     strind = (char *)string;
4119     if (*strind != '+' && *strind != '-' && *strind != 'x')
4120     {
4121     tempWidth = read_integer (strind, &nextCharacter);
4122     if (strind == nextCharacter)
4123     return (0);
4124     strind = nextCharacter;
4125     mask |= WidthValue;
4126     }
4127    
4128     if (*strind == 'x' || *strind == 'X')
4129     {
4130     strind++;
4131     tempHeight = read_integer (strind, &nextCharacter);
4132     if (strind == nextCharacter)
4133     return (0);
4134     strind = nextCharacter;
4135     mask |= HeightValue;
4136     }
4137    
4138     if ((*strind == '+') || (*strind == '-'))
4139     {
4140     if (*strind == '-')
4141     {
4142     strind++;
4143     tempX = -read_integer (strind, &nextCharacter);
4144     if (strind == nextCharacter)
4145     return (0);
4146     strind = nextCharacter;
4147     mask |= XNegative;
4148    
4149     }
4150     else
4151     {
4152     strind++;
4153     tempX = read_integer (strind, &nextCharacter);
4154     if (strind == nextCharacter)
4155     return (0);
4156     strind = nextCharacter;
4157     }
4158     mask |= XValue;
4159     if ((*strind == '+') || (*strind == '-'))
4160     {
4161     if (*strind == '-')
4162     {
4163     strind++;
4164     tempY = -read_integer (strind, &nextCharacter);
4165     if (strind == nextCharacter)
4166     return (0);
4167     strind = nextCharacter;
4168     mask |= YNegative;
4169    
4170     }
4171     else
4172     {
4173     strind++;
4174     tempY = read_integer (strind, &nextCharacter);
4175     if (strind == nextCharacter)
4176     return (0);
4177     strind = nextCharacter;
4178     }
4179     mask |= YValue;
4180     }
4181     }
4182    
4183     /* If strind isn't at the end of the string the it's an invalid
4184     geometry specification. */
4185    
4186     if (*strind != '\0') return (0);
4187    
4188     if (mask & XValue)
4189     *x = tempX;
4190     if (mask & YValue)
4191     *y = tempY;
4192     if (mask & WidthValue)
4193     *width = tempWidth;
4194     if (mask & HeightValue)
4195     *height = tempHeight;
4196     return (mask);
4197     }
4198    
4199     XResizeWindow(
4200     Display* display,
4201     Window w,
4202     unsigned int width,
4203     unsigned int height)
4204     {
4205     RECT r;
4206     NT_window *ntw=(NT_window *)w;
4207     xtrace("XResizeWindow\n");
4208     r.left = ntw->x;
4209     r.top = ntw->y;
4210     r.right = r.left + width;
4211     r.bottom = r.top + height;
4212     if (ntw->top_flag)
4213     AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW, FALSE);
4214     if (VALID_WINDOW(ntw))
4215     MoveWindow(ntw->w, r.left, r.top,
4216     r.right-r.left, r.bottom-r.top,TRUE);
4217     return 0;
4218     }
4219    
4220     void
4221     XSetWMNormalHints(Display* display,Window w,XSizeHints* hints)
4222     {
4223     xtrace("XSetWMNormalHints\n");
4224     XSetNormalHints(display,w,hints);
4225     }
4226    
4227     void
4228     XSetWMProperties(
4229     Display* display,
4230     Window w,
4231     XTextProperty* window_name,
4232     XTextProperty* icon_name,
4233     char** argv,
4234     int argc,
4235     XSizeHints* normal_hints,
4236     XWMHints* wm_hints,
4237     XClassHint* class_hints)
4238     {
4239     xtrace("XSetWMProperties\n");
4240     XSetNormalHints(display,w,normal_hints);
4241     }
4242     XDefineCursor(Display* display,Window w,Cursor cursor)
4243     {
4244     xtrace("XDefineCursor\n");
4245     return 0;
4246     }
4247    
4248     XMoveResizeWindow(
4249     Display* display,
4250     Window w,
4251     int x,
4252     int y,
4253     unsigned int width,
4254     unsigned int height)
4255     {
4256     NT_window *ntw=(NT_window *)w;
4257     xtrace("XMoveResizeWindow\n");
4258     ntw->x = x;
4259     ntw->y = y;
4260     ntw->wdth = width;
4261     ntw->hght = height;
4262     if (VALID_WINDOW(ntw)) {
4263     NT_moveWindow(ntw,TRUE);
4264     }
4265    
4266     }
4267    
4268     XMoveWindow(
4269     Display* display,
4270     Window w,
4271     int x,
4272     int y)
4273     {
4274     NT_window *ntw=(NT_window *)w;
4275     xtrace("XMoveWindow\n");
4276     ntw->x = x;
4277     ntw->y = y;
4278     if (VALID_WINDOW(ntw)) {
4279     NT_moveWindow(ntw,TRUE);
4280     }
4281     return 0;
4282     }
4283    
4284     /*
4285     * xcolors.c --
4286     *
4287     * This file contains the routines used to map from X color
4288     * names to RGB and pixel values.
4289     *
4290     * Copyright (c) 1996 by Sun Microsystems, Inc.
4291     *
4292     * See the file "license.terms" for information on usage and redistribution
4293     * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
4294     *
4295     * SCCS: @(#) xcolors.c 1.3 96/12/17 13:07:02
4296     */
4297    
4298     /*
4299     * Define an array that defines the mapping from color names to RGB values.
4300     * Note that this array must be kept sorted alphabetically so that the
4301     * binary search used in XParseColor will succeed.
4302     */
4303     typedef struct {
4304     char *name;
4305     unsigned char red;
4306     unsigned char green;
4307     unsigned char blue;
4308     } XColorEntry;
4309    
4310     static XColorEntry xColors[] = {
4311     "alice blue", 240, 248, 255,
4312     "AliceBlue", 240, 248, 255,
4313     "antique white", 250, 235, 215,
4314     "AntiqueWhite", 250, 235, 215,
4315     "AntiqueWhite1", 255, 239, 219,
4316     "AntiqueWhite2", 238, 223, 204,
4317     "AntiqueWhite3", 205, 192, 176,
4318     "AntiqueWhite4", 139, 131, 120,
4319     "aquamarine", 127, 255, 212,
4320     "aquamarine1", 127, 255, 212,
4321     "aquamarine2", 118, 238, 198,
4322     "aquamarine3", 102, 205, 170,
4323     "aquamarine4", 69, 139, 116,
4324     "azure", 240, 255, 255,
4325     "azure1", 240, 255, 255,
4326     "azure2", 224, 238, 238,
4327     "azure3", 193, 205, 205,
4328     "azure4", 131, 139, 139,
4329     "beige", 245, 245, 220,
4330     "bisque", 255, 228, 196,
4331     "bisque1", 255, 228, 196,
4332     "bisque2", 238, 213, 183,
4333     "bisque3", 205, 183, 158,
4334     "bisque4", 139, 125, 107,
4335     "black", 0, 0, 0,
4336     "blanched almond", 255, 235, 205,
4337     "BlanchedAlmond", 255, 235, 205,
4338     "blue", 0, 0, 255,
4339     "blue violet", 138, 43, 226,
4340     "blue1", 0, 0, 255,
4341     "blue2", 0, 0, 238,
4342     "blue3", 0, 0, 205,
4343     "blue4", 0, 0, 139,
4344     "BlueViolet", 138, 43, 226,
4345     "brown", 165, 42, 42,
4346     "brown1", 255, 64, 64,
4347     "brown2", 238, 59, 59,
4348     "brown3", 205, 51, 51,
4349     "brown4", 139, 35, 35,
4350     "burlywood", 222, 184, 135,
4351     "burlywood1", 255, 211, 155,
4352     "burlywood2", 238, 197, 145,
4353     "burlywood3", 205, 170, 125,
4354     "burlywood4", 139, 115, 85,
4355     "cadet blue", 95, 158, 160,
4356     "CadetBlue", 95, 158, 160,
4357     "CadetBlue1", 152, 245, 255,
4358     "CadetBlue2", 142, 229, 238,
4359     "CadetBlue3", 122, 197, 205,
4360     "CadetBlue4", 83, 134, 139,
4361     "chartreuse", 127, 255, 0,
4362     "chartreuse1", 127, 255, 0,
4363     "chartreuse2", 118, 238, 0,
4364     "chartreuse3", 102, 205, 0,
4365     "chartreuse4", 69, 139, 0,
4366     "chocolate", 210, 105, 30,
4367     "chocolate1", 255, 127, 36,
4368     "chocolate2", 238, 118, 33,
4369     "chocolate3", 205, 102, 29,
4370     "chocolate4", 139, 69, 19,
4371     "coral", 255, 127, 80,
4372     "coral1", 255, 114, 86,
4373     "coral2", 238, 106, 80,
4374     "coral3", 205, 91, 69,
4375     "coral4", 139, 62, 47,
4376     "cornflower blue", 100, 149, 237,
4377     "CornflowerBlue", 100, 149, 237,
4378     "cornsilk", 255, 248, 220,
4379     "cornsilk1", 255, 248, 220,
4380     "cornsilk2", 238, 232, 205,
4381     "cornsilk3", 205, 200, 177,
4382     "cornsilk4", 139, 136, 120,
4383     "cyan", 0, 255, 255,
4384     "cyan1", 0, 255, 255,
4385     "cyan2", 0, 238, 238,
4386     "cyan3", 0, 205, 205,
4387     "cyan4", 0, 139, 139,
4388     "dark goldenrod", 184, 134, 11,
4389     "dark green", 0, 100, 0,
4390     "dark khaki", 189, 183, 107,
4391     "dark olive green", 85, 107, 47,
4392     "dark orange", 255, 140, 0,
4393     "dark orchid", 153, 50, 204,
4394     "dark salmon", 233, 150, 122,
4395     "dark sea green", 143, 188, 143,
4396     "dark slate blue", 72, 61, 139,
4397     "dark slate gray", 47, 79, 79,
4398     "dark slate grey", 47, 79, 79,
4399     "dark turquoise", 0, 206, 209,
4400     "dark violet", 148, 0, 211,
4401     "DarkGoldenrod", 184, 134, 11,
4402     "DarkGoldenrod1", 255, 185, 15,
4403     "DarkGoldenrod2", 238, 173, 14,
4404     "DarkGoldenrod3", 205, 149, 12,
4405     "DarkGoldenrod4", 139, 101, 8,
4406     "DarkGreen", 0, 100, 0,
4407     "DarkKhaki", 189, 183, 107,
4408     "DarkOliveGreen", 85, 107, 47,
4409     "DarkOliveGreen1", 202, 255, 112,
4410     "DarkOliveGreen2", 188, 238, 104,
4411     "DarkOliveGreen3", 162, 205, 90,
4412     "DarkOliveGreen4", 110, 139, 61,
4413     "DarkOrange", 255, 140, 0,
4414     "DarkOrange1", 255, 127, 0,
4415     "DarkOrange2", 238, 118, 0,
4416     "DarkOrange3", 205, 102, 0,
4417     "DarkOrange4", 139, 69, 0,
4418     "DarkOrchid", 153, 50, 204,
4419     "DarkOrchid1", 191, 62, 255,
4420     "DarkOrchid2", 178, 58, 238,
4421     "DarkOrchid3", 154, 50, 205,
4422     "DarkOrchid4", 104, 34, 139,
4423     "DarkSalmon", 233, 150, 122,
4424     "DarkSeaGreen", 143, 188, 143,
4425     "DarkSeaGreen1", 193, 255, 193,
4426     "DarkSeaGreen2", 180, 238, 180,
4427     "DarkSeaGreen3", 155, 205, 155,
4428     "DarkSeaGreen4", 105, 139, 105,
4429     "DarkSlateBlue", 72, 61, 139,
4430     "DarkSlateGray", 47, 79, 79,
4431     "DarkSlateGray1", 151, 255, 255,
4432     "DarkSlateGray2", 141, 238, 238,
4433     "DarkSlateGray3", 121, 205, 205,
4434     "DarkSlateGray4", 82, 139, 139,
4435     "DarkSlateGrey", 47, 79, 79,
4436     "DarkTurquoise", 0, 206, 209,
4437     "DarkViolet", 148, 0, 211,
4438     "deep pink", 255, 20, 147,
4439     "deep sky blue", 0, 191, 255,
4440     "DeepPink", 255, 20, 147,
4441     "DeepPink1", 255, 20, 147,
4442     "DeepPink2", 238, 18, 137,
4443     "DeepPink3", 205, 16, 118,
4444     "DeepPink4", 139, 10, 80,
4445     "DeepSkyBlue", 0, 191, 255,
4446     "DeepSkyBlue1", 0, 191, 255,
4447     "DeepSkyBlue2", 0, 178, 238,
4448     "DeepSkyBlue3", 0, 154, 205,
4449     "DeepSkyBlue4", 0, 104, 139,
4450     "dim gray", 105, 105, 105,
4451     "dim grey", 105, 105, 105,
4452     "DimGray", 105, 105, 105,
4453     "DimGrey", 105, 105, 105,
4454     "dodger blue", 30, 144, 255,
4455     "DodgerBlue", 30, 144, 255,
4456     "DodgerBlue1", 30, 144, 255,
4457     "DodgerBlue2", 28, 134, 238,
4458     "DodgerBlue3", 24, 116, 205,
4459     "DodgerBlue4", 16, 78, 139,
4460     "firebrick", 178, 34, 34,
4461     "firebrick1", 255, 48, 48,
4462     "firebrick2", 238, 44, 44,
4463     "firebrick3", 205, 38, 38,
4464     "firebrick4", 139, 26, 26,
4465     "floral white", 255, 250, 240,
4466     "FloralWhite", 255, 250, 240,
4467     "forest green", 34, 139, 34,
4468     "ForestGreen", 34, 139, 34,
4469     "gainsboro", 220, 220, 220,
4470     "ghost white", 248, 248, 255,
4471     "GhostWhite", 248, 248, 255,
4472     "gold", 255, 215, 0,
4473     "gold1", 255, 215, 0,
4474     "gold2", 238, 201, 0,
4475     "gold3", 205, 173, 0,
4476     "gold4", 139, 117, 0,
4477     "goldenrod", 218, 165, 32,
4478     "goldenrod1", 255, 193, 37,
4479     "goldenrod2", 238, 180, 34,
4480     "goldenrod3", 205, 155, 29,
4481     "goldenrod4", 139, 105, 20,
4482     "gray", 190, 190, 190,
4483     "gray0", 0, 0, 0,
4484     "gray1", 3, 3, 3,
4485     "gray10", 26, 26, 26,
4486     "gray100", 255, 255, 255,
4487     "gray11", 28, 28, 28,
4488     "gray12", 31, 31, 31,
4489     "gray13", 33, 33, 33,
4490     "gray14", 36, 36, 36,
4491     "gray15", 38, 38, 38,
4492     "gray16", 41, 41, 41,
4493     "gray17", 43, 43, 43,
4494     "gray18", 46, 46, 46,
4495     "gray19", 48, 48, 48,
4496     "gray2", 5, 5, 5,
4497     "gray20", 51, 51, 51,
4498     "gray21", 54, 54, 54,
4499     "gray22", 56, 56, 56,
4500     "gray23", 59, 59, 59,
4501     "gray24", 61, 61, 61,
4502     "gray25", 64, 64, 64,
4503     "gray26", 66, 66, 66,
4504     "gray27", 69, 69, 69,
4505     "gray28", 71, 71, 71,
4506     "gray29", 74, 74, 74,
4507     "gray3", 8, 8, 8,
4508     "gray30", 77, 77, 77,
4509     "gray31", 79, 79, 79,
4510     "gray32", 82, 82, 82,
4511     "gray33", 84, 84, 84,
4512     "gray34", 87, 87, 87,
4513     "gray35", 89, 89, 89,
4514     "gray36", 92, 92, 92,
4515     "gray37", 94, 94, 94,
4516     "gray38", 97, 97, 97,
4517     "gray39", 99, 99, 99,
4518     "gray4", 10, 10, 10,
4519     "gray40", 102, 102, 102,
4520     "gray41", 105, 105, 105,
4521     "gray42", 107, 107, 107,
4522     "gray43", 110, 110, 110,
4523     "gray44", 112, 112, 112,
4524     "gray45", 115, 115, 115,
4525     "gray46", 117, 117, 117,
4526     "gray47", 120, 120, 120,
4527     "gray48", 122, 122, 122,
4528     "gray49", 125, 125, 125,
4529     "gray5", 13, 13, 13,
4530     "gray50", 127, 127, 127,
4531     "gray51", 130, 130, 130,
4532     "gray52", 133, 133, 133,
4533     "gray53", 135, 135, 135,
4534     "gray54", 138, 138, 138,
4535     "gray55", 140, 140, 140,
4536     "gray56", 143, 143, 143,
4537     "gray57", 145, 145, 145,
4538     "gray58", 148, 148, 148,
4539     "gray59", 150, 150, 150,
4540     "gray6", 15, 15, 15,
4541     "gray60", 153, 153, 153,
4542     "gray61", 156, 156, 156,
4543     "gray62", 158, 158, 158,
4544     "gray63", 161, 161, 161,
4545     "gray64", 163, 163, 163,
4546     "gray65", 166, 166, 166,
4547     "gray66", 168, 168, 168,
4548     "gray67", 171, 171, 171,
4549     "gray68", 173, 173, 173,
4550     "gray69", 176, 176, 176,
4551     "gray7", 18, 18, 18,
4552     "gray70", 179, 179, 179,
4553     "gray71", 181, 181, 181,
4554     "gray72", 184, 184, 184,
4555     "gray73", 186, 186, 186,
4556     "gray74", 189, 189, 189,
4557     "gray75", 191, 191, 191,
4558     "gray76", 194, 194, 194,
4559     "gray77", 196, 196, 196,
4560     "gray78", 199, 199, 199,
4561     "gray79", 201, 201, 201,
4562     "gray8", 20, 20, 20,
4563     "gray80", 204, 204, 204,
4564     "gray81", 207, 207, 207,
4565     "gray82", 209, 209, 209,
4566     "gray83", 212, 212, 212,
4567     "gray84", 214, 214, 214,
4568     "gray85", 217, 217, 217,
4569     "gray86", 219, 219, 219,
4570     "gray87", 222, 222, 222,
4571     "gray88", 224, 224, 224,
4572     "gray89", 227, 227, 227,
4573     "gray9", 23, 23, 23,
4574     "gray90", 229, 229, 229,
4575     "gray91", 232, 232, 232,
4576     "gray92", 235, 235, 235,
4577     "gray93", 237, 237, 237,
4578     "gray94", 240, 240, 240,
4579     "gray95", 242, 242, 242,
4580     "gray96", 245, 245, 245,
4581     "gray97", 247, 247, 247,
4582     "gray98", 250, 250, 250,
4583     "gray99", 252, 252, 252,
4584     "green", 0, 255, 0,
4585     "green yellow", 173, 255, 47,
4586     "green1", 0, 255, 0,
4587     "green2", 0, 238, 0,
4588     "green3", 0, 205, 0,
4589     "green4", 0, 139, 0,
4590     "GreenYellow", 173, 255, 47,
4591     "grey", 190, 190, 190,
4592     "grey0", 0, 0, 0,
4593     "grey1", 3, 3, 3,
4594     "grey10", 26, 26, 26,
4595     "grey100", 255, 255, 255,
4596     "grey11", 28, 28, 28,
4597     "grey12", 31, 31, 31,
4598     "grey13", 33, 33, 33,
4599     "grey14", 36, 36, 36,
4600     "grey15", 38, 38, 38,
4601     "grey16", 41, 41, 41,
4602     "grey17", 43, 43, 43,
4603     "grey18", 46, 46, 46,
4604     "grey19", 48, 48, 48,
4605     "grey2", 5, 5, 5,
4606     "grey20", 51, 51, 51,
4607     "grey21", 54, 54, 54,
4608     "grey22", 56, 56, 56,
4609     "grey23", 59, 59, 59,
4610     "grey24", 61, 61, 61,
4611     "grey25", 64, 64, 64,
4612     "grey26", 66, 66, 66,
4613     "grey27", 69, 69, 69,
4614     "grey28", 71, 71, 71,
4615     "grey29", 74, 74, 74,
4616     "grey3", 8, 8, 8,
4617     "grey30", 77, 77, 77,
4618     "grey31", 79, 79, 79,
4619     "grey32", 82, 82, 82,
4620     "grey33", 84, 84, 84,
4621     "grey34", 87, 87, 87,
4622     "grey35", 89, 89, 89,
4623     "grey36", 92, 92, 92,
4624     "grey37", 94, 94, 94,
4625     "grey38", 97, 97, 97,
4626     "grey39", 99, 99, 99,
4627     "grey4", 10, 10, 10,
4628     "grey40", 102, 102, 102,
4629     "grey41", 105, 105, 105,
4630     "grey42", 107, 107, 107,
4631     "grey43", 110, 110, 110,
4632     "grey44", 112, 112, 112,
4633     "grey45", 115, 115, 115,
4634     "grey46", 117, 117, 117,
4635     "grey47", 120, 120, 120,
4636     "grey48", 122, 122, 122,
4637     "grey49", 125, 125, 125,
4638     "grey5", 13, 13, 13,
4639     "grey50", 127, 127, 127,
4640     "grey51", 130, 130, 130,
4641     "grey52", 133, 133, 133,
4642     "grey53", 135, 135, 135,
4643     "grey54", 138, 138, 138,
4644     "grey55", 140, 140, 140,
4645     "grey56", 143, 143, 143,
4646     "grey57", 145, 145, 145,
4647     "grey58", 148, 148, 148,
4648     "grey59", 150, 150, 150,
4649     "grey6", 15, 15, 15,
4650     "grey60", 153, 153, 153,
4651     "grey61", 156, 156, 156,
4652     "grey62", 158, 158, 158,
4653     "grey63", 161, 161, 161,
4654     "grey64", 163, 163, 163,
4655     "grey65", 166, 166, 166,
4656     "grey66", 168, 168, 168,
4657     "grey67", 171, 171, 171,
4658     "grey68", 173, 173, 173,
4659     "grey69", 176, 176, 176,
4660     "grey7", 18, 18, 18,
4661     "grey70", 179, 179, 179,
4662     "grey71", 181, 181, 181,
4663     "grey72", 184, 184, 184,
4664     "grey73", 186, 186, 186,
4665     "grey74", 189, 189, 189,
4666     "grey75", 191, 191, 191,
4667     "grey76", 194, 194, 194,
4668     "grey77", 196, 196, 196,
4669     "grey78", 199, 199, 199,
4670     "grey79", 201, 201, 201,
4671     "grey8", 20, 20, 20,
4672     "grey80", 204, 204, 204,
4673     "grey81", 207, 207, 207,
4674     "grey82", 209, 209, 209,
4675     "grey83", 212, 212, 212,
4676     "grey84", 214, 214, 214,
4677     "grey85", 217, 217, 217,
4678     "grey86", 219, 219, 219,
4679     "grey87", 222, 222, 222,
4680     "grey88", 224, 224, 224,
4681     "grey89", 227, 227, 227,
4682     "grey9", 23, 23, 23,
4683     "grey90", 229, 229, 229,
4684     "grey91", 232, 232, 232,
4685     "grey92", 235, 235, 235,
4686     "grey93", 237, 237, 237,
4687     "grey94", 240, 240, 240,
4688     "grey95", 242, 242, 242,
4689     "grey96", 245, 245, 245,
4690     "grey97", 247, 247, 247,
4691     "grey98", 250, 250, 250,
4692     "grey99", 252, 252, 252,
4693     "honeydew", 240, 255, 240,
4694     "honeydew1", 240, 255, 240,
4695     "honeydew2", 224, 238, 224,
4696     "honeydew3", 193, 205, 193,
4697     "honeydew4", 131, 139, 131,
4698     "hot pink", 255, 105, 180,
4699     "HotPink", 255, 105, 180,
4700     "HotPink1", 255, 110, 180,
4701     "HotPink2", 238, 106, 167,
4702     "HotPink3", 205, 96, 144,
4703     "HotPink4", 139, 58, 98,
4704     "indian red", 205, 92, 92,
4705     "IndianRed", 205, 92, 92,
4706     "IndianRed1", 255, 106, 106,
4707     "IndianRed2", 238, 99, 99,
4708     "IndianRed3", 205, 85, 85,
4709     "IndianRed4", 139, 58, 58,
4710     "ivory", 255, 255, 240,
4711     "ivory1", 255, 255, 240,
4712     "ivory2", 238, 238, 224,
4713     "ivory3", 205, 205, 193,
4714     "ivory4", 139, 139, 131,
4715     "khaki", 240, 230, 140,
4716     "khaki1", 255, 246, 143,
4717     "khaki2", 238, 230, 133,
4718     "khaki3", 205, 198, 115,
4719     "khaki4", 139, 134, 78,
4720     "lavender", 230, 230, 250,
4721     "lavender blush", 255, 240, 245,
4722     "LavenderBlush", 255, 240, 245,
4723     "LavenderBlush1", 255, 240, 245,
4724     "LavenderBlush2", 238, 224, 229,
4725     "LavenderBlush3", 205, 193, 197,
4726     "LavenderBlush4", 139, 131, 134,
4727     "lawn green", 124, 252, 0,
4728     "LawnGreen", 124, 252, 0,
4729     "lemon chiffon", 255, 250, 205,
4730     "LemonChiffon", 255, 250, 205,
4731     "LemonChiffon1", 255, 250, 205,
4732     "LemonChiffon2", 238, 233, 191,
4733     "LemonChiffon3", 205, 201, 165,
4734     "LemonChiffon4", 139, 137, 112,
4735     "light blue", 173, 216, 230,
4736     "light coral", 240, 128, 128,
4737     "light cyan", 224, 255, 255,
4738     "light goldenrod", 238, 221, 130,
4739     "light goldenrod yellow", 250, 250, 210,
4740     "light gray", 211, 211, 211,
4741     "light grey", 211, 211, 211,
4742     "light pink", 255, 182, 193,
4743     "light salmon", 255, 160, 122,
4744     "light sea green", 32, 178, 170,
4745     "light sky blue", 135, 206, 250,
4746     "light slate blue", 132, 112, 255,
4747     "light slate gray", 119, 136, 153,
4748     "light slate grey", 119, 136, 153,
4749     "light steel blue", 176, 196, 222,
4750     "light yellow", 255, 255, 224,
4751     "LightBlue", 173, 216, 230,
4752     "LightBlue1", 191, 239, 255,
4753     "LightBlue2", 178, 223, 238,
4754     "LightBlue3", 154, 192, 205,
4755     "LightBlue4", 104, 131, 139,
4756     "LightCoral", 240, 128, 128,
4757     "LightCyan", 224, 255, 255,
4758     "LightCyan1", 224, 255, 255,
4759     "LightCyan2", 209, 238, 238,
4760     "LightCyan3", 180, 205, 205,
4761     "LightCyan4", 122, 139, 139,
4762     "LightGoldenrod", 238, 221, 130,
4763     "LightGoldenrod1", 255, 236, 139,
4764     "LightGoldenrod2", 238, 220, 130,
4765     "LightGoldenrod3", 205, 190, 112,
4766     "LightGoldenrod4", 139, 129, 76,
4767     "LightGoldenrodYellow", 250, 250, 210,
4768     "LightGray", 211, 211, 211,
4769     "LightGrey", 211, 211, 211,
4770     "LightPink", 255, 182, 193,
4771     "LightPink1", 255, 174, 185,
4772     "LightPink2", 238, 162, 173,
4773     "LightPink3", 205, 140, 149,
4774     "LightPink4", 139, 95, 101,
4775     "LightSalmon", 255, 160, 122,
4776     "LightSalmon1", 255, 160, 122,
4777     "LightSalmon2", 238, 149, 114,
4778     "LightSalmon3", 205, 129, 98,
4779     "LightSalmon4", 139, 87, 66,
4780     "LightSeaGreen", 32, 178, 170,
4781     "LightSkyBlue", 135, 206, 250,
4782     "LightSkyBlue1", 176, 226, 255,
4783     "LightSkyBlue2", 164, 211, 238,
4784     "LightSkyBlue3", 141, 182, 205,
4785     "LightSkyBlue4", 96, 123, 139,
4786     "LightSlateBlue", 132, 112, 255,
4787     "LightSlateGray", 119, 136, 153,
4788     "LightSlateGrey", 119, 136, 153,
4789     "LightSteelBlue", 176, 196, 222,
4790     "LightSteelBlue1", 202, 225, 255,
4791     "LightSteelBlue2", 188, 210, 238,
4792     "LightSteelBlue3", 162, 181, 205,
4793     "LightSteelBlue4", 110, 123, 139,
4794     "LightYellow", 255, 255, 224,
4795     "LightYellow1", 255, 255, 224,
4796     "LightYellow2", 238, 238, 209,
4797     "LightYellow3", 205, 205, 180,
4798     "LightYellow4", 139, 139, 122,
4799     "lime green", 50, 205, 50,
4800     "LimeGreen", 50, 205, 50,
4801     "linen", 250, 240, 230,
4802     "magenta", 255, 0, 255,
4803     "magenta1", 255, 0, 255,
4804     "magenta2", 238, 0, 238,
4805     "magenta3", 205, 0, 205,
4806     "magenta4", 139, 0, 139,
4807     "maroon", 176, 48, 96,
4808     "maroon1", 255, 52, 179,
4809     "maroon2", 238, 48, 167,
4810     "maroon3", 205, 41, 144,
4811     "maroon4", 139, 28, 98,
4812     "medium aquamarine", 102, 205, 170,
4813     "medium blue", 0, 0, 205,
4814     "medium orchid", 186, 85, 211,
4815     "medium purple", 147, 112, 219,
4816     "medium sea green", 60, 179, 113,
4817     "medium slate blue", 123, 104, 238,
4818     "medium spring green", 0, 250, 154,
4819     "medium turquoise", 72, 209, 204,
4820     "medium violet red", 199, 21, 133,
4821     "MediumAquamarine", 102, 205, 170,
4822     "MediumBlue", 0, 0, 205,
4823     "MediumOrchid", 186, 85, 211,
4824     "MediumOrchid1", 224, 102, 255,
4825     "MediumOrchid2", 209, 95, 238,
4826     "MediumOrchid3", 180, 82, 205,
4827     "MediumOrchid4", 122, 55, 139,
4828     "MediumPurple", 147, 112, 219,
4829     "MediumPurple1", 171, 130, 255,
4830     "MediumPurple2", 159, 121, 238,
4831     "MediumPurple3", 137, 104, 205,
4832     "MediumPurple4", 93, 71, 139,
4833     "MediumSeaGreen", 60, 179, 113,
4834     "MediumSlateBlue", 123, 104, 238,
4835     "MediumSpringGreen", 0, 250, 154,
4836     "MediumTurquoise", 72, 209, 204,
4837     "MediumVioletRed", 199, 21, 133,
4838     "midnight blue", 25, 25, 112,
4839     "MidnightBlue", 25, 25, 112,
4840     "mint cream", 245, 255, 250,
4841     "MintCream", 245, 255, 250,
4842     "misty rose", 255, 228, 225,
4843     "MistyRose", 255, 228, 225,
4844     "MistyRose1", 255, 228, 225,
4845     "MistyRose2", 238, 213, 210,
4846     "MistyRose3", 205, 183, 181,
4847     "MistyRose4", 139, 125, 123,
4848     "moccasin", 255, 228, 181,
4849     "navajo white", 255, 222, 173,
4850     "NavajoWhite", 255, 222, 173,
4851     "NavajoWhite1", 255, 222, 173,
4852     "NavajoWhite2", 238, 207, 161,
4853     "NavajoWhite3", 205, 179, 139,
4854     "NavajoWhite4", 139, 121, 94,
4855     "navy", 0, 0, 128,
4856     "navy blue", 0, 0, 128,
4857     "NavyBlue", 0, 0, 128,
4858     "old lace", 253, 245, 230,
4859     "OldLace", 253, 245, 230,
4860     "olive drab", 107, 142, 35,
4861     "OliveDrab", 107, 142, 35,
4862     "OliveDrab1", 192, 255, 62,
4863     "OliveDrab2", 179, 238, 58,
4864     "OliveDrab3", 154, 205, 50,
4865     "OliveDrab4", 105, 139, 34,
4866     "orange", 255, 165, 0,
4867     "orange red", 255, 69, 0,
4868     "orange1", 255, 165, 0,
4869     "orange2", 238, 154, 0,
4870     "orange3", 205, 133, 0,
4871     "orange4", 139, 90, 0,
4872     "OrangeRed", 255, 69, 0,
4873     "OrangeRed1", 255, 69, 0,
4874     "OrangeRed2", 238, 64, 0,
4875     "OrangeRed3", 205, 55, 0,
4876     "OrangeRed4", 139, 37, 0,
4877     "orchid", 218, 112, 214,
4878     "orchid1", 255, 131, 250,
4879     "orchid2", 238, 122, 233,
4880     "orchid3", 205, 105, 201,
4881     "orchid4", 139, 71, 137,
4882     "pale goldenrod", 238, 232, 170,
4883     "pale green", 152, 251, 152,
4884     "pale turquoise", 175, 238, 238,
4885     "pale violet red", 219, 112, 147,
4886     "PaleGoldenrod", 238, 232, 170,
4887     "PaleGreen", 152, 251, 152,
4888     "PaleGreen1", 154, 255, 154,
4889     "PaleGreen2", 144, 238, 144,
4890     "PaleGreen3", 124, 205, 124,
4891     "PaleGreen4", 84, 139, 84,
4892     "PaleTurquoise", 175, 238, 238,
4893     "PaleTurquoise1", 187, 255, 255,
4894     "PaleTurquoise2", 174, 238, 238,
4895     "PaleTurquoise3", 150, 205, 205,
4896     "PaleTurquoise4", 102, 139, 139,
4897     "PaleVioletRed", 219, 112, 147,
4898     "PaleVioletRed1", 255, 130, 171,
4899     "PaleVioletRed2", 238, 121, 159,
4900     "PaleVioletRed3", 205, 104, 137,
4901     "PaleVioletRed4", 139, 71, 93,
4902     "papaya whip", 255, 239, 213,
4903     "PapayaWhip", 255, 239, 213,
4904     "peach puff", 255, 218, 185,
4905     "PeachPuff", 255, 218, 185,
4906     "PeachPuff1", 255, 218, 185,
4907     "PeachPuff2", 238, 203, 173,
4908     "PeachPuff3", 205, 175, 149,
4909     "PeachPuff4", 139, 119, 101,
4910     "peru", 205, 133, 63,
4911     "pink", 255, 192, 203,
4912     "pink1", 255, 181, 197,
4913     "pink2", 238, 169, 184,
4914     "pink3", 205, 145, 158,
4915     "pink4", 139, 99, 108,
4916     "plum", 221, 160, 221,
4917     "plum1", 255, 187, 255,
4918     "plum2", 238, 174, 238,
4919     "plum3", 205, 150, 205,
4920     "plum4", 139, 102, 139,
4921     "powder blue", 176, 224, 230,
4922     "PowderBlue", 176, 224, 230,
4923     "purple", 160, 32, 240,
4924     "purple1", 155, 48, 255,
4925     "purple2", 145, 44, 238,
4926     "purple3", 125, 38, 205,
4927     "purple4", 85, 26, 139,
4928     "red", 255, 0, 0,
4929     "red1", 255, 0, 0,
4930     "red2", 238, 0, 0,
4931     "red3", 205, 0, 0,
4932     "red4", 139, 0, 0,
4933     "rosy brown", 188, 143, 143,
4934     "RosyBrown", 188, 143, 143,
4935     "RosyBrown1", 255, 193, 193,
4936     "RosyBrown2", 238, 180, 180,
4937     "RosyBrown3", 205, 155, 155,
4938     "RosyBrown4", 139, 105, 105,
4939     "royal blue", 65, 105, 225,
4940     "RoyalBlue", 65, 105, 225,
4941     "RoyalBlue1", 72, 118, 255,
4942     "RoyalBlue2", 67, 110, 238,
4943     "RoyalBlue3", 58, 95, 205,
4944     "RoyalBlue4", 39, 64, 139,
4945     "saddle brown", 139, 69, 19,
4946     "SaddleBrown", 139, 69, 19,
4947     "salmon", 250, 128, 114,
4948     "salmon1", 255, 140, 105,
4949     "salmon2", 238, 130, 98,
4950     "salmon3", 205, 112, 84,
4951     "salmon4", 139, 76, 57,
4952     "sandy brown", 244, 164, 96,
4953     "SandyBrown", 244, 164, 96,
4954     "sea green", 46, 139, 87,
4955     "SeaGreen", 46, 139, 87,
4956     "SeaGreen1", 84, 255, 159,
4957     "SeaGreen2", 78, 238, 148,
4958     "SeaGreen3", 67, 205, 128,
4959     "SeaGreen4", 46, 139, 87,
4960     "seashell", 255, 245, 238,
4961     "seashell1", 255, 245, 238,
4962     "seashell2", 238, 229, 222,
4963     "seashell3", 205, 197, 191,
4964     "seashell4", 139, 134, 130,
4965     "sienna", 160, 82, 45,
4966     "sienna1", 255, 130, 71,
4967     "sienna2", 238, 121, 66,
4968     "sienna3", 205, 104, 57,
4969     "sienna4", 139, 71, 38,
4970     "sky blue", 135, 206, 235,
4971     "SkyBlue", 135, 206, 235,
4972     "SkyBlue1", 135, 206, 255,
4973     "SkyBlue2", 126, 192, 238,
4974     "SkyBlue3", 108, 166, 205,
4975     "SkyBlue4", 74, 112, 139,
4976     "slate blue", 106, 90, 205,
4977     "slate gray", 112, 128, 144,
4978     "slate grey", 112, 128, 144,
4979     "SlateBlue", 106, 90, 205,
4980     "SlateBlue1", 131, 111, 255,
4981     "SlateBlue2", 122, 103, 238,
4982     "SlateBlue3", 105, 89, 205,
4983     "SlateBlue4", 71, 60, 139,
4984     "SlateGray", 112, 128, 144,
4985     "SlateGray1", 198, 226, 255,
4986     "SlateGray2", 185, 211, 238,
4987     "SlateGray3", 159, 182, 205,
4988     "SlateGray4", 108, 123, 139,
4989     "SlateGrey", 112, 128, 144,
4990     "snow", 255, 250, 250,
4991     "snow1", 255, 250, 250,
4992     "snow2", 238, 233, 233,
4993     "snow3", 205, 201, 201,
4994     "snow4", 139, 137, 137,
4995     "spring green", 0, 255, 127,
4996     "SpringGreen", 0, 255, 127,
4997     "SpringGreen1", 0, 255, 127,
4998     "SpringGreen2", 0, 238, 118,
4999     "SpringGreen3", 0, 205, 102,
5000     "SpringGreen4", 0, 139, 69,
5001     "steel blue", 70, 130, 180,
5002     "SteelBlue", 70, 130, 180,
5003     "SteelBlue1", 99, 184, 255,
5004     "SteelBlue2", 92, 172, 238,
5005     "SteelBlue3", 79, 148, 205,
5006     "SteelBlue4", 54, 100, 139,
5007     "tan", 210, 180, 140,
5008     "tan1", 255, 165, 79,
5009     "tan2", 238, 154, 73,
5010     "tan3", 205, 133, 63,
5011     "tan4", 139, 90, 43,
5012     "thistle", 216, 191, 216,
5013     "thistle1", 255, 225, 255,
5014     "thistle2", 238, 210, 238,
5015     "thistle3", 205, 181, 205,
5016     "thistle4", 139, 123, 139,
5017     "tomato", 255, 99, 71,
5018     "tomato1", 255, 99, 71,
5019     "tomato2", 238, 92, 66,
5020     "tomato3", 205, 79, 57,
5021     "tomato4", 139, 54, 38,
5022     "turquoise", 64, 224, 208,
5023     "turquoise1", 0, 245, 255,
5024     "turquoise2", 0, 229, 238,
5025     "turquoise3", 0, 197, 205,
5026     "turquoise4", 0, 134, 139,
5027     "violet", 238, 130, 238,
5028     "violet red", 208, 32, 144,
5029     "VioletRed", 208, 32, 144,
5030     "VioletRed1", 255, 62, 150,
5031     "VioletRed2", 238, 58, 140,
5032     "VioletRed3", 205, 50, 120,
5033     "VioletRed4", 139, 34, 82,
5034     "wheat", 245, 222, 179,
5035     "wheat1", 255, 231, 186,
5036     "wheat2", 238, 216, 174,
5037     "wheat3", 205, 186, 150,
5038     "wheat4", 139, 126, 102,
5039     "white", 255, 255, 255,
5040     "white smoke", 245, 245, 245,
5041     "WhiteSmoke", 245, 245, 245,
5042     "yellow", 255, 255, 0,
5043     "yellow green", 154, 205, 50,
5044     "yellow1", 255, 255, 0,
5045     "yellow2", 238, 238, 0,
5046     "yellow3", 205, 205, 0,
5047     "yellow4", 139, 139, 0,
5048     "YellowGreen", 154, 205, 50,
5049     NULL, 0, 0, 0
5050     };
5051    
5052    
5053     /*
5054     * This value will be set to the number of colors in the color table
5055     * the first time it is needed.
5056     */
5057    
5058     static int numXColors = 0;
5059    
5060     /*
5061     * Forward declarations for functions used only in this file.
5062     */
5063    
5064     static int FindColor(const char *name, XColor *colorPtr);
5065    
5066     int strcasecmp(const char *a, const char *b)
5067     {
5068     int i=0,c;
5069     if((a==NULL)||(b==NULL)) return -1;
5070    
5071     while(((!(c=toupper(a[i])-toupper(b[i])))&&a[i]&&b[i])) i++;
5072     return c;
5073     }
5074     /*
5075     *----------------------------------------------------------------------
5076     *
5077     * FindColor --
5078     *
5079     * This routine finds the color entry that corresponds to the
5080     * specified color.
5081     *
5082     * Results:
5083     * Returns non-zero on success. The RGB values of the XColor
5084     * will be initialized to the proper values on success.
5085     *
5086     * Side effects:
5087     * None.
5088     *
5089     *----------------------------------------------------------------------
5090     */
5091    
5092     static int
5093     FindColor(name, colorPtr)
5094     const char *name;
5095     XColor *colorPtr;
5096     {
5097     int l, u, r, i;
5098    
5099     /*
5100     * Count the number of elements in the color array if we haven't
5101     * done so yet.
5102     */
5103    
5104     if (numXColors == 0) {
5105     XColorEntry *ePtr;
5106     for (ePtr = xColors; ePtr->name != NULL; ePtr++) {
5107     numXColors++;
5108     }
5109     }
5110    
5111     /*
5112     * Perform a binary search on the sorted array of colors.
5113     */
5114    
5115     l = 0;
5116     u = numXColors - 1;
5117     while (l <= u) {
5118     i = (l + u) / 2;
5119     r = strcasecmp(name, xColors[i].name);
5120     if (r == 0) {
5121     break;
5122     } else if (r < 0) {
5123     u = i-1;
5124     } else {
5125     l = i+1;
5126     }
5127     }
5128     if (l > u) {
5129     return 0;
5130     }
5131     colorPtr->red = xColors[i].red << 8;
5132     colorPtr->green = xColors[i].green << 8;
5133     colorPtr->blue = xColors[i].blue << 8;
5134     return 1;
5135     }
5136    
5137     /*
5138     *----------------------------------------------------------------------
5139     *
5140     * XParseColor --
5141     *
5142     * Partial implementation of X color name parsing interface.
5143     *
5144     * Results:
5145     * Returns non-zero on success.
5146     *
5147     * Side effects:
5148     * None.
5149     *
5150     *----------------------------------------------------------------------
5151     */
5152    
5153     StatusDef
5154     XParseColor(display, map, spec, colorPtr)
5155     Display *display;
5156     Colormap map;
5157     const char* spec;
5158     XColor *colorPtr;
5159     {
5160     if (spec[0] == '#') {
5161     char fmt[16];
5162     int i, red, green, blue;
5163    
5164     if ((i = strlen(spec+1))%3) {
5165     return 0;
5166     }
5167     i /= 3;
5168    
5169     sprintf(fmt, "%%%dx%%%dx%%%dx", i, i, i);
5170     if (sscanf(spec+1, fmt, &red, &green, &blue) != 3) {
5171     return 0;
5172     }
5173     colorPtr->red = ((unsigned short) red) << (4 * (4 - i));
5174     colorPtr->green = ((unsigned short) green) << (4 * (4 - i));
5175     colorPtr->blue = ((unsigned short) blue) << (4 * (4 - i));
5176     } else {
5177     if (!FindColor(spec, colorPtr)) {
5178     return 0;
5179     }
5180     }
5181     colorPtr->pixel = ((colorPtr->red)>>8)&0xff;
5182     colorPtr->flags = DoRed|DoGreen|DoBlue;
5183     colorPtr->pad = 0;
5184     return 1;
5185     }
5186     /** xpm support */
5187     int
5188     XFreeColors(display, cmap, pixels, npixels, planes)
5189     Display *display;
5190     Colormap cmap;
5191     unsigned long pixels[];
5192     int npixels;
5193     unsigned long planes;
5194     {
5195     return 0;
5196     }
5197    
5198     int
5199     XGrabServer(display)
5200     Display *display;
5201     {
5202     return 0;
5203     }
5204    
5205     int
5206     XUngrabServer(display)
5207     Display *display;
5208     {
5209     return 0;
5210     }
5211    
5212    
5213     #endif