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 / mouse.h < prev    next >
C/C++ Source or Header  |  1989-11-28  |  13KB  |  594 lines

  1. char InvBuf[]=
  2.    {CSI,'7',0x6d,NULL,CSI,'0',0x6d};
  3. char Inv[]=
  4.    {CSI,'7',0x6d,NULL};
  5. char Norm[]=
  6.    {CSI,'0',0x6d,NULL};
  7.  
  8. struct LineItem *InvItem;
  9.  
  10. MovedMouse(x,y)   /*The mouse was moved! Record its new position*/
  11. int x,y;
  12. {
  13.    LastX=PtrX;
  14.    LastY=PtrY;
  15.    PtrX=(x/8)+1;
  16.    PtrY=(y/8)+1;
  17. }
  18.  
  19. HandleButton(Seconds,Micros)  /*Handle a button press*/
  20. int Seconds,Micros;
  21. {
  22.    int status;
  23.    static int LastSeconds=1,LastMicros=1,DoubClicked=FALSE;
  24.    static UBYTE ButtonX,ButtonY;
  25.  
  26.    /*If the user double-clicked (the mouse button), start or modify*/
  27.    /*a highlighted block*/
  28.    if(DoubleClick(LastSeconds,LastMicros,Seconds,Micros) &&
  29.          PtrY==LastY && !DoubClicked)
  30.       {
  31.       PtrX=ButtonX;
  32.       PtrY=ButtonY;
  33.       DoubClicked=TRUE;
  34.       HandleInvs();
  35.       BLastX=PtrX;
  36.       BLastY=PtrY;
  37.       }
  38.    else  /*Otherwise, just move the cursor accordingly*/
  39.       if(PtrY > 0 && PtrY <= SCRNHEIGHT)
  40.          {
  41.          ButtonX=PtrX;
  42.          ButtonY=PtrY;
  43.          DoubClicked=FALSE;
  44.          if(PtrY != InvY && InvsMode > NOINV)
  45.             EndLineInvs();
  46.          if(PtrY-CurY < 0)
  47.             status=MoveBack(-(PtrY-CurY));
  48.          else
  49.             status=MoveForward(PtrY-CurY);
  50.          if(status==FALSE)
  51.             return(FALSE);
  52.  
  53.          if(PtrX > MaxX(CurrentItem))
  54.             CurX=MaxX(CurrentItem);
  55.          else
  56.             if(PtrX < MinX(CurrentItem))
  57.                CurX=MinX(CurrentItem);
  58.             else
  59.                CurX=PtrX;
  60.          PlotCursor(CurX,PtrY);
  61.          }
  62.    LastSeconds=Seconds;
  63.    LastMicros=Micros;
  64. }
  65.  
  66. HandleInvs() /*Handle a modification or creation of a highlighted block*/
  67. {
  68.    if(InvsMode==NOINV)
  69.       if(PtrX >= MinX(CurrentItem) && PtrX <= MaxX(CurrentItem))
  70.          HandleLineInvs();
  71.       else
  72.          HandleBlockInvs();
  73.    else
  74.       if(InvsMode > NOINV)
  75.          HandleLineInvs();
  76.       else
  77.          HandleBlockInvs();
  78. }
  79.  
  80. HandleBlockInvs() /*Handle the inverse of a block of lines*/
  81. {
  82.    int X,Y;
  83.  
  84.    if(InvsMode==NOINV)
  85.       {
  86.       InvY=EndIY=CurY;
  87.       WriteConsole(Inv,-1);
  88.       PlotCursor(1,CurY);
  89.       PrintItem(CurrentItem);
  90.       WriteConsole(Norm,-1);
  91.       EndIItem=StartIItem=(struct LineItem *)CurrentItem;
  92.       PlotCursor(MinX(CurrentItem),CurY);
  93.       InvsMode=BLOCK_PENDING;
  94.       return(TRUE);
  95.       }
  96.  
  97.    if(InvsMode==BLOCK_PENDING)
  98.       {
  99.       if(PtrY == BLastY)
  100.          {
  101.          EndBlockInvs();
  102.          return(TRUE);
  103.          }
  104.  
  105.       if(PtrY > BLastY)
  106.          {
  107.          EndIItem=(struct LineItem *)CurrentItem;
  108.          PlotCursor(1,BLastY+1);
  109.          RvsBlock(StartIItem->NextItem,EndIItem);
  110.          EndIY=CurY=PtrY;
  111.          InvsMode=BLOCK_DOWN;
  112.          PlotCursor(MinX(EndIItem),CurY);
  113.          }
  114.  
  115.       if(PtrY < BLastY)
  116.          {
  117.          EndIItem=(struct LineItem *)CurrentItem;
  118.          EndIY=CurY;
  119.          RvsBlock(EndIItem,StartIItem->PrevItem);
  120.          PlotCursor(MinX(EndIItem),EndIY);
  121.          InvsMode=BLOCK_UP;
  122.          }
  123.       return(TRUE);
  124.       }
  125.  
  126.    if(InvsMode == BLOCK_DOWN)
  127.       {
  128.       if(PtrY > BLastY)
  129.          {
  130.          PlotCursor(1,BLastY+1);
  131.          RvsBlock(EndIItem->NextItem,CurrentItem);
  132.          EndIY=CurY=PtrY;
  133.          EndIItem=(struct LineItem *)CurrentItem;
  134.          PlotCursor(MinX(EndIItem),CurY);
  135.          }
  136.       if(PtrY < BLastY)
  137.          {
  138.          if(PtrY <= InvY)
  139.             {
  140.             EndBlockInvs(FALSE);
  141.             return(TRUE);
  142.             }
  143.          EndIY=Y=CurY;
  144.          X=CurX;
  145.          PlotCursor(CurX,CurY+1);
  146.          NormBlock(CurrentItem->NextItem,EndIItem);
  147.          PlotCursor(X,Y);
  148.          EndIItem=(struct LineItem *)CurrentItem;
  149.          }
  150.       }
  151.    else
  152.       {
  153.       if(PtrY < BLastY)
  154.          {
  155.          EndIY=Y=CurY;
  156.          RvsBlock(CurrentItem,EndIItem->PrevItem);
  157.          PlotCursor(MinX(CurrentItem),Y);
  158.          EndIItem=(struct LineItem *)CurrentItem;
  159.          }
  160.       if(PtrY > BLastY)
  161.          {
  162.          if(PtrY >= InvY)
  163.             {
  164.             EndBlockInvs();
  165.             return(TRUE);
  166.             }
  167.          Y=CurY;
  168.          PlotCursor(CurX,EndIY);
  169.          NormBlock(EndIItem,CurrentItem->PrevItem);
  170.          EndIItem=(struct LineItem *)CurrentItem;
  171.          PlotCursor(MinX(CurrentItem),CurY+1);
  172.          EndIY=CurY;
  173.          }
  174.       }
  175. }
  176.  
  177. NormBlock(Start,End) /*Normalize a specified block of highlight*/
  178. struct LineItem *Start,*End;
  179. {
  180.    struct LineItem *CurItem;
  181.  
  182.    CurItem=(struct LineItem *)Start;
  183.    WriteConsole(Norm,-1);
  184.  
  185.    CurY--;
  186.    while(CurItem != End->NextItem)
  187.       {
  188.       PlotCursor(1,CurY+1);
  189.       PrintItem(CurItem);
  190.       CurItem=(struct LineItem *)CurItem->NextItem;
  191.       }
  192. }
  193.  
  194. RvsBlock(Start,End)  /*Reverse a block*/
  195. struct LineItem *Start,*End;
  196. {
  197.    struct LineItem *CurItem;
  198.  
  199.    CurItem=(struct LineItem *)Start;
  200.    WriteConsole(Inv,-1);
  201.  
  202.    CurY--;
  203.    while(CurItem != End->NextItem)
  204.       {
  205.       PlotCursor(1,CurY+1);
  206.       PrintItem(CurItem);
  207.       CurItem=(struct LineItem *)CurItem->NextItem;
  208.       }
  209.    WriteConsole(Norm,-1);
  210. }
  211.  
  212. EndBlockInvs() /*End the highlight of a block of lines*/
  213. {
  214.    int Y=CurY;
  215.  
  216.    if(InvY > EndIY)
  217.       {
  218.       PlotCursor(1,EndIY);
  219.       NormBlock(EndIItem,StartIItem);
  220.       PlotCursor(MinX(CurrentItem),Y);
  221.       }
  222.    else
  223.       {
  224.       PlotCursor(1,InvY);
  225.       NormBlock(StartIItem,EndIItem);
  226.       PlotCursor(MinX(StartIItem),Y);
  227.       }
  228.    InvsMode=NOINV;
  229. }
  230.  
  231. HandleLineInvs()  /*Handle the inverse of individual characters*/
  232. {
  233.    int NewEnd;
  234.  
  235.    if(PtrX < MinX(CurrentItem))
  236.       PtrX=MinX(CurrentItem);
  237.    else
  238.       if(PtrX > MaxX(CurrentItem))
  239.          PtrX=MaxX(CurrentItem);
  240.  
  241.    if(InvsMode==NOINV)
  242.       {
  243.       InvBuf[3]=CurrentItem->Text[PosInText(CurrentItem->Level)];
  244.       WriteConsole(InvBuf,7);
  245.       StartChar=EndChar=PosInText(CurrentItem->Level);
  246.       PlotCursor(CurX,CurY);
  247.       InvsMode=LINE_PENDING;
  248.       InvY=CurY;
  249.       InvItem=(struct LineItem *)CurrentItem;
  250.       return(TRUE);
  251.       }
  252.  
  253.    if(InvsMode==LINE_PENDING)
  254.       {
  255.       if(PtrX == BLastX)
  256.          {
  257.          EndLineInvs();
  258.          return(TRUE);
  259.          }
  260.  
  261.       if(PtrX > BLastX)
  262.          {
  263.          if(PtrX > BLastX+1)
  264.             {
  265.             EndChar=PosInText(InvItem->Level)-1;
  266.             PlotCursor(BLastX+1,CurY);
  267.             RvsText(StartChar+1,EndChar);
  268.             CurX=CurX+EndChar-StartChar;
  269.             }
  270.          InvsMode=LINE_FWD;
  271.          return(TRUE);
  272.          }
  273.  
  274.       if(PtrX < BLastX)
  275.          {
  276.          EndChar=PosInText(InvItem->Level);
  277.          RvsText(EndChar,StartChar-1);
  278.          PlotCursor(PtrX,CurY);
  279.          InvsMode=LINE_BACK;
  280.          }
  281.       return(TRUE);
  282.       }
  283.    else
  284.       if(InvsMode==LINE_FWD)
  285.          {
  286.          if(PtrX > BLastX)
  287.             {
  288.             NewEnd=PtrX-MinX(InvItem)-1;
  289.             PlotCursor(EndChar+MinX(InvItem),CurY);
  290.             RvsText(EndChar,NewEnd);
  291.             CurX=NewEnd+MinX(InvItem);
  292.             EndChar=NewEnd;
  293.             }
  294.  
  295.          if(PtrX < BLastX)
  296.             if(PtrX-MinX(InvItem)<=StartChar)
  297.                EndLineInvs();
  298.             else
  299.                {
  300.                NewEnd=PtrX-MinX(InvItem);
  301.                NormText(NewEnd,EndChar);
  302.                PlotCursor(CurX,CurY);
  303.                EndChar=NewEnd;
  304.                }
  305.          }
  306.       else
  307.          {
  308.          if(PtrX < BLastX)
  309.             {
  310.             NewEnd=PtrX-MinX(InvItem);
  311.             RvsText(NewEnd,EndChar);
  312.             PlotCursor(CurX,CurY);
  313.             EndChar=NewEnd;
  314.             }
  315.  
  316.          if(PtrX > BLastX)
  317.             if(PtrX-MinX(InvItem)>=StartChar)
  318.                EndLineInvs();
  319.             else
  320.                {
  321.                NewEnd=PtrX-MinX(InvItem)-1;
  322.                PlotCursor(EndChar+MinX(InvItem),CurY);
  323.                NormText(EndChar,NewEnd);
  324.                CurX=NewEnd+MinX(InvItem);
  325.                EndChar=NewEnd;
  326.                PlotCursor(CurX+1,CurY);
  327.                }
  328.          }
  329. }
  330.  
  331. RvsText(Start,End)   /*Highlight a block of text*/
  332. int Start,End;
  333. {
  334.    char Buffer[80];
  335.    int c,l;
  336.  
  337.    strcpy(Buffer,Inv);
  338.    l=strlen(Buffer);
  339.  
  340.    for(c=l; c-l < End-Start+1 ; c++)
  341.       {
  342.       Buffer[c]=InvItem->Text[c+Start-l];
  343.       }
  344.    Buffer[c]=0;
  345.  
  346.    strcat(Buffer,Norm);
  347.  
  348.    WriteConsole(Inv,-1);
  349.    WriteConsole(Buffer,c);
  350.    WriteConsole(Norm,-1);
  351. }
  352.  
  353.  
  354. MoveBack(Number)  /*Move back in the item list a specified number of times*/
  355. int Number;
  356. {
  357.    int c;
  358.  
  359.    for(c=0;c<Number;c++)
  360.       {
  361.       if(CurrentItem->PrevItem==NULL)
  362.          return(FALSE);
  363.       else
  364.          CurrentItem=(struct LineItem *)CurrentItem->PrevItem;
  365.       }
  366.    return(TRUE);
  367. }
  368.  
  369. MoveForward(Number)  /*Move forward in the item list a specifiecd*/
  370. int Number;       /*number of times*/
  371. {
  372.    int c;
  373.    struct LineItem *OrigItem;
  374.  
  375.    OrigItem=(struct LineItem *)CurrentItem;
  376.    for(c=0;c<Number;c++)
  377.       {
  378.       if(CurrentItem->NextItem==NULL)
  379.          {
  380.          CurrentItem=(struct LineItem *)OrigItem;
  381.          return(FALSE);
  382.          }
  383.       else
  384.          CurrentItem=(struct LineItem *)CurrentItem->NextItem;
  385.       }
  386.    return(TRUE);
  387. }
  388.  
  389. EndLineInvs()  /*End text inverse*/
  390. {
  391.    if(StartChar < EndChar)
  392.       NormText(StartChar,EndChar);
  393.    else
  394.       NormText(EndChar,StartChar);
  395.    InvsMode=NOINV;
  396. }
  397.  
  398. NormText(Start,End)     /*Un-reverse text*/
  399. int Start,End;
  400. {
  401.    int TempX,c;
  402.    char Buffer[80];
  403.  
  404.    for(c=Start;c<=End;c++)
  405.       Buffer[c-Start]=InvItem->Text[c];
  406.  
  407.    Buffer[c-Start]=0;
  408.  
  409.    TempX=CurX;
  410.    PlotCursor(MinX(InvItem)+Start,InvY);
  411.    WriteConsole(Buffer,-1);
  412.    PlotCursor(TempX,InvY);
  413. }
  414.  
  415. HandleDelBlock()  /*Delete a block of lines*/
  416. {
  417.    InvsMode=NOINV;
  418.  
  419.    if((StartIItem->PrevItem==NULL && EndIItem->NextItem==NULL) ||
  420.          (StartIItem->NextItem==NULL && EndIItem->PrevItem==NULL))
  421.       {
  422.       NewAll();
  423.       return(TRUE);
  424.       }
  425.  
  426.    if(InvY <= BLastY)
  427.       DelBlock(StartIItem,EndIItem,InvY,BLastY);
  428.    else
  429.       DelBlock(EndIItem,StartIItem,BLastY,InvY);
  430. }
  431.  
  432. DelBlock(Start,End,StartY,EndY)  /*Delete a block of lines*/
  433. struct LineItem *Start,*End;
  434. int StartY,EndY;
  435. {
  436.    int TOS;
  437.  
  438.    if(Start==FirstScrnItem)
  439.       TOS=TRUE;
  440.    else
  441.       TOS=FALSE;
  442.  
  443.    if(Start->PrevItem == NULL)
  444.       {
  445.       CurrentItem=FirstItem=FirstScrnItem=
  446.             (struct LineItem *)End->NextItem;
  447.       CurrentItem->PrevItem=NULL;
  448.       RemItem(CurrentItem);
  449.       AddItem(CurrentItem);
  450.       TOS=FALSE;
  451.       }
  452.    else
  453.       if(End->NextItem==NULL)
  454.          {
  455.          CurrentItem=LastItem=
  456.                (struct LineItem *)Start->PrevItem;
  457.          LastItem->NextItem=NULL;
  458.          if(Start==FirstScrnItem)
  459.             {
  460.             FirstScrnItem=ScrnBtm=(struct LineItem *)CurrentItem;
  461.             StartY=1;
  462.             }
  463.          else
  464.             StartY--;
  465.          TOS=FALSE;
  466.          }
  467.       else
  468.          {
  469.          CurrentItem=Start->PrevItem->NextItem=(struct LineItem *)
  470.                End->NextItem;
  471.          End->NextItem->PrevItem=
  472.                (struct LineItem *)Start->PrevItem;
  473.          }
  474.    if(TOS)
  475.       CurrentItem=FirstScrnItem=(struct LineItem *)End->NextItem;
  476.    FreeListMem(Start,End);
  477.    RemItem(CurrentItem);
  478.    AddItem(CurrentItem);
  479.    BackSearchRefresh(CurrentItem);
  480.    PrintItemList(CurrentItem,StartY);
  481.    PlotCursor(MinX(CurrentItem),StartY);
  482. }
  483.  
  484. FreeListMem(Start,End)  /*Free several Items at once*/
  485. struct LineItem *Start,*End;
  486. {
  487.    struct LineItem *Item,*Next;
  488.    Next=(struct LineItem *)Start;
  489.    do
  490.       {
  491.       Item=(struct LineItem *)Next;
  492.       RemItem(Item);
  493.       Next=(struct LineItem *)Item->NextItem;
  494.       FreeMem(Item,sizeof(struct LineItem));
  495.       }
  496.    while(Item != End && Next != NULL);
  497. }
  498.  
  499. DelTextBlock() /*Delete the highlighted text*/
  500. {
  501.    int c,Start,End,len;
  502.    char Buffer[2];
  503.  
  504.    if(StartChar < EndChar)
  505.       {
  506.       Start=StartChar;
  507.       End=EndChar;
  508.       }
  509.    else
  510.       {
  511.       Start=EndChar;
  512.       End=StartChar;
  513.       }
  514.    len=strlen(InvItem->Text);
  515.  
  516.    for(c=0;c <= len-End; c++)
  517.       InvItem->Text[c+Start]=InvItem->Text[c+End+1];
  518.  
  519.    PlotCursor(1,InvY);
  520.    Buffer[0]=CSI;
  521.    Buffer[1]=0x4b;
  522.    WriteConsole(Buffer,2);
  523.    PrintItem(InvItem);
  524.    PlotCursor(MinX(InvItem)+Start,InvY);
  525.    InvsMode=NOINV;
  526. }
  527.  
  528. CancelInvs()  /*Cancel inversed text or lines*/
  529. {
  530.    if(NOINV == InvsMode)
  531.       return(FALSE);
  532.    else
  533.       if(InvsMode > NOINV)
  534.          EndLineInvs();
  535.       else
  536.          EndBlockInvs();
  537.  
  538.    return(TRUE);
  539. }
  540.  
  541. DelInvs()   /*Delete the highlighted block or text*/
  542. {
  543.    if(InvsMode==NULL)
  544.       return(FALSE);
  545.  
  546.    if(InvsMode > NOINV)
  547.       DelTextBlock();
  548.    else
  549.       HandleDelBlock();
  550.  
  551.    return(TRUE);
  552. }
  553.  
  554. TitleError(string)
  555. char *string;
  556. {
  557.    DisplayBeep(Screen);
  558.    ErrorInTitle = TRUE;
  559.    SetWindowTitles(Window,-1,string);
  560. }
  561.  
  562. TitleErrorCancel()
  563. {
  564.    static char Title[85];
  565.  
  566.    strcpy(Title,ScreenTitle);
  567.    if(FileName[0])
  568.       strncat(Title,FileName,65);
  569.    else
  570.       strcat(Title,"Untitled");
  571.    if(Modified==TRUE)
  572.       Title[0]='*';
  573.    ErrorInTitle = FALSE;
  574.    SetWindowTitles(Window,-1,Title);
  575. }
  576.  
  577. BackSearchRefresh(Base)    /*Do a refresh of ItemNumbers by searching*/
  578. struct LineItem *Base;    /*back through the item list*/
  579. {
  580.    struct LineItem *Work,Dummy;
  581.  
  582.    Dummy.PrevItem=(struct LineItem *)Base->PrevItem;
  583.    Dummy.NextItem=(struct LineItem *)Base->NextItem;
  584.  
  585.    for(Dummy.Level=Base->Level;Dummy.Level > 0;Dummy.Level--)
  586.       if((Work=(struct LineItem *)FindPrev(&Dummy))!=NULL)
  587.          {
  588.          RemItem(Work);
  589.          AddItem(Work);
  590.          }
  591. }
  592.  
  593.  
  594.