2 * RichEdit - Basic operations on double linked lists.
4 * Copyright 2004 by Krzysztof Foltman
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 WINE_DEFAULT_DEBUG_CHANNEL(richedit_lists
);
25 void ME_InsertBefore(ME_DisplayItem
*diWhere
, ME_DisplayItem
*diWhat
)
27 diWhat
->next
= diWhere
;
28 diWhat
->prev
= diWhere
->prev
;
30 diWhere
->prev
->next
= diWhat
;
31 diWhat
->next
->prev
= diWhat
;
34 void ME_Remove(ME_DisplayItem
*diWhere
)
36 ME_DisplayItem
*diNext
= diWhere
->next
;
37 ME_DisplayItem
*diPrev
= diWhere
->prev
;
40 diPrev
->next
= diNext
;
41 diNext
->prev
= diPrev
;
44 static BOOL
ME_DITypesEqual(ME_DIType type
, ME_DIType nTypeOrClass
)
48 case diRunOrParagraph
:
49 return type
== diRun
|| type
== diParagraph
;
51 return type
== diRun
|| type
== diStartRow
;
52 case diParagraphOrEnd
:
53 return type
== diTextEnd
|| type
== diParagraph
;
54 case diStartRowOrParagraph
:
55 return type
== diStartRow
|| type
== diParagraph
;
56 case diStartRowOrParagraphOrEnd
:
57 return type
== diStartRow
|| type
== diParagraph
|| type
== diTextEnd
;
58 case diRunOrParagraphOrEnd
:
59 return type
== diRun
|| type
== diParagraph
|| type
== diTextEnd
;
61 return type
== nTypeOrClass
;
65 /* Modifies run pointer to point to the next run, and modify the
66 * paragraph pointer if moving into the next paragraph.
68 * Returns TRUE if next run is found, otherwise returns FALSE. */
69 BOOL
ME_NextRun(ME_DisplayItem
**para
, ME_DisplayItem
**run
)
71 ME_DisplayItem
*p
= (*run
)->next
;
72 while (p
->type
!= diTextEnd
)
74 if (p
->type
== diParagraph
) {
76 } else if (p
->type
== diRun
) {
85 /* Modifies run pointer to point to the previous run, and modify the
86 * paragraph pointer if moving into the previous paragraph.
88 * Returns TRUE if previous run is found, otherwise returns FALSE. */
89 BOOL
ME_PrevRun(ME_DisplayItem
**para
, ME_DisplayItem
**run
)
91 ME_DisplayItem
*p
= (*run
)->prev
;
92 while (p
->type
!= diTextStart
)
94 if (p
->type
== diParagraph
) {
95 if (p
->member
.para
.prev_para
->type
== diParagraph
)
96 *para
= p
->member
.para
.prev_para
;
97 } else if (p
->type
== diRun
) {
106 ME_DisplayItem
*ME_FindItemBack(ME_DisplayItem
*di
, ME_DIType nTypeOrClass
)
112 if (ME_DITypesEqual(di
->type
, nTypeOrClass
))
119 ME_DisplayItem
*ME_FindItemBackOrHere(ME_DisplayItem
*di
, ME_DIType nTypeOrClass
)
122 if (ME_DITypesEqual(di
->type
, nTypeOrClass
))
129 ME_DisplayItem
*ME_FindItemFwd(ME_DisplayItem
*di
, ME_DIType nTypeOrClass
)
131 if (!di
) return NULL
;
134 if (ME_DITypesEqual(di
->type
, nTypeOrClass
))
141 void ME_DestroyDisplayItem(ME_DisplayItem
*item
)
143 /* TRACE("type=%s\n", ME_GetDITypeName(item->type)); */
144 if (item
->type
==diParagraph
)
146 FREE_OBJ(item
->member
.para
.pFmt
);
147 ME_DestroyString(item
->member
.para
.text
);
150 if (item
->type
==diRun
)
152 if (item
->member
.run
.ole_obj
) ME_DeleteReObject(item
->member
.run
.ole_obj
);
153 ME_ReleaseStyle(item
->member
.run
.style
);
158 ME_DisplayItem
*ME_MakeDI(ME_DIType type
)
160 ME_DisplayItem
*item
= ALLOC_OBJ(ME_DisplayItem
);
161 ZeroMemory(item
, sizeof(ME_DisplayItem
));
163 item
->prev
= item
->next
= NULL
;
164 if (type
== diParagraph
)
166 item
->member
.para
.pFmt
= ALLOC_OBJ(PARAFORMAT2
);
167 ME_SetDefaultParaFormat(item
->member
.para
.pFmt
);
168 item
->member
.para
.nFlags
= MEPF_REWRAP
;
174 const char *ME_GetDITypeName(ME_DIType type
)
178 case diParagraph
: return "diParagraph";
179 case diRun
: return "diRun";
180 case diCell
: return "diCell";
181 case diTextStart
: return "diTextStart";
182 case diTextEnd
: return "diTextEnd";
183 case diStartRow
: return "diStartRow";
188 void ME_DumpDocument(ME_TextBuffer
*buffer
)
190 /* FIXME this is useless, */
191 ME_DisplayItem
*pItem
= buffer
->pFirst
;
192 TRACE("DOCUMENT DUMP START\n");
200 TRACE("Cell(level=%d%s)\n", pItem
->member
.cell
.nNestingLevel
,
201 !pItem
->member
.cell
.next_cell
? ", END" :
202 (!pItem
->member
.cell
.prev_cell
? ", START" :""));
205 TRACE("Paragraph(ofs=%d)\n", pItem
->member
.para
.nCharOfs
);
206 if (pItem
->member
.para
.nFlags
& MEPF_ROWSTART
)
207 TRACE(" - (Table Row Start)\n");
208 if (pItem
->member
.para
.nFlags
& MEPF_ROWEND
)
209 TRACE(" - (Table Row End)\n");
212 TRACE(" - StartRow\n");
215 TRACE(" - Run(%s, %d, flags=%x)\n", debugstr_run( &pItem
->member
.run
),
216 pItem
->member
.run
.nCharOfs
, pItem
->member
.run
.nFlags
);
219 TRACE("End(ofs=%d)\n", pItem
->member
.para
.nCharOfs
);
226 TRACE("DOCUMENT DUMP END\n");