/src/wrappers/gtk/library/gtk_progress_bar.e

http://github.com/tybor/Liberty · Specman e · 188 lines · 121 code · 28 blank · 39 comment · 3 complexity · 8b844909fbb14130e96ba8047cd1232a MD5 · raw file

  1. indexing
  2. description: "GtkProgressBar: A widget which indicates progress visually"
  3. copyright: "[
  4. Copyright (C) 2006 Nicolas Fafchamps <nicolas.fafchamps@gmail-com
  5. Copyright (C) 2006 eiffel-libraries team, GTK+ team
  6. This library is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Lesser General Public License
  8. as published by the Free Software Foundation; either version 2.1 of
  9. the License, or (at your option) any later version.
  10. This library is distributed in the hope that it will be useful, but
  11. WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with this library; if not, write to the Free Software
  16. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. 02110-1301 USA
  18. ]"
  19. copyright: "(C) 2006 Nicolas Fafchamps <nicolas.fafchamps@gmail.com> and Others"
  20. license: "LGPL v2 or later"
  21. date: "$Date:$"
  22. revision "$REvision:$"
  23. class GTK_PROGRESS_BAR
  24. -- the GtkProgressBar is typically used to display the progress of
  25. -- a long running operation. It provides a visual clue that
  26. -- processing is underway. The GtkProgressBar can be used in two
  27. -- different modes: percentage mode and activity mode.
  28. -- When an application can determine how much work needs to take
  29. -- place (e.g. read a fixed number of bytes from a file) and can
  30. -- monitor its progress, it can use the GtkProgressBar in
  31. -- percentage mode and the user sees a growing bar indicating the
  32. -- percentage of the work that has been completed. In this mode,
  33. -- the application is required to call `set_fraction' periodically
  34. -- to update the progress bar.
  35. -- When an application has no accurate way of knowing the amount of
  36. -- work to do, it can use the GtkProgressBar in activity mode,
  37. -- which shows activity by a block moving back and forth within the
  38. -- progress area. In this mode, the application is required to call
  39. -- `pulse' perodically to update the progress bar.
  40. -- There is quite a bit of flexibility provided to control the
  41. -- appearance of the GtkProgressBar. Functions are provided to
  42. -- control the orientation of the bar, optional text can be
  43. -- displayed along with the bar, and the step size used in activity
  44. -- mode can be set.
  45. inherit GTK_BIN
  46. insert
  47. GTK_PROGRESS_BAR_EXTERNALS
  48. GTK_PROGRESS_BAR_ORIENTATION
  49. PANGO_ELLIPSIZE_MODE
  50. creation
  51. make, from_external_pointer
  52. feature {} -- Initialization
  53. make is
  54. -- Create a new GtkProgressBar.
  55. require gtk_initialized: gtk.is_initialized
  56. do
  57. from_external_pointer (gtk_progress_bar_new)
  58. end
  59. feature -- Element change
  60. pulse is
  61. -- Move the bar with `pulse_step'.
  62. do
  63. gtk_progress_bar_pulse(handle)
  64. end
  65. feature -- Status setting
  66. set_text (a_text : STRING) is
  67. -- Set the text to appear superimposed on the progress bar.
  68. require
  69. valid_text: a_text/=Void
  70. do
  71. gtk_progress_bar_set_text(handle,a_text.to_external)
  72. end
  73. set_fraction (a_fraction : REAL) is
  74. -- Cause the progress bar to "fill in" the given fraction of the bar.
  75. require
  76. valid_fraction: a_fraction >= 0 and a_fraction <= 1
  77. do
  78. gtk_progress_bar_set_fraction(handle,a_fraction)
  79. end
  80. set_pulse_step (a_fraction : REAL) is
  81. -- Sets the fraction of total progress bar length to move the bouncing block for each call to `pulse'.
  82. require
  83. valid_fraction: a_fraction >= 0 and a_fraction <= 1
  84. do
  85. gtk_progress_bar_set_pulse_step(handle,a_fraction)
  86. end
  87. set_orientation (an_orientation: INTEGER) is
  88. -- Causes the progress bar to switch to a different
  89. -- orientation (left-to-right, right-to-left, top-to-bottom,
  90. -- or bottom-to-top).
  91. require valid_orientation: is_valid_gtk_progress_bar_orientation (an_orientation)
  92. do
  93. gtk_progress_bar_set_orientation (handle, an_orientation)
  94. end
  95. set_ellipsize (a_mode: INTEGER) is
  96. -- Sets the mode used to ellipsize (add an ellipsis: "...")
  97. -- the text if there is not enough space to render the entire
  98. -- string.
  99. require is_valid_ellipsize_mode: is_valid_pango_ellipsize_mode(a_mode)
  100. do
  101. gtk_progress_bar_set_ellipsize (handle, a_mode)
  102. end
  103. feature -- Status report
  104. text : STRING is
  105. -- Text displayed superimposed on the progress bar.
  106. local ptr: POINTER
  107. do
  108. ptr:=gtk_progress_bar_get_text(handle)
  109. if ptr.is_not_null then
  110. create Result.from_external_copy (ptr)
  111. else
  112. Result := Void
  113. end
  114. end
  115. fraction: REAL is
  116. -- Current fraction of the task that's been completed
  117. do
  118. Result := gtk_progress_bar_get_fraction (handle)
  119. end
  120. orientation: INTEGER is
  121. -- the current progress bar orientation
  122. do
  123. Result:=gtk_progress_bar_get_orientation(handle)
  124. ensure valid_progress_bar_orientation:
  125. is_valid_gtk_progress_bar_orientation (Result)
  126. end
  127. ellipsize_mode: INTEGER is
  128. -- the ellipsizing position of the progressbar. See `set_ellipsize'
  129. do
  130. Result := gtk_progress_bar_get_ellipsize (handle)
  131. ensure valid_ellipsize_mode: is_valid_pango_ellipsize_mode(Result)
  132. end
  133. pulse_step: REAL is
  134. -- The fraction of total progress to move the bouncing block
  135. -- when pulsed.
  136. do
  137. invoke_get_property (pulse_step_property.owner_class, handle,
  138. pulse_step_property.param_id, pulse_step_gvalue.handle,
  139. pulse_step_property.handle)
  140. Result := pulse_step_gvalue.real
  141. ensure valid: Result.in_range(0.0, 1.0)
  142. end
  143. -- Note : Other functions are deprecated
  144. feature {} -- Properties implementation
  145. pulse_step_label: STRING is "pulse-step"
  146. pulse_step_property: G_PARAM_SPEC is
  147. once
  148. Result := find_property(pulse_step_label)
  149. end
  150. pulse_step_gvalue: G_VALUE is
  151. once
  152. create Result.with_gtype (pulse_step_property.value_gtype)
  153. ensure not_void: Result /= Void
  154. end
  155. feature -- size
  156. struct_size: INTEGER is
  157. external "C inline use <gtk/gtk.h>"
  158. alias "sizeof(GtkProgressBar)"
  159. end
  160. end