/src/wrappers/gtk/library/gtk_entry.e

http://github.com/tybor/Liberty · Specman e · 591 lines · 235 code · 134 blank · 222 comment · 2 complexity · 816497dadacf35150450a62636379fd0 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. class GTK_ENTRY
  19. -- The GtkEntry widget is a single line text entry widget. A fairly large set
  20. -- of key bindings are supported by default. If the entered text is longer
  21. -- than the allocation of the widget, the widget will scroll so that the
  22. -- cursor position is visible.
  23. inherit
  24. GTK_WIDGET
  25. GTK_EDITABLE
  26. GTK_CELL_EDITABLE
  27. -- GtkEntry implements AtkImplementorIface, GtkCellEditable and GtkEditable.
  28. insert
  29. G_OBJECT_FACTORY [GTK_MENU]
  30. GTK_ENTRY_EXTERNALS
  31. creation make, from_external_pointer
  32. feature {} -- Creation
  33. make is
  34. -- Creates a new GtkEntry widget.
  35. do
  36. from_external_pointer (gtk_entry_new)
  37. end
  38. feature
  39. set_text (a_text: STRING) is
  40. -- Sets the text in the widget to the given value, replacing
  41. -- the current contents.
  42. require valid_text: a_text/=Void
  43. do
  44. gtk_entry_set_text (handle, a_text.to_external)
  45. end
  46. text: STRING is
  47. -- the contents of the entry widget.
  48. do
  49. -- TODO: implement something that doesn't involve copying
  50. create Result.from_external_copy(gtk_entry_get_text(handle))
  51. -- The result of gtk_entry_get_text is a pointer to the
  52. -- contents of the widget as a string. This string points to
  53. -- internally allocated storage in the widget and must not be
  54. -- freed, modified or stored.
  55. end
  56. feature -- visibility
  57. set_contents_visible is
  58. -- Makes the contents of the entry visible.
  59. do
  60. gtk_entry_set_visibility (handle, 1)
  61. ensure
  62. contents_visible
  63. end
  64. set_contents_invisible is
  65. -- Makes the contents of the entry invisible. Characters are
  66. -- displayed as the invisible char, and will also appear that
  67. -- way when the text in the entry widget is copied
  68. -- elsewhere. The default invisible char is the asterisk `*',
  69. -- but it can be changed with `set_invisible_char'.
  70. do
  71. gtk_entry_set_visibility (handle, 0)
  72. ensure
  73. not contents_visible
  74. end
  75. contents_visible: BOOLEAN is
  76. -- is the text currently visible?
  77. do
  78. Result := gtk_entry_get_visibility (handle).to_boolean
  79. end
  80. set_invisible_char (a_unicode: INTEGER) is
  81. -- Sets the character to use in place of the actual text when
  82. -- is_visible is False. i.e. this is the character used in
  83. -- "password mode" to show the user how many characters have
  84. -- been typed. The default invisible char is an asterisk
  85. -- ('*'). If you set the invisible char to 0, then the user
  86. -- will get no feedback at all; there will be no text on the
  87. -- screen as they type.
  88. do
  89. gtk_entry_set_invisible_char (handle, a_unicode)
  90. end
  91. feature -- maximum lenght
  92. max_length: INTEGER is
  93. -- the maximum allowed length of the text in entry; 0 if
  94. -- there is no maximum.
  95. do
  96. Result := gtk_entry_get_max_length (handle)
  97. end
  98. set_max_length (a_maximum_length: INTEGER) is
  99. -- Sets the maximum allowed length of the contents of the
  100. -- widget. If the current contents are longer than the given
  101. -- length, then they will be truncated to fit. The value
  102. -- passed in will be clamped to the range 0-65536.
  103. do
  104. gtk_entry_set_max_length (handle, a_maximum_length)
  105. end
  106. set_no_maximum_length is
  107. do
  108. gtk_entry_set_max_length (handle, 0)
  109. end
  110. activates_default: BOOLEAN is
  111. -- Will the entry activate the default widget?
  112. do
  113. Result := gtk_entry_get_activates_default (handle).to_boolean
  114. end
  115. has_frame: BOOLEAN is
  116. -- Has the entry a beveled frame?
  117. do
  118. Result := gtk_entry_get_has_frame (handle).to_boolean
  119. end
  120. set_has_frame is
  121. do
  122. gtk_entry_set_has_frame (handle, 1)
  123. end
  124. unset_has_frame is
  125. do
  126. gtk_entry_set_has_frame (handle, 0)
  127. end
  128. feature --
  129. width_chars: INTEGER is
  130. -- number of chars to request space for, or negative if unset
  131. do
  132. Result := gtk_entry_get_width_chars (handle)
  133. end
  134. set_width_chars (n_chars: INTEGER) is
  135. -- Changes the size request of the entry to be about the
  136. -- right size for `n_chars' characters. Note that it changes
  137. -- the size request, the size can still be affected by how
  138. -- you pack the widget into containers. If `n_chars' is -1,
  139. -- the size reverts to the default entry size.
  140. do
  141. gtk_entry_set_width_chars (handle, n_chars)
  142. end
  143. set_activates_default is
  144. -- Makes pressing Enter in the entry will activate the
  145. -- default widget for the window containing the entry. This
  146. -- usually means that the dialog box containing the entry
  147. -- will be closed, since the default widget is usually one of
  148. -- the dialog buttons.
  149. -- (For experts: if setting is TRUE, the entry calls gtk_window_activate_default() on the window containing the entry, in the default handler for the "activate" signal.)
  150. -- setting : TRUE to activate window's default widget on Enter keypress
  151. do
  152. gtk_entry_set_activates_default (handle, 1)
  153. end
  154. unset_activates_default is
  155. -- When pressing Enter the default widget is not activated
  156. do
  157. gtk_entry_set_activates_default (handle, 0)
  158. end
  159. invisible_char: INTEGER is
  160. -- the (unicode) character displayed in place of the real
  161. -- characters for entries with visibility set to false. See
  162. -- `set_invisible_char'. If 0 the entry does not show
  163. -- invisible text at all.
  164. do
  165. Result := gtk_entry_get_invisible_char (handle)
  166. end
  167. feature -- Alignment
  168. set_alignment (an_x_align: REAL) is
  169. -- Sets the alignment for the contents of the entry. This
  170. -- controls the horizontal positioning of the contents when
  171. -- the displayed text is shorter than the width of the
  172. -- entry. The horizontal alignment ranges from 0 (left) to 1
  173. -- (right) and it is reversed for RTL layouts.
  174. do
  175. gtk_entry_set_alignment (handle, an_x_align)
  176. end
  177. alignment: REAL is
  178. -- the alignment for the contents of the entry.
  179. do
  180. Result := gtk_entry_get_alignment (handle)
  181. end
  182. layout: PANGO_LAYOUT is
  183. -- the PangoLayout used to display the entry. The layout is useful
  184. -- to e.g. convert text positions to pixel positions, in
  185. -- combination with `layout_offsets'.
  186. -- Keep in mind that the layout text may contain a preedit string,
  187. -- so `layout_index_to_text_index' and `text_index_to_layout_index'
  188. -- are needed to convert byte indices in the layout to byte indices
  189. -- in the entry contents.
  190. local factory: G_OBJECT_EXPANDED_FACTORY[PANGO_LAYOUT]
  191. do
  192. -- Note: The returned layout is owned by the entry and must not be
  193. -- modified or freed by the caller.
  194. Result := factory.wrapper(gtk_entry_get_layout (handle))
  195. end
  196. layout_offsets: TUPLE[INTEGER,INTEGER] is
  197. -- the position (in [x,y] format) of the PangoLayout used to
  198. -- render text in the entry, in widget coordinates. Useful if
  199. -- you want to line up the text in an entry with some other
  200. -- text, e.g. when using the entry to implement editable
  201. -- cells in a sheet widget.
  202. -- Also useful to convert mouse events into coordinates
  203. -- inside the PangoLayout, e.g. to take some action if some
  204. -- part of the entry text is clicked.
  205. -- Note that as the user scrolls around in the entry the
  206. -- offsets will change; you'll need to connect to the
  207. -- "notify::scroll-offset" signal to track this. Remember
  208. -- when using the PangoLayout functions you need to convert
  209. -- to and from pixels using PANGO_PIXELS() or PANGO_SCALE.
  210. -- Keep in mind that the layout text may contain a preedit
  211. -- string, so `layout_index_to_text_index' and
  212. -- `text_index_to_layout_index' are needed to convert byte
  213. -- indices in the layout to byte indices in the entry
  214. -- contents.
  215. local
  216. an_x,an_y: INTEGER
  217. do
  218. gtk_entry_get_layout_offsets (handle, $an_x, $an_y)
  219. create Result.make_2 (an_x, an_y)
  220. end
  221. layout_index_to_text_index (a_layout_index: INTEGER): INTEGER is
  222. -- Converts from a position in the entry contents (returned
  223. -- by `text') to a position in the entry's PangoLayout
  224. -- (returned by `layout', with text retrieved via
  225. -- `PANGO_LAYOUT.text').
  226. -- `a_layout_index' is the byte index into the entry layout
  227. -- text
  228. -- Result is the byte index into the entry contents
  229. do
  230. Result := gtk_entry_layout_index_to_text_index (handle, a_layout_index)
  231. end
  232. text_index_to_layout_index (a_text_index: INTEGER): INTEGER is
  233. -- Converts from a position in the entry's PangoLayout
  234. -- (returned by `layout') to a position in the
  235. -- entry contents (returned by `text').
  236. -- `a_text_index': byte index into the entry contents
  237. -- Result is the byte index into the entry layout text
  238. do
  239. Result := gtk_entry_text_index_to_layout_index (handle, a_text_index)
  240. end
  241. set_completion (an_entry_completion: GTK_ENTRY_COMPLETION) is
  242. -- Sets completion to be the auxiliary completion object to
  243. -- use with entry. All further configuration of the
  244. -- completion mechanism is done on completion using the
  245. -- GTK_ENTRY_COMPLETION.
  246. do
  247. gtk_entry_set_completion (handle, an_entry_completion.handle)
  248. end
  249. completion: GTK_ENTRY_COMPLETION is
  250. -- the auxiliary completion object currently in use by entry.
  251. do
  252. create Result.from_external_pointer (gtk_entry_get_completion (handle))
  253. end
  254. feature -- Property Details
  255. -- The "activates-default" property
  256. -- "activates-default" gboolean : Read / Write
  257. -- Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed.
  258. -- Default value: FALSE
  259. -- The "cursor-position" property
  260. -- "cursor-position" gint : Read
  261. -- The current position of the insertion cursor in chars.
  262. -- Allowed values: [0,65535]
  263. -- Default value: 0
  264. -- The "editable" property
  265. -- "editable" gboolean : Read / Write
  266. -- Whether the entry contents can be edited.
  267. -- Default value: TRUE
  268. -- The "has-frame" property
  269. -- "has-frame" gboolean : Read / Write
  270. -- FALSE removes outside bevel from entry.
  271. -- Default value: TRUE
  272. -- The "invisible-char" property
  273. -- "invisible-char" guint : Read / Write
  274. -- The character to use when masking entry contents (in "password mode").
  275. -- Default value: '*'
  276. -- The "max-length" property
  277. -- "max-length" gint : Read / Write
  278. -- Maximum number of characters for this entry. Zero if no maximum.
  279. -- Allowed values: [0,65535]
  280. -- Default value: 0
  281. -- The "scroll-offset" property
  282. -- "scroll-offset" gint : Read
  283. -- Number of pixels of the entry scrolled off the screen to the left.
  284. -- Allowed values: >= 0
  285. -- Default value: 0
  286. -- The "selection-bound" property
  287. -- "selection-bound" gint : Read
  288. -- The position of the opposite end of the selection from the cursor in chars.
  289. -- Allowed values: [0,65535]
  290. -- Default value: 0
  291. -- The "text" property
  292. -- "text" gchararray : Read / Write
  293. -- The contents of the entry.
  294. -- Default value: ""
  295. -- The "visibility" property
  296. -- "visibility" gboolean : Read / Write
  297. -- FALSE displays the "invisible char" instead of the actual text (password mode).
  298. -- Default value: TRUE
  299. -- The "width-chars" property
  300. -- "width-chars" gint : Read / Write
  301. -- Number of characters to leave space for in the entry.
  302. -- Allowed values: >= -1
  303. -- Default value: -1
  304. -- The "xalign" property
  305. -- "xalign" gfloat : Read / Write
  306. -- The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts.
  307. -- Allowed values: [0,1]
  308. -- Default value: 0
  309. -- Since 2.4
  310. -- Signal Details
  311. feature -- The "activate" signal
  312. activate_signal_name: STRING is "activate"
  313. on_activate is
  314. -- Built-in activate signal handler; empty by design; redefine it.
  315. do
  316. end
  317. enable_on_activate is
  318. -- Connects "activate" signal to `on_activate' feature.
  319. do
  320. connect (Current, activate_signal_name, $on_activate)
  321. end
  322. connect_agent_to_activate_signal (a_procedure: PROCEDURE [ANY, TUPLE[GTK_ENTRY]]) is
  323. require
  324. valid_procedure: a_procedure /= Void
  325. local
  326. activate_callback: ACTIVATE_CALLBACK[like Current]
  327. do
  328. create activate_callback.make
  329. activate_callback.connect (Current, a_procedure)
  330. end
  331. feature -- The "backspace" signal
  332. backspace_signal_name: STRING is "backspace"
  333. on_backspace is
  334. -- Built-in backspace signal handler; empty by design; redefine it.
  335. local a_foo: INTEGER
  336. do
  337. a_foo := 12 -- Dummy instructions
  338. end
  339. enable_on_backspace is
  340. -- Connects "backspace" signal to `on_backspace' feature.
  341. do
  342. connect (Current, backspace_signal_name, $on_backspace)
  343. end
  344. -- TODO: implement connect_agent_to_backspace_signal (a_procedure:
  345. -- PROCEDURE [ANY, TUPLE[GTK_ENTRY]]). See GTK_BUTTON's clicked for
  346. -- inspiration.
  347. feature -- The "copy-clipboard" signal
  348. copy_clipboard_signal_name: STRING is "copy-clipboard"
  349. on_copy_clipboard is
  350. -- Built-in copy-clipboard signal handler; empty by design; redefine it.
  351. do
  352. end
  353. enable_on_copy_clipboard is
  354. -- Connects "copy_clipboard" signal to `on_copy_clipboard' feature.
  355. do
  356. connect (Current, copy_clipboard_signal_name, $on_copy_clipboard)
  357. end
  358. -- TODO: implement connect_agent_to_backspace_signal (a_procedure:
  359. -- PROCEDURE [ANY, TUPLE[GTK_ENTRY]]). See GTK_BUTTON's clicked for
  360. -- inspiration.
  361. feature -- The "cut-clipboard" signal
  362. cut_clipboard_signal_name: STRING is "cut-clipboard"
  363. on_cut_clipboard is
  364. -- Built-in cut_clipboard signal handler; empty by design; redefine it.
  365. do
  366. end
  367. enable_on_cut_clipboard is
  368. -- Connects "cut_clipboard" signal to `on_cut_clipboard' feature.
  369. do
  370. connect (Current, cut_clipboard_signal_name, $on_cut_clipboard)
  371. end
  372. -- TODO: implement connect_agent_to_cut_clipboard_signal (a_procedure:
  373. -- PROCEDURE [ANY, TUPLE[GTK_ENTRY]]). See GTK_BUTTON's clicked for
  374. -- inspiration.
  375. feature -- The "delete-from-cursor" signal
  376. -- void user_function (GtkEntry *entry,
  377. -- GtkDeleteType arg1,
  378. -- gint arg2,
  379. -- gpointer user_data) : Run last / Action
  380. -- entry : the object which received the signal.
  381. -- arg1 :
  382. -- arg2 :
  383. -- user_data : user data set when the signal handler was connected.
  384. feature -- The "insert-at-cursor" signal
  385. -- void user_function (GtkEntry *entry,
  386. -- gchar *arg1,
  387. -- gpointer user_data) : Run last / Action
  388. -- entry : the object which received the signal.
  389. -- arg1 :
  390. -- user_data : user data set when the signal handler was connected.
  391. feature -- The "move-cursor" signal
  392. -- void user_function (GtkEntry *entry,
  393. -- GtkMovementStep arg1,
  394. -- gint arg2,
  395. -- gboolean arg3,
  396. -- gpointer user_data) : Run last / Action
  397. -- entry : the object which received the signal.
  398. -- arg1 :
  399. -- arg2 :
  400. -- arg3 :
  401. -- user_data : user data set when the signal handler was connected.
  402. feature -- The "paste-clipboard" signal
  403. paste_clipboard_signal_name: STRING is "paste-clipboard"
  404. on_paste_clipboard is
  405. -- Built-in paste-clipboard signal handler; empty by design; redefine it.
  406. do
  407. end
  408. enable_on_paste_clipboard is
  409. -- Connects "paste-clipboard" signal to `on_paste_clipboard' feature.
  410. do
  411. connect (Current, paste_clipboard_signal_name, $on_paste_clipboard)
  412. end
  413. -- TODO: implement connect_agent_to_paste_clipboard_signal (a_procedure:
  414. -- PROCEDURE [ANY, TUPLE[GTK_ENTRY]]). See GTK_BUTTON's clicked for
  415. -- inspiration.
  416. feature -- The "populate-popup" signal
  417. populate_popup_signal_name: STRING is "populate-popup"
  418. on_populate_popup (a_menu: GTK_MENU) is
  419. -- Built-in paste-clipboard signal handler; empty by design; redefine it.
  420. require
  421. menu_not_void: a_menu /= Void
  422. do
  423. end
  424. enable_on_populate_popup is
  425. -- Connects "paste-clipboard" signal to `on_populate_popup' feature.
  426. do
  427. connect (Current, populate_popup_signal_name, $hidden_on_populate_popup)
  428. end
  429. -- TODO: implement connect_agent_to_populate_popup_signal (a_procedure:
  430. -- PROCEDURE [ANY, TUPLE[GTK_ENTRY]]). See GTK_BUTTON's clicked for
  431. -- inspiration.
  432. feature {} -- populate-popup signal implementation
  433. hidden_on_populate_popup (a_gtk_menu, a_gtk_entry: POINTER) is
  434. require
  435. menu_not_null: a_gtk_menu.is_not_null
  436. entry_not_null: a_gtk_entry.is_not_null -- Otherwise very bad things are happening.
  437. do
  438. on_populate_popup (wrapper (a_gtk_menu))
  439. end
  440. -- void user_function (GtkEntry *entry, GtkMenu *arg1, gpointer
  441. -- user_data) : Run
  442. -- last
  443. -- entry : the object which received the signal.
  444. -- arg1 :
  445. -- user_data : user data set when the signal handler was
  446. -- connected.
  447. feature -- The "toggle-overwrite" signal
  448. -- void user_function (GtkEntry *entry,
  449. -- gpointer user_data) : Run last / Action
  450. -- entry : the object which received the signal.
  451. -- user_data : user data set when the signal handler was connected.
  452. feature -- struct size
  453. struct_size: INTEGER is
  454. external "C inline use <gtk/gtk.h>"
  455. alias "sizeof(GtkEntry)"
  456. end
  457. end