Beispiel #1
0
int mvgetn_wstr(int y, int x, wint_t *wstr, int n)
{
    PDC_LOG(("mvgetn_wstr() - called\n"));

    if (move(y, x) == ERR)
        return ERR;

    return wgetn_wstr(stdscr, wstr, n);
}
Beispiel #2
0
int
wget_wstr(WINDOW *w, wint_t *wis)
{
	int code;

	code = wgetn_wstr(w, wis, -1);

	return (code);
}
/*
 * getn_wstr --
 *	Get a string (of maximum n) characters from stdscr starting at
 *	(cury, curx).
 */
int
getn_wstr(wchar_t *wstr, int n)
{
#ifndef HAVE_WCHAR
	return ERR;
#else
	return wgetn_wstr(stdscr, wstr, n);
#endif /* HAVE_WCHAR */
}
Beispiel #4
0
int mvwgetn_wstr(WINDOW *win, int y, int x, wint_t *wstr, int n)
{
    PDC_LOG(("mvwgetn_wstr() - called\n"));

    if (wmove(win, y, x) == ERR)
        return ERR;

    return wgetn_wstr(win, wstr, n);
}
Beispiel #5
0
int
get_wstr(wint_t *wis)
{
	int code;

	code = wgetn_wstr(stdscr, wis, -1);

	return (code);
}
Beispiel #6
0
int
getn_wstr(wint_t *wis, int n)
{
	int code;

	code = wgetn_wstr(stdscr, wis, n);

	return (code);
}
Beispiel #7
0
int
mvgetn_wstr(int y, int x, wint_t *wis, int n)
{
	int code;

	if ((code = wmove(stdscr, y, x)) == OK)
		code = wgetn_wstr(stdscr, wis, n);

	return (code);
}
Beispiel #8
0
int
mvwgetn_wstr(WINDOW *w, int y, int x, wint_t *wis, int n)
{
	int code;

	if ((code = wmove(w, y, x)) == OK)
		code = wgetn_wstr(w, wis, n);

	return (code);
}
/*
 * mvwgetn_wstr --
 *  Get a string (of maximum n) characters from the given window starting
 *	at (y, x).
 */
int
mvwgetn_wstr(WINDOW *win, int y, int x, wchar_t *wstr, int n)
{
#ifndef HAVE_WCHAR
	return ERR;
#else
	if (wmove(win, y, x) == ERR)
		return ERR;

	return wgetn_wstr(win, wstr, n);
#endif /* HAVE_WCHAR */
}
Beispiel #10
0
/* Accept character strings from the curses terminal keyboard */
SCM
gucu_wgetnstr (SCM win, SCM n)
{
  SCM s_str;
  int ret;
  int c_n;

  c_n = scm_to_int (n);
  if (c_n <= 0)
    scm_out_of_range ("%wgetnstr", n);

#ifdef HAVE_NCURSESW
  {
    wint_t *c_wstr = (wint_t *) scm_malloc (sizeof (wint_t) * (c_n + 1));

    ret = wgetn_wstr (_scm_to_window (win), c_wstr, c_n);
    c_wstr[c_n] = 0;
    if (ret == OK)
      {
	s_str = _scm_sstring_from_wint_string (c_wstr);
	free (c_wstr);
      }
    else if (ret == KEY_RESIZE)
      {
	s_str = scm_from_int (KEY_RESIZE);
      }
    else
      abort ();
  }
#else
  {
    char *c_str = (char *) scm_malloc (sizeof (char) * (c_n + 1));

    ret = wgetnstr (_scm_to_window (win), c_str, c_n);
    c_str[c_n] = '\0';
    if (ret == OK)
      {
	s_str = scm_from_locale_string (c_str);
	free (c_str);
      }
    else if (ret == KEY_RESIZE)
      {
	s_str = scm_from_int (KEY_RESIZE);
      }
    else
      abort ();
  }
#endif

  return (s_str);
}
		//	Function responsible of reading a wide string of the given size. For size = 0, a maximum number of _buffer_size characters is read.
		std::wstring	PDCursesWindow::read_wstring( const unsigned int size )
		{
			std::wstring	return_value(L"");
			
			
			
			if ( _window != NULL )
			{
				wint_t*			buffer = NULL;
				unsigned int	buffer_size = 0;


				
				if ( size == 0 )
				{
					buffer = new (std::nothrow) wint_t[_buffer_size+1];
					buffer_size = _buffer_size;
				}
				else
				{
					buffer = new (std::nothrow) wint_t[size+1];
					buffer_size = size;
				}

				if ( buffer != NULL )
				{
					memset(buffer,'\0',buffer_size+1);
					wgetn_wstr(_window,buffer,buffer_size);

					for ( unsigned int i = 0;  i < size;  ++i )
						return_value += static_cast<wchar_t>(buffer[i]);
					
					delete[] buffer;
				}
			}


			return return_value;
		};
Beispiel #12
0
NCURSES_EXPORT(int) (getn_wstr) (wint_t * a1, int z)
{
	T((T_CALLED("getn_wstr(%p,%d)"), (const void *)a1, z)); returnCode(wgetn_wstr(stdscr,a1,z));
}
Beispiel #13
0
int getn_wstr(wint_t *wstr, int n)
{
    PDC_LOG(("getn_wstr() - called\n"));

    return wgetn_wstr(stdscr, wstr, n);
}
Beispiel #14
0
int wget_wstr(WINDOW *win, wint_t *wstr)
{
    PDC_LOG(("wget_wstr() - called\n"));

    return wgetn_wstr(win, wstr, MAXLINE);
}
Beispiel #15
0
int get_wstr(wint_t *wstr)
{
    PDC_LOG(("get_wstr() - called\n"));

    return wgetn_wstr(stdscr, wstr, MAXLINE);
}
Beispiel #16
0
NCURSES_EXPORT(int) (mvgetn_wstr) (int a1, int a2, wint_t * a3, int z)
{
	T((T_CALLED("mvgetn_wstr(%d,%d,%p,%d)"), a1, a2, (const void *)a3, z)); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : wgetn_wstr(stdscr,a3,z)));
}
Beispiel #17
0
NCURSES_EXPORT(int) (mvwgetn_wstr) (WINDOW * a1, int a2, int a3, wint_t * a4, int z)
{
	T((T_CALLED("mvwgetn_wstr(%p,%d,%d,%p,%d)"), (const void *)a1, a2, a3, (const void *)a4, z)); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : wgetn_wstr(a1,a4,z)));
}
Beispiel #18
0
NCURSES_EXPORT(int) (get_wstr) (wint_t * z)
{
	T((T_CALLED("get_wstr(%p)"), (const void *)z)); returnCode(wgetn_wstr(stdscr,z,-1));
}
Beispiel #19
0
NCURSES_EXPORT(int) (wget_wstr) (WINDOW * a1, wint_t * z)
{
	T((T_CALLED("wget_wstr(%p,%p)"), (const void *)a1, (const void *)z)); returnCode(wgetn_wstr(a1,z,-1));
}
Beispiel #20
0
// for emscripten
int wgetnstr(WINDOW *win, char *str, int n)
{
#ifdef PDC_WIDE
    wchar_t wstr[MAXLINE + 1];

    if (n < 0 || n > MAXLINE)
        n = MAXLINE;

    if (wgetn_wstr(win, (wint_t *)wstr, n) == ERR)
        return ERR;

    return PDC_wcstombs(str, wstr, n);
#else
    int ch, i, num, x, chars;
    char *p;
    bool stop, oldecho, oldcbreak, oldnodelay;

    PDC_LOG(("wgetnstr() - called\n"));

    if (!win || !str)
        return ERR;

    chars = 0;
    p = str;
    stop = FALSE;

    x = win->_curx;

    oldcbreak = SP->cbreak; /* remember states */
    oldecho = SP->echo;
    oldnodelay = win->_nodelay;

    SP->echo = FALSE;       /* we do echo ourselves */
    cbreak();               /* ensure each key is returned immediately */
    win->_nodelay = FALSE;  /* don't return -1 */

    wrefresh(win);

    while (!stop)
    {
        ch = wgetch(win);

        switch (ch)
        {

        case '\t':
            ch = ' ';
            num = TABSIZE - (win->_curx - x) % TABSIZE;
            for (i = 0; i < num; i++)
            {
                if (chars < n)
                {
                    if (oldecho) 
                        waddch(win, ch);
                    *p++ = ch;
                    ++chars;
                }
                else
                    beep();
            }
            break;

        case _ECHAR:        /* CTRL-H -- Delete character */
            if (p > str)
            {
                if (oldecho) 
                    waddstr(win, "\b \b");
                ch = (unsigned char)(*--p);
                if ((ch < ' ') && (oldecho))
                    waddstr(win, "\b \b");
                chars--;
            }
            break;

        case _DLCHAR:       /* CTRL-U -- Delete line */
            while (p > str)
            {
                if (oldecho) 
                    waddstr(win, "\b \b");
                ch = (unsigned char)(*--p);
                if ((ch < ' ') && (oldecho))
                    waddstr(win, "\b \b");
            }
            chars = 0;
            break;

        case _DWCHAR:       /* CTRL-W -- Delete word */

            while ((p > str) && (*(p - 1) == ' '))
            {
                if (oldecho) 
                    waddstr(win, "\b \b");

                --p;        /* remove space */
                chars--;
            }
            while ((p > str) && (*(p - 1) != ' '))
            {
                if (oldecho) 
                    waddstr(win, "\b \b");

                ch = (unsigned char)(*--p);
                if ((ch < ' ') && (oldecho))
                    waddstr(win, "\b \b");
                chars--;
            }
            break;

        case '\n':
        case '\r':
            stop = TRUE;
            if (oldecho) 
                waddch(win, '\n');
            break;

        default:
            if (chars < n)
            {
                if (!SP->key_code && ch < 0x100)
                {
                    *p++ = ch;
                    if (oldecho) 
                        waddch(win, ch);
                    chars++;
                }
            }
            else
                beep();

            break;
      
        }

        wrefresh(win);
    }

    *p = '\0';

    SP->echo = oldecho;     /* restore old settings */
    SP->cbreak = oldcbreak;
    win->_nodelay = oldnodelay;

    return OK;
#endif
}
Beispiel #21
0
static int
test_get_wstr(int level, char **argv, WINDOW *strwin)
{
    WINDOW *txtbox = 0;
    WINDOW *txtwin = 0;
    FILE *fp;
    int ch;
    int rc;
    int txt_x = 0, txt_y = 0;
    int base_y;
    int flavor = 0;
    int limit = getmaxx(strwin) - 5;
    int actual;
    wint_t buffer[MAX_COLS];

    if (argv[level] == 0) {
	beep();
	return FALSE;
    }

    if (level > 1) {
	txtbox = newwin(LINES - BASE_Y, COLS - level, BASE_Y, level);
	box(txtbox, 0, 0);
	wnoutrefresh(txtbox);

	txtwin = derwin(txtbox,
			getmaxy(txtbox) - 2,
			getmaxx(txtbox) - 2,
			1, 1);
	base_y = 0;
    } else {
	txtwin = stdscr;
	base_y = BASE_Y;
    }

    keypad(txtwin, TRUE);	/* enable keyboard mapping */
    (void) cbreak();		/* take input chars one at a time, no wait for \n */
    (void) noecho();		/* don't echo input */

    txt_y = base_y;
    txt_x = 0;
    wmove(txtwin, txt_y, txt_x);

    if ((fp = fopen(argv[level], "r")) != 0) {
	while ((ch = fgetc(fp)) != EOF) {
	    if (waddch(txtwin, UChar(ch)) != OK) {
		break;
	    }
	}
	fclose(fp);
    } else {
	wprintw(txtwin, "Cannot open:\n%s", argv[1]);
    }

    wmove(txtwin, txt_y, txt_x);
    actual = ShowFlavor(strwin, txtwin, flavor, limit);
    while (!Quit(ch = mvwgetch(txtwin, txt_y, txt_x))) {
	switch (ch) {
	case KEY_DOWN:
	case 'j':
	    if (txt_y < getmaxy(txtwin) - 1) {
		MovePrompt(txtwin, actual, ++txt_y, txt_x);
	    } else {
		beep();
	    }
	    break;
	case KEY_UP:
	case 'k':
	    if (txt_y > base_y) {
		MovePrompt(txtwin, actual, --txt_y, txt_x);
	    } else {
		beep();
	    }
	    break;
	case KEY_LEFT:
	case 'h':
	    if (txt_x > 0) {
		MovePrompt(txtwin, actual, txt_y, --txt_x);
	    } else {
		beep();
	    }
	    break;
	case KEY_RIGHT:
	case 'l':
	    if (txt_x < getmaxx(txtwin) - 1) {
		MovePrompt(txtwin, actual, txt_y, ++txt_x);
	    } else {
		beep();
	    }
	    break;

	case 'w':
	    test_get_wstr(level + 1, argv, strwin);
	    if (txtbox != 0) {
		touchwin(txtbox);
		wnoutrefresh(txtbox);
	    } else {
		touchwin(txtwin);
		wnoutrefresh(txtwin);
	    }
	    break;

	case '-':
	    if (limit > 0) {
		actual = ShowFlavor(strwin, txtwin, flavor, --limit);
		MovePrompt(txtwin, actual, txt_y, txt_x);
	    } else {
		beep();
	    }
	    break;

	case '+':
	    actual = ShowFlavor(strwin, txtwin, flavor, ++limit);
	    MovePrompt(txtwin, actual, txt_y, txt_x);
	    break;

	case '<':
	    if (flavor > 0) {
		actual = ShowFlavor(strwin, txtwin, --flavor, limit);
		MovePrompt(txtwin, actual, txt_y, txt_x);
	    } else {
		beep();
	    }
	    break;

	case '>':
	    if (flavor + 1 < eMaxFlavor) {
		actual = ShowFlavor(strwin, txtwin, ++flavor, limit);
		MovePrompt(txtwin, actual, txt_y, txt_x);
	    } else {
		beep();
	    }
	    break;

	case ':':
	    actual = ShowFlavor(strwin, txtwin, flavor, limit);
	    *buffer = '\0';
	    rc = ERR;
	    echo();
	    (void) wattrset(txtwin, A_REVERSE);
	    switch (flavor) {
	    case eGetStr:
		if (txtwin != stdscr) {
		    wmove(txtwin, txt_y, txt_x);
		    rc = wget_wstr(txtwin, buffer);
		} else {
		    move(txt_y, txt_x);
		    rc = get_wstr(buffer);
		}
		break;
	    case eGetNStr:
		if (txtwin != stdscr) {
		    wmove(txtwin, txt_y, txt_x);
		    rc = wgetn_wstr(txtwin, buffer, limit);
		} else {
		    move(txt_y, txt_x);
		    rc = getn_wstr(buffer, limit);
		}
		break;
	    case eMvGetStr:
		if (txtwin != stdscr) {
		    rc = mvwget_wstr(txtwin, txt_y, txt_x, buffer);
		} else {
		    rc = mvget_wstr(txt_y, txt_x, buffer);
		}
		break;
	    case eMvGetNStr:
		if (txtwin != stdscr) {
		    rc = mvwgetn_wstr(txtwin, txt_y, txt_x, buffer, limit);
		} else {
		    rc = mvgetn_wstr(txt_y, txt_x, buffer, limit);
		}
		break;
	    case eMaxFlavor:
		break;
	    }
	    noecho();
	    (void) wattrset(txtwin, A_NORMAL);
	    wprintw(strwin, "%d", rc);
	    (void) waddwstr(strwin, (wchar_t *) buffer);
	    wnoutrefresh(strwin);
	    break;
	default:
	    beep();
	    break;
	}
	doupdate();
    }
    if (level > 1) {
	delwin(txtwin);
	delwin(txtbox);
    }
    return TRUE;
}