]>
Commit | Line | Data |
---|---|---|
5ed738a7 JS |
1 | /* |
2 | * nanox.c | |
3 | * | |
4 | * Replacements for some comomon Xlib functions | |
84969af7 | 5 | * Licence: The wxWindows licence |
5ed738a7 JS |
6 | */ |
7 | ||
8 | #include "wx/setup.h" | |
9 | ||
10 | #if wxUSE_NANOX | |
11 | ||
461e93f9 JS |
12 | #ifdef __GNUG__ |
13 | #pragma implementation "Xlib.h" | |
14 | #endif | |
15 | ||
788519c6 JS |
16 | #include <ctype.h> |
17 | #include <malloc.h> | |
461e93f9 | 18 | #include <string.h> |
16d865f7 | 19 | #include <stdio.h> |
788519c6 | 20 | #include "wx/defs.h" |
5ed738a7 JS |
21 | #include "wx/x11/nanox/X11/Xlib.h" |
22 | ||
c79a329d JS |
23 | /* Expands to some compatibility functions (see XtoNX.h) */ |
24 | ||
25 | STATIC_FUNCTIONS | |
26 | ||
788519c6 | 27 | static GR_PALETTE* s_globalColormap = 0; |
5ed738a7 | 28 | |
788519c6 JS |
29 | Colormap DefaultColormapOfScreen(Screen* screen) |
30 | { | |
31 | if (!s_globalColormap) | |
5ed738a7 | 32 | { |
c79a329d JS |
33 | s_globalColormap = (GR_PALETTE*) malloc(sizeof(GR_PALETTE)); |
34 | ||
35 | GrGetSystemPalette(s_globalColormap); | |
5ed738a7 JS |
36 | } |
37 | ||
38 | return s_globalColormap; | |
39 | } | |
40 | ||
788519c6 | 41 | int XSetGraphicsExposures( Display* display, GC gc, Bool graphics_exposures) |
e941874b JS |
42 | { |
43 | return Success ; | |
44 | } | |
45 | ||
788519c6 JS |
46 | int XWarpPointer( Display* display, Window srcW, Window destW, |
47 | int srcX, int srcY, | |
48 | unsigned int srcWidth, | |
49 | unsigned int srcHeight, | |
e941874b JS |
50 | int destX, int destY) |
51 | { | |
52 | GrMoveCursor(destX, destY); | |
53 | return Success; | |
54 | } | |
55 | ||
788519c6 | 56 | int XSetInputFocus(Display* display, Window focus, int revert_to, Time time) |
e941874b JS |
57 | { |
58 | GrSetFocus(focus); | |
59 | return Success; | |
60 | } | |
61 | ||
788519c6 | 62 | int XGetInputFocus(Display* display, Window* focus_return, int* revert_to_return) |
e941874b JS |
63 | { |
64 | * focus_return = GrGetFocus(); | |
65 | * revert_to_return = 0; | |
66 | return Success; | |
67 | } | |
68 | ||
788519c6 JS |
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) | |
e941874b JS |
73 | { |
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. | |
77 | */ | |
78 | return Success; | |
79 | } | |
80 | ||
461e93f9 | 81 | int XUngrabPointer(Display* display, Time time) |
e941874b JS |
82 | { |
83 | return Success; | |
84 | } | |
85 | ||
788519c6 | 86 | int XCopyArea(Display* display, Drawable src, Drawable dest, GC gc, |
e941874b JS |
87 | int src_x, int src_y, unsigned int width, unsigned int height, |
88 | int dest_x, int dest_y) | |
89 | { | |
90 | GrCopyArea(dest, gc, dest_x, dest_y, | |
91 | width, height, src, | |
92 | src_x, src_y, 0); | |
93 | return Success; | |
94 | } | |
95 | ||
788519c6 | 96 | int XCopyPlane(Display* display, Drawable src, Drawable dest, GC gc, |
e941874b | 97 | int src_x, int src_y, unsigned int width, unsigned int height, |
788519c6 | 98 | int dest_x, int dest_y, unsigned long plane) |
e941874b JS |
99 | { |
100 | GrCopyArea(dest, gc, dest_x, dest_y, | |
101 | width, height, src, | |
102 | src_x, src_y, 0); | |
103 | return Success; | |
104 | } | |
105 | ||
106 | #if 0 | |
107 | typedef struct { | |
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*/ | |
126 | } GR_WINDOW_INFO; | |
127 | ||
128 | typedef struct { | |
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 */ | |
150 | } XWindowAttributes; | |
151 | ||
152 | #endif | |
153 | ||
154 | ||
155 | Status XGetWindowAttributes(Display* display, Window w, | |
788519c6 | 156 | XWindowAttributes* window_attributes) |
e941874b JS |
157 | { |
158 | GR_WINDOW_INFO info; | |
ff6b424a JS |
159 | Window parent = 0; |
160 | GrFlush(); | |
e941874b JS |
161 | GrGetWindowInfo(w, & info); |
162 | ||
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; | |
788519c6 | 171 | window_attributes->_class = info.inputonly ? InputOnly : InputOutput ; |
e941874b JS |
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; | |
185 | ||
ff6b424a JS |
186 | /* We need to check if any parents are unmapped, |
187 | * or we will report a window as mapped when it is not. | |
188 | */ | |
189 | parent = info.parent; | |
190 | while (parent) | |
191 | { | |
192 | GrGetWindowInfo(parent, & info); | |
193 | if (info.mapped == 0) | |
194 | window_attributes->map_state = IsUnmapped; | |
195 | ||
196 | parent = info.parent; | |
197 | } | |
198 | ||
e941874b JS |
199 | return 1; |
200 | } | |
201 | ||
c79a329d JS |
202 | static XErrorHandler* g_ErrorHandler = NULL; |
203 | ||
ff6b424a | 204 | void DefaultNanoXErrorHandler(GR_EVENT_ERROR* ep) |
c79a329d JS |
205 | { |
206 | if (g_ErrorHandler) | |
207 | { | |
208 | XErrorEvent errEvent; | |
209 | errEvent.type = ep->type; | |
788519c6 | 210 | errEvent.display = NULL; |
c79a329d JS |
211 | errEvent.resourceid = ep->id; |
212 | errEvent.serial = 0; | |
213 | errEvent.error_code = ep->code; | |
214 | errEvent.request_code = 0; | |
215 | errEvent.minor_code = 0; | |
788519c6 | 216 | (*g_ErrorHandler)(NULL, & errEvent); |
c79a329d JS |
217 | } |
218 | } | |
219 | ||
220 | XErrorHandler XSetErrorHandler (XErrorHandler handler) | |
221 | { | |
222 | XErrorHandler oldHandler = g_ErrorHandler; | |
788519c6 JS |
223 | g_ErrorHandler = handler; |
224 | GrSetErrorHandler(DefaultNanoXErrorHandler); | |
c79a329d JS |
225 | return oldHandler; |
226 | } | |
227 | ||
788519c6 JS |
228 | static Screen s_screen; |
229 | Screen *XScreenOfDisplay(Display* display, | |
230 | int screen_number) | |
c79a329d | 231 | { |
c79a329d JS |
232 | /* TODO: fill in the members. See Xlib.h */ |
233 | return & s_screen; | |
234 | } | |
235 | ||
788519c6 | 236 | int DisplayWidth(Display* display, int screen) |
c79a329d JS |
237 | { |
238 | return _display.display_width; | |
239 | } | |
240 | ||
788519c6 | 241 | int DisplayHeight(Display* display, int screen) |
c79a329d JS |
242 | { |
243 | return _display.display_height; | |
244 | } | |
245 | ||
788519c6 | 246 | int DefaultDepth(Display* display, int screen) |
c79a329d JS |
247 | { |
248 | return _display.display_bpp; | |
249 | } | |
250 | ||
788519c6 | 251 | int XAllocColor(Display* display, Colormap cmap, |
c79a329d JS |
252 | XColor* color) |
253 | { | |
254 | GR_PIXELVAL pixel; | |
788519c6 JS |
255 | GrFindColor(GR_RGB(color->red, color->green, color->blue), & pixel); |
256 | color->pixel = pixel; | |
257 | return 1; | |
c79a329d JS |
258 | } |
259 | ||
461e93f9 JS |
260 | typedef struct { |
261 | const char* name; | |
262 | unsigned int red; | |
263 | unsigned int green; | |
264 | unsigned int blue; | |
265 | } _wxColourEntry; | |
266 | ||
267 | static _wxColourEntry _wxColourDatabase[] = | |
268 | { | |
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 }, | |
282 | ||
283 | /* TODO: the rest */ | |
284 | { NULL, 0, 0, 0 } | |
285 | }; | |
286 | ||
788519c6 | 287 | int XParseColor(Display* display, Colormap cmap, |
c79a329d JS |
288 | const char* cname, XColor* color) |
289 | { | |
461e93f9 JS |
290 | int i = 0; |
291 | for (;;) | |
292 | { | |
293 | if (!_wxColourDatabase[i].name) | |
294 | break; | |
295 | else | |
296 | { | |
297 | if (strcmp(cname, _wxColourDatabase[i].name) == 0) | |
298 | { | |
299 | color->red = _wxColourDatabase[i].red; | |
300 | color->green = _wxColourDatabase[i].green; | |
301 | color->blue = _wxColourDatabase[i].blue; | |
302 | ||
303 | return 1; | |
304 | } | |
305 | i ++; | |
306 | } | |
307 | } | |
308 | ||
309 | /* Not found: use black */ | |
310 | color->red = 0; | |
311 | color->green = 0; | |
312 | color->blue = 0; | |
313 | ||
c79a329d JS |
314 | return 0; |
315 | } | |
316 | ||
788519c6 JS |
317 | int XDrawLine(Display* display, Window win, GC gc, |
318 | int x1, int y1, int x2, int y2) | |
319 | { | |
320 | GR_POINT points[2]; | |
321 | points[0].x = x1; | |
322 | points[0].y = y1; | |
323 | points[1].x = x2; | |
324 | points[1].y = y2; | |
325 | ||
326 | GrDrawLines(win, gc, points, 2); | |
327 | return 1; | |
328 | } | |
329 | ||
330 | int XTextExtents( XFontStruct* font, char* s, int len, int* direction, | |
331 | int* ascent, int* descent2, XCharStruct* overall) | |
332 | { | |
333 | GR_SIZE retwidth, retheight, retbase; | |
334 | GR_GC_ID gc = GrNewGC(); | |
335 | ||
336 | *ascent = font->info.baseline; | |
337 | *direction = 1; /* ? */ | |
338 | *descent2 = 0; /* ? */ | |
339 | ||
340 | GrSetGCFont(gc, font->fid); | |
341 | ||
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* | |
344 | * to this function. | |
345 | */ | |
346 | ||
347 | GrGetGCTextSize(gc, s, len, GR_TFASCII, & retwidth, | |
348 | & retheight, & retbase); | |
349 | if (overall) | |
350 | { | |
351 | overall->width = retwidth; | |
352 | overall->lbearing = 0; | |
353 | overall->rbearing = 0; | |
354 | overall->ascent = *ascent; | |
355 | overall->descent = 0; | |
356 | overall->attributes = 0; | |
357 | } | |
358 | ||
359 | GrDestroyGC(gc); | |
360 | ||
361 | return 1; | |
362 | } | |
363 | ||
364 | XFontStruct* XLoadQueryFont(Display* display, const char* fontSpec) | |
365 | { | |
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); | |
16d865f7 | 371 | printf("Warning: should not call XLoadQueryFont since font spec is not used in Nano-X.\n"); |
788519c6 JS |
372 | return fontInfo; |
373 | } | |
374 | ||
375 | int XFreeFont(Display* display, XFontStruct* fontStruct) | |
376 | { | |
377 | GrDestroyFont(fontStruct->fid); | |
378 | free(fontStruct); | |
379 | return 1; | |
380 | } | |
381 | ||
382 | int XQueryColor(Display* display, Colormap cmap, XColor* color) | |
383 | { | |
384 | /* cmap is a GR_PALETTE */ | |
385 | if (color->pixel < cmap->count) | |
386 | { | |
387 | color->red = cmap->palette[color->pixel].r; | |
388 | color->green = cmap->palette[color->pixel].g; | |
389 | color->blue = cmap->palette[color->pixel].b; | |
390 | return 1; | |
391 | } | |
392 | else | |
393 | return 0; | |
394 | } | |
395 | ||
461e93f9 JS |
396 | int XConfigureWindow(Display* display, Window w, int mask, XWindowChanges* changes) |
397 | { | |
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) | |
403 | { | |
404 | /* TODO */ | |
405 | } | |
406 | if (mask & CWSibling) | |
407 | { | |
408 | /* TODO */ | |
409 | } | |
410 | if (mask & CWStackMode) | |
411 | { | |
412 | /* TODO */ | |
413 | } | |
414 | return 1; | |
415 | } | |
416 | ||
417 | int XTranslateCoordinates(Display* display, Window srcWindow, Window destWindow, int srcX, int srcY, int* destX, int* destY, Window* childReturn) | |
418 | { | |
419 | int offx = 0; | |
420 | int offy = 0; | |
421 | ||
422 | Window w = srcWindow; | |
423 | while (w != GR_ROOT_WINDOW_ID) | |
424 | { | |
425 | GR_WINDOW_INFO info; | |
426 | GrGetWindowInfo(w, & info); | |
427 | w = info.parent; | |
428 | ||
429 | offx += info.x ; | |
430 | offy += info.y ; | |
431 | } | |
432 | ||
433 | w = destWindow; | |
434 | ||
435 | while (w != GR_ROOT_WINDOW_ID) | |
436 | { | |
437 | GR_WINDOW_INFO info; | |
438 | GrGetWindowInfo(w, & info); | |
439 | w = info.parent; | |
440 | ||
441 | offx -= info.x ; | |
442 | offy -= info.y ; | |
443 | } | |
444 | ||
445 | *destX = srcX + offx; | |
446 | *destY = srcY + offy; | |
447 | ||
448 | if (childReturn) | |
449 | *childReturn = 0; | |
450 | ||
451 | return 1; | |
452 | } | |
453 | ||
0b5c0e1a JS |
454 | /* Should not really be necessary but in no-optimize mode |
455 | * gcc complains that wxNoop is not found if wxNoop is inline. | |
456 | */ | |
457 | ||
458 | void wxNoop() | |
459 | { | |
460 | } | |
461 | ||
5ed738a7 | 462 | #endif |
c79a329d | 463 | /* wxUSE_NANOX */ |