sample-curses_demo.adb 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. ------------------------------------------------------------------------------
  2. -- --
  3. -- GNAT ncurses Binding Samples --
  4. -- --
  5. -- Sample.Curses_Demo --
  6. -- --
  7. -- B O D Y --
  8. -- --
  9. ------------------------------------------------------------------------------
  10. -- Copyright (c) 1998,2004 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: 2004/08/21 21:37:00 $
  40. -- Binding Version 01.00
  41. ------------------------------------------------------------------------------
  42. with Terminal_Interface.Curses; use Terminal_Interface.Curses;
  43. with Terminal_Interface.Curses.Menus; use Terminal_Interface.Curses.Menus;
  44. with Terminal_Interface.Curses.Mouse; use Terminal_Interface.Curses.Mouse;
  45. with Terminal_Interface.Curses.Panels; use Terminal_Interface.Curses.Panels;
  46. with Terminal_Interface.Curses.Panels.User_Data;
  47. with Sample.Manifest; use Sample.Manifest;
  48. with Sample.Helpers; use Sample.Helpers;
  49. with Sample.Function_Key_Setting; use Sample.Function_Key_Setting;
  50. with Sample.Explanation; use Sample.Explanation;
  51. with Sample.Menu_Demo.Handler;
  52. with Sample.Curses_Demo.Mouse;
  53. with Sample.Curses_Demo.Attributes;
  54. package body Sample.Curses_Demo is
  55. type User_Data is new Integer;
  56. type User_Data_Access is access all User_Data;
  57. package PUD is new Panels.User_Data (User_Data, User_Data_Access);
  58. -- We use above instantiation of the generic User_Data package to
  59. -- demonstrate and test the use of the user data maechanism.
  60. procedure Demo
  61. is
  62. function My_Driver (M : Menu;
  63. K : Key_Code;
  64. Pan : Panel) return Boolean;
  65. package Mh is new Sample.Menu_Demo.Handler (My_Driver);
  66. Itm : Item_Array_Access := new Item_Array'
  67. (New_Item ("Attributes Demo"),
  68. New_Item ("Mouse Demo"),
  69. Null_Item);
  70. M : Menu := New_Menu (Itm);
  71. U1 : constant User_Data_Access := new User_Data'(4711);
  72. U2 : User_Data_Access;
  73. function My_Driver (M : Menu;
  74. K : Key_Code;
  75. Pan : Panel) return Boolean
  76. is
  77. Idx : constant Positive := Get_Index (Current (M));
  78. Result : Boolean := False;
  79. begin
  80. PUD.Set_User_Data (Pan, U1); -- set some user data, just for fun
  81. if K in User_Key_Code'Range then
  82. if K = QUIT then
  83. Result := True;
  84. elsif K = SELECT_ITEM then
  85. if Idx in Itm'Range then
  86. Hide (Pan);
  87. Update_Panels;
  88. end if;
  89. case Idx is
  90. when 1 => Sample.Curses_Demo.Attributes.Demo;
  91. when 2 => Sample.Curses_Demo.Mouse.Demo;
  92. when others => Not_Implemented;
  93. end case;
  94. if Idx in Itm'Range then
  95. Top (Pan);
  96. Show (Pan);
  97. Update_Panels;
  98. Update_Screen;
  99. end if;
  100. end if;
  101. end if;
  102. PUD.Get_User_Data (Pan, U2); -- get the user data
  103. pragma Assert (U1.all = U2.all and then U1 = U2);
  104. return Result;
  105. end My_Driver;
  106. begin
  107. if (1 + Item_Count (M)) /= Itm'Length then
  108. raise Constraint_Error;
  109. end if;
  110. if not Has_Mouse then
  111. declare
  112. O : Item_Option_Set;
  113. begin
  114. Get_Options (Itm (2), O);
  115. O.Selectable := False;
  116. Set_Options (Itm (2), O);
  117. end;
  118. end if;
  119. Push_Environment ("CURSES00");
  120. Notepad ("CURSES-PAD00");
  121. Default_Labels;
  122. Refresh_Soft_Label_Keys_Without_Update;
  123. Mh.Drive_Me (M, " Demo ");
  124. Pop_Environment;
  125. Delete (M);
  126. Free (Itm, True);
  127. end Demo;
  128. end Sample.Curses_Demo;