home *** CD-ROM | disk | FTP | other *** search
- #include "stdlib.h"
- #include "string.h"
- #include "wimp.h"
- #include "types.h"
- #include "CreateMenu.h"
-
- /*
- Conversion From DeskLib by Andrew Campbell
-
- File: Menu.NewMenu.c
- Author: Copyright © 1993 Shaun Blackmore and Jason Williams
- Version: 1.00 (30 Apr 1993)
- Purpose: Creates a new menu given a textual description string
- */
-
-
- /* Description format:
- * opt :- " " no special options (i.e. leading spaces are skipped)
- * "!" ticked
- * "~" shaded
- * ">" has submenu/subwindow
- * "|" dotted
- * name :- any character except "," and "|"
- * entry :- {opt}* name
- * sep :- "," to separate normal items
- * "|" to separate items and place a dotted line between them
- * descr :- entry {sep entry}*
- *
- * EXAMPLE:
- * ">Info, Create, Quit"
- * "!Ticked,~Disabled|>Submenu"
- */
-
- extern bool Menu__Create(wimp_menu_entry *item, char *description, int numitems);
-
- extern bool Menu__Create(wimp_menu_entry *item, char *description, int numitems)
- {
- wimp_menu_entry *it;
- char *s, *t;
- int i, index;
- bool foundtext;
-
- s = description;
- for (i = 0; i < numitems; i++)
- {
- it = &item[i];
- it->menu_flags = 0x0u;
- it->sub_menu = NULL;
- it->icon_flags = wimp_ICON_TEXT | wimp_ICON_FILLED;
- it->icon_flags |= wimp_ICON_FG_COLOUR &
- (wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT );
- it->icon_flags |= wimp_ICON_BG_COLOUR &
- (wimp_COLOUR_WHITE << wimp_ICON_BG_COLOUR_SHIFT );
- foundtext = FALSE;
- do
- {
- switch(*s++)
- {
- case '!':
- it->menu_flags |= wimp_MENU_TICKED;
- break;
-
- case '~':
- it->icon_flags |= wimp_ICON_SHADED;
- break;
-
- case '>':
- /*it->menu_flags |= wimp_MENU_GIVE_WARNING;*/ /* Ask for sublink warnings */
- it->sub_menu = wimp_DEFER_SUB_MENU; /* This is sublink item '1' */
- break;
-
- case ' ': /* No option */
- break;
-
- default: /* Any other == start of menu item text, so don't lose it */
- s--;
- foundtext = TRUE;
- break;
- }
- } while (!foundtext);
-
- t = s;
- for (index = 0; ; index++)
- if (t[index] == 0 || t[index] == '|' || t[index] == ',')
- break;
-
- if (index <= wimp_MENU_NAME_LIMIT)
- t = it->data.text; /* Copy text directly into menu item */
- else
- {
- /* Copy text into indirected menu item */
- it->icon_flags |= wimp_ICON_INDIRECTED;
- it->data.indirected_text.text = malloc(index + 1);
-
- it->data.indirected_text.size = index + 1;
- it->data.indirected_text.validation = (char *) -1;
-
- t = it->data.indirected_text.text;
- }
-
- while (*s != 0 && *s != ',' && *s != '|')
- *t++ = *s++;
-
- *t = 0;
- if (*s++ == '|') /* Step over separator... */
- it->menu_flags |= wimp_MENU_SEPARATE; /* ...setting 'dotted' if needed */
- }
-
- return(TRUE);
- }
-
-
- extern wimp_menu *Menu_New(char *title, char *description, int numitems, int maxwidth)
- {
- wimp_menu *menu;
- wimp_menu_entry *item;
-
- maxwidth+=2;
-
- /*Menu__CountItems(description, &numitems, &maxwidth);*/
-
- if (strlen(title) > maxwidth) /* Make sure it is wide enough for title */
- maxwidth = strlen(title);
-
- menu = (wimp_menu*) malloc(sizeof(wimp_menu) + (numitems * sizeof(wimp_menu_entry)));
-
- /*item = (wimp_menu_entry *) &(menu[1]);*/ /* pointer after menu block */
-
- item = menu->entries;
-
- /* Copy the string. If it's less than 12 characters we need it to be
- * zero-terminated. We can let it go to 12 chars without any terminator
- * though, so we don't need to bother terminating after the strncpy.
- */
- strncpy(menu->title_data.text, title, 12);
-
- menu->title_fg = wimp_COLOUR_BLACK ;
- menu->title_bg = wimp_COLOUR_LIGHT_GREY ;
- menu->work_fg = wimp_COLOUR_BLACK ;
- menu->work_bg = wimp_COLOUR_WHITE ;
- menu->width = maxwidth * 16;
- menu->height = 44;
- menu->gap = 0;
-
- Menu__Create(item, description, numitems);
- item[numitems - 1].menu_flags |= wimp_MENU_LAST ;
-
- return(menu);
- }
-