📄 tkvisual.c
字号:
case StaticColor: prio = 3; break; case StaticGray: prio = 1; break; case TrueColor: prio = 5; break; default: prio = 0; break; } if (visInfoList[i].visual == DefaultVisualOfScreen(Tk_Screen(tkwin))) { prio++; } if (bestPtr == NULL) { goto newBest; } if (visInfoList[i].depth < bestPtr->depth) { if (visInfoList[i].depth >= template.depth) { goto newBest; } } else if (visInfoList[i].depth > bestPtr->depth) { if (bestPtr->depth < template.depth) { goto newBest; } } else { if (prio > bestPrio) { goto newBest; } } continue; newBest: bestPtr = &visInfoList[i]; bestPrio = prio; } *depthPtr = bestPtr->depth; visual = bestPtr->visual; XFree((char *) visInfoList); /* * If we need to find a colormap for this visual, do it now. * If the visual is the default visual for the screen, then * use the default colormap. Otherwise search for an existing * colormap that's shareable. If all else fails, create a new * colormap. */ if (colormapPtr != NULL) { if (visual == DefaultVisualOfScreen(Tk_Screen(tkwin))) { *colormapPtr = DefaultColormapOfScreen(Tk_Screen(tkwin)); } else { for (cmapPtr = dispPtr->cmapPtr; cmapPtr != NULL; cmapPtr = cmapPtr->nextPtr) { if (cmapPtr->shareable && (cmapPtr->visual == visual)) { *colormapPtr = cmapPtr->colormap; cmapPtr->refCount += 1; goto done; } } cmapPtr = (TkColormap *) ckalloc(sizeof(TkColormap)); cmapPtr->colormap = XCreateColormap(Tk_Display(tkwin), RootWindowOfScreen(Tk_Screen(tkwin)), visual, AllocNone); cmapPtr->visual = visual; cmapPtr->refCount = 1; cmapPtr->shareable = 1; cmapPtr->nextPtr = dispPtr->cmapPtr; dispPtr->cmapPtr = cmapPtr; *colormapPtr = cmapPtr->colormap; } } done: return visual;}/* *---------------------------------------------------------------------- * * Tk_GetColormap -- * * Given a string identifying a colormap, this procedure finds * an appropriate colormap. * * Results: * The return value is normally the X resource identifier for the * colormap. If an error occurs, None is returned and an error * message is placed in interp->result. * * Side effects: * A reference count is incremented for the colormap, so * Tk_FreeColormap must eventually be called exactly once for * each call to Tk_GetColormap. * *---------------------------------------------------------------------- */ColormapTk_GetColormap(interp, tkwin, string) Tcl_Interp *interp; /* Interpreter to use for error * reporting. */ Tk_Window tkwin; /* Window where colormap will be * used. */ char *string; /* String that identifies colormap: * either "new" or the name of * another window. */{ Colormap colormap; TkColormap *cmapPtr; TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr; Tk_Window other; /* * Allocate a new colormap, if that's what is wanted. */ if (strcmp(string, "new") == 0) { cmapPtr = (TkColormap *) ckalloc(sizeof(TkColormap)); cmapPtr->colormap = XCreateColormap(Tk_Display(tkwin), RootWindowOfScreen(Tk_Screen(tkwin)), Tk_Visual(tkwin), AllocNone); cmapPtr->visual = Tk_Visual(tkwin); cmapPtr->refCount = 1; cmapPtr->shareable = 0; cmapPtr->nextPtr = dispPtr->cmapPtr; dispPtr->cmapPtr = cmapPtr; return cmapPtr->colormap; } /* * Use a colormap from an existing window. It must have the same * visual as tkwin (which means, among other things, that the * other window must be on the same screen). */ other = Tk_NameToWindow(interp, string, tkwin); if (other == NULL) { return None; } if (Tk_Screen(other) != Tk_Screen(tkwin)) { Tcl_AppendResult(interp, "can't use colormap for ", string, ": not on same screen", (char *) NULL); return None; } if (Tk_Visual(other) != Tk_Visual(tkwin)) { Tcl_AppendResult(interp, "can't use colormap for ", string, ": incompatible visuals", (char *) NULL); return None; } colormap = Tk_Colormap(other); /* * If the colormap was a special one allocated by code in this file, * increment its reference count. */ for (cmapPtr = dispPtr->cmapPtr; cmapPtr != NULL; cmapPtr = cmapPtr->nextPtr) { if (cmapPtr->colormap == colormap) { cmapPtr->refCount += 1; } } return colormap;}/* *---------------------------------------------------------------------- * * Tk_FreeColormap -- * * This procedure is called to release a colormap that was * previously allocated by Tk_GetColormap. * * Results: * None. * * Side effects: * The colormap's reference count is decremented. If this was the * last reference to the colormap, then the colormap is freed. * *---------------------------------------------------------------------- */voidTk_FreeColormap(display, colormap) Display *display; /* Display for which colormap was * allocated. */ Colormap colormap; /* Colormap that is no longer needed. * Must have been returned by previous * call to Tk_GetColormap, or * preserved by a previous call to * Tk_PreserveColormap. */{ TkDisplay *dispPtr; TkColormap *cmapPtr, *prevPtr; /* * Find Tk's information about the display, then see if this * colormap is a non-default one (if it's a default one, there * won't be an entry for it in the display's list). */ dispPtr = TkGetDisplay(display); if (dispPtr == NULL) { panic("unknown display passed to Tk_FreeColormap"); } for (prevPtr = NULL, cmapPtr = dispPtr->cmapPtr; cmapPtr != NULL; prevPtr = cmapPtr, cmapPtr = cmapPtr->nextPtr) { if (cmapPtr->colormap == colormap) { cmapPtr->refCount -= 1; if (cmapPtr->refCount == 0) { XFreeColormap(display, colormap); if (prevPtr == NULL) { dispPtr->cmapPtr = cmapPtr->nextPtr; } else { prevPtr->nextPtr = cmapPtr->nextPtr; } ckfree((char *) cmapPtr); } return; } } }/* *---------------------------------------------------------------------- * * Tk_PreserveColormap -- * * This procedure is called to indicate to Tk that the specified * colormap is being referenced from another location and should * not be freed until all extra references are eliminated. The * colormap must have been returned by Tk_GetColormap. * * Results: * None. * * Side effects: * The colormap's reference count is incremented, so * Tk_FreeColormap must eventually be called exactly once for * each call to Tk_PreserveColormap. * *---------------------------------------------------------------------- */voidTk_PreserveColormap(display, colormap) Display *display; /* Display for which colormap was * allocated. */ Colormap colormap; /* Colormap that should be * preserved. */{ TkDisplay *dispPtr; TkColormap *cmapPtr; /* * Find Tk's information about the display, then see if this * colormap is a non-default one (if it's a default one, there * won't be an entry for it in the display's list). */ dispPtr = TkGetDisplay(display); if (dispPtr == NULL) { panic("unknown display passed to Tk_PreserveColormap"); } for (cmapPtr = dispPtr->cmapPtr; cmapPtr != NULL; cmapPtr = cmapPtr->nextPtr) { if (cmapPtr->colormap == colormap) { cmapPtr->refCount += 1; return; } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -