on_unmap not called?



I have noticed that the on_unmap() and on_unmap_event() methods are
not called on my widget when the main window is closed.

In attachment you can find a simple example with a "noisy" widget that
prints info about the called events, and the "unmap" methods are not
called when you close the window. Why is it so?

Thanks

O.
#include "NoisyWidget.h"
#include <gtkmm.h>
#include <glibmm.h>
#include <iostream>

NoisyWidget *mNoisy1;

int main(int argc, char** argv)
{
	Gtk::Main kit(argc, argv);

	mNoisy1 = new NoisyWidget();	
	mNoisy1->show();

	Gtk::Window win1;
	win1.set_title("Noisy");
	win1.set_size_request(300, 300);
	win1.add(*mNoisy1);
	win1.show();

	Gtk::Main::run(win1);
	//Gtk::Main::run();
 
	return 0;
}
#include "NoisyWidget.h"

#include <iostream>
#include <cmath>
#include <cstdio>
#include <gdk/gdkx.h>

NoisyWidget::NoisyWidget()
{
	add_events(Gdk::ALL_EVENTS_MASK);
	set_flags(get_flags() | Gtk::CAN_FOCUS);
}

void NoisyWidget::on_realize()
{
	std::cout << "on_realize()\n";
	Gtk::DrawingArea::on_realize();
}

bool NoisyWidget::on_expose_event(GdkEventExpose* event)
{
	std::cout << "on_expose_event()\n";
	return Gtk::DrawingArea::on_expose_event(event);
}

void NoisyWidget::on_map () 
{
	std::cout << "on_map()\n";
	Gtk::DrawingArea::on_map();
}

bool NoisyWidget::on_map_event (GdkEventAny* event)
{
	std::cout << "on_map_event()\n";
	return Gtk::DrawingArea::on_map_event(event);
}

void NoisyWidget::on_unmap ()
{
	std::cout << "on_unmap()\n";
	Gtk::DrawingArea::on_unmap();
}

bool NoisyWidget::on_unmap_event (GdkEventAny* event)
{
	std::cout << "on_unmap_event()\n";
	return Gtk::DrawingArea::on_unmap_event(event);
}

void NoisyWidget::on_unrealize ()
{
	std::cout << "on_unrealize()\n";
	Gtk::DrawingArea::on_unrealize();
}

void NoisyWidget::on_show()
{
	std::cout << "on_show()\n";
	Gtk::DrawingArea::on_show();
}

void NoisyWidget::on_hide()
{
	std::cout << "on_hide()\n";
	Gtk::DrawingArea::on_hide();
}

bool NoisyWidget::on_configure_event (GdkEventConfigure* event)
{
	std::cout << "on_configure_event()\n";
	std::cout << "   x, y = " << event->x << ", " << event->y << std::endl;
	std::cout << "   w, h = " << event->width << ", " << event->height << std::endl;
	return Gtk::DrawingArea::on_configure_event(event);
}

void NoisyWidget::on_size_allocate(Gtk::Allocation& allocation)
{
	std::cout << "on_configure_event()\n";
	std::cout << "   x, y = " << allocation.get_x() << ", " << allocation.get_y() << std::endl;
	std::cout << "   w, h = " << allocation.get_width() << ", " << allocation.get_height() << std::endl;
	Gtk::DrawingArea::on_size_allocate(allocation);
}

bool NoisyWidget::on_delete_event (GdkEventAny* event)
{
	std::cout << "on_delete_event()\n";
	return Gtk::DrawingArea::on_delete_event(event);
}

bool NoisyWidget::on_button_press_event (GdkEventButton* event) 
{
	std::cout << "on_button_press_event()\n";
	return Gtk::DrawingArea::on_button_press_event(event);
}

bool NoisyWidget::on_button_release_event (GdkEventButton* event) 
{
	std::cout << "on_button_release_event()\n";
	return Gtk::DrawingArea::on_button_release_event(event);
}

bool NoisyWidget::on_motion_notify_event (GdkEventMotion *event)
{
	//	std::cout << "on_motion_notify_event()\n";
	//	std::cout << "   x, y = " << event->x << ", " << event->y << std::endl;
	//	std::cout << "   " << event->time << std::endl;
	return Gtk::DrawingArea::on_motion_notify_event(event);
}

bool NoisyWidget::on_enter_notify_event(GdkEventCrossing* pEvent)
{
	std::cout << "on_enter_notify_event()\n";
	std::cout << "   state = " << pEvent->state << std::endl;
	return Gtk::DrawingArea::on_enter_notify_event(pEvent);
}

bool NoisyWidget::on_leave_notify_event(GdkEventCrossing* pEvent)
{
	std::cout << "on_leave_notify_event()\n";
	std::cout << "   state = " << pEvent->state << std::endl;
	return Gtk::DrawingArea::on_leave_notify_event(pEvent);
}

bool NoisyWidget::on_key_press_event(GdkEventKey* pEvent)
{
	std::cout << "on_key_press_event()\n";
	return Gtk::DrawingArea::on_key_press_event(pEvent);
}

bool NoisyWidget::on_key_release_event(GdkEventKey* pEvent)
{
	std::cout << "on_key_release_event()\n";
	return Gtk::DrawingArea::on_key_release_event(pEvent);
}
#ifndef TOTAL_SCORE_H
#define TOTAL_SCORE_H

#include <gtkmm.h>
#include <gdkmm.h>
#include <vector>
#include <boost/shared_ptr.hpp>

class NoisyWidget : public Gtk::DrawingArea
{
	public:
		NoisyWidget();

	protected:
		virtual void on_realize();
		virtual void on_unrealize ();

		virtual bool on_expose_event(GdkEventExpose* event);
		virtual void on_size_allocate(Gtk::Allocation& allocation);

		virtual void on_map ();
		virtual bool on_map_event (GdkEventAny* event);
		virtual void on_unmap ();
		virtual bool on_unmap_event (GdkEventAny* event);

		virtual void on_show ();
		virtual void on_hide ();

		virtual bool on_configure_event (GdkEventConfigure* event);
		virtual bool on_delete_event (GdkEventAny* event);

		virtual bool on_button_press_event (GdkEventButton* event);
		virtual bool on_button_release_event (GdkEventButton* event);

		virtual bool on_motion_notify_event (GdkEventMotion *event);

		bool on_enter_notify_event(GdkEventCrossing* pEvent);
		bool on_leave_notify_event(GdkEventCrossing* pEvent);

		bool on_key_press_event(GdkEventKey* pEvent);
		bool on_key_release_event(GdkEventKey* pEvent);
};

#endif // TOTAL_SCORE_H



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]