1 /************************************************************************/
2 /* */
3 /* Keep a collection TextAttributes by number. */
4 /* */
5 /************************************************************************/
6
7 # include "docBaseConfig.h"
8
9 # include <stdlib.h>
10
11 # include <appDebugon.h>
12
13 # include "docFramePropertiesAdmin.h"
14
15 /************************************************************************/
16 /* */
17 /* Initialize/Clean attribute administration. */
18 /* */
19 /************************************************************************/
20
docInitFramePropertyList(NumberedPropertiesList * fpl)21 void docInitFramePropertyList( NumberedPropertiesList * fpl )
22 {
23 int num;
24 FrameProperties fp;
25
26 utilInitNumberedPropertiesList( fpl );
27
28 utilStartNumberedPropertyList( fpl,
29
30 TFPprop_COUNT,
31 (NumberedPropertiesGetProperty)docGetFrameProperty,
32
33 sizeof(FrameProperties),
34 (InitPagedListItem)docInitFrameProperties,
35 (CleanPagedListItem)0 );
36
37 docInitFrameProperties( &fp );
38
39 num= docFramePropertiesNumberImpl( fpl, &fp );
40 if ( num != 0 )
41 { LDEB(num); }
42
43 return;
44 }
45
46 /************************************************************************/
47 /* */
48 /* Translate a frame properties number to a struct value. */
49 /* */
50 /************************************************************************/
51
docGetFramePropertiesByNumberImpl(FrameProperties * fp,const NumberedPropertiesList * fpl,int n)52 void docGetFramePropertiesByNumberImpl( FrameProperties * fp,
53 const NumberedPropertiesList * fpl,
54 int n )
55 {
56 void * vfp= utilPagedListGetItemByNumber( &(fpl->nplPagedList), n );
57
58 if ( ! vfp )
59 { LXDEB(n,vfp); docInitFrameProperties( fp ); return; }
60
61 *fp= *((FrameProperties *)vfp);
62 return;
63 }
64
65 /************************************************************************/
66 /* */
67 /* Is this number really a border? */
68 /* */
69 /************************************************************************/
70
docFrameNumberIsFrameImpl(const NumberedPropertiesList * fpl,int n)71 int docFrameNumberIsFrameImpl( const NumberedPropertiesList * fpl,
72 int n )
73 {
74 FrameProperties fp;
75
76 if ( n < 0 )
77 { return 0; }
78
79 docGetFramePropertiesByNumberImpl( &fp, fpl, n );
80
81 return DOCisFRAME( &fp );
82 }
83
84 /************************************************************************/
85 /* */
86 /* Call a function for all FrameProperties in the list. */
87 /* */
88 /************************************************************************/
89
docForAllFrameProperties(const NumberedPropertiesList * fpl,FramePropertiesFunction f,void * through)90 void docForAllFrameProperties( const NumberedPropertiesList * fpl,
91 FramePropertiesFunction f,
92 void * through )
93 {
94 int n;
95
96 for ( n= 0; n < fpl->nplPagedList.plItemCount; n++ )
97 {
98 void * vbp= utilPagedListGetItemByNumber(
99 &(fpl->nplPagedList), n );
100
101 (*f)( (FrameProperties *)vbp, n, through );
102 }
103
104 return;
105 }
106
107 /************************************************************************/
108 /* */
109 /* Translate a text attribute to its number. */
110 /* */
111 /************************************************************************/
112
docFramePropertiesNumberImpl(NumberedPropertiesList * fpl,const FrameProperties * fp)113 int docFramePropertiesNumberImpl( NumberedPropertiesList * fpl,
114 const FrameProperties * fp )
115 {
116 const int make= 1;
117
118 return utilGetPropertyNumber( fpl, make, (void *)fp );
119 }
120
docMergeFramePropertyLists(int ** pFrameMap,NumberedPropertiesList * fplTo,const NumberedPropertiesList * fplFrom)121 int docMergeFramePropertyLists( int ** pFrameMap,
122 NumberedPropertiesList * fplTo,
123 const NumberedPropertiesList * fplFrom )
124 {
125 int fromCount= fplFrom->nplPagedList.plItemCount;
126
127 if ( fromCount > 0 )
128 {
129 int n;
130 int * frameMmap= (int *)malloc( fromCount* sizeof(int) );
131
132 if ( ! frameMmap )
133 { LXDEB(fromCount,frameMmap); return -1; }
134
135 for ( n= 0; n < fromCount; n++ )
136 { frameMmap[n]= -1; }
137
138 for ( n= 0; n < fromCount; n++ )
139 {
140 int to;
141 void * vfp;
142 FrameProperties fp;
143
144 vfp= utilPagedListGetItemByNumber( &(fplFrom->nplPagedList), n );
145 if ( ! vfp )
146 { continue; }
147
148 fp= *((FrameProperties *)vfp);
149
150 to= docFramePropertiesNumberImpl( fplTo, &fp );
151 if ( to < 0 )
152 { LDEB(to); free( frameMmap ); return -1; }
153 frameMmap[n]= to;
154 }
155
156 *pFrameMap= frameMmap;
157 }
158
159 return 0;
160 }
161
162