File : terminal_interface-curses-forms-field_types-user.adb
with System.Address_To_Access_Conversions;
with Terminal_Interface.Curses.Aux; use Terminal_Interface.Curses.Aux;
package body Terminal_Interface.Curses.Forms.Field_Types.User is
procedure Set_Field_Type (Fld : Field;
Typ : User_Defined_Field_Type)
is
function Allocate_Arg (T : User_Defined_Field_Type'Class)
return Argument_Access;
function Set_Fld_Type (F : Field := Fld;
Cft : C_Field_Type := C_Generic_Type;
Arg1 : Argument_Access)
return Eti_Error;
pragma Import (C, Set_Fld_Type, "set_field_type_user");
function Allocate_Arg (T : User_Defined_Field_Type'Class)
return Argument_Access
is
Ptr : constant Field_Type_Access
:= new User_Defined_Field_Type'Class'(T);
begin
return new Argument'(Usr => System.Null_Address,
Typ => Ptr,
Cft => Null_Field_Type);
end Allocate_Arg;
begin
Eti_Exception (Set_Fld_Type (Arg1 => Allocate_Arg (Typ)));
end Set_Field_Type;
package Argument_Conversions is
new System.Address_To_Access_Conversions (Argument);
function Generic_Field_Check (Fld : Field;
Usr : System.Address) return Curses_Bool
is
Result : Boolean;
Udf : constant User_Defined_Field_Type_Access :=
User_Defined_Field_Type_Access
(Argument_Access (Argument_Conversions.To_Pointer (Usr)).all.Typ);
begin
Result := Field_Check (Fld, Udf.all);
return Curses_Bool (Boolean'Pos (Result));
end Generic_Field_Check;
function Generic_Char_Check (Ch : C_Int;
Usr : System.Address) return Curses_Bool
is
Result : Boolean;
Udf : constant User_Defined_Field_Type_Access :=
User_Defined_Field_Type_Access
(Argument_Access (Argument_Conversions.To_Pointer (Usr)).all.Typ);
begin
Result := Character_Check (Character'Val (Ch), Udf.all);
return Curses_Bool (Boolean'Pos (Result));
end Generic_Char_Check;
function C_Generic_Type return C_Field_Type
is
Res : Eti_Error;
T : C_Field_Type;
begin
if M_Generic_Type = Null_Field_Type then
T := New_Fieldtype (Generic_Field_Check'Access,
Generic_Char_Check'Access);
if T = Null_Field_Type then
raise Form_Exception;
else
Res := Set_Fieldtype_Arg (T,
Make_Arg'Access,
Copy_Arg'Access,
Free_Arg'Access);
Eti_Exception (Res);
end if;
M_Generic_Type := T;
end if;
pragma Assert (M_Generic_Type /= Null_Field_Type);
return M_Generic_Type;
end C_Generic_Type;
end Terminal_Interface.Curses.Forms.Field_Types.User;