📄 crtitemtype.3
字号:
\fIdeleteProc\fR should not actually free the item record; this willbe done by Tk when \fIdeleteProc\fR returns..SH "DISPLAYPROC AND ALWAYSREDRAW".PP\fItypePtr->displayProc\fR is invoked by Tk to redraw an itemon the screen.It must match the following prototype:.CStypedef void Tk_ItemDisplayProc( Tk_Canvas \fIcanvas\fR, Tk_Item *\fIitemPtr\fR, Display *\fIdisplay\fR, Drawable \fIdst\fR, int \fIx\fR, int \fIy\fR, int \fIwidth\fR, int \fIheight\fR);.CEThe \fIcanvas\fR and \fIitemPtr\fR arguments have the usual meaning.\fIdisplay\fR identifies the display containing the canvas, and\fIdst\fR specifies a drawable in which the item should be rendered;typically this is an off-screen pixmap, which Tk will copy intothe canvas's window once all relevant items have been drawn.\fIx\fR, \fIy\fR, \fIwidth\fR, and \fIheight\fR specify a rectangularregion in canvas coordinates, which is the area to be redrawn;only information that overlaps this area needs to be redrawn.Tk will not call \fIdisplayProc\fR unless the item's bounding boxoverlaps the redraw area, but the type manager may wish to usethe redraw area to optimize the redisplay of the item..PPBecause of scrolling and the use of off-screen pixmaps fordouble-buffered redisplay, the item's coordinates in \fIdst\fRwill not necessarily be the same as those in the canvas.\fIdisplayProc\fR should call \fBTk_CanvasDrawableCoords\fRto transform coordinates from those of the canvas to thoseof \fIdst\fR..PPNormally an item's \fIdisplayProc\fR is only invoked if the itemoverlaps the area being displayed.However, if \fItypePtr->alwaysRedraw\fR has a non-zero value, then\fIdisplayProc\fR is invoked during every redisplay operation,even if the item doesn't overlap the area of redisplay.\fIalwaysRedraw\fR should normally be set to 0; it is onlyset to 1 in special cases such as window items that need to beunmapped when they are off-screen..SH POINTPROC.PP\fItypePtr->pointProc\fR is invoked by Tk to find out how closea given point is to a canvas item.Tk uses this procedure for purposes such as locating the itemunder the mouse or finding the closest item to a given point.The procedure must match the following prototype:.CStypedef double Tk_ItemPointProc( Tk_Canvas \fIcanvas\fR, Tk_Item *\fIitemPtr\fR, double *\fIpointPtr\fR);.CE\fIcanvas\fR and \fIitemPtr\fR have the usual meaning.\fIpointPtr\fR points to an array of two numbers givingthe x and y coordinates of a point.\fIpointProc\fR must return a real value giving the distancefrom the point to the item, or 0 if the point lies insidethe item..SH AREAPROC.PP\fItypePtr->areaProc\fR is invoked by Tk to find out the relationshipbetween an item and a rectangular area.It must match the following prototype:.CStypedef int Tk_ItemAreaProc( Tk_Canvas \fIcanvas\fR, Tk_Item *\fIitemPtr\fR, double *\fIrectPtr\fR);.CE\fIcanvas\fR and \fIitemPtr\fR have the usual meaning.\fIrectPtr\fR points to an array of four real numbers;the first two give the x and y coordinates of the upper leftcorner of a rectangle, and the second two give the x and ycoordinates of the lower right corner.\fIareaProc\fR must return \-1 if the item lies entirely outsidethe given area, 0 if it lies partially inside and partiallyoutside the area, and 1 if it lies entirely inside the area..SH POSTSCRIPTPROC.PP\fItypePtr->postscriptProc\fR is invoked by Tk to generatePostcript for an item during the \fBpostscript\fR widget command.If the type manager is not capable of generating Postscript then\fItypePtr->postscriptProc\fR should be NULL.The procedure must match the following prototype:.CStypedef int Tk_ItemPostscriptProc( Tcl_Interp *\fIinterp\fR, Tk_Canvas \fIcanvas\fR, Tk_Item *\fIitemPtr\fR, int \fIprepass\fR);.CEThe \fIinterp\fR, \fIcanvas\fR, and \fIitemPtr\fR arguments all havestandard meanings; \fIprepass\fR will be described below.If \fIpostscriptProc\fR completes successfully, it should appendPostscript for the item to the information in \fIinterp->result\fR(e.g. by calling \fBTcl_AppendResult\fR, not \fBTcl_SetResult\fR)and return TCL_OK.If an error occurs, \fIpostscriptProc\fR should clear the resultand replace its contents with an error message; then it shouldreturn TCL_ERROR..PPTk provides a collection of utility procedures to simplify\fIpostscriptProc\fR.For example, \fBTk_CanvasPsColor\fR will generate Postscript to setthe current color to a given Tk color and \fBTk_CanvasPsFont\fR willset up font information.When generating Postscript, the type manager is free to change thegraphics state of the Postscript interpreter, since Tk places\fBgsave\fR and \fBgrestore\fR commands around the Postscript forthe item.The type manager can use canvas x coordinates directly in its Postscript,but it must call \fBTk_CanvasPsY\fR to convert y coordinates fromthe space of the canvas (where the origin is at theupper left) to the space of Postscript (where the origin is at thelower left)..PPIn order to generate Postscript that complies with the Adobe DocumentStructuring Conventions, Tk actually generates Postscript in two passes.It calls each item's \fIpostscriptProc\fR in each pass.The only purpose of the first pass is to collect font information(which is done by \fBTk_CanvPsFont\fR); the actual Postscript isdiscarded.Tk sets the \fIprepass\fR argument to \fIpostscriptProc\fR to 1during the first pass; the type manager can use \fIprepass\fR to skipall Postscript generation except for calls to \fBTk_CanvasPsFont\fR.During the second pass \fIprepass\fR will be 0, so the type managermust generate complete Postscript..SH SCALEPROC\fItypePtr->scaleProc\fR is invoked by Tk to rescale a canvas itemduring the \fBscale\fR widget command.The procedure must match the following prototype:.CStypedef void Tk_ItemScaleProc( Tk_Canvas \fIcanvas\fR, Tk_Item *\fIitemPtr\fR, double \fIoriginX\fR, double \fIoriginY\fR, double \fIscaleX\fR, double \fIscaleY\fR);.CEThe \fIcanvas\fR and \fIitemPtr\fR arguments have the usual meaning.\fIoriginX\fR and \fIoriginY\fR specify an origin relative to whichthe item is to be scaled, and \fIscaleX\fR and \fIscaleY\fR give thex and y scale factors.The item should adjust its coordinates so that a point in the itemthat used to have coordinates \fIx\fR and \fIy\fR will have newcoordinates \fIx'\fR and \fIy'\fR, where.CS\fIx' = originX + scaleX*(x-originX)y' = originY + scaleY*(y-originY)\fR.CE\fIscaleProc\fR must also update the bounding box in the item'sheader..SH TRANSLATEPROC\fItypePtr->translateProc\fR is invoked by Tk to translate a canvas itemduring the \fBmove\fR widget command.The procedure must match the following prototype:.CStypedef void Tk_ItemTranslateProc( Tk_Canvas \fIcanvas\fR, Tk_Item *\fIitemPtr\fR, double \fIdeltaX\fR, double \fIdeltaY\fR);.CEThe \fIcanvas\fR and \fIitemPtr\fR arguments have the usual meaning,and \fIdeltaX\fR and \fIdeltaY\fR give the amounts that should beadded to each x and y coordinate within the item.The type manager should adjust the item's coordinates andupdate the bounding box in the item's header..SH INDEXPROC\fItypePtr->indexProc\fR is invoked by Tk to translate a stringindex specification into a numerical index, for example during the\fBindex\fR widget command.It is only relevant for item types that support indexable text;\fItypePtr->indexProc\fR may be specified as NULL for non-textualitem types.The procedure must match the following prototype:.CStypedef int Tk_ItemIndexProc( Tcl_Interp *\fIinterp\fR, Tk_Canvas \fIcanvas\fR, Tk_Item *\fIitemPtr\fR, char \fIindexString\fR, int *\fIindexPtr\fR);.CEThe \fIinterp\fR, \fIcanvas\fR, and \fIitemPtr\fR arguments allhave the usual meaning.\fIindexString\fR contains a textual description of an index,and \fIindexPtr\fR points to an integer value that should befilled in with a numerical index.It is up to the type manager to decide what forms of indexare supported (e.g., numbers, \fBinsert\fR, \fBsel.first\fR,\fBend\fR, etc.).\fIindexProc\fR should return a Tcl completion code and set\fIinterp->result\fR in the event of an error..SH ICURSORPROC.PP\fItypePtr->icursorProc\fR is invoked by Tk duringthe \fBicursor\fR widget command to set the position of theinsertion cursor in a textual item.It is only relevant for item types that support an insertion cursor;\fItypePtr->icursorProc\fR may be specified as NULL for item typesthat don't support an insertion cursor.The procedure must match the following prototype:.CStypedef void Tk_ItemIndexProc( Tk_Canvas \fIcanvas\fR, Tk_Item *\fIitemPtr\fR, int \fIindex\fR);.CE\fIcanvas\fR and \fIitemPtr\fR have the usual meanings, and\fIindex\fR is an index into the item's text, as returned by aprevious call to \fItypePtr->insertProc\fR.The type manager should position the insertion cursor in theitem just before the character given by \fIindex\fR.Whether or not to actually display the insertion cursor isdetermined by other information provided by \fBTk_CanvasGetTextInfo\fR..SH SELECTIONPROC.PP\fItypePtr->selectionProc\fR is invoked by Tk during selectionretrievals; it must return part or all of the selected text inthe item (if any).It is only relevant for item types that support text;\fItypePtr->selectionProc\fR may be specified as NULL for non-textualitem types.The procedure must match the following prototype:.CStypedef int Tk_ItemSelectionProc( Tk_Canvas \fIcanvas\fR, Tk_Item *\fIitemPtr\fR, int \fIoffset\fR, char *\fIbuffer\fR, int \fImaxBytes\fR);.CE\fIcanvas\fR and \fIitemPtr\fR have the usual meanings.\fIoffset\fR is an offset in bytes into the selection where 0 refersto the first byte of the selection; it identifiesthe first character that is to be returned in this call.\fIbuffer\fR points to an area of memory in which to store therequested bytes, and \fImaxBytes\fR specifies the maximum numberof bytes to return.\fIselectionProc\fR should extract up to \fImaxBytes\fR charactersfrom the selection and copy them to \fImaxBytes\fR; it shouldreturn a count of the number of bytes actually copied, which maybe less than \fImaxBytes\fR if there aren't \fIoffset+maxBytes\fR bytesin the selection..SH INSERTPROC.PP\fItypePtr->insertProc\fR is invoked by Tk duringthe \fBinsert\fR widget command to insert new text into acanvas item.It is only relevant for item types that support text;\fItypePtr->insertProc\fR may be specified as NULL for non-textualitem types.The procedure must match the following prototype:.CStypedef void Tk_ItemInsertProc( Tk_Canvas \fIcanvas\fR, Tk_Item *\fIitemPtr\fR, int \fIindex\fR, char *\fIstring\fR);.CE\fIcanvas\fR and \fIitemPtr\fR have the usual meanings.\fIindex\fR is an index into the item's text, as returned by aprevious call to \fItypePtr->insertProc\fR, and \fIstring\fRcontains new text to insert just before the character givenby \fIindex\fR.The type manager should insert the text and recompute the boundingbox in the item's header..SH DCHARSPROC.PP\fItypePtr->dCharsProc\fR is invoked by Tk during the \fBdchars\fRwidget command to delete a range of text from a canvas item.It is only relevant for item types that support text;\fItypePtr->dCharsProc\fR may be specified as NULL for non-textualitem types.The procedure must match the following prototype:.CStypedef void Tk_ItemDCharsProc( Tk_Canvas \fIcanvas\fR, Tk_Item *\fIitemPtr\fR, int \fIfirst\fR, int \fIlast\fR);.CE\fIcanvas\fR and \fIitemPtr\fR have the usual meanings.\fIfirst\fR and \fIlast\fR give the indices of the first and last bytesto be deleted, as returned by previous calls to \fItypePtr->indexProc\fR.The type manager should delete the specified characters and updatethe bounding box in the item's header..SH "SEE ALSO"Tk_CanvasPsY, Tk_CanvasTextInfo, Tk_CanvasTkwin.SH KEYWORDScanvas, focus, item type, selection, type manager
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -