Update preset.
[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, 2010 Develer S.r.l. (http://www.develer.com/)
30  * Copyright 2000 Bernie Innocenti <bernie@codewiz.org>
31  * All Rights Reserved.
32  * -->
33  *
34  * \defgroup menu Menu handling module
35  * \ingroup gui
36  * \{
37  * \author Bernie Innocenti <bernie@codewiz.org>
38  * \author Stefano Fedrigo <aleph@develer.com>
39  *
40  * \brief Common menu handling API
41  *
42  * $WIZ$ module_name = "menu"
43  * $WIZ$ module_depends = "text", "gfx", "timer", "kbd"
44  */
45
46 #ifndef GUI_MENU_H
47 #define GUI_MENU_H
48
49 #include <cfg/compiler.h>
50
51 #include <gfx/gfx.h>
52
53 /** Menu callback function */
54 typedef iptr_t (*MenuHook)(iptr_t userdata);
55 typedef void (*BlitBitmap)(const Bitmap *bm);
56
57 /**
58  * Menu item description.
59  */
60 typedef struct MenuItem
61 {
62         const_iptr_t label;    /**< Item label (ID or ptr to string, 0 to disable) */
63         int          flags;    /**< See MIF_#? definitions below */
64         MenuHook     hook;     /**< Callback function (NULL to terminate item list) */
65         iptr_t       userdata; /**< User data to be passed back to the hook */
66 } MenuItem;
67
68 /** Render hook callback function prototype */
69 typedef void (*RenderHook)(struct Bitmap *bitmap, int ypos, bool selected, const struct MenuItem *item);
70
71 /**
72  * \name Flags for MenuItem.flags.
73  * \{
74  */
75 #define MIF_EXCLUDE_MASK    0x00FF /**< Mask for mutual exclusion map (shared with priority). */
76 #define MIF_PRI_MASK        0x00FF /**< Mask for priority value (shared with mutual exclusion). */
77 #define MIF_PRI(x)          ((x) & MIF_PRI_MASK) /**< Set menu item priority. */
78 #define MIF_EXCLUDE_0       BV(0)  /**< Exclude item 0 when this item is checked */
79 #define MIF_EXCLUDE_1       BV(1)  /**< Exclude item 1 when this item is checked */
80 #define MIF_EXCLUDE_2       BV(2)  /**< Exclude item 2 when this item is checked */
81 #define MIF_EXCLUDE_3       BV(3)  /**< Exclude item 3 when this item is checked */
82 #define MIF_EXCLUDE_4       BV(4)  /**< Exclude item 4 when this item is checked */
83 #define MIF_EXCLUDE_5       BV(5)  /**< Exclude item 5 when this item is checked */
84 #define MIF_EXCLUDE_6       BV(6)  /**< Exclude item 6 when this item is checked */
85 #define MIF_EXCLUDE_7       BV(7)  /**< Exclude item 7 when this item is checked */
86 #define MIF_CHECKED         BV(8)  /**< Item is currently checked */
87 #define MIF_CHECKIT         BV(9)  /**< Automatically check this item when selected */
88 #define MIF_TOGGLE          BV(10) /**< Toggle MIF_CHECKED when item is selected */
89 #define MIF_HIDDEN          BV(11) /**< This menu item is not visible */
90 #define MIF_DISABLED        BV(12) /**< This menu item is not visible */
91 #define MIF_RAMLABEL        BV(13) /**< Item label is stored in RAM, not in program memory */
92 #define MIF_RENDERHOOK      BV(14) /**< Menu render function is passed in label field */
93 /* \} */
94
95 /**
96  * Menu description.
97  */
98 typedef struct Menu
99 {
100         MenuItem        *items;    /**< Array of items (end with a NULL hook) */
101         const_iptr_t     title;    /**< Menu title (ID or ptr to string, 0 to disable) */
102         int              flags;    /**< See MF_#? definitions below */
103         struct Bitmap   *bitmap;   /**< Bitmap where the menu is rendered */
104         int              selected; /**< Initial selection (written to if MF_SAVESEL is set). */
105         BlitBitmap       lcd_blitBitmap; /**< Callback to call to do smooth the display */
106 } Menu;
107
108 /**
109  * \name Flags for Menu.flags.
110  * \{
111  */
112 #define MF_STICKY   BV(0)  /**< Stay in the menu when the items called return */
113 #define MF_TOPLEVEL BV(1)  /**< Top-level menu (do not display "back" label) */
114 #define MF_ROMITEMS BV(2)  /**< Menu items are stored in ROM (default is RAM) */
115 #define MF_SAVESEL  BV(3)  /**< Remember the selected item across invocations. */
116 /* \} */
117
118 /**
119  * \name Special result codes for menu_handle().
120  * \{
121  */
122 #define MENU_OK       ((iptr_t)0)
123 #define MENU_CANCEL   ((iptr_t)-1)
124 #define MENU_TIMEOUT  ((iptr_t)-2)
125 #define MENU_ABORT    ((iptr_t)-3)
126 #define MENU_DISABLED ((iptr_t)-4)
127 /* \} */
128
129 /* Function prototypes */
130 iptr_t menu_handle(const struct Menu *menu);
131 int menu_setFlags(struct Menu *menu, int idx, int flags);
132 int menu_clearFlags(struct Menu *menu, int idx, int flags);
133
134 /** \} */ //defgroup menu
135 #endif /* GUI_MENU_H */