📄 srvfunc.c
字号:
GR_DRAWABLE *dp; GR_POINT *pp; GR_COUNT i; PSD psd; switch (GsPrepareDrawing(id, gc, &dp)) { case GR_DRAW_TYPE_WINDOW: case GR_DRAW_TYPE_PIXMAP: psd = dp->psd; break; default: return; } /* * Here for drawing to a window. * Relocate all the points relative to the window. */ pp = pointtable; for (i = count; i-- > 0; pp++) { pp->x += dp->x; pp->y += dp->y; } GdPoly(psd, count, pointtable);#ifdef NONETWORK /* * The following is only necessary when the server * isn't a separate process. We don't want to change the * user's arguments! */ pp = pointtable; for (i = count; i-- > 0; pp++) { pp->x -= dp->x; pp->y -= dp->y; }#endif}/* * Draw a filled polygon in the specified drawable using the specified * graphics context. The last point may be a duplicate of the first * point, but this is not required. */voidGrFillPoly(GR_DRAW_ID id, GR_GC_ID gc, GR_COUNT count, GR_POINT *pointtable){ GR_DRAWABLE *dp; GR_POINT *pp; GR_COUNT i; PSD psd; switch (GsPrepareDrawing(id, gc, &dp)) { case GR_DRAW_TYPE_WINDOW: case GR_DRAW_TYPE_PIXMAP: psd = dp->psd; break; default: return; } /* * Here for drawing to a window. * Relocate all the points relative to the window. */ pp = pointtable; for (i = count; i-- > 0; pp++) { pp->x += dp->x; pp->y += dp->y; } GdFillPoly(psd, count, pointtable);#ifdef NONETWORK /* * The following is only necessary when the server * isn't a separate process. We don't want to change the * user's arguments! */ pp = pointtable; for (i = count; i-- > 0; pp++) { pp->x -= dp->x; pp->y -= dp->y; }#endif }/* * Draw a text string in the specified drawable using the * specified graphics context. */voidGrText(GR_DRAW_ID id, GR_GC_ID gc, GR_COORD x, GR_COORD y, void *str, GR_COUNT count, int flags){ GR_DRAWABLE *dp; /* default to baseline alignment if none specified*/ if((flags&(MWTF_TOP|MWTF_BASELINE|MWTF_BOTTOM)) == 0) flags |= MWTF_BASELINE; switch (GsPrepareDrawing(id, gc, &dp)) { case GR_DRAW_TYPE_WINDOW: case GR_DRAW_TYPE_PIXMAP: GdText(dp->psd, dp->x + x, dp->y + y, str, count,flags); break; }}/* Return the system palette entries*/voidGrGetSystemPalette(GR_PALETTE *pal){ /* return 0 count if not in palettized mode*/ memset(pal, 0, sizeof(GR_PALETTE *)); if(rootwp->psd->pixtype == MWPF_PALETTE) { pal->count = (int)rootwp->psd->ncolors; GdGetPalette(rootwp->psd, 0, pal->count, pal->palette); }}/* Set the system palette entries from first for count*/voidGrSetSystemPalette(GR_COUNT first, GR_PALETTE *pal){ GdSetPalette(rootwp->psd, first, pal->count, pal->palette); if (first == 0) GsRedrawScreen();}/* Convert passed color value to pixel value, depending on system mode*/voidGrFindColor(GR_COLOR c, GR_PIXELVAL *retpixel){ *retpixel = GdFindColor(c);}/* visible =0, no cursor change; =1, show; else hide*/voidGrInjectPointerEvent(GR_COORD x, GR_COORD y, int button, int visible){ if (visible != 0) { if (visible == 1) GdShowCursor(&scrdev); else GdHideCursor(&scrdev); } GdMoveMouse(x, y); GsHandleMouseStatus(x, y, button);}voidGrInjectKeyboardEvent(GR_WINDOW_ID wid, GR_KEY keyvalue, GR_KEYMOD modifiers, GR_SCANCODE scancode, GR_BOOL pressed){ /* create a keyboard event */ GsDeliverKeyboardEvent(wid, pressed? GR_EVENT_TYPE_KEY_DOWN: GR_EVENT_TYPE_KEY_UP, keyvalue, modifiers, scancode);}/* * Set certain window properties, according to flags value * passed in props. */voidGrSetWMProperties(GR_WINDOW_ID wid, GR_WM_PROPERTIES *props){ GR_WINDOW *wp; int tl = 0; /* Initialized to avoid warning */ /* Find the window structure (generate an error if it doesn't exist) */ wp = GsFindWindow(wid); if(!wp) { GsError(GR_ERROR_BAD_WINDOW_ID, wid); return; } /* Set window properties*/ if (props->flags & GR_WM_FLAGS_PROPS) wp->props = props->props; /* Set window title*/ if (props->flags & GR_WM_FLAGS_TITLE) { /* Remove the old title if it exists */ if(wp->title) free(wp->title); /* Calculate the space needed to store the new title */ if(props->title) tl = strlen(props->title) + 1; /* Check for empty title*/ if(!props->title || tl == 1) { wp->title = NULL; } else { /* Otherwise, allocate some space for the new title */ if(!(wp->title = malloc(tl))) GsError(GR_ERROR_MALLOC_FAILED, wid); else memcpy(wp->title, props->title, tl); } } /* Set window background*/ if (props->flags & GR_WM_FLAGS_BACKGROUND) { if (wp->background != props->background) { wp->background = props->background; GsExposeArea(wp, wp->x, wp->y, wp->width, wp->height, NULL); } } /* Set window border size*/ if (props->flags & GR_WM_FLAGS_BORDERSIZE) { if (wp->bordersize != props->bordersize) { GsWpUnmapWindow(wp, GR_TRUE); wp->bordersize = props->bordersize; GsWpMapWindow(wp, GR_TRUE); } } /* Set window border color*/ if (props->flags & GR_WM_FLAGS_BORDERCOLOR) { if (wp->bordercolor != props->bordercolor) { wp->bordercolor = props->bordercolor; if (wp->bordersize) GsDrawBorder(wp); } }}/* * Return all window properties */voidGrGetWMProperties(GR_WINDOW_ID wid, GR_WM_PROPERTIES *props){ GR_WINDOW *wp; /* Find the window structure, no error on invalid window id*/ wp = GsFindWindow(wid); if(!wp) { /* set flags to 0 on bad window id*/ memset(props, 0, sizeof(GR_WM_PROPERTIES)); return; } /* Return everything, regardless of props->flags*/ props->flags = GR_WM_FLAGS_PROPS | GR_WM_FLAGS_TITLE | GR_WM_FLAGS_BACKGROUND | GR_WM_FLAGS_BORDERSIZE | GR_WM_FLAGS_BORDERCOLOR; props->props = wp->props; props->title = wp->title; props->background = wp->background; props->bordersize = wp->bordersize; props->bordercolor = wp->bordercolor;}voidGrCloseWindow(GR_WINDOW_ID wid){ GR_WINDOW *wp; /* Find the window structure (generate an error if it doesn't exist) */ wp = GsFindWindow(wid); if(!wp) { /* * no error for now, client/server problems * with nxwm when sent */ /*GsError(GR_ERROR_BAD_WINDOW_ID, wid);*/ return; } /* Send a CLOSE_REQ event to the client */ GsDeliverGeneralEvent(wp, GR_EVENT_TYPE_CLOSE_REQ, NULL);}voidGrKillWindow(GR_WINDOW_ID wid){ GR_WINDOW *wp; /* Find the window structure (generate an error if it doesn't exist) */ wp = GsFindWindow(wid); if(!wp) { GsError(GR_ERROR_BAD_WINDOW_ID, wid); return; } /* Forcibly kill the connection to the client */ GsClose(wp->owner->id);}/* * GrGetSystemColor color scheme definitions */ /* define color scheme: A (tan), B (winstd) or C (old)*/#define A#define A_RGB(r,g,b)#define B_RGB(r,g,b)#define C_RGB(r,g,b)#ifdef A#undef A_RGB#define A_RGB(r,g,b) GR_RGB(r,g,b),#endif#ifdef B#undef B_RGB#define B_RGB(r,g,b) GR_RGB(r,g,b),#endif#ifdef C#undef C_RGB#define C_RGB(r,g,b) GR_RGB(r,g,b),#endif#define MAXSYSCOLORS 20 /* # of GR_COLOR_* system colors*/static GR_COLOR sysColors[MAXSYSCOLORS] = { /* desktop background*/ GR_RGB( 0, 128, 128), /* GR_COLOR_DESKTOP */ /* caption colors*/ A_RGB(128, 0, 0) /* GR_COLOR_ACTIVECAPTION */ B_RGB(128, 0, 128) /* GR_COLOR_ACTIVECAPTION */ C_RGB(128, 0, 128) /* GR_COLOR_ACTIVECAPTION */ GR_RGB(255, 255, 255), /* GR_COLOR_ACTIVECAPTIONTEXT */ A_RGB(162, 141, 104) /* GR_COLOR_INACTIVECAPTION */ B_RGB(128, 128, 128) /* GR_COLOR_INACTIVECAPTION */ C_RGB( 0, 64, 128) /* GR_COLOR_INACTIVECAPTION */ GR_RGB(192, 192, 192), /* GR_COLOR_INACTIVECAPTIONTEXT */ /* 3d border shades*/ GR_RGB( 0, 0, 0), /* GR_COLOR_WINDOWFRAME */ A_RGB(162, 141, 104) /* GR_COLOR_BTNSHADOW */ B_RGB(128, 128, 128) /* GR_COLOR_BTNSHADOW */ C_RGB(128, 128, 128) /* GR_COLOR_BTNSHADOW */ A_RGB(213, 204, 187) /* GR_COLOR_3DLIGHT */ B_RGB(223, 223, 223) /* GR_COLOR_3DLIGHT */ C_RGB(192, 192, 192) /* GR_COLOR_3DLIGHT */ A_RGB(234, 230, 221) /* GR_COLOR_BTNHIGHLIGHT */ B_RGB(255, 255, 255) /* GR_COLOR_BTNHIGHLIGHT */ C_RGB(223, 223, 223) /* GR_COLOR_BTNHIGHLIGHT */ /* top level application window backgrounds/text*/ A_RGB(213, 204, 187) /* GR_COLOR_APPWINDOW */ B_RGB(192, 192, 192) /* GR_COLOR_APPWINDOW */ C_RGB(160, 160, 160) /* GR_COLOR_APPWINDOW */ GR_RGB( 0, 0, 0), /* GR_COLOR_APPTEXT */ /* button control backgrounds/text (usually same as app window colors)*/ A_RGB(213, 204, 187) /* GR_COLOR_BTNFACE */ B_RGB(192, 192, 192) /* GR_COLOR_BTNFACE */ C_RGB(160, 160, 160) /* GR_COLOR_BTNFACE */ GR_RGB( 0, 0, 0), /* GR_COLOR_BTNTEXT */ /* edit/listbox control backgrounds/text, selected highlights*/ GR_RGB(255, 255, 255), /* GR_COLOR_WINDOW */ GR_RGB( 0, 0, 0), /* GR_COLOR_WINDOWTEXT */ GR_RGB(128, 0, 0), /* GR_COLOR_HIGHLIGHT */ GR_RGB(255, 255, 255), /* GR_COLOR_HIGHLIGHTTEXT */ GR_RGB( 64, 64, 64), /* GR_COLOR_GRAYTEXT */ /* menu backgrounds/text*/ A_RGB(213, 204, 187) /* GR_COLOR_MENU */ B_RGB(192, 192, 192) /* GR_COLOR_MENU */ C_RGB(160, 160, 160) /* GR_COLOR_MENU */ GR_RGB( 0, 0, 0), /* GR_COLOR_MENUTEXT */};/* Return system-defined color*/GR_COLORGrGetSysColor(int index){ if(index >= 0 && index < MAXSYSCOLORS) return sysColors[index]; return 0;}voidGrSetScreenSaverTimeout(GR_TIMEOUT timeout){ MWTIMER *timer; screensaver_delay = timeout * 1000; if((timer = GdFindTimer(GsActivateScreenSaver))) GdDestroyTimer(timer); /* 0 timeout cancels timer*/ if (timeout == 0) return; GdAddTimer(screensaver_delay, GsActivateScreenSaver, GsActivateScreenSaver);}voidGrSetSelectionOwner(GR_WINDOW_ID wid, GR_CHAR *typelist){ GR_WINDOW_ID oldwid = selection_owner.wid; if(selection_owner.typelist) free(selection_owner.typelist); selection_owner.wid = wid; if(wid) { if(!(selection_owner.typelist = strdup(typelist))) { GsError(GR_ERROR_MALLOC_FAILED, wid); selection_owner.wid = 0; } } else selection_owner.typelist = NULL; GsDeliverSelectionChangedEvent(oldwid, wid);}GR_WINDOW_IDGrGetSelectionOwner(GR_CHAR **typelist){ *typelist = selection_owner.typelist; return selection_owner.wid;}voidGrRequestClientData(GR_WINDOW_ID wid, GR_WINDOW_ID rid, GR_SERIALNO serial, GR_MIMETYPE mimetype){ GsDeliverClientDataReqEvent(rid, wid, serial, mimetype);}voidGrSendClientData(GR_WINDOW_ID wid, GR_WINDOW_ID did, GR_SERIALNO serial, GR_LENGTH len, GR_LENGTH thislen, void *data){ void *p; if(!(p = malloc(len))) { GsError(GR_ERROR_MALLOC_FAILED, wid); return; /* FIXME note no error to application*/ } memcpy(p, data, thislen); GsDeliverClientDataEvent(did, wid, serial, len, thislen, p);}/* * Set a window's background pixmap. Note that this doesn't * cause a screen refresh, use GrClearWindow if required. */voidGrSetBackgroundPixmap(GR_WINDOW_ID wid, GR_WINDOW_ID pixmap, int flags){ GR_WINDOW *wp; GR_PIXMAP *pp = NULL; if (!(wp = GsFindWindow(wid))) { GsError(GR_ERROR_BAD_WINDOW_ID, wid); return; } if (pixmap && !(pp = GsFindPixmap(pixmap))) { GsError(GR_ERROR_BAD_WINDOW_ID, pixmap); return; } wp->bgpixmap = pp; wp->bgpixmapflags = flags;}voidGrGetFontList(GR_FONTLIST ***fonts, int *numfonts){ GdGetFontList(fonts,numfonts);}void GrFreeFontList(GR_FONTLIST ***fonts, int num){ GdFreeFontList(fonts, num);}/* * Return window parent and list of children. * Caller must free() children list after use. */voidGrQueryTree(GR_WINDOW_ID wid, GR_WINDOW_ID *parentid, GR_WINDOW_ID **children, GR_COUNT *nchildren){ GR_WINDOW *wp; GR_WINDOW *cp; GR_WINDOW_ID *retarray; GR_COUNT n = 0; wp = GsFindWindow(wid); if (!wp) { *parentid = 0;nochildren: *children = NULL; *nchildren = 0; return; } *parentid = wp->parent? wp->parent->id: 0; /* count children for alloc*/ for(cp=wp->children; cp; cp=cp->siblings) ++n; if (n == 0) goto nochildren; /* alloc return child array*/ retarray = (GR_WINDOW_ID *)malloc(n * sizeof(GR_WINDOW_ID)); if (!retarray) { GsError(GR_ERROR_MALLOC_FAILED, 0); goto nochildren; } /* fill in return array*/ n = 0; for(cp=wp->children; cp; cp=cp->siblings) { retarray[n++] = cp->id; } *children = retarray; *nchildren = n;}static int next_timer_id = 1000;/** * GrCreateTimer: * @wid: the ID of the window to use as a destination for GR_TIMER_EVENT * events that result from this timer. * @period: the timer period in milliseconds * @Returns: the ID of the newly created timer, or 0 if failure. * * Creates a Nano-X timer with the specified period. * NOTE: There is a potential for more GR_TIMER_EVENTS to be queued * in the connection between the Nano-X server and client. The client * should be able to handle late arriving GR_TIMER_EVENTs. */GR_TIMER_IDGrCreateTimer (GR_WINDOW_ID wid, GR_TIMEOUT period){ GR_TIMER *timer; /* Create a nano-X layer timr */ timer = (GR_TIMER*) malloc (sizeof (GR_TIMER)); if (timer == NULL) { GsError (GR_ERROR_MALLOC_FAILED, 0); return 0; } /* Create a device independent layer timer */ timer->timer = GdAddPeriodicTimer (period, GsTimerCB, timer); if (timer->timer == NULL) { free (timer); GsError (GR_ERROR_MALLOC_FAILED, 0); return 0; } /* * Fill in the rest of the timer structure, and * link the new timer into the servers list of timers. */ timer->id = next_timer_id++; timer->owner = curclient; timer->wid = wid; timer->next = list_ti
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -