?? tktextwind.c
字號:
Tk_CreateEventHandler(ewPtr->body.ew.tkwin, StructureNotifyMask, EmbWinStructureProc, (ClientData) ewPtr); /* * Special trick! Must enter into the hash table *after* * calling Tk_ManageGeometry: if the window was already managed * elsewhere in this text, the Tk_ManageGeometry call will cause * the entry to be removed, which could potentially lose the new * entry. */ hPtr = Tcl_CreateHashEntry(&textPtr->windowTable, Tk_PathName(ewPtr->body.ew.tkwin), &new); Tcl_SetHashValue(hPtr, ewPtr); } } return TCL_OK;}/* *-------------------------------------------------------------- * * AlignParseProc -- * * This procedure is invoked by Tk_ConfigureWidget during * option processing to handle "-align" options for embedded * windows. * * Results: * A standard Tcl return value. * * Side effects: * The alignment for the embedded window may change. * *-------------------------------------------------------------- */ /* ARGSUSED */static intAlignParseProc(clientData, interp, tkwin, value, widgRec, offset) ClientData clientData; /* Not used.*/ Tcl_Interp *interp; /* Used for reporting errors. */ Tk_Window tkwin; /* Window for text widget. */ char *value; /* Value of option. */ char *widgRec; /* Pointer to TkTextEmbWindow * structure. */ int offset; /* Offset into item (ignored). */{ register TkTextEmbWindow *embPtr = (TkTextEmbWindow *) widgRec; if (strcmp(value, "baseline") == 0) { embPtr->align = ALIGN_BASELINE; } else if (strcmp(value, "bottom") == 0) { embPtr->align = ALIGN_BOTTOM; } else if (strcmp(value, "center") == 0) { embPtr->align = ALIGN_CENTER; } else if (strcmp(value, "top") == 0) { embPtr->align = ALIGN_TOP; } else { Tcl_AppendResult(interp, "bad alignment \"", value, "\": must be baseline, bottom, center, or top", (char *) NULL); return TCL_ERROR; } return TCL_OK;}/* *-------------------------------------------------------------- * * AlignPrintProc -- * * This procedure is invoked by the Tk configuration code * to produce a printable string for the "-align" configuration * option for embedded windows. * * Results: * The return value is a string describing the embedded * window's current alignment. * * Side effects: * None. * *-------------------------------------------------------------- */ /* ARGSUSED */static char *AlignPrintProc(clientData, tkwin, widgRec, offset, freeProcPtr) ClientData clientData; /* Ignored. */ Tk_Window tkwin; /* Window for text widget. */ char *widgRec; /* Pointer to TkTextEmbWindow * structure. */ int offset; /* Ignored. */ Tcl_FreeProc **freeProcPtr; /* Pointer to variable to fill in with * information about how to reclaim * storage for return string. */{ switch (((TkTextEmbWindow *) widgRec)->align) { case ALIGN_BASELINE: return "baseline"; case ALIGN_BOTTOM: return "bottom"; case ALIGN_CENTER: return "center"; case ALIGN_TOP: return "top"; default: return "??"; }}/* *-------------------------------------------------------------- * * EmbWinStructureProc -- * * This procedure is invoked by the Tk event loop whenever * StructureNotify events occur for a window that's embedded * in a text widget. This procedure's only purpose is to * clean up when windows are deleted. * * Results: * None. * * Side effects: * The window is disassociated from the window segment, and * the portion of the text is redisplayed. * *-------------------------------------------------------------- */static voidEmbWinStructureProc(clientData, eventPtr) ClientData clientData; /* Pointer to record describing window item. */ XEvent *eventPtr; /* Describes what just happened. */{ register TkTextSegment *ewPtr = (TkTextSegment *) clientData; TkTextIndex index; if (eventPtr->type != DestroyNotify) { return; } Tcl_DeleteHashEntry(Tcl_FindHashEntry(&ewPtr->body.ew.textPtr->windowTable, Tk_PathName(ewPtr->body.ew.tkwin))); ewPtr->body.ew.tkwin = NULL; index.tree = ewPtr->body.ew.textPtr->tree; index.linePtr = ewPtr->body.ew.linePtr; index.charIndex = TkTextSegToOffset(ewPtr, ewPtr->body.ew.linePtr); TkTextChanged(ewPtr->body.ew.textPtr, &index, &index);}/* *-------------------------------------------------------------- * * EmbWinRequestProc -- * * This procedure is invoked whenever a window that's associated * with a window canvas item changes its requested dimensions. * * Results: * None. * * Side effects: * The size and location on the screen of the window may change, * depending on the options specified for the window item. * *-------------------------------------------------------------- */ /* ARGSUSED */static voidEmbWinRequestProc(clientData, tkwin) ClientData clientData; /* Pointer to record for window item. */ Tk_Window tkwin; /* Window that changed its desired * size. */{ TkTextSegment *ewPtr = (TkTextSegment *) clientData; TkTextIndex index; index.tree = ewPtr->body.ew.textPtr->tree; index.linePtr = ewPtr->body.ew.linePtr; index.charIndex = TkTextSegToOffset(ewPtr, ewPtr->body.ew.linePtr); TkTextChanged(ewPtr->body.ew.textPtr, &index, &index);}/* *-------------------------------------------------------------- * * EmbWinLostSlaveProc -- * * This procedure is invoked by the Tk geometry manager when * a slave window managed by a text widget is claimed away * by another geometry manager. * * Results: * None. * * Side effects: * The window is disassociated from the window segment, and * the portion of the text is redisplayed. * *-------------------------------------------------------------- */static voidEmbWinLostSlaveProc(clientData, tkwin) ClientData clientData; /* Pointer to record describing window item. */ Tk_Window tkwin; /* Window that was claimed away by another * geometry manager. */{ register TkTextSegment *ewPtr = (TkTextSegment *) clientData; TkTextIndex index; Tk_DeleteEventHandler(ewPtr->body.ew.tkwin, StructureNotifyMask, EmbWinStructureProc, (ClientData) ewPtr); Tcl_CancelIdleCall(EmbWinDelayedUnmap, (ClientData) ewPtr); if (ewPtr->body.ew.textPtr->tkwin != Tk_Parent(tkwin)) { Tk_UnmaintainGeometry(tkwin, ewPtr->body.ew.textPtr->tkwin); } else { Tk_UnmapWindow(tkwin); } Tcl_DeleteHashEntry(Tcl_FindHashEntry(&ewPtr->body.ew.textPtr->windowTable, Tk_PathName(ewPtr->body.ew.tkwin))); ewPtr->body.ew.tkwin = NULL; index.tree = ewPtr->body.ew.textPtr->tree; index.linePtr = ewPtr->body.ew.linePtr; index.charIndex = TkTextSegToOffset(ewPtr, ewPtr->body.ew.linePtr); TkTextChanged(ewPtr->body.ew.textPtr, &index, &index);}/* *-------------------------------------------------------------- * * EmbWinDeleteProc -- * * This procedure is invoked by the text B-tree code whenever * an embedded window lies in a range of characters being deleted. * * Results: * Returns 0 to indicate that the deletion has been accepted. * * Side effects: * The embedded window is deleted, if it exists, and any resources * associated with it are released. * *-------------------------------------------------------------- */ /* ARGSUSED */static intEmbWinDeleteProc(ewPtr, linePtr, treeGone) TkTextSegment *ewPtr; /* Segment being deleted. */ TkTextLine *linePtr; /* Line containing segment. */ int treeGone; /* Non-zero means the entire tree is * being deleted, so everything must * get cleaned up. */{ Tcl_HashEntry *hPtr; if (ewPtr->body.ew.tkwin != NULL) { hPtr = Tcl_FindHashEntry(&ewPtr->body.ew.textPtr->windowTable, Tk_PathName(ewPtr->body.ew.tkwin)); if (hPtr != NULL) { /* * (It's possible for there to be no hash table entry for this * window, if an error occurred while creating the window segment * but before the window got added to the table) */ Tcl_DeleteHashEntry(hPtr); } /* * Delete the event handler for the window before destroying * the window, so that EmbWinStructureProc doesn't get called * (we'll already do everything that it would have done, and * it will just get confused). */ Tk_DeleteEventHandler(ewPtr->body.ew.tkwin, StructureNotifyMask, EmbWinStructureProc, (ClientData) ewPtr); Tk_DestroyWindow(ewPtr->body.ew.tkwin); } Tcl_CancelIdleCall(EmbWinDelayedUnmap, (ClientData) ewPtr); Tk_FreeOptions(configSpecs, (char *) &ewPtr->body.ew, ewPtr->body.ew.textPtr->display, 0); ckfree((char *) ewPtr); return 0;}/* *-------------------------------------------------------------- * * EmbWinCleanupProc -- * * This procedure is invoked by the B-tree code whenever a * segment containing an embedded window is moved from one * line to another. * * Results: * None. * * Side effects: * The linePtr field of the segment gets updated. * *-------------------------------------------------------------- */static TkTextSegment *EmbWinCleanupProc(ewPtr, linePtr) TkTextSegment *ewPtr; /* Mark segment that's being moved. */ TkTextLine *linePtr; /* Line that now contains segment. */{ ewPtr->body.ew.linePtr = linePtr; return ewPtr;}/* *-------------------------------------------------------------- * * EmbWinLayoutProc -- * * This procedure is the "layoutProc" for embedded window * segments. * * Results: * 1 is returned to indicate that the segment should be * displayed. The chunkPtr structure is filled in. * * Side effects: * None, except for filling in chunkPtr. * *-------------------------------------------------------------- */ /*ARGSUSED*/static intEmbWinLayoutProc(textPtr, indexPtr, ewPtr, offset, maxX, maxChars, noCharsYet, wrapMode, chunkPtr) TkText *textPtr; /* Text widget being layed out. */ TkTextIndex *indexPtr; /* Identifies first character in chunk. */ TkTextSegment *ewPtr; /* Segment corresponding to indexPtr. */ int offset; /* Offset within segPtr corresponding to * indexPtr (always 0). */ int maxX; /* Chunk must not occupy pixels at this * position or higher. */ int maxChars; /* Chunk must not include more than this * many characters. */ int noCharsYet; /* Non-zero means no characters have been * assigned to this line yet. */ Tk_Uid wrapMode; /* Wrap mode to use for line: tkTextCharUid, * tkTextNoneUid, or tkTextWordUid. */ register TkTextDispChunk *chunkPtr; /* Structure to fill in with information * about this chunk. The x field has already * been set by the caller. */{ int width, height; if (offset != 0) { panic("Non-zero offset in EmbWinLayoutProc"); } if ((ewPtr->body.ew.tkwin == NULL) && (ewPtr->body.ew.create != NULL)) { int code, new; Tcl_DString name; Tk_Window ancestor; Tcl_HashEntry *hPtr; /* * The window doesn't currently exist. Create it by evaluating * the creation script. The script must return the window's * path name: look up that name to get back to the window * token. Then register ourselves as the geometry manager for * the window. */ code = Tcl_GlobalEval(textPtr->interp, ewPtr->body.ew.create); if (code != TCL_OK) { createError: Tcl_BackgroundError(textPtr->interp); goto gotWindow; } Tcl_DStringInit(&name); Tcl_DStringAppend(&name, textPtr->interp->result, -1); Tcl_ResetResult(textPtr->interp); ewPtr->body.ew.tkwin = Tk_NameToWindow(textPtr->interp, Tcl_DStringValue(&name), textPtr->tkwin); if (ewPtr->body.ew.tkwin == NULL) { goto createError;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -