]>
git.saurik.com Git - wxWidgets.git/blob - src/x11/nanox.c
73aede11b5767b8080c93854c5b97571cbffb5e8
4 * Replacements for some comomon Xlib functions
14 #include "wx/x11/nanox/X11/Xlib.h"
16 /* Expands to some compatibility functions (see XtoNX.h) */
20 static GR_PALETTE
* s_globalColormap
= 0;
22 Colormap
DefaultColormapOfScreen(Screen
* screen
)
24 if (!s_globalColormap
)
26 s_globalColormap
= (GR_PALETTE
*) malloc(sizeof(GR_PALETTE
));
28 GrGetSystemPalette(s_globalColormap
);
31 return s_globalColormap
;
34 int XSetGraphicsExposures( Display
* display
, GC gc
, Bool graphics_exposures
)
39 int XWarpPointer( Display
* display
, Window srcW
, Window destW
,
41 unsigned int srcWidth
,
42 unsigned int srcHeight
,
45 GrMoveCursor(destX
, destY
);
49 int XSetInputFocus(Display
* display
, Window focus
, int revert_to
, Time time
)
55 int XGetInputFocus(Display
* display
, Window
* focus_return
, int* revert_to_return
)
57 * focus_return
= GrGetFocus();
58 * revert_to_return
= 0;
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
)
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.
74 int XUngrabPointer(Display display
, Time time
)
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
)
83 GrCopyArea(dest
, gc
, dest_x
, dest_y
,
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
)
93 GrCopyArea(dest
, gc
, dest_x
, dest_y
,
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*/
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 */
148 Status
XGetWindowAttributes(Display
* display
, Window w
,
149 XWindowAttributes
* window_attributes
)
152 GrGetWindowInfo(w
, & info
);
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
;
180 static XErrorHandler
* g_ErrorHandler
= NULL
;
182 static void DefaultNanoXErrorHandler(GR_EVENT_ERROR
* ep
)
186 XErrorEvent errEvent
;
187 errEvent
.type
= ep
->type
;
188 errEvent
.display
= NULL
;
189 errEvent
.resourceid
= ep
->id
;
191 errEvent
.error_code
= ep
->code
;
192 errEvent
.request_code
= 0;
193 errEvent
.minor_code
= 0;
194 (*g_ErrorHandler
)(NULL
, & errEvent
);
198 XErrorHandler
XSetErrorHandler (XErrorHandler handler
)
200 XErrorHandler oldHandler
= g_ErrorHandler
;
201 g_ErrorHandler
= handler
;
202 GrSetErrorHandler(DefaultNanoXErrorHandler
);
206 static Screen s_screen
;
207 Screen
*XScreenOfDisplay(Display
* display
,
210 /* TODO: fill in the members. See Xlib.h */
214 int DisplayWidth(Display
* display
, int screen
)
216 return _display
.display_width
;
219 int DisplayHeight(Display
* display
, int screen
)
221 return _display
.display_height
;
224 int DefaultDepth(Display
* display
, int screen
)
226 return _display
.display_bpp
;
229 int XAllocColor(Display
* display
, Colormap cmap
,
233 GrFindColor(GR_RGB(color
->red
, color
->green
, color
->blue
), & pixel
);
234 color
->pixel
= pixel
;
238 int XParseColor(Display
* display
, Colormap cmap
,
239 const char* cname
, XColor
* color
)
245 int XDrawLine(Display
* display
, Window win
, GC gc
,
246 int x1
, int y1
, int x2
, int y2
)
254 GrDrawLines(win
, gc
, points
, 2);
258 int XTextExtents( XFontStruct
* font
, char* s
, int len
, int* direction
,
259 int* ascent
, int* descent2
, XCharStruct
* overall
)
261 GR_SIZE retwidth
, retheight
, retbase
;
262 GR_GC_ID gc
= GrNewGC();
264 *ascent
= font
->info
.baseline
;
265 *direction
= 1; /* ? */
266 *descent2
= 0; /* ? */
268 GrSetGCFont(gc
, font
->fid
);
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*
275 GrGetGCTextSize(gc
, s
, len
, GR_TFASCII
, & retwidth
,
276 & retheight
, & retbase
);
279 overall
->width
= retwidth
;
280 overall
->lbearing
= 0;
281 overall
->rbearing
= 0;
282 overall
->ascent
= *ascent
;
283 overall
->descent
= 0;
284 overall
->attributes
= 0;
292 XFontStruct
* XLoadQueryFont(Display
* display
, const char* fontSpec
)
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
);
302 int XFreeFont(Display
* display
, XFontStruct
* fontStruct
)
304 GrDestroyFont(fontStruct
->fid
);
309 int XQueryColor(Display
* display
, Colormap cmap
, XColor
* color
)
311 /* cmap is a GR_PALETTE */
312 if (color
->pixel
< cmap
->count
)
314 color
->red
= cmap
->palette
[color
->pixel
].r
;
315 color
->green
= cmap
->palette
[color
->pixel
].g
;
316 color
->blue
= cmap
->palette
[color
->pixel
].b
;