File: events2.ml

package info (click to toggle)
lablgtk2 2.6.0-7
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,032 kB
  • ctags: 5,191
  • sloc: ml: 27,719; ansic: 7,662; makefile: 532; sh: 83
file content (30 lines) | stat: -rw-r--r-- 835 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(* $Id: events2.ml,v 1.3 2003/06/18 10:04:51 garrigue Exp $ *)

(* See comments in events.ml *)

open GMain

let _ =
  let window = GWindow.window () in
  window#connect#destroy ~callback:Main.quit;

  let text = GText.view ~width:200 ~height:100 ~packing:window#add () in
  text#event#connect#button_press ~callback:
    begin fun ev ->
      GdkEvent.Button.button ev = 3 &&
      GdkEvent.get_type ev = `BUTTON_PRESS &&
      begin
	let win = match text#get_window `WIDGET with
	  | None -> assert false
	  | Some w -> w
	in
	let x,y = Gdk.Window.get_pointer_location win in
	let b_x,b_y = text#window_to_buffer_coords ~tag:`WIDGET ~x ~y in
	let clicked_pos = text#get_iter_at_location ~x:b_x ~y:b_y in
	Printf.printf "Position is %d.\n" clicked_pos#offset;
	flush stdout;
	true;
      end
    end;
  window#show ();
  Main.main ()