/src/wrappers/gtk/library/gtk_button.e

http://github.com/tybor/Liberty · Specman e · 514 lines · 254 code · 98 blank · 162 comment · 3 complexity · 405513b360c40a3b1a00d87f8924ca23 MD5 · raw file

  1. indexing
  2. description: "GtkButton -- A widget that creates a signal when clicked on"
  3. copyright: "[
  4. Copyright (C) 2006 eiffel-libraries team, GTK+ team and others
  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_BUTTON
  21. -- The GtkButton widget is generally used to attach a function to
  22. -- that is called when the button is pressed. The various signals
  23. -- and how to use them are outlined below.
  24. -- The GtkButton widget can hold any valid child widget. That is it
  25. -- can hold most any other standard GtkWidget. The most commonly
  26. -- used child is the GtkLabel.
  27. inherit GTK_BIN
  28. insert
  29. GTK_BUTTON_EXTERNALS
  30. -- Implemented Interfaces GtkButton implements
  31. -- AtkImplementorIface.
  32. creation
  33. make,
  34. with_label,
  35. with_mnemonic,
  36. from_stock,
  37. from_external_pointer
  38. feature {} -- Creation
  39. make is
  40. -- Creates a new GtkButton widget. To add a child widget to
  41. -- the button, use `add' (of GTK_CONTAINER)
  42. do
  43. from_external_pointer (gtk_button_new)
  44. end
  45. with_label (a_label: STRING) is
  46. -- Creates a GtkButton widget with a GtkLabel child
  47. -- containing the given text (`a_label')
  48. require valid_label: a_label/=Void
  49. do
  50. from_external_pointer(gtk_button_new_with_label (a_label.to_external))
  51. end
  52. with_mnemonic (a_label: STRING) is
  53. -- Creates a new GtkButton containing a label. If characters
  54. -- in label are preceded by an underscore, they are
  55. -- underlined. If you need a literal underscore character in
  56. -- a label, use '__' (two underscores). The first underlined
  57. -- character represents a keyboard accelerator called a
  58. -- mnemonic. Pressing Alt and that key activates the button.
  59. require valid_label: a_label/=Void
  60. do
  61. from_external_pointer(gtk_button_new_with_mnemonic (a_label.to_external))
  62. end
  63. from_stock (a_stock: STRING) is
  64. -- Creates a new GtkButton containing the image and text from
  65. -- a stock item. TODO: implement GTK_STOCK_ITEMS wrapping
  66. -- preprocessor macros like GTK_STOCK_OK and GTK_STOCK_APPLY
  67. -- (stock ids).
  68. -- If stock_id is unknown, then it will be treated as a
  69. -- mnemonic label (as for make_with_mnemonic()).
  70. require stock_not_void: a_stock/=Void
  71. valid_stock: True -- TODO
  72. do
  73. from_external_pointer (gtk_button_new_from_stock (a_stock.to_external))
  74. end
  75. feature
  76. pressed is
  77. -- Emits a GtkButton::pressed signal to Current GtkButton.
  78. do
  79. gtk_button_pressed (handle)
  80. end
  81. released is
  82. -- Emits a GtkButton::released signal to the Current GtkButton.
  83. do
  84. gtk_button_released (handle)
  85. end
  86. clicked is
  87. -- Emits a GtkButton::clicked signal to the Current GtkButton.
  88. do
  89. gtk_button_clicked (handle)
  90. end
  91. enter is
  92. -- Emits a GtkButton::enter signal to the given GtkButton.
  93. do
  94. gtk_button_enter (handle)
  95. end
  96. leave is
  97. -- Emits a GtkButton::leave signal to the given GtkButton.
  98. do
  99. gtk_button_leave (handle)
  100. end
  101. feature -- Button's relief
  102. set_relief (a_relief: INTEGER) is
  103. -- Sets the relief style of the edges of the given GtkButton
  104. -- widget. Three styles exist, `gtk_relief_normal',
  105. -- `gtk_relief_half', `gtk_relief_none'. The default style is, as
  106. -- one can guess, `gtk_relief_normal'.
  107. require valid_relief_style: is_valid_gtk_relief_style (a_relief)
  108. do
  109. gtk_button_set_relief (handle, a_relief)
  110. end
  111. relief: INTEGER is
  112. -- the current relief style of the Current GtkButton.
  113. do
  114. Result := gtk_button_get_relief (handle)
  115. ensure valid_relief_style: is_valid_gtk_relief_style (Result)
  116. end
  117. is_relief_normal: BOOLEAN is
  118. -- Is the relief style normal?
  119. do
  120. Result := (relief = gtk_relief_normal)
  121. end
  122. set_relief_normal is
  123. -- Set relief style to normal
  124. do
  125. set_relief (gtk_relief_normal)
  126. ensure relief_set: is_relief_normal
  127. end
  128. is_relief_half: BOOLEAN is
  129. -- Is the relief style half?
  130. do
  131. Result := (relief = gtk_relief_half)
  132. end
  133. set_relief_half is
  134. -- Set relief style to half
  135. do
  136. set_relief (gtk_relief_half)
  137. ensure relief_set: is_relief_half
  138. end
  139. is_relief_none: BOOLEAN is
  140. -- Is the relief style none?
  141. do
  142. Result := (relief = gtk_relief_none)
  143. end
  144. set_relief_none is
  145. -- Set relief style to none
  146. do
  147. set_relief (gtk_relief_none)
  148. ensure relief_set: is_relief_none
  149. end
  150. feature -- Label
  151. label: STRING is
  152. -- the text from the label of the button, as set by
  153. -- `set_label'. If the label text has not been set the return
  154. -- value will be Void. This will be the case if you create an
  155. -- empty button with `make' to use as a container.
  156. local ptr: POINTER
  157. do
  158. check Result=Void end
  159. ptr:=gtk_button_get_label(handle)
  160. if ptr.is_not_null
  161. then create Result.from_external_copy (ptr)
  162. end
  163. end
  164. set_label (a_label: STRING) is
  165. -- Sets the text of the label of the button to
  166. -- `a_label'. This text is also used to select the stock item
  167. -- if `set_use_stock' is used. This will also clear any
  168. -- previously set labels.
  169. require valid_label: a_label/=Void
  170. do
  171. gtk_button_set_label (handle,a_label.to_external)
  172. end
  173. is_stock_item: BOOLEAN is
  174. -- Is the button label a stock item?
  175. do
  176. Result:=(gtk_button_get_use_stock(handle)).to_boolean
  177. end
  178. set_stock_item is
  179. -- Use the label as a stock id to select the stock item for
  180. -- the button.
  181. do
  182. gtk_button_set_use_stock (handle,1)
  183. end
  184. unset_stock_item is
  185. -- Use the label as a normal string. See `set_stock_item'
  186. do
  187. gtk_button_set_use_stock (handle,0)
  188. end
  189. is_using_underline: BOOLEAN is
  190. -- Is there an embedded underline in the button label
  191. -- indicating the mnemonic character? See
  192. -- `set_use_underline'.
  193. do
  194. Result:=(gtk_button_get_use_underline(handle)).to_boolean
  195. end
  196. set_use_underline is
  197. -- Put an underline in the text of the button label
  198. -- indicating the mnemonic accelerator key.
  199. do
  200. gtk_button_set_use_underline (handle,1)
  201. end
  202. unset_use_underline is
  203. -- Put an underline in the text of the button label
  204. -- indicating the mnemonic accelerator key.
  205. do
  206. gtk_button_set_use_underline (handle,1)
  207. end
  208. set_focus_on_click is
  209. -- the button grab focus when clicked with the mouse.
  210. obsolete "Use set_focus_on_click_bool, which will soon take place of current set_focus_on_click"
  211. do
  212. gtk_button_set_focus_on_click (handle,1)
  213. ensure is_focused_on_click
  214. end
  215. unset_focus_on_click is
  216. -- the button doesn't grab focus when clicked with the
  217. -- mouse. Making mouse clicks not grab focus is useful in
  218. -- places like toolbars where you don't want the keyboard
  219. -- focus removed from the main area of the application.
  220. obsolete "Use set_focus_on_click_bool, which will soon take place of current set_focus_on_click"
  221. do
  222. gtk_button_set_focus_on_click (handle,0)
  223. ensure not is_focused_on_click
  224. end
  225. is_focused_on_click: BOOLEAN is
  226. -- Does the button grabs focus when it is clicked with the mouse? See unset_focus_on_click.
  227. do
  228. Result:=(gtk_button_get_focus_on_click(handle)).to_boolean
  229. end
  230. set_alignment (an_x_alignment,an_y_alignment: REAL) is
  231. -- Sets the alignment of the child. This property has no
  232. -- effect unless the child is a GtkMisc or a GtkAligment.
  233. -- `an_x_alignment', `an_y_alignment' are the horizontal and
  234. -- vertical position of the child, 0.0 is left/top aligned,
  235. -- 1.0 is right/bottom aligned.
  236. require
  237. valid_x: an_x_alignment.in_range (0.0,1.0)
  238. valid_y: an_y_alignment.in_range (0.0,1.0)
  239. do
  240. gtk_button_set_alignment (handle, an_x_alignment,an_y_alignment)
  241. end
  242. alignments: TUPLE[REAL,REAL] is
  243. -- The x and y alignments.
  244. local x_al,y_al: REAL
  245. do
  246. gtk_button_get_alignment (handle, x_al.to_pointer, y_al.to_pointer)
  247. create Result.make_2 (x_al,y_al)
  248. ensure
  249. valid_x: Result.item_1.in_range (0.0,1.0)
  250. valid_y: Result.item_2.in_range (0.0,1.0)
  251. end
  252. set_image (a_widget: GTK_WIDGET) is
  253. -- Set the image of button to the given widget. Note that it
  254. -- depends on the gtk-button-images setting whether the image
  255. -- will be displayed or not, you don't have to call
  256. -- `show' on image yourself.
  257. require
  258. a_widget /= Void
  259. do
  260. gtk_button_set_image (handle, a_widget.handle)
  261. end
  262. image: GTK_WIDGET is
  263. -- The widget that is currently set as the image of
  264. -- button. This may have been explicitly set by `set_image'
  265. -- or constructed by `from_stock'.
  266. local factory: G_OBJECT_EXPANDED_FACTORY [GTK_WIDGET]
  267. do
  268. Result := factory.wrapper (gtk_button_get_image (handle))
  269. end
  270. -- Since 2.10
  271. -- set_image_position (a_position: INTEGER) is
  272. -- -- Sets the position of the image relative
  273. -- -- to the text inside the button.
  274. -- require
  275. -- is_valid_gtk_position_type (a_position)
  276. -- do
  277. -- gtk_button_set_image_position (handle, a_position)
  278. -- end
  279. --
  280. -- image_position: INTEGER is
  281. -- -- Gets the position of the image relative
  282. -- -- to the text inside the button.
  283. -- do
  284. -- Result := gtk_button_get_image_position (handle)
  285. -- ensure
  286. -- is_valid_gtk_position_type (Result)
  287. -- end
  288. feature -- Properties
  289. focus_on_click: BOOLEAN is
  290. -- Does the button grab focus when it is clicked with the
  291. -- mouse?
  292. -- Default value: TRUE
  293. do
  294. Result:=boolean_property(focus_on_click_property_name)
  295. end
  296. feature -- Properties setters
  297. set_focus_on_click_bool (a_setting: BOOLEAN) is
  298. do
  299. set_boolean_property(focus_on_click_property_name, a_setting)
  300. ensure set: focus_on_click = a_setting
  301. end
  302. -- The "relief" property
  303. -- "relief" GtkReliefStyle : Read / Write
  304. -- The border relief style.
  305. -- Default value: GTK_RELIEF_NORMAL
  306. -- The "use-stock" property
  307. -- "use-stock" gboolean : Read / Write / Construct
  308. -- If set, the label is used to pick a stock item instead of being displayed.
  309. -- Default value: FALSE
  310. -- The "use-underline" property
  311. -- "use-underline" gboolean : Read / Write / Construct
  312. -- If set, an underline in the text indicates the next character should be used for the mnemonic accelerator key.
  313. -- Default value: FALSE
  314. -- The "xalign" property
  315. -- "xalign" gfloat : Read / Write
  316. -- If the child of the button is a GtkMisc or GtkAlignment, this property can be used to control it's horizontal alignment. 0.0 is left aligned, 1.0 is right aligned.
  317. -- Allowed values: [0,1]
  318. -- Default value: 0.5
  319. -- Since 2.4
  320. -- The "yalign" property
  321. -- "yalign" gfloat : Read / Write
  322. -- If the child of the button is a GtkMisc or GtkAlignment, this property can be used to control it's vertical alignment. 0.0 is top aligned, 1.0 is bottom aligned.
  323. -- Allowed values: [0,1]
  324. -- Default value: 0.5
  325. -- Since 2.4
  326. feature -- Style Properties
  327. -- "child-displacement-x" gint : Read
  328. -- "child-displacement-y" gint : Read
  329. -- "default-border" GtkBorder : Read
  330. -- "default-outside-border" GtkBorder : Read
  331. -- "displace-focus" gboolean : Read
  332. -- Style Property Details
  333. -- The "child-displacement-x" style property
  334. -- "child-displacement-x" gint : Read
  335. -- How far in the x direction to move the child when the button is depressed.
  336. -- Default value: 0
  337. -- The "child-displacement-y" style property
  338. -- "child-displacement-y" gint : Read
  339. -- How far in the y direction to move the child when the button is depressed.
  340. -- Default value: 0
  341. -- The "default-border" style property
  342. -- "default-border" GtkBorder : Read
  343. -- Extra space to add for CAN_DEFAULT buttons.
  344. -- The "default-outside-border" style property
  345. -- "default-outside-border" GtkBorder : Read
  346. -- Extra space to add for CAN_DEFAULT buttons that is always drawn outside the border.
  347. -- The "displace-focus" style property
  348. -- "displace-focus" gboolean : Read
  349. -- Whether the child_displacement_x/child_displacement_y properties should also affect the focus rectangle.
  350. -- Default value: FALSE
  351. -- Since 2.6
  352. feature -- The "activate" signal
  353. activate_signal_name: STRING is "activate"
  354. enable_on_activate is
  355. -- Connects "activate" signal to `on_activate' feature.
  356. do
  357. connect (Current, activate_signal_name, $on_activate)
  358. end
  359. on_activate is
  360. -- Built-in activate signal handler; empty by design; redefine it.
  361. -- The "activate" signal on GtkButton is an action signal and
  362. -- emitting it causes the button to animate press then
  363. -- release. Applications should never connect to this signal,
  364. -- but use the "activate" signal.
  365. do
  366. end
  367. connect_agent_to_activate_signal (a_procedure: PROCEDURE [ANY, TUPLE[GTK_BUTTON]]) is
  368. require
  369. valid_procedure: a_procedure /= Void
  370. local
  371. activate_callback: ACTIVATE_CALLBACK[like Current]
  372. do
  373. create activate_callback.make
  374. activate_callback.connect (Current, a_procedure)
  375. end
  376. feature -- The "clicked" signal
  377. clicked_signal_name: STRING is "clicked"
  378. on_clicked is
  379. -- Built-in clicked signal handler; empty by design; redefine it.
  380. local a_foo: INTEGER
  381. do
  382. a_foo := 12 -- Dummy instructions
  383. end
  384. enable_on_clicked is
  385. -- Connects "clicked" signal to `on_clicked' feature.
  386. -- Emitted when the button has been activated (pressed and released).
  387. -- Emitted when a button clicked on by the mouse and the
  388. -- cursor stays on the button. If the cursor is not on the
  389. -- button when the mouse button is released, the signal is
  390. -- not emitted.
  391. do
  392. connect (Current, clicked_signal_name, $on_clicked)
  393. end
  394. connect_agent_to_clicked_signal (a_procedure: PROCEDURE [ANY, TUPLE[GTK_BUTTON]]) is
  395. -- button : the object that received the signal
  396. require valid_procedure: a_procedure /= Void
  397. local clicked_callback: CLICKED_CALLBACK [like Current]
  398. do
  399. create clicked_callback.make
  400. clicked_callback.connect (Current, a_procedure)
  401. end
  402. feature -- struct size
  403. struct_size: INTEGER is
  404. external "C inline use <gtk/gtk.h>"
  405. alias "sizeof(GtkButton)"
  406. end
  407. feature {} -- Property names
  408. focus_on_click_property_name: STRING is "focus-on-click"
  409. image_property_name: STRING is "image"
  410. label_property_name: STRING is "label"
  411. relief_property_name: STRING is "relief"
  412. use_stock_property_name: STRING is "use-stock"
  413. use_underline_property_name: STRING is "use-underline"
  414. xalign_property_name: STRING is "xalign"
  415. yalign_property_name: STRING is "yalign"
  416. end