1 /****************************************************************************
2 * Copyright (c) 1998,2000 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, 1995,1997 *
31 * Contact: http://www.familiepfeifer.de/Contact.aspx?Lang=en *
32 ****************************************************************************/
34 /***************************************************************************
36 * Write or erase menus from associated subwindows *
37 ***************************************************************************/
39 #include "menu.priv.h"
41 MODULE_ID("$Id: m_post.c,v 1.18 2002/07/06 15:22:16 juergen Exp $")
43 /*---------------------------------------------------------------------------
45 | Function : void _nc_Post_Item(MENU *menu, ITEM *item)
47 | Description : Draw the item in the menus window at the current
51 +--------------------------------------------------------------------------*/
53 _nc_Post_Item (const MENU * menu, const ITEM * item)
59 bool isfore = FALSE, isback=FALSE, isgrey = FALSE;
63 getyx(menu->win,item_y,item_x);
65 /* We need a marker iff
66 - it is a onevalued menu and it is the current item
67 - or it has a selection value
69 wattron(menu->win,menu->back);
70 if (item->value || (item==menu->curitem))
74 /* In a multi selection menu we use the fore attribute
75 for a selected marker that is not the current one.
76 This improves visualization of the menu, because now
77 always the 'normal' marker denotes the current
79 if (!(menu->opt & O_ONEVALUE) && item->value && item!=menu->curitem)
81 wattron(menu->win,menu->fore);
84 waddstr(menu->win,menu->mark);
87 wattron(menu->win,menu->fore);
92 else /* otherwise we have to wipe out the marker area */
93 for(ch=' ',i=menu->marklen;i>0;i--)
95 wattroff(menu->win,menu->back);
96 count += menu->marklen;
98 /* First we have to calculate the attribute depending on selectability
101 if (!(item->opt & O_SELECTABLE))
103 wattron(menu->win,menu->grey);
108 if (item->value || item==menu->curitem)
110 wattron(menu->win,menu->fore);
115 wattron(menu->win,menu->back);
120 waddnstr(menu->win,item->name.str,item->name.length);
121 for(ch=' ',i=menu->namelen-item->name.length;i>0;i--)
123 waddch(menu->win,ch);
125 count += menu->namelen;
127 /* Show description if required and available */
128 if ( (menu->opt & O_SHOWDESC) && menu->desclen>0 )
130 int m = menu->spc_desc/2;
131 int cy = -1, cx = -1;
133 for(ch=' ',i=0; i < menu->spc_desc; i++)
137 waddch(menu->win,menu->pad);
138 getyx(menu->win,cy,cx);
141 waddch(menu->win,ch);
143 if (item->description.length)
144 waddnstr(menu->win,item->description.str,item->description.length);
145 for(ch=' ',i=menu->desclen-item->description.length; i>0; i--)
147 waddch(menu->win,ch);
149 count += menu->desclen + menu->spc_desc;
151 if (menu->spc_rows > 1)
155 assert(cx>=0 && cy>=0);
156 getyx(menu->win,ncy,ncx);
157 if (isgrey) wattroff(menu->win,menu->grey);
158 else if (isfore) wattroff(menu->win,menu->fore);
159 wattron(menu->win,menu->back);
160 for(j=1; j < menu->spc_rows;j++)
162 if ((item_y+j) < getmaxy(menu->win))
164 wmove (menu->win,item_y+j,item_x);
166 waddch(menu->win,' ');
168 if ((cy+j) < getmaxy(menu->win))
169 mvwaddch(menu->win,cy+j,cx-1,menu->pad);
171 wmove(menu->win,ncy,ncx);
173 wattroff(menu->win,menu->back);
177 /* Remove attributes */
179 wattroff(menu->win,menu->fore);
181 wattroff(menu->win,menu->back);
183 wattroff(menu->win,menu->grey);
186 /*---------------------------------------------------------------------------
187 | Facility : libnmenu
188 | Function : void _nc_Draw_Menu(const MENU *)
190 | Description : Display the menu in its windows
193 +--------------------------------------------------------------------------*/
195 _nc_Draw_Menu (const MENU * menu)
197 ITEM *item = menu->items[0];
198 ITEM *lasthor, *lastvert;
203 assert(item && menu->win);
205 s_bkgd = getbkgd(menu->win);
206 wbkgdset(menu->win,menu->back);
208 wbkgdset(menu->win,s_bkgd);
210 lastvert = (menu->opt & O_NONCYCLIC) ? (ITEM *)0 : item;
214 wmove(menu->win,y,0);
217 lasthor = (menu->opt & O_NONCYCLIC) ? (ITEM *)0 : hitem;
221 _nc_Post_Item( menu, hitem);
223 wattron(menu->win,menu->back);
224 if ( ((hitem = hitem->right) != lasthor) && hitem )
229 getyx(menu->win,cy,cx);
230 for(j=0;j<menu->spc_rows;j++)
232 wmove(menu->win,cy+j,cx);
233 for(i=0; i < menu->spc_cols; i++)
235 waddch( menu->win,ch);
238 wmove(menu->win,cy,cx+menu->spc_cols);
240 } while (hitem && (hitem != lasthor));
241 wattroff(menu->win,menu->back);
246 } while( item && (item != lastvert) );
249 /*---------------------------------------------------------------------------
250 | Facility : libnmenu
251 | Function : int post_menu(MENU *)
253 | Description : Post a menu to the screen. This makes it visible.
255 | Return Values : E_OK - success
256 | E_BAD_ARGUMENT - not a valid menu pointer
257 | E_SYSTEM_ERROR - error in lower layers
258 | E_NO_ROOM - Menu to large for screen
259 | E_NOT_CONNECTED - No items connected to menu
260 | E_BAD_STATE - Menu in userexit routine
261 | E_POSTED - Menu already posted
262 +--------------------------------------------------------------------------*/
264 post_menu (MENU * menu)
267 RETURN(E_BAD_ARGUMENT);
269 if ( menu->status & _IN_DRIVER )
272 if ( menu->status & _POSTED )
275 if (menu->items && *(menu->items))
278 int h = 1 + menu->spc_rows * (menu->rows - 1);
280 WINDOW *win = Get_Menu_Window(menu);
281 int maxy = getmaxy(win);
282 int maxx = getmaxx(win);
284 if (maxx < menu->width || maxy < menu->height)
287 if ( (menu->win = newpad(h,menu->width)) )
289 y = (maxy >= h) ? h : maxy;
292 if(!(menu->sub = subpad(menu->win,y,menu->width,0,0)))
293 RETURN(E_SYSTEM_ERROR);
296 RETURN(E_SYSTEM_ERROR);
298 if (menu->status & _LINK_NEEDED)
299 _nc_Link_Items(menu);
302 RETURN(E_NOT_CONNECTED);
304 menu->status |= _POSTED;
306 if (!(menu->opt&O_ONEVALUE))
310 for(items=menu->items;*items;items++)
312 (*items)->value = FALSE;
318 Call_Hook(menu,menuinit);
319 Call_Hook(menu,iteminit);
326 /*---------------------------------------------------------------------------
327 | Facility : libnmenu
328 | Function : int unpost_menu(MENU *)
330 | Description : Detach menu from screen
332 | Return Values : E_OK - success
333 | E_BAD_ARGUMENT - not a valid menu pointer
334 | E_BAD_STATE - menu in userexit routine
335 | E_NOT_POSTED - menu is not posted
336 +--------------------------------------------------------------------------*/
338 unpost_menu (MENU * menu)
343 RETURN(E_BAD_ARGUMENT);
345 if ( menu->status & _IN_DRIVER )
348 if ( !( menu->status & _POSTED ) )
349 RETURN(E_NOT_POSTED);
351 Call_Hook(menu,itemterm);
352 Call_Hook(menu,menuterm);
354 win = Get_Menu_Window(menu);
360 menu->sub = (WINDOW *)0;
364 menu->win = (WINDOW *)0;
366 menu->status &= ~_POSTED;
371 /* m_post.c ends here */