Re: Questions on Gtk::Notebook



Murray Cumming wrote:

On Tue, 2005-07-19 at 22:55 +0200, Antonio Coralles wrote:

plain text document attachment (NOTEBOOK.txt)
After deriving my own Gtk::Notebook class, i experienced the following
behavour, for which i want to know, if this is on purpose:

1.) A Gtk::Notebook seems to emit signal_switch_page with a second
parameter 0
when realized. Because i wanted to open a different page by
default, i had
    to override on_realize().

2.) A Gtk::Notebook emits the same signal a few times, when getting
destroyed.
    This led to following warnings glibmm-warnings:

    (duty-roaster:20667): glibmm-WARNING **: Glib::create_new_wrapper:
Attempted to create a 2nd C++ wrapper for a C instance whose C++
wrapper
    has been deleted.

If you can make a test case for this, please add it to bugzilla.

Did you mean a testcase for the above glibmm warning, or for the fact
the signal_switch_page is emited on destruction ? Because the problem
with my code was, that i connected a function to signal_switch_page, which
modified the contens of the page which should be displayed, which isn't
the best to do on destruction ...

However, because i've allready written it, here is an complete example,
which shows clearly, that signal_switch_page is emited (total_pages -
selected_page) times on destruction, if selected_page starts with 1.


#include <gtkmm/notebook.h>
#include <gtkmm/frame.h>
#include <gtkmm/main.h>
#include <gtkmm/window.h>
#include <iostream>
#include <sstream>

using namespace Gtk; using std::cout; using std::endl;
using std::stringstream;

class TestNotebook : public Notebook
{
	public:
	
	TestNotebook() : _destruct(false), _dCount(0)
	{
		init();
		signal_switch_page().connect
		(sigc::mem_fun(*this, &TestNotebook::cb_switchPage));
	}
		
	virtual ~TestNotebook() 
	{ 
		_destruct = true;
		for(unsigned i=0; i != 5; ++i)
			delete _ap_frames[i];
			
	}	

	private:
	
	void init()
	{
		//create our frames and append them to our notebook
		for(unsigned i=0; i != 5; ++i)
		{
			stringstream hStr;
			hStr << "Frame-" << i+1;
			_ap_frames[i] = new Frame(hStr.str());

			hStr.str("");
			hStr << "Page-" << i+1;
			append_page(*_ap_frames[i], hStr.str());
		}
	}			
	
	void cb_switchPage(GtkNotebookPage*, guint page)
	{
		if(_destruct)
		{
			cout << "signal_switch_page caught on destruction for the "
			     << ++_dCount << " time !" << endl;
		}
	}
	
	Frame *_ap_frames[5];
	bool _destruct;
	unsigned _dCount;
};

class MainWindow : public Window
{
	public:
	MainWindow()
	{
		set_size_request(400, 400);
		add(_testNotebook);
		show_all_children();
	}
		
	private:
	TestNotebook _testNotebook;
};
		
int main(int argc, char **argv)
{
	Main kit(argc, argv);
	MainWindow win;
	Main::run(win);
}




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