diff options
author | N.N. <krzyszcz@users.sourceforge.net> | 2004-03-29 17:09:53 +0000 |
---|---|---|
committer | N.N. <krzyszcz@users.sourceforge.net> | 2004-03-29 17:09:53 +0000 |
commit | 14b05069b61d8d86d52415acb1adea7a61547ac6 (patch) | |
tree | c1a5e683b309349d4c261476154897fba6c0578b | |
parent | 6f0f6fb5c0fe8ab2548c84a65fb6d1ee9363e317 (diff) |
toxy alpha10
svn path=/trunk/externals/miXed/; revision=1502
-rw-r--r-- | shared/common/port.c | 6 | ||||
-rw-r--r-- | shared/hammer/gui.c | 25 | ||||
-rw-r--r-- | shared/toxy/scriptlet.c | 47 | ||||
-rw-r--r-- | shared/unstable/fringe.c | 12 | ||||
-rw-r--r-- | test/toxy/tot-query.pd | 8 | ||||
-rw-r--r-- | toxy/Makefile | 9 | ||||
-rw-r--r-- | toxy/build_counter | 2 | ||||
-rw-r--r-- | toxy/tot.c | 113 |
8 files changed, 182 insertions, 40 deletions
diff --git a/shared/common/port.c b/shared/common/port.c index fa81bc0..26f24ca 100644 --- a/shared/common/port.c +++ b/shared/common/port.c @@ -35,7 +35,13 @@ enum { PORT_OK, PORT_NEXT, /* next line, please */ PORT_UNKNOWN, PORT_CORRUPT, PORT_FATAL }; +/* without access to sys_defaultfont, we just mimic defs from s_main.c */ +#ifdef MSW +#define PORT_DEFFONTSIZE 12. +#else #define PORT_DEFFONTSIZE 10. +#endif + #define PORT_XSTRETCH 1.25 #define PORT_YSTRETCH 1.1 #define PORT_WSTRETCH 1.25 diff --git a/shared/hammer/gui.c b/shared/hammer/gui.c index 5e98ff8..131ddfe 100644 --- a/shared/hammer/gui.c +++ b/shared/hammer/gui.c @@ -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. */ @@ -131,9 +131,11 @@ static void hammergui__remouse(t_hammergui *snk) static void hammergui_dobindfocus(t_hammergui *snk) { sys_vgui("bind Canvas <<hammerfocusin>> \ - {pd [concat %s _focus %%W 1 \\;]}\n", snk->g_gui->s_name); + {if {[hammergui_ispatcher %%W]} \ + {pd [concat %s _focus %%W 1 \\;]}}\n", snk->g_gui->s_name); sys_vgui("bind Canvas <<hammerfocusout>> \ - {pd [concat %s _focus %%W 0 \\;]}\n", snk->g_gui->s_name); + {if {[hammergui_ispatcher %%W]} \ + {pd [concat %s _focus %%W 0 \\;]}}\n", snk->g_gui->s_name); } static void hammergui__refocus(t_hammergui *snk) @@ -152,9 +154,11 @@ static void hammergui__refocus(t_hammergui *snk) static void hammergui_dobindvised(t_hammergui *snk) { sys_vgui("bind Canvas <<hammervised>> \ - {pd [concat %s _vised %%W 1 \\;]}\n", snk->g_gui->s_name); + {if {[hammergui_ispatcher %%W]} \ + {pd [concat %s _vised %%W 1 \\;]}}\n", snk->g_gui->s_name); sys_vgui("bind Canvas <<hammerunvised>> \ - {pd [concat %s _vised %%W 0 \\;]}\n", snk->g_gui->s_name); + {if {[hammergui_ispatcher %%W]} \ + {pd [concat %s _vised %%W 0 \\;]}}\n", snk->g_gui->s_name); } static void hammergui__revised(t_hammergui *snk) @@ -192,6 +196,17 @@ static void hammergui_setup(void) class_addmethod(hammergui_class, (t_method)hammergui__vised, ps__vised, A_SYMBOL, A_FLOAT, 0); + /* Protect against pdCmd being called (via "Canvas <Destroy>" binding) + during Tcl_Finalize(). FIXME this should be a standard exit handler. */ + sys_gui("proc hammergui_exithook {cmd op} {proc pd {} {}}\n"); + sys_gui("trace add execution exit enter hammergui_exithook\n"); + + sys_gui("proc hammergui_ispatcher {cv} {\n"); + sys_gui(" if {[string range $cv 0 1] == \".x\""); + sys_gui(" && [string range $cv end-1 end] == \".c\"} {\n"); + sys_gui(" return 1} else {return 0}\n"); + sys_gui("}\n"); + sys_gui("proc hammergui_remouse {} {\n"); sys_gui(" bind all <<hammerdown>> {}\n"); sys_gui(" bind all <<hammerup>> {}\n"); diff --git a/shared/toxy/scriptlet.c b/shared/toxy/scriptlet.c index f7ce800..a2f5ee0 100644 --- a/shared/toxy/scriptlet.c +++ b/shared/toxy/scriptlet.c @@ -200,30 +200,56 @@ static char *scriptlet_dedot(t_scriptlet *sp, char *ibuf, char *obuf, t_canvas *cv; if (cv = scriptlet_canvasvalidate(sp, 0)) { + t_glist *glist; if (!strncmp(&ibuf[1], "tag", 3)) { t_rtext *rt; - if (cv->gl_owner && glist_isvisible(cv->gl_owner) && - cv->gl_owner->gl_editor && - (rt = glist_findrtext(cv->gl_owner, (t_object *)cv))) + glist = cv->gl_owner; + if (glist && glist_isvisible(glist) && glist->gl_editor + && (rt = glist_findrtext(glist, (t_object *)cv))) sprintf(obuf, "%s", rtext_gettag(rt)); else obuf[0] = 0; len = 4; } - else if (!strncmp(&ibuf[1], "owner", 5)) + else if (!strncmp(&ibuf[1], "parent", 6)) { - if (cv->gl_owner && glist_isvisible(cv->gl_owner)) - sprintf(obuf, ".x%x", (int)cv->gl_owner); + glist = cv->gl_owner; + if (glist && glist_isvisible(glist)) + sprintf(obuf, ".x%x", (int)glist); else obuf[0] = 0; - len = 6; + len = 7; } else if (!strncmp(&ibuf[1], "root", 4)) { - sprintf(obuf, ".x%x", (int)canvas_getrootfor(cv)); + glist = canvas_getrootfor(cv); + if (glist && glist_isvisible(glist)) + sprintf(obuf, ".x%x", (int)glist); + else + obuf[0] = 0; len = 5; } + else if (!strncmp(&ibuf[1], "owner", 5)) + { + if (glist = canvas_getrootfor(cv)) + glist = glist->gl_owner; + if (glist && glist_isvisible(glist)) + sprintf(obuf, ".x%x", (int)glist); + else + obuf[0] = 0; + len = 6; + } + else if (!strncmp(&ibuf[1], "top", 3)) + { + glist = cv; + while (glist->gl_owner) glist = glist->gl_owner; + if (glist && glist_isvisible(glist)) + sprintf(obuf, ".x%x", (int)glist); + else + obuf[0] = 0; + len = 4; + } /* LATER find out when gl_<coords> are updated, think how to better sync them to Tk. */ else if (!strncmp(&ibuf[1], "x1", 2)) @@ -256,6 +282,11 @@ static char *scriptlet_dedot(t_scriptlet *sp, char *ibuf, char *obuf, sprintf(obuf, "%d", glist_isgraph(cv)); len = 4; } + else if (!strncmp(&ibuf[1], "dir", 3)) + { + sprintf(obuf, "%s", canvas_getdir(cv)->s_name); + len = 4; + } else loud_error(sp->s_owner, "bad field '%s'", &ibuf[1]); } } diff --git a/shared/unstable/fringe.c b/shared/unstable/fringe.c index cf29ec6..913d201 100644 --- a/shared/unstable/fringe.c +++ b/shared/unstable/fringe.c @@ -9,6 +9,8 @@ #include "unstable/forky.h" #include "unstable/fringe.h" +//#define FRINGE_DEBUG + static int gobj_getindex(t_glist *gl, t_gobj *ob) { t_gobj *ob1; @@ -57,7 +59,7 @@ static void gobj_stowconnections(t_glist *gl, t_gobj *ob, t_binbuf *bb) gobj_getindex(gl, (t_gobj *)lt.tr_ob), lt.tr_outno, gobj_getindex(gl, (t_gobj *)lt.tr_ob2), lt.tr_inno); } -#if 0 +#ifdef FRINGE_DEBUG post("packed connections:"); binbuf_print(bb); #endif @@ -65,9 +67,13 @@ static void gobj_stowconnections(t_glist *gl, t_gobj *ob, t_binbuf *bb) static void gobj_restoreconnections(t_glist *gl, t_binbuf *bb) { - pd_bind((t_pd *)gl, gensym("#X")); +#ifdef FRINGE_DEBUG + post("restoring connections:"); + binbuf_print(bb); +#endif + canvas_setcurrent(gl); binbuf_eval(bb, 0, 0, 0); - pd_unbind((t_pd *)gl, gensym("#X")); + canvas_unsetcurrent(gl); } void gobj_recreate(t_glist *gl, t_gobj *ob, t_binbuf *bb) diff --git a/test/toxy/tot-query.pd b/test/toxy/tot-query.pd index 36286b3..7ecb091 100644 --- a/test/toxy/tot-query.pd +++ b/test/toxy/tot-query.pd @@ -38,9 +38,9 @@ txt .: concat set $txt; #X obj 21 468 tot .; #X obj 67 238 tot .; #X msg 67 202 tot eval .< [global ch .: info exists ch] .>; -#X msg 54 376 tot set ::ch [open ~/.pdrc] \, query concat set [read -$::ch] \, after 0 .(tot close $::ch .: unset ::ch.); #X msg 21 502; +#X msg 54 376 tot set ::ch [open ~/.pdrc] \, query concat set [read +$::ch] \, tot after 0 .(close $::ch .: unset ::ch.); #X connect 0 0 11 0; #X connect 1 0 3 0; #X connect 2 0 11 0; @@ -55,7 +55,7 @@ $::ch] \, after 0 .(tot close $::ch .: unset ::ch.); #X connect 10 0 14 0; #X connect 11 0 14 0; #X connect 12 0 14 0; -#X connect 14 0 18 0; +#X connect 14 0 17 0; #X connect 15 1 4 0; #X connect 16 0 15 0; -#X connect 17 0 14 0; +#X connect 18 0 14 0; diff --git a/toxy/Makefile b/toxy/Makefile index 1a1e2f5..07cd407 100644 --- a/toxy/Makefile +++ b/toxy/Makefile @@ -9,9 +9,12 @@ checkwiq: $(WIQFILE): $(WIDPATH) @echo transferring widget definitions from \"$<\" to \"$@\" @cat $< | sed \ --e '1i// Do not edit this file (edit \"$<\", and run \"make\").' \ --e '1i//' \ --e '1i\"puts stderr [concat loading built-in widget definitions]\\n\"' \ +-e '1i\ +// Do not edit this file (edit \"$<\", and run \"make\").' \ +-e '1i\ +//' \ +-e '1i\ +\"puts stderr [concat loading built-in widget definitions]\\n\"' \ -e 's/\([\\\"]\)/\\\1/g' \ -e 's/^.*$$/\"&\\n\"/' > $@ @if [ -f $(WIQFILE) ] && ! [ -s $(WIQFILE) ] ; then \ diff --git a/toxy/build_counter b/toxy/build_counter index f292bc7..34a11d3 100644 --- a/toxy/build_counter +++ b/toxy/build_counter @@ -1,3 +1,3 @@ #define TOXY_VERSION "0.1" #define TOXY_RELEASE "alpha" -#define TOXY_BUILD 9 +#define TOXY_BUILD 10 @@ -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. */ @@ -24,8 +24,9 @@ typedef struct _tot { t_object x_ob; t_glist *x_glist; /* containing glist */ - t_symbol *x_cvremote; /* null if containing glist is our destination */ - t_symbol *x_cvname; + t_symbol *x_dotname; /* "." (if explicit), ".parent", ".root", etc. */ + t_symbol *x_cvname; /* destination name (if literal), or 0 */ + t_symbol *x_cvremote; /* bindsym of the above */ t_symbol *x_cvpathname; /* see tot_getpathname() */ t_symbol *x_visedpathname; /* see tot__vised() */ t_symbol *x_target; @@ -54,6 +55,7 @@ typedef struct _totspy t_symbol *ts_selector; t_atom ts_outbuf[TOTSPY_MAXSIZE]; t_outlet *ts_out3; + t_clock *ts_cleanupclock; /* also a tot-is-gone flag */ } t_totspy; static t_class *tot_class; @@ -65,17 +67,66 @@ static t_symbol *totps_motion; static t_symbol *totps_qpush; static t_symbol *totps_query; +static t_symbol *totps_dotparent; /* holder of our containing glist's box */ +static t_symbol *totps_dotroot; /* our document's root canvas */ +static t_symbol *totps_dotowner; /* parent of .root */ +static t_symbol *totps_dottop; /* top-level canvas */ + +static t_glist *tot_getglist(t_tot *x) +{ + t_glist *glist; + if (x->x_cvremote) + glist = (t_glist *)pd_findbyclass(x->x_cvremote, canvas_class); + else if (x->x_dotname == totps_dotparent) + glist = x->x_glist->gl_owner; + else if (x->x_dotname == totps_dotroot) + glist = canvas_getrootfor(x->x_glist); + else if (x->x_dotname == totps_dotowner) + { + if (glist = canvas_getrootfor(x->x_glist)) + glist = glist->gl_owner; + } + else if (x->x_dotname == totps_dottop) + { + glist = x->x_glist; + while (glist->gl_owner) glist = glist->gl_owner; + } + else + glist = x->x_glist; + return (glist); +} + +static t_symbol *tot_getcvname(t_tot *x) +{ + t_glist *glist = tot_getglist(x); + t_symbol *cvname = (glist ? glist->gl_name : x->x_cvname); + if (cvname) + return (cvname); + else if (x->x_dotname) + return (x->x_dotname); + else + { + bug("tot_getcvname"); + return (gensym("???")); + } +} + static t_canvas *tot_getcanvas(t_tot *x, int complain) { t_canvas *cv = 0; - t_glist *glist = - (x->x_cvremote ? - (t_glist *)pd_findbyclass(x->x_cvremote, canvas_class) : x->x_glist); + t_glist *glist = tot_getglist(x); if (glist) cv = glist_getcanvas(glist); else if (complain) - loud_error((t_pd *)x, "bad canvas name '%s'", x->x_cvname->s_name); - if (!x->x_warned && !x->x_cvremote) + { + if (x->x_dotname && *x->x_dotname->s_name) + loud_error((t_pd *)x, "%s canvas does not exist", + &x->x_dotname->s_name[1]); + else + loud_error((t_pd *)x, "bad canvas name '%s'", + tot_getcvname(x)->s_name); + } + if (!x->x_warned) { x->x_warned = 1; if (!cv) cv = x->x_glist; /* redundant */ @@ -258,7 +309,7 @@ static void tot_debug(t_tot *x) int sz; char *bp; post("containing glist: %x", x->x_glist); - post("destination: %s", x->x_cvname->s_name); + post("destination: %s", tot_getcvname(x)->s_name); post("pathname%s %s", (pn ? ":" : ""), (pn ? pn->s_name : "unknown")); bp = scriptlet_getbuffer(x->x_transient, &sz); post("transient buffer (size %d):\n\"%s\"", sz, bp); @@ -397,6 +448,8 @@ static void tot_lastmotion(t_tot *x, t_symbol *s) static void totspy_anything(t_totspy *ts, t_symbol *s, int ac, t_atom *av) { + if (ts->ts_cleanupclock) + return; if (s == totps_motion) { if (ac == 3) @@ -432,6 +485,15 @@ static void totspy_anything(t_totspy *ts, t_symbol *s, int ac, t_atom *av) } } +static void totspy_cleanuptick(t_totspy *ts) +{ + if (ts->ts_target) + pd_unbind((t_pd *)ts, ts->ts_target); + if (ts->ts_cleanupclock) + clock_free(ts->ts_cleanupclock); + pd_free((t_pd *)ts); +} + static void totsink_anything(t_pd *x, t_symbol *s, int ac, t_atom *av) { /* nop */ @@ -445,8 +507,14 @@ static void tot_free(t_tot *x) scriptlet_free(x->x_persistent); scriptlet_free(x->x_transient); if (x->x_spy->ts_target) - pd_unbind((t_pd *)x->x_spy, x->x_spy->ts_target); - pd_free((t_pd *)x->x_spy); + { + /* postpone unbinding, due to a danger of being deleted by + a message to the canvas we spy on... */ + x->x_spy->ts_cleanupclock = + clock_new(x->x_spy, (t_method)totspy_cleanuptick); + clock_delay(x->x_spy->ts_cleanupclock, 0); + } + else pd_free((t_pd *)x->x_spy); pd_free(x->x_guisink); } @@ -461,18 +529,27 @@ static void *tot_new(t_symbol *s1, t_symbol *s2) 0, x->x_glist, tot_cvhook); x->x_persistent = scriptlet_new((t_pd *)x, x->x_target, x->x_target, 0, x->x_glist, tot_cvhook); - if (s1 && s1 != &s_ && strcmp(s1->s_name, ".")) + if (s1 && s1 != &s_ && *s1->s_name != '.') { + x->x_dotname = 0; + x->x_warned = 1; x->x_cvremote = canvas_makebindsym(x->x_cvname = s1); x->x_cvpathname = 0; } else { - x->x_warned = (s1 && *s1->s_name == '.'); /* do not warn if explicit */ + t_glist *glist; + x->x_dotname = (s1 && *s1->s_name == '.' ? s1 : 0); + x->x_warned = (x->x_dotname != 0); /* do not warn if explicit */ + x->x_cvname = 0; x->x_cvremote = 0; - x->x_cvname = x->x_glist->gl_name; - sprintf(buf, ".x%x.c", (int)x->x_glist); - x->x_cvpathname = gensym(buf); + glist = tot_getglist(x); + if (glist == x->x_glist) + { + sprintf(buf, ".x%x.c", (int)glist); + x->x_cvpathname = gensym(buf); + } + else x->x_cvpathname = 0; } outlet_new((t_object *)x, &s_anything); x->x_out2 = outlet_new((t_object *)x, &s_anything); @@ -506,6 +583,10 @@ void tot_setup(void) totps_motion = gensym("motion"); totps_qpush = gensym("qpush"); totps_query = gensym("query"); + totps_dotparent = gensym(".parent"); + totps_dotroot = gensym(".root"); + totps_dotowner = gensym(".owner"); + totps_dottop = gensym(".top"); tot_class = class_new(gensym("tot"), (t_newmethod)tot_new, (t_method)tot_free, |