📄 xlib.c
字号:
/*****************************************************************\ Library of X window functions which call Windows 32 equivalent functions. Some data structures are maintained by this code, simulating the operation of an X server and window manager. Aug/Sep-92 xyz $$1 Created. Oct-92 abc $$2 Added color stuff.\******************************************************************/#ifndef __XNT#define __XNT#include <X11/Xlib.h>#include <X11/Xatom.h>#include <stdio.h>#include <math.h>#include <string.h>#include <fcntl.h>#include "ntdef.h"/* Local Data */static void NT_set_GC_pen();static void NT_set_GC_brush();static HPEN NT_get_GC_pen();static HBRUSH NT_get_GC_brush();static HBRUSH NT_get_GC_bgbrush();void NT_set_rop();double NT_deg64_to_rad(int a);/*----------------------------------------------------------------*\| FUNCTIONS TO MAINTAIN AN INTERNAL LIST OF WINDOWS AND THEIR || ATTRIBUTES - AS WOULD BE MAINTAINED IN THE X SERVER. |\*----------------------------------------------------------------*//* Structure to hold pen and brush info in GC ext_data field */typedef struct NTGC_{ HPEN pen; HBRUSH brush; HBRUSH bgbrush;} NTGC;HDCcjh_get_dc(NT_window *window){ /* pixmaps have to do SelectObject() on their dc's */ if (window->hDC == INVALID_HANDLE) if (window->w == INVALID_HANDLE) { window->hDC= CreateDC("DISPLAY", NULL, NULL, NULL); } else window->hDC=GetDC(window->w); return window->hDC;}intcjh_rel_dc(NT_window *window,HDC dc){ return TRUE; /* return ReleaseDC(window, dc); */}HDCdrawableGetDC(Drawable drawable){ cjh_get_dc((NT_window *)drawable);}intdrawableRelDC(Drawable drawable, HDC hDC){ cjh_rel_dc((NT_window *)drawable, hDC);}/*****************************************************************\ Function: XOpenDisplay Inputs: Display name Comments: Fills out a Display structure and a Visual and Screen. Hopefully all the X macros should work with this structure. Note that the default visual is for a True colour screen (24bits).\*****************************************************************/Display *XOpenDisplay (name)const char *name;{ static char vstring[]="NT Xlibemu", *vs,*dn; Display *d = NULL; Screen *scrd; static Depth dlist[1]; static Visual vlist[1]; Colormap cmap; RECT rect; int depth; HDC rootDC = CreateDC("DISPLAY",NULL,NULL,NULL); depth = GetDeviceCaps(rootDC, BITSPIXEL); xtrace("XOpenDisplay\n"); initQ(); dlist[0].depth=depth; dlist[0].nvisuals=1; dlist[0].visuals=vlist; vlist[0].ext_data=NULL; vlist[0].visualid=0; vlist[0].class=PseudoColor; vlist[0].bits_per_rgb=8; vlist[0].map_entries=256; vlist[0].red_mask=255; vlist[0].green_mask=255<<8; vlist[0].blue_mask=255<<16; scrd=(Screen *) allocateMemory (sizeof (Screen)); (NT_window*)(scrd->root)= NT_new_window(); ((NT_window*)(scrd->root))->w=GetDesktopWindow(); ((NT_window*)(scrd->root))->parent=0; GetWindowRect(GetDesktopWindow(),&rect); scrd->width=rect.right-rect.left; scrd->height=rect.bottom-rect.top; scrd->mwidth=260; scrd->mheight=190; scrd->ndepths=1; scrd->depths=dlist; scrd->root_depth=depth; scrd->root_visual=vlist; scrd->default_gc=NULL; scrd->cmap=cmap; scrd->white_pixel=0xffffff; scrd->black_pixel=0; d=(Display *) allocateMemory (sizeof (Display)); scrd->display=d; vs=(char *) allocateMemory (sizeof (char)*strlen (vstring)+1); dn=(char *) allocateMemory (sizeof (char)*strlen (name)+1); strcpy (vs,vstring); strcpy (dn,name); d->ext_data=NULL; d->fd=0; d->proto_major_version=11; d->proto_minor_version=4; d->vendor=vs; d->release=4; d->display_name=dn; d->nscreens=1; d->screens=scrd; d->max_keycode=255; return (d);}intXCloseDisplay(Display *display){ NT_window *wanderer; xtrace("XCloseDisplay\n");/* Do something ? *//* Must GlobalDelete all atoms/properties leftover */ return 0;}char *XDisplayString(Display *display){ return (display->display_name);}intXFlush(Display *display){ xtrace("XFlush\n"); return 0;}intXSync(display,discard)Display *display;int discard;{ /* Do nothing here either */ return 0;}/*****************************************************************\ Function: XGetVisualInfo Inputs: display, info mask, template, number of matches. Returned: List of XVisualInfo structures, one for each matching Visual. Comments: Behaves like X routine, but there is only ever one Visual, so the returned list is never longer than one.\*****************************************************************/XVisualInfo *XGetVisualInfo(display,vinm,vint,n)Display *display;long vinm;XVisualInfo *vint;int *n;{ static XVisualInfo xvi; int status=1; xtrace("XGetVisualInfo\n"); if ((vinm&VisualIDMask|vinm==VisualAllMask)&& vint->visualid!=display->screens->root_visual->visualid) status=0; if ((vinm&VisualScreenMask|vinm==VisualAllMask)&& vint->screen!=0) status=0; if ((vinm&VisualDepthMask|vinm==VisualAllMask)&& vint->depth!=24) status=0; if ((vinm&VisualClassMask|vinm==VisualAllMask)&& vint->class!=display->screens->root_visual->class) status=0; if ((vinm&VisualRedMaskMask|vinm==VisualAllMask)&& vint->red_mask!=display->screens->root_visual->red_mask) status=0; if ((vinm&VisualGreenMaskMask|vinm==VisualAllMask)&& vint->green_mask!=display->screens->root_visual->green_mask) status=0; if ((vinm&VisualBlueMaskMask|vinm==VisualAllMask)&& vint->blue_mask!=display->screens->root_visual->blue_mask) status=0; if ((vinm&VisualColormapSizeMask|vinm==VisualAllMask)&& vint->colormap_size!=display->screens->root_visual->map_entries) status=0; if ((vinm&VisualBitsPerRGBMask|vinm==VisualAllMask)&& vint->bits_per_rgb!=display->screens->root_visual->bits_per_rgb) status=0; if (status==1) { xvi.visualid=display->screens->root_visual->visualid; xvi.screen=0; xvi.depth=display->screens->root_visual->bits_per_rgb; xvi.class=display->screens->root_visual->class; xvi.red_mask=display->screens->root_visual->red_mask; xvi.green_mask=display->screens->root_visual->green_mask; xvi.blue_mask=display->screens->root_visual->blue_mask; xvi.colormap_size=display->screens->root_visual->map_entries; xvi.bits_per_rgb=display->screens->root_visual->bits_per_rgb; xvi.visual=display->screens->root_visual; *n=1; return (&xvi); } *n=0; return (&xvi);}StatusDef XMatchVisualInfo( Display* display, int screen, int depth, int class, XVisualInfo* vinfo_return){ int status=0; xtrace("XMatchVisualInfo\n"); return status;}/*****************************************************************\ Function: XClearWindow Inputs: display, window Comments: As mentioned, the Window structure is not the one windows recognises. The background colour for the window is stored in this structure. The sequence of GetDC, CreateBrush/Pen, SelectObject, <draw stuff>, DeleteObject, ReleaseDC occurs in all the drawing functions.\*****************************************************************/intXClearWindow(display, w)Display *display;Window w;{ RECT rRect; HBRUSH hbrush; HDC hDC; HANDLE oldObj; int oldROP; NT_window *window = (NT_window *)w; xtrace("XClearWindow\n"); if (VALID_WINDOW(window)) { rRect.left= rRect.right=rRect.bottom=rRect.top =0; hDC = cjh_get_dc(window); oldROP = SetROP2(hDC,R2_COPYPEN); hbrush = window->bg; oldObj = SelectObject(hDC, hbrush); GetClientRect(window->w, &rRect); FillRect(hDC, &rRect, hbrush); SelectObject(hDC, oldObj); // DeleteObject(hbrush); SetROP2(hDC,oldROP); cjh_rel_dc(window,hDC); } return 0;}/*****************************************************************\ Function: XCreateSimpleWindow Inputs: display, parent window, geometry, border width, border colour, background colour. Returned: Window ID Comments: The first time a window is made by the application, it has to be registered. To simulate the action of a window manager, the toplevel client window is reparented and a frame window is created. A MapNotify event is sent to the new client. Note that child windows are created in the manner of the default X behaviour, ie. each is clipped individually. NOTE: This routine has now changed. As part of our role as Window manager, we now defer creation of the windows until they are mapped. The fact that a window has been created and not mapped is flagged to other routines by setting the w element of the structure to -1. WE STILL CREATE THE Window STRUCTURES. (SEE XMapWindow)\*****************************************************************/WindowXCreateSimpleWindow(display, parent,x, y, w, h, brd, brd_col, bg)Display *display;Window parent;int x, y;unsigned int brd,w,h;unsigned long bg, brd_col;{ NT_window *canvas; xtrace("XCreateSimpleWindow\n"); canvas = NT_new_window(); canvas->x = x; canvas->y = y; canvas->wdth = w; canvas->hght = h; NT_add_child((NT_window *)parent,canvas); canvas->bg=CreateSolidBrush (CNUMTORGB(bg)); canvas->parent=(NT_window *)parent; canvas->title_text = NULL; if (canvas->parent->w == GetDesktopWindow()) { if (x==0 && y==0) { canvas->x = -1; canvas->y = -1; } canvas->top_flag = TRUE; } else canvas->top_flag = 0; return ((Window)canvas);}/*****************************************************************\ Function: XCreateWindow Inputs: display, parent window, geometry, border width, depth, class, visual, attributes mask, attributes structure Returned: Window ID Comments: Simply calls XCreateSimpleWindow. Some of the arguments are ignored :-).\*****************************************************************/WindowXCreateWindow(display,parent,x,y,width,height,bw,depth,class,visual, valuemask,attr)Display *display;Window parent;int x,y;unsigned int width,height,bw;int depth;unsigned int class;Visual *visual;unsigned long valuemask;XSetWindowAttributes *attr;{ xtrace("XCreateWindow\n"); return (XCreateSimpleWindow(display,parent,x,y,width,height,bw, attr->border_pixel,attr->background_pixel));}/*****************************************************************\ Function: XDestroyWindow Inputs: Display, window to be destroyed. Comments: Removes a window from the server. \*****************************************************************/intXDestroyWindow(display,w)Display *display;Window w;{ NT_window *ntw = (NT_window *)w; xtrace("XDestroyWindow\n"); if (ntw->hDC != INVALID_HANDLE) { ReleaseDC(ntw->w,ntw->hDC); ntw->hDC = INVALID_HANDLE; } /*DestroyWindow(w->w);*/ NT_delete_window(ntw); /* Remove window from data structure */ return 0;}/*****************************************************************\ Function: XGetGeometry Inputs: display, window Returned: root window, screen depth, geometry, border width Comments: fetches information from the windows kernel and our display structure.\*****************************************************************/StatusDefXGetGeometry(display,w,root,x,y,width,height,bw,depth)Display *display;Drawable w;Window *root;int *x,*y;unsigned int *width,*height;unsigned int *bw,*depth;{ NT_window *ntw = (NT_window *)w; RECT r; xtrace("XGetGeometry\n"); *root=display->screens[0].root; *depth=24; GetWindowRect(ntw->w,&r); *x=r.left; *y=r.top; GetClientRect(ntw->w,&r); *width=r.right-r.left; if (*width<ntw->minx) *width=ntw->minx; *height=r.bottom-r.top; if (*height<ntw->miny) *height=ntw->miny; *bw=(*width-(r.right-r.left))/2; return 0;}/*****************************************************************\ Function: XGetWindowAttributes Inputs: display, window, attributes Returned: 1 = ok. Comments: Fills out attributes structure.\*****************************************************************/StatusDefXGetWindowAttributes(display,w,wattr)Display *display;Window w;XWindowAttributes *wattr;{ xtrace("XGetWindowAttributes\n"); XGetGeometry(display,w,&wattr->root,&wattr->x,&wattr->y,&wattr->width, &wattr->height,&wattr->border_width,&wattr->depth); wattr->class=InputOutput; wattr->bit_gravity=StaticGravity; wattr->win_gravity=CenterGravity; wattr->backing_store=NotUseful; wattr->backing_planes=0; wattr->backing_pixel=0; wattr->save_under=0; wattr->colormap=None; wattr->map_installed=TRUE; wattr->map_state=IsViewable; wattr->override_redirect=FALSE; wattr->screen=display->screens; return (1);}intXSelectInput(display, window, mask)Display *display;Window window;long mask;{ NT_window *ntw = (NT_window *)window; xtrace("XSelectInput\n"); ntw->mask=mask; return 0;}void NT_dispError(char *msg){ LPVOID lpMsgBuf=NULL; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL); MessageBox( NULL, lpMsgBuf, msg, MB_OK|MB_ICONINFORMATION ); LocalFree( lpMsgBuf );}/*****************************************************************\ Function: XMapWindow Inputs: display, window to be mapped Comments: If the specified window is not already mapped, this routine calls the Windows function which displays it. Again, frames have to be mapped as well as clients.\*****************************************************************/intXMapWindow(display, window)Display *display;Window window;{ NT_window *ntw = (NT_window *)window; RECT rect; unsigned char *hints; Atom property; Atom ret_type; int ret_format; DWORD frame_style; long ret_nitems; long ret_after; HDC hDC; char *title = ""; xtrace("XMapWindow\n"); if (ntw->w == INVALID_HANDLE) { frame_style = WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS; if (ntw->top_flag) { /* frame_style = WS_CLIPCHILDREN; frame_style |= WS_BORDER; frame_style |= WS_THICKFRAME; frame_style |= WS_CAPTION; frame_style |= WS_POPUP; frame_style |= WS_SYSMENU; frame_style |= WS_MINIMIZEBOX; frame_style |= WS_MAXIMIZEBOX; */ frame_style = WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN; ntw->hght += GetSystemMetrics(SM_CYSIZE)+(GetSystemMetrics(SM_CYBORDER)+GetSystemMetrics(SM_CYFRAME))*2; ntw->wdth += (GetSystemMetrics(SM_CXBORDER) + GetSystemMetrics(SM_CXFRAME))*2; title = ntw->title_text; if (ntw->x == -1 && ntw->y == -1) { ntw->x = CW_USEDEFAULT;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -