Skip to content
Newer
Older
100644 213 lines (179 sloc) 7.44 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-progress.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_progress
39 !*
40 ! Progress Bar
41 ! Implements the GtkProgressBar widget. Includes the facility to
42 ! make a bar display "n of m" as well as the usual fraction.
43 !/
44
45 use gtk_sup
46 use iso_c_binding
47 ! Autogenerated use's
48 use gtk, only: gtk_orientable_set_orientation, gtk_progress_bar_new&
49 &, gtk_progress_bar_pulse, gtk_progress_bar_set_fraction,&
50 & gtk_progress_bar_set_pulse_step,&
51 & gtk_progress_bar_set_text, &
585e643 @jtappin Update syntax for conditional lines in high-level templates.
jtappin authored
52 !!$GTK< 3.0! & gtk_progress_bar_set_orientation, &
53 !!$GTK>=3.0! & gtk_progress_bar_set_show_text, &
54 !!$GTK>=3.0! & gtk_progress_bar_set_inverted, &
55 !!$GTK< 3.0! & GTK_PROGRESS_LEFT_TO_RIGHT, GTK_PROGRESS_BOTTOM_TO_TOP, &
56 !!$GTK< 3.0! & GTK_PROGRESS_TOP_TO_BOTTOM, GTK_PROGRESS_RIGHT_TO_LEFT, &
57 !!$GTK>=3.0! & GTK_ORIENTATION_VERTICAL, GTK_ORIENTATION_HORIZONTAL, &
e6eb552 @jtappin * Add scrolled window to HL_CONTAINER, and a markup friendly set labe…
jtappin authored
58 & TRUE, FALSE
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
59
60 implicit none
61
62 ! A progress bar value can be given as a fraction or m of n
63 interface hl_gtk_progress_bar_set
64 module procedure hl_gtk_progress_bar_set_f
65 module procedure hl_gtk_progress_bar_set_ii
66 end interface hl_gtk_progress_bar_set
67
68 contains
69
70 !+
71 function hl_gtk_progress_bar_new(vertical, reversed, step) result(bar)
72
73 type(c_ptr) :: bar
74 integer(kind=c_int), optional :: vertical, reversed
75 real(kind=c_double), optional :: step
76
77 ! Intializer for a progress bar
78 !
79 ! ORIENTATION: integer: optional: The orientation of the bar.
80 ! STEP: double: optional: The fractional step to advance when
81 ! pulsing the bar
82 !-
83
84 integer(kind=c_int) :: orientation
85
86 bar = gtk_progress_bar_new()
87
88 ! GTK2 version
585e643 @jtappin Update syntax for conditional lines in high-level templates.
jtappin authored
89 !!$GTK< 3.0! orientation = GTK_PROGRESS_LEFT_TO_RIGHT
90 !!$GTK< 3.0! if (present(vertical)) then
91 !!$GTK< 3.0! if (vertical == TRUE) orientation = GTK_PROGRESS_BOTTOM_TO_TOP
92 !!$GTK< 3.0! if (present(reversed)) then
93 !!$GTK< 3.0! if (reversed == TRUE) orientation = GTK_PROGRESS_TOP_TO_BOTTOM
94 !!$GTK< 3.0! end if
95 !!$GTK< 3.0! else if (present(reversed)) then
96 !!$GTK< 3.0! if (reversed == TRUE) orientation = GTK_PROGRESS_RIGHT_TO_LEFT
97 !!$GTK< 3.0! end if
98 !!$GTK< 3.0! call gtk_progress_bar_set_orientation(bar, orientation)
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
99 ! end GTK2 version
100 ! GTK3 version
585e643 @jtappin Update syntax for conditional lines in high-level templates.
jtappin authored
101 !!$GTK>=3.0! if (present(vertical)) then
102 !!$GTK>=3.0! if (vertical == TRUE) then
103 !!$GTK>=3.0! call gtk_orientable_set_orientation (bar, &
104 !!$GTK>=3.0! & GTK_ORIENTATION_VERTICAL)
105 !!$GTK>=3.0! else
106 !!$GTK>=3.0! call gtk_orientable_set_orientation (bar, &
107 !!$GTK>=3.0! & GTK_ORIENTATION_HORIZONTAL)
108 !!$GTK>=3.0! end if
109 !!$GTK>=3.0! end if
110 !!$GTK>=3.0!
111 !!$GTK>=3.0! if (present(reversed)) call gtk_progress_bar_set_inverted(bar, reversed)
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
112 ! end GTK3 version
113
114 if (present(step)) &
115 & call gtk_progress_bar_set_pulse_step(bar, step)
116
117 end function hl_gtk_progress_bar_new
118
119 !+
120 subroutine hl_gtk_progress_bar_set_f(bar, val, string, text)
121
122 type(c_ptr) :: bar
123 real(kind=c_double), optional :: val
124 integer(kind=c_int), optional :: string
125 character(len=*), intent(in), optional:: text
126
127 ! Set the value of a progress bar (fraction or pulse)
128 !
129 ! BAR: c_ptr: required: The bar to set
130 ! VAL: double: optional: The value to set. If absent, the bar is pulsed
131 ! STRING: boolean: optional: Whether to put a string on the bar.
132 ! TEXT: string: optional: Text to put in the bar, (overrides STRING)
133 !
134 ! This routine is normally accessed via the generic interface
6d8caf1 @jtappin * call gtk_disable_setlocale in gtk_init to prevent broken reads in d…
jtappin authored
135 ! hl_gtk_progress_bar_set
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
136 !-
137
138 character(len=50) :: sval
139
140 ! If no value given pulse the bar
141 if (.not. present(val)) then
142 call gtk_progress_bar_pulse(bar)
143 else
144 ! Determine the fraction to fill & fill it
145 call gtk_progress_bar_set_fraction(bar, val)
146 end if
147
148 ! If annotation is needed, add it.
149 if (present(text)) then
e6eb552 @jtappin * Add scrolled window to HL_CONTAINER, and a markup friendly set labe…
jtappin authored
150 call gtk_progress_bar_set_text (bar, text//c_null_char)
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
151 ! GTK3 Only
585e643 @jtappin Update syntax for conditional lines in high-level templates.
jtappin authored
152 !!$GTK>=3.0! call gtk_progress_bar_set_show_text(bar, TRUE)
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
153 ! End GTK3 only
154 else if (present(string)) then
155 if (string == FALSE .or. .not. present(val)) return
156 ! Otherwise we display a percentage
157 write(sval, "(F5.1,'%')") val*100.
158
e6eb552 @jtappin * Add scrolled window to HL_CONTAINER, and a markup friendly set labe…
jtappin authored
159 call gtk_progress_bar_set_text (bar, trim(sval)//c_null_char)
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
160 ! GTK3 Only
585e643 @jtappin Update syntax for conditional lines in high-level templates.
jtappin authored
161 !!$GTK>=3.0! call gtk_progress_bar_set_show_text(bar, TRUE)
162 !!$GTK>=3.0! else
163 !!$GTK>=3.0! call gtk_progress_bar_set_show_text(bar, FALSE)
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
164 ! End GTK3 only
165 end if
166 end subroutine hl_gtk_progress_bar_set_f
167
168 !+
169 subroutine hl_gtk_progress_bar_set_ii(bar, val, maxv, string, text)
170
171 type(c_ptr) :: bar
172 integer(kind=c_int) :: val, maxv
173 integer(kind=c_int), optional :: string
174 character(len=*), intent(in), optional:: text
175
176 ! Set the value of a progress bar (n of m)
177 !
178 ! BAR: c_ptr: required: The bar to set
179 ! VAL: int: required: The value to set.
180 ! MAXV: int: required: The maximum value for the bar
181 ! STRING: boolean: optional: Whether to put a string on the bar.
182 ! TEXT: string: optional: Text to put in the bar, (overrides STRING)
183 !
184 ! This routine is normally accessed via the generic interface
6d8caf1 @jtappin * call gtk_disable_setlocale in gtk_init to prevent broken reads in d…
jtappin authored
185 ! hl_gtk_progress_bar_set
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
186 !-
187
6d8caf1 @jtappin * call gtk_disable_setlocale in gtk_init to prevent broken reads in d…
jtappin authored
188 real(kind=c_double) :: frac
189 character(len=50) :: sval
190
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
191 frac = real(val,c_double)/real(maxv,c_double)
192 call gtk_progress_bar_set_fraction(bar, frac)
193
194 ! If annotation is needed, add it.
195 if (present(text)) then
e6eb552 @jtappin * Add scrolled window to HL_CONTAINER, and a markup friendly set labe…
jtappin authored
196 call gtk_progress_bar_set_text (bar, text//c_null_char)
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
197 ! GTK3 Only
585e643 @jtappin Update syntax for conditional lines in high-level templates.
jtappin authored
198 !!$GTK>=3.0! call gtk_progress_bar_set_show_text(bar, TRUE)
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
199 ! End GTK3 only
200 else if (present(string)) then
201 if (string == FALSE) return
202 ! Otherwise we display n or m
203 write(sval, "(I0,' of ',I0)") val, maxv
e6eb552 @jtappin * Add scrolled window to HL_CONTAINER, and a markup friendly set labe…
jtappin authored
204 call gtk_progress_bar_set_text (bar, trim(sval)//c_null_char)
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
205 ! GTK3 Only
585e643 @jtappin Update syntax for conditional lines in high-level templates.
jtappin authored
206 !!$GTK>=3.0! call gtk_progress_bar_set_show_text(bar, TRUE)
207 !!$GTK>=3.0! else
208 !!$GTK>=3.0! call gtk_progress_bar_set_show_text(bar, FALSE)
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
209 ! End GTK3 only
210 end if
211 end subroutine hl_gtk_progress_bar_set_ii
212 end module gtk_hl_progress
Something went wrong with that request. Please try again.