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