home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume2 / xbrowser / part02 / popup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-01-03  |  10.2 KB  |  407 lines

  1. /* Systems Sciences Laboratory, Webster Research Center */
  2.  
  3. static char *PROGRAM_information[] =
  4. {
  5.     "Copyright (c) 1988 Xerox Corporation.  All rights reserved.",
  6.     "$Header$",
  7.     "$Locker$"
  8. }
  9. ;
  10.  
  11. /*
  12.  * Copyright protection claimed includes all forms and matters of copyrightable
  13.  * material and information now allowed by statutory or judicial lay or
  14.  * herinafter granted, including without limitation, material generated from
  15.  * the software programs which are displayed on the screen such as icons,
  16.  * screen display looks, etc.
  17.  */
  18.  
  19. #include "xfilebrowser.h"
  20.  
  21. Widget confirmwidget = NULL;
  22. static Widget confirmshell = NULL;
  23. static Widget extpromptwidget = NULL;        /* specifies the form widget
  24.                 in case a prompt with toggle was created */
  25. static Widget extoutwidget;
  26. static Widget extdiagwidget;
  27.  
  28. static Widget logshell = NULL;
  29. static Widget loglabel;
  30. static Widget logpane;
  31. static Widget logbox;
  32. static Widget logtext;
  33.  
  34. static short disp_prompt = 0;
  35.  
  36. check_confirm()
  37. {
  38.     return disp_prompt;
  39. }
  40.  
  41. check_prompt()
  42. {
  43.     return disp_prompt;
  44. }
  45.  
  46.  
  47.  
  48. /* ARGSUSED */
  49. change_sensitive(w, value)
  50. Widget w;
  51. Boolean value;
  52. {
  53.     XtSetSensitive(listbutton, value);
  54.     XtSetSensitive(editbutton, value);
  55.     XtSetSensitive(parentdirbutton, value);
  56.     XtSetSensitive(renamebutton, value);
  57.     XtSetSensitive(deletebutton, value);
  58.     XtSetSensitive(shellbutton, value);
  59.     XtSetSensitive(copybutton, value);
  60.     XtSetSensitive(grepbutton, value);
  61.     XtSetSensitive(grepeditbutton, value);
  62. }
  63.  
  64. /* ARGSUSED */
  65. confirmyes(w, client_data, call_data)
  66. Widget w;
  67. caddr_t client_data, call_data;
  68. {
  69.     DialogData *data = (DialogData *)client_data;
  70.  
  71.     destroyconfirm(data, (*data->yes));
  72. }
  73.  
  74. /* ARGSUSED */
  75. confirmno(w, client_data, call_data)
  76. Widget w;
  77. caddr_t client_data, call_data;
  78. {
  79.     DialogData *data = (DialogData *)client_data;
  80.  
  81.     destroyconfirm(data, (*data->no));
  82. }
  83.  
  84. /* ARGSUSED */
  85. confirmcancel(w, client_data, call_data)
  86. Widget w;
  87. caddr_t client_data, call_data;
  88. {
  89.     DialogData *data = (DialogData *)client_data;
  90.  
  91.     destroyconfirm(data, (*data->cancel));
  92. }
  93.  
  94. /* ARGSUSED */
  95. destroyconfirm(data, func)
  96. DialogData *data;
  97. int (*func)();
  98. {
  99.     change_sensitive(data->w, TRUE);
  100.     XtPopdown(confirmshell);
  101.     disp_prompt = 0;
  102.  
  103.     extpromptwidget = NULL;
  104.     XtDestroyWidget(confirmshell);
  105.     confirmshell = NULL;
  106.         /* I tried to reuse the previous popup shell for new
  107.         dialog widgets; but after the first use the dialog buttons
  108.         of my dialog widget were never displayed; it displayed
  109.         only the label of the dialog box */
  110.     
  111.     func(data);
  112. }
  113.  
  114. int move_popup(w, caller)
  115. Widget w, caller;
  116. {
  117.     Dimension widthw, heightw;
  118.     Position callerx, callery;
  119.     int wx, wy;
  120.     Window parentcaller, child;
  121.     Screen *screen;
  122.  
  123.     getsize(w, &widthw, &heightw);
  124.     getpos(caller, &callerx, &callery);
  125.     parentcaller = XtWindow(XtParent(caller));
  126.     screen = XtScreen(caller);
  127.     if (XTranslateCoordinates(curdisplay, parentcaller, screen->root, 
  128.         (int)callerx, (int)callery, &wx, &wy, &child) == BadWindow) 
  129.        return(-1);
  130.     wx += 5; wy += 5;
  131.  
  132.     if ( (wx + widthw) >= screen->width)
  133.        wx = screen->width - widthw - 10;
  134.     if ( (wy + heightw) >= screen->height)
  135.        wy = screen->height - heightw - 10;
  136.  
  137.     XtMoveWidget(w, (Position)wx, (Position)wy);
  138.     return(0);
  139. }
  140.  
  141. /* ARGSUSED */
  142. int position_dialog(dialog, caller)
  143. Widget dialog, caller;
  144. {
  145.     XtSetMappedWhenManaged(dialog, FALSE);
  146.     XtRealizeWidget(dialog);
  147.  
  148.     move_popup(dialog, caller);
  149.  
  150.     change_sensitive(caller, FALSE);
  151.     XtMapWidget(dialog);
  152.     return(0);
  153. }
  154.  
  155. /* ARGSUSED */
  156. int create_confirm(data, str)
  157. DialogData *data;
  158. char *str;
  159. {
  160.     Arg args[1];
  161.     Arg popargs[1];
  162.  
  163.     if (disp_prompt) return(-1);
  164.  
  165.     disp_prompt = 1;
  166.     XtSetArg( popargs[0], XtNborderWidth, 2 );
  167.  
  168.  
  169.     confirmshell = XtCreatePopupShell("popupshell",
  170.                overrideShellWidgetClass,
  171.             toplevel, popargs, XtNumber(popargs));
  172.  
  173.     XtSetArg( args[0], XtNlabel, str );
  174.     
  175.     confirmwidget = XtCreateManagedWidget("confirm", dialogWidgetClass,
  176.             confirmshell, args, XtNumber(args) );
  177.     XtDialogAddButton(confirmwidget, "yes", confirmyes, (caddr_t)data);
  178.     XtDialogAddButton(confirmwidget, "no", confirmno, (caddr_t)data);
  179.     XtDialogAddButton(confirmwidget, "cancel", confirmcancel, (caddr_t)data);
  180.  
  181.     if (position_dialog(confirmshell, data->w) == -1) {
  182.        XtDestroyWidget(confirmshell);
  183.        confirmwidget = NULL;
  184.        confirmshell = NULL;
  185.     }
  186.     XtPopup(confirmshell, XtGrabNonexclusive);
  187.     return(0);
  188. }
  189.  
  190.  
  191. /* ARGSUSED */
  192. promptok(w, client_data, call_data)
  193. Widget w;
  194. caddr_t client_data, call_data;
  195. {
  196.     DialogData *data = (DialogData *)client_data;
  197.     Arg togargs[1];
  198.     XtState extstate;
  199.  
  200.     data->answer = XtDialogGetValueString(confirmwidget);
  201.     if (extpromptwidget != NULL) {
  202.        XtSetArg(togargs[0], XtNstate, (XtArgVal)&extstate);
  203.        XtGetValues(extdiagwidget, togargs, (Cardinal)1);
  204.        data->diag = (Boolean)extstate;
  205.  
  206.        XtSetArg(togargs[0], XtNstate, (XtArgVal)&extstate);
  207.        XtGetValues(extoutwidget, togargs, (Cardinal)1);
  208.        data->out = (Boolean)extstate;
  209.     }
  210.     else data->diag = data->out = FALSE;
  211.  
  212.     destroyconfirm(data, (*data->yes));
  213. }
  214.  
  215. /* ARGSUSED */
  216. promptcancel(w, client_data, call_data)
  217. Widget w;
  218. caddr_t client_data, call_data;
  219. {
  220.     DialogData *data = (DialogData *)client_data;
  221.  
  222.     destroyconfirm(data, (*data->cancel));
  223. }
  224.  
  225. /* ARGSUSED */
  226. int create_prompt(data, str, defvalue)
  227. DialogData *data;
  228. char *str, *defvalue;
  229. {
  230.     Arg args[2];
  231.     Arg popargs[1];
  232.  
  233.     if (disp_prompt) return(-1);
  234.     disp_prompt = 1;
  235.  
  236.     XtSetArg( popargs[0], XtNborderWidth, 2 );
  237.  
  238. /*    confirmshell = XtCreatePopupShell("promptshell",
  239.                transientShellWidgetClass,
  240.             toplevel, popargs, XtNumber(popargs));*/
  241. confirmshell = XtCreatePopupShell("promptshell",
  242.                topLevelShellWidgetClass,
  243.             toplevel, popargs, XtNumber(popargs));
  244.  
  245.     XtSetArg( args[0], XtNlabel, str );
  246.     XtSetArg( args[1], XtNvalue, defvalue );
  247.     
  248.     confirmwidget = XtCreateManagedWidget("confirm", dialogWidgetClass,
  249.             confirmshell, args, XtNumber(args) );
  250.     XtDialogAddButton(confirmwidget, "ok", promptok, (caddr_t)data);
  251.     XtDialogAddButton(confirmwidget, "cancel", promptcancel, (caddr_t)data);
  252.  
  253.     if (position_dialog(confirmshell, data->w) == -1) {
  254.        XtDestroyWidget(confirmshell);
  255.        confirmwidget = NULL;
  256.        confirmshell = NULL;
  257.     }
  258.     XtPopup(confirmshell, XtGrabNonexclusive);
  259.     return(0);
  260. }
  261.  
  262. /* ARGSUSED */
  263. /* creates a prompt window which contains a dialog widget as well as two
  264.  * toggle widgets defining if the output/diagnostics should be returned 
  265.  */
  266. int create_toggleprompt(data, str, defvalue)
  267. DialogData *data;
  268. char *str, *defvalue;
  269. {
  270.     Arg args[3];
  271.     Arg popargs[1];
  272.     Arg toggleargs[6];
  273.  
  274.     if (disp_prompt) return(-1);
  275.     disp_prompt = 1;
  276.  
  277.     XtSetArg( popargs[0], XtNborderWidth, 2 );
  278.  
  279. /*    confirmshell = XtCreatePopupShell("toggleshell",
  280.                transientShellWidgetClass,
  281.             toplevel, popargs, XtNumber(popargs));*/
  282. confirmshell = XtCreatePopupShell("toggleshell",
  283.                topLevelShellWidgetClass,
  284.             toplevel, popargs, XtNumber(popargs));
  285.     extpromptwidget = XtCreateManagedWidget("form", formWidgetClass,
  286.             confirmshell, NULL, 0);
  287.  
  288.     XtSetArg( args[0], XtNlabel, str );
  289.     XtSetArg( args[1], XtNvalue, defvalue );
  290.     XtSetArg( args[2], XtNborderWidth, 0 );
  291.     
  292.     confirmwidget = XtCreateManagedWidget("confirm", dialogWidgetClass,
  293.             extpromptwidget, args, XtNumber(args) );
  294.     XtDialogAddButton(confirmwidget, "ok", promptok, (caddr_t)data);
  295.     XtDialogAddButton(confirmwidget, "cancel", promptcancel, (caddr_t)data);
  296.  
  297.     /* create the two toggle buttons "Return Diagnostic"
  298.      * and "Return Output" */ 
  299.     XtSetArg( toggleargs[0], XtNfromVert, (XtArgVal)confirmwidget );
  300.     XtSetArg( toggleargs[1], XtNfromHoriz, (XtArgVal)NULL);
  301.     XtSetArg( toggleargs[2], XtNleft, (XtArgVal)XtChainLeft);
  302.     XtSetArg( toggleargs[3], XtNright, (XtArgVal)XtChainLeft);
  303.     XtSetArg( toggleargs[4], XtNstate, (XtArgVal)XtToggleOff );
  304.     extoutwidget = XtCreateManagedWidget( "Return Output", 
  305.             toggleWidgetClass, extpromptwidget, toggleargs,
  306.             XtNumber(toggleargs) - 1 );
  307.  
  308.     XtSetArg( toggleargs[0], XtNfromVert, (XtArgVal)confirmwidget );
  309.     XtSetArg( toggleargs[1], XtNfromHoriz, (XtArgVal)extoutwidget );
  310.     XtSetArg( toggleargs[2], XtNleft, (XtArgVal)XtChainLeft);
  311.     XtSetArg( toggleargs[3], XtNright, (XtArgVal)XtChainLeft);
  312.     XtSetArg( toggleargs[4], XtNstate, (XtArgVal)XtToggleOn);
  313.     XtSetArg( toggleargs[5], XtNhorizDistance, (XtArgVal)20);
  314.     extdiagwidget = XtCreateManagedWidget( "Return Diagnostic", 
  315.             toggleWidgetClass, extpromptwidget, toggleargs,
  316.             XtNumber(toggleargs) );
  317.  
  318.     if (position_dialog(confirmshell, data->w) == -1) {
  319.        XtDestroyWidget(confirmshell);
  320.        confirmshell = NULL;
  321.        extpromptwidget = NULL;
  322.     }
  323.     XtPopup(confirmshell, XtGrabNonexclusive);
  324.     return(0);
  325. }
  326.  
  327.  
  328. /* ARGSUSED */
  329. logquit()
  330. {
  331.     XtPopdown(logshell);
  332.     XtSetSensitive(outer, TRUE);    
  333.     return;
  334. }
  335.  
  336. create_log()
  337. {
  338.     Arg popargs[1];
  339.  
  340.     static Arg textargs[] = {
  341.        { XtNfile, (XtArgVal)"/dev/null"},
  342.        { XtNeditType, (XtArgVal)XttextRead },
  343.        { XtNtextOptions, (XtArgVal)(wordBreak | scrollVertical) },
  344.     };    
  345.  
  346.     static Arg labelargs[] = {
  347.        { XtNjustify, (XtArgVal)XtJustifyCenter },
  348.        { XtNlabel,     NULL },
  349.     };
  350.  
  351.  
  352.     if (logshell != NULL)  return;
  353.     XtSetArg( popargs[0], XtNborderWidth, 2 );
  354.  
  355. /*    logshell = XtCreatePopupShell("logshell",
  356.                transientShellWidgetClass,
  357.             toplevel, popargs, XtNumber(popargs));*/
  358. logshell = XtCreatePopupShell("logshell",
  359.                topLevelShellWidgetClass,
  360.             toplevel, popargs, XtNumber(popargs));
  361.  
  362.     logpane = XtCreateManagedWidget("pane", vPanedWidgetClass, 
  363.             logshell, (ArgList)NULL, 0);
  364.     logbox = XtCreateManagedWidget("box", boxWidgetClass, 
  365.             logpane, (ArgList)NULL,0);
  366.     makeCommandButton(logbox, "Quit", logquit);
  367.     loglabel = XtCreateManagedWidget("labelWindow",labelWidgetClass, 
  368.         logpane, labelargs, XtNumber(labelargs)); 
  369.     logtext = XtCreateManagedWidget("data", asciiDiskWidgetClass,
  370.             logpane, textargs, XtNumber(textargs));
  371.     
  372. }
  373.  
  374. /* ARGSUSED */
  375. log_popup(label, file)
  376. char *label, *file;
  377. {
  378.     XtTextSource old, new;
  379.  
  380.     static Arg textargs[] = {
  381.        { XtNfile, NULL},
  382.        { XtNeditType, (XtArgVal)XttextRead },
  383.        { XtNtextOptions, (XtArgVal)(wordBreak | scrollVertical) },
  384.     };    
  385.  
  386.     static Arg labelargs[] = {
  387.        { XtNjustify, (XtArgVal)XtJustifyCenter },
  388.        { XtNlabel,     NULL },
  389.     };
  390.  
  391.     textargs[0].value = (XtArgVal)file;
  392.     labelargs[1].value = (XtArgVal)label;
  393.     
  394.  
  395.     if (logshell == NULL) create_log();
  396.     old = XtTextGetSource(logtext);
  397.     new = XtDiskSourceCreate(logtext, textargs, XtNumber(textargs));
  398.     XtTextSetSource(logtext, new, 0);
  399.     XtDiskSourceDestroy(old);
  400.     XtSetValues(loglabel, labelargs, XtNumber(labelargs));
  401.  
  402.     XtSetSensitive(outer, FALSE);    
  403.     XtPopup(logshell, XtGrabExclusive);
  404.     return(0);
  405. }
  406.  
  407.