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