xref: /openbsd-src/lib/libmenu/m_win.c (revision a4afd6dad3fba28f80e70208181c06c482259988)
1 
2 /***************************************************************************
3 *                            COPYRIGHT NOTICE                              *
4 ****************************************************************************
5 *                ncurses is copyright (C) 1992-1995                        *
6 *                          Zeyd M. Ben-Halim                               *
7 *                          zmbenhal@netcom.com                             *
8 *                          Eric S. Raymond                                 *
9 *                          esr@snark.thyrsus.com                           *
10 *                                                                          *
11 *        Permission is hereby granted to reproduce and distribute ncurses  *
12 *        by any means and for any fee, whether alone or as part of a       *
13 *        larger distribution, in source or in binary form, PROVIDED        *
14 *        this notice is included with any such distribution, and is not    *
15 *        removed from any of its header files. Mention of ncurses in any   *
16 *        applications linked with it is highly appreciated.                *
17 *                                                                          *
18 *        ncurses comes AS IS with no warranty, implied or expressed.       *
19 *                                                                          *
20 ***************************************************************************/
21 
22 /***************************************************************************
23 * Module menu_win                                                          *
24 * Menus window and subwindow association routines                          *
25 ***************************************************************************/
26 
27 #include "menu.priv.h"
28 
29 /*---------------------------------------------------------------------------
30 |   Facility      :  libnmenu
31 |   Function      :  int set_menu_win(MENU *menu, WINDOW *win)
32 |
33 |   Description   :  Sets the window of the menu.
34 |
35 |   Return Values :  E_OK               - success
36 |                    E_POSTED           - menu is already posted
37 +--------------------------------------------------------------------------*/
38 int set_menu_win(MENU *menu, WINDOW *win)
39 {
40   if (menu)
41     {
42       if ( menu->status & _POSTED )
43 	RETURN(E_POSTED);
44       menu->userwin = win;
45       _nc_Calculate_Item_Length_and_Width(menu);
46     }
47   else
48     _nc_Default_Menu.userwin = win;
49 
50   RETURN(E_OK);
51 }
52 
53 /*---------------------------------------------------------------------------
54 |   Facility      :  libnmenu
55 |   Function      :  WINDOW *menu_win(const MENU *)
56 |
57 |   Description   :  Returns pointer to the window of the menu
58 |
59 |   Return Values :  NULL on error, otherwise pointer to window
60 +--------------------------------------------------------------------------*/
61 WINDOW *menu_win(const MENU *menu)
62 {
63   return Normalize_Menu(menu)->userwin;
64 }
65 
66 /*---------------------------------------------------------------------------
67 |   Facility      :  libnmenu
68 |   Function      :  int set_menu_sub(MENU *menu, WINDOW *win)
69 |
70 |   Description   :  Sets the subwindow of the menu.
71 |
72 |   Return Values :  E_OK           - success
73 |                    E_POSTED       - menu is already posted
74 +--------------------------------------------------------------------------*/
75 int set_menu_sub(MENU *menu, WINDOW *win)
76 {
77   if (menu)
78     {
79       if ( menu->status & _POSTED )
80 	RETURN(E_POSTED);
81       menu->usersub = win;
82       _nc_Calculate_Item_Length_and_Width(menu);
83     }
84   else
85     _nc_Default_Menu.usersub = win;
86 
87   RETURN(E_OK);
88 }
89 
90 /*---------------------------------------------------------------------------
91 |   Facility      :  libnmenu
92 |   Function      :  WINDOW *menu_sub(const MENU *menu)
93 |
94 |   Description   :  Returns a pointer to the subwindow of the menu
95 |
96 |   Return Values :  NULL on error, otherwise a pointer to the window
97 +--------------------------------------------------------------------------*/
98 WINDOW *menu_sub(const MENU * menu)
99 {
100   return Normalize_Menu(menu)->usersub;
101 }
102 
103 /*---------------------------------------------------------------------------
104 |   Facility      :  libnmenu
105 |   Function      :  int scale_menu(const MENU *menu)
106 |
107 |   Description   :  Returns the minimum window size necessary for the
108 |                    subwindow of menu.
109 |
110 |   Return Values :  E_OK                  - success
111 |                    E_BAD_ARGUMENT        - invalid menu pointer
112 |                    E_NOT_CONNECTED       - no items are connected to menu
113 +--------------------------------------------------------------------------*/
114 int scale_menu(const MENU *menu, int *rows, int *cols)
115 {
116   if (!menu)
117     RETURN( E_BAD_ARGUMENT );
118 
119   if (menu->items && *(menu->items))
120     {
121       if (rows)
122 	*rows = menu->height;
123       if (cols)
124 	*cols = menu->width;
125       RETURN(E_OK);
126     }
127   else
128     RETURN( E_NOT_CONNECTED );
129 }
130 
131 /* m_win.c ends here */
132