-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallbacks.c
More file actions
1605 lines (1363 loc) · 42 KB
/
Copy pathcallbacks.c
File metadata and controls
1605 lines (1363 loc) · 42 KB
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
/*
Quickplot - an interactive 2D plotter
Copyright (C) 1998-2011 Lance Arsenault
This file is part of Quickplot.
Quickplot 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 3 of the License,
or (at your option) any later version.
Quickplot 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 Quickplot. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <math.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <gdk/gdkkeysyms.h>
#include <cairo/cairo-xlib.h>
#include "quickplot.h"
#include "config.h"
#include "debug.h"
#include "list.h"
#include "callbacks.h"
#include "channel.h"
#include "channel_double.h"
#include "qp.h"
#include "plot.h"
#include "zoom.h"
#ifdef DMALLOC
# include "dmalloc.h"
#endif
int save_x, save_y, start_x, start_y;
int mouse_num = 0, got_motion = 0;
#define L_SHIFT (01<<0)
#define R_SHIFT (01<<1)
#define L_CNTL (01<<2)
#define R_CNTL (01<<3)
/* optionally, we use the shift/cntl key press/release
* in the zoom box adjusting */
static int got_mod_key = 0;
gboolean ecb_close(GtkWidget *w, GdkEvent *event, gpointer data)
{
ASSERT(data);
ASSERT(app && app->is_gtk_init);
ASSERT(app->main_window_count > 0);
if(app->gui_can_exit && app->main_window_count == 1)
{
cb_quit(NULL, data);
return TRUE;
}
cb_delete_window(NULL, data);
return TRUE; /* TRUE means event is handled */
}
void cb_delete_window(GtkWidget *w, gpointer data)
{
ASSERT(data);
VASSERT(app->main_window_count > 1,
"the delete window menu item should be deactivated if"
" there is just one main quickplot window");
qp_win_destroy((struct qp_win *) data);
}
void cb_quit(GtkWidget *w, gpointer data)
{
struct qp_win *qp;
ASSERT(app && app->is_gtk_init);
while((qp = qp_sllist_last(app->qps)))
qp_win_destroy(qp);
ASSERT(qp_sllist_length(app->qps) == 0);
gtk_main_quit();
}
gboolean ecb_key_release(GtkWidget *w, GdkEvent *event, gpointer data)
{
switch(event->key.keyval)
{
case GDK_KEY_Shift_L:
got_mod_key &= ~L_SHIFT;
break;
case GDK_KEY_Shift_R:
got_mod_key &= ~R_SHIFT;
break;
case GDK_KEY_Control_L:
got_mod_key &= ~L_CNTL;
break;
case GDK_KEY_Control_R:
got_mod_key &= ~R_CNTL;
break;
}
return FALSE;
}
static inline
void toggle_all_guis(struct qp_win *qp)
{
int showing = 0;
if(qp->view_menubar)
showing =
gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(qp->view_menubar));
showing |=
gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(qp->view_buttonbar))
||
gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(qp->view_graph_tabs))
||
gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(qp->view_statusbar))
||
gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(qp->view_graph_detail));
if(showing)
{
/* Hide them */
if(qp->view_menubar &&
gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(qp->view_menubar)))
gtk_menu_item_activate(GTK_MENU_ITEM(qp->view_menubar));
if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(qp->view_buttonbar)))
gtk_menu_item_activate(GTK_MENU_ITEM(qp->view_buttonbar));
if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(qp->view_graph_tabs)))
gtk_menu_item_activate(GTK_MENU_ITEM(qp->view_graph_tabs));
if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(qp->view_statusbar)))
gtk_menu_item_activate(GTK_MENU_ITEM(qp->view_statusbar));
if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(qp->view_graph_detail)))
gtk_menu_item_activate(GTK_MENU_ITEM(qp->view_graph_detail));
return;
}
/* Show them */
if(qp->view_menubar &&
!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(qp->view_menubar)))
gtk_menu_item_activate(GTK_MENU_ITEM(qp->view_menubar));
if(!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(qp->view_buttonbar)))
gtk_menu_item_activate(GTK_MENU_ITEM(qp->view_buttonbar));
if(!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(qp->view_graph_tabs)))
gtk_menu_item_activate(GTK_MENU_ITEM(qp->view_graph_tabs));
if(!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(qp->view_statusbar)))
gtk_menu_item_activate(GTK_MENU_ITEM(qp->view_statusbar));
#if 0
/* Maybe not this one */
if(!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(qp->view_graph_detail)))
gtk_menu_item_activate(GTK_MENU_ITEM(qp->view_graph_detail));
#endif
}
gboolean ecb_key_press(GtkWidget *w, GdkEvent *event, gpointer data)
{
struct qp_win *qp;
ASSERT(data);
ASSERT(event->type == GDK_KEY_PRESS);
qp = data;
//DEBUG("got press keyval=0x%x\n", event->key.keyval);
// Since the key accelerators that are associated with the menus
// above do not work if the menu is not visible we just handle the
// key press here. We still need the key letter to be labeled on
// the menu item which the accelerator does, so we setup the
// accelerators just for the label, but otherwise the accelerators
// could be removed since we override them here.
/********************************************************************
* MAP KEY PRESSES for main window *
********************************************************************/
// KEEP THESE KEY MAPPING CONSISTENT WITH THE MENU ITEMS ABOVE.
// Yes, this is a not so nice hack. And GTK+ sucks, because it
// stops accelerators when widgets are not visible, but it beats QT
// (with butt ugly moc preprocessor) and GTKmm (which is a wrapper
// that makes you go under the covers to get shit done). I prefer
// this hack to making another abstraction layer that you put keys
// and actions into. This is the most straight forward method.
switch(event->key.keyval)
{
case GDK_KEY_A:
case GDK_KEY_a:
cb_about(NULL, NULL);
break;
case GDK_KEY_B:
case GDK_KEY_b:
gtk_menu_item_activate(GTK_MENU_ITEM(qp->view_buttonbar));
break;
case GDK_KEY_C:
case GDK_KEY_c:
if(gtk_widget_get_sensitive(qp->copy_window_menu_item))
cb_copy_window(NULL, qp);
break;
case GDK_KEY_D:
case GDK_KEY_d:
if(app->main_window_count > 1)
ecb_close(NULL, NULL, qp);
break;
case GDK_KEY_Escape:
if(qp->graph_detail && qp->graph_detail->window == w)
cb_graph_detail_show_hide(NULL, qp);
else if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(qp->view_fullscreen)))
gtk_menu_item_activate(GTK_MENU_ITEM(qp->view_fullscreen));
else if(app->main_window_count > 1)
ecb_close(NULL, NULL, qp);
break;
case GDK_KEY_E:
case GDK_KEY_e:
gtk_menu_item_activate(GTK_MENU_ITEM(qp->view_border));
break;
case GDK_KEY_F:
case GDK_KEY_f:
case GDK_KEY_F11:
gtk_menu_item_activate(GTK_MENU_ITEM(qp->view_fullscreen));
break;
case GDK_KEY_G:
case GDK_KEY_g:
case GDK_KEY_F9:
gtk_menu_item_activate(GTK_MENU_ITEM(qp->view_graph_detail));
break;
case GDK_KEY_H:
case GDK_KEY_h:
case GDK_KEY_F1:
cb_help(NULL, NULL);
break;
case GDK_KEY_I:
case GDK_KEY_i:
cb_save_png_image_file(NULL, qp);
break;
case GDK_KEY_M:
case GDK_KEY_m:
if(qp->view_menubar)
gtk_menu_item_activate(GTK_MENU_ITEM(qp->view_menubar));
break;
case GDK_KEY_N:
case GDK_KEY_n:
cb_new_graph_tab(NULL, qp);
break;
case GDK_KEY_O:
case GDK_KEY_o:
cb_open_file(NULL, qp);
break;
case GDK_KEY_P:
case GDK_KEY_p:
break;
case GDK_KEY_Q:
case GDK_KEY_q:
cb_quit(qp->window, NULL);
break;
case GDK_KEY_R:
case GDK_KEY_r:
gtk_menu_item_activate(GTK_MENU_ITEM(qp->view_cairo_draw));
break;
case GDK_KEY_S:
case GDK_KEY_s:
gtk_menu_item_activate(GTK_MENU_ITEM(qp->view_statusbar));
break;
case GDK_KEY_T:
case GDK_KEY_t:
gtk_menu_item_activate(GTK_MENU_ITEM(qp->view_graph_tabs));
break;
case GDK_KEY_U:
case GDK_KEY_u:
toggle_all_guis(qp);
break;
case GDK_KEY_W:
case GDK_KEY_w:
cb_new_window(NULL, NULL);
break;
case GDK_KEY_X:
case GDK_KEY_x:
gtk_menu_item_activate(GTK_MENU_ITEM(qp->view_shape));
break;
case GDK_KEY_Z:
qp_graph_zoom_out(qp->current_graph, 1);
break;
case GDK_KEY_z:
qp_graph_zoom_out(qp->current_graph, 0);
break;
case GDK_KEY_Shift_L:
got_mod_key |= L_SHIFT;
break;
case GDK_KEY_Shift_R:
got_mod_key |= R_SHIFT;
break;
case GDK_KEY_Control_L:
got_mod_key |= L_CNTL;
break;
case GDK_KEY_Control_R:
got_mod_key |= R_CNTL;
break;
case GDK_KEY_Left:
case GDK_KEY_leftarrow:
if(gtk_notebook_get_show_tabs(GTK_NOTEBOOK(qp->notebook)) ||
gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(qp->view_buttonbar)))
return FALSE;
else
gtk_notebook_prev_page(GTK_NOTEBOOK(qp->notebook));
break;
case GDK_KEY_Right:
case GDK_KEY_rightarrow:
if(gtk_notebook_get_show_tabs(GTK_NOTEBOOK(qp->notebook)) ||
gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(qp->view_buttonbar)))
return FALSE;
else
gtk_notebook_next_page(GTK_NOTEBOOK(qp->notebook));
break;
default:
return FALSE; /* FALSE means the event is not handled. */
}
return TRUE; /* TRUE means the event is handled. */
}
void cb_zoom_out(GtkWidget *w, gpointer data)
{
struct qp_win *qp;
qp = data;
qp_graph_zoom_out(qp->current_graph, 0);
}
void cb_zoom_out_all(GtkWidget *w, gpointer data)
{
struct qp_win *qp;
qp = data;
qp_graph_zoom_out(qp->current_graph, 1);
}
/* this will not be called if qp->view_menubar is not set */
void cb_view_menubar(GtkWidget *w, gpointer data)
{
struct qp_win *qp;
ASSERT(data);
qp = data;
if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(qp->view_menubar)))
gtk_widget_show(qp->menubar);
else
gtk_widget_hide(qp->menubar);
gdk_window_set_cursor(gtk_widget_get_window(qp->window), app->waitCursor);
}
void cb_view_graph_tabs(GtkWidget *w, gpointer data)
{
struct qp_win *qp;
ASSERT(data);
qp = data;
if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(qp->view_graph_tabs)))
{
struct qp_graph *gr;
/* GTK+ does not like having a showing widget in a
* hidden tab. */
for(gr = qp_sllist_begin(qp->graphs);gr;gr=qp_sllist_next(qp->graphs))
gtk_widget_show(gr->tab_label_hbox);
gtk_notebook_set_show_tabs(GTK_NOTEBOOK(qp->notebook), TRUE);
}
else
{
struct qp_graph *gr;
/* GTK+ does not like having a showing widget in a
* hidden tab. */
for(gr = qp_sllist_begin(qp->graphs);gr;gr=qp_sllist_next(qp->graphs))
gtk_widget_hide(gr->tab_label_hbox);
gtk_notebook_set_show_tabs(GTK_NOTEBOOK(qp->notebook), FALSE);
}
gdk_window_set_cursor(gtk_widget_get_window(qp->window), app->waitCursor);
}
void cb_view_buttonbar(GtkWidget *w, gpointer data)
{
struct qp_win *qp;
ASSERT(data);
qp = data;
if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(qp->view_buttonbar)))
gtk_widget_show(qp->buttonbar);
else
gtk_widget_hide(qp->buttonbar);
gdk_window_set_cursor(gtk_widget_get_window(qp->window), app->waitCursor);
}
void cb_view_statusbar(GtkWidget *w, gpointer data)
{
struct qp_win *qp;
ASSERT(data);
qp = data;
if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(qp->view_statusbar)))
gtk_widget_show(qp->statusbar);
else
gtk_widget_hide(qp->statusbar);
gdk_window_set_cursor(gtk_widget_get_window(qp->window), app->waitCursor);
}
void cb_view_border(GtkWidget *w, gpointer data)
{
struct qp_win *qp;
gboolean i;
ASSERT(data);
qp = data;
if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(qp->view_border)))
{
gtk_window_set_decorated(GTK_WINDOW(qp->window), qp->border = TRUE);
i = gtk_window_get_decorated(GTK_WINDOW(qp->window));
if(!i)
{
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(qp->view_border), FALSE);
qp->border = FALSE;
}
}
else
{
gtk_window_set_decorated(GTK_WINDOW(qp->window), qp->border = FALSE);
i = gtk_window_get_decorated(GTK_WINDOW(qp->window));
if(i)
{
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(qp->view_border), TRUE);
qp->border = TRUE;
}
}
}
#ifdef NO_BIG_WIN_COPY
gboolean ecb_window_state(GtkWidget *widget, GdkEventWindowState *e, struct qp_win *qp)
{
if((e->changed_mask & (
GDK_WINDOW_STATE_MAXIMIZED |GDK_WINDOW_STATE_FULLSCREEN)))
{
if((e->new_window_state & (
GDK_WINDOW_STATE_MAXIMIZED |GDK_WINDOW_STATE_FULLSCREEN)))
gtk_widget_set_sensitive(qp->copy_window_menu_item, FALSE);
else
gtk_widget_set_sensitive(qp->copy_window_menu_item, TRUE);
}
return TRUE;
}
#endif
void cb_view_fullscreen(GtkWidget *w, gpointer data)
{
struct qp_win *qp;
ASSERT(data);
qp = data;
if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(qp->view_fullscreen)))
gtk_window_fullscreen(GTK_WINDOW(qp->window));
else
gtk_window_unfullscreen(GTK_WINDOW(qp->window));
/* if we set the waitCursor but do not have a redraw happen it would
* be bad, given the wait cursor would not change back until the
* next redraw. So maybe it would be better to force the redraw
* which would do nothing if it works and will add an extra redraw
* if the set fullscreen failed and the wait cursor will not be stuck.
*
* tracking the window-state-event may not work, because the
* wait cursor will get set too late to show.
*
* If will work in all cases and in the off chance that
* gtk_window_*fullscreen() fails the results not too bad.
* */
gtk_widget_queue_draw(qp->current_graph->drawing_area);
qp->current_graph->pixbuf_needs_draw = 1;
gdk_window_set_cursor(gtk_widget_get_window(qp->window), app->waitCursor);
}
int _cairo_draw_ignore_event = 0;
void cb_view_cairo_draw(GtkWidget *w, gpointer data)
{
struct qp_win *qp;
if(_cairo_draw_ignore_event)
{
//DEBUG("ignoring\n");
return;
}
ASSERT(data);
qp = data;
if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(qp->view_cairo_draw)))
qp->x11_draw = 0;
else
qp->x11_draw = 1;
qp_graph_switch_draw_mode(qp->current_graph);
ecb_graph_configure(NULL, NULL, qp->current_graph);
gtk_widget_queue_draw(qp->current_graph->drawing_area);
gdk_window_set_cursor(gtk_widget_get_window(qp->window), app->waitCursor);
}
void cb_view_shape(GtkWidget *w, gpointer data)
{
struct qp_win *qp;
struct qp_graph *gr;
ASSERT(data);
qp = data;
/* this must set the gr->background_color consistant
* with qp_graph_create() in graph.c */
if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(qp->view_shape)))
{
DEBUG("shape on\n");
/* turn on shape */
for(gr=qp_sllist_begin(qp->graphs);gr;gr=qp_sllist_next(qp->graphs))
{
/* Full redraw needed to unset anti-aliasing */
gr->pixbuf_needs_draw = 1;
if(gr->background_color.a >= 0.5)
gr->background_color.a = 0.4;
}
qp->shape = 1;
gdk_window_set_cursor(gtk_widget_get_window(qp->window),app->waitCursor);
}
else
{
DEBUG("shape off\n");
/* turn off shape */
for(gr=qp_sllist_begin(qp->graphs);gr;gr=qp_sllist_next(qp->graphs))
{
/* Full redraw needed to set anti-aliasing */
gr->pixbuf_needs_draw = 1;
if(gr->background_color.a != gr->bg_alpha_preshape)
gr->background_color.a = gr->bg_alpha_preshape;
}
qp->shape = 0;
/* This should remove the current shape thingy */
/* by applying a NULL shape_region */
gtk_widget_shape_combine_region(qp->window, NULL);
if(qp->last_shape_region)
{
cairo_region_destroy(qp->last_shape_region);
qp->last_shape_region = NULL;
/* now it is NULL in our record of it */
}
if(qp->current_graph->pixbuf_needs_draw)
gdk_window_set_cursor(gtk_widget_get_window(qp->window),app->waitCursor);
}
gtk_widget_queue_draw(qp->current_graph->drawing_area);
}
void cb_close_tab(GtkWidget *w, gpointer data)
{
ASSERT(data);
qp_graph_destroy((struct qp_graph *) data);
}
gboolean ecb_graph_draw(GtkWidget *w, cairo_t *cr, gpointer data)
{
struct qp_graph *gr;
ASSERT(data);
gr = data;
qp_graph_draw(gr, cr);
return TRUE; /* TRUE means the event is handled. */
}
void cb_about(GtkWidget *w, gpointer data)
{
qp_launch_browser("about.html");
if(data)
{
printf("Quickplot version " VERSION "\n"
"The Quickplot home-page is at <" PACKAGE_URL ">\n"
"This was compiled on: " __DATE__ " at the time: " __TIME__ "\n"
"Quickplot is free software, distributed under the terms of the\n"
"GNU General Public License (version 3 or higher).\n"
#ifdef QP_DEBUG
"This Quickplot installation was built with extra debuging code.\n"
"You do not want that unless you are writing/debuging Quickplot code.\n"
#endif
);
exit(0);
}
}
void cb_help(GtkWidget *w, gpointer data)
{
qp_launch_browser("help.html");
if(data)
{
printf("Quickplot is a fast interactive 2D plotter.\n"
"\n"
"Quickplot uses html files for its reference documentation.\n"
"Quickplot also has a man page.\n"
"If you're not seeing a browser now with the\n"
"Quickplot Help document loaded than you may not be using a\n"
"windowing system or something else went wrong.\n"
"\n"
"The Quickplot text help document can be printed to standard\n"
"output by running `quickplot --print-help'.\n"
"\n"
"The lastest copy of the Quickplot reference documentation can be\n"
"found at <" PACKAGE_URL "help.html>.\n"
"The Quickplot home-page is at <" PACKAGE_URL ">.\n");
exit(1);
}
}
gboolean ecb_graph_configure(GtkWidget *wdgt, GdkEvent *event, gpointer data)
{
struct qp_graph *gr;
GtkAllocation allocation;
int w1, w2, h1, h2, h, w;
int old_xscale, old_yscale;
ASSERT(data);
gr = data;
ASSERT(gr->drawing_area);
gtk_widget_get_allocation(gr->drawing_area, &allocation);
w1 = 2*allocation.width;
w2 = 1.5*app->root_window_width;
h1 = 2*allocation.height;
h2 = 1.5*app->root_window_height;
w = (w1 > w2)?w1:w2;
h = (h1 > h2)?h1:h2;
if(!gr->pixbuf_surface || w > gr->pixbuf_width || h > gr->pixbuf_height)
{
if(gr->x11)
{
/* Drawing with X11 and Cairo */
unsigned int depth;
Display *dsp;
Window win;
int screen;
if(!gr->x11->dsp)
dsp = (gr->x11->dsp = gdk_x11_get_default_xdisplay());
else
dsp = gr->x11->dsp;
screen = DefaultScreen(gr->x11->dsp);
depth = DefaultDepth(dsp, screen);
ASSERT(depth > 7);
win = gdk_x11_window_get_xid(gtk_widget_get_window(gr->drawing_area));
if(gr->pixbuf_surface)
cairo_surface_destroy(gr->pixbuf_surface);
if(gr->x11->gc)
XFreeGC(dsp, gr->x11->gc);
if(gr->x11->pixmap)
XFreePixmap(dsp, gr->x11->pixmap);
gr->x11->pixmap =
XCreatePixmap(dsp, win, w, h, depth);
gr->x11->gc = XCreateGC(dsp, gr->x11->pixmap, 0, 0);
XSetLineAttributes(dsp, gr->x11->gc, 4, LineSolid, CapButt, JoinRound);
gr->pixbuf_surface =
cairo_xlib_surface_create(dsp, gr->x11->pixmap,
DefaultVisual(dsp, screen), w, h);
//DEBUG("Using X11 Pixmap\n");
}
else
{
/* Drawing just with Cairo */
if(gr->pixbuf_surface)
cairo_surface_destroy(gr->pixbuf_surface);
gr->pixbuf_surface =
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
}
/* The drawing_area widget fits inside the pixbuf */
////////pixbuf////////
// //
// ********** //
// * * //
gr->pixbuf_width = w; // * widget * //
gr->pixbuf_height = h; // * * //
// ********** //
// //
//////////////////////
}
gr->pixbuf_x = (gr->pixbuf_width - allocation.width)/2;
gr->pixbuf_y = (gr->pixbuf_height - allocation.height)/2;
gr->pixbuf_needs_draw = 1;
gr->draw_value_pick = 0;
// TODO: Too bad this does not work
gdk_window_set_cursor(gtk_widget_get_window(gr->qp->window),
app->waitCursor);
/* plot_val = scale*(zoomed plot val) + shift */
/* if we have any grab shifting we scale that to work
* with the new tranformation */
old_xscale = gr->xscale;
old_yscale = gr->yscale;
gr->xscale = allocation.width;
gr->yscale = - allocation.height;
gr->xshift = 0;
gr->yshift = allocation.height;
/* multiply out the new scale to the grab. */
/* If this is the first configure event the
* old gr->scale will be zero, but the
* gr->grab_x (y) may not be 0 if this is a copied gr.
* So we have gr->scale start at 0 to catch this case. */
if(gr->grab_x && old_xscale)
gr->grab_x *= ((double)gr->xscale)/((double)old_xscale);
if(gr->grab_y && old_xscale)
gr->grab_y *= ((double)gr->yscale)/((double)old_yscale);
gr->waiting_to_resize_draw = 1;
if(ABSVAL(gr->grab_x) > gr->pixbuf_x ||
ABSVAL(gr->grab_y) > gr->pixbuf_y)
{
qp_zoom_push_shift(&(gr->z), - gr->grab_x/gr->xscale,
- gr->grab_y/gr->yscale);
++gr->zoom_level;
gr->grab_x = 0;
gr->grab_y = 0;
}
gr->qp->pointer_x = -1;
gr->qp->pointer_y = -1;
//DEBUG("graph named: \"%s\" surface=%p\n", gr->name, gr->surface);
return TRUE; /* TRUE means the event is handled. */
}
/* We use this to zoom in and out at the pointer */
gboolean ecb_graph_scroll(GtkWidget *w, GdkEvent *event, gpointer data)
{
#ifdef QP_DEBUG
const char *dir[] = { "up", "down", "left", "right"};
DEBUG("x=%g y=%g direction=%s time=%u\n",
event->scroll.x, event->scroll.y,
dir[((int) (event->scroll.direction)) % 4],
event->scroll.time);
#endif
return TRUE;
}
gboolean cb_switch_page(GtkNotebook *notebook, GtkWidget *page,
guint page_num, gpointer data)
{
struct qp_graph *gr;
ASSERT(page);
gr = g_object_get_data(G_OBJECT(page), "qp_graph");
ASSERT(gr);
/* gtk_notebook_get_current_page(GTK_NOTEBOOK(qp->notebook)) is broken
* so we catch this event to get the current graph that is showing here. */
gr->qp->current_graph = gr;
//WARN("page_num=%d graph named=\"%s\"\n", page_num, gr->name);
qp_win_set_status(gr->qp);
if((gtk_check_menu_item_get_active(
GTK_CHECK_MENU_ITEM(gr->qp->view_cairo_draw)) &&
gr->x11) ||
(!gtk_check_menu_item_get_active(
GTK_CHECK_MENU_ITEM(gr->qp->view_cairo_draw)) &&
!gr->x11) )
{
_cairo_draw_ignore_event = 1;
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gr->qp->view_cairo_draw),
(gr->x11)?FALSE:TRUE);
_cairo_draw_ignore_event = 0;
}
// redraw queuing is not needed
//gtk_widget_queue_draw(gr->drawing_area);
/* a new graph will use the draw mode of this graph */
gr->qp->x11_draw = (gr->x11)?1:0;
if(gr->qp->shape)
gdk_window_set_cursor(gtk_widget_get_window(gr->qp->window),app->waitCursor);
gr->qp->update_graph_detail = 0;
if(gr->qp->graph_detail)
if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(gr->qp->view_graph_detail)))
/* qp->graph_detail is showing
* We need to update it, but if there is a new graph we will
* wait until after the graph drawn. */
gr->qp->update_graph_detail = 1;
return TRUE;
}
/* i is the current index starting at 0 and
* ending at num_points-1. So when i == -1
* we must start over and when i == num_points
* we end (start). */
static inline
void get_next_val(struct qp_plot *p, ssize_t *i)
{
double x = NAN, y;
if(*i == -1)
{
x = p->channel_x_begin(p->x_picker);
y = p->channel_y_begin(p->y_picker);
++(*i);
}
while((!is_good_double(x) || !is_good_double(y)) &&
*i < p->num_points-1)
{
x = p->channel_x_next(p->x_picker);
y = p->channel_y_next(p->y_picker);
++(*i);
}
if(is_good_double(x) && is_good_double(y))
{
p->xval = x;
p->yval = y;
}
}
static inline
void get_prev_val(struct qp_plot *p, ssize_t *i)
{
double x = NAN, y;
if(*i == p->num_points)
{
x = p->channel_x_end(p->x_picker);
y = p->channel_y_end(p->y_picker);
--(*i);
}
while((!is_good_double(x) || !is_good_double(y)) &&
*i > 0)
{
x = p->channel_x_prev(p->x_picker);
y = p->channel_y_prev(p->y_picker);
--(*i);
}
if(is_good_double(x) && is_good_double(y))
{
p->xval = x;
p->yval = y;
}
}
void set_value_pick_entries(struct qp_graph *gr, int x, int y)
{
struct qp_plot *p;
int mode;
mode = ((gr->value_mode) & 3);
ASSERT(mode == 0 || mode == 1 || mode == 2);
if(mode == 0)
{
for(p=qp_sllist_begin(gr->plots);p;p=qp_sllist_next(gr->plots))
{
char text[64];
if(!p->x_entry) break;
snprintf(text, 64, "%.*g", p->sig_fig_x, qp_plot_get_xval(p, x));
gtk_entry_set_text(GTK_ENTRY(p->x_entry), text);
snprintf(text, 64, "%.*g", p->sig_fig_y, qp_plot_get_yval(p, y));
gtk_entry_set_text(GTK_ENTRY(p->y_entry), text);
}
return;
}
for(p=qp_sllist_begin(gr->plots);p;p=qp_sllist_next(gr->plots))
{
double xval, yval, x_pix;
char text[64];
ssize_t i;
/* the channel p->x_picker is assumed to be
* monotonically increasing. */
x_pix = qp_plot_get_xval(p, x);
if(!p->x_picker)
{
ssize_t j;
ASSERT(p->x->form == QP_CHANNEL_FORM_SERIES);
p->x_picker = qp_channel_series_create(p->x, 0);
p->y_picker = qp_channel_series_create(p->y, 0);
i = -1;
get_next_val(p, &i);
p->picker_i = i;
p->num_points = qp_channel_series_length(p->x_picker);
j = qp_channel_series_length(p->y_picker);
if(p->num_points > j)
p->num_points = j;
}
else
i = p->picker_i;
/* TODO: Make work for the case when values can be NAN and INFINTY */
xval = p->xval;
yval = p->yval;
if(xval == x_pix || (i == p->num_points-1 && xval <= x_pix) ||
p->num_points == 1 || (i == 0 && xval >= x_pix))
goto finish;
while(i < p->num_points-1 && p->xval < x_pix)
{
xval = p->xval;
yval = p->yval;
get_next_val(p, &i);
}
if(i == p->num_points-1 && p->xval <= x_pix)
{
xval = p->xval;
yval = p->yval;
goto finish;
}
if(i < p->num_points-1 && xval < x_pix) /* p->xval >= x_pix */
{
if(mode == 1)
{
/* interpolate the y value */
yval = yval + (x_pix - xval)*(p->yval - yval)/(p->xval - xval);
xval = x_pix;
}
else /* mode == 2 */
{