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,>k_fixed::on_mouse_press));
add_events(Gdk::BUTTON_RELEASE_MASK);
signal_button_release_event().connect(sigc::mem_fun(*this,>k_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!!