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

📄 tktextimage.c

📁 linux系统下的音频通信
💻 C
📖 第 1 页 / 共 2 页
字号:
 *-------------------------------------------------------------- * * AlignPrintProc -- * *	This procedure is invoked by the Tk configuration code *	to produce a printable string for the "-align" configuration *	option for embedded images. * * Results: *	The return value is a string describing the embedded *	images'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 TkTextEmbImage					 * structure. */    int offset;				/* Ignored. */    Tcl_FreeProc **freeProcPtr;		/* Pointer to variable to fill in with					 * information about how to reclaim					 * storage for return string. */{    switch (((TkTextEmbImage *) widgRec)->align) {	case ALIGN_BASELINE:	    return "baseline";	case ALIGN_BOTTOM:	    return "bottom";	case ALIGN_CENTER:	    return "center";	case ALIGN_TOP:	    return "top";	default:	    return "??";    }}/* *-------------------------------------------------------------- * * EmbImageDeleteProc -- * *	This procedure is invoked by the text B-tree code whenever *	an embedded image lies in a range of characters being deleted. * * Results: *	Returns 0 to indicate that the deletion has been accepted. * * Side effects: *	The embedded image is deleted, if it exists, and any resources *	associated with it are released. * *-------------------------------------------------------------- */	/* ARGSUSED */static intEmbImageDeleteProc(eiPtr, linePtr, treeGone)    TkTextSegment *eiPtr;		/* 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 (eiPtr->body.ei.image != NULL) {	hPtr = Tcl_FindHashEntry(&eiPtr->body.ei.textPtr->imageTable,		eiPtr->body.ei.name);	if (hPtr != NULL) {	    /*	     * (It's possible for there to be no hash table entry for this	     * image, if an error occurred while creating the image segment	     * but before the image got added to the table)	     */	    Tcl_DeleteHashEntry(hPtr);	}	Tk_FreeImage(eiPtr->body.ei.image);    }    Tk_FreeOptions(configSpecs, (char *) &eiPtr->body.ei,	    eiPtr->body.ei.textPtr->display, 0);    if (eiPtr->body.ei.name != NULL) {	ckfree(eiPtr->body.ei.name);    }    ckfree((char *) eiPtr);    return 0;}/* *-------------------------------------------------------------- * * EmbImageCleanupProc -- * *	This procedure is invoked by the B-tree code whenever a *	segment containing an embedded image is moved from one *	line to another. * * Results: *	None. * * Side effects: *	The linePtr field of the segment gets updated. * *-------------------------------------------------------------- */static TkTextSegment *EmbImageCleanupProc(eiPtr, linePtr)    TkTextSegment *eiPtr;		/* Mark segment that's being moved. */    TkTextLine *linePtr;		/* Line that now contains segment. */{    eiPtr->body.ei.linePtr = linePtr;    return eiPtr;}/* *-------------------------------------------------------------- * * EmbImageLayoutProc -- * *	This procedure is the "layoutProc" for embedded image *	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 intEmbImageLayoutProc(textPtr, indexPtr, eiPtr, offset, maxX, maxChars,	noCharsYet, wrapMode, chunkPtr)    TkText *textPtr;		/* Text widget being layed out. */    TkTextIndex *indexPtr;	/* Identifies first character in chunk. */    TkTextSegment *eiPtr;	/* 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 EmbImageLayoutProc");    }    /*     * See if there's room for this image on this line.     */    if (eiPtr->body.ei.image == NULL) {	width = 0;	height = 0;    } else {	Tk_SizeOfImage(eiPtr->body.ei.image, &width, &height);	width += 2*eiPtr->body.ei.padX;	height += 2*eiPtr->body.ei.padY;    }    if ((width > (maxX - chunkPtr->x))	    && !noCharsYet && (textPtr->wrapMode != tkTextNoneUid)) {	return 0;    }    /*     * Fill in the chunk structure.     */    chunkPtr->displayProc = EmbImageDisplayProc;    chunkPtr->undisplayProc = (Tk_ChunkUndisplayProc *) NULL;    chunkPtr->measureProc = (Tk_ChunkMeasureProc *) NULL;    chunkPtr->bboxProc = EmbImageBboxProc;    chunkPtr->numChars = 1;    if (eiPtr->body.ei.align == ALIGN_BASELINE) {	chunkPtr->minAscent = height - eiPtr->body.ei.padY;	chunkPtr->minDescent = eiPtr->body.ei.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) eiPtr;    eiPtr->body.ei.chunkCount += 1;    return 1;}/* *-------------------------------------------------------------- * * EmbImageCheckProc -- * *	This procedure is invoked by the B-tree code to perform *	consistency checks on embedded images. * * Results: *	None. * * Side effects: *	The procedure panics if it detects anything wrong with *	the embedded image. * *-------------------------------------------------------------- */static voidEmbImageCheckProc(eiPtr, linePtr)    TkTextSegment *eiPtr;		/* Segment to check. */    TkTextLine *linePtr;		/* Line containing segment. */{    if (eiPtr->nextPtr == NULL) {	panic("EmbImageCheckProc: embedded image is last segment in line");    }    if (eiPtr->size != 1) {	panic("EmbImageCheckProc: embedded image has size %d", eiPtr->size);    }}/* *-------------------------------------------------------------- * * EmbImageDisplayProc -- * *	This procedure is invoked by the text displaying code *	when it is time to actually draw an embedded image *	chunk on the screen. * * Results: *	None. * * Side effects: *	The embedded image gets moved to the correct location *	and drawn onto the display. * *-------------------------------------------------------------- */static voidEmbImageDisplayProc(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 *eiPtr = (TkTextSegment *) chunkPtr->clientData;    int lineX, imageX, imageY, width, height;    Tk_Image image;    image = eiPtr->body.ei.image;    if (image == NULL) {	return;    }    if ((x + chunkPtr->width) <= 0) {	return;    }    /*     * Compute the image's location and size in the text widget, taking     * into account the align value for the image.     */    EmbImageBboxProc(chunkPtr, 0, y, lineHeight, baseline, &lineX,	    &imageY, &width, &height);    imageX = lineX - chunkPtr->x + x;    Tk_RedrawImage(image, 0, 0, width, height, dst,	    imageX, imageY);}/* *-------------------------------------------------------------- * * EmbImageBboxProc -- * *	This procedure is called to compute the bounding box of *	the area occupied by an embedded image. * * Results: *	There is no return value.  *xPtr and *yPtr are filled in *	with the coordinates of the upper left corner of the *	image, and *widthPtr and *heightPtr are filled in with *	the dimensions of the image 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 voidEmbImageBboxProc(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 *eiPtr = (TkTextSegment *) chunkPtr->clientData;    Tk_Image image;    image = eiPtr->body.ei.image;    if (image != NULL) {	Tk_SizeOfImage(image, widthPtr, heightPtr);    } else {	*widthPtr = 0;	*heightPtr = 0;    }    *xPtr = chunkPtr->x + eiPtr->body.ei.padX;    switch (eiPtr->body.ei.align) {	case ALIGN_BOTTOM:	    *yPtr = y + (lineHeight - *heightPtr - eiPtr->body.ei.padY);	    break;	case ALIGN_CENTER:	    *yPtr = y + (lineHeight - *heightPtr)/2;	    break;	case ALIGN_TOP:	    *yPtr = y + eiPtr->body.ei.padY;	    break;	case ALIGN_BASELINE:	    *yPtr = y + (baseline - *heightPtr);	    break;    }}/* *-------------------------------------------------------------- * * TkTextImageIndex -- * *	Given the name of an embedded image within a text widget, *	returns an index corresponding to the image's position *	in the text. * * Results: *	The return value is 1 if there is an embedded image by *	the given name in the text widget, 0 otherwise.  If the *	image exists, *indexPtr is filled in with its index. * * Side effects: *	None. * *-------------------------------------------------------------- */intTkTextImageIndex(textPtr, name, indexPtr)    TkText *textPtr;		/* Text widget containing image. */    char *name;			/* Name of image. */    TkTextIndex *indexPtr;	/* Index information gets stored here. */{    Tcl_HashEntry *hPtr;    TkTextSegment *eiPtr;    hPtr = Tcl_FindHashEntry(&textPtr->imageTable, name);    if (hPtr == NULL) {	return 0;    }    eiPtr = (TkTextSegment *) Tcl_GetHashValue(hPtr);    indexPtr->tree = textPtr->tree;    indexPtr->linePtr = eiPtr->body.ei.linePtr;    indexPtr->charIndex = TkTextSegToOffset(eiPtr, indexPtr->linePtr);    return 1;}/* *-------------------------------------------------------------- * * EmbImageProc -- * *	This procedure is called by the image code whenever an *	image or its contents changes. * * Results: *	None. * * Side effects: *	The image will be redisplayed. * *-------------------------------------------------------------- */static voidEmbImageProc(clientData, x, y, width, height, imgWidth, imgHeight)    ClientData clientData;              /* Pointer to widget record. */    int x, y;                           /* Upper left pixel (within image)                                         * that must be redisplayed. */    int width, height;                  /* Dimensions of area to redisplay                                         * (may be <= 0). */    int imgWidth, imgHeight;            /* New dimensions of image. */{    TkTextSegment *eiPtr = (TkTextSegment *) clientData;    TkTextIndex index;    index.tree = eiPtr->body.ei.textPtr->tree;    index.linePtr = eiPtr->body.ei.linePtr;    index.charIndex = TkTextSegToOffset(eiPtr, eiPtr->body.ei.linePtr);    TkTextChanged(eiPtr->body.ei.textPtr, &index, &index);}

⌨️ 快捷键说明

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