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 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850
|
/*
* Xgraph Dialog Boxes
*
* This file constructs the hardcopy and error dialog
* boxes used by xgraph. It uses the mini-toolbox given
* in toolbox.c.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "copyright.h"
#include "xgout.h"
#include "xgraph.h"
#include "hard_devices.h"
#include "xtb.h"
#include "params.h"
#include <X11/Xutil.h>
void do_error();
int getline();
#define MAXCHBUF 1024
#ifdef SHADOW
#define gray_width 16
#define gray_height 16
static short gray_bits[] = {
0x5555, 0xaaaa, 0x5555, 0xaaaa,
0x5555, 0xaaaa, 0x5555, 0xaaaa,
0x5555, 0xaaaa, 0x5555, 0xaaaa,
0x5555, 0xaaaa, 0x5555, 0xaaaa};
#endif
static void make_msg_box();
static void del_msg_box();
#define D_VPAD 2
#define D_HPAD 2
#define D_INT 4
#define D_BRDR 2
#define D_INP 35
#define D_DSP 10
#define D_FS 10
struct d_info {
char *prog; /* Program name */
xtb_data cookie; /* Info used by do_harcopy */
Window choices; /* Output device choices */
Window fod; /* File or device flag */
Window fodspec; /* File or device spec */
Window docu_p; /* Document predicate */
Window dimspec; /* Maximum dimension spec */
Window tf_family; /* Title font family spec */
Window tf_size; /* Title font size spec */
Window af_family; /* Axis font family spec */
Window af_size; /* Axis font size spec */
};
#define BACKSPACE 0010
#define DELETE 0177
#define CONTROL_U 0025
#define CONTROL_X 0030
/*ARGSUSED*/
static xtb_hret df_fun(win, ch, text, val)
Window win; /* Widget window */
int ch; /* Typed character */
char *text; /* Copy of text */
xtb_data val; /* User info */
/*
* This is the handler function for the text widget for
* specifing the file or device name. It supports simple
* line editing operations.
*/
{
if ((ch == BACKSPACE) || (ch == DELETE)) {
if (!xtb_ti_dch(win)) XBell(disp, 0);
} else if ((ch == CONTROL_U) || (ch == CONTROL_X)) {
(void) xtb_ti_set(win, "", (xtb_data) 0);
} else {
/* Insert if printable - ascii dependent */
if ((ch < ' ') || (ch >= DELETE) || !xtb_ti_ins(win, ch)) {
XBell(disp, 0);
}
}
return XTB_HANDLED;
}
/*ARGSUSED*/
static xtb_hret ok_fun(win, bval, info)
Window win; /* Button window */
int bval; /* Button value */
xtb_data info; /* Local button info */
/*
* This is the handler function for when the `Ok' button
* is hit. It sets the button, does the hardcopy output,
* and turns the button off. It returns a status which
* deactivates the dialog.
*/
{
struct d_info *real_info = (struct d_info *) info;
int val, dev_p, doc_p;
char file_or_dev[MAXCHBUF], dim_spec[MAXCHBUF], *dev_spec;
char tfam[MAXCHBUF], afam[MAXCHBUF];
char tsizstr[MAXCHBUF], asizstr[MAXCHBUF];
double centimeters, tsize, asize;
xtb_hret rtn;
(void) xtb_bt_set(win, 1, (xtb_data) 0, 0);
val = xtb_br_get(real_info->choices);
if ((val >= 0) && (val < hard_count)) {
dev_p = xtb_br_get(real_info->fod);
if ((dev_p == 0) || (dev_p == 1)) {
xtb_ti_get(real_info->fodspec, file_or_dev, (xtb_data *) 0);
doc_p = xtb_bt_get(real_info->docu_p, (xtb_data *) 0, (int *) 0);
xtb_ti_get(real_info->dimspec, dim_spec, (xtb_data *) 0);
if (sscanf(dim_spec, "%lf", ¢imeters) == 1) {
xtb_ti_get(real_info->tf_family, tfam, (xtb_data *) 0);
xtb_ti_get(real_info->af_family, afam, (xtb_data *) 0);
xtb_ti_get(real_info->tf_size, tsizstr, (xtb_data *) 0);
if (sscanf(tsizstr, "%lf", &tsize) == 1) {
xtb_ti_get(real_info->af_size, asizstr, (xtb_data *) 0);
if (sscanf(asizstr, "%lf", &asize) == 1) {
/* Got all the info */
if (dev_p) {
dev_spec = (char *) 0;
} else {
dev_spec = hard_devices[val].dev_spec;
}
do_hardcopy(real_info->prog, real_info->cookie,
hard_devices[val].dev_init, dev_spec,
file_or_dev, centimeters,
tfam, tsize, afam, asize, doc_p);
rtn = XTB_STOP;
} else {
/* Bad axis size */
do_error("Bad axis font size\n");
rtn = XTB_HANDLED;
}
} else {
/* Bad title size */
do_error("Bad title font size\n");
rtn = XTB_HANDLED;
}
} else {
/* Bad max dimension */
do_error("Bad maximum dimension\n");
rtn = XTB_HANDLED;
}
} else {
/* Bad device spec */
do_error("Must specify `To File' or `To Device'\n");
rtn = XTB_HANDLED;
}
} else {
/* Bad value spec */
do_error("Must specify an output device\n");
rtn = XTB_HANDLED;
}
(void) xtb_bt_set(win, 0, (xtb_data) 0, 0);
return rtn;
}
/*ARGSUSED*/
static xtb_hret can_fun(win, val, info)
Window win; /* Button window */
int val; /* Button value */
xtb_data info; /* Local button info */
/*
* This is the handler function for the cancel button. It
* turns itself on and off and then exits with a status
* which kills the dialog.
*/
{
(void) xtb_bt_set(win, 1, (xtb_data) 0, 0);
(void) xtb_bt_set(win, 0, (xtb_data) 0, 0);
return XTB_STOP;
}
/*ARGSUSED*/
static xtb_hret docu_fun(win, val, info)
Window win; /* Button window */
int val; /* Button value */
xtb_data info; /* Local button info */
/*
* This is the handler function for the document button. It
* toggles it's state.
*/
{
int state;
state = xtb_bt_get(win, (xtb_data *) 0, (int *) 0);
xtb_bt_set(win, (state == 0), (xtb_data) 0, 0);
return XTB_HANDLED;
}
/*ARGSUSED*/
static xtb_hret dev_fun(win, old, new, info)
Window win; /* Button row window */
int old; /* Previous button */
int new; /* Current button */
xtb_data info; /* User data */
/*
* This routine swaps the device specific information
* in the dialog based on what device is selected. The
* information passed is the information for the whole
* dialog.
*/
{
struct d_info *data = (struct d_info *) info;
char text[MAXCHBUF];
int fod_spot, inactive;
fod_spot = xtb_br_get(data->fod);
if ((old >= 0) && (old < hard_count)) {
/* Save old info */
xtb_ti_get(data->fodspec, text, (xtb_data *) 0);
if (fod_spot == 1) {
strncpy(hard_devices[old].dev_file, text, MFNAME-1);
} else if (fod_spot == 0) {
strncpy(hard_devices[old].dev_printer, text, MFNAME-1);
}
if (xtb_bt_get(data->docu_p, (xtb_data *) 0, &inactive)) {
if (inactive) hard_devices[old].dev_docu = NONE;
else hard_devices[old].dev_docu = YES;
} else if (inactive) hard_devices[old].dev_docu = NONE;
else hard_devices[old].dev_docu = NO;
xtb_ti_get(data->dimspec, text, (xtb_data *) 0);
if (sscanf(text, "%lf", &hard_devices[old].dev_max_dim) != 1) {
do_error("Warning: can't read maximum dimension");
}
xtb_ti_get(data->tf_family, text, (xtb_data *) 0);
strncpy(hard_devices[old].dev_title_font, text, MFNAME-1);
xtb_ti_get(data->tf_size, text, (xtb_data *) 0);
if (sscanf(text, "%lf", &hard_devices[old].dev_title_size) != 1) {
do_error("Warning: can't read title font size");
}
xtb_ti_get(data->af_family, text, (xtb_data *) 0);
strncpy(hard_devices[old].dev_axis_font, text, MFNAME-1);
xtb_ti_get(data->af_size, text, (xtb_data *) 0);
if (sscanf(text, "%lf", &hard_devices[old].dev_axis_size) != 1) {
do_error("Warning: can't read axis font size");
}
}
/* Insert new info */
if ((new >= 0) && (new < hard_count)) {
if (fod_spot == 1) {
xtb_ti_set(data->fodspec, hard_devices[new].dev_file, (xtb_data) 0);
} else if (fod_spot == 0) {
xtb_ti_set(data->fodspec, hard_devices[new].dev_printer,
(xtb_data) 0);
} else {
xtb_ti_set(data->fodspec, "", (xtb_data) 0);
}
switch (hard_devices[new].dev_docu) {
case NONE:
(void) xtb_bt_set(data->docu_p, 0, (xtb_data) 0, 1);
break;
case NO:
(void) xtb_bt_set(data->docu_p, 0, (xtb_data) 0, 0);
break;
case YES:
(void) xtb_bt_set(data->docu_p, 1, (xtb_data) 0, 0);
break;
}
(void) sprintf(text, "%g", hard_devices[new].dev_max_dim);
xtb_ti_set(data->dimspec, text, (xtb_data) 0);
xtb_ti_set(data->tf_family, hard_devices[new].dev_title_font,
(xtb_data) 0);
(void) sprintf(text, "%g", hard_devices[new].dev_title_size);
xtb_ti_set(data->tf_size, text, (xtb_data) 0);
xtb_ti_set(data->af_family, hard_devices[new].dev_axis_font,
(xtb_data) 0);
(void) sprintf(text, "%g", hard_devices[new].dev_axis_size);
xtb_ti_set(data->af_size, text, (xtb_data) 0);
}
return XTB_HANDLED;
}
/*ARGSUSED*/
static xtb_hret fd_fun(win, old, new, info)
Window win; /* Button row window */
int old; /* Previous button */
int new; /* Current button */
xtb_data info; /* User data */
/*
* This routine swaps the default file or device names
* based on the state of the file or device buttons.
* The information passed is the information for the whole
* dialog.
*/
{
struct d_info *data = (struct d_info *) info;
char text[MAXCHBUF];
int which_one;
which_one = xtb_br_get(data->choices);
if ((which_one >= 0) && (which_one < hard_count)) {
if (old == 0) {
/* Save into device space */
xtb_ti_get(data->fodspec, text, (xtb_data *) 0);
strncpy(hard_devices[which_one].dev_printer, text, MFNAME-1);
} else if (old == 1) {
/* Save into file space */
xtb_ti_get(data->fodspec, text, (xtb_data *) 0);
which_one = xtb_br_get(data->choices);
strncpy(hard_devices[which_one].dev_file, text, MFNAME-1);
}
if (new == 0) {
/* Restore into device */
xtb_ti_set(data->fodspec, hard_devices[which_one].dev_printer,
(xtb_data *) 0);
} else if (new == 1) {
xtb_ti_set(data->fodspec, hard_devices[which_one].dev_file,
(xtb_data *) 0);
}
}
return XTB_HANDLED;
}
/* Indices for frames made in make_dialog */
enum d_frames_defn {
TITLE_F, ODEVLBL_F, ODEVROW_F, DISPLBL_F, DISPROW_F, FDLBL_F,
FDINP_F, OPTLBL_F, DOCU_F, MDIMLBL_F, MDIMI_F, TFLBL_F, TFFAMLBL_F, TFFAM_F,
TFSIZLBL_F, TFSIZ_F, AFLBL_F, AFFAMLBL_F, AFFAM_F, AFSIZLBL_F, AFSIZ_F,
OK_F, CAN_F, BAR_F, LAST_F
} d_frames;
#define AF(ix) af[(int) (ix)]
#define BAR_SLACK 10
static void make_dialog(win, spawned, prog, cookie, okbtn, frame)
Window win; /* Parent window */
Window spawned; /* Spawned from window */
char *prog; /* Program name */
xtb_data cookie; /* Info for do_hardcopy */
xtb_frame *okbtn; /* Frame for OK button */
xtb_frame *frame; /* Returned window/size */
/*
* This routine constructs a new dialog for asking the user about
* hardcopy devices. The dialog and its size is returned in
* `frame'. The window of the `ok' button is returned in `btnwin'.
* This can be used to reset some of the button state to reuse the dialog.
*/
{
Window overall;
xtb_frame AF(LAST_F);
xtb_fmt *def, *cntrl, *mindim, *tfarea, *afarea;
Cursor diag_cursor;
XColor fg_color, bg_color;
XSizeHints hints;
unsigned long wamask;
XSetWindowAttributes wattr;
struct d_info *info;
int i, found, max_width, which_one, fodi;
char **names;
static char *fodstrs[] = { "To Device", "To File" };
XFontStruct *bigFont = PM_FONT("TitleFont");
XFontStruct *medFont = PM_FONT("LabelFont");
char *Odevice = PM_STR("Device");
char *Odisp = PM_STR("Disposition");
char *OfileDev = PM_STR("FileOrDev");
wamask = CWBackPixel | CWBorderPixel | CWOverrideRedirect |
CWSaveUnder| CWColormap;
wattr.background_pixel = PM_PIXEL("Background");
wattr.border_pixel = PM_PIXEL("Border");
wattr.override_redirect = True;
wattr.save_under = True;
wattr.colormap = cmap;
overall = XCreateWindow(disp, win, 0, 0, 1, 1, D_BRDR,
depth, InputOutput, vis,
wamask, &wattr);
frame->win = overall;
frame->width = frame->height = frame->x_loc = frame->y_loc = 0;
XStoreName(disp, overall, "Hardcopy Dialog");
XSetTransientForHint(disp, spawned, overall);
info = (struct d_info *) malloc(sizeof(struct d_info));
info->prog = prog;
info->cookie = cookie;
/* Make all frames */
xtb_to_new(overall, "Hardcopy Options", bigFont, &AF(TITLE_F));
xtb_to_new(overall, "Output device:", medFont, &AF(ODEVLBL_F));
found = -1;
names = (char **) malloc((unsigned) (sizeof(char *) * hard_count));
for (i = 0; i < hard_count; i++) {
names[i] = hard_devices[i].dev_name;
if (strcmp(Odevice, names[i]) == 0) {
found = i;
}
}
xtb_br_new(overall, hard_count, names, found,
dev_fun, (xtb_data) info, &AF(ODEVROW_F));
info->choices = AF(ODEVROW_F).win;
xtb_to_new(overall, "Disposition:", medFont, &AF(DISPLBL_F));
found = -1;
for (i = 0; i < 2; i++) {
if (strcmp(Odisp, fodstrs[i]) == 0) {
found = i;
}
}
xtb_br_new(overall, 2, fodstrs, found,
fd_fun, (xtb_data) info, &AF(DISPROW_F));
info->fod = AF(DISPROW_F).win;
xtb_to_new(overall, "File or Device Name:", medFont, &AF(FDLBL_F));
xtb_ti_new(overall, "", D_INP, df_fun, (xtb_data) 0, &AF(FDINP_F));
if (OfileDev && strlen(OfileDev)) {
which_one = xtb_br_get(info->choices);
if ((which_one >= 0) && (which_one < hard_count)) {
fodi = xtb_br_get(info->fod);
if (fodi == 0) {
strncpy(hard_devices[which_one].dev_printer, OfileDev, MFNAME-1);
} else if (fodi == 1) {
strncpy(hard_devices[which_one].dev_file, OfileDev, MFNAME-1);
}
}
}
info->fodspec = AF(FDINP_F).win;
xtb_to_new(overall, "Optional Parameters", bigFont, &AF(OPTLBL_F));
xtb_bt_new(overall, "Include in Document", docu_fun, (xtb_data) 0, &AF(DOCU_F));
info->docu_p = AF(DOCU_F).win;
xtb_to_new(overall, "Maximum Dimension (cm):", medFont, &AF(MDIMLBL_F));
xtb_ti_new(overall, "", D_DSP, df_fun, (xtb_data) 0, &AF(MDIMI_F));
info->dimspec = AF(MDIMI_F).win;
xtb_to_new(overall, "Title Font", medFont, &AF(TFLBL_F));
xtb_to_new(overall, "Family:", medFont, &AF(TFFAMLBL_F));
xtb_ti_new(overall, "", MFNAME, df_fun, (xtb_data) 0, &AF(TFFAM_F));
info->tf_family = AF(TFFAM_F).win;
xtb_to_new(overall, "Size (pnts):", medFont, &AF(TFSIZLBL_F));
xtb_ti_new(overall, "", D_FS, df_fun, (xtb_data) 0, &AF(TFSIZ_F));
info->tf_size = AF(TFSIZ_F).win;
xtb_to_new(overall, "Axis Font", medFont, &AF(AFLBL_F));
xtb_to_new(overall, "Family:", medFont, &AF(AFFAMLBL_F));
xtb_ti_new(overall, "", MFNAME, df_fun, (xtb_data) 0, &AF(AFFAM_F));
info->af_family = AF(AFFAM_F).win;
xtb_to_new(overall, "Size (pnts):", medFont, &AF(AFSIZLBL_F));
xtb_ti_new(overall, "", D_FS, df_fun, (xtb_data) 0, &AF(AFSIZ_F));
info->af_size = AF(AFSIZ_F).win;
xtb_bt_new(overall, " Ok ", ok_fun, (xtb_data) info, &AF(OK_F));
xtb_bt_new(overall, "Cancel", can_fun, (xtb_data) 0, &AF(CAN_F));
/* Dividing bar */
max_width = 0;
for (i = 0; i < ((int) BAR_F); i++) {
if (AF(i).width > max_width) max_width = AF(i).width;
}
xtb_bk_new(overall, max_width - BAR_SLACK, 1, &AF(BAR_F));
/* Set device specific info */
(void) dev_fun(info->choices, -1,xtb_br_get(info->choices),(xtb_data) info);
(void) fd_fun(info->fod, -1, xtb_br_get(info->fod), (xtb_data) info);
/*
* Now place elements - could make this one expression but pcc
* is too wimpy.
*/
cntrl = xtb_vert(XTB_LEFT, D_VPAD, D_INT,
xtb_hort(XTB_CENTER, D_HPAD, D_INT,
xtb_w(&AF(ODEVLBL_F)),
xtb_w(&AF(ODEVROW_F)), NE),
xtb_hort(XTB_CENTER, D_HPAD, D_INT,
xtb_w(&AF(DISPLBL_F)),
xtb_w(&AF(DISPROW_F)), NE),
xtb_hort(XTB_CENTER, D_HPAD, D_INT,
xtb_w(&AF(FDLBL_F)),
xtb_w(&AF(FDINP_F)), NE),
NE);
mindim = xtb_vert(XTB_LEFT, D_VPAD, D_INT,
xtb_hort(XTB_CENTER, D_HPAD, D_INT,
xtb_w(&AF(MDIMLBL_F)),
xtb_w(&AF(MDIMI_F)),
NE),
NE);
tfarea = xtb_vert(XTB_LEFT, D_VPAD, D_INT,
xtb_hort(XTB_CENTER, D_HPAD, D_INT,
xtb_w(&AF(TFFAMLBL_F)),
xtb_w(&AF(TFFAM_F)),
xtb_w(&AF(TFSIZLBL_F)),
xtb_w(&AF(TFSIZ_F)), NE),
NE);
afarea = xtb_vert(XTB_LEFT, D_VPAD, D_INT,
xtb_hort(XTB_CENTER, D_HPAD, D_INT,
xtb_w(&AF(AFFAMLBL_F)),
xtb_w(&AF(AFFAM_F)),
xtb_w(&AF(AFSIZLBL_F)),
xtb_w(&AF(AFSIZ_F)), NE),
NE);
def = xtb_fmt_do
(xtb_vert(XTB_CENTER, D_VPAD, D_INT,
xtb_w(&AF(TITLE_F)),
cntrl,
xtb_w(&AF(BAR_F)),
xtb_w(&AF(OPTLBL_F)),
mindim,
xtb_w(&AF(DOCU_F)),
xtb_w(&AF(TFLBL_F)),
tfarea,
xtb_w(&AF(AFLBL_F)),
afarea,
xtb_hort(XTB_CENTER, D_HPAD, D_INT,
xtb_w(&AF(OK_F)), xtb_w(&AF(CAN_F)), NE),
NE),
&frame->width, &frame->height);
xtb_mv_frames(LAST_F, af);
xtb_fmt_free(def);
/* Make window large enough to contain the info */
XResizeWindow(disp, overall, frame->width, frame->height);
hints.flags = PSize;
hints.width = frame->width;
hints.height = frame->height;
XSetNormalHints(disp, overall, &hints);
diag_cursor = XCreateFontCursor(disp, XC_dotbox);
fg_color.pixel = PM_PIXEL("Foreground");
XQueryColor(disp, cmap, &fg_color);
bg_color.pixel = PM_PIXEL("Background");
XQueryColor(disp, cmap, &bg_color);
XRecolorCursor(disp, diag_cursor, &fg_color, &bg_color);
XDefineCursor(disp, overall, diag_cursor);
frame->width += (2 * D_BRDR);
frame->height += (2 * D_BRDR);
*okbtn = AF(OK_F);
}
#ifdef SHADOW
Window make_shadow(w, h)
int w, h;
/*
* Makes a shadow window for a pop-up window of the specified size.
* Needs hint work as well. Try no background window.
*/
{
Window shadow;
Bitmap gray_bm;
Pixmap gray_pm;
gray_bm = XStoreBitmap(gray_width, gray_height, gray_bits);
gray_pm = XMakePixmap(gray_bm, PM_PIXEL("Foreground"), PM_PIXEL("Background"));
shadow = XCreateWindow(RootWindow, 0, 0, w, h, 0, BlackPixmap, gray_pm);
XFreePixmap(gray_pm);
XFreeBitmap(gray_bm);
return shadow;
}
#endif
#define SH_W 5
#define SH_H 5
void ho_dialog(parent, prog, cookie)
Window parent; /* Parent window */
char *prog; /* Program name */
xtb_data cookie; /* Info passed to do_hardcopy */
/*
* Asks the user about hardcopy devices. A table of hardcopy
* device names and function pointers to their initialization
* functions is assumed to be in the global `hard_devices' and
* `hard_count'. Returns a non-zero status if the dialog was
* sucessfully posted. Calls do_hardcopy in xgraph to actually
* output information.
*/
{
#ifdef SHADOW
static Window shadow;
#endif
static Window dummy;
static xtb_frame overall = { (Window) 0, 0, 0, 0, 0 };
static xtb_frame okbtn;
XEvent evt;
XWindowAttributes winInfo;
XSizeHints hints;
struct d_info *info;
if (!overall.win) {
make_dialog(RootWindow(disp, screen), parent, prog, cookie,
&okbtn, &overall);
#ifdef SHADOW
shadow = make_shadow(d_w, d_h);
#endif
} else {
/* Change the button information */
(void) xtb_bt_get(okbtn.win, (xtb_data *) &info, (int *) 0);
info->prog = prog;
info->cookie = cookie;
}
XGetWindowAttributes(disp, parent, &winInfo);
XTranslateCoordinates(disp, parent, RootWindow(disp, screen),
0, 0, &winInfo.x, &winInfo.y, &dummy);
XMoveWindow(disp, overall.win,
(int) (winInfo.x + winInfo.width/2 - overall.width/2),
(int) (winInfo.y + winInfo.height/2 - overall.height/2));
hints.flags = PPosition;
hints.x = winInfo.x + winInfo.width/2 - overall.width/2;
hints.y = winInfo.y + winInfo.height/2 - overall.height/2;
XSetNormalHints(disp, overall.win, &hints);
#ifdef SHADOW
XMoveWindow(disp, shadow, winInfo.x + winInfo.width/2 - d_w/2 + SH_W,
winInfo.y + winInfo.height/2 - d_h/2 + SH_H);
hints.flags = PPosition;
hints.x = winInfo.x + winInfo.width/2 - d_w/2 + SH_W;
hints.y = winInfo.y + winInfo.height/2 - d_h/2 + SH_H;
XSetNormalHints(disp, shadow, &hints);
XRaiseWindow(disp, shadow);
XMapWindow(disp, shadow);
#endif
XRaiseWindow(disp, overall.win);
XMapWindow(disp, overall.win);
do {
XNextEvent(disp, &evt);
} while (xtb_dispatch(&evt) != XTB_STOP);
XUnmapWindow(disp, overall.win);
#ifdef SHADOW
XUnmapWindow(disp, shadow);
#endif
}
/*ARGSUSED*/
static xtb_hret err_func(win, bval, info)
Window win; /* Button window */
int bval; /* Button value */
xtb_data info; /* Local button info */
/*
* Handler function for button in error box. Simply stops dialog.
*/
{
(void) xtb_bt_set(win, 1, (xtb_data) 0, 0);
(void) xtb_bt_set(win, 0, (xtb_data) 0, 0);
return XTB_STOP;
}
struct err_info {
Window title;
Window contbtn;
int num_lines;
int alloc_lines;
Window *lines;
};
#define E_LINES 2
#define E_VPAD 3
#define E_HPAD 3
#define E_INTER 1
#define ML 256
static void make_msg_box(text, title, frame)
char *text; /* Error text */
char *title; /* Title text */
xtb_frame *frame; /* Returned frame */
/*
* Makes an error box with a title.
*/
{
XSizeHints hints;
struct err_info *new_info;
xtb_frame tf, cf, lf;
char *lineptr, line[ML];
int y, i;
unsigned long wamask;
XSetWindowAttributes wattr;
XFontStruct *bigFont = PM_FONT("TitleFont");
XFontStruct *medFont = PM_FONT("LabelFont");
wamask = CWBackPixel | CWBorderPixel | CWOverrideRedirect |
CWSaveUnder | CWColormap;
wattr.background_pixel = PM_PIXEL("Background");
wattr.border_pixel = PM_PIXEL("Border");
wattr.override_redirect = True;
wattr.save_under = True;
wattr.colormap = cmap;
frame->win = XCreateWindow(disp, RootWindow(disp, screen),
0, 0, 1, 1, D_BRDR,
depth, InputOutput, vis,
wamask, &wattr);
frame->x_loc = frame->y_loc = frame->width = frame->height = 0;
XStoreName(disp, frame->win, "Error Dialog");
XSetTransientForHint(disp, RootWindow(disp, screen), frame->win);
new_info = (struct err_info *) malloc((unsigned) sizeof(struct err_info));
xtb_to_new(frame->win, title, bigFont, &tf);
new_info->title = tf.win;
if (tf.width > frame->width) frame->width = tf.width;
xtb_bt_new(frame->win, "Dismiss", err_func, (xtb_data) 0, &cf);
new_info->contbtn = cf.win;
if (cf.width > frame->width) frame->width = cf.width;
new_info->alloc_lines = E_LINES;
new_info->num_lines = 0;
new_info->lines = (Window *) malloc((unsigned) (sizeof(Window) * E_LINES));
lineptr = text;
while (getline(&lineptr, line)) {
if (new_info->num_lines >= new_info->alloc_lines) {
new_info->alloc_lines *= 2;
new_info->lines = (Window *) realloc((char *) new_info->lines,
(unsigned)
(new_info->alloc_lines *
sizeof(Window)));
}
xtb_to_new(frame->win, line, medFont, &lf);
new_info->lines[new_info->num_lines] = lf.win;
new_info->num_lines += 1;
if (lf.width > frame->width) frame->width = lf.width;
}
/* Placement */
frame->width += (2 * E_HPAD);
y = E_VPAD;
/* Title */
XMoveWindow(disp, new_info->title, (int) (frame->width/2 - tf.width/2), y);
y += (tf.height + E_INTER);
/* All lines */
for (i = 0; i < new_info->num_lines; i++) {
XMoveWindow(disp, new_info->lines[i], E_HPAD, y);
y += (lf.height + E_INTER);
}
/* Button */
XMoveWindow(disp, new_info->contbtn, (int) (frame->width/2 - cf.width/2), y);
y += (cf.height + E_INTER);
/* Make dialog the right size */
y += (E_VPAD - E_INTER);
XResizeWindow(disp, frame->win, frame->width, (unsigned int) y);
hints.flags = PSize;
hints.width = frame->width;
hints.height = (unsigned int) y;
XSetNormalHints(disp, frame->win, &hints);
frame->width += (2 * D_BRDR);
frame->height = y + (2 * D_BRDR);
xtb_register(frame->win, (xtb_hret (*)()) 0, (xtb_data) new_info);
}
void msg_box(title, text)
char *title, *text;
/*
* This posts a dialog that contains lines of text and a continue
* button. The text may be multiple lines. The dialog is remade
* each time.
*/
{
#ifdef SHADOW
Window shadow;
#endif
XWindowAttributes info;
XEvent evt;
XSizeHints hints;
xtb_frame text_frame;
make_msg_box(text, title, &text_frame);
#ifdef SHADOW
shadow = make_shadow(w, h);
#endif
XGetWindowAttributes(disp, RootWindow(disp, screen), &info);
XMoveWindow(disp, text_frame.win, (int) (info.width/2 - text_frame.width/2),
(int) (info.height/2 - text_frame.height/2));
hints.flags = PPosition;
hints.x = info.width/2 - text_frame.width/2;
hints.y = info.height/2 - text_frame.height/2;
XSetNormalHints(disp, text_frame.win, &hints);
#ifdef SHADOW
XMoveWindow(disp, shadow, info.width/2 - w/2 + SH_W,
info.height/2 - h/2 + SH_H);
hints.flags = PPosition;
hints.x = info.width/2 - w/2 + SH_W;
hints.y = info.height/2 - h/2 + SH_H;
XSetNormalHints(disp, text_frame.win, &hints);
XRaiseWindow(disp, shadow);
XMapWindow(disp, shadow);
#endif
XRaiseWindow(disp, text_frame.win);
XMapWindow(disp, text_frame.win);
do {
XNextEvent(disp, &evt);
} while (xtb_dispatch(&evt) != XTB_STOP);
#ifdef SHADOW
XDestroyWindow(disp, shadow);
#endif
del_msg_box(text_frame.win);
}
void do_error(err_text)
char *err_text;
{
msg_box("Xgraph Error", err_text);
}
int getline(tptr, lptr)
char **tptr;
char *lptr;
/*
* Returns next line from tptr. Assumes `lptr' is large enough to
* accept the line.
*/
{
char *start;
start = *tptr;
while (*tptr && **tptr && (**tptr != '\n')) {
(*tptr)++;
}
if (*tptr > start) {
(void) strncpy(lptr, start, (*tptr - start));
lptr[*tptr-start] = '\0';
if (**tptr == '\n') (*tptr)++;
return 1;
} else {
return 0;
}
}
static void del_msg_box(msg)
Window msg;
/*
* Deletes all components of an msg box
*/
{
struct err_info *info;
char *dummy;
int i;
if (xtb_unregister(msg, (xtb_data *) &info)) {
xtb_to_del(info->title);
xtb_bt_del(info->contbtn, (xtb_data *) &dummy);
for (i = 0; i < info->num_lines; i++) {
xtb_to_del(info->lines[i]);
}
free((char *) info->lines);
free((char *) info);
XDestroyWindow(disp, msg);
}
}
|