X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/788519c6055dc2290c40fb1569d2889d8ef8e76b..2e14066008229145e2da7b9f05a478ce38631f83:/src/x11/nanox.c?ds=sidebyside diff --git a/src/x11/nanox.c b/src/x11/nanox.c index 73aede11b5..a9619fb547 100644 --- a/src/x11/nanox.c +++ b/src/x11/nanox.c @@ -2,6 +2,7 @@ * nanox.c * * Replacements for some comomon Xlib functions + * Licence: The wxWindows licence */ #include "wx/setup.h" @@ -10,6 +11,8 @@ #include #include +#include +#include #include "wx/defs.h" #include "wx/x11/nanox/X11/Xlib.h" @@ -71,7 +74,7 @@ int XGrabPointer(Display* display, Window grab_window, return Success; } -int XUngrabPointer(Display display, Time time) +int XUngrabPointer(Display* display, Time time) { return Success; } @@ -149,6 +152,8 @@ Status XGetWindowAttributes(Display* display, Window w, XWindowAttributes* window_attributes) { GR_WINDOW_INFO info; + Window parent = 0; + GrFlush(); GrGetWindowInfo(w, & info); window_attributes->x = info.x; @@ -174,12 +179,25 @@ Status XGetWindowAttributes(Display* display, Window w, window_attributes->override_redirect = FALSE; window_attributes->screen = NULL; + /* We need to check if any parents are unmapped, + * or we will report a window as mapped when it is not. + */ + parent = info.parent; + while (parent) + { + GrGetWindowInfo(parent, & info); + if (info.mapped == 0) + window_attributes->map_state = IsUnmapped; + + parent = info.parent; + } + return 1; } static XErrorHandler* g_ErrorHandler = NULL; -static void DefaultNanoXErrorHandler(GR_EVENT_ERROR* ep) +void DefaultNanoXErrorHandler(GR_EVENT_ERROR* ep) { if (g_ErrorHandler) { @@ -235,10 +253,60 @@ int XAllocColor(Display* display, Colormap cmap, return 1; } +typedef struct { + const char* name; + unsigned int red; + unsigned int green; + unsigned int blue; +} _wxColourEntry; + +static _wxColourEntry _wxColourDatabase[] = +{ + { "WHITE", 255, 255, 255 }, + { "BLACK", 0, 0, 0 }, + { "RED", 255, 0, 0 }, + { "GREEN", 0, 255, 0 }, + { "BLUE", 0, 255, 255 }, + { "GREY", 128, 128, 128 }, + { "GRAY", 128, 128, 128 }, + { "LIGHT GREY", 192, 192, 192 }, + { "LIGHT GRAY", 192, 192, 192 }, + { "DARK GREY", 32, 32, 32 }, + { "DARK GRAY", 32, 32, 32 }, + { "CYAN", 0, 255, 255 }, + { "MAGENTA", 255, 255, 0 }, + + /* TODO: the rest */ + { NULL, 0, 0, 0 } +}; + int XParseColor(Display* display, Colormap cmap, const char* cname, XColor* color) { - /* TODO */ + int i = 0; + for (;;) + { + if (!_wxColourDatabase[i].name) + break; + else + { + if (strcmp(cname, _wxColourDatabase[i].name) == 0) + { + color->red = _wxColourDatabase[i].red; + color->green = _wxColourDatabase[i].green; + color->blue = _wxColourDatabase[i].blue; + + return 1; + } + i ++; + } + } + + /* Not found: use black */ + color->red = 0; + color->green = 0; + color->blue = 0; + return 0; } @@ -296,6 +364,7 @@ XFontStruct* XLoadQueryFont(Display* display, const char* fontSpec) XFontStruct* fontInfo = malloc(sizeof(XFontStruct)); fontInfo->fid = GrCreateFont(fontName, 0, 0); GrGetFontInfo(fontInfo->fid, & fontInfo->info); + printf("Warning: should not call XLoadQueryFont since font spec is not used in Nano-X.\n"); return fontInfo; } @@ -320,5 +389,71 @@ int XQueryColor(Display* display, Colormap cmap, XColor* color) return 0; } +int XConfigureWindow(Display* display, Window w, int mask, XWindowChanges* changes) +{ + if ((mask & CWX) && (mask & CWY)) + GrMoveWindow(w, changes->x, changes->y); + if ((mask & CWWidth) && (mask & CWHeight)) + GrResizeWindow(w, changes->width, changes->height); + if (mask & CWBorderWidth) + { + /* TODO */ + } + if (mask & CWSibling) + { + /* TODO */ + } + if (mask & CWStackMode) + { + /* TODO */ + } + return 1; +} + +int XTranslateCoordinates(Display* display, Window srcWindow, Window destWindow, int srcX, int srcY, int* destX, int* destY, Window* childReturn) +{ + int offx = 0; + int offy = 0; + + Window w = srcWindow; + while (w != GR_ROOT_WINDOW_ID) + { + GR_WINDOW_INFO info; + GrGetWindowInfo(w, & info); + w = info.parent; + + offx += info.x ; + offy += info.y ; + } + + w = destWindow; + + while (w != GR_ROOT_WINDOW_ID) + { + GR_WINDOW_INFO info; + GrGetWindowInfo(w, & info); + w = info.parent; + + offx -= info.x ; + offy -= info.y ; + } + + *destX = srcX + offx; + *destY = srcY + offy; + + if (childReturn) + *childReturn = 0; + + return 1; +} + +/* Should not really be necessary but in no-optimize mode + * gcc complains that wxNoop is not found if wxNoop is inline. + */ + +void wxNoop() +{ +} + #endif /* wxUSE_NANOX */