Overloading mouse events in a ProgressBar

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Overloading mouse events in a ProgressBar

Gtkmm mailing list
I'm deriving from Gtk::ProgressBar in order to track mouse events within
the widget. The only callback that executes is on_map(). Can anyone tell
me what vital (and likely obvious) operation I've failed to include?

// g++ -o test test.cc `pkg-config gtkmm-3.0 --cflags --libs`

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

class CProgressBar : public Gtk::ProgressBar
{
public:
     explicit        CProgressBar ();
protected:
     virtual bool    on_button_press_event ( GdkEventButton* pEvent );
     virtual bool    on_enter_notify_event ( GdkEventCrossing* pEvent );
     virtual bool    on_leave_notify_event ( GdkEventCrossing* pEvent );
     virtual void    on_map ();
     virtual bool    on_motion_notify_event ( GdkEventMotion* pEvent );
};

class CTest : public Gtk::ApplicationWindow
{
public:
     CTest();
protected:
     CProgressBar* m_pBar;
};

CTest::CTest ()
{
     m_pBar = Gtk::manage ( new CProgressBar () );
     add ( *m_pBar );
     set_position ( Gtk::WIN_POS_CENTER );
     show_all_children ();
}

CProgressBar::CProgressBar ()
{
     set_hexpand ();
     set_margin_bottom ( 30 );
     set_margin_end ( 30 );
     set_margin_top ( 30 );
     set_margin_start ( 30 );
     set_fraction ( 0.5 );
}

bool CProgressBar::on_button_press_event ( GdkEventButton* pEvent )
{
     Gtk::ProgressBar::on_button_press_event ( pEvent );
     std::cout << "Click @ " << pEvent->x << std::endl;
     return ( false );
}

bool CProgressBar::on_enter_notify_event ( GdkEventCrossing* pEvent )
{
     Gtk::ProgressBar::on_enter_notify_event ( pEvent );
     std::cout << "Enter @ " << pEvent->x << std::endl;
     return ( false );
}

bool CProgressBar::on_leave_notify_event ( GdkEventCrossing* pEvent )
{
     Gtk::ProgressBar::on_leave_notify_event ( pEvent );
     std::cout << "Leave @ " << pEvent->x << std::endl;
     return ( false );
}

void CProgressBar::on_map ()
{
     Gtk::ProgressBar::on_map ();
     Glib::RefPtr<Gdk::Window > refWindow = get_window ();
     Gdk::EventMask mask = refWindow->get_events ();
     mask |= Gdk::ENTER_NOTIFY_MASK | Gdk::LEAVE_NOTIFY_MASK |
Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_PRESS_MASK;
     refWindow->set_events ( mask );
}

bool CProgressBar::on_motion_notify_event ( GdkEventMotion* pEvent )
{
     Gtk::ProgressBar::on_motion_notify_event ( pEvent );
     std::cout << "Move to " << pEvent->x << std::endl;
     return ( false );
}

int main ( int argc, char *argv[] )
{
     Glib::RefPtr<Gtk::Application> app = Gtk::Application::create (
"org.gtkmm.example" );
     CTest test;
     return app->run ( test );
}

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Overloading mouse events in a ProgressBar

Rob Pearce-2
On 06/08/2019 14:50, Phil Wolff via gtkmm-list wrote:
> I'm deriving from Gtk::ProgressBar in order to track mouse events
> within the widget. The only callback that executes is on_map(). Can
> anyone tell me what vital (and likely obvious) operation I've failed
> to include?
>
I don't know if this still applies on GTK3 but on earlier versions ISTR
that display widgets (like progress bar) usually aren't sensitive to
mouse events because they have no reason to be. On X11 that also means
they don't have the necessary X type. You have to wrap them in an event
box and hook up to that instead.

HTH,

Rob

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Overloading mouse events in a ProgressBar

Gtkmm mailing list
yup, that sounds about right. only in GTK 4 will that change and all widgets be able to receive all events.

...although also there, it is encouraged more to use gestures and whatnot, and the events that remain have proper API instead of poking around directly in event structures.

On Wed, 7 Aug 2019, 05:09 Rob Pearce, <[hidden email]> wrote:
On 06/08/2019 14:50, Phil Wolff via gtkmm-list wrote:
> I'm deriving from Gtk::ProgressBar in order to track mouse events
> within the widget. The only callback that executes is on_map(). Can
> anyone tell me what vital (and likely obvious) operation I've failed
> to include?
>
I don't know if this still applies on GTK3 but on earlier versions ISTR
that display widgets (like progress bar) usually aren't sensitive to
mouse events because they have no reason to be. On X11 that also means
they don't have the necessary X type. You have to wrap them in an event
box and hook up to that instead.

HTH,

Rob

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Overloading mouse events in a ProgressBar

Gtkmm mailing list
In reply to this post by Rob Pearce-2
Bingo! Thanks for the tip.

On 8/6/19 12:36 PM, Rob Pearce wrote:

> On 06/08/2019 14:50, Phil Wolff via gtkmm-list wrote:
>> I'm deriving from Gtk::ProgressBar in order to track mouse events
>> within the widget. The only callback that executes is on_map(). Can
>> anyone tell me what vital (and likely obvious) operation I've failed
>> to include?
>>
> I don't know if this still applies on GTK3 but on earlier versions
> ISTR that display widgets (like progress bar) usually aren't sensitive
> to mouse events because they have no reason to be. On X11 that also
> means they don't have the necessary X type. You have to wrap them in
> an event box and hook up to that instead.
>
> HTH,
>
> Rob
>
> _______________________________________________
> gtkmm-list mailing list
> [hidden email]
> https://mail.gnome.org/mailman/listinfo/gtkmm-list
_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list