Tk_CreateItemType

Tk_CreateItemType is a Perl module that define new kind of canvas item.
Download

Tk_CreateItemType Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Nick Ing-Simmons
  • Publisher web site:
  • http://search.cpan.org/~ni-s/

Tk_CreateItemType Tags


Tk_CreateItemType Description

Tk_CreateItemType is a Perl module that define new kind of canvas item. Tk_CreateItemType is a Perl module that define new kind of canvas item.SYNOPSIS#include Tk_CreateItemType(typePtr)Tk_ItemType * Tk_GetItemTypes()ARGUMENTSTk_ItemType *typePtr (in)Structure that defines the new type of canvas item.INTRODUCTIONTk_CreateItemType is invoked to define a new kind of canvas item described by the typePtr argument. An item type corresponds to a particular value of the type argument to the create method for canvases, and the code that implements a canvas item type is called a type manager. Tk defines several built-in item types, such as rectangle and text and image, but Tk_CreateItemType allows additional item types to be defined. Once Tk_CreateItemType returns, the new item type may be used in new or existing canvas widgets just like the built-in item types.Tk_GetItemTypes returns a pointer to the first in the list of all item types currently defined for canvases. The entries in the list are linked together through their nextPtr fields, with the end of the list marked by a NULL nextPtr.You may find it easier to understand the rest of this manual entry by looking at the code for an existing canvas item type such as bitmap (file tkCanvBmap.c) or text (tkCanvText.c). The easiest way to create a new type manager is to copy the code for an existing type and modify it for the new type.Tk provides a number of utility procedures for the use of canvas type managers, such as Tk_CanvasCoords and Tk_CanvasPsColor; these are described in separate manual entries.DATA STRUCTURESA type manager consists of a collection of procedures that provide a standard set of operations on items of that type. The type manager deals with three kinds of data structures. The first data structure is a Tk_ItemType; it contains information such as the name of the type and pointers to the standard procedures implemented by the type manager: typedef struct Tk_ItemType { char *name; int itemSize; Tk_ItemCreateProc *createProc; Tk_ConfigSpec *configSpecs; Tk_ItemConfigureProc *configProc; Tk_ItemCoordProc *coordProc; Tk_ItemDeleteProc *deleteProc; Tk_ItemDisplayProc *displayProc; int alwaysRedraw; Tk_ItemPointProc *pointProc; Tk_ItemAreaProc *areaProc; Tk_ItemPostscriptProc *postscriptProc; Tk_ItemScaleProc *scaleProc; Tk_ItemTranslateProc *translateProc; Tk_ItemIndexProc *indexProc; Tk_ItemCursorProc *icursorProc; Tk_ItemSelectionProc *selectionProc; Tk_ItemInsertProc *insertProc; Tk_ItemDCharsProc *dCharsProc; Tk_ItemType *nextPtr; } Tk_ItemType;The fields of a Tk_ItemType structure are described in more detail later in this manual entry. When Tk_CreateItemType is called, its typePtr argument must point to a structure with all of the fields initialized except nextPtr, which Tk sets to link all the types together into a list. The structure must be in permanent memory (either statically allocated or dynamically allocated but never freed); Tk retains a pointer to this structure.The second data structure manipulated by a type manager is an item record. For each item in a canvas there exists one item record. All of the items of a given type generally have item records with the same structure, but different types usually have different formats for their item records. The first part of each item record is a header with a standard structure defined by Tk via the type Tk_Item; the rest of the item record is defined by the type manager. A type manager must define its item records with a Tk_Item as the first field. For example, the item record for bitmap items is defined as follows: typedef struct BitmapItem { Tk_Item header; double x, y; Tk_Anchor anchor; Pixmap bitmap; XColor *fgColor; XColor *bgColor; GC gc; } BitmapItem;The header substructure contains information used by Tk to manage the item, such as its identifier, its tags, its type, and its bounding box. The fields starting with x belong to the type manager: Tk will never read or write them. The type manager should not need to read or write any of the fields in the header except for four fields whose names are x1, y1, x2, and y2. These fields give a bounding box for the items using integer canvas coordinates: the item should not cover any pixels with x-coordinate lower than x1 or y-coordinate lower than y1, nor should it cover any pixels with x-coordinate greater than or equal to x2 or y-coordinate greater than or equal to y2. It is up to the type manager to keep the bounding box up to date as the item is moved and reconfigured.Whenever Tk calls a procedure in a type manager it passes in a pointer to an item record. The argument is always passed as a pointer to a Tk_Item; the type manager will typically cast this into a pointer to its own specific type, such as BitmapItem.The third data structure used by type managers has type Tk_Canvas; it serves as an opaque handle for the canvas widget as a whole. Type managers need not know anything about the contents of this structure. A Tk_Canvas handle is typically passed in to the procedures of a type manager, and the type manager can pass the handle back to library procedures such as Tk_CanvasTkwin to fetch information about the canvas.nameThis section and the ones that follow describe each of the fields in a Tk_ItemType structure in detail. The name field provides a string name for the item type. Once Tk_CreateImageType returns, this name may be used in create methods to create items of the new type. If there already existed an item type by this name then the new item type replaces the old one.itemSizetypePtr->itemSize gives the size in bytes of item records of this type, including the Tk_Item header. Tk uses this size to allocate memory space for items of the type. All of the item records for a given type must have the same size. If variable length fields are needed for an item (such as a list of points for a polygon), the type manager can allocate a separate object of variable length and keep a pointer to it in the item record. Requirements: · Perl


Tk_CreateItemType Related Software