File: FileSelect2.c

package info (click to toggle)
motif 2.3.4-13
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 81,160 kB
  • ctags: 51,769
  • sloc: ansic: 596,938; cpp: 3,951; yacc: 2,854; makefile: 2,070; csh: 1,199; sh: 1,070; lex: 455
file content (344 lines) | stat: -rw-r--r-- 9,608 bytes parent folder | download | duplicates (3)
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
/* 
 * Motif
 *
 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
 *
 * These libraries and programs are free software; you can
 * redistribute them and/or modify them under the terms of the GNU
 * Lesser General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * These libraries and programs are distributed in the hope that
 * they will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with these librararies and programs; if not, write
 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
 * Floor, Boston, MA 02110-1301 USA
*/ 
/* 
 * HISTORY
*/ 
#ifdef REV_INFO
#ifndef lint
static char rcsid[] = "$TOG: FileSelect2.c /main/10 1999/05/28 15:45:55 jff $"
#endif
#endif
/*
*  (c) Copyright 1987, 1988, 1989 HEWLETT-PACKARD COMPANY */
#include <testlib.h>
#include <unistd.h>

Widget   	CancelW;
Widget     	FileSelectionBox1;
Widget		Text1;

void  GoneCB();

#define MYNSTRINGS_DIR 8
#define TARGET_DIR "/tmp/FS/fourteencharac/fourteencharac/fourteencharac/"

char *mystrings_dir[] = {
   "Hello", "this", "is", "a", "new", "dir", "search", "proc"
};

#define MYNSTRINGS_FILE 8

char *mystrings_file[] = {
   "Hello", "this", "is", "a", "new", "file", "search", "proc"
};

/* New file Search Proc */

XtArgVal NewDirSearchProc()
{
    register int  n;
    Arg           args[MAX_ARGS];
    XmString      tcs;
    XmString      mymask, myspec, mylist[MYNSTRINGS_DIR];

    /*  Fill in the list, Items, Count */

    for (n = 0; n < MYNSTRINGS_DIR; n++)
    	mylist[n] = XmStringCreateSimple ((char *) mystrings_dir[n]);

    tcs = XmStringCreateSimple ((char *)"A very very long label");

    n = 0;
    XtSetArg (args[n], XmNdirListItems, mylist); 		n++;
    XtSetArg (args[n], XmNdirListItemCount, MYNSTRINGS_DIR); 	n++;
    XtSetArg (args[n], XmNdirListLabelString, tcs ); n++;
    XtSetArg (args[n], XmNdirectoryValid, TRUE); 		n++;
    XtSetArg (args[n], XmNlistUpdated, FALSE); 			n++;
    XtSetValues (FileSelectionBox1, args, n);

    XmStringFree( tcs );
    for (n = 0; n < MYNSTRINGS_DIR; n++)
		XmStringFree(mylist[n]);
}


XtArgVal NewFileSearchProc()
{
    register int  n;
    Arg           args[MAX_ARGS];
    XmString      tcs;
    XmString      mymask, myspec, mylist[MYNSTRINGS_FILE];

    /*  Fill in the list, Items, Count */

    for (n = 0; n < MYNSTRINGS_FILE; n++)
    	mylist[n] = XmStringCreateSimple ((char *) mystrings_file[n]);

    tcs = XmStringCreateSimple("A Very Long Label for test purposes");

    n = 0;
    XtSetArg (args[n], XmNfileListItems, mylist); 		n++;
    XtSetArg (args[n], XmNfileListItemCount, MYNSTRINGS_FILE); 	n++;
    XtSetArg (args[n], XmNfileListLabelString, tcs ); n++;
    XtSetArg (args[n], XmNlistUpdated, TRUE); 			n++;
    XtSetValues (FileSelectionBox1, args, n);

    XmStringFree(tcs);

    for (n = 0; n < MYNSTRINGS_FILE; n++)
		XmStringFree(mylist[n]);
}


void check_out()
{
    Arg           args[MAX_ARGS];
    XmString      mymask, myspec;
    int           n, *mydircount, *myfilecount;
    XtArgVal      search_proc;


    /* Print out interesting values */

    XmFileSelectionDoSearch (FileSelectionBox1, NULL);

    n = 0;
    XtSetArg (args[n], XmNdirectory, &mymask); 			n++;
    XtSetArg (args[n], XmNpattern, &myspec); 			n++;
    XtSetArg (args[n], XmNdirListItemCount, &mydircount); 	n++;
    XtSetArg (args[n], XmNfileListItemCount, &myfilecount); 	n++;
    XtSetArg (args[n], XmNfileSearchProc, &search_proc); 	n++;
    XtGetValues (FileSelectionBox1, args, n);

#ifdef DEBUG

    printf ("Dir: %s, Pat: %s, dirCount: %i, fileCount: %i,\n", 
             CommonCsToRs(mymask), CommonCsToRs(myspec), 
	     mydircount, myfilecount);

    printf ("Is fileSearchProc NULL? ");

    if (!search_proc) 
	printf (" Yes.\n");
    else 
	printf (" No, address is %d\n", search_proc);

#endif

	if (mymask != NULL)
		XmStringFree(mymask);
	if (myspec != NULL)
		XmStringFree(myspec);

}


void  main(argc, argv)
    int     argc;
    char  **argv;
{
    register int  n;
    Arg           args[MAX_ARGS];
    XmString      tcs, tcs2;
    Widget	  Frame;

/* Ensure target directory for FSB is set up properly */

    if ( access(TARGET_DIR,F_OK | R_OK) ) {
	printf("Target directory %s is not set up\n",TARGET_DIR);
	exit(1);
    }

    CommonTestInit(argc, argv);

    n = 0;
    Frame = XmCreateFrame(Shell1, "Frame1", args, n);
    XtManageChild(Frame);

    tcs = XmStringCreateSimple(TARGET_DIR);

    tcs2 = XmStringCreateSimple("*");

    n = 0;
    XtSetArg(args[n], XmNdirMask, tcs);  			n++;
    XtSetArg(args[n], XmNdirectory, tcs);  			n++;
    XtSetArg(args[n], XmNpattern, tcs2); 			n++;
    XtSetArg(args[n], XmNwidth, 400);				n++;
    XtSetArg(args[n], XmNresizePolicy, XmRESIZE_NONE);          n++;
    FileSelectionBox1 = XmCreateFileSelectionBox(Frame, "FileSelectionBox1", 
						 args, n);
    XtManageChild(FileSelectionBox1);

    XmStringFree(tcs);
    XmStringFree(tcs2);

    XtRealizeWidget(Shell1);

    /* Print out the DirMask and  DirSpec */

    check_out();

    /* add a callback to the Cancel button to destroy the world */

    CancelW = XmFileSelectionBoxGetChild(FileSelectionBox1,
            				 XmDIALOG_CANCEL_BUTTON);
    XtAddCallback(CancelW,XmNactivateCallback, GoneCB, NULL);

    /* Ok, we will start playing with the doc ideas */

    CommonPause ();

    printf ("Adding an additional Work Area - Text widget\n");

    XtSetArg(args[n], XmNrows, 4);  				n++;
    XtSetArg(args[n], XmNscrollVertical, True);  		n++;
    XtSetArg(args[n], XmNscrollHorizontal, True);  		n++;
    XtSetArg(args[n], XmNeditMode, XmMULTI_LINE_EDIT);  	n++;
    XtSetArg(args[n], XmNvalue, "Some Text.");  		n++;
    Text1 = XmCreateText(FileSelectionBox1, "Text1", args, n);

    XtManageChild(XmFileSelectionBoxGetChild(FileSelectionBox1,
                                             XmDIALOG_WORK_AREA));

    CommonPause ();

    printf ("Unmanage Files label and list\n");

    XtUnmanageChild(XtParent (XmFileSelectionBoxGetChild(FileSelectionBox1,
                                       	XmDIALOG_LIST)));
    XtUnmanageChild(XmFileSelectionBoxGetChild(FileSelectionBox1,
                                       	XmDIALOG_LIST_LABEL));

    CommonPause ();

    printf ("Manage Files and Unmanage Directories label and list\n");

    XtManageChild(XtParent (XmFileSelectionBoxGetChild(FileSelectionBox1,
                                     	XmDIALOG_LIST)));
    XtManageChild(XmFileSelectionBoxGetChild(FileSelectionBox1,
                                   	XmDIALOG_LIST_LABEL));
    XtUnmanageChild( XtParent (XmFileSelectionBoxGetChild(FileSelectionBox1,
                                      	XmDIALOG_DIR_LIST)));
    XtUnmanageChild(XmFileSelectionBoxGetChild(FileSelectionBox1,
                                      	XmDIALOG_DIR_LIST_LABEL));

    CommonPause ();

    printf ("Manage Directories label and list - unmap Files list\n");

    XtManageChild(XtParent (XmFileSelectionBoxGetChild(FileSelectionBox1,
                    			XmDIALOG_DIR_LIST)));
    XtManageChild(XmFileSelectionBoxGetChild(FileSelectionBox1,
                    			XmDIALOG_DIR_LIST_LABEL));
    XtUnmapWidget(XtParent (XmFileSelectionBoxGetChild(FileSelectionBox1,
                    			XmDIALOG_LIST)));

    CommonPause ();

    printf ("Remap the Files list\n");

    XtMapWidget(XtParent (XmFileSelectionBoxGetChild(FileSelectionBox1,
                    			XmDIALOG_LIST)));
    XtMapWidget(XtParent (XmFileSelectionBoxGetChild(FileSelectionBox1,
                    			XmDIALOG_LIST_LABEL)));


    /*  Modify the Directory list and Sundries... */

    CommonPause();

    printf("Set new DirSearchProc\n");

    n = 0;
    XtSetArg (args[n], XmNdirSearchProc, NewDirSearchProc); 	n++;
    XtSetValues(FileSelectionBox1, args, n);

    XmFileSelectionDoSearch (FileSelectionBox1, NULL);

    /* check out interesting values */

    check_out();

    /*  Modify the File list and sundries.... */

    CommonPause();

    printf("Set new FileSearchProc\n");

    n = 0;
    XtSetArg (args[n], XmNfileSearchProc, NewFileSearchProc); 	n++;
    XtSetValues (FileSelectionBox1, args, n);

    XmFileSelectionDoSearch (FileSelectionBox1, NULL);

    /* check out interesting values */

    check_out();

    /*  Set the dir and file search proc back to the originals */

    CommonPause();

    /* Begin Test for Pir2985 */

    printf("Set FileSearchProc and DirSearchProc back to default\n");

    tcs = XmStringLtoRCreate(TARGET_DIR,XmSTRING_DEFAULT_CHARSET);

    n = 0;
    XtSetArg (args[n], XmNdirSearchProc, NULL); 		n++;
    XtSetArg (args[n], XmNfileSearchProc, NULL); 		n++;
    XtSetValues (FileSelectionBox1, args, n);

    XmFileSelectionDoSearch (FileSelectionBox1, tcs);


    XmStringFree(tcs);

    /* check_out interesting values */

    check_out();

    /* End Test for Pir2985 */
    
    printf("That's All Folks\n");

    CommonPause();

    XtAppMainLoop(app_context);
}


void GoneCB(w, client_data, call_data )
    Widget  w;
    XtPointer client_data;
    XtPointer call_data;
{
    /* callback for when user clicks the cancel button */
    
    Widget dad;

    dad = XtParent(w);      /* get parent of cancel button */
    XtDestroyWidget(w);      /* destroy widget */
    XtDestroyWidget(dad);   /* and parent */
}