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
)
158 GrGetWindowInfo(w
, & info
);
160 window_attributes
->x
= info
.x
;
161 window_attributes
->y
= info
.y
;
162 window_attributes
->width
= info
.width
;
163 window_attributes
->height
= info
.height
;
164 window_attributes
->border_width
= info
.bordersize
;
165 window_attributes
->depth
= 0;
166 window_attributes
->visual
= NULL
;
167 window_attributes
->root
= 0;
168 window_attributes
->_class
= info
.inputonly
? InputOnly
: InputOutput
;
169 window_attributes
->bit_gravity
= 0;
170 window_attributes
->win_gravity
= 0;
171 window_attributes
->backing_store
= 0;
172 window_attributes
->backing_planes
= 0;
173 window_attributes
->backing_pixel
= 0;
174 window_attributes
->save_under
= FALSE
;
175 window_attributes
->colormap
= DefaultColormapOfScreen(0);
176 window_attributes
->map_installed
= FALSE
;
177 window_attributes
->map_state
= info
.mapped
? IsViewable
: IsUnmapped
;
178 window_attributes
->all_event_masks
= 0;
179 window_attributes
->do_not_propagate_mask
= 0;
180 window_attributes
->override_redirect
= FALSE
;
181 window_attributes
->screen
= NULL
;
186 static XErrorHandler
* g_ErrorHandler
= NULL
;
188 static void DefaultNanoXErrorHandler(GR_EVENT_ERROR
* ep
)
192 XErrorEvent errEvent
;
193 errEvent
.type
= ep
->type
;
194 errEvent
.display
= NULL
;
195 errEvent
.resourceid
= ep
->id
;
197 errEvent
.error_code
= ep
->code
;
198 errEvent
.request_code
= 0;
199 errEvent
.minor_code
= 0;
200 (*g_ErrorHandler
)(NULL
, & errEvent
);
204 XErrorHandler
XSetErrorHandler (XErrorHandler handler
)
206 XErrorHandler oldHandler
= g_ErrorHandler
;
207 g_ErrorHandler
= handler
;
208 GrSetErrorHandler(DefaultNanoXErrorHandler
);
212 static Screen s_screen
;
213 Screen
*XScreenOfDisplay(Display
* display
,
216 /* TODO: fill in the members. See Xlib.h */
220 int DisplayWidth(Display
* display
, int screen
)
222 return _display
.display_width
;
225 int DisplayHeight(Display
* display
, int screen
)
227 return _display
.display_height
;
230 int DefaultDepth(Display
* display
, int screen
)
232 return _display
.display_bpp
;
235 int XAllocColor(Display
* display
, Colormap cmap
,
239 GrFindColor(GR_RGB(color
->red
, color
->green
, color
->blue
), & pixel
);
240 color
->pixel
= pixel
;
251 static _wxColourEntry _wxColourDatabase
[] =
253 { "WHITE", 255, 255, 255 },
254 { "BLACK", 0, 0, 0 },
255 { "RED", 255, 0, 0 },
256 { "GREEN", 0, 255, 0 },
257 { "BLUE", 0, 255, 255 },
258 { "GREY", 128, 128, 128 },
259 { "GRAY", 128, 128, 128 },
260 { "LIGHT GREY", 192, 192, 192 },
261 { "LIGHT GRAY", 192, 192, 192 },
262 { "DARK GREY", 32, 32, 32 },
263 { "DARK GRAY", 32, 32, 32 },
264 { "CYAN", 0, 255, 255 },
265 { "MAGENTA", 255, 255, 0 },
271 int XParseColor(Display
* display
, Colormap cmap
,
272 const char* cname
, XColor
* color
)
277 if (!_wxColourDatabase
[i
].name
)
281 if (strcmp(cname
, _wxColourDatabase
[i
].name
) == 0)
283 color
->red
= _wxColourDatabase
[i
].red
;
284 color
->green
= _wxColourDatabase
[i
].green
;
285 color
->blue
= _wxColourDatabase
[i
].blue
;
293 /* Not found: use black */
301 int XDrawLine(Display
* display
, Window win
, GC gc
,
302 int x1
, int y1
, int x2
, int y2
)
310 GrDrawLines(win
, gc
, points
, 2);
314 int XTextExtents( XFontStruct
* font
, char* s
, int len
, int* direction
,
315 int* ascent
, int* descent2
, XCharStruct
* overall
)
317 GR_SIZE retwidth
, retheight
, retbase
;
318 GR_GC_ID gc
= GrNewGC();
320 *ascent
= font
->info
.baseline
;
321 *direction
= 1; /* ? */
322 *descent2
= 0; /* ? */
324 GrSetGCFont(gc
, font
->fid
);
326 /* TODO need to set the relevant flags for the character set.
327 * A good trick might be to pass a wxString instead of char*
331 GrGetGCTextSize(gc
, s
, len
, GR_TFASCII
, & retwidth
,
332 & retheight
, & retbase
);
335 overall
->width
= retwidth
;
336 overall
->lbearing
= 0;
337 overall
->rbearing
= 0;
338 overall
->ascent
= *ascent
;
339 overall
->descent
= 0;
340 overall
->attributes
= 0;
348 XFontStruct
* XLoadQueryFont(Display
* display
, const char* fontSpec
)
350 /* TODO: map fontSpec to something sensible for Nano-X */
351 char *fontName
= NULL
;
352 XFontStruct
* fontInfo
= malloc(sizeof(XFontStruct
));
353 fontInfo
->fid
= GrCreateFont(fontName
, 0, 0);
354 GrGetFontInfo(fontInfo
->fid
, & fontInfo
->info
);
355 printf("Warning: should not call XLoadQueryFont since font spec is not used in Nano-X.\n");
359 int XFreeFont(Display
* display
, XFontStruct
* fontStruct
)
361 GrDestroyFont(fontStruct
->fid
);
366 int XQueryColor(Display
* display
, Colormap cmap
, XColor
* color
)
368 /* cmap is a GR_PALETTE */
369 if (color
->pixel
< cmap
->count
)
371 color
->red
= cmap
->palette
[color
->pixel
].r
;
372 color
->green
= cmap
->palette
[color
->pixel
].g
;
373 color
->blue
= cmap
->palette
[color
->pixel
].b
;
380 int XConfigureWindow(Display
* display
, Window w
, int mask
, XWindowChanges
* changes
)
382 if ((mask
& CWX
) && (mask
& CWY
))
383 GrMoveWindow(w
, changes
->x
, changes
->y
);
384 if ((mask
& CWWidth
) && (mask
& CWHeight
))
385 GrResizeWindow(w
, changes
->width
, changes
->height
);
386 if (mask
& CWBorderWidth
)
390 if (mask
& CWSibling
)
394 if (mask
& CWStackMode
)
401 int XTranslateCoordinates(Display
* display
, Window srcWindow
, Window destWindow
, int srcX
, int srcY
, int* destX
, int* destY
, Window
* childReturn
)
406 Window w
= srcWindow
;
407 while (w
!= GR_ROOT_WINDOW_ID
)
410 GrGetWindowInfo(w
, & info
);
419 while (w
!= GR_ROOT_WINDOW_ID
)
422 GrGetWindowInfo(w
, & info
);
429 *destX
= srcX
+ offx
;
430 *destY
= srcY
+ offy
;
438 /* Should not really be necessary but in no-optimize mode
439 * gcc complains that wxNoop is not found if wxNoop is inline.