mirror of
https://github.com/VARCem/PDCurses.git
synced 2026-09-24 15:55:14 +00:00
A proper winsch() -- it wasn't handling the "special" characters
correctly before. This also lets me finally chuck PDC_chadd() (or rather, change PDC_chadd() to waddch() and chuck the wrapper). To Do: Make _attr_passthru() external and use it here?
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
* See the file maintain.er for details of the current maintainer. *
|
||||
************************************************************************/
|
||||
|
||||
/* $Id: curspriv.h,v 1.135 2006/11/03 14:08:10 wmcbrine Exp $ */
|
||||
/* $Id: curspriv.h,v 1.136 2006/11/07 16:32:13 wmcbrine Exp $ */
|
||||
|
||||
/* CURSPRIV.H
|
||||
|
||||
@@ -96,7 +96,6 @@ const char *PDC_sysname(void);
|
||||
|
||||
/* Internal cross-module functions */
|
||||
|
||||
int PDC_chadd(WINDOW *, chtype, bool);
|
||||
WINDOW *PDC_makenew(int, int, int, int);
|
||||
int PDC_mouse_in_slk(int, int);
|
||||
void PDC_slk_free(void);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
#include <curspriv.h>
|
||||
|
||||
RCSID("$Id: addch.c,v 1.42 2006/11/07 01:36:11 wmcbrine Exp $");
|
||||
RCSID("$Id: addch.c,v 1.43 2006/11/07 16:32:14 wmcbrine Exp $");
|
||||
|
||||
/*man-start**************************************************************
|
||||
|
||||
@@ -34,8 +34,6 @@ RCSID("$Id: addch.c,v 1.42 2006/11/07 01:36:11 wmcbrine Exp $");
|
||||
int echo_wchar(const cchar_t *wch);
|
||||
int wecho_wchar(WINDOW *win, const cchar_t *wch);
|
||||
|
||||
int PDC_chadd(WINDOW *win, chtype ch, bool advance);
|
||||
|
||||
X/Open Description:
|
||||
The routine addch() inserts the character ch into the default
|
||||
window at the current cursor position and the window cursor is
|
||||
@@ -91,15 +89,6 @@ RCSID("$Id: addch.c,v 1.42 2006/11/07 01:36:11 wmcbrine Exp $");
|
||||
attributes, can be copied from one place to another using inch()
|
||||
and addch().
|
||||
|
||||
PDCurses Description:
|
||||
PDC_chadd provides the basic functionality for [mv][w]addch().
|
||||
If 'advance' is TRUE, PDC_chadd() will move the current cusor
|
||||
position appropriately. The *addch functions call PDC_chadd()
|
||||
with advance TRUE, while the *insch functions call PDC_chadd()
|
||||
with advance FALSE. If an alternate character is to be
|
||||
displayed, the character is displayed without translation. This
|
||||
function returns OK on success and ERR on error.
|
||||
|
||||
X/Open Return Value:
|
||||
All functions return OK on success and ERR on error.
|
||||
|
||||
@@ -116,19 +105,18 @@ RCSID("$Id: addch.c,v 1.42 2006/11/07 01:36:11 wmcbrine Exp $");
|
||||
mvwadd_wch Y
|
||||
echo_wchar Y
|
||||
wecho_wchar Y
|
||||
PDC_chadd - - -
|
||||
|
||||
**man-end****************************************************************/
|
||||
|
||||
int PDC_chadd(WINDOW *win, chtype ch, bool advance)
|
||||
int waddch(WINDOW *win, chtype ch)
|
||||
{
|
||||
int x, y;
|
||||
chtype attr;
|
||||
bool xlat;
|
||||
|
||||
PDC_LOG(("PDC_chadd() - called: win=%p ch=%x "
|
||||
"(char=%c attr=0x%x) advance=%d\n", win, ch,
|
||||
ch & A_CHARTEXT, ch & A_ATTRIBUTES, advance));
|
||||
PDC_LOG(("waddch() - called: win=%p ch=%x "
|
||||
"(char=%c attr=0x%x)\n", win, ch,
|
||||
ch & A_CHARTEXT, ch & A_ATTRIBUTES));
|
||||
|
||||
if (!win)
|
||||
return ERR;
|
||||
@@ -272,11 +260,8 @@ int PDC_chadd(WINDOW *win, chtype ch, bool advance)
|
||||
}
|
||||
}
|
||||
|
||||
if (advance)
|
||||
{
|
||||
win->_curx = x;
|
||||
win->_cury = y;
|
||||
}
|
||||
win->_curx = x;
|
||||
win->_cury = y;
|
||||
|
||||
if (win->_immed)
|
||||
wrefresh(win);
|
||||
@@ -286,13 +271,6 @@ int PDC_chadd(WINDOW *win, chtype ch, bool advance)
|
||||
return OK;
|
||||
}
|
||||
|
||||
int waddch(WINDOW *win, const chtype ch)
|
||||
{
|
||||
PDC_LOG(("waddch() - called: win=%p ch=%x\n", win, ch));
|
||||
|
||||
return PDC_chadd(win, ch, TRUE);
|
||||
}
|
||||
|
||||
int addch(const chtype ch)
|
||||
{
|
||||
PDC_LOG(("addch() - called: ch=%x\n", ch));
|
||||
@@ -343,7 +321,7 @@ int wadd_wch(WINDOW *win, const cchar_t *wch)
|
||||
{
|
||||
PDC_LOG(("wadd_wch() - called: win=%p wch=%x\n", win, *wch));
|
||||
|
||||
return wch ? PDC_chadd(win, *wch, TRUE) : ERR;
|
||||
return wch ? waddch(win, *wch) : ERR;
|
||||
}
|
||||
|
||||
int add_wch(const cchar_t *wch)
|
||||
|
||||
112
pdcurses/insch.c
112
pdcurses/insch.c
@@ -14,7 +14,7 @@
|
||||
#include <curspriv.h>
|
||||
#include <string.h>
|
||||
|
||||
RCSID("$Id: insch.c,v 1.33 2006/11/05 03:57:26 wmcbrine Exp $");
|
||||
RCSID("$Id: insch.c,v 1.34 2006/11/07 16:32:14 wmcbrine Exp $");
|
||||
|
||||
/*man-start**************************************************************
|
||||
|
||||
@@ -78,10 +78,6 @@ RCSID("$Id: insch.c,v 1.33 2006/11/05 03:57:26 wmcbrine Exp $");
|
||||
attributes, can be copied from one place to another using inch()
|
||||
and insch().
|
||||
|
||||
PDCurses Description:
|
||||
Depending upon the state of the raw character output, 7- or
|
||||
8-bit characters will be output.
|
||||
|
||||
X/Open Return Value:
|
||||
All functions return OK on success and ERR on error.
|
||||
|
||||
@@ -99,36 +95,110 @@ RCSID("$Id: insch.c,v 1.33 2006/11/05 03:57:26 wmcbrine Exp $");
|
||||
|
||||
int winsch(WINDOW *win, chtype ch)
|
||||
{
|
||||
int x, y, maxx, offset;
|
||||
chtype *temp;
|
||||
int x, y;
|
||||
chtype attr;
|
||||
bool xlat;
|
||||
|
||||
PDC_LOG(("winsch() - called\n"));
|
||||
PDC_LOG(("winsch() - called: win=%p ch=%x "
|
||||
"(char=%c attr=0x%x)\n", win, ch,
|
||||
ch & A_CHARTEXT, ch & A_ATTRIBUTES));
|
||||
|
||||
if (!win)
|
||||
return ERR;
|
||||
|
||||
xlat = !(SP->raw_out) && !(ch & A_ALTCHARSET);
|
||||
|
||||
x = win->_curx;
|
||||
y = win->_cury;
|
||||
maxx = win->_maxx;
|
||||
temp = &win->_y[y][x];
|
||||
offset = 1;
|
||||
|
||||
if (((ch & A_CHARTEXT) < ' ') && xlat)
|
||||
offset++;
|
||||
if (y > win->_maxy || x > win->_maxx || y < 0 || x < 0)
|
||||
return ERR;
|
||||
|
||||
memmove(temp + offset, temp, (maxx - x - offset) * sizeof(chtype));
|
||||
xlat = !SP->raw_out && !(ch & A_ALTCHARSET);
|
||||
attr = ch & A_ATTRIBUTES;
|
||||
ch &= A_CHARTEXT;
|
||||
|
||||
win->_lastch[y] = maxx - 1;
|
||||
if (xlat && (ch < ' ' || ch == 0x7f))
|
||||
{
|
||||
int x2;
|
||||
|
||||
if ((win->_firstch[y] == _NO_CHANGE) || (win->_firstch[y] > x))
|
||||
win->_firstch[y] = x;
|
||||
switch (ch)
|
||||
{
|
||||
case '\t':
|
||||
for (x2 = ((x / TABSIZE) + 1) * TABSIZE; x < x2; x++)
|
||||
{
|
||||
if (winsch(win, ' ') == ERR)
|
||||
return ERR;
|
||||
}
|
||||
return OK;
|
||||
|
||||
/* PDC_chadd() fixes CTRL-chars too */
|
||||
case '\n':
|
||||
wclrtoeol(win);
|
||||
break;
|
||||
|
||||
return PDC_chadd(win, ch, FALSE);
|
||||
case 0x7f:
|
||||
if (winsch(win, '?') == ERR)
|
||||
return ERR;
|
||||
|
||||
return winsch(win, '^');
|
||||
|
||||
default:
|
||||
/* handle control chars */
|
||||
|
||||
if (winsch(win, ch + '@') == ERR)
|
||||
return ERR;
|
||||
|
||||
return winsch(win, '^');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int maxx;
|
||||
chtype *temp;
|
||||
|
||||
/* If the incoming character doesn't have its own
|
||||
attribute, then use the current attributes for
|
||||
the window. If it has attributes but not a color
|
||||
component, OR the attributes to the current
|
||||
attributes for the window. If it has a color
|
||||
component, use the attributes solely from the
|
||||
incoming character. */
|
||||
|
||||
if (!(attr & A_COLOR))
|
||||
attr |= win->_attrs;
|
||||
|
||||
/* wrs (4/10/93): Apply the same sort of logic for the
|
||||
window background, in that it only takes precedence
|
||||
if other color attributes are not there and that the
|
||||
background character will only print if the printing
|
||||
character is blank. */
|
||||
|
||||
if (!(attr & A_COLOR))
|
||||
attr |= win->_bkgd & A_ATTRIBUTES;
|
||||
else
|
||||
attr |= win->_bkgd & (A_ATTRIBUTES ^ A_COLOR);
|
||||
|
||||
if (ch == ' ')
|
||||
ch = win->_bkgd & A_CHARTEXT;
|
||||
|
||||
/* Add the attribute back into the character. */
|
||||
|
||||
ch |= attr;
|
||||
|
||||
maxx = win->_maxx;
|
||||
temp = &win->_y[y][x];
|
||||
|
||||
memmove(temp + 1, temp, (maxx - x - 1) * sizeof(chtype));
|
||||
|
||||
win->_lastch[y] = maxx - 1;
|
||||
|
||||
if ((win->_firstch[y] == _NO_CHANGE) || (win->_firstch[y] > x))
|
||||
win->_firstch[y] = x;
|
||||
|
||||
*temp = ch;
|
||||
}
|
||||
|
||||
PDC_sync(win);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
int insch(chtype ch)
|
||||
|
||||
Reference in New Issue
Block a user