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

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