#include "helloworld2.h"
#include <inti/gtk/button.h>
#include <inti/bind.h>
#include <iostream>

HelloWorld2::HelloWorld2()
{
	// This is a new call, which just sets the title of our new window to "Hello Buttons!"
	set_title("Hello Buttons!");

	// Sets the border width of the window.
	set_border_width(10);

	// We create a box to pack widgets into. The box is not really visible, it is just used
	// as a tool to arrange widgets.
	Gtk::HBox *box1 = new Gtk::HBox;

	// Put the box into the main window.
	add(*box1);

	// Creates a new button with the label "Button 1".
	Gtk::Button *button = new Gtk::Button("Button 1");

	// Now when the button is clicked, we call the slot function with a pointer to "button 1" bound to it.
	button->sig_clicked().connect(bind(slot(this, &HelloWorld2::on_clicked), "button 1"));

	// Instead of Gtk::Container::add, we pack this button into the invisible box, which has been added to the window.
	box1->pack_start(*button);

	// Always remember this step, this tells Inti that our preparation for this button is complete,
	// and it can now be displayed.
	button->show();

	// Do these same steps again to create a second button
	button = new Gtk::Button("Button 2");

	// Call the same slot function with a different argument, passing a pointer to "button 2" instead.
 	button->sig_clicked().connect(bind(slot(this, &HelloWorld2::on_clicked), "button 2"));
	box1->pack_start(*button);

	// The order in which we show the buttons is not really important, but Irecommend showing the window last,
	// so it all pops up at once.
	button->show();
	box1->show();
}

HelloWorld2::~HelloWorld2()
{
}

void
HelloWorld2::on_clicked(const char *text)
{
	using namespace std;

	cout << "Hello again" << " - " << text << " " << "was pressed" << endl;
}

int main (int argc, char *argv[])
{
	using namespace Main;

	init(&argc, &argv);

	HelloWorld2 window;
	window.sig_destroy().connect(slot(&Inti::Main::quit));
	window.show();

	run();
	return 0;
}
