Refactor BeRTOS to be in his own directory.
[bertos.git] / bertos / gui / menu.h
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
6  * Bertos is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  * As a special exception, you may use this file as part of a free software
21  * library without restriction.  Specifically, if other files instantiate
22  * templates or use macros or inline functions from this file, or you compile
23  * this file and link it with other files to produce an executable, this
24  * file does not by itself cause the resulting executable to be covered by
25  * the GNU General Public License.  This exception does not however
26  * invalidate any other reasons why the executable file might be covered by
27  * the GNU General Public License.
28  *
29  * Copyright 2003, 2004, 2006 Develer S.r.l. (http://www.develer.com/)
30  * Copyright 2000 Bernardo Innocenti <bernie@codewiz.org>
31  * All Rights Reserved.
32  * -->
33  *
34  * \version $Id$
35  *
36  * \author Bernardo Innocenti <bernie@develer.com>
37  * \author Stefano Fedrigo <aleph@develer.com>
38  *
39  * \brief Common menu handling API
40  */
41
42 /*#*
43  *#* $Log$
44  *#* Revision 1.5  2007/09/19 16:23:27  batt
45  *#* Fix doxygen warnings.
46  *#*
47  *#* Revision 1.4  2006/09/13 13:58:33  bernie
48  *#* Add RenderHook support.
49  *#*
50  *#* Revision 1.3  2006/07/19 12:56:27  bernie
51  *#* Convert to new Doxygen style.
52  *#*
53  *#* Revision 1.2  2006/06/03 13:58:02  bernie
54  *#* Fix recursive timeout and add exit status information.
55  *#*
56  *#* Revision 1.1  2006/05/15 07:20:54  bernie
57  *#* Move menu to gui/.
58  *#*
59  *#* Revision 1.4  2006/04/11 00:07:32  bernie
60  *#* Implemenent MF_SAVESEL flag.
61  *#*
62  *#* Revision 1.3  2006/03/22 09:49:51  bernie
63  *#* Simplifications from project_grl.
64  *#*
65  *#* Revision 1.2  2006/03/20 17:48:35  bernie
66  *#* Implement support for ROM menus.
67  *#*
68  *#* Revision 1.1  2006/02/10 12:29:36  bernie
69  *#* Add menu system.
70  *#*
71  *#* Revision 1.20  2005/11/16 18:10:19  bernie
72  *#* Move top-level headers to cfg/ as in DevLib.
73  *#*
74  *#* Revision 1.19  2005/02/11 19:11:38  aleph
75  *#* Move menu_displaymsg() in new displaymsg module
76  *#*
77  *#* Revision 1.18  2005/01/13 16:56:36  aleph
78  *#* Fix progmem includes.
79  *#*
80  *#* Revision 1.17  2004/12/14 12:52:45  aleph
81  *#* Add exclude menu flags
82  *#*
83  *#* Revision 1.16  2004/10/01 14:04:59  customer_pw
84  *#* Add accessor functions for menu flags
85  *#*
86  *#* Revision 1.15  2004/09/09 08:31:36  customer_pw
87  *#* Add disabled item type
88  *#*
89  *#* Revision 1.14  2004/08/29 21:46:12  bernie
90  *#* CVSSILENT: Mark CVS log blocks.
91  *#*
92  *#* Revision 1.13  2004/08/25 15:35:23  customer_pw
93  *#* IPTR -> iptr_t conversion.
94  *#*
95  *#* Revision 1.12  2004/08/25 13:23:45  bernie
96  *#* IPTR -> iptr_t conversion.
97  *#*/
98 #ifndef MWARE_MENU_H
99 #define MWARE_MENU_H
100
101 #include <cfg/compiler.h>
102
103 /* Fwd decl */
104 struct Bitmap;
105
106 /** Menu callback function */
107 typedef iptr_t (*MenuHook)(iptr_t userdata);
108
109 /**
110  * Menu item description.
111  */
112 typedef struct MenuItem
113 {
114         const_iptr_t label;    /**< Item label (ID or ptr to string, 0 to disable) */
115         int          flags;    /**< See MIF_#? definitions below */
116         MenuHook     hook;     /**< Callback function (NULL to terminate item list) */
117         iptr_t       userdata; /**< User data to be passed back to the hook */
118 } MenuItem;
119
120 /** Render hook callback function prototype */
121 typedef void (*RenderHook)(struct Bitmap *bitmap, int ypos, bool selected, const struct MenuItem *item);
122
123 /**
124  * \name Flags for MenuItem.flags.
125  * \{
126  */
127 #define MIF_EXCLUDE_MASK    0x00FF /**< Mask for mutual exclusion map (shared with priority). */
128 #define MIF_PRI_MASK        0x00FF /**< Mask for priority value (shared with mutual exclusion). */
129 #define MIF_PRI(x)          ((x) & MIF_PRI_MASK) /**< Set menu item priority. */
130 #define MIF_EXCLUDE_0       BV(0)  /**< Exclude item 0 when this item is checked */
131 #define MIF_EXCLUDE_1       BV(1)  /**< Exclude item 1 when this item is checked */
132 #define MIF_EXCLUDE_2       BV(2)  /**< Exclude item 2 when this item is checked */
133 #define MIF_EXCLUDE_3       BV(3)  /**< Exclude item 3 when this item is checked */
134 #define MIF_EXCLUDE_4       BV(4)  /**< Exclude item 4 when this item is checked */
135 #define MIF_EXCLUDE_5       BV(5)  /**< Exclude item 5 when this item is checked */
136 #define MIF_EXCLUDE_6       BV(6)  /**< Exclude item 6 when this item is checked */
137 #define MIF_EXCLUDE_7       BV(7)  /**< Exclude item 7 when this item is checked */
138 #define MIF_CHECKED         BV(8)  /**< Item is currently checked */
139 #define MIF_CHECKIT         BV(9)  /**< Automatically check this item when selected */
140 #define MIF_TOGGLE          BV(10) /**< Toggle MIF_CHECKED when item is selected */
141 #define MIF_HIDDEN          BV(11) /**< This menu item is not visible */
142 #define MIF_DISABLED        BV(12) /**< This menu item is not visible */
143 #define MIF_RAMLABEL        BV(13) /**< Item label is stored in RAM, not in program memory */
144 #define MIF_RENDERHOOK      BV(14) /**< Menu render function is passed in label field */
145 /* \} */
146
147 /**
148  * Menu description.
149  */
150 typedef struct Menu
151 {
152         MenuItem        *items;    /**< Array of items (end with a NULL hook) */
153         const_iptr_t     title;    /**< Menu title (ID or ptr to string, 0 to disable) */
154         int              flags;    /**< See MF_#? definitions below */
155         struct Bitmap   *bitmap;   /**< Bitmap where the menu is rendered */
156         int              selected; /**< Initial selection (written to if MF_SAVESEL is set). */
157 } Menu;
158
159 /**
160  * \name Flags for Menu.flags.
161  * \{
162  */
163 #define MF_STICKY   BV(0)  /**< Stay in the menu when the items called return */
164 #define MF_TOPLEVEL BV(1)  /**< Top-level menu (do not display "back" label) */
165 #define MF_ROMITEMS BV(2)  /**< Menu items are stored in ROM (default is RAM) */
166 #define MF_SAVESEL  BV(3)  /**< Remember the selected item across invocations. */
167 /* \} */
168
169 /**
170  * \name Special result codes for menu_handle().
171  * \{
172  */
173 #define MENU_OK       ((iptr_t)0)
174 #define MENU_CANCEL   ((iptr_t)-1)
175 #define MENU_TIMEOUT  ((iptr_t)-2)
176 #define MENU_ABORT    ((iptr_t)-3)
177 #define MENU_DISABLED ((iptr_t)-4)
178 /* \} */
179
180 /* Function prototypes */
181 iptr_t menu_handle(const struct Menu *menu);
182 int menu_setFlags(struct Menu *menu, int idx, int flags);
183 int menu_clearFlags(struct Menu *menu, int idx, int flags);
184
185 #endif /* MWARE_MENU_H */