1 /*
2    Copyright (c) 1999-2002 Perry Rapp
3    "The MIT license"
4    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7 */
8 /*=============================================================
9  * dynmenu.c -- dynamically resizable & pageable menus
10  *  This module holds the code to resize & page thru the menus
11  *   Created: 1999/03 by Perry Rapp
12  *   Brought into repository: 2001/01/28 by Perry Rapp
13  *==============================================================*/
14 
15 #include "llstdlib.h"
16 #include "feedback.h"
17 #include "gedcom.h"
18 #include "menuitem.h"
19 
20 /*********************************************
21  * external/imported variables
22  *********************************************/
23 
24 extern STRING qSttlindibrw, qSttlfambrw, qSttl2perbrw, qSttl2fambrw;
25 extern STRING qSttlauxbrw, qSttllstbrw;
26 
27 /*********************************************
28  * local types
29  *********************************************/
30 
31 
32 /*********************************************
33  * local function prototypes
34  *********************************************/
35 
36 /* alphabetical */
37 
38 /*********************************************
39  * local variables
40  *********************************************/
41 
42 /* menu items added to all menus */
43 static MenuItem * f_ExtraItems[] =
44 {
45 	&g_MenuItemOther,
46 	&g_MenuItemQuit,
47 	0
48 };
49 
50 
51 /*********************************************
52  * local function definitions
53  * body of module
54  *********************************************/
55 
56 /*============================
57  * dynmenu_init - initialize one dynamic menu
58  * Safe to call on either empty or full DYNMENU
59  * Created: 2002/10/24, Perry Rapp
60  *==========================*/
61 void
dynmenu_init(DYNMENU dynmenu,STRING title,INT MenuRows,INT MenuCols,INT MinCols,INT MaxCols,INT MinRows,INT MaxRows,INT MenuTop,INT MenuLeft,INT MenuWidth,INT MenuSize,MenuItem ** MenuItems)62 dynmenu_init (DYNMENU dynmenu , STRING title, INT MenuRows, INT MenuCols
63 	, INT MinCols, INT MaxCols
64 	, INT MinRows, INT MaxRows
65 	, INT MenuTop, INT MenuLeft, INT MenuWidth
66 	, INT MenuSize, MenuItem ** MenuItems)
67 {
68 	dynmenu->rows = MenuRows;
69 	dynmenu->cols = MenuCols;
70 	dynmenu->size = MenuSize;
71 	dynmenu->page = 0;
72 	/* dynmenu->pages */
73 	/* dynmenu->pageitems */
74 	dynmenu->mincols = MinCols;
75 	dynmenu->maxcols = MaxCols;
76 	dynmenu->minrows = MinRows;
77 	dynmenu->maxrows = MaxRows;
78 	dynmenu->hidden = 0;
79 	dynmenu->dirty = 1;
80 	dynmenu->top = MenuTop;
81 	dynmenu->bottom = MenuTop + MenuRows-1;
82 	dynmenu->left = MenuLeft;
83 	dynmenu->width = MenuLeft + MenuWidth-1;
84 	menuset_init(&dynmenu->menuset, title, MenuItems, f_ExtraItems);
85 }
86 /*============================
87  * dynmenu_clear - Free memory in dynmenu
88  * reentrant
89  * Created: 2002/10/24, Perry Rapp
90  *==========================*/
91 void
dynmenu_clear(DYNMENU dynmenu)92 dynmenu_clear (DYNMENU dynmenu)
93 {
94 	menuset_clear(&dynmenu->menuset);
95 }
96 /*==================================================================
97  * dynmenu_next_page - show next page of menu choices
98  * Created: 2002/10/24, Perry Rapp
99  *================================================================*/
100 void
dynmenu_next_page(DYNMENU dynmenu)101 dynmenu_next_page (DYNMENU dynmenu)
102 {
103 	INT MenuSize = dynmenu->size;
104 	INT pageitems = dynmenu->pageitems;
105 	if (dynmenu->pages == 1) return;
106 	++dynmenu->page;
107 	if (dynmenu->page > (MenuSize-1)/pageitems)
108 		dynmenu->page = 0;
109 	dynmenu->dirty = 1;
110 }
111 /*==================================================================
112  * dynmenu_adjust_height - Increase or decrease screen size of menu
113  * Created: 2002/10/28, Perry Rapp
114  *================================================================*/
115 void
dynmenu_adjust_height(DYNMENU dynmenu,INT delta)116 dynmenu_adjust_height (DYNMENU dynmenu, INT delta)
117 {
118 	INT oldrows = dynmenu->rows;
119 	dynmenu->rows += delta;
120 	if (dynmenu->rows < dynmenu->minrows)
121 		dynmenu->rows = dynmenu->minrows;
122 	if (dynmenu->rows > dynmenu->maxrows)
123 		dynmenu->rows = dynmenu->maxrows;
124 	if (dynmenu->rows != oldrows)
125 		dynmenu->dirty = 1;
126 	dynmenu->top = dynmenu->bottom - (dynmenu->rows-1);
127 }
128 /*==================================================================
129  * dynmenu_adjust_menu_cols - Change # of columns in menu
130  * Created: 2002/10/28, Perry Rapp
131  *================================================================*/
132 void
dynmenu_adjust_menu_cols(DYNMENU dynmenu,INT delta)133 dynmenu_adjust_menu_cols (DYNMENU dynmenu, INT delta)
134 {
135 	INT oldcols = dynmenu->cols;
136 	dynmenu->cols += delta;
137 	if (dynmenu->cols < dynmenu->mincols)
138 		dynmenu->cols = dynmenu->mincols;
139 	else if (dynmenu->cols > dynmenu->maxcols)
140 		dynmenu->cols = dynmenu->maxcols;
141 	if (dynmenu->cols != oldcols)
142 		dynmenu->dirty = 1;
143 }
144 /*==================================================================
145  * dynmenu_get_menuset - Return the menuset (keystroke to command info)
146  * Created: 2002/10/28, Perry Rapp
147  *================================================================*/
148 MENUSET
dynmenu_get_menuset(DYNMENU dynmenu)149 dynmenu_get_menuset (DYNMENU dynmenu)
150 {
151 	return &dynmenu->menuset;
152 }
153 /*==================================================================
154  * dynmenu_toggle_menu() - hide/show menu
155  * Created: 2002/10/28, Perry Rapp
156  *================================================================*/
157 void
dynmenu_toggle_menu(DYNMENU dynmenu)158 dynmenu_toggle_menu (DYNMENU dynmenu)
159 {
160 	dynmenu->hidden = !dynmenu->hidden;
161 	dynmenu->dirty = 1;
162 }
163