• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1------------------------------------------------------------------------------
2--                                                                          --
3--                       GNAT ncurses Binding Samples                       --
4--                                                                          --
5--                             Sample.Form_Demo                             --
6--                                                                          --
7--                                 B O D Y                                  --
8--                                                                          --
9------------------------------------------------------------------------------
10-- Copyright 2020 Thomas E. Dickey                                          --
11-- Copyright 1998-2006,2011 Free Software Foundation, Inc.                  --
12--                                                                          --
13-- Permission is hereby granted, free of charge, to any person obtaining a  --
14-- copy of this software and associated documentation files (the            --
15-- "Software"), to deal in the Software without restriction, including      --
16-- without limitation the rights to use, copy, modify, merge, publish,      --
17-- distribute, distribute with modifications, sublicense, and/or sell       --
18-- copies of the Software, and to permit persons to whom the Software is    --
19-- furnished to do so, subject to the following conditions:                 --
20--                                                                          --
21-- The above copyright notice and this permission notice shall be included  --
22-- in all copies or substantial portions of the Software.                   --
23--                                                                          --
24-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  --
25-- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               --
26-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   --
27-- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   --
28-- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    --
29-- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    --
30-- THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               --
31--                                                                          --
32-- Except as contained in this notice, the name(s) of the above copyright   --
33-- holders shall not be used in advertising or otherwise to promote the     --
34-- sale, use or other dealings in this Software without prior written       --
35-- authorization.                                                           --
36------------------------------------------------------------------------------
37--  Author:  Juergen Pfeifer, 1996
38--  Version Control
39--  $Revision: 1.17 $
40--  $Date: 2020/02/02 23:34:34 $
41--  Binding Version 01.00
42------------------------------------------------------------------------------
43with Terminal_Interface.Curses; use Terminal_Interface.Curses;
44with Terminal_Interface.Curses.Forms; use Terminal_Interface.Curses.Forms;
45with Terminal_Interface.Curses.Forms.Field_User_Data;
46with Sample.My_Field_Type; use Sample.My_Field_Type;
47with Sample.Explanation; use Sample.Explanation;
48with Sample.Form_Demo.Aux; use Sample.Form_Demo.Aux;
49with Sample.Function_Key_Setting; use Sample.Function_Key_Setting;
50with Sample.Form_Demo.Handler;
51
52with Terminal_Interface.Curses.Forms.Field_Types.Enumeration.Ada;
53with Terminal_Interface.Curses.Forms.Field_Types.Enumeration;
54use  Terminal_Interface.Curses.Forms.Field_Types.Enumeration;
55with Terminal_Interface.Curses.Forms.Field_Types.IntField;
56use  Terminal_Interface.Curses.Forms.Field_Types.IntField;
57
58package body Sample.Form_Demo is
59
60   type User_Data is
61      record
62         Data : Integer;
63      end record;
64   type User_Access is access User_Data;
65
66   package Fld_U is new
67     Terminal_Interface.Curses.Forms.Field_User_Data (User_Data,
68                                                      User_Access);
69
70   type Weekday is (Sunday, Monday, Tuesday, Wednesday, Thursday,
71                    Friday, Saturday);
72
73   package Weekday_Enum is new
74     Terminal_Interface.Curses.Forms.Field_Types.Enumeration.Ada (Weekday);
75
76   Enum_Field : constant Enumeration_Field :=
77     Weekday_Enum.Create;
78
79   procedure Demo
80   is
81
82      Mft : constant My_Data := (Ch => 'X');
83
84      FA : Field_Array_Access := new Field_Array'
85        (Make (0, 14, "Sample Entry Form"),
86         Make (2, 0,  "WeekdayEnumeration"),
87         Make (2, 20, "Numeric 1-10"),
88         Make (2, 34, "Only 'X'"),
89         Make (5, 0, "Multiple Lines offscreen(Scroll)"),
90         Make (Width => 18, Top => 3, Left =>  0),
91         Make (Width => 12, Top => 3, Left => 20),
92         Make (Width => 12, Top => 3, Left => 34),
93         Make (Width => 46, Top => 6, Left => 0, Height => 4, Off_Screen => 2),
94         Null_Field
95         );
96
97      Frm : Terminal_Interface.Curses.Forms.Form := Create (FA);
98
99      I_F : constant Integer_Field := (Precision   => 0,
100                                       Lower_Limit => 1,
101                                       Upper_Limit => 10);
102
103      F1, F2 : User_Access;
104
105      package Fh is new Sample.Form_Demo.Handler (Default_Driver);
106
107   begin
108      Push_Environment ("FORM00");
109      Notepad ("FORM-PAD00");
110      Default_Labels;
111
112      Set_Field_Type (FA.all (6), Enum_Field);
113      Set_Field_Type (FA.all (7), I_F);
114      Set_Field_Type (FA.all (8), Mft);
115
116      F1 := new User_Data'(Data => 4711);
117      Fld_U.Set_User_Data (FA.all (1), F1);
118
119      Fh.Drive_Me (Frm);
120
121      Fld_U.Get_User_Data (FA.all (1), F2);
122      pragma Assert (F1 = F2);
123      pragma Assert (F1.Data = F2.Data);
124
125      Pop_Environment;
126      Delete (Frm);
127
128      Free (FA, True);
129   end Demo;
130
131end Sample.Form_Demo;
132