GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed Sep 03, 2014 4:42 am

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: A simple Gnome application in C/GTK+
PostPosted: Thu Mar 09, 2006 6:41 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
This code is taken from my website: Gnome Programming Tutorial: Simple Gnome Application Using libglade and C/GTK+
This code is a very basic Gnome application. The entire tarball with the glade file and the configure script can be downloaded here: gnome3-0.1.tar.gz


Code:
/* the config.h file generated by the autotools */
#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

/* this will hold the path to the glade file after the "make install" */
#define GLADE_FILE PACKAGE_DATA_DIR"/gnome3/gnome3.glade"

#include <gnome.h>
#include <glade/glade.h>

/* callback function prototypes */
static gint delete_event_cb(GtkWidget* w, GdkEventAny* e, gpointer data);
static gint destroy_cb(GtkWidget* w, GdkEventAny* e, gpointer data);


int main (int argc, char *argv[])
{
        GtkWidget *app_window;          /* main application window widget */
        GladeXML *gxml;                 /* glade xml file */

        /* initialize libgnome */
        gnome_program_init (PACKAGE, VERSION, LIBGNOMEUI_MODULE,
                            argc, argv,
                            NULL);

        /* create GladeXML object and connect signals */
        gxml = glade_xml_new (GLADE_FILE, NULL, NULL);
        glade_xml_signal_autoconnect (gxml);
       
        /* get the app_window from the glade XML file */
        app_window = glade_xml_get_widget (gxml, "app_window");
               
        /* Connect signals for termination of application */
        g_signal_connect(G_OBJECT(app_window), "delete_event",
                G_CALLBACK(delete_event_cb), NULL);
               
        g_signal_connect(G_OBJECT(app_window), "destroy",
                G_CALLBACK(destroy_cb), NULL);
       
        /* show the main window */
        gtk_widget_show (app_window);

        /* begin main GTK loop */
        gtk_main ();
       
        return 0;
}

static gint delete_event_cb(GtkWidget* w, GdkEventAny* e, gpointer data)
{   
        /* callback for "delete" signal */
        g_print("main.c:delete_event_cb()\n");
        return 0;
}

static gint destroy_cb(GtkWidget* w, GdkEventAny* e, gpointer data)
{
        /* callback for "destroy" signal */
        g_print("main.c:destroy_cb()\n"); 
       
        /* quit application */
        gtk_main_quit();
        return 0;
}

void
on_toolbutton_new_clicked(GtkWidget *w, GdkEventKey *e)
{
        /* the 'New' toolbar was clicked */
        g_print("main.c:on_toolbutton_new_clicked()");
}

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: Google Adsense [Bot], ldries46 and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group