Source Code
File: examplewindow.h
#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H
#include <gtkmm.h>
class ExampleWindow : public Gtk::Window
{
public:
ExampleWindow();
virtual ~ExampleWindow();
protected:
//Signal handlers:
virtual void on_button_clicked();
//Child widgets:
Gtk::Button m_Button;
};
#endif //GTKMM_EXAMPLEWINDOW_H
File: examplewindow.cc
#include "examplewindow.h"
#include <iostream>
ExampleWindow::ExampleWindow()
: m_Button("Show Dialog")
{
set_title("Gtk::FontSelectionDialog example");
add(m_Button);
m_Button.signal_clicked().connect( SigC::slot(*this, &ExampleWindow::on_button_clicked) );
show_all_children();
}
ExampleWindow::~ExampleWindow()
{
}
void ExampleWindow::on_button_clicked()
{
Gtk::FontSelectionDialog dialog;
int result = dialog.run();
//Handle the response:
switch(result)
{
case(Gtk::RESPONSE_OK):
{
Glib::ustring font_name = dialog.get_font_name();
std::cout << "Font chosen: " << font_name << std::endl;
break;
}
case(Gtk::RESPONSE_CANCEL):
{
std::cout << "Cancel clicked." << std::endl;
break;
}
default:
{
std::cout << "Unexpected button clicked." << std::endl;
break;
}
}
}
File: main.cc
#include <gtkmm/main.h>
#include <examplewindow.h>
int main(int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
ExampleWindow window;
Gtk::Main::run(window); //Shows the window and returns when it is closed.
return 0;
}