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 ME_DisplayItem
*make_para(ME_TextEditor
*editor
)
28 ME_DisplayItem
*item
= ME_MakeDI(diParagraph
);
30 ME_SetDefaultParaFormat(editor
, &item
->member
.para
.fmt
);
31 item
->member
.para
.nFlags
= MEPF_REWRAP
;
35 void ME_MakeFirstParagraph(ME_TextEditor
*editor
)
41 ME_TextBuffer
*text
= editor
->pBuffer
;
42 ME_DisplayItem
*para
= make_para(editor
);
46 WCHAR cr_lf
[] = {'\r','\n',0};
48 ME_InitContext(&c
, editor
, ITextHost_TxGetDC(editor
->texthost
));
50 hf
= GetStockObject(SYSTEM_FONT
);
52 GetObjectW(hf
, sizeof(LOGFONTW
), &lf
);
53 ZeroMemory(&cf
, sizeof(cf
));
54 cf
.cbSize
= sizeof(cf
);
55 cf
.dwMask
= CFM_BACKCOLOR
|CFM_COLOR
|CFM_FACE
|CFM_SIZE
|CFM_CHARSET
;
56 cf
.dwMask
|= CFM_ALLCAPS
|CFM_BOLD
|CFM_DISABLED
|CFM_EMBOSS
|CFM_HIDDEN
;
57 cf
.dwMask
|= CFM_IMPRINT
|CFM_ITALIC
|CFM_LINK
|CFM_OUTLINE
|CFM_PROTECTED
;
58 cf
.dwMask
|= CFM_REVISED
|CFM_SHADOW
|CFM_SMALLCAPS
|CFM_STRIKEOUT
;
59 cf
.dwMask
|= CFM_SUBSCRIPT
|CFM_UNDERLINETYPE
|CFM_WEIGHT
;
61 cf
.dwEffects
= CFE_AUTOCOLOR
| CFE_AUTOBACKCOLOR
;
62 lstrcpyW(cf
.szFaceName
, lf
.lfFaceName
);
63 /* Convert system font height from logical units to twips for cf.yHeight */
64 cf
.yHeight
= (lf
.lfHeight
* 72 * 1440) / (c
.dpi
.cy
* c
.dpi
.cy
);
65 if (lf
.lfWeight
> FW_NORMAL
) cf
.dwEffects
|= CFE_BOLD
;
66 cf
.wWeight
= lf
.lfWeight
;
67 if (lf
.lfItalic
) cf
.dwEffects
|= CFE_ITALIC
;
68 cf
.bUnderlineType
= (lf
.lfUnderline
) ? CFU_CF1UNDERLINE
: CFU_UNDERLINENONE
;
69 if (lf
.lfStrikeOut
) cf
.dwEffects
|= CFE_STRIKEOUT
;
70 cf
.bPitchAndFamily
= lf
.lfPitchAndFamily
;
71 cf
.bCharSet
= lf
.lfCharSet
;
73 style
= ME_MakeStyle(&cf
);
74 text
->pDefaultStyle
= style
;
76 eol_len
= editor
->bEmulateVersion10
? 2 : 1;
77 para
->member
.para
.text
= ME_MakeStringN( cr_lf
, eol_len
);
79 run
= ME_MakeRun(style
, MERF_ENDPARA
);
80 run
->member
.run
.nCharOfs
= 0;
81 run
->member
.run
.len
= eol_len
;
82 run
->member
.run
.para
= ¶
->member
.para
;
84 ME_InsertBefore(text
->pLast
, para
);
85 ME_InsertBefore(text
->pLast
, run
);
86 para
->member
.para
.prev_para
= text
->pFirst
;
87 para
->member
.para
.next_para
= text
->pLast
;
88 text
->pFirst
->member
.para
.next_para
= para
;
89 text
->pLast
->member
.para
.prev_para
= para
;
91 text
->pLast
->member
.para
.nCharOfs
= editor
->bEmulateVersion10
? 2 : 1;
93 ME_DestroyContext(&c
);
96 static void ME_MarkForWrapping(ME_TextEditor
*editor
, ME_DisplayItem
*first
, const ME_DisplayItem
*last
)
100 first
->member
.para
.nFlags
|= MEPF_REWRAP
;
101 first
= first
->member
.para
.next_para
;
105 void ME_MarkAllForWrapping(ME_TextEditor
*editor
)
107 ME_MarkForWrapping(editor
, editor
->pBuffer
->pFirst
->member
.para
.next_para
, editor
->pBuffer
->pLast
);
110 static void ME_UpdateTableFlags(ME_DisplayItem
*para
)
112 para
->member
.para
.fmt
.dwMask
|= PFM_TABLE
|PFM_TABLEROWDELIMITER
;
113 if (para
->member
.para
.pCell
) {
114 para
->member
.para
.nFlags
|= MEPF_CELL
;
116 para
->member
.para
.nFlags
&= ~MEPF_CELL
;
118 if (para
->member
.para
.nFlags
& MEPF_ROWEND
) {
119 para
->member
.para
.fmt
.wEffects
|= PFE_TABLEROWDELIMITER
;
121 para
->member
.para
.fmt
.wEffects
&= ~PFE_TABLEROWDELIMITER
;
123 if (para
->member
.para
.nFlags
& (MEPF_ROWSTART
|MEPF_CELL
|MEPF_ROWEND
))
124 para
->member
.para
.fmt
.wEffects
|= PFE_TABLE
;
126 para
->member
.para
.fmt
.wEffects
&= ~PFE_TABLE
;
129 static BOOL
ME_SetParaFormat(ME_TextEditor
*editor
, ME_Paragraph
*para
, const PARAFORMAT2
*pFmt
)
134 assert(para
->fmt
.cbSize
== sizeof(PARAFORMAT2
));
135 dwMask
= pFmt
->dwMask
;
136 if (pFmt
->cbSize
< sizeof(PARAFORMAT
))
138 else if (pFmt
->cbSize
< sizeof(PARAFORMAT2
))
143 add_undo_set_para_fmt( editor
, para
);
147 #define COPY_FIELD(m, f) \
148 if (dwMask & (m)) { \
149 para->fmt.dwMask |= m; \
150 para->fmt.f = pFmt->f; \
153 COPY_FIELD(PFM_NUMBERING
, wNumbering
);
154 COPY_FIELD(PFM_STARTINDENT
, dxStartIndent
);
155 if (dwMask
& PFM_OFFSETINDENT
)
156 para
->fmt
.dxStartIndent
+= pFmt
->dxStartIndent
;
157 COPY_FIELD(PFM_RIGHTINDENT
, dxRightIndent
);
158 COPY_FIELD(PFM_OFFSET
, dxOffset
);
159 COPY_FIELD(PFM_ALIGNMENT
, wAlignment
);
160 if (dwMask
& PFM_TABSTOPS
)
162 para
->fmt
.cTabCount
= pFmt
->cTabCount
;
163 memcpy(para
->fmt
.rgxTabs
, pFmt
->rgxTabs
, pFmt
->cTabCount
*sizeof(LONG
));
166 #define EFFECTS_MASK (PFM_RTLPARA|PFM_KEEP|PFM_KEEPNEXT|PFM_PAGEBREAKBEFORE| \
167 PFM_NOLINENUMBER|PFM_NOWIDOWCONTROL|PFM_DONOTHYPHEN|PFM_SIDEBYSIDE| \
169 /* we take for granted that PFE_xxx is the hiword of the corresponding PFM_xxx */
170 if (dwMask
& EFFECTS_MASK
)
172 para
->fmt
.dwMask
|= dwMask
& EFFECTS_MASK
;
173 para
->fmt
.wEffects
&= ~HIWORD(dwMask
);
174 para
->fmt
.wEffects
|= pFmt
->wEffects
& HIWORD(dwMask
);
178 COPY_FIELD(PFM_SPACEBEFORE
, dySpaceBefore
);
179 COPY_FIELD(PFM_SPACEAFTER
, dySpaceAfter
);
180 COPY_FIELD(PFM_LINESPACING
, dyLineSpacing
);
181 COPY_FIELD(PFM_STYLE
, sStyle
);
182 COPY_FIELD(PFM_LINESPACING
, bLineSpacingRule
);
183 COPY_FIELD(PFM_SHADING
, wShadingWeight
);
184 COPY_FIELD(PFM_SHADING
, wShadingStyle
);
185 COPY_FIELD(PFM_NUMBERINGSTART
, wNumberingStart
);
186 COPY_FIELD(PFM_NUMBERINGSTYLE
, wNumberingStyle
);
187 COPY_FIELD(PFM_NUMBERINGTAB
, wNumberingTab
);
188 COPY_FIELD(PFM_BORDER
, wBorderSpace
);
189 COPY_FIELD(PFM_BORDER
, wBorderWidth
);
190 COPY_FIELD(PFM_BORDER
, wBorders
);
192 para
->fmt
.dwMask
|= dwMask
;
195 if (memcmp(©
, ¶
->fmt
, sizeof(PARAFORMAT2
)))
196 para
->nFlags
|= MEPF_REWRAP
;
201 /* split paragraph at the beginning of the run */
202 ME_DisplayItem
*ME_SplitParagraph(ME_TextEditor
*editor
, ME_DisplayItem
*run
,
203 ME_Style
*style
, const WCHAR
*eol_str
, int eol_len
,
206 ME_DisplayItem
*next_para
= NULL
;
207 ME_DisplayItem
*run_para
= NULL
;
208 ME_DisplayItem
*new_para
= make_para(editor
);
209 ME_DisplayItem
*end_run
;
212 int run_flags
= MERF_ENDPARA
;
214 if (!editor
->bEmulateVersion10
) { /* v4.1 */
215 /* At most 1 of MEPF_CELL, MEPF_ROWSTART, or MEPF_ROWEND should be set. */
216 assert(!(paraFlags
& ~(MEPF_CELL
|MEPF_ROWSTART
|MEPF_ROWEND
)));
217 assert(!(paraFlags
& (paraFlags
-1)));
218 if (paraFlags
== MEPF_CELL
)
219 run_flags
|= MERF_ENDCELL
;
220 else if (paraFlags
== MEPF_ROWSTART
)
221 run_flags
|= MERF_TABLESTART
|MERF_HIDDEN
;
222 } else { /* v1.0 - v3.0 */
223 assert(!(paraFlags
& (MEPF_CELL
|MEPF_ROWSTART
|MEPF_ROWEND
)));
225 assert(run
->type
== diRun
);
226 run_para
= ME_GetParagraph(run
);
227 assert(run_para
->member
.para
.fmt
.cbSize
== sizeof(PARAFORMAT2
));
229 new_para
->member
.para
.text
= ME_VSplitString( run_para
->member
.para
.text
, run
->member
.run
.nCharOfs
);
231 end_run
= ME_MakeRun(style
, run_flags
);
232 ofs
= end_run
->member
.run
.nCharOfs
= run
->member
.run
.nCharOfs
;
233 end_run
->member
.run
.len
= eol_len
;
234 end_run
->member
.run
.para
= run
->member
.run
.para
;
235 ME_AppendString( run_para
->member
.para
.text
, eol_str
, eol_len
);
236 next_para
= run_para
->member
.para
.next_para
;
237 assert(next_para
== ME_FindItemFwd(run_para
, diParagraphOrEnd
));
239 add_undo_join_paras( editor
, run_para
->member
.para
.nCharOfs
+ ofs
);
241 /* Update selection cursors to point to the correct paragraph. */
242 for (i
= 0; i
< editor
->nCursors
; i
++) {
243 if (editor
->pCursors
[i
].pPara
== run_para
&&
244 run
->member
.run
.nCharOfs
<= editor
->pCursors
[i
].pRun
->member
.run
.nCharOfs
)
246 editor
->pCursors
[i
].pPara
= new_para
;
250 /* the new paragraph will have a different starting offset, so let's update its runs */
252 while(pp
->type
== diRun
) {
253 pp
->member
.run
.nCharOfs
-= ofs
;
254 pp
->member
.run
.para
= &new_para
->member
.para
;
255 pp
= ME_FindItemFwd(pp
, diRunOrParagraphOrEnd
);
257 new_para
->member
.para
.nCharOfs
= run_para
->member
.para
.nCharOfs
+ ofs
;
258 new_para
->member
.para
.nCharOfs
+= eol_len
;
259 new_para
->member
.para
.nFlags
= MEPF_REWRAP
;
261 /* FIXME initialize format style and call ME_SetParaFormat blah blah */
262 new_para
->member
.para
.fmt
= run_para
->member
.para
.fmt
;
263 new_para
->member
.para
.border
= run_para
->member
.para
.border
;
265 /* insert paragraph into paragraph double linked list */
266 new_para
->member
.para
.prev_para
= run_para
;
267 new_para
->member
.para
.next_para
= next_para
;
268 run_para
->member
.para
.next_para
= new_para
;
269 next_para
->member
.para
.prev_para
= new_para
;
271 /* insert end run of the old paragraph, and new paragraph, into DI double linked list */
272 ME_InsertBefore(run
, new_para
);
273 ME_InsertBefore(new_para
, end_run
);
275 if (!editor
->bEmulateVersion10
) { /* v4.1 */
276 if (paraFlags
& (MEPF_ROWSTART
|MEPF_CELL
))
278 ME_DisplayItem
*cell
= ME_MakeDI(diCell
);
279 ME_InsertBefore(new_para
, cell
);
280 new_para
->member
.para
.pCell
= cell
;
281 cell
->member
.cell
.next_cell
= NULL
;
282 if (paraFlags
& MEPF_ROWSTART
)
284 run_para
->member
.para
.nFlags
|= MEPF_ROWSTART
;
285 cell
->member
.cell
.prev_cell
= NULL
;
286 cell
->member
.cell
.parent_cell
= run_para
->member
.para
.pCell
;
287 if (run_para
->member
.para
.pCell
)
288 cell
->member
.cell
.nNestingLevel
= run_para
->member
.para
.pCell
->member
.cell
.nNestingLevel
+ 1;
290 cell
->member
.cell
.nNestingLevel
= 1;
292 cell
->member
.cell
.prev_cell
= run_para
->member
.para
.pCell
;
293 assert(cell
->member
.cell
.prev_cell
);
294 cell
->member
.cell
.prev_cell
->member
.cell
.next_cell
= cell
;
295 assert(run_para
->member
.para
.nFlags
& MEPF_CELL
);
296 assert(!(run_para
->member
.para
.nFlags
& MEPF_ROWSTART
));
297 cell
->member
.cell
.nNestingLevel
= cell
->member
.cell
.prev_cell
->member
.cell
.nNestingLevel
;
298 cell
->member
.cell
.parent_cell
= cell
->member
.cell
.prev_cell
->member
.cell
.parent_cell
;
300 } else if (paraFlags
& MEPF_ROWEND
) {
301 run_para
->member
.para
.nFlags
|= MEPF_ROWEND
;
302 run_para
->member
.para
.pCell
= run_para
->member
.para
.pCell
->member
.cell
.parent_cell
;
303 new_para
->member
.para
.pCell
= run_para
->member
.para
.pCell
;
304 assert(run_para
->member
.para
.prev_para
->member
.para
.nFlags
& MEPF_CELL
);
305 assert(!(run_para
->member
.para
.prev_para
->member
.para
.nFlags
& MEPF_ROWSTART
));
306 if (new_para
->member
.para
.pCell
!= new_para
->member
.para
.next_para
->member
.para
.pCell
307 && new_para
->member
.para
.next_para
->member
.para
.pCell
308 && !new_para
->member
.para
.next_para
->member
.para
.pCell
->member
.cell
.prev_cell
)
310 /* Row starts just after the row that was ended. */
311 new_para
->member
.para
.nFlags
|= MEPF_ROWSTART
;
314 new_para
->member
.para
.pCell
= run_para
->member
.para
.pCell
;
316 ME_UpdateTableFlags(run_para
);
317 ME_UpdateTableFlags(new_para
);
320 /* force rewrap of the */
321 run_para
->member
.para
.prev_para
->member
.para
.nFlags
|= MEPF_REWRAP
;
322 new_para
->member
.para
.prev_para
->member
.para
.nFlags
|= MEPF_REWRAP
;
324 /* we've added the end run, so we need to modify nCharOfs in the next paragraphs */
325 ME_PropagateCharOffset(next_para
, eol_len
);
326 editor
->nParagraphs
++;
331 /* join tp with tp->member.para.next_para, keeping tp's style; this
332 * is consistent with the original */
333 ME_DisplayItem
*ME_JoinParagraphs(ME_TextEditor
*editor
, ME_DisplayItem
*tp
,
334 BOOL keepFirstParaFormat
)
336 ME_DisplayItem
*pNext
, *pFirstRunInNext
, *pRun
, *pTmp
, *pCell
= NULL
;
340 ME_Cursor startCur
, endCur
;
343 assert(tp
->type
== diParagraph
);
344 assert(tp
->member
.para
.next_para
);
345 assert(tp
->member
.para
.next_para
->type
== diParagraph
);
347 pNext
= tp
->member
.para
.next_para
;
349 /* Need to locate end-of-paragraph run here, in order to know end_len */
350 pRun
= ME_FindItemBack(pNext
, diRunOrParagraph
);
353 assert(pRun
->type
== diRun
);
354 assert(pRun
->member
.run
.nFlags
& MERF_ENDPARA
);
356 end_len
= pRun
->member
.run
.len
;
357 eol_str
= ME_VSplitString( tp
->member
.para
.text
, pRun
->member
.run
.nCharOfs
);
358 ME_AppendString( tp
->member
.para
.text
, pNext
->member
.para
.text
->szData
, pNext
->member
.para
.text
->nLen
);
360 /* null char format operation to store the original char format for the ENDPARA run */
361 ME_InitCharFormat2W(&fmt
);
362 endCur
.pPara
= pNext
;
363 endCur
.pRun
= ME_FindItemFwd(pNext
, diRun
);
366 ME_PrevRun(&startCur
.pPara
, &startCur
.pRun
, TRUE
);
367 ME_SetCharFormat(editor
, &startCur
, &endCur
, &fmt
);
369 if (!editor
->bEmulateVersion10
) { /* v4.1 */
370 /* Table cell/row properties are always moved over from the removed para. */
371 tp
->member
.para
.nFlags
= pNext
->member
.para
.nFlags
;
372 tp
->member
.para
.pCell
= pNext
->member
.para
.pCell
;
374 /* Remove cell boundary if it is between the end paragraph run and the next
375 * paragraph display item. */
376 for (pTmp
= pRun
->next
; pTmp
!= pNext
; pTmp
= pTmp
->next
)
378 if (pTmp
->type
== diCell
)
386 add_undo_split_para( editor
, &pNext
->member
.para
, eol_str
, pCell
? &pCell
->member
.cell
: NULL
);
391 if (pCell
->member
.cell
.prev_cell
)
392 pCell
->member
.cell
.prev_cell
->member
.cell
.next_cell
= pCell
->member
.cell
.next_cell
;
393 if (pCell
->member
.cell
.next_cell
)
394 pCell
->member
.cell
.next_cell
->member
.cell
.prev_cell
= pCell
->member
.cell
.prev_cell
;
395 ME_DestroyDisplayItem( pCell
);
398 if (!keepFirstParaFormat
)
400 add_undo_set_para_fmt( editor
, &tp
->member
.para
);
401 tp
->member
.para
.fmt
= pNext
->member
.para
.fmt
;
402 tp
->member
.para
.border
= pNext
->member
.para
.border
;
405 shift
= pNext
->member
.para
.nCharOfs
- tp
->member
.para
.nCharOfs
- end_len
;
407 pFirstRunInNext
= ME_FindItemFwd(pNext
, diRunOrParagraph
);
409 assert(pFirstRunInNext
->type
== diRun
);
411 /* Update selection cursors so they don't point to the removed end
412 * paragraph run, and point to the correct paragraph. */
413 for (i
=0; i
< editor
->nCursors
; i
++) {
414 if (editor
->pCursors
[i
].pRun
== pRun
) {
415 editor
->pCursors
[i
].pRun
= pFirstRunInNext
;
416 editor
->pCursors
[i
].nOffset
= 0;
417 } else if (editor
->pCursors
[i
].pPara
== pNext
) {
418 editor
->pCursors
[i
].pPara
= tp
;
424 pTmp
= ME_FindItemFwd(pTmp
, diRunOrParagraphOrEnd
);
425 if (pTmp
->type
!= diRun
)
427 TRACE("shifting %s by %d (previous %d)\n", debugstr_run( &pTmp
->member
.run
), shift
, pTmp
->member
.run
.nCharOfs
);
428 pTmp
->member
.run
.nCharOfs
+= shift
;
429 pTmp
->member
.run
.para
= &tp
->member
.para
;
433 ME_DestroyDisplayItem(pRun
);
435 if (editor
->pLastSelStartPara
== pNext
)
436 editor
->pLastSelStartPara
= tp
;
437 if (editor
->pLastSelEndPara
== pNext
)
438 editor
->pLastSelEndPara
= tp
;
440 tp
->member
.para
.next_para
= pNext
->member
.para
.next_para
;
441 pNext
->member
.para
.next_para
->member
.para
.prev_para
= tp
;
443 ME_DestroyDisplayItem(pNext
);
445 ME_PropagateCharOffset(tp
->member
.para
.next_para
, -end_len
);
447 ME_CheckCharOffsets(editor
);
449 editor
->nParagraphs
--;
450 tp
->member
.para
.nFlags
|= MEPF_REWRAP
;
454 ME_DisplayItem
*ME_GetParagraph(ME_DisplayItem
*item
) {
455 return ME_FindItemBackOrHere(item
, diParagraph
);
458 void ME_DumpParaStyleToBuf(const PARAFORMAT2
*pFmt
, char buf
[2048])
463 #define DUMP(mask, name, fmt, field) \
464 if (pFmt->dwMask & (mask)) p += sprintf(p, "%-22s" fmt "\n", name, pFmt->field); \
465 else p += sprintf(p, "%-22sN/A\n", name);
467 /* we take for granted that PFE_xxx is the hiword of the corresponding PFM_xxx */
468 #define DUMP_EFFECT(mask, name) \
469 p += sprintf(p, "%-22s%s\n", name, (pFmt->dwMask & (mask)) ? ((pFmt->wEffects & ((mask) >> 16)) ? "yes" : "no") : "N/A");
471 DUMP(PFM_NUMBERING
, "Numbering:", "%u", wNumbering
);
472 DUMP_EFFECT(PFM_DONOTHYPHEN
, "Disable auto-hyphen:");
473 DUMP_EFFECT(PFM_KEEP
, "No page break in para:");
474 DUMP_EFFECT(PFM_KEEPNEXT
, "No page break in para & next:");
475 DUMP_EFFECT(PFM_NOLINENUMBER
, "No line number:");
476 DUMP_EFFECT(PFM_NOWIDOWCONTROL
, "No widow & orphan:");
477 DUMP_EFFECT(PFM_PAGEBREAKBEFORE
, "Page break before:");
478 DUMP_EFFECT(PFM_RTLPARA
, "RTL para:");
479 DUMP_EFFECT(PFM_SIDEBYSIDE
, "Side by side:");
480 DUMP_EFFECT(PFM_TABLE
, "Table:");
481 DUMP(PFM_OFFSETINDENT
, "Offset indent:", "%d", dxStartIndent
);
482 DUMP(PFM_STARTINDENT
, "Start indent:", "%d", dxStartIndent
);
483 DUMP(PFM_RIGHTINDENT
, "Right indent:", "%d", dxRightIndent
);
484 DUMP(PFM_OFFSET
, "Offset:", "%d", dxOffset
);
485 if (pFmt
->dwMask
& PFM_ALIGNMENT
) {
486 switch (pFmt
->wAlignment
) {
487 case PFA_LEFT
: p
+= sprintf(p
, "Alignment: left\n"); break;
488 case PFA_RIGHT
: p
+= sprintf(p
, "Alignment: right\n"); break;
489 case PFA_CENTER
: p
+= sprintf(p
, "Alignment: center\n"); break;
490 case PFA_JUSTIFY
: p
+= sprintf(p
, "Alignment: justify\n"); break;
491 default : p
+= sprintf(p
, "Alignment: incorrect %d\n", pFmt
->wAlignment
); break;
494 else p
+= sprintf(p
, "Alignment: N/A\n");
495 DUMP(PFM_TABSTOPS
, "Tab Stops:", "%d", cTabCount
);
496 if (pFmt
->dwMask
& PFM_TABSTOPS
) {
498 p
+= sprintf(p
, "\t");
499 for (i
= 0; i
< pFmt
->cTabCount
; i
++) p
+= sprintf(p
, "%x ", pFmt
->rgxTabs
[i
]);
500 p
+= sprintf(p
, "\n");
502 DUMP(PFM_SPACEBEFORE
, "Space Before:", "%d", dySpaceBefore
);
503 DUMP(PFM_SPACEAFTER
, "Space After:", "%d", dySpaceAfter
);
504 DUMP(PFM_LINESPACING
, "Line spacing:", "%d", dyLineSpacing
);
505 DUMP(PFM_STYLE
, "Text style:", "%d", sStyle
);
506 DUMP(PFM_LINESPACING
, "Line spacing rule:", "%u", bLineSpacingRule
);
507 /* bOutlineLevel should be 0 */
508 DUMP(PFM_SHADING
, "Shading Weight:", "%u", wShadingWeight
);
509 DUMP(PFM_SHADING
, "Shading Style:", "%u", wShadingStyle
);
510 DUMP(PFM_NUMBERINGSTART
, "Numbering Start:", "%u", wNumberingStart
);
511 DUMP(PFM_NUMBERINGSTYLE
, "Numbering Style:", "0x%x", wNumberingStyle
);
512 DUMP(PFM_NUMBERINGTAB
, "Numbering Tab:", "%u", wNumberingStyle
);
513 DUMP(PFM_BORDER
, "Border Space:", "%u", wBorderSpace
);
514 DUMP(PFM_BORDER
, "Border Width:", "%u", wBorderWidth
);
515 DUMP(PFM_BORDER
, "Borders:", "%u", wBorders
);
522 ME_GetSelectionParas(ME_TextEditor
*editor
, ME_DisplayItem
**para
, ME_DisplayItem
**para_end
)
524 ME_Cursor
*pEndCursor
= &editor
->pCursors
[1];
526 *para
= editor
->pCursors
[0].pPara
;
527 *para_end
= editor
->pCursors
[1].pPara
;
528 if (*para
== *para_end
)
531 if ((*para_end
)->member
.para
.nCharOfs
< (*para
)->member
.para
.nCharOfs
) {
532 ME_DisplayItem
*tmp
= *para
;
536 pEndCursor
= &editor
->pCursors
[0];
539 /* The paragraph at the end of a non-empty selection isn't included
540 * if the selection ends at the start of the paragraph. */
541 if (!pEndCursor
->pRun
->member
.run
.nCharOfs
&& !pEndCursor
->nOffset
)
542 *para_end
= (*para_end
)->member
.para
.prev_para
;
546 BOOL
ME_SetSelectionParaFormat(ME_TextEditor
*editor
, const PARAFORMAT2
*pFmt
)
548 ME_DisplayItem
*para
, *para_end
;
550 ME_GetSelectionParas(editor
, ¶
, ¶_end
);
553 ME_SetParaFormat(editor
, ¶
->member
.para
, pFmt
);
554 if (para
== para_end
)
556 para
= para
->member
.para
.next_para
;
562 static void ME_GetParaFormat(ME_TextEditor
*editor
,
563 const ME_DisplayItem
*para
,
566 UINT cbSize
= pFmt
->cbSize
;
567 if (pFmt
->cbSize
>= sizeof(PARAFORMAT2
)) {
568 *pFmt
= para
->member
.para
.fmt
;
570 CopyMemory(pFmt
, ¶
->member
.para
.fmt
, pFmt
->cbSize
);
571 pFmt
->dwMask
&= PFM_ALL
;
573 pFmt
->cbSize
= cbSize
;
576 void ME_GetSelectionParaFormat(ME_TextEditor
*editor
, PARAFORMAT2
*pFmt
)
578 ME_DisplayItem
*para
, *para_end
;
581 if (pFmt
->cbSize
< sizeof(PARAFORMAT
)) {
586 ME_GetSelectionParas(editor
, ¶
, ¶_end
);
588 ME_GetParaFormat(editor
, para
, pFmt
);
590 /* Invalidate values that change across the selected paragraphs. */
591 while (para
!= para_end
)
593 para
= para
->member
.para
.next_para
;
594 curFmt
= ¶
->member
.para
.fmt
;
596 #define CHECK_FIELD(m, f) \
597 if (pFmt->f != curFmt->f) pFmt->dwMask &= ~(m);
599 CHECK_FIELD(PFM_NUMBERING
, wNumbering
);
600 CHECK_FIELD(PFM_STARTINDENT
, dxStartIndent
);
601 CHECK_FIELD(PFM_RIGHTINDENT
, dxRightIndent
);
602 CHECK_FIELD(PFM_OFFSET
, dxOffset
);
603 CHECK_FIELD(PFM_ALIGNMENT
, wAlignment
);
604 if (pFmt
->dwMask
& PFM_TABSTOPS
) {
605 if (pFmt
->cTabCount
!= para
->member
.para
.fmt
.cTabCount
||
606 memcmp(pFmt
->rgxTabs
, curFmt
->rgxTabs
, curFmt
->cTabCount
*sizeof(int)))
607 pFmt
->dwMask
&= ~PFM_TABSTOPS
;
610 if (pFmt
->dwMask
>= sizeof(PARAFORMAT2
))
612 pFmt
->dwMask
&= ~((pFmt
->wEffects
^ curFmt
->wEffects
) << 16);
613 CHECK_FIELD(PFM_SPACEBEFORE
, dySpaceBefore
);
614 CHECK_FIELD(PFM_SPACEAFTER
, dySpaceAfter
);
615 CHECK_FIELD(PFM_LINESPACING
, dyLineSpacing
);
616 CHECK_FIELD(PFM_STYLE
, sStyle
);
617 CHECK_FIELD(PFM_SPACEAFTER
, bLineSpacingRule
);
618 CHECK_FIELD(PFM_SHADING
, wShadingWeight
);
619 CHECK_FIELD(PFM_SHADING
, wShadingStyle
);
620 CHECK_FIELD(PFM_NUMBERINGSTART
, wNumberingStart
);
621 CHECK_FIELD(PFM_NUMBERINGSTYLE
, wNumberingStyle
);
622 CHECK_FIELD(PFM_NUMBERINGTAB
, wNumberingTab
);
623 CHECK_FIELD(PFM_BORDER
, wBorderSpace
);
624 CHECK_FIELD(PFM_BORDER
, wBorderWidth
);
625 CHECK_FIELD(PFM_BORDER
, wBorders
);
631 void ME_SetDefaultParaFormat(ME_TextEditor
*editor
, PARAFORMAT2
*pFmt
)
633 ZeroMemory(pFmt
, sizeof(PARAFORMAT2
));
634 pFmt
->cbSize
= sizeof(PARAFORMAT2
);
635 pFmt
->dwMask
= PFM_ALL2
;
636 pFmt
->wAlignment
= editor
->alignStyle
;
638 pFmt
->bOutlineLevel
= TRUE
;