Quicker Way to Program with Gtkmm 3.0?

Status
Not open for further replies.

theopfor

In Runtime
Messages
173
Location
Right behind you
Recently I have been using the C API for GTK+, but a lot of people said that if I was using C++, and the C API, I should just use Gtkmm. I got this 400 page PDF of the Internet, and everything seems so lengthy.

Here is what I mean:

helloworld.h:
Code:
#ifndef GTKMM_EXAMPLE_HELLOWORLD_H
#define GTKMM_EXAMPLE_HELLOWORLD_H
#include <gtkmm/button.h>
#include <gtkmm/window.h>
class HelloWorld : public Gtk::Window
{
public:
HelloWorld();
virtual ~HelloWorld();
protected:
//Signal handlers:
virtual void on_button_clicked();
//Member widgets:
Gtk::Button m_button;
};
#endif // GTKMM_EXAMPLE_HELLOWORLD_H

main.cpp:
Code:
#include <gtkmm/main.h>
#include "helloworld.h"
int main (int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
HelloWorld helloworld;
//Shows the window and returns when it is closed.
Gtk::Main::run(helloworld);
return 0;
}

helloworld.cpp:

Code:
include "helloworld.h"
#include <iostream>
HelloWorld::HelloWorld()
: m_button("Hello World")
// creates a new button with label "Hello World".
{
// Sets the border width of the window.
set_border_width(10);
// When the button receives the "clicked" signal, it will call the
// on_button_clicked() method defined below.
m_button.signal_clicked().connect(sigc::mem_fun(*this,
&HelloWorld::on_button_clicked));
// This packs the button into the Window (a container).
add(m_button);
// The final step is to display this newly created widget...
m_button.show();
}
HelloWorld::~HelloWorld()
{
}
void HelloWorld::on_button_clicked()
{
std::cout << "Hello World" << std::endl;
}

Seems lengthy to the C API. Here is the C API version:

Code:
#include <gtk/gtk.h>

int main(int argc, char* argv[])
{
    gtk_init(&argc, &argv);
    GtkWidget *window, *button;

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    button = gtk_button_new("Hello world!");

    gtk_containter_add(GTK_CONTAINER(button), window);
    gtk_widget_show_all(window);
    gtk_main();
    return 0;
}

So, is there any way I can get Gtkmm's code stuff, to get around the same size as GTK+?
 
Status
Not open for further replies.
Back
Top Bottom