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