1 /***************************************************************************
2  begin       : Sat Feb 20 2010
3  copyright   : (C) 2010 by Martin Preuss
4  email       : martin@libchipcard.de
5 
6  ***************************************************************************
7  *          Please see toplevel file COPYING for license details           *
8  ***************************************************************************/
9 
10 #ifdef HAVE_CONFIG_H
11 # include <config.h>
12 #endif
13 
14 #define DISABLE_DEBUGLOG
15 
16 
17 #include "htmlobject_p.h"
18 
19 #include <gwenhywfar/misc.h>
20 #include <gwenhywfar/debug.h>
21 
22 #include <assert.h>
23 #include <string.h>
24 
25 
GWEN_TREE_FUNCTIONS(HTML_OBJECT,HtmlObject)26 GWEN_TREE_FUNCTIONS(HTML_OBJECT, HtmlObject)
27 GWEN_INHERIT_FUNCTIONS(HTML_OBJECT)
28 
29 
30 
31 HTML_OBJECT *HtmlObject_new(GWEN_XML_CONTEXT *ctx, HTML_OBJECT_TYPE t)
32 {
33   HTML_OBJECT *o;
34 
35   GWEN_NEW_OBJECT(HTML_OBJECT, o);
36   o->refCount=1;
37   o->objectType=t;
38   o->xmlCtx=ctx;
39   GWEN_TREE_INIT(HTML_OBJECT, o);
40   GWEN_INHERIT_INIT(HTML_OBJECT, o);
41 
42   return o;
43 }
44 
45 
46 
HtmlObject_free(HTML_OBJECT * o)47 void HtmlObject_free(HTML_OBJECT *o)
48 {
49   if (o) {
50     assert(o->refCount);
51     if (o->refCount>1)
52       o->refCount--;
53     else {
54       GWEN_TREE_FINI(HTML_OBJECT, o);
55       GWEN_INHERIT_FINI(HTML_OBJECT, o);
56 
57       free(o->text);
58       HtmlProps_free(o->properties);
59 
60       o->refCount=0;
61       GWEN_FREE_OBJECT(o);
62     }
63   }
64 }
65 
66 
67 
HtmlObject_Attach(HTML_OBJECT * o)68 void HtmlObject_Attach(HTML_OBJECT *o)
69 {
70   assert(o);
71   assert(o->refCount);
72   o->refCount++;
73 }
74 
75 
76 
HtmlObject_GetXmlCtx(const HTML_OBJECT * o)77 GWEN_XML_CONTEXT *HtmlObject_GetXmlCtx(const HTML_OBJECT *o)
78 {
79   assert(o);
80   assert(o->refCount);
81   return o->xmlCtx;
82 }
83 
84 
85 
HtmlObject_GetObjectType(const HTML_OBJECT * o)86 HTML_OBJECT_TYPE HtmlObject_GetObjectType(const HTML_OBJECT *o)
87 {
88   assert(o);
89   assert(o->refCount);
90   return o->objectType;
91 }
92 
93 
94 
HtmlObject_SetObjectType(HTML_OBJECT * o,HTML_OBJECT_TYPE t)95 void HtmlObject_SetObjectType(HTML_OBJECT *o, HTML_OBJECT_TYPE t)
96 {
97   assert(o);
98   assert(o->refCount);
99   o->objectType=t;
100 }
101 
102 
103 
HtmlObject_GetProperties(const HTML_OBJECT * o)104 HTML_PROPS *HtmlObject_GetProperties(const HTML_OBJECT *o)
105 {
106   assert(o);
107   assert(o->refCount);
108   return o->properties;
109 }
110 
111 
112 
HtmlObject_SetProperties(HTML_OBJECT * o,HTML_PROPS * pr)113 void HtmlObject_SetProperties(HTML_OBJECT *o, HTML_PROPS *pr)
114 {
115   assert(o);
116   assert(o->refCount);
117 
118   HtmlProps_Attach(pr);
119   HtmlProps_free(o->properties);
120   o->properties=pr;
121 }
122 
123 
124 
HtmlObject_GetX(const HTML_OBJECT * o)125 int HtmlObject_GetX(const HTML_OBJECT *o)
126 {
127   assert(o);
128   assert(o->refCount);
129   return o->x;
130 }
131 
132 
133 
HtmlObject_SetX(HTML_OBJECT * o,int i)134 void HtmlObject_SetX(HTML_OBJECT *o, int i)
135 {
136   assert(o);
137   assert(o->refCount);
138   o->x=i;
139 }
140 
141 
142 
HtmlObject_GetY(const HTML_OBJECT * o)143 int HtmlObject_GetY(const HTML_OBJECT *o)
144 {
145   assert(o);
146   assert(o->refCount);
147   return o->y;
148 }
149 
150 
151 
HtmlObject_SetY(HTML_OBJECT * o,int i)152 void HtmlObject_SetY(HTML_OBJECT *o, int i)
153 {
154   assert(o);
155   assert(o->refCount);
156   o->y=i;
157 }
158 
159 
160 
HtmlObject_GetWidth(const HTML_OBJECT * o)161 int HtmlObject_GetWidth(const HTML_OBJECT *o)
162 {
163   assert(o);
164   assert(o->refCount);
165   return o->width;
166 }
167 
168 
169 
HtmlObject_SetWidth(HTML_OBJECT * o,int i)170 void HtmlObject_SetWidth(HTML_OBJECT *o, int i)
171 {
172   assert(o);
173   assert(o->refCount);
174   o->width=i;
175 }
176 
177 
178 
HtmlObject_GetHeight(const HTML_OBJECT * o)179 int HtmlObject_GetHeight(const HTML_OBJECT *o)
180 {
181   assert(o);
182   assert(o->refCount);
183   return o->height;
184 }
185 
186 
187 
HtmlObject_SetHeight(HTML_OBJECT * o,int i)188 void HtmlObject_SetHeight(HTML_OBJECT *o, int i)
189 {
190   assert(o);
191   assert(o->refCount);
192   o->height=i;
193 }
194 
195 
196 
HtmlObject_GetConfiguredWidth(const HTML_OBJECT * o)197 int HtmlObject_GetConfiguredWidth(const HTML_OBJECT *o)
198 {
199   assert(o);
200   assert(o->refCount);
201   return o->configuredWidth;
202 }
203 
204 
205 
HtmlObject_SetConfiguredWidth(HTML_OBJECT * o,int i)206 void HtmlObject_SetConfiguredWidth(HTML_OBJECT *o, int i)
207 {
208   assert(o);
209   assert(o->refCount);
210   o->configuredWidth=i;
211 }
212 
213 
214 
HtmlObject_GetConfiguredHeight(const HTML_OBJECT * o)215 int HtmlObject_GetConfiguredHeight(const HTML_OBJECT *o)
216 {
217   assert(o);
218   assert(o->refCount);
219   return o->configuredHeight;
220 }
221 
222 
223 
HtmlObject_SetConfiguredHeight(HTML_OBJECT * o,int i)224 void HtmlObject_SetConfiguredHeight(HTML_OBJECT *o, int i)
225 {
226   assert(o);
227   assert(o->refCount);
228   o->configuredHeight=i;
229 }
230 
231 
232 
HtmlObject_GetText(const HTML_OBJECT * o)233 const char *HtmlObject_GetText(const HTML_OBJECT *o)
234 {
235   assert(o);
236   assert(o->refCount);
237   return o->text;
238 }
239 
240 
241 
HtmlObject_SetText(HTML_OBJECT * o,const char * s)242 void HtmlObject_SetText(HTML_OBJECT *o, const char *s)
243 {
244   assert(o);
245   assert(o->refCount);
246   free(o->text);
247   if (s)
248     o->text=strdup(s);
249   else
250     o->text=NULL;
251 }
252 
253 
254 
HtmlObject_GetFlags(const HTML_OBJECT * o)255 uint32_t HtmlObject_GetFlags(const HTML_OBJECT *o)
256 {
257   assert(o);
258   assert(o->refCount);
259 
260   return o->flags;
261 }
262 
263 
264 
HtmlObject_SetFlags(HTML_OBJECT * o,uint32_t fl)265 void HtmlObject_SetFlags(HTML_OBJECT *o, uint32_t fl)
266 {
267   assert(o);
268   assert(o->refCount);
269 
270   o->flags=fl;
271 }
272 
273 
274 
HtmlObject_AddFlags(HTML_OBJECT * o,uint32_t fl)275 void HtmlObject_AddFlags(HTML_OBJECT *o, uint32_t fl)
276 {
277   assert(o);
278   assert(o->refCount);
279 
280   o->flags|=fl;
281 }
282 
283 
284 
HtmlObject_SubFlags(HTML_OBJECT * o,uint32_t fl)285 void HtmlObject_SubFlags(HTML_OBJECT *o, uint32_t fl)
286 {
287   assert(o);
288   assert(o->refCount);
289 
290   o->flags&=~fl;
291 }
292 
293 
294 
HtmlObject_Layout(HTML_OBJECT * o)295 int HtmlObject_Layout(HTML_OBJECT *o)
296 {
297   assert(o);
298   assert(o->refCount);
299   if (o->layoutFn)
300     return o->layoutFn(o);
301   else {
302     o->width=0;
303     o->height=0;
304     return 0;
305   }
306 }
307 
308 
309 
HtmlObject_SetLayoutFn(HTML_OBJECT * o,HTML_OBJECT_LAYOUT_FN fn)310 HTML_OBJECT_LAYOUT_FN HtmlObject_SetLayoutFn(HTML_OBJECT *o,
311                                              HTML_OBJECT_LAYOUT_FN fn)
312 {
313   HTML_OBJECT_LAYOUT_FN of;
314 
315   of=o->layoutFn;
316   o->layoutFn=fn;
317   return of;
318 }
319 
320 
321 
322