buttons.c revision ae5a67ad
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#ifdef INCLUDE_XPRINT_SUPPORT 2866d36ef34Smrg XtSetArg(arglist[0], XtNsensitive, True); 2876d36ef34Smrg XtSetValues(man_globals->print_entry, arglist, ONE); 2886d36ef34Smrg#endif /* INCLUDE_XPRINT_SUPPORT */ 2891abf7346Smrg 2906d36ef34Smrg man_globals->label = XtCreateManagedWidget("manualTitle", labelWidgetClass, 2916d36ef34Smrg hpane, NULL, (Cardinal) 0); 2921abf7346Smrg 2931abf7346Smrg/* Create Directory */ 2941abf7346Smrg 2956d36ef34Smrg if (full_instance) { 2966d36ef34Smrg num_args = 0; 2976d36ef34Smrg XtSetArg(arglist[num_args], XtNallowVert, TRUE); 2986d36ef34Smrg num_args++; 2996d36ef34Smrg 3006d36ef34Smrg mpw->directory = XtCreateWidget(DIRECTORY_NAME, viewportWidgetClass, 3016d36ef34Smrg pane, arglist, num_args); 3026d36ef34Smrg 3036d36ef34Smrg man_globals->current_directory = INITIAL_DIR; 3046d36ef34Smrg MakeDirectoryBox(man_globals, mpw->directory, 3056d36ef34Smrg mpw->box + man_globals->current_directory, 3066d36ef34Smrg man_globals->current_directory); 3076d36ef34Smrg XtManageChild(mpw->box[man_globals->current_directory]); 3086d36ef34Smrg } 3091abf7346Smrg 3101abf7346Smrg/* Create Manpage */ 3111abf7346Smrg 3126d36ef34Smrg mpw->manpage = XtCreateWidget(MANUALPAGE, scrollByLineWidgetClass, 3136d36ef34Smrg pane, NULL, (Cardinal) 0); 3141abf7346Smrg 3151abf7346Smrg} 3161abf7346Smrg 3171abf7346Smrg/* Function Name: StartManpage 3181abf7346Smrg * Description: Starts up a new manpage. 3196d36ef34Smrg * Arguments: man_globals - the pseudo globals variable. 3201abf7346Smrg * help - is this a help file? 3211abf7346Smrg * page - Is there a page to display? 3221abf7346Smrg * Returns: none. 3231abf7346Smrg */ 3241abf7346Smrg 3251abf7346Smrgstatic void 3261abf7346SmrgStartManpage(ManpageGlobals * man_globals, Boolean help, Boolean page) 3271abf7346Smrg{ 3286d36ef34Smrg Widget dir = man_globals->manpagewidgets.directory; 3296d36ef34Smrg Widget manpage = man_globals->manpagewidgets.manpage; 3306d36ef34Smrg Widget label = man_globals->label; 3316d36ef34Smrg Arg arglist[1]; 3321abf7346Smrg 3336d36ef34Smrg/* 3341abf7346Smrg * If there is a helpfile then put up both screens if both_show is set. 3351abf7346Smrg */ 3361abf7346Smrg 3376d36ef34Smrg if (page || help) { 3386d36ef34Smrg if (help) 3396d36ef34Smrg strcpy(man_globals->manpage_title, "Xman Help"); 3406d36ef34Smrg 3416d36ef34Smrg if (man_globals->both_shown) { 3426d36ef34Smrg XtManageChild(dir); 3436d36ef34Smrg man_globals->dir_shown = TRUE; 3446d36ef34Smrg 3456d36ef34Smrg XtSetArg(arglist[0], XtNpreferredPaneSize, 3466d36ef34Smrg resources.directory_height); 3476d36ef34Smrg XtSetValues(dir, arglist, (Cardinal) 1); 3486d36ef34Smrg 3496d36ef34Smrg XtSetArg(arglist[0], XtNsensitive, FALSE); 3506d36ef34Smrg XtSetValues(man_globals->manpage_entry, arglist, ONE); 3516d36ef34Smrg XtSetValues(man_globals->dir_entry, arglist, ONE); 3526d36ef34Smrg 3536d36ef34Smrg XtSetArg(arglist[0], XtNlabel, SHOW_ONE); 3546d36ef34Smrg XtSetValues(man_globals->both_screens_entry, arglist, ONE); 3556d36ef34Smrg ChangeLabel(label, 3566d36ef34Smrg man_globals->section_name[man_globals-> 3576d36ef34Smrg current_directory]); 3586d36ef34Smrg } 3596d36ef34Smrg else { 3606d36ef34Smrg ChangeLabel(label, man_globals->manpage_title); 3616d36ef34Smrg } 3626d36ef34Smrg XtManageChild(manpage); 3636d36ef34Smrg man_globals->dir_shown = FALSE; 3641abf7346Smrg } 3651abf7346Smrg/* 3661abf7346Smrg * Since There is file to display, put up directory and do not allow change 3671abf7346Smrg * to manpage, show both, or help. 3681abf7346Smrg */ 3696d36ef34Smrg else { 3706d36ef34Smrg XtManageChild(dir); 3716d36ef34Smrg man_globals->dir_shown = TRUE; 3726d36ef34Smrg XtSetArg(arglist[0], XtNsensitive, FALSE); 3736d36ef34Smrg XtSetValues(man_globals->manpage_entry, arglist, ONE); 3746d36ef34Smrg XtSetValues(man_globals->help_entry, arglist, ONE); 3756d36ef34Smrg XtSetValues(man_globals->both_screens_entry, arglist, ONE); 3766d36ef34Smrg man_globals->both_shown = FALSE; 3776d36ef34Smrg ChangeLabel(label, 3786d36ef34Smrg man_globals->section_name[man_globals->current_directory]); 3796d36ef34Smrg } 3801abf7346Smrg 3811abf7346Smrg/* 3821abf7346Smrg * Start 'er up, and change the cursor. 3831abf7346Smrg */ 3841abf7346Smrg 3856d36ef34Smrg XtRealizeWidget(man_globals->This_Manpage); 3866d36ef34Smrg SaveGlobals(man_globals->This_Manpage, man_globals); 3876d36ef34Smrg XtMapWidget(man_globals->This_Manpage); 3886d36ef34Smrg AddCursor(man_globals->This_Manpage, resources.cursors.manpage); 3896d36ef34Smrg XtSetArg(arglist[0], XtNtransientFor, man_globals->This_Manpage); 3906d36ef34Smrg XtSetValues(XtParent(man_globals->standby), arglist, (Cardinal) 1); 3916d36ef34Smrg XtSetValues(XtParent(man_globals->save), arglist, (Cardinal) 1); 3926d36ef34Smrg XtRealizeWidget(XtParent(man_globals->standby)); 3936d36ef34Smrg XtRealizeWidget(XtParent(man_globals->save)); 3946d36ef34Smrg AddCursor(XtParent(man_globals->standby), resources.cursors.top); 3956d36ef34Smrg AddCursor(XtParent(man_globals->save), resources.cursors.top); 3961abf7346Smrg 3971abf7346Smrg/* 3981abf7346Smrg * Set up ICCCM delete window. 3991abf7346Smrg */ 4006d36ef34Smrg XtOverrideTranslations 4016d36ef34Smrg (man_globals->This_Manpage, 4026d36ef34Smrg XtParseTranslationTable("<Message>WM_PROTOCOLS: RemoveThisManpage()")); 4036d36ef34Smrg (void) XSetWMProtocols(XtDisplay(man_globals->This_Manpage), 4046d36ef34Smrg XtWindow(man_globals->This_Manpage), 4056d36ef34Smrg &wm_delete_window, 1); 4061abf7346Smrg 4071abf7346Smrg} 4081abf7346Smrg 4091abf7346Smrg/* Function Name: MenuDestroy 4101abf7346Smrg * Description: free's data associated with menu when it is destroyed. 4111abf7346Smrg * Arguments: w - menu widget. 4121abf7346Smrg * free_me - data to free. 4131abf7346Smrg * junk - not used. 4141abf7346Smrg * Returns: none. 4151abf7346Smrg */ 4161abf7346Smrg 4171abf7346Smrg/* ARGSUSED */ 4181abf7346Smrgstatic void 4191abf7346SmrgMenuDestroy(Widget w, XtPointer free_me, XtPointer junk) 4201abf7346Smrg{ 4216d36ef34Smrg XtFree((char *) free_me); 4221abf7346Smrg} 4231abf7346Smrg 4241abf7346Smrg/* Function Name: CreateOptionMenu 4251abf7346Smrg * Description: Create the option menu. 4261abf7346Smrg * Arguments: man_globals - the manual page globals. 4271abf7346Smrg * parent - the button that activates the menu. 4281abf7346Smrg * Returns: none. 4291abf7346Smrg */ 4301abf7346Smrg 4311abf7346Smrgstatic void 4321abf7346SmrgCreateOptionMenu(ManpageGlobals * man_globals, Widget parent) 4331abf7346Smrg{ 4346d36ef34Smrg Widget menu, entry; 4356d36ef34Smrg int i; 4366d36ef34Smrg static const char *option_names[] = { /* Names of the buttons. */ 4376d36ef34Smrg DIRECTORY, 4386d36ef34Smrg MANPAGE, 4396d36ef34Smrg HELP, 4406d36ef34Smrg SEARCH, 4416d36ef34Smrg BOTH_SCREENS, 4426d36ef34Smrg REMOVE_MANPAGE, 4436d36ef34Smrg OPEN_MANPAGE, 4441abf7346Smrg#ifdef INCLUDE_XPRINT_SUPPORT 4456d36ef34Smrg PRINT_MANPAGE, 4466d36ef34Smrg#endif /* INCLUDE_XPRINT_SUPPORT */ 4476d36ef34Smrg SHOW_VERSION, 4486d36ef34Smrg QUIT 4496d36ef34Smrg }; 4506d36ef34Smrg 4516d36ef34Smrg menu = XtCreatePopupShell(OPTION_MENU, simpleMenuWidgetClass, parent, 4526d36ef34Smrg NULL, (Cardinal) 0); 4536d36ef34Smrg man_globals->option_menu = menu; 4546d36ef34Smrg 4556d36ef34Smrg for (i = 0; i < NUM_OPTIONS; i++) { 4566d36ef34Smrg entry = XtCreateManagedWidget(option_names[i], smeBSBObjectClass, 4576d36ef34Smrg menu, NULL, ZERO); 4586d36ef34Smrg XtAddCallback(entry, XtNcallback, OptionCallback, 4596d36ef34Smrg (caddr_t) man_globals); 4606d36ef34Smrg switch (i) { 4616d36ef34Smrg case 0: 4626d36ef34Smrg man_globals->dir_entry = entry; 4636d36ef34Smrg break; 4646d36ef34Smrg case 1: 4656d36ef34Smrg man_globals->manpage_entry = entry; 4666d36ef34Smrg break; 4676d36ef34Smrg case 2: 4686d36ef34Smrg man_globals->help_entry = entry; 4696d36ef34Smrg break; 4706d36ef34Smrg case 3: 4716d36ef34Smrg man_globals->search_entry = entry; 4726d36ef34Smrg break; 4736d36ef34Smrg case 4: 4746d36ef34Smrg man_globals->both_screens_entry = entry; 4756d36ef34Smrg break; 4766d36ef34Smrg case 5: 4776d36ef34Smrg man_globals->remove_entry = entry; 4786d36ef34Smrg break; 4796d36ef34Smrg case 6: 4806d36ef34Smrg man_globals->open_entry = entry; 4816d36ef34Smrg break; 4821abf7346Smrg#ifdef INCLUDE_XPRINT_SUPPORT 4836d36ef34Smrg case 7: 4846d36ef34Smrg man_globals->print_entry = entry; 4856d36ef34Smrg break; 4866d36ef34Smrg case 8: 4876d36ef34Smrg man_globals->version_entry = entry; 4886d36ef34Smrg break; 4896d36ef34Smrg case 9: 4906d36ef34Smrg man_globals->quit_entry = entry; 4916d36ef34Smrg break; 4926d36ef34Smrg#else /* !INCLUDE_XPRINT_SUPPORT */ 4936d36ef34Smrg case 7: 4946d36ef34Smrg man_globals->version_entry = entry; 4956d36ef34Smrg break; 4966d36ef34Smrg case 8: 4976d36ef34Smrg man_globals->quit_entry = entry; 4986d36ef34Smrg break; 4996d36ef34Smrg#endif /* !INCLUDE_XPRINT_SUPPORT */ 5006d36ef34Smrg default: 5016d36ef34Smrg Error(("CreateOptionMenu: Unknown id=%d\n", i)); 5026d36ef34Smrg break; 5036d36ef34Smrg } 5041abf7346Smrg } 5051abf7346Smrg 5061abf7346Smrg#ifdef INCLUDE_XPRINT_SUPPORT 5076d36ef34Smrg XtVaSetValues(man_globals->print_entry, XtNsensitive, FALSE, NULL); 5086d36ef34Smrg#endif /* INCLUDE_XPRINT_SUPPORT */ 5091abf7346Smrg} 5101abf7346Smrg 5111abf7346Smrg/* Function Name: CreateSectionMenu 5121abf7346Smrg * Description: Create the Section menu. 5131abf7346Smrg * Arguments: man_globals - the manual page globals. 5141abf7346Smrg * parent - the button that activates the menu. 5151abf7346Smrg * Returns: none. 5161abf7346Smrg */ 5171abf7346Smrg 5181abf7346Smrgstatic void 5191abf7346SmrgCreateSectionMenu(ManpageGlobals * man_globals, Widget parent) 5201abf7346Smrg{ 5216d36ef34Smrg Widget menu, entry; 5226d36ef34Smrg int i; 5236d36ef34Smrg MenuStruct *menu_struct; 5246d36ef34Smrg Arg args[1]; 5256d36ef34Smrg Cardinal num_args; 5266d36ef34Smrg char entry_name[BUFSIZ]; 5276d36ef34Smrg 5286d36ef34Smrg menu = XtCreatePopupShell(SECTION_MENU, simpleMenuWidgetClass, parent, 5296d36ef34Smrg NULL, (Cardinal) 0); 5306d36ef34Smrg 5316d36ef34Smrg for (i = 0; i < sections; i++) { 5326d36ef34Smrg num_args = 0; 5336d36ef34Smrg XtSetArg(args[num_args], XtNlabel, manual[i].blabel); 5346d36ef34Smrg num_args++; 5356d36ef34Smrg snprintf(entry_name, sizeof(entry_name), "section%d", i); 5366d36ef34Smrg 5376d36ef34Smrg entry = XtCreateManagedWidget(entry_name, smeBSBObjectClass, 5386d36ef34Smrg menu, args, num_args); 5396d36ef34Smrg menu_struct = (MenuStruct *) XtMalloc(sizeof(MenuStruct)); 5406d36ef34Smrg menu_struct->data = (caddr_t) man_globals; 5416d36ef34Smrg menu_struct->number = i; 5426d36ef34Smrg XtAddCallback(entry, XtNcallback, DirPopupCallback, 5436d36ef34Smrg (caddr_t) menu_struct); 5446d36ef34Smrg XtAddCallback(entry, XtNdestroyCallback, MenuDestroy, 5456d36ef34Smrg (caddr_t) menu_struct); 5461abf7346Smrg 5476d36ef34Smrg } 5481abf7346Smrg} 5491abf7346Smrg 5501abf7346Smrg/* Function Name: CreateList 5511abf7346Smrg * Description: this function prints a label in the directory list 5521abf7346Smrg * Arguments: section - the manual section. 5531abf7346Smrg * Returns: none 5541abf7346Smrg */ 5551abf7346Smrg 5561abf7346Smrgstatic char ** 5571abf7346SmrgCreateList(int section) 5581abf7346Smrg{ 5596d36ef34Smrg char **ret_list, **current; 5606d36ef34Smrg int count; 5616d36ef34Smrg 5626d36ef34Smrg ret_list = (char **) XtMalloc((manual[section].nentries + 1) * 5636d36ef34Smrg sizeof(char *)); 5646d36ef34Smrg 5656d36ef34Smrg for (current = ret_list, count = 0; count < manual[section].nentries; 5666d36ef34Smrg count++, current++) 5676d36ef34Smrg *current = CreateManpageName(manual[section].entries[count], section, 5686d36ef34Smrg manual[section].flags); 5696d36ef34Smrg 5706d36ef34Smrg *current = NULL; /* NULL terminate the list. */ 5716d36ef34Smrg return (ret_list); 5721abf7346Smrg} 5731abf7346Smrg 5741abf7346Smrg/* Function Name: MakeDirectoryBox 5751abf7346Smrg * Description: make a directory box. 5766d36ef34Smrg * Arguments: man_globals - the pseudo global structure for each manpage. 5771abf7346Smrg * parent - this guys parent widget. 5781abf7346Smrg * dir_disp - the directory display widget. 5791abf7346Smrg * section - the section number. 5801abf7346Smrg * Returns: none. 5811abf7346Smrg */ 5821abf7346Smrg 5831abf7346Smrgvoid 5846d36ef34SmrgMakeDirectoryBox(ManpageGlobals * man_globals, Widget parent, Widget * dir_disp, 5856d36ef34Smrg int section) 5861abf7346Smrg{ 5876d36ef34Smrg Arg arglist[10]; 5886d36ef34Smrg Cardinal num_args; 5896d36ef34Smrg char *name, label_name[BUFSIZ]; 5906d36ef34Smrg 5916d36ef34Smrg if (*dir_disp != NULL) /* If we have one, don't make another. */ 5926d36ef34Smrg return; 5936d36ef34Smrg 5946d36ef34Smrg name = manual[section].blabel; /* Set the section name */ 5956d36ef34Smrg snprintf(label_name, sizeof(label_name), "Directory of: %s", name); 5966d36ef34Smrg man_globals->section_name[section] = XtNewString(label_name); 5976d36ef34Smrg 5986d36ef34Smrg num_args = 0; 5996d36ef34Smrg XtSetArg(arglist[num_args], XtNlist, CreateList(section)); 6006d36ef34Smrg num_args++; 6016d36ef34Smrg XtSetArg(arglist[num_args], XtNfont, resources.fonts.directory); 6026d36ef34Smrg num_args++; 6036d36ef34Smrg 6046d36ef34Smrg *dir_disp = XtCreateWidget(DIRECTORY_NAME, listWidgetClass, parent, 6056d36ef34Smrg arglist, num_args); 6066d36ef34Smrg 6076d36ef34Smrg XtAddCallback(*dir_disp, XtNcallback, 6086d36ef34Smrg DirectoryHandler, (caddr_t) man_globals); 6091abf7346Smrg} 6101abf7346Smrg 6111abf7346Smrg/* Function Name: MakeSaveWidgets. 6126d36ef34Smrg * Description: This functions creates two popup widgets, the please 6131abf7346Smrg * standby widget and the would you like to save widget. 6146d36ef34Smrg * Arguments: man_globals - the pseudo globals structure for each man page 6151abf7346Smrg * parent - the realized parent for both popups. 6161abf7346Smrg * Returns: none. 6171abf7346Smrg */ 6181abf7346Smrg 6191abf7346Smrgvoid 6206d36ef34SmrgMakeSaveWidgets(ManpageGlobals * man_globals, Widget parent) 6211abf7346Smrg{ 6226d36ef34Smrg Widget shell, dialog; /* misc. widgets. */ 6236d36ef34Smrg Arg warg[1]; 6246d36ef34Smrg Cardinal n = 0; 6251abf7346Smrg 6261abf7346Smrg/* make the please stand by popup widget. */ 6276d36ef34Smrg if (XtIsRealized(parent)) { 6286d36ef34Smrg XtSetArg(warg[0], XtNtransientFor, parent); 6296d36ef34Smrg n++; 6306d36ef34Smrg } 6316d36ef34Smrg shell = XtCreatePopupShell("pleaseStandBy", transientShellWidgetClass, 6326d36ef34Smrg parent, warg, (Cardinal) n); 6336d36ef34Smrg 6346d36ef34Smrg man_globals->standby = XtCreateManagedWidget("label", labelWidgetClass, 6356d36ef34Smrg shell, NULL, (Cardinal) 0); 6366d36ef34Smrg 6376d36ef34Smrg man_globals->save = XtCreatePopupShell("likeToSave", 6386d36ef34Smrg transientShellWidgetClass, 6396d36ef34Smrg parent, warg, n); 6406d36ef34Smrg 6416d36ef34Smrg dialog = XtCreateManagedWidget("dialog", dialogWidgetClass, 6426d36ef34Smrg man_globals->save, NULL, (Cardinal) 0); 6436d36ef34Smrg 6446d36ef34Smrg XawDialogAddButton(dialog, FILE_SAVE, NULL, NULL); 6456d36ef34Smrg XawDialogAddButton(dialog, CANCEL_FILE_SAVE, NULL, NULL); 6466d36ef34Smrg 6476d36ef34Smrg if (XtIsRealized(parent)) { 6486d36ef34Smrg XtRealizeWidget(shell); 6496d36ef34Smrg AddCursor(shell, resources.cursors.top); 6506d36ef34Smrg XtRealizeWidget(man_globals->save); 6516d36ef34Smrg AddCursor(man_globals->save, resources.cursors.top); 6526d36ef34Smrg } 6531abf7346Smrg} 6541abf7346Smrg 6551abf7346Smrg/* Function Name: FormUpWidgets 6561abf7346Smrg * Description: Sizes widgets to look nice. 6571abf7346Smrg * Arguments: parent - the common parent of all the widgets. 658da4a0041Smrg * full_size - array of widget names that will be full size. 659da4a0041Smrg * half_size - array of widget names that will be half size. 6601abf7346Smrg * Returns: none 6611abf7346Smrg */ 6621abf7346Smrg 6631abf7346Smrgvoid 6646d36ef34SmrgFormUpWidgets(Widget parent, const char **full_size, const char **half_size) 6651abf7346Smrg{ 6666d36ef34Smrg Widget *full_widgets, *half_widgets, *temp, long_widget; 6676d36ef34Smrg Dimension longest, length, b_width; 6686d36ef34Smrg int interior_dist; 6696d36ef34Smrg Arg arglist[2]; 6706d36ef34Smrg 6716d36ef34Smrg full_widgets = ConvertNamesToWidgets(parent, full_size); 6726d36ef34Smrg half_widgets = ConvertNamesToWidgets(parent, half_size); 6736d36ef34Smrg 6746d36ef34Smrg long_widget = NULL; 6756d36ef34Smrg longest = 0; 6766d36ef34Smrg XtSetArg(arglist[0], XtNwidth, &length); 6776d36ef34Smrg XtSetArg(arglist[1], XtNborderWidth, &b_width); 6781abf7346Smrg 6791abf7346Smrg/* 6801abf7346Smrg * Find Longest widget. 6811abf7346Smrg */ 6821abf7346Smrg 6836d36ef34Smrg for (temp = full_widgets; *temp != (Widget) NULL; temp++) { 6846d36ef34Smrg XtGetValues(*temp, arglist, (Cardinal) 2); 6856d36ef34Smrg length += 2 * b_width; 6866d36ef34Smrg if (length > longest) { 6876d36ef34Smrg longest = length; 6886d36ef34Smrg long_widget = *temp; 6896d36ef34Smrg } 6901abf7346Smrg } 6911abf7346Smrg 6926d36ef34Smrg if (long_widget == (Widget) NULL) { /* Make sure we found one. */ 6936d36ef34Smrg PopupWarning(GetGlobals(parent), 6946d36ef34Smrg "Could not find longest widget, aborting..."); 6956d36ef34Smrg XtFree((char *) full_widgets); 6966d36ef34Smrg XtFree((char *) half_widgets); 6976d36ef34Smrg return; 6986d36ef34Smrg } 6991abf7346Smrg 7001abf7346Smrg/* 7011abf7346Smrg * Set all other full_widgets to this length. 7021abf7346Smrg */ 7031abf7346Smrg 7046d36ef34Smrg for (temp = full_widgets; *temp != (Widget) NULL; temp++) 7056d36ef34Smrg if (long_widget != *temp) { 7066d36ef34Smrg Dimension width, border_width; 7071abf7346Smrg 7086d36ef34Smrg XtSetArg(arglist[0], XtNborderWidth, &border_width); 7096d36ef34Smrg XtGetValues(*temp, arglist, (Cardinal) 1); 7106d36ef34Smrg 7116d36ef34Smrg width = longest - 2 * border_width; 7126d36ef34Smrg XtSetArg(arglist[0], XtNwidth, width); 7136d36ef34Smrg XtSetValues(*temp, arglist, (Cardinal) 1); 7146d36ef34Smrg } 7151abf7346Smrg 7161abf7346Smrg/* 7171abf7346Smrg * Set all the half widgets to the right length. 7181abf7346Smrg */ 7191abf7346Smrg 7206d36ef34Smrg XtSetArg(arglist[0], XtNdefaultDistance, &interior_dist); 7216d36ef34Smrg XtGetValues(parent, arglist, (Cardinal) 1); 7226d36ef34Smrg 7236d36ef34Smrg for (temp = half_widgets; *temp != (Widget) NULL; temp++) { 7246d36ef34Smrg Dimension width, border_width; 7256d36ef34Smrg 7266d36ef34Smrg XtSetArg(arglist[0], XtNborderWidth, &border_width); 7276d36ef34Smrg XtGetValues(*temp, arglist, (Cardinal) 1); 7286d36ef34Smrg 7296d36ef34Smrg width = (int) (longest - interior_dist) / 2 - 2 * border_width; 7306d36ef34Smrg XtSetArg(arglist[0], XtNwidth, width); 7316d36ef34Smrg XtSetValues(*temp, arglist, (Cardinal) 1); 7326d36ef34Smrg } 7336d36ef34Smrg 7346d36ef34Smrg XtFree((char *) full_widgets); 7356d36ef34Smrg XtFree((char *) half_widgets); 7361abf7346Smrg} 7376d36ef34Smrg 7381abf7346Smrg/* Function Name: ConvertNamesToWidgets 7396d36ef34Smrg * Description: Converts a list of names into a list of widgets. 7401abf7346Smrg * Arguments: parent - the common parent of these widgets. 7411abf7346Smrg * names - an array of widget names. 7421abf7346Smrg * Returns: an array of widget id's. 7431abf7346Smrg */ 7441abf7346Smrg 7451abf7346Smrgstatic Widget * 7466d36ef34SmrgConvertNamesToWidgets(Widget parent, const char **names) 7471abf7346Smrg{ 7486d36ef34Smrg const char **temp; 7496d36ef34Smrg Widget *ids, *temp_ids; 7506d36ef34Smrg int count; 7516d36ef34Smrg 7526d36ef34Smrg for (count = 0, temp = names; *temp != NULL; count++, temp++); 7536d36ef34Smrg 7546d36ef34Smrg ids = (Widget *) XtMalloc((count + 1) * sizeof(Widget)); 7556d36ef34Smrg 7566d36ef34Smrg for (temp_ids = ids; *names != NULL; names++, temp_ids++) { 7576d36ef34Smrg *temp_ids = XtNameToWidget(parent, *names); 7586d36ef34Smrg if (*temp_ids == NULL) { 7596d36ef34Smrg char error_buf[BUFSIZ]; 7606d36ef34Smrg 7616d36ef34Smrg snprintf(error_buf, sizeof(error_buf), 7626d36ef34Smrg "Could not find widget named '%s'", *names); 7636d36ef34Smrg PrintError(error_buf); 7646d36ef34Smrg XtFree((char *) ids); 7656d36ef34Smrg return (NULL); 7666d36ef34Smrg } 7671abf7346Smrg } 7686d36ef34Smrg 7696d36ef34Smrg *temp_ids = (Widget) NULL; 7706d36ef34Smrg return (ids); 7711abf7346Smrg} 772