]> ncurses.scripts.mit.edu Git - ncurses.git/blob - menu/m_win.c
ncurses 4.1
[ncurses.git] / menu / m_win.c
1 /*-----------------------------------------------------------------------------+
2 |           The ncurses menu library is  Copyright (C) 1995-1997               |
3 |             by Juergen Pfeifer <Juergen.Pfeifer@T-Online.de>                 |
4 |                          All Rights Reserved.                                |
5 |                                                                              |
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.                         | 
13 |                                                                              |
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 +-----------------------------------------------------------------------------*/
22
23 /***************************************************************************
24 * Module menu_win                                                          *
25 * Menus window and subwindow association routines                          *
26 ***************************************************************************/
27
28 #include "menu.priv.h"
29
30 MODULE_ID("$Id: m_win.c,v 1.5 1997/05/01 16:47:26 juergen Exp $")
31
32 /*---------------------------------------------------------------------------
33 |   Facility      :  libnmenu  
34 |   Function      :  int set_menu_win(MENU *menu, WINDOW *win)
35 |   
36 |   Description   :  Sets the window of the menu.
37 |
38 |   Return Values :  E_OK               - success
39 |                    E_POSTED           - menu is already posted
40 +--------------------------------------------------------------------------*/
41 int set_menu_win(MENU *menu, WINDOW *win)
42 {
43   if (menu)
44     {
45       if ( menu->status & _POSTED )
46         RETURN(E_POSTED);
47       menu->userwin = win;
48       _nc_Calculate_Item_Length_and_Width(menu);
49     }
50   else
51     _nc_Default_Menu.userwin = win;
52   
53   RETURN(E_OK);
54 }
55
56 /*---------------------------------------------------------------------------
57 |   Facility      :  libnmenu  
58 |   Function      :  WINDOW *menu_win(const MENU *)
59 |   
60 |   Description   :  Returns pointer to the window of the menu
61 |
62 |   Return Values :  NULL on error, otherwise pointer to window
63 +--------------------------------------------------------------------------*/
64 WINDOW *menu_win(const MENU *menu)
65 {
66   const MENU* m = Normalize_Menu(menu);
67   return (m->userwin ? m->userwin : stdscr);
68 }
69
70 /*---------------------------------------------------------------------------
71 |   Facility      :  libnmenu  
72 |   Function      :  int set_menu_sub(MENU *menu, WINDOW *win)
73 |   
74 |   Description   :  Sets the subwindow of the menu.
75 |
76 |   Return Values :  E_OK           - success
77 |                    E_POSTED       - menu is already posted
78 +--------------------------------------------------------------------------*/
79 int set_menu_sub(MENU *menu, WINDOW *win)
80 {
81   if (menu)
82     {
83       if ( menu->status & _POSTED )
84         RETURN(E_POSTED);
85       menu->usersub = win;
86       _nc_Calculate_Item_Length_and_Width(menu);
87     }
88   else
89     _nc_Default_Menu.usersub = win;
90   
91   RETURN(E_OK);
92 }
93
94 /*---------------------------------------------------------------------------
95 |   Facility      :  libnmenu  
96 |   Function      :  WINDOW *menu_sub(const MENU *menu)
97 |   
98 |   Description   :  Returns a pointer to the subwindow of the menu
99 |
100 |   Return Values :  NULL on error, otherwise a pointer to the window
101 +--------------------------------------------------------------------------*/
102 WINDOW *menu_sub(const MENU * menu)
103 {
104   const MENU* m = Normalize_Menu(menu);
105   return Get_Menu_Window(m);
106 }
107
108 /*---------------------------------------------------------------------------
109 |   Facility      :  libnmenu  
110 |   Function      :  int scale_menu(const MENU *menu)
111 |   
112 |   Description   :  Returns the minimum window size necessary for the
113 |                    subwindow of menu.  
114 |
115 |   Return Values :  E_OK                  - success
116 |                    E_BAD_ARGUMENT        - invalid menu pointer
117 |                    E_NOT_CONNECTED       - no items are connected to menu
118 +--------------------------------------------------------------------------*/
119 int scale_menu(const MENU *menu, int *rows, int *cols)
120 {
121   if (!menu) 
122     RETURN( E_BAD_ARGUMENT );
123   
124   if (menu->items && *(menu->items))
125     {
126       if (rows)
127         *rows = menu->height;
128       if (cols)
129         *cols = menu->width;
130       RETURN(E_OK);
131     }
132   else
133     RETURN( E_NOT_CONNECTED );
134 }
135
136 /* m_win.c ends here */