-
Notifications
You must be signed in to change notification settings - Fork 0
/
XmFile.cc
79 lines (59 loc) · 2.34 KB
/
XmFile.cc
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
/*
-------------------------------------------------------------------------
OBJECT NAME: XmFile.cc
FULL NAME: Motif File Selection Box
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.
-------------------------------------------------------------------------
*/
#include "XmFile.h"
/* -------------------------------------------------------------------- */
static void DismissFile(Widget w, XtPointer client, XtPointer call)
{
XtUnmanageChild((Widget)client);
XtRemoveGrab((Widget)client);
}
/* -------------------------------------------------------------------- */
XmFile::XmFile(Widget parent)
{
fileBox = XmCreateFileSelectionDialog(parent, const_cast<char *>("fileBox"), NULL, 0);
XtSetSensitive(XmFileSelectionBoxGetChild(fileBox, XmDIALOG_HELP_BUTTON), false);
XtAddCallback(fileBox,XmNcancelCallback,(XtCallbackProc)DismissFile, fileBox);
} /* END CONSTRUCTOR */
/* -------------------------------------------------------------------- */
void XmFile::QueryFile(const char prompt[], const char directory[], XtCallbackProc callBack)
{
XmString xmdir, xmprompt;
Arg args[4];
Cardinal n = 0;
if (prompt)
{
xmprompt = XmStringCreate(const_cast<char *>(prompt), XmSTRING_DEFAULT_CHARSET);
XtSetArg(args[n], XmNselectionLabelString, xmprompt); ++n;
XtSetValues(fileBox, args, n);
XmStringFree(xmprompt);
}
if (directory)
{
xmdir = XmStringCreate(const_cast<char *>(directory), XmSTRING_DEFAULT_CHARSET);
XmFileSelectionDoSearch(fileBox, xmdir);
XmStringFree(xmdir);
}
else
XmFileSelectionDoSearch(fileBox, NULL);
XtRemoveAllCallbacks(fileBox, XmNokCallback);
XtAddCallback(fileBox, XmNokCallback, (XtCallbackProc)DismissFile, fileBox);
XtAddCallback(fileBox, XmNokCallback, (XtCallbackProc)callBack, fileBox);
XtAddGrab(fileBox, true, false);
XtManageChild(fileBox);
} /* END QUERYFILE */
/* -------------------------------------------------------------------- */
void XmFile::ExtractFileName(XmString str, char **text)
{
XmStringGetLtoR(str, XmSTRING_DEFAULT_CHARSET, text);
} /* END EXTRACTFILENAME */
/* END XMFILE.CC */