home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff285.lzh / 'Liner / Source / menu.h < prev    next >
C/C++ Source or Header  |  1989-11-28  |  9KB  |  403 lines

  1. #define ABOUT_Y_REG 42
  2. #define ABOUT_Y_LACED 142
  3. #define FP 1  /*Pen for filenames in YAFR (white)*/
  4. #define DP 3  /* "   "  dirnames   "   "  (orange)*/
  5.  
  6. NewAll() /*Get rid of all the Items*/
  7. {
  8.    char Buffer[10];
  9.  
  10.    FreeListMem(FirstItem,LastItem);
  11.  
  12.    DoubleSpc=0;
  13.    MenuItem1.Flags=CHECKIT+ITEMTEXT+COMMSEQ+MENUTOGGLE+ITEMENABLED+HIGHCOMP;
  14.    SubItems[StartingLevel]->Flags-=CHECKED; /*Restore StartingLevel to 0*/
  15.    StartingLevel=0;
  16.    SubItems[0]->Flags+=CHECKED;
  17.  
  18.    FirstItem=LastItem=FirstScrnItem=ScrnBtm=CurrentItem=
  19.          (struct LineItem *)AllocMem(sizeof(struct LineItem),MEMF_CLEAR);
  20.    CurrentItem->Level=1;
  21.    Buffer[0]=0x0c;
  22.    WriteConsole(Buffer,1);
  23.    PrintItemList(CurrentItem,1);
  24.    PlotCursor(MinX(CurrentItem),CurY);
  25.    Modified=FALSE;
  26.    TitleErrorCancel();
  27.    MenuItem1.Flags=CHECKIT+ITEMTEXT+COMMSEQ+MENUTOGGLE+ITEMENABLED+HIGHCOMP;
  28.    return(TRUE);
  29. }
  30.  
  31. /*I think most of these are self explanatory (HandleNew() handles the New*/
  32. /*item in the Project menu, etc.)*/
  33. HandleNew()
  34. {
  35.    if(AreYouSure(Window))
  36.       {
  37.       NewAll();
  38.       FileName[0]=NULL;     /*Remove default filenames*/
  39.       SFileName[0]=NULL;
  40.       PDName[0]=NULL;
  41.       PFileName[0]=NULL;
  42.       TitleErrorCancel();
  43.       }
  44. }
  45.  
  46. HandleOpen()
  47. {
  48.    if(GetFilename(SFileName,SDirName,SExt,FileName,24,9,
  49.          "Enter filename for open",Screen,FP,DP,TRUE))
  50.       {
  51.       if(Modified)
  52.          if(!AreYouSure(Window))
  53.             return(FALSE);
  54.  
  55.       if(ReadItemList(FileName))
  56.             {
  57.             Modified=FALSE;
  58.             TitleErrorCancel(); /*Write current filename in Title bar*/
  59.             }                   /*if there was no error*/
  60.       }
  61. }
  62.  
  63. Save()
  64. {
  65.    if(FileName[0]==NULL)
  66.       HandleSaveAs();
  67.    else
  68.       {
  69.       WriteItemList(FileName);
  70.       Modified=FALSE;
  71.       TitleErrorCancel();
  72.       }
  73. }
  74.  
  75. HandleSaveAs()
  76. {
  77.    if(GetFilename(SFileName,SDirName,SExt,FileName,24,9,
  78.          "Enter filename for save",Screen,FP,DP,TRUE))
  79.       {
  80.       if(WriteItemList(FileName))
  81.          {
  82.          Modified=FALSE;
  83.          TitleErrorCancel();     /*Update filename in title bar*/
  84.          }                       /*if there was no error*/
  85.       }
  86. }
  87.  
  88. HandlePrintDisk()
  89. {
  90.    struct FileHandle *fp;
  91.    char *buffer;
  92.    struct LineItem *Item;
  93.  
  94.    if(!GetFilename(PFileName,PDirName,PExt,PDName,24,9,
  95.          "Enter filename for print",Screen,FP,DP,TRUE))
  96.       return(FALSE);
  97.  
  98.    if((fp=(struct FileHandle *)Open(PDName,MODE_NEWFILE))==NULL)
  99.       {
  100.       TitleError("Can't open file!");
  101.       return(FALSE);
  102.       }
  103.  
  104.    buffer=(char *)AllocMem(90,MEMF_CHIP|MEMF_CLEAR);
  105.  
  106.    Item=(struct LineItem *)FirstItem;
  107.    while(Item != NULL)
  108.       {
  109.       strcpy(buffer,"");
  110.       GetOutlineChars(Item,buffer);
  111.       strcat(buffer,"  ");
  112.       strcat(buffer,Item->Text);
  113.       Write(fp,&buffer[Indent],strlen(&buffer[Indent]));
  114.       buffer[0]=0x0a;
  115.       Write(fp,buffer,1);
  116.       if(DoubleSpc)
  117.          Write(fp,buffer,1); /*If double spaced, print another RETURN*/
  118.       Item=(struct LineItem *)Item->NextItem;
  119.       }
  120.    FreeMem(buffer,90);
  121.    Close(fp);
  122.    return(TRUE);
  123. }
  124.  
  125. HandlePrintPrinter()
  126. {
  127.    struct FileHandle *fp;
  128.    char *buffer,RetBuf[5],Printed=0;
  129.    struct LineItem *Item;
  130.  
  131.    if((fp=(struct FileHandle *)Open("prt:",MODE_OLDFILE))==NULL)
  132.       {
  133.       TitleError("Can't open printer!");
  134.       return(FALSE);
  135.       }
  136.    buffer=(char *)AllocMem(90,MEMF_CHIP|MEMF_CLEAR);
  137.    RetBuf[0]=0x0d;
  138.    RetBuf[1]=0x0a;
  139.    if(DoubleSpc)
  140.       {
  141.       RetBuf[2]=0x0d;
  142.       RetBuf[3]=0x0a;
  143.       RetBuf[4]=0;
  144.       }
  145.    else
  146.       RetBuf[2]=0;
  147.  
  148.    Item=(struct LineItem *)FirstItem;
  149.    while(Item != NULL)
  150.       {
  151.       for(Printed=0;Printed < 60 && Item != NULL;Printed+=(1+DoubleSpc))
  152.          {
  153.          strcpy(buffer,"");
  154.          GetOutlineChars(Item,buffer);
  155.          strcat(buffer,"  ");
  156.          strcat(buffer,Item->Text);
  157.          Write(fp,&buffer[Indent],strlen(&buffer[Indent]));
  158.          strcpy(buffer,RetBuf);
  159.          Write(fp,buffer,strlen(buffer));
  160.          Item=(struct LineItem *)Item->NextItem;
  161.          }
  162.       buffer[0]=NEWPAGE;
  163.       Write(fp,buffer,1);
  164.       }
  165.    FreeMem(buffer,90);
  166.    Close(fp);
  167.    return(TRUE);
  168. }
  169.  
  170. HandleAbout()
  171. {
  172.    int ctr;
  173.    struct Window *AboutWdw;
  174.  
  175.    /*Get chip memory for the gadget image.*/
  176.    if((ImageData1Chip=(USHORT *)AllocMem(420,MEMF_CHIP|MEMF_CLEAR))==NULL)
  177.       return(FALSE);
  178.  
  179.    for(ctr=0;ctr<210;ctr++)    /*Transfer image info into chip memory*/
  180.       {
  181.       ImageData1Chip[ctr]=ImageData1[ctr];
  182.       }
  183.  
  184.    /*Do the same for the reversed image*/
  185.    if((ImageData2Chip=(USHORT *)AllocMem(840,MEMF_CHIP|MEMF_CLEAR))==NULL)
  186.       return(FALSE);
  187.  
  188.    for(ctr=0;ctr<420;ctr++)    /*Transfer image info into chip memory*/
  189.       {
  190.       ImageData2Chip[ctr]=ImageData2[ctr];
  191.       }
  192.  
  193.    NewAboutWindow.Screen=Screen;    /*Pointer to window's screen*/
  194.    Image1.ImageData=(USHORT *)ImageData1Chip;
  195.    Image2.ImageData=(USHORT *)ImageData2Chip;
  196.  
  197.    if(Laced)
  198.       NewAboutWindow.TopEdge=ABOUT_Y_LACED;
  199.    else
  200.       NewAboutWindow.TopEdge=ABOUT_Y_REG;
  201.  
  202.    if((AboutWdw=(struct Window *)OpenWindow(&NewAboutWindow))==NULL)
  203.       {                    /*Open the window*/
  204.       FreeMem(ImageData1Chip,420);
  205.       FreeMem(ImageData2Chip,840);
  206.       return(FALSE);
  207.       }
  208.  
  209.    SetWindowTitles(AboutWdw,-1,"For your information...");
  210.    SetAPen(AboutWdw->RPort,1);
  211.    PrintIText(AboutWdw->RPort,&IntuiTextList2,0,0);
  212.  
  213.          /*Wait for the user to press the Continue... gadget*/
  214.    Wait(1<<AboutWdw->UserPort->mp_SigBit);
  215.  
  216.    CloseWindow(AboutWdw);     /*Close the window*/
  217.    FreeMem(ImageData1Chip,420);
  218.    FreeMem(ImageData2Chip,840);
  219. }
  220.  
  221. HandleQuit()
  222. {
  223.    if(Modified) /*Ask "Are you sure?" only if outline isn't saved*/
  224.       {
  225.       if(AreYouSure(Window))
  226.          CloseStuff();
  227.       }
  228.    else
  229.       CloseStuff();
  230. }
  231.  
  232. HandleCut()
  233. {
  234.    if(NOINV==InvsMode)
  235.       return(FALSE);
  236.    CheckModified();
  237.    HandleCopy();
  238.    HandleErase();
  239. }
  240.  
  241. HandleCopy()
  242. {
  243.    if(ClipMode < NOINV)
  244.       FreeListMem(ClipStart,ClipEnd);
  245.    ClipMode=InvsMode;
  246.    if(InvsMode > NOINV)
  247.       if(StartChar < EndChar)
  248.          WriteInvsTextToClip(StartChar,EndChar-StartChar+1,CurrentItem->Text);
  249.       else
  250.          WriteInvsTextToClip(EndChar,StartChar-EndChar+1,CurrentItem->Text);
  251.    else
  252.       if(InvsMode == BLOCK_DOWN)
  253.          SnagBlock(StartIItem,EndIItem);
  254.       else
  255.          SnagBlock(EndIItem,StartIItem);
  256. }
  257.  
  258. HandlePaste()
  259. {
  260.    int TempX;
  261.  
  262.    CheckModified();
  263.    if(ClipMode < NOINV)
  264.       AddBlock(CurrentItem);
  265.    else
  266.       {
  267.          ReadItemString(PosInText(CurrentItem->Level),
  268.             79-PosInText(CurrentItem->Level),CurrentItem->Text);
  269.          CurrentItem->Text[MaxLen(CurrentItem->Level)]=NULL;
  270.          TempX=CurX;
  271.          PlotCursor(1,CurY);
  272.          PrintItem(CurrentItem);
  273.          PlotCursor(TempX,CurY);
  274.       }
  275. }
  276.  
  277. HandleErase()
  278. {
  279.    if(InvsMode==NOINV)
  280.       return(FALSE);
  281.  
  282.    CheckModified();
  283.    if(InvsMode > NOINV)
  284.       DelTextBlock();
  285.    else
  286.       HandleDelBlock();
  287.    InvsMode=NOINV;
  288.  
  289. }
  290.  
  291. DoubleSpacing()
  292. {
  293.    CheckModified();
  294.    DoubleSpc=DoubleSpc ^ 1;   /*XOR DoubleSpc w/1 to toggle between*/
  295. }                             /*true and false*/
  296.  
  297. HandleInterlaced()   /*Toggle between normal and interlaced screen*/
  298. {
  299.    UBYTE X,Y;
  300.    X=CurX;
  301.    Y=CurY;  /*Store cursor position*/
  302.    CloseGraphics();
  303.    if(Laced)   /*If interlaced*/
  304.       {
  305.       NewScreen.Height=200;
  306.       NewWindow.Height-=200;
  307.       NewScreen.ViewModes=HIRES; /*Remove LACE from screen description*/
  308.       SCRNHEIGHT-=25;      /*Rows*/
  309.       Laced=FALSE;         /*Status switch*/
  310.       }
  311.    else  /*not interlaced*/
  312.       {
  313.       NewScreen.Height=400;
  314.       NewWindow.Height+=200;
  315.       NewScreen.ViewModes=HIRES+LACE; /*Add LACE to screen description*/
  316.       SCRNHEIGHT+=25;      /*Rows*/
  317.       Laced=TRUE;
  318.       }
  319.  
  320.    OpenGraphics();
  321.    PrintItemList(FirstScrnItem,1);
  322.    if(Y > DispRows)  /*if the old laced Y is > the current possible rows*/
  323.       {
  324.       Y=DispRows;    /*Y now = the last screen item*/
  325.       CurrentItem=(struct LineItem *)ScrnBtm;
  326.       }
  327.    if(X > MaxX(CurrentItem))  /*Out of bounds*/
  328.       X=MaxX(CurrentItem);
  329.    else if(X < MinX(CurrentItem))
  330.       X=MinX(CurrentItem);
  331.  
  332.    PlotCursor(X,Y);     /*Restore cursor position*/
  333. }
  334.  
  335. HandleFirst()  /*Handle 'Starting Level' menu item*/
  336. {
  337.    CheckModified();
  338.    StartingLevel=0;
  339.    Refresh();
  340. }
  341.  
  342. HandleSecond()
  343. {
  344.    CheckModified();
  345.    StartingLevel=1;
  346.    Refresh();
  347. }
  348.  
  349. HandleThird()
  350. {
  351.    CheckModified();
  352.    StartingLevel=2;
  353.    Refresh();
  354. }
  355.  
  356. HandleFourth()
  357. {
  358.    CheckModified();
  359.    StartingLevel=3;
  360.    Refresh();
  361. }
  362.  
  363. HandleFifth()
  364. {
  365.    CheckModified();
  366.    StartingLevel=4;
  367.    Refresh();
  368. }
  369.  
  370. HandleSixth()
  371. {
  372.    CheckModified();
  373.    StartingLevel=5;
  374.    Refresh();
  375. }
  376.  
  377. Refresh()
  378. {
  379.    UBYTE OldX,OldY;
  380.    OldX=CurX;
  381.    OldY=CurY;
  382.  
  383.    PrintItemList(FirstScrnItem,1);
  384.    if(OldX < MinX(CurrentItem))
  385.       OldX=MinX(CurrentItem);
  386.    else
  387.       if(OldX > MaxX(CurrentItem))
  388.          OldX=MaxX(CurrentItem);
  389.  
  390.    PlotCursor(OldX,OldY);
  391. }
  392.  
  393. CheckModified()
  394. {
  395.    if(Modified==FALSE)
  396.       {
  397.       Modified=TRUE;
  398.       TitleErrorCancel();
  399.       }
  400. }
  401.  
  402.  
  403.