PageRenderTime 14ms CodeModel.GetById 9ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 1ms

/src/wrappers/gtk/library/gtk_tool_button.e

http://github.com/tybor/Liberty
Specman e | 323 lines | 181 code | 48 blank | 94 comment | 7 complexity | 98f040359034937097a3edf439183f41 MD5 | raw file
  1indexing
  2	description: "A GtkToolItem subclass that displays buttons."
  3	copyright: "[
  4					Copyright (C) 2006 Daniel F Moisset, 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_TOOL_BUTTON
 23	-- GtkToolButtons are GtkToolItems containing buttons. Use `with_label'
 24	-- to create a new GtkToolButton. Use `with_stock' to create a
 25	-- GtkToolButton containing a stock item.
 26
 27	-- The label of a GtkToolButton is determined by the
 28	-- properties/feature "label_widget", "label", and "stock_id". If
 29	-- "label_widget" is non-Void, then that widget is used as the
 30	-- label. Otherwise, if "label" is non-Void, that string is used as
 31	-- the label. Otherwise, if "stock_id" is non-Void, the label is
 32	-- determined by the stock item. Otherwise, the button does not
 33	-- have a label.
 34
 35	-- The icon of a GtkToolButton is determined by the properties
 36	-- "icon_widget" and "stock_id". If "icon_widget" is non-Void, then
 37	-- that widget is used as the icon. Otherwise, if "stock_id" is
 38	-- non-Void, the icon is determined by the stock item. Otherwise,
 39	-- the button does not have a label.
 40
 41inherit
 42	GTK_TOOL_ITEM redefine struct_size end
 43	
 44create
 45	from_external_pointer, from_stock, from_label
 46
 47
 48feature {} -- Creation
 49	from_label (an_icon_widget: GTK_WIDGET; a_label: STRING) is
 50			--Creates a new GtkToolButton using `an_icon_widget' as icon
 51			--and `a_label' as label. Both can be Void.
 52		do
 53			from_external_pointer(gtk_tool_button_new(null_or(an_icon_widget),
 54																	null_or_string(a_label)))
 55		end
 56
 57	from_stock (a_stock_id: STRING) is
 58			-- Creates a new GtkToolButton containing the image and text
 59			-- from a stock item. Some stock ids have preprocessor macros
 60			-- like GTK_STOCK_OK and GTK_STOCK_APPLY.
 61		require
 62			id_not_void: a_stock_id /= Void
 63			valid_stock_id: -- TODO It is an error if stock_id is not a name of a stock 
 64			-- item.
 65		do
 66			from_external_pointer(gtk_tool_button_new_from_stock (a_stock_id.to_external))
 67		end
 68		
 69
 70feature 
 71	
 72	set_label (a_label: STRING) is
 73			-- Sets label as the label used for the tool button. The
 74			-- "label" property only has an effect if not overridden by a
 75			-- non-Void "label_widget" property. If both the
 76			-- "label_widget" and "label" properties are Void, the label
 77			-- is determined by the "stock_id" property. If the
 78			-- "stock_id" property is also Void, button will not have a
 79			-- label.
 80		do
 81			gtk_tool_button_set_label (handle,null_or_string(a_label))
 82			ensure set: a_label/=Void implies a_label.is_equal(label)
 83		end
 84
 85	label: CONST_STRING is
 86			-- the label used by the tool button; Void if the tool button
 87			-- doesn't have a label or uses a the label from a stock
 88			-- item. 
 89		local ptr: POINTER
 90		do
 91			ptr := gtk_tool_button_get_label(handle)
 92			-- The returned string is owned by GTK+, and must not be
 93			-- modified or freed. So we create a CONST_STRING
 94			if ptr.is_not_null then 
 95				create {CONST_STRING} Result.from_external(ptr)
 96			end
 97		end
 98
 99	set_use_underline (a_setting: BOOLEAN) is
100			-- If set, an underline in the label property indicates that
101			-- the next character should be used for the mnemonic
102			-- accelerator key in the overflow menu. For example, if the
103			-- label property is "_Open" and use_underline is True, the
104			-- label on the tool button will be "Open" and the item on
105			-- the overflow menu will have an underlined 'O'.
106			
107			-- Labels shown on tool buttons never have mnemonics on them;
108			-- this property only affects the menu item on the overflow
109			-- menu.
110		do
111			gtk_tool_button_set_use_underline(handle,
112														 a_setting.to_integer)
113		ensure set: a_setting = is_underline_used
114		end
115
116	is_underline_used: BOOLEAN is
117			-- Are underscores used in the label property as mnemonics?
118			-- See `set_use_underline'.
119		do 
120			Result:=(gtk_tool_button_get_use_underline(handle).to_boolean)
121		end
122
123	set_stock_id (a_stock_id: STRING) is
124			-- Sets the name of the stock item. See `from_stock'. The
125			-- stock_id property only has an effect if not overridden by
126			-- non-Void "label" and "icon_widget" properties.
127		do
128			gtk_tool_button_set_stock_id(handle,
129												  null_or_string(a_stock_id))
130		end
131
132	stock_id: CONST_STRING is
133			-- The name of the stock item. See `set_stock_id'.
134		local ptr: POINTER 
135		do
136			ptr := gtk_tool_button_get_stock_id (handle)
137			if ptr.is_not_null then
138				create Result.from_external(ptr)
139			end
140		end
141
142	set_icon_name (an_icon_name: STRING) is
143			-- Sets the icon for the tool button from a named themed
144			-- icon. See the docs for GtkIconTheme for more details. The
145			-- "icon_name" property only has an effect if not overridden
146			-- by non-Void "label", "icon_widget" and "stock_id"
147			-- properties.
148		require name_not_void: an_icon_name/=Void
149		do
150			gtk_tool_button_set_icon_name(handle, an_icon_name.to_external)
151		end
152
153	icon_name: CONST_STRING is
154			--  name of the themed icon for the tool button, see
155			-- `set_icon_name'.
156		local ptr: POINTER
157		do 
158			ptr:=gtk_tool_button_get_icon_name(handle)
159			if ptr.is_not_null then
160				create Result.from_external(ptr)
161			end
162		end
163	
164	set_icon_widget (an_icon_widget: GTK_WIDGET) is
165			-- Sets `an_icon_widget' as the widget used as icon on
166			-- button. If Voidthe icon is determined by the "stock_id"
167			-- property. If the "stock_id" property is also Void, button
168			-- will not have an icon.
169		do
170			gtk_tool_button_set_icon_widget (handle,null_or(an_icon_widget))
171		ensure set: an_icon_widget = icon_widget
172		end
173
174	icon_widget: GTK_WIDGET is
175			-- the widget used as icon widget on button. See
176			-- `set_icon_widget'. 
177
178			-- Note: In debug mode an unwrapped object obtained from the
179			-- GTK library will produce an exception; otherwise Result
180			-- will be Void
181		local ptr: POINTER; r: G_OBJECT_EXPANDED_FACTORY[GTK_WIDGET]
182		do
183			ptr:=gtk_tool_button_get_icon_widget(handle)
184			if ptr.is_not_null then
185				Result:=r.wrapper(ptr)
186				debug 
187					if Result=Void then
188						raise(pointer_to_unwrapped_deferred_object)
189					end
190				end
191			end
192		end
193
194	set_label_widget (a_label_widget: GTK_WIDGET) is
195			-- Sets `a_label_widget' as the widget that will be used as
196			-- the label for button. If label_widget is Void the "label"
197			-- property is used as label. If "label" is also Void, the
198			-- label in the stock item determined by the "stock_id"
199			-- property is used as label. If "stock_id" is also Void,
200			-- button does not have a label.  
201		do
202			gtk_tool_button_set_label_widget(handle,null_or(a_label_widget))
203		ensure set: a_label_widget = label_widget
204		end
205
206	label_widget: GTK_WIDGET is
207		-- The widget used as label on button. Can be Void. See
208		-- `set_label_widget'.
209		local factory: G_OBJECT_EXPANDED_FACTORY[GTK_WIDGET]
210		do
211			Result := factory.wrapper_or_void (gtk_tool_button_get_label_widget(handle))
212		end
213	
214feature --Properties 
215
216	-- Note: "icon-name", "icon-widget", "label", "label-widget",  "stock-id" 
217	-- and "use-underline" properties have proper, strongly-typed 
218	-- getter/setters features so they're not wrapped as properties
219
220feature -- The "clicked" signal
221	clicked_signal_name: STRING is "clicked"
222
223	on_clicked is
224			-- Built-in clicked signal handler; empty by design; redefine it.
225		local a_foo: INTEGER
226		do
227			a_foo := 12 -- Dummy instructions
228		end
229
230	enable_on_clicked is
231			-- Connects "clicked" signal to `on_clicked' feature.
232			-- This signal is emitted when the tool button is clicked with the
233			-- mouse or activated with the keyboard.
234		do
235			connect (Current, clicked_signal_name, $on_clicked)
236		end
237
238	connect_agent_to_clicked_signal (a_procedure: PROCEDURE [ANY, TUPLE[GTK_TOOL_BUTTON]]) is
239			-- button : 	the object that received the signal
240		require valid_procedure: a_procedure /= Void
241		local clicked_callback: CLICKED_CALLBACK [like Current]
242		do
243			create clicked_callback.make
244			clicked_callback.connect (Current, a_procedure)
245		end
246
247feature -- size
248	struct_size: INTEGER is
249		external "C inline use <gtk/gtk.h>"
250		alias "sizeof(GtkToolButton)"
251		end
252	
253feature {} -- External calls
254	gtk_tool_button_new (a_icon_widget, a_label: POINTER): POINTER is
255			-- GtkToolItem* gtk_tool_button_new (GtkWidget *icon_widget, const gchar *label);
256		external "C use <gtk/gtk.h>"
257		end
258
259	gtk_tool_button_new_from_stock (a_stock_id: POINTER): POINTER is
260			-- GtkToolItem* gtk_tool_button_new_from_stock (const gchar *stock_id);
261		external "C use <gtk/gtk.h>"
262		end
263
264	gtk_tool_button_set_label (a_button, a_label: POINTER) is
265			-- void gtk_tool_button_set_label (GtkToolButton *button, const gchar *label);
266		external "C use <gtk/gtk.h>"
267		end
268
269	gtk_tool_button_get_label (a_button: POINTER): POINTER is
270			-- const gchar* gtk_tool_button_get_label (GtkToolButton *button);
271		external "C use <gtk/gtk.h>"
272		end
273
274	gtk_tool_button_set_use_underline (a_button: POINTER; a_use_underline: INTEGER) is
275			-- void gtk_tool_button_set_use_underline (GtkToolButton *button, gboolean use_underline);
276		external "C use <gtk/gtk.h>"
277		end
278
279	gtk_tool_button_get_use_underline (a_button: POINTER): INTEGER is
280			-- gboolean gtk_tool_button_get_use_underline (GtkToolButton *button);
281		external "C use <gtk/gtk.h>"
282		end
283
284	gtk_tool_button_set_stock_id (a_button, a_stock_id: POINTER) is
285			-- void gtk_tool_button_set_stock_id (GtkToolButton *button, const gchar *stock_id);
286		external "C use <gtk/gtk.h>"
287		end
288
289	gtk_tool_button_get_stock_id (a_button: POINTER): POINTER is
290			-- const gchar* gtk_tool_button_get_stock_id (GtkToolButton *button);
291		external "C use <gtk/gtk.h>"
292		end
293
294	gtk_tool_button_set_icon_name (a_button, an_icon_name: POINTER) is
295			-- void gtk_tool_button_set_icon_name (GtkToolButton *button, const gchar *icon_name);
296		external "C use <gtk/gtk.h>"
297		end
298
299	gtk_tool_button_get_icon_name (a_button: POINTER): POINTER is
300			-- const gchar* gtk_tool_button_get_icon_name (GtkToolButton *button);
301		external "C use <gtk/gtk.h>"
302		end
303
304	gtk_tool_button_set_icon_widget (a_button, an_icon_widget: POINTER) is
305			-- void gtk_tool_button_set_icon_widget (GtkToolButton *button, GtkWidget *icon_widget);
306		external "C use <gtk/gtk.h>"
307		end
308
309	gtk_tool_button_get_icon_widget (a_button: POINTER): POINTER is
310			-- GtkWidget* gtk_tool_button_get_icon_widget (GtkToolButton *button);
311		external "C use <gtk/gtk.h>"
312		end
313
314	gtk_tool_button_set_label_widget (a_button, a_label_widget: POINTER) is
315			-- void gtk_tool_button_set_label_widget (GtkToolButton *button, GtkWidget *label_widget);
316		external "C use <gtk/gtk.h>"
317		end
318
319	gtk_tool_button_get_label_widget (a_button: POINTER): POINTER is
320			-- GtkWidget* gtk_tool_button_get_label_widget (GtkToolButton *button);
321		external "C use <gtk/gtk.h>"
322		end
323end