Reply To: Initial active line from "find" list

Product Compare Forums Multi-Edit Support Initial active line from "find" list Reply To: Initial active line from "find" list

#5825
Bret Sutton
Participant

Here is a macro that will allow you to position the current line anywhere on the screen that you want.

[code:2whscim1]
#include stddlgs.sh

//*******************************************************************************

Name: CENTER_LINE

Description: If called with no parameters, it centers the current line
vertically in the window.
If /P=T, the current line is moved to the top of the window.
If /P=B, the current line is moved to the bottom of the window.
If /P=C, the current line is centered in the window.
If /P=n.d (a fraction), the current line is centered that far
down the screen.

05-01-96 BJS Added /P=n.d, /P=C

NWS Macros Version 9.10.03 by David White and Bret Sutton
*******************************************************************************/

macro CENTER_LINE
{
int dest_pos, cur_line, tr, dp_pos, num, denom;
str opt;

tr = Refresh;
Refresh = False;

opt = Parse_Str(’/P=’, mparm_str);
switch (opt)
{
case ‘T’ :
dest_pos = 1;
break;
case ‘B’ :
dest_pos = Win_Y2 – Win_Y1 – 1;
break;
case ‘C’ :
case ” :
dest_pos = (Win_Y2 – Win_Y1) / 2;
break;
default :
dp_pos = XPos(’.’,opt,1);
if (dp_pos == 0)
goto BAD_ND;
if (Val(num,Copy(opt,1,dp_pos-1)) != 0)
goto BAD_ND;
if (Val(denom,Copy(opt,dp_pos+1,99)) != 0)
goto BAD_ND;
dest_pos = (Win_Y2 – Win_Y1) * num / denom;
}
cur_line = C_Line;
while (C_Row > dest_pos)
Up;
while (C_Row < dest_pos)
Down;
Goto_Line(cur_line);
// This works because, if cur_line is on the screen, and we do a Goto_Line,
// it will always put that line at the cursor position.
Redraw;
goto EXIT;

BAD_ND:
MsgDlg("’" + opt + "’ is invalid format for /P=n.d parameter!", "NWSTEXT^CENTER_LINE", "", 1);
EXIT:
Refresh = tr;
}
[/code:2whscim1]