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

Revision 18404, 2.8 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18403, which included commits to RCS files with non-trunk default branches.
Line 
1/* libglade-support.c -- support functions for libglade
2   $Id: libglade-support.c,v 1.1.1.2 2003-01-05 00:30:04 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
29typedef struct {
30    repv func;
31} conn_data;
32
33static void
34connector (const gchar *handler_name, GtkObject *object,
35           const gchar *signal_name, const gchar *signal_data,
36           GtkObject *connect_object, gboolean after, gpointer user_data)
37{
38    repv func = ((conn_data *) user_data)->func;
39
40    if (func == Qnil)
41    {
42        /* Look for a signal handler called HANDLER-NAME. */
43        repv sym = Fintern (rep_string_dup (handler_name), Qnil);
44        if (sym && rep_SYMBOLP(sym))
45            func = Fsymbol_value (sym, Qt);
46    }
47
48    if (Ffunctionp (func) != Qnil)
49    {
50        /* Looks like we've got something callable */
51        sgtk_protshell *data = sgtk_protect (sgtk_wrap_gtkobj (object), func);
52        gtk_signal_connect_full (object, signal_name, 0,
53                                 sgtk_callback_marshal,
54                                 (gpointer) data, sgtk_callback_destroy,
55                                 connect_object != 0, after);
56    }
57}
58
59void
60sgtk_glade_xml_signal_connect (GladeXML *self, char *handler_name, repv func)
61{
62    conn_data data;
63    data.func = func;
64    glade_xml_signal_connect_full (self, handler_name,
65                                   connector, (gpointer) &data);
66}
67
68void
69sgtk_glade_xml_signal_autoconnect (GladeXML *self)
70{
71    conn_data data;
72    data.func = Qnil;
73    glade_xml_signal_autoconnect_full (self, connector, (gpointer) &data);
74}
75
76GladeXML *
77sgtk_glade_xml_new_from_string (repv text, const char *root,
78                                const char *domain)
79{
80    if (!rep_STRINGP(text))
81    {
82        rep_signal_arg_error (text, 1);
83        return 0;
84    }
85
86    return glade_xml_new_from_memory (rep_STR(text),
87                                      rep_STRING_LEN(text),
88                                      root, domain);
89}
90
91
92/* dl hooks / init */
93
94repv
95rep_dl_init (void)
96{
97    repv s;
98    char *tem = getenv ("REP_GTK_DONT_INITIALIZE");
99    if (tem == 0 || atoi (tem) == 0)
100        glade_init ();
101
102    s = rep_push_structure ("gui.gtk-2.libglade");
103
104    sgtk_init_gtk_libglade_glue ();
105    return rep_pop_structure (s);
106}
Note: See TracBrowser for help on using the repository browser.