]> ncurses.scripts.mit.edu Git - ncurses.git/blob - Ada95/ada_include/terminal_interface-curses-forms-field_user_data.adb
ncurses 4.1
[ncurses.git] / Ada95 / ada_include / terminal_interface-curses-forms-field_user_data.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                           GNAT ncurses Binding                           --
4 --                                                                          --
5 --               Terminal_Interface.Curses.Forms.Field_User_Data            --
6 --                                                                          --
7 --                                 B O D Y                                  --
8 --                                                                          --
9 --  Version 00.92                                                           --
10 --                                                                          --
11 --  The ncurses Ada95 binding is copyrighted 1996 by                        --
12 --  Juergen Pfeifer, Email: Juergen.Pfeifer@T-Online.de                     --
13 --                                                                          --
14 --  Permission is hereby granted to reproduce and distribute this           --
15 --  binding by any means and for any fee, whether alone or as part          --
16 --  of a larger distribution, in source or in binary form, PROVIDED         --
17 --  this notice is included with any such distribution, and is not          --
18 --  removed from any of its header files. Mention of ncurses and the        --
19 --  author of this binding in any applications linked with it is            --
20 --  highly appreciated.                                                     --
21 --                                                                          --
22 --  This binding comes AS IS with no warranty, implied or expressed.        --
23 ------------------------------------------------------------------------------
24 --  Version Control:
25 --  $Revision: 1.3 $
26 ------------------------------------------------------------------------------
27 with Unchecked_Conversion;
28 with Terminal_Interface.Curses.Aux;
29 use  Terminal_Interface.Curses.Aux;
30
31 --  |
32 --  |=====================================================================
33 --  | man page form_field_userptr.3x
34 --  |=====================================================================
35 --  |
36 package body Terminal_Interface.Curses.Forms.Field_User_Data is
37
38    function To_Address is new Unchecked_Conversion (User_Access,
39                                                     System.Address);
40    function To_Pointer is new Unchecked_Conversion (System.Address,
41                                                     User_Access);
42    --  |
43    --  |
44    --  |
45    procedure Set_User_Data (Fld  : in Field;
46                             Data : in User_Access)
47    is
48       A : constant Field_User_Wrapper_Access := Field_Userptr (Fld);
49       B : Field_User_Wrapper_Access;
50       R : C_Int;
51    begin
52       if A = null then
53          raise Form_Exception;
54       else
55          if A.N > 1 then
56             B := new Field_User_Wrapper'(T => A.T,
57                                          N => 1,
58                                          U => To_Address (Data));
59             R := Set_Field_Userptr (Fld, B);
60             A.N := A.N - 1;
61          else
62             A.U := To_Address (Data);
63          end if;
64       end if;
65    end Set_User_Data;
66    --  |
67    --  |
68    --  |
69    procedure Get_User_Data (Fld  : in  Field;
70                             Data : out User_Access)
71    is
72       A : constant Field_User_Wrapper_Access := Field_Userptr (Fld);
73    begin
74       if A = null then
75          raise Form_Exception;
76       else
77          Data := To_Pointer (A.U);
78       end if;
79    end Get_User_Data;
80    
81 end Terminal_Interface.Curses.Forms.Field_User_Data;