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