/src/wrappers/gtk/library/gtk_toggle_button.e

http://github.com/tybor/Liberty · Specman e · 247 lines · 114 code · 50 blank · 83 comment · 2 complexity · ff66b29e7dde4f769946677d8019ec3a MD5 · raw file

  1. indexing
  2. description: "."
  3. copyright: "[
  4. Copyright (C) 2006 eiffel-libraries team, GTK+ team
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public License
  7. as published by the Free Software Foundation; either version 2.1 of
  8. the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with this library; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. 02110-1301 USA
  17. ]"
  18. date: "$Date:$"
  19. revision: "$Revision:$"
  20. class GTK_TOGGLE_BUTTON
  21. -- A GtkToggleButton is a GtkButton which will remain 'pressed-in' when
  22. -- clicked. Clicking again will cause the toggle button to return to its
  23. -- normal state.
  24. -- A toggle button is created by calling either `make' or `with_label'. If
  25. -- using the former, it is advisable to pack a widget, (such as a GtkLabel
  26. -- and/or a GtkPixmap), into the toggle button's container. (See GtkButton
  27. -- for more information).
  28. -- The state of a GtkToggleButton can be set specifically using `set_active,'
  29. -- and retrieved using `is_active'.
  30. -- To simply switch the state of a toggle button, use `toggled'.
  31. -- Example 2. Creating two GtkToggleButton widgets.
  32. -- dialog: GTK_DIALOG
  33. -- toggle1,toggle2: GTK_TOGGLE_BUTTON
  34. -- make_toggles is
  35. -- do
  36. -- create dialog.make
  37. -- create toggle1.with_label ("Hi, i'm a toggle button.")
  38. -- -- Makes this toggle button invisible
  39. -- toggle1.draw_indicator
  40. -- -- toggle1.connect_to_toggled_signal (--TODO)
  41. -- dialog.action_area.pack_start (toggle1, False, False, 2)
  42. -- create toggle2.with_label ("Hi, i'm another toggle button.")
  43. -- toggle2.draw_as_button
  44. -- -- g_signal_connect (toggle2, "toggled", G_CALLBACK (output_state), NULL);
  45. -- dialog.action_area.pack_start (toggle2, False, False, 2)
  46. -- dialog.show_all
  47. -- end
  48. inherit
  49. GTK_BUTTON redefine make, with_label, with_mnemonic end
  50. insert
  51. GTK
  52. GTK_TOGGLE_BUTTON_EXTERNALS
  53. -- TODO: GtkToggleButton implements AtkImplementorIface.
  54. creation make, with_label, with_mnemonic, from_external_pointer
  55. feature {} -- Creation
  56. make is
  57. -- Creates a new toggle button. A widget should be packed
  58. -- into the button, as GTK_BUTTON.make.
  59. require gtk_initialized: gtk.is_initialized
  60. do
  61. from_external_pointer (gtk_toggle_button_new)
  62. end
  63. with_label (a_label: STRING) is
  64. -- Creates a new toggle button with a text `a_label'.
  65. require else
  66. gtk_initialized: gtk.is_initialized
  67. label_not_void: a_label /= Void
  68. do
  69. from_external_pointer (gtk_toggle_button_new_with_label (a_label.to_external))
  70. end
  71. with_mnemonic (a_label: STRING) is
  72. -- Creates a new GtkToggleButton containing `a_label'. The
  73. -- label will be created using GTK_LABEL.with_mnemonic, so
  74. -- underscores in label indicate the mnemonic for the button.
  75. require else
  76. gtk_initialized: gtk.is_initialized
  77. label_not_void: a_label /= Void
  78. do
  79. from_external_pointer (gtk_toggle_button_new_with_mnemonic (a_label.to_external))
  80. end
  81. feature
  82. draw_indicator is
  83. -- Makes the button displayed as a separate indicator and
  84. -- label. This feature only effects instances of classes like
  85. -- GtkCheckButton and GtkRadioButton that derive from
  86. -- GtkToggleButton, not instances of GtkToggleButton itself.
  87. do
  88. gtk_toggle_button_set_mode (handle, 1)
  89. ensure is_indicator_drawn
  90. end
  91. draw_as_button is
  92. -- Makes the button look like a normal button. This function
  93. -- only effects instances of classes like GtkCheckButton and
  94. -- GtkRadioButton that derive from GtkToggleButton, not
  95. -- instances of GtkToggleButton itself.
  96. do
  97. gtk_toggle_button_set_mode (handle, 0)
  98. ensure drawn_as_button
  99. end
  100. is_indicator_drawn: BOOLEAN is
  101. -- is the button displayed as a separate indicator and label?
  102. do
  103. Result := (gtk_toggle_button_get_mode(handle) = 1)
  104. end
  105. drawn_as_button: BOOLEAN is
  106. -- is the toggle button drawn as a normal button?
  107. do
  108. Result := (gtk_toggle_button_get_mode(handle) = 0)
  109. end
  110. toggled is
  111. -- Emits the toggled signal on the GtkToggleButton. There is
  112. -- no good reason for an application ever to call this
  113. -- function.
  114. do
  115. gtk_toggle_button_toggled (handle)
  116. end
  117. is_active: BOOLEAN is
  118. -- Is the toggle button pressed? (False means that it is
  119. -- raised).
  120. do
  121. Result:=(gtk_toggle_button_get_active(handle)).to_boolean
  122. end
  123. set_active is
  124. -- Sets the status of the toggle button to be 'pressed
  125. -- in'. This action causes the toggled signal to be emitted.
  126. do
  127. gtk_toggle_button_set_active (handle,1)
  128. end
  129. set_inactive is
  130. -- Sets the status of the toggle button to be 'pressed out',
  131. -- i.e. to raise it. This action causes the toggled signal
  132. -- to be emitted.
  133. do
  134. gtk_toggle_button_set_active (handle,0)
  135. end
  136. is_inconsistent: BOOLEAN is
  137. -- Is button inconsistent?
  138. do
  139. Result := (gtk_toggle_button_get_inconsistent (handle)).to_boolean
  140. end
  141. set_inconsistent is
  142. -- If the user has selected a range of elements (such as some
  143. -- text or spreadsheet cells) that are affected by a toggle
  144. -- button, and the current values in that range are
  145. -- inconsistent, you may want to display the toggle in an "in
  146. -- between" state. This function turns on "in between"
  147. -- display. Normally you would turn off the inconsistent
  148. -- state again if the user toggles the toggle button. This
  149. -- has to be done manually, `set_inconsistent' only affects
  150. -- visual appearance, it doesn't affect the semantics of the
  151. -- button.
  152. do
  153. gtk_toggle_button_set_inconsistent (handle,1)
  154. ensure is_inconsistent
  155. end
  156. set_consistent is
  157. do
  158. gtk_toggle_button_set_inconsistent (handle,0)
  159. ensure not is_inconsistent
  160. end
  161. feature -- "active" property
  162. -- "active" gboolean : Read / Write
  163. -- If the toggle button should be pressed in or not.
  164. -- Default value: FALSE
  165. feature -- The "draw-indicator" property
  166. -- "draw-indicator" gboolean : Read / Write
  167. -- If the toggle part of the button is displayed.
  168. -- Default value: FALSE
  169. -- The "inconsistent" property
  170. -- "inconsistent" gboolean : Read / Write
  171. -- If the toggle button is in an "in between" state.
  172. -- Default value: FALSE
  173. feature -- The "toggled" signal
  174. toggled_signal_name: STRING is "toggled"
  175. -- void user_function (GtkToggleButton *togglebutton,
  176. -- gpointer user_data);
  177. on_toggled is
  178. -- Built-in toggled signal handler; empty by design; redefine it.
  179. do
  180. -- local a_foo: INTEGER --a_foo := 12 -- Dummy instructions
  181. end
  182. enable_on_toggled is
  183. -- Connects "toggled" signal to `on_toggled' feature.
  184. -- Should be connected if you wish to perform an action
  185. -- whenever the GTK_TOGGLE_BUTTON's state is changed.
  186. do
  187. connect (Current, toggled_signal_name, $on_toggled)
  188. end
  189. connect_to_toggled_signal, connect_agent_to_toggled_signal (a_procedure: PROCEDURE [ANY, TUPLE[GTK_TOGGLE_BUTTON]]) is
  190. -- togglebutton : the object which received the signal.
  191. require valid_procedure: a_procedure /= Void
  192. local toggled_callback: TOGGLED_CALLBACK [like Current]
  193. do
  194. create toggled_callback.make
  195. toggled_callback.connect (Current, a_procedure)
  196. end
  197. end