curses 1.2.6 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/macos.yml +19 -0
- data/.github/workflows/ubuntu.yml +26 -0
- data/.github/workflows/windows.yml +28 -0
- data/.gitmodules +1 -1
- data/.travis.yml +6 -3
- data/History.md +40 -0
- data/README.md +4 -1
- data/Rakefile +0 -83
- data/curses.gemspec +2 -3
- data/ext/curses/curses.c +1271 -151
- data/ext/curses/extconf.rb +140 -17
- data/lib/curses.rb +5 -12
- data/sample/form.rb +52 -0
- data/sample/menu.rb +1 -1
- data/vendor/PDCurses/.gitignore +47 -0
- data/vendor/PDCurses/.travis.yml +49 -0
- data/vendor/PDCurses/CMakeLists.txt +68 -0
- data/vendor/PDCurses/HISTORY.md +2036 -0
- data/vendor/PDCurses/IMPLEMNT.md +327 -0
- data/vendor/PDCurses/README.md +77 -0
- data/vendor/PDCurses/acs_defs.h +265 -0
- data/vendor/PDCurses/appveyor.yml +218 -0
- data/vendor/PDCurses/cmake/README.md +71 -0
- data/vendor/PDCurses/cmake/build_dependencies.cmake +178 -0
- data/vendor/PDCurses/cmake/build_options.cmake +25 -0
- data/vendor/PDCurses/cmake/dll_version.cmake +26 -0
- data/vendor/PDCurses/cmake/gen_config_header.cmake +43 -0
- data/vendor/PDCurses/cmake/get_version.cmake +17 -0
- data/vendor/PDCurses/cmake/make_uninstall.cmake +19 -0
- data/vendor/PDCurses/cmake/project_common.cmake +121 -0
- data/vendor/PDCurses/cmake/resource.in.cmake +52 -0
- data/vendor/PDCurses/cmake/sdl2_ttf/CMakeLists.txt +83 -0
- data/vendor/PDCurses/cmake/target_arch.cmake +36 -0
- data/vendor/PDCurses/cmake/version.in.cmake +73 -0
- data/vendor/PDCurses/cmake/watcom_open_dos16_toolchain.cmake +96 -0
- data/vendor/PDCurses/cmake/watcom_open_dos32_toolchain.cmake +106 -0
- data/vendor/PDCurses/cmake/watcom_open_os2v2_toolchain.cmake +105 -0
- data/vendor/PDCurses/curses.h +1846 -0
- data/vendor/PDCurses/curspriv.h +134 -0
- data/vendor/PDCurses/demos/README.md +25 -0
- data/vendor/PDCurses/demos/firework.c +144 -0
- data/vendor/PDCurses/demos/newtest.c +581 -0
- data/vendor/PDCurses/demos/ozdemo.c +447 -0
- data/vendor/PDCurses/demos/ptest.c +283 -0
- data/vendor/PDCurses/demos/rain.c +157 -0
- data/vendor/PDCurses/demos/testcurs.c +1607 -0
- data/vendor/PDCurses/demos/tui.c +1048 -0
- data/vendor/PDCurses/demos/tui.h +65 -0
- data/vendor/PDCurses/demos/tuidemo.c +233 -0
- data/vendor/PDCurses/demos/version.c +61 -0
- data/vendor/PDCurses/demos/worm.c +432 -0
- data/vendor/PDCurses/demos/xmas.c +955 -0
- data/vendor/PDCurses/dos/CMakeLists.txt +47 -0
- data/vendor/PDCurses/dos/Makefile.bcc +83 -0
- data/vendor/PDCurses/dos/Makefile.dmc +257 -0
- data/vendor/PDCurses/dos/Makefile.msc +113 -0
- data/vendor/PDCurses/dos/Makefile.wcc +107 -0
- data/vendor/PDCurses/dos/README.md +51 -0
- data/vendor/PDCurses/dos/bccdos.lrf +9 -0
- data/vendor/PDCurses/dos/mscdos.lrf +50 -0
- data/vendor/PDCurses/dos/pdcclip.c +132 -0
- data/vendor/PDCurses/dos/pdcdisp.c +135 -0
- data/vendor/PDCurses/dos/pdcdos.h +194 -0
- data/vendor/PDCurses/dos/pdcgetsc.c +98 -0
- data/vendor/PDCurses/dos/pdckbd.c +513 -0
- data/vendor/PDCurses/dos/pdcscrn.c +785 -0
- data/vendor/PDCurses/dos/pdcsetsc.c +101 -0
- data/vendor/PDCurses/dos/pdcutil.c +212 -0
- data/vendor/PDCurses/libobjs.mif +26 -0
- data/vendor/PDCurses/makedist.mif +20 -0
- data/vendor/PDCurses/man/README.md +21 -0
- data/vendor/PDCurses/man/intro.md +361 -0
- data/vendor/PDCurses/man/manext.c +119 -0
- data/vendor/PDCurses/man/sdl.md +152 -0
- data/vendor/PDCurses/man/sdl2.md +58 -0
- data/vendor/PDCurses/man/x11.md +407 -0
- data/vendor/PDCurses/ncurses/CMakeLists.txt +66 -0
- data/vendor/PDCurses/ncurses/README.md +26 -0
- data/vendor/PDCurses/ncurses/makefile +29 -0
- data/vendor/PDCurses/os2/CMakeLists.txt +41 -0
- data/vendor/PDCurses/os2/Makefile.bcc +90 -0
- data/vendor/PDCurses/os2/Makefile.wcc +43 -0
- data/vendor/PDCurses/os2/README.md +43 -0
- data/vendor/PDCurses/os2/iccos2.lrf +50 -0
- data/vendor/PDCurses/os2/iccos2.mak +256 -0
- data/vendor/PDCurses/os2/pdcclip.c +188 -0
- data/vendor/PDCurses/os2/pdcdisp.c +93 -0
- data/vendor/PDCurses/os2/pdcgetsc.c +89 -0
- data/vendor/PDCurses/os2/pdckbd.c +521 -0
- data/vendor/PDCurses/os2/pdcos2.h +55 -0
- data/vendor/PDCurses/os2/pdcscrn.c +449 -0
- data/vendor/PDCurses/os2/pdcsetsc.c +112 -0
- data/vendor/PDCurses/os2/pdcutil.c +52 -0
- data/vendor/PDCurses/panel.h +56 -0
- data/vendor/PDCurses/pdcurses/README.md +25 -0
- data/vendor/PDCurses/pdcurses/addch.c +693 -0
- data/vendor/PDCurses/pdcurses/addchstr.c +245 -0
- data/vendor/PDCurses/pdcurses/addstr.c +240 -0
- data/vendor/PDCurses/pdcurses/attr.c +359 -0
- data/vendor/PDCurses/pdcurses/beep.c +68 -0
- data/vendor/PDCurses/pdcurses/bkgd.c +223 -0
- data/vendor/PDCurses/pdcurses/border.c +411 -0
- data/vendor/PDCurses/pdcurses/clear.c +159 -0
- data/vendor/PDCurses/pdcurses/color.c +298 -0
- data/vendor/PDCurses/pdcurses/debug.c +109 -0
- data/vendor/PDCurses/pdcurses/delch.c +96 -0
- data/vendor/PDCurses/pdcurses/deleteln.c +211 -0
- data/vendor/PDCurses/pdcurses/deprec.c +27 -0
- data/vendor/PDCurses/pdcurses/getch.c +417 -0
- data/vendor/PDCurses/pdcurses/getstr.c +474 -0
- data/vendor/PDCurses/pdcurses/getyx.c +139 -0
- data/vendor/PDCurses/pdcurses/inch.c +127 -0
- data/vendor/PDCurses/pdcurses/inchstr.c +214 -0
- data/vendor/PDCurses/pdcurses/initscr.c +367 -0
- data/vendor/PDCurses/pdcurses/inopts.c +324 -0
- data/vendor/PDCurses/pdcurses/insch.c +271 -0
- data/vendor/PDCurses/pdcurses/insstr.c +264 -0
- data/vendor/PDCurses/pdcurses/instr.c +246 -0
- data/vendor/PDCurses/pdcurses/kernel.c +259 -0
- data/vendor/PDCurses/pdcurses/keyname.c +157 -0
- data/vendor/PDCurses/pdcurses/mouse.c +438 -0
- data/vendor/PDCurses/pdcurses/move.c +57 -0
- data/vendor/PDCurses/pdcurses/outopts.c +159 -0
- data/vendor/PDCurses/pdcurses/overlay.c +214 -0
- data/vendor/PDCurses/pdcurses/pad.c +260 -0
- data/vendor/PDCurses/pdcurses/panel.c +633 -0
- data/vendor/PDCurses/pdcurses/printw.c +126 -0
- data/vendor/PDCurses/pdcurses/refresh.c +279 -0
- data/vendor/PDCurses/pdcurses/scanw.c +578 -0
- data/vendor/PDCurses/pdcurses/scr_dump.c +213 -0
- data/vendor/PDCurses/pdcurses/scroll.c +101 -0
- data/vendor/PDCurses/pdcurses/slk.c +591 -0
- data/vendor/PDCurses/pdcurses/termattr.c +182 -0
- data/vendor/PDCurses/pdcurses/terminfo.c +217 -0
- data/vendor/PDCurses/pdcurses/touch.c +163 -0
- data/vendor/PDCurses/pdcurses/util.c +312 -0
- data/vendor/PDCurses/pdcurses/window.c +569 -0
- data/vendor/PDCurses/sdl1/Makefile.mng +110 -0
- data/vendor/PDCurses/sdl1/README.md +31 -0
- data/vendor/PDCurses/sdl1/deffont.h +385 -0
- data/vendor/PDCurses/sdl1/deficon.h +23 -0
- data/vendor/PDCurses/sdl1/pdcclip.c +131 -0
- data/vendor/PDCurses/sdl1/pdcdisp.c +373 -0
- data/vendor/PDCurses/sdl1/pdcgetsc.c +30 -0
- data/vendor/PDCurses/sdl1/pdckbd.c +405 -0
- data/vendor/PDCurses/sdl1/pdcscrn.c +414 -0
- data/vendor/PDCurses/sdl1/pdcsdl.h +31 -0
- data/vendor/PDCurses/sdl1/pdcsetsc.c +64 -0
- data/vendor/PDCurses/sdl1/pdcutil.c +40 -0
- data/vendor/PDCurses/sdl1/sdltest.c +79 -0
- data/vendor/PDCurses/sdl2/CMakeLists.txt +76 -0
- data/vendor/PDCurses/sdl2/Makefile.vc +164 -0
- data/vendor/PDCurses/sdl2/README.md +34 -0
- data/vendor/PDCurses/sdl2/deffont.h +385 -0
- data/vendor/PDCurses/sdl2/deficon.h +23 -0
- data/vendor/PDCurses/sdl2/pdcclip.c +93 -0
- data/vendor/PDCurses/sdl2/pdcdisp.c +534 -0
- data/vendor/PDCurses/sdl2/pdcgetsc.c +30 -0
- data/vendor/PDCurses/sdl2/pdckbd.c +480 -0
- data/vendor/PDCurses/sdl2/pdcscrn.c +443 -0
- data/vendor/PDCurses/sdl2/pdcsdl.h +33 -0
- data/vendor/PDCurses/sdl2/pdcsetsc.c +67 -0
- data/vendor/PDCurses/sdl2/pdcutil.c +39 -0
- data/vendor/PDCurses/sdl2/sdltest.c +81 -0
- data/vendor/PDCurses/term.h +48 -0
- data/vendor/PDCurses/version.mif +7 -0
- data/vendor/PDCurses/vt/CMakeLists.txt +28 -0
- data/vendor/PDCurses/vt/Makefile.bcc +111 -0
- data/vendor/PDCurses/vt/Makefile.dmc +258 -0
- data/vendor/PDCurses/vt/Makefile.vc +144 -0
- data/vendor/PDCurses/vt/Makefile.wcc +107 -0
- data/vendor/PDCurses/vt/README.md +64 -0
- data/vendor/PDCurses/vt/pdcclip.c +20 -0
- data/vendor/PDCurses/vt/pdcdisp.c +284 -0
- data/vendor/PDCurses/vt/pdcgetsc.c +27 -0
- data/vendor/PDCurses/vt/pdckbd.c +394 -0
- data/vendor/PDCurses/vt/pdcscrn.c +434 -0
- data/vendor/PDCurses/vt/pdcsetsc.c +45 -0
- data/vendor/PDCurses/vt/pdcutil.c +43 -0
- data/vendor/PDCurses/vt/pdcvt.h +16 -0
- data/vendor/PDCurses/watcom.mif +68 -0
- data/vendor/PDCurses/wincon/CMakeLists.txt +27 -0
- data/vendor/PDCurses/wincon/Makefile.bcc +88 -0
- data/vendor/PDCurses/wincon/Makefile.dmc +256 -0
- data/vendor/PDCurses/wincon/Makefile.lcc +273 -0
- data/vendor/PDCurses/wincon/Makefile.mng +176 -0
- data/vendor/PDCurses/wincon/Makefile.vc +144 -0
- data/vendor/PDCurses/wincon/Makefile.wcc +51 -0
- data/vendor/PDCurses/wincon/README.md +85 -0
- data/vendor/PDCurses/wincon/pdcclip.c +174 -0
- data/vendor/PDCurses/wincon/pdcdisp.c +143 -0
- data/vendor/PDCurses/wincon/pdcgetsc.c +55 -0
- data/vendor/PDCurses/wincon/pdckbd.c +786 -0
- data/vendor/PDCurses/wincon/pdcscrn.c +717 -0
- data/vendor/PDCurses/wincon/pdcsetsc.c +91 -0
- data/vendor/PDCurses/wincon/pdcurses.ico +0 -0
- data/vendor/PDCurses/wincon/pdcurses.rc +28 -0
- data/vendor/PDCurses/wincon/pdcutil.c +41 -0
- data/vendor/PDCurses/wincon/pdcwin.h +31 -0
- data/vendor/PDCurses/wingui/CMakeLists.txt +27 -0
- data/vendor/PDCurses/wingui/Makefile.bcc +85 -0
- data/vendor/PDCurses/wingui/Makefile.dmc +259 -0
- data/vendor/PDCurses/wingui/Makefile.lcc +273 -0
- data/vendor/PDCurses/wingui/Makefile.mng +171 -0
- data/vendor/PDCurses/wingui/Makefile.vc +144 -0
- data/vendor/PDCurses/wingui/Makefile.wcc +51 -0
- data/vendor/PDCurses/wingui/README.md +93 -0
- data/vendor/PDCurses/wingui/pdcclip.c +174 -0
- data/vendor/PDCurses/wingui/pdcdisp.c +718 -0
- data/vendor/PDCurses/wingui/pdcgetsc.c +30 -0
- data/vendor/PDCurses/wingui/pdckbd.c +143 -0
- data/vendor/PDCurses/wingui/pdcscrn.c +2797 -0
- data/vendor/PDCurses/wingui/pdcsetsc.c +89 -0
- data/vendor/PDCurses/wingui/pdcurses.ico +0 -0
- data/vendor/PDCurses/wingui/pdcurses.rc +28 -0
- data/vendor/PDCurses/wingui/pdcutil.c +61 -0
- data/vendor/PDCurses/wingui/pdcwin.h +122 -0
- data/vendor/PDCurses/x11/Makefile.in +754 -0
- data/vendor/PDCurses/x11/PDCurses.spec +82 -0
- data/vendor/PDCurses/x11/README.md +62 -0
- data/vendor/PDCurses/x11/ScrollBox.c +319 -0
- data/vendor/PDCurses/x11/ScrollBox.h +51 -0
- data/vendor/PDCurses/x11/ScrollBoxP.h +70 -0
- data/vendor/PDCurses/x11/aclocal.m4 +994 -0
- data/vendor/PDCurses/x11/big_icon.xbm +46 -0
- data/vendor/PDCurses/x11/compose.h +201 -0
- data/vendor/PDCurses/x11/config.guess +1500 -0
- data/vendor/PDCurses/x11/config.h.in +100 -0
- data/vendor/PDCurses/x11/config.sub +1616 -0
- data/vendor/PDCurses/x11/configure +6700 -0
- data/vendor/PDCurses/x11/configure.ac +295 -0
- data/vendor/PDCurses/x11/debian/changelog +6 -0
- data/vendor/PDCurses/x11/debian/compat +1 -0
- data/vendor/PDCurses/x11/debian/control +11 -0
- data/vendor/PDCurses/x11/debian/copyright +27 -0
- data/vendor/PDCurses/x11/debian/rules +98 -0
- data/vendor/PDCurses/x11/install-sh +253 -0
- data/vendor/PDCurses/x11/little_icon.xbm +14 -0
- data/vendor/PDCurses/x11/ncurses_cfg.h +45 -0
- data/vendor/PDCurses/x11/pdcclip.c +173 -0
- data/vendor/PDCurses/x11/pdcdisp.c +85 -0
- data/vendor/PDCurses/x11/pdcgetsc.c +28 -0
- data/vendor/PDCurses/x11/pdckbd.c +104 -0
- data/vendor/PDCurses/x11/pdcscrn.c +258 -0
- data/vendor/PDCurses/x11/pdcsetsc.c +95 -0
- data/vendor/PDCurses/x11/pdcutil.c +52 -0
- data/vendor/PDCurses/x11/pdcx11.c +316 -0
- data/vendor/PDCurses/x11/pdcx11.h +191 -0
- data/vendor/PDCurses/x11/sb.c +155 -0
- data/vendor/PDCurses/x11/x11.c +3686 -0
- data/vendor/PDCurses/x11/xcurses-config.in +81 -0
- metadata +255 -21
@@ -0,0 +1,1048 @@
|
|
1
|
+
/********************************* tui.c ************************************/
|
2
|
+
/*
|
3
|
+
* 'textual user interface'
|
4
|
+
*
|
5
|
+
* Author : P.J. Kunst <kunst@prl.philips.nl>
|
6
|
+
* Date : 25-02-93
|
7
|
+
*/
|
8
|
+
|
9
|
+
#include <ctype.h>
|
10
|
+
#include <curses.h>
|
11
|
+
#include <stdio.h>
|
12
|
+
#include <stdlib.h>
|
13
|
+
#include <string.h>
|
14
|
+
#include <time.h>
|
15
|
+
#include "tui.h"
|
16
|
+
|
17
|
+
void statusmsg(char *);
|
18
|
+
int waitforkey(void);
|
19
|
+
void rmerror(void);
|
20
|
+
|
21
|
+
#if defined(__unix) && !defined(__DJGPP__)
|
22
|
+
#include <unistd.h>
|
23
|
+
#endif
|
24
|
+
|
25
|
+
#ifdef PDCURSES
|
26
|
+
#define HAVE_CLIPBOARD
|
27
|
+
#else
|
28
|
+
#define nc_getmouse getmouse
|
29
|
+
#endif
|
30
|
+
|
31
|
+
#ifdef A_COLOR
|
32
|
+
# define TITLECOLOR 1 /* color pair indices */
|
33
|
+
# define MAINMENUCOLOR (2 | A_BOLD)
|
34
|
+
# define MAINMENUREVCOLOR (3 | A_BOLD | A_REVERSE)
|
35
|
+
# define SUBMENUCOLOR (4 | A_BOLD)
|
36
|
+
# define SUBMENUREVCOLOR (5 | A_BOLD | A_REVERSE)
|
37
|
+
# define BODYCOLOR 6
|
38
|
+
# define STATUSCOLOR (7 | A_BOLD)
|
39
|
+
# define INPUTBOXCOLOR 8
|
40
|
+
# define EDITBOXCOLOR (9 | A_BOLD | A_REVERSE)
|
41
|
+
#else
|
42
|
+
# define TITLECOLOR 0 /* color pair indices */
|
43
|
+
# define MAINMENUCOLOR (A_BOLD)
|
44
|
+
# define MAINMENUREVCOLOR (A_BOLD | A_REVERSE)
|
45
|
+
# define SUBMENUCOLOR (A_BOLD)
|
46
|
+
# define SUBMENUREVCOLOR (A_BOLD | A_REVERSE)
|
47
|
+
# define BODYCOLOR 0
|
48
|
+
# define STATUSCOLOR (A_BOLD)
|
49
|
+
# define INPUTBOXCOLOR 0
|
50
|
+
# define EDITBOXCOLOR (A_BOLD | A_REVERSE)
|
51
|
+
#endif
|
52
|
+
|
53
|
+
|
54
|
+
#define th 1 /* title window height */
|
55
|
+
#define mh 1 /* main menu height */
|
56
|
+
#define sh 2 /* status window height */
|
57
|
+
#define bh (LINES - th - mh - sh) /* body window height */
|
58
|
+
#define bw COLS /* body window width */
|
59
|
+
|
60
|
+
|
61
|
+
/******************************* STATIC ************************************/
|
62
|
+
|
63
|
+
static WINDOW *wtitl, *wmain, *wbody, *wstat; /* title, menu, body, status win*/
|
64
|
+
static int nexty, nextx;
|
65
|
+
static int key = ERR, ch = ERR;
|
66
|
+
static bool quit = FALSE;
|
67
|
+
static bool incurses = FALSE;
|
68
|
+
|
69
|
+
#ifndef PDCURSES
|
70
|
+
static char wordchar(void)
|
71
|
+
{
|
72
|
+
return 0x17; /* ^W */
|
73
|
+
}
|
74
|
+
#endif
|
75
|
+
|
76
|
+
static char *padstr(char *s, int length)
|
77
|
+
{
|
78
|
+
static char buf[MAXSTRLEN];
|
79
|
+
char fmt[10];
|
80
|
+
|
81
|
+
sprintf(fmt, (int)strlen(s) > length ? "%%.%ds" : "%%-%ds", length);
|
82
|
+
sprintf(buf, fmt, s);
|
83
|
+
|
84
|
+
return buf;
|
85
|
+
}
|
86
|
+
|
87
|
+
static char *prepad(char *s, int length)
|
88
|
+
{
|
89
|
+
int i;
|
90
|
+
char *p = s;
|
91
|
+
|
92
|
+
if (length > 0)
|
93
|
+
{
|
94
|
+
memmove((void *)(s + length), (const void *)s, strlen(s) + 1);
|
95
|
+
|
96
|
+
for (i = 0; i < length; i++)
|
97
|
+
*p++ = ' ';
|
98
|
+
}
|
99
|
+
|
100
|
+
return s;
|
101
|
+
}
|
102
|
+
|
103
|
+
static void rmline(WINDOW *win, int nr) /* keeps box lines intact */
|
104
|
+
{
|
105
|
+
mvwaddstr(win, nr, 1, padstr(" ", bw - 2));
|
106
|
+
wrefresh(win);
|
107
|
+
}
|
108
|
+
|
109
|
+
static void initcolor(void)
|
110
|
+
{
|
111
|
+
#ifdef A_COLOR
|
112
|
+
if (has_colors())
|
113
|
+
start_color();
|
114
|
+
|
115
|
+
/* foreground, background */
|
116
|
+
|
117
|
+
init_pair(TITLECOLOR & ~A_ATTR, COLOR_BLACK, COLOR_CYAN);
|
118
|
+
init_pair(MAINMENUCOLOR & ~A_ATTR, COLOR_WHITE, COLOR_CYAN);
|
119
|
+
init_pair(MAINMENUREVCOLOR & ~A_ATTR, COLOR_WHITE, COLOR_BLACK);
|
120
|
+
init_pair(SUBMENUCOLOR & ~A_ATTR, COLOR_WHITE, COLOR_CYAN);
|
121
|
+
init_pair(SUBMENUREVCOLOR & ~A_ATTR, COLOR_WHITE, COLOR_BLACK);
|
122
|
+
init_pair(BODYCOLOR & ~A_ATTR, COLOR_WHITE, COLOR_BLUE);
|
123
|
+
init_pair(STATUSCOLOR & ~A_ATTR, COLOR_WHITE, COLOR_CYAN);
|
124
|
+
init_pair(INPUTBOXCOLOR & ~A_ATTR, COLOR_BLACK, COLOR_CYAN);
|
125
|
+
init_pair(EDITBOXCOLOR & ~A_ATTR, COLOR_WHITE, COLOR_BLACK);
|
126
|
+
#endif
|
127
|
+
}
|
128
|
+
|
129
|
+
static void setcolor(WINDOW *win, chtype color)
|
130
|
+
{
|
131
|
+
chtype attr = color & A_ATTR; /* extract Bold, Reverse, Blink bits */
|
132
|
+
|
133
|
+
#ifdef A_COLOR
|
134
|
+
attr &= ~A_REVERSE; /* ignore reverse, use colors instead! */
|
135
|
+
wattrset(win, COLOR_PAIR(color & A_CHARTEXT) | attr);
|
136
|
+
#else
|
137
|
+
attr &= ~A_BOLD; /* ignore bold, gives messy display on HP-UX */
|
138
|
+
wattrset(win, attr);
|
139
|
+
#endif
|
140
|
+
}
|
141
|
+
|
142
|
+
static void colorbox(WINDOW *win, chtype color, int hasbox)
|
143
|
+
{
|
144
|
+
int maxy;
|
145
|
+
#ifndef PDCURSES
|
146
|
+
int maxx;
|
147
|
+
#endif
|
148
|
+
chtype attr = color & A_ATTR; /* extract Bold, Reverse, Blink bits */
|
149
|
+
|
150
|
+
setcolor(win, color);
|
151
|
+
|
152
|
+
#ifdef A_COLOR
|
153
|
+
if (has_colors())
|
154
|
+
wbkgd(win, COLOR_PAIR(color & A_CHARTEXT) | (attr & ~A_REVERSE));
|
155
|
+
else
|
156
|
+
#endif
|
157
|
+
wbkgd(win, attr);
|
158
|
+
|
159
|
+
werase(win);
|
160
|
+
|
161
|
+
#ifdef PDCURSES
|
162
|
+
maxy = getmaxy(win);
|
163
|
+
#else
|
164
|
+
getmaxyx(win, maxy, maxx);
|
165
|
+
#endif
|
166
|
+
if (hasbox && (maxy > 2))
|
167
|
+
box(win, 0, 0);
|
168
|
+
|
169
|
+
touchwin(win);
|
170
|
+
wrefresh(win);
|
171
|
+
}
|
172
|
+
|
173
|
+
static void idle(void)
|
174
|
+
{
|
175
|
+
char buf[MAXSTRLEN];
|
176
|
+
time_t t;
|
177
|
+
struct tm *tp;
|
178
|
+
|
179
|
+
if (time (&t) == -1)
|
180
|
+
return; /* time not available */
|
181
|
+
|
182
|
+
tp = localtime(&t);
|
183
|
+
sprintf(buf, " %.2d-%.2d-%.4d %.2d:%.2d:%.2d",
|
184
|
+
tp->tm_mday, tp->tm_mon + 1, tp->tm_year + 1900,
|
185
|
+
tp->tm_hour, tp->tm_min, tp->tm_sec);
|
186
|
+
|
187
|
+
mvwaddstr(wtitl, (int)0, (int)(bw - strlen(buf) - 2), buf);
|
188
|
+
wrefresh(wtitl);
|
189
|
+
}
|
190
|
+
|
191
|
+
static void menudim(menu *mp, int *lines, int *columns)
|
192
|
+
{
|
193
|
+
int n, l, mmax = 0;
|
194
|
+
|
195
|
+
for (n=0; mp->func; n++, mp++)
|
196
|
+
if ((l = (int)strlen(mp->name)) > mmax) mmax = l;
|
197
|
+
|
198
|
+
*lines = n;
|
199
|
+
*columns = mmax + 2;
|
200
|
+
}
|
201
|
+
|
202
|
+
static void setmenupos(int y, int x)
|
203
|
+
{
|
204
|
+
nexty = y;
|
205
|
+
nextx = x;
|
206
|
+
}
|
207
|
+
|
208
|
+
static void getmenupos(int *y, int *x)
|
209
|
+
{
|
210
|
+
*y = nexty;
|
211
|
+
*x = nextx;
|
212
|
+
}
|
213
|
+
|
214
|
+
static int hotkey(const char *s)
|
215
|
+
{
|
216
|
+
int c0 = *s; /* if no upper case found, return first char */
|
217
|
+
|
218
|
+
for (; *s; s++)
|
219
|
+
if (isupper((unsigned char)*s))
|
220
|
+
break;
|
221
|
+
|
222
|
+
return *s ? *s : c0;
|
223
|
+
}
|
224
|
+
|
225
|
+
static void repaintmenu(WINDOW *wmenu, menu *mp)
|
226
|
+
{
|
227
|
+
int i;
|
228
|
+
menu *p = mp;
|
229
|
+
|
230
|
+
for (i = 0; p->func; i++, p++)
|
231
|
+
mvwaddstr(wmenu, i + 1, 2, p->name);
|
232
|
+
|
233
|
+
touchwin(wmenu);
|
234
|
+
wrefresh(wmenu);
|
235
|
+
}
|
236
|
+
|
237
|
+
static void repaintmainmenu(int width, menu *mp)
|
238
|
+
{
|
239
|
+
int i;
|
240
|
+
menu *p = mp;
|
241
|
+
|
242
|
+
for (i = 0; p->func; i++, p++)
|
243
|
+
mvwaddstr(wmain, 0, i * width, prepad(padstr(p->name, width - 1), 1));
|
244
|
+
|
245
|
+
touchwin(wmain);
|
246
|
+
wrefresh(wmain);
|
247
|
+
}
|
248
|
+
|
249
|
+
static void mainhelp(void)
|
250
|
+
{
|
251
|
+
#ifdef ALT_X
|
252
|
+
statusmsg("Use arrow keys and Enter to select (Alt-X to quit)");
|
253
|
+
#else
|
254
|
+
statusmsg("Use arrow keys and Enter to select");
|
255
|
+
#endif
|
256
|
+
}
|
257
|
+
|
258
|
+
static void mainmenu(menu *mp)
|
259
|
+
{
|
260
|
+
int nitems, barlen, old = -1, cur = 0, c, cur0, x;
|
261
|
+
MEVENT mouse_event;
|
262
|
+
|
263
|
+
menudim(mp, &nitems, &barlen);
|
264
|
+
repaintmainmenu(barlen, mp);
|
265
|
+
#ifdef __PDCURSES__
|
266
|
+
nc_getmouse( &mouse_event);
|
267
|
+
#else
|
268
|
+
getmouse( &mouse_event);
|
269
|
+
#endif
|
270
|
+
mousemask( BUTTON1_DOUBLE_CLICKED | BUTTON1_PRESSED | BUTTON1_CLICKED |BUTTON3_DOUBLE_CLICKED |BUTTON3_PRESSED |BUTTON3_CLICKED , NULL);
|
271
|
+
|
272
|
+
while (!quit)
|
273
|
+
{
|
274
|
+
if (cur != old)
|
275
|
+
{
|
276
|
+
if (old != -1)
|
277
|
+
{
|
278
|
+
mvwaddstr(wmain, 0, old * barlen,
|
279
|
+
prepad(padstr(mp[old].name, barlen - 1), 1));
|
280
|
+
|
281
|
+
statusmsg(mp[cur].desc);
|
282
|
+
}
|
283
|
+
else
|
284
|
+
mainhelp();
|
285
|
+
|
286
|
+
setcolor(wmain, MAINMENUREVCOLOR);
|
287
|
+
|
288
|
+
mvwaddstr(wmain, 0, cur * barlen,
|
289
|
+
prepad(padstr(mp[cur].name, barlen - 1), 1));
|
290
|
+
|
291
|
+
setcolor(wmain, MAINMENUCOLOR);
|
292
|
+
old = cur;
|
293
|
+
wrefresh(wmain);
|
294
|
+
}
|
295
|
+
|
296
|
+
switch (c = (key != ERR ? key : waitforkey()))
|
297
|
+
{
|
298
|
+
#ifdef KEY_C2
|
299
|
+
case KEY_C2:
|
300
|
+
#endif
|
301
|
+
case KEY_DOWN:
|
302
|
+
|
303
|
+
case '\n': /* menu item selected */
|
304
|
+
touchwin(wbody);
|
305
|
+
wrefresh(wbody);
|
306
|
+
rmerror();
|
307
|
+
setmenupos(th + mh, cur * barlen);
|
308
|
+
curs_set(1);
|
309
|
+
(mp[cur].func)(); /* perform function */
|
310
|
+
curs_set(0);
|
311
|
+
|
312
|
+
switch (key)
|
313
|
+
{
|
314
|
+
#ifdef KEY_B1
|
315
|
+
case KEY_B1:
|
316
|
+
#endif
|
317
|
+
case KEY_LEFT:
|
318
|
+
cur = (cur + nitems - 1) % nitems;
|
319
|
+
key = '\n';
|
320
|
+
break;
|
321
|
+
|
322
|
+
#ifdef KEY_B3
|
323
|
+
case KEY_B3:
|
324
|
+
#endif
|
325
|
+
case KEY_RIGHT:
|
326
|
+
cur = (cur + 1) % nitems;
|
327
|
+
key = '\n';
|
328
|
+
break;
|
329
|
+
|
330
|
+
case KEY_MOUSE:
|
331
|
+
if(nc_getmouse(&mouse_event) == OK)
|
332
|
+
{
|
333
|
+
if((mouse_event.bstate & BUTTON1_PRESSED) || (mouse_event.bstate & BUTTON1_DOUBLE_CLICKED) || (mouse_event.bstate & BUTTON1_CLICKED))
|
334
|
+
{
|
335
|
+
for( x = 1; x <= nitems ; ++x){
|
336
|
+
if((mouse_event.x > (barlen * (x-1)) && mouse_event.x < (barlen * x) ) &&
|
337
|
+
(mouse_event.y == th )){
|
338
|
+
if(x>=1){
|
339
|
+
cur = x-1;
|
340
|
+
break;
|
341
|
+
}
|
342
|
+
else{
|
343
|
+
key = KEY_ESC;
|
344
|
+
break;
|
345
|
+
}
|
346
|
+
}
|
347
|
+
}
|
348
|
+
}
|
349
|
+
break;
|
350
|
+
}
|
351
|
+
break;
|
352
|
+
|
353
|
+
default:
|
354
|
+
key = ERR;
|
355
|
+
}
|
356
|
+
|
357
|
+
repaintmainmenu(barlen, mp);
|
358
|
+
old = -1;
|
359
|
+
break;
|
360
|
+
|
361
|
+
#ifdef KEY_B1
|
362
|
+
case KEY_B1:
|
363
|
+
#endif
|
364
|
+
case KEY_LEFT:
|
365
|
+
cur = (cur + nitems - 1) % nitems;
|
366
|
+
break;
|
367
|
+
|
368
|
+
#ifdef KEY_B3
|
369
|
+
case KEY_B3:
|
370
|
+
#endif
|
371
|
+
case KEY_RIGHT:
|
372
|
+
cur = (cur + 1) % nitems;
|
373
|
+
break;
|
374
|
+
|
375
|
+
case KEY_ESC:
|
376
|
+
mainhelp();
|
377
|
+
break;
|
378
|
+
|
379
|
+
case KEY_MOUSE:
|
380
|
+
if(nc_getmouse(&mouse_event) == OK)
|
381
|
+
{
|
382
|
+
if((mouse_event.bstate & BUTTON1_PRESSED) || (mouse_event.bstate & BUTTON1_DOUBLE_CLICKED) || (mouse_event.bstate & BUTTON1_CLICKED))
|
383
|
+
{
|
384
|
+
for( x = 1; x <= nitems ; ++x){
|
385
|
+
if((mouse_event.x > (barlen * (x-1)) && mouse_event.x < (barlen * x) ) &&
|
386
|
+
(mouse_event.y == th)){
|
387
|
+
cur = x-1;
|
388
|
+
key = '\n';
|
389
|
+
break;
|
390
|
+
}
|
391
|
+
}
|
392
|
+
}
|
393
|
+
break;
|
394
|
+
}
|
395
|
+
break;
|
396
|
+
|
397
|
+
default:
|
398
|
+
cur0 = cur;
|
399
|
+
|
400
|
+
do
|
401
|
+
{
|
402
|
+
cur = (cur + 1) % nitems;
|
403
|
+
|
404
|
+
} while ((cur != cur0) && (hotkey(mp[cur].name) != toupper(c)));
|
405
|
+
|
406
|
+
if (hotkey(mp[cur].name) == toupper(c))
|
407
|
+
key = '\n';
|
408
|
+
}
|
409
|
+
|
410
|
+
}
|
411
|
+
|
412
|
+
rmerror();
|
413
|
+
touchwin(wbody);
|
414
|
+
wrefresh(wbody);
|
415
|
+
}
|
416
|
+
|
417
|
+
static void cleanup(void) /* cleanup curses settings */
|
418
|
+
{
|
419
|
+
if (incurses)
|
420
|
+
{
|
421
|
+
delwin(wtitl);
|
422
|
+
delwin(wmain);
|
423
|
+
delwin(wbody);
|
424
|
+
delwin(wstat);
|
425
|
+
curs_set(1);
|
426
|
+
endwin();
|
427
|
+
incurses = FALSE;
|
428
|
+
}
|
429
|
+
}
|
430
|
+
|
431
|
+
|
432
|
+
/******************************* EXTERNAL **********************************/
|
433
|
+
|
434
|
+
void clsbody(void)
|
435
|
+
{
|
436
|
+
werase(wbody);
|
437
|
+
wmove(wbody, 0, 0);
|
438
|
+
}
|
439
|
+
|
440
|
+
int bodylen(void)
|
441
|
+
{
|
442
|
+
#ifdef PDCURSES
|
443
|
+
return getmaxy(wbody);
|
444
|
+
#else
|
445
|
+
int maxy, maxx;
|
446
|
+
|
447
|
+
getmaxyx(wbody, maxy, maxx);
|
448
|
+
return maxy;
|
449
|
+
#endif
|
450
|
+
}
|
451
|
+
|
452
|
+
WINDOW *bodywin(void)
|
453
|
+
{
|
454
|
+
return wbody;
|
455
|
+
}
|
456
|
+
|
457
|
+
void rmerror(void)
|
458
|
+
{
|
459
|
+
rmline(wstat, 0);
|
460
|
+
}
|
461
|
+
|
462
|
+
void rmstatus(void)
|
463
|
+
{
|
464
|
+
rmline(wstat, 1);
|
465
|
+
}
|
466
|
+
|
467
|
+
void titlemsg(char *msg)
|
468
|
+
{
|
469
|
+
mvwaddstr(wtitl, 0, 2, padstr(msg, bw - 3));
|
470
|
+
wrefresh(wtitl);
|
471
|
+
}
|
472
|
+
|
473
|
+
void bodymsg(char *msg)
|
474
|
+
{
|
475
|
+
waddstr(wbody, msg);
|
476
|
+
wrefresh(wbody);
|
477
|
+
}
|
478
|
+
|
479
|
+
void errormsg(char *msg)
|
480
|
+
{
|
481
|
+
beep();
|
482
|
+
mvwaddstr(wstat, 0, 2, padstr(msg, bw - 3));
|
483
|
+
wrefresh(wstat);
|
484
|
+
}
|
485
|
+
|
486
|
+
void statusmsg(char *msg)
|
487
|
+
{
|
488
|
+
mvwaddstr(wstat, 1, 2, padstr(msg, bw - 3));
|
489
|
+
wrefresh(wstat);
|
490
|
+
}
|
491
|
+
|
492
|
+
bool keypressed(void)
|
493
|
+
{
|
494
|
+
ch = wgetch(wbody);
|
495
|
+
|
496
|
+
return ch != ERR;
|
497
|
+
}
|
498
|
+
|
499
|
+
int getkey(void)
|
500
|
+
{
|
501
|
+
int c = ch;
|
502
|
+
|
503
|
+
ch = ERR;
|
504
|
+
#ifdef ALT_X
|
505
|
+
quit = (c == ALT_X); /* PC only ! */
|
506
|
+
#endif
|
507
|
+
return c;
|
508
|
+
}
|
509
|
+
|
510
|
+
int waitforkey(void)
|
511
|
+
{
|
512
|
+
do idle(); while (!keypressed());
|
513
|
+
return getkey();
|
514
|
+
}
|
515
|
+
|
516
|
+
void DoExit(void) /* terminate program */
|
517
|
+
{
|
518
|
+
quit = TRUE;
|
519
|
+
}
|
520
|
+
|
521
|
+
void domenu(menu *mp)
|
522
|
+
{
|
523
|
+
int y, x, nitems, barlen, mheight, mw, old = -1, cur = 0, cur0;
|
524
|
+
bool stop = FALSE;
|
525
|
+
WINDOW *wmenu;
|
526
|
+
MEVENT mouse_event;
|
527
|
+
|
528
|
+
curs_set(0);
|
529
|
+
getmenupos(&y, &x);
|
530
|
+
menudim(mp, &nitems, &barlen);
|
531
|
+
mheight = nitems + 2;
|
532
|
+
mw = barlen + 2;
|
533
|
+
wmenu = newwin(mheight, mw, y, x);
|
534
|
+
colorbox(wmenu, SUBMENUCOLOR, 1);
|
535
|
+
repaintmenu(wmenu, mp);
|
536
|
+
|
537
|
+
key = ERR;
|
538
|
+
#ifdef __PDCURSES__
|
539
|
+
nc_getmouse( &mouse_event);
|
540
|
+
#else
|
541
|
+
getmouse( &mouse_event);
|
542
|
+
#endif
|
543
|
+
mousemask( BUTTON1_DOUBLE_CLICKED | BUTTON1_PRESSED | BUTTON1_CLICKED |BUTTON3_DOUBLE_CLICKED |BUTTON3_PRESSED |BUTTON3_CLICKED , NULL);
|
544
|
+
|
545
|
+
while (!stop && !quit)
|
546
|
+
{
|
547
|
+
if (cur != old)
|
548
|
+
{
|
549
|
+
if (old != -1)
|
550
|
+
mvwaddstr(wmenu, old + 1, 1,
|
551
|
+
prepad(padstr(mp[old].name, barlen - 1), 1));
|
552
|
+
|
553
|
+
setcolor(wmenu, SUBMENUREVCOLOR);
|
554
|
+
mvwaddstr(wmenu, cur + 1, 1,
|
555
|
+
prepad(padstr(mp[cur].name, barlen - 1), 1));
|
556
|
+
|
557
|
+
setcolor(wmenu, SUBMENUCOLOR);
|
558
|
+
statusmsg(mp[cur].desc);
|
559
|
+
|
560
|
+
old = cur;
|
561
|
+
wrefresh(wmenu);
|
562
|
+
}
|
563
|
+
|
564
|
+
switch (key = ((key != ERR) ? key : waitforkey()))
|
565
|
+
{
|
566
|
+
case '\n': /* menu item selected */
|
567
|
+
touchwin(wbody);
|
568
|
+
wrefresh(wbody);
|
569
|
+
setmenupos(y + 1, x + 1);
|
570
|
+
rmerror();
|
571
|
+
|
572
|
+
key = ERR;
|
573
|
+
curs_set(1);
|
574
|
+
(mp[cur].func)(); /* perform function */
|
575
|
+
curs_set(0);
|
576
|
+
|
577
|
+
repaintmenu(wmenu, mp);
|
578
|
+
|
579
|
+
old = -1;
|
580
|
+
break;
|
581
|
+
|
582
|
+
#ifdef KEY_A2
|
583
|
+
case KEY_A2:
|
584
|
+
#endif
|
585
|
+
case KEY_UP:
|
586
|
+
cur = (cur + nitems - 1) % nitems;
|
587
|
+
key = ERR;
|
588
|
+
break;
|
589
|
+
|
590
|
+
#ifdef KEY_C2
|
591
|
+
case KEY_C2:
|
592
|
+
#endif
|
593
|
+
case KEY_DOWN:
|
594
|
+
cur = (cur + 1) % nitems;
|
595
|
+
key = ERR;
|
596
|
+
break;
|
597
|
+
|
598
|
+
case KEY_ESC:
|
599
|
+
#ifdef KEY_B1
|
600
|
+
case KEY_B1:
|
601
|
+
#endif
|
602
|
+
case KEY_LEFT:
|
603
|
+
#ifdef KEY_B3
|
604
|
+
case KEY_B3:
|
605
|
+
#endif
|
606
|
+
case KEY_RIGHT:
|
607
|
+
if (key == KEY_ESC)
|
608
|
+
key = ERR; /* return to prev submenu */
|
609
|
+
|
610
|
+
stop = TRUE;
|
611
|
+
break;
|
612
|
+
|
613
|
+
case KEY_MOUSE:
|
614
|
+
if(nc_getmouse(&mouse_event) == OK)
|
615
|
+
{
|
616
|
+
if((mouse_event.bstate & BUTTON1_PRESSED) || (mouse_event.bstate & BUTTON1_CLICKED))
|
617
|
+
{
|
618
|
+
if( mouse_event.y <= th+1)
|
619
|
+
{
|
620
|
+
key = KEY_ESC; /* exit menu */
|
621
|
+
break;
|
622
|
+
}
|
623
|
+
else if((mouse_event.y - (y-1) > 0) && mouse_event.y > th && mouse_event.y < y+mheight && mouse_event.y > y && mouse_event.x > x && mouse_event.x < mw +x)
|
624
|
+
{
|
625
|
+
cur = (mouse_event.y - y-1) % nitems;
|
626
|
+
key = ERR;
|
627
|
+
break;
|
628
|
+
|
629
|
+
}
|
630
|
+
else if(mouse_event.y > 0 && mouse_event.y != y-1 && mouse_event.x > 0 && mouse_event.x != x-1)
|
631
|
+
{
|
632
|
+
key = KEY_ESC; /* exit menu */
|
633
|
+
break;
|
634
|
+
}
|
635
|
+
stop = TRUE;
|
636
|
+
break;
|
637
|
+
}
|
638
|
+
else if(mouse_event.bstate & BUTTON1_DOUBLE_CLICKED)
|
639
|
+
{
|
640
|
+
if((mouse_event.y - (y-1) > 0) && mouse_event.y > th && mouse_event.y < y+mheight && mouse_event.y > y){
|
641
|
+
cur = (mouse_event.y - y-1) % nitems;
|
642
|
+
key = '\n';
|
643
|
+
break;
|
644
|
+
}else{
|
645
|
+
key = KEY_ESC;
|
646
|
+
break;
|
647
|
+
}
|
648
|
+
|
649
|
+
}
|
650
|
+
else if( (mouse_event.bstate & BUTTON3_PRESSED) || (mouse_event.bstate & BUTTON3_CLICKED))
|
651
|
+
{
|
652
|
+
key = KEY_ESC;
|
653
|
+
break;
|
654
|
+
}
|
655
|
+
}
|
656
|
+
break;
|
657
|
+
|
658
|
+
default:
|
659
|
+
cur0 = cur;
|
660
|
+
|
661
|
+
do
|
662
|
+
{
|
663
|
+
cur = (cur + 1) % nitems;
|
664
|
+
|
665
|
+
} while ((cur != cur0) &&
|
666
|
+
(hotkey(mp[cur].name) != toupper((int)key)));
|
667
|
+
|
668
|
+
key = (hotkey(mp[cur].name) == toupper((int)key)) ? '\n' : ERR;
|
669
|
+
}
|
670
|
+
|
671
|
+
}
|
672
|
+
|
673
|
+
rmerror();
|
674
|
+
delwin(wmenu);
|
675
|
+
touchwin(wbody);
|
676
|
+
wrefresh(wbody);
|
677
|
+
}
|
678
|
+
|
679
|
+
void startmenu(menu *mp, char *mtitle)
|
680
|
+
{
|
681
|
+
initscr();
|
682
|
+
incurses = TRUE;
|
683
|
+
initcolor();
|
684
|
+
|
685
|
+
wtitl = subwin(stdscr, th, bw, 0, 0);
|
686
|
+
wmain = subwin(stdscr, mh, bw, th, 0);
|
687
|
+
wbody = subwin(stdscr, bh, bw, th + mh, 0);
|
688
|
+
wstat = subwin(stdscr, sh, bw, th + mh + bh, 0);
|
689
|
+
|
690
|
+
colorbox(wtitl, TITLECOLOR, 0);
|
691
|
+
colorbox(wmain, MAINMENUCOLOR, 0);
|
692
|
+
colorbox(wbody, BODYCOLOR, 0);
|
693
|
+
colorbox(wstat, STATUSCOLOR, 0);
|
694
|
+
|
695
|
+
if (mtitle)
|
696
|
+
titlemsg(mtitle);
|
697
|
+
|
698
|
+
cbreak(); /* direct input (no newline required)... */
|
699
|
+
noecho(); /* ... without echoing */
|
700
|
+
curs_set(0); /* hide cursor (if possible) */
|
701
|
+
nodelay(wbody, TRUE); /* don't wait for input... */
|
702
|
+
halfdelay(10); /* ...well, no more than a second, anyway */
|
703
|
+
keypad(wbody, TRUE); /* enable cursor keys */
|
704
|
+
scrollok(wbody, TRUE); /* enable scrolling in main window */
|
705
|
+
|
706
|
+
leaveok(stdscr, TRUE);
|
707
|
+
leaveok(wtitl, TRUE);
|
708
|
+
leaveok(wmain, TRUE);
|
709
|
+
leaveok(wstat, TRUE);
|
710
|
+
|
711
|
+
mainmenu(mp);
|
712
|
+
|
713
|
+
cleanup();
|
714
|
+
}
|
715
|
+
|
716
|
+
static void repainteditbox(WINDOW *win, int x, char *buf)
|
717
|
+
{
|
718
|
+
#ifndef PDCURSES
|
719
|
+
int maxy;
|
720
|
+
#endif
|
721
|
+
int maxx;
|
722
|
+
|
723
|
+
#ifdef PDCURSES
|
724
|
+
maxx = getmaxx(win);
|
725
|
+
#else
|
726
|
+
getmaxyx(win, maxy, maxx);
|
727
|
+
#endif
|
728
|
+
werase(win);
|
729
|
+
mvwprintw(win, 0, 0, "%s", padstr(buf, maxx));
|
730
|
+
wmove(win, 0, x);
|
731
|
+
wrefresh(win);
|
732
|
+
}
|
733
|
+
|
734
|
+
/*
|
735
|
+
|
736
|
+
weditstr() - edit string
|
737
|
+
|
738
|
+
Description:
|
739
|
+
The initial value of 'str' with a maximum length of 'field' - 1,
|
740
|
+
which is supplied by the calling routine, is editted. The user's
|
741
|
+
erase (^H), kill (^U) and delete word (^W) chars are interpreted.
|
742
|
+
The PC insert or Tab keys toggle between insert and edit mode.
|
743
|
+
Escape aborts the edit session, leaving 'str' unchanged.
|
744
|
+
Enter, Up or Down Arrow are used to accept the changes to 'str'.
|
745
|
+
NOTE: editstr(), mveditstr(), and mvweditstr() are macros.
|
746
|
+
|
747
|
+
Return Value:
|
748
|
+
Returns the input terminating character on success (Escape,
|
749
|
+
Enter, Up or Down Arrow) and ERR on error.
|
750
|
+
|
751
|
+
Errors:
|
752
|
+
It is an error to call this function with a NULL window pointer.
|
753
|
+
The length of the initial 'str' must not exceed 'field' - 1.
|
754
|
+
|
755
|
+
*/
|
756
|
+
|
757
|
+
int weditstr(WINDOW *win, char *buf, int field)
|
758
|
+
{
|
759
|
+
char org[MAXSTRLEN], *tp, *bp = buf;
|
760
|
+
bool defdisp = TRUE, stop = FALSE, insert = FALSE;
|
761
|
+
int cury, curx, begy, begx;
|
762
|
+
chtype oldattr;
|
763
|
+
WINDOW *wedit;
|
764
|
+
int c = 0;
|
765
|
+
#ifdef HAVE_CLIPBOARD
|
766
|
+
char *ptr = NULL;
|
767
|
+
long j, length = 0;
|
768
|
+
MEVENT mouse_event;
|
769
|
+
#ifdef __PDCURSES__
|
770
|
+
nc_getmouse( &mouse_event);
|
771
|
+
#else
|
772
|
+
getmouse( &mouse_event);
|
773
|
+
#endif
|
774
|
+
mousemask( BUTTON1_DOUBLE_CLICKED | BUTTON1_PRESSED | BUTTON1_CLICKED |BUTTON3_DOUBLE_CLICKED |BUTTON3_PRESSED |BUTTON3_CLICKED , NULL);
|
775
|
+
#endif
|
776
|
+
if ((field >= MAXSTRLEN) || (buf == NULL) ||
|
777
|
+
((int)strlen(buf) > field - 1))
|
778
|
+
return ERR;
|
779
|
+
|
780
|
+
strcpy(org, buf); /* save original */
|
781
|
+
|
782
|
+
wrefresh(win);
|
783
|
+
getyx(win, cury, curx);
|
784
|
+
getbegyx(win, begy, begx);
|
785
|
+
|
786
|
+
wedit = subwin(win, 1, field, begy + cury, begx + curx);
|
787
|
+
oldattr = wedit->_attrs;
|
788
|
+
colorbox(wedit, EDITBOXCOLOR, 0);
|
789
|
+
|
790
|
+
keypad(wedit, TRUE);
|
791
|
+
curs_set(1);
|
792
|
+
|
793
|
+
while (!stop)
|
794
|
+
{
|
795
|
+
idle();
|
796
|
+
repainteditbox(wedit, (int)(bp - buf), buf);
|
797
|
+
|
798
|
+
switch (c = wgetch(wedit))
|
799
|
+
{
|
800
|
+
case ERR:
|
801
|
+
break;
|
802
|
+
|
803
|
+
case KEY_ESC:
|
804
|
+
strcpy(buf, org); /* restore original */
|
805
|
+
stop = TRUE;
|
806
|
+
break;
|
807
|
+
|
808
|
+
case '\n':
|
809
|
+
#ifdef KEY_A2
|
810
|
+
case KEY_A2:
|
811
|
+
#endif
|
812
|
+
case KEY_UP:
|
813
|
+
#ifdef KEY_C2
|
814
|
+
case KEY_C2:
|
815
|
+
#endif
|
816
|
+
case KEY_DOWN:
|
817
|
+
stop = TRUE;
|
818
|
+
break;
|
819
|
+
|
820
|
+
#ifdef KEY_B1
|
821
|
+
case KEY_B1:
|
822
|
+
#endif
|
823
|
+
case KEY_LEFT:
|
824
|
+
if (bp > buf)
|
825
|
+
bp--;
|
826
|
+
break;
|
827
|
+
|
828
|
+
#ifdef KEY_B3
|
829
|
+
case KEY_B3:
|
830
|
+
#endif
|
831
|
+
case KEY_RIGHT:
|
832
|
+
defdisp = FALSE;
|
833
|
+
if (bp - buf < (int)strlen(buf))
|
834
|
+
bp++;
|
835
|
+
break;
|
836
|
+
#ifdef HAVE_CLIPBOARD
|
837
|
+
case KEY_MOUSE:
|
838
|
+
if(nc_getmouse(&mouse_event) == OK)
|
839
|
+
{
|
840
|
+
if(mouse_event.bstate & BUTTON1_DOUBLE_CLICKED){
|
841
|
+
if(mouse_event.y >= begy + cury && mouse_event.y <= begy + cury + 1 &&
|
842
|
+
mouse_event.x >= begx + curx && mouse_event.x <= begx + curx + field){
|
843
|
+
c = KEY_DOWN;
|
844
|
+
stop = TRUE;
|
845
|
+
break;
|
846
|
+
}else{
|
847
|
+
c = KEY_ESC;
|
848
|
+
strcpy(buf, org); /* restore original */
|
849
|
+
stop = TRUE;
|
850
|
+
break;
|
851
|
+
}
|
852
|
+
}
|
853
|
+
else if(mouse_event.bstate & BUTTON3_DOUBLE_CLICKED){
|
854
|
+
c = KEY_UP;
|
855
|
+
strcpy(buf, org); /* restore original */
|
856
|
+
stop = TRUE;
|
857
|
+
break;
|
858
|
+
}
|
859
|
+
else if( (mouse_event.bstate & BUTTON3_PRESSED) || (mouse_event.bstate & BUTTON3_CLICKED))
|
860
|
+
{
|
861
|
+
j = PDC_getclipboard(&ptr, &length);
|
862
|
+
switch(j)
|
863
|
+
{
|
864
|
+
case PDC_CLIP_ACCESS_ERROR:
|
865
|
+
strcpy(buf, org); /* restore original as default */
|
866
|
+
stop = TRUE;
|
867
|
+
c = KEY_ESC;
|
868
|
+
break;
|
869
|
+
case PDC_CLIP_MEMORY_ERROR:
|
870
|
+
strcpy(buf, org); /* restore original as default */
|
871
|
+
stop = TRUE;
|
872
|
+
c = KEY_ESC;
|
873
|
+
break;
|
874
|
+
case PDC_CLIP_EMPTY:
|
875
|
+
strcpy(buf, org); /* restore original as default */
|
876
|
+
stop = TRUE;
|
877
|
+
c = KEY_ESC;
|
878
|
+
break;
|
879
|
+
case PDC_CLIP_SUCCESS:
|
880
|
+
if ((int)strlen(ptr) && insert){
|
881
|
+
|
882
|
+
if ((int)strlen(buf) < field + 1 )
|
883
|
+
{
|
884
|
+
memmove((void *)(ptr+(int)strlen(ptr)), (const void *)bp, (int)strlen(buf)+1); /* Experimental insert/add to existing text*/
|
885
|
+
strncpy(bp, ptr, field - (int)strlen(buf)); /* copy clip-board to already existing field */
|
886
|
+
insert = !insert;
|
887
|
+
curs_set(insert ? 2 : 1);
|
888
|
+
while (bp - buf < (int)strlen(buf))
|
889
|
+
bp++;
|
890
|
+
}
|
891
|
+
}
|
892
|
+
break;
|
893
|
+
default:
|
894
|
+
strcpy(buf, org); /* restore original */
|
895
|
+
stop = TRUE;
|
896
|
+
c = KEY_ESC;
|
897
|
+
break;
|
898
|
+
}
|
899
|
+
}
|
900
|
+
}
|
901
|
+
break;
|
902
|
+
#endif
|
903
|
+
case '\t': /* TAB -- because insert
|
904
|
+
is broken on HPUX */
|
905
|
+
case KEY_IC: /* enter insert mode */
|
906
|
+
case KEY_EIC: /* exit insert mode */
|
907
|
+
defdisp = FALSE;
|
908
|
+
insert = !insert;
|
909
|
+
|
910
|
+
curs_set(insert ? 2 : 1);
|
911
|
+
break;
|
912
|
+
|
913
|
+
default:
|
914
|
+
if (c == erasechar()) /* backspace, ^H */
|
915
|
+
{
|
916
|
+
if (bp > buf)
|
917
|
+
{
|
918
|
+
memmove((void *)(bp - 1), (const void *)bp, strlen(bp) + 1);
|
919
|
+
bp--;
|
920
|
+
}
|
921
|
+
}
|
922
|
+
else if (c == killchar()) /* ^U */
|
923
|
+
{
|
924
|
+
bp = buf;
|
925
|
+
*bp = '\0';
|
926
|
+
}
|
927
|
+
else if (c == wordchar()) /* ^W */
|
928
|
+
{
|
929
|
+
tp = bp;
|
930
|
+
|
931
|
+
while ((bp > buf) && (*(bp - 1) == ' '))
|
932
|
+
bp--;
|
933
|
+
while ((bp > buf) && (*(bp - 1) != ' '))
|
934
|
+
bp--;
|
935
|
+
|
936
|
+
memmove((void *)bp, (const void *)tp, strlen(tp) + 1);
|
937
|
+
}
|
938
|
+
else if( c >=0 && c < 256 && isprint(c))
|
939
|
+
{
|
940
|
+
if (defdisp)
|
941
|
+
{
|
942
|
+
bp = buf;
|
943
|
+
*bp = '\0';
|
944
|
+
defdisp = FALSE;
|
945
|
+
}
|
946
|
+
|
947
|
+
if (insert)
|
948
|
+
{
|
949
|
+
if ((int)strlen(buf) < field - 1)
|
950
|
+
{
|
951
|
+
memmove((void *)(bp + 1), (const void *)bp,
|
952
|
+
strlen(bp) + 1);
|
953
|
+
|
954
|
+
*bp++ = c;
|
955
|
+
}
|
956
|
+
}
|
957
|
+
else if (bp - buf < field - 1)
|
958
|
+
{
|
959
|
+
/* append new string terminator */
|
960
|
+
|
961
|
+
if (!*bp)
|
962
|
+
bp[1] = '\0';
|
963
|
+
|
964
|
+
*bp++ = c;
|
965
|
+
}
|
966
|
+
}
|
967
|
+
}
|
968
|
+
}
|
969
|
+
|
970
|
+
curs_set(0);
|
971
|
+
|
972
|
+
wattrset(wedit, oldattr);
|
973
|
+
repainteditbox(wedit, (int)(bp - buf), buf);
|
974
|
+
delwin(wedit);
|
975
|
+
|
976
|
+
return c;
|
977
|
+
}
|
978
|
+
|
979
|
+
WINDOW *winputbox(WINDOW *win, int nlines, int ncols)
|
980
|
+
{
|
981
|
+
WINDOW *winp;
|
982
|
+
int cury, curx, begy, begx;
|
983
|
+
|
984
|
+
getyx(win, cury, curx);
|
985
|
+
getbegyx(win, begy, begx);
|
986
|
+
|
987
|
+
winp = newwin(nlines, ncols, begy + cury, begx + curx);
|
988
|
+
colorbox(winp, INPUTBOXCOLOR, 1);
|
989
|
+
|
990
|
+
return winp;
|
991
|
+
}
|
992
|
+
|
993
|
+
int getstrings(char *desc[], char *buf[], int field)
|
994
|
+
{
|
995
|
+
WINDOW *winput;
|
996
|
+
int oldy, oldx, maxy, maxx, nlines, ncols, i, n, l, mmax = 0;
|
997
|
+
int c = 0;
|
998
|
+
bool stop = FALSE;
|
999
|
+
|
1000
|
+
for (n = 0; desc[n]; n++)
|
1001
|
+
if ((l = (int)strlen(desc[n])) > mmax)
|
1002
|
+
mmax = l;
|
1003
|
+
|
1004
|
+
nlines = n + 2; ncols = mmax + field + 4;
|
1005
|
+
getyx(wbody, oldy, oldx);
|
1006
|
+
getmaxyx(wbody, maxy, maxx);
|
1007
|
+
|
1008
|
+
winput = mvwinputbox(wbody, (maxy - nlines) / 2, (maxx - ncols) / 2,
|
1009
|
+
nlines, ncols);
|
1010
|
+
|
1011
|
+
for (i = 0; i < n; i++)
|
1012
|
+
mvwprintw(winput, i + 1, 2, "%s", desc[i]);
|
1013
|
+
|
1014
|
+
i = 0;
|
1015
|
+
|
1016
|
+
while (!stop)
|
1017
|
+
{
|
1018
|
+
switch (c = mvweditstr(winput, i+1, mmax+3, buf[i], field))
|
1019
|
+
{
|
1020
|
+
case KEY_ESC:
|
1021
|
+
stop = TRUE;
|
1022
|
+
break;
|
1023
|
+
|
1024
|
+
#ifdef KEY_A2
|
1025
|
+
case KEY_A2:
|
1026
|
+
#endif
|
1027
|
+
case KEY_UP:
|
1028
|
+
i = (i + n - 1) % n;
|
1029
|
+
break;
|
1030
|
+
|
1031
|
+
case '\n':
|
1032
|
+
case '\t':
|
1033
|
+
#ifdef KEY_C2
|
1034
|
+
case KEY_C2:
|
1035
|
+
#endif
|
1036
|
+
case KEY_DOWN:
|
1037
|
+
if (++i == n)
|
1038
|
+
stop = TRUE; /* all passed? */
|
1039
|
+
}
|
1040
|
+
}
|
1041
|
+
|
1042
|
+
delwin(winput);
|
1043
|
+
touchwin(wbody);
|
1044
|
+
wmove(wbody, oldy, oldx);
|
1045
|
+
wrefresh(wbody);
|
1046
|
+
|
1047
|
+
return c;
|
1048
|
+
}
|