sample-form_demo.adb 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. ------------------------------------------------------------------------------
  2. -- --
  3. -- GNAT ncurses Binding Samples --
  4. -- --
  5. -- Sample.Form_Demo --
  6. -- --
  7. -- B O D Y --
  8. -- --
  9. ------------------------------------------------------------------------------
  10. -- Copyright (c) 1998-2004,2006 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, 1996
  37. -- Version Control
  38. -- $Revision: 1.15 $
  39. -- $Date: 2006/06/25 14:30:22 $
  40. -- Binding Version 01.00
  41. ------------------------------------------------------------------------------
  42. with Terminal_Interface.Curses; use Terminal_Interface.Curses;
  43. with Terminal_Interface.Curses.Forms; use Terminal_Interface.Curses.Forms;
  44. with Terminal_Interface.Curses.Forms.Field_User_Data;
  45. with Sample.My_Field_Type; use Sample.My_Field_Type;
  46. with Sample.Explanation; use Sample.Explanation;
  47. with Sample.Form_Demo.Aux; use Sample.Form_Demo.Aux;
  48. with Sample.Function_Key_Setting; use Sample.Function_Key_Setting;
  49. with Sample.Form_Demo.Handler;
  50. with Terminal_Interface.Curses.Forms.Field_Types.Enumeration.Ada;
  51. with Terminal_Interface.Curses.Forms.Field_Types.Enumeration;
  52. use Terminal_Interface.Curses.Forms.Field_Types.Enumeration;
  53. with Terminal_Interface.Curses.Forms.Field_Types.IntField;
  54. use Terminal_Interface.Curses.Forms.Field_Types.IntField;
  55. package body Sample.Form_Demo is
  56. type User_Data is
  57. record
  58. Data : Integer;
  59. end record;
  60. type User_Access is access User_Data;
  61. package Fld_U is new
  62. Terminal_Interface.Curses.Forms.Field_User_Data (User_Data,
  63. User_Access);
  64. type Weekday is (Sunday, Monday, Tuesday, Wednesday, Thursday,
  65. Friday, Saturday);
  66. package Weekday_Enum is new
  67. Terminal_Interface.Curses.Forms.Field_Types.Enumeration.Ada (Weekday);
  68. Enum_Field : constant Enumeration_Field :=
  69. Weekday_Enum.Create;
  70. procedure Demo
  71. is
  72. Mft : constant My_Data := (Ch => 'X');
  73. FA : Field_Array_Access := new Field_Array'
  74. (Make (0, 14, "Sample Entry Form"),
  75. Make (2, 0, "WeekdayEnumeration"),
  76. Make (2, 20, "Numeric 1-10"),
  77. Make (2, 34, "Only 'X'"),
  78. Make (5, 0, "Multiple Lines offscreen(Scroll)"),
  79. Make (Width => 18, Top => 3, Left => 0),
  80. Make (Width => 12, Top => 3, Left => 20),
  81. Make (Width => 12, Top => 3, Left => 34),
  82. Make (Width => 46, Top => 6, Left => 0, Height => 4, Off_Screen => 2),
  83. Null_Field
  84. );
  85. Frm : Terminal_Interface.Curses.Forms.Form := Create (FA);
  86. I_F : constant Integer_Field := (Precision => 0,
  87. Lower_Limit => 1,
  88. Upper_Limit => 10);
  89. F1, F2 : User_Access;
  90. package Fh is new Sample.Form_Demo.Handler (Default_Driver);
  91. begin
  92. Push_Environment ("FORM00");
  93. Notepad ("FORM-PAD00");
  94. Default_Labels;
  95. Set_Field_Type (FA (6), Enum_Field);
  96. Set_Field_Type (FA (7), I_F);
  97. Set_Field_Type (FA (8), Mft);
  98. F1 := new User_Data'(Data => 4711);
  99. Fld_U.Set_User_Data (FA (1), F1);
  100. Fh.Drive_Me (Frm);
  101. Fld_U.Get_User_Data (FA (1), F2);
  102. pragma Assert (F1 = F2);
  103. pragma Assert (F1.Data = F2.Data);
  104. Pop_Environment;
  105. Delete (Frm);
  106. Free (FA, True);
  107. end Demo;
  108. end Sample.Form_Demo;