2005-03-05 12:19:14 +01:00
|
|
|
/*
|
|
|
|
* RichEdit - Basic operations on double linked lists.
|
|
|
|
*
|
|
|
|
* Copyright 2004 by Krzysztof Foltman
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-03-05 12:19:14 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "editor.h"
|
|
|
|
|
2005-10-08 12:33:44 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(richedit_lists);
|
2005-03-05 12:19:14 +01:00
|
|
|
|
|
|
|
void ME_InsertBefore(ME_DisplayItem *diWhere, ME_DisplayItem *diWhat)
|
|
|
|
{
|
|
|
|
diWhat->next = diWhere;
|
|
|
|
diWhat->prev = diWhere->prev;
|
|
|
|
|
|
|
|
diWhere->prev->next = diWhat;
|
|
|
|
diWhat->next->prev = diWhat;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ME_Remove(ME_DisplayItem *diWhere)
|
|
|
|
{
|
|
|
|
ME_DisplayItem *diNext = diWhere->next;
|
|
|
|
ME_DisplayItem *diPrev = diWhere->prev;
|
|
|
|
assert(diNext);
|
|
|
|
assert(diPrev);
|
|
|
|
diPrev->next = diNext;
|
|
|
|
diNext->prev = diPrev;
|
|
|
|
}
|
|
|
|
|
2009-01-14 00:25:51 +01:00
|
|
|
static BOOL ME_DITypesEqual(ME_DIType type, ME_DIType nTypeOrClass)
|
|
|
|
{
|
2009-08-10 16:53:21 +02:00
|
|
|
switch (nTypeOrClass)
|
|
|
|
{
|
|
|
|
case diRunOrParagraph:
|
|
|
|
return type == diRun || type == diParagraph;
|
|
|
|
case diRunOrStartRow:
|
|
|
|
return type == diRun || type == diStartRow;
|
|
|
|
case diParagraphOrEnd:
|
|
|
|
return type == diTextEnd || type == diParagraph;
|
|
|
|
case diStartRowOrParagraph:
|
|
|
|
return type == diStartRow || type == diParagraph;
|
|
|
|
case diStartRowOrParagraphOrEnd:
|
|
|
|
return type == diStartRow || type == diParagraph || type == diTextEnd;
|
|
|
|
case diRunOrParagraphOrEnd:
|
|
|
|
return type == diRun || type == diParagraph || type == diTextEnd;
|
|
|
|
default:
|
|
|
|
return type == nTypeOrClass;
|
|
|
|
}
|
2009-01-14 00:25:51 +01:00
|
|
|
}
|
|
|
|
|
2016-07-04 09:43:22 +02:00
|
|
|
/* Modifies run pointer to point to the next run.
|
|
|
|
* If all_para is FALSE constrain the search to the current para,
|
|
|
|
* otherwise modify the paragraph pointer if moving into the next paragraph.
|
2009-08-12 15:06:00 +02:00
|
|
|
*
|
|
|
|
* Returns TRUE if next run is found, otherwise returns FALSE. */
|
2016-07-04 09:43:22 +02:00
|
|
|
BOOL ME_NextRun(ME_DisplayItem **para, ME_DisplayItem **run, BOOL all_para)
|
2009-08-12 15:06:00 +02:00
|
|
|
{
|
|
|
|
ME_DisplayItem *p = (*run)->next;
|
|
|
|
while (p->type != diTextEnd)
|
|
|
|
{
|
|
|
|
if (p->type == diParagraph) {
|
2016-07-04 09:43:22 +02:00
|
|
|
if (!all_para) return FALSE;
|
2009-08-12 15:06:00 +02:00
|
|
|
*para = p;
|
|
|
|
} else if (p->type == diRun) {
|
|
|
|
*run = p;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-07-04 09:43:22 +02:00
|
|
|
/* Modifies run pointer to point to the previous run.
|
|
|
|
* If all_para is FALSE constrain the search to the current para,
|
|
|
|
* otherwise modify the paragraph pointer if moving into the previous paragraph.
|
2009-08-12 15:06:00 +02:00
|
|
|
*
|
|
|
|
* Returns TRUE if previous run is found, otherwise returns FALSE. */
|
2016-07-04 09:43:22 +02:00
|
|
|
BOOL ME_PrevRun(ME_DisplayItem **para, ME_DisplayItem **run, BOOL all_para)
|
2009-08-12 15:06:00 +02:00
|
|
|
{
|
|
|
|
ME_DisplayItem *p = (*run)->prev;
|
|
|
|
while (p->type != diTextStart)
|
|
|
|
{
|
|
|
|
if (p->type == diParagraph) {
|
2016-07-04 09:43:22 +02:00
|
|
|
if (!all_para) return FALSE;
|
2018-04-13 09:56:44 +02:00
|
|
|
if (para && p->member.para.prev_para->type == diParagraph)
|
2009-08-12 15:06:00 +02:00
|
|
|
*para = p->member.para.prev_para;
|
|
|
|
} else if (p->type == diRun) {
|
|
|
|
*run = p;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
p = p->prev;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_DisplayItem *ME_FindItemBack(ME_DisplayItem *di, ME_DIType nTypeOrClass)
|
|
|
|
{
|
|
|
|
if (!di)
|
|
|
|
return NULL;
|
|
|
|
di = di->prev;
|
|
|
|
while(di!=NULL) {
|
|
|
|
if (ME_DITypesEqual(di->type, nTypeOrClass))
|
|
|
|
return di;
|
|
|
|
di = di->prev;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ME_DisplayItem *ME_FindItemBackOrHere(ME_DisplayItem *di, ME_DIType nTypeOrClass)
|
|
|
|
{
|
|
|
|
while(di!=NULL) {
|
|
|
|
if (ME_DITypesEqual(di->type, nTypeOrClass))
|
|
|
|
return di;
|
|
|
|
di = di->prev;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ME_DisplayItem *ME_FindItemFwd(ME_DisplayItem *di, ME_DIType nTypeOrClass)
|
|
|
|
{
|
|
|
|
if (!di) return NULL;
|
|
|
|
di = di->next;
|
|
|
|
while(di!=NULL) {
|
|
|
|
if (ME_DITypesEqual(di->type, nTypeOrClass))
|
|
|
|
return di;
|
|
|
|
di = di->next;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-01-13 13:30:37 +01:00
|
|
|
static const char *ME_GetDITypeName(ME_DIType type)
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case diParagraph: return "diParagraph";
|
|
|
|
case diRun: return "diRun";
|
|
|
|
case diCell: return "diCell";
|
|
|
|
case diTextStart: return "diTextStart";
|
|
|
|
case diTextEnd: return "diTextEnd";
|
|
|
|
case diStartRow: return "diStartRow";
|
|
|
|
default: return "?";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-29 14:41:48 +01:00
|
|
|
void ME_DestroyDisplayItem(ME_DisplayItem *item)
|
|
|
|
{
|
2014-01-13 13:30:37 +01:00
|
|
|
if (0)
|
|
|
|
TRACE("type=%s\n", ME_GetDITypeName(item->type));
|
2013-01-29 14:41:48 +01:00
|
|
|
if (item->type==diParagraph)
|
2013-02-05 14:19:41 +01:00
|
|
|
{
|
|
|
|
ME_DestroyString(item->member.para.text);
|
2016-10-07 11:49:35 +02:00
|
|
|
para_num_clear( &item->member.para.para_num );
|
2013-02-05 14:19:41 +01:00
|
|
|
}
|
2013-01-29 14:41:48 +01:00
|
|
|
|
|
|
|
if (item->type==diRun)
|
|
|
|
{
|
2018-04-13 09:56:54 +02:00
|
|
|
if (item->member.run.reobj)
|
|
|
|
{
|
|
|
|
list_remove(&item->member.run.reobj->entry);
|
|
|
|
ME_DeleteReObject(item->member.run.reobj);
|
|
|
|
}
|
2014-01-15 14:06:43 +01:00
|
|
|
heap_free( item->member.run.glyphs );
|
|
|
|
heap_free( item->member.run.clusters );
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_ReleaseStyle(item->member.run.style);
|
|
|
|
}
|
2018-02-03 23:59:46 +01:00
|
|
|
heap_free(item);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2013-01-29 14:41:48 +01:00
|
|
|
ME_DisplayItem *ME_MakeDI(ME_DIType type)
|
|
|
|
{
|
2018-02-03 23:59:47 +01:00
|
|
|
ME_DisplayItem *item = heap_alloc_zero(sizeof(*item));
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
item->type = type;
|
|
|
|
item->prev = item->next = NULL;
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ME_DumpDocument(ME_TextBuffer *buffer)
|
|
|
|
{
|
|
|
|
/* FIXME this is useless, */
|
|
|
|
ME_DisplayItem *pItem = buffer->pFirst;
|
|
|
|
TRACE("DOCUMENT DUMP START\n");
|
|
|
|
while(pItem) {
|
|
|
|
switch(pItem->type)
|
|
|
|
{
|
|
|
|
case diTextStart:
|
2006-01-11 20:55:18 +01:00
|
|
|
TRACE("Start\n");
|
2005-03-05 12:19:14 +01:00
|
|
|
break;
|
2008-08-07 18:31:41 +02:00
|
|
|
case diCell:
|
|
|
|
TRACE("Cell(level=%d%s)\n", pItem->member.cell.nNestingLevel,
|
|
|
|
!pItem->member.cell.next_cell ? ", END" :
|
|
|
|
(!pItem->member.cell.prev_cell ? ", START" :""));
|
|
|
|
break;
|
2005-03-05 12:19:14 +01:00
|
|
|
case diParagraph:
|
2006-01-11 20:55:18 +01:00
|
|
|
TRACE("Paragraph(ofs=%d)\n", pItem->member.para.nCharOfs);
|
2008-08-07 18:31:41 +02:00
|
|
|
if (pItem->member.para.nFlags & MEPF_ROWSTART)
|
|
|
|
TRACE(" - (Table Row Start)\n");
|
|
|
|
if (pItem->member.para.nFlags & MEPF_ROWEND)
|
|
|
|
TRACE(" - (Table Row End)\n");
|
2005-03-05 12:19:14 +01:00
|
|
|
break;
|
|
|
|
case diStartRow:
|
2006-01-11 20:55:18 +01:00
|
|
|
TRACE(" - StartRow\n");
|
2005-03-05 12:19:14 +01:00
|
|
|
break;
|
|
|
|
case diRun:
|
2013-01-30 16:10:19 +01:00
|
|
|
TRACE(" - Run(%s, %d, flags=%x)\n", debugstr_run( &pItem->member.run ),
|
2009-01-28 07:34:56 +01:00
|
|
|
pItem->member.run.nCharOfs, pItem->member.run.nFlags);
|
2005-03-05 12:19:14 +01:00
|
|
|
break;
|
|
|
|
case diTextEnd:
|
2006-01-11 20:55:18 +01:00
|
|
|
TRACE("End(ofs=%d)\n", pItem->member.para.nCharOfs);
|
2005-03-05 12:19:14 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pItem = pItem->next;
|
|
|
|
}
|
|
|
|
TRACE("DOCUMENT DUMP END\n");
|
|
|
|
}
|