Tk Source Code

tkoWidget(3) -- oo class like widgets


Tko_WidgetClassDefine, Tko_WidgetCreate, Tko_WidgetDestroy, Tko_WidgetClientData, Tko_WidgetOptionGet, Tko_WidgetOptionSet,


#include "tkoWidget.h"

int Tko_WidgetClassDefine(interp,classname,methods,options) int Tko_WidgetCreate(clientdata,interp,object,createmode,arglist) void Tko_WidgetDestroy(context) ClientData Tko_WidgetClientData(context) Tcl_Obj * Tko_WidgetOptionGet(widget,option) int Tko_WidgetOptionSet(widget,option,value)


Tcl_Interp *interp Used interpreter.
Tcl_Obj *classname Oo class name of widget.
const Tcl_MethodType *methods This array defines class methods to create. For creation methods see [Tcl_NewMethod] manpage. If the method name of the first array entry is not NULL it will be used as constructor, if the second method name is not NULL it used as destructor. Then follow public methods until an entry with an method name equal NULL comes. Then follow private methods until an entry with an method name equal NULL comes.
const Tko_WidgetOptionDefine *options This array contain option definitions.
Tcl_Object object This is the current object reference.
Tko_WidgetCreateMode createmode When =1 then create a toplevel otherwise a frame window.
Tcl_Obj arglist Argument list of constructor call.
ClientData cientdata Pointer to widget structure. First part in this struct is Tko_Widget. It
Tcl_ObjectContext context Context of method calls.
Tcl_Obj *option The name of the used option.
Tcl_Obj *value New value of the given option.


The Tko_WidgetClassDefine function create a new tko widget class of classname. The function create the class add common methods (cget, configure, _tko_configure) and then add given methods and options.

The Tko_WidgetCreate function create a new window. The clientdata should be ckalloced in the widget constructor. The function add the given clientdata to the object metadata. The function should be called in a C widget constructor.

The Tko_WidgetDestroy function clears all internal widget data. The function also arrange the ckfree of the clientdata.

The Tko_WidgetClientData should be used from inside widget methods to get the widget structure data given in the Tko_WidgetCreate function.

The Tko_WidgetOptionGet function returns the current value of the given option.

The Tko_WidgetOptionSet function set the given option to the new given value.

Enum: Tko_WidgetOptionType

Suported enum type in the Tko_WidgetOptionDefine definition. As comment is the type of the address provided in the Tko_WidgetOptionDefine definition.

typedef enum Tko\_WidgetOptionType {
    TKO_SET_CLASS = 1,     /* (Tcl_Obj **)address */
    TKO_SET_VISUAL, /* (Tcl_Obj **)address */
    TKO_SET_COLORMAP,       /* (Tcl_Obj **)address */
    TKO_SET_USE,        /* (Tcl_Obj **)address */
    TKO_SET_CONTAINER,      /* (int *)address */
    TKO_SET_TCLOBJ, /* (Tcl_Obj **)address */
    TKO_SET_XCOLOR, /* (Xcolor **)address */
    TKO_SET_3DBORDER,       /* (Tk_3DBorder *)address */
    TKO_SET_PIXEL,  /* (int *)address */
    TKO_SET_PIXELNONEGATIV, /* (int *)address */
    TKO_SET_PIXELPOSITIV,   /* (int *)address */
    TKO_SET_DOUBLE, /* (double *)address */
    TKO_SET_BOOLEAN,        /* (int *)address */
    TKO_SET_CURSOR, /* (Tk_Cursor *)address */
    TKO_SET_INT,    /* (int *)address */
    TKO_SET_RELIEF, /* (int *)address */
    TKO_SET_ANCHOR, /* (int *)address */
    TKO_SET_WINDOW, /* (Tk_Window *)address */
    TKO_SET_FONT,   /* (Tk_Font *)address */
    TKO_SET_STRING, /* (char **)address */
    TKO_SET_SCROLLREGION,   /* (int *[4])address */
    TKO_SET_JUSTIFY /* (Tk_Justify *)address */
} Tko\_WidgetOptionType;

Enum: Tko_WidgetCreateMode

Supported values in Tko_WdigetCreate() function call.

typedef enum Tko_WidgetCreateMode {
  TKO_CREATE_WIDGET, /* Create new widget */
  TKO_CREATE_TOPLEVEL, /* Create new toplevel widget */
  TKO_CREATE_CLASS, /* See "tko initclass" */
  TKO_CREATE_WRAP /* See "tko initwrap" */
} Tko_WidgetCreateMode;

Struct: Tko_WidgetOptionDefine

Widget definition data used in class. An option set method "-option" is created in the following order:

Struct: Tko_Widget

Widget structure data used in objects. These structure will be filled in the Tko_WidgetCreate call and cleared in the Tko_WidgetDestroy call. Widget methods should check the value of tkWin on NULL before using it.

typedef struct Tko_Widget {
    Tk_Window tkWin;       /* Window that embodies the widget. NULL means
                            * that the window has been destroyed but the
                            * data structures haven't yet been cleaned
                            * up.*/
    Display *display;      /* Display containing widget. Used, among
                            * other things, so that resources can be
                            * freed even after tkwin has gone away. */
    Tcl_Interp *interp;    /* Interpreter associated with widget. */
    Tcl_Command widgetCmd; /* Token for command. */
    Tcl_Object object;     /* our own object */
    Tcl_Obj *myCmd;        /* Objects "my" command. Needed to call internal methods. */
    Tcl_Obj *optionsArray; /* Name of option array variable */
    Tcl_HashTable *optionsTable; /* Hash table containing all used options */
} Tko_Widget;


static Tko_WidgetOptionDefine myOptions[] = {
     * Readonly option, only setable on creation time.
     * Use of internal standard option setting function.
     * Option value in structure have NULL value when option is empty.
     * Use of internal standard option setting function.
        NULL,NULL,TKO_SET_3DBORDER,&frameMeta,offsetof(tkoFrame, border)},
     * Use own provided oo method to set option value.
     * Synonym option definition.
     * Indicate end of options in array.

For detailed examples see also the implementation of tko::toplevel, tko::frame and tko::labelframe widgets in file generic/tko/tkoFrame.c.


frame, labelframe, toplevel, oo::class


oo widget method option


© 2019- RenĂ© Zaumseil [email protected]

BSD style license.