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 27, 1987 351abf7346Smrg */ 361abf7346Smrg 371abf7346Smrg#include "globals.h" 381abf7346Smrg#include "vendor.h" 391abf7346Smrg 401abf7346Smrg/* The files with the icon bits in them. */ 411abf7346Smrg 421abf7346Smrg#include "icon_open.h" 431abf7346Smrg#include "icon_help.h" 441abf7346Smrg#include "iconclosed.h" 451abf7346Smrg 461abf7346Smrgstatic void CreateOptionMenu(ManpageGlobals * man_globals, Widget parent); 471abf7346Smrgstatic void CreateSectionMenu(ManpageGlobals * man_globals, Widget parent); 486d36ef34Smrgstatic void StartManpage(ManpageGlobals * man_globals, Boolean help, 496d36ef34Smrg Boolean page); 506d36ef34Smrgstatic Widget *ConvertNamesToWidgets(Widget parent, const char **names); 511abf7346Smrg 521abf7346Smrg/* Function Name: MakeTopBox 536d36ef34Smrg * Description: This function creates the top menu, in a shell widget. 541abf7346Smrg * Arguments: none. 551abf7346Smrg * Returns: the top level widget 561abf7346Smrg */ 571abf7346Smrg 581abf7346Smrg#define TOPARGS 5 591abf7346Smrg 606d36ef34SmrgWidget top; /* needed in PopupWarning, misc.c */ 611abf7346Smrg 621abf7346Smrgvoid 631abf7346SmrgMakeTopBox(void) 641abf7346Smrg{ 656d36ef34Smrg Widget form, command, label; /* widgets. */ 666d36ef34Smrg Arg arglist[TOPARGS]; /* An argument list */ 676d36ef34Smrg Cardinal num_args = 0; /* The number of arguments. */ 686d36ef34Smrg ManpageGlobals *man_globals; 696d36ef34Smrg static const char *full_size[] = { 706d36ef34Smrg "topLabel", MANPAGE_BUTTON, NULL 716d36ef34Smrg }; 726d36ef34Smrg static const char *half_size[] = { 736d36ef34Smrg HELP_BUTTON, QUIT_BUTTON, NULL 746d36ef34Smrg }; 756d36ef34Smrg 761abf7346Smrg/* create the top icon. */ 771abf7346Smrg 786d36ef34Smrg num_args = 0; 796d36ef34Smrg XtSetArg(arglist[num_args], XtNiconPixmap, 806d36ef34Smrg XCreateBitmapFromData(XtDisplay(initial_widget), 816d36ef34Smrg XtScreen(initial_widget)->root, 826d36ef34Smrg (const char *) iconclosed_bits, 836d36ef34Smrg iconclosed_width, iconclosed_height)); 846d36ef34Smrg num_args++; 856d36ef34Smrg XtSetArg(arglist[num_args], XtNtitle, resources.title); 866d36ef34Smrg num_args++; 876d36ef34Smrg XtSetArg(arglist[num_args], XtNiconic, resources.iconic); 886d36ef34Smrg num_args++; 896d36ef34Smrg top = XtCreatePopupShell(TOPBOXNAME, topLevelShellWidgetClass, 906d36ef34Smrg initial_widget, arglist, num_args); 916d36ef34Smrg 926d36ef34Smrg form = XtCreateManagedWidget("form", formWidgetClass, top, 936d36ef34Smrg NULL, (Cardinal) 0); 946d36ef34Smrg 956d36ef34Smrg label = XtCreateManagedWidget("topLabel", labelWidgetClass, form, 966d36ef34Smrg NULL, (Cardinal) 0); 976d36ef34Smrg 986d36ef34Smrg num_args = 0; 996d36ef34Smrg XtSetArg(arglist[num_args], XtNfromVert, label); 1006d36ef34Smrg num_args++; 1016d36ef34Smrg command = XtCreateManagedWidget(HELP_BUTTON, commandWidgetClass, form, 1026d36ef34Smrg arglist, num_args); 1036d36ef34Smrg 1046d36ef34Smrg /* use same vertical as help widget. */ 1056d36ef34Smrg XtSetArg(arglist[num_args], XtNfromHoriz, command); 1066d36ef34Smrg num_args++; 1076d36ef34Smrg command = XtCreateManagedWidget(QUIT_BUTTON, commandWidgetClass, form, 1086d36ef34Smrg arglist, num_args); 1096d36ef34Smrg 1106d36ef34Smrg num_args = 0; 1116d36ef34Smrg XtSetArg(arglist[num_args], XtNfromVert, command); 1126d36ef34Smrg num_args++; 1136d36ef34Smrg command = XtCreateManagedWidget(MANPAGE_BUTTON, commandWidgetClass, form, 1146d36ef34Smrg arglist, num_args); 1156d36ef34Smrg 1166d36ef34Smrg help_widget = NULL; /* We have not seen the help yet. */ 1176d36ef34Smrg 1186d36ef34Smrg FormUpWidgets(form, full_size, half_size); 1196d36ef34Smrg 1206d36ef34Smrg XtRealizeWidget(top); 1216d36ef34Smrg /* add WM_COMMAND property */ 1226d36ef34Smrg XSetCommand(XtDisplay(top), XtWindow(top), saved_argv, saved_argc); 1236d36ef34Smrg 1246d36ef34Smrg man_globals = 1256d36ef34Smrg (ManpageGlobals *) XtCalloc(ONE, (Cardinal) sizeof(ManpageGlobals)); 1266d36ef34Smrg MakeSearchWidget(man_globals, top); 1276d36ef34Smrg MakeSaveWidgets(man_globals, top); 1286d36ef34Smrg 1296d36ef34Smrg SaveGlobals((man_globals->This_Manpage = top), man_globals); 1306d36ef34Smrg XtMapWidget(top); 1316d36ef34Smrg AddCursor(top, resources.cursors.top); 1321abf7346Smrg 1331abf7346Smrg/* 1341abf7346Smrg * Set up ICCCM delete window. 1351abf7346Smrg */ 1366d36ef34Smrg XtOverrideTranslations 1376d36ef34Smrg (top, XtParseTranslationTable("<Message>WM_PROTOCOLS: Quit()")); 1386d36ef34Smrg (void) XSetWMProtocols(XtDisplay(top), XtWindow(top), &wm_delete_window, 1); 1391abf7346Smrg 1401abf7346Smrg} 1411abf7346Smrg 1421abf7346Smrg/* Function Name: CreateManpage 1431abf7346Smrg * Description: Creates a new manpage. 1441abf7346Smrg * Arguments: none. 1451abf7346Smrg * Returns: none. 1461abf7346Smrg */ 1471abf7346Smrg 1481abf7346SmrgWidget 1491abf7346SmrgCreateManpage(FILE * file) 1501abf7346Smrg{ 1516d36ef34Smrg ManpageGlobals *man_globals; /* The pseudo global structure. */ 1526d36ef34Smrg 1536d36ef34Smrg man_globals = InitPsuedoGlobals(); 1546d36ef34Smrg if (man_globals == NULL) 1556d36ef34Smrg return NULL; 1566d36ef34Smrg CreateManpageWidget(man_globals, MANNAME, TRUE); 1576d36ef34Smrg 1586d36ef34Smrg if (file == NULL) 1596d36ef34Smrg StartManpage(man_globals, OpenHelpfile(man_globals), FALSE); 1606d36ef34Smrg else { 1616d36ef34Smrg OpenFile(man_globals, file); 1626d36ef34Smrg StartManpage(man_globals, FALSE, TRUE); 1636d36ef34Smrg } 1646d36ef34Smrg return (man_globals->This_Manpage); 1651abf7346Smrg} 1661abf7346Smrg 1671abf7346Smrg/* Function Name: InitPsuedoGlobals 1686d36ef34Smrg * Description: Initializes the pseudo global variables. 1691abf7346Smrg * Arguments: none. 1701abf7346Smrg * Returns: a pointer to a new pseudo globals structure. 1711abf7346Smrg */ 1721abf7346Smrg 1736d36ef34SmrgManpageGlobals * 1741abf7346SmrgInitPsuedoGlobals(void) 1751abf7346Smrg{ 1766d36ef34Smrg ManpageGlobals *man_globals; 1776d36ef34Smrg 1786d36ef34Smrg /* 1796d36ef34Smrg * Allocate necessary memory. 1806d36ef34Smrg */ 1816d36ef34Smrg 1826d36ef34Smrg man_globals = 1836d36ef34Smrg (ManpageGlobals *) XtCalloc(ONE, (Cardinal) sizeof(ManpageGlobals)); 1846d36ef34Smrg if (!man_globals) 1856d36ef34Smrg return NULL; 1866d36ef34Smrg 1876d36ef34Smrg man_globals->search_widget = NULL; 1886d36ef34Smrg man_globals->section_name = (char **) XtMalloc((Cardinal) (sections * 1896d36ef34Smrg sizeof(char *))); 1906d36ef34Smrg man_globals->manpagewidgets.box = (Widget *) XtCalloc((Cardinal) sections, 1916d36ef34Smrg (Cardinal) 1926d36ef34Smrg sizeof(Widget)); 1936d36ef34Smrg 1946d36ef34Smrg /* Initialize the number of screens that will be shown */ 1956d36ef34Smrg 1966d36ef34Smrg man_globals->both_shown = resources.both_shown_initial; 1976d36ef34Smrg 1986d36ef34Smrg return (man_globals); 1991abf7346Smrg} 2006d36ef34Smrg 2011abf7346Smrg/* Function Name: CreateManpageWidget 2021abf7346Smrg * Description: Creates a new manual page widget. 2031abf7346Smrg * Arguments: man_globals - a new man_globals structure. 2041abf7346Smrg * name - name of this shell widget instance. 2051abf7346Smrg * full_instance - if true then create a full manpage, 2061abf7346Smrg * otherwise create stripped down version 2071abf7346Smrg * used for help. 2081abf7346Smrg * Returns: none 2091abf7346Smrg */ 2101abf7346Smrg 2111abf7346Smrg#define MANPAGEARGS 10 2121abf7346Smrg 2131abf7346Smrgvoid 2146d36ef34SmrgCreateManpageWidget(ManpageGlobals * man_globals, 215ae5a67adSmrg String name, Boolean full_instance) 2161abf7346Smrg{ 2176d36ef34Smrg Arg arglist[MANPAGEARGS]; /* An argument list for widget creation */ 2186d36ef34Smrg Cardinal num_args; /* The number of arguments in the list. */ 2196d36ef34Smrg Widget mytop, pane, hpane, mysections; /* Widgets */ 2206d36ef34Smrg ManPageWidgets *mpw = &(man_globals->manpagewidgets); 2216d36ef34Smrg 2226d36ef34Smrg num_args = (Cardinal) 0; 2236d36ef34Smrg XtSetArg(arglist[num_args], XtNwidth, default_width); 2246d36ef34Smrg num_args++; 2256d36ef34Smrg XtSetArg(arglist[num_args], XtNheight, default_height); 2266d36ef34Smrg num_args++; 2276d36ef34Smrg 2286d36ef34Smrg mytop = XtCreatePopupShell(name, topLevelShellWidgetClass, initial_widget, 2296d36ef34Smrg arglist, num_args); 2306d36ef34Smrg 2316d36ef34Smrg man_globals->This_Manpage = mytop; /* pointer to root widget of Manualpage. */ 2326d36ef34Smrg num_args = 0; 2336d36ef34Smrg if (full_instance) 2346d36ef34Smrg XtSetArg(arglist[num_args], XtNiconPixmap, 2356d36ef34Smrg XCreateBitmapFromData(XtDisplay(mytop), XtScreen(mytop)->root, 2366d36ef34Smrg (const char *) icon_open_bits, 2376d36ef34Smrg icon_open_width, icon_open_height)); 2386d36ef34Smrg else 2396d36ef34Smrg XtSetArg(arglist[num_args], XtNiconPixmap, 2406d36ef34Smrg XCreateBitmapFromData(XtDisplay(mytop), XtScreen(mytop)->root, 2416d36ef34Smrg (const char *) icon_help_bits, 2426d36ef34Smrg icon_help_width, icon_help_height)); 2436d36ef34Smrg num_args++; 2446d36ef34Smrg XtSetValues(mytop, arglist, num_args); 2451abf7346Smrg 2466d36ef34Smrg pane = XtCreateManagedWidget("vertPane", panedWidgetClass, mytop, NULL, 2476d36ef34Smrg (Cardinal) 0); 2481abf7346Smrg 2491abf7346Smrg/* Create menu bar. */ 2501abf7346Smrg 2516d36ef34Smrg hpane = XtCreateManagedWidget("horizPane", panedWidgetClass, 2526d36ef34Smrg pane, NULL, (Cardinal) 0); 2536d36ef34Smrg num_args = 0; 2546d36ef34Smrg XtSetArg(arglist[num_args], XtNmenuName, OPTION_MENU); 2556d36ef34Smrg num_args++; 2566d36ef34Smrg (void) XtCreateManagedWidget("options", menuButtonWidgetClass, 2576d36ef34Smrg hpane, arglist, num_args); 2586d36ef34Smrg 2596d36ef34Smrg CreateOptionMenu(man_globals, mytop); 2606d36ef34Smrg 2616d36ef34Smrg num_args = 0; 2626d36ef34Smrg XtSetArg(arglist[num_args], XtNmenuName, SECTION_MENU); 2636d36ef34Smrg num_args++; 2646d36ef34Smrg mysections = XtCreateManagedWidget("sections", menuButtonWidgetClass, 2656d36ef34Smrg hpane, arglist, num_args); 2666d36ef34Smrg 2676d36ef34Smrg XtSetArg(arglist[0], XtNlabel, SHOW_BOTH); 2686d36ef34Smrg XtSetValues(man_globals->both_screens_entry, arglist, (Cardinal) 1); 2696d36ef34Smrg 2706d36ef34Smrg if (full_instance) { 2716d36ef34Smrg MakeSearchWidget(man_globals, mytop); 2726d36ef34Smrg CreateSectionMenu(man_globals, mytop); 2736d36ef34Smrg MakeSaveWidgets(man_globals, mytop); 2746d36ef34Smrg } 2756d36ef34Smrg else { 2766d36ef34Smrg XtSetSensitive(mysections, FALSE); 2776d36ef34Smrg XtSetArg(arglist[0], XtNsensitive, FALSE); 2786d36ef34Smrg XtSetValues(man_globals->dir_entry, arglist, ONE); 2796d36ef34Smrg XtSetValues(man_globals->manpage_entry, arglist, ONE); 2806d36ef34Smrg XtSetValues(man_globals->help_entry, arglist, ONE); 2816d36ef34Smrg XtSetValues(man_globals->search_entry, arglist, ONE); 2826d36ef34Smrg XtSetValues(man_globals->both_screens_entry, arglist, ONE); 2836d36ef34Smrg } 2841abf7346Smrg 2851abf7346Smrg 2866d36ef34Smrg man_globals->label = XtCreateManagedWidget("manualTitle", labelWidgetClass, 2876d36ef34Smrg hpane, NULL, (Cardinal) 0); 2881abf7346Smrg 2891abf7346Smrg/* Create Directory */ 2901abf7346Smrg 2916d36ef34Smrg if (full_instance) { 2926d36ef34Smrg num_args = 0; 2936d36ef34Smrg XtSetArg(arglist[num_args], XtNallowVert, TRUE); 2946d36ef34Smrg num_args++; 2956d36ef34Smrg 2966d36ef34Smrg mpw->directory = XtCreateWidget(DIRECTORY_NAME, viewportWidgetClass, 2976d36ef34Smrg pane, arglist, num_args); 2986d36ef34Smrg 2996d36ef34Smrg man_globals->current_directory = INITIAL_DIR; 3006d36ef34Smrg MakeDirectoryBox(man_globals, mpw->directory, 3016d36ef34Smrg mpw->box + man_globals->current_directory, 3026d36ef34Smrg man_globals->current_directory); 3036d36ef34Smrg XtManageChild(mpw->box[man_globals->current_directory]); 3046d36ef34Smrg } 3051abf7346Smrg 3061abf7346Smrg/* Create Manpage */ 3071abf7346Smrg 3086d36ef34Smrg mpw->manpage = XtCreateWidget(MANUALPAGE, scrollByLineWidgetClass, 3096d36ef34Smrg pane, NULL, (Cardinal) 0); 3101abf7346Smrg 3111abf7346Smrg} 3121abf7346Smrg 3131abf7346Smrg/* Function Name: StartManpage 3141abf7346Smrg * Description: Starts up a new manpage. 3156d36ef34Smrg * Arguments: man_globals - the pseudo globals variable. 3161abf7346Smrg * help - is this a help file? 3171abf7346Smrg * page - Is there a page to display? 3181abf7346Smrg * Returns: none. 3191abf7346Smrg */ 3201abf7346Smrg 3211abf7346Smrgstatic void 3221abf7346SmrgStartManpage(ManpageGlobals * man_globals, Boolean help, Boolean page) 3231abf7346Smrg{ 3246d36ef34Smrg Widget dir = man_globals->manpagewidgets.directory; 3256d36ef34Smrg Widget manpage = man_globals->manpagewidgets.manpage; 3266d36ef34Smrg Widget label = man_globals->label; 3276d36ef34Smrg Arg arglist[1]; 3281abf7346Smrg 3296d36ef34Smrg/* 3301abf7346Smrg * If there is a helpfile then put up both screens if both_show is set. 3311abf7346Smrg */ 3321abf7346Smrg 3336d36ef34Smrg if (page || help) { 3346d36ef34Smrg if (help) 3356d36ef34Smrg strcpy(man_globals->manpage_title, "Xman Help"); 3366d36ef34Smrg 3376d36ef34Smrg if (man_globals->both_shown) { 3386d36ef34Smrg XtManageChild(dir); 3396d36ef34Smrg man_globals->dir_shown = TRUE; 3406d36ef34Smrg 3416d36ef34Smrg XtSetArg(arglist[0], XtNpreferredPaneSize, 3426d36ef34Smrg resources.directory_height); 3436d36ef34Smrg XtSetValues(dir, arglist, (Cardinal) 1); 3446d36ef34Smrg 3456d36ef34Smrg XtSetArg(arglist[0], XtNsensitive, FALSE); 3466d36ef34Smrg XtSetValues(man_globals->manpage_entry, arglist, ONE); 3476d36ef34Smrg XtSetValues(man_globals->dir_entry, arglist, ONE); 3486d36ef34Smrg 3496d36ef34Smrg XtSetArg(arglist[0], XtNlabel, SHOW_ONE); 3506d36ef34Smrg XtSetValues(man_globals->both_screens_entry, arglist, ONE); 3516d36ef34Smrg ChangeLabel(label, 3526d36ef34Smrg man_globals->section_name[man_globals-> 3536d36ef34Smrg current_directory]); 3546d36ef34Smrg } 3556d36ef34Smrg else { 3566d36ef34Smrg ChangeLabel(label, man_globals->manpage_title); 3576d36ef34Smrg } 3586d36ef34Smrg XtManageChild(manpage); 3596d36ef34Smrg man_globals->dir_shown = FALSE; 3601abf7346Smrg } 3611abf7346Smrg/* 3621abf7346Smrg * Since There is file to display, put up directory and do not allow change 3631abf7346Smrg * to manpage, show both, or help. 3641abf7346Smrg */ 3656d36ef34Smrg else { 3666d36ef34Smrg XtManageChild(dir); 3676d36ef34Smrg man_globals->dir_shown = TRUE; 3686d36ef34Smrg XtSetArg(arglist[0], XtNsensitive, FALSE); 3696d36ef34Smrg XtSetValues(man_globals->manpage_entry, arglist, ONE); 3706d36ef34Smrg XtSetValues(man_globals->help_entry, arglist, ONE); 3716d36ef34Smrg XtSetValues(man_globals->both_screens_entry, arglist, ONE); 3726d36ef34Smrg man_globals->both_shown = FALSE; 3736d36ef34Smrg ChangeLabel(label, 3746d36ef34Smrg man_globals->section_name[man_globals->current_directory]); 3756d36ef34Smrg } 3761abf7346Smrg 3771abf7346Smrg/* 3781abf7346Smrg * Start 'er up, and change the cursor. 3791abf7346Smrg */ 3801abf7346Smrg 3816d36ef34Smrg XtRealizeWidget(man_globals->This_Manpage); 3826d36ef34Smrg SaveGlobals(man_globals->This_Manpage, man_globals); 3836d36ef34Smrg XtMapWidget(man_globals->This_Manpage); 3846d36ef34Smrg AddCursor(man_globals->This_Manpage, resources.cursors.manpage); 3856d36ef34Smrg XtSetArg(arglist[0], XtNtransientFor, man_globals->This_Manpage); 3866d36ef34Smrg XtSetValues(XtParent(man_globals->standby), arglist, (Cardinal) 1); 3876d36ef34Smrg XtSetValues(XtParent(man_globals->save), arglist, (Cardinal) 1); 3886d36ef34Smrg XtRealizeWidget(XtParent(man_globals->standby)); 3896d36ef34Smrg XtRealizeWidget(XtParent(man_globals->save)); 3906d36ef34Smrg AddCursor(XtParent(man_globals->standby), resources.cursors.top); 3916d36ef34Smrg AddCursor(XtParent(man_globals->save), resources.cursors.top); 3921abf7346Smrg 3931abf7346Smrg/* 3941abf7346Smrg * Set up ICCCM delete window. 3951abf7346Smrg */ 3966d36ef34Smrg XtOverrideTranslations 3976d36ef34Smrg (man_globals->This_Manpage, 3986d36ef34Smrg XtParseTranslationTable("<Message>WM_PROTOCOLS: RemoveThisManpage()")); 3996d36ef34Smrg (void) XSetWMProtocols(XtDisplay(man_globals->This_Manpage), 4006d36ef34Smrg XtWindow(man_globals->This_Manpage), 4016d36ef34Smrg &wm_delete_window, 1); 4021abf7346Smrg 4031abf7346Smrg} 4041abf7346Smrg 4051abf7346Smrg/* Function Name: MenuDestroy 4061abf7346Smrg * Description: free's data associated with menu when it is destroyed. 4071abf7346Smrg * Arguments: w - menu widget. 4081abf7346Smrg * free_me - data to free. 4091abf7346Smrg * junk - not used. 4101abf7346Smrg * Returns: none. 4111abf7346Smrg */ 4121abf7346Smrg 4131abf7346Smrg/* ARGSUSED */ 4141abf7346Smrgstatic void 4151abf7346SmrgMenuDestroy(Widget w, XtPointer free_me, XtPointer junk) 4161abf7346Smrg{ 4176d36ef34Smrg XtFree((char *) free_me); 4181abf7346Smrg} 4191abf7346Smrg 4201abf7346Smrg/* Function Name: CreateOptionMenu 4211abf7346Smrg * Description: Create the option menu. 4221abf7346Smrg * Arguments: man_globals - the manual page globals. 4231abf7346Smrg * parent - the button that activates the menu. 4241abf7346Smrg * Returns: none. 4251abf7346Smrg */ 4261abf7346Smrg 4271abf7346Smrgstatic void 4281abf7346SmrgCreateOptionMenu(ManpageGlobals * man_globals, Widget parent) 4291abf7346Smrg{ 4306d36ef34Smrg Widget menu, entry; 4316d36ef34Smrg int i; 4326d36ef34Smrg static const char *option_names[] = { /* Names of the buttons. */ 4336d36ef34Smrg DIRECTORY, 4346d36ef34Smrg MANPAGE, 4356d36ef34Smrg HELP, 4366d36ef34Smrg SEARCH, 4376d36ef34Smrg BOTH_SCREENS, 4386d36ef34Smrg REMOVE_MANPAGE, 4396d36ef34Smrg OPEN_MANPAGE, 4406d36ef34Smrg SHOW_VERSION, 4416d36ef34Smrg QUIT 4426d36ef34Smrg }; 4436d36ef34Smrg 4446d36ef34Smrg menu = XtCreatePopupShell(OPTION_MENU, simpleMenuWidgetClass, parent, 4456d36ef34Smrg NULL, (Cardinal) 0); 4466d36ef34Smrg man_globals->option_menu = menu; 4476d36ef34Smrg 4486d36ef34Smrg for (i = 0; i < NUM_OPTIONS; i++) { 4496d36ef34Smrg entry = XtCreateManagedWidget(option_names[i], smeBSBObjectClass, 4506d36ef34Smrg menu, NULL, ZERO); 4516d36ef34Smrg XtAddCallback(entry, XtNcallback, OptionCallback, 4526d36ef34Smrg (caddr_t) man_globals); 4536d36ef34Smrg switch (i) { 4546d36ef34Smrg case 0: 4556d36ef34Smrg man_globals->dir_entry = entry; 4566d36ef34Smrg break; 4576d36ef34Smrg case 1: 4586d36ef34Smrg man_globals->manpage_entry = entry; 4596d36ef34Smrg break; 4606d36ef34Smrg case 2: 4616d36ef34Smrg man_globals->help_entry = entry; 4626d36ef34Smrg break; 4636d36ef34Smrg case 3: 4646d36ef34Smrg man_globals->search_entry = entry; 4656d36ef34Smrg break; 4666d36ef34Smrg case 4: 4676d36ef34Smrg man_globals->both_screens_entry = entry; 4686d36ef34Smrg break; 4696d36ef34Smrg case 5: 4706d36ef34Smrg man_globals->remove_entry = entry; 4716d36ef34Smrg break; 4726d36ef34Smrg case 6: 4736d36ef34Smrg man_globals->open_entry = entry; 4746d36ef34Smrg break; 4756d36ef34Smrg case 7: 4766d36ef34Smrg man_globals->version_entry = entry; 4776d36ef34Smrg break; 4786d36ef34Smrg case 8: 4796d36ef34Smrg man_globals->quit_entry = entry; 4806d36ef34Smrg break; 4816d36ef34Smrg default: 4826d36ef34Smrg Error(("CreateOptionMenu: Unknown id=%d\n", i)); 4836d36ef34Smrg break; 4846d36ef34Smrg } 4851abf7346Smrg } 4861abf7346Smrg 4871abf7346Smrg} 4881abf7346Smrg 4891abf7346Smrg/* Function Name: CreateSectionMenu 4901abf7346Smrg * Description: Create the Section menu. 4911abf7346Smrg * Arguments: man_globals - the manual page globals. 4921abf7346Smrg * parent - the button that activates the menu. 4931abf7346Smrg * Returns: none. 4941abf7346Smrg */ 4951abf7346Smrg 4961abf7346Smrgstatic void 4971abf7346SmrgCreateSectionMenu(ManpageGlobals * man_globals, Widget parent) 4981abf7346Smrg{ 4996d36ef34Smrg Widget menu, entry; 5006d36ef34Smrg int i; 5016d36ef34Smrg MenuStruct *menu_struct; 5026d36ef34Smrg Arg args[1]; 5036d36ef34Smrg Cardinal num_args; 5046d36ef34Smrg char entry_name[BUFSIZ]; 5056d36ef34Smrg 5066d36ef34Smrg menu = XtCreatePopupShell(SECTION_MENU, simpleMenuWidgetClass, parent, 5076d36ef34Smrg NULL, (Cardinal) 0); 5086d36ef34Smrg 5096d36ef34Smrg for (i = 0; i < sections; i++) { 5106d36ef34Smrg num_args = 0; 5116d36ef34Smrg XtSetArg(args[num_args], XtNlabel, manual[i].blabel); 5126d36ef34Smrg num_args++; 5136d36ef34Smrg snprintf(entry_name, sizeof(entry_name), "section%d", i); 5146d36ef34Smrg 5156d36ef34Smrg entry = XtCreateManagedWidget(entry_name, smeBSBObjectClass, 5166d36ef34Smrg menu, args, num_args); 5176d36ef34Smrg menu_struct = (MenuStruct *) XtMalloc(sizeof(MenuStruct)); 5186d36ef34Smrg menu_struct->data = (caddr_t) man_globals; 5196d36ef34Smrg menu_struct->number = i; 5206d36ef34Smrg XtAddCallback(entry, XtNcallback, DirPopupCallback, 5216d36ef34Smrg (caddr_t) menu_struct); 5226d36ef34Smrg XtAddCallback(entry, XtNdestroyCallback, MenuDestroy, 5236d36ef34Smrg (caddr_t) menu_struct); 5241abf7346Smrg 5256d36ef34Smrg } 5261abf7346Smrg} 5271abf7346Smrg 5281abf7346Smrg/* Function Name: CreateList 5291abf7346Smrg * Description: this function prints a label in the directory list 5301abf7346Smrg * Arguments: section - the manual section. 5311abf7346Smrg * Returns: none 5321abf7346Smrg */ 5331abf7346Smrg 5341abf7346Smrgstatic char ** 5351abf7346SmrgCreateList(int section) 5361abf7346Smrg{ 5376d36ef34Smrg char **ret_list, **current; 5386d36ef34Smrg int count; 5396d36ef34Smrg 5406d36ef34Smrg ret_list = (char **) XtMalloc((manual[section].nentries + 1) * 5416d36ef34Smrg sizeof(char *)); 5426d36ef34Smrg 5436d36ef34Smrg for (current = ret_list, count = 0; count < manual[section].nentries; 5446d36ef34Smrg count++, current++) 5456d36ef34Smrg *current = CreateManpageName(manual[section].entries[count], section, 5466d36ef34Smrg manual[section].flags); 5476d36ef34Smrg 5486d36ef34Smrg *current = NULL; /* NULL terminate the list. */ 5496d36ef34Smrg return (ret_list); 5501abf7346Smrg} 5511abf7346Smrg 5521abf7346Smrg/* Function Name: MakeDirectoryBox 5531abf7346Smrg * Description: make a directory box. 5546d36ef34Smrg * Arguments: man_globals - the pseudo global structure for each manpage. 5551abf7346Smrg * parent - this guys parent widget. 5561abf7346Smrg * dir_disp - the directory display widget. 5571abf7346Smrg * section - the section number. 5581abf7346Smrg * Returns: none. 5591abf7346Smrg */ 5601abf7346Smrg 5611abf7346Smrgvoid 5626d36ef34SmrgMakeDirectoryBox(ManpageGlobals * man_globals, Widget parent, Widget * dir_disp, 5636d36ef34Smrg int section) 5641abf7346Smrg{ 5656d36ef34Smrg Arg arglist[10]; 5666d36ef34Smrg Cardinal num_args; 5676d36ef34Smrg char *name, label_name[BUFSIZ]; 5686d36ef34Smrg 5696d36ef34Smrg if (*dir_disp != NULL) /* If we have one, don't make another. */ 5706d36ef34Smrg return; 5716d36ef34Smrg 5726d36ef34Smrg name = manual[section].blabel; /* Set the section name */ 5736d36ef34Smrg snprintf(label_name, sizeof(label_name), "Directory of: %s", name); 5746d36ef34Smrg man_globals->section_name[section] = XtNewString(label_name); 5756d36ef34Smrg 5766d36ef34Smrg num_args = 0; 5776d36ef34Smrg XtSetArg(arglist[num_args], XtNlist, CreateList(section)); 5786d36ef34Smrg num_args++; 5796d36ef34Smrg XtSetArg(arglist[num_args], XtNfont, resources.fonts.directory); 5806d36ef34Smrg num_args++; 5816d36ef34Smrg 5826d36ef34Smrg *dir_disp = XtCreateWidget(DIRECTORY_NAME, listWidgetClass, parent, 5836d36ef34Smrg arglist, num_args); 5846d36ef34Smrg 5856d36ef34Smrg XtAddCallback(*dir_disp, XtNcallback, 5866d36ef34Smrg DirectoryHandler, (caddr_t) man_globals); 5871abf7346Smrg} 5881abf7346Smrg 5891abf7346Smrg/* Function Name: MakeSaveWidgets. 5906d36ef34Smrg * Description: This functions creates two popup widgets, the please 5911abf7346Smrg * standby widget and the would you like to save widget. 5926d36ef34Smrg * Arguments: man_globals - the pseudo globals structure for each man page 5931abf7346Smrg * parent - the realized parent for both popups. 5941abf7346Smrg * Returns: none. 5951abf7346Smrg */ 5961abf7346Smrg 5971abf7346Smrgvoid 5986d36ef34SmrgMakeSaveWidgets(ManpageGlobals * man_globals, Widget parent) 5991abf7346Smrg{ 6006d36ef34Smrg Widget shell, dialog; /* misc. widgets. */ 6016d36ef34Smrg Arg warg[1]; 6026d36ef34Smrg Cardinal n = 0; 6031abf7346Smrg 6041abf7346Smrg/* make the please stand by popup widget. */ 6056d36ef34Smrg if (XtIsRealized(parent)) { 6066d36ef34Smrg XtSetArg(warg[0], XtNtransientFor, parent); 6076d36ef34Smrg n++; 6086d36ef34Smrg } 6096d36ef34Smrg shell = XtCreatePopupShell("pleaseStandBy", transientShellWidgetClass, 6106d36ef34Smrg parent, warg, (Cardinal) n); 6116d36ef34Smrg 6126d36ef34Smrg man_globals->standby = XtCreateManagedWidget("label", labelWidgetClass, 6136d36ef34Smrg shell, NULL, (Cardinal) 0); 6146d36ef34Smrg 6156d36ef34Smrg man_globals->save = XtCreatePopupShell("likeToSave", 6166d36ef34Smrg transientShellWidgetClass, 6176d36ef34Smrg parent, warg, n); 6186d36ef34Smrg 6196d36ef34Smrg dialog = XtCreateManagedWidget("dialog", dialogWidgetClass, 6206d36ef34Smrg man_globals->save, NULL, (Cardinal) 0); 6216d36ef34Smrg 6226d36ef34Smrg XawDialogAddButton(dialog, FILE_SAVE, NULL, NULL); 6236d36ef34Smrg XawDialogAddButton(dialog, CANCEL_FILE_SAVE, NULL, NULL); 6246d36ef34Smrg 6256d36ef34Smrg if (XtIsRealized(parent)) { 6266d36ef34Smrg XtRealizeWidget(shell); 6276d36ef34Smrg AddCursor(shell, resources.cursors.top); 6286d36ef34Smrg XtRealizeWidget(man_globals->save); 6296d36ef34Smrg AddCursor(man_globals->save, resources.cursors.top); 6306d36ef34Smrg } 6311abf7346Smrg} 6321abf7346Smrg 6331abf7346Smrg/* Function Name: FormUpWidgets 6341abf7346Smrg * Description: Sizes widgets to look nice. 6351abf7346Smrg * Arguments: parent - the common parent of all the widgets. 636da4a0041Smrg * full_size - array of widget names that will be full size. 637da4a0041Smrg * half_size - array of widget names that will be half size. 6381abf7346Smrg * Returns: none 6391abf7346Smrg */ 6401abf7346Smrg 6411abf7346Smrgvoid 6426d36ef34SmrgFormUpWidgets(Widget parent, const char **full_size, const char **half_size) 6431abf7346Smrg{ 6446d36ef34Smrg Widget *full_widgets, *half_widgets, *temp, long_widget; 6456d36ef34Smrg Dimension longest, length, b_width; 6466d36ef34Smrg int interior_dist; 6476d36ef34Smrg Arg arglist[2]; 6486d36ef34Smrg 6496d36ef34Smrg full_widgets = ConvertNamesToWidgets(parent, full_size); 6506d36ef34Smrg half_widgets = ConvertNamesToWidgets(parent, half_size); 6516d36ef34Smrg 6526d36ef34Smrg long_widget = NULL; 6536d36ef34Smrg longest = 0; 6546d36ef34Smrg XtSetArg(arglist[0], XtNwidth, &length); 6556d36ef34Smrg XtSetArg(arglist[1], XtNborderWidth, &b_width); 6561abf7346Smrg 6571abf7346Smrg/* 6581abf7346Smrg * Find Longest widget. 6591abf7346Smrg */ 6601abf7346Smrg 6616d36ef34Smrg for (temp = full_widgets; *temp != (Widget) NULL; temp++) { 6626d36ef34Smrg XtGetValues(*temp, arglist, (Cardinal) 2); 6636d36ef34Smrg length += 2 * b_width; 6646d36ef34Smrg if (length > longest) { 6656d36ef34Smrg longest = length; 6666d36ef34Smrg long_widget = *temp; 6676d36ef34Smrg } 6681abf7346Smrg } 6691abf7346Smrg 6706d36ef34Smrg if (long_widget == (Widget) NULL) { /* Make sure we found one. */ 6716d36ef34Smrg PopupWarning(GetGlobals(parent), 6726d36ef34Smrg "Could not find longest widget, aborting..."); 6736d36ef34Smrg XtFree((char *) full_widgets); 6746d36ef34Smrg XtFree((char *) half_widgets); 6756d36ef34Smrg return; 6766d36ef34Smrg } 6771abf7346Smrg 6781abf7346Smrg/* 6791abf7346Smrg * Set all other full_widgets to this length. 6801abf7346Smrg */ 6811abf7346Smrg 6826d36ef34Smrg for (temp = full_widgets; *temp != (Widget) NULL; temp++) 6836d36ef34Smrg if (long_widget != *temp) { 6846d36ef34Smrg Dimension width, border_width; 6851abf7346Smrg 6866d36ef34Smrg XtSetArg(arglist[0], XtNborderWidth, &border_width); 6876d36ef34Smrg XtGetValues(*temp, arglist, (Cardinal) 1); 6886d36ef34Smrg 6896d36ef34Smrg width = longest - 2 * border_width; 6906d36ef34Smrg XtSetArg(arglist[0], XtNwidth, width); 6916d36ef34Smrg XtSetValues(*temp, arglist, (Cardinal) 1); 6926d36ef34Smrg } 6931abf7346Smrg 6941abf7346Smrg/* 6951abf7346Smrg * Set all the half widgets to the right length. 6961abf7346Smrg */ 6971abf7346Smrg 6986d36ef34Smrg XtSetArg(arglist[0], XtNdefaultDistance, &interior_dist); 6996d36ef34Smrg XtGetValues(parent, arglist, (Cardinal) 1); 7006d36ef34Smrg 7016d36ef34Smrg for (temp = half_widgets; *temp != (Widget) NULL; temp++) { 7026d36ef34Smrg Dimension width, border_width; 7036d36ef34Smrg 7046d36ef34Smrg XtSetArg(arglist[0], XtNborderWidth, &border_width); 7056d36ef34Smrg XtGetValues(*temp, arglist, (Cardinal) 1); 7066d36ef34Smrg 7076d36ef34Smrg width = (int) (longest - interior_dist) / 2 - 2 * border_width; 7086d36ef34Smrg XtSetArg(arglist[0], XtNwidth, width); 7096d36ef34Smrg XtSetValues(*temp, arglist, (Cardinal) 1); 7106d36ef34Smrg } 7116d36ef34Smrg 7126d36ef34Smrg XtFree((char *) full_widgets); 7136d36ef34Smrg XtFree((char *) half_widgets); 7141abf7346Smrg} 7156d36ef34Smrg 7161abf7346Smrg/* Function Name: ConvertNamesToWidgets 7176d36ef34Smrg * Description: Converts a list of names into a list of widgets. 7181abf7346Smrg * Arguments: parent - the common parent of these widgets. 7191abf7346Smrg * names - an array of widget names. 7201abf7346Smrg * Returns: an array of widget id's. 7211abf7346Smrg */ 7221abf7346Smrg 7231abf7346Smrgstatic Widget * 7246d36ef34SmrgConvertNamesToWidgets(Widget parent, const char **names) 7251abf7346Smrg{ 7266d36ef34Smrg const char **temp; 7276d36ef34Smrg Widget *ids, *temp_ids; 7286d36ef34Smrg int count; 7296d36ef34Smrg 7306d36ef34Smrg for (count = 0, temp = names; *temp != NULL; count++, temp++); 7316d36ef34Smrg 7326d36ef34Smrg ids = (Widget *) XtMalloc((count + 1) * sizeof(Widget)); 7336d36ef34Smrg 7346d36ef34Smrg for (temp_ids = ids; *names != NULL; names++, temp_ids++) { 7356d36ef34Smrg *temp_ids = XtNameToWidget(parent, *names); 7366d36ef34Smrg if (*temp_ids == NULL) { 7376d36ef34Smrg char error_buf[BUFSIZ]; 7386d36ef34Smrg 7396d36ef34Smrg snprintf(error_buf, sizeof(error_buf), 7406d36ef34Smrg "Could not find widget named '%s'", *names); 7416d36ef34Smrg PrintError(error_buf); 7426d36ef34Smrg XtFree((char *) ids); 7436d36ef34Smrg return (NULL); 7446d36ef34Smrg } 7451abf7346Smrg } 7466d36ef34Smrg 7476d36ef34Smrg *temp_ids = (Widget) NULL; 7486d36ef34Smrg return (ids); 7491abf7346Smrg} 750