1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
|
/* Help for the X11 interface to Xconq.
Copyright (C) 1991-1995, 1997 Stanley T. Shebs.
Xconq is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version. See the file COPYING. */
#include "conq.h"
#include "xconq.h"
void update_help PARAMS ((Side *side));
/* (node stack code should go to ui.[ch]) */
#define NODESTACKSIZE 100
static void describe_map PARAMS ((int arg, char *key, TextBuffer *buf));
static void help_next_callback PARAMS ((Widget w, XtPointer client_data,
XtPointer call_data));
static void help_prev_callback PARAMS ((Widget w, XtPointer client_data,
XtPointer call_data));
static void help_back_callback PARAMS ((Widget w, XtPointer client_data,
XtPointer call_data));
static void help_close_callback PARAMS ((Widget w, XtPointer client_data,
XtPointer call_data));
static void interp_help_command PARAMS ((Side *side, int ch));
static void jump_to_help_node PARAMS ((Side *side, int i));
static void help_topic_callback PARAMS ((Widget w, XtPointer dummy,
XawListReturnStruct *list));
static char **nodetitles;
static void
describe_map(arg, key, buf)
int arg;
char *key;
TextBuffer *buf;
{
#define SCB(s) tbcat(buf,s)
SCB("In move mode:\n");
SCB(" The next unit that can do anything will be selected automatically.\n");
SCB(" Left-click on a destination to move the selected unit there.\n");
SCB(" To select a unit, center-click it.\n");
SCB("\n");
SCB("In look mode:\n");
SCB(" Left-click on a unit to make the current one.\n");
SCB(" To move it, right-click, use 'm'ove command or 'z' to switch back ");
SCB("to move mode.\n");
SCB("\n");
#ifdef DESIGNERS
SCB("In design mode:\n");
SCB(" Left-click to perform the tool-specific action: add unit or paint ");
SCB("terrain, population, or feature.\n");
SCB(" Shift-left-click to perform the tool-specific current object ");
SCB("selection: pick current unit type, terrain type, side, or feature.\n");
SCB("\n");
#endif /* DESIGNERS */
SCB("In any mode:\n");
SCB(" Center-click on a unit or cell to make the current one.\n");
SCB(" Drag-shift-center-click to measure distance (gasp! hold down Shift, ");
SCB("press center button at origin, drag to destination, release button ");
SCB("and Shift).\n");
SCB(" Right-click on a destination to move the selected unit there.\n");
SCB(" Move the mouse while holding Meta to change the current cell.\n");
SCB(" Press a keypad key to scroll the look.\n");
#undef SCB
}
static void
help_topic_callback (w, dummy, list)
Widget w;
XtPointer dummy;
XawListReturnStruct *list;
{
Side *side;
if (!find_side_via_widget(w, &side))
return;
jump_to_help_node(side, list->list_index);
}
static void
jump_to_help_node(side, i)
Side *side;
int i;
{
i = i % side->ui->nodenumber;
if (i < 0)
i += side->ui->nodenumber;
XawListHighlight(side->ui->help_topicList, i);
side->ui->curhelpnode = side->ui->nodestack[i];
side->ui->nodestackpos = i;
update_help(side);
}
void
create_help(side)
Side *side;
{
int i;
HelpNode *hnp;
add_help_node("map", describe_map, 0, first_help_node);
/* initialize node stack */
if (side->ui->nodestack == NULL)
side->ui->nodestack =
(HelpNode **) xmalloc(1000 * sizeof(HelpNode *));
for (i = 0, hnp = first_help_node;
hnp && (hnp != first_help_node || i == 0); hnp = hnp->next) {
side->ui->nodestack[i++] = hnp;
}
side->ui->nodenumber = i;
nodetitles = (char **) xmalloc((side->ui->nodenumber+1)*sizeof(char *));
for (i = 0; i < side->ui->nodenumber; i++) {
nodetitles[i] = side->ui->nodestack[i]->key;
}
nodetitles[side->ui->nodenumber] = NULL;
side->ui->help_shell =
XtVaCreatePopupShell("helpShell", topLevelShellWidgetClass,
side->ui->shell, NULL);
side->ui->help_form =
XtVaCreateManagedWidget("form", formWidgetClass,
side->ui->help_shell, NULL);
side->ui->help_title =
XtVaCreateManagedWidget("title", labelWidgetClass, side->ui->help_form,
XtNlabel, "",
XtNtop, XawChainTop,
XtNbottom, XawChainTop,
XtNleft, XawChainLeft,
XtNright, XawChainRight,
NULL);
side->ui->help_topicPort =
XtVaCreateManagedWidget("topicPort", viewportWidgetClass, side->ui->help_form,
XtNallowVert, True,
XtNfromVert, side->ui->help_title,
XtNtop, XawChainTop,
XtNbottom, XawChainBottom,
XtNleft, XawChainLeft,
XtNright, XawChainLeft,
NULL);
side->ui->help_topicList =
XtVaCreateManagedWidget("topicList", listWidgetClass, side->ui->help_topicPort,
XtNbottom, XawChainTop,
XtNverticalList, True,
XtNforceColumns, True,
XtNdefaultColumns, 1,
NULL);
XawListChange(side->ui->help_topicList,
nodetitles, side->ui->nodenumber, 0, True);
XtAddCallback(side->ui->help_topicList, XtNcallback,
(XtCallbackProc) help_topic_callback, (XtPointer) NULL);
side->ui->help_text =
XtVaCreateManagedWidget("text", asciiTextWidgetClass, side->ui->help_form,
XtNdisplayCaret, False,
XtNeditType, XawtextRead,
/* XtNscrollHorizontal, XawtextScrollWhenNeeded, */
XtNscrollVertical, XawtextScrollAlways,
XtNwrap, XawtextWrapWord,
XtNfromVert, side->ui->help_title,
XtNfromHoriz, side->ui->help_topicPort,
XtNtop, XawChainTop,
XtNbottom, XawChainBottom,
XtNleft, XawChainLeft,
XtNright, XawChainRight,
NULL);
side->ui->help_next =
XtVaCreateManagedWidget("next", commandWidgetClass, side->ui->help_form,
XtNlabel, "Next",
XtNfromVert, side->ui->help_text,
XtNtop, XawChainBottom,
XtNbottom, XawChainBottom,
XtNleft, XawChainLeft,
XtNright, XawChainLeft,
NULL);
XtAddCallback(side->ui->help_next, XtNcallback, help_next_callback, NULL);
side->ui->help_prev =
XtVaCreateManagedWidget("prev", commandWidgetClass, side->ui->help_form,
XtNlabel, "Prev",
XtNfromHoriz, side->ui->help_next,
XtNfromVert, side->ui->help_text,
XtNtop, XawChainBottom,
XtNbottom, XawChainBottom,
XtNleft, XawChainLeft,
XtNright, XawChainLeft,
NULL);
XtAddCallback(side->ui->help_prev, XtNcallback, help_prev_callback, NULL);
side->ui->help_back =
XtVaCreateManagedWidget("back", commandWidgetClass, side->ui->help_form,
XtNlabel, "Back",
XtNfromHoriz, side->ui->help_prev,
XtNfromVert, side->ui->help_text,
XtNtop, XawChainBottom,
XtNbottom, XawChainBottom,
XtNleft, XawChainLeft,
XtNright, XawChainLeft,
NULL);
XtAddCallback(side->ui->help_back, XtNcallback, help_back_callback, NULL);
side->ui->help_close =
XtVaCreateManagedWidget("close", commandWidgetClass, side->ui->help_form,
XtNlabel, "Close",
XtNfromHoriz, side->ui->help_back,
XtNfromVert, side->ui->help_text,
XtNtop, XawChainBottom,
XtNbottom, XawChainBottom,
XtNleft, XawChainLeft,
XtNright, XawChainLeft,
NULL);
XtAddCallback(side->ui->help_close, XtNcallback, help_close_callback, NULL);
XtRealizeWidget(side->ui->help_shell);
/* which is the most useful help page to display at startup? */
jump_to_help_node (side, 2);
}
static void
help_next_callback(w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
Side *side;
if (find_side_via_widget(w, &side)) {
interp_help_command(side, 'n');
}
}
static void
help_prev_callback(w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
Side *side;
if (find_side_via_widget(w, &side)) {
interp_help_command(side, 'p');
}
}
static void
help_back_callback(w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
Side *side;
if (find_side_via_widget(w, &side)) {
interp_help_command(side, 'b');
}
}
static void
help_close_callback(w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
Side *side;
if (find_side_via_widget(w, &side)) {
popdown_help(side);
}
}
/* Keyboard command interpretation for the help window. */
static void
interp_help_command(side, ch)
Side *side;
int ch;
{
int i;
switch (ch) {
case 'n':
i = side->ui->nodestackpos+1;
break;
case 'p':
i = side->ui->nodestackpos-1;
break;
case 'b':
if (side->ui->nodestackpos <= 0) {
beep(side);
return;
}
i = side->ui->nodestackpos-1;
break;
case 't':
i = 0;
break;
default:
abort(); /* should never happen */
}
jump_to_help_node(side, i);
}
void
update_help(side)
Side *side;
{
char *keystr, *helpstr;
if (!side->ui->help_shell)
return;
if (side->ui->curhelpnode == NULL)
return; /* (should never happen?) */
/* Update the topic title widget. */
keystr = side->ui->curhelpnode->key;
if (keystr == NULL)
keystr = "???";
nargs = 0;
XtSetArg(tmpargs[nargs], XtNlabel, keystr); nargs++;
XtSetValues(side->ui->help_title, tmpargs, nargs);
/* Update the help info proper. */
helpstr = get_help_text(side->ui->curhelpnode);
if (helpstr == NULL)
helpstr = "???";
/* This shouldn't be necessary, but apparently some text widgets
go berserk when handed zero-length strings. (This happens
on several different platforms.) */
if (strlen(helpstr) == 0)
helpstr = " ";
nargs = 0;
XtSetArg(tmpargs[nargs], XtNstring, helpstr); nargs++;
XtSetArg(tmpargs[nargs], XtNlength, strlen(helpstr)); nargs++;
XtSetArg(tmpargs[nargs], XtNinsertPosition, 0); nargs++;
XtSetValues(side->ui->help_text, tmpargs, nargs);
}
void
popup_help(side)
Side *side;
{
if (!side->ui->help_shell) {
create_help(side);
update_help(side);
XSetWMProtocols(side->ui->dpy, XtWindow(side->ui->help_shell),
&side->ui->kill_atom, 1);
XtOverrideTranslations(side->ui->help_shell,
XtParseTranslationTable("<Message>WM_PROTOCOLS: wm-quit()"));
}
XtPopup(side->ui->help_shell, XtGrabNone);
/* Expose event will cause window contents to be drawn now. */
}
void
popdown_help(side)
Side *side;
{
if (side->ui->help_shell)
XtPopdown(side->ui->help_shell);
}
|