sample-menu_demo-aux.adb 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. ------------------------------------------------------------------------------
  2. -- --
  3. -- GNAT ncurses Binding Samples --
  4. -- --
  5. -- Sample.Menu_Demo.Aux --
  6. -- --
  7. -- B O D Y --
  8. -- --
  9. ------------------------------------------------------------------------------
  10. -- Copyright (c) 1998,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.13 $
  39. -- $Date: 2006/06/25 14:30:22 $
  40. -- Binding Version 01.00
  41. ------------------------------------------------------------------------------
  42. with Ada.Characters.Latin_1; use Ada.Characters.Latin_1;
  43. with Sample.Manifest; use Sample.Manifest;
  44. with Sample.Helpers; use Sample.Helpers;
  45. with Sample.Keyboard_Handler; use Sample.Keyboard_Handler;
  46. with Sample.Explanation; use Sample.Explanation;
  47. package body Sample.Menu_Demo.Aux is
  48. procedure Geometry (M : in Menu;
  49. L : out Line_Count;
  50. C : out Column_Count;
  51. Y : out Line_Position;
  52. X : out Column_Position;
  53. Fy : out Line_Position;
  54. Fx : out Column_Position);
  55. procedure Geometry (M : in Menu;
  56. L : out Line_Count; -- Lines used for menu
  57. C : out Column_Count; -- Columns used for menu
  58. Y : out Line_Position; -- Proposed Line for menu
  59. X : out Column_Position; -- Proposed Column for menu
  60. Fy : out Line_Position; -- Vertical inner frame
  61. Fx : out Column_Position) -- Horiz. inner frame
  62. is
  63. Spc_Desc : Column_Position; -- spaces between description and item
  64. begin
  65. Set_Mark (M, Menu_Marker);
  66. Spacing (M, Spc_Desc, Fy, Fx);
  67. Scale (M, L, C);
  68. Fx := Fx + Column_Position (Fy - 1); -- looks a bit nicer
  69. L := L + 2 * Fy; -- count for frame at top and bottom
  70. C := C + 2 * Fx; -- "
  71. -- Calculate horizontal coordinate at the screen center
  72. X := (Columns - C) / 2;
  73. Y := 1; -- always startin line 1
  74. end Geometry;
  75. procedure Geometry (M : in Menu;
  76. L : out Line_Count; -- Lines used for menu
  77. C : out Column_Count; -- Columns used for menu
  78. Y : out Line_Position; -- Proposed Line for menu
  79. X : out Column_Position) -- Proposed Column for menu
  80. is
  81. Fy : Line_Position;
  82. Fx : Column_Position;
  83. begin
  84. Geometry (M, L, C, Y, X, Fy, Fx);
  85. end Geometry;
  86. function Create (M : Menu;
  87. Title : String;
  88. Lin : Line_Position;
  89. Col : Column_Position) return Panel
  90. is
  91. W, S : Window;
  92. L : Line_Count;
  93. C : Column_Count;
  94. Y, Fy : Line_Position;
  95. X, Fx : Column_Position;
  96. Pan : Panel;
  97. begin
  98. Geometry (M, L, C, Y, X, Fy, Fx);
  99. W := New_Window (L, C, Lin, Col);
  100. Set_Meta_Mode (W);
  101. Set_KeyPad_Mode (W);
  102. if Has_Colors then
  103. Set_Background (Win => W,
  104. Ch => (Ch => ' ',
  105. Color => Menu_Back_Color,
  106. Attr => Normal_Video));
  107. Set_Foreground (Men => M, Color => Menu_Fore_Color);
  108. Set_Background (Men => M, Color => Menu_Back_Color);
  109. Set_Grey (Men => M, Color => Menu_Grey_Color);
  110. Erase (W);
  111. end if;
  112. S := Derived_Window (W, L - Fy, C - Fx, Fy, Fx);
  113. Set_Meta_Mode (S);
  114. Set_KeyPad_Mode (S);
  115. Box (W);
  116. Set_Window (M, W);
  117. Set_Sub_Window (M, S);
  118. if Title'Length > 0 then
  119. Window_Title (W, Title);
  120. end if;
  121. Pan := New_Panel (W);
  122. Post (M);
  123. return Pan;
  124. end Create;
  125. procedure Destroy (M : in Menu;
  126. P : in out Panel)
  127. is
  128. W, S : Window;
  129. begin
  130. W := Get_Window (M);
  131. S := Get_Sub_Window (M);
  132. Post (M, False);
  133. Erase (W);
  134. Delete (P);
  135. Set_Window (M, Null_Window);
  136. Set_Sub_Window (M, Null_Window);
  137. Delete (S);
  138. Delete (W);
  139. Update_Panels;
  140. end Destroy;
  141. function Get_Request (M : Menu; P : Panel) return Key_Code
  142. is
  143. W : constant Window := Get_Window (M);
  144. K : Real_Key_Code;
  145. Ch : Character;
  146. begin
  147. Top (P);
  148. loop
  149. K := Get_Key (W);
  150. if K in Special_Key_Code'Range then
  151. case K is
  152. when HELP_CODE => Explain_Context;
  153. when EXPLAIN_CODE => Explain ("MENUKEYS");
  154. when Key_Home => return REQ_FIRST_ITEM;
  155. when QUIT_CODE => return QUIT;
  156. when Key_Cursor_Down => return REQ_DOWN_ITEM;
  157. when Key_Cursor_Up => return REQ_UP_ITEM;
  158. when Key_Cursor_Left => return REQ_LEFT_ITEM;
  159. when Key_Cursor_Right => return REQ_RIGHT_ITEM;
  160. when Key_End => return REQ_LAST_ITEM;
  161. when Key_Backspace => return REQ_BACK_PATTERN;
  162. when Key_Next_Page => return REQ_SCR_DPAGE;
  163. when Key_Previous_Page => return REQ_SCR_UPAGE;
  164. when others => return K;
  165. end case;
  166. elsif K in Normal_Key_Code'Range then
  167. Ch := Character'Val (K);
  168. case Ch is
  169. when CAN => return QUIT; -- CTRL-X
  170. when SO => return REQ_NEXT_ITEM; -- CTRL-N
  171. when DLE => return REQ_PREV_ITEM; -- CTRL-P
  172. when NAK => return REQ_SCR_ULINE; -- CTRL-U
  173. when EOT => return REQ_SCR_DLINE; -- CTRL-D
  174. when ACK => return REQ_SCR_DPAGE; -- CTRL-F
  175. when STX => return REQ_SCR_UPAGE; -- CTRL-B
  176. when EM => return REQ_CLEAR_PATTERN; -- CTRL-Y
  177. when BS => return REQ_BACK_PATTERN; -- CTRL-H
  178. when SOH => return REQ_NEXT_MATCH; -- CTRL-A
  179. when ENQ => return REQ_PREV_MATCH; -- CTRL-E
  180. when DC4 => return REQ_TOGGLE_ITEM; -- CTRL-T
  181. when CR | LF => return SELECT_ITEM;
  182. when others => return K;
  183. end case;
  184. else
  185. return K;
  186. end if;
  187. end loop;
  188. end Get_Request;
  189. end Sample.Menu_Demo.Aux;