iPXE
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.
WINDOWderwin (WINDOW *parent, int nlines, int ncols, int begin_y, int begin_x)
 Create a new derived window.
WINDOWdupwin (WINDOW *orig)
 Create a duplicate of the specified window.
int mvwin (WINDOW *win, int y, int x)
 Move window origin to specified coordinates.
WINDOWnewwin (int nlines, int ncols, int begin_y, int begin_x)
 Create new WINDOW.
WINDOWsubwin (WINDOW *parent, int nlines, int ncols, int begin_y, int begin_x)
 Create a new sub-window.

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}
uint32_t chtype
Definition curses.h:30
#define stdscr
Definition curses.h:111
#define OK
Definition curses.h:25
int wmove(WINDOW *win, int y, int x) __nonnull
Move a window's cursor to the specified position.
Definition mucurses.c:136
void _wputch(WINDOW *win, chtype ch, int wrap) __nonnull
Write a single character rendition to a window.
Definition mucurses.c:51
#define WRAP
Definition mucurses.h:13
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55
unsigned int curs_x
window cursor position
Definition curses.h:98
unsigned int curs_y
Definition curses.h:98

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}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
struct _curses_window WINDOW
Curses Window struct.
void * malloc(size_t size)
Allocate memory.
Definition malloc.c:621
unsigned int ori_x
window origin coordinates
Definition curses.h:96
unsigned int width
window dimensions
Definition curses.h:100
unsigned int height
Definition curses.h:100
unsigned int ori_y
Definition curses.h:96
struct _curses_window * parent
parent window
Definition curses.h:102
SCREEN * scr
screen with which window associates
Definition curses.h:92

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}
attr_t attrs
window attributes
Definition curses.h:94

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 ERR
Definition curses.h:19
#define LINES(...)
Define inline lines.
static unsigned int unsigned int y
Definition pixbuf.h:63
static unsigned int x
Definition pixbuf.h:63
#define COLS
Definition vga.h:27

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

◆ 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}

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}
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.