- initializer
- self#set_font_size !current_font_size;
- ignore (self#connect#selection_changed self#choose_selection);
- ignore (self#event#connect#button_press self#button_press);
- ignore (self#event#connect#button_release self#button_release);
-(* ignore (self#connect#click (fun (gdome_elt, _, _, _) ->
- match gdome_elt with
- | Some elt |+ element is an hyperlink, use href_callback on it +|
- when elt#hasAttributeNS ~namespaceURI:DomMisc.xlink_ns ~localName:href ->
- (match href_callback with
- | None -> ()
- | Some f ->
- let uri =
- elt#getAttributeNS ~namespaceURI:DomMisc.xlink_ns ~localName:href
- in
- f (uri#to_string))
- | Some elt -> ignore (self#action_toggle elt)
- | None -> ())) *)
-
- val mutable button_press_x = -1.
- val mutable button_press_y = -1.
- val mutable selection_changed = false
-
- method private button_press gdk_button =
- if GdkEvent.Button.button gdk_button = left_button then begin
- button_press_x <- GdkEvent.Button.x gdk_button;
- button_press_y <- GdkEvent.Button.y gdk_button;
- selection_changed <- false
- end;
- false
-
- method private button_release gdk_button =
- if GdkEvent.Button.button gdk_button = left_button then begin
- let button_release_x = GdkEvent.Button.x gdk_button in
- let button_release_y = GdkEvent.Button.y gdk_button in
- (if near (button_press_x, button_press_y)
+class clickableMathView obj =
+let text_width = 80 in
+object (self)
+ inherit GMathViewAux.multi_selection_math_view obj
+
+ val mutable href_callback: (string -> unit) option = None
+ method set_href_callback f = href_callback <- f
+
+ val mutable _cic_info = None
+ method private set_cic_info info = _cic_info <- info
+ method private cic_info = _cic_info
+
+ initializer
+ self#set_font_size !current_font_size;
+ ignore (self#connect#selection_changed self#choose_selection_cb);
+ ignore (self#event#connect#button_press self#button_press_cb);
+ ignore (self#event#connect#button_release self#button_release_cb);
+ ignore (self#event#connect#selection_clear self#selection_clear_cb);
+ ignore (self#coerce#misc#connect#selection_get self#selection_get_cb)
+
+ val mutable button_press_x = -1.
+ val mutable button_press_y = -1.
+ val mutable selection_changed = false
+
+ method private selection_get_cb ctxt ~info ~time =
+ (match self#get_selections with
+ | [] -> ()
+ | node :: _ -> ctxt#return (self#string_of_node node))
+
+ method private selection_clear_cb sel_event =
+ self#remove_selections;
+ false
+
+ method private button_press_cb gdk_button =
+ let button = GdkEvent.Button.button gdk_button in
+ if button = left_button then begin
+ button_press_x <- GdkEvent.Button.x gdk_button;
+ button_press_y <- GdkEvent.Button.y gdk_button;
+ selection_changed <- false
+ end else if button = right_button then
+ self#popup_contextual_menu (GdkEvent.Button.time gdk_button);
+ false
+
+ method private popup_contextual_menu time =
+ match self#string_of_selection with
+ | None -> ()
+ | Some s ->
+ let clipboard = GData.clipboard Gdk.Atom.clipboard in
+ let menu = GMenu.menu () in
+ let copy_menu_item =
+ GMenu.image_menu_item
+ ~label:"_Copy" ~stock:`COPY ~packing:menu#append ()
+ in
+ connect_menu_item copy_menu_item (fun () -> clipboard#set_text s);
+ menu#popup ~button:right_button ~time
+
+ method private button_release_cb gdk_button =
+ let clipboard = GData.clipboard Gdk.Atom.primary in
+ if GdkEvent.Button.button gdk_button = left_button then begin
+ let button_release_x = GdkEvent.Button.x gdk_button in
+ let button_release_y = GdkEvent.Button.y gdk_button in
+ if selection_changed then
+ ()
+ else (* selection _not_ changed *)
+ if near (button_press_x, button_press_y)