source: trunk/third/rep-gtk/libglade-support.c @ 15286

Revision 15286, 3.5 KB checked in by ghudson, 24 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r15285, which included commits to RCS files with non-trunk default branches.
RevLine 
[15285]1/* libglade-support.c -- support functions for libglade
2   $Id: libglade-support.c,v 1.1.1.1 2000-11-12 06:16:30 ghudson Exp $
3
4   Copyright (C) 1999 John Harper <john@dcs.warwick.ac.uk>
5
6   This file is part of rep-gtk.
7
8   rep-gtk is free software; you can redistribute it and/or modify it
9   under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2, or (at your option)
11   any later version.
12
13   rep-gtk is distributed in the hope that it will be useful, but
14   WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18   You should have received a copy of the GNU General Public License
19   along with rep-gtk; see the file COPYING.   If not, write to
20   the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21
22#include <config.h>
23#include <assert.h>
24#include <glade/glade.h>
25#include "rep-gtk.h"
26#include "rep-libglade.h"
27#include <string.h>
28
29#ifdef GLADE_GNOME
30# define GLADE_INIT_FUNC glade_gnome_init
31# define GLADE_MODULE "gui.gnome.libglade"
32# define GLADE_ALIAS "libglade-gnome"
33# define GLADE_EXTRA_ALIAS "libglade"
34#else
35# define GLADE_INIT_FUNC glade_init
36# define GLADE_MODULE "gui.gtk.libglade"
37# define GLADE_ALIAS "libglade"
38#endif
39
40typedef struct {
41    repv func;
42} conn_data;
43
44static void
45connector (const gchar *handler_name, GtkObject *object,
46           const gchar *signal_name, const gchar *signal_data,
47           GtkObject *connect_object, gboolean after, gpointer user_data)
48{
49    repv func = ((conn_data *) user_data)->func;
50
51    if (func == Qnil)
52    {
53        /* Look for a signal handler called HANDLER-NAME. */
54        repv sym = Fintern (rep_string_dup (handler_name), Qnil);
55        if (sym && rep_SYMBOLP(sym))
56            func = Fsymbol_value (sym, Qt);
57    }
58
59    if (Ffunctionp (func) != Qnil)
60    {
61        /* Looks like we've got something callable */
62        sgtk_protshell *data = sgtk_protect (sgtk_wrap_gtkobj (object), func);
63        gtk_signal_connect_full (object, signal_name, 0,
64                                 sgtk_callback_marshal,
65                                 (gpointer) data, sgtk_callback_destroy,
66                                 connect_object != 0, after);
67    }
68}
69
70void
71sgtk_glade_xml_signal_connect (GladeXML *self, char *handler_name, repv func)
72{
73    conn_data data;
74    data.func = func;
75    glade_xml_signal_connect_full (self, handler_name,
76                                   connector, (gpointer) &data);
77}
78
79void
80sgtk_glade_xml_signal_autoconnect (GladeXML *self)
81{
82    conn_data data;
83    data.func = Qnil;
84    glade_xml_signal_autoconnect_full (self, connector, (gpointer) &data);
85}
86
87GladeXML *
88sgtk_glade_xml_new_from_string (repv text, const char *root,
89                                const char *domain)
90{
91    if (!rep_STRINGP(text))
92    {
93        rep_signal_arg_error (text, 1);
94        return 0;
95    }
96
97    return glade_xml_new_from_memory (rep_STR(text),
98                                      rep_STRING_LEN(text),
99                                      root, domain);
100}
101
102char *
103sgtk_glade_xml_textdomain (GladeXML *xml)
104{
105#ifdef LIBGLADE_XML_TXTDOMAIN
106    /* libglade 0.13 onwards */
107    return xml->txtdomain;
108#else
109    return xml->textdomain;
110#endif
111}
112
113
114/* dl hooks / init */
115
116repv
117rep_dl_init (void)
118{
119    repv s;
120    char *tem = getenv ("REP_GTK_DONT_INITIALIZE");
121    if (tem == 0 || atoi (tem) == 0)
122        GLADE_INIT_FUNC ();
123
124    s = rep_push_structure (GLADE_MODULE);
125
126    /* ::alias:libglade gui.gtk.libglade::
127       ::alias:libglade-gnome gui.gnome.libglade:: */
128    rep_alias_structure (GLADE_ALIAS);
129#ifdef GLADE_EXTRA_ALIAS
130    rep_alias_structure (GLADE_EXTRA_ALIAS);
131#endif
132
133    sgtk_init_gtk_libglade_glue ();
134    return rep_pop_structure (s);
135}
Note: See TracBrowser for help on using the repository browser.