]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - Ada95/src/terminal_interface-curses-forms.adb
ncurses 5.0
[ncurses.git] / Ada95 / src / terminal_interface-curses-forms.adb
similarity index 94%
rename from Ada95/ada_include/terminal_interface-curses-forms.adb
rename to Ada95/src/terminal_interface-curses-forms.adb
index fbb43b7f81e665f1fcc716675cd15162493ff829..669ac5f3415b73347b2d8bc94df4896dcb5000a2 100644 (file)
 -- sale, use or other dealings in this Software without prior written       --
 -- authorization.                                                           --
 ------------------------------------------------------------------------------
---  Author: Juergen Pfeifer <Juergen.Pfeifer@T-Online.de> 1996
+--  Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1996
 --  Version Control:
---  $Revision: 1.13 $
---  Binding Version 00.93
+--  $Revision: 1.20 $
+--  Binding Version 01.00
 ------------------------------------------------------------------------------
 with Ada.Unchecked_Deallocation;
-with Unchecked_Conversion;
+with Ada.Unchecked_Conversion;
 
 with Interfaces.C; use Interfaces.C;
 with Interfaces.C.Strings; use Interfaces.C.Strings;
+with Interfaces.C.Pointers;
 
-with Terminal_Interface.Curses.Aux; use Terminal_Interface.Curses.Aux;
+with Terminal_Interface.Curses.Aux;
 
 package body Terminal_Interface.Curses.Forms is
 
+   use Terminal_Interface.Curses.Aux;
+
+   type C_Field_Array is array (Natural range <>) of aliased Field;
+   package F_Array is new
+     Interfaces.C.Pointers (Natural, Field, C_Field_Array, Null_Field);
+
 ------------------------------------------------------------------------------
    --  |
    --  |
@@ -55,20 +62,20 @@ package body Terminal_Interface.Curses.Forms is
    --  subtype chars_ptr is Interfaces.C.Strings.chars_ptr;
 
    function FOS_2_CInt is new
-     Unchecked_Conversion (Field_Option_Set,
-                           C_Int);
+     Ada.Unchecked_Conversion (Field_Option_Set,
+                               C_Int);
 
    function CInt_2_FOS is new
-     Unchecked_Conversion (C_Int,
-                           Field_Option_Set);
+     Ada.Unchecked_Conversion (C_Int,
+                               Field_Option_Set);
 
    function FrmOS_2_CInt is new
-     Unchecked_Conversion (Form_Option_Set,
-                           C_Int);
+     Ada.Unchecked_Conversion (Form_Option_Set,
+                               C_Int);
 
    function CInt_2_FrmOS is new
-     Unchecked_Conversion (C_Int,
-                           Form_Option_Set);
+     Ada.Unchecked_Conversion (C_Int,
+                               Form_Option_Set);
 
    procedure Request_Name (Key  : in Form_Request_Code;
                                 Name : out String)
@@ -219,7 +226,7 @@ package body Terminal_Interface.Curses.Forms is
       Buffer : in Buffer_Number := Buffer_Number'First;
       Str    : in String)
    is
-      type Char_Ptr is access all Interfaces.C.Char;
+      type Char_Ptr is access all Interfaces.C.char;
       function Set_Fld_Buffer (Fld    : Field;
                                  Bufnum : C_Int;
                                  S      : Char_Ptr)
@@ -316,9 +323,6 @@ package body Terminal_Interface.Curses.Forms is
    --  |
    --  |
    --  |
-   procedure Normalize_Field_Options (Options : in out C_Int);
-   pragma Import (C, Normalize_Field_Options, "_nc_ada_normalize_field_opts");
-
    procedure Set_Options (Fld     : in Field;
                           Options : in Field_Option_Set)
    is
@@ -329,7 +333,6 @@ package body Terminal_Interface.Curses.Forms is
       Opt : C_Int := FOS_2_CInt (Options);
       Res : Eti_Error;
    begin
-      Normalize_Field_Options (Opt);
       Res := Set_Field_Opts (Fld, Opt);
       if Res /= E_Ok then
          Eti_Exception (Res);
@@ -352,7 +355,6 @@ package body Terminal_Interface.Curses.Forms is
       Err : Eti_Error;
       Opt : C_Int := FOS_2_CInt (Options);
    begin
-      Normalize_Field_Options (Opt);
       if On then
          Err := Field_Opts_On (Fld, Opt);
       else
@@ -373,7 +375,6 @@ package body Terminal_Interface.Curses.Forms is
 
       Res : C_Int := Field_Opts (Fld);
    begin
-      Normalize_Field_Options (Res);
       Options := CInt_2_FOS (Res);
    end Get_Options;
    --  |
@@ -400,13 +401,14 @@ package body Terminal_Interface.Curses.Forms is
       Color : in Color_Pair := Color_Pair'First)
    is
       function Set_Field_Fore (Fld  : Field;
-                               Attr : C_Int) return C_Int;
+                               Attr : C_Chtype) return C_Int;
       pragma Import (C, Set_Field_Fore, "set_field_fore");
 
       Ch : constant Attributed_Character := (Ch    => Character'First,
                                              Color => Color,
                                              Attr  => Fore);
-      Res : constant Eti_Error := Set_Field_Fore (Fld, Chtype_To_CInt (Ch));
+      Res : constant Eti_Error :=
+        Set_Field_Fore (Fld, AttrChar_To_Chtype (Ch));
    begin
       if  Res /= E_Ok then
          Eti_Exception (Res);
@@ -418,21 +420,21 @@ package body Terminal_Interface.Curses.Forms is
    procedure Foreground (Fld  : in  Field;
                          Fore : out Character_Attribute_Set)
    is
-      function Field_Fore (Fld : Field) return C_Int;
+      function Field_Fore (Fld : Field) return C_Chtype;
       pragma Import (C, Field_Fore, "field_fore");
    begin
-      Fore := CInt_To_Chtype (Field_Fore (Fld)).Attr;
+      Fore := Chtype_To_AttrChar (Field_Fore (Fld)).Attr;
    end Foreground;
 
    procedure Foreground (Fld   : in  Field;
                          Fore  : out Character_Attribute_Set;
                          Color : out Color_Pair)
    is
-      function Field_Fore (Fld : Field) return C_Int;
+      function Field_Fore (Fld : Field) return C_Chtype;
       pragma Import (C, Field_Fore, "field_fore");
    begin
-      Fore  := CInt_To_Chtype (Field_Fore (Fld)).Attr;
-      Color := CInt_To_Chtype (Field_Fore (Fld)).Color;
+      Fore  := Chtype_To_AttrChar (Field_Fore (Fld)).Attr;
+      Color := Chtype_To_AttrChar (Field_Fore (Fld)).Color;
    end Foreground;
    --  |
    --  |
@@ -443,13 +445,14 @@ package body Terminal_Interface.Curses.Forms is
       Color : in Color_Pair := Color_Pair'First)
    is
       function Set_Field_Back (Fld  : Field;
-                               Attr : C_Int) return C_Int;
+                               Attr : C_Chtype) return C_Int;
       pragma Import (C, Set_Field_Back, "set_field_back");
 
       Ch : constant Attributed_Character := (Ch    => Character'First,
                                              Color => Color,
                                              Attr  => Back);
-      Res : constant Eti_Error := Set_Field_Back (Fld, Chtype_To_CInt (Ch));
+      Res : constant Eti_Error :=
+        Set_Field_Back (Fld, AttrChar_To_Chtype (Ch));
    begin
       if  Res /= E_Ok then
          Eti_Exception (Res);
@@ -461,21 +464,21 @@ package body Terminal_Interface.Curses.Forms is
    procedure Background (Fld  : in  Field;
                          Back : out Character_Attribute_Set)
    is
-      function Field_Back (Fld : Field) return C_Int;
+      function Field_Back (Fld : Field) return C_Chtype;
       pragma Import (C, Field_Back, "field_back");
    begin
-      Back := CInt_To_Chtype (Field_Back (Fld)).Attr;
+      Back := Chtype_To_AttrChar (Field_Back (Fld)).Attr;
    end Background;
 
    procedure Background (Fld   : in  Field;
                          Back  : out Character_Attribute_Set;
                          Color : out Color_Pair)
    is
-      function Field_Back (Fld : Field) return C_Int;
+      function Field_Back (Fld : Field) return C_Chtype;
       pragma Import (C, Field_Back, "field_back");
    begin
-      Back  := CInt_To_Chtype (Field_Back (Fld)).Attr;
-      Color := CInt_To_Chtype (Field_Back (Fld)).Color;
+      Back  := Chtype_To_AttrChar (Field_Back (Fld)).Attr;
+      Color := Chtype_To_AttrChar (Field_Back (Fld)).Color;
    end Background;
    --  |
    --  |
@@ -748,14 +751,18 @@ package body Terminal_Interface.Curses.Forms is
    function Fields (Frm   : Form;
                     Index : Positive) return Field
    is
-      function F_Fields (Frm : Form;
-                         Idx : C_Int) return Field;
-      pragma Import (C, F_Fields, "_nc_get_field");
+      use F_Array;
+
+      function C_Fields (Frm : Form) return Pointer;
+      pragma Import (C, C_Fields, "form_fields");
+
+      P : Pointer := C_Fields (Frm);
    begin
-      if Frm = Null_Form or else Index not in 1 .. Field_Count (Frm) then
+      if P = null or else Index not in 1 .. Field_Count (Frm) then
          raise Form_Exception;
       else
-         return F_Fields (Frm, C_Int (Index) - 1);
+         P := P + ptrdiff_t (C_Int (Index) - 1);
+         return P.all;
       end if;
    end Fields;
    --  |
@@ -831,9 +838,6 @@ package body Terminal_Interface.Curses.Forms is
    --  |
    --  |
    --  |
-   procedure Normalize_Form_Options (Options : in out C_Int);
-   pragma Import (C, Normalize_Form_Options, "_nc_ada_normalize_form_opts");
-
    procedure Set_Options (Frm     : in Form;
                           Options : in Form_Option_Set)
    is
@@ -844,7 +848,6 @@ package body Terminal_Interface.Curses.Forms is
       Opt : C_Int := FrmOS_2_CInt (Options);
       Res : Eti_Error;
    begin
-      Normalize_Form_Options (Opt);
       Res := Set_Form_Opts (Frm, Opt);
       if  Res /= E_Ok then
          Eti_Exception (Res);
@@ -867,7 +870,6 @@ package body Terminal_Interface.Curses.Forms is
       Err : Eti_Error;
       Opt : C_Int := FrmOS_2_CInt (Options);
    begin
-      Normalize_Form_Options (Opt);
       if On then
          Err := Form_Opts_On (Frm, Opt);
       else
@@ -888,7 +890,6 @@ package body Terminal_Interface.Curses.Forms is
 
       Res : C_Int := Form_Opts (Frm);
    begin
-      Normalize_Form_Options (Res);
       Options := CInt_2_FrmOS (Res);
    end Get_Options;
    --  |