#include <gtkmm.h>

const char* EXAMPLE_UI = "\
<?xml version='1.0' encoding='UTF-8'?>\
<!-- Generated with glade 3.18.3 -->\
<interface>\
  <requires lib='gtk+' version='3.12'/>\
  <object class='GtkApplicationWindow' id='window1'>\
    <property name='can_focus'>False</property>\
    <child>\
      <object class='GtkButton' id='button1'>\
        <property name='label' translatable='yes'>Close</property>\
        <property name='visible'>True</property>\
        <property name='can_focus'>True</property>\
        <property name='receives_default'>True</property>\
      </object>\
    </child>\
  </object>\
</interface>";

class MyWindow: public Gtk::ApplicationWindow
{
public:
	MyWindow(GtkApplicationWindow* cobject, const Glib::RefPtr<Gtk::Builder>& builder, const Glib::ustring& title):
		Gtk::ApplicationWindow(cobject)
	{
		set_title(title);

		Gtk::Button* button;
		builder->get_widget("button1", button);
		button->signal_clicked().connect(sigc::mem_fun(*this, &MyWindow::hide));
	}
};

class Application: public Gtk::Application
{
public:
	Application(int argc, char* argv[]): Gtk::Application(argc, argv) {}

	virtual void on_startup()
	{
		Gtk::Application::on_startup();

		Glib::RefPtr<Gtk::Builder> builder = Gtk::Builder::create_from_string(EXAMPLE_UI);

		MyWindow* window_ptr = NULL;
		builder->create_widget_derived("window1", window_ptr, "My Title");

		m_window.reset(window_ptr);
		m_window->show();
		add_window(*m_window);
	}

private:
	std::auto_ptr<MyWindow> m_window;
};

int main(int argc, char* argv[])
{
	Glib::RefPtr<Gtk::Application> app(
		new Application(argc, argv));

	app->run();

	return 0;
}

