| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
#include "menu.priv.h" |
| 39 |
|
| 40 |
MODULE_ID("$Id: m_post.c,v 1.29 2010/05/01 19:18:27 tom Exp $") |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
NCURSES_EXPORT(void) |
| 52 |
_nc_Post_Item(const MENU * menu, const ITEM * item) |
| 53 |
{ |
| 54 |
int i; |
| 55 |
chtype ch; |
| 56 |
int item_x, item_y; |
| 57 |
int count = 0; |
| 58 |
bool isfore = FALSE, isback = FALSE, isgrey = FALSE; |
| 59 |
int name_len; |
| 60 |
int desc_len; |
| 61 |
|
| 62 |
assert(menu->win); |
| 63 |
|
| 64 |
getyx(menu->win, item_y, item_x); |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
wattron(menu->win, menu->back); |
| 71 |
if (item->value || (item == menu->curitem)) |
| 72 |
{ |
| 73 |
if (menu->marklen) |
| 74 |
{ |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
if (!(menu->opt & O_ONEVALUE) && item->value && item != menu->curitem) |
| 81 |
{ |
| 82 |
wattron(menu->win, menu->fore); |
| 83 |
isfore = TRUE; |
| 84 |
} |
| 85 |
waddstr(menu->win, menu->mark); |
| 86 |
if (isfore) |
| 87 |
{ |
| 88 |
wattron(menu->win, menu->fore); |
| 89 |
isfore = FALSE; |
| 90 |
} |
| 91 |
} |
| 92 |
} |
| 93 |
else |
| 94 |
for (ch = ' ', i = menu->marklen; i > 0; i--) |
| 95 |
waddch(menu->win, ch); |
| 96 |
wattroff(menu->win, menu->back); |
| 97 |
count += menu->marklen; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
if (!(item->opt & O_SELECTABLE)) |
| 103 |
{ |
| 104 |
wattron(menu->win, menu->grey); |
| 105 |
isgrey = TRUE; |
| 106 |
} |
| 107 |
else |
| 108 |
{ |
| 109 |
if (item->value || item == menu->curitem) |
| 110 |
{ |
| 111 |
wattron(menu->win, menu->fore); |
| 112 |
isfore = TRUE; |
| 113 |
} |
| 114 |
else |
| 115 |
{ |
| 116 |
wattron(menu->win, menu->back); |
| 117 |
isback = TRUE; |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
waddnstr(menu->win, item->name.str, item->name.length); |
| 122 |
name_len = _nc_Calculate_Text_Width(&(item->name)); |
| 123 |
for (ch = ' ', i = menu->namelen - name_len; i > 0; i--) |
| 124 |
{ |
| 125 |
waddch(menu->win, ch); |
| 126 |
} |
| 127 |
count += menu->namelen; |
| 128 |
|
| 129 |
|
| 130 |
if ((menu->opt & O_SHOWDESC) && menu->desclen > 0) |
| 131 |
{ |
| 132 |
int m = menu->spc_desc / 2; |
| 133 |
int cy = -1, cx = -1; |
| 134 |
|
| 135 |
for (ch = ' ', i = 0; i < menu->spc_desc; i++) |
| 136 |
{ |
| 137 |
if (i == m) |
| 138 |
{ |
| 139 |
waddch(menu->win, menu->pad); |
| 140 |
getyx(menu->win, cy, cx); |
| 141 |
} |
| 142 |
else |
| 143 |
waddch(menu->win, ch); |
| 144 |
} |
| 145 |
if (item->description.length) |
| 146 |
waddnstr(menu->win, item->description.str, item->description.length); |
| 147 |
desc_len = _nc_Calculate_Text_Width(&(item->description)); |
| 148 |
for (ch = ' ', i = menu->desclen - desc_len; i > 0; i--) |
| 149 |
{ |
| 150 |
waddch(menu->win, ch); |
| 151 |
} |
| 152 |
count += menu->desclen + menu->spc_desc; |
| 153 |
|
| 154 |
if (menu->spc_rows > 1) |
| 155 |
{ |
| 156 |
int j, k, ncy, ncx; |
| 157 |
|
| 158 |
assert(cx >= 0 && cy >= 0); |
| 159 |
getyx(menu->win, ncy, ncx); |
| 160 |
if (isgrey) |
| 161 |
wattroff(menu->win, menu->grey); |
| 162 |
else if (isfore) |
| 163 |
wattroff(menu->win, menu->fore); |
| 164 |
wattron(menu->win, menu->back); |
| 165 |
for (j = 1; j < menu->spc_rows; j++) |
| 166 |
{ |
| 167 |
if ((item_y + j) < getmaxy(menu->win)) |
| 168 |
{ |
| 169 |
wmove(menu->win, item_y + j, item_x); |
| 170 |
for (k = 0; k < count; k++) |
| 171 |
waddch(menu->win, ' '); |
| 172 |
} |
| 173 |
if ((cy + j) < getmaxy(menu->win)) |
| 174 |
(void)mvwaddch(menu->win, cy + j, cx - 1, menu->pad); |
| 175 |
} |
| 176 |
wmove(menu->win, ncy, ncx); |
| 177 |
if (!isback) |
| 178 |
wattroff(menu->win, menu->back); |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
if (isfore) |
| 184 |
wattroff(menu->win, menu->fore); |
| 185 |
if (isback) |
| 186 |
wattroff(menu->win, menu->back); |
| 187 |
if (isgrey) |
| 188 |
wattroff(menu->win, menu->grey); |
| 189 |
} |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
NCURSES_EXPORT(void) |
| 200 |
_nc_Draw_Menu(const MENU * menu) |
| 201 |
{ |
| 202 |
ITEM *item = menu->items[0]; |
| 203 |
ITEM *lasthor, *lastvert; |
| 204 |
ITEM *hitem; |
| 205 |
int y = 0; |
| 206 |
chtype s_bkgd; |
| 207 |
|
| 208 |
assert(item && menu->win); |
| 209 |
|
| 210 |
s_bkgd = getbkgd(menu->win); |
| 211 |
wbkgdset(menu->win, menu->back); |
| 212 |
werase(menu->win); |
| 213 |
wbkgdset(menu->win, s_bkgd); |
| 214 |
|
| 215 |
lastvert = (menu->opt & O_NONCYCLIC) ? (ITEM *) 0 : item; |
| 216 |
|
| 217 |
do |
| 218 |
{ |
| 219 |
wmove(menu->win, y, 0); |
| 220 |
|
| 221 |
hitem = item; |
| 222 |
lasthor = (menu->opt & O_NONCYCLIC) ? (ITEM *) 0 : hitem; |
| 223 |
|
| 224 |
do |
| 225 |
{ |
| 226 |
_nc_Post_Item(menu, hitem); |
| 227 |
|
| 228 |
wattron(menu->win, menu->back); |
| 229 |
if (((hitem = hitem->right) != lasthor) && hitem) |
| 230 |
{ |
| 231 |
int i, j, cy, cx; |
| 232 |
chtype ch = ' '; |
| 233 |
|
| 234 |
getyx(menu->win, cy, cx); |
| 235 |
for (j = 0; j < menu->spc_rows; j++) |
| 236 |
{ |
| 237 |
wmove(menu->win, cy + j, cx); |
| 238 |
for (i = 0; i < menu->spc_cols; i++) |
| 239 |
{ |
| 240 |
waddch(menu->win, ch); |
| 241 |
} |
| 242 |
} |
| 243 |
wmove(menu->win, cy, cx + menu->spc_cols); |
| 244 |
} |
| 245 |
} |
| 246 |
while (hitem && (hitem != lasthor)); |
| 247 |
wattroff(menu->win, menu->back); |
| 248 |
|
| 249 |
item = item->down; |
| 250 |
y += menu->spc_rows; |
| 251 |
|
| 252 |
} |
| 253 |
while (item && (item != lastvert)); |
| 254 |
} |
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
NCURSES_EXPORT(int) |
| 270 |
post_menu(MENU * menu) |
| 271 |
{ |
| 272 |
T((T_CALLED("post_menu(%p)"), (void *)menu)); |
| 273 |
|
| 274 |
if (!menu) |
| 275 |
RETURN(E_BAD_ARGUMENT); |
| 276 |
|
| 277 |
if (menu->status & _IN_DRIVER) |
| 278 |
RETURN(E_BAD_STATE); |
| 279 |
|
| 280 |
if (menu->status & _POSTED) |
| 281 |
RETURN(E_POSTED); |
| 282 |
|
| 283 |
if (menu->items && *(menu->items)) |
| 284 |
{ |
| 285 |
int y; |
| 286 |
int h = 1 + menu->spc_rows * (menu->rows - 1); |
| 287 |
|
| 288 |
WINDOW *win = Get_Menu_Window(menu); |
| 289 |
int maxy = getmaxy(win); |
| 290 |
|
| 291 |
if ((menu->win = newpad(h+2, menu->width+2))) |
| 292 |
{ |
| 293 |
y = (maxy >= h) ? h : maxy; |
| 294 |
if (y >= menu->height) |
| 295 |
y = menu->height; |
| 296 |
if (!(menu->sub = subpad(menu->win, y, menu->width, 0, 0))) |
| 297 |
RETURN(E_SYSTEM_ERROR); |
| 298 |
} |
| 299 |
else |
| 300 |
RETURN(E_SYSTEM_ERROR); |
| 301 |
|
| 302 |
if (menu->status & _LINK_NEEDED) |
| 303 |
_nc_Link_Items(menu); |
| 304 |
} |
| 305 |
else |
| 306 |
RETURN(E_NOT_CONNECTED); |
| 307 |
|
| 308 |
menu->status |= _POSTED; |
| 309 |
|
| 310 |
if (!(menu->opt & O_ONEVALUE)) |
| 311 |
{ |
| 312 |
ITEM **items; |
| 313 |
|
| 314 |
for (items = menu->items; *items; items++) |
| 315 |
{ |
| 316 |
(*items)->value = FALSE; |
| 317 |
} |
| 318 |
} |
| 319 |
|
| 320 |
_nc_Draw_Menu(menu); |
| 321 |
|
| 322 |
Call_Hook(menu, menuinit); |
| 323 |
Call_Hook(menu, iteminit); |
| 324 |
|
| 325 |
_nc_Show_Menu(menu); |
| 326 |
|
| 327 |
RETURN(E_OK); |
| 328 |
} |
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
NCURSES_EXPORT(int) |
| 342 |
unpost_menu(MENU * menu) |
| 343 |
{ |
| 344 |
WINDOW *win; |
| 345 |
|
| 346 |
T((T_CALLED("unpost_menu(%p)"), (void *)menu)); |
| 347 |
|
| 348 |
if (!menu) |
| 349 |
RETURN(E_BAD_ARGUMENT); |
| 350 |
|
| 351 |
if (menu->status & _IN_DRIVER) |
| 352 |
RETURN(E_BAD_STATE); |
| 353 |
|
| 354 |
if (!(menu->status & _POSTED)) |
| 355 |
RETURN(E_NOT_POSTED); |
| 356 |
|
| 357 |
Call_Hook(menu, itemterm); |
| 358 |
Call_Hook(menu, menuterm); |
| 359 |
|
| 360 |
win = Get_Menu_Window(menu); |
| 361 |
werase(win); |
| 362 |
wsyncup(win); |
| 363 |
|
| 364 |
assert(menu->sub); |
| 365 |
delwin(menu->sub); |
| 366 |
menu->sub = (WINDOW *)0; |
| 367 |
|
| 368 |
assert(menu->win); |
| 369 |
delwin(menu->win); |
| 370 |
menu->win = (WINDOW *)0; |
| 371 |
|
| 372 |
menu->status &= ~_POSTED; |
| 373 |
|
| 374 |
RETURN(E_OK); |
| 375 |
} |
| 376 |
|
| 377 |
|