iPXE
Functions
windows.c File Reference

MuCurses windows instance functions. More...

#include <curses.h>
#include <stddef.h>
#include <stdlib.h>
#include "mucurses.h"

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
int delwin (WINDOW *win)
 Delete a window. More...
 
WINDOWderwin (WINDOW *parent, int nlines, int ncols, int begin_y, int begin_x)
 Create a new derived window. More...
 
WINDOWdupwin (WINDOW *orig)
 Create a duplicate of the specified window. More...
 
int mvwin (WINDOW *win, int y, int x)
 Move window origin to specified coordinates. More...
 
WINDOWnewwin (int nlines, int ncols, int begin_y, int begin_x)
 Create new WINDOW. More...
 
WINDOWsubwin (WINDOW *parent, int nlines, int ncols, int begin_y, int begin_x)
 Create a new sub-window. More...
 

Detailed Description

MuCurses windows instance functions.

Definition in file windows.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ delwin()

int delwin ( WINDOW win)

Delete a window.

Parameters
*winpointer to window being deleted
Return values
rcreturn status code

Definition at line 20 of file windows.c.

20  {
21  /* I think we should blank the region covered by the window -
22  ncurses doesn't do this, but they have a buffer, so they
23  may just be deleting from an offscreen context whereas we
24  are guaranteed to be deleting something onscreen */
25  wmove( win, 0, 0 );
26  chtype killch = (chtype)' ';
27  do {
28  _wputch( win, killch, WRAP );
29  } while ( win->curs_x + win->curs_y );
30 
31  free( win );
32 
33  wmove ( stdscr, 0, 0 );
34 
35  return OK;
36 }
int wmove(WINDOW *win, int y, int x) __nonnull
Move a window's cursor to the specified position.
Definition: mucurses.c:135
unsigned int curs_y
Definition: curses.h:97
Definition: sis900.h:208
#define stdscr
Definition: curses.h:110
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void _wputch(WINDOW *win, chtype ch, int wrap) __nonnull
Write a single character rendition to a window.
Definition: mucurses.c:50
uint32_t chtype
Definition: curses.h:29
#define WRAP
Definition: mucurses.h:12
unsigned int curs_x
window cursor position
Definition: curses.h:97

References _wputch(), _curses_window::curs_x, _curses_window::curs_y, free, OK, stdscr, wmove(), and WRAP.

◆ derwin()

WINDOW* derwin ( WINDOW parent,
int  nlines,
int  ncols,
int  begin_y,
int  begin_x 
)

Create a new derived window.

Parameters
parentparent window
nlineswindow height
ncolswindow width
begin_ywindow y origin (relative to parent)
begin_xwindow x origin (relative to parent)
Return values
ptrreturn pointer to child window

Definition at line 48 of file windows.c.

49  {
50  WINDOW *child;
51  if ( ( (unsigned)ncols > parent->width ) ||
52  ( (unsigned)nlines > parent->height ) )
53  return NULL;
54  if ( ( child = malloc( sizeof( WINDOW ) ) ) == NULL )
55  return NULL;
56  child->ori_y = parent->ori_y + begin_y;
57  child->ori_x = parent->ori_x + begin_x;
58  child->height = nlines;
59  child->width = ncols;
60  child->parent = parent;
61  child->scr = parent->scr;
62  return child;
63 }
Curses Window struct.
Definition: curses.h:89
unsigned int height
Definition: curses.h:99
unsigned int width
window dimensions
Definition: curses.h:99
SCREEN * scr
screen with which window associates
Definition: curses.h:91
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:583
struct _curses_window * parent
parent window
Definition: curses.h:101
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
unsigned int ori_x
window origin coordinates
Definition: curses.h:95
unsigned int ori_y
Definition: curses.h:95

References _curses_window::height, malloc(), NULL, _curses_window::ori_x, _curses_window::ori_y, _curses_window::parent, _curses_window::scr, and _curses_window::width.

◆ dupwin()

WINDOW* dupwin ( WINDOW orig)

Create a duplicate of the specified window.

Parameters
origoriginal window
Return values
ptrpointer to duplicate window

Definition at line 71 of file windows.c.

71  {
72  WINDOW *copy;
73  if ( ( copy = malloc( sizeof( WINDOW ) ) ) == NULL )
74  return NULL;
75  copy->scr = orig->scr;
76  copy->attrs = orig->attrs;
77  copy->ori_y = orig->ori_y;
78  copy->ori_x = orig->ori_x;
79  copy->curs_y = orig->curs_y;
80  copy->curs_x = orig->curs_x;
81  copy->height = orig->height;
82  copy->width = orig->width;
83  return copy;
84 }
Curses Window struct.
Definition: curses.h:89
unsigned int curs_y
Definition: curses.h:97
unsigned int height
Definition: curses.h:99
unsigned int width
window dimensions
Definition: curses.h:99
SCREEN * scr
screen with which window associates
Definition: curses.h:91
attr_t attrs
window attributes
Definition: curses.h:93
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:583
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
unsigned int curs_x
window cursor position
Definition: curses.h:97
unsigned int ori_x
window origin coordinates
Definition: curses.h:95
unsigned int ori_y
Definition: curses.h:95

References _curses_window::attrs, _curses_window::curs_x, _curses_window::curs_y, _curses_window::height, malloc(), NULL, _curses_window::ori_x, _curses_window::ori_y, _curses_window::scr, and _curses_window::width.

◆ mvwin()

int mvwin ( WINDOW win,
int  y,
int  x 
)

Move window origin to specified coordinates.

Parameters
*winwindow to move
yY position
xX position
Return values
rcreturn status code

Definition at line 94 of file windows.c.

94  {
95  if ( ( ( (unsigned)y + win->height ) > LINES ) ||
96  ( ( (unsigned)x + win->width ) > COLS ) )
97  return ERR;
98 
99  win->ori_y = y;
100  win->ori_x = x;
101 
102  return OK;
103 }
#define LINES(...)
Define inline lines.
Definition: linebuf_test.c:44
unsigned int height
Definition: curses.h:99
unsigned int width
window dimensions
Definition: curses.h:99
Definition: sis900.h:208
#define ERR
Definition: curses.h:18
#define COLS
Definition: curses.h:111
unsigned int y
Definition: cursor.h:13
unsigned int x
Definition: cursor.h:13
unsigned int ori_x
window origin coordinates
Definition: curses.h:95
unsigned int ori_y
Definition: curses.h:95

References COLS, ERR, _curses_window::height, LINES, OK, _curses_window::ori_x, _curses_window::ori_y, and _curses_window::width.

◆ newwin()

WINDOW* newwin ( int  nlines,
int  ncols,
int  begin_y,
int  begin_x 
)

Create new WINDOW.

Parameters
nlinesnumber of lines
ncolsnumber of columns
begin_ycolumn origin
begin_xline origin
Return values
*winreturn pointer to new window

Definition at line 114 of file windows.c.

114  {
115  WINDOW *win;
116  if ( ( (unsigned)( begin_y + nlines ) > stdscr->height ) &&
117  ( (unsigned)( begin_x + ncols ) > stdscr->width ) )
118  return NULL;
119  if ( ( win = malloc( sizeof(WINDOW) ) ) == NULL )
120  return NULL;
121  win->ori_y = begin_y;
122  win->ori_x = begin_x;
123  win->height = nlines;
124  win->width = ncols;
125  win->scr = stdscr->scr;
126  win->parent = stdscr;
127  return win;
128 }
Curses Window struct.
Definition: curses.h:89
unsigned int height
Definition: curses.h:99
unsigned int width
window dimensions
Definition: curses.h:99
#define stdscr
Definition: curses.h:110
SCREEN * scr
screen with which window associates
Definition: curses.h:91
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:583
struct _curses_window * parent
parent window
Definition: curses.h:101
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
unsigned int ori_x
window origin coordinates
Definition: curses.h:95
unsigned int ori_y
Definition: curses.h:95

References _curses_window::height, malloc(), NULL, _curses_window::ori_x, _curses_window::ori_y, _curses_window::parent, _curses_window::scr, stdscr, and _curses_window::width.

Referenced by subwin().

◆ subwin()

WINDOW* subwin ( WINDOW parent,
int  nlines,
int  ncols,
int  begin_y,
int  begin_x 
)

Create a new sub-window.

Parameters
origparent window
nlineswindow height
ncolswindow width
begin_ywindow y origin (absolute)
begin_xwindow x origin (absolute)
Return values
ptrreturn pointer to child window

Definition at line 140 of file windows.c.

141  {
142  WINDOW *child;
143  child = newwin( nlines, ncols, begin_y, begin_x );
144  child->parent = parent;
145  child->scr = parent->scr;
146  return child;
147 }
Curses Window struct.
Definition: curses.h:89
SCREEN * scr
screen with which window associates
Definition: curses.h:91
struct _curses_window * parent
parent window
Definition: curses.h:101
WINDOW * newwin(int nlines, int ncols, int begin_y, int begin_x)
Create new WINDOW.
Definition: windows.c:114

References newwin(), _curses_window::parent, and _curses_window::scr.