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

Revision 18268, 4.9 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18267, 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#include <config.h>
48#include <string.h>
49#include <stdlib.h>
50#include <gtk/gtk.h>
51#include <glade/glade.h>
52#include <glade/glade-build.h>
53
54#ifdef WITH_GNOME
55#  include <libgnomeui/libgnomeui.h>
56#endif
57
58int
59main (int argc, char **argv)
60{
61    const char *filename = NULL;
62    const char *rootnode = NULL;
63    gboolean no_connect = FALSE;
64
65    int i;
66    GladeXML *xml;
67
68    /* initialise libraries */
69    gtk_init(&argc, &argv);
70
71#ifdef WITH_GNOME
72    if (!gnome_program_init ("Terminal", VERSION,
73                             LIBGNOMEUI_MODULE,
74                             argc, argv,
75                             NULL))
76        g_error ("Cannot gnome_program_init ()");
77#endif
78
79    /* argument parsing */
80    for (i = 1; i < argc; i++) {
81        if (!strcmp(argv[i], "--no-connect"))
82            no_connect = TRUE;
83        else if (filename == NULL)
84            filename = argv[i];
85        else if (rootnode == NULL)
86            rootnode = argv[i];
87        else {
88            g_print("Usage: %s [--no-connect] filename [rootnode]\n", argv[0]);
89            return 1;
90        }
91    }
92    if (filename == NULL) {
93        g_print("Usage: %s [--no-connect] filename [rootnode]\n", argv[0]);
94        return 1;
95    }
96
97    /* construct the interface */
98    xml = glade_xml_new(filename, rootnode, NULL);
99    if (!xml) {
100        g_warning("something bad happened while creating the interface");
101        return 1;
102    }
103
104    /* if you pass the rootnode argument to libglade, it will only
105     * construct widgets below that point. This shows how you might
106     * want to integrate the constructed interface in your program. */
107    if (rootnode) {
108        GtkWidget *wid = glade_xml_get_widget(xml, rootnode);
109        if (!GTK_IS_WINDOW(wid)) {
110            GtkWidget *win, *frame;
111
112            win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
113            gtk_signal_connect(GTK_OBJECT(win), "destroy",
114                               GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
115            gtk_container_set_border_width(GTK_CONTAINER(win), 5);
116            frame = gtk_frame_new(NULL);
117            gtk_container_set_border_width(GTK_CONTAINER(frame), 5);
118            gtk_container_add(GTK_CONTAINER(win), frame);
119            gtk_widget_show(frame);
120            gtk_container_add(GTK_CONTAINER(frame), wid);
121            gtk_widget_show(win);
122        }
123    }
124
125    /* look up handler names in the symbol table and automatically
126     * connect the signals. This requires that your program export
127     * dynamic symbols.  If you link using libtool, passing the
128     * -export-dynamic link flag will do this in a cross platform
129     * manner.  For GNU ld, the --export-dynamic argument should
130     * work.
131     *
132     * If you don't want to do symbol lookups like this, the
133     * glade_xml_signal_connect() function allows you to connect
134     * individual handlers up. */
135    if (!no_connect)
136        glade_xml_signal_autoconnect(xml);
137
138    /* we have finished with the GladeXML object, so release our
139     * reference to it.  This does not destroy all the widgets created
140     * as part of the interface. */
141    g_object_unref(G_OBJECT(xml));
142
143    /* start the event loop */
144    gtk_main();
145
146    return 0;
147}
Note: See TracBrowser for help on using the repository browser.