iPXE
windows.c
Go to the documentation of this file.
1#include <curses.h>
2#include <stddef.h>
3#include <stdlib.h>
4#include "mucurses.h"
5
6/** @file
7 *
8 * MuCurses windows instance functions
9 *
10 */
11
12FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
13
14/**
15 * Delete a window
16 *
17 * @v *win pointer to window being deleted
18 * @ret rc return status code
19 */
20int delwin ( WINDOW *win ) {
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}
37
38/**
39 * Create a new derived window
40 *
41 * @v parent parent window
42 * @v nlines window height
43 * @v ncols window width
44 * @v begin_y window y origin (relative to parent)
45 * @v begin_x window x origin (relative to parent)
46 * @ret ptr return pointer to child window
47 */
48WINDOW *derwin ( WINDOW *parent, int nlines, int ncols,
49 int begin_y, int begin_x ) {
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}
64
65/**
66 * Create a duplicate of the specified window
67 *
68 * @v orig original window
69 * @ret ptr pointer to duplicate window
70 */
71WINDOW *dupwin ( WINDOW *orig ) {
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}
85
86/**
87 * Move window origin to specified coordinates
88 *
89 * @v *win window to move
90 * @v y Y position
91 * @v x X position
92 * @ret rc return status code
93 */
94int mvwin ( WINDOW *win, int y, int x ) {
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}
104
105/**
106 * Create new WINDOW
107 *
108 * @v nlines number of lines
109 * @v ncols number of columns
110 * @v begin_y column origin
111 * @v begin_x line origin
112 * @ret *win return pointer to new window
113 */
114WINDOW *newwin ( int nlines, int ncols, int begin_y, int begin_x ) {
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}
129
130/**
131 * Create a new sub-window
132 *
133 * @v orig parent window
134 * @v nlines window height
135 * @v ncols window width
136 * @v begin_y window y origin (absolute)
137 * @v begin_x window x origin (absolute)
138 * @ret ptr return pointer to child window
139 */
140WINDOW *subwin ( WINDOW *parent, int nlines, int ncols,
141 int begin_y, int begin_x ) {
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}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
MuCurses header file.
uint32_t chtype
Definition curses.h:30
#define stdscr
Definition curses.h:111
#define ERR
Definition curses.h:19
#define OK
Definition curses.h:25
struct _curses_window WINDOW
Curses Window struct.
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define LINES(...)
Define inline lines.
void * malloc(size_t size)
Allocate memory.
Definition malloc.c:621
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
MuCurses core implementation specific header file.
#define WRAP
Definition mucurses.h:13
static unsigned int unsigned int y
Definition pixbuf.h:63
static unsigned int x
Definition pixbuf.h:63
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55
unsigned int ori_x
window origin coordinates
Definition curses.h:96
unsigned int curs_x
window cursor position
Definition curses.h:98
unsigned int width
window dimensions
Definition curses.h:100
unsigned int height
Definition curses.h:100
unsigned int ori_y
Definition curses.h:96
unsigned int curs_y
Definition curses.h:98
struct _curses_window * parent
parent window
Definition curses.h:102
attr_t attrs
window attributes
Definition curses.h:94
SCREEN * scr
screen with which window associates
Definition curses.h:92
#define COLS
Definition vga.h:27
int mvwin(WINDOW *win, int y, int x)
Move window origin to specified coordinates.
Definition windows.c:94
WINDOW * newwin(int nlines, int ncols, int begin_y, int begin_x)
Create new WINDOW.
Definition windows.c:114
int delwin(WINDOW *win)
Delete a window.
Definition windows.c:20
WINDOW * subwin(WINDOW *parent, int nlines, int ncols, int begin_y, int begin_x)
Create a new sub-window.
Definition windows.c:140
WINDOW * derwin(WINDOW *parent, int nlines, int ncols, int begin_y, int begin_x)
Create a new derived window.
Definition windows.c:48
WINDOW * dupwin(WINDOW *orig)
Create a duplicate of the specified window.
Definition windows.c:71