5
/* $XFree86: xc/programs/xgc/getfile.c,v 1.4tsi Exp $ */
7
#include <X11/Intrinsic.h>
8
#include <X11/StringDefs.h>
9
#include <X11/Xaw/Label.h>
10
#include <X11/Xaw/Command.h>
11
#include <X11/Xaw/Form.h>
12
#include <X11/Shell.h>
13
#include <X11/Xaw/AsciiText.h>
19
static Widget popupshell = NULL; /* popup dialog box */
20
Widget filename_text_widget; /* Widget containing the name of
21
the file the user has selected */
23
static void kill_popup_shell(void);
27
void (*success)(void), /* what function to call when a filename is
29
void (*failure)(void)) /* what function to call when the user
32
static Widget popupform; /* form inside shell */
33
static Widget label; /* "Filename :" */
35
Window dummy1, dummy2;
39
/* The translation table for the text widget. Things such as <RETURN>
40
** confirm the user's choice. Other keys which would move out of
41
** the range of a one-line window are disabled. */
43
static const char *translationtable =
44
"Ctrl<Key>J: KillPopup() Done()\n\
45
Ctrl<Key>M: KillPopup() Done()\n\
46
<Key>Linefeed: KillPopup() Done()\n\
47
<Key>Return: KillPopup() Done()\n\
48
Ctrl<Key>O: Nothing()\n\
49
Meta<Key>I: Nothing()\n\
50
Ctrl<Key>N: Nothing()\n\
51
Ctrl<Key>P: Nothing()\n\
52
Ctrl<Key>Z: Nothing()\n\
53
Meta<Key>Z: Nothing()\n\
54
Ctrl<Key>V: Nothing()\n\
55
Meta<Key>V: Nothing()";
57
/* What the actions in the translation table correspond to. */
59
static XtActionsRec actiontable[] = {
60
{"KillPopup", (XtActionProc) kill_popup_shell},
65
static Arg popupshellargs[] = { /* Where to put the popup shell. */
66
{XtNx, (XtArgVal) NULL},
67
{XtNy, (XtArgVal) NULL}
70
static Arg labelargs[] = { /* ArgList for the label */
71
{XtNborderWidth, (XtArgVal) 0},
72
{XtNjustify, (XtArgVal) XtJustifyRight}
75
static Arg textargs[] = { /* ArgList for the text widget */
76
{XtNeditType, (XtArgVal) XawtextEdit},
77
{XtNwidth, (XtArgVal) 200},
78
{XtNhorizDistance, (XtArgVal) 10},
79
{XtNfromHoriz, (XtArgVal) NULL},
82
static Arg cancelargs[] = { /* ArgList for the cancel button */
83
{XtNfromHoriz, (XtArgVal) NULL},
84
{XtNcallback, (XtArgVal) NULL}
87
/* Procedures to call when the user selects 'cancel' */
88
static XtCallbackRec cancelcallbacklist[] = {
89
{(XtCallbackProc) kill_popup_shell, NULL},
94
if (popupshell != NULL) {
95
XtPopup(popupshell,XtGrabExclusive);
99
/* Find out where the pointer is, so we can put the popup window there */
101
(void) XQueryPointer(X.dpy,XtWindow(topform),&dummy1,&dummy2,&x1,&y1,
104
popupshellargs[0].value = (XtArgVal) x2;
105
popupshellargs[1].value = (XtArgVal) y2;
107
popupshell = XtCreatePopupShell("popup",overrideShellWidgetClass,
108
topform,popupshellargs,XtNumber(popupshellargs));
110
popupform = XtCreateManagedWidget("form",formWidgetClass,popupshell,
113
label = XtCreateManagedWidget("Filename: ",labelWidgetClass,popupform,
114
labelargs,XtNumber(labelargs));
116
textargs[3].value = (XtArgVal) label;
118
filename_text_widget = XtCreateManagedWidget("text",asciiTextWidgetClass,
120
textargs,XtNumber(textargs));
122
/* Complete the action table. We have to do it here because success
123
** isn't known at compile time. */
125
actiontable[1].proc = (XtActionProc) success;
127
/* Register actions, translations, callbacks */
129
XtAppAddActions(appcontext,actiontable,XtNumber(actiontable));
130
XtOverrideTranslations(filename_text_widget,
131
XtParseTranslationTable(translationtable));
132
cancelcallbacklist[1].callback = (XtCallbackProc) failure;
134
cancelargs[0].value = (XtArgVal) filename_text_widget;
135
cancelargs[1].value = (XtArgVal) cancelcallbacklist;
137
(void) XtCreateManagedWidget("Cancel",commandWidgetClass,popupform,
138
cancelargs,XtNumber(cancelargs));
140
/* Bring up the popup. When the user presses cancel or the return key,
141
** the function kill_popup_shell (below) will be called to remove it. */
143
XtPopup(popupshell,XtGrabExclusive);
146
/* kill_popup_shell()
147
** ------------------
148
** Remove the popup window that get_filename popped up.
152
kill_popup_shell(void)
154
XtPopdown(popupshell);