1 /* Part of XPCE --- The SWI-Prolog GUI toolkit
2
3 Author: Jan Wielemaker and Anjo Anjewierden
4 E-mail: jan@swi.psy.uva.nl
5 WWW: http://www.swi.psy.uva.nl/projects/xpce/
6 Copyright (c) 2005-2011, University of Amsterdam
7 All rights reserved.
8
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions
11 are met:
12
13 1. Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
15
16 2. Redistributions in binary form must reproduce the above copyright
17 notice, this list of conditions and the following disclaimer in
18 the documentation and/or other materials provided with the
19 distribution.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #define XPCE_PUBLIC_IMPL 1
36 #include <h/XPCE.h>
37
38 int
XPCE_define_classes(const XPCE_class_definition_t * classes)39 XPCE_define_classes(const XPCE_class_definition_t *classes)
40 { for(; classes->name; classes++)
41 { Class class = defineClass(CtoName(classes->name),
42 CtoName(classes->super),
43 staticCtoString(classes->summary),
44 classes->makefunction);
45
46 if ( classes->global )
47 *classes->global = class;
48 }
49
50 numberTreeClass(ClassObject, 0);
51
52 succeed;
53 }
54
55
56 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
57 XPCE_declare_class() calls declareClass() after internalising all names,
58 so we can load the class without assigning all names at compiletime.
59 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
60
61 static void
charpToName(Name * n)62 charpToName(Name *n)
63 { if ( !n )
64 return;
65
66 *n = CtoName((char *)*n);
67 }
68
69 static void
groupToName(Name * n)70 groupToName(Name *n)
71 { if ( !n )
72 *n = DEFAULT; /* meaning inherit from superclass */
73
74 *n = CtoName((char *)*n);
75 }
76
77 #define ToName(a) charpToName(&a)
78 #define GToName(a) groupToName(&a)
79
80 static void
intern_vardef(vardecl * vd)81 intern_vardef(vardecl *vd)
82 { ToName(vd->name);
83 GToName(vd->group);
84 }
85
86
87 static void
intern_send(senddecl * sd)88 intern_send(senddecl *sd)
89 { ToName(sd->name);
90 GToName(sd->group);
91 }
92
93
94 static void
intern_get(getdecl * gd)95 intern_get(getdecl *gd)
96 { ToName(gd->name);
97 GToName(gd->group);
98 }
99
100
101 static void
intern_cvardef(classvardecl * cvd)102 intern_cvardef(classvardecl *cvd)
103 { ToName(cvd->name);
104 }
105
106
107 static void
intern_term_name(Name * np)108 intern_term_name(Name *np)
109 { charpToName(np);
110 }
111
112
113 int
XPCE_declare_class(Class class,classdecl * decl)114 XPCE_declare_class(Class class, classdecl *decl)
115 { int i;
116
117 for(i=0; i<decl->nvar; i++)
118 intern_vardef(&decl->variables[i]);
119 for(i=0; i<decl->nsend; i++)
120 intern_send(&decl->send_methods[i]);
121 for(i=0; i<decl->nget; i++)
122 intern_get(&decl->get_methods[i]);
123 for(i=0; i<decl->nclassvars; i++)
124 intern_cvardef(&decl->class_variables[i]);
125 for(i=0; i<decl->term_arity; i++)
126 intern_term_name(&decl->term_names[i]);
127
128 return declareClass(class, decl);
129 }
130
131
132 void
XPCE_assignField(Instance instance,Any * field,Any value)133 XPCE_assignField(Instance instance, Any *field, Any value)
134 { assignField(instance, field, value);
135 }
136
137
138 Any
XPCE_constant(xpce_constant_id id)139 XPCE_constant(xpce_constant_id id)
140 { static Any constants[] =
141 { NIL,
142 DEFAULT,
143 CLASSDEFAULT,
144 ON,
145 OFF
146 };
147
148 return constants[id];
149 }
150
151
152 int
initPublicInterface()153 initPublicInterface()
154 { succeed;
155 }
156