aboutsummaryrefslogtreecommitdiff
path: root/pd/src/g_editor.c
diff options
context:
space:
mode:
Diffstat (limited to 'pd/src/g_editor.c')
-rw-r--r--pd/src/g_editor.c201
1 files changed, 97 insertions, 104 deletions
diff --git a/pd/src/g_editor.c b/pd/src/g_editor.c
index 0890d465..89dd874c 100644
--- a/pd/src/g_editor.c
+++ b/pd/src/g_editor.c
@@ -8,7 +8,11 @@
#include "m_imp.h"
#include "s_stuff.h"
#include "g_canvas.h"
+#include "s_utf8.h" /*-- moo --*/
#include <string.h>
+#ifdef _MSC_VER /* This is only for Microsoft's compiler, not cygwin, e.g. */
+#define snprintf sprintf_s
+#endif
void glist_readfrombinbuf(t_glist *x, t_binbuf *b, char *filename,
int selectem);
@@ -66,7 +70,8 @@ int gobj_shouldvis(t_gobj *x, struct _glist *glist)
{
t_object *ob;
if (!glist->gl_havewindow && glist->gl_isgraph && glist->gl_goprect &&
- glist->gl_owner && (pd_class(&glist->gl_pd) != garray_class))
+ glist->gl_owner && (pd_class(&x->g_pd) != scalar_class)
+ && (pd_class(&x->g_pd) != garray_class))
{
/* if we're graphing-on-parent and the object falls outside the
graph rectangle, don't draw it. */
@@ -236,7 +241,7 @@ void glist_deselect(t_glist *x, t_gobj *y)
rtext_gettext(z, &buf, &bufsize);
text_setto((t_text *)y, x, buf, bufsize);
- canvas_fixlinesfor(glist_getcanvas(x), (t_text *)y);
+ canvas_fixlinesfor(x, (t_text *)y);
x->gl_editor->e_textedfor = 0;
}
if (fixdsp)
@@ -713,7 +718,7 @@ static void glist_doreload(t_glist *gl, t_symbol *name, t_symbol *dir,
{
t_gobj *g;
int i, nobj = glist_getindex(gl, 0); /* number of objects */
- int hadwindow = gl->gl_havewindow;
+ int hadwindow = (gl->gl_editor != 0);
for (g = gl->gl_list, i = 0; g && i < nobj; i++)
{
if (g != except && pd_class(&g->g_pd) == canvas_class &&
@@ -726,8 +731,10 @@ static void glist_doreload(t_glist *gl, t_symbol *name, t_symbol *dir,
replacement will be at the end of the list, so we don't
do g = g->g_next in this case. */
int j = glist_getindex(gl, g);
- if (!gl->gl_havewindow)
- canvas_vis(glist_getcanvas(gl), 1);
+ if (!gl->gl_editor)
+ canvas_vis(gl, 1);
+ if (!gl->gl_editor)
+ bug("editor");
glist_noselect(gl);
glist_select(gl, g);
canvas_setundo(gl, canvas_undo_cut,
@@ -744,7 +751,7 @@ static void glist_doreload(t_glist *gl, t_symbol *name, t_symbol *dir,
g = g->g_next;
}
}
- if (!hadwindow && gl->gl_havewindow)
+ if (!hadwindow && gl->gl_editor)
canvas_vis(glist_getcanvas(gl), 0);
}
@@ -768,17 +775,13 @@ void canvas_reload(t_symbol *name, t_symbol *dir, t_gobj *except)
/* ------------------------ event handling ------------------------ */
static char *cursorlist[] = {
-#ifdef MSW
- "right_ptr", /* CURSOR_RUNMODE_NOTHING */
-#else
- "left_ptr", /* CURSOR_RUNMODE_NOTHING */
-#endif
- "arrow", /* CURSOR_RUNMODE_CLICKME */
- "sb_v_double_arrow", /* CURSOR_RUNMODE_THICKEN */
- "plus", /* CURSOR_RUNMODE_ADDPOINT */
- "hand2", /* CURSOR_EDITMODE_NOTHING */
- "circle", /* CURSOR_EDITMODE_CONNECT */
- "X_cursor" /* CURSOR_EDITMODE_DISCONNECT */
+ "$cursor_runmode_nothing",
+ "$cursor_runmode_clickme",
+ "$cursor_runmode_thicken",
+ "$cursor_runmode_addpoint",
+ "$cursor_editmode_nothing",
+ "$cursor_editmode_connect",
+ "$cursor_editmode_disconnect"
};
void canvas_setcursor(t_canvas *x, unsigned int cursornum)
@@ -866,6 +869,7 @@ static t_editor *editor_new(t_glist *owner)
x->e_glist = owner;
sprintf(buf, ".x%lx", (t_int)owner);
x->e_guiconnect = guiconnect_new(&owner->gl_pd, gensym(buf));
+ x->e_clock = 0;
return (x);
}
@@ -875,6 +879,8 @@ static void editor_free(t_editor *x, t_glist *y)
guiconnect_notarget(x->e_guiconnect, 1000);
binbuf_free(x->e_connectbuf);
binbuf_free(x->e_deleted);
+ if (x->e_clock)
+ clock_free(x->e_clock);
freebytes((void *)x, sizeof(*x));
}
@@ -897,6 +903,7 @@ void canvas_destroy_editor(t_glist *x)
{
t_gobj *y;
t_object *ob;
+ glist_noselect(x);
if (x->gl_editor)
{
for (y = x->gl_list; y; y = y->g_next)
@@ -917,33 +924,38 @@ void canvas_vis(t_canvas *x, t_floatarg f)
{
char buf[30];
int flag = (f != 0);
- if (x != glist_getcanvas(x))
- bug("canvas_vis");
if (flag)
{
- /* post("havewindow %d, isgraph %d, isvisible %d editor %d",
- x->gl_havewindow, x->gl_isgraph, glist_isvisible(x),
- (x->gl_editor != 0)); */
- /* test if we're already visible and toplevel */
- if (x->gl_editor)
+ /* If a subpatch/abstraction has GOP/gl_isgraph set, then it will have
+ * a gl_editor already, if its not, it will not have a gl_editor.
+ * canvas_create_editor(x) checks if a gl_editor is already created,
+ * so its ok to run it on a canvas that already has a gl_editor. */
+ if (x->gl_editor && x->gl_havewindow)
{ /* just put us in front */
-#ifdef MSW
- canvas_vis(x, 0);
- canvas_vis(x, 1);
-#else
- sys_vgui("raise .x%lx\n", x);
- sys_vgui("focus .x%lx.c\n", x);
- sys_vgui("wm deiconify .x%lx\n", x);
-#endif
+ sys_vgui("pdtk_canvas_raise .x%lx\n", x);
}
else
{
+ char cbuf[MAXPDSTRING];
+ int cbuflen;
+ t_canvas *c = x;
canvas_create_editor(x);
sys_vgui("pdtk_canvas_new .x%lx %d %d +%d+%d %d\n", x,
(int)(x->gl_screenx2 - x->gl_screenx1),
(int)(x->gl_screeny2 - x->gl_screeny1),
(int)(x->gl_screenx1), (int)(x->gl_screeny1),
x->gl_edit);
+ snprintf(cbuf, MAXPDSTRING - 2, "pdtk_canvas_setparents .x%lx",
+ (unsigned long)c);
+ while (c->gl_owner) {
+ c = c->gl_owner;
+ cbuflen = strlen(cbuf);
+ snprintf(cbuf + cbuflen,
+ MAXPDSTRING - cbuflen - 2,/* leave 2 for "\n\0" */
+ " .x%lx", (unsigned long)c);
+ }
+ strcat(cbuf, "\n");
+ sys_gui(cbuf);
canvas_reflecttitle(x);
x->gl_havewindow = 1;
canvas_updatewindowlist();
@@ -964,7 +976,6 @@ void canvas_vis(t_canvas *x, t_floatarg f)
canvas_destroy_editor(x);
return;
}
- sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x);
glist_noselect(x);
if (glist_isvisible(x))
canvas_map(x, 0);
@@ -972,7 +983,6 @@ void canvas_vis(t_canvas *x, t_floatarg f)
sys_vgui("destroy .x%lx\n", x);
for (i = 1, x2 = x; x2; x2 = x2->gl_next, i++)
;
- sys_vgui(".mbar.find delete %d\n", i);
/* if we're a graph on our parent, and if the parent exists
and is visible, show ourselves on parent. */
if (glist_isgraph(x) && x->gl_owner)
@@ -1019,16 +1029,7 @@ void canvas_setgraph(t_glist *x, int flag, int nogoprect)
gobj_vis(&x->gl_gobj, x->gl_owner, 0);
x->gl_isgraph = 1;
x->gl_hidetext = !(!(flag&2));
- if (!nogoprect && !x->gl_goprect)
- {
- t_gobj *g;
- for (g = x->gl_list; g; g = g->g_next)
- if (pd_checkobject(&g->g_pd))
- {
- x->gl_goprect = 1;
- break;
- }
- }
+ x->gl_goprect = !nogoprect;
if (glist_isvisible(x) && x->gl_goprect)
glist_redraw(x);
if (x->gl_owner && !x->gl_loading && glist_isvisible(x->gl_owner))
@@ -1139,6 +1140,7 @@ static void canvas_donecanvasdialog(t_glist *x,
}
/* LATER avoid doing 2 redraws here (possibly one inside setgraph) */
canvas_setgraph(x, graphme, 0);
+ canvas_dirty(x, 1);
if (x->gl_havewindow)
canvas_redraw(x);
else if (glist_isvisible(x->gl_owner))
@@ -1513,10 +1515,11 @@ void canvas_doconnect(t_canvas *x, int xpos, int ypos, int which, int doit)
((x22-x21-IOWIDTH) * closest2)/(ninlet2-1) : 0)
+ IOMIDDLE;
ly2 = y21;
- sys_vgui(".x%lx.c create line %d %d %d %d -width %d -tags l%lx\n",
+ sys_vgui(".x%lx.c create line %d %d %d %d -width %d -tags [list l%lx cord]\n",
glist_getcanvas(x),
lx1, ly1, lx2, ly2,
(obj_issignaloutlet(ob1, closest1) ? 2 : 1), oc);
+ canvas_dirty(x, 1);
canvas_setundo(x, canvas_undo_connect,
canvas_undo_set_connect(x,
canvas_getindex(x, &ob1->ob_g), closest1,
@@ -1608,8 +1611,6 @@ void canvas_mouseup(t_canvas *x,
gobj_activate(x->gl_editor->e_selection->sel_what, x, 1);
}
}
- if (x->gl_editor->e_onmotion != MA_NONE)
- sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x);
x->gl_editor->e_onmotion = MA_NONE;
}
@@ -1634,6 +1635,7 @@ static void canvas_displaceselection(t_canvas *x, int dx, int dy)
}
if (resortin) canvas_resortinlets(x);
if (resortout) canvas_resortoutlets(x);
+ sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x);
if (x->gl_editor->e_selection)
canvas_dirty(x, 1);
}
@@ -1661,9 +1663,20 @@ void canvas_key(t_canvas *x, t_symbol *s, int ac, t_atom *av)
gotkeysym = av[1].a_w.w_symbol;
else if (av[1].a_type == A_FLOAT)
{
- char buf[3];
- sprintf(buf, "%c", (int)(av[1].a_w.w_float));
- gotkeysym = gensym(buf);
+ char buf[UTF8_MAXBYTES1];
+ switch((int)(av[1].a_w.w_float))
+ {
+ case 8: gotkeysym = gensym("BackSpace"); break;
+ case 9: gotkeysym = gensym("Tab"); break;
+ case 10: gotkeysym = gensym("Return"); break;
+ case 27: gotkeysym = gensym("Escape"); break;
+ case 32: gotkeysym = gensym("Space"); break;
+ case 127:gotkeysym = gensym("Delete"); break;
+ default:
+ /*-- moo: assume keynum is a Unicode codepoint; encode as UTF-8 --*/
+ u8_wc_toutf8_nul(buf, (UCS4)(av[1].a_w.w_float));
+ gotkeysym = gensym(buf);
+ }
}
else gotkeysym = gensym("?");
fflag = (av[0].a_type == A_FLOAT ? av[0].a_w.w_float : 0);
@@ -1770,6 +1783,15 @@ void canvas_key(t_canvas *x, t_symbol *s, int ac, t_atom *av)
CURSOR_RUNMODE_NOTHING :CURSOR_EDITMODE_NOTHING);
}
+static void delay_move(t_canvas *x)
+{
+ canvas_displaceselection(x,
+ x->gl_editor->e_xnew - x->gl_editor->e_xwas,
+ x->gl_editor->e_ynew - x->gl_editor->e_ywas);
+ x->gl_editor->e_xwas = x->gl_editor->e_xnew;
+ x->gl_editor->e_ywas = x->gl_editor->e_ynew;
+}
+
void canvas_motion(t_canvas *x, t_floatarg xpos, t_floatarg ypos,
t_floatarg fmod)
{
@@ -1783,10 +1805,12 @@ void canvas_motion(t_canvas *x, t_floatarg xpos, t_floatarg ypos,
glist_setlastxy(x, xpos, ypos);
if (x->gl_editor->e_onmotion == MA_MOVE)
{
- canvas_displaceselection(x,
- xpos - x->gl_editor->e_xwas, ypos - x->gl_editor->e_ywas);
- x->gl_editor->e_xwas = xpos;
- x->gl_editor->e_ywas = ypos;
+ if (!x->gl_editor->e_clock)
+ x->gl_editor->e_clock = clock_new(x, (t_method)delay_move);
+ clock_unset(x->gl_editor->e_clock);
+ clock_delay(x->gl_editor->e_clock, 5);
+ x->gl_editor->e_xnew = xpos;
+ x->gl_editor->e_ynew = ypos;
}
else if (x->gl_editor->e_onmotion == MA_REGION)
canvas_doregion(x, xpos, ypos, 0);
@@ -1858,13 +1882,12 @@ void glob_verifyquit(void *dummy, t_floatarg f)
if (g2 = glist_finddirty(g))
{
canvas_vis(g2, 1);
- sys_vgui(
-"pdtk_check .x%lx {Discard changes to '%s'?} {.x%lx menuclose 3;\n} no\n",
- canvas_getrootfor(g2), canvas_getrootfor(g2)->gl_name->s_name, g2);
+ sys_vgui("pdtk_canvas_menuclose .x%lx {.x%lx menuclose 3;\n}\n",
+ canvas_getrootfor(g2), g2);
return;
}
if (f == 0 && sys_perf)
- sys_vgui("pdtk_check . {really quit?} {pd quit;\n} yes\n");
+ sys_vgui("pdtk_check .pdwindow {really quit?} {pd quit} yes\n");
else glob_quit(0);
}
@@ -1887,16 +1910,14 @@ void canvas_menuclose(t_canvas *x, t_floatarg fforce)
if (g)
{
vmess(&g->gl_pd, gensym("menu-open"), "");
- sys_vgui(
-"pdtk_check .x%lx {Discard changes to '%s'?} {.x%lx menuclose 2;\n} no\n",
- canvas_getrootfor(g), canvas_getrootfor(g)->gl_name->s_name, g);
+ sys_vgui("pdtk_canvas_menuclose .x%lx {.x%lx menuclose 2;\n}\n",
+ canvas_getrootfor(g), g);
return;
}
else if (sys_perf)
{
- sys_vgui(
-"pdtk_check .x%lx {Close '%s'?} {.x%lx menuclose 1;\n} yes\n",
- canvas_getrootfor(x), canvas_getrootfor(x)->gl_name->s_name, x);
+ sys_vgui("pdtk_canvas_menuclose .x%lx {.x%lx menuclose 1;\n}\n",
+ canvas_getrootfor(g), g);
}
else pd_free(&x->gl_pd);
}
@@ -1911,9 +1932,8 @@ void canvas_menuclose(t_canvas *x, t_floatarg fforce)
if (g)
{
vmess(&g->gl_pd, gensym("menu-open"), "");
- sys_vgui(
-"pdtk_check .x%lx {Discard changes to '%s'?} {.x%lx menuclose 2;\n} no\n",
- canvas_getrootfor(x), canvas_getrootfor(x)->gl_name->s_name, g);
+ sys_vgui("pdtk_canvas_menuclose .x%lx {.x%lx menuclose 2;\n}\n",
+ canvas_getrootfor(x), g);
return;
}
else pd_free(&x->gl_pd);
@@ -1997,7 +2017,7 @@ static void canvas_find(t_canvas *x, t_symbol *s, t_floatarg wholeword)
if (!canvas_dofind(x, &myindex1))
{
binbuf_print(canvas_findbuf);
- post("... couldn't find");
+ sys_vgui("pdtk_couldnotfind .x%lx\n", x);
}
}
@@ -2009,7 +2029,7 @@ static void canvas_find_again(t_canvas *x)
if (!canvas_dofind(canvas_whichfind, &myindex1))
{
binbuf_print(canvas_findbuf);
- post("... couldn't find");
+ sys_vgui("pdtk_couldnotfind .x%lx\n", x);
}
}
@@ -2051,7 +2071,7 @@ void canvas_finderror(void *error_object)
if (glist_dofinderror(x, error_object))
return;
}
- post("... sorry, I couldn't find the source of that error.");
+ error("... sorry, I couldn't find the source of that error.");
}
void canvas_stowconnections(t_canvas *x)
@@ -2155,22 +2175,8 @@ static void canvas_copy(t_canvas *x)
char *buf;
int bufsize;
rtext_getseltext(x->gl_editor->e_textedfor, &buf, &bufsize);
-
-#if defined(MSW) || defined(__APPLE__)
- /* for Mac or Windows, copy the text to the clipboard here */
- sys_vgui("clipboard clear\n", bufsize, buf);
+ sys_gui("clipboard clear\n");
sys_vgui("clipboard append {%.*s}\n", bufsize, buf);
-#else
- /* in X windows the selection already went to the
- clipboard when it was made; here we "copy" it to our own buffer
- as well, because, annoyingly, the clipboard will usually be
- destroyed by the time the user asks to "paste". */
- if (canvas_textcopybuf)
- t_freebytes(canvas_textcopybuf, canvas_textcopybufsize);
- canvas_textcopybuf = (char *)getbytes(bufsize);
- memcpy(canvas_textcopybuf, buf, bufsize);
- canvas_textcopybufsize = bufsize;
-#endif
}
}
@@ -2182,6 +2188,7 @@ static void canvas_clearline(t_canvas *x)
x->gl_editor->e_selectline_outno,
x->gl_editor->e_selectline_index2,
x->gl_editor->e_selectline_inno);
+ canvas_dirty(x, 1);
canvas_setundo(x, canvas_undo_disconnect,
canvas_undo_set_disconnect(x,
x->gl_editor->e_selectline_index1,
@@ -2321,19 +2328,8 @@ static void canvas_paste(t_canvas *x)
return;
if (x->gl_editor->e_textedfor)
{
- /* simulate keystrokes as if the copy buffer were typed in. */
-#if defined(MSW) || defined(__APPLE__)
- /* for Mac or Windows, ask the GUI to send the clipboard down */
+ /* simulate keystrokes as if the copy buffer were typed in. */
sys_gui("pdtk_pastetext\n");
-#else
- /* in X windows we kept the text in our own copy buffer */
- int i;
- for (i = 0; i < canvas_textcopybufsize; i++)
- {
- pd_vmess(&x->gl_gobj.g_pd, gensym("key"), "iii",
- 1, canvas_textcopybuf[i]&0xff, 0);
- }
-#endif
}
else
{
@@ -2446,7 +2442,7 @@ void canvas_connect(t_canvas *x, t_floatarg fwhoout, t_floatarg foutno,
if (!(oc = obj_connect(objsrc, outno, objsink, inno))) goto bad;
if (glist_isvisible(x))
{
- sys_vgui(".x%lx.c create line %d %d %d %d -width %d -tags l%lx\n",
+ sys_vgui(".x%lx.c create line %d %d %d %d -width %d -tags [list l%lx cord]\n",
glist_getcanvas(x), 0, 0, 0, 0,
(obj_issignaloutlet(objsrc, outno) ? 2 : 1),oc);
canvas_fixlinesfor(x, objsrc);
@@ -2586,12 +2582,9 @@ void glob_key(void *dummy, t_symbol *s, int ac, t_atom *av)
canvas_key(canvas_editing, s, ac, av);
}
-void canvas_editmode(t_canvas *x, t_floatarg fyesplease)
+void canvas_editmode(t_canvas *x, t_floatarg state)
{
- int yesplease = fyesplease;
- if (yesplease && x->gl_edit)
- return;
- x->gl_edit = !x->gl_edit;
+ x->gl_edit = (unsigned int) state;
if (x->gl_edit && glist_isvisible(x) && glist_istoplevel(x))
canvas_setcursor(x, CURSOR_EDITMODE_NOTHING);
else
@@ -2600,7 +2593,7 @@ void canvas_editmode(t_canvas *x, t_floatarg fyesplease)
if (glist_isvisible(x) && glist_istoplevel(x))
canvas_setcursor(x, CURSOR_RUNMODE_NOTHING);
}
- sys_vgui("pdtk_canvas_editval .x%lx %d\n",
+ sys_vgui("pdtk_canvas_editmode .x%lx %d\n",
glist_getcanvas(x), x->gl_edit);
}