File: xmpi_copies.c

package info (click to toggle)
xmpi 2.2-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,232 kB
  • ctags: 1,656
  • sloc: ansic: 13,738; sh: 1,799; makefile: 233
file content (242 lines) | stat: -rw-r--r-- 5,161 bytes parent folder | download
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/*
 * Copyright 1998-1999, University of Notre Dame.
 * Authors: Brian W. Barrett, Arun F. Rodrigues, Jeffrey M. Squyres,
 * 	 and Andrew Lumsdaine
 *
 * This file is part of XMPI
 *
 * You should have received a copy of the License Agreement for XMPI 
 * along with the software; see the file LICENSE.  If not, contact 
 * Office of Research, University of Notre Dame, Notre Dame, IN 46556.
 *
 * Permission to modify the code and to distribute modified code is
 * granted, provided the text of this NOTICE is retained, a notice that
 * the code was modified is included with the above COPYRIGHT NOTICE and
 * with the COPYRIGHT NOTICE in the LICENSE file, and that the LICENSE
 * file is distributed with the modified code.
 *
 * LICENSOR MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED.
 * By way of example, but not limitation, Licensor MAKES NO
 * REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY
 * PARTICULAR PURPOSE OR THAT THE USE OF THE LICENSED SOFTWARE COMPONENTS
 * OR DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, TRADEMARKS
 * OR OTHER RIGHTS.
 *
 * Additional copyrights may follow.

 *
 *	$Id: xmpi_copies.c,v 1.5 1999/11/08 06:20:22 bbarrett Exp $
 * 
 *	Function:	- widgets for setting number of application copies
 */

#define _NO_PROTO

#include <Xm/ArrowBG.h>
#include <Xm/Form.h>
#include <Xm/TextF.h>

#include <ctype.h>
#include <stdio.h>
#include "lam.h"

/*
 * local definitions
 */
#define XMPI_UPARROW	((XtPointer) 1)
#define XMPI_DOWNARROW	((XtPointer) 2)

/*
 * external functions
 */
extern int4		stoi();

/*
 * local functions
 */
static void		do_arrow();
static void		verify();
static void		change();

/*
 * local variables
 */
static int		copies = 0;		/* counter as value */
static Widget		text_w;			/* counter as text */
static Widget		sc_w = 0;		/* container */

/*
 *	xmpi_copies_get
 *
 *	Function:	- copy counter accessor
 *	Returns:	- copy counter text
 */
char *
xmpi_copies_get()

{
	char		*s;
	
	XtVaGetValues(text_w, XmNvalue, &s, NULL);
	return(s);
}

/*
 *	xmpi_copies_create
 *
 *	Function:	- create the widget for setting the copy counter
 *	Accepts:	- parent widget
 *	Returns:	- copy counter setting widget
 */
Widget
xmpi_copies_create(parent_w)

Widget			parent_w;

{
	Widget		up_w;		/* up arrow */
	Widget		down_w;		/* down arrow */
	Dimension	height;

	if (sc_w != 0) return(sc_w);
	
	sc_w = XtVaCreateWidget("setcopies",
			xmFormWidgetClass, parent_w, NULL);
/*
 * Create the text field.
 */
	text_w = XtVaCreateManagedWidget("text",
		xmTextFieldWidgetClass, sc_w,
		XmNvalue, "",
		XmNtopAttachment, XmATTACH_FORM,
		XmNbottomAttachment, XmATTACH_FORM,
		XmNleftAttachment, XmATTACH_FORM,
		NULL);
	XtVaGetValues(text_w, XmNheight, &height, NULL);
	XtAddCallback(text_w, XmNmodifyVerifyCallback, verify, NULL);
	XtAddCallback(text_w, XmNvalueChangedCallback, change, NULL);
/*
 * Create the up arrow.
 */
	up_w = XtVaCreateManagedWidget("uparrow",
		xmArrowButtonGadgetClass, sc_w,
		XmNarrowDirection, XmARROW_UP,
		XmNtopAttachment, XmATTACH_FORM,
		XmNbottomAttachment, XmATTACH_FORM,
		XmNrightAttachment, XmATTACH_FORM,
		XmNborderWidth, 0,
		NULL);

	XtAddCallback(up_w, XmNactivateCallback, do_arrow, XMPI_UPARROW);
/*
 * Create the down arrow.
 */
	down_w = XtVaCreateManagedWidget("downarrow",
		xmArrowButtonGadgetClass, sc_w,
		XmNarrowDirection, XmARROW_DOWN,
		XmNtopAttachment, XmATTACH_FORM,
		XmNbottomAttachment, XmATTACH_FORM,
		XmNrightAttachment, XmATTACH_WIDGET,
		XmNrightWidget, up_w,
		NULL);

	XtAddCallback(down_w, XmNactivateCallback, do_arrow, XMPI_DOWNARROW);
	
	XtVaSetValues(text_w,
		XmNrightAttachment, XmATTACH_WIDGET,
		XmNrightWidget, down_w,
		NULL);

	return(sc_w);
}

/*
 *	do_arrow
 *
 *	Function:	- manage arrows of copy counter
 *			- increment/decrement copy counter
 *	Accepts:	- callback parameters
 */
static void
do_arrow(parent_w, data, cbs)

Widget			parent_w;
XtPointer		data;
XmArrowButtonCallbackStruct
			*cbs;

{
	char		fbuf[16];	/* small formatting buffer */
	int		inc;

	inc = (cbs->event->xbutton.state & ShiftMask) ? 10 : 1;

	if (data == XMPI_UPARROW) {
		copies += inc;
	} else {
		copies -= inc;
	}
	if (copies < 0) copies = 0;

	if (copies > 0) {
		sprintf(fbuf, "%d", copies);
	} else {
		fbuf[0] = 0;
	}
	XtVaSetValues(text_w, XmNvalue, fbuf, NULL);
}

/*
 *	verify
 *
 *	Function:	- verify numeric input for copy counter
 *	Accepts:	- callback parameters
 */
static void
verify(parent_w, unused, cbs)

Widget			parent_w;
XtPointer		unused;
XmTextVerifyCallbackStruct
			*cbs;

{
	int		i;
	
	if (cbs->event == NULL || cbs->text->ptr == NULL) return;

	for (i = 0; i < cbs->text->length; i++) {
		if (! isdigit((int)cbs->text->ptr[i])) {
			cbs->doit = False;
			return;
		}
	}
}

/*
 *	change
 *
 *	Function:	- update counter to reflect text change
 *	Accepts:	- callback parameters
 */
static void
change(parent_w, unused, cbs)

Widget			parent_w;
XtPointer		unused;
XmTextVerifyCallbackStruct
			*cbs;

{
	char		*s;
	
	if (cbs->event == NULL) return;

	XtVaGetValues(text_w, XmNvalue, &s, NULL);

	if (s == 0 || *s == 0) {
		copies = 0;
	} else {
		copies = (int) stoi((unsigned char *)s);
	}
}