This is the mail archive of the guile-gtk@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Right mouse click on buttons?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]