Re: [gtkmm] TreeView widget - Double-Click



On Wed, 18 Dec 2002 18:04:14 +0100
"Sebastian Stark" <stark sebastian gmx de> wrote:

> >>signal_event() and signal_button_press_event().
> Yes I have seen this in the tutorial and tried it. But i don't  know the
> right syntax to use this standard signals for the TreeView.
Well. I don't think Gtk provides convenience functions for working with double-clicks, so one has to come up on his own with a solution.
Yet it should be mentioned that this might not be good in terms of accessibility guidelines.
Anyway here's a way one might go:


#include <gtkmm.h>
#include <iostream>

using namespace std;

bool buttoncallback(GdkEventButton *event);

const long doubleclickdelay = 250000; /* that is, if I am not mistaken, 250 ms */

int main(int argc, char** argv)
{
	Gtk::Main foo(argc, argv);

	Gtk::Window bar;

	bar.signal_button_press_event.connect(SigC::slot(&buttoncallback));

	bar.show_all();

	foo.run(bar);

	return(0);
}

bool buttoncallback(GdkEventButton *event)
{
	static long lastclick = 0;

	if ((event->type == GDK_BUTTON_PRESS) && (event->button == 1))
	{
		/* handle and return true */
		
		if (lastclick == 0 || (lastclick + doubleclickdelay < event->time))
		{
			lastclick = event->time;
		}
		else
		{
			cout << "got doubleclick" << endl ;
		}

		return(true);
	}
	else
	{
		/* not handled, return false */
		return(false);
	}
}

...not tested and with some style issues, yet it should show you how you can do it.

Leslie



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]