2 * RichEdit - functions working on paragraphs of text (diParagraph).
4 * Copyright 2004 by Krzysztof Foltman
5 * Copyright 2006 by Phil Krylov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
26 void ME_MakeFirstParagraph(ME_TextEditor *editor)
32 ME_TextBuffer *text = editor->pBuffer;
33 ME_DisplayItem *para = ME_MakeDI(diParagraph);
37 WCHAR cr_lf[] = {'\r','\n',0};
39 ME_InitContext(&c, editor, ITextHost_TxGetDC(editor->texthost));
41 hf = GetStockObject(SYSTEM_FONT);
43 GetObjectW(hf, sizeof(LOGFONTW), &lf);
44 ZeroMemory(&cf, sizeof(cf));
45 cf.cbSize = sizeof(cf);
46 cf.dwMask = CFM_BACKCOLOR|CFM_COLOR|CFM_FACE|CFM_SIZE|CFM_CHARSET;
47 cf.dwMask |= CFM_ALLCAPS|CFM_BOLD|CFM_DISABLED|CFM_EMBOSS|CFM_HIDDEN;
48 cf.dwMask |= CFM_IMPRINT|CFM_ITALIC|CFM_LINK|CFM_OUTLINE|CFM_PROTECTED;
49 cf.dwMask |= CFM_REVISED|CFM_SHADOW|CFM_SMALLCAPS|CFM_STRIKEOUT;
50 cf.dwMask |= CFM_SUBSCRIPT|CFM_UNDERLINETYPE|CFM_WEIGHT;
52 cf.dwEffects = CFE_AUTOCOLOR | CFE_AUTOBACKCOLOR;
53 lstrcpyW(cf.szFaceName, lf.lfFaceName);
54 /* Convert system font height from logical units to twips for cf.yHeight */
55 cf.yHeight = (lf.lfHeight * 72 * 1440) / (c.dpi.cy * c.dpi.cy);
56 if (lf.lfWeight > FW_NORMAL) cf.dwEffects |= CFE_BOLD;
57 cf.wWeight = lf.lfWeight;
58 if (lf.lfItalic) cf.dwEffects |= CFE_ITALIC;
59 cf.bUnderlineType = (lf.lfUnderline) ? CFU_CF1UNDERLINE : CFU_UNDERLINENONE;
60 if (lf.lfStrikeOut) cf.dwEffects |= CFE_STRIKEOUT;
61 cf.bPitchAndFamily = lf.lfPitchAndFamily;
62 cf.bCharSet = lf.lfCharSet;
64 style = ME_MakeStyle(&cf);
65 text->pDefaultStyle = style;
67 eol_len = editor->bEmulateVersion10 ? 2 : 1;
68 para->member.para.text = ME_MakeStringN( cr_lf, eol_len );
70 run = ME_MakeRun(style, MERF_ENDPARA);
71 run->member.run.nCharOfs = 0;
72 run->member.run.len = eol_len;
73 run->member.run.para = ¶->member.para;
75 ME_InsertBefore(text->pLast, para);
76 ME_InsertBefore(text->pLast, run);
77 para->member.para.prev_para = text->pFirst;
78 para->member.para.next_para = text->pLast;
79 text->pFirst->member.para.next_para = para;
80 text->pLast->member.para.prev_para = para;
82 text->pLast->member.para.nCharOfs = editor->bEmulateVersion10 ? 2 : 1;
84 ME_DestroyContext(&c);
87 static void ME_MarkForWrapping(ME_TextEditor *editor, ME_DisplayItem *first, const ME_DisplayItem *last)
91 first->member.para.nFlags |= MEPF_REWRAP;
92 first = first->member.para.next_para;
96 void ME_MarkAllForWrapping(ME_TextEditor *editor)
98 ME_MarkForWrapping(editor, editor->pBuffer->pFirst->member.para.next_para, editor->pBuffer->pLast);
101 static void ME_UpdateTableFlags(ME_DisplayItem *para)
103 para->member.para.pFmt->dwMask |= PFM_TABLE|PFM_TABLEROWDELIMITER;
104 if (para->member.para.pCell) {
105 para->member.para.nFlags |= MEPF_CELL;
107 para->member.para.nFlags &= ~MEPF_CELL;
109 if (para->member.para.nFlags & MEPF_ROWEND) {
110 para->member.para.pFmt->wEffects |= PFE_TABLEROWDELIMITER;
112 para->member.para.pFmt->wEffects &= ~PFE_TABLEROWDELIMITER;
114 if (para->member.para.nFlags & (MEPF_ROWSTART|MEPF_CELL|MEPF_ROWEND))
115 para->member.para.pFmt->wEffects |= PFE_TABLE;
117 para->member.para.pFmt->wEffects &= ~PFE_TABLE;
120 static BOOL ME_SetParaFormat(ME_TextEditor *editor, ME_DisplayItem *para, const PARAFORMAT2 *pFmt)
125 assert(para->member.para.pFmt->cbSize == sizeof(PARAFORMAT2));
126 dwMask = pFmt->dwMask;
127 if (pFmt->cbSize < sizeof(PARAFORMAT))
129 else if (pFmt->cbSize < sizeof(PARAFORMAT2))
134 add_undo_set_para_fmt( editor, ¶->member.para );
136 copy = *para->member.para.pFmt;
138 #define COPY_FIELD(m, f) \
139 if (dwMask & (m)) { \
140 para->member.para.pFmt->dwMask |= m; \
141 para->member.para.pFmt->f = pFmt->f; \
144 COPY_FIELD(PFM_NUMBERING, wNumbering);
145 COPY_FIELD(PFM_STARTINDENT, dxStartIndent);
146 if (dwMask & PFM_OFFSETINDENT)
147 para->member.para.pFmt->dxStartIndent += pFmt->dxStartIndent;
148 COPY_FIELD(PFM_RIGHTINDENT, dxRightIndent);
149 COPY_FIELD(PFM_OFFSET, dxOffset);
150 COPY_FIELD(PFM_ALIGNMENT, wAlignment);
151 if (dwMask & PFM_TABSTOPS)
153 para->member.para.pFmt->cTabCount = pFmt->cTabCount;
154 memcpy(para->member.para.pFmt->rgxTabs, pFmt->rgxTabs, pFmt->cTabCount*sizeof(LONG));
157 if (dwMask & (PFM_ALL2 & ~PFM_ALL))
159 /* PARAFORMAT2 fields */
161 #define EFFECTS_MASK (PFM_RTLPARA|PFM_KEEP|PFM_KEEPNEXT|PFM_PAGEBREAKBEFORE| \
162 PFM_NOLINENUMBER|PFM_NOWIDOWCONTROL|PFM_DONOTHYPHEN|PFM_SIDEBYSIDE| \
164 /* we take for granted that PFE_xxx is the hiword of the corresponding PFM_xxx */
165 if (dwMask & EFFECTS_MASK) {
166 para->member.para.pFmt->dwMask |= dwMask & EFFECTS_MASK;
167 para->member.para.pFmt->wEffects &= ~HIWORD(dwMask);
168 para->member.para.pFmt->wEffects |= pFmt->wEffects & HIWORD(dwMask);
172 COPY_FIELD(PFM_SPACEBEFORE, dySpaceBefore);
173 COPY_FIELD(PFM_SPACEAFTER, dySpaceAfter);
174 COPY_FIELD(PFM_LINESPACING, dyLineSpacing);
175 COPY_FIELD(PFM_STYLE, sStyle);
176 COPY_FIELD(PFM_LINESPACING, bLineSpacingRule);
177 COPY_FIELD(PFM_SHADING, wShadingWeight);
178 COPY_FIELD(PFM_SHADING, wShadingStyle);
179 COPY_FIELD(PFM_NUMBERINGSTART, wNumberingStart);
180 COPY_FIELD(PFM_NUMBERINGSTYLE, wNumberingStyle);
181 COPY_FIELD(PFM_NUMBERINGTAB, wNumberingTab);
182 COPY_FIELD(PFM_BORDER, wBorderSpace);
183 COPY_FIELD(PFM_BORDER, wBorderWidth);
184 COPY_FIELD(PFM_BORDER, wBorders);
187 para->member.para.pFmt->dwMask |= dwMask;
190 if (memcmp(©, para->member.para.pFmt, sizeof(PARAFORMAT2)))
191 para->member.para.nFlags |= MEPF_REWRAP;
196 /* split paragraph at the beginning of the run */
197 ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run,
198 ME_Style *style, const WCHAR *eol_str, int eol_len,
201 ME_DisplayItem *next_para = NULL;
202 ME_DisplayItem *run_para = NULL;
203 ME_DisplayItem *new_para = ME_MakeDI(diParagraph);
204 ME_DisplayItem *end_run;
207 int run_flags = MERF_ENDPARA;
209 if (!editor->bEmulateVersion10) { /* v4.1 */
210 /* At most 1 of MEPF_CELL, MEPF_ROWSTART, or MEPF_ROWEND should be set. */
211 assert(!(paraFlags & ~(MEPF_CELL|MEPF_ROWSTART|MEPF_ROWEND)));
212 assert(!(paraFlags & (paraFlags-1)));
213 if (paraFlags == MEPF_CELL)
214 run_flags |= MERF_ENDCELL;
215 else if (paraFlags == MEPF_ROWSTART)
216 run_flags |= MERF_TABLESTART|MERF_HIDDEN;
217 } else { /* v1.0 - v3.0 */
218 assert(!(paraFlags & (MEPF_CELL|MEPF_ROWSTART|MEPF_ROWEND)));
220 assert(run->type == diRun);
221 run_para = ME_GetParagraph(run);
222 assert(run_para->member.para.pFmt->cbSize == sizeof(PARAFORMAT2));
224 new_para->member.para.text = ME_VSplitString( run_para->member.para.text, run->member.run.nCharOfs );
226 end_run = ME_MakeRun(style, run_flags);
227 ofs = end_run->member.run.nCharOfs = run->member.run.nCharOfs;
228 end_run->member.run.len = eol_len;
229 end_run->member.run.para = run->member.run.para;
230 ME_AppendString( run_para->member.para.text, eol_str, eol_len );
231 next_para = run_para->member.para.next_para;
232 assert(next_para == ME_FindItemFwd(run_para, diParagraphOrEnd));
234 add_undo_join_paras( editor, run_para->member.para.nCharOfs + ofs );
236 /* Update selection cursors to point to the correct paragraph. */
237 for (i = 0; i < editor->nCursors; i++) {
238 if (editor->pCursors[i].pPara == run_para &&
239 run->member.run.nCharOfs <= editor->pCursors[i].pRun->member.run.nCharOfs)
241 editor->pCursors[i].pPara = new_para;
245 /* the new paragraph will have a different starting offset, so let's update its runs */
247 while(pp->type == diRun) {
248 pp->member.run.nCharOfs -= ofs;
249 pp->member.run.para = &new_para->member.para;
250 pp = ME_FindItemFwd(pp, diRunOrParagraphOrEnd);
252 new_para->member.para.nCharOfs = run_para->member.para.nCharOfs + ofs;
253 new_para->member.para.nCharOfs += eol_len;
254 new_para->member.para.nFlags = MEPF_REWRAP;
256 /* FIXME initialize format style and call ME_SetParaFormat blah blah */
257 *new_para->member.para.pFmt = *run_para->member.para.pFmt;
258 new_para->member.para.border = run_para->member.para.border;
260 /* insert paragraph into paragraph double linked list */
261 new_para->member.para.prev_para = run_para;
262 new_para->member.para.next_para = next_para;
263 run_para->member.para.next_para = new_para;
264 next_para->member.para.prev_para = new_para;
266 /* insert end run of the old paragraph, and new paragraph, into DI double linked list */
267 ME_InsertBefore(run, new_para);
268 ME_InsertBefore(new_para, end_run);
270 if (!editor->bEmulateVersion10) { /* v4.1 */
271 if (paraFlags & (MEPF_ROWSTART|MEPF_CELL))
273 ME_DisplayItem *cell = ME_MakeDI(diCell);
274 ME_InsertBefore(new_para, cell);
275 new_para->member.para.pCell = cell;
276 cell->member.cell.next_cell = NULL;
277 if (paraFlags & MEPF_ROWSTART)
279 run_para->member.para.nFlags |= MEPF_ROWSTART;
280 cell->member.cell.prev_cell = NULL;
281 cell->member.cell.parent_cell = run_para->member.para.pCell;
282 if (run_para->member.para.pCell)
283 cell->member.cell.nNestingLevel = run_para->member.para.pCell->member.cell.nNestingLevel + 1;
285 cell->member.cell.nNestingLevel = 1;
287 cell->member.cell.prev_cell = run_para->member.para.pCell;
288 assert(cell->member.cell.prev_cell);
289 cell->member.cell.prev_cell->member.cell.next_cell = cell;
290 assert(run_para->member.para.nFlags & MEPF_CELL);
291 assert(!(run_para->member.para.nFlags & MEPF_ROWSTART));
292 cell->member.cell.nNestingLevel = cell->member.cell.prev_cell->member.cell.nNestingLevel;
293 cell->member.cell.parent_cell = cell->member.cell.prev_cell->member.cell.parent_cell;
295 } else if (paraFlags & MEPF_ROWEND) {
296 run_para->member.para.nFlags |= MEPF_ROWEND;
297 run_para->member.para.pCell = run_para->member.para.pCell->member.cell.parent_cell;
298 new_para->member.para.pCell = run_para->member.para.pCell;
299 assert(run_para->member.para.prev_para->member.para.nFlags & MEPF_CELL);
300 assert(!(run_para->member.para.prev_para->member.para.nFlags & MEPF_ROWSTART));
301 if (new_para->member.para.pCell != new_para->member.para.next_para->member.para.pCell
302 && new_para->member.para.next_para->member.para.pCell
303 && !new_para->member.para.next_para->member.para.pCell->member.cell.prev_cell)
305 /* Row starts just after the row that was ended. */
306 new_para->member.para.nFlags |= MEPF_ROWSTART;
309 new_para->member.para.pCell = run_para->member.para.pCell;
311 ME_UpdateTableFlags(run_para);
312 ME_UpdateTableFlags(new_para);
315 /* force rewrap of the */
316 run_para->member.para.prev_para->member.para.nFlags |= MEPF_REWRAP;
317 new_para->member.para.prev_para->member.para.nFlags |= MEPF_REWRAP;
319 /* we've added the end run, so we need to modify nCharOfs in the next paragraphs */
320 ME_PropagateCharOffset(next_para, eol_len);
321 editor->nParagraphs++;
326 /* join tp with tp->member.para.next_para, keeping tp's style; this
327 * is consistent with the original */
328 ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp,
329 BOOL keepFirstParaFormat)
331 ME_DisplayItem *pNext, *pFirstRunInNext, *pRun, *pTmp, *pCell = NULL;
335 ME_Cursor startCur, endCur;
338 assert(tp->type == diParagraph);
339 assert(tp->member.para.next_para);
340 assert(tp->member.para.next_para->type == diParagraph);
342 pNext = tp->member.para.next_para;
344 /* Need to locate end-of-paragraph run here, in order to know end_len */
345 pRun = ME_FindItemBack(pNext, diRunOrParagraph);
348 assert(pRun->type == diRun);
349 assert(pRun->member.run.nFlags & MERF_ENDPARA);
351 end_len = pRun->member.run.len;
352 eol_str = ME_VSplitString( tp->member.para.text, pRun->member.run.nCharOfs );
353 ME_AppendString( tp->member.para.text, pNext->member.para.text->szData, pNext->member.para.text->nLen );
355 /* null char format operation to store the original char format for the ENDPARA run */
356 ME_InitCharFormat2W(&fmt);
357 endCur.pPara = pNext;
358 endCur.pRun = ME_FindItemFwd(pNext, diRun);
361 ME_PrevRun(&startCur.pPara, &startCur.pRun);
362 ME_SetCharFormat(editor, &startCur, &endCur, &fmt);
364 if (!editor->bEmulateVersion10) { /* v4.1 */
365 /* Table cell/row properties are always moved over from the removed para. */
366 tp->member.para.nFlags = pNext->member.para.nFlags;
367 tp->member.para.pCell = pNext->member.para.pCell;
369 /* Remove cell boundary if it is between the end paragraph run and the next
370 * paragraph display item. */
371 for (pTmp = pRun->next; pTmp != pNext; pTmp = pTmp->next)
373 if (pTmp->type == diCell)
381 add_undo_split_para( editor, &pNext->member.para, eol_str, pCell ? &pCell->member.cell : NULL );
386 if (pCell->member.cell.prev_cell)
387 pCell->member.cell.prev_cell->member.cell.next_cell = pCell->member.cell.next_cell;
388 if (pCell->member.cell.next_cell)
389 pCell->member.cell.next_cell->member.cell.prev_cell = pCell->member.cell.prev_cell;
390 ME_DestroyDisplayItem( pCell );
393 if (!keepFirstParaFormat)
395 add_undo_set_para_fmt( editor, &tp->member.para );
396 *tp->member.para.pFmt = *pNext->member.para.pFmt;
397 tp->member.para.border = pNext->member.para.border;
400 shift = pNext->member.para.nCharOfs - tp->member.para.nCharOfs - end_len;
402 pFirstRunInNext = ME_FindItemFwd(pNext, diRunOrParagraph);
404 assert(pFirstRunInNext->type == diRun);
406 /* Update selection cursors so they don't point to the removed end
407 * paragraph run, and point to the correct paragraph. */
408 for (i=0; i < editor->nCursors; i++) {
409 if (editor->pCursors[i].pRun == pRun) {
410 editor->pCursors[i].pRun = pFirstRunInNext;
411 editor->pCursors[i].nOffset = 0;
412 } else if (editor->pCursors[i].pPara == pNext) {
413 editor->pCursors[i].pPara = tp;
419 pTmp = ME_FindItemFwd(pTmp, diRunOrParagraphOrEnd);
420 if (pTmp->type != diRun)
422 TRACE("shifting %s by %d (previous %d)\n", debugstr_run( &pTmp->member.run ), shift, pTmp->member.run.nCharOfs);
423 pTmp->member.run.nCharOfs += shift;
424 pTmp->member.run.para = &tp->member.para;
428 ME_DestroyDisplayItem(pRun);
430 if (editor->pLastSelStartPara == pNext)
431 editor->pLastSelStartPara = tp;
432 if (editor->pLastSelEndPara == pNext)
433 editor->pLastSelEndPara = tp;
435 tp->member.para.next_para = pNext->member.para.next_para;
436 pNext->member.para.next_para->member.para.prev_para = tp;
438 ME_DestroyDisplayItem(pNext);
440 ME_PropagateCharOffset(tp->member.para.next_para, -end_len);
442 ME_CheckCharOffsets(editor);
444 editor->nParagraphs--;
445 tp->member.para.nFlags |= MEPF_REWRAP;
449 ME_DisplayItem *ME_GetParagraph(ME_DisplayItem *item) {
450 return ME_FindItemBackOrHere(item, diParagraph);
453 void ME_DumpParaStyleToBuf(const PARAFORMAT2 *pFmt, char buf[2048])
458 #define DUMP(mask, name, fmt, field) \
459 if (pFmt->dwMask & (mask)) p += sprintf(p, "%-22s" fmt "\n", name, pFmt->field); \
460 else p += sprintf(p, "%-22sN/A\n", name);
462 /* we take for granted that PFE_xxx is the hiword of the corresponding PFM_xxx */
463 #define DUMP_EFFECT(mask, name) \
464 p += sprintf(p, "%-22s%s\n", name, (pFmt->dwMask & (mask)) ? ((pFmt->wEffects & ((mask) >> 16)) ? "yes" : "no") : "N/A");
466 DUMP(PFM_NUMBERING, "Numbering:", "%u", wNumbering);
467 DUMP_EFFECT(PFM_DONOTHYPHEN, "Disable auto-hyphen:");
468 DUMP_EFFECT(PFM_KEEP, "No page break in para:");
469 DUMP_EFFECT(PFM_KEEPNEXT, "No page break in para & next:");
470 DUMP_EFFECT(PFM_NOLINENUMBER, "No line number:");
471 DUMP_EFFECT(PFM_NOWIDOWCONTROL, "No widow & orphan:");
472 DUMP_EFFECT(PFM_PAGEBREAKBEFORE, "Page break before:");
473 DUMP_EFFECT(PFM_RTLPARA, "RTL para:");
474 DUMP_EFFECT(PFM_SIDEBYSIDE, "Side by side:");
475 DUMP_EFFECT(PFM_TABLE, "Table:");
476 DUMP(PFM_OFFSETINDENT, "Offset indent:", "%d", dxStartIndent);
477 DUMP(PFM_STARTINDENT, "Start indent:", "%d", dxStartIndent);
478 DUMP(PFM_RIGHTINDENT, "Right indent:", "%d", dxRightIndent);
479 DUMP(PFM_OFFSET, "Offset:", "%d", dxOffset);
480 if (pFmt->dwMask & PFM_ALIGNMENT) {
481 switch (pFmt->wAlignment) {
482 case PFA_LEFT : p += sprintf(p, "Alignment: left\n"); break;
483 case PFA_RIGHT : p += sprintf(p, "Alignment: right\n"); break;
484 case PFA_CENTER : p += sprintf(p, "Alignment: center\n"); break;
485 case PFA_JUSTIFY: p += sprintf(p, "Alignment: justify\n"); break;
486 default : p += sprintf(p, "Alignment: incorrect %d\n", pFmt->wAlignment); break;
489 else p += sprintf(p, "Alignment: N/A\n");
490 DUMP(PFM_TABSTOPS, "Tab Stops:", "%d", cTabCount);
491 if (pFmt->dwMask & PFM_TABSTOPS) {
493 p += sprintf(p, "\t");
494 for (i = 0; i < pFmt->cTabCount; i++) p += sprintf(p, "%x ", pFmt->rgxTabs[i]);
495 p += sprintf(p, "\n");
497 DUMP(PFM_SPACEBEFORE, "Space Before:", "%d", dySpaceBefore);
498 DUMP(PFM_SPACEAFTER, "Space After:", "%d", dySpaceAfter);
499 DUMP(PFM_LINESPACING, "Line spacing:", "%d", dyLineSpacing);
500 DUMP(PFM_STYLE, "Text style:", "%d", sStyle);
501 DUMP(PFM_LINESPACING, "Line spacing rule:", "%u", bLineSpacingRule);
502 /* bOutlineLevel should be 0 */
503 DUMP(PFM_SHADING, "Shading Weigth:", "%u", wShadingWeight);
504 DUMP(PFM_SHADING, "Shading Style:", "%u", wShadingStyle);
505 DUMP(PFM_NUMBERINGSTART, "Numbering Start:", "%u", wNumberingStart);
506 DUMP(PFM_NUMBERINGSTYLE, "Numbering Style:", "0x%x", wNumberingStyle);
507 DUMP(PFM_NUMBERINGTAB, "Numbering Tab:", "%u", wNumberingStyle);
508 DUMP(PFM_BORDER, "Border Space:", "%u", wBorderSpace);
509 DUMP(PFM_BORDER, "Border Width:", "%u", wBorderWidth);
510 DUMP(PFM_BORDER, "Borders:", "%u", wBorders);
517 ME_GetSelectionParas(ME_TextEditor *editor, ME_DisplayItem **para, ME_DisplayItem **para_end)
519 ME_Cursor *pEndCursor = &editor->pCursors[1];
521 *para = editor->pCursors[0].pPara;
522 *para_end = editor->pCursors[1].pPara;
523 if (*para == *para_end)
526 if ((*para_end)->member.para.nCharOfs < (*para)->member.para.nCharOfs) {
527 ME_DisplayItem *tmp = *para;
531 pEndCursor = &editor->pCursors[0];
534 /* The paragraph at the end of a non-empty selection isn't included
535 * if the selection ends at the start of the paragraph. */
536 if (!pEndCursor->pRun->member.run.nCharOfs && !pEndCursor->nOffset)
537 *para_end = (*para_end)->member.para.prev_para;
541 BOOL ME_SetSelectionParaFormat(ME_TextEditor *editor, const PARAFORMAT2 *pFmt)
543 ME_DisplayItem *para, *para_end;
545 ME_GetSelectionParas(editor, ¶, ¶_end);
548 ME_SetParaFormat(editor, para, pFmt);
549 if (para == para_end)
551 para = para->member.para.next_para;
557 static void ME_GetParaFormat(ME_TextEditor *editor,
558 const ME_DisplayItem *para,
561 UINT cbSize = pFmt->cbSize;
562 if (pFmt->cbSize >= sizeof(PARAFORMAT2)) {
563 *pFmt = *para->member.para.pFmt;
565 CopyMemory(pFmt, para->member.para.pFmt, pFmt->cbSize);
566 pFmt->dwMask &= PFM_ALL;
568 pFmt->cbSize = cbSize;
571 void ME_GetSelectionParaFormat(ME_TextEditor *editor, PARAFORMAT2 *pFmt)
573 ME_DisplayItem *para, *para_end;
576 if (pFmt->cbSize < sizeof(PARAFORMAT)) {
581 ME_GetSelectionParas(editor, ¶, ¶_end);
583 ME_GetParaFormat(editor, para, pFmt);
585 /* Invalidate values that change across the selected paragraphs. */
586 while (para != para_end)
588 para = para->member.para.next_para;
589 curFmt = para->member.para.pFmt;
591 #define CHECK_FIELD(m, f) \
592 if (pFmt->f != curFmt->f) pFmt->dwMask &= ~(m);
594 CHECK_FIELD(PFM_NUMBERING, wNumbering);
595 CHECK_FIELD(PFM_STARTINDENT, dxStartIndent);
596 CHECK_FIELD(PFM_RIGHTINDENT, dxRightIndent);
597 CHECK_FIELD(PFM_OFFSET, dxOffset);
598 CHECK_FIELD(PFM_ALIGNMENT, wAlignment);
599 if (pFmt->dwMask & PFM_TABSTOPS) {
600 if (pFmt->cTabCount != para->member.para.pFmt->cTabCount ||
601 memcmp(pFmt->rgxTabs, curFmt->rgxTabs, curFmt->cTabCount*sizeof(int)))
602 pFmt->dwMask &= ~PFM_TABSTOPS;
605 if (pFmt->dwMask >= sizeof(PARAFORMAT2))
607 pFmt->dwMask &= ~((pFmt->wEffects ^ curFmt->wEffects) << 16);
608 CHECK_FIELD(PFM_SPACEBEFORE, dySpaceBefore);
609 CHECK_FIELD(PFM_SPACEAFTER, dySpaceAfter);
610 CHECK_FIELD(PFM_LINESPACING, dyLineSpacing);
611 CHECK_FIELD(PFM_STYLE, sStyle);
612 CHECK_FIELD(PFM_SPACEAFTER, bLineSpacingRule);
613 CHECK_FIELD(PFM_SHADING, wShadingWeight);
614 CHECK_FIELD(PFM_SHADING, wShadingStyle);
615 CHECK_FIELD(PFM_NUMBERINGSTART, wNumberingStart);
616 CHECK_FIELD(PFM_NUMBERINGSTYLE, wNumberingStyle);
617 CHECK_FIELD(PFM_NUMBERINGTAB, wNumberingTab);
618 CHECK_FIELD(PFM_BORDER, wBorderSpace);
619 CHECK_FIELD(PFM_BORDER, wBorderWidth);
620 CHECK_FIELD(PFM_BORDER, wBorders);
626 void ME_SetDefaultParaFormat(PARAFORMAT2 *pFmt)
628 ZeroMemory(pFmt, sizeof(PARAFORMAT2));
629 pFmt->cbSize = sizeof(PARAFORMAT2);
630 pFmt->dwMask = PFM_ALL2;
631 pFmt->wAlignment = PFA_LEFT;
633 pFmt->bOutlineLevel = TRUE;