File: pbutton.c

package info (click to toggle)
treetool 2.0.2-1
  • links: PTS
  • area: non-free
  • in suites: potato
  • size: 3,460 kB
  • ctags: 2,692
  • sloc: ansic: 26,504; makefile: 212
file content (208 lines) | stat: -rw-r--r-- 3,390 bytes parent folder | download | duplicates (5)
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#include <stdio.h>

#include <xview/xview.h>
#include <xview/panel.h>
#include "generic.h"

typedef struct {
	ltgenericd g;
	Panel_item t;	/* xview panel item */
	int (*do_events)();
	} ltpbuttond, *ltpbutton;

int tpbutton_right_side(t)
ltpbutton t;
{
	/* check type */
	if(t==NULL)
		return(0);
	if(titem_type(t)!=lt_pbutton)
		return(0);
	
	return(xv_get(t->t, XV_X)+xv_get(t->t, XV_WIDTH));
}

int tpbutton_bottom_side(t)
ltpbutton t;
{
	/* check type */
	if(t==NULL)
		return(0);
	if(titem_type(t)!=lt_pbutton)
		return(0);
	
	return(xv_get(t->t, XV_Y)+xv_get(t->t, XV_HEIGHT));
}

Panel_setting tpbutton_notify(item, e)
Panel_item item;
Event *e;
{
    ltpbutton t;
    int a;
	tevent te;

    t=(ltpbutton)xv_get(item, PANEL_CLIENT_DATA);

    if(t->do_events!=NULL)
	{
		te=tevent_create_from_xviewevent(e, event_x(e), event_y(e), 0, 0);
		a=(*t->do_events)(t, te);
		tevent_free(te);
	}
    return(XV_OK);
}

tpbutton tpbutton_new(parent, x,y,w,h,right,below, name)
tpanel parent;
int x,y,w,h;
titem right,below;
char *name;
{
	ltpbutton tmp;

	/* check types */
	if(parent==NULL)
		return(NULL);
	if(titem_type(parent)!=lt_panel)
		return(NULL);
	
	if(name==NULL)
		name="Button Item";
	
	tmp=(ltpbutton)titem_new(parent, lt_pbutton, sizeof(ltpbuttond));
	if(tmp==NULL)
		return(NULL);
	
	tmp->t=(Panel_item)xv_create(tpanel_xview(parent), PANEL_BUTTON,
		PANEL_LABEL_STRING, name,
		XV_WIDTH, w,
		XV_HEIGHT, h,
		NULL);
	
	if(right!=NULL)
		x=tp_right_side(right);
	if(below!=NULL)
		y=tp_bottom_side(below);

	xv_set(tmp->t,
		XV_X, x,
		XV_Y, y,
		PANEL_CLIENT_DATA, tmp,
		PANEL_NOTIFY_PROC, tpbutton_notify,
		NULL);

	tmp->do_events=NULL;

	return(tmp);
}

tpbutton tpbutton_new_image(parent, x,y,w,h,right,below, pic)
tpanel parent;
int x,y,w,h;
titem right,below;
tpic pic;
{
	ltpbutton tmp;

	/* check types */
	if(parent==NULL)
		return(NULL);
	if(titem_type(parent)!=lt_panel)
		return(NULL);
	
	if(pic==NULL)
		return(NULL);
	
	tmp=(ltpbutton)titem_new(parent, lt_pbutton, sizeof(ltpbuttond));
	if(tmp==NULL)
		return(NULL);
	
	tmp->t=(Panel_item)xv_create(tpanel_xview(parent), PANEL_BUTTON,
		PANEL_LABEL_IMAGE, tpic_xview(pic),
		XV_WIDTH, w,
		XV_HEIGHT, h,
		NULL);
	
	if(right!=NULL)
		x=tp_right_side(right);
	if(below!=NULL)
		y=tp_bottom_side(below);

	xv_set(tmp->t,
		XV_X, x,
		XV_Y, y,
		PANEL_CLIENT_DATA, tmp,
		PANEL_NOTIFY_PROC, tpbutton_notify,
		NULL);

	tmp->do_events=NULL;

	return(tmp);
}

int tpbutton_free(t)
ltpbutton t;
{
	/* check type */
	if(t==NULL)
		return(0);
	if(titem_type(t)!=lt_pbutton)
		return(0);
	
	xv_destroy_safe(t->t);
	return(titem_free(t));
}

int tpbutton_enable(t)
ltpbutton t;
{
	/* check type */
	if(t==NULL)
		return(0);
	if(titem_type(t)!=lt_pbutton)
		return(0);
	
	xv_set(t->t, PANEL_INACTIVE, FALSE, NULL);
	return(1);
}

int tpbutton_disable(t)
ltpbutton t;
{
	/* check type */
	if(t==NULL)
		return(0);
	if(titem_type(t)!=lt_pbutton)
		return(0);
	
	xv_set(t->t, PANEL_INACTIVE, TRUE, NULL);
	return(1);
}

int tpbutton_set_event_procedure(t, do_events)
ltpbutton t;
int (*do_events)();
{
	/* check type */
	if(t==NULL)
		return(0);
	if(titem_type(t)!=lt_pbutton)
		return(0);
	
	t->do_events=do_events;
	return(1);
}

tpbutton_set_color(b, p)
ltpbutton b;
unsigned long p;
{
	/* check type */
	if(b==NULL)
		return(0);
	if(titem_type(b)!=lt_pbutton)
		return(0);
	
	xv_set(b->t, PANEL_ITEM_COLOR, p, NULL);
}