home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 2 / DATAFILE_PDCD2.iso / utilities2 / desklib / Libraries / Menu / c / Extend < prev    next >
Encoding:
Text File  |  1993-04-29  |  1.9 KB  |  59 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for 
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #                                      
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Menu.Extend.c
  12.     Author:  Copyright © 1993 Shaun Blackmore and Jason Williams
  13.     Version: 1.00 (30 Apr 1993)
  14.     Purpose: Extends a menu by adding entries to the bottom of it
  15. */
  16.  
  17. #include <stdlib.h>
  18.  
  19. #include "Error.h"
  20. #include "Screen.h"
  21. #include "Wimp.h"
  22.  
  23.  
  24. /* These two functions are defined in Menu.c.NewMenu */
  25. extern void Menu__CountItems(char *, int *, int *);
  26. extern BOOL Menu__Create(menu_item *, char *, int);
  27.  
  28.  
  29. extern menu_ptr Menu_Extend(menu_ptr menu, char *description)
  30. {
  31.   menu_ptr  newmenu;
  32.   int       maxwidth = 0, newitems = 0, lastitem = 0;
  33.   menu_item *item = (menu_item *) ((int) menu + sizeof(menu_block));
  34.  
  35.   Menu__CountItems(description, &newitems, &maxwidth);
  36.  
  37.   maxwidth *= 8 * screen_delta.x;
  38.   if (menu->width < maxwidth)
  39.     menu->width = maxwidth;
  40.  
  41.   while (!item[lastitem].menuflags.data.last)         /* Find the last item */
  42.     lastitem++;
  43.  
  44.   newmenu = realloc((void *) menu, sizeof(menu_block) +
  45.                              (sizeof(menu_item) * (lastitem + 1 + newitems)));
  46.   if (newmenu == NULL)
  47.     return((menu_ptr) Error_OutOfMemory(FALSE, "menus"));
  48.  
  49.   item = (menu_item *) ((int) newmenu + sizeof(menu_block));
  50.   item[lastitem].menuflags.data.last = FALSE;
  51.  
  52.   if (!Menu__Create(&item[lastitem + 1], description, newitems))
  53.     return(menu);
  54.  
  55.   item[lastitem + newitems].menuflags.data.last = TRUE;
  56.  
  57.   return(newmenu);
  58. }
  59.