From: Olivier Andrieu MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <16355.8721.795161.532146 at akasha.ijm.jussieu.fr> Date: Fri, 19 Dec 2003 17:06:41 +0100 To: stalkern2 at tin.it Cc: lablgtk at kaba.or.jp Subject: Re: About automatic column sorting and right-click detection In-Reply-To: <200312191550.35477.stalkern2 at tin.it> References: <200312171132.49128.stalkern2 at tin.it> <16352.20548.48550.69416@akasha.ijm.jussieu.fr> <200312191550.35477.stalkern2@tin.it> Stalkern 2 [Friday 19 December 2003] : > > Il Wednesday 17 December 2003 13:47, Olivier Andrieu ha scritto: > > > 2) How do I recognize a right-clicking on a button or a drawing > > > area? I'm getting a bit puzzled by events and signals (and types > > > with type variables like GtkSignal.t) > > > > All event-related methods and signals are in an #event sub-object. So, > > with > > button#event#connect#button_press callback > > you should be able to detect righ-clicks. > > > > Note that sometimes you have to modify the event mask so that the > > events you're interested in are reported : button#event#add . > > I'm trying to work out right-clicking driven actions on a > GTree.view. However, I'd need to set my ideas clearer about these > issues: > > 1_ GTree.tree (and GList.clist, and several classes in GBin) > has a #event subobject, but GTree.view has not Yes, this has been discussed recently on this list. GTree.view _should_ have an #event suboject (and will have in the next version of lablGTK). You can easily work around this by creating the event object directly : let make_event w = new GObj.event_ops w#as_widget > 2_ If I set a event_box besides setting GTree.view, and I pack > GTree.view in it, I "hide" it so the "button pressed" event never > reaches it Well, you just don't need to use an event box because GTree.view is capable of receiving event signals, but I guess you could make it do what you want. > 3_ The example > http://www.gtkmm.org/gtkmm2/docs/tutorial/html/ch08s07.html#id2879790 > suggests wrapping the default handler for GTree.view. I'd love to > do so, but where is it? If callbacks where all event-to-unit > functions, it'd be so easy to overload them, but when they're > unit-to-unit functions, what can be done? The GtkTreeView default signal handler for the button-press-event signal is run *after* user-connected handlers (like all event-related default handlers I believe). Now, if you want to "override" this default handler, you have to connect your own handler and have it stop the signal emission by calling GtkSignal.stop_emit (). The effect is that your handler is run and the default handler is not. > 4_ To connect a signal to an object, one can use > GtkSignal.connect etc. To create (well, pick in a list) an event, > one can use GdkEvent.create. But how do I create a Signal? How do I > listen to an event and have it trigger the emission of that signal? You usually connect a signal with a #connect subobject ; you should not need to use GtkSignal.connect directly. As for events, you usually don't manipulate them directly. The main loop processes events and dispatches them to the appropriate widgets using signals. So, you merely connect a signal like button-press-event : that's the way to "listen" to a button event. A good source of information concerning these mechanisms is `GTK+ / Gnome Application Development', a book by Havoc Pennington available here: http://developer.gnome.org/doc/GGAD/ggad.html (see the chapters about `GDK Basics' and `The GTK+ Object and Type System'). The book is about GTK/GNOME 1.x but these chapters about the internals of GTK+ are still valid. > Actually, I can not understand whether I can do that with the > standard distribution of LablGtk2.2. Everything seems so > close... yet so far. Well, you didn't clearly state what you want to do :). This, I guess, should be close to what you want to do : let make_event w = new GObj.event_ops w#as_widget (make_event you_tree_view_widget)#connect#button_press (fun ev -> if GdkEvent.Button.button ev = 3 then begin (* right mouse button click *) (* do something ... *) (* stop signal emission, ie override the default handler *) GtkSignal.stop_emit () ; (* stop propagation of the signal *) true end else begin (* other mouse button click *) (* maybe do something *) false end) -- Olivier