home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / gopher / Unix / xgopher.1.3 / index.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-25  |  8.2 KB  |  342 lines

  1. /* index.c
  2.    processing for full index search support */
  3.  
  4.      /*---------------------------------------------------------------*/
  5.      /* Xgopher        version 1.3     08 April 1993                  */
  6.      /*                version 1.2     20 November 1992               */
  7.      /*                version 1.1     20 April 1992                  */
  8.      /*                version 1.0     04 March 1992                  */
  9.      /* X window system client for the University of Minnesota        */
  10.      /*                                Internet Gopher System.        */
  11.      /* Allan Tuchman, University of Illinois at Urbana-Champaign     */
  12.      /*                Computing and Communications Services Office   */
  13.      /* Copyright 1992, 1993 by                                       */
  14.      /*           the Board of Trustees of the University of Illinois */
  15.      /* Permission is granted to freely copy and redistribute this    */
  16.      /* software with the copyright notice intact.                    */
  17.      /*---------------------------------------------------------------*/
  18.  
  19.  
  20. #include <stdio.h>
  21.  
  22. #include <X11/Intrinsic.h>
  23. #include <X11/StringDefs.h>
  24.  
  25. #include <X11/Shell.h>
  26. #include <X11/Xaw/Command.h>
  27. #include <X11/Xaw/Form.h>
  28. #include <X11/Xaw/Label.h>
  29. #include <X11/Xaw/AsciiText.h>
  30.  
  31. #include "osdep.h"
  32. #include "compatR4.h"
  33. #include "index.h"
  34. #include "gui.h"
  35. #include "appres.h"
  36. #include "xglobals.h"
  37.  
  38. #define INDEX_SHELL_TITLE    "Index Search"
  39.  
  40.  
  41. static    Widget        topLevel;
  42. static    Widget        indexShell,
  43.             queryText, doIndexButton,
  44.             indexLabel;
  45. static    Boolean        indexPanelCreated = False;
  46. static    XtPointer    savedItem;
  47.  
  48. #define THIS_POPUP_NAME        "indexPopup"
  49.  
  50.                 /* default values */
  51. static popupPosResources    placement = {
  52.  
  53.     /* position at the top of the main panel, centered across */
  54.     from_main, 50, 0, justify_center, justify_top_left, True, True
  55.     };
  56.  
  57.  
  58.  
  59. /* helpProc
  60.    provide help for a index search session */
  61.  
  62. static void
  63. helpProc(w, clientData, callData)
  64. Widget        w;
  65. XtPointer    clientData, callData;
  66. {
  67.     showHelp("index help");
  68. }
  69.  
  70.  
  71. /* doIndexProc
  72.    submit a query to an index search */
  73.  
  74. static void
  75. doIndexProc(w, clientData, callData)
  76. Widget        w;
  77. XtPointer    clientData, callData;
  78. {
  79.     Cardinal    n;
  80.     Arg        args[5];
  81.     char        *string, *s;
  82.     int        length;
  83.     Boolean        inPlace;
  84.  
  85.  
  86.     n=0;
  87.     XtSetArg(args[n], XtNstring, &s);  n++;
  88.     XtGetValues(queryText, args, n);
  89.     length = strlen(s);
  90.  
  91.     string = XtMalloc(length + 1);
  92.     strncpy (string, s, length);
  93.     string[length] = '\0';
  94.  
  95.     if (strlen(string) == 0) {
  96.         showError("Enter a query string.");
  97.     } else {
  98.  
  99.         XtRemoveAllCallbacks(doIndexButton, XtNcallback);
  100.         /* do Index */
  101.         XtPopdown(indexShell);
  102.  
  103.         processIndexSelection(clientData, string);
  104.     }
  105.  
  106. }
  107.  
  108.  
  109. /* cancelProc
  110.    cancel a index search session */
  111.  
  112. static void
  113. cancelProc(w, clientData, callData)
  114. Widget        w;
  115. XtPointer    clientData, callData;
  116. {
  117.     Cardinal    n;
  118.     Arg        args[5];
  119.  
  120.     XtRemoveAllCallbacks(doIndexButton, XtNcallback);
  121.     XtPopdown(indexShell);
  122. }
  123.  
  124.  
  125. /* removeIndexPanel
  126.    remove the index panel (Pop down).  Similar to cancel button,
  127.    but a public interface with no parameters. */
  128.  
  129. void
  130. removeIndexPanel()
  131. {
  132.     cancelProc(NULL, NULL, NULL);
  133. }
  134.  
  135.  
  136. /* IndexOk
  137.    accept the "do Index" action from a keyboard <cr> instead of the
  138.    "do Index" button.  The <cr> translation is defined elsewhere.
  139.    Capitalized name is for X action proc convention. */
  140.  
  141. static void
  142. IndexOk(w, event, parms, nparms)
  143. Widget          w;
  144. XEvent          *event;
  145. String          *parms;
  146. Cardinal        *nparms;
  147. {
  148.     XtCallActionProc(doIndexButton, "set", NULL, NULL, 0);
  149.         doIndexProc(w, savedItem, NULL);
  150.     XtCallActionProc(doIndexButton, "unset", NULL, NULL, 0);
  151.         return;
  152. }
  153.  
  154.  
  155. /* IndexCancel
  156.    accept the "do Index" action by a translation.
  157.    Capitalized name is for X action proc convention. */
  158.  
  159. static void
  160. IndexCancel(w, event, parms, nparms)
  161. Widget          w;
  162. XEvent          *event;
  163. String          *parms;
  164. Cardinal        *nparms;
  165. {
  166.         cancelProc(w, NULL, NULL);
  167.         return;
  168. }
  169.  
  170.  
  171. /* displayIndexPanel
  172.    display the panel for index search queries */
  173.  
  174. void
  175. displayIndexPanel(clientData, title)
  176. XtPointer    clientData;
  177. char        *title;
  178. {
  179.     Arg        args[10];
  180.     Cardinal    n;
  181.     char        titleString[128];
  182.  
  183.  
  184.     sprintf (titleString, "Search of:  %.60s\n", title);
  185.     n=0;
  186.     XtSetArg(args[n], XtNlabel, titleString);  n++;
  187.     XtSetValues(indexLabel, args, n);
  188.  
  189.     XtAddCallback(doIndexButton, XtNcallback, doIndexProc, clientData);
  190.     savedItem = clientData;
  191.  
  192.     positionAPopup(indexShell, topLevel, &placement);
  193.  
  194.     XtPopup (indexShell, XtGrabNone);
  195.  
  196.     if (appResources->warpCursor) {
  197.         XWarpPointer(XtDisplay(indexShell), None,
  198.                 XtWindow(queryText),
  199.                 0, 0, 0, 0,
  200.                 10, 5);
  201.  
  202.     }
  203.  
  204.  
  205.     return;
  206. }
  207.  
  208.  
  209. /* makeIndexPanel
  210.    create the X panel for Index Search queries */
  211.  
  212. void
  213. makeIndexPanel(top)
  214. Widget    top;
  215. {
  216.     Arg        args[10];
  217.     Cardinal    n;
  218.     Widget        indexForm;
  219.     Widget        cancelButton, helpButton;
  220.     static XtActionsRec     indexActionsTable[] = {
  221.                 { "indexok", (XtActionProc) IndexOk },
  222.                 { "indexCancel", (XtActionProc) IndexCancel }
  223.                     };
  224.  
  225.  
  226.     if (indexPanelCreated) return;
  227.  
  228.     topLevel = top;
  229.  
  230.  
  231.     /* create Index Search shell */
  232.  
  233.         n=0;
  234.         XtSetArg(args[n], XtNtitle, INDEX_SHELL_TITLE);  n++;
  235.     indexShell = XtCreatePopupShell("indexShell",
  236.                 transientShellWidgetClass,
  237.                 topLevel, args, n);
  238.  
  239.  
  240.     /* create Index Search main panel form */
  241.  
  242.         n=0;
  243.     indexForm  = XtCreateManagedWidget("indexForm",
  244.                 formWidgetClass,
  245.                 indexShell, args, n);
  246.  
  247.  
  248.     /* create DO QUERY button */
  249.  
  250.         n=0;
  251.         XtSetArg(args[n], XtNtop,    XawChainTop);  n++;
  252.         XtSetArg(args[n], XtNbottom,    XawChainTop);  n++;
  253.         XtSetArg(args[n], XtNleft,    XawChainLeft);  n++;
  254.         XtSetArg(args[n], XtNright,    XawChainLeft);  n++;
  255.     doIndexButton = XtCreateManagedWidget("indexDoIndex",
  256.                 commandWidgetClass,
  257.                 indexForm, args, n);
  258.  
  259.  
  260.     /* create CANCEL button */
  261.  
  262.         n=0;
  263.         XtSetArg(args[n], XtNfromHoriz,    doIndexButton);  n++;
  264.         XtSetArg(args[n], XtNtop,    XawChainTop);  n++;
  265.         XtSetArg(args[n], XtNbottom,    XawChainTop);  n++;
  266.         XtSetArg(args[n], XtNleft,    XawChainLeft);  n++;
  267.         XtSetArg(args[n], XtNright,    XawChainLeft);  n++;
  268.     cancelButton = XtCreateManagedWidget("indexCancel", commandWidgetClass,
  269.                 indexForm, args, n);
  270.         XtAddCallback(cancelButton, XtNcallback, cancelProc, NULL);
  271.  
  272.  
  273.     /* create HELP button */
  274.  
  275.         n=0;
  276.         XtSetArg(args[n], XtNfromHoriz,    cancelButton);  n++;
  277.         XtSetArg(args[n], XtNtop,    XawChainTop);  n++;
  278.         XtSetArg(args[n], XtNbottom,    XawChainTop);  n++;
  279.         XtSetArg(args[n], XtNleft,    XawChainLeft);  n++;
  280.         XtSetArg(args[n], XtNright,    XawChainLeft);  n++;
  281.     helpButton = XtCreateManagedWidget("indexHelp", commandWidgetClass,
  282.                 indexForm, args, n);
  283.         XtAddCallback(helpButton, XtNcallback, helpProc, NULL);
  284.     
  285.  
  286.     /* create INDEX label */
  287.  
  288.         n=0;
  289.         XtSetArg(args[n], XtNfromVert,    doIndexButton);  n++;
  290.         XtSetArg(args[n], XtNtop,    XawChainTop);  n++;
  291.         XtSetArg(args[n], XtNbottom,    XawChainTop);  n++;
  292.         XtSetArg(args[n], XtNleft,    XawChainLeft);  n++;
  293.         XtSetArg(args[n], XtNright,    XawChainLeft);  n++;
  294.     indexLabel = XtCreateManagedWidget("indexLabel",
  295.                 labelWidgetClass,
  296.                 indexForm, args, n);
  297.  
  298.  
  299.     /* create NAME TEXT entry */
  300.  
  301.         n=0;
  302.         XtSetArg(args[n], XtNeditType, XawtextEdit);  n++;
  303.         XtSetArg(args[n], XtNstring, "");  n++;
  304.         XtSetArg(args[n], XtNfromVert,    indexLabel);  n++;
  305.         XtSetArg(args[n], XtNtop,    XawChainTop);  n++;
  306.         XtSetArg(args[n], XtNbottom,    XawChainBottom);  n++;
  307.         XtSetArg(args[n], XtNleft,    XawChainLeft);  n++;
  308.         XtSetArg(args[n], XtNright,    XawChainRight);  n++;
  309.     queryText = XtCreateManagedWidget("indexQueryText",
  310.                 asciiTextWidgetClass,
  311.                 indexForm, args, n);
  312.         setTextWidgetSize(queryText, 60, 1);
  313.     XtOverrideTranslations(queryText, oneLineParsed);
  314.  
  315.     XtAppAddActions(appcon, indexActionsTable,
  316.          XtNumber(indexActionsTable));
  317.  
  318.     XtSetKeyboardFocus(indexForm, queryText);
  319.  
  320.         /* for ICCCM window manager protocol complience */
  321.  
  322.         XtOverrideTranslations (indexShell,
  323.             XtParseTranslationTable ("<Message>WM_PROTOCOLS: indexCancel()"));
  324.         XtRealizeWidget(indexShell);
  325.         (void) XSetWMProtocols (XtDisplay(indexShell), XtWindow(indexShell),
  326.                                     &wmDeleteAtom, 1);
  327.  
  328.     /* find the popup placement for this shell */
  329.  
  330.     {
  331.     popupPosResources *resourcePlacement;
  332.  
  333.     resourcePlacement = getPopupPosResources(
  334.                 THIS_POPUP_NAME, POPUP_POS_CLASS, &placement);
  335.     bcopy( (char *) resourcePlacement, (char *) &placement,
  336.                 sizeof(popupPosResources) );
  337.     }
  338.  
  339.  
  340.     indexPanelCreated = True;
  341. }
  342.