File: option.c

package info (click to toggle)
xlockmore 1%3A5.02-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 8,676 kB
  • ctags: 12,741
  • sloc: ansic: 105,468; cpp: 3,216; makefile: 2,255; sh: 1,908; tcl: 1,333; java: 471; perl: 434
file content (300 lines) | stat: -rw-r--r-- 8,647 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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#if !defined( lint ) && !defined( SABER )
static const char sccsid[] = "@(#)option.c	4.00 97/01/01 xlockmore";

#endif

/*-
 * option.c - option stuff for xmlock, the gui interface to xlock.
 *
 * Copyright (c) 1996 by Charles Vidal
 *
 * See xlock.c for copying information.
 *
 * Revision History:
 * Nov-96: written.
 *
 */

/*-
 * if you want add some options ,so it's not really difficult
 * 1: Learn Motif ... but only if you want to :)
 * 2: add a name of widget after geometry,font,program
 * 3: add a string ( char * ) after *inval=NULL,*geo=NULL
 * 4: add a callback like f_username with your new string
 * 5: copy and paste after
   geometry=XtVaCreateManagedWidget("geometry",xmPushButtonGadgetClass,options,NULL);
   XtAddCallback(geometry,XmNactivateCallback,f_geometry,NULL);
 *    change geometry by your name of widget, and f_geometry by the name
 *    of your new callback
 * 6: go to the church , call god for a miracle :)
 * GOOD LUCK
 */

#include <stdio.h>
#include <stdlib.h>
#ifdef VMS
#include <vms_x_fix.h>
#include <descrip.h>
#include <lib$routines.h>
#endif

#include <X11/cursorfont.h>
/* #include <Xm/XmAll.h> Does not work on my version of Lesstif */
#include <Xm/RowColumn.h>
#include <Xm/SelectioB.h>
#include <Xm/CascadeB.h>
#include <Xm/PushBG.h>
#include <Xm/List.h>
#include <Xm/Label.h>
#include <Xm/ToggleBG.h>


#include <Xm/MessageB.h> /* needed ? */

#include "option.h"

/*#define OPTIONS 8*/
/*#define REGULAR_OPTIONS (OPTIONS-2)*/

#define NBPROGNAME 3
#define MAXNAMES 10000
Widget      Menuoption;
static Widget Options[OPTIONS];

/* extern variables */
extern Widget toplevel;

void exitcallback(Widget w, XtPointer client_data, XtPointer call_data);


/* Widget */
static Widget PromptDialog, FontSelectionDialog, ProgramSelectionDialog;

/* strings */
char       *c_Options[OPTIONS];
extern char *r_Options[OPTIONS];

Widget Toggles[TOGGLES];

static char *prompts[OPTIONS] =
{
	(char *) "Enter the user name.",
	(char *) "Enter the password message.",
	(char *) "Enter the info message.",
	(char *) "Enter the valid message.",
	(char *) "Enter the invalid message.",
	(char *) "Enter the geometry mxn."
};

static char *prognames[NBPROGNAME] =
{
	(char *) "fortune",
	(char *) "finger",
	(char *) "echo hello world"
};

char *r_Toggles[TOGGLES] =
{
        (char *) "allowaccess",
        (char *) "allowroot",
        (char *) "debug",
        (char *) "echokeys",
        (char *) "echokeys",
        (char *) "enablesaver",
        (char *) "fullrandom",
        (char *) "grabmouse",
        (char *) "grabmouse",
        (char *) "grabserver",
        (char *) "install",
        (char *) "mousemotion",
        (char *) "nolock",
        (char *) "remote",
        (char *) "sound",
        (char *) "timeelapsed",
        (char *) "trackmouse",
        (char *) "use3d",
        (char *) "usefirst",
        (char *) "usefirst",
        (char *) "verbose",
        (char *) "wireframe",
	(char *) "mono"

};

/* string temp */
static char **whichone;


static void
managePrompt(char *s)
{
	int         ac;
	Arg         args[3];
	XmString    label_str1, label_str2;

	ac = 0;
	label_str1 = XmStringCreateSimple(s);
	XtSetArg(args[ac], XmNselectionLabelString, label_str1);
	ac++;
	if (*whichone != NULL) {
		label_str2 = XmStringCreateSimple(*whichone);
		XtSetArg(args[ac], XmNtextString, label_str2);
		ac++;
	} else {
		label_str2 = XmStringCreateSimple((char *) "");
		XtSetArg(args[ac], XmNtextString, label_str2);
		ac++;
	}

	XtSetValues(PromptDialog, args, ac);
/* PURIFY 4.0.1 on Solaris 2 reports a 71 byte memory leak on the next line. */
	XtManageChild(PromptDialog);
	XmStringFree(label_str1);
	XmStringFree(label_str2);
}

/* CallBack */
static void
f_option(Widget w, XtPointer client_data, XtPointer call_data)
{
			whichone = &c_Options[(int) client_data];
			managePrompt(prompts[(int) client_data]);
}

#if 0
static int  loadfont = 0;

/******************************
 * Callback for the font dialog
******************************/
static void
f_fontdia(Widget w, XtPointer client_data, XtPointer call_data)
{
	int         numdirnames, i;
	char      **dirnames;
	XmString    label_str;
	Widget      listtmp;
	Cursor      tmp;

	whichone = &c_Options[OPTIONS];
	if (!loadfont) {
		tmp = XCreateFontCursor(XtDisplay(toplevel), XC_watch);
		XDefineCursor(XtDisplay(toplevel), XtWindow(toplevel), tmp);
		dirnames = XListFonts(XtDisplay(toplevel), "*", MAXNAMES, &numdirnames);
		listtmp = XmSelectionBoxGetChild(FontSelectionDialog, XmDIALOG_LIST);
		for (i = 0; i < numdirnames; i++) {
			label_str = XmStringCreateSimple(dirnames[i]);
			XmListAddItemUnselected(listtmp, label_str, 0);
			XmStringFree(label_str);
		}
		tmp = XCreateFontCursor(XtDisplay(toplevel), XC_left_ptr);
		XDefineCursor(XtDisplay(toplevel), XtWindow(toplevel), tmp);
		loadfont = 1;
		XFreeFontNames(dirnames);
	}
	XtManageChild(FontSelectionDialog);
}

/******************************
 * Callback for the program dialog
******************************/
static void f_programdia(Widget w, XtPointer client_data, XtPointer call_data) {
			/*whichone = &c_Options[REGULAR_OPTIONS + 1];*/
/* PURIFY 4.0.1 on Solaris 2 reports a 71 byte memory leak on the next line. */
			XtManageChild(ProgramSelectionDialog);
	}
#endif

static void
f_Dialog(Widget w, XtPointer client_data, XtPointer call_data)
{
	static char *quoted_text;
	char       *nonquoted_text = (char *) NULL;
	XmSelectionBoxCallbackStruct *scb =
		(XmSelectionBoxCallbackStruct *) call_data;

	if (whichone != NULL)
		XtFree(*whichone);
	XmStringGetLtoR(scb->value, XmSTRING_DEFAULT_CHARSET, &nonquoted_text);
	if ((quoted_text = (char *) malloc(strlen(nonquoted_text) + 3)) ==
			NULL) {
		(void) fprintf(stderr, "Memory error\n");
		return;
	}
	(void) sprintf(quoted_text, "\"%s\"", nonquoted_text);
	(void) free((void *) nonquoted_text);
	*whichone = quoted_text;
}

/* Setup Widget */
void
setup_Option(Widget MenuBar)
{
	Arg         args[15];
	int         i, ac = 0;
	XmString    label_str;
	Widget      listtmp, pulldownmenu,exitwidget;

/** 
 ** Popup Menu File
 **/
	pulldownmenu = XmCreatePulldownMenu(MenuBar, (char *) "PopupFile",
		(Arg *) NULL, 0);
	label_str = XmStringCreateSimple((char *) "File");
	XtVaCreateManagedWidget("File", xmCascadeButtonWidgetClass, MenuBar,
		XmNlabelString, label_str, XmNsubMenuId, pulldownmenu, NULL);
	XmStringFree(label_str);
	exitwidget = XtVaCreateManagedWidget("Exit", xmPushButtonGadgetClass,
		pulldownmenu, NULL);
	XtAddCallback(exitwidget, XmNactivateCallback, exitcallback,NULL);

	pulldownmenu = XmCreatePulldownMenu(MenuBar, (char *) "PopupOptions",
		(Arg *) NULL, 0);
	label_str = XmStringCreateSimple((char *) "Options");
	XtVaCreateManagedWidget("Options", xmCascadeButtonWidgetClass, MenuBar,
		XmNlabelString, label_str, XmNsubMenuId, pulldownmenu, NULL);
	XmStringFree(label_str);

	for (i = 0; i < OPTIONS; i++) {
		Options[i] = XtVaCreateManagedWidget(r_Options[i],
			/*xmToggleButtonGadgetClass, pulldownmenu, NULL);*/
			xmPushButtonGadgetClass, pulldownmenu, NULL);
		XtAddCallback(Options[i], XmNactivateCallback, f_option, (XtPointer) i);
	}
/* PURIFY 4.0.1 on Solaris 2 reports a 12 byte memory leak on the next line. */
	PromptDialog = XmCreatePromptDialog(toplevel, (char *) "PromptDialog",
		args, ac);
	XtAddCallback(PromptDialog, XmNokCallback, f_Dialog, NULL);

/* PURIFY 4.0.1 on Solaris 2 reports a 28 byte and a 12 byte memory leak on
   the next line. */
	FontSelectionDialog = XmCreateSelectionDialog(toplevel,
		(char *) "FontSelectionDialog", (Arg *) NULL, 0);
	XtAddCallback(FontSelectionDialog, XmNokCallback, f_Dialog, NULL);

/* PURIFY 4.0.1 on Solaris 2 reports a 38 byte memory leak on the next line. */
	ProgramSelectionDialog = XmCreateSelectionDialog(toplevel,
		(char *) "ProgramSelectionDialog", (Arg *) NULL, 0);
	XtAddCallback(ProgramSelectionDialog, XmNokCallback, f_Dialog, NULL);
	listtmp = XmSelectionBoxGetChild(ProgramSelectionDialog, XmDIALOG_LIST);
	for (i = 0; i < NBPROGNAME; i++) {
		label_str = XmStringCreateSimple(prognames[i]);
		XmListAddItemUnselected(listtmp, label_str, 0);
		XmStringFree(label_str);
	}

/**
 ** Make the menu with all options boolean
***/
	pulldownmenu = XmCreatePulldownMenu(MenuBar, (char *) "PopupSwitches",
		(Arg *) NULL, 0);
	label_str = XmStringCreateSimple((char *) "Switches");
	XtVaCreateManagedWidget("Switches", xmCascadeButtonWidgetClass, MenuBar,
		XmNlabelString, label_str, XmNsubMenuId, pulldownmenu, NULL);
	XmStringFree(label_str);

        for (i = 0; i < TOGGLES; i++) {
		Toggles[i] = XtVaCreateManagedWidget(r_Toggles[i],
			xmToggleButtonGadgetClass, pulldownmenu, NULL);
	}
}