[PD-cvs] externals/miXed/toxy widget.h, NONE, 1.1 widgethandlers.c, NONE, 1.1 Makefile.objects, 1.4, 1.5 build_counter, 1.14, 1.15 notes.txt, 1.2, 1.3 widget.c, 1.16, 1.17 widgettype.c, 1.12, 1.13 widgettype.h, 1.5, NONE

Krzysztof Czaja krzyszcz at users.sourceforge.net
Tue May 10 20:00:04 CEST 2005


Update of /cvsroot/pure-data/externals/miXed/toxy
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10414

Modified Files:
	Makefile.objects build_counter notes.txt widget.c widgettype.c 
Added Files:
	widget.h widgethandlers.c 
Removed Files:
	widgettype.h 
Log Message:
toxy alpha17 and pddp alpha1 (see notes.txt for toxy, pddp and shared)

Index: notes.txt
===================================================================
RCS file: /cvsroot/pure-data/externals/miXed/toxy/notes.txt,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** notes.txt	12 Mar 2005 00:19:13 -0000	1.2
--- notes.txt	10 May 2005 17:59:59 -0000	1.3
***************
*** 1,12 ****
  TODO for toxy
    * widget
!     . cached handlers
      . better megawidgets
      . editor: handle semicolons (need to revisit resolution rules)
!     . editor: differentiate argument keys from casual #strings (color-names)
    * tow: canvas-wide and type-on-canvas-wide broadcasting
  
  DONE for toxy
  
  alpha16
    * widget:
--- 1,34 ----
  TODO for toxy
    * widget
!     . push long message handlers if defined, instead of short
!     . widgetcontainer: woc and wiw-list
      . better megawidgets
      . editor: handle semicolons (need to revisit resolution rules)
!     . editor: break editorhook into separate properties, add them in single mode
!     . find a way for "package require" to work out-of-the-box on windows
    * tow: canvas-wide and type-on-canvas-wide broadcasting
  
  DONE for toxy
  
+ alpha17
+   * widget:
+     . first sketch of an editor widget (bpf), introducing a basic set of rules:
+       - instance data kept in its own namespace
+       - gui sends '_data' (replaces '_value') requests to pd, specifying one
+ 	of the standard submessages: add, delete, set, get
+       - pd uses the new special handler for replying: @data
+       (for the time being, there is only an idle loop between the two sides)
+     . maintaining a scriptlet collection, which mirrors type and instance
+       handler properties (including specials: @vis, @new, @free and @data)
+     . lookup in the mirror for faster and more robust handling of messages 
+     . '@ini' section and 'ini' message removed, after being unified as the
+       @vis special handler (use 'set @vis' message form for passing options)
+     . all special handlers support short definitions (inside #. comments)
+       and long definitions (tagged with #@ comments), however only short
+       ones may be overriden by instance definitions
+     . long message handlers are stored, but not used yet
+     . .wid file header may include requirements (base widget definitions)
+     . fixed: patch's directory handling in 'redefine'
+ 
  alpha16
    * widget:

Index: widgettype.c
===================================================================
RCS file: /cvsroot/pure-data/externals/miXed/toxy/widgettype.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** widgettype.c	12 Mar 2005 00:19:13 -0000	1.12
--- widgettype.c	10 May 2005 18:00:00 -0000	1.13
***************
*** 7,14 ****
  #include "m_pd.h"
  #include "common/loud.h"
  #include "common/dict.h"
  #include "common/props.h"
  #include "toxy/scriptlet.h"
! #include "widgettype.h"
  
  static char masterwidget_builtin[] =
--- 7,15 ----
  #include "m_pd.h"
  #include "common/loud.h"
+ #include "common/grow.h"
  #include "common/dict.h"
  #include "common/props.h"
  #include "toxy/scriptlet.h"
! #include "widget.h"
  
  static char masterwidget_builtin[] =
***************
*** 17,34 ****
  
  #define WIDGETTYPE_VERBOSE
  
  struct _widgettype
  {
      t_pd          wt_pd;
      t_symbol     *wt_typekey;     /* this is a typemap symbol */
      t_symbol     *wt_tkclass;     /* also 'undefined' flag (gensym symbol) */
!     t_symbol     *wt_tkpackage;   /* gensym symbol */
      int           wt_isinternal;  /* true if built-in or defined in setup.wid */
!     t_props      *wt_options;
!     t_props      *wt_handlers;
!     t_props      *wt_arguments;
!     t_scriptlet  *wt_iniscript;
!     t_scriptlet  *wt_newscript;
!     t_scriptlet  *wt_freescript;
  };
  
--- 18,38 ----
  
  #define WIDGETTYPE_VERBOSE
+ #ifdef KRZYSZCZ
+ //#define WIDGETTYPE_DEBUG
+ #endif
  
  struct _widgettype
  {
      t_pd          wt_pd;
+     t_glist      *wt_glist;       /* set by the loading widget */
      t_symbol     *wt_typekey;     /* this is a typemap symbol */
      t_symbol     *wt_tkclass;     /* also 'undefined' flag (gensym symbol) */
!     char         *wt_requirements;
      int           wt_isinternal;  /* true if built-in or defined in setup.wid */
!     t_props           *wt_options;
!     t_props           *wt_handlers;  /* defined inside of #. comments */
!     t_props           *wt_arguments;
!     t_scriptlet       *wt_auxscript;
!     t_widgethandlers  *wt_scripts;   /* multiliners tagged with #@ comments */
  };
  
***************
*** 53,60 ****
  }
  
! static void widgettype_map(t_widgettype *wt, char *cls, char *pkg)
  {
      wt->wt_tkclass = (cls ? gensym(cls) : 0);
!     wt->wt_tkpackage = (pkg ? gensym(pkg) : 0);
  }
  
--- 57,113 ----
  }
  
! static void widgettype_map(t_widgettype *wt, char *cls, char *req)
  {
      wt->wt_tkclass = (cls ? gensym(cls) : 0);
!     if (wt->wt_requirements)
! 	freebytes(wt->wt_requirements, strlen(wt->wt_requirements) + 1);
!     if (req && *req)
!     {
! 	char *opt = 0;
! 	wt->wt_requirements = getbytes(strlen(req) + 1);
! 	strcpy(wt->wt_requirements, req);
! 	while (req)
! 	{
! 	    char *w1 = scriptlet_nextword(req);
! 	    opt = (*req == '-' ? req : (w1 && *w1 == '-' ? w1 : 0));
! 	    if (opt)
! 	    {
! 		if (strcmp(opt + 1, "exact"))
! 		{
! 		    loud_error
! 			(0, "unknown option \"%s\" in widget type header", opt);
! 		    opt = 0;
! 		}
! 		if (*req == '-')
! 		{
! 		    req = w1;
! 		    continue;
! 		}
! 		else w1 = scriptlet_nextword(w1);
! 	    }
! 	    if (*req >= '0' && *req <= '9')
! 	    {
! 		loud_error
! 		    (0, "invalid base widget name \"%s\" in widget type header",
! 		     req);
! 		req = w1;
! 	    }
! 	    else
! 	    {
! 		t_widgettype *base;
! 		char *ver = (w1 && *w1 >= '0' && *w1 <= '9' ? w1 : 0);
! 		char *w2 = (ver ? scriptlet_nextword(ver) : w1);
! #if 1
! 		loudbug_post("require %s (version %s %s)",
! 			     req, (opt ? opt : ">="), (ver ? ver : "any"));
! #endif
! 		base = widgettype_get(gensym(req), ver, opt, wt->wt_glist);
! 		if (!base->wt_tkclass)
! 		    loud_error(0, "missing base widget file \"%s.wid\"", req);
! 		req = w2;
! 	    }
! 	}
!     }
!     else wt->wt_requirements = 0;
  }
  
***************
*** 62,68 ****
  {
      props_clearall(wt->wt_options);
!     scriptlet_reset(wt->wt_iniscript);
!     scriptlet_reset(wt->wt_newscript);
!     scriptlet_reset(wt->wt_freescript);
  }
  
--- 115,119 ----
  {
      props_clearall(wt->wt_options);
!     widgethandlers_reset(wt->wt_scripts);
  }
  
***************
*** 72,80 ****
  {
      loudbug_startpost("widgettype free... ");
      dict_unbind(mw->mw_typemap, (t_pd *)wt, wt->wt_typekey);
      props_freeall(wt->wt_options);
!     scriptlet_free(wt->wt_iniscript);
!     scriptlet_free(wt->wt_newscript);
!     scriptlet_free(wt->wt_freescript);
      pd_free((t_pd *)wt);
      loudbug_post("done");
--- 123,132 ----
  {
      loudbug_startpost("widgettype free... ");
+     if (wt->wt_requirements)
+ 	freebytes(wt->wt_requirements, strlen(wt->wt_requirements) + 1);
      dict_unbind(mw->mw_typemap, (t_pd *)wt, wt->wt_typekey);
      props_freeall(wt->wt_options);
!     scriptlet_free(wt->wt_auxscript);
!     widgethandlers_free(wt->wt_scripts);
      pd_free((t_pd *)wt);
      loudbug_post("done");
***************
*** 82,101 ****
  #endif
  
! static t_widgettype *widgettype_new(t_masterwidget *mw,
! 				    char *typ, char *cls, char *pkg)
  {
      t_widgettype *wt = (t_widgettype *)pd_new(widgettype_class);
      wt->wt_typekey = dict_key(mw->mw_typemap, typ);
!     widgettype_map(wt, cls, pkg);
      wt->wt_isinternal = 0;
      wt->wt_options = props_new(0, "option", "-", 0, 0);
      wt->wt_handlers = props_new(0, "handler", "@", wt->wt_options, 0);
      wt->wt_arguments = props_new(0, "argument", "#", wt->wt_options, 0);
!     wt->wt_iniscript = scriptlet_new((t_pd *)wt, mw->mw_target, mw->mw_target,
! 				     0, 0, widgettype_cvhook);
!     wt->wt_newscript = scriptlet_new((t_pd *)wt, mw->mw_target, mw->mw_target,
  				     0, 0, widgettype_cvhook);
!     wt->wt_freescript = scriptlet_new((t_pd *)wt, mw->mw_target, mw->mw_target,
! 				      0, 0, widgettype_cvhook);
      dict_bind(mw->mw_typemap, (t_pd *)wt, wt->wt_typekey);
      return (wt);
--- 134,151 ----
  #endif
  
! static t_widgettype *widgettype_new(t_masterwidget *mw, char *typ, char *cls,
! 				    char *req, t_glist *glist)
  {
      t_widgettype *wt = (t_widgettype *)pd_new(widgettype_class);
+     wt->wt_glist = glist;
      wt->wt_typekey = dict_key(mw->mw_typemap, typ);
!     widgettype_map(wt, cls, req);
      wt->wt_isinternal = 0;
      wt->wt_options = props_new(0, "option", "-", 0, 0);
      wt->wt_handlers = props_new(0, "handler", "@", wt->wt_options, 0);
      wt->wt_arguments = props_new(0, "argument", "#", wt->wt_options, 0);
!     wt->wt_auxscript = scriptlet_new((t_pd *)wt, mw->mw_target, mw->mw_target,
  				     0, 0, widgettype_cvhook);
!     wt->wt_scripts = widgethandlers_new(wt->wt_auxscript);
      dict_bind(mw->mw_typemap, (t_pd *)wt, wt->wt_typekey);
      return (wt);
***************
*** 118,122 ****
  	t_widgettype *typeval;
  	char *cls = scriptlet_nextword(buf);
! 	char *pkg = (cls ? scriptlet_nextword(cls) : 0);
  	mw->mw_parsedtype = 0;
  	if (!cls)
--- 168,172 ----
  	t_widgettype *typeval;
  	char *cls = scriptlet_nextword(buf);
! 	char *req = (cls ? scriptlet_nextword(cls) : 0);
  	mw->mw_parsedtype = 0;
  	if (!cls)
***************
*** 144,155 ****
  	    }
  	}
- 	if (pkg)
- 	    /* carve out a single word as pkg, LATER rethink */
- 	    scriptlet_nextword(pkg);
  	if (typeval)
! 	    widgettype_map(typeval, cls, pkg);
  	else
  	{
! 	    typeval = widgettype_new(mw, buf, cls, pkg);
  	    typeval->wt_isinternal = (caller == (t_pd *)mw);
  	}
--- 194,202 ----
  	    }
  	}
  	if (typeval)
! 	    widgettype_map(typeval, cls, req);
  	else
  	{
! 	    typeval = widgettype_new(mw, buf, cls, req, 0);
  	    typeval->wt_isinternal = (caller == (t_pd *)mw);
  	}
***************
*** 158,163 ****
  	loudbug_post("adding widget type '%s'", typeval->wt_typekey->s_name);
  #endif
! 	scriptlet_reset(typeval->wt_iniscript);
! 	return (typeval->wt_iniscript);
      }
      else if (sel == '.')
--- 205,218 ----
  	loudbug_post("adding widget type '%s'", typeval->wt_typekey->s_name);
  #endif
! 	widgethandlers_reset(typeval->wt_scripts);
! 
! 	/* What should follow after the header?  In a cleaner layout, perhaps,
! 	   the header would be placed at the top, followed by setup.  Any
! 	   handler would require an explicit #@ tag, and the next statement
! 	   would return SCRIPTLET_UNLOCK.  LATER revisit -- the change breaks
! 	   old .wid files, so better wait for a more robust parsing, which
! 	   notices dot-sequences in the setup part and warns about them.
! 	   Setup before header will be valid after the change, anyway. */
! 	return (widgethandlers_getvis(typeval->wt_scripts));
      }
      else if (sel == '.')
***************
*** 193,216 ****
  	scriptlet_nextword(buf);
  	if (mw->mw_parsedtype)
! 	{
! 	    if (!strcmp(buf, "vis") || !strcmp(buf, "ini"))
! 		/* already reset */
! 		return (mw->mw_parsedtype->wt_iniscript);
! 	    else if (!strcmp(buf, "new"))
! 	    {
! 		scriptlet_reset(mw->mw_parsedtype->wt_newscript);
! 		return (mw->mw_parsedtype->wt_newscript);
! 	    }
! 	    else if (!strcmp(buf, "free"))
! 	    {
! 		scriptlet_reset(mw->mw_parsedtype->wt_freescript);
! 		return (mw->mw_parsedtype->wt_freescript);
! 	    }
! 	    else
! 	    {
! 		/* LATER start parsing any method handler: search for it,
! 		   create if not found, return */
! 	    }
! 	}
      }
      return (SCRIPTLET_UNLOCK);
--- 248,253 ----
  	scriptlet_nextword(buf);
  	if (mw->mw_parsedtype)
! 	    return (widgethandlers_takeany(mw->mw_parsedtype->wt_scripts,
! 					   gensym(buf)));
      }
      return (SCRIPTLET_UNLOCK);
***************
*** 224,228 ****
      t_scriptlet *mwsp =
  	scriptlet_new((t_pd *)masterwidget, masterwidget->mw_target,
! 		      masterwidget->mw_target, 0, canvas_getcurrent(), 0);
      masterwidget->mw_parsedtype = wt;
  
--- 261,265 ----
      t_scriptlet *mwsp =
  	scriptlet_new((t_pd *)masterwidget, masterwidget->mw_target,
! 		      masterwidget->mw_target, 0, wt->wt_glist, 0);
      masterwidget->mw_parsedtype = wt;
  
***************
*** 260,264 ****
  }
  
! t_widgettype *widgettype_get(t_symbol *s)
  {
      t_widgettype *wt = widgettype_find(s);
--- 297,301 ----
  }
  
! t_widgettype *widgettype_get(t_symbol *s, char *ver, char *opt, t_glist *glist)
  {
      t_widgettype *wt = widgettype_find(s);
***************
*** 269,273 ****
      {
  	/* first instance of a type not defined in setup.wid */
! 	wt = widgettype_new(masterwidget, s->s_name, 0, 0);
  	widgettype_doload(wt, s);
      }
--- 306,311 ----
      {
  	/* first instance of a type not defined in setup.wid */
! 	wt = widgettype_new(masterwidget, s->s_name, 0, 0, glist);
! 	/* LATER use version and option */
  	widgettype_doload(wt, s);
      }
***************
*** 275,287 ****
  }
  
! t_widgettype *widgettype_reload(t_symbol *s)
  {
      t_widgettype *wt = widgettype_find(s);
      if (!wt)
  	/* first instance of a type not defined in setup.wid */
! 	wt = widgettype_new(masterwidget, s->s_name, 0, 0);
      if (wt && !wt->wt_isinternal)
      {  /* LATER consider safe-loading through a temporary type */
  	widgettype_clear(wt);
  	if (widgettype_doload(wt, s))
  	    return (wt);
--- 313,326 ----
  }
  
! t_widgettype *widgettype_reload(t_symbol *s, t_glist *glist)
  {
      t_widgettype *wt = widgettype_find(s);
      if (!wt)
  	/* first instance of a type not defined in setup.wid */
! 	wt = widgettype_new(masterwidget, s->s_name, 0, 0, glist);
      if (wt && !wt->wt_isinternal)
      {  /* LATER consider safe-loading through a temporary type */
  	widgettype_clear(wt);
+ 	wt->wt_glist = glist;
  	if (widgettype_doload(wt, s))
  	    return (wt);
***************
*** 315,352 ****
  }
  
! char *widgettype_getinitializer(t_widgettype *wt, int *szp)
! {
!     return (scriptlet_getcontents(wt->wt_iniscript, szp));
! }
! 
! char *widgettype_getconstructor(t_widgettype *wt, int *szp)
! {
!     return (scriptlet_getcontents(wt->wt_newscript, szp));
! }
! 
! char *widgettype_getdestructor(t_widgettype *wt, int *szp)
! {
!     return (scriptlet_getcontents(wt->wt_freescript, szp));
! }
! 
! int widgettype_ievaluate(t_widgettype *wt, t_scriptlet *outsp,
! 			 int visedonly, int ac, t_atom *av, t_props *argprops)
! {
!     return (scriptlet_evaluate(wt->wt_iniscript, outsp,
! 			       visedonly, ac, av, argprops));
! }
! 
! int widgettype_cevaluate(t_widgettype *wt, t_scriptlet *outsp,
! 			 int visedonly, int ac, t_atom *av, t_props *argprops)
! {
!     return (scriptlet_evaluate(wt->wt_newscript, outsp,
! 			       visedonly, ac, av, argprops));
! }
! 
! int widgettype_devaluate(t_widgettype *wt, t_scriptlet *outsp,
! 			 int visedonly, int ac, t_atom *av, t_props *argprops)
  {
!     return (scriptlet_evaluate(wt->wt_freescript, outsp,
! 			       visedonly, ac, av, argprops));
  }
  
--- 354,360 ----
  }
  
! t_widgethandlers *widgettype_getscripts(t_widgettype *wt)
  {
!     return (wt->wt_scripts);
  }
  
***************
*** 435,441 ****
      if (rcresult == SCRIPTLET_OK)
      {
! 	t_scriptlet *sp =
! 	    scriptlet_new((t_pd *)masterwidget, masterwidget->mw_target,
! 			  masterwidget->mw_target, 0, 0, 0);
  	if (scriptlet_evaluate(masterwidget->mw_setupscript, sp, 0, 0, 0, 0))
  	    scriptlet_push(sp);
--- 443,447 ----
      if (rcresult == SCRIPTLET_OK)
      {
! 	t_scriptlet *sp = scriptlet_newalike(masterwidget->mw_setupscript);
  	if (scriptlet_evaluate(masterwidget->mw_setupscript, sp, 0, 0, 0, 0))
  	    scriptlet_push(sp);

Index: build_counter
===================================================================
RCS file: /cvsroot/pure-data/externals/miXed/toxy/build_counter,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** build_counter	12 Mar 2005 00:19:13 -0000	1.14
--- build_counter	10 May 2005 17:59:58 -0000	1.15
***************
*** 1,7 ****
  #define TOXY_VERSION "0.1"
  #define TOXY_RELEASE "alpha"
! #define TOXY_BUILD 16
  
  #if 0
! TOXY_SNAPSHOT = 0.1-alpha16
  #endif
--- 1,7 ----
  #define TOXY_VERSION "0.1"
  #define TOXY_RELEASE "alpha"
! #define TOXY_BUILD 17
  
  #if 0
! TOXY_SNAPSHOT = 0.1-alpha17
  #endif

--- NEW FILE: widgethandlers.c ---
/* Copyright (c) 2005 krzYszcz and others.
 * For information on usage and redistribution, and for a DISCLAIMER OF ALL
 * WARRANTIES, see the file, "LICENSE.txt," in this distribution.  */

#include <stdio.h>
#include "m_pd.h"
#include "common/loud.h"
#include "common/props.h"
#include "toxy/scriptlet.h"
#include "widget.h"

#ifdef KRZYSZCZ
//#define WIDGETHANDLERS_DEBUG
#endif

typedef struct _widgetscript
{
    t_symbol              *ws_selector;
    t_scriptlet           *ws_script;
    struct _widgetscript  *ws_next;
} t_widgetscript;

struct _widgethandlers
{
    t_scriptlet      *wh_vis;
    t_scriptlet      *wh_new;
    t_scriptlet      *wh_free;
    t_scriptlet      *wh_data;
    t_scriptlet      *wh_bang;
    t_scriptlet      *wh_float;
    t_scriptlet      *wh_symbol;
    t_widgetscript   *wh_others;
};

static t_symbol *widgetps_vis = 0;
static t_symbol *widgetps_new;
static t_symbol *widgetps_free;
static t_symbol *widgetps_data;

t_widgethandlers *widgethandlers_new(t_scriptlet *generator)
{
    t_widgethandlers *wh = getbytes(sizeof(*wh));
    if (!widgetps_vis)
    {
	widgetps_vis = gensym("vis");
	widgetps_new = gensym("new");
	widgetps_free = gensym("free");
	widgetps_data = gensym("data");
    }
    wh->wh_vis = scriptlet_newalike(generator);
    wh->wh_new = scriptlet_newalike(generator);
    wh->wh_free = scriptlet_newalike(generator);
    wh->wh_data = scriptlet_newalike(generator);
    wh->wh_bang = scriptlet_newalike(generator);
    wh->wh_float = scriptlet_newalike(generator);
    wh->wh_symbol = scriptlet_newalike(generator);
    wh->wh_others = 0;
    return (wh);
}

void widgethandlers_free(t_widgethandlers *wh)
{
    t_widgetscript  *ws, *wsnext = wh->wh_others;
    scriptlet_free(wh->wh_vis);
    scriptlet_free(wh->wh_new);
    scriptlet_free(wh->wh_free);
    scriptlet_free(wh->wh_data);
    scriptlet_free(wh->wh_bang);
    scriptlet_free(wh->wh_float);
    scriptlet_free(wh->wh_symbol);
    while (ws = wsnext)
    {
	wsnext = ws->ws_next;
	scriptlet_free(ws->ws_script);
	freebytes(ws, sizeof(*ws));
    }
    freebytes(wh, sizeof(*wh));
}

void widgethandlers_reset(t_widgethandlers *wh)
{
    t_widgetscript  *ws = wh->wh_others;
    scriptlet_reset(wh->wh_vis);
    scriptlet_reset(wh->wh_new);
    scriptlet_reset(wh->wh_free);
    scriptlet_reset(wh->wh_data);
    scriptlet_reset(wh->wh_bang);
    scriptlet_reset(wh->wh_float);
    scriptlet_reset(wh->wh_symbol);
    for (ws = wh->wh_others; ws; ws = ws->ws_next)
	scriptlet_reset(ws->ws_script);
}

static t_widgetscript *widgethandlers_takeotherscript(t_widgethandlers *wh,
						      t_symbol *selector)
{
    t_widgetscript *ws;
    for (ws = wh->wh_others; ws; ws = ws->ws_next)
	if (ws->ws_selector == selector)
	    break;
    if (!ws)
    {
	ws = getbytes(sizeof(*ws));
	ws->ws_selector = selector;
	ws->ws_script = scriptlet_newalike(wh->wh_vis);
	ws->ws_next = wh->wh_others;
	wh->wh_others = ws;
    }
    return (ws);
}

t_scriptlet *widgethandlers_takeany(t_widgethandlers *wh, t_symbol *selector)
{
    t_scriptlet *sp;
    if (selector == widgetps_vis)
	sp = wh->wh_vis;
    else if (selector == widgetps_new)
	sp = wh->wh_new;
    else if (selector == widgetps_free)
	sp = wh->wh_free;
    else if (selector == widgetps_data)
	sp = wh->wh_data;
    else if (selector == &s_bang)
	sp = wh->wh_bang;
    else if (selector == &s_float)
	sp = wh->wh_float;
    else if (selector == &s_symbol)
	sp = wh->wh_symbol;
    else
    {
	t_widgetscript *ws;
	if (ws = widgethandlers_takeotherscript(wh, selector))
	    sp = ws->ws_script;
	else
	{
	    loudbug_bug("widgethandlers_takeany");
	    sp = 0;
	}
    }
    return (sp);
}

void widgethandlers_fill(t_widgethandlers *wh, t_props *pp)
{
    int ac;
    t_atom *ap;
    if (ap = props_getfirst(pp, &ac))
    {
	do
	{
	    if (ac > 1 && ap->a_type == A_SYMBOL &&
		ap->a_w.w_symbol->s_name[0] == '@' &&
		ap->a_w.w_symbol->s_name[1] != 0)
	    {
		t_symbol *sel = gensym(ap->a_w.w_symbol->s_name + 1);
		t_scriptlet *sp;
		if (sp = widgethandlers_takeany(wh, sel))
		{
		    scriptlet_reset(sp);
		    scriptlet_add(sp, 0, 0, ac - 1, ap + 1);
		}
	    }
	    else loudbug_bug("widgethandlers_fill");
	}
	while (ap = props_getnext(pp, &ac));
    }
}

t_scriptlet *widgethandlers_getvis(t_widgethandlers *wh)
{
    return (wh->wh_vis);
}

t_scriptlet *widgethandlers_getnew(t_widgethandlers *wh)
{
    return (wh->wh_new);
}

t_scriptlet *widgethandlers_getfree(t_widgethandlers *wh)
{
    return (wh->wh_free);
}

t_scriptlet *widgethandlers_getdata(t_widgethandlers *wh)
{
    return (wh->wh_data);
}

t_scriptlet *widgethandlers_getbang(t_widgethandlers *wh)
{
    return (wh->wh_bang);
}

t_scriptlet *widgethandlers_getfloat(t_widgethandlers *wh)
{
    return (wh->wh_float);
}

t_scriptlet *widgethandlers_getsymbol(t_widgethandlers *wh)
{
    return (wh->wh_symbol);
}

t_scriptlet *widgethandlers_getother(t_widgethandlers *wh, t_symbol *selector)
{
    t_widgetscript *ws;
    for (ws = wh->wh_others; ws; ws = ws->ws_next)
	if (ws->ws_selector == selector)
	    return (ws->ws_script);
    return (0);
}

--- NEW FILE: widget.h ---
/* Copyright (c) 2003-2005 krzYszcz and others.
 * For information on usage and redistribution, and for a DISCLAIMER OF ALL
 * WARRANTIES, see the file, "LICENSE.txt," in this distribution.  */

#ifndef __WIDGET_H__
#define __WIDGET_H__

EXTERN_STRUCT _widgettype;
#define t_widgettype  struct _widgettype

EXTERN_STRUCT _masterwidget;
#define t_masterwidget  struct _masterwidget

EXTERN_STRUCT _widgethandlers;
#define t_widgethandlers  struct _widgethandlers

t_widgettype *widgettype_find(t_symbol *s);
t_widgettype *widgettype_get(t_symbol *s, char *ver, char *opt, t_glist *glist);
t_widgettype *widgettype_reload(t_symbol *s, t_glist *glist);
int widgettype_isdefined(t_widgettype *wt);
t_symbol *widgettype_tkclass(t_widgettype *wt);
t_props *widgettype_getoptions(t_widgettype *wt);
t_props *widgettype_gethandlers(t_widgettype *wt);
t_props *widgettype_getarguments(t_widgettype *wt);
t_widgethandlers *widgettype_getscripts(t_widgettype *wt);
char *widgettype_propname(t_symbol *s);
void widgettype_setup(void);

char *masterwidget_getcontents(int *szp);
void masterwidget_validate(void);

t_widgethandlers *widgethandlers_new(t_scriptlet *generator);
void widgethandlers_free(t_widgethandlers *wh);
void widgethandlers_reset(t_widgethandlers *wh);
void widgethandlers_fill(t_widgethandlers *wh, t_props *pp);
t_scriptlet *widgethandlers_getvis(t_widgethandlers *wh);
t_scriptlet *widgethandlers_getnew(t_widgethandlers *wh);
t_scriptlet *widgethandlers_getfree(t_widgethandlers *wh);
t_scriptlet *widgethandlers_getdata(t_widgethandlers *wh);
t_scriptlet *widgethandlers_getbang(t_widgethandlers *wh);
t_scriptlet *widgethandlers_getfloat(t_widgethandlers *wh);
t_scriptlet *widgethandlers_getsymbol(t_widgethandlers *wh);
t_scriptlet *widgethandlers_getother(t_widgethandlers *wh, t_symbol *selector);
t_scriptlet *widgethandlers_takeany(t_widgethandlers *wh, t_symbol *selector);

#endif

Index: Makefile.objects
===================================================================
RCS file: /cvsroot/pure-data/externals/miXed/toxy/Makefile.objects,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Makefile.objects	27 Jan 2005 14:42:54 -0000	1.4
--- Makefile.objects	10 May 2005 17:59:58 -0000	1.5
***************
*** 44,46 ****
  toxy/scriptlet.o
  
! WIDGET_PRIVATEOBJECTS = widgettype.o
--- 44,46 ----
  toxy/scriptlet.o
  
! WIDGET_PRIVATEOBJECTS = widgettype.o widgethandlers.o

--- widgettype.h DELETED ---

Index: widget.c
===================================================================
RCS file: /cvsroot/pure-data/externals/miXed/toxy/widget.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** widget.c	12 Mar 2005 00:19:13 -0000	1.16
--- widget.c	10 May 2005 17:59:59 -0000	1.17
***************
*** 15,19 ****
  #include "common/props.h"
  #include "toxy/scriptlet.h"
! #include "widgettype.h"
  #include "build_counter"
  
--- 15,19 ----
  #include "common/props.h"
  #include "toxy/scriptlet.h"
! #include "widget.h"
  #include "build_counter"
  
***************
*** 22,26 ****
  
  #ifdef KRZYSZCZ
! //#define WIDGET_DEBUG
  //#define TOW_DEBUG
  //#define WIDGET_PROFILE
--- 22,26 ----
  
  #ifdef KRZYSZCZ
! #define WIDGET_DEBUG
  //#define TOW_DEBUG
  //#define WIDGET_PROFILE
***************
*** 41,56 ****
  } t_widgetentry;
  
- /* move to widgettype.c&h */
- typedef struct _widgethandlers
- {
-     t_scriptlet  *wh_initializer;
-     t_scriptlet  *wh_new;
-     t_scriptlet  *wh_free;
-     t_scriptlet  *wh_bang;
-     t_scriptlet  *wh_float;
-     t_scriptlet  *wh_symbol;
-     /* ... (varsized vector) */
- } t_widgethandlers;
- 
  typedef struct _widget
  {
--- 41,44 ----
***************
*** 73,78 ****
      t_props       *x_diffhandlers;   /* same for handlers */
      t_props       *x_diffarguments;  /* same for arguments */
!     t_widgethandlers  x_cache;    /* actual handlers */
!     t_scriptlet   *x_iniscript;   /* instance initializer */
      t_scriptlet   *x_optscript;   /* option scriptlet */
      t_scriptlet   *x_auxscript;   /* auxiliary scriptlet */
--- 61,65 ----
      t_props       *x_diffhandlers;   /* same for handlers */
      t_props       *x_diffarguments;  /* same for arguments */
!     t_widgethandlers  *x_hooks;   /* actual handlers (short definitions) */
      t_scriptlet   *x_optscript;   /* option scriptlet */
      t_scriptlet   *x_auxscript;   /* auxiliary scriptlet */
***************
*** 87,90 ****
--- 74,78 ----
      int            x_update;      /* see widget_update() */
      int            x_vised;
+     int            x_constructed;
      t_clock       *x_transclock;
      t_towentry    *x_towlist;
***************
*** 113,121 ****
  static t_symbol *widgetps_mouse;
  static t_symbol *widgetps_motion;
! static t_symbol *widgetps_atbang;
! static t_symbol *widgetps_atfloat;
! static t_symbol *widgetps_atsymbol;
! static t_symbol *widgetps_atstore;
! static t_symbol *widgetps_atrestore;
  
  #ifdef WIDGET_PROFILE
--- 101,112 ----
  static t_symbol *widgetps_mouse;
  static t_symbol *widgetps_motion;
! static t_symbol *widgetps_vis;
! static t_symbol *widgetps_new;
! static t_symbol *widgetps_free;
! static t_symbol *widgetps_data;
! static t_symbol *widgetps_add;
! static t_symbol *widgetps_delete;
! static t_symbol *widgetps_set;
! static t_symbol *widgetps_get;
  
  #ifdef WIDGET_PROFILE
***************
*** 362,408 ****
  }
  
! static void widget_pushinits(t_widget *x)
  {
      if (widgettype_isdefined(x->x_typedef))
      {
! 	int sz;
! 	if (widgettype_ievaluate(x->x_typedef, x->x_transient, 0,
! 				 0, 0, x->x_xargs))
! 	    scriptlet_vpush(x->x_transient, "typeinit");
! 	else if (*widgettype_getinitializer(x->x_typedef, &sz) && sz > 0)
! 	    loudbug_bug("widget_pushinits (type)");
      }
!     if (scriptlet_evaluate(x->x_iniscript, x->x_transient, 0, 0, 0, x->x_xargs))
! 	scriptlet_vpush(x->x_transient, "iteminit");
!     else if (!scriptlet_isempty(x->x_iniscript))
! 	loudbug_bug("widget_pushinits (instance)");
  }
  
! static void widget_pushconstructors(t_widget *x)
  {
      /* LATER master constructor */
      if (widgettype_isdefined(x->x_typedef))
      {
! 	int sz;
! 	if (widgettype_cevaluate(x->x_typedef, x->x_transient, 0,
! 				 0, 0, x->x_xargs))
! 	    scriptlet_push(x->x_transient);
! 	else if (*widgettype_getconstructor(x->x_typedef, &sz) && sz > 0)
! 	    loudbug_bug("widget_pushconstructors (type)");
      }
  }
  
! static void widget_pushdestructors(t_widget *x)
  {
      /* LATER master destructor */
      if (widgettype_isdefined(x->x_typedef))
      {
! 	int sz;
! 	if (widgettype_devaluate(x->x_typedef, x->x_transient, 0,
! 				 0, 0, x->x_xargs))
  	    scriptlet_push(x->x_transient);
! 	else if (*widgettype_getdestructor(x->x_typedef, &sz) && sz > 0)
! 	    loudbug_bug("widget_pushdestructors (type)");
      }
  }
  
--- 353,418 ----
  }
  
! static void widget_pushonehook(t_widget *x, t_scriptlet *sp, char *vname)
! {
!     if (scriptlet_evaluate(sp, x->x_transient, 0, 0, 0, x->x_xargs))
! 	scriptlet_vpush(x->x_transient, vname);
!     else if (!scriptlet_isempty(sp))
! 	loudbug_bug("widget_pushonehook (%s)", vname);
! }
! 
! static void widget_pushvishooks(t_widget *x)
  {
      if (widgettype_isdefined(x->x_typedef))
      {
! 	t_widgethandlers *wh = widgettype_getscripts(x->x_typedef);
! 	widget_pushonehook(x, widgethandlers_getvis(wh), "longvishook");
      }
!     widget_pushonehook(x, widgethandlers_getvis(x->x_hooks), "shortvishook");
  }
  
! static void widget_pushnewhooks(t_widget *x)
  {
      /* LATER master constructor */
      if (widgettype_isdefined(x->x_typedef))
      {
! 	t_widgethandlers *wh = widgettype_getscripts(x->x_typedef);
! 	widget_pushonehook(x, widgethandlers_getnew(wh), "longnewhook");
      }
+     widget_pushonehook(x, widgethandlers_getnew(x->x_hooks), "shortnewhook");
  }
  
! static void widget_pushfreehooks(t_widget *x)
  {
      /* LATER master destructor */
      if (widgettype_isdefined(x->x_typedef))
      {
! 	t_widgethandlers *wh = widgettype_getscripts(x->x_typedef);
! 	widget_pushonehook(x, widgethandlers_getfree(wh), "longfreehook");
!     }
!     widget_pushonehook(x, widgethandlers_getfree(x->x_hooks), "shortfreehook");
! }
! 
! static void widget_pushdatahooks(t_widget *x, int ac, t_atom *av)
! {
!     t_scriptlet *sp;
!     WIDGETPROFILE_HANDLER_ENTER;
!     if (!widgettype_isdefined(x->x_typedef)
! 	|| !(sp = widgethandlers_getdata(widgettype_getscripts(x->x_typedef)))
! 	|| scriptlet_isempty(sp))
! 	sp = widgethandlers_getdata(x->x_hooks);
!     if (sp)
!     {
! 	WIDGETPROFILE_HANDLER_EVAL;
! 	if (scriptlet_evaluate(sp, x->x_transient, 0, ac, av, x->x_xargs))
! 	{
! 	    WIDGETPROFILE_HANDLER_PUSH;
  	    scriptlet_push(x->x_transient);
! 	}
! 	else if (!scriptlet_isempty(sp))
! 	    loudbug_bug("widget_pushdatahooks (%s)",
! 			(sp == widgethandlers_getdata(x->x_hooks) ?
! 			 "short" : "long"));
      }
+     WIDGETPROFILE_HANDLER_QUIT;
  }
  
***************
*** 429,433 ****
  #endif
  	widget_pushoptions(x, 0);
! 	widget_pushinits(x);
  	sys_vgui("::toxy::item_vis %s %s %s %s %s %s %g %g\n",
  		 x->x_tkclass->s_name, mypathname,
--- 439,448 ----
  #endif
  	widget_pushoptions(x, 0);
! 	widget_pushvishooks(x);
! 	if (!x->x_constructed)
! 	{
! 	    widget_pushnewhooks(x);
! 	    x->x_constructed = 1;
! 	}
  	sys_vgui("::toxy::item_vis %s %s %s %s %s %s %g %g\n",
  		 x->x_tkclass->s_name, mypathname,
***************
*** 567,573 ****
  	props_diff(x->x_diffhandlers,
  		   widgettype_gethandlers(x->x_typedef), x->x_handlers);
! 	/* LATER cache handlers.
  	   We get here both during construction, and after any change
! 	   in our handlers -- the cache never stales. */
      }
      else if (op == x->x_arguments)
--- 582,591 ----
  	props_diff(x->x_diffhandlers,
  		   widgettype_gethandlers(x->x_typedef), x->x_handlers);
! 	/* This is the only point where mirroring of handlers is performed.
  	   We get here both during construction, and after any change
! 	   in our handlers -- the mirror never stales. */
! 	widgethandlers_reset(x->x_hooks);
! 	widgethandlers_fill(x->x_hooks, x->x_diffhandlers);
! 	widgethandlers_fill(x->x_hooks, x->x_handlers);
      }
      else if (op == x->x_arguments)
***************
*** 647,675 ****
  	else
  	{
! 	    /* LATER cache this */
! 	    int hlen;
! 	    t_atom *hp;
! 	    t_symbol *sel;
! 	    char buf[MAXPDSTRING];
  	    WIDGETPROFILE_HANDLER_ENTER;
! 	    buf[0] = '@';
! 	    strcpy(buf + 1, s->s_name);
! 	    sel = gensym(buf);
! 	    if (((hp = props_getone(x->x_handlers, sel, &hlen)) ||
! 		 (hp = props_getone(widgettype_gethandlers(x->x_typedef),
! 				    sel, &hlen)))
! 		&& hlen > 1)
  	    {
  		WIDGETPROFILE_HANDLER_EVAL;
! 		scriptlet_reset(x->x_auxscript);
! 		scriptlet_add(x->x_auxscript, 0, 0, hlen - 1, hp + 1);
! 		if (scriptlet_evaluate(x->x_auxscript, x->x_transient, 1,
! 				       ac, av, x->x_xargs))
  		{
  		    WIDGETPROFILE_HANDLER_PUSH;
  		    scriptlet_push(x->x_transient);
  		}
  	    }
! 	    else loud_nomethod((t_pd *)x, s);
  	    WIDGETPROFILE_HANDLER_QUIT;
  	}
--- 665,690 ----
  	else
  	{
! 	    /* FIXME use long defs too, cf widget_pushdatahooks() */
! 	    t_scriptlet *sp;
  	    WIDGETPROFILE_HANDLER_ENTER;
! 	    if (sp = widgethandlers_getother(x->x_hooks, s))
  	    {
  		WIDGETPROFILE_HANDLER_EVAL;
! 		if (scriptlet_evaluate(sp, x->x_transient,
! 				       1, ac, av, x->x_xargs))
  		{
  		    WIDGETPROFILE_HANDLER_PUSH;
  		    scriptlet_push(x->x_transient);
  		}
+ 		else if (!scriptlet_isempty(sp))
+ 		    loudbug_bug("widget_anything");
  	    }
! 	    else if (s == widgetps_vis || s == widgetps_new ||
! 		     s == widgetps_free || s == widgetps_data)
! 		loud_error((t_pd *)x,
! 			   "explicit call of the special handler \"%s\"",
! 			   s->s_name);
! 	    else
! 		loud_nomethod((t_pd *)x, s);
  	    WIDGETPROFILE_HANDLER_QUIT;
  	}
***************
*** 677,772 ****
  }
  
! /* LATER cache this */
  static void widget_bang(t_widget *x)
  {
!     int ac;
!     t_atom *av;
      WIDGETPROFILE_HANDLER_ENTER;
!     if ((av = props_getone(x->x_handlers, widgetps_atbang, &ac)) ||
! 	(av = props_getone(widgettype_gethandlers(x->x_typedef),
! 			   widgetps_atbang, &ac)))
      {
! 	if (ac > 1)
! 	{
! 	    WIDGETPROFILE_HANDLER_EVAL;
! 	    scriptlet_reset(x->x_transient);
! 	    scriptlet_add(x->x_transient, 1, 1, ac - 1, av + 1);
! 	    WIDGETPROFILE_HANDLER_PUSH;
! 	    scriptlet_push(x->x_transient);
! 	}
      }
      WIDGETPROFILE_HANDLER_QUIT;
  }
  
! /* LATER cache this */
  static void widget_float(t_widget *x, t_float f)
  {
!     int ac;
!     t_atom *av;
      WIDGETPROFILE_HANDLER_ENTER;
!     if ((av = props_getone(x->x_handlers, widgetps_atfloat, &ac)) ||
! 	(av = props_getone(widgettype_gethandlers(x->x_typedef),
! 			   widgetps_atfloat, &ac)))
      {
! 	if (ac > 1)
! 	{
! 	    t_atom at;
! 	    WIDGETPROFILE_HANDLER_EVAL;
! 	    SETFLOAT(&at, f);
! 	    scriptlet_reset(x->x_auxscript);
! 	    scriptlet_add(x->x_auxscript, 0, 0, ac - 1, av + 1);
! 	    if (scriptlet_evaluate(x->x_auxscript, x->x_transient, 1,
! 				   1, &at, x->x_xargs))
! 	    {
! 		WIDGETPROFILE_HANDLER_PUSH;
! 		scriptlet_push(x->x_transient);
! 	    }
! 	}
      }
      WIDGETPROFILE_HANDLER_QUIT;
  }
  
! /* LATER cache this */
  static void widget_symbol(t_widget *x, t_symbol *s)
  {
!     int ac;
!     t_atom *av;
      WIDGETPROFILE_HANDLER_ENTER;
!     if ((av = props_getone(x->x_handlers, widgetps_atsymbol, &ac)) ||
! 	(av = props_getone(widgettype_gethandlers(x->x_typedef),
! 			   widgetps_atsymbol, &ac)))
      {
! 	if (ac > 1)
! 	{
! 	    t_atom at;
! 	    WIDGETPROFILE_HANDLER_EVAL;
! 	    SETSYMBOL(&at, s);
! 	    scriptlet_reset(x->x_auxscript);
! 	    scriptlet_add(x->x_auxscript, 0, 0, ac - 1, av + 1);
! 	    if (scriptlet_evaluate(x->x_auxscript, x->x_transient, 1,
! 				   1, &at, x->x_xargs))
! 	    {
! 		WIDGETPROFILE_HANDLER_PUSH;
! 		scriptlet_push(x->x_transient);
! 	    }
! 	}
      }
      WIDGETPROFILE_HANDLER_QUIT;
  }
  
- static void widget_store(t_widget *x, t_symbol *s)
- {
-     if (s == &s_)
- 	s = x->x_varname;
-     /* FIXME */
- }
- 
- static void widget_restore(t_widget *x, t_symbol *s)
- {
-     if (s == &s_)
- 	s = x->x_varname;
-     /* FIXME */
- }
- 
  static void widget_set(t_widget *x, t_symbol *s, int ac, t_atom *av)
  {
--- 692,750 ----
  }
  
! /* FIXME use long defs too, cf widget_pushdatahooks() */
  static void widget_bang(t_widget *x)
  {
!     t_scriptlet *sp;
      WIDGETPROFILE_HANDLER_ENTER;
!     sp = widgethandlers_getbang(x->x_hooks);
!     WIDGETPROFILE_HANDLER_EVAL;
!     if (scriptlet_evaluate(sp, x->x_transient, 1, 0, 0, x->x_xargs))
      {
! 	WIDGETPROFILE_HANDLER_PUSH;
! 	scriptlet_push(x->x_transient);
      }
+     else if (!scriptlet_isempty(sp))
+ 	loudbug_bug("widget_bang");
      WIDGETPROFILE_HANDLER_QUIT;
  }
  
! /* FIXME use long defs too, cf widget_pushdatahooks() */
  static void widget_float(t_widget *x, t_float f)
  {
!     t_scriptlet *sp;
!     t_atom at;
      WIDGETPROFILE_HANDLER_ENTER;
!     sp = widgethandlers_getfloat(x->x_hooks);
!     WIDGETPROFILE_HANDLER_EVAL;
!     SETFLOAT(&at, f);
!     if (scriptlet_evaluate(sp, x->x_transient, 1, 1, &at, x->x_xargs))
      {
! 	WIDGETPROFILE_HANDLER_PUSH;
! 	scriptlet_push(x->x_transient);
      }
+     else if (!scriptlet_isempty(sp))
+ 	loudbug_bug("widget_float");
      WIDGETPROFILE_HANDLER_QUIT;
  }
  
! /* FIXME use long defs too, cf widget_pushdatahooks() */
  static void widget_symbol(t_widget *x, t_symbol *s)
  {
!     t_scriptlet *sp;
!     t_atom at;
      WIDGETPROFILE_HANDLER_ENTER;
!     sp = widgethandlers_getsymbol(x->x_hooks);
!     WIDGETPROFILE_HANDLER_EVAL;
!     SETSYMBOL(&at, s);
!     if (scriptlet_evaluate(sp, x->x_transient, 1, 1, &at, x->x_xargs))
      {
! 	WIDGETPROFILE_HANDLER_PUSH;
! 	scriptlet_push(x->x_transient);
      }
+     else if (!scriptlet_isempty(sp))
+ 	loudbug_bug("widget_symbol");
      WIDGETPROFILE_HANDLER_QUIT;
  }
  
  static void widget_set(t_widget *x, t_symbol *s, int ac, t_atom *av)
  {
***************
*** 817,828 ****
  }
  
- static void widget_ini(t_widget *x, t_symbol *s, int ac, t_atom *av)
- {
-     if (ac)
-     {
- 	scriptlet_reset(x->x_iniscript);
- 	scriptlet_add(x->x_iniscript, 0, 0, ac, av);
-     }
- }
  static void widget_tot(t_widget *x, t_symbol *s, int ac, t_atom *av)
  {
--- 795,798 ----
***************
*** 850,858 ****
  	wt == x->x_typedef)
      {
  	if (!(x->x_tkclass = widgettype_tkclass(x->x_typedef)))
  	    x->x_tkclass = x->x_type;
  	x->x_update = WIDGET_REVIS;
  	widget_update(x, x->x_arguments);
! 	widget_pushconstructors(x);
  	widget_update(x, x->x_handlers);
  	widget_update(x, x->x_options);
--- 820,829 ----
  	wt == x->x_typedef)
      {
+ 	widget_pushfreehooks(x);
  	if (!(x->x_tkclass = widgettype_tkclass(x->x_typedef)))
  	    x->x_tkclass = x->x_type;
  	x->x_update = WIDGET_REVIS;
  	widget_update(x, x->x_arguments);
! 	widget_pushnewhooks(x);
  	widget_update(x, x->x_handlers);
  	widget_update(x, x->x_options);
***************
*** 868,872 ****
  static void widget_redefine(t_widget *x)
  {
!     widget_resettype(x, widgettype_reload(x->x_type));
  }
  
--- 839,843 ----
  static void widget_redefine(t_widget *x)
  {
!     widget_resettype(x, widgettype_reload(x->x_type, x->x_glist));
  }
  
***************
*** 904,915 ****
  }
  
! static void widget__value(t_widget *x, t_symbol *s, int ac, t_atom *av)
  {
  #ifdef WIDGET_DEBUG
!     loudbug_startpost("value:");
      loudbug_postatom(ac, av);
      loudbug_endpost();
  #endif
!     /* FIXME */
  }
  
--- 875,909 ----
  }
  
! /* FIXME this is only a template */
! static void widget__data(t_widget *x, t_symbol *s, int ac, t_atom *av)
  {
  #ifdef WIDGET_DEBUG
!     loudbug_startpost("_data:");
      loudbug_postatom(ac, av);
      loudbug_endpost();
  #endif
!     if (ac && av->a_type == A_SYMBOL)
!     {
! 	s = av->a_w.w_symbol;
! 	if (s == widgetps_add)
! 	{
! 	    widget_pushdatahooks(x, ac, av);
! 	}
! 	else if (s == widgetps_delete)
! 	{
! 	    widget_pushdatahooks(x, ac, av);
! 	}
! 	else if (s == widgetps_set)
! 	{
! 	    widget_pushdatahooks(x, ac, av);
! 	}
! 	else if (s == widgetps_get)
! 	{
! 	    widget_pushdatahooks(x, ac, av);
! 	}
! 	else loud_error((t_pd *)x,
! 			"invalid \"_data\" subcommand \"%s\"", s->s_name);
!     }
!     else loud_error((t_pd *)x, "missing \"_data\" subcommand");
  }
  
***************
*** 1027,1030 ****
--- 1021,1025 ----
  static void widget_debug(t_widget *x)
  {
+     t_widgethandlers *wh = widgettype_getscripts(x->x_typedef);
      t_symbol *pn = widget_getcvpathname(x, 0);
      t_symbol *mn = widget_getmypathname(x, 0);
***************
*** 1061,1073 ****
      bp = scriptlet_getcontents(x->x_optscript, &sz);
      loudbug_post("option buffer (size %d):\n\"%s\"", sz, (bp ? bp : bempty));
!     bp = widgettype_getconstructor(x->x_typedef, &sz);
!     loudbug_post("type constructor (size %d):\n\"%s\"", sz, (bp ? bp : bempty));
!     bp = widgettype_getdestructor(x->x_typedef, &sz);
!     loudbug_post("type destructor (size %d):\n\"%s\"", sz, (bp ? bp : bempty));
!     bp = widgettype_getinitializer(x->x_typedef, &sz);
!     loudbug_post("type initializer (size %d):\n\"%s\"", sz, (bp ? bp : bempty));
!     bp = scriptlet_getcontents(x->x_iniscript, &sz);
!     loudbug_post("instance initializer (size %d):\n\"%s\"",
  		 sz, (bp ? bp : bempty));
      bp = masterwidget_getcontents(&sz);
      loudbug_post("setup definitions (size %d):\n\"%s\"",
--- 1056,1073 ----
      bp = scriptlet_getcontents(x->x_optscript, &sz);
      loudbug_post("option buffer (size %d):\n\"%s\"", sz, (bp ? bp : bempty));
! 
!     bp = scriptlet_getcontents(widgethandlers_getnew(wh), &sz);
!     loudbug_post("long newhook (size %d):\n\"%s\"", sz, (bp ? bp : bempty));
!     bp = scriptlet_getcontents(widgethandlers_getfree(wh), &sz);
!     loudbug_post("long freehook (size %d):\n\"%s\"", sz, (bp ? bp : bempty));
!     bp = scriptlet_getcontents(widgethandlers_getdata(wh), &sz);
!     loudbug_post("long datahook (size %d):\n\"%s\"", sz, (bp ? bp : bempty));
! 
!     bp = scriptlet_getcontents(widgethandlers_getvis(wh), &sz);
!     loudbug_post("long vishook (size %d):\n\"%s\"", sz, (bp ? bp : bempty));
!     bp = scriptlet_getcontents(widgethandlers_getvis(x->x_hooks), &sz);
!     loudbug_post("short vishook (size %d):\n\"%s\"",
  		 sz, (bp ? bp : bempty));
+ 
      bp = masterwidget_getcontents(&sz);
      loudbug_post("setup definitions (size %d):\n\"%s\"",
***************
*** 1090,1100 ****
  {
      widget_novis(x);
!     widget_pushdestructors(x);
      gui_unbind((t_pd *)x, x->x_cbtarget);
      gui_unbind((t_pd *)x, x->x_rptarget);
      props_freeall(x->x_options);
      props_freeall(x->x_xargs);
      props_freeall(x->x_diffoptions);
-     scriptlet_free(x->x_iniscript);
      scriptlet_free(x->x_optscript);
      scriptlet_free(x->x_auxscript);
--- 1090,1100 ----
  {
      widget_novis(x);
!     widget_pushfreehooks(x);
      gui_unbind((t_pd *)x, x->x_cbtarget);
      gui_unbind((t_pd *)x, x->x_rptarget);
+     widgethandlers_free(x->x_hooks);
      props_freeall(x->x_options);
      props_freeall(x->x_xargs);
      props_freeall(x->x_diffoptions);
      scriptlet_free(x->x_optscript);
      scriptlet_free(x->x_auxscript);
***************
*** 1141,1145 ****
  
      x->x_glist = canvas_getcurrent();
!     x->x_typedef = widgettype_get(x->x_type);
      if (!(x->x_tkclass = widgettype_tkclass(x->x_typedef)))
  	x->x_tkclass = x->x_type;
--- 1141,1145 ----
  
      x->x_glist = canvas_getcurrent();
!     x->x_typedef = widgettype_get(x->x_type, 0, 0, x->x_glist);
      if (!(x->x_tkclass = widgettype_tkclass(x->x_typedef)))
  	x->x_tkclass = x->x_type;
***************
*** 1152,1163 ****
      x->x_varname = gensym(buf);
  
-     x->x_iniscript = scriptlet_new((t_pd *)x, x->x_rptarget, x->x_cbtarget,
- 				   x->x_name, x->x_glist, widget_cvhook);
-     x->x_optscript = scriptlet_new((t_pd *)x, x->x_rptarget, x->x_cbtarget,
- 				   x->x_name, x->x_glist, widget_cvhook);
      x->x_auxscript = scriptlet_new((t_pd *)x, x->x_rptarget, x->x_cbtarget,
  				   x->x_name, x->x_glist, widget_cvhook);
!     x->x_transient = scriptlet_new((t_pd *)x, x->x_rptarget, x->x_cbtarget,
! 				   x->x_name, x->x_glist, widget_cvhook);
  
      x->x_options = props_new((t_pd *)x, "option", "-", 0, 0);
--- 1152,1159 ----
      x->x_varname = gensym(buf);
  
      x->x_auxscript = scriptlet_new((t_pd *)x, x->x_rptarget, x->x_cbtarget,
  				   x->x_name, x->x_glist, widget_cvhook);
!     x->x_transient = scriptlet_newalike(x->x_auxscript);
!     x->x_optscript = scriptlet_newalike(x->x_auxscript);
  
      x->x_options = props_new((t_pd *)x, "option", "-", 0, 0);
***************
*** 1171,1174 ****
--- 1167,1172 ----
  				   x->x_diffoptions, 0);
  
+     x->x_hooks = widgethandlers_new(x->x_auxscript);
+ 
      outlet_new((t_object *)x, &s_anything);
      /* LATER consider estimating these, based on widget class and options.
***************
*** 1187,1191 ****
      widget_attach(x);
      widget_addmessage(x, 0, 0, ac, av);
!     widget_pushconstructors(x);
      return (x);
  }
--- 1185,1189 ----
      widget_attach(x);
      widget_addmessage(x, 0, 0, ac, av);
!     x->x_constructed = 0;
      return (x);
  }
***************
*** 1350,1354 ****
  static void tow_redefine(t_tow *x)
  {
!     t_widgettype *wt = widgettype_reload(x->x_type);
      t_widgetentry *we;
      for (we = x->x_widgetlist; we; we = we->we_next)
--- 1348,1352 ----
  static void tow_redefine(t_tow *x)
  {
!     t_widgettype *wt = widgettype_reload(x->x_type, x->x_glist);
      t_widgetentry *we;
      for (we = x->x_widgetlist; we; we = we->we_next)
***************
*** 1496,1504 ****
      widgetps_mouse = gensym("mouse");
      widgetps_motion = gensym("motion");
!     widgetps_atbang = gensym("@bang");
!     widgetps_atfloat = gensym("@float");
!     widgetps_atsymbol = gensym("@symbol");
!     widgetps_atstore = gensym("@store");
!     widgetps_atrestore = gensym("@restore");
      widgettype_setup();
      widget_class = class_new(gensym("widget"),
--- 1494,1505 ----
      widgetps_mouse = gensym("mouse");
      widgetps_motion = gensym("motion");
!     widgetps_vis = gensym("vis");
!     widgetps_new = gensym("new");
!     widgetps_free = gensym("free");
!     widgetps_data = gensym("data");
!     widgetps_add = gensym("add");
!     widgetps_delete = gensym("delete");
!     widgetps_set = gensym("set");
!     widgetps_get = gensym("get");
      widgettype_setup();
      widget_class = class_new(gensym("widget"),
***************
*** 1513,1526 ****
      class_addsymbol(widget_class, widget_symbol);
      class_addanything(widget_class, widget_anything);
-     class_addmethod(widget_class, (t_method)widget_store,
- 		    gensym("store"), A_DEFSYMBOL, 0);
-     class_addmethod(widget_class, (t_method)widget_restore,
- 		    gensym("restore"), A_DEFSYMBOL, 0);
      class_addmethod(widget_class, (t_method)widget_set,
  		    gensym("set"), A_GIMME, 0);
      class_addmethod(widget_class, (t_method)widget_remove,
  		    gensym("remove"), A_SYMBOL, 0);
-     class_addmethod(widget_class, (t_method)widget_ini,
- 		    gensym("ini"), A_GIMME, 0);
      class_addmethod(widget_class, (t_method)widget_tot,
  		    gensym("tot"), A_GIMME, 0);
--- 1514,1521 ----
***************
*** 1534,1539 ****
  		    gensym("_config"),
  		    A_SYMBOL, A_SYMBOL, A_FLOAT, A_FLOAT, A_FLOAT, 0);
!     class_addmethod(widget_class, (t_method)widget__value,
! 		    gensym("_value"), A_GIMME, 0);
      class_addmethod(widget_class, (t_method)widget__callback,
  		    gensym("_cb"), A_GIMME, 0);
--- 1529,1534 ----
  		    gensym("_config"),
  		    A_SYMBOL, A_SYMBOL, A_FLOAT, A_FLOAT, A_FLOAT, 0);
!     class_addmethod(widget_class, (t_method)widget__data,
! 		    gensym("_data"), A_GIMME, 0);
      class_addmethod(widget_class, (t_method)widget__callback,
  		    gensym("_cb"), A_GIMME, 0);





More information about the Pd-cvs mailing list