/src/wrappers/gtk/library/gtk_editable.e

http://github.com/tybor/Liberty · Specman e · 303 lines · 125 code · 48 blank · 130 comment · 2 complexity · b3dd56276c080babffd755b17216931c MD5 · raw file

  1. indexing
  2. description: "GtkEditable -- Interface for text-editing widgets."
  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. -- The GtkEditable interface is an interface which should be
  21. -- implemented by text editing widgets, such as GtkEntry and
  22. -- GtkText. It contains functions for generically
  23. -- manipulating an editable widget, a large number of action
  24. -- signals used for key bindings, and several signals that an
  25. -- application can connect to to modify the behavior of a
  26. -- widget.
  27. -- As an example of the latter usage, by connecting the
  28. -- following handler to "insert_text", an application can
  29. -- convert all entry into a widget into uppercase.
  30. -- Example 3. Forcing entry to uppercase.
  31. -- include <ctype.h>
  32. -- void
  33. -- insert_text_handler (GtkEditable *editable,
  34. -- const gchar *text,
  35. -- gint length,
  36. -- gint *position,
  37. -- gpointer data)
  38. -- {
  39. -- int i;
  40. -- gchar *result = g_utf8_strup (text, length);
  41. -- g_signal_handlers_block_by_func (editable,
  42. -- (gpointer) insert_text_handler, data);
  43. -- gtk_editable_insert_text (editable, result, length, position);
  44. -- g_signal_handlers_unblock_by_func (editable,
  45. -- (gpointer) insert_text_handler, data);
  46. -- g_signal_stop_emission_by_name (editable, "insert_text");
  47. -- g_free (result);
  48. -- }
  49. deferred class GTK_EDITABLE
  50. inherit
  51. GTK_WIDGET
  52. -- DELETE: undefine make end
  53. -- TODO check this, since I'm not sure. Indeed any known
  54. -- implementation is a GTK_WIDGET, therefore it shouldn't bring
  55. -- any harm.
  56. insert
  57. GTK_EDITABLE_EXTERNALS
  58. GTK_EDITABLE_STRUCT
  59. -- Known Implementations: GtkEditable is implemented by
  60. -- GtkEntry, GtkOldEditable, GtkSpinButton and GtkText.
  61. feature
  62. select_region (a_start, an_end: INTEGER) is
  63. -- Selects a region of text. The characters that are selected
  64. -- are those characters at positions from `a_start' up to,
  65. -- but not including `an_end'. If `an_end' is negative, then
  66. -- the the characters selected will be those characters from
  67. -- `a_start' to the end of the text.
  68. do
  69. gtk_editable_select_region (handle, a_start, an_end)
  70. end
  71. selection_bounds: TUPLE[BOOLEAN,INTEGER,INTEGER] is
  72. -- current selection bounds, and if there is a selection. The
  73. -- format of the tuple is [`is_there_a_selection',
  74. -- `start',`end'].
  75. local is_there,a_start,an_end: INTEGER
  76. do
  77. is_there := gtk_editable_get_selection_bounds(handle,$a_start,$an_end)
  78. create Result.make_3 (is_there.to_boolean,a_start,an_end)
  79. end
  80. insert_text (a_text: STRING; a_position: REFERENCE [INTEGER]) is
  81. -- Inserts `a_text' at `a_position'.
  82. local io_position: INTEGER
  83. do
  84. -- editable : a GtkEditable widget.
  85. -- new_text : the text to insert.
  86. -- new_text_length : the length of the text to insert, in bytes
  87. -- position : an inout parameter. The caller initializes it
  88. -- to the position at which to insert the text. After the
  89. -- call it points at the position after the newly inserted
  90. -- text.
  91. -- not_yet_implemented -- TODO missing position_ptr := WHAT? + a_position
  92. io_position := a_position.item
  93. gtk_editable_insert_text (handle, a_text.to_external, a_text.count, $io_position)
  94. a_position.set_item (io_position)
  95. end
  96. delete_text (a_start, an_end: INTEGER) is
  97. -- Deletes a sequence of characters. The characters that are
  98. -- deleted are those characters at positions from `a_start'
  99. -- up to, but not including `an_end'. If `an_end' is
  100. -- negative, then the the characters deleted will be those
  101. -- characters from 'a_start' to the end of the text.
  102. do
  103. gtk_editable_delete_text (handle,a_start, an_end)
  104. end
  105. substring (a_start, an_end: INTEGER): STRING is
  106. -- Retrieves a sequence of characters. The characters that
  107. -- are retrieved are those characters at positions from
  108. -- `a_start' up to, but not including `an_end'. If `an_end'
  109. -- is negative, then the the characters retrieved will be
  110. -- those characters from `a_start' to the end of the text.
  111. do
  112. create Result.from_external(gtk_editable_get_chars (handle,a_start,an_end))
  113. -- Using from_external, since the return value of
  114. -- gtk_editable_get_chars are the characters in the indicated
  115. -- region. The result must be freed with g_free() when the
  116. -- application is finished with it.
  117. end
  118. cut_clipboard is
  119. -- Causes the characters in the current selection to be
  120. -- copied to the clipboard and then deleted from the widget.
  121. do
  122. gtk_editable_cut_clipboard (handle)
  123. end
  124. copy_clipboard is
  125. -- Causes the characters in the current selection to be
  126. -- copied to the clipboard.
  127. do
  128. gtk_editable_copy_clipboard (handle)
  129. end
  130. paste_clipboard is
  131. -- Causes the contents of the clipboard to be pasted into the
  132. -- given widget at the current cursor position.
  133. do
  134. gtk_editable_paste_clipboard (handle)
  135. end
  136. delete_selection is
  137. -- Deletes the current contents of the widgets selection and disclaims the selection.
  138. do
  139. gtk_editable_delete_selection (handle)
  140. end
  141. set_position (a_position: INTEGER) is
  142. -- Sets the cursor position. The cursor is displayed before
  143. -- the character with the given (base 0) index in the
  144. -- widget. The value must be less than or equal to the number
  145. -- of characters in the widget. A value of -1 indicates that
  146. -- the position should be set after the last character in the
  147. -- entry. Note that this position is in characters, not in
  148. -- bytes.
  149. do
  150. gtk_editable_set_position (handle,a_position)
  151. end
  152. position: INTEGER is
  153. -- current cursor position. The cursor is displayed before
  154. -- the character with the given (base 0) index in the
  155. -- widget. The value will be less than or equal to the number
  156. -- of characters in the widget. Note that this position is in
  157. -- characters, not in bytes.
  158. do
  159. Result:=gtk_editable_get_position (handle)
  160. end
  161. set_editable is
  162. -- Allow the user to edit the text
  163. do
  164. gtk_editable_set_editable (handle,1)
  165. ensure is_editable
  166. end
  167. unset_editable is
  168. -- Forbid the user to edit the text
  169. do
  170. gtk_editable_set_editable (handle,0)
  171. ensure not is_editable
  172. end
  173. is_editable: BOOLEAN is
  174. -- is the text editable by the user?
  175. do
  176. Result := (gtk_editable_get_editable(handle)).to_boolean
  177. end
  178. feature -- The "changed" signal
  179. changed_signal_name: STRING is "changed"
  180. enable_on_changed is
  181. -- Connects "changed" signal to `on_changed' feature.
  182. do
  183. connect (Current, changed_signal_name, $on_changed)
  184. end
  185. on_changed is
  186. -- Built-in changed signal handler; empty by design; redefine it.
  187. -- Indicates that the user has changed the contents of the widget.
  188. do
  189. end
  190. connect_agent_to_changed_signal (a_procedure: PROCEDURE [ANY, TUPLE[GTK_EDITABLE]]) is
  191. require valid_procedure: a_procedure /= Void
  192. local changed_callback: CHANGED_CALLBACK [like Current]
  193. do
  194. create changed_callback.make
  195. changed_callback.connect (Current, a_procedure)
  196. end
  197. -- Signal Details
  198. -- The "changed" signal
  199. -- void user_function (GtkEditable *editable, gpointer user_data);
  200. -- editable : the object which received the signal.
  201. -- user_data : user data set when the signal handler was connected.
  202. feature -- The "delete-text" signal
  203. -- void user_function (GtkEditable *editable, gint `a_start', gint
  204. -- `an_end', gpointer user_data);
  205. -- This signal is emitted when text is deleted from the widget by
  206. -- the user. The default handler for this signal will normally be
  207. -- responsible for inserting the text, so by connecting to this
  208. -- signal and then stopping the signal with gtk_signal_emit_stop(),
  209. -- it is possible to modify the inserted text, or prevent it from
  210. -- being inserted entirely. The `a_start' and `an_end' parameters
  211. -- are interpreted as for gtk_editable_delete_text()
  212. -- editable : the object which received the signal.
  213. -- `a_start' : the starting position.
  214. -- `an_end' : the end position.
  215. -- user_data : user data set when the signal handler was connected.
  216. feature -- The "insert-text" signal
  217. insert_text_signal_name: STRING is "insert-text"
  218. -- "insert-text"
  219. -- void user_function (GtkEditable *editable,
  220. -- gchar *new_text,
  221. -- gint new_text_length,
  222. -- gint *position,
  223. -- gpointer user_data) : Run last
  224. on_insert_text is
  225. -- Built-in insert-text signal handler; empty by design; redefine it.
  226. do
  227. end
  228. enable_on_insert_text is
  229. -- Connects "insert-text" signal to `on_insert_text' feature.
  230. -- This signal is emitted when text is inserted into the widget by
  231. -- the user. The default handler for this signal will normally be
  232. -- responsible for inserting the text, so by connecting to this
  233. -- signal and then stopping the signal with gtk_signal_emit_stop(),
  234. -- it is possible to modify the inserted text, or prevent it from
  235. -- being inserted entirely.
  236. do
  237. connect (Current, insert_text_signal_name, $on_insert_text)
  238. end
  239. connect_agent_to_insert_text_signal (a_procedure: PROCEDURE [ANY, TUPLE [STRING, INTEGER, REFERENCE [INTEGER], GTK_EDITABLE]]) is
  240. -- editable : the object which received the signal.
  241. -- new_text : the new text to insert.
  242. -- new_text_length : the length of the new text, in bytes,
  243. -- or -1 if new_text is nul-terminated
  244. -- position : the position, in characters, at which to insert the new text.
  245. -- this is an in-out parameter. After the signal emission is finished,
  246. -- it should point after the newly inserted text.
  247. require
  248. valid_procedure: a_procedure /= Void
  249. local
  250. insert_text_callback: INSERT_TEXT_CALLBACK
  251. do
  252. create insert_text_callback.make
  253. insert_text_callback.connect (Current, a_procedure)
  254. end
  255. end -- class GTK_EDITABLE