2005-03-05 11:19:14 +00:00
|
|
|
/*
|
|
|
|
* RichEdit - functions working on paragraphs of text (diParagraph).
|
|
|
|
*
|
|
|
|
* Copyright 2004 by Krzysztof Foltman
|
2006-02-04 16:01:01 +00:00
|
|
|
* Copyright 2006 by Phil Krylov
|
2005-03-05 11:19:14 +00:00
|
|
|
*
|
|
|
|
* 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 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-03-05 11:19:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "editor.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(richedit);
|
|
|
|
|
2006-01-24 13:00:32 +00:00
|
|
|
static const WCHAR wszParagraphSign[] = {0xB6, 0};
|
2005-03-05 11:19:14 +00:00
|
|
|
|
2008-01-01 21:05:46 +00:00
|
|
|
void ME_MakeFirstParagraph(ME_TextEditor *editor)
|
2005-03-05 11:19:14 +00:00
|
|
|
{
|
2008-01-01 21:05:46 +00:00
|
|
|
ME_Context c;
|
2005-03-05 11:19:14 +00:00
|
|
|
PARAFORMAT2 fmt;
|
|
|
|
CHARFORMAT2W cf;
|
|
|
|
LOGFONTW lf;
|
|
|
|
HFONT hf;
|
2008-01-01 21:05:46 +00:00
|
|
|
ME_TextBuffer *text = editor->pBuffer;
|
2005-03-05 11:19:14 +00:00
|
|
|
ME_DisplayItem *para = ME_MakeDI(diParagraph);
|
|
|
|
ME_DisplayItem *run;
|
|
|
|
ME_Style *style;
|
|
|
|
|
2008-03-16 20:48:13 +00:00
|
|
|
ME_InitContext(&c, editor, GetDC(editor->hWnd));
|
2008-01-01 21:05:46 +00:00
|
|
|
|
2005-03-05 11:19:14 +00:00
|
|
|
hf = (HFONT)GetStockObject(SYSTEM_FONT);
|
|
|
|
assert(hf);
|
|
|
|
GetObjectW(hf, sizeof(LOGFONTW), &lf);
|
|
|
|
ZeroMemory(&cf, sizeof(cf));
|
|
|
|
cf.cbSize = sizeof(cf);
|
|
|
|
cf.dwMask = CFM_BACKCOLOR|CFM_COLOR|CFM_FACE|CFM_SIZE|CFM_CHARSET;
|
|
|
|
cf.dwMask |= CFM_ALLCAPS|CFM_BOLD|CFM_DISABLED|CFM_EMBOSS|CFM_HIDDEN;
|
|
|
|
cf.dwMask |= CFM_IMPRINT|CFM_ITALIC|CFM_LINK|CFM_OUTLINE|CFM_PROTECTED;
|
|
|
|
cf.dwMask |= CFM_REVISED|CFM_SHADOW|CFM_SMALLCAPS|CFM_STRIKEOUT;
|
2008-01-01 21:03:58 +00:00
|
|
|
cf.dwMask |= CFM_SUBSCRIPT|CFM_UNDERLINETYPE|CFM_WEIGHT;
|
2005-03-05 11:19:14 +00:00
|
|
|
|
|
|
|
cf.dwEffects = CFE_AUTOCOLOR | CFE_AUTOBACKCOLOR;
|
|
|
|
lstrcpyW(cf.szFaceName, lf.lfFaceName);
|
2008-06-25 15:40:39 +00:00
|
|
|
/* Convert system font height from logical units to twips for cf.yHeight */
|
|
|
|
cf.yHeight = (lf.lfHeight * 72 * 1440) / (c.dpi.cy * c.dpi.cy);
|
2008-03-16 20:47:39 +00:00
|
|
|
if (lf.lfWeight > FW_NORMAL) cf.dwEffects |= CFE_BOLD;
|
2005-03-05 11:19:14 +00:00
|
|
|
cf.wWeight = lf.lfWeight;
|
|
|
|
if (lf.lfItalic) cf.dwEffects |= CFE_ITALIC;
|
2008-01-01 21:03:58 +00:00
|
|
|
cf.bUnderlineType = (lf.lfUnderline) ? CFU_CF1UNDERLINE : CFU_UNDERLINENONE;
|
2005-03-05 11:19:14 +00:00
|
|
|
if (lf.lfStrikeOut) cf.dwEffects |= CFE_STRIKEOUT;
|
2008-01-01 21:03:40 +00:00
|
|
|
cf.bPitchAndFamily = lf.lfPitchAndFamily;
|
|
|
|
cf.bCharSet = lf.lfCharSet;
|
|
|
|
|
2005-03-05 11:19:14 +00:00
|
|
|
ZeroMemory(&fmt, sizeof(fmt));
|
|
|
|
fmt.cbSize = sizeof(fmt);
|
2005-04-16 10:48:35 +00:00
|
|
|
fmt.dwMask = PFM_ALIGNMENT | PFM_OFFSET | PFM_STARTINDENT | PFM_RIGHTINDENT | PFM_TABSTOPS;
|
2008-01-01 21:04:16 +00:00
|
|
|
fmt.wAlignment = PFA_LEFT;
|
2005-03-05 11:19:14 +00:00
|
|
|
|
2008-03-16 20:47:01 +00:00
|
|
|
*para->member.para.pFmt = fmt;
|
|
|
|
|
2005-03-05 11:19:14 +00:00
|
|
|
style = ME_MakeStyle(&cf);
|
|
|
|
text->pDefaultStyle = style;
|
|
|
|
|
|
|
|
run = ME_MakeRun(style, ME_MakeString(wszParagraphSign), MERF_ENDPARA);
|
|
|
|
run->member.run.nCharOfs = 0;
|
2008-04-26 20:26:58 +00:00
|
|
|
run->member.run.nCR = 1;
|
|
|
|
run->member.run.nLF = (editor->bEmulateVersion10) ? 1 : 0;
|
2005-03-05 11:19:14 +00:00
|
|
|
|
|
|
|
ME_InsertBefore(text->pLast, para);
|
|
|
|
ME_InsertBefore(text->pLast, run);
|
|
|
|
para->member.para.prev_para = text->pFirst;
|
|
|
|
para->member.para.next_para = text->pLast;
|
|
|
|
text->pFirst->member.para.next_para = para;
|
|
|
|
text->pLast->member.para.prev_para = para;
|
|
|
|
|
|
|
|
text->pLast->member.para.nCharOfs = 1;
|
2008-01-01 21:05:46 +00:00
|
|
|
|
2008-03-16 20:48:13 +00:00
|
|
|
ME_DestroyContext(&c, editor->hWnd);
|
2005-03-05 11:19:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ME_MarkAllForWrapping(ME_TextEditor *editor)
|
|
|
|
{
|
|
|
|
ME_MarkForWrapping(editor, editor->pBuffer->pFirst->member.para.next_para, editor->pBuffer->pLast);
|
|
|
|
}
|
|
|
|
|
2007-08-13 21:41:55 +00:00
|
|
|
void ME_MarkForWrapping(ME_TextEditor *editor, ME_DisplayItem *first, const ME_DisplayItem *last)
|
2005-03-05 11:19:14 +00:00
|
|
|
{
|
|
|
|
while(first != last)
|
|
|
|
{
|
2005-03-09 11:48:59 +00:00
|
|
|
first->member.para.nFlags |= MEPF_REWRAP;
|
2005-03-05 11:19:14 +00:00
|
|
|
first = first->member.para.next_para;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-13 21:41:55 +00:00
|
|
|
void ME_MarkForPainting(ME_TextEditor *editor, ME_DisplayItem *first, const ME_DisplayItem *last)
|
2006-08-07 15:27:16 +00:00
|
|
|
{
|
2008-06-25 15:33:06 +00:00
|
|
|
while(first != last && first)
|
2006-08-07 15:27:16 +00:00
|
|
|
{
|
|
|
|
first->member.para.nFlags |= MEPF_REPAINT;
|
|
|
|
first = first->member.para.next_para;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-05 11:19:14 +00:00
|
|
|
/* split paragraph at the beginning of the run */
|
2008-04-26 18:29:53 +00:00
|
|
|
ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run, ME_Style *style, int numCR, int numLF)
|
2005-03-05 11:19:14 +00:00
|
|
|
{
|
|
|
|
ME_DisplayItem *next_para = NULL;
|
|
|
|
ME_DisplayItem *run_para = NULL;
|
|
|
|
ME_DisplayItem *new_para = ME_MakeDI(diParagraph);
|
|
|
|
ME_DisplayItem *end_run = ME_MakeRun(style,ME_MakeString(wszParagraphSign), MERF_ENDPARA);
|
|
|
|
ME_UndoItem *undo = NULL;
|
|
|
|
int ofs;
|
|
|
|
ME_DisplayItem *pp;
|
2008-04-26 18:29:53 +00:00
|
|
|
int end_len = numCR + numLF;
|
2005-03-05 11:19:14 +00:00
|
|
|
|
|
|
|
assert(run->type == diRun);
|
|
|
|
|
2008-04-26 18:29:53 +00:00
|
|
|
end_run->member.run.nCR = numCR;
|
|
|
|
end_run->member.run.nLF = numLF;
|
2005-03-05 11:19:14 +00:00
|
|
|
run_para = ME_GetParagraph(run);
|
|
|
|
assert(run_para->member.para.pFmt->cbSize == sizeof(PARAFORMAT2));
|
|
|
|
|
|
|
|
ofs = end_run->member.run.nCharOfs = run->member.run.nCharOfs;
|
|
|
|
next_para = run_para->member.para.next_para;
|
|
|
|
assert(next_para == ME_FindItemFwd(run_para, diParagraphOrEnd));
|
|
|
|
|
|
|
|
undo = ME_AddUndoItem(editor, diUndoJoinParagraphs, NULL);
|
|
|
|
if (undo)
|
|
|
|
undo->nStart = run_para->member.para.nCharOfs + ofs;
|
|
|
|
|
|
|
|
/* the new paragraph will have a different starting offset, so let's update its runs */
|
|
|
|
pp = run;
|
|
|
|
while(pp->type == diRun) {
|
|
|
|
pp->member.run.nCharOfs -= ofs;
|
|
|
|
pp = ME_FindItemFwd(pp, diRunOrParagraphOrEnd);
|
|
|
|
}
|
|
|
|
new_para->member.para.nCharOfs = ME_GetParagraph(run)->member.para.nCharOfs+ofs;
|
2005-07-21 10:33:32 +00:00
|
|
|
new_para->member.para.nCharOfs += end_len;
|
2005-03-05 11:19:14 +00:00
|
|
|
|
2005-03-09 11:48:59 +00:00
|
|
|
new_para->member.para.nFlags = MEPF_REWRAP; /* FIXME copy flags (if applicable) */
|
2005-03-05 11:19:14 +00:00
|
|
|
/* FIXME initialize format style and call ME_SetParaFormat blah blah */
|
2008-03-16 20:47:01 +00:00
|
|
|
*new_para->member.para.pFmt = *run_para->member.para.pFmt;
|
2006-02-04 16:01:01 +00:00
|
|
|
|
|
|
|
new_para->member.para.bTable = run_para->member.para.bTable;
|
2006-04-11 22:00:01 +00:00
|
|
|
|
|
|
|
/* Inherit previous cell definitions if any */
|
2006-02-04 16:01:01 +00:00
|
|
|
new_para->member.para.pCells = NULL;
|
2006-04-11 22:00:01 +00:00
|
|
|
if (run_para->member.para.pCells)
|
|
|
|
{
|
|
|
|
ME_TableCell *pCell, *pNewCell;
|
2006-02-04 16:01:01 +00:00
|
|
|
|
2006-04-11 22:00:01 +00:00
|
|
|
for (pCell = run_para->member.para.pCells; pCell; pCell = pCell->next)
|
|
|
|
{
|
|
|
|
pNewCell = ALLOC_OBJ(ME_TableCell);
|
|
|
|
pNewCell->nRightBoundary = pCell->nRightBoundary;
|
|
|
|
pNewCell->next = NULL;
|
|
|
|
if (new_para->member.para.pCells)
|
|
|
|
new_para->member.para.pLastCell->next = pNewCell;
|
|
|
|
else
|
|
|
|
new_para->member.para.pCells = pNewCell;
|
|
|
|
new_para->member.para.pLastCell = pNewCell;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-04 16:01:01 +00:00
|
|
|
/* fix paragraph properties. FIXME only needed when called from RTF reader */
|
|
|
|
if (run_para->member.para.pCells && !run_para->member.para.bTable)
|
|
|
|
{
|
|
|
|
/* Paragraph does not have an \intbl keyword, so any table definition
|
|
|
|
* stored is invalid */
|
|
|
|
ME_DestroyTableCellList(run_para);
|
|
|
|
}
|
2005-03-05 11:19:14 +00:00
|
|
|
|
|
|
|
/* insert paragraph into paragraph double linked list */
|
|
|
|
new_para->member.para.prev_para = run_para;
|
|
|
|
new_para->member.para.next_para = next_para;
|
|
|
|
run_para->member.para.next_para = new_para;
|
|
|
|
next_para->member.para.prev_para = new_para;
|
|
|
|
|
|
|
|
/* insert end run of the old paragraph, and new paragraph, into DI double linked list */
|
|
|
|
ME_InsertBefore(run, new_para);
|
|
|
|
ME_InsertBefore(new_para, end_run);
|
|
|
|
|
|
|
|
/* force rewrap of the */
|
2005-03-09 11:48:59 +00:00
|
|
|
run_para->member.para.prev_para->member.para.nFlags |= MEPF_REWRAP;
|
|
|
|
new_para->member.para.prev_para->member.para.nFlags |= MEPF_REWRAP;
|
2005-03-05 11:19:14 +00:00
|
|
|
|
|
|
|
/* we've added the end run, so we need to modify nCharOfs in the next paragraphs */
|
2005-07-21 10:33:32 +00:00
|
|
|
ME_PropagateCharOffset(next_para, end_len);
|
2005-03-05 11:19:14 +00:00
|
|
|
editor->nParagraphs++;
|
|
|
|
|
|
|
|
return new_para;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* join tp with tp->member.para.next_para, keeping tp's style; this
|
|
|
|
* is consistent with the original */
|
|
|
|
ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp)
|
|
|
|
{
|
|
|
|
ME_DisplayItem *pNext, *pFirstRunInNext, *pRun, *pTmp;
|
|
|
|
int i, shift;
|
|
|
|
ME_UndoItem *undo = NULL;
|
2008-04-26 18:29:53 +00:00
|
|
|
int end_len;
|
2005-03-05 11:19:14 +00:00
|
|
|
|
|
|
|
assert(tp->type == diParagraph);
|
|
|
|
assert(tp->member.para.next_para);
|
|
|
|
assert(tp->member.para.next_para->type == diParagraph);
|
|
|
|
|
|
|
|
pNext = tp->member.para.next_para;
|
|
|
|
|
2008-04-26 18:29:53 +00:00
|
|
|
/* Need to locate end-of-paragraph run here, in order to know end_len */
|
|
|
|
pRun = ME_FindItemBack(pNext, diRunOrParagraph);
|
|
|
|
|
|
|
|
assert(pRun);
|
|
|
|
assert(pRun->type == diRun);
|
|
|
|
assert(pRun->member.run.nFlags & MERF_ENDPARA);
|
|
|
|
|
|
|
|
end_len = pRun->member.run.nCR + pRun->member.run.nLF;
|
|
|
|
|
2005-03-05 11:19:14 +00:00
|
|
|
{
|
|
|
|
/* null char format operation to store the original char format for the ENDPARA run */
|
|
|
|
CHARFORMAT2W fmt;
|
|
|
|
ME_InitCharFormat2W(&fmt);
|
2005-07-21 10:33:32 +00:00
|
|
|
ME_SetCharFormat(editor, pNext->member.para.nCharOfs - end_len, end_len, &fmt);
|
2005-03-05 11:19:14 +00:00
|
|
|
}
|
|
|
|
undo = ME_AddUndoItem(editor, diUndoSplitParagraph, NULL);
|
|
|
|
if (undo)
|
|
|
|
{
|
2005-07-21 10:33:32 +00:00
|
|
|
undo->nStart = pNext->member.para.nCharOfs - end_len;
|
2008-04-26 18:29:53 +00:00
|
|
|
undo->nCR = pRun->member.run.nCR;
|
|
|
|
undo->nLF = pRun->member.run.nLF;
|
2005-03-05 11:19:14 +00:00
|
|
|
assert(pNext->member.para.pFmt->cbSize == sizeof(PARAFORMAT2));
|
2008-03-16 20:47:01 +00:00
|
|
|
*undo->di.member.para.pFmt = *pNext->member.para.pFmt;
|
2005-03-05 11:19:14 +00:00
|
|
|
}
|
|
|
|
|
2005-07-21 10:33:32 +00:00
|
|
|
shift = pNext->member.para.nCharOfs - tp->member.para.nCharOfs - end_len;
|
2005-03-05 11:19:14 +00:00
|
|
|
|
|
|
|
pFirstRunInNext = ME_FindItemFwd(pNext, diRunOrParagraph);
|
2008-04-26 18:29:53 +00:00
|
|
|
|
2005-03-05 11:19:14 +00:00
|
|
|
assert(pFirstRunInNext->type == diRun);
|
|
|
|
|
|
|
|
/* if some cursor points at end of paragraph, make it point to the first
|
|
|
|
run of the next joined paragraph */
|
|
|
|
for (i=0; i<editor->nCursors; i++) {
|
|
|
|
if (editor->pCursors[i].pRun == pRun) {
|
|
|
|
editor->pCursors[i].pRun = pFirstRunInNext;
|
|
|
|
editor->pCursors[i].nOffset = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pTmp = pNext;
|
|
|
|
do {
|
|
|
|
pTmp = ME_FindItemFwd(pTmp, diRunOrParagraphOrEnd);
|
|
|
|
if (pTmp->type != diRun)
|
|
|
|
break;
|
|
|
|
TRACE("shifting \"%s\" by %d (previous %d)\n", debugstr_w(pTmp->member.run.strText->szData), shift, pTmp->member.run.nCharOfs);
|
|
|
|
pTmp->member.run.nCharOfs += shift;
|
|
|
|
} while(1);
|
|
|
|
|
|
|
|
ME_Remove(pRun);
|
|
|
|
ME_DestroyDisplayItem(pRun);
|
|
|
|
|
2006-08-07 15:27:16 +00:00
|
|
|
if (editor->pLastSelStartPara == pNext)
|
|
|
|
editor->pLastSelStartPara = tp;
|
|
|
|
if (editor->pLastSelEndPara == pNext)
|
|
|
|
editor->pLastSelEndPara = tp;
|
|
|
|
|
2005-03-05 11:19:14 +00:00
|
|
|
tp->member.para.next_para = pNext->member.para.next_para;
|
|
|
|
pNext->member.para.next_para->member.para.prev_para = tp;
|
|
|
|
ME_Remove(pNext);
|
|
|
|
ME_DestroyDisplayItem(pNext);
|
|
|
|
|
2005-07-21 10:33:32 +00:00
|
|
|
ME_PropagateCharOffset(tp->member.para.next_para, -end_len);
|
2005-03-05 11:19:14 +00:00
|
|
|
|
|
|
|
ME_CheckCharOffsets(editor);
|
|
|
|
|
|
|
|
editor->nParagraphs--;
|
2005-03-09 11:48:59 +00:00
|
|
|
tp->member.para.nFlags |= MEPF_REWRAP;
|
2005-03-05 11:19:14 +00:00
|
|
|
return tp;
|
|
|
|
}
|
|
|
|
|
|
|
|
ME_DisplayItem *ME_GetParagraph(ME_DisplayItem *item) {
|
|
|
|
return ME_FindItemBackOrHere(item, diParagraph);
|
|
|
|
}
|
|
|
|
|
2007-08-13 21:41:55 +00:00
|
|
|
void ME_DumpParaStyleToBuf(const PARAFORMAT2 *pFmt, char buf[2048])
|
2005-03-05 11:19:14 +00:00
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
p = buf;
|
|
|
|
|
2008-01-01 21:04:22 +00:00
|
|
|
#define DUMP(mask, name, fmt, field) \
|
|
|
|
if (pFmt->dwMask & (mask)) p += sprintf(p, "%-22s" fmt "\n", name, pFmt->field); \
|
|
|
|
else p += sprintf(p, "%-22sN/A\n", name);
|
|
|
|
|
|
|
|
/* we take for granted that PFE_xxx is the hiword of the corresponding PFM_xxx */
|
|
|
|
#define DUMP_EFFECT(mask, name) \
|
|
|
|
p += sprintf(p, "%-22s%s\n", name, (pFmt->dwMask & (mask)) ? ((pFmt->wEffects & ((mask) >> 8)) ? "yes" : "no") : "N/A");
|
|
|
|
|
|
|
|
DUMP(PFM_NUMBERING, "Numbering:", "%u", wNumbering);
|
|
|
|
DUMP_EFFECT(PFM_DONOTHYPHEN, "Disable auto-hyphen:");
|
|
|
|
DUMP_EFFECT(PFM_KEEP, "No page break in para:");
|
|
|
|
DUMP_EFFECT(PFM_KEEPNEXT, "No page break in para & next:");
|
|
|
|
DUMP_EFFECT(PFM_NOLINENUMBER, "No line number:");
|
|
|
|
DUMP_EFFECT(PFM_NOWIDOWCONTROL, "No widow & orphan:");
|
|
|
|
DUMP_EFFECT(PFM_PAGEBREAKBEFORE, "Page break before:");
|
|
|
|
DUMP_EFFECT(PFM_RTLPARA, "RTL para:");
|
|
|
|
DUMP_EFFECT(PFM_SIDEBYSIDE, "Side by side:");
|
|
|
|
DUMP_EFFECT(PFM_TABLE, "Table:");
|
|
|
|
DUMP(PFM_OFFSETINDENT, "Offset indent:", "%d", dxStartIndent);
|
|
|
|
DUMP(PFM_STARTINDENT, "Start indent:", "%d", dxStartIndent);
|
|
|
|
DUMP(PFM_RIGHTINDENT, "Right indent:", "%d", dxRightIndent);
|
|
|
|
DUMP(PFM_OFFSET, "Offset:", "%d", dxOffset);
|
|
|
|
if (pFmt->dwMask & PFM_ALIGNMENT) {
|
|
|
|
switch (pFmt->wAlignment) {
|
|
|
|
case PFA_LEFT : p += sprintf(p, "Alignment: left\n"); break;
|
|
|
|
case PFA_RIGHT : p += sprintf(p, "Alignment: right\n"); break;
|
|
|
|
case PFA_CENTER : p += sprintf(p, "Alignment: center\n"); break;
|
|
|
|
case PFA_JUSTIFY: p += sprintf(p, "Alignment: justify\n"); break;
|
|
|
|
default : p += sprintf(p, "Alignment: incorrect %d\n", pFmt->wAlignment); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else p += sprintf(p, "Alignment: N/A\n");
|
|
|
|
DUMP(PFM_TABSTOPS, "Tab Stops:", "%d", cTabCount);
|
|
|
|
if (pFmt->dwMask & PFM_TABSTOPS) {
|
|
|
|
int i;
|
|
|
|
p += sprintf(p, "\t");
|
|
|
|
for (i = 0; i < pFmt->cTabCount; i++) p += sprintf(p, "%x ", pFmt->rgxTabs[i]);
|
|
|
|
p += sprintf(p, "\n");
|
|
|
|
}
|
|
|
|
DUMP(PFM_SPACEBEFORE, "Space Before:", "%d", dySpaceBefore);
|
|
|
|
DUMP(PFM_SPACEAFTER, "Space After:", "%d", dySpaceAfter);
|
|
|
|
DUMP(PFM_LINESPACING, "Line spacing:", "%d", dyLineSpacing);
|
|
|
|
DUMP(PFM_STYLE, "Text style:", "%d", sStyle);
|
|
|
|
DUMP(PFM_LINESPACING, "Line spacing rule:", "%u", bLineSpacingRule);
|
|
|
|
/* bOutlineLevel should be 0 */
|
|
|
|
DUMP(PFM_SHADING, "Shading Weigth:", "%u", wShadingWeight);
|
|
|
|
DUMP(PFM_SHADING, "Shading Style:", "%u", wShadingStyle);
|
|
|
|
DUMP(PFM_NUMBERINGSTART, "Numbering Start:", "%u", wNumberingStart);
|
|
|
|
DUMP(PFM_NUMBERINGSTYLE, "Numbering Style:", "0x%x", wNumberingStyle);
|
|
|
|
DUMP(PFM_NUMBERINGTAB, "Numbering Tab:", "%u", wNumberingStyle);
|
|
|
|
DUMP(PFM_BORDER, "Border Space:", "%u", wBorderSpace);
|
|
|
|
DUMP(PFM_BORDER, "Border Width:", "%u", wBorderWidth);
|
|
|
|
DUMP(PFM_BORDER, "Borders:", "%u", wBorders);
|
|
|
|
|
|
|
|
#undef DUMP
|
|
|
|
#undef DUMP_EFFECT
|
2005-03-05 11:19:14 +00:00
|
|
|
}
|
|
|
|
|
2007-08-13 21:41:55 +00:00
|
|
|
void ME_SetParaFormat(ME_TextEditor *editor, ME_DisplayItem *para, const PARAFORMAT2 *pFmt)
|
2005-03-05 11:19:14 +00:00
|
|
|
{
|
|
|
|
PARAFORMAT2 copy;
|
|
|
|
assert(sizeof(*para->member.para.pFmt) == sizeof(PARAFORMAT2));
|
|
|
|
ME_AddUndoItem(editor, diUndoSetParagraphFormat, para);
|
|
|
|
|
2008-03-16 20:47:01 +00:00
|
|
|
copy = *para->member.para.pFmt;
|
2005-03-05 11:19:14 +00:00
|
|
|
|
2008-01-01 21:04:28 +00:00
|
|
|
#define COPY_FIELD(m, f) \
|
|
|
|
if (pFmt->dwMask & (m)) { \
|
|
|
|
para->member.para.pFmt->dwMask |= m; \
|
|
|
|
para->member.para.pFmt->f = pFmt->f; \
|
|
|
|
}
|
|
|
|
|
|
|
|
COPY_FIELD(PFM_NUMBERING, wNumbering);
|
|
|
|
#define EFFECTS_MASK (PFM_RTLPARA|PFM_KEEP|PFM_KEEPNEXT|PFM_PAGEBREAKBEFORE| \
|
|
|
|
PFM_NOLINENUMBER|PFM_NOWIDOWCONTROL|PFM_DONOTHYPHEN|PFM_SIDEBYSIDE| \
|
|
|
|
PFM_TABLE)
|
|
|
|
/* we take for granted that PFE_xxx is the hiword of the corresponding PFM_xxx */
|
|
|
|
if (pFmt->dwMask & EFFECTS_MASK) {
|
|
|
|
para->member.para.pFmt->dwMask &= ~(pFmt->dwMask & EFFECTS_MASK);
|
|
|
|
para->member.para.pFmt->wEffects |= pFmt->wEffects & HIWORD(pFmt->dwMask);
|
|
|
|
}
|
|
|
|
#undef EFFECTS_MASK
|
|
|
|
|
|
|
|
COPY_FIELD(PFM_STARTINDENT, dxStartIndent);
|
2005-04-16 10:48:35 +00:00
|
|
|
if (pFmt->dwMask & PFM_OFFSETINDENT)
|
|
|
|
para->member.para.pFmt->dxStartIndent += pFmt->dxStartIndent;
|
2008-01-01 21:04:28 +00:00
|
|
|
COPY_FIELD(PFM_RIGHTINDENT, dxRightIndent);
|
|
|
|
COPY_FIELD(PFM_OFFSET, dxOffset);
|
|
|
|
COPY_FIELD(PFM_ALIGNMENT, wAlignment);
|
|
|
|
|
2005-04-16 10:48:35 +00:00
|
|
|
if (pFmt->dwMask & PFM_TABSTOPS)
|
|
|
|
{
|
|
|
|
para->member.para.pFmt->cTabCount = pFmt->cTabCount;
|
2008-01-01 21:04:28 +00:00
|
|
|
memcpy(para->member.para.pFmt->rgxTabs, pFmt->rgxTabs, pFmt->cTabCount*sizeof(LONG));
|
2005-04-16 10:48:35 +00:00
|
|
|
}
|
2008-01-01 21:04:28 +00:00
|
|
|
COPY_FIELD(PFM_SPACEBEFORE, dySpaceBefore);
|
|
|
|
COPY_FIELD(PFM_SPACEAFTER, dySpaceAfter);
|
|
|
|
COPY_FIELD(PFM_LINESPACING, dyLineSpacing);
|
|
|
|
COPY_FIELD(PFM_STYLE, sStyle);
|
|
|
|
COPY_FIELD(PFM_LINESPACING, bLineSpacingRule);
|
|
|
|
COPY_FIELD(PFM_SHADING, wShadingWeight);
|
|
|
|
COPY_FIELD(PFM_SHADING, wShadingStyle);
|
|
|
|
COPY_FIELD(PFM_NUMBERINGSTART, wNumberingStart);
|
|
|
|
COPY_FIELD(PFM_NUMBERINGSTYLE, wNumberingStyle);
|
|
|
|
COPY_FIELD(PFM_NUMBERINGTAB, wNumberingTab);
|
|
|
|
COPY_FIELD(PFM_BORDER, wBorderSpace);
|
|
|
|
COPY_FIELD(PFM_BORDER, wBorderWidth);
|
|
|
|
COPY_FIELD(PFM_BORDER, wBorders);
|
|
|
|
|
|
|
|
para->member.para.pFmt->dwMask |= pFmt->dwMask;
|
|
|
|
#undef COPY_FIELD
|
2005-03-05 11:19:14 +00:00
|
|
|
|
|
|
|
if (memcmp(©, para->member.para.pFmt, sizeof(PARAFORMAT2)))
|
2005-03-09 11:48:59 +00:00
|
|
|
para->member.para.nFlags |= MEPF_REWRAP;
|
2005-03-05 11:19:14 +00:00
|
|
|
}
|
|
|
|
|
2006-01-10 11:10:49 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
ME_GetSelectionParas(ME_TextEditor *editor, ME_DisplayItem **para, ME_DisplayItem **para_end)
|
2005-03-05 11:19:14 +00:00
|
|
|
{
|
2006-01-10 11:10:49 +00:00
|
|
|
ME_Cursor *pEndCursor = &editor->pCursors[1];
|
2005-03-05 11:19:14 +00:00
|
|
|
|
2006-01-10 11:10:49 +00:00
|
|
|
*para = ME_GetParagraph(editor->pCursors[0].pRun);
|
|
|
|
*para_end = ME_GetParagraph(editor->pCursors[1].pRun);
|
|
|
|
if ((*para_end)->member.para.nCharOfs < (*para)->member.para.nCharOfs) {
|
|
|
|
ME_DisplayItem *tmp = *para;
|
|
|
|
|
|
|
|
*para = *para_end;
|
|
|
|
*para_end = tmp;
|
|
|
|
pEndCursor = &editor->pCursors[0];
|
|
|
|
}
|
2005-03-05 11:19:14 +00:00
|
|
|
|
2006-01-10 11:10:49 +00:00
|
|
|
/* selection consists of chars from nFrom up to nTo-1 */
|
|
|
|
if ((*para_end)->member.para.nCharOfs > (*para)->member.para.nCharOfs) {
|
|
|
|
if (!pEndCursor->nOffset) {
|
|
|
|
*para_end = ME_GetParagraph(ME_FindItemBack(pEndCursor->pRun, diRun));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-13 21:41:55 +00:00
|
|
|
void ME_SetSelectionParaFormat(ME_TextEditor *editor, const PARAFORMAT2 *pFmt)
|
2006-01-10 11:10:49 +00:00
|
|
|
{
|
|
|
|
ME_DisplayItem *para, *para_end;
|
2005-03-05 11:19:14 +00:00
|
|
|
|
2006-01-10 11:10:49 +00:00
|
|
|
ME_GetSelectionParas(editor, ¶, ¶_end);
|
|
|
|
|
2005-03-05 11:19:14 +00:00
|
|
|
do {
|
|
|
|
ME_SetParaFormat(editor, para, pFmt);
|
|
|
|
if (para == para_end)
|
|
|
|
break;
|
|
|
|
para = para->member.para.next_para;
|
|
|
|
} while(1);
|
|
|
|
}
|
|
|
|
|
2007-08-13 21:41:55 +00:00
|
|
|
void ME_GetParaFormat(ME_TextEditor *editor, const ME_DisplayItem *para, PARAFORMAT2 *pFmt)
|
2005-03-05 11:19:14 +00:00
|
|
|
{
|
|
|
|
if (pFmt->cbSize >= sizeof(PARAFORMAT2))
|
|
|
|
{
|
2008-03-16 20:47:01 +00:00
|
|
|
*pFmt = *para->member.para.pFmt;
|
2005-03-05 11:19:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
CopyMemory(pFmt, para->member.para.pFmt, pFmt->cbSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ME_GetSelectionParaFormat(ME_TextEditor *editor, PARAFORMAT2 *pFmt)
|
|
|
|
{
|
2006-01-10 11:10:49 +00:00
|
|
|
ME_DisplayItem *para, *para_end;
|
2005-03-05 11:19:14 +00:00
|
|
|
PARAFORMAT2 tmp;
|
|
|
|
|
2006-01-10 11:10:49 +00:00
|
|
|
ME_GetSelectionParas(editor, ¶, ¶_end);
|
2005-03-05 11:19:14 +00:00
|
|
|
|
|
|
|
ME_GetParaFormat(editor, para, pFmt);
|
|
|
|
if (para == para_end) return;
|
|
|
|
|
|
|
|
do {
|
|
|
|
ZeroMemory(&tmp, sizeof(tmp));
|
|
|
|
tmp.cbSize = sizeof(tmp);
|
|
|
|
ME_GetParaFormat(editor, para, &tmp);
|
2008-01-01 21:04:28 +00:00
|
|
|
|
|
|
|
#define CHECK_FIELD(m, f) \
|
|
|
|
if (pFmt->f != tmp.f) pFmt->dwMask &= ~(m);
|
|
|
|
|
|
|
|
CHECK_FIELD(PFM_NUMBERING, wNumbering);
|
|
|
|
/* para->member.para.pFmt->wEffects = pFmt->wEffects; */
|
|
|
|
assert(tmp.dwMask & PFM_ALIGNMENT);
|
|
|
|
CHECK_FIELD(PFM_NUMBERING, wNumbering);
|
2005-04-16 10:48:35 +00:00
|
|
|
assert(tmp.dwMask & PFM_STARTINDENT);
|
2008-01-01 21:04:28 +00:00
|
|
|
CHECK_FIELD(PFM_STARTINDENT, dxStartIndent);
|
|
|
|
assert(tmp.dwMask & PFM_RIGHTINDENT);
|
|
|
|
CHECK_FIELD(PFM_RIGHTINDENT, dxRightIndent);
|
2005-04-16 10:48:35 +00:00
|
|
|
assert(tmp.dwMask & PFM_OFFSET);
|
2008-01-01 21:04:28 +00:00
|
|
|
CHECK_FIELD(PFM_OFFSET, dxOffset);
|
|
|
|
CHECK_FIELD(PFM_ALIGNMENT, wAlignment);
|
|
|
|
|
|
|
|
assert(tmp.dwMask & PFM_TABSTOPS);
|
2005-04-16 10:48:35 +00:00
|
|
|
if (pFmt->dwMask & PFM_TABSTOPS) {
|
2008-01-01 21:04:28 +00:00
|
|
|
if (pFmt->cTabCount != tmp.cTabCount ||
|
|
|
|
memcmp(pFmt->rgxTabs, tmp.rgxTabs, tmp.cTabCount*sizeof(int)))
|
2005-04-16 10:48:35 +00:00
|
|
|
pFmt->dwMask &= ~PFM_TABSTOPS;
|
|
|
|
}
|
2008-01-01 21:04:28 +00:00
|
|
|
|
|
|
|
CHECK_FIELD(PFM_SPACEBEFORE, dySpaceBefore);
|
|
|
|
CHECK_FIELD(PFM_SPACEAFTER, dySpaceAfter);
|
|
|
|
CHECK_FIELD(PFM_LINESPACING, dyLineSpacing);
|
|
|
|
CHECK_FIELD(PFM_STYLE, sStyle);
|
|
|
|
CHECK_FIELD(PFM_SPACEAFTER, bLineSpacingRule);
|
|
|
|
CHECK_FIELD(PFM_SHADING, wShadingWeight);
|
|
|
|
CHECK_FIELD(PFM_SHADING, wShadingStyle);
|
|
|
|
CHECK_FIELD(PFM_NUMBERINGSTART, wNumberingStart);
|
|
|
|
CHECK_FIELD(PFM_NUMBERINGSTYLE, wNumberingStyle);
|
|
|
|
CHECK_FIELD(PFM_NUMBERINGTAB, wNumberingTab);
|
|
|
|
CHECK_FIELD(PFM_BORDER, wBorderSpace);
|
|
|
|
CHECK_FIELD(PFM_BORDER, wBorderWidth);
|
|
|
|
CHECK_FIELD(PFM_BORDER, wBorders);
|
|
|
|
|
|
|
|
#undef CHECK_FIELD
|
|
|
|
|
2005-03-05 11:19:14 +00:00
|
|
|
if (para == para_end)
|
|
|
|
return;
|
|
|
|
para = para->member.para.next_para;
|
|
|
|
} while(1);
|
|
|
|
}
|