4 * Replacements for some comomon Xlib functions
5 * Licence: The wxWindows licence
13 #pragma implementation "Xlib.h"
21 #include "wx/x11/nanox/X11/Xlib.h"
23 /* Expands to some compatibility functions (see XtoNX.h) */
27 static GR_PALETTE
* s_globalColormap
= 0;
29 Colormap
DefaultColormapOfScreen(Screen
* screen
)
31 if (!s_globalColormap
)
33 s_globalColormap
= (GR_PALETTE
*) malloc(sizeof(GR_PALETTE
));
35 GrGetSystemPalette(s_globalColormap
);
38 return s_globalColormap
;
41 int XSetGraphicsExposures( Display
* display
, GC gc
, Bool graphics_exposures
)
46 int XWarpPointer( Display
* display
, Window srcW
, Window destW
,
48 unsigned int srcWidth
,
49 unsigned int srcHeight
,
52 GrMoveCursor(destX
, destY
);
56 int XSetInputFocus(Display
* display
, Window focus
, int revert_to
, Time time
)
62 int XGetInputFocus(Display
* display
, Window
* focus_return
, int* revert_to_return
)
64 * focus_return
= GrGetFocus();
65 * revert_to_return
= 0;
69 int XGrabPointer(Display
* display
, Window grab_window
,
70 Bool owner_events
, unsigned int event_mask
,
71 int pointer_mode
, int keyboard_mode
,
72 Window confine_to
, Cursor cursor
, Time time
)
74 /* According to comments in srvevent.c in Nano-X, the pointer
75 * is implicitly grabbed when a mouse button is down.
76 * We may be able to simulate this further in the event loop.
81 int XUngrabPointer(Display
* display
, Time time
)
86 int XCopyArea(Display
* display
, Drawable src
, Drawable dest
, GC gc
,
87 int src_x
, int src_y
, unsigned int width
, unsigned int height
,
88 int dest_x
, int dest_y
)
90 GrCopyArea(dest
, gc
, dest_x
, dest_y
,
96 int XCopyPlane(Display
* display
, Drawable src
, Drawable dest
, GC gc
,
97 int src_x
, int src_y
, unsigned int width
, unsigned int height
,
98 int dest_x
, int dest_y
, unsigned long plane
)
100 GrCopyArea(dest
, gc
, dest_x
, dest_y
,
108 GR_WINDOW_ID wid
; /* window id (or 0 if no such window) */
109 GR_WINDOW_ID parent
; /* parent window id */
110 GR_WINDOW_ID child
; /* first child window id (or 0) */
111 GR_WINDOW_ID sibling
; /* next sibling window id (or 0) */
112 GR_BOOL inputonly
; /* TRUE if window is input only */
113 GR_BOOL mapped
; /* TRUE if window is mapped */
114 GR_COUNT unmapcount
; /* reasons why window is unmapped */
115 GR_COORD x
; /* absolute x position of window */
116 GR_COORD y
; /* absolute y position of window */
117 GR_SIZE width
; /* width of window */
118 GR_SIZE height
; /* height of window */
119 GR_SIZE bordersize
; /* size of border */
120 GR_COLOR bordercolor
; /* color of border */
121 GR_COLOR background
; /* background color */
122 GR_EVENT_MASK eventmask
; /* current event mask for this client */
123 GR_WM_PROPS props
; /* window properties */
124 GR_CURSOR_ID cursor
; /* cursor id*/
125 unsigned long processid
; /* process id of owner*/
129 int x
, y
; /* location of window */
130 int width
, height
; /* width and height of window */
131 int border_width
; /* border width of window */
132 int depth
; /* depth of window */
133 Visual
*visual
; /* the associated visual structure */
134 Window root
; /* root of screen containing window */
135 int class; /* InputOutput, InputOnly*/
136 int bit_gravity
; /* one of the bit gravity values */
137 int win_gravity
; /* one of the window gravity values */
138 int backing_store
; /* NotUseful, WhenMapped, Always */
139 unsigned long backing_planes
;/* planes to be preserved if possible */
140 unsigned long backing_pixel
;/* value to be used when restoring planes */
141 Bool save_under
; /* boolean, should bits under be saved? */
142 Colormap colormap
; /* color map to be associated with window */
143 Bool map_installed
; /* boolean, is color map currently installed*/
144 int map_state
; /* IsUnmapped, IsUnviewable, IsViewable */
145 long all_event_masks
; /* set of events all people have interest in*/
146 long your_event_mask
; /* my event mask */
147 long do_not_propagate_mask
;/* set of events that should not propagate */
148 Bool override_redirect
; /* boolean value for override-redirect */
149 Screen
*screen
; /* back pointer to correct screen */
155 Status
XGetWindowAttributes(Display
* display
, Window w
,
156 XWindowAttributes
* window_attributes
)
161 GrGetWindowInfo(w
, & info
);
163 window_attributes
->x
= info
.x
;
164 window_attributes
->y
= info
.y
;
165 window_attributes
->width
= info
.width
;
166 window_attributes
->height
= info
.height
;
167 window_attributes
->border_width
= info
.bordersize
;
168 window_attributes
->depth
= 0;
169 window_attributes
->visual
= NULL
;
170 window_attributes
->root
= 0;
171 window_attributes
->_class
= info
.inputonly
? InputOnly
: InputOutput
;
172 window_attributes
->bit_gravity
= 0;
173 window_attributes
->win_gravity
= 0;
174 window_attributes
->backing_store
= 0;
175 window_attributes
->backing_planes
= 0;
176 window_attributes
->backing_pixel
= 0;
177 window_attributes
->save_under
= FALSE
;
178 window_attributes
->colormap
= DefaultColormapOfScreen(0);
179 window_attributes
->map_installed
= FALSE
;
180 window_attributes
->map_state
= info
.mapped
? IsViewable
: IsUnmapped
;
181 window_attributes
->all_event_masks
= 0;
182 window_attributes
->do_not_propagate_mask
= 0;
183 window_attributes
->override_redirect
= FALSE
;
184 window_attributes
->screen
= NULL
;
186 /* We need to check if any parents are unmapped,
187 * or we will report a window as mapped when it is not.
189 parent
= info
.parent
;
192 GrGetWindowInfo(parent
, & info
);
193 if (info
.mapped
== 0)
194 window_attributes
->map_state
= IsUnmapped
;
196 parent
= info
.parent
;
202 static XErrorHandler
* g_ErrorHandler
= NULL
;
204 void DefaultNanoXErrorHandler(GR_EVENT_ERROR
* ep
)
208 XErrorEvent errEvent
;
209 errEvent
.type
= ep
->type
;
210 errEvent
.display
= NULL
;
211 errEvent
.resourceid
= ep
->id
;
213 errEvent
.error_code
= ep
->code
;
214 errEvent
.request_code
= 0;
215 errEvent
.minor_code
= 0;
216 (*g_ErrorHandler
)(NULL
, & errEvent
);
220 XErrorHandler
XSetErrorHandler (XErrorHandler handler
)
222 XErrorHandler oldHandler
= g_ErrorHandler
;
223 g_ErrorHandler
= handler
;
224 GrSetErrorHandler(DefaultNanoXErrorHandler
);
228 static Screen s_screen
;
229 Screen
*XScreenOfDisplay(Display
* display
,
232 /* TODO: fill in the members. See Xlib.h */
236 int DisplayWidth(Display
* display
, int screen
)
238 return _display
.display_width
;
241 int DisplayHeight(Display
* display
, int screen
)
243 return _display
.display_height
;
246 int DefaultDepth(Display
* display
, int screen
)
248 return _display
.display_bpp
;
251 int XAllocColor(Display
* display
, Colormap cmap
,
255 GrFindColor(GR_RGB(color
->red
, color
->green
, color
->blue
), & pixel
);
256 color
->pixel
= pixel
;
267 static _wxColourEntry _wxColourDatabase
[] =
269 { "WHITE", 255, 255, 255 },
270 { "BLACK", 0, 0, 0 },
271 { "RED", 255, 0, 0 },
272 { "GREEN", 0, 255, 0 },
273 { "BLUE", 0, 255, 255 },
274 { "GREY", 128, 128, 128 },
275 { "GRAY", 128, 128, 128 },
276 { "LIGHT GREY", 192, 192, 192 },
277 { "LIGHT GRAY", 192, 192, 192 },
278 { "DARK GREY", 32, 32, 32 },
279 { "DARK GRAY", 32, 32, 32 },
280 { "CYAN", 0, 255, 255 },
281 { "MAGENTA", 255, 255, 0 },
287 int XParseColor(Display
* display
, Colormap cmap
,
288 const char* cname
, XColor
* color
)
293 if (!_wxColourDatabase
[i
].name
)
297 if (strcmp(cname
, _wxColourDatabase
[i
].name
) == 0)
299 color
->red
= _wxColourDatabase
[i
].red
;
300 color
->green
= _wxColourDatabase
[i
].green
;
301 color
->blue
= _wxColourDatabase
[i
].blue
;
309 /* Not found: use black */
317 int XDrawLine(Display
* display
, Window win
, GC gc
,
318 int x1
, int y1
, int x2
, int y2
)
326 GrDrawLines(win
, gc
, points
, 2);
330 int XTextExtents( XFontStruct
* font
, char* s
, int len
, int* direction
,
331 int* ascent
, int* descent2
, XCharStruct
* overall
)
333 GR_SIZE retwidth
, retheight
, retbase
;
334 GR_GC_ID gc
= GrNewGC();
336 *ascent
= font
->info
.baseline
;
337 *direction
= 1; /* ? */
338 *descent2
= 0; /* ? */
340 GrSetGCFont(gc
, font
->fid
);
342 /* TODO need to set the relevant flags for the character set.
343 * A good trick might be to pass a wxString instead of char*
347 GrGetGCTextSize(gc
, s
, len
, GR_TFASCII
, & retwidth
,
348 & retheight
, & retbase
);
351 overall
->width
= retwidth
;
352 overall
->lbearing
= 0;
353 overall
->rbearing
= 0;
354 overall
->ascent
= *ascent
;
355 overall
->descent
= 0;
356 overall
->attributes
= 0;
364 XFontStruct
* XLoadQueryFont(Display
* display
, const char* fontSpec
)
366 /* TODO: map fontSpec to something sensible for Nano-X */
367 char *fontName
= NULL
;
368 XFontStruct
* fontInfo
= malloc(sizeof(XFontStruct
));
369 fontInfo
->fid
= GrCreateFont(fontName
, 0, 0);
370 GrGetFontInfo(fontInfo
->fid
, & fontInfo
->info
);
371 printf("Warning: should not call XLoadQueryFont since font spec is not used in Nano-X.\n");
375 int XFreeFont(Display
* display
, XFontStruct
* fontStruct
)
377 GrDestroyFont(fontStruct
->fid
);
382 int XQueryColor(Display
* display
, Colormap cmap
, XColor
* color
)
384 /* cmap is a GR_PALETTE */
385 if (color
->pixel
< cmap
->count
)
387 color
->red
= cmap
->palette
[color
->pixel
].r
;
388 color
->green
= cmap
->palette
[color
->pixel
].g
;
389 color
->blue
= cmap
->palette
[color
->pixel
].b
;
396 int XConfigureWindow(Display
* display
, Window w
, int mask
, XWindowChanges
* changes
)
398 if ((mask
& CWX
) && (mask
& CWY
))
399 GrMoveWindow(w
, changes
->x
, changes
->y
);
400 if ((mask
& CWWidth
) && (mask
& CWHeight
))
401 GrResizeWindow(w
, changes
->width
, changes
->height
);
402 if (mask
& CWBorderWidth
)
406 if (mask
& CWSibling
)
410 if (mask
& CWStackMode
)
417 int XTranslateCoordinates(Display
* display
, Window srcWindow
, Window destWindow
, int srcX
, int srcY
, int* destX
, int* destY
, Window
* childReturn
)
422 Window w
= srcWindow
;
423 while (w
!= GR_ROOT_WINDOW_ID
)
426 GrGetWindowInfo(w
, & info
);
435 while (w
!= GR_ROOT_WINDOW_ID
)
438 GrGetWindowInfo(w
, & info
);
445 *destX
= srcX
+ offx
;
446 *destY
= srcY
+ offy
;
454 /* Should not really be necessary but in no-optimize mode
455 * gcc complains that wxNoop is not found if wxNoop is inline.