ReactOS 0.4.15-dev-7711-g5627da4
list.c
Go to the documentation of this file.
1/*
2 * RichEdit - Basic operations on double linked lists.
3 *
4 * Copyright 2004 by Krzysztof Foltman
5 *
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.
10 *
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.
15 *
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
19 */
20
21
22#include "editor.h"
23
25
27{
28 diWhat->next = diWhere;
29 diWhat->prev = diWhere->prev;
30
31 diWhere->prev->next = diWhat;
32 diWhat->next->prev = diWhat;
33}
34
36{
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;
43}
44
46{
47 switch (nTypeOrClass)
48 {
50 return type == diRun || type == diParagraph;
51 case diRunOrStartRow:
52 return type == diRun || type == diStartRow;
54 return type == diTextEnd || type == diParagraph;
56 return type == diStartRow || type == diParagraph;
58 return type == diStartRow || type == diParagraph || type == diTextEnd;
60 return type == diRun || type == diParagraph || type == diTextEnd;
61 default:
62 return type == nTypeOrClass;
63 }
64}
65
66/* Modifies run pointer to point to the next run.
67 * If all_para is FALSE constrain the search to the current para,
68 * otherwise modify the paragraph pointer if moving into the next paragraph.
69 *
70 * Returns TRUE if next run is found, otherwise returns FALSE. */
72{
73 ME_DisplayItem *p = (*run)->next;
74 while (p->type != diTextEnd)
75 {
76 if (p->type == diParagraph) {
77 if (!all_para) return FALSE;
78 *para = p;
79 } else if (p->type == diRun) {
80 *run = p;
81 return TRUE;
82 }
83 p = p->next;
84 }
85 return FALSE;
86}
87
88/* Modifies run pointer to point to the previous run.
89 * If all_para is FALSE constrain the search to the current para,
90 * otherwise modify the paragraph pointer if moving into the previous paragraph.
91 *
92 * Returns TRUE if previous run is found, otherwise returns FALSE. */
94{
95 ME_DisplayItem *p = (*run)->prev;
96 while (p->type != diTextStart)
97 {
98 if (p->type == diParagraph) {
99 if (!all_para) return FALSE;
100 if (para && p->member.para.prev_para->type == diParagraph)
101 *para = p->member.para.prev_para;
102 } else if (p->type == diRun) {
103 *run = p;
104 return TRUE;
105 }
106 p = p->prev;
107 }
108 return FALSE;
109}
110
112{
113 if (!di)
114 return NULL;
115 di = di->prev;
116 while(di!=NULL) {
117 if (ME_DITypesEqual(di->type, nTypeOrClass))
118 return di;
119 di = di->prev;
120 }
121 return NULL;
122}
123
125{
126 while(di!=NULL) {
127 if (ME_DITypesEqual(di->type, nTypeOrClass))
128 return di;
129 di = di->prev;
130 }
131 return NULL;
132}
133
135{
136 if (!di) return NULL;
137 di = di->next;
138 while(di!=NULL) {
139 if (ME_DITypesEqual(di->type, nTypeOrClass))
140 return di;
141 di = di->next;
142 }
143 return NULL;
144}
145
146static const char *ME_GetDITypeName(ME_DIType type)
147{
148 switch(type)
149 {
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 default: return "?";
157 }
158}
159
161{
162 if (0)
163 TRACE("type=%s\n", ME_GetDITypeName(item->type));
164 if (item->type==diRun)
165 {
166 if (item->member.run.reobj)
167 {
168 list_remove(&item->member.run.reobj->entry);
169 ME_DeleteReObject(item->member.run.reobj);
170 }
171 heap_free( item->member.run.glyphs );
172 heap_free( item->member.run.clusters );
173 ME_ReleaseStyle(item->member.run.style);
174 }
176}
177
179{
180 ME_DisplayItem *item = heap_alloc_zero(sizeof(*item));
181
182 item->type = type;
183 item->prev = item->next = NULL;
184 return item;
185}
186
188{
189 /* FIXME this is useless, */
190 ME_DisplayItem *pItem = buffer->pFirst;
191 TRACE("DOCUMENT DUMP START\n");
192 while(pItem) {
193 switch(pItem->type)
194 {
195 case diTextStart:
196 TRACE("Start\n");
197 break;
198 case diCell:
199 TRACE("Cell(level=%d%s)\n", pItem->member.cell.nNestingLevel,
200 !pItem->member.cell.next_cell ? ", END" :
201 (!pItem->member.cell.prev_cell ? ", START" :""));
202 break;
203 case diParagraph:
204 TRACE("Paragraph(ofs=%d)\n", pItem->member.para.nCharOfs);
205 if (pItem->member.para.nFlags & MEPF_ROWSTART)
206 TRACE(" - (Table Row Start)\n");
207 if (pItem->member.para.nFlags & MEPF_ROWEND)
208 TRACE(" - (Table Row End)\n");
209 break;
210 case diStartRow:
211 TRACE(" - StartRow\n");
212 break;
213 case diRun:
214 TRACE(" - Run(%s, %d, flags=%x)\n", debugstr_run( &pItem->member.run ),
215 pItem->member.run.nCharOfs, pItem->member.run.nFlags);
216 break;
217 case diTextEnd:
218 TRACE("End(ofs=%d)\n", pItem->member.para.nCharOfs);
219 break;
220 default:
221 break;
222 }
223 pItem = pItem->next;
224 }
225 TRACE("DOCUMENT DUMP END\n");
226}
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
static void list_remove(struct list_entry *entry)
Definition: list.h:90
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
void ME_Remove(ME_DisplayItem *diWhere)
Definition: list.c:35
ME_DisplayItem * ME_FindItemBack(ME_DisplayItem *di, ME_DIType nTypeOrClass)
Definition: list.c:111
BOOL ME_NextRun(ME_DisplayItem **para, ME_DisplayItem **run, BOOL all_para)
Definition: list.c:71
static const char * ME_GetDITypeName(ME_DIType type)
Definition: list.c:146
void ME_DumpDocument(ME_TextBuffer *buffer)
Definition: list.c:187
ME_DisplayItem * ME_FindItemFwd(ME_DisplayItem *di, ME_DIType nTypeOrClass)
Definition: list.c:134
BOOL ME_PrevRun(ME_DisplayItem **para, ME_DisplayItem **run, BOOL all_para)
Definition: list.c:93
void ME_InsertBefore(ME_DisplayItem *diWhere, ME_DisplayItem *diWhat)
Definition: list.c:26
ME_DisplayItem * ME_FindItemBackOrHere(ME_DisplayItem *di, ME_DIType nTypeOrClass)
Definition: list.c:124
void ME_DestroyDisplayItem(ME_DisplayItem *item)
Definition: list.c:160
static BOOL ME_DITypesEqual(ME_DIType type, ME_DIType nTypeOrClass)
Definition: list.c:45
ME_DisplayItem * ME_MakeDI(ME_DIType type)
Definition: list.c:178
#define assert(x)
Definition: debug.h:53
void ME_ReleaseStyle(ME_Style *item) DECLSPEC_HIDDEN
Definition: style.c:462
void ME_DeleteReObject(struct re_object *re_object) DECLSPEC_HIDDEN
Definition: richole.c:5899
static const char * debugstr_run(const ME_Run *run)
Definition: editor.h:46
#define MEPF_ROWSTART
Definition: editstr.h:144
#define MEPF_ROWEND
Definition: editstr.h:145
ME_DIType
Definition: editstr.h:82
@ diStartRow
Definition: editstr.h:88
@ diTextEnd
Definition: editstr.h:89
@ diRunOrParagraphOrEnd
Definition: editstr.h:97
@ diCell
Definition: editstr.h:86
@ diParagraphOrEnd
Definition: editstr.h:96
@ diRun
Definition: editstr.h:87
@ diStartRowOrParagraphOrEnd
Definition: editstr.h:93
@ diRunOrParagraph
Definition: editstr.h:94
@ diTextStart
Definition: editstr.h:84
@ diRunOrStartRow
Definition: editstr.h:95
@ diStartRowOrParagraph
Definition: editstr.h:92
@ diParagraph
Definition: editstr.h:85
unsigned int BOOL
Definition: ntddk_ex.h:94
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint buffer
Definition: glext.h:5915
GLfloat GLfloat p
Definition: glext.h:8902
static ATOM item
Definition: dde.c:856
#define TRACE(s)
Definition: solgame.cpp:4
struct define * next
Definition: compiler.c:65
struct tagME_DisplayItem * prev_cell
Definition: editstr.h:229
struct tagME_DisplayItem * next_cell
Definition: editstr.h:229
int nNestingLevel
Definition: editstr.h:223
ME_DIType type
Definition: editstr.h:256
struct tagME_DisplayItem * prev
Definition: editstr.h:257
ME_Cell cell
Definition: editstr.h:261
union tagME_DisplayItem::@537 member
struct tagME_DisplayItem * next
Definition: editstr.h:257
ME_Paragraph para
Definition: editstr.h:262
struct tagME_DisplayItem * prev_para
Definition: editstr.h:217
int nCharOfs
Definition: editstr.h:162
int nFlags
Definition: editstr.h:165