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 #define EFFECTS_MASK (PFM_RTLPARA|PFM_KEEP|PFM_KEEPNEXT|PFM_PAGEBREAKBEFORE| \
158 PFM_NOLINENUMBER|PFM_NOWIDOWCONTROL|PFM_DONOTHYPHEN|PFM_SIDEBYSIDE| \
160 /* we take for granted that PFE_xxx is the hiword of the corresponding PFM_xxx */
161 if (dwMask
& EFFECTS_MASK
)
163 para
->member
.para
.pFmt
->dwMask
|= dwMask
& EFFECTS_MASK
;
164 para
->member
.para
.pFmt
->wEffects
&= ~HIWORD(dwMask
);
165 para
->member
.para
.pFmt
->wEffects
|= pFmt
->wEffects
& HIWORD(dwMask
);
169 COPY_FIELD(PFM_SPACEBEFORE
, dySpaceBefore
);
170 COPY_FIELD(PFM_SPACEAFTER
, dySpaceAfter
);
171 COPY_FIELD(PFM_LINESPACING
, dyLineSpacing
);
172 COPY_FIELD(PFM_STYLE
, sStyle
);
173 COPY_FIELD(PFM_LINESPACING
, bLineSpacingRule
);
174 COPY_FIELD(PFM_SHADING
, wShadingWeight
);
175 COPY_FIELD(PFM_SHADING
, wShadingStyle
);
176 COPY_FIELD(PFM_NUMBERINGSTART
, wNumberingStart
);
177 COPY_FIELD(PFM_NUMBERINGSTYLE
, wNumberingStyle
);
178 COPY_FIELD(PFM_NUMBERINGTAB
, wNumberingTab
);
179 COPY_FIELD(PFM_BORDER
, wBorderSpace
);
180 COPY_FIELD(PFM_BORDER
, wBorderWidth
);
181 COPY_FIELD(PFM_BORDER
, wBorders
);
183 para
->member
.para
.pFmt
->dwMask
|= dwMask
;
186 if (memcmp(©
, para
->member
.para
.pFmt
, sizeof(PARAFORMAT2
)))
187 para
->member
.para
.nFlags
|= MEPF_REWRAP
;
192 /* split paragraph at the beginning of the run */
193 ME_DisplayItem
*ME_SplitParagraph(ME_TextEditor
*editor
, ME_DisplayItem
*run
,
194 ME_Style
*style
, const WCHAR
*eol_str
, int eol_len
,
197 ME_DisplayItem
*next_para
= NULL
;
198 ME_DisplayItem
*run_para
= NULL
;
199 ME_DisplayItem
*new_para
= ME_MakeDI(diParagraph
);
200 ME_DisplayItem
*end_run
;
203 int run_flags
= MERF_ENDPARA
;
205 if (!editor
->bEmulateVersion10
) { /* v4.1 */
206 /* At most 1 of MEPF_CELL, MEPF_ROWSTART, or MEPF_ROWEND should be set. */
207 assert(!(paraFlags
& ~(MEPF_CELL
|MEPF_ROWSTART
|MEPF_ROWEND
)));
208 assert(!(paraFlags
& (paraFlags
-1)));
209 if (paraFlags
== MEPF_CELL
)
210 run_flags
|= MERF_ENDCELL
;
211 else if (paraFlags
== MEPF_ROWSTART
)
212 run_flags
|= MERF_TABLESTART
|MERF_HIDDEN
;
213 } else { /* v1.0 - v3.0 */
214 assert(!(paraFlags
& (MEPF_CELL
|MEPF_ROWSTART
|MEPF_ROWEND
)));
216 assert(run
->type
== diRun
);
217 run_para
= ME_GetParagraph(run
);
218 assert(run_para
->member
.para
.pFmt
->cbSize
== sizeof(PARAFORMAT2
));
220 new_para
->member
.para
.text
= ME_VSplitString( run_para
->member
.para
.text
, run
->member
.run
.nCharOfs
);
222 end_run
= ME_MakeRun(style
, run_flags
);
223 ofs
= end_run
->member
.run
.nCharOfs
= run
->member
.run
.nCharOfs
;
224 end_run
->member
.run
.len
= eol_len
;
225 end_run
->member
.run
.para
= run
->member
.run
.para
;
226 ME_AppendString( run_para
->member
.para
.text
, eol_str
, eol_len
);
227 next_para
= run_para
->member
.para
.next_para
;
228 assert(next_para
== ME_FindItemFwd(run_para
, diParagraphOrEnd
));
230 add_undo_join_paras( editor
, run_para
->member
.para
.nCharOfs
+ ofs
);
232 /* Update selection cursors to point to the correct paragraph. */
233 for (i
= 0; i
< editor
->nCursors
; i
++) {
234 if (editor
->pCursors
[i
].pPara
== run_para
&&
235 run
->member
.run
.nCharOfs
<= editor
->pCursors
[i
].pRun
->member
.run
.nCharOfs
)
237 editor
->pCursors
[i
].pPara
= new_para
;
241 /* the new paragraph will have a different starting offset, so let's update its runs */
243 while(pp
->type
== diRun
) {
244 pp
->member
.run
.nCharOfs
-= ofs
;
245 pp
->member
.run
.para
= &new_para
->member
.para
;
246 pp
= ME_FindItemFwd(pp
, diRunOrParagraphOrEnd
);
248 new_para
->member
.para
.nCharOfs
= run_para
->member
.para
.nCharOfs
+ ofs
;
249 new_para
->member
.para
.nCharOfs
+= eol_len
;
250 new_para
->member
.para
.nFlags
= MEPF_REWRAP
;
252 /* FIXME initialize format style and call ME_SetParaFormat blah blah */
253 *new_para
->member
.para
.pFmt
= *run_para
->member
.para
.pFmt
;
254 new_para
->member
.para
.border
= run_para
->member
.para
.border
;
256 /* insert paragraph into paragraph double linked list */
257 new_para
->member
.para
.prev_para
= run_para
;
258 new_para
->member
.para
.next_para
= next_para
;
259 run_para
->member
.para
.next_para
= new_para
;
260 next_para
->member
.para
.prev_para
= new_para
;
262 /* insert end run of the old paragraph, and new paragraph, into DI double linked list */
263 ME_InsertBefore(run
, new_para
);
264 ME_InsertBefore(new_para
, end_run
);
266 if (!editor
->bEmulateVersion10
) { /* v4.1 */
267 if (paraFlags
& (MEPF_ROWSTART
|MEPF_CELL
))
269 ME_DisplayItem
*cell
= ME_MakeDI(diCell
);
270 ME_InsertBefore(new_para
, cell
);
271 new_para
->member
.para
.pCell
= cell
;
272 cell
->member
.cell
.next_cell
= NULL
;
273 if (paraFlags
& MEPF_ROWSTART
)
275 run_para
->member
.para
.nFlags
|= MEPF_ROWSTART
;
276 cell
->member
.cell
.prev_cell
= NULL
;
277 cell
->member
.cell
.parent_cell
= run_para
->member
.para
.pCell
;
278 if (run_para
->member
.para
.pCell
)
279 cell
->member
.cell
.nNestingLevel
= run_para
->member
.para
.pCell
->member
.cell
.nNestingLevel
+ 1;
281 cell
->member
.cell
.nNestingLevel
= 1;
283 cell
->member
.cell
.prev_cell
= run_para
->member
.para
.pCell
;
284 assert(cell
->member
.cell
.prev_cell
);
285 cell
->member
.cell
.prev_cell
->member
.cell
.next_cell
= cell
;
286 assert(run_para
->member
.para
.nFlags
& MEPF_CELL
);
287 assert(!(run_para
->member
.para
.nFlags
& MEPF_ROWSTART
));
288 cell
->member
.cell
.nNestingLevel
= cell
->member
.cell
.prev_cell
->member
.cell
.nNestingLevel
;
289 cell
->member
.cell
.parent_cell
= cell
->member
.cell
.prev_cell
->member
.cell
.parent_cell
;
291 } else if (paraFlags
& MEPF_ROWEND
) {
292 run_para
->member
.para
.nFlags
|= MEPF_ROWEND
;
293 run_para
->member
.para
.pCell
= run_para
->member
.para
.pCell
->member
.cell
.parent_cell
;
294 new_para
->member
.para
.pCell
= run_para
->member
.para
.pCell
;
295 assert(run_para
->member
.para
.prev_para
->member
.para
.nFlags
& MEPF_CELL
);
296 assert(!(run_para
->member
.para
.prev_para
->member
.para
.nFlags
& MEPF_ROWSTART
));
297 if (new_para
->member
.para
.pCell
!= new_para
->member
.para
.next_para
->member
.para
.pCell
298 && new_para
->member
.para
.next_para
->member
.para
.pCell
299 && !new_para
->member
.para
.next_para
->member
.para
.pCell
->member
.cell
.prev_cell
)
301 /* Row starts just after the row that was ended. */
302 new_para
->member
.para
.nFlags
|= MEPF_ROWSTART
;
305 new_para
->member
.para
.pCell
= run_para
->member
.para
.pCell
;
307 ME_UpdateTableFlags(run_para
);
308 ME_UpdateTableFlags(new_para
);
311 /* force rewrap of the */
312 run_para
->member
.para
.prev_para
->member
.para
.nFlags
|= MEPF_REWRAP
;
313 new_para
->member
.para
.prev_para
->member
.para
.nFlags
|= MEPF_REWRAP
;
315 /* we've added the end run, so we need to modify nCharOfs in the next paragraphs */
316 ME_PropagateCharOffset(next_para
, eol_len
);
317 editor
->nParagraphs
++;
322 /* join tp with tp->member.para.next_para, keeping tp's style; this
323 * is consistent with the original */
324 ME_DisplayItem
*ME_JoinParagraphs(ME_TextEditor
*editor
, ME_DisplayItem
*tp
,
325 BOOL keepFirstParaFormat
)
327 ME_DisplayItem
*pNext
, *pFirstRunInNext
, *pRun
, *pTmp
, *pCell
= NULL
;
331 ME_Cursor startCur
, endCur
;
334 assert(tp
->type
== diParagraph
);
335 assert(tp
->member
.para
.next_para
);
336 assert(tp
->member
.para
.next_para
->type
== diParagraph
);
338 pNext
= tp
->member
.para
.next_para
;
340 /* Need to locate end-of-paragraph run here, in order to know end_len */
341 pRun
= ME_FindItemBack(pNext
, diRunOrParagraph
);
344 assert(pRun
->type
== diRun
);
345 assert(pRun
->member
.run
.nFlags
& MERF_ENDPARA
);
347 end_len
= pRun
->member
.run
.len
;
348 eol_str
= ME_VSplitString( tp
->member
.para
.text
, pRun
->member
.run
.nCharOfs
);
349 ME_AppendString( tp
->member
.para
.text
, pNext
->member
.para
.text
->szData
, pNext
->member
.para
.text
->nLen
);
351 /* null char format operation to store the original char format for the ENDPARA run */
352 ME_InitCharFormat2W(&fmt
);
353 endCur
.pPara
= pNext
;
354 endCur
.pRun
= ME_FindItemFwd(pNext
, diRun
);
357 ME_PrevRun(&startCur
.pPara
, &startCur
.pRun
);
358 ME_SetCharFormat(editor
, &startCur
, &endCur
, &fmt
);
360 if (!editor
->bEmulateVersion10
) { /* v4.1 */
361 /* Table cell/row properties are always moved over from the removed para. */
362 tp
->member
.para
.nFlags
= pNext
->member
.para
.nFlags
;
363 tp
->member
.para
.pCell
= pNext
->member
.para
.pCell
;
365 /* Remove cell boundary if it is between the end paragraph run and the next
366 * paragraph display item. */
367 for (pTmp
= pRun
->next
; pTmp
!= pNext
; pTmp
= pTmp
->next
)
369 if (pTmp
->type
== diCell
)
377 add_undo_split_para( editor
, &pNext
->member
.para
, eol_str
, pCell
? &pCell
->member
.cell
: NULL
);
382 if (pCell
->member
.cell
.prev_cell
)
383 pCell
->member
.cell
.prev_cell
->member
.cell
.next_cell
= pCell
->member
.cell
.next_cell
;
384 if (pCell
->member
.cell
.next_cell
)
385 pCell
->member
.cell
.next_cell
->member
.cell
.prev_cell
= pCell
->member
.cell
.prev_cell
;
386 ME_DestroyDisplayItem( pCell
);
389 if (!keepFirstParaFormat
)
391 add_undo_set_para_fmt( editor
, &tp
->member
.para
);
392 *tp
->member
.para
.pFmt
= *pNext
->member
.para
.pFmt
;
393 tp
->member
.para
.border
= pNext
->member
.para
.border
;
396 shift
= pNext
->member
.para
.nCharOfs
- tp
->member
.para
.nCharOfs
- end_len
;
398 pFirstRunInNext
= ME_FindItemFwd(pNext
, diRunOrParagraph
);
400 assert(pFirstRunInNext
->type
== diRun
);
402 /* Update selection cursors so they don't point to the removed end
403 * paragraph run, and point to the correct paragraph. */
404 for (i
=0; i
< editor
->nCursors
; i
++) {
405 if (editor
->pCursors
[i
].pRun
== pRun
) {
406 editor
->pCursors
[i
].pRun
= pFirstRunInNext
;
407 editor
->pCursors
[i
].nOffset
= 0;
408 } else if (editor
->pCursors
[i
].pPara
== pNext
) {
409 editor
->pCursors
[i
].pPara
= tp
;
415 pTmp
= ME_FindItemFwd(pTmp
, diRunOrParagraphOrEnd
);
416 if (pTmp
->type
!= diRun
)
418 TRACE("shifting %s by %d (previous %d)\n", debugstr_run( &pTmp
->member
.run
), shift
, pTmp
->member
.run
.nCharOfs
);
419 pTmp
->member
.run
.nCharOfs
+= shift
;
420 pTmp
->member
.run
.para
= &tp
->member
.para
;
424 ME_DestroyDisplayItem(pRun
);
426 if (editor
->pLastSelStartPara
== pNext
)
427 editor
->pLastSelStartPara
= tp
;
428 if (editor
->pLastSelEndPara
== pNext
)
429 editor
->pLastSelEndPara
= tp
;
431 tp
->member
.para
.next_para
= pNext
->member
.para
.next_para
;
432 pNext
->member
.para
.next_para
->member
.para
.prev_para
= tp
;
434 ME_DestroyDisplayItem(pNext
);
436 ME_PropagateCharOffset(tp
->member
.para
.next_para
, -end_len
);
438 ME_CheckCharOffsets(editor
);
440 editor
->nParagraphs
--;
441 tp
->member
.para
.nFlags
|= MEPF_REWRAP
;
445 ME_DisplayItem
*ME_GetParagraph(ME_DisplayItem
*item
) {
446 return ME_FindItemBackOrHere(item
, diParagraph
);
449 void ME_DumpParaStyleToBuf(const PARAFORMAT2
*pFmt
, char buf
[2048])
454 #define DUMP(mask, name, fmt, field) \
455 if (pFmt->dwMask & (mask)) p += sprintf(p, "%-22s" fmt "\n", name, pFmt->field); \
456 else p += sprintf(p, "%-22sN/A\n", name);
458 /* we take for granted that PFE_xxx is the hiword of the corresponding PFM_xxx */
459 #define DUMP_EFFECT(mask, name) \
460 p += sprintf(p, "%-22s%s\n", name, (pFmt->dwMask & (mask)) ? ((pFmt->wEffects & ((mask) >> 16)) ? "yes" : "no") : "N/A");
462 DUMP(PFM_NUMBERING
, "Numbering:", "%u", wNumbering
);
463 DUMP_EFFECT(PFM_DONOTHYPHEN
, "Disable auto-hyphen:");
464 DUMP_EFFECT(PFM_KEEP
, "No page break in para:");
465 DUMP_EFFECT(PFM_KEEPNEXT
, "No page break in para & next:");
466 DUMP_EFFECT(PFM_NOLINENUMBER
, "No line number:");
467 DUMP_EFFECT(PFM_NOWIDOWCONTROL
, "No widow & orphan:");
468 DUMP_EFFECT(PFM_PAGEBREAKBEFORE
, "Page break before:");
469 DUMP_EFFECT(PFM_RTLPARA
, "RTL para:");
470 DUMP_EFFECT(PFM_SIDEBYSIDE
, "Side by side:");
471 DUMP_EFFECT(PFM_TABLE
, "Table:");
472 DUMP(PFM_OFFSETINDENT
, "Offset indent:", "%d", dxStartIndent
);
473 DUMP(PFM_STARTINDENT
, "Start indent:", "%d", dxStartIndent
);
474 DUMP(PFM_RIGHTINDENT
, "Right indent:", "%d", dxRightIndent
);
475 DUMP(PFM_OFFSET
, "Offset:", "%d", dxOffset
);
476 if (pFmt
->dwMask
& PFM_ALIGNMENT
) {
477 switch (pFmt
->wAlignment
) {
478 case PFA_LEFT
: p
+= sprintf(p
, "Alignment: left\n"); break;
479 case PFA_RIGHT
: p
+= sprintf(p
, "Alignment: right\n"); break;
480 case PFA_CENTER
: p
+= sprintf(p
, "Alignment: center\n"); break;
481 case PFA_JUSTIFY
: p
+= sprintf(p
, "Alignment: justify\n"); break;
482 default : p
+= sprintf(p
, "Alignment: incorrect %d\n", pFmt
->wAlignment
); break;
485 else p
+= sprintf(p
, "Alignment: N/A\n");
486 DUMP(PFM_TABSTOPS
, "Tab Stops:", "%d", cTabCount
);
487 if (pFmt
->dwMask
& PFM_TABSTOPS
) {
489 p
+= sprintf(p
, "\t");
490 for (i
= 0; i
< pFmt
->cTabCount
; i
++) p
+= sprintf(p
, "%x ", pFmt
->rgxTabs
[i
]);
491 p
+= sprintf(p
, "\n");
493 DUMP(PFM_SPACEBEFORE
, "Space Before:", "%d", dySpaceBefore
);
494 DUMP(PFM_SPACEAFTER
, "Space After:", "%d", dySpaceAfter
);
495 DUMP(PFM_LINESPACING
, "Line spacing:", "%d", dyLineSpacing
);
496 DUMP(PFM_STYLE
, "Text style:", "%d", sStyle
);
497 DUMP(PFM_LINESPACING
, "Line spacing rule:", "%u", bLineSpacingRule
);
498 /* bOutlineLevel should be 0 */
499 DUMP(PFM_SHADING
, "Shading Weigth:", "%u", wShadingWeight
);
500 DUMP(PFM_SHADING
, "Shading Style:", "%u", wShadingStyle
);
501 DUMP(PFM_NUMBERINGSTART
, "Numbering Start:", "%u", wNumberingStart
);
502 DUMP(PFM_NUMBERINGSTYLE
, "Numbering Style:", "0x%x", wNumberingStyle
);
503 DUMP(PFM_NUMBERINGTAB
, "Numbering Tab:", "%u", wNumberingStyle
);
504 DUMP(PFM_BORDER
, "Border Space:", "%u", wBorderSpace
);
505 DUMP(PFM_BORDER
, "Border Width:", "%u", wBorderWidth
);
506 DUMP(PFM_BORDER
, "Borders:", "%u", wBorders
);
513 ME_GetSelectionParas(ME_TextEditor
*editor
, ME_DisplayItem
**para
, ME_DisplayItem
**para_end
)
515 ME_Cursor
*pEndCursor
= &editor
->pCursors
[1];
517 *para
= editor
->pCursors
[0].pPara
;
518 *para_end
= editor
->pCursors
[1].pPara
;
519 if (*para
== *para_end
)
522 if ((*para_end
)->member
.para
.nCharOfs
< (*para
)->member
.para
.nCharOfs
) {
523 ME_DisplayItem
*tmp
= *para
;
527 pEndCursor
= &editor
->pCursors
[0];
530 /* The paragraph at the end of a non-empty selection isn't included
531 * if the selection ends at the start of the paragraph. */
532 if (!pEndCursor
->pRun
->member
.run
.nCharOfs
&& !pEndCursor
->nOffset
)
533 *para_end
= (*para_end
)->member
.para
.prev_para
;
537 BOOL
ME_SetSelectionParaFormat(ME_TextEditor
*editor
, const PARAFORMAT2
*pFmt
)
539 ME_DisplayItem
*para
, *para_end
;
541 ME_GetSelectionParas(editor
, ¶
, ¶_end
);
544 ME_SetParaFormat(editor
, para
, pFmt
);
545 if (para
== para_end
)
547 para
= para
->member
.para
.next_para
;
553 static void ME_GetParaFormat(ME_TextEditor
*editor
,
554 const ME_DisplayItem
*para
,
557 UINT cbSize
= pFmt
->cbSize
;
558 if (pFmt
->cbSize
>= sizeof(PARAFORMAT2
)) {
559 *pFmt
= *para
->member
.para
.pFmt
;
561 CopyMemory(pFmt
, para
->member
.para
.pFmt
, pFmt
->cbSize
);
562 pFmt
->dwMask
&= PFM_ALL
;
564 pFmt
->cbSize
= cbSize
;
567 void ME_GetSelectionParaFormat(ME_TextEditor
*editor
, PARAFORMAT2
*pFmt
)
569 ME_DisplayItem
*para
, *para_end
;
572 if (pFmt
->cbSize
< sizeof(PARAFORMAT
)) {
577 ME_GetSelectionParas(editor
, ¶
, ¶_end
);
579 ME_GetParaFormat(editor
, para
, pFmt
);
581 /* Invalidate values that change across the selected paragraphs. */
582 while (para
!= para_end
)
584 para
= para
->member
.para
.next_para
;
585 curFmt
= para
->member
.para
.pFmt
;
587 #define CHECK_FIELD(m, f) \
588 if (pFmt->f != curFmt->f) pFmt->dwMask &= ~(m);
590 CHECK_FIELD(PFM_NUMBERING
, wNumbering
);
591 CHECK_FIELD(PFM_STARTINDENT
, dxStartIndent
);
592 CHECK_FIELD(PFM_RIGHTINDENT
, dxRightIndent
);
593 CHECK_FIELD(PFM_OFFSET
, dxOffset
);
594 CHECK_FIELD(PFM_ALIGNMENT
, wAlignment
);
595 if (pFmt
->dwMask
& PFM_TABSTOPS
) {
596 if (pFmt
->cTabCount
!= para
->member
.para
.pFmt
->cTabCount
||
597 memcmp(pFmt
->rgxTabs
, curFmt
->rgxTabs
, curFmt
->cTabCount
*sizeof(int)))
598 pFmt
->dwMask
&= ~PFM_TABSTOPS
;
601 if (pFmt
->dwMask
>= sizeof(PARAFORMAT2
))
603 pFmt
->dwMask
&= ~((pFmt
->wEffects
^ curFmt
->wEffects
) << 16);
604 CHECK_FIELD(PFM_SPACEBEFORE
, dySpaceBefore
);
605 CHECK_FIELD(PFM_SPACEAFTER
, dySpaceAfter
);
606 CHECK_FIELD(PFM_LINESPACING
, dyLineSpacing
);
607 CHECK_FIELD(PFM_STYLE
, sStyle
);
608 CHECK_FIELD(PFM_SPACEAFTER
, bLineSpacingRule
);
609 CHECK_FIELD(PFM_SHADING
, wShadingWeight
);
610 CHECK_FIELD(PFM_SHADING
, wShadingStyle
);
611 CHECK_FIELD(PFM_NUMBERINGSTART
, wNumberingStart
);
612 CHECK_FIELD(PFM_NUMBERINGSTYLE
, wNumberingStyle
);
613 CHECK_FIELD(PFM_NUMBERINGTAB
, wNumberingTab
);
614 CHECK_FIELD(PFM_BORDER
, wBorderSpace
);
615 CHECK_FIELD(PFM_BORDER
, wBorderWidth
);
616 CHECK_FIELD(PFM_BORDER
, wBorders
);
622 void ME_SetDefaultParaFormat(PARAFORMAT2
*pFmt
)
624 ZeroMemory(pFmt
, sizeof(PARAFORMAT2
));
625 pFmt
->cbSize
= sizeof(PARAFORMAT2
);
626 pFmt
->dwMask
= PFM_ALL2
;
627 pFmt
->wAlignment
= PFA_LEFT
;
629 pFmt
->bOutlineLevel
= TRUE
;