source: trunk/third/libglade2/test-libglade.c @ 21576

Revision 21576, 4.9 KB checked in by ghudson, 19 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r21575, which included commits to RCS files with non-trunk default branches.
Line 
1/* -*- Mode: C; c-basic-offset: 4 -*-
2 * Copyright (C) 1998-2001  James Henstridge <james@daa.com.au>
3 * GNOME option parsing code by Miguel de Icaza.
4 *
5 * test-libglade.c: a test program for the libglade library
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License as
9 *   published by the Free Software Foundation; either version 2 of
10 *   the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 *   General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 *   02111-1307 USA
21 *
22 *
23 * At your option, you may use this alternative X style licence:
24 *
25 *   Permission is hereby granted, free of charge, to any person
26 *   obtaining a copy of this software and associated documentation
27 *   files (the "Software"), to deal in the Software without
28 *   restriction, including without limitation the rights to use,
29 *   copy, modify, merge, publish, distribute, sublicense, and/or sell
30 *   copies of the Software, and to permit persons to whom the
31 *   Software is furnished to do so, subject to the following
32 *   conditions:
33 *
34 *   The above copyright notice and this permission notice shall be
35 *   included in all copies or substantial portions of the Software.
36 *
37 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
38 *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
39 *   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
40 *   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
41 *   CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
42 *   CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
43 *   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
44 *   SOFTWARE.
45 */
46
47#ifdef HAVE_CONFIG_H
48#  include <config.h>
49#endif
50#include <string.h>
51#include <stdlib.h>
52#include <gtk/gtk.h>
53#include <glade/glade.h>
54#include <glade/glade-build.h>
55
56#ifdef WITH_GNOME
57#  include <libgnomeui/libgnomeui.h>
58#endif
59
60int
61main (int argc, char **argv)
62{
63    const char *filename = NULL;
64    const char *rootnode = NULL;
65    gboolean no_connect = FALSE;
66
67    int i;
68    GladeXML *xml;
69
70    /* initialise libraries */
71    gtk_init(&argc, &argv);
72
73#ifdef WITH_GNOME
74    if (!gnome_program_init ("Terminal", VERSION,
75                             LIBGNOMEUI_MODULE,
76                             argc, argv,
77                             NULL))
78        g_error ("Cannot gnome_program_init ()");
79#endif
80
81    /* argument parsing */
82    for (i = 1; i < argc; i++) {
83        if (!strcmp(argv[i], "--no-connect"))
84            no_connect = TRUE;
85        else if (filename == NULL)
86            filename = argv[i];
87        else if (rootnode == NULL)
88            rootnode = argv[i];
89        else {
90            g_print("Usage: %s [--no-connect] filename [rootnode]\n", argv[0]);
91            return 1;
92        }
93    }
94    if (filename == NULL) {
95        g_print("Usage: %s [--no-connect] filename [rootnode]\n", argv[0]);
96        return 1;
97    }
98
99    /* construct the interface */
100    xml = glade_xml_new(filename, rootnode, NULL);
101    if (!xml) {
102        g_warning("something bad happened while creating the interface");
103        return 1;
104    }
105
106    /* if you pass the rootnode argument to libglade, it will only
107     * construct widgets below that point. This shows how you might
108     * want to integrate the constructed interface in your program. */
109    if (rootnode) {
110        GtkWidget *wid = glade_xml_get_widget(xml, rootnode);
111        if (!GTK_IS_WINDOW(wid)) {
112            GtkWidget *win, *frame;
113
114            win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
115            g_signal_connect(win, "destroy",
116                             G_CALLBACK(gtk_main_quit), NULL);
117            gtk_container_set_border_width(GTK_CONTAINER(win), 5);
118            frame = gtk_frame_new(NULL);
119            gtk_container_set_border_width(GTK_CONTAINER(frame), 5);
120            gtk_container_add(GTK_CONTAINER(win), frame);
121            gtk_widget_show(frame);
122            gtk_container_add(GTK_CONTAINER(frame), wid);
123            gtk_widget_show(win);
124        }
125    }
126
127    /* look up handler names in the symbol table and automatically
128     * connect the signals. This requires that your program export
129     * dynamic symbols.  If you link using libtool, passing the
130     * -export-dynamic link flag will do this in a cross platform
131     * manner.  For GNU ld, the --export-dynamic argument should
132     * work.
133     *
134     * If you don't want to do symbol lookups like this, the
135     * glade_xml_signal_connect() function allows you to connect
136     * individual handlers up. */
137    if (!no_connect)
138        glade_xml_signal_autoconnect(xml);
139
140    /* we have finished with the GladeXML object, so release our
141     * reference to it.  This does not destroy all the widgets created
142     * as part of the interface. */
143    g_object_unref(G_OBJECT(xml));
144
145    /* start the event loop */
146    gtk_main();
147
148    return 0;
149}
Note: See TracBrowser for help on using the repository browser.