1 /****************************************************************************
2 * Copyright (c) 1998 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Juergen Pfeifer <Juergen.Pfeifer@T-Online.de> 1995,1997 *
31 ****************************************************************************/
33 /***************************************************************************
35 * Write or erase menus from associated subwindows *
36 ***************************************************************************/
38 #include "menu.priv.h"
40 MODULE_ID("$Id: m_post.c,v 1.14 1998/02/11 12:13:49 tom Exp $")
42 /*---------------------------------------------------------------------------
44 | Function : void _nc_Post_Item(MENU *menu, ITEM *item)
46 | Description : Draw the item in the menus window at the current
50 +--------------------------------------------------------------------------*/
51 void _nc_Post_Item(const MENU * menu, const ITEM * item)
57 bool isfore = FALSE, isback=FALSE, isgrey = FALSE;
61 getyx(menu->win,item_y,item_x);
63 /* We need a marker iff
64 - it is a onevalued menu and it is the current item
65 - or it has a selection value
67 wattron(menu->win,menu->back);
68 if (item->value || (item==menu->curitem))
72 /* In a multi selection menu we use the fore attribute
73 for a selected marker that is not the current one.
74 This improves visualization of the menu, because now
75 always the 'normal' marker denotes the current
77 if (!(menu->opt & O_ONEVALUE) && item->value && item!=menu->curitem)
79 wattron(menu->win,menu->fore);
82 waddstr(menu->win,menu->mark);
85 wattron(menu->win,menu->fore);
90 else /* otherwise we have to wipe out the marker area */
91 for(ch=' ',i=menu->marklen;i>0;i--)
93 wattroff(menu->win,menu->back);
94 count += menu->marklen;
96 /* First we have to calculate the attribute depending on selectability
99 if (!(item->opt & O_SELECTABLE))
101 wattron(menu->win,menu->grey);
106 if (item->value || item==menu->curitem)
108 wattron(menu->win,menu->fore);
113 wattron(menu->win,menu->back);
118 waddnstr(menu->win,item->name.str,item->name.length);
119 for(ch=' ',i=menu->namelen-item->name.length;i>0;i--)
121 waddch(menu->win,ch);
123 count += menu->namelen;
125 /* Show description if required and available */
126 if ( (menu->opt & O_SHOWDESC) && menu->desclen>0 )
128 int m = menu->spc_desc/2;
129 int cy = -1, cx = -1;
131 for(ch=' ',i=0; i < menu->spc_desc; i++)
135 waddch(menu->win,menu->pad);
136 getyx(menu->win,cy,cx);
139 waddch(menu->win,ch);
141 if (item->description.length)
142 waddnstr(menu->win,item->description.str,item->description.length);
143 for(ch=' ',i=menu->desclen-item->description.length; i>0; i--)
145 waddch(menu->win,ch);
147 count += menu->desclen + menu->spc_desc;
149 if (menu->spc_rows > 1)
153 assert(cx>=0 && cy>=0);
154 getyx(menu->win,ncy,ncx);
155 if (isgrey) wattroff(menu->win,menu->grey);
156 else if (isfore) wattroff(menu->win,menu->fore);
157 wattron(menu->win,menu->back);
158 for(j=1; j < menu->spc_rows;j++)
160 if ((item_y+j) < getmaxy(menu->win))
162 wmove (menu->win,item_y+j,item_x);
164 waddch(menu->win,' ');
166 if ((cy+j) < getmaxy(menu->win))
167 mvwaddch(menu->win,cy+j,cx-1,menu->pad);
169 wmove(menu->win,ncy,ncx);
171 wattroff(menu->win,menu->back);
175 /* Remove attributes */
177 wattroff(menu->win,menu->fore);
179 wattroff(menu->win,menu->back);
181 wattroff(menu->win,menu->grey);
184 /*---------------------------------------------------------------------------
185 | Facility : libnmenu
186 | Function : void _nc_Draw_Menu(const MENU *)
188 | Description : Display the menu in its windows
191 +--------------------------------------------------------------------------*/
192 void _nc_Draw_Menu(const MENU * menu)
194 ITEM *item = menu->items[0];
195 ITEM *lasthor, *lastvert;
200 assert(item && menu->win);
202 s_bkgd = getbkgd(menu->win);
203 wbkgdset(menu->win,menu->back);
205 wbkgdset(menu->win,s_bkgd);
207 lastvert = (menu->opt & O_NONCYCLIC) ? (ITEM *)0 : item;
211 wmove(menu->win,y,0);
214 lasthor = (menu->opt & O_NONCYCLIC) ? (ITEM *)0 : hitem;
218 _nc_Post_Item( menu, hitem);
220 wattron(menu->win,menu->back);
221 if ( ((hitem = hitem->right) != lasthor) && hitem )
226 getyx(menu->win,cy,cx);
227 for(j=0;j<menu->spc_rows;j++)
229 wmove(menu->win,cy+j,cx);
230 for(i=0; i < menu->spc_cols; i++)
232 waddch( menu->win,ch);
235 wmove(menu->win,cy,cx+menu->spc_cols);
237 } while (hitem && (hitem != lasthor));
238 wattroff(menu->win,menu->back);
243 } while( item && (item != lastvert) );
246 /*---------------------------------------------------------------------------
247 | Facility : libnmenu
248 | Function : int post_menu(MENU *)
250 | Description : Post a menu to the screen. This makes it visible.
252 | Return Values : E_OK - success
253 | E_BAD_ARGUMENT - not a valid menu pointer
254 | E_SYSTEM_ERROR - error in lower layers
255 | E_NO_ROOM - Menu to large for screen
256 | E_NOT_CONNECTED - No items connected to menu
257 | E_BAD_STATE - Menu in userexit routine
258 | E_POSTED - Menu already posted
259 +--------------------------------------------------------------------------*/
260 int post_menu(MENU * menu)
263 RETURN(E_BAD_ARGUMENT);
265 if ( menu->status & _IN_DRIVER )
268 if ( menu->status & _POSTED )
271 if (menu->items && *(menu->items))
274 int h = 1 + menu->spc_rows * (menu->rows - 1);
276 WINDOW *win = Get_Menu_Window(menu);
277 int maxy = getmaxy(win);
278 int maxx = getmaxx(win);
280 if (maxx < menu->width || maxy < menu->height)
283 if ( (menu->win = newpad(h,menu->width)) )
285 y = (maxy >= h) ? h : maxy;
288 if(!(menu->sub = subpad(menu->win,y,menu->width,0,0)))
289 RETURN(E_SYSTEM_ERROR);
292 RETURN(E_SYSTEM_ERROR);
294 if (menu->status & _LINK_NEEDED)
295 _nc_Link_Items(menu);
298 RETURN(E_NOT_CONNECTED);
300 menu->status |= _POSTED;
302 if (!(menu->opt&O_ONEVALUE))
306 for(items=menu->items;*items;items++)
308 (*items)->value = FALSE;
314 Call_Hook(menu,menuinit);
315 Call_Hook(menu,iteminit);
322 /*---------------------------------------------------------------------------
323 | Facility : libnmenu
324 | Function : int unpost_menu(MENU *)
326 | Description : Detach menu from screen
328 | Return Values : E_OK - success
329 | E_BAD_ARGUMENT - not a valid menu pointer
330 | E_BAD_STATE - menu in userexit routine
331 | E_NOT_POSTED - menu is not posted
332 +--------------------------------------------------------------------------*/
333 int unpost_menu(MENU * menu)
338 RETURN(E_BAD_ARGUMENT);
340 if ( menu->status & _IN_DRIVER )
343 if ( !( menu->status & _POSTED ) )
344 RETURN(E_NOT_POSTED);
346 Call_Hook(menu,itemterm);
347 Call_Hook(menu,menuterm);
349 win = Get_Menu_Window(menu);
355 menu->sub = (WINDOW *)0;
359 menu->win = (WINDOW *)0;
361 menu->status &= ~_POSTED;
366 /* m_post.c ends here */