/*
 *  menu_riscos.c -- menu creation, RISC OS
 */

#include "gui.h"

wimp_menu *gui_menu(unsigned int base, unsigned int items)
{
  char *text;
  unsigned int line, i;
  wimp_menu *menu;

  menu = malloc(wimp_SIZEOF_MENU(items));
  if (menu == NULL) gui_raise_error("out of memory");

  menu->title_data.indirected_text.text = gui_message[base];
  menu->title_fg = wimp_COLOUR_BLACK;
  menu->title_bg = wimp_COLOUR_VERY_LIGHT_GREY;
  menu->work_fg = wimp_COLOUR_RED;
  menu->work_bg = wimp_COLOUR_WHITE;
  menu->width = 300;
  menu->height = wimp_MENU_ITEM_HEIGHT;
  menu->gap = wimp_MENU_ITEM_GAP;

  for (i = 0; i < items; i++)
  {
    text = gui_message[base + 1 + i];

    line = (text[0] == '-'); if (line) text++;
    menu->entries[i].menu_flags = (i == 0 ? wimp_MENU_TITLE_INDIRECTED : 0) |
                                  (i == items-1 ? wimp_MENU_LAST : 0) |
                                  (line ? wimp_MENU_SEPARATE : 0);
    menu->entries[i].sub_menu = wimp_NO_SUB_MENU;
    menu->entries[i].icon_flags = wimp_ICON_TEXT | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED |
                                  wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT |
                                  wimp_COLOUR_WHITE << wimp_ICON_BG_COLOUR_SHIFT;
    menu->entries[i].data.indirected_text.text = text;
    menu->entries[i].data.indirected_text.validation = (char *) "";
  }

  return menu;
}

void gui_menu_attach(wimp_menu *menu, unsigned int item, wimp_menu *submenu)
{
  menu->entries[item].sub_menu = submenu;
}
