From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Tell To: Marius Vollmer Cc: "Greg J. Badros" , guile-gtk@sourceware.cygnus.com Subject: Re: Right mouse click on buttons? Date: Sun, 05 Dec 1999 07:48:00 -0000 Message-id: References: <874sdxhdop.fsf@zagadka.ping.de> X-SW-Source: 1999-q4/msg00058.html On 5 Dec 1999, Marius Vollmer wrote: > "Greg J. Badros" 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