Example #1
0
/*** Remove the char under the cursor ***/
void del(Project p, BYTE word)
{
	if(p->nbc < p->edited->size)
	{
		ULONG nbc = word ? forward_word(p->edited,p->nbc)-1 : p->nbc;
		rem_chars(&p->undo, p->edited, p->nbc, nbc);
		REDRAW_CURLINE(p);
		inv_curs(p, TRUE);
	}	else if(p->edited->next) {

		/* Join current and next line: */
		if( join_lines(&p->undo, p->edited, p->edited->next) )
		{
			REDRAW_CURLINE(p);
			/* Is it needed to scroll display? */
			if(p->ycurs < gui.botcurs)
				scroll_up(p,p->edited->next,p->ycurs,p->left_pos);

			/* Redraw the cursor: */
			inv_curs(p,TRUE);
			p->max_lines--;
			prop_adj(p);
		}	else ThrowError(Wnd, ErrMsg(ERR_NOMEM));
	}
}
Example #2
0
/*** Jump the cursor far left or far right ***/
void jump_horiz(Project p, BYTE dir)
{
	if( dir >= 0 )
	{
		/* If cursor is already at rightmost position, scroll display */
		if( p->nbrwc == p->left_pos+gui.nbcol-1 )
		{
			p->nbrwc += gui.nbcol-1;
		}
		else p->nbrwc = p->left_pos+gui.nbcol-1;
	} else {
		/* Check if cursor is already at leftmost position */
		if( p->nbrwc == p->left_pos )
		{
			p->nbrwc = p->left_pos - (gui.nbcol-1);
			if( (LONG)p->nbrwc < 0 ) p->nbrwc = 0;
		}
		else p->nbrwc = p->left_pos;
	}

	inv_curs(p,FALSE);
	p->nbrc  = adjust_rc(p->edited, p->nbrwc, &p->nbc, dir<0);
	p->xcurs = (p->nbrc-p->left_pos)*XSIZE + gui.left;
	{
		LONG newleft = center_horiz( p );
		if( newleft != p->left_pos )
			scroll_xy(p, newleft, p->top_line, 0);
	}
	/* Move selection or cursor? */
	if(p->ccp.select) move_selection(p, p->nbrwc, p->nbl);
	inv_curs(p,TRUE);
	draw_info( p );
}
Example #3
0
/*** Move cursor down ***/
void curs_down(Project p)
{
	LINE *ln;
	if( ( ln = p->edited->next) )
	{
		LONG newx; BYTE scroll=0;

		inv_curs(p, FALSE);
		/* Is the cursor at the bottom of the display? */
		if( p->ycurs < gui.botcurs) p->ycurs += YSIZE;
		else scroll=1;

		p->nbl++; p->edited=ln;
		p->nbrc = adjust_rc(ln, p->nbrwc, &p->nbc, FALSE);
		p->xcurs = (p->nbrc-p->left_pos)*XSIZE + gui.left;

		/* Minimise calls to scroll_xy */
		if((newx=center_horiz(p))!=p->left_pos || scroll)
			scroll_xy(p, newx, p->top_line+scroll, scroll);

		/* Update selection */
		if(p->ccp.select) move_selection(p, p->nbrc, p->nbl);
		inv_curs(p, TRUE);
		draw_info( p );
	}
}
Example #4
0
/*** Move cursor up ***/
void curs_up(Project p)
{
	LINE *ln;
	if( ( ln = p->edited->prev) )
	{
		LONG newx; BYTE scroll=0;

		inv_curs(p, FALSE);
		/* Is the cursor on top of display? */
		if(p->ycurs > gui.topcurs) p->ycurs -= YSIZE;
		else scroll=1;

		p->nbl--; p->edited=ln;
		p->nbrc  = adjust_rc(ln, p->nbrwc, &p->nbc, FALSE);
		p->xcurs = (p->nbrc-p->left_pos)*XSIZE + gui.left;

		/* If cursor exits edit area due to horizontal **
		** adjustment, scroll the display accordingly: */
		if((newx=center_horiz(p))!=p->left_pos || scroll)
			scroll_xy(p, newx, p->top_line-scroll, scroll);

		/* Update selection */
		if(p->ccp.select) move_selection(p, p->nbrc, p->nbl);
		inv_curs(p, TRUE);
		draw_info( p );
	}
}
Example #5
0
/*** Move cursor to absolute position ***/
void move_to_line(Project p, ULONG nbline, char dirtiness)
{
	ULONG newtop;

	if(!p->ccp.select) inv_curs(p,FALSE);
	/* Get the new top line */
	{	register ULONG old_nbl = p->nbl;
		p->nbl = nbline;
		newtop = center_vert(p);
		p->nbl = old_nbl;
	}	set_cursor_line(p, nbline, newtop);

	if(dirtiness == LINE_AS_IS)
		scroll_xy(p, center_horiz(p), newtop, TRUE);
	else
	{
		/* Some lines are modified: redraw in one pass */
		if( newtop == p->top_line ) {
			REDRAW_CURLINE(p);
			if( dirtiness == LINES_DIRTY )
				scroll_up(p, p->edited->next, p->ycurs, center_horiz(p)),
				prop_adj(p);
			else if( p->left_pos != (newtop = center_horiz(p)) )
				scroll_xy(p, newtop, p->top_line, FALSE);
		}
		else if( dirtiness == LINE_DIRTY )
			scroll_xy(p, center_horiz(p), newtop, TRUE);
		else
			set_top_line(p, newtop, center_horiz(p));
	}
	/* Move cursor or selection */
	if(p->ccp.select) move_selection(p, p->nbrwc, p->nbl);
	inv_curs(p,TRUE);
	draw_info( p );
}
Example #6
0
/*** Join two lines and strip spaces on the next ***/
void join_strip( Project p )
{
	LINE *ln;
	if((ln = p->edited->next) != NULL)
	{
		STRPTR data; ULONG i;
		inv_curs(p, FALSE);
		p->nbc = p->edited->size;
		for(i=0, data=ln->stream; TypeChar[*data] == SPACE && i<ln->size; i++, data++);

		reg_group_by(&p->undo);
		if(i != ln->size)
		{
			/* Do not add a blank if there is already one */
			if( p->nbc > 0 && TypeChar[ p->edited->stream[ p->nbc-1 ] ] != SPACE )
				add_char(&p->undo, p->edited, p->nbc, ' ');
			if( insert_str(&p->undo, p->edited, p->edited->size, data, ln->size-i) == 0 )
				ThrowError(Wnd, ErrMsg(ERR_NOMEM));
		}
		/* ln can't be the first */
		del_line(&p->undo, NULL, ln); p->max_lines--;
		reg_group_by(&p->undo);
		prop_adj(p);
		/* Refresh screen */
		p->nbrc = p->nbrwc = x2pos(p->edited, p->nbc);
		REDRAW_CURLINE( p );
		draw_info( p );
		scroll_up(p, p->edited->next, p->ycurs, center_horiz(p));
		inv_curs(p,TRUE);
	}
}
Example #7
0
/*** Move cursor down/up one page ***/
void pg_updown(Project p, BYTE dir)
{
	LONG newtop = p->top_line, newcrs;

	if(dir>0)
		/* One page down */
		if(newtop+gui.nbline >= p->max_lines) newcrs = p->max_lines-1;
		else {
			newtop += gui.nbline;
			if(newtop+gui.nbline >= p->max_lines)
				newtop = p->max_lines - gui.nbline;
			newcrs = newtop - p->top_line + p->nbl;
		}
	else
		/* One page up */
		if(newtop == 0) newcrs=0;
		else {
			newtop -= gui.nbline;
			if(newtop<0) newtop=0;
			newcrs = newtop - p->top_line + p->nbl;
		}
	if(newcrs != p->nbl) inv_curs(p,FALSE),set_cursor_line(p,newcrs,newtop);
	scroll_xy(p,center_horiz(p),newtop,TRUE);
	if(p->ccp.select) move_selection(p, p->nbrc, p->nbl);
	inv_curs(p,TRUE);
	draw_info( p );
}
Example #8
0
/*** Jump cursor to an absolute position in line (ie: beginning or end) ***/
void horiz_pos( Project p, ULONG newpos )
{
	if( newpos != p->nbrwc )
	{
		inv_curs(p, FALSE);
		p->nbrc = adjust_rc(p->edited, p->nbrwc = newpos, &p->nbc, FALSE);
		scroll_xy(p, center_horiz(p), p->top_line, FALSE);
		p->xcurs = (p->nbrc-p->left_pos)*XSIZE + gui.left;
		if(p->ccp.select) move_selection(p, p->nbrwc, p->nbl);
		inv_curs(p, TRUE);
		draw_info( p );
	}
}
Example #9
0
/*** Refresh display, according to new window size ***/
void new_size(UBYTE Flags)
{
	inv_curs(edit, FALSE);
	adjust_win(Wnd,NbProject>1);   /* Adjust internal variables */
	SetABPenDrMd(RP, pen.fg, pen.bg, JAM2);
	clear_brcorner();
	prop_adj(edit);
	edit->left_pos = curs_visible(edit, edit->top_line);
	edit->xcurs    = (edit->nbrc - edit->left_pos)*XSIZE + gui.left;
	if(Flags & EDIT_GUI)  reshape_panel(edit);
	if(Flags & EDIT_AREA) redraw_content(edit,edit->show,gui.topcurs,gui.nbline);
	inv_curs(edit,TRUE);
}
Example #10
0
/*** Move the cursor according to mouse click ***/
void click(Project p, WORD x, WORD y, BYTE update)
{
	WORD xp = (x-gui.left) / XSIZE,
	     yp = (y-gui.top) / YSIZE;
	LINE *ln;

	if(!p->ccp.select) inv_curs(p, FALSE);

	p->nbl = p->top_line + yp;
	for(ln=p->show; ln->next && yp; yp--,ln=ln->next);
	/* There was no lines, where we've clicked */
	p->nbl -= yp;
	p->edited = ln;
	p->nbrwc  = p->nbrc = xp+p->left_pos;

	xp = curs_visible(p,p->top_line);
	if(xp!=p->left_pos)
		scroll_xy(p, xp, p->top_line, FALSE);
	draw_info( p );
	RP->Mask = gui.selmask;

	/* Set starting selection point */
	if( update )
	{
		ln->flags = FIRSTSEL | LASTSEL;
		p->ccp.xc = p->ccp.xp = p->ccp.startsel = p->ccp.endsel = p->nbrc;
		p->ccp.yc = p->ccp.yp = p->nbl;
		p->ccp.cline = p->ccp.line = ln;
	}
}
Example #11
0
/*** Scroll display according to right prop gadget ***/
void scroll_disp(Project p, BOOL adjust)
{
	ULONG pos = ((struct PropInfo *)((struct Gadget*)Prop)->SpecialInfo)->VertPot *
	            (p->max_lines - gui.nbline) / MAXPOT;

	if(p->max_lines>gui.nbline && pos!=p->top_line)
	{
		if(p->ccp.select)
			/* If selection mode is on, don't move cursor */
			p->ycurs-=(pos-p->top_line)*YSIZE,
			scroll_xy(p, p->left_pos, pos, adjust);
		else
			/* Be sure cursor is always in the edit area */
			inv_curs(p,FALSE),
			scroll_xy(p, curs_visible(p,pos), pos, adjust),
			inv_curs(p,TRUE);
	}
}
Example #12
0
/*** Remove the char before the cursor ***/
void back_space(Project p, BYTE word)
{
	if(p->nbc!=0)
	{
		ULONG nbc = word ? backward_word(p->edited,p->nbc-1) : p->nbc-1;
		rem_chars(&p->undo, p->edited, nbc, p->nbc-1);

		/* Set cursor position and redraws it */
		inv_curs(p,FALSE);
		REDRAW_CURLINE(p);
		p->nbrwc = p->nbrc = x2pos(p->edited, p->nbc=nbc);
		p->xcurs = (p->nbrc-p->left_pos)*XSIZE + gui.left;
		if( (nbc = center_horiz(p)) != p->left_pos )
			scroll_xy(p, nbc, p->top_line, FALSE);
		inv_curs(p,TRUE);
		draw_info( p );
	}	else if(p->edited->prev != NULL) {

		p->edited = p->edited->prev;
		p->nbc    = p->edited->size;
		/* Join previous and current line */
		if( join_lines(&p->undo, p->edited, p->edited->next) )
		{
			/* Move cursor to the end of previous line */
			p->nbrwc = p->nbrc = x2pos(p->edited, p->nbc);

			p->max_lines--; p->nbl--;
			/* Require to scroll the display? */
			inv_curs(p, FALSE);
			if(p->ycurs>gui.topcurs)
				scroll_up(p, p->edited->next, p->ycurs-=YSIZE, center_horiz(p));
			else
				p->top_line--, p->show = p->edited,
				p->xcurs = (p->nbrc-p->left_pos)*XSIZE + gui.left;

			SetAPen(RP, pen.fg);
			REDRAW_CURLINE(p);
			/* Redraw the cursor: */
			inv_curs(p,TRUE);
			draw_info(p);
			prop_adj(p);
		}	else ThrowError(Wnd, ErrMsg(ERR_NOMEM));
	}
}
Example #13
0
/*** User release mouse button ***/
void unclick(Project p)
{
	/* Is there something selected ? */
	if( p->ccp.yp!=p->ccp.yc || p->ccp.startsel!=p->ccp.endsel )
		/* Yes ! */
		p->edited = p->ccp.cline, p->nbrwc=p->ccp.xc,
		set_cursor_line(p, p->nbl = p->ccp.yc, p->top_line);
	else
		p->edited->flags = 0, p->ccp.select = 0,
		inv_curs(p, TRUE), RP->Mask = gui.txtmask;
}
Example #14
0
/*** Remove part of a line ***/
void cut_line(Project p, BYTE mode)
{
	/* Is there something to do? */
	if( (mode==0 && p->nbc==0) || (mode==1 && p->nbc==p->edited->size)) return;

	if( rem_chars(&p->undo, p->edited, mode ? p->nbc : 0, (mode ? p->edited->size : p->nbc)-1) )
	{
		/* Recompute cursor position */
		if(mode==0)
		{
			inv_curs(p,FALSE);
			p->nbc=p->nbrc=p->nbrwc=0;
			if(p->left_pos!=0) scroll_xy(p, 0, p->top_line, FALSE);
			p->xcurs=gui.left;
			draw_info(p);
		}
		REDRAW_CURLINE(p);
		inv_curs(p,TRUE);
	}	else ThrowError(Wnd, ErrMsg(ERR_NOMEM));
}
Example #15
0
/*** Remove an entire line ***/
void amiga_k(Project p)
{
	LINE *del = p->edited;

	if(p->ccp.select) return;

	/* In there a next line, move cursor to */
	if( del->next ) {
		p->edited=del->next; p->max_lines--;
		if(p->show==del) p->show=del->next;
		prop_adj(p);
	}
	/* Adjust cursor position */
	inv_curs(p,FALSE);
	del_line(&p->undo, &p->the_line, del);
	p->nbrc = adjust_rc(p->edited, p->nbrwc, &p->nbc, FALSE);
	REDRAW_CURLINE(p);
	scroll_up(p, p->edited->next, p->ycurs, center_horiz(p));
	inv_curs(p,TRUE);
}
Example #16
0
/*** Jump the cursor at bottom or top of display ***/
void jump_vert(Project p, BYTE dir)
{
	LONG newline, newtop=p->top_line;
	if( dir>=0 )
	{
		/* Move cursor to bottom of display or scroll one page if it's already here */
		newline=newtop+gui.nbline-1;
		if( p->nbl==newline )
			newline+=gui.nbline,
			newtop+=gui.nbline;

		/* Want to jump after the last line? */
		if(newline>=p->max_lines) {
			newline=p->max_lines-1;
			newtop=(p->top_line + gui.nbline > p->max_lines ? p->top_line : newline-gui.nbline+1);
			if(newtop<0) newtop=0;
		}
	}	else {
		/* Same fight with reverse direction */
		newline=newtop;
		if( p->nbl==newline ) {
			newtop-=gui.nbline;
			if(newtop<0) newtop=0;
			newline=newtop;
		}
	}
	/* Adjust display according to cursor position */
	if(newline != p->nbl) {
		inv_curs(p,FALSE);
		set_cursor_line(p, newline, newtop);

		/* Set the selection flags before to scroll display */
		if(p->ccp.select) move_selection(p, p->nbrwc, p->nbl);
		scroll_xy(p,center_horiz(p), newtop, TRUE);
		inv_curs(p,TRUE);
		draw_info( p );
	}
}
Example #17
0
/*** Move cursor to the left ***/
void curs_left(Project p, BYTE word)
{
	register LINE *prev;
	if(p->nbc != 0)
	{
		inv_curs(p,FALSE);
		if(word) p->nbc = backward_word(p->edited, p->nbc-1); else p->nbc--;
		p->nbrwc = p->nbrc = x2pos(p->edited, p->nbc);
		p->xcurs = (p->nbrc-p->left_pos) * XSIZE + gui.left;

		/* Is it gone outside edit area? */
		if(p->nbrc<p->left_pos)
			scroll_xy(p, adjust_leftpos(p, -gui.xstep), p->top_line, FALSE);

		if(p->ccp.select) move_selection(p, p->nbrc, p->nbl);
		inv_curs(p,TRUE);
		draw_info( p );

	}	else if( ( prev = p->edited->prev ) ) {
		/* jump up */
		p->nbrwc = x2pos(prev, prev->size);
		curs_up(p);
	}
}
Example #18
0
/*** One pos right ***/
void curs_right(Project p, BYTE word)
{
	if(p->nbc < p->edited->size)
	{
		inv_curs(p,FALSE);
		if(word) p->nbc = forward_word(p->edited, p->nbc); else p->nbc++;
		p->nbrwc = p->nbrc = x2pos(p->edited, p->nbc);
		p->xcurs = (p->nbrc-p->left_pos) * XSIZE + gui.left;

		/* Move the cursor */
		/* Is it gone outside edit area? */
		if(p->nbrc>=p->left_pos+gui.nbcol)
			scroll_xy(p, adjust_leftpos(p, gui.xstep), p->top_line, FALSE);

		if(p->ccp.select) move_selection(p, p->nbrc, p->nbl);
		inv_curs(p,TRUE);
		draw_info( p );
			
	}	else if(p->edited->next) {
		/* jump down to next line */
		p->nbrwc = 0;
		curs_down(p);
	}
}
Example #19
0
/*** Move cursor incrementally (paste) ***/
void move_cursor(Project p, LONG dx, LONG dy)
{
	LINE *ln; LONG nb=dy;
	inv_curs(p, FALSE);
	if(nb < 0) for(ln=p->edited; nb++; ln=ln->prev);
	else       for(ln=p->edited; nb--; ln=ln->next);
	p->edited = ln;
	p->nbl   += dy;
	p->nbrwc  = p->nbrc = x2pos(ln,p->nbc = dx);

	dx = center_horiz(p);
	/* Don't scroll if top_line changed! (whole redraw instead) */
	if(dx != p->left_pos && dy == 0)
		scroll_xy(p, dx, p->top_line, TRUE);
	else {
		nb = center_vert(p) - p->top_line;
		for(p->top_line += nb,ln=p->show; nb--; ln=ln->next);
		p->show = ln; p->left_pos = dx;
	}
	p->ycurs = (p->nbl-p->top_line)*YSIZE + gui.topcurs;
	p->xcurs = (p->nbrc-p->left_pos)*XSIZE + gui.left;
	draw_info( p );
}
Example #20
0
/*** Mark: block selection ***/
BYTE move_column_selection(Project p, LONG xn, LONG yn)
{
	static WORD left, nbcol;
	static LONG left_pos;
	extern BYTE	clear;
	LONG yline;				/* Nb. of line marked */
	LINE *ln;				/* Running pointer */
	BYTE ret;				/* Autoscroll ? */
	WORD y;					/* VPos of item sel */
	BYTE rdw = 0;

	/** Vertical autoscroll ? **/
	ret = (yn<p->top_line ? 2 : (yn>=(LONG)(p->top_line+gui.nbline) ? 1 : 0));
	if(p->nbrc<p->ccp.startsel && gui.topcurs <= p->ycurs && p->ycurs <= gui.botcurs)
		p->ccp.select=0,inv_curs(p,0),p->ccp.select=COLUMN_TYPE;
	clear=FALSE;

	/** Reduce refreshed area **/
	left_pos=p->left_pos; left=gui.left; nbcol=gui.nbcol;

	gui.left += XSIZE * ( (
	p->left_pos = MIN(MIN(p->ccp.xp,p->ccp.xc), xn)) - left_pos);
	yline = MAX(MAX(p->ccp.xp,p->ccp.xc), xn);
	gui.nbcol = yline - p->left_pos + tabstop(yline);
	if(p->left_pos+gui.nbcol > left_pos+nbcol)
		gui.nbcol = left_pos+nbcol-p->left_pos;

	if(yn<0) yn=0; if(yn>=p->max_lines) yn=p->max_lines-1,ret=0;
	yline=p->ccp.yc; ln=p->ccp.cline;
	/* top_line may changed */
	y=(yline-p->top_line)*YSIZE+gui.topcurs;

	/** Update start & end selection pos **/
	if( xn < p->ccp.xp )
		p->ccp.endsel = p->ccp.xp, p->ccp.startsel = xn;
	else
		p->ccp.startsel = p->ccp.xp, p->ccp.endsel = xn;

	/** Same fight as before: afterward or backward scan **/
	if( yn >= yline )
	{
		/* Search is afterward */
		for(; yline<yn; y+=YSIZE, yline++, ln=ln->next)
		{
			if(yline < p->ccp.yp) ln->flags=0;
			else ln->flags=FIRSTSEL | LASTSEL;
			if(gui.topcurs <= y && y <= gui.botcurs)
				Move(RP,gui.left,y),write_text(p,ln);
		}
		/* If user has changed vertical position of selection an **
		** update of part of selected buffer will be required:   */
		if(xn != p->ccp.xc) {
			if(p->ccp.yp < p->ccp.yc) rdw=6;
			else if(p->ccp.yp > yn) rdw=1;
		}
	} else {
		/* Scan is backward */
		for(; yline>yn; y-=YSIZE, yline--, ln=ln->prev)
		{
			if(yline > p->ccp.yp) ln->flags=0;
			else ln->flags=FIRSTSEL | LASTSEL;
			if(gui.topcurs <= y && y <= gui.botcurs)
				Move(RP,gui.left,y),write_text(p,ln);
		}
		/* If user has changed vertical position of selection an **
		** update of part of selected buffer will be required:   */
		if(xn != p->ccp.xc) {
			if(p->ccp.yp > p->ccp.yc) rdw=5;
			else if(p->ccp.yp < yn) rdw=2;
		}
	}

	/** Current point now become the previous **/
	ln->flags = FIRSTSEL | LASTSEL;
	/* Last line can overlap edit area */
	if(gui.topcurs<=y && y<=gui.botcurs)
		Move(RP,gui.left,y),write_text(p,ln);

	/** Update unmodified lines **/
	if(rdw)
	{
		register LINE *ptr; register WORD yc;
		/* Limits number of lines to redraw */
		if(rdw&4)
			ptr=p->ccp.cline, yline=p->ccp.yc,
			yc=(yline-p->top_line)*YSIZE+gui.topcurs;
		else ptr=ln, yc=y;

		/* Reduces number of columns to redraw */
		if(p->ccp.xc < xn)
			p->left_pos=p->ccp.xc, gui.nbcol=xn-p->ccp.xc+1+tabstop(xn);
		else
			p->left_pos=xn, gui.nbcol=p->ccp.xc-xn+1+tabstop(p->ccp.xc);
		gui.left = left + XSIZE*(p->left_pos-left_pos);

		/* Be sure lines won't erase right border of window */
		if(p->left_pos+gui.nbcol > left_pos+nbcol) gui.nbcol = left_pos+nbcol-p->left_pos;

		if(rdw&1) {
			for(; yc<=gui.botcurs && yline<=p->ccp.yp; yline++, yc+=YSIZE, ptr=ptr->next)
				if(yc>=gui.topcurs) Move(RP,gui.left,yc),write_text(p,ptr);
		} else {
			for(; yc>=gui.topcurs && yline>=p->ccp.yp; yline--, yc-=YSIZE, ptr=ptr->prev)
				if(yc<=gui.botcurs) Move(RP,gui.left,yc),write_text(p,ptr);
		}
	}

	p->left_pos=left_pos; gui.left=left; gui.nbcol=nbcol;
	p->ccp.xc=xn; p->ccp.cline=ln; p->ccp.yc=yn;
	clear=TRUE;
	return ret;
}
Example #21
0
/*** Handle events coming from main window: ***/
void dispatch_events()
{
	extern ULONG sigmainwnd, swinsig;
	extern UBYTE record;
	BYTE  scrolldisp=0, state=0, cnt=0, mark=0, quit = 0;

	while( quit == 0 )
	{
		/* Active collect, when pressing arrow gadgets */
		sigrcvd = (state==0 ? Wait(sigbits) : sigmainwnd);

/*		if(sigrcvd & SIGBREAKF_CTRL_C) break;

		else */ if(sigrcvd & sigport) { handle_port(); continue; }

		else if(sigrcvd & swinsig) { handle_search(); continue; }

		/* Collect messages posted to the window port */
		while( ( msg = (struct IntuiMessage *) GetMsg(Wnd->UserPort) ) )
		{
			/* Copy the entire message into the buffer */
			CopyMemQuick(msg, &msgbuf, sizeof(msgbuf));
			ReplyMsg( (struct Message *) msg );

			switch( msgbuf.Class )
			{
				case IDCMP_CLOSEWINDOW: handle_menu(112); break;
				case IDCMP_RAWKEY:
					handle_kbd(edit);
					if(record) {
						if(record == 1) reg_act_com(MAC_ACT_SHORTCUT, msgbuf.Code, msgbuf.Qualifier);
						else record &= 0x7f;
					}
					break;
				case IDCMP_INTUITICKS:
					/* An error message which needs to be removed? */
					if(err_time == 0) err_time = msgbuf.Seconds;
					if(err_time && msgbuf.Seconds-err_time>4) StopError(Wnd);
					break;
				case IDCMP_MOUSEBUTTONS:
					/* Click somewhere in the text */
					switch( msgbuf.Code )
					{
						case SELECTDOWN:
							/* Click over the project bar ? */
							if(msgbuf.MouseY < gui.top)
							{
								edit = select_panel(edit, msgbuf.MouseX);
								break;
							}

							click(edit, msgbuf.MouseX, msgbuf.MouseY, FALSE);

							/* Shift-click to use columnar selection */
							if( ( move_selection = SwitchSelect(edit, msgbuf.Qualifier & SHIFTKEYS ? 1:0, 1) ) )
								mark=TRUE;
							break;
						case SELECTUP:
							if(mark) unclick(edit);
							mark=FALSE; scrolldisp=0; break;
					}
					break;
				case IDCMP_NEWSIZE:
					new_size(EDIT_ALL);
					break;
				case IDCMP_GADGETDOWN:       /* Left scroll bar */
					if(msgbuf.IAddress == (APTR) &Prop->down) state=1;
					if(msgbuf.IAddress == (APTR) &Prop->up)   state=2;
					break;
				case IDCMP_GADGETUP:        /* Arrows or prop gadget */
					state=0;
					if(msgbuf.IAddress == (APTR) Prop)
						scroll_disp(edit, FALSE), scrolldisp=0;
					break;
				case IDCMP_MOUSEMOVE:
					if(mark) scrolldisp=2;
					else
						if(Prop->scroller.Flags & GFLG_SELECTED) scrolldisp=1;
					break;
				case IDCMP_MENUPICK:
				{	struct MenuItem * Item;
					ULONG             MenuId;

					/* Multi-selection of menu entries */
					while(msgbuf.Code != MENUNULL)
						if( (Item = ItemAddress( Menu, msgbuf.Code )) )
						{
							/* stegerg: get NextSelect here in case menu action causes screen
							   to be closed/reopened in which case item becomes invalid.
							   Also assuming here that user in such case will not use
							   multiselection, ie. that nextselect will be MENUNULL.
							   
							   If that's not the case it would mean more trouble and to protect
							   against that one would need to check if during handle_menu() the
							   screen has been closed/reopened and in that case break out of
							   the menu multiselection loop here. */
							   							   
							UWORD nextselect = Item->NextSelect;
							
							MenuId = (ULONG)GTMENUITEM_USERDATA( Item );
							handle_menu( MenuId );

							if(record) reg_act_com(MAC_ACT_COM_MENU, MenuId, msgbuf.Qualifier);
							else record &= 0x7f;

							msgbuf.Code = nextselect;
						}
				}
			}
		}
		/* Reduces the number of IDCMP mousemove messages to process */
		if(scrolldisp==1) scroll_disp(edit, FALSE), scrolldisp=0;
		if(scrolldisp==2) { scrolldisp=0; goto moveit; }

		/* User may want to auto-scroll the display using arrow gadgets */
		if(state && (mark || (((struct Gadget *)Prop)[state].Flags & GFLG_SELECTED))) {
			/* Slow down animation: */
			WaitTOF(); cnt++;
			if(cnt>1) {
				cnt=0;
				if(autoscroll(edit,state==1 ? 1:-1)==0) state=0;
				else if(mark) {
					LONG x , y; moveit:
					/* Adjust mouse position */
					x = (msgbuf.MouseX-gui.left) / XSIZE;
					y = (msgbuf.MouseY-gui.top) / YSIZE;
					if(x < 0) x =  0; if(x >= gui.nbcol)  x = gui.nbcol-1;
					if(y < 0) y = -1; if(y >  gui.nbline) y = gui.nbline;
					edit->nbrwc = (x += edit->left_pos);
					y += (LONG)edit->top_line;
					if( x != edit->ccp.xc || y != edit->ccp.yc )
						/* Move the selected stream */
						if( !(state = move_selection(edit,x,y)) )
							set_cursor_line(edit, y, edit->top_line),
							inv_curs(edit,TRUE);
				}
			}
		}	/* endif: arrow gadget pressed or autoscroll */
	}
}