handler.c revision 3653852e
11abf7346Smrg/*
21abf7346Smrg
31abf7346SmrgCopyright (c) 1987, 1988  X Consortium
41abf7346Smrg
51abf7346SmrgPermission is hereby granted, free of charge, to any person obtaining
61abf7346Smrga copy of this software and associated documentation files (the
71abf7346Smrg"Software"), to deal in the Software without restriction, including
81abf7346Smrgwithout limitation the rights to use, copy, modify, merge, publish,
91abf7346Smrgdistribute, sublicense, and/or sell copies of the Software, and to
101abf7346Smrgpermit persons to whom the Software is furnished to do so, subject to
111abf7346Smrgthe following conditions:
121abf7346Smrg
131abf7346SmrgThe above copyright notice and this permission notice shall be included
141abf7346Smrgin all copies or substantial portions of the Software.
151abf7346Smrg
161abf7346SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
171abf7346SmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
181abf7346SmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
191abf7346SmrgIN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
201abf7346SmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
211abf7346SmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
221abf7346SmrgOTHER DEALINGS IN THE SOFTWARE.
231abf7346Smrg
241abf7346SmrgExcept as contained in this notice, the name of the X Consortium shall
251abf7346Smrgnot be used in advertising or otherwise to promote the sale, use or
261abf7346Smrgother dealings in this Software without prior written authorization
271abf7346Smrgfrom the X Consortium.
281abf7346Smrg
291abf7346Smrg*/
301abf7346Smrg
311abf7346Smrg/*
321abf7346Smrg * xman - X window system manual page display program.
331abf7346Smrg * Author:    Chris D. Peterson, MIT Project Athena
341abf7346Smrg * Created:   October 29, 1987
351abf7346Smrg */
3623a8d56dSmrg#ifdef HAVE_CONFIG_H
3723a8d56dSmrg# include "config.h"
3823a8d56dSmrg#endif
391abf7346Smrg
401abf7346Smrg#include <sys/types.h>
411abf7346Smrg#include <sys/stat.h>
421abf7346Smrg#include "globals.h"
431abf7346Smrg#include "vendor.h"
441abf7346Smrg#ifdef INCLUDE_XPRINT_SUPPORT
451abf7346Smrg#include "printdialog.h"
461abf7346Smrg#include "print.h"
471abf7346Smrg#endif /* INCLUDE_XPRINT_SUPPORT */
481abf7346Smrg
4923a8d56dSmrg#ifdef RELEASE_VERSION
5023a8d56dSmrg#define XMAN_VERSION "Xman Version " PACKAGE_VERSION " - X11R" RELEASE_VERSION
5123a8d56dSmrg#else
5223a8d56dSmrg#define XMAN_VERSION "Xman Version " PACKAGE_VERSION
5323a8d56dSmrg#endif
5423a8d56dSmrg
551abf7346Smrgstatic void PutUpManpage(ManpageGlobals * man_globals, FILE * file);
561abf7346Smrgstatic void ToggleBothShownState(ManpageGlobals * man_globals);
571abf7346Smrg
581abf7346Smrg/*	Function Name: OptionCallback
591abf7346Smrg *	Description: This is the callback function for the callback menu.
6036ffeb23Smrg *	Arguments: w - the widget we are calling back from.
6136ffeb23Smrg *                 globals_pointer - a pointer to the pseudo globals structure
621abf7346Smrg *                                  for this manpage.
631abf7346Smrg *                 junk - (call data) not used.
641abf7346Smrg *	Returns: none.
651abf7346Smrg */
661abf7346Smrg
671abf7346Smrg/*ARGSUSED*/
681abf7346Smrgvoid
691abf7346SmrgOptionCallback(Widget w, XtPointer pointer, XtPointer junk)
701abf7346Smrg{
7136ffeb23Smrg    ManpageGlobals *man_globals = (ManpageGlobals *) pointer;
7236ffeb23Smrg    String params;
7336ffeb23Smrg    Cardinal num_params = 1;
7436ffeb23Smrg
7536ffeb23Smrg    if (w == man_globals->search_entry)
7636ffeb23Smrg        PopupSearch(XtParent(w), NULL, NULL, NULL);
7736ffeb23Smrg    else if (w == man_globals->dir_entry) {     /* Put Up Directory */
7836ffeb23Smrg        params = "Directory";
7936ffeb23Smrg        GotoPage(XtParent(w), NULL, &params, &num_params);
8036ffeb23Smrg    }
8136ffeb23Smrg    else if (w == man_globals->manpage_entry) { /* Put Up Man Page */
8236ffeb23Smrg        params = "ManualPage";
8336ffeb23Smrg        GotoPage(XtParent(w), NULL, &params, &num_params);
8436ffeb23Smrg    }
8536ffeb23Smrg    else if (w == man_globals->help_entry)      /* Help */
8636ffeb23Smrg        PopupHelp(XtParent(w), NULL, NULL, NULL);
8736ffeb23Smrg    else if (w == man_globals->both_screens_entry)      /*Toggle Both_Shown State. */
8836ffeb23Smrg        ToggleBothShownState(man_globals);
8936ffeb23Smrg    else if (w == man_globals->remove_entry)    /* Kill the manpage */
9036ffeb23Smrg        RemoveThisManpage(XtParent(w), NULL, NULL, NULL);
9136ffeb23Smrg    else if (w == man_globals->open_entry)      /* Open new manpage */
9236ffeb23Smrg        CreateNewManpage(XtParent(w), NULL, NULL, NULL);
931abf7346Smrg#ifdef INCLUDE_XPRINT_SUPPORT
9436ffeb23Smrg    else if (w == man_globals->print_entry)     /* Print current manpage */
9536ffeb23Smrg        PrintThisManpage(XtParent(w), NULL, NULL, NULL);
9636ffeb23Smrg#endif                          /* INCLUDE_XPRINT_SUPPORT */
9736ffeb23Smrg    else if (w == man_globals->version_entry)   /* Get version */
9836ffeb23Smrg        ShowVersion(XtParent(w), NULL, NULL, NULL);
9936ffeb23Smrg    else if (w == man_globals->quit_entry)      /* Quit. */
10036ffeb23Smrg        Quit(XtParent(w), NULL, NULL, NULL);
1011abf7346Smrg}
1021abf7346Smrg
1031abf7346Smrg/*      Function Name: ToggleBothShownState;
1041abf7346Smrg *      Description: toggles the state of the both shown feature.
1051abf7346Smrg *      Arguments: man_globals - the man globals structure.
1061abf7346Smrg *      Returns: none.
1071abf7346Smrg */
1081abf7346Smrg
1091abf7346Smrg/*
1101abf7346Smrg * I did not have a two state widget, which is the way this
1111abf7346Smrg * should really be done.  1/22/88 - CDP.
1121abf7346Smrg */
1131abf7346Smrg
1141abf7346Smrgstatic void
1151abf7346SmrgToggleBothShownState(ManpageGlobals * man_globals)
1161abf7346Smrg{
11736ffeb23Smrg    const char *label_str;
11836ffeb23Smrg    Arg arglist[1];
11936ffeb23Smrg
12036ffeb23Smrg    if (man_globals->both_shown == TRUE) {
12136ffeb23Smrg        label_str = SHOW_BOTH;
12236ffeb23Smrg        if (man_globals->dir_shown)
12336ffeb23Smrg            XtUnmanageChild(man_globals->manpagewidgets.manpage);
12436ffeb23Smrg        else
12536ffeb23Smrg            XtUnmanageChild(man_globals->manpagewidgets.directory);
12636ffeb23Smrg    }
12736ffeb23Smrg    else {
12836ffeb23Smrg        Widget manpage = man_globals->manpagewidgets.manpage;
12936ffeb23Smrg        Widget dir = man_globals->manpagewidgets.directory;
13036ffeb23Smrg
13136ffeb23Smrg        label_str = SHOW_ONE;
13236ffeb23Smrg
13336ffeb23Smrg        XtSetArg(arglist[0], XtNpreferredPaneSize, resources.directory_height);
13436ffeb23Smrg        XtSetValues(dir, arglist, (Cardinal) 1);
13536ffeb23Smrg
13636ffeb23Smrg        if (!man_globals->dir_shown) {
13736ffeb23Smrg            XtUnmanageChild(manpage);
13836ffeb23Smrg            XtManageChild(dir);
13936ffeb23Smrg        }
14036ffeb23Smrg        XtManageChild(manpage);
14136ffeb23Smrg    }
14236ffeb23Smrg    man_globals->both_shown = !man_globals->both_shown;
1431abf7346Smrg
1441abf7346Smrg    if (man_globals->dir_shown)
14536ffeb23Smrg        ChangeLabel(man_globals->label,
14636ffeb23Smrg                    man_globals->section_name[man_globals->current_directory]);
1471abf7346Smrg    else
14836ffeb23Smrg        ChangeLabel(man_globals->label, man_globals->manpage_title);
14936ffeb23Smrg
15036ffeb23Smrg    XtSetArg(arglist[0], XtNlabel, label_str);
15136ffeb23Smrg    XtSetValues(man_globals->both_screens_entry, arglist, ONE);
15236ffeb23Smrg
15336ffeb23Smrg    /* if both are shown there is no need to switch between the two. */
15436ffeb23Smrg
15536ffeb23Smrg    XtSetArg(arglist[0], XtNsensitive, !man_globals->both_shown);
15636ffeb23Smrg    XtSetValues(man_globals->manpage_entry, arglist, ONE);
15736ffeb23Smrg    XtSetValues(man_globals->dir_entry, arglist, ONE);
1581abf7346Smrg}
1591abf7346Smrg
1601abf7346Smrg/*	Function Name: Popup
1611abf7346Smrg *	Description: This function pops up the given widget under the cursor.
1621abf7346Smrg *	Arguments: w - the widget to popup.
1631abf7346Smrg *                 grab_kind - the kind of grab to register.
1641abf7346Smrg *	Returns: none
1651abf7346Smrg */
1661abf7346Smrg
16736ffeb23Smrg/* How far off the top of the widget to have the initial cursor position. */
1681abf7346Smrg
1691abf7346Smrg#define OFF_OF_TOP 25
1701abf7346Smrg
1711abf7346Smrgvoid
1721abf7346SmrgPopup(Widget w, XtGrabKind grab_kind)
1731abf7346Smrg{
17436ffeb23Smrg    int x_root, y_root, y_pos, garbage;
17536ffeb23Smrg    unsigned int mask;
17636ffeb23Smrg    Window junk_window;
1771abf7346Smrg
17836ffeb23Smrg    XQueryPointer(XtDisplay(w), XtWindow(w), &junk_window, &junk_window,
17936ffeb23Smrg                  &x_root, &y_root, &garbage, &garbage, &mask);
1801abf7346Smrg
18136ffeb23Smrg    y_pos = OFF_OF_TOP - Height(w) / 2 - BorderWidth(w);
18236ffeb23Smrg    PositionCenter(w, x_root, y_root, y_pos, 0, 2, 2);
18336ffeb23Smrg    XtPopup(w, grab_kind);
1841abf7346Smrg}
1851abf7346Smrg
1861abf7346Smrg/*	Function Name: PutUpManpage
1871abf7346Smrg *	Description: Puts the manpage on the display.
18836ffeb23Smrg *	Arguments: man_globals - a pointer to the pseudo globals structure
1891abf7346Smrg *                                  for this manpage.
1901abf7346Smrg *                 file - the file to display.
1911abf7346Smrg *	Returns: none.
1921abf7346Smrg */
1931abf7346Smrg
1941abf7346Smrgstatic void
1951abf7346SmrgPutUpManpage(ManpageGlobals * man_globals, FILE * file)
1961abf7346Smrg{
19736ffeb23Smrg    String params = "ManualPage";
19836ffeb23Smrg    Cardinal num_params = 1;
1991abf7346Smrg
20036ffeb23Smrg    if (file == NULL)
20136ffeb23Smrg        return;
2021abf7346Smrg
20336ffeb23Smrg    OpenFile(man_globals, file);
20436ffeb23Smrg
20536ffeb23Smrg    if (!man_globals->both_shown) {
20636ffeb23Smrg        Arg arglist[1];
20736ffeb23Smrg
20836ffeb23Smrg        XtSetArg(arglist[0], XtNsensitive, TRUE);
20936ffeb23Smrg        XtSetValues(man_globals->manpage_entry, arglist, ONE);
21036ffeb23Smrg        XtSetValues(man_globals->both_screens_entry, arglist, ONE);
21136ffeb23Smrg    }
21236ffeb23Smrg    GotoPage(man_globals->manpagewidgets.manpage, NULL, &params, &num_params);
2131abf7346Smrg}
2141abf7346Smrg
2151abf7346Smrg/*	Function Name: DirectoryHandler
2161abf7346Smrg *	Description: This is the callback function for the directory listings.
21736ffeb23Smrg *	Arguments: w - the widget we are calling back from.
21836ffeb23Smrg *                 global_pointer - the pointer to the pseudo global structure
2191abf7346Smrg *                                  associated with this manpage.
2201abf7346Smrg *                 ret_val - return value from the list widget.
2211abf7346Smrg *	Returns: none.
2221abf7346Smrg */
2231abf7346Smrg
2241abf7346Smrgvoid
2251abf7346SmrgDirectoryHandler(Widget w, XtPointer global_pointer, XtPointer ret_val)
2261abf7346Smrg{
22736ffeb23Smrg    FILE *file;                 /* The manpage file. */
22836ffeb23Smrg    ManpageGlobals *man_globals = (ManpageGlobals *) global_pointer;
22936ffeb23Smrg    XawListReturnStruct *ret_struct = (XawListReturnStruct *) ret_val;
23036ffeb23Smrg
23136ffeb23Smrg    file = FindManualFile(man_globals, man_globals->current_directory,
23236ffeb23Smrg                          ret_struct->list_index);
23336ffeb23Smrg    PutUpManpage(man_globals, file);
23436ffeb23Smrg    if ((file != NULL) && (file != man_globals->curr_file)) {
23536ffeb23Smrg        fclose(file);
23636ffeb23Smrg    }
2371abf7346Smrg}
2381abf7346Smrg
2391abf7346Smrg/*	Function Name: DirPopupCallback
2401abf7346Smrg *	Description: This is the callback function for the callback menu.
24136ffeb23Smrg *	Arguments: w - the widget we are calling back from.
24236ffeb23Smrg *                 pointer - a pointer to the pseudo globals structure
2431abf7346Smrg *                                  for this manpage.
2441abf7346Smrg *                 junk - (call data) not used.
2451abf7346Smrg *	Returns: none.
2461abf7346Smrg */
2471abf7346Smrg
2481abf7346Smrg/*ARGSUSED*/
2491abf7346Smrgvoid
2501abf7346SmrgDirPopupCallback(Widget w, XtPointer pointer, XtPointer junk)
2511abf7346Smrg{
25236ffeb23Smrg    ManpageGlobals *man_globals;
25336ffeb23Smrg    MenuStruct *menu_struct;
25436ffeb23Smrg    Widget parent;
25536ffeb23Smrg    int number;
25636ffeb23Smrg    int current_box;
25736ffeb23Smrg
25836ffeb23Smrg    menu_struct = (MenuStruct *) pointer;
25936ffeb23Smrg    man_globals = (ManpageGlobals *) menu_struct->data;
26036ffeb23Smrg
26136ffeb23Smrg    number = menu_struct->number;
26236ffeb23Smrg    current_box = man_globals->current_directory;
26336ffeb23Smrg
26436ffeb23Smrg    /* We have used this guy, pop down the menu. */
26536ffeb23Smrg
26636ffeb23Smrg    if (number != current_box) {
26736ffeb23Smrg        /* This is the only one that we know has a parent. */
26836ffeb23Smrg        parent = XtParent(man_globals->manpagewidgets.box[INITIAL_DIR]);
26936ffeb23Smrg
27036ffeb23Smrg        MakeDirectoryBox(man_globals, parent,
27136ffeb23Smrg                         man_globals->manpagewidgets.box + number, number);
27236ffeb23Smrg        XtUnmanageChild(man_globals->manpagewidgets.box[current_box]);
27336ffeb23Smrg        XtManageChild(man_globals->manpagewidgets.box[number]);
27436ffeb23Smrg
27536ffeb23Smrg        XawListUnhighlight(man_globals->manpagewidgets.box[current_box]);
27636ffeb23Smrg        ChangeLabel(man_globals->label, man_globals->section_name[number]);
27736ffeb23Smrg        man_globals->current_directory = number;
27836ffeb23Smrg    }
27936ffeb23Smrg
28036ffeb23Smrg    /* put up directory. */
28136ffeb23Smrg    if (!man_globals->both_shown) {
28236ffeb23Smrg        XtUnmanageChild(man_globals->manpagewidgets.manpage);
28336ffeb23Smrg        XtManageChild(man_globals->manpagewidgets.directory);
28436ffeb23Smrg    }
2851abf7346Smrg}
28636ffeb23Smrg
2871abf7346Smrg/************************************************************
2881abf7346Smrg *
2891abf7346Smrg * Action Routines.
2901abf7346Smrg *
2911abf7346Smrg ************************************************************/
2921abf7346Smrg
2931abf7346Smrg/*	Function Name: SaveFormattedPage
2941abf7346Smrg *	Description: This is the action routine may save the manpage.
2951abf7346Smrg *      Arguments: w - any widget in the widget tree.
2961abf7346Smrg *                 event - NOT USED.
29736ffeb23Smrg *                 params, num_params - the parameters passed to the action
2981abf7346Smrg *                                      routine, can be either Manpage or
2991abf7346Smrg *                                      Directory.
3001abf7346Smrg *      Returns: none.
3011abf7346Smrg */
3021abf7346Smrg
3031abf7346Smrg/*ARGSUSED*/
3041abf7346Smrgvoid
30536ffeb23SmrgSaveFormattedPage(Widget w, XEvent * event, String * params,
30636ffeb23Smrg                  Cardinal * num_params)
3071abf7346Smrg{
30836ffeb23Smrg    ManpageGlobals *man_globals;
30936ffeb23Smrg    char cmdbuf[BUFSIZ], error_buf[BUFSIZ];
3101abf7346Smrg
31136ffeb23Smrg    if (*num_params != 1) {
31236ffeb23Smrg        XtAppWarning(XtWidgetToApplicationContext(w),
31336ffeb23Smrg                     "Xman - SaveFormattedPage: This action routine requires one argument.");
31436ffeb23Smrg        return;
31536ffeb23Smrg    }
3161abf7346Smrg
31736ffeb23Smrg    man_globals = GetGlobals(w);
3181abf7346Smrg
3191abf7346Smrg/*
3201abf7346Smrg * If we are not active then take no action.
3211abf7346Smrg */
3221abf7346Smrg
3233653852eSmrg    if (man_globals->tempfile == NULL || man_globals->tempfile[0] == '\0')
32436ffeb23Smrg        return;
32536ffeb23Smrg
32636ffeb23Smrg    switch (params[0][0]) {
32736ffeb23Smrg    case 'S':
32836ffeb23Smrg    case 's':
3291abf7346Smrg
3301abf7346Smrg#ifndef NO_COMPRESS
33136ffeb23Smrg        if (!man_globals->compress)
3321abf7346Smrg#endif
3331abf7346Smrg
33436ffeb23Smrg            snprintf(cmdbuf, sizeof(cmdbuf), "%s %s %s", COPY,
33536ffeb23Smrg                     man_globals->tempfile, man_globals->save_file);
3361abf7346Smrg
3371abf7346Smrg#ifndef NO_COMPRESS
33836ffeb23Smrg        else if (man_globals->gzip)
33936ffeb23Smrg            snprintf(cmdbuf, sizeof(cmdbuf), "%s < %s > %s", GZIP_COMPRESS,
34036ffeb23Smrg                     man_globals->tempfile, man_globals->save_file);
34136ffeb23Smrg        else
34236ffeb23Smrg            snprintf(cmdbuf, sizeof(cmdbuf), "%s < %s > %s", COMPRESS,
34336ffeb23Smrg                     man_globals->tempfile, man_globals->save_file);
3441abf7346Smrg#endif
3451abf7346Smrg
34636ffeb23Smrg        if (!system(cmdbuf)) {
34736ffeb23Smrg            /* make sure the formatted man page is fully accessible by the world */
34836ffeb23Smrg            if (chmod(man_globals->save_file, CHMOD_MODE) != 0) {
34936ffeb23Smrg                snprintf(error_buf, sizeof(error_buf),
35036ffeb23Smrg                         "Couldn't set permissions on formatted man page '%s'.\n",
35136ffeb23Smrg                         man_globals->save_file);
35236ffeb23Smrg                PopupWarning(man_globals, error_buf);
35336ffeb23Smrg            }
35436ffeb23Smrg        }
35536ffeb23Smrg        else {
35636ffeb23Smrg            snprintf(error_buf, sizeof(error_buf),
35736ffeb23Smrg                     "Error while executing the command '%s'.\n", cmdbuf);
35836ffeb23Smrg            PopupWarning(man_globals, error_buf);
35936ffeb23Smrg        }
36036ffeb23Smrg        break;
36136ffeb23Smrg    case 'C':
36236ffeb23Smrg    case 'c':
36336ffeb23Smrg        break;
36436ffeb23Smrg    default:
36536ffeb23Smrg        PopupWarning(man_globals, "Xman - SaveFormattedPage: "
36636ffeb23Smrg                     "Unknown argument must be either 'Save' or 'Cancel'.");
36736ffeb23Smrg        return;
3681abf7346Smrg    }
36936ffeb23Smrg
3701abf7346Smrg/*
3711abf7346Smrg * We do not need the filename anymore, and have the fd open.
37236ffeb23Smrg * We will remove it.
3731abf7346Smrg */
3741abf7346Smrg
37536ffeb23Smrg    remove(man_globals->tempfile);
37636ffeb23Smrg    XtPopdown(XtParent(XtParent(w)));
3771abf7346Smrg}
3781abf7346Smrg
3791abf7346Smrg/*      Function Name: GotoPage
3801abf7346Smrg *      Description: The Action routine that switches over to the manpage
3811abf7346Smrg *                   or directory.
3821abf7346Smrg *      Arguments: w - any widget in the widget tree.
3831abf7346Smrg *                 event - NOT USED.
38436ffeb23Smrg *                 params, num_params - the parameters passed to the action
3851abf7346Smrg *                                      routine, can be either Manpage or
3861abf7346Smrg *                                      Directory.
3871abf7346Smrg *      Returns: none.
3881abf7346Smrg */
3891abf7346Smrg
3901abf7346Smrg/*ARGSUSED*/
3911abf7346Smrgvoid
3921abf7346SmrgGotoPage(Widget w, XEvent * event, String * params, Cardinal * num_params)
3931abf7346Smrg{
39436ffeb23Smrg    ManpageGlobals *man_globals;
39536ffeb23Smrg    Arg arglist[1];
39636ffeb23Smrg    Boolean sensitive;
39736ffeb23Smrg
39836ffeb23Smrg    if (*num_params != 1) {
39936ffeb23Smrg        XtAppWarning(XtWidgetToApplicationContext(w),
40036ffeb23Smrg                     "Xman - GotoPage: This action routine requires one argument.");
40136ffeb23Smrg        return;
40236ffeb23Smrg    }
40336ffeb23Smrg
40436ffeb23Smrg    man_globals = GetGlobals(w);
40536ffeb23Smrg
40636ffeb23Smrg    if (man_globals->both_shown) {
40736ffeb23Smrg        ChangeLabel(man_globals->label,
40836ffeb23Smrg                    man_globals->section_name[man_globals->current_directory]);
40936ffeb23Smrg        return;
41036ffeb23Smrg    }
41136ffeb23Smrg
41236ffeb23Smrg    switch (params[0][0]) {
41336ffeb23Smrg    case 'M':
41436ffeb23Smrg    case 'm':
41536ffeb23Smrg        XtSetArg(arglist[0], XtNsensitive, &sensitive);
41636ffeb23Smrg        XtGetValues(man_globals->manpage_entry, arglist, ONE);
41736ffeb23Smrg        if (sensitive) {
41836ffeb23Smrg            ChangeLabel(man_globals->label, man_globals->manpage_title);
41936ffeb23Smrg            XtUnmanageChild(man_globals->manpagewidgets.directory);
42036ffeb23Smrg            XtManageChild(man_globals->manpagewidgets.manpage);
42136ffeb23Smrg            man_globals->dir_shown = FALSE;
42236ffeb23Smrg        }
42336ffeb23Smrg        break;
42436ffeb23Smrg    case 'D':
42536ffeb23Smrg    case 'd':
42636ffeb23Smrg        ChangeLabel(man_globals->label,
42736ffeb23Smrg                    man_globals->section_name[man_globals->current_directory]);
42836ffeb23Smrg        XtUnmanageChild(man_globals->manpagewidgets.manpage);
42936ffeb23Smrg        XtManageChild(man_globals->manpagewidgets.directory);
43036ffeb23Smrg        man_globals->dir_shown = TRUE;
43136ffeb23Smrg        break;
43236ffeb23Smrg    default:
43336ffeb23Smrg        XtAppWarning(XtWidgetToApplicationContext(w),
43436ffeb23Smrg                     "Xman - GotoPage: Unknown argument must be "
43536ffeb23Smrg                     "either Manpage or Directory.");
43636ffeb23Smrg        return;
4371abf7346Smrg    }
4381abf7346Smrg}
4391abf7346Smrg
4401abf7346Smrg/*      Function Name: Quit.
4411abf7346Smrg *      Description: Quits Xman.
4421abf7346Smrg *      Arguments: w - any widget.
4431abf7346Smrg *                 event - NOT USED.
4441abf7346Smrg *                 params, num_params - NOT USED.
4451abf7346Smrg *      Returns: none.
4461abf7346Smrg */
4471abf7346Smrg
4481abf7346Smrg/*ARGSUSED*/
44936ffeb23Smrgvoid
4501abf7346SmrgQuit(Widget w, XEvent * event, String * params, Cardinal * num_params)
4511abf7346Smrg{
45236ffeb23Smrg    XtAppSetExitFlag(XtWidgetToApplicationContext(w));
4531abf7346Smrg}
4541abf7346Smrg
4551abf7346Smrg/*      Function Name: PopupHelp
4561abf7346Smrg *      Description: Pops up xman's help.
4571abf7346Smrg *      Arguments: w - NOT USED.
4581abf7346Smrg *                 event - NOT USED.
4591abf7346Smrg *                 params, num_params - NOT USED.
4601abf7346Smrg *      Returns: none.
4611abf7346Smrg */
4621abf7346Smrg
4631abf7346Smrg/*ARGSUSED*/
46436ffeb23Smrgvoid
4651abf7346SmrgPopupHelp(Widget w, XEvent * event, String * params, Cardinal * num_params)
4661abf7346Smrg{
46736ffeb23Smrg    if (MakeHelpWidget())
46836ffeb23Smrg        XtPopup(help_widget, XtGrabNone);
4691abf7346Smrg}
4701abf7346Smrg
4711abf7346Smrg/*      Function Name: PopupSearch
4721abf7346Smrg *      Description: Pops up this manual pages search widget.
4731abf7346Smrg *      Arguments: w - any widget in this manpage.
4741abf7346Smrg *                 event - NOT USED.
4751abf7346Smrg *                 params, num_params - NOT USED.
4761abf7346Smrg *      Returns: none.
4771abf7346Smrg */
4781abf7346Smrg
4791abf7346Smrg/*ARGSUSED*/
48036ffeb23Smrgvoid
4811abf7346SmrgPopupSearch(Widget w, XEvent * event, String * params, Cardinal * num_params)
4821abf7346Smrg{
48336ffeb23Smrg    ManpageGlobals *man_globals = GetGlobals(w);
48436ffeb23Smrg
48536ffeb23Smrg    if (man_globals->search_widget) {
48636ffeb23Smrg        if (!XtIsRealized(man_globals->search_widget)) {
48736ffeb23Smrg            XtRealizeWidget(man_globals->search_widget);
48836ffeb23Smrg            AddCursor(man_globals->search_widget,
48936ffeb23Smrg                      resources.cursors.search_entry);
49036ffeb23Smrg        }
49136ffeb23Smrg        Popup(man_globals->search_widget, XtGrabNone);
4921abf7346Smrg    }
4931abf7346Smrg}
4941abf7346Smrg
4951abf7346Smrg/*      Function Name: CreateNewManpage
4961abf7346Smrg *      Description: Creates A New Manual Page.
4971abf7346Smrg *      Arguments: w - NOT USED.
4981abf7346Smrg *                 event - NOT USED.
4991abf7346Smrg *                 params, num_params - NOT USED.
5001abf7346Smrg *      Returns: none.
5011abf7346Smrg */
5021abf7346Smrg
5031abf7346Smrg/*ARGSUSED*/
50436ffeb23Smrgvoid
50536ffeb23SmrgCreateNewManpage(Widget w, XEvent * event, String * params,
50636ffeb23Smrg                 Cardinal * num_params)
5071abf7346Smrg{
50836ffeb23Smrg    if (CreateManpage(NULL))
50936ffeb23Smrg        man_pages_shown++;
5101abf7346Smrg}
5111abf7346Smrg
5121abf7346Smrg/*      Function Name: RemoveThisManpage
5131abf7346Smrg *      Description: Removes a manual page.
5141abf7346Smrg *      Arguments: w - any widget in the manpage.
5151abf7346Smrg *                 event - NOT USED.
5161abf7346Smrg *                 params, num_params - NOT USED.
5171abf7346Smrg *      Returns: none.
5181abf7346Smrg */
5191abf7346Smrg
5201abf7346Smrg/*ARGSUSED*/
52136ffeb23Smrgvoid
52236ffeb23SmrgRemoveThisManpage(Widget w, XEvent * event, String * params,
52336ffeb23Smrg                  Cardinal * num_params)
5241abf7346Smrg{
52536ffeb23Smrg    ManpageGlobals *man_globals = GetGlobals(w);
52636ffeb23Smrg
52736ffeb23Smrg    if (man_globals->This_Manpage != help_widget) {
52836ffeb23Smrg        RemoveGlobals(man_globals->This_Manpage);
52936ffeb23Smrg        XtDestroyWidget(man_globals->This_Manpage);
53036ffeb23Smrg
53136ffeb23Smrg        XtFree((char *) man_globals->section_name);
53236ffeb23Smrg        XtFree((char *) man_globals->manpagewidgets.box);
53336ffeb23Smrg        XtFree((char *) man_globals);
53436ffeb23Smrg
53536ffeb23Smrg        if ((--man_pages_shown) == 0)
53636ffeb23Smrg            Quit(w, NULL, NULL, NULL);
53736ffeb23Smrg    }
53836ffeb23Smrg    else
53936ffeb23Smrg        XtPopdown(help_widget);
5401abf7346Smrg}
5411abf7346Smrg
5421abf7346Smrg/*      Function Name: Search
5431abf7346Smrg *      Description: Actually performs a search.
5441abf7346Smrg *      Arguments: w - any widget in the manpage.
5451abf7346Smrg *                 event - NOT USED.
5461abf7346Smrg *                 params, num_params - NOT USED.
5471abf7346Smrg *      Returns: none.
5481abf7346Smrg */
5491abf7346Smrg
5501abf7346Smrg/*ARGSUSED*/
55136ffeb23Smrgvoid
5521abf7346SmrgSearch(Widget w, XEvent * event, String * params, Cardinal * num_params)
5531abf7346Smrg{
55436ffeb23Smrg    ManpageGlobals *man_globals = GetGlobals(w);
55536ffeb23Smrg    FILE *file = NULL;
55636ffeb23Smrg
55736ffeb23Smrg    XtPopdown(XtParent(XtParent(w)));   /* popdown the search widget */
55836ffeb23Smrg
55936ffeb23Smrg    if ((*num_params < 1) || (*num_params > 2)) {
56036ffeb23Smrg        XtAppWarning(XtWidgetToApplicationContext(w),
56136ffeb23Smrg                     "Xman - Search: This action routine requires one or two arguments.");
56236ffeb23Smrg        return;
56336ffeb23Smrg    }
56436ffeb23Smrg
56536ffeb23Smrg    switch (params[0][0]) {
56636ffeb23Smrg    case 'a':
56736ffeb23Smrg    case 'A':
56836ffeb23Smrg        file = DoSearch(man_globals, APROPOS);
56936ffeb23Smrg        break;
57036ffeb23Smrg    case 'm':
57136ffeb23Smrg    case 'M':
57236ffeb23Smrg        file = DoSearch(man_globals, MANUAL);
57336ffeb23Smrg        break;
57436ffeb23Smrg    case 'c':
57536ffeb23Smrg    case 'C':
57636ffeb23Smrg        file = NULL;
57736ffeb23Smrg        break;
5781abf7346Smrg    default:
57936ffeb23Smrg        XtAppWarning(XtWidgetToApplicationContext(w),
58036ffeb23Smrg                     "Xman - Search: First parameter unknown.");
58136ffeb23Smrg        file = NULL;
58236ffeb23Smrg        break;
58336ffeb23Smrg    }
58436ffeb23Smrg
58536ffeb23Smrg    if (*num_params == 2)
58636ffeb23Smrg        switch (params[1][0]) {
58736ffeb23Smrg        case 'O':
58836ffeb23Smrg        case 'o':
58936ffeb23Smrg            if (file != NULL) {
5903653852eSmrg                Widget w2;
59136ffeb23Smrg                char *label;
59236ffeb23Smrg
5933653852eSmrg                w2 = CreateManpage(file);
5943653852eSmrg                if (w2) {
59536ffeb23Smrg                    man_pages_shown++;
59636ffeb23Smrg
59736ffeb23Smrg                    /* Put title into new manual page. */
59836ffeb23Smrg
59936ffeb23Smrg                    label = man_globals->manpage_title;
6003653852eSmrg                    man_globals = GetGlobals(w2);
60136ffeb23Smrg                    strcpy(man_globals->manpage_title, label);
60236ffeb23Smrg                    ChangeLabel(man_globals->label, label);
60336ffeb23Smrg                }
60436ffeb23Smrg            }
60536ffeb23Smrg            break;
60636ffeb23Smrg        default:
60736ffeb23Smrg            XtAppWarning(XtWidgetToApplicationContext(w),
60836ffeb23Smrg                         "Xman - Search: Second parameter unknown.");
60936ffeb23Smrg            break;
61036ffeb23Smrg        }
61136ffeb23Smrg    else {
61236ffeb23Smrg        PutUpManpage(man_globals, file);
61336ffeb23Smrg    }
61436ffeb23Smrg    if ((file != NULL) && (file != man_globals->curr_file)) {
61536ffeb23Smrg        fclose(file);
6161abf7346Smrg    }
6171abf7346Smrg}
6181abf7346Smrg
6191abf7346Smrg#ifdef INCLUDE_XPRINT_SUPPORT
6201abf7346Smrgstatic void
6211abf7346SmrgprintshellDestroyXtProc(Widget w, XtPointer client_data, XtPointer callData)
6221abf7346Smrg{
62336ffeb23Smrg    ManpageGlobals *mg = GetGlobals(w);
62436ffeb23Smrg
62536ffeb23Smrg    XawPrintDialogClosePrinterConnection(mg->printdialog, False);
6261abf7346Smrg}
6271abf7346Smrg
6281abf7346Smrgstatic void
6291abf7346SmrgprintOKXtProc(Widget w, XtPointer client_data, XtPointer callData)
6301abf7346Smrg{
63136ffeb23Smrg    XawPrintDialogCallbackStruct *pdcs =
63236ffeb23Smrg        (XawPrintDialogCallbackStruct *) callData;
63336ffeb23Smrg    Cardinal n;
63436ffeb23Smrg    Arg args[2];
63536ffeb23Smrg    ManpageGlobals *mg = GetGlobals(w);
63636ffeb23Smrg    Widget topwindow = mg->This_Manpage;
63736ffeb23Smrg    FILE *file;
63836ffeb23Smrg
63936ffeb23Smrg    Log(("printOKXtProc: OK.\n"));
64036ffeb23Smrg
64136ffeb23Smrg    /* Get file object */
64236ffeb23Smrg    n = 0;
64336ffeb23Smrg    XtSetArg(args[n], XtNfile, &file);
64436ffeb23Smrg    n++;
64536ffeb23Smrg    XtGetValues(mg->manpagewidgets.manpage, args, n);
64636ffeb23Smrg    Assertion(file != NULL, (("printOKXtProc: file == NULL.\n")));
64736ffeb23Smrg
64836ffeb23Smrg    DoPrintManpage("Xman",
64936ffeb23Smrg                   file, topwindow,
65036ffeb23Smrg                   pdcs->pdpy, pdcs->pcontext, pdcs->colorspace,
65136ffeb23Smrg                   printshellDestroyXtProc,
65236ffeb23Smrg                   mg->manpage_title,
65336ffeb23Smrg                   pdcs->printToFile ? pdcs->printToFileName : NULL);
65436ffeb23Smrg
65536ffeb23Smrg    XtPopdown(mg->printdialog_shell);
6561abf7346Smrg}
6571abf7346Smrg
6581abf7346Smrgstatic void
6591abf7346SmrgprintCancelXtProc(Widget w, XtPointer client_data, XtPointer callData)
6601abf7346Smrg{
66136ffeb23Smrg    ManpageGlobals *mg = GetGlobals(w);
6621abf7346Smrg
6631abf7346Smrg    Log(("printCancelXtProc: cancel.\n"));
6641abf7346Smrg    XtPopdown(mg->printdialog_shell);
66536ffeb23Smrg
6661abf7346Smrg    Log(("destroying print dialog shell...\n"));
6671abf7346Smrg    XtDestroyWidget(mg->printdialog_shell);
6681abf7346Smrg    mg->printdialog_shell = NULL;
66936ffeb23Smrg    mg->printdialog = NULL;
6701abf7346Smrg    Log(("... done\n"));
6711abf7346Smrg}
6721abf7346Smrg
6731abf7346Smrg/*      Function Name: PrintThisManpage
6741abf7346Smrg *      Description: Print the current manual page.
6751abf7346Smrg *      Arguments: mg - manpage globals
6761abf7346Smrg *      Returns: none.
6771abf7346Smrg */
6781abf7346Smrg
6791abf7346Smrg/*ARGSUSED*/
68036ffeb23Smrgvoid
68136ffeb23SmrgPrintThisManpage(Widget w, XEvent * event, String * params,
68236ffeb23Smrg                 Cardinal * num_params)
6831abf7346Smrg{
68436ffeb23Smrg    ManpageGlobals *mg = GetGlobals(w);
68536ffeb23Smrg    Dimension width, height;
68636ffeb23Smrg    Position x, y;
68736ffeb23Smrg    Widget parent = mg->This_Manpage;
68836ffeb23Smrg    Widget topwindow = mg->This_Manpage;
68936ffeb23Smrg
69036ffeb23Smrg    Log(("print!\n"));
69136ffeb23Smrg
69236ffeb23Smrg    if (!mg->printdialog) {
69336ffeb23Smrg        int n;
69436ffeb23Smrg        Arg args[20];
69536ffeb23Smrg
69636ffeb23Smrg        n = 0;
69736ffeb23Smrg        XtSetArg(args[n], XtNallowShellResize, True);
69836ffeb23Smrg        n++;
69936ffeb23Smrg        mg->printdialog_shell = XtCreatePopupShell("printdialogshell",
70036ffeb23Smrg                                                   transientShellWidgetClass,
70136ffeb23Smrg                                                   topwindow, args, n);
70236ffeb23Smrg        n = 0;
70336ffeb23Smrg        mg->printdialog =
70436ffeb23Smrg            XtCreateManagedWidget("printdialog", printDialogWidgetClass,
70536ffeb23Smrg                                  mg->printdialog_shell, args, n);
70636ffeb23Smrg        XtAddCallback(mg->printdialog, XawNOkCallback, printOKXtProc, NULL);
70736ffeb23Smrg        XtAddCallback(mg->printdialog, XawNCancelCallback, printCancelXtProc,
70836ffeb23Smrg                      NULL);
70936ffeb23Smrg
71036ffeb23Smrg        XtRealizeWidget(mg->printdialog_shell);
71136ffeb23Smrg    }
7121abf7346Smrg
71336ffeb23Smrg    /* Center dialog */
71436ffeb23Smrg    XtVaGetValues(mg->printdialog_shell,
71536ffeb23Smrg                  XtNwidth, &width, XtNheight, &height, NULL);
71636ffeb23Smrg
71736ffeb23Smrg    x = (Position) (XWidthOfScreen(XtScreen(parent)) - width) / 2;
71836ffeb23Smrg    y = (Position) (XHeightOfScreen(XtScreen(parent)) - height) / 3;
71936ffeb23Smrg
72036ffeb23Smrg    XtVaSetValues(mg->printdialog_shell, XtNx, x, XtNy, y, NULL);
72136ffeb23Smrg
72236ffeb23Smrg    XtPopup(mg->printdialog_shell, XtGrabNonexclusive);
7231abf7346Smrg}
72436ffeb23Smrg#endif                          /* INCLUDE_XPRINT_SUPPORT */
7251abf7346Smrg
7261abf7346Smrg/*      Function Name: ShowVersion
7271abf7346Smrg *      Description: Show current version.
7281abf7346Smrg *      Arguments: w - any widget in the manpage.
7291abf7346Smrg *                 event - NOT USED.
7301abf7346Smrg *                 params, num_params - NOT USED.
7311abf7346Smrg *      Returns: none.
7321abf7346Smrg */
7331abf7346Smrg
7341abf7346Smrg/*ARGSUSED*/
73536ffeb23Smrgvoid
7361abf7346SmrgShowVersion(Widget w, XEvent * event, String * params, Cardinal * num_params)
7371abf7346Smrg{
73836ffeb23Smrg    ManpageGlobals *man_globals = GetGlobals(w);
73936ffeb23Smrg
74036ffeb23Smrg    ChangeLabel(man_globals->label, XMAN_VERSION);
7411abf7346Smrg}
742