Explorar el Código

initial check in

tags/v0.9.3
Dan Lynch hace 18 años
padre
commit
3994688804
Se han modificado 2 ficheros con 179 adiciones y 0 borrados
  1. 26
    0
      src/hci/mucurses/print_nadv.c
  2. 153
    0
      src/hci/mucurses/windows.c

+ 26
- 0
src/hci/mucurses/print_nadv.c Ver fichero

@@ -0,0 +1,26 @@
1
+#include <curses.h>
2
+#include "core.h"
3
+#include "cursor.h"
4
+
5
+/** @file
6
+ *
7
+ * MuCurses printing functions (no cursor advance)
8
+ *
9
+ */
10
+
11
+/**
12
+ * Add string of single-byte characters and renditions to a window
13
+ *
14
+ * @v *win	window to be rendered in
15
+ * @v *chstr	pointer to first chtype in "string"
16
+ * @v n		max number of chars from chstr to render
17
+ * @ret rc	return status code
18
+ */
19
+int waddchnstr ( WINDOW *win, const chtype *chstr, int n ) {
20
+	struct cursor_pos pos;	
21
+
22
+	_store_curs_pos( win, &pos );
23
+	_wputchstr( win, chstr, NOWRAP, n );
24
+	_restore_curs_pos( win, &pos );
25
+	return OK;
26
+}

+ 153
- 0
src/hci/mucurses/windows.c Ver fichero

@@ -0,0 +1,153 @@
1
+#include <curses.h>
2
+#include <stddef.h>
3
+#include <malloc.h>
4
+#include "core.h"
5
+
6
+/** @file
7
+ *
8
+ * MuCurses windows instance functions
9
+ *
10
+ */
11
+
12
+/**
13
+ * Delete a window
14
+ *
15
+ * @v *win	pointer to window being deleted
16
+ * @ret rc	return status code
17
+ */
18
+int delwin ( WINDOW *win ) {
19
+	if ( win == NULL )
20
+		return ERR;
21
+
22
+	/* I think we should blank the region covered by the window -
23
+	   ncurses doesn't do this, but they have a buffer, so they
24
+	   may just be deleting from an offscreen context whereas we
25
+	   are guaranteed to be deleting something onscreen */
26
+	wmove( win, 0, 0 );
27
+	chtype killch = (chtype)' ';
28
+	do {
29
+		_wputch( win, killch, WRAP );
30
+	} while ( win->curs_x + win->curs_y );
31
+
32
+	free( win );
33
+
34
+	wmove ( stdscr, 0, 0 );
35
+
36
+	return OK;
37
+}
38
+
39
+/**
40
+ * Create a new derived window
41
+ *
42
+ * @v parent	parent window
43
+ * @v nlines	window height
44
+ * @v ncols	window width
45
+ * @v begin_y	window y origin (relative to parent)
46
+ * @v begin_x	window x origin (relative to parent)
47
+ * @ret ptr	return pointer to child window
48
+ */
49
+WINDOW *derwin ( WINDOW *parent, int nlines, int ncols,
50
+	     		  	 int begin_y, int begin_x ) {
51
+	WINDOW *child;
52
+	if ( parent == NULL )
53
+		return NULL;
54
+	if ( ( (unsigned)ncols > parent->width ) || 
55
+	     ( (unsigned)nlines > parent->height ) )
56
+		return NULL;
57
+	child = malloc( sizeof( WINDOW ) );
58
+	child->ori_y = parent->ori_y + begin_y;
59
+	child->ori_x = parent->ori_x + begin_x;
60
+	child->height = nlines;
61
+	child->width = ncols;
62
+	child->parent = parent;
63
+	child->scr = parent->scr;
64
+	return child;
65
+}
66
+
67
+/**
68
+ * Create a duplicate of the specified window
69
+ *
70
+ * @v orig	original window
71
+ * @ret ptr	pointer to duplicate window
72
+ */
73
+WINDOW *dupwin ( WINDOW *orig ) {
74
+	WINDOW *copy;
75
+	if ( orig == NULL )
76
+		return NULL;
77
+	copy = malloc( sizeof( WINDOW ) );
78
+	copy->scr = orig->scr;
79
+	copy->attrs = orig->attrs;
80
+	copy->ori_y = orig->ori_y;
81
+	copy->ori_x = orig->ori_x;
82
+	copy->curs_y = orig->curs_y;
83
+	copy->curs_x = orig->curs_x;
84
+	copy->height = orig->height;
85
+	copy->width = orig->width;
86
+	return copy;
87
+}
88
+
89
+/**
90
+ * Move window origin to specified coordinates
91
+ *
92
+ * @v *win	window to move
93
+ * @v y		Y position
94
+ * @v x		X position
95
+ * @ret rc	return status code
96
+ */
97
+int mvwin ( WINDOW *win, int y, int x ) {
98
+	if ( win == NULL )
99
+		return ERR;
100
+	if ( ( ( (unsigned)y + win->height ) > LINES ) ||
101
+	     ( ( (unsigned)x + win->width ) > COLS ) )
102
+		return ERR;
103
+
104
+	win->ori_y = y;
105
+	win->ori_x = x;
106
+
107
+	return OK;
108
+}
109
+
110
+/**
111
+ * Create new WINDOW
112
+ *
113
+ * @v nlines	number of lines
114
+ * @v ncols	number of columns
115
+ * @v begin_y	column origin
116
+ * @v begin_x	line origin
117
+ * @ret *win	return pointer to new window
118
+ */
119
+WINDOW *newwin ( int nlines, int ncols, int begin_y, int begin_x ) {
120
+	WINDOW *win = malloc( sizeof(WINDOW) );
121
+	if ( ( (unsigned)( begin_y + nlines ) > stdscr->height ) &&
122
+	     ( (unsigned)( begin_x + ncols ) > stdscr->width ) )
123
+		return NULL;
124
+	win->ori_y = begin_y;
125
+	win->ori_x = begin_x;
126
+	win->height = nlines;
127
+	win->width = ncols;
128
+	win->scr = stdscr->scr;
129
+	win->parent = stdscr;
130
+	return win;
131
+}
132
+
133
+/**
134
+ * Create a new sub-window
135
+ *
136
+ * @v orig	parent window
137
+ * @v nlines	window height
138
+ * @v ncols	window width
139
+ * @v begin_y	window y origin (absolute)
140
+ * @v begin_x	window x origin (absolute)
141
+ * @ret ptr	return pointer to child window
142
+ */
143
+WINDOW *subwin ( WINDOW *parent, int nlines, int ncols,
144
+			         int begin_y, int begin_x ) {
145
+	WINDOW *child;
146
+	if ( parent == NULL )
147
+		return NULL;
148
+	child = malloc( sizeof( WINDOW ) );
149
+	child = newwin( nlines, ncols, begin_y, begin_x );
150
+	child->parent = parent;
151
+	child->scr = parent->scr;
152
+	return child;
153
+}

Loading…
Cancelar
Guardar