Merge branch 'master' of https://git.maemo.org/projects/erwise
[erwise] / Cl / WWWLibrary / HTAnchor.h
1 /*      Hypertext "Anchor" Object                                    HTAnchor.h
2 **      ==========================
3 **
4 **      An anchor represents a region of a hypertext document which is linked
5 **      to another anchor in the same or a different document.
6 */
7
8 #ifndef HTANCHOR_H
9 #define HTANCHOR_H
10
11 /* Version 0 (TBL) written in Objective-C for the NeXT browser */
12 /* Version 1 of 24-Oct-1991 (JFG), written in C, browser-independant */
13
14 #include "HTList.h"
15 #include "HTAtom.h"
16
17 #ifdef SHORT_NAMES
18 #define HTAnchor_findChild                      HTAnFiCh
19 #define HTAnchor_findChildAndLink               HTAnFiLi
20 #define HTAnchor_findAddress                    HTAnFiAd
21 #define HTAnchor_delete                         HTAnDele
22 #define HTAnchor_makeLastChild                  HTAnMaLa
23 #define HTAnchor_parent                         HTAnPare
24 #define HTAnchor_setDocument                    HTAnSeDo
25 #define HTAnchor_document                       HTAnDocu
26 #define HTAnchor_setFormat                      HTAnSeFo
27 #define HTAnchor_format                         HTAnForm
28 #define HTAnchor_setIndex                       HTAnSeIn
29 #define HTAnchor_isIndex                        HTAnIsIn
30 #define HTAnchor_address                        HTAnAddr
31 #define HTAnchor_hasChildren                    HTAnHaCh
32 #define HTAnchor_title                          HTAnTitl
33 #define HTAnchor_setTitle                       HTAnSeTi
34 #define HTAnchor_appendTitle                    HTAnApTi
35 #define HTAnchor_link                           HTAnLink
36 #define HTAnchor_followMainLink                 HTAnFoMa
37 #define HTAnchor_followTypedLink                HTAnFoTy
38 #define HTAnchor_makeMainLink                   HTAnMaMa
39 #endif
40
41 /*                      Main definition of anchor
42 **                      =========================
43 */
44
45 typedef struct _HyperDoc HyperDoc;  /* Ready for forward references */
46 typedef struct _HTAnchor HTAnchor;
47 typedef struct _HTParentAnchor HTParentAnchor;
48
49 #include "HTFormat.h"
50
51 typedef HTAtom HTLinkType;
52
53 typedef struct {
54   HTAnchor *    dest;           /* The anchor to which this leads */
55   HTLinkType *  type;           /* Semantics of this link */
56 } HTLink;
57
58 struct _HTAnchor {              /* Generic anchor : just links */
59   HTLink        mainLink;       /* Main (or default) destination of this */
60   HTList *      links;          /* List of extra links from this, if any */
61   /* We separate the first link from the others to avoid too many small mallocs
62      involved by a list creation. Most anchors only point to one place. */
63   HTParentAnchor * parent;      /* Parent of this anchor (self for adults) */
64 };
65
66 struct _HTParentAnchor {
67   /* Common part from the generic anchor structure */
68   HTLink        mainLink;       /* Main (or default) destination of this */
69   HTList *      links;          /* List of extra links from this, if any */
70   HTParentAnchor * parent;      /* Parent of this anchor (self) */
71
72   /* ParentAnchor-specific information */
73   HTList *      children;       /* Subanchors of this, if any */
74   HTList *      sources;        /* List of anchors pointing to this, if any */
75   HyperDoc *    document;       /* The document within which this is an anchor */
76   char *        address;        /* Absolute address of this node */
77   HTFormat *    format;         /* Pointer to node format descriptor */
78   BOOL          isIndex;        /* Acceptance of a keyword search */
79   char *        title;          /* Title of document */
80 };
81
82 typedef struct {
83   /* Common part from the generic anchor structure */
84   HTLink        mainLink;       /* Main (or default) destination of this */
85   HTList *      links;          /* List of extra links from this, if any */
86   HTParentAnchor * parent;      /* Parent of this anchor */
87
88   /* ChildAnchor-specific information */
89   char *        tag;            /* Address of this anchor relative to parent */
90 } HTChildAnchor;
91
92
93 /*      Create new or find old sub-anchor
94 **      ---------------------------------
95 **
96 **      This one is for a new anchor being edited into an existing
97 **      document. The parent anchor must already exist.
98 */
99
100 extern HTChildAnchor * HTAnchor_findChild
101   PARAMS(
102      (HTParentAnchor *parent,
103       CONST char *tag)
104   );
105
106 /*      Create or find a child anchor with a possible link
107 **      --------------------------------------------------
108 **
109 **      Create new anchor with a given parent and possibly
110 **      a name, and possibly a link to a _relatively_ named anchor.
111 **      (Code originally in ParseHTML.h)
112 */
113 extern HTChildAnchor * HTAnchor_findChildAndLink
114   PARAMS((
115       HTParentAnchor * parent,  /* May not be 0 */
116       CONST char * tag,         /* May be "" or 0 */
117       CONST char * href,        /* May be "" or 0 */
118       HTLinkType * ltype        /* May be 0 */
119   ));
120
121
122 /*      Create new or find old named anchor
123 **      -----------------------------------
124 **
125 **      This one is for a reference which is found in a document, and might
126 **      not be already loaded.
127 **      Note: You are not guaranteed a new anchor -- you might get an old one,
128 **      like with fonts.
129 */
130
131 extern HTAnchor * HTAnchor_findAddress
132   PARAMS(
133      (CONST char * address)
134      );
135
136
137 /*      Delete an anchor and possibly related things (auto garbage collection)
138 **      --------------------------------------------
139 **
140 **      The anchor is only deleted if the corresponding document is not loaded.
141 **      All outgoing links from parent and children are deleted, and this anchor
142 **      is removed from the sources list of all its targets.
143 **      We also try to delete the targets whose documents are not loaded.
144 **      If this anchor's source list is empty, we delete it and its children.
145 */
146
147 extern BOOL HTAnchor_delete
148   PARAMS(
149      (HTParentAnchor *this)
150      );
151
152
153 /*              Move an anchor to the head of the list of its siblings
154 **              ------------------------------------------------------
155 **
156 **      This is to ensure that an anchor which might have already existed
157 **      is put in the correct order as we load the document.
158 */
159
160 extern void HTAnchor_makeLastChild
161   PARAMS(
162      (HTChildAnchor *this)
163      );
164
165 /*      Data access functions
166 **      ---------------------
167 */
168
169 extern HTParentAnchor * HTAnchor_parent
170   PARAMS(
171      (HTAnchor *this)
172      );
173
174 extern void HTAnchor_setDocument
175   PARAMS(
176      (HTParentAnchor *this, HyperDoc *doc)
177      );
178
179 extern HyperDoc * HTAnchor_document
180   PARAMS(
181      (HTParentAnchor *this)
182      );
183 /* We don't want code to change an address after anchor creation... yet ?
184 extern void HTAnchor_setAddress
185   PARAMS(
186      (HTAnchor *this, char *addr)
187      );
188 */
189
190 extern char * HTAnchor_address
191   PARAMS(
192      (HTAnchor *this)
193      );
194
195 extern void HTAnchor_setFormat
196   PARAMS(
197      (HTParentAnchor *this, HTFormat *form)
198      );
199
200 extern HTFormat * HTAnchor_format
201   PARAMS(
202      (HTParentAnchor *this)
203      );
204
205 extern void HTAnchor_setIndex
206   PARAMS(
207      (HTParentAnchor *this)
208      );
209
210 extern BOOL HTAnchor_isIndex
211   PARAMS(
212      (HTParentAnchor *this)
213      );
214
215 extern BOOL HTAnchor_hasChildren
216   PARAMS(
217      (HTParentAnchor *this)
218      );
219
220 /*      Title handling
221 */
222 extern CONST char * HTAnchor_title
223   PARAMS(
224      (HTParentAnchor *this)
225      );
226
227 extern void HTAnchor_setTitle
228   PARAMS(
229      (HTParentAnchor *this, CONST char * title)
230      );
231
232 extern void HTAnchor_appendTitle
233   PARAMS(
234      (HTParentAnchor *this, CONST char * title)
235      );
236
237 /*      Link this Anchor to another given one
238 **      -------------------------------------
239 */
240
241 extern BOOL HTAnchor_link
242   PARAMS(
243      (HTAnchor *source, HTAnchor *destination, HTLinkType *type)
244      );
245
246 /*      Manipulation of links
247 **      ---------------------
248 */
249
250 extern HTAnchor * HTAnchor_followMainLink
251   PARAMS(
252      (HTAnchor *this)
253      );
254
255 extern HTAnchor * HTAnchor_followTypedLink
256   PARAMS(
257      (HTAnchor *this, HTLinkType *type)
258      );
259
260 extern BOOL HTAnchor_makeMainLink
261   PARAMS(
262      (HTAnchor *this, HTLink *movingLink)
263      );
264
265 #endif /* HTANCHOR_H */