[gtkmm] Mouse problems



Hi,

I'm having a little trouble with keyboard and mouse events at the moment, and if anyone out there could help I would be most grateful. Firstly, the program below is supposed to catch mouse movement and mouse clicks, but it doesn't (none of the messages are ever printed), and I have no idea why. I also don't understand why only the root widget sees keyboard events - if I try to capture keyboard events in a child widget, regardless of whether it is in focus or not, it cannot receive keyboard input.

If anyone can provide enlightenment to my situation I would be most grateful! Thanks in advance

Ben Stephens

-----------------------------------------------------------------------------

#include <gtkmm/widget.h>
#include <gtkmm/window.h>
#include <gtkmm/main.h>
#include <iostream>
using namespace std;

class MainWindow : public Gtk::Window
{
	public:
		MainWindow();
		bool testfunc(GdkEventButton *event);
		
	protected:
		virtual bool on_button_press_event(GdkEventButton *event);
		virtual bool on_key_press_event(GdkEventKey *event);
		virtual bool on_motion_notify_event(GdkEventMotion* event);
};

MainWindow::MainWindow()
{
	// Shouldn't be neccessary, but I have no better ideas...
	signal_button_press_event().connect(SigC::slot(*this, &MainWindow::testfunc));
}

// This is never called
bool MainWindow::testfunc(GdkEventButton *event)
{
	cout << "Button pressed - testfunc" << endl;
	return false;
}

// Nor is this
bool MainWindow::on_button_press_event(GdkEventButton *event)
{
	cout << "Button pressed" << endl;
	
	Gtk::Widget::on_button_press_event(event);
	return false;
}

// Works fine
bool MainWindow::on_key_press_event(GdkEventKey *event)
{
	cout << "Key pressed" << endl;
	
	Gtk::Widget::on_key_press_event(event);
	return false;
}

// Also never called
bool MainWindow::on_motion_notify_event(GdkEventMotion* event)
{
	cout << "Motion detected" << endl;
	
	Gtk::Widget::on_motion_notify_event(event);
	return false;
}

int main(int argc, char **argv)
{
	Gtk::Main kit(argc, argv);
	MainWindow wind;
	Gtk::Main::run(wind);
	return(0);
}

********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************



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