-/*!
+/**
* \file
* <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
* Copyright 2003, 2004, 2006 Develer S.r.l. (http://www.develer.com/)
* Copyright 2000 Bernardo Innocenti <bernie@codewiz.org>
- * All Rights Reserved.
+ *
* -->
*
* \version $Id$
/*#*
*#* $Log$
+ *#* Revision 1.8 2006/09/13 13:58:32 bernie
+ *#* Add RenderHook support.
+ *#*
+ *#* Revision 1.7 2006/08/01 12:22:46 bernie
+ *#* Mention DevLib license.
+ *#*
+ *#* Revision 1.6 2006/07/19 12:56:27 bernie
+ *#* Convert to new Doxygen style.
+ *#*
+ *#* Revision 1.5 2006/06/03 13:58:01 bernie
+ *#* Fix recursive timeout and add exit status information.
+ *#*
*#* Revision 1.4 2006/06/02 12:26:18 bernie
*#* Draw graphical checkmarks.
*#*
*#*/
#include "menu.h"
+
#include <gfx/gfx.h>
#include <gfx/font.h>
#include <gfx/text.h>
#define PTRMSG(x) ((const char *)x)
#endif
+
/* Temporary fake defines for ABORT stuff... */
#define abort_top 0
#define PUSH_ABORT false
#if CONFIG_MENU_MENUBAR
-/*!
- * Update the menu bar according to the selected item
- * and redraw it.
+/**
+ * Update the menu bar according to the selected item and redraw it.
*/
static void menu_update_menubar(
const struct Menu *menu,
#endif /* CONFIG_MENU_MENUBAR */
+static void menu_defaultRenderHook(struct Bitmap *bm, int ypos, bool selected, const struct MenuItem *item)
+{
+ if (item->flags & MIF_CHECKIT)
+ {
+ gfx_rectClear(bm, 0, ypos,
+ bm->font->height, ypos + bm->font->height);
+
+ if (item->flags & MIF_TOGGLE)
+ gfx_rectDraw(bm, 2, ypos + 2,
+ bm->font->height - 2, ypos + bm->font->height - 2);
+ if (item->flags & MIF_CHECKED)
+ {
+ gfx_line(bm,
+ 3, ypos + 3,
+ bm->font->height - 3, ypos + bm->font->height - 3);
+ gfx_line(bm,
+ bm->font->height - 3, ypos + 3,
+ 3, ypos + bm->font->height - 3);
+ }
+ }
+
+#if CPU_HARVARD
+ ((item->flags & MIF_RAMLABEL) ? text_xyprintf : text_xyprintf_P)
+#else
+ text_xyprintf
+#endif
+ (
+ bm, (item->flags & MIF_CHECKIT) ? bm->font->height : 0, ypos,
+ selected ? (STYLEF_INVERT | TEXT_FILL) : TEXT_FILL,
+ PTRMSG(item->label)
+ );
+}
+
/**
* Show a menu on the display.
*/
memcpy_P(&ram_item, item, sizeof(ram_item));
item = &ram_item;
}
-#endif
+#endif /* CPU_HARVARD */
/* Check for end of room */
if (ypos > bm->cr.ymax)
/* Only print visible items */
if (!(item->flags & MIF_HIDDEN))
{
- if (item->flags & MIF_CHECKIT)
- {
- gfx_rectClear(bm, 0, ypos,
- bm->font->height, ypos + bm->font->height);
-
- if (item->flags & MIF_TOGGLE)
- gfx_rectDraw(bm, 2, ypos + 2,
- bm->font->height - 2, ypos + bm->font->height - 2);
- if (item->flags & MIF_CHECKED)
- {
- gfx_line(bm,
- 3, ypos + 3,
- bm->font->height - 3, ypos + bm->font->height - 3);
- gfx_line(bm,
- bm->font->height - 3, ypos + 3,
- 3, ypos + bm->font->height - 3);
- }
- }
+ /* Check if a special render function is supplied, otherwise use defaults */
+ RenderHook renderhook = (item->flags & MIF_RENDERHOOK) ? (RenderHook)item->label : menu_defaultRenderHook;
-#if CPU_HARVARD
- ((item->flags & MIF_RAMLABEL) ? text_xyprintf : text_xyprintf_P)
-#else
- text_xyprintf
-#endif
- (
- bm, (item->flags & MIF_CHECKIT) ? bm->font->height : 0, ypos,
- (i == selected) ? (STYLEF_INVERT | TEXT_FILL) : TEXT_FILL,
- PTRMSG(item->label)
- );
+ /* Render menuitem */
+ renderhook(menu->bitmap, ypos++, (i == selected), item);
ypos += bm->font->height;
}
gfx_setClipRect(bm,
bm->cr.xmin, old_ymin,
bm->cr.xmax, bm->cr.ymax);
-#endif
+
+#endif /* CONFIG_MENU_SMOOTH */
}
-/*!
+/**
* Handle menu item selection
*/
-static void menu_doselect(const struct Menu *menu, struct MenuItem *item)
+static iptr_t menu_doselect(const struct Menu *menu, struct MenuItem *item)
{
+ iptr_t result = 0;
+
/* Exclude other items */
int mask, i;
for (mask = item->flags & MIF_EXCLUDE_MASK, i = 0; mask; mask >>= 1, ++i)
}
if (item->flags & MIF_DISABLED)
- return;
+ return MENU_DISABLED;
/* Handle checkable items */
if (item->flags & MIF_TOGGLE)
/* Handle items with callback hooks */
if (item->hook)
{
- /* Push a jmp buffer to abort the operation with the STOP key */
+ /* Push a jmp buffer to abort the operation with the STOP/CANCEL key */
if (!PUSH_ABORT)
{
- item->hook(item->userdata);
+ result = item->hook(item->userdata);
POP_ABORT;
}
}
+ else
+ result = item->userdata;
+
+ return result;
}
uint8_t items_per_page;
uint8_t first_item = 0;
uint8_t selected;
+ iptr_t result = 0;
bool redraw = true;
#if (CONFIG_MENU_TIMEOUT != 0)
item = &ram_item;
}
#endif
- menu_doselect(menu, item);
+ result = menu_doselect(menu, item);
redraw = true;
- /* Return userdata as result */
- if (!menu->flags & MF_STICKY)
- {
- /* Store currently selected item before leaving. */
- if (menu->flags & MF_SAVESEL)
- CONST_CAST(struct Menu *, menu)->selected = selected;
- return item->userdata;
- }
+ /* Return immediately */
+ if (!(menu->flags & MF_STICKY))
+ break;
+
+ #if (CONFIG_MENU_TIMEOUT != 0)
+ /* Chain timeout */
+ if ((result == MENU_TIMEOUT) && !(menu->flags & MF_TOPLEVEL))
+ break;
+
+ /* Reset timeout */
+ menu_idle_time = timer_clock();
+ #endif
}
else if (key & K_UP)
{
selected = menu_next_visible_item(menu, selected);
redraw = true;
}
- else if (((key & K_CANCEL)
+ else if (!(menu->flags & MF_TOPLEVEL))
+ {
+ if (key & K_CANCEL)
+ {
+ result = MENU_CANCEL;
+ break;
+ }
+
#if CONFIG_MENU_TIMEOUT != 0
- || (now - menu_idle_time > ms_to_ticks(CONFIG_MENU_TIMEOUT))
+ if (now - menu_idle_time > ms_to_ticks(CONFIG_MENU_TIMEOUT))
+ {
+ result = MENU_TIMEOUT;
+ break;
+ }
#endif
- ) && !(menu->flags & MF_TOPLEVEL)
- )
- {
- /* Store currently selected item before leaving. */
- if (menu->flags & MF_SAVESEL)
- CONST_CAST(struct Menu *, menu)->selected = selected;
- return 0;
}
}
+
+ /* Store currently selected item before leaving. */
+ if (menu->flags & MF_SAVESEL)
+ CONST_CAST(struct Menu *, menu)->selected = selected;
+
+ return result;
}
-/*!
+/**
* Set flags on a menuitem.
*
* \param menu Menu owner of the item to change.
}
-/*!
+/**
* Clear flags on a menuitem.
*
* \param menu Menu owner of the item to change.