2 define(`HTMLNAME',`terminal_interface-curses-forms-field_user_data__ads.htm')dnl
4 ------------------------------------------------------------------------------
6 -- GNAT ncurses Binding --
8 -- Terminal_Interface.Curses.Forms.Field_Types --
12 ------------------------------------------------------------------------------
13 -- Copyright (c) 1998 Free Software Foundation, Inc. --
15 -- Permission is hereby granted, free of charge, to any person obtaining a --
16 -- copy of this software and associated documentation files (the --
17 -- "Software"), to deal in the Software without restriction, including --
18 -- without limitation the rights to use, copy, modify, merge, publish, --
19 -- distribute, distribute with modifications, sublicense, and/or sell --
20 -- copies of the Software, and to permit persons to whom the Software is --
21 -- furnished to do so, subject to the following conditions: --
23 -- The above copyright notice and this permission notice shall be included --
24 -- in all copies or substantial portions of the Software. --
26 -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS --
27 -- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF --
28 -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. --
29 -- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, --
30 -- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR --
31 -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR --
32 -- THE USE OR OTHER DEALINGS IN THE SOFTWARE. --
34 -- Except as contained in this notice, the name(s) of the above copyright --
35 -- holders shall not be used in advertising or otherwise to promote the --
36 -- sale, use or other dealings in this Software without prior written --
38 ------------------------------------------------------------------------------
39 -- Author: Juergen Pfeifer, 1996
42 -- Binding Version 01.00
43 ------------------------------------------------------------------------------
46 package Terminal_Interface.Curses.Forms.Field_Types is
47 pragma Preelaborate (Terminal_Interface.Curses.Forms.Field_Types);
48 use type Interfaces.C.int;
49 subtype C_Int is Interfaces.C.int;
51 -- MANPAGE(`form_fieldtype.3x')
53 type Field_Type is abstract tagged null record;
54 -- Abstract base type for all field types. A concrete field type
55 -- is an extension that adds some data elements describing formats or
56 -- boundary values for the type and validation routines.
57 -- For the builtin low-level fieldtypes, the validation routines are
58 -- already defined by the low-level C library.
59 -- The builtin types like Alpha or AlphaNumeric etc. are defined in
60 -- child packages of this package. You may use one of them as example
61 -- how to create you own child packages for low-level field types that
62 -- you may have already written in C.
64 type Field_Type_Access is access all Field_Type'Class;
66 -- ANCHOR(`set_field_type()',`Set_Type')
67 procedure Set_Field_Type (Fld : in Field;
68 Fld_Type : in Field_Type) is abstract;
70 -- But: we hide the vararg mechanism of the C interface. You always
71 -- have to pass a single Field_Type parameter.
73 -- ---------------------------------------------------------------------
75 -- MANPAGE(`form_field_validation.3x')
77 -- ANCHOR(`field_type()',`Get_Type')
78 function Get_Type (Fld : in Field) return Field_Type_Access;
80 -- ALIAS(`field_arg()')
81 -- In Ada95 we can combine these. If you try to retrieve the field type
82 -- that is not defined as extension of the abstract tagged type above,
83 -- you will raise a Form_Exception.
84 -- This is not inlined
86 -- +----------------------------------------------------------------------
88 -- | Most of this is used by the implementations of the child packages.
91 type Makearg_Function is access
92 function (Args : System.Address) return System.Address;
93 pragma Convention (C, Makearg_Function);
95 type Copyarg_Function is access
96 function (Usr : System.Address) return System.Address;
97 pragma Convention (C, Copyarg_Function);
99 type Freearg_Function is access
100 procedure (Usr : System.Address);
101 pragma Convention (C, Freearg_Function);
103 type Field_Check_Function is access
104 function (Fld : Field; Usr : System.Address) return C_Int;
105 pragma Convention (C, Field_Check_Function);
107 type Char_Check_Function is access
108 function (Ch : C_Int; Usr : System.Address) return C_Int;
109 pragma Convention (C, Char_Check_Function);
111 type Choice_Function is access
112 function (Fld : Field; Usr : System.Address) return C_Int;
113 pragma Convention (C, Choice_Function);
115 -- +----------------------------------------------------------------------
116 -- | This must be in sync with the FIELDTYPE structure in form.h
118 type Low_Level_Field_Type is
120 Status : Interfaces.C.short;
121 Ref_Count : Interfaces.C.long;
122 Left, Right : System.Address;
123 Makearg : Makearg_Function;
124 Copyarg : Copyarg_Function;
125 Freearg : Freearg_Function;
126 Fcheck : Field_Check_Function;
127 Ccheck : Char_Check_Function;
128 Next, Prev : Choice_Function;
130 pragma Convention (C, Low_Level_Field_Type);
131 type C_Field_Type is access all Low_Level_Field_Type;
133 Null_Field_Type : constant C_Field_Type := null;
135 -- +----------------------------------------------------------------------
136 -- | This four low-level fieldtypes are the ones associated with
137 -- | fieldtypes handled by this binding. Any other low-level fieldtype
138 -- | will result in a Form_Exception is function Get_Type.
140 M_Generic_Type : C_Field_Type := null;
141 M_Generic_Choice : C_Field_Type := null;
142 M_Builtin_Router : C_Field_Type := null;
143 M_Choice_Router : C_Field_Type := null;
145 -- Two wrapper functions to access those low-level fieldtypes defined
147 function C_Builtin_Router return C_Field_Type;
148 function C_Choice_Router return C_Field_Type;
150 procedure Wrap_Builtin (Fld : Field;
151 Typ : Field_Type'Class;
152 Cft : C_Field_Type := C_Builtin_Router);
153 -- This procedure has to be called by the Set_Field_Type implementation
154 -- for builtin low-level fieldtypes to replace it by an Ada95
155 -- conformant Field_Type object.
156 -- The parameter Cft must be C_Builtin_Router for regular low-level
157 -- fieldtypes (like TYP_ALPHA or TYP_ALNUM) and C_Choice_Router for
158 -- low-level fieldtypes witch choice functions (like TYP_ENUM).
159 -- Any other value will raise a Form_Exception.
161 function Make_Arg (Args : System.Address) return System.Address;
162 pragma Convention (C, Make_Arg);
163 -- This is the Makearg_Function for the internal low-level types
164 -- introduced by this binding.
166 function Copy_Arg (Usr : System.Address) return System.Address;
167 pragma Convention (C, Copy_Arg);
168 -- This is the Copyarg_Function for the internal low-level types
169 -- introduced by this binding.
171 procedure Free_Arg (Usr : System.Address);
172 pragma Convention (C, Free_Arg);
173 -- This is the Freearg_Function for the internal low-level types
174 -- introduced by this binding.
176 function Field_Check_Router (Fld : Field;
177 Usr : System.Address) return C_Int;
178 pragma Convention (C, Field_Check_Router);
179 -- This is the Field_Check_Function for the internal low-level types
180 -- introduced to wrap the low-level types by a Field_Type derived
181 -- type. It routes the call to the corresponding low-level validation
184 function Char_Check_Router (Ch : C_Int;
185 Usr : System.Address) return C_Int;
186 pragma Convention (C, Char_Check_Router);
187 -- This is the Char_Check_Function for the internal low-level types
188 -- introduced to wrap the low-level types by a Field_Type derived
189 -- type. It routes the call to the corresponding low-level validation
192 function Next_Router (Fld : Field;
193 Usr : System.Address) return C_Int;
194 pragma Convention (C, Next_Router);
195 -- This is the Choice_Function for the internal low-level types
196 -- introduced to wrap the low-level types by a Field_Type derived
197 -- type. It routes the call to the corresponding low-level next_choice
200 function Prev_Router (Fld : Field;
201 Usr : System.Address) return C_Int;
202 pragma Convention (C, Prev_Router);
203 -- This is the Choice_Function for the internal low-level types
204 -- introduced to wrap the low-level types by a Field_Type derived
205 -- type. It routes the call to the corresponding low-level prev_choice
208 -- This is the Argument structure maintained by all low-level field types
209 -- introduced by this binding.
210 type Argument is record
211 Typ : Field_Type_Access; -- the Field_Type creating this record
212 Usr : System.Address; -- original arg for builtin low-level types
213 Cft : C_Field_Type; -- the original low-level type
215 type Argument_Access is access all Argument;
217 -- +----------------------------------------------------------------------
219 -- | Some Imports of libform routines to deal with low-level fieldtypes.
221 function New_Fieldtype (Fcheck : Field_Check_Function;
222 Ccheck : Char_Check_Function)
224 pragma Import (C, New_Fieldtype, "new_fieldtype");
226 function Set_Fieldtype_Arg (Cft : C_Field_Type;
227 Mak : Makearg_Function := Make_Arg'Access;
228 Cop : Copyarg_Function := Copy_Arg'Access;
229 Fre : Freearg_Function := Free_Arg'Access)
231 pragma Import (C, Set_Fieldtype_Arg, "set_fieldtype_arg");
233 function Set_Fieldtype_Choice (Cft : C_Field_Type;
234 Next, Prev : Choice_Function)
236 pragma Import (C, Set_Fieldtype_Choice, "set_fieldtype_choice");
238 end Terminal_Interface.Curses.Forms.Field_Types;