PageRenderTime 71ms CodeModel.GetById 65ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

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