-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXfile.c
87 lines (65 loc) · 2.27 KB
/
Xfile.c
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
/*
-------------------------------------------------------------------------
OBJECT NAME: Xfile.c
FULL NAME: FileSelectionBox
DESCRIPTION: This pops up a Fileselection box for choosing a file name
Call CreateFile where you init X stuff. Then just call
QueryFile(Prompt, Default Directory, OK_callBack); Then your
OKcallBack procedure calls ExtractFileName()
INPUT: String to Display.
OUTPUT: Error message in its own tidy little window.
-------------------------------------------------------------------------
*/
#define register
#include <Xm/Xm.h>
#include <Xm/FileSB.h>
static Widget fileBox;
/* -------------------------------------------------------------------- */
void QueryFile(char *prompt, char *directory, XtCallbackProc callBack)
{
XmString xmdir, xmprompt;
Arg args[4];
int n = 0;
if (prompt)
{
xmprompt = XmStringCreateLocalized(prompt);
XtSetArg(args[n], XmNselectionLabelString, xmprompt); ++n;
XtSetValues(fileBox, args, n);
XmStringFree(xmprompt);
}
if (directory)
{
xmdir = XmStringCreateLocalized(directory);
XmFileSelectionDoSearch(fileBox, xmdir);
XmStringFree(xmdir);
}
else
XmFileSelectionDoSearch(fileBox, NULL);
XtRemoveAllCallbacks(fileBox, XmNokCallback);
XtAddCallback(fileBox, XmNokCallback, (XtCallbackProc)callBack,
(XtPointer)NULL);
XtAddGrab(fileBox, TRUE, FALSE);
XtManageChild(fileBox);
} /* END QUERYFILE */
/* -------------------------------------------------------------------- */
/* ARGSUSED */
void FileCancel(Widget w, XtPointer clientData, XtPointer callData)
{
XtUnmanageChild(fileBox);
XtRemoveGrab(fileBox);
} /* END FILECANCEL */
/* -------------------------------------------------------------------- */
void CreateFileSelectionBox(Widget parent)
{
fileBox = XmCreateFileSelectionDialog(parent, "fileBox", NULL, 0);
XtSetSensitive(XmFileSelectionBoxGetChild(fileBox, XmDIALOG_HELP_BUTTON),
FALSE);
XtAddCallback(fileBox, XmNcancelCallback, (XtCallbackProc)FileCancel,
(XtPointer)FALSE);
} /* END CREATEFILESELECTIONBOX */
/* -------------------------------------------------------------------- */
void ExtractFileName(XmString str, char **text)
{
XmStringGetLtoR(str, XmSTRING_DEFAULT_CHARSET, text);
} /* END EXTRACTFILENAME */
/* END XFILE.C */