GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

A simple Gnome application in C/GTK+

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Example Code
Author Message
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 407
Location: Portland, OR USA

PostPosted: Thu Mar 09, 2006 6:41 pm    Post subject: A simple Gnome application in C/GTK+ Reply with quote

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: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74

/* 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()");
}
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Example Code All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP