Update of /cvsroot/pure-data/externals/bbogart/entry
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6300
Modified Files:
entry.c
Log Message:
got selecting with a click working, but not deselecting afterwards
Index: entry.c
===================================================================
RCS file: /cvsroot/pure-data/externals/bbogart/entry/entry.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** entry.c 7 Nov 2007 05:58:05 -0000 1.25
--- entry.c 13 Nov 2007 05:31:50 -0000 1.26
***************
*** 27,30 ****
--- 27,32 ----
/* TODO: set message doesnt work with a loadbang */
/* TODO: complete inlet draw/erase logic */
+ /* TODO: unbind text from all key events when selected */
+ /* TODO try binding to FocusIn and FocusOut for making selection */
#ifdef _MSC_VER
***************
*** 39,42 ****
--- 41,53 ----
#define BACKGROUNDCOLOR "grey70"
+ #define TKW_HANDLE_HEIGHT 10
+ #define TKW_HANDLE_WIDTH 10
+
+ #define SCOPE_SELBDWIDTH 3.0
+ #define SCOPE_DEFWIDTH 130 /* CHECKED */
+ #define SCOPE_MINWIDTH 66
+ #define SCOPE_DEFHEIGHT 130 /* CHECKED */
+ #define SCOPE_MINHEIGHT 34
+
#define TOTAL_INLETS 1
#define TOTAL_OUTLETS 2
***************
*** 47,50 ****
--- 58,63 ----
{
t_object x_obj;
+ t_canvas *x_canvas;
+ t_glist *x_glist;
int x_rect_width;
***************
*** 52,55 ****
--- 65,72 ----
t_symbol* x_receive_name;
+ int h_dragon;
+ int h_dragx;
+ int h_dragy;
+
/* TODO: these all should be settable by messages */
int x_height;
***************
*** 66,71 ****
t_symbol *x_relief;
t_int x_have_scrollbar;
!
! t_canvas *canvas;
/* IDs for Tk widgets */
char *tcl_namespace;
--- 83,88 ----
t_symbol *x_relief;
t_int x_have_scrollbar;
! t_int x_selected;
!
/* IDs for Tk widgets */
char *tcl_namespace;
***************
*** 75,79 ****
char *scrollbar_id;
char *handle_id;
! char *window_id;
t_outlet* x_data_outlet;
--- 92,98 ----
char *scrollbar_id;
char *handle_id;
! char *window_tag;
! char *all_tag;
! char *outline_tag;
t_outlet* x_data_outlet;
***************
*** 103,106 ****
--- 122,127 ----
static void entry_delete(t_gobj *z, t_glist *glist);
static void entry_vis(t_gobj *z, t_glist *glist, int vis);
+ static void entry_activate(t_gobj *x, struct _glist *glist, int state);
+ //static int entry_click(t_gobj *x, struct _glist *glist, int xpix, int ypix, int shift, int alt, int dbl, int doit);
static void entry_save(t_gobj *z, t_binbuf *b);
***************
*** 129,133 ****
char buf[MAXPDSTRING];
! x->canvas = canvas;
/* Tk ID for the current canvas that this object is drawn in */
--- 150,154 ----
char buf[MAXPDSTRING];
! x->x_canvas = canvas;
/* Tk ID for the current canvas that this object is drawn in */
***************
*** 141,151 ****
strcpy(x->frame_id, buf);
! sprintf(buf,"%s.text", x->frame_id);
x->text_id = getbytes(strlen(buf));
strcpy(x->text_id, buf); /* Tk ID for the "text", the meat! */
sprintf(buf,"%s.window%lx", x->canvas_id, (long unsigned int)x);
! x->window_id = getbytes(strlen(buf));
! strcpy(x->window_id, buf); /* Tk ID for the resizing "window" */
sprintf(buf,"%s.handle%lx", x->canvas_id, (long unsigned int)x);
--- 162,173 ----
strcpy(x->frame_id, buf);
! sprintf(buf,"%s.text%lx", x->frame_id, (long unsigned int)x);
x->text_id = getbytes(strlen(buf));
strcpy(x->text_id, buf); /* Tk ID for the "text", the meat! */
sprintf(buf,"%s.window%lx", x->canvas_id, (long unsigned int)x);
! x->window_tag = getbytes(strlen(buf));
! strcpy(x->window_tag, buf); /* Tk ID for the resizing "window" */
! post("");
sprintf(buf,"%s.handle%lx", x->canvas_id, (long unsigned int)x);
***************
*** 153,167 ****
strcpy(x->handle_id, buf); /* Tk ID for the resizing "handle" */
! sprintf(buf,"%s.scrollbar", x->frame_id);
x->scrollbar_id = getbytes(strlen(buf));
strcpy(x->scrollbar_id, buf); /* Tk ID for the optional "scrollbar" */
! post("buf: %s scrollbar_id %s", buf, x->scrollbar_id);
! post("buf: %s handle_id %s", buf, x->handle_id);
! }
!
! static void draw_resize_handle(t_entry *x)
! {
!
}
--- 175,185 ----
strcpy(x->handle_id, buf); /* Tk ID for the resizing "handle" */
! sprintf(buf,"%s.scrollbar%lx", x->frame_id, (long unsigned int)x);
x->scrollbar_id = getbytes(strlen(buf));
strcpy(x->scrollbar_id, buf); /* Tk ID for the optional "scrollbar" */
! sprintf(buf,"all%lx", (long unsigned int)x);
! x->all_tag = getbytes(strlen(buf));
! strcpy(x->all_tag, buf); /* Tk ID for the optional "scrollbar" */
}
***************
*** 186,200 ****
if (firsttime)
{
! sys_vgui("%s create rectangle %d %d %d %d -tags {%xi%d %xi}\n",
x->canvas_id, onset, text_ypix(&x->x_obj, glist) - 1,
onset + IOWIDTH, text_ypix(&x->x_obj, glist),
! x, i, x);
}
! else
{
sys_vgui("%s coords %xi%d %d %d %d %d\n",
x->canvas_id, x, i, onset, text_ypix(&x->x_obj, glist) - 1,
onset + IOWIDTH, text_ypix(&x->x_obj, glist));
! }
}
for (i = 0; i < total_outlets; i++) /* outlets */
--- 204,218 ----
if (firsttime)
{
! sys_vgui("%s create rectangle %d %d %d %d -tags {%xi%d %xi %s}\n",
x->canvas_id, onset, text_ypix(&x->x_obj, glist) - 1,
onset + IOWIDTH, text_ypix(&x->x_obj, glist),
! x, i, x, x->all_tag);
}
! /* else
{
sys_vgui("%s coords %xi%d %d %d %d %d\n",
x->canvas_id, x, i, onset, text_ypix(&x->x_obj, glist) - 1,
onset + IOWIDTH, text_ypix(&x->x_obj, glist));
! }*/
}
for (i = 0; i < total_outlets; i++) /* outlets */
***************
*** 203,212 ****
if (firsttime)
{
! sys_vgui("%s create rectangle %d %d %d %d -tags {%xo%d %xo}\n",
x->canvas_id, onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 1,
onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height,
! x, i, x);
}
! else
{
sys_vgui("%s coords %xo%d %d %d %d %d\n",
--- 221,230 ----
if (firsttime)
{
! sys_vgui("%s create rectangle %d %d %d %d -tags {%xo%d %xo %s}\n",
x->canvas_id, onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 1,
onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height,
! x, i, x, x->all_tag);
}
! /* else
{
sys_vgui("%s coords %xo%d %d %d %d %d\n",
***************
*** 214,218 ****
onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 1,
onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height);
! }
}
DEBUG(post("draw inlet end"););
--- 232,236 ----
onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 1,
onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height);
! }*/
}
DEBUG(post("draw inlet end"););
***************
*** 243,260 ****
}
static void bind_button_events(t_entry *x)
{
sys_vgui("bind %s <Button-2> \
{pdtk_canvas_popup .x%lx [expr %%x + %d] [expr %%y + %d] 0 0} \n",
! x->text_id, x->canvas, x->x_obj.te_xpix, x->x_obj.te_ypix);
sys_vgui("bind %s <Control-Button> \
{pdtk_canvas_popup .x%lx [expr %%x + %d] [expr %%y + %d] 0 0} \n",
! x->text_id, x->canvas, x->x_obj.te_xpix, x->x_obj.te_ypix);
sys_vgui("bind %s <Button-3> \
{pdtk_canvas_popup .x%lx [expr %%x + %d] [expr %%y + %d] 0 0} \n",
! x->text_id, x->canvas, x->x_obj.te_xpix, x->x_obj.te_ypix);
sys_vgui("bind %s <Control-Button> \
{pdtk_canvas_popup .x%lx [expr %%x + %d] [expr %%y + %d] 0 0} \n",
! x->text_id, x->canvas, x->x_obj.te_xpix, x->x_obj.te_ypix);
}
--- 261,289 ----
}
+ static void draw_resize_handle(t_entry *x)
+ {
+ }
+
+ static void erase_resize_handle(t_entry *x)
+ {
+ }
+
+
static void bind_button_events(t_entry *x)
{
+ sys_vgui("bind %s <Button> {pd [concat %s click 1 \\;]}\n",
+ x->text_id, x->x_receive_name->s_name);
sys_vgui("bind %s <Button-2> \
{pdtk_canvas_popup .x%lx [expr %%x + %d] [expr %%y + %d] 0 0} \n",
! x->text_id, x->x_canvas, x->x_obj.te_xpix, x->x_obj.te_ypix);
sys_vgui("bind %s <Control-Button> \
{pdtk_canvas_popup .x%lx [expr %%x + %d] [expr %%y + %d] 0 0} \n",
! x->text_id, x->x_canvas, x->x_obj.te_xpix, x->x_obj.te_ypix);
sys_vgui("bind %s <Button-3> \
{pdtk_canvas_popup .x%lx [expr %%x + %d] [expr %%y + %d] 0 0} \n",
! x->text_id, x->x_canvas, x->x_obj.te_xpix, x->x_obj.te_ypix);
sys_vgui("bind %s <Control-Button> \
{pdtk_canvas_popup .x%lx [expr %%x + %d] [expr %%y + %d] 0 0} \n",
! x->text_id, x->x_canvas, x->x_obj.te_xpix, x->x_obj.te_ypix);
}
***************
*** 277,284 ****
-yscrollcommand {%s set} \n",
x->text_id,
! x->x_font_face->s_name, x->x_font_size, x->x_font_weight->s_name,
! x->x_bgcolour->s_name, x->x_fgcolour->s_name,
x->scrollbar_id);
! sys_vgui("scrollbar %s -command {%s yview} \n",
x->scrollbar_id, x->text_id);
sys_vgui("pack %s -side left -fill both -expand 1 \n", x->text_id);
--- 306,313 ----
-yscrollcommand {%s set} \n",
x->text_id,
! x->x_font_face->s_name, x->x_font_size, x->x_font_weight->s_name,
! x->x_bgcolour->s_name, x->x_fgcolour->s_name,
x->scrollbar_id);
! sys_vgui("scrollbar %s -command {%s yview}\n",
x->scrollbar_id, x->text_id);
sys_vgui("pack %s -side left -fill both -expand 1 \n", x->text_id);
***************
*** 294,311 ****
static void entry_drawme(t_entry *x, t_glist *glist, int firsttime)
{
! DEBUG(post("entry_drawme: firsttime %d canvas %s glist %s", firsttime, x->canvas, glist););
set_tk_widget_ids(x,glist_getcanvas(glist));
if (firsttime)
{
create_widget(x); /* TODO: what is this window for? */
! sys_vgui("%s create window %d %d -anchor nw -window %s \
! -tags %xS -width %d -height %d \n", x->canvas_id,
text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
! x->frame_id,x, x->x_width, x->x_height);
}
else
{
! sys_vgui("%s coords %xS %d %d\n", x->canvas_id, x,
! text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist));
}
if(glist->gl_edit) /* this is buggy logic */
--- 323,341 ----
static void entry_drawme(t_entry *x, t_glist *glist, int firsttime)
{
! DEBUG(post("entry_drawme: firsttime %d canvas %lx glist %lx", firsttime, x->x_canvas, glist););
set_tk_widget_ids(x,glist_getcanvas(glist));
if (firsttime)
{
create_widget(x); /* TODO: what is this window for? */
! sys_vgui("%s create window %d %d -anchor nw -window %s \
! -tags {%s %s} -width %d -height %d \n", x->canvas_id,
text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
! x->frame_id, x->window_tag, x->all_tag, x->x_width, x->x_height);
}
else
{
! post("NO MORE COORDS");
! // sys_vgui("%s coords %s %d %d\n", x->canvas_id, x->all_tag,
! // text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist));
}
if(glist->gl_edit) /* this is buggy logic */
***************
*** 319,327 ****
static void entry_erase(t_entry* x,t_glist* glist)
{
! DEBUG(post("entry_erase: canvas %s glist %s", x->canvas, glist););
! erase_inlets(x);
sys_vgui("destroy %s\n", x->frame_id);
! sys_vgui("%s delete %xS\n", x->canvas_id, x);
}
--- 349,358 ----
static void entry_erase(t_entry* x,t_glist* glist)
{
! DEBUG(post("entry_erase: canvas %lx glist %lx", x->x_canvas, glist););
! set_tk_widget_ids(x,glist_getcanvas(glist));
! // erase_inlets(x);
sys_vgui("destroy %s\n", x->frame_id);
! sys_vgui("%s delete %s\n", x->canvas_id, x->all_tag);
}
***************
*** 349,363 ****
{
t_entry *x = (t_entry *)z;
! DEBUG(post("entry_displace: canvas %s glist %s", x->canvas, glist););
x->x_obj.te_xpix += dx;
x->x_obj.te_ypix += dy;
if (glist_isvisible(glist))
{
! sys_vgui("%s coords %xSEL %d %d %d %d\n", x->canvas_id, x,
text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist)-1,
text_xpix(&x->x_obj, glist) + x->x_rect_width,
! text_ypix(&x->x_obj, glist) + x->x_rect_height-2);
!
! entry_drawme(x, glist, 0);
canvas_fixlinesfor(glist_getcanvas(glist), (t_text*) x);
}
--- 380,395 ----
{
t_entry *x = (t_entry *)z;
! DEBUG(post("entry_displace: canvas %lx glist %lx", x->x_canvas, glist););
x->x_obj.te_xpix += dx;
x->x_obj.te_ypix += dy;
if (glist_isvisible(glist))
{
! set_tk_widget_ids(x,glist_getcanvas(glist));
! sys_vgui("%s move %s %d %d\n", x->canvas_id, x->all_tag, dx, dy);
! /* sys_vgui("%s coords %s %d %d %d %d\n", x->canvas_id, x->all_tag,
text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist)-1,
text_xpix(&x->x_obj, glist) + x->x_rect_width,
! text_ypix(&x->x_obj, glist) + x->x_rect_height-2);*/
! // entry_drawme(x, glist, 0);
canvas_fixlinesfor(glist_getcanvas(glist), (t_text*) x);
}
***************
*** 368,384 ****
{
t_entry *x = (t_entry *)z;
! DEBUG(post("entry_select: canvas %s glist %s", x->canvas, glist););
!
! if (state) {
! // sys_vgui(".x%x.c itemconfigure %s -outline blue -width %f -fill %s\n",
! // x->canvas_id, x->x_bgtag, SCOPE_SELBDWIDTH, SCOPE_SELCOLOR);
! sys_vgui("%s create rectangle %d %d %d %d -tags %xSEL -outline blue\n",
x->canvas_id,
text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist)-1,
text_xpix(&x->x_obj, glist) + x->x_rect_width,
! text_ypix(&x->x_obj, glist) + x->x_rect_height-2, x);
}
! else {
sys_vgui("%s delete %xSEL\n", x->canvas_id, x);
}
}
--- 400,439 ----
{
t_entry *x = (t_entry *)z;
! int x1, y1, x2, y2;
! DEBUG(post("entry_select: canvas %lx glist %lx state %d", x->x_canvas, glist, state););
!
! // set_tk_widget_ids(x,glist_getcanvas(glist));
! if( (state) && (!x->x_selected))
! {
! entry_getrect(z, glist, &x1, &y1, &x2, &y2);
! sys_vgui("%s configure -bg #bdbddd -state disabled\n", x->text_id);
! sys_vgui("canvas %s -width %d -height %d -bg #fedc00 -bd 0 -cursor top_left_arrow\n",
! x->handle_id, TKW_HANDLE_WIDTH, TKW_HANDLE_HEIGHT);
! sys_vgui("%s create window %f %f -anchor nw -width %d -height %d -window %s -tags %s\n",
! x->canvas_id, x2 - (TKW_HANDLE_WIDTH - SCOPE_SELBDWIDTH),
! y2 - (TKW_HANDLE_HEIGHT - SCOPE_SELBDWIDTH),
! TKW_HANDLE_WIDTH, TKW_HANDLE_HEIGHT,
! x->handle_id, x->all_tag);
! sys_vgui("bind %s <Button> {pd [concat %s resize_click 1 \\;]}\n",
! x->handle_id, x->x_receive_name->s_name);
! sys_vgui("bind %s <ButtonRelease> {pd [concat %s resize_click 0 \\;]}\n",
! x->handle_id, x->x_receive_name->s_name);
! sys_vgui("bind %s <Motion> {pd [concat %s resize_motion %%x %%y \\;]}\n",
! x->handle_id, x->x_receive_name->s_name);
! /* */
! sys_vgui("%s create rectangle %d %d %d %d -tags {%xSEL %s} -outline blue -width 2\n",
x->canvas_id,
text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist)-1,
text_xpix(&x->x_obj, glist) + x->x_rect_width,
! text_ypix(&x->x_obj, glist) + x->x_rect_height-2,
! x, x->all_tag);
! x->x_selected = 1;
}
! else if (!state)
! {
! sys_vgui("%s configure -bg grey -state normal\n", x->text_id);
sys_vgui("%s delete %xSEL\n", x->canvas_id, x);
+ sys_vgui("destroy %s\n", x->handle_id);
+ x->x_selected = 0;
}
}
***************
*** 396,400 ****
static void entry_delete(t_gobj *z, t_glist *glist)
{
! DEBUG(post("entry_delete: glist %s", glist););
t_text *x = (t_text *)z;
canvas_deletelinesfor(glist_getcanvas(glist), x);
--- 451,455 ----
static void entry_delete(t_gobj *z, t_glist *glist)
{
! DEBUG(post("entry_delete: glist %lx", glist););
t_text *x = (t_text *)z;
canvas_deletelinesfor(glist_getcanvas(glist), x);
***************
*** 405,409 ****
{
t_entry *x = (t_entry*)z;
! DEBUG(post("entry_vis: vis %d canvas %s glist %s", vis, x->canvas, glist););
t_rtext *y;
if (vis) {
--- 460,464 ----
{
t_entry *x = (t_entry*)z;
! DEBUG(post("entry_vis: vis %d canvas %lx glist %lx", vis, x->x_canvas, glist););
t_rtext *y;
if (vis) {
***************
*** 640,643 ****
--- 695,767 ----
x->x_height = height;
x->x_width = width;
+ // sys_vgui("%s configure -width %d -height %d \n", x->text_id, (int)width, (int)height);
+ sys_vgui("%s itemconfigure %s -width %d -height %d \n",
+ x->canvas_id, x->all_tag, (int)width, (int)height);
+ }
+
+ static void entry_click_callback(t_entry *x, t_floatarg f)
+ {
+ if( (x->x_glist->gl_edit) && (x->x_glist == x->x_canvas) )
+ {
+ entry_select((t_gobj *)x, x->x_glist, f);
+ }
+ }
+
+ static void entry_resize_click_callback(t_entry *x, t_floatarg f)
+ {
+ /*
+ t_canvas *canvas = (glist_isvisible(x->x_glist) ? x->x_canvas : 0);
+ int newstate = (int)f;
+ if (x->h_dragon && newstate == 0)
+ {
+ x->x_width += x->h_dragx;
+ x->x_height += x->h_dragy;
+ if (canvas)
+ {
+ sys_vgui(".x%x.c delete %s\n", canvas, x->outline_tag);
+ scope_revis(x, canvas);
+ sys_vgui("destroy %s\n", x->handle_id);
+ entry_select((t_gobj *)x, x->x_glist, 1);
+ canvas_fixlinesfor(x->x_glist, (t_text *)x); // 2nd inlet
+ }
+ }
+ else if (!x->h_dragon && newstate)
+ {
+ if (canvas)
+ {
+ int x1, y1, x2, y2;
+ entry_getrect((t_gobj *)x, x->x_glist, &x1, &y1, &x2, &y2);
+ sys_vgui("lower %s\n", x->handle_id);
+ sys_vgui(".x%x.c create rectangle %d %d %d %d -outline blue -width %f -tags %s\n",
+ canvas, x1, y1, x2, y2, SCOPE_SELBDWIDTH, x->outline_tag);
+ }
+ x->h_dragx = 0;
+ x->h_dragy = 0;
+ }
+ x->h_dragon = newstate;
+ */
+ }
+
+ static void entry_resize_motion_callback(t_entry *x, t_floatarg f1, t_floatarg f2)
+ {
+ /*
+ if (x->h_dragon)
+ {
+ int dx = (int)f1, dy = (int)f2;
+ int x1, y1, x2, y2, newx, newy;
+ entry_getrect((t_gobj *)x, x->x_glist, &x1, &y1, &x2, &y2);
+ newx = x2 + dx;
+ newy = y2 + dy;
+ if (newx > x1 + SCOPE_MINWIDTH && newy > y1 + SCOPE_MINHEIGHT)
+ {
+ t_canvas *canvas = (glist_isvisible(x->x_glist) ? x->x_canvas : 0);
+ if (canvas)
+ sys_vgui(".x%x.c coords %s %d %d %d %d\n",
+ canvas, x->outline_tag, x1, y1, newx, newy);
+ x->h_dragx = dx;
+ x->h_dragy = dy;
+ }
+ }
+ */
}
***************
*** 658,661 ****
--- 782,786 ----
x->x_font_weight = gensym("normal");
x->x_have_scrollbar = 0;
+ x->x_selected = 0;
if (argc < 4)
***************
*** 688,692 ****
post("2");
! set_tk_widget_ids(x, canvas_getcurrent());
return (x);
--- 813,818 ----
post("2");
! x->x_glist = canvas_getcurrent();
! set_tk_widget_ids(x, x->x_glist);
return (x);
***************
*** 758,761 ****
--- 884,894 ----
A_DEFSYMBOL,
0);
+
+ class_addmethod(entry_class, (t_method)entry_click_callback,
+ gensym("click"), A_FLOAT, 0);
+ class_addmethod(entry_class, (t_method)entry_resize_click_callback,
+ gensym("resize_click"), A_FLOAT, 0);
+ class_addmethod(entry_class, (t_method)entry_resize_motion_callback,
+ gensym("resize_motion"), A_FLOAT, A_FLOAT, 0);
class_setwidget(entry_class,&entry_widgetbehavior);