LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-30-2011, 03:21 PM   #1
Amonith
LQ Newbie
 
Registered: Dec 2011
Posts: 2

Rep: Reputation: Disabled
Question D&D motion event handler called only once. [gtkmm 3 && goocanvasmm (irrelevant)]


Fellow programmers,

I have a little problem and I can't find it's source.
I derived a new class from "Goocanvas::Canvas" (This one inherits Gtk::Container what's important, if you don't use Goocanvas you can still help) called "InteractiveBoard" and overloaded four functions which handle drag & drop events:
  • bool on_drag_motion(const Glib::RefPtr< Gdk::DragContext >& context, int x, int y, guint time)
  • void on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, const Gtk::SelectionData& selData, guint info, guint time)
  • bool on_drag_drop(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, guint time)
  • void on_drag_leave(const Glib::RefPtr<Gdk::DragContext>& context, guint time)

The problem is, "on_drag_motion" is called only once! And it should be called on every mouse movement. The program stops responding after finishing "on_drag_data_received" ("drag_get_data" is called within "on_drag_motion") and ending "on_drag_motion". If I remove "drag_get_data" it works as it should.
If I don't overload "on_drag_data_received" it works too but I need it. If I overload it with empty function, problem exists. It's the proof that the problem lays not in what I've written in my handler but in something I'm missing.
Here are the bodies of these functions:

Code:
bool InteractiveBoard::on_drag_motion(const Glib::RefPtr< Gdk::DragContext >& context, int x, int y, guint time)
{
    std::cerr << "motion -- x: "<<x<<" y: "<<y<<std::endl;
    if(draggedWidget)
    {
        std::cerr << "Dragging widget\n";
        draggedWidgetRefPtr->set_property("x", x);
        draggedWidgetRefPtr->set_property("y", y);
        context->drag_status(Gdk::ACTION_COPY, time);
        std::cerr << "After dragging->set status";
    }
    else
    {
        const Glib::ustring target = drag_dest_find_target(context);

        if(target.empty()) return false;

        requestedData = true;
        dataRequestedForDrop = false;
        std::cerr << "Calling drag_get_data\n";
        drag_get_data(context, target, time);
        std::cerr << "Returned! :)\n";
    }

    std::cerr << "Canvas::on_drag_motion start\n";
    Goocanvas::Canvas::on_drag_motion(context,x,y,time);
    std::cerr << "Canvas::on_drag_motion end\n";
    return true;
}

void InteractiveBoard::on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, const Gtk::SelectionData& selData, guint info, guint time)
{
    std::cerr << "I'm kinda in on_drag_data_received\n";

    if(!draggedWidget)
    {
        std::cerr << "Creating ellipse at "<<x<<" "<<y<<std::endl;
        draggedWidget = true;
        draggedWidgetRefPtr = Goocanvas::Ellipse::create(x,y,50,50);
        get_root_item()->add_child(draggedWidgetRefPtr);
    }

    if(dataRequestedForDrop && draggedWidget)
    {
        std::cerr << "Finishing drag\n";
        context->drag_finish(true, false, time);
    }
    else if(!dataRequestedForDrop && draggedWidget)
    {
        std::cerr << "Calling context->set_status\n";
        context->drag_status(Gdk::ACTION_COPY, time);
        std::cerr << "Called\n";
    }

}

bool InteractiveBoard::on_drag_drop(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, guint time)
{
    std::cerr << "on_drag_drop";
    const Glib::ustring target = drag_dest_find_target(context);

    if(target.empty()) return false;

    dataRequestedForDrop = true;
    drag_get_data(context, target, time);

    return true;
}

void InteractiveBoard::on_drag_leave(const Glib::RefPtr<Gdk::DragContext>& context, guint time)
{
    std::cerr << "on_drag_leave\n";
    if(!draggedWidget) return;

    if(!dataRequestedForDrop)
        draggedWidgetRefPtr->remove();

    draggedWidgetRefPtr.reset();
    draggedWidget = false;

    Goocanvas::Canvas::on_drag_leave(context, time);
}
These functions are almost identical to ones showed in the ToolPallette example from gtkmm book: http://git.gnome.org/browse/gtkmm-do...ette/canvas.cc

Sorry for my bad english. I'm from Poland, but I always try to write with some degree of communicative language. If you find any mistakes please correct me.

I count on your's help! :)

Last edited by Amonith; 01-06-2012 at 09:56 AM. Reason: Added some details.
 
Old 01-06-2012, 09:54 AM   #2
Amonith
LQ Newbie
 
Registered: Dec 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
Found it.

The problem lied in the source ToolPalette, not in the destination widget.
When I registered a destination for my source ToolPalette I had used
Code:
toolPalette->add_drag_dest(*interactiveBoard);
and relied on default paremeters particularly on second argument which was Gtk::DEST_DEFAULT_ALL.
This one caused the problem. I have absolutely no idea why, so if anyone can explain meaning of the Gtk::DestDefaults enum it would be great.

Anyway, I changed the above mentioned line of code to:
Code:
toolPalette->add_drag_dest(*interactiveBoard, Gtk::DEST_DEFAULT_HIGHLIGHT);
and it works as it should earlier.

Last edited by Amonith; 01-06-2012 at 09:55 AM. Reason: Unwanted smilies
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with linux event handler linux88 Linux - Server 3 09-18-2008 12:20 PM
Nagios Event Handler issue lil_drummaboy Linux - Networking 3 02-29-2008 03:03 AM
Error with "SDL_MouseMotionEvent *motion = event->motion;" aatwell Programming 3 11-30-2007 01:46 PM
Gtkmm / UIManager / passing info to event handler cheeseplz Programming 4 10-18-2007 11:33 PM
howto know whether a function is called in signal handler snowing Programming 1 11-07-2005 09:55 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration