MHEG5  18.9.0
MHEG5 Documentation
mh5hypertext.c
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright © 2014 The DTVKit Open Software Foundation Ltd (www.dtvkit.org)
3  * Copyright © 2004 Ocean Blue Software Ltd
4  * Copyright © 2000 Koninklijke Philips Electronics N.V
5  *
6  * This file is part of a DTVKit Software Component
7  * You are permitted to copy, modify or distribute this file subject to the terms
8  * of the DTVKit 1.0 Licence which can be found in licence.txt or at www.dtvkit.org
9  *
10  * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
11  * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
12  * OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
13  *
14  * If you or your organisation is not a member of DTVKit then you have access
15  * to this source code outside of the terms of the licence agreement
16  * and you are expected to delete this and any associated files immediately.
17  * Further information on DTVKit, membership and terms can be found at www.dtvkit.org
18  *******************************************************************************/
33 /*---includes for this file--------------------------------------------------*/
34 #include "mh5hypertext.h"
35 #include "mh5object.h" /* for actions */
36 #include "mh5variable.h" /* for actions */
37 #include "mh5display.h" /* for actions */
38 #include "mh5memory.h" /* for constructor/destructor */
39 #include "mh5queue.h" /* Events */
40 #include <stdlib.h>
41 #include "mh5drawtext.h"
42 
43 /*
44  Debug
45  */
46 #ifdef MH5PRINTOUT
47 #include <string.h>
48 
49 void MHEG5hypertextPrint(MHEG5Hypertext *hypertext, char *out)
50 {
51  MHEG5textPrint(&hypertext->text, out);
52  MHEG5interactiblePrint(&hypertext->interactible, out);
53  MHEG5indent(out);
54  MHEG_PRINT(out, "// LastAnchorFired:\t");
55  MHEG5stringPrint( hypertext->lastAnchorFired, out);
56  MHEG5newLine(out);
57  MHEG_PRINT(out, "// FocusPosition:\t");
58  MHEG5intPrint(hypertext->focusPosition, out);
59  MHEG5newLine(out);
60 }
61 
62 #endif
63 
64 /*
65  Hypertext Class
66  */
73 {
74  if ((hypertext->focusPosition != 0) && (hypertext->numberOfLinks != -1))
75  {
76  if (hypertext->focusPosition > 1)
77  {
78  hypertext->focusPosition--;
79  MHEG5drawHypertext(hypertext);
80  return;
81  }
82  if (hypertext->focusPosition == 1 && hypertext->anchorWrappingFlag == MHEG5TRUE)
83  {
84  hypertext->focusPosition = hypertext->numberOfLinks;
85  MHEG5drawHypertext(hypertext);
86  return;
87  }
88  }
89  if (hypertext->anchorWrappingFlag == MHEG5FALSE)
90  {
92  /* free any previous anchor string */
93  if (hypertext->lafAlloc)
94  {
95  MHEG5stringDestruct( &hypertext->lastAnchorFired );
96  hypertext->lafAlloc = MHEG5FALSE;
97  }
98  /* Keep an up-to-date copy of the last anchor fired */
100  }
101 }
102 
109 {
110  if ((hypertext->focusPosition != 0) && (hypertext->numberOfLinks != -1))
111  {
112  if (hypertext->focusPosition < hypertext->numberOfLinks)
113  {
114  hypertext->focusPosition++;
115  MHEG5drawHypertext(hypertext);
116  return;
117  }
118  if (hypertext->focusPosition == hypertext->numberOfLinks &&
119  hypertext->anchorWrappingFlag == MHEG5TRUE)
120  {
121  hypertext->focusPosition = 1;
122  MHEG5drawHypertext(hypertext);
123  return;
124  }
125  }
126  if (hypertext->anchorWrappingFlag == MHEG5FALSE)
127  {
129  /* free any previous anchor string */
130  if (hypertext->lafAlloc)
131  {
132  MHEG5stringDestruct( &hypertext->lastAnchorFired );
133  hypertext->lafAlloc = MHEG5FALSE;
134  }
135  /* Keep an up-to-date copy of the last anchor fired */
137  }
138 }
139 
141 {
142  MHEG5Int anchor = 0;
143  unsigned short *data;
144  int i, j, len;
145 
146  data = (unsigned short *)hypertext->text.visible.ingredient.data;
147 
148  if (data)
149  {
150  /* data associated with the hypertext object */
151 
152  /* Search for hypertext anchors */
153  for (i = 0; i != hypertext->text.visible.ingredient.dataLen; i++)
154  {
155  if ((data[i] == 0x1B) && (data[i + 1] == 0x41))
156  {
157  /* Found an anchor. Increment the counter */
158  anchor++;
159  len = data[i + 2];
160  if (anchor != hypertext->focusPosition)
161  {
162  i += len + 2; /* skip past this anchor */
163  if (i >= hypertext->text.visible.ingredient.dataLen)
164  {
165  break;
166  }
167  }
168  else
169  {
170  /* Found the anchor that we want to fire */
171 
172  /* free any previous anchor string */
173  if (hypertext->lafAlloc)
174  {
175  MHEG5stringDestruct( &hypertext->lastAnchorFired );
176  hypertext->lafAlloc = MHEG5FALSE;
177  }
178 
179  /* Keep an up-to-date copy of the last anchor fired */
180  if (len != 0)
181  {
182  hypertext->lastAnchorFired.data = STR_DataAlloc(len);
183  if (hypertext->lastAnchorFired.data)
184  {
185  /* Not out of memory */
186  hypertext->lafAlloc = MHEG5TRUE;
187 
188  for (j = 0; j != len; j++)
189  {
190  /* Note conversion from (unsigned short) to (MHEG5Byte) */
191  hypertext->lastAnchorFired.data[j] = (MHEG5Byte)data[i + 3 + j];
192  }
193  hypertext->lastAnchorFired.len = len;
194  }
195  else
196  {
197  hypertext->lastAnchorFired.len = 0;
198  }
199  }
200  else
201  {
202  hypertext->lastAnchorFired.data = NULL;
203  hypertext->lastAnchorFired.len = 0;
204  }
205 
206  /* Send the anchor fired event with anchor as parameter */
208  LNK_GetStringIndex( hypertext->lastAnchorFired ));
209  break;
210  }
211  }
212  }
213  }
214 }
215 
217 {
218  hypertext->focusPosition = 0;
219  hypertext->numberOfLinks = -1;
220  hypertext->anchorWrappingFlag = MHEG5FALSE;
221 }
222 
223 /*
224  Constructor
225  */
232 {
233  assert(hypertext);
234 
235  MHEG5textInit(&hypertext->text);
236  MHEG5interactibleInit(&hypertext->interactible);
237 }
238 
247 {
248  assert(hypertext);
249 
250  /* free any previous anchor string */
251  if (hypertext->lafAlloc)
252  {
253  MHEG5stringDestruct( &hypertext->lastAnchorFired );
254  }
255  MHEG5textFree(&hypertext->text);
256  MHEG5interactibleFree(&hypertext->interactible);
257 }
258 
259 /*
260  Internal behaviours
261  */
263 {
264  assert(hypertext);
265 
267 
268  hypertext->numberOfLinks = -1;
269  hypertext->focusPosition = 0;
270  hypertext->lastFocusPosition = 0;
271  hypertext->anchorWrappingFlag = MHEG5FALSE;
272 
273  MHEG5textPrepare(&hypertext->text);
274 }
275 
277 {
278  assert(hypertext);
279  if (!hypertext->text.visible.ingredient.root.runningStatus)
280  {
282  {
284  hypertext->lastFocusPosition = 0;
285  }
287  MHEG5textActivate(&hypertext->text);
288  }
289 }
290 
292 {
293  assert(hypertext);
294  MHEG5textDeactivate(&hypertext->text);
295 
296  /* Apply deactivation behaviour inherrited from Interactible class */
298 }
299 
301 {
302  assert(hypertext);
303 
304  MHEG5textDestruct(&hypertext->text);
306 }
307 
309 {
310  MHEG5Root *var = 0;
311  MHEG5Hypertext *hypertext;
312  MHEG5OctetStringVariable *oc_var;
313 
314  assert(target);
315 
316  if (target->clazz != MHEG5HYPERTEXT)
317  {
318  return MHEG5ERR_WRONGTARGET;
319  }
320 
321  if (!params)
322  {
324  }
325  MHEG5resolveORef(params, &var);
326  if (!var)
327  {
329  }
330  if (var->clazz != MHEG5OCTETSTRINGVARIABLE)
331  {
332  return MHEG5ERR_WRONGPARAM;
333  }
334 
335  oc_var = (MHEG5OctetStringVariable *)var;
336  hypertext = (MHEG5Hypertext *)target;
337  MHEG5stringDestruct(&oc_var->value);
338  oc_var->value = MHEG5stringCopy( hypertext->lastAnchorFired );
339 
340  return MHEG5ERR_NOERROR;
341 }
342 
344 {
345  MHEG5Root *var = 0;
346  MHEG5Hypertext *hypertext;
347  MHEG5IntegerVariable *i_var;
348 
349  if (target->clazz != MHEG5HYPERTEXT)
350  {
351  return MHEG5ERR_WRONGTARGET;
352  }
353  if (!params)
354  {
356  }
357  MHEG5resolveORef(params, &var);
358  if (!var)
359  {
361  }
362  if (var->clazz != MHEG5INTEGERVARIABLE)
363  {
364  return MHEG5ERR_WRONGPARAM;
365  }
366 
367  i_var = (MHEG5IntegerVariable *)var;
368  hypertext = (MHEG5Hypertext *)target;
369 
370  i_var->value = hypertext->focusPosition;
371 
372  return MHEG5ERR_NOERROR;
373 }
374 
376 {
377  MHEG5Int focusPosition;
378  MHEG5Hypertext *hypertext;
379 
380  assert(target);
381 
382  if (target->clazz != MHEG5HYPERTEXT)
383  {
384  return MHEG5ERR_WRONGTARGET;
385  }
386  if (!params)
387  {
389  }
390  MHEG5resolveGenericInteger(params, &focusPosition);
391 
392  hypertext = (MHEG5Hypertext *)target;
393  hypertext->focusPosition = focusPosition;
394  MHEG5drawHypertext(hypertext);
395  return MHEG5ERR_NOERROR;
396 }
397 
MHEG5Bool availabilityStatus
Definition: mh5root.h:52
MHEG5Visible visible
Definition: mh5text.h:62
MHEG5Byte * data
Definition: mh5ingredient.h:80
MHEG5Interactible interactible
Definition: mh5hypertext.h:49
Implement the MHEG5 Hypertext Class. The HyperText class is a subclass of the Text class...
MHEG5ErrorCode MHEG5setFocusPosition(MHEG5Root *target, MHEG5GList *params)
Definition: mh5hypertext.c:375
const char * data
Definition: mh5gate.c:56
void MHEG5drawHypertext(MHEG5Hypertext *hypertxt)
Definition: mh5drawtext.c:578
MHEG5ErrorCode MHEG5getLastAnchorFired(MHEG5Root *target, MHEG5GList *params)
Definition: mh5hypertext.c:308
unsigned char * STR_DataAlloc(unsigned int size)
Definition: glue_memory.c:596
MHEG5GList * MHEG5resolveGenericInteger(MHEG5GList *params, MHEG5Int *value)
Definition: mh5object.c:510
MHEG5Bool lafAlloc
Definition: mh5hypertext.h:61
void MHEG5textDestruct(MHEG5Text *text)
Destruct a text object.
Definition: mh5text.c:365
void MHEG5hypertextPrepare(MHEG5Hypertext *hypertext)
Definition: mh5hypertext.c:262
MHEG5Final clazz
Definition: mh5root.h:55
void MHEG5interactibleDestruct(MHEG5Interactible *interactible)
MHEG5Int numberOfLinks
Definition: mh5hypertext.h:58
MHEG5ErrorCode MHEG5getFocusPosition(MHEG5Root *target, MHEG5GList *params)
Definition: mh5hypertext.c:343
MHEG5String MHEG5stringCopy(MHEG5String source)
<Function description>="">
Definition: mh5base.c:574
void MHEG5textPrepare(MHEG5Text *text)
Apply the preparation behaviour of the text class Apply the preparation behaviour of the text class...
Definition: mh5text.c:293
Implement the MHEG5 Variable Class 21 Variable Class Defines a variable within the context of a Group...
void MHEG5stringDestruct(MHEG5String *item)
Destruct a MHEG5String.
Definition: mh5base.c:686
void MHEG5hypertextDOWN(MHEG5Hypertext *hypertext)
Definition: mh5hypertext.c:108
long MHEG5Int
Definition: mh5base.h:73
MHEG5String lastAnchorFired
Definition: mh5hypertext.h:54
void MHEG5interactibleDeactivate(MHEG5Interactible *interactible)
Implementation of the deactivation behaviour of the interactible class. This behaviour was introduced...
void MHEG5hypertextSELECT(MHEG5Hypertext *hypertext)
Definition: mh5hypertext.c:140
MHEG5ErrorCode
Definition: mh5base.h:222
unsigned char MHEG5Byte
Definition: mh5base.h:74
Event handling. Implementation of a combined queue for events and actions. This is the eventsystem wh...
MHEG5Text text
Definition: mh5hypertext.h:48
MHEG5Byte * data
Definition: mh5base.h:85
void MHEG5textDeactivate(MHEG5Text *text)
Apply the deactivation behaviour of the text class. As this class has no own deactivation behaviour t...
Definition: mh5text.c:348
int len
Definition: mh5gate.c:57
void MHEG5textInit(MHEG5Text *text)
<Function description>="">
Definition: mh5text.c:190
#define MHEG5TRUE
Definition: mh5base.h:49
MHEG5Bool anchorWrappingFlag
Definition: mh5hypertext.h:60
Implement functions to retrieve MHEG5objects by GroupID and ID.
void MHEG5hyperTextInitCurrentLink(MHEG5Hypertext *hypertext)
Definition: mh5hypertext.c:216
void MHEG5textActivate(MHEG5Text *text)
Apply the activation behaviour of the text class. As this class has no own activation behaviour this ...
Definition: mh5text.c:330
void MHEG5hypertextUP(MHEG5Hypertext *hypertext)
Definition: mh5hypertext.c:72
MHEG class interface to graphics text render.
void MHEG5hypertextDestruct(MHEG5Hypertext *hypertext)
Definition: mh5hypertext.c:300
void MHEG5hypertextActivate(MHEG5Hypertext *hypertext)
Definition: mh5hypertext.c:276
MHEG5Bool runningStatus
Definition: mh5root.h:51
MHEG5Ingredient ingredient
Definition: mh5visible.h:49
MHEG5Int lastFocusPosition
Definition: mh5hypertext.h:59
void MHEG5interactibleInit(MHEG5Interactible *interactible)
<Function description>="">
redirection include
void MHEG5hypertextInit(MHEG5Hypertext *hypertext)
Initialise a hypertext object with default values.
Definition: mh5hypertext.c:231
void MHEG5sendEvent(MHEG5Root *source, MHEG5EventType event, MHEG5Int data)
Store an event in the asynchronous event queue.
Definition: mh5queue.c:1540
MHEG5Int len
Definition: mh5base.h:84
void MHEG5interactibleFree(MHEG5Interactible *interactible)
Free off all memory associated with the specified object, including any exchanged attributes and inte...
MHEG5Int focusPosition
Definition: mh5hypertext.h:55
MHEG5GList * MHEG5resolveORef(MHEG5GList *params, MHEG5Root **object)
Definition: mh5object.c:126
void MHEG5textFree(MHEG5Text *text)
Free off all memory associated with the specified object, including any exchanged attributes and inte...
Definition: mh5text.c:204
Implement generic MHEG5-display functions - independent from the OSD These are generic functions used...
void MHEG5hypertextDeactivate(MHEG5Hypertext *hypertext)
Definition: mh5hypertext.c:291
void MHEG5interactiblePrepare(MHEG5Interactible *interactible)
Sets all internal attributes for the specified object to their default values.
#define MHEG5FALSE
Definition: mh5base.h:48
void MHEG5hypertextFree(MHEG5Hypertext *hypertext)
Free off all memory associated with the specified object, including any exchanged attributes and inte...
Definition: mh5hypertext.c:246