Jump to content

User:arthurcy

From Wikipedia, the free encyclopedia

gtkmm (formerly known as gtk-- or gtk minus minus[1]) is the official C++ interface for the popular GUI library GTK+. gtkmm is free software distributed under the GNU Lesser General Public License (LGPL).

gtkmm allows the creation of user interfaces either in code or with the Glade Interface Designer, using libglademm. Other features include typesafe callbacks, a comprehensive set of widgets, and the extensibility of widgets via inheritance.

Features

[edit]

Due to the fact that gtkmm is the official C++ interface of the graphical user interface (GUI) library GTK+, C++ programmers can use the common OOP techniques such as inheritance, and C++-specific facilities such as STL (In fact, many of the gtkmm interfaces, especially those for widget containers, are designed to be STL-like).

Main features of gtkmm are listed as follows:

Hello World in Gtkmm

[edit]
//HelloWorldWindnow.h
#ifndef __HELLOWORLDWINDOW_H__
#define __HELLOWORLDWINDOW_H__

#include<gtkmm/window.h>
#include<gtkmm/button.h>

//derive a new window widger from an existing one
//this window will only contain a button labelled "Hello World"
class HelloWorldWindow : public Gtk::Window {
  public:
    HelloWorldWindow( );
    virtual ~HelloWorldWindow( ) { }

  protected:
    virtual void on_button_clicked( ); //event handler

    Gtk::Button hello_world;
};

#endif
//HelloWorldWindow.cc
#include<iostream>
#include"HelloWorldWindow.h"

HelloWorldWindow::HelloWorldWindow( )
 : hello_world( "Hello World" )
{
    //set the title of the window
    set_title( "Hello World" );

    //add the member button to the window
    add( hello_world );

    //handle the 'click' event
    hello_world.signal_clicked( ).connect(
        sigc::mem_fun( *this, &HelloWorldWindow::on_button_clicked ) );

    //display all the child widgets of the window
    show_all_children( );
}

void HelloWorldWindow::on_button_clicked( )
{
    std::cout << "Hello world" << std::endl;
}
//main.cc
#include<gtkmm/main.h>
#include"HelloWorldWindow.h"

int main( int argc, char *argv[] )
{
    //initialization
    Gtk::Main kit( argc, argv );
    //create a hello world window object
    HelloWorldWindow example;
    //gtkmm main loop
    Gtk::Main::run( example );
    return 0;
}

This program will create a window with a button labelled "hello world".

To run this program, just type the following command at your terminal:

g++ *.cc -o example `pkg-config gtkmm-2.4 --cflags --libs`
./example

or you can write a simple makefile.

To run gtkmm programs on windows, see official manual[2].

Applications

[edit]

Some notable applications that use GTK+ as a widget toolkit include:

  • Inkscape Vector graphics drawing.
  • Gnomoradio peer to peer sharing of freely licensed music.
  • K-3D 3D modelling and animation.
  • Workrave Assists in recovery and prevention of RSI.
  • GParted disk partitioning tool.
  • Gobby Collaborative text editor.
  • Nemiver GUI for the GNU debugger gdb.
  • Referencer document organiser and bibliography manager
  • MySQL Administrator Database GUI.

See also

[edit]

References

[edit]
[edit]