home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume19 / Jetedit / part02 / xmespec.c < prev   
Encoding:
C/C++ Source or Header  |  1993-04-28  |  22.1 KB  |  712 lines

  1. /**---------------------------------------------------------------------
  2. ***     
  3. ***    file:        xmespec.c
  4. ***            Special dialogs and supporting routines.
  5. ***
  6. ***    project:    jetedit - Motif Widgets text editor
  7. ***
  8. ***-------------------------------------------------------------------*/
  9.  
  10. #include "xme.h"
  11. #define FIND 1
  12. #define REPLACE 2
  13.  
  14. static Widget    Find_dialog;
  15. static Widget    find_entry;
  16. static Widget    replace_entry;
  17. static Widget    start_at_top;
  18. static Widget    find_case;
  19. static Widget    regular_exp;
  20.  
  21. char    *seg_string;
  22. char    *find_string;
  23. #define EXPSIZE 4096
  24. #define INIT register char *sp = find_string; 
  25. #define GETC() (*sp++)
  26. #define PEEKC() (*sp)
  27. #define UNGETC(c) (--sp)
  28. #define RETURN(c) return;
  29. #define ERROR(c) fprintf (stderr, "\7")
  30. #include <regexp.h>
  31.  
  32. /* bits for exclamation point in dialog */
  33. char warningBits[] = {
  34.    0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00,
  35.    0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00,
  36.    0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00,
  37.    0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00,
  38.    0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00,
  39.    0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00,
  40.    0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
  41.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00,
  42.    0x00, 0xe0, 0x07, 0x00, 0x00, 0xf0, 0x0f, 0x00, 0x00, 0xf0, 0x0f, 0x00,
  43.    0x00, 0xf0, 0x0f, 0x00, 0x00, 0xf0, 0x0f, 0x00, 0x00, 0xe0, 0x07, 0x00,
  44.    0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00};
  45.  
  46. /************************************************************************
  47.  *
  48.  *  CreateDefaultImage - create a default image for warning symbol.
  49.  *
  50.  **********************************<->***********************************/
  51. XImage *CreateDefaultImage (bits, width, height)
  52. char *bits;
  53. int   width, height;
  54. {
  55.     XImage *image;
  56.  
  57.     image = (XImage *) XtMalloc (sizeof (XImage));
  58.     image->width = width;
  59.     image->height = height;
  60.     image->data = bits;
  61.     image->depth = 1;
  62.     image->xoffset = 0;
  63.     image->format = XYBitmap;
  64.     image->byte_order = LSBFirst;
  65.     image->bitmap_unit = 8;
  66.     image->bitmap_bit_order = LSBFirst;
  67.     image->bitmap_pad = 8;
  68.     image->bytes_per_line = (width+7)/8;
  69.     return (image);
  70. }
  71.  
  72.  
  73.  
  74. /*-------------------------------------------------------------
  75. **    CreateSpecialWarningDialog
  76. **        Create special 3 button message box out of a
  77. **     Selection box.
  78. */
  79. Widget CreateSpecialWarningDialog (parent, name, image_string, message,
  80.                     arglist, argcount)
  81. Widget        parent;
  82. String        name;
  83. String        image_string;
  84. String        message;
  85. Arg        arglist[];
  86. Cardinal    argcount;
  87. {
  88.     Widget    warning_dialog;    /*  special warning selection box */
  89.     Widget    work_area;    /*  rowcolumn for pixmap and text */
  90.     Widget    pixmap_label;
  91.     Widget    text_label;
  92.     Widget    apply_button;
  93.     Widget    ok_button;
  94.     Widget    kid[5];        /*  buttons        */
  95.     XmFontList    font_list;
  96.     Pixel    foreground;    /*  dialog foreground    */
  97.     Pixel    background;    /*  dialog background    */
  98.     Pixmap    pixmap;        /*  dialog pixmap    */
  99.     register int    i;    /*  kid index        */
  100.     Arg        al[10];
  101.     Cardinal    ac;
  102.  
  103.     warning_dialog = XmCreatePromptDialog(parent, name, arglist, argcount);
  104.  
  105.     /* Create work area for insertion of prompt. */
  106.     ac = 0;
  107.     XtSetArg(al[ac], XmNorientation, XmHORIZONTAL); ac++;
  108.     work_area = XmCreateRowColumn(warning_dialog, "workarea", al, ac);
  109.     XtManageChild(work_area);
  110.  
  111.     ac = 0;
  112.     XtSetArg(al[ac], XmNforeground, &foreground); ac++;
  113.     XtSetArg(al[ac], XmNbackground, &background); ac++;
  114.     XtGetValues(warning_dialog, al, ac);
  115.  
  116.     /* Create and insert prompt. */
  117.     ac = 0;
  118.     XtSetArg(al[ac], XmNlabelType, XmPIXMAP); ac++;
  119.     pixmap = XmGetPixmap(XtScreen(warning_dialog), image_string,
  120.                      foreground, background);
  121.     XtSetArg(al[ac], XmNlabelPixmap, pixmap); ac++;
  122.     pixmap_label = XmCreateLabel(work_area, "pixmap_label", al, ac);
  123.     XtManageChild(pixmap_label);
  124.  
  125.     /* Label for the prompt. */
  126.     ac = 0;
  127.     XtSetArg(al[ac], XmNlabelString,
  128.          XmStringCreateLtoR(message, charset)); ac++;
  129. #ifdef HARDCODE
  130.     XtSetArg (al[ac], XmNfontList, fontlist);  ac++;
  131. #endif
  132.     text_label = XmCreateLabel(work_area, "text_label", al, ac);
  133.     XtManageChild(text_label);
  134.  
  135.     /* Create discard button. */
  136.     ac = 0;
  137.     apply_button = XmSelectionBoxGetChild (warning_dialog,
  138.          XmDIALOG_APPLY_BUTTON);
  139.     XtSetArg(al[ac], XmNlabelString,
  140.          XmStringCreateLtoR("Discard", charset)); ac++;
  141.     XtSetValues(apply_button, al, ac);
  142.     XtManageChild(apply_button);
  143.  
  144.     /* Change label on OK button. */
  145.     ac = 0;
  146.     ok_button = XmSelectionBoxGetChild (warning_dialog,
  147.          XmDIALOG_OK_BUTTON);
  148.     XtSetArg(al[ac], XmNlabelString,
  149.          XmStringCreateLtoR("Save", charset)); ac++;
  150.     XtSetValues(ok_button, al, ac);
  151.  
  152.         
  153.     /*        Unmanage unneeded children.
  154.     */
  155.     i = 0;
  156.     kid[i++] = XmSelectionBoxGetChild (warning_dialog, XmDIALOG_TEXT);
  157.     kid[i++] = XmSelectionBoxGetChild (warning_dialog,
  158.          XmDIALOG_SELECTION_LABEL);
  159.     kid[i++] = XmSelectionBoxGetChild (warning_dialog, XmDIALOG_HELP_BUTTON);
  160.     XtUnmanageChildren (kid, i);
  161.  
  162.     return(warning_dialog);
  163. }
  164.  
  165.  
  166. /*-------------------------------------------------------------
  167. **    strlwr
  168. **        Convert any upper case letters in string
  169. **        to lower case.
  170. */
  171. void strlwr (theString)
  172. char    *theString;
  173. {
  174.     int  i, j;
  175.     
  176.     j = strlen (theString);
  177.     for (i=0; i<j; i++)
  178.         if (theString[i] >= 'A' && theString[i] <= 'Z')
  179.             theString[i] += 'a' - 'A';
  180. }
  181.  
  182.  
  183.  
  184. /*-------------------------------------------------------------
  185. **      ReplaceString
  186. **        The callback for the menu replace function.
  187. */
  188. void ReplaceString()
  189. {
  190.     Arg        al[1];
  191.     char    replaceString[MAXLENGTH];
  192.     char    *aString;
  193.     char    *selString;
  194.     char    *file_string;        /* Contents of file.    */
  195.     XmTextPosition cursorPos;
  196.  
  197.     /* Get the Replace string */
  198.     aString = &replaceString[0];
  199.     XtSetArg (al[0], XmNvalue, &aString);
  200.     XtGetValues (replace_entry, al, 1);
  201.     
  202.     if (selString = XmTextGetSelection(text)) {
  203.         file_string = XmTextGetString(text);
  204.         XtSetArg (al[0], XmNcursorPosition, &cursorPos);
  205.         XtGetValues (text, al, 1);
  206.         if (!strncmp (selString, file_string+cursorPos, strlen(selString))) {
  207.             XmTextReplace (text, cursorPos, cursorPos + strlen(selString), "");
  208.             XmTextReplace (text, cursorPos, cursorPos, aString);
  209.         }
  210.         else {
  211.             XmTextReplace (text, cursorPos, cursorPos, aString);
  212.             XmTextReplace (text, cursorPos - strlen(selString), cursorPos, "");
  213.         }
  214.         XtFree (selString);
  215.         XtFree (file_string);
  216.     }
  217. }
  218.  
  219.  
  220. /*-------------------------------------------------------------
  221. **      FindString
  222. **        The use of regular expressions was contributed by:
  223. **        jec@milne.boeing.com (Jim Campbell)
  224. */
  225. Boolean FindString(thetime)
  226. Time thetime;
  227. {
  228.     char    *file_string;        /* Contents of file.    */
  229.     char    *found;
  230.     char    buffer[30];
  231.     XmTextPosition cursorPos;
  232.     XmTextPosition end_cursorPos;
  233.     Arg        al[1];
  234.     Boolean    ignore_case;
  235.     Boolean    reg_exp;
  236.     char expbuf [EXPSIZE];
  237.  
  238.     if (!the_string) {
  239.         fprintf (stderr, "\7");    /* Beep */
  240.         XmTextClearSelection(text, thetime);
  241.         return (False);
  242.     }
  243.         
  244.     /* get the text string */
  245.     file_string = XmTextGetString(text);
  246.     XtSetArg (al[0], XmNcursorPosition, &cursorPos);
  247.     XtGetValues (text, al, 1);
  248.     seg_string = (char *)((long)file_string + (long)cursorPos);
  249.     find_string = XtMalloc (strlen(the_string) + 1);
  250.     strcpy (find_string, the_string);
  251.     
  252.     XtSetArg (al[0], XmNset, &ignore_case);
  253.     XtGetValues (find_case, al, 1);
  254.     if (ignore_case) {
  255.         strlwr (seg_string);
  256.         strlwr (find_string);
  257.     }
  258.         
  259.     XtSetArg (al[0], XmNset, ®_exp);
  260.     XtGetValues (regular_exp, al, 1);
  261.     if (reg_exp) {
  262.         compile (find_string, expbuf, &expbuf[EXPSIZE], '\0');     
  263.         if (step (seg_string, expbuf)) {
  264.             cursorPos = (XmTextPosition)((long)loc1 + (long)cursorPos - (long)seg_string); 
  265.             end_cursorPos = (XmTextPosition)((long)cursorPos + (long)loc2 - (long)loc1); 
  266.             XmTextSetSelection(text, cursorPos, end_cursorPos, thetime); 
  267.             MoveTo(end_cursorPos);
  268.             XtFree (file_string);
  269.             XtFree (find_string);
  270.             return (True);
  271.         }
  272.         else {
  273.             fprintf (stderr, "\7");    /* Beep */
  274.             XmTextClearSelection(text, thetime);
  275.             XtFree (file_string);
  276.             XtFree (find_string);
  277.             return (False);
  278.         }
  279.     }
  280.     else {
  281.         if ((found = strstr (seg_string, find_string)) != NULL) {
  282.             cursorPos = (XmTextPosition)((long)found + (long)cursorPos - (long)seg_string);
  283.             end_cursorPos = (XmTextPosition)((long)cursorPos + strlen(the_string));
  284.             XmTextSetSelection(text, cursorPos, end_cursorPos, thetime);
  285.             MoveTo(end_cursorPos);
  286.             XtFree (file_string);
  287.             XtFree (find_string);
  288.             return (True);
  289.         }
  290.         else {
  291.             fprintf (stderr, "\7");    /* Beep */
  292.             XmTextClearSelection(text, thetime);
  293.             XtFree (file_string);
  294.             XtFree (find_string);
  295.             return (False);
  296.         }
  297.     }
  298. }
  299.  
  300.  
  301. /*-------------------------------------------------------------
  302. **    FindCB
  303. */
  304. void FindCB (w, client_data, call_data) 
  305. Widget         w;        /*  widget id           */
  306. caddr_t        client_data;    /*  data from application   */
  307. caddr_t        call_data;    /*  data from widget class  */
  308. {
  309.     Arg        al[1];
  310.     Boolean    startAtTop;
  311.  
  312.     XmAnyCallbackStruct *cb = (XmAnyCallbackStruct *) call_data;
  313.     
  314.     XtSetArg (al[0], XmNvalue, &the_string);
  315.     XtGetValues (find_entry, al, 1);
  316.     
  317.     /* Get Start at beginning of file indicator */
  318.     XtSetArg (al[0], XmNset, &startAtTop);
  319.     XtGetValues (start_at_top, al, 1);
  320.     if (startAtTop) {
  321.         MoveTo((XmTextPosition)0);
  322.         XtSetArg (al[0], XmNset, False);
  323.         XtSetValues (start_at_top, al, 1);
  324.     }
  325.     
  326.     FindString (cb->event->xbutton.time);
  327.     XtSetSensitive (findA_button, True);
  328.     XtSetSensitive (replace_button, True);
  329.     XtSetSensitive (replace_pb, True);
  330.     XtSetSensitive (replaceAll_pb, True);
  331. }
  332.  
  333.  
  334. /*-------------------------------------------------------------
  335. **    ReplaceCB
  336. */
  337. void ReplaceCB (w, client_data, call_data) 
  338. Widget         w;        /*  widget id           */
  339. caddr_t        client_data;    /*  data from application   */
  340. caddr_t        call_data;    /*  data from widget class  */
  341. {
  342.     Arg        al[1];
  343.     char    replaceString[MAXLENGTH];
  344.     char    *aString;
  345.     XmTextPosition cursorPos;        /* text cursor position */
  346.     XmTextPosition cursorBack;
  347.     Boolean    startAtTop;
  348.     Time    thetime;
  349.     
  350.     XmAnyCallbackStruct *cb = (XmAnyCallbackStruct *) call_data;
  351.     thetime = cb->event->xbutton.time;
  352.     
  353.     ReplaceString();
  354.     FindString(thetime+2);
  355. }
  356.  
  357. /*-------------------------------------------------------------
  358. **    ReplaceAllCB
  359. */
  360. void ReplaceAllCB (w, client_data, call_data) 
  361. Widget         w;        /*  widget id           */
  362. caddr_t        client_data;    /*  data from application   */
  363. caddr_t        call_data;    /*  data from widget class  */
  364. {
  365.     Arg        al[1];
  366.     char    replaceString[MAXLENGTH];
  367.     char    *aString;
  368.     XmTextPosition cursorPos;        /* text cursor position */
  369.     XmTextPosition cursorBack;
  370.     Boolean    startAtTop;
  371.     Time    thetime;
  372.     
  373.     XmAnyCallbackStruct *cb = (XmAnyCallbackStruct *) call_data;
  374.     thetime = cb->event->xbutton.time;
  375.     
  376.     /* Get the Find string */
  377.     XtSetArg (al[0], XmNvalue, &the_string);
  378.     XtGetValues (find_entry, al, 1);
  379.     cursorBack = strlen (the_string);
  380.     /* Get the Replace string */
  381.     aString = &replaceString[0];
  382.     XtSetArg (al[0], XmNvalue, &aString);
  383.     XtGetValues (replace_entry, al, 1);
  384.     /* Get Start at beginning of file indicator */
  385.     XtSetArg (al[0], XmNset, &startAtTop);
  386.     XtGetValues (start_at_top, al, 1);
  387.     
  388.     XtSetSensitive (findA_button, True);
  389.     if (startAtTop) {
  390.         MoveTo((XmTextPosition)0);
  391.         XtSetArg (al[0], XmNset, False);
  392.         XtSetValues (start_at_top, al, 1);
  393.     }
  394.     
  395.     while (FindString(thetime++)) {
  396.         XtSetArg (al[0], XmNcursorPosition, &cursorPos);
  397.         XtGetValues (text, al, 1);
  398.         XmTextReplace (text, cursorPos-cursorBack, cursorPos, aString);
  399.     }
  400. }
  401.  
  402. /*-------------------------------------------------------------
  403. **    ExitCB
  404. */
  405. void ExitCB (w, client_data, call_data) 
  406. Widget         w;        /*  widget id           */
  407. caddr_t        client_data;    /*  data from application   */
  408. caddr_t        call_data;    /*  data from widget class  */
  409. {
  410.     XtUnmanageChild (Find_dialog);
  411. }
  412.  
  413.  
  414. /*-------------------------------------------------------------
  415. **    FindHelpCB
  416. */
  417. void FindHelpCB (w, client_data, call_data) 
  418. Widget         w;        /*  widget id           */
  419. caddr_t        client_data;    /*  data from application   */
  420. caddr_t        call_data;    /*  data from widget class  */
  421. {
  422.     XtManageChild (find_help_dialog);
  423. }
  424.  
  425.  
  426. /*--------------------------------------------------------------
  427. **    Translation table for the find dialog's text widgets.
  428. */
  429. static char defaultTranslations[] =
  430.     "Meta<Key>X:    CutItem()    \n\
  431.     Meta<Key>C:        CopyItem()    \n\
  432.     Meta<Key>V:        PasteItem()";
  433.  
  434. /*-------------------------------------------------------------
  435. **    CreateSpecialFindDialog
  436. **        Create find & replace message box out of a
  437. **     Dialog Shell.
  438. */
  439. Widget CreateSpecialFindDialog (parent, dialog_name, arglist, argcount)
  440. Widget        parent;
  441. String        dialog_name;
  442. Arg        arglist[];
  443. Cardinal    argcount;
  444. {
  445.     Widget    work_area;
  446.     Widget    help_area;
  447.     Widget    button;
  448.     Widget    separator;
  449.     Widget    label;
  450.     Widget    kid[5];
  451.     int        i;
  452.     Arg        al[15];
  453.     Cardinal    ac;
  454.     XmFontList    font_list;
  455.     Dimension    button_width;
  456.     XtTranslations trans_table;
  457.     
  458.     trans_table = XtParseTranslationTable(defaultTranslations);
  459.     
  460.     Find_dialog = XmCreatePromptDialog(parent, dialog_name, arglist, argcount);
  461.     
  462.     ac = 0;
  463.     XtSetArg(al[ac], XmNtextFontList, &font_list); ac++;
  464.     XtGetValues(Find_dialog, al, ac);
  465.     
  466.     /* Create work area. */
  467.     ac=0;
  468.     work_area = XmCreateRowColumn(Find_dialog, "workarea", al, ac);
  469.     XtManageChild(work_area);
  470.     
  471.     /* Label for the "Find Text". */
  472.     ac = 0;
  473.     XtSetArg(al[ac], XmNmarginWidth, 0); ac++;
  474. #ifdef HARDCODE
  475.     XtSetArg (al[ac], XmNfontList, fontlist);  ac++;
  476. #endif
  477.     label = XmCreateLabel(work_area, "Find Text:", al, ac);
  478.     XtManageChild(label);
  479.  
  480.     /* Create "Find Text" box. */
  481.     ac = 0;
  482.     XtSetArg(al[ac], XmNmaxLength, MAXLENGTH); ac++;
  483. #ifdef HARDCODE
  484.     XtSetArg (al[ac], XmNfontList, fontlist);  ac++;
  485. #endif
  486.     find_entry = XmCreateText(work_area, "find_entry", al, ac);
  487.     XtManageChild(find_entry);
  488.     XtOverrideTranslations (find_entry, trans_table);
  489.  
  490.     /* Label for the "Replace With". */
  491.     ac = 0;
  492.     XtSetArg(al[ac], XmNmarginWidth, 0); ac++;
  493.     XtSetArg(al[ac], XmNalignment, XmALIGNMENT_BEGINNING); ac++;
  494. #ifdef HARDCODE
  495.     XtSetArg (al[ac], XmNfontList, fontlist);  ac++;
  496. #endif
  497.     label = XmCreateLabel(work_area, "Replace With:", al, ac);
  498.     XtManageChild(label);
  499.  
  500.     /* Create "Replace With" box. */
  501.     ac = 0;
  502.     XtSetArg(al[ac], XmNmaxLength, MAXLENGTH); ac++;
  503. #ifdef HARDCODE
  504.     XtSetArg (al[ac], XmNfontList, fontlist);  ac++;
  505. #endif
  506.     replace_entry = XmCreateText(work_area, "replace_entry", al, ac);
  507.     XtManageChild(replace_entry);
  508.     XtOverrideTranslations (replace_entry, trans_table);
  509.  
  510.     /* Create "Ignore Case" button. */
  511.     ac = 0;
  512.     XtSetArg(al[ac], XmNlabelString,
  513.          XmStringCreateLtoR("Ignore text case", charset)); ac++;
  514. #ifdef HARDCODE
  515.     XtSetArg (al[ac], XmNfontList, fontlist);  ac++;
  516. #endif
  517.     find_case = XmCreateToggleButtonGadget(work_area, "find_case", al, ac);
  518.     XtManageChild(find_case);
  519.  
  520.     /* Create "Start at top of file" button. */
  521.     ac = 0;
  522.     XtSetArg(al[ac], XmNlabelString,
  523.          XmStringCreateLtoR("Start at top of file", charset)); ac++;
  524. #ifdef HARDCODE
  525.     XtSetArg (al[ac], XmNfontList, fontlist);  ac++;
  526. #endif
  527.     start_at_top = XmCreateToggleButtonGadget(work_area, "start_at_top", al, ac);
  528.     XtManageChild(start_at_top);
  529.  
  530.     /* Create "Use Regular Expressions" button. */
  531.     ac = 0;
  532.     XtSetArg(al[ac], XmNlabelString,
  533.          XmStringCreateLtoR("Use regular expressions", charset)); ac++;
  534. #ifdef HARDCODE
  535.     XtSetArg (al[ac], XmNfontList, fontlist);  ac++;
  536. #endif
  537.     regular_exp = XmCreateToggleButtonGadget(work_area, "regular_exp", al, ac);
  538.     XtManageChild(regular_exp);
  539.  
  540.     /*** Put a separator and help message below the work area ***/
  541.     ac = 0;
  542.     separator = XmCreateSeparator(work_area, "separator", al, ac);
  543.     XtManageChild(separator);
  544.     
  545.     ac = 0;
  546.     XtSetArg (al[ac], XmNorientation, XmHORIZONTAL);  ac++;
  547.     help_area = XmCreateRowColumn(work_area, "help_area", al, ac);
  548.     XtManageChild(help_area);
  549.     
  550.     ac = 0;
  551.     XtSetArg(al[ac], XmNlabelString,
  552.          XmStringCreateLtoR("Help", charset)); ac++;
  553. #ifdef HARDCODE
  554.     XtSetArg (al[ac], XmNfontList, fontlist);  ac++;
  555. #endif
  556.     button = XmCreatePushButtonGadget(help_area, "Help", al, ac);
  557.     XtManageChild(button);
  558.     
  559.     ac = 0;
  560. #ifdef HARDCODE
  561.     XtSetArg (al[ac], XmNfontList, fontlist);  ac++;
  562. #endif
  563.     label = XmCreateLabelGadget (help_area, 
  564.         "Press HELP for a quick reference to regular expressions.", al, ac);
  565.     XtManageChild (label);
  566.     
  567.     /* Relabel OK button */
  568.     ac = 0;
  569.     XtSetArg(al[ac], XmNokLabelString,
  570.          XmStringCreateLtoR("Find", charset)); ac++;
  571.     XtSetValues(Find_dialog, al, ac);
  572.  
  573.     /* Create Replace button. */
  574.     ac = 0;
  575.     XtSetArg(al[ac], XmNapplyLabelString,
  576.          XmStringCreateLtoR("Replace", charset)); ac++;
  577.     XtSetValues(Find_dialog, al, ac);
  578.     replace_pb = XmSelectionBoxGetChild (Find_dialog, XmDIALOG_APPLY_BUTTON);
  579.     XtManageChild(replace_pb);
  580.     XtSetSensitive(replace_pb, False);
  581.  
  582.     /* Relabel Cancel button */
  583.     ac = 0;
  584.     XtSetArg(al[ac], XmNcancelLabelString,
  585.          XmStringCreateLtoR("Replace All", charset)); ac++;
  586.     XtSetValues(Find_dialog, al, ac);
  587.     replaceAll_pb = XmSelectionBoxGetChild (Find_dialog, XmDIALOG_CANCEL_BUTTON);
  588.     XtSetSensitive(replaceAll_pb, False);
  589.  
  590.     /* Relabel Help button */
  591.     ac = 0;
  592.     XtSetArg(al[ac], XmNhelpLabelString,
  593.          XmStringCreateLtoR("Done", charset)); ac++;
  594.     XtSetValues(Find_dialog, al, ac);
  595.  
  596.     XtAddCallback (button, XmNactivateCallback, FindHelpCB, NULL);
  597.     XtAddCallback (Find_dialog, XmNokCallback, FindCB, NULL);
  598.     XtAddCallback (Find_dialog, XmNapplyCallback, ReplaceCB, NULL);
  599.     XtAddCallback (Find_dialog, XmNcancelCallback, ReplaceAllCB, NULL);
  600.     XtAddCallback (Find_dialog, XmNhelpCallback, ExitCB, NULL); 
  601.     
  602.     /*    Unmanage unneeded children. */
  603.     i = 0;
  604.     kid[i++] = XmSelectionBoxGetChild (Find_dialog, XmDIALOG_TEXT);
  605.     kid[i++] = XmSelectionBoxGetChild (Find_dialog, XmDIALOG_SELECTION_LABEL);
  606.     XtUnmanageChildren (kid, i);
  607.  
  608.     XmAddTabGroup(find_entry);
  609.     XmAddTabGroup(replace_entry);
  610.     XmAddTabGroup(find_case);
  611.     XmAddTabGroup(start_at_top);
  612.     XmAddTabGroup(regular_exp);
  613.     XmAddTabGroup(button);
  614.     XmAddTabGroup(Find_dialog);
  615.     return(Find_dialog);
  616. }
  617.  
  618.         
  619.  
  620. /*-------------------------------------------------------------
  621. **    CreateSpecialHelpDialog
  622. */
  623. Widget CreateSpecialHelpDialog (parent, help_txt, dialog_name, arglist, argcount)
  624. Widget        parent;
  625. Widget        *help_txt;
  626. String        dialog_name;
  627. Arg        arglist[];
  628. Cardinal    argcount;
  629. {
  630.     Widget    the_dialog;
  631.     Widget    text_window;
  632.     Widget    butt_sep;
  633.     Widget    button_area;
  634.     Widget    helpok_button;
  635.     Arg        al[15];
  636.     Cardinal    ac;
  637.     int        file_length;    /* Length of file.        */
  638.     char    *file_string;    /* Contents of file.      */
  639.     int        tfd;        /* Temporary file descriptor */
  640.     struct stat statbuf;    /* Information on a file. */
  641.     XmFontList    font_list;
  642.     
  643.     the_dialog = XmCreateFormDialog(parent, dialog_name, arglist, argcount);
  644.  
  645.     ac = 0;
  646.     XtSetArg(al[ac], XmNtextFontList, &font_list); ac++;
  647.     XtGetValues(the_dialog, al, ac);
  648.  
  649.     ac = 0;
  650.     XtSetArg(al[ac], XmNmarginWidth, 0); ac++;
  651.     XtSetArg(al[ac], XmNmarginHeight, 0); ac++;
  652.     XtSetArg(al[ac], XmNheight, 400); ac++;
  653.     XtSetArg(al[ac], XmNwidth, 400); ac++;
  654.     XtSetArg(al[ac], XmNresizePolicy, XmRESIZE_GROW); ac++;
  655.     XtSetArg(al[ac], XmNdialogTitle,
  656.          XmStringCreateLtoR(dialog_name, charset)); ac++;
  657.     XtSetValues (the_dialog, al, ac);
  658.  
  659.     /* Create Help Ok button. */
  660.     ac = 0;
  661.     XtSetArg(al[ac], XmNbottomOffset, 10); ac++;
  662.     XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
  663.     XtSetArg(al[ac], XmNleftOffset, 15); ac++;
  664.     XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
  665.     XtSetArg(al[ac], XmNshowAsDefault, 1); ac++;
  666. #ifdef HARDCODE
  667.     XtSetArg (al[ac], XmNfontList, fontlist);  ac++;
  668. #endif
  669.     helpok_button = XmCreatePushButtonGadget (the_dialog, "OK",al, ac);
  670.     XtManageChild(helpok_button);
  671.  
  672.     /* Create seperator above button. */
  673.     ac = 0;
  674.     XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
  675.     XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
  676.     XtSetArg(al[ac], XmNbottomWidget, (XtArgVal)helpok_button); ac++;
  677.     XtSetArg(al[ac], XmNbottomOffset, 10); ac++;
  678.     XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_WIDGET); ac++;
  679.     butt_sep = XmCreateSeparator(the_dialog, "butt_sep", al, ac);
  680.     XtManageChild(butt_sep);
  681.  
  682.     /* Create "Help Text" box. */
  683.     ac = 0;
  684.     XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
  685.     XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
  686.     XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
  687.     XtSetArg(al[ac], XmNbottomWidget, (XtArgVal)butt_sep); ac++;
  688.     XtSetArg(al[ac], XmNbottomOffset, 10); ac++;
  689.     XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_WIDGET); ac++;
  690.     XtSetArg(al[ac], XmNeditMode, XmMULTI_LINE_EDIT); ac++;
  691.     XtSetArg(al[ac], XmNeditable, False); ac++;
  692.     XtSetArg(al[ac], XmNscrollHorizontal, False); ac++;
  693.     XtSetArg(al[ac], XmNwordWrap, True); ac++;
  694. #ifdef HARDCODE
  695.     XtSetArg (al[ac], XmNfontList, fontlist);  ac++;
  696. #endif
  697.     *help_txt = XmCreateScrolledText(the_dialog, "help_text", al, ac);
  698.     XtManageChild(*help_txt);
  699.     
  700.     text_window = XtParent (*help_txt);
  701.     ac = 0;
  702.     XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
  703.     XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
  704.     XtSetArg(al[ac], XmNbottomWidget, (XtArgVal)butt_sep); ac++;
  705.     XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_WIDGET); ac++;
  706.     XtSetValues (text_window, al, ac);
  707.     
  708.     return (the_dialog);
  709. }
  710.  
  711.  
  712.