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
fgreco@dprg-330.GOVt.shearson.COM (Frank Greco) (12/24/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? > This is determined from the XY of the mouse and the font dimensions (mostly just the font height) of the TEXTSW's font. e.g., To get the on-screen line number, call this little ditty from your event proc, passing the view and the mouse XY. int getscreenline(tswv, x, y) Textsw tswv; /* Which text subwindow (view) */ int x, y; /* Coordinates of mouse */ { Xv_font font; /* Font of the textsw */ Font_string_dims strdims; if ( !(font = (Xv_font) xv_get(tswv, TEXTSW_FONT)) ) return -1; (void) xv_get(font, FONT_STRING_DIMS, "abcde", &strdims); return y / strdims.height; } Of course, you add the line # of the first viewable line in the TEXTSW to this number to get the overall line #. Getting the character index is done similarly. Frank G.