]> ncurses.scripts.mit.edu Git - ncurses.git/blob - Ada95/gen/terminal_interface-curses-forms-field_types.ads.m4
ncurses 5.9 - patch 20121110
[ncurses.git] / Ada95 / gen / terminal_interface-curses-forms-field_types.ads.m4
1 --  -*- ada -*-
2 define(`HTMLNAME',`terminal_interface-curses-forms-field_user_data__ads.htm')dnl
3 include(M4MACRO)dnl
4 ------------------------------------------------------------------------------
5 --                                                                          --
6 --                           GNAT ncurses Binding                           --
7 --                                                                          --
8 --                 Terminal_Interface.Curses.Forms.Field_Types              --
9 --                                                                          --
10 --                                 S P E C                                  --
11 --                                                                          --
12 ------------------------------------------------------------------------------
13 -- Copyright (c) 1998-2009,2011 Free Software Foundation, Inc.              --
14 --                                                                          --
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:                 --
22 --                                                                          --
23 -- The above copyright notice and this permission notice shall be included  --
24 -- in all copies or substantial portions of the Software.                   --
25 --                                                                          --
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.                               --
33 --                                                                          --
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       --
37 -- authorization.                                                           --
38 ------------------------------------------------------------------------------
39 --  Author:  Juergen Pfeifer, 1996
40 --  Version Control:
41 --  $Revision: 1.16 $
42 --  Binding Version 01.00
43 ------------------------------------------------------------------------------
44 with Interfaces.C;
45
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;
50
51    --  MANPAGE(`form_fieldtype.3x')
52
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.
63
64    type Field_Type_Access is access all Field_Type'Class;
65
66    --  ANCHOR(`set_field_type()',`Set_Type')
67    procedure Set_Field_Type (Fld      : Field;
68                              Fld_Type : Field_Type) is abstract;
69    --  AKA
70    --  But: we hide the vararg mechanism of the C interface. You always
71    --       have to pass a single Field_Type parameter.
72
73    --  ---------------------------------------------------------------------
74
75    --  MANPAGE(`form_field_validation.3x')
76
77    --  ANCHOR(`field_type()',`Get_Type')
78    function Get_Type (Fld : Field) return Field_Type_Access;
79    --  AKA
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
85
86    --  +----------------------------------------------------------------------
87    --  | Private Part.
88    --  | Most of this is used by the implementations of the child packages.
89    --  |
90 private
91    type Makearg_Function is access
92      function (Args : System.Address) return System.Address;
93    pragma Convention (C, Makearg_Function);
94
95    type Copyarg_Function is access
96      function (Usr : System.Address) return System.Address;
97    pragma Convention (C, Copyarg_Function);
98
99    type Freearg_Function is access
100      procedure (Usr : System.Address);
101    pragma Convention (C, Freearg_Function);
102
103    type Field_Check_Function is access
104      function (Fld : Field; Usr : System.Address) return Curses_Bool;
105    pragma Convention (C, Field_Check_Function);
106
107    type Char_Check_Function is access
108      function (Ch : C_Int; Usr : System.Address) return Curses_Bool;
109    pragma Convention (C, Char_Check_Function);
110
111    type Choice_Function is access
112      function (Fld : Field; Usr : System.Address) return Curses_Bool;
113    pragma Convention (C, Choice_Function);
114
115    --  +----------------------------------------------------------------------
116    --  | This must be in sync with the FIELDTYPE structure in form.h
117    --  |
118    type Low_Level_Field_Type is
119       record
120          Status :              Interfaces.C.unsigned_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;
129       end record;
130    pragma Convention (C, Low_Level_Field_Type);
131    type C_Field_Type is access all Low_Level_Field_Type;
132
133    Null_Field_Type   : constant C_Field_Type := null;
134
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.
139    --  |
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;
144
145    --  Two wrapper functions to access those low-level fieldtypes defined
146    --  in this package.
147    function C_Builtin_Router return C_Field_Type;
148    function C_Choice_Router  return C_Field_Type;
149
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.
160
161    function Make_Arg (Args : System.Address) return System.Address;
162    pragma Import (C, Make_Arg, "void_star_make_arg");
163    --  This is the Makearg_Function for the internal low-level types
164    --  introduced by this binding.
165
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.
170
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.
175
176    function Field_Check_Router (Fld : Field;
177                                 Usr : System.Address) return Curses_Bool;
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
182    --  function.
183
184    function Char_Check_Router (Ch : C_Int;
185                                Usr : System.Address) return Curses_Bool;
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
190    --  function.
191
192    function Next_Router (Fld : Field;
193                          Usr : System.Address) return Curses_Bool;
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
198    --  function.
199
200    function Prev_Router (Fld : Field;
201                          Usr : System.Address) return Curses_Bool;
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
206    --  function.
207
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
214    end record;
215    type Argument_Access is access all Argument;
216
217    --  +----------------------------------------------------------------------
218    --  |
219    --  | Some Imports of libform routines to deal with low-level fieldtypes.
220    --  |
221    function New_Fieldtype (Fcheck : Field_Check_Function;
222                            Ccheck : Char_Check_Function)
223      return C_Field_Type;
224    pragma Import (C, New_Fieldtype, "new_fieldtype");
225
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)
230      return C_Int;
231    pragma Import (C, Set_Fieldtype_Arg, "set_fieldtype_arg");
232
233    function Set_Fieldtype_Choice (Cft : C_Field_Type;
234                                   Next, Prev : Choice_Function)
235      return C_Int;
236    pragma Import (C, Set_Fieldtype_Choice, "set_fieldtype_choice");
237
238 end Terminal_Interface.Curses.Forms.Field_Types;