1 /************************************************************************/
2 /*									*/
3 /*  Ted: Get/Set/Delete Hyperlinks.					*/
4 /*									*/
5 /************************************************************************/
6 
7 #   include	"tedConfig.h"
8 
9 #   include	<stddef.h>
10 #   include	<stdio.h>
11 
12 #   include	"tedEdit.h"
13 #   include	"tedDocFront.h"
14 #   include	"tedDocument.h"
15 #   include	"tedSelect.h"
16 #   include	<docField.h>
17 #   include	<docHyperlinkField.h>
18 #   include	<docBookmarkField.h>
19 #   include	<docEditCommand.h>
20 
21 #   include	<appDebugon.h>
22 
tedDocSetHyperlink(EditDocument * ed,const HyperlinkField * hf,int traced)23 int tedDocSetHyperlink(	EditDocument *		ed,
24 			const HyperlinkField *	hf,
25 			int			traced )
26     {
27     int				rval= 0;
28     TedDocument *		td= (TedDocument *)ed->edPrivateData;
29     BufferDocument *		bd= td->tdDocument;
30 
31     DocumentSelection		ds;
32     SelectionGeometry		sg;
33     SelectionDescription	sd;
34 
35     DocumentField *		dfHyperlink;
36 
37     TedEditOperation		teo;
38     EditOperation *		eo= &(teo.teoEo);
39 
40     TextAttribute		taSet;
41     PropertyMask		taSetMask;
42 
43     FieldInstructions		fi;
44 
45     const int			fullWidth= 0;
46 
47     docInitFieldInstructions( &fi );
48 
49     utilInitTextAttribute( &taSet );
50     utilPropMaskClear( &taSetMask );
51 
52     tedStartEditOperation( &teo, &sg, &sd, ed, fullWidth, traced );
53 
54     docEditOperationGetSelection( &ds, eo );
55 
56     if  ( docSetHyperlinkField( &fi, hf ) )
57 	{ LDEB(1); rval= -1; goto ready;	}
58 
59     dfHyperlink= docFindTypedFieldForPosition( bd, &(ds.dsHead),
60 							DOCfkHYPERLINK, 0 );
61     if  ( ! dfHyperlink )
62 	{
63 	if  ( docSetHyperlinkAttribute( &taSet, &taSetMask, bd ) )
64 	    { LDEB(1); rval= -1; goto ready;	}
65 
66 	if  ( tedDocSetField( &teo, &ds,
67 				EDITcmdSET_HYPERLINK, DOCfkHYPERLINK,
68 				&fi, &taSetMask, &taSet ) )
69 	    { LDEB(1); rval= -1; goto ready;	}
70 	}
71     else{
72 	if  ( tedDocUpdField( &teo, dfHyperlink, &fi ) )
73 	    { LDEB(1); rval= -1; goto ready;	}
74 	}
75 
76   ready:
77 
78     docCleanFieldInstructions( &fi );
79     tedCleanEditOperation( &teo );
80 
81     return rval;
82     }
83 
tedDocRemoveHyperlink(EditDocument * ed,int traced)84 int tedDocRemoveHyperlink(	EditDocument *		ed,
85 				int			traced )
86     {
87     TedDocument *		td= (TedDocument *)ed->edPrivateData;
88     BufferDocument *		bd= td->tdDocument;
89 
90     PropertyMask		taSetMask;
91     TextAttribute		taSet;
92 
93     if  ( docRemoveHyperlinkAttribute( &taSet, &taSetMask, bd ) )
94 	{ LDEB(1); return -1;	}
95 
96     return tedDocFlattenTypedField( ed, DOCfkHYPERLINK,
97 						&taSetMask, &taSet, traced );
98     }
99 
tedDocFindBookmarkField(DocumentField ** pDf,EditDocument * ed,const MemoryBuffer * markName)100 int tedDocFindBookmarkField(	DocumentField **		pDf,
101 				EditDocument *			ed,
102 				const MemoryBuffer *		markName )
103     {
104     TedDocument *		td= (TedDocument *)ed->edPrivateData;
105     BufferDocument *		bd= td->tdDocument;
106 
107     return docFindBookmarkField( pDf, &(bd->bdFieldList), markName );
108     }
109 
tedDocSetBookmark(EditDocument * ed,const MemoryBuffer * markName,int traced)110 int tedDocSetBookmark(	EditDocument *		ed,
111 			const MemoryBuffer *	markName,
112 			int			traced )
113     {
114     int				rval= 0;
115     TedDocument *		td= (TedDocument *)ed->edPrivateData;
116     BufferDocument *		bd= td->tdDocument;
117 
118     DocumentField *		dfBookmark;
119 
120     TedEditOperation		teo;
121     EditOperation *		eo= &(teo.teoEo);
122 
123     DocumentSelection		ds;
124     SelectionGeometry		sg;
125     SelectionDescription	sd;
126 
127     DocumentField *		dfFound;
128     FieldInstructions		fi;
129 
130     const int			fullWidth= 0;
131 
132     docInitFieldInstructions( &fi );
133 
134     tedStartEditOperation( &teo, &sg, &sd, ed, fullWidth, traced );
135 
136     docEditOperationGetSelection( &ds, eo );
137 
138     if  ( docSetBookmarkField( &fi, markName ) )
139 	{ LDEB(1); rval= -1; goto ready;	}
140 
141     if  ( docFindBookmarkField( &dfFound, &(bd->bdFieldList), markName ) >= 0 )
142 	{ LDEB(1); rval= -1; goto ready;	}
143 
144     dfBookmark= docFindTypedFieldForPosition( bd, &(ds.dsHead),
145 							    DOCfkBOOKMARK, 0 );
146     if  ( ! dfBookmark )
147 	{
148 	if  ( tedDocSetField( &teo, &ds,
149 		    EDITcmdSET_BOOKMARK, DOCfkBOOKMARK,
150 		    &fi, (const PropertyMask *)0, (const TextAttribute *)0 ) )
151 	    { LDEB(1); rval= -1; goto ready;	}
152 	}
153     else{
154 	if  ( tedDocUpdField( &teo, dfBookmark, &fi ) )
155 	    { LDEB(1); rval= -1; goto ready;	}
156 	}
157 
158   ready:
159 
160     docCleanFieldInstructions( &fi );
161     tedCleanEditOperation( &teo );
162 
163     return rval;
164     }
165 
166 /************************************************************************/
167 /*									*/
168 /*  Remove the bookmark that holds the head of the selection.		*/
169 /*  The contents of the bookmark are retained: Only the field is	*/
170 /*  removed.								*/
171 /*									*/
172 /************************************************************************/
173 
tedDocRemoveBookmark(EditDocument * ed,int traced)174 int tedDocRemoveBookmark(	EditDocument *		ed,
175 				int			traced )
176     {
177     return tedDocFlattenTypedField( ed, DOCfkBOOKMARK,
178 		(const PropertyMask *)0, (const TextAttribute *)0, traced );
179     }
180 
181 /************************************************************************/
182 /*									*/
183 /*  Select a particular bookmark in a document.				*/
184 /*									*/
185 /************************************************************************/
186 
tedDocGoToBookmark(EditDocument * ed,const MemoryBuffer * markName)187 int tedDocGoToBookmark(	EditDocument *		ed,
188 			const MemoryBuffer *	markName )
189     {
190     DocumentSelection		dsInside;
191     int				partHead;
192     int				partTail;
193 
194     TedDocument *		td;
195 
196     const int			lastLine= 0;
197 
198     if  ( ! markName )
199 	{ XDEB(markName); return -1;	}
200 
201     td= (TedDocument *)ed->edPrivateData;
202 
203     docInitDocumentSelection( &dsInside );
204 
205     if  ( docFindBookmarkInDocument( &dsInside, &partHead, &partTail,
206 						td->tdDocument, markName ) )
207 	{ LDEB(1); return -1;	}
208 
209     tedSetSelection( ed, &dsInside, lastLine, (int *)0, (int *)0 );
210 
211     return 0;
212     }
213 
214