This is the mail archive of the
guile-gtk@sourceware.cygnus.com
mailing list for the Guile project.
Re: Right mouse click on buttons?
- To: Marius Vollmer <mvo at zagadka dot ping dot de>
- Subject: Re: Right mouse click on buttons?
- From: Stephen Tell <tell at cs dot unc dot edu>
- Date: Sun, 5 Dec 1999 10:47:34 -0500 (EST)
- cc: "Greg J. Badros" <gjb at cs dot washington dot edu>, guile-gtk at sourceware dot cygnus dot com
On 5 Dec 1999, Marius Vollmer wrote:
> "Greg J. Badros" <gjb@cs.washington.edu> writes:
>
> > Anybody know how to make GTk+ generate a signal on a right-mouse
> > click on a button (or a button-bar)?
> Try the "button_press_event" signal, like so
> (gtk-signal-connect b "button_press_event"
> (lambda (ev)
For a context-sensitive popup menu out of such an event, build the menu in
the event handler, and use gtk-menu-popup. In this code, I put the actual
gtk-signal-connect in C, which calls out to guile on selected events and
passes along a context object. The menu actions are specific to my
program, but you get the idea I'm sure.
I've done this for a drawing_area - does the menu pop up in the
correct-looking place when attached to a button?
(wavepanel-bind-mouse 3 ; calls proc on indicated button-press event
(lambda (wp event)
(let ((menu (gtk-menu-new)))
(gtk-widget-show menu)
(add-menuitem menu "Zoom Cursors" x-zoom-cursors!)
(add-menuitem menu "Zoom Area..." x-zoom-area!)
(add-menuitem menu "Zoom Full" x-zoom-full!)
(case (wavepanel-type wp)
((0) (add-menuitem menu "Set type jge"
(lambda () (set-wavepanel-type! wp 1))))
((1) (add-menuitem menu "Set type std"
(lambda () (set-wavepanel-type! wp 0)))))
(gtk-menu-popup menu #f #f
(gdk-event-button event)
(gdk-event-time event)))))
; add-menuitem is a little helper to make menu and menubar creation
; a bit more readable.
(define-public (add-menuitem parent label proc)
(let ((item (if label
(gtk-menu-item-new-with-label label)
(gtk-menu-item-new))))
(gtk-widget-show item)
(if proc
(gtk-signal-connect item "activate" proc))
(cond ((gtk-menu? parent) (gtk-menu-append parent item))
((gtk-menu-bar? parent) (gtk-menu-bar-append parent item)))
item))
--
Steve Tell | tell@cs.unc.edu | http://www.cs.unc.edu/~tell | KF4ZPF
Research Associate, Microelectronic Systems Laboratory
Computer Science Department, UNC@Chapel Hill. W:919-962-1845