Skip to content

Commit

Permalink
Merge pull request #106 from uhlin/master
Browse files Browse the repository at this point in the history
Curses window properties
  • Loading branch information
wmcbrine committed May 27, 2023
2 parents 8e2b0a2 + b3276a8 commit c4fa20c
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 12 deletions.
12 changes: 12 additions & 0 deletions curses.h
Original file line number Diff line number Diff line change
Expand Up @@ -1300,11 +1300,23 @@ PDCEX const char *curses_version(void);
PDCEX int find_pair(int, int);
PDCEX int free_pair(int);
PDCEX bool has_key(int);
PDCEX bool is_cleared(const WINDOW *);
PDCEX bool is_idcok(const WINDOW *);
PDCEX bool is_idlok(const WINDOW *);
PDCEX bool is_immedok(const WINDOW *);
PDCEX bool is_keypad(const WINDOW *);
PDCEX bool is_leaveok(const WINDOW *);
PDCEX bool is_nodelay(const WINDOW *);
PDCEX bool is_notimeout(const WINDOW *);
PDCEX bool is_pad(const WINDOW *);
PDCEX bool is_scrollok(const WINDOW *);
PDCEX bool is_subwin(const WINDOW *);
PDCEX bool is_syncok(const WINDOW *);
PDCEX int set_tabsize(int);
PDCEX int use_default_colors(void);
PDCEX int wgetdelay(const WINDOW *);
PDCEX WINDOW *wgetparent(const WINDOW *);
PDCEX int wgetscrreg(const WINDOW *, int *, int *);
PDCEX int wresize(WINDOW *, int, int);

PDCEX bool has_mouse(void);
Expand Down
59 changes: 51 additions & 8 deletions pdcurses/inopts.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ inopts
void qiflush(void);
void timeout(int delay);
void wtimeout(WINDOW *win, int delay);
int wgetdelay(const WINDOW *win);
int typeahead(int fildes);
int crmode(void);
int nocrmode(void);
bool is_keypad(const WINDOW *win);
bool is_nodelay(const WINDOW *win);
bool is_notimeout(const WINDOW *win);
### Description
Expand Down Expand Up @@ -83,6 +86,8 @@ inopts
delay is given; i.e., 1-99 will wait 50ms, 100-149 will wait 100ms,
etc.
wgetdelay() returns the delay timeout as set in wtimeout().
intrflush(), notimeout(), noqiflush(), qiflush() and typeahead() do
nothing in PDCurses, but are included for compatibility with other
curses implementations.
Expand All @@ -92,10 +97,16 @@ inopts
is_keypad() reports whether the specified window is in keypad mode.
is_nodelay() reports whether the specified window is in nodelay mode.
### Return Value
All functions except is_keypad() and the void functions return OK on
success and ERR on error.
All functions that returns an int returns OK on success and ERR on error.
is_keypad() and is_nodelay() returns TRUE or FALSE.
is_notimeout() is provided for compatibility with other curses
implementations, i.e. it always returns FALSE.
### Portability
X/Open ncurses NetBSD
Expand All @@ -117,10 +128,13 @@ inopts
qiflush Y Y Y
timeout Y Y Y
wtimeout Y Y Y
wgetdelay - Y -
typeahead Y Y Y
crmode Y Y Y
nocrmode Y Y Y
is_keypad - Y Y
is_nodelay - Y -
is_notimeout - Y -
**man-end****************************************************************/

Expand Down Expand Up @@ -295,11 +309,11 @@ void qiflush(void)
PDC_LOG(("qiflush() - called\n"));
}

int typeahead(int fildes)
void timeout(int delay)
{
PDC_LOG(("typeahead() - called\n"));
PDC_LOG(("timeout() - called\n"));

return OK;
wtimeout(stdscr, delay);
}

void wtimeout(WINDOW *win, int delay)
Expand Down Expand Up @@ -336,11 +350,21 @@ void wtimeout(WINDOW *win, int delay)
}
}

void timeout(int delay)
int wgetdelay(const WINDOW *win)
{
PDC_LOG(("timeout() - called\n"));
PDC_LOG(("wgetdelay() - called\n"));

wtimeout(stdscr, delay);
if (!win)
return 0;

return win->_delayms;
}

int typeahead(int fildes)
{
PDC_LOG(("typeahead() - called\n"));

return OK;
}

int crmode(void)
Expand All @@ -366,3 +390,22 @@ bool is_keypad(const WINDOW *win)

return win->_use_keypad;
}

bool is_nodelay(const WINDOW *win)
{
PDC_LOG(("is_nodelay() - called\n"));

if (!win)
return FALSE;

return win->_nodelay;
}

bool is_notimeout(const WINDOW *win)
{
(void) win;

PDC_LOG(("is_notimeout() - called - returning FALSE...\n"));

return FALSE;
}
94 changes: 91 additions & 3 deletions pdcurses/outopts.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ outopts
int leaveok(WINDOW *win, bool bf);
int setscrreg(int top, int bot);
int wsetscrreg(WINDOW *win, int top, int bot);
int wgetscrreg(const WINDOW *win, int *top, int *bot);
int scrollok(WINDOW *win, bool bf);
int raw_output(bool bf);
bool is_cleared(const WINDOW *win);
bool is_idlok(const WINDOW *win);
bool is_idcok(const WINDOW *win);
bool is_immedok(const WINDOW *win);
bool is_leaveok(const WINDOW *win);
bool is_scrollok(const WINDOW *win);
### Description
Expand All @@ -42,19 +48,34 @@ outopts
will cause all lines in the scrolling region to scroll up one line.
setscrreg() is the stdscr version.
wgetscrreg() gets the top and bottom margins as set in wsetscrreg().
idlok() and idcok() do nothing in PDCurses, but are provided for
compatibility with other curses implementations.
compatibility with other curses implementations, likewise is_idlok()
and is_idcok().
raw_output() enables the output of raw characters using the standard
*add* and *ins* curses functions (that is, it disables translation of
control characters).
is_cleared() reports whether the specified window causes clear at next
refresh.
is_immedok() reports whether the specified window is in immedok mode.
is_leaveok() reports whether the specified window is in leaveok mode.
is_scrollok() reports whether the specified window allows scrolling.
### Return Value
All functions except is_leaveok() return OK on success and ERR on
error.
All functions that returns an int returns OK on success and ERR on error.
is_cleared(), is_immedok(), is_leaveok() and is_scrollok() are booleans
and returns TRUE or FALSE.
is_idlok() and is_idcok() are provided for compatibility with other curses
implementations, i.e. they always returns FALSE.
### Portability
X/Open ncurses NetBSD
Expand All @@ -65,8 +86,14 @@ outopts
leaveok Y Y Y
setscrreg Y Y Y
wsetscrreg Y Y Y
wgetscrreg - Y -
scrollok Y Y Y
is_cleared - Y -
is_idlok - Y -
is_idcok - Y -
is_immedok - Y -
is_leaveok - Y Y
is_scrollok - Y -
raw_output - - -
**man-end****************************************************************/
Expand Down Expand Up @@ -140,6 +167,19 @@ int wsetscrreg(WINDOW *win, int top, int bottom)
return ERR;
}

int wgetscrreg(const WINDOW *win, int *top, int *bot)
{
PDC_LOG(("wgetscrreg() - called\n"));

if (!win || !top || !bot)
return ERR;

*top = win->_tmarg;
*bot = win->_bmarg;

return OK;
}

int scrollok(WINDOW *win, bool bf)
{
PDC_LOG(("scrollok() - called\n"));
Expand All @@ -164,6 +204,44 @@ int raw_output(bool bf)
return OK;
}

bool is_cleared(const WINDOW *win)
{
PDC_LOG(("is_cleared() - called\n"));

if (!win)
return FALSE;

return win->_clear;
}

bool is_idlok(const WINDOW *win)
{
(void) win;

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

return FALSE;
}

bool is_idcok(const WINDOW *win)
{
(void) win;

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

return FALSE;
}

bool is_immedok(const WINDOW *win)
{
PDC_LOG(("is_immedok() - called\n"));

if (!win)
return FALSE;

return win->_immed;
}

bool is_leaveok(const WINDOW *win)
{
PDC_LOG(("is_leaveok() - called\n"));
Expand All @@ -173,3 +251,13 @@ bool is_leaveok(const WINDOW *win)

return win->_leaveit;
}

bool is_scrollok(const WINDOW *win)
{
PDC_LOG(("is_scrollok() - called\n"));

if (!win)
return FALSE;

return win->_scroll;
}
48 changes: 47 additions & 1 deletion pdcurses/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ window
WINDOW *subwin(WINDOW* orig, int nlines, int ncols,
int begy, int begx);
WINDOW *dupwin(WINDOW *win);
WINDOW *wgetparent(const WINDOW *win);
int delwin(WINDOW *win);
int mvwin(WINDOW *win, int y, int x);
int mvderwin(WINDOW *win, int pary, int parx);
int syncok(WINDOW *win, bool bf);
bool is_subwin(const WINDOW *win);
bool is_syncok(const WINDOW *win);
void wsyncup(WINDOW *win);
void wcursyncup(WINDOW *win);
void wsyncdown(WINDOW *win);
Expand Down Expand Up @@ -64,11 +67,19 @@ window
dupwin() creates an exact duplicate of the window win.
wgetparent() returns the parent WINDOW pointer for subwindows, or NULL
for windows having no parent.
wsyncup() causes a touchwin() of all of the window's parents.
If wsyncok() is called with a second argument of TRUE, this causes a
If syncok() is called with a second argument of TRUE, this causes a
wsyncup() to be called every time the window is changed.
is_subwin() reports whether the specified window is a subwindow,
created by subwin() or derwin().
is_syncok() reports whether the specified window is in syncok mode.
wcursyncup() causes the current cursor position of all of a window's
ancestors to reflect the current cursor position of the current
window.
Expand Down Expand Up @@ -101,6 +112,8 @@ window
syncok() return OK or ERR. wsyncup(), wcursyncup() and wsyncdown()
return nothing.
is_subwin() and is_syncok() returns TRUE or FALSE.
### Errors
It is an error to call resize_window() before calling initscr().
Expand All @@ -119,8 +132,11 @@ window
derwin Y Y Y
mvderwin Y Y Y
dupwin Y Y Y
wgetparent - Y -
wsyncup Y Y Y
syncok Y Y Y
is_subwin - Y -
is_syncok - Y -
wcursyncup Y Y Y
wsyncdown Y Y Y
wresize - Y Y
Expand Down Expand Up @@ -447,6 +463,16 @@ WINDOW *dupwin(WINDOW *win)
return new;
}

WINDOW *wgetparent(const WINDOW *win)
{
PDC_LOG(("wgetparent() - called\n"));

if (!win || !win->_parent)
return NULL;

return win->_parent;
}

WINDOW *resize_window(WINDOW *win, int nlines, int ncols)
{
WINDOW *new;
Expand Down Expand Up @@ -564,6 +590,26 @@ int syncok(WINDOW *win, bool bf)
return OK;
}

bool is_subwin(const WINDOW *win)
{
PDC_LOG(("is_subwin() - called\n"));

if (!win)
return FALSE;

return ((win->_flags & _SUBWIN) ? TRUE : FALSE);
}

bool is_syncok(const WINDOW *win)
{
PDC_LOG(("is_syncok() - called\n"));

if (!win)
return FALSE;

return win->_sync;
}

void wcursyncup(WINDOW *win)
{
WINDOW *tmp;
Expand Down

0 comments on commit c4fa20c

Please sign in to comment.