• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Example for use of GNU gettext.
2    This file is in the public domain.
3 
4    Source code of the C program.  */
5 
6 
7 /* Get GNOME declarations.  */
8 #include <gnome.h>
9 
10 /* Get getpid() declaration.  */
11 #if HAVE_UNISTD_H
12 # include <unistd.h>
13 #endif
14 
15 static void
quit_callback(GtkWidget * widget,void * data)16 quit_callback (GtkWidget *widget, void *data)
17 {
18   gtk_main_quit ();
19 }
20 
21 int
main(int argc,char * argv[])22 main (int argc, char *argv[])
23 {
24   GtkWidget *window;
25   GtkWidget *panel;
26   GtkWidget *label1;
27   GtkWidget *label1aligned;
28   GtkWidget *label2;
29   GtkWidget *label2aligned;
30   GtkWidget *button;
31   GtkWidget *buttonbar;
32 
33   /* Initializations.  */
34 
35   gnome_init (PACKAGE, VERSION, argc, argv);
36   textdomain ("hello-c-gnome");
37   bindtextdomain ("hello-c-gnome", LOCALEDIR);
38 
39   /* Create the GUI elements.  */
40 
41   window = gnome_app_new ("hello-c-gnome", "Hello example");
42   gtk_widget_realize (window);
43   gtk_signal_connect (GTK_OBJECT (window), "delete_event",
44                       GTK_SIGNAL_FUNC (quit_callback), NULL);
45 
46   label1 = gtk_label_new (_("Hello, world!"));
47 
48   label1aligned = gtk_alignment_new (0.0, 0.5, 0, 0);
49   gtk_container_add (GTK_CONTAINER (label1aligned), label1);
50 
51   label2 = gtk_label_new (g_strdup_printf (_("This program is running as process number %d."), getpid ()));
52 
53   label2aligned = gtk_alignment_new (0.0, 0.5, 0, 0);
54   gtk_container_add (GTK_CONTAINER (label2aligned), label2);
55 
56   button = gtk_button_new_with_label ("OK");
57   gtk_signal_connect (GTK_OBJECT (button), "clicked",
58                       GTK_SIGNAL_FUNC (quit_callback), NULL);
59 
60   buttonbar = gtk_hbutton_box_new ();
61   gtk_button_box_set_layout (GTK_BUTTON_BOX (buttonbar), GTK_BUTTONBOX_END);
62   gtk_box_pack_start_defaults (GTK_BOX (buttonbar), button);
63 
64   panel = gtk_vbox_new (FALSE, GNOME_PAD_SMALL);
65   gtk_box_pack_start_defaults (GTK_BOX (panel), label1aligned);
66   gtk_box_pack_start_defaults (GTK_BOX (panel), label2aligned);
67   gtk_box_pack_start_defaults (GTK_BOX (panel), buttonbar);
68 
69   gnome_app_set_contents (GNOME_APP (window), panel);
70 
71   /* Make the GUI elements visible.  */
72 
73   gtk_widget_show (label1);
74   gtk_widget_show (label1aligned);
75   gtk_widget_show (label2);
76   gtk_widget_show (label2aligned);
77   gtk_widget_show (button);
78   gtk_widget_show (buttonbar);
79   gtk_widget_show (panel);
80   gtk_widget_show (window);
81 
82   /* Start the event loop.  */
83 
84   gtk_main ();
85 
86   return 0;
87 }
88