/
giv-win.gob
4380 lines (3833 loc) · 144 KB
/
giv-win.gob
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
//======================================================================
// giv_window.gob -
//
// Dov Grobgeld <dov.grobgeld@gmail.com>
// Thu Aug 16 20:12:48 2007
//----------------------------------------------------------------------
requires 2.0.0
%headertop{
#include <math.h>
#include <gtk/gtk.h>
#include "giv-data.h"
#include "plis/plis.h"
#include "givimage.h"
#include "glib-jsonrpc/glib-jsonrpc-server.h"
#include "glib-jsonrpc/glib-jsonrpc-client.h"
%}
%{
#ifdef _WIN32
#include <windows.h>
#include <cairo-win32.h>
#endif
#include <gdk/gdkkeysyms.h>
#include "givplugin.h"
#include "giv-widget.h"
#include "giv-color-map.h"
#include <stdlib.h>
#include <vector>
#include "../config.h"
#include "gtkimageviewer/gtk-image-viewer.h"
#include "logo_150_inline.i"
#include "giv-logo.i"
#include "giv-parser.h"
#include "GivPainterAgg.h"
#include "GivPainterCairoPixbuf.h"
#include "GivRenderer.h"
#include "colormaps.h"
#include "giv-info.h"
#include "giv-markup.h"
#include "cairo-svg.h"
#include "cairo-ps.h"
#include "cairo-pdf.h"
#include "GivStringArray.h"
#include "time.h"
#include <sys/stat.h>
#include "giv-calibrate-dialog.h"
#include "giv-settings.h"
#include "giv-settings-editor.h"
#include "glib-jsonrpc/glib-jsonrpc-json.h"
using namespace std;
using namespace plis;
#define CASE(s) if (strcmp(s,S_)==0)
#ifdef WIN32
#include <windows.h>
#undef PRINT_BY_IMAGE
#endif
static const char ui_descr_menu_string[] =
#include "menu-top-xml.i"
;
static const char ui_descr_popup_string[] =
#include "menu-popup-xml.i"
;
static const char copyright_string[] =
#include "copyright.i"
;
enum {
PSEUDO_COLOR_OFF,
PSEUDO_COLOR_LOW_CONTRAST,
PSEUDO_COLOR_RAINBOW,
PSEUDO_COLOR_RED_TEMP,
PSEUDO_COLOR_BGRY,
PSEUDO_COLOR_BLUE_WHITE,
PSEUDO_COLOR_GRBW,
PSEUDO_COLOR_INVERT,
PSEUDO_COLOR_EQUALIZE,
PSEUDO_COLOR_NORMALIZE
};
enum
{
DND_TEXT_PLAIN,
DND_TEXT_URI_LIST
};
const int GIV_DEFAULT_PORT = 8222;
/* Target types for dropping into the file list */
static const GtkTargetEntry file_list_dest_targets[] = {
{ (gchar*)"text/uri-list", 0, DND_TEXT_URI_LIST }
};
static void cb_view_menu_bar (GtkAction *action, gpointer data);
static void cb_view_marks (GtkAction *action, gpointer data);
static void cb_view_balloons (GtkAction *action, gpointer data);
static void cb_view_sub_pixel (GtkAction *action, gpointer data);
static void cb_view_hflip (GtkAction *action, gpointer data);
static void cb_view_vflip (GtkAction *action, gpointer data);
static void cb_view_vertical_zoom_lock (GtkAction *action, gpointer data);
static void cb_view_colormap (GtkAction *action, gpointer data);
static void cb_view_pixel_grid (GtkAction *action, gpointer data);
static void cb_view_auto_resize (GtkAction *action, gpointer data);
static void cb_view_auto_contrast (GtkAction *action, gpointer data);
static void cb_view_auto_reload (GtkAction *action, gpointer data);
static void cb_menu_measure_distance (GtkAction *action, gpointer data);
static void cb_menu_calibrate (GtkAction *action, gpointer data);
static void cb_menu_quiver_zoom (GtkAction *action, gpointer data);
static void cb_menu_count_marks (GtkAction *action, gpointer data);
#if 0
static void cb_menu_default (GtkAction *action, gpointer data);
#endif
static void cb_menu_preferences (GtkAction *action, gpointer data);
static void cb_menu_new_window (GtkAction *action, gpointer data);
static void cb_menu_fill (GtkAction *action, gpointer data);
static void cb_menu_shrink_wrap (GtkAction *action, gpointer data);
static void cb_menu_close_window (GtkAction *action, gpointer data);
static void cb_menu_clear (GtkAction *action, gpointer data);
static void cb_menu_copyright (GtkAction *action, gpointer data);
static void cb_menu_about (GtkAction *action, gpointer data);
static void cb_menu_manual (GtkAction *action, gpointer data);
static void cb_menu_open (GtkAction *action, gpointer data);
static void cb_menu_export (GtkAction *action, gpointer data);
static void cb_menu_print (GtkAction *action, gpointer data);
static void cb_menu_mark_browser (GtkAction *action, gpointer data);
static void cb_menu_contrast_view (GtkAction *action, gpointer data);
static void cb_menu_info_dialog (GtkAction *action, gpointer data);
static gboolean giv_check_img_for_mono(GivImage *im);
static void cb_change_pseudo_color(GtkRadioAction* action,
GtkRadioAction*,
GivWin *self);
static void cb_image_reference(GtkWidget *widget,
const char *filename,
gpointer user_data);
static void menu_add_widget (GtkUIManager *ui, GtkWidget *widget, GtkContainer *container);
static void
cb_balloon_changed(GtkWidget *widget,
bool show_balloon,
gpointer data);
static void
cb_marks_changed(GtkWidget *widget,
bool show_balloon,
gpointer data);
static void
cb_file_list_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection_data,
guint info,
guint drag_time,
gpointer data);
static void
fit_marks_in_window(GivWin *self);
static void
app_error (GivWin *self,
const char *format, ...);
static int
cb_image_size_alloc(GtkWidget *widget,
GtkAllocation *allocation,
gpointer user_data);
static void
cb_flip_changed(GtkImageViewer *imgv,
gboolean do_flip_horizontal,
gboolean do_flip_vertical,
gpointer data);
static void
cb_vertical_zoom_lock_changed(GtkImageViewer *imgv,
gboolean do_vertical_zoom_lock,
gpointer data);
static gint
cb_button_press_event (GtkWidget * widget,
GdkEventButton * event,
gpointer user_data);
static gint
cb_button_release_event (GtkWidget * widget,
GdkEventButton * event,
gpointer user_data);
static gint
cb_key_press_event (GtkWidget * widget,
GdkEventKey * event,
gpointer user_data);
static gint
cb_motion_event(GtkWidget *widget,
GdkEventMotion *event,
gpointer user_data);
static void
apply_color_map(GivWin *self);
static double sqr(double x);
#if 0
static void
draw_measure_line(giv_backstore_t *backstore,
GtkWidget *image_viewer,
double x0, double y0,
double x1, double y1);
static giv_backstore_t *create_backstore(GtkWidget *image_viewer);
#endif
static void pixbuf_to_cairo(GdkPixbuf *img,
// output
GdkPixbuf **cairo_img);
static gchar *read_pnm_comment(const char *filename);
void draw_to_cairo(cairo_t *cr,
int width,
int height,
GivWin *self);
bool is_file_ext(const char *fn,
const char* ext_match);
static gboolean cb_load_image_when_idle(gpointer user_data);
static gboolean cb_redraw_when_idle(gpointer user_data);
static void
cb_contrast_changed(GtkWidget* widget,
double contrast_min,
double contrast_max,
GivWin *self);
static void
export_to_file(GivWin *self,
int width,
int height,
const char *filename);
static gboolean auto_reload_function(gpointer data);
static void
cb_image_annotate(GivWidget *imgv,
GdkPixbuf *pixbuf,
gint shift_x,
gint shift_y,
gdouble scale_x,
gdouble scale_y,
gpointer user_data
);
static void
my_lasso_draw(cairo_t *cr,
DovtkLassoContext context,
gpointer user_data);
static void
my_lasso_draw_rectangle(cairo_t *cr,
DovtkLassoContext context,
gpointer user_data);
static void create_remote_commands(GivWin *self);
static void giv_win_json_pick_reply(GivWin *self, const gchar *error, double x, double y);
// The following tables contain all the actions for both the menubar
// and the popup menus.
static int num_top_levels = 0;
static GtkActionEntry entries[] =
{
{ "FileMenuAction", NULL, "_File" }, /* name, stock id, label */
{ "ViewMenuAction", NULL, "_View" },
{ "ToolMenuAction", NULL, "_Tools" },
{ "HelpMenuAction", NULL, "_Help" },
{ "ColorTableMenuAction", NULL, "_ColorTable" },
{ "OpenAction", GTK_STOCK_OPEN,
"_Open", "<control>O",
"Open",
G_CALLBACK (cb_menu_open) },
{ "ExportAction", GTK_STOCK_SAVE,
"_Export", "<control>E",
"Export",
G_CALLBACK (cb_menu_export) },
{ "NewWindowAction", GTK_STOCK_NEW,
"_New Window", "<control>n",
"New Window",
G_CALLBACK (cb_menu_new_window) },
{ "CloseWindowAction", GTK_STOCK_CLOSE,
"_Close Window", "<control>n",
"Close Window",
G_CALLBACK (cb_menu_close_window) },
{ "ClearAction", GTK_STOCK_CLEAR,
"_Clear", "<control>c",
"Clear",
G_CALLBACK (cb_menu_clear) },
{ "PrintAction", GTK_STOCK_PRINT,
"_Print", "<control>P",
"Print",
G_CALLBACK (cb_menu_print) },
{ "QuitAction", GTK_STOCK_QUIT,
"_Quit", "<control>Q",
"Quit",
G_CALLBACK (gtk_main_quit) },
{ "AboutAction", GTK_STOCK_ABOUT,
"_About", NULL,
"About",
G_CALLBACK (cb_menu_about) },
{ "ManualAction", NULL,
"_User Manual", NULL,
"Manual",
G_CALLBACK (cb_menu_manual) },
{ "CopyrightAction", NULL,
"_Copyright", NULL,
"Copyright",
G_CALLBACK (cb_menu_copyright) },
{ "ToolMarkBrowserAction",
NULL,
"View Mark Browser", NULL,
"View Mark Browser",
G_CALLBACK (cb_menu_mark_browser) },
{ "ToolContrast",
NULL,
"Adjust Contrast", NULL,
"Adjust Contrast",
G_CALLBACK (cb_menu_contrast_view) },
{ "ToolInfoAction",
NULL,
"View Info", NULL,
"View Info",
G_CALLBACK (cb_menu_info_dialog) },
{ "PreferencesAction",
GTK_STOCK_PREFERENCES,
"_Preferences", NULL,
"Preferences",
G_CALLBACK (cb_menu_preferences) },
{ "FillAction",
NULL,
"_Fill", NULL,
"Fill",
G_CALLBACK (cb_menu_fill) },
{ "ShrinkWrapAction",
NULL,
"_Shrink Wrap", NULL,
"Shrink Wrap",
G_CALLBACK (cb_menu_shrink_wrap) },
{ "ToolCalibrateAction",
NULL,
"_Calibrate pixel size", NULL,
"Calibrate",
G_CALLBACK (cb_menu_calibrate) }
};
static GtkToggleActionEntry toggle_entries[] =
{
{ "ViewMenuBarAction",
NULL,
"View Menu", "<control>V",
"View Menu",
G_CALLBACK (cb_view_menu_bar), TRUE },
{ "ViewMarksAction",
NULL,
"View Marks", NULL,
"View Marks",
G_CALLBACK (cb_view_marks), TRUE },
{ "ViewBalloonAction",
NULL,
"View Balloons", NULL,
"View Balloons",
G_CALLBACK (cb_view_balloons), FALSE },
{ "ViewSubPixelAction",
NULL,
"Sub pixel coord", NULL,
"View sub pixel",
G_CALLBACK (cb_view_sub_pixel), FALSE },
{ "ViewHorizontalFlip",
NULL,
"Horizontal Flip", NULL,
"Horizontal Flip",
G_CALLBACK (cb_view_hflip), FALSE },
{ "ViewVerticalFlip",
NULL,
"Vertical Flip", NULL,
"Vertical Flip",
G_CALLBACK (cb_view_vflip), FALSE },
{ "ViewVerticalZoomLock",
NULL,
"Vertical Zoom Lock", NULL,
"Vertical Zoom Lock",
G_CALLBACK (cb_view_vertical_zoom_lock), FALSE },
{ "ViewColorMap",
NULL,
"Colormap Bar", NULL,
"Colormap Bar",
G_CALLBACK (cb_view_colormap), FALSE },
{ "ViewPixelGrid",
NULL,
"View Pixel Grid", NULL,
"View Pixel Grid",
G_CALLBACK (cb_view_pixel_grid), FALSE },
{ "AutoResize",
NULL,
"_Auto Resize", NULL,
"Auto Resize",
G_CALLBACK (cb_view_auto_resize), TRUE },
{ "AutoContrast",
NULL,
"_Auto Contrast", NULL,
"Auto Resize",
G_CALLBACK (cb_view_auto_contrast), TRUE },
{ "AutoReload",
NULL,
"A_uto Reload", NULL,
"Auto Reload the image",
G_CALLBACK (cb_view_auto_reload), FALSE },
{ "ToolMeasureDistanceAction",
NULL,
"_Measure Distance", NULL,
"Measure Distance",
G_CALLBACK (cb_menu_measure_distance), FALSE },
{ "ToolQuiverZoomAction",
NULL,
"_Quiver Zoom", NULL,
"Quiver Zoom",
G_CALLBACK (cb_menu_quiver_zoom), FALSE },
{ "ToolCountMarks",
NULL,
"_Count Marks", NULL,
"Count Marks",
G_CALLBACK (cb_menu_count_marks), FALSE },
};
static GtkRadioActionEntry actionsPseudoColor[] = {
{ "PseudoColorNone", NULL, "_None", NULL, "Histogram equaliziation", PSEUDO_COLOR_OFF },
{ "PseudoColorEqualize", NULL, "_Equalize", NULL, NULL, PSEUDO_COLOR_EQUALIZE },
{ "PseudoColorNormalize", NULL, "N_ormalize", NULL, NULL, PSEUDO_COLOR_NORMALIZE },
{ "PseudoColorInvert", NULL, "_Invert", NULL, NULL, PSEUDO_COLOR_INVERT },
{ "PseudoColorLowContrast", NULL, "Low _Contrast", NULL, NULL, PSEUDO_COLOR_LOW_CONTRAST },
{ "PseudoColorRainbow", NULL, "_Rainbow", NULL, NULL, PSEUDO_COLOR_RAINBOW },
{ "PseudoColorRedTemp", NULL, "Red _Temperature", NULL, NULL, PSEUDO_COLOR_RED_TEMP },
{ "PseudoColorBGRY", NULL, "_Blue Green Red Yellow", NULL, NULL, PSEUDO_COLOR_BGRY },
{ "PseudoColorBlueWhite", NULL, "Blue _White", NULL, NULL, PSEUDO_COLOR_BLUE_WHITE },
{ "PseudoColorGRBW", NULL, "_Green Red Blue White", NULL, NULL, PSEUDO_COLOR_GRBW }
};
static void die(const char *fmt, ...);
static gchar *last_image_path = NULL;
static gchar *last_export_image_path = NULL;
%}
%privateheader{
#include "giv-mark-tree-dialog.h"
#include "giv-contrast.h"
#include "giv-settings.h"
#include "dovtk-lasso.h"
%}
class Giv:Win from Gtk:Window
{
private GtkWidget *w_menubox;
private GtkWidget *w_popup;
private GtkWidget *w_imgv;
private GtkWidget *w_info_label;
private GtkWidget *w_filechooser = NULL;
private GtkWidget *w_mark_tree_dialog = NULL;
private GtkWidget *w_contrast_view = NULL;
private GtkWidget *w_calibrate = NULL;
private GtkWidget *w_info_dialog = NULL;
private GtkWidget *w_balloon_window = NULL;
private GtkWidget *w_balloon_label = NULL;
private GtkWidget *w_scrolled_win;
private GtkWidget *w_preferences = NULL;
private GivImage *img_org = NULL
destroy {
if (img_org) {
giv_image_unref(img_org);
img_org = NULL;
}
};
private double contrast_min = 0;
private double contrast_max = 255;
private gchar *format = NULL destroy { g_free(format); };
private GdkPixbuf *img_display = NULL
destroy {
if (img_display)
g_object_unref(img_display);
};
// This image is a copy of the img display but with label
// colors. It is never shown onto the screen.
private GdkPixbuf *w_label_image = NULL
destroy {
if (w_label_image) {
g_object_unref(w_label_image);
};
};
private gint cb_annotate_id;
private bool do_view_marks = true;
private bool do_view_colormap = false;
private bool img_is_mono = false;
private bool do_show_sub_pixel = false;
private bool do_square_aspect_ratio = true;
private bool do_auto_fit_marks = TRUE;
private bool do_auto_reload = FALSE;
private bool do_draw_pixel_grid = TRUE;
// If the image is triggered to be loaded by auto reload then the
// a failure to load is silently ignored. This is handled by the
// auto_relod_trigger flag;
private bool auto_reload_trigger = FALSE;
private bool do_auto_contrast = TRUE;
private bool do_no_transparency = FALSE;
private gdouble last_move_x=-1;
private gdouble last_move_y=-1;
private double last_cx;
private double last_cy;
private GtkUIManager *menu_manager = NULL;
private GtkUIManager *popup_manager = NULL;
private gint colormap = PSEUDO_COLOR_OFF;
private GPtrArray *filename_list = NULL
destroy {
g_ptr_array_foreach(filename_list, (GFunc)giv_string_array_free, NULL);
};
private int filename_list_index = -1;
private int img_in_list_idx = -1;
private GPtrArray *cb_names = NULL
destroy {
giv_string_array_free(cb_names);
};
// private giv_backstore_t *back_store = NULL;
private DovtkLasso *lasso = NULL;
private gboolean is_measuring_distance = FALSE;
private gboolean is_counting_marks = FALSE;
private int picking_mode = 0;
private gboolean is_quiver_zoom = FALSE;
private gint measure_point_index = 0;
private double picking_x=-1;
private double picking_y=-1;
private double measure_x1=-1;
private double measure_y1=-1;
private double measure_x2=-1;
private double measure_y2=-1;
private double quiver_scale = 1.0;
private GdkCursor *current_cursor=0;
private GdkCursor *cursor_plus=0;
private GdkCursor *cursor_diamond_cross = NULL;
private GdkCursor *cursor_default=0;
private GtkWidget *w_color_map_bar = NULL;
private gboolean is_dragging = FALSE;
private GtkPrintSettings *print_settings = NULL;
private gchar *img_comment = NULL;
private gint idle_index = 0;
private gint idle_handle = -1;
private time_t cached_mtime = 0;
private gint current_slice = 0;
private double pixelsize = 1;
private gchar *pixelsize_unit = NULL;
private double last_measure_distance_in_pixels = -1;
private GivSettings *giv_settings = NULL destroy { g_object_unref(giv_settings); };
private GLibJsonRpcServer *jsonrpc_server;
private GLibJsonRpcAsyncQuery *json_query = NULL;
private gboolean do_pick_coordinate = FALSE;
private gboolean do_fit_on_load_image = FALSE;
private gdouble margin = 10;
public GtkWidget *
new (int argc, char *argv[])
{
GivWin *self = GIV_WIN(GET_NEW);
GtkWidget *w_vbox, *w_right_box;
GtkActionGroup *action_group;
GError *error = NULL;
int argp = 1;
GdkPixbuf *pixbuf_icon;
bool do_join = false;
int width = 500;
int height = 500;
double scale = -1;
double shift_x = 0;
double shift_y = 0;
char *export_filename = NULL;
int giv_port = GIV_DEFAULT_PORT;
gboolean do_remote = FALSE;
const gchar *giv_host = "localhost"; // Currently fixed
gchar *remote_string=NULL;
gchar *json_method=NULL;
gchar *json_params_string=NULL;
// Parse command line
while(argp < argc && argv[argp][0] == '-') {
char *S_ = argv[argp++];
CASE("-help") {
printf("giv - An image and vector viewer\n"
"\n"
"Syntax:\n"
" giv [-n] [-join] image [image...]\n"
"\n"
"Options:\n"
" -join Join the display of all files on command line\n"
" -n Initially use 1:1 zoom for images.\n"
" -geometry Set size of image viewer\n"
" -zoom scale shift_x shift_y Zoom the image\n"
" -export fn Export to fn.\n"
);
exit(0);
}
CASE("-n") {
selfp->do_auto_fit_marks = false;
continue;
}
CASE("-join") {
do_join = true;
continue;
}
CASE("-geometry") {
llip matches;
if (slip(argv[argp++]).m("(\\d+)x(\\d+)", matches)) {
width = atoi(matches[1]);
height = atoi(matches[2]);
}
continue;
}
CASE("-zoom") {
scale = atof(argv[argp++]);
shift_x = atof(argv[argp++]);
shift_y = atof(argv[argp++]);
continue;
}
CASE("-export")
{
export_filename = argv[argp++];
continue;
}
CASE("-port")
{
giv_port = atoi(argv[argp++]);
continue;
}
CASE("-remote")
{
do_remote = TRUE;
remote_string= argv[argp++];
continue;
}
CASE("-json_method")
{
do_remote = TRUE;
json_method = g_strdup(argv[argp++]);
continue;
}
CASE("-json_params")
{
json_params_string = argv[argp++];
continue;
}
printf("Unknown option %s!\n", S_);
exit(-1);
}
// Load an image into a remote instance of giv. If this fails,
// then normal loading should take place.
if (do_remote)
{
GLibJsonRpcClient *client = glib_jsonrpc_client_new(giv_host,
giv_port);
if (client)
{
JsonNode *params = NULL;
if (!json_method)
{
// Either split remote string as space separated by params
char **json_args = g_strsplit(remote_string," ",-1);
json_method = g_strdup(json_args[0]);
char **json_params = &json_args[1];
params = glib_jsonrpc_json_strv_to_json_array(json_params);
g_strfreev(json_args);
}
else if (json_params_string)
params = glib_jsonrpc_json_string_to_json_node(json_params_string);
JsonNode *response = NULL;
glib_jsonrpc_client_call(client,
json_method,
params,
// output
&response);
g_free(json_method);
json_node_free(params);
if (response)
{
gchar *str = glib_jsonrpc_json_to_string(response);
printf("%s\n",str);
g_free(str);
json_node_free(response);
}
exit(0);
}
// Fall through and run giv normally!
}
selfp->cursor_plus = gdk_cursor_new(GDK_PLUS);
selfp->cb_names = g_ptr_array_new();
selfp->filename_list = g_ptr_array_new();
selfp->pixelsize_unit = g_strdup("");
selfp->jsonrpc_server = glib_jsonrpc_server_new(giv_port);
// Silently ignore failed server
if (selfp->jsonrpc_server)
create_remote_commands(self);
gchar *settings_file = g_strdup_printf("%s/.config/Giv/giv.conf", g_get_home_dir());
selfp->giv_settings = GIV_SETTINGS(giv_settings_new(settings_file));
gtk_window_set_resizable(GTK_WINDOW(self), true);
g_object_set(G_OBJECT(self),
"allow-shrink", TRUE,
NULL);
pixbuf_icon = gdk_pixbuf_new_from_inline(sizeof(image_giv_icon_inline),
image_giv_icon_inline,
FALSE,
&error);
gtk_window_set_icon (GTK_WINDOW(self),
pixbuf_icon);
g_object_unref(pixbuf_icon);
num_top_levels++;
g_signal_connect (G_OBJECT(self), "destroy",
GTK_SIGNAL_FUNC (giv_win_destroy), self);
w_vbox = gtk_vbox_new(0,0);
gtk_widget_show(w_vbox);
gtk_container_add(GTK_CONTAINER(self),
w_vbox);
selfp->w_menubox = gtk_vbox_new(0,0);
gtk_widget_show(selfp->w_menubox);
w_right_box = gtk_hbox_new(0,0);
gtk_widget_show(w_right_box);
action_group = gtk_action_group_new ("TestActions");
selfp->menu_manager = gtk_ui_manager_new ();
selfp->popup_manager = gtk_ui_manager_new ();
gtk_ui_manager_insert_action_group (selfp->menu_manager, action_group, 0);
gtk_ui_manager_insert_action_group (selfp->popup_manager, action_group, 0);
gtk_action_group_add_actions (action_group, entries, G_N_ELEMENTS(entries), self);
gtk_action_group_add_toggle_actions (action_group,
toggle_entries,
G_N_ELEMENTS(toggle_entries),
self);
gtk_action_group_add_radio_actions (action_group,
actionsPseudoColor,
G_N_ELEMENTS(actionsPseudoColor),
0,
G_CALLBACK(cb_change_pseudo_color),
self);
gtk_ui_manager_add_ui_from_string (selfp->menu_manager,
ui_descr_menu_string,
-1,
&error);
if (error)
die("Got error: %s\n", error->message);
gtk_ui_manager_add_ui_from_string (selfp->popup_manager,
ui_descr_popup_string,
-1,
&error);
if (error)
die("Got error: %s\n", error->message);
selfp->w_popup = gtk_ui_manager_get_widget (selfp->popup_manager,
"/popup");
/* This signal is necessary in order to place widgets from the UI manager
* into the menu_box */
g_signal_connect(selfp->menu_manager,
"add_widget",
G_CALLBACK (menu_add_widget),
selfp->w_menubox
);
g_signal_connect(selfp->popup_manager,
"add_widget",
G_CALLBACK (menu_add_widget),
selfp->w_popup
);
gtk_box_pack_start(GTK_BOX(w_vbox),
selfp->w_menubox, FALSE, FALSE, 0);
gtk_widget_show(gtk_ui_manager_get_widget(selfp->menu_manager,
"/menubar"));
GtkWidget *w_hbox = gtk_hbox_new(FALSE, 0);
gtk_widget_show(w_hbox);
gtk_box_pack_start(GTK_BOX(w_vbox),
w_hbox, TRUE, TRUE, 0);
selfp->w_color_map_bar = GTK_WIDGET(giv_color_map_new());
gtk_box_pack_start(GTK_BOX(w_hbox),
selfp->w_color_map_bar, FALSE, FALSE, 0);
selfp->w_scrolled_win = gtk_scrolled_window_new(NULL, NULL);
gtk_widget_show(selfp->w_scrolled_win);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(selfp->w_scrolled_win),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_box_pack_start(GTK_BOX(w_hbox),
selfp->w_scrolled_win, TRUE, TRUE, 0);
selfp->w_imgv = giv_widget_new(NULL);
gtk_image_viewer_set_fill_on_resize_margin(GTK_IMAGE_VIEWER(selfp->w_imgv),
selfp->margin);
gtk_widget_show(selfp->w_imgv);
g_signal_connect(selfp->w_imgv, "file-reference",
G_CALLBACK(cb_image_reference), self);
g_signal_connect(selfp->w_imgv, "button-press-event",
G_CALLBACK(cb_button_press_event), self);
g_signal_connect(selfp->w_imgv, "button-release-event",
G_CALLBACK(cb_button_release_event), self);
g_signal_connect(selfp->w_imgv, "key-press-event",
G_CALLBACK(cb_key_press_event), self);
g_signal_connect(selfp->w_imgv, "motion-notify-event",
G_CALLBACK(cb_motion_event), self);
g_signal_connect(selfp->w_imgv,
"image-annotate",
G_CALLBACK(cb_image_annotate),
self);
g_signal_connect(selfp->w_imgv,
"balloon-changed",
G_CALLBACK(cb_balloon_changed),
self);
g_signal_connect(selfp->w_imgv,
"show-marks-changed",
G_CALLBACK(cb_marks_changed),
self);
// Scrolling is like moving
g_signal_connect(selfp->w_imgv, "scroll-event",
G_CALLBACK(cb_motion_event), self);
#if 0
giv_widget_set_file_reference_callback(GIV_WIDGET(selfp->w_imgv),
cb_image_reference, self);
#endif
gtk_container_add(GTK_CONTAINER(selfp->w_scrolled_win),
selfp->w_imgv);
// The new windows version does not propagate this as it should!
gtk_image_viewer_set_vadjustment(GTK_IMAGE_VIEWER(selfp->w_imgv),
gtk_scrolled_window_get_vadjustment(
GTK_SCROLLED_WINDOW(selfp->w_scrolled_win)));
gtk_image_viewer_set_hadjustment(GTK_IMAGE_VIEWER(selfp->w_imgv),
gtk_scrolled_window_get_hadjustment(
GTK_SCROLLED_WINDOW(selfp->w_scrolled_win)));
selfp->w_info_label = gtk_label_new("");
gtk_widget_show(selfp->w_info_label);
gtk_box_pack_start(GTK_BOX(w_vbox),
selfp->w_info_label, FALSE, FALSE, 0);
gtk_widget_set_events(GTK_WIDGET(selfp->w_imgv),
GDK_EXPOSURE_MASK
| GDK_STRUCTURE_MASK
| GDK_SUBSTRUCTURE_MASK
| GDK_PROPERTY_CHANGE_MASK
| GDK_POINTER_MOTION_MASK
| GDK_BUTTON_PRESS_MASK
| GDK_KEY_PRESS_MASK
| GDK_LEAVE_NOTIFY_MASK
| GDK_SCROLL_MASK
);
g_signal_connect(selfp->w_imgv,
"flip-changed",
G_CALLBACK(cb_flip_changed),
self);
g_signal_connect(selfp->w_imgv,
"vertical-zoom-lock-changed",
G_CALLBACK(cb_vertical_zoom_lock_changed),
self);
g_signal_connect (selfp->w_imgv,
"drag-data-received",
G_CALLBACK (cb_file_list_drag_data_received),
self);
/* DnD */
gtk_drag_dest_set (selfp->w_imgv,
(GTK_DEST_DEFAULT_ALL),
file_list_dest_targets,
G_N_ELEMENTS(file_list_dest_targets),
GDK_ACTION_COPY);
GtkTargetList *target_list;
target_list = gtk_target_list_new (NULL, 0);
gtk_target_list_add_uri_targets (target_list, DND_TEXT_URI_LIST);
gtk_target_list_add_text_targets (target_list, DND_TEXT_PLAIN);
gtk_drag_dest_set_target_list (GTK_WIDGET (selfp->w_imgv), target_list);
gtk_target_list_unref (target_list);
gtk_widget_set_size_request(selfp->w_imgv, width, height);
#if 0
giv_win_shrink_wrap(self);
#endif
// This is ugly, don't show the window if we are exporting...
#if 0
if (!export_filename)
gtk_widget_show_all(GTK_WIDGET(self));
#endif
// Create the balloon window that is not shown at this point
selfp->w_balloon_window = gtk_window_new (GTK_WINDOW_POPUP);
// Make tooltip color yellow. This should probably be configurable
{
GdkColor color = {0,0,0,0};
gdk_color_parse("yellow", &color);
gtk_widget_modify_bg(selfp->w_balloon_window,
GTK_STATE_NORMAL, &color);
}
gtk_widget_set_app_paintable (selfp->w_balloon_window, TRUE);
gtk_window_set_resizable (GTK_WINDOW(selfp->w_balloon_window), FALSE);
selfp->w_balloon_label = gtk_label_new("Balloon");
gtk_label_set_line_wrap (GTK_LABEL (selfp->w_balloon_label), TRUE);
gtk_misc_set_alignment (GTK_MISC (selfp->w_balloon_label), 0.5, 0.5);
gtk_widget_show (selfp->w_balloon_label);
gtk_container_add (GTK_CONTAINER (selfp->w_balloon_window),
selfp->w_balloon_label);
// Hide the colormap bar. It will be displayed if we load a
// non 8-bit image.
gtk_widget_hide(selfp->w_color_map_bar);
gdk_flush();
// Apply settings
gtk_check_menu_item_set_active(
GTK_CHECK_MENU_ITEM(
gtk_ui_manager_get_widget(selfp->menu_manager,
"/menubar/ViewMenu/Sub-pixel")),
selfp->giv_settings->default_show_subpixel);
gtk_check_menu_item_set_active(
GTK_CHECK_MENU_ITEM(
gtk_ui_manager_get_widget(selfp->menu_manager,
"/menubar/ViewMenu/AutoResize")),
selfp->giv_settings->default_auto_resize);
gtk_check_menu_item_set_active(
GTK_CHECK_MENU_ITEM(
gtk_ui_manager_get_widget(selfp->menu_manager,
"/menubar/ViewMenu/AutoContrast")),
selfp->giv_settings->default_auto_contrast);
gtk_image_viewer_set_fill_on_resize(GTK_IMAGE_VIEWER(selfp->w_imgv),
selfp->giv_settings->default_auto_resize);
// Handle the command line
if (argc == argp+1) {
char *filename = argv[argp++];
char *basename = g_path_get_basename(filename);
giv_win_read_dir_into_filename_list(self, filename);
selfp->filename_list_index = -1;
for (int i=0; i<(int)selfp->filename_list->len; i++) {
GPtrArray *string_list = (GPtrArray*)g_ptr_array_index(selfp->filename_list, i);
gchar *filename0 = (gchar*)g_ptr_array_index(string_list, 0);
char *fl_basename = g_path_get_basename(filename0);
bool are_equal = (slip(fl_basename) == slip(basename));
g_free(fl_basename);
if (are_equal) {
selfp->filename_list_index = i;
break;
}
}
if (selfp->filename_list->len
&& selfp->filename_list_index < 0) {
app_error(self,
"Failed loading %s! No such file.\n",
filename);
GPtrArray *string_list = (GPtrArray*)g_ptr_array_index(selfp->filename_list, 0);
gchar *filename0 = (gchar*)g_ptr_array_index(string_list, 0);
giv_win_load_file(self, filename0);
selfp->filename_list_index = 0;
}
#if 0
else
giv_win_set_current_file(self,
selfp->filename_list_index);
#endif
g_free(basename);
}
else {
selfp->filename_list_index = 0;