home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / s / seyon197.tz / seyon197 / seyon / SeWin.c < prev    next >
C/C++ Source or Header  |  1993-02-20  |  20KB  |  987 lines

  1.  
  2. /*
  3.  * This file is part of the Seyon, Copyright (c) 1992-1993 by Muhammad M.
  4.  * Saggaf. All rights reserved.
  5.  *
  6.  * See the file COPYING (1-COPYING) or the manual page seyon(1) for a full
  7.  * statement of rights and permissions for this program.
  8.  */
  9.  
  10. #include <setjmp.h>
  11.  
  12. #include <X11/Intrinsic.h>
  13. #include <X11/StringDefs.h>
  14. #include <X11/Shell.h>
  15. #include <X11/Xmu/CharSet.h>
  16. #include <X11/Xaw/Command.h>
  17. #include <X11/Xaw/List.h>
  18. #include "MultiList.h"
  19. #include <X11/Xaw/Toggle.h>
  20. #include <X11/Xaw/AsciiText.h>
  21. #include <X11/Xaw/Box.h>
  22. #include <X11/Xaw/Dialog.h>
  23. #include <X11/Xaw/Form.h>
  24. #include <X11/Xaw/Paned.h>
  25.  
  26. #include "seyon.h"
  27. #include "SeDecl.h"
  28.  
  29. extern Widget   topLevel;
  30. extern Widget   statusMessage;
  31. extern Pixmap   progIcon;
  32.  
  33. void            SePopupMsg(),
  34.                 SeEditSaveFile(),
  35.                 StopMainLoop();
  36.  
  37. Boolean         DoMainLoop;
  38.  
  39. /*
  40.  * does nothing
  41.  */
  42.  
  43. void
  44. DoNothing()
  45. {
  46.   return;
  47. }
  48.  
  49. /*
  50.  * distroys a popup
  51.  */
  52.  
  53. void
  54. DestroyShell(widget)
  55.      Widget          widget;
  56. {
  57.   Widget          shell = GetShell(widget);
  58.  
  59.   XtPopdown(shell);
  60.   XtDestroyWidget(shell);
  61. }
  62.  
  63. void
  64. DestroyShellCallBack(widget, child)
  65.      Widget          widget;
  66.      XtPointer       child;
  67. {
  68.   DestroyShell((Widget)child);
  69. }
  70.  
  71. void
  72. DestroyParentPopup(widget, child)
  73.      Widget          widget;
  74.      XtPointer       child;
  75. {
  76.   DestroyShellCallBack(widget, child);
  77. }
  78.  
  79. void
  80. DismissPopup(widget, up_flag)
  81.      Widget          widget;
  82.      XtPointer       up_flag;
  83. {
  84.   *(Boolean *) up_flag = False;
  85.   DestroyParentPopup(NULL, XtParent(widget));
  86. }
  87.  
  88. void
  89. DismissPopup2(widget, up_flag)
  90.      Widget          widget;
  91.      XtPointer       up_flag;
  92. {
  93.   DismissPopup(XtParent(widget), up_flag);
  94. }
  95.  
  96. /*
  97.  * same as the above
  98.  */
  99.  
  100. void
  101. DestroyPopupPrompt(w, client_data, call_data)
  102.      Widget          w;
  103.      XtPointer       client_data,
  104.                      call_data;
  105. {
  106.   Widget          popup = XtParent((Widget) client_data);
  107.   XtDestroyWidget(popup);
  108. }
  109.  
  110. /*
  111.  * creates a button
  112.  */
  113.  
  114. Widget
  115. SeAddButton(name, parent, call_back)
  116.      String          name;
  117.      Widget          parent;
  118.      void            (*call_back) ();
  119. {
  120.   Widget          widget;
  121.  
  122.   widget = XtCreateManagedWidget(name, commandWidgetClass, parent, NULL, 0);
  123.   XtAddCallback(widget, XtNcallback, call_back, (XtPointer) parent);
  124.   return widget;
  125. }
  126.  
  127. /*
  128.  * similar to the above, but also passes client data to the call back
  129.  * WCD = with client data
  130.  */
  131.  
  132. Widget
  133. SeAddButtonWCD(name, parent, call_back, client_data)
  134.      String          name;
  135.      Widget          parent;
  136.      void            (*call_back) ();
  137.      XtPointer       client_data;
  138. {
  139.   Widget          widget;
  140.  
  141.   widget = XtCreateManagedWidget(name, commandWidgetClass, parent, NULL, 0);
  142.   XtAddCallback(widget, XtNcallback, call_back, client_data);
  143.   return widget;
  144. }
  145.  
  146. Widget
  147. SeAddButtonWithClientData(name, parent, call_back, client_data)
  148.      String          name;
  149.      Widget          parent;
  150.      void            (*call_back) ();
  151.      XtPointer       client_data;
  152. {
  153.   return SeAddButtonWCD(name, parent, call_back, client_data);
  154. }
  155.  
  156. /*
  157.  * creates a label
  158.  */
  159.  
  160. Widget
  161. SeAddLabel(name, parent)
  162.      String          name;
  163.      Widget          parent;
  164. {
  165.   return XtCreateManagedWidget(name, labelWidgetClass, parent, NULL, 0);
  166. }
  167.  
  168. /*
  169.  * sets a widget's label
  170.  */
  171.  
  172. void
  173. SeSetLabel(widget, label)
  174.      Widget          widget;
  175.      String          label;
  176. {
  177.   XtVaSetValues(widget, XtNlabel, label, NULL);
  178. }
  179.  
  180. /*
  181.  * creates a toggle
  182.  */
  183.  
  184. Widget
  185. SeAddToggleWCD(name, parent, call_back, clientData)
  186.      String          name;
  187.      Widget          parent;
  188.      void            (*call_back) ();
  189.      XtPointer       clientData;
  190. {
  191.   Widget          widget;
  192.  
  193.   widget = XtCreateManagedWidget(name, toggleWidgetClass, parent, NULL, 0);
  194.   if (call_back) {
  195.     if (clientData == NULL)
  196.       clientData = (XtPointer) parent;
  197.     XtAddCallback(widget, XtNcallback, call_back, clientData);
  198.   }
  199.   return widget;
  200. }
  201.  
  202. Widget
  203. SeAddToggle(name, parent, call_back)
  204.      String          name;
  205.      Widget          parent;
  206.      void            (*call_back) ();
  207. {
  208.   return SeAddToggleWCD(name, parent, call_back, NULL);
  209. }
  210.  
  211. /*
  212.  * sets or unsets a toggle
  213.  */
  214.  
  215. void
  216. SeSetUnsetToggle(widget, state)
  217.      Widget          widget;
  218.      Boolean         state;
  219. {
  220.   XtVaSetValues(widget, XtNstate, state, NULL);
  221. }
  222.  
  223. /*
  224.  * gets a toggle's state
  225.  */
  226.  
  227. Boolean
  228. SeGetToggleState(widget)
  229.      Widget          widget;
  230. {
  231.   Boolean         state;
  232.  
  233.   XtVaGetValues(widget, XtNstate, &state, NULL);
  234.   return state;
  235. }
  236.  
  237. Widget
  238. SePopupRadio(popup_name, parent, name, active, call_back, clientData)
  239.      String          popup_name;
  240.      Widget          parent;
  241.      String          name[];
  242.      int             active;
  243.      void            (*call_back) ();
  244.      XtPointer       clientData;
  245. {
  246.   Widget          popup,
  247.                   mBox,
  248.                   uBox,
  249.                   lBox,
  250.                   toggle,
  251.                   widget;
  252.   long            i = 0;
  253.  
  254.   popup = AddSimplePopup(popup_name, parent);
  255.   mBox = SeAddPaned("mBox", popup);
  256.   uBox = SeAddBox("Radio", mBox);
  257.   lBox = SeAddBox("lBox", mBox);
  258.  
  259.   toggle =
  260.     XtVaCreateManagedWidget(name[i], toggleWidgetClass, uBox, XtNradioData,
  261.                 (XtPointer) (i + 1), NULL);
  262.   SeSetUnsetToggle(toggle, (active == i + 1));
  263.   XtAddCallback(toggle, XtNcallback, call_back, clientData);
  264.  
  265.   for (i++; name[i]; i++) {
  266.     widget =
  267.       XtVaCreateManagedWidget(name[i], toggleWidgetClass, uBox, XtNradioGroup,
  268.                toggle, XtNradioData, (XtPointer) (i + 1), NULL);
  269.     SeSetUnsetToggle(widget, (active == i + 1));
  270.     XtAddCallback(widget, XtNcallback, call_back, clientData);
  271.   }
  272.  
  273.   SeAddButtonWCD("dismiss", lBox, DestroyParentPopup, (XtPointer) mBox);
  274.  
  275.   PopupCentered(popup, parent);
  276.   return toggle;
  277. }
  278.  
  279. /*
  280.  * creates a box
  281.  */
  282.  
  283. Widget
  284. SeAddBox(name, parent)
  285.      String          name;
  286.      Widget          parent;
  287. {
  288.   return XtCreateManagedWidget(name, boxWidgetClass, parent, NULL, 0);
  289. }
  290.  
  291. /*
  292.  * creates a dialog
  293.  */
  294.  
  295. Widget
  296. SeAddDialog(name, parent)
  297.      String          name;
  298.      Widget          parent;
  299. {
  300.   return XtCreateManagedWidget(name, dialogWidgetClass, parent, NULL, 0);
  301. }
  302.  
  303. /*
  304.  * sets a dialog's label
  305.  */
  306.  
  307. void
  308. SeSetDialogValue(dialog, value)
  309.      Widget          dialog;
  310.      String          value;
  311. {
  312.   Arg             args;
  313.  
  314.   XtSetArg(args, XtNvalue, value);
  315.   XtSetValues(dialog, &args, 1);
  316. }
  317.  
  318. Widget
  319. SePopupDialogGetStringE(popup_name, parent, ok_callback,
  320.             ok_client_data, def_val, UL)
  321.      String          popup_name;
  322.      Widget          parent;
  323.      void            (*ok_callback) ();
  324.      XtPointer       ok_client_data;
  325.      String          def_val;
  326.      Boolean         UL;
  327. {
  328.   Widget          popup,
  329.                   dialog;
  330.  
  331.   popup = AddSimplePopup(popup_name, parent);
  332.   dialog = SeAddDialog("dialog", popup);
  333.  
  334.   if (def_val)
  335.     SeSetDialogValue(dialog, def_val);
  336.   if (ok_client_data == NULL)
  337.     ok_client_data = (XtPointer) dialog;
  338.  
  339.   XawDialogAddButton(dialog, "ok", ok_callback, ok_client_data);
  340.   XawDialogAddButton(dialog, "cancel", DestroyShellCallBack,
  341.              (XtPointer) dialog);
  342.  
  343.   PopupCentered(popup, parent);
  344.   return dialog;
  345. }
  346.  
  347. Widget
  348. SePopupDialogGetString(popup_name, parent, ok_callback,
  349.                ok_client_data)
  350.      String          popup_name;
  351.      Widget          parent;
  352.      void            (*ok_callback) ();
  353.      XtPointer       ok_client_data;
  354. {
  355.   return SePopupDialogGetStringE(popup_name, parent, ok_callback,
  356.                  ok_client_data, NULL, False);
  357. }
  358.  
  359. /*
  360.  * creates a from
  361.  */
  362.  
  363. Widget
  364. SeAddForm(name, parent)
  365.      String          name;
  366.      Widget          parent;
  367. {
  368.   return XtCreateManagedWidget(name, formWidgetClass, parent, NULL, 0);
  369. }
  370.  
  371. Widget
  372. SeAddPaned(name, parent)
  373.      String          name;
  374.      Widget          parent;
  375. {
  376.   return XtCreateManagedWidget(name, panedWidgetClass, parent, NULL, 0);
  377. }
  378.  
  379. /*
  380.  * sets a viewport's dimensions
  381.  */
  382.  
  383. void
  384. SeSetViewportDimensions(viewport, child, max_height)
  385.      Widget          viewport,
  386.                      child;
  387.      Dimension       max_height;
  388. {
  389.   SeSetWidgetWidth(viewport, SeWidgetWidth(child) + 14);
  390.  
  391.   if (SeWidgetHeight(child) > max_height)
  392.     SeSetWidgetHeight(viewport, max_height);
  393. }
  394.  
  395. /*
  396.  * sets a viwport's dimensions according to a child list
  397.  */
  398.  
  399. void
  400. SeSetViewportDimFromList(viewport, list, rows)
  401.      Widget          viewport,
  402.                      list;
  403.      Cardinal        rows;
  404. {
  405.   XFontStruct    *font;
  406.   Dimension       height,
  407.                   internalHeight,
  408.                   rowSpacing,
  409.                   borderWidth;
  410.   Cardinal        n;
  411.   Arg             args[5];
  412.  
  413.   n = 0;
  414.   XtSetArg(args[n], XtNfont, &font);
  415.   n++;
  416.   XtSetArg(args[n], XtNinternalHeight, &internalHeight);
  417.   n++;
  418.   XtSetArg(args[n], XtNrowSpacing, &rowSpacing);
  419.   n++;
  420.   XtSetArg(args[n], XtNborderWidth, &borderWidth);
  421.   n++;
  422.   XtGetValues(list, args, n);
  423.  
  424.   height = font->ascent + font->descent;
  425.   height = height * rows + rowSpacing * (rows - 1) +
  426.     2 * (internalHeight + borderWidth);
  427.  
  428.   SeSetViewportDimensions(viewport, list, height);
  429. }
  430.  
  431. /*
  432.  * sets a viwport's dimensions according to a child multi-list
  433.  */
  434.  
  435. void
  436. SeSetViewportDimFromMultiList(viewport, list, rows)
  437.      Widget          viewport,
  438.                      list;
  439.      Cardinal        rows;
  440. {
  441.   Dimension       rowHeight,
  442.                   borderWidth;
  443.   Cardinal        n;
  444.   Arg             args[2];
  445.  
  446.   n = 0;
  447.   XtSetArg(args[n], XtNrowHeight, &rowHeight);
  448.   n++;
  449.   XtSetArg(args[n], XtNborderWidth, &borderWidth);
  450.   n++;
  451.   XtGetValues(list, args, n);
  452.  
  453.   SeSetViewportDimensions(viewport, list,
  454.               rowHeight * rows + 2 * borderWidth);
  455. }
  456.  
  457. /*
  458.  * creates a transient popup
  459.  */
  460.  
  461. Widget
  462. SeCreatePopup(name, parent)
  463.      String          name;
  464.      Widget          parent;
  465. {
  466.   return SeAddPopup(name, parent);
  467. }
  468.  
  469. Widget
  470. GetShell(w)
  471.      Widget          w;
  472. {
  473.   while ((w != NULL) && !XtIsShell(w))
  474.     w = XtParent(w);
  475.  
  476.   return (w);
  477. }
  478.  
  479. /*
  480.  *   Creates a popup with a bit more control on geometry.
  481.  *   WG = With Geometry
  482.  */
  483.  
  484. void
  485. CenterShell(widget, geomParent)
  486.      Widget          widget,
  487.                      geomParent;
  488. {
  489.   Dimension width, height, borderWidth;
  490.   Position x, y, max;
  491.  
  492.   XtVaGetValues(geomParent, XtNwidth, &width, XtNheight, &height, NULL);
  493.   XtTranslateCoords(geomParent, (Position)width/2, (Position)height/2, 
  494.                     &x, &y);
  495.  
  496.   widget = GetShell(widget);
  497.   if (!XtIsRealized(widget)) XtRealizeWidget(widget);
  498.  
  499.   XtVaGetValues(widget, XtNwidth, &width, XtNheight, &height, XtNborderWidth,
  500.                 &borderWidth, NULL);
  501.  
  502.   width += 2 * borderWidth;
  503.   height += 2 * borderWidth;
  504.  
  505.   x -= (Position)width/2;
  506.   if (x < 0) x = 0;
  507.   if (x > (max = (Position)(XtScreen(widget)->width - width))) x = max;
  508.  
  509.   y -= (Position)height/2;
  510.   if (y < 0) y = 0;
  511.   if (y > (max = (Position)(XtScreen(widget)->height - height))) y = max;
  512.  
  513.   XtVaSetValues(widget, XtNx, x, XtNy, y, NULL);
  514. }
  515.  
  516. Widget
  517. SeAddPopupWG(name, parent, x_widget, y_widget, x_offset, y_offset, topLev,
  518.          setGeom)
  519.      String          name;
  520.      Widget          parent,
  521.                      x_widget,
  522.                      y_widget;
  523.      Position        x_offset,
  524.                      y_offset;
  525.      Boolean         topLev;
  526.      Boolean         setGeom;
  527. {
  528.   Widget          popup;
  529.   Position        x,
  530.                   y,
  531.                   dummy;
  532.  
  533.   if (x_widget == NULL)
  534.     x_widget = parent;
  535.   if (y_widget == NULL)
  536.     y_widget = x_widget;
  537.  
  538.   if (topLev)
  539.     popup = XtVaCreatePopupShell(name, topLevelShellWidgetClass, parent,
  540.                                  XtNiconPixmap, progIcon, NULL);
  541.   else
  542.     popup = XtVaCreatePopupShell(name, transientShellWidgetClass, parent,
  543.                                  XtNtransientFor, GetShell(parent),
  544.                                  XtNiconPixmap, progIcon, NULL);
  545.  
  546.   if (setGeom) {
  547.     XtTranslateCoords(x_widget, x_offset, (Position)0, &x, &dummy);
  548.     XtTranslateCoords(y_widget, (Position)0, y_offset, &dummy, &y);
  549.     XtVaSetValues(popup, XtNx, x, XtNy, y, NULL);
  550.   }
  551.  
  552.   return popup;
  553. }
  554.  
  555. Widget
  556. AddSimplePopup(name, parent)
  557.      String          name;
  558.      Widget          parent;
  559. {
  560.   return XtVaCreatePopupShell(name, transientShellWidgetClass, parent,
  561.                               XtNtransientFor, GetShell(parent),
  562.                               XtNiconPixmap, progIcon, NULL);
  563. }
  564.  
  565. Widget
  566. SeAddPopup(name, parent)
  567.      String          name;
  568.      Widget          parent;
  569. {
  570.   return SeAddPopupWG(name, parent, NULL, NULL, SeWidgetWidth(parent) / 2,
  571.               SeWidgetHeight(parent), False, True);
  572. }
  573.  
  574. Widget
  575. SeAddPopupOffset(name, parent, geomParent)
  576.      String          name;
  577.      Widget          parent;
  578.      Widget          geomParent;
  579. {
  580.   return SeAddPopupWG(name, parent, geomParent, geomParent, 10, 10, False,
  581.               True);
  582. }
  583.  
  584. Widget
  585. SeAddPopupUL(name, parent)
  586.      String          name;
  587.      Widget          parent;
  588. {
  589.   return SeAddPopupOffset(name, parent, XtParent(parent));
  590. }
  591.  
  592. Widget
  593. SeAddPopupSh(name, parent)
  594.      String          name;
  595.      Widget          parent;
  596. {
  597.   return SeAddPopupOffset(name, parent, GetShell(parent));
  598. }
  599.  
  600. /*
  601.  * creates a top-level popup
  602.  */
  603.  
  604. Widget
  605. SeCreateTopLevelPopup(name, parent, x_widget, y_widget)
  606.      String          name;
  607.      Widget          parent,
  608.                      x_widget,
  609.                      y_widget;
  610. {
  611.   Arg             args[5];
  612.   Position        x,
  613.                   y,
  614.                   dummy;
  615.   Dimension       width,
  616.                   height;
  617.   Cardinal        n;
  618.  
  619.  
  620.   if (x_widget == NULL)
  621.     x_widget = parent;
  622.   if (y_widget == NULL)
  623.     y_widget = x_widget;
  624.  
  625.   n = 0;
  626.   XtSetArg(args[n], XtNwidth, &width);
  627.   n++;
  628.   XtGetValues(x_widget, args, n);
  629.   XtTranslateCoords(x_widget, (Position) (width / 2),
  630.             (Position) 0, &x, &dummy);
  631.  
  632.   n = 0;
  633.   XtSetArg(args[n], XtNheight, &height);
  634.   n++;
  635.   XtGetValues(y_widget, args, n);
  636.   XtTranslateCoords(y_widget, (Position) 0, (Position) height,
  637.             &dummy, &y);
  638.  
  639. /*
  640.   XtSetArg(args[n], XtNinternalHeight, &internalHeight); n++;
  641.   XtTranslateCoords(y_widget, (Position) 0,
  642.                     (Position) (height + 2 * internalHeight),
  643.                     &dummy, &y);
  644. */
  645.  
  646.   n = 0;
  647.   XtSetArg(args[n], XtNx, x);
  648.   n++;
  649.   XtSetArg(args[n], XtNy, y);
  650.   n++;
  651.  
  652.   return XtCreatePopupShell(name, topLevelShellWidgetClass,
  653.                 parent, args, n);
  654. }
  655.  
  656. /*
  657.  * pops up a message
  658.  */
  659.  
  660. void
  661. SePopupMsg(parent, msg)
  662.      Widget          parent;
  663.      String          msg;
  664. {
  665.   Widget          popup,
  666.                   dialog;
  667.   Arg             args;
  668.  
  669.   popup = SeCreatePopup("message", parent);
  670.  
  671.   XtSetArg(args, XtNlabel, msg);
  672.   dialog = XtCreateManagedWidget("dialog", dialogWidgetClass, popup,
  673.                  &args, 1);
  674.  
  675.   XawDialogAddButton(dialog, "dismiss", DestroyPopupPrompt,
  676.              (XtPointer) dialog);
  677.  
  678.   XtPopup(popup, XtGrabExclusive);
  679. }
  680.  
  681. void
  682. SePopupMsgf(parent, fmt, a, b, c)
  683.      Widget          parent;
  684.      String          fmt,
  685.                      a,
  686.                      b,
  687.                      c;
  688. {
  689.   char            buf[REG_BUF];
  690.  
  691.   sprintf(buf, fmt, a, b, c);
  692.   SePopupMsg(parent, buf);
  693. }
  694.  
  695. Widget
  696. SePopupNotice(parent, title, call_back, msg)
  697.      Widget          parent;
  698.      String          title;
  699.      void            (*call_back) ();
  700.      String          msg;
  701. {
  702.   Widget          popup,
  703.                   dialog;
  704.  
  705.   popup = SeAddPopupUL("notice", parent);
  706.   XtVaSetValues(popup, XtNtitle, title, NULL);
  707.   dialog = XtVaCreateManagedWidget("dialog", dialogWidgetClass, popup,
  708.                    XtNlabel, msg, NULL);
  709.  
  710.   XawDialogAddButton(dialog, "dismiss", call_back, (XtPointer) dialog);
  711.  
  712.   XtPopup(popup, XtGrabExclusive);
  713.   return popup;
  714. }
  715.  
  716. void
  717. SePopupNoticeF(parent, title, call_back, fmt, a, b, c, d)
  718.      Widget          parent;
  719.      String          title;
  720.      void            (*call_back) ();
  721.      String          fmt,
  722.                      a,
  723.                      b,
  724.                      c,
  725.                      d;
  726. {
  727.   char            buf[REG_BUF];
  728.  
  729.   sprintf(buf, fmt, a, b, c);
  730.   SePopupNotice(parent, title, call_back, buf);
  731. }
  732.  
  733. /*
  734.  * almost similar to the above
  735.  */
  736.  
  737. void
  738. SeTransMsg(name, parent)
  739.      String          name;
  740.      Widget          parent;
  741. {
  742.   Widget          popup,
  743.                   dialog;
  744.  
  745.   popup = SeCreatePopup(name, parent);
  746.   dialog = XtCreateManagedWidget("dialog", dialogWidgetClass, popup,
  747.                  NULL, 0);
  748.  
  749.   XawDialogAddButton(dialog, "dismiss", DestroyPopupPrompt,
  750.              (XtPointer) dialog);
  751.  
  752.   XtPopupSpringLoaded(popup);
  753. }
  754.  
  755. /*
  756.  * pops up a message to the effect that a feature is not implemented
  757.  */
  758.  
  759. void
  760. NotImplemented(w)
  761.      Widget          w;
  762. {
  763.   SeTransMsg("notImplemented", w);
  764. }
  765.  
  766. void
  767. SeSetValue(widget, name, value)
  768.      Widget          widget;
  769.      String          name;
  770.      XtArgVal        value;
  771. {
  772.   Arg             args;
  773.  
  774.   XtSetArg(args, name, value);
  775.   XtSetValues(widget, &args, 1);
  776. }
  777.  
  778. /*
  779.  * returns a widget's height
  780.  */
  781.  
  782. Dimension
  783. SeWidgetHeight(widget)
  784.      Widget          widget;
  785. {
  786.   Dimension       height;
  787.   Arg             args;
  788.  
  789.   XtSetArg(args, XtNheight, &height);
  790.   XtGetValues(widget, &args, 1);
  791.   return height;
  792. }
  793.  
  794. /*
  795.  * sets a widget's height
  796.  */
  797.  
  798. void
  799. SeSetWidgetHeight(widget, height)
  800.      Widget          widget;
  801.      Dimension       height;
  802. {
  803.   Arg             args;
  804.  
  805.   XtSetArg(args, XtNheight, height);
  806.   XtSetValues(widget, &args, 1);
  807. }
  808.  
  809. /*
  810.  * returns a widget's width
  811.  */
  812.  
  813. Dimension
  814. SeWidgetWidth(widget)
  815.      Widget          widget;
  816. {
  817.   Dimension       width;
  818.   Arg             args;
  819.  
  820.   XtSetArg(args, XtNwidth, &width);
  821.   XtGetValues(widget, &args, 1);
  822.   return width;
  823. }
  824.  
  825. /*
  826.  * sets a widget's width
  827.  */
  828.  
  829. void
  830. SeSetWidgetWidth(widget, width)
  831.      Widget          widget;
  832.      Dimension       width;
  833. {
  834.   Arg             args;
  835.  
  836.   XtSetArg(args, XtNwidth, width);
  837.   XtSetValues(widget, &args, 1);
  838. }
  839.  
  840. /*
  841.  * sets the status message
  842.  */
  843.  
  844. void
  845. SetStatusMessage(msg)
  846.      String          msg;
  847. {
  848.   SeSetLabel(statusMessage, msg);
  849. /*  XFlush(XtDisplay(statusMessage));*/
  850. }
  851.  
  852. /*
  853.  * similar to the above, but accepts a formmat string
  854.  */
  855.  
  856. void
  857. SetStatusMessagef(fmt, a, b, c)
  858.      String          fmt,
  859.                      a,
  860.                      b,
  861.                      c;
  862. {
  863.   char            buffer[REG_BUF];
  864.  
  865.   sprintf(buffer, fmt, a, b, c);
  866.   SetStatusMessage(buffer);
  867. }
  868.  
  869. /*
  870.  * beeps the bell
  871.  */
  872.  
  873. void
  874. SeBeep(widget)
  875.      Widget          widget;
  876. {
  877.   XBell(XtDisplay(widget), 10);
  878. }
  879.  
  880. void
  881. Beep()
  882. {
  883.   XBell(XtDisplay(topLevel), 10);
  884. }
  885.  
  886. /*
  887.  * displays a file in a popup
  888.  */
  889.  
  890. void
  891. SeDisplayFile(parent, geomParent, file_name)
  892.      Widget          parent;
  893.      Widget          geomParent;
  894.      XtPointer       file_name;
  895. {
  896.   Widget          popup,
  897.                   form;
  898.  
  899.   if (geomParent == NULL)
  900.     geomParent = parent;
  901.  
  902.   popup = SeAddPopupOffset("display", parent, geomParent);
  903.   form = SeAddForm("form", popup);
  904.  
  905.   XtVaCreateManagedWidget("text", asciiTextWidgetClass, form, XtNtype,
  906.               XawAsciiFile, XtNstring, (String) file_name,
  907.               NULL);
  908.  
  909.   SeAddButton("dismiss", form, DestroyShellCallBack);
  910.  
  911.   XtPopup(popup, XtGrabExclusive);
  912. }
  913.  
  914. /*
  915.  * pops up a file for editing
  916.  */
  917.  
  918. void
  919. EditFile(parent, file_name)
  920.      Widget          parent;
  921.      XtPointer       file_name;
  922. {
  923.   Widget          popup,
  924.                   form,
  925.                   text;
  926.  
  927.   popup = AddSimplePopup("edit", parent);
  928.   form = SeAddForm("form", popup);
  929.  
  930.   text = XtVaCreateManagedWidget("text", asciiTextWidgetClass, form, XtNtype,
  931.                  XawAsciiFile, XtNstring, (String) file_name, NULL);
  932.  
  933.   SeAddButtonWCD("save", form, SeEditSaveFile, text);
  934.   SeAddButton("dismiss", form, DestroyShellCallBack);
  935.  
  936.   PopupCentered(popup, parent);
  937. }
  938.  
  939. /*
  940.  * saves the file being edited
  941.  */
  942.  
  943. void
  944. SeEditSaveFile(widget, text)
  945.      Widget          widget;
  946.      XtPointer       text;
  947. {
  948.   Widget          textSource;
  949.   Arg             args;
  950.  
  951.   XtSetArg(args, XtNtextSource, &textSource);
  952.   XtGetValues(text, &args, 1);
  953.  
  954.   if (XawAsciiSave(textSource) != True)
  955.     SePopupMsg(widget, "File Save Failed");
  956. }
  957.  
  958. jmp_buf         MainLoopEnv;
  959.  
  960. void
  961. SeAppMainLoop(app_context)
  962.      XtAppContext    app_context;
  963. {
  964.   DoMainLoop = True;
  965.   while (DoMainLoop)
  966.     XtAppProcessEvent(app_context, XtIMAll);
  967. }
  968.  
  969. void
  970. StopMainLoop()
  971. {
  972.   DoMainLoop = False;
  973. }
  974.  
  975. void
  976. SeAppMSleep(app_context, msec)
  977.      XtAppContext    app_context;
  978.      unsigned long   msec;
  979. {
  980.   Widget          widget = statusMessage;
  981.  
  982.   XtAppAddTimeOut(app_context, msec, (XtTimerCallbackProc) StopMainLoop, NULL);
  983.   XtAddGrab(widget, True, False);
  984.   SeAppMainLoop(app_context);
  985.   XtRemoveGrab(widget);
  986. }
  987.