PageRenderTime 23ms CodeModel.GetById 11ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

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