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
|
/* dialogs - General Dialog Objects */
/* XLISP-STAT 2.1 Copyright (c) 1990, by Luke Tierney */
/* Additions to Xlisp 2.1, Copyright (c) 1989 by David Michael Betz */
/* You may give out copies of this software; for conditions see the */
/* file COPYING included with this distribution. */
#include "xlisp.h"
#include "xlstat.h"
/* external variables */
extern LVAL s_title, s_items, s_true, s_text, s_location, s_size,
s_action, s_dialog, s_min_value, s_max_value, s_page_increment,
s_editable, s_value, s_list_data, s_columns, s_dialog_proto,
s_dialog_item_proto, s_button_item_proto, s_toggle_item_proto,
s_text_item_proto, sk_editable, s_choice_item_proto,
s_scroll_item_proto, sk_min_value, sk_max_value, sk_page_increment,
s_list_item_proto, sk_columns, s_modeless, sk_allocate, s_modal,
s_hardware_address, sk_show;
extern LVAL DialogGetModalItem(), DialogToggleItemValue(),
DialogTextItemText(), DialogChoiceItemValue(), DialogScrollItemValue(),
DialogScrollItemMax(), DialogScrollItemMin(), DialogListItemSelection();
/* layout definitions */
# define ITEM_GAP 10
# define SCROLL_MIN 0
# define SCROLL_MAX 100
# define SCROLL_PAGE 5
# define has_item_location(i) (slot_value(i, s_location) != NIL)
# define has_item_size(i) (slot_value(i, s_size) != NIL)
# define check_dialog_address(d) valid_dialog_address(slot_value(d, s_hardware_address))
/***********************************************************************/
/** **/
/** Utility Functions **/
/** **/
/***********************************************************************/
static int check_point_list P1C(LVAL, x)
{
return(listp(x) && llength(x) == 2 && fixp(car(x)) && fixp(car(cdr(x))));
}
Point ListToPoint P1C(LVAL, list)
{
Point pt;
if (! check_point_list(list)) xlerror("not a point", list);
pt.h = getfixnum(car(list));
pt.v = getfixnum(car(cdr(list)));
return(pt);
}
LVAL PointToList P1C(Point, pt)
{
return(integer_list_2((int) pt.h, (int) pt.v));
}
/***********************************************************************/
/***********************************************************************/
/** **/
/** DIALOG-PROTO Methods **/
/** **/
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/
/** **/
/** Support Functions **/
/** **/
/***********************************************************************/
/* Is this a dialog? */
int dialog_p P1C(LVAL, x)
{
return (kind_of_p(x, getvalue(s_dialog_proto)));
}
/* get a dialog from the stack */
LVAL xsgetdialog(V)
{
LVAL x;
x = xlgetarg();
if (! dialog_p(x)) xlerror("not a dialog", x);
return(x);
}
static Point calc_item_size P4C(LVAL, dialog, LVAL, item, int, left, int, top)
{
Point sz, loc;
if (! dialog_item_p(item)) xlerror("not a dialog item", item);
if (slot_value(item, s_dialog) != NIL
&& check_dialog_address(slot_value(item, s_dialog)))
xlfail("item is already installed in a dialog");
sz = ListToPoint(slot_value(item, s_size));
if (has_item_location(item))
loc = ListToPoint(slot_value(item, s_location));
else {
loc.h = left;
loc.v = top;
set_slot_value(item, s_location, PointToList(loc));
}
sz.h += loc.h - left;
sz.v += loc.v - top;
sz.h = max((int) sz.h, 0);
sz.v = max((int) sz.v, 0);
set_slot_value(item, s_dialog, dialog);
return(sz);
}
static Point calc_item_list_size P5C(LVAL, dialog, LVAL, items, int, left, int, top, int, as_column)
{
LVAL item;
Point sz, pt;
for (sz.h = 0, sz.v = 0; consp(items); items = cdr(items)) {
item = car(items);
if consp(item)
pt = calc_item_list_size(dialog, item, left, top, ! as_column);
else pt = calc_item_size(dialog, item, left, top);
if (as_column) {
sz.h = max((int) sz.h, (int) pt.h);
sz.v += pt.v + ITEM_GAP;
top += pt.v + ITEM_GAP;
}
else {
sz.h += pt.h + ITEM_GAP;
left += pt.h + ITEM_GAP;
sz.v = max((int) sz.v, (int) pt.v);
}
}
if (as_column) sz.v = max((int) (sz.v - ITEM_GAP), 0);
else sz.h = max((int) (sz.h - ITEM_GAP), 0);
return(sz);
}
static VOID calc_size P1C(LVAL, dialog)
{
Point sz;
LVAL size = slot_value(dialog, s_size);
LVAL items = slot_value(dialog, s_items);
sz = calc_item_list_size(dialog, items, ITEM_GAP, ITEM_GAP, TRUE);
sz.h += 2 * ITEM_GAP;
sz.v += 2 * ITEM_GAP;
if (! check_point_list(size)) {
set_slot_value(dialog, s_size, PointToList(sz));
}
}
static VOID calc_location P1C(LVAL, dialog)
{
Point screen, size, location;
int left, top;
LVAL loc = slot_value(dialog, s_location);
if (! check_point_list(loc)) {
StGetScreenSize(&left, &top);
screen.h = left; screen.v = top; /* needed since components may be shorts */
size = ListToPoint(slot_value(dialog, s_size));
location.h = (screen.h - size.h) / 2;
location.v = (screen.v - size.v) / 2;
set_slot_value(dialog, s_location, PointToList(location));
}
}
static LVAL simple_dialog_method P1C(int, which)
{
LVAL dialog, result = NIL;
dialog = xsgetdialog();
xllastarg();
switch (which) {
case 'R': DialogRemove(dialog); break;
case 'A': calc_size(dialog);
calc_location(dialog);
DialogAllocate(dialog);
break;
case 'a': result = (check_dialog_address(dialog)) ? s_true : NIL; break;
}
return(result);
}
extern LVAL s_text_item_proto, sk_new;
static LVAL make_text_item P1C(LVAL, string)
{
LVAL result;
result = send_message_1L(getvalue(s_text_item_proto), sk_new, string);
return(result);
}
static LVAL process_items P1C(LVAL, items)
{
LVAL next;
xlprot1(items);
items = copylist(items);
for (next = items; consp(next); next = cdr(next)) {
if (stringp(car(next))) rplaca(next, make_text_item(car(next)));
else if (consp(car(next))) rplaca(next, process_items(car(next)));
}
xlpop();
return(items);
}
/***********************************************************************/
/** **/
/** Methods **/
/** **/
/***********************************************************************/
/* :ISNEW Method */
LVAL xsdialog_isnew(V)
{
LVAL dialog, items;
dialog = xsgetdialog();
items = xlgalist();
items = process_items(items);
set_slot_value(dialog, s_items, items);
object_isnew(dialog);
if (! stringp(slot_value(dialog, s_title)))
set_slot_value(dialog, s_title, cvstring("Dialog"));
if (xsboolkey(sk_show, TRUE)) send_message(dialog, sk_allocate);
return(dialog);
}
LVAL xsdialog_allocate(V) { return(simple_dialog_method('A')); }
LVAL xsdialog_remove(V) { return(simple_dialog_method('R')); }
LVAL xsdialog_allocated_p(V) { return(simple_dialog_method('a')); }
LVAL xsdialog_default_button(V)
{
LVAL dialog, item;
dialog = xsgetdialog();
item = xlgetarg();
xllastarg();
DialogSetDefaultButton(dialog, item);
return (item);
}
/* :MODAL-DIALOG method */
LVAL xsdialog_modal(V)
{
LVAL dialog;
dialog = xsgetdialog();
xllastarg();
return(DialogGetModalItem(dialog));
}
/***********************************************************************/
/***********************************************************************/
/** **/
/** DIALOG-ITEM-PROTO Methods **/
/** **/
/***********************************************************************/
/***********************************************************************/
/* Is this a dialog-item? */
int dialog_item_p P1C(LVAL, x)
{
return (kind_of_p(x, getvalue(s_dialog_item_proto)));
}
/* get a dialog item from the stack */
LVAL xsgetdialogitem(V)
{
LVAL x;
x = xlgetarg();
if (! dialog_item_p(x)) xlerror("not a dialog item", x);
return(x);
}
static VOID get_initial_item_values P2C(LVAL, item, int, get_first)
{
LVAL text;
if (get_first) {
text = xlgastring();
set_slot_value(item, s_text, text);
}
object_isnew(item);
}
/* :DO-ACTION Method */
LVAL xsdialog_item_do_action(V)
{
LVAL item, action, result;
item = xsgetdialogitem();
xllastarg();
action = slot_value(item, s_action);
result = (action != NIL) ? xlapply(pushargs(action, NIL)) : NIL;
return(result);
}
/* :ACTION Method */
LVAL xsdialog_item_action(V)
{
LVAL item, action=NIL;
int set;
item = xsgetdialogitem();
set = moreargs();
if (set) action = xlgetarg();
xllastarg();
if (set) set_slot_value(item, s_action, action);
return(slot_value(item, s_action));
}
/***********************************************************************/
/***********************************************************************/
/** **/
/** BUTTON-ITEM-PROTO Methods **/
/** **/
/***********************************************************************/
/***********************************************************************/
/* Is this a button-item? */
int button_item_p P1C(LVAL, x)
{
return (kind_of_p(x, getvalue(s_button_item_proto)));
}
/* get a button item from the stack */
LVAL xsgetbuttonitem(V)
{
LVAL x;
x = xlgetarg();
if (! button_item_p(x)) xlerror("not a button item", x);
return(x);
}
/* :ISNEW Method */
LVAL xsbutton_item_isnew(V)
{
LVAL item;
int width, height;
item = xsgetbuttonitem();
get_initial_item_values(item, TRUE);
if (! has_item_size(item)) {
DialogButtonGetDefaultSize(item, &width, &height);
set_slot_value(item, s_size, integer_list_2(width, height));
}
return(item);
}
/***********************************************************************/
/***********************************************************************/
/** **/
/** TOGGLE-ITEM-PROTO Methods **/
/** **/
/***********************************************************************/
/***********************************************************************/
/* Is this a toggle-item? */
int toggle_item_p P1C(LVAL, x)
{
return (kind_of_p(x, getvalue(s_toggle_item_proto)));
}
/* get a toggle item from the stack */
LVAL xsgettoggleitem(V)
{
LVAL x;
x = xlgetarg();
if (! toggle_item_p(x)) xlerror("not a toggle item", x);
return(x);
}
/* :ISNEW Method */
LVAL xstoggle_item_isnew(V)
{
LVAL item;
int width, height;
item = xsgettoggleitem();
get_initial_item_values(item, TRUE);
if (! has_item_size(item)) {
DialogToggleGetDefaultSize(item, &width, &height);
set_slot_value(item, s_size, integer_list_2(width, height));
}
return(item);
}
/* :VALUE Method */
LVAL xstoggle_item_value(V)
{
LVAL item, value=NIL;
int set;
item = xsgettoggleitem();
set = moreargs();
if (set) value = xlgetarg();
xllastarg();
return(DialogToggleItemValue(item, set, value));
}
/***********************************************************************/
/***********************************************************************/
/** **/
/** TEXT-ITEM-PROTO Methods **/
/** **/
/***********************************************************************/
/***********************************************************************/
/* Is this a text-item? */
int text_item_p P1C(LVAL, x)
{
return (kind_of_p(x, getvalue(s_text_item_proto)));
}
/* get a text item from the stack */
LVAL xsgettextitem(V)
{
LVAL x;
x = xlgetarg();
if (! text_item_p(x)) xlerror("not a text item", x);
return(x);
}
/* :ISNEW Method */
LVAL xstext_item_isnew(V)
{
LVAL item, edit;
int width, height;
item = xsgettextitem();
get_initial_item_values(item, TRUE);
if (xlgetkeyarg(sk_editable, &edit) && edit != NIL)
set_slot_value(item, s_editable, s_true);
if (! has_item_size(item)) {
DialogTextGetDefaultSize(item, &width, &height);
set_slot_value(item, s_size, integer_list_2(width, height));
}
return(item);
}
/* :TEXT Method */
LVAL xstext_item_text(V)
{
LVAL item;
int set;
char *text=NULL;
item = xsgettextitem();
set = moreargs();
if (set) text = (char *) getstring(xlgastring());
xllastarg();
return(DialogTextItemText(item, set, text));
}
/***********************************************************************/
/***********************************************************************/
/** **/
/** CHOICE-ITEM-PROTO Methods **/
/** **/
/***********************************************************************/
/***********************************************************************/
/* Is this a choice-item? */
int choice_item_p P1C(LVAL, x)
{
return (kind_of_p(x, getvalue(s_choice_item_proto)));
}
/* get a choice item from the stack */
LVAL xsgetchoiceitem(V)
{
LVAL x;
x = xlgetarg();
if (! choice_item_p(x)) xlerror("not a choice item", x);
return(x);
}
/* :ISNEW Method */
LVAL xschoice_item_isnew(V)
{
LVAL item, text, next;
int width, height;
item = xsgetchoiceitem();
text = xlgalist();
for (next = text; consp(next); next = cdr(next))
if (! stringp(car(next))) xlerror("not a string", car(next));
set_slot_value(item, s_text, text);
get_initial_item_values(item, FALSE);
if (! has_item_size(item)) {
DialogChoiceGetDefaultSize(item, &width, &height);
set_slot_value(item, s_size, integer_list_2(width, height));
}
if (! fixp(slot_value(item, s_value)))
set_slot_value(item, s_value, cvfixnum((FIXTYPE) 0));
return(item);
}
/* :VALUE Method */
LVAL xschoice_item_value(V)
{
LVAL item;
int value=0, set;
item = xsgetchoiceitem();
set = moreargs();
if (set) value = getfixnum(xlgafixnum());
xllastarg();
return(DialogChoiceItemValue(item, set, value));
}
/***********************************************************************/
/***********************************************************************/
/** **/
/** SCROLL-ITEM-PROTO Methods **/
/** **/
/***********************************************************************/
/***********************************************************************/
/* Is this a scroll-item? */
int scroll_item_p P1C(LVAL, x)
{
return (kind_of_p(x, getvalue(s_scroll_item_proto)));
}
/* get a scroll item from the stack */
LVAL xsgetscrollitem(V)
{
LVAL x;
x = xlgetarg();
if (! scroll_item_p(x)) xlerror("not a scroll item", x);
return(x);
}
/* :ISNEW Method */
LVAL xsscroll_item_isnew(V)
{
LVAL item, low, high, page;
int width, height;
item = xsgetscrollitem();
get_initial_item_values(item, FALSE);
if (! xlgetkeyarg(sk_min_value, &low) || ! fixp(low))
low = cvfixnum((FIXTYPE) SCROLL_MIN);
set_slot_value(item, s_min_value, low);
if (! fixp(slot_value(item, s_value)))
set_slot_value(item, s_value, low);
if (! xlgetkeyarg(sk_max_value, &high) || ! fixp(high))
high = cvfixnum((FIXTYPE) SCROLL_MAX);
set_slot_value(item, s_max_value, high);
if (! xlgetkeyarg(sk_page_increment, &page) || ! fixp(page))
page = cvfixnum((FIXTYPE) SCROLL_PAGE);
set_slot_value(item, s_page_increment, page);
if (! has_item_size(item)) {
DialogScrollGetDefaultSize(item, &width, &height);
set_slot_value(item, s_size, integer_list_2(width, height));
}
return(item);
}
/* :VALUE Method */
LVAL xsscroll_item_value(V)
{
LVAL item;
int set, value=0;
item = xsgetscrollitem();
set = moreargs();
if (set) value = getfixnum(xlgafixnum());
xllastarg();
return(DialogScrollItemValue(item, set, value));
}
/* :MAX Method */
LVAL xsscroll_item_max(V)
{
LVAL item;
int set, value=0;
item = xsgetscrollitem();
set = moreargs();
if (set) value = getfixnum(xlgafixnum());
xllastarg();
return(DialogScrollItemMax(item, set, value));
}
/* :MIN Method */
LVAL xsscroll_item_min(V)
{
LVAL item;
int set, value=0;
item = xsgetscrollitem();
set = moreargs();
if (set) value = getfixnum(xlgafixnum());
xllastarg();
return(DialogScrollItemMin(item, set, value));
}
/* :SCROLL-ACTION Method */
LVAL xsscroll_item_action(V)
{
LVAL item, action, result;
item = xsgetdialogitem();
xllastarg();
action = slot_value(item, s_action);
result = (action != NIL) ? xlapply(pushargs(action, NIL)) : NIL;
return(result);
}
/***********************************************************************/
/***********************************************************************/
/** **/
/** LIST-ITEM-PROTO Methods **/
/** **/
/***********************************************************************/
/***********************************************************************/
/* Is this a list-item? */
int list_item_p P1C(LVAL, x)
{
return (kind_of_p(x, getvalue(s_list_item_proto)));
}
/* get a list item from the stack */
LVAL xsgetlistitem(V)
{
LVAL x;
x = xlgetarg();
if (! list_item_p(x)) xlerror("not a list item", x);
return(x);
}
/* :ISNEW Method */
LVAL xslist_item_isnew(V)
{
LVAL item, data, columns;
int width, height;
item = xsgetlistitem();
data = xlgetarg();
if (listp(data)) data = coerce_to_tvec(data, s_true);
else data = copyarray(data);
set_slot_value(item, s_list_data, data);
get_initial_item_values(item, FALSE);
if (! xlgetkeyarg(sk_columns, &columns) || ! fixp(columns)
|| getfixnum(columns) < 1) columns = cvfixnum((FIXTYPE) 1);
set_slot_value(item, s_columns, columns);
if (! has_item_size(item)) {
DialogListGetDefaultSize(item, &width, &height);
set_slot_value(item, s_size, integer_list_2(width, height));
}
return(item);
}
/* :DO-ACTION Method */
LVAL xslist_item_action(V)
{
LVAL item, action, double_click, result;
item = xsgetlistitem();
double_click = (moreargs() && xlgetarg() != NIL) ? s_true : NIL;
xllastarg();
action = slot_value(item, s_action);
result = (action != NIL) ? xsfuncall1(action, double_click) : NIL;
return(result);
}
/* :SET-TEXT Method */
LVAL xslist_item_text(V)
{
LVAL item, data, index, value;
char *text;
item = xsgetlistitem();
index = xlgetarg();
value = xlgastring();
text = (char *) getstring(value);
xllastarg();
data = slot_value(item, s_list_data);
if (vectorp(data) || tvecp(data) || stringp(data))
settvecelement(data, rowmajorindex(data, consa(index), FALSE), value);
else if (darrayp(data))
settvecelement(getdarraydata(data),
rowmajorindex(data, index, FALSE), value);
else xlerror("not an array", data);
DialogListItemSetText(item, index, text);
return(NIL);
}
/* :SELECTION Method */
LVAL xslist_item_selection(V)
{
LVAL item, index=NIL;
int set;
item = xsgetlistitem();
set = moreargs();
if (set) index = xlgetarg();
xllastarg();
return(DialogListItemSelection(item, set, index));
}
|