PageRenderTime 36ms CodeModel.GetById 33ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/src/wrappers/gtk/library/gtk_color_button.e

http://github.com/tybor/Liberty
Specman e | 171 lines | 95 code | 28 blank | 48 comment | 2 complexity | 7d2645b7a7f6670a7262d481fbc707ff MD5 | raw file
  1indexing
  2	description: "GtkColorButton รข€” A button to launch a color selection dialog"
  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_COLOR_BUTTON
 25	-- The GtkColorButton is a button which displays the currently
 26	-- selected color an allows to open a color selection dialog to
 27	-- change the color.
 28	
 29	-- It is suitable widget for selecting a color in a preference dialog.
 30
 31inherit
 32	GTK_BUTTON
 33		undefine struct_size
 34		redefine make end
 35
 36insert
 37	GTK_COLOR_BUTTON_EXTERNALS
 38		-- Implemented Interfaces
 39		-- GtkColorButton implements AtkImplementorIface.
 40
 41creation
 42	make, with_color,
 43	from_external_pointer
 44	
 45feature {} -- Creation
 46
 47	make is
 48			-- Creates a new color button. This is a widget in the form of a small button
 49			-- containing a swatch representing the current selected color.
 50			-- When the button is clicked, a color-selection dialog will open,
 51			-- allowing the user to select a color.
 52			-- The swatch will be updated to reflect the new color when the user finishes.
 53		do
 54			from_external_pointer (gtk_color_button_new)
 55		end
 56
 57	with_color (a_color: GDK_COLOR) is
 58		do
 59			from_external_pointer( gtk_color_button_new_with_color (a_color.handle))
 60		end
 61-- 
 62-- Creates a new color button.
 63-- 
 64-- color : 	A GdkColor to set the current color with.
 65-- Returns : 	a new color button.
 66-- 
 67-- Since 2.4
 68
 69feature
 70
 71	set_color (a_color: GDK_COLOR) is
 72			-- Sets the current color to be a_color.
 73		do
 74			gtk_color_button_set_color (handle, a_color.handle)
 75		end
 76
 77	color: GDK_COLOR is
 78			-- Current color in the widget.
 79		do
 80			create Result.make
 81			gtk_color_button_get_color (handle, Result.handle)
 82		end
 83
 84	set_alpha (an_alpha: INTEGER) is
 85			-- Sets the current opacity to be `an_alpha'.
 86			-- TODO: an_alpha should be NATURAL_16
 87		require
 88			fits_natural_16: an_alpha.in_range (0, 65535)
 89		do
 90			gtk_color_button_set_alpha (handle, an_alpha)
 91		end
 92
 93	alpha: INTEGER is
 94			-- The selected opacity value (0 fully transparent, 65535 fully opaque).
 95			-- TODO: it should be NATURAL_16
 96		do
 97			Result := gtk_color_button_get_alpha (handle)
 98		ensure
 99			fits_natural_16: Result.in_range (0, 65535)
100		end
101
102	set_use_alpha (a_setting: BOOLEAN) is
103			-- Sets whether or not the color button should use the alpha 
104			-- channel.
105		do
106			gtk_color_button_set_use_alpha (handle, a_setting.to_integer)
107		ensure
108			set: a_setting = is_alpha_used
109		end
110
111	is_alpha_used: BOOLEAN is
112			-- Does the color selection dialog use the alpha channel?
113			-- If True, the color swatch on the button is rendered
114			-- against a checkerboard background to show its opacity and
115			-- the opacity slider is displayed in the color selection
116			-- dialog.
117		do
118			Result := gtk_color_button_get_use_alpha (handle).to_boolean
119		end
120
121	set_title (a_title: STRING) is
122			-- Sets the title for the color selection dialog.
123		require
124			title_not_void: a_title /= Void
125		do
126			gtk_color_button_set_title (handle, a_title.to_external)
127		ensure
128			set: a_title.is_equal (title)
129		end
130
131	title: CONST_STRING is
132			-- the title of the color selection dialog.
133		do
134			create Result.from_external (gtk_color_button_get_title (handle))
135		ensure
136			not_void: Result /= Void
137		end
138
139	-- Note: it is not necessary to wrap the "alpha", "title" and
140	-- "use-alpha" properties, since there are strongly-typed setter
141	-- and getter features
142
143	-- TODO: The "color" property
144	
145	--   "color"                GdkColor              : Read / Write
146	 
147	-- The selected color.
148
149	
150feature -- The "color-set" signal
151
152	connect_agent_to_color_set_signal (a_procedure: PROCEDURE [ANY, TUPLE[GTK_COLOR_BUTTON]]) is
153			-- The ::color-set signal is emitted when the user selects a color.
154			-- When handling this signal, use `get_color()' and `get_alpha()'
155			-- to find out which color was just selected.
156			-- 
157			-- Note that this signal is only emitted when the user changes the
158			-- color. If you need to react to programmatic color changes as
159			-- well, use the notify::color signal.
160			-- 
161			-- widget : 	the object which received the signal.
162		require
163			valid_procedure: a_procedure /= Void
164		local
165			color_set_callback: COLOR_SET_CALLBACK
166		do
167			create color_set_callback.make
168			color_set_callback.connect (Current, a_procedure)
169		end
170
171end -- GTK_COLOR_BUTTON