~ubuntu-branches/ubuntu/intrepid/libgtkada2/intrepid

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
-----------------------------------------------------------------------
--               GtkAda - Ada95 binding for Gtk+/Gnome               --
--                                                                   --
--   Copyright (C) 1998-2000 E. Briot, J. Brobecker and A. Charlet   --
--                Copyright (C) 2000-2007 AdaCore                    --
--                                                                   --
-- This library is free software; you can redistribute it and/or     --
-- modify it under the terms of the GNU General Public               --
-- License as published by the Free Software Foundation; either      --
-- version 2 of the License, or (at your option) any later version.  --
--                                                                   --
-- This library is distributed in the hope that it will be useful,   --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of    --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU --
-- General Public License for more details.                          --
--                                                                   --
-- You should have received a copy of the GNU General Public         --
-- License along with this library; if not, write to the             --
-- Free Software Foundation, Inc., 59 Temple Place - Suite 330,      --
-- Boston, MA 02111-1307, USA.                                       --
--                                                                   --
-----------------------------------------------------------------------

--  <description>
--  A Gtk_Color_Selection widget is a complex dialog that allows the user
--  to select a color based either on its (Red, Green, Blue) or its
--  (Hue, Saturation, Value).
--  An additional field is provided to select the opacity of the color (this
--  is usually called the alpha channel).
--
--  See Gtk.Color_Selection_Dialog for a version of this widget that comes with
--  its own dialog.
--
--  See Gtk.Extra.Color_Combo for a different way to select colors.
--  </description>
--  <c_version>2.8.17</c_version>
--  <group>Drawing</group>
--  <testgtk>create_color_selection.adb</testgtk>
--  <screenshot>gtk-colorsel</screenshot>

with Glib.Properties;
with Gdk.Color;
with Gtk.Enums;
with Gtk.Box;

package Gtk.Color_Selection is

   type Gtk_Color_Selection_Record is new Gtk.Box.Gtk_Box_Record with private;
   type Gtk_Color_Selection is access all Gtk_Color_Selection_Record'Class;

   type Color_Index is (Red, Green, Blue, Opacity);
   --  Used as an index to the table used to set and get the currently
   --  selected color.

   type Color_Array is array (Color_Index) of Gdouble;
   --  Array that indicates the currently selected color.
   --  All the values are between 0.0 and 1.0 (a percentage value).
   --  They should be converted to absolute values before using them to create
   --  a new color, with the following piece of code:
   --    Absolute := To_Absolute (Color_Array (Index))

   procedure Gtk_New (Widget : out Gtk_Color_Selection);
   procedure Initialize (Widget : access Gtk_Color_Selection_Record'Class);
   --  Creates or initiailizes a new color selection widget.

   function Get_Type return Glib.GType;
   --  Return the internal value associated with a Gtk_Color_Selection.

   procedure Set_Current_Color
     (Colorsel : access Gtk_Color_Selection_Record;
      Color    : Gdk.Color.Gdk_Color);
   procedure Get_Current_Color
     (Colorsel : access Gtk_Color_Selection_Record;
      Color    : out Gdk.Color.Gdk_Color);
   --  Set the current color of the Colorsel. When called for the first time,
   --  the original color will the set to Color as well.

   procedure Set_Previous_Color
     (Colorsel : access Gtk_Color_Selection_Record;
      Color    : Gdk.Color.Gdk_Color);
   procedure Get_Previous_Color
     (Colorsel : access Gtk_Color_Selection_Record;
      Color    : out Gdk.Color.Gdk_Color);
   --  Set the previous color. This procedure should not be called without
   --  analysis, as it might seem confusing to see that color change.
   --  Calling Set_Current_Color for the first time will also set this
   --  color.

   function Is_Adjusting
      (Colorsel : access Gtk_Color_Selection_Record) return Boolean;
   --  Get the current state of the Colorsel.
   --  Return TRue if the user is currently dragging a color around, False if
   --  the selection has stopped.

   function To_Absolute (Color : Gdouble) return Gushort;
   --  Convert from a percentage value as returned by Get_Color to an
   --  absolute value as can be used with Gdk_Color.

   function To_Percent (Color : Gushort) return Gdouble;
   --  Convert from an absolute value as used in Gdk_Color to a percentage
   --  value as used in Set_Color.

   -------------
   -- Opacity --
   -------------
   --  The color selection widget allows you optionally to select the opacity
   --  of the color

   procedure Set_Has_Opacity_Control
     (Colorsel    : access Gtk_Color_Selection_Record;
      Has_Opacity : Boolean);
   function Get_Has_Opacity_Control
     (Colorsel : access Gtk_Color_Selection_Record) return Boolean;
   --  Set the Colorsel to use or not use opacity. An additional field is
   --  displayed to select the opacity if needed.

   procedure Set_Previous_Alpha
     (Colorsel : access Gtk_Color_Selection_Record;
      Alpha    : Guint16);
   function Get_Previous_Alpha
     (Colorsel : access Gtk_Color_Selection_Record) return Guint16;
   --  Set the previous opacity to Alpha. This procedure should not be called
   --  without analysis, as it might seem confusing to see that value change.

   procedure Set_Current_Alpha
     (Colorsel : access Gtk_Color_Selection_Record;
      Alpha    : Guint16);
   function Get_Current_Alpha
     (Colorsel : access Gtk_Color_Selection_Record) return Guint16;
   --  Set the current opacity to be Alpha. When called for the first time,
   --  the original opacity will be set too.

   -------------
   -- Palette --
   -------------
   --  The color selection widget can optionally display a palette, which the
   --  user can change dynamically. This palette helps selecting colors for the
   --  user, who can chose faster among a limited set of colors.

   procedure Set_Has_Palette
     (Colorsel    : access Gtk_Color_Selection_Record;
      Has_Palette : Boolean);
   function Get_Has_Palette
     (Colorsel : access Gtk_Color_Selection_Record) return Boolean;
   --  If Has_Palette is True, then set the Colorsel to show the palette.
   --  Hide the palette otherwise.

   function Palette_From_String
     (Str : String) return Gdk.Color.Gdk_Color_Array;
   --  Parses a color palette string; this string is a colon-separated list of
   --  color names readable by Gdk.Color.Parse.
   --  An empty array is returned if Str couldn't be parsed

   function Palette_To_String
     (Colors   : Gdk.Color.Gdk_Color_Array) return String;
   --  Encodes a palette as a string, useful for persistent storage.

   type Gtk_Color_Selection_Change_Palette_With_Screen_Func is access
     procedure (Screen : Gdk.Gdk_Screen;
                Colors : Gdk.Color.Gdk_Color_Array);
   --  This function should save the new palette contents, and update the
   --  Gtk_Settings property "gtk-color-palette" so all Gtk_Color_Selection
   --  widgets will be modified, including the current one. For instance, you
   --  would do:
   --    Set_String_Property
   --      (Get_Default, Gtk_Color_Palette, Palette_To_String (Colors), "Foo");

   function Set_Change_Palette_With_Screen_Hook
     (Func : Gtk_Color_Selection_Change_Palette_With_Screen_Func)
      return Gtk_Color_Selection_Change_Palette_With_Screen_Func;
   --  Installs a global function to be called whenever the user tries to
   --  modify the palette in a color selection.
   --  Return value: the previous change palette hook (that was replaced).

   -----------------
   -- Obsolescent --
   -----------------
   --  All subprograms below are now obsolescent in gtk+. They might be removed
   --  from future versions of gtk+ (and therefore GtkAda).
   --  To find out whether your code uses any of these, we recommend compiling
   --  with the -gnatwj switch
   --  <doc_ignore>

   procedure Set_Update_Policy
     (Colorsel : access Gtk_Color_Selection_Record;
      Policy   : Enums.Gtk_Update_Type);
   pragma Obsolescent;  --  Set_Update_Policy
   --  Set the behavior of the scales used to select a value (red, green,...)
   --  Set Policy to Update_Continuous if you want to update the color
   --  continuously as the slider is mode, Update_Discontinuous to update the
   --  color only when the mouse is released and Update_Delayed to update when
   --  the mouse is released or has been motionless for a while.

   procedure Set_Color
     (Colorsel : access Gtk_Color_Selection_Record;
      Color    : Color_Array);
   pragma Obsolescent ("Use Set_Current_Color");  --  Set_Color
   --  Modify the current color.
   --  Note that Color is an array of percentages, between 0.0 and 1.0, not
   --  absolute values.

   procedure Get_Color
     (Colorsel : access Gtk_Color_Selection_Record;
      Color    : out Color_Array);
   pragma Obsolescent ("Use Get_Current_Color");  --  Get_Color
   --  Get the current color.
   --  Note that Color is an array of percentages, between 0.0 and 1.0, not
   --  absolute values.

   --  </doc_ignore>

   ----------------
   -- Properties --
   ----------------

   --  <properties>
   --  The following properties are defined for this widget. See
   --  Glib.Properties for more information on properties.
   --
   --  Name:  Current_Alpha_Property
   --  Type:  Uint
   --  Descr: The current opacity value (0 fully transparent, 65535 fully
   --         opaque)
   --
   --  Name:  Current_Color_Property
   --  Type:  Boxed
   --  Descr: The current color
   --
   --  Name:  Has_Opacity_Control_Property
   --  Type:  Boolean
   --  Descr: Whether the color selector should allow setting opacity
   --
   --  Name:  Has_Palette_Property
   --  Type:  Boolean
   --  Descr: Whether a palette should be used
   --
   --  </properties>

   Current_Alpha_Property       : constant Glib.Properties.Property_Uint;
   --  Current_Color_Property       : constant Glib.Properties.Property_Boxed;
   Has_Opacity_Control_Property : constant Glib.Properties.Property_Boolean;
   Has_Palette_Property         : constant Glib.Properties.Property_Boolean;

   -------------
   -- Signals --
   -------------

   --  <signals>
   --  The following new signals are defined for this widget:
   --
   --  - "color_changed"
   --    procedure Handler
   --       (Selection : access Gtk_Color_Selection_Record'Class);
   --    Called every time a new color is selected in the dialog
   --  </signals>

   Signal_Color_Changed : constant Glib.Signal_Name := "color_changed";

private
   type Gtk_Color_Selection_Record is new Gtk.Box.Gtk_Box_Record
     with null record;

   Current_Alpha_Property : constant Glib.Properties.Property_Uint :=
     Glib.Properties.Build ("current-alpha");
   --  Current_Color_Property : constant Glib.Properties.Property_Boxed :=
   --    Glib.Properties.Build ("current-color");
   Has_Opacity_Control_Property : constant Glib.Properties.Property_Boolean :=
     Glib.Properties.Build ("has-opacity-control");
   Has_Palette_Property : constant Glib.Properties.Property_Boolean :=
     Glib.Properties.Build ("has-palette");

   pragma Import (C, Get_Type, "gtk_color_selection_get_type");
end Gtk.Color_Selection;

--  These subprograms never had a binding and are now obsolescent:
--  No binding: gtk_color_selection_set_change_palette_hook