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
24 WINE_DEFAULT_DEBUG_CHANNEL(richedit_lists);
26 void ME_InsertBefore(ME_DisplayItem *diWhere, ME_DisplayItem *diWhat)
28 diWhat->next = diWhere;
29 diWhat->prev = diWhere->prev;
31 diWhere->prev->next = diWhat;
32 diWhat->next->prev = diWhat;
35 void ME_Remove(ME_DisplayItem *diWhere)
37 ME_DisplayItem *diNext = diWhere->next;
38 ME_DisplayItem *diPrev = diWhere->prev;
41 diPrev->next = diNext;
42 diNext->prev = diPrev;
45 static BOOL ME_DITypesEqual(ME_DIType type, ME_DIType nTypeOrClass)
49 case diRunOrParagraph:
50 return type == diRun || type == diParagraph;
52 return type == diRun || type == diStartRow;
53 case diParagraphOrEnd:
54 return type == diTextEnd || type == diParagraph;
55 case diStartRowOrParagraph:
56 return type == diStartRow || type == diParagraph;
57 case diStartRowOrParagraphOrEnd:
58 return type == diStartRow || type == diParagraph || type == diTextEnd;
59 case diRunOrParagraphOrEnd:
60 return type == diRun || type == diParagraph || type == diTextEnd;
62 return type == nTypeOrClass;
66 /* Modifies run pointer to point to the next run, and modify the
67 * paragraph pointer if moving into the next paragraph.
69 * Returns TRUE if next run is found, otherwise returns FALSE. */
70 BOOL ME_NextRun(ME_DisplayItem **para, ME_DisplayItem **run)
72 ME_DisplayItem *p = (*run)->next;
73 while (p->type != diTextEnd)
75 if (p->type == diParagraph) {
77 } else if (p->type == diRun) {
86 /* Modifies run pointer to point to the previous run, and modify the
87 * paragraph pointer if moving into the previous paragraph.
89 * Returns TRUE if previous run is found, otherwise returns FALSE. */
90 BOOL ME_PrevRun(ME_DisplayItem **para, ME_DisplayItem **run)
92 ME_DisplayItem *p = (*run)->prev;
93 while (p->type != diTextStart)
95 if (p->type == diParagraph) {
96 if (p->member.para.prev_para->type == diParagraph)
97 *para = p->member.para.prev_para;
98 } else if (p->type == diRun) {
107 ME_DisplayItem *ME_FindItemBack(ME_DisplayItem *di, ME_DIType nTypeOrClass)
113 if (ME_DITypesEqual(di->type, nTypeOrClass))
120 ME_DisplayItem *ME_FindItemBackOrHere(ME_DisplayItem *di, ME_DIType nTypeOrClass)
123 if (ME_DITypesEqual(di->type, nTypeOrClass))
130 ME_DisplayItem *ME_FindItemFwd(ME_DisplayItem *di, ME_DIType nTypeOrClass)
132 if (!di) return NULL;
135 if (ME_DITypesEqual(di->type, nTypeOrClass))
142 void ME_DestroyDisplayItem(ME_DisplayItem *item)
144 /* TRACE("type=%s\n", ME_GetDITypeName(item->type)); */
145 if (item->type==diParagraph)
147 FREE_OBJ(item->member.para.pFmt);
148 ME_DestroyString(item->member.para.text);
151 if (item->type==diRun)
153 if (item->member.run.ole_obj) ME_DeleteReObject(item->member.run.ole_obj);
154 ME_ReleaseStyle(item->member.run.style);
159 ME_DisplayItem *ME_MakeDI(ME_DIType type)
161 ME_DisplayItem *item = ALLOC_OBJ(ME_DisplayItem);
162 ZeroMemory(item, sizeof(ME_DisplayItem));
164 item->prev = item->next = NULL;
165 if (type == diParagraph)
167 item->member.para.pFmt = ALLOC_OBJ(PARAFORMAT2);
168 ME_SetDefaultParaFormat(item->member.para.pFmt);
169 item->member.para.nFlags = MEPF_REWRAP;
175 const char *ME_GetDITypeName(ME_DIType type)
179 case diParagraph: return "diParagraph";
180 case diRun: return "diRun";
181 case diCell: return "diCell";
182 case diTextStart: return "diTextStart";
183 case diTextEnd: return "diTextEnd";
184 case diStartRow: return "diStartRow";
189 void ME_DumpDocument(ME_TextBuffer *buffer)
191 /* FIXME this is useless, */
192 ME_DisplayItem *pItem = buffer->pFirst;
193 TRACE("DOCUMENT DUMP START\n");
201 TRACE("Cell(level=%d%s)\n", pItem->member.cell.nNestingLevel,
202 !pItem->member.cell.next_cell ? ", END" :
203 (!pItem->member.cell.prev_cell ? ", START" :""));
206 TRACE("Paragraph(ofs=%d)\n", pItem->member.para.nCharOfs);
207 if (pItem->member.para.nFlags & MEPF_ROWSTART)
208 TRACE(" - (Table Row Start)\n");
209 if (pItem->member.para.nFlags & MEPF_ROWEND)
210 TRACE(" - (Table Row End)\n");
213 TRACE(" - StartRow\n");
216 TRACE(" - Run(%s, %d, flags=%x)\n", debugstr_run( &pItem->member.run ),
217 pItem->member.run.nCharOfs, pItem->member.run.nFlags);
220 TRACE("End(ofs=%d)\n", pItem->member.para.nCharOfs);
227 TRACE("DOCUMENT DUMP END\n");