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