1 /************************************************************************/
2 /* */
3 /* Buffer administration routines. */
4 /* */
5 /************************************************************************/
6
7 # include "docBaseConfig.h"
8
9 # include <appDebugon.h>
10
11 # include "docListAdmin.h"
12 # include "docDocumentList.h"
13 # include "docListOverride.h"
14
15 /************************************************************************/
16 /* */
17 /* Initialise Document Properties. */
18 /* */
19 /************************************************************************/
20
docInitListAdmin(ListAdmin * la)21 void docInitListAdmin( ListAdmin * la )
22 {
23 docInitListTable( &(la->laListTable) );
24 docInitListOverrideTable( &(la->laListOverrideTable) );
25
26 }
27
docCleanListAdmin(ListAdmin * la)28 void docCleanListAdmin( ListAdmin * la )
29 {
30 docCleanListTable( &(la->laListTable) );
31 docCleanListOverrideTable( &(la->laListOverrideTable) );
32
33 return;
34 }
35
docCopyListAdmin(ListAdmin * to,const ListAdmin * from)36 int docCopyListAdmin( ListAdmin * to,
37 const ListAdmin * from )
38 {
39 if ( docCopyListTable( &(to->laListTable), &(from->laListTable) ) )
40 { LDEB(1); return -1; }
41
42 if ( docCopyListOverrideTable( &(to->laListOverrideTable),
43 &(from->laListOverrideTable) ) )
44 { LDEB(1); return -1; }
45
46 return 0;
47 }
48
49 /************************************************************************/
50 /* */
51 /* As at least MS-Word 2000 crashes on lists without an override, */
52 /* and on the other hand staroffice/openoffice creates them under */
53 /* certain circumstances: Make an empty override for lists without */
54 /* overrides. */
55 /* */
56 /************************************************************************/
57
docMakeOverrideForEveryList(ListAdmin * la)58 int docMakeOverrideForEveryList( ListAdmin * la )
59 {
60 const DocumentListTable * dlt= &(la->laListTable);
61 const DocumentList * dl;
62
63 int li;
64
65 ListOverrideTable * lot= &(la->laListOverrideTable);
66
67 dl= dlt->dltLists;
68 for ( li= 0; li < dlt->dltListCount; dl++, li++ )
69 {
70 int ov;
71 const ListOverride * lo;
72
73 lo= lot->lotOverrides;
74 for ( ov= 0; ov < lot->lotOverrideCount; lo++, ov++ )
75 {
76 if ( lo->loIndex < 1 )
77 { continue; }
78
79 if ( lo->loListID == dl->dlListID )
80 { break; }
81 }
82
83 if ( ov >= lot->lotOverrideCount )
84 {
85 int ls;
86
87 ls= docListOverrideTableAddOverride( (ListOverride **)0, lot,
88 -1, dl->dlListID, li );
89 if ( ls < 0 )
90 { LDEB(ls); return -1; }
91 }
92 }
93
94 return 0;
95 }
96
docMergeListAdmins(ListAdmin * laTo,const ListAdmin * laFrom,const int * lsUsed,int * lsMap,const int * listUsed,const int * fontMap,const int * colorMap,const int * rulerMap)97 int docMergeListAdmins( ListAdmin * laTo,
98 const ListAdmin * laFrom,
99 const int * lsUsed,
100 int * lsMap,
101 const int * listUsed,
102 const int * fontMap,
103 const int * colorMap,
104 const int * rulerMap )
105 {
106 const DocumentListTable * dltFrom= &(laFrom->laListTable);
107 DocumentListTable * dltTo= &(laTo->laListTable);
108 const ListOverrideTable * lotFrom= &(laFrom->laListOverrideTable);
109 ListOverrideTable * lotTo= &(laTo->laListOverrideTable);
110 const DocumentList * dl;
111 const ListOverride * lo;
112
113 int from;
114 int listStylesAdded= 0;
115
116 lo= lotFrom->lotOverrides;
117 for ( from= 0; from < lotFrom->lotOverrideCount; lo++, from++ )
118 {
119 int oldCount= lotTo->lotOverrideCount;
120
121 int listStyle;
122
123 if ( ! lsUsed[from] )
124 { continue; }
125
126 listStyle= docMergeListOverrideIntoTable( lotTo, lo,
127 fontMap, colorMap, rulerMap );
128 if ( listStyle < 0 )
129 { LDEB(listStyle); return -1; }
130 lsMap[from]= listStyle;
131
132 if ( listStyle >= oldCount )
133 { listStylesAdded++; }
134 }
135
136 dl= dltFrom->dltLists;
137 for ( from= 0; from < dltFrom->dltListCount; dl++, from++ )
138 {
139 int listIndex;
140
141 if ( ! listUsed[from] )
142 { continue; }
143
144 listIndex= docMergeListIntoTable( dltTo, dltFrom->dltLists+ from,
145 fontMap, colorMap, rulerMap );
146 if ( listIndex < 0 )
147 { LLDEB(from,listIndex); return -1; }
148 }
149
150 return listStylesAdded;
151 }
152
docGetListOfOverride(ListOverride * lo,const DocumentListTable * dlt)153 int docGetListOfOverride( ListOverride * lo,
154 const DocumentListTable * dlt )
155 {
156 int li;
157 const DocumentList * dl;
158
159 if ( lo->loListIndex >= 0 )
160 { return lo->loListIndex; }
161
162 dl= dlt->dltLists;
163 for ( li= 0; li < dlt->dltListCount; dl++, li++ )
164 {
165 if ( dl->dlListID == lo->loListID )
166 { lo->loListIndex= li; return li; }
167 }
168
169 LDEB(lo->loListID);
170 return -1;
171 }
172
docGetListForStyle(ListOverride ** pLo,DocumentList ** pDl,int ls,const ListAdmin * la)173 int docGetListForStyle( ListOverride ** pLo,
174 DocumentList ** pDl,
175 int ls,
176 const ListAdmin * la )
177 {
178 const ListOverrideTable * lot= &(la->laListOverrideTable);
179 const DocumentListTable * dlt= &(la->laListTable);
180
181 ListOverride * lo;
182 DocumentList * dl= (DocumentList *)0;
183
184 /* 1 */
185 if ( ls < 0 || ls >= lot->lotOverrideCount )
186 { LLDEB(ls,lot->lotOverrideCount); return -1; }
187
188 /* 2 */
189 lo= lot->lotOverrides+ ls;
190
191 /* 3,4 */
192 if ( lo->loListIndex < 0 && docGetListOfOverride( lo, dlt ) < 0 )
193 { LLDEB(lo->loListIndex,dlt->dltListCount); return -1; }
194
195 dl= dlt->dltLists+ lo->loListIndex;
196
197 if ( pLo )
198 { *pLo= lo; }
199 if ( pDl )
200 { *pDl= dl; }
201
202 return 0;
203 }
204
205 /************************************************************************/
206 /* */
207 /* Determine the path of number styles and formatting instructions */
208 /* to a certain level. */
209 /* */
210 /************************************************************************/
211
docListGetFormatPath(int * startPath,int * formatPath,const ListLevel ** pLl,int ilvl,const DocumentList * dl,const ListOverride * lo)212 int docListGetFormatPath( int * startPath,
213 int * formatPath,
214 const ListLevel ** pLl,
215 int ilvl,
216 const DocumentList * dl,
217 const ListOverride * lo )
218 {
219 int level= 0;
220 const ListLevel * dllFound= (const ListLevel *)0;
221
222 if ( dl->dlLevelCount < 1 ||
223 dl->dlLevelCount > DLmaxLEVELS )
224 { LLDEB(dl->dlLevelCount,DLmaxLEVELS); return -1; }
225
226 while( level < dl->dlLevelCount )
227 {
228 const ListLevel * ll= (const ListLevel *)0;
229 const ListOverrideLevel * lol= (const ListOverrideLevel *)0;
230
231 int startAt= 0;
232
233 if ( level < lo->loLevelCount )
234 { lol= &(lo->loLevels[level]); }
235 if ( level < dl->dlLevelCount )
236 { ll= &(dl->dlLevels[level]); }
237
238 if ( ll )
239 { startAt= ll->llStartAt; }
240 if ( lol && lol->lolOverrideStartAt )
241 { startAt= lol->lolListLevel.llStartAt; }
242
243 if ( lol && lol->lolOverrideFormat )
244 { ll= &(lol->lolListLevel); }
245
246 if ( startPath )
247 { startPath[level]= startAt; }
248 if ( formatPath && ll )
249 { formatPath[level]= ll->llNumberStyle; }
250
251 if ( level == ilvl )
252 { dllFound= ll; }
253
254 level++;
255 }
256
257 if ( ! dllFound )
258 { XDEB(dllFound); return -1; }
259
260 *pLl= dllFound;
261 return 0;
262 }
263
264