handler.c revision 1abf7346
11abf7346Smrg/* $XConsortium: handler.c,v 1.22 94/12/16 21:36:53 gildea Exp $ */ 21abf7346Smrg/* 31abf7346Smrg 41abf7346SmrgCopyright (c) 1987, 1988 X Consortium 51abf7346Smrg 61abf7346SmrgPermission is hereby granted, free of charge, to any person obtaining 71abf7346Smrga copy of this software and associated documentation files (the 81abf7346Smrg"Software"), to deal in the Software without restriction, including 91abf7346Smrgwithout limitation the rights to use, copy, modify, merge, publish, 101abf7346Smrgdistribute, sublicense, and/or sell copies of the Software, and to 111abf7346Smrgpermit persons to whom the Software is furnished to do so, subject to 121abf7346Smrgthe following conditions: 131abf7346Smrg 141abf7346SmrgThe above copyright notice and this permission notice shall be included 151abf7346Smrgin all copies or substantial portions of the Software. 161abf7346Smrg 171abf7346SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 181abf7346SmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 191abf7346SmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 201abf7346SmrgIN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR 211abf7346SmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 221abf7346SmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 231abf7346SmrgOTHER DEALINGS IN THE SOFTWARE. 241abf7346Smrg 251abf7346SmrgExcept as contained in this notice, the name of the X Consortium shall 261abf7346Smrgnot be used in advertising or otherwise to promote the sale, use or 271abf7346Smrgother dealings in this Software without prior written authorization 281abf7346Smrgfrom the X Consortium. 291abf7346Smrg 301abf7346Smrg*/ 311abf7346Smrg/* $XFree86: xc/programs/xman/handler.c,v 1.6 2003/01/19 04:44:45 paulo Exp $ */ 321abf7346Smrg 331abf7346Smrg/* 341abf7346Smrg * xman - X window system manual page display program. 351abf7346Smrg * Author: Chris D. Peterson, MIT Project Athena 361abf7346Smrg * Created: October 29, 1987 371abf7346Smrg */ 381abf7346Smrg 391abf7346Smrg#include <sys/types.h> 401abf7346Smrg#include <sys/stat.h> 411abf7346Smrg#include "globals.h" 421abf7346Smrg#include "vendor.h" 431abf7346Smrg#ifdef INCLUDE_XPRINT_SUPPORT 441abf7346Smrg#include "printdialog.h" 451abf7346Smrg#include "print.h" 461abf7346Smrg#endif /* INCLUDE_XPRINT_SUPPORT */ 471abf7346Smrg 481abf7346Smrgstatic void PutUpManpage(ManpageGlobals * man_globals, FILE * file); 491abf7346Smrgstatic void ToggleBothShownState(ManpageGlobals * man_globals); 501abf7346Smrg 511abf7346Smrg/* Function Name: OptionCallback 521abf7346Smrg * Description: This is the callback function for the callback menu. 531abf7346Smrg * Arguments: w - the widget we are calling back from. 541abf7346Smrg * globals_pointer - a pointer to the psuedo globals structure 551abf7346Smrg * for this manpage. 561abf7346Smrg * junk - (call data) not used. 571abf7346Smrg * Returns: none. 581abf7346Smrg */ 591abf7346Smrg 601abf7346Smrg/*ARGSUSED*/ 611abf7346Smrgvoid 621abf7346SmrgOptionCallback(Widget w, XtPointer pointer, XtPointer junk) 631abf7346Smrg{ 641abf7346Smrg ManpageGlobals * man_globals = (ManpageGlobals *) pointer; 651abf7346Smrg String params; 661abf7346Smrg Cardinal num_params = 1; 671abf7346Smrg 681abf7346Smrg if ( w == man_globals->search_entry ) 691abf7346Smrg PopupSearch(XtParent(w), NULL, NULL, NULL); 701abf7346Smrg else if (w == man_globals->dir_entry) { /* Put Up Directory */ 711abf7346Smrg params = "Directory"; 721abf7346Smrg GotoPage(XtParent(w), NULL, ¶ms, &num_params); 731abf7346Smrg } 741abf7346Smrg else if (w == man_globals->manpage_entry ) { /* Put Up Man Page */ 751abf7346Smrg params = "ManualPage"; 761abf7346Smrg GotoPage(XtParent(w), NULL, ¶ms, &num_params); 771abf7346Smrg } 781abf7346Smrg else if ( w == man_globals->help_entry ) /* Help */ 791abf7346Smrg PopupHelp(XtParent(w), NULL, NULL, NULL); 801abf7346Smrg else if ( w == man_globals->both_screens_entry ) /*Toggle Both_Shown State.*/ 811abf7346Smrg ToggleBothShownState(man_globals); 821abf7346Smrg else if ( w == man_globals->remove_entry) /* Kill the manpage */ 831abf7346Smrg RemoveThisManpage(XtParent(w), NULL, NULL, NULL); 841abf7346Smrg else if ( w == man_globals->open_entry) /* Open new manpage */ 851abf7346Smrg CreateNewManpage(XtParent(w), NULL, NULL, NULL); 861abf7346Smrg#ifdef INCLUDE_XPRINT_SUPPORT 871abf7346Smrg else if ( w == man_globals->print_entry) /* Print current manpage */ 881abf7346Smrg PrintThisManpage(XtParent(w), NULL, NULL, NULL); 891abf7346Smrg#endif /* INCLUDE_XPRINT_SUPPORT */ 901abf7346Smrg else if ( w == man_globals->version_entry) /* Get version */ 911abf7346Smrg ShowVersion(XtParent(w), NULL, NULL, NULL); 921abf7346Smrg else if ( w == man_globals->quit_entry) /* Quit. */ 931abf7346Smrg Quit(XtParent(w), NULL, NULL, NULL); 941abf7346Smrg} 951abf7346Smrg 961abf7346Smrg/* Function Name: ToggleBothShownState; 971abf7346Smrg * Description: toggles the state of the both shown feature. 981abf7346Smrg * Arguments: man_globals - the man globals structure. 991abf7346Smrg * Returns: none. 1001abf7346Smrg */ 1011abf7346Smrg 1021abf7346Smrg/* 1031abf7346Smrg * I did not have a two state widget, which is the way this 1041abf7346Smrg * should really be done. 1/22/88 - CDP. 1051abf7346Smrg */ 1061abf7346Smrg 1071abf7346Smrgstatic void 1081abf7346SmrgToggleBothShownState(ManpageGlobals * man_globals) 1091abf7346Smrg{ 1101abf7346Smrg char * label_str; 1111abf7346Smrg Arg arglist[1]; 1121abf7346Smrg 1131abf7346Smrg if (man_globals->both_shown == TRUE) { 1141abf7346Smrg label_str = SHOW_BOTH; 1151abf7346Smrg if (man_globals->dir_shown) 1161abf7346Smrg XtUnmanageChild(man_globals->manpagewidgets.manpage); 1171abf7346Smrg else 1181abf7346Smrg XtUnmanageChild(man_globals->manpagewidgets.directory); 1191abf7346Smrg } 1201abf7346Smrg else { 1211abf7346Smrg Widget manpage = man_globals->manpagewidgets.manpage; 1221abf7346Smrg Widget dir = man_globals->manpagewidgets.directory; 1231abf7346Smrg 1241abf7346Smrg label_str = SHOW_ONE; 1251abf7346Smrg 1261abf7346Smrg XtSetArg(arglist[0], XtNpreferredPaneSize, resources.directory_height); 1271abf7346Smrg XtSetValues(dir, arglist, (Cardinal) 1); 1281abf7346Smrg 1291abf7346Smrg if (!man_globals->dir_shown) { 1301abf7346Smrg XtUnmanageChild(manpage); 1311abf7346Smrg XtManageChild(dir); 1321abf7346Smrg } 1331abf7346Smrg XtManageChild(manpage); 1341abf7346Smrg } 1351abf7346Smrg man_globals->both_shown = !man_globals->both_shown; 1361abf7346Smrg 1371abf7346Smrg if (man_globals->dir_shown) 1381abf7346Smrg ChangeLabel(man_globals->label, 1391abf7346Smrg man_globals->section_name[man_globals->current_directory]); 1401abf7346Smrg else 1411abf7346Smrg ChangeLabel(man_globals->label, man_globals->manpage_title); 1421abf7346Smrg 1431abf7346Smrg XtSetArg(arglist[0], XtNlabel, label_str); 1441abf7346Smrg XtSetValues(man_globals->both_screens_entry, arglist, ONE); 1451abf7346Smrg 1461abf7346Smrg /* if both are shown there is no need to switch between the two. */ 1471abf7346Smrg 1481abf7346Smrg XtSetArg(arglist[0], XtNsensitive, !man_globals->both_shown); 1491abf7346Smrg XtSetValues(man_globals->manpage_entry, arglist, ONE); 1501abf7346Smrg XtSetValues(man_globals->dir_entry, arglist, ONE); 1511abf7346Smrg} 1521abf7346Smrg 1531abf7346Smrg/* Function Name: Popup 1541abf7346Smrg * Description: This function pops up the given widget under the cursor. 1551abf7346Smrg * Arguments: w - the widget to popup. 1561abf7346Smrg * grab_kind - the kind of grab to register. 1571abf7346Smrg * Returns: none 1581abf7346Smrg */ 1591abf7346Smrg 1601abf7346Smrg/* How far off the top of the widget to have the initial cursor postion. */ 1611abf7346Smrg 1621abf7346Smrg#define OFF_OF_TOP 25 1631abf7346Smrg 1641abf7346Smrgvoid 1651abf7346SmrgPopup(Widget w, XtGrabKind grab_kind) 1661abf7346Smrg{ 1671abf7346Smrg int x_root,y_root,y_pos,garbage; 1681abf7346Smrg unsigned int mask; 1691abf7346Smrg Window junk_window; 1701abf7346Smrg 1711abf7346Smrg XQueryPointer(XtDisplay(w), XtWindow(w), &junk_window, &junk_window, 1721abf7346Smrg &x_root, &y_root, &garbage, &garbage, &mask); 1731abf7346Smrg 1741abf7346Smrg y_pos = OFF_OF_TOP - Height(w)/2 - BorderWidth(w); 1751abf7346Smrg PositionCenter(w, x_root, y_root, y_pos, 0, 2, 2); 1761abf7346Smrg XtPopup(w, grab_kind); 1771abf7346Smrg} 1781abf7346Smrg 1791abf7346Smrg/* Function Name: PutUpManpage 1801abf7346Smrg * Description: Puts the manpage on the display. 1811abf7346Smrg * Arguments: man_globals - a pointer to the psuedo globals structure 1821abf7346Smrg * for this manpage. 1831abf7346Smrg * file - the file to display. 1841abf7346Smrg * Returns: none. 1851abf7346Smrg */ 1861abf7346Smrg 1871abf7346Smrgstatic void 1881abf7346SmrgPutUpManpage(ManpageGlobals * man_globals, FILE * file) 1891abf7346Smrg{ 1901abf7346Smrg String params = "ManualPage"; 1911abf7346Smrg Cardinal num_params = 1; 1921abf7346Smrg 1931abf7346Smrg if (file == NULL) 1941abf7346Smrg return; 1951abf7346Smrg 1961abf7346Smrg OpenFile(man_globals, file); 1971abf7346Smrg 1981abf7346Smrg if (!man_globals->both_shown) { 1991abf7346Smrg Arg arglist[1]; 2001abf7346Smrg XtSetArg(arglist[0], XtNsensitive, TRUE); 2011abf7346Smrg XtSetValues(man_globals->manpage_entry, arglist, ONE); 2021abf7346Smrg XtSetValues(man_globals->both_screens_entry, arglist, ONE); 2031abf7346Smrg } 2041abf7346Smrg GotoPage(man_globals->manpagewidgets.manpage, NULL, ¶ms, &num_params); 2051abf7346Smrg} 2061abf7346Smrg 2071abf7346Smrg/* Function Name: DirectoryHandler 2081abf7346Smrg * Description: This is the callback function for the directory listings. 2091abf7346Smrg * Arguments: w - the widget we are calling back from. 2101abf7346Smrg * global_pointer - the pointer to the psuedo global structure 2111abf7346Smrg * associated with this manpage. 2121abf7346Smrg * ret_val - return value from the list widget. 2131abf7346Smrg * Returns: none. 2141abf7346Smrg */ 2151abf7346Smrg 2161abf7346Smrgvoid 2171abf7346SmrgDirectoryHandler(Widget w, XtPointer global_pointer, XtPointer ret_val) 2181abf7346Smrg{ 2191abf7346Smrg FILE * file; /* The manpage file. */ 2201abf7346Smrg ManpageGlobals * man_globals = (ManpageGlobals *) global_pointer; 2211abf7346Smrg XawListReturnStruct * ret_struct = (XawListReturnStruct *) ret_val; 2221abf7346Smrg 2231abf7346Smrg file = FindManualFile(man_globals, man_globals->current_directory, 2241abf7346Smrg ret_struct->list_index); 2251abf7346Smrg PutUpManpage(man_globals, file); 2261abf7346Smrg if ((file != NULL) && (file != man_globals->curr_file)) { 2271abf7346Smrg fclose(file); 2281abf7346Smrg } 2291abf7346Smrg} 2301abf7346Smrg 2311abf7346Smrg/* Function Name: DirPopupCallback 2321abf7346Smrg * Description: This is the callback function for the callback menu. 2331abf7346Smrg * Arguments: w - the widget we are calling back from. 2341abf7346Smrg * pointer - a pointer to the psuedo globals structure 2351abf7346Smrg * for this manpage. 2361abf7346Smrg * junk - (call data) not used. 2371abf7346Smrg * Returns: none. 2381abf7346Smrg */ 2391abf7346Smrg 2401abf7346Smrg/*ARGSUSED*/ 2411abf7346Smrgvoid 2421abf7346SmrgDirPopupCallback(Widget w, XtPointer pointer, XtPointer junk) 2431abf7346Smrg{ 2441abf7346Smrg ManpageGlobals * man_globals; 2451abf7346Smrg MenuStruct * menu_struct; 2461abf7346Smrg Widget parent; 2471abf7346Smrg int number; 2481abf7346Smrg int current_box; 2491abf7346Smrg 2501abf7346Smrg menu_struct = (MenuStruct *) pointer; 2511abf7346Smrg man_globals = (ManpageGlobals *) menu_struct->data; 2521abf7346Smrg 2531abf7346Smrg number = menu_struct->number; 2541abf7346Smrg current_box = man_globals->current_directory; 2551abf7346Smrg 2561abf7346Smrg /* We have used this guy, pop down the menu. */ 2571abf7346Smrg 2581abf7346Smrg if (number != current_box) { 2591abf7346Smrg /* This is the only one that we know has a parent. */ 2601abf7346Smrg parent = XtParent(man_globals->manpagewidgets.box[INITIAL_DIR]); 2611abf7346Smrg 2621abf7346Smrg MakeDirectoryBox(man_globals, parent, 2631abf7346Smrg man_globals->manpagewidgets.box + number, number); 2641abf7346Smrg XtUnmanageChild(man_globals->manpagewidgets.box[current_box]); 2651abf7346Smrg XtManageChild(man_globals->manpagewidgets.box[number]); 2661abf7346Smrg 2671abf7346Smrg XawListUnhighlight(man_globals->manpagewidgets.box[current_box]); 2681abf7346Smrg ChangeLabel(man_globals->label, man_globals->section_name[number]); 2691abf7346Smrg man_globals->current_directory = number; 2701abf7346Smrg } 2711abf7346Smrg 2721abf7346Smrg /* put up directory. */ 2731abf7346Smrg if (!man_globals->both_shown) { 2741abf7346Smrg XtUnmanageChild(man_globals->manpagewidgets.manpage); 2751abf7346Smrg XtManageChild(man_globals->manpagewidgets.directory); 2761abf7346Smrg } 2771abf7346Smrg} 2781abf7346Smrg 2791abf7346Smrg/************************************************************ 2801abf7346Smrg * 2811abf7346Smrg * Action Routines. 2821abf7346Smrg * 2831abf7346Smrg ************************************************************/ 2841abf7346Smrg 2851abf7346Smrg/* Function Name: SaveFormattedPage 2861abf7346Smrg * Description: This is the action routine may save the manpage. 2871abf7346Smrg * Arguments: w - any widget in the widget tree. 2881abf7346Smrg * event - NOT USED. 2891abf7346Smrg * params, num_params - the parameters paseed to the action 2901abf7346Smrg * routine, can be either Manpage or 2911abf7346Smrg * Directory. 2921abf7346Smrg * Returns: none. 2931abf7346Smrg */ 2941abf7346Smrg 2951abf7346Smrg/*ARGSUSED*/ 2961abf7346Smrgvoid 2971abf7346SmrgSaveFormattedPage(Widget w, XEvent * event, String * params, Cardinal * num_params) 2981abf7346Smrg{ 2991abf7346Smrg ManpageGlobals * man_globals; 3001abf7346Smrg char cmdbuf[BUFSIZ], error_buf[BUFSIZ]; 3011abf7346Smrg 3021abf7346Smrg if (*num_params != 1) { 3031abf7346Smrg XtAppWarning(XtWidgetToApplicationContext(w), 3041abf7346Smrg "Xman - SaveFormattedPage: This action routine requires one argument."); 3051abf7346Smrg return; 3061abf7346Smrg } 3071abf7346Smrg 3081abf7346Smrg man_globals = GetGlobals(w); 3091abf7346Smrg 3101abf7346Smrg/* 3111abf7346Smrg * If we are not active then take no action. 3121abf7346Smrg */ 3131abf7346Smrg 3141abf7346Smrg if (man_globals->tempfile == '\0') return; 3151abf7346Smrg 3161abf7346Smrg switch (params[0][0]) { 3171abf7346Smrg case 'S': 3181abf7346Smrg case 's': 3191abf7346Smrg 3201abf7346Smrg#ifndef NO_COMPRESS 3211abf7346Smrg if (!man_globals->compress) 3221abf7346Smrg#endif 3231abf7346Smrg 3241abf7346Smrg sprintf(cmdbuf, "%s %s %s", COPY, man_globals->tempfile, 3251abf7346Smrg man_globals->save_file); 3261abf7346Smrg 3271abf7346Smrg#ifndef NO_COMPRESS 3281abf7346Smrg else 3291abf7346Smrg if (man_globals->gzip) 3301abf7346Smrg sprintf(cmdbuf, "%s < %s > %s", GZIP_COMPRESS, man_globals->tempfile, 3311abf7346Smrg man_globals->save_file); 3321abf7346Smrg else 3331abf7346Smrg sprintf(cmdbuf, "%s < %s > %s", COMPRESS, man_globals->tempfile, 3341abf7346Smrg man_globals->save_file); 3351abf7346Smrg#endif 3361abf7346Smrg 3371abf7346Smrg if(! system(cmdbuf)) { 3381abf7346Smrg /* make sure the formatted man page is fully accessible by the world */ 3391abf7346Smrg if (chmod(man_globals->save_file, CHMOD_MODE) != 0) { 3401abf7346Smrg sprintf(error_buf, 3411abf7346Smrg "Couldn't set permissions on formatted man page '%s'.\n", 3421abf7346Smrg man_globals->save_file); 3431abf7346Smrg PopupWarning( man_globals, error_buf); 3441abf7346Smrg } 3451abf7346Smrg } else { 3461abf7346Smrg sprintf(error_buf, "Error while executing the command '%s'.\n", 3471abf7346Smrg cmdbuf); 3481abf7346Smrg PopupWarning( man_globals, error_buf); 3491abf7346Smrg } 3501abf7346Smrg break; 3511abf7346Smrg case 'C': 3521abf7346Smrg case 'c': 3531abf7346Smrg break; 3541abf7346Smrg default: 3551abf7346Smrg sprintf(error_buf,"%s %s", "Xman - SaveFormattedPagee:", 3561abf7346Smrg "Unknown argument must be either 'Save' or 'Cancel'."); 3571abf7346Smrg PopupWarning(man_globals, error_buf); 3581abf7346Smrg return; 3591abf7346Smrg } 3601abf7346Smrg 3611abf7346Smrg/* 3621abf7346Smrg * We do not need the filename anymore, and have the fd open. 3631abf7346Smrg * We will unlink it. 3641abf7346Smrg */ 3651abf7346Smrg 3661abf7346Smrg unlink(man_globals->tempfile); 3671abf7346Smrg XtPopdown( XtParent(XtParent(w)) ); 3681abf7346Smrg} 3691abf7346Smrg 3701abf7346Smrg/* Function Name: GotoPage 3711abf7346Smrg * Description: The Action routine that switches over to the manpage 3721abf7346Smrg * or directory. 3731abf7346Smrg * Arguments: w - any widget in the widget tree. 3741abf7346Smrg * event - NOT USED. 3751abf7346Smrg * params, num_params - the parameters paseed to the action 3761abf7346Smrg * routine, can be either Manpage or 3771abf7346Smrg * Directory. 3781abf7346Smrg * Returns: none. 3791abf7346Smrg */ 3801abf7346Smrg 3811abf7346Smrg/*ARGSUSED*/ 3821abf7346Smrgvoid 3831abf7346SmrgGotoPage(Widget w, XEvent * event, String * params, Cardinal * num_params) 3841abf7346Smrg{ 3851abf7346Smrg ManpageGlobals * man_globals; 3861abf7346Smrg char error_buf[BUFSIZ]; 3871abf7346Smrg Arg arglist[1]; 3881abf7346Smrg Boolean sensitive; 3891abf7346Smrg 3901abf7346Smrg if (*num_params != 1) { 3911abf7346Smrg XtAppWarning(XtWidgetToApplicationContext(w), 3921abf7346Smrg "Xman - GotoPage: This action routine requires one argument."); 3931abf7346Smrg return; 3941abf7346Smrg } 3951abf7346Smrg 3961abf7346Smrg man_globals = GetGlobals(w); 3971abf7346Smrg 3981abf7346Smrg if (man_globals->both_shown) { 3991abf7346Smrg ChangeLabel(man_globals->label, 4001abf7346Smrg man_globals->section_name[man_globals->current_directory]); 4011abf7346Smrg return; 4021abf7346Smrg } 4031abf7346Smrg 4041abf7346Smrg switch (params[0][0]) { 4051abf7346Smrg case 'M': 4061abf7346Smrg case 'm': 4071abf7346Smrg XtSetArg(arglist[0], XtNsensitive, &sensitive); 4081abf7346Smrg XtGetValues(man_globals->manpage_entry, arglist, ONE); 4091abf7346Smrg if (sensitive) { 4101abf7346Smrg ChangeLabel(man_globals->label,man_globals->manpage_title); 4111abf7346Smrg XtUnmanageChild(man_globals->manpagewidgets.directory); 4121abf7346Smrg XtManageChild(man_globals->manpagewidgets.manpage); 4131abf7346Smrg man_globals->dir_shown = FALSE; 4141abf7346Smrg } 4151abf7346Smrg break; 4161abf7346Smrg case 'D': 4171abf7346Smrg case 'd': 4181abf7346Smrg ChangeLabel(man_globals->label, 4191abf7346Smrg man_globals->section_name[man_globals->current_directory]); 4201abf7346Smrg XtUnmanageChild(man_globals->manpagewidgets.manpage); 4211abf7346Smrg XtManageChild(man_globals->manpagewidgets.directory); 4221abf7346Smrg man_globals->dir_shown = TRUE; 4231abf7346Smrg break; 4241abf7346Smrg default: 4251abf7346Smrg sprintf(error_buf,"%s %s", "Xman - GotoPage: Unknown argument must be", 4261abf7346Smrg "either Manpage or Directory."); 4271abf7346Smrg XtAppWarning(XtWidgetToApplicationContext(w), error_buf); 4281abf7346Smrg return; 4291abf7346Smrg } 4301abf7346Smrg} 4311abf7346Smrg 4321abf7346Smrg/* Function Name: Quit. 4331abf7346Smrg * Description: Quits Xman. 4341abf7346Smrg * Arguments: w - any widget. 4351abf7346Smrg * event - NOT USED. 4361abf7346Smrg * params, num_params - NOT USED. 4371abf7346Smrg * Returns: none. 4381abf7346Smrg */ 4391abf7346Smrg 4401abf7346Smrg/*ARGSUSED*/ 4411abf7346Smrgvoid 4421abf7346SmrgQuit(Widget w, XEvent * event, String * params, Cardinal * num_params) 4431abf7346Smrg{ 4441abf7346Smrg XtAppSetExitFlag(XtWidgetToApplicationContext(w)); 4451abf7346Smrg} 4461abf7346Smrg 4471abf7346Smrg/* Function Name: PopupHelp 4481abf7346Smrg * Description: Pops up xman's help. 4491abf7346Smrg * Arguments: w - NOT USED. 4501abf7346Smrg * event - NOT USED. 4511abf7346Smrg * params, num_params - NOT USED. 4521abf7346Smrg * Returns: none. 4531abf7346Smrg */ 4541abf7346Smrg 4551abf7346Smrg/*ARGSUSED*/ 4561abf7346Smrgvoid 4571abf7346SmrgPopupHelp(Widget w, XEvent * event, String * params, Cardinal * num_params) 4581abf7346Smrg{ 4591abf7346Smrg if (MakeHelpWidget()) 4601abf7346Smrg XtPopup(help_widget,XtGrabNone); 4611abf7346Smrg} 4621abf7346Smrg 4631abf7346Smrg/* Function Name: PopupSearch 4641abf7346Smrg * Description: Pops up this manual pages search widget. 4651abf7346Smrg * Arguments: w - any widget in this manpage. 4661abf7346Smrg * event - NOT USED. 4671abf7346Smrg * params, num_params - NOT USED. 4681abf7346Smrg * Returns: none. 4691abf7346Smrg */ 4701abf7346Smrg 4711abf7346Smrg/*ARGSUSED*/ 4721abf7346Smrgvoid 4731abf7346SmrgPopupSearch(Widget w, XEvent * event, String * params, Cardinal * num_params) 4741abf7346Smrg{ 4751abf7346Smrg ManpageGlobals * man_globals = GetGlobals(w); 4761abf7346Smrg 4771abf7346Smrg if (man_globals->search_widget) { 4781abf7346Smrg if (!XtIsRealized(man_globals->search_widget)) { 4791abf7346Smrg XtRealizeWidget(man_globals->search_widget); 4801abf7346Smrg AddCursor(man_globals->search_widget, resources.cursors.search_entry); 4811abf7346Smrg } 4821abf7346Smrg Popup(man_globals->search_widget, XtGrabNone); 4831abf7346Smrg } 4841abf7346Smrg} 4851abf7346Smrg 4861abf7346Smrg/* Function Name: CreateNewManpage 4871abf7346Smrg * Description: Creates A New Manual Page. 4881abf7346Smrg * Arguments: w - NOT USED. 4891abf7346Smrg * event - NOT USED. 4901abf7346Smrg * params, num_params - NOT USED. 4911abf7346Smrg * Returns: none. 4921abf7346Smrg */ 4931abf7346Smrg 4941abf7346Smrg/*ARGSUSED*/ 4951abf7346Smrgvoid 4961abf7346SmrgCreateNewManpage(Widget w, XEvent * event, String * params, Cardinal * num_params) 4971abf7346Smrg{ 4981abf7346Smrg (void) CreateManpage(NULL); 4991abf7346Smrg man_pages_shown++; 5001abf7346Smrg} 5011abf7346Smrg 5021abf7346Smrg/* Function Name: RemoveThisManpage 5031abf7346Smrg * Description: Removes a manual page. 5041abf7346Smrg * Arguments: w - any widget in the manpage. 5051abf7346Smrg * event - NOT USED. 5061abf7346Smrg * params, num_params - NOT USED. 5071abf7346Smrg * Returns: none. 5081abf7346Smrg */ 5091abf7346Smrg 5101abf7346Smrg/*ARGSUSED*/ 5111abf7346Smrgvoid 5121abf7346SmrgRemoveThisManpage(Widget w, XEvent * event, String * params, Cardinal * num_params) 5131abf7346Smrg{ 5141abf7346Smrg ManpageGlobals * man_globals = GetGlobals(w); 5151abf7346Smrg 5161abf7346Smrg if (man_globals->This_Manpage != help_widget) { 5171abf7346Smrg RemoveGlobals(man_globals->This_Manpage); 5181abf7346Smrg XtDestroyWidget(man_globals->This_Manpage); 5191abf7346Smrg 5201abf7346Smrg XtFree( (char *) man_globals->section_name); 5211abf7346Smrg XtFree( (char *) man_globals->manpagewidgets.box); 5221abf7346Smrg XtFree( (char *) man_globals); 5231abf7346Smrg 5241abf7346Smrg if ( (--man_pages_shown) == 0) 5251abf7346Smrg Quit(w, NULL, NULL, NULL); 5261abf7346Smrg } 5271abf7346Smrg else 5281abf7346Smrg XtPopdown(help_widget); 5291abf7346Smrg} 5301abf7346Smrg 5311abf7346Smrg/* Function Name: Search 5321abf7346Smrg * Description: Actually performs a search. 5331abf7346Smrg * Arguments: w - any widget in the manpage. 5341abf7346Smrg * event - NOT USED. 5351abf7346Smrg * params, num_params - NOT USED. 5361abf7346Smrg * Returns: none. 5371abf7346Smrg */ 5381abf7346Smrg 5391abf7346Smrg/*ARGSUSED*/ 5401abf7346Smrgvoid 5411abf7346SmrgSearch(Widget w, XEvent * event, String * params, Cardinal * num_params) 5421abf7346Smrg{ 5431abf7346Smrg ManpageGlobals * man_globals = GetGlobals(w); 5441abf7346Smrg FILE * file = NULL; 5451abf7346Smrg 5461abf7346Smrg XtPopdown( XtParent(XtParent(w)) ); /* popdown the search widget */ 5471abf7346Smrg 5481abf7346Smrg if ( (*num_params < 1) || (*num_params > 2) ) { 5491abf7346Smrg XtAppWarning(XtWidgetToApplicationContext(w), 5501abf7346Smrg "Xman - Search: This action routine requires one or two arguments."); 5511abf7346Smrg return; 5521abf7346Smrg } 5531abf7346Smrg 5541abf7346Smrg switch(params[0][0]) { 5551abf7346Smrg case 'a': 5561abf7346Smrg case 'A': 5571abf7346Smrg file = DoSearch(man_globals,APROPOS); 5581abf7346Smrg break; 5591abf7346Smrg case 'm': 5601abf7346Smrg case 'M': 5611abf7346Smrg file = DoSearch(man_globals,MANUAL); 5621abf7346Smrg break; 5631abf7346Smrg case 'c': 5641abf7346Smrg case 'C': 5651abf7346Smrg file = NULL; 5661abf7346Smrg break; 5671abf7346Smrg default: 5681abf7346Smrg XtAppWarning(XtWidgetToApplicationContext(w), 5691abf7346Smrg "Xman - Search: First parameter unknown."); 5701abf7346Smrg file = NULL; 5711abf7346Smrg break; 5721abf7346Smrg } 5731abf7346Smrg 5741abf7346Smrg if ( *num_params == 2 ) 5751abf7346Smrg switch (params[1][0]) { 5761abf7346Smrg case 'O': 5771abf7346Smrg case 'o': 5781abf7346Smrg if (file != NULL) { 5791abf7346Smrg Widget w; 5801abf7346Smrg char * label; 5811abf7346Smrg 5821abf7346Smrg w = CreateManpage(file); 5831abf7346Smrg man_pages_shown++; 5841abf7346Smrg 5851abf7346Smrg /* Put title into new manual page. */ 5861abf7346Smrg 5871abf7346Smrg label = man_globals->manpage_title; 5881abf7346Smrg man_globals = GetGlobals(w); 5891abf7346Smrg strcpy(man_globals->manpage_title, label); 5901abf7346Smrg ChangeLabel(man_globals->label, label); 5911abf7346Smrg } 5921abf7346Smrg break; 5931abf7346Smrg default: 5941abf7346Smrg XtAppWarning(XtWidgetToApplicationContext(w), 5951abf7346Smrg "Xman - Search: Second parameter unknown."); 5961abf7346Smrg break; 5971abf7346Smrg } 5981abf7346Smrg else { 5991abf7346Smrg PutUpManpage(man_globals, file); 6001abf7346Smrg } 6011abf7346Smrg if ((file != NULL) && (file != man_globals->curr_file)) { 6021abf7346Smrg fclose(file); 6031abf7346Smrg } 6041abf7346Smrg} 6051abf7346Smrg 6061abf7346Smrg#ifdef INCLUDE_XPRINT_SUPPORT 6071abf7346Smrgstatic void 6081abf7346SmrgprintshellDestroyXtProc(Widget w, XtPointer client_data, XtPointer callData) 6091abf7346Smrg{ 6101abf7346Smrg ManpageGlobals *mg = GetGlobals(w); 6111abf7346Smrg XawPrintDialogClosePrinterConnection(mg->printdialog, False); 6121abf7346Smrg} 6131abf7346Smrg 6141abf7346Smrgstatic void 6151abf7346SmrgprintOKXtProc(Widget w, XtPointer client_data, XtPointer callData) 6161abf7346Smrg{ 6171abf7346Smrg XawPrintDialogCallbackStruct *pdcs = (XawPrintDialogCallbackStruct *)callData; 6181abf7346Smrg Cardinal n; 6191abf7346Smrg Arg args[2]; 6201abf7346Smrg ManpageGlobals *mg = GetGlobals(w); 6211abf7346Smrg Widget topwindow = mg->This_Manpage; 6221abf7346Smrg FILE *file; 6231abf7346Smrg 6241abf7346Smrg Log(("printOKXtProc: OK.\n")); 6251abf7346Smrg 6261abf7346Smrg /* Get file object */ 6271abf7346Smrg n = 0; 6281abf7346Smrg XtSetArg(args[n], XtNfile, &file); n++; 6291abf7346Smrg XtGetValues(mg->manpagewidgets.manpage, args, n); 6301abf7346Smrg Assertion(file != NULL, (("printOKXtProc: file == NULL.\n"))); 6311abf7346Smrg 6321abf7346Smrg DoPrintManpage("Xman", 6331abf7346Smrg file, topwindow, 6341abf7346Smrg pdcs->pdpy, pdcs->pcontext, pdcs->colorspace, 6351abf7346Smrg printshellDestroyXtProc, 6361abf7346Smrg mg->manpage_title, 6371abf7346Smrg pdcs->printToFile?pdcs->printToFileName:NULL); 6381abf7346Smrg 6391abf7346Smrg XtPopdown(mg->printdialog_shell); 6401abf7346Smrg} 6411abf7346Smrg 6421abf7346Smrgstatic void 6431abf7346SmrgprintCancelXtProc(Widget w, XtPointer client_data, XtPointer callData) 6441abf7346Smrg{ 6451abf7346Smrg ManpageGlobals * mg = GetGlobals(w); 6461abf7346Smrg 6471abf7346Smrg Log(("printCancelXtProc: cancel.\n")); 6481abf7346Smrg XtPopdown(mg->printdialog_shell); 6491abf7346Smrg 6501abf7346Smrg Log(("destroying print dialog shell...\n")); 6511abf7346Smrg XtDestroyWidget(mg->printdialog_shell); 6521abf7346Smrg mg->printdialog_shell = NULL; 6531abf7346Smrg mg->printdialog = NULL; 6541abf7346Smrg Log(("... done\n")); 6551abf7346Smrg} 6561abf7346Smrg 6571abf7346Smrg/* Function Name: PrintThisManpage 6581abf7346Smrg * Description: Print the current manual page. 6591abf7346Smrg * Arguments: mg - manpage globals 6601abf7346Smrg * Returns: none. 6611abf7346Smrg */ 6621abf7346Smrg 6631abf7346Smrg/*ARGSUSED*/ 6641abf7346Smrgvoid 6651abf7346SmrgPrintThisManpage(Widget w, XEvent * event, String * params, Cardinal * num_params) 6661abf7346Smrg{ 6671abf7346Smrg ManpageGlobals *mg = GetGlobals(w); 6681abf7346Smrg Dimension width, height; 6691abf7346Smrg Position x, y; 6701abf7346Smrg Widget parent = mg->This_Manpage; 6711abf7346Smrg Widget topwindow = mg->This_Manpage; 6721abf7346Smrg Log(("print!\n")); 6731abf7346Smrg 6741abf7346Smrg if (!mg->printdialog) { 6751abf7346Smrg int n; 6761abf7346Smrg Arg args[20]; 6771abf7346Smrg 6781abf7346Smrg n = 0; 6791abf7346Smrg XtSetArg(args[n], XtNallowShellResize, True); n++; 6801abf7346Smrg mg->printdialog_shell = XtCreatePopupShell("printdialogshell", 6811abf7346Smrg transientShellWidgetClass, 6821abf7346Smrg topwindow, args, n); 6831abf7346Smrg n = 0; 6841abf7346Smrg mg->printdialog = XtCreateManagedWidget("printdialog", printDialogWidgetClass, 6851abf7346Smrg mg->printdialog_shell, args, n); 6861abf7346Smrg XtAddCallback(mg->printdialog, XawNOkCallback, printOKXtProc, NULL); 6871abf7346Smrg XtAddCallback(mg->printdialog, XawNCancelCallback, printCancelXtProc, NULL); 6881abf7346Smrg 6891abf7346Smrg XtRealizeWidget(mg->printdialog_shell); 6901abf7346Smrg } 6911abf7346Smrg 6921abf7346Smrg /* Center dialog */ 6931abf7346Smrg XtVaGetValues(mg->printdialog_shell, 6941abf7346Smrg XtNwidth, &width, 6951abf7346Smrg XtNheight, &height, 6961abf7346Smrg NULL); 6971abf7346Smrg 6981abf7346Smrg x = (Position)(XWidthOfScreen( XtScreen(parent)) - width) / 2; 6991abf7346Smrg y = (Position)(XHeightOfScreen(XtScreen(parent)) - height) / 3; 7001abf7346Smrg 7011abf7346Smrg XtVaSetValues(mg->printdialog_shell, 7021abf7346Smrg XtNx, x, 7031abf7346Smrg XtNy, y, 7041abf7346Smrg NULL); 7051abf7346Smrg 7061abf7346Smrg XtPopup(mg->printdialog_shell, XtGrabNonexclusive); 7071abf7346Smrg} 7081abf7346Smrg#endif /* INCLUDE_XPRINT_SUPPORT */ 7091abf7346Smrg 7101abf7346Smrg/* Function Name: ShowVersion 7111abf7346Smrg * Description: Show current version. 7121abf7346Smrg * Arguments: w - any widget in the manpage. 7131abf7346Smrg * event - NOT USED. 7141abf7346Smrg * params, num_params - NOT USED. 7151abf7346Smrg * Returns: none. 7161abf7346Smrg */ 7171abf7346Smrg 7181abf7346Smrg/*ARGSUSED*/ 7191abf7346Smrgvoid 7201abf7346SmrgShowVersion(Widget w, XEvent * event, String * params, Cardinal * num_params) 7211abf7346Smrg{ 7221abf7346Smrg ManpageGlobals * man_globals = GetGlobals(w); 7231abf7346Smrg ChangeLabel(man_globals->label, XMAN_VERSION); 7241abf7346Smrg} 725