4 * Replacements for some comomon Xlib functions
5 * Licence: The wxWindows licence
17 #include "wx/x11/nanox/X11/Xlib.h"
19 /* Expands to some compatibility functions (see XtoNX.h) */
23 static GR_PALETTE
* s_globalColormap
= 0;
25 Colormap
DefaultColormapOfScreen(Screen
* screen
)
27 if (!s_globalColormap
)
29 s_globalColormap
= (GR_PALETTE
*) malloc(sizeof(GR_PALETTE
));
31 GrGetSystemPalette(s_globalColormap
);
34 return s_globalColormap
;
37 int XSetGraphicsExposures( Display
* display
, GC gc
, Bool graphics_exposures
)
42 int XWarpPointer( Display
* display
, Window srcW
, Window destW
,
44 unsigned int srcWidth
,
45 unsigned int srcHeight
,
48 GrMoveCursor(destX
, destY
);
52 int XSetInputFocus(Display
* display
, Window focus
, int revert_to
, Time time
)
58 int XGetInputFocus(Display
* display
, Window
* focus_return
, int* revert_to_return
)
60 * focus_return
= GrGetFocus();
61 * revert_to_return
= 0;
65 int XGrabPointer(Display
* display
, Window grab_window
,
66 Bool owner_events
, unsigned int event_mask
,
67 int pointer_mode
, int keyboard_mode
,
68 Window confine_to
, Cursor cursor
, Time time
)
70 /* According to comments in srvevent.c in Nano-X, the pointer
71 * is implicitly grabbed when a mouse button is down.
72 * We may be able to simulate this further in the event loop.
77 int XUngrabPointer(Display
* display
, Time time
)
82 int XCopyArea(Display
* display
, Drawable src
, Drawable dest
, GC gc
,
83 int src_x
, int src_y
, unsigned int width
, unsigned int height
,
84 int dest_x
, int dest_y
)
86 GrCopyArea(dest
, gc
, dest_x
, dest_y
,
92 int XCopyPlane(Display
* display
, Drawable src
, Drawable dest
, GC gc
,
93 int src_x
, int src_y
, unsigned int width
, unsigned int height
,
94 int dest_x
, int dest_y
, unsigned long plane
)
96 GrCopyArea(dest
, gc
, dest_x
, dest_y
,
104 GR_WINDOW_ID wid
; /* window id (or 0 if no such window) */
105 GR_WINDOW_ID parent
; /* parent window id */
106 GR_WINDOW_ID child
; /* first child window id (or 0) */
107 GR_WINDOW_ID sibling
; /* next sibling window id (or 0) */
108 GR_BOOL inputonly
; /* TRUE if window is input only */
109 GR_BOOL mapped
; /* TRUE if window is mapped */
110 GR_COUNT unmapcount
; /* reasons why window is unmapped */
111 GR_COORD x
; /* absolute x position of window */
112 GR_COORD y
; /* absolute y position of window */
113 GR_SIZE width
; /* width of window */
114 GR_SIZE height
; /* height of window */
115 GR_SIZE bordersize
; /* size of border */
116 GR_COLOR bordercolor
; /* color of border */
117 GR_COLOR background
; /* background color */
118 GR_EVENT_MASK eventmask
; /* current event mask for this client */
119 GR_WM_PROPS props
; /* window properties */
120 GR_CURSOR_ID cursor
; /* cursor id*/
121 unsigned long processid
; /* process id of owner*/
125 int x
, y
; /* location of window */
126 int width
, height
; /* width and height of window */
127 int border_width
; /* border width of window */
128 int depth
; /* depth of window */
129 Visual
*visual
; /* the associated visual structure */
130 Window root
; /* root of screen containing window */
131 int class; /* InputOutput, InputOnly*/
132 int bit_gravity
; /* one of the bit gravity values */
133 int win_gravity
; /* one of the window gravity values */
134 int backing_store
; /* NotUseful, WhenMapped, Always */
135 unsigned long backing_planes
;/* planes to be preserved if possible */
136 unsigned long backing_pixel
;/* value to be used when restoring planes */
137 Bool save_under
; /* boolean, should bits under be saved? */
138 Colormap colormap
; /* color map to be associated with window */
139 Bool map_installed
; /* boolean, is color map currently installed*/
140 int map_state
; /* IsUnmapped, IsUnviewable, IsViewable */
141 long all_event_masks
; /* set of events all people have interest in*/
142 long your_event_mask
; /* my event mask */
143 long do_not_propagate_mask
;/* set of events that should not propagate */
144 Bool override_redirect
; /* boolean value for override-redirect */
145 Screen
*screen
; /* back pointer to correct screen */
151 Status
XGetWindowAttributes(Display
* display
, Window w
,
152 XWindowAttributes
* window_attributes
)
157 GrGetWindowInfo(w
, & info
);
159 window_attributes
->x
= info
.x
;
160 window_attributes
->y
= info
.y
;
161 window_attributes
->width
= info
.width
;
162 window_attributes
->height
= info
.height
;
163 window_attributes
->border_width
= info
.bordersize
;
164 window_attributes
->depth
= 0;
165 window_attributes
->visual
= NULL
;
166 window_attributes
->root
= 0;
167 window_attributes
->_class
= info
.inputonly
? InputOnly
: InputOutput
;
168 window_attributes
->bit_gravity
= 0;
169 window_attributes
->win_gravity
= 0;
170 window_attributes
->backing_store
= 0;
171 window_attributes
->backing_planes
= 0;
172 window_attributes
->backing_pixel
= 0;
173 window_attributes
->save_under
= FALSE
;
174 window_attributes
->colormap
= DefaultColormapOfScreen(0);
175 window_attributes
->map_installed
= FALSE
;
176 window_attributes
->map_state
= info
.mapped
? IsViewable
: IsUnmapped
;
177 window_attributes
->all_event_masks
= 0;
178 window_attributes
->do_not_propagate_mask
= 0;
179 window_attributes
->override_redirect
= FALSE
;
180 window_attributes
->screen
= NULL
;
182 /* We need to check if any parents are unmapped,
183 * or we will report a window as mapped when it is not.
185 parent
= info
.parent
;
188 GrGetWindowInfo(parent
, & info
);
189 if (info
.mapped
== 0)
190 window_attributes
->map_state
= IsUnmapped
;
192 parent
= info
.parent
;
198 static XErrorHandler
* g_ErrorHandler
= NULL
;
200 void DefaultNanoXErrorHandler(GR_EVENT_ERROR
* ep
)
204 XErrorEvent errEvent
;
205 errEvent
.type
= ep
->type
;
206 errEvent
.display
= NULL
;
207 errEvent
.resourceid
= ep
->id
;
209 errEvent
.error_code
= ep
->code
;
210 errEvent
.request_code
= 0;
211 errEvent
.minor_code
= 0;
212 (*g_ErrorHandler
)(NULL
, & errEvent
);
216 XErrorHandler
XSetErrorHandler (XErrorHandler handler
)
218 XErrorHandler oldHandler
= g_ErrorHandler
;
219 g_ErrorHandler
= handler
;
220 GrSetErrorHandler(DefaultNanoXErrorHandler
);
224 static Screen s_screen
;
225 Screen
*XScreenOfDisplay(Display
* display
,
228 /* TODO: fill in the members. See Xlib.h */
232 int DisplayWidth(Display
* display
, int screen
)
234 return _display
.display_width
;
237 int DisplayHeight(Display
* display
, int screen
)
239 return _display
.display_height
;
242 int DefaultDepth(Display
* display
, int screen
)
244 return _display
.display_bpp
;
247 int XAllocColor(Display
* display
, Colormap cmap
,
251 GrFindColor(GR_RGB(color
->red
, color
->green
, color
->blue
), & pixel
);
252 color
->pixel
= pixel
;
263 static _wxColourEntry _wxColourDatabase
[] =
265 { "WHITE", 255, 255, 255 },
266 { "BLACK", 0, 0, 0 },
267 { "RED", 255, 0, 0 },
268 { "GREEN", 0, 255, 0 },
269 { "BLUE", 0, 255, 255 },
270 { "GREY", 128, 128, 128 },
271 { "GRAY", 128, 128, 128 },
272 { "LIGHT GREY", 192, 192, 192 },
273 { "LIGHT GRAY", 192, 192, 192 },
274 { "DARK GREY", 32, 32, 32 },
275 { "DARK GRAY", 32, 32, 32 },
276 { "CYAN", 0, 255, 255 },
277 { "MAGENTA", 255, 255, 0 },
283 int XParseColor(Display
* display
, Colormap cmap
,
284 const char* cname
, XColor
* color
)
289 if (!_wxColourDatabase
[i
].name
)
293 if (strcmp(cname
, _wxColourDatabase
[i
].name
) == 0)
295 color
->red
= _wxColourDatabase
[i
].red
;
296 color
->green
= _wxColourDatabase
[i
].green
;
297 color
->blue
= _wxColourDatabase
[i
].blue
;
305 /* Not found: use black */
313 int XDrawLine(Display
* display
, Window win
, GC gc
,
314 int x1
, int y1
, int x2
, int y2
)
322 GrDrawLines(win
, gc
, points
, 2);
326 int XTextExtents( XFontStruct
* font
, char* s
, int len
, int* direction
,
327 int* ascent
, int* descent2
, XCharStruct
* overall
)
329 GR_SIZE retwidth
, retheight
, retbase
;
330 GR_GC_ID gc
= GrNewGC();
332 *ascent
= font
->info
.baseline
;
333 *direction
= 1; /* ? */
334 *descent2
= 0; /* ? */
336 GrSetGCFont(gc
, font
->fid
);
338 /* TODO need to set the relevant flags for the character set.
339 * A good trick might be to pass a wxString instead of char*
343 GrGetGCTextSize(gc
, s
, len
, GR_TFASCII
, & retwidth
,
344 & retheight
, & retbase
);
347 overall
->width
= retwidth
;
348 overall
->lbearing
= 0;
349 overall
->rbearing
= 0;
350 overall
->ascent
= *ascent
;
351 overall
->descent
= 0;
352 overall
->attributes
= 0;
360 XFontStruct
* XLoadQueryFont(Display
* display
, const char* fontSpec
)
362 /* TODO: map fontSpec to something sensible for Nano-X */
363 char *fontName
= NULL
;
364 XFontStruct
* fontInfo
= malloc(sizeof(XFontStruct
));
365 fontInfo
->fid
= GrCreateFont(fontName
, 0, 0);
366 GrGetFontInfo(fontInfo
->fid
, & fontInfo
->info
);
367 printf("Warning: should not call XLoadQueryFont since font spec is not used in Nano-X.\n");
371 int XFreeFont(Display
* display
, XFontStruct
* fontStruct
)
373 GrDestroyFont(fontStruct
->fid
);
378 int XQueryColor(Display
* display
, Colormap cmap
, XColor
* color
)
380 /* cmap is a GR_PALETTE */
381 if (color
->pixel
< cmap
->count
)
383 color
->red
= cmap
->palette
[color
->pixel
].r
;
384 color
->green
= cmap
->palette
[color
->pixel
].g
;
385 color
->blue
= cmap
->palette
[color
->pixel
].b
;
392 int XConfigureWindow(Display
* display
, Window w
, int mask
, XWindowChanges
* changes
)
394 if ((mask
& CWX
) && (mask
& CWY
))
395 GrMoveWindow(w
, changes
->x
, changes
->y
);
396 if ((mask
& CWWidth
) && (mask
& CWHeight
))
397 GrResizeWindow(w
, changes
->width
, changes
->height
);
398 if (mask
& CWBorderWidth
)
402 if (mask
& CWSibling
)
406 if (mask
& CWStackMode
)
413 int XTranslateCoordinates(Display
* display
, Window srcWindow
, Window destWindow
, int srcX
, int srcY
, int* destX
, int* destY
, Window
* childReturn
)
418 Window w
= srcWindow
;
419 while (w
!= GR_ROOT_WINDOW_ID
)
422 GrGetWindowInfo(w
, & info
);
431 while (w
!= GR_ROOT_WINDOW_ID
)
434 GrGetWindowInfo(w
, & info
);
441 *destX
= srcX
+ offx
;
442 *destY
= srcY
+ offy
;
450 /* Should not really be necessary but in no-optimize mode
451 * gcc complains that wxNoop is not found if wxNoop is inline.