-
Notifications
You must be signed in to change notification settings - Fork 45
/
gtk-hl-tree-tmpl.f90
3423 lines (3000 loc) · 128 KB
/
gtk-hl-tree-tmpl.f90
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
! Copyright (C) 2011
! Free Software Foundation, Inc.
! This file is part of the gtk-fortran GTK+ Fortran Interface library.
! This 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, or (at your option)
! any later version.
! This software 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.
! Under Section 7 of GPL version 3, you are granted additional
! permissions described in the GCC Runtime Library Exception, version
! 3.1, as published by the Free Software Foundation.
! You should have received a copy of the GNU General Public License along with
! this program; see the files COPYING3 and COPYING.RUNTIME respectively.
! If not, see <http://www.gnu.org/licenses/>.
!
! Contributed by James Tappin
! Last modification: 07-30-2012
!!$T Template file for gtk-hl-tree.f90.
!!$T Make edits to this file, and keep them identical between the
!!$T GTK2 & GTK3 branches.
!!$T Lines to appear only in specific versions should be prefixed by
!!$T !!$<lib><op><ver>!
!!$T Where <lib> is GTK or GLIB, <op> is one of < > <= >=
!!$T and <ver> is the version boundary, e.g. !!$GTK<=2.24! to include
!!$T the line in GTK+ version 2.24 and higher.
!!$T The mk_gtk_hl.pl script should be used to generate the source file.
!*
! Lists and Trees
module gtk_hl_tree
! These functions attempt to hide some of the complexity of the GtkTreeView
! system of widgets and object, while still allowing the main functionality
! to be accessed. Most possible renderers are supported (spinner is not).
!
! There are three types of list and tree supported.
!
! 1. listn; A multi-column flat list.
! 2. list1; A single-column flat list, that allows only string values.
! (This is now implemented by calls to the corresponding listn routines).
! Editability is not available for list1.
! 3. tree; A tree view (similar to listn but with child rows).
!/
use gtk_sup
use iso_c_binding
use iso_fortran_env, only: error_unit
! Auto generated use's
use gtk, only: gtk_cell_layout_get_cells,&
& gtk_cell_renderer_set_alignment,&
& gtk_cell_renderer_set_padding, gtk_cell_renderer_text_new,&
& gtk_container_add, gtk_list_store_append,&
& gtk_list_store_clear, gtk_list_store_insert,&
& gtk_list_store_move_after, gtk_list_store_move_before,&
& gtk_list_store_newv, gtk_list_store_remove,&
& gtk_list_store_reorder, gtk_list_store_set_value,&
& gtk_list_store_swap, gtk_scrolled_window_new,&
& gtk_scrolled_window_set_policy,&
& gtk_tree_model_get_column_type, gtk_tree_model_get_iter,&
& gtk_tree_model_get_iter_first, gtk_tree_model_get_value,&
& gtk_tree_model_iter_children, gtk_tree_model_iter_n_children,&
& gtk_tree_model_iter_next, gtk_tree_model_iter_nth_child,&
& gtk_tree_model_iter_parent, gtk_tree_path_free,&
& gtk_tree_model_get_string_from_iter, &
& gtk_tree_model_get_iter_from_string, &
& gtk_tree_path_get_depth, gtk_tree_path_get_indices,&
& gtk_tree_path_get_indices_with_depth,&
& gtk_tree_selection_get_selected,&
& gtk_tree_selection_get_selected_rows,&
& gtk_tree_selection_select_iter, gtk_tree_selection_set_mode,&
& gtk_tree_selection_unselect_all, gtk_tree_store_append,&
& gtk_tree_store_clear, gtk_tree_store_insert,&
& gtk_tree_store_insert_before, gtk_tree_store_newv,&
& gtk_tree_store_prepend, gtk_tree_store_remove,&
& gtk_tree_store_set_value, gtk_tree_view_append_column,&
& gtk_tree_view_column_add_attribute, gtk_tree_view_column_new,&
& gtk_tree_view_column_pack_start,&
& gtk_tree_view_column_set_cell_data_func,&
& gtk_tree_view_column_set_fixed_width,&
& gtk_tree_view_column_set_resizable,&
& gtk_tree_view_column_set_sizing,&
& gtk_tree_view_column_set_sort_column_id,&
& gtk_tree_view_column_set_sort_indicator,&
& gtk_tree_view_column_set_title, gtk_tree_view_get_column,&
& gtk_tree_view_get_model, gtk_tree_view_get_selection,&
& gtk_tree_view_new, gtk_tree_view_new_with_model,&
& gtk_tree_model_get_type, &
& gtk_widget_set_sensitive, gtk_widget_set_size_request,&
& gtk_widget_set_tooltip_text, &
& gtk_adjustment_set_lower, gtk_adjustment_set_upper, &
& gtk_adjustment_set_step_increment, gtk_adjustment_new, &
& gtk_adjustment_set_page_increment, gtk_adjustment_set_value, &
& gtk_cell_renderer_toggle_new, gtk_cell_renderer_spin_new, &
& gtk_cell_renderer_toggle_get_active, gtk_cell_renderer_progress_new, &
& gtk_cell_renderer_set_fixed_size, gtk_cell_renderer_pixbuf_new, &
& gtk_cell_renderer_combo_new, gtk_combo_box_set_active, &
& gtk_cell_renderer_toggle_set_radio, &
& GTK_POLICY_AUTOMATIC, GTK_TREE_VIEW_COLUMN_FIXED, &
& GTK_SELECTION_MULTIPLE, &
& TRUE, FALSE, g_signal_connect
use g, only: g_list_foreach, g_list_free, g_list_length, g_list_nth,&
& g_list_nth_data, g_object_get_data, g_object_set_data,&
& g_object_set_property, g_value_get_boolean, &
!!$GLIB< 2.32! & g_value_get_char, g_value_set_char, &
!!$GLIB>=2.32! & g_value_get_schar, g_value_set_schar, &
& g_value_get_double, g_value_get_float, g_value_get_int,&
& g_value_get_int64, g_value_get_long, g_value_get_string,&
& g_value_get_uchar, g_value_get_uint, g_value_get_uint64,&
& g_value_get_ulong, g_value_init, g_value_set_boolean,&
& g_value_set_double, g_value_set_float,&
& g_value_set_int, g_value_set_int64, g_value_set_long,&
& g_value_set_string, g_value_set_uchar, g_value_set_uint,&
& g_value_set_uint64, g_value_set_ulong, g_value_unset, &
& g_object_get_property, g_value_get_object, g_value_set_object, &
& g_value_take_object, g_object_ref
use gdk_pixbuf, only: gdk_pixbuf_get_type
implicit none
! Interfaces to give suitable names to procedures that are
! identical between lists and trees. (Yes I know this is the
! reverse of how the construct is usually meant to be used).
interface hl_gtk_listn_set_cell_data_func
module procedure hl_gtk_list_tree_set_cell_data_func
end interface hl_gtk_listn_set_cell_data_func
interface hl_gtk_tree_set_cell_data_func
module procedure hl_gtk_list_tree_set_cell_data_func
end interface hl_gtk_tree_set_cell_data_func
interface hl_gtk_listn_config_spin
module procedure hl_gtk_list_tree_config_spin
end interface hl_gtk_listn_config_spin
interface hl_gtk_tree_config_spin
module procedure hl_gtk_list_tree_config_spin
end interface hl_gtk_tree_config_spin
interface hl_gtk_listn_config_combo
module procedure hl_gtk_list_tree_combo_model_config
end interface hl_gtk_listn_config_combo
interface hl_gtk_tree_config_combo
module procedure hl_gtk_list_tree_combo_model_config
end interface hl_gtk_tree_config_combo
interface hl_gtk_listn_combo_set_model
module procedure hl_gtk_list_tree_combo_model_attach
end interface hl_gtk_listn_combo_set_model
interface hl_gtk_tree_combo_set_model
module procedure hl_gtk_list_tree_combo_model_attach
end interface hl_gtk_tree_combo_set_model
! Renderer types (convenience constants)
character(len=10), parameter :: hl_gtk_cell_text = 'text'
character(len=10), parameter :: hl_gtk_cell_toggle = 'toggle'
character(len=10), parameter :: hl_gtk_cell_radio = 'radio'
character(len=10), parameter :: hl_gtk_cell_combo = 'combo'
character(len=10), parameter :: hl_gtk_cell_spin = 'spin'
character(len=10), parameter :: hl_gtk_cell_pixbuf = 'pixbuf'
character(len=10), parameter :: hl_gtk_cell_progress = 'progress'
character(len=10), parameter :: hl_gtk_cell_spinner = 'spinner'
! Make the code-saver routines private
private :: hl_gtk_list_tree_add_column, hl_gtk_list_tree_set_gvalue, &
& hl_gtk_list_tree_get_gvalue, hl_gtk_list_tree_set_cell_data_func, &
& hl_gtk_list_tree_type_adjust, hl_gtk_list_tree_config_spin, &
& hl_gtk_list_tree_combo_model_attach, &
& hl_gtk_list_tree_combo_model_config
contains
!+
function hl_gtk_listn_new(scroll, ncols, types, changed, data, multiple,&
& width, titles, height, swidth, align, ixpad, iypad, renderers, &
& sensitive, tooltip, sortable, editable, colnos, edited, &
& data_edited, edited_text, data_edited_text, toggled,&
& data_toggled, edited_spin, data_edited_spin, &
& edited_combo, data_edited_combo, changed_combo, data_changed_combo,&
& toggled_radio, data_toggled_radio, &
& hscroll_policy, vscroll_policy) result(list)
type(c_ptr) :: list
type(c_ptr), intent(out), optional :: scroll
integer(kind=c_int), intent(in), optional :: ncols
integer(kind=type_kind), dimension(:), intent(in), optional :: types
type(c_funptr), optional :: changed
type(c_ptr), intent(in), optional :: data
integer(kind=c_int), intent(in), optional :: multiple
integer(kind=c_int), intent(in), optional, dimension(:) :: width
character(len=*), dimension(:), intent(in), optional :: titles, renderers
integer(kind=c_int), intent(in), optional :: height, swidth
real(kind=c_float), intent(in), optional, dimension(:) :: align
integer(kind=c_int), intent(in), optional, dimension(:) :: ixpad, iypad
integer(kind=c_int), intent(in), optional :: sensitive
character(kind=c_char), dimension(*), intent(in), optional :: tooltip
integer(kind=c_int), intent(in), optional, dimension(:) :: sortable, editable
type(c_funptr), optional :: edited, edited_text, toggled, edited_spin, &
& edited_combo, changed_combo, toggled_radio
type(c_ptr), optional, intent(in) :: data_edited, data_edited_text, &
& data_toggled, data_edited_spin, data_edited_combo, &
& data_changed_combo, data_toggled_radio
integer(kind=c_int), dimension(:), allocatable, intent(out), optional, target :: colnos
integer(kind=c_int), intent(in), optional :: hscroll_policy, vscroll_policy
! Make a multi column list
!
! SCROLL: c_ptr: optional: A scrollable widget containing the list.
! (If present, then this is used to pack the list)
! NCOLS: c_int: optional: The number of columns.
! TYPES: GType(): optional: The types for each column.
! CHANGED: c_funptr: optional: Callback function for the "changed"
! signal to the associated selection object.
! DATA: c_ptr: optional: Data to be passed to/from the callback.
! MULTIPLE: boolean: optional: Whether multiple selections are allowed.
! WIDTH: integer(): optional: The width of the displayed columns.
! TITLES: string(): optional: Titles for the visible columns.
! HEIGHT: c_int: optional: The height of the display (this is
! actually the height of the scroll box).
! SWIDTH: c_int: Optional: The width for the scroll box
! ALIGN: c_float(): optional: The alignment of the columns
! IXPAD: c_int(): optional: The X-padding around the cells.
! IYPAD: c_int(): optional: The Y-Padding around the cells.
! RENDERERS: f_string(): optional: List of renderer types.
! SENSITIVE: boolean: optional: Whether the widget is intially sensitive.
! TOOLTIP: string: optional: Tooltip for the widget
! SORTABLE: boolean(): optional: Set whether the list can be sorted
! on that column.
! EDITABLE: boolean(): optional: Set whether the column can be edited.
! EDITED: c_funptr: optional: An alternative callback for the "edited"
! signal on edited cells. N.B. Only a single callback can be set
! if different actions are needed for different columns,
! you must use the column number inside the callback. See
! hl_gtk_listn_edit_cb for how to access the column numbers.
! Used for all "text" dereived renderers unless overridden
! by specific callbacks.
! DATA_EDITED: c_ptr: optional: Data to pass to the edited callback.
! EDITED_TEXT: c_funptr: optional: An alternative callback for
! text renderers (not applied to derived renderers).
! DATA_EDITED_TEXT: c_ptr: optional: Data to pass to the edited_text
! callback.
! EDITED_SPIN: c_funptr: optional: An alternative callback for
! spin button.
! DATA_EDITED_SPIN: c_ptr: optional: Data to pass to the edited_spin
! callback.
! EDITED_COMBO: c_funptr: optional: An alternative callback for
! the "edited" signal from a combo cell
! DATA_EDITED_COMBO: c_ptr: optional: Data to pass to the edited_combo
! callback.
! TOGGLED: c_funptr: optional: An alternative callback for the "toggled"
! signal from toggle renderers.
! DATA_TOGGLED: c_ptr: optional: Data to pass to the toggled callback.
! TOGGLED_RADIO: c_funptr: optional: An alternative callback for the
! "toggled" signal from radio toggle renderers.
! DATA_TOGGLED_RADIO: c_ptr: optional: Data to pass to the toggled callback
! for radio toggle renderers
! CHANGED_COMBO: c_funptr: optional: Callback for the "changed" signal from
! a combo cell. This is not actually all that useful as the
! edited signal will be emitted as soon as focus leaves the combo.
! DATA_CHANGED_COMBO: c_ptr: optional: Data to pass to the changed callback.
! HSCROLL_POLICY: int: optional: Horizontal scrolling policy for the
! containing scroll window (default AUTOMATIC).
! VSCROLL_POLICY: int: optional: Vertical scrolling policy for the
! containing scroll window (default AUTOMATIC).
!
! At least one of the array arguments or NCOLS must be given.
! If TYPES is not given, then strings are assumed.
!
! The following types of renderer are implemented.
!
! * "text" (hl_gtk_cell_text) A standard text box (can also have
! numeric types.)
! * "toggle" (hl_gtk_cell_toggle) A toggle button (always
! G_TYPE_BOOLEAN).
! * "radio" (hl_gtk_cell_radio) A toggle button with radio button
! renderering. As far as I can see it is the programmer's
! responsibility to deal with the exclusivity--there does not
! appear to be an equivalent of the group for normal
! radio buttons.
! * "combo" (hl_gtk_cell_combo) A combo box--the default model supports
! strings only but user-defined models are possible.
! * "spin" (hl_gtk_cell_spin) A spin button. Always of type G_TYPE_DOUBLE.
! * "pixbuf" (hl_gtk_cell_pixbuf) A gdk_pixbuf. Always of type
! gdk_pixbuf_get_type()
! * "progress" (hl_gtk_cell_progress) A progress bar. Always of type
! G_TYPE_INT, not editable.
! * The spinner type is not (yet) implemented.
!-
integer(kind=c_int) :: ncols_all, i, hscroll, vscroll
integer(kind=type_kind), dimension(:), allocatable, target :: types_all
type(c_ptr) :: model, renderer, column, select
! Warn if the obsolete COLNOS argument is present
if (present(colnos)) write(error_unit, *) "hl_gtk_listn_new: "//&
& "The COLNOS argument is no longer needed."
! First find how many columns there are.
if (present(ncols)) then
ncols_all = ncols
else if (present(types)) then
ncols_all = size(types)
else if (present(titles)) then
ncols_all = size(titles)
else if (present(align)) then
ncols_all = size(align)
else if (present(width)) then
ncols_all = size(width)
else if (present(sortable)) then
ncols_all = size(sortable)
else if (present(ixpad)) then
ncols_all = size(ixpad)
else if (present(iypad)) then
ncols_all = size(iypad)
else if (present(editable)) then
ncols_all = size(editable)
else if (present(renderers)) then
ncols_all = size(renderers)
else
write(error_unit,*) &
& "hl_gtk_listn_new: Cannot determine the number of columns"
list = C_NULL_PTR
scroll=C_NULL_PTR
return
end if
! Now determine the column types.
allocate(types_all(ncols_all))
if (present(types)) then
types_all = types
else
types_all = (/ (ncols_all-1)*G_TYPE_STRING /)
end if
if (present(renderers)) &
& call hl_gtk_list_tree_type_adjust(types_all, renderers)
! Create the storage model and the list.
model = gtk_list_store_newv(ncols_all, c_loc(types_all))
list = gtk_tree_view_new_with_model(model)
if (present(scroll)) then
if (present(hscroll_policy)) then
hscroll = hscroll_policy
else
hscroll = GTK_POLICY_AUTOMATIC
end if
if (present(vscroll_policy)) then
vscroll = vscroll_policy
else
vscroll = GTK_POLICY_AUTOMATIC
end if
! Pack the list in the scroll box
scroll = gtk_scrolled_window_new(C_NULL_PTR, C_NULL_PTR)
call gtk_scrolled_window_set_policy(scroll, hscroll, &
& vscroll)
call gtk_container_add(scroll, list)
if (present(height) .and. present(swidth)) then
call gtk_widget_set_size_request(scroll,swidth,height)
else if (present(height)) then
call gtk_widget_set_size_request(scroll,-1_c_int,height)
else if (present(swidth)) then
call gtk_widget_set_size_request(scroll,swidth,1_c_int)
end if
else
if (present(height) .and. present(swidth)) then
call gtk_widget_set_size_request(list,swidth,height)
else if (present(height)) then
call gtk_widget_set_size_request(list,-1_c_int,height)
else if (present(swidth)) then
call gtk_widget_set_size_request(list,swidth,1_c_int)
end if
end if
! Now the visible columns
do i = 1, ncols_all
call hl_gtk_list_tree_add_column(i, list, .true., type=types_all(i), &
& editable=editable, &
& ixpad=ixpad, iypad=iypad, align=align, titles=titles, &
& sortable=sortable, width=width, &
& renderers=renderers, edited=edited, data_edited=data_edited, &
& edited_text=edited_text, data_edited_text=data_edited_text, &
& edited_spin=edited_spin, data_edited_spin=data_edited_spin, &
& toggled=toggled, data_toggled=data_toggled, &
& edited_combo=edited_combo, data_edited_combo=data_edited_combo, &
& changed_combo=changed_combo, &
& data_changed_combo=data_changed_combo, &
& toggled_radio=toggled_radio, &
& data_toggled_radio=data_toggled_radio)
end do
! The event handler is attached to the selection object, as is
! the multiple selection property.
select = gtk_tree_view_get_selection(list)
if (present(multiple)) then
if (multiple == TRUE) &
& call gtk_tree_selection_set_mode(select, GTK_SELECTION_MULTIPLE)
end if
if (present(changed)) then
if (present(data)) then
call g_signal_connect(select, "changed"//c_null_char, &
& changed, data)
else
call g_signal_connect(select, "changed"//c_null_char, changed)
end if
end if
if (present(tooltip)) call gtk_widget_set_tooltip_text(list, tooltip)
if (present(sensitive)) &
& call gtk_widget_set_sensitive(list, sensitive)
deallocate(types_all)
end function hl_gtk_listn_new
!+
subroutine hl_gtk_listn_ins(list, row)
type(c_ptr), intent(in) :: list
integer(kind=c_int), intent(in), optional :: row
! Insert a row into a tabular list.
!
! LIST: c_ptr: required: The list into which to insert the row.
! ROW: c_int: optional: The row BEFORE which to insert the row
! (append if absent)
!-
type(c_ptr) :: store
type(gtktreeiter), target :: iter
! Get the ListStore
store = gtk_tree_view_get_model(list)
! Insert the row
if (present(row)) then
call gtk_list_store_insert(store, c_loc(iter), row)
else
call gtk_list_store_append(store, c_loc(iter))
end if
end subroutine hl_gtk_listn_ins
!+
subroutine hl_gtk_listn_rem(list, row)
type(c_ptr), intent(in) :: list
integer(kind=c_int), optional, intent(in) :: row
! Remove a row or clear a list
!
! LIST: c_ptr: required: The list to modify
! ROW: integer: optional: The row to remove, if absent clear the list
!-
integer(kind=c_int) :: valid
type(c_ptr) :: store
type(gtktreeiter), target :: iter
! Get list store
store = gtk_tree_view_get_model(list)
! If 2 arguments, then remove a row
if (present(row)) then
valid = gtk_tree_model_iter_nth_child(store, c_loc(iter), &
& C_NULL_PTR, row)
if (valid==FALSE) return
valid = gtk_list_store_remove(store, c_loc(iter))
else ! 1 argument clear the whole list
call gtk_list_store_clear(store)
end if
end subroutine hl_gtk_listn_rem
!+
function hl_gtk_listn_get_selections(list, indices, selection) result(count)
integer(kind=c_int) :: count
type(c_ptr), intent(in) :: list
integer(kind=c_int), dimension(:), allocatable, target, &
& intent(out), optional :: indices
type(c_ptr), optional :: selection
! Get the indices of the selected rows
!
! LIST: c_ptr: required: The list whose selections are to be found.
! INDICES: integer: optional: An allocatable array to return the
! list of selections. (If count = 0 it will not be allocated).
! If this argument is not given, then the number of
! selected rows is returned.
! SELECTION: c_ptr: optional: A selection. If this is given then LIST
! is ignored. This is most often used in the callback routine
! for the changed signal when that needs to find which element(s)
! are selected.
!
! Returns the number of selections.
!-
type(c_ptr) :: slist, vselection
integer(kind=c_int) :: i
type(c_ptr) :: cindex
integer(kind=c_int), pointer :: findex
if (present(selection)) then
vselection = selection
else
vselection = gtk_tree_view_get_selection(list)
end if
slist = gtk_tree_selection_get_selected_rows(vselection, &
& c_null_ptr)
! If no selections, then set the count to 0 and return
if (.not. c_associated(slist)) then
count=0
return
end if
! Determine how many rows are selected. Then if no output list was
! supplied, return, otherwise go on and make a list.
count = g_list_length(slist)
if (.not. present(indices)) return
allocate(indices(count))
! For each of the elements in the selection list, find its index
! from the hidden first column
do i = 1, count
cindex = gtk_tree_path_get_indices(g_list_nth_data(slist, i-1_c_int))
call c_f_pointer(cindex, findex)
indices(i) = findex
end do
! Free the selection list.
call g_list_foreach(slist, c_funloc(gtk_tree_path_free), C_NULL_PTR)
call g_list_free(slist)
end function hl_gtk_listn_get_selections
!+
subroutine hl_gtk_listn_set_selection(list, row)
type(c_ptr), intent(in) :: list
integer(kind=c_int), intent(in), optional :: row
! Set the selected row in a list (single row only).
!
! LIST: c_ptr: required: The list to work on.
! ROW: c_int: optional: The row to select (absent or less than 0 is
! clear selection)
!-
type(c_ptr) :: selection, store
type(gtktreeiter), target :: iter
integer(kind=c_int) :: valid
! Get list store and selection
store = gtk_tree_view_get_model(list)
selection = gtk_tree_view_get_selection(list)
if (.not. present(row)) then
call gtk_tree_selection_unselect_all(selection)
else if (row < 0) then
call gtk_tree_selection_unselect_all(selection)
else
valid = gtk_tree_model_iter_nth_child(store, c_loc(iter), &
& C_NULL_PTR, row)
if (valid == FALSE) return
call gtk_tree_selection_select_iter(selection, c_loc(iter))
end if
end subroutine hl_gtk_listn_set_selection
!+
subroutine hl_gtk_listn_set_cell(list, row, col, &
& svalue, fvalue, dvalue, ivalue, lvalue, l64value, logvalue, &
& i8value, pbvalue)
type(c_ptr), intent(in) :: list
integer(kind=c_int), intent(in) :: row, col
character(len=*), intent(in), optional :: svalue
real(kind=c_float), intent(in), optional :: fvalue
real(kind=c_double), intent(in), optional :: dvalue
integer(kind=c_int), intent(in), optional :: ivalue
integer(kind=c_long), intent(in), optional :: lvalue
integer(kind=c_int64_t), intent(in), optional :: l64value
logical, intent(in), optional :: logvalue
integer(kind=c_int8_t), intent(in), optional :: i8value
type(c_ptr), intent(in), optional :: pbvalue
! Set the value of a cell.
!
! LIST: c_ptr: required: The list containing the cell.
! ROW: c_int: required: The row of the cell
! COL: c_int: required: The column of the cell.
! SVALUE: string: optional: A string value for the cell.
! FVALUE: float: optional: A single precision FP value for the cell.
! DVALUE: double: optional: A double precision FP value for the cell.
! IVALUE: c_int: optional: A normal integer value for the cell.
! LVALUE: c_long: optional: A long integer value for the cell.
! L64VALUE: c_int64_t: optional: A 64-bit integer value for the cell.
! LOGVALUE: logical: optional: A logical value for the cell.
! I8VALUE: int8_t: optional: An 8-bit integer value for the cell.
! PBVALUE: c_ptr: optional: A pixbuf pointer value for the cell.
!
! Note that reasonable conversions are made between types.
!-
integer(kind=type_kind) :: ctype
type(c_ptr) :: store, val
integer(kind=c_int) :: valid
type(gtktreeiter), target :: iter
type(gvalue), target :: value
! Get list store
store = gtk_tree_view_get_model(list)
! Find the type for the requested column
ctype = gtk_tree_model_get_column_type(store, col)
! Get the iterator of the row
valid = gtk_tree_model_iter_nth_child(store, c_loc(iter), C_NULL_PTR, row)
if (valid == FALSE) return
! Set up the GValue to the right type.
val = c_loc(value)
call hl_gtk_list_tree_set_gvalue(val, ctype, svalue=svalue, fvalue=fvalue, &
& dvalue=dvalue, ivalue=ivalue, lvalue=lvalue, l64value=l64value, &
& logvalue=logvalue, i8value=i8value, pbvalue=pbvalue)
call gtk_list_store_set_value(store, c_loc(iter), col, val)
end subroutine hl_gtk_listn_set_cell
!+
subroutine hl_gtk_listn_get_cell(list, row, col, &
& svalue, fvalue, dvalue, ivalue, lvalue, l64value, logvalue, &
& i8value, pbvalue)
type(c_ptr), intent(in) :: list
integer(kind=c_int), intent(in) :: row, col
character(len=*), intent(out), optional :: svalue
real(kind=c_float), intent(out), optional :: fvalue
real(kind=c_double), intent(out), optional :: dvalue
integer(kind=c_int), intent(out), optional :: ivalue
integer(kind=c_long), intent(out), optional :: lvalue
integer(kind=c_int64_t), intent(out), optional :: l64value
logical, intent(out), optional :: logvalue
integer(kind=c_int8_t), intent(out), optional :: i8value
type(c_ptr), intent(out), optional :: pbvalue
! Retrieve the value of a cell.
!
! LIST: c_ptr: required: The list containing the cell.
! ROW: c_int: required: The row of the cell
! COL: c_int: required: The column of the cell.
! SVALUE: string: optional: A string value from the cell.
! FVALUE: float: optional: A single precision FP value from the cell.
! DVALUE: double: optional: A double precision FP value from the cell.
! IVALUE: c_int: optional: A normal integer value from the cell.
! LVALUE: c_long: optional: A long integer value from the cell.
! L64VALUE: c_int64_t: optional: A 64-bit integer value from the cell.
! LOGVALUE: logical : optional: A logical value from the cell.
! I8VALUE: int8_t: optional: An 8-bit integer value from the cell.
! PBVALUE: c_ptr: optional: A pixbuf pointer from the cell.
!
! Note that a similar conversion system to the set_cell routine
! except that strings can only be returned to SVALUE.
!-
integer(kind=type_kind) :: ctype
type(c_ptr) :: store, val
integer(kind=c_int) :: valid
type(gtktreeiter), target :: iter
type(gvalue), target :: value
! Get list store
store = gtk_tree_view_get_model(list)
! Find the type for the requested column
ctype = gtk_tree_model_get_column_type(store, col)
! Get the iterator of the row
valid = gtk_tree_model_iter_nth_child(store, c_loc(iter), C_NULL_PTR, row)
if (valid == FALSE) return
! Set up the GValue pointer (for convenience) gtk_tree_model_get_value
! does the initialization.
val = c_loc(value)
! Get the GValue of the cell.
call gtk_tree_model_get_value(store, c_loc(iter), col, val)
call hl_gtk_list_tree_get_gvalue(val, ctype, &
& svalue=svalue, fvalue=fvalue, dvalue=dvalue, ivalue=ivalue, &
& lvalue=lvalue, l64value=l64value, logvalue=logvalue, &
& i8value=i8value, pbvalue=pbvalue)
end subroutine hl_gtk_listn_get_cell
!+
subroutine hl_gtk_listn_move_row(list, row1, row2, after)
type(c_ptr), intent(in) :: list
integer(kind=c_int), intent(in) :: row1
integer(kind=c_int), intent(in), optional :: row2
integer(kind=c_int), intent(in), optional :: after
! Move a row in a list to a new location
!
! LIST: c_ptr: required: The list to work on.
! ROW1: c_int: required: The index of the row to move.
! ROW2: c_int: optional: The location before which to place
! the row. (If omitted, then move to start (or end if AFTER
! is TRUE)).
! AFTER: boolean: optional: Set this to TRUE to put the row after
! the location instead of before.
!-
type(c_ptr) :: store
type(gtktreeiter), target :: iter1, iter2
integer(kind=c_int) :: isafter
integer(kind=c_int) :: valid
if (present(after)) then
isafter = after
else
isafter = FALSE
end if
! Get list store
store = gtk_tree_view_get_model(list)
! Get the iterator of the row to move
valid = gtk_tree_model_iter_nth_child(store, c_loc(iter1), &
& C_NULL_PTR, row1)
if (valid == FALSE) return
! And of the target location
if (present(row2)) then
valid = gtk_tree_model_iter_nth_child(store, c_loc(iter2), &
& C_NULL_PTR, row2)
if (valid == FALSE) return
end if
! Move it
if (isafter == TRUE) then
if (present(row2)) then
call gtk_list_store_move_after(store, c_loc(iter1), c_loc(iter2))
else
call gtk_list_store_move_before(store, c_loc(iter1), C_NULL_PTR)
end if
else
if (present(row2)) then
call gtk_list_store_move_before(store, c_loc(iter1), c_loc(iter2))
else
call gtk_list_store_move_after(store, c_loc(iter1), C_NULL_PTR)
end if
end if
end subroutine hl_gtk_listn_move_row
!+
subroutine hl_gtk_listn_swap_rows(list, row1, row2)
type(c_ptr), intent(in) :: list
integer(kind=c_int), intent(in) :: row1, row2
! Move a row in a list to a new location
!
! LIST: c_ptr: required: The list to work on.
! ROW1: c_int: required: The index of the first row to move.
! ROW2: c_int: required: The index of the second row to move
!-
type(c_ptr) :: store
type(gtktreeiter), target :: iter1, iter2
integer(kind=c_int) :: valid
! Get list store
store = gtk_tree_view_get_model(list)
! Get the iterator of the first row to move
valid = gtk_tree_model_iter_nth_child(store, c_loc(iter1), &
& C_NULL_PTR, row1)
if (valid == FALSE) return
! And of the second
valid = gtk_tree_model_iter_nth_child(store, c_loc(iter2), &
& C_NULL_PTR, row2)
if (valid == FALSE) return
! Exchange the rows
call gtk_list_store_swap(store, c_loc(iter1), c_loc(iter2))
end subroutine hl_gtk_listn_swap_rows
!+
subroutine hl_gtk_listn_reorder(list, indices)
type(c_ptr), intent(in) :: list
integer(kind=c_int), intent(in), dimension(:) :: indices
! Move a row in a list to a new location
!
! LIST: c_ptr: required: The list to work on.
! INDICES: c_int(): required: The sorting array. The ith element
! contains the old location of the new (i-1)th row.
!-
type(c_ptr) :: store
integer(kind=c_int), dimension(:), allocatable, target :: idx
allocate(idx(size(indices)))
idx = indices
! Get list store
store = gtk_tree_view_get_model(list)
! Reorder the list
call gtk_list_store_reorder(store, c_loc(idx))
deallocate(idx)
end subroutine hl_gtk_listn_reorder
!+
function hl_gtk_listn_get_n_rows(list) result(nrows)
integer(kind=c_int) :: nrows
type(c_ptr), intent(in) :: list
! Return the number of rows in a list.
!
! LIST: c_ptr: required: the list to query
!-
type(c_ptr) :: store
! Get list store
store = gtk_tree_view_get_model(list)
! Find how many rows
nrows = gtk_tree_model_iter_n_children(store, C_NULL_PTR)
end function hl_gtk_listn_get_n_rows
!+
function hl_gtk_list1_new(scroll, width, changed, data, multiple, &
& sensitive, tooltip, title, height) result(list)
type(c_ptr) :: list
type(c_ptr), intent(out), optional :: scroll
integer(kind=c_int), intent(in), optional :: width
type(c_funptr), intent(in), optional :: changed
type(c_ptr), intent(in), optional :: data
integer(kind=c_int), intent(in), optional :: multiple, sensitive
character(kind=c_char), dimension(*), intent(in), optional :: tooltip
character(len=*), intent(in), optional :: title
integer(kind=c_int), intent(in), optional :: height
! A single column selectable list based on the GTK Tree View
!
! SCROLL: c_ptr: optional: A scroll box that will contain the list
! (used for packing etc.)
! WIDTH: integer: optional: The width of the displayed column.
! CHANGED: c_funptr: optional: Callback function for the "changed"
! signal to the associated selection object.
! DATA: c_ptr: optional: Data to be passed to/from the callback.
! MULTIPLE: boolean: optional: Whether multiple selections are allowed.
! SENSITIVE: boolean: optional: Whether the widget is intially sensitive.
! TOOLTIP: string: optional: Tooltip for the widget
! TITLE: string: optional: Title for the visible column.
! HEIGHT: integer: optional: The height of the display (this is
! actually the height of the scroll box).
!
! If other options (e.g. sortable columns or editable cells are needed,
! the use hl_gtk_listn_new with 1 column).
!-
integer(kind=type_kind), target, dimension(1) :: types
! Create list storage with 2 colums (one is a dummy, to provide an index)
types = (/ G_TYPE_STRING /)
! This slightly clunky if /else cascade is needed because the attempt to convert
! an unset scalar argument to an array causes a segfault.
if (present(title) .and. present(width)) then
list = hl_gtk_listn_new(scroll, ncols=1_c_int, types=types, &
& changed=changed, &
& data=data, multiple=multiple, sensitive=sensitive, &
& tooltip=tooltip, width=(/width/), titles=(/title/), height=height)
else if (present(title)) then
list = hl_gtk_listn_new(scroll, ncols=1_c_int, types=types, &
& changed=changed, &
& data=data, multiple=multiple, sensitive=sensitive, &
& tooltip=tooltip, titles=(/title/), height=height)
else if (present(width)) then
list = hl_gtk_listn_new(scroll, ncols=1_c_int, types=types, &
& changed=changed, &
& data=data, multiple=multiple, sensitive=sensitive, &
& tooltip=tooltip, width=(/width/), height=height)
else
list = hl_gtk_listn_new(scroll, ncols=1_c_int, types=types, &
& changed=changed, &
& data=data, multiple=multiple, sensitive=sensitive, &
& tooltip=tooltip, height=height)
end if
end function hl_gtk_list1_new
!+
subroutine hl_gtk_list1_ins(list, text, row)
type(c_ptr), intent(in) :: list
character(kind=c_char, len=*), intent(in), optional :: text
integer(kind=c_int), intent(in), optional :: row
! Insert a row into a list
!
! LIST: c_ptr: required: The list to insert to.
! TEXT: string: optional: The text to insert.
! ROW: integer: optional: The row at which to insert the text
! (omit to append)
!-
integer(kind=c_int) :: irow
type(c_ptr) :: store
call hl_gtk_listn_ins(list, row)
if (.not. present(text)) return
if (present(row)) then
irow = row
else
store = gtk_tree_view_get_model(list)
irow=gtk_tree_model_iter_n_children (store, C_NULL_PTR)-1
end if
call hl_gtk_listn_set_cell(list, irow, 0_c_int, svalue=text)
end subroutine hl_gtk_list1_ins
!+
subroutine hl_gtk_list1_rem(list, row)
type(c_ptr), intent(in) :: list
integer(kind=c_int), optional, intent(in) :: row
! Remove a row or clear a list
!
! LIST: c_ptr: required: The list to modify
! ROW: integer: optional: The row to remove, if absent clear the list
!-
call hl_gtk_listn_rem(list, row)
end subroutine hl_gtk_list1_rem
!+
function hl_gtk_list1_get_selections(list, indices, selection) result(count)
integer(kind=c_int) :: count
type(c_ptr), intent(in) :: list
integer(kind=c_int), dimension(:), allocatable, target, &
& intent(out), optional :: indices
type(c_ptr), optional :: selection
! Get the indices of the selected rows
!
! LIST: c_ptr: required: The list whose selections are to be found.
! INDICES: integer: optional: An allocatable array to return the
! list of selections. (If count = 0 it will not be allocated).
! If this argument is not given, then the number of
! selected rows is returned.
! SELECTION: c_ptr: optional: A selection. If this is given then LIST
! is ignored. This is most often used in the callback routine
! for the changed signal when that needs to find which element(s)
! are selected.
!
! Returns the number of selections.
!-
count = hl_gtk_listn_get_selections(list, indices, selection)