Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 316 lines (260 sloc) 10.472 kB
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
1 ! Copyright (C) 2011
2 ! Free Software Foundation, Inc.
3
4 ! This file is part of the gtk-fortran GTK+ Fortran Interface library.
5
6 ! This is free software; you can redistribute it and/or modify
7 ! it under the terms of the GNU General Public License as published by
8 ! the Free Software Foundation; either version 3, or (at your option)
9 ! any later version.
10
11 ! This software is distributed in the hope that it will be useful,
12 ! but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ! GNU General Public License for more details.
15
16 ! Under Section 7 of GPL version 3, you are granted additional
17 ! permissions described in the GCC Runtime Library Exception, version
18 ! 3.1, as published by the Free Software Foundation.
19
20 ! You should have received a copy of the GNU General Public License along with
21 ! this program; see the files COPYING3 and COPYING.RUNTIME respectively.
22 ! If not, see <http://www.gnu.org/licenses/>.
23 !
24 ! Contributed by James Tappin
25 ! Last modification: 11-21-2011
26
27 !!$T Template file for gtk-hl-combobox.f90.
28 !!$T Make edits to this file, and keep them identical between the
29 !!$T GTK2 & GTK3 branches.
30
585e643 @jtappin Update syntax for conditional lines in high-level templates.
jtappin authored
31 !!$T Lines to appear only in specific versions should be prefixed by
32 !!$T !!$<lib><op><ver>!
33 !!$T Where <lib> is GTK or GLIB, <op> is one of < > <= >=
34 !!$T and <ver> is the version boundary, e.g. !!$GTK<=2.24! to include
35 !!$T the line in GTK+ version 2.24 and higher.
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
36 !!$T The mk_gtk_hl.pl script should be used to generate the source file.
37
38 module gtk_hl_combobox
39 !*
40 ! ComboBox
41 ! This interface implements the GtkComboBoxText widget for making a chooser.
42 ! While this has more limited capabilities than the full GtkComboBox, it
43 ! is adequate for the vast majority of uses.
44 !/
45
46 use gtk_sup
47 use iso_c_binding
48 ! Autogenerated use's
49 use gtk, only: gtk_combo_box_get_active, gtk_combo_box_new,&
50 & gtk_combo_box_set_active, &
51 & gtk_widget_set_sensitive, gtk_widget_set_tooltip_text,&
a6fa4b8 @jtappin Add multiple and all delete options, and routine to get count. Improv…
jtappin authored
52 !!$GTK< 2.24! & gtk_combo_box_get_active_text, &
53 !!$GTK< 2.24! & gtk_combo_box_new_with_entry, &
54 !!$GTK< 2.24! & gtk_combo_box_new_text, gtk_combo_box_entry_new_text, &
55 !!$GTK< 2.24! & gtk_combo_box_append_text,&
56 !!$GTK< 2.24! & gtk_combo_box_insert_text,&
57 !!$GTK< 2.24! & gtk_combo_box_prepend_text,&
58 !!$GTK< 2.24! & gtk_combo_box_remove_text,&
59 !!$GTK>=2.24! & gtk_combo_box_text_get_active_text, gtk_combo_box_text_new,&
60 !!$GTK>=2.24! & gtk_combo_box_text_new_with_entry, &
61 !!$GTK>=2.24! & gtk_combo_box_text_remove, &
62 !!$GTK>=2.24! & gtk_combo_box_text_append_text,&
63 !!$GTK>=2.24! & gtk_combo_box_text_insert_text,&
64 !!$GTK>=2.24! & gtk_combo_box_text_prepend_text,&
65 !!$GTK>=3.0! & gtk_combo_box_text_remove_all, &
66 & gtk_combo_box_get_model, gtk_tree_model_iter_n_children, &
e6eb552 @jtappin * Add scrolled window to HL_CONTAINER, and a markup friendly set labe…
jtappin authored
67 & TRUE, FALSE, g_signal_connect
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
68
69 implicit none
70
a6fa4b8 @jtappin Add multiple and all delete options, and routine to get count. Improv…
jtappin authored
71 interface hl_gtk_combo_box_delete
72 module procedure hl_gtk_combo_box_delete_single
73 module procedure hl_gtk_combo_box_delete_multi
74 module procedure hl_gtk_combo_box_delete_all
75 end interface hl_gtk_combo_box_delete
76
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
77 contains
78 !+
79 function hl_gtk_combo_box_new(has_entry, changed, data, initial_choices, &
80 & sensitive, tooltip, active) result(cbox)
81
82 type(c_ptr) :: cbox
83 integer(kind=c_int), intent(in), optional :: has_entry
84 type(c_funptr), optional :: changed
85 type(c_ptr), intent(in), optional :: data
86 character(len=*), dimension(:), intent(in), optional :: initial_choices
87 integer(kind=c_int), intent(in), optional :: sensitive
88 character(kind=c_char), dimension(*), optional, intent(in) :: tooltip
89 integer(kind=c_int), optional, intent(in) :: active
90
91 ! Creator for the combobox.
92 !
93 ! HAS_ENTRY: boolean: optional: Set to TRUE to add an entry field.
94 ! CHANGED: c_funptr: optional: Callback routine for the "changed" signal.
95 ! DATA: c_ptr: optional: User data for the changed callback.
96 ! INITIAL_CHOICES: string(): optional: Initial list of choices.
97 ! SENSITIVE: boolean: optional: Set to FALSE to make the widget start in an
98 ! insensitive state.
99 ! TOOLTIP: string: optional: A tooltip to display when the pointer is
100 ! held over the widget.
101 ! ACTIVE: c_int: optional: The initial active selection.
102 !-
103
104 integer(kind=c_int) :: ientry
105 integer(kind=c_int) :: i
106
107 if (present(has_entry)) then
108 ientry = has_entry
109 else
110 ientry = FALSE
111 end if
112
113 if (ientry == TRUE) then
114 !GTK3
a6fa4b8 @jtappin Add multiple and all delete options, and routine to get count. Improv…
jtappin authored
115 !!$GTK>=2.24! cbox = gtk_combo_box_text_new_with_entry()
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
116 !GTK2
a6fa4b8 @jtappin Add multiple and all delete options, and routine to get count. Improv…
jtappin authored
117 !!$GTK< 2.24! cbox = gtk_combo_box_entry_new_text()
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
118 else
119 !GTK3
a6fa4b8 @jtappin Add multiple and all delete options, and routine to get count. Improv…
jtappin authored
120 !!$GTK>=2.24! cbox = gtk_combo_box_text_new()
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
121 !GTK2
a6fa4b8 @jtappin Add multiple and all delete options, and routine to get count. Improv…
jtappin authored
122 !!$GTK< 2.24! cbox = gtk_combo_box_new_text()
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
123 end if
124
125 if (present(initial_choices)) then
126 do i=1,size(initial_choices)
127 !GTK3
a6fa4b8 @jtappin Add multiple and all delete options, and routine to get count. Improv…
jtappin authored
128 !!$GTK>=2.24! call gtk_combo_box_text_append_text(cbox, &
129 !!$GTK>=2.24! & trim(initial_choices(i))//C_NULL_CHAR)
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
130 !GTK2
a6fa4b8 @jtappin Add multiple and all delete options, and routine to get count. Improv…
jtappin authored
131 !!$GTK< 2.24! call gtk_combo_box_append_text(cbox, &
132 !!$GTK< 2.24! & trim(initial_choices(i))//C_NULL_CHAR)
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
133 end do
134 end if
135
136 if (present(changed)) then
137 if (present(data)) then
e6eb552 @jtappin * Add scrolled window to HL_CONTAINER, and a markup friendly set labe…
jtappin authored
138 call g_signal_connect(cbox, "changed"//C_NULL_CHAR, changed, data)
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
139 else
e6eb552 @jtappin * Add scrolled window to HL_CONTAINER, and a markup friendly set labe…
jtappin authored
140 call g_signal_connect(cbox, "changed"//C_NULL_CHAR, changed)
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
141 end if
142 end if
143
144 if (present(active)) call gtk_combo_box_set_active(cbox, active)
145 if (present(sensitive)) call gtk_widget_set_sensitive(cbox, sensitive)
146 if (present(tooltip)) call gtk_widget_set_tooltip_text(cbox, tooltip)
147 end function hl_gtk_combo_box_new
148
149 !+
150 subroutine hl_gtk_combo_box_add_text(cbox, text, index, at_start)
151
152 type(c_ptr), intent(in) :: cbox
153 character(kind=c_char), dimension(*), optional :: text
154 integer(kind=c_int), intent(in), optional :: index
155 integer(kind=c_int), intent(in), optional :: at_start
156
157 ! Add a new choice to a combo box.
158 !
159 ! CBOX: c_ptr: required: The combo box to modify.
160 ! TEXT: string: required: The text to add.
161 ! INDEX: c_int: optional: The location at which to add the text.
162 ! AT_START: boolean: optional: If set to TRUE and INDEX is not given
163 ! then add the text at the start of the list.
164 !
165 ! If neither INDEX nor AT_START is present the text is appended.
166 !-
167
168 integer(kind=c_int) :: prepend
169
170 if (present(index)) then
171 !GTK3
a6fa4b8 @jtappin Add multiple and all delete options, and routine to get count. Improv…
jtappin authored
172 !!$GTK>=2.24! call gtk_combo_box_text_insert_text(cbox, index, text)
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
173 !GTK2
a6fa4b8 @jtappin Add multiple and all delete options, and routine to get count. Improv…
jtappin authored
174 !!$GTK< 2.24! call gtk_combo_box_insert_text(cbox, index, text)
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
175 else
176 if (present(at_start)) then
177 prepend = at_start
178 else
179 prepend = FALSE
180 end if
181 if (prepend == TRUE) then
182 !GTK3
a6fa4b8 @jtappin Add multiple and all delete options, and routine to get count. Improv…
jtappin authored
183 !!$GTK>=2.24! call gtk_combo_box_text_prepend_text(cbox, text)
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
184 !GTK2
a6fa4b8 @jtappin Add multiple and all delete options, and routine to get count. Improv…
jtappin authored
185 !!$GTK< 2.24! call gtk_combo_box_prepend_text(cbox, text)
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
186 else
187 !GTK3
a6fa4b8 @jtappin Add multiple and all delete options, and routine to get count. Improv…
jtappin authored
188 !!$GTK>=2.24! call gtk_combo_box_text_append_text(cbox, text)
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
189 !GTK2
a6fa4b8 @jtappin Add multiple and all delete options, and routine to get count. Improv…
jtappin authored
190 !!$GTK< 2.24! call gtk_combo_box_append_text(cbox, text)
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
191 end if
192 end if
193 end subroutine hl_gtk_combo_box_add_text
194
195 !+
a6fa4b8 @jtappin Add multiple and all delete options, and routine to get count. Improv…
jtappin authored
196 subroutine hl_gtk_combo_box_delete_single(cbox, index)
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
197
198 type(c_ptr), intent(in) :: cbox
199 integer(kind=c_int), intent(in) :: index
200
201 ! Delete a line from a combo box
202 !
203 ! CBOX: c_ptr: required: The combo box to update
204 ! INDEX: c_int: required: The index of the choce to remove
a6fa4b8 @jtappin Add multiple and all delete options, and routine to get count. Improv…
jtappin authored
205 !
206 ! Usually called via the generic hl_gtk_combo_box_delete interface.
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
207 !-
208
209 !GTK3
a6fa4b8 @jtappin Add multiple and all delete options, and routine to get count. Improv…
jtappin authored
210 !!$GTK>=2.24! call gtk_combo_box_text_remove(cbox, index)
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
211 !GTK2
a6fa4b8 @jtappin Add multiple and all delete options, and routine to get count. Improv…
jtappin authored
212 !!$GTK< 2.24! call gtk_combo_box_remove_text(cbox, index)
213
214 end subroutine hl_gtk_combo_box_delete_single
215
216 !+
217 subroutine hl_gtk_combo_box_delete_multi(cbox, index)
218
219 type(c_ptr), intent(in) :: cbox
220 integer(kind=c_int), dimension(:), intent(in) :: index
221
222 ! Delete lines from a combo box
223 !
224 ! CBOX: c_ptr: required: The combo box to update
225 ! INDEX: c_int(): required: The index of the choce to remove
226 !
227 ! Usually called via the generic hl_gtk_combo_box_delete interface.
228 !-
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
229
a6fa4b8 @jtappin Add multiple and all delete options, and routine to get count. Improv…
jtappin authored
230 integer(kind=c_int) :: i
231
232 do i = size(index),1,-1
233 !GTK3
234 !!$GTK>=2.24! call gtk_combo_box_text_remove(cbox, index(i))
235 !GTK2
236 !!$GTK< 2.24! call gtk_combo_box_remove_text(cbox, index(i))
237 end do
238 end subroutine hl_gtk_combo_box_delete_multi
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
239
240 !+
a6fa4b8 @jtappin Add multiple and all delete options, and routine to get count. Improv…
jtappin authored
241 subroutine hl_gtk_combo_box_delete_all(cbox)
242
243 type(c_ptr), intent(in) :: cbox
244
245 ! Delete all lines from a combo box
246 !
247 ! CBOX: c_ptr: required: The combo box to update
248 !
249 ! Usually called via the generic hl_gtk_combo_box_delete interface.
250 !-
251
25765f9 @jtappin Fix conditional compile error.
jtappin authored
252 !!$GTK<3.0! integer(kind=c_int) :: n, i
a6fa4b8 @jtappin Add multiple and all delete options, and routine to get count. Improv…
jtappin authored
253
254 !GTK3
25765f9 @jtappin Fix conditional compile error.
jtappin authored
255 !!$GTK>=3.0! call gtk_combo_box_text_remove_all(cbox)
a6fa4b8 @jtappin Add multiple and all delete options, and routine to get count. Improv…
jtappin authored
256 !GTK2
257 ! Note that by using the hl delete we avoid 3-level conditional compilation.
25765f9 @jtappin Fix conditional compile error.
jtappin authored
258 !!$GTK<3.0! n = hl_gtk_combo_box_n_entries(cbox)
259 !!$GTK<3.0! do i = 1, n
260 !!$GTK<3.0! call hl_gtk_combo_box_delete(cbox, 0)
261 !!$GTK<3.0! end do
a6fa4b8 @jtappin Add multiple and all delete options, and routine to get count. Improv…
jtappin authored
262
263 end subroutine hl_gtk_combo_box_delete_all
264 !+
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
265 function hl_gtk_combo_box_get_active(cbox, text, ftext) result(index)
266
267 integer(kind=c_int) :: index
268 type(c_ptr), intent(in) :: cbox
269 type(c_ptr), intent(out), optional :: text
270 character(len=*), intent(out), optional :: ftext
271
272 ! Get the selection from a combo box
273 !
274 ! CBOX: c_ptr: required: The combo box to query.
275 ! TEXT: c_ptr: optional: C pointer to the text.
276 ! FTEXT: fstring: optional: The string as a Fortran string.
277 !-
278
279 type(c_ptr), target :: ctext
280
281 index = gtk_combo_box_get_active(cbox)
282
283 if (present(text) .or. present(ftext)) then
284
285 !GTK3
a6fa4b8 @jtappin Add multiple and all delete options, and routine to get count. Improv…
jtappin authored
286 !!$GTK>=2.24! ctext = gtk_combo_box_text_get_active_text(cbox)
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
287 !GTK2
a6fa4b8 @jtappin Add multiple and all delete options, and routine to get count. Improv…
jtappin authored
288 !!$GTK< 2.24! ctext = gtk_combo_box_get_active_text(cbox)
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
289
290 ! This is a bit ugly
291 if (present(ftext)) &
292 & call convert_c_string(ctext, len(ftext), ftext)
293
294 if (present(text)) text=ctext
295 end if
296 end function hl_gtk_combo_box_get_active
a6fa4b8 @jtappin Add multiple and all delete options, and routine to get count. Improv…
jtappin authored
297
298 !+
299 function hl_gtk_combo_box_n_entries(cbox) result(count)
300 integer(kind=c_int) :: count
301 type(c_ptr), intent(in) :: cbox
302
303 ! Find the number of entries in a combo box.
304 !
305 ! CBOX: c_ptr: required: The combo box to query.
306 !-
307
308 type(c_ptr) :: model
309
310 model = gtk_combo_box_get_model(cbox)
311 count = gtk_tree_model_iter_n_children (model, C_NULL_PTR)
312
313 end function hl_gtk_combo_box_n_entries
314
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
315 end module gtk_hl_combobox
Something went wrong with that request. Please try again.