home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
new
/
util
/
edit
/
jade
/
src
/
housekeeping.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-03
|
14KB
|
528 lines
/* housekeeping.c -- Generally editor fiddly stuff
Copyright (C) 1993, 1994 John Harper <jsh@ukc.ac.uk>
This file is part of Jade.
Jade is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
Jade is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Jade; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "jade.h"
#include "jade_protos.h"
_PR void adjust_marks_add_x(TX *, long, long, long);
_PR void adjust_marks_sub_x(TX *, long, long, long);
_PR void adjust_marks_add_y(TX *, long, long);
_PR void adjust_marks_sub_y(TX *, long, long);
_PR void adjust_marks_split_y(TX *, long, long);
_PR void adjust_marks_join_y(TX *, long, long);
_PR void resync_xy(VW *);
_PR void set_start_col(VW *, long);
_PR void set_start_line(VW *, long);
_PR void reset_all_views(TX *);
/* The next few routines deal with updating the various references to
coordinates throughout the views after chunks have been deleted and
inserted. */
void
adjust_marks_add_x(TX *tx, long addx, long xpos, long ypos)
{
VW *thisvw;
Mark *thismark;
#define UPD(x,y) \
do { \
if((y == ypos) && (x >= xpos)) \
x += addx; \
} while(0)
for(thisvw = view_chain; thisvw; thisvw = thisvw->vw_Next)
{
if(thisvw->vw_Tx == tx)
{
UPD(thisvw->vw_CursorPos.pos_Col, thisvw->vw_CursorPos.pos_Line);
if(!(thisvw->vw_Flags & VWFF_RECTBLOCKS))
{
UPD(thisvw->vw_BlockS.pos_Col, thisvw->vw_BlockS.pos_Line);
UPD(thisvw->vw_BlockE.pos_Col, thisvw->vw_BlockE.pos_Line);
}
}
}
for(thismark = tx->tx_MarkChain; thismark; thismark = thismark->mk_Next)
{
UPD(VPOS(thismark->mk_Pos).pos_Col, VPOS(thismark->mk_Pos).pos_Line);
}
UPD(tx->tx_SavedCPos.pos_Col, tx->tx_SavedCPos.pos_Line);
UPD(tx->tx_SavedWPos.pos_Col, tx->tx_SavedWPos.pos_Line);
UPD(tx->tx_SavedBlockPos[0].pos_Col, tx->tx_SavedBlockPos[0].pos_Line);
UPD(tx->tx_SavedBlockPos[1].pos_Col, tx->tx_SavedBlockPos[1].pos_Line);
#if 1
if((tx->tx_ModStart.pos_Line == ypos) && (tx->tx_ModStart.pos_Col > xpos))
tx->tx_ModStart.pos_Col += addx;
#else
UPD(tx->tx_ModStart.pos_Col, tx->tx_ModStart.pos_Line);
#endif
UPD(tx->tx_ModEnd.pos_Col, tx->tx_ModEnd.pos_Line);
#undef UPD
}
void
adjust_marks_sub_x(TX *tx, long subx, long xpos, long ypos)
{
VW *thisvw;
Mark *thismark;
#define UPD(x,y) \
do { \
if((y == ypos) && (x >= xpos)) \
{ \
if((x -= subx) < xpos) \
x = xpos; \
} \
} while(0)
for(thisvw = view_chain; thisvw; thisvw = thisvw->vw_Next)
{
if(thisvw->vw_Tx == tx)
{
UPD(thisvw->vw_CursorPos.pos_Col, thisvw->vw_CursorPos.pos_Line);
if(!(thisvw->vw_Flags & VWFF_RECTBLOCKS))
{
UPD(thisvw->vw_BlockS.pos_Col, thisvw->vw_BlockS.pos_Line);
UPD(thisvw->vw_BlockE.pos_Col, thisvw->vw_BlockE.pos_Line);
}
}
}
for(thismark = tx->tx_MarkChain; thismark; thismark = thismark->mk_Next)
{
UPD(VPOS(thismark->mk_Pos).pos_Col, VPOS(thismark->mk_Pos).pos_Line);
}
UPD(tx->tx_SavedCPos.pos_Col, tx->tx_SavedCPos.pos_Line);
UPD(tx->tx_SavedWPos.pos_Col, tx->tx_SavedWPos.pos_Line);
UPD(tx->tx_SavedBlockPos[0].pos_Col, tx->tx_SavedBlockPos[0].pos_Line);
UPD(tx->tx_SavedBlockPos[1].pos_Col, tx->tx_SavedBlockPos[1].pos_Line);
UPD(tx->tx_ModStart.pos_Col, tx->tx_ModStart.pos_Line);
#if 1
if((tx->tx_ModEnd.pos_Line == ypos) && (tx->tx_ModEnd.pos_Col > xpos))
{
if((tx->tx_ModEnd.pos_Col -= subx) < xpos)
tx->tx_ModEnd.pos_Col = xpos;
}
#else
UPD(tx->tx_ModEnd.pos_Col, tx->tx_ModEnd.pos_Line);
#endif
#undef UPD
}
/*
* Whole lines only please
*/
void
adjust_marks_add_y(TX *tx, long addy, long ypos)
{
VW *thisvw;
Mark *thismark;
#define UPD(y) \
do { \
if(y >= ypos) \
y += addy; \
} while(0)
for(thisvw = view_chain; thisvw; thisvw = thisvw->vw_Next)
{
if(thisvw->vw_Tx == tx)
{
UPD(thisvw->vw_CursorPos.pos_Line);
UPD(thisvw->vw_BlockS.pos_Line);
UPD(thisvw->vw_BlockE.pos_Line);
if(thisvw != curr_vw)
UPD(thisvw->vw_StartLine);
}
}
for(thismark = tx->tx_MarkChain; thismark; thismark = thismark->mk_Next)
{
UPD(VPOS(thismark->mk_Pos).pos_Line);
}
UPD(tx->tx_SavedCPos.pos_Line);
UPD(tx->tx_SavedWPos.pos_Line);
UPD(tx->tx_SavedBlockPos[0].pos_Line);
UPD(tx->tx_SavedBlockPos[1].pos_Line);
#if 0
#if 1
if(tx->tx_ModStart.pos_Line > ypos)
tx->tx_ModStart.pos_Line += addy;
#else
UPD(tx->tx_ModStart.pos_Line);
#endif
UPD(tx->tx_ModEnd.pos_Line);
#endif
#undef UPD
}
/*
* Whole lines only please
*/
void
adjust_marks_sub_y(TX *tx, long suby, long ypos)
{
VW *thisvw;
Mark *thismark;
#define UPD(y) \
do { \
if(y > ypos) \
{ \
if((y -= suby) < ypos) \
y = ypos; \
} \
} while(0)
#define UPD2(x,y) \
if(y >= ypos) \
{ \
if((y -= suby) < ypos) \
{ \
y = ypos; \
x = 0; \
} \
} while(0)
for(thisvw = view_chain; thisvw; thisvw = thisvw->vw_Next)
{
if(thisvw->vw_Tx == tx)
{
UPD2(thisvw->vw_CursorPos.pos_Col, thisvw->vw_CursorPos.pos_Line);
if(thisvw->vw_Flags & VWFF_RECTBLOCKS)
{
UPD(thisvw->vw_BlockS.pos_Line);
UPD(thisvw->vw_BlockE.pos_Line);
}
else
{
UPD2(thisvw->vw_BlockS.pos_Col, thisvw->vw_BlockS.pos_Line);
UPD2(thisvw->vw_BlockE.pos_Col, thisvw->vw_BlockE.pos_Line);
}
if(thisvw != curr_vw)
UPD(thisvw->vw_StartLine);
}
}
for(thismark = tx->tx_MarkChain; thismark; thismark = thismark->mk_Next)
{
UPD2(VPOS(thismark->mk_Pos).pos_Col, VPOS(thismark->mk_Pos).pos_Line);
}
UPD2(tx->tx_SavedCPos.pos_Col, tx->tx_SavedCPos.pos_Line);
UPD2(tx->tx_SavedWPos.pos_Col, tx->tx_SavedWPos.pos_Line);
UPD2(tx->tx_SavedBlockPos[0].pos_Col, tx->tx_SavedBlockPos[0].pos_Line);
UPD2(tx->tx_SavedBlockPos[1].pos_Col, tx->tx_SavedBlockPos[1].pos_Line);
UPD2(tx->tx_ModStart.pos_Col, tx->tx_ModStart.pos_Line);
#if 1
if(tx->tx_ModEnd.pos_Line > ypos)
{
if((tx->tx_ModEnd.pos_Line -= suby) < ypos)
{
tx->tx_ModEnd.pos_Line = ypos;
tx->tx_ModEnd.pos_Col = 0;
}
}
#else
UPD2(tx->tx_ModEnd.pos_Col, tx->tx_ModEnd.pos_Line);
#endif
#undef UPD
#undef UPD2
}
/*
* Use when splitting a line into 2, cursor should be at position of split
*/
void
adjust_marks_split_y(TX *tx, long xpos, long ypos)
{
VW *thisvw;
Mark *thismark;
#define UPD(y) \
do { \
if(y > ypos) \
y++; \
} while(0)
#define UPD2(x,y) \
do { \
if((y == ypos) && (x >= xpos)) \
{ \
x -= xpos; \
y++; \
} \
else if(y > ypos) \
y++; \
} while(0)
for(thisvw = view_chain; thisvw; thisvw = thisvw->vw_Next)
{
if(thisvw->vw_Tx == tx)
{
UPD2(thisvw->vw_CursorPos.pos_Col, thisvw->vw_CursorPos.pos_Line);
if(thisvw->vw_Flags & VWFF_RECTBLOCKS)
{
UPD(thisvw->vw_BlockS.pos_Line);
UPD(thisvw->vw_BlockE.pos_Line);
}
else
{
UPD2(thisvw->vw_BlockS.pos_Col, thisvw->vw_BlockS.pos_Line);
UPD2(thisvw->vw_BlockE.pos_Col, thisvw->vw_BlockE.pos_Line);
}
if(thisvw != curr_vw)
UPD(thisvw->vw_StartLine);
}
}
for(thismark = tx->tx_MarkChain; thismark; thismark = thismark->mk_Next)
{
UPD2(VPOS(thismark->mk_Pos).pos_Col, VPOS(thismark->mk_Pos).pos_Line);
}
UPD2(tx->tx_SavedCPos.pos_Col, tx->tx_SavedCPos.pos_Line);
UPD2(tx->tx_SavedWPos.pos_Col, tx->tx_SavedWPos.pos_Line);
UPD2(tx->tx_SavedBlockPos[0].pos_Col, tx->tx_SavedBlockPos[0].pos_Line