aboutsummaryrefslogtreecommitdiff
path: root/checkbutton.c
blob: 371ff4832230f507dbf358d830565c1f4b21dd1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/* [checkbutton] object for dislaying a check box

   Copyright (C) 2002-2004 Guenter Geiger
   Copyright (C) 2007 Hans-Christoph Steiner <hans@at.or.at>

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

   This is part of the tkwidgets library for Pd.

*/

#include "shared/tkwidgets.h"

/* ------------------------ class variables --------------------------------- */

static t_class *checkbutton_class;
static t_widgetbehavior checkbutton_widgetbehavior;

typedef struct _checkbutton
{
    t_object     x_obj;
    t_glist*     x_glist;
    int          x_width;
    int          x_height;
    
    /* IDs for Tk widgets */
	t_symbol*   tcl_namespace;       
    t_symbol*   receive_name;  /* name to bind to to receive callbacks */
	t_symbol*   canvas_id;  
	t_symbol*   widget_id;        
	t_symbol*   handle_id;      
	t_symbol*   all_tag;
    
    t_outlet*   x_data_outlet;
    t_outlet*   x_status_outlet;
} t_checkbutton;

static char *checkbutton_tk_options[] = {
    "activebackground",
    "activeforeground",
    "anchor",
    "background",
    "bitmap",
    "borderwidth",
    "command",
    "compound",
    "cursor",
    "disabledforeground",
    "font",
    "foreground",
    "height",
    "highlightbackground",
    "highlightcolor",
    "highlightthickness",
    "image",
    "indicatoron",
    "justify",
    "offrelief",
    "offvalue",
    "onvalue",
    "overrelief",
    "padx",
    "pady",
    "relief",
    "selectcolor",
    "selectimage",
    "state",
    "takefocus",
    "text",
    "textvariable",
    "underline",
    "variable",
    "width",
    "wraplength"
};

/* -------------------- widget helper functions------------------------------ */

static void checkbutton_drawme(t_checkbutton *x, t_glist *glist)
{
    sys_vgui("checkbutton %s\n", x->widget_id);
}


static void checkbutton_erase(t_checkbutton* x,t_glist* glist)
{
    sys_vgui("%s delete %s\n", x->canvas_id, x->widget_id);
}



/* --------------------- checkbutton widgetbehaviour ------------------------ */
static void checkbutton_getrect(t_gobj *z, t_glist *glist,
                          int *xp1, int *yp1, int *xp2, int *yp2)
{
    t_checkbutton* x = (t_checkbutton*)z;

    *xp1 = text_xpix(&x->x_obj, glist);
    *yp1 = text_ypix(&x->x_obj, glist);
    *xp2 = text_xpix(&x->x_obj, glist) + x->x_width;
    *yp2 = text_ypix(&x->x_obj, glist) + x->x_height;
}

static void checkbutton_delete(t_gobj *z, t_glist *glist)
{
    t_text *x = (t_text *)z;
    canvas_deletelinesfor(glist_getcanvas(glist), x);
}
       
static void checkbutton_vis(t_gobj *z, t_glist *glist, int vis)
{
    t_checkbutton* s = (t_checkbutton*)z;
    if (vis)
        checkbutton_drawme(s, glist);
    else
        checkbutton_erase(s, glist);
}

/* --------------------------- standard class functions --------------------- */

static void checkbutton_free(t_checkbutton *x)
{
    pd_unbind(&x->x_obj.ob_pd, x->receive_name);
}

static void *checkbutton_new(t_symbol* s, int argc, t_atom *argv)
{
    t_checkbutton *x = (t_checkbutton *)pd_new(checkbutton_class);

    x->x_glist = (t_glist*) canvas_getcurrent();

    x->x_width = 15;
    x->x_height = 15;

    outlet_new(&x->x_obj, &s_float);
    return (x);
}

void checkbutton_setup(void)
{
    checkbutton_class = class_new(gensym("checkbutton"), (t_newmethod)checkbutton_new, 
                            (t_method)checkbutton_free, 
                            sizeof(t_checkbutton), 0, A_GIMME,0);

    checkbutton_widgetbehavior.w_getrectfn  = checkbutton_getrect;
    checkbutton_widgetbehavior.w_displacefn = NULL;
    checkbutton_widgetbehavior.w_selectfn   = NULL;
    checkbutton_widgetbehavior.w_activatefn = NULL;
    checkbutton_widgetbehavior.w_deletefn   = checkbutton_delete;
    checkbutton_widgetbehavior.w_visfn      = checkbutton_vis;
    checkbutton_widgetbehavior.w_clickfn    = NULL;
    class_setwidget(checkbutton_class, &checkbutton_widgetbehavior);
}