Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
9214 | turbocat | 1 | /* PDCurses */ |
2 | |||
3 | #include |
||
4 | |||
5 | /*man-start************************************************************** |
||
6 | |||
7 | insch |
||
8 | ----- |
||
9 | |||
10 | ### Synopsis |
||
11 | |||
12 | int insch(chtype ch); |
||
13 | int winsch(WINDOW *win, chtype ch); |
||
14 | int mvinsch(int y, int x, chtype ch); |
||
15 | int mvwinsch(WINDOW *win, int y, int x, chtype ch); |
||
16 | |||
17 | int insrawch(chtype ch); |
||
18 | int winsrawch(WINDOW *win, chtype ch); |
||
19 | int mvinsrawch(int y, int x, chtype ch); |
||
20 | int mvwinsrawch(WINDOW *win, int y, int x, chtype ch); |
||
21 | |||
22 | int ins_wch(const cchar_t *wch); |
||
23 | int wins_wch(WINDOW *win, const cchar_t *wch); |
||
24 | int mvins_wch(int y, int x, const cchar_t *wch); |
||
25 | int mvwins_wch(WINDOW *win, int y, int x, const cchar_t *wch); |
||
26 | |||
27 | ### Description |
||
28 | |||
29 | The insch() functions insert a chtype into the window at the current |
||
30 | or specified cursor position. The cursor is NOT advanced. A newline |
||
31 | is equivalent to clrtoeol(); tabs are expanded; other control |
||
32 | characters are converted as with unctrl(). |
||
33 | |||
34 | The ins_wch() functions are the wide-character equivalents, taking |
||
35 | cchar_t pointers rather than chtypes. |
||
36 | |||
37 | Video attributes can be combined with a character by ORing them into |
||
38 | the parameter. Text, including attributes, can be copied from one |
||
39 | place to another using inch() and insch(). |
||
40 | |||
41 | insrawch() etc. are PDCurses-specific wrappers for insch() etc. that |
||
42 | disable the translation of control characters. |
||
43 | |||
44 | ### Return Value |
||
45 | |||
46 | All functions return OK on success and ERR on error. |
||
47 | |||
48 | ### Portability |
||
49 | X/Open ncurses NetBSD |
||
50 | insch Y Y Y |
||
51 | winsch Y Y Y |
||
52 | mvinsch Y Y Y |
||
53 | mvwinsch Y Y Y |
||
54 | ins_wch Y Y Y |
||
55 | wins_wch Y Y Y |
||
56 | mvins_wch Y Y Y |
||
57 | mvwins_wch Y Y Y |
||
58 | insrawch - - - |
||
59 | winsrawch - - - |
||
60 | |||
61 | **man-end****************************************************************/ |
||
62 | |||
63 | #include |
||
64 | |||
65 | int winsch(WINDOW *win, chtype ch) |
||
66 | { |
||
67 | int x, y; |
||
68 | chtype attr; |
||
69 | bool xlat; |
||
70 | |||
71 | PDC_LOG(("winsch() - called: win=%p ch=%x (text=%c attr=0x%x)\n", |
||
72 | win, ch, ch & A_CHARTEXT, ch & A_ATTRIBUTES)); |
||
73 | |||
74 | if (!win) |
||
75 | return ERR; |
||
76 | |||
77 | x = win->_curx; |
||
78 | y = win->_cury; |
||
79 | |||
80 | if (y > win->_maxy || x > win->_maxx || y < 0 || x < 0) |
||
81 | return ERR; |
||
82 | |||
83 | xlat = !SP->raw_out && !(ch & A_ALTCHARSET); |
||
84 | attr = ch & A_ATTRIBUTES; |
||
85 | ch &= A_CHARTEXT; |
||
86 | |||
87 | if (xlat && (ch < ' ' || ch == 0x7f)) |
||
88 | { |
||
89 | int x2; |
||
90 | |||
91 | switch (ch) |
||
92 | { |
||
93 | case '\t': |
||
94 | for (x2 = ((x / TABSIZE) + 1) * TABSIZE; x < x2; x++) |
||
95 | { |
||
96 | if (winsch(win, attr | ' ') == ERR) |
||
97 | return ERR; |
||
98 | } |
||
99 | return OK; |
||
100 | |||
101 | case '\n': |
||
102 | wclrtoeol(win); |
||
103 | break; |
||
104 | |||
105 | case 0x7f: |
||
106 | if (winsch(win, attr | '?') == ERR) |
||
107 | return ERR; |
||
108 | |||
109 | return winsch(win, attr | '^'); |
||
110 | |||
111 | default: |
||
112 | /* handle control chars */ |
||
113 | |||
114 | if (winsch(win, attr | (ch + '@')) == ERR) |
||
115 | return ERR; |
||
116 | |||
117 | return winsch(win, attr | '^'); |
||
118 | } |
||
119 | } |
||
120 | else |
||
121 | { |
||
122 | int maxx; |
||
123 | chtype *temp; |
||
124 | |||
125 | /* If the incoming character doesn't have its own attribute, |
||
126 | then use the current attributes for the window. If it has |
||
127 | attributes but not a color component, OR the attributes to |
||
128 | the current attributes for the window. If it has a color |
||
129 | component, use the attributes solely from the incoming |
||
130 | character. */ |
||
131 | |||
132 | if (!(attr & A_COLOR)) |
||
133 | attr |= win->_attrs; |
||
134 | |||
135 | /* wrs (4/10/93): Apply the same sort of logic for the window |
||
136 | background, in that it only takes precedence if other color |
||
137 | attributes are not there and that the background character |
||
138 | will only print if the printing character is blank. */ |
||
139 | |||
140 | if (!(attr & A_COLOR)) |
||
141 | attr |= win->_bkgd & A_ATTRIBUTES; |
||
142 | else |
||
143 | attr |= win->_bkgd & (A_ATTRIBUTES ^ A_COLOR); |
||
144 | |||
145 | if (ch == ' ') |
||
146 | ch = win->_bkgd & A_CHARTEXT; |
||
147 | |||
148 | /* Add the attribute back into the character. */ |
||
149 | |||
150 | ch |= attr; |
||
151 | |||
152 | maxx = win->_maxx; |
||
153 | temp = &win->_y[y][x]; |
||
154 | |||
155 | memmove(temp + 1, temp, (maxx - x - 1) * sizeof(chtype)); |
||
156 | |||
157 | win->_lastch[y] = maxx - 1; |
||
158 | |||
159 | if ((win->_firstch[y] == _NO_CHANGE) || (win->_firstch[y] > x)) |
||
160 | win->_firstch[y] = x; |
||
161 | |||
162 | *temp = ch; |
||
163 | } |
||
164 | |||
165 | PDC_sync(win); |
||
166 | |||
167 | return OK; |
||
168 | } |
||
169 | |||
170 | int insch(chtype ch) |
||
171 | { |
||
172 | PDC_LOG(("insch() - called\n")); |
||
173 | |||
174 | return winsch(stdscr, ch); |
||
175 | } |
||
176 | |||
177 | int mvinsch(int y, int x, chtype ch) |
||
178 | { |
||
179 | PDC_LOG(("mvinsch() - called\n")); |
||
180 | |||
181 | if (move(y, x) == ERR) |
||
182 | return ERR; |
||
183 | |||
184 | return winsch(stdscr, ch); |
||
185 | } |
||
186 | |||
187 | int mvwinsch(WINDOW *win, int y, int x, chtype ch) |
||
188 | { |
||
189 | PDC_LOG(("mvwinsch() - called\n")); |
||
190 | |||
191 | if (wmove(win, y, x) == ERR) |
||
192 | return ERR; |
||
193 | |||
194 | return winsch(win, ch); |
||
195 | } |
||
196 | |||
197 | int winsrawch(WINDOW *win, chtype ch) |
||
198 | { |
||
199 | PDC_LOG(("winsrawch() - called: win=%p ch=%x " |
||
200 | "(char=%c attr=0x%x)\n", win, ch, |
||
201 | ch & A_CHARTEXT, ch & A_ATTRIBUTES)); |
||
202 | |||
203 | if ((ch & A_CHARTEXT) < ' ' || (ch & A_CHARTEXT) == 0x7f) |
||
204 | ch |= A_ALTCHARSET; |
||
205 | |||
206 | return winsch(win, ch); |
||
207 | } |
||
208 | |||
209 | int insrawch(chtype ch) |
||
210 | { |
||
211 | PDC_LOG(("insrawch() - called\n")); |
||
212 | |||
213 | return winsrawch(stdscr, ch); |
||
214 | } |
||
215 | |||
216 | int mvinsrawch(int y, int x, chtype ch) |
||
217 | { |
||
218 | PDC_LOG(("mvinsrawch() - called\n")); |
||
219 | |||
220 | if (move(y, x) == ERR) |
||
221 | return ERR; |
||
222 | |||
223 | return winsrawch(stdscr, ch); |
||
224 | } |
||
225 | |||
226 | int mvwinsrawch(WINDOW *win, int y, int x, chtype ch) |
||
227 | { |
||
228 | PDC_LOG(("mvwinsrawch() - called\n")); |
||
229 | |||
230 | if (wmove(win, y, x) == ERR) |
||
231 | return ERR; |
||
232 | |||
233 | return winsrawch(win, ch); |
||
234 | } |
||
235 | |||
236 | #ifdef PDC_WIDE |
||
237 | int wins_wch(WINDOW *win, const cchar_t *wch) |
||
238 | { |
||
239 | PDC_LOG(("wins_wch() - called\n")); |
||
240 | |||
241 | return wch ? winsch(win, *wch) : ERR; |
||
242 | } |
||
243 | |||
244 | int ins_wch(const cchar_t *wch) |
||
245 | { |
||
246 | PDC_LOG(("ins_wch() - called\n")); |
||
247 | |||
248 | return wins_wch(stdscr, wch); |
||
249 | } |
||
250 | |||
251 | int mvins_wch(int y, int x, const cchar_t *wch) |
||
252 | { |
||
253 | PDC_LOG(("mvins_wch() - called\n")); |
||
254 | |||
255 | if (move(y, x) == ERR) |
||
256 | return ERR; |
||
257 | |||
258 | return wins_wch(stdscr, wch); |
||
259 | } |
||
260 | |||
261 | int mvwins_wch(WINDOW *win, int y, int x, const cchar_t *wch) |
||
262 | { |
||
263 | PDC_LOG(("mvwins_wch() - called\n")); |
||
264 | |||
265 | if (wmove(win, y, x) == ERR) |
||
266 | return ERR; |
||
267 | |||
268 | return wins_wch(win, wch); |
||
269 | } |
||
270 | #endif>>>>> |