Skip to content
This repository
Newer
Older
100644 236 lines (198 sloc) 7.728 kb
5dc9ac01 » jtappin
2011-11-25 * Split high-level code into submodules
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 ! --------------------------------------------------------
28 ! gtk-hl-combobox.f90
4638a70d » jtappin
2011-12-01 * Further markup label support.
29 ! Generated: Thu Dec 1 21:27:37 2011 GMT
5dc9ac01 » jtappin
2011-11-25 * Split high-level code into submodules
30 ! Please do not edit this file directly,
31 ! Edit gtk-hl-combobox-tmpl.f90, and use ./mk_gtk_hl.pl to regenerate.
32 ! --------------------------------------------------------
33
34
35 module gtk_hl_combobox
36 !*
37 ! ComboBox
38 ! This interface implements the GtkComboBoxText widget for making a chooser.
39 ! While this has more limited capabilities than the full GtkComboBox, it
40 ! is adequate for the vast majority of uses.
41 !/
42
43 use gtk_sup
44 use iso_c_binding
45 ! Autogenerated use's
46 use gtk, only: gtk_combo_box_get_active, gtk_combo_box_new,&
47 & gtk_combo_box_set_active, &
48 & gtk_widget_set_sensitive, gtk_widget_set_tooltip_text,&
49 & gtk_combo_box_get_active_text, &
50 & gtk_combo_box_new_with_entry, &
51 & gtk_combo_box_new_text, gtk_combo_box_entry_new_text, &
52 & gtk_combo_box_append_text,&
53 & gtk_combo_box_insert_text,&
54 & gtk_combo_box_prepend_text,&
55 & gtk_combo_box_remove_text,&
56 !!$3 & gtk_combo_box_text_get_active_text, gtk_combo_box_text_new,&
57 !!$3 & gtk_combo_box_text_new_with_entry, &
58 !!$3 & gtk_combo_box_text_remove, &
59 !!$3 & gtk_combo_box_text_append_text,&
60 !!$3 & gtk_combo_box_text_insert_text,&
61 !!$3 & gtk_combo_box_text_prepend_text,&
62 & NULL, CNULL, FNULL, TRUE, FALSE, g_signal_connect
63
64 implicit none
65
66 contains
67 !+
68 function hl_gtk_combo_box_new(has_entry, changed, data, initial_choices, &
69 & sensitive, tooltip, active) result(cbox)
70
71 type(c_ptr) :: cbox
72 integer(kind=c_int), intent(in), optional :: has_entry
73 type(c_funptr), optional :: changed
74 type(c_ptr), intent(in), optional :: data
75 character(len=*), dimension(:), intent(in), optional :: initial_choices
76 integer(kind=c_int), intent(in), optional :: sensitive
77 character(kind=c_char), dimension(*), optional, intent(in) :: tooltip
78 integer(kind=c_int), optional, intent(in) :: active
79
80 ! Creator for the combobox.
81 !
82 ! HAS_ENTRY: boolean: optional: Set to TRUE to add an entry field.
83 ! CHANGED: c_funptr: optional: Callback routine for the "changed" signal.
84 ! DATA: c_ptr: optional: User data for the changed callback.
85 ! INITIAL_CHOICES: string(): optional: Initial list of choices.
86 ! SENSITIVE: boolean: optional: Set to FALSE to make the widget start in an
87 ! insensitive state.
88 ! TOOLTIP: string: optional: A tooltip to display when the pointer is
89 ! held over the widget.
90 ! ACTIVE: c_int: optional: The initial active selection.
91 !-
92
93 integer(kind=c_int) :: ientry
94 integer(kind=c_int) :: i
95
96 if (present(has_entry)) then
97 ientry = has_entry
98 else
99 ientry = FALSE
100 end if
101
102 if (ientry == TRUE) then
103 !GTK3
104 !!$3 cbox = gtk_combo_box_text_new_with_entry()
105 !GTK2
106 cbox = gtk_combo_box_entry_new_text()
107 else
108 !GTK3
109 !!$3 cbox = gtk_combo_box_text_new()
110 !GTK2
111 cbox = gtk_combo_box_new_text()
112 end if
113
114 if (present(initial_choices)) then
115 do i=1,size(initial_choices)
116 !GTK3
117 !!$3 call gtk_combo_box_text_append_text(cbox, &
118 !!$3 & trim(initial_choices(i))//CNULL)
119 !GTK2
120 call gtk_combo_box_append_text(cbox, &
121 & trim(initial_choices(i))//CNULL)
122 end do
123 end if
124
125 if (present(changed)) then
126 if (present(data)) then
127 call g_signal_connect(cbox, "changed"//CNULL, changed, data)
128 else
129 call g_signal_connect(cbox, "changed"//CNULL, changed)
130 end if
131 end if
132
133 if (present(active)) call gtk_combo_box_set_active(cbox, active)
134 if (present(sensitive)) call gtk_widget_set_sensitive(cbox, sensitive)
135 if (present(tooltip)) call gtk_widget_set_tooltip_text(cbox, tooltip)
136 end function hl_gtk_combo_box_new
137
138 !+
139 subroutine hl_gtk_combo_box_add_text(cbox, text, index, at_start)
140
141 type(c_ptr), intent(in) :: cbox
142 character(kind=c_char), dimension(*), optional :: text
143 integer(kind=c_int), intent(in), optional :: index
144 integer(kind=c_int), intent(in), optional :: at_start
145
146 ! Add a new choice to a combo box.
147 !
148 ! CBOX: c_ptr: required: The combo box to modify.
149 ! TEXT: string: required: The text to add.
150 ! INDEX: c_int: optional: The location at which to add the text.
151 ! AT_START: boolean: optional: If set to TRUE and INDEX is not given
152 ! then add the text at the start of the list.
153 !
154 ! If neither INDEX nor AT_START is present the text is appended.
155 !-
156
157 integer(kind=c_int) :: prepend
158
159 if (present(index)) then
160 !GTK3
161 !!$3 call gtk_combo_box_text_insert_text(cbox, index, text)
162 !GTK2
163 call gtk_combo_box_insert_text(cbox, index, text)
164 else
165 if (present(at_start)) then
166 prepend = at_start
167 else
168 prepend = FALSE
169 end if
170 if (prepend == TRUE) then
171 !GTK3
172 !!$3 call gtk_combo_box_text_prepend_text(cbox, text)
173 !GTK2
174 call gtk_combo_box_prepend_text(cbox, text)
175 else
176 !GTK3
177 !!$3 call gtk_combo_box_text_append_text(cbox, text)
178 !GTK2
179 call gtk_combo_box_append_text(cbox, text)
180 end if
181 end if
182 end subroutine hl_gtk_combo_box_add_text
183
184 !+
185 subroutine hl_gtk_combo_box_delete(cbox, index)
186
187 type(c_ptr), intent(in) :: cbox
188 integer(kind=c_int), intent(in) :: index
189
190 ! Delete a line from a combo box
191 !
192 ! CBOX: c_ptr: required: The combo box to update
193 ! INDEX: c_int: required: The index of the choce to remove
194 !-
195
196 !GTK3
197 !!$3 call gtk_combo_box_text_remove(cbox, index)
198 !GTK2
199 call gtk_combo_box_remove_text(cbox, index)
200
201 end subroutine hl_gtk_combo_box_delete
202
203 !+
204 function hl_gtk_combo_box_get_active(cbox, text, ftext) result(index)
205
206 integer(kind=c_int) :: index
207 type(c_ptr), intent(in) :: cbox
208 type(c_ptr), intent(out), optional :: text
209 character(len=*), intent(out), optional :: ftext
210
211 ! Get the selection from a combo box
212 !
213 ! CBOX: c_ptr: required: The combo box to query.
214 ! TEXT: c_ptr: optional: C pointer to the text.
215 ! FTEXT: fstring: optional: The string as a Fortran string.
216 !-
217
218 type(c_ptr), target :: ctext
219
220 index = gtk_combo_box_get_active(cbox)
221
222 if (present(text) .or. present(ftext)) then
223
224 !GTK3
225 !!$3 ctext = gtk_combo_box_text_get_active_text(cbox)
226 !GTK2
227 ctext = gtk_combo_box_get_active_text(cbox)
228
229 ! This is a bit ugly
230 if (present(ftext)) &
231 & call convert_c_string(ctext, len(ftext), ftext)
232
233 if (present(text)) text=ctext
234 end if
235 end function hl_gtk_combo_box_get_active
236 end module gtk_hl_combobox
Something went wrong with that request. Please try again.