2eb8e5ce0af8d160654cddba421997257dc825c0
[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, form, text, buttons; 
13
14 static String fallback[] = {
15     /* text window resources */
16     "*text.resizable: true",
17     "*text.resize: ResizeBoth",
18     NULL,
19 };
20
21 struct cmd_t {
22     char *name;
23     void (*callback)(Widget, XtPointer, XtPointer);
24     int enable;
25     Widget widget;
26 };
27
28 static void quit_proc(Widget w, XtPointer client_data, XtPointer call_data)
29
30     XtDestroyApplicationContext (app_context);
31     exit (0);
32 }
33
34 static void noargs_proc(Widget w, XtPointer client_data, XtPointer call_data)
35 /* use this for commands that take no arguments */
36 {
37     /* currently a stub */
38 }
39
40 static struct cmd_t commands[] = {
41     {"Phasers",         NULL,           0},
42     {"Torpedo",         NULL,           0},
43     {"Move",            NULL,           0},
44     {"Shields",         NULL,           0},
45     {"Dock",            noargs_proc,    0},
46     {"Damages",         noargs_proc,    0},
47     {"Chart",           noargs_proc,    0},
48     {"Impulse",         NULL,           0},
49     {"Rest",            NULL,           0},
50     {"Warp",            NULL,           0},
51     {"Score",           noargs_proc,    0},
52     {"Sensors",         noargs_proc,    OPTION_PLANETS},
53     {"Orbit",           noargs_proc,    OPTION_PLANETS},
54     {"Transport",       noargs_proc,    OPTION_PLANETS},
55     {"Mine",            noargs_proc,    OPTION_PLANETS},
56     {"Crystals",        noargs_proc,    OPTION_PLANETS},
57     {"Shuttle",         noargs_proc,    OPTION_PLANETS},
58     {"Planets",         noargs_proc,    OPTION_PLANETS},
59     {"Report",          noargs_proc,    0},
60     {"Computer",        noargs_proc,    0},
61     {"Emexit",          noargs_proc,    0},
62     {"Probe",           NULL,           OPTION_PROBE},
63     {"Save",            NULL,           0},
64     {"Abandon",         noargs_proc,    0},
65     {"Destruct",        noargs_proc,    0},
66     {"Deathray",        noargs_proc,    0},
67     {"Mayday",          noargs_proc,    0},
68     {"Quit",            quit_proc,      0},
69     {"Help",            noargs_proc,    0},
70 };
71
72 int main(int argc, char **argv)
73
74     struct cmd_t *cp;
75
76     toplevel = XtVaOpenApplication(&app_context, "sst2k", NULL, 0, &argc,
77                                     argv, fallback, 
78                                     applicationShellWidgetClass,
79                                     XtNallowShellResize, True, NULL);
80     form = XtVaCreateManagedWidget("form", formWidgetClass, toplevel, NULL);
81     /* the command window */
82     text = XtVaCreateManagedWidget("text", asciiTextWidgetClass, form, 
83                                    XtNwidth, 400, XtNheight, 200,
84                                    NULL);
85     XtVaSetValues(text, XtNeditType,XawtextRead, XtNdisplayCaret,False, NULL);
86     /* The button panel */
87     buttons  = XtVaCreateManagedWidget("form", 
88                                        boxWidgetClass, form,
89                                        XtNfromVert, text, 
90                                        XtNorientation, XtorientHorizontal,
91                                        NULL); 
92     for (cp = commands; cp < commands + sizeof(commands)/sizeof(commands[0]); cp++) {
93         cp->widget = XtVaCreateManagedWidget(cp->name, 
94                                              commandWidgetClass, buttons, 
95                                              XtNlabel, cp->name,
96                                              NULL);
97         if (cp->callback)
98             XtAddCallback (cp->widget, XtNcallback, cp->callback, NULL);
99     }
100     XtRealizeWidget(toplevel);
101     XtAppMainLoop(app_context);
102     /* loop may be interrupted */
103     XtDestroyApplicationContext(app_context);
104     exit(0);
105 }