aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2007-11-22 05:57:45 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2007-11-22 05:57:45 +0000
commitdc52874be8ee2b471502809380354249b251b58a (patch)
tree72702ba59d8654ef17a2711d12604c0c8c616218
parente1e0533814d29fea5d0ba318df034a9e82ec6df3 (diff)
- removed xscrollcommand and yscrollcommand from supported options since
currently they use generated names, i.e. canvas_id, etc. Perhaps it's possible to support user override of these, but it probably would not be simple - renamed "inlets" functions to "iolets" since they handle outlets too - fixed bug in save logic that made the options get appended everytime it was saved: I needed to binbuf_clear() first. - created tkwidgets_restore_options() and implemented it in [text]. It turned out to be quite easy since Tk's "canvas configure" can take the whole slew of options all at once. svn path=/trunk/externals/tkwidgets/; revision=9024
-rw-r--r--shared/tkwidgets.c32
-rw-r--r--shared/tkwidgets.h6
-rw-r--r--text.c42
3 files changed, 39 insertions, 41 deletions
diff --git a/shared/tkwidgets.c b/shared/tkwidgets.c
index a2c520f..7b1dc4f 100644
--- a/shared/tkwidgets.c
+++ b/shared/tkwidgets.c
@@ -43,39 +43,35 @@ void tkwidgets_query_options(t_symbol *receive_name, t_symbol *widget_id,
receive_name->s_name, argv[i], widget_id->s_name, argv[i]);
}
-/* this function queries the widget and sends the data to the store_callback */
+/* this queries the widget for each option listed in the tk_options struct,
+ * builts a list in Tcl-space, then send that list to the store_callback */
void tkwidgets_store_options(t_symbol *receive_name, t_symbol *tcl_namespace,
t_symbol *widget_id, int argc, char **argv)
{
- // build list then send the whole shebang to store_callback
int i;
- post("tkwidgets_store_options total options: %d", argc);
for(i = 0; i < argc; i++)
{
- // TODO: only send if there is a value, not when blank
sys_vgui("set ::%s::ret [%s cget -%s]\n",
tcl_namespace->s_name, widget_id->s_name, argv[i]);
sys_vgui("if {[string length $::%s::ret] > 0} {\n",
tcl_namespace->s_name);
- sys_vgui("lappend ::%s::store_list -%s ; lappend ::%s::store_list $::%s::ret}\n",
+ sys_vgui("lappend ::%s::list -%s; lappend ::%s::list $::%s::ret}\n",
tcl_namespace->s_name, argv[i],
tcl_namespace->s_name, tcl_namespace->s_name);
}
- sys_vgui("pd [concat %s store_callback $::%s::store_list \\;]\n",
+ sys_vgui("pd [concat %s store_callback $::%s::list \\;]\n",
receive_name->s_name, tcl_namespace->s_name);
- sys_vgui("unset ::%s::store_list \n", tcl_namespace->s_name);
+ sys_vgui("unset ::%s::list \n", tcl_namespace->s_name);
}
-void tkwidgets_restore_options(t_symbol *receive_name, t_symbol *widget_id,
- int argc, char** argv)
+void tkwidgets_restore_options(t_symbol *receive_name, t_symbol *tcl_namespace,
+ t_symbol *widget_id, t_binbuf *options_binbuf)
{
- int i;
- for(i = 0; i < argc; i++)
- {
- // TODO parse out -flags and values, and set them here:
- sys_vgui("%s configure %s\n",
- widget_id->s_name, argv[i]);
- }
+ int length;
+ char *options;
+ binbuf_gettext(options_binbuf, &options, &length);
+ options[length] = 0; //binbuf_gettext() doesn't put a null, so we do
+ sys_vgui("%s configure %s\n", widget_id->s_name, options);
}
/* -------------------- generate names for various elements ----------------- */
@@ -160,7 +156,7 @@ static int calculate_onset(int x_location, int width,
* current_iolet / (total_iolets == 1 ? 1 : total_iolets - 1));
}
-void tkwidgets_draw_inlets(t_object *x, t_glist *glist, t_symbol *canvas_id,
+void tkwidgets_draw_iolets(t_object *x, t_glist *glist, t_symbol *canvas_id,
t_symbol *iolets_tag, t_symbol *all_tag,
int width, int height,
int total_inlets, int total_outlets)
@@ -189,7 +185,7 @@ void tkwidgets_draw_inlets(t_object *x, t_glist *glist, t_symbol *canvas_id,
}
}
-void tkwidgets_erase_inlets(t_symbol* canvas_id, t_symbol* iolets_tag)
+void tkwidgets_erase_iolets(t_symbol* canvas_id, t_symbol* iolets_tag)
{
sys_vgui("%s delete %s\n", canvas_id->s_name, iolets_tag);
}
diff --git a/shared/tkwidgets.h b/shared/tkwidgets.h
index 999e2ac..171b3c7 100644
--- a/shared/tkwidgets.h
+++ b/shared/tkwidgets.h
@@ -71,6 +71,8 @@ void tkwidgets_setcallbackname(void *x, char *widget_name);
/* handle options */
void tkwidgets_store_options(t_symbol *receive_name, t_symbol *tcl_namespace,
t_symbol *widget_id, int argc, char **argv);
+void tkwidgets_restore_options(t_symbol *receive_name, t_symbol *tcl_namespace,
+ t_symbol *widget_id, t_binbuf *options_binbuf);
void tkwidgets_query_options(t_symbol *receive_name, t_symbol *widget_id,
int argc, char** argv);
@@ -89,11 +91,11 @@ t_symbol* tkwidgets_gen_all_tag(t_object *x);
// TODO perhaps I should try to use glist_drawiofor() from g_text.c
-void tkwidgets_draw_inlets(t_object *x, t_glist *glist, t_symbol *canvas_id,
+void tkwidgets_draw_iolets(t_object *x, t_glist *glist, t_symbol *canvas_id,
t_symbol *iolets_tag, t_symbol *all_tag,
int width, int height,
int total_inlets, int total_outlets);
-void tkwidgets_erase_inlets(t_symbol* canvas_id, t_symbol* iolets_tag);
+void tkwidgets_erase_iolets(t_symbol* canvas_id, t_symbol* iolets_tag);
void tkwidgets_draw_handle(); // TODO draw resize handle when selected in editmode
void tkwidgets_draw_resize_window(); // TODO draw the resize window while resizing
diff --git a/text.c b/text.c
index 65eab40..5ec1d84 100644
--- a/text.c
+++ b/text.c
@@ -30,7 +30,8 @@
/* TODO: remove glist from _erase() args */
/* TODO: window name "handle1376fc00" already exists in parent */
/* TODO: figure out window vs. text width/height */
-
+/* TODO: move bind_* to tkwidgets.c */
+/* TODO: erase iolets on resize, they are leaving old ones behind */
#define DEFAULT_COLOR "grey70"
@@ -111,8 +112,6 @@ static char *textwidget_tk_options[] = {
"undo",
"width",
"wrap",
- "xscrollcommand",
- "yscrollcommand"
};
@@ -237,7 +236,7 @@ static void textwidget_drawme(t_textwidget *x, t_glist *glist)
DEBUG(post("textwidget_drawme: firsttime %d canvas %lx glist %lx", x->x_canvas, glist););
set_tkwidgets_ids(x,glist_getcanvas(glist));
create_widget(x);
- tkwidgets_draw_inlets((t_object*)x, glist,
+ tkwidgets_draw_iolets((t_object*)x, glist,
x->canvas_id, x->iolets_tag, x->all_tag,
x->width, x->height, TOTAL_INLETS, TOTAL_OUTLETS);
if(x->have_scrollbars) draw_scrollbar(x);
@@ -246,6 +245,8 @@ static void textwidget_drawme(t_textwidget *x, t_glist *glist)
text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
x->frame_id->s_name, x->window_tag->s_name, x->all_tag->s_name,
x->width, x->height);
+ tkwidgets_restore_options(x->receive_name, x->tcl_namespace,
+ x->widget_id, x->options_binbuf);
}
static void textwidget_erase(t_textwidget* x,t_glist* glist)
@@ -253,7 +254,7 @@ static void textwidget_erase(t_textwidget* x,t_glist* glist)
DEBUG(post("textwidget_erase: canvas %lx glist %lx", x->x_canvas, glist););
set_tkwidgets_ids(x,glist_getcanvas(glist));
- tkwidgets_erase_inlets(x->canvas_id, x->iolets_tag);
+ tkwidgets_erase_iolets(x->canvas_id, x->iolets_tag);
sys_vgui("destroy %s\n", x->frame_id->s_name);
sys_vgui("%s delete %s\n", x->canvas_id->s_name, x->all_tag->s_name);
}
@@ -540,7 +541,7 @@ static void textwidget_option(t_textwidget *x, t_symbol *s, int argc, t_atom *ar
x->widget_id->s_name, s->s_name, argument_buffer);
tkwidgets_store_options(x->receive_name, x->tcl_namespace, x->widget_id,
sizeof(textwidget_tk_options)/sizeof(char *),
- &textwidget_tk_options);
+ (char **)&textwidget_tk_options);
}
}
@@ -598,8 +599,8 @@ static void textwidget_size(t_textwidget *x, t_float width, t_float height)
{
sys_vgui("%s itemconfigure %s -width %d -height %d\n",
x->canvas_id->s_name, x->window_tag->s_name, x->width, x->height);
- tkwidgets_erase_inlets(x->canvas_id, x->iolets_tag);
- tkwidgets_draw_inlets((t_object*)x, x->x_glist,
+ tkwidgets_erase_iolets(x->canvas_id, x->iolets_tag);
+ tkwidgets_draw_iolets((t_object*)x, x->x_glist,
x->canvas_id, x->iolets_tag, x->all_tag,
x->width, x->height, TOTAL_INLETS, TOTAL_OUTLETS);
canvas_fixlinesfor(x->x_glist, (t_text *)x); // 2nd inlet
@@ -611,7 +612,12 @@ static void textwidget_size(t_textwidget *x, t_float width, t_float height)
static void textwidget_store_callback(t_textwidget *x, t_symbol *s, int argc, t_atom *argv)
{
if(s != &s_)
+ {
+ binbuf_clear(x->options_binbuf);
binbuf_restore(x->options_binbuf, argc, argv);
+ }
+ else
+ post("ERROR: does this ever happen?");
}
static void textwidget_query_callback(t_textwidget *x, t_symbol *s, int argc, t_atom *argv)
@@ -640,19 +646,16 @@ static void textwidget_resize_click_callback(t_textwidget *x, t_floatarg f)
{
t_canvas *canvas = (glist_isvisible(x->x_glist) ? x->x_canvas : 0);
int newstate = (int)f;
- if (x->x_resizing && newstate == 0)
+ if (x->x_resizing && !newstate && canvas)
{
- if (canvas)
- {
- tkwidgets_draw_inlets((t_object*)x, canvas,
- x->canvas_id, x->iolets_tag, x->all_tag,
- x->width, x->height, TOTAL_INLETS, TOTAL_OUTLETS);
- canvas_fixlinesfor(x->x_glist, (t_text *)x); // 2nd inlet
- }
+ tkwidgets_draw_iolets((t_object*)x, canvas,
+ x->canvas_id, x->iolets_tag, x->all_tag,
+ x->width, x->height, TOTAL_INLETS, TOTAL_OUTLETS);
+ canvas_fixlinesfor(x->x_glist, (t_text *)x); // 2nd inlet
}
- else if (!x->x_resizing && newstate)
+ if (!x->x_resizing && newstate)
{
- tkwidgets_erase_inlets(x->canvas_id, x->iolets_tag);
+ tkwidgets_erase_iolets(x->canvas_id, x->iolets_tag);
}
x->x_resizing = newstate;
}
@@ -707,10 +710,7 @@ static void *textwidget_new(t_symbol *s, int argc, t_atom *argv)
x->height = atom_getint(argv + 1);
x->have_scrollbars = atom_getint(argv + 2);
if(argc > 3)
- {
binbuf_add(x->options_binbuf, argc - 3, argv + 3);
-//TODO tkwidgets_restore_options(x->receive_name, x->widget_id);
- }
}
x->tcl_namespace = tkwidgets_gen_tcl_namespace((t_object*)x, s);