Convert to new Doxygen style.
[bertos.git] / gui / menu.h
1 /**
2  * \file
3  * <!--
4  * Copyright 2003, 2004, 2006 Develer S.r.l. (http://www.develer.com/)
5  * Copyright 2000 Bernardo Innocenti <bernie@codewiz.org>
6  * All Rights Reserved.
7  * -->
8  *
9  * \version $Id$
10  *
11  * \author Bernardo Innocenti <bernie@develer.com>
12  * \author Stefano Fedrigo <aleph@develer.com>
13  *
14  * \brief Common menu handling API
15  */
16
17 /*#*
18  *#* $Log$
19  *#* Revision 1.3  2006/07/19 12:56:27  bernie
20  *#* Convert to new Doxygen style.
21  *#*
22  *#* Revision 1.2  2006/06/03 13:58:02  bernie
23  *#* Fix recursive timeout and add exit status information.
24  *#*
25  *#* Revision 1.1  2006/05/15 07:20:54  bernie
26  *#* Move menu to gui/.
27  *#*
28  *#* Revision 1.4  2006/04/11 00:07:32  bernie
29  *#* Implemenent MF_SAVESEL flag.
30  *#*
31  *#* Revision 1.3  2006/03/22 09:49:51  bernie
32  *#* Simplifications from project_grl.
33  *#*
34  *#* Revision 1.2  2006/03/20 17:48:35  bernie
35  *#* Implement support for ROM menus.
36  *#*
37  *#* Revision 1.1  2006/02/10 12:29:36  bernie
38  *#* Add menu system.
39  *#*
40  *#* Revision 1.20  2005/11/16 18:10:19  bernie
41  *#* Move top-level headers to cfg/ as in DevLib.
42  *#*
43  *#* Revision 1.19  2005/02/11 19:11:38  aleph
44  *#* Move menu_displaymsg() in new displaymsg module
45  *#*
46  *#* Revision 1.18  2005/01/13 16:56:36  aleph
47  *#* Fix progmem includes.
48  *#*
49  *#* Revision 1.17  2004/12/14 12:52:45  aleph
50  *#* Add exclude menu flags
51  *#*
52  *#* Revision 1.16  2004/10/01 14:04:59  customer_pw
53  *#* Add accessor functions for menu flags
54  *#*
55  *#* Revision 1.15  2004/09/09 08:31:36  customer_pw
56  *#* Add disabled item type
57  *#*
58  *#* Revision 1.14  2004/08/29 21:46:12  bernie
59  *#* CVSSILENT: Mark CVS log blocks.
60  *#*
61  *#* Revision 1.13  2004/08/25 15:35:23  customer_pw
62  *#* IPTR -> iptr_t conversion.
63  *#*
64  *#* Revision 1.12  2004/08/25 13:23:45  bernie
65  *#* IPTR -> iptr_t conversion.
66  *#*/
67 #ifndef MWARE_MENU_H
68 #define MWARE_MENU_H
69
70 #include <cfg/compiler.h>
71
72 /* Fwd decl */
73 struct Bitmap;
74
75 /** Menu callback function */
76 typedef iptr_t (*MenuHook)(iptr_t userdata);
77
78 /**
79  * Menu item description.
80  */
81 typedef struct MenuItem
82 {
83         const_iptr_t label;    /**< Item label (ID or ptr to string, 0 to disable) */
84         int          flags;    /**< See MIF_#? definitions below */
85         MenuHook     hook;     /**< Callback function (NULL to terminate item list) */
86         iptr_t       userdata; /**< User data to be passed back to the hook */
87 } MenuItem;
88
89 /**
90  * \name Flags for MenuItem.flags.
91  * \{
92  */
93 #define MIF_EXCLUDE_MASK    0x00FF /**< Mask for mutual exclusion map (shared with priority). */
94 #define MIF_PRI_MASK        0x00FF /**< Mask for priority value (shared with mutual exclusion). */
95 #define MIF_PRI(x)          ((x) & MIF_PRI_MASK) /**< Set menu item priority. */
96 #define MIF_EXCLUDE_0       BV(0)  /**< Exclude item 0 when this item is checked */
97 #define MIF_EXCLUDE_1       BV(1)  /**< Exclude item 1 when this item is checked */
98 #define MIF_EXCLUDE_2       BV(2)  /**< Exclude item 2 when this item is checked */
99 #define MIF_EXCLUDE_3       BV(3)  /**< Exclude item 3 when this item is checked */
100 #define MIF_EXCLUDE_4       BV(4)  /**< Exclude item 4 when this item is checked */
101 #define MIF_EXCLUDE_5       BV(5)  /**< Exclude item 5 when this item is checked */
102 #define MIF_EXCLUDE_6       BV(6)  /**< Exclude item 6 when this item is checked */
103 #define MIF_EXCLUDE_7       BV(7)  /**< Exclude item 7 when this item is checked */
104 #define MIF_CHECKED         BV(8)  /**< Item is currently checked */
105 #define MIF_CHECKIT         BV(9)  /**< Automatically check this item when selected */
106 #define MIF_TOGGLE          BV(10) /**< Toggle MIF_CHECKED when item is selected */
107 #define MIF_HIDDEN          BV(11) /**< This menu item is not visible */
108 #define MIF_DISABLED        BV(12) /**< This menu item is not visible */
109 #define MIF_RAMLABEL        BV(13) /**< Item label is stored in RAM, not in program memory */
110 /* \} */
111
112 /**
113  * Menu description.
114  */
115 typedef struct Menu
116 {
117         MenuItem        *items;    /**< Array of items (end with a NULL hook) */
118         const_iptr_t     title;    /**< Menu title (ID or ptr to string, 0 to disable) */
119         int              flags;    /**< See MF_#? definitions below */
120         struct Bitmap   *bitmap;   /**< Bitmap where the menu is rendered */
121         int              selected; /**< Initial selection (written to if #MF_SAVESEL is set). */
122 } Menu;
123
124 /**
125  * \name Flags for Menu.flags.
126  * \{
127  */
128 #define MF_STICKY   BV(0)  /**< Stay in the menu when the items called return */
129 #define MF_TOPLEVEL BV(1)  /**< Top-level menu (do not display "back" label) */
130 #define MF_ROMITEMS BV(2)  /**< Menu items are stored in ROM (default is RAM) */
131 #define MF_SAVESEL  BV(3)  /**< Remember the selected item across invocations. */
132 /* \} */
133
134 /**
135  * \name Special result codes for menu_handle().
136  * \{
137  */
138 #define MENU_OK       ((iptr_t)0)
139 #define MENU_CANCEL   ((iptr_t)-1)
140 #define MENU_TIMEOUT  ((iptr_t)-2)
141 #define MENU_ABORT    ((iptr_t)-3)
142 #define MENU_DISABLED ((iptr_t)-4)
143 /* \} */
144
145 /* Function prototypes */
146 iptr_t menu_handle(const struct Menu *menu);
147 int menu_setFlags(struct Menu *menu, int idx, int flags);
148 int menu_clearFlags(struct Menu *menu, int idx, int flags);
149
150 #endif /* MWARE_MENU_H */