summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/src/x_gui.c
diff options
context:
space:
mode:
authorPeter D'Hoye <peter.dhoye@gmail.com>2009-05-24 21:28:16 +0000
committerPeter D'Hoye <peter.dhoye@gmail.com>2009-05-24 21:28:16 +0000
commit526b5580dabbfed7cfe5439dc3a90ec727f563c2 (patch)
tree22b1af92348785daad16714ee5e2b633017e0e48 /apps/plugins/pdbox/PDa/src/x_gui.c
parent4f2dfcc01b260d946044ef2b6af5fe36cb772c8d (diff)
downloadrockbox-526b5580dabbfed7cfe5439dc3a90ec727f563c2.tar.gz
rockbox-526b5580dabbfed7cfe5439dc3a90ec727f563c2.zip
Cut the files in half and it might work better (note to self: check your tree is really clean before patching)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21070 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/x_gui.c')
-rw-r--r--apps/plugins/pdbox/PDa/src/x_gui.c376
1 files changed, 0 insertions, 376 deletions
diff --git a/apps/plugins/pdbox/PDa/src/x_gui.c b/apps/plugins/pdbox/PDa/src/x_gui.c
index edff70e8cd..c54fef948d 100644
--- a/apps/plugins/pdbox/PDa/src/x_gui.c
+++ b/apps/plugins/pdbox/PDa/src/x_gui.c
@@ -375,380 +375,4 @@ void x_gui_setup(void)
375 savepanel_setup(); 375 savepanel_setup();
376 key_setup(); 376 key_setup();
377} 377}
378/* Copyright (c) 1997-2000 Miller Puckette.
379* For information on usage and redistribution, and for a DISCLAIMER OF ALL
380* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
381
382/* dialogs. LATER, deal with the situation where the object goes
383away before the panel does... */
384
385#include "m_pd.h"
386#include <stdio.h>
387#include <string.h>
388#ifdef UNIX
389#include <unistd.h>
390#endif
391
392/* --------------------- graphics responder ---------------- */
393
394/* make one of these if you want to put up a dialog window but want to be
395protected from getting deleted and then having the dialog call you back. In
396this design the calling object doesn't have to keep the address of the dialog
397window around; instead we keep a list of all open dialogs. Any object that
398might have dialogs, when it is deleted, simply checks down the dialog window
399list and breaks off any dialogs that might later have sent messages to it.
400Only when the dialog window itself closes do we delete the gfxstub object. */
401
402static t_class *gfxstub_class;
403
404typedef struct _gfxstub
405{
406 t_pd x_pd;
407 t_pd *x_owner;
408 void *x_key;
409 t_symbol *x_sym;
410 struct _gfxstub *x_next;
411} t_gfxstub;
412
413static t_gfxstub *gfxstub_list;
414
415 /* create a new one. the "key" is an address by which the owner
416 will identify it later; if the owner only wants one dialog, this
417 could just be a pointer to the owner itself. The string "cmd"
418 is a TK command to create the dialog, with "%s" embedded in
419 it so we can provide a name by which the GUI can send us back
420 messages; e.g., "pdtk_canvas_dofont %s 10". */
421
422void gfxstub_new(t_pd *owner, void *key, const char *cmd)
423{
424 char buf[MAXPDSTRING];
425 char namebuf[80];
426 t_gfxstub *x;
427 t_symbol *s;
428 /* if any exists with matching key, no need to make a
429 new one; just tell tk to send it front. */
430 for (x = gfxstub_list; x; x = x->x_next)
431 {
432 if (x->x_key == key)
433 {
434 sys_vgui("raise .gfxstub%x\n", x);
435 sys_vgui("focus .gfxstub%x\n", x);
436 return;
437 }
438 }
439 if (strlen(cmd) + 84 > MAXPDSTRING)
440 return;
441 x = (t_gfxstub *)pd_new(gfxstub_class);
442 sprintf(namebuf, ".gfxstub%x", (t_int)x);
443
444 s = gensym(namebuf);
445 pd_bind(&x->x_pd, s);
446 x->x_owner = owner;
447 x->x_sym = s;
448 x->x_key = key;
449 x->x_next = gfxstub_list;
450 gfxstub_list = x;
451 sprintf(buf, cmd, s->s_name);
452 sys_gui(buf);
453}
454
455static void gfxstub_offlist(t_gfxstub *x)
456{
457 t_gfxstub *y1, *y2;
458 if (gfxstub_list == x)
459 gfxstub_list = x->x_next;
460 else for (y1 = gfxstub_list; y2 = y1->x_next; y1 = y2)
461 if (y2 == x)
462 {
463 y1->x_next = y2->x_next;
464 break;
465 }
466}
467
468 /* if the owner disappears, we still may have to stay around until our
469 dialog window signs off. Anyway we can now tell the GUI to destroy the
470 window. */
471void gfxstub_deleteforkey(void *key)
472{
473 t_gfxstub *y;
474 int didit = 1;
475 while (didit)
476 {
477 didit = 0;
478 for (y = gfxstub_list; y; y = y->x_next)
479 {
480 if (y->x_key == key)
481 {
482 sys_vgui("destroy .gfxstub%x\n", y);
483 y->x_owner = 0;
484 gfxstub_offlist(y);
485 didit = 1;
486 break;
487 }
488 }
489 }
490}
491
492/* --------- pd messages for gfxstub (these come from the GUI) ---------- */
493
494 /* "cancel" to request that we close the dialog window. */
495static void gfxstub_cancel(t_gfxstub *x)
496{
497 gfxstub_deleteforkey(x->x_key);
498}
499
500 /* "signoff" comes from the GUI to say the dialog window closed. */
501static void gfxstub_signoff(t_gfxstub *x)
502{
503 gfxstub_offlist(x);
504 pd_free(&x->x_pd);
505}
506
507static t_binbuf *gfxstub_binbuf;
508
509 /* a series of "data" messages rebuilds a scalar */
510static void gfxstub_data(t_gfxstub *x, t_symbol *s, int argc, t_atom *argv)
511{
512 if (!gfxstub_binbuf)
513 gfxstub_binbuf = binbuf_new();
514 binbuf_add(gfxstub_binbuf, argc, argv);
515 binbuf_addsemi(gfxstub_binbuf);
516}
517 /* the "end" message terminates rebuilding the scalar */
518static void gfxstub_end(t_gfxstub *x)
519{
520 canvas_dataproperties((t_canvas *)x->x_owner,
521 (t_scalar *)x->x_key, gfxstub_binbuf);
522 binbuf_free(gfxstub_binbuf);
523 gfxstub_binbuf = 0;
524}
525
526 /* anything else is a message from the dialog window to the owner;
527 just forward it. */
528static void gfxstub_anything(t_gfxstub *x, t_symbol *s, int argc, t_atom *argv)
529{
530 if (x->x_owner)
531 pd_typedmess(x->x_owner, s, argc, argv);
532}
533
534static void gfxstub_free(t_gfxstub *x)
535{
536 pd_unbind(&x->x_pd, x->x_sym);
537}
538
539static void gfxstub_setup(void)
540{
541 gfxstub_class = class_new(gensym("gfxstub"), (t_newmethod)gfxstub_new,
542 (t_method)gfxstub_free,
543 sizeof(t_gfxstub), CLASS_PD, 0);
544 class_addanything(gfxstub_class, gfxstub_anything);
545 class_addmethod(gfxstub_class, (t_method)gfxstub_signoff,
546 gensym("signoff"), 0);
547 class_addmethod(gfxstub_class, (t_method)gfxstub_data,
548 gensym("data"), A_GIMME, 0);
549 class_addmethod(gfxstub_class, (t_method)gfxstub_end,
550 gensym("end"), 0);
551 class_addmethod(gfxstub_class, (t_method)gfxstub_cancel,
552 gensym("cancel"), 0);
553}
554
555/* -------------------------- openpanel ------------------------------ */
556
557static t_class *openpanel_class;
558
559typedef struct _openpanel
560{
561 t_object x_obj;
562 t_symbol *x_s;
563} t_openpanel;
564
565static void *openpanel_new(void)
566{
567 char buf[50];
568 t_openpanel *x = (t_openpanel *)pd_new(openpanel_class);
569 sprintf(buf, "d%x", (t_int)x);
570 x->x_s = gensym(buf);
571 pd_bind(&x->x_obj.ob_pd, x->x_s);
572 outlet_new(&x->x_obj, &s_symbol);
573 return (x);
574}
575
576static void openpanel_bang(t_openpanel *x)
577{
578 sys_vgui("pdtk_openpanel %s\n", x->x_s->s_name);
579}
580
581static void openpanel_symbol(t_openpanel *x, t_symbol *s)
582{
583 outlet_symbol(x->x_obj.ob_outlet, s);
584}
585
586static void openpanel_free(t_openpanel *x)
587{
588 pd_unbind(&x->x_obj.ob_pd, x->x_s);
589}
590
591static void openpanel_setup(void)
592{
593 openpanel_class = class_new(gensym("openpanel"),
594 (t_newmethod)openpanel_new, (t_method)openpanel_free,
595 sizeof(t_openpanel), 0, A_DEFFLOAT, 0);
596 class_addbang(openpanel_class, openpanel_bang);
597 class_addsymbol(openpanel_class, openpanel_symbol);
598}
599
600/* -------------------------- savepanel ------------------------------ */
601
602static t_class *savepanel_class;
603
604typedef struct _savepanel
605{
606 t_object x_obj;
607 t_symbol *x_s;
608} t_savepanel;
609
610static void *savepanel_new(void)
611{
612 char buf[50];
613 t_savepanel *x = (t_savepanel *)pd_new(savepanel_class);
614 sprintf(buf, "d%x", (t_int)x);
615 x->x_s = gensym(buf);
616 pd_bind(&x->x_obj.ob_pd, x->x_s);
617 outlet_new(&x->x_obj, &s_symbol);
618 return (x);
619}
620
621static void savepanel_bang(t_savepanel *x)
622{
623 sys_vgui("pdtk_savepanel %s\n", x->x_s->s_name);
624}
625
626static void savepanel_symbol(t_savepanel *x, t_symbol *s)
627{
628 outlet_symbol(x->x_obj.ob_outlet, s);
629}
630
631static void savepanel_free(t_savepanel *x)
632{
633 pd_unbind(&x->x_obj.ob_pd, x->x_s);
634}
635
636static void savepanel_setup(void)
637{
638 savepanel_class = class_new(gensym("savepanel"),
639 (t_newmethod)savepanel_new, (t_method)savepanel_free,
640 sizeof(t_savepanel), 0, A_DEFFLOAT, 0);
641 class_addbang(savepanel_class, savepanel_bang);
642 class_addsymbol(savepanel_class, savepanel_symbol);
643}
644
645/* ---------------------- key and its relatives ------------------ */
646
647static t_symbol *key_sym, *keyup_sym, *keyname_sym;
648static t_class *key_class, *keyup_class, *keyname_class;
649
650typedef struct _key
651{
652 t_object x_obj;
653} t_key;
654
655static void *key_new( void)
656{
657 t_key *x = (t_key *)pd_new(key_class);
658 outlet_new(&x->x_obj, &s_float);
659 pd_bind(&x->x_obj.ob_pd, key_sym);
660 return (x);
661}
662
663static void key_float(t_key *x, t_floatarg f)
664{
665 outlet_float(x->x_obj.ob_outlet, f);
666}
667
668static void key_free(t_key *x)
669{
670 pd_unbind(&x->x_obj.ob_pd, key_sym);
671}
672
673typedef struct _keyup
674{
675 t_object x_obj;
676} t_keyup;
677
678static void *keyup_new( void)
679{
680 t_keyup *x = (t_keyup *)pd_new(keyup_class);
681 outlet_new(&x->x_obj, &s_float);
682 pd_bind(&x->x_obj.ob_pd, keyup_sym);
683 return (x);
684}
685
686static void keyup_float(t_keyup *x, t_floatarg f)
687{
688 outlet_float(x->x_obj.ob_outlet, f);
689}
690
691static void keyup_free(t_keyup *x)
692{
693 pd_unbind(&x->x_obj.ob_pd, keyup_sym);
694}
695
696typedef struct _keyname
697{
698 t_object x_obj;
699 t_outlet *x_outlet1;
700 t_outlet *x_outlet2;
701} t_keyname;
702
703static void *keyname_new( void)
704{
705 t_keyname *x = (t_keyname *)pd_new(keyname_class);
706 x->x_outlet1 = outlet_new(&x->x_obj, &s_float);
707 x->x_outlet2 = outlet_new(&x->x_obj, &s_symbol);
708 pd_bind(&x->x_obj.ob_pd, keyname_sym);
709 return (x);
710}
711
712static void keyname_list(t_keyname *x, t_symbol *s, int ac, t_atom *av)
713{
714 outlet_symbol(x->x_outlet2, atom_getsymbolarg(1, ac, av));
715 outlet_float(x->x_outlet1, atom_getfloatarg(0, ac, av));
716}
717
718static void keyname_free(t_keyname *x)
719{
720 pd_unbind(&x->x_obj.ob_pd, keyname_sym);
721}
722
723static void key_setup(void)
724{
725 key_class = class_new(gensym("key"),
726 (t_newmethod)key_new, (t_method)key_free,
727 sizeof(t_key), CLASS_NOINLET, 0);
728 class_addfloat(key_class, key_float);
729 key_sym = gensym("#key");
730 378
731 keyup_class = class_new(gensym("keyup"),
732 (t_newmethod)keyup_new, (t_method)keyup_free,
733 sizeof(t_keyup), CLASS_NOINLET, 0);
734 class_addfloat(keyup_class, keyup_float);
735 keyup_sym = gensym("#keyup");
736 class_sethelpsymbol(keyup_class, gensym("key"));
737
738 keyname_class = class_new(gensym("keyname"),
739 (t_newmethod)keyname_new, (t_method)keyname_free,
740 sizeof(t_keyname), CLASS_NOINLET, 0);
741 class_addlist(keyname_class, keyname_list);
742 keyname_sym = gensym("#keyname");
743 class_sethelpsymbol(keyname_class, gensym("key"));
744}
745
746/* -------------------------- setup routine ------------------------------ */
747
748void x_gui_setup(void)
749{
750 gfxstub_setup();
751 openpanel_setup();
752 savepanel_setup();
753 key_setup();
754}