File: pcheck.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 (187 lines) | stat: -rw-r--r-- 2,975 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
#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)();
	int selected;	/* 1 if checked (on) */
	} ltpcheckd, *ltpcheck;

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

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

int tpcheck_set(t)
ltpcheck t;
{
	/* check type */
	if(t==NULL)
		return(0);
	if(titem_type(t)!=lt_pcheck)
		return(0);
	
	xv_set(t->t, PANEL_VALUE, 1, NULL);
	t->selected=1;
	return(1);
}

int tpcheck_unset(t)
ltpcheck t;
{
	/* check type */
	if(t==NULL)
		return(0);
	if(titem_type(t)!=lt_pcheck)
		return(0);
	
	xv_set(t->t, PANEL_VALUE, 0, NULL);
	t->selected=0;
	return(1);
}

Panel_setting tpcheck_notify(item, val, e)
Panel_item item;
int val;
Event *e;
{
	ltpcheck t;
	int a;
	tevent te;

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

	t->selected=val;

	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, t->selected);
		tevent_free(te);
	}
	return(XV_OK);
}

tpcheck tpcheck_new(parent, x,y,w,h,right,below, name)
tpanel parent;
int x,y,w,h;
titem right,below;
char *name;
{
	ltpcheck tmp;

	/* check types */
	if(parent==NULL)
		return(NULL);
	if(titem_type(parent)!=lt_panel)
		return(NULL);
	
	if(name==NULL)
		name="Check Item";
	
	tmp=(ltpcheck)titem_new(parent, lt_pcheck, sizeof(ltpcheckd));
	if(tmp==NULL)
		return(NULL);
	
	tmp->t=(Panel_item)xv_create(tpanel_xview(parent), PANEL_CHECK_BOX,
		PANEL_LABEL_STRING, NULL,
		PANEL_LAYOUT, PANEL_HORIZONTAL,
		PANEL_CHOOSE_ONE, FALSE,
		PANEL_CHOICE_STRINGS, name, NULL,
		PANEL_VALUE, 1,
		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, tpcheck_notify,
		NULL);

	tmp->do_events=NULL;

	return(tmp);
}

int tpcheck_free(t)
ltpcheck t;
{
	/* check type */
	if(t==NULL)
		return(0);
	if(titem_type(t)!=lt_pcheck)
		return(0);
	
	xv_destroy_safe(t->t);
	return(titem_free(t));
}

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

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

int tpcheck_set_event_procedure(t, do_events)
ltpcheck t;
int (*do_events)();
{
	/* check type */
	if(t==NULL)
		return(0);
	if(titem_type(t)!=lt_pcheck)
		return(0);
	
	t->do_events=do_events;
	return(1);
}