home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / rramdisk_451.lzh / 'Liner / Source / menu.c < prev    next >
C/C++ Source or Header  |  1991-02-06  |  8KB  |  354 lines

  1. #include "Globals.h"
  2.  
  3. #define FP 1  /*Pen for filenames in YAFR (white)*/
  4. #define DP 3  /* "   "  dirnames   "   "  (orange)*/
  5.  
  6. extern ColorReq();
  7.  
  8. /*I think most of these are self explanatory (HandleNew() handles the New*/
  9. /*item in the Project menu, etc.)*/
  10. void HandleNew()
  11. {
  12.    if(Modified && !AreYouSure(Window))
  13.       return;
  14.  
  15.    NewAll();
  16. }
  17.  
  18. void MakeFilename(File,Dir,Complete)
  19. char *File,*Dir,*Complete;
  20. {
  21.    strcpy(Complete,Dir);
  22.    if(Complete[strlen(Complete)-1]!=':' && Complete[0] != NULL)
  23.       strcat(Complete,"/");
  24.    strcat(Complete,File);
  25. }
  26.  
  27. HandleOpen()
  28. {
  29.    UBYTE *stat;
  30.  
  31.     MainReq->rf_Hail=OpenHail;
  32.    stat=RequestFile(MainReq);
  33.  
  34.    if(*stat!=FALSE)
  35.    {
  36.       MakeFilename(SFileName,SDirName,FileName);
  37.       if(Modified)
  38.      if(!AreYouSure(Window))
  39.         return(FALSE);
  40.  
  41.       if(ReadItemList(FileName,FALSE))
  42.       {
  43.      Modified=FALSE;
  44.      TitleErrorCancel(); /*Write current filename in title bar*/
  45.       }           /*if there was no error*/
  46.    }
  47. }
  48.  
  49. void Save(arexx)
  50. BYTE arexx;
  51. {
  52.    if(FileName[0]==NULL)
  53.       HandleSaveAs();
  54.    else
  55.       {
  56.       WriteItemList(FileName,arexx);
  57.       Modified=FALSE;
  58.       TitleErrorCancel();
  59.       }
  60. }
  61.  
  62. void HandleSaveAs()  /*Save As...  never called from ARexx*/
  63. {
  64.    UBYTE *stat;
  65.  
  66.    MainReq->rf_Hail=SaveHail;
  67.  
  68.    stat=RequestFile(MainReq);
  69.  
  70.    if(*stat != FALSE)
  71.    {
  72.       MakeFilename(SFileName,SDirName,FileName);
  73.       if(WriteItemList(FileName,FALSE))
  74.       {
  75.      Modified=FALSE;
  76.      TitleErrorCancel();     /*Update filename in title bar*/
  77.       }              /*if there was no error*/
  78.    }
  79. }
  80.  
  81. HandlePrintDisk(arexxstat,filename)
  82. BYTE arexxstat;   /*Called from arexx or not?*/
  83. char *filename;   /*Filename if called from ARexx*/
  84. {
  85.    UBYTE *stat;
  86.  
  87.    BPTR fp;
  88.    char chip buffer[90];
  89.    struct LineItem *Item;
  90.  
  91.    PTDReq->rf_Hail=PrintHail;
  92.  
  93.    if(arexxstat)
  94.       strcpy(PDName,filename);
  95.    else
  96.    {
  97.       stat=RequestFile(PTDReq);
  98.       if(*stat==FALSE)
  99.      return(FALSE);
  100.       MakeFilename(PFileName,PDirName,PDName);
  101.    }
  102.  
  103.    if((fp=(BPTR)Open(PDName,MODE_NEWFILE))==NULL)
  104.    {
  105.       if(!arexxstat)
  106.      TitleError("Can't open file!");
  107.       return(FALSE);
  108.    }
  109.  
  110.    Item=(struct LineItem *)FirstItem;
  111.    while(Item != NULL)
  112.    {
  113.       MakeTextLine(buffer,Item);
  114.       Write(fp,buffer,strlen(buffer));
  115.       Item=(struct LineItem *)Item->NextItem;
  116.    }
  117.  
  118.    Close(fp);
  119.    return(TRUE);
  120. }
  121.  
  122. HandlePrintPrinter() /*Send an outline to the printer*/
  123. {
  124.    BPTR fp;
  125.    char chip RetBuf[8];
  126.    char Printed=0;
  127.    char chip buffer[90];
  128.    struct LineItem *Item;
  129.    struct Preferences preferences;
  130.    UWORD maxlines;
  131.  
  132.    if((fp=(BPTR)Open("prt:",MODE_OLDFILE))==NULL)
  133.       {
  134.       TitleError("Can't open printer!");
  135.       return(FALSE);
  136.       }
  137.  
  138.    GetPrefs(&preferences,sizeof(struct Preferences));
  139.    maxlines=preferences.PaperLength-1; /*Get maximum page size*/
  140.  
  141.    RetBuf[0]=0x0d;
  142.    RetBuf[1]=0x0a;
  143.  
  144.    if(prefs.DS)
  145.       {
  146.       RetBuf[2]=0x0d;
  147.       RetBuf[3]=0x0a;
  148.       RetBuf[4]=0;
  149.       }
  150.    else
  151.       RetBuf[2]=0;
  152.  
  153.    Item=(struct LineItem *)FirstItem;
  154.    while(Item != NULL)
  155.       {
  156.       for(Printed=2;Printed < maxlines && Item != NULL;
  157.         Printed+=(prefs.DS) ? 2 : 1)
  158.      {
  159.      strcpy(buffer,"");
  160.      GetOutlineChars(Item,buffer);
  161.      strcat(buffer,"  ");
  162.      strcat(buffer,Item->Text);
  163.      Write(fp,&buffer[Indent],strlen(&buffer[Indent]));
  164.      strcpy(buffer,RetBuf);
  165.      Write(fp,buffer,strlen(buffer));
  166.      Item=(struct LineItem *)Item->NextItem;
  167.      }
  168.       buffer[0]=NEWPAGE;
  169.       Write(fp,buffer,1);
  170.       }
  171.    Close(fp);
  172.    return(TRUE);
  173. }
  174.  
  175. void HandleQuit()
  176. {
  177.    if(Modified) /*Ask "Are you sure?" only if outline isn't saved*/
  178.    {
  179.       if(AreYouSure(Window))
  180.       CloseStuff();
  181.    }
  182.    else
  183.       CloseStuff();
  184. }
  185.  
  186. HandleCut()
  187. {
  188.    if(NOINV==InvsMode)
  189.       return(FALSE);
  190.    if(HandleCopy())   /*Copy to buffer.  If it was successful,*/
  191.       HandleErase();    /*erase the block copied from*/
  192.    else
  193.       return(FALSE);
  194.    CheckModified();
  195. }
  196.  
  197. HandleCopy()
  198. {
  199.    struct WhichOne which;
  200.  
  201.    if(ClipMode < NOINV)
  202.       FreeListMem(ClipStart,ClipEnd);
  203.    if(InvsMode > NOINV)
  204.       if(StartChar < EndChar)
  205.      WriteInvsTextToClip(StartChar,EndChar-StartChar+1,CurrentItem->Text);
  206.       else
  207.      WriteInvsTextToClip(EndChar,StartChar-EndChar+1,CurrentItem->Text);
  208.    else
  209.    {           /*Find the true start/end*/
  210.       FindStartEnd(StartIItem,EndIItem,&which);
  211.  
  212.      /*If cutting out a bunch of continuations, get the parent and all*/
  213.      /*the child continuations as well*/
  214.       which.Start=(struct LineItem *)FindPrevNonCont(which.Start);
  215.       if((which.End = (struct LineItem *)FindNextNonCont(which.End))==NULL)
  216.      which.End=(struct LineItem *)LastItem;
  217.  
  218.       if(which.End->NextItem != NULL && !which.End->cont &&
  219.         which.End->NextItem->cont)
  220.      return(FALSE);
  221.       if(!SnagBlock(which.Start,which.End))
  222.      return(FALSE);
  223.    }
  224.    ClipMode=InvsMode;
  225.    return(TRUE);
  226. }
  227.  
  228. void HandlePaste()
  229. {
  230.    int TempX,TempY;
  231.    char text[160];
  232.  
  233.    CancelInvs();
  234.    CheckModified();
  235.    if(ClipMode < NOINV)
  236.    {
  237.       if((!CurrentItem->NextItem->cont) || (CurrentItem->NextItem == NULL))
  238.      AddBlock(CurrentItem);
  239.    }
  240.    else
  241.    {
  242.       strcpy(text,CurrentItem->Text);
  243.       ReadItemString(PosInText(CurrentItem->Level),
  244.      79-PosInText(CurrentItem->Level),text);
  245.  
  246.       TempX=CurX;
  247.       PlotCursor(1,(TempY=CurY));
  248.  
  249.      /*Break line apart if paste overruns the line*/
  250.       if(BreakLineApart(CurrentItem,CurrentItem->NextItem,
  251.         text)==CurrentItem)
  252.      PrintItem(CurrentItem);
  253.       else
  254.      PrintItemList(CurrentItem,CurY);
  255.       PlotCursor(TempX > MaxX(CurrentItem)?MaxX(CurrentItem):TempX,TempY);
  256.    }
  257. }
  258.  
  259. HandleErase()
  260. {
  261.    BYTE status=TRUE;
  262.  
  263.    if(InvsMode==NOINV)
  264.       return(FALSE);
  265.  
  266.    if(InvsMode > NOINV)
  267.       DelTextBlock();
  268.    else
  269.       status=HandleDelBlock();
  270.    if(status)
  271.    {
  272.       InvsMode=NOINV;
  273.       CheckModified();
  274.    }
  275. }
  276.  
  277. void Refresh() /*Refresh the entire screen*/
  278. {
  279.    UBYTE OldX,OldY;
  280.    OldX=CurX;
  281.    OldY=CurY;
  282.  
  283.    PrintItemList(FirstScrnItem,1);
  284.    if(OldX < MinX(CurrentItem))
  285.       OldX=MinX(CurrentItem);
  286.    else
  287.       if(OldX > MaxX(CurrentItem))
  288.      OldX=MaxX(CurrentItem);
  289.  
  290.    PlotCursor(OldX,OldY);
  291. }
  292.  
  293. void CheckModified() /*Put an '*' in the title bar if it isn't there*/
  294. {
  295.    if(Modified==FALSE)
  296.       {
  297.       Modified=TRUE;
  298.       TitleErrorCancel();
  299.       }
  300. }
  301.  
  302. void MakeTextLine(Buffer,Item)  /*Convert a LineItem into a text string*/
  303. char *Buffer;
  304. struct LineItem *Item;
  305. {
  306.    UBYTE buflen;
  307.    strcpy(Buffer,"");
  308.    GetOutlineChars(Item,Buffer); /*Get the number*/
  309.    strcat(Buffer,"  ");
  310.    strcat(Buffer,Item->Text); /*Append the text*/
  311.    buflen=strlen(Buffer);
  312.    Buffer[buflen]=0x0a;
  313.    if(prefs.DS)
  314.    {
  315.       Buffer[buflen+1]=0x0a;
  316.       Buffer[buflen+2]=NULL;
  317.    }
  318.    else
  319.       Buffer[buflen+1]=NULL;
  320. }
  321.  
  322. void HandlePalette() /*Change the color palette*/
  323. {
  324.    ColorReq(Screen,prefs.ScreenType,VisInfo);
  325.    SaveColors(&(Screen->ViewPort));
  326. }
  327.  
  328. void HandleReloadPrefs()
  329. {
  330.    UBYTE X,Y;
  331.    X=CurX;
  332.    Y=CurY;
  333.  
  334.    GetLinerPrefs("liner:liner.prefs");   /*Get the preferences from disk*/
  335.    CloseGraphics();
  336.    MakeMenus();
  337.    InterpretPrefs();          /*Install them*/
  338.  
  339.    PrintItemList(FirstScrnItem,1); /*Restore the current outline*/
  340.    if(Y > DispRows)  /*if the old laced Y is > the current possible rows*/
  341.       {
  342.       Y=DispRows;    /*Y now = the last screen item*/
  343.       CurrentItem=(struct LineItem *)ScrnBtm;
  344.       }
  345.    if(X > MaxX(CurrentItem))  /*Out of bounds*/
  346.       X=MaxX(CurrentItem);
  347.    else if(X < MinX(CurrentItem))
  348.       X=MinX(CurrentItem);
  349.  
  350.    PlotCursor(X,Y);     /*Restore cursor position*/
  351. }
  352.  
  353. /*~~~End of menu.c*/
  354.