[gnomemm] Gnome::Canvas::Canvas problem dragging text item



I'm trying to drag some Gnome::Canvas::Canvas' items. The Rect and
Pixbuf items works fine, but the Text items not. 

I can drag Text items, the problem appears when i release them up the
coordinate y 100 approx, then Text item will not receive more events.This not
occurs with the Rect and Pixbuf items.

Perhaps i'm doing something wrong or my libgnomecanvasmm/libgnomecanvas
has some bugs... I've upgrated from libgnomecanvas-2.0 2.0.2 to 2.3.0
but the problem is still here.

$ pkg-config libgnomecanvas-2.0 --modversion
2.3.0

$ pkg-config libgnomecanvasmm-2.0 --modversion
1.3.11

$ pkg-config gtkmm-2.0 --modversion
2.0.0

a little example is attached.


Thanks!



#include <gtkmm/box.h>

#include <libgnomecanvasmm/canvas.h>
#include <libgnomecanvasmm/item.h>
#include <libgnomecanvasmm/rect.h>
#include <libgnomecanvasmm/text.h>
#include <libgnomecanvasmm/canvas-property.h>
#include <libgnomecanvasmm/init.h>

#include <gtkmm/main.h>
#include <gtkmm/window.h>
#include <gtkmm/scrolledwindow.h>

#include <glibmm/main.h>

#include <gdkmm/cursor.h>

#include <iostream>

using namespace Gnome::Canvas::Properties;
using namespace Gnome::Canvas;
using namespace  std;


//class MyCanvas: public Gnome::Canvas::CanvasAA
class MyCanvas: public Gnome::Canvas::Canvas
{
public:
    MyCanvas () : 
		fleur_(Gdk::FLEUR),
		dragging_(false)
	{
		set_scroll_region(0,0,1000,1000);
		
		//Draw a Rectangle
		item_ = manage(new Gnome::Canvas::Rect (*root(), 0, 0,  100, 100));
		*item_ << width_pixels (5) << outline_color ("red");		
		item_->signal_event().connect(SigC::bind(SigC::slot(*this, &MyCanvas::itemEvent), item_));
			
		//Draw a simple text
		item_ = manage(new Gnome::Canvas::Text(*root(), 120, 120,  Glib::locale_to_utf8("Hello World!")));
		*item_ << fill_color ("blue") << font("Arial 20");		
		item_->signal_event().connect(SigC::bind(SigC::slot(*this, &MyCanvas::itemEvent), item_));		
	}
private:
	
	bool itemEvent(GdkEvent* event, Gnome::Canvas::Item* item) 
	{		
		cout << "Event" << endl;
		
		double item_x, item_y;

		item_x = event->button.x;
		item_y = event->button.y;		
		
		switch (event->type) 
		{			
			case GDK_BUTTON_PRESS:
			{
				switch(event->button.button) 
				{
					case 3:
					{
						item_ = item;

						x_ = item_x;
						y_ = item_y;
										  
						item_->raise_to_top();								
						item_->grab(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, fleur_, event->button.time);
						dragging_ = true;
					}										
					break;
				}
			}
			break;
		
			case GDK_MOTION_NOTIFY:
			{
				if (dragging_ && (event->motion.state & GDK_BUTTON3_MASK)) 
				{
					item_->move(item_x - x_, item_y - y_);
					x_ = item_x;
					y_ = item_y;
				}
			}
			break;
				
			case GDK_BUTTON_RELEASE:
			{
				cout << "x: " << item_x << " y: " << item_y << endl;
				item_->ungrab(event->button.time);
				dragging_ = false;
			}
			break;
			  
			default:
			break;			
		}
		
		return true;
	}
		
	Gnome::Canvas::Item *item_;	
	Gdk::Cursor fleur_;	
	bool dragging_;
	double x_, y_;
};





class MyWindow: public Gtk::Window
{
	public:
		MyWindow()
		{
			add(scrolledWindow_);
	
			scrolledWindow_.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);					
			
			scrolledWindow_.add(canvas_);
				
			set_resizable(false);
			set_size_request(400,300);
			show_all_children();
		}
		~MyWindow() {}
	private:
		MyCanvas canvas_;
		Gtk::ScrolledWindow scrolledWindow_;
};



int main (int argc, char **argv)
{
    Gtk::Main m (argc, argv);
    Gnome::Canvas::init ();
    
	MyWindow w;
	m.run(w);
}


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