source: trunk/athena/bin/xmore/help.c @ 12350

Revision 12350, 5.1 KB checked in by ghudson, 26 years ago (diff)
Some RCS ID cleanup: delete $Log$ and replace other RCS keywords with $Id$.
Line 
1#ifndef lint
2  static char rcsid_module_c[] = "$Id: help.c,v 1.3 1999-01-22 23:15:43 ghudson Exp $";
3#endif lint
4
5/*      This is the file help.c for the Xmore, a file browsing utility
6 *      built upon Xlib and the XToolkit.
7 *      It Contains: CreateHelp(), PopupHelp(), and PopdownHelp().
8 *     
9 *      Created:        January 19, 1987
10 *      By:             Chris D. Peterson
11 *
12 *      $Id: help.c,v 1.3 1999-01-22 23:15:43 ghudson Exp $
13 *     
14 *      Copyright 1987, 1988 by the Massachusetts Institute of Technology.
15 *
16 *      For further information on copyright and distribution
17 *      see the file mit-copyright.h
18 */
19
20#include "globals.h"
21#include "mit-copyright.h"
22
23#define Y_POS 50
24
25/*      Function Name: CreateHelp.
26 *      Description: This function creates the help widget so that it will be
27 *                   ready to be displayed.
28 *      Arguments:
29 *      Returns: FALSE if it could not create help window.
30 */
31
32Boolean
33CreateHelp()
34{
35  struct stat fileinfo;         /* file information from fstat. */
36  FILE * help_file;             /* The stream of the help file. */
37  char * help_page;             /* The help text strored in memory. */
38  int help_width;               /* The width of the help window. (default). */
39  Arg arglist[10];              /* The arglist */
40  Cardinal num_args;            /* The number of arguments. */
41  Widget pane;                  /* The Vpane, that will contain the help info.
42                                   */
43  static XtCallbackRec Callbacks[] = {
44    { PopdownHelp, NULL },
45    { NULL, NULL },
46  };
47 
48  if (help_widget != NULL)      /* If we already have a help widget.
49                                   then do not create one. */
50    return(TRUE);
51
52/* Open help_file and read it into memory. */
53
54/*
55 * Get file size and allocate a chunk of memory for the file to be
56 * copied into.
57 */
58
59  if( (help_file = fopen(help_file_name, "r")) == NULL ) {
60    PrintWarning("Could not open help file, NO HELP WILL BE AVALIABLE.");
61    return(FALSE);
62  }
63
64  if ( stat(help_file_name, &fileinfo) ) {
65    PrintWarning("Failure in fstat, NO HELP WILL BE AVALIABLE.");
66    return(FALSE);
67  }
68
69  /* leave space for the NULL */
70  help_page = (char *) malloc(fileinfo.st_size + 1);   
71
72  if (help_page == NULL) {
73    PrintWarning(
74      "Could not allocate memory for help file, NO HELP WILL BE AVALIABLE.");
75    return(FALSE);
76  }
77
78/*
79 * Copy the file into memory.
80 */
81 
82  fread(help_page,sizeof(char),fileinfo.st_size,help_file);
83  fclose(help_file);
84   
85/* put NULL at end of buffer. */
86
87  *(help_page + fileinfo.st_size) = '\0';
88
89/*
90 * Help file now loaded in to memory. Create widgets do display it.
91 */
92
93  num_args = 0;
94  XtSetArg(arglist[num_args], XtNallowShellResize, TRUE);
95  num_args++;
96
97  help_widget = XtCreateApplicationShell("help", applicationShellWidgetClass,
98                                   arglist, num_args);
99
100  num_args = 0;
101  help_width = DisplayWidth(XtDisplay(help_widget),
102                            DefaultScreen(XtDisplay(help_widget)));
103  help_width /= 2;
104  XtSetArg(arglist[num_args], XtNwidth, help_width);
105  num_args++;
106
107#if XtSpecificationRelease < 4
108  pane = XtCreateWidget("Help_VPaned",vPanedWidgetClass,help_widget,
109                        arglist,num_args);
110#else
111  pane = XtCreateWidget("Help_Paned",panedWidgetClass,help_widget,
112                        arglist,num_args);
113#endif
114
115  num_args = 0;
116  XtSetArg(arglist[num_args], XtNborderWidth, 0);
117  num_args++;
118  XtSetArg(arglist[num_args], XtNlabel, "Done With Help");
119  num_args++;
120  XtSetArg(arglist[num_args], XtNcallback, Callbacks);
121  num_args++;
122
123  (void) XtCreateManagedWidget("Help_Quit",commandWidgetClass, pane,
124                               arglist, num_args);
125
126  num_args = 0;
127  XtSetArg(arglist[num_args], XtNborderWidth, 0);
128  num_args++;
129  XtSetArg(arglist[num_args], XtNstring, help_page);
130  num_args++;
131#if XtSpecificationRelease < 4
132  XtSetArg(arglist[num_args], XtNtextOptions, scrollVertical);
133  num_args++;
134#else
135  XtSetArg(arglist[num_args],XtNscrollVertical,XawtextScrollAlways);
136  num_args++;
137  XtSetArg(arglist[num_args],XtNscrollHorizontal,XawtextScrollWhenNeeded);
138  num_args++;
139  XtSetArg(arglist[num_args],XtNuseStringInPlace, TRUE);
140  num_args++;
141#endif
142  /* make the text shown a square box. */
143  XtSetArg(arglist[num_args], XtNheight, help_width);
144  num_args++;
145 
146
147#if XtSpecificationRelease < 4
148  (void) XtCreateManagedWidget("Help_Text",asciiStringWidgetClass, pane,
149                               arglist, num_args);
150#else
151  (void) XtCreateManagedWidget("Help_Text",asciiTextWidgetClass, pane,
152                               arglist, num_args);
153#endif
154
155  XtManageChild(pane);
156  XtRealizeWidget(help_widget);
157  AddCursor(help_widget,help_cursor);
158
159  return(TRUE);
160}
161
162/*      Function Name: PopdownHelp
163 *      Description: This function pops down the help widget.
164 *      Arguments: w - the widget we are calling back from.
165 *                 number - (closure) the number to switch on.
166 *                 junk - (call data) not used.
167 *      Returns: none.
168 */
169
170/* ARGSUSED */
171
172void
173PopdownHelp(w,number,junk)
174Widget w;
175caddr_t number,junk;
176{
177  XtPopdown(help_widget);
178}
179
180/*      Function Name: PopupHelp
181 *      Description: This function pops up the help widget, unless no
182 *                   help could be found.
183 *      Arguments: w - the widget we are calling back from.
184 *                 number - (closure) the number to switch on.
185 *                 junk - (call data) not used.
186 *      Returns: none.
187 */
188
189/* ARGSUSED */
190
191void
192PopupHelp(w,number,junk)
193Widget w;
194caddr_t number,junk;
195{
196  if (CreateHelp())
197    XtPopup(help_widget,XtGrabNone);
198}
199
Note: See TracBrowser for help on using the repository browser.