All pastes #962229 Raw Edit

simpleapp

public cpp v1 · immutable
#962229 ·published 2008-03-29 16:37 UTC
rendered paste body
////// MainWindow.h#ifndef MAINWINDOW_H_#define MAINWINDOW_H_#include <iostream>#include <fstream>#include <exception>#include <glibmm.h>#include <gtkmm.h>#include <libglademm.h>#include "PreferencesWindow.h"class MainWindow{public:	MainWindow();	virtual ~MainWindow();	// The window. This is public so we can hook into events and	// call kit.run(window) against it, if needed.	Gtk::Window		*window;private:	// Contains the Xml reference for this window and it's widgets.	Glib::RefPtr<Gnome::Glade::Xml> 					refXml;			// Widgets in the window.			// Child Windows	PreferencesWindow	*preferences_window;		// Methods	void on_preferences_open();	bool on_preferences_close(GdkEventAny *e);	void on_preferences_hide();};#endif /*MAINWINDOW_H_*/////// MainWindow.cpp#include "MainWindow.h"MainWindow::MainWindow(){	// Load the data for this window and it's widgets.    refXml = Gnome::Glade::Xml::create("simpleapp.glade", "main_window");        // The window    refXml->get_widget("main_window", window);        // Widgets    refXml->connect_clicked("preferences_button", sigc::mem_fun(*this, &MainWindow::on_preferences_open));        // Show everything.    window->show_all_children(true);}MainWindow::~MainWindow(){	delete window; // Frees all the children for the window, too.}void MainWindow::on_preferences_open(){	preferences_window = new PreferencesWindow;		//preferences_window->window->signal_delete_event().connect(sigc::mem_fun(*this, &MainWindow::on_preferences_close));	preferences_window->window->signal_hide().connect(sigc::mem_fun(*this, &MainWindow::on_preferences_hide));}void MainWindow::on_preferences_hide(){	std::cout << "MainWindow::on_preferences_hide() called" << std::endl;		delete preferences_window;	std::cout << "MainWindow::on_preferences_hide() finished" << std::endl;}bool MainWindow::on_preferences_close(GdkEventAny *e){	on_preferences_hide();	return false;}////// PreferencesWindow.h#ifndef PREFERENCESWINDOW_H_#define PREFERENCESWINDOW_H_#include <iostream>#include <fstream>#include <exception>#include <glibmm.h>#include <gtkmm.h>#include <libglademm.h>class PreferencesWindow{public:	PreferencesWindow();	virtual ~PreferencesWindow();	// The window. This is public so we can hook into events and	// call kit.run(window) against it, if needed.	Gtk::Window		*window;private:	// Contains the Xml reference for this window and it's widgets.	Glib::RefPtr<Gnome::Glade::Xml> 					refXml;			// Widgets in the window.		// Methods	void on_ok_button_clicked();};#endif /*PREFERENCESWINDOW_H_*/////// PreferencesWindow.cpp#include "include/PreferencesWindow.h"PreferencesWindow::PreferencesWindow(){	// Load the data for this window and it's widgets.    refXml = Gnome::Glade::Xml::create("simpleapp.glade", "preferences_window");        // The window    refXml->get_widget("preferences_window", window);        // Widgets    refXml->connect_clicked("ok_button", sigc::mem_fun(*this, &PreferencesWindow::on_ok_button_clicked));    refXml->connect_clicked("close_button", sigc::mem_fun(*window, &Gtk::Window::hide));        // Show everything.    window->show_all_children(true);}PreferencesWindow::~PreferencesWindow(){	delete window;}void PreferencesWindow::on_ok_button_clicked(){	std::cout << "Clicked ok!" << std::endl;	window->hide();}///// SimpleApp.cpp#include <iostream>#include <fstream>#include <exception>#include <gtkmm.h>#include <libglademm.h>#include "MainWindow.h"int main(int argc, char **argv) {    Gtk::Main 		kit(argc, argv);    MainWindow		main_window;    kit.run(*main_window.window);        return 0;}