Интерфейс пользователя при построении системного ПО. Структура системы меню, страница 2


Текст программы:

#include "stdio.h"

#include "stdlib.h"

#include "ctype.h"

#include "graphics.h"

#include "bios.h"

#include "conio.h"

#include "string.h"

#define NS 200

#define W 90

#define H 17

#define BkClr 1

#define FillClr 8 //Fill color

#define SlctClr 2 //Fill color for selected item

#define TxtClr 5 //Text color

#define SlctTxtClr 12 //Text color for selected item

#define Esc 283

#define Left 19200

#define Right 19712

#define Up 18432

#define Down 20480

#define Enter 7181

class Menu_Item;

struct item_list //Element of menu list

{

       item_list *next;

       item_list *prev;

       Menu_Item *Item;

};

class Menu_Item

{

       public:

       int x;

       int y;

       char Name[NS];

       item_list *Children;

       item_list *Parent;

       int Selected;

       int Main;

Menu_Item :: Menu_Item(char *Str, char *aName, int nx, int ny, item_list *P, int isMain, item_list *ths, int chx);

};

class Main_Menu

{

       public:

       item_list *items;

       item_list *Cur;

       Main_Menu(char *Str);  //Constructor for main menu

       void Paint_Item(Menu_Item *I);

       void Erase_Item(Menu_Item *I);

       void Paint_Tree(item_list *I);

       void Erase_Tree(item_list *I);

       void Process();

};

//==================Menu_Item====================

Menu_Item :: Menu_Item(char *Str, char *aName, int nx, int ny, item_list *P, int isMain, item_list *ths, int chx)

{      //Constructor for every menu item

       strcpy(&Name[0], aName);

       x = nx;

       y = ny;

       Parent = P;

       Selected = 0;

       Main = isMain;

       if (strlen(Str)>0)

       {

              item_list *t;

              t = new item_list;

              t->next = NULL;

              t->prev = NULL;

              Children = t;

              int o,c,i,cx,cy,ID;

              if (chx) cx = nx+W;

              else cx = nx;

              if (!chx)

              cy = ny+H; else cy = ny;

              char aN[NS], aT[NS];

              char *F, *T, *N;

              N = &aN[0];

              F = &aN[0];

              T = &aT[0];

              for(i=0;i<NS;i++){aN[i]='\0';aT[i]='\0';}

              while (strlen(Str)>0)

              {

                     if (*Str=='{')

                     {

                            for(i=0;i<NS;i++)aT[i]='\0';

                            T = &aT[0];

                            strcpy(T, F);

                            for(i=0;i<NS;i++)aN[i]='\0';

                            N = &aN[0];   F = &aN[0];

                            o=1; c=0;

                            *N = *Str;

                            Str++; N++;

                            while (o!=c)

                            {

                                    if (*Str == '{') o++;

                                    else

                                    if (*Str == '}') c++;

                                    *N = *Str;

                                    Str++; N++;

                            }

                            N--; *N='\0'; F++;//Add new item

                            t->Item = new Menu_Item(F,T, cx, cy, ths, 0, t, 1);

                            t->next = new item_list;

                            t->next->prev = t;

                            t = t->next; t->next = NULL;

                            cy += H;

                            for(i=0;i<NS;i++)aN[i]='\0';

                            N = &aN[0];   F = &aN[0];

                     } else

                     if (*Str==',')

                     {

                            N++; *N='\0';//Add new item

                            t->Item = new Menu_Item(NULL, F, cx, cy, ths, 0, t, 1);

                            t->next = new item_list;

                            t->next->prev = t;

                            t = t->next; t->next = NULL;

                            cy += H;

                            for(i=0;i<NS;i++)aN[i]='\0';

                            N = &aN[0];   F = &aN[0];

                     } else

                     {      *N = *Str; N++;}

                     if (strlen(Str)>0) Str++;

              }

              N++; *N='\0';