1 /*-----------------------------------------------------------------------------+
2 | The ncurses menu library is Copyright (C) 1995-1997 |
3 | by Juergen Pfeifer <Juergen.Pfeifer@T-Online.de> |
4 | All Rights Reserved. |
6 | Permission to use, copy, modify, and distribute this software and its |
7 | documentation for any purpose and without fee is hereby granted, provided |
8 | that the above copyright notice appear in all copies and that both that |
9 | copyright notice and this permission notice appear in supporting |
10 | documentation, and that the name of the above listed copyright holder(s) not |
11 | be used in advertising or publicity pertaining to distribution of the |
12 | software without specific, written prior permission. |
14 | THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD TO |
15 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT- |
16 | NESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR |
17 | ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RE- |
18 | SULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
19 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH |
20 | THE USE OR PERFORMANCE OF THIS SOFTWARE. |
21 +-----------------------------------------------------------------------------*/
23 /***************************************************************************
25 * Write or erase menus from associated subwindows *
26 ***************************************************************************/
28 #include "menu.priv.h"
30 MODULE_ID("$Id: m_post.c,v 1.12 1997/05/01 16:47:26 juergen Exp $")
32 /*---------------------------------------------------------------------------
34 | Function : void _nc_Post_Item(MENU *menu, ITEM *item)
36 | Description : Draw the item in the menus window at the current
40 +--------------------------------------------------------------------------*/
41 void _nc_Post_Item(const MENU * menu, const ITEM * item)
47 bool isfore = FALSE, isback=FALSE, isgrey = FALSE;
51 getyx(menu->win,item_y,item_x);
53 /* We need a marker iff
54 - it is a onevalued menu and it is the current item
55 - or it has a selection value
57 wattron(menu->win,menu->back);
58 if (item->value || (item==menu->curitem))
62 /* In a multi selection menu we use the fore attribute
63 for a selected marker that is not the current one.
64 This improves visualization of the menu, because now
65 always the 'normal' marker denotes the current
67 if (!(menu->opt & O_ONEVALUE) && item->value && item!=menu->curitem)
69 wattron(menu->win,menu->fore);
72 waddstr(menu->win,menu->mark);
75 wattron(menu->win,menu->fore);
80 else /* otherwise we have to wipe out the marker area */
81 for(ch=' ',i=menu->marklen;i>0;i--)
83 wattroff(menu->win,menu->back);
84 count += menu->marklen;
86 /* First we have to calculate the attribute depending on selectability
89 if (!(item->opt & O_SELECTABLE))
91 wattron(menu->win,menu->grey);
96 if (item->value || item==menu->curitem)
98 wattron(menu->win,menu->fore);
103 wattron(menu->win,menu->back);
108 waddnstr(menu->win,item->name.str,item->name.length);
109 for(ch=' ',i=menu->namelen-item->name.length;i>0;i--)
111 waddch(menu->win,ch);
113 count += menu->namelen;
115 /* Show description if required and available */
116 if ( (menu->opt & O_SHOWDESC) && menu->desclen>0 )
118 int m = menu->spc_desc/2;
119 int cy = -1, cx = -1;
121 for(ch=' ',i=0; i < menu->spc_desc; i++)
125 waddch(menu->win,menu->pad);
126 getyx(menu->win,cy,cx);
129 waddch(menu->win,ch);
131 if (item->description.length)
132 waddnstr(menu->win,item->description.str,item->description.length);
133 for(ch=' ',i=menu->desclen-item->description.length; i>0; i--)
135 waddch(menu->win,ch);
137 count += menu->desclen + menu->spc_desc;
139 if (menu->spc_rows > 1)
143 assert(cx>=0 && cy>=0);
144 getyx(menu->win,ncy,ncx);
145 if (isgrey) wattroff(menu->win,menu->grey);
146 else if (isfore) wattroff(menu->win,menu->fore);
147 wattron(menu->win,menu->back);
148 for(j=1; j < menu->spc_rows;j++)
150 if ((item_y+j) < getmaxy(menu->win))
152 wmove (menu->win,item_y+j,item_x);
154 waddch(menu->win,' ');
156 if ((cy+j) < getmaxy(menu->win))
157 mvwaddch(menu->win,cy+j,cx-1,menu->pad);
159 wmove(menu->win,ncy,ncx);
161 wattroff(menu->win,menu->back);
165 /* Remove attributes */
167 wattroff(menu->win,menu->fore);
169 wattroff(menu->win,menu->back);
171 wattroff(menu->win,menu->grey);
174 /*---------------------------------------------------------------------------
175 | Facility : libnmenu
176 | Function : void _nc_Draw_Menu(const MENU *)
178 | Description : Display the menu in its windows
181 +--------------------------------------------------------------------------*/
182 void _nc_Draw_Menu(const MENU * menu)
184 ITEM *item = menu->items[0];
185 ITEM *lasthor, *lastvert;
190 assert(item && menu->win);
192 s_bkgd = getbkgd(menu->win);
193 wbkgdset(menu->win,menu->back);
195 wbkgdset(menu->win,s_bkgd);
197 lastvert = (menu->opt & O_NONCYCLIC) ? (ITEM *)0 : item;
201 wmove(menu->win,y,0);
204 lasthor = (menu->opt & O_NONCYCLIC) ? (ITEM *)0 : hitem;
208 _nc_Post_Item( menu, hitem);
210 wattron(menu->win,menu->back);
211 if ( ((hitem = hitem->right) != lasthor) && hitem )
216 getyx(menu->win,cy,cx);
217 for(j=0;j<menu->spc_rows;j++)
219 wmove(menu->win,cy+j,cx);
220 for(i=0; i < menu->spc_cols; i++)
222 waddch( menu->win,ch);
225 wmove(menu->win,cy,cx+menu->spc_cols);
227 } while (hitem && (hitem != lasthor));
228 wattroff(menu->win,menu->back);
233 } while( item && (item != lastvert) );
236 /*---------------------------------------------------------------------------
237 | Facility : libnmenu
238 | Function : int post_menu(MENU *)
240 | Description : Post a menu to the screen. This makes it visible.
242 | Return Values : E_OK - success
243 | E_BAD_ARGUMENT - not a valid menu pointer
244 | E_SYSTEM_ERROR - error in lower layers
245 | E_NO_ROOM - Menu to large for screen
246 | E_NOT_CONNECTED - No items connected to menu
247 | E_BAD_STATE - Menu in userexit routine
248 | E_POSTED - Menu already posted
249 +--------------------------------------------------------------------------*/
250 int post_menu(MENU * menu)
253 RETURN(E_BAD_ARGUMENT);
255 if ( menu->status & _IN_DRIVER )
258 if ( menu->status & _POSTED )
261 if (menu->items && *(menu->items))
264 int h = 1 + menu->spc_rows * (menu->rows - 1);
266 WINDOW *win = Get_Menu_Window(menu);
267 int maxy = getmaxy(win);
268 int maxx = getmaxx(win);
270 if (maxx < menu->width || maxy < menu->height)
273 if ( (menu->win = newpad(h,menu->width)) )
275 y = (maxy >= h) ? h : maxy;
278 if(!(menu->sub = subpad(menu->win,y,menu->width,0,0)))
279 RETURN(E_SYSTEM_ERROR);
282 RETURN(E_SYSTEM_ERROR);
284 if (menu->status & _LINK_NEEDED)
285 _nc_Link_Items(menu);
288 RETURN(E_NOT_CONNECTED);
290 menu->status |= _POSTED;
292 if (!(menu->opt&O_ONEVALUE))
296 for(items=menu->items;*items;items++)
298 (*items)->value = FALSE;
304 Call_Hook(menu,menuinit);
305 Call_Hook(menu,iteminit);
312 /*---------------------------------------------------------------------------
313 | Facility : libnmenu
314 | Function : int unpost_menu(MENU *)
316 | Description : Detach menu from screen
318 | Return Values : E_OK - success
319 | E_BAD_ARGUMENT - not a valid menu pointer
320 | E_BAD_STATE - menu in userexit routine
321 | E_NOT_POSTED - menu is not posted
322 +--------------------------------------------------------------------------*/
323 int unpost_menu(MENU * menu)
328 RETURN(E_BAD_ARGUMENT);
330 if ( menu->status & _IN_DRIVER )
333 if ( !( menu->status & _POSTED ) )
334 RETURN(E_NOT_POSTED);
336 Call_Hook(menu,itemterm);
337 Call_Hook(menu,menuterm);
339 win = Get_Menu_Window(menu);
345 menu->sub = (WINDOW *)0;
349 menu->win = (WINDOW *)0;
351 menu->status &= ~_POSTED;
356 /* m_post.c ends here */