home *** CD-ROM | disk | FTP | other *** search
- /*
- #### # # # #
- # # # # # The FreeWare C library for
- # # ## ### # # # # ### RISC OS machines
- # # # # # # # # # # # ___________________________________
- # # #### ### ## # # # #
- # # # # # # # # # # Please refer to the accompanying
- #### ### #### # # ##### # ### documentation for conditions of use
- ________________________________________________________________________
-
- File: Menu.Extend.c
- Author: Copyright © 1993 Shaun Blackmore and Jason Williams
- Version: 1.00 (30 Apr 1993)
- Purpose: Extends a menu by adding entries to the bottom of it
- */
-
- #include <stdlib.h>
-
- #include "Error.h"
- #include "Screen.h"
- #include "Wimp.h"
-
-
- /* These two functions are defined in Menu.c.NewMenu */
- extern void Menu__CountItems(char *, int *, int *);
- extern BOOL Menu__Create(menu_item *, char *, int);
-
-
- extern menu_ptr Menu_Extend(menu_ptr menu, char *description)
- {
- menu_ptr newmenu;
- int maxwidth = 0, newitems = 0, lastitem = 0;
- menu_item *item = (menu_item *) ((int) menu + sizeof(menu_block));
-
- Menu__CountItems(description, &newitems, &maxwidth);
-
- maxwidth *= 8 * screen_delta.x;
- if (menu->width < maxwidth)
- menu->width = maxwidth;
-
- while (!item[lastitem].menuflags.data.last) /* Find the last item */
- lastitem++;
-
- newmenu = realloc((void *) menu, sizeof(menu_block) +
- (sizeof(menu_item) * (lastitem + 1 + newitems)));
- if (newmenu == NULL)
- return((menu_ptr) Error_OutOfMemory(FALSE, "menus"));
-
- item = (menu_item *) ((int) newmenu + sizeof(menu_block));
- item[lastitem].menuflags.data.last = FALSE;
-
- if (!Menu__Create(&item[lastitem + 1], description, newitems))
- return(menu);
-
- item[lastitem + newitems].menuflags.data.last = TRUE;
-
- return(newmenu);
- }
-