/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

  1. indexing
  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. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public License
  7. as published by the Free Software Foundation; either version 2.1 of
  8. the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with this library; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. 02110-1301 USA
  17. ]"
  18. date: "$Date:$"
  19. revision "$REvision:$"
  20. class GTK_COLOR_BUTTON
  21. -- The GtkColorButton is a button which displays the currently
  22. -- selected color an allows to open a color selection dialog to
  23. -- change the color.
  24. -- It is suitable widget for selecting a color in a preference dialog.
  25. inherit
  26. GTK_BUTTON
  27. undefine struct_size
  28. redefine make end
  29. insert
  30. GTK_COLOR_BUTTON_EXTERNALS
  31. -- Implemented Interfaces
  32. -- GtkColorButton implements AtkImplementorIface.
  33. creation
  34. make, with_color,
  35. from_external_pointer
  36. feature {} -- Creation
  37. make is
  38. -- Creates a new color button. This is a widget in the form of a small button
  39. -- containing a swatch representing the current selected color.
  40. -- When the button is clicked, a color-selection dialog will open,
  41. -- allowing the user to select a color.
  42. -- The swatch will be updated to reflect the new color when the user finishes.
  43. do
  44. from_external_pointer (gtk_color_button_new)
  45. end
  46. with_color (a_color: GDK_COLOR) is
  47. do
  48. from_external_pointer( gtk_color_button_new_with_color (a_color.handle))
  49. end
  50. --
  51. -- Creates a new color button.
  52. --
  53. -- color : A GdkColor to set the current color with.
  54. -- Returns : a new color button.
  55. --
  56. -- Since 2.4
  57. feature
  58. set_color (a_color: GDK_COLOR) is
  59. -- Sets the current color to be a_color.
  60. do
  61. gtk_color_button_set_color (handle, a_color.handle)
  62. end
  63. color: GDK_COLOR is
  64. -- Current color in the widget.
  65. do
  66. create Result.make
  67. gtk_color_button_get_color (handle, Result.handle)
  68. end
  69. set_alpha (an_alpha: INTEGER) is
  70. -- Sets the current opacity to be `an_alpha'.
  71. -- TODO: an_alpha should be NATURAL_16
  72. require
  73. fits_natural_16: an_alpha.in_range (0, 65535)
  74. do
  75. gtk_color_button_set_alpha (handle, an_alpha)
  76. end
  77. alpha: INTEGER is
  78. -- The selected opacity value (0 fully transparent, 65535 fully opaque).
  79. -- TODO: it should be NATURAL_16
  80. do
  81. Result := gtk_color_button_get_alpha (handle)
  82. ensure
  83. fits_natural_16: Result.in_range (0, 65535)
  84. end
  85. set_use_alpha (a_setting: BOOLEAN) is
  86. -- Sets whether or not the color button should use the alpha
  87. -- channel.
  88. do
  89. gtk_color_button_set_use_alpha (handle, a_setting.to_integer)
  90. ensure
  91. set: a_setting = is_alpha_used
  92. end
  93. is_alpha_used: BOOLEAN is
  94. -- Does the color selection dialog use the alpha channel?
  95. -- If True, the color swatch on the button is rendered
  96. -- against a checkerboard background to show its opacity and
  97. -- the opacity slider is displayed in the color selection
  98. -- dialog.
  99. do
  100. Result := gtk_color_button_get_use_alpha (handle).to_boolean
  101. end
  102. set_title (a_title: STRING) is
  103. -- Sets the title for the color selection dialog.
  104. require
  105. title_not_void: a_title /= Void
  106. do
  107. gtk_color_button_set_title (handle, a_title.to_external)
  108. ensure
  109. set: a_title.is_equal (title)
  110. end
  111. title: CONST_STRING is
  112. -- the title of the color selection dialog.
  113. do
  114. create Result.from_external (gtk_color_button_get_title (handle))
  115. ensure
  116. not_void: Result /= Void
  117. end
  118. -- Note: it is not necessary to wrap the "alpha", "title" and
  119. -- "use-alpha" properties, since there are strongly-typed setter
  120. -- and getter features
  121. -- TODO: The "color" property
  122. -- "color" GdkColor : Read / Write
  123. -- The selected color.
  124. feature -- The "color-set" signal
  125. connect_agent_to_color_set_signal (a_procedure: PROCEDURE [ANY, TUPLE[GTK_COLOR_BUTTON]]) is
  126. -- The ::color-set signal is emitted when the user selects a color.
  127. -- When handling this signal, use `get_color()' and `get_alpha()'
  128. -- to find out which color was just selected.
  129. --
  130. -- Note that this signal is only emitted when the user changes the
  131. -- color. If you need to react to programmatic color changes as
  132. -- well, use the notify::color signal.
  133. --
  134. -- widget : the object which received the signal.
  135. require
  136. valid_procedure: a_procedure /= Void
  137. local
  138. color_set_callback: COLOR_SET_CALLBACK
  139. do
  140. create color_set_callback.make
  141. color_set_callback.connect (Current, a_procedure)
  142. end
  143. end -- GTK_COLOR_BUTTON