push 535a8035db5d709ef8f05977281c2f1a0c4cce0a
[wine/hacks.git] / dlls / riched20 / list.c
blob092fde473323159f94e7d360a5e92688654cc3ea
1 /*
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
22 #include "editor.h"
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;
39 assert(diNext);
40 assert(diPrev);
41 diPrev->next = diNext;
42 diNext->prev = diPrev;
45 ME_DisplayItem *ME_FindItemBack(ME_DisplayItem *di, ME_DIType nTypeOrClass)
47 if (!di)
48 return NULL;
49 di = di->prev;
50 while(di!=NULL) {
51 if (ME_DITypesEqual(di->type, nTypeOrClass))
52 return di;
53 di = di->prev;
55 return NULL;
58 ME_DisplayItem *ME_FindItemBackOrHere(ME_DisplayItem *di, ME_DIType nTypeOrClass)
60 while(di!=NULL) {
61 if (ME_DITypesEqual(di->type, nTypeOrClass))
62 return di;
63 di = di->prev;
65 return NULL;
68 ME_DisplayItem *ME_FindItemFwd(ME_DisplayItem *di, ME_DIType nTypeOrClass)
70 if (!di) return NULL;
71 di = di->next;
72 while(di!=NULL) {
73 if (ME_DITypesEqual(di->type, nTypeOrClass))
74 return di;
75 di = di->next;
77 return NULL;
80 ME_DisplayItem *ME_FindItemFwdOrHere(ME_DisplayItem *di, ME_DIType nTypeOrClass)
82 while(di!=NULL) {
83 if (ME_DITypesEqual(di->type, nTypeOrClass))
84 return di;
85 di = di->next;
87 return NULL;
90 BOOL ME_DITypesEqual(ME_DIType type, ME_DIType nTypeOrClass)
92 if (type==nTypeOrClass)
93 return TRUE;
94 if (nTypeOrClass==diRunOrParagraph && (type==diRun || type==diParagraph))
95 return TRUE;
96 if (nTypeOrClass==diRunOrStartRow && (type==diRun || type==diStartRow))
97 return TRUE;
98 if (nTypeOrClass==diParagraphOrEnd && (type==diTextEnd || type==diParagraph))
99 return TRUE;
100 if (nTypeOrClass==diStartRowOrParagraph && (type==diStartRow || type==diParagraph))
101 return TRUE;
102 if (nTypeOrClass==diStartRowOrParagraphOrEnd
103 && (type==diStartRow || type==diParagraph || type==diTextEnd))
104 return TRUE;
105 if (nTypeOrClass==diRunOrParagraphOrEnd
106 && (type==diRun || type==diParagraph || type==diTextEnd))
107 return TRUE;
108 return FALSE;
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 if (item->member.run.ole_obj) ME_DeleteReObject(item->member.run.ole_obj);
118 ME_ReleaseStyle(item->member.run.style);
119 ME_DestroyString(item->member.run.strText);
121 if (item->type==diUndoSetCharFormat) {
122 ME_ReleaseStyle(item->member.ustyle);
124 if (item->type==diUndoSplitParagraph) {
125 FREE_OBJ(item->member.para.pFmt);
126 if (item->member.para.pCell)
127 FREE_OBJ(item->member.para.pCell);
129 FREE_OBJ(item);
132 ME_DisplayItem *ME_MakeDI(ME_DIType type) {
133 ME_DisplayItem *item = ALLOC_OBJ(ME_DisplayItem);
134 ZeroMemory(item, sizeof(ME_DisplayItem));
135 item->type = type;
136 item->prev = item->next = NULL;
137 if (type == diParagraph || type == diUndoSplitParagraph) {
138 item->member.para.pFmt = ALLOC_OBJ(PARAFORMAT2);
139 ME_SetDefaultParaFormat(item->member.para.pFmt);
140 item->member.para.nFlags = MEPF_REWRAP;
143 return item;
146 const char *ME_GetDITypeName(ME_DIType type)
148 switch(type)
150 case diParagraph: return "diParagraph";
151 case diRun: return "diRun";
152 case diCell: return "diCell";
153 case diTextStart: return "diTextStart";
154 case diTextEnd: return "diTextEnd";
155 case diStartRow: return "diStartRow";
156 case diUndoEndTransaction: return "diUndoEndTransaction";
157 case diUndoPotentialEndTransaction: return "diUndoPotentialEndTransaction";
158 case diUndoSetParagraphFormat: return "diUndoSetParagraphFormat";
159 case diUndoSetCharFormat: return "diUndoSetCharFormat";
160 case diUndoInsertRun: return "diUndoInsertRun";
161 case diUndoDeleteRun: return "diUndoDeleteRun";
162 case diUndoJoinParagraphs: return "diJoinParagraphs";
163 case diUndoSplitParagraph: return "diSplitParagraph";
164 default: return "?";
168 void ME_DumpDocument(ME_TextBuffer *buffer)
170 /* FIXME this is useless, */
171 ME_DisplayItem *pItem = buffer->pFirst;
172 TRACE("DOCUMENT DUMP START\n");
173 while(pItem) {
174 switch(pItem->type)
176 case diTextStart:
177 TRACE("Start\n");
178 break;
179 case diCell:
180 TRACE("Cell(level=%d%s)\n", pItem->member.cell.nNestingLevel,
181 !pItem->member.cell.next_cell ? ", END" :
182 (!pItem->member.cell.prev_cell ? ", START" :""));
183 break;
184 case diParagraph:
185 TRACE("Paragraph(ofs=%d)\n", pItem->member.para.nCharOfs);
186 if (pItem->member.para.nFlags & MEPF_ROWSTART)
187 TRACE(" - (Table Row Start)\n");
188 if (pItem->member.para.nFlags & MEPF_ROWEND)
189 TRACE(" - (Table Row End)\n");
190 break;
191 case diStartRow:
192 TRACE(" - StartRow\n");
193 break;
194 case diRun:
195 TRACE(" - Run(\"%s\", %d)\n", debugstr_w(pItem->member.run.strText->szData),
196 pItem->member.run.nCharOfs);
197 if (pItem->member.run.nFlags & MERF_ENDPARA)
198 TRACE(" - Paragraph end: %d CR, %d LF\n", pItem->member.run.nCR, pItem->member.run.nLF);
199 break;
200 case diTextEnd:
201 TRACE("End(ofs=%d)\n", pItem->member.para.nCharOfs);
202 break;
203 default:
204 break;
206 pItem = pItem->next;
208 TRACE("DOCUMENT DUMP END\n");