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
|
/**
* @file callbacks.c
* @brief Callbacks for the various interface widgets.
*
* Routines for handling interaction with the ygraph interface.
*
* @author Denis Pollney
* @date 1 Oct 2001
*
* @par Copyright (C) 2001-2002 Denis Pollney
*
* 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, or (at your option)
* any later version.
* @par
* 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
* @par
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <gdk/gdkkeysyms.h>
#include <stdlib.h>
#include <stdio.h>
#include "ygraph.h"
guint motion_id;
GtkWidget* file_entry_A = NULL;
/*
* PLOT WINDOW CALLBACKS.
*/
/**
* @brief Configure the plot window.
*
* @param plot_area The plot area widget to be drawn.
* @param event The calling event.
* @param plot The Plot to be drawn.
* @returns FALSE to propagate the event even further
*/
gboolean
plot_window_configure(GtkWidget* plot_area, GdkEventConfigure* event,
Plot* plot)
{
YDEB("plot_window_configure\n");
UNUSED(event);
if (plot->pixmap)
gdk_pixmap_unref(plot->pixmap);
plot->pixmap = gdk_pixmap_new(plot_area->window,
plot_area->allocation.width,
plot_area->allocation.height,
-1);
plot_window_expunge(plot);
plot_window_reconfigure(plot);
return FALSE;
}
/**
* @brief Expose the plot window.
*
* @param plot_area The plot area widget to be drawn.
* @param event The calling event.
* @param plot The Plot to be drawn.
* @returns TRUE if successful, crash if not.
*/
gboolean
plot_window_expose(GtkWidget* plot_area, GdkEventExpose* event, Plot* plot)
{
YDEB("plot_window_expose\n");
axis_draw(plot);
legend_draw(plot);
plot_window_draw_time(plot);
plot_area_draw(plot);
gdk_draw_pixmap(plot_area->window,
plot_area->style->fg_gc[GTK_WIDGET_STATE(plot_area)],
plot->pixmap,
event->area.x, event->area.y,
event->area.x, event->area.y,
event->area.width, event->area.height);
return TRUE;
}
/**
* @brief Destroy the plot window.
*
* @param plot_area The plot area widget to be destroyed.
* @param event The calling event.
* @param plot The Plot in question.
* @returns TRUE if successful, crash if not.
*/
gboolean
plot_window_destroy(GtkWidget* plot_area, GdkEventConfigure* event,
Plot* plot)
{
Plot* check_plot;
guint i;
UNUSED(plot_area);
UNUSED(event);
for (i=0; i<global_plot_window->len; ++i)
{
check_plot = g_array_index(global_plot_window, Plot*, i);
if (check_plot->plot_nbr == plot->plot_nbr)
{
g_array_remove_index(global_plot_window, i);
break;
}
}
gtk_widget_destroy(plot->window);
plot_free(plot);
return TRUE;
}
void
plot_window_close(Plot* plot, gint action, GtkItem* file_select_button)
{
UNUSED(action);
UNUSED(file_select_button);
plot_window_destroy(NULL, NULL, plot);
}
/**
* @brief Determine the location of the pointer.
*
* This routine determines the location of the pointer whenever
* it has been moved. In the case that the right-button has
* been clicked (in which case plot->zoom_x_start will have
* been set) then it calls a routine to zoom the axes according
* to the pointer location.
*
* @param plot_area The plot area widget.
* @param event The calling event.
* @param plot The Plot in question.
* @returns TRUE if successful, crash if not.
*/
gboolean
plot_area_motion_notify_event(GtkWidget* plot_area, GdkEventMotion* event,
Plot* plot)
{
GdkModifierType state;
gint x;
gint y;
UNUSED(plot_area);
if (event->is_hint)
gdk_window_get_pointer(event->window, &x, &y, &state);
else
{
x = event->x;
y = event->y;
state = event->state;
}
if ((state & GDK_BUTTON1_MASK) && (plot->zoom_x_start != NO_ZOOM))
plot_area_zoom_rectangle_draw(plot, x, y);
return TRUE;
}
/**
* @brief Handle a button release in the plot area.
*
* If the program is not ready for a zoom (zoom_x_start has
* not been set) then just return. Otherwise call the zoom
* function with the pointer location.
*
* @param plot_area The plot area widget to be closed.
* @param event The calling event.
* @param plot The Plot in question.
* @returns TRUE if successful, crash if not.
*/
gboolean
plot_area_button_release_event(GtkWidget* plot_area, GdkEventButton* event,
Plot* plot)
{
UNUSED(plot_area);
if (plot->zoom_x_start == NO_ZOOM)
return TRUE;
if (event->button == 1)
plot_area_zoom_finish(plot, event->x, event->y);
return TRUE;
}
/**
* @brief Handle a button press in the plot area.
*
* When the button has been pressed, call the function to
* record the upper left-hand corner of the zoom box.
* If the right button is pressed, a popup showing the location
* of the pointer is presented.
*
* @param plot_area The plot area widget to be closed.
* @param event The calling event.
* @param plot The Plot in question.
* @returns TRUE if successful, crash if not.
*/
gboolean
plot_area_button_press_event(GtkWidget* plot_area, GdkEventButton* event,
Plot* plot)
{
UNUSED(plot_area);
if (event->button == 1)
plot_area_zoom_start(plot, event->x, event->y);
else if (event->button == 3)
plot_area_write_location(plot, event->x, event->y);
return TRUE;
}
/**
* @brief Handle an unzoom event.
*
* If the unzoom event is called, then reset the axis ranges
* to their original value and redraw the plot.
*
* @param plot The Plot in question.
* @returns void
*/
void
plot_window_unzoom(Plot* plot)
{
/* If there was no zoom, just return */
if (!plot->zoom_history_start || !plot->zoom_history_start)
return;
/* remove the last entry in the zoom history */
g_array_remove_index(plot->zoom_history_start,
plot->zoom_history_start->len-1);
g_array_remove_index(plot->zoom_history_end,
plot->zoom_history_end->len-1);
/* if the array is empty now, free the memory */
if (plot->zoom_history_start->len==0)
{
plot->fixed_range = FALSE;
g_array_free(plot->zoom_history_start, TRUE);
plot->zoom_history_start=NULL;
}
if (plot->zoom_history_end->len==0)
{
plot->fixed_range = FALSE;
g_array_free(plot->zoom_history_end, TRUE);
plot->zoom_history_end=NULL;
}
/* If it is still fixed range (== zoomed), then emulate the zoom done by
* clicking into the window */
if (plot->fixed_range==TRUE)
{
plot->x_range[0] = g_array_index(plot->zoom_history_start, Point_Double,
plot->zoom_history_start->len-1).x;
plot->y_range[0] = g_array_index(plot->zoom_history_start, Point_Double,
plot->zoom_history_start->len-1).y;
plot->x_range[1] = g_array_index(plot->zoom_history_end, Point_Double,
plot->zoom_history_end->len-1).x;
plot->y_range[1] = g_array_index(plot->zoom_history_end, Point_Double,
plot->zoom_history_end->len-1).y;
}
plot_window_reconfigure(plot);
plot_window_display_all(plot);
return;
}
/**
* @brief Open a blank new plot window.
*/
void
plot_window_empty_new(void)
{
GArray* data;
Plot* plot;
YDEB("plot_window_empty_new\n");
data = g_array_new(FALSE, FALSE, sizeof(gint));
plot = plot_data_init(data);
gtk_widget_show(plot->window);
}
/*
* FILE SELECTION CALLBACKS.
*/
/**
* @brief Act on the result of a file selection.
*
* Gets the filename returned by a file selection dialog
* and reads the specified file. Any new datasets are
* appended to the existing list and the plot is redrawn.
*
* @param ok_button The button which initiated the callback.
* @param fs The file selection dialog.
* @returns TRUE if successful.
*/
gboolean
file_select_read(GtkObject* ok_button, GtkFileSelection* fs)
{
GArray* new_data_array;
Plot* plot;
gint new_data_set_idx;
gchar* filename;
UNUSED(ok_button);
filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(fs));
new_data_set_idx = dataset_read_from_file(filename, option_read_skip_step);
if (new_data_set_idx == FAIL)
return TRUE;
plot = gtk_object_get_data(GTK_OBJECT(fs), "plot");
if (plot == NULL)
{
new_data_array = g_array_new(FALSE, FALSE, sizeof(gint));
g_array_append_val(new_data_array, new_data_set_idx);
plot = plot_data_init(new_data_array);
plot_window_show();
}
else
plot_data_append(plot, new_data_set_idx);
if (plot->current_directory)
g_free(plot->current_directory);
plot->current_directory = g_strdup_printf("%s/", g_dirname(filename));
plot_window_display_all(plot);
return TRUE;
}
/**
* @brief Creates a file selection dialog box for reading data into the
* existing window.
*
* @param plot The Plot to which any new data should be
* added.
* @param action The action initiating the call.
* @param file_select_button The button initiating the call.
*/
void
file_select(Plot* plot, gint action, GtkItem* file_select_button)
{
GtkWidget* fs;
UNUSED(action);
UNUSED(file_select_button);
fs = gtk_file_selection_new(FILE_SELECTION_TITLE);
gtk_file_selection_set_filename(GTK_FILE_SELECTION(fs),
plot->current_directory);
gtk_object_set_data(GTK_OBJECT(fs), "plot", plot);
gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(fs)->ok_button),
"clicked", GTK_SIGNAL_FUNC(file_select_read), fs);
gtk_signal_connect_object(GTK_OBJECT(GTK_FILE_SELECTION(fs)->ok_button),
"clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy),
(gpointer) fs);
gtk_signal_connect_object(GTK_OBJECT(GTK_FILE_SELECTION(fs)->cancel_button),
"clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy),
(gpointer) fs);
gtk_widget_show(fs);
}
/**
* @brief Creates a file selection dialog box for reading data into the
* new window.
*
* @param plot The Plot in the window which called the
* file selector.
* @param action The action initiating the call.
* @param file_select_button The button initiating the call.
*/
void
file_select_new_window(Plot* plot, gint action, GtkItem* file_select_button)
{
GtkWidget* fs;
UNUSED(action);
UNUSED(file_select_button);
fs = gtk_file_selection_new(FILE_SELECTION_TITLE);
gtk_file_selection_set_filename(GTK_FILE_SELECTION(fs),
plot->current_directory);
gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(fs)->ok_button),
"clicked", GTK_SIGNAL_FUNC(file_select_read), fs);
gtk_signal_connect_object(GTK_OBJECT(GTK_FILE_SELECTION(fs)->ok_button),
"clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy),
(gpointer) fs);
gtk_signal_connect_object(GTK_OBJECT(GTK_FILE_SELECTION(fs)->cancel_button),
"clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy),
(gpointer) fs);
gtk_widget_show(fs);
}
/**
* @brief Turn on/off the drawing of dots at each data point.
*
* @param plot The Plot to be toggled.
* @param action The action initiating the call.
* @param draw_points_toggle The button initiating the call.
*/
void
plot_window_draw_points_toggle (Plot* plot, gint action,
GtkItem* draw_points_toggle)
{
UNUSED(action);
UNUSED(draw_points_toggle);
option_draw_no_points = plot->draw_points;
plot->draw_points = !(plot->draw_points);
if (plot->pixmap != NULL)
{
plot_area_draw(plot);
plot_window_display_data(plot);
}
}
/**
* @brief Turn on/off the drawing of grid lines on the plot.
*
* @param plot The Plot to be toggled.
* @param action The action initiating the call.
* @param draw_grid_toggle The button initiating the call.
*/
void
plot_window_draw_grid_toggle (Plot* plot, gint action,
GtkItem* draw_grid_toggle)
{
UNUSED(action);
UNUSED(draw_grid_toggle);
plot->draw_grid = !(plot->draw_grid);
option_draw_grid = plot->draw_grid;
if (plot->pixmap != NULL)
{
plot_area_draw(plot);
plot_window_display_data(plot);
}
}
/**
* @brief Turn on/off the drawing of range values at corners of the plot.
*
* @param plot The Plot to be toggled.
* @param action The action initiating the call.
* @param draw_range_toggle The button initiating the call.
*/
void
plot_window_draw_range_toggle (Plot* plot, gint action,
GtkItem* draw_range_toggle)
{
UNUSED(action);
UNUSED(draw_range_toggle);
plot->draw_range = !(plot->draw_range);
option_draw_range = plot->draw_range;
if (plot->pixmap != NULL)
{
plot_area_draw(plot);
plot_window_display_data(plot);
}
}
/**
* @brief Create a new plot containing the derivative of the current plot.
*
* @param plot The Plot whose derivative should be taken.
* @param action The action initiating the call.
* @param button The button initiating the call.
*/
void
plot_window_derivative(Plot* plot, gint action, GtkItem* button)
{
DataSet* data_set;
DataSet* d_data_set;
Plot* d_plot;
GArray* data;
GArray* d_data;
guint i;
gint idx;
gint d_data_set_idx;
UNUSED(action);
UNUSED(button);
data = plot->data;
d_data = g_array_new(FALSE, FALSE, sizeof(gint));
for (i=0; i<data->len; ++i)
{
idx = g_array_index(data, gint, i);
data_set = g_array_index(global_data_set_list, DataSet*, idx);
d_data_set = dataset_derivative(idx);
d_data_set_idx = global_data_set_list_append(d_data_set);
g_array_append_val(d_data, d_data_set_idx);
}
d_plot = plot_data_init(d_data);
gtk_widget_show(d_plot->window);
}
/*
* CONTROL PANEL CALLBACKS.
*/
/**
* @brief Switch the display mode based on "play" button clicks.
*
* @param play_button The play button widget.
* @param event The calling event.
* @param data Data attached to the event (unused).
* @returns TRUE if successful, otherwise something else.
*/
gboolean
pause_play_button_click(GtkWidget* play_button, GdkEventExpose* event,
gpointer* data)
{
UNUSED(event);
UNUSED(data);
if (global_display_mode == ANIMATE_MODE)
{
global_display_mode = PAUSE_MODE;
if (global_control_panel != NULL)
gtk_object_set(GTK_OBJECT(global_control_panel->play_button),
"GtkButton::label", (gchar*) PLAY_BUTTON_LABEL, NULL);
return TRUE;
}
if (global_control_panel != NULL)
gtk_object_set(GTK_OBJECT(global_control_panel->play_button),
"GtkButton::label", (gchar*) PAUSE_BUTTON_LABEL, NULL);
if ((global_display_mode == SHOW_ALL_MODE) ||
(global_current_frame == global_last_frame))
global_current_frame = FIRST_FRAME-1;
global_display_mode = ANIMATE_MODE;
gtk_timeout_add (option_animate_delay, (GtkFunction) frame_draw_next,
play_button);
return TRUE;
}
/**
* @brief Go to the first frame of an animation due to a "start" button
* click, and toggle the display mode to PAUSE_MODE.
*
* @param start_button The start button widget.
* @param event The calling event.
* @param data Data attached to the event (unused).
* @returns TRUE if successful, otherwise something else.
*/
gboolean
start_button_click(GtkWidget* start_button, GdkEventExpose* event,
gpointer* data)
{
UNUSED(start_button);
UNUSED(event);
UNUSED(data);
if (global_display_mode == PAUSE_MODE && global_current_frame == FIRST_FRAME)
return TRUE;
global_display_mode = PAUSE_MODE;
current_frame_set(FIRST_FRAME);
current_time_display_value();
all_windows_draw();
return TRUE;
}
/**
* @brief Go to the last frame of an animation due to a "end" button
* click, and toggle the display mode to PAUSE_MODE.
*
* @param end_button The end button widget.
* @param event The calling event.
* @param data Data attached to the event (unused).
* @returns TRUE if successful, otherwise something else.
*/
gboolean
end_button_click(GtkWidget* end_button, GdkEventExpose* event, gpointer* data)
{
UNUSED(end_button);
UNUSED(event);
UNUSED(data);
if ((global_display_mode == PAUSE_MODE) &&
(global_current_frame == global_last_frame))
return TRUE;
global_display_mode = PAUSE_MODE;
current_frame_set(global_last_frame);
current_time_display_value();
all_windows_draw();
return TRUE;
}
/**
* @brief Move an animation one frame forward due to a "fwd" button click.
* Toggle to PAUSE_MODE and increment the frame number.
*
* @param fwd_button The forward button widget.
* @param event The calling event.
* @param data Data attached to the event (unused).
* @returns TRUE if successful, otherwise something else.
*/
gboolean
step_fwd_button_click(GtkWidget* fwd_button, GdkEventExpose* event,
gpointer* data)
{
if ((global_display_mode == PAUSE_MODE) &&
(global_current_frame == global_last_frame))
return TRUE;
if (global_display_mode == SHOW_ALL_MODE)
return start_button_click(fwd_button, event, data);
global_display_mode = PAUSE_MODE;
current_frame_increment(1);
current_time_display_value();
all_windows_draw();
return TRUE;
}
/**
* @brief Move an animation one frame backward due to a "back" button click.
* Toggle to PAUSE_MODE and increment the frame number.
*
* @param back_button The back button widget.
* @param event The calling event.
* @param data Data attached to the event (unused).
* @returns TRUE if successful, otherwise something else.
*/
gboolean
step_back_button_click(GtkWidget* back_button, GdkEventExpose* event,
gpointer* data)
{
if (global_display_mode == PAUSE_MODE && global_current_frame == FIRST_FRAME)
return TRUE;
if (global_display_mode == SHOW_ALL_MODE)
return end_button_click(back_button, event, data);
global_display_mode = PAUSE_MODE;
current_frame_increment(-1);
current_time_display_value();
all_windows_draw();
return TRUE;
}
/**
* @brief Toggle between SHOW_ALL and single frame display modes.
*
* @param showall_button The show-all button widget.
* @param event The calling event.
* @param data Data attached to the event (unused).
* @returns TRUE if successful, otherwise something else.
*/
gboolean
show_all_button_click(GtkWidget* showall_button, GdkEventExpose* event,
gpointer* data)
{
UNUSED(showall_button);
UNUSED(event);
UNUSED(data);
if (global_display_mode == SHOW_ALL_MODE)
return TRUE;
global_display_mode = SHOW_ALL_MODE;
current_frame_set(FIRST_FRAME);
all_windows_draw();
return TRUE;
}
/**
* @brief Close the plot window.
*
* @param plot_area The plot area widget to be closed.
* @param event The calling event.
* @param plot The Plot in question.
* @returns TRUE if successful, crash if not.
*/
gboolean
plot_window_key_press_event(GtkWidget* plot_area, GdkEventKey* event,
Plot* plot)
{
UNUSED(plot_area);
if (event->keyval == GDK_p)
control_panel_raise();
else if (event->keyval == GDK_j)
step_back_button_click(NULL, NULL, NULL);
else if (event->keyval == GDK_k)
step_fwd_button_click(NULL, NULL, NULL);
else if (event->keyval == GDK_h)
start_button_click(NULL, NULL, NULL);
else if (event->keyval == GDK_l)
end_button_click(NULL, NULL, NULL);
else if (event->keyval == GDK_s)
show_all_button_click(NULL, NULL, NULL);
else if (event->keyval == GDK_L)
axis_toggle_log_state(plot);
else if (event->keyval == GDK_c)
plot_window_display_all(plot); /* clears labels on the plot */
else if (event->keyval == GDK_space)
pause_play_button_click(NULL, NULL, NULL);
return TRUE;
}
/**
* @brief Set the animation delay based on updated contents of the "delay"
* input field.
*
* @param delay_entry The delay entry field widget.
* @param data Data attached to the event (unused).
* @returns TRUE if successful, otherwise something else.
*/
gboolean
delay_set(GtkEditable* delay_entry, gpointer data)
{
gchar* delay_str;
gint requested_delay;
UNUSED(data);
delay_str = gtk_editable_get_chars(GTK_EDITABLE(delay_entry), 0, -1);
requested_delay = strtol(delay_str, NULL, 10);
if (requested_delay >= 0)
option_animate_delay = requested_delay;
return TRUE;
}
/**
* @brief Set the frame time.
*
* Set the current frame time based on updated contents of the
* "time" input field. The data frames whose times are closest
* to the requested times are displayed.
*
* @param time_entry The time entry field widget.
* @param data Data attached to the event (unused).
* @returns TRUE if successful, otherwise something else.
*/
gboolean
current_time_set(GtkEditable* time_entry, gpointer data)
{
gchar* time_str;
gdouble requested_time;
gdouble available_time;
guint frame_nbr;
UNUSED(data);
if (global_time_list == NULL)
return TRUE;
time_str = gtk_editable_get_chars(GTK_EDITABLE(time_entry), 0, -1);
frame_nbr = 0;
requested_time = g_strtod(time_str, NULL);
if (!requested_time)
return TRUE;
available_time = g_array_index(global_time_list, gdouble, frame_nbr);
while ((available_time < requested_time) &&
(frame_nbr < global_time_list->len))
{
++frame_nbr;
available_time = g_array_index(global_time_list, gdouble, frame_nbr);
}
if (frame_nbr == global_time_list->len)
--frame_nbr;
global_display_mode = PAUSE_MODE;
current_frame_set(frame_nbr);
current_time_display_value();
all_windows_draw();
return TRUE;
}
/**
* @brief Reload all of the currently loaded data.
*
* @param reload_button The "reload" button.
* @param event The event initiating the callback.
* @returns TRUE if successful, otherwise crash.
*/
gboolean
data_reload_all(GtkWidget* reload_button, GdkEvent* event)
{
Plot* plot;
DataSet* data_set;
guint i;
UNUSED(reload_button);
UNUSED(event);
/* Any plot windows at all? */
if (!global_plot_window || !global_data_set_list)
return TRUE;
for(i=0; i<global_data_set_list->len; ++i)
{
data_set = g_array_index(global_data_set_list, DataSet*, i);
dataset_recalc(data_set);
}
for (i=0; i<global_plot_window->len; ++i)
{
plot = g_array_index(global_plot_window, Plot*, i);
plot_window_reconfigure(plot);
plot_window_display_all(plot);
}
return TRUE;
}
/**
* @brief Reload all of the data in a given plot.
*
* @param plot The Plot whose data is to be reloaded.
* @param action The calling action.
* @param reload_button The "reload" button.
* @returns TRUE if successful, otherwise crash.
*/
void
data_reload_plot(Plot* plot, gint action, GtkItem* reload_button)
{
DataSet* data_set;
guint i;
UNUSED(action);
UNUSED(reload_button);
if (plot->data == NULL)
return;
for (i=0; i<plot->data->len; ++i)
{
data_set = plot_get_data_index(plot, i);
dataset_read_from_file(data_set->fname, option_read_skip_step);
}
plot_window_reconfigure(plot);
plot_window_display_all(plot);
}
/**
* @brief Read the contents of an export file selection dialog.
*
* @param ok_button The okay button of the file selector.
* @param fs The file selection widget.
* @returns TRUE if successful, otherwise crash.
*/
gboolean
file_select_export(GtkObject* ok_button, GtkFileSelection* fs)
{
gchar* filename;
UNUSED(ok_button);
filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(fs));
gtk_entry_set_text(GTK_ENTRY(file_entry_A), filename);
return TRUE;
}
/**
* @brief Export a plot to a specified file.
*
* @param file_entry The file entry widget.
* @param plot The Plot to be exported.
* @returns TRUE if successful, otherwise crash.
*/
gboolean
export_file_set(GtkEditable* file_entry, Plot* plot)
{
gchar* filename;
UNUSED(file_entry);
filename = gtk_entry_get_text(GTK_ENTRY(file_entry_A));
export_to_file(plot, filename);
return TRUE;
}
/**
* @brief Export a plot to a specified directory as a series of frames.
*
* @param file_entry The file entry widget.
* @param plot The Plot to be exported.
* @returns TRUE if successful, otherwise crash.
*/
gboolean
export_dir_set(GtkEditable* file_entry, Plot* plot)
{
gchar* dirname;
UNUSED(file_entry);
dirname = gtk_entry_get_text(GTK_ENTRY(file_entry_A));
export_to_dir(plot, dirname);
return TRUE;
}
/**
* @brief Create a file selection dialog for exporting plots.
*
* @param select_button The button calling for the file selector.
* @param event The initiating event.
* @param plot The Plot to be exported.
* @returns TRUE if successful, otherwise crash.
*/
void
image_export_file_select(GtkWidget* select_button, GdkEvent* event, Plot* plot)
{
GtkWidget* fs;
gchar* filename;
UNUSED(select_button);
UNUSED(event);
fs = gtk_file_selection_new(EXPORT_TO_FILE_TITLE);
filename = gtk_entry_get_text(GTK_ENTRY(file_entry_A));
if (filename != NULL)
gtk_file_selection_set_filename(GTK_FILE_SELECTION(fs), filename);
gtk_object_set_data(GTK_OBJECT(fs), "plot", plot);
gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(fs)->ok_button),
"clicked", GTK_SIGNAL_FUNC(file_select_export), fs);
gtk_signal_connect_object(GTK_OBJECT(GTK_FILE_SELECTION(fs)->ok_button),
"clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy),
(gpointer) fs);
gtk_signal_connect_object(GTK_OBJECT(GTK_FILE_SELECTION(fs)->cancel_button),
"clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy),
(gpointer) fs);
gtk_widget_show(fs);
}
/**
* @brief Create a dialog box for exporting an image to a file.
*
* @param plot The Plot to be exported.
* @param action The calling action.
* @param export_button The calling button.
* @returns TRUE if successful, otherwise crash.
*/
void
image_export_dialog(Plot* plot, gint action, GtkItem* export_button)
{
GtkWidget* dialog;
GtkWidget* label;
GtkWidget* hbox_A;
GtkWidget* file_label_A;
GtkWidget* file_button_A;
GtkWidget* okay_button;
GtkWidget* cancel_button;
UNUSED(action);
UNUSED(export_button);
dialog = gtk_dialog_new();
gtk_window_set_title(GTK_WINDOW(dialog), EXPORT_TO_FILE_TITLE);
gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, FALSE, TRUE);
label = gtk_label_new(EXPORT_FILE_SELECT_MESSAGE);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), label);
hbox_A = gtk_hbox_new(FALSE, 0);
gtk_widget_show(hbox_A);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox_A, FALSE,
FALSE, 0);
file_label_A = gtk_label_new(EXPORT_FILE_LABEL);
gtk_widget_show(file_label_A);
gtk_box_pack_start(GTK_BOX(hbox_A), file_label_A, FALSE, FALSE, 0);
file_entry_A = gtk_entry_new();
gtk_entry_set_max_length(GTK_ENTRY(file_entry_A), FILE_STR_SIZE);
gtk_entry_set_text(GTK_ENTRY(file_entry_A), "");
gtk_widget_show(file_entry_A);
gtk_box_pack_start(GTK_BOX(hbox_A), file_entry_A, FALSE, FALSE, 0);
gtk_widget_set_usize(file_entry_A, FILE_ENTRY_LENGTH, -2);
gtk_signal_connect(GTK_OBJECT(file_entry_A), "activate",
GTK_SIGNAL_FUNC(export_file_set), plot);
gtk_signal_connect_object(GTK_OBJECT(file_entry_A), "activate",
GTK_SIGNAL_FUNC (gtk_widget_destroy),
GTK_OBJECT(dialog));
file_button_A = gtk_button_new_with_label(SELECT_LABEL);
gtk_signal_connect(GTK_OBJECT(file_button_A), "clicked",
GTK_SIGNAL_FUNC(image_export_file_select), plot);
gtk_widget_show(file_button_A);
gtk_box_pack_start(GTK_BOX(hbox_A), file_button_A, FALSE, FALSE, 0);
okay_button = gtk_button_new_with_label(OKAY_BUTTON_LABEL);
gtk_signal_connect(GTK_OBJECT(okay_button),
"clicked", GTK_SIGNAL_FUNC(export_file_set), plot);
gtk_signal_connect_object (GTK_OBJECT (okay_button), "clicked",
GTK_SIGNAL_FUNC (gtk_widget_destroy),
GTK_OBJECT(dialog));
gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->action_area),
okay_button);
gtk_widget_show(okay_button);
cancel_button = gtk_button_new_with_label(CANCEL_BUTTON_LABEL);
gtk_signal_connect_object (GTK_OBJECT (cancel_button), "clicked",
GTK_SIGNAL_FUNC (gtk_widget_destroy),
GTK_OBJECT(dialog));
gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->action_area),
cancel_button);
gtk_widget_show(cancel_button);
gtk_widget_show_all (dialog);
}
/**
* @brief Create a dialog box for exporting a series of images to a
* directory.
*
* @param plot The Plot to be exported.
* @param action The calling action.
* @param export_button The calling button.
* @returns TRUE if successful, otherwise crash.
*/
void
image_dir_export_dialog(Plot* plot, gint action, GtkItem* export_button)
{
GtkWidget* dialog;
GtkWidget* label;
GtkWidget* hbox_A;
GtkWidget* file_label_A;
GtkWidget* file_button_A;
GtkWidget* okay_button;
GtkWidget* cancel_button;
UNUSED(action);
UNUSED(export_button);
dialog = gtk_dialog_new();
gtk_window_set_title(GTK_WINDOW(dialog), EXPORT_TO_DIR_TITLE);
gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, FALSE, TRUE);
label = gtk_label_new(EXPORT_DIR_SELECT_MESSAGE);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), label);
hbox_A = gtk_hbox_new(FALSE, 0);
gtk_widget_show(hbox_A);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox_A, FALSE,
FALSE, 0);
file_label_A = gtk_label_new(EXPORT_DIR_LABEL);
gtk_widget_show(file_label_A);
gtk_box_pack_start(GTK_BOX(hbox_A), file_label_A, FALSE, FALSE, 0);
file_entry_A = gtk_entry_new();
gtk_entry_set_max_length(GTK_ENTRY(file_entry_A), FILE_STR_SIZE);
gtk_entry_set_text(GTK_ENTRY(file_entry_A), "");
gtk_widget_show(file_entry_A);
gtk_box_pack_start(GTK_BOX(hbox_A), file_entry_A, FALSE, FALSE, 0);
gtk_widget_set_usize(file_entry_A, FILE_ENTRY_LENGTH, -2);
gtk_signal_connect(GTK_OBJECT(file_entry_A), "activate",
GTK_SIGNAL_FUNC(export_dir_set), plot);
gtk_signal_connect_object(GTK_OBJECT(file_entry_A), "activate",
GTK_SIGNAL_FUNC (gtk_widget_destroy),
GTK_OBJECT(dialog));
file_button_A = gtk_button_new_with_label(SELECT_LABEL);
gtk_signal_connect(GTK_OBJECT(file_button_A), "clicked",
GTK_SIGNAL_FUNC(image_export_file_select), plot);
gtk_widget_show(file_button_A);
gtk_box_pack_start(GTK_BOX(hbox_A), file_button_A, FALSE, FALSE, 0);
okay_button = gtk_button_new_with_label(OKAY_BUTTON_LABEL);
gtk_signal_connect(GTK_OBJECT(okay_button),
"clicked", GTK_SIGNAL_FUNC(export_dir_set), plot);
gtk_signal_connect_object (GTK_OBJECT (okay_button), "clicked",
GTK_SIGNAL_FUNC (gtk_widget_destroy),
GTK_OBJECT(dialog));
gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->action_area),
okay_button);
gtk_widget_show(okay_button);
cancel_button = gtk_button_new_with_label(CANCEL_BUTTON_LABEL);
gtk_signal_connect_object (GTK_OBJECT (cancel_button), "clicked",
GTK_SIGNAL_FUNC (gtk_widget_destroy),
GTK_OBJECT(dialog));
gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->action_area),
cancel_button);
gtk_widget_show(cancel_button);
gtk_widget_show_all (dialog);
}
/*
* ABOUT BOX CALLBACKS.
*/
/**
* @brief Expose the "About" dialog box.
*
* @param drawing_area The About box drawing area.
* @param event The calling event.
* @param data Data attached to the event (unused).
* @returns TRUE if successful, otherwise crash.
*/
gboolean
about_expose(GtkWidget* drawing_area, GdkEventExpose* event, gpointer data)
{
UNUSED(data);
gdk_draw_pixmap(drawing_area->window,
drawing_area->style->fg_gc[GTK_WIDGET_STATE(drawing_area)],
global_about_pixmap,
event->area.x, event->area.y,
event->area.x, event->area.y,
event->area.width, event->area.height);
return TRUE;
}
/*
* HELP WINDOW CALLBACKS.
*/
/**
* @brief Expose the "Help" text box.
*
* @param text_area The Help window text area.
* @param event The calling event.
* @param data Data attached to the event (unused).
* @returns TRUE if successful, otherwise crash.
*/
gboolean
help_expose(GtkWidget* text_area, GdkEventExpose* event, gpointer data)
{
UNUSED(text_area);
UNUSED(event);
UNUSED(data);
return TRUE;
}
|