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 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382
|
/* gEDA - GPL Electronic Design Automation
* gschem - gEDA Schematic Capture
* Copyright (C) 1998-2010 Ales Hvezda
* Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
*
* This program 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 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <config.h>
#include <stdio.h>
#include <math.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include "gschem.h"
#include <gdk/gdkkeysyms.h>
#ifdef HAVE_LIBDMALLOC
#include <dmalloc.h>
#endif
/* used by mouse pan */
int start_pan_x, start_pan_y;
int throttle = 0;
/* used for the stroke stuff */
#ifdef HAVE_LIBSTROKE
static int DOING_STROKE = FALSE;
#endif /* HAVE_LIBSTROKE */
/*! \todo Finish function documentation!!!
* \brief
* \par Function Description
*
*/
gint x_event_expose(GtkWidget *widget, GdkEventExpose *event,
GSCHEM_TOPLEVEL *w_current)
{
GdkRectangle *rectangles;
int n_rectangles;
cairo_t *save_cr;
PangoLayout *save_pl;
#if DEBUG
printf("EXPOSE\n");
#endif
exit_if_null(w_current);
/* nasty global variable */
global_window_current = w_current;
save_cr = w_current->cr;
save_pl = w_current->pl;
w_current->cr = gdk_cairo_create( widget->window );
w_current->pl = pango_cairo_create_layout (w_current->cr);
gdk_region_get_rectangles (event->region, &rectangles, &n_rectangles);
o_redraw_rects (w_current, rectangles, n_rectangles);
g_free (rectangles);
/* raise the dialog boxes if this feature is enabled */
if (w_current->raise_dialog_boxes) {
x_dialog_raise_all(w_current);
}
g_object_unref (w_current->pl);
cairo_destroy (w_current->cr);
w_current->cr = save_cr;
w_current->pl = save_pl;
return(0);
}
/*! \todo Finish function documentation!!!
* \brief
* \par Function Description
*
*/
gint x_event_button_pressed(GtkWidget *widget, GdkEventButton *event,
GSCHEM_TOPLEVEL *w_current)
{
TOPLEVEL *toplevel = w_current->toplevel;
int prev_state;
int w_x, w_y;
int unsnapped_wx, unsnapped_wy;
exit_if_null(w_current);
global_window_current = w_current;
#if DEBUG
printf("pressed button %d! \n", event->button);
printf("event state: %d \n", event->state);
printf("w_current state: %d \n", w_current->event_state);
printf("Selection is:\n");
o_selection_print_all(&(toplevel->page_current->selection_list));
printf("\n");
#endif
SCREENtoWORLD (w_current, (int) event->x, (int) event->y,
&unsnapped_wx, &unsnapped_wy);
w_x = snap_grid (w_current, unsnapped_wx);
w_y = snap_grid (w_current, unsnapped_wy);
if (event->type == GDK_2BUTTON_PRESS &&
(w_current->event_state == STARTSELECT ||
w_current->event_state == SELECT)) {
o_find_object(w_current, w_x, w_y, TRUE);
if (o_select_selected (w_current)) {
o_edit(w_current, geda_list_get_glist( toplevel->page_current->selection_list ));
i_set_state(w_current, SELECT);
return(0);
}
}
w_current->SHIFTKEY = (event->state & GDK_SHIFT_MASK ) ? 1 : 0;
w_current->CONTROLKEY = (event->state & GDK_CONTROL_MASK) ? 1 : 0;
w_current->ALTKEY = (event->state & GDK_MOD1_MASK) ? 1 : 0;
if (event->button == 1) {
switch(w_current->event_state) {
case(SELECT):
/* look for grips or fall through if not enabled */
if (!o_grips_start(w_current, unsnapped_wx, unsnapped_wy)) {
/* now go into normal SELECT */
w_current->event_state = STARTSELECT;
w_current->first_wx = w_current->second_wx = unsnapped_wx;
w_current->first_wy = w_current->second_wy = unsnapped_wy;
} else {
/* a grip was found */
w_current->event_state = GRIPS;
w_current->inside_action = 1;
}
break;
case(STARTCOPY):
if (o_select_selected(w_current)) {
o_copy_start(w_current, w_x, w_y);
w_current->event_state = COPY;
w_current->inside_action = 1;
}
break;
case(STARTMCOPY):
if (o_select_selected(w_current)) {
o_copy_start(w_current, w_x, w_y);
w_current->event_state = MCOPY;
w_current->inside_action = 1;
}
break;
case(STARTMOVE):
if (o_select_selected(w_current)) {
o_move_start(w_current, w_x, w_y);
w_current->event_state = MOVE;
w_current->inside_action = 1;
}
break;
case(STARTPASTE):
o_buffer_paste_start(w_current, w_x, w_y, w_current->buffer_number);
w_current->event_state = ENDPASTE;
w_current->inside_action = 1;
break;
case(DRAWLINE):
o_line_start(w_current, w_x, w_y);
w_current->event_state = ENDLINE;
w_current->inside_action = 1;
break;
case(ENDLINE):
o_line_end(w_current, w_x, w_y);
w_current->inside_action = 0;
w_current->event_state = DRAWLINE;
break;
case(DRAWBOX):
o_box_start(w_current, w_x, w_y);
w_current->event_state = ENDBOX;
w_current->inside_action = 1;
break;
case(ENDBOX):
o_box_end(w_current, w_x, w_y);
w_current->inside_action = 0;
w_current->event_state = DRAWBOX;
break;
case(DRAWPICTURE):
o_picture_start(w_current, w_x, w_y);
w_current->event_state = ENDPICTURE;
w_current->inside_action = 1;
break;
case(ENDPICTURE):
o_picture_end(w_current, w_x, w_y);
w_current->inside_action = 0;
w_current->event_state = DRAWPICTURE;
break;
case(DRAWCIRCLE):
o_circle_start(w_current, w_x, w_y);
w_current->event_state = ENDCIRCLE;
w_current->inside_action = 1;
break;
case(ENDCIRCLE):
o_circle_end(w_current, w_x, w_y);
w_current->inside_action = 0;
w_current->event_state = DRAWCIRCLE;
break;
case(DRAWARC):
o_arc_start(w_current, w_x, w_y);
w_current->event_state = ENDARC;
w_current->inside_action = 1;
break;
case(ENDARC):
o_arc_end1(w_current, w_x, w_y);
w_current->inside_action = 0;
w_current->event_state = DRAWARC;
break;
case(DRAWPIN):
o_pin_start(w_current, w_x, w_y);
w_current->event_state = ENDPIN;
w_current->inside_action = 1;
break;
case(ENDPIN):
o_pin_end(w_current, w_x, w_y);
w_current->inside_action = 0;
w_current->event_state = DRAWPIN;
break;
case(STARTDRAWNET): /*! \todo change state name? */
o_net_start(w_current, w_x, w_y);
w_current->inside_action = 1;
w_current->event_state=DRAWNET;
break;
case(STARTDRAWBUS):
o_bus_start(w_current, w_x, w_y);
w_current->inside_action = 1;
w_current->event_state=DRAWBUS;
break;
case(DRAWNET):
case(NETCONT):
/* Only continue the net if net end worked */
if (o_net_end(w_current, w_x, w_y)) {
o_net_start(w_current, w_current->first_wx, w_current->first_wy);
w_current->event_state=NETCONT;
} else { /* cleanup and start a new net */
o_net_invalidate_rubber (w_current);
o_net_reset(w_current);
i_set_state(w_current, STARTDRAWNET);
w_current->inside_action = 0;
}
break;
case(DRAWBUS):
case(BUSCONT):
/* Only continue the net if net end worked */
if (o_bus_end(w_current, w_x, w_y)) {
o_bus_start(w_current, w_current->first_wx, w_current->first_wy);
w_current->event_state=BUSCONT;
} else {
w_current->inside_action=0;
i_set_state(w_current, STARTDRAWBUS);
}
break;
case(ENDCOMP):
o_complex_end(w_current, w_x, w_y, w_current->continue_component_place);
if (!w_current->continue_component_place) {
w_current->inside_action = 0;
i_set_state(w_current, SELECT);
i_update_toolbar(w_current);
}
break;
case(ENDPASTE):
o_place_end(w_current, w_x, w_y, FALSE, NULL);
w_current->inside_action = 0;
i_set_state(w_current, SELECT);
i_update_toolbar(w_current);
break;
case(ENDROTATEP):
prev_state = toplevel->DONT_REDRAW;
toplevel->DONT_REDRAW = 0;
o_rotate_world_update(w_current, w_x, w_y, 90,
geda_list_get_glist(toplevel->page_current->selection_list ));
toplevel->DONT_REDRAW = prev_state;
w_current->inside_action = 0;
i_set_state(w_current, SELECT);
i_update_toolbar(w_current);
break;
case(ENDMIRROR):
o_mirror_world_update(w_current, w_x, w_y,
geda_list_get_glist(
toplevel->page_current->selection_list ));
w_current->inside_action = 0;
i_set_state(w_current, SELECT);
i_update_toolbar(w_current);
break;
case(ENDTEXT):
o_place_end(w_current, w_x, w_y, FALSE, NULL);
w_current->inside_action = 0;
i_set_state(w_current, SELECT);
i_update_toolbar(w_current);
break;
case(STARTPAN):
a_pan(w_current, w_x, w_y);
i_set_state(w_current, SELECT);
i_update_toolbar(w_current);
break;
case(ZOOMBOXSTART):
a_zoom_box_start(w_current, unsnapped_wx, unsnapped_wy);
w_current->event_state = ZOOMBOXEND;
w_current->inside_action = 1;
break;
}
} else if (event->button == 2) {
/* try this out and see how it behaves */
if (w_current->inside_action) {
if (w_current->event_state == ENDCOMP ||
w_current->event_state == ENDTEXT ||
w_current->event_state == ENDMOVE ||
w_current->event_state == ENDCOPY ||
w_current->event_state == ENDMCOPY ||
w_current->event_state == ENDPASTE ) {
return(0);
} else {
i_callback_cancel(w_current, 0, NULL);
return(0);
}
}
switch(w_current->middle_button) {
case(ACTION):
/* determine here if copy or move */
/* for now do move only */
/* make sure the list is not empty */
if (o_select_selected(w_current)) {
/* don't want to search if shift */
/* key is depresed */
if (!w_current->SHIFTKEY) {
o_find_object(w_current, unsnapped_wx, unsnapped_wy, TRUE);
}
} else {
o_select_unselect_all(w_current);
/* don't want to search if shift */
/* key is depresed */
if (!w_current->SHIFTKEY) {
o_find_object(w_current, unsnapped_wx, unsnapped_wy, TRUE);
}
}
if (!o_select_selected(w_current)) {
/* this means the above find did not
* find anything */
w_current->inside_action = 0;
i_set_state(w_current, SELECT);
i_update_toolbar(w_current);
return(0);
}
if (w_current->ALTKEY) {
o_copy_start(w_current, w_x, w_y);
w_current->inside_action = 1;
i_set_state(w_current, COPY);
} else {
o_move_start(w_current, w_x, w_y);
w_current->inside_action = 1;
i_set_state(w_current, MOVE);
}
break;
case(REPEAT):
if (w_current->last_callback != NULL) {
(*w_current->last_callback)(w_current, 0, NULL);
}
break;
#ifdef HAVE_LIBSTROKE
case(STROKE):
DOING_STROKE=TRUE;
break;
#endif /* HAVE_LIBSTROKE */
case(MID_MOUSEPAN_ENABLED):
w_current->event_state = MOUSEPAN; /* start */
w_current->inside_action = 1;
w_current->doing_pan = TRUE;
start_pan_x = (int) event->x;
start_pan_y = (int) event->y;
throttle=0;
break;
}
} else if (event->button == 3) {
if (!w_current->inside_action) {
if (w_current->third_button == POPUP_ENABLED) {
i_update_menus(w_current); /* update menus before popup */
do_popup(w_current, event);
} else {
w_current->event_state = MOUSEPAN; /* start */
w_current->inside_action = 1;
w_current->doing_pan = TRUE;
start_pan_x = (int) event->x;
start_pan_y = (int) event->y;
throttle=0;
}
} else { /* this is the default cancel */
switch (w_current->event_state) {
case(STARTDRAWNET):
case(DRAWNET):
case(NETCONT):
w_current->inside_action = 0;
i_set_state(w_current, STARTDRAWNET);
o_net_invalidate_rubber (w_current);
o_net_reset(w_current);
break;
case(STARTDRAWBUS):
case(DRAWBUS):
case(BUSCONT):
w_current->inside_action = 0;
i_set_state(w_current, STARTDRAWBUS);
o_bus_invalidate_rubber (w_current);
break;
case(DRAWPIN):
case(ENDPIN):
w_current->inside_action = 0;
i_set_state(w_current, DRAWPIN);
o_pin_invalidate_rubber (w_current);
break;
case(DRAWLINE):
case(ENDLINE):
w_current->inside_action = 0;
i_set_state(w_current, DRAWLINE);
o_line_invalidate_rubber (w_current);
break;
case(DRAWBOX):
case(ENDBOX):
w_current->inside_action = 0;
i_set_state(w_current, DRAWBOX);
o_box_invalidate_rubber (w_current);
break;
case(DRAWPICTURE):
case(ENDPICTURE):
w_current->inside_action = 0;
i_set_state(w_current, DRAWPICTURE);
o_picture_invalidate_rubber (w_current);
break;
case(DRAWCIRCLE):
case(ENDCIRCLE):
w_current->inside_action = 0;
i_set_state(w_current, DRAWCIRCLE);
o_circle_invalidate_rubber (w_current);
break;
case(DRAWARC):
case(ENDARC):
w_current->inside_action = 0;
i_set_state(w_current, DRAWARC);
o_arc_invalidate_rubber (w_current);
break;
default:
i_callback_cancel(w_current, 0, NULL);
break;
}
i_update_toolbar(w_current);
}
}
return(0);
}
/*! \todo Finish function documentation!!!
* \brief
* \par Function Description
*
*/
gint x_event_button_released(GtkWidget *widget, GdkEventButton *event,
GSCHEM_TOPLEVEL *w_current)
{
TOPLEVEL *toplevel = w_current->toplevel;
int prev_state;
int w_x, w_y;
int unsnapped_wx, unsnapped_wy;
exit_if_null(w_current);
global_window_current = w_current;
#if DEBUG
printf("released! %d \n", w_current->event_state);
#endif
w_current->SHIFTKEY = (event->state & GDK_SHIFT_MASK ) ? 1 : 0;
w_current->CONTROLKEY = (event->state & GDK_CONTROL_MASK) ? 1 : 0;
w_current->ALTKEY = (event->state & GDK_MOD1_MASK) ? 1 : 0;
SCREENtoWORLD (w_current, (int) event->x, (int) event->y,
&unsnapped_wx, &unsnapped_wy);
w_x = snap_grid (w_current, unsnapped_wx);
w_y = snap_grid (w_current, unsnapped_wy);
if (event->button == 1) {
switch(w_current->event_state) {
case(SELECT):
/* do nothing */
break;
case(MOVE):
w_current->event_state = ENDMOVE;
break;
case(COPY):
w_current->event_state = ENDCOPY;
break;
case(MCOPY):
w_current->event_state = ENDMCOPY;
break;
case(GRIPS):
o_grips_end(w_current),
w_current->inside_action = 0;
i_set_state(w_current, SELECT);
i_update_toolbar(w_current);
break;
case(ENDMOVE):
o_move_end(w_current);
/* having this stay in copy was driving me nuts*/
w_current->inside_action = 0;
i_set_state(w_current, SELECT);
i_update_toolbar(w_current);
break;
case(ENDCOPY):
o_copy_end(w_current);
/* having this stay in copy was driving me nuts*/
w_current->inside_action = 0;
i_set_state(w_current, SELECT);
i_update_toolbar(w_current);
break;
case(ENDMCOPY):
o_copy_multiple_end(w_current);
/* having this stay in copy was driving me nuts*/
w_current->inside_action = 1;
/* Keep the state and the inside_action, as the copy has not finished. */
i_set_state(w_current, ENDMCOPY);
i_update_toolbar(w_current);
o_undo_savestate(w_current, UNDO_ALL);
break;
case(SBOX):
o_select_box_end(w_current, unsnapped_wx, unsnapped_wy);
w_current->inside_action = 0;
i_set_state(w_current, SELECT);
i_update_toolbar(w_current);
break;
case(ZOOMBOXEND):
a_zoom_box_end(w_current, unsnapped_wx, unsnapped_wy);
w_current->inside_action = 0;
i_set_state(w_current, SELECT);
i_update_toolbar(w_current);
break;
case(STARTSELECT):
/* first look for grips */
if (!o_grips_start(w_current, unsnapped_wx, unsnapped_wy)) {
/* now go looking for objects to select */
o_find_object(w_current, unsnapped_wx, unsnapped_wy, TRUE);
w_current->event_state = SELECT;
w_current->inside_action = 0;
} else {
/* an grip was found */
w_current->event_state = GRIPS;
w_current->inside_action = 1;
}
break;
}
} else if (event->button == 2) {
if (w_current->inside_action) {
if (w_current->event_state == ENDCOMP ||
w_current->event_state == ENDTEXT ||
w_current->event_state == ENDMOVE ||
w_current->event_state == ENDCOPY ||
w_current->event_state == ENDMCOPY ||
w_current->event_state == ENDPASTE ) {
if (w_current->event_state == ENDMOVE) {
o_move_invalidate_rubber (w_current, FALSE);
} else {
o_place_invalidate_rubber (w_current, FALSE);
}
w_current->rubber_visible = 0;
o_place_rotate(w_current);
if (w_current->event_state == ENDCOMP) {
/* Run the complex place list changed hook without redrawing */
/* since all objects are being redrawn afterwards */
prev_state = toplevel->DONT_REDRAW;
toplevel->DONT_REDRAW = 1;
o_complex_place_changed_run_hook (w_current);
toplevel->DONT_REDRAW = prev_state;
}
if (w_current->event_state == ENDMOVE) {
o_move_invalidate_rubber (w_current, TRUE);
} else {
o_place_invalidate_rubber (w_current, TRUE);
}
w_current->rubber_visible = 1;
return(0);
}
}
switch(w_current->middle_button) {
case(ACTION):
switch(w_current->event_state) {
case(MOVE):
o_move_end(w_current);
w_current->inside_action = 0;
i_set_state(w_current, SELECT);
i_update_toolbar(w_current);
break;
case(COPY):
o_copy_end(w_current);
w_current->inside_action = 0;
i_set_state(w_current, SELECT);
i_update_toolbar(w_current);
break;
}
break;
#ifdef HAVE_LIBSTROKE
case(STROKE):
DOING_STROKE = FALSE;
x_stroke_translate_and_execute (w_current);
break;
#endif /* HAVE_LIBSTROKE */
case(MID_MOUSEPAN_ENABLED):
w_current->doing_pan=FALSE;
o_invalidate_all (w_current);
if (w_current->undo_panzoom) {
o_undo_savestate(w_current, UNDO_VIEWPORT_ONLY);
}
/* this needs to be REDONE */
/* if you mouse pan, you will be thrown out of the current mode. */
/* not good */
w_current->inside_action = 0;
i_set_state(w_current, SELECT);
i_update_toolbar(w_current);
break;
}
} else if (event->button == 3) {
if (w_current->doing_pan) { /* just for ending a mouse pan */
w_current->doing_pan=FALSE;
o_invalidate_all (w_current);
if (w_current->undo_panzoom) {
o_undo_savestate(w_current, UNDO_VIEWPORT_ONLY);
}
/* this needs to be REDONE */
/* if you mouse pan, you will be thrown out of the current mode. */
/* not good */
w_current->inside_action = 0;
i_set_state(w_current, SELECT);
i_update_toolbar(w_current);
}
}
return(0);
}
/*! \todo Finish function documentation!!!
* \brief
* \par Function Description
*
*/
gint x_event_motion(GtkWidget *widget, GdkEventMotion *event,
GSCHEM_TOPLEVEL *w_current)
{
int pdiff_x, pdiff_y;
int w_x, w_y;
int unsnapped_wx, unsnapped_wy;
int skip_event=0;
GdkEvent *test_event;
exit_if_null(w_current);
global_window_current = w_current;
w_current->SHIFTKEY = (event->state & GDK_SHIFT_MASK ) ? 1 : 0;
w_current->CONTROLKEY = (event->state & GDK_CONTROL_MASK) ? 1 : 0;
w_current->ALTKEY = (event->state & GDK_MOD1_MASK) ? 1 : 0;
#if DEBUG
/* printf("MOTION!\n");*/
#endif
#ifdef HAVE_LIBSTROKE
if (DOING_STROKE == TRUE) {
x_stroke_record (w_current, event->x, event->y);
return(0);
}
#endif /* HAVE_LIBSTROKE */
/* skip the moving event if there are other moving events in the
gdk event queue (Werner)
Only skip the event if is the same event and no buttons or modifier
keys changed*/
if ((test_event = gdk_event_get()) != NULL) {
if (test_event->type == GDK_MOTION_NOTIFY
&& ((GdkEventMotion *) test_event)->state == event->state) {
skip_event= 1;
}
gdk_event_put(test_event); /* put it back in front of the queue */
gdk_event_free(test_event);
if (skip_event == 1)
return 0;
}
SCREENtoWORLD (w_current, (int) event->x, (int) event->y,
&unsnapped_wx, &unsnapped_wy);
w_x = snap_grid (w_current, unsnapped_wx);
w_y = snap_grid (w_current, unsnapped_wy);
if (w_current->cowindow) {
coord_display_update(w_current, (int) event->x, (int) event->y);
}
if (w_current->third_button == MOUSEPAN_ENABLED || w_current->middle_button == MID_MOUSEPAN_ENABLED) {
if((w_current->event_state == MOUSEPAN) &&
w_current->inside_action) {
pdiff_x = (int) event->x - start_pan_x;
pdiff_y = (int) event->y - start_pan_y;
if (!(throttle % 5)) {
a_pan_mouse(w_current, pdiff_x*w_current->mousepan_gain,
pdiff_y*w_current->mousepan_gain);
start_pan_x = (int) event->x;
start_pan_y = (int) event->y;
}
throttle++;
return(0);
}
}
switch(w_current->event_state) {
case(SELECT):
/* do nothing */
break;
case(GRIPS):
o_grips_motion(w_current, w_x, w_y);
break;
case(STARTSELECT):
if ( (!w_current->drag_can_move) ||
(w_current->drag_can_move &&
(! o_find_selected_object(w_current,
w_current->first_wx, w_current->first_wy)))) {
if (o_select_box_start(w_current, unsnapped_wx, unsnapped_wy)) {
w_current->event_state = SBOX;
w_current->inside_action = 1;
}
break;
} else {
/* Start the object movement */
o_move_start(w_current, w_x, w_y);
w_current->event_state = ENDMOVE;
w_current->inside_action = 1;
}
/* Fall through */
case(ENDMOVE):
case(MOVE):
if (w_current->inside_action)
o_move_motion (w_current, w_x, w_y);
break;
case(ENDLINE):
if (w_current->inside_action)
o_line_motion (w_current, w_x, w_y);
break;
case(ENDBOX):
if (w_current->inside_action)
o_box_motion ( w_current, w_x, w_y);
break;
case(ENDPICTURE):
if (w_current->inside_action)
o_picture_motion ( w_current, w_x, w_y);
break;
case(ENDCIRCLE):
if (w_current->inside_action)
o_circle_motion (w_current, w_x, w_y);
break;
case(ENDARC):
if (w_current->inside_action)
o_arc_motion (w_current, w_x, w_y, ARC_RADIUS);
break;
case(STARTDRAWNET):
if(w_current->magneticnet_mode == 1) {
o_net_start_magnetic(w_current, w_x, w_y);
}
break;
case(DRAWNET):
case(NETCONT):
if (w_current->inside_action)
o_net_motion (w_current, w_x, w_y);
break;
case(DRAWBUS):
case(BUSCONT):
if (w_current->inside_action)
o_bus_motion (w_current, w_x, w_y);
break;
case(ENDPIN):
if (w_current->inside_action)
o_pin_motion (w_current, w_x, w_y);
break;
case(COPY):
case(MCOPY):
case(ENDCOPY):
case(ENDMCOPY):
case(ENDCOMP):
case(ENDPASTE):
case(ENDTEXT):
o_place_motion (w_current, w_x, w_y);
break;
case(SBOX):
if (w_current->inside_action)
o_select_box_motion (w_current, unsnapped_wx, unsnapped_wy);
break;
case(ZOOMBOXEND):
if (w_current->inside_action)
a_zoom_box_motion (w_current, unsnapped_wx, unsnapped_wy);
break;
}
return(0);
}
/*! \brief Updates the GSCHEM_TOPLEVEL and display when drawing area is configured.
* \par Function Description
* This is the callback function connected to the configure event of
* the drawing area of the main window.
*
* It updates the size of the backingstore for the associated
* toplevel structure (creates a new pixmap) and re-pans each of its
* pages to keep their contents centered in the drawing area.
*
* When the window is maximised, the zoom of every page is changed to
* best fit the previously displayed area of the page in the new
* area. Otherwise the current zoom level is left unchanged.
*
* \param [in] widget The drawing area which received the signal.
* \param [in] event The event structure of signal configure-event.
* \param [in] user_data The toplevel environment as user data.
* \returns FALSE to propagate the event further.
*/
gboolean
x_event_configure (GtkWidget *widget,
GdkEventConfigure *event,
gpointer user_data)
{
GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*)user_data;
TOPLEVEL *toplevel = w_current->toplevel;
GList *iter;
PAGE *old_page_current, *p_current;
gint old_win_width, old_win_height, new_win_width, new_win_height;
gdouble relativ_zoom_factor = 1.0;
g_assert (toplevel != NULL);
global_window_current = w_current;
if (toplevel->page_current == NULL) {
/* don't want to call this if the current page isn't setup yet */
return FALSE;
}
old_win_width = w_current->win_width;
old_win_height = w_current->win_height;
new_win_width = event->width;
new_win_height = event->height;
if (old_win_width == new_win_width &&
old_win_height == new_win_height) {
/* the size of the drawing area has not changed */
/* nothing to do here */
return FALSE;
}
w_current->drawable = w_current->window;
/* update the GSCHEM_TOPLEVEL with new size of drawing area */
w_current->win_width = toplevel->width = new_win_width;
w_current->win_height = toplevel->height = new_win_height;
/* in the case the user has maximised the window (hence the */
/* configure event) fit the view by playing with zoom level */
if (gdk_window_get_state (
(gtk_widget_get_toplevel (
widget))->window) & GDK_WINDOW_STATE_MAXIMIZED) {
gdouble width_ratio, height_ratio;
/* tweak relative_zoom to better fit page in maximized window */
width_ratio = ((gdouble)new_win_width) / ((gdouble)old_win_width);
height_ratio = ((gdouble)new_win_height) / ((gdouble)old_win_height);
/* keep smallest ratio as relative zoom factor when panning */
relativ_zoom_factor =
(width_ratio < height_ratio) ? width_ratio : height_ratio;
}
/* save current page */
old_page_current = toplevel->page_current;
/* re-pan each page of the TOPLEVEL */
for ( iter = geda_list_get_glist( toplevel->pages );
iter != NULL;
iter = g_list_next( iter ) ) {
gdouble cx, cy;
p_current = (PAGE *)iter->data;
/* doing this the aspectratio is kept when changing (hw)*/
cx = ((gdouble)(p_current->left + p_current->right)) / 2;
cy = ((gdouble)(p_current->top + p_current->bottom)) / 2;
s_page_goto (toplevel, p_current);
a_pan_general (w_current, cx, cy, relativ_zoom_factor, A_PAN_DONT_REDRAW);
}
/* restore current page to saved value */
s_page_goto (toplevel, old_page_current);
if (!toplevel->DONT_REDRAW) {
/* redraw the current page and update UI */
o_invalidate_all (w_current);
x_scrollbars_update (w_current);
}
return FALSE;
}
/*! \todo Finish function documentation!!!
* \brief
* \par Function Description
*
* \note
* this is used during an open command
* to setup the correct sizes
*/
void x_manual_resize(GSCHEM_TOPLEVEL *w_current)
{
TOPLEVEL *toplevel = w_current->toplevel;
/* of the actual win window (drawing_area) */
w_current->win_width = w_current->drawing_area->allocation.width;
w_current->win_height = w_current->drawing_area->allocation.height;
#if DEBUG
printf("manual: %d %d\n", w_current->win_width, w_current->win_height);
#endif
toplevel->width = w_current->win_width;
toplevel->height = w_current->win_height;
/* need to do this every time you change width / height */
set_window(toplevel, toplevel->page_current,
toplevel->page_current->left,
toplevel->page_current->right,
toplevel->page_current->top,
toplevel->page_current->bottom);
#if DEBUG
printf("Window aspect: %f\n",
(float) w_current->win_width / (float) w_current->win_height);
/* No longer used?
printf("w: %d h: %d\n", width, height); */
printf("aw: %d ah: %d\n", w_current->win_width, w_current->win_height);
#endif
}
/*! \todo Finish function documentation!!!
* \brief
* \par Function Description
*
*/
void x_event_hschanged (GtkAdjustment *adj, GSCHEM_TOPLEVEL *w_current)
{
TOPLEVEL *toplevel = w_current->toplevel;
int current_left;
int new_left;
GtkAdjustment *hadjustment;
exit_if_null(w_current);
global_window_current = w_current;
if (w_current->scrollbars_flag == FALSE) {
return;
}
hadjustment =
gtk_range_get_adjustment(GTK_RANGE(w_current->h_scrollbar));
current_left = toplevel->page_current->left;
new_left = (int) hadjustment->value;
toplevel->page_current->left = new_left;
toplevel->page_current->right =
toplevel->page_current->right -
(current_left - new_left);
if (!toplevel->DONT_REDRAW) {
o_invalidate_all (w_current);
}
}
/*! \todo Finish function documentation!!!
* \brief
* \par Function Description
*
*/
void x_event_vschanged (GtkAdjustment *adj, GSCHEM_TOPLEVEL *w_current)
{
TOPLEVEL *toplevel = w_current->toplevel;
int current_bottom;
int new_bottom;
GtkAdjustment *vadjustment;
exit_if_null(w_current);
global_window_current = w_current;
if (w_current->scrollbars_flag == FALSE) {
return;
}
vadjustment = gtk_range_get_adjustment(
GTK_RANGE(w_current->v_scrollbar));
current_bottom = toplevel->page_current->bottom;
new_bottom = toplevel->init_bottom - (int) vadjustment->value;
toplevel->page_current->bottom = new_bottom;
toplevel->page_current->top =
toplevel->page_current->top -
(current_bottom - new_bottom);
#if DEBUG
printf("vrange %f %f\n", vadjustment->lower, vadjustment->upper);
printf("vvalue %f\n", vadjustment->value);
printf("actual: %d %d\n", toplevel->page_current->top,
toplevel->page_current->bottom);
#endif
if (!toplevel->DONT_REDRAW) {
o_invalidate_all (w_current);
}
}
/*! \todo Finish function documentation!!!
* \brief
* \par Function Description
*
*/
gint x_event_enter(GtkWidget *widget, GdkEventCrossing *event,
GSCHEM_TOPLEVEL *w_current)
{
exit_if_null(w_current);
global_window_current = w_current;
/* do nothing or now */
return(0);
}
/*! \brief Get a snapped pointer position in world coordinates
*
* \par Function Description
* Queries GTK for the mouse location in world coordinates,
* then snaps it to the grid.
*
* \param [in] w_current The GSCHEM_TOPLEVEL object.
* \param [out] wx Return location for the snapped X coordinate.
* \param [out] wy Return location for the snapped Y coordiante.
*/
static void get_snapped_pointer (GSCHEM_TOPLEVEL *w_current, int *wx, int *wy)
{
int sx, sy;
int unsnapped_wx, unsnapped_wy;
gtk_widget_get_pointer (w_current->drawing_area, &sx, &sy);
SCREENtoWORLD (w_current, sx, sy, &unsnapped_wx, &unsnapped_wy);
*wx = snap_grid (w_current, unsnapped_wx);
*wy = snap_grid (w_current, unsnapped_wy);
}
/*! \todo Finish function documentation!!!
* \brief
* \par Function Description
*
*/
gboolean x_event_key (GtkWidget *widget, GdkEventKey *event,
GSCHEM_TOPLEVEL *w_current)
{
gboolean retval = FALSE;
int wx, wy;
int alt_key = 0;
int shift_key = 0;
int control_key = 0;
int pressed;
global_window_current = w_current;
#if DEBUG
printf("x_event_key_pressed: Pressed key %i.\n", event->keyval);
#endif
/* update the state of the modifiers */
w_current->ALTKEY = (event->state & GDK_MOD1_MASK) ? 1 : 0;
w_current->SHIFTKEY = (event->state & GDK_SHIFT_MASK) ? 1 : 0;
w_current->CONTROLKEY = (event->state & GDK_CONTROL_MASK) ? 1 : 0;
pressed = (event->type == GDK_KEY_PRESS) ? 1 : 0;
switch (event->keyval) {
case GDK_Alt_L:
case GDK_Alt_R:
alt_key = 1;
w_current->ALTKEY = pressed;
break;
case GDK_Shift_L:
case GDK_Shift_R:
shift_key = 1;
w_current->SHIFTKEY = pressed;
break;
case GDK_Control_L:
case GDK_Control_R:
control_key = 1;
w_current->CONTROLKEY = pressed;
break;
}
switch (w_current->event_state) {
case ENDLINE:
if (control_key) {
get_snapped_pointer (w_current, &wx, &wy);
o_line_motion (w_current, wx, wy);
}
break;
case STARTDRAWNET:
if (control_key) {
get_snapped_pointer (w_current, &wx, &wy);
o_net_start_magnetic(w_current, wx, wy);
}
break;
case DRAWNET:
case NETCONT:
if (shift_key || control_key) {
get_snapped_pointer (w_current, &wx, &wy);
o_net_motion (w_current, wx, wy);
}
break;
case DRAWBUS:
case BUSCONT:
if (control_key) {
get_snapped_pointer (w_current, &wx, &wy);
o_bus_motion (w_current, wx, wy);
}
break;
case ENDMOVE:
if (control_key) {
get_snapped_pointer (w_current, &wx, &wy);
o_move_motion (w_current, wx, wy);
}
break;
case ENDCOMP: /* FIXME: This state shouldn't respond to modifier keys */
case ENDPASTE: /* FIXME: This state shouldn't respond to modifier keys */
case ENDTEXT: /* FIXME: This state shouldn't respond to modifier keys */
case ENDCOPY:
case ENDMCOPY:
if (control_key) {
get_snapped_pointer (w_current, &wx, &wy);
o_place_motion (w_current, wx, wy);
}
break;
}
if (pressed)
retval = g_keys_execute (w_current, event->state, event->keyval)
? TRUE : FALSE;
return retval;
}
/*! \todo Finish function documentation!!!
* \brief
* \par Function Description
*
*/
gint x_event_scroll (GtkWidget *widget, GdkEventScroll *event,
GSCHEM_TOPLEVEL *w_current)
{
GtkAdjustment *adj;
gboolean pan_xaxis = FALSE;
gboolean pan_yaxis = FALSE;
gboolean zoom = FALSE;
int pan_direction = 1;
int zoom_direction = ZOOM_IN;
exit_if_null(w_current);
global_window_current = w_current;
/* update the state of the modifiers */
w_current->SHIFTKEY = (event->state & GDK_SHIFT_MASK ) ? 1 : 0;
w_current->CONTROLKEY = (event->state & GDK_CONTROL_MASK) ? 1 : 0;
w_current->ALTKEY = (event->state & GDK_MOD1_MASK) ? 1 : 0;
if (w_current->scroll_wheel == SCROLL_WHEEL_CLASSIC) {
/* Classic gschem behaviour */
zoom = !w_current->CONTROLKEY && !w_current->SHIFTKEY;
pan_yaxis = !w_current->CONTROLKEY && w_current->SHIFTKEY;
pan_xaxis = w_current->CONTROLKEY && !w_current->SHIFTKEY;
} else {
/* GTK style behaviour */
zoom = w_current->CONTROLKEY && !w_current->SHIFTKEY;
pan_yaxis = !w_current->CONTROLKEY && !w_current->SHIFTKEY;
pan_xaxis = !w_current->CONTROLKEY && w_current->SHIFTKEY;
}
/* If the user has a left/right scroll wheel, always scroll the y-axis */
if (event->direction == GDK_SCROLL_LEFT ||
event->direction == GDK_SCROLL_RIGHT) {
zoom = FALSE;
pan_yaxis = FALSE;
pan_xaxis = TRUE;
}
/* You must have scrollbars enabled if you want to use the scroll wheel to pan */
if (!w_current->scrollbars_flag) {
pan_xaxis = FALSE;
pan_yaxis = FALSE;
}
switch (event->direction) {
case GDK_SCROLL_UP:
case GDK_SCROLL_LEFT:
pan_direction = -1;
zoom_direction = ZOOM_IN;
break;
case GDK_SCROLL_DOWN:
case GDK_SCROLL_RIGHT:
pan_direction = 1;
zoom_direction = ZOOM_OUT;
break;
}
if (zoom) {
/*! \todo Change "HOTKEY" TO new "MOUSE" specifier? */
a_zoom(w_current, zoom_direction, HOTKEY, 0);
}
if (pan_xaxis) {
adj = gtk_range_get_adjustment(GTK_RANGE(w_current->h_scrollbar));
gtk_adjustment_set_value(adj, min(adj->value + pan_direction *
(adj->page_increment /
w_current->scrollpan_steps),
adj->upper - adj->page_size));
}
if (pan_yaxis) {
adj = gtk_range_get_adjustment(GTK_RANGE(w_current->v_scrollbar));
gtk_adjustment_set_value(adj, min(adj->value + pan_direction *
(adj->page_increment /
w_current->scrollpan_steps),
adj->upper - adj->page_size));
}
if (w_current->undo_panzoom && (zoom || pan_xaxis || pan_yaxis)) {
o_undo_savestate(w_current, UNDO_VIEWPORT_ONLY);
}
return 0;
}
/*! \brief get the pointer position of a given GSCHEM_TOPLEVEL
* \par Function Description
* This function gets the pointer position of the drawing area of the
* current workspace <b>GSCHEM_TOPLEVEL</b>. The flag <b>snapped</b> specifies
* whether the pointer position should be snapped to the current grid.
*
* \param [in] w_current The GSCHEM_TOPLEVEL object.
* \param [in] snapped An option flag to specify the wished coords
* \param [out] wx snapped/unsnapped world x coordinate
* \param [out] wy snapped/unsnapped world y coordinate
*
* \return Returns TRUE if the pointer position is inside the drawing area.
*
*/
gboolean x_event_get_pointer_position (GSCHEM_TOPLEVEL *w_current,
gboolean snapped,
gint *wx, gint *wy)
{
int sx, sy, x, y;
gtk_widget_get_pointer(w_current->drawing_area, &sx, &sy);
/* check if we are inside the drawing area */
if (sx < 0 || sx >= w_current->win_width
|| sy <0 || sy >= w_current->win_height)
return FALSE;
SCREENtoWORLD (w_current, sx, sy, &x, &y);
if (snapped) {
x = snap_grid (w_current, x);
y = snap_grid (w_current, y);
}
*wx = x;
*wy = y;
return TRUE;
}
|