📄 srvfunc.c
字号:
GsWpRealizeWindow(wp, GR_FALSE); SERVER_UNLOCK();}/* * Reparent window to new parent, position at passed x, y */voidGrReparentWindow(GR_WINDOW_ID wid, GR_WINDOW_ID pwid, GR_COORD x, GR_COORD y){ GR_WINDOW *wp; /* window structure */ GR_WINDOW *pwp; /* parent window structure */ GR_WINDOW **mysibptr; /* handle to my sibling ptr */ GR_COORD offx, offy; SERVER_LOCK(); wp = GsFindWindow(wid); pwp = GsFindWindow(pwid); if (!wp || !pwp || wp == pwp) { SERVER_UNLOCK(); return; } if (wp == rootwp) { GsError(GR_ERROR_ILLEGAL_ON_ROOT_WINDOW, wid); SERVER_UNLOCK(); return; }/*printf("grreparent: pid %d wid %d (oldpid %d) realized %d,%d\n", pwid, wid, wp->parent->id, pwp->realized, wp->realized);*/ x += pwp->x; y += pwp->y; offx = x - wp->x; offy = y - wp->y; /* * Unrealize window and all children. No effect if * this window isn't already realized. */ GsWpUnrealizeWindow(wp, GR_TRUE); /* link window into new parent chain*/ for(mysibptr = &(wp->parent->children); *mysibptr != wp; mysibptr = &((*mysibptr)->siblings)) continue; *mysibptr = wp->siblings; wp->parent = pwp; wp->siblings = pwp->children; pwp->children = wp; if (offx || offy) OffsetWindow(wp, offx, offy); /* * Realize window again. Window will become visible if * the parent window is realized and this window is mapped. * * Temp flag is set TRUE, no additional * UPDATE_MAP will be sent. */ GsWpRealizeWindow(wp, GR_TRUE); /* send reparent update event*/ GsDeliverUpdateEvent(wp, GR_UPDATE_REPARENT, wp->x, wp->y, wp->width, wp->height); SERVER_UNLOCK();}static int nextgcid = 1000;/* * Allocate a new GC with default parameters. * The GC is owned by the current client. */GR_GC_ID GrNewGC(void){ GR_GC *gcp; SERVER_LOCK(); gcp = (GR_GC *) malloc(sizeof(GR_GC)); if (gcp == NULL) { GsError(GR_ERROR_MALLOC_FAILED, 0); SERVER_UNLOCK(); return 0; } gcp->id = nextgcid++; gcp->mode = GR_MODE_COPY; gcp->regionid = 0; /* no region*/ gcp->xoff = 0; /* no offset*/ gcp->yoff = 0; gcp->fontid = 0; /* 0 is default font*/ gcp->foreground = WHITE; gcp->background = BLACK; gcp->fgispixelval = GR_FALSE; gcp->bgispixelval = GR_FALSE; gcp->usebackground = GR_TRUE; gcp->exposure = GR_TRUE; gcp->linestyle = GR_LINE_SOLID; gcp->fillmode = GR_FILL_SOLID; gcp->dashcount = 0; gcp->dashmask = 0; gcp->stipple.bitmap = NULL; gcp->stipple.width = 0; gcp->stipple.height = 0; gcp->tile.psd = NULL; gcp->tile.width = 0; gcp->tile.height = 0; gcp->ts_offset.x = 0; gcp->ts_offset.y = 0; gcp->changed = GR_TRUE; gcp->owner = curclient; gcp->next = listgcp; listgcp = gcp; SERVER_UNLOCK(); return gcp->id;}/* * Destroy an existing graphics context. */voidGrDestroyGC(GR_GC_ID gc){ GR_GC *gcp; /* graphics context */ GR_GC *prevgcp; /* previous graphics context */ SERVER_LOCK(); gcp = GsFindGC(gc); if (gcp == NULL) { SERVER_UNLOCK(); return; } if (gc == cachegcid) { cachegcid = 0; cachegcp = NULL; } if (gcp == curgcp) curgcp = NULL; if (listgcp == gcp) listgcp = gcp->next; else { prevgcp = listgcp; while (prevgcp->next != gcp) prevgcp = prevgcp->next; prevgcp->next = gcp->next; } if (gcp->stipple.bitmap) free(gcp->stipple.bitmap); free(gcp); SERVER_UNLOCK();}/* * Allocate a new GC which is a copy of another one. * The GC is owned by the current client. */GR_GC_ID GrCopyGC(GR_GC_ID gc){ GR_GC *oldgcp; /* old graphics context */ GR_GC *gcp; /* new graphics context */ GR_GC_ID id; SERVER_LOCK(); oldgcp = GsFindGC(gc); if (oldgcp == NULL) { SERVER_UNLOCK(); return 0; } gcp = (GR_GC *) malloc(sizeof(GR_GC)); if (gcp == NULL) { GsError(GR_ERROR_MALLOC_FAILED, 0); SERVER_UNLOCK(); return 0; } /* * Copy all the old gcp values into the new one, except allocate * a new id for it and link it into the list of GCs. */ *gcp = *oldgcp; gcp->id = nextgcid++; id = gcp->id; gcp->changed = GR_TRUE; gcp->owner = curclient; gcp->next = listgcp; listgcp = gcp; SERVER_UNLOCK(); return id;}/* * Return information about the specified graphics context. */void GrGetGCInfo(GR_GC_ID gc, GR_GC_INFO *gcip){ GR_GC *gcp; SERVER_LOCK(); /* * Find the GC manually so that an error is not generated. */ for (gcp = listgcp; gcp && (gcp->id != gc); gcp = gcp->next) continue; if (gcp == NULL) { memset(gcip, 0, sizeof(GR_GC_INFO)); SERVER_UNLOCK(); return; } gcip->gcid = gc; gcip->mode = gcp->mode; gcip->region = gcp->regionid; gcip->xoff = gcp->xoff; gcip->yoff = gcp->yoff; gcip->font = gcp->fontid; gcip->foreground = gcp->foreground; gcip->background = gcp->background; gcip->fgispixelval = gcp->fgispixelval; gcip->bgispixelval = gcp->bgispixelval; gcip->usebackground = gcp->usebackground; gcip->exposure = gcp->exposure; SERVER_UNLOCK();}static int nextregionid = 1000;/* * Allocate a new REGION with default parameters. * The REGION is owned by the current client. */GR_REGION_IDGrNewRegion(void){ GR_REGION *regionp; GR_REGION_ID id; SERVER_LOCK(); regionp = (GR_REGION *) malloc(sizeof(GR_REGION)); if (regionp == NULL) { GsError(GR_ERROR_MALLOC_FAILED, 0); SERVER_UNLOCK(); return 0; } regionp->rgn = GdAllocRegion(); regionp->id = nextregionid++; regionp->owner = curclient; regionp->next = listregionp; listregionp = regionp; id = regionp->id; SERVER_UNLOCK(); return id;}/* * Allocate a new region from a set of points interpreted as a polygon. * The REGION is owned by the current client. */GR_REGION_IDGrNewPolygonRegion(int mode, GR_COUNT count, GR_POINT *points){#if POLYREGIONS GR_REGION *regionp; GR_REGION_ID id; SERVER_LOCK(); regionp = (GR_REGION *) malloc(sizeof(GR_REGION)); if (regionp == NULL) { GsError(GR_ERROR_MALLOC_FAILED, 0); SERVER_UNLOCK(); return 0; } regionp->rgn = GdAllocPolygonRegion(points, count, mode); regionp->id = nextregionid++; regionp->owner = curclient; regionp->next = listregionp; listregionp = regionp; id = regionp->id; SERVER_UNLOCK(); return id;#else return 0;#endif}/* * Destroy an existing region. */voidGrDestroyRegion(GR_REGION_ID region){ GR_REGION *regionp; /* region */ GR_REGION *prevregionp; /* previous region */ SERVER_LOCK(); regionp = GsFindRegion(region); if (regionp == NULL) { SERVER_UNLOCK(); return; } if (listregionp == regionp) { listregionp = regionp->next; } else { prevregionp = listregionp; while (prevregionp->next != regionp) prevregionp = prevregionp->next; prevregionp->next = regionp->next; } GdDestroyRegion(regionp->rgn); free(regionp); SERVER_UNLOCK();}/* * Updates the region from a union of the specified rectangle * and the original region. */voidGrUnionRectWithRegion(GR_REGION_ID region, GR_RECT *rect){ GR_REGION *regionp; MWRECT rc; SERVER_LOCK(); regionp = GsFindRegion(region); if (regionp) { /* convert Nano-X rect to MW rect*/ rc.left = rect->x; rc.top = rect->y; rc.right = rect->x + rect->width; rc.bottom = rect->y + rect->height; GdUnionRectWithRegion(&rc, regionp->rgn); } SERVER_UNLOCK();}/* * Updates the region from a union of two regions. */ voidGrUnionRegion(GR_REGION_ID dst_rgn, GR_REGION_ID src_rgn1, GR_REGION_ID src_rgn2){ GR_REGION *regionp; GR_REGION *srcregionp1; GR_REGION *srcregionp2; SERVER_LOCK(); regionp = GsFindRegion(dst_rgn); if (regionp == NULL) { SERVER_UNLOCK(); return; } srcregionp1 = GsFindRegion(src_rgn1); if (srcregionp1 == NULL) { SERVER_UNLOCK(); return; } srcregionp2 = GsFindRegion(src_rgn2); if (srcregionp2 == NULL) { SERVER_UNLOCK(); return; } GdUnionRegion(regionp->rgn, srcregionp1->rgn, srcregionp2->rgn); SERVER_UNLOCK();}/* * Updates the region by subtracting a region from another. */ voidGrSubtractRegion(GR_REGION_ID dst_rgn, GR_REGION_ID src_rgn1, GR_REGION_ID src_rgn2){ GR_REGION *regionp; GR_REGION *srcregionp1; GR_REGION *srcregionp2; SERVER_LOCK(); regionp = GsFindRegion(dst_rgn); if (regionp == NULL) { SERVER_UNLOCK(); return; } srcregionp1 = GsFindRegion(src_rgn1); if (srcregionp1 == NULL) { SERVER_UNLOCK(); return; } srcregionp2 = GsFindRegion(src_rgn2); if (srcregionp2 == NULL) { SERVER_UNLOCK(); return; } GdSubtractRegion(regionp->rgn, srcregionp1->rgn, srcregionp2->rgn); SERVER_UNLOCK();}/* * Updates the region to the difference of two regions. */ voidGrXorRegion(GR_REGION_ID dst_rgn, GR_REGION_ID src_rgn1, GR_REGION_ID src_rgn2){ GR_REGION *regionp; GR_REGION *srcregionp1; GR_REGION *srcregionp2; SERVER_LOCK(); regionp = GsFindRegion(dst_rgn); if (regionp == NULL) { SERVER_UNLOCK(); return; } srcregionp1 = GsFindRegion(src_rgn1); if (srcregionp1 == NULL) { SERVER_UNLOCK(); return; } srcregionp2 = GsFindRegion(src_rgn2); if (srcregionp2 == NULL) { SERVER_UNLOCK(); return; } GdXorRegion(regionp->rgn, srcregionp1->rgn, srcregionp2->rgn); SERVER_UNLOCK();}/* * Updates the region from a intersection of two regions. */ voidGrIntersectRegion(GR_REGION_ID dst_rgn, GR_REGION_ID src_rgn1, GR_REGION_ID src_rgn2){ GR_REGION *regionp; GR_REGION *srcregionp1; GR_REGION *srcregionp2; SERVER_LOCK(); regionp = GsFindRegion(dst_rgn); if (regionp == NULL) { SERVER_UNLOCK(); return; } srcregionp1 = GsFindRegion(src_rgn1); if (srcregionp1 == NULL) { SERVER_UNLOCK(); return; } srcregionp2 = GsFindRegion(src_rgn2); if (srcregionp2 == NULL) { SERVER_UNLOCK(); return; } GdIntersectRegion(regionp->rgn, srcregionp1->rgn, srcregionp2->rgn); SERVER_UNLOCK();}/* * Sets the clip-mask in the GC to the specified region. */voidGrSetGCRegion(GR_GC_ID gc, GR_REGION_ID region){ GR_GC *gcp; SERVER_LOCK(); gcp = GsFindGC(gc); if (gcp) { gcp->regionid = region; gcp->changed = GR_TRUE; } SERVER_UNLOCK();}/* * Set the x,y origin of user clip region in GC. */voidGrSetGCClipOrigin(GR_GC_ID gc, int xoff, int yoff){ GR_GC *gcp; SERVER_LOCK(); gcp = GsFindGC(gc); if (gcp) { gcp->xoff = xoff; gcp->yoff = yoff; gcp->changed = GR_TRUE; } SERVER_UNLOCK();}/* * Determines whether a specified point resides in a region. */ GR_BOOLGrPointInRegion(GR_REGION_ID region, GR_COORD x, GR_COORD y){ GR_REGION *regionp; GR_BOOL result; SERVER_LOCK(); regionp = GsFindRegion(region); if (regionp == NULL) { SERVER_UNLOCK(); return GR_FALSE; } result = GdPtInRegion(regionp->rgn, x, y); SERVER_UNLOCK(); return result;}/* * Determines whether a specified rectangle at least partly resides * in a region. */ intGrRectInRegion(GR_REGION_ID region, GR_COORD x, GR_COORD y, GR_COORD w, GR_COORD h){ GR_REGION *regionp; MWRECT rect; int result; SERVER_LOCK(); regionp = GsFindRegion(region); if (regionp == NULL) { SERVER_UNLOCK(); return MWRECT_OUT; } rect.left = x; rect.top = y; rect.right = x + w; rect.bottom = y + h; result = GdRectInRegion(regionp->rgn, &rect); SERVER_UNLOCK(); return result;}/* * Return GR_TRUE if a region is empty. */ GR_BOOLGrEmptyRegion(GR_REGION_ID region){ GR_REGION *regionp; GR_BOOL result; SERVER_LOCK(); regionp = GsFindRegion(region); if (regionp == NULL) { SERVER_UNLOCK(); return GR_TRUE; } result = GdEmptyRegion(regionp->rgn); SERVER_UNLOCK(); return result;}/* * Return GR_TRUE if two regions are identical. */ GR_BOOLGrEqualRegion(GR_REGION_ID rgn1, GR_REGION_ID rgn2){ GR_REGION *prgn1; GR_REGION *prgn2; GR_BOOL result;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -