4 * Replacements for some comomon Xlib functions
12 #pragma implementation "Xlib.h"
20 #include "wx/x11/nanox/X11/Xlib.h"
22 /* Expands to some compatibility functions (see XtoNX.h) */
26 static GR_PALETTE
* s_globalColormap
= 0;
28 Colormap
DefaultColormapOfScreen(Screen
* screen
)
30 if (!s_globalColormap
)
32 s_globalColormap
= (GR_PALETTE
*) malloc(sizeof(GR_PALETTE
));
34 GrGetSystemPalette(s_globalColormap
);
37 return s_globalColormap
;
40 int XSetGraphicsExposures( Display
* display
, GC gc
, Bool graphics_exposures
)
45 int XWarpPointer( Display
* display
, Window srcW
, Window destW
,
47 unsigned int srcWidth
,
48 unsigned int srcHeight
,
51 GrMoveCursor(destX
, destY
);
55 int XSetInputFocus(Display
* display
, Window focus
, int revert_to
, Time time
)
61 int XGetInputFocus(Display
* display
, Window
* focus_return
, int* revert_to_return
)
63 * focus_return
= GrGetFocus();
64 * revert_to_return
= 0;
68 int XGrabPointer(Display
* display
, Window grab_window
,
69 Bool owner_events
, unsigned int event_mask
,
70 int pointer_mode
, int keyboard_mode
,
71 Window confine_to
, Cursor cursor
, Time time
)
73 /* According to comments in srvevent.c in Nano-X, the pointer
74 * is implicitly grabbed when a mouse button is down.
75 * We may be able to simulate this further in the event loop.
80 int XUngrabPointer(Display
* display
, Time time
)
85 int XCopyArea(Display
* display
, Drawable src
, Drawable dest
, GC gc
,
86 int src_x
, int src_y
, unsigned int width
, unsigned int height
,
87 int dest_x
, int dest_y
)
89 GrCopyArea(dest
, gc
, dest_x
, dest_y
,
95 int XCopyPlane(Display
* display
, Drawable src
, Drawable dest
, GC gc
,
96 int src_x
, int src_y
, unsigned int width
, unsigned int height
,
97 int dest_x
, int dest_y
, unsigned long plane
)
99 GrCopyArea(dest
, gc
, dest_x
, dest_y
,
107 GR_WINDOW_ID wid
; /* window id (or 0 if no such window) */
108 GR_WINDOW_ID parent
; /* parent window id */
109 GR_WINDOW_ID child
; /* first child window id (or 0) */
110 GR_WINDOW_ID sibling
; /* next sibling window id (or 0) */
111 GR_BOOL inputonly
; /* TRUE if window is input only */
112 GR_BOOL mapped
; /* TRUE if window is mapped */
113 GR_COUNT unmapcount
; /* reasons why window is unmapped */
114 GR_COORD x
; /* absolute x position of window */
115 GR_COORD y
; /* absolute y position of window */
116 GR_SIZE width
; /* width of window */
117 GR_SIZE height
; /* height of window */
118 GR_SIZE bordersize
; /* size of border */
119 GR_COLOR bordercolor
; /* color of border */
120 GR_COLOR background
; /* background color */
121 GR_EVENT_MASK eventmask
; /* current event mask for this client */
122 GR_WM_PROPS props
; /* window properties */
123 GR_CURSOR_ID cursor
; /* cursor id*/
124 unsigned long processid
; /* process id of owner*/
128 int x
, y
; /* location of window */
129 int width
, height
; /* width and height of window */
130 int border_width
; /* border width of window */
131 int depth
; /* depth of window */
132 Visual
*visual
; /* the associated visual structure */
133 Window root
; /* root of screen containing window */
134 int class; /* InputOutput, InputOnly*/
135 int bit_gravity
; /* one of the bit gravity values */
136 int win_gravity
; /* one of the window gravity values */
137 int backing_store
; /* NotUseful, WhenMapped, Always */
138 unsigned long backing_planes
;/* planes to be preserved if possible */
139 unsigned long backing_pixel
;/* value to be used when restoring planes */
140 Bool save_under
; /* boolean, should bits under be saved? */
141 Colormap colormap
; /* color map to be associated with window */
142 Bool map_installed
; /* boolean, is color map currently installed*/
143 int map_state
; /* IsUnmapped, IsUnviewable, IsViewable */
144 long all_event_masks
; /* set of events all people have interest in*/
145 long your_event_mask
; /* my event mask */
146 long do_not_propagate_mask
;/* set of events that should not propagate */
147 Bool override_redirect
; /* boolean value for override-redirect */
148 Screen
*screen
; /* back pointer to correct screen */
154 Status
XGetWindowAttributes(Display
* display
, Window w
,
155 XWindowAttributes
* window_attributes
)
160 GrGetWindowInfo(w
, & info
);
162 window_attributes
->x
= info
.x
;
163 window_attributes
->y
= info
.y
;
164 window_attributes
->width
= info
.width
;
165 window_attributes
->height
= info
.height
;
166 window_attributes
->border_width
= info
.bordersize
;
167 window_attributes
->depth
= 0;
168 window_attributes
->visual
= NULL
;
169 window_attributes
->root
= 0;
170 window_attributes
->_class
= info
.inputonly
? InputOnly
: InputOutput
;
171 window_attributes
->bit_gravity
= 0;
172 window_attributes
->win_gravity
= 0;
173 window_attributes
->backing_store
= 0;
174 window_attributes
->backing_planes
= 0;
175 window_attributes
->backing_pixel
= 0;
176 window_attributes
->save_under
= FALSE
;
177 window_attributes
->colormap
= DefaultColormapOfScreen(0);
178 window_attributes
->map_installed
= FALSE
;
179 window_attributes
->map_state
= info
.mapped
? IsViewable
: IsUnmapped
;
180 window_attributes
->all_event_masks
= 0;
181 window_attributes
->do_not_propagate_mask
= 0;
182 window_attributes
->override_redirect
= FALSE
;
183 window_attributes
->screen
= NULL
;
185 /* We need to check if any parents are unmapped,
186 * or we will report a window as mapped when it is not.
188 parent
= info
.parent
;
191 GrGetWindowInfo(parent
, & info
);
192 if (info
.mapped
== 0)
193 window_attributes
->map_state
= IsUnmapped
;
195 parent
= info
.parent
;
201 static XErrorHandler
* g_ErrorHandler
= NULL
;
203 void DefaultNanoXErrorHandler(GR_EVENT_ERROR
* ep
)
207 XErrorEvent errEvent
;
208 errEvent
.type
= ep
->type
;
209 errEvent
.display
= NULL
;
210 errEvent
.resourceid
= ep
->id
;
212 errEvent
.error_code
= ep
->code
;
213 errEvent
.request_code
= 0;
214 errEvent
.minor_code
= 0;
215 (*g_ErrorHandler
)(NULL
, & errEvent
);
219 XErrorHandler
XSetErrorHandler (XErrorHandler handler
)
221 XErrorHandler oldHandler
= g_ErrorHandler
;
222 g_ErrorHandler
= handler
;
223 GrSetErrorHandler(DefaultNanoXErrorHandler
);
227 static Screen s_screen
;
228 Screen
*XScreenOfDisplay(Display
* display
,
231 /* TODO: fill in the members. See Xlib.h */
235 int DisplayWidth(Display
* display
, int screen
)
237 return _display
.display_width
;
240 int DisplayHeight(Display
* display
, int screen
)
242 return _display
.display_height
;
245 int DefaultDepth(Display
* display
, int screen
)
247 return _display
.display_bpp
;
250 int XAllocColor(Display
* display
, Colormap cmap
,
254 GrFindColor(GR_RGB(color
->red
, color
->green
, color
->blue
), & pixel
);
255 color
->pixel
= pixel
;
266 static _wxColourEntry _wxColourDatabase
[] =
268 { "WHITE", 255, 255, 255 },
269 { "BLACK", 0, 0, 0 },
270 { "RED", 255, 0, 0 },
271 { "GREEN", 0, 255, 0 },
272 { "BLUE", 0, 255, 255 },
273 { "GREY", 128, 128, 128 },
274 { "GRAY", 128, 128, 128 },
275 { "LIGHT GREY", 192, 192, 192 },
276 { "LIGHT GRAY", 192, 192, 192 },
277 { "DARK GREY", 32, 32, 32 },
278 { "DARK GRAY", 32, 32, 32 },
279 { "CYAN", 0, 255, 255 },
280 { "MAGENTA", 255, 255, 0 },
286 int XParseColor(Display
* display
, Colormap cmap
,
287 const char* cname
, XColor
* color
)
292 if (!_wxColourDatabase
[i
].name
)
296 if (strcmp(cname
, _wxColourDatabase
[i
].name
) == 0)
298 color
->red
= _wxColourDatabase
[i
].red
;
299 color
->green
= _wxColourDatabase
[i
].green
;
300 color
->blue
= _wxColourDatabase
[i
].blue
;
308 /* Not found: use black */
316 int XDrawLine(Display
* display
, Window win
, GC gc
,
317 int x1
, int y1
, int x2
, int y2
)
325 GrDrawLines(win
, gc
, points
, 2);
329 int XTextExtents( XFontStruct
* font
, char* s
, int len
, int* direction
,
330 int* ascent
, int* descent2
, XCharStruct
* overall
)
332 GR_SIZE retwidth
, retheight
, retbase
;
333 GR_GC_ID gc
= GrNewGC();
335 *ascent
= font
->info
.baseline
;
336 *direction
= 1; /* ? */
337 *descent2
= 0; /* ? */
339 GrSetGCFont(gc
, font
->fid
);
341 /* TODO need to set the relevant flags for the character set.
342 * A good trick might be to pass a wxString instead of char*
346 GrGetGCTextSize(gc
, s
, len
, GR_TFASCII
, & retwidth
,
347 & retheight
, & retbase
);
350 overall
->width
= retwidth
;
351 overall
->lbearing
= 0;
352 overall
->rbearing
= 0;
353 overall
->ascent
= *ascent
;
354 overall
->descent
= 0;
355 overall
->attributes
= 0;
363 XFontStruct
* XLoadQueryFont(Display
* display
, const char* fontSpec
)
365 /* TODO: map fontSpec to something sensible for Nano-X */
366 char *fontName
= NULL
;
367 XFontStruct
* fontInfo
= malloc(sizeof(XFontStruct
));
368 fontInfo
->fid
= GrCreateFont(fontName
, 0, 0);
369 GrGetFontInfo(fontInfo
->fid
, & fontInfo
->info
);
370 printf("Warning: should not call XLoadQueryFont since font spec is not used in Nano-X.\n");
374 int XFreeFont(Display
* display
, XFontStruct
* fontStruct
)
376 GrDestroyFont(fontStruct
->fid
);
381 int XQueryColor(Display
* display
, Colormap cmap
, XColor
* color
)
383 /* cmap is a GR_PALETTE */
384 if (color
->pixel
< cmap
->count
)
386 color
->red
= cmap
->palette
[color
->pixel
].r
;
387 color
->green
= cmap
->palette
[color
->pixel
].g
;
388 color
->blue
= cmap
->palette
[color
->pixel
].b
;
395 int XConfigureWindow(Display
* display
, Window w
, int mask
, XWindowChanges
* changes
)
397 if ((mask
& CWX
) && (mask
& CWY
))
398 GrMoveWindow(w
, changes
->x
, changes
->y
);
399 if ((mask
& CWWidth
) && (mask
& CWHeight
))
400 GrResizeWindow(w
, changes
->width
, changes
->height
);
401 if (mask
& CWBorderWidth
)
405 if (mask
& CWSibling
)
409 if (mask
& CWStackMode
)
416 int XTranslateCoordinates(Display
* display
, Window srcWindow
, Window destWindow
, int srcX
, int srcY
, int* destX
, int* destY
, Window
* childReturn
)
421 Window w
= srcWindow
;
422 while (w
!= GR_ROOT_WINDOW_ID
)
425 GrGetWindowInfo(w
, & info
);
434 while (w
!= GR_ROOT_WINDOW_ID
)
437 GrGetWindowInfo(w
, & info
);
444 *destX
= srcX
+ offx
;
445 *destY
= srcY
+ offy
;
453 /* Should not really be necessary but in no-optimize mode
454 * gcc complains that wxNoop is not found if wxNoop is inline.