sample-menu_demo-handler.adb 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. ------------------------------------------------------------------------------
  2. -- --
  3. -- GNAT ncurses Binding Samples --
  4. -- --
  5. -- Sample.Menu_Demo.Handler --
  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 Sample.Menu_Demo.Aux;
  43. with Sample.Manifest; use Sample.Manifest;
  44. with Terminal_Interface.Curses.Mouse; use Terminal_Interface.Curses.Mouse;
  45. package body Sample.Menu_Demo.Handler is
  46. package Aux renames Sample.Menu_Demo.Aux;
  47. procedure Drive_Me (M : in Menu;
  48. Title : in String := "")
  49. is
  50. L : Line_Count;
  51. C : Column_Count;
  52. Y : Line_Position;
  53. X : Column_Position;
  54. begin
  55. Aux.Geometry (M, L, C, Y, X);
  56. Drive_Me (M, Y, X, Title);
  57. end Drive_Me;
  58. procedure Drive_Me (M : in Menu;
  59. Lin : in Line_Position;
  60. Col : in Column_Position;
  61. Title : in String := "")
  62. is
  63. Mask : Event_Mask := No_Events;
  64. Old : Event_Mask;
  65. Pan : Panel := Aux.Create (M, Title, Lin, Col);
  66. V : Cursor_Visibility := Invisible;
  67. begin
  68. -- We are only interested in Clicks with the left button
  69. Register_Reportable_Events (Left, All_Clicks, Mask);
  70. Old := Start_Mouse (Mask);
  71. Set_Cursor_Visibility (V);
  72. loop
  73. declare
  74. K : Key_Code := Aux.Get_Request (M, Pan);
  75. R : constant Driver_Result := Driver (M, K);
  76. begin
  77. case R is
  78. when Menu_Ok => null;
  79. when Unknown_Request =>
  80. declare
  81. I : constant Item := Current (M);
  82. O : Item_Option_Set;
  83. begin
  84. if K = Key_Mouse then
  85. K := SELECT_ITEM;
  86. end if;
  87. Get_Options (I, O);
  88. if K = SELECT_ITEM and then not O.Selectable then
  89. Beep;
  90. else
  91. if My_Driver (M, K, Pan) then
  92. exit;
  93. end if;
  94. end if;
  95. end;
  96. when others => Beep;
  97. end case;
  98. end;
  99. end loop;
  100. End_Mouse (Old);
  101. Aux.Destroy (M, Pan);
  102. end Drive_Me;
  103. end Sample.Menu_Demo.Handler;