X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=menu%2Fm_post.c;h=1dbd6b807bde8a673da7a2581e5f9f161a9db08c;hp=1f0b623ed456f192016dc8ae73ec45ee4ae834d6;hb=56a81c7e79f73d397cc8074401d039f59c34cad5;hpb=92e187a3459ab7ce1613a3684ca6642447c73620 diff --git a/menu/m_post.c b/menu/m_post.c index 1f0b623e..1dbd6b80 100644 --- a/menu/m_post.c +++ b/menu/m_post.c @@ -1,5 +1,6 @@ /**************************************************************************** - * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc. * + * Copyright 2020,2021 Thomas E. Dickey * + * Copyright 1998-2010,2012 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -37,7 +38,7 @@ #include "menu.priv.h" -MODULE_ID("$Id: m_post.c,v 1.29 2010/05/01 19:18:27 tom Exp $") +MODULE_ID("$Id: m_post.c,v 1.36 2021/05/08 20:20:01 tom Exp $") /*--------------------------------------------------------------------------- | Facility : libnmenu @@ -48,8 +49,8 @@ MODULE_ID("$Id: m_post.c,v 1.29 2010/05/01 19:18:27 tom Exp $") | | Return Values : - +--------------------------------------------------------------------------*/ -NCURSES_EXPORT(void) -_nc_Post_Item(const MENU * menu, const ITEM * item) +MENU_EXPORT(void) +_nc_Post_Item(const MENU *menu, const ITEM *item) { int i; chtype ch; @@ -57,7 +58,6 @@ _nc_Post_Item(const MENU * menu, const ITEM * item) int count = 0; bool isfore = FALSE, isback = FALSE, isgrey = FALSE; int name_len; - int desc_len; assert(menu->win); @@ -67,7 +67,7 @@ _nc_Post_Item(const MENU * menu, const ITEM * item) - it is a onevalued menu and it is the current item - or it has a selection value */ - wattron(menu->win, menu->back); + wattron(menu->win, (int)menu->back); if (item->value || (item == menu->curitem)) { if (menu->marklen) @@ -79,13 +79,13 @@ _nc_Post_Item(const MENU * menu, const ITEM * item) item. */ if (!(menu->opt & O_ONEVALUE) && item->value && item != menu->curitem) { - wattron(menu->win, menu->fore); + wattron(menu->win, (int)menu->fore); isfore = TRUE; } waddstr(menu->win, menu->mark); if (isfore) { - wattron(menu->win, menu->fore); + wattron(menu->win, (int)menu->fore); isfore = FALSE; } } @@ -93,7 +93,7 @@ _nc_Post_Item(const MENU * menu, const ITEM * item) else /* otherwise we have to wipe out the marker area */ for (ch = ' ', i = menu->marklen; i > 0; i--) waddch(menu->win, ch); - wattroff(menu->win, menu->back); + wattroff(menu->win, (int)menu->back); count += menu->marklen; /* First we have to calculate the attribute depending on selectability @@ -101,19 +101,19 @@ _nc_Post_Item(const MENU * menu, const ITEM * item) */ if (!(item->opt & O_SELECTABLE)) { - wattron(menu->win, menu->grey); + wattron(menu->win, (int)menu->grey); isgrey = TRUE; } else { if (item->value || item == menu->curitem) { - wattron(menu->win, menu->fore); + wattron(menu->win, (int)menu->fore); isfore = TRUE; } else { - wattron(menu->win, menu->back); + wattron(menu->win, (int)menu->back); isback = TRUE; } } @@ -131,6 +131,7 @@ _nc_Post_Item(const MENU * menu, const ITEM * item) { int m = menu->spc_desc / 2; int cy = -1, cx = -1; + int desc_len; for (ch = ' ', i = 0; i < menu->spc_desc; i++) { @@ -158,10 +159,10 @@ _nc_Post_Item(const MENU * menu, const ITEM * item) assert(cx >= 0 && cy >= 0); getyx(menu->win, ncy, ncx); if (isgrey) - wattroff(menu->win, menu->grey); + wattroff(menu->win, (int)menu->grey); else if (isfore) - wattroff(menu->win, menu->fore); - wattron(menu->win, menu->back); + wattroff(menu->win, (int)menu->fore); + wattron(menu->win, (int)menu->back); for (j = 1; j < menu->spc_rows; j++) { if ((item_y + j) < getmaxy(menu->win)) @@ -175,17 +176,17 @@ _nc_Post_Item(const MENU * menu, const ITEM * item) } wmove(menu->win, ncy, ncx); if (!isback) - wattroff(menu->win, menu->back); + wattroff(menu->win, (int)menu->back); } } /* Remove attributes */ if (isfore) - wattroff(menu->win, menu->fore); + wattroff(menu->win, (int)menu->fore); if (isback) - wattroff(menu->win, menu->back); + wattroff(menu->win, (int)menu->back); if (isgrey) - wattroff(menu->win, menu->grey); + wattroff(menu->win, (int)menu->grey); } /*--------------------------------------------------------------------------- @@ -196,11 +197,11 @@ _nc_Post_Item(const MENU * menu, const ITEM * item) | | Return Values : - +--------------------------------------------------------------------------*/ -NCURSES_EXPORT(void) -_nc_Draw_Menu(const MENU * menu) +MENU_EXPORT(void) +_nc_Draw_Menu(const MENU *menu) { ITEM *item = menu->items[0]; - ITEM *lasthor, *lastvert; + ITEM *lastvert; ITEM *hitem; int y = 0; chtype s_bkgd; @@ -212,45 +213,50 @@ _nc_Draw_Menu(const MENU * menu) werase(menu->win); wbkgdset(menu->win, s_bkgd); - lastvert = (menu->opt & O_NONCYCLIC) ? (ITEM *) 0 : item; + lastvert = (menu->opt & O_NONCYCLIC) ? (ITEM *)0 : item; - do + if (item != NULL) { - wmove(menu->win, y, 0); - - hitem = item; - lasthor = (menu->opt & O_NONCYCLIC) ? (ITEM *) 0 : hitem; - do { - _nc_Post_Item(menu, hitem); + ITEM *lasthor; + + wmove(menu->win, y, 0); - wattron(menu->win, menu->back); - if (((hitem = hitem->right) != lasthor) && hitem) + hitem = item; + lasthor = (menu->opt & O_NONCYCLIC) ? (ITEM *)0 : hitem; + + do { - int i, j, cy, cx; - chtype ch = ' '; + _nc_Post_Item(menu, hitem); - getyx(menu->win, cy, cx); - for (j = 0; j < menu->spc_rows; j++) + wattron(menu->win, (int)menu->back); + if (((hitem = hitem->right) != lasthor) && hitem) { - wmove(menu->win, cy + j, cx); - for (i = 0; i < menu->spc_cols; i++) + int i, j, cy, cx; + chtype ch = ' '; + + getyx(menu->win, cy, cx); + for (j = 0; j < menu->spc_rows; j++) { - waddch(menu->win, ch); + wmove(menu->win, cy + j, cx); + for (i = 0; i < menu->spc_cols; i++) + { + waddch(menu->win, ch); + } } + wmove(menu->win, cy, cx + menu->spc_cols); } - wmove(menu->win, cy, cx + menu->spc_cols); } - } - while (hitem && (hitem != lasthor)); - wattroff(menu->win, menu->back); + while (hitem && (hitem != lasthor)); + wattroff(menu->win, (int)menu->back); - item = item->down; - y += menu->spc_rows; + item = item->down; + y += menu->spc_rows; + } + while (item && (item != lastvert)); } - while (item && (item != lastvert)); } /*--------------------------------------------------------------------------- @@ -266,8 +272,8 @@ _nc_Draw_Menu(const MENU * menu) | E_BAD_STATE - Menu in userexit routine | E_POSTED - Menu already posted +--------------------------------------------------------------------------*/ -NCURSES_EXPORT(int) -post_menu(MENU * menu) +MENU_EXPORT(int) +post_menu(MENU *menu) { T((T_CALLED("post_menu(%p)"), (void *)menu)); @@ -282,7 +288,6 @@ post_menu(MENU * menu) if (menu->items && *(menu->items)) { - int y; int h = 1 + menu->spc_rows * (menu->rows - 1); WINDOW *win = Get_Menu_Window(menu); @@ -290,7 +295,8 @@ post_menu(MENU * menu) if ((menu->win = newpad(h, menu->width))) { - y = (maxy >= h) ? h : maxy; + int y = (maxy >= h) ? h : maxy; + if (y >= menu->height) y = menu->height; if (!(menu->sub = subpad(menu->win, y, menu->width, 0, 0))) @@ -305,7 +311,7 @@ post_menu(MENU * menu) else RETURN(E_NOT_CONNECTED); - menu->status |= _POSTED; + SetStatus(menu, _POSTED); if (!(menu->opt & O_ONEVALUE)) { @@ -338,8 +344,8 @@ post_menu(MENU * menu) | E_BAD_STATE - menu in userexit routine | E_NOT_POSTED - menu is not posted +--------------------------------------------------------------------------*/ -NCURSES_EXPORT(int) -unpost_menu(MENU * menu) +MENU_EXPORT(int) +unpost_menu(MENU *menu) { WINDOW *win; @@ -369,7 +375,7 @@ unpost_menu(MENU * menu) delwin(menu->win); menu->win = (WINDOW *)0; - menu->status &= ~_POSTED; + ClrStatus(menu, _POSTED); RETURN(E_OK); }