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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 WINE_DEFAULT_DEBUG_CHANNEL(riched20);
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 ME_DisplayItem *ME_FindItemBack(ME_DisplayItem *di, ME_DIType nTypeOrClass)
51 if (ME_DITypesEqual(di->type, nTypeOrClass))
58 ME_DisplayItem *ME_FindItemBackOrHere(ME_DisplayItem *di, ME_DIType nTypeOrClass)
61 if (ME_DITypesEqual(di->type, nTypeOrClass))
68 ME_DisplayItem *ME_FindItemFwd(ME_DisplayItem *di, ME_DIType nTypeOrClass)
73 if (ME_DITypesEqual(di->type, nTypeOrClass))
80 ME_DisplayItem *ME_FindItemFwdOrHere(ME_DisplayItem *di, ME_DIType nTypeOrClass)
83 if (ME_DITypesEqual(di->type, nTypeOrClass))
90 BOOL ME_DITypesEqual(ME_DIType type, ME_DIType nTypeOrClass)
92 if (type==nTypeOrClass)
94 if (nTypeOrClass==diRunOrParagraph && (type==diRun || type==diParagraph))
96 if (nTypeOrClass==diRunOrStartRow && (type==diRun || type==diStartRow))
98 if (nTypeOrClass==diParagraphOrEnd && (type==diTextEnd || type==diParagraph))
100 if (nTypeOrClass==diStartRowOrParagraph && (type==diStartRow || type==diParagraph))
102 if (nTypeOrClass==diStartRowOrParagraphOrEnd
103 && (type==diStartRow || type==diParagraph || type==diTextEnd))
105 if (nTypeOrClass==diRunOrParagraphOrEnd
106 && (type==diRun || type==diParagraph || type==diTextEnd))
111 void ME_DestroyDisplayItem(ME_DisplayItem *item) {
112 /* TRACE("type=%s\n", ME_GetDITypeName(item->type)); */
113 if (item->type==diParagraph || item->type == diUndoSetParagraphFormat) {
114 FREE_OBJ(item->member.para.pFmt);
116 if (item->type==diRun || item->type == diUndoInsertRun) {
117 ME_ReleaseStyle(item->member.run.style);
118 ME_DestroyString(item->member.run.strText);
120 if (item->type==diUndoSetCharFormat || item->type==diUndoSetDefaultCharFormat) {
121 ME_ReleaseStyle(item->member.ustyle);
126 ME_DisplayItem *ME_MakeDI(ME_DIType type) {
127 ME_DisplayItem *item = ALLOC_OBJ(ME_DisplayItem);
128 ZeroMemory(item, sizeof(ME_DisplayItem));
130 item->prev = item->next = NULL;
131 if (type == diParagraph || type == diUndoSplitParagraph) {
132 item->member.para.pFmt = ALLOC_OBJ(PARAFORMAT2);
133 item->member.para.pFmt->cbSize = sizeof(PARAFORMAT2);
134 item->member.para.pFmt->dwMask = 0;
135 item->member.para.nFlags = MEPF_REWRAP;
141 const char *ME_GetDITypeName(ME_DIType type)
145 case diParagraph: return "diParagraph";
146 case diRun: return "diRun";
147 case diTextStart: return "diTextStart";
148 case diTextEnd: return "diTextEnd";
149 case diStartRow: return "diStartRow";
150 case diUndoEndTransaction: return "diUndoEndTransaction";
151 case diUndoSetParagraphFormat: return "diUndoSetParagraphFormat";
152 case diUndoSetCharFormat: return "diUndoSetCharFormat";
153 case diUndoInsertRun: return "diUndoInsertRun";
154 case diUndoDeleteRun: return "diUndoDeleteRun";
155 case diUndoJoinParagraphs: return "diJoinParagraphs";
156 case diUndoSplitParagraph: return "diSplitParagraph";
157 case diUndoSetDefaultCharFormat: return "diUndoSetDefaultCharFormat";
162 void ME_DumpDocument(ME_TextBuffer *buffer)
164 /* FIXME this is useless, */
165 ME_DisplayItem *pItem = buffer->pFirst;
166 TRACE("DOCUMENT DUMP START\n");
174 TRACE("\nParagraph(ofs=%d)", pItem->member.para.nCharOfs);
177 TRACE(" - StartRow");
180 TRACE(" - Run(\"%s\", %d)", debugstr_w(pItem->member.run.strText->szData),
181 pItem->member.run.nCharOfs);
191 TRACE("DOCUMENT DUMP END\n");