From d5a39ff6469f8762218c00a34f4b0a120a56332b Mon Sep 17 00:00:00 2001 From: "N.N." Date: Wed, 8 Dec 2004 15:40:14 +0000 Subject: various bug-fixes, maxmode, toxy .#args svn path=/trunk/externals/miXed/; revision=2360 --- toxy/Makefile | 1 + toxy/plustot.print.c | 12 ++-- toxy/widget.c | 189 +++++++++++++++++++++++++++++++++++++++------------ toxy/widgettype.c | 87 +++++++++++++++++++----- toxy/widgettype.h | 21 ++++-- 5 files changed, 238 insertions(+), 72 deletions(-) (limited to 'toxy') diff --git a/toxy/Makefile b/toxy/Makefile index 3035cb4..cd9cd5a 100644 --- a/toxy/Makefile +++ b/toxy/Makefile @@ -8,6 +8,7 @@ checkwiq: rm -f $(WIQFILE) ; fi $(WIQFILE): $(WIDPATH) @echo transferring widget definitions from \"$<\" to \"$@\" +# LATER think how to replace puts with pdtk_post @echo -e '// Do not edit this file (edit "$<", and run "make").\ \n//\nputs stderr [concat loading built-in widget definitions]' \ | cat - $< | sed \ diff --git a/toxy/plustot.print.c b/toxy/plustot.print.c index 42ef385..0bd6357 100644 --- a/toxy/plustot.print.c +++ b/toxy/plustot.print.c @@ -16,6 +16,11 @@ typedef struct _plustot_print static t_class *plustot_print_class; +static char *plustot_print_symbolname(t_symbol *s) +{ + return (s && s != &s_ ? s->s_name : "???"); +} + static void plustot_print_symbol(t_plustot_print *x, t_symbol *s) { Tcl_Obj *ob = plustag_tobvalue(s, (t_pd *)x); @@ -36,10 +41,9 @@ static void plustot_print_symbol(t_plustot_print *x, t_symbol *s) t_atom *av = binbuf_getvec(x->x_bb); if (av->a_type == A_SYMBOL || av->a_type == A_FLOAT) { - char *lstring = - (x->x_label ? x->x_label->s_name : - loud_symbolname(plustag_typename(s, 1, (t_pd *)x), - "???")); + char *lstring = (x->x_label ? x->x_label->s_name : + plustot_print_symbolname( + plustag_typename(s, 1, (t_pd *)x))); if (glname) startpost("%s (%s):", lstring, glname->s_name); else diff --git a/toxy/widget.c b/toxy/widget.c index d544145..7bfbb74 100644 --- a/toxy/widget.c +++ b/toxy/widget.c @@ -2,8 +2,6 @@ * For information on usage and redistribution, and for a DISCLAIMER OF ALL * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ -/* LATER consider supporting a special @ini handler, also think about - differentiating 'ini' from 'vis' */ /* LATER think about reloading method for .wid files */ #include @@ -39,6 +37,18 @@ typedef struct _widgetentry struct _widgetentry *we_next; } 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 { t_object x_ob; @@ -55,6 +65,7 @@ typedef struct _widget t_props *x_options; /* instance options */ t_props *x_handlers; /* instance handlers */ t_props *x_arguments; /* instance 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 */ @@ -145,18 +156,35 @@ static t_symbol *widget_getmypathname(t_widget *x, t_glist *glist) return (gensym(buf)); } -static void widget_postatoms(char *msg, int ac, t_atom *av) +/* pity cannot set sys_printtostderr... */ +static void widget_postatoms(FILE *fp, char *msg, int ac, t_atom *av) { - startpost(msg); - while (ac--) + if (fp) { - if (av->a_type == A_FLOAT) - postfloat(av->a_w.w_float); - else if (av->a_type == A_SYMBOL) - poststring(av->a_w.w_symbol->s_name); - av++; + fputs(msg, fp); + while (ac--) + { + char buf[80]; + atom_string(av, buf, 80); + fputc(' ', fp); + fputs(buf, fp); + av++; + } + fputc('\n', fp); + } + else + { + startpost(msg); + while (ac--) + { + if (av->a_type == A_FLOAT) + postfloat(av->a_w.w_float); + else if (av->a_type == A_SYMBOL) + poststring(av->a_w.w_symbol->s_name); + av++; + } + endpost(); } - endpost(); } /* If Tk widget creation fails, gui will send the '_failure' message @@ -292,26 +320,54 @@ static void widget_pushoptions(t_widget *x, int doit) static void widget_pushinits(t_widget *x) { - if (masterwidget_evaluate(x->x_transient, 0, 0, 0, x->x_arguments)) - scriptlet_vpush(x->x_transient, "masterinits"); + if (masterwidget_ievaluate(x->x_transient, 0, 0, 0, x->x_arguments)) + scriptlet_vpush(x->x_transient, "masterinit"); else bug("widget_pushinits (master)"); if (widgettype_isdefined(x->x_typedef)) { int sz; - if (widgettype_evaluate(x->x_typedef, x->x_transient, 0, - 0, 0, x->x_arguments)) - scriptlet_vpush(x->x_transient, "typeinits"); - else if (*widgettype_getcontents(x->x_typedef, &sz) && sz > 0) + if (widgettype_ievaluate(x->x_typedef, x->x_transient, 0, + 0, 0, x->x_arguments)) + scriptlet_vpush(x->x_transient, "typeinit"); + else if (*widgettype_getinitializer(x->x_typedef, &sz) && sz > 0) bug("widget_pushinits (type)"); } if (scriptlet_evaluate(x->x_iniscript, x->x_transient, 0, 0, 0, x->x_arguments)) - scriptlet_vpush(x->x_transient, "iteminits"); + scriptlet_vpush(x->x_transient, "iteminit"); else if (!scriptlet_isempty(x->x_iniscript)) 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_arguments)) + scriptlet_push(x->x_transient); + else if (*widgettype_getconstructor(x->x_typedef, &sz) && sz > 0) + 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_arguments)) + scriptlet_push(x->x_transient); + else if (*widgettype_getdestructor(x->x_typedef, &sz) && sz > 0) + bug("widget_pushdestructors (type)"); + } +} + static void widget_getconfig(t_widget *x) { sys_vgui("::toxy::item_getconfig %s %s\n", @@ -465,7 +521,9 @@ static void widget_update(t_widget *x, t_props *op) } else { - /* LATER cache handlers */ + /* LATER cache handlers. + We get here both during construction, and after any change + in our handlers -- the cache never stales. */ } } @@ -697,7 +755,7 @@ static void widget_refresh(t_widget *x) static void widget__failure(t_widget *x, t_symbol *s, int ac, t_atom *av) { #if 0 - /* moved to the gui side, in order to alow special chars in error message */ + /* moved to the gui side -- supporting special chars in error message */ startpost("tcl error:"); postatom(ac, av); endpost(); @@ -839,39 +897,56 @@ static void widget_debug(t_widget *x) t_symbol *mn = widget_getmypathname(x, 0); int sz, i, nopt; t_atom *ap; + static char bempty[] = ""; char *bp, *key; - post("containing glist: %x", x->x_glist); - post("cv pathname%s %s", (pn ? ":" : ""), (pn ? pn->s_name : "unknown")); - post("my pathname%s %s", (mn ? ":" : ""), (mn ? mn->s_name : "unknown")); + fprintf(stderr, "containing glist: %x\n", (int)x->x_glist); + fprintf(stderr, "cv pathname%s %s\n", + (pn ? ":" : ""), (pn ? pn->s_name : "unknown")); + fprintf(stderr, "my pathname%s %s\n", + (mn ? ":" : ""), (mn ? mn->s_name : "unknown")); if (ap = props_getall(widgettype_getoptions(x->x_typedef), &nopt)) - widget_postatoms("default options:", nopt, ap); + widget_postatoms(stderr, "default options:", nopt, ap); if (ap = props_getall(x->x_options, &nopt)) - widget_postatoms("instance options:", nopt, ap); + widget_postatoms(stderr, "instance options:", nopt, ap); if (ap = props_getall(widgettype_gethandlers(x->x_typedef), &nopt)) - widget_postatoms("default handlers:", nopt, ap); + widget_postatoms(stderr, "default handlers:", nopt, ap); if (ap = props_getall(x->x_handlers, &nopt)) - widget_postatoms("instance handlers:", nopt, ap); + widget_postatoms(stderr, "instance handlers:", nopt, ap); if (ap = props_getall(widgettype_getarguments(x->x_typedef), &nopt)) - widget_postatoms("default arguments:", nopt, ap); + widget_postatoms(stderr, "default arguments:", nopt, ap); if (ap = props_getall(x->x_arguments, &nopt)) - widget_postatoms("instance arguments:", nopt, ap); - post("dictionary:"); + widget_postatoms(stderr, "instance arguments:", nopt, ap); + fprintf(stderr, "dictionary:\n"); bp = props_firstvalue(x->x_arguments, &key); while (bp) { - post("\t%s: \"%s\"", key, bp); + fprintf(stderr, "\t%s: \"%s\"\n", key, bp); bp = props_nextvalue(x->x_arguments, &key); } bp = scriptlet_getcontents(x->x_transient, &sz); - post("transient buffer (size %d):\n\"%s\"", sz, bp); + fprintf(stderr, "transient buffer (size %d):\n\"%s\"\n", + sz, (bp ? bp : bempty)); bp = scriptlet_getcontents(x->x_optscript, &sz); - post("option buffer (size %d):\n\"%s\"", sz, bp); - bp = widgettype_getcontents(x->x_typedef, &sz); - post("type initializer (size %d):\n\"%s\"", sz, bp); + fprintf(stderr, "option buffer (size %d):\n\"%s\"\n", + sz, (bp ? bp : bempty)); + bp = widgettype_getconstructor(x->x_typedef, &sz); + fprintf(stderr, "type constructor (size %d):\n\"%s\"\n", + sz, (bp ? bp : bempty)); + bp = widgettype_getdestructor(x->x_typedef, &sz); + fprintf(stderr, "type destructor (size %d):\n\"%s\"\n", + sz, (bp ? bp : bempty)); + bp = masterwidget_getinitializer(&sz); + fprintf(stderr, "master initializer (size %d):\n\"%s\"\n", + sz, (bp ? bp : bempty)); + bp = widgettype_getinitializer(x->x_typedef, &sz); + fprintf(stderr, "type initializer (size %d):\n\"%s\"\n", + sz, (bp ? bp : bempty)); bp = scriptlet_getcontents(x->x_iniscript, &sz); - post("instance initializer (size %d):\n\"%s\"", sz, bp); + fprintf(stderr, "instance initializer (size %d):\n\"%s\"\n", + sz, (bp ? bp : bempty)); bp = masterwidget_getcontents(&sz); - post("setup definitions (size %d):\n\"%s\"", sz, bp); + fprintf(stderr, "setup definitions (size %d):\n\"%s\"\n", + sz, (bp ? bp : bempty)); } #endif @@ -889,6 +964,7 @@ static void gui_unbind(t_pd *x, t_symbol *s) static void widget_free(t_widget *x) { 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); @@ -907,7 +983,7 @@ static void *widget_new(t_symbol *s, int ac, t_atom *av) char buf[MAXPDSTRING]; if (widget_transforming) return (0); - masterwidget_initialize(); + masterwidget_validate(); x = (t_widget *)pd_new(widget_class); x->x_type = 0; x->x_name = 0; @@ -978,6 +1054,7 @@ static void *widget_new(t_symbol *s, int ac, t_atom *av) x->x_disabled = 0; x->x_vised = 0; widget_attach(x); + widget_pushconstructors(x); return (x); } @@ -988,7 +1065,7 @@ static t_glist *tow_getglist(t_tow *x, int complain) (t_glist *)pd_findbyclass(x->x_cvremote, canvas_class) : x->x_glist); if (!glist && complain) loud_error((t_pd *)x, "bad canvas name '%s'", x->x_cvname->s_name); - return (glist); + return (glist_getcanvas(glist)); } static void tow_bang(t_tow *x) @@ -1160,20 +1237,22 @@ static void tow_detach(t_tow *x) static void tow_debug(t_tow *x) { t_widgetentry *we; - post("attached widgets:"); + fprintf(stderr, "attached widgets:\n"); for (we = x->x_widgetlist; we; we = we->we_next) { t_widget *w = we->we_widget; t_towentry *te; int other = 0, found = 0; - startpost("\t%s %s", w->x_type->s_name, w->x_cbtarget->s_name); + fprintf(stderr, "\t%s %s", w->x_type->s_name, w->x_cbtarget->s_name); for (te = w->x_towlist; te; te = te->te_next) if (te->te_tow == x) found++; else other++; - post(" (%d other tow%s)", other, (other == 1 ? "" : "s")); - if (found != 1) post("BUG: listed %d times in widget's towlist", found); + fprintf(stderr, " (%d other tow%s)\n", other, (other == 1 ? "" : "s")); + if (found != 1) + fprintf(stderr, "BUG: listed %d times in widget's towlist\n", + found); } } #endif @@ -1207,8 +1286,28 @@ static void *tow_new(t_symbol *s1, t_symbol *s2, t_symbol *s3) t_tow *x = (t_tow *)pd_new(tow_class); char buf[64]; x->x_glist = canvas_getcurrent(); - if (s1 && s1 != &s_ && strcmp(s1->s_name, ".")) - x->x_cvremote = canvas_makebindsym(x->x_cvname = s1); + if (s1 == &s_ || !strcmp(s1->s_name, ".")) + s1 = 0; + if (s1) + { + if (strcmp(s1->s_name, ".parent")) + x->x_cvremote = canvas_makebindsym(x->x_cvname = s1); + else + { + if (x->x_glist->gl_owner) + { + x->x_glist = x->x_glist->gl_owner; + x->x_cvremote = 0; + x->x_cvname = x->x_glist->gl_name; + } + else + { + /* FIXME */ + loud_error((t_pd *)x, "no parent patch"); + x->x_cvremote = canvas_makebindsym(x->x_cvname = s1); + } + } + } else { x->x_cvremote = 0; diff --git a/toxy/widgettype.c b/toxy/widgettype.c index 3cb7d6e..0b8163f 100644 --- a/toxy/widgettype.c +++ b/toxy/widgettype.c @@ -16,7 +16,7 @@ static char masterwidget_builtin[] = ; #define WIDGETTYPE_VERBOSE -//#define WIDGETTYPE_DEBUG +#define WIDGETTYPE_DEBUG struct _widgettype { @@ -28,6 +28,8 @@ struct _widgettype t_props *wt_handlers; t_props *wt_arguments; t_scriptlet *wt_iniscript; + t_scriptlet *wt_newscript; + t_scriptlet *wt_freescript; }; struct _masterwidget @@ -36,7 +38,7 @@ struct _masterwidget t_symbol *mw_target; t_scriptlet *mw_setupscript; t_dict *mw_typemap; - t_widgettype *mw_mastertype; /* contains master iniscript */ + t_widgettype *mw_mastertype; /* contains master initializer */ t_widgettype *mw_parsedtype; /* the type currently parsed, if loading */ t_binbuf *mw_bb; /* auxiliary, LATER remove */ }; @@ -68,6 +70,10 @@ static t_widgettype *widgettype_new(t_masterwidget *mw, 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); } @@ -93,7 +99,7 @@ static t_scriptlet *masterwidget_cmnthook(t_pd *caller, char *rc, if (!cls) cls = buf; typekey = dict_key(mw->mw_typemap, buf); - typeval = (t_widgettype *)dict_value(mw->mw_typemap, typekey); + typeval = (t_widgettype *)dict_firstvalue(mw->mw_typemap, typekey, 0); if (caller == (t_pd *)mw) { /* setup.wid or built-in defaults */ if (mw->mw_mastertype) @@ -162,6 +168,24 @@ static t_scriptlet *masterwidget_cmnthook(t_pd *caller, char *rc, } } } + else if (sel == '@') + { /* multiline definition of a handler */ + scriptlet_nextword(buf); + if (mw->mw_parsedtype) + { + if (!strcmp(buf, "vis") || !strcmp(buf, "ini")) + return (mw->mw_parsedtype->wt_iniscript); + else if (!strcmp(buf, "new")) + return (mw->mw_parsedtype->wt_newscript); + else if (!strcmp(buf, "free")) + return (mw->mw_parsedtype->wt_freescript); + else + { + /* LATER start parsing any method handler: search for it, + create if not found, return */ + } + } + } return (SCRIPTLET_UNLOCK); } @@ -170,9 +194,9 @@ t_widgettype *widgettype_get(t_symbol *s) t_widgettype *wt; /* Design decision: setup.wid defs are NOT overridden by .wid (sacrificing flexibility for feature stability). */ - if (wt = (t_widgettype *)dict_value(masterwidget->mw_typemap, - dict_key(masterwidget->mw_typemap, - s->s_name))) + if (wt = (t_widgettype *)dict_firstvalue(masterwidget->mw_typemap, + dict_key(masterwidget->mw_typemap, + s->s_name), 0)) masterwidget->mw_parsedtype = 0; else { @@ -193,7 +217,7 @@ t_widgettype *widgettype_get(t_symbol *s) == SCRIPTLET_OK) { #ifdef WIDGETTYPE_VERBOSE - post("using %s's initializer", s->s_name); + post("using a separate %s's definition file", s->s_name); #endif if (!scriptlet_isempty(mwsp)) { @@ -239,18 +263,42 @@ t_props *widgettype_getarguments(t_widgettype *wt) return (wt->wt_arguments); } -char *widgettype_getcontents(t_widgettype *wt, int *szp) +char *widgettype_getinitializer(t_widgettype *wt, int *szp) { return (scriptlet_getcontents(wt->wt_iniscript, szp)); } -int widgettype_evaluate(t_widgettype *wt, t_scriptlet *outsp, - int visedonly, int ac, t_atom *av, t_props *argprops) +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)); +} + void widgettype_setup(void) { static int done = 0; @@ -264,11 +312,10 @@ void widgettype_setup(void) } } -int masterwidget_evaluate(t_scriptlet *outsp, int visedonly, - int ac, t_atom *av, t_props *argprops) +char *masterwidget_getinitializer(int *szp) { - return (scriptlet_evaluate(masterwidget->mw_mastertype->wt_iniscript, - outsp, visedonly, ac, av, argprops)); + return (scriptlet_getcontents(masterwidget->mw_mastertype->wt_iniscript, + szp)); } char *masterwidget_getcontents(int *szp) @@ -276,7 +323,14 @@ char *masterwidget_getcontents(int *szp) return (scriptlet_getcontents(masterwidget->mw_setupscript, szp)); } -void masterwidget_initialize(void) +int masterwidget_ievaluate(t_scriptlet *outsp, int visedonly, + int ac, t_atom *av, t_props *argprops) +{ + return (scriptlet_evaluate(masterwidget->mw_mastertype->wt_iniscript, + outsp, visedonly, ac, av, argprops)); +} + +void masterwidget_validate(void) { int rcresult; t_symbol *typekey; @@ -315,7 +369,8 @@ void masterwidget_initialize(void) "no file 'setup.wid'... using built-in defaults"); } typekey = dict_key(masterwidget->mw_typemap, "master"); - if ((typeval = (t_widgettype *)dict_value(masterwidget->mw_typemap, typekey)) + if ((typeval = (t_widgettype *)dict_firstvalue(masterwidget->mw_typemap, + typekey, 0)) && !scriptlet_isempty(masterwidget->mw_setupscript)) { masterwidget->mw_mastertype = typeval; diff --git a/toxy/widgettype.h b/toxy/widgettype.h index d0df8c6..4894d00 100644 --- a/toxy/widgettype.h +++ b/toxy/widgettype.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2003 krzYszcz and others. +/* Copyright (c) 2003-2004 krzYszcz and others. * For information on usage and redistribution, and for a DISCLAIMER OF ALL * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ @@ -18,14 +18,21 @@ t_props *widgettype_getoptions(t_widgettype *wt); t_props *widgettype_gethandlers(t_widgettype *wt); t_props *widgettype_getarguments(t_widgettype *wt); char *widgettype_propname(t_symbol *s); -char *widgettype_getcontents(t_widgettype *wt, int *szp); -int widgettype_evaluate(t_widgettype *wt, t_scriptlet *outsp, - int visedonly, int ac, t_atom *av, t_props *argprops); +char *widgettype_getinitializer(t_widgettype *wt, int *szp); +char *widgettype_getconstructor(t_widgettype *wt, int *szp); +char *widgettype_getdestructor(t_widgettype *wt, int *szp); +int widgettype_ievaluate(t_widgettype *wt, t_scriptlet *outsp, + int visedonly, int ac, t_atom *av, t_props *argprops); +int widgettype_cevaluate(t_widgettype *wt, t_scriptlet *outsp, + int visedonly, int ac, t_atom *av, t_props *argprops); +int widgettype_devaluate(t_widgettype *wt, t_scriptlet *outsp, + int visedonly, int ac, t_atom *av, t_props *argprops); void widgettype_setup(void); +char *masterwidget_getinitializer(int *szp); char *masterwidget_getcontents(int *szp); -int masterwidget_evaluate(t_scriptlet *outsp, int visedonly, - int ac, t_atom *av, t_props *argprops); -void masterwidget_initialize(void); +int masterwidget_ievaluate(t_scriptlet *outsp, int visedonly, + int ac, t_atom *av, t_props *argprops); +void masterwidget_validate(void); #endif -- cgit v1.2.1