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