Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / lib / libmenu / post.c
blobf4657211bc492955a4ea36c509d8bcafcb839f20
1 /* $NetBSD: post.c,v 1.11 2003/03/09 01:08:48 lukem Exp $ */
3 /*-
4 * Copyright (c) 1998-1999 Brett Lymn (blymn@baea.com.au, brett_lymn@yahoo.com.au)
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __RCSID("$NetBSD: post.c,v 1.11 2003/03/09 01:08:48 lukem Exp $");
32 #include <menu.h>
33 #include <stdlib.h>
34 #include "internals.h"
37 * Post the menu to the screen. Call any defined init routines and then
38 * draw the menu on the screen.
40 int
41 post_menu(MENU *menu)
43 int maxx, maxy, i;
45 if (menu == NULL)
46 return E_BAD_ARGUMENT;
47 if (menu->posted == 1)
48 return E_POSTED;
49 if (menu->in_init == 1)
50 return E_BAD_STATE;
51 if (menu->items == NULL)
52 return E_NOT_CONNECTED;
53 if (*menu->items == NULL)
54 return E_NOT_CONNECTED;
56 menu->in_init = 1;
58 if (menu->menu_init != NULL)
59 menu->menu_init(menu);
60 if (menu->item_init != NULL)
61 menu->item_init(menu);
63 menu->in_init = 0;
65 getmaxyx(menu->scrwin, maxy, maxx);
66 if ((maxx == ERR) || (maxy == ERR)) return E_SYSTEM_ERROR;
68 if ((menu->cols * menu->max_item_width + menu->cols - 1) > maxx)
69 return E_NO_ROOM;
71 if ((menu->opts & O_RADIO) != O_RADIO) {
72 for (i = 0; i < menu->item_count; i++) {
73 menu->items[i]->selected = 0;
77 menu->posted = 1;
78 return _menui_draw_menu(menu);
83 * Unpost the menu. Call any defined termination routines and remove the
84 * menu from the screen.
86 int
87 unpost_menu(MENU *menu)
89 if (menu == NULL)
90 return E_BAD_ARGUMENT;
91 if (menu->posted != 1)
92 return E_NOT_POSTED;
93 if (menu->in_init == 1)
94 return E_BAD_STATE;
95 if (menu->item_term != NULL)
96 menu->item_term(menu);
98 if (menu->menu_term != NULL)
99 menu->menu_term(menu);
101 menu->posted = 0;
102 werase(menu->scrwin);
103 wrefresh(menu->scrwin);
104 return E_OK;