Re: Adding new ItemType to Canvas
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

Re: Adding new ItemType to Canvas

From: George Peter Staplin <georgeps@xmission.com>
Date: Mon Sep 19 2005 - 12:36:56 CEST

on Jingzhao wrote:
> Dear all,
>
> I want to add a new ItemType to the Canvas widget. The implemenation
> will be in C and hopefully be able to work crossplatform.
>
> I checked out the source code of Tk. It seems that this is possible
> using "Tk_CreateItemType(typePtr)". The source code recommends to check
> out the implemenation of the built-in types on how to create new
> ItemType.

> However, to compile the file, the following header files are required:
>
> #include "tkInt.h"
> #include "tkPort.h"
> #include "tkCanvas.h"

For your own canvas item type you don't need the internal headers.
They are mostly used for some internal procedures that some Tk types
share, such as TkStateParseProc.

I've written my own canvas item type using just the public headers. The
only problem I've run into is a documentation bug (which I reported).
Make sure you do something like this:

/* should be 0 or 1 */
->alwaysRedraw = 1 | TK_CONFIG_OBJS

You may note that most Tk_ItemType definitions just use TK_CONFIG_OBJS,
and the comments actually say "flags," but the actual structure member
is ->alwaysRedraw.

Another thing I found undocumented was that Tk_ConfigureWidget needs
TK_CONFIG_OBJS.

if (TCL_OK != Tk_ConfigureWidget (interp, Tk_CanvasTkwin (canvas),
tg_config_spec, objc, (CONST char **) objv, (char *)inst,
TK_CONFIG_OBJS)) {
 return TCL_ERROR;
}

Unfortunately this is somewhat hackish, because not all pointers are
guaranteed to fit into (char *), but it's what Tk does. Eventually we
may have to cleanup bits like this in Tcl/Tk. There is also a newer API
than Tk_ConfigureWidget that uses a Tk_OptionTable, but the canvas code
hasn't been modified to use that AFAIK.

Have fun,

George
Received on Thu Sep 29 14:37:42 2005