1 /*
2  * Copyright (C) 1990 Regents of the University of California.
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and
5  * its documentation for any purpose is hereby granted without fee,
6  * provided that the above copyright notice appear in all copies and that
7  * both that copyright notice and this permission notice appear in
8  * supporting documentation, and that the name of the University of
9  * California not be used in advertising or publicity pertaining to
10  * distribution of the software without specific, written prior
11  * permission.  the University of California makes no representations
12  * about the suitability of this software for any purpose.  It is provided
13  * "as is" without express or implied warranty.
14  */
15 
16 # include <X11/Intrinsic.h>
17 # include <X11/StringDefs.h>
18 # include <X11/Shell.h>
19 # include <X11/Xaw/Form.h>
20 
21 # include <stdio.h>
22 # include <string.h>
23 
24 # include "cdrom_globs.h"
25 # include "debug.h"
26 # include "logo.xbm"
27 
28 XtAppContext	appc;
29 
30 AppData app_data;
31 
32 extern char	*getenv();
33 
34 static Widget	top_shell;
35 Widget	top_form_widget;
36 
37 static XrmOptionDescRec options[] = {
38 { "-file",	".file",	XrmoptionSepArg,	(caddr_t) NULL },
39 { "-device",	".device",	XrmoptionSepArg,	(caddr_t) NULL },
40 { "-debug",	".debug",	XrmoptionNoArg,		(caddr_t) "True" },
41 { "-displayTimer", ".displayTimer", XrmoptionNoArg,	(caddr_t) "True" },
42 { "-volBase",	".volBase",	XrmoptionSepArg,	(caddr_t) 0 },
43 { "-volPcent",	".volPcent",	XrmoptionSepArg,	(caddr_t) 0 },
44 { "-cdInfoDir",	".cdInfoDir",	XrmoptionSepArg,	(caddr_t) NULL },
45 };
46 
47 static XtResource	resources[] = {
48 	{ "file", "File", XtRString, sizeof(String), XtOffsetOf(AppData,file),
49 		  XtRString, (caddr_t) NULL },
50 	{ "device", "Device", XtRString, sizeof(String), XtOffsetOf(AppData,device),
51 		  XtRString, (caddr_t) NULL },
52 	{ "debug", "Debug", XtRBoolean, sizeof(Boolean), XtOffsetOf(AppData,debug),
53 		  XtRBoolean, &app_data.debug },
54 	{ "displayTimer", "DisplayTimer", XtRBoolean, sizeof(Boolean),
55 		  XtOffsetOf(AppData,display_timer), XtRBoolean,
56 		  &app_data.display_timer },
57 	{ "volBase", "VolBase", XtRFloat, sizeof(float),
58 		  XtOffsetOf(AppData,volbase), XtRFloat, &app_data.volbase },
59 	{ "volPcent", "VolPcent", XtRFloat, sizeof(float),
60 		  XtOffsetOf(AppData,volpcent), XtRFloat, &app_data.volpcent },
61 	{ "replayThreshold", "replayThreshold", XtRInt, sizeof(int),
62 		  XtOffsetOf(AppData,replayThreshold), XtRInt,
63 		  &app_data.replayThreshold },
64 	{ "scanSkipInterval", "scanSkipInterval", XtRInt, sizeof(int),
65 		  XtOffsetOf(AppData,scanSkipInterval), XtRInt,
66 		  &app_data.scanSkipInterval },
67 	{ "scanPauseInterval", "scanPauseInterval", XtRFloat, sizeof(float),
68 		  XtOffsetOf(AppData,scanPauseInterval), XtRFloat,
69 		  &app_data.scanPauseInterval },
70 	{ "pauseSkipInterval", "pauseSkipInterval", XtRInt, sizeof(int),
71 		  XtOffsetOf(AppData,pauseSkipInterval), XtRInt,
72 		  &app_data.pauseSkipInterval },
73 	{ "pausePauseInterval", "pausePauseInterval", XtRFloat, sizeof(float),
74 		  XtOffsetOf(AppData,pausePauseInterval), XtRFloat,
75 		  &app_data.pausePauseInterval },
76 	{ "cdInfoDir", "cdInfoDir", XtRString, sizeof(String),
77 		  XtOffsetOf(AppData,cdInfoDir), XtRString, (caddr_t) NULL },
78 };
79 
80 Widget
top_setup(argc,argv)81 top_setup(argc, argv)
82 	int		argc;
83 	char		**argv;
84 {
85 	Display		*dpy;
86 
87 	Pixmap		icon_pixmap;
88 	Arg		arg;
89 	char		*s;
90 
91 	/*
92 	 * set default values
93 	 */
94 
95 	app_data.debug = False;
96 	app_data.display_timer = True;
97 	app_data.volbase = 187.0;
98 	app_data.volpcent = 0.267;
99 	app_data.replayThreshold = 4;
100 	app_data.pauseSkipInterval = 15;
101 	app_data.scanSkipInterval = 1;
102 	app_data.scanPauseInterval = 0.062;
103 	app_data.pausePauseInterval = 0.500;
104 
105 	XtToolkitInitialize();
106 
107 	appc = XtCreateApplicationContext();
108 
109 	dpy = XtOpenDisplay(appc, NULL, "xcdplayer", "XCdplayer",
110 			    options, XtNumber(options),
111 			    (Cardinal *) &argc, argv);
112 
113 	if (dpy == NULL) {
114 		fprintf(stderr, "can't open display\n");
115 		exit(1);
116 	}
117 
118 	top_shell = XtAppCreateShell("xcdplayer", "XCdplayer",
119 				     applicationShellWidgetClass,
120 				     dpy, (ArgList) NULL, 0);
121 
122 	icon_pixmap = XCreateBitmapFromData(XtDisplay(top_shell),
123 				RootWindowOfScreen(XtScreen(top_shell)),
124 				logo_bits, logo_width, logo_height);
125 
126 	XtSetArg(arg, XtNiconPixmap, icon_pixmap);
127 	XtSetValues(top_shell, &arg, 1);
128 
129 
130 	(void) XtGetApplicationResources(top_shell, (caddr_t) &app_data,
131 					 resources, XtNumber(resources),
132 					 (ArgList) NULL, 0);
133 
134 	if ((app_data.cdInfoDir == NULL) && ((s=getenv("XCDINFODIR")) != NULL))
135 	    app_data.cdInfoDir = strdup(s);
136 
137 	top_form_widget = XtCreateWidget("mainForm", formWidgetClass,
138 						 top_shell,
139 						 (ArgList) NULL, 0);
140 
141 	return(top_form_widget);
142 }
143 
144 void
top_start()145 top_start() {
146 	XtManageChild(top_form_widget);
147 	XtRealizeWidget(top_shell);
148 }
149