[comp.windows.open-look] XView textsw question

straw@cam.nist.gov (Mike Strawbridge) (12/21/90)

I am interposing a Text Subwindow to catch mouse events in the window. In
the interposing function how can I calculate the mouse location in terms of
a character index or line index in the Text Subwindow?

-----------------------------------------------------------------------
NAME:   Michael Strawbridge             	TELE: (301) 975-3852
USMAIL: National Institute of Standards 	ARPA: straw@cam.nist.gov
		and Technology            	UUCP: uunet!cme-durer!straw
        Rm. B-146, Bldg. 225
        Gaithersburg, MD  20899

barnett@grymoire.crd.ge.com (Bruce Barnett) (12/21/90)

In article <6336@pizza.cam.nist.gov> straw@cam.nist.gov (Mike Strawbridge) writes:

>   I am interposing a Text Subwindow to catch mouse events in the window. In
>   the interposing function how can I calculate the mouse location in terms of
>   a character index or line index in the Text Subwindow?

My xvttool program (on titan.rice.edu) does this. If you type
Control-LeftButton, it sends a special sequence to the program running
in the tty window. The client understands the escape sequence and
positions the cursor at the location of the mouse click. (The only
client that understands this so far is Mike Gerard's 3270 emulator)

Here is the appropriate code. - first get the height and width of the font.

	font_height = (int)xv_get (terminal_sw, WIN_ROW_HEIGHT);
	font_width = (int)xv_get (terminal_sw, WIN_COLUMN_WIDTH);
	if ( debug && verbose ) 
	  Fprintf(console," Pixel Width: %d, height: %d\n", 
		  font_width, font_height);

and in the event handler: (The || is because of a
different between OW 2.0 pre-fcs and OW 2.0)

    if (event_is_button(event) && 
	(event_left_is_down(event) || (event_id(event) == BUT(1))) &&
	event_ctrl_is_down (event)  ) { 
	column = (event_x(event) / font_width); 
	/* the first line would be 0 - we'll add one to it */
	line = (event_y(event) / font_height) +1;
	if (debug) Fprintf(console, "Mouse at [%d(%d),%d(%d)]\n",
			   line, event_y(event), column, event_x(event));


--
Bruce G. Barnett	barnett@crd.ge.com	uunet!crdgw1!barnett