File: xcal_buts.c

package info (click to toggle)
xcal 4.1-19
  • links: PTS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, lenny, sid, squeeze, stretch, wheezy
  • size: 780 kB
  • ctags: 3,851
  • sloc: ansic: 5,576; makefile: 4,265; sh: 573
file content (206 lines) | stat: -rw-r--r-- 3,679 bytes parent folder | download | duplicates (6)
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
#ifndef lint
static char    *sccsid = "@(#)xcal_buts.c	1.3 (Hillside Systems) 10/25/93";
static char    *copyright = "@(#)Copyright 1989,1990,1993 Peter Collinson, Hillside Systems";
#endif				/* lint */
/***

* module name:
	xcal_buts.c
* function:
	Deal with callback management for sensitive buttons
	When a button is pressed we make it insensitive.
	In general a button starts a popup - when the popup
	dies we reset the button.
	Problem is when the button dies before the popup.

* history:
	Written October 1993
	Peter Collinson
	Hillside Systems
* (C) Copyright: 1989 Hillside Systems/Peter Collinson

	For full permissions and copyright notice - see xcal.c
***/
#include <stdio.h>
#include <ctype.h>
#include <pwd.h>
#include <X11/Intrinsic.h>
#include <X11/Xos.h>
#include <X11/StringDefs.h>
#include <X11/Xaw/Command.h>
#include "xcal.h"

typedef struct active {
	struct active   *next;
	Widget		button;
	Widget		popup;
} Active;

static Active *act;

/*
 * Local routines
 */
static void AddToActive();
static Active *LookActive();
static Active *LookPopup();
static void DeleteFromActive();
static void PopupIsDead();
static void ButtonIsDead();

/*
 * Here's the global entry point
 * given a button and a popup
 * make the button insensitive
 * add a destroy callback to the popup to turn the button on again when
 * the popup dies - assuming the button is in the list
 * add a destroy callback to the button to remove the button from the list
 */
void
ButtonOff(but, popup)
	Widget		but;
	Widget		popup;
{
	
	XtSetSensitive(but, False);
	
	XtAddCallback(popup, XtNdestroyCallback, PopupIsDead, but);

	XtAddCallback(but, XtNdestroyCallback, ButtonIsDead, but);

	AddToActive(but, popup);
}

/*
 * Turn a button on
 */
void
ButtonOn(but)
	Widget		but;
{
	Active		*ap;

	if (ap = LookActive(but)) {
		XtRemoveCallback(but, XtNdestroyCallback, ButtonIsDead, but);
		XtSetSensitive(but, True);
		DeleteFromActive(but);
	}
}

/*
 * Turn a help button on
 */
void
HelpButtonOn(popup)
	Widget		popup;
{
	Active		*ap;

	while (ap = LookPopup(popup))
		ButtonOn(ap->button);
}

/*
 * Callbacks
 * 1) called from popup when it dies
 */
/* ARGSUSED */
static void
PopupIsDead(w, closure, call_data)
	Widget		w;
	caddr_t         closure;
	caddr_t         call_data;
	
{
	ButtonOn((Widget) closure);
}

/*
 * Callbacks
 * 2) called when button is dead
 */
/* ARGSUSED */
static void
ButtonIsDead(w, closure, call_data)
	Widget		w;
	caddr_t         closure;
	caddr_t         call_data;
	
{
	Active	       *ap;
	Widget		but = (Widget)closure;

	if (ap = LookActive(but)) {
		XtRemoveCallback(ap->popup, XtNdestroyCallback, PopupIsDead, but);
		DeleteFromActive(but);
	}
}

/*
 * Add a button to the active list
 */
static void
AddToActive(but, popup)
	Widget		but;
	Widget		popup;
{
	Active	        *ap;

	if (LookActive(but) == NULL) {
		ap = (Active *) XtMalloc(sizeof (Active));
		ap->button = but;
		ap->popup = popup;
		ap->next = act;
		act = ap;
	} /* not convinced that the else arm here is a never happen */
}

static Active *
LookActive(but)
	Widget		but;
{
	Active	       *ap;
	
	for (ap = act; ap; ap = ap->next) {
		if (ap->button == but)
			return ap;
	}
	return NULL;
}

static Active *
LookPopup(popup)
	Widget		popup;
{
	Active	       *ap;
	
	for (ap = act; ap; ap = ap->next) {
		if (ap->popup == popup)
			return ap;
	}
	return NULL;
}

/*
 * remove an active entry
 */
static void
DeleteFromActive(but)
	Widget		but;
{
	Active	       *ap;
	Active	       *lp = NULL;

	for (ap = act; ap; ap = ap->next) {
		if (ap->button == but) {
			if (lp == NULL) 
				act = ap->next;
			else
				lp->next = ap->next;
			XtFree((char *)ap);
			return;
		}
		lp = ap;
	}
}