From 2a320ac2fbd246be7b0844fe00b543bcd1bae271 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 21 Nov 2007 22:19:12 +0000 Subject: - created functions to generate all the various Tk IDs and tags and ported text.c to use those functions - started sketch for checkbutton.c svn path=/trunk/externals/tkwidgets/; revision=9020 --- text.c | 250 +++++++++++++++++++++++++++++------------------------------------ 1 file changed, 113 insertions(+), 137 deletions(-) (limited to 'text.c') diff --git a/text.c b/text.c index d420c6d..ddb9697 100644 --- a/text.c +++ b/text.c @@ -43,30 +43,28 @@ typedef struct _textwidget { - t_object x_obj; - t_canvas* x_canvas; - t_glist* x_glist; + t_object x_obj; + t_canvas* x_canvas; /* canvas/glist this widget is currently drawn in*/ + t_glist* x_glist; /* glist that owns this widget */ + t_binbuf* options_binbuf;/* binbuf to save options state in */ - t_symbol* receive_name; + int size_x; + int size_y; + int x_have_scrollbars; - t_binbuf* options_binbuf; - - int size_x; - int size_y; - int x_have_scrollbars; - - int x_resizing; - int x_selected; + int x_resizing; + int x_selected; /* IDs for Tk widgets */ - char* tcl_namespace; - char* canvas_id; - char* frame_id; - char* text_id; - char* scrollbar_id; - char* handle_id; - char* window_tag; - char* all_tag; + t_symbol* tcl_namespace; + t_symbol* receive_name; /* name to bind to to receive callbacks */ + t_symbol* canvas_id; + t_symbol* frame_id; + t_symbol* widget_id; + t_symbol* scrollbar_id; + t_symbol* handle_id; + t_symbol* window_id; + t_symbol* all_tag; t_outlet* x_data_outlet; t_outlet* x_status_outlet; @@ -113,7 +111,7 @@ static char *textwidget_tk_options[] = { }; -/* move these to tkwidgets.c */ +/* common symbols to preload */ static t_symbol *scrollbars_symbol; static t_symbol *size_symbol; static t_symbol *backspace_symbol; @@ -162,14 +160,14 @@ static void store_options(t_textwidget *x) { // TODO: only send if there is a value, not when blank sys_vgui("lappend ::%s::store_list -%s \n", - x->tcl_namespace, textwidget_tk_options[i]); + x->tcl_namespace->s_name, textwidget_tk_options[i]); sys_vgui("lappend ::%s::store_list [%s cget -%s] \n", - x->tcl_namespace, x->text_id, textwidget_tk_options[i]); + x->tcl_namespace->s_name, x->widget_id, textwidget_tk_options[i]); post("option %d: %s", i, textwidget_tk_options[i]); } sys_vgui("pd [concat %s store_callback $::%s::store_list \\;]\n", - x->receive_name->s_name, x->tcl_namespace); - sys_vgui("unset ::%s::store_list \n", x->tcl_namespace); + x->receive_name->s_name, x->tcl_namespace->s_name); + sys_vgui("unset ::%s::store_list \n", x->tcl_namespace->s_name); } static void restore_options(t_textwidget *x) @@ -177,42 +175,15 @@ static void restore_options(t_textwidget *x) // TODO restore options from x->options_binbuf } -static void set_tk_widget_ids(t_textwidget *x, t_canvas *canvas) +static void set_tkwidgets_ids(t_textwidget *x, t_canvas *canvas) { - char buf[MAXPDSTRING]; - x->x_canvas = canvas; - - /* Tk ID for the current canvas that this object is drawn in */ - sprintf(buf,".x%lx.c", (long unsigned int) canvas); - x->canvas_id = getbytes(strlen(buf)); - strcpy(x->canvas_id, buf); - - /* Tk ID for the "frame" the other things are drawn in */ - sprintf(buf,"%s.frame%lx", x->canvas_id, (long unsigned int)x); - x->frame_id = getbytes(strlen(buf)); - 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); - x->handle_id = getbytes(strlen(buf)); - 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" */ + x->canvas_id = tkwidgets_gen_canvas_id(x->x_canvas); + x->frame_id = tkwidgets_gen_frame_id((t_object*)x, x->canvas_id); + x->widget_id = tkwidgets_gen_widget_id((t_object*)x, x->frame_id); + x->scrollbar_id = tkwidgets_gen_scrollbar_id((t_object*)x, x->frame_id); + x->window_id = tkwidgets_gen_window_id((t_object*)x, x->frame_id); + x->handle_id = tkwidgets_gen_handle_id((t_object *)x, x->canvas_id); } static int calculate_onset(t_textwidget *x, t_glist *glist, @@ -233,17 +204,17 @@ static void textwidget_draw_inlets(t_textwidget *x, t_glist *glist, int firsttim { onset = calculate_onset(x, glist, i, total_inlets); 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) - 2, + x->canvas_id->s_name, onset, text_ypix(&x->x_obj, glist) - 2, onset + IOWIDTH, text_ypix(&x->x_obj, glist), - x, i, x, x->all_tag); + x, i, x, x->all_tag->s_name); } for (i = 0; i < total_outlets; i++) /* outlets */ { onset = calculate_onset(x, glist, i, total_outlets); 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->size_y, + x->canvas_id->s_name, onset, text_ypix(&x->x_obj, glist) + x->size_y, onset + IOWIDTH, text_ypix(&x->x_obj, glist) + x->size_y + 2, - x, i, x, x->all_tag); + x, i, x, x->all_tag->s_name); } } @@ -251,21 +222,21 @@ static void erase_inlets(t_textwidget *x) { DEBUG(post("erase_inlets");); /* Added tag for all inlets/outlets of one instance */ - sys_vgui("%s delete %xi\n", x->canvas_id, x); - sys_vgui("%s delete %xo\n", x->canvas_id, x); + sys_vgui("%s delete %xi\n", x->canvas_id->s_name, x); + sys_vgui("%s delete %xo\n", x->canvas_id->s_name, x); } static void draw_scrollbar(t_textwidget *x) { sys_vgui("pack %s -side right -fill y -before %s \n", - x->scrollbar_id, x->text_id); + x->scrollbar_id->s_name, x->widget_id->s_name); x->x_have_scrollbars = 1; } static void erase_scrollbar(t_textwidget *x) { - sys_vgui("pack forget %s \n", x->scrollbar_id); + sys_vgui("pack forget %s \n", x->scrollbar_id->s_name); x->x_have_scrollbars = 0; } @@ -273,14 +244,14 @@ static void bind_standard_keys(t_textwidget *x) { #ifdef __APPLE__ sys_vgui("bind %s {pdtk_canvas_ctrlkey %s %%K 0}\n", - x->text_id, x->canvas_id); + x->widget_id->s_name, x->canvas_id->s_name); sys_vgui("bind %s {pdtk_canvas_ctrlkey %s %%K 1}\n", - x->text_id, x->canvas_id); + x->widget_id->s_name, x->canvas_id->s_name); #else sys_vgui("bind %s {pdtk_canvas_ctrlkey %s %%K 0}\n", - x->text_id, x->canvas_id); + x->widget_id->s_name, x->canvas_id->s_name); sys_vgui("bind %s {pdtk_canvas_ctrlkey %s %%K 1}\n", - x->text_id, x->canvas_id); + x->widget_id->s_name, x->canvas_id->s_name); #endif } @@ -289,26 +260,33 @@ static void bind_button_events(t_textwidget *x) /* mouse buttons */ sys_vgui("bind %s