4 * Replacements for some comomon Xlib functions
12 #pragma implementation "Xlib.h"
19 #include "wx/x11/nanox/X11/Xlib.h"
21 /* Expands to some compatibility functions (see XtoNX.h) */
25 static GR_PALETTE
* s_globalColormap
= 0;
27 Colormap
DefaultColormapOfScreen(Screen
* screen
)
29 if (!s_globalColormap
)
31 s_globalColormap
= (GR_PALETTE
*) malloc(sizeof(GR_PALETTE
));
33 GrGetSystemPalette(s_globalColormap
);
36 return s_globalColormap
;
39 int XSetGraphicsExposures( Display
* display
, GC gc
, Bool graphics_exposures
)
44 int XWarpPointer( Display
* display
, Window srcW
, Window destW
,
46 unsigned int srcWidth
,
47 unsigned int srcHeight
,
50 GrMoveCursor(destX
, destY
);
54 int XSetInputFocus(Display
* display
, Window focus
, int revert_to
, Time time
)
60 int XGetInputFocus(Display
* display
, Window
* focus_return
, int* revert_to_return
)
62 * focus_return
= GrGetFocus();
63 * revert_to_return
= 0;
67 int XGrabPointer(Display
* display
, Window grab_window
,
68 Bool owner_events
, unsigned int event_mask
,
69 int pointer_mode
, int keyboard_mode
,
70 Window confine_to
, Cursor cursor
, Time time
)
72 /* According to comments in srvevent.c in Nano-X, the pointer
73 * is implicitly grabbed when a mouse button is down.
74 * We may be able to simulate this further in the event loop.
79 int XUngrabPointer(Display
* display
, Time time
)
84 int XCopyArea(Display
* display
, Drawable src
, Drawable dest
, GC gc
,
85 int src_x
, int src_y
, unsigned int width
, unsigned int height
,
86 int dest_x
, int dest_y
)
88 GrCopyArea(dest
, gc
, dest_x
, dest_y
,
94 int XCopyPlane(Display
* display
, Drawable src
, Drawable dest
, GC gc
,
95 int src_x
, int src_y
, unsigned int width
, unsigned int height
,
96 int dest_x
, int dest_y
, unsigned long plane
)
98 GrCopyArea(dest
, gc
, dest_x
, dest_y
,
106 GR_WINDOW_ID wid
; /* window id (or 0 if no such window) */
107 GR_WINDOW_ID parent
; /* parent window id */
108 GR_WINDOW_ID child
; /* first child window id (or 0) */
109 GR_WINDOW_ID sibling
; /* next sibling window id (or 0) */
110 GR_BOOL inputonly
; /* TRUE if window is input only */
111 GR_BOOL mapped
; /* TRUE if window is mapped */
112 GR_COUNT unmapcount
; /* reasons why window is unmapped */
113 GR_COORD x
; /* absolute x position of window */
114 GR_COORD y
; /* absolute y position of window */
115 GR_SIZE width
; /* width of window */
116 GR_SIZE height
; /* height of window */
117 GR_SIZE bordersize
; /* size of border */
118 GR_COLOR bordercolor
; /* color of border */
119 GR_COLOR background
; /* background color */
120 GR_EVENT_MASK eventmask
; /* current event mask for this client */
121 GR_WM_PROPS props
; /* window properties */
122 GR_CURSOR_ID cursor
; /* cursor id*/
123 unsigned long processid
; /* process id of owner*/
127 int x
, y
; /* location of window */
128 int width
, height
; /* width and height of window */
129 int border_width
; /* border width of window */
130 int depth
; /* depth of window */
131 Visual
*visual
; /* the associated visual structure */
132 Window root
; /* root of screen containing window */
133 int class; /* InputOutput, InputOnly*/
134 int bit_gravity
; /* one of the bit gravity values */
135 int win_gravity
; /* one of the window gravity values */
136 int backing_store
; /* NotUseful, WhenMapped, Always */
137 unsigned long backing_planes
;/* planes to be preserved if possible */
138 unsigned long backing_pixel
;/* value to be used when restoring planes */
139 Bool save_under
; /* boolean, should bits under be saved? */
140 Colormap colormap
; /* color map to be associated with window */
141 Bool map_installed
; /* boolean, is color map currently installed*/
142 int map_state
; /* IsUnmapped, IsUnviewable, IsViewable */
143 long all_event_masks
; /* set of events all people have interest in*/
144 long your_event_mask
; /* my event mask */
145 long do_not_propagate_mask
;/* set of events that should not propagate */
146 Bool override_redirect
; /* boolean value for override-redirect */
147 Screen
*screen
; /* back pointer to correct screen */
153 Status
XGetWindowAttributes(Display
* display
, Window w
,
154 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
;
185 static XErrorHandler
* g_ErrorHandler
= NULL
;
187 static void DefaultNanoXErrorHandler(GR_EVENT_ERROR
* ep
)
191 XErrorEvent errEvent
;
192 errEvent
.type
= ep
->type
;
193 errEvent
.display
= NULL
;
194 errEvent
.resourceid
= ep
->id
;
196 errEvent
.error_code
= ep
->code
;
197 errEvent
.request_code
= 0;
198 errEvent
.minor_code
= 0;
199 (*g_ErrorHandler
)(NULL
, & errEvent
);
203 XErrorHandler
XSetErrorHandler (XErrorHandler handler
)
205 XErrorHandler oldHandler
= g_ErrorHandler
;
206 g_ErrorHandler
= handler
;
207 GrSetErrorHandler(DefaultNanoXErrorHandler
);
211 static Screen s_screen
;
212 Screen
*XScreenOfDisplay(Display
* display
,
215 /* TODO: fill in the members. See Xlib.h */
219 int DisplayWidth(Display
* display
, int screen
)
221 return _display
.display_width
;
224 int DisplayHeight(Display
* display
, int screen
)
226 return _display
.display_height
;
229 int DefaultDepth(Display
* display
, int screen
)
231 return _display
.display_bpp
;
234 int XAllocColor(Display
* display
, Colormap cmap
,
238 GrFindColor(GR_RGB(color
->red
, color
->green
, color
->blue
), & pixel
);
239 color
->pixel
= pixel
;
250 static _wxColourEntry _wxColourDatabase
[] =
252 { "WHITE", 255, 255, 255 },
253 { "BLACK", 0, 0, 0 },
254 { "RED", 255, 0, 0 },
255 { "GREEN", 0, 255, 0 },
256 { "BLUE", 0, 255, 255 },
257 { "GREY", 128, 128, 128 },
258 { "GRAY", 128, 128, 128 },
259 { "LIGHT GREY", 192, 192, 192 },
260 { "LIGHT GRAY", 192, 192, 192 },
261 { "DARK GREY", 32, 32, 32 },
262 { "DARK GRAY", 32, 32, 32 },
263 { "CYAN", 0, 255, 255 },
264 { "MAGENTA", 255, 255, 0 },
270 int XParseColor(Display
* display
, Colormap cmap
,
271 const char* cname
, XColor
* color
)
276 if (!_wxColourDatabase
[i
].name
)
280 if (strcmp(cname
, _wxColourDatabase
[i
].name
) == 0)
282 color
->red
= _wxColourDatabase
[i
].red
;
283 color
->green
= _wxColourDatabase
[i
].green
;
284 color
->blue
= _wxColourDatabase
[i
].blue
;
292 /* Not found: use black */
300 int XDrawLine(Display
* display
, Window win
, GC gc
,
301 int x1
, int y1
, int x2
, int y2
)
309 GrDrawLines(win
, gc
, points
, 2);
313 int XTextExtents( XFontStruct
* font
, char* s
, int len
, int* direction
,
314 int* ascent
, int* descent2
, XCharStruct
* overall
)
316 GR_SIZE retwidth
, retheight
, retbase
;
317 GR_GC_ID gc
= GrNewGC();
319 *ascent
= font
->info
.baseline
;
320 *direction
= 1; /* ? */
321 *descent2
= 0; /* ? */
323 GrSetGCFont(gc
, font
->fid
);
325 /* TODO need to set the relevant flags for the character set.
326 * A good trick might be to pass a wxString instead of char*
330 GrGetGCTextSize(gc
, s
, len
, GR_TFASCII
, & retwidth
,
331 & retheight
, & retbase
);
334 overall
->width
= retwidth
;
335 overall
->lbearing
= 0;
336 overall
->rbearing
= 0;
337 overall
->ascent
= *ascent
;
338 overall
->descent
= 0;
339 overall
->attributes
= 0;
347 XFontStruct
* XLoadQueryFont(Display
* display
, const char* fontSpec
)
349 /* TODO: map fontSpec to something sensible for Nano-X */
350 char *fontName
= NULL
;
351 XFontStruct
* fontInfo
= malloc(sizeof(XFontStruct
));
352 fontInfo
->fid
= GrCreateFont(fontName
, 0, 0);
353 GrGetFontInfo(fontInfo
->fid
, & fontInfo
->info
);
357 int XFreeFont(Display
* display
, XFontStruct
* fontStruct
)
359 GrDestroyFont(fontStruct
->fid
);
364 int XQueryColor(Display
* display
, Colormap cmap
, XColor
* color
)
366 /* cmap is a GR_PALETTE */
367 if (color
->pixel
< cmap
->count
)
369 color
->red
= cmap
->palette
[color
->pixel
].r
;
370 color
->green
= cmap
->palette
[color
->pixel
].g
;
371 color
->blue
= cmap
->palette
[color
->pixel
].b
;
378 int XConfigureWindow(Display
* display
, Window w
, int mask
, XWindowChanges
* changes
)
380 if ((mask
& CWX
) && (mask
& CWY
))
381 GrMoveWindow(w
, changes
->x
, changes
->y
);
382 if ((mask
& CWWidth
) && (mask
& CWHeight
))
383 GrResizeWindow(w
, changes
->width
, changes
->height
);
384 if (mask
& CWBorderWidth
)
388 if (mask
& CWSibling
)
392 if (mask
& CWStackMode
)
399 int XTranslateCoordinates(Display
* display
, Window srcWindow
, Window destWindow
, int srcX
, int srcY
, int* destX
, int* destY
, Window
* childReturn
)
404 Window w
= srcWindow
;
405 while (w
!= GR_ROOT_WINDOW_ID
)
408 GrGetWindowInfo(w
, & info
);
417 while (w
!= GR_ROOT_WINDOW_ID
)
420 GrGetWindowInfo(w
, & info
);
427 *destX
= srcX
+ offx
;
428 *destY
= srcY
+ offy
;