dwmapi: Clear DWM_TIMING_INFO structure before returning.
[wine.git] / dlls / riched20 / list.c
blob891a52e605f105d176487abeca2172a946417350
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 static BOOL ME_DITypesEqual(ME_DIType type, ME_DIType nTypeOrClass)
47 switch (nTypeOrClass)
49 case diRunOrParagraph:
50 return type == diRun || type == diParagraph;
51 case diRunOrStartRow:
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;
61 default:
62 return type == nTypeOrClass;
66 ME_DisplayItem *ME_FindItemBack(ME_DisplayItem *di, ME_DIType nTypeOrClass)
68 if (!di)
69 return NULL;
70 di = di->prev;
71 while(di!=NULL) {
72 if (ME_DITypesEqual(di->type, nTypeOrClass))
73 return di;
74 di = di->prev;
76 return NULL;
79 ME_DisplayItem *ME_FindItemBackOrHere(ME_DisplayItem *di, ME_DIType nTypeOrClass)
81 while(di!=NULL) {
82 if (ME_DITypesEqual(di->type, nTypeOrClass))
83 return di;
84 di = di->prev;
86 return NULL;
89 ME_DisplayItem *ME_FindItemFwd(ME_DisplayItem *di, ME_DIType nTypeOrClass)
91 if (!di) return NULL;
92 di = di->next;
93 while(di!=NULL) {
94 if (ME_DITypesEqual(di->type, nTypeOrClass))
95 return di;
96 di = di->next;
98 return NULL;
101 static const char *ME_GetDITypeName(ME_DIType type)
103 switch(type)
105 case diParagraph: return "diParagraph";
106 case diRun: return "diRun";
107 case diCell: return "diCell";
108 case diTextStart: return "diTextStart";
109 case diTextEnd: return "diTextEnd";
110 case diStartRow: return "diStartRow";
111 default: return "?";
115 void ME_DestroyDisplayItem(ME_DisplayItem *item)
117 if (0)
118 TRACE("type=%s\n", ME_GetDITypeName(item->type));
119 if (item->type==diRun)
121 if (item->member.run.reobj)
123 list_remove(&item->member.run.reobj->entry);
124 ME_DeleteReObject(item->member.run.reobj);
126 heap_free( item->member.run.glyphs );
127 heap_free( item->member.run.clusters );
128 ME_ReleaseStyle(item->member.run.style);
130 heap_free(item);
133 ME_DisplayItem *ME_MakeDI(ME_DIType type)
135 ME_DisplayItem *item = heap_alloc_zero(sizeof(*item));
137 item->type = type;
138 item->prev = item->next = NULL;
139 return item;
142 void ME_DumpDocument(ME_TextBuffer *buffer)
144 /* FIXME this is useless, */
145 ME_DisplayItem *pItem = buffer->pFirst;
146 TRACE("DOCUMENT DUMP START\n");
147 while(pItem) {
148 switch(pItem->type)
150 case diTextStart:
151 TRACE("Start\n");
152 break;
153 case diCell:
154 TRACE("Cell(level=%d%s)\n", pItem->member.cell.nNestingLevel,
155 !pItem->member.cell.next_cell ? ", END" :
156 (!pItem->member.cell.prev_cell ? ", START" :""));
157 break;
158 case diParagraph:
159 TRACE("Paragraph(ofs=%d)\n", pItem->member.para.nCharOfs);
160 if (pItem->member.para.nFlags & MEPF_ROWSTART)
161 TRACE(" - (Table Row Start)\n");
162 if (pItem->member.para.nFlags & MEPF_ROWEND)
163 TRACE(" - (Table Row End)\n");
164 break;
165 case diStartRow:
166 TRACE(" - StartRow\n");
167 break;
168 case diRun:
169 TRACE(" - Run(%s, %d, flags=%x)\n", debugstr_run( &pItem->member.run ),
170 pItem->member.run.nCharOfs, pItem->member.run.nFlags);
171 break;
172 case diTextEnd:
173 TRACE("End(ofs=%d)\n", pItem->member.para.nCharOfs);
174 break;
175 default:
176 break;
178 pItem = pItem->next;
180 TRACE("DOCUMENT DUMP END\n");