⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tktextwind.c

📁 linux系统下的音频通信
💻 C
📖 第 1 页 / 共 3 页
字号:
	}	for (ancestor = textPtr->tkwin; ;		ancestor = Tk_Parent(ancestor)) {	    if (ancestor == Tk_Parent(ewPtr->body.ew.tkwin)) {		break;	    }	    if (Tk_IsTopLevel(ancestor)) {		badMaster:		Tcl_AppendResult(textPtr->interp, "can't embed ",			Tk_PathName(ewPtr->body.ew.tkwin), " relative to ",			Tk_PathName(textPtr->tkwin), (char *) NULL);		Tcl_BackgroundError(textPtr->interp);		ewPtr->body.ew.tkwin = NULL;		goto gotWindow;	    }	}	if (Tk_IsTopLevel(ewPtr->body.ew.tkwin)		|| (textPtr->tkwin == ewPtr->body.ew.tkwin)) {	    goto badMaster;	}	Tk_ManageGeometry(ewPtr->body.ew.tkwin, &textGeomType,		(ClientData) ewPtr);	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);    }    /*     * See if there's room for this window on this line.     */    gotWindow:    if (ewPtr->body.ew.tkwin == NULL) {	width = 0;	height = 0;    } else {	width = Tk_ReqWidth(ewPtr->body.ew.tkwin) + 2*ewPtr->body.ew.padX;	height = Tk_ReqHeight(ewPtr->body.ew.tkwin) + 2*ewPtr->body.ew.padY;    }    if ((width > (maxX - chunkPtr->x))	    && !noCharsYet && (textPtr->wrapMode != tkTextNoneUid)) {	return 0;    }    /*     * Fill in the chunk structure.     */    chunkPtr->displayProc = EmbWinDisplayProc;    chunkPtr->undisplayProc = EmbWinUndisplayProc;    chunkPtr->measureProc = (Tk_ChunkMeasureProc *) NULL;    chunkPtr->bboxProc = EmbWinBboxProc;    chunkPtr->numChars = 1;    if (ewPtr->body.ew.align == ALIGN_BASELINE) {	chunkPtr->minAscent = height - ewPtr->body.ew.padY;	chunkPtr->minDescent = ewPtr->body.ew.padY;	chunkPtr->minHeight = 0;    } else {	chunkPtr->minAscent = 0;	chunkPtr->minDescent = 0;	chunkPtr->minHeight = height;    }    chunkPtr->width = width;    chunkPtr->breakIndex = -1;    chunkPtr->breakIndex = 1;    chunkPtr->clientData = (ClientData) ewPtr;    ewPtr->body.ew.chunkCount += 1;    return 1;}/* *-------------------------------------------------------------- * * EmbWinCheckProc -- * *	This procedure is invoked by the B-tree code to perform *	consistency checks on embedded windows. * * Results: *	None. * * Side effects: *	The procedure panics if it detects anything wrong with *	the embedded window. * *-------------------------------------------------------------- */static voidEmbWinCheckProc(ewPtr, linePtr)    TkTextSegment *ewPtr;		/* Segment to check. */    TkTextLine *linePtr;		/* Line containing segment. */{    if (ewPtr->nextPtr == NULL) {	panic("EmbWinCheckProc: embedded window is last segment in line");    }    if (ewPtr->size != 1) {	panic("EmbWinCheckProc: embedded window has size %d", ewPtr->size);    }}/* *-------------------------------------------------------------- * * EmbWinDisplayProc -- * *	This procedure is invoked by the text displaying code *	when it is time to actually draw an embedded window *	chunk on the screen. * * Results: *	None. * * Side effects: *	The embedded window gets moved to the correct location *	and mapped onto the screen. * *-------------------------------------------------------------- */static voidEmbWinDisplayProc(chunkPtr, x, y, lineHeight, baseline, display, dst, screenY)    TkTextDispChunk *chunkPtr;		/* Chunk that is to be drawn. */    int x;				/* X-position in dst at which to					 * draw this chunk (differs from					 * the x-position in the chunk because					 * of scrolling). */    int y;				/* Top of rectangular bounding box					 * for line: tells where to draw this					 * chunk in dst (x-position is in					 * the chunk itself). */    int lineHeight;			/* Total height of line. */    int baseline;			/* Offset of baseline from y. */    Display *display;			/* Display to use for drawing. */    Drawable dst;			/* Pixmap or window in which to draw */    int screenY;			/* Y-coordinate in text window that					 * corresponds to y. */{    TkTextSegment *ewPtr = (TkTextSegment *) chunkPtr->clientData;    int lineX, windowX, windowY, width, height;    Tk_Window tkwin;    tkwin = ewPtr->body.ew.tkwin;    if (tkwin == NULL) {	return;    }    if ((x + chunkPtr->width) <= 0) {	/*	 * The window is off-screen;  just unmap it.	 */	if (ewPtr->body.ew.textPtr->tkwin != Tk_Parent(tkwin)) {	    Tk_UnmaintainGeometry(tkwin, ewPtr->body.ew.textPtr->tkwin);	} else {	    Tk_UnmapWindow(tkwin);	}	return;    }    /*     * Compute the window's location and size in the text widget, taking     * into account the align and stretch values for the window.     */    EmbWinBboxProc(chunkPtr, 0, screenY, lineHeight, baseline, &lineX,	    &windowY, &width, &height);    windowX = lineX - chunkPtr->x + x;    if (ewPtr->body.ew.textPtr->tkwin == Tk_Parent(tkwin)) {	if ((windowX != Tk_X(tkwin)) || (windowY != Tk_Y(tkwin))		|| (Tk_ReqWidth(tkwin) != Tk_Width(tkwin))		|| (height != Tk_Height(tkwin))) {	    Tk_MoveResizeWindow(tkwin, windowX, windowY, width, height);	}	Tk_MapWindow(tkwin);    } else {	Tk_MaintainGeometry(tkwin, ewPtr->body.ew.textPtr->tkwin,		windowX, windowY, width, height);    }    /*     * Mark the window as displayed so that it won't get unmapped.     */    ewPtr->body.ew.displayed = 1;}/* *-------------------------------------------------------------- * * EmbWinUndisplayProc -- * *	This procedure is called when the chunk for an embedded *	window is no longer going to be displayed.  It arranges *	for the window associated with the chunk to be unmapped. * * Results: *	None. * * Side effects: *	The window is scheduled for unmapping. * *-------------------------------------------------------------- */static voidEmbWinUndisplayProc(textPtr, chunkPtr)    TkText *textPtr;			/* Overall information about text					 * widget. */    TkTextDispChunk *chunkPtr;		/* Chunk that is about to be freed. */{    TkTextSegment *ewPtr = (TkTextSegment *) chunkPtr->clientData;    ewPtr->body.ew.chunkCount--;    if (ewPtr->body.ew.chunkCount == 0) {	/*	 * Don't unmap the window immediately, since there's a good chance	 * that it will immediately be redisplayed, perhaps even in the	 * same place.  Instead, schedule the window to be unmapped later;	 * the call to EmbWinDelayedUnmap will be cancelled in the likely	 * event that the unmap becomes unnecessary.	 */	ewPtr->body.ew.displayed = 0;	Tcl_DoWhenIdle(EmbWinDelayedUnmap, (ClientData) ewPtr);    }}/* *-------------------------------------------------------------- * * EmbWinBboxProc -- * *	This procedure is called to compute the bounding box of *	the area occupied by an embedded window. * * Results: *	There is no return value.  *xPtr and *yPtr are filled in *	with the coordinates of the upper left corner of the *	window, and *widthPtr and *heightPtr are filled in with *	the dimensions of the window in pixels.  Note:  not all *	of the returned bbox is necessarily visible on the screen *	(the rightmost part might be off-screen to the right, *	and the bottommost part might be off-screen to the bottom). * * Side effects: *	None. * *-------------------------------------------------------------- */static voidEmbWinBboxProc(chunkPtr, index, y, lineHeight, baseline, xPtr, yPtr,	widthPtr, heightPtr)    TkTextDispChunk *chunkPtr;		/* Chunk containing desired char. */    int index;				/* Index of desired character within					 * the chunk. */    int y;				/* Topmost pixel in area allocated					 * for this line. */    int lineHeight;			/* Total height of line. */    int baseline;			/* Location of line's baseline, in					 * pixels measured down from y. */    int *xPtr, *yPtr;			/* Gets filled in with coords of					 * character's upper-left pixel. */    int *widthPtr;			/* Gets filled in with width of					 * character, in pixels. */    int *heightPtr;			/* Gets filled in with height of					 * character, in pixels. */{    TkTextSegment *ewPtr = (TkTextSegment *) chunkPtr->clientData;    Tk_Window tkwin;    tkwin = ewPtr->body.ew.tkwin;    if (tkwin != NULL) {	*widthPtr = Tk_ReqWidth(tkwin);	*heightPtr = Tk_ReqHeight(tkwin);    } else {	*widthPtr = 0;	*heightPtr = 0;    }    *xPtr = chunkPtr->x + ewPtr->body.ew.padX;    if (ewPtr->body.ew.stretch) {	if (ewPtr->body.ew.align == ALIGN_BASELINE) {	    *heightPtr = baseline - ewPtr->body.ew.padY;	} else {	    *heightPtr = lineHeight - 2*ewPtr->body.ew.padY;	}    }    switch (ewPtr->body.ew.align) {	case ALIGN_BOTTOM:	    *yPtr = y + (lineHeight - *heightPtr - ewPtr->body.ew.padY);	    break;	case ALIGN_CENTER:	    *yPtr = y + (lineHeight - *heightPtr)/2;	    break;	case ALIGN_TOP:	    *yPtr = y + ewPtr->body.ew.padY;	    break;	case ALIGN_BASELINE:	    *yPtr = y + (baseline - *heightPtr);	    break;    }}/* *-------------------------------------------------------------- * * EmbWinDelayedUnmap -- * *	This procedure is an idle handler that does the actual *	work of unmapping an embedded window.  See the comment *	in EmbWinUndisplayProc for details. * * Results: *	None. * * Side effects: *	The window gets unmapped, unless its chunk reference count *	has become non-zero again. * *-------------------------------------------------------------- */static voidEmbWinDelayedUnmap(clientData)    ClientData clientData;		/* Token for the window to					 * be unmapped. */{    TkTextSegment *ewPtr = (TkTextSegment *) clientData;    if (!ewPtr->body.ew.displayed && (ewPtr->body.ew.tkwin != NULL)) {	if (ewPtr->body.ew.textPtr->tkwin != Tk_Parent(ewPtr->body.ew.tkwin)) {	    Tk_UnmaintainGeometry(ewPtr->body.ew.tkwin,		    ewPtr->body.ew.textPtr->tkwin);	} else {	    Tk_UnmapWindow(ewPtr->body.ew.tkwin);	}    }}/* *-------------------------------------------------------------- * * TkTextWindowIndex -- * *	Given the name of an embedded window within a text widget, *	returns an index corresponding to the window's position *	in the text. * * Results: *	The return value is 1 if there is an embedded window by *	the given name in the text widget, 0 otherwise.  If the *	window exists, *indexPtr is filled in with its index. * * Side effects: *	None. * *-------------------------------------------------------------- */intTkTextWindowIndex(textPtr, name, indexPtr)    TkText *textPtr;		/* Text widget containing window. */    char *name;			/* Name of window. */    TkTextIndex *indexPtr;	/* Index information gets stored here. */{    Tcl_HashEntry *hPtr;    TkTextSegment *ewPtr;    hPtr = Tcl_FindHashEntry(&textPtr->windowTable, name);    if (hPtr == NULL) {	return 0;    }    ewPtr = (TkTextSegment *) Tcl_GetHashValue(hPtr);    indexPtr->tree = textPtr->tree;    indexPtr->linePtr = ewPtr->body.ew.linePtr;    indexPtr->charIndex = TkTextSegToOffset(ewPtr, indexPtr->linePtr);    return 1;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -