]> git.saurik.com Git - wxWidgets.git/blob - src/x11/nanox.c
73aede11b5767b8080c93854c5b97571cbffb5e8
[wxWidgets.git] / src / x11 / nanox.c
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 #include <ctype.h>
12 #include <malloc.h>
13 #include "wx/defs.h"
14 #include "wx/x11/nanox/X11/Xlib.h"
15
16 /* Expands to some compatibility functions (see XtoNX.h) */
17
18 STATIC_FUNCTIONS
19
20 static GR_PALETTE* s_globalColormap = 0;
21
22 Colormap DefaultColormapOfScreen(Screen* screen)
23 {
24 if (!s_globalColormap)
25 {
26 s_globalColormap = (GR_PALETTE*) malloc(sizeof(GR_PALETTE));
27
28 GrGetSystemPalette(s_globalColormap);
29 }
30
31 return s_globalColormap;
32 }
33
34 int XSetGraphicsExposures( Display* display, GC gc, Bool graphics_exposures)
35 {
36 return Success ;
37 }
38
39 int XWarpPointer( Display* display, Window srcW, Window destW,
40 int srcX, int srcY,
41 unsigned int srcWidth,
42 unsigned int srcHeight,
43 int destX, int destY)
44 {
45 GrMoveCursor(destX, destY);
46 return Success;
47 }
48
49 int XSetInputFocus(Display* display, Window focus, int revert_to, Time time)
50 {
51 GrSetFocus(focus);
52 return Success;
53 }
54
55 int XGetInputFocus(Display* display, Window* focus_return, int* revert_to_return)
56 {
57 * focus_return = GrGetFocus();
58 * revert_to_return = 0;
59 return Success;
60 }
61
62 int XGrabPointer(Display* display, Window grab_window,
63 Bool owner_events, unsigned int event_mask,
64 int pointer_mode, int keyboard_mode,
65 Window confine_to, Cursor cursor, Time time)
66 {
67 /* According to comments in srvevent.c in Nano-X, the pointer
68 * is implicitly grabbed when a mouse button is down.
69 * We may be able to simulate this further in the event loop.
70 */
71 return Success;
72 }
73
74 int XUngrabPointer(Display display, Time time)
75 {
76 return Success;
77 }
78
79 int XCopyArea(Display* display, Drawable src, Drawable dest, GC gc,
80 int src_x, int src_y, unsigned int width, unsigned int height,
81 int dest_x, int dest_y)
82 {
83 GrCopyArea(dest, gc, dest_x, dest_y,
84 width, height, src,
85 src_x, src_y, 0);
86 return Success;
87 }
88
89 int XCopyPlane(Display* display, Drawable src, Drawable dest, GC gc,
90 int src_x, int src_y, unsigned int width, unsigned int height,
91 int dest_x, int dest_y, unsigned long plane)
92 {
93 GrCopyArea(dest, gc, dest_x, dest_y,
94 width, height, src,
95 src_x, src_y, 0);
96 return Success;
97 }
98
99 #if 0
100 typedef struct {
101 GR_WINDOW_ID wid; /* window id (or 0 if no such window) */
102 GR_WINDOW_ID parent; /* parent window id */
103 GR_WINDOW_ID child; /* first child window id (or 0) */
104 GR_WINDOW_ID sibling; /* next sibling window id (or 0) */
105 GR_BOOL inputonly; /* TRUE if window is input only */
106 GR_BOOL mapped; /* TRUE if window is mapped */
107 GR_COUNT unmapcount; /* reasons why window is unmapped */
108 GR_COORD x; /* absolute x position of window */
109 GR_COORD y; /* absolute y position of window */
110 GR_SIZE width; /* width of window */
111 GR_SIZE height; /* height of window */
112 GR_SIZE bordersize; /* size of border */
113 GR_COLOR bordercolor; /* color of border */
114 GR_COLOR background; /* background color */
115 GR_EVENT_MASK eventmask; /* current event mask for this client */
116 GR_WM_PROPS props; /* window properties */
117 GR_CURSOR_ID cursor; /* cursor id*/
118 unsigned long processid; /* process id of owner*/
119 } GR_WINDOW_INFO;
120
121 typedef struct {
122 int x, y; /* location of window */
123 int width, height; /* width and height of window */
124 int border_width; /* border width of window */
125 int depth; /* depth of window */
126 Visual *visual; /* the associated visual structure */
127 Window root; /* root of screen containing window */
128 int class; /* InputOutput, InputOnly*/
129 int bit_gravity; /* one of the bit gravity values */
130 int win_gravity; /* one of the window gravity values */
131 int backing_store; /* NotUseful, WhenMapped, Always */
132 unsigned long backing_planes;/* planes to be preserved if possible */
133 unsigned long backing_pixel;/* value to be used when restoring planes */
134 Bool save_under; /* boolean, should bits under be saved? */
135 Colormap colormap; /* color map to be associated with window */
136 Bool map_installed; /* boolean, is color map currently installed*/
137 int map_state; /* IsUnmapped, IsUnviewable, IsViewable */
138 long all_event_masks; /* set of events all people have interest in*/
139 long your_event_mask; /* my event mask */
140 long do_not_propagate_mask;/* set of events that should not propagate */
141 Bool override_redirect; /* boolean value for override-redirect */
142 Screen *screen; /* back pointer to correct screen */
143 } XWindowAttributes;
144
145 #endif
146
147
148 Status XGetWindowAttributes(Display* display, Window w,
149 XWindowAttributes* window_attributes)
150 {
151 GR_WINDOW_INFO info;
152 GrGetWindowInfo(w, & info);
153
154 window_attributes->x = info.x;
155 window_attributes->y = info.y;
156 window_attributes->width = info.width;
157 window_attributes->height = info.height;
158 window_attributes->border_width = info.bordersize;
159 window_attributes->depth = 0;
160 window_attributes->visual = NULL;
161 window_attributes->root = 0;
162 window_attributes->_class = info.inputonly ? InputOnly : InputOutput ;
163 window_attributes->bit_gravity = 0;
164 window_attributes->win_gravity = 0;
165 window_attributes->backing_store = 0;
166 window_attributes->backing_planes = 0;
167 window_attributes->backing_pixel = 0;
168 window_attributes->save_under = FALSE;
169 window_attributes->colormap = DefaultColormapOfScreen(0);
170 window_attributes->map_installed = FALSE;
171 window_attributes->map_state = info.mapped ? IsViewable : IsUnmapped ;
172 window_attributes->all_event_masks = 0;
173 window_attributes->do_not_propagate_mask = 0;
174 window_attributes->override_redirect = FALSE;
175 window_attributes->screen = NULL;
176
177 return 1;
178 }
179
180 static XErrorHandler* g_ErrorHandler = NULL;
181
182 static void DefaultNanoXErrorHandler(GR_EVENT_ERROR* ep)
183 {
184 if (g_ErrorHandler)
185 {
186 XErrorEvent errEvent;
187 errEvent.type = ep->type;
188 errEvent.display = NULL;
189 errEvent.resourceid = ep->id;
190 errEvent.serial = 0;
191 errEvent.error_code = ep->code;
192 errEvent.request_code = 0;
193 errEvent.minor_code = 0;
194 (*g_ErrorHandler)(NULL, & errEvent);
195 }
196 }
197
198 XErrorHandler XSetErrorHandler (XErrorHandler handler)
199 {
200 XErrorHandler oldHandler = g_ErrorHandler;
201 g_ErrorHandler = handler;
202 GrSetErrorHandler(DefaultNanoXErrorHandler);
203 return oldHandler;
204 }
205
206 static Screen s_screen;
207 Screen *XScreenOfDisplay(Display* display,
208 int screen_number)
209 {
210 /* TODO: fill in the members. See Xlib.h */
211 return & s_screen;
212 }
213
214 int DisplayWidth(Display* display, int screen)
215 {
216 return _display.display_width;
217 }
218
219 int DisplayHeight(Display* display, int screen)
220 {
221 return _display.display_height;
222 }
223
224 int DefaultDepth(Display* display, int screen)
225 {
226 return _display.display_bpp;
227 }
228
229 int XAllocColor(Display* display, Colormap cmap,
230 XColor* color)
231 {
232 GR_PIXELVAL pixel;
233 GrFindColor(GR_RGB(color->red, color->green, color->blue), & pixel);
234 color->pixel = pixel;
235 return 1;
236 }
237
238 int XParseColor(Display* display, Colormap cmap,
239 const char* cname, XColor* color)
240 {
241 /* TODO */
242 return 0;
243 }
244
245 int XDrawLine(Display* display, Window win, GC gc,
246 int x1, int y1, int x2, int y2)
247 {
248 GR_POINT points[2];
249 points[0].x = x1;
250 points[0].y = y1;
251 points[1].x = x2;
252 points[1].y = y2;
253
254 GrDrawLines(win, gc, points, 2);
255 return 1;
256 }
257
258 int XTextExtents( XFontStruct* font, char* s, int len, int* direction,
259 int* ascent, int* descent2, XCharStruct* overall)
260 {
261 GR_SIZE retwidth, retheight, retbase;
262 GR_GC_ID gc = GrNewGC();
263
264 *ascent = font->info.baseline;
265 *direction = 1; /* ? */
266 *descent2 = 0; /* ? */
267
268 GrSetGCFont(gc, font->fid);
269
270 /* TODO need to set the relevant flags for the character set.
271 * A good trick might be to pass a wxString instead of char*
272 * to this function.
273 */
274
275 GrGetGCTextSize(gc, s, len, GR_TFASCII, & retwidth,
276 & retheight, & retbase);
277 if (overall)
278 {
279 overall->width = retwidth;
280 overall->lbearing = 0;
281 overall->rbearing = 0;
282 overall->ascent = *ascent;
283 overall->descent = 0;
284 overall->attributes = 0;
285 }
286
287 GrDestroyGC(gc);
288
289 return 1;
290 }
291
292 XFontStruct* XLoadQueryFont(Display* display, const char* fontSpec)
293 {
294 /* TODO: map fontSpec to something sensible for Nano-X */
295 char *fontName = NULL;
296 XFontStruct* fontInfo = malloc(sizeof(XFontStruct));
297 fontInfo->fid = GrCreateFont(fontName, 0, 0);
298 GrGetFontInfo(fontInfo->fid, & fontInfo->info);
299 return fontInfo;
300 }
301
302 int XFreeFont(Display* display, XFontStruct* fontStruct)
303 {
304 GrDestroyFont(fontStruct->fid);
305 free(fontStruct);
306 return 1;
307 }
308
309 int XQueryColor(Display* display, Colormap cmap, XColor* color)
310 {
311 /* cmap is a GR_PALETTE */
312 if (color->pixel < cmap->count)
313 {
314 color->red = cmap->palette[color->pixel].r;
315 color->green = cmap->palette[color->pixel].g;
316 color->blue = cmap->palette[color->pixel].b;
317 return 1;
318 }
319 else
320 return 0;
321 }
322
323 #endif
324 /* wxUSE_NANOX */