More settings into fallback.
[super-star-trek.git] / src / xio.c
1 #include <stdlib.h>
2 #include <X11/Intrinsic.h>
3 #include <X11/StringDefs.h>
4 #include <X11/Shell.h>
5 #include <X11/Xaw/Box.h>
6 #include <X11/Xaw/Form.h>
7 #include <X11/Xaw/Command.h>
8 #include <X11/Xaw/AsciiText.h>
9 #include "sst.h"
10
11 static XtAppContext app_context;
12 static Widget toplevel, text, form; 
13 static Widget navigation, weapons, planets, misc; 
14 static Widget navlabel, weaplabel, planlabel, misclabel;
15
16 static String fallback[] = {
17     "*text.resizable: true",
18     "*text.resize: ResizeBoth",
19     "*text.width: 640",
20     "*text.height: 200",
21     "*text.autoFill: True",
22     "*text.scrollVertical: Always",
23     "*text.scrollHorizontal: WhenNeeded",
24     "*text.displayCaret: True",
25     "*navigation.fromVert: text",
26     "*navigation.borderWidth: 0",
27     "*navlabel.label: Navigation:   ",
28     "*navlabel.borderWidth: 0",
29     "*weapons.fromVert: navigation",
30     "*weapons.borderWidth: 0",
31     "*weaplabel.label: Weapons:      ",
32     "*weaplabel.borderWidth: 0",
33     "*planets.fromVert: weapons",
34     "*planets.borderWidth: 0",
35     "*planlabel.label: Planets:      ",
36     "*planlabel.borderWidth: 0",
37     "*misc.fromVert: planets",
38     "*misc.borderWidth: 0",
39     "*misclabel.label: Miscellaneous:",
40     "*misclabel.borderWidth: 0",
41     NULL,
42 };
43
44 struct cmd_t {
45     char *name;
46     void (*callback)(Widget, XtPointer, XtPointer);
47     Widget *parent;
48     int enable;
49     Widget widget;
50
51 };
52
53 static void quit_proc(Widget w, XtPointer client_data, XtPointer call_data)
54
55     XtDestroyApplicationContext (app_context);
56     exit (0);
57 }
58
59 static void noargs_proc(Widget w, XtPointer client_data, XtPointer call_data)
60 /* use this for commands that take no arguments */
61 {
62     /* currently a stub */
63     printf("Button %s pressed\n", XtName(w));
64 }
65
66 static struct cmd_t commands[] = {
67     {"Move",            NULL,           &navigation,    0},
68     {"Dock",            noargs_proc,    &navigation,    0},
69     {"Chart",           noargs_proc,    &navigation,    0},
70     {"Impulse",         NULL,           &navigation,    0},
71     {"Rest",            NULL,           &navigation,    0},
72     {"Warp",            NULL,           &navigation,    0},
73     {"Probe",           NULL,           &navigation,    OPTION_PROBE},
74
75     {"Phasers",         NULL,           &weapons,       0},
76     {"Torpedo",         NULL,           &weapons,       0},
77     {"Shields",         NULL,           &weapons,       0},
78     {"Damages",         noargs_proc,    &weapons,       0},
79     {"Abandon",         noargs_proc,    &weapons,       0},
80     {"Destruct",        noargs_proc,    &weapons,       0},
81     {"Deathray",        noargs_proc,    &weapons,       0},
82     {"Mayday",          noargs_proc,    &weapons,       0},
83
84     {"Sensors",         noargs_proc,    &planets,       OPTION_PLANETS},
85     {"Orbit",           noargs_proc,    &planets,       OPTION_PLANETS},
86     {"Transport",       noargs_proc,    &planets,       OPTION_PLANETS},
87     {"Mine",            noargs_proc,    &planets,       OPTION_PLANETS},
88     {"Crystals",        noargs_proc,    &planets,       OPTION_PLANETS},
89     {"Shuttle",         noargs_proc,    &planets,       OPTION_PLANETS},
90     {"Planets",         noargs_proc,    &planets,       OPTION_PLANETS},
91
92     {"Score",           noargs_proc,    &misc,          0},
93     {"Report",          noargs_proc,    &misc,          0},
94     {"Computer",        noargs_proc,    &misc,          0},
95     {"Save",            NULL,           &misc,          0},
96     {"Quit",            quit_proc,      &misc,          0},
97     {"Help",            noargs_proc,    &misc,          0},
98 };
99
100 static void instantiate_main(int argc, char **argv)
101
102     struct cmd_t *cp;
103
104     toplevel = XtVaOpenApplication(&app_context, "sst2k", NULL, 0, &argc,
105                                     argv, fallback, 
106                                     applicationShellWidgetClass,
107                                     XtNallowShellResize, True, NULL);
108     form = XtVaCreateManagedWidget("form", formWidgetClass, toplevel, NULL);
109     /* the command window */
110     text = XtVaCreateManagedWidget("text", 
111                                    asciiTextWidgetClass, form,
112                                    XtNeditType, XawtextEdit,
113                                    NULL);
114     /* The button panels */
115     navigation  = XtVaCreateManagedWidget("navigation", 
116                                           boxWidgetClass, form,
117                                           XtNorientation, XtorientHorizontal,
118                                           NULL); 
119     navlabel  = XtVaCreateManagedWidget("navlabel", 
120                                         labelWidgetClass, navigation,
121                                         NULL); 
122     weapons  = XtVaCreateManagedWidget("weapons", 
123                                        boxWidgetClass, form,
124                                        XtNorientation, XtorientHorizontal,
125                                        NULL); 
126     weaplabel  = XtVaCreateManagedWidget("weaplabel", 
127                                          labelWidgetClass, weapons,
128                                          NULL); 
129     planets  = XtVaCreateManagedWidget("planets", 
130                                        boxWidgetClass, form,
131                                        XtNorientation, XtorientHorizontal,
132                                        NULL); 
133     planlabel  = XtVaCreateManagedWidget("planlabel", 
134                                          labelWidgetClass, planets,
135                                          XtNborderWidth, 0,
136                                          NULL); 
137     misc  = XtVaCreateManagedWidget("misc", 
138                                        boxWidgetClass, form,
139                                        XtNorientation, XtorientHorizontal,
140                                        NULL); 
141     misclabel  = XtVaCreateManagedWidget("misclabel", 
142                                          labelWidgetClass, misc,
143                                          NULL); 
144     for (cp = commands; cp < commands + sizeof(commands)/sizeof(commands[0]); cp++) {
145         cp->widget = XtVaCreateManagedWidget(cp->name, 
146                                              commandWidgetClass, 
147                                              *cp->parent, 
148                                              XtNlabel, cp->name,
149                                              NULL);
150         if (cp->callback)
151             XtAddCallback (cp->widget, XtNcallback, cp->callback, NULL);
152     }
153     XtRealizeWidget(toplevel);
154     XtAppMainLoop(app_context);
155     /* loop may be interrupted */
156     XtDestroyApplicationContext(app_context);
157 }
158
159 int main(int argc, char **argv)
160 {
161     instantiate_main(argc, argv);
162     exit(0);
163 }