1/* 2** getfilename.c 3** 4*/ 5 6#include <X11/Intrinsic.h> 7#include <X11/StringDefs.h> 8#include <X11/Xaw/Label.h> 9#include <X11/Xaw/Command.h> 10#include <X11/Xaw/Form.h> 11#include <X11/Shell.h> 12#include <X11/Xaw/AsciiText.h> 13#include <stdio.h> 14 15#include "xgc.h" 16 17 18static Widget popupshell = NULL; /* popup dialog box */ 19Widget filename_text_widget; /* Widget containing the name of 20 the file the user has selected */ 21 22static void kill_popup_shell(void); 23 24void 25get_filename( 26 void (*success)(void), /* what function to call when a filename is 27 chosen */ 28 void (*failure)(void)) /* what function to call when the user 29 cancels */ 30{ 31 static Widget popupform; /* form inside shell */ 32 static Widget label; /* "Filename :" */ 33 34 Window dummy1, dummy2; 35 int x1,y1,x2,y2; 36 unsigned int mask; 37 38 /* The translation table for the text widget. Things such as <RETURN> 39 ** confirm the user's choice. Other keys which would move out of 40 ** the range of a one-line window are disabled. */ 41 42 static const char *translationtable = 43 "Ctrl<Key>J: KillPopup() Done()\n\ 44 Ctrl<Key>M: KillPopup() Done()\n\ 45 <Key>Linefeed: KillPopup() Done()\n\ 46 <Key>Return: KillPopup() Done()\n\ 47 Ctrl<Key>O: Nothing()\n\ 48 Meta<Key>I: Nothing()\n\ 49 Ctrl<Key>N: Nothing()\n\ 50 Ctrl<Key>P: Nothing()\n\ 51 Ctrl<Key>Z: Nothing()\n\ 52 Meta<Key>Z: Nothing()\n\ 53 Ctrl<Key>V: Nothing()\n\ 54 Meta<Key>V: Nothing()"; 55 56 /* What the actions in the translation table correspond to. */ 57 58 static XtActionsRec actiontable[] = { 59 {"KillPopup", (XtActionProc) kill_popup_shell}, 60 {"Done", NULL}, 61 {"Nothing", NULL} 62 }; 63 64 static Arg popupshellargs[] = { /* Where to put the popup shell. */ 65 {XtNx, (XtArgVal) NULL}, 66 {XtNy, (XtArgVal) NULL} 67 }; 68 69 static Arg labelargs[] = { /* ArgList for the label */ 70 {XtNborderWidth, (XtArgVal) 0}, 71 {XtNjustify, (XtArgVal) XtJustifyRight} 72 }; 73 74 static Arg textargs[] = { /* ArgList for the text widget */ 75 {XtNeditType, (XtArgVal) XawtextEdit}, 76 {XtNwidth, (XtArgVal) 200}, 77 {XtNhorizDistance, (XtArgVal) 10}, 78 {XtNfromHoriz, (XtArgVal) NULL}, 79 }; 80 81 static Arg cancelargs[] = { /* ArgList for the cancel button */ 82 {XtNfromHoriz, (XtArgVal) NULL}, 83 {XtNcallback, (XtArgVal) NULL} 84 }; 85 86 /* Procedures to call when the user selects 'cancel' */ 87 static XtCallbackRec cancelcallbacklist[] = { 88 {(XtCallbackProc) kill_popup_shell, NULL}, 89 {NULL, NULL}, 90 {NULL, NULL} 91 }; 92 93 if (popupshell != NULL) { 94 XtPopup(popupshell,XtGrabExclusive); 95 return; 96 } 97 98 /* Find out where the pointer is, so we can put the popup window there */ 99 100 (void) XQueryPointer(X.dpy,XtWindow(topform),&dummy1,&dummy2,&x1,&y1, 101 &x2,&y2,&mask); 102 103 popupshellargs[0].value = (XtArgVal) x2; 104 popupshellargs[1].value = (XtArgVal) y2; 105 106 popupshell = XtCreatePopupShell("popup",overrideShellWidgetClass, 107 topform,popupshellargs,XtNumber(popupshellargs)); 108 109 popupform = XtCreateManagedWidget("form",formWidgetClass,popupshell, 110 NULL, 0); 111 112 label = XtCreateManagedWidget("Filename: ",labelWidgetClass,popupform, 113 labelargs,XtNumber(labelargs)); 114 115 textargs[3].value = (XtArgVal) label; 116 117 filename_text_widget = XtCreateManagedWidget("text",asciiTextWidgetClass, 118 popupform, 119 textargs,XtNumber(textargs)); 120 121 /* Complete the action table. We have to do it here because success 122 ** isn't known at compile time. */ 123 124 actiontable[1].proc = (XtActionProc) success; 125 126 /* Register actions, translations, callbacks */ 127 128 XtAppAddActions(appcontext,actiontable,XtNumber(actiontable)); 129 XtOverrideTranslations(filename_text_widget, 130 XtParseTranslationTable(translationtable)); 131 cancelcallbacklist[1].callback = (XtCallbackProc) failure; 132 133 cancelargs[0].value = (XtArgVal) filename_text_widget; 134 cancelargs[1].value = (XtArgVal) cancelcallbacklist; 135 136 (void) XtCreateManagedWidget("Cancel",commandWidgetClass,popupform, 137 cancelargs,XtNumber(cancelargs)); 138 139 /* Bring up the popup. When the user presses cancel or the return key, 140 ** the function kill_popup_shell (below) will be called to remove it. */ 141 142 XtPopup(popupshell,XtGrabExclusive); 143} 144 145/* kill_popup_shell() 146** ------------------ 147** Remove the popup window that get_filename popped up. 148*/ 149 150static void 151kill_popup_shell(void) 152{ 153 XtPopdown(popupshell); 154} 155