/src/wrappers/gtk/library/gtk_tool_button.e

http://github.com/tybor/Liberty · Specman e · 323 lines · 181 code · 48 blank · 94 comment · 7 complexity · 98f040359034937097a3edf439183f41 MD5 · raw file

  1. indexing
  2. description: "A GtkToolItem subclass that displays buttons."
  3. copyright: "[
  4. Copyright (C) 2006 Daniel F Moisset, 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. class GTK_TOOL_BUTTON
  19. -- GtkToolButtons are GtkToolItems containing buttons. Use `with_label'
  20. -- to create a new GtkToolButton. Use `with_stock' to create a
  21. -- GtkToolButton containing a stock item.
  22. -- The label of a GtkToolButton is determined by the
  23. -- properties/feature "label_widget", "label", and "stock_id". If
  24. -- "label_widget" is non-Void, then that widget is used as the
  25. -- label. Otherwise, if "label" is non-Void, that string is used as
  26. -- the label. Otherwise, if "stock_id" is non-Void, the label is
  27. -- determined by the stock item. Otherwise, the button does not
  28. -- have a label.
  29. -- The icon of a GtkToolButton is determined by the properties
  30. -- "icon_widget" and "stock_id". If "icon_widget" is non-Void, then
  31. -- that widget is used as the icon. Otherwise, if "stock_id" is
  32. -- non-Void, the icon is determined by the stock item. Otherwise,
  33. -- the button does not have a label.
  34. inherit
  35. GTK_TOOL_ITEM redefine struct_size end
  36. create
  37. from_external_pointer, from_stock, from_label
  38. feature {} -- Creation
  39. from_label (an_icon_widget: GTK_WIDGET; a_label: STRING) is
  40. --Creates a new GtkToolButton using `an_icon_widget' as icon
  41. --and `a_label' as label. Both can be Void.
  42. do
  43. from_external_pointer(gtk_tool_button_new(null_or(an_icon_widget),
  44. null_or_string(a_label)))
  45. end
  46. from_stock (a_stock_id: STRING) is
  47. -- Creates a new GtkToolButton containing the image and text
  48. -- from a stock item. Some stock ids have preprocessor macros
  49. -- like GTK_STOCK_OK and GTK_STOCK_APPLY.
  50. require
  51. id_not_void: a_stock_id /= Void
  52. valid_stock_id: -- TODO It is an error if stock_id is not a name of a stock
  53. -- item.
  54. do
  55. from_external_pointer(gtk_tool_button_new_from_stock (a_stock_id.to_external))
  56. end
  57. feature
  58. set_label (a_label: STRING) is
  59. -- Sets label as the label used for the tool button. The
  60. -- "label" property only has an effect if not overridden by a
  61. -- non-Void "label_widget" property. If both the
  62. -- "label_widget" and "label" properties are Void, the label
  63. -- is determined by the "stock_id" property. If the
  64. -- "stock_id" property is also Void, button will not have a
  65. -- label.
  66. do
  67. gtk_tool_button_set_label (handle,null_or_string(a_label))
  68. ensure set: a_label/=Void implies a_label.is_equal(label)
  69. end
  70. label: CONST_STRING is
  71. -- the label used by the tool button; Void if the tool button
  72. -- doesn't have a label or uses a the label from a stock
  73. -- item.
  74. local ptr: POINTER
  75. do
  76. ptr := gtk_tool_button_get_label(handle)
  77. -- The returned string is owned by GTK+, and must not be
  78. -- modified or freed. So we create a CONST_STRING
  79. if ptr.is_not_null then
  80. create {CONST_STRING} Result.from_external(ptr)
  81. end
  82. end
  83. set_use_underline (a_setting: BOOLEAN) is
  84. -- If set, an underline in the label property indicates that
  85. -- the next character should be used for the mnemonic
  86. -- accelerator key in the overflow menu. For example, if the
  87. -- label property is "_Open" and use_underline is True, the
  88. -- label on the tool button will be "Open" and the item on
  89. -- the overflow menu will have an underlined 'O'.
  90. -- Labels shown on tool buttons never have mnemonics on them;
  91. -- this property only affects the menu item on the overflow
  92. -- menu.
  93. do
  94. gtk_tool_button_set_use_underline(handle,
  95. a_setting.to_integer)
  96. ensure set: a_setting = is_underline_used
  97. end
  98. is_underline_used: BOOLEAN is
  99. -- Are underscores used in the label property as mnemonics?
  100. -- See `set_use_underline'.
  101. do
  102. Result:=(gtk_tool_button_get_use_underline(handle).to_boolean)
  103. end
  104. set_stock_id (a_stock_id: STRING) is
  105. -- Sets the name of the stock item. See `from_stock'. The
  106. -- stock_id property only has an effect if not overridden by
  107. -- non-Void "label" and "icon_widget" properties.
  108. do
  109. gtk_tool_button_set_stock_id(handle,
  110. null_or_string(a_stock_id))
  111. end
  112. stock_id: CONST_STRING is
  113. -- The name of the stock item. See `set_stock_id'.
  114. local ptr: POINTER
  115. do
  116. ptr := gtk_tool_button_get_stock_id (handle)
  117. if ptr.is_not_null then
  118. create Result.from_external(ptr)
  119. end
  120. end
  121. set_icon_name (an_icon_name: STRING) is
  122. -- Sets the icon for the tool button from a named themed
  123. -- icon. See the docs for GtkIconTheme for more details. The
  124. -- "icon_name" property only has an effect if not overridden
  125. -- by non-Void "label", "icon_widget" and "stock_id"
  126. -- properties.
  127. require name_not_void: an_icon_name/=Void
  128. do
  129. gtk_tool_button_set_icon_name(handle, an_icon_name.to_external)
  130. end
  131. icon_name: CONST_STRING is
  132. -- name of the themed icon for the tool button, see
  133. -- `set_icon_name'.
  134. local ptr: POINTER
  135. do
  136. ptr:=gtk_tool_button_get_icon_name(handle)
  137. if ptr.is_not_null then
  138. create Result.from_external(ptr)
  139. end
  140. end
  141. set_icon_widget (an_icon_widget: GTK_WIDGET) is
  142. -- Sets `an_icon_widget' as the widget used as icon on
  143. -- button. If Voidthe icon is determined by the "stock_id"
  144. -- property. If the "stock_id" property is also Void, button
  145. -- will not have an icon.
  146. do
  147. gtk_tool_button_set_icon_widget (handle,null_or(an_icon_widget))
  148. ensure set: an_icon_widget = icon_widget
  149. end
  150. icon_widget: GTK_WIDGET is
  151. -- the widget used as icon widget on button. See
  152. -- `set_icon_widget'.
  153. -- Note: In debug mode an unwrapped object obtained from the
  154. -- GTK library will produce an exception; otherwise Result
  155. -- will be Void
  156. local ptr: POINTER; r: G_OBJECT_EXPANDED_FACTORY[GTK_WIDGET]
  157. do
  158. ptr:=gtk_tool_button_get_icon_widget(handle)
  159. if ptr.is_not_null then
  160. Result:=r.wrapper(ptr)
  161. debug
  162. if Result=Void then
  163. raise(pointer_to_unwrapped_deferred_object)
  164. end
  165. end
  166. end
  167. end
  168. set_label_widget (a_label_widget: GTK_WIDGET) is
  169. -- Sets `a_label_widget' as the widget that will be used as
  170. -- the label for button. If label_widget is Void the "label"
  171. -- property is used as label. If "label" is also Void, the
  172. -- label in the stock item determined by the "stock_id"
  173. -- property is used as label. If "stock_id" is also Void,
  174. -- button does not have a label.
  175. do
  176. gtk_tool_button_set_label_widget(handle,null_or(a_label_widget))
  177. ensure set: a_label_widget = label_widget
  178. end
  179. label_widget: GTK_WIDGET is
  180. -- The widget used as label on button. Can be Void. See
  181. -- `set_label_widget'.
  182. local factory: G_OBJECT_EXPANDED_FACTORY[GTK_WIDGET]
  183. do
  184. Result := factory.wrapper_or_void (gtk_tool_button_get_label_widget(handle))
  185. end
  186. feature --Properties
  187. -- Note: "icon-name", "icon-widget", "label", "label-widget", "stock-id"
  188. -- and "use-underline" properties have proper, strongly-typed
  189. -- getter/setters features so they're not wrapped as properties
  190. feature -- The "clicked" signal
  191. clicked_signal_name: STRING is "clicked"
  192. on_clicked is
  193. -- Built-in clicked signal handler; empty by design; redefine it.
  194. local a_foo: INTEGER
  195. do
  196. a_foo := 12 -- Dummy instructions
  197. end
  198. enable_on_clicked is
  199. -- Connects "clicked" signal to `on_clicked' feature.
  200. -- This signal is emitted when the tool button is clicked with the
  201. -- mouse or activated with the keyboard.
  202. do
  203. connect (Current, clicked_signal_name, $on_clicked)
  204. end
  205. connect_agent_to_clicked_signal (a_procedure: PROCEDURE [ANY, TUPLE[GTK_TOOL_BUTTON]]) is
  206. -- button : the object that received the signal
  207. require valid_procedure: a_procedure /= Void
  208. local clicked_callback: CLICKED_CALLBACK [like Current]
  209. do
  210. create clicked_callback.make
  211. clicked_callback.connect (Current, a_procedure)
  212. end
  213. feature -- size
  214. struct_size: INTEGER is
  215. external "C inline use <gtk/gtk.h>"
  216. alias "sizeof(GtkToolButton)"
  217. end
  218. feature {} -- External calls
  219. gtk_tool_button_new (a_icon_widget, a_label: POINTER): POINTER is
  220. -- GtkToolItem* gtk_tool_button_new (GtkWidget *icon_widget, const gchar *label);
  221. external "C use <gtk/gtk.h>"
  222. end
  223. gtk_tool_button_new_from_stock (a_stock_id: POINTER): POINTER is
  224. -- GtkToolItem* gtk_tool_button_new_from_stock (const gchar *stock_id);
  225. external "C use <gtk/gtk.h>"
  226. end
  227. gtk_tool_button_set_label (a_button, a_label: POINTER) is
  228. -- void gtk_tool_button_set_label (GtkToolButton *button, const gchar *label);
  229. external "C use <gtk/gtk.h>"
  230. end
  231. gtk_tool_button_get_label (a_button: POINTER): POINTER is
  232. -- const gchar* gtk_tool_button_get_label (GtkToolButton *button);
  233. external "C use <gtk/gtk.h>"
  234. end
  235. gtk_tool_button_set_use_underline (a_button: POINTER; a_use_underline: INTEGER) is
  236. -- void gtk_tool_button_set_use_underline (GtkToolButton *button, gboolean use_underline);
  237. external "C use <gtk/gtk.h>"
  238. end
  239. gtk_tool_button_get_use_underline (a_button: POINTER): INTEGER is
  240. -- gboolean gtk_tool_button_get_use_underline (GtkToolButton *button);
  241. external "C use <gtk/gtk.h>"
  242. end
  243. gtk_tool_button_set_stock_id (a_button, a_stock_id: POINTER) is
  244. -- void gtk_tool_button_set_stock_id (GtkToolButton *button, const gchar *stock_id);
  245. external "C use <gtk/gtk.h>"
  246. end
  247. gtk_tool_button_get_stock_id (a_button: POINTER): POINTER is
  248. -- const gchar* gtk_tool_button_get_stock_id (GtkToolButton *button);
  249. external "C use <gtk/gtk.h>"
  250. end
  251. gtk_tool_button_set_icon_name (a_button, an_icon_name: POINTER) is
  252. -- void gtk_tool_button_set_icon_name (GtkToolButton *button, const gchar *icon_name);
  253. external "C use <gtk/gtk.h>"
  254. end
  255. gtk_tool_button_get_icon_name (a_button: POINTER): POINTER is
  256. -- const gchar* gtk_tool_button_get_icon_name (GtkToolButton *button);
  257. external "C use <gtk/gtk.h>"
  258. end
  259. gtk_tool_button_set_icon_widget (a_button, an_icon_widget: POINTER) is
  260. -- void gtk_tool_button_set_icon_widget (GtkToolButton *button, GtkWidget *icon_widget);
  261. external "C use <gtk/gtk.h>"
  262. end
  263. gtk_tool_button_get_icon_widget (a_button: POINTER): POINTER is
  264. -- GtkWidget* gtk_tool_button_get_icon_widget (GtkToolButton *button);
  265. external "C use <gtk/gtk.h>"
  266. end
  267. gtk_tool_button_set_label_widget (a_button, a_label_widget: POINTER) is
  268. -- void gtk_tool_button_set_label_widget (GtkToolButton *button, GtkWidget *label_widget);
  269. external "C use <gtk/gtk.h>"
  270. end
  271. gtk_tool_button_get_label_widget (a_button: POINTER): POINTER is
  272. -- GtkWidget* gtk_tool_button_get_label_widget (GtkToolButton *button);
  273. external "C use <gtk/gtk.h>"
  274. end
  275. end