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 static const WCHAR wszParagraphSign
[] = {0xB6, 0};
28 void ME_MakeFirstParagraph(ME_TextEditor
*editor
)
34 ME_TextBuffer
*text
= editor
->pBuffer
;
35 ME_DisplayItem
*para
= ME_MakeDI(diParagraph
);
39 ME_InitContext(&c
, editor
, GetDC(editor
->hWnd
));
41 hf
= (HFONT
)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 run
= ME_MakeRun(style
, ME_MakeString(wszParagraphSign
), MERF_ENDPARA
);
68 run
->member
.run
.nCharOfs
= 0;
69 run
->member
.run
.nCR
= 1;
70 run
->member
.run
.nLF
= (editor
->bEmulateVersion10
) ? 1 : 0;
72 ME_InsertBefore(text
->pLast
, para
);
73 ME_InsertBefore(text
->pLast
, run
);
74 para
->member
.para
.prev_para
= text
->pFirst
;
75 para
->member
.para
.next_para
= text
->pLast
;
76 text
->pFirst
->member
.para
.next_para
= para
;
77 text
->pLast
->member
.para
.prev_para
= para
;
79 text
->pLast
->member
.para
.nCharOfs
= 1;
81 ME_DestroyContext(&c
, editor
->hWnd
);
84 void ME_MarkAllForWrapping(ME_TextEditor
*editor
)
86 ME_MarkForWrapping(editor
, editor
->pBuffer
->pFirst
->member
.para
.next_para
, editor
->pBuffer
->pLast
);
89 void ME_MarkForWrapping(ME_TextEditor
*editor
, ME_DisplayItem
*first
, const ME_DisplayItem
*last
)
93 first
->member
.para
.nFlags
|= MEPF_REWRAP
;
94 first
= first
->member
.para
.next_para
;
98 void ME_MarkForPainting(ME_TextEditor
*editor
, ME_DisplayItem
*first
, const ME_DisplayItem
*last
)
100 while(first
!= last
&& first
)
102 first
->member
.para
.nFlags
|= MEPF_REPAINT
;
103 first
= first
->member
.para
.next_para
;
107 static void ME_UpdateTableFlags(ME_DisplayItem
*para
)
109 para
->member
.para
.pFmt
->dwMask
|= PFM_TABLE
|PFM_TABLEROWDELIMITER
;
110 if (para
->member
.para
.pCell
) {
111 para
->member
.para
.nFlags
|= MEPF_CELL
;
113 para
->member
.para
.nFlags
&= ~MEPF_CELL
;
115 if (para
->member
.para
.nFlags
& MEPF_ROWEND
) {
116 para
->member
.para
.pFmt
->wEffects
|= PFE_TABLEROWDELIMITER
;
118 para
->member
.para
.pFmt
->wEffects
&= ~PFE_TABLEROWDELIMITER
;
120 if (para
->member
.para
.nFlags
& (MEPF_ROWSTART
|MEPF_CELL
|MEPF_ROWEND
))
121 para
->member
.para
.pFmt
->wEffects
|= PFE_TABLE
;
123 para
->member
.para
.pFmt
->wEffects
&= ~PFE_TABLE
;
126 /* split paragraph at the beginning of the run */
127 ME_DisplayItem
*ME_SplitParagraph(ME_TextEditor
*editor
, ME_DisplayItem
*run
,
128 ME_Style
*style
, int numCR
, int numLF
,
131 ME_DisplayItem
*next_para
= NULL
;
132 ME_DisplayItem
*run_para
= NULL
;
133 ME_DisplayItem
*new_para
= ME_MakeDI(diParagraph
);
134 ME_DisplayItem
*end_run
;
135 ME_UndoItem
*undo
= NULL
;
138 int end_len
= numCR
+ numLF
;
139 int run_flags
= MERF_ENDPARA
;
140 if (!editor
->bEmulateVersion10
) { /* v4.1 */
141 /* At most 1 of MEPF_CELL, MEPF_ROWSTART, or MEPF_ROWEND should be set. */
142 assert(!(paraFlags
& ~(MEPF_CELL
|MEPF_ROWSTART
|MEPF_ROWEND
)));
143 assert(!(paraFlags
& (paraFlags
-1)));
144 if (paraFlags
== MEPF_CELL
)
145 run_flags
|= MERF_ENDCELL
;
146 else if (paraFlags
== MEPF_ROWSTART
)
147 run_flags
|= MERF_TABLESTART
|MERF_HIDDEN
;
148 } else { /* v1.0 - v3.0 */
149 assert(!(paraFlags
& (MEPF_CELL
|MEPF_ROWSTART
|MEPF_ROWEND
)));
151 end_run
= ME_MakeRun(style
,ME_MakeString(wszParagraphSign
), run_flags
);
153 assert(run
->type
== diRun
);
155 end_run
->member
.run
.nCR
= numCR
;
156 end_run
->member
.run
.nLF
= numLF
;
157 run_para
= ME_GetParagraph(run
);
158 assert(run_para
->member
.para
.pFmt
->cbSize
== sizeof(PARAFORMAT2
));
160 ofs
= end_run
->member
.run
.nCharOfs
= run
->member
.run
.nCharOfs
;
161 next_para
= run_para
->member
.para
.next_para
;
162 assert(next_para
== ME_FindItemFwd(run_para
, diParagraphOrEnd
));
164 undo
= ME_AddUndoItem(editor
, diUndoJoinParagraphs
, NULL
);
166 undo
->nStart
= run_para
->member
.para
.nCharOfs
+ ofs
;
168 /* the new paragraph will have a different starting offset, so let's update its runs */
170 while(pp
->type
== diRun
) {
171 pp
->member
.run
.nCharOfs
-= ofs
;
172 pp
= ME_FindItemFwd(pp
, diRunOrParagraphOrEnd
);
174 new_para
->member
.para
.nCharOfs
= ME_GetParagraph(run
)->member
.para
.nCharOfs
+ofs
;
175 new_para
->member
.para
.nCharOfs
+= end_len
;
176 new_para
->member
.para
.nFlags
= MEPF_REWRAP
;
178 /* FIXME initialize format style and call ME_SetParaFormat blah blah */
179 *new_para
->member
.para
.pFmt
= *run_para
->member
.para
.pFmt
;
180 new_para
->member
.para
.border
= run_para
->member
.para
.border
;
182 /* insert paragraph into paragraph double linked list */
183 new_para
->member
.para
.prev_para
= run_para
;
184 new_para
->member
.para
.next_para
= next_para
;
185 run_para
->member
.para
.next_para
= new_para
;
186 next_para
->member
.para
.prev_para
= new_para
;
188 /* insert end run of the old paragraph, and new paragraph, into DI double linked list */
189 ME_InsertBefore(run
, new_para
);
190 ME_InsertBefore(new_para
, end_run
);
192 if (!editor
->bEmulateVersion10
) { /* v4.1 */
193 if (paraFlags
& (MEPF_ROWSTART
|MEPF_CELL
))
195 ME_DisplayItem
*cell
= ME_MakeDI(diCell
);
196 ME_InsertBefore(new_para
, cell
);
197 new_para
->member
.para
.pCell
= cell
;
198 cell
->member
.cell
.next_cell
= NULL
;
199 if (paraFlags
& MEPF_ROWSTART
)
201 run_para
->member
.para
.nFlags
|= MEPF_ROWSTART
;
202 cell
->member
.cell
.prev_cell
= NULL
;
203 cell
->member
.cell
.parent_cell
= run_para
->member
.para
.pCell
;
204 if (run_para
->member
.para
.pCell
)
205 cell
->member
.cell
.nNestingLevel
= run_para
->member
.para
.pCell
->member
.cell
.nNestingLevel
+ 1;
207 cell
->member
.cell
.nNestingLevel
= 1;
209 cell
->member
.cell
.prev_cell
= run_para
->member
.para
.pCell
;
210 assert(cell
->member
.cell
.prev_cell
);
211 cell
->member
.cell
.prev_cell
->member
.cell
.next_cell
= cell
;
212 assert(run_para
->member
.para
.nFlags
& MEPF_CELL
);
213 assert(!(run_para
->member
.para
.nFlags
& MEPF_ROWSTART
));
214 cell
->member
.cell
.nNestingLevel
= cell
->member
.cell
.prev_cell
->member
.cell
.nNestingLevel
;
215 cell
->member
.cell
.parent_cell
= cell
->member
.cell
.prev_cell
->member
.cell
.parent_cell
;
217 } else if (paraFlags
& MEPF_ROWEND
) {
218 run_para
->member
.para
.nFlags
|= MEPF_ROWEND
;
219 run_para
->member
.para
.pCell
= run_para
->member
.para
.pCell
->member
.cell
.parent_cell
;
220 new_para
->member
.para
.pCell
= run_para
->member
.para
.pCell
;
221 assert(run_para
->member
.para
.prev_para
->member
.para
.nFlags
& MEPF_CELL
);
222 assert(!(run_para
->member
.para
.prev_para
->member
.para
.nFlags
& MEPF_ROWSTART
));
224 new_para
->member
.para
.pCell
= run_para
->member
.para
.pCell
;
226 ME_UpdateTableFlags(run_para
);
227 ME_UpdateTableFlags(new_para
);
230 /* force rewrap of the */
231 run_para
->member
.para
.prev_para
->member
.para
.nFlags
|= MEPF_REWRAP
;
232 new_para
->member
.para
.prev_para
->member
.para
.nFlags
|= MEPF_REWRAP
;
234 /* we've added the end run, so we need to modify nCharOfs in the next paragraphs */
235 ME_PropagateCharOffset(next_para
, end_len
);
236 editor
->nParagraphs
++;
241 /* join tp with tp->member.para.next_para, keeping tp's style; this
242 * is consistent with the original */
243 ME_DisplayItem
*ME_JoinParagraphs(ME_TextEditor
*editor
, ME_DisplayItem
*tp
,
244 BOOL keepFirstParaFormat
)
246 ME_DisplayItem
*pNext
, *pFirstRunInNext
, *pRun
, *pTmp
;
248 ME_UndoItem
*undo
= NULL
;
251 assert(tp
->type
== diParagraph
);
252 assert(tp
->member
.para
.next_para
);
253 assert(tp
->member
.para
.next_para
->type
== diParagraph
);
255 pNext
= tp
->member
.para
.next_para
;
257 /* Need to locate end-of-paragraph run here, in order to know end_len */
258 pRun
= ME_FindItemBack(pNext
, diRunOrParagraph
);
261 assert(pRun
->type
== diRun
);
262 assert(pRun
->member
.run
.nFlags
& MERF_ENDPARA
);
264 end_len
= pRun
->member
.run
.nCR
+ pRun
->member
.run
.nLF
;
267 /* null char format operation to store the original char format for the ENDPARA run */
269 ME_InitCharFormat2W(&fmt
);
270 ME_SetCharFormat(editor
, pNext
->member
.para
.nCharOfs
- end_len
, end_len
, &fmt
);
272 undo
= ME_AddUndoItem(editor
, diUndoSplitParagraph
, pNext
);
275 undo
->nStart
= pNext
->member
.para
.nCharOfs
- end_len
;
276 undo
->nCR
= pRun
->member
.run
.nCR
;
277 undo
->nLF
= pRun
->member
.run
.nLF
;
279 if (!keepFirstParaFormat
)
281 ME_AddUndoItem(editor
, diUndoSetParagraphFormat
, tp
);
282 *tp
->member
.para
.pFmt
= *pNext
->member
.para
.pFmt
;
285 if (!editor
->bEmulateVersion10
) { /* v4.1 */
286 /* Table cell/row properties are always moved over from the removed para. */
287 tp
->member
.para
.nFlags
= pNext
->member
.para
.nFlags
;
288 tp
->member
.para
.pCell
= pNext
->member
.para
.pCell
;
290 /* Remove cell boundary if it is between the end paragraph run and the next
291 * paragraph display item. */
293 while (pTmp
!= pNext
) {
294 if (pTmp
->type
== diCell
)
296 ME_Cell
*pCell
= &pTmp
->member
.cell
;
299 assert(!(undo
->di
.member
.para
.nFlags
& MEPF_ROWEND
));
300 if (!(undo
->di
.member
.para
.nFlags
& MEPF_ROWSTART
))
301 undo
->di
.member
.para
.nFlags
|= MEPF_CELL
;
302 undo
->di
.member
.para
.pCell
= ALLOC_OBJ(ME_DisplayItem
);
303 *undo
->di
.member
.para
.pCell
= *pTmp
;
304 undo
->di
.member
.para
.pCell
->next
= NULL
;
305 undo
->di
.member
.para
.pCell
->prev
= NULL
;
306 undo
->di
.member
.para
.pCell
->member
.cell
.next_cell
= NULL
;
307 undo
->di
.member
.para
.pCell
->member
.cell
.prev_cell
= NULL
;
310 if (pCell
->prev_cell
)
311 pCell
->prev_cell
->member
.cell
.next_cell
= pCell
->next_cell
;
312 if (pCell
->next_cell
)
313 pCell
->next_cell
->member
.cell
.prev_cell
= pCell
->prev_cell
;
314 ME_DestroyDisplayItem(pTmp
);
321 shift
= pNext
->member
.para
.nCharOfs
- tp
->member
.para
.nCharOfs
- end_len
;
323 pFirstRunInNext
= ME_FindItemFwd(pNext
, diRunOrParagraph
);
325 assert(pFirstRunInNext
->type
== diRun
);
327 /* if some cursor points at end of paragraph, make it point to the first
328 run of the next joined paragraph */
329 for (i
=0; i
<editor
->nCursors
; i
++) {
330 if (editor
->pCursors
[i
].pRun
== pRun
) {
331 editor
->pCursors
[i
].pRun
= pFirstRunInNext
;
332 editor
->pCursors
[i
].nOffset
= 0;
338 pTmp
= ME_FindItemFwd(pTmp
, diRunOrParagraphOrEnd
);
339 if (pTmp
->type
!= diRun
)
341 TRACE("shifting \"%s\" by %d (previous %d)\n", debugstr_w(pTmp
->member
.run
.strText
->szData
), shift
, pTmp
->member
.run
.nCharOfs
);
342 pTmp
->member
.run
.nCharOfs
+= shift
;
346 ME_DestroyDisplayItem(pRun
);
348 if (editor
->pLastSelStartPara
== pNext
)
349 editor
->pLastSelStartPara
= tp
;
350 if (editor
->pLastSelEndPara
== pNext
)
351 editor
->pLastSelEndPara
= tp
;
353 tp
->member
.para
.next_para
= pNext
->member
.para
.next_para
;
354 pNext
->member
.para
.next_para
->member
.para
.prev_para
= tp
;
356 ME_DestroyDisplayItem(pNext
);
358 ME_PropagateCharOffset(tp
->member
.para
.next_para
, -end_len
);
360 ME_CheckCharOffsets(editor
);
362 editor
->nParagraphs
--;
363 tp
->member
.para
.nFlags
|= MEPF_REWRAP
;
367 ME_DisplayItem
*ME_GetParagraph(ME_DisplayItem
*item
) {
368 return ME_FindItemBackOrHere(item
, diParagraph
);
371 void ME_DumpParaStyleToBuf(const PARAFORMAT2
*pFmt
, char buf
[2048])
376 #define DUMP(mask, name, fmt, field) \
377 if (pFmt->dwMask & (mask)) p += sprintf(p, "%-22s" fmt "\n", name, pFmt->field); \
378 else p += sprintf(p, "%-22sN/A\n", name);
380 /* we take for granted that PFE_xxx is the hiword of the corresponding PFM_xxx */
381 #define DUMP_EFFECT(mask, name) \
382 p += sprintf(p, "%-22s%s\n", name, (pFmt->dwMask & (mask)) ? ((pFmt->wEffects & ((mask) >> 8)) ? "yes" : "no") : "N/A");
384 DUMP(PFM_NUMBERING
, "Numbering:", "%u", wNumbering
);
385 DUMP_EFFECT(PFM_DONOTHYPHEN
, "Disable auto-hyphen:");
386 DUMP_EFFECT(PFM_KEEP
, "No page break in para:");
387 DUMP_EFFECT(PFM_KEEPNEXT
, "No page break in para & next:");
388 DUMP_EFFECT(PFM_NOLINENUMBER
, "No line number:");
389 DUMP_EFFECT(PFM_NOWIDOWCONTROL
, "No widow & orphan:");
390 DUMP_EFFECT(PFM_PAGEBREAKBEFORE
, "Page break before:");
391 DUMP_EFFECT(PFM_RTLPARA
, "RTL para:");
392 DUMP_EFFECT(PFM_SIDEBYSIDE
, "Side by side:");
393 DUMP_EFFECT(PFM_TABLE
, "Table:");
394 DUMP(PFM_OFFSETINDENT
, "Offset indent:", "%d", dxStartIndent
);
395 DUMP(PFM_STARTINDENT
, "Start indent:", "%d", dxStartIndent
);
396 DUMP(PFM_RIGHTINDENT
, "Right indent:", "%d", dxRightIndent
);
397 DUMP(PFM_OFFSET
, "Offset:", "%d", dxOffset
);
398 if (pFmt
->dwMask
& PFM_ALIGNMENT
) {
399 switch (pFmt
->wAlignment
) {
400 case PFA_LEFT
: p
+= sprintf(p
, "Alignment: left\n"); break;
401 case PFA_RIGHT
: p
+= sprintf(p
, "Alignment: right\n"); break;
402 case PFA_CENTER
: p
+= sprintf(p
, "Alignment: center\n"); break;
403 case PFA_JUSTIFY
: p
+= sprintf(p
, "Alignment: justify\n"); break;
404 default : p
+= sprintf(p
, "Alignment: incorrect %d\n", pFmt
->wAlignment
); break;
407 else p
+= sprintf(p
, "Alignment: N/A\n");
408 DUMP(PFM_TABSTOPS
, "Tab Stops:", "%d", cTabCount
);
409 if (pFmt
->dwMask
& PFM_TABSTOPS
) {
411 p
+= sprintf(p
, "\t");
412 for (i
= 0; i
< pFmt
->cTabCount
; i
++) p
+= sprintf(p
, "%x ", pFmt
->rgxTabs
[i
]);
413 p
+= sprintf(p
, "\n");
415 DUMP(PFM_SPACEBEFORE
, "Space Before:", "%d", dySpaceBefore
);
416 DUMP(PFM_SPACEAFTER
, "Space After:", "%d", dySpaceAfter
);
417 DUMP(PFM_LINESPACING
, "Line spacing:", "%d", dyLineSpacing
);
418 DUMP(PFM_STYLE
, "Text style:", "%d", sStyle
);
419 DUMP(PFM_LINESPACING
, "Line spacing rule:", "%u", bLineSpacingRule
);
420 /* bOutlineLevel should be 0 */
421 DUMP(PFM_SHADING
, "Shading Weigth:", "%u", wShadingWeight
);
422 DUMP(PFM_SHADING
, "Shading Style:", "%u", wShadingStyle
);
423 DUMP(PFM_NUMBERINGSTART
, "Numbering Start:", "%u", wNumberingStart
);
424 DUMP(PFM_NUMBERINGSTYLE
, "Numbering Style:", "0x%x", wNumberingStyle
);
425 DUMP(PFM_NUMBERINGTAB
, "Numbering Tab:", "%u", wNumberingStyle
);
426 DUMP(PFM_BORDER
, "Border Space:", "%u", wBorderSpace
);
427 DUMP(PFM_BORDER
, "Border Width:", "%u", wBorderWidth
);
428 DUMP(PFM_BORDER
, "Borders:", "%u", wBorders
);
434 BOOL
ME_SetParaFormat(ME_TextEditor
*editor
, ME_DisplayItem
*para
, const PARAFORMAT2
*pFmt
)
437 assert(sizeof(*para
->member
.para
.pFmt
) == sizeof(PARAFORMAT2
));
438 ME_AddUndoItem(editor
, diUndoSetParagraphFormat
, para
);
440 copy
= *para
->member
.para
.pFmt
;
442 #define COPY_FIELD(m, f) \
443 if (pFmt->dwMask & (m)) { \
444 para->member.para.pFmt->dwMask |= m; \
445 para->member.para.pFmt->f = pFmt->f; \
448 COPY_FIELD(PFM_NUMBERING
, wNumbering
);
449 #define EFFECTS_MASK (PFM_RTLPARA|PFM_KEEP|PFM_KEEPNEXT|PFM_PAGEBREAKBEFORE| \
450 PFM_NOLINENUMBER|PFM_NOWIDOWCONTROL|PFM_DONOTHYPHEN|PFM_SIDEBYSIDE| \
452 /* we take for granted that PFE_xxx is the hiword of the corresponding PFM_xxx */
453 if (pFmt
->dwMask
& EFFECTS_MASK
) {
454 para
->member
.para
.pFmt
->dwMask
|= pFmt
->dwMask
& EFFECTS_MASK
;
455 para
->member
.para
.pFmt
->wEffects
&= ~HIWORD(pFmt
->dwMask
);
456 para
->member
.para
.pFmt
->wEffects
|= pFmt
->wEffects
& HIWORD(pFmt
->dwMask
);
460 COPY_FIELD(PFM_STARTINDENT
, dxStartIndent
);
461 if (pFmt
->dwMask
& PFM_OFFSETINDENT
)
462 para
->member
.para
.pFmt
->dxStartIndent
+= pFmt
->dxStartIndent
;
463 COPY_FIELD(PFM_RIGHTINDENT
, dxRightIndent
);
464 COPY_FIELD(PFM_OFFSET
, dxOffset
);
465 COPY_FIELD(PFM_ALIGNMENT
, wAlignment
);
467 if (pFmt
->dwMask
& PFM_TABSTOPS
)
469 para
->member
.para
.pFmt
->cTabCount
= pFmt
->cTabCount
;
470 memcpy(para
->member
.para
.pFmt
->rgxTabs
, pFmt
->rgxTabs
, pFmt
->cTabCount
*sizeof(LONG
));
472 COPY_FIELD(PFM_SPACEBEFORE
, dySpaceBefore
);
473 COPY_FIELD(PFM_SPACEAFTER
, dySpaceAfter
);
474 COPY_FIELD(PFM_LINESPACING
, dyLineSpacing
);
475 COPY_FIELD(PFM_STYLE
, sStyle
);
476 COPY_FIELD(PFM_LINESPACING
, bLineSpacingRule
);
477 COPY_FIELD(PFM_SHADING
, wShadingWeight
);
478 COPY_FIELD(PFM_SHADING
, wShadingStyle
);
479 COPY_FIELD(PFM_NUMBERINGSTART
, wNumberingStart
);
480 COPY_FIELD(PFM_NUMBERINGSTYLE
, wNumberingStyle
);
481 COPY_FIELD(PFM_NUMBERINGTAB
, wNumberingTab
);
482 COPY_FIELD(PFM_BORDER
, wBorderSpace
);
483 COPY_FIELD(PFM_BORDER
, wBorderWidth
);
484 COPY_FIELD(PFM_BORDER
, wBorders
);
486 para
->member
.para
.pFmt
->dwMask
|= pFmt
->dwMask
;
489 if (memcmp(©
, para
->member
.para
.pFmt
, sizeof(PARAFORMAT2
)))
490 para
->member
.para
.nFlags
|= MEPF_REWRAP
;
497 ME_GetSelectionParas(ME_TextEditor
*editor
, ME_DisplayItem
**para
, ME_DisplayItem
**para_end
)
499 ME_Cursor
*pEndCursor
= &editor
->pCursors
[1];
501 *para
= ME_GetParagraph(editor
->pCursors
[0].pRun
);
502 *para_end
= ME_GetParagraph(editor
->pCursors
[1].pRun
);
503 if ((*para_end
)->member
.para
.nCharOfs
< (*para
)->member
.para
.nCharOfs
) {
504 ME_DisplayItem
*tmp
= *para
;
508 pEndCursor
= &editor
->pCursors
[0];
511 /* selection consists of chars from nFrom up to nTo-1 */
512 if ((*para_end
)->member
.para
.nCharOfs
> (*para
)->member
.para
.nCharOfs
) {
513 if (!pEndCursor
->nOffset
) {
514 *para_end
= ME_GetParagraph(ME_FindItemBack(pEndCursor
->pRun
, diRun
));
520 BOOL
ME_SetSelectionParaFormat(ME_TextEditor
*editor
, const PARAFORMAT2
*pFmt
)
522 ME_DisplayItem
*para
, *para_end
;
524 ME_GetSelectionParas(editor
, ¶
, ¶_end
);
527 ME_SetParaFormat(editor
, para
, pFmt
);
528 if (para
== para_end
)
530 para
= para
->member
.para
.next_para
;
536 void ME_GetParaFormat(ME_TextEditor
*editor
, const ME_DisplayItem
*para
, PARAFORMAT2
*pFmt
)
538 if (pFmt
->cbSize
>= sizeof(PARAFORMAT2
))
540 *pFmt
= *para
->member
.para
.pFmt
;
543 CopyMemory(pFmt
, para
->member
.para
.pFmt
, pFmt
->cbSize
);
546 void ME_GetSelectionParaFormat(ME_TextEditor
*editor
, PARAFORMAT2
*pFmt
)
548 ME_DisplayItem
*para
, *para_end
;
551 ME_GetSelectionParas(editor
, ¶
, ¶_end
);
553 ME_GetParaFormat(editor
, para
, pFmt
);
554 if (para
== para_end
) return;
556 /* Invalidate values that change across the selected paragraphs. */
558 ZeroMemory(&tmp
, sizeof(tmp
));
559 tmp
.cbSize
= sizeof(tmp
);
560 ME_GetParaFormat(editor
, para
, &tmp
);
562 #define CHECK_FIELD(m, f) \
563 if (pFmt->f != tmp.f) pFmt->dwMask &= ~(m);
565 pFmt
->dwMask
&= ~((pFmt
->wEffects
^ tmp
.wEffects
) << 16);
566 CHECK_FIELD(PFM_NUMBERING
, wNumbering
);
567 assert(tmp
.dwMask
& PFM_ALIGNMENT
);
568 CHECK_FIELD(PFM_NUMBERING
, wNumbering
);
569 assert(tmp
.dwMask
& PFM_STARTINDENT
);
570 CHECK_FIELD(PFM_STARTINDENT
, dxStartIndent
);
571 assert(tmp
.dwMask
& PFM_RIGHTINDENT
);
572 CHECK_FIELD(PFM_RIGHTINDENT
, dxRightIndent
);
573 assert(tmp
.dwMask
& PFM_OFFSET
);
574 CHECK_FIELD(PFM_OFFSET
, dxOffset
);
575 CHECK_FIELD(PFM_ALIGNMENT
, wAlignment
);
577 assert(tmp
.dwMask
& PFM_TABSTOPS
);
578 if (pFmt
->dwMask
& PFM_TABSTOPS
) {
579 if (pFmt
->cTabCount
!= tmp
.cTabCount
||
580 memcmp(pFmt
->rgxTabs
, tmp
.rgxTabs
, tmp
.cTabCount
*sizeof(int)))
581 pFmt
->dwMask
&= ~PFM_TABSTOPS
;
584 CHECK_FIELD(PFM_SPACEBEFORE
, dySpaceBefore
);
585 CHECK_FIELD(PFM_SPACEAFTER
, dySpaceAfter
);
586 CHECK_FIELD(PFM_LINESPACING
, dyLineSpacing
);
587 CHECK_FIELD(PFM_STYLE
, sStyle
);
588 CHECK_FIELD(PFM_SPACEAFTER
, bLineSpacingRule
);
589 CHECK_FIELD(PFM_SHADING
, wShadingWeight
);
590 CHECK_FIELD(PFM_SHADING
, wShadingStyle
);
591 CHECK_FIELD(PFM_NUMBERINGSTART
, wNumberingStart
);
592 CHECK_FIELD(PFM_NUMBERINGSTYLE
, wNumberingStyle
);
593 CHECK_FIELD(PFM_NUMBERINGTAB
, wNumberingTab
);
594 CHECK_FIELD(PFM_BORDER
, wBorderSpace
);
595 CHECK_FIELD(PFM_BORDER
, wBorderWidth
);
596 CHECK_FIELD(PFM_BORDER
, wBorders
);
600 if (para
== para_end
)
602 para
= para
->member
.para
.next_para
;
606 void ME_SetDefaultParaFormat(PARAFORMAT2
*pFmt
)
608 ZeroMemory(pFmt
, sizeof(PARAFORMAT2
));
609 pFmt
->cbSize
= sizeof(PARAFORMAT2
);
610 pFmt
->dwMask
= PFM_ALL2
;
611 pFmt
->wAlignment
= PFA_LEFT
;
613 pFmt
->bOutlineLevel
= TRUE
;