GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Nov 01, 2014 4:53 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Gtk::EventBox not propogating mouse events
PostPosted: Sun Jul 29, 2012 4:26 pm 
Offline
GTK+ Geek

Joined: Sun Apr 03, 2011 11:12 am
Posts: 63
Hello everyone, here's a problem with my program. main_window contains Gtk::EventBox(eventbox1), it contains Gtk::Frame, which contains another Gtk::EventBox(eventbox2), which contains Gtk::Notebook, which contains a page with my custom made container gtk_fixed. The problem is gtk_fixed doesn't propagate the mouse pressed and released events to eventbox1. Here's the code

Object Hierarchy
Code:
main_window : Gtk::Window
    eventbox1 : Gtk::EventBox   
        frame    : Gtk::Frame
            eventbox2 : Gtk::EventBox
                notebook : Gtk::Notebook
                    fixed : gtk_fixed (my custom made Gtk::Container widget)

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

class gtk_fixed : public Gtk::Container
{
    public:
        gtk_fixed();
        virtual ~gtk_fixed();       
    protected:
        virtual void on_size_request(Gtk::Requisition* requisition);
        virtual void on_size_allocate(Gtk::Allocation& allocation);
        virtual void on_map();
        virtual void on_unmap();
        virtual void on_realize();
        virtual void on_unrealize();       
       
        virtual GtkType child_type_vfunc() const;
        bool on_mouse_press(GdkEventButton* event);
        bool on_mouse_release(GdkEventButton* event);
   
        Glib::RefPtr<Gdk::Window> m_refGdkWindow;       
        int x_new,y_new;         
    };

gtk_fixed::gtk_fixed()
{
    set_flags(Gtk::NO_WINDOW);
    add_events(Gdk::BUTTON_PRESS_MASK);
    signal_button_press_event().connect(sigc::mem_fun(*this,&gtk_fixed::on_mouse_press));
    add_events(Gdk::BUTTON_RELEASE_MASK);
    signal_button_release_event().connect(sigc::mem_fun(*this,&gtk_fixed::on_mouse_release));   
    }

gtk_fixed::~gtk_fixed(){}

bool gtk_fixed::on_mouse_press(GdkEventButton* event)
{
    std::cout<<"FIXED MOUSE PRESSED"<<std::endl;
    return false;
    }

bool gtk_fixed::on_mouse_release(GdkEventButton* event)
{
    std::cout<<"FIXED MOUSE RELEASED"<<std::endl;
    return false;
    }
void gtk_fixed::on_size_request(Gtk::Requisition* requisition)
{
    *requisition = Gtk::Requisition();
    requisition->height = 200;
    requisition->width = 200;       
   }

void gtk_fixed::on_size_allocate(Gtk::Allocation& allocation)
{
    set_allocation(allocation);   
   
    if(m_refGdkWindow)
        m_refGdkWindow->move_resize(allocation.get_x(), allocation.get_y(),allocation.get_width(),allocation.get_height());
    }

GtkType gtk_fixed::child_type_vfunc() const
{
        return Gtk::Widget::get_type();
        }
   
void gtk_fixed::on_map()
{
    Gtk::Widget::on_map();
    }

void gtk_fixed::on_unmap()
{
    Gtk::Widget::on_unmap();
    }

void gtk_fixed::on_realize()
{
    Gtk::Widget::on_realize();
    ensure_style();
   
    if(!m_refGdkWindow)
    {
        GdkWindowAttr attributes;
        memset(&attributes, 0, sizeof(attributes));
        Gtk::Allocation allocation = get_allocation();
       
        attributes.x = allocation.get_x();
        attributes.y = allocation.get_y();
        attributes.width = allocation.get_width();
        attributes.height = allocation.get_height();
       
        attributes.event_mask = get_events() | Gdk::EXPOSURE_MASK;
        attributes.window_type = GDK_WINDOW_CHILD;
        attributes.wclass = GDK_INPUT_OUTPUT;
       
        m_refGdkWindow = Gdk::Window::create(get_window(),&attributes,GDK_WA_X|GDK_WA_Y);
        unset_flags(Gtk::NO_WINDOW);
        set_window(m_refGdkWindow);
        m_refGdkWindow->set_user_data(gobj());
        }
    }

void gtk_fixed::on_unrealize()
{
    m_refGdkWindow.clear();
    Gtk::Widget::on_unrealize();
    }

class main_window : public Gtk::Window
{
    public:
        main_window();
        ~main_window();
        Gtk::EventBox eventbox1,eventbox2;
        Gtk::Frame frame;
        Gtk::Notebook notebook;
        gtk_fixed fixed;
        bool on_mouse_pressed(GdkEventButton *event);
        bool on_mouse_released(GdkEventButton *event);
    };
bool main_window::on_mouse_pressed(GdkEventButton *event)
{
    std::cout<<"pressed"<<std::endl;
    return false;
    }

bool main_window::on_mouse_released(GdkEventButton *event)
{
    std::cout<<"released"<<std::endl;
    return false;
    }

main_window::main_window()
:eventbox1(),eventbox2(),frame("FRAME"),notebook(),fixed()
{
    add(eventbox1);
    eventbox1.add(frame);
    frame.add(eventbox2);
    eventbox2.add(notebook);
    notebook.append_page(fixed);   
   
    add_events(Gdk::BUTTON_PRESS_MASK);
    add_events(Gdk::BUTTON_RELEASE_MASK);   
   
    eventbox1.add_events(Gdk::BUTTON_PRESS_MASK);
    eventbox1.add_events(Gdk::BUTTON_RELEASE_MASK);
    eventbox1.signal_button_press_event().connect(sigc::mem_fun(*this,&main_window::on_mouse_pressed));
    eventbox1.signal_button_release_event().connect(sigc::mem_fun(*this,&main_window::on_mouse_released));
     
    show_all_children();
    }

main_window::~main_window(){}

int main(int argc, char *argv[])
{
    Gtk::Main kit(argc,argv);   
    main_window window;
    Gtk::Main::run(window);
    return 0;
}


Pls help!!


Top
 Profile  
 
 Post subject: Re: Gtk::EventBox not propogating mouse events
PostPosted: Thu Aug 02, 2012 7:39 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 768
Location: UK
Hi,

You do not say which version of gtkmm you are using and I am unable to compile your example so will go by what you are saying.

I expect that the Gtk::Notebook is catching the button pressed and release events and not passing them on as it has then handled these events.

You may want to review why you are using Gtk::EventBox as there are better ways of doing many high level actions.

_________________
E.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group