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