home *** CD-ROM | disk | FTP | other *** search
- /* Commands for the X11 interface to Xconq.
- Copyright (C) 1994, 1995 Massimo Campostrini & 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"
-
- /* Xconq 7.0 printing options front-end.
- Version 0.0 May 1994.
- By Massimo Campostrini <campo@sunthpi3.difi.unipi.it>.
- */
-
- #define N_COMMAND 3
- #define N_CHOICE 1
- #define N_BUTTON (N_COMMAND+N_CHOICE)
- #define N_TOGGLE 6
- #define N_DIALOG 12
- #define N_DIMEN_D 10
- #define N_WIDGET (N_BUTTON+N_TOGGLE+N_DIALOG)
-
- static int choi[N_CHOICE];
- static int flag[N_TOGGLE];
- static double parm[N_DIALOG];
- static int i_metric;
- static Side *ps_side;
-
- static PrintParameters *ps_pp = NULL;
-
- typedef struct a_widgetId {
- String name;
- int newline;
- } WidgetId;
-
- typedef struct a_choice {
- int number;
- String legends[5];
- } Choice;
-
- Choice choices[N_CHOICE] = {
- {3,
- {"no names",
- "interesting names",
- "all names",
- NULL, NULL}
- }
- };
-
- void print_parms PROTO ((void));
- void print_ok PROTO ((void));
- void print_skip PROTO ((void));
- void open_print_help PROTO ((void));
- static void done_print_help ();
-
- int w_comm_ind PROTO ((Widget w));
- void update_values PROTO ((void));
- void hilight_label PROTO ((void));
- void do_dialog PROTO ((Widget wdgt, XEvent *event, String *params, Cardinal *num_params));
- void handle_print_setup_button ();
- void handle_metric_convert ();
- void read_all PROTO ((void));
-
- static XtActionsRec xcps_actions[] = {
- { "DoButton", handle_print_setup_button },
- { "DoMetric", handle_metric_convert },
- { "DoDialog", do_dialog },
- { "DoneHelp", done_print_help },
- };
-
- /* these should go somewhere else. Massimo
- static String fallback_resources[] = {
- "*Dialog*value: 0",
- "*Dialog*value.translations: #override \\n <Key>Return: DoDialog()",
- "*help.Label: \\ help ",
- "*print.Label:\\ print ",
- "*quit.Label: \\ quit ",
- "*names.label: interesting names",
- "*cellSize.label: cell size",
- "*gridSize.label: grid thick.",
- "*pageWidth.label: page width",
- "*pageHeight.label: page height",
- "*topMargin.label: top margin",
- "*bottomMargin.label: bottom margin",
- "*leftMargin.label: left margin",
- "*rightMargin.label: right margin",
- "*terrainGray.label: terrain gray",
- "*enemyGray.label: enemy gray",
- "*borderWidth.label: border thick.",
- "*connWidth.label: conn thick.",
- "*PrintSetupHelp.title: print setup help",
- "*PrintSetupHelp*baseTranslations: #override \
- <Key>Return: DoneHelp()\\n\
- <Key>Escape: DoneHelp()\\n\
- <Btn1Down>: DoneHelp()",
- "*PrintSetupHelp*helpDone.Label: \\ done ",
- NULL,
- }; */
-
- Widget w_shell = NULL, w_comm[N_WIDGET], w_help_shell=NULL;
-
- WidgetId w_table[N_WIDGET] = {
- {"help", 1 },
- {"print", 0 },
- {"quit", 0 },
- {"names", 1 },
- {"coord", 0 },
- {"dither", 0 },
- {"double", 1 },
- {"features", 0 },
- {"summary", 0 },
- {"metric", 0 },
- {"cellSize", 1 },
- {"gridSize", 0 },
- {"borderWidth", 1 },
- {"connWidth", 0 },
- {"pageWidth", 1 },
- {"pageHeight", 0 },
- {"topMargin", 1 },
- {"bottomMargin", 0 },
- {"leftMargin", 1 },
- {"rightMargin", 0 },
- {"terrainGray", 1 },
- {"enemyGray", 0 },
- };
-
- static String helpText =
- "Modify values, then press \"print\" (or \"quit\" to skip printing).\n\
- \n\
- Multiple choices (click to cycle)\n\
- o print unit names: no names, interesting names, all names.\n\
- \n\
- Binary options (dark background = set)\n\
- o coord: print coordinates of map corners\n\
- o dither: use dithering to print terrain gray\n\
- o double: map a pixel into 2x2 pixels wile dithering\n\
- o features: print geographical features\n\
- o summary: print summary of units in cell\n\
- o metric: print distances in centimetres (otherwise in inches)\n\
- \n\
- Numerical options (accept floating-point values)\n\
- o cell size: printed size of hexagonal cells\n\
- o grid thick.: thickness of cell grid (0 to suppress)\n\
- o border/conn thick.: thickness of borders and connections\n\
- o page width/height: dimension of sheets to print on\n\
- o top/bottom/left/right margin: margins of the region where\n\
- cells are printed; labels and titles are printed in the margins\n\
- o border/connection thickness\n\
- o terrain gray: from 0 (black) to 1 (white)\n\
- o enemy gray: from 0 (black) to 1 (white), [not implemented]";
-
- int
- popup_print_setup_dialog(side, pspp)
- Side *side;
- PrintParameters *pspp;
- {
- int i;
- Widget w_form, w_left, w_up, w_oldup;
- WidgetClass class;
- ps_side = side;
-
- XtAppAddActions(thisapp, xcps_actions, XtNumber(xcps_actions));
-
- ps_pp = pspp;
-
- if (!w_shell) {
- w_shell =
- XtVaCreatePopupShell("PrintSetup", topLevelShellWidgetClass,
- side->ui->shell, NULL);
-
- w_form = XtVaCreateManagedWidget ("form", formWidgetClass, w_shell, NULL);
- w_left = w_up = w_oldup = NULL;
-
- for (i = 0; i < N_WIDGET; i++) {
- if (i < N_BUTTON)
- class = commandWidgetClass;
- else if (i < N_BUTTON + N_TOGGLE)
- class = toggleWidgetClass;
- else
- class = dialogWidgetClass;
-
- w_comm[i] = XtVaCreateManagedWidget (w_table[i].name, class, w_form,
- NULL);
- if (w_table[i].newline) {
- w_oldup = w_up;
- w_up = w_comm[i];
- w_left = NULL;
- }
- XtVaSetValues(w_comm[i],
- XtNfromVert, w_oldup,
- XtNfromHoriz, w_left,
- NULL);
- w_left = w_comm[i];
-
- if (strcmp(w_table[i].name, "metric") == 0) {
- XtAddCallback (w_comm[i], XtNcallback, handle_metric_convert, NULL);
- i_metric = i;
- }
- /* yes, we really need to cast commandWidgetClass into WidgetClass */
- if (class == (WidgetClass) commandWidgetClass) {
- XtAddCallback (w_comm[i], XtNcallback,
- handle_print_setup_button, NULL);
- }
- }
-
- XtRealizeWidget (w_shell);
- }
-
- /* unelegant... */
- choi[ 0] = ps_pp->names;
- flag[ 0] = ps_pp->corner_coord;
- flag[ 1] = ps_pp->terrain_dither;
- flag[ 2] = ps_pp->terrain_double;
- flag[ 3] = ps_pp->features;
- flag[ 4] = ps_pp->cell_summary;
- flag[ 5] = ps_pp->cm;
- parm[ 0] = ps_pp->cell_size;
- parm[ 1] = ps_pp->cell_grid_width;
- parm[ 2] = ps_pp->border_width;
- parm[ 3] = ps_pp->connection_width;
- parm[ 4] = ps_pp->page_width;
- parm[ 5] = ps_pp->page_height;
- parm[ 6] = ps_pp->top_margin;
- parm[ 7] = ps_pp->bottom_margin;
- parm[ 8] = ps_pp->left_margin;
- parm[ 9] = ps_pp->right_margin;
- parm[10] = ps_pp->terrain_gray;
- parm[11] = ps_pp->enemy_gray;
- update_values();
-
- XtPopup(w_shell, XtGrabNone);
-
- return 0;
- }
-
- void
- print_ok()
- {
- double conv;
-
- /* unelegant... */
- ps_pp->names = choi[ 0];
- ps_pp->corner_coord = flag[ 0];
- ps_pp->terrain_dither = flag[ 1];
- ps_pp->terrain_double = flag[ 2];
- ps_pp->features = flag[ 3];
- ps_pp->cell_summary = flag[ 4];
- ps_pp->cm = flag[ 5];
- ps_pp->cell_size = parm[ 0];
- ps_pp->cell_grid_width = parm[ 1];
- ps_pp->border_width = parm[ 2];
- ps_pp->connection_width = parm[ 3];
- ps_pp->page_width = parm[ 4];
- ps_pp->page_height = parm[ 5];
- ps_pp->top_margin = parm[ 6];
- ps_pp->bottom_margin = parm[ 7];
- ps_pp->left_margin = parm[ 8];
- ps_pp->right_margin = parm[ 9];
- ps_pp->terrain_gray = parm[10];
- ps_pp->enemy_gray = parm[11];
- if (w_shell) {
- XtPopdown (w_shell);
- }
- if (w_help_shell) {
- XtPopdown (w_help_shell);
- }
- /* convert from cm or in */
- if (ps_pp->cm) {
- conv = 72/2.54;
- } else {
- conv = 72;
- }
- ps_pp->cell_size *= conv;
- ps_pp->cell_grid_width *= conv;
- ps_pp->border_width *= conv;
- ps_pp->connection_width *= conv;
- ps_pp->page_width *= conv;
- ps_pp->page_height *= conv;
- ps_pp->top_margin *= conv;
- ps_pp->bottom_margin *= conv;
- ps_pp->left_margin *= conv;
- ps_pp->right_margin *= conv;
-
- /* dump view */
- notify(ps_side, "dumping view to file \"view.xconq\" ...");
- flush_output(ps_side);
- dump_ps_view(ps_side, ps_pp, "view.xconq");
- notify(ps_side, "... done.");
-
- }
-
- void
- print_skip()
- {
- double conv;
-
- if (w_shell)
- XtPopdown (w_shell);
- if (w_help_shell)
- XtPopdown (w_help_shell);
-
- /* Convert from cm or in. */
- conv = 72;
- if (ps_pp->cm)
- conv /= 2.54;
-
- ps_pp->cell_size *= conv;
- ps_pp->cell_grid_width *= conv;
- ps_pp->border_width *= conv;
- ps_pp->connection_width *= conv;
- ps_pp->page_width *= conv;
- ps_pp->page_height *= conv;
- ps_pp->top_margin *= conv;
- ps_pp->bottom_margin *= conv;
- ps_pp->left_margin *= conv;
- ps_pp->right_margin *= conv;
- }
-
- void
- update_values()
- {
- char buffer[80];
- int i;
- char flg;
- Arg args[1];
-
- for (i = 0; i < N_CHOICE; i++) {
- XtSetArg(args[0], XtNlabel, (XtArgVal) choices[i].legends[choi[i]]);
- XtSetValues(w_comm[i + N_COMMAND], args, 1);
- }
- for (i = 0; i < N_TOGGLE; i++) {
- flg = flag[i];
- XtSetArg(args[0], XtNstate, (XtArgVal) flg);
- XtSetValues(w_comm[i + N_BUTTON], args, 1);
- }
- for (i = 0; i < N_DIALOG; i++) {
- sprintf(buffer, "%.11g", parm[i]);
- XtSetArg(args[0], XtNvalue, (XtArgVal) buffer);
- XtSetValues(w_comm[i + N_BUTTON + N_TOGGLE], args, 1);
- }
- }
-
- int
- w_comm_ind(w)
- Widget w;
- {
- int i;
-
- for (i = 0; i <= N_WIDGET; i++) {
- if (w == w_comm[i])
- return i;
- }
- fprintf(stderr, "w_comm_ind: widget not found\n");
- return -1;
- }
-
- void
- do_dialog(w, event, params, numparms)
- Widget w;
- XEvent *event;
- String *params;
- Cardinal *numparms;
- {
- read_all();
- update_values();
- }
-
- void
- read_all()
- {
- String string;
- int i;
- double result;
- char flg;
- Arg args[1];
-
- for (i = 0; i < N_TOGGLE; i++) {
- XtSetArg(args[0], XtNstate, (XtArgVal) &flg);
- XtGetValues(w_comm[i+N_BUTTON], args, 1);
- flag[i] = flg;
- }
- for (i = 0; i < N_DIALOG; i++) {
- string = XawDialogGetValueString(w_comm[i+N_BUTTON+N_TOGGLE]);
- sscanf(string, "%lf", &result);
- parm[i] = result;
- }
- }
-
- void
- handle_print_setup_button(w)
- Widget w;
- {
- int i = w_comm_ind(w);
-
- read_all();
-
- if (i == 0) {
- open_print_help();
- } else if (i == 1) {
- print_ok();
- } else if (i == 2) {
- print_skip();
- } else if (i >= N_COMMAND) {
- i -= N_COMMAND;
- choi[i] = (choi[i] + 1) % choices[i].number;
- }
- update_values();
- }
-
- /* Convert in to cm, or vice versa. */
-
- void
- handle_metric_convert (w)
- Widget w;
- {
- char flg;
- int i;
- double conv;
- Arg args[1];
-
- XtSetArg(args[0], XtNstate, (XtArgVal) &flg);
- XtGetValues(w_comm[i_metric], args, 1);
- conv = flg ? 2.54 : (1 / 2.54);
- read_all();
- for (i = 0; i < N_DIMEN_D; i++) {
- parm[i] *= conv;
- }
- update_values();
- }
-
- static void
- done_print_help(w, client_data, call_data)
- Widget w;
- XtPointer client_data;
- XtPointer call_data;
- {
- if (w_help_shell)
- XtPopdown(w_help_shell);
- }
-
- void
- open_print_help()
- {
- Widget w_form, w_done, w_text;
-
- if (!w_help_shell) {
- /* If first time, create it. */
- w_help_shell =
- XtVaCreatePopupShell("PrintSetupHelp", topLevelShellWidgetClass,
- ps_side->ui->shell,
- NULL);
- w_form =
- XtVaCreateManagedWidget("helpForm", formWidgetClass, w_help_shell,
- NULL);
- w_text =
- XtVaCreateManagedWidget("helpText", labelWidgetClass, w_form,
- XtNlabel, helpText,
- NULL);
- w_done =
- XtVaCreateManagedWidget("helpDone", commandWidgetClass, w_form,
- XtNfromVert, w_text,
- NULL);
- XtAddCallback(w_done, XtNcallback, done_print_help, NULL);
- }
- XtPopup(w_help_shell, XtGrabNone);
- }
-
-