home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 568b.lha / PowerSource_v3.0 / source.lzh / source / Ied.c < prev    next >
Text File  |  1991-09-15  |  27KB  |  907 lines

  1. /*----------------------------------------------------------------------*
  2.     Ied.c version 3.0 - © Copyright 1991 Jaba Development
  3.  
  4.     Author : Jan van den Baard
  5.     Purpose: The editing on items and subitems.
  6.  *----------------------------------------------------------------------*/
  7. /*---------------------------------------------------*
  8.   Gadgets created with GadgetEd V2.5
  9.   which is (c) Copyright 1990-91 by Jaba Development
  10.   written by Jan van den Baard
  11.  *---------------------------------------------------*/
  12.  
  13. static SHORT Border0_pairs[] = {
  14.   -1,-1,266,-1,266,140,-1,140,-1,-1 };
  15. static SHORT Border1_pairs[] = {
  16.   -1,-1,266,-1,266,9,-1,9,-1,-1 };
  17.  
  18. static struct Border Border_bord[] = {
  19.   3,2,0,0,JAM1,5,(SHORT *)&Border0_pairs,&Border_bord[1],
  20.   3,2,0,0,JAM1,5,(SHORT *)&Border1_pairs,NULL };
  21.  
  22. static struct IntuiText Render_text = {
  23.   0,1,JAM1,84,3,NULL,(UBYTE *)"Edit MenuItem",NULL };
  24. static struct IntuiText Render_text1 = {
  25.   0,1,JAM1,88,3,NULL,(UBYTE *)"Edit SubItem",NULL };
  26.  
  27. static SHORT CANCEL_pairs0[] = {
  28.   -1,-1,58,-1,58,35,-1,35,-1,-1 };
  29.  
  30. static struct Border CANCEL_bord = {
  31.   0,0,0,0,JAM1,5,(SHORT *)&CANCEL_pairs0,NULL };
  32.  
  33. static struct IntuiText CANCEL_text = {
  34.   0,1,JAM1,5,14,NULL,(UBYTE *)"CANCEL",NULL };
  35.  
  36. #define CANCEL_ID    17
  37.  
  38. static struct Gadget CANCEL = {
  39.   NULL,205,103,58,35,
  40.   GADGHCOMP,
  41.   RELVERIFY,
  42.   BOOLGADGET,
  43.   (APTR)&CANCEL_bord,NULL,
  44.   &CANCEL_text,NULL,NULL,CANCEL_ID,NULL };
  45.  
  46. static SHORT OKIDOKI_pairs0[] = {
  47.   -1,-1,58,-1,58,35,-1,35,-1,-1 };
  48.  
  49. static struct Border OKIDOKI_bord = {
  50.   0,0,0,0,JAM1,5,(SHORT *)&OKIDOKI_pairs0,NULL };
  51.  
  52. static struct IntuiText OKIDOKI_text = {
  53.   0,1,JAM1,21,14,NULL,(UBYTE *)"OK",NULL };
  54.  
  55. #define OKIDOKI_ID    16
  56.  
  57. static struct Gadget OKIDOKI = {
  58.   &CANCEL,139,103,58,35,
  59.   GADGHCOMP,
  60.   RELVERIFY,
  61.   BOOLGADGET,
  62.   (APTR)&OKIDOKI_bord,NULL,
  63.   &OKIDOKI_text,NULL,NULL,OKIDOKI_ID,NULL };
  64.  
  65. static UBYTE HEIGHT_buf[5] = "0";
  66.  
  67. static struct StringInfo HEIGHT_info = {
  68.   (UBYTE *)&HEIGHT_buf,NULL,0,5,0,0,0,0,0,0,NULL,NULL,NULL };
  69.  
  70. static SHORT HEIGHT_pairs0[] = {
  71.   -1,-1,59,-1,59,8,-1,8,-1,-1 };
  72.  
  73. static struct Border HEIGHT_bord = {
  74.   0,0,2,0,JAM1,5,(SHORT *)&HEIGHT_pairs0,NULL };
  75.  
  76. static struct IntuiText HEIGHT_text = {
  77.   0,1,JAM2,5,-9,NULL,(UBYTE *)"HEIGHT",NULL };
  78.  
  79. #define HEIGHT_ID    15
  80.  
  81. static struct Gadget HEIGHT = {
  82.   &OKIDOKI,72,130,59,8,
  83.   GADGHCOMP+GADGDISABLED,
  84.   RELVERIFY+STRINGCENTER+LONGINT,
  85.   STRGADGET,
  86.   (APTR)&HEIGHT_bord,NULL,
  87.   &HEIGHT_text,NULL,(APTR)&HEIGHT_info,HEIGHT_ID,NULL };
  88.  
  89. static UBYTE WIDTH_buf[5] = "0";
  90.  
  91. static struct StringInfo WIDTH_info = {
  92.   (UBYTE *)&WIDTH_buf,NULL,0,5,0,0,0,0,0,0,NULL,NULL,NULL };
  93.  
  94. static SHORT WIDTH_pairs0[] = {
  95.   -1,-1,59,-1,59,8,-1,8,-1,-1 };
  96.  
  97. static struct Border WIDTH_bord = {
  98.   0,0,2,0,JAM1,5,(SHORT *)&WIDTH_pairs0,NULL };
  99.  
  100. static struct IntuiText WIDTH_text = {
  101.   0,1,JAM2,10,-9,NULL,(UBYTE *)"WIDTH",NULL };
  102.  
  103. #define WIDTH_ID    14
  104.  
  105. static struct Gadget WIDTH = {
  106.   &HEIGHT,8,130,59,8,
  107.   GADGHCOMP+GADGDISABLED,
  108.   RELVERIFY+STRINGCENTER+LONGINT,
  109.   STRGADGET,
  110.   (APTR)&WIDTH_bord,NULL,
  111.   &WIDTH_text,NULL,(APTR)&WIDTH_info,WIDTH_ID,NULL };
  112.  
  113. static UBYTE TOP_buf[5] = "0";
  114.  
  115. static struct StringInfo TOP_info = {
  116.   (UBYTE *)&TOP_buf,NULL,0,5,0,0,0,0,0,0,NULL,NULL,NULL };
  117.  
  118. static SHORT TOP_pairs0[] = {
  119.   -1,-1,59,-1,59,8,-1,8,-1,-1 };
  120.  
  121. static struct Border TOP_bord = {
  122.   0,0,2,0,JAM1,5,(SHORT *)&TOP_pairs0,NULL };
  123.  
  124. static struct IntuiText TOP_text = {
  125.   0,1,JAM2,16,-9,NULL,(UBYTE *)"TOP",NULL };
  126.  
  127. #define TOP_ID    13
  128.  
  129. static struct Gadget TOP = {
  130.   &WIDTH,72,111,59,8,
  131.   GADGHCOMP+GADGDISABLED,
  132.   RELVERIFY+STRINGCENTER+LONGINT,
  133.   STRGADGET,
  134.   (APTR)&TOP_bord,NULL,
  135.   &TOP_text,NULL,(APTR)&TOP_info,TOP_ID,NULL };
  136.  
  137. static UBYTE LEFT_buf[5] = "0";
  138.  
  139. static struct StringInfo LEFT_info = {
  140.   (UBYTE *)&LEFT_buf,NULL,0,5,0,0,0,0,0,0,NULL,NULL,NULL };
  141.  
  142. static SHORT LEFT_pairs0[] = {
  143.   -1,-1,59,-1,59,8,-1,8,-1,-1 };
  144.  
  145. static struct Border LEFT_bord = {
  146.   0,0,2,0,JAM1,5,(SHORT *)&LEFT_pairs0,NULL };
  147.  
  148. static struct IntuiText LEFT_text = {
  149.   0,1,JAM2,15,-9,NULL,(UBYTE *)"LEFT",NULL };
  150.  
  151. #define LEFT_ID    12
  152.  
  153. static struct Gadget LEFT = {
  154.   &TOP,8,111,59,8,
  155.   GADGHCOMP+GADGDISABLED,
  156.   RELVERIFY+STRINGCENTER+LONGINT,
  157.   STRGADGET,
  158.   (APTR)&LEFT_bord,NULL,
  159.   &LEFT_text,NULL,(APTR)&LEFT_info,LEFT_ID,NULL };
  160.  
  161. static SHORT FORMAT_pairs0[] = {
  162.   -1,-1,124,-1,124,9,-1,9,-1,-1 };
  163.  
  164. static struct Border FORMAT_bord = {
  165.   0,0,0,0,JAM1,5,(SHORT *)&FORMAT_pairs0,NULL };
  166.  
  167. #define FORMAT_ID    11
  168.  
  169. static struct Gadget FORMAT = {
  170.   &LEFT,8,89,124,9,
  171.   GADGHCOMP,
  172.   RELVERIFY,
  173.   BOOLGADGET,
  174.   (APTR)&FORMAT_bord,NULL,
  175.   NULL,NULL,NULL,FORMAT_ID,NULL };
  176.  
  177. static SHORT DRMD_pairs0[] = {
  178.   -1,-1,124,-1,124,9,-1,9,-1,-1 };
  179.  
  180. static struct Border DRMD_bord = {
  181.   0,0,0,0,JAM1,5,(SHORT *)&DRMD_pairs0,NULL };
  182.  
  183. #define DRMD_ID    10
  184.  
  185. static struct Gadget DRMD = {
  186.   &FORMAT,139,89,124,9,
  187.   GADGHCOMP,
  188.   RELVERIFY,
  189.   BOOLGADGET,
  190.   (APTR)&DRMD_bord,NULL,
  191.   NULL,NULL,NULL,DRMD_ID,NULL };
  192.  
  193. static UBYTE ITEXT_buf[33];
  194.  
  195. static struct StringInfo ITEXT_info = {
  196.   (UBYTE *)&ITEXT_buf,NULL,0,33,0,0,0,0,0,0,NULL,NULL,NULL };
  197.  
  198. static SHORT ITEXT_pairs0[] = {
  199.   -1,-1,124,-1,124,8,-1,8,-1,-1 };
  200.  
  201. static struct Border ITEXT_bord = {
  202.   0,0,2,0,JAM1,5,(SHORT *)&ITEXT_pairs0,NULL };
  203.  
  204. static struct IntuiText ITEXT_text = {
  205.   0,1,JAM2,26,-9,NULL,(UBYTE *)"ITEM TEXT",NULL };
  206.  
  207. #define ITEXT_ID    9
  208.  
  209. static struct Gadget ITEXT = {
  210.   &DRMD,139,76,124,8,
  211.   GADGHCOMP,
  212.   RELVERIFY+STRINGCENTER,
  213.   STRGADGET,
  214.   (APTR)&ITEXT_bord,NULL,
  215.   &ITEXT_text,NULL,(APTR)&ITEXT_info,ITEXT_ID,NULL };
  216.  
  217. static UBYTE CK_buf[2];
  218.  
  219. static struct StringInfo CK_info = {
  220.   (UBYTE *)&CK_buf,NULL,0,2,0,0,0,0,0,0,NULL,NULL,NULL };
  221.  
  222. static SHORT CK_pairs0[] = {
  223.   -1,-1,124,-1,124,8,-1,8,-1,-1 };
  224.  
  225. static struct Border CK_bord = {
  226.   0,0,2,0,JAM1,5,(SHORT *)&CK_pairs0,NULL };
  227.  
  228. static struct IntuiText CK_text = {
  229.   0,1,JAM2,17,-9,NULL,(UBYTE *)"COMMAND KEY",NULL };
  230.  
  231. #define CK_ID    8
  232.  
  233. static struct Gadget CK = {
  234.   &ITEXT,8,76,124,8,
  235.   GADGHCOMP,
  236.   RELVERIFY+STRINGCENTER,
  237.   STRGADGET,
  238.   (APTR)&CK_bord,NULL,
  239.   &CK_text,NULL,(APTR)&CK_info,CK_ID,NULL };
  240.  
  241. static SHORT IE_pairs0[] = {
  242.   -1,-1,124,-1,124,9,-1,9,-1,-1 };
  243.  
  244. static struct Border IE_bord = {
  245.   0,0,0,0,JAM1,5,(SHORT *)&IE_pairs0,NULL };
  246.  
  247. static struct IntuiText IE_text = {
  248.   0,1,JAM1,18,1,NULL,(UBYTE *)"ITEMENABLED",NULL };
  249.  
  250. #define IE_ID    7
  251.  
  252. static struct Gadget IE = {
  253.   &CK,139,54,124,9,
  254.   GADGHCOMP+SELECTED,
  255.   TOGGLESELECT+GADGIMMEDIATE,
  256.   BOOLGADGET,
  257.   (APTR)&IE_bord,NULL,
  258.   &IE_text,NULL,NULL,IE_ID,NULL };
  259.  
  260. static SHORT MT_pairs0[] = {
  261.   -1,-1,124,-1,124,9,-1,9,-1,-1 };
  262.  
  263. static struct Border MT_bord = {
  264.   0,0,0,0,JAM1,5,(SHORT *)&MT_pairs0,NULL };
  265.  
  266. static struct IntuiText MT_text = {
  267.   0,1,JAM1,22,1,NULL,(UBYTE *)"MENUTOGGLE",NULL };
  268.  
  269. #define MT_ID    6
  270.  
  271. static struct Gadget MT = {
  272.   &IE,139,41,124,9,
  273.   GADGHCOMP,
  274.   TOGGLESELECT+GADGIMMEDIATE,
  275.   BOOLGADGET,
  276.   (APTR)&MT_bord,NULL,
  277.   &MT_text,NULL,NULL,MT_ID,NULL };
  278.  
  279. static SHORT CI_pairs0[] = {
  280.   -1,-1,124,-1,124,9,-1,9,-1,-1 };
  281.  
  282. static struct Border CI_bord = {
  283.   0,0,0,0,JAM1,5,(SHORT *)&CI_pairs0,NULL };
  284.  
  285. static struct IntuiText CI_text = {
  286.   0,1,JAM1,34,1,NULL,(UBYTE *)"CHECKIT",NULL };
  287.  
  288. #define CI_ID    5
  289.  
  290. static struct Gadget CI = {
  291.   &MT,139,28,124,9,
  292.   GADGHCOMP,
  293.   TOGGLESELECT+GADGIMMEDIATE,
  294.   BOOLGADGET,
  295.   (APTR)&CI_bord,NULL,
  296.   &CI_text,NULL,NULL,CI_ID,NULL };
  297.  
  298. static SHORT CD_pairs0[] = {
  299.   -1,-1,124,-1,124,9,-1,9,-1,-1 };
  300.  
  301. static struct Border CD_bord = {
  302.   0,0,0,0,JAM1,5,(SHORT *)&CD_pairs0,NULL };
  303.  
  304. static struct IntuiText CD_text = {
  305.   0,1,JAM1,34,1,NULL,(UBYTE *)"CHECKED",NULL };
  306.  
  307. #define CD_ID    4
  308.  
  309. static struct Gadget CD = {
  310.   &CI,139,15,124,9,
  311.   GADGHCOMP,
  312.   TOGGLESELECT+GADGIMMEDIATE,
  313.   BOOLGADGET,
  314.   (APTR)&CD_bord,NULL,
  315.   &CD_text,NULL,NULL,CD_ID,NULL };
  316.  
  317. static SHORT CS_pairs0[] = {
  318.   -1,-1,124,-1,124,9,-1,9,-1,-1 };
  319.  
  320. static struct Border CS_bord = {
  321.   0,0,0,0,JAM1,5,(SHORT *)&CS_pairs0,NULL };
  322.  
  323. static struct IntuiText CS_text = {
  324.   0,1,JAM1,34,1,NULL,(UBYTE *)"COMMSEQ",NULL };
  325.  
  326. #define CS_ID    3
  327.  
  328. static struct Gadget CS = {
  329.   &CD,8,54,124,9,
  330.   GADGHCOMP,
  331.   TOGGLESELECT+GADGIMMEDIATE,
  332.   BOOLGADGET,
  333.   (APTR)&CS_bord,NULL,
  334.   &CS_text,NULL,NULL,CS_ID,NULL };
  335.  
  336. static SHORT HN_pairs0[] = {
  337.   -1,-1,124,-1,124,9,-1,9,-1,-1 };
  338.  
  339. static struct Border HN_bord = {
  340.   0,0,0,0,JAM1,5,(SHORT *)&HN_pairs0,NULL };
  341.  
  342. static struct IntuiText HN_text = {
  343.   0,1,JAM1,30,1,NULL,(UBYTE *)"HIGHNONE",NULL };
  344.  
  345. #define HN_ID    2
  346.  
  347. static struct Gadget HN = {
  348.   &CS,8,41,124,9,
  349.   GADGHCOMP,
  350.   TOGGLESELECT+GADGIMMEDIATE,
  351.   BOOLGADGET,
  352.   (APTR)&HN_bord,NULL,
  353.   &HN_text,3L,NULL,HN_ID,NULL };
  354.  
  355. static SHORT HB_pairs0[] = {
  356.   -1,-1,124,-1,124,9,-1,9,-1,-1 };
  357.  
  358. static struct Border HB_bord = {
  359.   0,0,0,0,JAM1,5,(SHORT *)&HB_pairs0,NULL };
  360.  
  361. static struct IntuiText HB_text = {
  362.   0,1,JAM1,34,1,NULL,(UBYTE *)"HIGHBOX",NULL };
  363.  
  364. #define HB_ID    1
  365.  
  366. static struct Gadget HB = {
  367.   &HN,8,28,124,9,
  368.   GADGHCOMP,
  369.   TOGGLESELECT+GADGIMMEDIATE,
  370.   BOOLGADGET,
  371.   (APTR)&HB_bord,NULL,
  372.   &HB_text,5L,NULL,HB_ID,NULL };
  373.  
  374. static SHORT HC_pairs0[] = {
  375.   -1,-1,124,-1,124,9,-1,9,-1,-1 };
  376.  
  377. static struct Border HC_bord = {
  378.   0,0,0,0,JAM1,5,(SHORT *)&HC_pairs0,NULL };
  379.  
  380. static struct IntuiText HC_text = {
  381.   0,1,JAM1,30,1,NULL,(UBYTE *)"HIGHCOMP",NULL };
  382.  
  383. #define HC_ID    0
  384.  
  385. static struct Gadget HC = {
  386.   &HB,8,15,124,9,
  387.   GADGHCOMP+SELECTED,
  388.   TOGGLESELECT+GADGIMMEDIATE,
  389.   BOOLGADGET,
  390.   (APTR)&HC_bord,NULL,
  391.   &HC_text,6L,NULL,HC_ID,NULL };
  392.  
  393. static struct NewWindow nw_item = {
  394.   24,15,272,144,0,1,
  395.   GADGETDOWN+GADGETUP+CLOSEWINDOW,
  396.   NOCAREREFRESH+SMART_REFRESH+ACTIVATE+RMBTRAP+BORDERLESS,
  397.   NULL,NULL,
  398.   NULL,NULL,NULL,
  399.   150,50,320,256,CUSTOMSCREEN };
  400.  
  401. extern struct Window        *MainWindow;
  402. extern struct Screen        *MainScreen;
  403. extern struct RastPort      *MainRP;
  404. extern struct Gadget        *Gadget;
  405. extern struct MyMenu        *ParentMenu;
  406. extern struct MyMenuItem    *ParentItem;
  407. extern struct ListItem      *ItemsList, *SubsList;
  408. extern struct MyMenu        *MenuStrip;
  409. extern struct MemoryChain    Memory;
  410. extern struct MyMenuItem     dummy;
  411. extern struct MenuItem       TheItem[], SubItem[];
  412. extern struct Menu           ItemMenuStrip[], SubMenuStrip[];
  413.  
  414. extern ULONG                 Class;
  415. extern UWORD                 Code, ItemCount, SubCount;
  416. extern UWORD                 ActEd, ItemTotal, SubTotal;
  417. extern UWORD                 FrontPen, BackPen;
  418. extern BOOL                  Saved;
  419.  
  420. static struct Window    *IedWindow;
  421. static UWORD             FormatNum = 0L, DrMdNum = 0L;
  422.  
  423. static UBYTE             DrMd[] = { JAM1,JAM2,COMPLEMENT,INVERSVID };
  424.  
  425. static struct IntuiText  FmatText[] = {
  426.     0,1,JAM2,18,1,NULL,(UBYTE *)"AUTO FORMAT",NULL,
  427.     0,1,JAM2,18,1,NULL,(UBYTE *)"USER FORMAT",NULL
  428. };
  429.  
  430. static struct IntuiText DrMdText[] = {
  431.     0,1,JAM2,46,1,NULL,(UBYTE *)"JAM1",NULL,
  432.     0,1,JAM2,46,1,NULL,(UBYTE *)"JAM2",NULL,
  433.     0,1,JAM2,22,1,NULL,(UBYTE *)"COMPLEMENT",NULL,
  434.     0,1,JAM2,26,1,NULL,(UBYTE *)"INVERSVID",NULL
  435. };
  436.  
  437. void SetNIL( void )
  438. {
  439.     register struct Gadget *g;
  440.  
  441.     for(g = &HB; g; g = g->NextGadget) {
  442.         if(TestBits((ULONG)g->GadgetType,BOOLGADGET))
  443.             g->Flags = GADGHCOMP;
  444.     }
  445.  
  446.     HC.Flags    = SELECTED;
  447.     IE.Flags    = SELECTED;
  448.  
  449.     CK_buf[0]    = 0;
  450.     ITEXT_buf[0] = 0;
  451.  
  452.     FormatNum    = 0;
  453.     DrMdNum      = 0;
  454.     LEFT.Flags   = GADGDISABLED;
  455.     TOP.Flags    = GADGDISABLED;
  456.     WIDTH.Flags  = GADGDISABLED;
  457.     HEIGHT.Flags = GADGDISABLED;
  458.  
  459.     redisplay(&ITEXT);
  460. }
  461.  
  462. struct MyMenuItem *MakeItem( void )
  463. {
  464.     struct MyMenuItem   *item;
  465.     struct IntuiText    *itext;
  466.     WORD                 top, width;
  467.  
  468.     if(NOT ITEXT_buf[0]) return(NULL);
  469.  
  470.     width = TEXT_WIDTH(MainRP,(char *)&ITEXT_buf[0]) + TEXTSPACING;
  471.     if(SelectTest(&CS)) width += 40;
  472.     if(SelectTest(&CI)) width += 20;
  473.  
  474.     if(ActEd == ITEMED) {
  475.         if((width + 10) > MainScreen->Width)
  476.             goto nfErr;
  477.         if(ParentMenu->FirstItem == &dummy)
  478.             top = MainScreen->BarHeight-1;
  479.         else
  480.             top = ItemHeight( ParentMenu->FirstItem ) + MainScreen->BarHeight-1;
  481.     } else {
  482.         if((width + ParentItem->Width) > MainScreen->Width)
  483.             goto nfErr;
  484.         if(NOT ParentItem->SubItem)
  485.             top = ParentItem->TopEdge + MainScreen->BarHeight - 1;
  486.         else
  487.             top = ItemHeight(ParentItem->SubItem) + ParentItem->TopEdge + MainScreen->BarHeight - 1;
  488.     }
  489.  
  490.     if(MainScreen->Width == 320)
  491.         top += MainScreen->MenuHBorder;
  492.  
  493.     if((top + TEXT_HEIGHT(MainRP) + ITEMSPACING + MainScreen->MenuHBorder) > MainScreen->Height)
  494.         goto nfErr;
  495.  
  496.     if(NOT(item = (struct MyMenuItem *)AllocItem(&Memory,(ULONG)sizeof(struct MyMenuItem),MEMF_PUBLIC)))
  497.         goto itErr;
  498.     if(NOT(itext = (struct IntuiText *)MakeIText(&ITEXT_buf[0],DrMd[DrMdNum],80L)))
  499.         goto itErr;
  500.  
  501.     if(NOT FormatNum)
  502.         item->Height   = TEXT_HEIGHT(MainRP) + ITEMSPACING;
  503.     else {
  504.         item->LeftEdge = LEFT_info.LongInt;
  505.         item->TopEdge  = TOP_info.LongInt;
  506.         item->Width    = WIDTH_info.LongInt;
  507.         item->Height   = HEIGHT_info.LongInt;
  508.         item->SpecialFlags = USERFORMAT;
  509.     }
  510.  
  511.     if(SelectTest(&HC))         item->Flags = HIGHCOMP;
  512.     else if(SelectTest(&HB))    item->Flags = HIGHBOX;
  513.     else                        item->Flags = HIGHNONE;
  514.  
  515.     if(SelectTest(&CI)) {       item->Flags |= CHECKIT;
  516.                                 itext->LeftEdge = 18;
  517.                         }
  518.     if(SelectTest(&CS)) {       item->Flags  |= COMMSEQ;
  519.                                 item->Command = CK_buf[0];
  520.                         }
  521.     if(SelectTest(&MT))         item->Flags |= MENUTOGGLE;
  522.     if(SelectTest(&IE))         item->Flags |= ITEMENABLED;
  523.     if(SelectTest(&CD))         item->Flags |= CHECKED;
  524.  
  525.     item->ItemFill = (APTR)itext;
  526.     item->Flags   |= ITEMTEXT;
  527.     if(ActEd == ITEMED) {
  528.         ItemCount++;
  529.         ItemTotal++;
  530.     } else {
  531.         SubCount++;
  532.         SubTotal++;
  533.     }
  534.     return(item);
  535. itErr:
  536.     enable_window();
  537.     ok();
  538.     Error("Out of memory!");
  539.     if(item) FreeMenuItem(item);
  540.     return(NULL);
  541. nfErr:
  542.     enable_window();
  543.     ok();
  544.     Error("Item won't fit!");
  545.     return(NULL);
  546. }
  547.  
  548. void RemoveItem( struct ListItem *l )
  549. {
  550.     struct MyMenuItem   *item, *pitem;
  551.     struct ListItem     *pred;
  552.     UWORD                count;
  553.     WORD                 width, left;
  554.     UBYTE                message[36];
  555.  
  556.     Saved = FALSE;
  557.  
  558.     if(ActEd == ITEMED)
  559.         item = l->Item;
  560.     else
  561.         item = l->SubItem;
  562.  
  563.     StringFormat((char *)&message,"Delete: %.27s",((struct IntuiText *)item->ItemFill)->IText);
  564.     if(Ask(&message[0],"Are you sure?") == FALSE)
  565.         return;
  566.  
  567.     ClearMenuStrip(MainWindow);
  568.  
  569.     if(ActEd == ITEMED) {
  570.         if(l == ItemsList) {
  571.             for(count = 1; count < 5; count++)
  572.                 TheItem[count].SubItem = l->AItem.NextItem;
  573.            ItemsList = (struct ListItem *)l->AItem.NextItem;
  574.         } else {
  575.             pred = (struct ListItem *)FindPredItem(ItemsList, l);
  576.             pred->AItem.NextItem = l->AItem.NextItem;
  577.         }
  578.     } else {
  579.         if(l == SubsList) {
  580.             for(count = 1; count < 4; count++)
  581.                 SubItem[count].SubItem = l->AItem.NextItem;
  582.             SubsList = (struct ListItem *)l->AItem.NextItem;
  583.         } else {
  584.             pred = (struct ListItem *)FindPredItem(SubsList,l);
  585.             pred->AItem.NextItem = l->AItem.NextItem;
  586.         }
  587.     }
  588.  
  589.     if(ActEd == ITEMED) {
  590.         if(item == ParentMenu->FirstItem) {
  591.             ParentMenu->FirstItem = item->NextItem;
  592.             if(NOT item->NextItem) ParentMenu->FirstItem = (struct MyMenuItem *)&dummy;
  593.         } else {
  594.             pitem = (struct MyMenuItem *)FindPredItem(ParentMenu->FirstItem, item);
  595.             pitem->NextItem = item->NextItem;
  596.         }
  597.     } else {
  598.         if(item == ParentItem->SubItem)
  599.             ParentItem->SubItem = item->NextItem;
  600.         else {
  601.             pitem = (struct MyMenuItem *)FindPredItem(ParentItem->SubItem,item);
  602.             pitem->NextItem = item->NextItem;
  603.         }
  604.     }
  605.     FreeMenuItem(item);
  606.     if(ActEd == ITEMED) {
  607.         ItemCount--;
  608.         ItemTotal--;
  609.     } else {
  610.         SubCount--;
  611.         SubTotal--;
  612.     }
  613. Mistake:
  614.     ReformatM();
  615.     ReformatList(ActEd);
  616.     if(ActEd == ITEMED)
  617.         SetMenuStrip(MainWindow,&ItemMenuStrip[0]);
  618.     else
  619.         SetMenuStrip(MainWindow,&SubMenuStrip[0]);
  620.     SetMainMenus();
  621. }
  622.  
  623. ULONG CheckHotKey( UBYTE key )
  624. {
  625.     register struct MyMenu      *menu;
  626.     register struct MyMenuItem  *it, *sb;
  627.  
  628.     for(menu = MenuStrip; menu; menu = menu->NextMenu) {
  629.         if(menu->FirstItem != &dummy) {
  630.             for(it = menu->FirstItem; it; it = it->NextItem) {
  631.                 if(it->Command == key)
  632.                     return(TRUE);
  633.                 if(it->SubItem) {
  634.                     for(sb = it->SubItem; sb; sb = sb->NextItem) {
  635.                         if(sb->Command == key)
  636.                             return(TRUE);
  637.                     }
  638.                 }
  639.             }
  640.         }
  641.     }
  642.     return(FALSE);
  643. }
  644.  
  645. struct MyMenuItem *EditItem( struct ListItem *l, ULONG ModeIns )
  646. {
  647.     struct MyMenuItem   *TheItem, *Last, *Edit, *TheList;
  648.     struct IntuiText    *itext, *tt;
  649.     BOOL                 running = TRUE;
  650.     ULONG                flags;
  651.     WORD                 left, width;
  652.  
  653.     SetNIL();
  654.  
  655.     if(ActEd == ITEMED) {
  656.         tt = &Render_text;
  657.         TheList = ParentMenu->FirstItem;
  658.     } else {
  659.         tt = &Render_text1;
  660.         TheList = ParentItem->SubItem;
  661.     }
  662.  
  663.     if((NOT l) || ModeIns) {
  664.         LEFT_info.LongInt   = 0;
  665.         if(TheList == &dummy || NOT TheList)
  666.             TOP_info.LongInt = 0;
  667.         else
  668.             TOP_info.LongInt    = ItemHeight(TheList);
  669.         StringFormat((char *)&TOP_buf[0],"%ld",TOP_info.LongInt);
  670.         WIDTH_info.LongInt  = 10;
  671.         HEIGHT_info.LongInt = 9;
  672.         strcpy((char *)&LEFT_buf[0],"0");
  673.         strcpy((char *)&WIDTH_buf[0],"10");
  674.         strcpy((char *)&HEIGHT_buf[0],"9");
  675.     } else if(l && (NOT ModeIns)) {
  676.         if(ActEd == ITEMED)
  677.             Edit = l->Item;
  678.         else
  679.             Edit = l->SubItem;
  680.         itext = (struct IntuiText *)Edit->ItemFill;
  681.         strcpy((char *)&ITEXT_buf[0],itext->IText);
  682.         flags = (ULONG)Edit->Flags;
  683.         HC.Flags = IE.Flags = NULL;
  684.         if(TestBits(flags,HIGHNONE))        HN.Flags = SELECTED;
  685.         else if(TestBits(flags,HIGHCOMP))   HC.Flags = SELECTED;
  686.         else                                HB.Flags = SELECTED;
  687.         if(TestBits(flags,CHECKIT))         CI.Flags = SELECTED;
  688.         if(TestBits(flags,COMMSEQ)) {       CS.Flags = SELECTED;
  689.                                             CK_buf[0] = Edit->Command;
  690.                                             CK_buf[1] = 0;
  691.                                     }
  692.         if(TestBits(flags,MENUTOGGLE))      MT.Flags = SELECTED;
  693.         if(TestBits(flags,ITEMENABLED))     IE.Flags = SELECTED;
  694.         if(TestBits(flags,CHECKED))         CD.Flags = SELECTED;
  695.  
  696.         LEFT_info.LongInt   = Edit->LeftEdge;
  697.         TOP_info.LongInt    = Edit->TopEdge;
  698.         WIDTH_info.LongInt  = Edit->Width;
  699.         HEIGHT_info.LongInt = Edit->Height;
  700.         StringFormat((char *)&LEFT_buf[0],"%ld",Edit->LeftEdge);
  701.         StringFormat((char *)&TOP_buf[0],"%ld",Edit->TopEdge);
  702.         StringFormat((char *)&WIDTH_buf[0],"%ld",Edit->Width);
  703.         StringFormat((char *)&HEIGHT_buf[0],"%ld",Edit->Height);
  704.  
  705.         if(TestBits((ULONG)Edit->SpecialFlags,USERFORMAT)) {
  706.             LEFT.Flags   = GADGHCOMP;
  707.             TOP.Flags    = GADGHCOMP;
  708.             WIDTH.Flags  = GADGHCOMP;
  709.             HEIGHT.Flags = GADGHCOMP;
  710.             FormatNum = 1;
  711.         }
  712.  
  713.         for(DrMdNum = 0; DrMdNum < 4; DrMdNum++)
  714.             if(itext->DrawMode == DrMd[DrMdNum])
  715.                 break;
  716.         }
  717.  
  718.     FORMAT.GadgetText = &FmatText[FormatNum];
  719.     DRMD.GadgetText   = &DrMdText[DrMdNum];
  720.  
  721.     nw_item.Screen = MainScreen;
  722.  
  723.     if(NOT(IedWindow = (struct Window *)OpenWindow(&nw_item)))
  724.         return(NULL);
  725.  
  726.     disable_window();
  727.     buisy();
  728.     draw(IedWindow,&HC,&Border_bord[0],tt);
  729.     ActivateGadget(&ITEXT,IedWindow,NULL);
  730.  
  731.     do {
  732.         WaitPort(IedWindow->UserPort);
  733.         while(read_msg(IedWindow)) {
  734.             switch(Class) {
  735.                 case GADGETUP:
  736.                     switch(Gadget->GadgetID) {
  737.                         case    OKIDOKI_ID:
  738.                             if(NOT ITEXT_buf[0]) {
  739.                                 DisplayBeep(MainScreen);
  740.                                 break;
  741.                             }
  742.                         case    CANCEL_ID:
  743.                             running = FALSE;
  744.                             break;
  745.                         case    FORMAT_ID:
  746.                             if(FormatNum) {
  747.                                 OffGList(IedWindow,&LEFT,NULL,4);
  748.                                 FORMAT.GadgetText = &FmatText[0];
  749.                                 FormatNum = 0;
  750.                             } else {
  751.                                 OnGList(IedWindow,&LEFT,NULL,4);
  752.                                 FORMAT.GadgetText = &FmatText[1];
  753.                                 FormatNum = 1;
  754.                             }
  755.                             SetAPen(IedWindow->RPort,1);
  756.                             RectFill(IedWindow->RPort,8,89,132,98);
  757.                             RefreshGList(&FORMAT,IedWindow,NULL,1);
  758.                             break;
  759.                         case    DRMD_ID:
  760.                             if(DrMdNum == 3)
  761.                                 DrMdNum = 0;
  762.                             else
  763.                                 DrMdNum++;
  764.                             DRMD.GadgetText = &DrMdText[DrMdNum];
  765.                             SetAPen(IedWindow->RPort,1);
  766.                             RectFill(IedWindow->RPort,139,89,263,98);
  767.                             RefreshGList(&DRMD,IedWindow,NULL,1);
  768.                             break;
  769.                         case    CK_ID:
  770.                             if(NOT CK_buf[0])
  771.                                 DeSelectGadget(IedWindow,&CS,NULL);
  772.                             else {
  773.                                 if(NOT CheckHotKey(CK_buf[0]))
  774.                                     SelectGadget(IedWindow,&CS,NULL);
  775.                                 else {
  776.                                     DeSelectGadget(IedWindow,&CS,NULL);
  777.                                     CK_buf[0] = 0;
  778.                                     enable_window();
  779.                                     Error("Hotkey already used !");
  780.                                     disable_window();
  781.                                     RefreshGList(&CK,IedWindow,NULL,1);
  782.                                 }
  783.                             }
  784.                             break;
  785.                         case    LEFT_ID:
  786.                         case    TOP_ID:
  787.                         case    WIDTH_ID:
  788.                         case    HEIGHT_ID:
  789.                             CheckNumbers(ParentMenu->LeftEdge+LEFT_info.LongInt,MainScreen->BarHeight+TOP_info.LongInt,WIDTH_info.LongInt,HEIGHT_info.LongInt);
  790.                             break;
  791.                     }
  792.                 case GADGETDOWN:
  793.                     switch(Gadget->GadgetID) {
  794.                         case    HC_ID:
  795.                         case    HB_ID:
  796.                         case    HN_ID:
  797.                             MutualExclude(IedWindow,Gadget,&HC,NULL);
  798.                             SelectGadget(IedWindow,Gadget,NULL);
  799.                             break;
  800.                         case    CS_ID:
  801.                             if(SelectTest(&CS))
  802.                                 ActivateGadget(&CK,IedWindow,NULL);
  803.                             else {
  804.                                 CK_buf[0] = 0;
  805.                                 RefreshGList(&CK,IedWindow,NULL,1);
  806.                             }
  807.                             break;
  808.                     }
  809.             }
  810.         }
  811.     } while(running == TRUE);
  812.     CloseWindow(IedWindow);
  813.  
  814.     if(Gadget->GadgetID == OKIDOKI_ID && ModeIns && l) {
  815.         Saved = FALSE;
  816.         if(ActEd == ITEMED)
  817.             Edit = l->Item;
  818.         else
  819.             Edit = l->SubItem;
  820.         if((TheItem = MakeItem())) {
  821.             if(l->Item == TheList || l->SubItem == TheList) {
  822.                 TheItem->NextItem = TheList;
  823.                 if(ActEd == ITEMED)
  824.                     ParentMenu->FirstItem = TheItem;
  825.                 else
  826.                     ParentItem->SubItem = TheItem;
  827.                 TheList = TheItem;
  828.             } else {
  829.                 Last = (struct MyMenuItem *)FindPredItem(TheList,Edit);
  830.                 Last->NextItem = TheItem;
  831.                 TheItem->NextItem = Edit;
  832.             }
  833.             TheItem->ItsListItem = (struct ListItem *)CreateListItem((APTR)TheItem,ActEd,TRUE,l,TRUE);
  834.             ReformatM();
  835.             ReformatList(ActEd);
  836.             enable_window();
  837.             ok();
  838.             return(NULL);
  839.         } else
  840.             return(NULL);
  841.     } else if(Gadget->GadgetID == OKIDOKI_ID && (NOT l)) {
  842.         Saved = FALSE;
  843.         if((TheItem = MakeItem())) {
  844.             if(TheList == &dummy || NOT TheList) {
  845.                 if(ActEd == ITEMED)
  846.                     ParentMenu->FirstItem = TheItem;
  847.                 else
  848.                     ParentItem->SubItem = TheItem;
  849.             } else {
  850.                 Last = (struct MyMenuItem *)LastItem(TheList);
  851.                 Last->NextItem = TheItem;
  852.             }
  853.             TheItem->ItsListItem = (struct ListItem *)CreateListItem((APTR)TheItem, ActEd, FALSE, NULL,TRUE);
  854.             ReformatM();
  855.             enable_window();
  856.             ok();
  857.             return(NULL);
  858.         } else
  859.             return(NULL);
  860.     } else if(Gadget->GadgetID == OKIDOKI_ID && l && (NOT ModeIns)) {
  861.         Saved = FALSE;
  862.         if(NOT FormatNum) {
  863.             Edit->Width = TEXT_WIDTH(MainRP,(char *)&ITEXT_buf[0]) + TEXTSPACING;
  864.             Edit->SpecialFlags = NULL;
  865.         } else {
  866.             Edit->LeftEdge = LEFT_info.LongInt;
  867.             Edit->TopEdge  = TOP_info.LongInt;
  868.             Edit->Width    = WIDTH_info.LongInt;
  869.             Edit->Height   = HEIGHT_info.LongInt;
  870.             Edit->SpecialFlags = USERFORMAT;
  871.         }
  872.  
  873.         if(SelectTest(&HC))             Edit->Flags = HIGHCOMP;
  874.         else if(SelectTest(&HB))        Edit->Flags = HIGHBOX;
  875.         else                            Edit->Flags = HIGHNONE;
  876.         if(SelectTest(&CI)) {           Edit->Flags |= CHECKIT;
  877.                                         if(NOT FormatNum)
  878.                                             Edit->Width += 20;
  879.                                         itext->LeftEdge = 18;
  880.                             }
  881.         if(SelectTest(&CS)) {           Edit->Flags |= COMMSEQ;
  882.                                         Edit->Command = CK_buf[0];
  883.                                         if(NOT FormatNum)
  884.                                             Edit->Width += 40;
  885.                             }
  886.         if(SelectTest(&MT))             Edit->Flags |= MENUTOGGLE;
  887.         if(SelectTest(&IE))             Edit->Flags |= ITEMENABLED;
  888.         if(SelectTest(&CD))             Edit->Flags |= CHECKED;
  889.         Edit->Flags |= ITEMTEXT;
  890.  
  891.         itext->DrawMode = DrMd[DrMdNum];
  892.         itext->FrontPen = FrontPen;
  893.         itext->BackPen  = BackPen;
  894.  
  895.         strcpy((char *)itext->IText,(char *)&ITEXT_buf[0]);
  896.         strncpy((char *)&l->Letters[0],(char *)itext->IText,9);
  897.  
  898.         ReformatM();
  899.         enable_window();
  900.         ok();
  901.         return(NULL);
  902.     }
  903.     enable_window();
  904.     ok();
  905.     return(NULL);
  906. }
  907.