source: trunk/athena/bin/xmore/main.c @ 2969

Revision 2969, 8.1 KB checked in by epeisach, 34 years ago (diff)
Coverted to X11R4
Line 
1#ifndef lint
2  static char rcsid_module_c[] = "$Header: /afs/dev.mit.edu/source/repository/athena/bin/xmore/main.c,v 1.2 1990-05-01 14:48:49 epeisach Exp $";
3#endif lint
4
5/*      This is the file main.c for the Xmore, a file browsing utility
6 *      built upon Xlib and the XToolkit.
7 *      It Contains: main(), Quit(), TextExit(), PrintWarning(), PrintError(),
8 *                   CreateScroll(), CreatePane(), and AddCursor().
9 *     
10 *      Created:        October 22, 1987
11 *      By:             Chris D. Peterson
12 *
13 *      $Source: /afs/dev.mit.edu/source/repository/athena/bin/xmore/main.c,v $
14 *      $Author: epeisach $
15 *      $Header: /afs/dev.mit.edu/source/repository/athena/bin/xmore/main.c,v 1.2 1990-05-01 14:48:49 epeisach Exp $
16 *     
17 *      Copyright 1987, 1988 by the Massachusetts Institute of Technology.
18 *
19 *      For further information on copyright and distribution
20 *      see the file mit-copyright.h
21 */
22
23#include "globals.h"
24#include "mit-copyright.h"
25
26/*      Function Name: main
27 *      Description: This is the main driver for Xman.
28 *      Arguments: argc, argv - the command line arguments.
29 *      Returns: return, what return.
30 */
31
32
33static XtResource resources[] = {
34  {"textFontNormal", XtCFont, XtRFontStruct, sizeof(XFontStruct *),
35     (Cardinal) &(fonts.normal), XtRString, NORMALFONT},
36  {"textFontItalic", XtCFont, XtRFontStruct, sizeof(XFontStruct *),
37     (Cardinal) &(fonts.italic), XtRString, ITALICFONT},
38  {"topCursor", XtCCursor, XtRCursor, sizeof(Cursor),
39     (Cardinal) &main_cursor, XtRString, MAIN_CURSOR},
40  {"helpCursor", XtCCursor, XtRCursor, sizeof(Cursor),
41     (Cardinal) &help_cursor, XtRString, HELP_CURSOR},
42  {"helpFile", XtCFile, XtRString, sizeof(char *),
43     (Cardinal) &(help_file_name), XtRString, HELPFILE},
44};
45
46void
47main(argc,argv)
48char ** argv;
49int argc;
50{
51  Widget top,scroll,pane;       /* The top level widget, and scroll widget,
52                                   and the pane widget.*/
53  FILE * file;
54
55  top = XtInitialize(argv[0],"Topwidget",NULL,(unsigned int) 0,
56                     (Cardinal*) &argc,argv);
57
58  XtGetApplicationResources( (Widget) top, (caddr_t) NULL,
59                            resources, XtNumber(resources),
60                            NULL, (Cardinal) 0);
61  if (!fonts.normal)
62        XtError("failed to get the textFontNormal font");
63  if (!fonts.italic)
64        fonts.italic = fonts.normal;
65
66#ifdef DEBUG
67  printf("debugging mode, snychronizing the X server.\n");
68  XSynchronize( XtDisplay(top), 1);
69#endif
70
71/* Initialize Help. */
72
73  help_widget = NULL;
74
75  if (argc > 1) {
76    if ( (file = fopen(argv[1],"r")) == NULL) {
77      printf("Could not open file -  %s\n",argv[1]);
78      exit(1);
79    }
80    pane = CreatePane(top);
81    scroll = CreateScroll(pane);
82    XtManageChild(pane);
83    InitPage(scroll,file);
84    XtAddEventHandler(scroll,(unsigned int) ButtonPressMask|ButtonReleaseMask,
85                      FALSE, TextExit, NULL);
86    XtRealizeWidget(top);
87    AddCursor(top,main_cursor); /* must be done after realize. */
88    XtMainLoop();
89  }
90    printf("usage: xmore filename\n");
91}
92
93/*      Function Name: CreateScroll
94 *      Description: This function creates the scrollByLineWidget for Xmore.
95 *      Arguments: parent - the parent widget.
96 *      Returns: none.
97 */
98
99Widget
100CreateScroll(parent)
101Widget parent;
102{
103  Widget scroll;                /* The scrollByLine Widget we are creating. */
104  Arg arglist[10];              /* The arglist */
105  Cardinal num_args;            /* The number of arguments in the arglist. */
106  MemoryStruct * memory_struct; /* The memory structure. */
107  int font_height;
108
109  static XtCallbackRec Callback[] = {
110    { PrintPage, NULL },
111    { NULL, NULL },
112  };
113
114  /* find out how tall the font is. */
115
116  font_height = (fonts.normal->max_bounds.ascent +
117                   fonts.normal->max_bounds.descent);
118
119/* Initialize the memory structure. */
120
121  memory_struct = (MemoryStruct *) malloc(sizeof(MemoryStruct));
122  memory_struct->top_line = NULL;
123  memory_struct->top_of_page = NULL;
124 
125  global_memory_struct = memory_struct;
126
127  Callback[0].closure = (caddr_t) memory_struct;
128  num_args = (Cardinal) 0;
129  XtSetArg(arglist[num_args], XtNcallback, Callback);
130  num_args++;
131  XtSetArg(arglist[num_args], XtNfontHeight, font_height);
132  num_args++; 
133  XtSetArg(arglist[num_args], XtNallowVert, TRUE);
134  num_args++; 
135 
136  scroll = XtCreateWidget("ScrolledWidget",scrollByLineWidgetClass,
137                          parent,arglist,num_args);
138  XtManageChild(scroll);
139
140  return(scroll);
141}
142
143/*      Function Name: CreatePane
144 *      Description: This function Creates a vPaned widget with a help
145 *                   button in the top pane.
146 *      Arguments: parent - the parent of the vpane.
147 *      Returns: pane - the Vpaned widget.
148 */
149
150Widget
151CreatePane(parent)
152Widget parent;
153{
154  Widget pane,form,quit,help;   /* Several widget names. */
155  Arg arglist[3];               /* An arglist. */
156  Cardinal num_args;          /* The number of argument in the current list. */
157  int height, height_vert, border_width; /* The sizes of the quit widget. */
158
159  num_args = (Cardinal) 0;
160/* TopLevel overrides but this gives it something to work with. */
161  XtSetArg(arglist[num_args], XtNwidth, DEFAULT_WIDTH);
162  num_args++;
163  XtSetArg(arglist[num_args], XtNheight, DEFAULT_HEIGHT);
164  num_args++;
165
166#if XtSpecificationRelease < 4
167  pane = XtCreateWidget("VPanedTop",vPanedWidgetClass,
168                          parent,arglist, num_args);
169#else
170  pane = XtCreateWidget("PanedTop",panedWidgetClass,
171                          parent,arglist, num_args);
172#endif
173
174  num_args = 0;
175  form = XtCreateWidget("formButtons",formWidgetClass,pane,
176                        arglist,num_args);
177
178  num_args = (Cardinal) 0;
179  quit = XtCreateManagedWidget("Click Here To Quit",commandWidgetClass,
180                               form,arglist,num_args);
181  XtAddCallback(quit, XtNcallback, Quit, NULL);
182
183  XtSetArg(arglist[num_args], XtNfromHoriz, quit);
184  num_args++;
185 
186  help = XtCreateManagedWidget("Click Here For Help",commandWidgetClass,
187                               form,arglist,num_args);
188  XtAddCallback(help, XtNcallback, PopupHelp, NULL);
189
190/*
191 * Mildly confusing method of setting the max paramater for
192 * This pane to be its height.
193 */
194
195  num_args = (Cardinal) 0;
196  XtSetArg(arglist[num_args], XtNheight, &height);
197  num_args++;
198  XtSetArg(arglist[num_args], XtNvertDistance, &height_vert);
199  num_args++;
200  XtSetArg(arglist[num_args], XtNborderWidth, &border_width);
201  num_args++;
202  XtGetValues(quit, arglist, num_args);
203#if XtSpecificationRelease < 4
204  XtPanedSetMinMax( form, 2, height + 2 * (height_vert + border_width) );
205#else
206  XawPanedSetMinMax( form, 2, height + 2 * (height_vert + border_width) );
207#endif
208
209  XtManageChild(form);
210  return(pane);
211}
212
213/*      Function Name: TextExit
214 *      Description: closes the display and quits.
215 *      Arguments: widget - the widget that called the event.
216 *                 junk - closure (not used).
217 *                 event - the event structure.
218 *      Returns: none.
219 */
220
221/* ARGSUSED */
222void
223TextExit(w,junk,event)
224Widget w;
225caddr_t junk;
226XEvent * event;
227{
228  switch(event->type) {
229  case ButtonPress:
230    break;
231  case ButtonRelease:
232    if (event->xbutton.button == 2) {
233      Quit(w,NULL,NULL);
234    }
235    break;
236  default:
237    break;
238  }
239}
240
241/*      Function Name: Quit
242 *      Description: closes the display and quits.
243 *      Arguments: widget - the widget that called the event.
244 *                 junk, garbage - closure and callback (not used).
245 *      Returns: none.
246 */
247
248/* ARGSUSED */
249void
250Quit(w,junk,garbage)
251Widget w;
252caddr_t junk,garbage;
253{
254  XCloseDisplay(XtDisplay(w));
255  exit(0);
256}
257
258/*      Function Name: PrintWarning
259 *      Description: This function prints a warning message to stderr.
260 *      Arguments: string - the specific warning string.
261 *      Returns: none
262 */
263
264void
265PrintWarning(string)
266char * string;
267{
268  fprintf(stderr,"Xmore Warning: %s\n",string);
269}
270
271/*      Function Name: PrintError
272 *      Description: This Function prints an error message and exits.
273 *      Arguments: string - the specific message.
274 *      Returns: none. - exits tho.
275 */
276
277void
278PrintError(string)
279char * string;
280{
281  fprintf(stderr,"Xmore Error: %s\n",string);
282#ifdef DEBUG
283  fprintf(stderr,"\n\nbye,bye\n\n\n\n\nsniff...\n");
284#endif
285  exit(42);
286}
287
288/*      Function Name: AddCursor
289 *      Description: This function adds the cursor to the window.
290 *      Arguments: w - the widget to add the cursor to.
291 *                 cursor - the cursor to add to this widget.
292 *      Returns: none
293 */
294
295void
296AddCursor(w,cursor)
297Widget w;
298Cursor cursor;
299{
300
301  if (!XtIsRealized(w)) {
302    PrintWarning("Widget is not realized, no cursor added.\n");
303    return;
304  }
305  XDefineCursor(XtDisplay(w),XtWindow(w),cursor);
306}
Note: See TracBrowser for help on using the repository browser.