Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.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  * $DragonFly: src/usr.sbin/i4b/isdnphone/display.c,v 1.2 2003/06/17 04:29:55 dillon Exp $
34  *
35  *      last edit-date: [Mon Dec 13 21:52:55 1999]
36  *
37  *----------------------------------------------------------------------------*/
38
39 #include "defs.h"
40
41 /*---------------------------------------------------------------------------*
42  *      init curses fullscreen display
43  *---------------------------------------------------------------------------*/
44 void
45 init_mainw(void)
46 {
47         char buffer[512];
48         
49         initscr();                      /* curses init */
50         
51         if((COLS < 80) || (LINES < 24))
52                 fatal(0, "ERROR, minimal screensize must be 80x24, is %dx%d, terminating!", COLS, LINES);
53
54         
55         if((main_w = newwin(MW_HEIGHT, MW_WIDTH, MW_ROW, MW_COL)) == NULL)
56                 fatal("ERROR, curses init main window, terminating!");
57
58         if(opt_d)
59         {
60                 if((dbg_w = newwin(DB_HGT, DB_WID, DB_ROW, DB_COL)) == NULL)
61                         fatal("ERROR, curses init debug window, terminating!");
62                 scrollok(dbg_w, TRUE);
63         }
64
65         raw();                                  /* raw input */
66         noecho();                               /* do not echo input */
67         keypad(stdscr, TRUE);                   /* use special keys */
68         keypad(main_w, TRUE);                   /* use special keys */
69
70         box(main_w, 0, 0);
71
72         sprintf(buffer, "isdnphone %d.%d ", VERSION, REL);
73
74         wstandout(main_w);      
75         mvwaddstr(main_w, 0,  (MW_WIDTH / 2) - (strlen(buffer) / 2), buffer);
76         wstandend(main_w);      
77         
78         mvwaddstr(main_w, MW_STATEY, MW_STATEX, "  state: ");
79         mvwprintw(main_w, MW_STATEY, MW_STX, "%s", states[state]);      
80         wmove(main_w, MW_STATEY+1, 1);
81         whline(main_w, 0, MW_WIDTH-2);
82         
83         mvwaddstr(main_w, MW_NUMY, MW_NUMX, " number: ");
84         wmove(main_w, MW_NUMY+1, 1);
85         whline(main_w, 0, MW_WIDTH-2);
86         
87         mvwaddstr(main_w, MW_MSGY, MW_MSGX, "message: ");
88
89         wrefresh(main_w);
90
91         curses_ready = 1;
92 }
93
94 /*---------------------------------------------------------------------------*
95  *      curses menu for fullscreen command mode
96  *---------------------------------------------------------------------------*/
97 void
98 do_menu(void)
99 {
100         static char *menu[WMITEMS] =
101         {
102                 "Hangup",
103 #define HANGUP  0               
104                 "Dial",
105 #define DIAL    1
106                 "Refresh",
107 #define REFRESH 2
108                 "Exit",
109 #define EXIT    3
110         };
111
112         WINDOW *menu_w;
113         int c;
114         int mpos;
115
116         /* create a new window in the lower screen area */
117         
118         if((menu_w = newwin(WMENU_HGT, WMENU_LEN, WMENU_POSLN, WMENU_POSCO )) == NULL)
119                 return;
120
121         keypad(menu_w, TRUE);                   /* use special keys */
122                 
123         /* draw border around the window */
124         
125         box(menu_w, 0, 0);
126
127         /* add a title */
128         
129         wstandout(menu_w);
130         mvwaddstr(menu_w, 0, (WMENU_LEN / 2) - (strlen(WMENU_TITLE) / 2), WMENU_TITLE);
131         wstandend(menu_w);      
132
133         /* fill the window with the menu options */
134         
135         for(mpos=0; mpos <= (WMITEMS-1); mpos++)
136                 mvwaddstr(menu_w, mpos + 2, 2, menu[mpos]);
137
138         /* highlight the first menu option */
139         
140         mpos = 0;
141         wstandout(menu_w);
142         mvwaddstr(menu_w, mpos + 2, 2, menu[mpos]);
143         wstandend(menu_w);
144
145         /* input loop */
146         
147         for(;;)
148         {
149                 wrefresh(menu_w);
150
151                 c = wgetch(menu_w);
152
153                 switch(c)
154                 {
155                         case TAB:
156                         case KEY_DOWN:  /* down-move cursor */
157                         case ' ':
158                                 mvwaddstr(menu_w, mpos + 2, 2, menu[mpos]);
159                                 mpos++;
160                                 if(mpos >= WMITEMS)
161                                         mpos = 0;
162                                 wstandout(menu_w);
163                                 mvwaddstr(menu_w, mpos + 2, 2, menu[mpos]);
164                                 wstandend(menu_w);
165                                 break;
166
167                         case KEY_UP:    /* up-move cursor */
168                                 mvwaddstr(menu_w, mpos + 2, 2, menu[mpos]);
169                                 if(mpos)
170                                         mpos--;
171                                 else
172                                         mpos = WMITEMS-1;
173                                 wstandout(menu_w);
174                                 mvwaddstr(menu_w, mpos + 2, 2, menu[mpos]);
175                                 wstandend(menu_w);
176                                 break;
177
178                         case 'R':
179                         case 'r':
180                                 wrefresh(curscr);
181                                 goto mexit;
182
183                         case 'E':
184                         case 'e':
185                         case 'Q':
186                         case 'q':
187                         case 'X':
188                         case 'x':
189                                 do_quit(0);
190                                 goto mexit;
191                                 break;
192
193                         case 'H':
194                         case 'h':
195                                 do_hangup();
196                                 goto mexit;
197                                 break;
198
199                         case 'D':
200                         case 'd':
201                                 goto mexit;                             
202                                 break;
203                                 
204                         case CR:
205                         case LF:        /* exec highlighted option */
206 #ifdef KEY_ENTER
207                         case KEY_ENTER:
208 #endif
209                                 switch(mpos)
210                                 {
211                                         case DIAL:
212                                                 goto mexit;
213                                                 break;
214                                         case HANGUP:
215                                                 do_hangup();
216                                                 goto mexit;
217                                                 break;
218                                         case REFRESH:
219                                                 wrefresh(curscr);
220                                                 break;
221                                         case EXIT:
222                                                 do_quit(0);
223                                                 break;
224                                 }
225                                 goto mexit;
226                                 break;
227                 
228                         default:
229                                 goto mexit;
230                                 break;
231                 }
232         }
233
234 mexit:
235         /* delete the menu window */
236
237         wclear(menu_w);
238         wrefresh(menu_w);
239         delwin(menu_w);
240
241         /* re-display the original lower window contents */
242         
243         touchwin(main_w);
244         wrefresh(main_w);
245 }
246
247 /* EOF */