]> ncurses.scripts.mit.edu Git - ncurses.git/blob - Ada95/gen/terminal_interface-curses.adb.m4
ncurses 5.8 - patch 20110319
[ncurses.git] / Ada95 / gen / terminal_interface-curses.adb.m4
1 --  -*- ada -*-
2 define(`HTMLNAME',`terminal_interface-curses__adb.htm')dnl
3 include(M4MACRO)------------------------------------------------------------------------------
4 --                                                                          --
5 --                           GNAT ncurses Binding                           --
6 --                                                                          --
7 --                        Terminal_Interface.Curses                         --
8 --                                                                          --
9 --                                 B O D Y                                  --
10 --                                                                          --
11 ------------------------------------------------------------------------------
12 -- Copyright (c) 1998-2009,2011 Free Software Foundation, Inc.              --
13 --                                                                          --
14 -- Permission is hereby granted, free of charge, to any person obtaining a  --
15 -- copy of this software and associated documentation files (the            --
16 -- "Software"), to deal in the Software without restriction, including      --
17 -- without limitation the rights to use, copy, modify, merge, publish,      --
18 -- distribute, distribute with modifications, sublicense, and/or sell       --
19 -- copies of the Software, and to permit persons to whom the Software is    --
20 -- furnished to do so, subject to the following conditions:                 --
21 --                                                                          --
22 -- The above copyright notice and this permission notice shall be included  --
23 -- in all copies or substantial portions of the Software.                   --
24 --                                                                          --
25 -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  --
26 -- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               --
27 -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   --
28 -- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   --
29 -- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    --
30 -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    --
31 -- THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               --
32 --                                                                          --
33 -- Except as contained in this notice, the name(s) of the above copyright   --
34 -- holders shall not be used in advertising or otherwise to promote the     --
35 -- sale, use or other dealings in this Software without prior written       --
36 -- authorization.                                                           --
37 ------------------------------------------------------------------------------
38 --  Author: Juergen Pfeifer, 1996
39 --  Version Control:
40 --  $Revision: 1.7 $
41 --  $Date: 2011/03/19 16:17:19 $
42 --  Binding Version 01.00
43 ------------------------------------------------------------------------------
44 with System;
45
46 with Terminal_Interface.Curses.Aux;
47 with Interfaces.C;                  use Interfaces.C;
48 with Interfaces.C.Strings;          use Interfaces.C.Strings;
49 with Ada.Characters.Handling;       use Ada.Characters.Handling;
50 with Ada.Strings.Fixed;
51
52 package body Terminal_Interface.Curses is
53
54    use Aux;
55    use type System.Bit_Order;
56
57    package ASF renames Ada.Strings.Fixed;
58
59    type chtype_array is array (size_t range <>)
60       of aliased Attributed_Character;
61    pragma Convention (C, chtype_array);
62
63 ------------------------------------------------------------------------------
64    function Key_Name (Key : Real_Key_Code) return String
65    is
66       function Keyname (K : C_Int) return chars_ptr;
67       pragma Import (C, Keyname, "keyname");
68
69       Ch : Character;
70    begin
71       if Key <= Character'Pos (Character'Last) then
72          Ch := Character'Val (Key);
73          if Is_Control (Ch) then
74             return Un_Control (Attributed_Character'(Ch    => Ch,
75                                                      Color => Color_Pair'First,
76                                                      Attr  => Normal_Video));
77          elsif Is_Graphic (Ch) then
78             declare
79                S : String (1 .. 1);
80             begin
81                S (1) := Ch;
82                return S;
83             end;
84          else
85             return "";
86          end if;
87       else
88          return Fill_String (Keyname (C_Int (Key)));
89       end if;
90    end Key_Name;
91
92    procedure Key_Name (Key  :  Real_Key_Code;
93                        Name : out String)
94    is
95    begin
96       ASF.Move (Key_Name (Key), Name);
97    end Key_Name;
98
99 ------------------------------------------------------------------------------
100    procedure Init_Screen
101    is
102       function Initscr return Window;
103       pragma Import (C, Initscr, "initscr");
104
105       W : Window;
106    begin
107       W := Initscr;
108       if W = Null_Window then
109          raise Curses_Exception;
110       end if;
111    end Init_Screen;
112
113    procedure End_Windows
114    is
115       function Endwin return C_Int;
116       pragma Import (C, Endwin, "endwin");
117    begin
118       if Endwin = Curses_Err then
119          raise Curses_Exception;
120       end if;
121    end End_Windows;
122
123    function Is_End_Window return Boolean
124    is
125       function Isendwin return Curses_Bool;
126       pragma Import (C, Isendwin, "isendwin");
127    begin
128       if Isendwin = Curses_Bool_False then
129          return False;
130       else
131          return True;
132       end if;
133    end Is_End_Window;
134 ------------------------------------------------------------------------------
135    procedure Move_Cursor (Win    : Window := Standard_Window;
136                           Line   : Line_Position;
137                           Column : Column_Position)
138    is
139       function Wmove (Win    : Window;
140                       Line   : C_Int;
141                       Column : C_Int
142                      ) return C_Int;
143       pragma Import (C, Wmove, "wmove");
144    begin
145       if Wmove (Win, C_Int (Line), C_Int (Column)) = Curses_Err then
146          raise Curses_Exception;
147       end if;
148    end Move_Cursor;
149 ------------------------------------------------------------------------------
150    procedure Add (Win : Window := Standard_Window;
151                   Ch  : Attributed_Character)
152    is
153       function Waddch (W  : Window;
154                        Ch : C_Chtype) return C_Int;
155       pragma Import (C, Waddch, "waddch");
156    begin
157       if Waddch (Win, AttrChar_To_Chtype (Ch)) = Curses_Err then
158          raise Curses_Exception;
159       end if;
160    end Add;
161
162    procedure Add (Win : Window := Standard_Window;
163                   Ch  : Character)
164    is
165    begin
166       Add (Win,
167            Attributed_Character'(Ch    => Ch,
168                                  Color => Color_Pair'First,
169                                  Attr  => Normal_Video));
170    end Add;
171
172    procedure Add
173      (Win    : Window := Standard_Window;
174       Line   : Line_Position;
175       Column : Column_Position;
176       Ch     : Attributed_Character)
177    is
178       function mvwaddch (W  : Window;
179                          Y  : C_Int;
180                          X  : C_Int;
181                          Ch : C_Chtype) return C_Int;
182       pragma Import (C, mvwaddch, "mvwaddch");
183    begin
184       if mvwaddch (Win, C_Int (Line),
185                    C_Int (Column),
186                    AttrChar_To_Chtype (Ch)) = Curses_Err then
187          raise Curses_Exception;
188       end if;
189    end Add;
190
191    procedure Add
192      (Win    : Window := Standard_Window;
193       Line   : Line_Position;
194       Column : Column_Position;
195       Ch     : Character)
196    is
197    begin
198       Add (Win,
199            Line,
200            Column,
201            Attributed_Character'(Ch    => Ch,
202                                  Color => Color_Pair'First,
203                                  Attr  => Normal_Video));
204    end Add;
205
206    procedure Add_With_Immediate_Echo
207      (Win : Window := Standard_Window;
208       Ch  : Attributed_Character)
209    is
210       function Wechochar (W  : Window;
211                           Ch : C_Chtype) return C_Int;
212       pragma Import (C, Wechochar, "wechochar");
213    begin
214       if Wechochar (Win, AttrChar_To_Chtype (Ch)) = Curses_Err then
215          raise Curses_Exception;
216       end if;
217    end Add_With_Immediate_Echo;
218
219    procedure Add_With_Immediate_Echo
220      (Win : Window := Standard_Window;
221       Ch  : Character)
222    is
223    begin
224       Add_With_Immediate_Echo
225         (Win,
226          Attributed_Character'(Ch    => Ch,
227                                Color => Color_Pair'First,
228                                Attr  => Normal_Video));
229    end Add_With_Immediate_Echo;
230 ------------------------------------------------------------------------------
231    function Create (Number_Of_Lines       : Line_Count;
232                     Number_Of_Columns     : Column_Count;
233                     First_Line_Position   : Line_Position;
234                     First_Column_Position : Column_Position) return Window
235    is
236       function Newwin (Number_Of_Lines       : C_Int;
237                        Number_Of_Columns     : C_Int;
238                        First_Line_Position   : C_Int;
239                        First_Column_Position : C_Int) return Window;
240       pragma Import (C, Newwin, "newwin");
241
242       W : Window;
243    begin
244       W := Newwin (C_Int (Number_Of_Lines),
245                    C_Int (Number_Of_Columns),
246                    C_Int (First_Line_Position),
247                    C_Int (First_Column_Position));
248       if W = Null_Window then
249          raise Curses_Exception;
250       end if;
251       return W;
252    end Create;
253
254    procedure Delete (Win : in out Window)
255    is
256       function Wdelwin (W : Window) return C_Int;
257       pragma Import (C, Wdelwin, "delwin");
258    begin
259       if Wdelwin (Win) = Curses_Err then
260          raise Curses_Exception;
261       end if;
262       Win := Null_Window;
263    end Delete;
264
265    function Sub_Window
266      (Win                   : Window := Standard_Window;
267       Number_Of_Lines       : Line_Count;
268       Number_Of_Columns     : Column_Count;
269       First_Line_Position   : Line_Position;
270       First_Column_Position : Column_Position) return Window
271    is
272       function Subwin
273         (Win                   : Window;
274          Number_Of_Lines       : C_Int;
275          Number_Of_Columns     : C_Int;
276          First_Line_Position   : C_Int;
277          First_Column_Position : C_Int) return Window;
278       pragma Import (C, Subwin, "subwin");
279
280       W : Window;
281    begin
282       W := Subwin (Win,
283                    C_Int (Number_Of_Lines),
284                    C_Int (Number_Of_Columns),
285                    C_Int (First_Line_Position),
286                    C_Int (First_Column_Position));
287       if W = Null_Window then
288          raise Curses_Exception;
289       end if;
290       return W;
291    end Sub_Window;
292
293    function Derived_Window
294      (Win                   : Window := Standard_Window;
295       Number_Of_Lines       : Line_Count;
296       Number_Of_Columns     : Column_Count;
297       First_Line_Position   : Line_Position;
298       First_Column_Position : Column_Position) return Window
299    is
300       function Derwin
301         (Win                   : Window;
302          Number_Of_Lines       : C_Int;
303          Number_Of_Columns     : C_Int;
304          First_Line_Position   : C_Int;
305          First_Column_Position : C_Int) return Window;
306       pragma Import (C, Derwin, "derwin");
307
308       W : Window;
309    begin
310       W := Derwin (Win,
311                    C_Int (Number_Of_Lines),
312                    C_Int (Number_Of_Columns),
313                    C_Int (First_Line_Position),
314                    C_Int (First_Column_Position));
315       if W = Null_Window then
316          raise Curses_Exception;
317       end if;
318       return W;
319    end Derived_Window;
320
321    function Duplicate (Win : Window) return Window
322    is
323       function Dupwin (Win : Window) return Window;
324       pragma Import (C, Dupwin, "dupwin");
325
326       W : constant Window := Dupwin (Win);
327    begin
328       if W = Null_Window then
329          raise Curses_Exception;
330       end if;
331       return W;
332    end Duplicate;
333
334    procedure Move_Window (Win    : Window;
335                           Line   : Line_Position;
336                           Column : Column_Position)
337    is
338       function Mvwin (Win    : Window;
339                       Line   : C_Int;
340                       Column : C_Int) return C_Int;
341       pragma Import (C, Mvwin, "mvwin");
342    begin
343       if Mvwin (Win, C_Int (Line), C_Int (Column)) = Curses_Err then
344          raise Curses_Exception;
345       end if;
346    end Move_Window;
347
348    procedure Move_Derived_Window (Win    : Window;
349                                   Line   : Line_Position;
350                                   Column : Column_Position)
351    is
352       function Mvderwin (Win    : Window;
353                          Line   : C_Int;
354                          Column : C_Int) return C_Int;
355       pragma Import (C, Mvderwin, "mvderwin");
356    begin
357       if Mvderwin (Win, C_Int (Line), C_Int (Column)) = Curses_Err then
358          raise Curses_Exception;
359       end if;
360    end Move_Derived_Window;
361
362    procedure Set_Synch_Mode (Win  : Window  := Standard_Window;
363                              Mode : Boolean := False)
364    is
365       function Syncok (Win  : Window;
366                        Mode : Curses_Bool) return C_Int;
367       pragma Import (C, Syncok, "syncok");
368    begin
369       if Syncok (Win, Curses_Bool (Boolean'Pos (Mode))) = Curses_Err then
370          raise Curses_Exception;
371       end if;
372    end Set_Synch_Mode;
373 ------------------------------------------------------------------------------
374    procedure Add (Win : Window := Standard_Window;
375                   Str : String;
376                   Len : Integer := -1)
377    is
378       function Waddnstr (Win : Window;
379                          Str : char_array;
380                          Len : C_Int := -1) return C_Int;
381       pragma Import (C, Waddnstr, "waddnstr");
382
383       Txt    : char_array (0 .. Str'Length);
384       Length : size_t;
385    begin
386       To_C (Str, Txt, Length);
387       if Waddnstr (Win, Txt, C_Int (Len)) = Curses_Err then
388          raise Curses_Exception;
389       end if;
390    end Add;
391
392    procedure Add
393      (Win    : Window := Standard_Window;
394       Line   : Line_Position;
395       Column : Column_Position;
396       Str    : String;
397       Len    : Integer := -1)
398    is
399    begin
400       Move_Cursor (Win, Line, Column);
401       Add (Win, Str, Len);
402    end Add;
403 ------------------------------------------------------------------------------
404    procedure Add
405      (Win : Window := Standard_Window;
406       Str : Attributed_String;
407       Len : Integer := -1)
408    is
409       function Waddchnstr (Win : Window;
410                            Str : chtype_array;
411                            Len : C_Int := -1) return C_Int;
412       pragma Import (C, Waddchnstr, "waddchnstr");
413
414       Txt : chtype_array (0 .. Str'Length);
415    begin
416       for Length in 1 .. size_t (Str'Length) loop
417          Txt (Length - 1) := Str (Natural (Length));
418       end loop;
419       Txt (Str'Length) := Default_Character;
420       if Waddchnstr (Win,
421                      Txt,
422                      C_Int (Len)) = Curses_Err then
423          raise Curses_Exception;
424       end if;
425    end Add;
426
427    procedure Add
428      (Win    : Window := Standard_Window;
429       Line   : Line_Position;
430       Column : Column_Position;
431       Str    : Attributed_String;
432       Len    : Integer := -1)
433    is
434    begin
435       Move_Cursor (Win, Line, Column);
436       Add (Win, Str, Len);
437    end Add;
438 ------------------------------------------------------------------------------
439    procedure Border
440      (Win                       : Window := Standard_Window;
441       Left_Side_Symbol          : Attributed_Character := Default_Character;
442       Right_Side_Symbol         : Attributed_Character := Default_Character;
443       Top_Side_Symbol           : Attributed_Character := Default_Character;
444       Bottom_Side_Symbol        : Attributed_Character := Default_Character;
445       Upper_Left_Corner_Symbol  : Attributed_Character := Default_Character;
446       Upper_Right_Corner_Symbol : Attributed_Character := Default_Character;
447       Lower_Left_Corner_Symbol  : Attributed_Character := Default_Character;
448       Lower_Right_Corner_Symbol : Attributed_Character := Default_Character)
449    is
450       function Wborder (W   : Window;
451                         LS  : C_Chtype;
452                         RS  : C_Chtype;
453                         TS  : C_Chtype;
454                         BS  : C_Chtype;
455                         ULC : C_Chtype;
456                         URC : C_Chtype;
457                         LLC : C_Chtype;
458                         LRC : C_Chtype) return C_Int;
459       pragma Import (C, Wborder, "wborder");
460    begin
461       if Wborder (Win,
462                   AttrChar_To_Chtype (Left_Side_Symbol),
463                   AttrChar_To_Chtype (Right_Side_Symbol),
464                   AttrChar_To_Chtype (Top_Side_Symbol),
465                   AttrChar_To_Chtype (Bottom_Side_Symbol),
466                   AttrChar_To_Chtype (Upper_Left_Corner_Symbol),
467                   AttrChar_To_Chtype (Upper_Right_Corner_Symbol),
468                   AttrChar_To_Chtype (Lower_Left_Corner_Symbol),
469                   AttrChar_To_Chtype (Lower_Right_Corner_Symbol)
470                   ) = Curses_Err
471       then
472          raise Curses_Exception;
473       end if;
474    end Border;
475
476    procedure Box
477      (Win               : Window := Standard_Window;
478       Vertical_Symbol   : Attributed_Character := Default_Character;
479       Horizontal_Symbol : Attributed_Character := Default_Character)
480    is
481    begin
482       Border (Win,
483               Vertical_Symbol, Vertical_Symbol,
484               Horizontal_Symbol, Horizontal_Symbol);
485    end Box;
486
487    procedure Horizontal_Line
488      (Win         : Window := Standard_Window;
489       Line_Size   : Natural;
490       Line_Symbol : Attributed_Character := Default_Character)
491    is
492       function Whline (W   : Window;
493                        Ch  : C_Chtype;
494                        Len : C_Int) return C_Int;
495       pragma Import (C, Whline, "whline");
496    begin
497       if Whline (Win,
498                  AttrChar_To_Chtype (Line_Symbol),
499                  C_Int (Line_Size)) = Curses_Err then
500          raise Curses_Exception;
501       end if;
502    end Horizontal_Line;
503
504    procedure Vertical_Line
505      (Win         : Window := Standard_Window;
506       Line_Size   : Natural;
507       Line_Symbol : Attributed_Character := Default_Character)
508    is
509       function Wvline (W   : Window;
510                        Ch  : C_Chtype;
511                        Len : C_Int) return C_Int;
512       pragma Import (C, Wvline, "wvline");
513    begin
514       if Wvline (Win,
515                  AttrChar_To_Chtype (Line_Symbol),
516                  C_Int (Line_Size)) = Curses_Err then
517          raise Curses_Exception;
518       end if;
519    end Vertical_Line;
520
521 ------------------------------------------------------------------------------
522    function Get_Keystroke (Win : Window := Standard_Window)
523      return Real_Key_Code
524    is
525       function Wgetch (W : Window) return C_Int;
526       pragma Import (C, Wgetch, "wgetch");
527
528       C : constant C_Int := Wgetch (Win);
529    begin
530       if C = Curses_Err then
531          return Key_None;
532       else
533          return Real_Key_Code (C);
534       end if;
535    end Get_Keystroke;
536
537    procedure Undo_Keystroke (Key : Real_Key_Code)
538    is
539       function Ungetch (Ch : C_Int) return C_Int;
540       pragma Import (C, Ungetch, "ungetch");
541    begin
542       if Ungetch (C_Int (Key)) = Curses_Err then
543          raise Curses_Exception;
544       end if;
545    end Undo_Keystroke;
546
547    function Has_Key (Key : Special_Key_Code) return Boolean
548    is
549       function Haskey (Key : C_Int) return C_Int;
550       pragma Import (C, Haskey, "has_key");
551    begin
552       if Haskey (C_Int (Key)) = Curses_False then
553          return False;
554       else
555          return True;
556       end if;
557    end Has_Key;
558
559    function Is_Function_Key (Key : Special_Key_Code) return Boolean
560    is
561       L : constant Special_Key_Code  := Special_Key_Code (Natural (Key_F0) +
562         Natural (Function_Key_Number'Last));
563    begin
564       if (Key >= Key_F0) and then (Key <= L) then
565          return True;
566       else
567          return False;
568       end if;
569    end Is_Function_Key;
570
571    function Function_Key (Key : Real_Key_Code)
572                           return Function_Key_Number
573    is
574    begin
575       if Is_Function_Key (Key) then
576          return Function_Key_Number (Key - Key_F0);
577       else
578          raise Constraint_Error;
579       end if;
580    end Function_Key;
581
582    function Function_Key_Code (Key : Function_Key_Number) return Real_Key_Code
583    is
584    begin
585       return Real_Key_Code (Natural (Key_F0) + Natural (Key));
586    end Function_Key_Code;
587 ------------------------------------------------------------------------------
588    procedure Standout (Win : Window  := Standard_Window;
589                        On  : Boolean := True)
590    is
591       function wstandout (Win : Window) return C_Int;
592       pragma Import (C, wstandout, "wstandout");
593       function wstandend (Win : Window) return C_Int;
594       pragma Import (C, wstandend, "wstandend");
595
596       Err : C_Int;
597    begin
598       if On then
599          Err := wstandout (Win);
600       else
601          Err := wstandend (Win);
602       end if;
603       if Err = Curses_Err then
604          raise Curses_Exception;
605       end if;
606    end Standout;
607
608    procedure Switch_Character_Attribute
609      (Win  : Window := Standard_Window;
610       Attr : Character_Attribute_Set := Normal_Video;
611       On   : Boolean := True)
612    is
613       function Wattron (Win    : Window;
614                         C_Attr : C_AttrType) return C_Int;
615       pragma Import (C, Wattron, "wattr_on");
616       function Wattroff (Win    : Window;
617                          C_Attr : C_AttrType) return C_Int;
618       pragma Import (C, Wattroff, "wattr_off");
619       --  In Ada we use the On Boolean to control whether or not we want to
620       --  switch on or off the attributes in the set.
621       Err : C_Int;
622       AC  : constant Attributed_Character := (Ch    => Character'First,
623                                               Color => Color_Pair'First,
624                                               Attr  => Attr);
625    begin
626       if On then
627          Err := Wattron  (Win, AttrChar_To_AttrType (AC));
628       else
629          Err := Wattroff (Win, AttrChar_To_AttrType (AC));
630       end if;
631       if Err = Curses_Err then
632          raise Curses_Exception;
633       end if;
634    end Switch_Character_Attribute;
635
636    procedure Set_Character_Attributes
637      (Win   : Window := Standard_Window;
638       Attr  : Character_Attribute_Set := Normal_Video;
639       Color : Color_Pair := Color_Pair'First)
640    is
641       function Wattrset (Win    : Window;
642                          C_Attr : C_AttrType) return C_Int;
643       pragma Import (C, Wattrset, "wattrset"); -- ??? wattr_set
644    begin
645       if Wattrset (Win,
646                    AttrChar_To_AttrType (Attributed_Character'
647                                          (Ch    => Character'First,
648                                           Color => Color,
649                                           Attr  => Attr))) = Curses_Err then
650          raise Curses_Exception;
651       end if;
652    end Set_Character_Attributes;
653
654    function Get_Character_Attribute (Win : Window := Standard_Window)
655                                      return Character_Attribute_Set
656    is
657       function Wattrget (Win : Window;
658                          Atr : access C_AttrType;
659                          Col : access C_Short;
660                          Opt : System.Address) return C_Int;
661       pragma Import (C, Wattrget, "wattr_get");
662
663       Attr : aliased C_AttrType;
664       Col  : aliased C_Short;
665       Res  : constant C_Int := Wattrget (Win, Attr'Access, Col'Access,
666                                          System.Null_Address);
667       Ch   : Attributed_Character;
668    begin
669       if Res = Curses_Ok then
670          Ch := AttrType_To_AttrChar (Attr);
671          return Ch.Attr;
672       else
673          raise Curses_Exception;
674       end if;
675    end Get_Character_Attribute;
676
677    function Get_Character_Attribute (Win : Window := Standard_Window)
678                                      return Color_Pair
679    is
680       function Wattrget (Win : Window;
681                          Atr : access C_AttrType;
682                          Col : access C_Short;
683                          Opt : System.Address) return C_Int;
684       pragma Import (C, Wattrget, "wattr_get");
685
686       Attr : aliased C_AttrType;
687       Col  : aliased C_Short;
688       Res  : constant C_Int := Wattrget (Win, Attr'Access, Col'Access,
689                                          System.Null_Address);
690       Ch   : Attributed_Character;
691    begin
692       if Res = Curses_Ok then
693          Ch := AttrType_To_AttrChar (Attr);
694          return Ch.Color;
695       else
696          raise Curses_Exception;
697       end if;
698    end Get_Character_Attribute;
699
700    procedure Set_Color (Win  : Window := Standard_Window;
701                         Pair : Color_Pair)
702    is
703       function Wset_Color (Win   : Window;
704                            Color : C_Short;
705                            Opts  : C_Void_Ptr) return C_Int;
706       pragma Import (C, Wset_Color, "wcolor_set");
707    begin
708       if Wset_Color (Win,
709                      C_Short (Pair),
710                      C_Void_Ptr (System.Null_Address)) = Curses_Err then
711          raise Curses_Exception;
712       end if;
713    end Set_Color;
714
715    procedure Change_Attributes
716      (Win   : Window := Standard_Window;
717       Count : Integer := -1;
718       Attr  : Character_Attribute_Set := Normal_Video;
719       Color : Color_Pair := Color_Pair'First)
720    is
721       function Wchgat (Win   : Window;
722                        Cnt   : C_Int;
723                        Attr  : C_AttrType;
724                        Color : C_Short;
725                        Opts  : System.Address := System.Null_Address)
726                        return C_Int;
727       pragma Import (C, Wchgat, "wchgat");
728
729       Ch : constant Attributed_Character :=
730         (Ch => Character'First, Color => Color_Pair'First, Attr => Attr);
731    begin
732       if Wchgat (Win, C_Int (Count), AttrChar_To_AttrType (Ch),
733                  C_Short (Color)) = Curses_Err then
734          raise Curses_Exception;
735       end if;
736    end Change_Attributes;
737
738    procedure Change_Attributes
739      (Win    : Window := Standard_Window;
740       Line   : Line_Position := Line_Position'First;
741       Column : Column_Position := Column_Position'First;
742       Count  : Integer := -1;
743       Attr   : Character_Attribute_Set := Normal_Video;
744       Color  : Color_Pair := Color_Pair'First)
745    is
746    begin
747       Move_Cursor (Win, Line, Column);
748       Change_Attributes (Win, Count, Attr, Color);
749    end Change_Attributes;
750 ------------------------------------------------------------------------------
751    procedure Beep
752    is
753       function Beeper return C_Int;
754       pragma Import (C, Beeper, "beep");
755    begin
756       if Beeper = Curses_Err then
757          raise Curses_Exception;
758       end if;
759    end Beep;
760
761    procedure Flash_Screen
762    is
763       function Flash return C_Int;
764       pragma Import (C, Flash, "flash");
765    begin
766       if Flash = Curses_Err then
767          raise Curses_Exception;
768       end if;
769    end Flash_Screen;
770 ------------------------------------------------------------------------------
771    procedure Set_Cbreak_Mode (SwitchOn : Boolean := True)
772    is
773       function Cbreak return C_Int;
774       pragma Import (C, Cbreak, "cbreak");
775       function NoCbreak return C_Int;
776       pragma Import (C, NoCbreak, "nocbreak");
777
778       Err : C_Int;
779    begin
780       if SwitchOn then
781          Err := Cbreak;
782       else
783          Err := NoCbreak;
784       end if;
785       if Err = Curses_Err then
786          raise Curses_Exception;
787       end if;
788    end Set_Cbreak_Mode;
789
790    procedure Set_Raw_Mode (SwitchOn : Boolean := True)
791    is
792       function Raw return C_Int;
793       pragma Import (C, Raw, "raw");
794       function NoRaw return C_Int;
795       pragma Import (C, NoRaw, "noraw");
796
797       Err : C_Int;
798    begin
799       if SwitchOn then
800          Err := Raw;
801       else
802          Err := NoRaw;
803       end if;
804       if Err = Curses_Err then
805          raise Curses_Exception;
806       end if;
807    end Set_Raw_Mode;
808
809    procedure Set_Echo_Mode (SwitchOn : Boolean := True)
810    is
811       function Echo return C_Int;
812       pragma Import (C, Echo, "echo");
813       function NoEcho return C_Int;
814       pragma Import (C, NoEcho, "noecho");
815
816       Err : C_Int;
817    begin
818       if SwitchOn then
819          Err := Echo;
820       else
821          Err := NoEcho;
822       end if;
823       if Err = Curses_Err then
824          raise Curses_Exception;
825       end if;
826    end Set_Echo_Mode;
827
828    procedure Set_Meta_Mode (Win      : Window := Standard_Window;
829                             SwitchOn : Boolean := True)
830    is
831       function Meta (W : Window; Mode : Curses_Bool) return C_Int;
832       pragma Import (C, Meta, "meta");
833    begin
834       if Meta (Win, Curses_Bool (Boolean'Pos (SwitchOn))) = Curses_Err then
835          raise Curses_Exception;
836       end if;
837    end Set_Meta_Mode;
838
839    procedure Set_KeyPad_Mode (Win      : Window := Standard_Window;
840                               SwitchOn : Boolean := True)
841    is
842       function Keypad (W : Window; Mode : Curses_Bool) return C_Int;
843       pragma Import (C, Keypad, "keypad");
844    begin
845       if Keypad (Win, Curses_Bool (Boolean'Pos (SwitchOn))) = Curses_Err then
846          raise Curses_Exception;
847       end if;
848    end Set_KeyPad_Mode;
849
850    function Get_KeyPad_Mode (Win : Window := Standard_Window)
851                              return Boolean
852    is
853       function Is_Keypad (W : Window) return Curses_Bool;
854       pragma Import (C, Is_Keypad, "is_keypad");
855    begin
856       return (Is_Keypad (Win) /= Curses_Bool_False);
857    end Get_KeyPad_Mode;
858
859    procedure Half_Delay (Amount : Half_Delay_Amount)
860    is
861       function Halfdelay (Amount : C_Int) return C_Int;
862       pragma Import (C, Halfdelay, "halfdelay");
863    begin
864       if Halfdelay (C_Int (Amount)) = Curses_Err then
865          raise Curses_Exception;
866       end if;
867    end Half_Delay;
868
869    procedure Set_Flush_On_Interrupt_Mode
870      (Win  : Window := Standard_Window;
871       Mode : Boolean := True)
872    is
873       function Intrflush (Win : Window; Mode : Curses_Bool) return C_Int;
874       pragma Import (C, Intrflush, "intrflush");
875    begin
876       if Intrflush (Win, Curses_Bool (Boolean'Pos (Mode))) = Curses_Err then
877          raise Curses_Exception;
878       end if;
879    end Set_Flush_On_Interrupt_Mode;
880
881    procedure Set_Queue_Interrupt_Mode
882      (Win   : Window := Standard_Window;
883       Flush : Boolean := True)
884    is
885       procedure Qiflush;
886       pragma Import (C, Qiflush, "qiflush");
887       procedure No_Qiflush;
888       pragma Import (C, No_Qiflush, "noqiflush");
889    begin
890       if Win = Null_Window then
891          raise Curses_Exception;
892       end if;
893       if Flush then
894          Qiflush;
895       else
896          No_Qiflush;
897       end if;
898    end Set_Queue_Interrupt_Mode;
899
900    procedure Set_NoDelay_Mode
901      (Win  : Window := Standard_Window;
902       Mode : Boolean := False)
903    is
904       function Nodelay (Win : Window; Mode : Curses_Bool) return C_Int;
905       pragma Import (C, Nodelay, "nodelay");
906    begin
907       if Nodelay (Win, Curses_Bool (Boolean'Pos (Mode))) = Curses_Err then
908          raise Curses_Exception;
909       end if;
910    end Set_NoDelay_Mode;
911
912    procedure Set_Timeout_Mode (Win    : Window := Standard_Window;
913                                Mode   : Timeout_Mode;
914                                Amount : Natural)
915    is
916       procedure Wtimeout (Win : Window; Amount : C_Int);
917       pragma Import (C, Wtimeout, "wtimeout");
918
919       Time : C_Int;
920    begin
921       case Mode is
922          when Blocking     => Time := -1;
923          when Non_Blocking => Time := 0;
924          when Delayed      =>
925             if Amount = 0 then
926                raise Constraint_Error;
927             end if;
928             Time := C_Int (Amount);
929       end case;
930       Wtimeout (Win, Time);
931    end Set_Timeout_Mode;
932
933    procedure Set_Escape_Timer_Mode
934      (Win       : Window := Standard_Window;
935       Timer_Off : Boolean := False)
936    is
937       function Notimeout (Win : Window; Mode : Curses_Bool) return C_Int;
938       pragma Import (C, Notimeout, "notimeout");
939    begin
940       if Notimeout (Win, Curses_Bool (Boolean'Pos (Timer_Off)))
941         = Curses_Err then
942          raise Curses_Exception;
943       end if;
944    end Set_Escape_Timer_Mode;
945
946 ------------------------------------------------------------------------------
947    procedure Set_NL_Mode (SwitchOn : Boolean := True)
948    is
949       function NL return C_Int;
950       pragma Import (C, NL, "nl");
951       function NoNL return C_Int;
952       pragma Import (C, NoNL, "nonl");
953
954       Err : C_Int;
955    begin
956       if SwitchOn then
957          Err := NL;
958       else
959          Err := NoNL;
960       end if;
961       if Err = Curses_Err then
962          raise Curses_Exception;
963       end if;
964    end Set_NL_Mode;
965
966    procedure Clear_On_Next_Update
967      (Win      : Window := Standard_Window;
968       Do_Clear : Boolean := True)
969    is
970       function Clear_Ok (W : Window; Flag : Curses_Bool) return C_Int;
971       pragma Import (C, Clear_Ok, "clearok");
972    begin
973       if Clear_Ok (Win, Curses_Bool (Boolean'Pos (Do_Clear))) = Curses_Err then
974          raise Curses_Exception;
975       end if;
976    end Clear_On_Next_Update;
977
978    procedure Use_Insert_Delete_Line
979      (Win    : Window := Standard_Window;
980       Do_Idl : Boolean := True)
981    is
982       function IDL_Ok (W : Window; Flag : Curses_Bool) return C_Int;
983       pragma Import (C, IDL_Ok, "idlok");
984    begin
985       if IDL_Ok (Win, Curses_Bool (Boolean'Pos (Do_Idl))) = Curses_Err then
986          raise Curses_Exception;
987       end if;
988    end Use_Insert_Delete_Line;
989
990    procedure Use_Insert_Delete_Character
991      (Win    : Window := Standard_Window;
992       Do_Idc : Boolean := True)
993    is
994       procedure IDC_Ok (W : Window; Flag : Curses_Bool);
995       pragma Import (C, IDC_Ok, "idcok");
996    begin
997       IDC_Ok (Win, Curses_Bool (Boolean'Pos (Do_Idc)));
998    end Use_Insert_Delete_Character;
999
1000    procedure Leave_Cursor_After_Update
1001      (Win      : Window := Standard_Window;
1002       Do_Leave : Boolean := True)
1003    is
1004       function Leave_Ok (W : Window; Flag : Curses_Bool) return C_Int;
1005       pragma Import (C, Leave_Ok, "leaveok");
1006    begin
1007       if Leave_Ok (Win, Curses_Bool (Boolean'Pos (Do_Leave))) = Curses_Err then
1008          raise Curses_Exception;
1009       end if;
1010    end Leave_Cursor_After_Update;
1011
1012    procedure Immediate_Update_Mode
1013      (Win  : Window := Standard_Window;
1014       Mode : Boolean := False)
1015    is
1016       procedure Immedok (Win : Window; Mode : Curses_Bool);
1017       pragma Import (C, Immedok, "immedok");
1018    begin
1019       Immedok (Win, Curses_Bool (Boolean'Pos (Mode)));
1020    end Immediate_Update_Mode;
1021
1022    procedure Allow_Scrolling
1023      (Win  : Window  := Standard_Window;
1024       Mode : Boolean := False)
1025    is
1026       function Scrollok (Win : Window; Mode : Curses_Bool) return C_Int;
1027       pragma Import (C, Scrollok, "scrollok");
1028    begin
1029       if Scrollok (Win, Curses_Bool (Boolean'Pos (Mode))) = Curses_Err then
1030          raise Curses_Exception;
1031       end if;
1032    end Allow_Scrolling;
1033
1034    function Scrolling_Allowed (Win : Window := Standard_Window)
1035                                return Boolean
1036    is
1037       function Is_Scroll_Ok (W : Window) return Curses_Bool;
1038       pragma Import (C, Is_Scroll_Ok, "is_scrollok");
1039    begin
1040       return (Is_Scroll_Ok (Win) /= Curses_Bool_False);
1041    end Scrolling_Allowed;
1042
1043    procedure Set_Scroll_Region
1044      (Win         : Window := Standard_Window;
1045       Top_Line    : Line_Position;
1046       Bottom_Line : Line_Position)
1047    is
1048       function Wsetscrreg (Win : Window;
1049                            Lin : C_Int;
1050                            Col : C_Int) return C_Int;
1051       pragma Import (C, Wsetscrreg, "wsetscrreg");
1052    begin
1053       if Wsetscrreg (Win, C_Int (Top_Line), C_Int (Bottom_Line))
1054         = Curses_Err then
1055          raise Curses_Exception;
1056       end if;
1057    end Set_Scroll_Region;
1058 ------------------------------------------------------------------------------
1059    procedure Update_Screen
1060    is
1061       function Do_Update return C_Int;
1062       pragma Import (C, Do_Update, "doupdate");
1063    begin
1064       if Do_Update = Curses_Err then
1065          raise Curses_Exception;
1066       end if;
1067    end Update_Screen;
1068
1069    procedure Refresh (Win : Window := Standard_Window)
1070    is
1071       function Wrefresh (W : Window) return C_Int;
1072       pragma Import (C, Wrefresh, "wrefresh");
1073    begin
1074       if Wrefresh (Win) = Curses_Err then
1075          raise Curses_Exception;
1076       end if;
1077    end Refresh;
1078
1079    procedure Refresh_Without_Update
1080      (Win : Window := Standard_Window)
1081    is
1082       function Wnoutrefresh (W : Window) return C_Int;
1083       pragma Import (C, Wnoutrefresh, "wnoutrefresh");
1084    begin
1085       if Wnoutrefresh (Win) = Curses_Err then
1086          raise Curses_Exception;
1087       end if;
1088    end Refresh_Without_Update;
1089
1090    procedure Redraw (Win : Window := Standard_Window)
1091    is
1092       function Redrawwin (Win : Window) return C_Int;
1093       pragma Import (C, Redrawwin, "redrawwin");
1094    begin
1095       if Redrawwin (Win) = Curses_Err then
1096          raise Curses_Exception;
1097       end if;
1098    end Redraw;
1099
1100    procedure Redraw
1101      (Win        : Window := Standard_Window;
1102       Begin_Line : Line_Position;
1103       Line_Count : Positive)
1104    is
1105       function Wredrawln (Win : Window; First : C_Int; Cnt : C_Int)
1106                           return C_Int;
1107       pragma Import (C, Wredrawln, "wredrawln");
1108    begin
1109       if Wredrawln (Win,
1110                     C_Int (Begin_Line),
1111                     C_Int (Line_Count)) = Curses_Err then
1112          raise Curses_Exception;
1113       end if;
1114    end Redraw;
1115
1116 ------------------------------------------------------------------------------
1117    procedure Erase (Win : Window := Standard_Window)
1118    is
1119       function Werase (W : Window) return C_Int;
1120       pragma Import (C, Werase, "werase");
1121    begin
1122       if Werase (Win) = Curses_Err then
1123          raise Curses_Exception;
1124       end if;
1125    end Erase;
1126
1127    procedure Clear (Win : Window := Standard_Window)
1128    is
1129       function Wclear (W : Window) return C_Int;
1130       pragma Import (C, Wclear, "wclear");
1131    begin
1132       if Wclear (Win) = Curses_Err then
1133          raise Curses_Exception;
1134       end if;
1135    end Clear;
1136
1137    procedure Clear_To_End_Of_Screen (Win : Window := Standard_Window)
1138    is
1139       function Wclearbot (W : Window) return C_Int;
1140       pragma Import (C, Wclearbot, "wclrtobot");
1141    begin
1142       if Wclearbot (Win) = Curses_Err then
1143          raise Curses_Exception;
1144       end if;
1145    end Clear_To_End_Of_Screen;
1146
1147    procedure Clear_To_End_Of_Line (Win : Window := Standard_Window)
1148    is
1149       function Wcleareol (W : Window) return C_Int;
1150       pragma Import (C, Wcleareol, "wclrtoeol");
1151    begin
1152       if Wcleareol (Win) = Curses_Err then
1153          raise Curses_Exception;
1154       end if;
1155    end Clear_To_End_Of_Line;
1156 ------------------------------------------------------------------------------
1157    procedure Set_Background
1158      (Win : Window := Standard_Window;
1159       Ch  : Attributed_Character)
1160    is
1161       procedure WBackground (W : Window; Ch : C_Chtype);
1162       pragma Import (C, WBackground, "wbkgdset");
1163    begin
1164       WBackground (Win, AttrChar_To_Chtype (Ch));
1165    end Set_Background;
1166
1167    procedure Change_Background
1168      (Win : Window := Standard_Window;
1169       Ch  : Attributed_Character)
1170    is
1171       function WChangeBkgd (W : Window; Ch : C_Chtype) return C_Int;
1172       pragma Import (C, WChangeBkgd, "wbkgd");
1173    begin
1174       if WChangeBkgd (Win, AttrChar_To_Chtype (Ch)) = Curses_Err then
1175          raise Curses_Exception;
1176       end if;
1177    end Change_Background;
1178
1179    function Get_Background (Win : Window := Standard_Window)
1180      return Attributed_Character
1181    is
1182       function Wgetbkgd (Win : Window) return C_Chtype;
1183       pragma Import (C, Wgetbkgd, "getbkgd");
1184    begin
1185       return Chtype_To_AttrChar (Wgetbkgd (Win));
1186    end Get_Background;
1187 ------------------------------------------------------------------------------
1188    procedure Change_Lines_Status (Win   : Window := Standard_Window;
1189                                   Start : Line_Position;
1190                                   Count : Positive;
1191                                   State : Boolean)
1192    is
1193       function Wtouchln (Win : Window;
1194                          Sta : C_Int;
1195                          Cnt : C_Int;
1196                          Chg : C_Int) return C_Int;
1197       pragma Import (C, Wtouchln, "wtouchln");
1198    begin
1199       if Wtouchln (Win, C_Int (Start), C_Int (Count),
1200                    C_Int (Boolean'Pos (State))) = Curses_Err then
1201          raise Curses_Exception;
1202       end if;
1203    end Change_Lines_Status;
1204
1205    procedure Touch (Win : Window := Standard_Window)
1206    is
1207       Y : Line_Position;
1208       X : Column_Position;
1209    begin
1210       Get_Size (Win, Y, X);
1211       Change_Lines_Status (Win, 0, Positive (Y), True);
1212    end Touch;
1213
1214    procedure Untouch (Win : Window := Standard_Window)
1215    is
1216       Y : Line_Position;
1217       X : Column_Position;
1218    begin
1219       Get_Size (Win, Y, X);
1220       Change_Lines_Status (Win, 0, Positive (Y), False);
1221    end Untouch;
1222
1223    procedure Touch (Win   : Window := Standard_Window;
1224                     Start : Line_Position;
1225                     Count : Positive)
1226    is
1227    begin
1228       Change_Lines_Status (Win, Start, Count, True);
1229    end Touch;
1230
1231    function Is_Touched
1232      (Win  : Window := Standard_Window;
1233       Line : Line_Position) return Boolean
1234    is
1235       function WLineTouched (W : Window; L : C_Int) return Curses_Bool;
1236       pragma Import (C, WLineTouched, "is_linetouched");
1237    begin
1238       if WLineTouched (Win, C_Int (Line)) = Curses_Bool_False then
1239          return False;
1240       else
1241          return True;
1242       end if;
1243    end Is_Touched;
1244
1245    function Is_Touched
1246      (Win : Window := Standard_Window) return Boolean
1247    is
1248       function WWinTouched (W : Window) return Curses_Bool;
1249       pragma Import (C, WWinTouched, "is_wintouched");
1250    begin
1251       if WWinTouched (Win) = Curses_Bool_False then
1252          return False;
1253       else
1254          return True;
1255       end if;
1256    end Is_Touched;
1257 ------------------------------------------------------------------------------
1258    procedure Copy
1259      (Source_Window            : Window;
1260       Destination_Window       : Window;
1261       Source_Top_Row           : Line_Position;
1262       Source_Left_Column       : Column_Position;
1263       Destination_Top_Row      : Line_Position;
1264       Destination_Left_Column  : Column_Position;
1265       Destination_Bottom_Row   : Line_Position;
1266       Destination_Right_Column : Column_Position;
1267       Non_Destructive_Mode     : Boolean := True)
1268    is
1269       function Copywin (Src : Window;
1270                         Dst : Window;
1271                         Str : C_Int;
1272                         Slc : C_Int;
1273                         Dtr : C_Int;
1274                         Dlc : C_Int;
1275                         Dbr : C_Int;
1276                         Drc : C_Int;
1277                         Ndm : C_Int) return C_Int;
1278       pragma Import (C, Copywin, "copywin");
1279    begin
1280       if Copywin (Source_Window,
1281                   Destination_Window,
1282                   C_Int (Source_Top_Row),
1283                   C_Int (Source_Left_Column),
1284                   C_Int (Destination_Top_Row),
1285                   C_Int (Destination_Left_Column),
1286                   C_Int (Destination_Bottom_Row),
1287                   C_Int (Destination_Right_Column),
1288                   Boolean'Pos (Non_Destructive_Mode)
1289                 ) = Curses_Err then
1290          raise Curses_Exception;
1291       end if;
1292    end Copy;
1293
1294    procedure Overwrite
1295      (Source_Window      : Window;
1296       Destination_Window : Window)
1297    is
1298       function Overwrite (Src : Window; Dst : Window) return C_Int;
1299       pragma Import (C, Overwrite, "overwrite");
1300    begin
1301       if Overwrite (Source_Window, Destination_Window) = Curses_Err then
1302          raise Curses_Exception;
1303       end if;
1304    end Overwrite;
1305
1306    procedure Overlay
1307      (Source_Window      : Window;
1308       Destination_Window : Window)
1309    is
1310       function Overlay (Src : Window; Dst : Window) return C_Int;
1311       pragma Import (C, Overlay, "overlay");
1312    begin
1313       if Overlay (Source_Window, Destination_Window) = Curses_Err then
1314          raise Curses_Exception;
1315       end if;
1316    end Overlay;
1317
1318 ------------------------------------------------------------------------------
1319    procedure Insert_Delete_Lines
1320      (Win   : Window := Standard_Window;
1321       Lines : Integer       := 1) -- default is to insert one line above
1322    is
1323       function Winsdelln (W : Window; N : C_Int) return C_Int;
1324       pragma Import (C, Winsdelln, "winsdelln");
1325    begin
1326       if Winsdelln (Win, C_Int (Lines)) = Curses_Err then
1327          raise Curses_Exception;
1328       end if;
1329    end Insert_Delete_Lines;
1330
1331    procedure Delete_Line (Win : Window := Standard_Window)
1332    is
1333    begin
1334       Insert_Delete_Lines (Win, -1);
1335    end Delete_Line;
1336
1337    procedure Insert_Line (Win : Window := Standard_Window)
1338    is
1339    begin
1340       Insert_Delete_Lines (Win, 1);
1341    end Insert_Line;
1342 ------------------------------------------------------------------------------
1343
1344    procedure Get_Size
1345      (Win               : Window := Standard_Window;
1346       Number_Of_Lines   : out Line_Count;
1347       Number_Of_Columns : out Column_Count)
1348    is
1349       function GetMaxY (W : Window) return C_Int;
1350       pragma Import (C, GetMaxY, "getmaxy");
1351
1352       function GetMaxX (W : Window) return C_Int;
1353       pragma Import (C, GetMaxX, "getmaxx");
1354
1355       Y : constant C_Int := GetMaxY (Win);
1356       X : constant C_Int := GetMaxX (Win);
1357    begin
1358       Number_Of_Lines   := Line_Count (Y);
1359       Number_Of_Columns := Column_Count (X);
1360    end Get_Size;
1361
1362    procedure Get_Window_Position
1363      (Win             : Window := Standard_Window;
1364       Top_Left_Line   : out Line_Position;
1365       Top_Left_Column : out Column_Position)
1366    is
1367       function GetBegY (W : Window) return C_Int;
1368       pragma Import (C, GetBegY, "getbegy");
1369
1370       function GetBegX (W : Window) return C_Int;
1371       pragma Import (C, GetBegX, "getbegx");
1372
1373       Y : constant C_Short := C_Short (GetBegY (Win));
1374       X : constant C_Short := C_Short (GetBegX (Win));
1375    begin
1376       Top_Left_Line   := Line_Position (Y);
1377       Top_Left_Column := Column_Position (X);
1378    end Get_Window_Position;
1379
1380    procedure Get_Cursor_Position
1381      (Win    :  Window := Standard_Window;
1382       Line   : out Line_Position;
1383       Column : out Column_Position)
1384    is
1385       function GetCurY (W : Window) return C_Int;
1386       pragma Import (C, GetCurY, "getcury");
1387
1388       function GetCurX (W : Window) return C_Int;
1389       pragma Import (C, GetCurX, "getcurx");
1390
1391       Y : constant C_Short := C_Short (GetCurY (Win));
1392       X : constant C_Short := C_Short (GetCurX (Win));
1393    begin
1394       Line   := Line_Position (Y);
1395       Column := Column_Position (X);
1396    end Get_Cursor_Position;
1397
1398    procedure Get_Origin_Relative_To_Parent
1399      (Win                :  Window;
1400       Top_Left_Line      : out Line_Position;
1401       Top_Left_Column    : out Column_Position;
1402       Is_Not_A_Subwindow : out Boolean)
1403    is
1404       function GetParY (W : Window) return C_Int;
1405       pragma Import (C, GetParY, "getpary");
1406
1407       function GetParX (W : Window) return C_Int;
1408       pragma Import (C, GetParX, "getparx");
1409
1410       Y : constant C_Int := GetParY (Win);
1411       X : constant C_Int := GetParX (Win);
1412    begin
1413       if Y = -1 then
1414          Top_Left_Line   := Line_Position'Last;
1415          Top_Left_Column := Column_Position'Last;
1416          Is_Not_A_Subwindow := True;
1417       else
1418          Top_Left_Line   := Line_Position (Y);
1419          Top_Left_Column := Column_Position (X);
1420          Is_Not_A_Subwindow := False;
1421       end if;
1422    end Get_Origin_Relative_To_Parent;
1423 ------------------------------------------------------------------------------
1424    function New_Pad (Lines   : Line_Count;
1425                      Columns : Column_Count) return Window
1426    is
1427       function Newpad (Lines : C_Int; Columns : C_Int) return Window;
1428       pragma Import (C, Newpad, "newpad");
1429
1430       W : Window;
1431    begin
1432       W := Newpad (C_Int (Lines), C_Int (Columns));
1433       if W = Null_Window then
1434          raise Curses_Exception;
1435       end if;
1436       return W;
1437    end New_Pad;
1438
1439    function Sub_Pad
1440      (Pad                   : Window;
1441       Number_Of_Lines       : Line_Count;
1442       Number_Of_Columns     : Column_Count;
1443       First_Line_Position   : Line_Position;
1444       First_Column_Position : Column_Position) return Window
1445    is
1446       function Subpad
1447         (Pad                   : Window;
1448          Number_Of_Lines       : C_Int;
1449          Number_Of_Columns     : C_Int;
1450          First_Line_Position   : C_Int;
1451          First_Column_Position : C_Int) return Window;
1452       pragma Import (C, Subpad, "subpad");
1453
1454       W : Window;
1455    begin
1456       W := Subpad (Pad,
1457                    C_Int (Number_Of_Lines),
1458                    C_Int (Number_Of_Columns),
1459                    C_Int (First_Line_Position),
1460                    C_Int (First_Column_Position));
1461       if W = Null_Window then
1462          raise Curses_Exception;
1463       end if;
1464       return W;
1465    end Sub_Pad;
1466
1467    procedure Refresh
1468      (Pad                      : Window;
1469       Source_Top_Row           : Line_Position;
1470       Source_Left_Column       : Column_Position;
1471       Destination_Top_Row      : Line_Position;
1472       Destination_Left_Column  : Column_Position;
1473       Destination_Bottom_Row   : Line_Position;
1474       Destination_Right_Column : Column_Position)
1475    is
1476       function Prefresh
1477         (Pad                      : Window;
1478          Source_Top_Row           : C_Int;
1479          Source_Left_Column       : C_Int;
1480          Destination_Top_Row      : C_Int;
1481          Destination_Left_Column  : C_Int;
1482          Destination_Bottom_Row   : C_Int;
1483          Destination_Right_Column : C_Int) return C_Int;
1484       pragma Import (C, Prefresh, "prefresh");
1485    begin
1486       if Prefresh (Pad,
1487                    C_Int (Source_Top_Row),
1488                    C_Int (Source_Left_Column),
1489                    C_Int (Destination_Top_Row),
1490                    C_Int (Destination_Left_Column),
1491                    C_Int (Destination_Bottom_Row),
1492                    C_Int (Destination_Right_Column)) = Curses_Err then
1493          raise Curses_Exception;
1494       end if;
1495    end Refresh;
1496
1497    procedure Refresh_Without_Update
1498      (Pad                      : Window;
1499       Source_Top_Row           : Line_Position;
1500       Source_Left_Column       : Column_Position;
1501       Destination_Top_Row      : Line_Position;
1502       Destination_Left_Column  : Column_Position;
1503       Destination_Bottom_Row   : Line_Position;
1504       Destination_Right_Column : Column_Position)
1505    is
1506       function Pnoutrefresh
1507         (Pad                      : Window;
1508          Source_Top_Row           : C_Int;
1509          Source_Left_Column       : C_Int;
1510          Destination_Top_Row      : C_Int;
1511          Destination_Left_Column  : C_Int;
1512          Destination_Bottom_Row   : C_Int;
1513          Destination_Right_Column : C_Int) return C_Int;
1514       pragma Import (C, Pnoutrefresh, "pnoutrefresh");
1515    begin
1516       if Pnoutrefresh (Pad,
1517                        C_Int (Source_Top_Row),
1518                        C_Int (Source_Left_Column),
1519                        C_Int (Destination_Top_Row),
1520                        C_Int (Destination_Left_Column),
1521                        C_Int (Destination_Bottom_Row),
1522                        C_Int (Destination_Right_Column)) = Curses_Err then
1523          raise Curses_Exception;
1524       end if;
1525    end Refresh_Without_Update;
1526
1527    procedure Add_Character_To_Pad_And_Echo_It
1528      (Pad : Window;
1529       Ch  : Attributed_Character)
1530    is
1531       function Pechochar (Pad : Window; Ch : C_Chtype)
1532                           return C_Int;
1533       pragma Import (C, Pechochar, "pechochar");
1534    begin
1535       if Pechochar (Pad, AttrChar_To_Chtype (Ch)) = Curses_Err then
1536          raise Curses_Exception;
1537       end if;
1538    end Add_Character_To_Pad_And_Echo_It;
1539
1540    procedure Add_Character_To_Pad_And_Echo_It
1541      (Pad : Window;
1542       Ch  : Character)
1543    is
1544    begin
1545       Add_Character_To_Pad_And_Echo_It
1546         (Pad,
1547          Attributed_Character'(Ch    => Ch,
1548                                Color => Color_Pair'First,
1549                                Attr  => Normal_Video));
1550    end Add_Character_To_Pad_And_Echo_It;
1551 ------------------------------------------------------------------------------
1552    procedure Scroll (Win    : Window := Standard_Window;
1553                      Amount : Integer := 1)
1554    is
1555       function Wscrl (Win : Window; N : C_Int) return C_Int;
1556       pragma Import (C, Wscrl, "wscrl");
1557
1558    begin
1559       if Wscrl (Win, C_Int (Amount)) = Curses_Err then
1560          raise Curses_Exception;
1561       end if;
1562    end Scroll;
1563
1564 ------------------------------------------------------------------------------
1565    procedure Delete_Character (Win : Window := Standard_Window)
1566    is
1567       function Wdelch (Win : Window) return C_Int;
1568       pragma Import (C, Wdelch, "wdelch");
1569    begin
1570       if Wdelch (Win) = Curses_Err then
1571          raise Curses_Exception;
1572       end if;
1573    end Delete_Character;
1574
1575    procedure Delete_Character
1576      (Win    : Window := Standard_Window;
1577       Line   : Line_Position;
1578       Column : Column_Position)
1579    is
1580       function Mvwdelch (Win : Window;
1581                          Lin : C_Int;
1582                          Col : C_Int) return C_Int;
1583       pragma Import (C, Mvwdelch, "mvwdelch");
1584    begin
1585       if Mvwdelch (Win, C_Int (Line), C_Int (Column)) = Curses_Err then
1586          raise Curses_Exception;
1587       end if;
1588    end Delete_Character;
1589 ------------------------------------------------------------------------------
1590    function Peek (Win : Window := Standard_Window)
1591      return Attributed_Character
1592    is
1593       function Winch (Win : Window) return C_Chtype;
1594       pragma Import (C, Winch, "winch");
1595    begin
1596       return Chtype_To_AttrChar (Winch (Win));
1597    end Peek;
1598
1599    function Peek
1600      (Win    : Window := Standard_Window;
1601       Line   : Line_Position;
1602       Column : Column_Position) return Attributed_Character
1603    is
1604       function Mvwinch (Win : Window;
1605                         Lin : C_Int;
1606                         Col : C_Int) return C_Chtype;
1607       pragma Import (C, Mvwinch, "mvwinch");
1608    begin
1609       return Chtype_To_AttrChar (Mvwinch (Win, C_Int (Line), C_Int (Column)));
1610    end Peek;
1611 ------------------------------------------------------------------------------
1612    procedure Insert (Win : Window := Standard_Window;
1613                      Ch  : Attributed_Character)
1614    is
1615       function Winsch (Win : Window; Ch : C_Chtype) return C_Int;
1616       pragma Import (C, Winsch, "winsch");
1617    begin
1618       if Winsch (Win, AttrChar_To_Chtype (Ch)) = Curses_Err then
1619          raise Curses_Exception;
1620       end if;
1621    end Insert;
1622
1623    procedure Insert
1624      (Win    : Window := Standard_Window;
1625       Line   : Line_Position;
1626       Column : Column_Position;
1627       Ch     : Attributed_Character)
1628    is
1629       function Mvwinsch (Win : Window;
1630                          Lin : C_Int;
1631                          Col : C_Int;
1632                          Ch  : C_Chtype) return C_Int;
1633       pragma Import (C, Mvwinsch, "mvwinsch");
1634    begin
1635       if Mvwinsch (Win,
1636                    C_Int (Line),
1637                    C_Int (Column),
1638                    AttrChar_To_Chtype (Ch)) = Curses_Err then
1639          raise Curses_Exception;
1640       end if;
1641    end Insert;
1642 ------------------------------------------------------------------------------
1643    procedure Insert (Win : Window := Standard_Window;
1644                      Str : String;
1645                      Len : Integer := -1)
1646    is
1647       function Winsnstr (Win : Window;
1648                          Str : char_array;
1649                          Len : Integer := -1) return C_Int;
1650       pragma Import (C, Winsnstr, "winsnstr");
1651
1652       Txt    : char_array (0 .. Str'Length);
1653       Length : size_t;
1654    begin
1655       To_C (Str, Txt, Length);
1656       if Winsnstr (Win, Txt, Len) = Curses_Err then
1657          raise Curses_Exception;
1658       end if;
1659    end Insert;
1660
1661    procedure Insert
1662      (Win    : Window := Standard_Window;
1663       Line   : Line_Position;
1664       Column : Column_Position;
1665       Str    : String;
1666       Len    : Integer := -1)
1667    is
1668       function Mvwinsnstr (Win    : Window;
1669                            Line   : C_Int;
1670                            Column : C_Int;
1671                            Str    : char_array;
1672                            Len    : C_Int) return C_Int;
1673       pragma Import (C, Mvwinsnstr, "mvwinsnstr");
1674
1675       Txt    : char_array (0 .. Str'Length);
1676       Length : size_t;
1677    begin
1678       To_C (Str, Txt, Length);
1679       if Mvwinsnstr (Win, C_Int (Line), C_Int (Column), Txt, C_Int (Len))
1680         = Curses_Err then
1681          raise Curses_Exception;
1682       end if;
1683    end Insert;
1684 ------------------------------------------------------------------------------
1685    procedure Peek (Win :  Window := Standard_Window;
1686                    Str : out String;
1687                    Len :  Integer := -1)
1688    is
1689       function Winnstr (Win : Window;
1690                         Str : char_array;
1691                         Len : C_Int) return C_Int;
1692       pragma Import (C, Winnstr, "winnstr");
1693
1694       N   : Integer := Len;
1695       Txt : char_array (0 .. Str'Length);
1696       Cnt : Natural;
1697    begin
1698       if N < 0 then
1699          N := Str'Length;
1700       end if;
1701       if N > Str'Length then
1702          raise Constraint_Error;
1703       end if;
1704       Txt (0) := Interfaces.C.char'First;
1705       if Winnstr (Win, Txt, C_Int (N)) = Curses_Err then
1706          raise Curses_Exception;
1707       end if;
1708       To_Ada (Txt, Str, Cnt, True);
1709       if Cnt < Str'Length then
1710          Str ((Str'First + Cnt) .. Str'Last) := (others => ' ');
1711       end if;
1712    end Peek;
1713
1714    procedure Peek
1715      (Win    :  Window := Standard_Window;
1716       Line   :  Line_Position;
1717       Column :  Column_Position;
1718       Str    : out String;
1719       Len    :  Integer := -1)
1720    is
1721    begin
1722       Move_Cursor (Win, Line, Column);
1723       Peek (Win, Str, Len);
1724    end Peek;
1725 ------------------------------------------------------------------------------
1726    procedure Peek
1727      (Win :  Window := Standard_Window;
1728       Str : out Attributed_String;
1729       Len :  Integer := -1)
1730    is
1731       function Winchnstr (Win : Window;
1732                           Str : chtype_array;             -- out
1733                           Len : C_Int) return C_Int;
1734       pragma Import (C, Winchnstr, "winchnstr");
1735
1736       N   : Integer := Len;
1737       Txt : constant chtype_array (0 .. Str'Length)
1738           := (0 => Default_Character);
1739       Cnt : Natural := 0;
1740    begin
1741       if N < 0 then
1742          N := Str'Length;
1743       end if;
1744       if N > Str'Length then
1745          raise Constraint_Error;
1746       end if;
1747       if Winchnstr (Win, Txt, C_Int (N)) = Curses_Err then
1748          raise Curses_Exception;
1749       end if;
1750       for To in Str'Range loop
1751          exit when Txt (size_t (Cnt)) = Default_Character;
1752          Str (To) := Txt (size_t (Cnt));
1753          Cnt := Cnt + 1;
1754       end loop;
1755       if Cnt < Str'Length then
1756          Str ((Str'First + Cnt) .. Str'Last) :=
1757            (others => (Ch => ' ',
1758                        Color => Color_Pair'First,
1759                        Attr => Normal_Video));
1760       end if;
1761    end Peek;
1762
1763    procedure Peek
1764      (Win    :  Window := Standard_Window;
1765       Line   :  Line_Position;
1766       Column :  Column_Position;
1767       Str    : out Attributed_String;
1768       Len    : Integer := -1)
1769    is
1770    begin
1771       Move_Cursor (Win, Line, Column);
1772       Peek (Win, Str, Len);
1773    end Peek;
1774 ------------------------------------------------------------------------------
1775    procedure Get (Win :  Window := Standard_Window;
1776                   Str : out String;
1777                   Len :  Integer := -1)
1778    is
1779       function Wgetnstr (Win : Window;
1780                          Str : char_array;
1781                          Len : C_Int) return C_Int;
1782       pragma Import (C, Wgetnstr, "wgetnstr");
1783
1784       N   : Integer := Len;
1785       Txt : char_array (0 .. Str'Length);
1786       Cnt : Natural;
1787    begin
1788       if N < 0 then
1789          N := Str'Length;
1790       end if;
1791       if N > Str'Length then
1792          raise Constraint_Error;
1793       end if;
1794       Txt (0) := Interfaces.C.char'First;
1795       if Wgetnstr (Win, Txt, C_Int (N)) = Curses_Err then
1796          raise Curses_Exception;
1797       end if;
1798       To_Ada (Txt, Str, Cnt, True);
1799       if Cnt < Str'Length then
1800          Str ((Str'First + Cnt) .. Str'Last) := (others => ' ');
1801       end if;
1802    end Get;
1803
1804    procedure Get
1805      (Win    :  Window := Standard_Window;
1806       Line   :  Line_Position;
1807       Column :  Column_Position;
1808       Str    : out String;
1809       Len    :  Integer := -1)
1810    is
1811    begin
1812       Move_Cursor (Win, Line, Column);
1813       Get (Win, Str, Len);
1814    end Get;
1815 ------------------------------------------------------------------------------
1816    procedure Init_Soft_Label_Keys
1817      (Format : Soft_Label_Key_Format := Three_Two_Three)
1818    is
1819       function Slk_Init (Fmt : C_Int) return C_Int;
1820       pragma Import (C, Slk_Init, "slk_init");
1821    begin
1822       if Slk_Init (Soft_Label_Key_Format'Pos (Format)) = Curses_Err then
1823          raise Curses_Exception;
1824       end if;
1825    end Init_Soft_Label_Keys;
1826
1827    procedure Set_Soft_Label_Key (Label : Label_Number;
1828                                  Text  : String;
1829                                  Fmt   : Label_Justification := Left)
1830    is
1831       function Slk_Set (Label : C_Int;
1832                         Txt   : char_array;
1833                         Fmt   : C_Int) return C_Int;
1834       pragma Import (C, Slk_Set, "slk_set");
1835
1836       Txt : char_array (0 .. Text'Length);
1837       Len : size_t;
1838    begin
1839       To_C (Text, Txt, Len);
1840       if Slk_Set (C_Int (Label), Txt,
1841                   C_Int (Label_Justification'Pos (Fmt))) = Curses_Err then
1842          raise Curses_Exception;
1843       end if;
1844    end Set_Soft_Label_Key;
1845
1846    procedure Refresh_Soft_Label_Keys
1847    is
1848       function Slk_Refresh return C_Int;
1849       pragma Import (C, Slk_Refresh, "slk_refresh");
1850    begin
1851       if Slk_Refresh = Curses_Err then
1852          raise Curses_Exception;
1853       end if;
1854    end Refresh_Soft_Label_Keys;
1855
1856    procedure Refresh_Soft_Label_Keys_Without_Update
1857    is
1858       function Slk_Noutrefresh return C_Int;
1859       pragma Import (C, Slk_Noutrefresh, "slk_noutrefresh");
1860    begin
1861       if Slk_Noutrefresh = Curses_Err then
1862          raise Curses_Exception;
1863       end if;
1864    end Refresh_Soft_Label_Keys_Without_Update;
1865
1866    procedure Get_Soft_Label_Key (Label : Label_Number;
1867                                  Text  : out String)
1868    is
1869       function Slk_Label (Label : C_Int) return chars_ptr;
1870       pragma Import (C, Slk_Label, "slk_label");
1871    begin
1872       Fill_String (Slk_Label (C_Int (Label)), Text);
1873    end Get_Soft_Label_Key;
1874
1875    function Get_Soft_Label_Key (Label : Label_Number) return String
1876    is
1877       function Slk_Label (Label : C_Int) return chars_ptr;
1878       pragma Import (C, Slk_Label, "slk_label");
1879    begin
1880       return Fill_String (Slk_Label (C_Int (Label)));
1881    end Get_Soft_Label_Key;
1882
1883    procedure Clear_Soft_Label_Keys
1884    is
1885       function Slk_Clear return C_Int;
1886       pragma Import (C, Slk_Clear, "slk_clear");
1887    begin
1888       if Slk_Clear = Curses_Err then
1889          raise Curses_Exception;
1890       end if;
1891    end Clear_Soft_Label_Keys;
1892
1893    procedure Restore_Soft_Label_Keys
1894    is
1895       function Slk_Restore return C_Int;
1896       pragma Import (C, Slk_Restore, "slk_restore");
1897    begin
1898       if Slk_Restore = Curses_Err then
1899          raise Curses_Exception;
1900       end if;
1901    end Restore_Soft_Label_Keys;
1902
1903    procedure Touch_Soft_Label_Keys
1904    is
1905       function Slk_Touch return C_Int;
1906       pragma Import (C, Slk_Touch, "slk_touch");
1907    begin
1908       if Slk_Touch = Curses_Err then
1909          raise Curses_Exception;
1910       end if;
1911    end Touch_Soft_Label_Keys;
1912
1913    procedure Switch_Soft_Label_Key_Attributes
1914      (Attr : Character_Attribute_Set;
1915       On   : Boolean := True)
1916    is
1917       function Slk_Attron (Ch : C_Chtype) return C_Int;
1918       pragma Import (C, Slk_Attron, "slk_attron");
1919       function Slk_Attroff (Ch : C_Chtype) return C_Int;
1920       pragma Import (C, Slk_Attroff, "slk_attroff");
1921
1922       Err : C_Int;
1923       Ch  : constant Attributed_Character := (Ch    => Character'First,
1924                                               Attr  => Attr,
1925                                               Color => Color_Pair'First);
1926    begin
1927       if On then
1928          Err := Slk_Attron  (AttrChar_To_Chtype (Ch));
1929       else
1930          Err := Slk_Attroff (AttrChar_To_Chtype (Ch));
1931       end if;
1932       if Err = Curses_Err then
1933          raise Curses_Exception;
1934       end if;
1935    end Switch_Soft_Label_Key_Attributes;
1936
1937    procedure Set_Soft_Label_Key_Attributes
1938      (Attr  : Character_Attribute_Set := Normal_Video;
1939       Color : Color_Pair := Color_Pair'First)
1940    is
1941       function Slk_Attrset (Ch : C_Chtype) return C_Int;
1942       pragma Import (C, Slk_Attrset, "slk_attrset");
1943
1944       Ch : constant Attributed_Character := (Ch    => Character'First,
1945                                              Attr  => Attr,
1946                                              Color => Color);
1947    begin
1948       if Slk_Attrset (AttrChar_To_Chtype (Ch)) = Curses_Err then
1949          raise Curses_Exception;
1950       end if;
1951    end Set_Soft_Label_Key_Attributes;
1952
1953    function Get_Soft_Label_Key_Attributes return Character_Attribute_Set
1954    is
1955       function Slk_Attr return C_Chtype;
1956       pragma Import (C, Slk_Attr, "slk_attr");
1957
1958       Attr : constant C_Chtype := Slk_Attr;
1959    begin
1960       return Chtype_To_AttrChar (Attr).Attr;
1961    end Get_Soft_Label_Key_Attributes;
1962
1963    function Get_Soft_Label_Key_Attributes return Color_Pair
1964    is
1965       function Slk_Attr return C_Chtype;
1966       pragma Import (C, Slk_Attr, "slk_attr");
1967
1968       Attr : constant C_Chtype := Slk_Attr;
1969    begin
1970       return Chtype_To_AttrChar (Attr).Color;
1971    end Get_Soft_Label_Key_Attributes;
1972
1973    procedure Set_Soft_Label_Key_Color (Pair : Color_Pair)
1974    is
1975       function Slk_Color (Color : C_Short) return C_Int;
1976       pragma Import (C, Slk_Color, "slk_color");
1977    begin
1978       if Slk_Color (C_Short (Pair)) = Curses_Err then
1979          raise Curses_Exception;
1980       end if;
1981    end Set_Soft_Label_Key_Color;
1982
1983 ------------------------------------------------------------------------------
1984    procedure Enable_Key (Key    : Special_Key_Code;
1985                          Enable : Boolean := True)
1986    is
1987       function Keyok (Keycode : C_Int;
1988                       On_Off  : Curses_Bool) return C_Int;
1989       pragma Import (C, Keyok, "keyok");
1990    begin
1991       if Keyok (C_Int (Key), Curses_Bool (Boolean'Pos (Enable)))
1992         = Curses_Err then
1993          raise Curses_Exception;
1994       end if;
1995    end Enable_Key;
1996 ------------------------------------------------------------------------------
1997    procedure Define_Key (Definition : String;
1998                          Key        : Special_Key_Code)
1999    is
2000       function Defkey (Def : char_array;
2001                        Key : C_Int) return C_Int;
2002       pragma Import (C, Defkey, "define_key");
2003
2004       Txt    : char_array (0 .. Definition'Length);
2005       Length : size_t;
2006    begin
2007       To_C (Definition, Txt, Length);
2008       if Defkey (Txt, C_Int (Key)) = Curses_Err then
2009          raise Curses_Exception;
2010       end if;
2011    end Define_Key;
2012 ------------------------------------------------------------------------------
2013    procedure Un_Control (Ch  : Attributed_Character;
2014                          Str : out String)
2015    is
2016       function Unctrl (Ch : C_Chtype) return chars_ptr;
2017       pragma Import (C, Unctrl, "unctrl");
2018    begin
2019       Fill_String (Unctrl (AttrChar_To_Chtype (Ch)), Str);
2020    end Un_Control;
2021
2022    function Un_Control (Ch : Attributed_Character) return String
2023    is
2024       function Unctrl (Ch : C_Chtype) return chars_ptr;
2025       pragma Import (C, Unctrl, "unctrl");
2026    begin
2027       return Fill_String (Unctrl (AttrChar_To_Chtype (Ch)));
2028    end Un_Control;
2029
2030    procedure Delay_Output (Msecs : Natural)
2031    is
2032       function Delayoutput (Msecs : C_Int) return C_Int;
2033       pragma Import (C, Delayoutput, "delay_output");
2034    begin
2035       if Delayoutput (C_Int (Msecs)) = Curses_Err then
2036          raise Curses_Exception;
2037       end if;
2038    end Delay_Output;
2039
2040    procedure Flush_Input
2041    is
2042       function Flushinp return C_Int;
2043       pragma Import (C, Flushinp, "flushinp");
2044    begin
2045       if Flushinp = Curses_Err then  -- docu says that never happens, but...
2046          raise Curses_Exception;
2047       end if;
2048    end Flush_Input;
2049 ------------------------------------------------------------------------------
2050    function Baudrate return Natural
2051    is
2052       function Baud return C_Int;
2053       pragma Import (C, Baud, "baudrate");
2054    begin
2055       return Natural (Baud);
2056    end Baudrate;
2057
2058    function Erase_Character return Character
2059    is
2060       function Erasechar return C_Int;
2061       pragma Import (C, Erasechar, "erasechar");
2062    begin
2063       return Character'Val (Erasechar);
2064    end Erase_Character;
2065
2066    function Kill_Character return Character
2067    is
2068       function Killchar return C_Int;
2069       pragma Import (C, Killchar, "killchar");
2070    begin
2071       return Character'Val (Killchar);
2072    end Kill_Character;
2073
2074    function Has_Insert_Character return Boolean
2075    is
2076       function Has_Ic return Curses_Bool;
2077       pragma Import (C, Has_Ic, "has_ic");
2078    begin
2079       if Has_Ic = Curses_Bool_False then
2080          return False;
2081       else
2082          return True;
2083       end if;
2084    end Has_Insert_Character;
2085
2086    function Has_Insert_Line return Boolean
2087    is
2088       function Has_Il return Curses_Bool;
2089       pragma Import (C, Has_Il, "has_il");
2090    begin
2091       if Has_Il = Curses_Bool_False then
2092          return False;
2093       else
2094          return True;
2095       end if;
2096    end Has_Insert_Line;
2097
2098    function Supported_Attributes return Character_Attribute_Set
2099    is
2100       function Termattrs return C_Chtype;
2101       pragma Import (C, Termattrs, "termattrs");
2102
2103       Ch : constant Attributed_Character := Chtype_To_AttrChar (Termattrs);
2104    begin
2105       return Ch.Attr;
2106    end Supported_Attributes;
2107
2108    procedure Long_Name (Name : out String)
2109    is
2110       function Longname return chars_ptr;
2111       pragma Import (C, Longname, "longname");
2112    begin
2113       Fill_String (Longname, Name);
2114    end Long_Name;
2115
2116    function Long_Name return String
2117    is
2118       function Longname return chars_ptr;
2119       pragma Import (C, Longname, "longname");
2120    begin
2121       return Fill_String (Longname);
2122    end Long_Name;
2123
2124    procedure Terminal_Name (Name : out String)
2125    is
2126       function Termname return chars_ptr;
2127       pragma Import (C, Termname, "termname");
2128    begin
2129       Fill_String (Termname, Name);
2130    end Terminal_Name;
2131
2132    function Terminal_Name return String
2133    is
2134       function Termname return chars_ptr;
2135       pragma Import (C, Termname, "termname");
2136    begin
2137       return Fill_String (Termname);
2138    end Terminal_Name;
2139 ------------------------------------------------------------------------------
2140    procedure Init_Pair (Pair : Redefinable_Color_Pair;
2141                         Fore : Color_Number;
2142                         Back : Color_Number)
2143    is
2144       function Initpair (Pair : C_Short;
2145                          Fore : C_Short;
2146                          Back : C_Short) return C_Int;
2147       pragma Import (C, Initpair, "init_pair");
2148    begin
2149       if Integer (Pair) >= Number_Of_Color_Pairs then
2150          raise Constraint_Error;
2151       end if;
2152       if Integer (Fore) >= Number_Of_Colors or else
2153          Integer (Back) >= Number_Of_Colors then
2154          raise Constraint_Error;
2155       end if;
2156       if Initpair (C_Short (Pair), C_Short (Fore), C_Short (Back))
2157         = Curses_Err then
2158          raise Curses_Exception;
2159       end if;
2160    end Init_Pair;
2161
2162    procedure Pair_Content (Pair : Color_Pair;
2163                            Fore : out Color_Number;
2164                            Back : out Color_Number)
2165    is
2166       type C_Short_Access is access all C_Short;
2167       function Paircontent (Pair : C_Short;
2168                             Fp   : C_Short_Access;
2169                             Bp   : C_Short_Access) return C_Int;
2170       pragma Import (C, Paircontent, "pair_content");
2171
2172       F, B : aliased C_Short;
2173    begin
2174       if Paircontent (C_Short (Pair), F'Access, B'Access) = Curses_Err then
2175          raise Curses_Exception;
2176       else
2177          Fore := Color_Number (F);
2178          Back := Color_Number (B);
2179       end if;
2180    end Pair_Content;
2181
2182    function Has_Colors return Boolean
2183    is
2184       function Hascolors return Curses_Bool;
2185       pragma Import (C, Hascolors, "has_colors");
2186    begin
2187       if Hascolors = Curses_Bool_False then
2188          return False;
2189       else
2190          return True;
2191       end if;
2192    end Has_Colors;
2193
2194    procedure Init_Color (Color : Color_Number;
2195                          Red   : RGB_Value;
2196                          Green : RGB_Value;
2197                          Blue  : RGB_Value)
2198    is
2199       function Initcolor (Col   : C_Short;
2200                           Red   : C_Short;
2201                           Green : C_Short;
2202                           Blue  : C_Short) return C_Int;
2203       pragma Import (C, Initcolor, "init_color");
2204    begin
2205       if Initcolor (C_Short (Color), C_Short (Red), C_Short (Green),
2206                     C_Short (Blue)) = Curses_Err then
2207             raise Curses_Exception;
2208       end if;
2209    end Init_Color;
2210
2211    function Can_Change_Color return Boolean
2212    is
2213       function Canchangecolor return Curses_Bool;
2214       pragma Import (C, Canchangecolor, "can_change_color");
2215    begin
2216       if Canchangecolor = Curses_Bool_False then
2217          return False;
2218       else
2219          return True;
2220       end if;
2221    end Can_Change_Color;
2222
2223    procedure Color_Content (Color :  Color_Number;
2224                             Red   : out RGB_Value;
2225                             Green : out RGB_Value;
2226                             Blue  : out RGB_Value)
2227    is
2228       type C_Short_Access is access all C_Short;
2229
2230       function Colorcontent (Color : C_Short; R, G, B : C_Short_Access)
2231                              return C_Int;
2232       pragma Import (C, Colorcontent, "color_content");
2233
2234       R, G, B : aliased C_Short;
2235    begin
2236       if Colorcontent (C_Short (Color), R'Access, G'Access, B'Access) =
2237         Curses_Err then
2238          raise Curses_Exception;
2239       else
2240          Red   := RGB_Value (R);
2241          Green := RGB_Value (G);
2242          Blue  := RGB_Value (B);
2243       end if;
2244    end Color_Content;
2245
2246 ------------------------------------------------------------------------------
2247    procedure Save_Curses_Mode (Mode : Curses_Mode)
2248    is
2249       function Def_Prog_Mode return C_Int;
2250       pragma Import (C, Def_Prog_Mode, "def_prog_mode");
2251       function Def_Shell_Mode return C_Int;
2252       pragma Import (C, Def_Shell_Mode, "def_shell_mode");
2253
2254       Err : C_Int;
2255    begin
2256       case Mode is
2257          when Curses => Err := Def_Prog_Mode;
2258          when Shell  => Err := Def_Shell_Mode;
2259       end case;
2260       if Err = Curses_Err then
2261          raise Curses_Exception;
2262       end if;
2263    end Save_Curses_Mode;
2264
2265    procedure Reset_Curses_Mode (Mode : Curses_Mode)
2266    is
2267       function Reset_Prog_Mode return C_Int;
2268       pragma Import (C, Reset_Prog_Mode, "reset_prog_mode");
2269       function Reset_Shell_Mode return C_Int;
2270       pragma Import (C, Reset_Shell_Mode, "reset_shell_mode");
2271
2272       Err : C_Int;
2273    begin
2274       case Mode is
2275          when Curses => Err := Reset_Prog_Mode;
2276          when Shell  => Err := Reset_Shell_Mode;
2277       end case;
2278       if Err = Curses_Err then
2279          raise Curses_Exception;
2280       end if;
2281    end Reset_Curses_Mode;
2282
2283    procedure Save_Terminal_State
2284    is
2285       function Savetty return C_Int;
2286       pragma Import (C, Savetty, "savetty");
2287    begin
2288       if Savetty = Curses_Err then
2289          raise Curses_Exception;
2290       end if;
2291    end Save_Terminal_State;
2292
2293    procedure Reset_Terminal_State
2294    is
2295       function Resetty return C_Int;
2296       pragma Import (C, Resetty, "resetty");
2297    begin
2298       if Resetty = Curses_Err then
2299          raise Curses_Exception;
2300       end if;
2301    end Reset_Terminal_State;
2302
2303    procedure Rip_Off_Lines (Lines : Integer;
2304                             Proc  : Stdscr_Init_Proc)
2305    is
2306       function Ripoffline (Lines : C_Int;
2307                            Proc  : Stdscr_Init_Proc) return C_Int;
2308       pragma Import (C, Ripoffline, "_nc_ripoffline");
2309    begin
2310       if Ripoffline (C_Int (Lines), Proc) = Curses_Err then
2311          raise Curses_Exception;
2312       end if;
2313    end Rip_Off_Lines;
2314
2315    procedure Set_Cursor_Visibility (Visibility : in out Cursor_Visibility)
2316    is
2317       function Curs_Set (Curs : C_Int) return C_Int;
2318       pragma Import (C, Curs_Set, "curs_set");
2319
2320       Res : C_Int;
2321    begin
2322       Res := Curs_Set (Cursor_Visibility'Pos (Visibility));
2323       if Res /= Curses_Err then
2324          Visibility := Cursor_Visibility'Val (Res);
2325       end if;
2326    end Set_Cursor_Visibility;
2327
2328    procedure Nap_Milli_Seconds (Ms : Natural)
2329    is
2330       function Napms (Ms : C_Int) return C_Int;
2331       pragma Import (C, Napms, "napms");
2332    begin
2333       if Napms (C_Int (Ms)) = Curses_Err then
2334          raise Curses_Exception;
2335       end if;
2336    end Nap_Milli_Seconds;
2337 ------------------------------------------------------------------------------
2338 include(`Public_Variables')
2339 ------------------------------------------------------------------------------
2340    procedure Transform_Coordinates
2341      (W      : Window := Standard_Window;
2342       Line   : in out Line_Position;
2343       Column : in out Column_Position;
2344       Dir    : Transform_Direction := From_Screen)
2345    is
2346       type Int_Access is access all C_Int;
2347       function Transform (W    : Window;
2348                           Y, X : Int_Access;
2349                           Dir  : Curses_Bool) return C_Int;
2350       pragma Import (C, Transform, "wmouse_trafo");
2351
2352       X : aliased C_Int := C_Int (Column);
2353       Y : aliased C_Int := C_Int (Line);
2354       D : Curses_Bool := Curses_Bool_False;
2355       R : C_Int;
2356    begin
2357       if Dir = To_Screen then
2358          D := 1;
2359       end if;
2360       R := Transform (W, Y'Access, X'Access, D);
2361       if R = Curses_False then
2362          raise Curses_Exception;
2363       else
2364          Line   := Line_Position (Y);
2365          Column := Column_Position (X);
2366       end if;
2367    end Transform_Coordinates;
2368 ------------------------------------------------------------------------------
2369    procedure Use_Default_Colors is
2370       function C_Use_Default_Colors return C_Int;
2371       pragma Import (C, C_Use_Default_Colors, "use_default_colors");
2372       Err : constant C_Int := C_Use_Default_Colors;
2373    begin
2374       if Err = Curses_Err then
2375          raise Curses_Exception;
2376       end if;
2377    end Use_Default_Colors;
2378
2379    procedure Assume_Default_Colors (Fore : Color_Number := Default_Color;
2380                                     Back : Color_Number := Default_Color)
2381    is
2382       function C_Assume_Default_Colors (Fore : C_Int;
2383                                         Back : C_Int) return C_Int;
2384       pragma Import (C, C_Assume_Default_Colors, "assume_default_colors");
2385
2386       Err : constant C_Int := C_Assume_Default_Colors (C_Int (Fore),
2387                                                        C_Int (Back));
2388    begin
2389       if Err = Curses_Err then
2390          raise Curses_Exception;
2391       end if;
2392    end Assume_Default_Colors;
2393 ------------------------------------------------------------------------------
2394    function Curses_Version return String
2395    is
2396       function curses_versionC return chars_ptr;
2397       pragma Import (C, curses_versionC, "curses_version");
2398       Result : constant chars_ptr := curses_versionC;
2399    begin
2400       return Fill_String (Result);
2401    end Curses_Version;
2402 ------------------------------------------------------------------------------
2403    procedure Curses_Free_All is
2404       procedure curses_freeall;
2405       pragma Import (C, curses_freeall, "_nc_freeall");
2406    begin
2407       --  Use this only for testing: you cannot use curses after calling it,
2408       --  so it has to be the "last" thing done before exiting the program.
2409       --  This will not really free ALL of memory used by curses.  That is
2410       --  because it cannot free the memory used for stdout's setbuf.  The
2411       --  _nc_free_and_exit() procedure can do that, but it can be invoked
2412       --  safely only from C - and again, that only as the "last" thing done
2413       --  before exiting the program.
2414       curses_freeall;
2415    end Curses_Free_All;
2416 ------------------------------------------------------------------------------
2417    function Use_Extended_Names (Enable : Boolean) return Boolean
2418    is
2419       function use_extended_namesC (e : Curses_Bool) return C_Int;
2420       pragma Import (C, use_extended_namesC, "use_extended_names");
2421
2422       Res : constant C_Int :=
2423          use_extended_namesC (Curses_Bool (Boolean'Pos (Enable)));
2424    begin
2425       if Res = C_Int (Curses_Bool_False) then
2426          return False;
2427       else
2428          return True;
2429       end if;
2430    end Use_Extended_Names;
2431 ------------------------------------------------------------------------------
2432    procedure Screen_Dump_To_File (Filename : String)
2433    is
2434       function scr_dump (f : char_array) return C_Int;
2435       pragma Import (C, scr_dump, "scr_dump");
2436       Txt    : char_array (0 .. Filename'Length);
2437       Length : size_t;
2438    begin
2439       To_C (Filename, Txt, Length);
2440       if Curses_Err = scr_dump (Txt) then
2441          raise Curses_Exception;
2442       end if;
2443    end Screen_Dump_To_File;
2444
2445    procedure Screen_Restore_From_File (Filename : String)
2446    is
2447       function scr_restore (f : char_array) return C_Int;
2448       pragma Import (C, scr_restore, "scr_restore");
2449       Txt    : char_array (0 .. Filename'Length);
2450       Length : size_t;
2451    begin
2452       To_C (Filename, Txt, Length);
2453       if Curses_Err = scr_restore (Txt)  then
2454          raise Curses_Exception;
2455       end if;
2456    end Screen_Restore_From_File;
2457
2458    procedure Screen_Init_From_File (Filename : String)
2459    is
2460       function scr_init (f : char_array) return C_Int;
2461       pragma Import (C, scr_init, "scr_init");
2462       Txt    : char_array (0 .. Filename'Length);
2463       Length : size_t;
2464    begin
2465       To_C (Filename, Txt, Length);
2466       if Curses_Err = scr_init (Txt) then
2467          raise Curses_Exception;
2468       end if;
2469    end Screen_Init_From_File;
2470
2471    procedure Screen_Set_File (Filename : String)
2472    is
2473       function scr_set (f : char_array) return C_Int;
2474       pragma Import (C, scr_set, "scr_set");
2475       Txt    : char_array (0 .. Filename'Length);
2476       Length : size_t;
2477    begin
2478       To_C (Filename, Txt, Length);
2479       if Curses_Err = scr_set (Txt) then
2480          raise Curses_Exception;
2481       end if;
2482    end Screen_Set_File;
2483 ------------------------------------------------------------------------------
2484    procedure Resize (Win               : Window := Standard_Window;
2485                      Number_Of_Lines   : Line_Count;
2486                      Number_Of_Columns : Column_Count) is
2487       function wresize (win     : Window;
2488                         lines   : C_Int;
2489                         columns : C_Int) return C_Int;
2490       pragma Import (C, wresize);
2491    begin
2492       if wresize (Win,
2493                   C_Int (Number_Of_Lines),
2494                   C_Int (Number_Of_Columns)) = Curses_Err then
2495          raise Curses_Exception;
2496       end if;
2497    end Resize;
2498 ------------------------------------------------------------------------------
2499
2500 end Terminal_Interface.Curses;