]> git.saurik.com Git - wxWidgets.git/blob - src/x11/nanox.c
No res-include for rpmspec wx24dsp
[wxWidgets.git] / src / x11 / nanox.c
1 /*
2 * nanox.c
3 *
4 * Replacements for some comomon Xlib functions
5 * Licence: The wxWidgets licence
6 */
7
8 #include "wx/setup.h"
9
10 #if wxUSE_NANOX
11
12 #ifdef __GNUG__
13 #pragma implementation "Xlib.h"
14 #endif
15
16 #include <ctype.h>
17 #include <malloc.h>
18 #include <string.h>
19 #include <stdio.h>
20 #include "wx/defs.h"
21 #include "wx/x11/nanox/X11/Xlib.h"
22
23 /* Expands to some compatibility functions (see XtoNX.h) */
24
25 STATIC_FUNCTIONS
26
27 static GR_PALETTE* s_globalColormap = 0;
28
29 Colormap DefaultColormapOfScreen(Screen* screen)
30 {
31 if (!s_globalColormap)
32 {
33 s_globalColormap = (GR_PALETTE*) malloc(sizeof(GR_PALETTE));
34
35 GrGetSystemPalette(s_globalColormap);
36 }
37
38 return s_globalColormap;
39 }
40
41 int XSetGraphicsExposures( Display* display, GC gc, Bool graphics_exposures)
42 {
43 return Success ;
44 }
45
46 int XWarpPointer( Display* display, Window srcW, Window destW,
47 int srcX, int srcY,
48 unsigned int srcWidth,
49 unsigned int srcHeight,
50 int destX, int destY)
51 {
52 GrMoveCursor(destX, destY);
53 return Success;
54 }
55
56 int XSetInputFocus(Display* display, Window focus, int revert_to, Time time)
57 {
58 GrSetFocus(focus);
59 return Success;
60 }
61
62 int XGetInputFocus(Display* display, Window* focus_return, int* revert_to_return)
63 {
64 * focus_return = GrGetFocus();
65 * revert_to_return = 0;
66 return Success;
67 }
68
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)
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
81 int XUngrabPointer(Display* display, Time time)
82 {
83 return Success;
84 }
85
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)
89 {
90 GrCopyArea(dest, gc, dest_x, dest_y,
91 width, height, src,
92 src_x, src_y, 0);
93 return Success;
94 }
95
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)
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,
156 XWindowAttributes* window_attributes)
157 {
158 GR_WINDOW_INFO info;
159 Window parent = 0;
160 GrFlush();
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;
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;
185
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
199 return 1;
200 }
201
202 static XErrorHandler* g_ErrorHandler = NULL;
203
204 void DefaultNanoXErrorHandler(GR_EVENT_ERROR* ep)
205 {
206 if (g_ErrorHandler)
207 {
208 XErrorEvent errEvent;
209 errEvent.type = ep->type;
210 errEvent.display = NULL;
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;
216 (*g_ErrorHandler)(NULL, & errEvent);
217 }
218 }
219
220 XErrorHandler XSetErrorHandler (XErrorHandler handler)
221 {
222 XErrorHandler oldHandler = g_ErrorHandler;
223 g_ErrorHandler = handler;
224 GrSetErrorHandler(DefaultNanoXErrorHandler);
225 return oldHandler;
226 }
227
228 static Screen s_screen;
229 Screen *XScreenOfDisplay(Display* display,
230 int screen_number)
231 {
232 /* TODO: fill in the members. See Xlib.h */
233 return & s_screen;
234 }
235
236 int DisplayWidth(Display* display, int screen)
237 {
238 return _display.display_width;
239 }
240
241 int DisplayHeight(Display* display, int screen)
242 {
243 return _display.display_height;
244 }
245
246 int DefaultDepth(Display* display, int screen)
247 {
248 return _display.display_bpp;
249 }
250
251 int XAllocColor(Display* display, Colormap cmap,
252 XColor* color)
253 {
254 GR_PIXELVAL pixel;
255 GrFindColor(GR_RGB(color->red, color->green, color->blue), & pixel);
256 color->pixel = pixel;
257 return 1;
258 }
259
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
287 int XParseColor(Display* display, Colormap cmap,
288 const char* cname, XColor* color)
289 {
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
314 return 0;
315 }
316
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);
371 printf("Warning: should not call XLoadQueryFont since font spec is not used in Nano-X.\n");
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
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
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
462 #endif
463 /* wxUSE_NANOX */