Initial import from FreeBSD RELENG_4:
[games.git] / usr.sbin / i4b / isdnphone / display.c
1 /*
2  * Copyright (c) 1999 Hellmuth Michaelis. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  *
25  *---------------------------------------------------------------------------
26  *
27  *      isdnphone - some display operations
28  *      ===================================
29  *
30  *      $Id: display.c,v 1.4 1999/12/13 21:25:26 hm Exp $ 
31  *
32  * $FreeBSD: src/usr.sbin/i4b/isdnphone/display.c,v 1.1.2.1 2001/08/01 17:45:06 obrien Exp $
33  *
34  *      last edit-date: [Mon Dec 13 21:52:55 1999]
35  *
36  *----------------------------------------------------------------------------*/
37
38 #include "defs.h"
39
40 /*---------------------------------------------------------------------------*
41  *      init curses fullscreen display
42  *---------------------------------------------------------------------------*/
43 void
44 init_mainw(void)
45 {
46         char buffer[512];
47         
48         initscr();                      /* curses init */
49         
50         if((COLS < 80) || (LINES < 24))
51                 fatal(0, "ERROR, minimal screensize must be 80x24, is %dx%d, terminating!", COLS, LINES);
52
53         
54         if((main_w = newwin(MW_HEIGHT, MW_WIDTH, MW_ROW, MW_COL)) == NULL)
55                 fatal("ERROR, curses init main window, terminating!");
56
57         if(opt_d)
58         {
59                 if((dbg_w = newwin(DB_HGT, DB_WID, DB_ROW, DB_COL)) == NULL)
60                         fatal("ERROR, curses init debug window, terminating!");
61                 scrollok(dbg_w, TRUE);
62         }
63
64         raw();                                  /* raw input */
65         noecho();                               /* do not echo input */
66         keypad(stdscr, TRUE);                   /* use special keys */
67         keypad(main_w, TRUE);                   /* use special keys */
68
69         box(main_w, 0, 0);
70
71         sprintf(buffer, "isdnphone %d.%d ", VERSION, REL);
72
73         wstandout(main_w);      
74         mvwaddstr(main_w, 0,  (MW_WIDTH / 2) - (strlen(buffer) / 2), buffer);
75         wstandend(main_w);      
76         
77         mvwaddstr(main_w, MW_STATEY, MW_STATEX, "  state: ");
78         mvwprintw(main_w, MW_STATEY, MW_STX, "%s", states[state]);      
79         wmove(main_w, MW_STATEY+1, 1);
80         whline(main_w, 0, MW_WIDTH-2);
81         
82         mvwaddstr(main_w, MW_NUMY, MW_NUMX, " number: ");
83         wmove(main_w, MW_NUMY+1, 1);
84         whline(main_w, 0, MW_WIDTH-2);
85         
86         mvwaddstr(main_w, MW_MSGY, MW_MSGX, "message: ");
87
88         wrefresh(main_w);
89
90         curses_ready = 1;
91 }
92
93 /*---------------------------------------------------------------------------*
94  *      curses menu for fullscreen command mode
95  *---------------------------------------------------------------------------*/
96 void
97 do_menu(void)
98 {
99         static char *menu[WMITEMS] =
100         {
101                 "Hangup",
102 #define HANGUP  0               
103                 "Dial",
104 #define DIAL    1
105                 "Refresh",
106 #define REFRESH 2
107                 "Exit",
108 #define EXIT    3
109         };
110
111         WINDOW *menu_w;
112         int c;
113         int mpos;
114
115         /* create a new window in the lower screen area */
116         
117         if((menu_w = newwin(WMENU_HGT, WMENU_LEN, WMENU_POSLN, WMENU_POSCO )) == NULL)
118                 return;
119
120         keypad(menu_w, TRUE);                   /* use special keys */
121                 
122         /* draw border around the window */
123         
124         box(menu_w, 0, 0);
125
126         /* add a title */
127         
128         wstandout(menu_w);
129         mvwaddstr(menu_w, 0, (WMENU_LEN / 2) - (strlen(WMENU_TITLE) / 2), WMENU_TITLE);
130         wstandend(menu_w);      
131
132         /* fill the window with the menu options */
133         
134         for(mpos=0; mpos <= (WMITEMS-1); mpos++)
135                 mvwaddstr(menu_w, mpos + 2, 2, menu[mpos]);
136
137         /* highlight the first menu option */
138         
139         mpos = 0;
140         wstandout(menu_w);
141         mvwaddstr(menu_w, mpos + 2, 2, menu[mpos]);
142         wstandend(menu_w);
143
144         /* input loop */
145         
146         for(;;)
147         {
148                 wrefresh(menu_w);
149
150                 c = wgetch(menu_w);
151
152                 switch(c)
153                 {
154                         case TAB:
155                         case KEY_DOWN:  /* down-move cursor */
156                         case ' ':
157                                 mvwaddstr(menu_w, mpos + 2, 2, menu[mpos]);
158                                 mpos++;
159                                 if(mpos >= WMITEMS)
160                                         mpos = 0;
161                                 wstandout(menu_w);
162                                 mvwaddstr(menu_w, mpos + 2, 2, menu[mpos]);
163                                 wstandend(menu_w);
164                                 break;
165
166                         case KEY_UP:    /* up-move cursor */
167                                 mvwaddstr(menu_w, mpos + 2, 2, menu[mpos]);
168                                 if(mpos)
169                                         mpos--;
170                                 else
171                                         mpos = WMITEMS-1;
172                                 wstandout(menu_w);
173                                 mvwaddstr(menu_w, mpos + 2, 2, menu[mpos]);
174                                 wstandend(menu_w);
175                                 break;
176
177                         case 'R':
178                         case 'r':
179                                 wrefresh(curscr);
180                                 goto mexit;
181
182                         case 'E':
183                         case 'e':
184                         case 'Q':
185                         case 'q':
186                         case 'X':
187                         case 'x':
188                                 do_quit(0);
189                                 goto mexit;
190                                 break;
191
192                         case 'H':
193                         case 'h':
194                                 do_hangup();
195                                 goto mexit;
196                                 break;
197
198                         case 'D':
199                         case 'd':
200                                 goto mexit;                             
201                                 break;
202                                 
203                         case CR:
204                         case LF:        /* exec highlighted option */
205 #ifdef KEY_ENTER
206                         case KEY_ENTER:
207 #endif
208                                 switch(mpos)
209                                 {
210                                         case DIAL:
211                                                 goto mexit;
212                                                 break;
213                                         case HANGUP:
214                                                 do_hangup();
215                                                 goto mexit;
216                                                 break;
217                                         case REFRESH:
218                                                 wrefresh(curscr);
219                                                 break;
220                                         case EXIT:
221                                                 do_quit(0);
222                                                 break;
223                                 }
224                                 goto mexit;
225                                 break;
226                 
227                         default:
228                                 goto mexit;
229                                 break;
230                 }
231         }
232
233 mexit:
234         /* delete the menu window */
235
236         wclear(menu_w);
237         wrefresh(menu_w);
238         delwin(menu_w);
239
240         /* re-display the original lower window contents */
241         
242         touchwin(main_w);
243         wrefresh(main_w);
244 }
245
246 /* EOF */