File: glib-generic_properties.ads

package info (click to toggle)
libgtkada2 2.8.1-6lenny3
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 13,496 kB
  • ctags: 3,886
  • sloc: ada: 103,189; ansic: 45,411; perl: 5,500; sh: 2,812; makefile: 1,169; xml: 19
file content (195 lines) | stat: -rw-r--r-- 8,131 bytes parent folder | download | duplicates (2)
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
-----------------------------------------------------------------------
--               GtkAda - Ada95 binding for Gtk+/Gnome               --
--                                                                   --
--                 Copyright (C) 2001-2002 ACT-Europe                --
--                                                                   --
-- 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>
--  Note: this package need only be used and understood by people who
--  want to create their own new widgets and their associated properties.
--  Normal usage of properties doesn't require any deep understanding of
--  this package.
--
--  This package provides two generic subpackages that make it easy to
--  declare properties.
--  Each of these packages define two types:
--
--  - Property_RO : this type should be used for a read-only property
--                  of the given type.
--  - Property    : This is for read-write properties
--
--  Each of these two types is associated with one or two primitive
--  operations Get_Property and Set_Property, that allows the modification
--  of properties of this type.
--
--  As a user and creator of new widgets, you should always use the
--  Generic_Enumeration_Property package, since it also registers the
--  enumeration type with gtk+ for a full compatibility with C.
--  </description>
--  <group>Glib, the general-purpose library</group>

with Glib.Object;
with Glib.Values;

package Glib.Generic_Properties is

   --------------------------------------------------
   -- Generic package for discrete type properties --
   --------------------------------------------------
   --  This package should be used to implement the
   --  Get_Property and Set_Property subprograms for all
   --  properties related to enumeration types and simple
   --  types.
   --  This should be used only for types defined in GtkAda
   --  or gtk+ themselves, not for types that you define
   --  yourself. Use Generic_Discrete_Type instead.

   generic
      type Discrete_Type is (<>);
   package Generic_Internal_Discrete_Property is
      type Property_RO is new Glib.Property;
      type Property is new Glib.Property;

      procedure Set_Property
        (Object : access Glib.Object.GObject_Record'Class;
         Name   : Property;
         Value  : Discrete_Type);
      --  Set a property of Object based on Enumeration_Type.

      function Get_Property
        (Object : access Glib.Object.GObject_Record'Class;
         Name   : Property) return Discrete_Type;
      pragma Inline (Get_Property);

      function Get_Property
        (Object : access Glib.Object.GObject_Record'Class;
         Name   : Property_RO) return Discrete_Type;
      --  Get a property from Object

   end Generic_Internal_Discrete_Property;

   -------------------------------------------------
   -- Generic package for enumerations properties --
   -------------------------------------------------
   --  This package should be used to implement the
   --  Get_Property and Set_Property subprograms for all
   --  properties related to enumeration types and simple
   --  types in users' applications.
   --  Name is the name registered in gtk+ for the type. This is also
   --  the name that appears in all the tools that use introspection
   --  to get information about the widgets and their properties, like
   --  GUI builders for instance
   --
   --  !!IMPORTANT!!: For proper usage of properties based on enumeration
   --  types, you must specify the Convention C on the type:
   --      pragma Convention (C, Enumeration_Type);

   generic
      Name : String;
      type Enumeration is (<>);
   package Generic_Enumeration_Property is

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

      package Properties is new Generic_Internal_Discrete_Property
        (Enumeration);
      type Property_RO is new Properties.Property_RO;
      type Property    is new Properties.Property;

      -----------
      -- Types --
      -----------

      function Get_Type return Glib.GType;
      --  Return the internal gtk+ type associated with the Ada enumeration
      --  Enumeration. You don't need to use such a function for the types
      --  defined in standard in GtkAda. Use Glib.Type_From_Name
      --  instead.

      function Gnew_Enum
        (Name, Nick, Blurb   : String;
         Default             : Enumeration := Enumeration'First;
         Flags : Param_Flags := Param_Readable or Param_Writable)
         return Param_Spec;
      --  Create a new param_spec (to describe properties), based on the
      --  Ada enumeration type Enumeration. This function is used when
      --  creating the property with Install_Property on an object.
      --  Name, Nick and Blurb should describe the property, not its type.

      ------------
      -- Values --
      ------------

      function Get_Enum (Value : Glib.Values.GValue) return Enumeration;
      --  Return the enumeration contained in Value, assuming it is of type
      --  Enumeration

      procedure Set_Enum
        (Value : in out Glib.Values.GValue; Enum : Enumeration);
      --  Set the enumeration value for Value. This properly initializes the
      --  type of Value, so you don't need to call Init yourself.

   private
      The_Type : Glib.GType := Glib.GType_Invalid;
      pragma Import (C, Get_Enum, "g_value_get_enum");
   end Generic_Enumeration_Property;

   -------------------------------------------------
   -- Generic package for record types properties --
   -------------------------------------------------
   --  This package should be used to implement the
   --  Get_Property and Set_Property subprograms for all
   --  properties related to record type, like Gdk_Color and
   --  Gdk_Rectangle.
   --  This should be used only for types defined in GtkAda
   --  or gtk+ themselves, not for types that you define
   --  yourself.

   generic
      type Boxed_Type is private;
      with function Get_Type return Glib.GType;
      with function Copy (B : Boxed_Type) return System.Address;
      --  Copy should return a newly allocated of B. Allocation should be done
      --  through the glib/gtk+ functions, or the memory will not be freed
      --  correctly.
   package Generic_Internal_Boxed_Property is
      type Property_RO is new Glib.Property;
      type Property    is new Glib.Property;

      procedure Set_Property
        (Object : access Glib.Object.GObject_Record'Class;
         Name   : Property;
         Value  : Boxed_Type);
      --  Set a property of Object based on Enumeration_Type.

      function Get_Property
        (Object : access Glib.Object.GObject_Record'Class;
         Name   : Property) return Boxed_Type;
      pragma Inline (Get_Property);

      function Get_Property
        (Object : access Glib.Object.GObject_Record'Class;
         Name   : Property_RO) return Boxed_Type;
      --  Get a property from Object

   end Generic_Internal_Boxed_Property;

end Glib.Generic_Properties;