home *** CD-ROM | disk | FTP | other *** search
- /*----------------------------------------------------------------------*
- Med.c version 3.0 - © Copyright 1991 Jaba Development
-
- Author : Jan van den Baard
- Purpose: The editing of menus.
- *----------------------------------------------------------------------*/
- /*---------------------------------------------------*
- Gadgets created with GadgetEd V2.5
- which is (c) Copyright 1990-91 by Jaba Development
- written by Jan van den Baard
- *---------------------------------------------------*/
-
- static SHORT Border0_pairs[] = {
- -1,-1,266,-1,266,85,-1,85,-1,-1 };
- static SHORT Border1_pairs[] = {
- -1,-1,266,-1,266,9,-1,9,-1,-1 };
-
- static struct Border Border_bord[] = {
- 3,2,0,0,JAM1,5,(SHORT *)&Border0_pairs,&Border_bord[1],
- 3,2,0,0,JAM1,5,(SHORT *)&Border1_pairs,NULL };
-
- static struct IntuiText Render_text = {
- 0,1,JAM1,100,3,NULL,(UBYTE *)"Edit Menu",NULL };
-
- static SHORT FORMAT_pairs0[] = {
- -1,-1,124,-1,124,9,-1,9,-1,-1 };
-
- static struct Border FORMAT_bord = {
- 0,0,0,0,JAM1,5,(SHORT *)&FORMAT_pairs0,NULL };
-
- #define FORMAT_ID 8
-
- static struct Gadget FORMAT = {
- NULL,9,34,124,9,
- GADGHCOMP,
- RELVERIFY,
- BOOLGADGET,
- (APTR)&FORMAT_bord,NULL,
- NULL,NULL,NULL,FORMAT_ID,NULL };
-
- static SHORT CANCEL_pairs0[] = {
- -1,-1,58,-1,58,35,-1,35,-1,-1 };
-
- static struct Border CANCEL_bord = {
- 0,0,0,0,JAM1,5,(SHORT *)&CANCEL_pairs0,NULL };
-
- static struct IntuiText CANCEL_text = {
- 0,1,JAM1,5,14,NULL,(UBYTE *)"CANCEL",NULL };
-
- #define CANCEL_ID 7
-
- static struct Gadget CANCEL = {
- &FORMAT,205,48,58,35,
- GADGHCOMP,
- RELVERIFY,
- BOOLGADGET,
- (APTR)&CANCEL_bord,NULL,
- &CANCEL_text,NULL,NULL,CANCEL_ID,NULL };
-
- static SHORT OKIDOKI_pairs0[] = {
- -1,-1,58,-1,58,35,-1,35,-1,-1 };
-
- static struct Border OKIDOKI_bord = {
- 0,0,0,0,JAM1,5,(SHORT *)&OKIDOKI_pairs0,NULL };
-
- static struct IntuiText OKIDOKI_text = {
- 0,1,JAM1,21,14,NULL,(UBYTE *)"OK",NULL };
-
- #define OKIDOKI_ID 6
-
- static struct Gadget OKIDOKI = {
- &CANCEL,140,48,58,35,
- GADGHCOMP,
- RELVERIFY,
- BOOLGADGET,
- (APTR)&OKIDOKI_bord,NULL,
- &OKIDOKI_text,NULL,NULL,OKIDOKI_ID,NULL };
-
- static UBYTE HEIGHT_buf[5] = "0";
-
- static struct StringInfo HEIGHT_info = {
- (UBYTE *)&HEIGHT_buf,NULL,0,5,0,0,0,0,0,0,NULL,NULL,NULL };
-
- static SHORT HEIGHT_pairs0[] = {
- -1,-1,59,-1,59,8,-1,8,-1,-1 };
-
- static struct Border HEIGHT_bord = {
- 0,0,2,0,JAM1,5,(SHORT *)&HEIGHT_pairs0,NULL };
-
- static struct IntuiText HEIGHT_text = {
- 0,1,JAM2,5,-9,NULL,(UBYTE *)"HEIGHT",NULL };
-
- #define HEIGHT_ID 5
-
- static struct Gadget HEIGHT = {
- &OKIDOKI,73,75,59,8,
- GADGHCOMP+GADGDISABLED,
- RELVERIFY+STRINGCENTER+LONGINT,
- STRGADGET,
- (APTR)&HEIGHT_bord,NULL,
- &HEIGHT_text,NULL,(APTR)&HEIGHT_info,HEIGHT_ID,NULL };
-
- static UBYTE WIDTH_buf[5] = "0";
-
- static struct StringInfo WIDTH_info = {
- (UBYTE *)&WIDTH_buf,NULL,0,5,0,0,0,0,0,0,NULL,NULL,NULL };
-
- static SHORT WIDTH_pairs0[] = {
- -1,-1,59,-1,59,8,-1,8,-1,-1 };
-
- static struct Border WIDTH_bord = {
- 0,0,2,0,JAM1,5,(SHORT *)&WIDTH_pairs0,NULL };
-
- static struct IntuiText WIDTH_text = {
- 0,1,JAM2,10,-9,NULL,(UBYTE *)"WIDTH",NULL };
-
- #define WIDTH_ID 4
-
- static struct Gadget WIDTH = {
- &HEIGHT,9,75,59,8,
- GADGHCOMP+GADGDISABLED,
- RELVERIFY+STRINGCENTER+LONGINT,
- STRGADGET,
- (APTR)&WIDTH_bord,NULL,
- &WIDTH_text,NULL,(APTR)&WIDTH_info,WIDTH_ID,NULL };
-
- static UBYTE TOP_buf[5] = "0";
-
- static struct StringInfo TOP_info = {
- (UBYTE *)&TOP_buf,NULL,0,5,0,0,0,0,0,0,NULL,NULL,NULL };
-
- static SHORT TOP_pairs0[] = {
- -1,-1,59,-1,59,8,-1,8,-1,-1 };
-
- static struct Border TOP_bord = {
- 0,0,2,0,JAM1,5,(SHORT *)&TOP_pairs0,NULL };
-
- static struct IntuiText TOP_text = {
- 0,1,JAM2,16,-9,NULL,(UBYTE *)"TOP",NULL };
-
- #define TOP_ID 3
-
- static struct Gadget TOP = {
- &WIDTH,73,56,59,8,
- GADGHCOMP+GADGDISABLED,
- RELVERIFY+STRINGCENTER+LONGINT,
- STRGADGET,
- (APTR)&TOP_bord,NULL,
- &TOP_text,NULL,(APTR)&TOP_info,TOP_ID,NULL };
-
- static UBYTE LEFT_buf[5] = "0";
-
- static struct StringInfo LEFT_info = {
- (UBYTE *)&LEFT_buf,NULL,0,5,0,0,0,0,0,0,NULL,NULL,NULL };
-
- static SHORT LEFT_pairs0[] = {
- -1,-1,59,-1,59,8,-1,8,-1,-1 };
-
- static struct Border LEFT_bord = {
- 0,0,2,0,JAM1,5,(SHORT *)&LEFT_pairs0,NULL };
-
- static struct IntuiText LEFT_text = {
- 0,1,JAM2,15,-9,NULL,(UBYTE *)"LEFT",NULL };
-
- #define LEFT_ID 2
-
- static struct Gadget LEFT = {
- &TOP,9,56,59,8,
- GADGHCOMP+GADGDISABLED,
- RELVERIFY+STRINGCENTER+LONGINT,
- STRGADGET,
- (APTR)&LEFT_bord,NULL,
- &LEFT_text,NULL,(APTR)&LEFT_info,LEFT_ID,NULL };
-
- static SHORT ENABLE_pairs0[] = {
- -1,-1,124,-1,124,9,-1,9,-1,-1 };
-
- static struct Border ENABLE_bord = {
- 0,0,0,0,JAM1,5,(SHORT *)&ENABLE_pairs0,NULL };
-
- static struct IntuiText ENABLE_text = {
- 0,1,JAM1,18,1,NULL,(UBYTE *)"MENUENABLED",NULL };
-
- #define ENABLE_ID 1
-
- static struct Gadget ENABLE = {
- &LEFT,140,34,124,9,
- GADGHCOMP+SELECTED,
- TOGGLESELECT+GADGIMMEDIATE,
- BOOLGADGET,
- (APTR)&ENABLE_bord,NULL,
- &ENABLE_text,NULL,NULL,ENABLE_ID,NULL };
-
- static UBYTE MNAME_buf[33];
-
- static struct StringInfo MNAME_info = {
- (UBYTE *)&MNAME_buf,NULL,0,33,0,0,0,0,0,0,NULL,NULL,NULL };
-
- static SHORT MNAME_pairs0[] = {
- -1,-1,255,-1,255,8,-1,8,-1,-1 };
-
- static struct Border MNAME_bord = {
- 0,0,2,0,JAM1,5,(SHORT *)&MNAME_pairs0,NULL };
-
- static struct IntuiText MNAME_text = {
- 0,1,JAM1,92,-9,NULL,(UBYTE *)"MENU NAME",NULL };
-
- #define MNAME_ID 0
-
- static struct Gadget MNAME = {
- &ENABLE,9,22,255,8,
- GADGHCOMP,
- RELVERIFY+STRINGCENTER,
- STRGADGET,
- (APTR)&MNAME_bord,NULL,
- &MNAME_text,NULL,(APTR)&MNAME_info,MNAME_ID,NULL };
-
- static struct NewWindow nw_menu = {
- 24,15,272,89,0,1,
- GADGETDOWN+GADGETUP+CLOSEWINDOW,
- NOCAREREFRESH+SMART_REFRESH+ACTIVATE+RMBTRAP+BORDERLESS,
- NULL,NULL,
- NULL,NULL,NULL,
- 150,50,320,256,CUSTOMSCREEN };
-
- extern struct Window *MainWindow;
- extern struct Screen *MainScreen;
- extern struct RastPort *MainRP;
- extern struct Gadget *Gadget;
- extern struct MemoryChain Memory;
- extern struct MyMenu *MenuStrip;
- extern struct MenuItem dummy;
- extern struct Menu MainMenuStrip[];
- extern struct MenuItem MainItem[];
- extern struct ListItem *MenusList;
-
- extern ULONG Class;
- extern UWORD Code, MenuCount, MenuTotal;
-
- static struct Window *MedWindow;
- static UWORD CycleNum = 0L;
- static UBYTE Buffer[33];
-
- static struct IntuiText CycleText[] = {
- 0,1,JAM2,18,1,NULL,(UBYTE *)"AUTO FORMAT",NULL,
- 0,1,JAM2,18,1,NULL,(UBYTE *)"USER FORMAT",NULL
- };
-
- struct MyMenu *MakeMenu( void )
- {
- struct MyMenu *menu;
- WORD left;
-
- left = StripWidth();
-
- if(NOT MNAME_buf[0]) return(NULL);
-
- if((left + TEXT_WIDTH(MainRP,(char *)&MNAME_buf[0]) + MENUSPACING) <= MainScreen->Width) {
- if((menu = (struct MyMenu *)AllocItem(&Memory,(ULONG)sizeof(struct MyMenu),MEMF_PUBLIC))) {
- if(NOT CycleNum) {
- menu->LeftEdge = left;
- menu->Width = TEXT_WIDTH(MainRP,(char *)&MNAME_buf[0]) + MENUSPACING;
- menu->Height = TEXT_HEIGHT(MainRP);
- } else {
- menu->LeftEdge = LEFT_info.LongInt;
- menu->TopEdge = TOP_info.LongInt;
- menu->Width = WIDTH_info.LongInt;
- menu->Height = HEIGHT_info.LongInt;
- menu->SpecialFlags = USERFORMAT;
- }
-
- menu->MenuName = &menu->TheMenuName[0];
-
- if(SelectTest(&ENABLE))
- menu->Flags = MENUENABLED;
-
- strcpy((char *)&menu->TheMenuName[0],(char *)&MNAME_buf[0]);
- menu->FirstItem = (struct MyMenuItem *)&dummy;
- MenuCount++;
- MenuTotal++;
- return(menu);
- } else {
- enable_window();
- ok();
- Error("Out of memory!");
- }
- } else {
- enable_window();
- ok();
- Error("Menu won't fit!");
- }
- return(NULL);
- }
-
- void NIL( void )
- {
- register struct Gadget *g;
-
- for(g = &MNAME; g; g = g->NextGadget) {
- if(TestBits((ULONG)g->GadgetType,BOOLGADGET))
- g->Flags = NULL;
- }
-
- ENABLE.Flags = SELECTED;
-
- LEFT.Flags = GADGDISABLED;
- TOP.Flags = GADGDISABLED;
- WIDTH.Flags = GADGDISABLED;
- HEIGHT.Flags = GADGDISABLED;
-
- CycleNum = 0L;
-
- redisplay(&MNAME);
- }
-
- void RemoveMenu( struct ListItem *l )
- {
- struct MyMenu *menu, *pmenu;
- struct ListItem *pred;
- UWORD count;
- UBYTE message[36];
-
- menu = l->Menu;
-
- StringFormat((char *)&message,"Delete: %.27s",menu->MenuName);
- if(Ask(&message[0],"Are you sure?") == FALSE)
- return;
-
- ClearMenuStrip(MainWindow);
-
- if(l == MenusList) {
- for(count = 3; count < 7; count++)
- MainItem[count].SubItem = l->AItem.NextItem;
- MenusList = (struct ListItem *)l->AItem.NextItem;
- } else {
- pred = (struct ListItem *)FindPredItem(MenusList, l);
- pred->AItem.NextItem = l->AItem.NextItem;
- }
-
- if(menu == MenuStrip)
- MenuStrip = menu->NextMenu;
- else {
- pmenu = (struct MyMenu *)FindPredMenu(menu);
- pmenu->NextMenu = menu->NextMenu;
- }
- FreeMenu(menu);
- MenuCount--;
- MenuTotal--;
- ReformatM();
- ReformatList(MENUED);
- SetMenuStrip(MainWindow,&MainMenuStrip[0]);
- SetMainMenus();
- }
-
- void CheckNumbers( LONG l, LONG t, LONG w, LONG h )
- {
- if(l < 0 || l > MainScreen->Width) DisplayBeep(NULL);
- if(t < 0 || t > MainScreen->Height) DisplayBeep(NULL);
- if(w > MainScreen->Width) DisplayBeep(NULL);
- if(h > MainScreen->Height) DisplayBeep(NULL);
- if((l+w) > MainScreen->Width) DisplayBeep(NULL);
- if((t+h) > MainScreen->Height) DisplayBeep(NULL);
- }
-
- struct MyMenu *EditMenu( struct ListItem *l, ULONG ModeIns)
- {
- struct MyMenu *TheMenu, *Last, *Edit;
- BOOL running = TRUE;
- WORD width;
-
- NIL();
-
- if((NOT l) || ModeIns) {
- MNAME_buf[0] = 0;
- ENABLE.Flags = GADGHCOMP+SELECTED;
- LEFT_info.LongInt = StripWidth();
- TOP_info.LongInt = 0;
- WIDTH_info.LongInt = 10;
- HEIGHT_info.LongInt = 9;
- StringFormat((char *)&LEFT_buf[0],"%ld",StripWidth());
- strcpy((char *)&TOP_buf[0],"0");
- strcpy((char *)&WIDTH_buf[0],"10");
- strcpy((char *)&HEIGHT_buf[0],"9");
- } else if(l && (NOT ModeIns)) {
- Edit = l->Menu;
- strcpy((char *)&MNAME_buf[0],Edit->MenuName);
- strcpy((char *)&Buffer[0],Edit->MenuName);
- if(TestBits((ULONG)Edit->Flags,MENUENABLED))
- ENABLE.Flags = GADGHCOMP+SELECTED;
- else
- ENABLE.Flags = GADGHCOMP;
- LEFT_info.LongInt = Edit->LeftEdge;
- TOP_info.LongInt = Edit->TopEdge;
- WIDTH_info.LongInt = Edit->Width;
- HEIGHT_info.LongInt = Edit->Height;
- StringFormat((char *)&LEFT_buf[0],"%ld",Edit->LeftEdge);
- StringFormat((char *)&TOP_buf[0],"%ld",Edit->TopEdge);
- StringFormat((char *)&WIDTH_buf[0],"%ld",Edit->Width);
- StringFormat((char *)&HEIGHT_buf[0],"%ld",Edit->Height);
- if(TestBits((ULONG)Edit->SpecialFlags,USERFORMAT)) {
- CycleNum = 1L;
- LEFT.Flags = GADGHCOMP;
- TOP.Flags = GADGHCOMP;
- WIDTH.Flags = GADGHCOMP;
- HEIGHT.Flags = GADGHCOMP;
- }
- }
-
- FORMAT.GadgetText = &CycleText[CycleNum];
- nw_menu.Screen = MainScreen;
-
- if(NOT(MedWindow = (struct Window *)OpenWindow(&nw_menu)))
- return(NULL);
-
- disable_window();
- buisy();
-
- draw(MedWindow,&MNAME,&Border_bord[0],&Render_text);
- ActivateGadget(&MNAME,MedWindow,NULL);
-
- do {
- WaitPort(MedWindow->UserPort);
- while(read_msg(MedWindow)) {
- switch(Class) {
- case GADGETUP:
- switch(Gadget->GadgetID) {
- case OKIDOKI_ID:
- if(NOT MNAME_buf[0]) {
- DisplayBeep(MainScreen);
- break;
- }
- case CANCEL_ID:
- running = FALSE;
- break;
- case FORMAT_ID:
- if(CycleNum) {
- OffGList(MedWindow,&LEFT,NULL,4);
- FORMAT.GadgetText = &CycleText[0];
- CycleNum = 0;
- } else {
- OnGList(MedWindow,&LEFT,NULL,4);
- FORMAT.GadgetText = &CycleText[1];
- CycleNum = 1;
- }
- SetAPen(MedWindow->RPort,1);
- RectFill(MedWindow->RPort,9,34,133,43);
- RefreshGList(&FORMAT,MedWindow,NULL,1);
- break;
- case MNAME_ID:
- width = StripWidth();
- if(l) {
- if(((width - Edit->Width) + TEXT_WIDTH(MainRP,(char *)&MNAME_buf[0]) + MENUSPACING) > MainScreen->Width) {
- DisplayBeep(MainScreen);
- strcpy((char *)&MNAME_buf[0],(char *)&Buffer[0]);
- RefreshGList(&MNAME,MedWindow,NULL,1);
- }
- } else {
- if((width + TEXT_WIDTH(MainRP,(char *)&MNAME_buf[0]) + MENUSPACING) > MainScreen->Width)
- DisplayBeep(NULL);
- }
- break;
- case LEFT_ID:
- case TOP_ID:
- case WIDTH_ID:
- case HEIGHT_ID:
- CheckNumbers(LEFT_info.LongInt,TOP_info.LongInt,WIDTH_info.LongInt, HEIGHT_info.LongInt);
- break;
- }
- }
- }
- } while(running == TRUE);
- CloseWindow(MedWindow);
-
- if(Gadget->GadgetID == OKIDOKI_ID && ModeIns && l) {
- if((TheMenu = MakeMenu())) {
- if(l->Menu == MenuStrip) {
- TheMenu->NextMenu = MenuStrip;
- MenuStrip = TheMenu;
- } else {
- Last = (struct MyMenu *)FindPredMenu(l->Menu);
- Last->NextMenu = TheMenu;
- TheMenu->NextMenu = l->Menu;
- }
- TheMenu->ItsListItem = (struct ListItem *)CreateListItem((APTR)TheMenu, MENUED, TRUE, l, TRUE);
- ReformatM();
- enable_window();
- ok();
- return(NULL);
- } else
- return(NULL);
- } else if(Gadget->GadgetID == OKIDOKI_ID && (NOT l)) {
- if((TheMenu = MakeMenu())) {
- if(NOT MenuStrip)
- MenuStrip = TheMenu;
- else {
- Last = (struct MyMenu *)LastMenu();
- Last->NextMenu = TheMenu;
- }
- TheMenu->ItsListItem = (struct ListItem *)CreateListItem((APTR)TheMenu, MENUED, FALSE, NULL,TRUE);
- enable_window();
- ok();
- return(NULL);
- } else
- return(NULL);
- } else if(Gadget->GadgetID && l && (NOT ModeIns)) {
- if(SelectTest(&ENABLE))
- Edit->Flags = MENUENABLED;
- else
- Edit->Flags = NULL;
- strcpy(Edit->MenuName,(char *)&MNAME_buf[0]);
- strncpy((char *)&l->Letters[0],Edit->MenuName,9);
- if(NOT CycleNum) {
- Edit->Width = TEXT_WIDTH(MainRP,Edit->MenuName) + MENUSPACING;
- Edit->SpecialFlags = NULL;
- } else {
- Edit->LeftEdge = LEFT_info.LongInt;
- Edit->TopEdge = TOP_info.LongInt;
- Edit->Width = WIDTH_info.LongInt;
- Edit->Height = HEIGHT_info.LongInt;
- Edit->SpecialFlags = USERFORMAT;
- }
- ReformatM();
- enable_window();
- ok();
- }
- enable_window();
- ok();
- return(NULL);
- }
-