PageRenderTime 20ms CodeModel.GetById 8ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/src/wrappers/gtk/library/gtk_toggle_button.e

http://github.com/tybor/Liberty
Specman e | 247 lines | 114 code | 50 blank | 83 comment | 2 complexity | ff66b29e7dde4f769946677d8019ec3a 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	date: "$Date:$"
 22	revision: "$Revision:$"
 23
 24class GTK_TOGGLE_BUTTON
 25	-- A GtkToggleButton is a GtkButton which will remain 'pressed-in' when
 26	-- clicked. Clicking again will cause the toggle button to return to its
 27	-- normal state.
 28
 29	-- A toggle button is created by calling either `make' or `with_label'. If
 30	-- using the former, it is advisable to pack a widget, (such as a GtkLabel
 31	-- and/or a GtkPixmap), into the toggle button's container. (See GtkButton
 32	-- for more information).
 33
 34	-- The state of a GtkToggleButton can be set specifically using `set_active,'
 35	-- and retrieved using `is_active'.
 36
 37	-- To simply switch the state of a toggle button, use `toggled'.
 38	
 39	-- Example 2. Creating two GtkToggleButton widgets.
 40
 41	-- dialog: GTK_DIALOG
 42	-- toggle1,toggle2: GTK_TOGGLE_BUTTON
 43	
 44	-- make_toggles is
 45	--   do
 46
 47	--     create dialog.make
 48	--     create toggle1.with_label ("Hi, i'm a toggle button.")
 49	
 50	--    -- Makes this toggle button invisible
 51	--    toggle1.draw_indicator 
 52
 53	--    -- toggle1.connect_to_toggled_signal (--TODO)
 54	--    dialog.action_area.pack_start (toggle1, False, False, 2)
 55	
 56	--    create toggle2.with_label ("Hi, i'm another toggle button.")
 57	--    toggle2.draw_as_button
 58	--    -- g_signal_connect (toggle2, "toggled",  G_CALLBACK (output_state), NULL);
 59	--    dialog.action_area.pack_start (toggle2, False, False, 2)
 60	--    dialog.show_all
 61	-- end
 62
 63inherit
 64	GTK_BUTTON redefine make, with_label, with_mnemonic end
 65
 66insert
 67	GTK
 68	GTK_TOGGLE_BUTTON_EXTERNALS
 69		-- TODO: GtkToggleButton implements AtkImplementorIface.
 70
 71creation make, with_label, with_mnemonic, from_external_pointer
 72
 73feature {} -- Creation
 74
 75	make is
 76			-- Creates a new toggle button. A widget should be packed
 77			-- into the button, as GTK_BUTTON.make.
 78		require gtk_initialized: gtk.is_initialized
 79		do
 80			from_external_pointer (gtk_toggle_button_new)
 81		end
 82
 83	with_label (a_label: STRING) is
 84			-- Creates a new toggle button with a text `a_label'.
 85		require else
 86			gtk_initialized: gtk.is_initialized
 87			label_not_void: a_label /= Void
 88		do
 89			from_external_pointer (gtk_toggle_button_new_with_label (a_label.to_external))
 90		end
 91
 92	with_mnemonic (a_label: STRING) is
 93			-- Creates a new GtkToggleButton containing `a_label'. The
 94			-- label will be created using GTK_LABEL.with_mnemonic, so
 95			-- underscores in label indicate the mnemonic for the button.
 96		require else
 97			gtk_initialized: gtk.is_initialized
 98			label_not_void: a_label /= Void
 99		do
100			from_external_pointer (gtk_toggle_button_new_with_mnemonic (a_label.to_external))
101		end
102
103feature
104
105	draw_indicator is
106			-- Makes the button displayed as a separate indicator and
107			-- label. This feature only effects instances of classes like
108			-- GtkCheckButton and GtkRadioButton that derive from
109			-- GtkToggleButton, not instances of GtkToggleButton itself.
110		do
111			gtk_toggle_button_set_mode (handle, 1)
112		ensure is_indicator_drawn
113		end
114
115	draw_as_button is
116			-- Makes the button look like a normal button.  This function
117			-- only effects instances of classes like GtkCheckButton and
118			-- GtkRadioButton that derive from GtkToggleButton, not
119			-- instances of GtkToggleButton itself.
120		do
121			gtk_toggle_button_set_mode (handle, 0)
122		ensure drawn_as_button
123		end
124
125	is_indicator_drawn: BOOLEAN is
126			-- is the button displayed as a separate indicator and label?
127		do
128			Result := (gtk_toggle_button_get_mode(handle) = 1)
129		end
130
131	drawn_as_button: BOOLEAN is
132			-- is the toggle button drawn as a normal button?
133		do
134			Result := (gtk_toggle_button_get_mode(handle) = 0)
135		end
136
137	toggled is
138			-- Emits the toggled signal on the GtkToggleButton. There is
139			-- no good reason for an application ever to call this
140			-- function.
141		do
142			gtk_toggle_button_toggled (handle)
143		end
144
145	is_active: BOOLEAN is
146			-- Is the toggle button pressed? (False means that it is
147			-- raised).
148		do
149			Result:=(gtk_toggle_button_get_active(handle)).to_boolean
150		end
151
152	set_active is
153			-- Sets the status of the toggle button to be 'pressed
154			-- in'. This action causes the toggled signal to be emitted.
155		do
156			gtk_toggle_button_set_active (handle,1)
157		end
158
159	set_inactive is
160			-- Sets the status of the toggle button to be 'pressed out',
161			-- i.e.  to raise it. This action causes the toggled signal
162			-- to be emitted.
163		do
164			gtk_toggle_button_set_active (handle,0)
165		end
166
167	is_inconsistent: BOOLEAN is
168			-- Is button inconsistent?
169		do
170			Result := (gtk_toggle_button_get_inconsistent (handle)).to_boolean
171		end
172
173	set_inconsistent is
174			-- If the user has selected a range of elements (such as some
175			-- text or spreadsheet cells) that are affected by a toggle
176			-- button, and the current values in that range are
177			-- inconsistent, you may want to display the toggle in an "in
178			-- between" state. This function turns on "in between"
179			-- display. Normally you would turn off the inconsistent
180			-- state again if the user toggles the toggle button. This
181			-- has to be done manually, `set_inconsistent' only affects
182			-- visual appearance, it doesn't affect the semantics of the
183			-- button.
184		do
185			gtk_toggle_button_set_inconsistent (handle,1)
186		ensure is_inconsistent
187		end
188
189	set_consistent is
190		do
191			gtk_toggle_button_set_inconsistent (handle,0)
192		ensure not is_inconsistent
193		end
194
195feature -- "active" property
196--   "active"               gboolean              : Read / Write
197
198-- If the toggle button should be pressed in or not.
199
200-- Default value: FALSE
201
202feature -- The "draw-indicator" property
203
204--   "draw-indicator"       gboolean              : Read / Write
205
206-- If the toggle part of the button is displayed.
207
208-- Default value: FALSE
209-- The "inconsistent" property
210
211--   "inconsistent"         gboolean              : Read / Write
212
213-- If the toggle button is in an "in between" state.
214
215-- Default value: FALSE
216
217feature -- The "toggled" signal
218
219	toggled_signal_name: STRING is "toggled"
220		-- void        user_function                  (GtkToggleButton *togglebutton,
221		--                                             gpointer user_data);
222
223	on_toggled is
224			-- Built-in toggled signal handler; empty by design; redefine it.
225		do
226			-- local a_foo: INTEGER --a_foo := 12 -- Dummy instructions
227		end
228
229	enable_on_toggled is
230			-- Connects "toggled" signal to `on_toggled' feature.
231
232			-- Should be connected if you wish to perform an action
233			-- whenever the GTK_TOGGLE_BUTTON's state is changed.
234		do
235			connect (Current, toggled_signal_name, $on_toggled)
236		end
237
238	connect_to_toggled_signal, connect_agent_to_toggled_signal (a_procedure: PROCEDURE [ANY, TUPLE[GTK_TOGGLE_BUTTON]]) is
239			-- togglebutton : 	the object which received the signal.
240		require valid_procedure: a_procedure /= Void
241		local toggled_callback: TOGGLED_CALLBACK [like Current]
242		do
243			create toggled_callback.make
244			toggled_callback.connect (Current, a_procedure)
245		end
246
247end