File: libglade-support.c

package info (click to toggle)
rep-gtk 0.15-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 728 kB
  • ctags: 349
  • sloc: ansic: 3,577; sh: 2,430; lisp: 1,102; makefile: 159
file content (135 lines) | stat: -rw-r--r-- 3,552 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* libglade-support.c -- support functions for libglade
   $Id: libglade-support.c,v 1.11 2000/07/23 22:52:49 john Exp $

   Copyright (C) 1999 John Harper <john@dcs.warwick.ac.uk>

   This file is part of rep-gtk.

   rep-gtk is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   rep-gtk is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with rep-gtk; see the file COPYING.   If not, write to
   the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */

#include <config.h>
#include <assert.h>
#include <glade/glade.h>
#include "rep-gtk.h"
#include "rep-libglade.h"
#include <string.h>

#ifdef GLADE_GNOME
# define GLADE_INIT_FUNC glade_gnome_init
# define GLADE_MODULE "gui.gnome.libglade"
# define GLADE_ALIAS "libglade-gnome"
# define GLADE_EXTRA_ALIAS "libglade"
#else
# define GLADE_INIT_FUNC glade_init
# define GLADE_MODULE "gui.gtk.libglade"
# define GLADE_ALIAS "libglade"
#endif

typedef struct {
    repv func;
} conn_data;

static void
connector (const gchar *handler_name, GtkObject *object,
	   const gchar *signal_name, const gchar *signal_data,
	   GtkObject *connect_object, gboolean after, gpointer user_data)
{
    repv func = ((conn_data *) user_data)->func;

    if (func == Qnil)
    {
	/* Look for a signal handler called HANDLER-NAME. */
	repv sym = Fintern (rep_string_dup (handler_name), Qnil);
	if (sym && rep_SYMBOLP(sym))
	    func = Fsymbol_value (sym, Qt);
    }

    if (Ffunctionp (func) != Qnil)
    {
	/* Looks like we've got something callable */
	sgtk_protshell *data = sgtk_protect (sgtk_wrap_gtkobj (object), func);
	gtk_signal_connect_full (object, signal_name, 0,
				 sgtk_callback_marshal,
				 (gpointer) data, sgtk_callback_destroy,
				 connect_object != 0, after);
    }
}

void
sgtk_glade_xml_signal_connect (GladeXML *self, char *handler_name, repv func)
{
    conn_data data;
    data.func = func;
    glade_xml_signal_connect_full (self, handler_name,
				   connector, (gpointer) &data);
}

void
sgtk_glade_xml_signal_autoconnect (GladeXML *self)
{
    conn_data data;
    data.func = Qnil;
    glade_xml_signal_autoconnect_full (self, connector, (gpointer) &data);
}

GladeXML *
sgtk_glade_xml_new_from_string (repv text, const char *root,
				const char *domain)
{
    if (!rep_STRINGP(text))
    {
	rep_signal_arg_error (text, 1);
	return 0;
    }

    return glade_xml_new_from_memory (rep_STR(text),
				      rep_STRING_LEN(text),
				      root, domain);
}

char *
sgtk_glade_xml_textdomain (GladeXML *xml)
{
#ifdef LIBGLADE_XML_TXTDOMAIN
    /* libglade 0.13 onwards */
    return xml->txtdomain;
#else
    return xml->textdomain;
#endif
}


/* dl hooks / init */

repv
rep_dl_init (void)
{
    repv s;
    char *tem = getenv ("REP_GTK_DONT_INITIALIZE");
    if (tem == 0 || atoi (tem) == 0)
	GLADE_INIT_FUNC ();

    s = rep_push_structure (GLADE_MODULE);

    /* ::alias:libglade gui.gtk.libglade::
       ::alias:libglade-gnome gui.gnome.libglade:: */
    rep_alias_structure (GLADE_ALIAS);
#ifdef GLADE_EXTRA_ALIAS
    rep_alias_structure (GLADE_EXTRA_ALIAS);
#endif

    sgtk_init_gtk_libglade_glue ();
    return rep_pop_structure (s);
}