-- 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 Terminal_Interface.Curses.Aux; use Terminal_Interface.Curses.Aux;
with Interfaces.C; use Interfaces.C;
with Interfaces.C.Strings; use Interfaces.C.Strings;
-with Terminal_Interface.Curses;
+with Interfaces.C.Pointers;
-with Unchecked_Conversion;
+with Ada.Unchecked_Conversion;
package body Terminal_Interface.Curses.Menus is
+ type C_Item_Array is array (Natural range <>) of aliased Item;
+ package I_Array is new
+ Interfaces.C.Pointers (Natural, Item, C_Item_Array, Null_Item);
+
use type System.Bit_Order;
subtype chars_ptr is Interfaces.C.Strings.chars_ptr;
function MOS_2_CInt is new
- Unchecked_Conversion (Menu_Option_Set,
- C_Int);
+ Ada.Unchecked_Conversion (Menu_Option_Set,
+ C_Int);
function CInt_2_MOS is new
- Unchecked_Conversion (C_Int,
- Menu_Option_Set);
+ Ada.Unchecked_Conversion (C_Int,
+ Menu_Option_Set);
function IOS_2_CInt is new
- Unchecked_Conversion (Item_Option_Set,
- C_Int);
+ Ada.Unchecked_Conversion (Item_Option_Set,
+ C_Int);
function CInt_2_IOS is new
- Unchecked_Conversion (C_Int,
- Item_Option_Set);
+ Ada.Unchecked_Conversion (C_Int,
+ Item_Option_Set);
------------------------------------------------------------------------------
procedure Request_Name (Key : in Menu_Request_Code;
function Create (Name : String;
Description : String := "") return Item
is
- type Char_Ptr is access all Interfaces.C.Char;
+ type Char_Ptr is access all Interfaces.C.char;
function Newitem (Name, Desc : Char_Ptr) return Item;
pragma Import (C, Newitem, "new_item");
end if;
end Visible;
-------------------------------------------------------------------------------
- procedure Normalize_Item_Options (Options : in out C_Int);
- pragma Import (C, Normalize_Item_Options, "_nc_ada_normalize_item_opts");
-
procedure Set_Options (Itm : in Item;
Options : in Item_Option_Set)
is
Opt : C_Int := IOS_2_CInt (Options);
Res : Eti_Error;
begin
- Normalize_Item_Options (Opt);
Res := Set_Item_Opts (Itm, Opt);
if Res /= E_Ok then
Eti_Exception (Res);
Opt : C_Int := IOS_2_CInt (Options);
Err : Eti_Error;
begin
- Normalize_Item_Options (Opt);
if On then
Err := Item_Opts_On (Itm, Opt);
else
Res : C_Int := Item_Opts (Itm);
begin
- Normalize_Item_Options (Res);
Options := CInt_2_IOS (Res);
end Get_Options;
end if;
end Post;
-------------------------------------------------------------------------------
- procedure Normalize_Menu_Options (Options : in out C_Int);
- pragma Import (C, Normalize_Menu_Options, "_nc_ada_normalize_menu_opts");
-
procedure Set_Options (Men : in Menu;
Options : in Menu_Option_Set)
is
Opt : C_Int := MOS_2_CInt (Options);
Res : Eti_Error;
begin
- Normalize_Menu_Options (Opt);
Res := Set_Menu_Opts (Men, Opt);
if Res /= E_Ok then
Eti_Exception (Res);
Opt : C_Int := MOS_2_CInt (Options);
Err : Eti_Error;
begin
- Normalize_Menu_Options (Opt);
if On then
Err := Menu_Opts_On (Men, Opt);
else
Res : C_Int := Menu_Opts (Men);
begin
- Normalize_Menu_Options (Res);
Options := CInt_2_MOS (Res);
end Get_Options;
procedure Set_Mark (Men : in Menu;
Mark : in String)
is
- type Char_Ptr is access all Interfaces.C.Char;
+ type Char_Ptr is access all Interfaces.C.char;
function Set_Mark (Men : Menu;
Mark : Char_Ptr) return C_Int;
pragma Import (C, Set_Mark, "set_menu_mark");
Color : in Color_Pair := Color_Pair'First)
is
function Set_Menu_Fore (Men : Menu;
- Attr : C_Int) return C_Int;
+ Attr : C_Chtype) return C_Int;
pragma Import (C, Set_Menu_Fore, "set_menu_fore");
Ch : constant Attributed_Character := (Ch => Character'First,
Color => Color,
Attr => Fore);
- Res : constant Eti_Error := Set_Menu_Fore (Men, Chtype_To_CInt (Ch));
+ Res : constant Eti_Error := Set_Menu_Fore (Men, AttrChar_To_Chtype (Ch));
begin
if Res /= E_Ok then
Eti_Exception (Res);
procedure Foreground (Men : in Menu;
Fore : out Character_Attribute_Set)
is
- function Menu_Fore (Men : Menu) return C_Int;
+ function Menu_Fore (Men : Menu) return C_Chtype;
pragma Import (C, Menu_Fore, "menu_fore");
begin
- Fore := CInt_To_Chtype (Menu_Fore (Men)).Attr;
+ Fore := Chtype_To_AttrChar (Menu_Fore (Men)).Attr;
end Foreground;
procedure Foreground (Men : in Menu;
Fore : out Character_Attribute_Set;
Color : out Color_Pair)
is
- function Menu_Fore (Men : Menu) return C_Int;
+ function Menu_Fore (Men : Menu) return C_Chtype;
pragma Import (C, Menu_Fore, "menu_fore");
begin
- Fore := CInt_To_Chtype (Menu_Fore (Men)).Attr;
- Color := CInt_To_Chtype (Menu_Fore (Men)).Color;
+ Fore := Chtype_To_AttrChar (Menu_Fore (Men)).Attr;
+ Color := Chtype_To_AttrChar (Menu_Fore (Men)).Color;
end Foreground;
procedure Set_Background
Color : in Color_Pair := Color_Pair'First)
is
function Set_Menu_Back (Men : Menu;
- Attr : C_Int) return C_Int;
+ Attr : C_Chtype) return C_Int;
pragma Import (C, Set_Menu_Back, "set_menu_back");
Ch : constant Attributed_Character := (Ch => Character'First,
Color => Color,
Attr => Back);
- Res : constant Eti_Error := Set_Menu_Back (Men, Chtype_To_CInt (Ch));
+ Res : constant Eti_Error := Set_Menu_Back (Men, AttrChar_To_Chtype (Ch));
begin
if Res /= E_Ok then
Eti_Exception (Res);
procedure Background (Men : in Menu;
Back : out Character_Attribute_Set)
is
- function Menu_Back (Men : Menu) return C_Int;
+ function Menu_Back (Men : Menu) return C_Chtype;
pragma Import (C, Menu_Back, "menu_back");
begin
- Back := CInt_To_Chtype (Menu_Back (Men)).Attr;
+ Back := Chtype_To_AttrChar (Menu_Back (Men)).Attr;
end Background;
procedure Background (Men : in Menu;
Back : out Character_Attribute_Set;
Color : out Color_Pair)
is
- function Menu_Back (Men : Menu) return C_Int;
+ function Menu_Back (Men : Menu) return C_Chtype;
pragma Import (C, Menu_Back, "menu_back");
begin
- Back := CInt_To_Chtype (Menu_Back (Men)).Attr;
- Color := CInt_To_Chtype (Menu_Back (Men)).Color;
+ Back := Chtype_To_AttrChar (Menu_Back (Men)).Attr;
+ Color := Chtype_To_AttrChar (Menu_Back (Men)).Color;
end Background;
procedure Set_Grey (Men : in Menu;
Color : in Color_Pair := Color_Pair'First)
is
function Set_Menu_Grey (Men : Menu;
- Attr : C_Int) return C_Int;
+ Attr : C_Chtype) return C_Int;
pragma Import (C, Set_Menu_Grey, "set_menu_grey");
Ch : constant Attributed_Character := (Ch => Character'First,
Color => Color,
Attr => Grey);
- Res : constant Eti_Error := Set_Menu_Grey (Men, Chtype_To_CInt (Ch));
+ Res : constant Eti_Error := Set_Menu_Grey (Men, AttrChar_To_Chtype (Ch));
begin
if Res /= E_Ok then
Eti_Exception (Res);
procedure Grey (Men : in Menu;
Grey : out Character_Attribute_Set)
is
- function Menu_Grey (Men : Menu) return C_Int;
+ function Menu_Grey (Men : Menu) return C_Chtype;
pragma Import (C, Menu_Grey, "menu_grey");
begin
- Grey := CInt_To_Chtype (Menu_Grey (Men)).Attr;
+ Grey := Chtype_To_AttrChar (Menu_Grey (Men)).Attr;
end Grey;
procedure Grey (Men : in Menu;
Grey : out Character_Attribute_Set;
Color : out Color_Pair)
is
- function Menu_Grey (Men : Menu) return C_Int;
+ function Menu_Grey (Men : Menu) return C_Chtype;
pragma Import (C, Menu_Grey, "menu_grey");
begin
- Grey := CInt_To_Chtype (Menu_Grey (Men)).Attr;
- Color := CInt_To_Chtype (Menu_Grey (Men)).Color;
+ Grey := Chtype_To_AttrChar (Menu_Grey (Men)).Attr;
+ Color := Chtype_To_AttrChar (Menu_Grey (Men)).Color;
end Grey;
procedure Set_Pad_Character (Men : in Menu;
function Set_Pattern (Men : Menu;
Text : String) return Boolean
is
- type Char_Ptr is access all Interfaces.C.Char;
+ type Char_Ptr is access all Interfaces.C.char;
function Set_Pattern (Men : Menu;
Pattern : Char_Ptr) return C_Int;
pragma Import (C, Set_Pattern, "set_menu_pattern");
if Items (Items'Last) /= Null_Item then
raise Menu_Exception;
else
- Res := Set_Items (Men, Items (Items'First)'Address);
+ Res := Set_Items (Men, Items.all'Address);
if Res /= E_Ok then
Eti_Exception (Res);
end if;
function Items (Men : Menu;
Index : Positive) return Item
is
- function M_Items (Men : Menu;
- Idx : C_Int) return Item;
- pragma Import (C, M_Items, "_nc_get_item");
+ use I_Array;
+
+ function C_Mitems (Men : Menu) return Pointer;
+ pragma Import (C, C_Mitems, "menu_items");
+
+ P : Pointer := C_Mitems (Men);
begin
- if Men = Null_Menu or else Index not in 1 .. Item_Count (Men) then
+ if P = null or else Index not in 1 .. Item_Count (Men) then
raise Menu_Exception;
else
- return M_Items (Men, C_Int (Index) - 1);
+ P := P + ptrdiff_t (C_Int (Index) - 1);
+ return P.all;
end if;
end Items;
pragma Import (C, Newmenu, "new_menu");
M : Menu;
- I : Item_Array_Access;
begin
pragma Assert (Items (Items'Last) = Null_Item);
if Items (Items'Last) /= Null_Item then
raise Menu_Exception;
else
- M := Newmenu (Items (Items'First)'Address);
+ M := Newmenu (Items.all'Address);
if M = Null_Menu then
raise Menu_Exception;
end if;