]> git.saurik.com Git - wxWidgets.git/blame - src/x11/nanox.c
fix should have been mac only
[wxWidgets.git] / src / x11 / nanox.c
CommitLineData
5ed738a7
JS
1/*
2 * nanox.c
3 *
4 * Replacements for some comomon Xlib functions
77ffb593 5 * Licence: The wxWidgets licence
5ed738a7
JS
6 */
7
8#include "wx/setup.h"
9
10#if wxUSE_NANOX
11
788519c6
JS
12#include <ctype.h>
13#include <malloc.h>
461e93f9 14#include <string.h>
16d865f7 15#include <stdio.h>
788519c6 16#include "wx/defs.h"
5ed738a7
JS
17#include "wx/x11/nanox/X11/Xlib.h"
18
c79a329d
JS
19/* Expands to some compatibility functions (see XtoNX.h) */
20
21STATIC_FUNCTIONS
22
788519c6 23static GR_PALETTE* s_globalColormap = 0;
5ed738a7 24
788519c6
JS
25Colormap DefaultColormapOfScreen(Screen* screen)
26{
27 if (!s_globalColormap)
5ed738a7 28 {
c79a329d
JS
29 s_globalColormap = (GR_PALETTE*) malloc(sizeof(GR_PALETTE));
30
31 GrGetSystemPalette(s_globalColormap);
5ed738a7
JS
32 }
33
34 return s_globalColormap;
35}
36
788519c6 37int XSetGraphicsExposures( Display* display, GC gc, Bool graphics_exposures)
e941874b
JS
38{
39 return Success ;
40}
41
788519c6
JS
42int XWarpPointer( Display* display, Window srcW, Window destW,
43 int srcX, int srcY,
44 unsigned int srcWidth,
45 unsigned int srcHeight,
e941874b
JS
46 int destX, int destY)
47{
48 GrMoveCursor(destX, destY);
49 return Success;
50}
51
788519c6 52int XSetInputFocus(Display* display, Window focus, int revert_to, Time time)
e941874b
JS
53{
54 GrSetFocus(focus);
55 return Success;
56}
57
788519c6 58int XGetInputFocus(Display* display, Window* focus_return, int* revert_to_return)
e941874b
JS
59{
60 * focus_return = GrGetFocus();
61 * revert_to_return = 0;
62 return Success;
63}
64
788519c6
JS
65int XGrabPointer(Display* display, Window grab_window,
66 Bool owner_events, unsigned int event_mask,
67 int pointer_mode, int keyboard_mode,
68 Window confine_to, Cursor cursor, Time time)
e941874b
JS
69{
70 /* According to comments in srvevent.c in Nano-X, the pointer
71 * is implicitly grabbed when a mouse button is down.
72 * We may be able to simulate this further in the event loop.
73 */
74 return Success;
75}
76
461e93f9 77int XUngrabPointer(Display* display, Time time)
e941874b
JS
78{
79 return Success;
80}
81
788519c6 82int XCopyArea(Display* display, Drawable src, Drawable dest, GC gc,
e941874b
JS
83 int src_x, int src_y, unsigned int width, unsigned int height,
84 int dest_x, int dest_y)
85{
86 GrCopyArea(dest, gc, dest_x, dest_y,
87 width, height, src,
88 src_x, src_y, 0);
89 return Success;
90}
91
788519c6 92int XCopyPlane(Display* display, Drawable src, Drawable dest, GC gc,
e941874b 93 int src_x, int src_y, unsigned int width, unsigned int height,
788519c6 94 int dest_x, int dest_y, unsigned long plane)
e941874b
JS
95{
96 GrCopyArea(dest, gc, dest_x, dest_y,
97 width, height, src,
98 src_x, src_y, 0);
99 return Success;
100}
101
102#if 0
103typedef struct {
104 GR_WINDOW_ID wid; /* window id (or 0 if no such window) */
105 GR_WINDOW_ID parent; /* parent window id */
106 GR_WINDOW_ID child; /* first child window id (or 0) */
107 GR_WINDOW_ID sibling; /* next sibling window id (or 0) */
108 GR_BOOL inputonly; /* TRUE if window is input only */
109 GR_BOOL mapped; /* TRUE if window is mapped */
110 GR_COUNT unmapcount; /* reasons why window is unmapped */
111 GR_COORD x; /* absolute x position of window */
112 GR_COORD y; /* absolute y position of window */
113 GR_SIZE width; /* width of window */
114 GR_SIZE height; /* height of window */
115 GR_SIZE bordersize; /* size of border */
116 GR_COLOR bordercolor; /* color of border */
117 GR_COLOR background; /* background color */
118 GR_EVENT_MASK eventmask; /* current event mask for this client */
119 GR_WM_PROPS props; /* window properties */
120 GR_CURSOR_ID cursor; /* cursor id*/
121 unsigned long processid; /* process id of owner*/
122} GR_WINDOW_INFO;
123
124typedef struct {
125 int x, y; /* location of window */
126 int width, height; /* width and height of window */
127 int border_width; /* border width of window */
128 int depth; /* depth of window */
129 Visual *visual; /* the associated visual structure */
130 Window root; /* root of screen containing window */
131 int class; /* InputOutput, InputOnly*/
132 int bit_gravity; /* one of the bit gravity values */
133 int win_gravity; /* one of the window gravity values */
134 int backing_store; /* NotUseful, WhenMapped, Always */
135 unsigned long backing_planes;/* planes to be preserved if possible */
136 unsigned long backing_pixel;/* value to be used when restoring planes */
137 Bool save_under; /* boolean, should bits under be saved? */
138 Colormap colormap; /* color map to be associated with window */
139 Bool map_installed; /* boolean, is color map currently installed*/
140 int map_state; /* IsUnmapped, IsUnviewable, IsViewable */
141 long all_event_masks; /* set of events all people have interest in*/
142 long your_event_mask; /* my event mask */
143 long do_not_propagate_mask;/* set of events that should not propagate */
144 Bool override_redirect; /* boolean value for override-redirect */
145 Screen *screen; /* back pointer to correct screen */
146} XWindowAttributes;
147
148#endif
149
150
151Status XGetWindowAttributes(Display* display, Window w,
788519c6 152 XWindowAttributes* window_attributes)
e941874b
JS
153{
154 GR_WINDOW_INFO info;
ff6b424a
JS
155 Window parent = 0;
156 GrFlush();
e941874b
JS
157 GrGetWindowInfo(w, & info);
158
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;
788519c6 167 window_attributes->_class = info.inputonly ? InputOnly : InputOutput ;
e941874b
JS
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;
181
ff6b424a
JS
182 /* We need to check if any parents are unmapped,
183 * or we will report a window as mapped when it is not.
184 */
185 parent = info.parent;
186 while (parent)
187 {
188 GrGetWindowInfo(parent, & info);
189 if (info.mapped == 0)
190 window_attributes->map_state = IsUnmapped;
191
192 parent = info.parent;
193 }
194
e941874b
JS
195 return 1;
196}
197
c79a329d
JS
198static XErrorHandler* g_ErrorHandler = NULL;
199
ff6b424a 200void DefaultNanoXErrorHandler(GR_EVENT_ERROR* ep)
c79a329d
JS
201{
202 if (g_ErrorHandler)
203 {
204 XErrorEvent errEvent;
205 errEvent.type = ep->type;
788519c6 206 errEvent.display = NULL;
c79a329d
JS
207 errEvent.resourceid = ep->id;
208 errEvent.serial = 0;
209 errEvent.error_code = ep->code;
210 errEvent.request_code = 0;
211 errEvent.minor_code = 0;
788519c6 212 (*g_ErrorHandler)(NULL, & errEvent);
c79a329d
JS
213 }
214}
215
216XErrorHandler XSetErrorHandler (XErrorHandler handler)
217{
218 XErrorHandler oldHandler = g_ErrorHandler;
788519c6
JS
219 g_ErrorHandler = handler;
220 GrSetErrorHandler(DefaultNanoXErrorHandler);
c79a329d
JS
221 return oldHandler;
222}
223
788519c6
JS
224static Screen s_screen;
225Screen *XScreenOfDisplay(Display* display,
226 int screen_number)
c79a329d 227{
c79a329d
JS
228 /* TODO: fill in the members. See Xlib.h */
229 return & s_screen;
230}
231
788519c6 232int DisplayWidth(Display* display, int screen)
c79a329d
JS
233{
234 return _display.display_width;
235}
236
788519c6 237int DisplayHeight(Display* display, int screen)
c79a329d
JS
238{
239 return _display.display_height;
240}
241
788519c6 242int DefaultDepth(Display* display, int screen)
c79a329d
JS
243{
244 return _display.display_bpp;
245}
246
788519c6 247int XAllocColor(Display* display, Colormap cmap,
c79a329d
JS
248 XColor* color)
249{
250 GR_PIXELVAL pixel;
788519c6
JS
251 GrFindColor(GR_RGB(color->red, color->green, color->blue), & pixel);
252 color->pixel = pixel;
253 return 1;
c79a329d
JS
254}
255
461e93f9
JS
256typedef struct {
257 const char* name;
258 unsigned int red;
259 unsigned int green;
260 unsigned int blue;
261} _wxColourEntry;
262
263static _wxColourEntry _wxColourDatabase[] =
264{
265 { "WHITE", 255, 255, 255 },
266 { "BLACK", 0, 0, 0 },
267 { "RED", 255, 0, 0 },
268 { "GREEN", 0, 255, 0 },
269 { "BLUE", 0, 255, 255 },
270 { "GREY", 128, 128, 128 },
271 { "GRAY", 128, 128, 128 },
272 { "LIGHT GREY", 192, 192, 192 },
273 { "LIGHT GRAY", 192, 192, 192 },
274 { "DARK GREY", 32, 32, 32 },
275 { "DARK GRAY", 32, 32, 32 },
276 { "CYAN", 0, 255, 255 },
277 { "MAGENTA", 255, 255, 0 },
278
279 /* TODO: the rest */
280 { NULL, 0, 0, 0 }
281};
282
788519c6 283int XParseColor(Display* display, Colormap cmap,
c79a329d
JS
284 const char* cname, XColor* color)
285{
461e93f9
JS
286 int i = 0;
287 for (;;)
288 {
289 if (!_wxColourDatabase[i].name)
290 break;
291 else
292 {
293 if (strcmp(cname, _wxColourDatabase[i].name) == 0)
294 {
295 color->red = _wxColourDatabase[i].red;
296 color->green = _wxColourDatabase[i].green;
297 color->blue = _wxColourDatabase[i].blue;
298
299 return 1;
300 }
301 i ++;
302 }
303 }
304
305 /* Not found: use black */
306 color->red = 0;
307 color->green = 0;
308 color->blue = 0;
309
c79a329d
JS
310 return 0;
311}
312
788519c6
JS
313int XDrawLine(Display* display, Window win, GC gc,
314 int x1, int y1, int x2, int y2)
315{
316 GR_POINT points[2];
317 points[0].x = x1;
318 points[0].y = y1;
319 points[1].x = x2;
320 points[1].y = y2;
321
322 GrDrawLines(win, gc, points, 2);
323 return 1;
324}
325
326int XTextExtents( XFontStruct* font, char* s, int len, int* direction,
327 int* ascent, int* descent2, XCharStruct* overall)
328{
329 GR_SIZE retwidth, retheight, retbase;
330 GR_GC_ID gc = GrNewGC();
331
332 *ascent = font->info.baseline;
333 *direction = 1; /* ? */
334 *descent2 = 0; /* ? */
335
336 GrSetGCFont(gc, font->fid);
337
338 /* TODO need to set the relevant flags for the character set.
339 * A good trick might be to pass a wxString instead of char*
340 * to this function.
341 */
342
343 GrGetGCTextSize(gc, s, len, GR_TFASCII, & retwidth,
344 & retheight, & retbase);
345 if (overall)
346 {
347 overall->width = retwidth;
348 overall->lbearing = 0;
349 overall->rbearing = 0;
350 overall->ascent = *ascent;
351 overall->descent = 0;
352 overall->attributes = 0;
353 }
354
355 GrDestroyGC(gc);
356
357 return 1;
358}
359
360XFontStruct* XLoadQueryFont(Display* display, const char* fontSpec)
361{
362 /* TODO: map fontSpec to something sensible for Nano-X */
363 char *fontName = NULL;
364 XFontStruct* fontInfo = malloc(sizeof(XFontStruct));
365 fontInfo->fid = GrCreateFont(fontName, 0, 0);
366 GrGetFontInfo(fontInfo->fid, & fontInfo->info);
16d865f7 367 printf("Warning: should not call XLoadQueryFont since font spec is not used in Nano-X.\n");
788519c6
JS
368 return fontInfo;
369}
370
371int XFreeFont(Display* display, XFontStruct* fontStruct)
372{
373 GrDestroyFont(fontStruct->fid);
374 free(fontStruct);
375 return 1;
376}
377
378int XQueryColor(Display* display, Colormap cmap, XColor* color)
379{
380 /* cmap is a GR_PALETTE */
381 if (color->pixel < cmap->count)
382 {
383 color->red = cmap->palette[color->pixel].r;
384 color->green = cmap->palette[color->pixel].g;
385 color->blue = cmap->palette[color->pixel].b;
386 return 1;
387 }
388 else
389 return 0;
390}
391
461e93f9
JS
392int XConfigureWindow(Display* display, Window w, int mask, XWindowChanges* changes)
393{
394 if ((mask & CWX) && (mask & CWY))
395 GrMoveWindow(w, changes->x, changes->y);
396 if ((mask & CWWidth) && (mask & CWHeight))
397 GrResizeWindow(w, changes->width, changes->height);
398 if (mask & CWBorderWidth)
399 {
400 /* TODO */
401 }
402 if (mask & CWSibling)
403 {
404 /* TODO */
405 }
406 if (mask & CWStackMode)
407 {
408 /* TODO */
409 }
410 return 1;
411}
412
413int XTranslateCoordinates(Display* display, Window srcWindow, Window destWindow, int srcX, int srcY, int* destX, int* destY, Window* childReturn)
414{
415 int offx = 0;
416 int offy = 0;
417
418 Window w = srcWindow;
419 while (w != GR_ROOT_WINDOW_ID)
420 {
421 GR_WINDOW_INFO info;
422 GrGetWindowInfo(w, & info);
423 w = info.parent;
424
425 offx += info.x ;
426 offy += info.y ;
427 }
428
429 w = destWindow;
430
431 while (w != GR_ROOT_WINDOW_ID)
432 {
433 GR_WINDOW_INFO info;
434 GrGetWindowInfo(w, & info);
435 w = info.parent;
436
437 offx -= info.x ;
438 offy -= info.y ;
439 }
440
441 *destX = srcX + offx;
442 *destY = srcY + offy;
443
444 if (childReturn)
445 *childReturn = 0;
446
447 return 1;
448}
449
0b5c0e1a
JS
450/* Should not really be necessary but in no-optimize mode
451 * gcc complains that wxNoop is not found if wxNoop is inline.
452 */
453
454void wxNoop()
455{
456}
457
5ed738a7 458#endif
c79a329d 459 /* wxUSE_NANOX */