Overloading mouse events in a ProgressBar
- From: Phil Wolff <adiabat centurylink net>
- To: "gtkmm-list gnome org" <gtkmm-list gnome org>
- Subject: Overloading mouse events in a ProgressBar
- Date: Tue, 6 Aug 2019 06:50:08 -0700
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 );
}
[Date Prev][
Date Next] [Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]