Update of /cvsroot/pure-data/externals/bbogart/entry
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19340
Modified Files:
entry.c
Log Message:
trying using symbols for canvas names built with pointers to make code easier to read; fixed fgcolour/bgcolour bugs where it was resettng the contents of the symbol rather than switching symbols for the color names
Index: entry.c
===================================================================
RCS file: /cvsroot/pure-data/externals/bbogart/entry/entry.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** entry.c 24 Oct 2007 00:36:01 -0000 1.7
--- entry.c 24 Oct 2007 05:22:45 -0000 1.8
***************
*** 21,40 ****
#include <string.h>
- /* TODO: make one .x%x.c.s%x replacement into x->x_widget_name */
- /* TODO: make one .x%x.c replacement into x->x_canvas_name */
/* TODO: make "display only" option, to force box to never accept focus */
/* TODO: make focus option only accept regular and shifted chars, not Cmd, Alt, Ctrl */
/* TODO: make entry_save include whole classname, including namespace prefix */
!
! #ifdef NT
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
- #if PD_MINOR_VERSION < 37
- #define t_rtext t_text
- #endif
-
#ifndef IOWIDTH
#define IOWIDTH 4
--- 21,34 ----
#include <string.h>
/* TODO: make "display only" option, to force box to never accept focus */
/* TODO: make focus option only accept regular and shifted chars, not Cmd, Alt, Ctrl */
/* TODO: make entry_save include whole classname, including namespace prefix */
+ /* TODO: set message doesnt work with a loadbang */
! #ifdef _MSC_VER
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
#endif
#ifndef IOWIDTH
#define IOWIDTH 4
***************
*** 50,54 ****
int x_rect_width;
int x_rect_height;
! t_symbol* x_receive_name_symbol;
/* TODO: these all should be settable by messages */
--- 44,51 ----
int x_rect_width;
int x_rect_height;
! t_symbol* x_receive_name;
!
! char *x_widget_name;
! char *x_canvas_name;
/* TODO: these all should be settable by messages */
***************
*** 80,84 ****
/* widget helper functions */
! #define DEBUG(x)
--- 77,81 ----
/* widget helper functions */
! #define DEBUG(x) x
***************
*** 96,116 ****
{
/* left outlet, for data */
! sys_vgui(".x%x.c create rectangle %d %d %d %d -tags {%xo%d %xo}\n",
! glist_getcanvas(glist),
! onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 2,
! onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height-1,
! x, i, x);
/* right outlet, for key status */
- /* sys_vgui(".x%x.c create rectangle %d %d %d %d -tags {%xo%d %xo}\n",
- glist_getcanvas(glist),
- onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 2,
- onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height-1,
- x, i, x);
- */
}
else
{
! sys_vgui(".x%x.c coords %xo%d %d %d %d %d\n",
! glist_getcanvas(glist), x, i,
onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 2,
onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height-1);
--- 93,116 ----
{
/* left outlet, for data */
! post("%s create rectangle %d %d %d %d -tags {%xo%d %xo}\n",
! x->x_canvas_name,
! onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 2,
! onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height-1,
! x, i, x);
! sys_vgui("%s create rectangle %d %d %d %d -tags {%xo%d %xo}\n",
! x->x_canvas_name,
! onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 2,
! onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height-1,
! x, i, x);
/* right outlet, for key status */
}
else
{
! post("%s coords %xo%d %d %d %d %d\n",
! x->x_canvas_name, x, i,
! onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 2,
! onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height-1);
! sys_vgui("%s coords %xo%d %d %d %d %d\n",
! x->x_canvas_name, x, i,
onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 2,
onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->x_rect_height-1);
***************
*** 124,138 ****
int onset = text_xpix(&x->x_obj, glist) + (x->x_rect_width - IOWIDTH) * i / nplus;
if (firsttime)
! sys_vgui(".x%x.c create rectangle %d %d %d %d -tags {%xi%d %xi}\n",
! glist_getcanvas(glist),
onset, text_ypix(&x->x_obj, glist),
onset + IOWIDTH, text_ypix(&x->x_obj, glist)+1,
x, i, x);
else
! sys_vgui(".x%x.c coords %xi%d %d %d %d %d\n",
! glist_getcanvas(glist), x, i,
onset, text_ypix(&x->x_obj, glist),
onset + IOWIDTH, text_ypix(&x->x_obj, glist)+1);
!
}
DEBUG(post("draw inlet end");)
--- 124,150 ----
int onset = text_xpix(&x->x_obj, glist) + (x->x_rect_width - IOWIDTH) * i / nplus;
if (firsttime)
! {
! post("%s create rectangle %d %d %d %d -tags {%xi%d %xi}\n",
! x->x_canvas_name,
! onset, text_ypix(&x->x_obj, glist),
! onset + IOWIDTH, text_ypix(&x->x_obj, glist)+1,
! x, i, x);
! sys_vgui("%s create rectangle %d %d %d %d -tags {%xi%d %xi}\n",
! x->x_canvas_name,
onset, text_ypix(&x->x_obj, glist),
onset + IOWIDTH, text_ypix(&x->x_obj, glist)+1,
x, i, x);
+ }
else
! {
! post("%s coords %xi%d %d %d %d %d\n",
! x->x_canvas_name, x, i,
onset, text_ypix(&x->x_obj, glist),
onset + IOWIDTH, text_ypix(&x->x_obj, glist)+1);
! sys_vgui("%s coords %xi%d %d %d %d %d\n",
! x->x_canvas_name, x, i,
! onset, text_ypix(&x->x_obj, glist),
! onset + IOWIDTH, text_ypix(&x->x_obj, glist)+1);
! }
}
DEBUG(post("draw inlet end");)
***************
*** 144,155 ****
if (firsttime)
! sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xhandle\n",
! glist_getcanvas(glist),
onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 12,
onset + IOWIDTH-2, text_ypix(&x->x_obj, glist) + x->x_rect_height-4,
x);
else
! sys_vgui(".x%x.c coords %xhandle %d %d %d %d\n",
! glist_getcanvas(glist), x,
onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 12,
onset + IOWIDTH-2, text_ypix(&x->x_obj, glist) + x->x_rect_height-4);
--- 156,167 ----
if (firsttime)
! sys_vgui("%s create rectangle %d %d %d %d -tags %xhandle\n",
! x->x_canvas_name,
onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 12,
onset + IOWIDTH-2, text_ypix(&x->x_obj, glist) + x->x_rect_height-4,
x);
else
! sys_vgui("%s coords %xhandle %d %d %d %d\n",
! x->x_canvas_name, x,
onset, text_ypix(&x->x_obj, glist) + x->x_rect_height - 12,
onset + IOWIDTH-2, text_ypix(&x->x_obj, glist) + x->x_rect_height-4);
***************
*** 167,178 ****
/* Seems we have to delete the widget in case it already exists (Provided by Guenter)*/
! sys_vgui("destroy .x%x.c.s%x\n",glist_getcanvas(glist),x);
! sys_vgui("set %xw .x%x.c.s%x ; text $%xw -font {helvetica 10} -border 1 -highlightthickness 1 -relief sunken -bg \"%s\" -fg \"%s\" \n",
! x,canvas,x,x,x->x_bgcolour->s_name,x->x_fgcolour->s_name);
! if(x->x_mousefocus)
! sys_vgui("bind .x%x.c.s%x <Leave> {focus [winfo parent .x%x.c.s%x]} \n",
! canvas, x, canvas, x);
! sys_vgui("namespace eval entry%p {} \n", x);
}
--- 179,196 ----
/* Seems we have to delete the widget in case it already exists (Provided by Guenter)*/
! post("destroy %s\n", x->x_widget_name);
! sys_vgui("destroy %s\n", x->x_widget_name);
! sys_vgui("set %xw %s ; text $%xw -font {helvetica 10} -border 1 -highlightthickness 1 -relief sunken -bg \"%s\" -fg \"%s\" \n",
! x,x->x_widget_name,x,x->x_bgcolour->s_name,x->x_fgcolour->s_name);
! if(x->x_mousefocus)
! {
! post("bind %s <Leave> {focus [winfo parent %s]} \n",
! x->x_widget_name, x->x_widget_name);
! sys_vgui("bind %s <Leave> {focus [winfo parent %s]} \n",
! x->x_widget_name, x->x_widget_name);
! }
! post("namespace eval %s {} \n", x->x_receive_name->s_name);
! sys_vgui("namespace eval %s {} \n", x->x_receive_name->s_name);
}
***************
*** 185,197 ****
create_widget(x,glist);
x->x_glist = canvas;
! sys_vgui(".x%x.c create window %d %d -anchor nw -window .x%x.c.s%x -tags %xS -width %d -height %d \n",
! canvas,text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),x->x_glist,x,x, x->x_width, x->x_height);
}
else {
! sys_vgui(".x%x.c coords %xS \
! %d %d\n",
! canvas, x,
! text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist));
}
draw_inlets(x, glist, firsttime, 1,1);
--- 203,217 ----
create_widget(x,glist);
x->x_glist = canvas;
! post("%s create window %d %d -anchor nw -window %s -tags %xS -width %d -height %d \n",
! x->x_canvas_name,text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),x->x_widget_name,x, x->x_width, x->x_height);
! sys_vgui("%s create window %d %d -anchor nw -window %s -tags %xS -width %d -height %d \n",
! x->x_canvas_name,text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),x->x_widget_name,x, x->x_width, x->x_height);
}
else {
! post("%s coords %xS %d %d\n", x->x_canvas_name, x,
! text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist));
! sys_vgui("%s coords %xS %d %d\n", x->x_canvas_name, x,
! text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist));
}
draw_inlets(x, glist, firsttime, 1,1);
***************
*** 204,218 ****
{
DEBUG(post("erase");)
! sys_vgui("destroy .x%x.c.s%x\n",glist_getcanvas(glist),x);
! sys_vgui(".x%x.c delete %xS\n",glist_getcanvas(glist), x);
/* inlets and outlets */
/* Added tag for all inlets of one instance */
! sys_vgui(".x%x.c delete %xi\n",glist_getcanvas(glist),x);
! sys_vgui(".x%x.c delete %xo\n",glist_getcanvas(glist),x);
/* Added tag for all outlets of one instance */
! sys_vgui(".x%x.c delete %xhandle\n",glist_getcanvas(glist),x,0);
}
--- 224,243 ----
{
DEBUG(post("erase");)
! post("destroy %s\n",x->x_widget_name);
! sys_vgui("destroy %s\n",x->x_widget_name);
! post("%s delete %xS\n", x->x_canvas_name, x);
! sys_vgui("%s delete %xS\n", x->x_canvas_name, x);
/* inlets and outlets */
/* Added tag for all inlets of one instance */
! post("%s delete %xi\n", x->x_canvas_name,x);
! sys_vgui("%s delete %xi\n", x->x_canvas_name,x);
! post("%s delete %xo\n", x->x_canvas_name,x);
! sys_vgui("%s delete %xo\n", x->x_canvas_name,x);
/* Added tag for all outlets of one instance */
! post("%s delete %xhandle\n", x->x_canvas_name,x,0);
! sys_vgui("%s delete %xhandle\n", x->x_canvas_name,x,0);
}
***************
*** 245,250 ****
if (glist_isvisible(glist))
{
! sys_vgui(".x%x.c coords %xSEL %d %d %d %d\n",
! glist_getcanvas(glist), 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);
--- 270,277 ----
if (glist_isvisible(glist))
{
! post("%s coords %xSEL %d %d %d %d\n", x->x_canvas_name, 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);
! sys_vgui("%s coords %xSEL %d %d %d %d\n", x->x_canvas_name, 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);
***************
*** 260,265 ****
t_entry *x = (t_entry *)z;
if (state) {
! sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xSEL -outline blue\n",
! glist_getcanvas(glist),
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,
--- 287,297 ----
t_entry *x = (t_entry *)z;
if (state) {
! post("%s create rectangle %d %d %d %d -tags %xSEL -outline blue\n",
! x->x_canvas_name,
! 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);
! sys_vgui("%s create rectangle %d %d %d %d -tags %xSEL -outline blue\n",
! x->x_canvas_name,
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,
***************
*** 267,272 ****
}
else {
! sys_vgui(".x%x.c delete %xSEL\n",
! glist_getcanvas(glist), x);
}
}
--- 299,304 ----
}
else {
! post("%s delete %xSEL\n", x->x_canvas_name, x);
! sys_vgui("%s delete %xSEL\n", x->x_canvas_name, x);
}
}
***************
*** 294,308 ****
DEBUG(post("vis: %d",vis);)
if (vis) {
- #ifdef PD_MINOR_VERSION
y = (t_rtext *) rtext_new(glist, (t_text *)z);
! #else
! y = (t_rtext *) rtext_new(glist, (t_text *)z,0,0);
! #endif
! entry_drawme(s, glist, 1);
}
else {
! y = glist_findrtext(glist, (t_text *)z);
! entry_erase(s,glist);
! rtext_free(y);
}
}
--- 326,336 ----
DEBUG(post("vis: %d",vis);)
if (vis) {
y = (t_rtext *) rtext_new(glist, (t_text *)z);
! entry_drawme(s, glist, 1);
}
else {
! y = glist_findrtext(glist, (t_text *)z);
! entry_erase(s,glist);
! rtext_free(y);
}
}
***************
*** 329,344 ****
static void entry_set(t_entry* x, t_symbol *s, int argc, t_atom *argv)
{
int i;
t_symbol *tmp;
tmp = s; /* this gets rid of the unused variable warning */
! sys_vgui(".x%x.c.s%x delete 0.0 end \n", x->x_glist, x);
for(i=0; i<argc ; i++)
{
tmp = atom_getsymbol(argv+i);
! sys_vgui("lappend ::entry%p::list %s \n", x, tmp->s_name );
}
! sys_vgui(".x%x.c.s%x insert end $::entry%p::list ; unset ::entry%p::list \n",
! x->x_glist, x, x, x );
}
--- 357,377 ----
static void entry_set(t_entry* x, t_symbol *s, int argc, t_atom *argv)
{
+ DEBUG(post("entry_new"););
int i;
t_symbol *tmp;
tmp = s; /* this gets rid of the unused variable warning */
! post("%s delete 0.0 end \n", x->x_widget_name);
! sys_vgui("%s delete 0.0 end \n", x->x_widget_name);
for(i=0; i<argc ; i++)
{
tmp = atom_getsymbol(argv+i);
! post("lappend ::entry%lx::list %s \n", x, tmp->s_name );
! sys_vgui("lappend ::entry%lx::list %s \n", x, tmp->s_name );
}
! post("%s insert end $::entry%lx::list ; unset ::entry%lx::list \n",
! x->x_widget_name, x, x );
! sys_vgui("%s insert end $::entry%lx::list ; unset ::entry%lx::list \n",
! x->x_widget_name, x, x );
}
***************
*** 346,350 ****
static void entry_clear(t_entry* x)
{
! sys_vgui(".x%x.c.s%x delete 0.0 end \n", x->x_glist, x);
}
--- 379,384 ----
static void entry_clear(t_entry* x)
{
! DEBUG(post("%s delete 0.0 end \n", x->x_widget_name););
! sys_vgui("%s delete 0.0 end \n", x->x_widget_name);
}
***************
*** 360,371 ****
{
/* With "," and ";" escaping thanks to JMZ */
! sys_vgui("pd [concat entry%p output [string map {\",\" \"\\\\,\" \";\" \"\\\\;\"} [.x%x.c.s%x get 0.0 end]] \\;]\n", x, x->x_glist, x);
/* Without "," and ";" escaping, left here but commented out in case we want to add a kind of "pd terminal" mode in the future.
! sys_vgui("pd [concat entry%p output [.x%x.c.s%x get 0.0 end] \\;]\n", x, x->x_glist, x); */
if(x->x_mousefocus)
! sys_vgui("bind .x%x.c.s%x <Leave> {focus [winfo parent .x%x.c.s%x]} \n",
! x->x_glist, x, x->x_glist, x);
}
--- 394,410 ----
{
/* With "," and ";" escaping thanks to JMZ */
! post("pd [concat entry%lx output [string map {\",\" \"\\\\,\" \";\" \"\\\\;\"} [%s get 0.0 end]] \\;]\n", x, x->x_widget_name);
! sys_vgui("pd [concat entry%lx output [string map {\",\" \"\\\\,\" \";\" \"\\\\;\"} [%s get 0.0 end]] \\;]\n", x, x->x_widget_name);
/* Without "," and ";" escaping, left here but commented out in case we want to add a kind of "pd terminal" mode in the future.
! sys_vgui("pd [concat entry%lx output [%s get 0.0 end] \\;]\n", x, x->x_glist, x); */
if(x->x_mousefocus)
! {
! post("bind %s <Leave> {focus [winfo parent %s]} \n",
! x->x_widget_name, x->x_widget_name);
! sys_vgui("bind %s <Leave> {focus [winfo parent %s]} \n",
! x->x_widget_name, x->x_widget_name);
! }
}
***************
*** 388,391 ****
--- 427,431 ----
gensym("entry"), x->x_width, x->x_height, x->x_bgcolour, x->x_fgcolour);
binbuf_addv(b, ";");
+ // post("objectclass: %s", ((t_pd *)x)->);
}
***************
*** 393,398 ****
void entry_bgcolour(t_entry* x, t_symbol* bgcol)
{
! x->x_bgcolour->s_name = bgcol->s_name;
! sys_vgui(".x%x.c.s%x configure -background \"%s\" \n", x->x_glist, x, bgcol->s_name);
}
--- 433,439 ----
void entry_bgcolour(t_entry* x, t_symbol* bgcol)
{
! x->x_bgcolour = bgcol;
! post("%s configure -background \"%s\" \n", x->x_widget_name, bgcol->s_name);
! sys_vgui("%s configure -background \"%s\" \n", x->x_widget_name, x->x_bgcolour->s_name);
}
***************
*** 400,419 ****
void entry_fgcolour(t_entry* x, t_symbol* fgcol)
{
! x->x_fgcolour->s_name = fgcol->s_name;
! sys_vgui(".x%x.c.s%x configure -foreground \"%s\" \n", x->x_glist, x, fgcol->s_name);
}
static void entry_free(t_entry *x)
{
! pd_unbind(&x->x_obj.ob_pd, x->x_receive_name_symbol);
}
static void *entry_new(t_symbol *s, int argc, t_atom *argv)
{
t_entry *x = (t_entry *)pd_new(entry_class);
! char buf[256];
/*x->x_glist = (t_glist*)NULL;*/
! /*x->x_glist = canvas_getcurrent();*/
x->x_height = 1;
--- 441,470 ----
void entry_fgcolour(t_entry* x, t_symbol* fgcol)
{
! x->x_fgcolour = fgcol;
! post("%s configure -foreground \"%s\" \n", x->x_widget_name, fgcol->s_name);
! sys_vgui("%s configure -foreground \"%s\" \n", x->x_widget_name, x->x_fgcolour->s_name);
}
static void entry_free(t_entry *x)
{
! pd_unbind(&x->x_obj.ob_pd, x->x_receive_name);
}
static void *entry_new(t_symbol *s, int argc, t_atom *argv)
{
+ DEBUG(post("entry_new"););
t_entry *x = (t_entry *)pd_new(entry_class);
! char buf[MAXPDSTRING];
/*x->x_glist = (t_glist*)NULL;*/
!
! x->x_glist = canvas_getcurrent();
! snprintf(buf, MAXPDSTRING, ".x%lx.c", (long unsigned int) glist_getcanvas(x->x_glist));
! x->x_canvas_name = getbytes(strlen(buf));
! strncpy(x->x_canvas_name, buf, strlen(buf));
! snprintf(buf, MAXPDSTRING, "%s.s%lx", x->x_canvas_name, (long unsigned int) x);
! x->x_widget_name = getbytes(strlen(buf));
! strncpy(x->x_widget_name, buf, strlen(buf));
! post("canvas: %s \nwidget: %s ",x->x_canvas_name, x->x_widget_name);
x->x_height = 1;
***************
*** 442,449 ****
x->x_height = x->x_char_height*5; */
! /* Bind the recieve "entry%p" to the widget instance*/
! snprintf(buf,MAXPDSTRING,"entry%p",x);
! x->x_receive_name_symbol = gensym(buf);
! pd_bind(&x->x_obj.ob_pd, x->x_receive_name_symbol);
x->x_data_outlet = outlet_new(&x->x_obj, &s_float);
--- 493,500 ----
x->x_height = x->x_char_height*5; */
! /* Bind the recieve "entry%lx" to the widget instance*/
! snprintf(buf,MAXPDSTRING,"entry%lx",(long unsigned int)x);
! x->x_receive_name = gensym(buf);
! pd_bind(&x->x_obj.ob_pd, x->x_receive_name);
x->x_data_outlet = outlet_new(&x->x_obj, &s_float);