#ifndef _DUMMY_XLIBH_
#define _DUMMY_XLIBH_
+/* Move away the typedef in XtoNX.h */
+#define XFontStruct XFontStruct1
#include <XtoNX.h>
+#undef XFontStruct
+#undef XCharStruct
/* Data types */
typedef int Bool;
typedef long XID;
typedef XID KeySym;
+typedef struct {
+ GR_FONT_INFO info;
+ GR_FONT_ID fid;
+} XFontStruct;
+typedef struct {
+ short lbearing; /* origin to left edge of raster */
+ short rbearing; /* origin to right edge of raster */
+ short width; /* advance to next char's origin */
+ short ascent; /* baseline to top edge of raster */
+ short descent; /* baseline to bottom edge of raster */
+ unsigned short attributes; /* per char flags (not predefined) */
+} XCharStruct;
+
+
/* typedef unsigned long Time; */
#define Success 0
#define PropertyChangeMask GR_EVENT_MASK_SELECTION_CHANGED
#define GraphicsExpose GR_EVENT_TYPE_EXPOSURE
#define GraphicsExposeMask GR_EVENT_MASK_EXPOSURE
+#define ColormapChangeMask 0
+#define FillSolid 0
+#define LineSolid 0
+#define LineOnOffDash 0
+#define CapNotLast 0
+#define CapRound 0
+#define CapProjecting 0
+#define CapButt 0
+#define JoinRound 0
+#define JoinBevel 0
+#define JoinMiter 0
+#define IncludeInferiors 0
+#define ClipByChildren 0
+#define DoRed 0
+#define DoGreen 0
+#define DoBlue 0
+
+#define GXcopy GR_MODE_COPY
+#define GXclear GR_MODE_CLEAR
+#ifndef GXxor
+#define GXxor GR_MODE_OR
+#endif
+#define GXinvert GR_MODE_INVERT
+#define GXorReverse GR_MODE_ORREVERSE
+#define GXandReverse GR_MODE_ANDREVERSE
+#define GXand GR_MODE_AND
+#define GXor GR_MODE_OR
+#define GXandInverted GR_MODE_ANDINVERTED
+#define GXnoop GR_MODE_NOOP
+#define GXnor GR_MODE_NOR
+#define GXequiv GR_MODE_EQUIV
+#define GXcopyInverted GR_MODE_COPYINVERTED
+#define GXorInverted GR_MODE_ORINVERTED
+#define GXnand GR_MODE_NAND
+#define GXset GR_MODE_SET
+
+inline void wxNoop() { /* Do nothing */ }
#define XSynchronize(display,sync)
#define XDefaultRootWindow(d) GR_ROOT_WINDOW_ID
#define XFreePixmap(d, p) GrDestroyWindow(p)
#define XFreeCursor(d, c) GrDestroyCursor(c)
+#define XFreeGC(d, gc) GrDestroyGC(gc)
+#define XSetBackground(d, gc, c) GrSetGCBackground(gc, c)
#define DefaultVisual(d, s) ((Visual*) NULL)
+#define DefaultColormap(d, s) DefaultColormapOfScreen((Screen*) NULL)
+#define XSetFillStyle(d, gc, s) wxNoop()
+#define XSetLineAttributes(d, gc, a, b, c, e) wxNoop()
+#define XSetClipMask(d, gc, m) wxNoop()
+#define XSetTSOrigin(d, gc, x, y) wxNoop()
+#define XFillArc(d, w, gc, x, y, rx, ry, a1, a2) GrArcAngle(w, gc, x, y, rx, ry, a1, a2, GR_PIE)
+#define XDrawArc(d, w, gc, x, y, rx, ry, a1, a2) GrArcAngle(w, gc, x, y, rx, ry, a1, a2, GR_ARC)
+#define XDrawPoint(d, w, gc, x, y) GrPoint(w, gc, x, y)
+#define XFillPolygon(d, w, gc, p, n, s, m) GrFillPoly(w, gc, n, p)
+#define XDrawRectangle(d, w, gc, x, y, width, height) GrRect(w, gc, x, y, width, height)
+#define XSetClipOrigin(d, gc, x, y) GrSetGCClipOrigin(gc, x, y)
+#define XSetRegion(d, gc, r) GrSetGCRegion(gc, r)
+#define XSetTile(d, gc, p) wxNoop()
+#define XSetStipple(d, gc, p) wxNoop()
+#define XSetSubwindowMode(d, gc, mode) wxNoop()
+#define XFreeColormap(d, cmap) wxNoop()
+#define XSetTransientForHint(d, w, p) wxNoop()
+#define XUnionRegion(sr1,sr2,r) GrUnionRegion(r,sr1,sr2)
+#define XIntersectRegion(sr1,sr2,r) GrIntersectRegion(r,sr1,sr2)
+#define XEqualRegion(r1, r2) GrEqualRegion(r1, r2)
+#define XEmptyRegion(r) GrEmptyRegion(r)
+#define XOffsetRegion(r, x, y) GrOffsetRegion(r, x, y)
+#define XClipBox(r, rect) GrGetRegionBox(r, rect)
+#define XPointInRegion(r, x, y) GrPointInRegion(r, x, y)
+#define XXorRegion(sr1, sr2, r) GrXorRegion(r, sr1, sr2)
+
/* These defines are wrongly defined in XtoNX.h, IMHO,
* since they reference a static global.
#define PointerMotionMask GR_EVENT_MASK_MOUSE_POSITION
#endif
+#define ButtonMotionMask GR_EVENT_MASK_MOUSE_POSITION
+#define KeymapStateMask 0
+#define StructureNotifyMask GR_EVENT_MASK_UPDATE
+
#ifndef FocusIn
#define FocusIn GR_EVENT_TYPE_FOCUS_IN
#define FocusOut GR_EVENT_TYPE_FOCUS_OUT
Colormap DefaultColormapOfScreen(Screen* /* screen */) ;
int XSetGraphicsExposures( Display* /* display */, GC /* gc */, Bool /* graphics_exposures */) ;
-int XWarpPointer( Display* /* display */, Window /* srcW */, Window /* srcW */,
+int XWarpPointer( Display* /* display */, Window /* srcW */, Window /* destW */,
int /* srcX */, int /* srcY */,
unsigned int /* srcWidth */,
unsigned int /* srcHeight */,
int dest_x, int dest_y, unsigned long /* plane */) ;
XErrorHandler XSetErrorHandler (XErrorHandler /* handler */);
-Display *XOpenDisplay(const char *name);
+Display *XOpenDisplay(char *name);
Screen *XScreenOfDisplay(Display* /* display */,
int /* screen_number */);
int DisplayWidth(Display* /* display */, int /* screen */);
XColor* color);
int XParseColor(Display* display, Colormap cmap,
const char* cname, XColor* color);
+int XDrawLine(Display* display, Window win, GC gc,
+ int x1, int y1, int x2, int y2);
+int XTextExtents( XFontStruct* font, char* s, int len, int* direction,
+ int* ascent, int* descent2, XCharStruct* overall);
+int XPending(Display *d);
+XFontStruct* XLoadQueryFont(Display* display, const char* fontSpec);
+int XFreeFont(Display* display, XFontStruct* fontStruct);
+int XQueryColor(Display* display, Colormap cmap, XColor* color);
#ifdef __cpluplus
}
#define XExposeEventGetY(event) event->exposure.y
#define XExposeEventGetWidth(event) event->exposure.width
#define XExposeEventGetHeight(event) event->exposure.height
+#define XFontStructGetAscent(f) f->info.baseline
#else
#define XEventGetWindow(event) event->xany.window
#define XConfigureEventGetWidth(event) event->xconfigure.width
#define XExposeEventGetY(event) event->xexpose.y
#define XExposeEventGetWidth(event) event->xexpose.width
#define XExposeEventGetHeight(event) event->xexpose.height
+#define XFontStructGetAscent(f) f->ascent
#endif
#endif
win->GetClearRegion().Union( XExposeEventGetX(event), XExposeEventGetY(event),
XExposeEventGetWidth(event), XExposeEventGetHeight(event));
+#if !wxUSE_NANOX
if (event->xexpose.count == 0)
+#endif
{
// Only erase background, paint in idle time.
win->SendEraseEvents();
#endif
XSetFont( (Display*) m_display, (GC) m_textGC, xfont->fid );
+#if !wxUSE_NANOX
if ((xfont->min_byte1 == 0) && (xfont->max_byte1 == 0))
- {
+#endif
+ {
XDrawString( (Display*) m_display, (Window) m_window,
- (GC) m_textGC, x, y + xfont->ascent, text.c_str(), text.Len() );
- }
+ (GC) m_textGC, x, y + XFontStructGetAscent(xfont), text.c_str(), text.Len() );
+ }
#if 0
if (m_font.GetUnderlined())
{
- wxCoord ul_y = y + font->ascent;
+ wxCoord ul_y = y + XFontStructGetAscent(font);
if (font->descent > 0) ul_y++;
gdk_draw_line( m_window, m_textGC, x, ul_y, x + width, ul_y);
}
int direction, ascent, descent2;
XCharStruct overall;
- XTextExtents( xfont, string.c_str(), string.Len(), &direction,
+ XTextExtents( xfont, (char*) string.c_str(), string.Len(), &direction,
&ascent, &descent2, &overall);
if (width)
/////////////////////////////////////////////////////////////////////////////
-// Name: src/motif/font.cpp
+// Name: src/x11/font.cpp
// Purpose: wxFont class
// Author: Julian Smart
// Modified by:
#if wxUSE_NANOX
+#include <ctype.h>
+#include <malloc.h>
+#include "wx/defs.h"
#include "wx/x11/nanox/X11/Xlib.h"
/* Expands to some compatibility functions (see XtoNX.h) */
STATIC_FUNCTIONS
-Colormap DefaultColormapOfScreen(Screen* /* screen */)
-{
- static GR_PALETTE* s_globalColormap = 0;
- static bool s_init = FALSE;
+static GR_PALETTE* s_globalColormap = 0;
- if (!s_init)
+Colormap DefaultColormapOfScreen(Screen* screen)
+{
+ if (!s_globalColormap)
{
s_globalColormap = (GR_PALETTE*) malloc(sizeof(GR_PALETTE));
GrGetSystemPalette(s_globalColormap);
- s_init = TRUE;
}
return s_globalColormap;
}
-int XSetGraphicsExposures( Display* /* display */, GC /* gc */, Bool /* graphics_exposures */)
+int XSetGraphicsExposures( Display* display, GC gc, Bool graphics_exposures)
{
return Success ;
}
-int XWarpPointer( Display* /* display */, Window /* srcW */, Window /* srcW */,
- int /* srcX */, int /* srcY */,
- unsigned int /* srcWidth */,
- unsigned int /* srcHeight */,
+int XWarpPointer( Display* display, Window srcW, Window destW,
+ int srcX, int srcY,
+ unsigned int srcWidth,
+ unsigned int srcHeight,
int destX, int destY)
{
GrMoveCursor(destX, destY);
return Success;
}
-int XSetInputFocus(Display* /* display */, Window focus, int /* revert_to */, Time /* time */)
+int XSetInputFocus(Display* display, Window focus, int revert_to, Time time)
{
GrSetFocus(focus);
return Success;
}
-int XGetInputFocus(Display* /* display */, Window* /* focus_return */, int* /* revert_to_return */)
+int XGetInputFocus(Display* display, Window* focus_return, int* revert_to_return)
{
* focus_return = GrGetFocus();
* revert_to_return = 0;
return Success;
}
-int XGrabPointer(Display* /* display */, Window /* grab_window */,
- Bool /* owner_events */, unsigned int /* event_mask */,
- int /* pointer_mode */, int /* keyboard_mode */,
- Window /* confine_to */, Cursor /* cursor */, Time /* time */)
+int XGrabPointer(Display* display, Window grab_window,
+ Bool owner_events, unsigned int event_mask,
+ int pointer_mode, int keyboard_mode,
+ Window confine_to, Cursor cursor, Time time)
{
/* According to comments in srvevent.c in Nano-X, the pointer
* is implicitly grabbed when a mouse button is down.
return Success;
}
-int XUngrabPointer(Display /* display */, Time /* time */)
+int XUngrabPointer(Display display, Time time)
{
return Success;
}
-int XCopyArea(Display* /* display */, Drawable src, Drawable dest, GC gc,
+int XCopyArea(Display* display, Drawable src, Drawable dest, GC gc,
int src_x, int src_y, unsigned int width, unsigned int height,
int dest_x, int dest_y)
{
return Success;
}
-int XCopyPlane(Display* /* display */, Drawable src, Drawable dest, GC gc,
+int XCopyPlane(Display* display, Drawable src, Drawable dest, GC gc,
int src_x, int src_y, unsigned int width, unsigned int height,
- int dest_x, int dest_y, unsigned long /* plane */)
+ int dest_x, int dest_y, unsigned long plane)
{
GrCopyArea(dest, gc, dest_x, dest_y,
width, height, src,
Status XGetWindowAttributes(Display* display, Window w,
- XWindowAttributes* window_attributes_return)
+ XWindowAttributes* window_attributes)
{
GR_WINDOW_INFO info;
GrGetWindowInfo(w, & info);
window_attributes->depth = 0;
window_attributes->visual = NULL;
window_attributes->root = 0;
- window_attributes->class = info.inputonly ? InputOnly : InputOutput ;
+ window_attributes->_class = info.inputonly ? InputOnly : InputOutput ;
window_attributes->bit_gravity = 0;
window_attributes->win_gravity = 0;
window_attributes->backing_store = 0;
{
XErrorEvent errEvent;
errEvent.type = ep->type;
- errEvent.display = wxGlobalDisplay();
+ errEvent.display = NULL;
errEvent.resourceid = ep->id;
errEvent.serial = 0;
errEvent.error_code = ep->code;
errEvent.request_code = 0;
errEvent.minor_code = 0;
- (*g_ErrorHandler)(wxGlobalDisplay(), & errEvent);
+ (*g_ErrorHandler)(NULL, & errEvent);
}
}
XErrorHandler XSetErrorHandler (XErrorHandler handler)
{
XErrorHandler oldHandler = g_ErrorHandler;
- g_errorHandler = handler;
+ g_ErrorHandler = handler;
+ GrSetErrorHandler(DefaultNanoXErrorHandler);
return oldHandler;
}
-Screen *XScreenOfDisplay(Display* /* display */,
- int /* screen_number */)
+static Screen s_screen;
+Screen *XScreenOfDisplay(Display* display,
+ int screen_number)
{
- static Screen s_screen;
/* TODO: fill in the members. See Xlib.h */
return & s_screen;
}
-int DisplayWidth(Display* /* display */, int /* screen */)
+int DisplayWidth(Display* display, int screen)
{
return _display.display_width;
}
-int DisplayHeight(Display* /* display */, int /* screen */)
+int DisplayHeight(Display* display, int screen)
{
return _display.display_height;
}
-int DefaultDepth(Display* /* display */, int /* screen */)
+int DefaultDepth(Display* display, int screen)
{
return _display.display_bpp;
}
-int XAllocColor(Display* /* display */, Colormap /* cmap */,
+int XAllocColor(Display* display, Colormap cmap,
XColor* color)
{
GR_PIXELVAL pixel;
- GrFindColor(color, & pixel);
- return pixel;
+ GrFindColor(GR_RGB(color->red, color->green, color->blue), & pixel);
+ color->pixel = pixel;
+ return 1;
}
-int XParseColor(Display* /* display */, Colormap /* cmap */,
+int XParseColor(Display* display, Colormap cmap,
const char* cname, XColor* color)
{
/* TODO */
return 0;
}
+int XDrawLine(Display* display, Window win, GC gc,
+ int x1, int y1, int x2, int y2)
+{
+ GR_POINT points[2];
+ points[0].x = x1;
+ points[0].y = y1;
+ points[1].x = x2;
+ points[1].y = y2;
+
+ GrDrawLines(win, gc, points, 2);
+ return 1;
+}
+
+int XTextExtents( XFontStruct* font, char* s, int len, int* direction,
+ int* ascent, int* descent2, XCharStruct* overall)
+{
+ GR_SIZE retwidth, retheight, retbase;
+ GR_GC_ID gc = GrNewGC();
+
+ *ascent = font->info.baseline;
+ *direction = 1; /* ? */
+ *descent2 = 0; /* ? */
+
+ GrSetGCFont(gc, font->fid);
+
+ /* TODO need to set the relevant flags for the character set.
+ * A good trick might be to pass a wxString instead of char*
+ * to this function.
+ */
+
+ GrGetGCTextSize(gc, s, len, GR_TFASCII, & retwidth,
+ & retheight, & retbase);
+ if (overall)
+ {
+ overall->width = retwidth;
+ overall->lbearing = 0;
+ overall->rbearing = 0;
+ overall->ascent = *ascent;
+ overall->descent = 0;
+ overall->attributes = 0;
+ }
+
+ GrDestroyGC(gc);
+
+ return 1;
+}
+
+XFontStruct* XLoadQueryFont(Display* display, const char* fontSpec)
+{
+ /* TODO: map fontSpec to something sensible for Nano-X */
+ char *fontName = NULL;
+ XFontStruct* fontInfo = malloc(sizeof(XFontStruct));
+ fontInfo->fid = GrCreateFont(fontName, 0, 0);
+ GrGetFontInfo(fontInfo->fid, & fontInfo->info);
+ return fontInfo;
+}
+
+int XFreeFont(Display* display, XFontStruct* fontStruct)
+{
+ GrDestroyFont(fontStruct->fid);
+ free(fontStruct);
+ return 1;
+}
+
+int XQueryColor(Display* display, Colormap cmap, XColor* color)
+{
+ /* cmap is a GR_PALETTE */
+ if (color->pixel < cmap->count)
+ {
+ color->red = cmap->palette[color->pixel].r;
+ color->green = cmap->palette[color->pixel].g;
+ color->blue = cmap->palette[color->pixel].b;
+ return 1;
+ }
+ else
+ return 0;
+}
+
#endif
/* wxUSE_NANOX */
if (pix_array_n > 0)
{
+#if !wxUSE_NANOX
// XFreeColors(display, cmap, pix_array, pix_array_n, 0);
// Be careful not to free '0' pixels...
int i, j;
if(j > i) XFreeColors(display, cmap, &pix_array[i], j-i, 0);
while(j<pix_array_n && pix_array[j]==0) j++;
}
+#endif
delete [] pix_array;
}
-
+
if (destroyable)
XFreeColormap(display, cmap);
Visual *xvisual = DefaultVisual( xdisplay, xscreen );
Window xparent = RootWindow( xdisplay, xscreen );
+#if wxUSE_NANOX
+ long xattributes_mask = 0;
+#else
XSetWindowAttributes xattributes;
long xattributes_mask =
xattributes.border_pixel = BlackPixel( xdisplay, xscreen );
xattributes.override_redirect = True;
xattributes.save_under = True;
-
+#endif
+
Window xwindow = XCreateWindow( xdisplay, xparent, pos.x, pos.y, size.x, size.y,
0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
XSetTransientForHint( xdisplay, xwindow, xparent );
+#if !wxUSE_NANOX
XWMHints wm_hints;
wm_hints.flags = InputHint | StateHint /* | WindowGroupHint */;
wm_hints.input = True;
wm_hints.initial_state = NormalState;
XSetWMHints( xdisplay, xwindow, &wm_hints);
-
+#endif
+
return TRUE;
}